Consumption table api feedback fix.
This commit is contained in:
parent
67325f063c
commit
15727b9769
@ -117,8 +117,9 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
|
|
||||||
$date_stat = current($val);
|
$date_stat = current($val);
|
||||||
$date_end = end($val);
|
$date_end = end($val);
|
||||||
|
|
||||||
$start_date = date_create("{$date_stat[0]}-01-01");
|
$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]}-03-30");// If you want to include this date, add 1 day
|
||||||
|
|
||||||
$interval = DateInterval::createFromDateString('1 months');
|
$interval = DateInterval::createFromDateString('1 months');
|
||||||
$daterange = new DatePeriod($start_date, $interval, $end_date);
|
$daterange = new DatePeriod($start_date, $interval, $end_date);
|
||||||
@ -133,11 +134,17 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($date as $dt) {
|
foreach ($date as $dt) {
|
||||||
if (empty($arr[$i])) {
|
if (empty($arr[$i])) {
|
||||||
|
$arr[] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($dt, $arr[$i])){
|
||||||
$arr[] = ['mes' => $dt];
|
$arr[] = ['mes' => $dt];
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
sort($arr);
|
|
||||||
|
dd($arr);
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
DB::raw('pld_sudeste.value as sudeste'),
|
DB::raw('pld_sudeste.value as sudeste'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = [];
|
$result = [];
|
||||||
$sql = DB::table('pld')
|
$sql = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
'submercado as submarket',
|
'submercado as submarket',
|
||||||
@ -72,7 +72,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
$query = DB::table('pld')->fromSub($sql, 'norte');
|
$query = DB::table('pld')->fromSub($sql, 'norte');
|
||||||
$data[] = static::responsePld($query, $sql, 'norte');
|
$result[] = static::responsePld($query, $sql, 'norte');
|
||||||
|
|
||||||
$sql2 = DB::table('pld')
|
$sql2 = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
@ -84,7 +84,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
$query = DB::table('pld')->fromSub($sql2, 'sul');
|
$query = DB::table('pld')->fromSub($sql2, 'sul');
|
||||||
$data[] = static::responsePld($query, $sql2, 'sul');
|
$result[] = static::responsePld($query, $sql2, 'sul');
|
||||||
|
|
||||||
|
|
||||||
$sql3 = DB::table('pld')
|
$sql3 = DB::table('pld')
|
||||||
@ -97,7 +97,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
$query = DB::table('pld')->fromSub($sql3, 'nordeste');
|
$query = DB::table('pld')->fromSub($sql3, 'nordeste');
|
||||||
$data[] = static::responsePld($query, $sql3, 'nordeste');
|
$result[] = static::responsePld($query, $sql3, 'nordeste');
|
||||||
|
|
||||||
$sql4 = DB::table('pld')
|
$sql4 = DB::table('pld')
|
||||||
->select([
|
->select([
|
||||||
@ -109,10 +109,10 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
->groupBy('submarket', 'year_month');
|
->groupBy('submarket', 'year_month');
|
||||||
|
|
||||||
$query = DB::table('pld')->fromSub($sql4, 'sudeste');
|
$query = DB::table('pld')->fromSub($sql4, 'sudeste');
|
||||||
$data[] = static::responsePld($query, $sql4, 'sudeste');
|
$result[] = static::responsePld($query, $sql4, 'sudeste');
|
||||||
|
|
||||||
|
|
||||||
$result = $this->model->select($fields)->joinSub($sql, 'pld_norte', function ($join) {
|
$data = $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');
|
||||||
@ -122,7 +122,10 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
$join->on('pld.mes_ref', '=', 'pld_sudeste.year_month');
|
$join->on('pld.mes_ref', '=', 'pld_sudeste.year_month');
|
||||||
})->distinct()->get();
|
})->distinct()->get();
|
||||||
|
|
||||||
return collect($result)->push(['result' => $data])->all();
|
return [
|
||||||
|
'data' => $data,
|
||||||
|
'result' => $result
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -185,12 +188,10 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
|
|
||||||
protected static function responsePld($query, $sql, $name)
|
protected static function responsePld($query, $sql, $name)
|
||||||
{
|
{
|
||||||
return [$name =>
|
return [
|
||||||
[
|
"{$name}_max" => $query->max('value'),
|
||||||
'max' => $query->max('value'),
|
"{$name}_min" => $query->min('value'),
|
||||||
'min' => $query->min('value'),
|
"{$name}desv_pad" => static::standardDeviation($sql->get()->toArray()),
|
||||||
'desv_pad' => static::standardDeviation($sql->get()->toArray()),
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user