From 60d357124cecf9b005cfd335e0503f440a82acaa Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Sat, 31 Mar 2018 10:55:10 +0200 Subject: [PATCH] Fix templatetag outdated after volumes/issues recontruction --- stats/templates/stats/statistics.html | 254 +++++++++++++------------- stats/templatetags/stats_extras.py | 10 +- 2 files changed, 133 insertions(+), 131 deletions(-) diff --git a/stats/templates/stats/statistics.html b/stats/templates/stats/statistics.html index 62cb8ec02..1e45058b4 100644 --- a/stats/templates/stats/statistics.html +++ b/stats/templates/stats/statistics.html @@ -21,141 +21,141 @@ <p>Clicking on a Journal/Volume/Issue gives aggregates for all publications in that object.</p> <ul> {% for journal in journals|dictsort:"doi_label" %} - <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label %}">{{ journal }}</a></li> - <ul> - {% for year in journal|journal_publication_years %} - <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label year=year %}">{{ year }}</a></li> - {% endfor %} - </ul> - <ul> -{% for volume in journal.volume_set.all|dictsort:"number" %} -<li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label volume_nr=volume.number %}">{{ volume }}</a></li> -<ul> - {% for issue in volume.issue_set.all|dictsort:"number" %} - <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label volume_nr=volume.number issue_nr=issue.number %}">{{ issue }}</a></li> - {% endfor %} -</ul> -{% endfor %} - </ul> + <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label %}">{{ journal }}</a></li> + <ul> + {% for year in journal|journal_publication_years %} + <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label year=year %}">{{ year }}</a></li> + {% endfor %} + </ul> + <ul> + {% for volume in journal.volumes.all|dictsort:"number" %} + <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label volume_nr=volume.number %}">{{ volume }}</a></li> + <ul> + {% for issue in volume.issues.all|dictsort:"number" %} + <li><a href="{% url 'stats:statistics' journal_doi_label=journal.doi_label volume_nr=volume.number issue_nr=issue.number %}">{{ issue }}</a></li> + {% endfor %} + </ul> + {% endfor %} + </ul> {% endfor %} </ul> {% if journal %} -<h2>Results:</h2> -<table class="table"> - <tr> - <th>DOI label</th> - {% if year %} - <th>Year</th> - <th>Nr submissions<br/>(distinct)</th> - <th>Nr submissions<br/>(including resubmissions)</th> - <th>Nr assignment failed</th> - <th>Nr accepted/<br/>published</th> - <th>Nr rejected</th> - <th>Nr withdrawn</th> - {% else %} - <th>Nr publications</th> - <th>Duration average</th> - <th>Citation rate (per paper per year)</th> - {% endif %} - </tr> - <tr> - {% if issue %} - <td>{{ issue.doi_label }}</td> - <td>{% nr_publications issue %}</td> - <td>{% avg_processing_duration issue as avg %}{{ avg|floatformat:2 }} days</td> - <td>{% citation_rate issue as cr %}{{ cr|floatformat:2 }}</td> - {% elif volume %} - <td>{{ volume.doi_label }}</td> - <td>{% nr_publications volume %}</td> - <td>{% avg_processing_duration volume as avg %}{{ avg|floatformat:2 }} days</td> - <td>{% citation_rate volume as cr %}{{ cr|floatformat:2 }}</td> - {% else %} - <td>{{ journal.doi_label }}</td> - {% if year %} - <td>{{ year }}</td> - <td>{{ submissions|submissions_count_distinct }}</td> - <td>{{ submissions|length }}</td> - <td>{{ submissions.assignment_failed.count }}</td> - <td>{{ submissions.accepted.count|add:submissions.published.count }}</td> - <td>{{ submissions.rejected.count }}</td> - <td>{{ submissions.withdrawn.count }}</td> - {% else %} - <td>{% nr_publications journal %}</td> - <td>{% avg_processing_duration journal as avg %}{{ avg|floatformat:2 }} days</td> - <td>{% citation_rate journal as cr %}{{ cr|floatformat:2 }}</td> - {% endif %} - {% endif %} - </tr> -</table> + <h2>Results:</h2> + <table class="table"> + <tr> + <th>DOI label</th> + {% if year %} + <th>Year</th> + <th>Nr submissions<br/>(distinct)</th> + <th>Nr submissions<br/>(including resubmissions)</th> + <th>Nr assignment failed</th> + <th>Nr accepted/<br/>published</th> + <th>Nr rejected</th> + <th>Nr withdrawn</th> + {% else %} + <th>Nr publications</th> + <th>Duration average</th> + <th>Citation rate (per paper per year)</th> + {% endif %} + </tr> + <tr> + {% if issue %} + <td>{{ issue.doi_label }}</td> + <td>{% nr_publications issue %}</td> + <td>{% avg_processing_duration issue as avg %}{{ avg|floatformat:2 }} days</td> + <td>{% citation_rate issue as cr %}{{ cr|floatformat:2 }}</td> + {% elif volume %} + <td>{{ volume.doi_label }}</td> + <td>{% nr_publications volume %}</td> + <td>{% avg_processing_duration volume as avg %}{{ avg|floatformat:2 }} days</td> + <td>{% citation_rate volume as cr %}{{ cr|floatformat:2 }}</td> + {% else %} + <td>{{ journal.doi_label }}</td> + {% if year %} + <td>{{ year }}</td> + <td>{{ submissions|submissions_count_distinct }}</td> + <td>{{ submissions|length }}</td> + <td>{{ submissions.assignment_failed.count }}</td> + <td>{{ submissions.accepted.count|add:submissions.published.count }}</td> + <td>{{ submissions.rejected.count }}</td> + <td>{{ submissions.withdrawn.count }}</td> + {% else %} + <td>{% nr_publications journal %}</td> + <td>{% avg_processing_duration journal as avg %}{{ avg|floatformat:2 }} days</td> + <td>{% citation_rate journal as cr %}{{ cr|floatformat:2 }}</td> + {% endif %} + {% endif %} + </tr> + </table> -<table class="table"> - <tr> - <th>DOI label</th> - <th colspan="3">Nr per Tier</th> - <th colspan="3">Citation rate (per paper per year)</th> - </tr> - <tr> - <th></th> - <th>I</th> - <th>II</th> - <th>IIII</th> - <th>I</th> - <th>II</th> - <th>IIII</th> - </tr> - <tr> - {% if issue %} - <td>{{ issue.doi_label }}</td> - <td>{% nr_publications issue tier=1 %}</td> - <td>{% nr_publications issue tier=2 %}</td> - <td>{% nr_publications issue tier=3 %}</td> - <td>{% citation_rate issue tier=1 as cr %}{{ cr|floatformat:2 }}</td> - <td>{% citation_rate issue tier=2 as cr %}{{ cr|floatformat:2 }}</td> - <td>{% citation_rate issue tier=3 as cr %}{{ cr|floatformat:2 }}</td> - {% elif volume %} - <td>{{ volume.doi_label }}</td> - <td>{% nr_publications volume tier=1 %}</td> - <td>{% nr_publications volume tier=2 %}</td> - <td>{% nr_publications volume tier=3 %}</td> - <td>{% citation_rate volume tier=1 as cr %}{{ cr|floatformat:2 }}</td> - <td>{% citation_rate volume tier=2 as cr %}{{ cr|floatformat:2 }}</td> - <td>{% citation_rate volume tier=3 as cr %}{{ cr|floatformat:2 }}</td> - {% else %} - <td>{{ journal.doi_label }}</td> - <td>{% nr_publications journal tier=1 %}</td> - <td>{% nr_publications journal tier=2 %}</td> - <td>{% nr_publications journal tier=3 %}</td> - <td>{% citation_rate journal tier=1 as cr %}{{ cr|floatformat:2 }}</td> - <td>{% citation_rate journal tier=2 as cr %}{{ cr|floatformat:2 }}</td> - <td>{% citation_rate journal tier=3 as cr %}{{ cr|floatformat:2 }}</td> - {% endif %} - </tr> -</table> + <table class="table"> + <tr> + <th>DOI label</th> + <th colspan="3">Nr per Tier</th> + <th colspan="3">Citation rate (per paper per year)</th> + </tr> + <tr> + <th></th> + <th>I</th> + <th>II</th> + <th>IIII</th> + <th>I</th> + <th>II</th> + <th>IIII</th> + </tr> + <tr> + {% if issue %} + <td>{{ issue.doi_label }}</td> + <td>{% nr_publications issue tier=1 %}</td> + <td>{% nr_publications issue tier=2 %}</td> + <td>{% nr_publications issue tier=3 %}</td> + <td>{% citation_rate issue tier=1 as cr %}{{ cr|floatformat:2 }}</td> + <td>{% citation_rate issue tier=2 as cr %}{{ cr|floatformat:2 }}</td> + <td>{% citation_rate issue tier=3 as cr %}{{ cr|floatformat:2 }}</td> + {% elif volume %} + <td>{{ volume.doi_label }}</td> + <td>{% nr_publications volume tier=1 %}</td> + <td>{% nr_publications volume tier=2 %}</td> + <td>{% nr_publications volume tier=3 %}</td> + <td>{% citation_rate volume tier=1 as cr %}{{ cr|floatformat:2 }}</td> + <td>{% citation_rate volume tier=2 as cr %}{{ cr|floatformat:2 }}</td> + <td>{% citation_rate volume tier=3 as cr %}{{ cr|floatformat:2 }}</td> + {% else %} + <td>{{ journal.doi_label }}</td> + <td>{% nr_publications journal tier=1 %}</td> + <td>{% nr_publications journal tier=2 %}</td> + <td>{% nr_publications journal tier=3 %}</td> + <td>{% citation_rate journal tier=1 as cr %}{{ cr|floatformat:2 }}</td> + <td>{% citation_rate journal tier=2 as cr %}{{ cr|floatformat:2 }}</td> + <td>{% citation_rate journal tier=3 as cr %}{{ cr|floatformat:2 }}</td> + {% endif %} + </tr> + </table> {% endif %} {% if year %} -<h2>Refereeing stats for {{ year }}</h2> -<table class="table"> - <tr> - <th>Nr refereeing<br/>invitations</th> - <th>Nr accepted</th> - <th>Nr declined</th> - <th>Nr pending</th> - <th>Nr reports<br/>obtained</th> - <th>Nr obtained<br/>(invited)</th> - <th>Nr obtained<br/>(contributed)</th> - </tr> - <tr> - <td>{{ nr_ref_inv }}</td> - <td>{{ nr_acc }} ({% widthratio nr_acc nr_ref_inv 100 %}%)</td> - <td>{{ nr_dec }} ({% widthratio nr_dec nr_ref_inv 100 %}%)</td> - <td>{{ nr_pen }} ({% widthratio nr_pen nr_ref_inv 100 %}%)</td> - <td>{{ nr_rep_obt }}</td> - <td>{{ nr_rep_obt_inv }} ({% widthratio nr_rep_obt_inv nr_rep_obt 100 %}%)</td> - <td>{{ nr_rep_obt_con }} ({% widthratio nr_rep_obt_con nr_rep_obt 100 %}%)</td> - </tr> -</table> + <h2>Refereeing stats for {{ year }}</h2> + <table class="table"> + <tr> + <th>Nr refereeing<br/>invitations</th> + <th>Nr accepted</th> + <th>Nr declined</th> + <th>Nr pending</th> + <th>Nr reports<br/>obtained</th> + <th>Nr obtained<br/>(invited)</th> + <th>Nr obtained<br/>(contributed)</th> + </tr> + <tr> + <td>{{ nr_ref_inv }}</td> + <td>{{ nr_acc }} ({% widthratio nr_acc nr_ref_inv 100 %}%)</td> + <td>{{ nr_dec }} ({% widthratio nr_dec nr_ref_inv 100 %}%)</td> + <td>{{ nr_pen }} ({% widthratio nr_pen nr_ref_inv 100 %}%)</td> + <td>{{ nr_rep_obt }}</td> + <td>{{ nr_rep_obt_inv }} ({% widthratio nr_rep_obt_inv nr_rep_obt 100 %}%)</td> + <td>{{ nr_rep_obt_con }} ({% widthratio nr_rep_obt_con nr_rep_obt 100 %}%)</td> + </tr> + </table> {% endif %} diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py index 398e779f9..7eb65db6a 100644 --- a/stats/templatetags/stats_extras.py +++ b/stats/templatetags/stats_extras.py @@ -33,8 +33,10 @@ def submissions_count_distinct(submissions): @register.filter(name='journal_publication_years') def journal_publication_years(journal): + """Return a sorted list of active years of the Journal.""" years = [] - for volume in journal.volume_set.all(): - if volume.until_date.year not in years: - years.append(volume.until_date.year) - return sorted(years) + if journal.has_volumes: + years = journal.volumes.dates('until_date', 'year') + else: + years = journal.publications.dates('publication_date', 'year') + return [x.year for x in years] -- GitLab