Пример #1
0
def mobile_app_availability_marker(all_streams, stream_name: str, owner_id,
                                   CC: CerebralCortex, config: dict):
    """
    This algorithm uses phone battery percentages to decide whether mobile app was available or unavailable.
    Theoretically, phone battery data shall be collected 24/7.
    :param raw_stream_id:
    :param CC:
    :param config:
    """
    marker_version = "0.0.1"

    if config["stream_names"]["phone_battery"] in all_streams:
        raw_stream_ids = all_streams[config["stream_names"]
                                     ["phone_battery"]]["stream_ids"]
        dd_stream_name = config["stream_names"]["app_availability_marker"]

        # using stream_id, data-diagnostic-stream-id, and owner id to generate a unique stream ID for battery-marker
        app_availability_marker_stream_id = generate_dd_stream_uuid(
            dd_stream_name, marker_version, owner_id,
            "MOBILE APP AVAILABILITY MARKER")
        input_streams = [{
            "owner_id": owner_id,
            "id": raw_stream_ids,
            "name": stream_name
        }]
        output_stream = {
            "id": app_availability_marker_stream_id,
            "name": dd_stream_name,
            "algo_type": config["algo_type"]["app_availability_marker"]
        }
        metadata = get_metadata(dd_stream_name, input_streams, config)

        if isinstance(raw_stream_ids, list):
            for raw_stream_id in raw_stream_ids:

                stream_days = CC.get_stream_days(
                    raw_stream_id, app_availability_marker_stream_id, CC)

                for day in stream_days:
                    try:
                        stream = CC.get_stream(raw_stream_id,
                                               day=day,
                                               data_type=DataSet.COMPLETE)
                        if len(stream.data) > 0:
                            windowed_data = window(
                                stream.data, config['general']['window_size'],
                                True)
                            results = process_windows(windowed_data, config)

                            merged_windows = merge_consective_windows(results)
                            if len(merged_windows) > 0:
                                store(merged_windows, input_streams,
                                      output_stream, metadata, CC, config)

                    except Exception as e:
                        CC.logging.log(
                            "Error processing: owner-id: %s, stream-id: %s, stream-name: %s, day: %s. Error: "
                            % (str(owner_id), str(raw_stream_id),
                               str(stream_name), str(day), str(e)))
def sensor_availability(all_streams, wrist: str, owner_id: uuid, CC: CerebralCortex, config: dict):
    """
    Mark missing data as wireless disconnection if a participate walks away from phone or sensor
    :param raw_stream_id:
    :param stream_name:
    :param owner_id:
    :param dd_stream_name:
    :param phone_physical_activity:
    :param CC:
    :param config:
    """
    marker_version = "0.0.1"

    if config["stream_names"]["phone_physical_activity"] in all_streams:
        phone_physical_activity = all_streams[config["stream_names"]["phone_physical_activity"]]["stream_ids"]
    else:
        phone_physical_activity = None

    key0 = "motionsense_hrv_accel_"+wrist
    key1 = "motionsense_hrv_"+wrist+"_wireless_marker"

    raw_stream_ids = all_streams[config["stream_names"][key0]]["stream_ids"],
    stream_name = all_streams[config["stream_names"][key0]]["name"]
    dd_stream_name = config["stream_names"][key1]

    if config["stream_names"]["phone_physical_activity"] in all_streams:
        # using stream_id, data-diagnostic-stream-id, and owner id to generate a unique stream ID for battery-marker
        wireless_marker_stream_id = generate_dd_stream_uuid(dd_stream_name, marker_version, owner_id, "WIRELESS DISCONNECTION MARKER")
        input_streams = [{"owner_id": owner_id, "id": raw_stream_ids, "name": stream_name}]
        output_stream = {"id": wireless_marker_stream_id, "name": dd_stream_name,
                         "algo_type": config["algo_type"]["sensor_unavailable_marker"]}
        metadata = get_metadata(dd_stream_name, input_streams, config)

        if isinstance(raw_stream_ids, list):
            for raw_stream_id in raw_stream_ids:
                stream_days = CC.get_stream_days(raw_stream_id, wireless_marker_stream_id, CC)

                for day in stream_days:
                    try:
                        # load stream data to be diagnosed
                        raw_stream = CC.get_stream(raw_stream_id, day=day, data_type=DataSet.COMPLETE)
                        if len(raw_stream.data) > 0:

                            windowed_data = window(raw_stream.data, config['general']['window_size'], True)
                            results = process_windows(windowed_data, day, CC, phone_physical_activity, config)
                            merged_windows = merge_consective_windows(results)

                            if len(merged_windows) > 0:

                                store(merged_windows, input_streams, output_stream, metadata, CC, config)
                    except Exception as e:
                        CC.logging.log("Error processing: owner-id: %s, stream-id: %s, stream-name: %s, day: %s. Error: "
                                       %(str(owner_id), str(raw_stream_id), str(stream_name), str(day), str(e)))
Пример #3
0
def attachment_marker(all_streams, wrist, owner_id: uuid, CC: CerebralCortex,
                      config: dict):
    """
    Label sensor data as sensor-on-body, sensor-off-body, or improper-attachment.
    All the labeled data (st, et, label) with its metadata are then stored in a datastore

    """
    marker_version = "0.0.1"

    # TODO: quality streams could be multiple so find the one computed with CC
    # using stream_id, data-diagnostic-stream-id, and owner id to generate a unique stream ID for battery-marker

    key0 = "motionsense_hrv_led_quality_" + wrist
    key1 = "motionsense_hrv_" + wrist + "_attachment_marker"
    raw_stream_ids = all_streams[config["stream_names"][key0]]["stream_ids"]
    stream_name = all_streams[config["stream_names"][key0]]["name"]
    dd_stream_name = config["stream_names"][key1]

    if config["stream_names"][key0] in all_streams:

        attachment_marker_stream_id = generate_dd_stream_uuid(
            dd_stream_name, marker_version, owner_id, "ATTACHMENT MARKER")
        input_streams = [{
            "owner_id": owner_id,
            "id": raw_stream_ids,
            "name": stream_name
        }]
        output_stream = {
            "id": attachment_marker_stream_id,
            "name": dd_stream_name,
            "algo_type": config["algo_type"]["attachment_marker"]
        }
        metadata = get_metadata(dd_stream_name, input_streams, config)

        if isinstance(raw_stream_ids, list):
            for raw_stream_id in raw_stream_ids:
                stream_days = CC.get_stream_days(raw_stream_id,
                                                 attachment_marker_stream_id,
                                                 CC)

                for day in stream_days:
                    try:
                        # load stream data to be diagnosed
                        raw_stream = CC.get_stream(raw_stream_id,
                                                   day=day,
                                                   data_type=DataSet.COMPLETE)

                        if len(raw_stream.data) > 0:
                            windowed_data = window(
                                raw_stream.data,
                                config['general']['window_size'], True)
                            results = process_windows(windowed_data, config)
                            merged_windows = merge_consective_windows(results)

                            store(merged_windows, input_streams, output_stream,
                                  metadata, CC, config)
                    except Exception as e:
                        CC.logging.log(
                            "Error processing: owner-id: %s, stream-id: %s, stream-name: %s, day: %s. Error: "
                            % (str(owner_id), str(raw_stream_id),
                               str(stream_name), str(day), str(e)))
def battery_marker(all_streams, owner_id, stream_name, CC: CerebralCortex,
                   config: dict):
    """
    This algorithm uses battery percentages to decide whether device was powered-off or battery was low.
    All the labeled data (st, et, label) with its metadata are then stored in a datastore.
    :param raw_stream_id:
    :param CC:
    :param config:
    """
    marker_version = "0.0.1"

    if stream_name in all_streams:
        raw_stream_ids = all_streams[config["stream_names"]
                                     ["phone_battery"]]["stream_ids"]
        dd_stream_name = config["stream_names"]["phone_battery_marker"]

        # using stream_id, data-diagnostic-stream-id, and owner id to generate a unique stream ID for battery-marker
        battery_marker_stream_id = generate_dd_stream_uuid(
            dd_stream_name, marker_version, owner_id, "BATTERY MARKER")

        input_streams = [{
            "owner_id": owner_id,
            "id": raw_stream_ids,
            "name": stream_name
        }]
        output_stream = {
            "id": battery_marker_stream_id,
            "name": dd_stream_name,
            "algo_type": config["algo_type"]["battery_marker"]
        }
        metadata = get_metadata(dd_stream_name, input_streams, config)

        if isinstance(raw_stream_ids, list):
            for raw_stream_id in raw_stream_ids:

                stream_days = CC.get_stream_days(raw_stream_id,
                                                 battery_marker_stream_id, CC)

                for day in stream_days:
                    try:
                        stream = CC.get_stream(raw_stream_id,
                                               day=day,
                                               data_type=DataSet.COMPLETE)

                        if len(stream.data) > 0:
                            windowed_data = window(
                                stream.data, config['general']['window_size'],
                                True)
                            results = process_windows(windowed_data,
                                                      stream_name, config)

                            merged_windows = merge_consective_windows(results)
                            if len(merged_windows) > 0:
                                labelled_windows = mark_windows(
                                    battery_marker_stream_id, merged_windows,
                                    CC, config)
                                store(labelled_windows, input_streams,
                                      output_stream, metadata, CC, config)
                    except Exception as e:
                        CC.logging.log(
                            "Error processing: owner-id: %s, stream-id: %s, stream-name: %s, day: %s. Error: "
                            % (str(owner_id), str(raw_stream_id),
                               str(stream_name), str(day), str(e)))
Пример #5
0
def sensor_failure_marker(all_streams, wrist: str, owner_id: uuid,
                          CC: CerebralCortex, config: dict):
    """
    Label a window as packet-loss if received packets are less than the expected packets.
    All the labeled data (st, et, label) with its metadata are then stored in a datastore.
    :param stream_id:
    :param CC_obj:
    :param config:
    """
    marker_version = "0.0.1"

    key0 = "motionsense_hrv_" + wrist + "_attachment_marker"
    key1 = "motionsense_hrv_" + wrist + "_attachment_marker"
    key2 = "motionsense_hrv_accel_" + wrist
    key3 = "motionsense_hrv_gyro_" + wrist
    key4 = "motionsense_hrv_" + wrist + "_sensor_failure_marker"

    stream_name = all_streams[config["stream_names"][key0]]["name"]
    raw_stream_ids = all_streams[config["stream_names"][key1]]["stream_ids"]
    mshrv_accel_id = all_streams[config["stream_names"][key2]]["stream_ids"]
    mshrv_gyro_id = all_streams[config["stream_names"][key3]]["stream_ids"]
    dd_stream_name = config["stream_names"][key4]

    if config["stream_names"][key2] in all_streams:

        # using stream_id, data-diagnostic-stream-id, and owner id to generate a unique stream ID for battery-marker
        sensor_failure_stream_id = generate_dd_stream_uuid(
            dd_stream_name, marker_version, owner_id, "SENSOR FAILURE MARKER")
        input_streams = [{
            "owner_id": owner_id,
            "id": raw_stream_ids,
            "name": stream_name
        }]
        output_stream = {
            "id": sensor_failure_stream_id,
            "name": dd_stream_name,
            "algo_type": config["algo_type"]["sensor_failure"]
        }
        metadata = get_metadata(dd_stream_name, input_streams, config)

        if isinstance(raw_stream_ids, list):
            for raw_stream_id in raw_stream_ids:
                stream_days = CC.get_stream_days(raw_stream_id,
                                                 sensor_failure_stream_id, CC)
                for day in stream_days:
                    try:
                        # load stream data to be diagnosed
                        attachment_marker_stream = CC.get_stream(
                            raw_stream_id, day, data_type=DataSet.COMPLETE)
                        results = OrderedDict()
                        if attachment_marker_stream.data:
                            for marker_window in attachment_marker_stream.data:
                                if "MOTIONSENSE-ON-BODY" in marker_window.sample:
                                    mshrv_accel_stream = CC.get_stream(
                                        mshrv_accel_id,
                                        day,
                                        start_time=marker_window.start_time,
                                        end_time=marker_window.end_time,
                                        data_type=DataSet.ONLY_DATA)
                                    mshrv_gyro_stream = CC.get_stream(
                                        mshrv_gyro_id,
                                        day,
                                        start_time=marker_window.start_time,
                                        end_time=marker_window.end_time,
                                        data_type=DataSet.ONLY_DATA)

                                results_accel = process_windows(
                                    mshrv_accel_stream, config)
                                results_gyro = process_windows(
                                    mshrv_gyro_stream, config)

                                key = marker_window.start_time, marker_window.end_time

                                # if sensor failure period is more than 12 hours then mark it as a sensor failure
                                if results_accel > 0 and results_gyro < 1:
                                    sample = "MOTIONSENE-HRV-" + str(
                                        wrist) + "ACCELEROMETER-FAILURE"
                                    results[key].append(
                                        DataPoint(marker_window.start_time,
                                                  marker_window.end_time,
                                                  sample))
                                elif results_accel < 1 and results_gyro > 0:
                                    sample = "MOTIONSENE-HRV-" + str(
                                        wrist) + "GYRO-FAILURE"
                                    results[key].append(
                                        DataPoint(marker_window.start_time,
                                                  marker_window.end_time,
                                                  sample))

                            if len(results) > 0:
                                merged_windows = merge_consective_windows(
                                    results)
                                store(merged_windows, input_streams,
                                      output_stream, metadata, CC, config)
                    except Exception as e:
                        CC.logging.log(
                            "Error processing: owner-id: %s, stream-id: %s, Algo-name: %s, day: %s. Error: "
                            % (str(owner_id), str(raw_stream_id),
                               "sensor_failure_marker", str(day), str(e)))