Skip to content

Instantly share code, notes, and snippets.

@timhunt
Created August 13, 2013 16:56
Show Gist options
  • Save timhunt/6223210 to your computer and use it in GitHub Desktop.
Save timhunt/6223210 to your computer and use it in GitHub Desktop.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script generates a .dot file that can be fed to graphviz, to show who
* has been peer-reviewing whose patches in the tracker.
*
* To use this script:
* 1. Save it into the top level folder of your Moodle site.
* 2. Hack it if you like, e.g. change the clusters, or the 120d in the query.
* 3. Run it.
* 4. Save the output in a file called graph.dot.
* 5. Download GraphViz from http://www.graphviz.org/Download..php
* 6. Run it, and open the graph.dot file.
* 7. Wait, and either GraphViz will crash, or you will get a graph.
* 8. Change the options in the Graph -> Settings menu to see if you can imporve the layout.
*
* @copyright 2013 The Open University
* @package randomhacks
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/config.php');
require_once($CFG->libdir . '/filelib.php');
$clusters = array(
'Integration' => array(
'stronk7' => 'Eloy Lafuente',
'samhemelryk' => 'Sam Hemelryk',
'poltawski' => 'Dan Poltawski',
'marina' => 'Marina Glancy',
'davmon' => 'David Monllaó',
),
'Backend' => array(
'skodak' => 'Petr Škoda',
'rajeshtaneja' => 'Rajesh Taneja',
'fred' => 'Frédéric Massart',
'ankit_frenz' => 'Ankit Agarwal',
'abgreeve' => 'Adrian Greeve',
'markn' => 'Mark Nelson',
),
'Frontend' => array(
'damyon' => 'Damyon Wiese',
'jerome' => 'Jérôme Mouneyrac',
'rwijaya' => 'Rossiani Wijaya',
'andyjdavis' => 'Andrew Davis',
'phalacee' => 'Jason Fowler',
),
'Sites' => array(
'barbararamiro' => 'Barbara Ramiro',
'mudrd8mz' => 'David Mudrak',
'' => 'Aparup Banerjee',
'' => 'X.Y. Ng',
'' => 'Matt Spurrier',
),
'OU' => array(
'quen' => 'Sam Marshall',
'timhunt' => 'Tim Hunt',
'colchambers' => 'Colin Chambers',
'jp76' => 'Jason Platts',
),
);
$trackerquery = '"Peer reviewer" is not EMPTY AND resolutiondate >= -120d';
$trackerresultsurl = new moodle_url('https://tracker.moodle.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml',
array('jqlQuery' => $trackerquery, 'tempMax' => 10000));
$xml = download_file_content($trackerresultsurl);
$xml = simplexml_load_string($xml);
$dom = dom_import_simplexml($xml);
$xsl = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common">
<!-- Root -->
<xsl:template match="/rss/channel">
<issues>
<xsl:apply-templates select="item"/>
</issues>
</xsl:template>
<xsl:template match="item">
<issue>
<key><xsl:value-of select="key"/></key>
<assignee><xsl:value-of select="assignee"/></assignee>
<assigneeusername><xsl:value-of select="assignee/@username"/></assigneeusername>
<reviewer><xsl:value-of select="customfields/customfield[customfieldname='Peer reviewer']/customfieldvalues/customfieldvalue"/></reviewer>
</issue>
</xsl:template>
</xsl:stylesheet>
END;
$xsl = simplexml_load_string($xsl);
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
$issuesxml = $proc->transformToDoc($dom);
$issuesxml = simplexml_import_dom($issuesxml);
// Array username => real name.
$realnames = array();
// Array reviewer username => reviewee username => count.
$edges = array();
foreach ($issuesxml->children() as $issue) {
$assignee = (string) $issue->assignee;
$assigneeusername = (string) $issue->assigneeusername;
$reviewer = (string) $issue->reviewer;
$realnames[$assigneeusername] = $assignee;
if (!array_key_exists($reviewer, $realnames)) {
$realnames[$reviewer] = $reviewer;
}
if (!array_key_exists($reviewer, $edges)) {
$edges[$reviewer] = array();
}
if (!array_key_exists($reviewer, $edges)) {
$edges[$reviewer] = array();
}
if (!array_key_exists($assigneeusername, $edges[$reviewer])) {
$edges[$reviewer][$assigneeusername] = 0;
}
$edges[$reviewer][$assigneeusername] += 1;
}
header('Content-Type: text/plain; charset=utf-8');
echo <<<END
digraph {
graph [fontsize=6;splines=compound]
edge [len=1.5,minlen=1]
node [shape=box];
END;
$i = 0;
foreach ($clusters as $label => $names) {
$i += 1;
echo " subgraph cluster_{$i} {\n";
echo ' label = "' . $label . '";' . "\n";
foreach ($names as $username => $realname) {
$realnames[$username] = $realname;
echo ' "' . $realname . '";' . "\n";
}
echo " }\n\n";
}
foreach ($edges as $reviewer => $reviewees) {
foreach ($reviewees as $reviewee => $weight) {
echo ' "' . $realnames[$reviewer] . '" -> "' . $realnames[$reviewee] .
'"[weight=' . $weight . ',penwidth=' . $weight . '];' . "\n";
}
}
echo "}\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment