race submission code in place, failing, littered with debug statements
This commit is contained in:
@@ -23,7 +23,8 @@ from rowers.mailprocessing import make_new_workout_from_email, send_confirm
|
||||
import rowers.polarstuff as polarstuff
|
||||
import rowers.c2stuff as c2stuff
|
||||
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')
|
||||
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)
|
||||
]
|
||||
|
||||
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:
|
||||
print 'Workout id = {workoutid}'.format(workoutid=workoutid)
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import courses
|
||||
import iso8601
|
||||
from iso8601 import ParseError
|
||||
from rowers.tasks import handle_check_race_course
|
||||
from rowers.utils import totaltime_sec_to_string
|
||||
|
||||
def get_indoorraces(workout):
|
||||
races1 = VirtualRace.objects.filter(
|
||||
@@ -777,7 +778,6 @@ def race_can_submit(r,race):
|
||||
else:
|
||||
return False
|
||||
|
||||
print 'pop'
|
||||
return False
|
||||
|
||||
def race_can_resubmit(r,race):
|
||||
@@ -877,6 +877,134 @@ def race_can_withdraw(r,race):
|
||||
|
||||
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):
|
||||
if race.sessiontype == 'race':
|
||||
recordobj = VirtualRaceResult
|
||||
|
||||
@@ -127,6 +127,22 @@ class UserFactory(factory.DjangoModelFactory):
|
||||
|
||||
first_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 Meta:
|
||||
|
||||
@@ -86,6 +86,7 @@ class EmailTests(TestCase):
|
||||
workoutsbox.save()
|
||||
failbox = Mailbox.objects.create(name='Failed')
|
||||
failbox.save()
|
||||
|
||||
|
||||
for filename in os.listdir(u'rowers/tests/testdata/emails'):
|
||||
m = Message(mailbox=workoutsbox,
|
||||
@@ -152,7 +153,8 @@ class EmailAdminUpload(TestCase):
|
||||
'sander@ds.ds',
|
||||
'koeinsloot')
|
||||
r = Rower.objects.create(user=u,gdproptin=True,
|
||||
gdproptindate=timezone.now()
|
||||
gdproptindate=timezone.now(),
|
||||
birthdate = faker.profile()['birthdate']
|
||||
)
|
||||
|
||||
self.theadmin = UserFactory(is_staff=True)
|
||||
@@ -162,6 +164,8 @@ class EmailAdminUpload(TestCase):
|
||||
gdproptindate=timezone.now(),
|
||||
rowerplan='coach')
|
||||
|
||||
self.race = RaceFactory(manager = self.theadmin)
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox.save()
|
||||
@@ -210,4 +214,11 @@ race 1
|
||||
w = ws[0]
|
||||
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)
|
||||
|
||||
|
||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
2
rowers/tests/testdata/testdata.tcx
vendored
2
rowers/tests/testdata/testdata.tcx
vendored
@@ -2502,7 +2502,7 @@
|
||||
</Trackpoint>
|
||||
</Track>
|
||||
</Lap>
|
||||
<Notes><Element 'Notes' at 0x14a96cf8></Notes>
|
||||
<Notes><Element 'Notes' at 0x13de37f0></Notes>
|
||||
</Activity>
|
||||
</Activities>
|
||||
<Creator>
|
||||
|
||||
@@ -90,7 +90,18 @@ def matchuser(line):
|
||||
return words[1]
|
||||
|
||||
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):
|
||||
results = []
|
||||
@@ -194,6 +205,14 @@ def getuseroptions_body2(uploadoptions,body):
|
||||
|
||||
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):
|
||||
result = []
|
||||
for line in body.splitlines():
|
||||
@@ -284,6 +303,15 @@ def getuser(uploadoptions,value,key):
|
||||
|
||||
return uploadoptions
|
||||
|
||||
def getrace(uploadoptions,value,key):
|
||||
try:
|
||||
raceid = int(value)
|
||||
uploadoptions['raceid'] = raceid
|
||||
except:
|
||||
pass
|
||||
|
||||
return uploadoptions
|
||||
|
||||
def getsource(uploadoptions,value,key):
|
||||
workoutsource = 'unknown'
|
||||
for type,verb in workoutsources:
|
||||
@@ -330,7 +358,9 @@ def upload_options(body):
|
||||
if 'source' in lowkey:
|
||||
uploadoptions = getsource(uploadoptions,value,'workoutsource')
|
||||
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:
|
||||
#pass
|
||||
raise yaml.YAMLError
|
||||
@@ -343,6 +373,7 @@ def upload_options(body):
|
||||
uploadoptions = getstravaid(uploadoptions,body)
|
||||
uploadoptions = getworkoutsources(uploadoptions,body)
|
||||
uploadoptions = getuseroptions_body2(uploadoptions,body)
|
||||
uploadoptions = getraceoptions_body2(uploadoptions,body)
|
||||
except IOError:
|
||||
pm = exc.problem_mark
|
||||
strpm = str(pm)
|
||||
|
||||
Reference in New Issue
Block a user