Allow calibration of all ports on a hub at once in addition to individually.

This commit is contained in:
Mark Milligan 2021-01-24 12:41:46 -06:00
parent 6c6f750691
commit fa606cce84
6 changed files with 24 additions and 12 deletions

View File

@ -85,7 +85,7 @@ public class CurrentMonitor {
vRms /= samples.size(); vRms /= samples.size();
double oldVrms = _curCalibration * Math.sqrt(vRms); double oldVrms = _curCalibration * Math.sqrt(vRms);
if (oldVrms < 20) { if (oldVrms < 20) {
LOG.info("Could not get a valid voltage read, please check that your AC/AC transformer is connected"); LOG.error("Could not get a valid voltage read, please check that your AC/AC transformer is connected");
return 0.0; return 0.0;
} }
double newCal = (_voltage/oldVrms) * _curCalibration; double newCal = (_voltage/oldVrms) * _curCalibration;
@ -235,7 +235,7 @@ public class CurrentMonitor {
vRms /= validSamples.size(); vRms /= validSamples.size();
vRms = hub.getVoltageCalibrationFactor() * Math.sqrt(vRms); vRms = hub.getVoltageCalibrationFactor() * Math.sqrt(vRms);
int lowSampleRatio = (lowSamples * 100) / samples.getSampleCnt(); int lowSampleRatio = (lowSamples * 100) / samples.getSampleCnt();
double realPower = Math.abs((hub.getVoltageCalibrationFactor() * samples.getBreaker().getFinalCalibrationFactor() * pSum) / samples.getSampleCnt()); double realPower = Math.abs((hub.getVoltageCalibrationFactor() * hub.getPortCalibrationFactor() * samples.getBreaker().getFinalCalibrationFactor() * pSum) / samples.getSampleCnt());
if ((lowSampleRatio > 75) && realPower < 13.0) if ((lowSampleRatio > 75) && realPower < 13.0)
realPower = 0.0; realPower = 0.0;
if (samples.getBreaker().getPolarity() == BreakerPolarity.SOLAR) if (samples.getBreaker().getPolarity() == BreakerPolarity.SOLAR)

View File

@ -160,10 +160,8 @@ public class MonitorApp {
} }
}); });
monitor.submit(bluetoothConfig); monitor.submit(bluetoothConfig);
if (NullUtils.isNotEmpty(config.getAuthCode())) { if (NullUtils.isNotEmpty(config.getAuthCode()))
authCode = config.getAuthCode(); authCode = config.getAuthCode();
//TODO: check auth code validity
}
else { else {
HttpGet auth = new HttpGet(host + "auth"); HttpGet auth = new HttpGet(host + "auth");
HttpPool.addBasicAuthHeader(auth, config.getUsername(), config.getPassword()); HttpPool.addBasicAuthHeader(auth, config.getUsername(), config.getPassword());
@ -187,7 +185,7 @@ public class MonitorApp {
hub.setVoltageCalibrationFactor(newCal); hub.setVoltageCalibrationFactor(newCal);
config.setNeedsCalibration(false); config.setNeedsCalibration(false);
ResourceLoader.writeFile(WORKING_DIR + "config.json", DaoSerializer.toJson(config)); ResourceLoader.writeFile(WORKING_DIR + "config.json", DaoSerializer.toJson(config));
post(DaoSerializer.toZipBson(breakerConfig), "currentmonitor/config"); post(DaoSerializer.toZipBson(breakerConfig), "config");
} }
} }
List<Breaker> breakers = breakerConfig.getBreakersForHub(config.getHub()); List<Breaker> breakers = breakerConfig.getBreakersForHub(config.getHub());
@ -341,6 +339,7 @@ public class MonitorApp {
if (CollectionUtils.length(jar) == DaoSerializer.getInteger(meta, "size") && NullUtils.isEqual(DigestUtils.md5Hex(jar), DaoSerializer.getString(meta, "checksum"))) { if (CollectionUtils.length(jar) == DaoSerializer.getInteger(meta, "size") && NullUtils.isEqual(DigestUtils.md5Hex(jar), DaoSerializer.getString(meta, "checksum"))) {
LOG.info("Update downloaded, writing jar and restarting..."); LOG.info("Update downloaded, writing jar and restarting...");
ResourceLoader.writeFile(WORKING_DIR + "lantern-currentmonitor.jar", jar); ResourceLoader.writeFile(WORKING_DIR + "lantern-currentmonitor.jar", jar);
ConcurrencyUtils.sleep(5000);
try { try {
Runtime.getRuntime().exec("service currentmonitor restart"); Runtime.getRuntime().exec("service currentmonitor restart");
} catch (IOException _e) { } catch (IOException _e) {

View File

@ -2,6 +2,7 @@ package com.lanternsoftware.datamodel.currentmonitor;
import com.lanternsoftware.util.CollectionUtils; import com.lanternsoftware.util.CollectionUtils;
import com.lanternsoftware.util.NullUtils; import com.lanternsoftware.util.NullUtils;
import com.lanternsoftware.util.dao.DaoSerializer;
import com.lanternsoftware.util.dao.annotations.DBSerializable; import com.lanternsoftware.util.dao.annotations.DBSerializable;
import com.lanternsoftware.util.dao.annotations.PrimaryKey; import com.lanternsoftware.util.dao.annotations.PrimaryKey;
@ -102,7 +103,7 @@ public class BreakerConfig {
public String nextGroupId() { public String nextGroupId() {
List<Integer> ids = CollectionUtils.transform(getAllBreakerGroupIds(), NullUtils::toInteger); List<Integer> ids = CollectionUtils.transform(getAllBreakerGroupIds(), NullUtils::toInteger);
return String.valueOf(CollectionUtils.getLargest(ids) + 1); return String.valueOf(DaoSerializer.toInteger(CollectionUtils.getLargest(ids)) + 1);
} }
public void addGroup(BreakerGroup _group) { public void addGroup(BreakerGroup _group) {
@ -116,7 +117,7 @@ public class BreakerConfig {
public void removeInvalidGroups() { public void removeInvalidGroups() {
if (breakerGroups != null) if (breakerGroups != null)
breakerGroups.removeIf(_g->!_g.removeInvalidGroups()); breakerGroups.removeIf(_g->!_g.removeInvalidGroups(CollectionUtils.transformToSet(panels, BreakerPanel::getIndex)));
} }
public String getGroupIdForBreaker(Breaker _breaker) { public String getGroupIdForBreaker(Breaker _breaker) {

View File

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
@DBSerializable() @DBSerializable()
public class BreakerGroup { public class BreakerGroup {
@ -169,11 +170,11 @@ public class BreakerGroup {
return null; return null;
} }
public boolean removeInvalidGroups() { public boolean removeInvalidGroups(Set<Integer> _validPanels) {
if (subGroups != null) if (subGroups != null)
subGroups.removeIf(_g->!_g.removeInvalidGroups()); subGroups.removeIf(_g->!_g.removeInvalidGroups(_validPanels));
if (breakers != null) if (breakers != null)
breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.getPort() < 1)); breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.isTandemBreaker() && (_b.getPort() < 1)) || !_validPanels.contains(_b.getPanel()));
return CollectionUtils.isNotEmpty(subGroups) || CollectionUtils.isNotEmpty(breakers); return CollectionUtils.isNotEmpty(subGroups) || CollectionUtils.isNotEmpty(breakers);
} }

View File

@ -7,6 +7,7 @@ import com.lanternsoftware.util.dao.annotations.DBSerializable;
public class BreakerHub { public class BreakerHub {
private int hub; private int hub;
private double voltageCalibrationFactor; private double voltageCalibrationFactor;
private double portCalibrationFactor;
private int frequency; private int frequency;
private String bluetoothMac; private String bluetoothMac;
@ -19,13 +20,21 @@ public class BreakerHub {
} }
public double getVoltageCalibrationFactor() { public double getVoltageCalibrationFactor() {
return voltageCalibrationFactor; return voltageCalibrationFactor == 0.0?1.0:voltageCalibrationFactor;
} }
public void setVoltageCalibrationFactor(double _voltageCalibrationFactor) { public void setVoltageCalibrationFactor(double _voltageCalibrationFactor) {
voltageCalibrationFactor = _voltageCalibrationFactor; voltageCalibrationFactor = _voltageCalibrationFactor;
} }
public double getPortCalibrationFactor() {
return portCalibrationFactor == 0.0?1.0:portCalibrationFactor;
}
public void setPortCalibrationFactor(double _portCalibrationFactor) {
portCalibrationFactor = _portCalibrationFactor;
}
public int getFrequency() { public int getFrequency() {
return frequency; return frequency;
} }

View File

@ -27,6 +27,7 @@ public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
DaoEntity d = new DaoEntity(); DaoEntity d = new DaoEntity();
d.put("hub", _o.getHub()); d.put("hub", _o.getHub());
d.put("voltage_calibration_factor", _o.getVoltageCalibrationFactor()); d.put("voltage_calibration_factor", _o.getVoltageCalibrationFactor());
d.put("port_calibration_factor", _o.getPortCalibrationFactor());
d.put("frequency", _o.getFrequency()); d.put("frequency", _o.getFrequency());
d.put("bluetooth_mac", _o.getBluetoothMac()); d.put("bluetooth_mac", _o.getBluetoothMac());
return d; return d;
@ -38,6 +39,7 @@ public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
BreakerHub o = new BreakerHub(); BreakerHub o = new BreakerHub();
o.setHub(DaoSerializer.getInteger(_d, "hub")); o.setHub(DaoSerializer.getInteger(_d, "hub"));
o.setVoltageCalibrationFactor(DaoSerializer.getDouble(_d, "voltage_calibration_factor")); o.setVoltageCalibrationFactor(DaoSerializer.getDouble(_d, "voltage_calibration_factor"));
o.setPortCalibrationFactor(DaoSerializer.getDouble(_d, "port_calibration_factor"));
o.setFrequency(DaoSerializer.getInteger(_d, "frequency")); o.setFrequency(DaoSerializer.getInteger(_d, "frequency"));
o.setBluetoothMac(DaoSerializer.getString(_d, "bluetooth_mac")); o.setBluetoothMac(DaoSerializer.getString(_d, "bluetooth_mac"));
return o; return o;