예제 #1
0
파일: core.py 프로젝트: exhuma/lost-tracker
def stats(conf):
    """
    Fetch some basic stats from the system.
    """
    num_groups = Group.all().count()
    num_slots = len(TimeSlot.all(conf)) * 2  # DIR_A and DIR_B
    return {
        'groups': num_groups,
        'slots': num_slots,
        'free_slots': num_slots - num_groups,
        'load': float(num_groups) / num_slots
    }
예제 #2
0
파일: core.py 프로젝트: exhuma/lost-tracker
def _generate_state_list(station):
    """
    Generates a simple Python dictionary with current group "states".
    """
    if not station:
        return []
    groups = Group.all().order_by(Group.order)
    state_info = DB.session.query(GroupStation).filter(
        GroupStation.station == station)
    state_info_map = {state.group: state for state in state_info}
    output = []
    for group in groups:
        si = state_info_map.get(group)
        output.append({
            "stationId": si.station_id if si else 0,
            "groupId": group.id,
            "groupName": group.name,
            "formScore": (si.form_score or 0) if si else 0,
            "stationScore": (si.score or 0) if si else 0,
            "state": si.state if si else 0
        })
    output = sorted(output, key=lambda x: (x['state'], x['groupName']))
    return output