def get(self): check_admin(self) template_values={'user_meta':get_meta()} player_scores = memcache.get('horse') if player_scores is None: players=Player.all().run() player_scores=[] for p in players: score=0 games=p.playergame_set for g in games: if g.batted and not g.not_out and g.how_out == 'Bowled': score += 1 if g.batted and g.runs == 0 and not g.not_out: if g.balls_faced <= 1: score += 5 else: score += 3 score += 2*g.sixes score += 3*g.drops + g.diving_drops + 5*g.non_attempts + g.misfields + g.other player_scores.append([p.first_name + ' ' + p.surname,score]) player_scores=sorted(player_scores,key=lambda player: -player[1]) memcache.add('horse',player_scores) template_values['player_scores']=player_scores template=jinja_environment.get_template('templates/horse.html') self.response.out.write(template.render(template_values))
def get(self): user_meta=get_meta() if not user_meta: self.redirect("/") players=Player.all().filter('active =',True).run() template_values={'user_meta':user_meta,'players':players} if check_mobile(): template=jinja_environment.get_template('templates/mobile/players.html') else: template=jinja_environment.get_template('templates/players.html') self.response.out.write(template.render(template_values))
def selected_available(selected_keys,active_only=True): selected=[] available=[] all_players=set(Player.all(keys_only=True).filter('active =',active_only).fetch(1000)) #selected_keys=set(selected_keys) available_keys=all_players.difference(selected_keys) for key in selected_keys: selected.append(db.get(key)) for key in available_keys: available.append(db.get(key)) return (selected,available)
def get(self,game_id): check_admin(self) game=Game.get_by_id(int(game_id)) players=Player.all().filter('active =',True).order('surname').fetch(1000) fielders=PlayerGame.all().filter('game =',game) batting_order=sorted(fielders,key=lambda p: p.batting_position) bowling_order=sorted(fielders,key=lambda p: p.bowling_position) template_values={'user_meta':get_meta(),'game':game,'players':players,'dismissal_types':dismissal_types,'batting_order':batting_order,'bowling_order':bowling_order, 'fielders':fielders} template=jinja_environment.get_template('templates/edit_game.html') self.response.out.write(template.render(template_values))
def post(self): if self.request.get('code')!='RESET': return self.response.out.write("Reset failed. No harm done") check_admin(self) players=Player.all().run() for p in players: p.batting_price=p.initial_batting_price p.bowling_price=p.initial_bowling_price p.fielding_price=p.initial_fielding_price p.put() usermetas=UserMeta.all().run() for u in usermetas: u.total_trades=10 u.round_trades=2 u.total_points=0 u.put() teams=Team.all().run() for t in teams: if t.game.round > 1: t.delete() else: t.batting_score=0 t.bowling_score=0 t.fielding_score=0 t.total_score=0 t.put() playergames=PlayerGame.all().run() for p in playergames: p.delete() games=Game.all().run() for g in games: g.played=False g.result='tie' g.score="0/0" g.opposition_score="0/0" g.batExtras=0 g.bowlExtras=0 g.put() u=Utilities.all().get() u.current_round=1 u.next_game=Game.all().filter('round =',1).get() u.lockout=False u.put() memcache.flush_all() self.response.out.write('System reset. I hope you meant to do that!');
def get(self): template_values={'user_meta':get_meta()} players=Player.all().run() ps=[] for p in players: bat_runs=0 innings=0 not_outs=0 balls_faced=0 highest=0 ducks=0 bat_fours=0 bat_sixes=0 overs=0 maidens=0 wickets=0 bowl_runs=0 wides=0 no_balls=0 catches=0 run_outs=0 misfields=0 drops=0 diving=0 non_attempts=0 other=0 games=p.playergame_set for g in games: bat_runs+=g.runs if g.batted: innings += 1 if g.runs == 0 and not g.not_out: ducks +=1 if g.not_out: not_outs+=1 if g.runs > highest: highest=g.runs bat_fours+=g.fours_hit bat_sixes+=g.sixes_hit balls_faced+=g.balls_faced overs+=g.overs+1/6.0*g.balls maidens+=g.maidens wickets+=g.wickets bowl_runs+=g.runs_conceded wides+=g.wides no_balls+=g.no_balls catches+=g.catches drops+=g.drops drops+=g.diving_drops diving+=g.diving_drops run_outs+=g.run_outs misfields+=g.misfields non_attempts+=g.non_attempts other+=g.other bat_average=0 if innings-not_outs > 0: bat_average=bat_runs*1.0/(innings-not_outs) else: bat_average='-' bowl_strike_rate=0 bowl_average=0 economy=0 if wickets > 0: bowl_average=bowl_runs*1.0/wickets bowl_strike_rate=overs*6.0/wickets if overs > 0: economy=bowl_runs*1.0/overs pl={'first_name':p.first_name,'surname':p.surname, 'bat_runs':bat_runs,'innings':innings,'not_outs':not_outs,'balls_faced':balls_faced, 'bat_average':bat_average,'highest_score':highest,'bat_strike_rate':bat_runs*100.0/balls_faced, 'ducks':ducks,'bat_fours':bat_fours,'bat_sixes':bat_sixes,'overs':str(int(overs))+'.'+str(int(overs-int(overs))), 'bowl_runs':bowl_runs,'wides':wides,'no_balls':no_balls,'bowl_average':bowl_average,'bowl_strike_rate':bowl_strike_rate, 'economy':economy,'catches':catches,'run_outs':run_outs,'misfields':misfields,'drops':drops,'diving':diving,'non_attempts':non_attempts, 'other':other,'wickets':wickets,'maidens':maidens} ps.append(pl) template_values['players']=ps template=jinja_environment.get_template('templates/stats.html') self.response.out.write(template.render(template_values))