Compare commits
3 commits
487f0255c0
...
bdbd84ab97
| Author | SHA1 | Date | |
|---|---|---|---|
| bdbd84ab97 | |||
| 99763d9881 | |||
| e9e33def3f |
5 changed files with 3805 additions and 1 deletions
26
README.md
26
README.md
|
|
@ -2,4 +2,28 @@
|
|||
|
||||
## Introduction
|
||||
|
||||
Use this template together with [Watt42's viewlib](https://source.c3.uber5.com/watt42-public/watt42_viewlib).
|
||||
Use this template together with [Watt42's viewlib](https://source.c3.uber5.com/watt42-public/watt42_viewlib).
|
||||
|
||||
## How to Run
|
||||
|
||||
1. Make sure you've got [poetry](https://python-poetry.org/) installed. You can
|
||||
install it by running the below (on MacOS/Linux), or [check installation
|
||||
instructions](https://python-poetry.org/docs/#installing-with-the-official-installer):
|
||||
|
||||
```bash
|
||||
curl -sSL https://install.python-poetry.org | python3 -
|
||||
```
|
||||
|
||||
2. Install dependencies using Poetry:
|
||||
|
||||
```bash
|
||||
poetry install
|
||||
```
|
||||
|
||||
3. Run the View app locally (replace `YOUR_ID` and `YOUR_TOKEN` with your actual
|
||||
Watt42 System ID and API Token):
|
||||
|
||||
```bash
|
||||
WATT42_SYSTEM_ID=YOUR_ID WATT42_API_TOKEN=YOUR_TOKEN poetry run panel serve main.py --port 5050
|
||||
```
|
||||
|
||||
|
|
|
|||
40
main.py
Normal file
40
main.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import json
|
||||
import os
|
||||
import panel
|
||||
from typing import Any
|
||||
|
||||
from watt42_viewlib import attach_w42_state
|
||||
|
||||
panel.extension('echarts', 'ace', 'jsoneditor')
|
||||
|
||||
SYSTEM_ID = os.environ.get("WATT42_SYSTEM_ID", "invalid-system-id")
|
||||
API_TOKEN = os.environ.get("WATT42_API_TOKEN", "invalid-api-token")
|
||||
|
||||
w42_state = panel.rx(None)
|
||||
|
||||
attach_w42_state(rx_var=w42_state, system_id=SYSTEM_ID, token=API_TOKEN)
|
||||
|
||||
def state_to_text(state: dict[str, Any]) -> str:
|
||||
return f"## Watt42 State:\n\nTop lines (as json):\n\n```\n{'\n'.join(json.dumps(state, indent=2).split('\n')[:15])}\n```\n\nReplace this with some awesome visuals"
|
||||
|
||||
state_as_text = panel.bind(state_to_text, w42_state)
|
||||
|
||||
state_pane = panel.pane.Markdown(state_as_text, sizing_mode='stretch_width')
|
||||
|
||||
sidebar_content = """
|
||||
This example shows how to build a front end for a Watt42 system: Watt42 API
|
||||
manages the state of the system, this app visualizes it.
|
||||
|
||||
Find instructions on [how to use this example
|
||||
here](https://source.c3.uber5.com/watt42-public/watt42_viewlib/src/branch/main/README.md#how-to-use).
|
||||
|
||||
"""
|
||||
|
||||
_ = panel.template.FastListTemplate(
|
||||
title="Sample Watt42 App",
|
||||
sidebar=[panel.pane.Markdown(sidebar_content, sizing_mode='stretch_width')],
|
||||
main=[
|
||||
state_pane,
|
||||
w42_state,
|
||||
],
|
||||
).servable()
|
||||
3711
poetry.lock
generated
Normal file
3711
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
2
poetry.toml
Normal file
2
poetry.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[virtualenvs]
|
||||
in-project = true
|
||||
27
pyproject.toml
Normal file
27
pyproject.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[tool.poetry]
|
||||
name = "watt42-view"
|
||||
version = "0.1.0"
|
||||
description = "Watt42 View, a browser-based app to visualize a Watt42 system, and to interact with it"
|
||||
authors = ["Chris Oloff <chris@uber5.com>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
watt42-viewlib = {git = "https://source.c3.uber5.com/watt42-public/watt42_viewlib.git"}
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.basedpyright]
|
||||
venvPath = "."
|
||||
venv = ".venv"
|
||||
# verboseOutput = true
|
||||
# include = ["."]
|
||||
# extraPaths = ["."]
|
||||
reportMissingTypeStubs = false
|
||||
|
||||
[basedpyright.analysis]
|
||||
extraPaths = ["."]
|
||||
autoImportCompletions = true
|
||||
Loading…
Add table
Add a link
Reference in a new issue