<commit_before>CATS.Rule.School = Classify({
    init: function (model) {
        this.name = "school";
    },

    compute_history: function (result_table, contest) {
        var tbl = result_table;
        var contest_start_time = contest.start_time;
        $.each(tbl.score_board, function (i, row) {
            $.each(row['problems'], function (k, v) {
                if (v['points'] > 0) {
                    var run = CATS.Model.Run();
                    run['problem'] = v['problem'];
                    run['start_processing_time'] = CATS.App.utils.add_time(contest_start_time, 0);
                    run['user'] = row['user'];
                    run['contest'] = contest.id;

                    if (v['best_run_time'])
                        run['start_processing_time'] = CATS.App.utils.add_time(contest_start_time, v['best_run_time']);

                    run['status'] = (v['points'] == CATS.App.problems[run['problem']].max_points) ? 'accepted' : 'wrong_answer';
                    run['points'] = v['points'];
                    CATS.App.add_object(run);
                    contest.add_object(run);
                }
            });
        });
    },

    compute_table: function (result_table, contest) {
        var teams_problems = {}, teams = {};

        $.each(contest.runs, function (i, row_id) {
            var row = CATS.App.runs[row_id];
            if (
                result_table.filters.duration.type == 'history' &&
                result_table.filters.duration.minutes != null &&
                CATS.App.utils.get_time_diff(CATS.App.contests[row.contest].start_time, row['start_processing_time']) > result_table.filters.duration.minutes
            )
                return;

            var team_id = row['user'];
            if (teams_problems[team_id] == undefined) {
                teams_problems[team_id] = [];
                teams[team_id] = {};
                teams[team_id]['penalty'] = 0;
                teams[team_id]['solved_cnt'] = 0;

                teams_problems[team_id] = result_table.get_empty_problems_field();
            }

            var p_idx = contest.get_problem_index(row['problem']);

            teams_problems[team_id][p_idx]['runs_cnt']++;
            teams_problems[team_id][p_idx]['last_run_time'] = CATS.App.utils.get_time_diff(CATS.App.contests[row.contest].start_time, row['start_processing_time']);
            if (teams_problems[team_id][p_idx]['points'] < row['points']) {
                teams_problems[team_id][p_idx]['best_run_time'] = teams_problems[team_id][p_idx]['last_run_time'];
                teams_problems[team_id][p_idx]['points'] = row['points'];
            }

            if (!teams_problems[team_id][p_idx]['is_solved'] && row['status'] == 'accepted') {
                teams_problems[team_id][p_idx]['is_solved'] = true;
                teams[team_id]['solved_cnt']++;
            }

        });

        var users_no_runs = {};
        $.each(contest.users, function (k, v) {
            users_no_runs[v] = true;
        });

        var teams_arr = [];
        $.each(teams, function (k, v) {
            var points_cnt = 0;
            for (var i = 0; i < contest.problems.length; ++i)
                points_cnt += teams_problems[k][i]['runs_cnt'] > 0 ? teams_problems[k][i]['points'] : 0;

            teams_arr.push({id: k, solved_cnt : v['solved_cnt'], points_cnt: points_cnt});
            users_no_runs[k] = false;
        });

        var group = teams_arr.sort(function (a, b) {
            return b['points_cnt'] - a['points_cnt'];
        });
        result_table.add_group(group, teams_problems, 'school');
        result_table.add_no_run_users(users_no_runs, 'school');
        result_table.apply_filters();
    },

    process: function (contest, result_table) {
        if (contest.runs.length == 0 && result_table.score_board.length > 0)
            this.compute_history(result_table, contest);
        else if (contest.runs.length > 0 && result_table.score_board.length == 0)
            this.compute_table(result_table, contest);
    }
});<commit_msg>rules/school: Fix style and simplify code<commit_after>CATS.Rule.School = Classify({

    init: function (model) {
        this.name = 'school';
    },

    compute_history: function (result_table, contest) {
        var contest_start_time = contest.start_time;
        _.each(result_table.score_board, function (row) {
            _.each(row.problems, function (p) {
                if (!p.points)
                    return;
                var run = CATS.Model.Run();
                run.problem = p.problem;
                run.user = row.user;
                run.contest = contest.id;
                run.start_processing_time = CATS.App.utils.add_time(contest.start_time, p.best_run_time ? p.best_run_time : 0);
                run.status = p.points === CATS.App.problems[run.problem].max_points ? 'accepted' : 'wrong_answer';
                run.points = p.points;
                CATS.App.add_object(run);
                contest.add_object(run);
            });
        });
    },

    compute_table: function (result_table, contest) {
        var teams_problems = {}, teams = {};

        _.each(contest.runs, function (run_id) {
            var run = CATS.App.runs[run_id];
            if (
                result_table.filters.duration.type === 'history' &&
                result_table.filters.duration.minutes != null &&
                run.minutes_since_start() > result_table.filters.duration.minutes
            )
                return;

            var team_id = run.user;
            if (teams_problems[team_id] === undefined) {
                teams[team_id] = { penalty: 0, solved_cnt: 0 };
                teams_problems[team_id] = result_table.get_empty_problems_field();
            }

            var tp = teams_problems[team_id][contest.get_problem_index(run.problem)];
            tp.runs_cnt++;
            tp.last_run_time = Math.floor(run.minutes_since_start());
            if (tp.points < run.points) {
                tp.best_run_time = tp.last_run_time;
                tp.points = run.points;
            }

            if (!tp.is_solved && run.status === 'accepted') {
                tp.is_solved = true;
                teams[team_id].solved_cnt++;
            }

        });

        var users_no_runs = _.reduce(contest.users, function (r, u) { r[u] = true; return r; }, {});

        var teams_arr = _.map(teams, function (v, team_id) {
            var points_cnt = 0;
            for (var i = 0; i < contest.problems.length; ++i)
                points_cnt += teams_problems[team_id][i].points;
            users_no_runs[team_id] = false;
            return { id: team_id, solved_cnt : v.solved_cnt, points_cnt: points_cnt };
        });

        teams_arr.sort(function (a, b) { return b.points_cnt - a.points_cnt; });
        result_table.add_group(teams_arr, teams_problems, 'school');
        result_table.add_no_run_users(users_no_runs, 'school');
        result_table.apply_filters();
    },

    process: function (contest, result_table) {
        if (contest.runs.length == 0 && result_table.score_board.length > 0)
            this.compute_history(result_table, contest);
        else if (contest.runs.length > 0 && result_table.score_board.length == 0)
            this.compute_table(result_table, contest);
    }
});
{'fraction_non_alphanumeric': 0.1376308989528084, 'fraction_numerical': 0.0028559771521827824, 'mean_word_length': 1.9979616795760293, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4510310', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2256, 'n_words': 355}