def _run(run_team_upd=True, team_upd_in_chall_upd=False): self.db.flush() if run_team_upd: update_playing_teams(self.db.connection()) update_challenge_points(self.db.connection(), team_upd_in_chall_upd) self.db.flush() self.db.expire_all()
def test_dynamic(self): self.challenge.base_points = 1338 self.challenge.dynamic = True self.challenge.base_points = None self.challenge.module = MagicMock() self.challenge.module.update_points.return_value = False update_playing_teams(self.db.connection()) update_challenge_points(self.db.connection()) self.db.flush() self.db.expire(self.challenge) out = self.render() points = out.find("tbody").find("tr").find_all("td")[3] assert points.text.strip() == '-'
def test_scoreboard(self): t1 = self.make_team(active=True) t2 = self.make_team(active=True) c = self.make_challenge(base_points=100, published=True) self.dbsession.add_all([t1, t2, c]) self.dbsession.flush() update_playing_teams(self.dbsession.connection()) update_challenge_points(self.dbsession.connection()) self.dbsession.flush() self.dbsession.expire(c) Submission(challenge=c, team=t1) ret = self.view.scoreboard() assert len(ret) == 2 teams = list(ret["teams"]) assert len(teams) == 2 assert teams[0] == (t1, c.points, 1) assert teams[1] == (t2, 0, 2) challenges = list(ret["challenges"]) assert len(challenges) == 1 assert challenges[0] is c
def test_defaults(self): c = self.make_challenge() self.dbsession.add(c) assert c.id is None assert c._points is None assert c.online is None assert c.manual is None assert c.dynamic is None assert c.has_token is None self.dbsession.flush() update_playing_teams(self.dbsession.connection()) update_challenge_points(self.dbsession.connection()) self.dbsession.flush() self.dbsession.expire(c) assert c.id assert c._points == 200 assert c.online is False assert c.manual is False assert c.dynamic is False assert c.has_token is False
def update_score(connection, update_all=True): """ Update the score of all teams. If ``update_all`` is set, the points for all challenges are updated beforehand as well. This is your one-shot function to create up-to-date points for everything. """ from fluxscoreboard.models import dynamic_challenges if update_all: update_challenge_points(connection, update_team_count=True) bonus_col = func.sum(Challenge._points - Challenge.base_points) bonus_score = (select([func.coalesce(bonus_col, 0)]). where(Challenge.id == Submission.challenge_id). where(Team.id == Submission.team_id). where(~Challenge.dynamic). where(Challenge.published). correlate(Team)) # base score challenge_sum = func.coalesce(func.sum(Challenge.base_points), 0) # first blood fb_sum = func.coalesce(func.sum(Submission.additional_pts), 0) points_col = challenge_sum + fb_sum for module in dynamic_challenges.registry.values(): points_col += module.get_points_query(Team) base_score = (select([points_col]). where(Challenge.id == Submission.challenge_id). where(Team.id == Submission.team_id). where(~Challenge.dynamic). where(Challenge.published). correlate(Team)) query = (Team.__table__.update(). where(Team.active). values(base_score=base_score, bonus_score=bonus_score)) connection.execute(query)