Aktueller stand
This commit is contained in:
parent
da12fcfee1
commit
4787d0dd2d
13
sqls.txt
13
sqls.txt
@ -16,3 +16,16 @@ 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 * 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 static class AggregateToSave {
|
||||||
private final long startTs;
|
private final long startTs;
|
||||||
private final long endTs;
|
private final long endTs;
|
||||||
private final long valuePos;
|
private final double valuePos;
|
||||||
private final long valueNeg;
|
private final double valueNeg;
|
||||||
private final int channelId;
|
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();
|
super();
|
||||||
this.startTs = startTs;
|
this.startTs = startTs;
|
||||||
this.endTs = endTs;
|
this.endTs = endTs;
|
||||||
@ -48,11 +48,11 @@ public class FillAggregateTableMain2 {
|
|||||||
return endTs;
|
return endTs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getValuePos() {
|
private double getValuePos() {
|
||||||
return valuePos;
|
return valuePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getValueNeg() {
|
private double getValueNeg() {
|
||||||
return valueNeg;
|
return valueNeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public class FillAggregateTableMain2 {
|
|||||||
processChannel(startTimeStamp, finalEndTimeStamp, 60*1000, channelId, con);
|
processChannel(startTimeStamp, finalEndTimeStamp, 60*1000, channelId, con);
|
||||||
}
|
}
|
||||||
System.out.println("Saving... " + SAVELIST.size());
|
System.out.println("Saving... " + SAVELIST.size());
|
||||||
// saveValues(con);
|
saveValues(con);
|
||||||
// for (AggregateToSave ats : SAVELIST) {
|
// for (AggregateToSave ats : SAVELIST) {
|
||||||
// saveValues(con, ats.startTs, ats.endTs, ats.channelId, new long[] {ats.valuePos, ats.valueNeg});
|
// saveValues(con, ats.startTs, ats.endTs, ats.channelId, new long[] {ats.valuePos, ats.valueNeg});
|
||||||
// System.out.println("####");
|
// System.out.println("####");
|
||||||
@ -101,11 +101,11 @@ public class FillAggregateTableMain2 {
|
|||||||
while (noNextRecord || (currentTimestamp <= endTimestamp && rs.next())) {
|
while (noNextRecord || (currentTimestamp <= endTimestamp && rs.next())) {
|
||||||
noNextRecord = false;
|
noNextRecord = false;
|
||||||
final long timestamp = rs.getLong("timestamp");
|
final long timestamp = rs.getLong("timestamp");
|
||||||
final long value;
|
final double value;
|
||||||
if (rs.getDouble("value") >= 0 && rs.getDouble("value") < 1) {
|
if (rs.getDouble("value") >= 0 && rs.getDouble("value") < 1) {
|
||||||
value = 0;
|
value = 0.0;
|
||||||
} else {
|
} else {
|
||||||
value = rs.getLong("value");
|
value = rs.getDouble("value");
|
||||||
}
|
}
|
||||||
final long tsDiff;
|
final long tsDiff;
|
||||||
if (timestamp < intervalEndTimestamp) {
|
if (timestamp < intervalEndTimestamp) {
|
||||||
@ -133,7 +133,7 @@ public class FillAggregateTableMain2 {
|
|||||||
(intervalPos/3600) + " / " +
|
(intervalPos/3600) + " / " +
|
||||||
(intervalNeg/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;
|
intervalStartTimestamp += interval;
|
||||||
intervalEndTimestamp += interval;
|
intervalEndTimestamp += interval;
|
||||||
currentTimestamp = intervalStartTimestamp;
|
currentTimestamp = intervalStartTimestamp;
|
||||||
@ -181,8 +181,8 @@ public class FillAggregateTableMain2 {
|
|||||||
stmt.setInt(1, ats.channelId);
|
stmt.setInt(1, ats.channelId);
|
||||||
stmt.setLong(2, ats.startTs);
|
stmt.setLong(2, ats.startTs);
|
||||||
stmt.setLong(3, ats.endTs);
|
stmt.setLong(3, ats.endTs);
|
||||||
stmt.setLong(4, ats.valuePos);
|
stmt.setDouble(4, ats.valuePos);
|
||||||
stmt.setLong(5, ats.valueNeg);
|
stmt.setDouble(5, ats.valueNeg);
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
i++;
|
i++;
|
||||||
if (i % 100000 == 0) {
|
if (i % 100000 == 0) {
|
||||||
|
|||||||
@ -47,8 +47,8 @@ class VzRestController {
|
|||||||
channelId ,timestampStart, timestampEnd);
|
channelId ,timestampStart, timestampEnd);
|
||||||
long firstTimestamp = Long.MAX_VALUE;
|
long firstTimestamp = Long.MAX_VALUE;
|
||||||
long lastTimestamp = Long.MIN_VALUE;
|
long lastTimestamp = Long.MIN_VALUE;
|
||||||
long sumPos = 0;
|
double sumPos = 0;
|
||||||
long sumNeg = 0;
|
double sumNeg = 0;
|
||||||
log.info("Number of aggregates: " + aggregates.size());
|
log.info("Number of aggregates: " + aggregates.size());
|
||||||
for (Aggregate ag : aggregates) {
|
for (Aggregate ag : aggregates) {
|
||||||
if (ag.getTimestampStart() < firstTimestamp) {
|
if (ag.getTimestampStart() < firstTimestamp) {
|
||||||
@ -60,11 +60,14 @@ class VzRestController {
|
|||||||
sumPos += ag.getSumPositive();
|
sumPos += ag.getSumPositive();
|
||||||
sumNeg += ag.getSumNegative();
|
sumNeg += ag.getSumNegative();
|
||||||
}
|
}
|
||||||
|
sumPos /= 3600;
|
||||||
|
sumNeg /= 3600;
|
||||||
log.info("sumPos: " + sumPos + " / sumNeg: " + sumNeg);
|
log.info("sumPos: " + sumPos + " / sumNeg: " + sumNeg);
|
||||||
log.info("timestampStart: " + timestampStart);
|
log.info("timestampStart: " + timestampStart);
|
||||||
log.info("timestampEnd: " + timestampEnd);
|
log.info("timestampEnd: " + timestampEnd);
|
||||||
log.info("firstTimestamp: " + firstTimestamp);
|
log.info("firstTimestamp: " + firstTimestamp);
|
||||||
log.info("lastTimestamp: " + lastTimestamp);
|
log.info("lastTimestamp: " + lastTimestamp);
|
||||||
|
|
||||||
if (timestampStart < firstTimestamp ) {
|
if (timestampStart < firstTimestamp ) {
|
||||||
final Sums startSums = getSums(timestampStart, firstTimestamp, channelId);
|
final Sums startSums = getSums(timestampStart, firstTimestamp, channelId);
|
||||||
sumPos += startSums.getSumPositive();
|
sumPos += startSums.getSumPositive();
|
||||||
@ -81,6 +84,14 @@ class VzRestController {
|
|||||||
return new Sums(sumPos, sumNeg);
|
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}")
|
@GetMapping("/test/{name}")
|
||||||
String hello(@PathVariable("name")final String name) {
|
String hello(@PathVariable("name")final String name) {
|
||||||
return "Hello " + name + "!";
|
return "Hello " + name + "!";
|
||||||
@ -95,8 +106,8 @@ class VzRestController {
|
|||||||
final long endTimestamp,
|
final long endTimestamp,
|
||||||
final int channelId) {
|
final int channelId) {
|
||||||
long currentTimestamp = startTimestamp;
|
long currentTimestamp = startTimestamp;
|
||||||
long wattMillisecondsPos = 0;
|
double wattMillisecondsPos = 0;
|
||||||
long wattMillisecondsNeg = 0;
|
double wattMillisecondsNeg = 0;
|
||||||
|
|
||||||
while (currentTimestamp < endTimestamp) {
|
while (currentTimestamp < endTimestamp) {
|
||||||
final List<Data> datas = jdbcTemplateWithLimitedRows.query("SELECT * FROM volkszaehler.data WHERE channel_id=? AND timestamp>? ORDER BY timestamp;",
|
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);
|
final long tsDiff = Math.min(data.getTimestamp() - currentTimestamp, endTimestamp - currentTimestamp);
|
||||||
currentTimestamp = data.getTimestamp();
|
currentTimestamp = data.getTimestamp();
|
||||||
if (data.getValue() > 0.0) {
|
if (data.getValue() > 1.0) {
|
||||||
wattMillisecondsPos += (data.getValue() * tsDiff);
|
wattMillisecondsPos += (data.getValue() * tsDiff);
|
||||||
}
|
}
|
||||||
if (data.getValue() < 0.0) {
|
if (data.getValue() < 0.0) {
|
||||||
|
|||||||
@ -1,29 +1,26 @@
|
|||||||
package info.peper.vz.rest.bo;
|
package info.peper.vz.rest.bo;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Sums implements Serializable {
|
public class Sums implements Serializable {
|
||||||
private static final long serialVersionUID = -1816023197422851264L;
|
private static final long serialVersionUID = -1816023197422851264L;
|
||||||
private final long sumPositive;
|
private final double sumPositive;
|
||||||
private final long sumNegative;
|
private final double sumNegative;
|
||||||
public Sums(long sumPositive, long sumNegative) {
|
public Sums(double sumPositive, double sumNegative) {
|
||||||
super();
|
super();
|
||||||
this.sumPositive = sumPositive;
|
this.sumPositive = sumPositive;
|
||||||
this.sumNegative = sumNegative;
|
this.sumNegative = sumNegative;
|
||||||
}
|
}
|
||||||
public long getSumPositive() {
|
public double getSumPositive() {
|
||||||
return sumPositive;
|
return sumPositive;
|
||||||
}
|
}
|
||||||
public long getSumNegative() {
|
public double getSumNegative() {
|
||||||
return sumNegative;
|
return sumNegative;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hash(sumNegative, sumPositive);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (int) (sumNegative ^ (sumNegative >>> 32));
|
|
||||||
result = prime * result + (int) (sumPositive ^ (sumPositive >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
@ -34,11 +31,8 @@ public class Sums implements Serializable {
|
|||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Sums other = (Sums) obj;
|
Sums other = (Sums) obj;
|
||||||
if (sumNegative != other.sumNegative)
|
return Double.doubleToLongBits(sumNegative) == Double.doubleToLongBits(other.sumNegative)
|
||||||
return false;
|
&& Double.doubleToLongBits(sumPositive) == Double.doubleToLongBits(other.sumPositive);
|
||||||
if (sumPositive != other.sumPositive)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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