-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·224 lines (185 loc) · 6.37 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python3
from flask import Flask,render_template,request
from model.Predictor import Predictor
from model.train import xTrain,yTrain
# import mysql.connector
import json
from flask_mysqldb import MySQL
# mydb = mysql.connector.connect(
# host="localhost",
# user="ajay",
# passwd="ajay",
# database='ajay_mariadb'
# )
app=Flask(__name__,static_folder='static')
app.config['MYSQL_HOST'] = "localhost"
app.config['MYSQL_USER'] = "ajay"
app.config['MYSQL_PASSWORD'] = "ajay"
app.config['MYSQL_DB'] = 'ajay_mariadb'
mysql=MySQL(app)
@app.route('/')
def enter_details():
return render_template('form.html')
# @app.route('/save',methods=['POST','GET'])
# def save():
# if request.method=='POST':
# return request.form
@app.route('/details',methods=['POST','GET'])
def details():
if request.method=='POST':
a=[]
obj=request.form
# print(request.form)
a.append(float(obj['companies_resolved'])/float(obj['companies_resolved']))
a.append(float(obj['amount'])/float(obj['sales']))
a.append(float(obj['market_share']))
a.append(float(obj['profits'])/float(obj['amount_business']))
a.append(float(obj['employees'])/float(obj['worth']))
a.append(obj['breaches'])
# print(a)
b=[0.5, 0.1, 0.7, 0.2, 0.3, 0.0]
for i in range(len(a)):
a[i]=float(a[i])
p=Predictor()
result=p.getPrediction(a)
array=[]
count = 0
for i in result:
if i>0:
array.append(count)
count+=1
# print(result)
# print(array)
# company_id=int(obj['id'])
filename = "database.txt"
with open(filename) as f:
content = f.readlines()
id=array
count=0
output=[]
company_data={}
for line in content[1:21]:
# if count==company_id:
# company_data['data']=line[:-1].split(',')
if(count in id):
output.append(line[:-1].split(','))
count+=1
# company_data['companies']=output
# data = json.dumps(company_data)
# print('data',data)
# if len(record)==0:
# q="INSERT INTO company_data(id,companies) VALUES (%s,%s);"
# cursor.execute(q,(company_id,data))
# else:
# q='update company_data set companies=%s where id=%s'
# cursor.execute(q,(data,company_id))
# mysql.connection.commit()
return render_template('show_data.html',data=output)
@app.route('/save',methods=['POST','GET'])
def save():
if request.method=='POST':
a=[]
obj=request.form
# print(request.form)
a.append(float(obj['companies_resolved'])/float(obj['companies_resolved']))
a.append(float(obj['amount'])/float(obj['sales']))
a.append(float(obj['market_share']))
a.append(float(obj['profits'])/float(obj['amount_business']))
a.append(float(obj['employees'])/float(obj['worth']))
a.append(obj['breaches'])
# print(a)
b=[0.5, 0.1, 0.7, 0.2, 0.3, 0.0]
for i in range(len(a)):
a[i]=float(a[i])
p=Predictor()
result=p.getPrediction(a)
array=[]
count = 0
for i in result:
if i>0:
array.append(count)
count+=1
# print(result)
# print(array)
# company_id=int(obj['id'])
filename = "database.txt"
with open(filename) as f:
content = f.readlines()
id=array
count=0
output=[]
company_data={}
for line in content[1:21]:
# if count==company_id:
# company_data['data']=line[:-1].split(',')
if(count in id):
output.append(line[:-1].split(','))
count+=1
company_name=obj['name']
cursor=mysql.connection.cursor()
q='select max(id) from company_data;'
cursor.execute(q)
max_id=cursor.fetchone()
print(max_id[0])
max_id=int(max_id[0])
company_data={
'data':output
}
company_data=json.dumps(company_data)
q1='INSERT INTO company_data(id,data,name) values (%s,%s,%s);'
cursor.execute(q1,(max_id+1,json.dumps(request.form),company_name))
mysql.connection.commit()
# company_data['companies']=output
# data = json.dumps(company_data)
# print('data',data)
# if len(record)==0:
# q="INSERT INTO company_data(id,companies) VALUES (%s,%s);"
# cursor.execute(q,(company_id,data))
# else:
# q='update company_data set companies=%s where id=%s'
# cursor.execute(q,(data,company_id))
# mysql.connection.commit()
return render_template('form.html',id=max_id+1)
if request.method=='GET':
return render_template('form.html')
@app.route('/<id>',methods=['GET'])
def get_company(id):
cursor=mysql.connection.cursor()
q="select name,data from company_data where id={0};".format(id)
cursor.execute(q)
record = cursor.fetchone()
obj=json.loads(record[1])
a=[]
# print(type(data['data']))
a.append(float(obj['companies_resolved'])/float(obj['companies_resolved']))
a.append(float(obj['amount'])/float(obj['sales']))
a.append(float(obj['market_share']))
a.append(float(obj['profits'])/float(obj['amount_business']))
a.append(float(obj['employees'])/float(obj['worth']))
a.append(float(obj['breaches'])/12)
for i in range(len(a)):
a[i]=float(a[i])
p=Predictor()
result=p.getPrediction(a)
count=0
array=[]
for i in result:
if i>0:
array.append(count)
count+=1
filename = "database.txt"
with open(filename) as f:
content = f.readlines()
id=array
count=0
output=[]
company_data={}
for line in content[1:21]:
# if count==company_id:
# company_data['data']=line[:-1].split(',')
if(count in id):
output.append(line[:-1].split(','))
count+=1
return render_template('show_data.html',data=output,name=record[0])
if __name__ == '__main__':
app.run(debug=True)