import csv
import math
import pandas as pd
import numpy as np
def azureml_main( data, ud):
FinanceDept = []
LogisticsDept = []
QualityDept = []
#Reading from the csv files
with open('.\Script Bundle\\quality1.csv', 'rb') as fin:
reader = csv.reader(fin)
QualityDept = list(reader)
with open('.\Script Bundle\\finance1.csv', 'rb') as f:
reader = csv.reader(f)
FinanceDept = list(reader)
with open('.\Script Bundle\\logistics1.csv', 'rb') as f:
reader = csv.reader(f)
LogisticDept = list(reader)
FinanceList = []
LogisticsList = []
QualityList = []
#Initializing the Lists
FinanceList.append(0)
LogisticsList.append(0)
QualityList.append(0)
rev = data['Data']
v = rev[0].split('.')
print FinanceDept
S = 0
for sentence in v:
S = S + 1
z = sentence.split(' ')
for c in z:
c = c.lower()
if c in FinanceDept and S not in FinanceList:
FinanceList.append(S)
if c in LogisticsDept and S not in LogisticsList:
LogisticsList.append(S)
if c in QualityDept and S not in QualityList:
QualityList.append(S)
#Compute User Reputation Score
Upvotes = int(ud['upvotes'].tolist()[0])
Downvotes = int(ud['downvotes'].tolist()[0])
TotalVotes = max(1,Upvotes+Downvotes)
q = data['Score']
print FinanceList
repScore = float(Upvotes)/TotalVotes
repScore = repScore*float( q[0] )
str1 = ','.join(str(e) for e in FinanceList)
str2 = ','.join(str(e) for e in QualityList)
str3 = ','.join(str(e) for e in LogisticsList)
x = ud['id']
#df = pd.DataFrame( [str(repScore), str1 , str2 , str3 ], columns=[Write the columns])
d = {'id': x[0], 'Score': float(repScore),'Logistics':str3,'Finance':str1,'Quality':str2}
df = pd.DataFrame(data=d, index=np.arange(1))
return df