aboutsummaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/models')
-rw-r--r--src/models/EventInfo.js41
-rw-r--r--src/models/Lab.js17
-rw-r--r--src/models/PeerTeacher.js29
3 files changed, 87 insertions, 0 deletions
diff --git a/src/models/EventInfo.js b/src/models/EventInfo.js
new file mode 100644
index 0000000..c1624a8
--- /dev/null
+++ b/src/models/EventInfo.js
@@ -0,0 +1,41 @@
+export default class EventInfo {
+ constructor(days = '', start = 0, end = 0) {
+ this.days = days;
+ this.start = start;
+ this.end = end;
+ }
+
+ static timeToStr(time) {
+ let hour = Math.floor(time / 100);
+ let minute = time % 100;
+ const meridiem = (hour < 12) ? 'AM' : 'PM';
+
+ if (hour === 0) {
+ hour = 12;
+ } else if (hour > 12) {
+ hour -= 12;
+ }
+
+ if (minute < 10) {
+ minute = `0${minute}`;
+ }
+
+ return `${hour}:${minute} ${meridiem}`;
+ }
+
+ conflictsWith(event) {
+ const daysConflict = event.days.match(new RegExp(`[${this.days}]`));
+
+ if (daysConflict) {
+ return (this.start <= event.end) && (event.start <= this.end);
+ }
+ return false;
+ }
+
+ get info() {
+ if (this.days === '') {
+ return 'ONLINE';
+ }
+ return `${this.days} ${EventInfo.timeToStr(this.start)}-${EventInfo.timeToStr(this.end)}`;
+ }
+}
diff --git a/src/models/Lab.js b/src/models/Lab.js
new file mode 100644
index 0000000..2e4412d
--- /dev/null
+++ b/src/models/Lab.js
@@ -0,0 +1,17 @@
+import EventInfo from '@/models/EventInfo';
+
+export default class Lab {
+ constructor(course = 0, section = 0, event = new EventInfo()) {
+ this.course = course;
+ this.section = section;
+ this.event = event;
+ }
+
+ get id() {
+ return `${this.course}-${this.section}`;
+ }
+
+ get fullInfo() {
+ return `${this.id} ${this.event.info}`;
+ }
+}
diff --git a/src/models/PeerTeacher.js b/src/models/PeerTeacher.js
new file mode 100644
index 0000000..00a2f0d
--- /dev/null
+++ b/src/models/PeerTeacher.js
@@ -0,0 +1,29 @@
+export default class PeerTeacher {
+ constructor(firstname = '', lastname = '', uin = 0) {
+ this.firstname = firstname;
+ this.lastname = lastname;
+ this.uin = uin;
+ this.events = [];
+ this.assignedLabs = new Set();
+ }
+
+ conflictsWith(event) {
+ let conflicts = false;
+ this.events.every((item) => {
+ if (item.conflictsWith(event)) {
+ conflicts = true;
+ return false;
+ }
+ return true;
+ });
+ return conflicts;
+ }
+
+ get name() {
+ return `${this.firstname} ${this.lastname}`;
+ }
+
+ get id() {
+ return this.uin;
+ }
+}