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

feat(bus): option to mark bus as delayed #1538

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions intranet/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,41 @@
# July = 7
YEAR_TURNOVER_MONTH = 7

# School years spans 2 calendar years. start_school_year is the year the school year starts in, and end_school_year is the year the school year ends in.
# School years span 2 calendar years.
# start_school_year is the year the school year starts in, and end_school_year is the year the school year ends in.
# For example, for the 2022-2023 school year, start_school_year = 2022 and end_school_year = 2023.
start_school_year = datetime.date.today().year - 1 if datetime.date.today().month < YEAR_TURNOVER_MONTH else datetime.date.today().year
end_school_year = start_school_year + 1


# fmt: off
""" !! -------- UPDATE ANNUALLY -------- !!
Update this section annually after summer school ends and before school starts.
Last updated: 2022-08-30. """
School year last updated: 2022-08-30
Hoco last updated: 2022-08-30
"""

# When school is scheduled to start and end
SCHOOL_START_DATE = datetime.date(start_school_year, 8, 22)
SCHOOL_END_DATE = datetime.date(end_school_year, 6, 16)
SCHOOL_START_DATE = datetime.date(start_school_year,
8, 22 # UPDATE THIS! Value when last updated: August 22, 2022 # noqa: E128
) # noqa: E124
SCHOOL_END_DATE = datetime.date(end_school_year,
6, 16 # UPDATE THIS! Value when last updated: June 16, 2023 # noqa: E128
) # noqa: E124

# Dates when hoco starts and ends
HOCO_START_DATE = datetime.date(start_school_year, 9, 19)
HOCO_END_DATE = datetime.date(start_school_year, 9, 24)
HOCO_START_DATE = datetime.date(start_school_year,
9, 19 # UPDATE THIS! Value when last updated: September 19, 2022 # noqa: E128
) # noqa: E124
HOCO_END_DATE = datetime.date(start_school_year,
9, 24 # UPDATE THIS! Value when last updated: September 24, 2022 # noqa: E128
) # noqa: E124

""" -------- END UPDATE ANNUALLY -------- """
# fmt: on

# Default fallback time for start and end of school if no schedule is available
SCHOOL_START_HOUR = 8 # Not currently used
SCHOOL_START_MINUTE = 40 # Not currently used
SCHOOL_START_HOUR = 8
SCHOOL_START_MINUTE = 40
SCHOOL_END_HOUR = 16
SCHOOL_END_MINUTE = 0

Expand Down
105 changes: 61 additions & 44 deletions intranet/static/js/bus-afternoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getSocket } from "./bus-shared.js";
/* globals Messenger */
var bus = {};

$(function() {
$(function () {
let base_url = window.location.host;

bus.sendUpdate = function (data) {
Expand All @@ -28,11 +28,11 @@ $(function() {
bus.StatusGroupModel = Backbone.Model.extend();

bus.PersonalStatusView = Backbone.View.extend({
initialize: function() {
initialize: function () {
_.bindAll(this, 'render');
this.template = _.template($('#personal-status').html());
},
render: function() {
render: function () {
var container = this.$el,
renderedContent = this.template(this.model.toJSON());
container.html(renderedContent);
Expand Down Expand Up @@ -84,7 +84,7 @@ $(function() {
'text': this.text
};
this.$el.html(this.buttonTemplate(data))
.removeClass('search-widget');
.removeClass('search-widget');
return this;
},
renderSearchView: function (routeList, action) {
Expand All @@ -95,23 +95,36 @@ $(function() {
let busList = [];
if (action === 'Search for a bus') {
busList = routeList.filter(bus => bus.attributes.status === 'a')
.filter(bus => bus.attributes.route_name.includes('JT'))
.map(bus => bus.attributes);
.filter(bus => bus.attributes.route_name.includes('JT'))
.map(bus => bus.attributes);
} else if (action === 'Mark a bus as arrived or on time') {
busList = routeList.filter(bus => !bus.attributes.route_name.includes('JT'))
.map(bus => {
if (bus.attributes.status === 'a') {
// TODO: less hacky deep copy
let attr = JSON.parse(JSON.stringify(bus.attributes));
attr.route_name = `Mark ${bus.attributes.route_name} as on time`;
return attr;
} else {
return bus.attributes;
}
});
busList = routeList.map(bus => {
if ((bus.attributes.status === 'a' || bus.attributes.status === 'd') && !bus.attributes.route_name.includes('JT')) {
let attr = JSON.parse(JSON.stringify(bus.attributes));
attr.route_name = `Mark ${bus.attributes.route_name} as on time`;
return attr;
}
else if (bus.attributes.status === 'o') {
let attr = JSON.parse(JSON.stringify(bus.attributes));
let attr2 = JSON.parse(JSON.stringify(bus.attributes));
if (bus.attributes.route_name.includes('JT')) {
attr.route_name = `Mark ${bus.attributes.route_name} as delayed`;
return attr;
}
attr.route_name = `Mark ${bus.attributes.route_name} as delayed`;
attr2.route_name = `Mark ${bus.attributes.route_name} as arrived`;
return [attr, attr2];
} else {
if (!bus.attributes.route_name.includes('JT')) {
return bus.attributes;
}
return null;

}
}).flat().filter((element) => element != null);
} else if (action === 'Assign a bus to this space') {
busList = routeList.filter(bus => bus.attributes.status !== 'a')
.map(bus => bus.attributes);
.map(bus => bus.attributes);
}
let selectField = container.find('select').selectize({
'options': busList,
Expand Down Expand Up @@ -159,24 +172,28 @@ $(function() {
if (!this.selected) {
return;
}
let route = this.model.findWhere({route_name: e.target.value}).attributes;
let route = this.model.findWhere({ route_name: e.target.value }).attributes;
route.space = this.selected.id;
route.status = 'a';
bus.sendUpdate(route);
} else if (this.action === 'Mark a bus as arrived or on time') {
let route_name = '';
let st = '';
// TODO: this is also super hacky
// Essentially, this checks if the selected route has "Mark"
// at the beginning, implying that it's to be marked on time.
if (e.target.value.indexOf('Mark') === 0) {
if (e.target.value.includes('on')) {
route_name = e.target.value.split(' ')[1];

st = 'o';
} else {
route_name = e.target.value;
}
else if (e.target.value.includes('delayed')) {
route_name = e.target.value.split(' ')[1];

st = 'd';
}
else {
route_name = e.target.value.split(' ')[1];
st = 'a';
}
let route = this.model.findWhere({route_name: route_name}).attributes;
let route = this.model.findWhere({ route_name: route_name }).attributes;
route.status = st;
bus.sendUpdate(route);
}
Expand Down Expand Up @@ -350,18 +367,18 @@ $(function() {
// fallbacks to avoid issues that have appeared in the past with the "sans-serif" default.
text.font("family", "Helvetica, Arial, 'Open Sans', 'Liberation Sans', sans-serif");

if(window.isSignage) {
if (window.isSignage) {
var tspan = $(text.node).find("tspan");
tspan.attr({"x": 0, "dy": 20.5});
tspan.attr({ "x": 0, "dy": 20.5 });

// If we run this directly, it hasn't rendered yet, so we have to run it after a timeout
setTimeout(function() {
setTimeout(function () {
var tbox = tspan.get(0).getBBox();
var sbox = space.getBBox();

var offset;
var dimenDiff;
if(tbox.width > tbox.height) {
if (tbox.width > tbox.height) {
dimenDiff = sbox.width - tbox.width;
offset = tbox.x - sbox.x;
}
Expand All @@ -370,9 +387,9 @@ $(function() {
offset = tbox.y - sbox.y;
}

if(dimenDiff < offset + 5) {
if (dimenDiff < offset + 5) {
text.node.classList.add("small");
if(route.attributes.route_name.length > 5) {
if (route.attributes.route_name.length > 5) {
text.node.classList.add("extra-small");
}
}
Expand All @@ -381,21 +398,21 @@ $(function() {
else {
var tspan = $(text.node).find("tspan");

setTimeout(function() {
setTimeout(function () {
var tbox = tspan.get(0).getBBox();
var sbox = space.getBBox();

var offset;
var dimenDiff;
if(tbox.width > tbox.height) {
if (tbox.width > tbox.height) {
dimenDiff = sbox.width - tbox.width;
offset = tbox.x - sbox.x;
}
else {
dimenDiff = sbox.height - tbox.height;
offset = tbox.y - sbox.y;
}
if(dimenDiff < offset + 5 || route.attributes.route_name.length > 5) {
if (dimenDiff < offset + 5 || route.attributes.route_name.length > 5) {
text.node.classList.add("extra-small");
}
}, 0);
Expand Down Expand Up @@ -560,7 +577,7 @@ $(function() {
// equatorial radius of Earth = 6,378.1370 km
// polar radius of Earth = 6,356.7523 km

// length of 1 deg equatorial longitude
// length of 1 deg equatorial longitude
let deg_lng_eq = 6378.1370 * 2 * Math.PI / 360;
// length of 1 deg equatorial latitude
let deg_lat_eq = 6356.7523 * 2 * Math.PI / 360;
Expand All @@ -587,7 +604,7 @@ $(function() {
}*/
let degrees = (direction) * (180 / Math.PI) - 49 + 90;
// let degrees = (direction) * (180 / Math.PI);
this.busDriverEl.css({'transform' : 'rotate('+ degrees +'deg)'});
this.busDriverEl.css({ 'transform': 'rotate(' + degrees + 'deg)' });
this.mapbox.setCenter(this.busDriverBus.point.coordinates);

this.busDriverBus.lastFrame = time;
Expand Down Expand Up @@ -634,7 +651,7 @@ $(function() {
container.empty();
container.append(this.template(this.model.toJSON()));
_.each(this.model.attributes.collection, function (route) {
container.append(new bus.RouteView({model: route}).render().el);
container.append(new bus.RouteView({ model: route }).render().el);
});
return this;
}
Expand Down Expand Up @@ -699,23 +716,23 @@ $(function() {
}
});

if(isAdmin) {
$(".bus-announcement-save").click(function() {
if (isAdmin) {
$(".bus-announcement-save").click(function () {
bus.sendUpdate({
announcement: $(".bus-announcement").text()
});
$(".bus-announcement-save").text("Saved!").css("color", "green");
setTimeout(function() {
setTimeout(function () {
$(".bus-announcement-save").text("Save").css("color", "");
}, 1500);
});
$(".bus-announcement-clear").click(function() {
$(".bus-announcement-clear").click(function () {
$(".bus-announcement").text("");
bus.sendUpdate({
announcement: "",
});
$(".bus-announcement-clear").text("Cleared!").css("color", "green");
setTimeout(function() {
setTimeout(function () {
$(".bus-announcement-clear").text("Clear").css("color", "");
}, 1500);
});
Expand All @@ -740,7 +757,7 @@ $(function() {
Backbone.trigger('recordScore', e);
});
}
// window.personalStatusView = new bus.personalStatusView();
// window.personalStatusView = new bus.personalStatusView();
});

/* TODO: flip bus map to be horizontal
Expand Down