Skip to content

Commit

Permalink
store and monitor total data size
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Nov 2, 2024
1 parent 086aae8 commit c112a13
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/ru/r2cloud/cloud/InfluxDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ru/r2cloud/model/DecoderResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/ru/r2cloud/model/Observation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/ru/r2cloud/satellite/decoder/LoraDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ public DecoderResult decode(File rawFile, Observation request, final Transmitter
result.setRawPath(null);
long numberOfDecodedPackets = 0;
try (BeaconInputStream<? extends Beacon> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BeaconSource<? extends Beacon>> input = null;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c112a13

Please sign in to comment.