aa-pilotstats 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. aa_pilotstats/__init__.py +4 -0
  2. aa_pilotstats/admin.py +221 -0
  3. aa_pilotstats/app_settings.py +60 -0
  4. aa_pilotstats/apps.py +29 -0
  5. aa_pilotstats/auth_hooks.py +55 -0
  6. aa_pilotstats/checks.py +29 -0
  7. aa_pilotstats/discord.py +433 -0
  8. aa_pilotstats/fleets.py +208 -0
  9. aa_pilotstats/forms.py +40 -0
  10. aa_pilotstats/leaderboard.py +327 -0
  11. aa_pilotstats/legacy_urls.py +27 -0
  12. aa_pilotstats/migration_ops.py +94 -0
  13. aa_pilotstats/migrations/0001_initial.py +117 -0
  14. aa_pilotstats/migrations/0002_esi_zkill_fleets.py +171 -0
  15. aa_pilotstats/migrations/0003_discord.py +49 -0
  16. aa_pilotstats/migrations/__init__.py +0 -0
  17. aa_pilotstats/models.py +632 -0
  18. aa_pilotstats/parsing.py +281 -0
  19. aa_pilotstats/payouts.py +135 -0
  20. aa_pilotstats/providers.py +50 -0
  21. aa_pilotstats/static/pilotstats/css/pilotstats.css +330 -0
  22. aa_pilotstats/static/pilotstats/js/dropzone.js +45 -0
  23. aa_pilotstats/static/pilotstats/js/scanner.js +447 -0
  24. aa_pilotstats/tasks.py +299 -0
  25. aa_pilotstats/templates/pilotstats/base.html +58 -0
  26. aa_pilotstats/templates/pilotstats/dashboard_widget.html +63 -0
  27. aa_pilotstats/templates/pilotstats/events.html +92 -0
  28. aa_pilotstats/templates/pilotstats/fleet_detail.html +80 -0
  29. aa_pilotstats/templates/pilotstats/fleets.html +56 -0
  30. aa_pilotstats/templates/pilotstats/includes/feed_line.html +39 -0
  31. aa_pilotstats/templates/pilotstats/includes/session_dashboard.html +121 -0
  32. aa_pilotstats/templates/pilotstats/leaderboard.html +109 -0
  33. aa_pilotstats/templates/pilotstats/my_uploads.html +81 -0
  34. aa_pilotstats/templates/pilotstats/session_detail.html +77 -0
  35. aa_pilotstats/templates/pilotstats/upload.html +73 -0
  36. aa_pilotstats/templatetags/__init__.py +0 -0
  37. aa_pilotstats/templatetags/pilotstats.py +35 -0
  38. aa_pilotstats/tests/__init__.py +0 -0
  39. aa_pilotstats/tests/test_discord.py +259 -0
  40. aa_pilotstats/tests/test_leaderboard.py +137 -0
  41. aa_pilotstats/tests/test_migrations.py +48 -0
  42. aa_pilotstats/tests/test_parsing.py +227 -0
  43. aa_pilotstats/tests/test_scanner_api.py +157 -0
  44. aa_pilotstats/tests/test_sources.py +529 -0
  45. aa_pilotstats/tests/test_upgrade.py +197 -0
  46. aa_pilotstats/tests/test_views.py +460 -0
  47. aa_pilotstats/typenames.py +101 -0
  48. aa_pilotstats/urls.py +23 -0
  49. aa_pilotstats/views.py +736 -0
  50. aa_pilotstats/zkill.py +130 -0
  51. aa_pilotstats-0.1.0.dist-info/METADATA +250 -0
  52. aa_pilotstats-0.1.0.dist-info/RECORD +54 -0
  53. aa_pilotstats-0.1.0.dist-info/WHEEL +4 -0
  54. aa_pilotstats-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,4 @@
1
+ """Initialize the app"""
2
+
3
+ __version__ = "0.1.0"
4
+ __title__ = "Pilot Stats"
aa_pilotstats/admin.py ADDED
@@ -0,0 +1,221 @@
1
+ """Pilot Stats Django Admin"""
2
+
3
+ # Django
4
+ from django import forms
5
+ from django.contrib import admin, messages
6
+
7
+ from .models import (
8
+ CombatLogUpload,
9
+ DiscordPost,
10
+ DiscordSettings,
11
+ FleetMember,
12
+ Killmail,
13
+ KillmailParticipant,
14
+ NpcKillDaily,
15
+ Payout,
16
+ PayoutDaily,
17
+ PilotSettings,
18
+ R2Z2State,
19
+ TrackedEntity,
20
+ TrackedFleet,
21
+ TypeName,
22
+ )
23
+
24
+
25
+ class ReadOnlyAdmin(admin.ModelAdmin):
26
+ """Rows written by tasks or uploads; admin is for looking, not editing."""
27
+
28
+ def has_add_permission(self, request):
29
+ return False
30
+
31
+ def has_change_permission(self, request, obj=None):
32
+ return False
33
+
34
+
35
+ @admin.register(CombatLogUpload)
36
+ class CombatLogUploadAdmin(admin.ModelAdmin):
37
+ list_display = (
38
+ "character", "uploaded_by", "uploaded_at",
39
+ "damage_out", "damage_in", "reps_received_total", "reps_given_total",
40
+ "matched_lines", "combat_lines",
41
+ )
42
+ list_filter = ("uploaded_at",)
43
+ search_fields = ("character__character_name", "uploaded_by__username", "source_filename")
44
+ readonly_fields = [f.name for f in CombatLogUpload._meta.fields]
45
+
46
+ def has_add_permission(self, request):
47
+ return False
48
+
49
+
50
+ @admin.register(PilotSettings)
51
+ class PilotSettingsAdmin(admin.ModelAdmin):
52
+ list_display = ("user", "hide_from_live_feed", "wallet_opt_out")
53
+ list_filter = ("hide_from_live_feed", "wallet_opt_out")
54
+ search_fields = ("user__username",)
55
+
56
+
57
+ @admin.register(Payout)
58
+ class PayoutAdmin(ReadOnlyAdmin):
59
+ list_display = ("character", "occurred_at", "entry_type", "amount", "ref_id")
60
+ list_filter = ("entry_type",)
61
+ search_fields = ("character__character_name",)
62
+ date_hierarchy = "occurred_at"
63
+
64
+
65
+ @admin.register(PayoutDaily)
66
+ class PayoutDailyAdmin(ReadOnlyAdmin):
67
+ list_display = ("character", "day", "entry_type", "amount")
68
+ list_filter = ("entry_type",)
69
+ search_fields = ("character__character_name",)
70
+ date_hierarchy = "day"
71
+
72
+
73
+ @admin.register(NpcKillDaily)
74
+ class NpcKillDailyAdmin(ReadOnlyAdmin):
75
+ list_display = ("character", "day", "npc_type_id", "count")
76
+ search_fields = ("character__character_name",)
77
+ date_hierarchy = "day"
78
+
79
+
80
+ class KillmailParticipantInline(admin.TabularInline):
81
+ model = KillmailParticipant
82
+ extra = 0
83
+ can_delete = False
84
+ readonly_fields = ("character", "is_victim", "final_blow", "damage", "ship_type_id")
85
+
86
+ def has_add_permission(self, request, obj=None):
87
+ return False
88
+
89
+
90
+ @admin.register(Killmail)
91
+ class KillmailAdmin(ReadOnlyAdmin):
92
+ list_display = ("killmail_id", "killmail_time", "victim_ship_type_id", "total_value", "npc", "solo")
93
+ list_filter = ("npc", "solo")
94
+ search_fields = ("killmail_id", "participants__character__character_name")
95
+ date_hierarchy = "killmail_time"
96
+ inlines = [KillmailParticipantInline]
97
+
98
+
99
+ @admin.register(TrackedEntity)
100
+ class TrackedEntityAdmin(admin.ModelAdmin):
101
+ """Which corporations/alliances' killmails are kept from zKill.
102
+
103
+ Automatic rows follow the mains of Member-state users (setting
104
+ PILOTSTATS_ZKILL_AUTO_STATES). Untick "enabled" to stop one; add rows
105
+ by hand for anyone else.
106
+ """
107
+
108
+ list_display = ("name", "kind", "entity_id", "source", "enabled")
109
+ list_filter = ("kind", "source", "enabled")
110
+ list_editable = ("enabled",)
111
+ search_fields = ("name", "entity_id")
112
+
113
+ def get_readonly_fields(self, request, obj=None):
114
+ if obj is not None and obj.source == TrackedEntity.Source.AUTO:
115
+ return ("kind", "entity_id", "name", "source")
116
+ return ("source",)
117
+
118
+
119
+ @admin.register(R2Z2State)
120
+ class R2Z2StateAdmin(admin.ModelAdmin):
121
+ """Edit last_sequence only to replay or skip part of the zKill feed."""
122
+
123
+ list_display = ("last_sequence", "updated_at")
124
+
125
+ def has_add_permission(self, request):
126
+ return not R2Z2State.objects.exists()
127
+
128
+
129
+ class FleetMemberInline(admin.TabularInline):
130
+ model = FleetMember
131
+ extra = 0
132
+ can_delete = False
133
+ readonly_fields = ("eve_character_id", "character", "ship_type_id", "first_seen", "last_seen")
134
+
135
+ def has_add_permission(self, request, obj=None):
136
+ return False
137
+
138
+
139
+ @admin.register(TrackedFleet)
140
+ class TrackedFleetAdmin(ReadOnlyAdmin):
141
+ list_display = ("fleet_id", "boss", "started_by", "started_at", "ended_at", "end_reason")
142
+ list_filter = ("ended_at",)
143
+ inlines = [FleetMemberInline]
144
+
145
+
146
+ @admin.register(TypeName)
147
+ class TypeNameAdmin(ReadOnlyAdmin):
148
+ list_display = ("type_id", "name", "group_name", "fetched_at")
149
+ search_fields = ("name", "type_id")
150
+
151
+
152
+ class DiscordSettingsForm(forms.ModelForm):
153
+ """The webhook URL is write-only: it's never shown again after saving."""
154
+
155
+ webhook_url = forms.CharField(
156
+ required=False,
157
+ widget=forms.PasswordInput(render_value=False, attrs={"autocomplete": "off", "size": 80}),
158
+ help_text="Discord channel → Integrations → Webhooks → Copy URL. Leave blank to keep the saved one.",
159
+ )
160
+ clear_webhook = forms.BooleanField(required=False, label="Remove the saved webhook URL")
161
+
162
+ class Meta:
163
+ model = DiscordSettings
164
+ fields = "__all__"
165
+
166
+ def clean_webhook_url(self):
167
+ value = (self.cleaned_data.get("webhook_url") or "").strip()
168
+ if not value and self.instance.pk:
169
+ return self.instance.webhook_url
170
+ return value
171
+
172
+ def save(self, commit=True):
173
+ obj = super().save(commit=False)
174
+ if self.cleaned_data.get("clear_webhook"):
175
+ obj.webhook_url = ""
176
+ obj.enabled = False
177
+ if commit:
178
+ obj.save()
179
+ return obj
180
+
181
+
182
+ @admin.register(DiscordSettings)
183
+ class DiscordSettingsAdmin(admin.ModelAdmin):
184
+ form = DiscordSettingsForm
185
+ list_display = ("__str__", "enabled", "webhook_saved", "daily_post_time", "timezone",
186
+ "payout_threshold_isk", "kill_threshold_isk", "max_posts_per_hour", "post_records")
187
+ actions = ["send_test_message"]
188
+ fieldsets = (
189
+ (None, {"fields": ("enabled", "webhook_url", "clear_webhook")}),
190
+ ("Daily top 10", {"fields": ("daily_post_time", "timezone")}),
191
+ ("Major events", {"fields": ("payout_threshold_isk", "kill_threshold_isk",
192
+ "max_posts_per_hour", "post_records")}),
193
+ )
194
+
195
+ @admin.display(boolean=True, description="webhook saved")
196
+ def webhook_saved(self, obj):
197
+ return bool(obj.webhook_url)
198
+
199
+ def has_add_permission(self, request):
200
+ return not DiscordSettings.objects.exists()
201
+
202
+ def has_delete_permission(self, request, obj=None):
203
+ return False
204
+
205
+ @admin.action(description="Send a test message to the webhook")
206
+ def send_test_message(self, request, queryset):
207
+ from . import discord
208
+
209
+ config = DiscordSettings.get()
210
+ if not config.is_active:
211
+ self.message_user(request, "Enable the feed and save a webhook URL first.", messages.WARNING)
212
+ return
213
+ discord.test_message(config)
214
+ self.message_user(request, "Test message queued. It appears in the channel within a few seconds.")
215
+
216
+
217
+ @admin.register(DiscordPost)
218
+ class DiscordPostAdmin(ReadOnlyAdmin):
219
+ list_display = ("created_at", "kind", "status", "key", "detail")
220
+ list_filter = ("kind", "status")
221
+ search_fields = ("key", "detail")
@@ -0,0 +1,60 @@
1
+ """
2
+ Settings, each overridable from Alliance Auth's ``local.py``.
3
+
4
+ Read once at import; restart Auth after changing one.
5
+ """
6
+
7
+ # Django
8
+ from django.conf import settings
9
+
10
+ from . import __version__
11
+
12
+ # Shared ---------------------------------------------------------------------
13
+
14
+ USER_AGENT = getattr(
15
+ settings,
16
+ "PILOTSTATS_USER_AGENT",
17
+ f"aa-pilotstats/{__version__} (+https://github.com/Thrainkrilleve/PilotStats)",
18
+ )
19
+
20
+ # ESI ------------------------------------------------------------------------
21
+
22
+ # Reviewed ESI compatibility date. ESI serves the oldest supported behaviour
23
+ # when none is sent, so this is pinned on purpose; bump it after checking the
24
+ # changelog at https://developers.eveonline.com/docs/services/esi/overview/
25
+ ESI_COMPATIBILITY_DATE = getattr(settings, "PILOTSTATS_ESI_COMPATIBILITY_DATE", "2026-11-19")
26
+
27
+ WALLET_SCOPE = "esi-wallet.read_character_wallet.v1"
28
+ FLEET_SCOPE = "esi-fleets.read_fleet.v1"
29
+
30
+ # Itemized payout lines are kept a little longer than the journal's 30-day
31
+ # window so a journal id is never seen twice; daily totals are kept forever.
32
+ PAYOUT_RETENTION_DAYS = int(getattr(settings, "PILOTSTATS_PAYOUT_RETENTION_DAYS", 35))
33
+
34
+ # Payouts, kills, and fleet hulls are matched to a Gamelog session when they
35
+ # fall within this many minutes of it.
36
+ SESSION_LINK_MINUTES = int(getattr(settings, "PILOTSTATS_SESSION_LINK_MINUTES", 15))
37
+
38
+ # zKillboard R2Z2 ---------------------------------------------------------------
39
+
40
+ R2Z2_URL = getattr(settings, "PILOTSTATS_R2Z2_URL", "https://r2z2.zkillboard.com/ephemeral").rstrip("/")
41
+ # Files fetched per run of drain_r2z2 (it runs every minute).
42
+ R2Z2_MAX_PER_RUN = int(getattr(settings, "PILOTSTATS_R2Z2_MAX_PER_RUN", 300))
43
+ # Pause between files. zKill allows 15 requests/second per IP; stay far under.
44
+ R2Z2_REQUEST_INTERVAL = float(getattr(settings, "PILOTSTATS_R2Z2_REQUEST_INTERVAL", 0.15))
45
+ # Auth states whose mains' corporations and alliances are tracked automatically.
46
+ ZKILL_AUTO_STATES = list(getattr(settings, "PILOTSTATS_ZKILL_AUTO_STATES", ["Member"]))
47
+
48
+ # EVE static data -------------------------------------------------------------
49
+
50
+ SDE_URL = getattr(settings, "PILOTSTATS_SDE_URL", "https://sde.evetech.net/tranquility/latest").rstrip("/")
51
+
52
+ # Gamelog folder scanner ------------------------------------------------------
53
+
54
+ # Most uploads one user's scanner may send per minute. A first scan of a
55
+ # large Gamelogs folder is paced to this; 0 turns the limit off.
56
+ SCANNER_UPLOADS_PER_MINUTE = int(getattr(settings, "PILOTSTATS_SCANNER_UPLOADS_PER_MINUTE", 30))
57
+
58
+ # By default the scanner only sends logs modified in the last N days; pilots
59
+ # can tick "include older logs" for a one-time backfill.
60
+ SCANNER_RECENT_DAYS = int(getattr(settings, "PILOTSTATS_SCANNER_RECENT_DAYS", 7))
aa_pilotstats/apps.py ADDED
@@ -0,0 +1,29 @@
1
+ """App Configuration"""
2
+
3
+ # Django
4
+ from django.apps import AppConfig
5
+
6
+ # Pilot Stats
7
+ from aa_pilotstats import __version__
8
+
9
+
10
+ class PilotstatsConfig(AppConfig):
11
+ """App Config
12
+
13
+ `name` is the importable package (what pip installs as "aa-pilotstats"
14
+ and what goes in INSTALLED_APPS). `label` is the short identifier used in
15
+ permission strings (`pilotstats.basic_access`), the URL namespace
16
+ (`{% url 'pilotstats:...' %}`), table names, and migrations.
17
+
18
+ This app was called PvE Tracker (package `aa_pvetracker`, label
19
+ `pvetracker`) up to v0.0.11. Migration 0001 adopts an old install's
20
+ tables, permissions, and migration history; see that migration.
21
+ """
22
+
23
+ name = "aa_pilotstats"
24
+ label = "pilotstats"
25
+ verbose_name = f"Pilot Stats v{__version__}"
26
+
27
+ def ready(self):
28
+ # Register system checks.
29
+ from . import checks # noqa: F401
@@ -0,0 +1,55 @@
1
+ """Hook into Alliance Auth"""
2
+
3
+ # Django
4
+ from django.utils.translation import gettext_lazy as _
5
+
6
+ # Alliance Auth
7
+ from allianceauth import hooks
8
+ from allianceauth.services.hooks import MenuItemHook, UrlHook
9
+
10
+ from . import legacy_urls, urls
11
+ from .views import pilotstats_dashboard
12
+
13
+
14
+ class PilotstatsMenuItem(MenuItemHook):
15
+ """Sidebar menu entry. Any logged-in member can open the leaderboard."""
16
+
17
+ def __init__(self):
18
+ MenuItemHook.__init__(
19
+ self,
20
+ _("Pilot Stats"),
21
+ "fas fa-crosshairs fa-fw",
22
+ "pilotstats:leaderboard",
23
+ navactive=["pilotstats:"],
24
+ )
25
+
26
+ def render(self, request) -> str:
27
+ if request.user.is_authenticated:
28
+ return MenuItemHook.render(self, request)
29
+ return ""
30
+
31
+
32
+ class PilotstatsDashboardHook(hooks.DashboardItemHook):
33
+ def __init__(self):
34
+ super().__init__(pilotstats_dashboard, 1)
35
+
36
+
37
+ @hooks.register("menu_item_hook")
38
+ def register_menu():
39
+ return PilotstatsMenuItem()
40
+
41
+
42
+ @hooks.register("url_hook")
43
+ def register_urls():
44
+ return UrlHook(urls, "pilotstats", r"^pilotstats/")
45
+
46
+
47
+ @hooks.register("url_hook")
48
+ def register_legacy_urls():
49
+ """Redirect PvE Tracker-era /pvetracker/... links to /pilotstats/..."""
50
+ return UrlHook(legacy_urls, "pvetracker_legacy", r"^pvetracker/")
51
+
52
+
53
+ @hooks.register("dashboard_hook")
54
+ def register_dashboard():
55
+ return PilotstatsDashboardHook()
@@ -0,0 +1,29 @@
1
+ """System checks."""
2
+
3
+ # Django
4
+ from django.conf import settings
5
+ from django.core.checks import Error, register
6
+
7
+ LEGACY_APP = "aa_pvetracker"
8
+
9
+
10
+ @register()
11
+ def legacy_app_not_installed(app_configs, **kwargs):
12
+ """
13
+ Pilot Stats replaces PvE Tracker and takes over its tables on upgrade.
14
+ Running both would leave the old app pointing at tables that no longer
15
+ exist under its name, so refuse to start until it's removed.
16
+ """
17
+ if LEGACY_APP in settings.INSTALLED_APPS:
18
+ return [
19
+ Error(
20
+ "Both Pilot Stats and its predecessor PvE Tracker are installed.",
21
+ hint=(
22
+ f"Remove '{LEGACY_APP}' from INSTALLED_APPS and run "
23
+ "'pip uninstall aa-pvetracker'. Pilot Stats keeps PvE Tracker's "
24
+ "data: its first migration takes the old tables over."
25
+ ),
26
+ id="pilotstats.E001",
27
+ )
28
+ ]
29
+ return []