Skip to content

Commit

Permalink
project refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
natankeddem committed May 5, 2024
1 parent c927ef4 commit 005af9e
Show file tree
Hide file tree
Showing 19 changed files with 535 additions and 327 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.12.2-bookworm

ENV DEBIAN_FRONTEND=noninteractive \
DISPLAY=:99 \
NICEGUI_STORAGE_PATH=data

# Install packages
RUN apt-get update && apt-get install --no-install-recommends -y \
sudo git build-essential chromium chromium-driver python3-pip\
&& rm -rf /var/lib/apt/lists/*

# Create remote user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

ENV PATH="/home/${USERNAME}/.local/bin:${PATH}"
ENV CHROME_BINARY_LOCATION=/usr/bin/chromium

USER $USERNAME

CMD ["python", "wait.py"]
38 changes: 38 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "autopve-dev",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"cschleiden.vscode-github-actions",
"esbenp.prettier-vscode",
"littlefoxteam.vscode-python-test-adapter",
"ms-python.python",
"samuelcolvin.jinjahtml",
"Vue.volar"
],
"settings": {
"python.testing.cwd": "/workspaces/autopve/",
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.defaultInterpreterPath": "/usr/local/bin/python3",
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.shell.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash (container default)": {
"path": "/usr/bin/bash",
"overrideName": true
}
}
}
}
},
// More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode",
"postCreateCommand": "/usr/local/bin/python3 -m pip install -r requirements-test.txt"
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ __pycache__/
logs/
notes/
mpl/
screenshots/
mysecret.py
test.py
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ notes/
mpl/
mysecret.py
test.py
mount/
mount/
screenshots/
Empty file removed __init__.py
Empty file.
23 changes: 15 additions & 8 deletions autopve/content.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import asyncio
from nicegui import ui # type: ignore
from autopve import elements as el
import autopve.logo as logo
from autopve.tabs import Tab
from autopve import logo as logo
from autopve.tabs.settings import Global, Network, Disk
from autopve.tabs.history import History
from autopve.tabs.system import System
from autopve.tabs.system import MustContain, MustNotContain
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -42,7 +41,8 @@ def _build(self):
self._tab["disk"] = ui.tab(name="Disk").classes("text-secondary")
self._tab["history"] = ui.tab(name="History").classes("text-secondary")
if self._answer != "Default":
self._tab["system"] = ui.tab(name="System").classes("text-secondary")
self._tab["must_contain"] = ui.tab(name="Must Contain").classes("text-secondary")
self._tab["must_not_contain"] = ui.tab(name="Must Not Contain").classes("text-secondary")
with ui.row().classes("items-center"):
self._answer_display = ui.label(self._answer).classes("text-secondary text-h4")
logo.show()
Expand All @@ -52,7 +52,11 @@ def _build(self):

async def _tab_changed(self, e):
if e.value == "History":
self._history.update_history()
self._history.update()
elif e.value == "Must Contain":
self._must_contain.update()
elif e.value == "Must Not Contain":
self._must_not_contain.update()

def _build_tab_panels(self):
self._tab_panels.clear()
Expand All @@ -62,7 +66,8 @@ def _build_tab_panels(self):
self._disk_content = el.ContentTabPanel(self._tab["disk"])
self._history_content = el.ContentTabPanel(self._tab["history"])
if self._answer != "Default":
self._system_content = el.ContentTabPanel(self._tab["system"])
self._must_contain_content = el.ContentTabPanel(self._tab["must_contain"])
self._must_not_contain_content = el.ContentTabPanel(self._tab["must_not_contain"])
with self._global_content:
self._global = Global(answer=self._answer)
with self._network_content:
Expand All @@ -72,8 +77,10 @@ def _build_tab_panels(self):
with self._history_content:
self._history = History(answer=self._answer)
if self._answer != "Default":
with self._system_content:
self._system = System(answer=self._answer)
with self._must_contain_content:
self._must_contain = MustContain(answer=self._answer)
with self._must_not_contain_content:
self._must_not_contain = MustNotContain(answer=self._answer)

async def answer_selected(self, name):
self._answer = name
Expand Down
12 changes: 9 additions & 3 deletions autopve/drawer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional
from nicegui.events import KeyEventArguments
from nicegui import ui # type: ignore
from autopve import elements as el
from autopve import storage
from autopve.tabs import Tab

import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -88,7 +87,7 @@ async def _display_answer_dialog(self, name=""):
save = None

with ui.dialog() as answer_dialog, el.Card():
with el.DBody(height="[95vh]", width="[360px]"):
with el.DBody(height="fit", width="[320px]"):
with el.WColumn():
all_answers = list(storage.answers.keys())
for answer in list(storage.answers.keys()):
Expand All @@ -106,16 +105,23 @@ def answer_check(value: str) -> Optional[bool]:
return False
return None

def enter_submit(e: KeyEventArguments) -> None:
if e.key == "Enter" and save_ea.no_errors is True:
answer_dialog.submit("save")

answer_input = el.VInput(label="answer", value=" ", invalid_characters="""'`"$\\;&<>|(){}""", invalid_values=all_answers, check=answer_check, max_length=20)
save_ea = el.ErrorAggregator(answer_input)
el.DButton("SAVE", on_click=lambda: answer_dialog.submit("save")).bind_enabled_from(save_ea, "no_errors")
ui.keyboard(on_key=enter_submit, ignore=[])
answer_input.value = name

result = await answer_dialog
if result == "save":
answer = answer_input.value.strip()
if len(answer) > 0 and name != "Default":
storage.answer(answer)
if name in storage.answers:
storage.answers[answer] = storage.answer(name, copy=True)
del storage.answers[name]
for row in self._table.rows:
if name == row["name"]:
Expand Down
74 changes: 0 additions & 74 deletions autopve/page.py

This file was deleted.

80 changes: 8 additions & 72 deletions autopve/storage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Any, Dict, Literal
from typing import Any, Dict
import json
from nicegui import app
import logging

logger = logging.getLogger(__name__)


configs_version = int(102)
configs_version = int(100)
configs_version_string = f"config_{configs_version}"
root = app.storage.general.get(configs_version_string, None)
if root is None:
Expand Down Expand Up @@ -35,73 +34,10 @@
}


def answer(name: str) -> dict:
def answer(name: str, copy: bool = False) -> dict:
if name not in answers:
answers[name] = {}
return answers[name]


# def algo(answer_name: str) -> dict:
# h = answer(answer_name)
# if "algo" not in h:
# h["algo"] = {}
# return h["algo"]


# def algo_sensor(answer_name: str, sensor: str) -> dict:
# a = algo(answer_name)
# if sensor not in a:
# a[sensor] = {}
# if "type" not in a[sensor]:
# a[sensor]["type"] = "curve"
# return a[sensor]


# def curve(answer_name: str, sensor: str) -> dict:
# s = algo_sensor(answer_name, sensor)
# if "curve" not in s:
# s["curve"] = {}
# return s["curve"]


# def curve_speed(answer_name: str, sensor: str, default=None) -> dict:
# c = curve(answer_name, sensor)
# if "speed" not in c:
# if default is None:
# c["speed"] = {
# "Min": None,
# "Low": None,
# "Medium": None,
# "High": None,
# "Max": None,
# }
# else:
# c["speed"] = default
# return c["speed"]


# def curve_temp(answer_name: str, sensor: str, default=None) -> dict:
# c = curve(answer_name, sensor)
# if "temp" not in c:
# if default is None:
# c["temp"] = {
# "Min": 30,
# "Low": 40,
# "Medium": 50,
# "High": 60,
# "Max": 70,
# }
# else:
# c["temp"] = default
# return c["temp"]


# def pid(answer_name: str, sensor: str) -> Dict[str, float]:
# s = algo_sensor(answer_name, sensor)
# if "pid" not in s:
# s["pid"] = {"Kp": 5, "Ki": 0.01, "Kd": 0.1, "Target": 40}
# return s["pid"]


# def pid_coefficient(answer_name: str, sensor: str, coefficient: Literal["Kp", "Ki", "Kd", "Target"]) -> float:
# return pid(answer_name, sensor)[coefficient]
if copy is False:
return answers[name]
else:
return json.loads(json.dumps(answers[name]))
Loading

0 comments on commit 005af9e

Please sign in to comment.