> ## Documentation Index
> Fetch the complete documentation index at: https://docs.highailabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stats & Analytics Flow

> The complete stats and analytics user flow — overview metrics, activity heatmap, spending analysis, predictive insights, and data-driven decision making.

## Overview

The Stats & Analytics dashboard transforms raw consumption data into actionable intelligence. This flow documents how users access, navigate, and interpret their cannabis analytics across four tabs plus predictive insights.

## Dashboard Access Flow

```mermaid theme={null}
graph TD
    A[User Wants Stats] --> B{Entry Point}

    B -->|You Tab| C[Profile Screen]
    C --> C1[Intelligence Section]
    C1 --> C2[Tap Full Analytics]

    B -->|Dashboard| D[Stats Preview Card]
    D --> D1[Tap for Full View]

    B -->|Ask AI| E[My Stats Tool]
    E --> E1[Stats Summary Card]

    C2 --> F[Stats Dashboard]
    D1 --> F
```

## Four-Tab Navigation

```mermaid theme={null}
graph TD
    A[Stats Dashboard] --> B{Tab Selection}

    B -->|Overview| C[Overview Tab]
    C --> C1[Hero Stats Grid]
    C --> C2[Lifetime Metrics]
    C --> C3[Dispensary Rankings]
    C --> C4[Top Strains List]

    B -->|Activity| D[Activity Tab]
    D --> D1[GitHub-Style Heatmap]
    D --> D2[Year Navigation]
    D --> D3[Shopping Patterns]
    D --> D4[Purchase Frequency]
    D --> D5[Preferred Shopping Day]

    B -->|Spending| E[Spending Tab]
    E --> E1[Monthly Bar Chart]
    E --> E2[Time Range Toggle: 3/6/12mo]
    E --> E3[Month-over-Month Comparison]
    E --> E4[Spending Insights]

    B -->|My Strains| F[My Strains Tab]
    F --> F1[Collection Summary]
    F --> F2[Searchable Strain List]
    F --> F3[Per-Strain Analytics]
    F --> F4[Sort: Ranking/Name/Most Consumed]
```

## Data Population Journey

```mermaid theme={null}
graph TD
    A[New User - No Data] --> B[Empty Stats State]
    B --> B1[Add data to see stats CTA]

    B1 --> C{First Data Entry}

    C -->|1 Order| D[Basic Metrics Appear]
    D --> D1[Total Orders: 1]
    D --> D2[Lifetime Spent: $X]
    D --> D3[Unique Strains: X]

    C -->|Gmail Import| E[Rich Metrics Instantly]
    E --> E1[Months of history populated]
    E --> E2[Spending charts filled]
    E --> E3[Activity heatmap backfilled]
    E --> E4[Dispensary rankings visible]

    D --> F[Ongoing Data Growth]
    E --> F

    F --> G{Data Threshold Milestones}
    G -->|5+ events| H[Predictive Analytics Unlock]
    H --> H1[Consumption Velocity]
    H --> H2[Cost Optimization]
    H --> H3[Restock Prediction]

    G -->|10+ orders| I[Shopping Patterns Rich]
    G -->|3+ months data| J[Spending Trends Meaningful]
    G -->|20+ strains| K[My Strains Tab Valuable]
```

## Predictive Analytics Flow

```mermaid theme={null}
graph TD
    A[5+ Consumption Events Logged] --> B[Predictive Engine Activates]

    B --> C[Consumption Velocity Card]
    C --> C1[Rate of consumption over time]
    C --> C2[Trend direction: increasing/decreasing/stable]

    B --> D[Cost Optimization Card]
    D --> D1[Monthly estimated savings]
    D --> D2[Price comparison across dispensaries]
    D --> D3[Alternative strain suggestions]

    B --> E[Restock Prediction Card]
    E --> F{For Each Active Stash Item}

    F --> G[Calculate Days Remaining]
    G --> H{Alert Level}
    H -->|Normal| I[Green: Comfortable supply]
    H -->|Low| J[Yellow: Running low]
    H -->|Critical| K[Red: Days until empty]
    H -->|Empty| L[Gray: Depleted]
```

## Activity Heatmap Interaction

```mermaid theme={null}
graph TD
    A[Activity Tab Loaded] --> B[Current Year Heatmap]
    B --> C[365 Day Grid]

    C --> D{Day Cell Coloring}
    D -->|No activity| E[Empty/Light]
    D -->|1-2 events| F[Light green]
    D -->|3-4 events| G[Medium green]
    D -->|5+ events| H[Dark green]

    B --> I[Year Navigation]
    I -->|Previous Year| J[Load Historical Data]
    I -->|Next Year| K[Return to Current]

    B --> L[Event Types Counted]
    L --> L1[Stash additions]
    L --> L2[Consumption logs]
    L --> L3[Order uploads]
    L --> L4[Favorites toggled]
    L --> L5[Rankings completed]
```

## Spending Analysis Flow

```mermaid theme={null}
sequenceDiagram
    participant U as User
    participant App as High IQ
    participant DB as Convex

    U->>App: Open Spending Tab
    App->>DB: Fetch orders with amounts
    DB-->>App: Order history data

    App->>App: Calculate monthly totals
    App->>App: Compute MoM comparison
    App->>App: Generate spending insights
    App->>U: Display bar chart + metrics

    U->>App: Toggle time range (3/6/12mo)
    App->>App: Recalculate for new range
    App->>U: Update chart + metrics

    U->>App: View MoM comparison
    App->>U: Show side-by-side metrics
    Note over App,U: Total spent, order count, unique strains, avg order value
```

## Edge Cases

| Scenario                               | Behavior                                           |
| -------------------------------------- | -------------------------------------------------- |
| Zero orders                            | Empty states with "Add data" CTAs on all tabs      |
| One order only                         | Basic metrics shown, charts have single data point |
| All orders same dispensary             | Dispensary rankings shows single entry             |
| Orders with no prices                  | Spending tab excludes, note shown                  |
| Very old data (5+ years)               | Heatmap navigable by year, all data preserved      |
| Consumption preferences not set        | Restock predictions disabled with setup prompt     |
| Strain in stats but deleted from stash | Historical data preserved in analytics             |
| Large dataset (500+ orders)            | Computed in real-time, may show brief loading      |
| Offline access                         | Cached analytics available, refresh disabled       |

## Related Flows

<CardGroup cols={2}>
  <Card title="Order Upload" icon="receipt" href="/help/user-flows/order-upload">
    Data sources that power analytics.
  </Card>

  <Card title="Stash Management" icon="box" href="/help/user-flows/stash-management">
    Consumption data feeding predictions.
  </Card>

  <Card title="Achievement System" icon="medal" href="/help/user-flows/achievements">
    Stats driving achievement progress.
  </Card>

  <Card title="User Personas" icon="users" href="/help/user-flows/personas">
    How different personas use analytics.
  </Card>
</CardGroup>
