-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1058 lines (1021 loc) · 47.4 KB
/
index.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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Projection of Impact of Charter Opening on Traditional District Finances</title>
<meta property="og:url" content="http://jcalz.github.io/schoolmodel" />
<meta property="og:title" content="Projection of Impact of Charter Opening on Traditional District Finances" />
<meta property="og:description" content="This page simulates the effect of a charter school's expansion or opening on the finances of public school districts. When students
leave a traditional district to a charter, their per pupil state and local funding follows them and the sending district must find places to cut."
/>
<meta property="og:image" content="http://jcalz.github.io/schoolmodel/img/exampleCharts.png" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-2.2.3.min.js">
</script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js">
</script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js">
</script>
<script src="js/util.js">
</script>
<style>
html {
font-family: Arial, Helvetica, sans-serif;
}
h2 {
margin: 0;
}
label {
display: inline-block;
width: 80%;
text-align: right;
}
.chart {
width: 80%;
height: 200px;
border: 1px solid black;
}
.details .summary {
border: 1px solid black;
background-color: #DDDDDD;
font-weight: bold;
cursor: pointer;
}
.details {
border: 1px solid black;
width: 80%;
margin: 10px;
}
.details:not([open])>.detailText {
display: none;
}
.details:not([open])>.summary .triangleIcon:before {
content: "\25ba";
}
.details[open]>.summary .triangleIcon:before {
content: "\25bc";
}
.enrollmentTable, .fundingTable {
border-collapse: collapse;
}
.enrollmentTable td,
.enrollmentTable th,
.fundingTable td,
.fundingTable th {
border: 1px solid black;
padding: 0.25rem;
}
.enrollmentTable th,
.fundingTable th {
font-size: 50%;
}
.enrollmentTable td, .fundingTable td {
font-size: 85%;
text-align: center;
}
.highlighted {
font-size: 110%;
font-weight: bold;
}
.urgent {
color: red;
}
.shareDialog .ui-dialog-titlebar {
display: none;
}
.shareDialog {
text-align: center;
}
</style>
</head>
<body>
<h2>Projection of Impact of Charter Opening on Traditional District Finances</h2>
(Kindergarten through 8th Grade)
<div class="details">
<div class="summary">
<span class="triangleIcon"></span> Projection details and FAQs</div>
<div class="detailText">
<div class="details">
<div class="summary"><span class="triangleIcon"></span> About the model</div>
<div class="detailText">This page simulates the effect of charter school's expansion or opening on the finances of public school districts.
The model shows enrollment changes and financial impact for K-8 only. The model uses
2014-2015 state data for each district, including total enrollment, number of schools, teacher salaries, per pupil
spending, and maximum class size. Data are available here: <a href="http://profiles.doe.mass.edu/state_report/">http://profiles.doe.mass.edu/state_report/</a>. It is based on what has happened to districts in the past when charters open or expand.</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>About us</div>
<div class="detailText"> We (Stephanie Hirsch and Joe Calzaretta) are parents of three children in the Somerville Public Schools. Stephanie
Hirsch has spent almost 20 years working in the analysis of finance and operations data at the state and local level.
She studied finance at Harvard Business School and the statistics at the University of Chicago and she believes in
strong local government and strong community institutions. Joe is an MIT-trained software engineer and mathematician.
Contact us at <a href="mailto:charter-simulation@googlegroups.com">charter-simulation@googlegroups.com</a></p>
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>What happens to funding when a child leaves the district for a charter school?</div>
<div
class="detailText"> When students leave a traditional district for a charter, the district loses the local tax dollars that pay for that
student's education, not just the state aid. In comparison, when a student goes to a private school, the state
aid is lost but the tax dollars – usually most of the per pupil expenses -- stay with the community.
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>What assumptions does the model make?</div>
<div class="detailText">
<p><span style="text-decoration: underline;">How Students Leave</span><strong>:</strong> Based on prior real-life cases,
we assume that a new charter school will draw a certain number of students from the public school district every
year. (You can <a href="#charterDrawParameter">change</a> this number in the projection.) Often new schools open
with one grade at a time, starting at K or at the start of middle school or high school. For the first year, there
will be a larger draw from Kindergarten than from the other grades. In the second year, there will be a larger
draw from 1st grade. This process continues for each year, targeting each successive grade level, until the ninth
year where there will be a larger draw from 8th grade. Specifically, the projection tries to draw 60% of students
from the targeted grade, and then draws the remainder from all grades equally. These students are chosen randomly
(to try to replicate what actually happens), which means that each run of the projection may result in slightly
different outcomes.</p>
<p><span style="text-decoration: underline;">What the District Does</span><strong>:</strong> <!--We assume that the district
receives a certain amount of funding for each enrolled student. (You can <a href="#fundingPerStudentParameter">change</a> this number in the projection.)-->
We assume that the district will try to close sections to save money, as section
teachers cost a certain amount per year. (We have added $18K to the teacher salary from the state data to account for benefits.
You can also <a href="#teacherSalaryParameter">change</a> the teacher salary number in the projection. )
The district has a maximum allowable number of students per class section (You can <a href="#maximumClassSizeParameter">change</a> this number in the projection.) The district will keep the fewest number of sections without exceeding this maximum
class size. That is, each school will freely move students between sections in a grade in order to close class
sections, but students are not moved across grades or across schools, even if this would result in fewer class
sections. We based the maximum class size on the largest class size we found in the district’s data for grades
K-8 (however you can adjust that number in the model).</p>
<p><span style="text-decoration: underline;">Other Details</span><strong>:</strong> We assume:</p>
<ul>
<li>Each section has one teacher.</li>
<li>If the district is chosen from <a href="#districtDropdown">the dropdown</a>, the K-8 enrollment for each grade
in each school in the district is initially chosen to match the 2014-2015 information published by the state.
(Note that this will differ slightly from actual enrollment, but it will be close). If the district is not chosen
from the dropdown, you can choose the <a href="#numberOfSchoolsParameter">number of schools</a> and the <a href="#numberOfStudentsParameter">initial number of students</a> in the district, and the total district K8 enrollment is distributed evenly across grades and schools at the
start of the projection.</li>
<li>The per pupil expenditure shown in the model has been reduced from the state data by 10% to account for the average effects of state facility aid (about 7%) and the deviation between the amount that districts pay for charter tuitions (about 3%). For districts that are currently making
tuition payments, they can find their payment and state facility aid in this report <a href="http://www.doe.mass.edu/charter/finance/tuition/">
http://www.doe.mass.edu/charter/finance/tuition/</a> and can plug it into the per-pupil spending to get a more precise
cost projection.</li>
<li>Each district is assumed to have a number of support, intervention, and enrichment teachers at the start of the
projection. These teachers are assumed to have the same yearly salary as the class section teachers.</li>
<li>According to state law, districts receive some funding during a transitional period when a student leaves. This
program aims to maintain full funding for a student the first year after she leaves the district, and then 25%
funding for each of the next five years, before dropping to zero funding entirely starting in the seventh year.
(Explained here: <a href="http://www.doe.mass.edu/charter/finance/tuition/Reimbursements.html">http://www.doe.mass.edu/charter/finance/tuition/Reimbursements.html</a>)
However, this program has not been fully funded in recent years, and a significant gap remains in the FY17 Governor’s budget. Thus, the district only receives a fraction of each departed student's reimbursement each year (e.g. 59% of 100% in year one, and 59% of 25% in years 2-6). (The default level is 59%, however you can <a href="#stateReimbursementPercentageParameter">change</a> this number in the projection to model different State funding scenarios).
</li>
</ul>
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>Why is there such a big deficit? </div>
<div class="detailText">As the projection progresses, the net loss of funding for departing students quickly becomes greater than the savings
in teacher salaries by closing sections. This is because too few students leave from any
one grade/school to close sections. Also, the district has fixed costs that don't disappear when a student leaves,
like the salary of a payroll coordinator or superintendent. To close the budget gaps, the district will need to
cut the extras — like reading teachers, school counselors, specialists (music/art), pre-kindergarten programming,
and any other student service or support. If the projection shows that these are completely eliminated, and the budget
drops below zero, it means that the district will need to cut costs in ways not accounted for by the projection.</p>
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>What else can districts do to cover the deficits?</div>
<div class="detailText"> Instead of cutting enrichment and support, districts can close schools to cover the annual deficit. However, because
no one school will lose all of its students, this means moving students who remain in the shuttered school to a new
school. That’s a very disruptive and politically difficult, so sometimes doesn’t happen as planned. Alternately,
a city can cut other city services (e.g. recreation, health and human services, police/fire) to cover increased funding
for the schools.</p>
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>How long will the deficits last?</div>
<div class="detailText"> With no cap, the deficits may continue until every school has been turned into a privately-run public charter school.</p>
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>Where can I learn more?</div>
<div class="detailText">We welcome a lively discussion on the model, as more information will help districs and voters make a decision on Question 2. Join the discussion at: <a href="https://www.facebook.com/SchoolFundingModel/">https://www.facebook.com/SchoolFundingModel/</a></p>
</div>
</div>
<div class="details">
<div class="summary"><span class="triangleIcon"></span>How can I see your code and math?</div>
<div class="detailText">Take a look here: <a href="https://github.com/jcalz/schoolmodel">http://github.com/jcalz/schoolmodel</a>.</p>
</div>
</div>
<div class="summary">close details </div>
</div>
</div>
<div id="config">
<label id="districtDropdown">School district:
<select id="districtSelect"></select>
</label>
<label id="numberOfSchoolsParameter">Number of schools in the district:
<input data-var="NUMBER_OF_SCHOOLS_IN_DISTRICT" data-io="naturalNumber">
</label>
<label id="numberOfStudentsParameter">Initial number of students in the district:
<input data-var="INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT" data-io="naturalNumber">
</label>
<label id="maximumClassSizeParameter">Maximum class size:
<input data-var="MAXIMUM_CLASS_SIZE" data-io="naturalNumber">
</label>
<label id="teacherSalaryParameter">District yearly teacher salary:
<input data-var="TEACHER_SALARY" data-io="dollarValue">
</label>
<label id="fundingPerStudentParameter">District yearly funding per student:
<input data-var="FUNDING_PER_STUDENT" data-io="dollarValue">
</label>
<label id="charterDrawParameter">Number of students leaving for charter per year:
<input data-var="CHARTER_DRAW_PER_YEAR" data-io="naturalNumber">
</label>
<label id="stateReimbursementPercentageParameter">Fraction of reimbursement funded:
<input data-var="STATE_REIMBURSEMENT_PERCENTAGE" data-io="percentage">
</label>
</div>
<br>
<button id="go">Advance year</button>
<button id="restart">Restart</button>
<button class="fb-share-link">Share on Facebook</button>
<br>
<div id="charts">
<div id="specialistChart" class="chart"></div>
<div id="fundingChart" class="chart"></div>
</div>
<div id="output">
<div>Year: <span id="currentYear"></span></div>
<div>Students lost: <span id="studentsLost"></span></div>
<div>Teacher reduction: <span id="teacherReduction"></span></div>
<div>Sections closed: <span id="sectionsClosed"></span></div>
<div class="highlighted" id="totalFunding">Total funding <span id="gainedOrLost">lost</span>: <span id="totalFundingChange"></span></div>
<div class="highlighted">Cuts made: <span id="cutsMade"></span></div>
<div class="urgent highlighted" id="cutsNeededDiv">Additional cuts needed: <span id="cutsNeededAmount"></span></div>
</div>
<div id="enrollmentDetails" class="details">
<div class="summary">
<span class="triangleIcon"></span> Enrollment details </div>
<div class="detailText">
<table id="enrollmentTable" class="enrollmentTable"></table>
</div>
</div>
<div id="fundingDetails" class="details">
<div class="summary">
<span class="triangleIcon"></span> Funding details
</div>
<div class="detailText">
<table id="fundingTable" class="fundingTable">
<thead><th>Year</th>
<th>Total funding lost</th>
<th>Sections closed</th>
<th>Additional cuts needed</th></thead>
<tbody></tbody>
</table>
</div>
</div>
<script>
var ioProcessors = {
naturalNumber: {
display: function(num) {
return num.toLocaleString('en-US', {
minimumFractionDigits: 0,
maximumFractionDigits: 0
});
},
parse: function(text) {
return Math.round(parseFloat(text.replace(/[^\d.]/g, '')));
}
},
dollarValue: {
display: function(num) {
return num.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
maximumFractionDigits: 0
});
},
parse: function(text) {
return Math.round(parseFloat(text.replace(/[^\d.]/g, '')));
}
},
percentage: {
display: function(num) {
return num.toLocaleString('en-US', {
style: 'percent',
minimumFractionDigits: 0,
maximumFractionDigits: 0
});
},
parse: function(text) {
return Math.round(parseFloat(text.replace(/[^\d.]/g, '')))/100.;
}
},
none: {
display: function(n) {
return n;
},
parse: function(n) {
return n;
}
}
};
google.charts.load('current', {
'packages': ['corechart']
});
var chartsLoaded = $.Deferred();
google.charts.setOnLoadCallback(function() {
chartsLoaded.resolve();
});
$(function() {
$.getJSON('data/districts.json').done(function(districtsObject) {
// make dropdown for districts
window.districtsObject = districtsObject;
var options = Object.keys(districtsObject).map(function(id) {
return $('<option>', {
value: id
}).text(districtsObject[id].districtName);
});
options.sort(function(a, b) {
return compare(a.text(), b.text());
});
options.unshift($('<option>', {
value: ''
}).text('Choose district or enter custom values'));
$('#districtSelect').append(options);
var currentYear = 0;
var unchangingConfig = {
// When a student leaves the district for for a charter school,
// the district still gets 100% of the student's funding for the first year,
// and then 25% of the student's funding for the next five years,
// before losing funding for thae student altogether after that.
//
// actually that's not true... this program is only 59% funded so only
// 59% of that funding comes in:
FUNDING_FRAC_REMOVED_STUDENT: [1, 0.25, 0.25, 0.25, 0.25, 0.25],
NUMBER_OF_YEARS: 9
}
// default to Abington
var config = {
DISTRICT_CODE: "00010000",
MAXIMUM_CLASS_SIZE: 32,
FUNDING_PER_STUDENT: 11944,
TEACHER_SALARY: 92662,
INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT: 1403,
NUMBER_OF_SCHOOLS_IN_DISTRICT: 4,
CHARTER_DRAW_PER_YEAR: 50,
STATE_REIMBURSEMENT_PERCENTAGE: 0.59
}
// replace with values from query param if present
var queryParams = caseInsensitiveQueryParams();
Object.keys(config).forEach(function(k) {
var lck = k.toLowerCase();
if (lck in queryParams) {
config[k] = JSON.parse(queryParams[lck][1]);
}
});
var specialistTypes = {};
var makeSpecialistType = function(typeId, typeName) {
specialistTypes[typeId] = {
'typeName': typeName,
'typeId': typeId,
'getCost': function() {
return config.TEACHER_SALARY;
}
};
}
makeSpecialistType('music', 'Music Teachers');
makeSpecialistType('art', 'Art Teachers');
makeSpecialistType('library', 'Librarians');
makeSpecialistType('languages', 'World Languages Teachers');
makeSpecialistType('physed', 'Physical Education Teachers');
makeSpecialistType('counselor', 'Counselor Educators');
makeSpecialistType('reading', 'Reading Teachers');
var getSpecialist = function(typeId) {
return {
'type': specialistTypes[typeId]
};
};
var getGrade = function(schoolName, initialNumberOfStudents) {
var name = schoolName ? schoolName : "unnamed grade";
var getName = function() {
return name;
};
var numberOfStudents = initialNumberOfStudents ? initialNumberOfStudents : 0;
var getNumberOfStudents = function() {
return numberOfStudents;
};
var removeStudents = function(n) {
if (n > numberOfStudents) n = numberOfStudents;
numberOfStudents -= n;
return n;
};
var getNumberOfSections = function() {
return Math.ceil(getNumberOfStudents() / config.MAXIMUM_CLASS_SIZE);
};
return {
getName: getName,
getNumberOfStudents: getNumberOfStudents,
removeStudents: removeStudents,
getNumberOfSections: getNumberOfSections,
};
};
var getCharter = function() {
var numberOfStudents = [0, 0, 0, 0, 0, 0, 0, 0, 0]; // array index represents grade, kindergarten - 8th grade
var getNumberOfStudents = function() {
return numberOfStudents.reduce(add, 0);
};
var yearOpened = null;
var takeStudentsFromDistrict = function(district) {
if (yearOpened === null) yearOpened = getCurrentYear();
var yearsSinceOpened = getCurrentYear() - yearOpened;
// take 60% of students in grade Y (where Y is years since opened)
var numFromOneGrade = Math.round(0.6 * config.CHARTER_DRAW_PER_YEAR);
var g;
if ((0 <= yearsSinceOpened) && (yearsSinceOpened <= 8)) {
g = yearsSinceOpened;
numberOfStudents[g] += district.removeStudentsFromGrade(numFromOneGrade, g);
}
// take remainder of students randomly from any grade in the district
num = 0;
while (num < (config.CHARTER_DRAW_PER_YEAR - numFromOneGrade)) {
if (district.getNumberOfStudents() == 0) break;
g = Math.floor(Math.random() * 9);
var n = district.removeStudentsFromGrade(1, g);
numberOfStudents[g] += n;
num += n;
}
};
var getNumberOfSections = function() {
var sec = 0;
for (var g = 0; g < numberOfStudents.length; g++) {
sec += Math.ceil(numberOfStudents[g] / config.MAXIMUM_CLASS_SIZE);
}
return sec;
}
return {
getName: function() {
return "Charter School";
},
getNumberOfStudents: getNumberOfStudents,
takeStudentsFromDistrict: takeStudentsFromDistrict,
getNumberOfSections: getNumberOfSections,
getNumberOfStudentsInGrade: function(g) {
return numberOfStudents[g];
}
};
}
var getSchool = function(name, grades) {
var sumOver = function(fname) {
return function() {
var sum = 0;
for (var i = 0; i < grades.length; i++) {
sum += grades[i][fname]();
}
return sum;
};
};
var getNumberOfStudents = sumOver('getNumberOfStudents');
return {
getName: function() {
return name;
},
getNumberOfStudents: getNumberOfStudents,
getNumberOfSections: sumOver('getNumberOfSections'),
getNumberOfStudentsInGrade: function(g) {
return grades[g].getNumberOfStudents();
},
removeStudentsFromGrade: function(num, g) {
return grades[g].removeStudents(num);
},
getNumberOfSectionsInGrade: function(g) {
return grades[g].getNumberOfSections();
}
};
}
var gradeNames = ['K', '1', '2', '3', '4', '5', '6', '7', '8'];
var gradeNamesLong = ['Kindergarten', '1st grade', '2nd grade', '3rd grade', '4th grade', '5th grade',
'6th grade', '7th grade', '8th grade'
];
var getDistrict = function(numberOfSchools, initialNumberOfStudentsPerSchool, districtCode) {
var getNumberOfSchools = function() {
return numberOfSchools;
}
var schools = [];
var d = districtsObject[districtCode];
var name = undefined;
if (d) {
name = d.districtName;
schools = d.schools.map(function(s) {
var grades = gradeNames.map(function(g) {
return getGrade(gradeNames[g], s['enrollment' + g]);
});
return getSchool(s.schoolName, grades);
});
numberOfSchools = schools.length;
} else {
for (var i = 0; i < numberOfSchools; i++) {
var grades = [];
var numKids = 0;
var kidsPerGrade = initialNumberOfStudentsPerSchool / gradeNames.length;
for (var g = 0; g < gradeNames.length; g++) {
numKids = Math.floor(kidsPerGrade * (g + 1)) - Math.floor(kidsPerGrade * g);
grades[g] = getGrade("DS#" + (i + 1) + ", " + gradeNames[g], numKids);
}
schools[i] = getSchool("District School #" + (i + 1), grades);
}
}
var getNumberOfStudents = function() {
return schools.map(function(x) {
return x.getNumberOfStudents();
}).reduce(add, 0);
};
var initialNumberOfStudents = getNumberOfStudents();
var getNumberOfStudentsInGrade = function(g) {
return schools.map(function(x) {
return x.getNumberOfStudentsInGrade(g);
}).reduce(add, 0);
};
var getNumberOfSections = function() {
var n = 0;
for (var i = 0; i < numberOfSchools; i++) {
n += schools[i].getNumberOfSections();
}
return n;
};
var specialists = [];
var addSpecialistType = function(specialistType) {
var specialist = getSpecialist(specialistType);
specialists.push(specialist);
};
var getSpecialists = function() {
var netFunds = getNetAvailableFunds();
for (var i = 0; i < specialists.length; i++) {
netFunds += specialists[i].type.getCost();
}
var specialistCosts = 0;
for (var i = 0; i < specialists.length; i++) {
specialistCosts += specialists[i].type.getCost();
specialists[i].exists = (netFunds >= specialistCosts);
}
return specialists;
}
var getSpecialistsSummary = function() {
var res = getSpecialists();
var obj = {};
for (var i = 0; i < res.length; i++) {
var t = res[i].type.typeId;
if (!(t in obj)) {
obj[t] = {
'type': res[i].type.typeName,
'retainedNumber': 0,
'initialNumber': 0,
'fundingCut': 0
};
//keys.push(t);
}
obj[t].initialNumber++;
if (res[i].exists) {
obj[t].retainedNumber++;
} else {
obj[t].fundingCut += res[i].type.getCost();
}
}
return obj;
}
var getAvailableFundsForSpecialists = function() {
var res = getSpecialists();
return sum(res.map(function(r) {
return r.type.getCost();
})) + getNetAvailableFunds();
}
var removedStudents = {};
var removeStudentsFromGrade = function(num, g) {
if (!(currentYear in removedStudents)) removedStudents[currentYear] = 0;
var ret = 0;
while (ret < num) {
if (getNumberOfStudentsInGrade(g) == 0) break;
var school = schools[Math.floor(Math.random() * schools.length)];
ret += school.removeStudentsFromGrade(1, g);
}
removedStudents[currentYear] += ret;
return ret;
}
var getAvailableFundsBeforePayingSectionTeachers = function() {
var funding = 0;
funding += config.FUNDING_PER_STUDENT * getNumberOfStudents();
for (var i = 0; i < unchangingConfig.FUNDING_FRAC_REMOVED_STUDENT.length; i++) {
var year = currentYear - i;
if (year in removedStudents) {
funding += config.FUNDING_PER_STUDENT * config.STATE_REIMBURSEMENT_PERCENTAGE *unchangingConfig.FUNDING_FRAC_REMOVED_STUDENT[i] *
removedStudents[year];
}
}
return funding;
};
var getAvailableFunds = function() {
return getAvailableFundsBeforePayingSectionTeachers() - config.TEACHER_SALARY *
getNumberOfSections();
}
var initialAvailableFunds = getAvailableFunds();
var initialNumberOfSections = getNumberOfSections();
var initialAvailableFundsBeforePayingSectionTeachers = getAvailableFundsBeforePayingSectionTeachers();
var getNetAvailableFunds = function() {
return getAvailableFunds() - initialAvailableFunds;
};
var getNetAvailableFundsBeforePayingSectionTeachers = function() {
return getAvailableFundsBeforePayingSectionTeachers() -
initialAvailableFundsBeforePayingSectionTeachers;
};
var getNumberOfRemovedTeachers = function() {
var numRemovedSpecialists = getSpecialists().filter(
function(r) {
return !r.exists;
}).length;
var numRemovedSections = initialNumberOfSections - getNumberOfSections();
return numRemovedSpecialists + numRemovedSections;
};
return {
schools: schools,
getNumberOfStudents: getNumberOfStudents,
getInitialNumberOfStudents: function() {
return initialNumberOfStudents;
},
getNumberOfStudentsInGrade: getNumberOfStudentsInGrade,
removeStudentsFromGrade: removeStudentsFromGrade,
getNetAvailableFunds: getNetAvailableFunds,
getNetAvailableFundsBeforePayingSectionTeachers: getNetAvailableFundsBeforePayingSectionTeachers,
getAvailableFundsForSpecialists: getAvailableFundsForSpecialists,
getNumberOfSections: getNumberOfSections,
getInitialNumberOfSections: function() {
return initialNumberOfSections;
},
addSpecialistType: addSpecialistType,
getSpecialists: getSpecialists,
getSpecialistsSummary: getSpecialistsSummary,
getNumberOfRemovedTeachers: getNumberOfRemovedTeachers,
getName: function() {
return name;
}
};
};
var setCurrentYear = function(y) {
currentYear = y;
};
var getCurrentYear = function() {
return currentYear;
}
var specialistChartObj;
var fundingChartObj;
function setup() {
// clear charts
chartsLoaded.done(function() {
specialistChartObj = {};
specialistChartObj.numRows = unchangingConfig.NUMBER_OF_YEARS + 1;
specialistChartObj.options = {
title: 'Illustration 1: Number of support and enrichment teachers over time\n(Scenario shows how district discretionary spending can be cut to close gaps)',
isStacked: true,
legend: {
position: 'none'
},
vAxis: {
viewWindow: {
min: 0
},
title: 'Teachers'
},
hAxis: {
title: 'Year'
},
};
specialistChartObj.data = new google.visualization.DataTable();
specialistChartObj.data.addColumn('string', 'Year');
Object.keys(specialistTypes).sort().forEach(function(t) {
specialistChartObj.data.addColumn('number', specialistTypes[t].typeName);
specialistChartObj.data.addColumn({
type: 'string',
role: 'tooltip'
});
});
specialistChartObj.data.addRows(specialistChartObj.numRows);
specialistChartObj.chart = new google.visualization.ColumnChart($('#specialistChart')[0]);
fundingChartObj = {};
fundingChartObj.numRows = unchangingConfig.NUMBER_OF_YEARS + 1;
fundingChartObj.options = {
title: 'Illustration 2: Deficit to close after savings from eliminating sections\n(Strategies can include increasing class size, raising fees, cutting support/enrichment/administration, etc.)',
legend: {
position: 'none'
},
vAxis: {
format: 'short',
title: 'Dollars'
},
hAxis: {
title: 'Year'
}
};
fundingChartObj.data = new google.visualization.DataTable();
fundingChartObj.data.addColumn('string', 'Year');
fundingChartObj.data.addColumn('number', 'Funding');
fundingChartObj.data.addColumn({
type: 'string',
role: 'tooltip'
});
fundingChartObj.data.addRows(fundingChartObj.numRows);
fundingChartObj.chart = new google.visualization.ColumnChart($('#fundingChart')[0]);
});
// remove rows from funding table
$('#fundingTable tbody tr').remove();
// replace query param with values from config
var queryParams = caseInsensitiveQueryParams();
Object.keys(config).forEach(function(k) {
var lck = k.toLowerCase();
queryParams[lck] = [lck, JSON.stringify(config[k])];
});
history.replaceState(null, "", '?' + $.param(objectMap(queryParams, function(kv) {
return kv[1];
})));
district = getDistrict(config.NUMBER_OF_SCHOOLS_IN_DISTRICT, Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT /
config.NUMBER_OF_SCHOOLS_IN_DISTRICT), config.DISTRICT_CODE);
window.district = district;
var m = 'music';
var a = 'art';
var r = 'library';
var repeat = function(array, element, times) {
for (var i = 0; i < times; i++) array.push(element);
}
var arr = [];
repeat(arr, 'languages', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 4 / 3300));
repeat(arr, 'art', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 6 / 3300));
repeat(arr, 'music', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 12 / 3300));
repeat(arr, 'physed', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 7 / 3300));
repeat(arr, 'library', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 7 / 3300));
repeat(arr, 'counselor', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 12 / 3300));
repeat(arr, 'reading', Math.round(config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT * 8 / 3300));
arrayShuffle(arr);
arr.forEach(function(x) {
district.addSpecialistType(x);
});
charter = getCharter('Charter School');
};
function getStateObject() {
var state = {};
state.year = getCurrentYear();
state.retainedStudents = district.getNumberOfStudents();
state.initialStudents = district.getInitialNumberOfStudents();
state.lostStudents = state.initialStudents - state.retainedStudents;
state.retainedSections = district.getNumberOfSections();
state.initialSections = district.getInitialNumberOfSections();
state.lostSections = state.initialSections - state.retainedSections;
state.availableFundsForSpecialists = (district.getAvailableFundsForSpecialists());
state.numberOfTeachersRemoved = district.getNumberOfRemovedTeachers();
state.specialists = district.getSpecialistsSummary();
state.totalFundingChange = district.getNetAvailableFundsBeforePayingSectionTeachers();
state.cutsNeeded = -district.getNetAvailableFunds();
state.cutsMade = -state.cutsNeeded - state.totalFundingChange;
return state;
}
function output() {
var stateObj = getStateObject();
var totalRetainedSpecialists = sum(Object.keys(stateObj.specialists).map(function(t) {
return stateObj.specialists[t].retainedNumber;
}));
chartsLoaded.done(function() {
if (stateObj.year < specialistChartObj.numRows) {
specialistChartObj.data.setCell(stateObj.year, 0, stateObj.year + '');
var i = 1;
Object.keys(specialistTypes).sort().forEach(function(t) {
var retained = 0;
if (t in stateObj.specialists) {
retained = stateObj.specialists[t].retainedNumber;
}
specialistChartObj.data.setCell(stateObj.year, i, retained);
i++;
specialistChartObj.data.setCell(stateObj.year, i, retained + ' ' + specialistTypes[t]
.typeName +
'\n' + totalRetainedSpecialists + ' Total Specialists');
i++;
});
}
specialistChartObj.chart.draw(specialistChartObj.data, specialistChartObj.options);
if (stateObj.year < fundingChartObj.numRows) {
fundingChartObj.data.setCell(stateObj.year, 0, stateObj.year + '');
fundingChartObj.data.setCell(stateObj.year, 1, stateObj.cutsNeeded);
fundingChartObj.data.setCell(stateObj.year, 2, money(stateObj.cutsNeeded,
false));
}
fundingChartObj.chart.draw(fundingChartObj.data, fundingChartObj.options);
});
$('#currentYear').text(stateObj.year);
$('#studentsLost').text(stateObj.lostStudents);
$('#teacherReduction').text(stateObj.numberOfTeachersRemoved);
$('#sectionsClosed').text(stateObj.lostSections);
var f = stateObj.totalFundingChange;
$('#gainedOrLost').text(f <= 0 ? 'lost' : 'gained');
$('#totalFundingChange').text(money(Math.abs(f), false));
$('#cutsMade').text(money(Math.abs(stateObj.cutsMade), false));
var cutsNeeded = stateObj.cutsNeeded;
if (cutsNeeded <= 0) {
$('#cutsNeededDiv').hide();
} else {
$('#cutsNeededAmount').text(money(cutsNeeded, false));
$('#cutsNeededDiv').show();
}
if ($('#enrollmentTable').closest('.details').attr('open'))
updateEnrollmentTable();
// update funding table
$('<tr>').append($('<td>').text(stateObj.year)).
append($('<td>').text(money(-f,false))).
append($('<td>').text(stateObj.lostSections)).
append($('<td>').text(cutsNeeded<0 ? '\u2014' : money(cutsNeeded,false))).
appendTo($('#fundingTable tbody'));
}
function updateEnrollmentTable() {
//console.log('making a table');
//$('#enrollmentTable');
var header = [].concat.apply(['School'], gradeNamesLong.map(function(g) {
return [g + " students\u00a0|\u00a0sections"];
})).map(function(txt) {
return $('<th/>').text(txt);
});
var rows = district.schools.concat().sort(function(a, b) {
return compare(a.getName(), b.getName());
}).map(function(s) {
return [].concat.apply([$('<th/>').text(s.getName())], gradeNames.map(function(n, g) {
return [$('<td/>').text(s.getNumberOfStudentsInGrade(g) + " | " + s.getNumberOfSectionsInGrade(
g))];
}));
}).map(function(cells) {
return $('<tr/>').append(cells);
});
$('#enrollmentTable').empty().append(header).append(rows);
//console.log($('#enrollmentTable').html());
}
$('#enrollmentTable').closest('.details')[0].populate = updateEnrollmentTable;
var charter;
var district;
setup();
output();
var year = 0;
$('#go').click(function() {
year++;
if (year >= unchangingConfig.NUMBER_OF_YEARS) {
$('#go').prop('disabled', true);
}
setCurrentYear(year);
charter.takeStudentsFromDistrict(district);
output();
});
var restart = function() {
year = 0;
$('#go').prop('disabled', false);
setCurrentYear(year);
setup();
output();
};
$('#restart').click(restart);
var parseConfig = function(elem) {
var ioProcessor = ioProcessors[$(elem).attr('data-io')];
if (!ioProcessor) ioProcessor = ioProcessors.none;
config[$(elem).attr('data-var')] = ioProcessor.parse($(elem).val());
};
var displayConfig = function(elem) {
var ioProcessor = ioProcessors[$(elem).attr('data-io')];
if (!ioProcessor) ioProcessor = ioProcessors.none;
$(elem).val(ioProcessor.display(config[$(elem).attr('data-var')]));
};
$('input[data-var]').change(function() {
parseConfig(this);
displayConfig(this);
restart();
}).each(function() {
displayConfig(this);
});
$('#districtSelect').change(function() {
// set the config values
districtId = $(this).val();
config.DISTRICT_CODE = districtId;
var d = districtsObject[districtId];
$(
'input[data-var="NUMBER_OF_SCHOOLS_IN_DISTRICT"], input[data-var="INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT"]'
).prop('disabled', !!d);
if (d) {
var totalEnrollment = sum(d.schools.map(function(s) {
return s.totalEnrollment;
}));
config.MAXIMUM_CLASS_SIZE = d.maxAllowableClassSize;
// take 10% off per-pupil spending to account for state facility aid (~7%)
// and average discrepancy between charter tuition and per-pupil spending (~3%)
config.FUNDING_PER_STUDENT = Math.round(d.perPupilSpending * 0.9);
// add $18K for teacher benefits
config.TEACHER_SALARY = Math.round(d.teacherSalary + 18000);
config.INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT = totalEnrollment;
config.NUMBER_OF_SCHOOLS_IN_DISTRICT = d.schools.length;
config.CHARTER_DRAW_PER_YEAR = 50 * Math.ceil(totalEnrollment / 3500);
$('input[data-var]').each(function() {
displayConfig(this);
});
}
restart();
}).val(config.DISTRICT_CODE);
$(
'input[data-var="NUMBER_OF_SCHOOLS_IN_DISTRICT"], input[data-var="INITIAL_NUMBER_OF_STUDENTS_IN_DISTRICT"]'
).prop('disabled', !!(districtsObject[config.DISTRICT_CODE]));
$('.details .summary').click(function() {
var el = $(this).closest('.details');
if (el.attr('open')) {
el.children(".detailText").slideUp();
el.removeAttr('open');
} else {
if (el[0].populate) el[0].populate();
el.children(".detailText").slideDown();
el.attr('open', true);
}
});
$('.fb-share-link').click(function() {
var button = $(this);
completeSimulation();
uploadChartsToImgur().then(function(previewImgUrl) {
//console.log(linkUrl);
var title = district.getName() ? district.getName() + ': ' : '';
var description = $('#totalFunding').text();
title += 'Projection of Impact of Charter Opening on Traditional District Finances';
var href = 'https://www.facebook.com/sharer/sharer.php?u=' +
encodeURIComponent(window.location.href.replace(/.*?schoolmodel/,
'https://jcalz.github.io/schoolmodel')) +
'&picture=' + encodeURIComponent(previewImgUrl) +
'&title=' + encodeURIComponent(title) +
'&description=' + encodeURIComponent(description);
var dialog = $('<div>');
var closeDialog = function() {
dialog.dialog("close");
return true;
};
dialog.append($(
'<a target="fbshare"><button>Share on Facebook<br>(opens new window)</button></a>').attr(
'href', href).click(closeDialog));
dialog.append($('<button>Don\'t Share</button>').click(closeDialog));
dialog.on('dialogclose', function() {
dialog.remove();
});
dialog.dialog({
modal: true,
dialogClass: 'shareDialog',
minHeight: 0
});
});
});
completeSimulation();
function completeSimulation() {
while (getCurrentYear() < unchangingConfig.NUMBER_OF_YEARS) {
$('#go').click();