mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Fix some timezone bugs.
This commit is contained in:
parent
181513c06d
commit
a43222049d
|
@ -41,6 +41,7 @@ public interface CurrentMonitorDao {
|
|||
Account getAccount(int _accountId);
|
||||
Account getAccountByUsername(String _username);
|
||||
TimeZone getTimeZoneForAccount(int _accountId);
|
||||
String getTimeZoneForAccount(String _authCode);
|
||||
|
||||
MongoProxy getProxy();
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
Account acct = proxy.queryOne(Account.class, new DaoQuery("username", _username));
|
||||
if ((acct == null) || !BCrypt.checkpw(_password, acct.getPassword()))
|
||||
return null;
|
||||
return aes.encryptToBase64(DaoSerializer.toZipBson(new AuthCode(acct.getId(), acct.getAuxiliaryAccountIds())));
|
||||
return toAuthCode(acct.getId(), acct.getAuxiliaryAccountIds());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,7 +226,13 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
account.setTimezone(_tz.getID());
|
||||
putAccount(account);
|
||||
}
|
||||
return aes.encryptToBase64(DaoSerializer.toZipBson(new AuthCode(account.getId(), account.getAuxiliaryAccountIds())));
|
||||
return toAuthCode(account.getId(), account.getAuxiliaryAccountIds());
|
||||
}
|
||||
|
||||
public String toAuthCode(int _acctId, List<Integer> _auxAcctIds) {
|
||||
if (_acctId < 1)
|
||||
return null;
|
||||
return aes.encryptToBase64(DaoSerializer.toZipBson(new AuthCode(_acctId, _auxAcctIds)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -275,6 +281,14 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
return tz == null ? TimeZone.getTimeZone("America/Chicago") : tz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTimeZoneForAccount(String _authCode) {
|
||||
AuthCode code = decryptAuthCode(_authCode);
|
||||
if (code == null)
|
||||
return null;
|
||||
return getTimeZoneForAccount(code.getAccountId()).getID();
|
||||
}
|
||||
|
||||
private Account clearPassword(Account _account) {
|
||||
if (_account == null)
|
||||
return null;
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
|||
public class SignupResponse {
|
||||
private String error;
|
||||
private String authCode;
|
||||
private String timezone;
|
||||
|
||||
public SignupResponse() {
|
||||
}
|
||||
|
@ -17,9 +18,10 @@ public class SignupResponse {
|
|||
return response;
|
||||
}
|
||||
|
||||
public static SignupResponse success(String _authCode) {
|
||||
public static SignupResponse success(String _authCode, String _timezone) {
|
||||
SignupResponse response = new SignupResponse();
|
||||
response.setAuthCode(_authCode);
|
||||
response.setTimezone(_timezone);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -39,6 +41,14 @@ public class SignupResponse {
|
|||
authCode = _authCode;
|
||||
}
|
||||
|
||||
public String getTimezone() {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
public void setTimezone(String _timezone) {
|
||||
timezone = _timezone;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return NullUtils.isEmpty(error) && NullUtils.isNotEmpty(authCode);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.lanternsoftware.datamodel.currentmonitor.bom;
|
|||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerConfig;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerType;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.csv.CSV;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
@ -18,7 +19,33 @@ public class BOM {
|
|||
public static BOM fromConfig(BreakerConfig _config) {
|
||||
BOM bom = new BOM();
|
||||
bom.setLineItems(new ArrayList<>());
|
||||
int hubCnt = (int)Math.ceil(CollectionUtils.size(_config.getAllBreakers())/15.0);
|
||||
Map<Integer, AtomicInteger> ctCnts = new TreeMap<>();
|
||||
Map<Integer, AtomicInteger> ctDuplicates = new TreeMap<>();
|
||||
for (Breaker breaker : CollectionUtils.makeNotNull(_config.getAllBreakers())) {
|
||||
if (breaker.getSizeAmps() <= 20) {
|
||||
ctCnts.computeIfAbsent(20, (_k) -> new AtomicInteger(0)).getAndIncrement();
|
||||
if (breaker.getType() == BreakerType.DOUBLE_POLE_TOP_ONE_CT)
|
||||
ctDuplicates.computeIfAbsent(20, (_k) -> new AtomicInteger(0)).getAndIncrement();
|
||||
}
|
||||
else if (breaker.getSizeAmps() <= 30) {
|
||||
ctCnts.computeIfAbsent(30, (_k) -> new AtomicInteger(0)).getAndIncrement();
|
||||
if (breaker.getType() == BreakerType.DOUBLE_POLE_TOP_ONE_CT)
|
||||
ctDuplicates.computeIfAbsent(30, (_k) -> new AtomicInteger(0)).getAndIncrement();
|
||||
}
|
||||
else {
|
||||
ctCnts.computeIfAbsent(50, (_k) -> new AtomicInteger(0)).getAndIncrement();
|
||||
if (breaker.getType() == BreakerType.DOUBLE_POLE_TOP_ONE_CT)
|
||||
ctDuplicates.computeIfAbsent(50, (_k) -> new AtomicInteger(0)).getAndIncrement();
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Integer, AtomicInteger> ctCnt : ctDuplicates.entrySet()) {
|
||||
AtomicInteger cnt = ctCnts.get(ctCnt.getKey());
|
||||
if (cnt != null)
|
||||
cnt.getAndAdd(-ctCnt.getValue().get());
|
||||
}
|
||||
int breakerCnt = CollectionUtils.sumIntegers(CollectionUtils.transform(ctCnts.values(), AtomicInteger::get));
|
||||
int hubCnt = (int)Math.ceil(breakerCnt/15.0);
|
||||
|
||||
bom.getLineItems().add(new LineItem("Lantern Power Monitor Case", "LPMC1", "https://github.com/MarkBryanMilligan/LanternPowerMonitor/tree/main/case", 0.10, 3.00, hubCnt));
|
||||
bom.getLineItems().add(new LineItem("Lantern Power Monitor Case Lid", "LPMCL1", "https://github.com/MarkBryanMilligan/LanternPowerMonitor/tree/main/case", 0.10, 2.00, hubCnt));
|
||||
bom.getLineItems().add(new LineItem("Lantern Power Monitor Soldering Jig", "LPMSJ1", "https://github.com/MarkBryanMilligan/LanternPowerMonitor/tree/main/case", 0.10, 4.00, 1));
|
||||
|
@ -39,15 +66,6 @@ public class BOM {
|
|||
bom.getLineItems().add(new LineItem("M2.5x10mm Cap Screw", "A15120300ux0225", "https://www.amazon.com/gp/product/B01B1OD7IK", 0.10, 0.20, hubCnt*8));
|
||||
bom.getLineItems().add(new LineItem("M2.5x11mm Female x Female Standoff", "", "https://www.ebay.com/itm/50pcs-M2-5-Female-Hex-Screw-Brass-PCB-Standoffs-Hexagonal-Spacers/172746413434", 0.15, 0.25, hubCnt*4));
|
||||
bom.getLineItems().add(new LineItem("M2.5x12mm Female x Male Standoff", "", "https://www.ebay.com/itm/M2-5-2-5mm-Thread-6mm-Brass-Standoff-Spacer-Male-x-Female-20-50pcs-New/283432513974", 0.15, 0.25, hubCnt*4));
|
||||
Map<Integer, AtomicInteger> ctCnts = new TreeMap<>();
|
||||
for (Breaker breaker : CollectionUtils.makeNotNull(_config.getAllBreakers())) {
|
||||
if (breaker.getSizeAmps() <= 20)
|
||||
ctCnts.computeIfAbsent(20, (_k)->new AtomicInteger(0)).getAndIncrement();
|
||||
else if (breaker.getSizeAmps() <= 30)
|
||||
ctCnts.computeIfAbsent(30, (_k)->new AtomicInteger(0)).getAndIncrement();
|
||||
else
|
||||
ctCnts.computeIfAbsent(50, (_k)->new AtomicInteger(0)).getAndIncrement();
|
||||
}
|
||||
for (Map.Entry<Integer, AtomicInteger> ctCnt : ctCnts.entrySet()) {
|
||||
bom.getLineItems().add(new LineItem(String.format("%d Amp Current Transformer", ctCnt.getKey()), String.format("SCT-013-0%d", ctCnt.getKey()), "N/A", 5.00, 7.00, ctCnt.getValue().get()));
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public class SignupResponseSerializer extends AbstractDaoSerializer<SignupRespon
|
|||
DaoEntity d = new DaoEntity();
|
||||
d.put("error", _o.getError());
|
||||
d.put("auth_code", _o.getAuthCode());
|
||||
d.put("timezone", _o.getTimezone());
|
||||
return d;
|
||||
}
|
||||
|
||||
|
@ -36,6 +37,7 @@ public class SignupResponseSerializer extends AbstractDaoSerializer<SignupRespon
|
|||
SignupResponse o = new SignupResponse();
|
||||
o.setError(DaoSerializer.getString(_d, "error"));
|
||||
o.setAuthCode(DaoSerializer.getString(_d, "auth_code"));
|
||||
o.setTimezone(DaoSerializer.getString(_d, "timezone"));
|
||||
return o;
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public class AuthServlet extends CMServlet {
|
|||
} else
|
||||
authCode = Globals.dao.authenticateAccount(auth.getUsername(), auth.getPassword());
|
||||
}
|
||||
DaoEntity rep = new DaoEntity("auth_code", authCode);
|
||||
DaoEntity rep = new DaoEntity("auth_code", authCode).and("timezone", Globals.dao.getTimeZoneForAccount(authCode));
|
||||
if (isPath(_req, 0, "bin"))
|
||||
zipBsonResponse(_rep, rep);
|
||||
else
|
||||
|
|
|
@ -40,6 +40,6 @@ public class SignupServlet extends CMServlet {
|
|||
acct.setTimezone(DateUtils.fromTimeZoneId(_req.getHeader("timezone")).getID());
|
||||
Globals.dao.putAccount(acct);
|
||||
String authCode = Globals.dao.authenticateAccount(auth.getUsername(), auth.getPassword());
|
||||
jsonResponse(_rep, SignupResponse.success(authCode));
|
||||
jsonResponse(_rep, SignupResponse.success(authCode, acct.getTimezone()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user