56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace BitGoblin\Colossus\Models;
 | |
| 
 | |
| use Illuminate\Database\Eloquent\Model;
 | |
| 
 | |
| class Test extends Model {
 | |
| 
 | |
|   protected $fillable = [
 | |
|     'date_tag',
 | |
|     'benchmark_id',
 | |
|     'component_id',
 | |
|   ];
 | |
| 
 | |
|   public function results() {
 | |
|     return $this->hasMany(Result::class);
 | |
|   }
 | |
| 
 | |
|   public function benchmarks() {
 | |
|     return $this->belongsToMany(Benchmark::class);
 | |
|   }
 | |
| 
 | |
|   public function component() {
 | |
|     return $this->belongsTo(Component::class);
 | |
|   }
 | |
| 
 | |
|   public function benchmarkResults() {
 | |
|     $data = [];
 | |
| 
 | |
|     foreach ($this->benchmarks as $i => $b) {
 | |
|       $benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get();
 | |
| 
 | |
|       $averageResults = [];
 | |
|       $minimumResults = [];
 | |
|       $maximumResults = [];
 | |
|       foreach ($benchmarkResults as $r) {
 | |
|         array_push($averageResults, $r->average);
 | |
|         array_push($minimumResults, $r->minimum);
 | |
|         array_push($maximumResults, $r->maximum);
 | |
|       }
 | |
| 
 | |
|       $data[$i] = [
 | |
|         'name'    => $b->name,
 | |
|         'scoring' => $b->scoring,
 | |
|         'count'   => count($benchmarkResults),
 | |
|         'average' => (array_sum($averageResults) / count($averageResults)),
 | |
|         'minimum' => (array_sum($minimumResults) / count($minimumResults)),
 | |
|         'maximum' => (array_sum($maximumResults) / count($maximumResults)),
 | |
|       ]
 | |
|     }
 | |
| 
 | |
|     return $data;
 | |
|   }
 | |
| 
 | |
| }
 |