mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Forgot that I still had everything hard-coded to central time. Changed it to be configurable per account.
This commit is contained in:
parent
98d1f0168c
commit
3d7f116baa
|
@ -33,13 +33,14 @@ public interface CurrentMonitorDao {
|
||||||
void updateSummaries(BreakerGroup _rootGroup, Set<Date> _daysToSummarize, TimeZone _tz);
|
void updateSummaries(BreakerGroup _rootGroup, Set<Date> _daysToSummarize, TimeZone _tz);
|
||||||
|
|
||||||
String authenticateAccount(String _username, String _password);
|
String authenticateAccount(String _username, String _password);
|
||||||
String getAuthCodeForEmail(String _email);
|
String getAuthCodeForEmail(String _email, TimeZone _tz);
|
||||||
Account authCodeToAccount(String _authCode);
|
Account authCodeToAccount(String _authCode);
|
||||||
AuthCode decryptAuthCode(String _authCode);
|
AuthCode decryptAuthCode(String _authCode);
|
||||||
|
|
||||||
Account putAccount(Account _account);
|
Account putAccount(Account _account);
|
||||||
Account getAccount(int _accountId);
|
Account getAccount(int _accountId);
|
||||||
Account getAccountByUsername(String _username);
|
Account getAccountByUsername(String _username);
|
||||||
|
TimeZone getTimeZoneForAccount(int _accountId);
|
||||||
|
|
||||||
MongoProxy getProxy();
|
MongoProxy getProxy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
@ -55,7 +54,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||||
proxy.ensureIndex(BreakerPower.class, DaoSort.sort("account_id").then("key"));
|
proxy.ensureIndex(BreakerPower.class, DaoSort.sort("account_id").then("key"));
|
||||||
proxy.ensureIndex(HubPowerMinute.class, DaoSort.sort("account_id").then("minute"));
|
proxy.ensureIndex(HubPowerMinute.class, DaoSort.sort("account_id").then("minute"));
|
||||||
proxy.ensureIndex(BreakerGroupEnergy.class, DaoSort.sort("account_id").then("group_id").then("view_mode"));
|
proxy.ensureIndex(BreakerGroupEnergy.class, DaoSort.sort("account_id").then("group_id").then("view_mode"));
|
||||||
proxy.ensureIndex(BreakerGroupSummary.class, DaoSort.sort("account_id").then("group_id").then("view_mode"));
|
proxy.ensureIndex(BreakerGroupSummary.class, DaoSort.sort("account_id").then("group_id").then("view_mode").then("start"));
|
||||||
proxy.ensureIndex(DirtyMinute.class, DaoSort.sort("posted"));
|
proxy.ensureIndex(DirtyMinute.class, DaoSort.sort("posted"));
|
||||||
for (DirtyMinute minute : proxy.queryAll(DirtyMinute.class)) {
|
for (DirtyMinute minute : proxy.queryAll(DirtyMinute.class)) {
|
||||||
updateSummaries(minute);
|
updateSummaries(minute);
|
||||||
|
@ -95,7 +94,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||||
private void updateSummaries(DirtyMinute _minute) {
|
private void updateSummaries(DirtyMinute _minute) {
|
||||||
DebugTimer timer = new DebugTimer("Updating summaries", logger);
|
DebugTimer timer = new DebugTimer("Updating summaries", logger);
|
||||||
List<HubPowerMinute> minutes = proxy.query(HubPowerMinute.class, new DaoQuery("account_id", _minute.getAccountId()).and("minute", _minute.getMinute()));
|
List<HubPowerMinute> minutes = proxy.query(HubPowerMinute.class, new DaoQuery("account_id", _minute.getAccountId()).and("minute", _minute.getMinute()));
|
||||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
TimeZone tz = getTimeZoneForAccount(_minute.getAccountId());
|
||||||
BreakerConfig config = getConfig(_minute.getAccountId());
|
BreakerConfig config = getConfig(_minute.getAccountId());
|
||||||
BreakerGroup group = CollectionUtils.getFirst(config.getBreakerGroups());
|
BreakerGroup group = CollectionUtils.getFirst(config.getBreakerGroups());
|
||||||
Date day = DateUtils.getMidnightBefore(_minute.getMinuteAsDate(), tz);
|
Date day = DateUtils.getMidnightBefore(_minute.getMinuteAsDate(), tz);
|
||||||
|
@ -103,7 +102,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||||
if (summary == null)
|
if (summary == null)
|
||||||
summary = new BreakerGroupEnergy(group, minutes, EnergyBlockViewMode.DAY, day, tz);
|
summary = new BreakerGroupEnergy(group, minutes, EnergyBlockViewMode.DAY, day, tz);
|
||||||
else
|
else
|
||||||
summary.addEnergy(group, minutes, tz);
|
summary.addEnergy(group, minutes);
|
||||||
putBreakerGroupEnergy(summary);
|
putBreakerGroupEnergy(summary);
|
||||||
updateSummaries(group, CollectionUtils.asHashSet(day), tz);
|
updateSummaries(group, CollectionUtils.asHashSet(day), tz);
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
@ -216,12 +215,13 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthCodeForEmail(String _email) {
|
public String getAuthCodeForEmail(String _email, TimeZone _tz) {
|
||||||
_email = _email.toLowerCase().trim();
|
_email = _email.toLowerCase().trim();
|
||||||
Account account = getAccountByUsername(_email);
|
Account account = getAccountByUsername(_email);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
account = new Account();
|
account = new Account();
|
||||||
account.setUsername(_email);
|
account.setUsername(_email);
|
||||||
|
account.setTimezone(_tz.getID());
|
||||||
putAccount(account);
|
putAccount(account);
|
||||||
}
|
}
|
||||||
return aes.encryptToBase64(DaoSerializer.toZipBson(new AuthCode(account.getId(), account.getAuxiliaryAccountIds())));
|
return aes.encryptToBase64(DaoSerializer.toZipBson(new AuthCode(account.getId(), account.getAuxiliaryAccountIds())));
|
||||||
|
@ -259,6 +259,20 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||||
return clearPassword(proxy.queryOne(Account.class, new DaoQuery("username", NullUtils.makeNotNull(_username).toLowerCase().trim())));
|
return clearPassword(proxy.queryOne(Account.class, new DaoQuery("username", NullUtils.makeNotNull(_username).toLowerCase().trim())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimeZone getTimeZoneForAccount(int _accountId) {
|
||||||
|
String timezone = proxy.queryForOneField(Account.class, new DaoQuery("_id", String.valueOf(_accountId)), "timezone");
|
||||||
|
TimeZone tz = null;
|
||||||
|
try {
|
||||||
|
if (NullUtils.isNotEmpty(timezone))
|
||||||
|
tz = TimeZone.getTimeZone(timezone);
|
||||||
|
}
|
||||||
|
catch (Exception _e) {
|
||||||
|
logger.error("TimeZone not configured correctly for account {}", _accountId);
|
||||||
|
}
|
||||||
|
return tz == null ? TimeZone.getTimeZone("America/Chicago") : tz;
|
||||||
|
}
|
||||||
|
|
||||||
private Account clearPassword(Account _account) {
|
private Account clearPassword(Account _account) {
|
||||||
if (_account == null)
|
if (_account == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class Account {
|
||||||
@PrimaryKey private int id;
|
@PrimaryKey private int id;
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
|
private String timezone;
|
||||||
private List<Integer> auxiliaryAccountIds;
|
private List<Integer> auxiliaryAccountIds;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -36,6 +37,14 @@ public class Account {
|
||||||
password = _password;
|
password = _password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTimezone() {
|
||||||
|
return timezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimezone(String _timezone) {
|
||||||
|
timezone = _timezone;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Integer> getAuxiliaryAccountIds() {
|
public List<Integer> getAuxiliaryAccountIds() {
|
||||||
return auxiliaryAccountIds;
|
return auxiliaryAccountIds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,38 +28,41 @@ public class BreakerGroupEnergy {
|
||||||
private List<EnergyBlock> energyBlocks;
|
private List<EnergyBlock> energyBlocks;
|
||||||
private double toGrid;
|
private double toGrid;
|
||||||
private double fromGrid;
|
private double fromGrid;
|
||||||
|
private TimeZone timezone;
|
||||||
|
|
||||||
public BreakerGroupEnergy() {
|
public BreakerGroupEnergy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BreakerGroupEnergy(BreakerGroup _group, Map<String, List<BreakerPower>> _powerReadings, EnergyBlockViewMode _viewMode, Date _start, TimeZone _tz) {
|
public BreakerGroupEnergy(BreakerGroup _group, Map<String, List<BreakerPower>> _powerReadings, EnergyBlockViewMode _viewMode, Date _start, TimeZone _timezone) {
|
||||||
groupId = _group.getId();
|
groupId = _group.getId();
|
||||||
groupName = _group.getName();
|
groupName = _group.getName();
|
||||||
viewMode = _viewMode;
|
viewMode = _viewMode;
|
||||||
start = _start;
|
start = _start;
|
||||||
accountId = _group.getAccountId();
|
accountId = _group.getAccountId();
|
||||||
subGroups = CollectionUtils.transform(_group.getSubGroups(), _g -> new BreakerGroupEnergy(_g, _powerReadings, _viewMode, _start, _tz));
|
timezone = _timezone;
|
||||||
|
subGroups = CollectionUtils.transform(_group.getSubGroups(), _g -> new BreakerGroupEnergy(_g, _powerReadings, _viewMode, _start, timezone));
|
||||||
energyBlocks = new ArrayList<>();
|
energyBlocks = new ArrayList<>();
|
||||||
List<String> breakerKeys = CollectionUtils.transform(_group.getBreakers(), Breaker::getKey);
|
List<String> breakerKeys = CollectionUtils.transform(_group.getBreakers(), Breaker::getKey);
|
||||||
if (!breakerKeys.isEmpty()) {
|
if (!breakerKeys.isEmpty()) {
|
||||||
for (BreakerPower power : CollectionUtils.aggregate(breakerKeys, _powerReadings::get)) {
|
for (BreakerPower power : CollectionUtils.aggregate(breakerKeys, _powerReadings::get)) {
|
||||||
addEnergy(groupId, power.getReadTime(), power.getPower(), _tz);
|
addEnergy(groupId, power.getReadTime(), power.getPower());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BreakerGroupEnergy(BreakerGroup _group, List<HubPowerMinute> _power, EnergyBlockViewMode _viewMode, Date _start, TimeZone _tz) {
|
public BreakerGroupEnergy(BreakerGroup _group, List<HubPowerMinute> _power, EnergyBlockViewMode _viewMode, Date _start, TimeZone _timezone) {
|
||||||
groupId = _group.getId();
|
groupId = _group.getId();
|
||||||
groupName = _group.getName();
|
groupName = _group.getName();
|
||||||
viewMode = _viewMode;
|
viewMode = _viewMode;
|
||||||
start = _start;
|
start = _start;
|
||||||
accountId = _group.getAccountId();
|
accountId = _group.getAccountId();
|
||||||
subGroups = CollectionUtils.transform(_group.getSubGroups(), _g -> new BreakerGroupEnergy(_g, (List<HubPowerMinute>)null, _viewMode, _start, _tz));
|
timezone = _timezone;
|
||||||
|
subGroups = CollectionUtils.transform(_group.getSubGroups(), _g -> new BreakerGroupEnergy(_g, (List<HubPowerMinute>)null, _viewMode, _start, timezone));
|
||||||
energyBlocks = new ArrayList<>();
|
energyBlocks = new ArrayList<>();
|
||||||
addEnergy(_group, _power, _tz);
|
addEnergy(_group, _power);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEnergy(BreakerGroup _group, List<HubPowerMinute> _hubPower, TimeZone _tz) {
|
public void addEnergy(BreakerGroup _group, List<HubPowerMinute> _hubPower) {
|
||||||
Map<String, Breaker> breakers = CollectionUtils.transformToMap(_group.getAllBreakers(), Breaker::getKey);
|
Map<String, Breaker> breakers = CollectionUtils.transformToMap(_group.getAllBreakers(), Breaker::getKey);
|
||||||
Map<String, BreakerGroup> breakerKeyToGroup = new HashMap<>();
|
Map<String, BreakerGroup> breakerKeyToGroup = new HashMap<>();
|
||||||
for (BreakerGroup group : _group.getAllBreakerGroups()) {
|
for (BreakerGroup group : _group.getAllBreakerGroups()) {
|
||||||
|
@ -67,14 +70,14 @@ public class BreakerGroupEnergy {
|
||||||
breakerKeyToGroup.put(b.getKey(), group);
|
breakerKeyToGroup.put(b.getKey(), group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addEnergy(breakers, breakerKeyToGroup, _hubPower, _tz);
|
addEnergy(breakers, breakerKeyToGroup, _hubPower);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEnergy(Map<String, Breaker> _breakers, Map<String, BreakerGroup> _breakerKeyToGroup, List<HubPowerMinute> _hubPower, TimeZone _tz) {
|
public void addEnergy(Map<String, Breaker> _breakers, Map<String, BreakerGroup> _breakerKeyToGroup, List<HubPowerMinute> _hubPower) {
|
||||||
if (CollectionUtils.isEmpty(_hubPower) || CollectionUtils.anyQualify(_hubPower, _p->_p.getAccountId() != accountId))
|
if (CollectionUtils.isEmpty(_hubPower) || CollectionUtils.anyQualify(_hubPower, _p->_p.getAccountId() != accountId))
|
||||||
return;
|
return;
|
||||||
Date minute = CollectionUtils.getFirst(_hubPower).getMinuteAsDate();
|
Date minute = CollectionUtils.getFirst(_hubPower).getMinuteAsDate();
|
||||||
resetEnergy(minute, _tz);
|
resetEnergy(minute);
|
||||||
Map<Integer, MeterMinute> meters = new HashMap<>();
|
Map<Integer, MeterMinute> meters = new HashMap<>();
|
||||||
for (HubPowerMinute hubPower : _hubPower) {
|
for (HubPowerMinute hubPower : _hubPower) {
|
||||||
for (BreakerPowerMinute breaker : CollectionUtils.makeNotNull(hubPower.getBreakers())) {
|
for (BreakerPowerMinute breaker : CollectionUtils.makeNotNull(hubPower.getBreakers())) {
|
||||||
|
@ -92,7 +95,7 @@ public class BreakerGroupEnergy {
|
||||||
else
|
else
|
||||||
meter.solar[idx] += -power;
|
meter.solar[idx] += -power;
|
||||||
if (power != 0.0)
|
if (power != 0.0)
|
||||||
addEnergy(group.getId(), minute, power, _tz);
|
addEnergy(group.getId(), minute, power);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,21 +111,21 @@ public class BreakerGroupEnergy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetEnergy(Date _readTime, TimeZone _tz) {
|
public void resetEnergy(Date _readTime) {
|
||||||
EnergyBlock block = getBlock(_readTime, _tz, false);
|
EnergyBlock block = getBlock(_readTime, false);
|
||||||
if (block != null)
|
if (block != null)
|
||||||
block.setJoules(0);
|
block.setJoules(0);
|
||||||
for (BreakerGroupEnergy subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
for (BreakerGroupEnergy subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
||||||
subGroup.resetEnergy(_readTime, _tz);
|
subGroup.resetEnergy(_readTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEnergy(String _groupId, Date _readTime, double _joules, TimeZone _tz) {
|
public void addEnergy(String _groupId, Date _readTime, double _joules) {
|
||||||
if (NullUtils.isEqual(groupId, _groupId))
|
if (NullUtils.isEqual(groupId, _groupId))
|
||||||
getBlock(_readTime, _tz).addJoules(_joules);
|
getBlock(_readTime).addJoules(_joules);
|
||||||
else {
|
else {
|
||||||
for (BreakerGroupEnergy subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
for (BreakerGroupEnergy subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
||||||
subGroup.addEnergy(_groupId, _readTime, _joules, _tz);
|
subGroup.addEnergy(_groupId, _readTime, _joules);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,9 +137,10 @@ public class BreakerGroupEnergy {
|
||||||
energy.setAccountId(_group.getAccountId());
|
energy.setAccountId(_group.getAccountId());
|
||||||
energy.setViewMode(_viewMode);
|
energy.setViewMode(_viewMode);
|
||||||
energy.setStart(_start);
|
energy.setStart(_start);
|
||||||
|
energy.setTimeZone(_tz);
|
||||||
energy.setSubGroups(CollectionUtils.transform(_group.getSubGroups(), _g -> BreakerGroupEnergy.summary(_g, _energies, _viewMode, _start, _tz)));
|
energy.setSubGroups(CollectionUtils.transform(_group.getSubGroups(), _g -> BreakerGroupEnergy.summary(_g, _energies, _viewMode, _start, _tz)));
|
||||||
for (BreakerGroupSummary curEnergy : CollectionUtils.makeNotNull(_energies.get(_group.getId()))) {
|
for (BreakerGroupSummary curEnergy : CollectionUtils.makeNotNull(_energies.get(_group.getId()))) {
|
||||||
EnergyBlock block = energy.getBlock(curEnergy.getStart(), _tz);
|
EnergyBlock block = energy.getBlock(curEnergy.getStart());
|
||||||
block.addJoules(curEnergy.getJoules());
|
block.addJoules(curEnergy.getJoules());
|
||||||
energy.setToGrid(energy.getToGrid()+curEnergy.getToGrid());
|
energy.setToGrid(energy.getToGrid()+curEnergy.getToGrid());
|
||||||
energy.setFromGrid(energy.getFromGrid()+curEnergy.getFromGrid());
|
energy.setFromGrid(energy.getFromGrid()+curEnergy.getFromGrid());
|
||||||
|
@ -144,20 +148,20 @@ public class BreakerGroupEnergy {
|
||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnergyBlock getBlock(Date _readTime, TimeZone _tz) {
|
private EnergyBlock getBlock(Date _readTime) {
|
||||||
return getBlock(_readTime, _tz, true);
|
return getBlock(_readTime, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnergyBlock getBlock(Date _readTime, TimeZone _tz, boolean _add) {
|
private EnergyBlock getBlock(Date _readTime, boolean _add) {
|
||||||
int size = CollectionUtils.size(energyBlocks);
|
int size = CollectionUtils.size(energyBlocks);
|
||||||
int idx = viewMode.blockIndex(_readTime, _tz);
|
int idx = viewMode.blockIndex(_readTime, timezone);
|
||||||
if (_add && (idx >= size)) {
|
if (_add && (idx >= size)) {
|
||||||
if (energyBlocks == null)
|
if (energyBlocks == null)
|
||||||
energyBlocks = new ArrayList<>();
|
energyBlocks = new ArrayList<>();
|
||||||
LinkedList<EnergyBlock> newBlocks = new LinkedList<>();
|
LinkedList<EnergyBlock> newBlocks = new LinkedList<>();
|
||||||
Date end = viewMode.toBlockEnd(_readTime, _tz);
|
Date end = viewMode.toBlockEnd(_readTime, timezone);
|
||||||
while (idx >= size) {
|
while (idx >= size) {
|
||||||
Date start = viewMode.decrementBlock(end, _tz);
|
Date start = viewMode.decrementBlock(end, timezone);
|
||||||
newBlocks.add(new EnergyBlock(start, end, 0));
|
newBlocks.add(new EnergyBlock(start, end, 0));
|
||||||
end = start;
|
end = start;
|
||||||
size++;
|
size++;
|
||||||
|
@ -254,6 +258,14 @@ public class BreakerGroupEnergy {
|
||||||
fromGrid = _fromGrid;
|
fromGrid = _fromGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TimeZone getTimeZone() {
|
||||||
|
return timezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeZone(TimeZone _timezone) {
|
||||||
|
timezone = _timezone;
|
||||||
|
}
|
||||||
|
|
||||||
public double wattHours() {
|
public double wattHours() {
|
||||||
return joules() / 3600;
|
return joules() / 3600;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class AccountSerializer extends AbstractDaoSerializer<Account>
|
||||||
d.put("_id", String.valueOf(_o.getId()));
|
d.put("_id", String.valueOf(_o.getId()));
|
||||||
d.put("username", _o.getUsername());
|
d.put("username", _o.getUsername());
|
||||||
d.put("password", _o.getPassword());
|
d.put("password", _o.getPassword());
|
||||||
|
d.put("timezone", _o.getTimezone());
|
||||||
if (CollectionUtils.isNotEmpty(_o.getAuxiliaryAccountIds()))
|
if (CollectionUtils.isNotEmpty(_o.getAuxiliaryAccountIds()))
|
||||||
d.put("aux_account_ids", CollectionUtils.toByteArray(_o.getAuxiliaryAccountIds()));
|
d.put("aux_account_ids", CollectionUtils.toByteArray(_o.getAuxiliaryAccountIds()));
|
||||||
return d;
|
return d;
|
||||||
|
@ -44,6 +45,7 @@ public class AccountSerializer extends AbstractDaoSerializer<Account>
|
||||||
o.setId(DaoSerializer.getInteger(_d, "_id"));
|
o.setId(DaoSerializer.getInteger(_d, "_id"));
|
||||||
o.setUsername(DaoSerializer.getString(_d, "username"));
|
o.setUsername(DaoSerializer.getString(_d, "username"));
|
||||||
o.setPassword(DaoSerializer.getString(_d, "password"));
|
o.setPassword(DaoSerializer.getString(_d, "password"));
|
||||||
|
o.setTimezone(DaoSerializer.getString(_d, "timezone"));
|
||||||
o.setAuxiliaryAccountIds(CollectionUtils.fromByteArrayOfIntegers(DaoSerializer.getByteArray(_d, "aux_account_ids")));
|
o.setAuxiliaryAccountIds(CollectionUtils.fromByteArrayOfIntegers(DaoSerializer.getByteArray(_d, "aux_account_ids")));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.lanternsoftware.datamodel.currentmonitor.BreakerGroupEnergy;
|
||||||
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlock;
|
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlock;
|
||||||
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlockViewMode;
|
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlockViewMode;
|
||||||
import com.lanternsoftware.util.CollectionUtils;
|
import com.lanternsoftware.util.CollectionUtils;
|
||||||
|
import com.lanternsoftware.util.DateUtils;
|
||||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||||
import com.lanternsoftware.util.dao.DaoEntity;
|
import com.lanternsoftware.util.dao.DaoEntity;
|
||||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||||
|
@ -41,10 +42,11 @@ public class BreakerGroupEnergySerializer extends AbstractDaoSerializer<BreakerG
|
||||||
d.put("view_mode", DaoSerializer.toEnumName(_o.getViewMode()));
|
d.put("view_mode", DaoSerializer.toEnumName(_o.getViewMode()));
|
||||||
d.put("start", DaoSerializer.toLong(_o.getStart()));
|
d.put("start", DaoSerializer.toLong(_o.getStart()));
|
||||||
d.put("sub_groups", DaoSerializer.toDaoEntities(_o.getSubGroups(), DaoProxyType.MONGO));
|
d.put("sub_groups", DaoSerializer.toDaoEntities(_o.getSubGroups(), DaoProxyType.MONGO));
|
||||||
|
TimeZone tz = DateUtils.defaultTimeZone(_o.getTimeZone());
|
||||||
|
d.put("timezone", tz.getID());
|
||||||
if (CollectionUtils.size(_o.getEnergyBlocks()) > 0) {
|
if (CollectionUtils.size(_o.getEnergyBlocks()) > 0) {
|
||||||
Date start = _o.getStart();
|
Date start = _o.getStart();
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
|
||||||
ByteBuffer bb = ByteBuffer.allocate(_o.getViewMode().blockCount(start, tz) * 4);
|
ByteBuffer bb = ByteBuffer.allocate(_o.getViewMode().blockCount(start, tz) * 4);
|
||||||
for (EnergyBlock b : _o.getEnergyBlocks()) {
|
for (EnergyBlock b : _o.getEnergyBlocks()) {
|
||||||
if (b.getStart().before(start))
|
if (b.getStart().before(start))
|
||||||
|
@ -71,7 +73,6 @@ public class BreakerGroupEnergySerializer extends AbstractDaoSerializer<BreakerG
|
||||||
@Override
|
@Override
|
||||||
public BreakerGroupEnergy fromDaoEntity(DaoEntity _d)
|
public BreakerGroupEnergy fromDaoEntity(DaoEntity _d)
|
||||||
{
|
{
|
||||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
|
||||||
BreakerGroupEnergy o = new BreakerGroupEnergy();
|
BreakerGroupEnergy o = new BreakerGroupEnergy();
|
||||||
o.setGroupId(DaoSerializer.getString(_d, "group_id"));
|
o.setGroupId(DaoSerializer.getString(_d, "group_id"));
|
||||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||||
|
@ -79,13 +80,14 @@ public class BreakerGroupEnergySerializer extends AbstractDaoSerializer<BreakerG
|
||||||
o.setViewMode(DaoSerializer.getEnum(_d, "view_mode", EnergyBlockViewMode.class));
|
o.setViewMode(DaoSerializer.getEnum(_d, "view_mode", EnergyBlockViewMode.class));
|
||||||
o.setStart(DaoSerializer.getDate(_d, "start"));
|
o.setStart(DaoSerializer.getDate(_d, "start"));
|
||||||
o.setSubGroups(DaoSerializer.getList(_d, "sub_groups", BreakerGroupEnergy.class));
|
o.setSubGroups(DaoSerializer.getList(_d, "sub_groups", BreakerGroupEnergy.class));
|
||||||
|
o.setTimeZone(DateUtils.fromTimeZoneId(DaoSerializer.getString(_d, "timezone")));
|
||||||
List<EnergyBlock> blocks = new ArrayList<>();
|
List<EnergyBlock> blocks = new ArrayList<>();
|
||||||
byte[] blockData = DaoSerializer.getByteArray(_d, "blocks");
|
byte[] blockData = DaoSerializer.getByteArray(_d, "blocks");
|
||||||
if (CollectionUtils.length(blockData) > 0) {
|
if (CollectionUtils.length(blockData) > 0) {
|
||||||
ByteBuffer bb = ByteBuffer.wrap(blockData);
|
ByteBuffer bb = ByteBuffer.wrap(blockData);
|
||||||
Date start = o.getStart();
|
Date start = o.getStart();
|
||||||
while (bb.hasRemaining()) {
|
while (bb.hasRemaining()) {
|
||||||
EnergyBlock block = new EnergyBlock(start, o.getViewMode().toBlockEnd(start, tz), bb.getFloat());
|
EnergyBlock block = new EnergyBlock(start, o.getViewMode().toBlockEnd(start, o.getTimeZone()), bb.getFloat());
|
||||||
blocks.add(block);
|
blocks.add(block);
|
||||||
start = block.getEnd();
|
start = block.getEnd();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
|
||||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||||
import com.lanternsoftware.currentmonitor.context.Globals;
|
import com.lanternsoftware.currentmonitor.context.Globals;
|
||||||
|
import com.lanternsoftware.util.DateUtils;
|
||||||
import com.lanternsoftware.util.LanternFiles;
|
import com.lanternsoftware.util.LanternFiles;
|
||||||
import com.lanternsoftware.util.NullUtils;
|
import com.lanternsoftware.util.NullUtils;
|
||||||
import com.lanternsoftware.util.ResourceLoader;
|
import com.lanternsoftware.util.ResourceLoader;
|
||||||
|
@ -38,7 +39,7 @@ public class AuthServlet extends CMServlet {
|
||||||
if (idToken != null) {
|
if (idToken != null) {
|
||||||
GoogleIdToken.Payload payload = idToken.getPayload();
|
GoogleIdToken.Payload payload = idToken.getPayload();
|
||||||
String email = payload.getEmail();
|
String email = payload.getEmail();
|
||||||
authCode = Globals.dao.getAuthCodeForEmail(email);
|
authCode = Globals.dao.getAuthCodeForEmail(email, DateUtils.fromTimeZoneId(_req.getHeader("timezone")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception _e) {
|
catch (Exception _e) {
|
||||||
|
|
|
@ -3,9 +3,8 @@ package com.lanternsoftware.currentmonitor.servlet;
|
||||||
import com.lanternsoftware.currentmonitor.context.Globals;
|
import com.lanternsoftware.currentmonitor.context.Globals;
|
||||||
import com.lanternsoftware.datamodel.currentmonitor.Account;
|
import com.lanternsoftware.datamodel.currentmonitor.Account;
|
||||||
import com.lanternsoftware.datamodel.currentmonitor.SignupResponse;
|
import com.lanternsoftware.datamodel.currentmonitor.SignupResponse;
|
||||||
|
import com.lanternsoftware.util.DateUtils;
|
||||||
import com.lanternsoftware.util.NullUtils;
|
import com.lanternsoftware.util.NullUtils;
|
||||||
import com.lanternsoftware.util.dao.DaoEntity;
|
|
||||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
|
||||||
import com.lanternsoftware.util.email.EmailValidator;
|
import com.lanternsoftware.util.email.EmailValidator;
|
||||||
import com.lanternsoftware.util.servlet.BasicAuth;
|
import com.lanternsoftware.util.servlet.BasicAuth;
|
||||||
|
|
||||||
|
@ -38,6 +37,7 @@ public class SignupServlet extends CMServlet {
|
||||||
acct = new Account();
|
acct = new Account();
|
||||||
acct.setUsername(auth.getUsername());
|
acct.setUsername(auth.getUsername());
|
||||||
acct.setPassword(auth.getPassword());
|
acct.setPassword(auth.getPassword());
|
||||||
|
acct.setTimezone(DateUtils.fromTimeZoneId(_req.getHeader("timezone")).getID());
|
||||||
Globals.dao.putAccount(acct);
|
Globals.dao.putAccount(acct);
|
||||||
String authCode = Globals.dao.authenticateAccount(auth.getUsername(), auth.getPassword());
|
String authCode = Globals.dao.authenticateAccount(auth.getUsername(), auth.getPassword());
|
||||||
jsonResponse(_rep, SignupResponse.success(authCode));
|
jsonResponse(_rep, SignupResponse.success(authCode));
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class RebuildSummaries {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int accountId = 1;
|
int accountId = 1;
|
||||||
CurrentMonitorDao dao = new MongoCurrentMonitorDao(MongoConfig.fromDisk(LanternFiles.OPS_PATH + "mongo.cfg"));
|
CurrentMonitorDao dao = new MongoCurrentMonitorDao(MongoConfig.fromDisk(LanternFiles.OPS_PATH + "mongo.cfg"));
|
||||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
TimeZone tz = dao.getTimeZoneForAccount(accountId);
|
||||||
Date start = DateUtils.date(1, 7, 2021, tz);
|
Date start = DateUtils.date(1, 7, 2021, tz);
|
||||||
// Date start = DateUtils.getMidnightBeforeNow(tz);
|
// Date start = DateUtils.getMidnightBeforeNow(tz);
|
||||||
Date end = DateUtils.getMidnightAfterNow(tz);
|
Date end = DateUtils.getMidnightAfterNow(tz);
|
||||||
|
@ -49,7 +49,7 @@ public class RebuildSummaries {
|
||||||
if (energy == null)
|
if (energy == null)
|
||||||
energy = new BreakerGroupEnergy(root, minute, EnergyBlockViewMode.DAY, day.getKey(), tz);
|
energy = new BreakerGroupEnergy(root, minute, EnergyBlockViewMode.DAY, day.getKey(), tz);
|
||||||
else
|
else
|
||||||
energy.addEnergy(breakers, breakerKeyToGroup, minute, tz);
|
energy.addEnergy(breakers, breakerKeyToGroup, minute);
|
||||||
}
|
}
|
||||||
timer.stop();
|
timer.stop();
|
||||||
if (energy != null)
|
if (energy != null)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.lanternsoftware.util;
|
package com.lanternsoftware.util;
|
||||||
|
|
||||||
|
import java.sql.Time;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -655,4 +656,27 @@ public abstract class DateUtils {
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getTimeZoneId(TimeZone _tz) {
|
||||||
|
return getTimeZoneId(_tz, "America/Chicago");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTimeZoneId(TimeZone _tz, String _default) {
|
||||||
|
return (_tz == null) ? _default : _tz.getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeZone defaultTimeZone(TimeZone _tz) {
|
||||||
|
return defaultTimeZone(_tz, "America/Chicago");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeZone defaultTimeZone(TimeZone _tz, String _default) {
|
||||||
|
return (_tz == null) ? TimeZone.getTimeZone(_default) : _tz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeZone fromTimeZoneId(String _id) {
|
||||||
|
return fromTimeZoneId(_id, "America/Chicago");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeZone fromTimeZoneId(String _id, String _defaultId) {
|
||||||
|
return TimeZone.getTimeZone(NullUtils.isEmpty(_id) ? _defaultId : _id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user