|
@@ 411-437 (lines=27) @@
|
| 408 |
|
dominant_sensor_routine = DominantSensorRoutine() |
| 409 |
|
|
| 410 |
|
|
| 411 |
|
class DominantSensor(FeatureTemplate): |
| 412 |
|
"""Dominant Sensor of current window |
| 413 |
|
""" |
| 414 |
|
def __init__(self, per_sensor=False): |
| 415 |
|
super().__init__(name='DominantSensor', |
| 416 |
|
description='Dominant Sensor in the window', |
| 417 |
|
normalized=True, |
| 418 |
|
per_sensor=per_sensor, |
| 419 |
|
enabled=True, |
| 420 |
|
routine=dominant_sensor_routine) |
| 421 |
|
|
| 422 |
|
def get_feature_value(self, data_list, cur_index, window_size, sensor_info, sensor_name=None): |
| 423 |
|
"""If per_sensor is True, returns 1 with corresponding sensor Id. |
| 424 |
|
otherwise, return the index of last sensor in the window |
| 425 |
|
""" |
| 426 |
|
self._is_value_valid = True |
| 427 |
|
dominant_sensor_label = self.routine.dominant_sensor_list.get(cur_index, None) |
| 428 |
|
if dominant_sensor_label is None: |
| 429 |
|
logger.warn(logging_name(self) + ': cannot find dominant sensor label for window index %d' % cur_index) |
| 430 |
|
if self.per_sensor: |
| 431 |
|
if sensor_name is not None: |
| 432 |
|
if sensor_name == dominant_sensor_label: |
| 433 |
|
return 1 |
| 434 |
|
else: |
| 435 |
|
return 0 |
| 436 |
|
else: |
| 437 |
|
return sensor_info[dominant_sensor_label]['index'] |
| 438 |
|
|
| 439 |
|
|
| 440 |
|
class DominantSensorPreviousWindow(FeatureTemplate): |
|
@@ 440-465 (lines=26) @@
|
| 437 |
|
return sensor_info[dominant_sensor_label]['index'] |
| 438 |
|
|
| 439 |
|
|
| 440 |
|
class DominantSensorPreviousWindow(FeatureTemplate): |
| 441 |
|
"""Dominant Sensor of previous window |
| 442 |
|
""" |
| 443 |
|
def __init__(self, per_sensor=False): |
| 444 |
|
super().__init__(name='DominantSensorPreviousWindow', |
| 445 |
|
description='Dominant Sensor in the previous window', |
| 446 |
|
normalized=True, |
| 447 |
|
per_sensor=per_sensor, |
| 448 |
|
enabled=True, |
| 449 |
|
routine=dominant_sensor_routine) |
| 450 |
|
|
| 451 |
|
def get_feature_value(self, data_list, cur_index, window_size, sensor_info, sensor_name=None): |
| 452 |
|
"""If per_sensor is True, returns 1 with corresponding sensor Id. |
| 453 |
|
otherwise, return the index of last sensor in the window |
| 454 |
|
""" |
| 455 |
|
dominant_sensor_label = self.routine.dominant_sensor_list.get([cur_index-1], None) |
| 456 |
|
if dominant_sensor_label is None: |
| 457 |
|
logger.warn(logging_name(self) + ': cannot find dominant sensor label for window index %d' % cur_index) |
| 458 |
|
if self.per_sensor: |
| 459 |
|
if sensor_name is not None: |
| 460 |
|
if sensor_name == dominant_sensor_label: |
| 461 |
|
return 1 |
| 462 |
|
else: |
| 463 |
|
return 0 |
| 464 |
|
else: |
| 465 |
|
return sensor_info[dominant_sensor_label]['index'] |
| 466 |
|
|