|
@@ 444-475 (lines=32) @@
|
| 441 |
|
dominant_sensor_routine = DominantSensorRoutine() |
| 442 |
|
|
| 443 |
|
|
| 444 |
|
class DominantSensor(FeatureTemplate): |
| 445 |
|
"""Dominant Sensor of current window. |
| 446 |
|
|
| 447 |
|
The sensor that fires the most amount of sensor event.rst in the current window. |
| 448 |
|
|
| 449 |
|
Args: |
| 450 |
|
per_sensor (:obj:`bool`): True if the sensor ID needs to be binary coded. |
| 451 |
|
""" |
| 452 |
|
def __init__(self, per_sensor=False): |
| 453 |
|
super().__init__(name='DominantSensor', |
| 454 |
|
description='Dominant Sensor in the window', |
| 455 |
|
normalized=True, |
| 456 |
|
per_sensor=per_sensor, |
| 457 |
|
enabled=True, |
| 458 |
|
routine=dominant_sensor_routine) |
| 459 |
|
|
| 460 |
|
def get_feature_value(self, data_list, cur_index, window_size, sensor_info, sensor_name=None): |
| 461 |
|
"""If per_sensor is True, returns 1 with corresponding sensor Id. |
| 462 |
|
otherwise, return the index of last sensor in the window |
| 463 |
|
""" |
| 464 |
|
self._is_value_valid = True |
| 465 |
|
dominant_sensor_label = self.routine.dominant_sensor_list.get(cur_index, None) |
| 466 |
|
if dominant_sensor_label is None: |
| 467 |
|
logger.warning(logging_name(self) + ': cannot find dominant sensor label for window index %d' % cur_index) |
| 468 |
|
if self.per_sensor: |
| 469 |
|
if sensor_name is not None: |
| 470 |
|
if sensor_name == dominant_sensor_label: |
| 471 |
|
return 1 |
| 472 |
|
else: |
| 473 |
|
return 0 |
| 474 |
|
else: |
| 475 |
|
return sensor_info[dominant_sensor_label]['index'] |
| 476 |
|
|
| 477 |
|
|
| 478 |
|
class DominantSensorPreviousWindow(FeatureTemplate): |
|
@@ 478-508 (lines=31) @@
|
| 475 |
|
return sensor_info[dominant_sensor_label]['index'] |
| 476 |
|
|
| 477 |
|
|
| 478 |
|
class DominantSensorPreviousWindow(FeatureTemplate): |
| 479 |
|
"""Dominant Sensor of previous window. |
| 480 |
|
|
| 481 |
|
The sensor that fires the most amount of sensor event.rst in the current window. |
| 482 |
|
|
| 483 |
|
Args: |
| 484 |
|
per_sensor (:obj:`bool`): True if the sensor ID needs to be binary coded. |
| 485 |
|
""" |
| 486 |
|
def __init__(self, per_sensor=False): |
| 487 |
|
super().__init__(name='DominantSensorPreviousWindow', |
| 488 |
|
description='Dominant Sensor in the previous window', |
| 489 |
|
normalized=True, |
| 490 |
|
per_sensor=per_sensor, |
| 491 |
|
enabled=True, |
| 492 |
|
routine=dominant_sensor_routine) |
| 493 |
|
|
| 494 |
|
def get_feature_value(self, data_list, cur_index, window_size, sensor_info, sensor_name=None): |
| 495 |
|
"""If per_sensor is True, returns 1 with corresponding sensor Id. |
| 496 |
|
otherwise, return the index of last sensor in the window |
| 497 |
|
""" |
| 498 |
|
dominant_sensor_label = self.routine.dominant_sensor_list.get([cur_index-1], None) |
| 499 |
|
if dominant_sensor_label is None: |
| 500 |
|
logger.warning(logging_name(self) + ': cannot find dominant sensor label for window index %d' % cur_index) |
| 501 |
|
if self.per_sensor: |
| 502 |
|
if sensor_name is not None: |
| 503 |
|
if sensor_name == dominant_sensor_label: |
| 504 |
|
return 1 |
| 505 |
|
else: |
| 506 |
|
return 0 |
| 507 |
|
else: |
| 508 |
|
return sensor_info[dominant_sensor_label]['index'] |
| 509 |
|
|