def test_basics(self): team = Team() team.id = 1 team.code = 'MAR' team.name = "Martian War Machines" team.name_full = "Martian War Machines" team.name_brief = "Mars" self.session.add(team) team2 = Team() team2.id = 2 team2.code = 'VEN' team2.name = "Venusian Pressure Cookers" team2.name_full = "Venusian Pressure Cookers" team2.name_brief = "Venus" self.session.add(team2) self.session.flush()
def post(self): team = Team.for_user(users.get_current_user()) if not team: team = Team() team.name = self.request.get('name') team.people = self.request.get('people') location = self.request.get('location') team.location = self.request.get('location') if location == 'Other': team.location = self.request.get('otherLocation') team.description = self.request.get('description') team.url = self.request.get('url') team.video = self.request.get('video') team.image = self.request.get('image') team.winner = self.request.get('winner') team.email = self.request.get('email') team.votes = 0 team.hackday = '092011' team.user = users.get_current_user() team.put() self.render('add_received', { })
def team_process(self, f): pattern = r""" <td>(\d+)</td> # rank <td>([A-Za-z. (),_0-9]+)</td> # name .* # rest of the line <td>(\d+)/(\d+)</td> # attempt, problemcount """ reg = re.compile( pattern, re.VERBOSE ) rankpat = r""" [A-Za-z]+\ ([A-Za-z]+\ \d+) # weekday, month, day \ \d\d:\d\d:\d\d\ [A-Za-z]+\ (\d+) # year """ rankreg = re.compile( rankpat, re.VERBOSE ) #finding the date of the event match = rankreg.search( f ) cdate = "" if match: cdate = match.group(1) + " " + match.group(2) logging.error( cdate ) logging.error( "finding something" ) else: logging.error( "nothing found" ) bests = "" results = reg.finditer(f) rank = 0; for result in results: # picking up details rank += 1 name = result.group(2) attempts = int(result.group(3)) solved = int(result.group(4)) earned = 0 # ignore autogenerated names if self.invalidName( name ): continue # pick up the earned points if rank <= 10 and int(solved) != 0: earned = points[ rank-1 ] if rank <= 3: if rank == 2: bests += ", " elif rank == 3: bests += " and " bests += name c = db.Query( Team ) c.filter( 'name =' , name ) teams = c.fetch(1) # updating database if len( teams ) == 0: # it was never in ranklist team = Team() team.name = name team.solve = solved team.points = earned team.contest = 1 team.attempt = attempts team.image = "img/nsu2.gif" if team.attempt: team.accuracy = str( round(( team.solve * 100. ) / team.attempt, 2) ) else: team.accuracy = str( 0.0 ) team.put() else: for team in teams: # it's one object though team.solve += solved team.points += earned team.contest += 1 team.attempt += attempts if team.attempt: team.accuracy = str( round(( team.solve * 100. ) / team.attempt,2) ) team.put() return [ bests, cdate ]
def team_process(self, f): pattern = r""" <td>(\d+)</td> # rank <td>([A-Za-z. (),_]+)</td> # name .* # rest of the line <td>(\d+)/(\d+)</td> # attempt, problemcount """ reg = re.compile( pattern, re.VERBOSE ) rankpat = r""" [A-Za-z]+\ ([A-Za-z]+\ \d+) # weekday, month, day \ \d\d:\d\d:\d\d\ [A-Za-z]+\ (\d+) # year """ rankreg = re.compile( rankpat, re.VERBOSE ) #finding the date of the event match = rankreg.search( f ) cdate = "" if match: cdate = match.group(1) + " " + match.group(2) logging.error( cdate ) logging.error( "finding something" ) else: logging.error( "nothing found" ) bests = "" results = reg.finditer(f) rank = 0; for result in results: # picking up details rank += 1 name = result.group(2) attempts = int(result.group(3)) solved = int(result.group(4)) earned = 0 # pick up the earned points if rank <= 10 and int(solved) != 0: earned = points[ rank-1 ] if rank <= 3: if rank == 2: bests += ", " elif rank == 3: bests += " and " bests += name c = db.Query( Team ) c.filter( 'name =' , name ) teams = c.fetch(1) # updating database if len( teams ) == 0: # it was never in ranklist team = Team() team.name = name team.solve = solved team.points = earned team.contest = 1 team.attempt = attempts team.image = "img/nsu2.gif" team.accuracy = str( round(( team.solve * 100. ) / team.attempt, 2) ) team.put() else: for team in teams: # it's one object though team.solve += solved team.points += earned team.contest += 1 team.attempt += attempts team.accuracy = str( round(( team.solve * 100. ) / team.attempt,2) ) team.put() return [ bests, cdate ]