Topsis-Lakshay-102303872 0.0.1__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,2 @@
1
+ from .topsis import topsis
2
+ __version__ = "0.0.1"
@@ -0,0 +1,84 @@
1
+ import sys
2
+ import pandas as pd
3
+ import numpy as np
4
+ import os
5
+
6
+ def topsis(input_file, weights, impacts, output_file):
7
+
8
+ # checking the file
9
+ if not os.path.isfile(input_file):
10
+ print("Error: Input file not found")
11
+ sys.exit(1)
12
+
13
+ df = pd.read_csv(input_file)
14
+
15
+ if df.shape[1] < 3:
16
+ print("Error: Input file must contain three or more columns")
17
+ sys.exit(1)
18
+
19
+ data = df.iloc[:, 1:].values
20
+
21
+ try:
22
+ data = data.astype(float)
23
+ except:
24
+ print("Error: From 2nd column to last column must be numeric")
25
+ sys.exit(1)
26
+
27
+ weights = weights.split(',')
28
+ impacts = impacts.split(',')
29
+
30
+ if len(weights) != data.shape[1] or len(impacts) != data.shape[1]:
31
+ print("Error: Number of weights, impacts and columns must be same")
32
+ sys.exit(1)
33
+
34
+ weights = np.array(weights, dtype=float)
35
+
36
+ for i in impacts:
37
+ if i not in ['+', '-']:
38
+ print("Error: Impacts must be either + or -")
39
+ sys.exit(1)
40
+
41
+ # normalization
42
+ n_factor = np.sqrt((data ** 2).sum(axis=0))
43
+ normalized = data / n_factor
44
+
45
+ # applying the wieghts to normalized matrix
46
+ weighted = normalized * weights
47
+
48
+ # ideal best and ideal worst
49
+ ideal_best = []
50
+ ideal_worst = []
51
+
52
+ for i in range(len(impacts)):
53
+ if impacts[i] == '+':
54
+ ideal_best.append(weighted[:, i].max())
55
+ ideal_worst.append(weighted[:, i].min())
56
+ else:
57
+ ideal_best.append(weighted[:, i].min())
58
+ ideal_worst.append(weighted[:, i].max())
59
+
60
+ ideal_best = np.array(ideal_best)
61
+ ideal_worst = np.array(ideal_worst)
62
+
63
+ # finding the distance
64
+ dist_best = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
65
+ dist_worst = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
66
+
67
+ # score calculation
68
+ score = dist_worst / (dist_best + dist_worst)
69
+
70
+ df['Topsis Score'] = score
71
+ df['Rank'] = df['Topsis Score'].rank(ascending=False).astype(int)
72
+
73
+ df.to_csv(output_file, index=False)
74
+ print("TOPSIS successfully completed")
75
+
76
+ def main():
77
+ if len(sys.argv) != 5:
78
+ print("Usage: topsis <inputfile> <weights> <impacts> <outputfile>")
79
+ sys.exit(1)
80
+
81
+ topsis(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
82
+
83
+ if __name__ == "__main__":
84
+ main()
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: Topsis-Lakshay-102303872
3
+ Version: 0.0.1
4
+ Summary: TOPSIS CLI tool for multi-criteria decision making
5
+ Author-email: Lakshay <lsawhney07@gmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: pandas
10
+ Requires-Dist: numpy
11
+
12
+ # Topsis-Lakshay-102303872
13
+
14
+ A Python package that implements **TOPSIS (Technique for Order Preference by Similarity to Ideal Solution)** as a command-line tool.
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ Install the package from PyPI using pip:
21
+
22
+ ```bash
23
+ pip install Topsis-Lakshay-102303872
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Command Line Usage
29
+
30
+ After installation, the TOPSIS program can be executed using the `topsis` command.
31
+
32
+ ```bash
33
+ topsis <InputDataFile> <Weights> <Impacts> <OutputResultFileName>
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Example
39
+
40
+ ```bash
41
+ topsis data.csv "1,1,1,2,1" "+,+,-,+,-" result.csv
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Input File Format
47
+
48
+ The input file must be a CSV file with:
49
+ - First column containing alternative names (non-numeric)
50
+ - Remaining columns containing numeric criteria values
51
+
52
+ Example `data.csv`:
53
+ ```csv
54
+ Fund Name,P1,P2,P3,P4,P5
55
+ M1,0.67,0.45,6.5,42.6,12.56
56
+ M2,0.60,0.36,3.5,53.3,14.47
57
+ M3,0.82,0.67,3.8,63.1,17.10
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Output File Format
63
+
64
+ The output CSV file contains all original columns along with:
65
+ - **Topsis Score**
66
+ - **Rank**
67
+
68
+ A higher Topsis Score indicates a better alternative.
69
+
70
+ ---
71
+
72
+ ## Validations Performed
73
+
74
+ - Correct number of command-line arguments
75
+ - Input file existence check
76
+ - Minimum of three columns in input file
77
+ - Numeric values in criteria columns
78
+ - Number of weights equals number of criteria
79
+ - Number of impacts equals number of criteria
80
+ - Impacts must be either `+` or `-`
81
+
82
+ ---
83
+
84
+ ## Author
85
+
86
+ Lakshay
87
+ Roll Number: 102303872
88
+
89
+ ---
90
+
91
+ ## License
92
+
93
+ MIT License
@@ -0,0 +1,7 @@
1
+ topsis_lakshay_102303872/__init__.py,sha256=_6ihuPBOaTFYivGr810edtEmv4DmfZvCyHURcpPQDEo,49
2
+ topsis_lakshay_102303872/topsis.py,sha256=fXhqFwFyBedJ_mSiY0X6_1pbZPidHRZy-4ar3FwYzyU,2372
3
+ topsis_lakshay_102303872-0.0.1.dist-info/METADATA,sha256=K2FexA4f05GOSadtVxHkVRekSsZLDT8J-rppvXjCmFI,1821
4
+ topsis_lakshay_102303872-0.0.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ topsis_lakshay_102303872-0.0.1.dist-info/entry_points.txt,sha256=Rar3lDcmxoH-mlyO7SSCo4z7cY2k_VtKGbkYDehEQHE,64
6
+ topsis_lakshay_102303872-0.0.1.dist-info/top_level.txt,sha256=pYxayDZwQvsgB4q-OSFBYY5aW9lmG_Zo8sgdrRe0XuU,25
7
+ topsis_lakshay_102303872-0.0.1.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_lakshay_102303872.topsis:main
@@ -0,0 +1 @@
1
+ topsis_lakshay_102303872