Skip to content

Commit

Permalink
Merge pull request #37 from Anant/fix/cloud_cover_frequency
Browse files Browse the repository at this point in the history
fix cloud cover frequency agg
  • Loading branch information
anomnaco authored Sep 13, 2024
2 parents daf5c0f + c4fc753 commit de6d6ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
45 changes: 26 additions & 19 deletions src/main/java/com/datastax/oss/cass_stac/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,32 @@
@Getter
@Setter
public class Item {
@PrimaryKey
private ItemPrimaryKey id;
private String collection;
private Instant datetime;
private ByteBuffer geometry;
private Map<String, String> indexed_properties_text;
private Map<String, Number> indexed_properties_double;
private Map<String, Boolean> indexed_properties_boolean;
private Map<String, Instant> indexed_properties_timestamp;
private String properties;
private String additional_attributes;
private CqlVector<Float> centroid;
@PrimaryKey
private ItemPrimaryKey id;
private String collection;
private Instant datetime;
private ByteBuffer geometry;
private Map<String, String> indexed_properties_text;
private Map<String, Number> indexed_properties_double;
private Map<String, Boolean> indexed_properties_boolean;
private Map<String, Instant> indexed_properties_timestamp;
private String properties;
private String additional_attributes;
private CqlVector<Float> centroid;

public Double getCloudCover() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
public Double getCloudCover() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());

Map<String, Object> map = objectMapper.readValue(properties, new TypeReference<>() {
});
Object value = map.get("eo:cloud_cover");
return value != null ? Double.parseDouble(value.toString()) : null;
}
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()));
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Getter;

import java.time.*;
import java.util.ArrayList;
import java.time.Instant;
import java.time.Month;
import java.time.Year;
import java.time.ZoneId;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -68,10 +70,7 @@ public Aggregation apply(List<Item> items, List<AggregateRequest.Range> ranges)
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
List<AggregateRequest.Range> _ranges = new ArrayList<>();
if(ranges == null)
_ranges.add(new AggregateRequest.Range());
else _ranges = ranges;
List<AggregateRequest.Range> _ranges = ranges == null ? List.of(new AggregateRequest.Range()) : ranges;
return _ranges.stream()
.filter(range -> range.contains(value)).findFirst();
}, Collectors.counting()));
Expand Down Expand Up @@ -119,7 +118,7 @@ public Aggregation apply(List<Item> items, List<AggregateRequest.Range> ranges)
@Override
public Aggregation apply(List<Item> items, List<AggregateRequest.Range> ranges) {
Map<Integer, Long> frequencyMap = items.stream().collect(Collectors.groupingBy(item ->
Year.from(item.getDatetime().atZone(ZoneId.systemDefault())).getValue(), Collectors.counting()));
Year.from(item.getDatetime().atZone(ZoneId.systemDefault())).getValue(), Collectors.counting()));
List<Aggregation.Bucket> buckets =
frequencyMap.entrySet().stream()
.map(entry -> {
Expand Down

0 comments on commit de6d6ce

Please sign in to comment.