This repository was archived by the owner on Jun 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
161 lines (123 loc) · 4.64 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
# https://plot.ly/python/bar-charts/
from flask import Flask, render_template, request, jsonify
import os
import json
import plotly
import plotly.graph_objs as go
from Helper.DataHelper import EdgeXInitHelper
from Helper.RestHelper.EdgeXRestHelper import VideoFovRestHelper
app = Flask(__name__)
app.debug = True
def load_videoList():
with open('Contents/contents.json') as f:
data = json.load(f)
list_videos = data["video_names"]
return jsonify(list_videos=list_videos)
@app.route('/video/list', methods=['GET'])
def get_videoList():
return load_videoList()
@app.route('/')
def index():
# mappingFovToTile(3, 3, 95, -100)
videos_list = load_videoList()
videos_types = ['3x4', '3x4']
videos_models = ['OVER_UNDER', 'EQUALRECT']
EdgeXInitHelper.initEdgeXWithVideoInformations(videos=videos_list, videos_types=videos_types, videos_models=videos_models,
edgex_host='http://localhost:48081/api/v1/')
return render_template('layouts/index.html',
videos=videos_list)
@app.route('/dashboard', methods=['GET', 'POST'])
def dashboard():
selected_video_name = request.form.get('selected_video')
fovRestHelper = VideoFovRestHelper(API_HOST='http://localhost:48080/api/v1/')
event_list = fovRestHelper.get_events(video_name=selected_video_name)
tile_row = 3
tile_col = 3
video_timeSlice = list(range(0, 15000, 500))
video_tile = list()
video_tile_boxplot = list()
for idx in range(0, len(video_timeSlice)):
video_tile.append(0)
video_tile_boxplot.append(list())
for each_event in event_list:
each_ts = each_event['timestamp']
each_yaw = each_event['yaw']
each_pitch = each_event['pitch']
tile_num = mappingFovToTile(tile_rows=tile_row, tile_cols=tile_col, yaw=each_yaw, pitch=each_pitch)
idx = int(video_timeSlice.index(int(each_ts)))
print(tile_num)
if video_tile[idx] is 0:
video_tile[idx] = tile_num
else:
video_tile[idx] = round(video_tile[idx] + tile_num) / 2
video_tile_boxplot[idx].append(tile_num)
traces = []
for xd, yd in zip(video_timeSlice, video_tile_boxplot):
traces.append(go.Box(
x=xd,
y=yd,
name=str(xd)
))
# for each_tile in video_tile:
# print(each_tile)
graphs = [
dict(
data=[
dict(
x=video_timeSlice, # timestamp
y=video_tile, # tile number
type='bar'
),
],
layout=dict(
title="Average tile numbers of "+str(selected_video_name),
plot_bgcolor='#F5F7FA'
)
),
dict(
data=traces,
layout=dict(
title="Boxplot graph for " + str(selected_video_name),
plot_bgcolor='#F5F7FA'
)
),
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids = ['Bar graph', 'Boxplot graph']
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('layouts/dashboard.html',
video_name=selected_video_name,
ids=ids,
graphJSON=graphJSON)
def mappingFovToTile(tile_rows, tile_cols, yaw, pitch):
fov_range_tile_rows = list()
fov_range_tile_cols = list()
range_start = -180
range_step_row = int(360 / tile_rows)
range_step_cols = int(360 / tile_cols)
for idx in range(0, tile_rows):
fov_range_tile_rows.append(list(range(range_start, range_start+range_step_row)))
range_start += range_step_row
for item in fov_range_tile_rows:
if int(str(yaw).split('.')[0]) in item:
tile_num_row = int(fov_range_tile_rows.index(item))+1
range_start = 180
for idx in range(0, tile_cols):
fov_range_tile_cols.append(list(range(range_start, range_start-range_step_cols, -1)))
range_start -= range_step_cols
for item in fov_range_tile_cols:
if int(str(pitch).split('.')[0]) in item:
tile_num_col = int(fov_range_tile_cols.index(item))+1
# tile_num_row = 4
# tile_num_col = 2
# print(tile_num_row)
# print(tile_num_col)
tile_num = tile_rows*(tile_num_col-1) + tile_num_row
# print(tile_num)
return tile_num
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9999, debug=True)