Topsis-Anahat-102313058 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.
File without changes
@@ -0,0 +1,88 @@
1
+ import sys
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ def error(msg):
6
+ print(f"Error: {msg}")
7
+ sys.exit(1)
8
+
9
+ def main():
10
+ # Correct number of parameters
11
+ if len(sys.argv) != 5:
12
+ error("Incorrect number of parameters.\nUsage: python topsis.py <InputFile> <Weights> <Impacts> <OutputFile>")
13
+
14
+ input_file = sys.argv[1]
15
+ weights = sys.argv[2]
16
+ impacts = sys.argv[3]
17
+ output_file = sys.argv[4]
18
+
19
+ #Message for wrong inputs
20
+ #File Handling
21
+ try:
22
+ data = pd.read_csv(input_file)
23
+ except FileNotFoundError:
24
+ error("Input file not found.")
25
+
26
+ if data.shape[1] < 3:
27
+ error("Input file must contain three or more columns.")
28
+
29
+ #Numeric Validation
30
+ try:
31
+ matrix = data.iloc[:, 1:].astype(float)
32
+ except ValueError:
33
+ error("From 2nd to last columns must contain numeric values only.")
34
+
35
+ #Weights & Impacts
36
+ try:
37
+ weights = list(map(float, weights.split(',')))
38
+ except:
39
+ error("Weights must be numeric and separated by commas.")
40
+
41
+ impacts = impacts.split(',')
42
+
43
+ if len(weights) != matrix.shape[1] or len(impacts) != matrix.shape[1]:
44
+ error("Number of weights, impacts, and criteria columns must be equal.")
45
+
46
+ for i in impacts:
47
+ if i not in ['+', '-']:
48
+ error("Impacts must be either '+' or '-'.")
49
+
50
+ # TOPSIS Steps
51
+ # Step 1: Normalize
52
+ norm = matrix / np.sqrt((matrix ** 2).sum())
53
+
54
+ # Step 2: Weighting
55
+ weighted = norm * weights
56
+
57
+ # Step 3: Ideal best & worst
58
+ ideal_best = []
59
+ ideal_worst = []
60
+
61
+ for i in range(len(impacts)):
62
+ if impacts[i] == '+':
63
+ ideal_best.append(weighted.iloc[:, i].max())
64
+ ideal_worst.append(weighted.iloc[:, i].min())
65
+ else:
66
+ ideal_best.append(weighted.iloc[:, i].min())
67
+ ideal_worst.append(weighted.iloc[:, i].max())
68
+
69
+ ideal_best = np.array(ideal_best)
70
+ ideal_worst = np.array(ideal_worst)
71
+
72
+ # Step 4: Distance
73
+ dist_best = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
74
+ dist_worst = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
75
+
76
+ # Step 5: Score
77
+ score = dist_worst / (dist_best + dist_worst)
78
+
79
+ # Step 6: Rank
80
+ data['Topsis Score'] = score
81
+ data['Rank'] = data['Topsis Score'].rank(ascending=False, method='dense').astype(int)
82
+
83
+ # Output
84
+ data.to_csv(output_file, index=False)
85
+ print(f"TOPSIS result saved to {output_file}")
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: Topsis-Anahat-102313058
3
+ Version: 1.0.0
4
+ Summary: TOPSIS implementation using Python
5
+ Author: Anahat
6
+ Requires-Dist: pandas
7
+ Requires-Dist: numpy
8
+ Dynamic: author
9
+ Dynamic: requires-dist
10
+ Dynamic: summary
@@ -0,0 +1,7 @@
1
+ topsis-anahat-102313058/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ topsis-anahat-102313058/topsis.py,sha256=35yhP8jsFRr9n7fXRS0iotjUrToOWjrsaM2RISVx-1g,2460
3
+ topsis_anahat_102313058-1.0.0.dist-info/METADATA,sha256=6GC092v8SuSlsLqNiQgOOVHup9nboA3QlSRfL3NH84k,225
4
+ topsis_anahat_102313058-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ topsis_anahat_102313058-1.0.0.dist-info/entry_points.txt,sha256=aqDRrV_gFjuL5a5XT_pJP8vkaG1dI4JfAhFyYmuXuNE,65
6
+ topsis_anahat_102313058-1.0.0.dist-info/top_level.txt,sha256=q8mKkbMWlQF1WRUBXPZj15XjpLdb3qY2GnCFjL9q1ps,24
7
+ topsis_anahat_102313058-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ topsis = topsis_anahat_102313058.topsis:topsis
@@ -0,0 +1 @@
1
+ topsis-anahat-102313058