Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time

not exported

DayDate
115/5/2023
216/5/2023
317/5/2023
418/5/2023
SlotTimings
109:00–10:30
210:45–12:15
313:00–15:30
415:45–17:00
DaySlotRowTitle
111Introduction
122Style
133Maths / Algorithms / Plots
144Ethics / Writing Exercise (AH/JB)
215Literature review
226Editing / Proofreading
237Proofreading Exercise
248OSR / Impact (EG)
319Data analysis (SS)
3210Presenting
3311Seminar (2pm)
3412Publishing (ME)
4113Presentations
4214Presentations (2)
4315Research toolkit
4416Closing
import tabulate
import pandas as pd

times = pd.DataFrame(times, columns=["Slot", "Timings"])
timetable = pd.DataFrame(timetable, columns=["Day", "Slot", "Row", "Title"])


#timetable = timetable.assign(Title=lambda x: x.apply(fmt_i, axis=1))

timetable = timetable.drop(columns=['Row'])
timetable = timetable.join(times.set_index("Slot"), on="Slot")
timetable = timetable.pivot(index="Timings", columns="Day", values="Title")

timetable.columns = [f"Day {d}" for d in timetable.columns]

with open("timetable.org", "w") as f:
    print("* Timetable", file=f)

    print(tabulate.tabulate(
        timetable,
        tablefmt="orgtbl", showindex=True, headers="keys"), file=f)

# for i in range(1, 5):
#     print(f"** Day {i}")
#     print(tabulate.tabulate(
#         timetable[[f'Day {i}']],
#         tablefmt="orgtbl", showindex=True, headers="keys"))


# ensure you set pyvenv-workon to ical first
import pandas as pd
from icalendar import Calendar, Event
from datetime import datetime
import re
mre = re.compile(r"([0-9]*:[0-9]*)--([0-9]*:[0-9]*)")
timeformat = "%H:%M"

def convert_time_range(s):
    m = mre.match(s)
    assert m
    return (datetime.strptime(m[1], timeformat).time(),
            datetime.strptime(m[2], timeformat).time())

slots = (pd.DataFrame(timetable, columns=["day", "slot", "row", "title"])
         .assign(day=lambda x: x.day.astype(int))
         )

times = (pd.DataFrame(times, columns=["slot", "times"])
         .assign(slot=lambda x: x.slot.astype(int))
         .assign(time_range=lambda x: x.times.apply(convert_time_range))
         .drop(['times'], axis=1)
         .set_index("slot")
         )

daydate = (pd.DataFrame(daydate, columns=["day", "date"])
           .assign(day=lambda x: x.day.astype(int),
                   date=lambda x: x.date.apply(lambda y: datetime.strptime(y, "%d/%m/%Y")))
           .set_index("day")
           )



slots = (slots.join(times, on='slot')
 .join(daydate, on="day")
)

cal = Calendar()
cal.add('prodid', '-//My calendar product//mxm.dk//')
cal.add('version', '2.0')

for ix, row in slots.iterrows():

    dstart = datetime.combine(row.date, row.time_range[0])
    dend = datetime.combine(row.date, row.time_range[1])

    event = Event()
    event.add('summary', row.title)
    event.add('location', "")
    event.add('dtstart', dstart)
    event.add('dtend', dend)
    event.add('dtstamp', datetime.now())
    cal.add_component(event)


with open("pgrweek.ics", "wb") as f:
    f.write(cal.to_ical())

from os import system

system("rsync pgrweek.ics cogentee:public_html/pgrweek.ics")

slots.to_csv("slots.csv")