def test_table_interaction(self):
     w = generate_widget()
     tbl_cnxn = storcon.get_tbl_cnxn()
     w.persist_table(tbl_cnxn)
     w2 = Widget.from_table(tbl_cnxn, w.factory_id, w.line_id,
                            w.serial_number)
     tbl_cnxn.delete_entity(
         "classifiedwidgets",
         Widget.generate_partition_key(w.factory_id, w.line_id),
         w.serial_number)
     assert (w.serial_number == w2.serial_number)
     assert (len(w2.telemetry) > 3)
Exemplo n.º 2
0
def main(event: func.EventHubEvent):

    w = Widget.from_json(event.get_body().decode('utf-8'))

    c = Widget_Classification()
    c.classified_time = datetime.utcnow()
    c.mean = random.randrange(1, 100)
    c.std = random.randrange(1, 2)
    c.std_dist = random.randrange(1, 3)
    c.threshold = random.randrange(1, 100)
    w.classification = c

    (result, good) = c.is_good()
    assert result.success
    rowId = uuid.uuid4().hex
    if not good:
        sqlDao = WidgetSqlDAO(connectODBC)
        sqlDao.persistWidget(w, rowId)
        sqlDao.disconnect()

    # Create a sample entity to insert into the table
    tableDao = WidgetTableDAO(connectTable(), "Predictions")
    tableDao.persistWidget(w, rowId)

    result = w.to_json()

    logging.info('Python EventHub trigger processed an event: %s', result)

    return result
Exemplo n.º 3
0
    def sendData(self):

        factoryId = 'factory-{0}'.format(random.randint(0, 999))

        t = Telemetry()
        t.voltage = random.uniform(10, 100)
        t.amperage = random.uniform(10, 100)
        t.ambient_temp = random.uniform(10, 100)
        t.ambient_humidity = random.uniform(10, 100)
        t.flux_capacitance = random.uniform(10, 100)
        t.time_stamp = datetime.datetime.utcnow()

        w = Widget()
        w.serial_number = uuid.uuid4().hex
        w.factory_id = factoryId
        w.line_id = random.choice(["L1", "L2", "L3"])
        w.telemetry = [t]
        w_json = w.to_json()

        headers = dict(self.headers)
        brokerProperties = {'PartitionKey': factoryId}
        headers["BrokerProperties"] = json.dumps(brokerProperties)
        self.client.post(self.endpoint,
                         data=w_json,
                         verify=False,
                         headers=headers)
Exemplo n.º 4
0
def generate_widget() -> Widget:
    w = Widget()
    w.serial_number = "devserial1"
    w.factory_id = "kitty hawk"
    w.line_id = "1"
    w.telemetry = generate_telemetry_list(10)
    w.classification = generate_classification()
    return w
def generate_widget() -> Widget:
    w = Widget()
    w.serial_number = "devserial1"
    w.factory_id = "kitty hawk"
    w.line_id = "1"
    w.classification = generate_classification()
    w.telemetry = [generate_telemetry() for i in range(0, 5)]
    return w
Exemplo n.º 6
0
 def test_widget(self):
     """
     Tests to ensure the assembly object can be converted to json properly
     """
     w = generate_widget()
     s = w.to_json()
     assert (type(s) is str)
     w2 = Widget.from_json(s)
     assert (w.serial_number == w2.serial_number)
     assert w2.to_json() == s
def generate_widget(is_anomaly=False) -> Widget:
    w = Widget()
    w.serial_number = str(uuid.uuid4())
    factories = ["kitty hawk", "nags head", "seattle", "miami"]
    w.factory_id = random.choice(factories)
    line_ids = ["1", "2", "3"]
    w.line_id = random.choice(line_ids)
    w.telemetry = generate_telemetry_list(10, is_anomaly=is_anomaly)
    w.classification = generate_classification()
    return w
Exemplo n.º 8
0
 def test_widget_no_classification(self):
     """
     Tests to ensure the assembly object can be converted to json properly
     """
     w = generate_widget()
     w.classification = None
     s = w.to_json()
     assert (type(s) is str)
     w2 = Widget.from_json(s)
     assert (w.serial_number == w2.serial_number)
     assert w2.to_json() == s
     assert w2.line_id == "1"
 def test_widget(self):
     """
     Tests to ensure the object can be converted to json properly
     """
     w = generate_widget()
     s = w.to_json()
     assert (type(s) is str)
     w2 = Widget.from_json(s)
     assert (w.serial_number == w2.serial_number)
     w2_json = w2.to_json()
     assert (type(w2_json) is str)
     json_obj_version = json.loads(w2_json)
     assert (type(json_obj_version["classification"]["is_good"]) is bool)
    def test_persist(self, mockConnection: pypyodbc.Connection,
                     mockTableService: TableService):
        """
        Tests to ensure the generator posts events to event hub
        """

        input_widget = generate_widget()
        input_event = func.EventHubEvent(body=input_widget.to_json().encode())

        ProcessTelemetry.connectTable = lambda: Mock(TableService)
        output_json = ProcessTelemetry.main(input_event)

        output_widget = Widget.from_json(output_json)

        assert output_widget.serial_number == input_widget.serial_number
        assert output_widget.classification.std_dist > 0
Exemplo n.º 11
0
def widget_from_row(row) -> Widget:
    w_class = Widget_Classification()
    w_class.classified_time = row.classified_time
    w_class.threshold = row.threshold
    w_class.mean = row.mean
    w_class.std = row.std
    w_class.std_dist = row.std_dist

    wid = Widget()
    wid.classification = w_class
    wid.serial_number = row.serial_number
    wid.line_id = row.line_id
    wid.factory_id = row.factory_id
    return wid