Skip to content

Commit

Permalink
Added new era store models
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightara committed Sep 17, 2019
1 parent 95620f4 commit 5de742f
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 42 deletions.
90 changes: 90 additions & 0 deletions raidar/migrations/0048_new_era_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Generated by Django 2.2.3 on 2019-09-17 08:34

import analyser.analyser
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('raidar', '0047_remove_userprofile_portrait_url'),
]

operations = [
migrations.CreateModel(
name='SquadStats',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
options={
'db_table': 'raidar_stats_squad',
},
),
migrations.AlterField(
model_name='participation',
name='elite',
field=models.PositiveSmallIntegerField(choices=[(-1, 'All'), (analyser.analyser.Elite(0), 'Core'), (analyser.analyser.Elite(1), 'Heart of Thorns'), (analyser.analyser.Elite(2), 'Path of Fire')], db_index=True),
),
migrations.AlterField(
model_name='participation',
name='profession',
field=models.PositiveSmallIntegerField(choices=[(-1, 'All'), (analyser.analyser.Profession(1), 'Guardian'), (analyser.analyser.Profession(2), 'Warrior'), (analyser.analyser.Profession(3), 'Engineer'), (analyser.analyser.Profession(4), 'Ranger'), (analyser.analyser.Profession(5), 'Thief'), (analyser.analyser.Profession(6), 'Elementalist'), (analyser.analyser.Profession(7), 'Mesmer'), (analyser.analyser.Profession(8), 'Necromancer'), (analyser.analyser.Profession(9), 'Revenant')], db_index=True),
),
migrations.AddConstraint(
model_name='encountermechanic',
constraint=models.UniqueConstraint(fields=('encounter_data', 'phase', 'source', 'name'), name='enc_mech_unique'),
),
migrations.CreateModel(
name='BuildStats',
fields=[
('squadstats_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='raidar.SquadStats')),
('archetype', models.PositiveSmallIntegerField(choices=[(analyser.analyser.Archetype(1), 'Power'), (analyser.analyser.Archetype(2), 'Condi'), (analyser.analyser.Archetype(3), 'Tank'), (analyser.analyser.Archetype(4), 'Heal'), (analyser.analyser.Archetype(5), 'Support')], db_index=True)),
('profession', models.PositiveSmallIntegerField(choices=[(-1, 'All'), (analyser.analyser.Profession(1), 'Guardian'), (analyser.analyser.Profession(2), 'Warrior'), (analyser.analyser.Profession(3), 'Engineer'), (analyser.analyser.Profession(4), 'Ranger'), (analyser.analyser.Profession(5), 'Thief'), (analyser.analyser.Profession(6), 'Elementalist'), (analyser.analyser.Profession(7), 'Mesmer'), (analyser.analyser.Profession(8), 'Necromancer'), (analyser.analyser.Profession(9), 'Revenant')], db_index=True)),
('elite', models.PositiveSmallIntegerField(choices=[(-1, 'All'), (analyser.analyser.Elite(0), 'Core'), (analyser.analyser.Elite(1), 'Heart of Thorns'), (analyser.analyser.Elite(2), 'Path of Fire')], db_index=True)),
],
options={
'db_table': 'raidar_stats_build',
},
bases=('raidar.squadstats',),
),
migrations.AddField(
model_name='squadstats',
name='area',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='raidar.Area'),
),
migrations.AddField(
model_name='squadstats',
name='era',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='raidar.Era'),
),
migrations.CreateModel(
name='UserStats',
fields=[
('buildstats_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='raidar.BuildStats')),
],
options={
'db_table': 'raidar_stats_user',
},
bases=('raidar.buildstats',),
),
migrations.AddConstraint(
model_name='squadstats',
constraint=models.UniqueConstraint(fields=('era', 'area', 'stat', 'out'), name='stats_group_unique'),
),
migrations.AddConstraint(
model_name='buildstats',
constraint=models.UniqueConstraint(fields=('era', 'area', 'archetype', 'profession', 'elite', 'stat', 'out'), name='stats_group_unique'),
),
migrations.AddField(
model_name='userstats',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddConstraint(
model_name='userstats',
constraint=models.UniqueConstraint(fields=('era', 'area', 'user', 'archetype', 'profession', 'elite', 'stat', 'out'), name='stats_group_unique'),
),
]
109 changes: 68 additions & 41 deletions raidar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import pytz
from django.db import models
from django.contrib.auth.models import User
from django.db.models.functions import Coalesce
from django.core.validators import RegexValidator
from django.db.models import UniqueConstraint, Sum, Avg
from django.db.models import UniqueConstraint as Unique, Sum, Avg
from django.db.models.signals import post_save, post_delete
from fuzzycount import FuzzyCountManager
from taggit.managers import TaggableManager
Expand All @@ -22,6 +21,34 @@
# unique to 30-60s precision
START_RESOLUTION = 60

PROFESSION_CHOICES = (
(-1, "All"),
(Profession.GUARDIAN, "Guardian"),
(Profession.WARRIOR, "Warrior"),
(Profession.ENGINEER, "Engineer"),
(Profession.RANGER, "Ranger"),
(Profession.THIEF, "Thief"),
(Profession.ELEMENTALIST, "Elementalist"),
(Profession.MESMER, "Mesmer"),
(Profession.NECROMANCER, "Necromancer"),
(Profession.REVENANT, "Revenant"),
)

ARCHETYPE_CHOICES = (
(Archetype.POWER, "Power"),
(Archetype.CONDI, "Condi"),
(Archetype.TANK, "Tank"),
(Archetype.HEAL, "Heal"),
(Archetype.SUPPORT, "Support"),
)

ELITE_CHOICES = (
(-1, "All"),
(Elite.CORE, "Core"),
(Elite.HEART_OF_THORNS, "Heart of Thorns"),
(Elite.PATH_OF_FIRE, "Path of Fire"),
)


def _safe_get(func, default=None):
try:
Expand Down Expand Up @@ -644,37 +671,11 @@ class Meta:


class Participation(models.Model):
PROFESSION_CHOICES = (
(int(Profession.GUARDIAN), 'Guardian'),
(int(Profession.WARRIOR), 'Warrior'),
(int(Profession.ENGINEER), 'Engineer'),
(int(Profession.RANGER), 'Ranger'),
(int(Profession.THIEF), 'Thief'),
(int(Profession.ELEMENTALIST), 'Elementalist'),
(int(Profession.MESMER), 'Mesmer'),
(int(Profession.NECROMANCER), 'Necromancer'),
(int(Profession.REVENANT), 'Revenant'),
)

ARCHETYPE_CHOICES = (
(int(Archetype.POWER), "Power"),
(int(Archetype.CONDI), "Condi"),
(int(Archetype.TANK), "Tank"),
(int(Archetype.HEAL), "Heal"),
(int(Archetype.SUPPORT), "Support"),
)

ELITE_CHOICES = (
(int(Elite.CORE), "Core"),
(int(Elite.HEART_OF_THORNS), "Heart of Thorns"),
(int(Elite.PATH_OF_FIRE), "Path of Fire"),
)

encounter = models.ForeignKey(Encounter, on_delete=models.CASCADE, related_name='participations')
character = models.CharField(max_length=64, db_index=True)
account = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='participations')
profession = models.PositiveSmallIntegerField(choices=PROFESSION_CHOICES, db_index=True)
archetype = models.PositiveSmallIntegerField(choices=ARCHETYPE_CHOICES, db_index=True)
profession = models.PositiveSmallIntegerField(choices=PROFESSION_CHOICES, db_index=True)
elite = models.PositiveSmallIntegerField(choices=ELITE_CHOICES, db_index=True)
party = models.PositiveSmallIntegerField(db_index=True)

Expand Down Expand Up @@ -703,6 +704,38 @@ class Meta:
unique_together = ('encounter', 'account')


class SquadStats(models.Model):
class Meta:
db_table = "raidar_stats_squad"
constraints = [Unique(fields=["era", "area", "stat", "out"], name="stats_group_unique")]
era = models.ForeignKey(Era, on_delete=models.CASCADE)
area = models.ForeignKey(Area, on_delete=models.CASCADE)
stat = models.TextField
out = models.BooleanField
min_val = models.FloatField
max_val = models.FloatField
avg_val = models.FloatField
perc_data = models.TextField


class BuildStats(SquadStats):
class Meta:
db_table = "raidar_stats_build"
constraints = [Unique(fields=["era", "area", "archetype", "profession", "elite", "stat", "out"],
name="stats_group_unique")]
archetype = models.PositiveSmallIntegerField(choices=ARCHETYPE_CHOICES, db_index=True)
profession = models.PositiveSmallIntegerField(choices=PROFESSION_CHOICES, db_index=True)
elite = models.PositiveSmallIntegerField(choices=ELITE_CHOICES, db_index=True)


class UserStats(BuildStats):
class Meta:
db_table = "raidar_stats_user"
constraints = [Unique(fields=["era", "area", "user", "archetype", "profession", "elite", "stat", "out"],
name="stats_group_unique")]
user = models.ForeignKey(User, on_delete=models.CASCADE)


class EraAreaStore(ValueModel):
era = models.ForeignKey(Era, on_delete=models.CASCADE, related_name="era_area_stores")
area = models.ForeignKey(Area, on_delete=models.CASCADE, related_name="era_area_stores")
Expand Down Expand Up @@ -742,7 +775,7 @@ class Meta:
class EncounterPhase(EncounterAttribute):
class Meta:
db_table = "raidar_encounter_phase"
constraints = [UniqueConstraint(fields=["encounter_data", "name"], name="enc_phase_unique")]
constraints = [Unique(fields=["encounter_data", "name"], name="enc_phase_unique")]
name = models.TextField()
start_tick = models.BigIntegerField()

Expand Down Expand Up @@ -898,31 +931,26 @@ def all_breakdown(phase_dump, prv_encounter, party_name, player_data):
class SourcedEncounterAttribute(EncounterAttribute):
class Meta:
abstract = True
constraints = [UniqueConstraint(fields=["encounter_data", "phase", "source"], name="enc_attr_unique")]
phase = models.ForeignKey(EncounterPhase, on_delete=models.CASCADE)
source = models.TextField()


class TargetedEncounterAttribute(SourcedEncounterAttribute):
class Meta:
abstract = True
constraints = [UniqueConstraint(fields=["encounter_data", "phase", "source", "target"],
name="enc_target_attr_unique")]
target = models.TextField()


class NamedSourcedEncounterAttribute(SourcedEncounterAttribute):
class Meta:
abstract = True
constraints = [UniqueConstraint(fields=["encounter_data", "phase", "source", "name"],
name="enc_name_attr_unique")]
name = models.TextField()


class EncounterEvent(SourcedEncounterAttribute):
class Meta:
db_table = "raidar_encounter_event"
constraints = [UniqueConstraint(fields=["encounter_data", "phase", "source"], name="enc_evt_unique")]
constraints = [Unique(fields=["encounter_data", "phase", "source"], name="enc_evt_unique")]
disconnect_count = models.PositiveIntegerField()
disconnect_time = models.PositiveIntegerField()
down_count = models.PositiveIntegerField()
Expand Down Expand Up @@ -952,15 +980,15 @@ def summarize(query):

class EncounterMechanic(NamedSourcedEncounterAttribute):
class Meta:
constraints = [Unique(fields=["encounter_data", "phase", "source", "name"], name="enc_mech_unique")]
db_table = "raidar_encounter_mechanic"
count = models.PositiveIntegerField()


class EncounterBuff(TargetedEncounterAttribute):
class Meta:
db_table = "raidar_encounter_buff"
constraints = [UniqueConstraint(fields=["encounter_data", "phase", "source", "target", "name"],
name="enc_buff_unique")]
constraints = [Unique(fields=["encounter_data", "phase", "source", "target", "name"], name="enc_buff_unique")]
name = models.TextField()
uptime = models.FloatField()

Expand All @@ -977,8 +1005,7 @@ def breakdown(buff_data, use_sum=False):
class EncounterDamage(TargetedEncounterAttribute):
class Meta:
db_table = "raidar_encounter_damage"
constraints = [UniqueConstraint(fields=["encounter_data", "phase", "source", "target", "skill"],
name="enc_dmg_unique")]
constraints = [Unique(fields=["encounter_data", "phase", "source", "target", "skill"], name="enc_dmg_unique")]
skill = models.TextField()
damage = models.IntegerField()
crit = models.FloatField()
Expand Down Expand Up @@ -1051,7 +1078,7 @@ def conditions():
class EncounterPlayer(EncounterAttribute):
class Meta:
db_table = "raidar_encounter_player"
constraints = [UniqueConstraint(fields=["encounter_data", "account"], name="enc_player_unique")]
constraints = [Unique(fields=["encounter_data", "account"], name="enc_player_unique")]
account = models.ForeignKey(Account, on_delete=models.CASCADE)
character = models.TextField()
party = models.PositiveIntegerField()
Expand Down
2 changes: 1 addition & 1 deletion raidar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _html_response(request, page, data=None):
except:
# No Google Analytics, it's fine
pass
response['archetypes'] = {k: v for k, v in Participation.ARCHETYPE_CHOICES}
response['archetypes'] = {k: v for k, v in ARCHETYPE_CHOICES}
response['areas'] = {id: {
"name": boss.name,
"kind": boss.kind,
Expand Down

0 comments on commit 5de742f

Please sign in to comment.