@extends('layouts.main') @section('container')

Vessel Fuel Refill Tracking

Monitor fuel consumption patterns and predict future refills

@foreach ($vesselData as $vesselId => $data) @php // Enhanced prediction calculation with proper date handling $daysBetween = []; $totalVolume = 0; $totalDays = 0; $refillDates = []; $refillVolumes = []; // Collect refill dates and volumes foreach ($data['refills'] as $refill) { $refillDates[] = $refill['date']; $refillVolumes[] = $refill['volume']; } // Calculate days between refills and total consumption if (count($refillDates) > 1) { for ($i = 1; $i < count($refillDates); $i++) { $diff = $refillDates[$i]->diffInDays($refillDates[$i - 1]); $daysBetween[] = $diff; $totalDays += $diff; $totalVolume += $refillVolumes[$i - 1]; } $avgDaysBetween = round($totalDays / count($daysBetween)); $avgConsumption = $totalVolume / $totalDays; // Calculate standard deviation for accuracy estimation $variance = 0; foreach ($daysBetween as $days) { $variance += pow($days - $avgDaysBetween, 2); } $stdDev = count($daysBetween) > 1 ? sqrt($variance / (count($daysBetween) - 1)) : 0; // Determine accuracy level based on standard deviation $accuracyPercentage = $stdDev > 7 ? ($stdDev > 14 ? 'Low' : 'Medium') : 'High'; // Get the most recent refill date $lastRefill = end($refillDates); // Calculate days since last refill $daysSinceLast = now()->diffInDays($lastRefill); // Calculate next predicted date (must be in the future) $nextPredicted = $lastRefill->copy()->addDays($avgDaysBetween); // Adjust prediction if it's in the past if ($nextPredicted < now()) { // Estimate current fuel level based on average consumption $estimatedCurrentLevel = end($refillVolumes) - $daysSinceLast * $avgConsumption; // Calculate remaining days based on current level $remainingDays = $estimatedCurrentLevel > 0 ? round($estimatedCurrentLevel / $avgConsumption) : 0; // Set new prediction (today + remaining days + buffer) $nextPredicted = now()->addDays(max(1, $remainingDays)); } // Ensure prediction is at least 1 day in the future if ($nextPredicted <= now()) { $nextPredicted = now()->addDay(); } } @endphp
{{ $data['name'] }}
{{ $data['fuel_type'] }} @if (isset($avgConsumption)) {{ round($avgConsumption, 1) }} L/day @endif
Refills: {{ count($data['refills']) }}
Total Volume: {{ number_format($data['total_volume']) }} L
@if (isset($avgDaysBetween) && isset($nextPredicted))
Avg. Interval: {{ $avgDaysBetween }} days
Next Predicted:
{{ $accuracyPercentage }} accuracy
{{ $nextPredicted->format('M d, Y') }}
@endif
@endforeach
@foreach ($vesselData as $vesselId => $data)
{{ $data['name'] }} {{ $data['total_volume'] }} L total
@endforeach
@foreach ($vesselData as $vesselId => $data) @php // Calculate consumption statistics for this vessel $consumptionStats = []; $refillDates = array_column($data['refills'], 'date'); $refillVolumes = array_column($data['refills'], 'volume'); if (count($refillDates) > 1) { for ($i = 1; $i < count($refillDates); $i++) { $days = $refillDates[$i]->diffInDays($refillDates[$i - 1]); $consumption = $refillVolumes[$i - 1] / $days; $consumptionStats[] = [ 'days' => $days, 'consumption' => $consumption, 'start_date' => $refillDates[$i - 1], 'end_date' => $refillDates[$i], ]; } $avgConsumption = array_sum(array_column($consumptionStats, 'consumption')) / count($consumptionStats); $sumSquares = 0; foreach ($consumptionStats as $stat) { $sumSquares += pow($stat['consumption'] - $avgConsumption, 2); } $stdDev = count($consumptionStats) > 1 ? sqrt($sumSquares / (count($consumptionStats) - 1)) : 0; // Determine pattern if we have enough data $patternAnalysis = ''; if (count($consumptionStats) > 3) { if ($stdDev < $avgConsumption * 0.2) { $patternAnalysis = 'This vessel shows consistent fuel consumption patterns with low variability. Predictions should be reliable.'; } elseif ($stdDev < $avgConsumption * 0.4) { $patternAnalysis = 'Moderate variability in consumption patterns. Predictions may need adjustment based on recent trends.'; } else { $patternAnalysis = 'High variability in consumption patterns. Consider additional factors for accurate predictions.'; } } // Recalculate prediction for display in this section $lastRefill = end($refillDates); $daysSinceLast = now()->diffInDays($lastRefill); $avgDaysBetween = round( array_sum(array_column($consumptionStats, 'days')) / count($consumptionStats), ); $nextPredicted = $lastRefill->copy()->addDays($avgDaysBetween); // Adjust if prediction is in the past if ($nextPredicted < now()) { $estimatedCurrentLevel = end($refillVolumes) - $daysSinceLast * $avgConsumption; $remainingDays = $estimatedCurrentLevel > 0 ? round($estimatedCurrentLevel / $avgConsumption) : 0; $nextPredicted = now()->addDays(max(1, $remainingDays)); } // Final check to ensure prediction is in the future if ($nextPredicted <= now()) { $nextPredicted = now()->addDay(); } // Recalculate accuracy for display $accuracyPercentage = $stdDev > 7 ? ($stdDev > 14 ? 'Low' : 'Medium') : 'High'; } @endphp
{{ $data['name'] }} - Refill History & Analysis
{{ $data['fuel_type'] }} {{ count($data['refills']) }} Refills
Refill Pattern Analysis
@if (count($consumptionStats) > 0)
Pattern Insights

Average consumption: {{ round($avgConsumption, 1) }} L/day
Standard deviation: {{ round($stdDev, 1) }} days
@if ($patternAnalysis) {{ $patternAnalysis }} @else Collecting more data will improve prediction accuracy. @endif

@endif @if (count($consumptionStats) > 0)
Refill Prediction
Next Predicted Refill:
{{ $nextPredicted->format('F j, Y') }}
{{ $nextPredicted->diffForHumans() }}
{{ $avgDaysBetween }} day cycle
{{ $accuracyPercentage }} confidence
@if ($daysSinceLast > $avgDaysBetween)
This vessel is overdue for refill by {{ $daysSinceLast - $avgDaysBetween }} days
@endif
@endif
Refill History Timeline
@foreach ($data['refills'] as $index => $refill)
{{ $refill['date']->format('M j, Y') }}
{{ $refill['volume'] }} L

{{ $refill['location'] }}

@if ($index > 0)

{{ $refill['date']->diffInDays($data['refills'][$index - 1]['date']) }} days since last refill

@endif
@endforeach
@endforeach
@endsection