Merge lp:~mhall119/summit/auto-slots into lp:summit

Proposed by Michael Hall
Status: Merged
Merged at revision: 79
Proposed branch: lp:~mhall119/summit/auto-slots
Merge into: lp:summit
Diff against target: 133 lines (+117/-1)
2 files modified
summit/schedule/management/commands/initslots.py (+117/-0)
summit/schedule/views.py (+0/-1)
To merge this branch: bzr merge lp:~mhall119/summit/auto-slots
Reviewer Review Type Date Requested Status
Dave Walker (community) Approve
Chris Johnston Needs Information
Review via email: mp+56027@code.launchpad.net

Description of the change

Defaults to assume a local 9am-6pm, 55 minute slots with 5 minute breaks, lunch at 1pm, plenary at 2pm.

To post a comment you must log in.
Revision history for this message
Chris Johnston (cjohnston) wrote :

I believe there is normally a 15 minute break at 1045 and another one at 1600.. May need to figure out how to accommodate those.

review: Needs Information
Revision history for this message
Michael Hall (mhall119) wrote :

It wouldn't be much work to change a couple of end times around either, once all the slots themselves are defined. This is an 80% solution to a time-consuming problem.

Revision history for this message
Chris Johnston (cjohnston) wrote :

It is confirmed that the two 15 minute breaks should always exist. Is it possible to code them in so that the work is already done?

review: Needs Information
lp:~mhall119/summit/auto-slots updated
74. By Michael Hall

Add morning and afternoon breaks to the initial slots

Revision history for this message
Dave Walker (davewalker) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'summit/schedule/management/commands/initslots.py'
--- summit/schedule/management/commands/initslots.py 1970-01-01 00:00:00 +0000
+++ summit/schedule/management/commands/initslots.py 2011-04-06 13:26:39 +0000
@@ -0,0 +1,117 @@
1# Ubuntu Developer Summit web application
2# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as
6# published by the Free Software Foundation, either version 3 of the
7# License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import datetime
18import pytz
19
20from django.core.management.base import BaseCommand, CommandError
21from optparse import make_option
22
23from summit.schedule.models import Summit, Slot
24
25__all__ = (
26 'Command',
27)
28
29
30class Command(BaseCommand):
31 help="Create slots for a summit"
32 option_list = BaseCommand.option_list + (
33 make_option("-s", "--summit", dest="summit", help="Supply a summit, will default to the current focus one.", default=Summit.objects.next()),
34 make_option("-b", "--begin", dest="begin", help="Beginning slot time.", default='09:00'),
35 make_option("-e", "--end", dest="end", help="End slot time.", default='17:00'),
36 make_option("-l", "--lunch", dest="lunch", help="Lunch Time.", default='13:00'),
37 make_option("-p", "--plenary", dest="plenary", help="Plenary Time.", default='14:00'),
38 make_option("-d", "--duration", dest="duration", help="Minutes per slot", type=int, default=60),
39 make_option("-i", "--interval", dest="interval", help="Minutes between sessions", type=int, default=5),
40 )
41
42
43 def handle(self, *args, **options):
44 summit = options["summit"]
45 begin = datetime.datetime.strptime(options["begin"], '%H:%M').time()
46 end = datetime.datetime.strptime(options["end"], '%H:%M').time()
47 lunch = datetime.datetime.strptime(options["lunch"], '%H:%M').time()
48 plenary = datetime.datetime.strptime(options["plenary"], '%H:%M').time()
49 duration = datetime.timedelta(minutes=options["duration"])
50 interval = datetime.timedelta(minutes=options["interval"])
51 breaktime = datetime.timedelta(minutes=15)
52 try:
53 summit = Summit.objects.get(name=summit.__str__)
54 except Summit.DoesNotExist:
55 raise CommandError("Summit doesn't exist: %s" % summit)
56
57 day = datetime.timedelta(days=1)
58 hour = datetime.timedelta(hours=1)
59 date = summit.date_start
60 while date <= summit.date_end:
61 slottime = pytz.timezone(summit.timezone).localize(datetime.datetime.combine(date, begin))
62 slot_count = 0
63 while (slottime-interval).time() <= end:
64 slot_count += 1
65 start_time = summit.delocalize(slottime)
66
67 # Determines the type of the session
68 if slottime.time() == lunch:
69 slot_type = 'lunch'
70 elif slottime.time() == plenary:
71 slot_type = 'plenary'
72 else:
73 slot_type = 'open'
74 slot_length = duration
75
76 # Morning Break
77 if slot_count == 2:
78 slot, created = Slot.objects.get_or_create(
79 summit=summit,
80 start_utc=start_time+slot_length-breaktime,
81 end_utc=start_time+slot_length,
82 type='break',
83 )
84 slot_length = slot_length - breaktime
85 # Afternoon Break
86 elif slot_count == 8:
87 slot, created = Slot.objects.get_or_create(
88 summit=summit,
89 start_utc=start_time,
90 end_utc=start_time++breaktime,
91 type='break',
92 )
93 start_time = start_time + breaktime
94 slot_length = slot_length - breaktime
95 slottime = slottime + interval
96 # Non-break intervals
97 elif slot_type == 'open':
98 nexthour = slottime + hour
99 if nexthour.time() != lunch \
100 and nexthour.time() != plenary \
101 and slot_count != 7:
102 slot_length = slot_length - interval
103
104 end_time = start_time + slot_length
105
106 # Add the slot
107 slot, created = Slot.objects.get_or_create(
108 summit=summit,
109 start_utc=start_time,
110 end_utc=end_time,
111 type=slot_type
112 )
113
114 slottime = slottime + duration
115
116 date = date + day
117
0118
=== modified file 'summit/schedule/views.py'
--- summit/schedule/views.py 2011-04-01 14:52:03 +0000
+++ summit/schedule/views.py 2011-04-06 13:26:39 +0000
@@ -112,7 +112,6 @@
112 'autoreload': 'reload' in request.GET,112 'autoreload': 'reload' in request.GET,
113 }113 }
114 converted_date = summit.delocalize(datetime.datetime.strptime(date, "%Y-%m-%d"))114 converted_date = summit.delocalize(datetime.datetime.strptime(date, "%Y-%m-%d"))
115 print "Converted_date: %s" % converted_date
116 if Slot.objects.filter(summit=summit, start_utc__gte=converted_date, end_utc__lte=converted_date+datetime.timedelta(days=1)).count() > 0:115 if Slot.objects.filter(summit=summit, start_utc__gte=converted_date, end_utc__lte=converted_date+datetime.timedelta(days=1)).count() > 0:
117 schedule.calculate()116 schedule.calculate()
118 else:117 else:

Subscribers

People subscribed via source and target branches