Skip to content

Commit f424ee4

Browse files
author
kuivenhoven1
committed
Building new chart
1 parent 0f6fb44 commit f424ee4

File tree

4 files changed

+243
-36
lines changed

4 files changed

+243
-36
lines changed

statsPage/templates/base.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
<ul class="dropdown-menu" role="menu">
3838
<li><a style="color:black; font-size:125%" href="/stats/all_years_pie/">All Years Stats</a></li>
3939
<li><a style="color:black; font-size:125%" href="/stats/pie_by_year/">By Year Stats</a></li>
40-
<li><a style="color:black; font-size:125%" href="/stats/testing/">Testing Page</a></li>
4140
</ul>
4241
</div>&nbsp;
4342
<div class="btn-group">
@@ -58,6 +57,15 @@
5857
<li><a style="color:black; font-size:125%" href="/stats/most_used_pie/">Actions Stats</a></li>
5958
</ul>
6059
</div>&nbsp;
60+
<div class="btn-group">
61+
<li class="dropdown-toggle" data-toggle="dropdown" style="font-size:125%">
62+
Testing Page <span class="caret"></span>
63+
</li>
64+
<ul class="dropdown-menu">
65+
<li><a style="color:black; font-size:125%" href="/stats/testing/">Testing Page</a></li>
66+
<li><a style="color:black; font-size:125%" href="/stats/nested_chart/">Nested Chart Page</a></li>
67+
</ul>
68+
</div>&nbsp;
6169
<div class="btn-group">
6270
<li><a style="color:black; font-size:125%" href="/logout/">Logout</a></li>
6371
</div>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
{% load staticfiles %}
5+
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
6+
7+
{{ all_names }}
8+
<br><br>
9+
{% for dup in dup_all %}
10+
<p>&clubs; dup: {{ dup }} <br>
11+
{% for d in dup.2 %}
12+
&rarr; d: {{d}}
13+
{% endfor %}
14+
</p>
15+
{% endfor %}
16+
<br><br>
17+
18+
19+
20+
<div id="hidden_div" style="display:none"></div>
21+
<div id="visible_div" style="height:300px"></div>
22+
23+
<script type="text/javascript">
24+
google.charts.load('current', {'packages':['corechart']});
25+
google.charts.setOnLoadCallback(drawTooltipCharts);
26+
27+
// Set up data for visible chart.
28+
var primaryData = [
29+
['NBA Finals', 22.4],
30+
['NFL Super Bowl', 111.3],
31+
['MLB World Series', 19.2],
32+
['UEFA Champions League Final', 1.9],
33+
['NHL Stanley Cup Finals', 6.4],
34+
['Wimbledon Men\'s Championship', 2.4]
35+
];
36+
37+
// Set up data for your tooltips.
38+
var tooltipData = [
39+
['Year', 'NBA Finals', 'NFL Super Bowl', 'MLB World Series',
40+
'UEFA Champions League Final', 'NHL Stanley Cup Finals',
41+
'Wimbledon Men\'s Championship'],
42+
['2005', 12.5, 98.7, 25.3, 0.6, 3.3, 2.8],
43+
['2006', 13.0, 90.7, 17.1, 0.8, 2.8, 3.4],
44+
['2007', 9.3, 93.0, 15.8, 0.9, 1.8, 3.8],
45+
['2008', 14.9, 97.5, 17.1, 1.3, 4.4, 5.1],
46+
['2009', 14.3, 98.7, 13.6, 2.1, 4.9, 5.7],
47+
['2010', 18.2, 106.5, 19.4, 2.2, 5.2, 2.3],
48+
['2011', 17.4, 111.0, 14.3, 4.2, 4.6, 2.7],
49+
['2012', 16.8, 111.3, 16.6, 2.0, 2.9, 3.9],
50+
['2013', 16.6, 108.7, 12.7, 1.4, 5.8, 2.5],
51+
['2014', 15.7, 111.3, 15.0, 1.9, 4.7, 2.4]
52+
];
53+
54+
var primaryOptions = {
55+
title: 'Highest U.S. Viewership for Most Recent Event (in millions)',
56+
legend: 'none',
57+
tooltip: {isHtml: true} // This MUST be set to true for your chart to show.
58+
};
59+
60+
var tooltipOptions = {
61+
title: 'U.S. Viewership Over The Last 10 Years (in millions)',
62+
legend: 'none'
63+
};
64+
65+
// Draws your charts to pull the PNGs for your tooltips.
66+
function drawTooltipCharts() {
67+
68+
var data = new google.visualization.arrayToDataTable(tooltipData);
69+
var view = new google.visualization.DataView(data);
70+
71+
// For each row of primary data, draw a chart of its tooltip data.
72+
for (var i = 0; i < primaryData.length; i++) {
73+
74+
// Set the view for each event's data
75+
view.setColumns([0, i + 1]);
76+
77+
var hiddenDiv = document.getElementById('hidden_div');
78+
var tooltipChart = new google.visualization.LineChart(hiddenDiv);
79+
80+
google.visualization.events.addListener(tooltipChart, 'ready', function() {
81+
82+
// Get the PNG of the chart and set is as the src of an img tag.
83+
var tooltipImg = '<img src="' + tooltipChart.getImageURI() + '">';
84+
85+
// Add the new tooltip image to your data rows.
86+
primaryData[i][2] = tooltipImg;
87+
88+
});
89+
tooltipChart.draw(view, tooltipOptions);
90+
}
91+
drawPrimaryChart();
92+
}
93+
94+
function drawPrimaryChart() {
95+
96+
var data = new google.visualization.DataTable();
97+
data.addColumn('string', 'Event');
98+
data.addColumn('number', 'Highest Recent Viewership');
99+
100+
// Add a new column for your tooltips.
101+
data.addColumn({
102+
type: 'string',
103+
label: 'Tooltip Chart',
104+
role: 'tooltip',
105+
'p': {'html': true}
106+
});
107+
108+
// Add your data (with the newly added tooltipImg).
109+
data.addRows(primaryData);
110+
111+
var visibleDiv = document.getElementById('visible_div');
112+
var primaryChart = new google.visualization.ColumnChart(visibleDiv);
113+
primaryChart.draw(data, primaryOptions);
114+
115+
}
116+
</script>
117+
118+
119+
120+
{% endblock content %}

statsPage/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
url(r'^bar_sesh/$','bar_sesh'),
2020
url(r'^most_used_pie/$','most_used_pie'),
2121

22+
url(r'^nested_chart/$','nested_chart'),
23+
2224
# /log/errors
2325
url(r'^errors/$','show_error_log'),
2426

statsPage/views.py

Lines changed: 112 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -826,42 +826,24 @@ def testing(request):
826826
la_country = omg[0]['cc']
827827
all_the_info = pycountry.countries.get(alpha_2=la_country)
828828
country_name = all_the_info.name
829-
print omg[0]['name']
830-
print la_state
831-
print la_country
832-
print all_the_info
833-
print country_name
834-
print omg
835-
# geolocator = Nominatim()
836-
# location = geolocator.reverse(latlon)
837-
# print(location.address)
838829

839830
actions = Action.objects.all()
840831
action_meta = Action._meta
841832

842833
act_names = []
843834
for act in actions:
844835
if ' ' in act.name:
845-
# act_names.append(act.name)
846836
stuff = act.name
847837
new_stuff = stuff.split()
848838
act_names.append(new_stuff[0])
849839
if ' ' not in act.name:
850840
act_names.append(act.name)
851841

852842

853-
# first = True
854843
cool = numpy.unique(act_names)
855-
# all_names = {}
856844
all_names = []
857845
for name in cool:
858846
func_names = []
859-
# if first == True:
860-
# func_names.append("Function")
861-
# func_names.append("Count")
862-
# all_names.append(func_names)
863-
# func_names = []
864-
# first = False
865847

866848
func_names.append(name)
867849
count = 0
@@ -870,43 +852,143 @@ def testing(request):
870852
count += 1
871853
func_names.append(count)
872854
all_names.append(func_names)
873-
# all_names[name] = func_names
874855

875856
all_names = json.dumps(all_names)
876857

877858
return render_to_response('testing/testing.html', { 'all_names': all_names, 'req': request, 'lon': lon, 'lat': lat }, context_instance=RequestContext(request))
878859

879860

880861

881-
# def late_april_stats(request):
882-
def most_used_pie(request):
862+
def nested_chart(request):
883863
actions = Action.objects.all()
884864
action_meta = Action._meta
885865

886866
act_names = []
887867
for act in actions:
888868
if 'Error' not in act.name:
889869
if ' ' in act.name:
890-
# act_names.append(act.name)
891870
stuff = act.name
892871
new_stuff = stuff.split()
893872
act_names.append(new_stuff[0])
894873
if ' ' not in act.name:
895874
act_names.append(act.name)
896875

876+
cool = numpy.unique(act_names)
877+
all_names = []
878+
for name in cool:
879+
func_names = []
880+
sub_list = []
881+
882+
func_names.append(name)
883+
count = 0
884+
for act in act_names:
885+
if name == act:
886+
count += 1
887+
func_names.append(count)
888+
func_names.append(sub_list)
889+
all_names.append(func_names)
890+
891+
dup_all = copy.deepcopy(all_names)
892+
faith = []
893+
hope = []
894+
sub_states = []
895+
fake = 0
896+
for fade in dup_all:
897+
if '.' in fade[0]:
898+
states = fade[0].split('.')
899+
fade[0] = states[0]
900+
# fade.append(states[0])
901+
que_bueno = []
902+
nested_bueno = []
903+
# for each in states:
904+
# if each != states[0]:
905+
# que_bueno.append(each)
906+
try:
907+
que_bueno.append(states[1])
908+
try:
909+
nested_bueno.append(states[2])
910+
try:
911+
super_nested = []
912+
super_nested.append(states[3])
913+
nested_bueno.append(super_nested)
914+
# nested_bueno.append(states[3])
915+
except IndexError:
916+
print 'sorry, no 3'
917+
except IndexError:
918+
print 'sorry, no 2'
919+
except IndexError:
920+
print 'sorry, no 1'
921+
que_bueno.append(nested_bueno)
922+
fade[2].append(que_bueno)
923+
924+
top_hier = []
925+
for dup in dup_all:
926+
print "print DUP yo"
927+
print "print DUP yo"
928+
print dup
929+
if dup[0] not in top_hier:
930+
nested_hier = []
931+
nested_hier.append(dup[0])
932+
nested_hier.append([])
933+
top_hier.append(nested_hier)
934+
# top_hier.append(dup[0])
935+
for d in dup[2]:
936+
for e in d:
937+
print "PRINT E YO"
938+
print e
939+
940+
print "TOP_HIER"
941+
print "TOP_HIER"
942+
print "TOP_HIER"
943+
print top_hier
944+
# for fade in dup_all:
945+
# # print fade
946+
# # sub_states = []
947+
# count = 0
948+
# tapout = []
949+
# if '.' in fade[0]:
950+
# # print fade[0]
951+
# states = fade[0].split('.')
952+
# # print states
953+
# if states[0] not in faith:
954+
# faith.append(states[0])
955+
# if states[1] not in sub_states:
956+
# sub_states.append(states[1])
957+
# tapout.append(states[1])
958+
# tapout.append(count)
959+
# perku.append(tapout)
960+
# if states[1] in sub_states:
961+
# for perk in perku:
962+
# if perk[0] == states[1]:
963+
# count += 1
964+
# perk[1] = count
965+
# # count += 1
966+
# if '.' not in fade[0]:
967+
# hope.append(fade)
968+
969+
# print hope
970+
all_names = json.dumps(all_names)
971+
return render_to_response('testing/nested_chart.html', { 'dup_all': dup_all, 'sub_states': sub_states, 'faith': faith, 'hope': hope, 'cool': cool, 'all_names': all_names, 'act_names': act_names, 'action_meta': action_meta, 'actions': actions }, context_instance=RequestContext(request))
972+
973+
974+
def most_used_pie(request):
975+
actions = Action.objects.all()
976+
action_meta = Action._meta
977+
978+
act_names = []
979+
for act in actions:
980+
if 'Error' not in act.name:
981+
if ' ' in act.name:
982+
stuff = act.name
983+
new_stuff = stuff.split()
984+
act_names.append(new_stuff[0])
985+
if ' ' not in act.name:
986+
act_names.append(act.name)
897987

898-
# first = True
899988
cool = numpy.unique(act_names)
900-
# all_names = {}
901989
all_names = []
902990
for name in cool:
903991
func_names = []
904-
# if first == True:
905-
# func_names.append("Function")
906-
# func_names.append("Count")
907-
# all_names.append(func_names)
908-
# func_names = []
909-
# first = False
910992

911993
func_names.append(name)
912994
count = 0
@@ -915,13 +997,8 @@ def most_used_pie(request):
915997
count += 1
916998
func_names.append(count)
917999
all_names.append(func_names)
918-
# all_names[name] = func_names
9191000

9201001
all_names = json.dumps(all_names)
921-
9221002
return render_to_response('action_stats/most_used_pie.html', { 'cool': cool, 'all_names': all_names, 'act_names': act_names, 'action_meta': action_meta, 'actions': actions }, context_instance=RequestContext(request))
9231003

9241004

925-
926-
927-

0 commit comments

Comments
 (0)