File size: 943 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from wandb.data_types import Table
from wandb.errors import Error


@dataclass
class VisualizeSpec:
    name: str
    key: str = ""

    @property
    def config_value(self) -> dict[str, Any]:
        return {
            "id": self.name,
            "historyFieldSettings": {"x-axis": "_step", "key": self.key},
        }

    @property
    def config_key(self) -> tuple[str, str, str]:
        return ("_wandb", "viz", self.key)


@dataclass
class Visualize:
    table: Table
    spec: VisualizeSpec

    def set_key(self, key: str) -> None:
        self.spec.key = key


def visualize(id: str, value: Table) -> Visualize:
    if not isinstance(value, Table):
        raise Error(
            f"Expected `value` to be `wandb.Table` type, instead got {type(value).__name__}"
        )
    return Visualize(table=value, spec=VisualizeSpec(name=id))