Skip to content

Commit

Permalink
Merge pull request #17 from vapor-ware/mhink-no-pressure
Browse files Browse the repository at this point in the history
Reading a broken DP sensor returns no reading.
  • Loading branch information
MatthewHink committed Nov 10, 2017
2 parents 9561a01 + 7861236 commit c0567f1
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions synse/protocols/i2c_common/i2c_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,19 @@ def _normalize_differential_pressure_result(channel, readings):
readings: the raw differential pressure readings from the sensor.
"""
# Dict for aggregating and logging.
result_stats = {
'sample_count': DIFFERENTIAL_PRESSURE_READ_COUNT,
'raw_mean': stats.std_dev(readings)[0],
'raw_stddev': stats.std_dev(readings)[1]
}
result_stats = {'sample_count': DIFFERENTIAL_PRESSURE_READ_COUNT}
result_stats['raw_mean'], result_stats['raw_stddev'] = stats.std_dev(readings)

if readings is None:
# Bad sensor read. Don't fail the fan_sensors web route.
result_stats['raw_mean'] = None
result_stats['raw_stddev'] = None
result_stats['remove_count'] = None
result_stats['outliers'] = None
result_stats['list'] = None
result_stats['mean'] = None
result_stats['stddev'] = None
return result_stats

# Remove outliers.
readings_copy = copy.deepcopy(readings)
Expand Down Expand Up @@ -373,6 +381,8 @@ def read_differential_pressure(channel):

# Now that the bus is closed, normalize the results.
normalized_result = _normalize_differential_pressure_result(channel, readings)
if normalized_result is None:
return None # Read of bad sensor.
return normalized_result['mean']


Expand Down Expand Up @@ -424,6 +434,8 @@ def read_differential_pressures(count):
for index, raw in enumerate(raw_result):
channel = get_channel_from_ordinal(index)
normalized = _normalize_differential_pressure_result(channel, raw)
if normalized is None:
return None # Read of bad sensor.
result.append(normalized['mean'])

end_time = datetime.datetime.now()
Expand Down

0 comments on commit c0567f1

Please sign in to comment.