本文整理汇总了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"));
}
示例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();
}
}
示例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();
}
示例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();
}
示例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;
}
示例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());
}
示例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());
}
示例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)));
}
示例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)));
}
示例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();
}
示例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()));
}