-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_participants.py
50 lines (46 loc) · 1.92 KB
/
switch_participants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from django.core.management import setup_environ
import settings
setup_environ(settings)
import datetime
import participant_info
from django.db import transaction
from server.feedme.models import *
import traceback
@transaction.commit_manually
def switch_participants():
try:
emails = participant_info.people
print emails
for email in emails:
sharer = Sharer.objects.get(user__email = email)
sp = StudyParticipant.objects.get(sharer = sharer)
assignments = StudyParticipantAssignment.objects \
.filter(study_participant = sp)
num_assignments = assignments.count()
if num_assignments > 1:
print "%s has %d assignments, not processing more" \
% (email, num_assignments)
continue
print "%s has at most one assignment---switching assignment" % (email)
# end the user's current assignment by setting its end_date
if num_assignments == 1:
print "---changed end time of the current study"
assignment = assignments.get(study_participant = sp)
assignment.end_time = datetime.datetime.now()
assignment.save()
# switch the user's UI configuration
sp.user_interface = not sp.user_interface
sp.save()
print "---group is %s, new ui setting is %s" \
% (sp.study_group, str(sp.user_interface))
# add a new assignment entry starting now
spa = StudyParticipantAssignment(study_participant = sp, user_interface = sp.user_interface, social_features = sp.social_features, start_time = datetime.datetime.now(), end_time = datetime.datetime(2009, 9, 1))
print "---adding assignment: %s" % (unicode(spa))
spa.save()
except Exception, ex:
traceback.print_exc()
transaction.rollback()
else:
transaction.commit()
if __name__ == '__main__':
switch_participants()