mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Update summaries when billing rate configuration changes. Refactor some of the billing rate variable names to be more clear.
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
public enum BillingMode {
|
||||
ANY_DIRECTION,
|
||||
CONSUMPTION,
|
||||
PRODUCTION;
|
||||
}
|
||||
@@ -5,13 +5,14 @@ import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@DBSerializable
|
||||
public class BillingRate {
|
||||
private int meter;
|
||||
private int dayBillingCycleStart;
|
||||
private BillingMode mode;
|
||||
private GridFlow flow;
|
||||
private double rate;
|
||||
private BillingCurrency currency;
|
||||
private int timeOfDayStart;
|
||||
@@ -38,12 +39,12 @@ public class BillingRate {
|
||||
dayBillingCycleStart = _dayBillingCycleStart;
|
||||
}
|
||||
|
||||
public BillingMode getMode() {
|
||||
return mode;
|
||||
public GridFlow getFlow() {
|
||||
return flow;
|
||||
}
|
||||
|
||||
public void setMode(BillingMode _mode) {
|
||||
mode = _mode;
|
||||
public void setFlow(GridFlow _flow) {
|
||||
flow = _flow;
|
||||
}
|
||||
|
||||
public double getRate() {
|
||||
@@ -118,8 +119,8 @@ public class BillingRate {
|
||||
recursAnnually = _recursAnnually;
|
||||
}
|
||||
|
||||
public boolean isApplicable(BillingMode _mode, int _meter, double _monthKWh, Date _time, TimeZone _tz) {
|
||||
if ((mode != BillingMode.ANY_DIRECTION) && (mode != _mode))
|
||||
public boolean isApplicable(GridFlow _mode, int _meter, double _monthKWh, Date _time, TimeZone _tz) {
|
||||
if ((flow != GridFlow.BOTH) && (flow != _mode))
|
||||
return false;
|
||||
if ((meter != -1) && (_meter != meter))
|
||||
return false;
|
||||
@@ -160,11 +161,24 @@ public class BillingRate {
|
||||
return rate * _kWh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
BillingRate that = (BillingRate) _o;
|
||||
return meter == that.meter && dayBillingCycleStart == that.dayBillingCycleStart && Double.compare(that.rate, rate) == 0 && timeOfDayStart == that.timeOfDayStart && timeOfDayEnd == that.timeOfDayEnd && Double.compare(that.monthKWhStart, monthKWhStart) == 0 && Double.compare(that.monthKWhEnd, monthKWhEnd) == 0 && recursAnnually == that.recursAnnually && flow == that.flow && currency == that.currency && Objects.equals(beginEffective, that.beginEffective) && Objects.equals(endEffective, that.endEffective);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(meter, dayBillingCycleStart, flow, rate, currency, timeOfDayStart, timeOfDayEnd, monthKWhStart, monthKWhEnd, beginEffective, endEffective, recursAnnually);
|
||||
}
|
||||
|
||||
public BillingRate duplicate() {
|
||||
BillingRate r = new BillingRate();
|
||||
r.setMeter(meter);
|
||||
r.setDayBillingCycleStart(dayBillingCycleStart);
|
||||
r.setMode(mode);
|
||||
r.setFlow(flow);
|
||||
r.setRate(rate);
|
||||
r.setCurrency(currency);
|
||||
r.setTimeOfDayStart(timeOfDayStart);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.IIdentical;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable()
|
||||
public class Breaker {
|
||||
public class Breaker implements IIdentical<Breaker> {
|
||||
private static final int TANDEM_BREAKER_MASK = 3072;
|
||||
private static final int SPACE_MASK = 1023;
|
||||
private static final int TANDEM_BREAKER_A_MASK = 1024;
|
||||
@@ -137,7 +140,7 @@ public class Breaker {
|
||||
}
|
||||
|
||||
public double getLowPassFilter() {
|
||||
return Math.abs(lowPassFilter) < 0.05 ? 1.6: lowPassFilter;
|
||||
return Math.abs(lowPassFilter) < 0.05 ? 1.6 : lowPassFilter;
|
||||
}
|
||||
|
||||
public void setLowPassFilter(double _lowPassFilter) {
|
||||
@@ -161,7 +164,7 @@ public class Breaker {
|
||||
}
|
||||
|
||||
public double getCalibrationFactor() {
|
||||
return calibrationFactor == 0.0?1.0:calibrationFactor;
|
||||
return calibrationFactor == 0.0 ? 1.0 : calibrationFactor;
|
||||
}
|
||||
|
||||
public void setCalibrationFactor(double _calibrationFactor) {
|
||||
@@ -196,15 +199,15 @@ public class Breaker {
|
||||
}
|
||||
|
||||
public static int portToChip(int _port) {
|
||||
return (_port < 9)?1:0;
|
||||
return (_port < 9) ? 1 : 0;
|
||||
}
|
||||
|
||||
public static int portToPin(int _port) {
|
||||
return (_port < 9)?_port-1:_port-8;
|
||||
return (_port < 9) ? _port - 1 : _port - 8;
|
||||
}
|
||||
|
||||
public static int toPort(int _chip, int _pin) {
|
||||
return (_chip == 0)?_pin+8:_pin+1;
|
||||
return (_chip == 0) ? _pin + 8 : _pin + 1;
|
||||
}
|
||||
|
||||
public static boolean isTandemBreakerA(int _space) {
|
||||
@@ -224,7 +227,7 @@ public class Breaker {
|
||||
}
|
||||
|
||||
public static int toSpace(int _id) {
|
||||
return _id & (TANDEM_BREAKER_MASK |SPACE_MASK);
|
||||
return _id & (TANDEM_BREAKER_MASK | SPACE_MASK);
|
||||
}
|
||||
|
||||
public static String toSpaceDisplay(int _space) {
|
||||
@@ -238,4 +241,23 @@ public class Breaker {
|
||||
public int getSpaceIndex() {
|
||||
return space & SPACE_MASK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
Breaker breaker = (Breaker) _o;
|
||||
return panel == breaker.panel && space == breaker.space;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentical(Breaker _o) {
|
||||
if (this == _o) return true;
|
||||
return panel == _o.panel && space == _o.space && meter == _o.meter && hub == _o.hub && port == _o.port && sizeAmps == _o.sizeAmps && Double.compare(_o.calibrationFactor, calibrationFactor) == 0 && Double.compare(_o.lowPassFilter, lowPassFilter) == 0 && doublePower == _o.doublePower && Objects.equals(name, _o.name) && Objects.equals(description, _o.description) && polarity == _o.polarity && type == _o.type && Objects.equals(key, _o.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(panel, space);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.IIdentical;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
@@ -8,9 +9,10 @@ import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerConfig {
|
||||
public class BreakerConfig implements IIdentical<BreakerConfig> {
|
||||
@PrimaryKey
|
||||
private int accountId;
|
||||
private List<Meter> meters;
|
||||
@@ -182,4 +184,23 @@ public class BreakerConfig {
|
||||
public BillingCurrency getCurrency() {
|
||||
return CollectionUtils.getFirst(CollectionUtils.transformToSet(billingRates, BillingRate::getCurrency));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
BreakerConfig that = (BreakerConfig) _o;
|
||||
return accountId == that.accountId && CollectionUtils.isEqual(meters, that.meters) && CollectionUtils.isEqual(panels, that.panels) && CollectionUtils.isEqual(breakerHubs, that.breakerHubs) && CollectionUtils.isEqual(breakerGroups, that.breakerGroups) && CollectionUtils.isEqual(billingRates, that.billingRates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentical(BreakerConfig _o) {
|
||||
if (this == _o) return true;
|
||||
return accountId == _o.accountId && CollectionUtils.isIdentical(meters, _o.meters) && CollectionUtils.isIdentical(panels, _o.panels) && CollectionUtils.isIdentical(breakerHubs, _o.breakerHubs) && CollectionUtils.isIdentical(breakerGroups, _o.breakerGroups) && CollectionUtils.isEqual(billingRates, _o.billingRates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(accountId, meters, panels, breakerHubs, breakerGroups, billingRates, version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,18 @@ package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.IIdentical;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@DBSerializable()
|
||||
public class BreakerGroup {
|
||||
public class BreakerGroup implements IIdentical<BreakerGroup> {
|
||||
@PrimaryKey private String id;
|
||||
private int accountId;
|
||||
private String name;
|
||||
@@ -186,6 +186,15 @@ public class BreakerGroup {
|
||||
return Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentical(BreakerGroup _o) {
|
||||
if (this == _o)
|
||||
return true;
|
||||
if (_o == null)
|
||||
return false;
|
||||
return NullUtils.isEqual(id, _o.id) && accountId == _o.accountId && NullUtils.isEqual(name, _o.name) && CollectionUtils.isIdentical(subGroups, _o.subGroups) && CollectionUtils.isIdentical(breakers, _o.breakers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
|
||||
@@ -96,8 +96,8 @@ public class BreakerGroupEnergy {
|
||||
double secondFromGrid;
|
||||
for (Map.Entry<MeterMinute, MeterMinuteValues> meter : meters.entrySet()) {
|
||||
double monthkWh = monthFromGrid/3600000;
|
||||
List<BillingRate> consumptionRates = CollectionUtils.filter(_rates, _r->_r.isApplicable(BillingMode.CONSUMPTION, meter.getKey().meter, monthkWh, meter.getKey().minute, timezone));
|
||||
List<BillingRate> productionRates = CollectionUtils.filter(_rates, _r->_r.isApplicable(BillingMode.PRODUCTION, meter.getKey().meter, monthkWh, meter.getKey().minute, timezone));
|
||||
List<BillingRate> consumptionRates = CollectionUtils.filter(_rates, _r->_r.isApplicable(GridFlow.FROM, meter.getKey().meter, monthkWh, meter.getKey().minute, timezone));
|
||||
List<BillingRate> productionRates = CollectionUtils.filter(_rates, _r->_r.isApplicable(GridFlow.TO, meter.getKey().meter, monthkWh, meter.getKey().minute, timezone));
|
||||
for (int i = 0; i < 60; i++) {
|
||||
secondFromGrid = meter.getValue().usage[i] - meter.getValue().solar[i];
|
||||
monthFromGrid += secondFromGrid;
|
||||
@@ -351,7 +351,7 @@ public class BreakerGroupEnergy {
|
||||
return charge(_selectedBreakers, true);
|
||||
}
|
||||
|
||||
public double charge(Set<String> _selectedBreakers, BillingMode _mode) {
|
||||
public double charge(Set<String> _selectedBreakers, GridFlow _mode) {
|
||||
return charge(_selectedBreakers, true, _mode);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ public class BreakerGroupEnergy {
|
||||
return charge(_selectedBreakers, _includeSubgroups, null);
|
||||
}
|
||||
|
||||
public double charge(Set<String> _selectedBreakers, boolean _includeSubgroups, BillingMode _mode) {
|
||||
public double charge(Set<String> _selectedBreakers, boolean _includeSubgroups, GridFlow _mode) {
|
||||
double charge = 0.0;
|
||||
if (_includeSubgroups) {
|
||||
for (BreakerGroupEnergy group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
@@ -368,7 +368,7 @@ public class BreakerGroupEnergy {
|
||||
}
|
||||
if ((energyBlocks != null) && ((_selectedBreakers == null) || _selectedBreakers.contains(getGroupId()))) {
|
||||
for (EnergyBlock energy : energyBlocks) {
|
||||
if ((_mode == null) || ((_mode == BillingMode.PRODUCTION) && energy.getCharge() < 0.0) || (_mode == BillingMode.CONSUMPTION && energy.getCharge() > 0.0))
|
||||
if ((_mode == null) || ((_mode == GridFlow.TO) && energy.getCharge() < 0.0) || (_mode == GridFlow.FROM && energy.getCharge() > 0.0))
|
||||
charge += energy.getCharge();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.IIdentical;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable
|
||||
public class BreakerHub {
|
||||
public class BreakerHub implements IIdentical<BreakerHub> {
|
||||
private int hub;
|
||||
private double voltageCalibrationFactor;
|
||||
private double portCalibrationFactor;
|
||||
@@ -50,4 +53,23 @@ public class BreakerHub {
|
||||
public void setBluetoothMac(String _bluetoothMac) {
|
||||
bluetoothMac = _bluetoothMac;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
BreakerHub that = (BreakerHub) _o;
|
||||
return hub == that.hub;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentical(BreakerHub _o) {
|
||||
if (this == _o) return true;
|
||||
return hub == _o.hub && Double.compare(_o.voltageCalibrationFactor, voltageCalibrationFactor) == 0 && Double.compare(_o.portCalibrationFactor, portCalibrationFactor) == 0 && frequency == _o.frequency && Objects.equals(bluetoothMac, _o.bluetoothMac);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(hub);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.IIdentical;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable
|
||||
public class BreakerPanel {
|
||||
public class BreakerPanel implements IIdentical<BreakerPanel> {
|
||||
private int accountId;
|
||||
private String name;
|
||||
private int index;
|
||||
@@ -49,4 +52,23 @@ public class BreakerPanel {
|
||||
public void setMeter(int _meter) {
|
||||
meter = _meter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
BreakerPanel that = (BreakerPanel) _o;
|
||||
return accountId == that.accountId && index == that.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentical(BreakerPanel _o) {
|
||||
if (this == _o) return true;
|
||||
return accountId == _o.accountId && index == _o.index && spaces == _o.spaces && meter == _o.meter && Objects.equals(name, _o.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(accountId, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
public enum GridFlow {
|
||||
BOTH,
|
||||
FROM,
|
||||
TO;
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.IIdentical;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable
|
||||
public class Meter {
|
||||
public class Meter implements IIdentical<Meter> {
|
||||
private int accountId;
|
||||
private int index;
|
||||
private String name;
|
||||
@@ -31,4 +34,24 @@ public class Meter {
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
Meter meter = (Meter) _o;
|
||||
return accountId == meter.accountId && index == meter.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentical(Meter _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null) return false;
|
||||
return accountId == _o.accountId && index == _o.index && Objects.equals(name, _o.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(accountId, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BillingCurrency;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BillingMode;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.GridFlow;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BillingRate;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
@@ -29,7 +29,7 @@ public class BillingRateSerializer extends AbstractDaoSerializer<BillingRate>
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("meter", _o.getMeter());
|
||||
d.put("day_billing_cycle_start", _o.getDayBillingCycleStart());
|
||||
d.put("mode", DaoSerializer.toEnumName(_o.getMode()));
|
||||
d.put("flow", DaoSerializer.toEnumName(_o.getFlow()));
|
||||
d.put("rate", _o.getRate());
|
||||
d.put("unit", DaoSerializer.toEnumName(_o.getCurrency()));
|
||||
d.put("time_of_day_start", _o.getTimeOfDayStart());
|
||||
@@ -48,7 +48,7 @@ public class BillingRateSerializer extends AbstractDaoSerializer<BillingRate>
|
||||
BillingRate o = new BillingRate();
|
||||
o.setMeter(DaoSerializer.getInteger(_d, "meter"));
|
||||
o.setDayBillingCycleStart(DaoSerializer.getInteger(_d, "day_billing_cycle_start"));
|
||||
o.setMode(DaoSerializer.getEnum(_d, "mode", BillingMode.class));
|
||||
o.setFlow(DaoSerializer.getEnum(_d, "flow", GridFlow.class, GridFlow.BOTH));
|
||||
o.setRate(DaoSerializer.getDouble(_d, "rate"));
|
||||
o.setCurrency(DaoSerializer.getEnum(_d, "unit", BillingCurrency.class));
|
||||
o.setTimeOfDayStart(DaoSerializer.getInteger(_d, "time_of_day_start"));
|
||||
|
||||
Reference in New Issue
Block a user