Comparing people flow

# Task: Given the average number of people which moved for a given duration through three different places, along with their daily capacities, determine which place has the highest load profile from people flow in that day. from collections import OrderedDict loads_dict = OrderedDict() total_hours = 24 place_people_hours_daily_capacity = { 'stadium': [[(0, 4), (30, 1), (75, 2), (100, 2), (330, 3), (1350, 1), (1980, 1), (7860, 2), (18300, 1), (64200, 2), (55000, 1), (35000, 1), (17600, 1), (920, 1), (130, 1)], total_hours*60000], 'mall': [[(0, 7), (80, 1), (360, 1), (2200, 1), (3800, 2), (4400, 2), (6500, 2), (5900, 1), (7800, 1), (7200, 1), (3600, 1), (1800, 1), (930, 1), (210, 1), (40, 1)], total_hours*25000], 'metro station': [[(0, 4), (40, 1), (80, 1), (120, 1), (5600, 1), (7100, 1), (6800, 1), (5500, 1), (4100, 2), ( 3300, 3), (2800, 2), (5800, 1), (6300, 1), (2100, 1), (1300, 1), (610, 1), (90, 1)], total_hours*8000] } loads = {key: 0 for key in place_people_hours_daily_capacity.keys()} for place, people_hours_daily_capacity in place_people_hours_daily_capacity.items(): sum_people, sum_hours = 0, 0 people_hours, daily_capacity = people_hours_daily_capacity for people, hours in people_hours: sum_people += people * hours sum_hours += hours if sum_hours == total_hours: loads[place] = (sum_people / daily_capacity) * 100 # in percent for s in sorted(loads.items(), key=lambda x: x[1], reverse=True): loads_dict[s[0]] = float("%.2f" % (s[1])) print(loads_dict) # OrderedDict([('metro station', 33.93), ('stadium', 19.15), ('mall', 9.92)])

It looks that the metro station had 33.93% equivalent load, followed by the stadium and then the mall.