Skip to content

Commit

Permalink
Resolved same day AM and PM issue
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongT16 committed Jun 13, 2024
1 parent 30aa7ab commit 38e57f6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
48 changes: 42 additions & 6 deletions IndividualCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,42 @@ def get_individual_calendars_using_batch(start_date, end_date, group_members, ac

return list_of_responses

def filter_events(events, events_to_add):
"""
Modifies parameters events and events_to_add if there are overlaps between them.
For example:
OUT AM and OUT PM on same day -> OUT (all day).
OUT AM and OUT (all day) -> OUT (all day)
OUT PM and OUT (all day) -> OUT (all day)
Args:
events (SimpleEvent list): Accumulation of events from various calendars
events_to_add (SimpleEvent list): Represent one single event from the calendar.
A multiday event is broken down into x single day events. Whereas a one day event will be one event.
"""

for new_event in events_to_add:
for event in events:
if new_event.net_id == event.net_id and new_event.date.date() == event.date.date():
new_event_subject_id = utils.subject_identifier(new_event.subject)
event_subject_id = utils.subject_identifier(event.subject)

if new_event_subject_id > event_subject_id:
logger.debug(f"Need to remove {event} and add {new_event} since it is ALL DAY")
events.remove(event)
elif new_event_subject_id < event_subject_id:
logger.debug(f"{event} is already added to filtered list (ALL DAY). Remove {new_event} from events list")
events_to_add.remove(new_event)
elif new_event_subject_id == 1:
logger.debug(f"{new_event} is a duplicate event of {event}. Won't be adding {new_event}")
events_to_add.remove(new_event)
else:
logger.debug(f"Need to remove {event} and NOT add {new_event} and create an all day event instead")
events.remove(event)
events.append(SimpleEvent.create_all_day_event(event.net_id, event.date))
events_to_add.remove(new_event)
return

def process_individual_calendars(calendar, start_date, end_date):
"""
Creates simple event objects using the the individual calendars
Expand All @@ -192,19 +228,19 @@ def process_individual_calendars(calendar, start_date, end_date):
"""

filtered_events = []
events = []
for member in calendar['value']:
net_id = member['scheduleId'].split('@')[0]

try:
for event in member['scheduleItems']:
if event['status'] != EVENT_STATUS: continue

simple_events = SimpleEvent.create_event_for_individual_calendars(event, start_date, end_date, net_id)
filtered_events.extend(simple_events)
events_to_add = SimpleEvent.create_event_for_individual_calendars(event, start_date, end_date, net_id)
filter_events(events, events_to_add)
events.extend(events_to_add)

except KeyError as e:
logger.warning(f"Unable to find: " + net_id)

#filtered_events = []
return filtered_events

return events
6 changes: 6 additions & 0 deletions SimpleEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ def create_event_for_shared_calendar(cls, event, net_ids):
return simple_event



@classmethod
def create_all_day_event(cls, net_id, date):
return cls(net_id, net_id + " OUT", date)


@staticmethod
# get_event_subject assumes that start and end are on the same day, so it's just checking their times to create the subject
def get_event_subject(start, end, net_id):
Expand Down
14 changes: 10 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,15 @@ def connection_error_handler(message, response, access_token):
raise ConnectionError(message)


def subject_identifier(subject):
"""
Give value to OUT AM, OUT PM, and OUT. This creates a hierarchy/priority scheme
that can used for filtering and comparison.
subject (string): the name of the event in format: [netID] OUT [None/AM/PM]
"""

#email_list = get_email_list('org_ici', 20)
#print(email_list)
#print(get_email_list_from_ldap('org_ici'))

if "AM" in subject or "PM" in subject:
return 0
else:
return 1

0 comments on commit 38e57f6

Please sign in to comment.