<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, re, sys, logging
import pytz, requests
from datetime import datetime, timedelta
from jinja2 import Environment, FileSystemLoader
import ics_parser

URL_STUDY_ACTIVITIES = 'https://dk.timeedit.net/web/itu/db1/public/ri6Q7ZYQQZ0Z6gQ9Q1gfQvXx5fY90Zc0nY5yZo.ics'
URL_ACTIVITIES = 'https://dk.timeedit.net/web/itu/db1/public/ri6g706QyfQZXxQ5f5gon9vZ5YY0Q0Q1Z0QZcZY.ics'
URL_WIFI = 'https://www.itu.dk/people/bfri/eitu.json'
FAKES = [
    r'ScrollBar', # Locked
    r'Balcony', # Open space
    r'learnIT', # Virtual
    r'DesignLab', # Lab, locked
    r'InterMediaLab', # Lab, locked
    r'5A30',
    r'3A20', # Locked
    r'3A50', # Stuffed with computers
    r'3A52',
    r'^$', # Bug
]
ROOM_TO_WIFI = {
    'Aud 1': 'AUD1front0A11',
    'Aud 2': 'Aud2front0A35',
    'Aud 3': 'AUD32-3A56',
    'Aud 4': 'AUD44A60',
    '3A12/14': '3A12',
    '5A14-16': '5A14',
}

# Logging
logging.getLogger().setLevel(logging.INFO)

# Fix unicode madness
reload(sys)
sys.setdefaultencoding('utf8')

# Establish timezone and present time
TZ = pytz.timezone('Europe/Copenhagen')
NOW = datetime.now(TZ)

def format_date(date): return date.strftime('%a %b %d at %H:%M')

def format_td(td): return '%02dh %02dm' % (td.total_seconds() // 3600, td.total_seconds() % 3600 // 60)

def format_wifi(reading):
    timestamp, clients = reading
    if clients > 5: return 'Many'
    if clients > 0: return 'Few'
    return 'Empty'

def clean_room(room):
    room = re.sub(r'^Room: ', '', room)
    room = re.sub(r' \(.*\)$', '', room)
    return room

def is_fake(room):
    return any([re.search(fake, room, re.IGNORECASE) for fake in FAKES])

def fetch_and_parse(url):
    logging.info('Fetching %s' % url)
    ics = requests.get(url).text
    logging.info('Parsing %s' % url)
    calendar = ics_parser.parse(ics)
    events = [{
        'rooms': map(clean_room, event['LOCATION'].split(', ')),
        'start': event['DTSTART'].astimezone(TZ),
        'end': event['DTEND'].astimezone(TZ),
        'uid': event['UID'],
    } for event in calendar]
    return events

def eitu():

    # Fetch iCalendar sources and parse events<commit_msg>Tweak status thresholds<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, re, sys, logging
import pytz, requests
from datetime import datetime, timedelta
from jinja2 import Environment, FileSystemLoader
import ics_parser

URL_STUDY_ACTIVITIES = 'https://dk.timeedit.net/web/itu/db1/public/ri6Q7ZYQQZ0Z6gQ9Q1gfQvXx5fY90Zc0nY5yZo.ics'
URL_ACTIVITIES = 'https://dk.timeedit.net/web/itu/db1/public/ri6g706QyfQZXxQ5f5gon9vZ5YY0Q0Q1Z0QZcZY.ics'
URL_WIFI = 'https://www.itu.dk/people/bfri/eitu.json'
FAKES = [
    r'ScrollBar', # Locked
    r'Balcony', # Open space
    r'learnIT', # Virtual
    r'DesignLab', # Lab, locked
    r'InterMediaLab', # Lab, locked
    r'5A30',
    r'3A20', # Locked
    r'3A50', # Stuffed with computers
    r'3A52',
    r'^$', # Bug
]
ROOM_TO_WIFI = {
    'Aud 1': 'AUD1front0A11',
    'Aud 2': 'Aud2front0A35',
    'Aud 3': 'AUD32-3A56',
    'Aud 4': 'AUD44A60',
    '3A12/14': '3A12',
    '5A14-16': '5A14',
}

# Logging
logging.getLogger().setLevel(logging.INFO)

# Fix unicode madness
reload(sys)
sys.setdefaultencoding('utf8')

# Establish timezone and present time
TZ = pytz.timezone('Europe/Copenhagen')
NOW = datetime.now(TZ)

def format_date(date): return date.strftime('%a %b %d at %H:%M')

def format_td(td): return '%02dh %02dm' % (td.total_seconds() // 3600, td.total_seconds() % 3600 // 60)

def format_wifi(reading):
    timestamp, clients = reading
    if clients > 5: return 'Many'
    if clients > 1: return 'Few'
    return 'Empty'

def clean_room(room):
    room = re.sub(r'^Room: ', '', room)
    room = re.sub(r' \(.*\)$', '', room)
    return room

def is_fake(room):
    return any([re.search(fake, room, re.IGNORECASE) for fake in FAKES])

def fetch_and_parse(url):
    logging.info('Fetching %s' % url)
    ics = requests.get(url).text
    logging.info('Parsing %s' % url)
    calendar = ics_parser.parse(ics)
    events = [{
        'rooms': map(clean_room, event['LOCATION'].split(', ')),
        'start': event['DTSTART'].astimezone(TZ),
        'end': event['DTEND'].astimezone(TZ),
        'uid': event['UID'],
    } for event in calendar]
    return events

def eitu():

    # Fetch iCalendar sources and parse events
{'fraction_non_alphanumeric': 0.16270566727605118, 'fraction_numerical': 0.04250457038391225, 'mean_word_length': 3.6913183279742765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7353876', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1727, 'n_words': 357}