<commit_before><?php
namespace Webdashboard;

$rss_status = <<<RSS
<p class="feed">
    <a href="?locale={$locale}&amp;rss">
    <img src="./assets/images/icon-rss-48x48.png" alt="rss"/>
    Subscribe to the RSS feed for your locale!
    </a>
</p>
<div id="locale_page_title">
    <a href="http://wiki.mozilla.org/L10n:Teams:{$locale}">{$locale}</a>
RSS;
if ($locamotion) {
    $rss_status .= '<img src="assets/images/locamotion.png" class="locamotion" />';
}
$rss_status .= '</div>';

$lang_files_status = '<h2 class="title_anchor" id="lang_status"><a href="#lang_status">#</a>State of your lang files <small>(data updated every 15 minutes)</small></h2>';

foreach ($lang_files as $site => $site_files) {
    $rows = '';
    $display_errors = false;

    foreach ($site_files as $file => $details) {
        // Determine critical status
        $critical = (isset($details['critical']) && $details['critical']) ? '<strong>Yes</strong>' : 'No';

        // Determine deadline status
        $deadline_class = '';
        if (isset($details['deadline'])) {
            $deadline_timestamp = (new \DateTime($details['deadline']))->getTimestamp();
            $deadline = date('F d', $deadline_timestamp);
            if ($deadline_timestamp < time()) {
                $deadline = date('F d Y', $deadline_timestamp);
                $deadline_class = 'deadline_overdue';
            }
        } else {
            $deadline = '-';
        }

        if ($details['data_source'] == 'lang') {
            // Standard .lang file
            $file_missing = $details['identical'] + $details['missing'];
            $file_errors = $details['errors'];
            if ($file_missing + $file_errors > 0) {
                // File has missing strings (identical or actually missing)
                $display_errors = true;
                $url = LANG_CHECKER . "?locale={$locale}#{$file}";
                if ($file_errors > 0) {
                    $error_display = "<a href='{$url}'>{$file_errors}</a>";
                } else {
                    $error_display = '-';
                }
                if ($file_missing > 0) {
                    $missing_display = "<a href='{$url}'>{$file_missing}</a>";
                } else {
                    $missing_display = '-';
                }
                $rows .= "  <tr>\n" .
                         "    <th class='main_column'><a href='{$url}'>{$file}</a></th>\n" .
                         "    <td>{$missing_display}</td>\n" .
                         "    <td>{$error_display}</td>\n" .
                         "    <td class='{$deadline_class}'>{$deadline}</td>\n" .
                         "    <td>{$critical}</td>\n" .
                         "  </tr>\n";
            }
        } else {
            // Raw file with only a generic status
            $url = LANG_CHECKER . "?locale={$locale}#{$site}";
            $cmp_status = $details['status'];
            $file_flags = isset($details['flags']) ? $details['flags'] : [];

            // We display a file only if it's untranslated or outdated, other cases
            // are displayed only if file is not optional
            $hide_file = true;

            if ($cmp_status == 'untranslated' || $cmp_status == 'outdated') {
                $hide_file = false;
            } elseif (($cmp_status == 'missing_locale' || $cmp_status == 'missing_reference') &&
                ! in_array('optional', $file_flags)) {
                // File is missing and it's not optional
                $hide_file = false;
            }

            if (! $hide_file) {
                // Display warnings only if the file is not optional
                $rows .= "  <tr>\n" .
                         "    <th class='main_column'><a href='{$url}'>{$file}</a></th>\n" .
                         "    <td><span class='raw_status raw_{$cmp_status}'>" . str_replace('_', ' ', $cmp_status) . "</span></td>" .
                         "    <td class='{$deadline_class}'>{$deadline}</td>\n" .
                         "    <td>{$critical}</td>\n" .
                         "  </tr>\n";
                $display_errors = true;
            }
        }
    }

    if ($display_errors) {
        /* The type of data source is identical for all files in a website.
         * Since I have errors, there's at least one file that I can use to
         * determine the data source type, no need to check if it exists.
         */
        $data_source_type = array_shift($site_files)['data_source'];

        if ($data_source_type == 'lang') {
            // Standard .lang file
            $lang_files_status .= "\n<table class='file_detail'>\n" .
                                  "  <tr>\n" .
                                  "    <th class='main_column'>{$site}</th>\n" .
                                  "    <th>Missing</th>\n" .
                                  "    <th>Errors</th>\n" .
                                  "    <th>Deadline</th>\n" .
                                  "    <th>Critical</th>\n" .
                                  "  </tr>\n" .
                                  $rows .
                                  "</table>\n";
        } else {
            // Raw file with only a generic status
            $lang_files_status .= "\n<table class='file_detail'>\n" .
                                  "  <tr>\n" .
                                  "    <th class='main_column'>{$site}</th>\n" .
                                  "    <th>Status</th>\n" .
                                  "    <th>Deadline</th>\n" .
                                  "    <th>Critical</th>\n" .
                                  "  </tr>\n" .
                                  $rows .
                                  "</table>\n";
        }
    } else {
        $lang_files_status .= "\n<table>\n" .
                              "  <tr>\n" .
                              "    <th class='main_column'>{$site}</th>\n" .
                              "    <th><span style='color:gray'>All Files translated</span></th>\n" .
                              "  </tr>\n" .
                              "</table>\n";
    }
}

if (isset($lang_files['www.mozilla.org'])) {
    $optin_url = LANG_CHECKER . "?action=optin&locale={$locale}";
    $lang_files_status .= "<p><small>Reminder: Your staging site for mozilla.org/{$locale}/ is " .
                          "<a href='https://www-dev.allizom.org/{$locale}'>www-dev.allizom.org/{$locale}/</a><br/>" .
                          "The list of opt-in pages for mozilla.org is available <a href='{$optin_url}'>here</a>.</small></p>";
}

if (count($lang_files) == 0) {
    $lang_files_status .= "<p>There are no files tracked for this locale at the moment.</p>";
}

ob_start();
echo '<h2 class="title_anchor" id="bugs"><a href="#bugs">#</a>Open bugs for your locale:</h2>';
echo '<ul>';

if (count($bugs) > 0) {
    foreach ($bugs as $bug_number => $bug_title) {
        echo "<li><a href='https://bugzilla.mozilla.org/show_bug.cgi?id={$bug_number}'>{$bug_number}: {$bug_title}</a></li>";
    }
} else {
    echo '<li>No bugs. Good job!</li>';
}

echo '</ul>';

$bugs_status = ob_get_contents();
ob_end_clean();

ob_start();

$weblocale = $locale;
if ($locale == 'es-ES') {
    // Use 'es' instead of 'es-ES' for web projects
    $weblocale = 'es';
}
echo "<h2 class=\"title_anchor\" id=\"web_projects\"><a href=\"#web_projects\">#</a>External Web Projects Status ({$weblocale})</h2>\n";
echo "<p>Hover your mouse on a cell in the <em>Status</em> column to display statistics or errors for a specific project.<br/>
         Data updated about every 5 hours. Last update: {$webprojects['metadata']['creation_date']}.</p>\n";
if (isset($webprojects['locales'][$weblocale])) {
    // Generate list of products for this locale and sort them by name
    $available_products = [];
    foreach (array_keys($webprojects['locales'][$weblocale]) as $product_code) {
        $available_products[$product_code] = $webprojects['locales'][$weblocale][$product_code]['name'];
    }
    asort($available_products);<commit_msg>Don't display instructions if locale has no web projects<commit_after><?php
namespace Webdashboard;

$rss_status = <<<RSS
<p class="feed">
    <a href="?locale={$locale}&amp;rss">
    <img src="./assets/images/icon-rss-48x48.png" alt="rss"/>
    Subscribe to the RSS feed for your locale!
    </a>
</p>
<div id="locale_page_title">
    <a href="http://wiki.mozilla.org/L10n:Teams:{$locale}">{$locale}</a>
RSS;
if ($locamotion) {
    $rss_status .= '<img src="assets/images/locamotion.png" class="locamotion" />';
}
$rss_status .= '</div>';

$lang_files_status = '<h2 class="title_anchor" id="lang_status"><a href="#lang_status">#</a>State of your lang files <small>(data updated every 15 minutes)</small></h2>';

foreach ($lang_files as $site => $site_files) {
    $rows = '';
    $display_errors = false;

    foreach ($site_files as $file => $details) {
        // Determine critical status
        $critical = (isset($details['critical']) && $details['critical']) ? '<strong>Yes</strong>' : 'No';

        // Determine deadline status
        $deadline_class = '';
        if (isset($details['deadline'])) {
            $deadline_timestamp = (new \DateTime($details['deadline']))->getTimestamp();
            $deadline = date('F d', $deadline_timestamp);
            if ($deadline_timestamp < time()) {
                $deadline = date('F d Y', $deadline_timestamp);
                $deadline_class = 'deadline_overdue';
            }
        } else {
            $deadline = '-';
        }

        if ($details['data_source'] == 'lang') {
            // Standard .lang file
            $file_missing = $details['identical'] + $details['missing'];
            $file_errors = $details['errors'];
            if ($file_missing + $file_errors > 0) {
                // File has missing strings (identical or actually missing)
                $display_errors = true;
                $url = LANG_CHECKER . "?locale={$locale}#{$file}";
                if ($file_errors > 0) {
                    $error_display = "<a href='{$url}'>{$file_errors}</a>";
                } else {
                    $error_display = '-';
                }
                if ($file_missing > 0) {
                    $missing_display = "<a href='{$url}'>{$file_missing}</a>";
                } else {
                    $missing_display = '-';
                }
                $rows .= "  <tr>\n" .
                         "    <th class='main_column'><a href='{$url}'>{$file}</a></th>\n" .
                         "    <td>{$missing_display}</td>\n" .
                         "    <td>{$error_display}</td>\n" .
                         "    <td class='{$deadline_class}'>{$deadline}</td>\n" .
                         "    <td>{$critical}</td>\n" .
                         "  </tr>\n";
            }
        } else {
            // Raw file with only a generic status
            $url = LANG_CHECKER . "?locale={$locale}#{$site}";
            $cmp_status = $details['status'];
            $file_flags = isset($details['flags']) ? $details['flags'] : [];

            // We display a file only if it's untranslated or outdated, other cases
            // are displayed only if file is not optional
            $hide_file = true;

            if ($cmp_status == 'untranslated' || $cmp_status == 'outdated') {
                $hide_file = false;
            } elseif (($cmp_status == 'missing_locale' || $cmp_status == 'missing_reference') &&
                ! in_array('optional', $file_flags)) {
                // File is missing and it's not optional
                $hide_file = false;
            }

            if (! $hide_file) {
                // Display warnings only if the file is not optional
                $rows .= "  <tr>\n" .
                         "    <th class='main_column'><a href='{$url}'>{$file}</a></th>\n" .
                         "    <td><span class='raw_status raw_{$cmp_status}'>" . str_replace('_', ' ', $cmp_status) . "</span></td>" .
                         "    <td class='{$deadline_class}'>{$deadline}</td>\n" .
                         "    <td>{$critical}</td>\n" .
                         "  </tr>\n";
                $display_errors = true;
            }
        }
    }

    if ($display_errors) {
        /* The type of data source is identical for all files in a website.
         * Since I have errors, there's at least one file that I can use to
         * determine the data source type, no need to check if it exists.
         */
        $data_source_type = array_shift($site_files)['data_source'];

        if ($data_source_type == 'lang') {
            // Standard .lang file
            $lang_files_status .= "\n<table class='file_detail'>\n" .
                                  "  <tr>\n" .
                                  "    <th class='main_column'>{$site}</th>\n" .
                                  "    <th>Missing</th>\n" .
                                  "    <th>Errors</th>\n" .
                                  "    <th>Deadline</th>\n" .
                                  "    <th>Critical</th>\n" .
                                  "  </tr>\n" .
                                  $rows .
                                  "</table>\n";
        } else {
            // Raw file with only a generic status
            $lang_files_status .= "\n<table class='file_detail'>\n" .
                                  "  <tr>\n" .
                                  "    <th class='main_column'>{$site}</th>\n" .
                                  "    <th>Status</th>\n" .
                                  "    <th>Deadline</th>\n" .
                                  "    <th>Critical</th>\n" .
                                  "  </tr>\n" .
                                  $rows .
                                  "</table>\n";
        }
    } else {
        $lang_files_status .= "\n<table>\n" .
                              "  <tr>\n" .
                              "    <th class='main_column'>{$site}</th>\n" .
                              "    <th><span style='color:gray'>All Files translated</span></th>\n" .
                              "  </tr>\n" .
                              "</table>\n";
    }
}

if (isset($lang_files['www.mozilla.org'])) {
    $optin_url = LANG_CHECKER . "?action=optin&locale={$locale}";
    $lang_files_status .= "<p><small>Reminder: Your staging site for mozilla.org/{$locale}/ is " .
                          "<a href='https://www-dev.allizom.org/{$locale}'>www-dev.allizom.org/{$locale}/</a><br/>" .
                          "The list of opt-in pages for mozilla.org is available <a href='{$optin_url}'>here</a>.</small></p>";
}

if (count($lang_files) == 0) {
    $lang_files_status .= "<p>There are no files tracked for this locale at the moment.</p>";
}

ob_start();
echo '<h2 class="title_anchor" id="bugs"><a href="#bugs">#</a>Open bugs for your locale:</h2>';
echo '<ul>';

if (count($bugs) > 0) {
    foreach ($bugs as $bug_number => $bug_title) {
        echo "<li><a href='https://bugzilla.mozilla.org/show_bug.cgi?id={$bug_number}'>{$bug_number}: {$bug_title}</a></li>";
    }
} else {
    echo '<li>No bugs. Good job!</li>';
}

echo '</ul>';

$bugs_status = ob_get_contents();
ob_end_clean();

ob_start();

$weblocale = $locale;
if ($locale == 'es-ES') {
    // Use 'es' instead of 'es-ES' for web projects
    $weblocale = 'es';
}
echo "<h2 class=\"title_anchor\" id=\"web_projects\"><a href=\"#web_projects\">#</a>External Web Projects Status ({$weblocale})</h2>\n";
if (isset($webprojects['locales'][$weblocale])) {
    echo "<p>Hover your mouse on a cell in the <em>Status</em> column to display statistics or errors for a specific project.<br/>
          <small>Data updated about every 3 hours. Last update: {$webprojects['metadata']['creation_date']}.</small></p>\n";
    // Generate list of products for this locale and sort them by name
    $available_products = [];
    foreach (array_keys($webprojects['locales'][$weblocale]) as $product_code) {
        $available_products[$product_code] = $webprojects['locales'][$weblocale][$product_code]['name'];
    }
    asort($available_products);
{'fraction_non_alphanumeric': 0.17175029388108642, 'fraction_numerical': 0.002474788096269257, 'mean_word_length': 1.6253045314276433, 'pattern_counts': {'":': 0, '<': 251, '<?xml version=': 0, '>': 257, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1826601', 'n_tokens_mistral': 4875, 'n_tokens_neox': 4665, 'n_words': 977}