Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect reviews as an input for index 'active' #1

Open
wants to merge 2 commits into
base: github-statistics
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions statistics/github/contributor-collect
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use warnings;
use Net::GitHub::V3;
use Data::Dumper;
use Time::Local;
use DateTime;
use File::Basename;
use JSON;

Expand Down Expand Up @@ -133,9 +134,11 @@ sub collect_all_pulls {
$created_date = $1 . $2 . $3;
}

$created_date = time_string_to_epoch($created_date);
my $created_week = time_string_to_last_sunday_epoch($created_date);

$data{stats}{$contributor}{prs}{$created_date} += 1;
$data{stats}{$contributor}{prs}{$created_week} += 1;

$data{stats}{$contributor}{active}{$created_week} = 1;

# check for comments in all PRs for the contributor
my $pull_id = $pull->{number};
Expand Down Expand Up @@ -195,7 +198,7 @@ sub collect_all_contribs {

# count active weeks
if ($week->{c} or $week->{a} or $week->{d}) {
$data{stats}{$contributor}{active}{$week->{w}} += 1;
$data{stats}{$contributor}{active}{$week->{w}} = 1;
}
}
print STDERR "+" if ++$cnt % 10 == 0;
Expand All @@ -222,14 +225,16 @@ sub count_reviews {
$created_date = $1 . $2 . $3;
}

$created_date = time_string_to_epoch($created_date);
my $created_week = time_string_to_last_sunday_epoch($created_date);

# This is always added
$data{stats}{$contributor}{comments}{$created_date} += 1;
$data{stats}{$contributor}{comments}{$created_week} += 1;

$data{stats}{$contributor}{active}{$created_week} = 1;

# This is added only if the author is not the contributor himself
if ($author ne $contributor) {
$data{stats}{$contributor}{reviews}{$created_date} += 1;
$data{stats}{$contributor}{reviews}{$created_week} += 1;
}
}
}
Expand All @@ -243,3 +248,13 @@ sub time_string_to_epoch {

return $epoch;
}

# date must be YYYYMMDD
sub time_string_to_last_sunday_epoch {
my ($date_string) = @_;
my ($year, $month, $day) = unpack "A4A2A2", $date_string;

my $date = DateTime->new(year => $year, month => $month, day => $day);
$date->subtract(days => $date->day_of_week % 7);
return $date->epoch;
}