Skip to content
This repository was archived by the owner on Jun 28, 2018. It is now read-only.

Commit 7da8fbf

Browse files
[IMPLEMENT] Add boxplot graph
1 parent 01eb02a commit 7da8fbf

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

Helper/RestHelper/EdgeXRestHelper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_events(self, video_name):
1919

2020
# print(count)
2121

22-
url_events = self.API_HOST + 'event/device/congo_2048/'+count
22+
url_events = self.API_HOST + 'event/device/'+video_name+'/'+count
2323
resp = requests.get(url=url_events, headers=self.API_HEADERS)
2424

2525
# print(resp.text)

app.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import json
55
import plotly
6+
import plotly.graph_objs as go
67

78
import pandas as pd
89
import numpy as np
@@ -42,9 +43,11 @@ def dashboard():
4243

4344
video_timeSlice = list(range(0, 15000, 500))
4445
video_tile = list()
46+
video_tile_boxplot = list()
4547

4648
for idx in range(0, len(video_timeSlice)):
4749
video_tile.append(0)
50+
video_tile_boxplot.append(list())
4851

4952
for each_event in event_list:
5053
each_ts = each_event['timestamp']
@@ -54,11 +57,22 @@ def dashboard():
5457
tile_num = mappingFovToTile(tile_rows=tile_row, tile_cols=tile_col, yaw=each_yaw, pitch=each_pitch)
5558

5659
idx = int(video_timeSlice.index(int(each_ts)))
60+
print(tile_num)
5761
if video_tile[idx] is 0:
5862
video_tile[idx] = tile_num
5963
else:
6064
video_tile[idx] = round(video_tile[idx] + tile_num) / 2
61-
print(video_tile[idx])
65+
66+
video_tile_boxplot[idx].append(tile_num)
67+
68+
traces = []
69+
70+
for xd, yd in zip(video_timeSlice, video_tile_boxplot):
71+
traces.append(go.Box(
72+
x=xd,
73+
y=yd,
74+
name=str(xd)
75+
))
6276

6377
# for each_tile in video_tile:
6478
# print(each_tile)
@@ -73,40 +87,23 @@ def dashboard():
7387
),
7488
],
7589
layout=dict(
76-
title=str(selected_video_name),
90+
title="Average tile numbers of "+str(selected_video_name),
7791
plot_bgcolor='#F5F7FA'
7892
)
7993
),
8094

8195
dict(
82-
data=[
83-
dict(
84-
x=['totoro', 'gaonasi', 'ponyo', 'yoobaba'],
85-
y=[70, 10, 40, 0],
86-
type='scatter'
87-
),
88-
],
96+
data=traces,
8997
layout=dict(
90-
title='second graph'
98+
title="Boxplot graph for " + str(selected_video_name),
99+
plot_bgcolor='#F5F7FA'
91100
)
92101
),
93-
94-
dict(
95-
data=[
96-
dict(
97-
x=ts.index, # Can use the pandas data structures directly
98-
y=ts
99-
)
100-
],
101-
layout=dict(
102-
title='third graph'
103-
)
104-
)
105102
]
106103

107104
# Add "ids" to each of the graphs to pass up to the client
108105
# for templating
109-
ids = ['graph-{}'.format(i) for i, _ in enumerate(graphs)]
106+
ids = ['Bar graph', 'Boxplot graph']
110107

111108
# Convert the figures to JSON
112109
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
@@ -144,10 +141,10 @@ def mappingFovToTile(tile_rows, tile_cols, yaw, pitch):
144141

145142
# tile_num_row = 4
146143
# tile_num_col = 2
147-
print(tile_num_row)
148-
print(tile_num_col)
144+
# print(tile_num_row)
145+
# print(tile_num_col)
149146
tile_num = tile_rows*(tile_num_col-1) + tile_num_row
150-
print(tile_num)
147+
# print(tile_num)
151148
return tile_num
152149

153150

templates/layouts/dashboard.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ <h3>{{id}}</h3>
2222
<!-- jQuery -->
2323
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
2424
<!-- Plotly.js -->
25-
<script src="https://d14fo0winaifog.cloudfront.net/plotly-basic.js"></script>
26-
25+
{# <script src="https://d14fo0winaifog.cloudfront.net/plotly-basic.js"></script> #}
26+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
2727
<script type="text/javascript">
2828
var graphs = {{graphJSON | safe}};
2929
var ids = {{ids | safe}};
3030
document.title = "IMES Dashboard - {{ video_name }}";
3131

3232

3333
for(var i in graphs) {
34-
Plotly.plot(ids[i], // the ID of the div, created above
34+
Plotly.newPlot(ids[i], // the ID of the div, created above
3535
graphs[i].data,
3636
graphs[i].layout || {});
3737
}

0 commit comments

Comments
 (0)