Skip to main content

TOPSIS decision method Python package

Project description

TOPSIS Implementation - Sachin Goyal

Python PyPI License

A complete TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) implementation in Python with both CLI and Web Service interfaces.


๐Ÿš€ Quick Start

๐Ÿ“ฆ Install from PyPI

pip install topsis-sachingoyal-102303557==1.0.0

๐ŸŒ Try the Web Interface

Access the live web service at:
https://topsis-sachin-goyal-102303557.vercel.app/

Upload your CSV, enter weights and impacts, and receive results via email!


๐Ÿ“ Project Structure

Topsis_SachinGoyal_102303557/
โ”‚
โ”œโ”€โ”€ topsis/                     # Python package
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ topsis.py               # Core TOPSIS implementation
โ”‚
โ”œโ”€โ”€ templates/                  # Web frontend
โ”‚   โ””โ”€โ”€ index.html              # Beautiful web UI
โ”‚
โ”œโ”€โ”€ uploads/                    # Temporary file storage (created automatically)
โ”‚
โ”œโ”€โ”€ main.py                     # FastAPI backend server
โ”œโ”€โ”€ data.csv                    # Sample input data
โ”œโ”€โ”€ setup.py                    # Package setup configuration
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ sample.env                  # Environment variables template
โ”œโ”€โ”€ README.md                   # This file

๐Ÿ“‹ Requirements

  • Python 3.6+
  • Dependencies: pandas, numpy, fastapi, mailjet-rest, python-dotenv

Install all dependencies:

pip install -r requirements.txt

๐Ÿ”ง Setup for Local Development

1. Clone the Repository

git clone <https://github.com/SachinGoyal94/Topsis_SachinGoyal_102303557>
cd Topsis_SachinGoyal_102303557

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment Variables

Create a .env file in the project root with the following:

SENDER_NAME=Your Name
SENDER_EMAIL=your-verified-email@example.com
MJ_APIKEY_PUBLIC=your-mailjet-public-key
MJ_APIKEY_PRIVATE=your-mailjet-private-key

Note: A sample.env file is provided as a template. Copy it to .env and fill in your credentials.

Required Variables:

  • SENDER_NAME - Your name or service name
  • SENDER_EMAIL - Verified sender email in Mailjet
  • MJ_APIKEY_PUBLIC - Your Mailjet API public key
  • MJ_APIKEY_PRIVATE - Your Mailjet API secret key

4. Run the Backend Server

uvicorn main:app --reload

The API will be available at http://127.0.0.1:8000

5. Open the Frontend

Navigate to http://127.0.0.1:8000 in your browser (if serving static files) or open templates/index.html directly.


๐Ÿ’ป CLI Usage

Command Syntax

python -m topsis.topsis <InputFile> "<Weights>" "<Impacts>" <OutputFile>

Arguments

Argument Description Example
InputFile Path to input CSV file data.csv
Weights Comma-separated numeric weights "1,1,1,1,2"
Impacts Comma-separated + or - "+,+,-,+,+"
OutputFile Path for output CSV result.csv

Example

python -m topsis.topsis data.csv "1,1,1,1,2" "+,+,+,-,+" result.csv

Output: Creates result.csv with two additional columns:

  • Topsis Score (higher is better)
  • Rank (1 = best)

๐Ÿ“Š Input CSV Format

Your CSV must have:

  • First column: Identifier (e.g., product name, model ID)
  • Remaining columns: Numeric criteria values

Example Input

Name,Cost,Performance,Reliability,Efficiency
ProductA,250,8,9,7
ProductB,200,7,8,9
ProductC,300,9,7,8

Example Output

Name,Cost,Performance,Reliability,Efficiency,Topsis Score,Rank
ProductA,250,8,9,7,0.534,2
ProductB,200,7,8,9,0.628,1
ProductC,300,9,7,8,0.421,3

๐ŸŒ Web Service Usage

  1. Visit: https://topsis-sachin-goyal-102303557.vercel.app/
  2. Upload your CSV file
  3. Enter weights (e.g., 1,1,1)
  4. Enter impacts (e.g., +,+,-)
  5. Enter your email address
  6. Submit and receive results via email

โš ๏ธ Common Errors

Error Cause Solution
Input file not found File path is incorrect Check file path and try again
Invalid email format Email is malformed Use valid email format
Weights and impacts count mismatch Different number of weights vs impacts Ensure equal counts
Impacts must be + or - Invalid impact symbol Use only + or -
Weights must be numeric Non-numeric weight Use only numbers
All columns must be numeric Non-numeric criteria values Ensure all criteria are numbers

๐Ÿ“š How TOPSIS Works

  1. Normalize the decision matrix using Euclidean normalization
  2. Weight the normalized matrix
  3. Identify ideal best and worst solutions
  4. Calculate Euclidean distances from ideal solutions
  5. Compute similarity score: S = D- / (D+ + D-)
  6. Rank alternatives by score (higher is better)

๐Ÿ› ๏ธ Technology Stack

  • Backend: FastAPI (Python)
  • Frontend: HTML, CSS, JavaScript
  • Email Service: Mailjet REST API
  • Package Management: PyPI
  • Deployment:
    • Frontend: Vercel
    • Backend: Render

๐Ÿ‘ค Author

Sachin Goyal


๐Ÿ”— Links


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topsis_sachin_102303557-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file topsis_sachin_102303557-1.0.0.tar.gz.

File metadata

  • Download URL: topsis_sachin_102303557-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for topsis_sachin_102303557-1.0.0.tar.gz
Algorithm Hash digest
SHA256 951e64f2b8f96a51ecc8c27c683522a1610fd1945940c17860ba81557ef65da9
MD5 1009a2574236df9055f37b0143104023
BLAKE2b-256 b23c1445a25eeadfb78d6623d62fd1c0bc676b51e7553fbccbd9a10e26dab08b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page