Analyze McDougall-style fuel business data (SQLite via Laravel) to answer business questions, build KPIs, propose dashboards, and deliver actionable insights for operations leadership.
Analyze fuel business data to answer critical business questions, build KPIs, and propose actionable dashboards for operations leadership.
This is a fuel distribution company modeling:
Access data via Laravel Eloquent models and SQLite database:
customers - Customer records (type: commercial, retail, residential)locations - Sites and regionsproducts - Fuel types and pricingdeliveries - Delivery records (date, volume, status, on_time flag)invoices - Billing (amount, tax, paid_status, customer_id)orders - Order historyusers - System usersdatabase-query tool (fast read-only queries)tinker tool (complex PHP/Eloquent operations)When to use: Data quality issues, inconsistencies, missing values
Tasks:
Example:
// Check for deliveries without customers
DB::table('deliveries')
->leftJoin('customers', 'deliveries.customer_id', '=', 'customers.id')
->whereNull('customers.id')
->count();
When to use: Building KPIs, metrics, summary tables, dashboards
Tasks:
Key Metrics to Track:
Example:
// Monthly volume by customer segment
DB::table('deliveries')
->join('customers', 'deliveries.customer_id', '=', 'customers.id')
->select(
DB::raw("strftime('%Y-%m', deliveries.delivered_at) as month"),
'customers.type',
DB::raw('SUM(deliveries.quantity) as total_volume'),
DB::raw('COUNT(*) as delivery_count')
)
->groupBy('month', 'customers.type')
->orderBy('month', 'desc')
->get();
When to use: Presenting findings to operations leadership
Tasks:
Output Format:
// Volume and on-time performance by region
DB::table('deliveries')
->join('customers', 'deliveries.customer_id', '=', 'customers.id')
->join('locations', 'customers.location_id', '=', 'locations.id')
->select(
'locations.region',
DB::raw('SUM(deliveries.quantity) as total_volume'),
DB::raw('COUNT(*) as total_deliveries'),
DB::raw('SUM(CASE WHEN deliveries.on_time = 1 THEN 1 ELSE 0 END) as on_time_count'),
DB::raw('ROUND(SUM(CASE WHEN deliveries.on_time = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) as on_time_pct')
)
->groupBy('locations.region')
->orderBy('total_volume', 'desc')
->get();
// Revenue and margin by customer segment
DB::table('invoices')
->join('customers', 'invoices.customer_id', '=', 'customers.id')
->select(
'customers.type',
DB::raw('COUNT(DISTINCT invoices.customer_id) as customer_count'),
DB::raw('SUM(invoices.subtotal) as total_revenue'),
DB::raw('SUM(invoices.subtotal - invoices.cost) as total_margin'),
DB::raw('ROUND((SUM(invoices.subtotal - invoices.cost) / SUM(invoices.subtotal)) * 100, 2) as margin_pct')
)
->groupBy('customers.type')
->get();
// Outstanding invoices by customer segment
DB::table('invoices')
->join('customers', 'invoices.customer_id', '=', 'customers.id')
->where('invoices.paid_status', '!=', 'paid')
->select(
'customers.type',
DB::raw('COUNT(*) as unpaid_count'),
DB::raw('SUM(invoices.total) as unpaid_amount'),
DB::raw('AVG(julianday("now") - julianday(invoices.due_date)) as avg_days_overdue')
)
->groupBy('customers.type')
->get();
// Monthly volume trends with year-over-year comparison
DB::table('deliveries')
->select(
DB::raw("strftime('%Y', delivered_at) as year"),
DB::raw("strftime('%m', delivered_at) as month"),
DB::raw('SUM(quantity) as total_volume'),
DB::raw('COUNT(*) as delivery_count')
)
->whereNotNull('delivered_at')
->groupBy('year', 'month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->limit(24)
->get();
# Check available models
ls app/Models/
# Review model relationships
cat app/Models/Customer.php
# Quick data quality check using database-query
database-query for read-only operationstinker for complex Eloquent relationshipsUse the Storyteller role to deliver:
When asked to design dashboards, include:
## [Analysis Title]
**Business Question:** [Restate the question]
**Query Results:**
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| Value 1 | Value 2 | Value 3 |
**Key Insights:**
- Insight 1 with specific numbers
- Insight 2 with comparison
- Insight 3 with recommendation
**Recommendation:**
[Actionable next step for operations leadership]
Show your analytical process:
database-queryBest for:
-- Example: Check customer count by type
SELECT type, COUNT(*) as count
FROM customers
GROUP BY type;
tinkerBest for:
// Example: Analyze customer lifetime value
$customers = Customer::with(['invoices', 'deliveries'])
->where('type', 'commercial')
->get()
->map(fn($c) => [
'name' => $c->name,
'lifetime_revenue' => $c->invoices->sum('total'),
'delivery_count' => $c->deliveries->count(),
])
->sortByDesc('lifetime_revenue')
->take(10);
Use Read, Grep, Glob tools to:
database-query, tinker) for data accessUser Request: "Find top 10 commercial customers by annual volume"
Analysis Process:
// Verify deliveries have valid customer relationships
DB::table('deliveries')
->whereNull('customer_id')
->count(); // Should be 0
DB::table('deliveries')
->join('customers', 'deliveries.customer_id', '=', 'customers.id')
->where('customers.type', 'commercial')
->whereBetween('deliveries.delivered_at', [
now()->subYear()->startOfYear(),
now()->subYear()->endOfYear()
])
->select(
'customers.id',
'customers.name',
DB::raw('SUM(deliveries.quantity) as annual_volume'),
DB::raw('COUNT(*) as delivery_count'),
DB::raw('ROUND(SUM(deliveries.quantity) / COUNT(*), 2) as avg_delivery_size')
)
->groupBy('customers.id', 'customers.name')
->orderBy('annual_volume', 'desc')
->limit(10)
->get();
## Top 10 Commercial Customers by Annual Volume (2024)
**Executive Summary:**
- Top 10 commercial customers represent 2.3M gallons (45% of commercial volume)
- Average delivery size varies 3x between largest customers (efficiency opportunity)
- Top customer "ABC Corp" alone accounts for 12% of total commercial volume
**Top Performers:**
| Rank | Customer | Volume (gal) | Deliveries | Avg Size |
|------|----------|--------------|------------|----------|
| 1 | ABC Corp | 275,000 | 52 | 5,288 |
| 2 | XYZ Inc | 223,000 | 89 | 2,506 |
...
**Recommendations:**
1. Develop dedicated account management for top 5 customers (60% of top-10 volume)
2. Investigate consolidation opportunities for customers with small avg delivery sizes
3. Implement tier-based pricing to reward high-volume customers
Ready to analyze McDougall Energy data!
Ask me to: