Пример #1
0
        SessionInsertRequest InsertFitnessSession()
        {
            Log.Info(TAG, "Creating a new session for an afternoon run");

            var  epoch         = new DateTime(1970, 1, 1);
            var  now           = DateTime.UtcNow;
            long endTime       = (long)(now - epoch).TotalMilliseconds;
            long endWalkTime   = (long)(now.Subtract(TimeSpan.FromDays(10)) - epoch).TotalMilliseconds;
            long startWalkTime = (long)(now.Subtract(TimeSpan.FromDays(20)) - epoch).TotalMilliseconds;
            long startTime     = (long)(now.Subtract(TimeSpan.FromMinutes(30)) - epoch).TotalMilliseconds;

            var speedDataSource = new DataSource.Builder()
                                  .SetAppPackageName(PackageName)
                                  .SetDataType(DataType.TypeSpeed)
                                  .SetName(SAMPLE_SESSION_NAME + "- speed")
                                  .SetType(DataSource.TypeRaw)
                                  .Build();

            const float runSpeedMps  = 10;
            const float walkSpeedMps = 3;
            // Create a data set of the run speeds to include in the session.
            DataSet speedDataSet = DataSet.Create(speedDataSource);

            DataPoint firstRunSpeed = speedDataSet.CreateDataPoint()
                                      .SetTimeInterval(startTime, startWalkTime, TimeUnit.Milliseconds);

            firstRunSpeed.GetValue(Field.FieldSpeed).SetFloat(runSpeedMps);
            speedDataSet.Add(firstRunSpeed);

            DataPoint walkSpeed = speedDataSet.CreateDataPoint()
                                  .SetTimeInterval(startWalkTime, endWalkTime, TimeUnit.Milliseconds);

            walkSpeed.GetValue(Field.FieldSpeed).SetFloat(walkSpeedMps);
            speedDataSet.Add(walkSpeed);

            DataPoint secondRunSpeed = speedDataSet.CreateDataPoint()
                                       .SetTimeInterval(endWalkTime, endTime, TimeUnit.Milliseconds);

            secondRunSpeed.GetValue(Field.FieldSpeed).SetFloat(runSpeedMps);
            speedDataSet.Add(secondRunSpeed);

            // [START build_insert_session_request_with_activity_segments]
            // Create a second DataSet of ActivitySegments to indicate the runner took a 10-minute walk
            // in the middle of the run.
            var activitySegmentDataSource = new DataSource.Builder()
                                            .SetAppPackageName(PackageName)
                                            .SetDataType(DataType.TypeActivitySegment)
                                            .SetName(SAMPLE_SESSION_NAME + "-activity segments")
                                            .SetType(DataSource.TypeRaw)
                                            .Build();
            DataSet activitySegments = DataSet.Create(activitySegmentDataSource);

            DataPoint firstRunningDp = activitySegments.CreateDataPoint()
                                       .SetTimeInterval(startTime, startWalkTime, TimeUnit.Milliseconds);

            firstRunningDp.GetValue(Field.FieldActivity).SetActivity(FitnessActivities.Running);
            activitySegments.Add(firstRunningDp);

            DataPoint walkingDp = activitySegments.CreateDataPoint()
                                  .SetTimeInterval(startWalkTime, endWalkTime, TimeUnit.Milliseconds);

            walkingDp.GetValue(Field.FieldActivity).SetActivity(FitnessActivities.Walking);
            activitySegments.Add(walkingDp);

            DataPoint secondRunningDp = activitySegments.CreateDataPoint()
                                        .SetTimeInterval(endWalkTime, endTime, TimeUnit.Milliseconds);

            secondRunningDp.GetValue(Field.FieldActivity).SetActivity(FitnessActivities.Running);
            activitySegments.Add(secondRunningDp);

            var session = new Session.Builder()
                          .SetName(SAMPLE_SESSION_NAME)
                          .SetDescription("Long run around Shoreline Park")
                          .SetIdentifier("UniqueIdentifierHere")
                          .SetActivity(FitnessActivities.Running)
                          .SetStartTime(startTime, TimeUnit.Milliseconds)
                          .SetEndTime(endTime, TimeUnit.Milliseconds)
                          .Build();

            var insertRequest = new SessionInsertRequest.Builder()
                                .SetSession(session)
                                .AddDataSet(speedDataSet)
                                .AddDataSet(activitySegments)
                                .Build();

            return(insertRequest);
        }
Пример #2
0
		SessionInsertRequest InsertFitnessSession()
		{
			Log.Info(TAG, "Creating a new session for an afternoon run");

			var epoch = new DateTime (1970, 1, 1);
			var now = DateTime.UtcNow;
			long endTime = (long)(now - epoch).TotalMilliseconds;
			long endWalkTime = (long)(now.Subtract (TimeSpan.FromMinutes (10)) - epoch).TotalMilliseconds;
			long startWalkTime = (long)(now.Subtract (TimeSpan.FromMinutes (20)) - epoch).TotalMilliseconds;
			long startTime = (long)(now.Subtract (TimeSpan.FromMinutes (30)) - epoch).TotalMilliseconds;

			var speedDataSource = new DataSource.Builder()
				.SetAppPackageName (PackageName)
				.SetDataType (DataType.TypeSpeed)
				.SetName (SAMPLE_SESSION_NAME + "- speed")
				.SetType (DataSource.TypeRaw)
				.Build ();

			const float runSpeedMps = 10;
			const float walkSpeedMps = 3;
			// Create a data set of the run speeds to include in the session.
			DataSet speedDataSet = DataSet.Create (speedDataSource);

			DataPoint firstRunSpeed = speedDataSet.CreateDataPoint ()
				.SetTimeInterval (startTime, startWalkTime, TimeUnit.Milliseconds);
			firstRunSpeed.GetValue (Field.FieldSpeed).SetFloat (runSpeedMps);
			speedDataSet.Add (firstRunSpeed);

			DataPoint walkSpeed = speedDataSet.CreateDataPoint ()
				.SetTimeInterval (startWalkTime, endWalkTime, TimeUnit.Milliseconds);
			walkSpeed.GetValue (Field.FieldSpeed).SetFloat (walkSpeedMps);
			speedDataSet.Add (walkSpeed);

			DataPoint secondRunSpeed = speedDataSet.CreateDataPoint ()
				.SetTimeInterval (endWalkTime, endTime, TimeUnit.Milliseconds);
			secondRunSpeed.GetValue (Field.FieldSpeed).SetFloat(runSpeedMps);
			speedDataSet.Add (secondRunSpeed);

			// [START build_insert_session_request_with_activity_segments]
			// Create a second DataSet of ActivitySegments to indicate the runner took a 10-minute walk
			// in the middle of the run.
			var activitySegmentDataSource = new DataSource.Builder()
				.SetAppPackageName (PackageName)
				.SetDataType (DataType.TypeActivitySegment)
				.SetName (SAMPLE_SESSION_NAME + "-activity segments")
				.SetType (DataSource.TypeRaw)
				.Build ();
			DataSet activitySegments = DataSet.Create (activitySegmentDataSource);

			DataPoint firstRunningDp = activitySegments.CreateDataPoint ()
				.SetTimeInterval (startTime, startWalkTime, TimeUnit.Milliseconds);
			firstRunningDp.GetValue (Field.FieldActivity).SetActivity (FitnessActivities.Running);
			activitySegments.Add (firstRunningDp);

			DataPoint walkingDp = activitySegments.CreateDataPoint ()
				.SetTimeInterval (startWalkTime, endWalkTime, TimeUnit.Milliseconds);
			walkingDp.GetValue (Field.FieldActivity).SetActivity (FitnessActivities.Walking);
			activitySegments.Add (walkingDp);

			DataPoint secondRunningDp = activitySegments.CreateDataPoint ()
				.SetTimeInterval (endWalkTime, endTime, TimeUnit.Milliseconds);
			secondRunningDp.GetValue (Field.FieldActivity).SetActivity (FitnessActivities.Running);
			activitySegments.Add (secondRunningDp);

			var session = new Session.Builder ()
				.SetName (SAMPLE_SESSION_NAME)
				.SetDescription ("Long run around Shoreline Park")
				.SetIdentifier ("UniqueIdentifierHere")
				.SetActivity (FitnessActivities.Running)
				.SetStartTime (startTime, TimeUnit.Milliseconds)
				.SetEndTime (endTime, TimeUnit.Milliseconds)
				.Build ();

			var insertRequest = new SessionInsertRequest.Builder()
				.SetSession (session)
				.AddDataSet (speedDataSet)
				.AddDataSet (activitySegments)
				.Build ();

			return insertRequest;
		}