def run_dns_to_entity_ids(conn, amount=100):
    dns = ["Network=TL,Node={}".format(i) for i in range(amount)]

    with closing(conn.cursor()) as cursor:
        entity_ids = helpers_v4.dns_to_entity_ids(cursor, dns)

    conn.commit()

    assert len(entity_ids) == amount
def test_dns_to_entity_ids(conn):
    dns = [
        "Network=TL,Node=001",
        "Network=TL,Node=002",
        "Network=TL,Node=003"]

    with closing(conn.cursor()) as cursor:
        entity_ids = helpers_v4.dns_to_entity_ids(cursor, dns)

    assert len(entity_ids) == 3
    def refine(self, cursor):
        """
        Return a DataPackage with 'refined' data of this package.

        This means that all distinguished names are translated to entity Ids.

        """
        dns, timestamps, value_rows = zip(*self.rows)

        entity_ids = dns_to_entity_ids(cursor, list(dns))

        rows = zip(entity_ids, timestamps, value_rows)
        return DataPackage(self.attribute_names, rows)
Example #4
0
def refine_datapackage(cursor, raw_datapackage):
    dns, value_rows = zip(*raw_datapackage.rows)

    entity_ids = dns_to_entity_ids(cursor, list(dns))

    refined_value_rows = map(refine_values, value_rows)

    refined_rows = zip(entity_ids, refined_value_rows)

    timestamp = pytz.UTC.localize(datetime.strptime(raw_datapackage.timestamp,
            "%Y-%m-%dT%H:%M:%S"))

    granularity = ensure_granularity(raw_datapackage.granularity)

    return DataPackage(granularity, timestamp, raw_datapackage.trend_names,
            refined_rows)