mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Initial Commit
This commit is contained in:
73
currentmonitor/lantern-datamodel-currentmonitor/pom.xml
Normal file
73
currentmonitor/lantern-datamodel-currentmonitor/pom.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-datamodel-currentmonitor</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-datamodel-currentmonitor</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
<phase>compile</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<index>true</index>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class Account {
|
||||
@PrimaryKey private int id;
|
||||
private String username;
|
||||
private String password;
|
||||
private List<Integer> auxiliaryAccountIds;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int _id) {
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String _username) {
|
||||
username = _username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String _password) {
|
||||
password = _password;
|
||||
}
|
||||
|
||||
public List<Integer> getAuxiliaryAccountIds() {
|
||||
return auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public void setAuxiliaryAccountIds(List<Integer> _auxiliaryAccountIds) {
|
||||
auxiliaryAccountIds = _auxiliaryAccountIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class AuthCode {
|
||||
private int accountId;
|
||||
private List<Integer> auxiliaryAccountIds;
|
||||
|
||||
public AuthCode() {
|
||||
}
|
||||
|
||||
public AuthCode(int _accountId, List<Integer> _auxiliaryAccountIds) {
|
||||
accountId = _accountId;
|
||||
auxiliaryAccountIds = _auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public List<Integer> getAuxiliaryAccountIds() {
|
||||
return auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public void setAuxiliaryAccountIds(List<Integer> _auxiliaryAccountIds) {
|
||||
auxiliaryAccountIds = _auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public List<Integer> getAllAccountIds() {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
ids.add(accountId);
|
||||
if (auxiliaryAccountIds != null)
|
||||
ids.addAll(auxiliaryAccountIds);
|
||||
return ids;
|
||||
}
|
||||
|
||||
public boolean isAuthorized(int _accountId) {
|
||||
return accountId == _accountId || CollectionUtils.contains(auxiliaryAccountIds, _accountId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable()
|
||||
public class 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;
|
||||
private static final int TANDEM_BREAKER_B_MASK = 2048;
|
||||
|
||||
private int panel;
|
||||
private int space;
|
||||
private int meter;
|
||||
private int hub;
|
||||
private int port;
|
||||
private String name;
|
||||
private String description;
|
||||
private int sizeAmps;
|
||||
private double calibrationFactor;
|
||||
private double lowPassFilter;
|
||||
private BreakerPolarity polarity;
|
||||
private BreakerType type;
|
||||
private transient String key;
|
||||
|
||||
public Breaker() {
|
||||
}
|
||||
|
||||
public Breaker(String _name, int _panel, int _space, int _hub, int _port, int _sizeAmps, double _lowPassFilter) {
|
||||
name = _name;
|
||||
panel = _panel;
|
||||
space = _space;
|
||||
hub = _hub;
|
||||
port = _port;
|
||||
sizeAmps = _sizeAmps;
|
||||
lowPassFilter = _lowPassFilter;
|
||||
}
|
||||
|
||||
public int getPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void setPanel(int _panel) {
|
||||
panel = _panel;
|
||||
key = null;
|
||||
}
|
||||
|
||||
public int getSpace() {
|
||||
return space;
|
||||
}
|
||||
|
||||
public void setSpace(int _space) {
|
||||
space = _space;
|
||||
key = null;
|
||||
}
|
||||
|
||||
public int getMeter() {
|
||||
return meter;
|
||||
}
|
||||
|
||||
public void setMeter(int _meter) {
|
||||
meter = _meter;
|
||||
}
|
||||
|
||||
public String getSpaceDisplay() {
|
||||
return toSpaceDisplay(space);
|
||||
}
|
||||
|
||||
public void setSpaceTandemA(int _space) {
|
||||
space = TANDEM_BREAKER_A_MASK | _space;
|
||||
}
|
||||
|
||||
public void setSpaceTandemB(int _space) {
|
||||
space = TANDEM_BREAKER_B_MASK | _space;
|
||||
}
|
||||
|
||||
public boolean isTandemBreaker() {
|
||||
return (TANDEM_BREAKER_MASK & space) != 0;
|
||||
}
|
||||
|
||||
public boolean isTandemBreakerA() {
|
||||
return isTandemBreakerA(space);
|
||||
}
|
||||
|
||||
public boolean isTandemBreakerB() {
|
||||
return isTandemBreakerB(space);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String _description) {
|
||||
description = _description;
|
||||
}
|
||||
|
||||
public int getHub() {
|
||||
return hub;
|
||||
}
|
||||
|
||||
public void setHub(int _hub) {
|
||||
hub = _hub;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int _port) {
|
||||
port = _port;
|
||||
}
|
||||
|
||||
public int getChip() {
|
||||
return portToChip(port);
|
||||
}
|
||||
|
||||
public int getPin() {
|
||||
return portToPin(port);
|
||||
}
|
||||
|
||||
public int getSizeAmps() {
|
||||
return sizeAmps;
|
||||
}
|
||||
|
||||
public void setSizeAmps(int _sizeAmps) {
|
||||
sizeAmps = _sizeAmps;
|
||||
}
|
||||
|
||||
public double getLowPassFilter() {
|
||||
return lowPassFilter;
|
||||
}
|
||||
|
||||
public void setLowPassFilter(double _lowPassFilter) {
|
||||
lowPassFilter = _lowPassFilter;
|
||||
}
|
||||
|
||||
public BreakerPolarity getPolarity() {
|
||||
return polarity;
|
||||
}
|
||||
|
||||
public void setPolarity(BreakerPolarity _polarity) {
|
||||
polarity = _polarity;
|
||||
}
|
||||
|
||||
public double getCalibrationFactor() {
|
||||
return calibrationFactor == 0.0?1.0:calibrationFactor;
|
||||
}
|
||||
|
||||
public void setCalibrationFactor(double _calibrationFactor) {
|
||||
calibrationFactor = _calibrationFactor;
|
||||
}
|
||||
|
||||
public BreakerType getType() {
|
||||
if (type == null) {
|
||||
if (isTandemBreaker())
|
||||
return BreakerType.SINGLE_POLE_TANDEM;
|
||||
return BreakerType.SINGLE_POLE;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(BreakerType _type) {
|
||||
type = _type;
|
||||
}
|
||||
|
||||
public double getFinalCalibrationFactor() {
|
||||
return getCalibrationFactor() * getSizeAmps() / 380.0;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
if (key == null)
|
||||
key = key(panel, space);
|
||||
return key;
|
||||
}
|
||||
|
||||
public static String key(int _panel, int _space) {
|
||||
return String.format("%d-%d", _panel, _space);
|
||||
}
|
||||
|
||||
public static int portToChip(int _port) {
|
||||
return (_port < 9)?1:0;
|
||||
}
|
||||
|
||||
public static int portToPin(int _port) {
|
||||
return (_port < 9)?_port-1:_port-8;
|
||||
}
|
||||
|
||||
public static int toPort(int _chip, int _pin) {
|
||||
return (_chip == 0)?_pin+8:_pin+1;
|
||||
}
|
||||
|
||||
public static boolean isTandemBreakerA(int _space) {
|
||||
return (TANDEM_BREAKER_A_MASK & _space) != 0;
|
||||
}
|
||||
|
||||
public static boolean isTandemBreakerB(int _space) {
|
||||
return (TANDEM_BREAKER_B_MASK & _space) != 0;
|
||||
}
|
||||
|
||||
public static int toId(int _panel, int _space) {
|
||||
return (_panel << 12) | _space;
|
||||
}
|
||||
|
||||
public static int toPanel(int _id) {
|
||||
return _id >> 12;
|
||||
}
|
||||
|
||||
public static int toSpace(int _id) {
|
||||
return _id & (TANDEM_BREAKER_MASK |SPACE_MASK);
|
||||
}
|
||||
|
||||
public static String toSpaceDisplay(int _space) {
|
||||
if (isTandemBreakerA(_space))
|
||||
return String.format("%dA", _space & SPACE_MASK);
|
||||
if (isTandemBreakerB(_space))
|
||||
return String.format("%dB", _space & SPACE_MASK);
|
||||
return String.valueOf(_space);
|
||||
}
|
||||
|
||||
public int getSpaceIndex() {
|
||||
return space & SPACE_MASK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
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.List;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerConfig {
|
||||
@PrimaryKey
|
||||
private int accountId;
|
||||
private List<Meter> meters;
|
||||
private List<BreakerPanel> panels;
|
||||
private List<BreakerHub> breakerHubs;
|
||||
private List<BreakerGroup> breakerGroups;
|
||||
|
||||
public BreakerConfig() {
|
||||
}
|
||||
|
||||
public BreakerConfig(List<BreakerGroup> _breakerGroups) {
|
||||
breakerGroups = _breakerGroups;
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public List<Meter> getMeters() {
|
||||
return meters;
|
||||
}
|
||||
|
||||
public void setMeters(List<Meter> _meters) {
|
||||
meters = _meters;
|
||||
}
|
||||
|
||||
public List<BreakerPanel> getPanels() {
|
||||
return panels;
|
||||
}
|
||||
|
||||
public void setPanels(List<BreakerPanel> _panels) {
|
||||
panels = _panels;
|
||||
}
|
||||
|
||||
public List<BreakerHub> getBreakerHubs() {
|
||||
return breakerHubs;
|
||||
}
|
||||
|
||||
public void setBreakerHubs(List<BreakerHub> _breakerHubs) {
|
||||
breakerHubs = _breakerHubs;
|
||||
}
|
||||
|
||||
public List<BreakerGroup> getBreakerGroups() {
|
||||
return breakerGroups;
|
||||
}
|
||||
|
||||
public void setBreakerGroups(List<BreakerGroup> _breakerGroups) {
|
||||
breakerGroups = _breakerGroups;
|
||||
}
|
||||
|
||||
public List<Breaker> getAllBreakers() {
|
||||
List<Breaker> allBreakers = new ArrayList<>();
|
||||
for (BreakerGroup g : CollectionUtils.makeNotNull(breakerGroups)) {
|
||||
allBreakers.addAll(g.getAllBreakers());
|
||||
}
|
||||
return allBreakers;
|
||||
}
|
||||
|
||||
public List<BreakerGroup> getAllBreakerGroups() {
|
||||
List<BreakerGroup> groups = new ArrayList<>();
|
||||
for (BreakerGroup g : CollectionUtils.makeNotNull(breakerGroups)) {
|
||||
groups.addAll(g.getAllBreakerGroups());
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
public List<String> getAllBreakerGroupIds() {
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (BreakerGroup g : CollectionUtils.makeNotNull(breakerGroups)) {
|
||||
ids.addAll(g.getAllBreakerGroupIds());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
public List<Breaker> getBreakersForHub(int _hub) {
|
||||
return CollectionUtils.filter(getAllBreakers(), _b -> _b.getHub() == _hub);
|
||||
}
|
||||
|
||||
public BreakerHub getHub(int _hub) {
|
||||
return CollectionUtils.filterOne(breakerHubs, _h->_h.getHub() == _hub);
|
||||
}
|
||||
|
||||
public boolean isSolarConfigured() {
|
||||
return CollectionUtils.anyQualify(getAllBreakers(), _b->_b.getPolarity() == BreakerPolarity.SOLAR);
|
||||
}
|
||||
|
||||
public String nextGroupId() {
|
||||
List<Integer> ids = CollectionUtils.transform(getAllBreakerGroupIds(), NullUtils::toInteger);
|
||||
return String.valueOf(CollectionUtils.getLargest(ids) + 1);
|
||||
}
|
||||
|
||||
public void addGroup(BreakerGroup _group) {
|
||||
if (NullUtils.isEmpty(_group.getId())) {
|
||||
_group.setId(nextGroupId());
|
||||
}
|
||||
if (breakerGroups == null)
|
||||
breakerGroups = new ArrayList<>();
|
||||
breakerGroups.add(_group);
|
||||
}
|
||||
|
||||
public void removeInvalidGroups() {
|
||||
if (breakerGroups != null)
|
||||
breakerGroups.removeIf(_g->!_g.removeInvalidGroups());
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(Breaker _breaker) {
|
||||
return getGroupIdForBreaker(_breaker.getKey());
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(int _panel, int _space) {
|
||||
return getGroupIdForBreaker(Breaker.key(_panel, _space));
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(String _breakerKey) {
|
||||
BreakerGroup group = getGroupForBreaker(_breakerKey);
|
||||
return group != null ? group.getId() : null;
|
||||
}
|
||||
|
||||
public BreakerGroup getGroupForBreaker(Breaker _breaker) {
|
||||
return getGroupForBreaker(_breaker.getKey());
|
||||
}
|
||||
|
||||
public BreakerGroup getGroupForBreaker(int _panel, int _space) {
|
||||
return getGroupForBreaker(Breaker.key(_panel, _space));
|
||||
}
|
||||
|
||||
public BreakerGroup getGroupForBreaker(String _breakerKey) {
|
||||
if (_breakerKey == null)
|
||||
return null;
|
||||
for (BreakerGroup subGroup : CollectionUtils.makeNotNull(breakerGroups)) {
|
||||
BreakerGroup group = subGroup.getGroupForBreaker(_breakerKey);
|
||||
if (group != null)
|
||||
return group;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BreakerGroup findParentGroup(BreakerGroup _group) {
|
||||
for (BreakerGroup group : CollectionUtils.makeNotNull(breakerGroups)) {
|
||||
BreakerGroup parent = group.findParentGroup(_group);
|
||||
if (parent != null)
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
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;
|
||||
|
||||
@DBSerializable()
|
||||
public class BreakerGroup {
|
||||
@PrimaryKey private String id;
|
||||
private int accountId;
|
||||
private String name;
|
||||
private List<BreakerGroup> subGroups;
|
||||
private List<Breaker> breakers;
|
||||
|
||||
public BreakerGroup() {
|
||||
}
|
||||
|
||||
public BreakerGroup(String _id, String _name, List<Breaker> _breakers) {
|
||||
id = _id;
|
||||
name = _name;
|
||||
breakers = _breakers;
|
||||
}
|
||||
|
||||
public BreakerGroup(String _id, String _name, List<BreakerGroup> _subGroups, List<Breaker> _breakers) {
|
||||
id = _id;
|
||||
name = _name;
|
||||
subGroups = _subGroups;
|
||||
breakers = _breakers;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String _id) {
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
|
||||
public List<BreakerGroup> getSubGroups() {
|
||||
return subGroups;
|
||||
}
|
||||
|
||||
public void setSubGroups(List<BreakerGroup> _subGroups) {
|
||||
subGroups = _subGroups;
|
||||
}
|
||||
|
||||
public List<Breaker> getBreakers() {
|
||||
return breakers;
|
||||
}
|
||||
|
||||
public void setBreakers(List<Breaker> _breakers) {
|
||||
breakers = _breakers;
|
||||
}
|
||||
|
||||
public List<Breaker> getAllBreakers() {
|
||||
List<Breaker> allBreakers = new ArrayList<>();
|
||||
getAllBreakers(allBreakers);
|
||||
return allBreakers;
|
||||
}
|
||||
|
||||
private void getAllBreakers(List<Breaker> _breakers) {
|
||||
if (breakers != null)
|
||||
_breakers.addAll(breakers);
|
||||
for (BreakerGroup group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
group.getAllBreakers(_breakers);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getAllBreakerKeys() {
|
||||
return CollectionUtils.transform(getAllBreakers(), Breaker::getKey);
|
||||
}
|
||||
|
||||
public List<BreakerGroup> getAllBreakerGroups() {
|
||||
List<BreakerGroup> allGroups = new ArrayList<>();
|
||||
getAllBreakerGroups(allGroups);
|
||||
return allGroups;
|
||||
}
|
||||
|
||||
private void getAllBreakerGroups(List<BreakerGroup> _groups) {
|
||||
_groups.add(this);
|
||||
for (BreakerGroup group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
group.getAllBreakerGroups(_groups);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getAllBreakerGroupIds() {
|
||||
return CollectionUtils.transform(getAllBreakerGroups(), BreakerGroup::getId);
|
||||
}
|
||||
|
||||
public Breaker getBreaker(String _breakerKey) {
|
||||
for (Breaker b : CollectionUtils.makeNotNull(breakers)) {
|
||||
if (NullUtils.isEqual(b.getKey(), _breakerKey))
|
||||
return b;
|
||||
}
|
||||
for (BreakerGroup group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
Breaker b = group.getBreaker(_breakerKey);
|
||||
if (b != null)
|
||||
return b;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(Breaker _breaker) {
|
||||
return getGroupIdForBreaker(_breaker.getKey());
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(int _panel, int _space) {
|
||||
return getGroupIdForBreaker(Breaker.key(_panel, _space));
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(String _breakerKey) {
|
||||
BreakerGroup group = getGroupForBreaker(_breakerKey);
|
||||
return group != null ? group.getId() : null;
|
||||
}
|
||||
|
||||
public BreakerGroup getGroupForBreaker(Breaker _breaker) {
|
||||
return getGroupForBreaker(_breaker.getKey());
|
||||
}
|
||||
|
||||
public BreakerGroup getGroupForBreaker(int _panel, int _space) {
|
||||
return getGroupForBreaker(Breaker.key(_panel, _space));
|
||||
}
|
||||
|
||||
public BreakerGroup getGroupForBreaker(String _breakerKey) {
|
||||
if (_breakerKey == null)
|
||||
return null;
|
||||
Breaker b = CollectionUtils.filterOne(breakers, _b->_breakerKey.equals(_b.getKey()));
|
||||
if (b != null)
|
||||
return this;
|
||||
for (BreakerGroup subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
||||
BreakerGroup group = subGroup.getGroupForBreaker(_breakerKey);
|
||||
if (group != null)
|
||||
return group;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BreakerGroup findParentGroup(BreakerGroup _group) {
|
||||
if (CollectionUtils.contains(subGroups, _group))
|
||||
return this;
|
||||
for (BreakerGroup subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
||||
BreakerGroup parent = subGroup.findParentGroup(_group);
|
||||
if (parent != null)
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean removeInvalidGroups() {
|
||||
if (subGroups != null)
|
||||
subGroups.removeIf(_g->!_g.removeInvalidGroups());
|
||||
if (breakers != null)
|
||||
breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.getPort() < 1));
|
||||
return CollectionUtils.isNotEmpty(subGroups) || CollectionUtils.isNotEmpty(breakers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
BreakerGroup that = (BreakerGroup) _o;
|
||||
return Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerGroupEnergy {
|
||||
private int accountId;
|
||||
private String groupId;
|
||||
private String groupName;
|
||||
private EnergyBlockViewMode viewMode;
|
||||
private Date start;
|
||||
private List<BreakerGroupEnergy> subGroups;
|
||||
private List<EnergyBlock> energyBlocks;
|
||||
private double toGrid;
|
||||
private double fromGrid;
|
||||
|
||||
public BreakerGroupEnergy() {
|
||||
}
|
||||
|
||||
public BreakerGroupEnergy(BreakerGroup _group, Map<String, List<BreakerPower>> _powerReadings, EnergyBlockViewMode _viewMode, Date _start, TimeZone _tz) {
|
||||
groupId = _group.getId();
|
||||
groupName = _group.getName();
|
||||
viewMode = _viewMode;
|
||||
start = _start;
|
||||
accountId = _group.getAccountId();
|
||||
subGroups = CollectionUtils.transform(_group.getSubGroups(), _g -> new BreakerGroupEnergy(_g, _powerReadings, _viewMode, _start, _tz));
|
||||
energyBlocks = new ArrayList<>();
|
||||
List<String> breakerKeys = CollectionUtils.transform(_group.getBreakers(), Breaker::getKey);
|
||||
if (!breakerKeys.isEmpty()) {
|
||||
for (BreakerPower power : CollectionUtils.aggregate(breakerKeys, _powerReadings::get)) {
|
||||
addEnergy(groupId, power.getReadTime(), power.getPower(), _tz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BreakerGroupEnergy(BreakerGroup _group, List<HubPowerMinute> _power, EnergyBlockViewMode _viewMode, Date _start, TimeZone _tz) {
|
||||
groupId = _group.getId();
|
||||
groupName = _group.getName();
|
||||
viewMode = _viewMode;
|
||||
start = _start;
|
||||
accountId = _group.getAccountId();
|
||||
subGroups = CollectionUtils.transform(_group.getSubGroups(), _g -> new BreakerGroupEnergy(_g, (List<HubPowerMinute>)null, _viewMode, _start, _tz));
|
||||
energyBlocks = new ArrayList<>();
|
||||
addEnergy(_group, _power, _tz);
|
||||
}
|
||||
|
||||
public void addEnergy(BreakerGroup _group, List<HubPowerMinute> _hubPower, TimeZone _tz) {
|
||||
Map<String, Breaker> breakers = CollectionUtils.transformToMap(_group.getAllBreakers(), Breaker::getKey);
|
||||
Map<String, BreakerGroup> breakerKeyToGroup = new HashMap<>();
|
||||
for (BreakerGroup group : _group.getAllBreakerGroups()) {
|
||||
for (Breaker b : group.getAllBreakers()) {
|
||||
breakerKeyToGroup.put(b.getKey(), group);
|
||||
}
|
||||
}
|
||||
addEnergy(breakers, breakerKeyToGroup, _hubPower, _tz);
|
||||
}
|
||||
|
||||
public void addEnergy(Map<String, Breaker> _breakers, Map<String, BreakerGroup> _breakerKeyToGroup, List<HubPowerMinute> _hubPower, TimeZone _tz) {
|
||||
if (CollectionUtils.isEmpty(_hubPower) || CollectionUtils.anyQualify(_hubPower, _p->_p.getAccountId() != accountId))
|
||||
return;
|
||||
Date minute = CollectionUtils.getFirst(_hubPower).getMinuteAsDate();
|
||||
resetEnergy(minute, _tz);
|
||||
Map<Integer, MeterMinute> meters = new HashMap<>();
|
||||
for (HubPowerMinute hubPower : _hubPower) {
|
||||
for (BreakerPowerMinute breaker : CollectionUtils.makeNotNull(hubPower.getBreakers())) {
|
||||
Breaker b = _breakers.get(breaker.breakerKey());
|
||||
if (b == null)
|
||||
continue;
|
||||
BreakerGroup group = _breakerKeyToGroup.get(breaker.breakerKey());
|
||||
if (group == null)
|
||||
continue;
|
||||
MeterMinute meter = meters.computeIfAbsent(b.getMeter(), _p->new MeterMinute());
|
||||
int idx = 0;
|
||||
for (Float power : CollectionUtils.makeNotNull(breaker.getReadings())) {
|
||||
if (power > 0)
|
||||
meter.usage[idx] += power;
|
||||
else
|
||||
meter.solar[idx] += -power;
|
||||
if (power != 0.0)
|
||||
addEnergy(group.getId(), minute, power, _tz);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MeterMinute meter : meters.values()) {
|
||||
for (int i = 0; i < 60; i++) {
|
||||
if (meter.usage[i] > meter.solar[i])
|
||||
fromGrid += meter.usage[i] - meter.solar[i];
|
||||
else
|
||||
toGrid += meter.solar[i] - meter.usage[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetEnergy(Date _readTime, TimeZone _tz) {
|
||||
EnergyBlock block = getBlock(_readTime, _tz, false);
|
||||
if (block != null)
|
||||
block.setJoules(0);
|
||||
for (BreakerGroupEnergy subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
||||
subGroup.resetEnergy(_readTime, _tz);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEnergy(String _groupId, Date _readTime, double _joules, TimeZone _tz) {
|
||||
if (NullUtils.isEqual(groupId, _groupId))
|
||||
getBlock(_readTime, _tz).addJoules(_joules);
|
||||
else {
|
||||
for (BreakerGroupEnergy subGroup : CollectionUtils.makeNotNull(subGroups)) {
|
||||
subGroup.addEnergy(_groupId, _readTime, _joules, _tz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BreakerGroupEnergy summary(BreakerGroup _group, Map<String, List<BreakerGroupSummary>> _energies, EnergyBlockViewMode _viewMode, Date _start, TimeZone _tz) {
|
||||
BreakerGroupEnergy energy = new BreakerGroupEnergy();
|
||||
energy.setGroupId(_group.getId());
|
||||
energy.setGroupName(_group.getName());
|
||||
energy.setAccountId(_group.getAccountId());
|
||||
energy.setViewMode(_viewMode);
|
||||
energy.setStart(_start);
|
||||
energy.setSubGroups(CollectionUtils.transform(_group.getSubGroups(), _g -> BreakerGroupEnergy.summary(_g, _energies, _viewMode, _start, _tz)));
|
||||
for (BreakerGroupSummary curEnergy : CollectionUtils.makeNotNull(_energies.get(_group.getId()))) {
|
||||
EnergyBlock block = energy.getBlock(curEnergy.getStart(), _tz);
|
||||
block.addJoules(curEnergy.getJoules());
|
||||
energy.setToGrid(energy.getToGrid()+curEnergy.getToGrid());
|
||||
energy.setFromGrid(energy.getFromGrid()+curEnergy.getFromGrid());
|
||||
}
|
||||
return energy;
|
||||
}
|
||||
|
||||
private EnergyBlock getBlock(Date _readTime, TimeZone _tz) {
|
||||
return getBlock(_readTime, _tz, true);
|
||||
}
|
||||
|
||||
private EnergyBlock getBlock(Date _readTime, TimeZone _tz, boolean _add) {
|
||||
int size = CollectionUtils.size(energyBlocks);
|
||||
int idx = viewMode.blockIndex(_readTime, _tz);
|
||||
if (_add && (idx >= size)) {
|
||||
if (energyBlocks == null)
|
||||
energyBlocks = new ArrayList<>();
|
||||
LinkedList<EnergyBlock> newBlocks = new LinkedList<>();
|
||||
Date end = viewMode.toBlockEnd(_readTime, _tz);
|
||||
while (idx >= size) {
|
||||
Date start = viewMode.decrementBlock(end, _tz);
|
||||
newBlocks.add(new EnergyBlock(start, end, 0));
|
||||
end = start;
|
||||
size++;
|
||||
}
|
||||
Iterator<EnergyBlock> iter = newBlocks.descendingIterator();
|
||||
while (iter.hasNext()) {
|
||||
energyBlocks.add(iter.next());
|
||||
}
|
||||
}
|
||||
return CollectionUtils.get(energyBlocks, idx);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return toId(accountId, groupId, viewMode, start);
|
||||
}
|
||||
|
||||
public static String toId(int _accountId, String _groupId, EnergyBlockViewMode _viewMode, Date _start) {
|
||||
return _accountId + "-" + _groupId + "-" + DaoSerializer.toEnumName(_viewMode) + "-" + _start.getTime();
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String _groupId) {
|
||||
groupId = _groupId;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String _groupName) {
|
||||
groupName = _groupName;
|
||||
}
|
||||
|
||||
public BreakerGroupEnergy getSubGroup(String _groupId) {
|
||||
return CollectionUtils.filterOne(subGroups, _g->_groupId.equals(_g.getGroupId()));
|
||||
}
|
||||
|
||||
public List<BreakerGroupEnergy> getSubGroups() {
|
||||
return subGroups;
|
||||
}
|
||||
|
||||
public EnergyBlockViewMode getViewMode() {
|
||||
return viewMode;
|
||||
}
|
||||
|
||||
public void setViewMode(EnergyBlockViewMode _viewMode) {
|
||||
viewMode = _viewMode;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Date _start) {
|
||||
start = _start;
|
||||
}
|
||||
|
||||
public void setSubGroups(List<BreakerGroupEnergy> _subGroups) {
|
||||
subGroups = _subGroups;
|
||||
}
|
||||
|
||||
public List<EnergyBlock> getEnergyBlocks() {
|
||||
return energyBlocks;
|
||||
}
|
||||
|
||||
public void setEnergyBlocks(List<EnergyBlock> _energyBlocks) {
|
||||
energyBlocks = _energyBlocks;
|
||||
}
|
||||
|
||||
public double getToGrid() {
|
||||
return toGrid;
|
||||
}
|
||||
|
||||
public void setToGrid(double _toGrid) {
|
||||
toGrid = _toGrid;
|
||||
}
|
||||
|
||||
public double getFromGrid() {
|
||||
return fromGrid;
|
||||
}
|
||||
|
||||
public void setFromGrid(double _fromGrid) {
|
||||
fromGrid = _fromGrid;
|
||||
}
|
||||
|
||||
public double wattHours() {
|
||||
return joules() / 3600;
|
||||
}
|
||||
|
||||
public double wattHours(Set<String> _selectedBreakers) {
|
||||
return joules(_selectedBreakers) / 3600;
|
||||
}
|
||||
|
||||
public double joules() {
|
||||
return joules(null);
|
||||
}
|
||||
|
||||
public double joules(Set<String> _selectedBreakers) {
|
||||
return joules(_selectedBreakers, true);
|
||||
}
|
||||
|
||||
public double joules(Set<String> _selectedBreakers, boolean _includeSubgroups) {
|
||||
double joules = 0.0;
|
||||
if (_includeSubgroups) {
|
||||
for (BreakerGroupEnergy group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
joules += group.joules(_selectedBreakers);
|
||||
}
|
||||
}
|
||||
if ((energyBlocks != null) && ((_selectedBreakers == null) || _selectedBreakers.contains(getGroupId()))) {
|
||||
for (EnergyBlock energy : energyBlocks) {
|
||||
joules += energy.getJoules();
|
||||
}
|
||||
}
|
||||
return joules;
|
||||
}
|
||||
|
||||
public List<BreakerGroupEnergy> getAllGroups() {
|
||||
Map<String, BreakerGroupEnergy> groups = new TreeMap<>();
|
||||
getAllGroups(groups);
|
||||
return new ArrayList<>(groups.values());
|
||||
}
|
||||
|
||||
public void getAllGroups(Map<String, BreakerGroupEnergy> _groups) {
|
||||
_groups.put(getGroupId(), this);
|
||||
for (BreakerGroupEnergy group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
group.getAllGroups(_groups);
|
||||
}
|
||||
}
|
||||
|
||||
public List<EnergyBlock> getAllEnergyBlocks() {
|
||||
return getAllEnergyBlocks(null);
|
||||
}
|
||||
|
||||
public List<EnergyBlock> getAllEnergyBlocks(Set<String> _selectedGroups) {
|
||||
return getAllEnergyBlocks(_selectedGroups, EnergyBlockType.ANY);
|
||||
}
|
||||
|
||||
public List<EnergyBlock> getAllEnergyBlocks(Set<String> _selectedGroups, EnergyBlockType _type) {
|
||||
Map<Long, EnergyBlock> blocks = new TreeMap<>();
|
||||
getAllEnergyBlocks(_selectedGroups, blocks, _type);
|
||||
return new ArrayList<>(blocks.values());
|
||||
}
|
||||
|
||||
private void getAllEnergyBlocks(Set<String> _selectedGroups, Map<Long, EnergyBlock> _energyBlocks, EnergyBlockType _type) {
|
||||
if ((energyBlocks != null) && ((_selectedGroups == null) || _selectedGroups.contains(getGroupId()))) {
|
||||
for (EnergyBlock block : energyBlocks) {
|
||||
if ((_type == EnergyBlockType.ANY) || ((_type == EnergyBlockType.POSITIVE) && block.getJoules() >= 0.0) || ((_type == EnergyBlockType.NEGATIVE) && block.getJoules() <= 0.0)) {
|
||||
EnergyBlock b = _energyBlocks.get(block.getStart().getTime());
|
||||
if (b == null) {
|
||||
b = new EnergyBlock(block.getStart(), block.getEnd(), block.getJoules());
|
||||
_energyBlocks.put(block.getStart().getTime(), b);
|
||||
} else
|
||||
b.addJoules(block.getJoules());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (BreakerGroupEnergy group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
group.getAllEnergyBlocks(_selectedGroups, _energyBlocks, _type);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MeterMinute {
|
||||
public double[] usage = new double[60];
|
||||
public double[] solar = new double[60];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerGroupSummary {
|
||||
private int accountId;
|
||||
private String groupId;
|
||||
private String groupName;
|
||||
private EnergyBlockViewMode viewMode;
|
||||
private Date start;
|
||||
private List<BreakerGroupSummary> subGroups;
|
||||
private double joules;
|
||||
private double toGrid;
|
||||
private double fromGrid;
|
||||
|
||||
public BreakerGroupSummary() {
|
||||
}
|
||||
|
||||
public BreakerGroupSummary(BreakerGroupEnergy _energy) {
|
||||
accountId = _energy.getAccountId();
|
||||
groupId = _energy.getGroupId();
|
||||
groupName = _energy.getGroupName();
|
||||
viewMode = _energy.getViewMode();
|
||||
start = _energy.getStart();
|
||||
subGroups = CollectionUtils.transform(_energy.getSubGroups(), BreakerGroupSummary::new);
|
||||
joules = _energy.joules(null, false);
|
||||
toGrid = _energy.getToGrid();
|
||||
fromGrid = _energy.getFromGrid();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return toId(accountId, groupId, viewMode, start);
|
||||
}
|
||||
|
||||
public static String toId(int _accountId, String _groupId, EnergyBlockViewMode _viewMode, Date _start) {
|
||||
return _accountId + "-" + _groupId + "-" + DaoSerializer.toEnumName(_viewMode) + "-" + _start.getTime();
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String _groupId) {
|
||||
groupId = _groupId;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String _groupName) {
|
||||
groupName = _groupName;
|
||||
}
|
||||
|
||||
public BreakerGroupSummary getSubGroup(String _groupId) {
|
||||
return CollectionUtils.filterOne(subGroups, _g->_groupId.equals(_g.getGroupId()));
|
||||
}
|
||||
|
||||
public List<BreakerGroupSummary> getSubGroups() {
|
||||
return subGroups;
|
||||
}
|
||||
|
||||
public EnergyBlockViewMode getViewMode() {
|
||||
return viewMode;
|
||||
}
|
||||
|
||||
public void setViewMode(EnergyBlockViewMode _viewMode) {
|
||||
viewMode = _viewMode;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Date _start) {
|
||||
start = _start;
|
||||
}
|
||||
|
||||
public void setSubGroups(List<BreakerGroupSummary> _subGroups) {
|
||||
subGroups = _subGroups;
|
||||
}
|
||||
|
||||
public double getJoules() {
|
||||
return joules;
|
||||
}
|
||||
|
||||
public void setJoules(double _joules) {
|
||||
joules = _joules;
|
||||
}
|
||||
|
||||
public double getToGrid() {
|
||||
return toGrid;
|
||||
}
|
||||
|
||||
public void setToGrid(double _toGrid) {
|
||||
toGrid = _toGrid;
|
||||
}
|
||||
|
||||
public double getFromGrid() {
|
||||
return fromGrid;
|
||||
}
|
||||
|
||||
public void setFromGrid(double _fromGrid) {
|
||||
fromGrid = _fromGrid;
|
||||
}
|
||||
|
||||
public List<BreakerGroupSummary> getAllGroups() {
|
||||
Map<String, BreakerGroupSummary> groups = new TreeMap<>();
|
||||
getAllGroups(groups);
|
||||
return new ArrayList<>(groups.values());
|
||||
}
|
||||
|
||||
public void getAllGroups(Map<String, BreakerGroupSummary> _groups) {
|
||||
if (NullUtils.isNotEmpty(getGroupId()))
|
||||
_groups.put(getGroupId(), this);
|
||||
for (BreakerGroupSummary group : CollectionUtils.makeNotNull(subGroups)) {
|
||||
group.getAllGroups(_groups);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable
|
||||
public class BreakerHub {
|
||||
private int hub;
|
||||
private double voltageCalibrationFactor;
|
||||
private int frequency;
|
||||
private String bluetoothMac;
|
||||
|
||||
public int getHub() {
|
||||
return hub;
|
||||
}
|
||||
|
||||
public void setHub(int _hub) {
|
||||
hub = _hub;
|
||||
}
|
||||
|
||||
public double getVoltageCalibrationFactor() {
|
||||
return voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public void setVoltageCalibrationFactor(double _voltageCalibrationFactor) {
|
||||
voltageCalibrationFactor = _voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public int getFrequency() {
|
||||
return frequency;
|
||||
}
|
||||
|
||||
public void setFrequency(int _frequency) {
|
||||
frequency = _frequency;
|
||||
}
|
||||
|
||||
public String getBluetoothMac() {
|
||||
return bluetoothMac;
|
||||
}
|
||||
|
||||
public void setBluetoothMac(String _bluetoothMac) {
|
||||
bluetoothMac = _bluetoothMac;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable
|
||||
public class BreakerPanel {
|
||||
private int accountId;
|
||||
private String name;
|
||||
private int index;
|
||||
private int spaces;
|
||||
private int meter;
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int _index) {
|
||||
index = _index;
|
||||
}
|
||||
|
||||
public int getSpaces() {
|
||||
return spaces;
|
||||
}
|
||||
|
||||
public void setSpaces(int _spaces) {
|
||||
spaces = _spaces;
|
||||
}
|
||||
|
||||
public int getMeter() {
|
||||
return meter;
|
||||
}
|
||||
|
||||
public void setMeter(int _meter) {
|
||||
meter = _meter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
public enum BreakerPolarity {
|
||||
NORMAL,
|
||||
SOLAR;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerPower {
|
||||
private int accountId;
|
||||
private int panel;
|
||||
private int space;
|
||||
private Date readTime;
|
||||
private String hubVersion;
|
||||
private double power;
|
||||
private double voltage;
|
||||
|
||||
public BreakerPower() {
|
||||
}
|
||||
|
||||
public BreakerPower(int _panel, int _space, Date _readTime, double _power, double _voltage) {
|
||||
panel = _panel;
|
||||
space = _space;
|
||||
readTime = _readTime;
|
||||
power = _power;
|
||||
voltage = _voltage;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return String.format("%d-%d-%d", accountId, panel, space);
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public int getPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void setPanel(int _panel) {
|
||||
panel = _panel;
|
||||
}
|
||||
|
||||
public int getSpace() {
|
||||
return space;
|
||||
}
|
||||
|
||||
public void setSpace(int _space) {
|
||||
space = _space;
|
||||
}
|
||||
|
||||
public Date getReadTime() {
|
||||
return readTime;
|
||||
}
|
||||
|
||||
public void setReadTime(Date _readTime) {
|
||||
readTime = _readTime;
|
||||
}
|
||||
|
||||
public String getHubVersion() {
|
||||
return hubVersion;
|
||||
}
|
||||
|
||||
public void setHubVersion(String _hubVersion) {
|
||||
hubVersion = _hubVersion;
|
||||
}
|
||||
|
||||
public double getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(double _power) {
|
||||
power = _power;
|
||||
}
|
||||
|
||||
public double getVoltage() {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
public void setVoltage(double _voltage) {
|
||||
voltage = _voltage;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return Breaker.key(panel, space);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerPowerMinute {
|
||||
private int panel;
|
||||
private int space;
|
||||
private List<Float> readings;
|
||||
|
||||
public int getPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void setPanel(int _panel) {
|
||||
panel = _panel;
|
||||
}
|
||||
|
||||
public int getSpace() {
|
||||
return space;
|
||||
}
|
||||
|
||||
public void setSpace(int _space) {
|
||||
space = _space;
|
||||
}
|
||||
|
||||
public String breakerKey() {
|
||||
return Breaker.key(panel, space);
|
||||
}
|
||||
|
||||
public List<Float> getReadings() {
|
||||
return readings;
|
||||
}
|
||||
|
||||
public void setReadings(List<Float> _readings) {
|
||||
readings = _readings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum BreakerType {
|
||||
EMPTY("Empty"),
|
||||
SINGLE_POLE("Single Pole"),
|
||||
SINGLE_POLE_TANDEM("Single Pole Tandem (Two Breakers in One)"),
|
||||
DOUBLE_POLE_TOP("Double Pole (240V)"),
|
||||
DOUBLE_POLE_BOTTOM("Double Pole (240V)");
|
||||
|
||||
private final String display;
|
||||
|
||||
BreakerType(String _display) {
|
||||
display = _display;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public static List<BreakerType> selectable() {
|
||||
return CollectionUtils.asArrayList(EMPTY, SINGLE_POLE, SINGLE_POLE_TANDEM, DOUBLE_POLE_TOP);
|
||||
}
|
||||
|
||||
public static BreakerType fromDisplay(String _display) {
|
||||
for (BreakerType type : values()) {
|
||||
if (NullUtils.isEqual(_display, type.getDisplay()))
|
||||
return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public enum CharacteristicFlag {
|
||||
BROADCAST("broadcast"),
|
||||
READ("read"),
|
||||
WRITE_WITHOUT_RESPONSE("write-without-response"),
|
||||
WRITE("write"),
|
||||
NOTIFY("notify"),
|
||||
INDICATE("indicate"),
|
||||
AUTHENTICATED_SIGNED_WRITES("authenticated-signed-writes"),
|
||||
RELIABLE_WRITE("reliable-write"),
|
||||
WRITABLE_AUXILIARIES("writable-auxiliaries"),
|
||||
ENCRYPT_READ("encrypt-read"),
|
||||
ENCRYPT_WRITE("encrypt-write"),
|
||||
ENCRYPT_AUTHENTICATED_READ("encrypt-authenticated-read"),
|
||||
ENCRYPT_AUTHENTICATED_WRITE("encrypt-authenticated-write");
|
||||
|
||||
CharacteristicFlag(String _value) {
|
||||
value = _value;
|
||||
}
|
||||
|
||||
public final String value;
|
||||
|
||||
public static String[] toArray(Collection<CharacteristicFlag> _flags) {
|
||||
return CollectionUtils.transform(_flags, _c->_c.value).toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@DBSerializable
|
||||
public class EnergyBlock {
|
||||
private Date start;
|
||||
private Date end;
|
||||
private double joules;
|
||||
|
||||
public EnergyBlock() {
|
||||
}
|
||||
|
||||
public EnergyBlock(Date _start, Date _end, double _joules) {
|
||||
start = _start;
|
||||
end = _end;
|
||||
joules = _joules;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Date _start) {
|
||||
start = _start;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Date _end) {
|
||||
end = _end;
|
||||
}
|
||||
|
||||
public double getJoules() {
|
||||
return joules;
|
||||
}
|
||||
|
||||
public void addJoules(double _joules) {
|
||||
joules += _joules;
|
||||
}
|
||||
|
||||
public void setJoules(double _joules) {
|
||||
joules = _joules;
|
||||
}
|
||||
|
||||
public double wattHours() {
|
||||
return joules / 3600;
|
||||
}
|
||||
|
||||
public double getAveragePower() {
|
||||
if ((end == null) || (start == null))
|
||||
return 0;
|
||||
return 1000*joules/(end.getTime()-start.getTime());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
public enum EnergyBlockType {
|
||||
ANY,
|
||||
POSITIVE,
|
||||
NEGATIVE
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.DateUtils;
|
||||
|
||||
import javax.management.remote.rmi._RMIConnection_Stub;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public enum EnergyBlockViewMode {
|
||||
DAY,
|
||||
MONTH,
|
||||
YEAR,
|
||||
ALL;
|
||||
|
||||
public Date toStart(Date _dt, TimeZone _tz) {
|
||||
if (this == DAY)
|
||||
return DateUtils.getMidnightBefore(_dt, _tz);
|
||||
if (this == MONTH)
|
||||
return DateUtils.getStartOfMonth(_dt, _tz);
|
||||
if (this == YEAR)
|
||||
return DateUtils.getStartOfYear(_dt, _tz);
|
||||
return new Date(0);
|
||||
}
|
||||
|
||||
public Date toEnd(Date _dt, TimeZone _tz) {
|
||||
if (this == DAY)
|
||||
return DateUtils.getMidnightAfter(_dt, _tz);
|
||||
if (this == MONTH)
|
||||
return DateUtils.getEndOfMonth(_dt, _tz);
|
||||
if (this == YEAR)
|
||||
return DateUtils.getEndOfYear(_dt, _tz);
|
||||
return new Date(0);
|
||||
}
|
||||
|
||||
public Date toBlockStart(Date _dt, TimeZone _tz) {
|
||||
if (this == DAY)
|
||||
return DateUtils.getStartOfMinute(_dt, _tz);
|
||||
if (this == MONTH)
|
||||
return DateUtils.getMidnightBefore(_dt, _tz);
|
||||
if (this == YEAR)
|
||||
return DateUtils.getStartOfMonth(_dt, _tz);
|
||||
return new Date(0);
|
||||
}
|
||||
|
||||
public Date toBlockEnd(Date _dt, TimeZone _tz) {
|
||||
if (this == DAY)
|
||||
return DateUtils.getEndOfMinute(_dt, _tz);
|
||||
if (this == MONTH)
|
||||
return DateUtils.getMidnightAfter(_dt, _tz);
|
||||
if (this == YEAR)
|
||||
return DateUtils.getEndOfMonth(_dt, _tz);
|
||||
return new Date(0);
|
||||
}
|
||||
|
||||
public Date incrementBlock(Date _dt, TimeZone _tz) {
|
||||
Calendar cal = DateUtils.toCalendar(_dt, _tz);
|
||||
if (this == DAY)
|
||||
cal.add(Calendar.MINUTE, 1);
|
||||
else if (this == MONTH)
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
if (this == YEAR)
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public Date decrementBlock(Date _dt, TimeZone _tz) {
|
||||
Calendar cal = DateUtils.toCalendar(_dt, _tz);
|
||||
if (this == DAY)
|
||||
cal.add(Calendar.MINUTE, -1);
|
||||
else if (this == MONTH)
|
||||
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||
if (this == YEAR)
|
||||
cal.add(Calendar.MONTH, -1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public Date incrementView(Date _dt, TimeZone _tz) {
|
||||
Calendar cal = DateUtils.toCalendar(_dt, _tz);
|
||||
if (this == DAY)
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
else if (this == MONTH)
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
if (this == YEAR)
|
||||
cal.add(Calendar.YEAR, 1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public Date decrementView(Date _dt, TimeZone _tz) {
|
||||
Calendar cal = DateUtils.toCalendar(_dt, _tz);
|
||||
if (this == DAY)
|
||||
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||
else if (this == MONTH)
|
||||
cal.add(Calendar.MONTH, -1);
|
||||
if (this == YEAR)
|
||||
cal.add(Calendar.YEAR, -1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public int blockCount(Date _start, TimeZone _tz) {
|
||||
if (this == ALL)
|
||||
return 1;
|
||||
Date end = toEnd(_start, _tz);
|
||||
int blockCnt = 0;
|
||||
while (_start.before(end)) {
|
||||
blockCnt++;
|
||||
_start = toBlockEnd(_start, _tz);
|
||||
}
|
||||
return blockCnt;
|
||||
}
|
||||
|
||||
public int blockIndex(Date _readTime, TimeZone _tz) {
|
||||
if (this == DAY) {
|
||||
Date start = DateUtils.getMidnightBefore(_readTime, _tz);
|
||||
return (int)((_readTime.getTime() - start.getTime())/60000);
|
||||
}
|
||||
else if (this == MONTH) {
|
||||
Calendar read = DateUtils.toCalendar(_readTime, _tz);
|
||||
return read.get(Calendar.DAY_OF_MONTH) - 1;
|
||||
}
|
||||
if (this == YEAR) {
|
||||
Calendar read = DateUtils.toCalendar(_readTime, _tz);
|
||||
return read.get(Calendar.MONTH);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Date toBlockStart(int _index, Date _start, TimeZone _tz) {
|
||||
if (this == DAY)
|
||||
return new Date(_start.getTime() + _index*60000);
|
||||
else if (this == MONTH) {
|
||||
Calendar read = DateUtils.toCalendar(_start, _tz);
|
||||
read.add(Calendar.DAY_OF_MONTH, _index);
|
||||
return read.getTime();
|
||||
}
|
||||
if (this == YEAR) {
|
||||
Calendar read = DateUtils.toCalendar(_start, _tz);
|
||||
read.add(Calendar.MONTH, _index);
|
||||
return read.getTime();
|
||||
}
|
||||
return new Date(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public enum HubConfigCharacteristic {
|
||||
WifiCredentials(2, CharacteristicFlag.WRITE),
|
||||
AuthCode(3, CharacteristicFlag.WRITE),
|
||||
HubIndex(4, CharacteristicFlag.READ, CharacteristicFlag.WRITE),
|
||||
Restart(5, CharacteristicFlag.WRITE),
|
||||
Reboot(6, CharacteristicFlag.WRITE),
|
||||
AccountId(7, CharacteristicFlag.READ),
|
||||
NetworkState(8, CharacteristicFlag.READ),
|
||||
Flash(9, CharacteristicFlag.WRITE);
|
||||
|
||||
public final int idx;
|
||||
public final UUID uuid;
|
||||
public final EnumSet<CharacteristicFlag> flags;
|
||||
|
||||
HubConfigCharacteristic(int _idx, CharacteristicFlag... _flags) {
|
||||
idx = _idx;
|
||||
uuid = HubConfigService.uuidFormat.format(_idx);
|
||||
flags = EnumSet.copyOf(Arrays.asList(_flags));
|
||||
}
|
||||
|
||||
public int getIdx() {
|
||||
return idx;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public EnumSet<CharacteristicFlag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public boolean isChar(String _char) {
|
||||
return NullUtils.isEqual(name(), _char);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.cryptography.AESTool;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HubConfigService {
|
||||
public static final UUIDFormatter uuidFormat = new UUIDFormatter("c5650001-d50f-49af-b906-cada0dc17937");
|
||||
private static final AESTool aes = new AESTool(37320708309265127L,-8068168662055796771L,-4867793276337148572L,4425609941731230765L);
|
||||
private static final UUID serviceUUID = uuidFormat.format(1);
|
||||
|
||||
public HubConfigService() {
|
||||
}
|
||||
|
||||
public static UUID getServiceUUID() {
|
||||
return serviceUUID;
|
||||
}
|
||||
|
||||
public List<HubConfigCharacteristic> getCharacteristics() {
|
||||
return Arrays.asList(HubConfigCharacteristic.values());
|
||||
}
|
||||
|
||||
public static byte[] encryptWifiCreds(String _ssid, String _password) {
|
||||
DaoEntity creds = new DaoEntity("ssid", _ssid).and("pwd", _password);
|
||||
return aes.encrypt(DaoSerializer.toZipBson(creds));
|
||||
}
|
||||
|
||||
public static String decryptWifiSSID(byte[] _payload) {
|
||||
return DaoSerializer.getString(DaoSerializer.fromZipBson(aes.decrypt(_payload)), "ssid");
|
||||
}
|
||||
|
||||
public static String decryptWifiPassword(byte[] _payload) {
|
||||
return DaoSerializer.getString(DaoSerializer.fromZipBson(aes.decrypt(_payload)), "pwd");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable
|
||||
public class HubPowerMinute {
|
||||
private int accountId;
|
||||
private int hub;
|
||||
private int minute;
|
||||
private List<BreakerPowerMinute> breakers;
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public int getHub() {
|
||||
return hub;
|
||||
}
|
||||
|
||||
public void setHub(int _hub) {
|
||||
hub = _hub;
|
||||
}
|
||||
|
||||
public Date getMinuteAsDate() {
|
||||
return new Date(((long)minute)*60000);
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
return minute;
|
||||
}
|
||||
|
||||
public void setMinute(int _minute) {
|
||||
minute = _minute;
|
||||
}
|
||||
|
||||
public void setMinute(Date _minute) {
|
||||
minute = (int)(_minute.getTime()/60000);
|
||||
}
|
||||
|
||||
public List<BreakerPowerMinute> getBreakers() {
|
||||
return breakers;
|
||||
}
|
||||
|
||||
public void setBreakers(List<BreakerPowerMinute> _breakers) {
|
||||
breakers = _breakers;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return String.format("%d-%d-%d", accountId, hub, minute);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable
|
||||
public class Meter {
|
||||
private int accountId;
|
||||
private int index;
|
||||
private String name;
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int _index) {
|
||||
index = _index;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public enum NetworkAdapter {
|
||||
ETHERNET((byte)0x1),
|
||||
WIFI((byte)0x2);
|
||||
|
||||
public final byte bt;
|
||||
|
||||
NetworkAdapter(byte _bt) {
|
||||
bt = _bt;
|
||||
}
|
||||
|
||||
public static NetworkAdapter fromByte(byte _bt) {
|
||||
for (NetworkAdapter a : values()) {
|
||||
if (a.bt == _bt)
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static EnumSet<NetworkAdapter> fromMask(byte _bt) {
|
||||
EnumSet<NetworkAdapter> values = EnumSet.noneOf(NetworkAdapter.class);
|
||||
for (NetworkAdapter a : values()) {
|
||||
if ((a.bt & _bt) == a.bt)
|
||||
values.add(a);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static byte toMask(Collection<NetworkAdapter> _adapters) {
|
||||
byte mask = 0;
|
||||
for (NetworkAdapter a : CollectionUtils.makeNotNull(_adapters)) {
|
||||
mask |= a.bt;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkStatus {
|
||||
private List<String> wifiIPs;
|
||||
private List<String> ethernetIPs;
|
||||
|
||||
public List<String> getWifiIPs() {
|
||||
return wifiIPs;
|
||||
}
|
||||
|
||||
public void setWifiIPs(List<String> _wifiIPs) {
|
||||
wifiIPs = _wifiIPs;
|
||||
}
|
||||
|
||||
public List<String> getEthernetIPs() {
|
||||
return ethernetIPs;
|
||||
}
|
||||
|
||||
public void setEthernetIPs(List<String> _ethernetIPs) {
|
||||
ethernetIPs = _ethernetIPs;
|
||||
}
|
||||
|
||||
public boolean isWifiConnected() {
|
||||
return CollectionUtils.isNotEmpty(wifiIPs);
|
||||
}
|
||||
|
||||
public boolean isEthernetConnected() {
|
||||
return CollectionUtils.isNotEmpty(ethernetIPs);
|
||||
}
|
||||
|
||||
public byte toMask() {
|
||||
EnumSet<NetworkAdapter> adapters = EnumSet.noneOf(NetworkAdapter.class);
|
||||
if (isWifiConnected())
|
||||
adapters.add(NetworkAdapter.WIFI);
|
||||
if (isEthernetConnected())
|
||||
adapters.add(NetworkAdapter.ETHERNET);
|
||||
return NetworkAdapter.toMask(adapters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
@DBSerializable
|
||||
public class Sequence {
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
private int sequence;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String _id) {
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public int getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(int _sequence) {
|
||||
sequence = _sequence;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable
|
||||
public class SignupResponse {
|
||||
private String error;
|
||||
private String authCode;
|
||||
|
||||
public SignupResponse() {
|
||||
}
|
||||
|
||||
public static SignupResponse error(String _error) {
|
||||
SignupResponse response = new SignupResponse();
|
||||
response.setError(_error);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static SignupResponse success(String _authCode) {
|
||||
SignupResponse response = new SignupResponse();
|
||||
response.setAuthCode(_authCode);
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String _error) {
|
||||
error = _error;
|
||||
}
|
||||
|
||||
public String getAuthCode() {
|
||||
return authCode;
|
||||
}
|
||||
|
||||
public void setAuthCode(String _authCode) {
|
||||
authCode = _authCode;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return NullUtils.isEmpty(error) && NullUtils.isNotEmpty(authCode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDFormatter {
|
||||
private final String uuidPrefix;
|
||||
private final String uuidSuffix;
|
||||
|
||||
public UUIDFormatter(String _uuid) {
|
||||
uuidPrefix = _uuid.substring(0,4);
|
||||
uuidSuffix = _uuid.substring(8);
|
||||
}
|
||||
|
||||
public UUID format(int _idx) {
|
||||
return UUID.fromString(uuidPrefix + String.format("%04X", _idx) + uuidSuffix);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Account;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AccountSerializer extends AbstractDaoSerializer<Account>
|
||||
{
|
||||
@Override
|
||||
public Class<Account> getSupportedClass()
|
||||
{
|
||||
return Account.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(Account _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", String.valueOf(_o.getId()));
|
||||
d.put("username", _o.getUsername());
|
||||
d.put("password", _o.getPassword());
|
||||
if (CollectionUtils.isNotEmpty(_o.getAuxiliaryAccountIds()))
|
||||
d.put("aux_account_ids", CollectionUtils.toByteArray(_o.getAuxiliaryAccountIds()));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
Account o = new Account();
|
||||
o.setId(DaoSerializer.getInteger(_d, "_id"));
|
||||
o.setUsername(DaoSerializer.getString(_d, "username"));
|
||||
o.setPassword(DaoSerializer.getString(_d, "password"));
|
||||
o.setAuxiliaryAccountIds(CollectionUtils.fromByteArrayOfIntegers(DaoSerializer.getByteArray(_d, "aux_account_ids")));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.AuthCode;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AuthCodeSerializer extends AbstractDaoSerializer<AuthCode>
|
||||
{
|
||||
@Override
|
||||
public Class<AuthCode> getSupportedClass()
|
||||
{
|
||||
return AuthCode.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(AuthCode _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("account_id", _o.getAccountId());
|
||||
if (CollectionUtils.isNotEmpty(_o.getAuxiliaryAccountIds()))
|
||||
d.put("aux_account_ids", CollectionUtils.toByteArray(_o.getAuxiliaryAccountIds()));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthCode fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
AuthCode o = new AuthCode();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setAuxiliaryAccountIds(CollectionUtils.fromByteArrayOfIntegers(DaoSerializer.getByteArray(_d, "aux_account_ids")));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerConfig;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerGroup;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerHub;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPanel;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Meter;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerConfigSerializer extends AbstractDaoSerializer<BreakerConfig>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerConfig> getSupportedClass()
|
||||
{
|
||||
return BreakerConfig.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerConfig _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", String.valueOf(_o.getAccountId()));
|
||||
d.put("meters", DaoSerializer.toDaoEntities(_o.getMeters(), DaoProxyType.MONGO));
|
||||
d.put("panels", DaoSerializer.toDaoEntities(_o.getPanels(), DaoProxyType.MONGO));
|
||||
d.put("breaker_hubs", DaoSerializer.toDaoEntities(_o.getBreakerHubs(), DaoProxyType.MONGO));
|
||||
d.put("breaker_groups", DaoSerializer.toDaoEntities(_o.getBreakerGroups(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerConfig fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
BreakerConfig o = new BreakerConfig();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "_id"));
|
||||
o.setMeters(DaoSerializer.getList(_d, "meters", Meter.class));
|
||||
o.setPanels(DaoSerializer.getList(_d, "panels", BreakerPanel.class));
|
||||
o.setBreakerHubs(DaoSerializer.getList(_d, "breaker_hubs", BreakerHub.class));
|
||||
o.setBreakerGroups(DaoSerializer.getList(_d, "breaker_groups", BreakerGroup.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerGroupEnergy;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlock;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlockViewMode;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class BreakerGroupEnergySerializer extends AbstractDaoSerializer<BreakerGroupEnergy>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerGroupEnergy> getSupportedClass()
|
||||
{
|
||||
return BreakerGroupEnergy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerGroupEnergy _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("group_id", _o.getGroupId());
|
||||
d.put("group_name", _o.getGroupName());
|
||||
d.put("view_mode", DaoSerializer.toEnumName(_o.getViewMode()));
|
||||
d.put("start", DaoSerializer.toLong(_o.getStart()));
|
||||
d.put("sub_groups", DaoSerializer.toDaoEntities(_o.getSubGroups(), DaoProxyType.MONGO));
|
||||
if (CollectionUtils.size(_o.getEnergyBlocks()) > 0) {
|
||||
Date start = _o.getStart();
|
||||
Date now = new Date();
|
||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
||||
ByteBuffer bb = ByteBuffer.allocate(_o.getViewMode().blockCount(start, tz) * 4);
|
||||
for (EnergyBlock b : _o.getEnergyBlocks()) {
|
||||
if (b.getStart().before(start))
|
||||
continue;
|
||||
if (now.before(start))
|
||||
break;
|
||||
while (start.before(b.getStart())) {
|
||||
bb.putFloat(0);
|
||||
start = _o.getViewMode().toBlockEnd(start, tz);
|
||||
}
|
||||
bb.putFloat((float) b.getJoules());
|
||||
start = _o.getViewMode().toBlockEnd(start, tz);
|
||||
}
|
||||
if (bb.position() < bb.limit())
|
||||
d.put("blocks", Arrays.copyOfRange(bb.array(), 0, bb.position()));
|
||||
else
|
||||
d.put("blocks", bb.array());
|
||||
}
|
||||
d.put("to_grid", _o.getToGrid());
|
||||
d.put("from_grid", _o.getFromGrid());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerGroupEnergy fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
||||
BreakerGroupEnergy o = new BreakerGroupEnergy();
|
||||
o.setGroupId(DaoSerializer.getString(_d, "group_id"));
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setGroupName(DaoSerializer.getString(_d, "group_name"));
|
||||
o.setViewMode(DaoSerializer.getEnum(_d, "view_mode", EnergyBlockViewMode.class));
|
||||
o.setStart(DaoSerializer.getDate(_d, "start"));
|
||||
o.setSubGroups(DaoSerializer.getList(_d, "sub_groups", BreakerGroupEnergy.class));
|
||||
List<EnergyBlock> blocks = new ArrayList<>();
|
||||
byte[] blockData = DaoSerializer.getByteArray(_d, "blocks");
|
||||
if (CollectionUtils.length(blockData) > 0) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(blockData);
|
||||
Date start = o.getStart();
|
||||
while (bb.hasRemaining()) {
|
||||
EnergyBlock block = new EnergyBlock(start, o.getViewMode().toBlockEnd(start, tz), bb.getFloat());
|
||||
blocks.add(block);
|
||||
start = block.getEnd();
|
||||
}
|
||||
}
|
||||
o.setEnergyBlocks(blocks);
|
||||
o.setToGrid(DaoSerializer.getDouble(_d, "to_grid"));
|
||||
o.setFromGrid(DaoSerializer.getDouble(_d, "from_grid"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerGroup;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerGroupSerializer extends AbstractDaoSerializer<BreakerGroup>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerGroup> getSupportedClass()
|
||||
{
|
||||
return BreakerGroup.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerGroup _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
if (_o.getId() != null)
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("name", _o.getName());
|
||||
d.put("sub_groups", DaoSerializer.toDaoEntities(_o.getSubGroups(), DaoProxyType.MONGO));
|
||||
d.put("breakers", DaoSerializer.toDaoEntities(_o.getBreakers(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerGroup fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
BreakerGroup o = new BreakerGroup();
|
||||
o.setId(DaoSerializer.getString(_d, "_id"));
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setName(DaoSerializer.getString(_d, "name"));
|
||||
o.setSubGroups(DaoSerializer.getList(_d, "sub_groups", BreakerGroup.class));
|
||||
o.setBreakers(DaoSerializer.getList(_d, "breakers", Breaker.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerGroupSummary;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlockViewMode;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class BreakerGroupSummarySerializer extends AbstractDaoSerializer<BreakerGroupSummary> {
|
||||
@Override
|
||||
public Class<BreakerGroupSummary> getSupportedClass() {
|
||||
return BreakerGroupSummary.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerGroupSummary _o) {
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("group_id", _o.getGroupId());
|
||||
d.put("group_name", _o.getGroupName());
|
||||
d.put("view_mode", DaoSerializer.toEnumName(_o.getViewMode()));
|
||||
d.put("start", DaoSerializer.toLong(_o.getStart()));
|
||||
d.put("sub_groups", DaoSerializer.toDaoEntities(_o.getSubGroups(), DaoProxyType.MONGO));
|
||||
d.put("joules", _o.getJoules());
|
||||
d.put("to_grid", _o.getToGrid());
|
||||
d.put("from_grid", _o.getFromGrid());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerGroupSummary fromDaoEntity(DaoEntity _d) {
|
||||
BreakerGroupSummary o = new BreakerGroupSummary();
|
||||
o.setGroupId(DaoSerializer.getString(_d, "group_id"));
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setGroupName(DaoSerializer.getString(_d, "group_name"));
|
||||
o.setViewMode(DaoSerializer.getEnum(_d, "view_mode", EnergyBlockViewMode.class));
|
||||
o.setStart(DaoSerializer.getDate(_d, "start"));
|
||||
o.setSubGroups(DaoSerializer.getList(_d, "sub_groups", BreakerGroupSummary.class));
|
||||
o.setJoules(DaoSerializer.getDouble(_d, "joules"));
|
||||
o.setToGrid(DaoSerializer.getDouble(_d, "to_grid"));
|
||||
o.setFromGrid(DaoSerializer.getDouble(_d, "from_grid"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerHub;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerHub> getSupportedClass()
|
||||
{
|
||||
return BreakerHub.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerHub _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("hub", _o.getHub());
|
||||
d.put("voltage_calibration_factor", _o.getVoltageCalibrationFactor());
|
||||
d.put("frequency", _o.getFrequency());
|
||||
d.put("bluetooth_mac", _o.getBluetoothMac());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerHub fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
BreakerHub o = new BreakerHub();
|
||||
o.setHub(DaoSerializer.getInteger(_d, "hub"));
|
||||
o.setVoltageCalibrationFactor(DaoSerializer.getDouble(_d, "voltage_calibration_factor"));
|
||||
o.setFrequency(DaoSerializer.getInteger(_d, "frequency"));
|
||||
o.setBluetoothMac(DaoSerializer.getString(_d, "bluetooth_mac"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPanel;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerPanelSerializer extends AbstractDaoSerializer<BreakerPanel>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerPanel> getSupportedClass()
|
||||
{
|
||||
return BreakerPanel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerPanel _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("name", _o.getName());
|
||||
d.put("index", _o.getIndex());
|
||||
d.put("spaces", _o.getSpaces());
|
||||
d.put("meter", _o.getMeter());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerPanel fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
BreakerPanel o = new BreakerPanel();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setName(DaoSerializer.getString(_d, "name"));
|
||||
o.setIndex(DaoSerializer.getInteger(_d, "index"));
|
||||
o.setSpaces(DaoSerializer.getInteger(_d, "spaces"));
|
||||
o.setMeter(DaoSerializer.getInteger(_d, "meter"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPowerMinute;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerPowerMinuteSerializer extends AbstractDaoSerializer<BreakerPowerMinute> {
|
||||
@Override
|
||||
public Class<BreakerPowerMinute> getSupportedClass() {
|
||||
return BreakerPowerMinute.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerPowerMinute _o) {
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("panel", _o.getPanel());
|
||||
d.put("space", _o.getSpace());
|
||||
ByteBuffer bb = ByteBuffer.allocate(240);
|
||||
for (Float reading : CollectionUtils.makeNotNull(_o.getReadings())) {
|
||||
bb.putFloat(DaoSerializer.toFloat(reading));
|
||||
}
|
||||
d.put("readings", bb.array());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerPowerMinute fromDaoEntity(DaoEntity _d) {
|
||||
BreakerPowerMinute o = new BreakerPowerMinute();
|
||||
o.setPanel(DaoSerializer.getInteger(_d, "panel"));
|
||||
o.setSpace(DaoSerializer.getInteger(_d, "space"));
|
||||
byte[] data = DaoSerializer.getByteArray(_d, "readings");
|
||||
List<Float> readings = new ArrayList<>();
|
||||
o.setReadings(readings);
|
||||
if (CollectionUtils.length(data) > 0) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(data);
|
||||
while (bb.hasRemaining()) {
|
||||
readings.add(bb.getFloat());
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPower;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerPowerSerializer extends AbstractDaoSerializer<BreakerPower>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerPower> getSupportedClass()
|
||||
{
|
||||
return BreakerPower.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerPower _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("panel", _o.getPanel());
|
||||
d.put("space", _o.getSpace());
|
||||
d.put("key", _o.getKey());
|
||||
d.put("read_time", DaoSerializer.toLong(_o.getReadTime()));
|
||||
d.put("hub_version", _o.getHubVersion());
|
||||
d.put("power", _o.getPower());
|
||||
d.put("voltage", _o.getVoltage());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerPower fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
BreakerPower o = new BreakerPower();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setPanel(DaoSerializer.getInteger(_d, "panel"));
|
||||
o.setSpace(DaoSerializer.getInteger(_d, "space"));
|
||||
o.setReadTime(DaoSerializer.getDate(_d, "read_time"));
|
||||
o.setHubVersion(DaoSerializer.getString(_d, "hub_version"));
|
||||
o.setPower(DaoSerializer.getDouble(_d, "power"));
|
||||
o.setVoltage(DaoSerializer.getDouble(_d, "voltage"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPolarity;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerType;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerSerializer extends AbstractDaoSerializer<Breaker>
|
||||
{
|
||||
@Override
|
||||
public Class<Breaker> getSupportedClass()
|
||||
{
|
||||
return Breaker.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(Breaker _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("panel", _o.getPanel());
|
||||
d.put("space", _o.getSpace());
|
||||
d.put("meter", _o.getMeter());
|
||||
d.put("hub", _o.getHub());
|
||||
d.put("port", _o.getPort());
|
||||
d.put("name", _o.getName());
|
||||
d.put("description", _o.getDescription());
|
||||
d.put("size_amps", _o.getSizeAmps());
|
||||
d.put("calibration_factor", _o.getCalibrationFactor());
|
||||
d.put("low_pass_filter", _o.getLowPassFilter());
|
||||
d.put("polarity", DaoSerializer.toEnumName(_o.getPolarity()));
|
||||
d.put("type", DaoSerializer.toEnumName(_o.getType()));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Breaker fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
Breaker o = new Breaker();
|
||||
o.setPanel(DaoSerializer.getInteger(_d, "panel"));
|
||||
o.setSpace(DaoSerializer.getInteger(_d, "space"));
|
||||
o.setMeter(DaoSerializer.getInteger(_d, "meter"));
|
||||
o.setHub(DaoSerializer.getInteger(_d, "hub"));
|
||||
o.setPort(DaoSerializer.getInteger(_d, "port"));
|
||||
o.setName(DaoSerializer.getString(_d, "name"));
|
||||
o.setDescription(DaoSerializer.getString(_d, "description"));
|
||||
o.setSizeAmps(DaoSerializer.getInteger(_d, "size_amps"));
|
||||
o.setCalibrationFactor(DaoSerializer.getDouble(_d, "calibration_factor"));
|
||||
o.setLowPassFilter(DaoSerializer.getDouble(_d, "low_pass_filter"));
|
||||
o.setPolarity(DaoSerializer.getEnum(_d, "polarity", BreakerPolarity.class));
|
||||
o.setType(DaoSerializer.getEnum(_d, "type", BreakerType.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EnergyBlock;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class EnergyBlockSerializer extends AbstractDaoSerializer<EnergyBlock>
|
||||
{
|
||||
@Override
|
||||
public Class<EnergyBlock> getSupportedClass()
|
||||
{
|
||||
return EnergyBlock.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(EnergyBlock _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("start", DaoSerializer.toLong(_o.getStart()));
|
||||
d.put("end", DaoSerializer.toLong(_o.getEnd()));
|
||||
d.put("joules", _o.getJoules());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyBlock fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
EnergyBlock o = new EnergyBlock();
|
||||
o.setStart(DaoSerializer.getDate(_d, "start"));
|
||||
o.setEnd(DaoSerializer.getDate(_d, "end"));
|
||||
o.setJoules(DaoSerializer.getDouble(_d, "joules"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPowerMinute;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.HubPowerMinute;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HubPowerMinuteSerializer extends AbstractDaoSerializer<HubPowerMinute>
|
||||
{
|
||||
@Override
|
||||
public Class<HubPowerMinute> getSupportedClass()
|
||||
{
|
||||
return HubPowerMinute.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(HubPowerMinute _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("hub", _o.getHub());
|
||||
d.put("minute", _o.getMinute());
|
||||
d.put("breakers", DaoSerializer.toDaoEntities(_o.getBreakers(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubPowerMinute fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
HubPowerMinute o = new HubPowerMinute();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setHub(DaoSerializer.getInteger(_d, "hub"));
|
||||
o.setMinute(DaoSerializer.getInteger(_d, "minute"));
|
||||
o.setBreakers(DaoSerializer.getList(_d, "breakers", BreakerPowerMinute.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Meter;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MeterSerializer extends AbstractDaoSerializer<Meter>
|
||||
{
|
||||
@Override
|
||||
public Class<Meter> getSupportedClass()
|
||||
{
|
||||
return Meter.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(Meter _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("index", _o.getIndex());
|
||||
d.put("name", _o.getName());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meter fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
Meter o = new Meter();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setIndex(DaoSerializer.getInteger(_d, "index"));
|
||||
o.setName(DaoSerializer.getString(_d, "name"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Sequence;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SequenceSerializer extends AbstractDaoSerializer<Sequence>
|
||||
{
|
||||
@Override
|
||||
public Class<Sequence> getSupportedClass()
|
||||
{
|
||||
return Sequence.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(Sequence _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
if (_o.getId() != null)
|
||||
d.put("_id", _o.getId());
|
||||
d.put("sequence", _o.getSequence());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sequence fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
Sequence o = new Sequence();
|
||||
o.setId(DaoSerializer.getString(_d, "_id"));
|
||||
o.setSequence(DaoSerializer.getInteger(_d, "sequence"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.SignupResponse;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SignupResponseSerializer extends AbstractDaoSerializer<SignupResponse>
|
||||
{
|
||||
@Override
|
||||
public Class<SignupResponse> getSupportedClass()
|
||||
{
|
||||
return SignupResponse.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(SignupResponse _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("error", _o.getError());
|
||||
d.put("auth_code", _o.getAuthCode());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignupResponse fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
SignupResponse o = new SignupResponse();
|
||||
o.setError(DaoSerializer.getString(_d, "error"));
|
||||
o.setAuthCode(DaoSerializer.getString(_d, "auth_code"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.AccountSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.AuthCodeSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerConfigSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerGroupEnergySerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerGroupSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerGroupSummarySerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerHubSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerPanelSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerPowerMinuteSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerPowerSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergyBlockSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.HubPowerMinuteSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.MeterSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.SequenceSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.SignupResponseSerializer
|
||||
Reference in New Issue
Block a user