Topsis-Mahim-102303958 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.
@@ -0,0 +1 @@
1
+ # TOPSIS package
@@ -0,0 +1,98 @@
1
+ import sys
2
+ import os
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+
7
+ def validate_inputs():
8
+
9
+ if len(sys.argv) != 5:
10
+ print("Error: Incorrect number of parameters.")
11
+ print("Usage: python topsis.py <InputDataFile> <Weights> <Impacts> <OutputResultFileName>")
12
+ sys.exit(1)
13
+
14
+ input_file, weights_str, impacts_str, output_file = sys.argv[1:]
15
+
16
+ if not os.path.isfile(input_file):
17
+ print(f"Error: File '{input_file}' not found.")
18
+ sys.exit(1)
19
+
20
+ try:
21
+ if input_file.endswith(".csv"):
22
+ df = pd.read_csv(input_file)
23
+ elif input_file.endswith(".xlsx"):
24
+ df = pd.read_excel(input_file)
25
+ else:
26
+ print("Error: Input file must be .csv or .xlsx")
27
+ sys.exit(1)
28
+ except:
29
+ print("Error: Unable to read input file.")
30
+ sys.exit(1)
31
+
32
+ if df.shape[1] < 3:
33
+ print("Error: Input file must contain at least 3 columns.")
34
+ sys.exit(1)
35
+
36
+ numeric_data = df.iloc[:, 1:].apply(pd.to_numeric, errors="coerce")
37
+ if numeric_data.isnull().values.any():
38
+ print("Error: From 2nd to last columns must contain numeric values only.")
39
+ sys.exit(1)
40
+
41
+ try:
42
+ weights = [float(w) for w in weights_str.split(",")]
43
+ impacts = impacts_str.split(",")
44
+ except:
45
+ print("Error: Weights must be numeric and comma separated.")
46
+ sys.exit(1)
47
+
48
+ if not all(i in ["+", "-"] for i in impacts):
49
+ print("Error: Impacts must be either '+' or '-'.")
50
+ sys.exit(1)
51
+
52
+ if len(weights) != df.shape[1] - 1 or len(impacts) != df.shape[1] - 1:
53
+ print("Error: Number of weights, impacts and criteria must be the same.")
54
+ sys.exit(1)
55
+
56
+ return df, weights, impacts, output_file
57
+
58
+
59
+ def topsis_calculation(df, weights, impacts):
60
+
61
+ data = df.iloc[:, 1:].values.astype(float)
62
+
63
+ norm = data / np.sqrt((data ** 2).sum(axis=0))
64
+ weighted = norm * weights
65
+
66
+ best, worst = [], []
67
+
68
+ for i in range(len(impacts)):
69
+ if impacts[i] == "+":
70
+ best.append(weighted[:, i].max())
71
+ worst.append(weighted[:, i].min())
72
+ else:
73
+ best.append(weighted[:, i].min())
74
+ worst.append(weighted[:, i].max())
75
+
76
+ best = np.array(best)
77
+ worst = np.array(worst)
78
+
79
+ d_pos = np.sqrt(((weighted - best) ** 2).sum(axis=1))
80
+ d_neg = np.sqrt(((weighted - worst) ** 2).sum(axis=1))
81
+
82
+ return d_neg / (d_pos + d_neg)
83
+
84
+
85
+ def main():
86
+
87
+ df, weights, impacts, output_file = validate_inputs()
88
+ scores = topsis_calculation(df, weights, impacts)
89
+
90
+ df["Topsis Score"] = scores
91
+ df["Rank"] = df["Topsis Score"].rank(ascending=False, method="dense").astype(int)
92
+
93
+ df.to_csv(output_file, index=False)
94
+ print(f"TOPSIS analysis completed. Results saved in '{output_file}'.")
95
+
96
+
97
+ if __name__ == "__main__":
98
+ main()
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: Topsis-Mahim-102303958
3
+ Version: 1.0.0
4
+ Summary: Implementation of TOPSIS method as a Python package
5
+ Author: Mahim
6
+ Author-email: mkatiyar_be23@thapar.edu
7
+ Requires-Python: >=3.7
8
+ License-File: LICENSE.txt
9
+ Requires-Dist: pandas
10
+ Requires-Dist: numpy
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: license-file
14
+ Dynamic: requires-dist
15
+ Dynamic: requires-python
16
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ topsis_mahim_102303958/__init__.py,sha256=BdA_ievcGGEIwN1JBBFA-l6oWMWUkWK-nWPGLFpAinE,18
2
+ topsis_mahim_102303958/topsis.py,sha256=5bX06uizEbt3Wvnlx5bNn2UqeXgRDyrDBjl-cospb84,2909
3
+ topsis_mahim_102303958-1.0.0.dist-info/licenses/LICENSE.txt,sha256=ztPBD5cEAHIcV6J8CyjPeK-U53Hvnf5XkBk6lob0XhY,409
4
+ topsis_mahim_102303958-1.0.0.dist-info/METADATA,sha256=JZpX2g345ZML_YSkualY2i0P18h7N8yQv9B3347Za8A,413
5
+ topsis_mahim_102303958-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ topsis_mahim_102303958-1.0.0.dist-info/entry_points.txt,sha256=0HZaSE1IAY5ZhQHW4EamhLgdUjL5Pr-Yr2uoqPEEgus,62
7
+ topsis_mahim_102303958-1.0.0.dist-info/top_level.txt,sha256=DZMnq560bQ_9_BpXTeEStwg3F4H61qsvs5aAi1-VufE,23
8
+ topsis_mahim_102303958-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_mahim_102303958.topsis:main
@@ -0,0 +1,11 @@
1
+ This project is developed for academic and educational purposes.
2
+
3
+ The source code may be used, modified, and shared strictly for learning,
4
+ assignment submission, and non-commercial use.
5
+
6
+ No warranty is provided. The author is not responsible for any misuse
7
+ or damage caused by this software.
8
+
9
+ Author: Mahim Katiyar
10
+ Roll Number: 102303958
11
+ Institution: Thapar Institute of Engineering and Technology
@@ -0,0 +1 @@
1
+ topsis_mahim_102303958