Notification API wheel fix, faq.
This commit is contained in:
parent
c233f7ad25
commit
cd690a35fa
@ -6,3 +6,28 @@ if (!function_exists('checkUserId')) {
|
|||||||
return \auth()->hasUser() && !is_null($client_id);
|
return \auth()->hasUser() && !is_null($client_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('stats_standard_deviation')) {
|
||||||
|
function stats_standard_deviation(array $a, $sample = false): float|bool
|
||||||
|
{
|
||||||
|
$n = count($a);
|
||||||
|
if ($n === 0) {
|
||||||
|
trigger_error("The array has zero elements", E_USER_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($sample && $n === 1) {
|
||||||
|
trigger_error("The array has only 1 element", E_USER_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$mean = array_sum($a) / $n;
|
||||||
|
$carry = 0.0;
|
||||||
|
foreach ($a as $val) {
|
||||||
|
$d = ((double)$val) - $mean;
|
||||||
|
$carry += $d * $d;
|
||||||
|
};
|
||||||
|
if ($sample) {
|
||||||
|
--$n;
|
||||||
|
}
|
||||||
|
return sqrt($carry / $n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -62,15 +62,31 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
DB::raw('pld_sudeste.value as sudeste'),
|
DB::raw('pld_sudeste.value as sudeste'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$data = [];
|
||||||
$sql = DB::table('pld')
|
$sql = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
'submercado as submarket',
|
'submercado as submarket',
|
||||||
'mes_ref as year_month',
|
'mes_ref as year_month',
|
||||||
DB::raw('SUM(valor) as value')
|
DB::raw('SUM(valor) as value'),
|
||||||
])
|
])
|
||||||
->where('pld.submercado', '=', 'NORTE')
|
->where('pld.submercado', '=', 'NORTE')
|
||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
|
$query = DB::table('pld')->fromSub($sql, 'norte');
|
||||||
|
$max_norte = $query->max('value');
|
||||||
|
$min_norte = $query->min('value');
|
||||||
|
$desvio_padrao = static::standardDeviation($sql->get()->toArray());
|
||||||
|
|
||||||
|
$data[] = ['norte' =>
|
||||||
|
[
|
||||||
|
'max' => $max_norte,
|
||||||
|
'min' => $min_norte,
|
||||||
|
'desv_pad' => $desvio_padrao
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
dd($data);
|
||||||
|
|
||||||
$sql2 = DB::table('pld')
|
$sql2 = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
'submercado as submarket',
|
'submercado as submarket',
|
||||||
@ -80,6 +96,19 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->where('pld.submercado', '=', 'SUL')
|
->where('pld.submercado', '=', 'SUL')
|
||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
|
$query = DB::table('pld')->fromSub($sql2, 'sul');
|
||||||
|
$max_sul = $query->max('value');
|
||||||
|
$min_sul = $query->min('value');
|
||||||
|
$desvio_padrao = static::standardDeviation($sql2->get()->toArray());
|
||||||
|
|
||||||
|
$data[] = ['sul' =>
|
||||||
|
[
|
||||||
|
'max' => $max_sul,
|
||||||
|
'min' => $min_sul,
|
||||||
|
'desv_pad' => $desvio_padrao
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
$sql3 = DB::table('pld')
|
$sql3 = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
'submercado as submarket',
|
'submercado as submarket',
|
||||||
@ -89,6 +118,20 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->where('pld.submercado', '=', 'NORDESTE')
|
->where('pld.submercado', '=', 'NORDESTE')
|
||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
|
$query = DB::table('pld')->fromSub($sql3, 'nordeste');
|
||||||
|
$max_nordeste = $query->max('value');
|
||||||
|
$min_nordeste = $query->min('value');
|
||||||
|
$desvio_padrao = static::standardDeviation($sql3->get()->toArray());
|
||||||
|
|
||||||
|
|
||||||
|
$data[] = ['nordeste' =>
|
||||||
|
[
|
||||||
|
'max' => $max_nordeste,
|
||||||
|
'min' => $min_nordeste,
|
||||||
|
'desv_pad' => $desvio_padrao
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
$sql4 = DB::table('pld')
|
$sql4 = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
'submercado as submarket',
|
'submercado as submarket',
|
||||||
@ -98,8 +141,20 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->where('pld.submercado', '=', 'SUDESTE')
|
->where('pld.submercado', '=', 'SUDESTE')
|
||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
|
$query = DB::table('pld')->fromSub($sql4, 'sudeste');
|
||||||
|
$max_sudeste = $query->max('value');
|
||||||
|
$min_sudeste = $query->min('value');
|
||||||
|
$desvio_padrao = static::standardDeviation($sql4->get()->toArray());
|
||||||
|
|
||||||
return $this->model->select($fields)->joinSub($sql, 'pld_norte', function ($join) {
|
$data[] = ['nordeste' =>
|
||||||
|
[
|
||||||
|
'max' => $max_sudeste,
|
||||||
|
'min' => $min_sudeste,
|
||||||
|
'desv_pad' => $desvio_padrao
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $this->model->select($fields)->joinSub($sql, 'pld_norte', function ($join) {
|
||||||
$join->on('pld.mes_ref', '=', 'pld_norte.year_month');
|
$join->on('pld.mes_ref', '=', 'pld_norte.year_month');
|
||||||
})->joinSub($sql2, 'pld_sul', function ($join) {
|
})->joinSub($sql2, 'pld_sul', function ($join) {
|
||||||
$join->on('pld.mes_ref', '=', 'pld_sul.year_month');
|
$join->on('pld.mes_ref', '=', 'pld_sul.year_month');
|
||||||
@ -108,6 +163,10 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
})->joinSub($sql4, 'pld_sudeste', function ($join) {
|
})->joinSub($sql4, 'pld_sudeste', function ($join) {
|
||||||
$join->on('pld.mes_ref', '=', 'pld_sudeste.year_month');
|
$join->on('pld.mes_ref', '=', 'pld_sudeste.year_month');
|
||||||
})->distinct()->get();
|
})->distinct()->get();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,17 +222,13 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function getRowField(): array
|
protected static function standardDeviation($array): float|bool
|
||||||
{
|
{
|
||||||
return [
|
return stats_standard_deviation(collect($array)->pluck('value')->all());
|
||||||
DB::raw("TO_CHAR((date('1899-12-30') + interval '1' day * pld.dia_num), 'DD') as day_formatted"),
|
}
|
||||||
'hora as hour',
|
|
||||||
DB::raw("(date('1899-12-30') + interval '1' day * pld.dia_num) as day_calc"),
|
protected static function responsePld($query, $name){
|
||||||
'pld.submercado as submarket',
|
|
||||||
DB::raw("SUM(pld.valor) as value"),
|
|
||||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month"),
|
|
||||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month_formatted"),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -30,13 +30,13 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
|||||||
Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () {
|
Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () {
|
||||||
Route::apiResource('user', \App\Http\Controllers\UserController::class);
|
Route::apiResource('user', \App\Http\Controllers\UserController::class);
|
||||||
|
|
||||||
Route::put('notification', [\App\Http\Controllers\NotificationController::class, 'update']);
|
Route::put('notification/{notification}', [\App\Http\Controllers\NotificationController::class, 'update']);
|
||||||
Route::post('notification', [\App\Http\Controllers\NotificationController::class, 'store']);
|
Route::post('notification', [\App\Http\Controllers\NotificationController::class, 'store']);
|
||||||
Route::delete('notification', [\App\Http\Controllers\NotificationController::class, 'destroy']);
|
Route::delete('notification/{notification}', [\App\Http\Controllers\NotificationController::class, 'destroy']);
|
||||||
|
|
||||||
Route::put('faq', [\App\Http\Controllers\FaqController::class, 'update']);
|
Route::put('faq/{faq}', [\App\Http\Controllers\FaqController::class, 'update']);
|
||||||
Route::post('faq', [\App\Http\Controllers\FaqController::class, 'store']);
|
Route::post('faq', [\App\Http\Controllers\FaqController::class, 'store']);
|
||||||
Route::delete('faq', [\App\Http\Controllers\FaqController::class, 'destroy']);
|
Route::delete('faq/{faq}', [\App\Http\Controllers\FaqController::class, 'destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user