简体   繁体   English

解释在google fit中onDataPoint中获得的步长值

[英]Interpretation of step value obtained in onDataPoint in google fit

I have the following code to get the step count 我有以下代码来计算步数

@Override
public void onDataPoint(DataPoint dataPoint) {
    for (final Field field : dataPoint.getDataType().getFields()) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                steps = dataPoint.getValue(field).asInt();
                Log.d(TAG, "Steps: " + steps); 
            }
        });
    }
}

What I have found out: 我发现了什么:

  1. This step value is not the current day's step value. 此步骤值不是当前步骤的值。 When the day changes the step value does not reset to 0 and continues to increment. 当日期更改时,步骤值不会重置为0并继续递增。
  2. It is not the aggregate of all the previous steps because my cumulative steps are close to 51,000 while currently it shows around 2000. 它不是所有先前步骤的总和,因为我的累计步骤接近51,000,而目前它显示在2000左右。
  3. Everytime I run the code the steps value doesn't reset to 0, so it is taking in some past values. 每次运行代码时,步骤值都不会重置为0,因此它会接收一些过去的值。
  4. If I uninstall and reinstall the app, it still starts from 2000. 如果我卸载并重新安装该应用程序,它仍然从2000开始。

I would like to know what exactly is dataPoint.getValue(field).asInt() when counting steps? 我想在计算步骤时知道dataPoint.getValue(field).asInt()究竟是什么?

DataPoint is defined as follows: DataPoint定义如下:

  • Represents a single data point in a data type's stream from a particular data source . 表示来自特定数据源的数据类型流中的单个数据点。 A data point holds a value for each field, a timestamp and an optional start time. 数据点包含每个字段的值,时间戳和可选的开始时间。 The exact semantics of each of these attributes is specified in the documentation for the particular data type, which can be found in the appropriate constant in DataType . 每个属性的确切语义在特定数据类型的文档中指定,可以在DataType中的相应常量中找到。

  • A data point can represent an instantaneous measurement, reading or inputted observation, as well as averages or aggregates over a time interval. 数据点可以表示瞬时测量,读取或输入观察,以及一段时间间隔内的平均值或聚合。 Check the data type documentation to determine which is the case for a particular data type. 检查数据类型文档以确定特定数据类型的情况。

  • DataPoints always contain one value for each the data type field. DataPoints始终为每个数据类型字段包含一个值。 Initially, all of the values are unset. 最初,所有值都未设置。 After creating the data point, the appropriate values and timestamps should be set. 创建数据点后,应设置适当的值和时间戳。

public Value getValue (Field field) 公共值getValue(字段字段)

Returns the value holder for the field with the given name. 返回具有给定名称的字段的值持有者。 This method can be used both to query the value and to set it. 此方法既可用于查询值也可用于设置值。

Create data points of custom data types: 创建自定义数据类型的数据点:

// Create a data point for a data source that provides
// data of type "com.app.custom_data_type" (created above)
DataPoint dataPoint = DataPoint.create(myDataSource);

// Set values for the data point
// This data type has two custom fields (int, float) and a common field
dataPoint.getValue(0).setInt(mField1IntValue);
dataPoint.getValue(1).setFloat(mField2FloatValue);
dataPoint.getValue(Field.FIELD_ACTIVITY).setInt(mActivityValue);

When you create custom data types that contain both int and float fields, you can't use the DataPoint.setFloatValues() and DataPoint.setIntValues() methods for those fields. 创建包含intfloat字段的自定义数据类型时,不能对这些字段使用DataPoint.setFloatValues()DataPoint.setIntValues()方法。 In this case, obtain the components of the data point and assign a value to each component individually 在这种情况下,获取数据点的组件并分别为每个组件分配值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM