You are given (1) a region table describing a hierarchy of locations and (2) a list of party attendance time intervals (all timestamps occur within a single calendar day).
town_id
(string/int)
town_name
(string)
city_id
(string/int)
city_name
(string)
state_id
(string/int)
state_name
(string)
Assume each town_id belongs to exactly one city_id.
town_id
start_time
(time within the day, e.g., minutes since 00:00)
end_time
(time within the day,
end_time > start_time
)
Notes:
Define the day as the window [day_start, day_end) (e.g., [00:00, 24:00)).
For each town_id, compute the total number of hours spent at a party during the day, counting the union of that town’s intervals (i.e., overlapping intervals should not be double-counted).
Return results as:
town_id
,
party_hours
(can be fractional)
Using the same party intervals, compute idle (not-at-party) time segments for each town (within [day_start, day_end)), then group the idle segments by city_id.
Output for each city a set/list of time segments representing the idle periods contributed by its towns. (You should specify clearly whether you are returning:
If not specified otherwise, assume you should return all idle segments per town, grouped by city:
city_id
,
town_id
,
idle_start
,
idle_end