aa-fatanalysis 1.2.0__tar.gz → 3.0.0__tar.gz

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 (52) hide show
  1. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/PKG-INFO +30 -5
  2. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/README.md +28 -2
  3. aa_fatanalysis-3.0.0/fatanalysis/__init__.py +1 -0
  4. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/services.py +94 -0
  5. aa_fatanalysis-3.0.0/fatanalysis/spa_api.py +541 -0
  6. aa_fatanalysis-3.0.0/fatanalysis/static/fatanalysis/spa/assets/index.css +1 -0
  7. aa_fatanalysis-3.0.0/fatanalysis/static/fatanalysis/spa/assets/index.js +204 -0
  8. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/index.html +87 -41
  9. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/period_detail.html +86 -40
  10. aa_fatanalysis-3.0.0/fatanalysis/templates/fatanalysis/spa.html +28 -0
  11. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_auto_sync.py +1 -1
  12. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_participation.py +1 -1
  13. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_services.py +140 -0
  14. aa_fatanalysis-3.0.0/fatanalysis/tests/test_spa_api.py +324 -0
  15. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_views.py +10 -10
  16. aa_fatanalysis-3.0.0/fatanalysis/urls.py +29 -0
  17. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/views.py +33 -0
  18. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/pyproject.toml +2 -3
  19. aa_fatanalysis-1.2.0/fatanalysis/__init__.py +0 -1
  20. aa_fatanalysis-1.2.0/fatanalysis/urls.py +0 -17
  21. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/.gitignore +0 -0
  22. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/LICENSE +0 -0
  23. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/apps.py +0 -0
  24. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/auth_hooks.py +0 -0
  25. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/forms.py +0 -0
  26. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/management/__init__.py +0 -0
  27. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/management/commands/__init__.py +0 -0
  28. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/management/commands/fatanalysis_sync_all.py +0 -0
  29. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0001_initial.py +0 -0
  30. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0002_alter_uploadperiod_upload_date.py +0 -0
  31. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0003_general.py +0 -0
  32. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0004_fatsyncconfig_alter_fatentry_options_and_more.py +0 -0
  33. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0005_fatmonthperiod_fats_by_time_and_more.py +0 -0
  34. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0006_fatmonthperiod_fats_by_ship.py +0 -0
  35. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/0007_auto_sync.py +0 -0
  36. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/migrations/__init__.py +0 -0
  37. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/models.py +0 -0
  38. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/scheduling.py +0 -0
  39. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tasks.py +0 -0
  40. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/base.html +0 -0
  41. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/import_csv.html +0 -0
  42. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/overview.html +0 -0
  43. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/period_delete.html +0 -0
  44. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/period_list.html +0 -0
  45. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/player_detail.html +0 -0
  46. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templates/fatanalysis/sync_management.html +0 -0
  47. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templatetags/__init__.py +0 -0
  48. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/templatetags/fatanalysis_tags.py +0 -0
  49. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/__init__.py +0 -0
  50. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_models.py +0 -0
  51. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_settings.py +0 -0
  52. {aa_fatanalysis-1.2.0 → aa_fatanalysis-3.0.0}/fatanalysis/tests/test_urls.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: aa-fatanalysis
3
- Version: 1.2.0
3
+ Version: 3.0.0
4
4
  Summary: FAT Analysis Plugin for Alliance Auth
5
5
  Author-email: Maddog Broekman <maddogbroekman@gmail.com>
6
6
  License: MIT License
@@ -34,13 +34,12 @@ Classifier: License :: OSI Approved :: MIT License
34
34
  Classifier: Operating System :: OS Independent
35
35
  Classifier: Programming Language :: Python
36
36
  Classifier: Programming Language :: Python :: 3 :: Only
37
- Classifier: Programming Language :: Python :: 3.10
38
37
  Classifier: Programming Language :: Python :: 3.11
39
38
  Classifier: Programming Language :: Python :: 3.12
40
39
  Classifier: Programming Language :: Python :: 3.13
41
40
  Classifier: Topic :: Internet :: WWW/HTTP
42
41
  Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
43
- Requires-Python: <3.14,>=3.10
42
+ Requires-Python: <3.14,>=3.11
44
43
  Requires-Dist: allianceauth>=5
45
44
  Requires-Dist: beautifulsoup4>=4.12
46
45
  Requires-Dist: requests>=2.31
@@ -60,9 +59,11 @@ Alliance Auth plugin for analyzing FATs (Fleet Activity Tracking). This plugin p
60
59
  - **INIT Auth Scraper**: Built-in scraper service to ingest reports directly from remote Alliance Auth AFAT instances using session cookies.
61
60
  - **Frontend Director UI**: Manage scraper credentials, test live connections, trigger on-demand imports, and upload CSVs directly from the web interface without needing Django admin.
62
61
  - **Automatic Sync**: A Celery task fetches the current month from INIT Auth on a schedule (default every 6 hours; during the first 3 days of a month the previous month too). Switch it on or off and set the interval on the Sync & Ingestion page. The plugin keeps its own Celery beat entry, so no `CELERYBEAT_SCHEDULE` entry in `local.py` is needed.
62
+ - **Modern SPA UI**: React + Tailwind CSS + shadcn/ui, following the Alliance Auth light/dark theme. Every table has per-column sorting and search. The classic Django templates stay available with `?classic=1`.
63
63
  - **Dynamic Time Windows**: Switch instantly between 30 Days (Latest), 90 Days, 120 Days, YTD, specific years, and All Time.
64
64
  - **Corp Participation & Averages**: Active Participation compares the mains with FATs to the corp's mains in Auth; the dashboard also shows corp averages (FATs per month, per active pilot and per member) for the selected window.
65
- - **Pilot Longitudinal Detail**: Track individual pilot participation trends over time with interactive Chart.js line and doughnut charts.
65
+ - **Pilot Longitudinal Detail**: Track individual pilot participation trends over time with interactive line and doughnut charts.
66
+ - **FATs per Ship & per Pilot Tables**: Sortable tables (dashboard and period detail) of total FATs per ship type, and a per-pilot x per-ship breakdown scraped from each active pilot's individual INIT Auth statistics page.
66
67
  - **Permissions Management**: Separate `fatanalysis.basic_access` (members) and `fatanalysis.manage_fatanalysis` (directors/leadership).
67
68
 
68
69
  ## Installation
@@ -98,8 +99,32 @@ Alliance Auth plugin for analyzing FATs (Fleet Activity Tracking). This plugin p
98
99
  sudo systemctl restart supervisor
99
100
  ```
100
101
  *(Or restart gunicorn and celery according to your specific setup)*
101
- Celery beat must be running for the automatic sync. `migrate` creates its schedule (`fatanalysis_auto_sync`, every 6 hours); it needs a session cookie on the Sync & Ingestion page to fetch data.
102
+ Restart the Celery workers too, also after every upgrade: a worker that is not restarted does not know new tasks.
103
+
104
+ 6. **Automatic sync (Celery task)**
105
+ The task `fatanalysis.tasks.auto_sync` fetches the current month from INIT Auth (and the previous month during the first 3 days of a month).
106
+ - **No `local.py` entry needed.** Do not add it to `CELERYBEAT_SCHEDULE`. `migrate` creates the periodic task `fatanalysis_auto_sync` (every 6 hours) in the database, and the plugin keeps it up to date.
107
+ - **Celery beat** must run with a database scheduler. Alliance Auth's default `allianceauth.crontab.schedulers.OffsetDatabaseScheduler` works.
108
+ - **Session cookie:** enter it on the Sync & Ingestion page (`/fatanalysis/sync/`); without it the task skips.
109
+ - **Settings:** switch the sync on or off and set the interval (1–168 hours) in the Automatic Sync card on that page. The change applies right away.
110
+ - Check that the workers know the task:
111
+
112
+ ```bash
113
+ celery -A myauth inspect registered | grep fatanalysis
114
+ ```
102
115
 
103
116
  ## Permissions
104
117
  - `fatanalysis.basic_access`: Allows members to view the FAT Analysis dashboard, filter by time windows, and view player details.
105
118
  - `fatanalysis.manage_fatanalysis`: Allows directors/leadership to access Sync & Ingestion management, configure the AFAT scraper, import CSVs, and manage/delete recording periods.
119
+
120
+ ## Frontend development
121
+
122
+ The UI is a Vite + React 19 + TypeScript + Tailwind v4 + shadcn/ui SPA in `frontend/`, scoped under `.aa-spa-root` (no global Preflight, so it does not disturb Bootstrap). The built bundle is committed in `fatanalysis/static/fatanalysis/spa/assets/`.
123
+
124
+ ```powershell
125
+ powershell -File frontend/build.ps1
126
+ ```
127
+
128
+ `build.ps1` copies the sources to `%LOCALAPPDATA%a-fatanalysis-frontend-build` (npm install fails on Google Drive), builds there and copies `index.js` and `index.css` back. After deploying, run `collectstatic` and restart the web workers.
129
+
130
+ The JSON API lives in `fatanalysis/spa_api.py` (`/fatanalysis/api/v1/spa/...`).
@@ -12,9 +12,11 @@ Alliance Auth plugin for analyzing FATs (Fleet Activity Tracking). This plugin p
12
12
  - **INIT Auth Scraper**: Built-in scraper service to ingest reports directly from remote Alliance Auth AFAT instances using session cookies.
13
13
  - **Frontend Director UI**: Manage scraper credentials, test live connections, trigger on-demand imports, and upload CSVs directly from the web interface without needing Django admin.
14
14
  - **Automatic Sync**: A Celery task fetches the current month from INIT Auth on a schedule (default every 6 hours; during the first 3 days of a month the previous month too). Switch it on or off and set the interval on the Sync & Ingestion page. The plugin keeps its own Celery beat entry, so no `CELERYBEAT_SCHEDULE` entry in `local.py` is needed.
15
+ - **Modern SPA UI**: React + Tailwind CSS + shadcn/ui, following the Alliance Auth light/dark theme. Every table has per-column sorting and search. The classic Django templates stay available with `?classic=1`.
15
16
  - **Dynamic Time Windows**: Switch instantly between 30 Days (Latest), 90 Days, 120 Days, YTD, specific years, and All Time.
16
17
  - **Corp Participation & Averages**: Active Participation compares the mains with FATs to the corp's mains in Auth; the dashboard also shows corp averages (FATs per month, per active pilot and per member) for the selected window.
17
- - **Pilot Longitudinal Detail**: Track individual pilot participation trends over time with interactive Chart.js line and doughnut charts.
18
+ - **Pilot Longitudinal Detail**: Track individual pilot participation trends over time with interactive line and doughnut charts.
19
+ - **FATs per Ship & per Pilot Tables**: Sortable tables (dashboard and period detail) of total FATs per ship type, and a per-pilot x per-ship breakdown scraped from each active pilot's individual INIT Auth statistics page.
18
20
  - **Permissions Management**: Separate `fatanalysis.basic_access` (members) and `fatanalysis.manage_fatanalysis` (directors/leadership).
19
21
 
20
22
  ## Installation
@@ -50,8 +52,32 @@ Alliance Auth plugin for analyzing FATs (Fleet Activity Tracking). This plugin p
50
52
  sudo systemctl restart supervisor
51
53
  ```
52
54
  *(Or restart gunicorn and celery according to your specific setup)*
53
- Celery beat must be running for the automatic sync. `migrate` creates its schedule (`fatanalysis_auto_sync`, every 6 hours); it needs a session cookie on the Sync & Ingestion page to fetch data.
55
+ Restart the Celery workers too, also after every upgrade: a worker that is not restarted does not know new tasks.
56
+
57
+ 6. **Automatic sync (Celery task)**
58
+ The task `fatanalysis.tasks.auto_sync` fetches the current month from INIT Auth (and the previous month during the first 3 days of a month).
59
+ - **No `local.py` entry needed.** Do not add it to `CELERYBEAT_SCHEDULE`. `migrate` creates the periodic task `fatanalysis_auto_sync` (every 6 hours) in the database, and the plugin keeps it up to date.
60
+ - **Celery beat** must run with a database scheduler. Alliance Auth's default `allianceauth.crontab.schedulers.OffsetDatabaseScheduler` works.
61
+ - **Session cookie:** enter it on the Sync & Ingestion page (`/fatanalysis/sync/`); without it the task skips.
62
+ - **Settings:** switch the sync on or off and set the interval (1–168 hours) in the Automatic Sync card on that page. The change applies right away.
63
+ - Check that the workers know the task:
64
+
65
+ ```bash
66
+ celery -A myauth inspect registered | grep fatanalysis
67
+ ```
54
68
 
55
69
  ## Permissions
56
70
  - `fatanalysis.basic_access`: Allows members to view the FAT Analysis dashboard, filter by time windows, and view player details.
57
71
  - `fatanalysis.manage_fatanalysis`: Allows directors/leadership to access Sync & Ingestion management, configure the AFAT scraper, import CSVs, and manage/delete recording periods.
72
+
73
+ ## Frontend development
74
+
75
+ The UI is a Vite + React 19 + TypeScript + Tailwind v4 + shadcn/ui SPA in `frontend/`, scoped under `.aa-spa-root` (no global Preflight, so it does not disturb Bootstrap). The built bundle is committed in `fatanalysis/static/fatanalysis/spa/assets/`.
76
+
77
+ ```powershell
78
+ powershell -File frontend/build.ps1
79
+ ```
80
+
81
+ `build.ps1` copies the sources to `%LOCALAPPDATA%a-fatanalysis-frontend-build` (npm install fails on Google Drive), builds there and copies `index.js` and `index.css` back. After deploying, run `collectstatic` and restart the web workers.
82
+
83
+ The JSON API lives in `fatanalysis/spa_api.py` (`/fatanalysis/api/v1/spa/...`).
@@ -0,0 +1 @@
1
+ __version__ = "3.0.0"
@@ -10,6 +10,7 @@ import csv
10
10
  import io
11
11
  import logging
12
12
  import re
13
+ import time
13
14
  from collections import defaultdict
14
15
  from typing import Any
15
16
 
@@ -103,6 +104,45 @@ class AfatScraperService:
103
104
  url = self.build_report_url(year, month, corporation_id)
104
105
  return self.fetch_report(url)
105
106
 
107
+ def build_character_report_url(self, character_id: int, year: int, month: int) -> str:
108
+ """
109
+ Constructs the URL for an individual character's monthly statistics page on INIT Auth.
110
+ """
111
+ base_url = self.config.source_url.rstrip("/")
112
+ return f"{base_url}/statistics/character/{character_id}/{year}/{month}/"
113
+
114
+ def fetch_character_ship_breakdown(self, character_id: int, year: int, month: int) -> dict[str, int]:
115
+ """
116
+ Fetches an individual character's monthly statistics page and extracts their
117
+ per-ship FAT breakdown from the embedded 'pie-ship' chart.
118
+ """
119
+ url = self.build_character_report_url(character_id, year, month)
120
+ html_content = self.fetch_report(url)
121
+ return FatIngestionService.parse_character_ship_chart(html_content)
122
+
123
+ def enrich_records_with_ship_details(self, records: list[dict[str, Any]], year: int, month: int) -> None:
124
+ """
125
+ Populates ``ship_details`` on each active pilot's record in place, by fetching
126
+ their individual INIT Auth statistics page for this month. A single pilot's
127
+ fetch failing (network error, no chart, left the corp, ...) is logged and
128
+ skipped so it never aborts the rest of the sync.
129
+ """
130
+ for rec in records:
131
+ character_id = rec.get("character_id")
132
+ if not character_id or not rec.get("total_fats"):
133
+ continue
134
+ try:
135
+ rec["ship_details"] = self.fetch_character_ship_breakdown(character_id, year, month)
136
+ except Exception as e:
137
+ logger.warning(
138
+ "Could not fetch ship breakdown for character %s (%s/%s): %s",
139
+ character_id,
140
+ year,
141
+ month,
142
+ e,
143
+ )
144
+ time.sleep(0.3)
145
+
106
146
  def sync_month(self, year: int, month: int, synced_by: User | None = None) -> FatMonthPeriod | None:
107
147
  """
108
148
  Fetches and ingests one month. Returns None when INIT Auth has no data for it.
@@ -112,6 +152,7 @@ class AfatScraperService:
112
152
  fats_by_time, fats_by_weekday, fats_by_ship = FatIngestionService.parse_html_charts(html_content)
113
153
  if not records and not fats_by_time and not fats_by_weekday and not fats_by_ship:
114
154
  return None
155
+ self.enrich_records_with_ship_details(records, year, month)
115
156
  return FatIngestionService.ingest_records(
116
157
  corporation_id=self.config.corporation_id,
117
158
  corporation_name=self.config.corporation_name,
@@ -165,6 +206,7 @@ class AfatScraperService:
165
206
  log_lines.append(f" - {period_label}: No pilot records found (skipped).")
166
207
  continue
167
208
 
209
+ self.enrich_records_with_ship_details(records, y, m)
168
210
  period = FatIngestionService.ingest_records(
169
211
  corporation_id=self.config.corporation_id,
170
212
  corporation_name=self.config.corporation_name,
@@ -453,6 +495,35 @@ class FatIngestionService:
453
495
 
454
496
  return fats_by_time, fats_by_weekday, fats_by_ship
455
497
 
498
+ @staticmethod
499
+ def parse_character_ship_chart(html_content: str) -> dict[str, int]:
500
+ """
501
+ Extracts the 'pie-ship' per-character ship-type breakdown chart from an INIT Auth
502
+ individual character statistics page (/statistics/character/<id>/<year>/<month>/).
503
+ """
504
+ ship_counts: dict[str, int] = {}
505
+
506
+ if not html_content or not html_content.strip():
507
+ return ship_counts
508
+
509
+ block_match = re.search(r'id="pie-ship".*?</script>', html_content, re.DOTALL)
510
+ if not block_match:
511
+ return ship_counts
512
+
513
+ chunk = block_match.group(0)
514
+ data_match = re.search(r"data:\s*\[([0-9,\s]+)\]", chunk)
515
+ labels_match = re.search(r"labels:\s*\[([^\]]+)\]", chunk)
516
+ if not data_match or not labels_match:
517
+ return ship_counts
518
+
519
+ counts = [int(x.strip()) for x in data_match.group(1).split(",") if x.strip()]
520
+ labels = [label.strip().strip("'\"") for label in labels_match.group(1).split(",")]
521
+ for label, count in zip(labels, counts):
522
+ if label and count > 0:
523
+ ship_counts[label] = ship_counts.get(label, 0) + count
524
+
525
+ return ship_counts
526
+
456
527
  @classmethod
457
528
  @transaction.atomic
458
529
  def ingest_records(
@@ -679,6 +750,8 @@ class FatAggregationService:
679
750
  "top_pilots_values": [],
680
751
  "fat_type_distribution": {},
681
752
  "ship_type_distribution": {},
753
+ "ship_table": [],
754
+ "pilot_ship_rows": [],
682
755
  "fats_by_time_labels": [f"{h:02d}:00" for h in range(24)],
683
756
  "fats_by_time_values": [0] * 24,
684
757
  "fats_by_weekday_labels": [
@@ -721,6 +794,7 @@ class FatAggregationService:
721
794
  "total_fats": 0,
722
795
  "period_fats": {p.id: 0 for p in periods},
723
796
  "fat_details": {h: 0 for h in dynamic_headers},
797
+ "ship_details": defaultdict(int),
724
798
  "active_months": 0,
725
799
  }
726
800
 
@@ -734,16 +808,32 @@ class FatAggregationService:
734
808
  pilot_records[name]["fat_details"][h] += count
735
809
  fat_type_distribution[h] += count
736
810
 
811
+ if e.ship_details and isinstance(e.ship_details, dict):
812
+ for ship, count in e.ship_details.items():
813
+ try:
814
+ c = int(count)
815
+ except (ValueError, TypeError):
816
+ continue
817
+ if c > 0:
818
+ pilot_records[name]["ship_details"][ship] += c
819
+
737
820
  # Convert to list and compute dynamic values list per pilot for template DataTables
738
821
  pilot_list = list(pilot_records.values())
739
822
  for p in pilot_list:
740
823
  p["dynamic_values"] = [p["fat_details"].get(h, 0) for h in dynamic_headers]
741
824
  p["period_values"] = [p["period_fats"].get(period.id, 0) for period in periods]
742
825
  p["avg_fats_per_month"] = round(p["total_fats"] / len(periods), 1) if periods else 0
826
+ p["ship_details"] = dict(p["ship_details"])
743
827
 
744
828
  # Sort pilots by total FATs descending
745
829
  pilot_list.sort(key=lambda x: x["total_fats"], reverse=True)
746
830
 
831
+ # Flat, sortable (pilot, ship, fats) rows for the per-pilot ship breakdown table
832
+ pilot_ship_rows: list[dict[str, Any]] = []
833
+ for p in pilot_list:
834
+ for ship, count in sorted(p["ship_details"].items(), key=lambda x: x[1], reverse=True):
835
+ pilot_ship_rows.append({"character_name": p["character_name"], "ship": ship, "fats": count})
836
+
747
837
  # Chart Data: Monthly Trends
748
838
  trend_labels = [p.label for p in periods]
749
839
  trend_values = [p.total_fats for p in periods]
@@ -816,6 +906,8 @@ class FatAggregationService:
816
906
  if other_ships_count > 0:
817
907
  ship_type_distribution[str(_("Other Ships"))] = other_ships_count
818
908
 
909
+ ship_table = [{"ship": ship, "fats": count} for ship, count in sorted_ships]
910
+
819
911
  return {
820
912
  "window": window,
821
913
  "periods": periods,
@@ -830,6 +922,8 @@ class FatAggregationService:
830
922
  "top_pilots_values": top_pilots_values,
831
923
  "fat_type_distribution": dict(fat_type_distribution),
832
924
  "ship_type_distribution": ship_type_distribution,
925
+ "ship_table": ship_table,
926
+ "pilot_ship_rows": pilot_ship_rows,
833
927
  "fats_by_time_labels": fats_by_time_labels,
834
928
  "fats_by_time_values": fats_by_time_values,
835
929
  "fats_by_weekday_labels": fats_by_weekday_labels,