def demo_entities(): """Simple test code to demonstrate using the entity classes. Output is to console. """ TIMED = True SCORED = False print("Demonstrate creating country objects:") CAN = Country("Canada", "CAN") AUS = Country("Australia", "AUS") all_countries.add_item(CAN.get_country_code(), CAN) all_countries.add_item(AUS.get_country_code(), AUS) for country in all_countries.get_items(): print(country) print("\nDemonstrate creating athlete objects, adding them to", "all_athletes and countries:") a1 = Athlete("1", "Athlete", "One", CAN) a2 = Athlete("2", "Athlete", "Two", CAN) a3 = Athlete("10", "Athlete", "Three", CAN) a4 = Athlete("4", "Athlete", "Four", AUS) a5 = Athlete("5", "Athlete", "Five", AUS) a6 = Athlete("20", "Athlete", "Six", AUS) for athlete in [a1, a2, a3, a4, a5, a6]: all_athletes.add_item(athlete.get_id(), athlete) athletes = all_athletes.get_items() for athlete in athletes: print(athlete) CAN.add_athletes([a1, a2, a3]) AUS.add_athletes([a4, a5, a6]) print("\nDemonstrate finding an athlete in all_athletes:") print(all_athletes.find_item("2")) # Create event objects and add athletes to the events. e1 = Event("Event1", TIMED, [a1, a2, a3, a4, a5]) all_events.add_item(e1.get_name(), e1) a2.add_event(e1) a3.add_event(e1) a4.add_event(e1) a5.add_event(e1) e2 = Event("Event2", SCORED, [a1, a2, a3, a5, a6]) all_events.add_item(e2.get_name(), e2) a2.add_event(e2) a3.add_event(e2) a5.add_event(e2) a6.add_event(e2) a1.add_events([e1, e2]) # Create result objects for each athlete in the events. a1.add_result(e1, Result(10.5)) a2.add_result(e1, Result(9.5)) a3.add_result(e1, Result(11.5)) a4.add_result(e1, Result(8.5)) a5.add_result(e1, Result(12.5)) a1.add_result(e2, Result(100.5)) a2.add_result(e2, Result(99.5)) a3.add_result(e2, Result(98.5)) a5.add_result(e2, Result(90.5)) a6.add_result(e2, Result(89.5))
def get_entry_exit_pairs(user_id, ridList, num=100): events = [] start = base for _ in range(num): room_id = ridList[random.randint(0, len(ridList)-1)] start = gen_datetime(start) if(start >= datetime.now()): break end = gen_datetime(start) events.append(Event(user_id, room_id, 1, start)) events.append(Event(user_id, room_id, 0, end)) start = end return events
def getEventObject(event): return Event(event['user_id'], event['room_id'], event['status'], event['timestamp'])