-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
159 lines (106 loc) · 4.34 KB
/
api.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
import analysis
import machineLearning
from flask import Flask, session, request, render_template, redirect, url_for, flash
from werkzeug.utils import secure_filename
import os
import json
import matplotlib
matplotlib.use('Agg')
UPLOAD_FOLDER = './files'
ALLOWED_EXTENSIONS = set(['csv'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# make this like the image html in cloud
@app.route("/", methods=['GET', 'POST'])
def uploadFile():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
columns = analysis.getColumns(filename)
return render_template('analysis.html', columns=columns, filename=filename)
return render_template('upload.html')
@app.route("/bar-chart")
def barChart():
file = request.args.get('file')
column1 = request.args.get('column1')
sort = request.args.get('sort')
bars = request.args.get('bars')
plot_name = analysis.barChart(file, column1, sort, bars)
return render_template('result.html', plot=plot_name, score='none')
@app.route("/line-chart")
def lineChart():
file = request.args.get('file')
time = request.args.get('column1')
col2 = request.args.get('column2')
col3 = request.args.get('column3')
col4 = request.args.get('column4')
bins = request.args.get('bins')
plot_name = analysis.lineChart(file, time, col2, col3, col4, bins)
return render_template('result.html', plot=plot_name, score='none')
@app.route("/scatter-plot")
def scatterPlot():
file = request.args.get('file')
column1 = request.args.get('column1')
column2 = request.args.get('column2')
bins = request.args.get('bins')
plot_name = analysis.scatterPlot(file, column1, column2, bins)
return render_template('result.html', plot=plot_name, score='none')
@app.route("/histogram-plot")
def histogramPlot():
file = request.args.get('file')
column1 = request.args.get('column1')
column2 = request.args.get('column2')
stat = request.args.get('stat')
bins = request.args.get('bins')
plot_name = analysis.histogramPlot(file, column1, column2, stat, bins)
return render_template('result.html', plot=plot_name, score='none')
@app.route("/box-plot")
def boxPlot():
file = request.args.get('file')
column1 = request.args.get('column1')
column2 = request.args.get('column2')
hue = request.args.get('column3')
bins = request.args.get('bins')
plot_name = analysis.boxPlot(file, column1, column2, hue, bins)
return render_template('result.html', plot=plot_name, score='none')
@app.route("/map-plot")
def mapPlot():
file = request.args.get('file')
lonlat = request.args.get('lonlat')
plot_col = request.args.get('column2')
countries = request.args.get('column3')
plot_name = analysis.mapPlot(file, lonlat, countries, plot_col)
return render_template('result.html', plot=plot_name, score='none')
@app.route("/gaussian-nb")
def gaussianNB():
target = request.args.get('target')
features = request.args.getlist('features')
print('targ: ', target)
print('feat: ', features)
plot_name, score = machineLearning.gaussianNB(target, features)
return render_template('result.html', plot=plot_name, score=score)
@app.route("/kmeans")
def kMeans():
features = request.args.getlist('features')
plot_name, score = machineLearning.kMeans(features)
return render_template('result.html', plot=plot_name, score=score)
@app.route("/regression")
def regression():
target = request.args.get('target')
feature = request.args.getlist('feature')
plot_name, score = machineLearning.regression(target, feature)
return render_template('result.html', plot=plot_name, score=score)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS