Skip to content

Commit

Permalink
#287: Change logic for data previews to be modular
Browse files Browse the repository at this point in the history
  • Loading branch information
benitsch committed Jul 5, 2024
1 parent dcbcf40 commit 8499865
Show file tree
Hide file tree
Showing 29 changed files with 549 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
package io.redlink.more.studymanager.core.component;

import io.redlink.more.studymanager.core.exception.ConfigurationValidationException;
import io.redlink.more.studymanager.core.io.TimeRange;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.DataView;
import io.redlink.more.studymanager.core.ui.DataViewInfo;

import java.util.Set;

public abstract class Observation<C extends ObservationProperties> extends Component<C> {

Expand All @@ -20,6 +25,15 @@ protected Observation(MoreObservationSDK sdk, C properties) throws Configuration
this.sdk = sdk;
}

public Set<DataViewInfo> listViews() {
return Set.of();
}

public DataView getView(String viewId, Integer studyGroupId, Integer participantId, TimeRange timerange) {
return null;
}


@Override
public void activate() {
// no action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.redlink.more.studymanager.core.measurement.MeasurementSet;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.DataPreview;

public abstract class ObservationFactory<C extends Observation<P>, P extends ObservationProperties> extends ComponentFactory<C, P> {
public abstract C create(MoreObservationSDK sdk, P properties) throws ConfigurationValidationException;
Expand All @@ -26,8 +25,6 @@ public Class<ObservationProperties> getPropertyClass() {

public abstract MeasurementSet getMeasurementSet();

public abstract DataPreview getDataPreview();

@Deprecated
public Boolean getHidden() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record MeasurementSet(String id, Set<Measurement> values) {

public MeasurementSet {
if (id == null || values == null) {
throw new IllegalArgumentException("Is and values must not be null");
throw new IllegalArgumentException("Id and values must not be null");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
*/
package io.redlink.more.studymanager.core.sdk;

import io.redlink.more.studymanager.core.io.TimeRange;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.ui.DataViewRow;
import io.redlink.more.studymanager.core.ui.ViewConfig;

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

Expand All @@ -22,5 +26,7 @@ public interface MoreObservationSDK extends MorePlatformSDK {

void storeDataPoint(Integer participantId, String observationType, Map data);

List<DataViewRow> queryData(ViewConfig viewConfig, Integer participantId, TimeRange timerange);

int getObservationId();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.ui;

import java.util.List;

public record DataView(
DataViewInfo viewInfo,
ChartType chartType,
List<String> labels,
List<DataViewRow> data
) {
public enum ChartType {
LINE,
BAR,
PIE
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.ui;

public record DataViewInfo(
String id,
String title,
String description
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.ui;

import java.util.List;

public record DataViewRow(
String label,
List<Integer> values
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.ui;

import java.util.List;

public record ViewConfig(
List<Filter> filters,
Aggregation rowAggregation,
Aggregation seriesAggregation,
Operation operation
) {

public record Filter(

) {
}

public enum Aggregation {
TIME,
STUDY_GROUP,
PARTICIPANT,
}

public record Operation(
Operator operator,
String field
) {
}

public enum Operator {
AVG,
SUM,
MIN,
MAX,
COUNT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
package io.redlink.more.studymanager.component.observation;

import io.redlink.more.studymanager.component.observation.measurement.GenericMeasurementSets;
import io.redlink.more.studymanager.component.observation.preview.GenericDataPreview;
import io.redlink.more.studymanager.core.component.Observation;
import io.redlink.more.studymanager.core.exception.ConfigurationValidationException;
import io.redlink.more.studymanager.core.factory.ObservationFactory;
import io.redlink.more.studymanager.core.measurement.MeasurementSet;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.DataPreview;

public class AccMobileObservationFactory<C extends Observation<P>, P extends ObservationProperties>
extends ObservationFactory<C, P> {
Expand Down Expand Up @@ -46,7 +44,4 @@ public AccMobileObservation create(MoreObservationSDK sdk, ObservationProperties
public MeasurementSet getMeasurementSet() {
return GenericMeasurementSets.ACCELEROMETER;
}

@Override
public DataPreview getDataPreview() { return GenericDataPreview.ACCELEROMETER; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
package io.redlink.more.studymanager.component.observation;

import io.redlink.more.studymanager.component.observation.measurement.GenericMeasurementSets;
import io.redlink.more.studymanager.component.observation.preview.GenericDataPreview;
import io.redlink.more.studymanager.core.component.Observation;
import io.redlink.more.studymanager.core.exception.ConfigurationValidationException;
import io.redlink.more.studymanager.core.factory.ObservationFactory;
import io.redlink.more.studymanager.core.io.Visibility;
import io.redlink.more.studymanager.core.measurement.MeasurementSet;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.DataPreview;

public class ExternalObservationFactory<C extends Observation<P>, P extends ObservationProperties>
extends ObservationFactory<C, P> {
Expand Down Expand Up @@ -58,7 +56,4 @@ public Boolean getHidden() {
public Visibility getVisibility() {
return visibility;
}

@Override
public DataPreview getDataPreview() { return GenericDataPreview.NOT_SPECIFIED; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
package io.redlink.more.studymanager.component.observation;

import io.redlink.more.studymanager.component.observation.measurement.GenericMeasurementSets;
import io.redlink.more.studymanager.component.observation.preview.GenericDataPreview;
import io.redlink.more.studymanager.core.component.Observation;
import io.redlink.more.studymanager.core.exception.ConfigurationValidationException;
import io.redlink.more.studymanager.core.factory.ObservationFactory;
import io.redlink.more.studymanager.core.measurement.MeasurementSet;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.DataPreview;

public class GpsMobileObservationFactory<C extends Observation<P>, P extends ObservationProperties> extends ObservationFactory<C, P> {

Expand Down Expand Up @@ -47,7 +45,4 @@ public GpsMobileObservation create(MoreObservationSDK sdk, ObservationProperties
public MeasurementSet getMeasurementSet() {
return GenericMeasurementSets.GEOLOCATION;
}

@Override
public DataPreview getDataPreview() { return GenericDataPreview.NOT_SPECIFIED; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,63 @@

import io.redlink.more.studymanager.core.component.Observation;
import io.redlink.more.studymanager.core.exception.ConfigurationValidationException;
import io.redlink.more.studymanager.core.io.TimeRange;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.*;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PolarVerityObservation<C extends ObservationProperties> extends Observation<C> {
public PolarVerityObservation(MoreObservationSDK sdk, C properties) throws ConfigurationValidationException {
super(sdk, properties);
}

private enum DataViewInfoType {
HEART_RATE("heartRate", "Heart rate", "Heart rate per participant over time.");

private final DataViewInfo dataViewInfo;

DataViewInfoType(String key, String displayName, String description) {
this.dataViewInfo = new DataViewInfo(key, displayName, description);
}

public DataViewInfo getDataViewInfo() {
return dataViewInfo;
}
}

public Set<DataViewInfo> listViews() {
return Stream.of(DataViewInfoType.values())
.map(DataViewInfoType::getDataViewInfo)
.collect(Collectors.toSet());
}

@Override
public DataView getView(String viewId, Integer studyGroupId, Integer participantId, TimeRange timerange) {
return switch (viewId) {
case "hr" -> createHeartRateView(studyGroupId, participantId, timerange);
default -> null;
};
}

private DataView createHeartRateView(Integer studyGroupId, Integer participantId, TimeRange timerange) {
var viewConfig = new ViewConfig(
List.of(),
ViewConfig.Aggregation.PARTICIPANT,
ViewConfig.Aggregation.TIME,
new ViewConfig.Operation(ViewConfig.Operator.AVG, "hr")
);

List<DataViewRow> rows = sdk.queryData(viewConfig, participantId, timerange);
return new DataView(
DataViewInfoType.HEART_RATE.getDataViewInfo(),
DataView.ChartType.LINE,
List.of(),
rows
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
package io.redlink.more.studymanager.component.observation;

import io.redlink.more.studymanager.component.observation.measurement.GenericMeasurementSets;
import io.redlink.more.studymanager.component.observation.preview.GenericDataPreview;
import io.redlink.more.studymanager.core.component.Observation;
import io.redlink.more.studymanager.core.exception.ConfigurationValidationException;
import io.redlink.more.studymanager.core.factory.ObservationFactory;
import io.redlink.more.studymanager.core.measurement.MeasurementSet;
import io.redlink.more.studymanager.core.properties.ObservationProperties;
import io.redlink.more.studymanager.core.sdk.MoreObservationSDK;
import io.redlink.more.studymanager.core.ui.DataPreview;

public class PolarVerityObservationFactory<C extends Observation<P>, P extends ObservationProperties> extends ObservationFactory<C, P> {

Expand Down Expand Up @@ -44,7 +42,4 @@ public PolarVerityObservation create(MoreObservationSDK sdk, ObservationProperti
public MeasurementSet getMeasurementSet() {
return GenericMeasurementSets.HEART_RATE;
}

@Override
public DataPreview getDataPreview() { return GenericDataPreview.HEART_RATE; }
}
Loading

0 comments on commit 8499865

Please sign in to comment.