]> iEval git - gruntmaster-data.git/blobdiff - lib/Gruntmaster/Data.pm
Sort problem and contest lists in user_entry
[gruntmaster-data.git] / lib / Gruntmaster / Data.pm
index 0b04b7b884ebb98e6a396005673971cd9ed0de1d..9d01418c062f08f94f9a39ef41bcf10fd872142c 100644 (file)
@@ -15,7 +15,7 @@ __PACKAGE__->load_namespaces;
 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-05 13:11:39
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dAEmtAexvUaNXLgYz2rNEg
 
-our $VERSION = '5999.000_011';
+our $VERSION = '5999.000_012';
 
 use Lingua::EN::Inflect qw/PL_N/;
 use JSON::MaybeXS qw/decode_json/;
@@ -42,15 +42,30 @@ BEGIN {
 }
 
 sub user_list {
-       my $rs = $_[0]->users->search(undef, {order_by => 'name', columns => USER_PUBLIC_COLUMNS});
-       [ map { { $_->get_columns } } $rs->all ]
+       my ($self) = @_;
+       my $rs = $self->users->search(undef, {columns => USER_PUBLIC_COLUMNS} );
+       my (%solved, %attempted, %contests);
+
+       for my $row ($self->problem_statuses->all) {
+               $solved   {$row->rawowner}++ if     $row->solved;
+               $attempted{$row->rawowner}++ unless $row->solved;
+       }
+       $contests{$_->rawowner}++ for $self->contest_statuses->all;
+
+       [ sort { $b->{solved} <=> $a->{solved} or $b->{attempted} <=> $a->{attempted} } map { ## no critic (ProhibitReverseSort)
+               my $id = $_->id;
+               +{ $_->get_columns,
+                  solved => ($solved{$id} // 0),
+                  attempted => ($attempted{$id} // 0),
+                  contests => ($contests{$id} // 0) }
+       } $rs->all ]
 }
 
 sub user_entry {
        my ($self, $id) = @_;
        my $user = $self->users->find($id, {columns => USER_PUBLIC_COLUMNS, prefetch => [qw/problem_statuses contest_statuses/]});
-       my @problems = map { {problem => $_->get_column('problem'), solved => $_->solved} } $user->problem_statuses;
-       my @contests = map { {contest => $_->contest->id, contest_name => $_->contest->name, rank => $_->rank, score => $_->score} } $user->contest_statuses->search(undef, {prefetch => 'contest'});
+       my @problems = map { {problem => $_->get_column('problem'), solved => $_->solved} } $user->problem_statuses->search(undef, {order_by => 'problem'});
+       my @contests = map { {contest => $_->contest->id, contest_name => $_->contest->name, rank => $_->rank, score => $_->score} } $user->contest_statuses->search(undef, {prefetch => 'contest', order_by => 'contest.start DESC'});
        +{ $user->get_columns, problems => \@problems, contests => \@contests }
 }
 
This page took 0.023689 seconds and 4 git commands to generate.