Skip to content

Commit 19c4def

Browse files
author
geekshe
committed
Experimenting with nested ddictionaries with date as key. This supports a date picker for filtering.
1 parent e32e8be commit 19c4def

File tree

2 files changed

+81
-45
lines changed

2 files changed

+81
-45
lines changed

server_functions.py

+35-12
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,47 @@ def get_call_name(call_id):
135135

136136

137137
def create_call_row(env_filter):
138+
""" Returns data in this format:
139+
{date: [call_name: {call_id: 3}, call_name: {call_id: 3}, call_name: {call_id: 3}]}
140+
"""
138141

139142
env_filter = env_filter
140143

141144
env_total = get_env_total(env_filter)
142145

143146
# Object containing individual agg_requests
144-
env_calls = get_agg_request(env_filter)
147+
all_dates = get_agg_request(env_filter)
148+
group_by_date = {}
145149

146-
call_rows = []
150+
calls = []
151+
call = {}
152+
call_values = {}
147153

148-
for obj in env_calls:
149-
row = {}
150-
row['call_id'] = obj.call_id
151-
# TODO: If call_id has already been used, use the same call name, and add the success count
152-
row['call_name'] = get_call_name(obj.call_id)
153-
row['percent_volume'] = round(obj.success_count / env_total, 2)
154-
row['call_latency'] = obj.avg_response_time
155-
row['date'] = obj.date
156-
call_rows.append(row)
154+
for obj in all_dates:
155+
group_by_date = {}
156+
date_val = []
157+
# group_by_date['date'] = date_val
158+
call_name = {}
159+
values = {}
157160

158-
return call_rows
161+
# get_call_name(obj.call_id)
162+
163+
# values['call_id'] = obj.call_id
164+
# # TODO: If call_id has already been used, use the same call name, and add the success count
165+
# # values['call_name'] = get_call_name(obj.call_id)
166+
# values['percent_volume'] = round(obj.success_count / env_total, 2)
167+
# values['call_latency'] = obj.avg_response_time
168+
# # values['date'] = obj.date
169+
170+
# group_by_date[get_call_name(obj.call_id)] = values
171+
# date_val.append(group_by_date)
172+
173+
174+
# if obj.date in by_date:
175+
176+
# by_date[obj.date] = row
177+
178+
# call_rows.append(by_date)
179+
180+
181+
return group_by_date

templates/env.html

+46-33
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,59 @@
22
{% block content %}
33

44
<!-- jQuery -->
5-
<script src="https://code.jquery.com/jquery.js"></script>
5+
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
6+
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
7+
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
8+
9+
<script>
10+
$( function() {
11+
$( "#datepicker" ).datepicker();
12+
$( "#anim" ).on( "change", function() {
13+
$( "#datepicker" ).datepicker( "option", "showAnim", $( this ).val() );
14+
});
15+
} );
16+
</script>
17+
618

719
<!-- Google Charts API -->
820
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
921

10-
<!-- /.col-lg-4 -->
11-
<div class="col-lg-4">
12-
<div class="panel panel-default">
13-
<div class="panel-heading">
14-
Donut Chart Example
15-
</div>
16-
<!-- /.panel-heading -->
17-
<div class="panel-body">
18-
<div id="morris-donut-chart"></div>
19-
20-
<script type="text/javascript">
21-
$(function() {
22-
23-
// Donut Chart
24-
Morris.Donut({
25-
element: 'morris-donut-chart',
26-
data: [
27-
{% for call in prod_calls %}
28-
{
29-
label: "{{ call['call_name'] }}",
30-
value: {{ call['percent_volume'] }}
31-
},
32-
{% endfor %}
33-
],
34-
resize: true
22+
<div class="row">
23+
<!-- /.col-lg-4 -->
24+
<div class="col-lg-4">
25+
<div class="panel panel-default">
26+
<div class="panel-heading">
27+
API Calls by Volume (morris)
28+
</div>
29+
<!-- /.panel-heading -->
30+
<div class="panel-body">
31+
<p>Date: <input type="text" id="datepicker" size="30"></p>
32+
<div id="morris-donut-prod"></div>
33+
<script type="text/javascript">
34+
$(function() {
35+
36+
// Donut Chart
37+
Morris.Donut({
38+
element: 'morris-donut-prod',
39+
data: [
40+
{% for call in prod_calls %}
41+
{
42+
label: "{{ call['call_name'] }}",
43+
value: {{ call['percent_volume'] }}
44+
},
45+
{% endfor %}
46+
],
47+
resize: true
48+
});
3549
});
36-
});
37-
</script>
38-
</div>
39-
<!-- /.panel-body -->
40-
</div>
41-
<!-- /.panel -->
50+
</script>
51+
</div>
52+
<!-- /.panel-body -->
53+
</div>
54+
<!-- /.panel -->
55+
</div>
4256
</div>
4357

44-
4558
<h1>API Calls by Volume</h1>
4659

4760
<!-- Identify where the chart should be drawn. -->

0 commit comments

Comments
 (0)