예제 #1
0
파일: views.py 프로젝트: thurloat/results
def latest_races_web(request):
    race = Race.all().filter("hasResults =", True).order("-raceNumber").fetch(1)
    if len(race)>0:
        results = Results.all().filter("race =",race[0]).order("place")
    else:
        results = None
    return UA_direct(request,template="results/latest.html", extra_context={'results':results,'race':race[0] if len(race)>0 else None})
예제 #2
0
파일: views.py 프로젝트: thurloat/results
def getrace(field):
    existing = Race.all()
    existing.filter("raceNumber =", int(field[0]))
    if existing.count(1) > 0:
        race = existing.get()
        messages.append("Updating race #" + field[0] + ": " + field[3])
    else:
        race = Race(raceNumber = int(field[0]))
        messages.append("Creating NEW race #" + field[0] + ": " + field[3])
    
    race.roundNumber = field[1]
    race.heatNumber = field[2]
    
    if len(field[3]) == 0 or field[3] == "":
        race.description = "Event # " + field[0]
    else:
        race.description = field[3]
        
    if len(field) >= 5:
        race.windSpeed = field[4]
    
    if len(field) >= 6:
        race.weather = field[5]
    
    return race
예제 #3
0
파일: views.py 프로젝트: thurloat/results
def cleardata(request):
    messages = []
    memcache.delete("raceshtml")
    if request.method == 'POST':
        existing = Race.all()
        db.delete(existing)
        messages.append("All races deleted")
        results = Results.all()
        db.delete(results)
        messages.append("All results deleted")
    return render_to_response(request, 'results/delete.html', {'messages':messages});
예제 #4
0
파일: views.py 프로젝트: thurloat/results
def ajax(request):
#    races = Race.all().order('-roundNumber').fetch(1)
#    r = races.pop(0)
#    races = Race.gql("where roundNumber = :1", r.roundNumber) #Race.all().filter("roundNumber = :1", r.roundNumber)
#    raceslist = []
#    for race in races:
#        raceslist.append(race.key())
#    
#    leaders = Results.gql("where race IN :1 order by time", raceslist).fetch(5)
    
    leaders = Results.all().order("time").fetch(5)
    data = UA_object_list(request,Race.all().order("raceNumber"), template_name="list.html", extra_context={'leaders':leaders})
    return data
예제 #5
0
파일: views.py 프로젝트: thurloat/results
def upload(request):
    if request.method == 'POST':
        memcache.delete("raceshtml")
        import re
        import os
        file = request.FILES['lif']
        uploadfile=file.name; 
        evt=".evt"
        lif=".lif"
        reneedle=re.compile(evt, re.IGNORECASE)
        reneedlelif=re.compile(lif)
        
        file_contents = request.FILES['lif'].read().strip()

        #file_contents = self.request.get('lif').strip()
        import csv
        imported = []
        importReader = csv.reader(file_contents.split('\n'))
        for row in importReader:
            imported += [row]
        existing = Race.all()
        existing.filter("raceNumber =", int(imported[0][0]))
            #validate data structure
        if lif in uploadfile:
            race = getrace(imported[0])
            race.hasResults = True
            race.put()
            #remove the race from the list
            imported.pop(0)
            #loop through the rest of the records and insert them as results.
            for r in imported:
                if len(r[0]) > 0:
                    result = getresult(r, race)
                    result.put()
                
        elif evt in uploadfile:
                for r in imported:
                    if len(r[0]) > 0:
                        race = getrace(r)
                        race.put()
                messages.append("Everything seems to have worked!")
        else:
            messages.append("Race Data Structure Not Acceptable.")
        memcache.delete("raceshtml")
    return render_to_response(request, 'results/upload.html', {'messages':messages});
예제 #6
0
파일: views.py 프로젝트: thurloat/results
def lif_upload(request):
    errmsg = []
    if request.method == 'POST':
        errmsg += ['beginning import']
        
        import re
        import os
        
        from bios.models import Country, Athlete, Crew
        file = request.FILES['csv']
        uploadfile=file.name; 
        
        file_contents = request.FILES['csv'].read().strip()
        
        p = re.compile('\r', re.IGNORECASE)
        file_contents = p.sub('\n',file_contents)
        #file_contents = self.request.get('lif').strip()
        import csv
        imported = []
        importReader = csv.reader(file_contents.split('\n'))

        selectedRace = None
        for row in importReader:
            imported += [row]
        
        selectedRace = Race.all().filter("raceNumber =",int(imported[0][0])).fetch(1)[0]
        #print selectedRace
        errmsg += [selectedRace]
        
        imported.pop(0)
        for r in imported:
            if len(r) > 1:
                result = Results.all().filter("race =", selectedRace).filter("laneNumber =",r[2]).fetch(1)
                if len(result) < 1:
                    errmsg += ["Did not work for %s" % (r)]
                else:
                    result[0].place = r[0]
                    result[0].finalTime = r[6]
                    result[0].put()
        selectedRace.hasResults = True
        selectedRace.put()
    return direct_to_template(request, 'results/lif-upload.html', extra_context={"errmsg":errmsg})
예제 #7
0
파일: views.py 프로젝트: thurloat/results
def show_race(request, key):
	return UA_object_list(request,Race.all(),key)
예제 #8
0
파일: views.py 프로젝트: thurloat/results
def show_races_event(request, event):
    event = Event.all().filter("eventString =", event).fetch(1)
    
    return UA_object_list(request,Race.all().filter("event =",event[0]).order("raceNumber"))
예제 #9
0
파일: views.py 프로젝트: thurloat/results
def show_races(request):
    leaders = Results.all().order("time").fetch(5)
    return UA_object_list(request,Race.all().order("raceNumber"), extra_context={'leaders':leaders})
예제 #10
0
파일: views.py 프로젝트: thurloat/results
def show_schedule(request):
    return UA_object_list(request,Race.all().order("raceTime").filter("raceTime !=",None), template_name="schedule.html")
예제 #11
0
파일: views.py 프로젝트: thurloat/results
def race_upload(request):
    errmsg = []
    if request.method == 'POST':
        errmsg += ['beginning import']
        
        import re
        import os
        
        from bios.models import Country, Athlete, Crew
        file = request.FILES['csv']
        uploadfile=file.name; 
        
        file_contents = request.FILES['csv'].read().strip()
        
        p = re.compile('\r', re.IGNORECASE)
        file_contents = p.sub('\n',file_contents)
        #file_contents = self.request.get('lif').strip()
        import csv
        imported = []
        importReader = csv.reader(file_contents.split('\n'))

        for row in importReader:
            imported += [row]
        #validate data structure
        
        ci = 0
        selectedEvent = None
        selectedRace = None
        errmsg += ['in the loop']
        for r in imported:
            try:
                if selectedEvent is not None and selectedEvent.eventString != r[0] or selectedEvent is None:
                    #does this event already exist?
                    evtest = Event.all().filter("eventString =",r[0]).fetch(1)
                    #print evtest
                    if len(evtest) > 0:
                        selectedEvent = evtest[0]
                        #print "re-using event"
                    else:
                        #print "making new event"
                        eventInfo = [x.strip() for x in r[0].split('-')]
                        event = Event()
                        event.eventClass=eventInfo[0]
                        event.gender=eventInfo[1]
                        event.distance=eventInfo[2]
                        event.eventString=r[0]
                        event.put()
                        selectedEvent = event
                    
                if selectedRace is not None and (selectedRace.event != selectedEvent or selectedRace.heatNumber != r[1]) or selectedRace is None:         
                    #print "making new race"
                    #check and re-use old races.
                    ractest = Race.all().filter("event =",selectedEvent).filter("heatNumber =",r[1]).fetch(1)
                    if len(ractest) > 0:
                        selectedRace = ractest[0]
                    else:
                    
                        race = Race()
                        race.event = selectedEvent
                        race.heatNumber = r[1]
                        race.hasResults = False
                        race.put()
                        
                        selectedRace = race
                
                
                #athelte or crew?
                athcrew = None
                if len(r) > 6 and r[6] != '':
                        if len(r) >8 and r[7] != '':
                            """
                                it's a 4 man crew
                            """
                            fourteam = Athlete.all().filter("bibNum IN",[int(r[5]),int(r[6]),int(r[7]),int(r[8])]).fetch(4)
                            
                            crew = Crew()
                            crew.athletes = fourteam
                            crew.put()
                            athcrew = crew
                        else:
                            """
                                it's a crew@@
                            """
                            #crew = Crew()
                            
                            twoteam = Athlete.all().filter("bibNum IN",[int(r[5]),int(r[6])]).fetch(2)
                            crew = Crew()
                            crew.athletes = twoteam
                            crew.put()                      
                            athcrew = crew
                else:
                    selath = Athlete.all().filter("bibNum =", int(r[5])).fetch(1)
                    athcrew = selath[0] if len(selath)>0 else None

                
                result = Results()
                #print athcrew.__class__.__name__

                if athcrew.__class__.__name__ is "Crew":
                    #print "its crew"
                    result.crew = athcrew
                elif athcrew.__class__.__name__ is "Athlete":
                    #print "its athlete"
                    result.athlete = athcrew
                
                
                #result.athlete = selath[0] if len(selath)>0 else None
                result.laneNumber = r[2]
                selc = Country.all().filter("code =", r[3]).fetch(1)
                result.country = selc[0] if len(selc)>0 else None
                result.race = selectedRace
                result.put()
                
                
                ci = ci + 1
                #if ci > 100:
                #    return UA_direct(request, 'results/race-upload.html')
                #print result
                #print r
            except:
                    errmsg += ["Error on Line :%s of CSV, line looks like: %s" % (ci,r)]
                    
            errmsg += ["%s rows imported<br/>" % ci]
    
    return render_to_response(request, 'results/race-upload.html', extra_context={"errmsg":errmsg})
예제 #12
0
파일: views.py 프로젝트: thurloat/results
def populate_races(request):
    errmsg = []
    if request.method == 'POST':
        errmsg += ['beginning import']
        
        import re
        import os
        
        from bios.models import Country, Athlete, Crew
        file_contents = request.FILES['evt'].read().strip()

        #file_contents = self.request.get('lif').strip()
        import csv
        imported = []
        importReader = csv.reader(file_contents.split('\n'))
        for row in importReader:
            imported += [row]
        
        selectedEvent = None
        selectedRace = None    
        for row in imported:
            if len(row) == 4:
                fields = row[3].strip().split(" ")
                evtStr = "%s-%s-%s" % (fields[2],fields[3],fields[4].strip("m"))
                selectedEvent = Event.all().filter("eventString =", evtStr).fetch(1)[0]
                selectedRace = Race.all().filter("raceNumber =", int(row[0])).fetch(1)[0]
                print selectedRace.raceNumber
                print selectedEvent
            else:
                #print row[1]
                """
                is it an athlete or a crew for the result? check class?
                
                if it's an athlete, search bibNumber set Result with lane number and athlete
                
                if it's a crew, search for the bibNum participating in the event and insert
                     that crew into a new result containing the lane number
                """
                
                newResult = Results()
                newResult.race = selectedRace
                
                chkRace = Race.all().filter("event =", selectedEvent).fetch(1)[0]
                
                
                if len(chkRace.results_race) > 0 and chkRace.results_race[0].crew is not None:
                    #find and assign crew
                    chkAthlete = Athlete.all().filter("bibNum =",int(row[1])).fetch(1)
                    #print chkAthlete
                    for crew in chkAthlete[0].crew_athlete:
                        for result in crew.result_crew:
                            if result.race.event == selectedEvent:
                                newResult.crew = crew
                else:
                    newResult.athlete = Athlete.all().filter("bibNum =", int(row[1])).fetch(1)[0]
                
                newResult.laneNumber = row[2]
                selc = Country.all().filter("code =", row[5]).fetch(1)[0]
                newResult.country = selc
                newResult.put()
                errmsg += [newResult]
                
            
    return render_to_response(request, 'results/populate.html', {'errmsg':errmsg})    
예제 #13
0
파일: views.py 프로젝트: thurloat/results
def purge_race(request):
    list = Race.all().fetch(250)
    db.delete(list)
    return UA_direct(request,'race-upload.html')