Skip to main content

Populate Clarify metadata through asset models.

Project description

clarify-assets

Populate Clarify metadata through asset models.

Flow example

from clarify_assets import Asset, Attribute, AssetBroker
from pyclarify import Item


enterprise = Asset(
    labels = [{"enterprise": "OG Inc"}]
)

station = Asset(
    labels = [{"station": "work"}]
)

temperature = Attribute(
    meta=Item(
        name="Temperature",
        labels={
            "medium": ["Air"]
        }
    ),
    filter = {"name": "Temperature"}
)

climate = Asset(
    labels=[{"cell": "climate"}],
    attributes=[temperature]
)

station.append(climate)
enterprise.append(station)

enterprise.pretty_print(debug=True)

AB = AssetBroker(
    credentials="credentials.json",
    integrations=["integration1"]
)

AB.flush_and_build_db()

AB.assign_signals(enterprise)

enterprise.pretty_print(minimal=True)

AB.publish_asset(enterprise)

Custom attribute example

from clarify_assets import Attribute
from dataclasses import dataclass

def get_value_or_none(key, asset):
  return list(filter(lambda x: x,
            list(map(lambda x: x[key] if key in x.keys() else None,
                     asset.labels)
                )
  ))

def get_line_number(string):
  return string.lower().replace(" ", "").split("line")[-1]


@dataclass
class FishtalkAttribute(Attribute):
  def __post_init__(self):
    super().__post_init__()
    self.independent = True
    if self.meta:
      i = self.meta.dict()
      i["labels"]["data-source"] = ["Fishtalk"]
      self.meta = Item(**i)
    if self.labels:

      area_label = get_value_or_none("area", self)
      line_label = get_value_or_none("line", self)
      if area_label and line_label:
        line_no =  get_line_number(line_label)
        if len(line_no) == 1:
          line_no = "0" + line_no

        unit_label = area_label + "-" + line_no

        self.filter = merge_filters(self.filter, {"labels.unit": [unit_label]})



@dataclass
class FishtalkBiomassCount(FishtalkAttribute):
  meta: Item = Item(
        name = "Biomasse antall",
        engUnit = "stk",
        visible = True,
  )
  def __post_init__(self):
        self.filter = merge_filters(self.filter, {"name": "fishtalkparser.Closing Count"})
        super().__post_init__()

Reusable attributes example

@dataclass
class ValveAeration(ScadaAttribute):
  meta: Item = Item(
        name = "Valve X",
        engUnit = "",
        valueType="enum",
        enumValues={
            "0": "Closed",
            "1": "Open"
        },
        visible = True,
  )
  def __post_init__(self):
    self.filter = merge_filters(self.filter, {"name": "Value"})
    super().__post_init__()



valve_aeration_list = [
    ValveAeration(name = f"Valve {i}", filter = {"labels.folder-3": [f"Valve_Aeriation_{i}"]})
    for i in range(1,9)
]

Reusable attributes with different filters

va = ValveAeration()

house = Asset(
    labels=[{"site":"home"}],
    attributes=[
        va.copy(
            name="Aeration Kitchen",
            add_filter={
                "labels.room": "Kitchen"
            }
        ),
        va.copy(
            name="Aeration Living room",
            add_filter={
                "labels.room": "Living room"
            }
        )
    ]
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clarify_assets-0.0.6.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

clarify_assets-0.0.6-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file clarify_assets-0.0.6.tar.gz.

File metadata

  • Download URL: clarify_assets-0.0.6.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for clarify_assets-0.0.6.tar.gz
Algorithm Hash digest
SHA256 d18cea8ff867224c4b1e4ee4f77b452a7e4839a0f802b979309145c14e9cbad8
MD5 75e14f3fa7f4d5a1c09bc33c8dc47792
BLAKE2b-256 27ec43c6b19f36bf31c6af8cf86acd7c147ddc50e705992b6aefa42d6c565b3f

See more details on using hashes here.

File details

Details for the file clarify_assets-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for clarify_assets-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2484aff09436389c117e384a75f38cf25af865c53b1fb542f004ec3d673f84e7
MD5 a005835a5d485269be73c18e39d6fa9a
BLAKE2b-256 47756f036b5c7f6351f5d0323ca99f4353f5df44066d6d3916c436f6f1c50842

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page