-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcalculation.php
More file actions
294 lines (135 loc) · 7.11 KB
/
calculation.php
File metadata and controls
294 lines (135 loc) · 7.11 KB
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
<?php
session_start();
//holidays array
$holiday_data_array = array();
$holiday_dt_array = array();
$holidayquery = "SELECT date FROM holidays";
$holiday_result = $db_server->query($holidayquery);
while ($holiday_data = $holiday_result->fetch_array()) {
array_push($holiday_dt_array, $holiday_data);
}
foreach ($holiday_dt_array as $k) {
array_push($holiday_data_array, $k[0]);
}
//allotted hours query
$yearinschool = $student_data_array[0]['yearinschool'];
$allottedquery = "SELECT * FROM allottedhours WHERE yis = '$yearinschool'";
$allotted_result = $db_server->query($allottedquery);
$allotted_data_array = $allotted_result->fetch_array();
//globals query
$globalsquery = "SELECT * FROM globals";
$globals_result = $db_server->query($globalsquery);
$globalsdata = $globals_result->fetch_array();
$studyhours_all = $allotted_data_array['IShours'] * 60;
$offsitehours_all = $allotted_data_array['offsitehours'] * 60;
$commhours_all = $allotted_data_array['communityhours'] * 60;
$studyhours_remaining = $studyhours_all;
$offsitehours_remaining = $offsitehours_all;
$commhours_remaining = $commhours_all;
$studyhours_used = 0;
$offsitehours_used = 0;
$commhours_used = 0;
$num_lates = 0;
$num_unexpected = 0;
$num_absent = 0;
$TimeQuery = $db_server->query("SELECT starttime,endtime FROM globals");
$TimeQuery = $TimeQuery->fetch_array();
$globalstarttime = new DateTime($TimeQuery['starttime']);
$globalendtime = new DateTime($TimeQuery['endtime']);
$globalstarttime = $globalstarttime->format("H:iA");
$globalendtime = $globalendtime->format("H:iA");
$today = New DateTime();
//counts time
//loops through each event for the given student
foreach($student_data_array as $event_key => $event_val) {
if (count($student_data_array) != $event_key) {
//makes the timestamp into datetime obj
$event_datetime_1 = new DateTime($student_data_array[$event_key+1]['timestamp']);
$event_datetime_2 = new DateTime($event_val['timestamp']);
//variables for easy comparison
$early = $event_datetime_1->format('m/d/y') . " " . $globalstarttime;
$late = $event_datetime_1->format('m/d/y') . " " . $globalendtime;
$event_early = new DateTime($early);
$event_late = new DateTime($late);
//echo $event_val['eventid'] . " || " . $event_datetime_1->format('m/d/y') . " || " . $event_datetime_1->format('H:i:s') . " || " . $student_data_array[$event_key+1]['eventid'] . " || " . $event_datetime_2->format('m/d/y') . " || " . $event_datetime_2->format('H:i:s') . " || " . "<br />";
//is event 1 on a weekend or holiday?
if (($event_datetime_1->format('w') == 0 || $event_datetime_1->format('w') == 6) || (in_array($event_datetime_1->format('Y-m-d'), $holiday_data_array) == True)) {
continue;
}
//is event 1 before the start of school?
if ($event_datetime_1 <= $event_early){
$event_datetime_1->setTime(9, 0, 0);
}
//is event 2 after the end of the school day of the same day of event 1?
if ($event_datetime_2 >= $event_late){
$event_datetime_2 = clone $event_datetime_1;
$event_datetime_2->setTime(15, 30, 0);
}
//echo $event_val['eventid'] . " || " . $event_datetime_1->format('m/d/y') . " || " . $event_datetime_1->format('H:i:s') . " || " . $student_data_array[$event_key+1]['eventid'] . " || " . $event_datetime_2->format('m/d/y') . " || " . $event_datetime_2->format('H:i:s') . " || " . "<br />";
//diff between adjacent events
$elapsed = $event_datetime_1->diff($event_datetime_2);
//format as total minutes
$elapsed_minutes = $elapsed->format('%i');
if ($event_val['statusname'] == 'Present' || $event_val['statusname'] == 'Field Trip' || $event_val['statusname'] == 'Independent Study') {
$commhours_remaining -= $elapsed_minutes;
$commhours_used += $elapsed_minutes;
if ($event_val['statusname'] == 'Independent Study') {
$studyhours_remaining -= $elapsed_minutes;
$studyhours_used += $elapsed_minutes;
}
}
else {
$offsitehours_remaining -= $elapsed_minutes;
$offsitehours_used += $elapsed_minutes;
if ($event_val['statusname'] == 'Not Checked In') {
$num_unexpected += 1;
$num_lates += 1;
}
if ($event_val['statusname'] == 'Late') {
$num_lates += 1;
}
if ($event_val['statusname'] == 'Absent') {
$num_absent += 1;
}
}
}
}
//Offsite information echoing
$offsiteHrs_remaining = floor($offsitehours_remaining / 60);
$offsiteMin_remaining = $offsitehours_remaining % 60;
$readable_offsiteleft = "<p class='reporttext'> You have " . $offsiteHrs_remaining . " hours and " . $offsiteMin_remaining . " minutes of offsite left. </p>";
if ($offsitehours_remaining < 0) {
$readable_offsiteleft = "<p class='reporttext'> You are out of offsite! You are over by " . $offsiteHrs_remaining . " hours and " . $offsiteMin_remaining . " minutes. </p>";
}
echo $readable_offsiteleft;
$offsiteHrs_used = floor($offsitehours_used / 60);
$offsiteMin_used = $offsitehours_remaining % 60;
echo "<p class='reporttext'> You have used " . $offsiteHrs_used . " hours and " . $offsiteMin_used . " minutes of your offsite time.</p>";
//Late information echoing
echo "<p class='reporttext'> You have been late " . $num_lates . " times.</p>";
echo "<p class='reporttext'> You have been unexpectedly late " . $num_unexpected . " times. </p>";
echo "<p class='reporttext'> You have been absent " . $num_absent . " times. </p>";
//IS information echoing
$studyHrs_remaining = floor($studyhours_remaining / 60);
$studyMin_remaining = $studyhours_remaining % 60;
$readable_studyleft = "<p class='reporttext'> You have " . $studyHrs_remaining . " hours and " . $studyMin_remaining . " minutes of independent study left. </p>";
if ($studyhours_remaining < 0) {
$readable_studyleft = "<p class='reporttext'> You are out of independent study! You are over by " . $studyHrs_remaining . " hours and " . $studyMin_remaining . " minutes. </p>";
}
echo $readable_studyleft;
$studyHrs_used = floor($studyhours_used / 60);
$studyMin_used = $studyhours_remaining % 60;
echo "<p class='reporttext'> You have used " . $studyHrs_used . " hours and " . $studyMin_used . " minutes of your independent study time.</p>";
echo "Study hours all: "; echo $studyhours_all; echo "<br />";
echo "Community hours all: "; echo $commhours_all; echo "<br />";
echo "Offsite hours all: "; echo $offsitehours_all; echo "<br />";
echo "Study hours used: "; echo $studyhours_used; echo "<br />";
echo "Community hours used: "; echo $commhours_used; echo "<br />";
echo "Offsite hours used: "; echo $offsitehours_used; echo "<br />";
echo "Study hours remaining: "; echo $studyhours_remaining; echo "<br />";
echo "Community hours remaining: "; echo $commhours_remaining; echo "<br />";
echo "Offsite hours remaining: "; echo $offsitehours_remaining; echo "<br />";
echo "Unexpected Lates: " . $num_unexpected;
echo "Lates: " . $num_lates;
echo "Absents: " . $num_absent;
?>