topsis-pranshu-102313009 1.0.0__py3-none-any.whl → 1.0.2__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 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,17 +18,33 @@ def main():
16
18
  if not os.path.exists(input_file):
17
19
  error("Input file not found")
18
20
 
19
- df = pd.read_csv(input_file)
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")
20
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 ----------
21
39
  if df.shape[1] < 3:
22
- error("File must contain at least 3 columns")
40
+ error("Input file must contain at least 3 columns")
23
41
 
24
42
  data = df.iloc[:, 1:]
25
43
 
26
44
  try:
27
45
  data = data.astype(float)
28
46
  except:
29
- error("Non-numeric values found")
47
+ error("Columns from 2nd onward must be numeric")
30
48
 
31
49
  weights = list(map(float, weights.split(",")))
32
50
  impacts = impacts.split(",")
@@ -37,32 +55,35 @@ def main():
37
55
  if not all(i in ['+', '-'] for i in impacts):
38
56
  error("Impacts must be + or -")
39
57
 
58
+ # ---------- TOPSIS CALCULATION ----------
40
59
  norm = data / np.sqrt((data ** 2).sum())
41
60
  weighted = norm * weights
42
61
 
43
- best = []
44
- worst = []
62
+ ideal_best = []
63
+ ideal_worst = []
45
64
 
46
65
  for i, impact in enumerate(impacts):
47
66
  if impact == '+':
48
- best.append(weighted.iloc[:, i].max())
49
- worst.append(weighted.iloc[:, i].min())
67
+ ideal_best.append(weighted.iloc[:, i].max())
68
+ ideal_worst.append(weighted.iloc[:, i].min())
50
69
  else:
51
- best.append(weighted.iloc[:, i].min())
52
- worst.append(weighted.iloc[:, i].max())
70
+ ideal_best.append(weighted.iloc[:, i].min())
71
+ ideal_worst.append(weighted.iloc[:, i].max())
53
72
 
54
- best = np.array(best)
55
- worst = np.array(worst)
73
+ ideal_best = np.array(ideal_best)
74
+ ideal_worst = np.array(ideal_worst)
56
75
 
57
- d_pos = np.sqrt(((weighted - best) ** 2).sum(axis=1))
58
- d_neg = np.sqrt(((weighted - worst) ** 2).sum(axis=1))
76
+ d_pos = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
77
+ d_neg = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
59
78
 
60
79
  score = d_neg / (d_pos + d_neg)
80
+
61
81
  df["Topsis Score"] = score
62
82
  df["Rank"] = score.rank(ascending=False).astype(int)
63
83
 
64
84
  df.to_csv(output_file, index=False)
65
- print("TOPSIS completed")
85
+ print("TOPSIS completed successfully")
86
+
66
87
 
67
88
  if __name__ == "__main__":
68
89
  main()
@@ -1,10 +1,14 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: topsis-pranshu-102313009
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: TOPSIS command-line tool
5
5
  Author: Pranshu Goel
6
6
  Author-email: your@email.com
7
7
  License-File: LICENSE
8
8
  Requires-Dist: pandas
9
9
  Requires-Dist: numpy
10
-
10
+ Dynamic: author
11
+ Dynamic: author-email
12
+ Dynamic: license-file
13
+ Dynamic: requires-dist
14
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ topsis_pranshu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ topsis_pranshu/topsis.py,sha256=x9alE2B8ibz-OVDrfgDBE1czUW1493QpZr5R-ICMpqg,2516
3
+ topsis_pranshu_102313009-1.0.2.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ topsis_pranshu_102313009-1.0.2.dist-info/METADATA,sha256=Fc7cHAt5tD9lBrntPWMusWv5JKjc5iUhIMnXGUd07YE,331
5
+ topsis_pranshu_102313009-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ topsis_pranshu_102313009-1.0.2.dist-info/entry_points.txt,sha256=jjw-fXzduRHvZc9NlWHV7aZzaHhK3En131ITtjs63Ag,54
7
+ topsis_pranshu_102313009-1.0.2.dist-info/top_level.txt,sha256=uuGS33veOL0dkp49hZ522LxEG8fHjA3KmvAP3hNVm2M,15
8
+ topsis_pranshu_102313009-1.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.46.3)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- topsis_pranshu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- topsis_pranshu/topsis.py,sha256=Nr1whhJL6erMJJFoWujJ7-0HAT8SNCLcbsJLeOcGDFs,1793
3
- topsis_pranshu_102313009-1.0.0.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- topsis_pranshu_102313009-1.0.0.dist-info/METADATA,sha256=8BUWqJZIkMwBS1YNcOP8_sBSCCjP7eQcMphwKwkdlHk,228
5
- topsis_pranshu_102313009-1.0.0.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
6
- topsis_pranshu_102313009-1.0.0.dist-info/entry_points.txt,sha256=jjw-fXzduRHvZc9NlWHV7aZzaHhK3En131ITtjs63Ag,54
7
- topsis_pranshu_102313009-1.0.0.dist-info/top_level.txt,sha256=uuGS33veOL0dkp49hZ522LxEG8fHjA3KmvAP3hNVm2M,15
8
- topsis_pranshu_102313009-1.0.0.dist-info/RECORD,,