Skip to content

Commit

Permalink
Clean up showrepos code, remove JSON option (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
flodolo authored and pascalchevrel committed Apr 12, 2016
1 parent 4e41272 commit 9861250
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 104 deletions.
8 changes: 8 additions & 0 deletions app/controllers/showrepos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require_once INC . 'l10n-init.php';

// Include JS lib after $javascript_include gets reset in l10n-init.php.
$javascript_include = ['/js/sorttable.js'];

include MODELS . 'showrepos.php';
include VIEWS . 'showrepos.php';
2 changes: 1 addition & 1 deletion app/inc/dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$css_include = ['health.css'];
break;
case 'stats':
$view = 'showrepos';
$controller = 'showrepos';
$page_title = 'Status Overview';
$page_descr = 'Repository status overview.';
break;
Expand Down
94 changes: 94 additions & 0 deletions app/models/showrepos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
namespace Transvision;

// Ignore mozilla.org
$repos = array_diff($repos, ['mozilla_org']);
$channel_selector = '';
foreach ($repos as $repo_name) {
$selected_channel = ($repo_name == $repo) ? ' selected' : '';
$channel_selector .= "\t<option {$selected_channel} value=\"{$repo_name}\">{$repos_nice_names[$repo_name]}</option>\n";
}

// Filter out empty strings and known exceptions from reference strings
$reference_locale = Project::getReferenceLocale($repo);
$is_desktop_repo = in_array($repo, $desktop_repos);
$filter_strings = function ($value, $id) use ($is_desktop_repo) {
// Ignore empty strings
if (! strlen($value)) {
return false;
}

// Exclude some known exceptions from desktop repositories
if ($is_desktop_repo) {
$exclusions = [
'/branding/', '/dataman/', '/fennec-tile-testapp/',
'/mozmill/', 'region.properties',
];
foreach ($exclusions as $exclusion) {
if (strpos($id, $exclusion) !== false) {
return false;
}
}
}

return true;
};
$reference_strings = array_filter(Utils::getRepoStrings($reference_locale, $repo), $filter_strings, ARRAY_FILTER_USE_BOTH);

// Get supported locales, ignore the reference locale
$supported_locales = Project::getRepositoryLocales($repo);
$supported_locales = array_diff($supported_locales, [$reference_locale]);

// Reference locale count
$string_count = [];
$reference_count = count($reference_strings);

foreach ($supported_locales as $locale) {
$locale_strings = array_filter(Utils::getRepoStrings($locale, $repo), 'strlen');
$string_count[$locale] = [
'total' => count($locale_strings),
'missing' => count(array_diff_key($reference_strings, $locale_strings)),
'identical' => count(array_intersect_assoc($reference_strings, $locale_strings)),
];
unset($locale_strings);
}
unset($reference_strings);

$table_data = [];
foreach ($string_count as $locale => $stats) {
$completion = $reference_count - $stats['missing'];

// Making sure we never divide by zero while computing percentage
$completion = $reference_count == 0
? 0
: number_format($completion / $reference_count * 100);

if ($completion >= 99) {
$confidence = 'Highest';
} elseif ($completion >= 95) {
$confidence = 'High';
} elseif ($completion >= 90) {
$confidence = 'High';
} elseif ($completion >= 60) {
$confidence = 'In progress';
} elseif ($completion >= 50) {
$confidence = 'Low';
} elseif ($completion >= 30) {
$confidence = 'Very Low';
} elseif ($completion >= 10) {
$confidence = 'Barely started';
} elseif ($completion >= 1) {
$confidence = 'Just started';
} else {
$confidence = 'No localization';
}

$table_data[$locale] = [
'total' => $stats['total'],
'missing' => $stats['missing'],
'translated' => ($stats['total'] - $stats['identical']),
'identical' => $stats['identical'],
'completion' => $completion,
'confidence' => $confidence,
];
}
125 changes: 26 additions & 99 deletions app/views/showrepos.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,16 @@
<?php
namespace Transvision;

$strings = [];
// Include the common simple search form
include __DIR__ . '/simplesearchform.php';

// We only want software on this view, not websites
unset($repos[array_search('mozilla_org', $repos)]);
?>
<p class="page_description">Note that it’s not possible to distinguish between untranslated
strings and strings left blank on purpose.<br> For this reason the number of <em>Missing</em>
string reported on this page might not be completely accurate.</p>
<p class="page_description">Click on the column headers to order the table.</p>

$repo = (isset($_GET['repo']) && in_array($_GET['repo'], $repos))
? $_GET['repo']
: 'gaia';

$channel_selector = '';

foreach ($repos as $val) {
$ch = ($val == $repo) ? ' selected' : '';
$channel_selector .= "\t<option" . $ch . " value=" . $val . ">" . $repos_nice_names[$val] . "</option>\n";
}

// Using a callback with strlen() avoids filtering out numeric strings with a value of 0
$strings['en-US'][$repo] = array_filter(Utils::getRepoStrings('en-US', $repo), 'strlen');
$gaia_locales = Project::getRepositoryLocales($repo);

// We don't want en-US in the repos
if ($key = array_search('en-US', $gaia_locales)) {
unset($gaia_locales[$key]);
}

$string_count = [];

// Reference locale count
$count_reference = count($strings['en-US'][$repo]);

foreach ($gaia_locales as $val) {
$strings[$val][$repo] = array_filter(Utils::getRepoStrings($val, $repo), 'strlen');
$string_count[$val] = [
'total' => count($strings[$val][$repo]),
'missing' => count(array_diff_key($strings['en-US'][$repo], $strings[$val][$repo])),
'identical' => count(array_intersect_assoc($strings['en-US'][$repo], $strings[$val][$repo])),
];
unset($strings[$val][$repo]);
}

$json = [];
$table = '
<table id="showrepos_table">
<table id="showrepos_table" class="sortable">
<thead>
<tr class="column_headers">
<th>Locale</th>
Expand All @@ -52,64 +19,24 @@
<th>Translated</th>
<th>Identical</th>
<th>Completion</th>
<th>Status estimate</th>
<th class="sorttable_nosort">Status estimate</th>
</tr>
</thead>
<tbody>';

foreach ($string_count as $locale => $numbers) {
$completion = $count_reference - $numbers['identical'] - $numbers['missing'];

// Making sure we never divide by zero while computing percentage
$completion = $count_reference == 0 ? 0 : number_format($completion / $count_reference * 100);

if ($completion >= 99) {
$confidence = 'Highest';
} elseif ($completion >= 95) {
$confidence = 'High';
} elseif ($completion >= 90) {
$confidence = 'High';
} elseif ($completion >= 60) {
$confidence = 'In progress';
} elseif ($completion >= 50) {
$confidence = 'Low';
} elseif ($completion >= 30) {
$confidence = 'very Low';
} elseif ($completion >= 10) {
$confidence = 'Barely started';
} elseif ($completion >= 1) {
$confidence = 'just started';
} else {
$confidence = 'No localization';
<tbody>
<?php
foreach ($table_data as $locale => $stats) {
$translated = $stats['total'] - $stats['identical'];
echo "
<tr id=\"{$locale}\">
<th>{$locale}</th>
<td>{$stats['total']}</td>
<td>{$stats['missing']}</td>
<td>{$translated}</td>
<td>{$stats['identical']}</td>
<td sorttable_customkey=\"{$stats['completion']}\">{$stats['completion']} %</td>
<td>{$stats['confidence']}</td>
</tr>\n";
}

$json[$locale] = [
'total' => $numbers['total'],
'missing' => $numbers['missing'],
'translated' => ($numbers['total'] - $numbers['identical']),
'identical' => $numbers['identical'],
'completion' => $completion,
'confidence' => $confidence,
];

$table .=
"<tr id=\"{$locale}\">
<th>{$locale}</th>
<td>{$numbers['total']}</td>
<td>{$numbers['missing']}</td>"
. '<td>' . ($numbers['total'] - $numbers['identical']) . '</td>'
. "<td>{$numbers['identical']}</td>
<td>{$completion} %</td>
<td>{$confidence}</td>
</tr>";
}

$table .= "</tbody>\n</table>\n";

if (isset($_GET['json'])) {
include VIEWS . 'json.php';
} else {
// Include the common simple search form
include __DIR__ . '/simplesearchform.php';
echo $table;
}
?>
</tbody>
</table>
2 changes: 1 addition & 1 deletion app/views/templates/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

<?php if ($show_title == true): ?>
<h2 id="page_title"><?= $page_title ?></h2>
<h3 id="page_descrition"><?= $page_descr ?></h3>
<p class="page_description"><?= $page_descr ?></p>
<?php endif; ?>

<div id="pagecontent">
Expand Down
2 changes: 1 addition & 1 deletion web/style/changelog.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
margin: 0;
}

#changelog #page_descrition {
#changelog .page_description {
display: none;
}

Expand Down
7 changes: 5 additions & 2 deletions web/style/transvision.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ h3 {
padding-bottom: 0;
}

#page_descrition {
padding: 0;
.page_description {
font-size: 14px;
font-weight: normal;
margin: 5px auto 15px;
padding: 0;
text-align: center;
width: 80%;
}

#current {
Expand Down

0 comments on commit 9861250

Please sign in to comment.