Skip to content

Commit

Permalink
Merge pull request #24 from AAP9002/11-restructure-for-features-and-a…
Browse files Browse the repository at this point in the history
…pi-v2

11 restructure for features and api v2
  • Loading branch information
AAP9002 authored Nov 16, 2023
2 parents 593365b + 207cf28 commit 0e5650d
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 67 deletions.
Binary file added Poster.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[![CodeQL](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/github-code-scanning/codeql)
[![.github/workflows/deploy.yml](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/deploy.yml/badge.svg)](https://github.com/AAP9002/Timetable-ICS-Live-Editor/actions/workflows/deploy.yml)
[![GitHub last commit (branch)](https://img.shields.io/github/last-commit/AAP9002/Timetable-ICS-Live-Editor/main?label=Last%20Live%20Publish&logo=iterm2)](https://github.com/AAP9002/Timetable-ICS-Live-Editor/)
[![Website](https://img.shields.io/website?url=https%3A%2F%2Faap9002.github.io%2FTimetable-ICS-Live-Editor%2F&logo=githubpages)](https://aap9002.github.io/Timetable-ICS-Live-Editor/)


![Screenshot from 2023-09-30 11-49-35](https://github.com/AAP9002/Timetable-ICS-Live-Editor/assets/42409957/390a7f9b-e74f-4b9f-89a6-818cba1577e7)
Expand Down Expand Up @@ -29,3 +31,14 @@ Get started at [https://aap9002.github.io/Timetable-ICS-Live-Editor/](https://aa
- [x] Materials Science
- [x] Areospace Engineering
- [x] Physics

# Contributing
## Adding courses
Add courses in allCourses.md
## Adding features
1. Create an issue
1. fork the project
1. create a new branch
1. read ```/server/features/_new_feature_doc.md```
1. add your feature
1. create a pull request
File renamed without changes.
4 changes: 2 additions & 2 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ function App() {
<p>PRs are welcome, please feel free to add courses, add a feature or fix a bug</p>
<p>Github Repo: <a href='https://github.com/AAP9002/Timetable-ICS-Live-Editor/'>https://github.com/AAP9002/Timetable-ICS-Live-Editor/</a></p>
<br />
<a href='https://github.com/AAP9002/Timetable-ICS-Live-Editor/blob/main/server/allCourses.md'>Contribute by adding courses here</a>
<a href='https://github.com/AAP9002/Timetable-ICS-Live-Editor/blob/main/allCourses.md'>Contribute by adding courses here</a>

<h2 id='supported' className='mt-5'>Supported Courses</h2>
<p>T-I-L-E is available for a limited number of courses at UoM, you can add yours <a href='https://github.com/AAP9002/Timetable-ICS-Live-Editor/blob/main/server/allCourses.md'>on github</a>.</p>
<p>T-I-L-E is available for a limited number of courses at UoM, you can add yours <a href='https://github.com/AAP9002/Timetable-ICS-Live-Editor/blob/main/allCourses.md'>on github</a>.</p>
<p>So far, we support:</p>
<a href='https://www.manchester.ac.uk/study/undergraduate/courses/2023/00560/bsc-computer-science/' target='_blank' rel="noreferrer" >Computer Science</a>
<a href='https://www.manchester.ac.uk/study/undergraduate/courses/2023/00609/bsc-microbiology/' target='_blank' rel="noreferrer" >Microbiology</a>
Expand Down
29 changes: 29 additions & 0 deletions server/features/_new_feature_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Implement your feature in its own file in /server/features
```js
// your feature
// @author : your github username
// @date : the date you created this file
// @description : a short description of what your feature does
// @params : any parameters your feature needs
// @returns : what your feature returns
// @notes : any notes you want to add

function run(cal) {
// your code

return cal
}

module.exports = {
run,
};
```

## Set up your feature in /server/index.js
- import your code within the commented section 'IMPORT FEATURES'
- Add a switch case for your feature in the performModifications method

## Finally
- add your feature to the README.md
- create a pull request
- once merged, I will add code on the front end to users can enable your feature
36 changes: 36 additions & 0 deletions server/features/forcedBreakPoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Forcing calenders to update events once a day
// @author : aap9002
// @date : 01/11/2023
// @description : once a day between 01:00 and 04:00, force a refresh of the events to restyle any new formatting
// @params : the calender in string format
// @returns : the calender in string format
// @notes : Be aware the time is based on the server time not UTC

const regex = /^LAST-MODIFIED:.*/gm;

/**
* Force events to update format once a day
* @param {string} cal
* @returns cal with last modified date time set
*/
function run(cal) {
// once a day between 01:00 and 04:00, force a refresh of the events to restyle any new formatting
// this is as modifications to the event will not be recognised and updated unless the UoM event changes on the timetabling system itself
// so this will manual set the last modified each day to force an update in the calender app
// NB. it will stop doing this at 4 am so any changes in the day will be recognised and updated live
// NB. 3 hour window set as the ICS is set to refresh evert 2 hours, so this should affect all users
const date = new Date();
const hour = date.getHours();
if (hour >= 1 && hour <= 4) {
datestr = date.toISOString().split('T')[0];
datestr = datestr.split('-').join('');
datestr = "LAST-MODIFIED:" + datestr + "T000000";
cal = cal.replace(regex, datestr);
}

return cal;
}

module.exports = {
run,
};
81 changes: 81 additions & 0 deletions server/features/replaceCodeName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Replace course codes
// @author : aap9002
// @date : 01/11/2023
// @description : Find and replace course codes with [course names] or [course code and course name]
// @params : the calender in string format
// @returns : the calender in string format


const pattern = /SUMMARY:[^\/]*\//g // REGEX to search the ICAL for the course code

/**
* List unique course names in the string
* @param {string} cal
* @returns List of unique course codes
*/
function parseCourseCodes(cal) {
const uniqueMatches = new Set();

let match;
while ((match = pattern.exec(cal)) !== null) {
//console.log(match[0].split(':')[1].split('/')[0]);
uniqueMatches.add(match[0].split(':')[1].split('/')[0]);
}
const uniqueCourseCodesArray = Array.from(uniqueMatches);
return uniqueCourseCodesArray;
}

/**
* Replace course codes with full course names
* @param {string} cal
* @returns cal with replacements
*/
function replaceCourseCodesWithNames(cal, courses) {
// get unique course codes
let uniqueCourseCodesArray = parseCourseCodes(cal);

// replace course codes with names
for (let i = 0; i < uniqueCourseCodesArray.length; i++) {
const courseCode = uniqueCourseCodesArray[i];
try {
const courseName = courses.find(course => course.split(' ')[0] === courseCode).split(' ').slice(1).join(' ');
cal = cal.split(courseCode).join(courseName);
}
catch (e) {
// if the course code is not found in the allCourses.md file, log it
console.log(courseCode + " not found in allCourses.md");
}
}

return cal;
}

/**
* Replace course codes with code and full course names
* @param {string} cal
* @returns cal with replacements
*/
function replaceCourseCodesWithCodeAndNames(cal, courses) {
// get unique course codes
let uniqueCourseCodesArray = parseCourseCodes(cal);

// replace course codes with names
for (let i = 0; i < uniqueCourseCodesArray.length; i++) {
const courseCode = uniqueCourseCodesArray[i];
try {
const courseName = courses.find(course => course.split(' ')[0] === courseCode).split(' ').slice(1).join(' ');
cal = cal.split(courseCode).join(courseCode + " " + courseName);
}
catch (e) {
// if the course code is not found in the allCourses.md file, log it
console.log(courseCode + " not found in allCourses.md");
}
}

return cal;
}

module.exports = {
replaceCourseCodesWithNames,
replaceCourseCodesWithCodeAndNames
};
Loading

0 comments on commit 0e5650d

Please sign in to comment.