Skip to content

Commit

Permalink
Merge branch 'master' into bundleMod
Browse files Browse the repository at this point in the history
  • Loading branch information
FGlazov committed Apr 12, 2021
2 parents d4a6e56 + bf85d61 commit f5c5e8a
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 30 deletions.
9 changes: 6 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ Version 1.3

Version 1.3.1


- Upgrade to version 2.0.1 of enhancements.

Version 1.3.1
Version 1.3.2

- Upgrade to version 2.0.2 of enhancements.

Version 1.3.3.

- Upgrade to version 2.0.2 of enhacements
- Upgrade to version 2.0.3 of enhancements.
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ the last 10 tours. More details inside the Global Aircraft stats readme.
6. Inside your src/confi.ini, configure the Stats Enhancements mod. I.e. choose the modules you want to use with the
config parameter modules under [stats].

6. Run the update script in your /run folder after you're done with the above.
7. Run the update script in your /run folder after you're done with the above.


Support
Expand Down
28 changes: 28 additions & 0 deletions src/mod_rating_by_type/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-04-12 18:36
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('stats', '0035_score_ai_value'),
]

operations = [
migrations.CreateModel(
name='SortieAugmentation',
fields=[
('sortie', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='SortieAugmentation_MOD_SPLIT_RANKINGS', serialize=False, to='stats.Sortie')),
('cls', models.CharField(blank=True, choices=[('heavy', 'heavy'), ('medium', 'medium'), ('light', 'light'), ('placeholder', 'placeholder')], max_length=16)),
],
options={
'db_table': 'Sortie_MOD_SPLIT_RANKINGS',
},
),
]
Empty file.
24 changes: 24 additions & 0 deletions src/mod_rating_by_type/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models
from stats.models import Sortie


# Additional fields to Sortie objects used by this mod.
class SortieAugmentation(models.Model):
sortie = models.OneToOneField(Sortie, on_delete=models.PROTECT, primary_key=True,
related_name='SortieAugmentation_MOD_SPLIT_RANKINGS')

CLASSES = (
('heavy', 'heavy'),
('medium', 'medium'),
('light', 'light'),
('placeholder', 'placeholder')
)

# This class differs from the cls found in a Sortie object.
# Namely: Jabo flights are considred "medium", and P-38/Me-262 without bombs are considered "light"
# In all other cases, it should be equal to the one found in
cls = models.CharField(choices=CLASSES, max_length=16, blank=True)

class Meta:
# The long table name is to avoid any conflicts with new tables defined in the main branch of IL2 Stats.
db_table = "Sortie_MOD_SPLIT_RANKINGS"
13 changes: 13 additions & 0 deletions src/mod_rating_by_type/stats_whore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta
from stats.models import Sortie
from .variant_utils import is_jabo, is_fighter
from .models import SortieAugmentation

SORTIE_MIN_TIME = settings.SORTIE_MIN_TIME
SORTIE_DISCO_MIN_TIME = settings.SORTIE_DISCO_MIN_TIME
Expand Down Expand Up @@ -133,6 +134,18 @@ def create_new_sortie(mission, profile, player, sortie, sortie_aircraft_id):
is_ignored=is_ignored,
)

new_sortie.save()

cls = 'placeholder'
if is_fighter(new_sortie):
cls = 'light'
elif new_sortie.aircraft.cls == "aircraft_medium" or is_jabo(new_sortie):
cls = 'medium'
elif new_sortie.aircraft.cls == "aircraft_heavy":
cls = 'heavy'

SortieAugmentation(sortie=new_sortie, cls=cls).save()

return new_sortie


Expand Down
15 changes: 10 additions & 5 deletions src/mod_rating_by_type/variant_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
BOMB_VARIANT_WHITE_LIST = {'P-38J-25', 'Me 262 A', 'Bristol F2B (F.II)', 'Bristol F2B (F.III)', 'Halberstadt CL.II',
'Halberstadt CL.II 200hp'}
FIGHTER_WHITE_LIST = {'P-38J-25', 'Me 262 A'}

JABO_MODS = {'Ground attack modification', 'U17 strike modification'}


Expand All @@ -11,15 +10,21 @@ def is_jabo(sortie):
if sortie.aircraft.cls != 'aircraft_light' and sortie.aircraft.name_en not in BOMB_VARIANT_WHITE_LIST:
return False

for modification in sortie.modifications:
if 'bomb' in modification.lower() or 'rocket' in modification.lower():
return True
if modification in JABO_MODS:
for mod in sortie.modifications:
if __is_modification_jabo(mod):
return True

return False


def __is_modification_jabo(mod):
if 'bomb' in mod.lower() or 'rocket' in mod.lower():
return True
if mod in JABO_MODS:
return True
return False


def is_fighter(sortie):
if is_jabo(sortie):
return False
Expand Down
42 changes: 21 additions & 21 deletions src/mod_rating_by_type/views.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from datetime import timedelta

from django.conf import settings
from django.db.models import Sum, OuterRef, Subquery
from django.db.models import Sum, OuterRef, Subquery, Q
from django.http import Http404
from django.shortcuts import render, get_object_or_404, redirect
from django.utils import timezone
from mission_report.constants import Coalition

from stats.helpers import Paginator, get_sort_by, redirect_fix_url
from stats.models import (Player, Mission, PlayerMission, PlayerAircraft, Sortie, KillboardPvP,
Tour, LogEntry, Profile, Squad, Reward, PlayerOnline, VLife)
from stats import sortie_log
from stats.views import _get_rating_position, _get_squad
from stats.models import (Player, Mission, PlayerMission, PlayerAircraft, Sortie, Tour, Profile, Squad, PlayerOnline,
VLife)
from stats.views import *
from stats.views import _get_rating_position, _get_squad

from .bullets_types import translate_ammo_breakdown
from .config_modules import *
from .variant_utils import FIGHTER_WHITE_LIST

INACTIVE_PLAYER_DAYS = settings.INACTIVE_PLAYER_DAYS
ITEMS_PER_PAGE = 20
Expand Down Expand Up @@ -162,21 +162,25 @@ def pilot(request, profile_id, nickname=None):
})


def _top_24_queryset(tour_id, aircraft_cls=None):
def __top_24_pilots(tour_id, cls=None):
_queryset = (Sortie.objects
.exclude(score=0)
.filter(tour_id=tour_id,
is_disco=False,
player__type='pilot',
profile__is_hide=False,
date_start__gt=timezone.now() - timedelta(hours=24)))
if aircraft_cls:
_queryset = _queryset.filter(aircraft__cls=aircraft_cls)
return _queryset.values('player').annotate(sum_score=Sum('score'))

if cls:
aircraft_cls = 'aircraft_' + cls
_queryset = _queryset.filter(
(Q(SortieAugmentation_MOD_SPLIT_RANKINGS__cls=cls) # Expected case. E.g. recorded jabos as type 'medium'.

# The edge case, when this mod is freshly installed we haven't recorded type. So instead use aircraft type.
| (Q(aircraft__cls=aircraft_cls) & Q(SortieAugmentation_MOD_SPLIT_RANKINGS=None))))

def _top_pilots(tour_id, queryset):
top_24_score = queryset.order_by('-sum_score')[:10]
_queryset = _queryset.values('player').annotate(sum_score=Sum('score'))
top_24_score = _queryset.order_by('-sum_score')[:10]
top_24_pilots = Player.players.pilots(tour_id=tour_id).filter(id__in=[s['player'] for s in top_24_score])
top_24_pilots = {p.id: p for p in top_24_pilots}
top_24 = []
Expand All @@ -198,8 +202,7 @@ def main(request):
.exclude(score_streak_current=0)
.active(tour=request.tour).order_by('-score_streak_current')[:10])

top_24 = _top_pilots(tour_id=request.tour.id,
queryset=_top_24_queryset(tour_id=request.tour.id))
top_24 = __top_24_pilots(tour_id=request.tour.id)

if module_active(MODULE_SPLIT_RANKINGS):
top_streak_heavy = (Player.players.pilots(tour_id=request.tour.id)
Expand All @@ -211,12 +214,9 @@ def main(request):
top_streak_light = (Player.players.pilots(tour_id=request.tour.id)
.exclude(score_streak_current_light=0)
.active(tour=request.tour).order_by('-score_streak_current_light')[:10])
top_24_heavy = _top_pilots(tour_id=request.tour.id,
queryset=_top_24_queryset(tour_id=request.tour.id, aircraft_cls='aircraft_heavy'))
top_24_medium = _top_pilots(tour_id=request.tour.id,
queryset=_top_24_queryset(tour_id=request.tour.id, aircraft_cls='aircraft_medium'))
top_24_light = _top_pilots(tour_id=request.tour.id,
queryset=_top_24_queryset(tour_id=request.tour.id, aircraft_cls='aircraft_light'))
top_24_heavy = __top_24_pilots(tour_id=request.tour.id, cls='heavy')
top_24_medium = __top_24_pilots(tour_id=request.tour.id, cls='medium')
top_24_light = __top_24_pilots(tour_id=request.tour.id, cls='light')
else:
top_streak_heavy = None
top_streak_medium = None
Expand Down Expand Up @@ -446,7 +446,7 @@ def pilot_sortie(request, sortie_id):
return render(request, 'pilot_sortie.html', {
'player': sortie.player,
'sortie': sortie,
'score_dict': mission_score_dict or sortie.mission.score_dict,
'score_dict': mission_score_dict or sortie.mission.score_dict,
'ammo_breakdown': ammo_breakdown,
})

Expand Down

0 comments on commit f5c5e8a

Please sign in to comment.