Loading

Paste #ptji6mpbg

  1. #/usr/bin/env python3
  2. import pandas as pd
  3. import datetime as dt
  4.  
  5.  
  6. class Calendar(object):
  7.     # :(
  8.     modulecodemap = (
  9.         ("COM00001C-A", "ICAR"),  # Introduction to Computer Architectures 15
  10.         ("COM00001H-A", "ARTS"),  # Analysable Real-Time Systems 20
  11.         ("COM00001I-A", "ARIN"),  # Artificial Intelligence 20
  12.         ("COM00002H-A", "CVIS"),  # Computer Vision 20
  13.         ("COM00002I-A", "COCO"),  # Computability & Complexity 10
  14.         ("COM00003C-A", "HACS"),  # Human Aspects of Computer Science 20
  15.         ("COM00003H-A", "EMBS"),  # Embedded Systems Design & Implementation 20
  16.         ("COM00004H-A", "ENAR"),  # Enterprise Architecture 20
  17.         ("COM00005C-A", "MFCS"),  # Mathematical Foundations of Computer Science 20
  18.         ("COM00005H-A", "GRAT"),  # Computing by Graph Transformation 20
  19.         ("COM00005I-A", "POPL"),  # Principles of Programming Languages 20
  20.         ("COM00006C-A", "NUMA"),  # Numerical Analysis 10
  21.         ("COM00006H-A", "ICOT"),  # Information & Coding Theory 20
  22.         ("COM00007C-A", "TPOP"),  # Theory and Practice of Programming 20
  23.         ("COM00007H-A", "INCA"),  # Introduction to Neural Computing & Applications 20
  24.         ("COM00007I-A", "SYAC"),  # Systems Software & Compilers 30
  25.         ("COM00008C-A", "SKIL"),  # Skills, Knowledge & Independent Learning 5
  26.         ("COM00008I-A", "SEPR"),  # Software Engineering Project 30
  27.         ("COM00009C-A", "FESC"),  # Foundations in Electronics, Signals and Circuits 20
  28.         ("COM00009H-A", "MAIG"),  # Multi-Agent Interaction & Games 20
  29.         ("COM00009I-A", "VIGR"),  # Vision & Graphics 10
  30.         ("COM00010C-A", "PROM"),  # Programming of Micro-controllers 10
  31.         ("COM00010H-A", "MLAP"),  # Machine Learning & Applications 20
  32.         ("COM00012H-A", "PCOC"),  # Programming: Correctness by Construction 20
  33.         ("COM00012I-A", "EMPR"),  # Embedded Systems Project 30
  34.         ("COM00013H-A", "PRBE"),  # Project: Computer Science with Embedded Systems 40
  35.         ("COM00014H-A", "PRBM"),  # Project: Mathematics and Computer Science 40
  36.         ("COM00015H-A", "PRBX"),  # Project: Computer Science 40
  37.         ("COM00016H-A", "IAPT"),  # Interactive Application Programming Techniques 20
  38.         ("COM00042M-A", "QIPR"),  # Quantum Information Processing 10
  39.         ("COM00045M-A", "QUCO"),  # Quantum Computation 10
  40.         ("COM00063M-A", "SAVE"),  # Static Analysis & Verification 10
  41.         ("COM00066M-A", "ALAS"),  # Adaptive & Learning Agents 10
  42.         ("COM00068M-A", "COPR"),  # Constraint Programming 10
  43.         ("COM00069M-A", "CRSY"),  # Critical Systems 10
  44.         ("COM00071M-A", "EVCO"),  # Evolutionary Computation 10
  45.         ("COM00073M-A", "GPIG"),  # Group Project (Integrated Masters) 20
  46.         ("COM00080M-A", "PRIS"),  # Individual Project - Computer Science with Business Enterprise Systems 50
  47.         ("COM00081M-A", "PRIA"),  # Individual Project - Computer Science with Artificial Intelligence 50
  48.         ("COM00081M-A", "PRIY"),  # Individual Project - Computer Systems & Software Engineering 50
  49.         ("COM00082M-A", "PSEC"),  # Topics in Privacy & Security 10
  50.         ("COM00085M-A", "SMAT"),  # Software Measurement & Testing 10
  51.         ("COM00087M-A", "SYAR"),  # Systems Architecture 10
  52.         ("COM00104M-A", "AVIS"),  # Advanced Computer Vision 10
  53.         ("COM00106M-A", "NLPR"),  # Natural Language Processing 10
  54.         ("COM00111M-A", "MODE"),  # Model-Driven Engineering 10
  55.         ("ELE00061M-A", "EVHW"),  # Evolvable Hardware 10
  56.         ("ELE00068M-A", "SWIN"),  # Swarm Intelligence 10
  57.     )
  58.  
  59.     def __init__(self, filename):
  60.         cols = ["start-date", "start-time", "end-date", "end-time",
  61.                 "activity-type", "activity-name", "taught-by", "location",
  62.                 "directions", "module", "activity-notes", "contact-details"]
  63.         self.df = pd.read_csv(filename, skipinitialspace=True, index_col=False,
  64.                               skiprows=1, dayfirst=True, names=cols)
  65.  
  66.         # Merge the date/time fields
  67.         self.df["start-date"] = pd.to_datetime(self.df["start-date"] + ' ' + self.df["start-time"], dayfirst=True)
  68.         self.df["end-date"] = pd.to_datetime(self.df["end-date"] + ' ' + self.df["end-time"], dayfirst=True)
  69.         self.df = self.df.drop("start-time", 1).drop("end-time", 1)
  70.         self.df.index = self.df["start-date"]
  71.  
  72.         # Get rid of useless fields
  73.         self.df = self.df.drop(["directions", "activity-notes",
  74.                                 "contact-details", "activity-name"], 1)
  75.  
  76.         # Get rid of rows that are in the past
  77.         self.df = self.df[dt.datetime.now().strftime("%Y-%m-%d %H:%M") <= self.df["end-date"]]
  78.  
  79.         self.df = self.df.sort()
  80.  
  81.     def get_long_code(self, code):
  82.         """raises StopIteration"""
  83.         return next((x[0] for x in self.modulecodemap if x[1] == code.upper()))
  84.  
  85.     def get_next_lecture(self, code):
  86.         try:
  87.             longcode = self.get_long_code(code)
  88.         except StopIteration:
  89.             # Fine, we'll try with the existing code
  90.             longcode = code
  91.         module = self.df[self.df["module"] == longcode].iloc[0]
  92.         timestr = ""
  93.         if module["start-date"] is not dt.datetime.today():
  94.             timestr += module["start-date"].strftime("%Y-%m-%d")
  95.         timestr += module["start-date"].strftime(" %H:%M")
  96.  
  97.         return "{} {activity-type} in {location} at {}".format(code, timestr, **module)
  98.  
  99.  
  100. cal = Calendar("cs-calendar.csv")
  101. print(cal.get_next_lecture("EMPR"))
  102.  
  103. #for _, row in cal.df.iterrows():
  104. #    if "Runciman" not in str(row["taught-by"]): continue
  105. #    print(row)
  106. #    input()
  107.  

Comments