Ignore:
Timestamp:
10/07/15 15:08:00 (9 years ago)
Author:
nanardon
Message:

Improve statistic view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Json/Stat.pm

    r1400 r1412  
    3636    } 
    3737 
    38     $c->stash->{data} = \@results; 
     38    $c->stash->{data} = [ sort { $b->[1] <=> $a->[1] } @results ]; 
    3939} 
    4040 
     
    5353    } 
    5454 
     55    $c->stash->{data} = [ sort { $b->[1] <=> $a->[1] } @results ]; 
     56} 
     57 
     58sub manager :Local :Args(0) { 
     59    my ( $self, $c ) = @_; 
     60 
     61    my $base = $c->model('Accounts')->db; 
     62 
     63    my @results = (); 
     64 
     65    my %active = map { $_ => 1 } $base->search_objects('user', 'active=1', 'givenName=*'); 
     66 
     67    my %managed = $base->attributes_summary_by_object('user', 'managerContact'); 
     68 
     69    my %managers = (); 
     70 
     71    my $total = 0; 
     72 
     73    foreach my $user (sort keys %managed) { 
     74        $active{$user} or next; 
     75        foreach (@{ $managed{ $user } }) { 
     76            $active{$_} or next; 
     77            $managers{$_} ||= 0; 
     78            $managers{$_} ++; 
     79            $total++; 
     80        } 
     81    } 
     82 
     83    my $minreport = $c->req->param('min'); 
     84    my $others = 0; 
     85 
     86    foreach my $user (sort { $managers{$b} <=> $managers{$a} } keys %managers) { 
     87        if ($minreport && $managers{$user} / $total * 100 < $minreport) { 
     88            $others++; 
     89            next; 
     90        } 
     91        push(@results, [ $user, $managers{$user} ]); 
     92    } 
     93 
     94    push(@results, [ 'Others', $others ]) if ($others);  
     95 
    5596    $c->stash->{data} = \@results; 
    5697} 
     98 
    5799 
    58100 
Note: See TracChangeset for help on using the changeset viewer.