1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using Sensors;
- using UnityEngine;
- using UnityEngine.TestTools;
- namespace Logging
- {
- public class BikeSensorDataLog
- {
- private float timestamp;
- private float speed;
- private float cadence;
- private int heartRate;
- private float torque;
- private float power;
- public BikeSensorDataLog(float timestamp, float speed, float cadence, int heartRate, float torque, float power)
- {
- this.timestamp = timestamp;
- this.speed = speed;
- this.cadence = cadence;
- this.heartRate = heartRate;
- this.torque = torque;
- this.power = power;
- }
- public string[] Serialize() =>
- new[]
- {
- timestamp.ToString("F4", CultureInfo.InvariantCulture),
- speed.ToString("F4", CultureInfo.InvariantCulture),
- cadence.ToString("F4", CultureInfo.InvariantCulture),
- heartRate.ToString(),
- torque.ToString("F4", CultureInfo.InvariantCulture),
- power.ToString("F4", CultureInfo.InvariantCulture)
- };
- }
- public class BikeSensorDataLogger : SensorDataLogger<BikeSensorDataLog>
- {
- public override string Key => "bike_sensor_data";
-
- private BikeSensorData bikeSensorData;
- public override void Start()
- {
- base.Start();
- bikeSensorData = BikeSensorData.Instance;
- }
- private void Update()
- {
- var hr = (int) (bikeSensorData.HrData?.HeartRate ?? -1);
- var speed = bikeSensorData.SpeedData?.SpeedKmh ?? -1f;
- var cadence = bikeSensorData.PowermeterData?.InstantaneousCadence ?? -1f;
- var power = bikeSensorData.PowermeterData?.InstantaneousPower ?? -1f;
- var torque = bikeSensorData.PowermeterData?.CrankTorque ?? -1f;
- Log(new BikeSensorDataLog(Time.time, speed, cadence, hr, torque, power));
- }
- public override void Log(BikeSensorDataLog value)
- {
- Buffer.Add(value.Serialize());
- }
- public override IEnumerable<BikeSensorDataLog> ReadLog(IEnumerable<IEnumerable<string>> lines)
- {
- throw new NotImplementedException(); //TODO
- }
- }
- }
|