当前位置: 首页>>代码示例>>Java>>正文


Java KcalUnitValue类代码示例

本文整理汇总了Java中org.openmhealth.schema.domain.omh.KcalUnitValue的典型用法代码示例。如果您正苦于以下问题:Java KcalUnitValue类的具体用法?Java KcalUnitValue怎么用?Java KcalUnitValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KcalUnitValue类属于org.openmhealth.schema.domain.omh包,在下文中一共展示了KcalUnitValue类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.openmhealth.schema.domain.omh.KcalUnitValue; //导入依赖的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

示例2: asDataPoint

import org.openmhealth.schema.domain.omh.KcalUnitValue; //导入依赖的package包/类
@Override
protected Optional<DataPoint<PhysicalActivity>> asDataPoint(JsonNode listEntryNode,
        Integer measureUnitMagicNumber) {

    String activityName = asRequiredString(listEntryNode, "SportName");

    if (activityName.isEmpty()) {

        return Optional.empty();
    }

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

    Optional<Long> startTimeUnixEpochSecs = asOptionalLong(listEntryNode, "SportStartTime");
    Optional<Long> endTimeUnixEpochSecs = asOptionalLong(listEntryNode, "SportEndTime");
    Optional<Integer> timeZoneOffset = asOptionalInteger(listEntryNode, "TimeZone");

    if (startTimeUnixEpochSecs.isPresent() && endTimeUnixEpochSecs.isPresent() && timeZoneOffset.isPresent()) {

        Integer timeZoneOffsetValue = timeZoneOffset.get();
        String timeZoneString = timeZoneOffsetValue.toString();

        // Zone offset cannot parse a positive string offset that's missing a '+' sign (i.e., "0200" vs "+0200")
        if (timeZoneOffsetValue >= 0) {
            timeZoneString = "+" + timeZoneOffsetValue.toString();
        }

        physicalActivityBuilder.setEffectiveTimeFrame(ofStartDateTimeAndEndDateTime(
                getDateTimeWithCorrectOffset(startTimeUnixEpochSecs.get(), ZoneOffset.of(timeZoneString)),
                getDateTimeWithCorrectOffset(endTimeUnixEpochSecs.get(), ZoneOffset.of(timeZoneString))));
    }

    asOptionalDouble(listEntryNode, "Calories").ifPresent(
            calories -> physicalActivityBuilder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, calories)));

    PhysicalActivity physicalActivity = physicalActivityBuilder.build();

    return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, physicalActivity), physicalActivity));
}
 
开发者ID:openmhealth,项目名称:shimmer,代码行数:40,代码来源:IHealthPhysicalActivityDataPointMapper.java

示例3: newKcalBurnedBody

import org.openmhealth.schema.domain.omh.KcalUnitValue; //导入依赖的package包/类
public static CaloriesBurned newKcalBurnedBody() {

        TimeInterval effectiveTimeInterval = TimeInterval.ofStartDateTimeAndEndDateTime(
                OffsetDateTime.of(2013, 2, 5, 6, 25, 0, 0, UTC),
                OffsetDateTime.of(2013, 2, 5, 7, 25, 0, 0, UTC)
        );

        return new CaloriesBurned.Builder(new KcalUnitValue(KILOCALORIE, 160))
                .setActivityName("walking")
                .setEffectiveTimeFrame(effectiveTimeInterval)
                .build();
    }
 
开发者ID:openmhealth,项目名称:omh-dsu-ri,代码行数:13,代码来源:DataPointFactory.java

示例4: createBody

import org.openmhealth.schema.domain.omh.KcalUnitValue; //导入依赖的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

示例5: getMeasure

import org.openmhealth.schema.domain.omh.KcalUnitValue; //导入依赖的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

示例6: newMeasure

import org.openmhealth.schema.domain.omh.KcalUnitValue; //导入依赖的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


注:本文中的org.openmhealth.schema.domain.omh.KcalUnitValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。