Skip to content

Commit

Permalink
Merge pull request #88 from PyconUK/define_conference
Browse files Browse the repository at this point in the history
Fix bugs with datetime objects and strings
  • Loading branch information
drvinceknight committed May 17, 2017
2 parents f6921e5 + 454bc22 commit 668e10b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions docs/howto/define_a_conference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ we'll need each list of :code:`Slots` separately later on::
... event_type: [
... Slot(
... venue=venue,
... starts_at=day + timedelta(0, slot_time['starts_at']),
... starts_at=(
... day + timedelta(0, slot_time['starts_at'])
... ).strftime('%d-%b-%Y %H:%M'),
... duration=slot_time['duration'],
... session=f"{day.date()} {slot_time['session_name']}",
... capacity=venues[venue]['capacity'])
Expand All @@ -299,11 +301,11 @@ we'll need each list of :code:`Slots` separately later on::
... for event_type in event_types}

>>> pprint(slots['talk'][0:5])
[Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 10, 15), duration=30, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 11, 15), duration=45, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 12, 0), duration=30, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 12, 30), duration=30, capacity=500, session='2016-09-16 afternoon'),
Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 14, 30), duration=30, capacity=500, session='2016-09-16 afternoon')]
[Slot(venue='Assembly Room', starts_at='16-Sep-2016 10:15', duration=30, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at='16-Sep-2016 11:15', duration=45, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at='16-Sep-2016 12:00', duration=30, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at='16-Sep-2016 12:30', duration=30, capacity=500, session='2016-09-16 afternoon'),
Slot(venue='Assembly Room', starts_at='16-Sep-2016 14:30', duration=30, capacity=500, session='2016-09-16 afternoon')]

.. _processing_events:

Expand Down Expand Up @@ -338,8 +340,8 @@ talk as the key mapping to a list of all slots on Friday and Sunday morning)::
... slots['talk'].index(slot)
... for period in periods
... for slot in slots['talk']
... if period['unavailable_from'] <= slot.starts_at and
... period['unavailable_until'] >= slot.starts_at + timedelta(0, slot.duration * 60)]
... if period['unavailable_from'] <= datetime.strptime(slot.starts_at, '%d-%b-%Y %H:%M') and
... period['unavailable_until'] >= datetime.strptime(slot.starts_at, '%d-%b-%Y %H:%M') + timedelta(0, slot.duration * 60)]
... for speaker, periods in speaker_unavailability.items()
... for talk in talks if talk['speaker'] == speaker}

Expand All @@ -352,9 +354,9 @@ And then add those entries to our :code:`events` dictionary::
... events['talk'][talk].add_unavailability(*[slots['talk'][s] for s in unavailable_slots])

>>> pprint(events['talk'][55].unavailability[0:3])
(Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 10, 15), duration=30, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 11, 15), duration=45, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at=datetime.datetime(2016, 9, 16, 12, 0), duration=30, capacity=500, session='2016-09-16 morning'))
(Slot(venue='Assembly Room', starts_at='16-Sep-2016 10:15', duration=30, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at='16-Sep-2016 11:15', duration=45, capacity=500, session='2016-09-16 morning'),
Slot(venue='Assembly Room', starts_at='16-Sep-2016 12:00', duration=30, capacity=500, session='2016-09-16 morning'))

To complete our Event objects, we'll need to add the information from our
:code:`speaker_clashes` dictionary to their unavailability. First, let's map
Expand Down

0 comments on commit 668e10b

Please sign in to comment.