Fixed Moving Average Endpoint Implementation.
This commit is contained in:
parent
dbdb64f507
commit
846b07c741
@ -14,7 +14,7 @@ use OwenIt\Auditing\Auditable;
|
|||||||
|
|
||||||
class Pld extends Model implements Auditing
|
class Pld extends Model implements Auditing
|
||||||
{
|
{
|
||||||
use HasFactory, SoftDeletes, Auditable;
|
use HasFactory, Auditable;
|
||||||
|
|
||||||
protected $table = "pld";
|
protected $table = "pld";
|
||||||
|
|
||||||
@ -42,5 +42,4 @@ class Pld extends Model implements Auditing
|
|||||||
return $date->format('d/m/Y H:i:s');
|
return $date->format('d/m/Y H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,18 +159,19 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
'pld.submercado as submarket',
|
'pld.submercado as submarket',
|
||||||
DB::raw("AVG(pld.valor) as value"),
|
DB::raw("AVG(pld.valor) as value"),
|
||||||
DB::raw("pld.mes_ref as year_month"),
|
DB::raw("pld.mes_ref as year_month"),
|
||||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'::text)::timestamp with time zone, 'MM/YYYY'::text) as year_month_formatted"),
|
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'::text)::timestamp with time zone, 'MM/YYYY'::text) as year_month_formatted")
|
||||||
];
|
];
|
||||||
|
|
||||||
$i = 0;
|
$fields2 = ['day_formatted',
|
||||||
foreach ($params['filters'] as $param) {
|
'day_calc',
|
||||||
if ($param['field'] === $field) {
|
'submarket',
|
||||||
$params['filters'][$i]['field'] = "TO_CHAR(TO_DATE(pld.{$param['field']}, 'YYMM'), 'MM/YYYY')";
|
'year_month',
|
||||||
}
|
'year_month_formatted',
|
||||||
$i++;
|
'value',
|
||||||
}
|
DB::raw('avg(value) over(ORDER BY day_formatted) as mMovel')
|
||||||
|
];
|
||||||
|
|
||||||
return $this->execute($fields, $params)
|
$query = $this->execute($fields)
|
||||||
->groupBy(
|
->groupBy(
|
||||||
DB::raw("(to_char(('1899-12-30'::date + ('1 day'::interval day * (pld.dia_num)::double precision)), 'DD'::text))"),
|
DB::raw("(to_char(('1899-12-30'::date + ('1 day'::interval day * (pld.dia_num)::double precision)), 'DD'::text))"),
|
||||||
DB::raw("('1899-12-30'::date + ('1 day'::interval day * (pld.dia_num)::double precision))"),
|
DB::raw("('1899-12-30'::date + ('1 day'::interval day * (pld.dia_num)::double precision))"),
|
||||||
@ -178,9 +179,12 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
"pld.mes_ref",
|
"pld.mes_ref",
|
||||||
DB::raw("(to_char((to_date(pld.mes_ref, 'YYMM'::text))::timestamp with time zone, 'MM/YYYY'::text))")
|
DB::raw("(to_char((to_date(pld.mes_ref, 'YYMM'::text))::timestamp with time zone, 'MM/YYYY'::text))")
|
||||||
)
|
)
|
||||||
->orderByRaw("('1899-12-30'::date + ('1 day'::interval day * (pld.dia_num)::double precision))")
|
->orderByRaw("('1899-12-30'::date + ('1 day'::interval day * (pld.dia_num)::double precision))");
|
||||||
->get();
|
|
||||||
|
|
||||||
|
return $this->execute($fields2, $params)
|
||||||
|
->from($query, 'plds')
|
||||||
|
->orderBy('day_calc', 'asc')
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConsumptionBySchedule($params, $field = "dia_num"): Collection|array
|
public function getConsumptionBySchedule($params, $field = "dia_num"): Collection|array
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user