topsis-pranshu-102313009 1.0.1__py3-none-any.whl → 1.0.3__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/topsis.py +50 -24
- {topsis_pranshu_102313009-1.0.1.dist-info → topsis_pranshu_102313009-1.0.3.dist-info}/METADATA +1 -1
- topsis_pranshu_102313009-1.0.3.dist-info/RECORD +8 -0
- topsis_pranshu_102313009-1.0.1.dist-info/RECORD +0 -8
- {topsis_pranshu_102313009-1.0.1.dist-info → topsis_pranshu_102313009-1.0.3.dist-info}/WHEEL +0 -0
- {topsis_pranshu_102313009-1.0.1.dist-info → topsis_pranshu_102313009-1.0.3.dist-info}/entry_points.txt +0 -0
- {topsis_pranshu_102313009-1.0.1.dist-info → topsis_pranshu_102313009-1.0.3.dist-info}/licenses/LICENSE +0 -0
- {topsis_pranshu_102313009-1.0.1.dist-info → topsis_pranshu_102313009-1.0.3.dist-info}/top_level.txt +0 -0
topsis_pranshu/topsis.py
CHANGED
|
@@ -3,10 +3,12 @@ import pandas as pd
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import os
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
def error(msg):
|
|
7
8
|
print(f"Error: {msg}")
|
|
8
9
|
sys.exit(1)
|
|
9
10
|
|
|
11
|
+
|
|
10
12
|
def main():
|
|
11
13
|
if len(sys.argv) != 5:
|
|
12
14
|
error("Usage: topsis <InputFile> <Weights> <Impacts> <OutputFile>")
|
|
@@ -16,56 +18,80 @@ def main():
|
|
|
16
18
|
if not os.path.exists(input_file):
|
|
17
19
|
error("Input file not found")
|
|
18
20
|
|
|
21
|
+
# ---------- READ FILE (CSV / XLSX) ----------
|
|
19
22
|
try:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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")
|
|
23
34
|
|
|
35
|
+
except Exception as e:
|
|
36
|
+
error(f"Unable to read input file: {e}")
|
|
37
|
+
|
|
38
|
+
# ---------- VALIDATIONS ----------
|
|
24
39
|
if df.shape[1] < 3:
|
|
25
|
-
error("
|
|
40
|
+
error("Input file must contain at least 3 columns")
|
|
26
41
|
|
|
27
|
-
|
|
42
|
+
# Keep first column as alternative name
|
|
43
|
+
alternatives = df.iloc[:, 0]
|
|
28
44
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
# Automatically select ONLY numeric columns (criteria)
|
|
46
|
+
data = df.iloc[:, 1:].select_dtypes(include=[np.number])
|
|
47
|
+
|
|
48
|
+
if data.shape[1] < 1:
|
|
49
|
+
error("No numeric criteria columns found")
|
|
33
50
|
|
|
34
51
|
weights = list(map(float, weights.split(",")))
|
|
35
52
|
impacts = impacts.split(",")
|
|
36
53
|
|
|
37
54
|
if len(weights) != len(impacts) or len(weights) != data.shape[1]:
|
|
38
|
-
error(
|
|
55
|
+
error(
|
|
56
|
+
f"Weights ({len(weights)}), impacts ({len(impacts)}) "
|
|
57
|
+
f"and criteria ({data.shape[1]}) count mismatch"
|
|
58
|
+
)
|
|
39
59
|
|
|
40
60
|
if not all(i in ['+', '-'] for i in impacts):
|
|
41
61
|
error("Impacts must be + or -")
|
|
42
62
|
|
|
63
|
+
# ---------- TOPSIS CALCULATION ----------
|
|
43
64
|
norm = data / np.sqrt((data ** 2).sum())
|
|
44
65
|
weighted = norm * weights
|
|
45
66
|
|
|
46
|
-
|
|
47
|
-
|
|
67
|
+
ideal_best = []
|
|
68
|
+
ideal_worst = []
|
|
48
69
|
|
|
49
70
|
for i, impact in enumerate(impacts):
|
|
50
71
|
if impact == '+':
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
ideal_best.append(weighted.iloc[:, i].max())
|
|
73
|
+
ideal_worst.append(weighted.iloc[:, i].min())
|
|
53
74
|
else:
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
ideal_best.append(weighted.iloc[:, i].min())
|
|
76
|
+
ideal_worst.append(weighted.iloc[:, i].max())
|
|
56
77
|
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
ideal_best = np.array(ideal_best)
|
|
79
|
+
ideal_worst = np.array(ideal_worst)
|
|
59
80
|
|
|
60
|
-
d_pos = np.sqrt(((weighted -
|
|
61
|
-
d_neg = np.sqrt(((weighted -
|
|
81
|
+
d_pos = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
|
|
82
|
+
d_neg = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
|
|
62
83
|
|
|
63
84
|
score = d_neg / (d_pos + d_neg)
|
|
64
|
-
df["Topsis Score"] = score
|
|
65
|
-
df["Rank"] = score.rank(ascending=False).astype(int)
|
|
66
85
|
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
result = pd.DataFrame({
|
|
87
|
+
df.columns[0]: alternatives,
|
|
88
|
+
"Topsis Score": score,
|
|
89
|
+
"Rank": score.rank(ascending=False).astype(int)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
result.to_csv(output_file, index=False)
|
|
93
|
+
print("TOPSIS completed successfully")
|
|
94
|
+
|
|
69
95
|
|
|
70
96
|
if __name__ == "__main__":
|
|
71
97
|
main()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
topsis_pranshu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
topsis_pranshu/topsis.py,sha256=px_u0knbzcvODV6e4RY53tNdIRJYIAvXeCdWqk05k0M,2827
|
|
3
|
+
topsis_pranshu_102313009-1.0.3.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
topsis_pranshu_102313009-1.0.3.dist-info/METADATA,sha256=lUD3Bq2rjW39h-p150c43amkSFF91HUuYywMJFQv3nk,331
|
|
5
|
+
topsis_pranshu_102313009-1.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
topsis_pranshu_102313009-1.0.3.dist-info/entry_points.txt,sha256=jjw-fXzduRHvZc9NlWHV7aZzaHhK3En131ITtjs63Ag,54
|
|
7
|
+
topsis_pranshu_102313009-1.0.3.dist-info/top_level.txt,sha256=uuGS33veOL0dkp49hZ522LxEG8fHjA3KmvAP3hNVm2M,15
|
|
8
|
+
topsis_pranshu_102313009-1.0.3.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
topsis_pranshu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
topsis_pranshu/topsis.py,sha256=cnIcW3iPZd3eN8qRkuv3QwUawXYhE6Y-QdJl2DeVjY8,1914
|
|
3
|
-
topsis_pranshu_102313009-1.0.1.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
topsis_pranshu_102313009-1.0.1.dist-info/METADATA,sha256=vGz5cqAlkrLHg6hkrHEzCz5BnPbBRfKw50xEx6fm3GY,331
|
|
5
|
-
topsis_pranshu_102313009-1.0.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
topsis_pranshu_102313009-1.0.1.dist-info/entry_points.txt,sha256=jjw-fXzduRHvZc9NlWHV7aZzaHhK3En131ITtjs63Ag,54
|
|
7
|
-
topsis_pranshu_102313009-1.0.1.dist-info/top_level.txt,sha256=uuGS33veOL0dkp49hZ522LxEG8fHjA3KmvAP3hNVm2M,15
|
|
8
|
-
topsis_pranshu_102313009-1.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{topsis_pranshu_102313009-1.0.1.dist-info → topsis_pranshu_102313009-1.0.3.dist-info}/top_level.txt
RENAMED
|
File without changes
|