Aktueller stand
This commit is contained in:
parent
da12fcfee1
commit
4787d0dd2d
15
sqls.txt
15
sqls.txt
@ -15,4 +15,17 @@ SELECT SUM(value) FROM volkszaehler.data WHERE channel_id=4 AND value < 1.0 AND
|
||||
|
||||
SELECT * FROM volkszaehler.data WHERE channel_id=4 AND timestamp>=1704063600000 AND timestamp<=1735686000000 AND value>0 ORDER BY timestamp;
|
||||
|
||||
SELECT timestamp FROM volkszaehler.data WHERE channel_id=4 AND timestamp >= 1740697200000 ORDER BY timestamp
|
||||
SELECT timestamp FROM volkszaehler.data WHERE channel_id=4 AND timestamp >= 1740697200000 ORDER BY timestamp
|
||||
|
||||
--
|
||||
|
||||
SELECT * FROM tobias_aggregate WHERE channel_id=4 ORDER BY timestamp_start;
|
||||
|
||||
DELETE FROM volkszaehler.tobias_aggregate
|
||||
|
||||
SELECT MIN(timestamp_start), MAX(timestamp_end), SUM(sum_positive), SUM(sum_negative), COUNT(*) FROM volkszaehler.tobias_aggregate
|
||||
WHERE channel_id=4 AND timestamp_start>=1704063600000 AND timestamp_end<=1735686000000
|
||||
|
||||
ALTER TABLE tobias_aggregate MODIFY sum_positive BIGINT;
|
||||
|
||||
SELECT (timestamp - 1653030000000) AS TS, value from data where timestamp>=1653030000000 and timestamp<=1653030124133 AND channel_id=4;
|
||||
@ -27,11 +27,11 @@ public class FillAggregateTableMain2 {
|
||||
private static class AggregateToSave {
|
||||
private final long startTs;
|
||||
private final long endTs;
|
||||
private final long valuePos;
|
||||
private final long valueNeg;
|
||||
private final double valuePos;
|
||||
private final double valueNeg;
|
||||
private final int channelId;
|
||||
|
||||
private AggregateToSave(long startTs, long endTs, long valuePos, long valueNeg, int channelId) {
|
||||
private AggregateToSave(long startTs, long endTs, double valuePos, double valueNeg, int channelId) {
|
||||
super();
|
||||
this.startTs = startTs;
|
||||
this.endTs = endTs;
|
||||
@ -48,11 +48,11 @@ public class FillAggregateTableMain2 {
|
||||
return endTs;
|
||||
}
|
||||
|
||||
private long getValuePos() {
|
||||
private double getValuePos() {
|
||||
return valuePos;
|
||||
}
|
||||
|
||||
private long getValueNeg() {
|
||||
private double getValueNeg() {
|
||||
return valueNeg;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class FillAggregateTableMain2 {
|
||||
processChannel(startTimeStamp, finalEndTimeStamp, 60*1000, channelId, con);
|
||||
}
|
||||
System.out.println("Saving... " + SAVELIST.size());
|
||||
// saveValues(con);
|
||||
saveValues(con);
|
||||
// for (AggregateToSave ats : SAVELIST) {
|
||||
// saveValues(con, ats.startTs, ats.endTs, ats.channelId, new long[] {ats.valuePos, ats.valueNeg});
|
||||
// System.out.println("####");
|
||||
@ -101,11 +101,11 @@ public class FillAggregateTableMain2 {
|
||||
while (noNextRecord || (currentTimestamp <= endTimestamp && rs.next())) {
|
||||
noNextRecord = false;
|
||||
final long timestamp = rs.getLong("timestamp");
|
||||
final long value;
|
||||
final double value;
|
||||
if (rs.getDouble("value") >= 0 && rs.getDouble("value") < 1) {
|
||||
value = 0;
|
||||
value = 0.0;
|
||||
} else {
|
||||
value = rs.getLong("value");
|
||||
value = rs.getDouble("value");
|
||||
}
|
||||
final long tsDiff;
|
||||
if (timestamp < intervalEndTimestamp) {
|
||||
@ -133,7 +133,7 @@ public class FillAggregateTableMain2 {
|
||||
(intervalPos/3600) + " / " +
|
||||
(intervalNeg/3600));
|
||||
}
|
||||
SAVELIST.add(new AggregateToSave(intervalStartTimestamp, intervalEndTimestamp, intervalPos/3600, intervalNeg/3600, channelId));
|
||||
SAVELIST.add(new AggregateToSave(intervalStartTimestamp, intervalEndTimestamp, ((double)intervalPos)/3600, ((double)intervalNeg)/3600, channelId));
|
||||
intervalStartTimestamp += interval;
|
||||
intervalEndTimestamp += interval;
|
||||
currentTimestamp = intervalStartTimestamp;
|
||||
@ -181,8 +181,8 @@ public class FillAggregateTableMain2 {
|
||||
stmt.setInt(1, ats.channelId);
|
||||
stmt.setLong(2, ats.startTs);
|
||||
stmt.setLong(3, ats.endTs);
|
||||
stmt.setLong(4, ats.valuePos);
|
||||
stmt.setLong(5, ats.valueNeg);
|
||||
stmt.setDouble(4, ats.valuePos);
|
||||
stmt.setDouble(5, ats.valueNeg);
|
||||
stmt.addBatch();
|
||||
i++;
|
||||
if (i % 100000 == 0) {
|
||||
|
||||
@ -47,8 +47,8 @@ class VzRestController {
|
||||
channelId ,timestampStart, timestampEnd);
|
||||
long firstTimestamp = Long.MAX_VALUE;
|
||||
long lastTimestamp = Long.MIN_VALUE;
|
||||
long sumPos = 0;
|
||||
long sumNeg = 0;
|
||||
double sumPos = 0;
|
||||
double sumNeg = 0;
|
||||
log.info("Number of aggregates: " + aggregates.size());
|
||||
for (Aggregate ag : aggregates) {
|
||||
if (ag.getTimestampStart() < firstTimestamp) {
|
||||
@ -60,11 +60,14 @@ class VzRestController {
|
||||
sumPos += ag.getSumPositive();
|
||||
sumNeg += ag.getSumNegative();
|
||||
}
|
||||
sumPos /= 3600;
|
||||
sumNeg /= 3600;
|
||||
log.info("sumPos: " + sumPos + " / sumNeg: " + sumNeg);
|
||||
log.info("timestampStart: " + timestampStart);
|
||||
log.info("timestampEnd: " + timestampEnd);
|
||||
log.info("firstTimestamp: " + firstTimestamp);
|
||||
log.info("lastTimestamp: " + lastTimestamp);
|
||||
|
||||
if (timestampStart < firstTimestamp ) {
|
||||
final Sums startSums = getSums(timestampStart, firstTimestamp, channelId);
|
||||
sumPos += startSums.getSumPositive();
|
||||
@ -81,6 +84,14 @@ class VzRestController {
|
||||
return new Sums(sumPos, sumNeg);
|
||||
}
|
||||
|
||||
@GetMapping("/data/sums2")
|
||||
Sums getData2(@RequestParam("timestampStart")final long timestampStart,
|
||||
@RequestParam("timestampEnd")final long timestampEnd,
|
||||
@RequestParam("channelId")final int channelId) {
|
||||
final Sums startSums = getSums(timestampStart, timestampEnd, channelId);
|
||||
return startSums;
|
||||
}
|
||||
|
||||
@GetMapping("/test/{name}")
|
||||
String hello(@PathVariable("name")final String name) {
|
||||
return "Hello " + name + "!";
|
||||
@ -95,8 +106,8 @@ class VzRestController {
|
||||
final long endTimestamp,
|
||||
final int channelId) {
|
||||
long currentTimestamp = startTimestamp;
|
||||
long wattMillisecondsPos = 0;
|
||||
long wattMillisecondsNeg = 0;
|
||||
double wattMillisecondsPos = 0;
|
||||
double wattMillisecondsNeg = 0;
|
||||
|
||||
while (currentTimestamp < endTimestamp) {
|
||||
final List<Data> datas = jdbcTemplateWithLimitedRows.query("SELECT * FROM volkszaehler.data WHERE channel_id=? AND timestamp>? ORDER BY timestamp;",
|
||||
@ -107,7 +118,7 @@ class VzRestController {
|
||||
{
|
||||
final long tsDiff = Math.min(data.getTimestamp() - currentTimestamp, endTimestamp - currentTimestamp);
|
||||
currentTimestamp = data.getTimestamp();
|
||||
if (data.getValue() > 0.0) {
|
||||
if (data.getValue() > 1.0) {
|
||||
wattMillisecondsPos += (data.getValue() * tsDiff);
|
||||
}
|
||||
if (data.getValue() < 0.0) {
|
||||
|
||||
@ -1,29 +1,26 @@
|
||||
package info.peper.vz.rest.bo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Sums implements Serializable {
|
||||
private static final long serialVersionUID = -1816023197422851264L;
|
||||
private final long sumPositive;
|
||||
private final long sumNegative;
|
||||
public Sums(long sumPositive, long sumNegative) {
|
||||
private final double sumPositive;
|
||||
private final double sumNegative;
|
||||
public Sums(double sumPositive, double sumNegative) {
|
||||
super();
|
||||
this.sumPositive = sumPositive;
|
||||
this.sumNegative = sumNegative;
|
||||
}
|
||||
public long getSumPositive() {
|
||||
public double getSumPositive() {
|
||||
return sumPositive;
|
||||
}
|
||||
public long getSumNegative() {
|
||||
public double getSumNegative() {
|
||||
return sumNegative;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (sumNegative ^ (sumNegative >>> 32));
|
||||
result = prime * result + (int) (sumPositive ^ (sumPositive >>> 32));
|
||||
return result;
|
||||
return Objects.hash(sumNegative, sumPositive);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@ -34,11 +31,8 @@ public class Sums implements Serializable {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Sums other = (Sums) obj;
|
||||
if (sumNegative != other.sumNegative)
|
||||
return false;
|
||||
if (sumPositive != other.sumPositive)
|
||||
return false;
|
||||
return true;
|
||||
return Double.doubleToLongBits(sumNegative) == Double.doubleToLongBits(other.sumNegative)
|
||||
&& Double.doubleToLongBits(sumPositive) == Double.doubleToLongBits(other.sumPositive);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
BIN
test-tabelle.ods
Normal file
BIN
test-tabelle.ods
Normal file
Binary file not shown.
BIN
testdaten.ods
Normal file
BIN
testdaten.ods
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user