Performance improvement for returning energy summaries from DB. Change the way MQTT values are posted. Add a BOM utf-8 char to the BOM csv, yo dawg, bom.

This commit is contained in:
MarkBryanMilligan
2021-08-29 22:53:41 -05:00
parent 77ceec745c
commit d63f6df1fd
12 changed files with 71 additions and 31 deletions

View File

@@ -20,18 +20,20 @@ public class BackupMinutes {
CurrentMonitorDao backupDao = new MongoCurrentMonitorDao(MongoConfig.fromDisk(LanternFiles.BACKUP_PATH + "mongo.cfg"));
Date now = new Date();
for (Account a : dao.getProxy().queryAll(Account.class)) {
if (a.getId() == 100)
if (a.getId() == 0)
continue;
DebugTimer t = new DebugTimer("Account " + a.getId());
if (NullUtils.isEmpty(a.getTimezone())) {
a.setTimezone("America/Chicago");
}
TimeZone tz = TimeZone.getTimeZone(a.getTimezone());
// Date start = DateUtils.addDays(DateUtils.getMidnightBeforeNow(tz), -2, tz);
HubPowerMinute minute = dao.getProxy().queryOne(HubPowerMinute.class, new DaoQuery("account_id", a.getId()), DaoSort.sort("minute"));
if (minute == null)
continue;
Date minStart = DateUtils.addDays(DateUtils.getMidnightBeforeNow(tz), -60, tz);
Date start = DateUtils.getMidnightBefore(minute.getMinuteAsDate(), tz);
if (minStart.after(start))
start = minStart;
Date end = DateUtils.addDays(start, 1, tz);
while (end.before(now)) {
DebugTimer t2 = new DebugTimer("Account Id: " + a.getId() + " Query Day " + DateUtils.format("MM/dd/yyyy", tz, start));
@@ -48,5 +50,6 @@ public class BackupMinutes {
t.stop();
}
dao.shutdown();
backupDao.shutdown();
}
}

View File

@@ -22,6 +22,7 @@ public interface CurrentMonitorDao {
List<BreakerPower> getBreakerPowerForAccount(int _accountId);
BreakerPower getLatestBreakerPower(int _accountId, int _hub, int _port);
BreakerGroupEnergy getBreakerGroupEnergy(int _accountId, String _groupId, EnergyBlockViewMode _viewMode, Date _start);
byte[] getBreakerGroupEnergyBinary(int _accountId, String _groupId, EnergyBlockViewMode _viewMode, Date _start);
void putBreakerGroupEnergy(BreakerGroupEnergy _energy);
void putHubPowerMinute(HubPowerMinute _power);

View File

@@ -125,6 +125,11 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
return proxy.queryOne(BreakerGroupEnergy.class, new DaoQuery("_id", BreakerGroupEnergy.toId(_accountId, _groupId, _viewMode, _start)));
}
@Override
public byte[] getBreakerGroupEnergyBinary(int _accountId, String _groupId, EnergyBlockViewMode _viewMode, Date _start) {
return DaoSerializer.toZipBson(proxy.queryForEntity(BreakerGroupEnergy.class, new DaoQuery("_id", BreakerGroupEnergy.toId(_accountId, _groupId, _viewMode, _start))));
}
@Override
public void updateSummaries(BreakerGroup _rootGroup, Set<Date> _daysToSummarize, TimeZone _tz) {
Set<Date> monthsToSummarize = CollectionUtils.transformToSet(_daysToSummarize, _c -> DateUtils.getStartOfMonth(_c, _tz));