diff --git a/cgi/CRMS.pm b/cgi/CRMS.pm index 76a2125d..4ff3c960 100755 --- a/cgi/CRMS.pm +++ b/cgi/CRMS.pm @@ -66,7 +66,7 @@ sub new return $self; } -our $VERSION = '8.5.22'; +our $VERSION = '8.5.23'; sub Version { return $VERSION; diff --git a/cgi/Graph.pm b/cgi/Graph.pm index 2a226526..f5fc7210 100644 --- a/cgi/Graph.pm +++ b/cgi/Graph.pm @@ -260,294 +260,6 @@ sub CreateReviewInstitutionGraph return \%data; } -sub CreateReviewerGraph -{ - my $self = shift; - my $type = shift; - my $start = shift; - my $end = shift; - my @users = @_; - - $type = 0 unless defined $type; - return CreateFlaggedGraph($self, @users) if $type == 3; - my %data = ('chart'=>{'type'=>'spline'}, 'title'=>{'text'=>undef}, - 'tooltip'=>{'pointFormat'=>'{series.name}: {point.y}'}, - 'xAxis'=>{'categories'=>[], 'labels'=>{'rotation'=>45}}, - 'yAxis'=>{'min'=>0, 'title'=>{'text'=>'Volumes'}}, - 'legend'=>{'enabled'=>JSON::XS::true}, - 'credits'=>{'enabled'=>JSON::XS::false}, - 'series'=>[]); - $start =~ s/(\d\d\d\d-\d\d)-\d\d/$1/ if defined $start; - $end =~ s/(\d\d\d\d-\d\d)-\d\d/$1/ if defined $end; - $start = $self->SimpleSqlGet('SELECT MIN(monthyear) FROM userstats') unless $start; - $end = $self->SimpleSqlGet('SELECT MAX(monthyear) FROM userstats') unless $end; - my %users; - my %titles = (0=>'Review Count', 1=>'Time Reviewing', - 2=>'Invalidation Rate', 3=>'Flagged Reviews'); - my %sel = (0=>'SUM(s.total_reviews)', - 1=>'SUM(s.total_time/60)', - 2=>'ROUND(100*SUM(s.total_incorrect)/SUM(s.total_reviews),2)', - 3=>'SUM(s.total_flagged)'); - $type = 0 unless defined $titles{$type}; - my $title = $titles{$type}; - my $sql = 'SELECT DISTINCT monthyear FROM userstats WHERE monthyear>=? AND monthyear<=? ORDER BY monthyear ASC'; - #print "$sql, $start, $end\n"; - my @dates; - my $ref = $self->SelectAll($sql, $start, $end); - foreach my $row (@{$ref}) - { - my $date = $row->[0]; - push @dates, $date; - push @{$data{'xAxis'}->{'categories'}}, $self->YearMonthToEnglish($date); - } - my $i = 0; - $data{'yAxis'}->{'title'}->{'text'} = $title; - $data{'yAxis'}->{'labels'}->{'format'} = '{value}%' if $type == 2; - $data{'tooltip'}->{'pointFormat'} = '{series.name}: {point.y}%' if $type == 2; - my @colors = PickColors(scalar @users); - foreach my $user (@users) - { - my $ids = $self->GetUserIncarnations($user); - my $name = $self->GetUserProperty($user, 'name'); - my $comm = $self->SimpleSqlGet('SELECT commitment FROM users WHERE id=?', $user); - my @counts; # For the inval rate tip - my $wc = $self->WildcardList(scalar @{$ids}); - my $h = {'color'=>$colors[$i], 'name'=>$name, 'data'=>[]}; - push @{$data{'series'}}, $h; - foreach my $date (@dates) - { - my $sql = 'SELECT ' . $sel{$type} . ' FROM userstats s'. - ' WHERE s.monthyear=? AND s.user IN '. $wc; - my $val = $self->SimpleSqlGet($sql, $date, @{$ids}); - $val = 0 unless $val; - my $count = 0; - if ($type == 2) - { - $sql = 'SELECT SUM(s.total_reviews) FROM userstats s'. - ' WHERE s.monthyear=? AND s.user IN '. $wc; - $count = $self->SimpleSqlGet($sql, $date, @{$ids}); - } - if ($type == 1) - { - $sql = 'SELECT COALESCE(SUM(TIME_TO_SEC(r.duration)),0)/3600.0 from reviews r'. - ' INNER JOIN users u ON r.id=u.id'. - ' WHERE CONCAT(YEAR(DATE(r.time)),"-",MONTH(DATE(r.time)))=?'. - ' AND r.user IN '. $wc; - $val += $self->SimpleSqlGet($sql, $date, @{$ids}); - } - $val = int($val) if $type == 0; - $val = $val + 0.0 if $type > 0; - if ($type == 1 && defined $comm && 160.0*$comm <= $val) - { - $val = {'y'=>$val, 'marker'=>{'radius'=>8}}; - } - elsif ($type == 2 && $val < 6.0 && $count > 0) - { - $val = {'y'=>$val, 'marker'=>{'radius'=>8}}; - } - push @{$data{'series'}->[$i]->{'data'}}, $val; - } - $i++; - } - return \%data; -} - -sub CreateFlaggedGraph -{ - my $self = shift; - my @users = @_; - - my %data = ('chart'=>{'type'=>'spline'}, 'title'=>{'text'=>undef}, - 'tooltip'=>{'pointFormat'=>'{series.name}: {point.y}'}, - 'xAxis'=>{'categories'=>[], 'labels'=>{'rotation'=>45}}, - 'yAxis'=>{'min'=>0, 'title'=>{'text'=>'Volumes'}}, - 'legend'=>{'enabled'=>JSON::XS::true}, - 'credits'=>{'enabled'=>JSON::XS::false}, - 'series'=>[], - 'users'=>[]); - my $sql = 'SELECT DISTINCT DATE(time) d FROM historicalreviews'. - ' WHERE time>=DATE_SUB(NOW(), INTERVAL 1 MONTH)'. - ' AND user IN ('. join(',',map {"\"$_\"";} @users). ')'. - ' ORDER BY d ASC'; - #print "$sql\n"; - my @dates; - my $ref = $self->SelectAll($sql); - foreach my $row (@{$ref}) - { - my $date = $row->[0]; - push @dates, $date; - push @{$data{'xAxis'}->{'categories'}}, $date; - } - my $i = 0; - $data{'yAxis'}->{'title'}->{'text'} = 'Flagged Reviews'; - my @colors = PickColors(scalar @users); - foreach my $user (@users) - { - my $ids = $self->GetUserIncarnations($user); - my $name = $self->GetUserProperty($user, 'name'); - my $wc = $self->WildcardList(scalar @{$ids}); - my $h = {'color'=>$colors[$i], 'name'=>$name, 'data'=>[]}; - push @{$data{'series'}}, $h; - foreach my $date (@dates) - { - my $sql = 'SELECT COUNT(id) FROM historicalreviews WHERE flagged IS NOT NULL'. - ' AND flagged>0 AND DATE(time)=? AND user in '. $wc; - my $val = int($self->SimpleSqlGet($sql, $date, @{$ids})); - $val = 0 unless $val; - push @{$data{'series'}->[$i]->{'data'}}, $val; - } - $i++; - } - return \%data; -} - -sub CreateCandidatesGraph2 -{ - my $self = shift; - - my %data = ('chart'=>{'type'=>'spline'}, 'title'=>{'text'=>undef}, - 'tooltip'=>{'pointFormat'=>'{point.y}'}, - 'xAxis'=>{'categories'=>[], 'labels'=>{'rotation'=>45}}, - 'yAxis'=>{'min'=>0, 'title'=>{'text'=>'Volumes'}}, - 'legend'=>{'enabled'=>JSON::XS::false}, - 'credits'=>{'enabled'=>JSON::XS::false}, - 'series'=>[{'name'=>'Candidates', 'data'=>[]}]); - my $sql = 'SELECT DATE(time),size FROM candidatessize'. - ' WHERE DATE(time)=(SELECT MIN(DATE(time)) FROM candidatessize)'. - ' OR DATE(time)=(SELECT MAX(DATE(time)) FROM candidatessize)'. - ' OR DATE(time) LIKE "%-01"'. - ' ORDER BY DATE(time) ASC'; - my $ref = $self->SelectAll($sql); - my @titles; - my @vals; - foreach my $row (@{$ref}) - { - my ($d,$cnt) = ($row->[0], $row->[1]); - push @titles, $d; - push @vals, $cnt; - } - foreach my $i (0 .. scalar @vals - 1) - { - push @{$data{'xAxis'}->{'categories'}}, $titles[$i]; - push @{$data{'series'}->[0]->{'data'}}, int($vals[$i]); - } - return \%data; -} - -sub CreateCandidatesGraph3 -{ - my $self = shift; - - my %data = ('chart'=>{'type'=>'spline'}, 'title'=>{'text'=>undef}, - 'tooltip'=>{'pointFormat'=>'{point.y}'}, - 'xAxis'=>{'categories'=>[], 'labels'=>{'rotation'=>45}}, - 'yAxis'=>{'min'=>0, 'title'=>{'text'=>'Volumes'}}, - 'legend'=>{'enabled'=>JSON::XS::false}, - 'credits'=>{'enabled'=>JSON::XS::false}, - 'series'=>[{'name'=>'Candidates', 'data'=>[]}]); - my $sql = 'SELECT DISTINCT(DATE(time)) FROM exportdata'. - ' WHERE DATE(time)=(SELECT MIN(DATE(time)) FROM exportdata)'. - ' OR DATE(time)=(SELECT MAX(DATE(time)) FROM exportdata)'. - ' OR DATE(time) LIKE "%-01"'. - ' ORDER BY DATE(time) DESC'; - my $size = $self->GetCandidatesSize(); - my $ref = $self->SelectAll($sql); - my @titles; - my @vals; - my $i; - push @titles, $ref->[0]->[0]; - push @vals, $size; - #print "Starting size $size\n"; - foreach my $i (1 .. scalar @{$ref} - 2) - { - # second date is earlier - $sql = 'SELECT COUNT(*) FROM exportdata WHERE DATE(time)>? AND DATE(time)<=? AND (src="candidates" OR src="cri" OR src="inherited")'; - my $cnt = $self->SimpleSqlGet($sql, $ref->[$i+1]->[0], $ref->[$i]->[0]); - $size += $cnt; - #printf "%s to %s: $cnt, size now $size\n", $ref->[$i+1]->[0], $ref->[$i]->[0]; - push @titles, $ref->[$i]->[0]; - push @vals, $size; - } - $sql = 'SELECT COUNT(*) FROM exportdata WHERE DATE(time)<=? AND (src="candidates" OR src="cri" OR src="inherited")'; - my $cnt = $self->SimpleSqlGet($sql, $ref->[scalar @{$ref}-2]->[0]); - push @titles, $ref->[scalar @{$ref}-1]->[0]; - push @vals, $size+$cnt; - @titles = reverse @titles; - @vals = reverse @vals; - foreach my $i (0 .. scalar @vals - 1) - { - push @{$data{'xAxis'}->{'categories'}}, $titles[$i]; - push @{$data{'series'}->[0]->{'data'}}, int($vals[$i]); - } - return \%data; -} - -sub CreateProgressGraph -{ - my $self = shift; - my $project = shift; - - my $proj = $self->SimpleSqlGet('SELECT COALESCE(id,1) FROM projects WHERE name=?', $project); - my $sql = 'SELECT COUNT(*) FROM exportdata WHERE project=?'; - my $val = $self->SimpleSqlGet($sql, $proj); - $sql = 'SELECT COUNT(*) FROM candidates WHERE project=?'; - my $n = $self->SimpleSqlGet($sql, $proj); - my $total = $val + $n; - my $ticks = NearestMultiple(1000, $total/10); - my $fmt = '
-
-
-
-
-
- -
-
-
-
- (YYYY-MM-DD)
-
- - - - - (YYYY-MM-DD) - - [% actives = [] %] - - |
-
- [% sql = "SELECT id,shortname FROM institutions WHERE id!=0 ORDER BY shortname ASC" %]
- [% ref = crms.SelectAll(sql) %]
- |
-
|