Skip to content

Commit

Permalink
/numbers - Remove unhelpful comparisons with earlier elections
Browse files Browse the repository at this point in the history
These comparisons were introduced when we just had the 2010 and 2015
UK elections on the site. Unfortunately, the code doesn't work now that
there are also local election and by-elections in the database. It's
better to just remove this feature than to present bizarre comparisons
to users.  The implementation would need to be completely rethought,
and that's very low priority compared to the other things we're trying
to get done in time for the 2017 General Election.

This is an alternative to fixing the problems described in #106
  • Loading branch information
mhl committed Apr 27, 2017
1 parent 87f8ff1 commit 721655b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 105 deletions.
31 changes: 0 additions & 31 deletions cached_counts/templates/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,6 @@ <h4>{% blocktrans %}Statistics for the {{ election_name }}{% endblocktrans %}</h
<li><a href="{% url "parties_counts" election=election.id %}">{% trans "Candidates per party" %}</a></li>
<li><a href="{% url "constituencies-unlocked" election=election.id %}">{% trans "See progress towards locking all posts" %}</a></li>
</ul>
{% if election.prior_elections %}
{% for prior_election in election.prior_elections %}
{% with prior_election_name=prior_election.name %}
<div "statistics-compared-to-prior-election">
<h5>{% blocktrans %}Statistics compared to the {{ prior_election_name }}{% endblocktrans %}</h5>
<ul>
<li>{% blocktrans %}Total candidates in {{ prior_election_name }}:{% endblocktrans %}
{{ prior_election.total }}
</li>
<li>{% blocktrans %}Percentage ({{ election_name }} / {{ prior_election_name }}):{% endblocktrans %}
{{ prior_election.percentage|floatformat }}%
</li>
<li>{% blocktrans %}New candidates compared to the {{ prior_election_name }}:{% endblocktrans %}
{{ prior_election.new_candidates|intcomma }}
</li>
<li>{% blocktrans %}Candidates standing again from the {{ prior_election_name }}:{% endblocktrans %}
{{ prior_election.standing_again |intcomma }}
</li>
<li>{% blocktrans trimmed %}Candidates standing again from the {{ prior_election_name }}
for the same party:{% endblocktrans %}
{{ prior_election.standing_again_same_party|intcomma }}
</li>
<li>{% blocktrans trimmed %}Candidates standing again from the {{ prior_election_name }}
for a different party:{% endblocktrans %}
{{ prior_election.standing_again_different_party |intcomma }}
</li>
</ul>
</div>
{% endwith %}
{% endfor %}
{% endif %}
{% endwith %}
</div>
{% endfor %}
Expand Down
10 changes: 0 additions & 10 deletions cached_counts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ def test_reports_top_page_json(self):
"html_id": "2015",
"id": "2015",
"name": "2015 General Election",
"prior_elections": [
{
"name": "2010 General Election",
"new_candidates": 16,
"percentage": 900.0,
"standing_again": 2,
"standing_again_different_party": 1,
"standing_again_same_party": 1
}
],
"total": 18
}
],
Expand Down
64 changes: 0 additions & 64 deletions cached_counts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,6 @@
from .models import get_attention_needed_posts


def get_prior_election_data(
total_current, current_election,
total_prior, prior_election
):
# Find all those people who are standing in both elections:
persons_standing_again = list(Person.objects \
.filter(memberships__extra__election=current_election) \
.filter(memberships__extra__election=prior_election) \
.prefetch_related('memberships', 'memberships__extra')
)
# Now see how many are standing for the same party in both:
standing_again = len(persons_standing_again)
new_candidates = total_current - standing_again
standing_again_same_party = 0
for p in persons_standing_again:
current_party = None
prior_party = None
for m in p.memberships.all():
try:
extra = m.extra
if extra.election_id == current_election.id:
current_party = m.on_behalf_of_id
elif extra.election_id == prior_election.id:
prior_party = m.on_behalf_of_id
except MembershipExtra.DoesNotExist:
# We need this because some memberships may not have
# an extra.
pass
if current_party == prior_party:
standing_again_same_party += 1
standing_again_different_party = \
standing_again - standing_again_same_party
if total_prior:
percentage = 100 * float(total_current) / total_prior
else:
percentage = 0

return {
'name': prior_election.name,
'percentage': percentage,
'new_candidates': new_candidates,
'standing_again': standing_again,
'standing_again_different_party': standing_again_different_party,
'standing_again_same_party': standing_again_same_party,
}


def get_counts(for_json=True):
election_id_to_candidates = {
d['extra__election']: d['count']
Expand All @@ -72,14 +25,6 @@ def get_counts(for_json=True):
.annotate(count=Count('extra__election'))
}
grouped_elections = Election.group_and_order_elections(for_json=for_json)
past_elections = [
election_data['election']
for era_data in grouped_elections
for date, elections in era_data['dates'].items()
for role_data in elections
for election_data in role_data['elections']
if not era_data['current']
]
for era_data in grouped_elections:
for date, elections in era_data['dates'].items():
for role_data in elections:
Expand All @@ -92,15 +37,6 @@ def get_counts(for_json=True):
'name': e.name,
'total': total,
}
if era_data['current']:
election_counts['prior_elections'] = [
get_prior_election_data(
total, e,
election_id_to_candidates.get(pe.id, 0), pe
)
for pe in past_elections
if pe.for_post_role == e.for_post_role
]
election_data.update(election_counts)
del election_data['election']
return grouped_elections
Expand Down

0 comments on commit 721655b

Please sign in to comment.