Forked from Rarst/wp-core-contributors-by-version.php
Created
January 9, 2017 10:28
-
-
Save chandrapatel/2ad88988f33916696f338f4f3bbb9d0f to your computer and use it in GitHub Desktop.
WordPress core contributors by version. Input data from https://api.wordpress.org/core/credits/1.1/?version=x.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data_dir = 'c:/server/www/dev/data/'; | |
$releases = [ ]; | |
foreach ( range( 3.2, 4.0, 0.1 ) as $version ) { | |
$version = number_format( $version, 1 ); | |
$data = json_decode( file_get_contents( $data_dir . $version . '.json' ), true ); | |
$groups = wp_list_pluck( $data['groups'], 'data' ); | |
unset( $groups['libraries'] ); | |
$groups = array_map( 'array_keys', $groups ); | |
$releases[ $version ] = call_user_func_array( 'array_merge', $groups ); | |
$releases[ $version ] = array_map( 'strtolower', $releases[ $version ] ); | |
$releases[ $version ] = array_unique( $releases[ $version ] ); | |
} | |
$all_contributors = $releases['3.2']; | |
unset( $releases['3.2'] ); | |
$total_counts = [ ]; | |
$repeat_counts = [ ]; | |
$new_counts = [ ]; | |
foreach ( $releases as $version => $contributors ) { | |
$new_contributors = array_filter( $contributors, function ( $contributor ) use ( $all_contributors ) { | |
return ! in_array( strtolower( $contributor ), $all_contributors ); | |
} ); | |
$all_contributors = array_unique( array_merge( $all_contributors, $contributors ) ); | |
$new_count = count( $new_contributors ); | |
$total_count = count( $contributors ); | |
$total_counts[] = $total_count; | |
$repeat_counts[] = $total_count - $new_count; | |
$new_counts[] = $new_count; | |
} | |
?> | |
<style type="text/css"> | |
#legend .bar-legend li { | |
display: inline; | |
list-style-type: none; | |
text-align: center; | |
margin-left: 10px; | |
} | |
#legend .bar-legend span { | |
display: inline-block; | |
width: 16px; | |
height: 16px; | |
vertical-align: middle; | |
margin: 0 5px; | |
} | |
</style> | |
<div id="legend"></div> | |
<canvas id="myChart" width="800" height="400"></canvas> | |
<script type="text/javascript" src="//cdn.jsdelivr.net/chart.js/1.0.1-beta.4/Chart.min.js"></script> | |
<script type="text/javascript"> | |
var ctx = document.getElementById("myChart").getContext("2d"); | |
var data = { | |
labels : <?= json_encode(array_keys($releases)) ?>, | |
datasets: [ | |
{ | |
label : "Total contributors", | |
fillColor: "rgba(220,220,220,0.5)", | |
data : <?= json_encode($total_counts) ?> | |
}, | |
{ | |
label : "Repeat contributors", | |
fillColor: "rgba(0, 168, 240,0.5)", | |
data : <?= json_encode($repeat_counts) ?> | |
}, | |
{ | |
label : "New contributors", | |
fillColor: "rgba( 192, 216, 0,0.5)", | |
data : <?= json_encode($new_counts) ?> | |
} | |
] | |
}; | |
var myBarChart = new Chart(ctx).Bar(data); | |
var legendHolder = document.getElementById('legend'); | |
legendHolder.innerHTML = myBarChart.generateLegend(); | |
</script> | |
<?php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment