org.openmhealth.schema.domain.omh.DataPoint Java Examples

The following examples show how to use org.openmhealth.schema.domain.omh.DataPoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataPointControllerIntegrationTests.java    From omh-dsu-ri with Apache License 2.0 6 votes vote down vote up
@Ignore("until access tokens are hooked up")
@Test
public void readDataShouldReturnDataPoint() throws Exception {

    DataPoint dataPoint = newDataPointBuilder().setBody(newKcalBurnedBody()).build();
    DataPointHeader header = dataPoint.getHeader();

    when(mockDataPointService.findOne(dataPoint.getHeader().getId())).thenReturn(Optional.of(dataPoint));

    mockMvc.perform(
            get(CONTROLLER_URI + "/" + dataPoint.getHeader().getId())
                    .accept(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().contentType(APPLICATION_JSON))
            .andExpect(jsonPath("$.header.id").value(header.getId()))
            .andExpect(jsonPath("$.header.creation_date_time").value(header.getCreationDateTime().toString()))
            .andExpect(jsonPath("$.header.schema_id.namespace").value(header.getSchemaId().getNamespace()))
            .andExpect(jsonPath("$.header.schema_id.name").value(header.getSchemaId().getName()))
            .andExpect(jsonPath("$.header.schema_id.version.major")
                    .value(header.getSchemaId().getVersion().getMajor()))
            .andExpect(jsonPath("$.header.schema_id.version.minor")
                    .value(header.getSchemaId().getVersion().getMinor()));
    // TODO add data assertions
}
 
Example #2
Source File: WithingsIntradayCaloriesBurnedDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
public void testIntradayCaloriesBurnedDataPoint(
        DataPoint<CaloriesBurned2> caloriesBurnedDataPoint,
        long expectedCaloriesBurnedValue,
        String expectedStartDateTimeString, Long expectedDuration) {

    CaloriesBurned2 expectedCaloriesBurned =
            new CaloriesBurned2.Builder(
                    KILOCALORIE.newUnitValue(expectedCaloriesBurnedValue),
                    ofStartDateTimeAndDuration(
                            OffsetDateTime.parse(expectedStartDateTimeString),
                            SECOND.newUnitValue(expectedDuration)))
                    .build();

    assertThat(caloriesBurnedDataPoint.getBody(), equalTo(expectedCaloriesBurned));
    assertThat(caloriesBurnedDataPoint.getHeader().getBodySchemaId(), equalTo(SCHEMA_ID));
    assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED));
    assertThat(caloriesBurnedDataPoint.getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
}
 
Example #3
Source File: MisfitSleepMeasureDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldSetModalityToSensedWhenAutoDetectedIsTrue() throws IOException {

    JsonNode node = objectMapper.readTree("{\n" +
            "    \"sleeps\": [\n" +
            "        {\n" +
            "            \"id\": \"54fa13a8440f705a7406845f\",\n" +
            "            \"autoDetected\": true,\n" +
            "            \"startTime\": \"2015-02-24T21:40:59-05:00\",\n" +
            "            \"duration\": 2580,\n" +
            "            \"sleepDetails\": [\n" +
            "                {\n" +
            "                    \"datetime\": \"2015-02-24T21:40:59-05:00\",\n" +
            "                    \"value\": 2\n" +
            "                }\n" +
            "            ]\n" +
            "        }\n" +
            "    ]\n" +
            "}");

    List<DataPoint<T>> dataPoints = getMapper().asDataPoints(node);

    assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED));
}
 
Example #4
Source File: MisfitSleepMeasureDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnEmptyListIfOnlyAwake() throws IOException {

    JsonNode node = objectMapper.readTree("{\n" +
            "    \"sleeps\": [\n" +
            "        {\n" +
            "            \"id\": \"54fa13a8440f705a7406845f\",\n" +
            "            \"autoDetected\": false,\n" +
            "            \"startTime\": \"2015-02-24T21:40:59-05:00\",\n" +
            "            \"duration\": 2580,\n" +
            "            \"sleepDetails\": [\n" +
            "                {\n" +
            "                    \"datetime\": \"2015-02-24T21:40:59-05:00\",\n" +
            "                    \"value\": 1\n" +
            "                }\n" +
            "            ]\n" +
            "        }\n" +
            "    ]\n" +
            "}");

    List<DataPoint<T>> dataPoints = getMapper().asDataPoints(node);

    assertThat(dataPoints, notNullValue());
    assertThat(dataPoints, empty());
}
 
Example #5
Source File: WithingsDailyStepCountDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
public void testDailyStepCountDataPoint(DataPoint<StepCount2> stepCountDataPoint, long expectedStepCountValue,
        String expectedStartDateString, String expectedEndDateString) {

    StepCount2 expectedStepCount = new StepCount2.Builder(
            expectedStepCountValue,
            ofStartDateTimeAndEndDateTime(
                    OffsetDateTime.parse(expectedStartDateString),
                    OffsetDateTime.parse(expectedEndDateString)))
            .build();

    StepCount2 stepCount = stepCountDataPoint.getBody();

    assertThat(stepCount, equalTo(expectedStepCount));
    assertThat(stepCountDataPoint.getHeader().getAcquisitionProvenance().getModality(), equalTo(SENSED));
    assertThat(stepCountDataPoint.getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(stepCountDataPoint.getHeader().getBodySchemaId(), equalTo(StepCount2.SCHEMA_ID));
}
 
Example #6
Source File: GoogleFitCaloriesBurnedDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Override
protected Optional<DataPoint<CaloriesBurned2>> asDataPoint(JsonNode listNode) {

    JsonNode listValueNode = asRequiredNode(listNode, "value");
    double caloriesBurnedValue = asRequiredDouble(listValueNode.get(0), "fpVal");

    CaloriesBurned2.Builder measureBuilder =
            new CaloriesBurned2.Builder(KILOCALORIE.newUnitValue(caloriesBurnedValue), getTimeFrame(listNode));

    CaloriesBurned2 caloriesBurned = measureBuilder.build();

    Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId");

    // Google Fit calories burned endpoint returns calories burned by basal metabolic rate (BMR), however these
    // are not activity related calories burned so we do not create a data point for values from this source
    if (originDataSourceId.isPresent()) {
        if (originDataSourceId.get().contains("bmr")) {
            return Optional.empty();
        }
    }

    return Optional.of(newDataPoint(caloriesBurned, originDataSourceId.orElse(null)));
}
 
Example #7
Source File: WithingsBodyHeightDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<BodyHeight>> actualDataPoints = mapper.asDataPoints(responseNode);

    BodyHeight expectedBodyHeight = new BodyHeight.Builder(new LengthUnitValue(METER, 1.93))
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-02-23T19:24:49Z"))
            .build();

    assertThat(actualDataPoints.get(0).getBody(), equalTo(expectedBodyHeight));

    DataPointHeader actualDataPointHeader = actualDataPoints.get(0).getHeader();
    assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(SCHEMA_ID));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get("external_id"),
            equalTo("320419189"));
}
 
Example #8
Source File: FitbitShim.java    From shimmer with Apache License 2.0 6 votes vote down vote up
/**
 * Each 'dayResponse', when normalized, will have a type->list[objects] for the day. So we collect each daily map to
 * create an aggregate map of the full time range.
 */
@SuppressWarnings("unchecked")
private ShimDataResponse aggregateNormalized(List<ShimDataResponse> dayResponses) {

    if (dayResponses.isEmpty()) {
        return ShimDataResponse.empty(FitbitShim.SHIM_KEY);
    }

    List<DataPoint> aggregateDataPoints = Lists.newArrayList();

    for (ShimDataResponse dayResponse : dayResponses) {
        if (dayResponse.getBody() != null) {

            List<DataPoint> dayList = (List<DataPoint>) dayResponse.getBody();

            aggregateDataPoints.addAll(dayList);
        }
    }

    return result(FitbitShim.SHIM_KEY, aggregateDataPoints);
}
 
Example #9
Source File: GoogleFitStepCountDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Override
protected Optional<DataPoint<StepCount2>> asDataPoint(JsonNode listNode) {

    JsonNode listValueNode = asRequiredNode(listNode, "value");
    long stepCountValue = asRequiredLong(listValueNode.get(0), "intVal");

    if (stepCountValue == 0) {
        return Optional.empty();
    }

    StepCount2 stepCount = new StepCount2.Builder(stepCountValue, getTimeFrame(listNode))
            .build();

    Optional<String> originSourceId = asOptionalString(listNode, "originDataSourceId");

    return Optional.of(newDataPoint(stepCount, originSourceId.orElse(null)));
}
 
Example #10
Source File: IHealthSleepDurationDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Override
protected Optional<DataPoint<SleepDuration2>> asDataPoint(JsonNode listEntryNode, Integer measureUnitMagicNumber) {

    Long effectiveStartEpochSecondsInLocalTime = asRequiredLong(listEntryNode, "StartTime");
    Long effectiveEndEpochSecondsInLocalTime = asRequiredLong(listEntryNode, "EndTime");
    ZoneOffset effectiveTimeZoneOffset = ZoneOffset.of(asRequiredString(listEntryNode, "TimeZone"));

    TimeInterval effectiveTimeInterval = ofStartDateTimeAndEndDateTime(
            getDateTimeWithCorrectOffset(effectiveStartEpochSecondsInLocalTime, effectiveTimeZoneOffset),
            getDateTimeWithCorrectOffset(effectiveEndEpochSecondsInLocalTime, effectiveTimeZoneOffset));

    SleepDuration2.Builder sleepDurationBuilder = new SleepDuration2.Builder(
            // property is called HoursSlept but it's in minutes
            new DurationUnitValue(MINUTE, asRequiredBigDecimal(listEntryNode, "HoursSlept")),
            effectiveTimeInterval);

    getUserNoteIfExists(listEntryNode).ifPresent(sleepDurationBuilder::setUserNotes);

    SleepDuration2 sleepDuration = sleepDurationBuilder.build();

    return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, sleepDuration), sleepDuration));
}
 
Example #11
Source File: FitbitIntradayStepCountDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<StepCount2>> dataPoints = mapper.asDataPoints(singletonList(responseNode));
    StepCount2.Builder stepCountBuilder;

    stepCountBuilder = new StepCount2.Builder(7,
            ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-08-21T00:00:00Z"),
                    new DurationUnitValue(DurationUnit.MINUTE, 1)));

    assertThat(dataPoints.get(0).getBody(), equalTo(stepCountBuilder.build()));
    assertThat(dataPoints.get(0).getHeader().getBodySchemaId(), equalTo(StepCount2.SCHEMA_ID));
    assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));

    stepCountBuilder = new StepCount2.Builder(52,
            ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-08-21T14:28:00Z"),
                    new DurationUnitValue(DurationUnit.MINUTE, 1)));

    assertThat(dataPoints.get(1).getBody(), equalTo(stepCountBuilder.build()));
    assertThat(dataPoints.get(1).getHeader().getBodySchemaId(), equalTo(StepCount2.SCHEMA_ID));
    assertThat(dataPoints.get(1).getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));
}
 
Example #12
Source File: GoogleFitGeopositionDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Override
protected Optional<DataPoint<Geoposition>> asDataPoint(JsonNode listNode) {

    JsonNode listValueNode = asRequiredNode(listNode, "value");
    double latitude = asRequiredDouble(listValueNode.get(0), "fpVal");
    double longitude = asRequiredDouble(listValueNode.get(1), "fpVal");
    // TODO add accuracy to geoposition
     Optional<Double> accuracyInM = asOptionalDouble(listValueNode.get(2), "fpVal");

    Geoposition.Builder measureBuilder =
            new Geoposition.Builder(
                    DEGREE_OF_ARC.newUnitValue(latitude),
                    DEGREE_OF_ARC.newUnitValue(longitude),
                    getTimeFrame(listNode));

    if (listValueNode.size() >= 4) {
        measureBuilder.setElevation(METER.newUnitValue(asRequiredDouble(listValueNode.get(3), "fpVal")));
    }

    Geoposition geoposition = measureBuilder.build();

    Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId");

    return Optional.of(newDataPoint(geoposition, originDataSourceId.orElse(null)));
}
 
Example #13
Source File: IHealthOxygenSaturationDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Override
protected Optional<DataPoint<OxygenSaturation>> asDataPoint(JsonNode listEntryNode,
        Integer measureUnitMagicNumber) {

    BigDecimal bloodOxygenValue = asRequiredBigDecimal(listEntryNode, "BO");

    // iHealth has stated that missing values would most likely be represented as a 0 value for the field
    if (bloodOxygenValue.compareTo(ZERO) == 0) {
        return Optional.empty();
    }

    OxygenSaturation.Builder oxygenSaturationBuilder =
            new OxygenSaturation.Builder(new TypedUnitValue<>(PERCENT, bloodOxygenValue))
                    .setMeasurementMethod(PULSE_OXIMETRY)
                    .setMeasurementSystem(PERIPHERAL_CAPILLARY);

    getEffectiveTimeFrameAsDateTime(listEntryNode).ifPresent(oxygenSaturationBuilder::setEffectiveTimeFrame);
    getUserNoteIfExists(listEntryNode).ifPresent(oxygenSaturationBuilder::setUserNotes);

    OxygenSaturation oxygenSaturation = oxygenSaturationBuilder.build();

    return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, oxygenSaturation), oxygenSaturation));
}
 
Example #14
Source File: MisfitSleepMeasureDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldNotSetModalityWhenAutoDetectedIsMissing() throws IOException {

    JsonNode node = objectMapper.readTree("{\n" +
            "    \"sleeps\": [\n" +
            "        {\n" +
            "            \"id\": \"54fa13a8440f705a7406845f\",\n" +
            "            \"startTime\": \"2015-02-24T21:40:59-05:00\",\n" +
            "            \"duration\": 2580,\n" +
            "            \"sleepDetails\": [\n" +
            "                {\n" +
            "                    \"datetime\": \"2015-02-24T21:40:59-05:00\",\n" +
            "                    \"value\": 2\n" +
            "                }\n" +
            "            ]\n" +
            "        }\n" +
            "    ]\n" +
            "}");

    List<DataPoint<T>> dataPoints = getMapper().asDataPoints(node);

    assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getModality(), nullValue());
}
 
Example #15
Source File: WithingsBodyTemperatureDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<BodyTemperature>> actualDataPoints = mapper.asDataPoints(responseNode);

    BodyTemperature expectedBodyTemperature = new BodyTemperature.Builder(new TemperatureUnitValue(CELSIUS, 37L))
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-02-23T19:24:49Z"))
            .build();

    assertThat(actualDataPoints.get(0).getBody(), equalTo(expectedBodyTemperature));

    DataPointHeader actualDataPointHeader = actualDataPoints.get(0).getHeader();
    assertThat(actualDataPointHeader.getBodySchemaId(), equalTo(expectedBodyTemperature.getSchemaId()));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getModality(), equalTo(SELF_REPORTED));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getSourceName(), equalTo(RESOURCE_API_SOURCE_NAME));
    assertThat(actualDataPointHeader.getAcquisitionProvenance().getAdditionalProperties().get("external_id"),
            equalTo("320419189"));
}
 
Example #16
Source File: WithingsListDataPointMapper.java    From shimmer with Apache License 2.0 6 votes vote down vote up
/**
 * Maps a JSON response with individual data points contained in a JSON array to a list of {@link DataPoint}
 * objects
 * with the appropriate measure. Splits individual nodes based on the name of the list node and then iteratively
 * maps the nodes in the list.
 *
 * @param responseNodes a list of a single JSON node containing the entire response from a Withings endpoint
 * @return a list of DataPoint objects of type T with the appropriate values mapped from the input JSON; because
 * these JSON objects are contained within an array in the input response, each object in that array will map into
 * an item in the list
 */
@Override
public List<DataPoint<T>> asDataPoints(List<JsonNode> responseNodes) {

    checkNotNull(responseNodes);
    checkNotNull(responseNodes.size() == 1, "A single response node is allowed per call.");

    JsonNode listNode = asRequiredNode(responseNodes.get(0), BODY_NODE_PROPERTY + "." + getListNodeName());

    List<DataPoint<T>> dataPoints = Lists.newArrayList();

    for (JsonNode listEntryNode : listNode) {
        asDataPoint(listEntryNode).ifPresent(dataPoints::add);
    }

    return dataPoints;
}
 
Example #17
Source File: JawboneStepCountDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPointsForSingleTimeZone() {

    List<DataPoint<StepCount1>> dataPoints = mapper.asDataPoints(singletonList(responseNode));

    StepCount1 expectedStepCount = new StepCount1.Builder(197)
            .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime(
                    OffsetDateTime.parse("2015-08-10T09:16:00-06:00"),
                    OffsetDateTime.parse("2015-08-10T11:43:00-06:00")))
            .build();

    assertThat(dataPoints.get(0).getBody(), equalTo(expectedStepCount));

    Map<String, Object> testProperties = Maps.newHashMap();

    testProperties.put(HEADER_SCHEMA_ID_KEY, StepCount1.SCHEMA_ID);
    testProperties.put(HEADER_SOURCE_UPDATE_KEY, "2015-08-18T03:11:44Z");
    testProperties.put(HEADER_SENSED_KEY, DataPointModality.SENSED);
    testProperties.put(HEADER_EXTERNAL_ID_KEY, "QkfTizSpRdvMvnHFctzItGNZMT-1F5vw");

    testDataPointHeader(dataPoints.get(0).getHeader(), testProperties);

}
 
Example #18
Source File: RunkeeperCaloriesBurnedDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPointBodies() {

    List<DataPoint<CaloriesBurned2>> dataPoints = mapper.asDataPoints(responseNode);

    TimeInterval effectiveTimeInterval = ofStartDateTimeAndDuration(
            OffsetDateTime.parse("2014-10-19T13:17:27+02:00"),
            SECOND.newUnitValue(4364.74158141667));

    CaloriesBurned2 expectedCaloriesBurned =
            new CaloriesBurned2.Builder(KILOCALORIE.newUnitValue(210.796359954334), effectiveTimeInterval)
                    .setActivityName("Cycling")
                    .build();

    assertThat(dataPoints.get(0).getBody(), equalTo(expectedCaloriesBurned));
}
 
Example #19
Source File: JawboneBodyMassIndexDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPointWithoutTimeZone() {

    List<DataPoint<BodyMassIndex1>> dataPoints = mapper.asDataPoints(singletonList(responseNode));
    BodyMassIndex1 expectedBodyMassIndex = new BodyMassIndex1
            .Builder(new TypedUnitValue<>(BodyMassIndexUnit1.KILOGRAMS_PER_SQUARE_METER, 22))
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-10-06T19:39:01Z"))
            .build();
    assertThat(dataPoints.get(1).getBody(), equalTo(expectedBodyMassIndex));

    Map<String, Object> testProperties = Maps.newHashMap();
    testProperties.put(HEADER_EXTERNAL_ID_KEY, "JM2JlMHcHlVYbz0vvV-tzteoDrIYcQ7k");
    testProperties.put(HEADER_SCHEMA_ID_KEY, BodyMassIndex1.SCHEMA_ID);
    testProperties.put(HEADER_SOURCE_UPDATE_KEY, "2015-10-06T19:39:02Z");
    testProperties.put(HEADER_SHARED_KEY, null);
    testDataPointHeader(dataPoints.get(1).getHeader(), testProperties);
}
 
Example #20
Source File: JawboneHeartRateDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<HeartRate>> dataPoints = mapper.asDataPoints(singletonList(responseNode));

    HeartRate expectedHeartRate = new HeartRate.Builder(55)
            .setTemporalRelationshipToPhysicalActivity(AT_REST)
            .setEffectiveTimeFrame(OffsetDateTime.parse("2013-11-20T08:05:00-08:00"))
            .build();

    assertThat(dataPoints.get(0).getBody(), equalTo(expectedHeartRate));

    // TODO kill maps
    Map<String, Object> testProperties = Maps.newHashMap();
    testProperties.put(HEADER_EXTERNAL_ID_KEY, "40F7_htRRnT8Vo7nRBZO1X");
    testProperties.put(HEADER_SOURCE_UPDATE_KEY, "2013-11-21T15:59:59Z");
    testProperties.put(HEADER_SCHEMA_ID_KEY, HeartRate.SCHEMA_ID);
    testProperties.put(HEADER_SENSED_KEY, DataPointModality.SENSED);
    testDataPointHeader(dataPoints.get(0).getHeader(), testProperties);
}
 
Example #21
Source File: FileSystemDataPointWritingServiceImpl.java    From sample-data-generator with Apache License 2.0 6 votes vote down vote up
@Override
public long writeDataPoints(Iterable<? extends DataPoint<?>> dataPoints) throws IOException {

    long written = 0;

    try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename, true))) {

        for (DataPoint dataPoint : dataPoints) {
            // this simplifies direct imports into MongoDB
            dataPoint.setAdditionalProperty("id", dataPoint.getHeader().getId());

            String valueAsString = objectMapper.writeValueAsString(dataPoint);
            writer.write(valueAsString);
            writer.write("\n");
            written++;
        }
    }

    return written;
}
 
Example #22
Source File: JawboneBodyWeightDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPointWhenTimeZoneIsInGMTOffset() {

    List<DataPoint<BodyWeight>> dataPoints = mapper.asDataPoints(singletonList(responseNode));
    BodyWeight testBodyWeight = dataPoints.get(1).getBody();
    BodyWeight expectedBodyWeight = new BodyWeight.Builder(new MassUnitValue(MassUnit.KILOGRAM, 74.5))
            .setEffectiveTimeFrame(OffsetDateTime.parse("2015-10-05T19:52:52-06:00"))
            .build();
    assertThat(testBodyWeight, equalTo(expectedBodyWeight));

    Map<String, Object> testProperties = Maps.newHashMap();
    testProperties.put("schemaId", BodyWeight.SCHEMA_ID);
    testProperties.put("externalId", "JM2JlMHcHlUP2mAvWWVlwwNFFVo_4CfQ");
    testProperties.put("sourceUpdatedDateTime", "2015-10-06T01:52:52Z");
    testProperties.put("shared", true);
    testDataPointHeader(dataPoints.get(1).getHeader(), testProperties);
}
 
Example #23
Source File: JawboneStepCountDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldUseCorrectTimeZoneWhenMultipleTimeZonesOnSingleDay() {

    List<DataPoint<StepCount1>> dataPoints = mapper.asDataPoints(singletonList(responseNode));

    StepCount1 expectedStepCount = new StepCount1.Builder(593)
            .setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime(
                    OffsetDateTime.parse("2015-08-05T00:00:00-04:00"),
                    OffsetDateTime.parse("2015-08-05T06:42:00-06:00")))
            .build();

    assertThat(dataPoints.get(1).getBody(), equalTo(expectedStepCount));
}
 
Example #24
Source File: FitbitIntradayHeartRateDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<HeartRate>> dataPoints = mapper.asDataPoints(singletonList(responseNode));
    HeartRate.Builder heartRateBuilder = new HeartRate.Builder(64)
            .setEffectiveTimeFrame(ofStartDateTimeAndDuration(OffsetDateTime.parse("2015-08-21T00:01Z"),
                    new DurationUnitValue(DurationUnit.MINUTE, 1)));

    assertThat(dataPoints.get(0).getBody(), equalTo(heartRateBuilder.build()));
    assertThat(dataPoints.get(0).getHeader().getBodySchemaId(), equalTo(HeartRate.SCHEMA_ID));
    assertThat(dataPoints.get(0).getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(RESOURCE_API_SOURCE_NAME));

}
 
Example #25
Source File: FitbitBodyWeightDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<BodyWeight>> dataPoints = mapper.asDataPoints(responseNode);

    assertThatDataPointMatches(dataPoints.get(0), 56.7, "2015-05-13T18:28:59Z", 1431541739000L);
    assertThatDataPointMatches(dataPoints.get(1), 55.9, "2015-05-14T11:51:57Z", 1431604317000L);
    assertThatDataPointMatches(dataPoints.get(2), 58.1, "2015-05-22T18:12:06Z", 1432318326000L);
    assertThatDataPointMatches(dataPoints.get(3), 57.2, "2015-05-24T15:15:25Z", 1432480525000L);
}
 
Example #26
Source File: MovesActivityNodeDataPointMapper.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Override
public List<DataPoint<T>> asDataPoints(List<JsonNode> responseNodes) {

    checkNotNull(responseNodes);
    checkArgument(responseNodes.size() == 1, "A single response node is allowed per call.");

    return StreamSupport.stream(responseNodes.get(0).spliterator(), false)
            .flatMap(dayNode -> asStream(asOptionalNode(dayNode, "segments")))
            .flatMap(segmentsNode -> StreamSupport.stream(segmentsNode.spliterator(), false))
            .flatMap(segmentNode -> asStream(asOptionalNode(segmentNode, "activities")))
            .flatMap(activitiesNode -> StreamSupport.stream(activitiesNode.spliterator(), false))
            .map(this::asDataPoint)
            .flatMap(OptionalStreamSupport::asStream)
            .collect(Collectors.toList());
}
 
Example #27
Source File: FitbitBodyWeightDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
public void assertThatDataPointMatches(DataPoint<BodyWeight> dataPoint, double expectedMassValue,
        String expectedEffectiveDateTime, long expectedExternalId) {

    BodyWeight expectedBodyWeight = new BodyWeight.Builder(new MassUnitValue(KILOGRAM, expectedMassValue))
            .setEffectiveTimeFrame(OffsetDateTime.parse(expectedEffectiveDateTime))
            .build();

    assertThat(dataPoint.getBody(), equalTo(expectedBodyWeight));
    assertThat(dataPoint.getHeader().getBodySchemaId(), equalTo(BodyWeight.SCHEMA_ID));
    assertThat(dataPoint.getHeader().getAcquisitionProvenance().getAdditionalProperties().get("external_id"),
            equalTo(expectedExternalId));
    assertThat(dataPoint.getHeader().getAcquisitionProvenance().getSourceName(),
            equalTo(FitbitDataPointMapper.RESOURCE_API_SOURCE_NAME));
}
 
Example #28
Source File: FitbitIntradayHeartRateDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldSetExternalId() {

    final List<DataPoint<HeartRate>> dataPoints = mapper.asDataPoints(singletonList(responseNode));

    for (DataPoint<?> dataPoint : dataPoints) {
        assertThat(
                dataPoint.getHeader().getAcquisitionProvenance().getAdditionalProperties().get("external_id"),
                is(not(nullValue())));
    }
}
 
Example #29
Source File: GoogleFitGeopositionDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPointsWithoutElevation() {

    List<DataPoint<Geoposition>> dataPoints = mapper.asDataPoints(responseNode);

    assertThatDataPointMatches(
            dataPoints.get(1),
            createTestProperties(
                    "2017-10-04T13:45:54Z",
                    null,
                    "raw:com.google.location.sample:com.google.android.gms:LGE:Nexus 5:bar:live_location",
                    SCHEMA_ID,
                    51.233600616455078, -0.57613241672515869, 43.0, 50.0));
}
 
Example #30
Source File: GoogleFitStepCountDataPointMapperUnitTests.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Test
public void asDataPointsShouldReturnCorrectDataPoints() {

    List<DataPoint<StepCount2>> dataPoints = mapper.asDataPoints(singletonList(responseNode));

    assertThatDataPointMatches(dataPoints.get(0),
            createIntegerTestProperties(4146, "2015-02-02T22:49:39.811Z", "2015-02-02T23:25:20.811Z",
                    "derived:com.google.step_count.delta:com.nike.plusgps:", SCHEMA_ID));

    assertThatDataPointMatches(dataPoints.get(1),
            createIntegerTestProperties(17, "2015-07-10T21:58:17.687316406Z", "2015-07-10T21:59:17.687316406Z",
                    "derived:com.google.step_count.cumulative:com.google.android.gms:samsung:Galaxy " +
                            "Nexus:32b1bd9e:soft_step_counter", SCHEMA_ID));
}