-sub generate{
- my ($path, $lang) = @_;
- $path =~ s,/st\.html$,,;
- my $template = $templates{$lang};
- my $htc = HTML::Template::Compiled->new(scalarref => \$template);
- IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
- flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
- my $meta = LoadFile "$path/meta.yml";
- my @problems = sort grep { /^\w+$/ } map { s,.*/,,r } <$path/../pb/*>;
- my %scores;
- for (1 .. $meta->{last}) {
- my $meta = LoadFile "$path/$_/meta.yml";
- if ($meta->{result_text} =~ m/^(\d+)/) {
- $scores{$meta->{user}}{$meta->{problem}} = $1;
- } else {
- $scores{$meta->{user}}{$meta->{problem}} = $meta->{result} ? 0 : 100;
- }
- }
+sub calc_score{
+ my ($user, $problem, $date, $tries) = @_;
+ my $mxscore = LEVEL_VALUES->{problem_level($problem)};
+ my $score = $mxscore;
+ my $timetaken = $date - get_open($problem, $user);
+ $timetaken = 1 if $timetaken < 1;
+ $timetaken = 150 + int rand 150 if $timetaken > 3600;
+ $score = (3600 - $timetaken) / 3600 * $score;
+ $score -= $tries / 10 * $mxscore;
+ $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
+ int $score
+}
+
+sub _generate{
+ my ($self, $htc, $path, $lang) = @_;