You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.7 KiB
124 lines
4.7 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Models\LicensePlateRecognition;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class LicensePlateRecognitionController extends BaseController
|
|
{
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$query = LicensePlateRecognition::query();
|
|
|
|
if ($request->has('start_time') && $request->has('end_time')) {
|
|
$start_time = $request->input('start_time');
|
|
$end_time = $request->input('end_time');
|
|
if (strtotime($start_time) && strtotime($end_time)) {
|
|
$query->whereBetween('time_slot', [$start_time, $end_time]);
|
|
}
|
|
}
|
|
|
|
// 分页
|
|
$page = $request->input('page', 1);
|
|
$perPage = $request->input('per_page', 10);
|
|
|
|
$columns = ['time_slot'];
|
|
|
|
$total = 0;
|
|
$all = $query->groupBy('time_slot')->select($columns)->get();
|
|
if ($all) {
|
|
$total = count($all);
|
|
}
|
|
$items = $query->groupBy(['time_slot'])->latest('time_slot')
|
|
->forPage($page, $perPage)->get()->each(function ($item) {
|
|
$countData = $this->getCount($item['time_slot']);
|
|
$item['sum_count'] = $countData['sum_count'];
|
|
$item['high_ratio'] = $countData['high_ratio'];
|
|
$item['middle_ratio'] = $countData['middle_ratio'];
|
|
$item['manual_count'] = $countData['manual_count'];
|
|
$item['manual_ratio'] = $countData['manual_ratio'];
|
|
return $item;
|
|
});
|
|
return $this->responseService->success([
|
|
'items' => $items,
|
|
'total' => $total,
|
|
'page' => $page,
|
|
'per_page' => $perPage,
|
|
'last_page' => ceil($total / $perPage),
|
|
]);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
protected function getCount($time_slot)
|
|
{
|
|
$manualWhere = $highWhere = $middleWhere = $where = [
|
|
'time_slot' => $time_slot
|
|
];
|
|
$where['manual_modification'] = 0;
|
|
$sumCount = LicensePlateRecognition::query()->where($where)
|
|
->count();
|
|
$highWhere['recognition'] = 5;
|
|
$highCount = LicensePlateRecognition::query()->where(
|
|
$highWhere
|
|
)->count();
|
|
$middleWhere['recognition'] = 1;
|
|
$middleCount = LicensePlateRecognition::query()->where(
|
|
$middleWhere
|
|
)->count();
|
|
$manualWhere['manual_modification'] = 1;
|
|
$manualCount = LicensePlateRecognition::query()->where(
|
|
$manualWhere
|
|
)->count();
|
|
return [
|
|
'sum_count' => $sumCount,
|
|
'high_count' => $highCount,
|
|
'middle_count' => $middleCount,
|
|
'manual_count' => $manualCount,
|
|
'high_ratio' => get_ratio($sumCount, $highCount),
|
|
'middle_ratio' => get_ratio($sumCount, $middleCount),
|
|
'manual_ratio' => get_ratio($sumCount, $manualCount)
|
|
];
|
|
}
|
|
|
|
public function curveGraph(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$query = LicensePlateRecognition::query();
|
|
if ($request->has('start_time') && $request->has('end_time')) {
|
|
$start_time = $request->input('start_time');
|
|
$end_time = $request->input('end_time');
|
|
if (strtotime($start_time) && strtotime($end_time)) {
|
|
$query->whereBetween('time_slot', [$start_time, $end_time]);
|
|
}
|
|
}
|
|
// 分页
|
|
$page = 1;
|
|
$perPage = 16;
|
|
$items = $query->groupBy(['time_slot'])->latest('time_slot')
|
|
->forPage($page, $perPage)->select('time_slot')->get()
|
|
->each(function ($item) {
|
|
$countData = $this->getCount($item['time_slot']);
|
|
$item['high_ratio'] = $countData['high_ratio'];
|
|
$item['middle_ratio'] = $countData['middle_ratio'];
|
|
$item['manual_ratio'] = $countData['manual_ratio'];
|
|
return $item;
|
|
});
|
|
return $this->responseService->success($items);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|