Esempio n. 1
0
def get_teams_scoreboard_cached(teams, cache_key):
    """Gets the cached scoreboard of teams.

    Kind of a hack, tells the front end to look for a static page scoreboard rather than sending a 2000+ length
    array that the front end must parse.
    """
    scoreboard = cache.get(cache_key)
    if scoreboard is None:
        scoreboard = dict()
        problems = problem.load_problems()
        problems = [{
            'pid': p['pid'], 
            'displayname': p['displayname']
        }   for p in problems]
        pids = [p['pid'] for p in problems]
        team_scores = [{
            "teamname": t['teamname'], 
            "score": load_team_score(t['tid']),
            "solved": [pids.index(p) 
                for p in problem.get_solved_problems(t['tid'])]
        }   for t in teams]
        team_scores.sort(key=lambda x: (-x['score']['score'], x['score']['time_penalty']))
        scoreboard['problems'] = problems
        scoreboard['teamname'] = [ts['teamname'] for ts in team_scores]
        scoreboard['score'] = [ts['score']['score'] for ts in team_scores]
        scoreboard['solved'] = [ts['solved'] for ts in team_scores]
        cache.set(cache_key, json.dumps(scoreboard), 60 * 60)
    else:
        scoreboard = json.loads(scoreboard)
    return scoreboard
Esempio n. 2
0
def load_team_score(tid):
    """Get the score for a team.

    Looks for a cached team score, if not found we query all correct submissions by the team and add up their
    basescores if they exist. Cache the result.
    """
    score = cache.get('teamscore_' + tid)
    if score is None:
        problems = problem.load_problems()
        pscore = {p['pid']: p['basescore'] for p in problems}
        solved = problem.get_solved_problems(tid)
        score = dict()
        score['score'] = sum(pscore[pid] for pid in solved)
        # TODO: calculate time penalty
        submission = list(db.submissions.find(
            {
                "tid": tid, 
                "correct": True,
                "pid": {"$ne": "wait_re"},
                "timestamp": {"$gt": ctf_start},
                "timestamp": {"$lt": ctf_end}
            }, {
                "_id": 0, 
                "pid": 1, 
                "timestamp": 1
            }))
        time_penalty = max([0] + [s['timestamp'] for s in submission])
        score['time_penalty'] = time_penalty
        cache.set('teamscore_' + tid, json.dumps(score), 60 * 60)
    else:
        score = json.loads(score)
    return score
Esempio n. 3
0
def get_probs(test_problems, test_name="spm"):

    if "spm" == test_name:
        probs = problem.load_problems()
    elif "ace" == test_name:
        probs = problem.load_ace_problems()
    else:
        raise Exception("Ryan!")

    if test_problems is None:
        return probs
    else:
        return [prob for prob in probs if prob.name in test_problems]
import problem
import analogy
import transform

problems = problem.load_problems()

analogy_groups = {
    "2x2_unary_analogies": analogy.unary_analogies_2by2,
    "2x2_binary_analogies": {},
    "3x3_unary_analogies": analogy.unary_analogies_3by3,
    "3x3_binary_analogies": analogy.binary_analogies_3by3
}

transformation_groups = {
    "2x2_unary_transformations": transform.unary_transformations,
    "2x2_binary_transformations": [],
    "3x3_unary_transformations": transform.unary_transformations,
    "3x3_binary_transformations": transform.binary_transformations
}


def get_probs(test_problems):
    if test_problems is None:
        return problems
    else:
        return [prob for prob in problems if prob.name in test_problems]


def get_anlgs(prob):
    if 2 == prob.matrix_n:
        return analogy_groups.get("2x2_unary_analogies")