bjornregnell / sigrid

Help queue web app for lab sessions and tutorials.
Apache License 2.0
10 stars 5 forks source link

Correctly display number of students in physical room #27

Closed theolundqvist closed 2 years ago

theolundqvist commented 2 years ago

Currently Sigrid can be misleading when considering which room to attend since it isn't used by every student. This is a problem for students as well as ambulances.

A solution is to use the Google Sheet pgk-dod-allokering-utfall to get information about number of users in the room.

This solution assumes that the supervisors can enter the number of students during the lab and not afterwards.

I created an endpoint that serves the necessary information using Google App Script, (which is kind of slow).

https://script.google.com/macros/s/AKfycbyBDGI4uTVbmFgQhA-r7xz8_x_7IGFx-gd1_cxZQQ8SedlBlY1gnfzX39dhNMFsPbK8Bw/exec

Use the suffix ?date=2021-12-09 to get information about a certain date. Default is to serve the current rooms.

This solution solves #26 .

The other way around Another solution is to make the students always join Sigrid when entering a room. If we can accomplish this then Sigrid can serve pgk-dod-allokering-utfall with information about number of students. Then the supervisors won't have to enter that information into the Google Sheet.

theolundqvist commented 2 years ago

The endpoint is created in Google Apps Script which is coupled to Google Sheets, Drive, Photo and Gmail.

The endpoint is written in javascript and is executed in my name so that it can access the spreadsheet.


function getRoomInfoJSON(date) {
  let sheet = SpreadsheetApp.openById("1kCHXPQEMHI7JCCfXSoYr_chrGB_mJyENlh3vUGYAFU0").getSheetByName("pgk-dod-2021-allokering-utfall")

  let dataNames = sheet.getRange(1,1, 1, 11).getDisplayValues()[0]
  let dataMatrix = sheet.getRange(2, 1, sheet.getMaxRows(),11).getDisplayValues()

  let rows = dataMatrix.map(xs => convertArrayToObject(xs, dataNames))

  let filteredRows = rows
    .filter(x => x.kurs == "pgk" && x.datum == date)
    .map(x => ({
      kl: x.kl,
      rum: x.rum,
      allokerad: x.allokerad,
      jobbar: x.jobbade,
      antal: x.antal
    }))

  return JSON.stringify(filteredRows)
}

const doGet = (event = {parameter : {}}) => {
  let {parameter} = event
  let {date = dateString} = parameter

  let json = getRoomInfoJSON(date)

  console.log("output: \n" + json)

  return ContentService.createTextOutput(json).setMimeType(
    ContentService.MimeType.JSON
  );
};

//const dateString = "2021-12-09"
const dateString = getDateString()

function getDateString(){
  let date = new Date(Date.now()).toLocaleDateString().split("/")
  return [date[2], date[0], date[1]].join("-")
}

const convertArrayToObject = (array, keys) =>
  array.reduce((obj,cur, i) => ({ ...obj, [keys[i]]: cur}), {})
bjornregnell commented 2 years ago

This is a requirement on the students and supervisors and not on Sigrid... Closing this in favour of #32