Skip to content

Commit

Permalink
Merge pull request #38 from Anant/fix/cloud_cover_frequency
Browse files Browse the repository at this point in the history
fix cloud cover agg
  • Loading branch information
anomnaco authored Sep 16, 2024
2 parents de6d6ce + 13a6b1a commit 8a71c87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/main/java/com/datastax/oss/cass_stac/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public Double getCloudCover() throws JsonProcessingException {

Map<String, Object> map = objectMapper.readValue(properties, new TypeReference<>() {
});
Object value = map.get("eo:cloud_cover");
if (value != null) {
try {
return Double.parseDouble(value.toString());
} catch (NumberFormatException e) {
return Double.longBitsToDouble(Long.getLong(value.toString()));
}
if (properties == null) {
return -1.0;
}
Object value = map.getOrDefault("eo:cloud_cover", -1.0);
try {
return Double.parseDouble(value.toString());
} catch (NumberFormatException e) {
return Double.longBitsToDouble(Long.getLong(value.toString()));
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Data
@Builder
Expand Down Expand Up @@ -41,18 +40,16 @@ public class AggregateRequest {
@NoArgsConstructor
@AllArgsConstructor
public static class Range {
private Optional<Double> from = Optional.of(Double.MIN_VALUE);
private Optional<Double> to = Optional.of(Double.MAX_VALUE);
private Double from = 0.0;
private Double to = 100.0;


public boolean contains(double value) {
return value >= from.orElse(Double.MIN_VALUE) && value < to.orElse(Double.MAX_VALUE);
return value >= from && value <= to;
}

public String toString() {
String _from = from.isPresent() ? from.get() == Double.MIN_VALUE ? "*" : from.get().toString() : "*";
String _to = to.isPresent() ? to.get() == Double.MAX_VALUE ? "*" : to.get().toString() : "*";
return _from + "-" + _to;
return from + "-" + to;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ public Aggregation apply(List<Item> items, List<AggregateRequest.Range> ranges)
bucket.setKey(entry.getKey().get().toString());
bucket.setFrequency(Math.toIntExact(entry.getValue()));
bucket.setData_type("numeric");
if (entry.getKey().get().getFrom().isPresent())
bucket.setFrom(entry.getKey().get().getFrom().orElse(null));
if (entry.getKey().get().getTo().isPresent())
bucket.setTo(entry.getKey().get().getTo().orElse(null));
bucket.setFrom(entry.getKey().get().getFrom());
bucket.setTo(entry.getKey().get().getTo());
}
return bucket;
})
Expand Down

0 comments on commit 8a71c87

Please sign in to comment.