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

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');
}
}