Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open history with open end date by default #329

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions app/scripts/controllers/historyController.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
this.setDefaultTime(this.startDate,this.endDate);
// по умолчанию дата равна сегодня минус один день
this.selectedStartDate = this.startDate? this.startDate : new Date( + (new Date()) - 24*60*60*1000 );
this.selectedEndDate = this.endDate? this.endDate : new Date();
this.selectedEndDate = this.endDate;
this.timeChanged = true;
};

Expand Down Expand Up @@ -370,11 +370,15 @@
_s.setMinutes(s.getMinutes());
this.selectedStartDateMinute = _s;

var e = end || new Date();
var _e = new Date();
_e.setHours(e.getHours());
_e.setMinutes(e.getMinutes());
this.selectedEndDateMinute = _e;
if (end) {
var e = end;
var _e = new Date();
_e.setHours(e.getHours());
_e.setMinutes(e.getMinutes());
this.selectedEndDateMinute = _e;
} else {
this.selectedEndDateMinute = null;
}
}

beforeLoadChunkedHistory(indexOfControl=0) {
Expand Down Expand Up @@ -435,16 +439,23 @@

// никаких проверок дат. есть значения по умолчанию
const startDate = new Date(chunks[indexOfChunk]);
const endDate = new Date(chunks[indexOfChunk + 1]);
const endDate = chunks[indexOfChunk + 1] ? new Date(chunks[indexOfChunk + 1]) : null;
params.timestamp = {
// add extra second to include 00:00:00
// но только для первого чанка / для последущих чанков наоборот
// прибавляю 1 чтобы не было нахлеста
// (FIXME: maybe wb-mqtt-db should support not just gt/lt, but also gte/lte?)
gt: indexOfChunk==0? startDate.getTime() / 1000 - 1 : startDate.getTime() / 1000 + 1,
lt: endDate.getTime() / 1000/// + 86400;
};
var intervalMs = endDate - startDate; // duration of requested interval, in ms
if (endDate) {
params.timestamp.lt = endDate.getTime() / 1000/// + 86400;
var intervalMs = endDate - startDate; // duration of requested interval, in ms
} else {
console.log(new Date());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это от отладки осталось?

console.log(startDate);
var intervalMs = (new Date()) - startDate;

Check warning on line 456 in app/scripts/controllers/historyController.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/scripts/controllers/historyController.js#L456

'intervalMs' is already defined.
}

// we want to request no more than "limit" data points.
// Additional divider 1.1 is here just to be on the safe side
params.min_interval = Math.trunc(intervalMs / params.limit * 1.1);
Expand Down
83 changes: 15 additions & 68 deletions app/scripts/services/handle-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,91 +25,38 @@ export default function handleDataService() {
}
};

// разница дат. при start=='now' считает от сегодня
// при end==='now' считает до сегодня с округлением в большую сторону
// может показывать часы если меньше 1 дня
this.diffDates = (start, end, showHours = false, plusOne = false)=> {
if (!start || !end) return undefined;
var endProj;
end = end === 'now' ? +new Date() : +new Date(end);
start = start === 'now' ? +new Date() : +new Date(start);
var _endProj = (end - start) / (24 * 60 * 60000);
_endProj = plusOne ? _endProj + 1 : _endProj;
if (showHours && _endProj < 1) {
//если часы то возвращаю строку а не число
// отнимаю 4 часа для перевода времени
endProj = '' + Math.floor(_endProj * 24 - 4)
} else {
endProj = Math.ceil(_endProj);
}
return (endProj > 0) ? endProj : 0;
};

// разница дат в минутах
this.diffDatesInMinutes = (start, end) => {
const s = new Date(start),
e = new Date(end);
return ((+end) - (+start)) / 60000
};



// прибавляет дни к дате
this.dayPlusNDays = (dayString, n, returnString = true)=> {
let d = JSON.stringify(new Date(+new Date(dayString) + n * (24 * 60 * 60000))).slice(1, 11);
return returnString ? d : new Date(d)
};

this.getOffset = function () {
return (new Date).getTimezoneOffset();
};

// убавляет дни от даты/ можно со временем
this.dayMinusNDays = (dayString,n, returnString = true,withTime=false)=> {
// делаю поправку на отступ
var offset = this.getOffset()/60;
let d = JSON.stringify(new Date(+new Date(dayString) -
n * ((24 + (withTime? offset : 0))* 60 * 60000) )).slice(1, withTime? 20 : 11);
return returnString ? d : new Date(d)
};

// добавляет ноль
this.addZeroToDate = (d)=> {
return d<10? '0' + d : d
};

// можно со временем без секунд
this.dateYYYYMMDD = (date,withTime = false)=> {
if (!date) return null;
date = typeof date ==='string'? new Date(date) : date;

var ret = date.getFullYear()
+ "-" + this.addZeroToDate(date.getMonth() + 1)
+ "-" + this.addZeroToDate(date.getDate());
ret = !withTime? ret : `${ret}T${this.addZeroToDate(date.getHours())}:${this.addZeroToDate(date.getMinutes())}:00`;
return ret
};

// разбивает дни на сегменты из N дней
// rangInterval параметр длины интервала графика если не указана начальная точка
// start, end - Date() или undefined
this.splitDate = (start, end, days = 10,rangInterval = 1)=> {
end = end? end : new Date();// если нету то = текущим дате и времени
end = typeof end ==='string'? end : this.dateYYYYMMDD(end,true);
var _end = end? end : new Date();// если нету то = текущим дате и времени
// если нету то = end - инетервал days вместе с минутами
start = start? start : this.dayMinusNDays(end,rangInterval,true,true);
start = typeof start ==='string'? start : this.dateYYYYMMDD(start,true);
var diffDates = this.diffDates(start, end);
if (diffDates <= days) return [start,end];
var ret = [start];
var iter = Math.floor(diffDates / days) + 1;
var _start = start ? start : new Date(+_end - 24 * 60 * 60 * 1000 * rangInterval);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24 * 60 * 60 * 1000 стоит в константу обернуть, а то оно в 3-х местах используется


var diffDays = (_end - _start) / 1000/ 60/ 60/ 24;
// здесь и ниже: не _end, а исходный end: если конец интервала не был задан, то нам нужно будет так и запрашивать последний чанк с открытым концом
if (diffDays <= days) return [_start, end];
var ret = [_start];
var iter = Math.floor(diffDays / days) + 1;
console.log(iter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug?

for (var i = 1; i < iter; i++) {
var actualD = this.dayPlusNDays(start, i * days);
ret.push(actualD);
// если последний проход и текущее значение не совпадает с end
if (i === iter - 1 && actualD !== end) {
ret.push(end);
var actualD = new Date(+_start + i * days * 24 * 60 * 60 * 1000);
if (actualD < _end) {
ret.push(actualD);
}
}
ret.push(end);
return ret
};

Expand All @@ -119,4 +66,4 @@ export default function handleDataService() {
return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
}

}
}
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
wb-mqtt-homeui (2.37.3) stable; urgency=medium
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.37.1 ?
Но вообще это же новая фича. Я бы сделал 2.38.0


* open history with open end date by default

-- Evgeny Boger <[email protected]> Sat, 04 Jun 2022 15:20:49 +0300

wb-mqtt-homeui (2.37.0) stable; urgency=medium

* Boots selection on logs page is limited to "All boots"/"Last boot" options.
Expand Down