loadStats();
}
public function loadStats()
{
// get total treatments
$this->totalTreatments = Treatment::count();
// get average success rate
$this->averageSuccessRate = round(Treatment::avg('successRate'), 1);
// get species statistics
$this->speciesStats = Species::withCount('treatments')
->withAvg('treatments', 'successRate')
->having('treatments_count', '>', 0)
->get();
// get recent treatments
$this->recentTreatments = Treatment::with('species')
->latest()
->take(5)
->get();
// get success rate by ems concentration
$this->successRateByConcentration = Treatment::select(
'emsConcentration',
DB::raw('AVG(successRate) as avg_success_rate'),
DB::raw('COUNT(*) as count')
)
->groupBy('emsConcentration')
->get();
// get temperature statistics
$this->temperatureStats = [
'avg_lowest' => round(Treatment::avg('lowestTemp'), 1),
'avg_highest' => round(Treatment::avg('highestTemp'), 1),
'most_successful_range' => Treatment::where('successRate', '>', 50)
->select(
DB::raw('ROUND(AVG(lowestTemp), 1) as avg_low'),
DB::raw('ROUND(AVG(highestTemp), 1) as avg_high')
)
->first()
];
}
}; ?>
Total Treatments
{{ $totalTreatments }}
Average Success Rate
{{ $averageSuccessRate }}%
Optimal Temperature Range
{{ $temperatureStats['most_successful_range']->avg_low }}°C - {{ $temperatureStats['most_successful_range']->avg_high }}°C
Species Performance
Species |
Total Treatments |
Avg Success Rate |
@foreach($speciesStats as $species)
{{ $species->name }}
|
{{ $species->treatments_count }}
|
{{ round($species->treatments_avg_success_rate, 1) }}%
|
@endforeach
Recent Treatments
Species |
EMS Conc. |
Duration |
Temp Range |
Success Rate |
@foreach($recentTreatments as $treatment)
{{ $treatment->species->name }}
|
{{ $treatment->emsConcentration }}
|
{{ $treatment->soakDuration }} min
|
{{ $treatment->lowestTemp }}°C - {{ $treatment->highestTemp }}°C
|
{{ $treatment->successRate }}%
|
@endforeach
EMS Concentration Analysis
Concentration |
Treatments |
Avg Success Rate |
@foreach($successRateByConcentration as $stat)
{{ $stat->emsConcentration }}
|
{{ $stat->count }}
|
{{ round($stat->avg_success_rate, 1) }}%
|
@endforeach