From c112a134b36b6946cae1a8aef9399a5befa96112 Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Sat, 2 Nov 2024 19:21:29 +0000 Subject: [PATCH] store and monitor total data size --- .../java/ru/r2cloud/cloud/InfluxDBClient.java | 5 +++++ .../java/ru/r2cloud/model/DecoderResult.java | 9 +++++++++ src/main/java/ru/r2cloud/model/Observation.java | 16 ++++++++++++++++ .../satellite/decoder/DecoderService.java | 1 + .../r2cloud/satellite/decoder/LoraDecoder.java | 5 ++++- .../satellite/decoder/TelemetryDecoder.java | 3 +++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/r2cloud/cloud/InfluxDBClient.java b/src/main/java/ru/r2cloud/cloud/InfluxDBClient.java index 03df9e59..45e581eb 100644 --- a/src/main/java/ru/r2cloud/cloud/InfluxDBClient.java +++ b/src/main/java/ru/r2cloud/cloud/InfluxDBClient.java @@ -94,6 +94,11 @@ public void send(Observation obs, Satellite satellite) { frames = 0L; } metric.append(",numberOfDecodedPackets=").append(frames); + Long totalSize = obs.getTotalSize(); + if (totalSize == null) { + totalSize = 0L; + } + metric.append(",totalSize=").append(totalSize); metric.append(",duration=").append(obs.getEndTimeMillis() - obs.getStartTimeMillis()); metric.append(" ").append(obs.getStartTimeMillis()).append("000000"); // nanoseconds diff --git a/src/main/java/ru/r2cloud/model/DecoderResult.java b/src/main/java/ru/r2cloud/model/DecoderResult.java index 92eaea49..8c38bfde 100644 --- a/src/main/java/ru/r2cloud/model/DecoderResult.java +++ b/src/main/java/ru/r2cloud/model/DecoderResult.java @@ -9,9 +9,18 @@ public class DecoderResult { private String channelA; private String channelB; private Long numberOfDecodedPackets = 0L; + private Long totalSize = 0L; private File imagePath; private File dataPath; + + public Long getTotalSize() { + return totalSize; + } + + public void setTotalSize(Long totalSize) { + this.totalSize = totalSize; + } public File getRawPath() { return rawPath; diff --git a/src/main/java/ru/r2cloud/model/Observation.java b/src/main/java/ru/r2cloud/model/Observation.java index ae79ee60..a66c5751 100644 --- a/src/main/java/ru/r2cloud/model/Observation.java +++ b/src/main/java/ru/r2cloud/model/Observation.java @@ -30,6 +30,7 @@ public class Observation { private String channelA; private String channelB; private Long numberOfDecodedPackets; + private Long totalSize = 0L; private String rawURL; private File rawPath; @@ -203,6 +204,14 @@ public void setChannelB(String channelB) { this.channelB = channelB; } + public Long getTotalSize() { + return totalSize; + } + + public void setTotalSize(Long totalSize) { + this.totalSize = totalSize; + } + public Long getNumberOfDecodedPackets() { return numberOfDecodedPackets; } @@ -307,6 +316,10 @@ public static Observation fromJson(JsonObject meta) { if (numberOfDecodedPackets != null) { result.setNumberOfDecodedPackets(numberOfDecodedPackets.asLong()); } + JsonValue totalSize = meta.get("totalSize"); + if (totalSize != null) { + result.setTotalSize(totalSize.asLong()); + } result.setRawURL(meta.getString("rawURL", null)); result.setaURL(meta.getString("aURL", null)); result.setSpectogramURL(meta.getString("spectogramURL", null)); @@ -352,6 +365,9 @@ public JsonObject toJson(SignedURL signed) { if (getNumberOfDecodedPackets() != null) { json.add("numberOfDecodedPackets", getNumberOfDecodedPackets()); } + if (totalSize != null) { + json.add("totalSize", getTotalSize()); + } addNullable("rawURL", getRawURL(), signed, json); addNullable("aURL", getaURL(), signed, json); addNullable("spectogramURL", getSpectogramURL(), signed, json); diff --git a/src/main/java/ru/r2cloud/satellite/decoder/DecoderService.java b/src/main/java/ru/r2cloud/satellite/decoder/DecoderService.java index 9c471857..6f1edc1e 100644 --- a/src/main/java/ru/r2cloud/satellite/decoder/DecoderService.java +++ b/src/main/java/ru/r2cloud/satellite/decoder/DecoderService.java @@ -150,6 +150,7 @@ private boolean decodeInternally(File rawFile, Observation observation) { observation.setChannelA(result.getChannelA()); observation.setChannelB(result.getChannelB()); observation.setNumberOfDecodedPackets(result.getNumberOfDecodedPackets()); + observation.setTotalSize(result.getTotalSize()); observation.setImagePath(result.getImagePath()); observation.setDataPath(result.getDataPath()); observation.setStatus(ObservationStatus.DECODED); diff --git a/src/main/java/ru/r2cloud/satellite/decoder/LoraDecoder.java b/src/main/java/ru/r2cloud/satellite/decoder/LoraDecoder.java index c9025137..c5f01288 100644 --- a/src/main/java/ru/r2cloud/satellite/decoder/LoraDecoder.java +++ b/src/main/java/ru/r2cloud/satellite/decoder/LoraDecoder.java @@ -31,11 +31,14 @@ public DecoderResult decode(File rawFile, Observation request, final Transmitter result.setRawPath(null); long numberOfDecodedPackets = 0; try (BeaconInputStream bis = new BeaconInputStream<>(new BufferedInputStream(new FileInputStream(rawFile)), beacon)) { + long totalSize = 0; while (bis.hasNext()) { - bis.next(); + Beacon beacon = bis.next(); numberOfDecodedPackets++; + totalSize += beacon.getRawData().length; } result.setNumberOfDecodedPackets(numberOfDecodedPackets); + result.setTotalSize(totalSize); } catch (IOException e) { LOG.error("unable to read lora beacons", e); diff --git a/src/main/java/ru/r2cloud/satellite/decoder/TelemetryDecoder.java b/src/main/java/ru/r2cloud/satellite/decoder/TelemetryDecoder.java index aaa90c45..a1259bc2 100644 --- a/src/main/java/ru/r2cloud/satellite/decoder/TelemetryDecoder.java +++ b/src/main/java/ru/r2cloud/satellite/decoder/TelemetryDecoder.java @@ -56,6 +56,7 @@ public DecoderResult decode(File rawIq, Observation req, final Transmitter trans } long numberOfDecodedPackets = 0; + long totalSize = 0; float sampleRate = req.getSampleRate(); File binFile = new File(config.getTempDirectory(), req.getId() + ".bin"); List> input = null; @@ -79,6 +80,7 @@ public DecoderResult decode(File rawIq, Observation req, final Transmitter trans next.setRxMeta(meta); beacons.add(next); numberOfDecodedPackets++; + totalSize += next.getRawData().length; } } finally { Util.closeQuietly(currentInput); @@ -108,6 +110,7 @@ public DecoderResult decode(File rawIq, Observation req, final Transmitter trans return result; } result.setNumberOfDecodedPackets(numberOfDecodedPackets); + result.setTotalSize(totalSize); if (numberOfDecodedPackets <= 0) { Util.deleteQuietly(binFile); } else {