topsis-pranshu-102313009 1.0.2__tar.gz → 1.0.4__tar.gz
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_102313009-1.0.2/topsis_pranshu_102313009.egg-info → topsis_pranshu_102313009-1.0.4}/PKG-INFO +1 -1
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/setup.py +1 -1
- topsis_pranshu_102313009-1.0.4/topsis_pranshu/topsis.py +95 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4/topsis_pranshu_102313009.egg-info}/PKG-INFO +1 -1
- topsis_pranshu_102313009-1.0.2/topsis_pranshu/topsis.py +0 -89
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/LICENSE +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/README.md +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/setup.cfg +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu/__init__.py +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu_102313009.egg-info/SOURCES.txt +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu_102313009.egg-info/dependency_links.txt +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu_102313009.egg-info/entry_points.txt +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu_102313009.egg-info/requires.txt +0 -0
- {topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu_102313009.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import pandas as pd
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
def error(msg):
|
|
7
|
+
print(f"Error: {msg}")
|
|
8
|
+
sys.exit(1)
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
if len(sys.argv) != 5:
|
|
12
|
+
error("Wrong number of parameters. Usage: python topsis.py <InputDataFile> <Weights> <Impacts> <OutputResultFileName>")
|
|
13
|
+
|
|
14
|
+
input_file = sys.argv[1]
|
|
15
|
+
weights_str = sys.argv[2]
|
|
16
|
+
impacts_str = sys.argv[3]
|
|
17
|
+
output_file = sys.argv[4]
|
|
18
|
+
|
|
19
|
+
if not os.path.exists(input_file):
|
|
20
|
+
error(f"The file '{input_file}' was not found.")
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
if input_file.lower().endswith(".csv"):
|
|
24
|
+
df = pd.read_csv(input_file)
|
|
25
|
+
elif input_file.lower().endswith(".xlsx") or input_file.lower().endswith(".xls"):
|
|
26
|
+
df = pd.read_excel(input_file)
|
|
27
|
+
else:
|
|
28
|
+
error("Unsupported file format. Use .csv or .xlsx")
|
|
29
|
+
except Exception as e:
|
|
30
|
+
error(f"Error reading file: {e}")
|
|
31
|
+
|
|
32
|
+
if df.shape[1] < 3:
|
|
33
|
+
error("Input file must contain three or more columns.")
|
|
34
|
+
|
|
35
|
+
data_df = df.iloc[:, 1:].copy()
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
data_df = data_df.apply(pd.to_numeric)
|
|
39
|
+
except:
|
|
40
|
+
error("From 2nd to last columns must contain numeric values only.")
|
|
41
|
+
|
|
42
|
+
if data_df.isnull().values.any():
|
|
43
|
+
error("Input data contains non-numeric or missing values.")
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
weights = [float(w) for w in weights_str.split(",")]
|
|
47
|
+
impacts = impacts_str.split(",")
|
|
48
|
+
except:
|
|
49
|
+
error("Weights must be numeric and impacts must be comma-separated.")
|
|
50
|
+
|
|
51
|
+
num_cols = data_df.shape[1]
|
|
52
|
+
|
|
53
|
+
if len(weights) != num_cols or len(impacts) != num_cols:
|
|
54
|
+
error("Number of weights, impacts and criteria columns must be the same.")
|
|
55
|
+
|
|
56
|
+
if not all(i in ["+", "-"] for i in impacts):
|
|
57
|
+
error("Impacts must be either '+' or '-'.")
|
|
58
|
+
|
|
59
|
+
matrix = data_df.values
|
|
60
|
+
rss = np.sqrt(np.sum(matrix ** 2, axis=0))
|
|
61
|
+
|
|
62
|
+
if (rss == 0).any():
|
|
63
|
+
error("Normalization failed due to zero variance column.")
|
|
64
|
+
|
|
65
|
+
normalized_matrix = matrix / rss
|
|
66
|
+
weighted_matrix = normalized_matrix * weights
|
|
67
|
+
|
|
68
|
+
ideal_best = []
|
|
69
|
+
ideal_worst = []
|
|
70
|
+
|
|
71
|
+
for i in range(num_cols):
|
|
72
|
+
if impacts[i] == "+":
|
|
73
|
+
ideal_best.append(np.max(weighted_matrix[:, i]))
|
|
74
|
+
ideal_worst.append(np.min(weighted_matrix[:, i]))
|
|
75
|
+
else:
|
|
76
|
+
ideal_best.append(np.min(weighted_matrix[:, i]))
|
|
77
|
+
ideal_worst.append(np.max(weighted_matrix[:, i]))
|
|
78
|
+
|
|
79
|
+
ideal_best = np.array(ideal_best)
|
|
80
|
+
ideal_worst = np.array(ideal_worst)
|
|
81
|
+
|
|
82
|
+
s_plus = np.sqrt(np.sum((weighted_matrix - ideal_best) ** 2, axis=1))
|
|
83
|
+
s_minus = np.sqrt(np.sum((weighted_matrix - ideal_worst) ** 2, axis=1))
|
|
84
|
+
|
|
85
|
+
total_dist = s_plus + s_minus
|
|
86
|
+
performance_score = np.divide(s_minus, total_dist, out=np.zeros_like(s_minus), where=total_dist != 0)
|
|
87
|
+
|
|
88
|
+
df["Topsis Score"] = performance_score
|
|
89
|
+
df["Rank"] = df["Topsis Score"].rank(ascending=False, method="min").astype(int)
|
|
90
|
+
|
|
91
|
+
df.to_csv(output_file, index=False)
|
|
92
|
+
print(f"Success: Result saved to {output_file}")
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
main()
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import pandas as pd
|
|
3
|
-
import numpy as np
|
|
4
|
-
import os
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def error(msg):
|
|
8
|
-
print(f"Error: {msg}")
|
|
9
|
-
sys.exit(1)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def main():
|
|
13
|
-
if len(sys.argv) != 5:
|
|
14
|
-
error("Usage: topsis <InputFile> <Weights> <Impacts> <OutputFile>")
|
|
15
|
-
|
|
16
|
-
input_file, weights, impacts, output_file = sys.argv[1:]
|
|
17
|
-
|
|
18
|
-
if not os.path.exists(input_file):
|
|
19
|
-
error("Input file not found")
|
|
20
|
-
|
|
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")
|
|
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 ----------
|
|
39
|
-
if df.shape[1] < 3:
|
|
40
|
-
error("Input file must contain at least 3 columns")
|
|
41
|
-
|
|
42
|
-
data = df.iloc[:, 1:]
|
|
43
|
-
|
|
44
|
-
try:
|
|
45
|
-
data = data.astype(float)
|
|
46
|
-
except:
|
|
47
|
-
error("Columns from 2nd onward must be numeric")
|
|
48
|
-
|
|
49
|
-
weights = list(map(float, weights.split(",")))
|
|
50
|
-
impacts = impacts.split(",")
|
|
51
|
-
|
|
52
|
-
if len(weights) != len(impacts) or len(weights) != data.shape[1]:
|
|
53
|
-
error("Weights, impacts and criteria count mismatch")
|
|
54
|
-
|
|
55
|
-
if not all(i in ['+', '-'] for i in impacts):
|
|
56
|
-
error("Impacts must be + or -")
|
|
57
|
-
|
|
58
|
-
# ---------- TOPSIS CALCULATION ----------
|
|
59
|
-
norm = data / np.sqrt((data ** 2).sum())
|
|
60
|
-
weighted = norm * weights
|
|
61
|
-
|
|
62
|
-
ideal_best = []
|
|
63
|
-
ideal_worst = []
|
|
64
|
-
|
|
65
|
-
for i, impact in enumerate(impacts):
|
|
66
|
-
if impact == '+':
|
|
67
|
-
ideal_best.append(weighted.iloc[:, i].max())
|
|
68
|
-
ideal_worst.append(weighted.iloc[:, i].min())
|
|
69
|
-
else:
|
|
70
|
-
ideal_best.append(weighted.iloc[:, i].min())
|
|
71
|
-
ideal_worst.append(weighted.iloc[:, i].max())
|
|
72
|
-
|
|
73
|
-
ideal_best = np.array(ideal_best)
|
|
74
|
-
ideal_worst = np.array(ideal_worst)
|
|
75
|
-
|
|
76
|
-
d_pos = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
|
|
77
|
-
d_neg = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
|
|
78
|
-
|
|
79
|
-
score = d_neg / (d_pos + d_neg)
|
|
80
|
-
|
|
81
|
-
df["Topsis Score"] = score
|
|
82
|
-
df["Rank"] = score.rank(ascending=False).astype(int)
|
|
83
|
-
|
|
84
|
-
df.to_csv(output_file, index=False)
|
|
85
|
-
print("TOPSIS completed successfully")
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if __name__ == "__main__":
|
|
89
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{topsis_pranshu_102313009-1.0.2 → topsis_pranshu_102313009-1.0.4}/topsis_pranshu/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|