mirror of
https://github.com/beestat/app.git
synced 2025-07-09 03:04:07 -04:00
Fixed #18 - Aggregate runtime - grouping by week causes odd spacing for months.
I did a terrible job of group by week; fixing it.
This commit is contained in:
parent
b02374a71b
commit
19ea51f121
@ -328,15 +328,26 @@ class ecobee_runtime_thermostat extends cora\crud {
|
|||||||
$select = [];
|
$select = [];
|
||||||
$group_by_order_by = [];
|
$group_by_order_by = [];
|
||||||
switch($group_by) {
|
switch($group_by) {
|
||||||
|
case 'week':
|
||||||
|
/**
|
||||||
|
* Week is a special case. If grouping by week, month, year, you can
|
||||||
|
* get one week listed twice if it spans across months. So the month
|
||||||
|
* group by is undesirable in this case.
|
||||||
|
*
|
||||||
|
* The second argument of 3 to the yearweek() function will cause
|
||||||
|
* MySQL to return the ISO 8601 week of the year.
|
||||||
|
*
|
||||||
|
* https://stackoverflow.com/a/11804076
|
||||||
|
*/
|
||||||
|
$select[] = 'yearweek(`timestamp`, 3) `yearweek`';
|
||||||
|
$group_by_order_by[] = 'yearweek(`timestamp`, 3)';
|
||||||
|
break;
|
||||||
case 'hour':
|
case 'hour':
|
||||||
$select[] = 'hour(`timestamp`) `hour`';
|
$select[] = 'hour(`timestamp`) `hour`';
|
||||||
$group_by_order_by[] = 'hour(`timestamp`)';
|
$group_by_order_by[] = 'hour(`timestamp`)';
|
||||||
case 'day':
|
case 'day':
|
||||||
$select[] = 'day(`timestamp`) `day`';
|
$select[] = 'day(`timestamp`) `day`';
|
||||||
$group_by_order_by[] = 'day(`timestamp`)';
|
$group_by_order_by[] = 'day(`timestamp`)';
|
||||||
case 'week':
|
|
||||||
$select[] = 'week(`timestamp`) `week`';
|
|
||||||
$group_by_order_by[] = 'week(`timestamp`)';
|
|
||||||
case 'month':
|
case 'month':
|
||||||
$select[] = 'month(`timestamp`) `month`';
|
$select[] = 'month(`timestamp`) `month`';
|
||||||
$group_by_order_by[] = 'month(`timestamp`)';
|
$group_by_order_by[] = 'month(`timestamp`)';
|
||||||
@ -397,6 +408,12 @@ class ecobee_runtime_thermostat extends cora\crud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($row['yearweek']) === true) {
|
||||||
|
$row['year'] = (int) substr($row['yearweek'], 0, 4);
|
||||||
|
$row['week'] = (int) substr($row['yearweek'], 4);
|
||||||
|
unset($row['yearweek']);
|
||||||
|
}
|
||||||
|
|
||||||
$return[] = $row;
|
$return[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +70,20 @@ beestat.component.card.aggregate_runtime.prototype.decorate_contents_ = function
|
|||||||
var date_parts = this.value.match(/(?:h(\d+))?(?:d(\d+))?(?:w(\d+))?(?:m(\d+))?(?:y(\d+))?/);
|
var date_parts = this.value.match(/(?:h(\d+))?(?:d(\d+))?(?:w(\d+))?(?:m(\d+))?(?:y(\d+))?/);
|
||||||
var hour = moment(date_parts[1], 'H').format('ha');
|
var hour = moment(date_parts[1], 'H').format('ha');
|
||||||
var day = date_parts[2];
|
var day = date_parts[2];
|
||||||
var week = date_parts[3];
|
|
||||||
var month = moment(date_parts[4], 'M').format('MMM');
|
var month = moment(date_parts[4], 'M').format('MMM');
|
||||||
var year = date_parts[5];
|
|
||||||
|
var year;
|
||||||
|
var week;
|
||||||
|
if (beestat.setting('aggregate_runtime_group_by') === 'week') {
|
||||||
|
// ISO 8601 week of the year.
|
||||||
|
var yearweek_m = moment().isoWeek(date_parts[3])
|
||||||
|
.year(date_parts[5])
|
||||||
|
.day('Monday');
|
||||||
|
week = yearweek_m.format('MMM D');
|
||||||
|
year = yearweek_m.format('YYYY');
|
||||||
|
} else {
|
||||||
|
year = date_parts[5];
|
||||||
|
}
|
||||||
|
|
||||||
var label_parts = [];
|
var label_parts = [];
|
||||||
switch (beestat.setting('aggregate_runtime_group_by')) {
|
switch (beestat.setting('aggregate_runtime_group_by')) {
|
||||||
@ -86,8 +97,8 @@ beestat.component.card.aggregate_runtime.prototype.decorate_contents_ = function
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'week':
|
case 'week':
|
||||||
if (month !== current_month) {
|
if (week !== current_week) {
|
||||||
label_parts.push(month);
|
label_parts.push(week);
|
||||||
}
|
}
|
||||||
if (year !== current_year) {
|
if (year !== current_year) {
|
||||||
label_parts.push(year);
|
label_parts.push(year);
|
||||||
@ -211,9 +222,20 @@ beestat.component.card.aggregate_runtime.prototype.decorate_contents_ = function
|
|||||||
var date_parts = this.x.match(/(?:h(\d+))?(?:d(\d+))?(?:w(\d+))?(?:m(\d+))?(?:y(\d+))?/);
|
var date_parts = this.x.match(/(?:h(\d+))?(?:d(\d+))?(?:w(\d+))?(?:m(\d+))?(?:y(\d+))?/);
|
||||||
var hour = moment(date_parts[1], 'H').format('ha');
|
var hour = moment(date_parts[1], 'H').format('ha');
|
||||||
var day = date_parts[2];
|
var day = date_parts[2];
|
||||||
var week = date_parts[3];
|
|
||||||
var month = moment(date_parts[4], 'M').format('MMM');
|
var month = moment(date_parts[4], 'M').format('MMM');
|
||||||
var year = date_parts[5];
|
|
||||||
|
var year;
|
||||||
|
var week;
|
||||||
|
if (beestat.setting('aggregate_runtime_group_by') === 'week') {
|
||||||
|
// ISO 8601 week of the year.
|
||||||
|
var yearweek_m = moment().isoWeek(date_parts[3])
|
||||||
|
.year(date_parts[5])
|
||||||
|
.day('Monday');
|
||||||
|
week = yearweek_m.format('MMM D');
|
||||||
|
year = yearweek_m.format('YYYY');
|
||||||
|
} else {
|
||||||
|
year = date_parts[5];
|
||||||
|
}
|
||||||
|
|
||||||
var label_parts = [];
|
var label_parts = [];
|
||||||
switch (beestat.setting('aggregate_runtime_group_by')) {
|
switch (beestat.setting('aggregate_runtime_group_by')) {
|
||||||
@ -225,7 +247,8 @@ beestat.component.card.aggregate_runtime.prototype.decorate_contents_ = function
|
|||||||
label_parts.push(year);
|
label_parts.push(year);
|
||||||
break;
|
break;
|
||||||
case 'week':
|
case 'week':
|
||||||
label_parts.push(month);
|
label_parts.push('Week of');
|
||||||
|
label_parts.push(week + ',');
|
||||||
label_parts.push(year);
|
label_parts.push(year);
|
||||||
break;
|
break;
|
||||||
case 'day':
|
case 'day':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user