Builder used to create new DataReadRequests.
Public Constructor Summary
Builder()
|
Public Method Summary
DataReadRequest.Builder |
aggregate(DataSource
dataSource)
Adds a specific data source we want aggregate data from for this request.
|
DataReadRequest.Builder | |
DataReadRequest.Builder |
aggregate(DataSource
dataSource, DataType
outputDataType)
This method is deprecated. Use
aggregate(DataSource) .
|
DataReadRequest.Builder |
aggregate(DataType
inputDataType, DataType
outputDataType)
This method is deprecated. Use
aggregate(DataType) .
|
DataReadRequest.Builder |
bucketByActivitySegment(int minDuration, TimeUnit
timeUnit, DataSource
activityDataSource)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_SEGMENT , sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT for the bucket.
|
DataReadRequest.Builder |
bucketByActivitySegment(int minDuration, TimeUnit
timeUnit)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_SEGMENT , sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT for the bucket.
|
DataReadRequest.Builder |
bucketByActivityType(int minDuration, TimeUnit
timeUnit, DataSource
activityDataSource)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_TYPE , sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT for computing the buckets and sets
the activity data source to be used to read activity segments from.
|
DataReadRequest.Builder |
bucketByActivityType(int minDuration, TimeUnit
timeUnit)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_TYPE , sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT for computing the buckets.
|
DataReadRequest.Builder |
bucketBySession(int minDuration, TimeUnit
timeUnit)
Specifies bucket type as
Bucket.TYPE_SESSION and sets the minimum duration of each
Session
for the bucket.
|
DataReadRequest.Builder |
bucketByTime(int duration, TimeUnit
timeUnit)
Specifies bucket type as
Bucket.TYPE_TIME
and sets the duration of each bucket.
|
DataReadRequest |
build()
Finishes building and returns the request.
|
DataReadRequest.Builder |
enableServerQueries()
Enable querying the Google Fit server to fetch query results, in case the local
store doesn't have data for the full requested time range.
|
DataReadRequest.Builder | |
DataReadRequest.Builder | |
DataReadRequest.Builder |
setLimit(int limit)
Limits results to the latest
limit data points.
|
DataReadRequest.Builder |
Inherited Method Summary
Public Constructors
public Builder ()
Public Methods
public DataReadRequest.Builder aggregate (DataSource dataSource)
Adds a specific data source we want aggregate data from for this request. For the
output aggregate data type for a given input data type see
DataType.getAggregateType()
.
Aggregation should be requested in conjunction with one of the bucketing strategies: by time, session or activity. At least one valid detailed data source or aggregate data source should be specified in the request.
The resulting aggregated data can be queried via
DataReadResult.getBuckets()
and
Bucket.getDataSet(DataType)
.
Parameters
dataSource | The data source you're reading for aggregate data. |
---|
Throws
IllegalStateException | If the data source is already requested as detailed. |
---|---|
IllegalArgumentException | If the input data type is not supported for aggregation. |
NullPointerException | If the data source is null. |
public DataReadRequest.Builder aggregate (DataType inputDataType)
Adds the default data source for the given aggregate dataType
to this
request. For the output aggregate data type for a given input data type see
DataType.getAggregateType()
.
The default data source is selected based on all available sources for the given data type, and may be averaged or filtered. Aggregation should be requested in conjunction with one of the bucketing strategy: by time, session, or activity. At least one valid detailed data source or aggregate data source should be specified in the request
This method can be used instead of
aggregate(DataSource)
when the application is not interested in a specific
data source.
The resulting aggregated data can be queried via
DataReadResult.getBuckets()
and
Bucket.getDataSet(DataType)
.
Parameters
inputDataType | The input data type you're aggregating. |
---|
Throws
IllegalStateException | If the data type is already requested as detailed. |
---|---|
IllegalArgumentException | If the input data type is not supported for aggregation. |
NullPointerException | If the data type is null. |
public DataReadRequest.Builder aggregate (DataSource dataSource, DataType outputDataType)
This method is deprecated.
Use
aggregate(DataSource)
.
Adds a specific data source we want aggregate data from for this request and also
sets the output aggregate data type that will be returned. For a list of valid output
aggregate data types for a given input data type see
DataType.getAggregateType()
.
Aggregation should be requested in conjunction with one of the bucketing strategies: by time, session or activity. At least one valid detailed data source or aggregate data source should be specified in the request.
The resulting aggregated data can be queried via
DataReadResult.getBuckets()
and
Bucket.getDataSet(DataType)
.
Parameters
dataSource | The data source you're reading for aggregate data. |
---|---|
outputDataType | The output data type that will be returned in the result. |
Throws
IllegalStateException | If the data source is already requested as detailed. |
---|---|
IllegalArgumentException | If the input data type is not supported for aggregation or if the output aggregate data type is invalid. |
NullPointerException | If the data source is null. |
public DataReadRequest.Builder aggregate (DataType inputDataType, DataType outputDataType)
This method is deprecated.
Use
aggregate(DataType)
.
Adds the default data source for the given aggregate dataType
to this
request and sets the output aggregate data type to be returned. See
DataType.getAggregateType()
for a list of valid output aggregate data types
for a given input data type.
The default data source is selected based on all available sources for the given data type, and may be averaged or filtered. Aggregation should be requested in conjunction with one of the bucketing strategy: by time, session, or activity. At least one valid detailed data source or aggregate data source should be specified in the request
This method can be used instead of
aggregate(DataSource, DataType)
when the application is not interested in a
specific data source.
The resulting aggregated data can be queried via
DataReadResult.getBuckets()
and
Bucket.getDataSet(DataType)
.
Parameters
inputDataType | The input data type you're aggregating. |
---|---|
outputDataType | The output data type that will be returned. |
Throws
IllegalStateException | If the data type is already requested as detailed. |
---|---|
IllegalArgumentException | If the input data type is not supported for aggregation or if the output data type is invalid |
NullPointerException | If the data type is null. |
public DataReadRequest.Builder bucketByActivitySegment (int minDuration, TimeUnit timeUnit, DataSource activityDataSource)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_SEGMENT
, sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT
for the bucket.
An
DataType.TYPE_ACTIVITY_SEGMENT
represents a continuous time interval with a
single activity value. In this case, each Bucket
will represent an individual activity segment which lies inside the time interval of
the request. For instance, if the user had two separate activity segments for walking,
one for 1km and another for 2km, the result will be two buckets one with distance value
of 1km and another with distance value of 2km.
If no activity segments exist recorded for specific time intervals of the read
query, a Bucket corresponding to activity type FitnessActivities.UNKNOWN
will be added for each missing interval. For instance, if there is an activity segment
for biking from time [20, 30] seconds and for running from time [40, 50] seconds, the
result for a read query over [0, 60] will have the following buckets:
- Bucket 1 Time Interval: [0, 20] Activity: UNKNOWN
- Bucket 2 Time Interval: [20, 30] Activity: BIKING
- Bucket 3 Time Interval: [30, 40] Activity: UNKNOWN
- Bucket 4 Time Interval: [40, 50] Activity: RUNNING
- Bucket 5 Time Interval: [50, 60] Activity: UNKNOWN
Only activity segments of duration longer than minDuration
are chosen
for bucketing.
The activity segments are chosen from the specified activityDataSource
.
To use the default activity data source, use
bucketByActivitySegment(int, TimeUnit)
.
Detailed data of the aggregate type(s) specified in the request over time interval
of each bucket will be aggregated and returned. Each bucket will have one
DataSet
of aggregated data for each requested aggregate DataType
.
Throws
IllegalArgumentException | If another bucket type is already specified in the request or if an invalid minDuration is specified |
---|
public DataReadRequest.Builder bucketByActivitySegment (int minDuration, TimeUnit timeUnit)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_SEGMENT
, sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT
for the bucket.
An
DataType.TYPE_ACTIVITY_SEGMENT
represents a continuous time interval with a
single activity value. In this case, each Bucket
will represent an individual activity segment which lies inside the time interval of
the request. For instance, if the user had two separate activity segments for walking,
one for 1km and another for 2km, the result will be two buckets one with distance value
of 1km and another with distance value of 2km.
If no activity segments exist recorded for specific time intervals of the read
query, a Bucket corresponding to activity type FitnessActivities.UNKNOWN
will be used instead. For instance, if there is an activity segment for biking from
time [20, 30] seconds and for running from time [40, 50] seconds, the result for a read
query over [0, 60] will have the following buckets:
- Bucket 1 Time Interval: [0, 20] Activity: UNKNOWN
- Bucket 2 Time Interval: [20, 30] Activity: BIKING
- Bucket 3 Time Interval: [30, 40] Activity: UNKNOWN
- Bucket 4 Time Interval: [40, 50] Activity: RUNNING
- Bucket 5 Time Interval: [50, 60] Activity: UNKNOWN
Only activity segments of duration longer than minDuration
are chosen
for bucketing.
By default, activity segments are chosen from the default data source. To use a
specific data source, use
bucketByActivitySegment(int, TimeUnit, DataSource)
.
Detailed data of the aggregate type(s) specified in the request over time interval
of each bucket will be aggregated and returned. Each bucket will have one
DataSet
of aggregated data for each requested aggregate DataType
.
Throws
IllegalArgumentException | If another bucket type is already specified in the request or if an invalid minDuration is specified |
---|
public DataReadRequest.Builder bucketByActivityType (int minDuration, TimeUnit timeUnit, DataSource activityDataSource)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_TYPE
, sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT
for computing the buckets and sets the
activity data source to be used to read activity segments from.
In this case, each Bucket
represents an activity type. It contains the aggregated data of all individual activity
segments inside the time range. For instance, if the user had two separate activity
segments of walking during the time interval, one for a distance of 1km and another for
a distance of 2km, the result will be one activity bucket with a single aggregate data
point for distance with a value of 3km.
If no activity segments are recorded for specific time intervals of the read query,
segments of type FitnessActivities.UNKNOWN
will be added for these intervals and used to compute an aggregate bucket of activity
type Unknown.
Only activity segments of duration longer than minDuration
are chosen
for bucketing.
The activity segments are chosen from the specified activityDataSource
.
To use the default activity segment data source use
bucketByActivityType(int, TimeUnit)
.
Detailed data of the aggregate type(s) specified in the request over time interval
of each bucket will be aggregated and returned. Each bucket will have one
DataSet
of aggregated data for each requested aggregate DataType
.
Throws
IllegalArgumentException | If another bucket type is already specified in the request or if an invalid minDuration is specified or if an invalid activity data source is specified. |
---|
public DataReadRequest.Builder bucketByActivityType (int minDuration, TimeUnit timeUnit)
Specifies bucket type as
Bucket.TYPE_ACTIVITY_TYPE
, sets the minimum duration of each
DataType.TYPE_ACTIVITY_SEGMENT
for computing the buckets.
In this case, each Bucket
represents an activity type. It contains the aggregated data of all individual activity
segments inside the time range. For instance, if the user had two separate activity
segments of walking during the time interval, one for a distance of 1km and another for
a distance of 2km, the result will be one activity bucket with a single aggregate data
point for distance with a value of 3km.
If no activity segments are recorded for specific time intervals of the read query,
segments of type FitnessActivities.UNKNOWN
will be added for these intervals and used to compute an aggregate bucket of activity
type Unknown.
Only activity segments of duration longer than minDuration
are chosen
for bucketing.
By default, activity segments are chosen from the default data source. To use a
specific data source, use
bucketByActivitySegment(int, TimeUnit, DataSource)
.
Detailed data of the aggregate type(s) specified in the request over time interval
of each bucket will be aggregated and returned. Each bucket will have one
DataSet
of aggregated data for each requested aggregate DataType
.
Throws
IllegalArgumentException | If another bucket type is already specified in the request or if an invalid minDuration is specified. |
---|
public DataReadRequest.Builder bucketBySession (int minDuration, TimeUnit timeUnit)
Specifies bucket type as Bucket.TYPE_SESSION
and sets the minimum duration of each Session
for the bucket.
A Session
represents a time interval with associate meta data to store user-visible groups of
related data. In this case, each bucket will signify a session which lies inside the
time interval of the request.
Detailed data of the aggregate type(s) specified in the request over time interval
of each bucket will be aggregated and returned. Each bucket will have one
DataSet
of aggregated data for each requested aggregate DataType
..
Throws
IllegalArgumentException | If another bucket type is already specified in the request or if an invalid minDuration is specified |
---|
public DataReadRequest.Builder bucketByTime (int duration, TimeUnit timeUnit)
Specifies bucket type as Bucket.TYPE_TIME
and sets the duration of each bucket.
The detailed data from the Google Fit store across the time interval of the request
is divided into sub-intervals of length duration
, and aggregation is then
performed over each sub-interval to return one Bucket
of aggregated data per sub-interval.
Aggregation is performed for data type(s) specified in the request. Each bucket will
have one DataSet
of aggregated data per requested aggregate DataType
.
Throws
IllegalArgumentException | If another bucket type is already specified in the request or if an invalid duration is specified. |
---|
public DataReadRequest build ()
Finishes building and returns the request.
Throws
IllegalStateException | If the builder doesn't have enough state to create a valid request |
---|
public DataReadRequest.Builder enableServerQueries ()
Enable querying the Google Fit server to fetch query results, in case the local store doesn't have data for the full requested time range. Server results will be combined with local results into one DataSet.
Note that querying the server adds latency, specially under poor network conditions.
Also note that attempting to query the server when there is no network connection may
result in a
transient error
. Server queries are off by default.
public DataReadRequest.Builder read (DataSource dataSource)
Adds a specific data source we want to read data from to this request. At least one valid detailed data source or aggregate data source should be specified in the request.
The resulting unaggregated data can be queried via
DataReadResult.getDataSet(DataSource)
.
Parameters
dataSource | The data source that you're reading. |
---|
Throws
IllegalArgumentException | If the data source is already requested as aggregate. |
---|---|
NullPointerException | If the data source is null. |
public DataReadRequest.Builder read (DataType dataType)
Adds the default data source to read for the given dataType
to this
request. The default data source is selected based on all available sources for the
given data type, and may be averaged or filtered. At least one valid detailed data
source or aggregate data source should be specified in the request.
This method can be used instead of
read(DataSource)
when the application is not interested in a specific data
source.
The resulting unaggregated data can be queried via
DataReadResult.getDataSet(DataType)
.
Parameters
dataType | The data type that you're reading. |
---|
Throws
IllegalStateException | If the data type is already requested as aggregate. |
---|---|
NullPointerException | If the data type is null. |
public DataReadRequest.Builder setLimit (int limit)
Limits results to the latest limit
data points. This parameter is
ignored for aggregated queries. By default there is no limit.
This method is useful to reduce the amount of sent data as well as to support
scenarios like requesting the current weight or height (use setLimit(1)
to
get the latest value).
public DataReadRequest.Builder setTimeRange (long start, long end, TimeUnit timeUnit)
Sets the time range for our query. Defined start and end times are required for every read query.
Parameters
start | A start time, in the given unit since epoch, inclusive. |
---|---|
end | An end time, in the given unit since epoch, inclusive. |
timeUnit | The unit of the start and end timestamps. |