add raw-data recording plan
Document the decision to store raw API JSON in the daemon and parse it in the tauri-app instead of mapping events to typed Rust structs.
This commit is contained in:
1 parent
953a920a23
commit
cfb49218f7
1 file changed
+246
@@ -0,0 +1,246 @@
|
|||||||
|
# Plan: Store Raw Data Only in record-daemon
|
||||||
|
|
||||||
|
## Problem
|
||||||
|
|
||||||
|
The record-daemon currently parses League Client API events into typed Rust structs (`GameEvent` enum with variants like `LpChangeInfo`, `KillEvent`, etc.) before storing them. This causes:
|
||||||
|
|
||||||
|
1. **Field name mismatches** — e.g., the LP_CHANGE event: the API returns `lpChange`/`lpAfter` but the daemon remaps to `leaguePointsDelta`/`leaguePoints`, creating confusion
|
||||||
|
2. **Data loss** — any API field not captured in the Rust struct is silently dropped
|
||||||
|
3. **Maintenance burden** — every API change requires daemon updates
|
||||||
|
4. **Redundant parsing** — the `raw_data` field already exists on `TimestampedEvent` but the parsed `GameEvent` is the primary data carrier
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
**The record-daemon should only store raw JSON data.** The tauri-app will parse the values it needs from the raw data.
|
||||||
|
|
||||||
|
The daemon still needs **minimal event classification** for state machine transitions (start/stop recording), but this can be derived from the URI alone — no typed structs needed.
|
||||||
|
|
||||||
|
## Current vs Proposed Data Flow
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
---
|
||||||
|
title: Current Data Flow
|
||||||
|
---
|
||||||
|
flowchart LR
|
||||||
|
A[WebSocket raw JSON] --> B[websocket.rs: parse into GameEvent enum]
|
||||||
|
B --> C[ParsedEvent with event + raw_data]
|
||||||
|
C --> D[main.rs: handle_game_event]
|
||||||
|
D --> E[TimestampedEvent with event: GameEvent + raw_data]
|
||||||
|
E --> F[Stored to disk as JSON]
|
||||||
|
F --> G[tauri-app reads timeline]
|
||||||
|
G --> H[Uses raw_data from metadata + event from TimestampedEvent]
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
---
|
||||||
|
title: Proposed Data Flow
|
||||||
|
---
|
||||||
|
flowchart LR
|
||||||
|
A[WebSocket raw JSON] --> B[websocket.rs: classify event type from URI only]
|
||||||
|
B --> C[ParsedEvent with event_type + raw_data + uri]
|
||||||
|
C --> D[main.rs: handle_game_event]
|
||||||
|
D --> E[TimestampedEvent with raw_data + uri + event_type]
|
||||||
|
E --> F[Stored to disk as JSON]
|
||||||
|
F --> G[tauri-app reads timeline]
|
||||||
|
G --> H[Parses everything from raw_data]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Detailed Changes
|
||||||
|
|
||||||
|
### 1. `record-daemon/src/lqp/events.rs` — Remove typed event structs
|
||||||
|
|
||||||
|
**Remove:**
|
||||||
|
- The entire `GameEvent` enum and all variant structs: `LpChangeInfo`, `MatchInfo`, `ChampSelectStartInfo`, `ChampionPickInfo`, `GameStartInfo`, `KillEvent`, `DeathEvent`, `ObjectiveEvent`, `InGameStats`, `GameEndInfo`, `PlayerStats`, `PhaseChangeInfo`, `ObjectiveType`, `Position`
|
||||||
|
- `RawEvent` and `EventData` enums
|
||||||
|
- `GameEvent::from_json()`, `GameEvent::description()`, `GameEvent::event_type_name()`, `GameEvent::is_relevant()`
|
||||||
|
|
||||||
|
**Keep:**
|
||||||
|
- `GameflowSession`, `QueueInfo`, `TeamMember`, `PlayerChampionSelection` — these are used by `client.rs` for REST API response parsing, not for event storage
|
||||||
|
- `PlayerGameMetadata`, `RunePage`, `SummonerSpells`, `ItemBuild`, `ItemInfo`, `PlayerIdentity`, `RuneSlot` — used for metadata, not event storage
|
||||||
|
|
||||||
|
**Add:**
|
||||||
|
- Event type constants:
|
||||||
|
```rust
|
||||||
|
pub const EVENT_TYPE_GAME_START: &str = "game_start";
|
||||||
|
pub const EVENT_TYPE_GAME_END: &str = "game_end";
|
||||||
|
pub const EVENT_TYPE_PHASE_CHANGE: &str = "phase_change";
|
||||||
|
pub const EVENT_TYPE_LP_CHANGE: &str = "lp_change";
|
||||||
|
pub const EVENT_TYPE_KILL: &str = "kill";
|
||||||
|
pub const EVENT_TYPE_DEATH: &str = "death";
|
||||||
|
pub const EVENT_TYPE_OBJECTIVE: &str = "objective";
|
||||||
|
pub const EVENT_TYPE_MATCH_FOUND: &str = "match_found";
|
||||||
|
pub const EVENT_TYPE_CHAMP_SELECT_START: &str = "champ_select_start";
|
||||||
|
pub const EVENT_TYPE_CHAMPION_PICK: &str = "champion_pick";
|
||||||
|
pub const EVENT_TYPE_STATS_UPDATE: &str = "stats_update";
|
||||||
|
pub const EVENT_TYPE_UNKNOWN: &str = "unknown";
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. `record-daemon/src/lqp/websocket.rs` — Simplify to classification only
|
||||||
|
|
||||||
|
**Change `ParsedEvent`:**
|
||||||
|
```rust
|
||||||
|
pub struct ParsedEvent {
|
||||||
|
/// Event type string derived from URI.
|
||||||
|
pub event_type: String,
|
||||||
|
/// The raw JSON data from the API — stored as-is.
|
||||||
|
pub raw_data: serde_json::Value,
|
||||||
|
/// The URI of the endpoint that triggered this event.
|
||||||
|
pub uri: String,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Replace all `parse_*` functions** with a single `classify_event(uri, event_type, data) -> ParsedEvent` that:
|
||||||
|
- Maps the URI to an event type string
|
||||||
|
- Generates a brief description from the raw data for logging
|
||||||
|
- Returns the raw data unchanged
|
||||||
|
|
||||||
|
The massive functions like `parse_lp_change_notification`, `parse_end_of_game_stats`, `parse_game_event`, `parse_game_start_event`, etc. are all replaced by simple URI-based classification. No field extraction, no JSON reconstruction.
|
||||||
|
|
||||||
|
### 3. `record-daemon/src/lqp/client.rs` — Use raw JSON for state updates
|
||||||
|
|
||||||
|
**Change `update_state_from_event`:**
|
||||||
|
- Instead of matching on `GameEvent::GameStart(info)`, match on `event_type == EVENT_TYPE_GAME_START` and extract `game_id` from `raw_data.get("gameId")`
|
||||||
|
- Same for `GameEvent::GameEnd` → check event_type string
|
||||||
|
|
||||||
|
**Change duplicate GameStart detection:**
|
||||||
|
- Extract `game_id` from `raw_data` instead of `parsed.event.game_id`
|
||||||
|
|
||||||
|
**Change live client event poller:**
|
||||||
|
- Use new `ParsedEvent` format
|
||||||
|
|
||||||
|
### 4. `record-daemon/src/state/machine.rs` — Use event type strings
|
||||||
|
|
||||||
|
**Change `process_event`:**
|
||||||
|
```rust
|
||||||
|
pub fn process_event(&self, event_type: &str, raw_data: &serde_json::Value) -> Option<StateTransition> {
|
||||||
|
match event_type {
|
||||||
|
EVENT_TYPE_GAME_START => Some(StateTransition::GameStarted),
|
||||||
|
EVENT_TYPE_GAME_END => Some(StateTransition::GameEnded),
|
||||||
|
EVENT_TYPE_PHASE_CHANGE => {
|
||||||
|
if raw_data.as_str() == Some("EndOfGame") && self.is_recording() {
|
||||||
|
Some(StateTransition::GameEnded)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. `record-daemon/src/timeline/store.rs` — Update TimestampedEvent
|
||||||
|
|
||||||
|
**New `TimestampedEvent`:**
|
||||||
|
```rust
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct TimestampedEvent {
|
||||||
|
pub video_timestamp: Duration,
|
||||||
|
pub game_timestamp: Option<Duration>,
|
||||||
|
pub timestamp: DateTime<Utc>,
|
||||||
|
/// Event type derived from URI — e.g. game_start, lp_change, kill.
|
||||||
|
pub event_type: String,
|
||||||
|
/// Brief human-readable description for logging.
|
||||||
|
#[serde(default)]
|
||||||
|
pub description: String,
|
||||||
|
/// The raw JSON data from the API — the single source of truth.
|
||||||
|
pub raw_data: serde_json::Value,
|
||||||
|
/// URI of the endpoint that triggered this event.
|
||||||
|
pub uri: String,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Key changes:
|
||||||
|
- Remove `event: GameEvent` field
|
||||||
|
- `raw_data` is now `serde_json::Value` — required, not `Option`
|
||||||
|
- `uri` is now `String` — required, not `Option`
|
||||||
|
- `description` gets `#[serde(default)]` for backward compat
|
||||||
|
|
||||||
|
**Backward compatibility:** serde ignores unknown fields by default, so old JSON files with `"event": {...}` will still load — the `event` key is simply ignored. New fields `raw_data` and `uri` get `#[serde(default)]` so old files without them get empty defaults.
|
||||||
|
|
||||||
|
### 6. `record-daemon/src/timeline/mod.rs` — Update Timeline methods
|
||||||
|
|
||||||
|
- Remove `add_event()` — no longer needed since we always have raw data
|
||||||
|
- Rename `add_event_with_raw()` to `add_event()` or simplify
|
||||||
|
- Update `event_type_name()` to just return the event_type string directly
|
||||||
|
|
||||||
|
### 7. `record-daemon/src/main.rs` — Update handle_game_event
|
||||||
|
|
||||||
|
- Use `parsed.event_type` instead of matching on `GameEvent` variants
|
||||||
|
- Extract `game_id` from `parsed.raw_data` for recording metadata
|
||||||
|
- Pass `event_type` string to state machine
|
||||||
|
- Create `TimestampedEvent` with raw data only
|
||||||
|
|
||||||
|
### 8. `record-daemon/src/lqp/mod.rs` — Update exports
|
||||||
|
|
||||||
|
- Remove `GameEvent` and all variant struct exports
|
||||||
|
- Add event type constant exports
|
||||||
|
- Update `ParsedEvent` export
|
||||||
|
|
||||||
|
### 9. `tauri-app/src/types/timeline.ts` — Update TypeScript types
|
||||||
|
|
||||||
|
**Update `TimestampedEvent`:**
|
||||||
|
```typescript
|
||||||
|
export interface TimestampedEvent {
|
||||||
|
video_timestamp: [number, number];
|
||||||
|
game_timestamp: [number, number] | null;
|
||||||
|
timestamp: string;
|
||||||
|
event_type: string;
|
||||||
|
description: string;
|
||||||
|
/** Raw JSON data from the League Client API — parse as needed based on event_type and uri */
|
||||||
|
raw_data: Record<string, unknown>;
|
||||||
|
/** URI of the API endpoint that produced this event */
|
||||||
|
uri: string;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Add LP change parsing from raw data:**
|
||||||
|
```typescript
|
||||||
|
export interface LpChangeData {
|
||||||
|
queueType: string;
|
||||||
|
leaguePointsDelta: number; // from API field lpChange
|
||||||
|
leaguePoints: number; // from API field lpAfter
|
||||||
|
tier: string;
|
||||||
|
division?: string;
|
||||||
|
// ... all other fields from the raw API response
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLpChangeData(event: TimestampedEvent): LpChangeData | null {
|
||||||
|
if (event.event_type !== 'lp_change') return null;
|
||||||
|
const raw = event.raw_data;
|
||||||
|
return {
|
||||||
|
queueType: raw.queueType as string ?? 'UNKNOWN',
|
||||||
|
leaguePointsDelta: raw.lpChange as number ?? 0,
|
||||||
|
leaguePoints: raw.lpAfter as number ?? 0,
|
||||||
|
tier: raw.tier as string ?? 'UNRANKED',
|
||||||
|
division: raw.division as string | undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Update event categorization** — `getEventCategory()` and `getEventLabel()` already use `event_type` string, so they should work with minimal changes.
|
||||||
|
|
||||||
|
### 10. `tauri-app/src/components/GameReview.vue` — Update event rendering
|
||||||
|
|
||||||
|
- Any code accessing `event.event` (typed event data) should use `event.raw_data` instead
|
||||||
|
- Kill/death/objective details should be parsed from `raw_data` based on `event_type`
|
||||||
|
|
||||||
|
## Migration Strategy
|
||||||
|
|
||||||
|
- Old timeline JSON files on disk will continue to load because serde ignores unknown fields
|
||||||
|
- Old files will have `raw_data: {}` and `uri: ""` defaults — the old `event` field data is lost for display purposes, but the metadata fields (`raw_session`, `raw_end_game_stats`, etc.) are unaffected
|
||||||
|
- New recordings will have complete raw data in every event
|
||||||
|
|
||||||
|
## Files Modified
|
||||||
|
|
||||||
|
| File | Change |
|
||||||
|
|------|--------|
|
||||||
|
| `record-daemon/src/lqp/events.rs` | Remove GameEvent enum and variants; add event type constants |
|
||||||
|
| `record-daemon/src/lqp/websocket.rs` | Replace parse functions with URI-based classification; update ParsedEvent |
|
||||||
|
| `record-daemon/src/lqp/client.rs` | Use raw JSON for state updates and dedup |
|
||||||
|
| `record-daemon/src/lqp/mod.rs` | Update exports |
|
||||||
|
| `record-daemon/src/state/machine.rs` | Use event_type string instead of GameEvent |
|
||||||
|
| `record-daemon/src/timeline/store.rs` | Update TimestampedEvent struct |
|
||||||
|
| `record-daemon/src/timeline/mod.rs` | Update Timeline methods |
|
||||||
|
| `record-daemon/src/main.rs` | Update handle_game_event to use raw data |
|
||||||
|
| `tauri-app/src/types/timeline.ts` | Update TimestampedEvent; add raw data parsing helpers |
|
||||||
|
| `tauri-app/src/components/GameReview.vue` | Use raw_data for event details |
|
||||||
Reference in new issue
Block a user