Skip to content

Commit

Permalink
Fix convert names and units
Browse files Browse the repository at this point in the history
  • Loading branch information
oscgonfer committed Jan 4, 2022
1 parent ae83dcf commit 33792b7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scdata/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,20 @@ def __check_sensors__(self):
for sensor_to_remove in remove_sensors:
self.sensors.pop(sensor_to_remove, None)

if config._strict_load:
remove_columns = list()
for column in self.readings.columns:
if column not in self.sensors: remove_columns.append(column)
self.readings.drop(remove_columns, axis=1, inplace=True)

std_out(f'Device sensors after removal: {list(self.sensors.keys())}')

def __convert_names__(self):
rename = dict()
for sensor in self.sensors:
if 'id' in self.sensors[sensor] and sensor in self.readings.columns:
rename[self.sensors[sensor]['id']] = sensor
if 'id' in self.sensors[sensor]:
if self.sensors[sensor]['id'] in self.readings.columns:
rename[self.sensors[sensor]['id']] = sensor
self.readings.rename(columns=rename, inplace=True)

def __convert_units__(self):
Expand All @@ -515,8 +522,8 @@ def __convert_units__(self):
factor = get_units_convf(sensor, from_units = self.sensors[sensor]['units'])

if factor != 1:
self.readings.rename(columns={sensor: sensor + '_RAW'}, inplace=True)
self.readings.loc[:, sensor] = self.readings.loc[:, sensor + '_RAW']*factor
self.readings.rename(columns={sensor: sensor + '_in_' + self.sensors[sensor]['units']}, inplace=True)
self.readings.loc[:, sensor] = self.readings.loc[:, sensor + '_in_' + self.sensors[sensor]['units']]*factor
std_out('Units check done', 'SUCCESS')

def process(self, only_new = False, lmetrics = None):
Expand Down

0 comments on commit 33792b7

Please sign in to comment.