topsis-pranshu-102313009 1.0.1__tar.gz → 1.0.2__tar.gz
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_102313009-1.0.1/topsis_pranshu_102313009.egg-info → topsis_pranshu_102313009-1.0.2}/PKG-INFO +1 -1
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/setup.py +1 -1
- topsis_pranshu_102313009-1.0.2/topsis_pranshu/topsis.py +89 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2/topsis_pranshu_102313009.egg-info}/PKG-INFO +1 -1
- topsis_pranshu_102313009-1.0.1/topsis_pranshu/topsis.py +0 -71
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/LICENSE +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/README.md +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/setup.cfg +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu/__init__.py +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu_102313009.egg-info/SOURCES.txt +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu_102313009.egg-info/dependency_links.txt +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu_102313009.egg-info/entry_points.txt +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu_102313009.egg-info/requires.txt +0 -0
- {topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu_102313009.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def error(msg):
|
|
8
|
+
print(f"Error: {msg}")
|
|
9
|
+
sys.exit(1)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
if len(sys.argv) != 5:
|
|
14
|
+
error("Usage: topsis <InputFile> <Weights> <Impacts> <OutputFile>")
|
|
15
|
+
|
|
16
|
+
input_file, weights, impacts, output_file = sys.argv[1:]
|
|
17
|
+
|
|
18
|
+
if not os.path.exists(input_file):
|
|
19
|
+
error("Input file not found")
|
|
20
|
+
|
|
21
|
+
# ---------- READ FILE (CSV / XLSX) ----------
|
|
22
|
+
try:
|
|
23
|
+
if input_file.lower().endswith(".csv"):
|
|
24
|
+
try:
|
|
25
|
+
df = pd.read_csv(input_file, encoding="utf-8")
|
|
26
|
+
except UnicodeDecodeError:
|
|
27
|
+
df = pd.read_csv(input_file, encoding="latin1")
|
|
28
|
+
|
|
29
|
+
elif input_file.lower().endswith(".xlsx"):
|
|
30
|
+
df = pd.read_excel(input_file)
|
|
31
|
+
|
|
32
|
+
else:
|
|
33
|
+
error("Only .csv or .xlsx files are supported")
|
|
34
|
+
|
|
35
|
+
except Exception as e:
|
|
36
|
+
error(f"Unable to read input file: {e}")
|
|
37
|
+
|
|
38
|
+
# ---------- VALIDATIONS ----------
|
|
39
|
+
if df.shape[1] < 3:
|
|
40
|
+
error("Input file must contain at least 3 columns")
|
|
41
|
+
|
|
42
|
+
data = df.iloc[:, 1:]
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
data = data.astype(float)
|
|
46
|
+
except:
|
|
47
|
+
error("Columns from 2nd onward must be numeric")
|
|
48
|
+
|
|
49
|
+
weights = list(map(float, weights.split(",")))
|
|
50
|
+
impacts = impacts.split(",")
|
|
51
|
+
|
|
52
|
+
if len(weights) != len(impacts) or len(weights) != data.shape[1]:
|
|
53
|
+
error("Weights, impacts and criteria count mismatch")
|
|
54
|
+
|
|
55
|
+
if not all(i in ['+', '-'] for i in impacts):
|
|
56
|
+
error("Impacts must be + or -")
|
|
57
|
+
|
|
58
|
+
# ---------- TOPSIS CALCULATION ----------
|
|
59
|
+
norm = data / np.sqrt((data ** 2).sum())
|
|
60
|
+
weighted = norm * weights
|
|
61
|
+
|
|
62
|
+
ideal_best = []
|
|
63
|
+
ideal_worst = []
|
|
64
|
+
|
|
65
|
+
for i, impact in enumerate(impacts):
|
|
66
|
+
if impact == '+':
|
|
67
|
+
ideal_best.append(weighted.iloc[:, i].max())
|
|
68
|
+
ideal_worst.append(weighted.iloc[:, i].min())
|
|
69
|
+
else:
|
|
70
|
+
ideal_best.append(weighted.iloc[:, i].min())
|
|
71
|
+
ideal_worst.append(weighted.iloc[:, i].max())
|
|
72
|
+
|
|
73
|
+
ideal_best = np.array(ideal_best)
|
|
74
|
+
ideal_worst = np.array(ideal_worst)
|
|
75
|
+
|
|
76
|
+
d_pos = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
|
|
77
|
+
d_neg = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
|
|
78
|
+
|
|
79
|
+
score = d_neg / (d_pos + d_neg)
|
|
80
|
+
|
|
81
|
+
df["Topsis Score"] = score
|
|
82
|
+
df["Rank"] = score.rank(ascending=False).astype(int)
|
|
83
|
+
|
|
84
|
+
df.to_csv(output_file, index=False)
|
|
85
|
+
print("TOPSIS completed successfully")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
main()
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
try:
|
|
20
|
-
df = pd.read_csv(input_file, encoding="utf-8")
|
|
21
|
-
except UnicodeDecodeError:
|
|
22
|
-
df = pd.read_csv(input_file, encoding="latin1")
|
|
23
|
-
|
|
24
|
-
if df.shape[1] < 3:
|
|
25
|
-
error("File must contain at least 3 columns")
|
|
26
|
-
|
|
27
|
-
data = df.iloc[:, 1:]
|
|
28
|
-
|
|
29
|
-
try:
|
|
30
|
-
data = data.astype(float)
|
|
31
|
-
except:
|
|
32
|
-
error("Non-numeric values found")
|
|
33
|
-
|
|
34
|
-
weights = list(map(float, weights.split(",")))
|
|
35
|
-
impacts = impacts.split(",")
|
|
36
|
-
|
|
37
|
-
if len(weights) != len(impacts) or len(weights) != data.shape[1]:
|
|
38
|
-
error("Weights, impacts and criteria count mismatch")
|
|
39
|
-
|
|
40
|
-
if not all(i in ['+', '-'] for i in impacts):
|
|
41
|
-
error("Impacts must be + or -")
|
|
42
|
-
|
|
43
|
-
norm = data / np.sqrt((data ** 2).sum())
|
|
44
|
-
weighted = norm * weights
|
|
45
|
-
|
|
46
|
-
best = []
|
|
47
|
-
worst = []
|
|
48
|
-
|
|
49
|
-
for i, impact in enumerate(impacts):
|
|
50
|
-
if impact == '+':
|
|
51
|
-
best.append(weighted.iloc[:, i].max())
|
|
52
|
-
worst.append(weighted.iloc[:, i].min())
|
|
53
|
-
else:
|
|
54
|
-
best.append(weighted.iloc[:, i].min())
|
|
55
|
-
worst.append(weighted.iloc[:, i].max())
|
|
56
|
-
|
|
57
|
-
best = np.array(best)
|
|
58
|
-
worst = np.array(worst)
|
|
59
|
-
|
|
60
|
-
d_pos = np.sqrt(((weighted - best) ** 2).sum(axis=1))
|
|
61
|
-
d_neg = np.sqrt(((weighted - worst) ** 2).sum(axis=1))
|
|
62
|
-
|
|
63
|
-
score = d_neg / (d_pos + d_neg)
|
|
64
|
-
df["Topsis Score"] = score
|
|
65
|
-
df["Rank"] = score.rank(ascending=False).astype(int)
|
|
66
|
-
|
|
67
|
-
df.to_csv(output_file, index=False)
|
|
68
|
-
print("TOPSIS completed")
|
|
69
|
-
|
|
70
|
-
if __name__ == "__main__":
|
|
71
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{topsis_pranshu_102313009-1.0.1 → topsis_pranshu_102313009-1.0.2}/topsis_pranshu/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|