def testInfluxDbTimestamp(self): test_datetime = datetime(2019, 8, 15, 23, 21, 30, tzinfo=timezone.utc) actual = TimeUtils.influxDBTimestamp(test_datetime) self.assertEqual( 1565911290000, actual, 'The conversion to InfluxDB timestamp did not return the expected value.' )
def testInfluxDbTimestampMillisecond(self): test_datetime = datetime(2019, 8, 20, 12, 12, 12, 531000, tzinfo=timezone.utc) actual = TimeUtils.influxDBTimestamp(test_datetime) self.assertEqual( 1566303132531, actual, 'The conversion to InfluxDB timestamp did not return the expected value.' )
def testInfluxDbTimestampMicrosecond(self): test_datetime = datetime(2019, 8, 20, 12, 12, 12, 531999, tzinfo=timezone.utc) actual = TimeUtils.influxDBTimestamp(test_datetime) # currently truncates, consider rounding self.assertEqual( 1566303132531, actual, 'The conversion to InfluxDB timestamp did not return the expected value.' )
def formatData(self, data_state): fields = data_state.get_dirty_fields() influx_timestamp = TimeUtils.influxDBTimestamp( data_state.get_data_item( DataState.names[DataState.names.DateTime])) influx_data_lines = [] if fields.issuperset(['Latitude', 'Longitude']): influx_data_lines.append( self.buildLocation(data_state) + str(influx_timestamp)) if fields.issuperset(['X', 'Y', 'Z']): influx_data_lines.append( self.buildAcceleration(data_state) + str(influx_timestamp)) if fields.issuperset(['Steering_Angle', 'Steering_Rate']): influx_data_lines.append( self.buildSteering(data_state) + str(influx_timestamp)) if fields.issuperset(['Throttle', 'ECU_Throttle']): influx_data_lines.append( self.buildThrottle(data_state) + str(influx_timestamp)) if fields.issuperset(['Brake', 'Brake_Pressure']): influx_data_lines.append( self.buildBrake(data_state) + str(influx_timestamp)) if fields.issuperset(['Clutch']): influx_data_lines.append( self.buildClutch(data_state) + str(influx_timestamp)) if fields.issuperset(['RPM']): influx_data_lines.append( self.buildRPM(data_state) + str(influx_timestamp)) if fields.issuperset(['Coolant_Temperature']): influx_data_lines.append( self.buildCoolant(data_state) + str(influx_timestamp)) if fields.issuperset(['Oil_Pressure']): influx_data_lines.append( self.buildOilPressure(data_state) + str(influx_timestamp)) if fields.issuperset(['Oil_Temperature']): influx_data_lines.append( self.buildOilTemperature(data_state) + str(influx_timestamp)) if fields.issuperset(['LF_KPH', 'RF_KPH', 'LR_KPH', 'RR_KPH']): influx_data_lines.append( self.buildWheelSpeed(data_state) + str(influx_timestamp)) if fields.issuperset(['Sport_Mode', 'Pasm_Sport_Mode', 'PSM_Disable']): influx_data_lines.append( self.buildPModes(data_state) + str(influx_timestamp)) return influx_data_lines