-
Notifications
You must be signed in to change notification settings - Fork 0
/
school.html
419 lines (388 loc) · 22.9 KB
/
school.html
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<!DOCTYPE html>
<html>
<head>
<title>
Measure G Spending by School
</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- used for social icons -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link href="style/school.css" type="text/css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
</script>
<!--Google analytics snippet -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-35908939-11', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<!-- Wrap all page content here -->
<div id="wrap">
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-target" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><strong>Track G - Oakland's Measure G</strong></a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-target">
<ul class="nav navbar-nav">
<li class=""><a href="index.html">About</a></li>
<li class=""><a href="map.html">By Location</a></li>
<li class=""><a href="programs.html#">By Program</a></li>
<li class=""><a href="chart.html">By School</a></li>
</ul>
<ul class="nav navbar-nav navbar-right social">
<li>
<a class="twitter" href="https://twitter.com/intent/tweet?hashtags=OAKEDU&original_referer=trackg.org&ref_src=twsrc%5Etfw&text=Explore%20how%20Measure%20G%20funds%20are%20spent%20in%20%23Oakland%20Schools%20at%20trackg.org!&tw_p=tweetbutton&url=&via=OpenOakland" target="_blank">
<i class="fa fa-twitter fa-lg"></i>
</a>
</li>
<li>
<a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Ftrackg.org" target="_blank" class="fbhover"><i class="fa fa-facebook fa-lg"></i></a>
</li>
</ul>
</div>
</div>
</div>
<!-- Begin page content -->
<div class="center-container">
<div class="center-row">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2 id="school_name"></h2>
<div id="school_address"></div>
</div>
</div>
<div class="row" id="school_summary" style="display:none">
<div class="col-xs-12 col-sm-6 col-md-8">
<div class="row">
<div class="col-xs-12 col-md-4">
<div class="stat_label">Measure G Spending (2018)</div>
<div class="spending" id="total_spending"></div>
</div>
<div class="col-xs-12 col-md-4">
<div class="stat_label">Per Student</div>
<div class= "spending" id="per_student_spending"></div>
</div>
<div class="col-xs-12 col-md-4">
<div class="stat_label">Number of Students</div>
<div class= "stat" id="total_enrollment"></div>
<div>Note: enrollment data from 2017</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4">
<div id="school_map"></div>
</div>
</div>
<div id="table_div"></div>
<div class="row">
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect" id="tabs">
<div class="mdl-tabs__tab-bar">
<a href="#all-programs-panel" class="mdl-tabs__tab is-active all-programs-data" id="all-programs-tab">All Programs</a>
<a href="#objects-panel" class="mdl-tabs__tab is-active object-level-data" id="objects-tab" style="display:none"></a>
<a href="#glossary-panel" class="mdl-tabs__tab is-active glossary-level-data" id="glossary-tab" style="display:none"></a>
</div>
<div class="mdl-tabs__panel is-active all-programs-data" id="all-programs-panel">
<div id="program_chart"></div>
</div>
<div class="mdl-tabs__panel object-level-data" id="objects-panel">
<div id="object_chart"></div>
</div>
<div class="mdl-tabs__panel glossary-level-data" id="glossary-panel">
<div id="glossary_info"></div>
<div id="gloss_summary"></div>
</div>
</div>
</div>
</div>
</div>
</div> <!-- end wrap -->
<!-- Place your code in the script tags below -->
<script type="text/javascript">
google.charts.load('current', {'packages':['bar','line']});
window.onload = function() {
var map;
function initMap(center, name) {
map = new google.maps.Map(document.getElementById('school_map'), {
center: center,
zoom: 15,
disableDefaultUI: true,
zoomControl: true
});
var marker = new google.maps.Marker({
position: center,
map: map,
title: name,
icon: "https://maps.google.com/mapfiles/kml/shapes/schools_maps.png"
});
};
function formatSchoolAddress(street,city,state,zip) {
return street + " " + city + ", " + state + " " + zip;
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var schoolID = getParameterByName("schoolID");
// global variables in _harp.json
var latestEnrollmentYear = 2017;
var latestExpenditureDataYear = 2018;
var yearToDisplay = {
2012: "2012-13",
2013: "2013-14",
2014: "2014-15",
2015: "2015-16",
2016: "2016-17",
2017: "2017-18",
2018: "2018-19"
};
// See pretty print here: https://github.com/openoakland/measure-g/issues/50
var sql = "SELECT ll.ousd_site,ll.ncessch,ll.latcod as latitude,ll.loncod as longitude,ll.schnam as school_name,ll.ncessch as nces,ll.lstree as street,ll.lcity as city,ll.lstate as state,ll.lzip as zip,ll.gslo as grade_low,ll.gshi as grade_high,ll.site_type, e.total_enrollment, to_char(mg.ytd_actual, '$999,999') as ytd_actual_money, to_char(round((mg.ytd_actual / e.total_enrollment)::numeric, 2),'$999,999.99') per_student_money FROM measure_g_schools_lat_long ll, ousd_enrollment_2017 e,(SELECT site, SUM(m.ytd_actual) as ytd_actual, m.year FROM measure_g_actuals m GROUP BY m.site, m.year) mg WHERE ll.ousd_site = %S AND e.ncessch = ll.ncessch AND e.year = %ENROLLMENTYEAR AND mg.site = %S AND mg.year = %MEASUREGYEAR";
sql = sql.replace(/%S/gi, schoolID).replace(/%ENROLLMENTYEAR/gi, latestEnrollmentYear).replace(/%MEASUREGYEAR/gi, latestExpenditureDataYear);
var schoolName = "";
// Call cartodb
$.getJSON('https://jbaldo.cartodb.com/api/v2/sql/?q='+sql, function(data) {
$.each(data.rows, function(key, row) {
schoolName = row.school_name;
$('#school_name').text(schoolName);
$('#school_address').text(formatSchoolAddress(row.street,row.city,row.state,row.zip));
var center = {lat: row.latitude, lng: row.longitude};
initMap(center,row.school_name);
$('#total_spending').text(row.ytd_actual_money);
$('#per_student_spending').text(row.per_student_money);
$('#total_enrollment').text(row.total_enrollment);
$('#school_summary').show();
});
});
var sql2 = "SELECT prog.short as program,a.year, COALESCE(SUM(ytd_actual), 0) as ytd_actual FROM programs prog, measure_g_actuals a WHERE prog.id = a.program_id AND a.site = %S GROUP BY program, a.year ORDER BY program, a.year".replace(/%S/gi, schoolID);
var programTotalsJson = [];
var programs_chart;
var programTotalData;
$('#all-programs-tab').click(function(){
$('#object-level-data').removeClass('is-active');
// $('#all-programs-data').addClass('');
});
function drawChart() {
programTotalData = google.visualization.arrayToDataTable(dataByProgram);
var options = {
chart: {
title: 'Click on a program for more detail',
subtitle: ''
},
height: 400,
width: $(window).width() * .8,
vAxis:{
format: '$#,###',
textStyle: {
fontSize: 14
}
},
hAxis: {
textStyle: {
fontSize: 14
}
}
};
programs_chart = new google.charts.Line(document.getElementById('program_chart'));
programs_chart.draw(programTotalData, google.charts.Bar.convertOptions(options));
google.visualization.events.addListener(programs_chart, 'select', selectHandler);
function selectHandler(e) {
var dataByObjects = [];
var selection = programs_chart.getSelection();
if (selection.length > 0){
var programName = programTotalData.getColumnLabel(selection[0].column);
var object_query = "SELECT a.year, a.ytd_actual, o.short as obj_desc FROM measure_g_actuals a JOIN programs p ON a.program_id = p.id AND p.short = '%P' LEFT JOIN objects o ON a.object_id = o.id WHERE a.site = 102 AND ytd_actual > 0 ORDER BY obj_desc".replace(/%P/gi, programName);
// TODO: get dynamically from Years table (or set in config)
var supportedYears = [
2012,
2013,
2014,
2015,
2016,
2017,
2018
];
var yearToColumnMapping = {};
var tableHeader = ['Expense Type'];
// Dynamically create Google Visualization DataTable columns based on # of years
for(var i = 0; i < supportedYears.length; i++){
var year = supportedYears[i];
var yearKey= year.toString();
yearToColumnMapping[yearKey] = _.indexOf(supportedYears,year,true);
tableHeader.push(yearToDisplay[yearKey]);
}
$.getJSON('https://jbaldo.cartodb.com/api/v2/sql/?q='+object_query, function(data) {
_.each(_.groupBy(data.rows, 'obj_desc'), function(yearsOfSpending, object){
var objectSpendingByYear = [object];
// Instead of complex SQL joining,
// start with 0 value for each year and replace with spending if it exists
for (var i = 0; i < supportedYears.length; i++) {
objectSpendingByYear.push(0);
}
_.each(yearsOfSpending, function(year){
var column = yearToColumnMapping[year.year] + 1;
objectSpendingByYear[column] = year.ytd_actual;
});
dataByObjects.push(objectSpendingByYear);
});
//Add a header
dataByObjects.unshift(tableHeader);
}).then(function(){
var obj_data = google.visualization.arrayToDataTable(dataByObjects);
obj_data.sort([{column: 1, desc:true}]);
var objectChart = new google.charts.Bar(document.getElementById('object_chart'));
var numBars = dataByObjects.length - 1;
var chartHeight = numBars * 70;
var options = {
chart: {
},
bars: 'horizontal', // Required for Material Bar Charts.
height: chartHeight,
width: $(window).width() * .8,
axes: {
x: {
0: { side: 'top', label: 'Amount spent'} // Top x-axis.
}
},
hAxis:{
format: '$#,###'
}
}
objectChart.draw(obj_data, google.charts.Bar.convertOptions(options));
google.visualization.events.addListener(objectChart, 'select', selectHandler2);
$('.all-programs-data').removeClass('is-active');
$('#objects-tab').text(programName);
$('.object-level-data').addClass('is-active');
$('#objects-tab').show();
$('#objects-tab').click();
function selectHandler2(f) {
var selection2 = objectChart.getSelection();
if (selection2.length > 0){
var objectName = obj_data.getValue(selection2[0].row, 0);
document.getElementById("glossary_info").innerHTML = objectName;
var glossary_query = "SELECT a.short, a.term_def FROM objects a WHERE a.short LIKE '%OBJNAME'".replace(/%OBJNAME/gi, objectName, objectName).replace('&', '%26');
$.getJSON('https://jbaldo.cartodb.com/api/v2/sql/?q='+glossary_query, function(data) {
if(data.rows.length > 0){
$.each(data.rows, function(key, row) {
var glossaryTerm = row.term_def;
if(glossaryTerm) {
$('#gloss_summary').text(glossaryTerm);
$('#gloss_summary').show();
}
});
} else {
$('#gloss_summary').text("Not found");
}
}).then(function(){
$('.object-level-data').removeClass('is-active');
$('#glossary-tab').text(objectName);
$('.glossary-level-data').addClass('is-active');
$('#glossary-tab').show();
$('#glossary-tab').click();
});
}
}
});
}
} //end select handler
}
$(window).resize(function() {
drawChart();
});
var dataByProgram = [];
// TODO: get dynamically from Years table (or set in config)
var supportedYears = [
2012,
2013,
2014,
2015,
2016,
2017,
2018
];
var yearToRowMapping = {};
var tableHeader = ['School Years'];
// Dynamically create Google Visualization DataTable rows based on # of years
for(var i = 0; i < supportedYears.length; i++){
var year = supportedYears[i];
var yearKey = year.toString();
yearToRowMapping[yearKey] = _.indexOf(supportedYears,year,true);
dataByProgram.push([yearToDisplay[year]]);
}
$.getJSON('https://jbaldo.cartodb.com/api/v2/sql/?q='+sql2, function(data) {
var groupedByProgram = _.groupBy(data.rows, 'program');
_.each(groupedByProgram, function(yearsOfSpending, program){
// Dynamically create a row for every program
tableHeader.push(program);
// Instead of complex SQL joining,
// start with 0 value for each program and replace with spending if it exists
for (var i = 0; i < dataByProgram.length; i++) {
dataByProgram[i].push(0);
}
_.each(yearsOfSpending, function(year){
var row = yearToRowMapping[year.year];
var column = tableHeader.length - 1;
dataByProgram[row][column] = year.ytd_actual;
});
});
//Add the table header
dataByProgram.unshift(tableHeader);
}).then(function(){
google.charts.setOnLoadCallback(drawChart);
});
}
var sqlCompare = "SELECT schnam, ousd_site FROM measure_g_schools_lat_long"
</script>
<script>
// Include the UserVoice JavaScript SDK (only needed once on a page)
UserVoice=window.UserVoice||[];(function(){var uv=document.createElement('script');uv.type='text/javascript';uv.async=true;uv.src='//widget.uservoice.com/fE7XpxXMOWc2yipGiIhow.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(uv,s)})();
//
// UserVoice Javascript SDK developer documentation:
// https://www.uservoice.com/o/javascript-sdk
//
// Set colors
UserVoice.push(['set', {
accent_color: '#6aba2e',
trigger_color: 'white',
trigger_background_color: '#6aba2e',
forum_id: '347124',
strings: {
post_suggestion_title: 'Post an idea to improve this page',
post_suggestion_body: 'Publica una idea para mejorar esta página. \n 张贴想法,以改善此页面',
suggestion_category_label: 'Which page are you on?'
}
}]);
// Add default trigger to the bottom-right corner of the window:
UserVoice.push(['addTrigger', {mode: 'feedback', trigger_position: 'bottom-right' }]);
// Autoprompt for Satisfaction and SmartVote (only displayed under certain conditions)
UserVoice.push(['autoprompt', {}]);
</script>
</body>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCqC5S-8nx5nXnD16I_FzA5KNhyjyFLRgw" async defer></script>
</html>