Private
Public Access
1
0

race submission code in place, failing, littered with debug statements

This commit is contained in:
Sander Roosendaal
2019-01-24 18:26:43 +01:00
parent 73fe1ddf8f
commit 27b26922ba
7 changed files with 207 additions and 6 deletions

View File

@@ -23,7 +23,8 @@ from rowers.mailprocessing import make_new_workout_from_email, send_confirm
import rowers.polarstuff as polarstuff import rowers.polarstuff as polarstuff
import rowers.c2stuff as c2stuff import rowers.c2stuff as c2stuff
import rowers.stravastuff as stravastuff import rowers.stravastuff as stravastuff
from rowers.models import User from rowers.models import User,VirtualRace,Workout
from rowers.plannedsessions import email_submit_race
workoutmailbox = Mailbox.objects.get(name='workouts') workoutmailbox = Mailbox.objects.get(name='workouts')
failedmailbox = Mailbox.objects.get(name='Failed') failedmailbox = Mailbox.objects.get(name='Failed')
@@ -82,6 +83,20 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
make_new_workout_from_email(therower, filename, title,testing=testing) make_new_workout_from_email(therower, filename, title,testing=testing)
] ]
if testing and workoutid[0]:
w = Workout.objects.get(id = workoutid[0])
w.startdatetime = timezone.now()
w.date = timezone.now().date()
w.save()
if 'raceid' in uploadoptions and workoutid[0]:
try:
race = VirtualRace.objects.get(id=uploadoptions['raceid'])
if race.manager == rower.user:
result = email_submit_race(therower,race,workoutid[0])
except VirtualRace.DoesNotExist:
pass
if testing: if testing:
print 'Workout id = {workoutid}'.format(workoutid=workoutid) print 'Workout id = {workoutid}'.format(workoutid=workoutid)

View File

@@ -36,6 +36,7 @@ import courses
import iso8601 import iso8601
from iso8601 import ParseError from iso8601 import ParseError
from rowers.tasks import handle_check_race_course from rowers.tasks import handle_check_race_course
from rowers.utils import totaltime_sec_to_string
def get_indoorraces(workout): def get_indoorraces(workout):
races1 = VirtualRace.objects.filter( races1 = VirtualRace.objects.filter(
@@ -777,7 +778,6 @@ def race_can_submit(r,race):
else: else:
return False return False
print 'pop'
return False return False
def race_can_resubmit(r,race): def race_can_resubmit(r,race):
@@ -877,6 +877,134 @@ def race_can_withdraw(r,race):
return True return True
def email_submit_race(r,race,workoutid):
try:
w = Workout.objects.get(id=workoutid)
except Workout.DoesNotExist:
return 0
if race.sessionmode == 'time':
wduration = timefield_to_seconds_duration(w.duration)
delta = wduration - (60.*race.sessionvalue)
if delta > -2 and delta < 2:
w.duration = totaltime_sec_to_string(60.*race.sessionvalue)
w.save()
elif race.sessionmode == 'distance':
delta = w.distance - race.sessionvalue
if delta > -5 and delta < 5:
w.distance = race.sessionvalue
w.save()
if race_can_register(r,race):
teamname = ''
weightcategory = w.weightcategory
sex = r.sex
if sex == 'not specified':
sex = 'male'
if not r.birthdate:
return 0
age = calculate_age(r.birthdate)
adaptiveclass = r.adaptiveclass
boatclass = w.workouttype
record = IndoorVirtualRaceResult(
userid = r.id,
teamname=teamname,
race=race,
username = u'{f} {l}'.format(
f = r.user.first_name,
l = r.user.last_name
),
weightcategory=weightcategory,
adaptiveclass=adaptiveclass,
duration=dt.time(0,0),
boatclass=boatclass,
coursecompleted=False,
sex=sex,
age=age
)
record.save()
result = add_rower_race(r,race)
otherrecords = IndoorVirtualRaceResult.objects.filter(
race = race).exclude(userid = r.id)
for otherrecord in otherrecords:
otheruser = Rower.objects.get(id=otherrecord.userid)
othername = otheruser.user.first_name+' '+otheruser.user.last_name
registeredname = r.user.first_name+' '+r.user.last_name
if otherrecord.emailnotifications:
job = myqueue(
queue,
handle_sendemail_raceregistration,
otheruser.user.email, othername,
registeredname,
race.name,
race.id
)
if race_can_submit(r,race):
records = IndoorVirtualRaceResult.objects.filter(
userid = r.id,
race=race
)
if not records:
print 'jet'
return 0
record = records[0]
workouts = Workout.objects.filter(id=w.id)
print workouts
print record.id
print 'aap'
result,comments,errors,jobid = add_workout_indoorrace(
workouts,race,r,recordid=record.id
)
print result,'noot'
if result:
otherrecords = resultobj.objects.filter(
race = race).exclude(userid = r.id)
for otherrecord in otherrecords:
otheruser = Rower.objects.get(id=otherrecord.userid)
othername = otheruser.user.first_name+' '+otheruser.user.last_name
registeredname = r.user.first_name+' '+r.user.last_name
if otherrecord.emailnotifications:
job = myqueue(
queue,
handle_sendemail_racesubmission,
otheruser.user.email, othername,
registeredname,
race.name,
race.id
)
return 1
else:
for error in errors:
print error
print 'fail'
else:
return 0
def race_can_register(r,race): def race_can_register(r,race):
if race.sessiontype == 'race': if race.sessiontype == 'race':
recordobj = VirtualRaceResult recordobj = VirtualRaceResult

View File

@@ -128,6 +128,22 @@ class UserFactory(factory.DjangoModelFactory):
first_name = faker.name().split(' ')[0] first_name = faker.name().split(' ')[0]
last_name = faker.name().split(' ')[0] last_name = faker.name().split(' ')[0]
class RaceFactory(factory.DjangoModelFactory):
class Meta:
model = VirtualRace
name = factory.LazyAttribute(lambda _: faker.word())
registration_closure = timezone.now()+datetime.timedelta(days=1)
evaluation_closure = timezone.now()+datetime.timedelta(days=2)
startdate = timezone.now().date()
start_time = datetime.time()
enddate = (timezone.now()+datetime.timedelta(days=1)).date()
end_time = datetime.time()
preferreddate = timezone.now().date()
sessiontype = 'indoorrace'
sessionvalue = 1
sessionmode = 'time'
class WorkoutFactory(factory.DjangoModelFactory): class WorkoutFactory(factory.DjangoModelFactory):
class Meta: class Meta:
model = Workout model = Workout

View File

@@ -87,6 +87,7 @@ class EmailTests(TestCase):
failbox = Mailbox.objects.create(name='Failed') failbox = Mailbox.objects.create(name='Failed')
failbox.save() failbox.save()
for filename in os.listdir(u'rowers/tests/testdata/emails'): for filename in os.listdir(u'rowers/tests/testdata/emails'):
m = Message(mailbox=workoutsbox, m = Message(mailbox=workoutsbox,
from_header = u.email, from_header = u.email,
@@ -152,7 +153,8 @@ class EmailAdminUpload(TestCase):
'sander@ds.ds', 'sander@ds.ds',
'koeinsloot') 'koeinsloot')
r = Rower.objects.create(user=u,gdproptin=True, r = Rower.objects.create(user=u,gdproptin=True,
gdproptindate=timezone.now() gdproptindate=timezone.now(),
birthdate = faker.profile()['birthdate']
) )
self.theadmin = UserFactory(is_staff=True) self.theadmin = UserFactory(is_staff=True)
@@ -162,6 +164,8 @@ class EmailAdminUpload(TestCase):
gdproptindate=timezone.now(), gdproptindate=timezone.now(),
rowerplan='coach') rowerplan='coach')
self.race = RaceFactory(manager = self.theadmin)
nu = datetime.datetime.now() nu = datetime.datetime.now()
workoutsbox = Mailbox.objects.create(name='workouts') workoutsbox = Mailbox.objects.create(name='workouts')
workoutsbox.save() workoutsbox.save()
@@ -210,4 +214,11 @@ race 1
w = ws[0] w = ws[0]
self.assertEqual(w.user.user.username,u'john') self.assertEqual(w.user.user.username,u'john')
results = IndoorVirtualRaceResult.objects.filter(
race=self.race)
self.assertEqual(len(results),1)
result = results[0]
self.assertTrue(result.coursecompleted)

Binary file not shown.

View File

@@ -2502,7 +2502,7 @@
</Trackpoint> </Trackpoint>
</Track> </Track>
</Lap> </Lap>
<Notes>&lt;Element 'Notes' at 0x14a96cf8&gt;</Notes> <Notes>&lt;Element 'Notes' at 0x13de37f0&gt;</Notes>
</Activity> </Activity>
</Activities> </Activities>
<Creator> <Creator>

View File

@@ -91,6 +91,17 @@ def matchuser(line):
return None return None
def matchrace(line):
testert = '^(race)'
tester = re.compile(testert)
if tester.match(line.lower()):
words = line.split()
try:
return int(words[1])
except:
return None
return None
def matchsync(line): def matchsync(line):
results = [] results = []
@@ -194,6 +205,14 @@ def getuseroptions_body2(uploadoptions,body):
return uploadoptions return uploadoptions
def getraceoptions_body2(uploadoptions,body):
for line in body.splitlines():
raceid = matchrace(line)
if raceid:
uploadoptions['raceid'] = raceid
return uploadoptions
def getsyncoptions_body2(uploadoptions,body): def getsyncoptions_body2(uploadoptions,body):
result = [] result = []
for line in body.splitlines(): for line in body.splitlines():
@@ -284,6 +303,15 @@ def getuser(uploadoptions,value,key):
return uploadoptions return uploadoptions
def getrace(uploadoptions,value,key):
try:
raceid = int(value)
uploadoptions['raceid'] = raceid
except:
pass
return uploadoptions
def getsource(uploadoptions,value,key): def getsource(uploadoptions,value,key):
workoutsource = 'unknown' workoutsource = 'unknown'
for type,verb in workoutsources: for type,verb in workoutsources:
@@ -330,7 +358,9 @@ def upload_options(body):
if 'source' in lowkey: if 'source' in lowkey:
uploadoptions = getsource(uploadoptions,value,'workoutsource') uploadoptions = getsource(uploadoptions,value,'workoutsource')
if 'username' in lowkey: if 'username' in lowkey:
uploadoptions = getuser(uploadoptions,value,'workoutuser') uploadoptions = getuser(uploadoptions,value,'username')
if 'raceid' in lowkey:
uploadoptions = getraceid(uploadoptions,value,'raceid')
except AttributeError: except AttributeError:
#pass #pass
raise yaml.YAMLError raise yaml.YAMLError
@@ -343,6 +373,7 @@ def upload_options(body):
uploadoptions = getstravaid(uploadoptions,body) uploadoptions = getstravaid(uploadoptions,body)
uploadoptions = getworkoutsources(uploadoptions,body) uploadoptions = getworkoutsources(uploadoptions,body)
uploadoptions = getuseroptions_body2(uploadoptions,body) uploadoptions = getuseroptions_body2(uploadoptions,body)
uploadoptions = getraceoptions_body2(uploadoptions,body)
except IOError: except IOError:
pm = exc.problem_mark pm = exc.problem_mark
strpm = str(pm) strpm = str(pm)