Skip to content

Commit

Permalink
Added way to track "not to exceed" number of steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleMcGrew committed Oct 26, 2021
1 parent 4e877a1 commit 72dcdfb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
20 changes: 18 additions & 2 deletions import_export_batches/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from import_export_ctcl.controllers import CTCL_VOTER_INFO_URL
from import_export_vote_usa.controllers import VOTE_USA_VOTER_INFO_URL
import json
import math
from polling_location.models import PollingLocation, PollingLocationManager
from position.models import POSITION
import random
Expand Down Expand Up @@ -1583,7 +1584,6 @@ def batch_process_list_view(request):

batch_process_list = []


# Make sure 'which_marking' is one of the allowed Filter fields
if which_marking and which_marking not in ["pause_process", "unpause_process", None]:
messages.add_message(request, messages.ERROR,
Expand Down Expand Up @@ -1736,8 +1736,24 @@ def batch_process_list_view(request):
status += 'FAILED retrieve_all_offices_for_upcoming_election: ' + str(e) + ' '
success = False

# Add the processing "chunks" under each Batch Process
state_codes_map_point_counts_dict = {}
polling_location_manager = PollingLocationManager()
for batch_process in batch_process_list:
if batch_process.kind_of_process in [
RETRIEVE_BALLOT_ITEMS_FROM_POLLING_LOCATIONS, REFRESH_BALLOT_ITEMS_FROM_POLLING_LOCATIONS,
]:
state_code_lower_case = ''
if positive_value_exists(batch_process.state_code):
state_code_lower_case = batch_process.state_code.lower()
if state_code_lower_case in state_codes_map_point_counts_dict:
batch_process.polling_location_count = state_codes_map_point_counts_dict[state_code_lower_case]
batch_process.ballot_item_chunks_expected = int(math.ceil(batch_process.polling_location_count / 125))
else:
state_codes_map_point_counts_dict[state_code_lower_case] = \
polling_location_manager.fetch_polling_location_count(state_code=state_code_lower_case)
batch_process.polling_location_count = state_codes_map_point_counts_dict[state_code_lower_case]
batch_process.ballot_item_chunks_expected = int(math.ceil(batch_process.polling_location_count / 125))
# Add the processing "chunks" under each Batch Process
batch_process_ballot_item_chunk_list = []
batch_process_ballot_item_chunk_list_found = False
batch_process_analytics_chunk_list = []
Expand Down
16 changes: 16 additions & 0 deletions polling_location/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ def save(self, *args, **kwargs):

class PollingLocationManager(models.Manager):

def fetch_polling_location_count(
self,
state_code=''):
status = ''
try:
polling_location_queryset = PollingLocation.objects.using('readonly').all()
polling_location_queryset = polling_location_queryset.exclude(polling_location_deleted=True)
if positive_value_exists(state_code):
polling_location_queryset = polling_location_queryset.filter(state__iexact=state_code)
polling_location_count = polling_location_queryset.count()
except Exception as e:
status += 'FAILED fetch_polling_location_count: ' + str(e) + ' '
polling_location_count = 0

return polling_location_count

def update_or_create_polling_location(
self,
we_vote_id,
Expand Down
5 changes: 5 additions & 0 deletions templates/import_export_batches/batch_process_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% block title %}Batch Processes{% endblock %}

{% block content %}
{% load humanize %}

<h1>
Batch Processes{% if batch_process_list %} ({{ batch_process_list|length }}){% endif %}
Expand Down Expand Up @@ -307,6 +308,10 @@ <h1>
target="_blank">batch set list</a>)
(<a href="{% url 'import_export_batches:batch_process_log_entry_list' %}?batch_process_id={{ batch_process.id }}&google_civic_election_id={{ batch_process.google_civic_election_id }}&state_code={{ batch_process.state_code }}"
target="_blank">batch log</a>)
{% if batch_process.polling_location_count %}
<br />
Should not exceed {{ batch_process.ballot_item_chunks_expected|intcomma }} steps ({{ batch_process.polling_location_count|intcomma }} total map points)
{% endif %}
{% if batch_process.completion_summary or batch_process.analytics_date_as_integer %}
<br />
{% if batch_process.analytics_date_as_integer %}
Expand Down

0 comments on commit 72dcdfb

Please sign in to comment.