diff --git a/.dockerignore b/.dockerignore index 01bcb40..5517ac1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,6 +7,8 @@ frontend/ # Data directory (runtime data, not needed for build) data/ +.cache + # Build artifacts *.exe *.log diff --git a/Dockerfile b/Dockerfile index 7fbb35e..a63a2a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ WORKDIR /app COPY go.mod go.sum ./ RUN go mod download +COPY sqlite-latest.sqlite ./ COPY . . RUN apt-get update && apt-get install -y \ diff --git a/templates.go b/templates.go deleted file mode 100644 index e369737..0000000 --- a/templates.go +++ /dev/null @@ -1,86 +0,0 @@ -package main - -import ( - "embed" - "strings" - "text/template" -) - -//go:embed templates/*.sql.tmpl -var templateFS embed.FS - -var ( - MainQueryTmpl *template.Template - ShipBreakdownTmpl *template.Template - SystemBreakdownTmpl *template.Template - ModuleStatsTmpl *template.Template - ComprehensiveStatsTmpl *template.Template -) - -func init() { - var err error - - // Parse templates once at startup - MainQueryTmpl, err = template.ParseFS(templateFS, "templates/main_query.sql.tmpl") - if err != nil { - panic("failed to parse main_query template: " + err.Error()) - } - - ShipBreakdownTmpl, err = template.ParseFS(templateFS, "templates/ship_breakdown.sql.tmpl") - if err != nil { - panic("failed to parse ship_breakdown template: " + err.Error()) - } - - SystemBreakdownTmpl, err = template.ParseFS(templateFS, "templates/system_breakdown.sql.tmpl") - if err != nil { - panic("failed to parse system_breakdown template: " + err.Error()) - } - - ModuleStatsTmpl, err = template.ParseFS(templateFS, "templates/module_stats.sql.tmpl") - if err != nil { - panic("failed to parse module_stats template: " + err.Error()) - } - - ComprehensiveStatsTmpl, err = template.ParseFS(templateFS, "templates/comprehensive_stats.sql.tmpl") - if err != nil { - panic("failed to parse comprehensive_stats template: " + err.Error()) - } -} - -// ExecuteTemplate executes a pre-parsed template and builds args -func ExecuteTemplate(tmpl *template.Template, data interface{}) (string, []interface{}, error) { - var queryBuf strings.Builder - if err := tmpl.Execute(&queryBuf, data); err != nil { - return "", nil, err - } - - query := strings.TrimSpace(queryBuf.String()) - args := []interface{}{} - - if qp, ok := data.(QueryParams); ok { - if qp.Ship > 0 { - args = append(args, qp.Ship) - } - if len(qp.Systems) > 0 { - args = append(args, qp.Systems) - } - if len(qp.Modules) > 0 { - args = append(args, qp.Modules) - } - } else if msData, ok := data.(ModuleStatsData); ok { - args = append(args, msData.KillmailIDs) - } else if csData, ok := data.(ComprehensiveStatsData); ok { - if csData.Ship > 0 { - args = append(args, csData.Ship) - } - if len(csData.Systems) > 0 { - args = append(args, csData.Systems) - } - if len(csData.Modules) > 0 { - args = append(args, csData.Modules) - } - args = append(args, csData.KillmailLimit) - } - - return query, args, nil -} diff --git a/templates/comprehensive_stats.sql.tmpl b/templates/comprehensive_stats.sql.tmpl deleted file mode 100644 index 75b6e30..0000000 --- a/templates/comprehensive_stats.sql.tmpl +++ /dev/null @@ -1,53 +0,0 @@ -WITH filtered_killmails AS ( - SELECT - fk.killmail_id, - fk.solar_system_id, - fk.victim_ship_type_id - FROM killmails fk - {{if .HasModules}} - INNER JOIN modules fm ON fk.killmail_id = fm.killmail_id - {{end}} - WHERE 1=1 - {{if .Ship}}AND fk.victim_ship_type_id = ?{{end}} - {{if .Systems}}AND fk.solar_system_id IN ?{{end}} - {{if .HasModules}}AND fm.item_type_id IN ?{{end}} -), -ship_stats AS ( - SELECT - victim_ship_type_id as id, - COUNT(*) as count - FROM filtered_killmails - GROUP BY victim_ship_type_id -), -system_stats AS ( - SELECT - solar_system_id as id, - COUNT(*) as count - FROM filtered_killmails - GROUP BY solar_system_id -), -module_stats AS ( - SELECT - fm.item_type_id, - fm.slot, - COUNT(DISTINCT fm.killmail_id) as count - FROM modules fm - WHERE fm.killmail_id IN (SELECT killmail_id FROM filtered_killmails) - GROUP BY fm.item_type_id, fm.slot -), -limited_killmails AS ( - SELECT killmail_id - FROM filtered_killmails - ORDER BY killmail_id - LIMIT ? -) -SELECT - toString(COUNT(*)) as total_killmails, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(id), groupArray(count))) FROM ship_stats) as ships, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(id), groupArray(count))) FROM system_stats) as systems, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(item_type_id), groupArray(count))) FROM module_stats WHERE slot = 'High') as modules_high, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(item_type_id), groupArray(count))) FROM module_stats WHERE slot = 'Mid') as modules_mid, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(item_type_id), groupArray(count))) FROM module_stats WHERE slot = 'Low') as modules_low, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(item_type_id), groupArray(count))) FROM module_stats WHERE slot = 'Rig') as modules_rigs, - (SELECT arraySort(x -> x.1, arrayZip(groupArray(item_type_id), groupArray(count))) FROM module_stats WHERE slot = 'Drone') as modules_drones, - (SELECT groupArray(killmail_id) FROM limited_killmails) as killmail_ids diff --git a/templates/main_query.sql.tmpl b/templates/main_query.sql.tmpl deleted file mode 100644 index efae6be..0000000 --- a/templates/main_query.sql.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -SELECT - fk.killmail_id, - fk.solar_system_id, - fk.victim_ship_type_id -FROM killmails fk -{{if .HasModules}} -INNER JOIN modules fm ON fk.killmail_id = fm.killmail_id -{{end}} -WHERE 1=1 -{{if .Ship}}AND fk.victim_ship_type_id = ?{{end}} -{{if .Systems}}AND fk.solar_system_id IN ?{{end}} -{{if .HasModules}}AND fm.item_type_id IN ?{{end}} \ No newline at end of file diff --git a/templates/module_stats.sql.tmpl b/templates/module_stats.sql.tmpl deleted file mode 100644 index 539415e..0000000 --- a/templates/module_stats.sql.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -SELECT - fm.item_type_id, - fm.slot, - COUNT(DISTINCT fm.killmail_id) as count -FROM modules fm -WHERE fm.killmail_id IN ? -GROUP BY fm.item_type_id, fm.slot -ORDER BY count DESC \ No newline at end of file diff --git a/templates/ship_breakdown.sql.tmpl b/templates/ship_breakdown.sql.tmpl deleted file mode 100644 index 9b0add0..0000000 --- a/templates/ship_breakdown.sql.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -SELECT - fk.victim_ship_type_id, - COUNT(*) as count -FROM killmails fk -{{if .HasModules}} -INNER JOIN modules fm ON fk.killmail_id = fm.killmail_id -{{end}} -WHERE 1=1 -{{if .Ship}}AND fk.victim_ship_type_id = ?{{end}} -{{if .Systems}}AND fk.solar_system_id IN ?{{end}} -{{if .HasModules}}AND fm.item_type_id IN ?{{end}} -GROUP BY fk.victim_ship_type_id ORDER BY count DESC \ No newline at end of file diff --git a/templates/system_breakdown.sql.tmpl b/templates/system_breakdown.sql.tmpl deleted file mode 100644 index 34823a1..0000000 --- a/templates/system_breakdown.sql.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -SELECT - fk.solar_system_id, - COUNT(*) as count -FROM killmails fk -{{if .HasModules}} -INNER JOIN modules fm ON fk.killmail_id = fm.killmail_id -{{end}} -WHERE 1=1 -{{if .Ship}}AND fk.victim_ship_type_id = ?{{end}} -{{if .Systems}}AND fk.solar_system_id IN ?{{end}} -{{if .HasModules}}AND fm.item_type_id IN ?{{end}} -GROUP BY fk.solar_system_id ORDER BY count DESC \ No newline at end of file diff --git a/utils.go b/utils.go deleted file mode 100644 index 0a7cb91..0000000 --- a/utils.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -func GetModuleSlotByKillmailFlag(flag int64) ModuleSlot { - // Pulled these right out of the fucking database - // | Flag ID | Slot Type | Position | Meaning | - // |---------|-----------------|----------|------------------------------| - // | 11-18 | Low Slots | 1-8 | Low power modules | - // | 19-26 | Mid Slots | 1-8 | Medium power modules | - // | 27-34 | High Slots | 1-8 | High power modules | - // | 92-99 | Rig Slots | 1-8 | Rig modules | - // | 125-132 | SubSystem Slots | 1-8 | Subsystem modules (T3 ships) | - switch { - case flag >= 11 && flag <= 18: - return ModuleSlotLow - case flag >= 19 && flag <= 26: - return ModuleSlotMid - case flag >= 27 && flag <= 34: - return ModuleSlotHigh - case flag >= 92 && flag <= 99: - return ModuleSlotRig - case flag >= 125 && flag <= 132: - return ModuleSlotSubsystem - case flag == 87: - return ModuleSlotDrone - } - return ModuleSlotOther -}