Correction of the return of the api cost R$/MWh.
This commit is contained in:
parent
15727b9769
commit
c53d0e0ed3
@ -113,13 +113,16 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
||||
public static function checkDate($value): array
|
||||
{
|
||||
|
||||
$val = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])->explode('/')->offsetGet(1)))->unique()->toArray();
|
||||
|
||||
$date_stat = current($val);
|
||||
$date_end = end($val);
|
||||
$year = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
||||
->explode('/')->offsetGet(1)))->unique()->toArray();
|
||||
$month = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
||||
->explode('/')->offsetGet(0)))->unique()->toArray();
|
||||
$month_stat = end($month);
|
||||
$date_stat = current($year);
|
||||
$date_end = end($year);
|
||||
|
||||
$start_date = date_create("{$date_stat[0]}-01-01");
|
||||
$end_date = date_create("{$date_end[0]}-03-30");// If you want to include this date, add 1 day
|
||||
$end_date = date_create("{$date_end[0]}-{$month_stat[0]}-30");
|
||||
|
||||
$interval = DateInterval::createFromDateString('1 months');
|
||||
$daterange = new DatePeriod($start_date, $interval, $end_date);
|
||||
@ -131,26 +134,20 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
||||
|
||||
$arr = collect($value)->toArray();
|
||||
|
||||
$i = 0;
|
||||
foreach ($date as $dt) {
|
||||
if (empty($arr[$i])) {
|
||||
$arr[] = [];
|
||||
}
|
||||
|
||||
if (in_array($dt, $arr[$i])){
|
||||
if (!in_array($dt, array_column($arr, 'mes'))) {
|
||||
$arr[] = ['mes' => $dt];
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
dd($arr);
|
||||
usort($arr, function ($a, $b, $i = 'mes') {
|
||||
$t1 = strtotime(str_replace('/', '-', $a[$i]));
|
||||
$t2 = strtotime(str_replace('/', '-', $b[$i]));
|
||||
return $t1 - $t2;
|
||||
});
|
||||
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -61,7 +61,9 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
DB::raw('pld_sudeste.value as sudeste'),
|
||||
];
|
||||
|
||||
$result = [];
|
||||
$res_max = [];
|
||||
$res_min = [];
|
||||
$desv_pad = [];
|
||||
$sql = DB::table('pld')
|
||||
->select([
|
||||
'submercado as submarket',
|
||||
@ -72,7 +74,9 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
->groupBy('submarket', 'year_month');
|
||||
|
||||
$query = DB::table('pld')->fromSub($sql, 'norte');
|
||||
$result[] = static::responsePld($query, $sql, 'norte');
|
||||
$res_max["norte_max"] = $query->max('value');
|
||||
$res_min["norte_min"] = $query->min('value');
|
||||
$desv_pad["norte_desv_pad"] = static::standardDeviation($sql->get()->toArray());
|
||||
|
||||
$sql2 = DB::table('pld')
|
||||
->select([
|
||||
@ -84,8 +88,9 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
->groupBy('submarket', 'year_month');
|
||||
|
||||
$query = DB::table('pld')->fromSub($sql2, 'sul');
|
||||
$result[] = static::responsePld($query, $sql2, 'sul');
|
||||
|
||||
$res_max["sul_max"] = $query->max('value');
|
||||
$res_min["sul_min"] = $query->min('value');
|
||||
$desv_pad["sul_desv_pad"] = static::standardDeviation($sql2->get()->toArray());
|
||||
|
||||
$sql3 = DB::table('pld')
|
||||
->select([
|
||||
@ -97,7 +102,9 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
->groupBy('submarket', 'year_month');
|
||||
|
||||
$query = DB::table('pld')->fromSub($sql3, 'nordeste');
|
||||
$result[] = static::responsePld($query, $sql3, 'nordeste');
|
||||
$res_max["nordeste_max"] = $query->max('value');
|
||||
$res_min["nordeste_min"] = $query->min('value');
|
||||
$desv_pad["nordeste_desv_pad"] = static::standardDeviation($sql3->get()->toArray());
|
||||
|
||||
$sql4 = DB::table('pld')
|
||||
->select([
|
||||
@ -109,8 +116,9 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
->groupBy('submarket', 'year_month');
|
||||
|
||||
$query = DB::table('pld')->fromSub($sql4, 'sudeste');
|
||||
$result[] = static::responsePld($query, $sql4, 'sudeste');
|
||||
|
||||
$res_max["sudeste_max"] = $query->max('value');
|
||||
$res_min["sudeste_min"] = $query->min('value');
|
||||
$desv_pad["sudeste_desv_pad"] = static::standardDeviation($sql3->get()->toArray());
|
||||
|
||||
$data = $this->model->select($fields)->joinSub($sql, 'pld_norte', function ($join) {
|
||||
$join->on('pld.mes_ref', '=', 'pld_norte.year_month');
|
||||
@ -124,7 +132,11 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'result' => $result
|
||||
'result' => [
|
||||
$res_max,
|
||||
$res_min,
|
||||
$desv_pad
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@ -186,14 +198,4 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
return stats_standard_deviation(collect($array)->pluck('value')->all());
|
||||
}
|
||||
|
||||
protected static function responsePld($query, $sql, $name)
|
||||
{
|
||||
return [
|
||||
"{$name}_max" => $query->max('value'),
|
||||
"{$name}_min" => $query->min('value'),
|
||||
"{$name}desv_pad" => static::standardDeviation($sql->get()->toArray()),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user