-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for clock with quarantine #145
Conversation
Thank you @andOrlando for the contribution. I'll do some testing next week and then merge it (possibly with a few minor formatting changes) if it works well. |
d97be37
to
5f8b28c
Compare
I did some refactoring to clock.js which makes PatchFrom d97be376ae7fe0a3a9c7b06f793ae8fe0171ee8c Mon Sep 17 00:00:00 2001
From: Bennett Gillig <bennettgillig@gmail.com>
Date: Fri, 23 Oct 2020 14:49:29 -0400
Subject: [PATCH] support for clock with quarantine
adds quarantine_schedule.json and changes clock.js
---
public/js/clock.js | 29 ++++++---
public/quarantine_schedule.json | 110 ++++++++++++++++++++++++++++++++
2 files changed, 129 insertions(+), 10 deletions(-)
create mode 100644 public/quarantine_schedule.json
diff --git a/public/js/clock.js b/public/js/clock.js
index 4e75c66..759c056 100755
--- a/public/js/clock.js
+++ b/public/js/clock.js
@@ -2,6 +2,10 @@ let current_schedule = "regular";
let schedules, logo;
let period_names = {black:[], silver:[]};
+//sets it to quarantine time
+const quarantine = true;
+const schedule_path = quarantine ? "quarantine_schedule.json" : "schedule.json";
+
let small_ctx, small_radius;
let small_clock = document.getElementById("small_clock");
small_ctx = small_clock.getContext("2d");
@@ -17,6 +21,7 @@ large_ctx.translate(large_radius, large_radius);
logo = document.getElementById("logo");
let schedulesCallback = function(response) {
+ //schedules is an array with the json data from schedule.json
schedules = response;
redraw_clock();
setInterval(function() {
@@ -26,7 +31,7 @@ let schedulesCallback = function(response) {
//#ifndef lite
$.ajax({
- url: "schedule.json",
+ url: schedule_path,
method: "GET"
}).then(schedulesCallback);
//#endif
@@ -189,22 +194,26 @@ function redraw_clock() {
let tod = now % (24 * 60 * 60 * 1000);
let pos;
if (school_day()) {
- // let tod = 41399000; // Simulate time
-
- let current_period_i = 0;// Get current period from array
- while (current_period_i < schedules[current_schedule].length - 1 &&
- tod > schedules[current_schedule][current_period_i + 1].start) {
+ // let tod = 30; // Simulate time
+
+ let current_period_i = 0;
+ while (current_period_i < schedules[current_schedule].length &&
+ tod > schedules[current_schedule][current_period_i].start) {
current_period_i++;
}
-
+
+ current_period_i--;
+
let current_period = schedules[current_schedule][current_period_i];
let next_period = schedules[current_schedule][current_period_i + 1];
- if(tod < current_period.start) { // Before school
+ //tod between 12:00 and first period -> before school
+ if(0 < tod && tod < schedules[current_schedule][0].start) { // Before school
period_name = "Before School";
- pos = tod / current_period.start;
- number = current_period.start - tod;
+ pos = tod / schedules[current_schedule][0].start;
+ number = schedules[current_schedule][0].start - tod;
}
+ //next period is undefined and tod > current_period but it's also not before school
else if(!next_period && tod > current_period.end) { // After school
// Realtime
period_name = "";
diff --git a/public/quarantine_schedule.json b/public/quarantine_schedule.json
new file mode 100644
index 0000000..881f9db
--- /dev/null
+++ b/public/quarantine_schedule.json
@@ -0,0 +1,110 @@
+{
+ "regular":[
+ {
+ "name":"Period 1",
+ "start": 33000000,
+ "end": 36000000
+ },
+ {
+ "name":"Period 2",
+ "start": 36600000,
+ "end": 39600000
+ },
+ {
+ "name":"Period 3",
+ "start": 40200000,
+ "end": 43200000
+ },
+ {
+ "name":"Lunch",
+ "start": 43200000,
+ "end": 46800000
+ },
+ {
+ "name":"Period 4",
+ "start": 46800000,
+ "end": 49800000
+ }
+ ],
+ "regular-a":[
+ {
+ "name":"Period 1",
+ "start": 33000000,
+ "end": 36000000
+ },
+ {
+ "name":"Period 2",
+ "start": 36600000,
+ "end": 39600000
+ },
+ {
+ "name":"Period 3",
+ "start": 40200000,
+ "end": 43200000
+ },
+ {
+ "name":"Lunch",
+ "start": 43200000,
+ "end": 46800000
+ },
+ {
+ "name":"Period 4",
+ "start": 46800000,
+ "end": 49800000
+ }
+ ],
+ "regular-b":[
+ {
+ "name":"Period 1",
+ "start": 33000000,
+ "end": 36000000
+ },
+ {
+ "name":"Period 2",
+ "start": 36600000,
+ "end": 39600000
+ },
+ {
+ "name":"Period 3",
+ "start": 40200000,
+ "end": 43200000
+ },
+ {
+ "name":"Lunch",
+ "start": 43200000,
+ "end": 46800000
+ },
+ {
+ "name":"Period 4",
+ "start": 46800000,
+ "end": 49800000
+ }
+ ],
+ "regular-c":[
+ {
+ "name":"Period 1",
+ "start": 33000000,
+ "end": 36000000
+ },
+ {
+ "name":"Period 2",
+ "start": 36600000,
+ "end": 39600000
+ },
+ {
+ "name":"Period 3",
+ "start": 40200000,
+ "end": 43200000
+ },
+ {
+ "name":"Lunch",
+ "start": 43200000,
+ "end": 46800000
+ },
+ {
+ "name":"Period 4",
+ "start": 46800000,
+ "end": 49800000
+ }
+ ]
+}
--
2.29.1 |
Allow the date and time used in the clock to be overriden (for testing purposes), and refactor some code in redraw_clock().
Adds "covid" option to schedule.json and changes clock.js to use the quarantine schedule Co-authored-by: psvenk <45520974+psvenk@users.noreply.github.com>
5f8b28c
to
7a274f6
Compare
This seems to work well notwithstanding #140 (i.e., the class names are wrong but consistent with what is displayed on the "Schedule" tab). I'll merge this later today unless I find some bug between now and then. Thanks @andOrlando! |
Until issue Aspine#140 ("Schedule Tab Only Displays First Three Classes") is fixed, certain periods do not exist in the schedule; the clock code now fails gracefully in this case.
Closes #84
adds quarantine_schedule.json
changes clock.js slightly to make it work with either quarantine_schedule.json or schedule.json
still probably need improvement