Skip to content

Commit

Permalink
Merges BattCat and DustUp model and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlan committed Mar 3, 2022
1 parent a13e816 commit 24b78f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/DustupOra.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ public function fetchFaultTypePoorData()
return DB::select('SELECT * FROM `fault_types_vacuums` WHERE `id`=25');
}



/**
* @return array
*/
public function fetchProgress()
{
$result = DB::select('
SELECT
ROUND((r2.opinions/r2.vacuums)*100,1) as total
FROM (
SELECT
COUNT(*) AS opinions,
(SELECT COUNT(*) FROM devices_dustup_ora) as vacuums
FROM (
SELECT
o.id_ords,
(SELECT a.fault_type_id FROM devices_faults_vacuums_ora_adjudicated a WHERE a.id_ords = o.id_ords) AS adjudicated_opinion_id,
(SELECT o1.fault_type_id FROM devices_faults_vacuums_ora_opinions o1 WHERE o1.id_ords = o.id_ords GROUP BY o1.fault_type_id ORDER BY COUNT(o1.fault_type_id) DESC LIMIT 1) AS winning_opinion_id,
ROUND((SELECT COUNT(o3.fault_type_id) as top_crowd_opinion_count FROM devices_faults_vacuums_ora_opinions o3 WHERE o3.id_ords = o.id_ords GROUP BY o3.fault_type_id ORDER BY top_crowd_opinion_count DESC LIMIT 1) /
(SELECT COUNT(o4.fault_type_id) as all_votes FROM devices_faults_vacuums_ora_opinions o4 WHERE o4.id_ords = o.id_ords) * 100) AS top_crowd_opinion_percentage,
COUNT(o.fault_type_id) AS all_crowd_opinions_count
FROM devices_faults_vacuums_ora_opinions o
GROUP BY o.id_ords
HAVING
(all_crowd_opinions_count > 1 AND top_crowd_opinion_percentage > 60)
OR
(all_crowd_opinions_count = 3 AND top_crowd_opinion_percentage < 60 AND adjudicated_opinion_id IS NOT NULL)
) AS r1
) AS r2
');

return $result;
}

/**
* @return mixed
*/
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/DustupOraController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function index(Request $request)
$user = $this->_anon();
}
// if survey is being submitted
$thankyou = false;
if ($request->has('task-survey')) {
$inputs = $request->all();
unset($inputs['_token']);
Expand All @@ -54,6 +55,7 @@ public function index(Request $request)
logger('MicrotaskSurvey error on insert.');
logger(print_r($insert, 1));
}
$thankyou = 'guest';
}

$this->Model = new DustupOra;
Expand Down Expand Up @@ -103,6 +105,7 @@ public function index(Request $request)
if (! $fault) {
return redirect()->action('DustupOraController@status')->withSuccess('done');
}
$progress = $this->Model->fetchProgress()[0]->total;

$fault->translate = rawurlencode($fault->problem);
$fault_types = $this->Model->fetchFaultTypes();
Expand All @@ -124,7 +127,9 @@ public function index(Request $request)
'fault' => $fault,
'poor_data' => $poor_data,
'user' => $user,
'progress' => $progress > 1 ? $progress : 0,
'signpost' => $signpost,
'thankyou' => $thankyou,
'locale' => $this->_getUserLocale(),
]);
}
Expand Down

0 comments on commit 24b78f1

Please sign in to comment.