Ausgabe (summary) überarbeitet und Klasse Sums überflüssig gemacht.
This commit is contained in:
parent
50cf2a06d0
commit
a8d65c21b2
@ -1,6 +1,5 @@
|
||||
package info.peper.vz.rest;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import info.peper.vz.rest.bo.Sums;
|
||||
import info.peper.vz.rest.bo.db.Aggregate;
|
||||
import info.peper.vz.rest.bo.db.EnergyPrice;
|
||||
|
||||
@ -34,7 +32,7 @@ class VzRestController {
|
||||
}
|
||||
|
||||
@GetMapping("/rest-vz/sums")
|
||||
Sums getData(@RequestParam("timestampStart")final long timestampStart,
|
||||
Aggregate getData(@RequestParam("timestampStart")final long timestampStart,
|
||||
@RequestParam("timestampEnd")final long timestampEnd,
|
||||
@RequestParam("houseId")final int houseId,
|
||||
@RequestParam("solarFactor")final float solarFactor) {
|
||||
@ -63,10 +61,7 @@ class VzRestController {
|
||||
log.debug("firstTimestamp: " + aggregate.getTimestampStart());
|
||||
log.debug("lastTimestamp: " + aggregate.getTimestampEnd());
|
||||
|
||||
return new Sums(
|
||||
Math.round(aggregate.getInjectedEnergy()),
|
||||
Math.round(aggregate.getObtainedEnergy()),
|
||||
Math.round(aggregate.getProducedEnergy()));
|
||||
return aggregate;
|
||||
}
|
||||
|
||||
@GetMapping("/rest-vz/prices")
|
||||
@ -82,7 +77,7 @@ class VzRestController {
|
||||
}
|
||||
|
||||
@GetMapping(value="/rest-vz/summary", produces = {"text/plain"})
|
||||
String getSummary2(@RequestParam(name = "timestampStart", defaultValue = "-1")long timestampStart,
|
||||
String getSummary(@RequestParam(name = "timestampStart", defaultValue = "-1")long timestampStart,
|
||||
@RequestParam(name = "timestampEnd", defaultValue = "-1")long timestampEnd,
|
||||
@RequestParam(name = "duration", defaultValue = "")final String duration,
|
||||
@RequestParam("houseId")final int houseId,
|
||||
@ -110,16 +105,26 @@ class VzRestController {
|
||||
long totalProduced = 0;
|
||||
long totalObtained = 0;
|
||||
long totalInjected = 0;
|
||||
long timestampMin = Long.MAX_VALUE;
|
||||
long timestampMax = Long.MIN_VALUE;
|
||||
for (EnergyPrice price : prices) {
|
||||
final long tsStart = Math.max(price.getTimestampStart(), timestampStart);
|
||||
final long tsEnd = Math.min(price.getTimestampEnd(), timestampEnd);
|
||||
final Sums sums = getData(tsStart, tsEnd, houseId, solarFactor);
|
||||
savedMoney += (float)(sums.getProduced() - sums.getInjected())/1000000 * price.getPrice();
|
||||
totalProduced += sums.getProduced();
|
||||
totalObtained += sums.getObtained();
|
||||
totalInjected += sums.getInjected();
|
||||
final Aggregate aggregate = getData(tsStart, tsEnd, houseId, solarFactor);
|
||||
savedMoney += (float)(aggregate.getProducedEnergy() - aggregate.getInjectedEnergy())/1000000 * price.getPrice();
|
||||
totalProduced += aggregate.getProducedEnergy();
|
||||
totalObtained += aggregate.getObtainedEnergy();
|
||||
totalInjected += aggregate.getInjectedEnergy();
|
||||
if (timestampMin > aggregate.getTimestampStart()) {
|
||||
timestampMin = aggregate.getTimestampStart();
|
||||
}
|
||||
if (timestampMax < aggregate.getTimestampEnd()) {
|
||||
timestampMax = aggregate.getTimestampEnd();
|
||||
}
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("Start: " + Instant.ofEpochMilli(timestampMin).toString() + "\n");
|
||||
sb.append("Ende: " + Instant.ofEpochMilli(timestampMax).toString() + "\n");
|
||||
sb.append("Erzeugter Strom von der Photovoltaik: " + formatEnergy.format((float)totalProduced/1000000) + " kWh\n");
|
||||
sb.append("Eingespeister Strom von der Photovoltaik: " + formatEnergy.format((float)totalInjected/1000000) + " kWh\n");
|
||||
sb.append("Genutzter Strom von der Photovoltaik: " + formatEnergy.format((float)(totalProduced-totalInjected)/1000000) + " kWh (=");
|
||||
|
||||
5
src/main/java/info/peper/vz/rest/bo/Statistics.java
Normal file
5
src/main/java/info/peper/vz/rest/bo/Statistics.java
Normal file
@ -0,0 +1,5 @@
|
||||
package info.peper.vz.rest.bo;
|
||||
|
||||
public class Statistics {
|
||||
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
package info.peper.vz.rest.bo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Sums implements Serializable {
|
||||
private static final long serialVersionUID = -1816023197422851264L;
|
||||
private final long injected;
|
||||
private final long obtained;
|
||||
private final long produced;
|
||||
public Sums(long injected, long obtained, long produced) {
|
||||
super();
|
||||
this.injected = injected;
|
||||
this.obtained = obtained;
|
||||
this.produced = produced;
|
||||
}
|
||||
public long getInjected() {
|
||||
return injected;
|
||||
}
|
||||
public long getObtained() {
|
||||
return obtained;
|
||||
}
|
||||
public long getProduced() {
|
||||
return produced;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (injected ^ (injected >>> 32));
|
||||
result = prime * result + (int) (obtained ^ (obtained >>> 32));
|
||||
result = prime * result + (int) (produced ^ (produced >>> 32));
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Sums other = (Sums) obj;
|
||||
if (injected != other.injected)
|
||||
return false;
|
||||
if (obtained != other.obtained)
|
||||
return false;
|
||||
if (produced != other.produced)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user