mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Allow exporting all data in bson, json, or csv formats.
This commit is contained in:
@@ -194,10 +194,26 @@ public class Breaker implements IIdentical<Breaker> {
|
||||
return key;
|
||||
}
|
||||
|
||||
public int getIntKey() {
|
||||
return intKey(panel, space);
|
||||
}
|
||||
|
||||
public static int intKeyToPanel(int _intKey) {
|
||||
return _intKey/10000;
|
||||
}
|
||||
|
||||
public static int intKeyToSpace(int _intKey) {
|
||||
return _intKey%10000;
|
||||
}
|
||||
|
||||
public static String key(int _panel, int _space) {
|
||||
return String.format("%d-%d", _panel, _space);
|
||||
}
|
||||
|
||||
public static int intKey(int _panel, int _space) {
|
||||
return 10000*_panel + _space;
|
||||
}
|
||||
|
||||
public static int portToChip(int _port) {
|
||||
return (_port < 9) ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ public class BreakerPowerMinute {
|
||||
return Breaker.key(panel, space);
|
||||
}
|
||||
|
||||
public int breakerIntKey() {
|
||||
return Breaker.intKey(panel, space);
|
||||
}
|
||||
|
||||
public List<Float> getReadings() {
|
||||
return readings;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive;
|
||||
|
||||
import com.lanternsoftware.util.DateUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class ArchiveStatus {
|
||||
private int accountId;
|
||||
private Date month;
|
||||
private float progress;
|
||||
|
||||
public ArchiveStatus() {
|
||||
}
|
||||
|
||||
public ArchiveStatus(int _accountId, Date _month, float _progress) {
|
||||
accountId = _accountId;
|
||||
month = _month;
|
||||
progress = _progress;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return String.format("%d-%d", accountId, DateUtils.toLong(month));
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public Date getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public void setMonth(Date _month) {
|
||||
month = _month;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(float _progress) {
|
||||
progress = _progress;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable
|
||||
public class BreakerEnergyArchive {
|
||||
private int panel;
|
||||
private int space;
|
||||
private byte[] 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 byte[] getReadings() {
|
||||
return readings;
|
||||
}
|
||||
|
||||
public void setReadings(byte[] _readings) {
|
||||
readings = _readings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable
|
||||
public class DailyEnergyArchive {
|
||||
private List<BreakerEnergyArchive> breakers;
|
||||
|
||||
public List<BreakerEnergyArchive> getBreakers() {
|
||||
return breakers;
|
||||
}
|
||||
|
||||
public void setBreakers(List<BreakerEnergyArchive> _breakers) {
|
||||
breakers = _breakers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive;
|
||||
|
||||
import com.lanternsoftware.util.DateUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class MonthlyEnergyArchive {
|
||||
private int accountId;
|
||||
private Date month;
|
||||
private List<DailyEnergyArchive> days;
|
||||
|
||||
public String getId() {
|
||||
return toId(accountId, month);
|
||||
}
|
||||
|
||||
public static String toId(int _accountId, Date _month) {
|
||||
return String.format("%d-%d", _accountId, DateUtils.toLong(_month));
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public Date getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public void setMonth(Date _month) {
|
||||
month = _month;
|
||||
}
|
||||
|
||||
public List<DailyEnergyArchive> getDays() {
|
||||
return days;
|
||||
}
|
||||
|
||||
public void setDays(List<DailyEnergyArchive> _days) {
|
||||
days = _days;
|
||||
}
|
||||
|
||||
public boolean isComplete(TimeZone _tz) {
|
||||
Date valid = DateUtils.addDays(new Date(), -7, _tz);
|
||||
valid = DateUtils.addMonths(valid, -1, _tz);
|
||||
return month.before(valid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.archive.ArchiveStatus;
|
||||
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 ArchiveStatusSerializer extends AbstractDaoSerializer<ArchiveStatus>
|
||||
{
|
||||
@Override
|
||||
public Class<ArchiveStatus> getSupportedClass()
|
||||
{
|
||||
return ArchiveStatus.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(ArchiveStatus _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("month", DaoSerializer.toLong(_o.getMonth()));
|
||||
d.put("progress", _o.getProgress());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArchiveStatus fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
ArchiveStatus o = new ArchiveStatus();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setMonth(DaoSerializer.getDate(_d, "month"));
|
||||
o.setProgress(DaoSerializer.getFloat(_d, "progress"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.archive.BreakerEnergyArchive;
|
||||
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 BreakerEnergyArchiveSerializer extends AbstractDaoSerializer<BreakerEnergyArchive>
|
||||
{
|
||||
@Override
|
||||
public Class<BreakerEnergyArchive> getSupportedClass()
|
||||
{
|
||||
return BreakerEnergyArchive.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(BreakerEnergyArchive _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("panel", _o.getPanel());
|
||||
d.put("space", _o.getSpace());
|
||||
d.put("readings", _o.getReadings());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakerEnergyArchive fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
BreakerEnergyArchive o = new BreakerEnergyArchive();
|
||||
o.setPanel(DaoSerializer.getInteger(_d, "panel"));
|
||||
o.setSpace(DaoSerializer.getInteger(_d, "space"));
|
||||
o.setReadings(DaoSerializer.getByteArray(_d, "readings"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.archive.BreakerEnergyArchive;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.archive.DailyEnergyArchive;
|
||||
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 DailyEnergyArchiveSerializer extends AbstractDaoSerializer<DailyEnergyArchive>
|
||||
{
|
||||
@Override
|
||||
public Class<DailyEnergyArchive> getSupportedClass()
|
||||
{
|
||||
return DailyEnergyArchive.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(DailyEnergyArchive _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("breakers", DaoSerializer.toDaoEntities(_o.getBreakers(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DailyEnergyArchive fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
DailyEnergyArchive o = new DailyEnergyArchive();
|
||||
o.setBreakers(DaoSerializer.getList(_d, "breakers", BreakerEnergyArchive.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.archive.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.archive.DailyEnergyArchive;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.archive.MonthlyEnergyArchive;
|
||||
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 MonthlyEnergyArchiveSerializer extends AbstractDaoSerializer<MonthlyEnergyArchive>
|
||||
{
|
||||
@Override
|
||||
public Class<MonthlyEnergyArchive> getSupportedClass()
|
||||
{
|
||||
return MonthlyEnergyArchive.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(MonthlyEnergyArchive _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("month", DaoSerializer.toLong(_o.getMonth()));
|
||||
d.put("days", DaoSerializer.toDaoEntities(_o.getDays(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MonthlyEnergyArchive fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
MonthlyEnergyArchive o = new MonthlyEnergyArchive();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setMonth(DaoSerializer.getDate(_d, "month"));
|
||||
o.setDays(DaoSerializer.getList(_d, "days", DailyEnergyArchive.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
com.lanternsoftware.datamodel.currentmonitor.archive.dao.ArchiveStatusSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.archive.dao.BreakerEnergyArchiveSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.archive.dao.DailyEnergyArchiveSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.archive.dao.MonthlyEnergyArchiveSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.AccountSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BillingPlanSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BillingRateSerializer
|
||||
|
||||
Reference in New Issue
Block a user