Skip to content
Merged
Show file tree
Hide file tree
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
673 changes: 340 additions & 333 deletions daily_table.js

Large diffs are not rendered by default.

83 changes: 70 additions & 13 deletions gather_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ function transform_pr_nodes(pr_nodes) {
return pr_nodes.map(pr_node => {
const maintainer_reviews = pr_node.reviews.nodes
.filter(review_node => {
if (review_node.author === null) {
return false; // Assume that deleted users were contributors.
}

const username = review_node.author.login;

const is_maintainer = maintainers.has(username);
Expand Down Expand Up @@ -235,6 +239,37 @@ function transform_issue_nodes(issue_nodes) {
});
}

function calculate_sliding_window(when, merged) {
// A sliding window of 30 days would be simple, but would result in a noisy line as PRs abruptly leave the window.
// To reduce such noise, this function applies smoothing between 20 and 40 days.
// (A range of 25 to 35 days would also work; the important thing is for the integral of this function to be 30,
// so we can still describe this metric as 'Monthly Merged PRs'.

const days_ago = when.diff(merged).as('days');

if (days_ago < 0) {
return 0; // PR was merged in the future
} else if (days_ago < 20) {
return 1; // PR was merged between 0 and 20 days ago
} else if (days_ago < 40) {
return (40 - days_ago) / 20; // PR was merged between 20 and 40 days ago; decrease weight from 1 to 0
} else {
return 0; // PR was merged in the ancient past
}
}

function write_generated_file(filename, table_str) {
const generated_file_warning_comment = '// Generated file - DO NOT EDIT manually!\n';

let str = '// Copyright (c) Microsoft Corporation.\n';
str += '// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\n';
str += generated_file_warning_comment;
str += table_str;
str += generated_file_warning_comment;

fs.writeFileSync(filename, str);
}

function write_daily_table(script_start, all_prs, all_issues) {
const progress_bar = new cliProgress.SingleBar(
{
Expand All @@ -246,19 +281,13 @@ function write_daily_table(script_start, all_prs, all_issues) {
);

try {
let str = '// Copyright (c) Microsoft Corporation.\n';
str += '// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n';
str += '\n';
const generated_file_warning_comment = '// Generated file - DO NOT EDIT manually!\n';
str += generated_file_warning_comment;
str += 'const daily_table = [\n';
let str = 'const daily_table = [\n';

const begin = DateTime.fromISO('2019-09-05' + 'T23:00:00-07');

progress_bar.start(Math.ceil(script_start.diff(begin).as('days')), 0);

for (let when = begin; when < script_start; when = when.plus({ days: 1 })) {
const one_month_ago = when.minus({ months: 1 });
let num_merged = 0;
let num_pr = 0;
let num_cxx20 = 0;
Expand All @@ -269,9 +298,7 @@ function write_daily_table(script_start, all_prs, all_issues) {
let combined_pr_wait = Duration.fromObject({});

for (const pr of all_prs) {
if (one_month_ago < pr.merged && pr.merged < when) {
++num_merged;
}
num_merged += calculate_sliding_window(when, pr.merged);

if (when < pr.opened || pr.closed < when) {
// This PR wasn't active; do nothing.
Expand Down Expand Up @@ -308,7 +335,7 @@ function write_daily_table(script_start, all_prs, all_issues) {
str += ' { ';
str += [
`date: '${when.toISODate()}'`,
`merged: ${num_merged}`,
`merged: ${Number.parseFloat(num_merged).toFixed(2)}`,
`pr: ${num_pr}`,
`cxx20: ${num_cxx20}`,
`lwg: ${num_lwg}`,
Expand All @@ -325,14 +352,43 @@ function write_daily_table(script_start, all_prs, all_issues) {
}

str += '];\n';
str += generated_file_warning_comment;

fs.writeFileSync('./daily_table.js', str);
write_generated_file('./daily_table.js', str);
} finally {
progress_bar.stop();
}
}

function write_monthly_table(script_start, all_prs) {
const monthly_merges = new Map();

for (const pr of all_prs) {
const year_month = pr.merged.toFormat('yyyy-MM');
const old_value = monthly_merges.get(year_month) ?? 0;
monthly_merges.set(year_month, old_value + 1);
}

let str = 'const monthly_table = [\n';

// Analyze complete months.
const begin = DateTime.fromISO('2019-10-01');
for (let when = begin; when < script_start.startOf('month'); when = when.plus({ months: 1 })) {
const year_month = when.toFormat('yyyy-MM');
const value = monthly_merges.get(year_month) ?? 0;

str += ' { ';
str += [
`date: '${year_month}-16'`, // position each bar in the middle of each month
`merge_bar: ${value}`,
'},\n',
].join(', ');
}

str += '];\n';

write_generated_file('./monthly_table.js', str);
}

async function async_main() {
try {
const script_start = DateTime.local();
Expand All @@ -343,6 +399,7 @@ async function async_main() {
const all_issues = transform_issue_nodes(issue_nodes);

write_daily_table(script_start, all_prs, all_issues);
write_monthly_table(script_start, all_prs);

const script_finish = DateTime.local();

Expand Down
28 changes: 18 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
integrity="sha256-OrN9od558nPowCwU4e475a5CCwTfCwSrk7TF7KYUoXk=" crossorigin="anonymous"></script>
<script src="daily_table.js"></script>
<script src="weekly_table.js"></script>
<script src="monthly_table.js"></script>
<script>
function get_values(table, key) {
return table.filter(row => row[key] !== undefined).map(row => ({ x: row.date, y: row[key] }));
Expand Down Expand Up @@ -138,11 +139,18 @@
datasets: [
{
data: get_values(daily_table, 'merged'),
label: 'Monthly Merged PRs',
label: 'Line: Sliding Window',
borderColor: '#00B050',
backgroundColor: '#00B050',
yAxisID: 'mergeAxis',
},
{
type: 'bar',
data: get_values(monthly_table, 'merge_bar'),
label: 'Bars: Calendar Months',
borderWidth: 1,
yAxisID: 'mergeAxis',
},
],
};

Expand Down Expand Up @@ -194,6 +202,7 @@
type: 'time',
ticks: {
min: timeframe.ticks.min,
max: daily_table[daily_table.length - 1].date,
},
time: {
parser: 'yyyy-MM-dd',
Expand Down Expand Up @@ -298,9 +307,6 @@
...common_title,
text: 'Monthly Merged PRs',
},
legend: {
display: false,
},
scales: {
xAxes: make_xAxes(timeframe_github),
yAxes: [
Expand Down Expand Up @@ -458,17 +464,19 @@ <h1>Explanation</h1>
<canvas id="mergeChart"></canvas>

<h1>Explanation</h1>
<p>For this line, more is better.</p>
<p>For this chart, more is better. It includes merges into any branch
and excludes PRs that were closed without being merged, which are rare.</p>

<ul>
<li>Right axis:
<li>(<span class="currentValue" id="currentValue-merged"></span>)
Line: How many PRs have been merged over the past month.
This uses a "30 day" sliding window, with some smoothing:
<ul>
<li>(<span class="currentValue" id="currentValue-merged"></span>)
How many PRs have been merged into any branch over the past month.
This uses a sliding window of 30 days, without any smoothing.
It excludes PRs that were closed without being merged, which are rare.</li>
<li>PRs merged 0 to 20 days ago are weighted at 100%.</li>
<li>PRs merged 20 to 40 days ago are weighted from 100% to 0%.</li>
</ul>
</li>
<li>Bars: How many PRs were merged in each calendar month.</li>
</ul>

<hr />
Expand Down
17 changes: 17 additions & 0 deletions monthly_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// Generated file - DO NOT EDIT manually!
const monthly_table = [
{ date: '2019-10-16', merge_bar: 29, },
{ date: '2019-11-16', merge_bar: 20, },
{ date: '2019-12-16', merge_bar: 26, },
{ date: '2020-01-16', merge_bar: 32, },
{ date: '2020-02-16', merge_bar: 27, },
{ date: '2020-03-16', merge_bar: 49, },
{ date: '2020-04-16', merge_bar: 47, },
{ date: '2020-05-16', merge_bar: 43, },
{ date: '2020-06-16', merge_bar: 29, },
{ date: '2020-07-16', merge_bar: 65, },
];
// Generated file - DO NOT EDIT manually!
1 change: 1 addition & 0 deletions usernames_contributors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This is very far from an exhaustive list of contributors, and confers no special status.
# It's simply a list of contributors who have submitted a PR review marked as CHANGES_REQUESTED.

AlexGuteniev
fsb4000
miscco
statementreply
Expand Down
1 change: 1 addition & 0 deletions weekly_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@ const weekly_table = [
{ date: '2020-07-17', vso: 166, libcxx: 546 },
{ date: '2020-07-24', vso: 166, libcxx: 546 },
{ date: '2020-07-31', vso: 160, libcxx: 545 },
{ date: '2020-08-07', vso: 161, libcxx: 546 },
];