"Was wäre wenn" Berechnungen hinzugefügt
This commit is contained in:
parent
dfe189bff7
commit
50cf2a06d0
@ -34,14 +34,24 @@ class VzRestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/rest-vz/sums")
|
@GetMapping("/rest-vz/sums")
|
||||||
Sums getData2(@RequestParam("timestampStart")final long timestampStart,
|
Sums getData(@RequestParam("timestampStart")final long timestampStart,
|
||||||
@RequestParam("timestampEnd")final long timestampEnd,
|
@RequestParam("timestampEnd")final long timestampEnd,
|
||||||
@RequestParam("houseId")final int houseId) {
|
@RequestParam("houseId")final int houseId,
|
||||||
final List<Aggregate> aggregates = jdbcTemplate.query(
|
@RequestParam("solarFactor")final float solarFactor) {
|
||||||
|
final List<Aggregate> aggregates;
|
||||||
|
if (solarFactor == 1.0f) {
|
||||||
|
aggregates = jdbcTemplate.query(
|
||||||
"SELECT MIN(timestamp_start) AS min_ts_start, MAX(timestamp_end) AS max_ts_end, SUM(produced_energy)/3600 AS sum_produced, SUM(obtained_energy)/3600 AS sum_obtained, SUM(injected_energy)/3600 AS sum_injected FROM volkszaehler.tobias_aggregate2 WHERE house_id=? AND timestamp_start>=? AND timestamp_end<=?;",
|
"SELECT MIN(timestamp_start) AS min_ts_start, MAX(timestamp_end) AS max_ts_end, SUM(produced_energy)/3600 AS sum_produced, SUM(obtained_energy)/3600 AS sum_obtained, SUM(injected_energy)/3600 AS sum_injected FROM volkszaehler.tobias_aggregate2 WHERE house_id=? AND timestamp_start>=? AND timestamp_end<=?;",
|
||||||
(rs, rowNum) -> new Aggregate(houseId, rs.getLong("min_ts_start"), rs.getLong("max_ts_end"),
|
(rs, rowNum) -> new Aggregate(houseId, rs.getLong("min_ts_start"), rs.getLong("max_ts_end"),
|
||||||
rs.getLong("sum_produced"), rs.getLong("sum_obtained"), rs.getLong("sum_injected")),
|
rs.getLong("sum_produced"), rs.getLong("sum_obtained"), rs.getLong("sum_injected")),
|
||||||
houseId ,timestampStart, timestampEnd);
|
houseId ,timestampStart, timestampEnd);
|
||||||
|
} else {
|
||||||
|
aggregates = jdbcTemplate.query(
|
||||||
|
"SELECT MIN(timestamp_start) AS min_ts_start, MAX(timestamp_end) AS max_ts_end, SUM(produced_energy * ?)/3600 AS sum_produced, SUM(GREATEST(obtained_energy + produced_energy - injected_energy - ? * produced_energy, 0))/3600 AS sum_obtained, SUM(ABS(LEAST(obtained_energy + produced_energy - injected_energy - ? * produced_energy, 0)))/3600 AS sum_injected FROM volkszaehler.tobias_aggregate2 WHERE house_id=? AND timestamp_start>=? AND timestamp_end<=?;",
|
||||||
|
(rs, rowNum) -> new Aggregate(houseId, rs.getLong("min_ts_start"), rs.getLong("max_ts_end"),
|
||||||
|
rs.getLong("sum_produced"), rs.getLong("sum_obtained"), rs.getLong("sum_injected")),
|
||||||
|
solarFactor, solarFactor, solarFactor, houseId ,timestampStart, timestampEnd);
|
||||||
|
}
|
||||||
if (aggregates.size() != 1) {
|
if (aggregates.size() != 1) {
|
||||||
throw new RuntimeException("Interal error in SQL query.");
|
throw new RuntimeException("Interal error in SQL query.");
|
||||||
}
|
}
|
||||||
@ -75,7 +85,8 @@ class VzRestController {
|
|||||||
String getSummary2(@RequestParam(name = "timestampStart", defaultValue = "-1")long timestampStart,
|
String getSummary2(@RequestParam(name = "timestampStart", defaultValue = "-1")long timestampStart,
|
||||||
@RequestParam(name = "timestampEnd", defaultValue = "-1")long timestampEnd,
|
@RequestParam(name = "timestampEnd", defaultValue = "-1")long timestampEnd,
|
||||||
@RequestParam(name = "duration", defaultValue = "")final String duration,
|
@RequestParam(name = "duration", defaultValue = "")final String duration,
|
||||||
@RequestParam("houseId")final int houseId) {
|
@RequestParam("houseId")final int houseId,
|
||||||
|
@RequestParam(name = "solarFactor", defaultValue = "1.0")final float solarFactor) {
|
||||||
|
|
||||||
if (!"".equals(duration)) {
|
if (!"".equals(duration)) {
|
||||||
final Duration dur = Duration.parse(duration);
|
final Duration dur = Duration.parse(duration);
|
||||||
@ -102,7 +113,7 @@ class VzRestController {
|
|||||||
for (EnergyPrice price : prices) {
|
for (EnergyPrice price : prices) {
|
||||||
final long tsStart = Math.max(price.getTimestampStart(), timestampStart);
|
final long tsStart = Math.max(price.getTimestampStart(), timestampStart);
|
||||||
final long tsEnd = Math.min(price.getTimestampEnd(), timestampEnd);
|
final long tsEnd = Math.min(price.getTimestampEnd(), timestampEnd);
|
||||||
final Sums sums = getData2(tsStart, tsEnd, houseId);
|
final Sums sums = getData(tsStart, tsEnd, houseId, solarFactor);
|
||||||
savedMoney += (float)(sums.getProduced() - sums.getInjected())/1000000 * price.getPrice();
|
savedMoney += (float)(sums.getProduced() - sums.getInjected())/1000000 * price.getPrice();
|
||||||
totalProduced += sums.getProduced();
|
totalProduced += sums.getProduced();
|
||||||
totalObtained += sums.getObtained();
|
totalObtained += sums.getObtained();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user