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

Proposed by Michael Hall on 2011-04-02
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 on 2011-04-13
Chris Johnston 2011-04-02 Needs Information on 2011-04-04
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.
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
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.

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 on 2011-04-06
74. By Michael Hall on 2011-04-06

Add morning and afternoon breaks to the initial slots

Dave Walker (davewalker) wrote :

lgtm

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches