[damned-lies] Uniform stats display in various pages
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Uniform stats display in various pages
- Date: Fri, 26 Aug 2011 22:30:44 +0000 (UTC)
commit 1669a495ed7d225f5e7a277beb8251143a111010
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Aug 26 22:13:05 2011 +0200
Uniform stats display in various pages
Also modify a bit the number display (Refs #657460)
media/css/main.css | 12 ++-
stats/models.py | 107 +++++++++++----------
stats/templatetags/stats_extras.py | 10 ++-
templates/languages/language_release_summary.html | 34 +++----
templates/release_detail.html | 27 ++----
templates/release_detail.xml | 12 +-
6 files changed, 99 insertions(+), 103 deletions(-)
---
diff --git a/media/css/main.css b/media/css/main.css
index bf3db11..988d48c 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -8,6 +8,13 @@ pre {
white-space: pre-wrap;
}
+pre.stats {
+ display: inline;
+ margin: 0;
+ white-space: pre;
+ font-size: 0.9em;
+}
+
#stats-table {
border-collapse: collapse;
}
@@ -54,7 +61,8 @@ table.stats {
}
.stats td.stats_numb {
- font-size: 85%;
+ padding-left: 1em;
+ text-align: left;
}
td.supported {
@@ -112,7 +120,7 @@ div.graph {
div.graphinline {
display: inline;
- top: -10px;
+ top: 4px;
}
div.translated {
diff --git a/stats/models.py b/stats/models.py
index b248179..5b87de3 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1018,43 +1018,45 @@ class Release(models.Model):
cursor = connection.cursor()
cursor.execute(query, (lang.id, self.id))
stats = {'id': self.id, 'name': self.name, 'description': _(self.description),
- 'uitrans': 0, 'uifuzzy': 0, 'uitotal': total_ui,
- 'uitrans_part': 0, 'uifuzzy_part': 0,
- 'doctrans': 0, 'docfuzzy': 0, 'doctotal': total_doc,
- 'uitransperc': 0, 'uifuzzyperc': 0, 'uiuntransperc': 0,
- 'uitransperc_part': 0, 'uifuzzyperc_part': 0, 'uiuntransperc_part': 0,
- 'doctransperc': 0, 'docfuzzyperc': 0, 'docuntransperc': 0}
+ 'ui': {'translated': 0, 'fuzzy': 0, 'total': total_ui,
+ 'translated_perc': 0, 'fuzzy_perc': 0, 'untranslated_perc': 0,
+ },
+ 'ui_part': {'translated': 0, 'fuzzy': 0, 'total': total_ui_part,
+ 'translated_perc': 0, 'fuzzy_perc': 0, 'untranslated_perc': 0,
+ },
+ 'doc': {'translated': 0, 'fuzzy': 0, 'total': total_doc,
+ 'translated_perc': 0, 'fuzzy_perc': 0, 'untranslated_perc': 0
+ },
+ }
for res in cursor.fetchall():
if res[0] == 'ui':
- stats['uitrans'] = res[1]
- stats['uifuzzy'] = res[2]
- stats['uitrans_part'] = res[3]
- stats['uifuzzy_part'] = res[4]
+ stats['ui']['translated'] = res[1]
+ stats['ui']['fuzzy'] = res[2]
+ stats['ui_part']['translated'] = res[3]
+ stats['ui_part']['fuzzy'] = res[4]
if res[0] == 'doc':
- stats['doctrans'] = res[1]
- stats['docfuzzy'] = res[2]
- stats['uitotal_part'] = total_ui_part
- stats['uiuntrans'] = total_ui - (stats['uitrans'] + stats['uifuzzy'])
- stats['uiuntrans_part'] = total_ui_part - (stats['uitrans_part'] + stats['uifuzzy_part'])
+ stats['doc']['translated'] = res[1]
+ stats['doc']['fuzzy'] = res[2]
+ stats['ui']['untranslated'] = total_ui - (stats['ui']['translated'] + stats['ui']['fuzzy'])
+ stats['ui_part']['untranslated'] = total_ui_part - (stats['ui_part']['translated'] + stats['ui_part']['fuzzy'])
if total_ui > 0:
- stats['uitransperc'] = int(100*stats['uitrans']/total_ui)
- stats['uifuzzyperc'] = int(100*stats['uifuzzy']/total_ui)
- stats['uiuntransperc'] = int(100*stats['uiuntrans']/total_ui)
+ stats['ui']['translated_perc'] = int(100*stats['ui']['translated']/total_ui)
+ stats['ui']['fuzzy_perc'] = int(100*stats['ui']['fuzzy']/total_ui)
+ stats['ui']['untranslated_perc'] = int(100*stats['ui']['untranslated']/total_ui)
if total_ui_part > 0:
- stats['uitransperc_part'] = int(100*stats['uitrans_part']/total_ui_part)
- stats['uifuzzyperc_part'] = int(100*stats['uifuzzy_part']/total_ui_part)
- stats['uiuntransperc_part'] = int(100*stats['uiuntrans_part']/total_ui_part)
- stats['docuntrans'] = total_doc - (stats['doctrans'] + stats['docfuzzy'])
+ stats['ui_part']['translated_perc'] = int(100*stats['ui_part']['translated']/total_ui_part)
+ stats['ui_part']['fuzzy_perc'] = int(100*stats['ui_part']['fuzzy']/total_ui_part)
+ stats['ui_part']['untranslated_perc'] = int(100*stats['ui_part']['untranslated']/total_ui_part)
+ stats['doc']['untranslated'] = total_doc - (stats['doc']['translated'] + stats['doc']['fuzzy'])
if total_doc > 0:
- stats['doctransperc'] = int(100*stats['doctrans']/total_doc)
- stats['docfuzzyperc'] = int(100*stats['docfuzzy']/total_doc)
- stats['docuntransperc'] = int(100*stats['docuntrans']/total_doc)
+ stats['doc']['translated_perc'] = int(100*stats['doc']['translated']/total_doc)
+ stats['doc']['fuzzy_perc'] = int(100*stats['doc']['fuzzy']/total_doc)
+ stats['doc']['untranslated_perc'] = int(100*stats['doc']['untranslated']/total_doc)
return stats
def get_global_stats(self):
""" Get statistics for all languages in a release, grouped by language
- Returns a sorted list: (language, doc_trans, doc_fuzzy,
- doc_untrans, ui_trans, ui_fuzzy, ui_untrans) """
+ Returns a sorted list: (language name and locale, ui, ui-part and doc stats dictionaries) """
query = """
SELECT MIN(lang.name),
@@ -1091,33 +1093,36 @@ class Release(models.Model):
# Initialize stats dict
stats[locale] = {
'lang_name': lang_name, 'lang_locale': locale,
- 'doc_trans': 0, 'doc_fuzzy': 0, 'doc_untrans': total_docstrings,
- 'doc_percent': 0, 'doc_percentfuzzy': 0, 'doc_percentuntrans': 100,
- 'ui_trans': 0, 'ui_fuzzy': 0, 'ui_untrans': total_uistrings,
- 'ui_percent': 0, 'ui_percentfuzzy': 0, 'ui_percentuntrans': 100}
+ 'ui' : {'translated': 0, 'fuzzy': 0, 'untranslated': total_uistrings,
+ 'translated_perc': 0, 'fuzzy_perc': 0, 'untranslated_perc': 100},
+ 'ui_part' : {'translated': 0, 'fuzzy': 0, 'untranslated': total_uistrings_part[locale],
+ 'translated_perc': 0, 'fuzzy_perc': 0, 'untranslated_perc': 100},
+ 'doc': {'translated': 0, 'fuzzy': 0, 'untranslated': total_docstrings,
+ 'translated_perc': 0, 'fuzzy_perc': 0, 'untranslated_perc': 100,},
+ }
if dtype == 'doc':
- stats[locale]['doc_trans'] = trans
- stats[locale]['doc_fuzzy'] = fuzzy
- stats[locale]['doc_untrans'] = total_docstrings - (trans + fuzzy)
+ stats[locale]['doc']['translated'] = trans
+ stats[locale]['doc']['fuzzy'] = fuzzy
+ stats[locale]['doc']['untranslated'] = total_docstrings - (trans + fuzzy)
if total_docstrings > 0:
- stats[locale]['doc_percent'] = int(100*trans/total_docstrings)
- stats[locale]['doc_percentfuzzy'] = int(100*fuzzy/total_docstrings)
- stats[locale]['doc_percentuntrans'] = int(100*stats[locale]['doc_untrans']/total_docstrings)
+ stats[locale]['doc']['translated_perc'] = int(100*trans/total_docstrings)
+ stats[locale]['doc']['fuzzy_perc'] = int(100*fuzzy/total_docstrings)
+ stats[locale]['doc']['untranslated_perc'] = int(100*stats[locale]['doc']['untranslated']/total_docstrings)
if dtype == 'ui':
- stats[locale]['ui_trans'] = trans
- stats[locale]['ui_fuzzy'] = fuzzy
- stats[locale]['ui_untrans'] = total_uistrings - (trans + fuzzy)
- stats[locale]['ui_trans_part'] = trans_p
- stats[locale]['ui_fuzzy_part'] = fuzzy_p
- stats[locale]['ui_untrans_part'] = total_uistrings_part[locale] - (trans_p + fuzzy_p)
+ stats[locale]['ui']['translated'] = trans
+ stats[locale]['ui']['fuzzy'] = fuzzy
+ stats[locale]['ui']['untranslated'] = total_uistrings - (trans + fuzzy)
+ stats[locale]['ui_part']['translated'] = trans_p
+ stats[locale]['ui_part']['fuzzy'] = fuzzy_p
+ stats[locale]['ui_part']['untranslated'] = total_uistrings_part[locale] - (trans_p + fuzzy_p)
if total_uistrings > 0:
- stats[locale]['ui_percent'] = int(100*trans/total_uistrings)
- stats[locale]['ui_percentfuzzy'] = int(100*fuzzy/total_uistrings)
- stats[locale]['ui_percentuntrans'] = int(100*stats[locale]['ui_untrans']/total_uistrings)
+ stats[locale]['ui']['translated_perc'] = int(100*trans/total_uistrings)
+ stats[locale]['ui']['fuzzy_perc'] = int(100*fuzzy/total_uistrings)
+ stats[locale]['ui']['untranslated_perc'] = int(100*stats[locale]['ui']['untranslated']/total_uistrings)
if total_uistrings_part.get(locale, 0) > 0:
- stats[locale]['ui_percent_part'] = int(100*trans_p/total_uistrings_part[locale])
- stats[locale]['ui_percentfuzzy_part'] = int(100*fuzzy_p/total_uistrings_part[locale])
- stats[locale]['ui_percentuntrans_part'] = int(100*stats[locale]['ui_untrans_part']/total_uistrings_part[locale])
+ stats[locale]['ui_part']['translated_perc'] = int(100*trans_p/total_uistrings_part[locale])
+ stats[locale]['ui_part']['fuzzy_perc'] = int(100*fuzzy_p/total_uistrings_part[locale])
+ stats[locale]['ui_part']['untranslated_perc'] = int(100*stats[locale]['ui_part']['untranslated']/total_uistrings_part[locale])
cursor.close()
results = stats.values()
@@ -1125,9 +1130,9 @@ class Release(models.Model):
return results
def compare_stats(self, a, b):
- res = cmp(b['ui_trans'], a['ui_trans'])
+ res = cmp(b['ui']['translated'], a['ui']['translated'])
if not res:
- res = cmp(b['doc_trans'], a['doc_trans'])
+ res = cmp(b['doc']['translated'], a['doc']['translated'])
if not res:
res = cmp(b['lang_name'], a['lang_name'])
return res
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index e93dc07..b3b40d9 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -56,8 +56,10 @@ def num_stats(stat, scope='full'):
stats['prc'] = stat.tr_percentage()
else:
stats = stat
+ if 'translated_perc' in stats:
+ stats['prc'] = stats['translated_perc']
if 'prc' in stats:
- model = "%(prc)s%% (%(translated)s/%(fuzzy)s/%(untranslated)s)"
+ model = '<pre class="stats"><b>%(prc)3s%%</b> (%(translated)s/%(fuzzy)s/%(untranslated)s)</pre>'
else:
model = "(%(translated)s/%(fuzzy)s/%(untranslated)s)"
return mark_safe(model % stats)
@@ -65,10 +67,12 @@ def num_stats(stat, scope='full'):
@register.filter
def vis_stats(stat, scope='full'):
""" Produce visual stats with green/red bar """
- if isinstance(stat, PoFile):
+ if isinstance(stat, (Statistics, FakeLangStatistics, FakeSummaryStatistics)):
+ trans, fuzzy, untrans = stat.tr_percentage(scope), stat.fu_percentage(scope), stat.un_percentage(scope)
+ elif isinstance(stat, PoFile):
trans, fuzzy, untrans = stat.tr_percentage(), stat.fu_percentage(), stat.un_percentage()
else:
- trans, fuzzy, untrans = stat.tr_percentage(scope), stat.fu_percentage(scope), stat.un_percentage(scope)
+ trans, fuzzy, untrans = stat['translated_perc'], stat['fuzzy_perc'], stat['untranslated_perc']
return mark_safe("""
<div class="translated" style="width: %(trans)spx;"></div>
<div class="fuzzy" style="%(dir)s:%(trans)spx; width:%(fuzzy)spx;"></div>
diff --git a/templates/languages/language_release_summary.html b/templates/languages/language_release_summary.html
index eb8e484..86442ff 100644
--- a/templates/languages/language_release_summary.html
+++ b/templates/languages/language_release_summary.html
@@ -1,4 +1,4 @@
-{% load i18n %}
+{% load i18n stats_extras %}
{% comment %}
Following variables should be set:
lang : current language
@@ -22,31 +22,21 @@ Following variables should be set:
</td>
<td class="stats_numb"><a href="{% url language_release lang.locale,stat.name,"ui" %}">
- {{ stat.uitransperc }}% ({{ stat.uitrans }}/{{ stat.uifuzzy }}/{{ stat.uiuntrans }})</a>
+ {{ stat.ui|num_stats }}</a>
</td>
- <td style="width: 108px; text-align: center;"><div class="graph">
- <div class="translated" style="width:{{ stat.uitransperc }}px;"></div>
- <div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stat.uitransperc }}px; width:{{ stat.uifuzzyperc }}px;"></div>
- {% with stat.uitransperc|add:stat.uifuzzyperc as upos %}
- <div class="untranslated" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ upos }}px; width:{{ stat.uiuntransperc }}px;"></div>
- {% endwith %}
- </div>
+ <td style="width: 108px; text-align: center;">
+ <div class="graph">{{ stat.ui|vis_stats }}</div>
</td>
<td class="stats_numb"><a href="{% url language_release lang.locale,stat.name,"ui-part" %}">
- {{ stat.uitransperc_part }}% ({{ stat.uitrans_part }}/{{ stat.uifuzzy_part }}/{{ stat.uiuntrans_part }})</a>
+ {{ stat.ui_part|num_stats }}</a>
</td>
- {% if stat.doctotal %}
+ {% if stat.doc.total %}
<td class="stats_numb"><a href="{% url language_release lang.locale,stat.name,"doc" %}">
- {{ stat.doctransperc }}% ({{ stat.doctrans }}/{{ stat.docfuzzy }}/{{ stat.docuntrans }})</a>
+ {{ stat.doc|num_stats }}</a>
</td>
- <td style="width: 108px; text-align: center;"><div class="graph">
- <div class="translated" style="width:{{ stat.doctransperc }}px;"></div>
- <div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stat.doctransperc }}px; width:{{ stat.docfuzzyperc }}px;"></div>
- {% with stat.doctransperc|add:stat.docfuzzyperc as upos %}
- <div class="untranslated" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ upos }}px; width:{{ stat.docuntransperc }}px;"></div>
- {% endwith %}
- </div>
+ <td style="width: 108px; text-align: center;">
+ <div class="graph">{{ stat.doc|vis_stats }}</div>
</td>
{% else %}
<td>-</td><td></td>
@@ -54,8 +44,8 @@ Following variables should be set:
</tr>
{% endfor %}
{% if show_all_modules_line %}
- <tr><td></td><td><a href="{% url language_all lang.locale,"ui" %}">{% trans "All modules" %}</a></td>
- <td></td><td><a href="{% url language_all lang.locale,"ui-part" %}">{% trans "All modules" %}</a></td>
- <td><a href="{% url language_all lang.locale,"doc" %}">{% trans "All modules" %}</a></td><td></td></tr>
+ <tr style="border-top: 1px solid gray;"><td></td><td class="stats_numb"><a href="{% url language_all lang.locale,"ui" %}">{% trans "All modules" %}</a></td>
+ <td></td><td class="stats_numb"><a href="{% url language_all lang.locale,"ui-part" %}">{% trans "All modules" %}</a></td>
+ <td class="stats_numb"><a href="{% url language_all lang.locale,"doc" %}">{% trans "All modules" %}</a></td><td></td></tr>
{% endif %}
</table>
diff --git a/templates/release_detail.html b/templates/release_detail.html
index 5d87183..1b3cc1f 100644
--- a/templates/release_detail.html
+++ b/templates/release_detail.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% load i18n %}
+{% load i18n stats_extras %}
{% block title %} {% trans release.description %} {% endblock %}
@@ -40,36 +40,25 @@
</td>
<td class="stats_numb"><a href="{% url language_release lstats.lang_locale release.name "ui" %}">
- {{ lstats.ui_percent }}% ({{ lstats.ui_trans }}/{{ lstats.ui_fuzzy }}/{{ lstats.ui_untrans }})</a>
+ {{ lstats.ui|num_stats }}</a>
</td>
- <td style="width: 108px; text-align: center;"><div class="graph">
- <div class="translated" style="width: {{ lstats.ui_percent }}px;"></div>
- <div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ lstats.ui_percent }}px; width:{{ lstats.ui_percentfuzzy }}px;"></div>
- {% with lstats.ui_percent|add:lstats.ui_percentfuzzy as upos %}
- <div class="untranslated" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ upos }}px; width: {{ lstats.ui_percentuntrans }}px;"></div>
- {% endwith %}
- </div>
+ <td style="width: 108px; text-align: center;">
+ <div class="graph">{{ lstats.ui|vis_stats }}</div>
</td>
<td class="stats_numb"><a href="{% url language_release lstats.lang_locale release.name "ui-part" %}">
- {{ lstats.ui_percent_part }}% ({{ lstats.ui_trans_part }}/{{ lstats.ui_fuzzy_part }}/{{ lstats.ui_untrans_part }})</a>
+ {{ lstats.ui_part|num_stats }}</a>
</td>
- {% if lstats.doc_trans|add:lstats.doc_fuzzy != "0" %}
+ {% if lstats.doc.translated|add:lstats.doc.fuzzy != "0" %}
<td class="stats_numb"><a href="{% url language_release lstats.lang_locale release.name "doc" %}">
- {{ lstats.doc_percent }}% ({{ lstats.doc_trans }}/{{ lstats.doc_fuzzy }}/{{ lstats.doc_untrans }})</a>
+ {{ lstats.doc|num_stats }}</a>
</td>
{% else %}
<td>-</td>
{% endif %}
<td style="width: 108px; text-align: center;">
- <div class="graph">
- <div class="translated" style="width: {{ lstats.doc_percent }}px;"></div>
- <div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ lstats.doc_percent }}px; width:{{ lstats.doc_percentfuzzy }}px;"></div>
- {% with lstats.doc_percent|add:lstats.doc_percentfuzzy as upos %}
- <div class="untranslated" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ upos }}px; width: {{ lstats.doc_percentuntrans }}px;"></div>
- {% endwith %}
- </div>
+ <div class="graph">{{ lstats.doc|vis_stats }}</div>
</td>
</tr>
diff --git a/templates/release_detail.xml b/templates/release_detail.xml
index 196d784..07550d4 100644
--- a/templates/release_detail.xml
+++ b/templates/release_detail.xml
@@ -2,12 +2,12 @@
{% for stat in release.get_global_stats %}
<language id="{{ stat.lang_locale }}">
<name>{{ stat.lang_name }}</name>
- <ui_translated>{{ stat.ui_trans }}</ui_translated>
- <ui_fuzzy>{{ stat.ui_fuzzy }}</ui_fuzzy>
- <ui_untranslated>{{ stat.ui_untrans }}</ui_untranslated>
- <doc_translated>{{ stat.doc_trans }}</doc_translated>
- <doc_fuzzy>{{ stat.doc_fuzzy }}</doc_fuzzy>
- <doc_untranslated>{{ stat.doc_untrans }}</doc_untranslated>
+ <ui_translated>{{ stat.ui.translated }}</ui_translated>
+ <ui_fuzzy>{{ stat.ui.fuzzy }}</ui_fuzzy>
+ <ui_untranslated>{{ stat.ui.untranslated }}</ui_untranslated>
+ <doc_translated>{{ stat.doc.translated }}</doc_translated>
+ <doc_fuzzy>{{ stat.doc.fuzzy }}</doc_fuzzy>
+ <doc_untranslated>{{ stat.doc.untranslated }}</doc_untranslated>
</language>
{% endfor %}
</release>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]