Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rteqs committed Nov 23, 2024
1 parent c08da28 commit 53a0ec2
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 7 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies = [
# marshmallow_jsonschema depends on setuptools but doesn't specify it so we have to do it for them yay :D
"setuptools>=75.3.0",
"pyxattr>=0.8.1",
"orjson>=3.10.12",
]
classifiers = [
"Development Status :: 4 - Beta",
Expand Down
43 changes: 37 additions & 6 deletions src/latch/types/plots.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
from dataclasses import dataclass
from typing import Any, Optional
from typing import Any, Optional, Union
import orjson


@dataclass(frozen=True)
class WidgetValue:
class Widget:
transform_id: str
key: str
value: Any


@dataclass(frozen=True)
class PlotsArtifactTemplate:
id: str
widgetValues: Optional[dict[str, WidgetValue]] = None
template_id: str
widgets: Optional[list[Widget]] = None


@dataclass(frozen=True)
class PlotsArtifactBindings:
plotTemplates: list[PlotsArtifactTemplate]
plot_templates: list[PlotsArtifactTemplate]

@dataclass(frozen= True)

@dataclass(frozen=True)
class PlotsArtifact:
bindings: PlotsArtifactBindings

def asdict(self):
d = {}
bindings = d["bindings"] = {}
plot_templates = bindings["plotTemplates"] = []

for pt in self.bindings.plot_templates:
template: dict[str, Union[str, dict[str, dict[str, Any]]]] = {
"id": pt.template_id
}

if pt.widgets is not None:
widget_values: dict[str, dict[str, Any]] = {}
for w in pt.widgets:
widget_values[f"{w.transform_id}/{w.key}"] = {"value": w.value}

template["widgetValues"] = widget_values

plot_templates.append(template)

return d

def to_json(self) -> str:
return orjson.dumps(self.asdict()).decode()
Loading

0 comments on commit 53a0ec2

Please sign in to comment.