topsis-pranshu-102313009 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- topsis_pranshu/__init__.py +0 -0
- topsis_pranshu/topsis.py +68 -0
- topsis_pranshu_102313009-1.0.0.dist-info/LICENSE +0 -0
- topsis_pranshu_102313009-1.0.0.dist-info/METADATA +10 -0
- topsis_pranshu_102313009-1.0.0.dist-info/RECORD +8 -0
- topsis_pranshu_102313009-1.0.0.dist-info/WHEEL +5 -0
- topsis_pranshu_102313009-1.0.0.dist-info/entry_points.txt +2 -0
- topsis_pranshu_102313009-1.0.0.dist-info/top_level.txt +1 -0
|
File without changes
|
topsis_pranshu/topsis.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
def error(msg):
|
|
7
|
+
print(f"Error: {msg}")
|
|
8
|
+
sys.exit(1)
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
if len(sys.argv) != 5:
|
|
12
|
+
error("Usage: topsis <InputFile> <Weights> <Impacts> <OutputFile>")
|
|
13
|
+
|
|
14
|
+
input_file, weights, impacts, output_file = sys.argv[1:]
|
|
15
|
+
|
|
16
|
+
if not os.path.exists(input_file):
|
|
17
|
+
error("Input file not found")
|
|
18
|
+
|
|
19
|
+
df = pd.read_csv(input_file)
|
|
20
|
+
|
|
21
|
+
if df.shape[1] < 3:
|
|
22
|
+
error("File must contain at least 3 columns")
|
|
23
|
+
|
|
24
|
+
data = df.iloc[:, 1:]
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
data = data.astype(float)
|
|
28
|
+
except:
|
|
29
|
+
error("Non-numeric values found")
|
|
30
|
+
|
|
31
|
+
weights = list(map(float, weights.split(",")))
|
|
32
|
+
impacts = impacts.split(",")
|
|
33
|
+
|
|
34
|
+
if len(weights) != len(impacts) or len(weights) != data.shape[1]:
|
|
35
|
+
error("Weights, impacts and criteria count mismatch")
|
|
36
|
+
|
|
37
|
+
if not all(i in ['+', '-'] for i in impacts):
|
|
38
|
+
error("Impacts must be + or -")
|
|
39
|
+
|
|
40
|
+
norm = data / np.sqrt((data ** 2).sum())
|
|
41
|
+
weighted = norm * weights
|
|
42
|
+
|
|
43
|
+
best = []
|
|
44
|
+
worst = []
|
|
45
|
+
|
|
46
|
+
for i, impact in enumerate(impacts):
|
|
47
|
+
if impact == '+':
|
|
48
|
+
best.append(weighted.iloc[:, i].max())
|
|
49
|
+
worst.append(weighted.iloc[:, i].min())
|
|
50
|
+
else:
|
|
51
|
+
best.append(weighted.iloc[:, i].min())
|
|
52
|
+
worst.append(weighted.iloc[:, i].max())
|
|
53
|
+
|
|
54
|
+
best = np.array(best)
|
|
55
|
+
worst = np.array(worst)
|
|
56
|
+
|
|
57
|
+
d_pos = np.sqrt(((weighted - best) ** 2).sum(axis=1))
|
|
58
|
+
d_neg = np.sqrt(((weighted - worst) ** 2).sum(axis=1))
|
|
59
|
+
|
|
60
|
+
score = d_neg / (d_pos + d_neg)
|
|
61
|
+
df["Topsis Score"] = score
|
|
62
|
+
df["Rank"] = score.rank(ascending=False).astype(int)
|
|
63
|
+
|
|
64
|
+
df.to_csv(output_file, index=False)
|
|
65
|
+
print("TOPSIS completed")
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
topsis_pranshu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
topsis_pranshu/topsis.py,sha256=Nr1whhJL6erMJJFoWujJ7-0HAT8SNCLcbsJLeOcGDFs,1793
|
|
3
|
+
topsis_pranshu_102313009-1.0.0.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
topsis_pranshu_102313009-1.0.0.dist-info/METADATA,sha256=8BUWqJZIkMwBS1YNcOP8_sBSCCjP7eQcMphwKwkdlHk,228
|
|
5
|
+
topsis_pranshu_102313009-1.0.0.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
|
|
6
|
+
topsis_pranshu_102313009-1.0.0.dist-info/entry_points.txt,sha256=jjw-fXzduRHvZc9NlWHV7aZzaHhK3En131ITtjs63Ag,54
|
|
7
|
+
topsis_pranshu_102313009-1.0.0.dist-info/top_level.txt,sha256=uuGS33veOL0dkp49hZ522LxEG8fHjA3KmvAP3hNVm2M,15
|
|
8
|
+
topsis_pranshu_102313009-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
topsis_pranshu
|