-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
234 lines (182 loc) · 6.86 KB
/
main.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
225
226
227
228
229
230
231
232
233
234
from flask import Flask, jsonify, request
from flask_cors import CORS
from sklearn import cluster
from mts.core.mtserie_dataset import MTSerieDataset
# from mts.core.projections import ProjectionAlg
from models.emotion_dataset_controller import *
import json
import numpy as np
from flask import jsonify
app = Flask(__name__)
CORS(app)
appController = AppController()
@app.route('/')
def index():
return "<h1>Welcome to our server !!</h1>"
@app.route("/routeGetDatasetsInfo", methods=['POST'])
def getDatasetsInfo():
return jsonify({
"loadedDatasetsIds": appController.loadedDatasets,
"localDatasetsIds": appController.localDatasetsIds,
})
@app.route("/loadLocalDataset", methods=['POST'])
def loadLocalDataset():
datasetId = request.form.get('datasetId')
succed = appController.loadLocalDataset(datasetId)
return jsonify({
"state": "success" if succed else "error"
})
@app.route("/removeDataset", methods=['POST'])
def removeDataset():
datasetId = request.form.get('datasetId')
succed = appController.removeDataset(datasetId)
return jsonify({
"state": "success" if succed else "error"
})
@app.route("/initializeDataset", methods=['POST'])
def initializeDataset():
datasetInfoJson = request.form.get('datasetInfo')
datasetId = appController.initializeDataset(datasetInfoJson)
print(f"Initialized: {datasetId}")
return jsonify({
"id": datasetId
})
@app.route("/addEmlToDataset", methods=['POST'])
def addEmlToDataset():
eml = request.form.get('eml')
datasetId = request.form.get('datasetId')
succed = appController.addEmlToDataset(datasetId, eml)
return jsonify({
"state": "success" if succed else "error"
})
@app.route("/getDatasetInfo", methods=['POST'])
def getDatasetInfo():
datasetId = request.form.get('datasetId')
dataInfo = appController.getDatasetInfo(datasetId)
return jsonify(dataInfo)
@app.route("/getMTSeries", methods=['POST'])
def getMTSeries():
datasetId = request.form.get('datasetId')
begin = int(request.form.get('begin'))
end = int(request.form.get('end'))
ids = json.loads(request.form.get('ids'))
saveEmotions = request.form.get('saveEmotions', type=int)
if saveEmotions == 1:
saveEmotions = True
else:
saveEmotions = False
return jsonify(
appController.getMTSeriesInRange(
datasetId, ids, begin, end, saveEmotions=saveEmotions)
)
@app.route("/downsampleData", methods=['POST'])
def downsampleData():
datasetId = request.form.get('datasetId')
rule = request.form.get('rule')
appController.downsampleDataset(datasetId, rule)
return jsonify({
"state": "success"
})
@app.route("/resetDataset", methods=['POST'])
def resetDataset():
datasetId = request.form.get('datasetId')
appController.resetDataset(datasetId)
return jsonify({
"state": "success"
})
"""
distance: 0 for euclidean, 1 for DTW, 2 for MPDist
"""
@app.route("/getDatasetProjection", methods=['POST'])
def getDatasetProjection():
datasetId = request.form.get('datasetId')
begin = request.form.get('begin', type=int)
end = request.form.get('end', type=int)
distance = request.form.get('distance', type=int)
projectionParameter = request.form.get('projectionParameter', 5, type=int, )
oldCoords = json.loads(request.form.get('oldCoords'))
if len(oldCoords) == 0:
oldCoords = None
else:
oldCoords = np.array(list(oldCoords.values()))
alphas = json.loads(request.form.get('alphas'))
# distanceType = DistanceType(distance)
# projectionAlg = ProjectionAlg.UMAP
print("parameter")
print(projectionParameter)
coords = appController.getProjection(
datasetId,
begin, end,
oldCoords=oldCoords,
projectionParam=projectionParameter
)
return jsonify({'coords': coords})
@app.route("/kmeansClustering", methods=['POST'])
def kmeansClustering():
datasetId = request.form.get('datasetId')
coords = json.loads(request.form.get('coords'))
k = int(request.form.get('k'))
clusters = appController.kmeans_clustering(
datasetId, coords, k=k
)
clusters = {int(k): clusters[k] for k in clusters.keys()}
return jsonify(clusters)
@app.route("/dbscanClustering", methods=['POST'])
def dbscanClustering():
datasetId = request.form.get('datasetId')
coords = json.loads(request.form.get('coords'))
min_samples = int(request.form.get('min_samples'))
eps = float(request.form.get('eps'))
clusters = appController.dbscan_clustering(
datasetId, coords, eps=eps, min_samples=min_samples
)
clusters = {int(k): clusters[k] for k in clusters.keys()}
# removing outliers
clusters.pop(-1, None)
return jsonify(clusters)
@app.route("/getFishersDiscriminantRanking", methods=['POST'])
def getFishersDiscriminantRanking():
datasetId = request.form.get('datasetId')
# D_k = json.loads(request.form.get('D_k'))
# D_k = {key: np.array(D_k[key]) for key in D_k.keys()}
blueCluster = json.loads(request.form.get('blueCluster'))
redCluster = json.loads(request.form.get('redCluster'))
j_s = appController.getFishersDiscriminantRanking(
datasetId, blueCluster, redCluster)
return jsonify(j_s)
@app.route("/getTemporalSummary", methods=['POST'])
def getTemporalSummary():
datasetId = request.form.get('datasetId')
temporalSummary = appController.getTemporalSummary(datasetId)
return jsonify(temporalSummary)
@app.route("/getTemporalGroupSummary", methods=['POST'])
def getTemporalGroupSummary():
datasetId = request.form.get('datasetId')
begin = request.form.get('begin', type=int)
end = request.form.get('end', type=int)
ids = json.loads(request.form.get('ids'))
temporalSummary = appController.getTemporalGroupSummary(
datasetId, ids, begin, end)
return jsonify(temporalSummary)
@app.route("/getInstanceGroupSummary", methods=['POST'])
def getInstanceGroupSummary():
datasetId = request.form.get('datasetId')
begin = request.form.get('begin', type=int)
end = request.form.get('end', type=int)
ids = json.loads(request.form.get('ids'))
temporalSummary = appController.getInstanceGroupSummary(
datasetId, ids, begin, end)
return jsonify(temporalSummary)
@app.route("/getValenceArousalHistogram", methods=['POST'])
def getValenceArousalHistogram():
datasetId = request.form.get('datasetId')
begin = request.form.get('begin', type=int)
end = request.form.get('end', type=int)
ids = json.loads(request.form.get('ids'))
arousal = request.form.get('arousal')
valence = request.form.get('valence')
histogram, maxCellCount = appController.getValenceArousalHistogram(
datasetId, ids, begin, end, valence, arousal)
return jsonify({'histogram': histogram, 'cellCount': maxCellCount})
if __name__ == "__main__":
app.run()