Skip to content
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

Merged
merged 3 commits into from
Oct 26, 2020
Merged

Conversation

andOrlando
Copy link
Collaborator

@andOrlando andOrlando commented Oct 23, 2020

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

@psvenk
Copy link
Member

psvenk commented Oct 23, 2020

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.

@psvenk
Copy link
Member

psvenk commented Oct 24, 2020

I did some refactoring to clock.js which makes clock.js more flexible and fixes #84 (because it's pretty closely related to this, one might as well put it in this pull request), and I merged quarantine_schedule.json with schedule.json (as a schedule option "covid"). Due to Aspen schedule quirks on weekends with the covid-19 schedule, I was not able to do comprehensive testing today. So, in case it would be useful later on, here is the original patch:

Patch
From 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

psvenk and others added 2 commits October 24, 2020 17:06
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>
@psvenk
Copy link
Member

psvenk commented Oct 26, 2020

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.
@psvenk psvenk merged commit 440e0df into Aspine:master Oct 26, 2020
@andOrlando andOrlando deleted the quarantine-clock branch December 20, 2020 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make clock use local time zone
2 participants