Topsis-Satyam-102303729 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/__init__.py ADDED
File without changes
topsis/topsis.py ADDED
@@ -0,0 +1,88 @@
1
+ import sys
2
+ import os
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+
7
+ def run_topsis(input_file, weights, impacts, output_file):
8
+ if not os.path.isfile(input_file):
9
+ raise FileNotFoundError("Input file not found")
10
+
11
+ try:
12
+ data = pd.read_csv(input_file)
13
+ except Exception:
14
+ raise ValueError("Unable to read input file")
15
+
16
+ if data.shape[1] < 3:
17
+ raise ValueError("Input file must contain at least 3 columns")
18
+
19
+ criteria = data.iloc[:, 1:]
20
+
21
+ criteria = criteria.apply(pd.to_numeric, errors="coerce")
22
+ if criteria.isnull().values.any():
23
+ raise ValueError("Non-numeric value found in criteria columns")
24
+
25
+ if len(weights) != criteria.shape[1] or len(impacts) != criteria.shape[1]:
26
+ raise ValueError("Number of weights/impacts must match number of criteria")
27
+
28
+ for i in impacts:
29
+ if i not in ['+', '-']:
30
+ raise ValueError("Impacts must be + or -")
31
+
32
+ # Step 1: Normalize
33
+ norm = criteria / np.sqrt((criteria ** 2).sum())
34
+
35
+ # Step 2: Apply weights
36
+ weighted = norm * weights
37
+
38
+ # Step 3: Ideal best and worst
39
+ ideal_best = []
40
+ ideal_worst = []
41
+
42
+ for i, impact in enumerate(impacts):
43
+ if impact == '+':
44
+ ideal_best.append(weighted.iloc[:, i].max())
45
+ ideal_worst.append(weighted.iloc[:, i].min())
46
+ else:
47
+ ideal_best.append(weighted.iloc[:, i].min())
48
+ ideal_worst.append(weighted.iloc[:, i].max())
49
+
50
+ ideal_best = np.array(ideal_best)
51
+ ideal_worst = np.array(ideal_worst)
52
+
53
+ # Step 4: Distance calculation
54
+ s_pos = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
55
+ s_neg = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
56
+
57
+ # Step 5: TOPSIS score
58
+ score = s_neg / (s_pos + s_neg)
59
+
60
+ # Step 6: Rank
61
+ data['Topsis Score'] = score
62
+ data['Rank'] = data['Topsis Score'].rank(
63
+ ascending=False, method='dense'
64
+ ).astype(int)
65
+
66
+ data.to_csv(output_file, index=False)
67
+
68
+
69
+ def main():
70
+ if len(sys.argv) != 5:
71
+ print("Usage: topsis-satyam input.csv \"w1,w2,...\" \"+,-,+,...\" output.csv")
72
+ sys.exit(1)
73
+
74
+ input_file = sys.argv[1]
75
+ weights = list(map(float, sys.argv[2].split(',')))
76
+ impacts = sys.argv[3].split(',')
77
+ output_file = sys.argv[4]
78
+
79
+ try:
80
+ run_topsis(input_file, weights, impacts, output_file)
81
+ print("Output saved to", output_file)
82
+ except Exception as e:
83
+ print("Error:", e)
84
+ sys.exit(1)
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: Topsis-Satyam-102303729
3
+ Version: 1.0.0
4
+ Summary: Implementation of TOPSIS (Technique for Order Preference by Similarity to Ideal Solution)
5
+ Home-page: https://github.com/sat-yam-12/TOPSIS-SATYAM-102303729
6
+ Author: Satyam Gupta
7
+ Author-email: sgupta5_be23@thapar.edu
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: numpy
14
+ Requires-Dist: pandas
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # Topsis-Satyam-102303729
26
+
27
+ This is a Python package implementing the **TOPSIS** method
28
+ (Technique for Order Preference by Similarity to Ideal Solution).
29
+
30
+ ## Installation
31
+ ```bash
32
+ pip install topsis-satyam-102303729
@@ -0,0 +1,7 @@
1
+ topsis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ topsis/topsis.py,sha256=gn533LiBBWzhXDA-sDQB5EieRdXZVaa_QlpA37quWbI,2574
3
+ topsis_satyam_102303729-1.0.0.dist-info/METADATA,sha256=2-JuVTntfYUCo9MPWn-DADCWCaKTfWsxotGmZZia004,986
4
+ topsis_satyam_102303729-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ topsis_satyam_102303729-1.0.0.dist-info/entry_points.txt,sha256=Gt1ZjSFUjOKPik6xi_X6MTNM1ANfCTq1tIOykL8N-6M,53
6
+ topsis_satyam_102303729-1.0.0.dist-info/top_level.txt,sha256=ol7AZ-3jpBeKNxw8WZBbIF4dSQOBGkuzmZDZaufWR4Q,7
7
+ topsis_satyam_102303729-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-satyam = topsis.topsis:main