com.samsung.android.sdk.healthdata
Enum HealthDataResolver.AggregateRequest.TimeGroupUnit
- java.lang.Object
-
- java.lang.Enum<HealthDataResolver.AggregateRequest.TimeGroupUnit>
-
- com.samsung.android.sdk.healthdata.HealthDataResolver.AggregateRequest.TimeGroupUnit
-
- All Implemented Interfaces:
- Serializable, Comparable<HealthDataResolver.AggregateRequest.TimeGroupUnit>
- Enclosing interface:
- HealthDataResolver.AggregateRequest
public static enum HealthDataResolver.AggregateRequest.TimeGroupUnit extends Enum<HealthDataResolver.AggregateRequest.TimeGroupUnit>
This enumeration defines time units to group values of the aggregate result.
You can retrieve grouped result ofHealthDataResolver.agregate()
with the specified time unit.Time Group Unit and Format
The time unit for grouping can be set with HealthDataResolver.AggregateRequest.Builder.setTimeGroup(). Time information in the aggregate result is included as the following format for each time group unit.Time group unit Format MINUTELY
yyyy-mm-dd hh:mm
(e.g. 2015-10-09 18:17)HOURLY
yyyy-mm-dd hh
(e.g. 2015-10-09 18)DAILY
yyyy-mm-dd
(e.g. 2015-10-09)WEEKLY
yyyy-ww
(e.g. 2015-41)MONTHLY
yyyy-mm
(e.g. 2015-10)Getting Grouped Aggregate Result with Time Group Unit
If you requests hourly average steps on today, you can set the time group unit for the aggregate request.
public class HealthDataResolverExample { // The state of connection private HealthDataStore mStore; private void getHourlySteps(long startTime, long endTime) { HealthDataResolver resolver = new HealthDataResolver(mStore, null); HealthDataResolver.AggregateRequest request = new HealthDataResolver.AggregateRequest.Builder() .setDataType(HealthConstants.StepCount.HEALTH_DATA_TYPE) .setLocalTimeRange(HealthConstants.StepCount.START_TIME, HealthConstants.StepCount.TIME_OFFSET, startTime, endTime) .addFunction(HealthDataResolver.AggregateRequest.AggregateFunction.AVG, HealthConstants.StepCount.COUNT, "average") .setTimeGroup(HealthDataResolver.AggregateRequest.TimeGroupUnit.HOURLY, 1, HealthConstants.StepCount.START_TIME, HealthConstants.StepCount.TIME_OFFSET, "hour") .build(); try { resolver.aggregate(request).setResultListener(mStepAggrResult); } catch (Exception e) { Log.d(APP_TAG, "Aggregating health data fails."); } }
The retrieved result can be checked:
private final HealthResultHolder.ResultListener<HealthDataResolver.AggregateResult> mStepAggrResult= new HealthResultHolder.ResultListener<HealthDataResolver.AggregateResult>() { @Override public void onResult(HealthDataResolver.AggregateResult result) { try { Iterator<HealthData> iterator = result.iterator(); if (iterator.hasNext()) { HealthData data = iterator.next(); // Gets hour information as yyyy-mm-dd hh, e.g. 2015-10-09 18 String hour = data.getString("hour"); // Gets the average value for the current cursor float avr = data.getFloat("average"); // ... } } finally { result.close(); } } }; }
- Since:
- 1.0.0
-
-
Enum Constant Summary
Enum Constants Enum Constant and Description DAILY
Time unit to group values of the aggregate result daily.HOURLY
Time unit to group values of the aggregate result hourly.MINUTELY
Time unit to group values of the aggregate result minutely.MONTHLY
Time unit to group the aggregate result monthly.WEEKLY
Time unit to group the aggregate result weekly.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static HealthDataResolver.AggregateRequest.TimeGroupUnit
valueOf(String name)
Returns the enum constant of this type with the specified name.static HealthDataResolver.AggregateRequest.TimeGroupUnit[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
MINUTELY
public static final HealthDataResolver.AggregateRequest.TimeGroupUnit MINUTELY
Time unit to group values of the aggregate result minutely. It is able to get minute information in the aggregate result as string with the following format.yyyy-mm-dd hh:mm
(e.g. 2014-10-09 18:17)- Since:
- 1.0.0
-
HOURLY
public static final HealthDataResolver.AggregateRequest.TimeGroupUnit HOURLY
Time unit to group values of the aggregate result hourly.yyyy-mm-dd hh
(e.g. 2014-10-09 18)- Since:
- 1.0.0
-
DAILY
public static final HealthDataResolver.AggregateRequest.TimeGroupUnit DAILY
Time unit to group values of the aggregate result daily.yyyy-mm-dd
(e.g. 2014-10-09)- Since:
- 1.0.0
-
WEEKLY
public static final HealthDataResolver.AggregateRequest.TimeGroupUnit WEEKLY
Time unit to group the aggregate result weekly.
The first day of the week is Monday.yyyy-ww
(e.g. 2014-41)- Since:
- 1.0.0
-
MONTHLY
public static final HealthDataResolver.AggregateRequest.TimeGroupUnit MONTHLY
Time unit to group the aggregate result monthly.yyyy-mm
(e.g. 2014-10)- Since:
- 1.0.0
-
-
Method Detail
-
values
public static HealthDataResolver.AggregateRequest.TimeGroupUnit[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (HealthDataResolver.AggregateRequest.TimeGroupUnit c : HealthDataResolver.AggregateRequest.TimeGroupUnit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static HealthDataResolver.AggregateRequest.TimeGroupUnit valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
-