Graphs generators and lib_revcheck optimizations

* removed functions doing the same job
* some functions replaced with already existing more efficient replacements
* total ammount of files on language graph fixed
* other improvements

Charts are generated over two times faster now
This commit is contained in:
Sobak
2014-03-31 08:24:42 +02:00
parent 487e76617c
commit b28179fbd7
4 changed files with 49 additions and 143 deletions

1
.gitignore vendored
View File

@ -4,4 +4,5 @@ include/jpgraph
shared
sqlite
svn
www/images
www/robots.txt

View File

@ -102,7 +102,6 @@ function get_outdated_files($idx, $lang, $dir)
}
return $tmp;
}
// return an array with the outdated files maintained by $user
@ -148,41 +147,23 @@ function get_outdated_translator_files($idx, $lang, $user)
}
return $tmp;
}
// Return an array of available languages for a revchecked documentation $type
// Return an array of available languages for manual
function revcheck_available_languages($idx)
{
$tmp = array();
if (!$idx) {
return FALSE;
}
$sql = 'SELECT lang FROM description';
$result = @$idx->query($sql);;
if (!$result) {
return FALSE;
}
if ($result) {
while ($r = $result->fetchArray()) {
$tmp[] = $r['lang'];
}
}
return $tmp;
$result = $idx->query('SELECT lang FROM description');
return $result->fetchArray(SQLITE3_NUM);
}
// Return en integer
function get_nb_EN_files($idx)
function count_en_files($idx)
{
$sql = "SELECT COUNT(*) AS total FROM files WHERE lang = 'en'";
$res = $idx->query($sql);;
$sql = "SELECT COUNT(name) FROM files WHERE lang = 'en'";
$res = $idx->query($sql);
$row = $res->fetchArray();
return $row['total'];
return $row[0];
}
function get_missfiles($idx, $lang)
@ -205,9 +186,9 @@ function get_missfiles($idx, $lang)
AND
b.lang="en"
AND
a.revision is NULL
a.revision IS NULL
AND
a.size is NULL
a.size IS NULL
AND
a.dir = d.id';
$result = $idx->query($sql);
@ -250,7 +231,7 @@ function get_misstags($idx, $lang)
d.name AS dir, b.size AS en_size, a.size AS trans_size, a.name AS name
FROM files a, dirs d
LEFT JOIN files b ON a.dir = b.dir AND a.name = b.name
WHERE a.lang="'.$lang.'" AND b.lang="en" AND a.revision IS NULL
WHERE a.lang="'.$lang.'" AND b.lang="en" AND a.revision IS NULL
AND a.size IS NOT NULL AND a.dir = d.id';
$result = $idx->query($sql);
@ -261,30 +242,6 @@ function get_misstags($idx, $lang)
return $tmp;
}
// Return an integer
function get_nb_LANG_files($idx)
{
$sql = '
SELECT
lang,
COUNT(*) as total
FROM
files
WHERE
lang != \'en\'
GROUP BY
lang
ORDER BY
lang
';
$result = $idx->query($sql);
while ($row = $result->fetchArray()) {
$files[$row['lang']] = $row['total'];
}
return $files;
}
// Return a string
function translator_get_wip($idx, $lang)
{
@ -345,7 +302,6 @@ function translator_get_old($idx, $lang)
return $tmp;
}
function translator_get_critical($idx, $lang)
{
$sql = 'SELECT
@ -425,7 +381,7 @@ function translator_get_uptodate($idx, $lang)
function get_translators($idx, $lang)
{
$sql= "SELECT nick, name, mail, svn FROM translators WHERE lang = '$lang' ORDER BY nick COLLATE NOCASE";
$sql = "SELECT nick, name, mail, svn FROM translators WHERE lang = '$lang' ORDER BY nick COLLATE NOCASE";
$persons = array();
$result = $idx->query($sql);
while ($r = $result->fetchArray()) {
@ -434,34 +390,6 @@ function get_translators($idx, $lang)
return $persons;
}
function get_nb_LANG_files_Translated($idx, $lang)
{
$sql = '
SELECT
b.lang as language,
COUNT(*) as total
FROM
files a
LEFT JOIN
files b
WHERE
b.lang="' . $lang . '"
AND
a.lang=\'en\'
AND
b.name = a.name
AND
b.dir = a.dir
AND
a.revision = b.revision
GROUP BY
b.lang
';
$result = $idx->query($sql);
return $result->fetchArray();
}
// Return an array
function get_stats_uptodate($idx, $lang)
{
@ -572,43 +500,18 @@ function get_stats_old($idx, $lang)
return $result;
}
// Returns number of untranslated files for specified $lang
function get_stats_notrans($idx, $lang)
{
$sql = 'SELECT
COUNT(a.name) as total,
sum(b.size) as size
FROM
files a,
dirs d
LEFT JOIN
files b
ON
a.dir = b.dir
AND
a.name = b.name
WHERE
a.lang="' . $lang . '"
AND
b.lang="en"
AND
a.revision is NULL
AND
a.size is NULL
AND
a.dir = d.id';
$sql = "SELECT COUNT(a.name) AS total, SUM(b.size) as size
FROM files a, dirs d
LEFT JOIN files b ON a.dir = b.dir AND a.name = b.name
WHERE a.lang = '$lang' AND b.lang='en' AND a.revision IS NULL AND a.size IS NULL AND a.dir = d.id";
$result = $idx->query($sql);
$r = $result->fetchArray();
return array($r['total'], $r['size']);
if (sqlite_num_rows($result)) {
$r = $result->fetchArray();
return array($r['total'], $r['size']);
} else {
return array(0,0);
}
}
function get_stats_wip($idx, $lang)

View File

@ -1,4 +1,6 @@
<?php
$time_start = microtime(true);
include '../include/jpgraph/src/jpgraph.php';
include '../include/jpgraph/src/jpgraph_pie.php';
include '../include/jpgraph/src/jpgraph_pie3d.php';
@ -9,27 +11,26 @@ include '../include/lib_proj_lang.inc.php';
$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
$available_langs = revcheck_available_languages($idx);
$langs = array_keys($LANGUAGES);
foreach ($langs as $lang) {
if (!generate_image($lang, $idx)) {
if (!in_array($lang, $available_langs)) {
echo "Documentation for $lang language does not exist.\n";
} else {
echo "Generated images/revcheck/info_revcheck_php_" . $lang . ".png\n";
generate_image($lang, $idx);
echo "Generated images/revcheck/info_revcheck_php_$lang.png\n";
}
}
$time = round(microtime(true) - $time_start, 3);
echo "Graphs generated in {$time}s\n";
function generate_image($lang, $idx) {
global $LANGUAGES;
$Total_files = @get_nb_LANG_files($idx);
if (!isset($Total_files[$lang]) ) {
return FALSE;
}
$Total_files_lang = $Total_files[$lang];
//
$up_to_date = @get_nb_LANG_files_Translated($idx, $lang);
$up_to_date = ($up_to_date['total'] == '') ? 0 : $up_to_date['total'];
$up_to_date = get_stats_uptodate($idx, $lang);
$up_to_date = $up_to_date[0];
//
$critical = @get_stats_critical($idx, $lang);
$critical = $critical[0];
@ -37,22 +38,27 @@ function generate_image($lang, $idx) {
$old = @get_stats_old($idx, $lang);
$old = $old[0];
//
$missing = sizeof(@get_missfiles($idx, $lang));
$missing = get_stats_notrans($idx, $lang);
$missing = $missing[0];
//
$no_tag = @get_stats_notag($idx, $lang);
$no_tag = $no_tag[0];
//
$data = array($up_to_date,$critical,$old,$missing,$no_tag);
$data = array(
$up_to_date,
$critical,
$old,
$missing,
$no_tag
);
$percent = array();
$total = 0;
$total = array_sum($data);
$total = array_sum($data); // Total ammount in EN manual (to calculate percentage values)
$total_files_lang = $total - $missing; // Total ammount of files in translation
foreach ($data as $value) {
$percent[] = round($value * 100 / $total);
}
$noExplode = ($Total_files_lang == $up_to_date) ? 1 : 0;
$legend = array($percent[0] . '%% up to date ('.$up_to_date.')', $percent[1] . '%% critical ('.$critical.')', $percent[2] . '%% old ('.$old.')', $percent[3] . '%% missing ('.$missing.')', $percent[4] . '%% without revtag ('.$no_tag.')');
$title = 'Details for '.$LANGUAGES[$lang].' PHP Manual';
@ -66,7 +72,7 @@ function generate_image($lang, $idx) {
$graph->legend->Pos(0.02,0.18,"right","center");
$graph->subtitle->Set('(Total: '.$Total_files_lang.' files)');
$graph->subtitle->Set('(Total: '.$total_files_lang.' files)');
$graph->subtitle->Align('left');
$graph->subtitle->SetColor('darkred');
@ -79,7 +85,7 @@ function generate_image($lang, $idx) {
$p1 = new PiePlot3D($data);
$p1->SetSliceColors(array("#68d888", "#ff6347", "#eee8aa", "#dcdcdc", "#f4a460"));
if ($noExplode != 1) {
if ($total_files_lang != $up_to_date) {
$p1->ExplodeAll();
}
$p1->SetCenter(0.35,0.55);
@ -88,8 +94,5 @@ function generate_image($lang, $idx) {
$p1->SetLegends($legend);
$graph->Add($p1);
$graph->Stroke('../www/images/revcheck/info_revcheck_php_' . $lang . '.png');
return TRUE;
}
$graph->Stroke("../www/images/revcheck/info_revcheck_php_$lang.png");
}

View File

@ -9,12 +9,12 @@ $idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
$language = revcheck_available_languages($idx);
sort($language);
$files_EN = get_nb_EN_files($idx);
$files_EN = count_en_files($idx);
foreach ($language as $lang) {
$tmp = get_nb_LANG_files_Translated($idx, $lang);
$tmp = get_stats_uptodate($idx, $lang);
$percent_tmp[] = round($tmp['total'] * 100 / $files_EN);
$percent_tmp[] = round($tmp[0] * 100 / $files_EN);
$legend_tmp[] = $lang;
}
@ -72,5 +72,4 @@ function generate_image() {
// Display the graph
$graph->Stroke('../www/images/revcheck/info_revcheck_php_all_lang.png');
}
}