當前位置: 首頁>>代碼示例>>Java>>正文


Java LengthUnitValue類代碼示例

本文整理匯總了Java中org.openmhealth.schema.domain.omh.LengthUnitValue的典型用法代碼示例。如果您正苦於以下問題:Java LengthUnitValue類的具體用法?Java LengthUnitValue怎麽用?Java LengthUnitValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LengthUnitValue類屬於org.openmhealth.schema.domain.omh包,在下文中一共展示了LengthUnitValue類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: asDataPointsShouldReturnCorrectDataPoints

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@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"));
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:19,代碼來源:WithingsBodyHeightDataPointMapperUnitTests.java

示例2: main

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
/**
	 * The main method.
	 *
	 * @param args the arguments
	 */
	public static void main(String[] args) {
		try {
	        LengthUnitValue distance = new LengthUnitValue(LengthUnit.MILE, ONE);
	        KcalUnitValue caloriesBurned = new KcalUnitValue(KcalUnit.KILOCALORIE, 15.7);
	        TimeFrame timeFrame = new TimeFrame(OffsetDateTime.now() );
	        PhysicalActivity physicalActivity = new PhysicalActivity.Builder("HKWorkoutActivityTypeCycling")
	                .setDistance(distance)
	                .setEffectiveTimeFrame(timeFrame)
	                .setCaloriesBurned(caloriesBurned)
	                .build();
			
			
			
			
//	        TypedUnitValue<HKWorkoutActivityUnit> hkWorkoutActivityUnit = new TypedUnitValue<>(HKWorkoutActivityUnit.CYCLING,123);
//	        TimeFrame timeFrame = new TimeFrame(OffsetDateTime.now() );
//	        HKWorkoutActivity hkWorkoutActivity = new HKWorkoutActivity.Builder(hkWorkoutActivityUnit)
//	                .setEffectiveTimeFrame(timeFrame)
//	                // .setEffectiveTimeFrame()
//	                .setDescriptiveStatistic(MEDIAN)
//	                .setUserNotes("feeling fine")
//	                .build();
	        ObjectMapper objectMapper = new ObjectMapper();
	        objectMapper.registerModule(new JavaTimeModule());
	        
	        String rawJson = objectMapper.writeValueAsString(physicalActivity);
	        System.out.println(rawJson);
	        

		} catch( Exception e ) {
			System.out.println(e);
			e.printStackTrace();
		}

	}
 
開發者ID:petezybrick,項目名稱:iote2e,代碼行數:41,代碼來源:TryHkWorkout.java

示例3: newMeasure

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
public PhysicalActivity newMeasure(TimestampedValueGroup valueGroup) {

    DurationUnitValue duration = new DurationUnitValue(SECOND, valueGroup.getValue(DURATION_KEY));

    PhysicalActivity.Builder builder = new PhysicalActivity.Builder("some activity")
            .setEffectiveTimeFrame(ofStartDateTimeAndDuration(valueGroup.getTimestamp(), duration));

    if (valueGroup.getValue(DISTANCE_KEY) != null) {
        builder.setDistance(new LengthUnitValue(METER, valueGroup.getValue(DISTANCE_KEY)));
    }

    return builder.build();
}
 
開發者ID:openmhealth,項目名稱:sample-data-generator,代碼行數:15,代碼來源:PhysicalActivityDataPointGenerator.java

示例4: newMeasure

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
public BodyHeight newMeasure(TimestampedValueGroup valueGroup) {

    return new BodyHeight.Builder(new LengthUnitValue(METER, valueGroup.getValue(HEIGHT_KEY)))
            .setEffectiveTimeFrame(valueGroup.getTimestamp())
            .build();
}
 
開發者ID:openmhealth,項目名稱:sample-data-generator,代碼行數:8,代碼來源:BodyHeightDataPointGenerator.java

示例5: createBody

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
public Object createBody( OffsetDateTime now, Object prevBody ) throws Exception {
	// Distance
	final long midDistance = 15;
	final long maxDistance = 25;
	final long minDistance = 5;
	final long exceedDistance = 50;
	final long incrDistance = 5;
	long valueDistance = 0;
	if( prevBody != null ) {
		long prevValueDistance = ((PhysicalActivity)prevBody).getDistance().getValue().longValue();
		if( (random.nextInt() % 2) == 1 ) valueDistance = prevValueDistance + incrDistance;
		else valueDistance = prevValueDistance - incrDistance;
		if( valueDistance < minDistance ) valueDistance = minDistance;
		else if( valueDistance > maxDistance ) valueDistance = maxDistance;
	} else valueDistance = midDistance;
	// 5% of the time use exceeded value
	if( random.nextInt(100) <= MIN_PCT_EXCEED ) {
		valueDistance = exceedDistance;
	}
	
	// KCals
	final long midKcals = 500;
	final long maxKcals = 1050;
	final long minKcals = 250;
	final long exceedKcals = 2000;
	final long incrKcals = 100;
	long valueKcals = 0;
	if( prevBody != null ) {
		long prevValueKcals = ((PhysicalActivity)prevBody).getCaloriesBurned().getValue().longValue();
		if( (random.nextInt() % 2) == 1 ) valueKcals = prevValueKcals + incrKcals;
		else valueKcals = prevValueKcals - incrKcals;
		if( valueKcals < minKcals ) valueKcals = minKcals;
		else if( valueKcals > maxKcals ) valueKcals = maxKcals;
	} else valueKcals = midKcals;
	// 5% of the time use exceeded value
	String userNotes = "Feeling fine";
	if( random.nextInt(100) <= MIN_PCT_EXCEED ) {
		valueKcals = exceedKcals;
		userNotes = "dizzy";
	}

       LengthUnitValue distance = new LengthUnitValue(LengthUnit.MILE, new BigDecimal(valueDistance));
       KcalUnitValue caloriesBurned = new KcalUnitValue(KcalUnit.KILOCALORIE, new BigDecimal(valueKcals));
       TimeFrame timeFrame = new TimeFrame(OffsetDateTime.now() );
       PhysicalActivity physicalActivity = new PhysicalActivity.Builder("HKWorkoutActivityTypeCycling")
       		.setUserNotes(userNotes)
               .setDistance(distance)
               .setEffectiveTimeFrame(timeFrame)
               .setCaloriesBurned(caloriesBurned)
               .build();

       return physicalActivity;
}
 
開發者ID:petezybrick,項目名稱:iote2e,代碼行數:55,代碼來源:SimSchemaImpl.java

示例6: getMeasure

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
protected Optional<PhysicalActivity> getMeasure(JsonNode workoutNode) {
    checkNotNull(workoutNode);

    // assume that the title and workout type are optional since the documentation isn't clear
    Optional<String> title = asOptionalString(workoutNode, "title");
    Optional<Integer> workoutType = asOptionalInteger(workoutNode, "sub_type");

    String activityName = getActivityName(title.orElse(null), workoutType.orElse(null));

    PhysicalActivity.Builder builder = new PhysicalActivity.Builder(activityName);

    asOptionalBigDecimal(workoutNode, "details.meters")
            .ifPresent(distance -> builder.setDistance(new LengthUnitValue(METER, distance)));

    Optional<Long> endTimestamp = asOptionalLong(workoutNode, "time_completed");
    Optional<Long> durationInSec = asOptionalLong(workoutNode, "details.time");
    Optional<ZoneId> timeZoneId = asOptionalZoneId(workoutNode, "details.tz");

    if (endTimestamp.isPresent() && durationInSec.isPresent() && timeZoneId.isPresent()) {

        OffsetDateTime endDateTime = ofInstant(ofEpochSecond(endTimestamp.get()),
                getTimeZoneForTimestamp(workoutNode, endTimestamp.get()));

        builder.setEffectiveTimeFrame(
                ofEndDateTimeAndDuration(endDateTime, new DurationUnitValue(SECOND, durationInSec.get())));
    }

    Optional<BigDecimal> totalCalories = asOptionalBigDecimal(workoutNode, "details.calories");

    if (totalCalories.isPresent()) {

        asOptionalBigDecimal(workoutNode, "details.bmr_calories")
                .ifPresent(bmrCalories -> {
                    BigDecimal caloriesBurned = totalCalories.get().subtract(bmrCalories);
                    builder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, caloriesBurned));
                });
    }

    asOptionalInteger(workoutNode, "details.intensity")
            .ifPresent(intensity -> builder.setReportedActivityIntensity(asSelfReportedIntensity(intensity)));

    return Optional.of(builder.build());
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:45,代碼來源:JawbonePhysicalActivityDataPointMapper.java

示例7: newMeasure

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
protected Optional<PhysicalActivity> newMeasure(JsonNode node) {

    Optional<TimeFrame> timeFrame = getTimeFrame(node);

    if (!timeFrame.isPresent()) {
        return empty();
    }

    String activityName = asRequiredString(node, "activity");

    PhysicalActivity.Builder builder = new PhysicalActivity.Builder(activityName);
    builder.setEffectiveTimeFrame(timeFrame.get());

    asOptionalDouble(node, "distance")
            .ifPresent(distanceInM -> builder.setDistance(new LengthUnitValue(METER, distanceInM)));

    asOptionalDouble(node, "calories")
            .ifPresent(calories -> builder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, calories)));

    return Optional.of(builder.build());
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:23,代碼來源:MovesPhysicalActivityDataPointMapper.java

示例8: asDataPoint

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
public Optional<DataPoint<BodyHeight>> asDataPoint(JsonNode listNode) {

    JsonNode valueListNode = asRequiredNode(listNode, getValueListNodeName());
    double bodyHeightValue = asRequiredDouble(valueListNode.get(0), "fpVal");

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

    BodyHeight.Builder measureBuilder = new BodyHeight.Builder(new LengthUnitValue(METER, bodyHeightValue));

    getOptionalTimeFrame(listNode).ifPresent(measureBuilder::setEffectiveTimeFrame);

    BodyHeight bodyHeight = measureBuilder.build();
    Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId");

    return Optional.of(newDataPoint(bodyHeight, originDataSourceId.orElse(null)));
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:20,代碼來源:GoogleFitBodyHeightDataPointMapper.java

示例9: newMeasureBuilder

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
public Optional<Measure.Builder<BodyHeight, ?>> newMeasureBuilder(JsonNode measuresNode) {

    Optional<BigDecimal> value = getValueForMeasureType(measuresNode, BODY_HEIGHT);

    return value.map(heightInM -> new BodyHeight.Builder(new LengthUnitValue(METER, heightInM)));
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:8,代碼來源:WithingsBodyHeightDataPointMapper.java

示例10: getMeasure

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
private PhysicalActivity getMeasure(JsonNode itemNode) {

        String activityName = asRequiredString(itemNode, "type");

        PhysicalActivity.Builder builder = new PhysicalActivity.Builder(activityName);

        getOptionalTimeFrame(itemNode).ifPresent(builder::setEffectiveTimeFrame);

        asOptionalDouble(itemNode, "total_distance")
                .ifPresent(distanceInM -> builder.setDistance(new LengthUnitValue(METER, distanceInM)));

        return builder.build();
    }
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:14,代碼來源:RunkeeperPhysicalActivityDataPointMapper.java

示例11: assertThatMeasureMatches

import org.openmhealth.schema.domain.omh.LengthUnitValue; //導入依賴的package包/類
@Override
public void assertThatMeasureMatches(BodyHeight testMeasure, GoogleFitTestProperties testProperties) {

    BodyHeight.Builder expectedBodyHeightBuilder =
            new BodyHeight.Builder(new LengthUnitValue(METER, testProperties.getFpValue()));

    testProperties.getEffectiveTimeFrame().ifPresent(expectedBodyHeightBuilder::setEffectiveTimeFrame);

    assertThat(testMeasure, equalTo(expectedBodyHeightBuilder.build()));
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:11,代碼來源:GoogleFitBodyHeightDataPointMapperUnitTests.java


注:本文中的org.openmhealth.schema.domain.omh.LengthUnitValue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。