Topsis-KhushiMehta-102303769 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_khushi/__init__.py +0 -0
- topsis_khushi/topsis.py +81 -0
- topsis_khushimehta_102303769-1.0.0.dist-info/METADATA +11 -0
- topsis_khushimehta_102303769-1.0.0.dist-info/RECORD +7 -0
- topsis_khushimehta_102303769-1.0.0.dist-info/WHEEL +5 -0
- topsis_khushimehta_102303769-1.0.0.dist-info/entry_points.txt +2 -0
- topsis_khushimehta_102303769-1.0.0.dist-info/top_level.txt +1 -0
|
File without changes
|
topsis_khushi/topsis.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
def topsis(input_file, weights, impacts, output_file):
|
|
8
|
+
|
|
9
|
+
# File check
|
|
10
|
+
if not os.path.exists(input_file):
|
|
11
|
+
raise Exception("Input file not found")
|
|
12
|
+
|
|
13
|
+
# INPUT (CSV or XLSX)
|
|
14
|
+
if input_file.endswith(".csv"):
|
|
15
|
+
df = pd.read_csv(input_file)
|
|
16
|
+
elif input_file.endswith(".xlsx"):
|
|
17
|
+
df = pd.read_excel(input_file)
|
|
18
|
+
else:
|
|
19
|
+
raise Exception("Input file must be .csv or .xlsx")
|
|
20
|
+
|
|
21
|
+
if df.shape[1] < 3:
|
|
22
|
+
raise Exception("Input file must contain 3 or more columns")
|
|
23
|
+
|
|
24
|
+
data = df.iloc[:, 1:]
|
|
25
|
+
|
|
26
|
+
# Numeric validation
|
|
27
|
+
if not np.all(data.map(np.isreal)):
|
|
28
|
+
raise Exception("Columns from 2nd to last must be numeric")
|
|
29
|
+
|
|
30
|
+
weights = list(map(float, weights.split(",")))
|
|
31
|
+
impacts = impacts.split(",")
|
|
32
|
+
|
|
33
|
+
if len(weights) != data.shape[1] or len(impacts) != data.shape[1]:
|
|
34
|
+
raise Exception("Weights, impacts and columns count mismatch")
|
|
35
|
+
|
|
36
|
+
for i in impacts:
|
|
37
|
+
if i not in ['+', '-']:
|
|
38
|
+
raise Exception("Impacts must be + or -")
|
|
39
|
+
|
|
40
|
+
# Normalization
|
|
41
|
+
norm = np.sqrt((data ** 2).sum())
|
|
42
|
+
norm_data = data / norm
|
|
43
|
+
|
|
44
|
+
# Weighted
|
|
45
|
+
weighted = norm_data * weights
|
|
46
|
+
|
|
47
|
+
# Ideal best & worst
|
|
48
|
+
ideal_best = []
|
|
49
|
+
ideal_worst = []
|
|
50
|
+
|
|
51
|
+
for i in range(len(impacts)):
|
|
52
|
+
if impacts[i] == '+':
|
|
53
|
+
ideal_best.append(weighted.iloc[:, i].max())
|
|
54
|
+
ideal_worst.append(weighted.iloc[:, i].min())
|
|
55
|
+
else:
|
|
56
|
+
ideal_best.append(weighted.iloc[:, i].min())
|
|
57
|
+
ideal_worst.append(weighted.iloc[:, i].max())
|
|
58
|
+
|
|
59
|
+
# Distance
|
|
60
|
+
d_best = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
|
|
61
|
+
d_worst = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
|
|
62
|
+
|
|
63
|
+
score = d_worst / (d_best + d_worst)
|
|
64
|
+
|
|
65
|
+
df["Topsis Score"] = score
|
|
66
|
+
df["Rank"] = score.rank(ascending=False)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if not output_file.endswith(".csv"):
|
|
70
|
+
raise Exception("Output file must be .csv")
|
|
71
|
+
|
|
72
|
+
df.to_csv(output_file, index=False)
|
|
73
|
+
|
|
74
|
+
def main():
|
|
75
|
+
if len(sys.argv) != 5:
|
|
76
|
+
print("Usage: topsis <input.(csv/xlsx)> <weights> <impacts> <output.csv>")
|
|
77
|
+
sys.exit(1)
|
|
78
|
+
|
|
79
|
+
_, input_file, weights, impacts, output_file = sys.argv
|
|
80
|
+
topsis(input_file, weights, impacts, output_file)
|
|
81
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Topsis-KhushiMehta-102303769
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: TOPSIS decision making method
|
|
5
|
+
Author: Khushi
|
|
6
|
+
Requires-Dist: pandas
|
|
7
|
+
Requires-Dist: numpy
|
|
8
|
+
Requires-Dist: openpyxl
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: requires-dist
|
|
11
|
+
Dynamic: summary
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
topsis_khushi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
topsis_khushi/topsis.py,sha256=jv_QK4J1-FbyXR7P21ETthcI6H_QeMePsPU3GNYy8Qw,2323
|
|
3
|
+
topsis_khushimehta_102303769-1.0.0.dist-info/METADATA,sha256=I7Cd5zvyw7RdkqccB8M7oY9nsPxhOSg3w7B2n0vm63s,260
|
|
4
|
+
topsis_khushimehta_102303769-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
topsis_khushimehta_102303769-1.0.0.dist-info/entry_points.txt,sha256=6TNBgjObW6hWlkxNwuUtngovpEAYX3lwsTjID_AMYn0,53
|
|
6
|
+
topsis_khushimehta_102303769-1.0.0.dist-info/top_level.txt,sha256=2ji7LC_9LHtRbKaVBVu0FEQUydFifsgKmb3-rOwxriI,14
|
|
7
|
+
topsis_khushimehta_102303769-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
topsis_khushi
|