# -*- coding: utf-8 -*-
"""Untitled5.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1hht-0qPL9Mhbi9qwoQLnMruCi2Ss-HNO
"""

import pandas as pd
import sys
import numpy as np
import math

df= pd.read_csv("data.csv")
df

dataframe=df.to_numpy()
print(dataframe)
dataframe=np.delete(dataframe,0,1)
print(dataframe)

lst=[]
n = 5
ele=0
nrow=dataframe.shape[0]
print(nrow)
ncol=dataframe.shape[1]  
# iterating till the range
for i in range(0, ncol):
  for j in range(0,nrow):
    s=dataframe[j,i]*dataframe[j,i]
    ele=ele+s;
  
  lst.append(math.sqrt(ele)) # adding the element
for i in range(0, ncol):  
   lst[i]=round(lst[i],3)      
print(lst)

df1=dataframe
#print(df1)
for i in range(0, ncol):
  for j in range(0,nrow):
    df1[j,i]=df1[j,i]/lst[i]
    df1[j,i]=round(df1[j,i],3)
print(df1)

l=[]
for i in range(0, n):
    e = int(input("Enter the individual weightage"))
  
    l.append(e) # adding the element

for i in range(0, ncol):
  for j in range(0,nrow):
    df1[j,i]=df1[j,i]*l[i]

print(df1)

im=[]
for i in range(0, n):
    string = input("Enter the impact value:")
    im.append(string)

ib=[]
iw=[]
for i in range(0,ncol):
    if(im[i]=="+"):
      ib.append(df1[:,i].max(0))
      iw.append(df1[:,i].min(0))
    else:
      ib.append(df1[:,i].min(0))
      iw.append(df1[:,i].max(0))

print(ib)
print(iw)

sw=[]
sb=[]

for i in range (0,nrow):
  s1=0
  s2=0
  for j in range (0,ncol):
    x=pow(df1[i,j]-ib[j],2)
    y=pow(df1[i,j]-iw[j],2)
    s1=s1+x
    s2=s2+y  
  sb.append(math.sqrt(s1)) 
  sw.append(math.sqrt(s2)) 
print(sb)
print(sw)

p=[]
for k in range(0,nrow):
  p.append(sw[k]/(sb[k]+sw[k]))

print(p)

#arr = np.append(df1, p, axis=1)
p1=pd.DataFrame(p)
print(p1)
#np.insert(df,p1,axis=0)
#df.insert(6,"Topsis Score",p,True)

kriti=df.join(p1)

print(kriti)

#Topsis_score=pd.DataFrame("0")
k1=kriti.rename(columns={0:'Topsis_score'})

print(k1)

rank=k1.sort_values(['Topsis_score'],ascending=False).index
k1['Rank']=pd.Series(range(1,len(k1)+1),index=rank)
k1

k1.to_csv("Output_file.csv")

