]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/St.pm
Merge branch 'master' into mindcoding
[gruntmaster-page.git] / lib / Gruntmaster / Page / St.pm
1 package Gruntmaster::Page::St;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use Gruntmaster::Page::Base st => 'Standings';
7 our @ISA = qw/Gruntmaster::Page::Base/;
8 our $VERSION = '0.001';
9
10 use constant LEVEL_VALUES => {
11 beginner => 100,
12 easy => 250,
13 medium => 600,
14 hard => 1000,
15 };
16
17 sub calc_score{
18 my ($user, $problem, $date, $tries, $totaltime) = @_;
19 my $mxscore = LEVEL_VALUES->{problem_level($problem)};
20 my $score = $mxscore;
21 my $timetaken = $date - get_open($problem, $user);
22 $timetaken = 0 if $timetaken < 0;
23 $timetaken = 300 if $timetaken > $totaltime;
24 $score = ($totaltime - $timetaken) / $totaltime * $score;
25 $score -= $tries / 10 * $mxscore;
26 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
27 int $score
28 }
29
30 sub _generate{
31 my ($self, $htc, $lang, $env, $ct) = @_;
32 debug $env => "language is '$lang' and contest is '$ct'";
33 my ($totaltime, $start);
34
35 local $Gruntmaster::Data::contest;
36 if ($ct) {
37 $start = contest_start ($ct);
38 $totaltime = contest_end ($ct) - $start;
39 $Gruntmaster::Data::contest = $ct;
40 }
41
42 my @problems = problems;
43 @problems = sort @problems;
44 my (%scores, %tries);
45 for (1 .. jobcard) {
46 if ($Gruntmaster::Data::contest) {
47 $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()}++, $totaltime) if job_date() > $start;
48 } elsif (defined job_user && defined job_problem && defined job_result) {
49 if (defined job_result_text && job_result_text =~ m/^(\scores+)/) {
50 $scores{job_user()}{job_problem()} = $ct;
51 } else {
52 $scores{job_user()}{job_problem()} = job_result() ? 0 : 100;
53 }
54 }
55 }
56
57 my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user}} map {
58 my $user = $_;
59 +{
60 user => $user,
61 score => sum (values $scores{$user}),
62 scores => [map { $scores{$user}{$_} // '-'} @problems],
63 problems => $Gruntmaster::Data::contest,
64 }
65 } keys %scores;
66
67 $st[0]->{rank} = 1;
68 $st[$_]->{rank} = $st[$_ - 1]->{rank} + ($st[$_]->{score} < $st[$_ - 1]->{score}) for 1 .. $#st;
69 $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
70 $htc->param(st => \@st);
71 }
72
73 1
This page took 0.049558 seconds and 4 git commands to generate.