Skip to content

Commit

Permalink
Skip over capture sorties which cause error.
Browse files Browse the repository at this point in the history
  • Loading branch information
FGlazov committed Apr 10, 2022
1 parent c5cdd4c commit d408b46
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/mod_stats_by_aircraft/background_jobs/fix_captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from stats.models import Sortie
from ..aircraft_mod_models import AircraftBucket
from ..aircraft_stats_compute import get_sortie_type
from django.db.utils import DatabaseError


class FixCaptures(BackgroundJob):
Expand All @@ -18,29 +19,33 @@ def query_find_sorties(self, tour_cutoff):
.order_by('-tour__id'))

def compute_for_sortie(self, sortie):
if sortie.is_captured and sortie.is_dead:
# TODO: Refactor this "get all buckets code" into a util function.
buckets = [(AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type='NO_FILTER', player=None))[0],
(AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type='NO_FILTER', player=sortie.player))[0]]
filter_type = get_sortie_type(sortie)
if filter_type != 'NO_FILTER':
buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type=filter_type, player=None))[0])
buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type=filter_type, player=sortie.player))[0])

for bucket in buckets:
bucket.captures -= 1
bucket.update_derived_fields()
bucket.save()
try:
if sortie.is_captured and sortie.is_dead:
# TODO: Refactor this "get all buckets code" into a util function.
buckets = [(AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type='NO_FILTER', player=None))[0],
(AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type='NO_FILTER', player=sortie.player))[0]]
filter_type = get_sortie_type(sortie)
if filter_type != 'NO_FILTER':
buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type=filter_type, player=None))[0])
buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft,
filter_type=filter_type,
player=sortie.player))[0])

for bucket in buckets:
bucket.captures -= 1
bucket.update_derived_fields()
bucket.save()
except DatabaseError:
pass # Just ignore the sortie if it fails for some reason. Old data - not too important.

sortie.SortieAugmentation_MOD_STATS_BY_AIRCRAFT.fixed_captures = True
sortie.SortieAugmentation_MOD_STATS_BY_AIRCRAFT.save()

def log_update(self, to_compute):
return '[mod_stats_by_aircraft]: Fixing capture stats. {} sorties left to process.' .format(to_compute)
return '[mod_stats_by_aircraft]: Fixing capture stats. {} sorties left to process.'.format(to_compute)

def log_done(self):
return '[mod_stats_by_aircraft]: Completed fixing capture stats.'

0 comments on commit d408b46

Please sign in to comment.