Created
October 9, 2012 21:21
-
-
Save benbalter/3861538 to your computer and use it in GitHub Desktop.
Generate a tag cloud of the .Gov Open Source Repos on Github
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 | |
//social media registry | |
$account_query = 'http://registry.usa.gov/accounts.json?service_id=github&agency_id=&tag='; | |
//URL to query GitHub API to retreive repos | |
$repo_query = 'https://api.github.com/users/%s/repos'; | |
//max size | |
$max_size = 60; | |
$min_size = 1; | |
//get accounts | |
$data = file_get_contents( $account_query ); | |
$agencies = json_decode( $data )->accounts; | |
//loop through accounts and build wordle seed info | |
$counts = array(); | |
foreach ( $agencies as &$agency ) { | |
$repos = json_decode( file_get_contents( sprintf( $repo_query, $agency->account ) ) ); | |
$counts[ $agency->organization ] = sizeof( $repos ); | |
} | |
//arsort( $counts ); | |
$counts = array_filter( $counts ); | |
$min = min( $counts ); | |
$max = max( $counts ); | |
?> | |
<style> | |
.tag { list-style: none; display: inline; } | |
</style> | |
<ul clas="tags"> | |
<?php foreach ( $counts as $agency => $count ) { | |
$weight = ( log( (int) $count ) - log( (int) $min ) ) / ( log( (int) $max ) - log( (int) $min ) ); | |
$size = round( $min_size + ( $max_size - $min_size ) * $weight, 2); | |
?> | |
<li class="tag" style="font-size: <?php echo $size; ?>px"><?php echo $agency; ?> (<?php echo $count; ?>) </li> | |
<?php } ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment