Task ID: task_e_682f2ee890948323991476bc0d433096
⠹ Preparing packages... (0/33)
pyee ------------------------------ 14.91 KiB/15.36 KiB
itsdangerous ------------------------------ 14.88 KiB/15.85 KiB
pluggy ------------------------------ 20.06 KiB/20.06 KiB
markupsafe ------------------------------ 22.58 KiB/22.58 KiB
execnet ------------------------------ 32.00 KiB/39.66 KiB
pytest-xdist ------------------------------ 30.90 KiB/45.03 KiB
requests ------------------------------ 30.88 KiB/63.41 KiB
packaging ------------------------------ 32.00 KiB/64.91 KiB
idna ------------------------------ 32.00 KiB/68.79 KiB
click ------------------------------ 80.00 KiB/99.76 KiB
flask ------------------------------ 62.88 KiB/100.88 KiB
urllib3 ------------------------------ 63.66 KiB/125.66 KiB
jinja2 ------------------------------ 48.00 KiB/131.74 KiB
charset-normalizer ------------------------------ 32.00 KiB/145.08 KiB
certifi ------------------------------ 155.88 KiB/155.88 KiB
werkzeug ------------------------------ 78.59 KiB/219.24 KiB
python-dateutil ------------------------------ 30.86 KiB/224.50 KiB
pytest ------------------------------ 32.00 KiB/335.58 KiB
greenlet ------------------------------ 48.00 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 220.07 KiB/11.02 MiB
duckdb ------------------------------ 30.90 KiB/19.27 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pyee ------------------------------ 14.91 KiB/15.36 KiB
itsdangerous ------------------------------ 14.88 KiB/15.85 KiB
pluggy ------------------------------ 20.06 KiB/20.06 KiB
markupsafe ------------------------------ 22.58 KiB/22.58 KiB
execnet ------------------------------ 32.00 KiB/39.66 KiB
pytest-xdist ------------------------------ 30.90 KiB/45.03 KiB
requests ------------------------------ 30.88 KiB/63.41 KiB
packaging ------------------------------ 48.00 KiB/64.91 KiB
idna ------------------------------ 64.00 KiB/68.79 KiB
click ------------------------------ 96.00 KiB/99.76 KiB
flask ------------------------------ 62.88 KiB/100.88 KiB
urllib3 ------------------------------ 63.66 KiB/125.66 KiB
jinja2 ------------------------------ 78.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 77.41 KiB/145.08 KiB
werkzeug ------------------------------ 94.59 KiB/219.24 KiB
python-dateutil ------------------------------ 30.86 KiB/224.50 KiB
pytest ------------------------------ 48.00 KiB/335.58 KiB
greenlet ------------------------------ 62.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 268.07 KiB/11.02 MiB
duckdb ------------------------------ 78.90 KiB/19.27 MiB
playwright ------------------------------ 32.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pyee ------------------------------ 15.36 KiB/15.36 KiB
pluggy ------------------------------ 20.06 KiB/20.06 KiB
markupsafe ------------------------------ 22.58 KiB/22.58 KiB
execnet ------------------------------ 32.00 KiB/39.66 KiB
pytest-xdist ------------------------------ 30.90 KiB/45.03 KiB
requests ------------------------------ 46.88 KiB/63.41 KiB
packaging ------------------------------ 48.00 KiB/64.91 KiB
idna ------------------------------ 64.00 KiB/68.79 KiB
click ------------------------------ 96.00 KiB/99.76 KiB
flask ------------------------------ 62.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 78.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 109.41 KiB/145.08 KiB
werkzeug ------------------------------ 94.59 KiB/219.24 KiB
python-dateutil ------------------------------ 46.86 KiB/224.50 KiB
pytest ------------------------------ 64.00 KiB/335.58 KiB
greenlet ------------------------------ 62.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 300.07 KiB/11.02 MiB
duckdb ------------------------------ 110.90 KiB/19.27 MiB
playwright ------------------------------ 32.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pyee ------------------------------ 15.36 KiB/15.36 KiB
pluggy ------------------------------ 20.06 KiB/20.06 KiB
execnet ------------------------------ 32.00 KiB/39.66 KiB
pytest-xdist ------------------------------ 30.90 KiB/45.03 KiB
requests ------------------------------ 46.88 KiB/63.41 KiB
packaging ------------------------------ 48.00 KiB/64.91 KiB
idna ------------------------------ 64.00 KiB/68.79 KiB
click ------------------------------ 96.00 KiB/99.76 KiB
flask ------------------------------ 62.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 78.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 109.41 KiB/145.08 KiB
werkzeug ------------------------------ 94.59 KiB/219.24 KiB
python-dateutil ------------------------------ 46.86 KiB/224.50 KiB
pytest ------------------------------ 64.00 KiB/335.58 KiB
greenlet ------------------------------ 62.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 300.07 KiB/11.02 MiB
duckdb ------------------------------ 110.90 KiB/19.27 MiB
playwright ------------------------------ 32.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pluggy ------------------------------ 20.06 KiB/20.06 KiB
execnet ------------------------------ 32.00 KiB/39.66 KiB
pytest-xdist ------------------------------ 30.90 KiB/45.03 KiB
requests ------------------------------ 46.88 KiB/63.41 KiB
packaging ------------------------------ 48.00 KiB/64.91 KiB
idna ------------------------------ 64.00 KiB/68.79 KiB
click ------------------------------ 96.00 KiB/99.76 KiB
flask ------------------------------ 62.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 78.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 109.41 KiB/145.08 KiB
werkzeug ------------------------------ 94.59 KiB/219.24 KiB
python-dateutil ------------------------------ 46.86 KiB/224.50 KiB
pytest ------------------------------ 64.00 KiB/335.58 KiB
greenlet ------------------------------ 78.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 300.07 KiB/11.02 MiB
duckdb ------------------------------ 110.90 KiB/19.27 MiB
playwright ------------------------------ 32.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
execnet ------------------------------ 32.00 KiB/39.66 KiB
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
requests ------------------------------ 46.88 KiB/63.41 KiB
packaging ------------------------------ 48.00 KiB/64.91 KiB
idna ------------------------------ 68.79 KiB/68.79 KiB
click ------------------------------ 99.76 KiB/99.76 KiB
flask ------------------------------ 62.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 94.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 125.41 KiB/145.08 KiB
werkzeug ------------------------------ 94.59 KiB/219.24 KiB
python-dateutil ------------------------------ 46.86 KiB/224.50 KiB
pytest ------------------------------ 80.00 KiB/335.58 KiB
greenlet ------------------------------ 110.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 348.07 KiB/11.02 MiB
duckdb ------------------------------ 142.90 KiB/19.27 MiB
playwright ------------------------------ 32.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
execnet ------------------------------ 39.66 KiB/39.66 KiB
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
requests ------------------------------ 46.88 KiB/63.41 KiB
packaging ------------------------------ 64.91 KiB/64.91 KiB
click ------------------------------ 99.76 KiB/99.76 KiB
flask ------------------------------ 78.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 94.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 125.41 KiB/145.08 KiB
werkzeug ------------------------------ 94.59 KiB/219.24 KiB
python-dateutil ------------------------------ 46.86 KiB/224.50 KiB
pytest ------------------------------ 80.00 KiB/335.58 KiB
greenlet ------------------------------ 174.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 380.07 KiB/11.02 MiB
duckdb ------------------------------ 206.90 KiB/19.27 MiB
playwright ------------------------------ 32.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
execnet ------------------------------ 39.66 KiB/39.66 KiB
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
requests ------------------------------ 63.41 KiB/63.41 KiB
packaging ------------------------------ 64.91 KiB/64.91 KiB
flask ------------------------------ 78.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 110.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 141.41 KiB/145.08 KiB
werkzeug ------------------------------ 110.59 KiB/219.24 KiB
python-dateutil ------------------------------ 62.86 KiB/224.50 KiB
pytest ------------------------------ 96.00 KiB/335.58 KiB
greenlet ------------------------------ 190.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 412.07 KiB/11.02 MiB
duckdb ------------------------------ 222.90 KiB/19.27 MiB
playwright ------------------------------ 48.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
execnet ------------------------------ 39.66 KiB/39.66 KiB
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
requests ------------------------------ 63.41 KiB/63.41 KiB
packaging ------------------------------ 64.91 KiB/64.91 KiB
flask ------------------------------ 78.88 KiB/100.88 KiB
urllib3 ------------------------------ 79.66 KiB/125.66 KiB
jinja2 ------------------------------ 110.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 141.41 KiB/145.08 KiB
werkzeug ------------------------------ 110.59 KiB/219.24 KiB
python-dateutil ------------------------------ 77.81 KiB/224.50 KiB
pytest ------------------------------ 112.00 KiB/335.58 KiB
greenlet ------------------------------ 222.38 KiB/589.71 KiB
pyright ------------------------------ 14.91 KiB/5.31 MiB
ruff ------------------------------ 444.07 KiB/11.02 MiB
duckdb ------------------------------ 272.00 KiB/19.27 MiB
playwright ------------------------------ 48.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
execnet ------------------------------ 39.66 KiB/39.66 KiB
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
packaging ------------------------------ 64.91 KiB/64.91 KiB
flask ------------------------------ 94.88 KiB/100.88 KiB
urllib3 ------------------------------ 95.66 KiB/125.66 KiB
jinja2 ------------------------------ 126.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 141.41 KiB/145.08 KiB
werkzeug ------------------------------ 126.59 KiB/219.24 KiB
python-dateutil ------------------------------ 141.81 KiB/224.50 KiB
pytest ------------------------------ 112.00 KiB/335.58 KiB
greenlet ------------------------------ 318.38 KiB/589.71 KiB
pyright ------------------------------ 46.91 KiB/5.31 MiB
ruff ------------------------------ 524.07 KiB/11.02 MiB
duckdb ------------------------------ 352.00 KiB/19.27 MiB
playwright ------------------------------ 48.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
packaging ------------------------------ 64.91 KiB/64.91 KiB
flask ------------------------------ 94.88 KiB/100.88 KiB
urllib3 ------------------------------ 95.66 KiB/125.66 KiB
jinja2 ------------------------------ 126.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 141.41 KiB/145.08 KiB
werkzeug ------------------------------ 126.59 KiB/219.24 KiB
python-dateutil ------------------------------ 173.81 KiB/224.50 KiB
pytest ------------------------------ 124.99 KiB/335.58 KiB
greenlet ------------------------------ 334.38 KiB/589.71 KiB
pyright ------------------------------ 78.91 KiB/5.31 MiB
ruff ------------------------------ 556.07 KiB/11.02 MiB
duckdb ------------------------------ 368.00 KiB/19.27 MiB
playwright ------------------------------ 48.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pytest-xdist ------------------------------ 45.03 KiB/45.03 KiB
flask ------------------------------ 94.88 KiB/100.88 KiB
urllib3 ------------------------------ 95.66 KiB/125.66 KiB
jinja2 ------------------------------ 126.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 141.41 KiB/145.08 KiB
werkzeug ------------------------------ 126.59 KiB/219.24 KiB
python-dateutil ------------------------------ 173.81 KiB/224.50 KiB
pytest ------------------------------ 124.99 KiB/335.58 KiB
greenlet ------------------------------ 334.38 KiB/589.71 KiB
pyright ------------------------------ 78.91 KiB/5.31 MiB
ruff ------------------------------ 556.07 KiB/11.02 MiB
duckdb ------------------------------ 368.00 KiB/19.27 MiB
playwright ------------------------------ 48.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
flask ------------------------------ 94.88 KiB/100.88 KiB
urllib3 ------------------------------ 95.66 KiB/125.66 KiB
jinja2 ------------------------------ 126.16 KiB/131.74 KiB
charset-normalizer ------------------------------ 141.41 KiB/145.08 KiB
werkzeug ------------------------------ 126.59 KiB/219.24 KiB
python-dateutil ------------------------------ 189.81 KiB/224.50 KiB
pytest ------------------------------ 140.99 KiB/335.58 KiB
greenlet ------------------------------ 350.38 KiB/589.71 KiB
pyright ------------------------------ 94.91 KiB/5.31 MiB
ruff ------------------------------ 572.07 KiB/11.02 MiB
duckdb ------------------------------ 384.00 KiB/19.27 MiB
playwright ------------------------------ 48.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
flask ------------------------------ 100.88 KiB/100.88 KiB
urllib3 ------------------------------ 111.66 KiB/125.66 KiB
jinja2 ------------------------------ 131.74 KiB/131.74 KiB
werkzeug ------------------------------ 142.59 KiB/219.24 KiB
python-dateutil ------------------------------ 221.81 KiB/224.50 KiB
pytest ------------------------------ 172.99 KiB/335.58 KiB
greenlet ------------------------------ 446.38 KiB/589.71 KiB
pyright ------------------------------ 190.91 KiB/5.31 MiB
ruff ------------------------------ 684.07 KiB/11.02 MiB
duckdb ------------------------------ 480.00 KiB/19.27 MiB
playwright ------------------------------ 64.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
flask ------------------------------ 100.88 KiB/100.88 KiB
urllib3 ------------------------------ 111.66 KiB/125.66 KiB
werkzeug ------------------------------ 142.59 KiB/219.24 KiB
python-dateutil ------------------------------ 221.81 KiB/224.50 KiB
pytest ------------------------------ 172.99 KiB/335.58 KiB
greenlet ------------------------------ 462.38 KiB/589.71 KiB
pyright ------------------------------ 206.91 KiB/5.31 MiB
ruff ------------------------------ 684.07 KiB/11.02 MiB
duckdb ------------------------------ 496.00 KiB/19.27 MiB
playwright ------------------------------ 64.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
urllib3 ------------------------------ 111.66 KiB/125.66 KiB
werkzeug ------------------------------ 142.59 KiB/219.24 KiB
python-dateutil ------------------------------ 221.81 KiB/224.50 KiB
pytest ------------------------------ 188.99 KiB/335.58 KiB
greenlet ------------------------------ 462.38 KiB/589.71 KiB
pyright ------------------------------ 222.91 KiB/5.31 MiB
ruff ------------------------------ 700.07 KiB/11.02 MiB
duckdb ------------------------------ 512.00 KiB/19.27 MiB
playwright ------------------------------ 64.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
urllib3 ------------------------------ 125.66 KiB/125.66 KiB
werkzeug ------------------------------ 142.59 KiB/219.24 KiB
pytest ------------------------------ 188.99 KiB/335.58 KiB
greenlet ------------------------------ 462.38 KiB/589.71 KiB
pyright ------------------------------ 270.91 KiB/5.31 MiB
ruff ------------------------------ 748.07 KiB/11.02 MiB
duckdb ------------------------------ 560.00 KiB/19.27 MiB
playwright ------------------------------ 80.00 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
werkzeug ------------------------------ 158.59 KiB/219.24 KiB
pytest ------------------------------ 204.99 KiB/335.58 KiB
greenlet ------------------------------ 478.38 KiB/589.71 KiB
pyright ------------------------------ 408.56 KiB/5.31 MiB
ruff ------------------------------ 892.07 KiB/11.02 MiB
duckdb ------------------------------ 720.00 KiB/19.27 MiB
playwright ------------------------------ 95.77 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
werkzeug ------------------------------ 174.59 KiB/219.24 KiB
pytest ------------------------------ 220.99 KiB/335.58 KiB
greenlet ------------------------------ 478.38 KiB/589.71 KiB
pyright ------------------------------ 520.56 KiB/5.31 MiB
ruff ------------------------------ 1004.07 KiB/11.02 MiB
duckdb ------------------------------ 832.00 KiB/19.27 MiB
playwright ------------------------------ 95.77 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
pytest ------------------------------ 284.99 KiB/335.58 KiB
greenlet ------------------------------ 494.38 KiB/589.71 KiB
pyright ------------------------------ 616.56 KiB/5.31 MiB
ruff ------------------------------ 1.25 MiB/11.02 MiB
duckdb ------------------------------ 1.08 MiB/19.27 MiB
playwright ------------------------------ 175.77 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
greenlet ------------------------------ 542.38 KiB/589.71 KiB
pyright ------------------------------ 712.56 KiB/5.31 MiB
ruff ------------------------------ 1.60 MiB/11.02 MiB
duckdb ------------------------------ 1.45 MiB/19.27 MiB
playwright ------------------------------ 511.77 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠹ Preparing packages... (0/33)
greenlet ------------------------------ 574.38 KiB/589.71 KiB
pyright ------------------------------ 840.56 KiB/5.31 MiB
ruff ------------------------------ 1.90 MiB/11.02 MiB
duckdb ------------------------------ 1.73 MiB/19.27 MiB
playwright ------------------------------ 815.77 KiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
pyright ------------------------------ 920.56 KiB/5.31 MiB
ruff ------------------------------ 2.15 MiB/11.02 MiB
duckdb ------------------------------ 2.00 MiB/19.27 MiB
playwright ------------------------------ 1.03 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
pyright ------------------------------ 1.19 MiB/5.31 MiB
ruff ------------------------------ 2.90 MiB/11.02 MiB
duckdb ------------------------------ 2.76 MiB/19.27 MiB
playwright ------------------------------ 1.80 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
text-unidecode ------------------------------ 14.83 KiB/76.32 KiB
pyright ------------------------------ 1.42 MiB/5.31 MiB
ruff ------------------------------ 3.48 MiB/11.02 MiB
duckdb ------------------------------ 3.31 MiB/19.27 MiB
playwright ------------------------------ 2.36 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
pyright ------------------------------ 1.50 MiB/5.31 MiB
ruff ------------------------------ 3.76 MiB/11.02 MiB
duckdb ------------------------------ 3.59 MiB/19.27 MiB
playwright ------------------------------ 2.62 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
pyright ------------------------------ 1.58 MiB/5.31 MiB
ruff ------------------------------ 3.97 MiB/11.02 MiB
duckdb ------------------------------ 3.81 MiB/19.27 MiB
playwright ------------------------------ 2.86 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
pyright ------------------------------ 1.81 MiB/5.31 MiB
ruff ------------------------------ 5.20 MiB/11.02 MiB
duckdb ------------------------------ 5.05 MiB/19.27 MiB
playwright ------------------------------ 4.11 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠸ Preparing packages... (25/33)
pyright ------------------------------ 1.87 MiB/5.31 MiB
ruff ------------------------------ 6.48 MiB/11.02 MiB
duckdb ------------------------------ 6.36 MiB/19.27 MiB
playwright ------------------------------ 5.36 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠼ Preparing packages... (28/33)
pyright ------------------------------ 1.93 MiB/5.31 MiB
ruff ------------------------------ 7.92 MiB/11.02 MiB
duckdb ------------------------------ 7.76 MiB/19.27 MiB
playwright ------------------------------ 6.78 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠼ Preparing packages... (28/33)
pyright ------------------------------ 1.98 MiB/5.31 MiB
ruff ------------------------------ 9.04 MiB/11.02 MiB
duckdb ------------------------------ 8.89 MiB/19.27 MiB
playwright ------------------------------ 7.92 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠼ Preparing packages... (28/33)
pyright ------------------------------ 2.06 MiB/5.31 MiB
ruff ------------------------------ 10.41 MiB/11.02 MiB
duckdb ------------------------------ 10.28 MiB/19.27 MiB
playwright ------------------------------ 9.31 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠼ Preparing packages... (28/33)
pyright ------------------------------ 2.09 MiB/5.31 MiB
duckdb ------------------------------ 10.90 MiB/19.27 MiB
playwright ------------------------------ 9.96 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠼ Preparing packages... (28/33)
pyright ------------------------------ 2.12 MiB/5.31 MiB
duckdb ------------------------------ 12.12 MiB/19.27 MiB
playwright ------------------------------ 11.17 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠴ Preparing packages... (29/33)
pyright ------------------------------ 2.17 MiB/5.31 MiB
duckdb ------------------------------ 14.34 MiB/19.27 MiB
playwright ------------------------------ 13.40 MiB/43.05 MiB
Building scubaduck @ file:///workspace/scubaduck
⠴ Preparing packages... (29/33)
pyright ------------------------------ 2.20 MiB/5.31 MiB
duckdb ------------------------------ 16.43 MiB/19.27 MiB
playwright ------------------------------ 15.44 MiB/43.05 MiB
Built scubaduck @ file:///workspace/scubaduck
⠴ Preparing packages... (29/33)
pyright ------------------------------ 2.20 MiB/5.31 MiB
duckdb ------------------------------ 16.43 MiB/19.27 MiB
playwright ------------------------------ 15.47 MiB/43.05 MiB
⠴ Preparing packages... (29/33)
pyright ------------------------------ 2.23 MiB/5.31 MiB
duckdb ------------------------------ 18.68 MiB/19.27 MiB
playwright ------------------------------ 17.72 MiB/43.05 MiB
⠴ Preparing packages... (29/33)
pyright ------------------------------ 2.25 MiB/5.31 MiB
playwright ------------------------------ 19.90 MiB/43.05 MiB
⠴ Preparing packages... (29/33)
pyright ------------------------------ 2.26 MiB/5.31 MiB
playwright ------------------------------ 20.95 MiB/43.05 MiB
⠦ Preparing packages... (31/33)
pyright ------------------------------ 2.40 MiB/5.31 MiB
playwright ------------------------------ 25.66 MiB/43.05 MiB
⠦ Preparing packages... (31/33)
pyright ------------------------------ 2.51 MiB/5.31 MiB
playwright ------------------------------ 27.59 MiB/43.05 MiB
⠦ Preparing packages... (31/33)
pyright ------------------------------ 2.64 MiB/5.31 MiB
playwright ------------------------------ 29.20 MiB/43.05 MiB
⠧ Preparing packages... (31/33)
pyright ------------------------------ 2.77 MiB/5.31 MiB
playwright ------------------------------ 30.95 MiB/43.05 MiB
⠧ Preparing packages... (31/33)
pyright ------------------------------ 2.90 MiB/5.31 MiB
playwright ------------------------------ 32.67 MiB/43.05 MiB
⠧ Preparing packages... (31/33)
pyright ------------------------------ 3.04 MiB/5.31 MiB
playwright ------------------------------ 34.47 MiB/43.05 MiB
⠧ Preparing packages... (31/33)
pyright ------------------------------ 3.13 MiB/5.31 MiB
playwright ------------------------------ 36.23 MiB/43.05 MiB
⠧ Preparing packages... (31/33)
pyright ------------------------------ 3.22 MiB/5.31 MiB
playwright ------------------------------ 37.84 MiB/43.05 MiB
⠇ Preparing packages... (31/33)
pyright ------------------------------ 3.32 MiB/5.31 MiB
playwright ------------------------------ 39.78 MiB/43.05 MiB
⠇ Preparing packages... (31/33)
pyright ------------------------------ 3.44 MiB/5.31 MiB
playwright ------------------------------ 40.98 MiB/43.05 MiB
⠇ Preparing packages... (31/33)
pyright ------------------------------ 3.65 MiB/5.31 MiB
playwright ------------------------------ 42.20 MiB/43.05 MiB
⠇ Preparing packages... (31/33)
pyright ------------------------------ 3.69 MiB/5.31 MiB
⠇ Preparing packages... (31/33)
pyright ------------------------------ 3.81 MiB/5.31 MiB
⠋ Preparing packages... (32/33)
pyright ------------------------------ 4.12 MiB/5.31 MiB
⠋ Preparing packages... (32/33)
pyright ------------------------------ 4.26 MiB/5.31 MiB
⠋ Preparing packages... (32/33)
pyright ------------------------------ 4.45 MiB/5.31 MiB
⠋ Preparing packages... (32/33)
pyright ------------------------------ 4.57 MiB/5.31 MiB
⠙ Preparing packages... (32/33)
Prepared 33 packages in 1.81s
░░░░░░░░░░░░░░░░░░░░ [0/0] Installing wheels...
░░░░░░░░░░░░░░░░░░░░ [0/33] Installing wheels...
░░░░░░░░░░░░░░░░░░░░ [0/33] markupsafe==3.0.2
░░░░░░░░░░░░░░░░░░░░ [1/33] markupsafe==3.0.2
░░░░░░░░░░░░░░░░░░░░ [1/33] pytest-playwright==0.7.0
█░░░░░░░░░░░░░░░░░░░ [2/33] pytest-playwright==0.7.0
█░░░░░░░░░░░░░░░░░░░ [2/33] packaging==25.0
█░░░░░░░░░░░░░░░░░░░ [3/33] packaging==25.0
█░░░░░░░░░░░░░░░░░░░ [3/33] itsdangerous==2.2.0
██░░░░░░░░░░░░░░░░░░ [4/33] itsdangerous==2.2.0
██░░░░░░░░░░░░░░░░░░ [4/33] typing-extensions==4.13.2
███░░░░░░░░░░░░░░░░░ [5/33] typing-extensions==4.13.2
███░░░░░░░░░░░░░░░░░ [5/33] pyee==13.0.0
███░░░░░░░░░░░░░░░░░ [6/33] pyee==13.0.0
███░░░░░░░░░░░░░░░░░ [6/33] pytest-xdist==3.6.1
████░░░░░░░░░░░░░░░░ [7/33] pytest-xdist==3.6.1
████░░░░░░░░░░░░░░░░ [7/33] six==1.17.0
████░░░░░░░░░░░░░░░░ [8/33] six==1.17.0
████░░░░░░░░░░░░░░░░ [8/33] pluggy==1.6.0
█████░░░░░░░░░░░░░░░ [9/33] pluggy==1.6.0
███████████████████░ [32/33] pyright==1.1.400
Installed 33 packages in 79ms
+ blinker==1.9.0
+ certifi==2025.4.26
+ charset-normalizer==3.4.2
+ click==8.2.0
+ duckdb==1.2.2
+ execnet==2.1.1
+ flask==3.1.1
+ greenlet==3.2.2
+ idna==3.10
+ iniconfig==2.1.0
+ itsdangerous==2.2.0
+ jinja2==3.1.6
+ markupsafe==3.0.2
+ nodeenv==1.9.1
+ packaging==25.0
+ playwright==1.52.0
+ pluggy==1.6.0
+ pyee==13.0.0
+ pyright==1.1.400
+ pytest==8.3.5
+ pytest-base-url==2.1.0
+ pytest-playwright==0.7.0
+ pytest-xdist==3.6.1
+ python-dateutil==2.9.0.post0
+ python-slugify==8.0.4
+ requests==2.32.3
+ ruff==0.11.10
+ scubaduck==0.1.0 (from file:///workspace/scubaduck)
+ six==1.17.0
+ text-unidecode==1.3
+ typing-extensions==4.13.2
+ urllib3==2.4.0
+ werkzeug==3.1.3
++ source .venv/bin/activate
+++ '[' -z '' ']'
+++ '[' -n x ']'
+++ SCRIPT_PATH=.venv/bin/activate
+++ '[' .venv/bin/activate = /tmp/2W8Jo3-setup_script.sh ']'
+++ deactivate nondestructive
+++ unset -f pydoc
+++ '[' -z '' ']'
+++ '[' -z '' ']'
+++ hash -r
+++ '[' -z '' ']'
+++ unset VIRTUAL_ENV
+++ unset VIRTUAL_ENV_PROMPT
+++ '[' '!' nondestructive = nondestructive ']'
+++ VIRTUAL_ENV=/workspace/scubaduck/.venv
+++ '[' linux-gnu = cygwin ']'
+++ '[' linux-gnu = msys ']'
+++ export VIRTUAL_ENV
+++ '[' -z '' ']'
+++ unset SCRIPT_PATH
+++ _OLD_VIRTUAL_PATH=/root/.cargo/bin:/root/.rbenv/shims:/root/.rbenv/bin:/root/.rbenv/shims:/root/.local/share/swiftly/bin:/root/.bun/bin:/root/.nvm/versions/node/v22.15.1/bin:/root/.pyenv/shims:3441PYENV_ROOT/shims:/root/.pyenv/bin:/usr/local/go/bin:/root/go/bin:/root/.rbenv/bin:/root/.rbenv/shims:/root/.bun/bin:/root/.local/bin:/root/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+++ PATH=/workspace/scubaduck/.venv/bin:/root/.cargo/bin:/root/.rbenv/shims:/root/.rbenv/bin:/root/.rbenv/shims:/root/.local/share/swiftly/bin:/root/.bun/bin:/root/.nvm/versions/node/v22.15.1/bin:/root/.pyenv/shims:3441PYENV_ROOT/shims:/root/.pyenv/bin:/usr/local/go/bin:/root/go/bin:/root/.rbenv/bin:/root/.rbenv/shims:/root/.bun/bin:/root/.local/bin:/root/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+++ export PATH
+++ '[' xscubaduck '!=' x ']'
+++ VIRTUAL_ENV_PROMPT='(scubaduck) '
+++ export VIRTUAL_ENV_PROMPT
+++ '[' -z '' ']'
+++ '[' -z '' ']'
+++ _OLD_VIRTUAL_PS1=
+++ PS1='(scubaduck) '
+++ export PS1
+++ alias pydoc
+++ true
+++ hash -r
++ python -c 'import os; import duckdb; con = duckdb.connect(); con.execute(f"SET http_proxy = '\''{os.getenv("HTTP_PROXY")}'\''"); con.execute("INSTALL '\''sqlite'\'';")'
++ playwright install chromium
Downloading Chromium 136.0.7103.25 (playwright build v1169) from https://cdn.playwright.dev/dbazure/download/playwright/builds/chromium/1169/chromium-linux.zip
167.7 MiB [] 0% 0.0s167.7 MiB [] 0% 25.5s167.7 MiB [] 0% 19.0s167.7 MiB [] 0% 9.6s167.7 MiB [] 1% 5.6s167.7 MiB [] 2% 3.9s167.7 MiB [] 3% 2.9s167.7 MiB [] 4% 2.5s167.7 MiB [] 5% 2.3s167.7 MiB [] 6% 2.3s167.7 MiB [] 6% 2.2s167.7 MiB [] 8% 1.9s167.7 MiB [] 9% 1.8s167.7 MiB [] 11% 1.7s167.7 MiB [] 13% 1.5s167.7 MiB [] 15% 1.4s167.7 MiB [] 16% 1.3s167.7 MiB [] 18% 1.2s167.7 MiB [] 19% 1.2s167.7 MiB [] 21% 1.1s167.7 MiB [] 22% 1.1s167.7 MiB [] 24% 1.0s167.7 MiB [] 27% 1.0s167.7 MiB [] 28% 0.9s167.7 MiB [] 30% 0.9s167.7 MiB [] 32% 0.8s167.7 MiB [] 34% 0.8s167.7 MiB [] 36% 0.8s167.7 MiB [] 38% 0.7s167.7 MiB [] 40% 0.7s167.7 MiB [] 42% 0.7s167.7 MiB [] 44% 0.6s167.7 MiB [] 46% 0.6s167.7 MiB [] 48% 0.6s167.7 MiB [] 50% 0.5s167.7 MiB [] 52% 0.5s167.7 MiB [] 54% 0.5s167.7 MiB [] 56% 0.5s167.7 MiB [] 58% 0.4s167.7 MiB [] 59% 0.4s167.7 MiB [] 61% 0.4s167.7 MiB [] 62% 0.4s167.7 MiB [] 63% 0.4s167.7 MiB [] 65% 0.4s167.7 MiB [] 67% 0.3s167.7 MiB [] 69% 0.3s167.7 MiB [] 71% 0.3s167.7 MiB [] 73% 0.3s167.7 MiB [] 74% 0.3s167.7 MiB [] 76% 0.2s167.7 MiB [] 78% 0.2s167.7 MiB [] 81% 0.2s167.7 MiB [] 83% 0.2s167.7 MiB [] 85% 0.1s167.7 MiB [] 87% 0.1s167.7 MiB [] 90% 0.1s167.7 MiB [] 92% 0.1s167.7 MiB [] 94% 0.1s167.7 MiB [] 97% 0.0s167.7 MiB [] 98% 0.0s167.7 MiB [] 100% 0.0s
Chromium 136.0.7103.25 (playwright build v1169) downloaded to /root/.cache/ms-playwright/chromium-1169
Downloading FFMPEG playwright build v1011 from https://cdn.playwright.dev/dbazure/download/playwright/builds/ffmpeg/1011/ffmpeg-linux.zip
2.3 MiB [] 0% 0.0s2.3 MiB [] 5% 0.3s2.3 MiB [] 15% 0.2s2.3 MiB [] 31% 0.1s2.3 MiB [] 68% 0.0s2.3 MiB [] 100% 0.0s
FFMPEG playwright build v1011 downloaded to /root/.cache/ms-playwright/ffmpeg-1011
Downloading Chromium Headless Shell 136.0.7103.25 (playwright build v1169) from https://cdn.playwright.dev/dbazure/download/playwright/builds/chromium/1169/chromium-headless-shell-linux.zip
101.4 MiB [] 0% 0.0s101.4 MiB [] 0% 20.0s101.4 MiB [] 0% 12.8s101.4 MiB [] 0% 9.1s101.4 MiB [] 1% 6.7s101.4 MiB [] 3% 3.1s101.4 MiB [] 4% 2.3s101.4 MiB [] 7% 1.6s101.4 MiB [] 8% 1.5s101.4 MiB [] 9% 1.5s101.4 MiB [] 11% 1.4s101.4 MiB [] 13% 1.3s101.4 MiB [] 14% 1.3s101.4 MiB [] 16% 1.2s101.4 MiB [] 17% 1.2s101.4 MiB [] 21% 1.0s101.4 MiB [] 24% 0.9s101.4 MiB [] 27% 0.8s101.4 MiB [] 31% 0.7s101.4 MiB [] 36% 0.6s101.4 MiB [] 40% 0.5s101.4 MiB [] 44% 0.5s101.4 MiB [] 47% 0.4s101.4 MiB [] 51% 0.4s101.4 MiB [] 54% 0.3s101.4 MiB [] 56% 0.3s101.4 MiB [] 61% 0.3s101.4 MiB [] 62% 0.3s101.4 MiB [] 66% 0.2s101.4 MiB [] 69% 0.2s101.4 MiB [] 74% 0.2s101.4 MiB [] 76% 0.2s101.4 MiB [] 81% 0.1s101.4 MiB [] 85% 0.1s101.4 MiB [] 89% 0.1s101.4 MiB [] 92% 0.0s101.4 MiB [] 95% 0.0s101.4 MiB [] 99% 0.0s101.4 MiB [] 100% 0.0s
Chromium Headless Shell 136.0.7103.25 (playwright build v1169) downloaded to /root/.cache/ms-playwright/chromium_headless_shell-1169
++ echo 'source .venv/bin/activate'
I'll open the /workspace/scubaduck directory to check the AGENTS.md file.
bash: .venv/bin/activate: No such file or directory
root@4dc88f61e6c2:/workspace# ls
scubaduck
I’ll switch to the root directory of this repo.
root@4dc88f61e6c2:/workspace# cd scubaduck
root@4dc88f61e6c2:/workspace/scubaduck# ls
AGENTS.md codex_setup.sh scubaduck tests
README.md pyproject.toml stubs uv.lock
I’ll take a look at the AGENTS.md file now.
root@4dc88f61e6c2:/workspace/scubaduck# cat AGENTS.md
- Use "source .venv/bin/activate" to activate the virtual environment before
running any commands
- ONLY use non-interactive commands like cat, sed, apply_patch to do edits.
Do NOT use interactive editors.
- Do NOT attempt to install packages. Only the packages specified in
pyproject.toml are available. You cannot add new packages. If you
desperately want another package, make a note of it in the final PR
description.
- Use conventional commits to format PR title
- There are no nested AGENTS.md files, this is the only agents file
- When using Playwright, ONLY use chromium browser. This browser is already
installed.
- Use "ruff check" to check lint, "ruff format" to autoformat files and
"pyright" to typecheck.
- When writing the PR description, include the original prompt supplied by the
user.
- When you add functionality to the server, add server tests to
tests/test_server.py. When you add features to the frontend, add frontend
tests to tests/test_web.py
I need to check if codex_setup.sh has run, so I'll open the README for guidance.
root@4dc88f61e6c2:/workspace/scubaduck# ls
AGENTS.md codex_setup.sh scubaduck tests
README.md pyproject.toml stubs uv.lock
root@4dc88f61e6c2:/workspace/scubaduck# cat README.md | head -n 20
I really like Scuba (Meta's internal real-time database system). The distributed
, real-time database part of Scuba is quite difficult (and expensive) to replica
te, but I also really like Scuba's UI for doing queries, and I have found myself
wishing that I have access to it even for "small" databases, e.g., I have a sql
ite dataset I want to explore.
Pivotal ideas:
* Time series by default. In the dedicated "time series" view, there are many fe
atures specifically oriented towards working towards tables that represent event
s that occurred over time: the start, end, compare, aggregate and granularity fi
elds all specially privilege the timestamp field. In fact, you can't log events
to Scuba's backing data store without a timestamp, they always come with one. (S
cuba also supports other views that don't presuppose a time series, but the time
series is the most beloved and well used view.) This is in contrast to typical
software which tries to generalize to arbitrary data first, with time series bei
ng added on later.
* It's all about exploration. Scuba is predicated on the idea that you don't kno
w what you're looking for, that you are going to spend time tweaking queries and
changing filters/grouping as part of an investigation to figure out why a syste
m behaves the way it is. So the filters/comparisons/groupings you want to edit a
re always visible on the left sidebar, with the expectation that you're going to
tweak the query to look at something else. Similarly, all the parameters of you
r query get saved into your URL, so your browser history can double up as a quer
y history / you can easily share a query with someone else. This is contrast to
typical software which is often oriented to making pretty dashboards and reports
. (This function is important too, but it's not what I want in exploration mode!
)
* You can fix data problems in the query editor. It's pretty common to have mess
ed up and ended up with a database that doesn't have exactly the columns you nee
d, or some columns that are corrupted in some way. Scuba has pretty robust suppo
rt for defining custom columns with arbitrary SQL functions, grouping over them
as if they were native functions, and doing so with minimal runtime cost (Scuba
aims to turn around your query in milliseconds!) Having to go and run a huge dat
a pipeline to fix your data is a big impediment to exploration; quick and easy c
ustom columns means you can patch over problems when you're investigating and fi
x them for real later.
We're going to build a exploratory data analysis tool like Scuba for time series
database (i.e., a database with a mandatory timestamp representing the time an
event occurred). We'll use DuckDB as the underlying SQL engine served from a Py
thon server, and render the GUI/results as a webpage with vanilla HTML and JS. W
e'll use choices.js to support token inputs. We define a token input to mean a
text input element where as you type a dropdown displays with valid values, and
if you select one or press enter, the selection turns into a token/chip that can
only be deleted as one unit.
To start, we are going to support one views: samples. The samples view only all
ows you to view individual samples from the database, subject to a filter. Our m
ain UI concept is that there is a left sidebar that is the query editor, and the
right side that shows the view. The sidebar is always visible and defaults to
the query parameters of the current view. After you make changes to the query,
clicking the "Dive" button updates the view. The URL of the page encodes all of
the values of the query (and gets updated when you Dive), so the browser's back
button lets you view previous queries.
The query editor's job is to generate a SQL query, which then is applied on the
database, and then the result visualized according to the view.
Here are the settings you can apply to the query. The help text should show up w
hen you mouse over the field name:
* Start/End - Help text: "Sets the start/end of the time range to query. Can be
any kind of datetime string. For example: 'April 23, 2014' or 'yesterday'." The
UI for this selector supports both relative selections (now, -1 hour, -3 hours,
-12 hours, -1 day, -3 days, -1 week, -1 fortnight, -30 days, -90 days) as well a
s specifying an absolute date. The way this field is rendered is there is a fre
e form text box, a drop down arrow (for the relative selectors), and then a cale
ndar button (for date selection).
* Order By - Help text: "Choose a column to sort results by." There is an ASC/D
ESC toggle next to it.
Just scrolling a bit more to make sure I have all the design info.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n "time series view" -n README.md
Time to take a look at the repository and see what's going on.
root@4dc88f61e6c2:/workspace/scubaduck# ls scubaduck
__init__.py sample.csv server.py static
root@4dc88f61e6c2:/workspace/scubaduck# ls scubaduck/static
index.html js
root@4dc88f61e6c2:/workspace/scubaduck# ls scubaduck/static/js
chip_input.js timeseries_chart.js
I'll take a look at the timeseries chart library to see what's going on.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '1,160p' scubaduck/static/js/time
series_chart.js
let resizeObserver = null;
let currentChart = null;
function showTimeSeries(data) {
function parseTs(s) {
if (s.match(/GMT/) || s.endsWith('Z') || /\+\d{2}:?\d{2}$/.test(s)) {
return new Date(s).getTime();
}
return new Date(s + 'Z').getTime();
}
const view = document.getElementById('view');
if (data.rows.length === 0) {
view.innerHTML = '<p id="empty-message">Empty data provided to table</p>';
return;
}
const height = 600;
view.innerHTML =
'<div id="ts-container"><div id="legend"></div><div id="chart-wrapper"><svg
id="chart" height="' +
height +
'"></svg></div></div>';
const svg = document.getElementById('chart');
const legend = document.getElementById('legend');
const crosshairLine = document.createElementNS('http://www.w3.org/2000/svg', '
line');
crosshairLine.id = 'crosshair_line';
crosshairLine.setAttribute('stroke', '#555');
crosshairLine.style.display = 'none';
const crosshairDots = document.createElementNS('http://www.w3.org/2000/svg', '
g');
crosshairDots.id = 'crosshair_dots';
crosshairDots.style.display = 'none';
const groups = groupBy.chips || [];
const hasHits = document.getElementById('show_hits').checked ? 1 : 0;
const fill = document.getElementById('fill').value;
const bucketMs = (data.bucket_size || 3600) * 1000;
const start = data.start ? parseTs(data.start) : null;
const end = data.end ? parseTs(data.end) : null;
const startIdx = 1 + groups.length + hasHits;
const valueCols = selectedColumns.slice(groups.length + hasHits);
const series = {};
data.rows.forEach(r => {
const ts = parseTs(r[0]);
const groupKey = groups.map((_, i) => r[1 + i]).join(':') || 'all';
valueCols.forEach((name, i) => {
const val = Number(r[startIdx + i]);
const key = groupKey === 'all' ? name : groupKey + ':' + name;
if (!series[key]) series[key] = {};
series[key][ts] = val;
});
});
const buckets = [];
let minX = start !== null ? start : Infinity;
let maxX = end !== null ? end : -Infinity;
if (start !== null && end !== null) {
for (let t = start; t <= end; t += bucketMs) {
buckets.push(t);
}
} else {
Object.keys(series).forEach(k => {
const s = series[k];
Object.keys(s).forEach(t => {
const n = Number(t);
if (n < minX) minX = n;
if (n > maxX) maxX = n;
});
});
for (let t = minX; t <= maxX; t += bucketMs) {
buckets.push(t);
}
}
let minY = Infinity,
maxY = -Infinity;
Object.keys(series).forEach(key => {
const vals = series[key];
buckets.forEach(b => {
const v = vals[b];
const val = v === undefined && fill === '0' ? 0 : v;
if (val === undefined) return;
if (val < minY) minY = val;
if (val > maxY) maxY = val;
});
});
if (fill === '0') {
if (minY > 0) minY = 0;
if (maxY < 0) maxY = 0;
}
const colors = [
'#1f77b4',
'#ff7f0e',
'#2ca02c',
'#d62728',
'#9467bd',
'#8c564b',
'#e377c2'
];
currentChart = {
svg,
legend,
series,
buckets,
minX,
maxX,
minY,
maxY,
fill,
colors,
height,
crosshairLine,
crosshairDots,
seriesEls: {},
bucketPixels: [],
xScale: null,
yScale: null,
selected: null,
frozen: false
};
const intervals = [
{unit: 'second', step: 1, ms: 1000},
{unit: 'second', step: 2, ms: 2000},
{unit: 'second', step: 5, ms: 5000},
{unit: 'second', step: 10, ms: 10000},
{unit: 'second', step: 15, ms: 15000},
{unit: 'second', step: 30, ms: 30000},
{unit: 'minute', step: 1, ms: 60000},
{unit: 'minute', step: 2, ms: 120000},
{unit: 'minute', step: 5, ms: 300000},
{unit: 'minute', step: 10, ms: 600000},
{unit: 'minute', step: 15, ms: 900000},
{unit: 'minute', step: 30, ms: 1800000},
{unit: 'hour', step: 1, ms: 3600000},
{unit: 'hour', step: 2, ms: 7200000},
{unit: 'hour', step: 3, ms: 10800000},
{unit: 'hour', step: 4, ms: 14400000},
{unit: 'hour', step: 6, ms: 21600000},
{unit: 'hour', step: 12, ms: 43200000},
{unit: 'day', step: 1, ms: 86400000},
{unit: 'day', step: 2, ms: 172800000},
{unit: 'week', step: 1, ms: 604800000},
{unit: 'week', step: 2, ms: 1209600000},
{unit: 'month', step: 1},
{unit: 'month', step: 3},
{unit: 'month', step: 6},
{unit: 'year', step: 1},
{unit: 'year', step: 2},
{unit: 'year', step: 5},
{unit: 'year', step: 10}
];
function chooseInterval(start, end) {
const span = end - start;
function approxMs(i) {
if (i.ms) return i.ms;
if (i.unit === 'month') return i.step * 2629800000;
if (i.unit === 'year') return i.step * 31557600000;
return 1000;
}
I'm checking out the code around the time series axis to understand it better.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'bucket_size' -n scubaduck/stati
c/js/timeseries_chart.js
34: const bucketMs = (data.bucket_size || 3600) * 1000;
I’m scrolling to make sure I review the axis tick formatting thoroughly.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'xScale' -n scubaduck/static/js/
timeseries_chart.js
115: xScale: null,
280: const xScale = x => ((x - minX) / xRange) * (width - 60) + 50;
289: gLine.setAttribute('x1', xScale(minX));
290: gLine.setAttribute('x2', xScale(maxX));
297: tick.setAttribute('x1', xScale(minX));
298: tick.setAttribute('x2', xScale(minX) - 5);
305: text.setAttribute('x', xScale(minX) - 8);
324: const x = xScale(b);
333: const x = xScale(b);
387: currentChart.xScale = xScale;
389: currentChart.bucketPixels = buckets.map(xScale);
399: axisLine.setAttribute('x1', xScale(minX));
400: axisLine.setAttribute('x2', xScale(maxX));
406: const x = xScale(t);
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '248,426p' scubaduck/static/js/ti
meseries_chart.js
else niceFraction = 10;
} else {
if (fraction <= 1) niceFraction = 1;
else if (fraction <= 2) niceFraction = 2;
else if (fraction <= 5) niceFraction = 5;
else niceFraction = 10;
}
return niceFraction * Math.pow(10, exponent);
}
function niceTicks(min, max, count) {
const range = niceNum(max - min || 1, false);
const step = niceNum(range / Math.max(count - 1, 1), true);
const start = Math.floor(min / step) * step;
const end = Math.ceil(max / step) * step;
const ticks = [];
for (let v = start; v <= end; v += step) ticks.push(v);
return ticks;
}
function render() {
const style = getComputedStyle(svg.parentElement);
const width =
svg.parentElement.clientWidth -
parseFloat(style.paddingLeft) -
parseFloat(style.paddingRight);
svg.setAttribute('width', width);
svg.innerHTML = '';
legend.innerHTML = '';
let colorIndex = 0;
const xRange = maxX - minX || 1;
const yRange = maxY - minY || 1;
const xScale = x => ((x - minX) / xRange) * (width - 60) + 50;
const yScale = y => height - 30 - ((y - minY) / yRange) * (height - 60);
const grid = document.createElementNS('http://www.w3.org/2000/svg', 'g');
svg.appendChild(grid);
const yAxis = document.createElementNS('http://www.w3.org/2000/svg', 'g');
const yTicks = niceTicks(minY, maxY, 10);
yTicks.forEach(v => {
const y = yScale(v);
const gLine = document.createElementNS('http://www.w3.org/2000/svg', 'line
');
gLine.setAttribute('x1', xScale(minX));
gLine.setAttribute('x2', xScale(maxX));
gLine.setAttribute('y1', y);
gLine.setAttribute('y2', y);
gLine.setAttribute('class', 'grid');
grid.appendChild(gLine);
const tick = document.createElementNS('http://www.w3.org/2000/svg', 'line'
);
tick.setAttribute('x1', xScale(minX));
tick.setAttribute('x2', xScale(minX) - 5);
tick.setAttribute('y1', y);
tick.setAttribute('y2', y);
tick.setAttribute('stroke', '#000');
yAxis.appendChild(tick);
const text = document.createElementNS('http://www.w3.org/2000/svg', 'text'
);
text.setAttribute('x', xScale(minX) - 8);
text.setAttribute('y', y + 3);
text.setAttribute('text-anchor', 'end');
text.setAttribute('class', 'y-tick-label');
text.textContent = formatNumber(v);
yAxis.appendChild(text);
});
const seriesEls = {};
const agg = document.getElementById('aggregate').value.toLowerCase();
const groups = {};
Object.keys(series).forEach(key => {
const vals = series[key];
const color = colors[colorIndex++ % colors.length];
let path = '';
let drawing = false;
buckets.forEach(b => {
const v = vals[b];
if (v === undefined) {
if (fill === '0') {
const x = xScale(b);
const y = yScale(0);
path += (drawing ? 'L' : 'M') + x + ' ' + y + ' ';
drawing = true;
} else if (fill === 'blank') {
drawing = false;
}
// connect: do nothing
} else {
const x = xScale(b);
const y = yScale(v);
path += (drawing ? 'L' : 'M') + x + ' ' + y + ' ';
drawing = true;
}
});
const el = document.createElementNS('http://www.w3.org/2000/svg', 'path');
el.setAttribute('d', path.trim());
el.setAttribute('fill', 'none');
el.setAttribute('stroke', color);
el.setAttribute('stroke-width', '1.3');
svg.appendChild(el);
const idx = key.lastIndexOf(':');
const groupKey = idx === -1 ? 'all' : key.slice(0, idx);
const name = idx === -1 ? key : key.slice(idx + 1);
let group = groups[groupKey];
if (!group) {
const gEl = document.createElement('div');
gEl.className = 'legend-group';
const header = document.createElement('div');
header.className = 'legend-header';
header.textContent =
groupKey === 'all' ? agg : `${groupKey} ${agg}`;
gEl.appendChild(header);
const items = document.createElement('div');
items.className = 'legend-items';
gEl.appendChild(items);
legend.appendChild(gEl);
group = {items};
groups[groupKey] = group;
}
const item = document.createElement('div');
item.className = 'legend-item';
const label = document.createElement('span');
label.textContent = name;
label.style.color = color;
const valueSpan = document.createElement('span');
valueSpan.className = 'legend-value';
item.appendChild(label);
item.appendChild(valueSpan);
group.items.appendChild(item);
function highlight(on) {
el.setAttribute('stroke-width', on ? '2.5' : '1.3');
item.classList.toggle('highlight', on);
}
el.addEventListener('mouseenter', () => highlight(true));
el.addEventListener('mouseleave', () => highlight(false));
item.addEventListener('mouseenter', () => highlight(true));
item.addEventListener('mouseleave', () => highlight(false));
seriesEls[key] = { path: el, item, highlight, color, valueEl: valueSpan };
});
currentChart.seriesEls = seriesEls;
currentChart.xScale = xScale;
currentChart.yScale = yScale;
currentChart.bucketPixels = buckets.map(xScale);
svg.appendChild(crosshairLine);
svg.appendChild(crosshairDots);
const intv = chooseInterval(minX, maxX);
const ticks = generateTicks(minX, maxX, intv);
const lu = labelUnit(intv);
const rotate = ticks.length > 0 && (width - 60) / ticks.length < 60;
const axis = document.createElementNS('http://www.w3.org/2000/svg', 'g');
const axisLine = document.createElementNS('http://www.w3.org/2000/svg', 'lin
e');
axisLine.setAttribute('x1', xScale(minX));
axisLine.setAttribute('x2', xScale(maxX));
axisLine.setAttribute('y1', height - 30);
axisLine.setAttribute('y2', height - 30);
axisLine.setAttribute('stroke', '#888');
axis.appendChild(axisLine);
ticks.forEach(t => {
const x = xScale(t);
const line = document.createElementNS('http://www.w3.org/2000/svg', 'line'
);
line.setAttribute('x1', x);
line.setAttribute('y1', height - 30);
line.setAttribute('x2', x);
line.setAttribute('y2', height - 25);
line.setAttribute('stroke', '#888');
axis.appendChild(line);
const text = document.createElementNS('http://www.w3.org/2000/svg', 'text'
);
text.setAttribute('x', x);
text.setAttribute('y', height - 10);
text.setAttribute('text-anchor', 'middle');
text.setAttribute('class', 'tick-label' + (rotate ? ' rotated' : ''));
if (rotate) text.setAttribute('transform', `rotate(-45 ${x} ${height - 10}
)`);
text.textContent = fmt(new Date(t), lu);
axis.appendChild(text);
});
svg.appendChild(axis);
svg.appendChild(yAxis);
const helper = document.createElement('div');
I'll open the tests folder now to review the available test cases.
root@4dc88f61e6c2:/workspace/scubaduck# ls tests
conftest.py test_server.py test_web.py
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '1,160p' tests/test_server.py
from __future__ import annotations
import json
from pathlib import Path
from typing import cast
import duckdb
from scubaduck import server
import pytest
def test_basic_query() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-02 00:00:00",
"order_by": "timestamp",
"order_dir": "ASC",
"limit": 10,
"columns": ["timestamp", "event", "value", "user"],
"filters": [],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert data
rows = data["rows"]
# We expect first three rows (until 2024-01-02 00:00:00)
assert len(rows) == 3
assert rows[0][1] == "login"
assert rows[1][1] == "logout"
def test_js_served() -> None:
app = server.app
client = app.test_client()
rv = client.get("/js/chip_input.js")
assert rv.status_code == 200
assert b"initChipInput" in rv.data
def test_filter_multi_token() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-02 03:00:00",
"order_by": "timestamp",
"limit": 10,
"columns": ["timestamp", "event", "value", "user"],
"filters": [{"column": "user", "op": "=", "value": ["alice", "charlie"]}
],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert data
rows = data["rows"]
# Should only return rows for alice and charlie
assert len(rows) == 3
assert rows[0][3] == "alice"
assert rows[-1][3] == "charlie"
def test_empty_filter_is_noop() -> None:
app = server.app
client = app.test_client()
base_payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"limit": 100,
"columns": ["timestamp", "event", "value", "user"],
}
no_filter = {**base_payload, "filters": []}
empty_filter = {
**base_payload,
"filters": [{"column": "user", "op": "=", "value": None}],
}
rv1 = client.post(
"/api/query", data=json.dumps(no_filter), content_type="application/json
"
)
rv2 = client.post(
"/api/query", data=json.dumps(empty_filter), content_type="application/j
son"
)
rows1 = rv1.get_json()["rows"]
rows2 = rv2.get_json()["rows"]
assert rows1 == rows2
def test_select_columns() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"order_by": "timestamp",
"limit": 10,
"columns": ["timestamp", "user"],
"filters": [],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert data
rows = data["rows"]
assert len(rows[0]) == 2
assert rows[0][1] == "alice"
def test_string_filter_ops() -> None:
app = server.app
client = app.test_client()
base = {
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"order_by": "timestamp",
"limit": 100,
"columns": ["timestamp", "event", "value", "user"],
}
contains = {
**base,
"filters": [{"column": "user", "op": "contains", "value": "ali"}],
}
rv = client.post(
"/api/query", data=json.dumps(contains), content_type="application/json"
)
rows = rv.get_json()["rows"]
assert all("ali" in r[3] for r in rows)
regex = {
**base,
"filters": [{"column": "user", "op": "~", "value": "^a.*"}],
}
rv = client.post(
"/api/query", data=json.dumps(regex), content_type="application/json"
)
rows = rv.get_json()["rows"]
assert all(r[3].startswith("a") for r in rows)
assert len(rows) == 2
not_empty = {**base, "filters": [{"column": "user", "op": "!empty"}]}
rv = client.post(
"/api/query", data=json.dumps(not_empty), content_type="application/json
"
)
assert len(rv.get_json()["rows"]) == 4
def _make_payload() -> dict[str, object]:
return {
"table": "events",
"start": "2024-01-01 00:00:00",
I'm scrolling to check additional tests, making sure I've got everything I need.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '160,320p' tests/test_server.py
"start": "2024-01-01 00:00:00",
"end": "2024-01-02 00:00:00",
"order_by": "timestamp",
"order_dir": "ASC",
"limit": 10,
"columns": ["timestamp", "event", "value", "user"],
"filters": [],
}
def test_database_types(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text(Path("scubaduck/sample.csv").read_text())
sqlite_file = tmp_path / "events.sqlite"
import sqlite3
conn = sqlite3.connect(sqlite_file)
conn.execute(
"CREATE TABLE events (timestamp TEXT, event TEXT, value INTEGER, user TE
XT)"
)
with open(csv_file) as f:
next(f)
for line in f:
ts, ev, val, user = line.strip().split(",")
conn.execute(
"INSERT INTO events VALUES (?, ?, ?, ?)", (ts, ev, int(val), use
r)
)
conn.commit()
conn.close() # pyright: ignore[reportUnknownMemberType, reportAttributeAcce
ssIssue]
duckdb_file = tmp_path / "events.duckdb"
con = duckdb.connect(duckdb_file)
con.execute(
f"CREATE TABLE events AS SELECT * FROM read_csv_auto('{csv_file.as_posix
()}')"
)
con.close() # pyright: ignore[reportUnknownMemberType, reportAttributeAcces
sIssue]
for db in (csv_file, sqlite_file, duckdb_file):
app = server.create_app(db)
client = app.test_client()
payload = _make_payload()
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/js
on"
)
rows = rv.get_json()["rows"]
assert len(rows) == 3
def test_sqlite_longvarchar(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) ->
None:
sqlite_file = tmp_path / "events.sqlite"
import sqlite3
conn = sqlite3.connect(sqlite_file)
conn.execute(
"CREATE TABLE events (timestamp TEXT, url LONGVARCHAR, title VARCHAR(10)
)"
)
conn.execute(
"INSERT INTO events VALUES ('2024-01-01 00:00:00', 'https://a.com', 'Hom
e')"
)
conn.commit()
conn.close() # pyright: ignore[reportUnknownMemberType, reportAttributeAcce
ssIssue]
from typing import Any
real_connect = duckdb.connect
def failing_connect(*args: Any, **kwargs: Any) -> Any:
real = real_connect(*args, **kwargs)
class Wrapper:
def __init__(self, con: duckdb.DuckDBPyConnection) -> None:
self.con = con
self._failed = False
def execute(self, sql: str, *a: Any, **kw: Any):
if not self._failed and sql == "LOAD sqlite":
self._failed = True
raise RuntimeError("fail")
return self.con.execute(sql, *a, **kw)
def __getattr__(self, name: str) -> object:
return getattr(self.con, name)
return Wrapper(real)
monkeypatch.setattr(server.duckdb, "connect", failing_connect)
app = server.create_app(sqlite_file)
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "timestamp",
"columns": ["timestamp", "url", "title"],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert data["rows"][0][1] == "https://a.com"
def test_sqlite_bigint(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
sqlite_file = tmp_path / "big.sqlite"
import sqlite3
conn = sqlite3.connect(sqlite_file)
conn.execute("CREATE TABLE events (timestamp TEXT, value INTEGER)")
big_value = 13385262862605259
conn.execute(
"INSERT INTO events VALUES ('2024-01-01 00:00:00', ?)",
(big_value,),
)
conn.commit()
conn.close() # pyright: ignore[reportUnknownMemberType, reportAttributeAcce
ssIssue]
from typing import Any
real_connect = duckdb.connect
def failing_connect(*args: Any, **kwargs: Any) -> Any:
real = real_connect(*args, **kwargs)
class Wrapper:
def __init__(self, con: duckdb.DuckDBPyConnection) -> None:
self.con = con
self._failed = False
def execute(self, sql: str, *a: Any, **kw: Any):
if not self._failed and sql == "LOAD sqlite":
self._failed = True
raise RuntimeError("fail")
return self.con.execute(sql, *a, **kw)
def __getattr__(self, name: str) -> object:
return getattr(self.con, name)
return Wrapper(real)
monkeypatch.setattr(server.duckdb, "connect", failing_connect)
app = server.create_app(sqlite_file)
client = app.test_client()
payload = {
"table": "events",
"order_by": "timestamp",
"columns": ["timestamp", "value"],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert data["rows"][0][1] == big_value
def test_integer_time_column(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
def test_integer_time_unit_ms(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text("created,event\n1704067200000,login\n1704070800000,logou
t\n")
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
"time_unit": "ms",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
def test_integer_time_unit_us_default_start_end(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text(
"created,event\n1704067200000000,login\n1704070800000000,logout\n"
)
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
"time_unit": "us",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert data["start"] == "2024-01-01 00:00:00"
assert data["end"] == "2024-01-01 01:00:00"
assert len(data["rows"]) == 2
def test_envvar_db(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
csv_file = tmp_path / "custom.csv"
csv_file.write_text("timestamp,event,value,user\n2024-01-01 00:00:00,login,5
,bob\n")
monkeypatch.setenv("SCUBADUCK_DB", str(csv_file))
app = server.create_app()
client = app.test_client()
payload = _make_payload()
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
rows = rv.get_json()["rows"]
assert len(rows) == 1
def test_envvar_db_missing(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> N
one:
missing = tmp_path / "missing.sqlite"
monkeypatch.setenv("SCUBADUCK_DB", str(missing))
with pytest.raises(FileNotFoundError):
server.create_app()
def test_group_by_table() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "table",
"order_by": "user",
"limit": 10,
"columns": ["value"],
"group_by": ["user"],
"aggregate": "Sum",
"show_hits": True,
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
rows = rv.get_json()["rows"]
assert rows[0][0] == "alice"
assert rows[0][1] == 2
assert rows[0][2] == 40
def test_relative_time_query(monkeypatch: pytest.MonkeyPatch) -> None:
app = server.app
client = app.test_client()
from datetime import datetime
fixed_now = datetime(2024, 1, 2, 4, 0, 0)
class FixedDateTime(datetime):
@classmethod
def now(cls, tz=None): # type: ignore[override]
return fixed_now if tz is None else fixed_now.astimezone(tz)
monkeypatch.setattr(server, "datetime", FixedDateTime)
...
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 400
assert "Unknown column" in data["error"]
def test_samples_view_rejects_group_by() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"graph_type": "samples",
"group_by": ["user"],
"columns": ["timestamp"],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 400
assert "only valid" in data["error"]
def test_table_avg_with_timestamp() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "table",
"order_by": "user",
"limit": 100,
"columns": ["user", "timestamp", "value"],
"group_by": ["user"],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert "error" not in data
rows = data["rows"]
assert rows[0][0] == "alice"
from dateutil import parser
ts = parser.parse(rows[0][1]).replace(tzinfo=None)
assert ts == parser.parse("2024-01-01 12:00:00")
def test_timeseries_basic() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 100,
"group_by": ["user"],
"aggregate": "Count",
"columns": ["value"],
"x_axis": "timestamp",
"granularity": "1 day",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 4
def test_timeseries_orders_by_xaxis() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 100,
"columns": ["value"],
"x_axis": "timestamp",
"granularity": "1 day",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
rows = data["rows"]
from dateutil import parser
timestamps = [parser.parse(r[0]).replace(tzinfo=None) for r in rows]
assert timestamps == sorted(timestamps)
def test_timeseries_limit_applies_to_series() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 1,
"order_by": "user",
"group_by": ["user"],
"aggregate": "Count",
"columns": ["value"],
"x_axis": "timestamp",
"granularity": "1 day",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
assert all(r[1] == "alice" for r in data["rows"])
I’m skipping ahead after 640 lines to find the tests for x_axis.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'x_axis' -n tests/test_server.py
582: "x_axis": "timestamp",
603: "x_axis": "timestamp",
631: "x_axis": "timestamp",
653: "x_axis": "timestamp",
687: "x_axis": "timestamp",
I'll open the file further after line 640 to check for more tests.
def test_timeseries_auto_and_fine_buckets() -> None:
app = server.app
client = app.test_client()
def run(gran: str) -> None:
payload = {
"start": "2024-01-01 00:00:00",
"end": "2024-01-02 03:00:00",
"graph_type": "timeseries",
"columns": ["value"],
"x_axis": "timestamp",
"granularity": gran,
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/js
on"
)
data = rv.get_json()
assert rv.status_code == 200
from dateutil import parser
start = parser.parse(cast(str, payload["start"])).replace(tzinfo=None)
buckets = [
parser.parse(cast(str, r[0])).replace(tzinfo=None) for r in data["ro
ws"]
]
assert buckets[0] == start
if len(buckets) > 1:
step = (buckets[1] - buckets[0]).total_seconds()
assert step % data["bucket_size"] == 0
assert any(r[1] != 0 for r in data["rows"])
run("Auto")
run("Fine")
def test_timeseries_string_column_error() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 7,
"columns": ["timestamp", "event", "value", "user"],
"x_axis": "timestamp",
"granularity": "1 hour",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 400
assert "Aggregate" in data["error"]
def test_derived_column_basic() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"limit": 10,
"columns": ["timestamp"],
"derived_columns": {"val2": "value * 2"},
"filters": [],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert data["rows"][0][1] == 20
def test_timeseries_derived_column() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"granularity": "1 hour",
"limit": 7,
"columns": ["value"],
"derived_columns": {"derived_1": "value * 2"},
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
rows = data["rows"]
assert all(r[2] == r[1] * 2 for r in rows)
def test_default_start_end_returned() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"order_by": "timestamp",
"limit": 5,
"columns": ["timestamp"],
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert data["start"] == "2024-01-01 00:00:00"
assert data["end"] == "2024-01-02 03:00:00"
I'll keep going down the lines to reach the end.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '960,1280p' tests/test_server.py
I’ll check out test_web.py to take a look at the front-end tests.
)
def run_query(
page: Any,
url: str,
*,
start: str | None = None,
end: str | None = None,
order_by: str | None = None,
order_dir: str | None = "ASC",
limit: int | None = None,
group_by: list[str] | None = None,
aggregate: str | None = None,
) -> dict[str, Any]:
page.goto(url)
page.wait_for_selector("#order_by option", state="attached")
page.wait_for_selector("#order_dir", state="attached")
page.wait_for_function("window.lastResults !== undefined")
if start is not None:
page.fill("#start", start)
if end is not None:
page.fill("#end", end)
if order_by is not None:
select_value(page, "#order_by", order_by)
if order_dir is not None and order_dir == "DESC":
page.click("#order_dir")
if limit is not None:
page.fill("#limit", str(limit))
if group_by is not None:
select_value(page, "#graph_type", "table")
page.evaluate(
"g => { groupBy.chips = g; groupBy.renderChips(); }",
group_by,
)
if aggregate is not None:
select_value(page, "#graph_type", "table")
select_value(page, "#aggregate", aggregate)
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
return page.evaluate("window.lastResults")
def test_range_filters(page: Any, server_url: str) -> None:
data = run_query(
page,
server_url,
start="2024-01-02 00:00:00",
end="2024-01-02 04:00:00",
order_by="timestamp",
limit=100,
)
assert len(data["rows"]) == 2
from dateutil import parser
timestamps = [parser.parse(row[0]).replace(tzinfo=None) for row in data["row
s"]]
assert timestamps == [
parser.parse("2024-01-02 00:00:00"),
parser.parse("2024-01-02 03:00:00"),
]
def test_order_by(page: Any, server_url: str) -> None:
data = run_query(
page,
server_url,
start="2024-01-01 00:00:00",
end="2024-01-03 00:00:00",
order_by="value",
order_dir="DESC",
limit=100,
)
values = [row[2] for row in data["rows"]]
assert values == sorted(values, reverse=True)
def test_limit(page: Any, server_url: str) -> None:
data = run_query(
page,
server_url,
start="2024-01-01 00:00:00",
end="2024-01-03 00:00:00",
order_by="timestamp",
limit=2,
)
assert len(data["rows"]) == 2
def test_time_column_dropdown(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#time_column option", state="attached")
options = page.locator("#time_column option").all_inner_texts()
assert "timestamp" in options
assert "value" in options
assert page.input_value("#time_column") == "timestamp"
def test_time_unit_dropdown(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#time_unit", state="attached")
opts = page.locator("#time_unit option").all_inner_texts()
assert "ms" in opts
assert page.input_value("#time_unit") == "s"
def test_simple_filter(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
page.click("text=Add Filter")
filter_el = page.query_selector("#filters .filter:last-child")
assert filter_el
page.evaluate(
"arg => setSelectValue(arg.el.querySelector('.f-col'), arg.val)",
{"el": filter_el, "val": "user"},
)
val_input = filter_el.query_selector(".f-val")
val_input.click()
page.keyboard.type("alice")
page.keyboard.press("Enter")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
data = page.evaluate("window.lastResults")
assert len(data["rows"]) == 2
assert all(row[3] == "alice" for row in data["rows"])
def test_default_filter_and_layout(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
count = page.evaluate("document.querySelectorAll('#filters .filter').length"
)
assert count == 1
last_is_button = page.evaluate(
"document.querySelector('#filters').lastElementChild.id === 'add_filter'
"
)
assert last_is_button
position = page.evaluate(
"getComputedStyle(document.querySelector('#filters .filter button.remove
')).position"
)
assert position == "static"
def test_filter_remove_alignment(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
diff = page.evaluate(
"() => { const r=document.querySelector('#filters .filter-row').getBound
ingClientRect(); const x=document.querySelector('#filters .filter-row button.rem
ove').getBoundingClientRect(); return Math.abs(r.right - x.right); }"
)
assert diff <= 1
assert page.is_visible("#settings")
assert page.is_hidden("#columns")
page.click("text=Columns")
assert page.is_visible("#columns")
cols = [c.strip() for c in page.locator("#column_groups li").all_inner_texts
()]
assert "timestamp" in cols
assert "event" in cols
page.click("text=View Settings")
assert page.is_visible("#settings")
btn_color = page.evaluate(
"getComputedStyle(document.querySelector('#dive')).backgroundColor"
)
assert "rgb(0, 128, 0)" == btn_color
sidebar_overflow = page.evaluate(
"getComputedStyle(document.querySelector('#sidebar')).overflowY"
)
view_overflow = page.evaluate(
"getComputedStyle(document.querySelector('#view')).overflowY"
)
assert sidebar_overflow == "auto"
assert view_overflow == "auto"
def test_graph_type_table_fields(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "table")
assert page.is_visible("#group_by_field")
assert page.is_visible("#aggregate_field")
assert page.is_visible("#show_hits_field")
page.click("text=Columns")
assert not page.is_visible("text=Strings:")
def test_graph_type_timeseries_fields(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "timeseries")
assert page.is_visible("#group_by_field")
assert page.is_visible("#aggregate_field")
assert page.is_visible("#x_axis_field")
assert page.is_visible("#granularity_field")
assert page.is_visible("#fill_field")
def test_timeseries_default_query(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "timeseries")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
data = page.evaluate("window.lastResults")
assert "error" not in data
assert page.is_visible("#chart")
page.click("text=Columns")
assert not page.is_checked("#column_groups input[value='timestamp']")
def test_timeseries_single_bucket(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
page.fill("#start", "2024-01-01 00:00:00")
page.fill("#end", "2024-01-01 00:00:00")
select_value(page, "#graph_type", "timeseries")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
path = page.get_attribute("#chart path", "d")
assert path is not None and "NaN" not in path
def test_timeseries_fill_options(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
page.fill("#start", "2024-01-01 00:00:00")
page.fill("#end", "2024-01-02 03:00:00")
select_value(page, "#graph_type", "timeseries")
select_value(page, "#granularity", "1 hour")
select_value(page, "#fill", "0")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
path_zero = page.get_attribute("#chart path", "d")
assert path_zero is not None and path_zero.count("L") > 20
select_value(page, "#fill", "connect")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
path_conn = page.get_attribute("#chart path", "d")
assert path_conn is not None and path_conn.count("M") == 1
select_value(page, "#fill", "blank")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
path_blank = page.get_attribute("#chart path", "d")
assert path_blank is not None and path_blank.count("M") > 1
def test_timeseries_hover_highlight(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "timeseries")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
page.wait_for_selector("#chart path", state="attached")
path_el = page.query_selector("#chart path")
assert path_el
page.evaluate(
"el => el.dispatchEvent(new MouseEvent('mouseenter', {bubbles: true}))",
path_el,
)
width = page.evaluate(
"getComputedStyle(document.querySelector('#chart path')).strokeWidth"
)
assert "2.5" in width
color = page.evaluate(
"getComputedStyle(document.querySelector('#legend .legend-item')).backgr
oundColor"
)
assert "221, 221, 221" in color
def test_timeseries_crosshair(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "timeseries")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
page.wait_for_selector("#chart path", state="attached")
page.eval_on_selector(
"#chart",
"el => { const r = el.getBoundingClientRect(); el.dispatchEvent(new Mous
eEvent('mousemove', {clientX: r.left + r.width/2, clientY: r.top + r.height/2, b
ubbles: true})); }",
)
line_display = page.evaluate(
"document.getElementById('crosshair_line').style.display"
)
assert line_display != "none"
count = page.eval_on_selector_all("#crosshair_dots circle", "els => els.leng
th")
assert count > 0
page.eval_on_selector(
"#chart",
"el => el.dispatchEvent(new MouseEvent('mouseleave', {bubbles: true}))",
)
line_display = page.evaluate(
"document.getElementById('crosshair_line').style.display"
"#chart",
"el => { const r = el.getBoundingClientRect(); el.dispatchEvent(new Mous
eEvent('mousemove', {clientX: r.left + r.width/2, clientY: r.top + r.height/2, b
ubbles: true})); }",
)
page.eval_on_selector(
"#chart",
"el => { const r = el.getBoundingClientRect(); el.dispatchEvent(new Mous
eEvent('click', {clientX: r.left + r.width/2, clientY: r.top + r.height/2, bubbl
es: true})); }",
)
line_display = page.evaluate(
"document.getElementById('crosshair_line').style.display"
)
assert line_display != "none"
pos1 = page.evaluate("document.getElementById('crosshair_line').getAttribute
('x1')")
page.eval_on_selector(
"#chart",
"el => { const r = el.getBoundingClientRect(); el.dispatchEvent(new Mous
eEvent('mousemove', {clientX: r.left + r.width/4, clientY: r.top + r.height/2, b
ubbles: true})); }",
)
pos2 = page.evaluate("document.getElementById('crosshair_line').getAttribute
('x1')")
assert pos1 == pos2
page.eval_on_selector(
"#chart",
"el => el.dispatchEvent(new MouseEvent('mouseleave', {bubbles: true}))",
)
line_display = page.evaluate(
"document.getElementById('crosshair_line').style.display"
)
assert line_display != "none"
page.eval_on_selector(
"#chart",
"el => { const r = el.getBoundingClientRect(); el.dispatchEvent(new Mous
eEvent('click', {clientX: r.left + r.width/2, clientY: r.top + r.height/2, bubbl
es: true})); }",
)
line_display = page.evaluate(
"document.getElementById('crosshair_line').style.display"
)
assert line_display == "none"
def test_timeseries_auto_timezone(browser: Any, server_url: str) -> None:
context = browser.new_context(timezone_id="America/New_York")
page = context.new_page()
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "timeseries")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
path = page.get_attribute("#chart path", "d")
context.close()
assert path is not None
coords = [float(p.split(" ")[1]) for p in path.replace("M", "L").split("L")[
1:]]
assert max(coords) > min(coords)
def test_timeseries_multi_series(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#graph_type", state="attached")
select_value(page, "#graph_type", "timeseries")
page.click("text=Columns")
page.click("text=Add Derived")
expr = page.query_selector("#derived_list .derived textarea")
assert expr
name_inp = page.query_selector("#derived_list .derived .d-name")
assert name_inp
name_inp.fill("value_2")
expr.fill("value * 2")
page.click("text=View Settings")
page.fill("#start", "2024-01-01 00:00:00")
page.fill("#end", "2024-01-03 00:00:00")
select_value(page, "#granularity", "1 hour")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
count = page.eval_on_selector_all("#chart path", "els => els.length")
assert count == 2
def test_help_and_alignment(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
titles = page.evaluate(
"Array.from(document.querySelectorAll('#settings .help')).map(e => e.tit
le)"
)
assert any("start/end of the time range" in t for t in titles)
text_align = page.evaluate(
"getComputedStyle(document.querySelector('#settings label')).textAlign"
)
assert text_align == "right"
def test_table_sorting(page: Any, server_url: str) -> None:
run_query(
page,
server_url,
start="2024-01-01 00:00:00",
end="2024-01-03 00:00:00",
order_by="timestamp",
order_dir="ASC",
limit=100,
)
# header alignment
align = page.evaluate(
"getComputedStyle(document.querySelector('#results th')).textAlign"
)
assert align == "right"
header = page.locator("#results th").nth(3)
def values() -> list[str]:
return page.locator("#results td:nth-child(4)").all_inner_texts()
orig_rows = values()
assert orig_rows == ["alice", "bob", "alice", "charlie"]
...
assert count == 4
page.click("#columns_none")
count = page.evaluate(
"document.querySelectorAll('#column_groups input:checked').length"
)
assert count == 0
page.click("#columns_all")
count = page.evaluate(
"document.querySelectorAll('#column_groups input:checked').length"
)
assert count == 4
page.uncheck("#column_groups input[value='value']")
page.click("text=View Settings")
page.fill("#start", "2024-01-01 00:00:00")
page.fill("#end", "2024-01-02 00:00:00")
select_value(page, "#order_by", "timestamp")
page.fill("#limit", "10")
page.evaluate("window.lastResults = undefined")
page.click("text=Dive")
page.wait_for_function("window.lastResults !== undefined")
data = page.evaluate("window.lastResults")
assert len(data["rows"][0]) == 3
headers = page.locator("#results th").all_inner_texts()
assert "value" not in headers
def test_columns_links_alignment(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
page.click("text=Columns")
page.wait_for_selector("#column_groups input", state="attached")
tag = page.evaluate("document.getElementById('columns_all').tagName")
assert tag == "A"
align = page.evaluate(
"getComputedStyle(document.querySelector('#column_actions')).textAlign"
)
assert align == "right"
def test_column_group_links(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
page.click("text=Columns")
page.wait_for_selector("#column_groups a", state="attached")
tag = page.evaluate("document.querySelector('#column_groups .col-group a').t
agName")
assert tag == "A"
def test_column_group_links_float_right(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
page.click("text=Columns")
page.wait_for_selector("#column_groups .col-group .links", state="attached")
float_val = page.evaluate(
"getComputedStyle(document.querySelector('#column_groups .col-group .lin
ks')).float"
)
assert float_val == "right"
def test_chip_dropdown_navigation(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
page.click("text=Add Filter")
f = page.query_selector("#filters .filter:last-child")
assert f
page.evaluate(
"arg => setSelectValue(arg.el.querySelector('.f-col'), arg.val)",
{"el": f, "val": "user"},
)
inp = f.query_selector(".f-val")
inp.click()
page.wait_for_selector("#filters .filter:last-child .chip-dropdown div")
page.keyboard.type("ali")
page.wait_for_selector("text=alice")
page.keyboard.press("ArrowDown")
page.keyboard.press("Enter")
chips = page.evaluate(
"Array.from(document.querySelectorAll('#filters .filter:last-child .chip
')).map(c => c.firstChild.textContent)"
)
assert chips == ["ali"]
page.click("#filters .filter:last-child .chip .x")
page.wait_for_selector(".chip", state="detached")
def test_chip_copy_and_paste(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#order_by option", state="attached")
page.evaluate(
"Object.defineProperty(navigator, 'clipboard', {value:{ _data: '', write
Text(t){ this._data = t; }, readText(){ return Promise.resolve(this._data); } }}
)"
)
page.click("text=Add Filter")
f = page.query_selector("#filters .filter:last-child")
assert f
page.evaluate(
"arg => setSelectValue(arg.el.querySelector('.f-col'), arg.val)",
{"el": f, "val": "user"},
)
inp = f.query_selector(".f-val")
inp.click()
page.keyboard.type("alice")
page.keyboard.press("Enter")
inp.click()
page.keyboard.type("bob")
page.keyboard.press("Enter")
f.query_selector(".chip-copy").click()
assert page.evaluate("navigator.clipboard._data") == "alice,bob"
page.evaluate(
"var f=document.querySelector('#filters .filter:last-child'); f.chips=[]
; f.querySelectorAll('.chip').forEach(c=>c.remove())"
)
page.wait_for_selector("#filters .chip", state="detached")
inp.click()
page.evaluate(
"var dt=new DataTransfer(); dt.setData('text/plain','alice,bob'); var e=
new ClipboardEvent('paste',{clipboardData:dt}); document.querySelector('#filters
.filter:last-child .f-val').dispatchEvent(e);"
)
I’ll search for tests related to time series x-axis defaults.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'x_axis' tests/test_web.py
211: assert page.is_visible("#x_axis_field")
I need to add a test for the default x-axis featuring the time column setting.
import re
from datetime import datetime, timedelta, timezone
import time
from pathlib import Path
import os
import sqlite3
import traceback
import math
import duckdb
from dateutil import parser as dtparser
from flask import Flask, jsonify, request, send_from_directory
@dataclass
class Filter:
column: str
op: str
value: str | int | float | list[str] | None
@dataclass
class QueryParams:
start: str | None = None
end: str | None = None
order_by: str | None = None
order_dir: str = "ASC"
limit: int | None = None
columns: list[str] = field(default_factory=lambda: [])
filters: list[Filter] = field(default_factory=lambda: [])
derived_columns: dict[str, str] = field(default_factory=lambda: {})
graph_type: str = "samples"
group_by: list[str] = field(default_factory=lambda: [])
aggregate: str | None = None
show_hits: bool = False
x_axis: str | None = None
granularity: str = "Auto"
fill: str = "0"
table: str = "events"
time_column: str = "timestamp"
time_unit: str = "s"
def _normalize_sqlite_type(sql: str) -> str:
"""Map arbitrary SQLite column types to DuckDB-compatible types."""
t = sql.strip().upper()
if "(" in t:
t = t.split("(", 1)[0]
if "INT" in t:
# SQLite only has a single INTEGER type which is always 64-bit.
# Use DuckDB's BIGINT to avoid overflow when values exceed INT32.
return "BIGINT"
if any(key in t for key in ("CHAR", "CLOB", "TEXT")):
return "VARCHAR"
if "BLOB" in t:
return "BLOB"
if any(key in t for key in ("DOUBLE", "REAL", "FLOA", "NUMERIC", "DECIMAL"))
:
return "DOUBLE"
if "BOOL" in t:
return "BOOLEAN"
if "DATE" in t or "TIME" in t:
return "TIMESTAMP" if "TIME" in t else "DATE"
return "VARCHAR"
def _load_database(path: Path) -> duckdb.DuckDBPyConnection:
if not path.exists():
raise FileNotFoundError(path)
ext = path.suffix.lower()
if ext == ".csv":
con = duckdb.connect()
con.execute(
f"CREATE TABLE events AS SELECT * FROM read_csv_auto('{path.as_posix
()}')"
)
elif ext in {".db", ".sqlite"}:
con = duckdb.connect()
try:
con.execute("LOAD sqlite")
con.execute(f"ATTACH '{path.as_posix()}' AS db (TYPE SQLITE)")
tables = [
r[0]
for r in con.execute(
"SELECT name FROM db.sqlite_master WHERE type='table'"
).fetchall()
]
for t in tables:
con.execute(f'CREATE VIEW "{t}" AS SELECT * FROM db."{t}"')
except Exception:
sconn = sqlite3.connect(path)
tables = [
r[0]
for r in sconn.execute(
"SELECT name FROM sqlite_master WHERE type='table'"
).fetchall()
]
for t in tables:
info = sconn.execute(f'PRAGMA table_info("{t}")').fetchall()
col_defs = ", ".join(
f'"{r[1]}" {_normalize_sqlite_type(cast(str, r[2]))}' for r
in info
)
sql = f'CREATE TABLE "{t}" ({col_defs})'
try:
con.execute(sql)
except Exception:
print(f"Failed SQL: {sql}")
raise
placeholders = ",".join("?" for _ in info)
for row in sconn.execute(f'SELECT * FROM "{t}"'):
con.execute(f'INSERT INTO "{t}" VALUES ({placeholders})', ro
w)
sconn.close()
else:
con = duckdb.connect(path)
return con
_REL_RE = re.compile(
r"([+-]?\d+(?:\.\d*)?)\s*(hour|hours|day|days|week|weeks|fortnight|fortnight
s)",
re.IGNORECASE,
)
def parse_time(val: str | None) -> str | None:
"""Parse an absolute or relative time string into ``YYYY-MM-DD HH:MM:SS``.""
"
if val is None or val == "":
return None
s = val.strip()
if s.lower() == "now":
dt = datetime.now(timezone.utc)
return dt.replace(microsecond=0).strftime("%Y-%m-%d %H:%M:%S")
m = _REL_RE.fullmatch(s)
if m:
qty = float(m.group(1))
unit = m.group(2).lower()
delta: timedelta
if unit.startswith("hour"):
delta = timedelta(hours=qty)
elif unit.startswith("day"):
delta = timedelta(days=qty)
elif unit.startswith("week"):
delta = timedelta(weeks=qty)
elif unit.startswith("fortnight"):
delta = timedelta(weeks=2 * qty)
else: # pragma: no cover - defensive
raise ValueError(f"Unsupported unit: {unit}")
dt = datetime.now(timezone.utc) + delta
return dt.replace(microsecond=0).strftime("%Y-%m-%d %H:%M:%S")
dt = dtparser.parse(s)
return dt.replace(microsecond=0, tzinfo=None).strftime("%Y-%m-%d %H:%M:%S")
def _granularity_seconds(granularity: str, start: str | None, end: str | None) -
> int:
gran = granularity.lower()
mapping = {
"1 second": 1,
"5 seconds": 5,
"10 seconds": 10,
"30 seconds": 30,
"1 minute": 60,
"4 minutes": 240,
"5 minutes": 300,
"10 minutes": 600,
"15 minutes": 900,
"30 minutes": 1800,
"1 hour": 3600,
"3 hours": 10800,
"6 hours": 21600,
"1 day": 86400,
"1 week": 604800,
"30 days": 2592000,
}
if gran in mapping:
return mapping[gran]
if gran in {"auto", "fine"} and start and end:
try:
s = dtparser.parse(start)
e = dtparser.parse(end)
except Exception:
return 3600
total = max((e - s).total_seconds(), 1)
buckets = 100 if gran == "auto" else 500
return max(int(total // buckets), 1)
return 3600
def _time_expr(col: str, column_types: Dict[str, str] | None, unit: str) -> str:
"""Return SQL expression for column interpreted as timestamp."""
if column_types is None:
return col
ctype = column_types.get(col, "").upper()
if not any(t in ctype for t in ["TIMESTAMP", "DATE", "TIME"]):
if any(
t in ctype
for t in [
"INT",
"DECIMAL",
"REAL",
"DOUBLE",
"FLOAT",
"NUMERIC",
"HUGEINT",
]
):
divisor = {
"s": 1,
"ms": 1000,
"us": 1_000_000,
"ns": 1_000_000_000,
}.get(unit, 1)
if divisor == 1:
expr = f"CAST({col} AS BIGINT)"
else:
expr = f"CAST({col} / {divisor} AS BIGINT)"
return f"TIMESTAMP 'epoch' + INTERVAL '1 second' * {expr}"
return col
def build_query(params: QueryParams, column_types: Dict[str, str] | None = None)
-> str:
select_parts: list[str] = []
group_cols = params.group_by[:]
if params.graph_type == "timeseries":
sec = _granularity_seconds(params.granularity, params.start, params.end)
x_axis = params.x_axis or params.time_column
xexpr = _time_expr(x_axis, column_types, params.time_unit)
if params.start:
bucket_expr = (
f"TIMESTAMP '{params.start}' + INTERVAL '{sec} second' * "
f"CAST(floor((epoch({xexpr}) - epoch(TIMESTAMP '{params.start}')
)/{sec}) AS BIGINT)"
)
else:
bucket_expr = (
f"TIMESTAMP 'epoch' + INTERVAL '{sec} second' * "
f"CAST(floor(epoch({xexpr})/{sec}) AS BIGINT)"
)
select_parts.append(f"{bucket_expr} AS bucket")
group_cols = ["bucket"] + group_cols
has_agg = bool(group_cols) or params.aggregate is not None
if has_agg:
select_cols = (
group_cols[1:] if params.graph_type == "timeseries" else group_cols
)
select_parts.extend(select_cols)
agg = (params.aggregate or "avg").lower()
def agg_expr(col: str) -> str:
if agg.startswith("p"):
quant = float(agg[1:]) / 100
return f"quantile({col}, {quant})"
if agg == "count distinct":
return f"count(DISTINCT {col})"
if agg == "avg" and column_types is not None:
ctype = column_types.get(col, "").upper()
if "TIMESTAMP" in ctype or "DATE" in ctype or "TIME" in ctype:
return (
"TIMESTAMP 'epoch' + INTERVAL '1 second' * "
f"CAST(avg(epoch({col})) AS BIGINT)"
)
return f"{agg}({col})"
for col in params.columns:
if col in group_cols:
continue
select_parts.append(f"{agg_expr(col)} AS {col}")
if params.show_hits:
select_parts.insert(len(group_cols), "count(*) AS Hits")
else:
select_parts.extend(params.columns)
if has_agg and params.derived_columns:
inner_params = replace(
params,
derived_columns={},
order_by=None,
limit=None,
)
inner_sql = build_query(inner_params, column_types)
outer_select = ["t.*"] + [
f"{expr} AS {name}" for name, expr in params.derived_columns.items()
]
indented_inner = "\n".join(" " + line for line in inner_sql.splitline
s())
lines = [
f"SELECT {', '.join(outer_select)}",
"FROM (",
indented_inner,
") t",
]
if params.order_by:
lines.append(f"ORDER BY {params.order_by} {params.order_dir}")
elif params.graph_type == "timeseries":
lines.append("ORDER BY bucket")
if params.limit is not None:
lines.append(f"LIMIT {params.limit}")
return "\n".join(lines)
for name, expr in params.derived_columns.items():
select_parts.append(f"{expr} AS {name}")
select_clause = ", ".join(select_parts) if select_parts else "*"
lines = [f"SELECT {select_clause}", f'FROM "{params.table}"']
where_parts: list[str] = []
time_expr = _time_expr(params.time_column, column_types, params.time_unit)
if params.start:
where_parts.append(f"{time_expr} >= '{params.start}'")
if params.end:
where_parts.append(f"{time_expr} <= '{params.end}'")
for f in params.filters:
op = f.op
if op in {"empty", "!empty"}:
val = "''"
else:
if f.value is None:
continue
if isinstance(f.value, list):
I'm continuing to scroll through more lines to get the full context.
if isinstance(f.value, list):
if not f.value:
continue
if op == "=":
vals = " OR ".join(f"{f.column} = '{v}'" for v in f.value)
where_parts.append(f"({vals})")
continue
val = f"'{f.value}'" if isinstance(f.value, str) else str(f.value)
if op == "contains":
where_parts.append(f"{f.column} ILIKE '%' || {val} || '%'")
elif op == "!contains":
where_parts.append(f"{f.column} NOT ILIKE '%' || {val} || '%'")
elif op == "empty":
where_parts.append(f"{f.column} = {val}")
elif op == "!empty":
where_parts.append(f"{f.column} != {val}")
else:
where_parts.append(f"{f.column} {op} {val}")
if where_parts:
lines.append("WHERE " + " AND ".join(where_parts))
if group_cols:
lines.append("GROUP BY " + ", ".join(group_cols))
if params.order_by:
lines.append(f"ORDER BY {params.order_by} {params.order_dir}")
elif params.graph_type == "timeseries":
lines.append("ORDER BY bucket")
if params.limit is not None:
lines.append(f"LIMIT {params.limit}")
return "\n".join(lines)
def create_app(db_file: str | Path | None = None) -> Flask:
app = Flask(__name__, static_folder="static")
if db_file is None:
env_db = os.environ.get("SCUBADUCK_DB")
if env_db:
db_file = env_db
db_path = Path(db_file or Path(__file__).with_name("sample.csv")).resolve()
con = _load_database(db_path)
tables = [r[0] for r in con.execute("SHOW TABLES").fetchall()]
if not tables:
raise ValueError("No tables found in database")
default_table = tables[0]
columns_cache: Dict[str, Dict[str, str]] = {}
def get_columns(table: str) -> Dict[str, str]:
if table not in columns_cache:
rows = con.execute(f'PRAGMA table_info("{table}")').fetchall()
if not rows:
raise ValueError(f"Unknown table: {table}")
columns_cache[table] = {r[1]: r[2] for r in rows}
return columns_cache[table]
sample_cache: Dict[Tuple[str, str, str], Tuple[List[str], float]] = {}
CACHE_TTL = 60.0
CACHE_LIMIT = 200
@app.route("/")
def index() -> Any: # pyright: ignore[reportUnusedFunction]
assert app.static_folder is not None
return send_from_directory(app.static_folder, "index.html")
@app.route("/js/<path:filename>")
def js(filename: str) -> Any: # pyright: ignore[reportUnusedFunction]
assert app.static_folder is not None
folder = Path(app.static_folder) / "js"
return send_from_directory(folder, filename)
@app.route("/api/tables")
def tables_endpoint() -> Any: # pyright: ignore[reportUnusedFunction]
return jsonify(tables)
@app.route("/api/columns")
def columns() -> Any: # pyright: ignore[reportUnusedFunction]
table = request.args.get("table", default_table)
rows = con.execute(f'PRAGMA table_info("{table}")').fetchall()
return jsonify([{"name": r[1], "type": r[2]} for r in rows])
def _cache_get(key: Tuple[str, str, str]) -> List[str] | None:
item = sample_cache.get(key)
if item is None:
return None
vals, ts = item
if time.time() - ts > CACHE_TTL:
del sample_cache[key]
return None
sample_cache[key] = (vals, time.time())
return vals
def _cache_set(key: Tuple[str, str, str], vals: List[str]) -> None:
sample_cache[key] = (vals, time.time())
if len(sample_cache) > CACHE_LIMIT:
oldest = min(sample_cache.items(), key=lambda kv: kv[1][1])[0]
del sample_cache[oldest]
@app.route("/api/samples")
def sample_values() -> Any: # pyright: ignore[reportUnusedFunction]
table = request.args.get("table", default_table)
column = request.args.get("column")
substr = request.args.get("q", "")
column_types = get_columns(table)
if not column or column not in column_types:
return jsonify([])
ctype = column_types[column].upper()
if "CHAR" not in ctype and "STRING" not in ctype and "VARCHAR" not in ct
ype:
return jsonify([])
key = (table, column, substr)
cached = _cache_get(key)
if cached is not None:
return jsonify(cached)
rows = con.execute(
f"SELECT DISTINCT {column} FROM \"{table}\" WHERE CAST({column} AS V
ARCHAR) ILIKE '%' || ? || '%' LIMIT 20",
[substr],
).fetchall()
values = [r[0] for r in rows]
_cache_set(key, values)
return jsonify(values)
@app.route("/api/query", methods=["POST"])
def query() -> Any: # pyright: ignore[reportUnusedFunction]
payload = request.get_json(force=True)
...
if params.group_by or params.graph_type == "timeseries":
agg = (params.aggregate or "avg").lower()
if agg.startswith("p") or agg == "sum":
need_numeric = True
allow_time = False
elif agg == "avg" or agg in {"min", "max"}:
need_numeric = False
allow_time = True
else:
need_numeric = False
allow_time = False
if need_numeric or allow_time:
for c in params.columns:
if c in params.group_by or c == params.x_axis:
continue
if c not in column_types:
continue
ctype = column_types.get(c, "").upper()
is_numeric = any(
t in ctype
for t in [
"INT",
"DECIMAL",
"REAL",
"DOUBLE",
"FLOAT",
"NUMERIC",
"HUGEINT",
]
)
is_time = "TIMESTAMP" in ctype or "DATE" in ctype or "TIME"
in ctype
if need_numeric and not is_numeric:
return (
jsonify(
{
"error": f"Aggregate {agg} cannot be applied
to column {c}",
}
),
400,
)
if allow_time and not (is_numeric or is_time):
return (
jsonify(
{
"error": f"Aggregate {agg} cannot be applied
to column {c}",
}
),
400,
)
if params.start is None or params.end is None:
axis = params.x_axis or params.time_column
row = cast(
tuple[datetime | None, datetime | None],
con.execute(
f'SELECT min({axis}), max({axis}) FROM "{params.table}"'
).fetchall()[0],
)
mn, mx = row
divisor = {
"s": 1,
"ms": 1000,
"us": 1_000_000,
"ns": 1_000_000_000,
}.get(params.time_unit, 1)
if isinstance(mn, (int, float)):
try:
mn = datetime.fromtimestamp(int(mn) / divisor, tz=timezone.u
tc)
except Exception:
return (
jsonify(
{
"error": (
f"Invalid time value {mn} for column {axis}"
f" with time_unit {params.time_unit}"
)
}
),
400,
)
if isinstance(mx, (int, float)):
try:
mx = datetime.fromtimestamp(int(mx) / divisor, tz=timezone.u
tc)
except Exception:
return (
jsonify(
{
"error": (
f"Invalid time value {mx} for column {axis}"
f" with time_unit {params.time_unit}"
)
}
),
400,
)
if params.start is None and mn is not None:
params.start = (
mn.strftime("%Y-%m-%d %H:%M:%S") if not isinstance(mn, str)
else mn
)
if params.end is None and mx is not None:
params.end = (
mx.strftime("%Y-%m-%d %H:%M:%S") if not isinstance(mx, str)
else mx
)
bucket_size: int | None = None
if params.graph_type == "timeseries":
bucket_size = _granularity_seconds(
params.granularity,
params.start if isinstance(params.start, str) else None,
params.end if isinstance(params.end, str) else None,
)
if (
params.limit is not None
and params.start is not None
and params.end is not None
):
try:
I’m checking further between lines 640 and 960 to capture the end of the query.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '640,960p' scubaduck/server.py
try:
start_dt = dtparser.parse(params.start)
end_dt = dtparser.parse(params.end)
buckets = math.ceil(
(end_dt - start_dt).total_seconds() / bucket_size
)
if buckets > 1:
params.limit *= buckets
except Exception:
pass
sql = build_query(params, column_types)
try:
rows = con.execute(sql).fetchall()
except Exception as exc:
tb = traceback.format_exc()
print(f"Query failed:\n{sql}\n{tb}")
return (
jsonify({"sql": sql, "error": str(exc), "traceback": tb}),
400,
)
result: Dict[str, Any] = {"sql": sql, "rows": rows}
if params.start is not None:
result["start"] = str(params.start)
if params.end is not None:
result["end"] = str(params.end)
if bucket_size is not None:
result["bucket_size"] = bucket_size
return jsonify(result)
return app
app = create_app()
if __name__ == "__main__":
app.run(debug=True)
I think the dropdown may currently list numeric or timestamp columns. I'll check index.html or JS.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ScubaDuck</title>
<style>
body { margin: 0; font-family: sans-serif; height: 100vh; display: flex; fle
x-direction: column; }
#header { padding: 10px; font-weight: bold; border-bottom: 1px solid #ccc; }
#content { flex: 1; display: flex; height: calc(100vh - 42px); overflow: hid
den; }
#sidebar { width: 450px; padding: 10px; border-right: 3px solid #ccc; overfl
ow-y: auto; display: flex; flex-direction: column; box-sizing: border-box; }
#sidebar-resizer { width: 5px; cursor: col-resize; background: #ccc; }
#view { flex: 1; padding: 10px; overflow-y: auto; overflow-x: auto; }
.field { display: flex; align-items: center; margin-bottom: 10px; }
.field label { width: 80px; text-align: right; margin-right: 5px; }
.help { margin-left: 4px; cursor: help; }
.rel-btn { margin-left: 4px; }
#tabs { display: flex; align-items: center; margin-bottom: 10px; }
#tabs .tab { margin-right: 5px; background: none; border: 1px solid #ccc; pa
dding: 4px 8px; cursor: pointer; width: 120px; text-align: center; box-sizing: b
order-box; }
#tabs .tab.active { background: #eee; font-weight: bold; }
#dive { margin-left: auto; background: green; color: white; border: none; pa
dding: 5px 10px; cursor: pointer; }
.tab-content { display: none; }
.tab-content.active { display: block; }
#filter_list { display: flex; flex-direction: column; }
#filters .filter {
border: 1px solid #ccc;
padding: 5px;
margin-bottom: 5px;
position: relative;
display: flex;
flex-direction: column;
}
#derived_columns .derived {
border: 1px solid #ccc;
padding: 5px;
margin-bottom: 5px;
display: flex;
flex-direction: column;
}
#derived_columns .derived-row {
display: flex;
margin-bottom: 5px;
}
#derived_columns .derived-row input[type="text"] {
margin-left: 5px;
flex: 1;
}
#derived_columns .derived-row button.remove {
margin-left: 5px;
width: 20px;
flex: 0 0 auto;
padding: 0;
text-align: center;
line-height: 1;
}
#derived_columns textarea {
width: 100%;
box-sizing: border-box;
}
#filters .filter-row { display: flex; margin-bottom: 5px; }
#filters .filter-row .f-col { flex: 1; }
#filters .filter-row .f-op {
margin-left: 5px;
width: fit-content;
flex: 0 0 auto;
}
.chip-input input {
border: none;
flex: 1;
min-width: 60px;
margin: 2px;
outline: none;
}
.chip-box { position: relative; }
.chip-input { display: flex; flex-wrap: wrap; border: 1px solid #ccc; paddin
g: 2px; min-height: 24px; }
.chip { background: #eee; border: 1px solid #999; padding: 2px 4px; margin:
2px; border-radius: 3px; display: flex; align-items: center; }
.chip .x { margin-left: 4px; cursor: pointer; }
.chip-copy { margin-left: 4px; cursor: pointer; background: none; border: no
ne; }
.chip-dropdown { position: absolute; left: 0; right: 0; top: 100%; backgroun
d: white; border: 1px solid #ccc; max-height: 120px; overflow-y: auto; z-index:
10; display: none; }
.chip-dropdown div { padding: 2px 4px; cursor: pointer; }
.chip-dropdown div.highlight { background: #bde4ff; }
.rel-box { position: relative; display: flex; }
.rel-dropdown { position: absolute; left: 0; right: 0; top: 100%; background
: white; border: 1px solid #ccc; z-index: 10; display: none; }
.rel-dropdown div { padding: 2px 4px; cursor: pointer; }
.rel-dropdown div:hover { background: #bde4ff; }
.dropdown { position: relative; display: inline-block; }
.dropdown-display {
border: 1px solid #ccc;
padding: 2px 18px 2px 4px;
cursor: pointer;
min-width: 80px;
position: relative;
}
.dropdown-display::after {
content: '\25BC';
position: absolute;
right: 4px;
pointer-events: none;
}
.dropdown-menu { position: absolute; left: 0; right: 0; top: 100%; backgroun
d: white; border: 1px solid #ccc; z-index: 10; max-height: 160px; overflow-y: au
to; display: none; }
.dropdown-menu input { width: 100%; box-sizing: border-box; padding: 2px 4px
; border: none; border-bottom: 1px solid #ccc; }
.dropdown-menu div { padding: 2px 4px; cursor: pointer; }
.dropdown-menu div.selected { background: #bde4ff; }
.dropdown-menu .option:hover { background: #eee; }
.dropdown-menu input::placeholder { color: #999; }
#filters .filter button.remove {
margin-left: 5px;
width: 20px;
flex: 0 0 auto;
padding: 0;
text-align: center;
line-height: 1;
}
#filters h4 { margin: 0 0 5px 0; }
table { border-collapse: collapse; min-width: 100%; }
th, td { border: 1px solid #ccc; padding: 4px; box-sizing: border-box; }
th { text-align: left; cursor: pointer; position: relative; }
th.sorted { color: blue; }
tr:nth-child(even) td { background: #f9f9f9; }
tr.selected td { background: #bde4ff !important; }
tr:hover:not(.selected) td { background: #eee; }
#column_actions {
text-align: right;
margin-bottom: 5px;
}
#column_actions a {
margin-left: 5px;
}
.col-group-header {
overflow: hidden;
}
.col-group-header .links {
float: right;
}
.col-group-header .links a {
margin-left: 5px;
}
#ts-container {
display: flex;
}
#legend {
width: 150px;
flex: 0 0 150px;
margin-right: 10px;
overflow-y: auto;
}
.legend-group {
margin-bottom: 4px;
}
.legend-header {
font-weight: normal;
}
.legend-item {
display: flex;
justify-content: space-between;
padding-left: 8px;
}
.legend-value {
margin-left: 4px;
}
#chart-wrapper {
flex: 1;
}
.legend-item.highlight {
background: #ddd;
}
#legend .drill-links h4 {
margin: 10px 0 4px 0;
}
#legend .drill-links a {
display: block;
margin-left: 8px;
}
#chart text.tick-label {
font-size: 10px;
user-select: none;
}
#chart text.tick-label.rotated {
text-anchor: end;
}
#chart text.y-tick-label {
font-size: 10px;
user-select: none;
}
#chart line.grid {
stroke: #ccc;
}
/* Column resizer removed */
</style>
</head>
<body>
<div id="header">sample.csv - <select id="table"></select> <select id="graph_t
ype"><option value="samples">Samples</option><option value="table">Table</option
><option value="timeseries">Time Series</option></select></div>
<div id="content">
<div id="sidebar">
<div id="tabs">
<button class="tab active" data-tab="settings">View Settings</button>
<button class="tab" data-tab="columns">Columns</button>
<button id="dive" onclick="dive()">Dive</button>
</div>
<div id="settings" class="tab-content active">
<div class="field">
I’m scrolling to find the time column and its related elements.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'time_column' -n scubaduck/stati
c/index.html
202: <select id="time_column"></select>
531: const timeColumnSelect = document.getElementById('time_column');
762: const sel = document.getElementById('time_column').value;
971: time_column: document.getElementById('time_column').value,
1015: if (params.time_column) sp.set('time_column', params.time_column);
1042: document.getElementById('time_column').value = params.time_column || defa
ultTimeColumn;
1102: if (sp.has('time_column')) params.time_column = sp.get('time_column');
I'll check out the settings section in index.html.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '180,240p' scubaduck/static/index
.html
#chart text.y-tick-label {
font-size: 10px;
user-select: none;
}
#chart line.grid {
stroke: #ccc;
}
/* Column resizer removed */
</style>
</head>
<body>
<div id="header">sample.csv - <select id="table"></select> <select id="graph_t
ype"><option value="samples">Samples</option><option value="table">Table</option
><option value="timeseries">Time Series</option></select></div>
<div id="content">
<div id="sidebar">
<div id="tabs">
<button class="tab active" data-tab="settings">View Settings</button>
<button class="tab" data-tab="columns">Columns</button>
<button id="dive" onclick="dive()">Dive</button>
</div>
<div id="settings" class="tab-content active">
<div class="field">
<label>Time Column</label>
<select id="time_column"></select>
<select id="time_unit" style="margin-left:4px">
<option value="s">s</option>
<option value="ms">ms</option>
<option value="us">us</option>
<option value="ns">ns</option>
</select>
</div>
<div class="field">
<label>Start<span class="help" title="Sets the start/end of the time r
ange to query. Can be any kind of datetime string. For example: 'April 23, 2014'
or 'yesterday'.">[?]</span></label>
<div class="rel-box">
<input id="start" type="text" />
<button type="button" class="rel-btn" data-target="start-select">	
660;</button>
<div id="start-select" class="rel-dropdown" data-input="start">
<div data-value="-1 hour">-1 hour</div>
<div data-value="-3 hours">-3 hours</div>
<div data-value="-12 hours">-12 hours</div>
<div data-value="-1 day">-1 day</div>
<div data-value="-3 days">-3 days</div>
<div data-value="-1 week">-1 week</div>
<div data-value="-1 fortnight">-1 fortnight</div>
<div data-value="-30 days">-30 days</div>
<div data-value="-90 days">-90 days</div>
</div>
</div>
</div>
<div class="field">
<label>End<span class="help" title="Sets the start/end of the time ran
ge to query. Can be any kind of datetime string. For example: 'April 23, 2014' o
r 'yesterday'.">[?]</span></label>
<div class="rel-box">
<input id="end" type="text" />
<button type="button" class="rel-btn" data-target="end-select">φ
0;</button>
<div id="end-select" class="rel-dropdown" data-input="end">
<div data-value="now">now</div>
<div data-value="-1 hour">-1 hour</div>
<div data-value="-3 hours">-3 hours</div>
<div data-value="-12 hours">-12 hours</div>
<div data-value="-1 day">-1 day</div>
<div data-value="-3 days">-3 days</div>
<div data-value="-1 week">-1 week</div>
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'x_axis_field' -n scubaduck/stat
ic/index.html
256: <div id="x_axis_field" class="field" style="display:none;">
496: document.getElementById('x_axis_field').style.display = showTS ? 'flex' :
'none';
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '252,272p' scubaduck/static/index
.html
<div class="field">
<label>Limit<span class="help" title="Choose the maximum number of res
ults to show in the chart after any aggregations have been applied. For example,
a limit of 10 will show no more than 10 rows for a table, etc.">[?]</span></lab
el>
<input id="limit" type="number" value="100" />
</div>
<div id="x_axis_field" class="field" style="display:none;">
<label>X-axis</label>
<select id="x_axis"></select>
</div>
<div id="granularity_field" class="field" style="display:none;">
<label>Granularity</label>
<select id="granularity">
<option>Auto</option>
<option>Fine</option>
<option>1 second</option>
<option>5 seconds</option>
<option>10 seconds</option>
<option>30 seconds</option>
<option>1 minute</option>
<option>4 minutes</option>
<option>5 minutes</option>
<option>10 minutes</option>
I'm looking for code related to the JS x_axis population selection.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'x_axis' -n scubaduck/static/ind
ex.html
256: <div id="x_axis_field" class="field" style="display:none;">
258: <select id="x_axis"></select>
496: document.getElementById('x_axis_field').style.display = showTS ? 'flex' :
'none';
529: const xAxisSelect = document.getElementById('x_axis');
763: const xsel = document.getElementById('x_axis').value;
1005: payload.x_axis = document.getElementById('x_axis').value;
1032: if (params.x_axis) sp.set('x_axis', params.x_axis);
1056: if (params.x_axis) document.getElementById('x_axis').value = params.x_axi
s;
1117: if (sp.has('x_axis')) params.x_axis = sp.get('x_axis');
I’ll look at lines 529 and 763 for JS functions related to dropdown population.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '520,540p' scubaduck/static/index
.html
orderDir = orderDir === 'ASC' ? 'DESC' : 'ASC';
updateOrderDirButton();
});
updateOrderDirButton();
graphTypeSel.addEventListener('change', updateDisplayTypeUI);
function loadColumns(table) {
return fetch('/api/columns?table=' + encodeURIComponent(table)).then(r => r.js
on()).then(cols => {
const orderSelect = document.getElementById('order_by');
const xAxisSelect = document.getElementById('x_axis');
const groupsEl = document.getElementById('column_groups');
const timeColumnSelect = document.getElementById('time_column');
orderSelect.innerHTML = '';
xAxisSelect.innerHTML = '';
timeColumnSelect.innerHTML = '';
groupsEl.innerHTML = '';
allColumns.length = 0;
stringColumns.length = 0;
integerColumns.length = 0;
timeColumns.length = 0;
timeColumnOptions.length = 0;
I’m paging through more lines to check the x_axis population in loadColumns.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '540,620p' scubaduck/static/index
.html
timeColumnOptions.length = 0;
baseColumns.length = 0;
baseStringColumns.length = 0;
baseIntegerColumns.length = 0;
baseTimeColumns.length = 0;
baseTimeColumnOptions.length = 0;
for (const k in columnTypes) delete columnTypes[k];
const groups = {
time: {name: 'Time', cols: [], ul: null},
integer: {name: 'Integers', cols: [], ul: null},
string: {name: 'Strings', cols: [], ul: null},
};
const heur = ['timestamp','created','created_at','event_time','time','date',
'occurred','happened','logged'];
let guess = null;
cols.forEach(c => {
const t = c.type.toUpperCase();
columnTypes[c.name] = c.type;
allColumns.push(c.name);
baseColumns.push(c.name);
let g = 'string';
const isNumeric = t.includes('INT') || t.includes('DECIMAL') || t.includes
('NUMERIC') || t.includes('REAL') || t.includes('DOUBLE') || t.includes('FLOAT')
|| t.includes('HUGEINT');
const isTimeType = t.includes('TIMESTAMP') || t.includes('DATE') || t.incl
udes('TIME');
if (isNumeric || isTimeType) {
timeColumnOptions.push(c.name);
baseTimeColumnOptions.push(c.name);
if (!guess && heur.some(h => c.name.toLowerCase().includes(h))) guess =
c.name;
}
if (isTimeType) {
g = 'time';
timeColumns.push(c.name);
baseTimeColumns.push(c.name);
} else if (isNumeric) {
g = 'integer';
}
if (g === 'string') {
stringColumns.push(c.name);
baseStringColumns.push(c.name);
} else if (g === 'integer') {
integerColumns.push(c.name);
baseIntegerColumns.push(c.name);
}
groups[g].cols.push(c.name);
if (g !== 'string') {
const o = document.createElement('option');
o.value = c.name;
o.textContent = c.name;
orderSelect.appendChild(o);
}
});
timeColumns.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
xAxisSelect.appendChild(o);
});
timeColumnOptions.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
timeColumnSelect.appendChild(o);
});
defaultTimeColumn = guess || timeColumnOptions[0] || '';
Object.keys(groups).forEach(key => {
const g = groups[key];
const div = document.createElement('div');
div.className = 'col-group';
const header = document.createElement('div');
header.className = 'col-group-header';
header.appendChild(document.createTextNode(g.name + ': '));
const links = document.createElement('span');
links.className = 'links';
const allBtn = document.createElement('a');
allBtn.href = '#';
allBtn.textContent = 'All';
const noneBtn = document.createElement('a');
noneBtn.href = '#';
noneBtn.textContent = 'None';
links.appendChild(allBtn);
links.appendChild(noneBtn);
header.appendChild(links);
div.appendChild(header);
I need a little more context to see how loadColumns ends.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '620,680p' scubaduck/static/index
.html
div.appendChild(header);
const ul = document.createElement('ul');
g.ul = ul;
g.cols.forEach(name => {
const li = document.createElement('li');
const label = document.createElement('label');
const cb = document.createElement('input');
cb.type = 'checkbox';
cb.value = name;
cb.checked = true;
cb.addEventListener('change', updateSelectedColumns);
label.appendChild(cb);
label.appendChild(document.createTextNode(' ' + name));
li.appendChild(label);
ul.appendChild(li);
});
allBtn.addEventListener('click', e => {
e.preventDefault();
ul.querySelectorAll('input').forEach(cb => (cb.checked = true));
updateSelectedColumns();
});
noneBtn.addEventListener('click', e => {
e.preventDefault();
ul.querySelectorAll('input').forEach(cb => (cb.checked = false));
updateSelectedColumns();
});
div.appendChild(ul);
groupsEl.appendChild(div);
});
document.getElementById('columns_all').addEventListener('click', e => {
e.preventDefault();
groupsEl.querySelectorAll('input').forEach(cb => (cb.checked = true));
updateSelectedColumns();
});
document.getElementById('columns_none').addEventListener('click', e => {
e.preventDefault();
groupsEl.querySelectorAll('input').forEach(cb => (cb.checked = false));
updateSelectedColumns();
});
updateSelectedColumns();
groupBy = document.getElementById('group_by').closest('.field');
initChipInput(groupBy, typed =>
allColumns.filter(c => c.toLowerCase().includes(typed.toLowerCase()))
);
initDropdown(orderSelect);
initDropdown(document.getElementById('aggregate'));
});
}
let columnsInitialized = false;
fetch('/api/tables').then(r => r.json()).then(tables => {
tables.forEach(t => {
const o = document.createElement('option');
o.value = t;
o.textContent = t;
document.getElementById('table').appendChild(o);
});
const table = parseSearch().table || tables[0];
document.getElementById('table').value = table;
loadColumns(table).then(() => {
updateDisplayTypeUI();
I'm scrolling further to locate more lines related to parseSearch.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'parseSearch' -n scubaduck/stati
c/index.html
677: const table = parseSearch().table || tables[0];
688: applyParams(parseSearch());
1098:function parseSearch() {
1127: const params = parseSearch();
1134: const params = e.state || parseSearch();
.html
if (!selectedColumns.includes(c)) selectedColumns.push(c);
});
derivedColumns.forEach(dc => {
if (dc.include && !selectedColumns.includes(dc.name)) selectedColumns.push
(dc.name);
});
} else {
selectedColumns = base.slice();
derivedColumns.forEach(dc => {
if (dc.include) selectedColumns.push(dc.name);
});
}
}
function isStringColumn(name) {
const t = (columnTypes[name] || '').toUpperCase();
return t.includes('CHAR') || t.includes('STRING') || t.includes('VARCHAR');
}
function isIntegerColumn(name) {
const t = (columnTypes[name] || '').toUpperCase();
return t.includes('INT');
}
function isTimeColumn(name) {
const t = (columnTypes[name] || '').toUpperCase();
if (t.includes('TIMESTAMP') || t.includes('DATE') || t.includes('TIME')) retur
n true;
const sel = document.getElementById('time_column').value;
const xsel = document.getElementById('x_axis').value;
if (name === sel || name === xsel) return true;
return false;
}
function formatNumber(val) {
if (typeof val !== 'number') val = Number(val);
if (Number.isNaN(val)) return '';
if (val === 0) return '0';
const abs = Math.abs(val);
if (abs > 999.999) {
const units = [
{n: 1e12, s: 'T'},
{n: 1e9, s: 'B'},
{n: 1e6, s: 'M'},
{n: 1e3, s: 'K'},
];
for (const u of units) {
if (abs >= u.n) {
return (val / u.n).toFixed(2) + ' ' + u.s;
}
}
}
if (abs < 0.0005) return '0.000';
return val.toFixed(3);
}
function addFilter() {
const container = document.createElement('div');
container.className = 'filter';
container.innerHTML = `
<div class="filter-row">
<select class="f-col"></select>
<select class="f-op"></select>
<button type="button" class="remove" onclick="this.closest('.filter').remo
ve()">✖</button>
</div>
<div class="chip-box">
<div class="chip-input">
<input class="f-val" type="text">
<button type="button" class="chip-copy">⎘</button>
</div>
<div class="chip-dropdown"></div>
</div>
`;
const colSel = container.querySelector('.f-col');
colSel.innerHTML = allColumns.map(c => `<option value="${c}">${c}</option>`).j
oin('');
initDropdown(colSel);
function populateOps() {
const opSel = container.querySelector('.f-op');
const col = colSel.value;
const ops = isStringColumn(col)
? [
['=', '='],
['!=', '!='],
['~', 'matches regex'],
['!~', 'not matches regex'],
Scrolling through the code to check how the time unit is being parsed and handled.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'time_unit' -n scubaduck/static/
index.html
203: <select id="time_unit" style="margin-left:4px">
972: time_unit: document.getElementById('time_unit').value,
1016: if (params.time_unit) sp.set('time_unit', params.time_unit);
1043: if (params.time_unit) document.getElementById('time_unit').value = params
.time_unit;
1103: if (sp.has('time_unit')) params.time_unit = sp.get('time_unit');
1195: const unit = document.getElementById('time_unit').value;
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '950,1015p' scubaduck/static/inde
x.html
window.lastResults = undefined;
queryStart = performance.now();
fetch('/api/query', {method:'POST', headers:{'Content-Type':'application/json'
}, body:JSON.stringify(payload)})
.then(async r => {
const data = await r.json();
if (!r.ok) throw data;
return data;
})
.then(data => {
lastQueryTime = Math.round(performance.now() - queryStart);
showResults(data);
})
.catch(err => {
showError(err);
});
}
function collectParams() {
updateSelectedColumns();
const payload = {
table: document.getElementById('table').value,
time_column: document.getElementById('time_column').value,
time_unit: document.getElementById('time_unit').value,
start: document.getElementById('start').value,
end: document.getElementById('end').value,
order_by: document.getElementById('order_by').value,
order_dir: orderDir,
limit: parseInt(document.getElementById('limit').value, 10),
columns: selectedColumns.filter(c =>
c !== 'Hits' && !derivedColumns.some(dc => dc.name === c)
),
graph_type: graphTypeSel.value,
filters: Array.from(document.querySelectorAll('#filters .filter')).map(f =>
{
const chips = f.chips || [];
const op = f.querySelector('.f-op').value;
let value = null;
if (op !== 'empty' && op !== '!empty') {
value = chips.length === 0 ? null : (chips.length === 1 ? chips[0] : chi
ps);
}
const colSel = f.querySelector('.f-col select') || f.querySelector('.f-col
');
return {column: colSel.value, op, value};
}),
derived_columns: Array.from(document.querySelectorAll('#derived_list .derive
d')).map(d => ({
type: d.querySelector('.d-type').value,
name: d.querySelector('.d-name').value,
expr: d.querySelector('.d-expr').value,
include: d.querySelector('.d-use').checked,
}))
};
if (graphTypeSel.value === 'table' || graphTypeSel.value === 'timeseries') {
payload.group_by = groupBy.chips || [];
payload.aggregate = document.getElementById('aggregate').value;
payload.show_hits = document.getElementById('show_hits').checked;
}
if (graphTypeSel.value === 'timeseries') {
payload.x_axis = document.getElementById('x_axis').value;
payload.granularity = document.getElementById('granularity').value;
payload.fill = document.getElementById('fill').value;
}
return payload;
}
function paramsToSearch(params) {
const sp = new URLSearchParams();
if (params.table) sp.set('table', params.table);
if (params.time_column) sp.set('time_column', params.time_column);
I'm reviewing how defaultTimeColumn is computed and looking for xAxisSelect.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'xAxisSelect' -n scubaduck/stati
c/index.html
529: const xAxisSelect = document.getElementById('x_axis');
533: xAxisSelect.innerHTML = '';
593: xAxisSelect.appendChild(o);
I'll verify parseSearch and applyParams to ensure the x_axis default is correct.
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '1000,1120p' scubaduck/static/ind
ex.html
payload.group_by = groupBy.chips || [];
payload.aggregate = document.getElementById('aggregate').value;
payload.show_hits = document.getElementById('show_hits').checked;
}
if (graphTypeSel.value === 'timeseries') {
payload.x_axis = document.getElementById('x_axis').value;
payload.granularity = document.getElementById('granularity').value;
payload.fill = document.getElementById('fill').value;
}
return payload;
}
function paramsToSearch(params) {
const sp = new URLSearchParams();
if (params.table) sp.set('table', params.table);
if (params.time_column) sp.set('time_column', params.time_column);
if (params.time_unit) sp.set('time_unit', params.time_unit);
if (params.start) sp.set('start', params.start);
if (params.end) sp.set('end', params.end);
if (params.order_by) sp.set('order_by', params.order_by);
if (params.order_dir) sp.set('order_dir', params.order_dir);
if (params.limit !== null && params.limit !== undefined) sp.set('limit', param
s.limit);
if (params.columns && params.columns.length) sp.set('columns', params.columns.
join(','));
if (params.filters && params.filters.length) sp.set('filters', JSON.stringify(
params.filters));
if (params.derived_columns && params.derived_columns.length) sp.set('derived_c
olumns', JSON.stringify(params.derived_columns));
if (params.graph_type) sp.set('graph_type', params.graph_type);
if (params.graph_type === 'table' || params.graph_type === 'timeseries') {
if (params.group_by && params.group_by.length) sp.set('group_by', params.gro
up_by.join(','));
if (params.aggregate) sp.set('aggregate', params.aggregate);
if (params.show_hits) sp.set('show_hits', '1');
}
if (params.graph_type === 'timeseries') {
if (params.x_axis) sp.set('x_axis', params.x_axis);
if (params.granularity) sp.set('granularity', params.granularity);
if (params.fill) sp.set('fill', params.fill);
}
const qs = sp.toString();
return qs ? '?' + qs : '';
}
function applyParams(params) {
if (params.table) document.getElementById('table').value = params.table;
document.getElementById('time_column').value = params.time_column || defaultTi
meColumn;
if (params.time_unit) document.getElementById('time_unit').value = params.time
_unit;
document.getElementById('start').value = params.start || '';
document.getElementById('end').value = params.end || '';
if (params.order_by) {
document.getElementById('order_by').value = params.order_by;
}
orderDir = params.order_dir || 'ASC';
updateOrderDirButton();
if (params.limit !== undefined && params.limit !== null) {
document.getElementById('limit').value = params.limit;
}
graphTypeSel.value = params.graph_type || 'samples';
updateDisplayTypeUI();
if (params.x_axis) document.getElementById('x_axis').value = params.x_axis;
if (params.granularity) document.getElementById('granularity').value = params.
granularity;
if (params.fill) document.getElementById('fill').value = params.fill;
if (params.group_by) {
groupBy.chips.splice(0, groupBy.chips.length, ...params.group_by);
groupBy.renderChips();
}
if (params.aggregate) document.getElementById('aggregate').value = params.aggr
egate;
document.getElementById('show_hits').checked = params.show_hits ?? true;
document.querySelectorAll('#column_groups input').forEach(cb => {
cb.checked = !params.columns || params.columns.includes(cb.value);
});
updateSelectedColumns();
const dlist = document.getElementById('derived_list');
dlist.innerHTML = '';
derivedColumns.splice(0, derivedColumns.length);
if (params.derived_columns && params.derived_columns.length) {
params.derived_columns.forEach(dc => addDerived(dc));
}
refreshDerivedColumns();
const list = document.getElementById('filter_list');
list.innerHTML = '';
if (params.filters && params.filters.length) {
params.filters.forEach(f => {
addFilter();
const el = list.lastElementChild;
const colSel = el.querySelector('.f-col select') || el.querySelector('.f-c
ol');
colSel.value = f.column;
colSel.dispatchEvent(new Event('change'));
el.querySelector('.f-op').value = f.op;
el.querySelector('.f-op').dispatchEvent(new Event('change'));
if (f.value !== null && f.op !== 'empty' && f.op !== '!empty') {
const values = Array.isArray(f.value) ? f.value : [f.value];
values.forEach(v => el.addChip(v));
el.renderChips();
}
});
} else {
addFilter();
}
}
function parseSearch() {
const sp = new URLSearchParams(window.location.search);
const params = {};
if (sp.has('table')) params.table = sp.get('table');
if (sp.has('time_column')) params.time_column = sp.get('time_column');
if (sp.has('time_unit')) params.time_unit = sp.get('time_unit');
if (sp.has('start')) params.start = sp.get('start');
if (sp.has('end')) params.end = sp.get('end');
if (sp.has('order_by')) params.order_by = sp.get('order_by');
if (sp.has('order_dir')) params.order_dir = sp.get('order_dir');
if (sp.has('limit')) params.limit = parseInt(sp.get('limit'), 10);
if (sp.has('columns')) params.columns = sp.get('columns').split(',').filter(c
=> c);
if (sp.has('filters')) {
try { params.filters = JSON.parse(sp.get('filters')); } catch(e) { params.fi
lters = []; }
}
if (sp.has('graph_type')) params.graph_type = sp.get('graph_type');
if (sp.has('group_by')) params.group_by = sp.get('group_by').split(',').filter
(c => c);
if (sp.has('aggregate')) params.aggregate = sp.get('aggregate');
if (sp.has('show_hits')) params.show_hits = sp.get('show_hits') === '1';
if (sp.has('x_axis')) params.x_axis = sp.get('x_axis');
if (sp.has('granularity')) params.granularity = sp.get('granularity');
if (sp.has('fill')) params.fill = sp.get('fill');
if (sp.has('derived_columns')) {
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '1120,1208p' scubaduck/static/ind
ex.html
if (sp.has('derived_columns')) {
try { params.derived_columns = JSON.parse(sp.get('derived_columns')); } catc
h(e) { params.derived_columns = []; }
}
return params;
}
function initFromUrl() {
const params = parseSearch();
history.replaceState(params, '', paramsToSearch(params));
applyParams(params);
dive(false);
}
window.addEventListener('popstate', e => {
const params = e.state || parseSearch();
applyParams(params);
dive(false);
});
let originalRows = [];
let sortState = {index: null, dir: null};
function renderTable(rows) {
const table = document.getElementById('results');
table.innerHTML = '';
if (rows.length === 0) return;
let hitsIndex = selectedColumns.indexOf('Hits');
let totalHits = 0;
if (hitsIndex !== -1) {
totalHits = rows.reduce((s, r) => s + Number(r[hitsIndex]), 0);
}
const header = document.createElement('tr');
selectedColumns.forEach((col, i) => {
const th = document.createElement('th');
let label = col;
if (
displayType === 'table' &&
col !== 'Hits' &&
!(groupBy.chips || []).includes(col)
) {
const agg = document.getElementById('aggregate').value.toLowerCase();
label += ` (${agg})`;
}
th.textContent = label;
th.dataset.index = i;
th.addEventListener('click', handleSort);
if (sortState.index === i) {
th.classList.add('sorted');
th.textContent =
label + (sortState.dir === 'desc' ? ' \u25BC' : ' \u25B2');
}
if (!isStringColumn(col)) th.style.textAlign = 'right';
header.appendChild(th);
});
table.appendChild(header);
rows.forEach(row => {
const tr = document.createElement('tr');
tr.addEventListener('click', () => {
const wasSelected = tr.classList.contains('selected');
document
.querySelectorAll('#results tr.selected')
.forEach(el => el.classList.remove('selected'));
if (!wasSelected) {
tr.classList.add('selected');
}
});
row.forEach((v, i) => {
const col = selectedColumns[i];
const td = document.createElement('td');
if (isTimeColumn(col)) {
let d;
const t = (columnTypes[col] || '').toUpperCase();
if (t.includes('TIMESTAMP') || t.includes('DATE') || t.includes('TIME'))
{
d = new Date(v);
} else {
const unit = document.getElementById('time_unit').value;
const factors = {s: 1000, ms: 1, us: 0.001, ns: 0.000001};
d = new Date(Number(v) * (factors[unit] || 1000));
}
td.textContent = d.toLocaleString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: true,
timeZoneName: 'short'
I need to add a "(default)" option to the x-axis dropdown that uses the time column. When selected, no x_axis parameter will be set. However, I need to handle cases where the time column isn't a timestamp. I'll ensure that x_axis defaults to use the time column, regardless of its type, such as integers. I'll also modify the UI and server side to reflect this behavior.
To handle numeric columns as time columns, I'll add a "default" option to x-axis, which will let users select any column from the time_column dropdown. When chosen, I'll treat x_axis as an empty or "null" value to rely on the time_column in the query. I'll adjust collectParams and applyParams to handle this behavior.
I’ll open tests/test_server.py to search for timeseries_xaxis_name and x_axis to update tests.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'x_axis' -n tests/test_server.py
582: "x_axis": "timestamp",
603: "x_axis": "timestamp",
631: "x_axis": "timestamp",
653: "x_axis": "timestamp",
687: "x_axis": "timestamp",
I'm reviewing tests around line 582 to verify the results.
assert "error" not in data
rows = data["rows"]
assert rows[0][0] == "alice"
from dateutil import parser
ts = parser.parse(rows[0][1]).replace(tzinfo=None)
assert ts == parser.parse("2024-01-01 12:00:00")
def test_timeseries_basic() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 100,
"group_by": ["user"],
"aggregate": "Count",
"columns": ["value"],
"x_axis": "timestamp",
"granularity": "1 day",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 4
def test_timeseries_orders_by_xaxis() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 100,
"columns": ["value"],
"x_axis": "timestamp",
"granularity": "1 day",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
rows = data["rows"]
from dateutil import parser
timestamps = [parser.parse(r[0]).replace(tzinfo=None) for r in rows]
assert timestamps == sorted(timestamps)
def test_timeseries_limit_applies_to_series() -> None:
app = server.app
client = app.test_client()
I need to scroll past 653 to view the full x-axis details.
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 1,
"order_by": "user",
"group_by": ["user"],
"aggregate": "Count",
"columns": ["value"],
"x_axis": "timestamp",
"granularity": "1 day",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
assert all(r[1] == "alice" for r in data["rows"])
def test_timeseries_auto_and_fine_buckets() -> None:
app = server.app
client = app.test_client()
def run(gran: str) -> None:
payload = {
"start": "2024-01-01 00:00:00",
"end": "2024-01-02 03:00:00",
"graph_type": "timeseries",
"columns": ["value"],
"x_axis": "timestamp",
"granularity": gran,
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/js
on"
)
data = rv.get_json()
assert rv.status_code == 200
from dateutil import parser
start = parser.parse(cast(str, payload["start"])).replace(tzinfo=None)
buckets = [
parser.parse(cast(str, r[0])).replace(tzinfo=None) for r in data["ro
ws"]
]
assert buckets[0] == start
if len(buckets) > 1:
step = (buckets[1] - buckets[0]).total_seconds()
assert step % data["bucket_size"] == 0
assert any(r[1] != 0 for r in data["rows"])
run("Auto")
run("Fine")
def test_timeseries_string_column_error() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "timeseries",
"limit": 7,
"columns": ["timestamp", "event", "value", "user"],
"x_axis": "timestamp",
"granularity": "1 hour",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 400
assert "Aggregate" in data["error"]
def test_derived_column_basic() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"limit": 10,
"columns": ["timestamp"],
Now, I need tests for x_axis to ensure it uses time_column, even without a timestamp.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'time_column' -n tests/test_serv
er.py
319:def test_integer_time_column(tmp_path: Path) -> None:
330: "time_column": "created",
351: "time_column": "created",
373: "time_column": "created",
def test_integer_time_column(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text("created,event\n1704067200,login\n1704070800,logout\n")
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
def test_integer_time_unit_ms(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text("created,event\n1704067200000,login\n1704070800000,logou
t\n")
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
"time_unit": "ms",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
def test_integer_time_unit_us_default_start_end(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text(
"created,event\n1704067200000000,login\n1704070800000000,logout\n"
)
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
"time_unit": "us",
}
rv = client.post(
data = rv.get_json()
assert rv.status_code == 200
assert data["start"] == "2024-01-01 00:00:00"
assert data["end"] == "2024-01-01 01:00:00"
assert len(data["rows"]) == 2
def test_envvar_db(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
csv_file = tmp_path / "custom.csv"
csv_file.write_text("timestamp,event,value,user\n2024-01-01 00:00:00,login,5
,bob\n")
monkeypatch.setenv("SCUBADUCK_DB", str(csv_file))
app = server.create_app()
client = app.test_client()
payload = _make_payload()
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
rows = rv.get_json()["rows"]
assert len(rows) == 1
def test_envvar_db_missing(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> N
one:
missing = tmp_path / "missing.sqlite"
monkeypatch.setenv("SCUBADUCK_DB", str(missing))
with pytest.raises(FileNotFoundError):
server.create_app()
def test_group_by_table() -> None:
app = server.app
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-03 00:00:00",
"graph_type": "table",
"order_by": "user",
"limit": 10,
"columns": ["value"],
"group_by": ["user"],
"aggregate": "Sum",
"show_hits": True,
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
rows = rv.get_json()["rows"]
assert rows[0][0] == "alice"
assert rows[0][1] == 2
assert rows[0][2] == 40
def test_relative_time_query(monkeypatch: pytest.MonkeyPatch) -> None:
app = server.app
client = app.test_client()
from datetime import datetime
fixed_now = datetime(2024, 1, 2, 4, 0, 0)
class FixedDateTime(datetime):
@classmethod
I'll add a default entry to the X-axis dropdown, using time_column/time_unit if applicable.
If x_axis is not set, I'll ensure to omit it rather than sending an empty string.
I'll ensure isTimeColumn
treats the time column correctly even when x_axis
is empty.
I’ll add a test for the default entry in the X-axis dropdown on the frontend.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'x_axis' -n tests/test_web.py
211: assert page.is_visible("#x_axis_field")
I'll add a front-end test for the dropdown default entry in tests/test_web.py.
I'll add a test for the dropdown default entry visibility in tests/test_web.py.
I'll add a server test for timeseries with an integer time column and default x_axis.
I need to specify a valid aggregator for the event column, as 'avg' can't be used.
I'll implement server test for timeseries and front-end test for dropdown default values.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'initDropdown' -n scubaduck/stat
ic/js/chip_input.js
I'll check index.html to see if the initDropdown function is defined inline.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'function initDropdown' -n scuba
duck/static/index.html
371:function initDropdown(select) {
.html
function initDropdown(select) {
const wrapper = document.createElement('div');
wrapper.className = 'dropdown';
if (select.classList.contains('f-col')) {
wrapper.classList.add('f-col');
}
select.parentNode.insertBefore(wrapper, select);
wrapper.appendChild(select);
select.style.display = 'none';
const disp = document.createElement('div');
disp.className = 'dropdown-display';
function updateDisplay() {
const opt = select.options[select.selectedIndex];
disp.textContent = opt ? opt.textContent : '';
}
updateDisplay();
wrapper.appendChild(disp);
const menu = document.createElement('div');
menu.className = 'dropdown-menu';
const search = document.createElement('input');
search.placeholder = 'Search';
menu.appendChild(search);
const list = document.createElement('div');
menu.appendChild(list);
wrapper.appendChild(menu);
function close() {
menu.style.display = 'none';
}
function open() {
renderOptions();
menu.style.display = 'block';
search.focus();
}
disp.addEventListener('click', () => {
if (menu.style.display === 'block') {
close();
} else {
open();
}
});
document.addEventListener('click', e => {
if (!wrapper.contains(e.target)) {
close();
}
});
function renderOptions() {
const q = search.value.toLowerCase();
list.innerHTML = '';
Array.from(select.options).forEach(o => {
if (!o.textContent.toLowerCase().includes(q)) return;
const div = document.createElement('div');
div.className = 'option';
if (q) {
const text = o.textContent;
const idx = text.toLowerCase().indexOf(q);
if (idx !== -1) {
div.innerHTML =
text.slice(0, idx) +
'<u>' +
text.slice(idx, idx + q.length) +
'</u>' +
text.slice(idx + q.length);
} else {
div.textContent = text;
}
} else {
div.textContent = o.textContent;
}
if (o.value === select.value) div.classList.add('selected');
div.addEventListener('mousedown', evt => {
evt.preventDefault();
select.value = o.value;
select.dispatchEvent(new Event('change'));
updateDisplay();
close();
});
list.appendChild(div);
});
}
search.addEventListener('input', renderOptions);
select.addEventListener('change', updateDisplay);
}
// Sidebar resizing
const sidebar = document.getElementById('sidebar');
const sidebarResizer = document.getElementById('sidebar-resizer');
let sidebarWidth = parseInt(localStorage.getItem('sidebarWidth') || 450, 10);
sidebar.style.width = sidebarWidth + 'px';
let sidebarResize = false;
I’m thinking I need to test the #x_axis dropdown with help from select_value. Also, I’ll adjust several functions to handle default and empty values for x_axis, ensuring it's handled properly across the front-end codes. Let me look for 'initFromUrl()' to confirm behavior after loading the columns.
root@4dc88f61e6c2:/workspace/scubaduck# grep -n 'initFromUrl()' -n scubaduck/sta
tic/index.html
682: initFromUrl();
1126:function initFromUrl() {
root@4dc88f61e6c2:/workspace/scubaduck# sed -n '672,692p' scubaduck/static/index
.html
const o = document.createElement('option');
o.value = t;
o.textContent = t;
document.getElementById('table').appendChild(o);
});
const table = parseSearch().table || tables[0];
document.getElementById('table').value = table;
loadColumns(table).then(() => {
updateDisplayTypeUI();
addFilter();
initFromUrl();
columnsInitialized = true;
});
document.getElementById('table').addEventListener('change', () => {
loadColumns(document.getElementById('table').value).then(() => {
if (columnsInitialized) {
applyParams(parseSearch());
}
});
});
});
I'll set xAxisSelect.value to '' as default and ensure consistent behavior across loads. Let's check .venv next.
root@4dc88f61e6c2:/workspace/scubaduck# ls -a
. .git .gitignore AGENTS.md codex_setup.sh scubaduck tests
.. .github .venv README.md pyproject.toml stubs uv.lock
root@4dc88f61e6c2:/workspace/scubaduck# source .venv/bin/activate
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll run a quick ruff check to confirm everything is good on the base.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# ruff check >/tmp/ruff.log &&
tail -n 20 /tmp/ruff.log
All checks passed!
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# pyright >/tmp/pyright.log &&
tail -n 20 /tmp/pyright.log
0 errors, 0 warnings, 0 informations
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll run some baseline tests to confirm everything is working as expected.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# pytest -q >/tmp/pytest.log &
& tail -n 20 /tmp/pytest.log
bringing up nodes...
bringing up nodes...
........................................................................ [ 78%]
.................... [100%]
92 passed in 12.24s
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll add a default option to the x_axis dropdown in index.html and update related functions.
static/index.html
orderDir = orderDir === 'ASC' ? 'DESC' : 'ASC';
updateOrderDirButton();
});
updateOrderDirButton();
graphTypeSel.addEventListener('change', updateDisplayTypeUI);
function loadColumns(table) {
return fetch('/api/columns?table=' + encodeURIComponent(table)).then(r => r.js
on()).then(cols => {
const orderSelect = document.getElementById('order_by');
const xAxisSelect = document.getElementById('x_axis');
const groupsEl = document.getElementById('column_groups');
const timeColumnSelect = document.getElementById('time_column');
orderSelect.innerHTML = '';
xAxisSelect.innerHTML = '';
timeColumnSelect.innerHTML = '';
groupsEl.innerHTML = '';
allColumns.length = 0;
stringColumns.length = 0;
integerColumns.length = 0;
timeColumns.length = 0;
timeColumnOptions.length = 0;
baseColumns.length = 0;
baseStringColumns.length = 0;
baseIntegerColumns.length = 0;
baseTimeColumns.length = 0;
baseTimeColumnOptions.length = 0;
for (const k in columnTypes) delete columnTypes[k];
const groups = {
time: {name: 'Time', cols: [], ul: null},
integer: {name: 'Integers', cols: [], ul: null},
string: {name: 'Strings', cols: [], ul: null},
};
const heur = ['timestamp','created','created_at','event_time','time','date',
'occurred','happened','logged'];
let guess = null;
cols.forEach(c => {
const t = c.type.toUpperCase();
columnTypes[c.name] = c.type;
allColumns.push(c.name);
baseColumns.push(c.name);
let g = 'string';
const isNumeric = t.includes('INT') || t.includes('DECIMAL') || t.includes
('NUMERIC') || t.includes('REAL') || t.includes('DOUBLE') || t.includes('FLOAT')
|| t.includes('HUGEINT');
const isTimeType = t.includes('TIMESTAMP') || t.includes('DATE') || t.incl
udes('TIME');
if (isNumeric || isTimeType) {
timeColumnOptions.push(c.name);
baseTimeColumnOptions.push(c.name);
if (!guess && heur.some(h => c.name.toLowerCase().includes(h))) guess =
c.name;
}
if (isTimeType) {
g = 'time';
timeColumns.push(c.name);
baseTimeColumns.push(c.name);
} else if (isNumeric) {
g = 'integer';
}
if (g === 'string') {
stringColumns.push(c.name);
baseStringColumns.push(c.name);
} else if (g === 'integer') {
integerColumns.push(c.name);
baseIntegerColumns.push(c.name);
}
groups[g].cols.push(c.name);
if (g !== 'string') {
const o = document.createElement('option');
o.value = c.name;
o.textContent = c.name;
orderSelect.appendChild(o);
}
});
timeColumns.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
xAxisSelect.appendChild(o);
});
timeColumnOptions.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
timeColumnSelect.appendChild(o);
});
defaultTimeColumn = guess || timeColumnOptions[0] || '';
Object.keys(groups).forEach(key => {
const g = groups[key];
const div = document.createElement('div');
div.className = 'col-group';
const header = document.createElement('div');
header.className = 'col-group-header';
header.appendChild(document.createTextNode(g.name + ': '));
const links = document.createElement('span');
links.className = 'links';
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I’ll add a default option before iterating through timeColumns.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '556,608p' scubaduck/
static/index.html
columnTypes[c.name] = c.type;
allColumns.push(c.name);
baseColumns.push(c.name);
let g = 'string';
const isNumeric = t.includes('INT') || t.includes('DECIMAL') || t.includes
('NUMERIC') || t.includes('REAL') || t.includes('DOUBLE') || t.includes('FLOAT')
|| t.includes('HUGEINT');
const isTimeType = t.includes('TIMESTAMP') || t.includes('DATE') || t.incl
udes('TIME');
if (isNumeric || isTimeType) {
timeColumnOptions.push(c.name);
baseTimeColumnOptions.push(c.name);
if (!guess && heur.some(h => c.name.toLowerCase().includes(h))) guess =
c.name;
}
if (isTimeType) {
g = 'time';
timeColumns.push(c.name);
baseTimeColumns.push(c.name);
} else if (isNumeric) {
g = 'integer';
}
if (g === 'string') {
stringColumns.push(c.name);
baseStringColumns.push(c.name);
} else if (g === 'integer') {
integerColumns.push(c.name);
baseIntegerColumns.push(c.name);
}
groups[g].cols.push(c.name);
if (g !== 'string') {
const o = document.createElement('option');
o.value = c.name;
o.textContent = c.name;
orderSelect.appendChild(o);
}
});
timeColumns.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
xAxisSelect.appendChild(o);
});
timeColumnOptions.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
timeColumnSelect.appendChild(o);
});
defaultTimeColumn = guess || timeColumnOptions[0] || '';
Object.keys(groups).forEach(key => {
const g = groups[key];
const div = document.createElement('div');
div.className = 'col-group';
const header = document.createElement('div');
header.className = 'col-group-header';
header.appendChild(document.createTextNode(g.name + ': '));
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll patch the code to add a default entry after setting xAxisSelect.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# apply_patch<<'PATCH'
> *** Begin Patch
> *** Update File: scubaduck/static/index.html
> @@
> - const orderSelect = document.getElementById('order_by');
> - const xAxisSelect = document.getElementById('x_axis');
> + const orderSelect = document.getElementById('order_by');
> + const xAxisSelect = document.getElementById('x_axis');
> *** End Patch
> PATCH
Success. Updated the following files:
M scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I noticed the default hasn’t been added yet. I'll apply the patch soon.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "xAxisSelect" -n scu
baduck/static/index.html | head
529: const xAxisSelect = document.getElementById('x_axis');
533: xAxisSelect.innerHTML = '';
593: xAxisSelect.appendChild(o);
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "xAxisSelect" -n scu
baduck/static/index.html
529: const xAxisSelect = document.getElementById('x_axis');
533: xAxisSelect.innerHTML = '';
593: xAxisSelect.appendChild(o);
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll show lines 528 through 596 now.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '524,601p' scubaduck/
static/index.html
graphTypeSel.addEventListener('change', updateDisplayTypeUI);
function loadColumns(table) {
return fetch('/api/columns?table=' + encodeURIComponent(table)).then(r => r.js
on()).then(cols => {
const orderSelect = document.getElementById('order_by');
const xAxisSelect = document.getElementById('x_axis');
const groupsEl = document.getElementById('column_groups');
const timeColumnSelect = document.getElementById('time_column');
orderSelect.innerHTML = '';
xAxisSelect.innerHTML = '';
timeColumnSelect.innerHTML = '';
groupsEl.innerHTML = '';
allColumns.length = 0;
stringColumns.length = 0;
integerColumns.length = 0;
timeColumns.length = 0;
timeColumnOptions.length = 0;
baseColumns.length = 0;
baseStringColumns.length = 0;
baseIntegerColumns.length = 0;
baseTimeColumns.length = 0;
baseTimeColumnOptions.length = 0;
for (const k in columnTypes) delete columnTypes[k];
const groups = {
time: {name: 'Time', cols: [], ul: null},
integer: {name: 'Integers', cols: [], ul: null},
string: {name: 'Strings', cols: [], ul: null},
};
const heur = ['timestamp','created','created_at','event_time','time','date',
'occurred','happened','logged'];
let guess = null;
cols.forEach(c => {
const t = c.type.toUpperCase();
columnTypes[c.name] = c.type;
allColumns.push(c.name);
baseColumns.push(c.name);
let g = 'string';
const isNumeric = t.includes('INT') || t.includes('DECIMAL') || t.includes
('NUMERIC') || t.includes('REAL') || t.includes('DOUBLE') || t.includes('FLOAT')
|| t.includes('HUGEINT');
const isTimeType = t.includes('TIMESTAMP') || t.includes('DATE') || t.incl
udes('TIME');
if (isNumeric || isTimeType) {
timeColumnOptions.push(c.name);
baseTimeColumnOptions.push(c.name);
if (!guess && heur.some(h => c.name.toLowerCase().includes(h))) guess =
c.name;
}
if (isTimeType) {
g = 'time';
timeColumns.push(c.name);
baseTimeColumns.push(c.name);
} else if (isNumeric) {
g = 'integer';
}
if (g === 'string') {
stringColumns.push(c.name);
baseStringColumns.push(c.name);
} else if (g === 'integer') {
integerColumns.push(c.name);
baseIntegerColumns.push(c.name);
}
groups[g].cols.push(c.name);
if (g !== 'string') {
const o = document.createElement('option');
o.value = c.name;
o.textContent = c.name;
orderSelect.appendChild(o);
}
});
timeColumns.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
xAxisSelect.appendChild(o);
});
timeColumnOptions.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
timeColumnSelect.appendChild(o);
});
defaultTimeColumn = guess || timeColumnOptions[0] || '';
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll reset xAxisSelect.innerHTML to add a default option, then patch it.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# apply_patch<<'PATCH'
> *** Begin Patch
> *** Update File: scubaduck/static/index.html
> @@
> - xAxisSelect.innerHTML = '';
> + xAxisSelect.innerHTML = '';
> + const defOpt = document.createElement('option');
> + defOpt.value = '';
> + defOpt.textContent = '(default)';
> + xAxisSelect.appendChild(defOpt);
> *** End Patch
> PATCH
Success. Updated the following files:
M scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll set xAxisSelect.value = ''
after the timeColumns loop or timeColumnOptions.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "xAxisSelect.value"
-n scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '598,610p' scubaduck/
static/index.html
});
timeColumnOptions.forEach(name => {
const o = document.createElement('option');
o.value = name;
o.textContent = name;
timeColumnSelect.appendChild(o);
});
defaultTimeColumn = guess || timeColumnOptions[0] || '';
Object.keys(groups).forEach(key => {
const g = groups[key];
const div = document.createElement('div');
div.className = 'col-group';
const header = document.createElement('div');
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I’ll add a reset for xAxisSelect.value after loops but before returning.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# apply_patch<<'PATCH'
> *** Begin Patch
> *** Update File: scubaduck/static/index.html
> @@
> - timeColumnOptions.forEach(name => {
> + timeColumnOptions.forEach(name => {
> const o = document.createElement('option');
> o.value = name;
> o.textContent = name;
> timeColumnSelect.appendChild(o);
> });
> + xAxisSelect.value = '';
> defaultTimeColumn = guess || timeColumnOptions[0] || '';
> *** End Patch
> PATCH
Success. Updated the following files:
M scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll adjust collectParams to skip the x_axis when it's set to default.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "collectParams" -n s
cubaduck/static/index.html
943: const params = collectParams();
972:function collectParams() {
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '972,1008p' scubaduck
/static/index.html
function collectParams() {
updateSelectedColumns();
const payload = {
table: document.getElementById('table').value,
time_column: document.getElementById('time_column').value,
time_unit: document.getElementById('time_unit').value,
start: document.getElementById('start').value,
end: document.getElementById('end').value,
order_by: document.getElementById('order_by').value,
order_dir: orderDir,
limit: parseInt(document.getElementById('limit').value, 10),
columns: selectedColumns.filter(c =>
c !== 'Hits' && !derivedColumns.some(dc => dc.name === c)
),
graph_type: graphTypeSel.value,
filters: Array.from(document.querySelectorAll('#filters .filter')).map(f =>
{
const chips = f.chips || [];
const op = f.querySelector('.f-op').value;
let value = null;
if (op !== 'empty' && op !== '!empty') {
value = chips.length === 0 ? null : (chips.length === 1 ? chips[0] : chi
ps);
}
const colSel = f.querySelector('.f-col select') || f.querySelector('.f-col
');
return {column: colSel.value, op, value};
}),
derived_columns: Array.from(document.querySelectorAll('#derived_list .derive
d')).map(d => ({
type: d.querySelector('.d-type').value,
name: d.querySelector('.d-name').value,
expr: d.querySelector('.d-expr').value,
include: d.querySelector('.d-use').checked,
}))
};
if (graphTypeSel.value === 'table' || graphTypeSel.value === 'timeseries') {
payload.group_by = groupBy.chips || [];
payload.aggregate = document.getElementById('aggregate').value;
payload.show_hits = document.getElementById('show_hits').checked;
}
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '1008,1040p' scubaduc
k/static/index.html
}
if (graphTypeSel.value === 'timeseries') {
payload.x_axis = document.getElementById('x_axis').value;
payload.granularity = document.getElementById('granularity').value;
payload.fill = document.getElementById('fill').value;
}
return payload;
}
function paramsToSearch(params) {
const sp = new URLSearchParams();
if (params.table) sp.set('table', params.table);
if (params.time_column) sp.set('time_column', params.time_column);
if (params.time_unit) sp.set('time_unit', params.time_unit);
if (params.start) sp.set('start', params.start);
if (params.end) sp.set('end', params.end);
if (params.order_by) sp.set('order_by', params.order_by);
if (params.order_dir) sp.set('order_dir', params.order_dir);
if (params.limit !== null && params.limit !== undefined) sp.set('limit', param
s.limit);
if (params.columns && params.columns.length) sp.set('columns', params.columns.
join(','));
if (params.filters && params.filters.length) sp.set('filters', JSON.stringify(
params.filters));
if (params.derived_columns && params.derived_columns.length) sp.set('derived_c
olumns', JSON.stringify(params.derived_columns));
if (params.graph_type) sp.set('graph_type', params.graph_type);
if (params.graph_type === 'table' || params.graph_type === 'timeseries') {
if (params.group_by && params.group_by.length) sp.set('group_by', params.gro
up_by.join(','));
if (params.aggregate) sp.set('aggregate', params.aggregate);
if (params.show_hits) sp.set('show_hits', '1');
}
if (params.graph_type === 'timeseries') {
if (params.x_axis) sp.set('x_axis', params.x_axis);
if (params.granularity) sp.set('granularity', params.granularity);
if (params.fill) sp.set('fill', params.fill);
}
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll update the code to exclude x_axis if it's an empty string.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# apply_patch<<'PATCH'
> *** Begin Patch
> *** Update File: scubaduck/static/index.html
> @@
> - if (graphTypeSel.value === 'timeseries') {
> - payload.x_axis = document.getElementById('x_axis').value;
> + if (graphTypeSel.value === 'timeseries') {
> + const xval = document.getElementById('x_axis').value;
> + if (xval) payload.x_axis = xval;
> payload.granularity = document.getElementById('granularity').value;
> payload.fill = document.getElementById('fill').value;
> }
> *** End Patch
> PATCH
Success. Updated the following files:
M scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# apply_patch<<'PATCH'
> *** Begin Patch
> *** Update File: scubaduck/static/index.html
> @@
> - if (params.graph_type === 'timeseries') {
> - if (params.x_axis) sp.set('x_axis', params.x_axis);
> + if (params.graph_type === 'timeseries') {
> + if (params.x_axis) sp.set('x_axis', params.x_axis);
> if (params.granularity) sp.set('granularity', params.granularity);
> if (params.fill) sp.set('fill', params.fill);
> }
> *** End Patch
> PATCH
Success. Updated the following files:
M scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
It seems no real change is needed, but I might adjust applyParams for undefined x_axis.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "applyParams" -n scu
baduck/static/index.html
693: applyParams(parseSearch());
1046:function applyParams(params) {
1135: applyParams(params);
1141: applyParams(params);
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '1046,1080p' scubaduc
k/static/index.html
function applyParams(params) {
if (params.table) document.getElementById('table').value = params.table;
document.getElementById('time_column').value = params.time_column || defaultTi
meColumn;
if (params.time_unit) document.getElementById('time_unit').value = params.time
_unit;
document.getElementById('start').value = params.start || '';
document.getElementById('end').value = params.end || '';
if (params.order_by) {
document.getElementById('order_by').value = params.order_by;
}
orderDir = params.order_dir || 'ASC';
updateOrderDirButton();
if (params.limit !== undefined && params.limit !== null) {
document.getElementById('limit').value = params.limit;
}
graphTypeSel.value = params.graph_type || 'samples';
updateDisplayTypeUI();
if (params.x_axis) document.getElementById('x_axis').value = params.x_axis;
if (params.granularity) document.getElementById('granularity').value = params.
granularity;
if (params.fill) document.getElementById('fill').value = params.fill;
if (params.group_by) {
groupBy.chips.splice(0, groupBy.chips.length, ...params.group_by);
groupBy.renderChips();
}
if (params.aggregate) document.getElementById('aggregate').value = params.aggr
egate;
document.getElementById('show_hits').checked = params.show_hits ?? true;
document.querySelectorAll('#column_groups input').forEach(cb => {
cb.checked = !params.columns || params.columns.includes(cb.value);
});
updateSelectedColumns();
const dlist = document.getElementById('derived_list');
dlist.innerHTML = '';
derivedColumns.splice(0, derivedColumns.length);
if (params.derived_columns && params.derived_columns.length) {
params.derived_columns.forEach(dc => addDerived(dc));
}
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# apply_patch<<'PATCH'
> *** Begin Patch
> *** Update File: scubaduck/static/index.html
> @@
> - if (params.x_axis) document.getElementById('x_axis').value = params.x_axis;
> + if (params.x_axis) {
> + document.getElementById('x_axis').value = params.x_axis;
> + } else {
> + document.getElementById('x_axis').value = '';
> + }
> *** End Patch
> PATCH
Success. Updated the following files:
M scubaduck/static/index.html
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll add a front-end test near test_time_column_dropdown or time_unit dropdown in test_web.py.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "time_column_dropdow
n" -n tests/test_web.py
99:def test_time_column_dropdown(page: Any, server_url: str) -> None:
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# sed -n '92,116p' tests/test_
web.py
end="2024-01-03 00:00:00",
order_by="timestamp",
limit=2,
)
assert len(data["rows"]) == 2
def test_time_column_dropdown(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#time_column option", state="attached")
options = page.locator("#time_column option").all_inner_texts()
assert "timestamp" in options
assert "value" in options
assert page.input_value("#time_column") == "timestamp"
def test_time_unit_dropdown(page: Any, server_url: str) -> None:
page.goto(server_url)
page.wait_for_selector("#time_unit", state="attached")
opts = page.locator("#time_unit option").all_inner_texts()
assert "ms" in opts
assert page.input_value("#time_unit") == "s"
def test_simple_filter(page: Any, server_url: str) -> None:
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll write a new test case to validate x-axis default behavior on page load.
> @@
> def test_time_unit_dropdown(page: Any, server_url: str) -> None:
> page.goto(server_url)
> page.wait_for_selector("#time_unit", state="attached")
> opts = page.locator("#time_unit option").all_inner_texts()
> assert "ms" in opts
> assert page.input_value("#time_unit") == "s"
> +
> +
> +def test_x_axis_default_entry(page: Any, server_url: str) -> None:
> + page.goto(server_url)
> + page.wait_for_selector("#graph_type", state="attached")
> + select_value(page, "#graph_type", "timeseries")
> + page.wait_for_selector("#x_axis option", state="attached")
> + options = page.locator("#x_axis option").all_inner_texts()
> + assert "(default)" in options
> + assert page.input_value("#x_axis") == ""
> *** End Patch
> PATCH
Success. Updated the following files:
M tests/test_web.py
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I’m going to open the tests near the integer time column and replicate them.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# grep -n "integer_time_unit_m
s" -n tests/test_server.py
340:def test_integer_time_unit_ms(tmp_path: Path) -> None:
assert data["rows"][0][1] == big_value
def test_integer_time_column(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text("created,event\n1704067200,login\n1704070800,logout\n")
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
def test_integer_time_unit_ms(tmp_path: Path) -> None:
csv_file = tmp_path / "events.csv"
csv_file.write_text("created,event\n1704067200000,login\n1704070800000,logou
t\n")
app = server.create_app(csv_file)
client = app.test_client()
payload = {
"table": "events",
"start": "2024-01-01 00:00:00",
"end": "2024-01-01 01:00:00",
"order_by": "created",
"columns": ["created", "event"],
"time_column": "created",
"time_unit": "ms",
}
rv = client.post(
"/api/query", data=json.dumps(payload), content_type="application/json"
)
data = rv.get_json()
assert rv.status_code == 200
assert len(data["rows"]) == 2
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll add the new test after test_integer_time_unit_ms to check time units are handled.
> *** Update File: tests/test_server.py
> @@
> def test_integer_time_unit_ms(tmp_path: Path) -> None:
> @@
> assert rv.status_code == 200
> assert len(data["rows"]) == 2
> +
> +
> +def test_timeseries_default_xaxis_uses_time_column(tmp_path: Path) -> None:
> + csv_file = tmp_path / "events.csv"
> + csv_file.write_text(
> + "created,event\n1704067200000,login\n1704070800000,logout\n"
> + )
> + app = server.create_app(csv_file)
> + client = app.test_client()
> + payload = {
> + "table": "events",
> + "start": "2024-01-01 00:00:00",
> + "end": "2024-01-01 01:00:00",
> + "graph_type": "timeseries",
> + "granularity": "1 hour",
> + "columns": ["event"],
> + "aggregate": "Count",
> + "time_column": "created",
> + "time_unit": "ms",
> + }
> + rv = client.post(
> + "/api/query", data=json.dumps(payload), content_type="application/jso
n"
> + )
> + data = rv.get_json()
> + assert rv.status_code == 200
> + assert len(data["rows"]) == 2
> *** End Patch
> PATCH
Success. Updated the following files:
M tests/test_server.py
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll go ahead and use ruff to auto-format the code.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# ruff format scubaduck/static
/index.html tests/test_web.py tests/test_server.py >/tmp/format.log && tail -n 2
0 /tmp/format.log
error: Failed to parse scubaduck/static/index.html:1:1: Expected a statement
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll run ruff format only on Python files, like tests/test_web.py and test_server.py.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# ruff format tests/test_web.p
y tests/test_server.py >/tmp/format.log && tail -n 20 /tmp/format.log
2 files left unchanged
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# ruff check >/tmp/ruff.log &&
tail -n 20 /tmp/ruff.log
All checks passed!
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'm checking the code with pyright to find any type errors.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# pyright >/tmp/pyright.log &&
tail -n 20 /tmp/pyright.log
0 errors, 0 warnings, 0 informations
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'm running pytest to check if all tests pass successfully. Let's do this!
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# pytest -q >/tmp/pytest.log &
& tail -n 20 /tmp/pytest.log
bringing up nodes...
bringing up nodes...
........................................................................ [ 76%]
...................... [100%]
94 passed in 11.84s
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
All tests have passed, so I'm ready to commit the changes.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# git status --short
M scubaduck/static/index.html
M tests/test_server.py
M tests/test_web.py
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# git add scubaduck/static/ind
ex.html tests/test_server.py tests/test_web.py
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# git commit -m "feat(web): ad
d default x-axis option" && git status --short
[work bab7d0d] feat(web): add default x-axis option
3 files changed, 46 insertions(+), 2 deletions(-)
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I finished the commit message, but I forgot to show the status.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# git status --short
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I’ll summarize the user prompt and gather citation lines for the final summary.
x.html | sed -n '528,608p'
528 const orderSelect = document.getElementById('order_by');
529 const xAxisSelect = document.getElementById('x_axis');
530 const groupsEl = document.getElementById('column_groups');
531 const timeColumnSelect = document.getElementById('time_column');
532 orderSelect.innerHTML = '';
533 xAxisSelect.innerHTML = '';
534 const defOpt = document.createElement('option');
535 defOpt.value = '';
536 defOpt.textContent = '(default)';
537 xAxisSelect.appendChild(defOpt);
538 timeColumnSelect.innerHTML = '';
539 groupsEl.innerHTML = '';
540 allColumns.length = 0;
541 stringColumns.length = 0;
542 integerColumns.length = 0;
543 timeColumns.length = 0;
544 timeColumnOptions.length = 0;
545 baseColumns.length = 0;
546 baseStringColumns.length = 0;
547 baseIntegerColumns.length = 0;
548 baseTimeColumns.length = 0;
549 baseTimeColumnOptions.length = 0;
550 for (const k in columnTypes) delete columnTypes[k];
551 const groups = {
552 time: {name: 'Time', cols: [], ul: null},
553 integer: {name: 'Integers', cols: [], ul: null},
554 string: {name: 'Strings', cols: [], ul: null},
555 };
556 const heur = ['timestamp','created','created_at','event_time','time'
,'date','occurred','happened','logged'];
557 let guess = null;
558 cols.forEach(c => {
559 const t = c.type.toUpperCase();
560 columnTypes[c.name] = c.type;
561 allColumns.push(c.name);
562 baseColumns.push(c.name);
563 let g = 'string';
564 const isNumeric = t.includes('INT') || t.includes('DECIMAL') || t.
includes('NUMERIC') || t.includes('REAL') || t.includes('DOUBLE') || t.includes(
'FLOAT') || t.includes('HUGEINT');
565 const isTimeType = t.includes('TIMESTAMP') || t.includes('DATE') |
| t.includes('TIME');
566 if (isNumeric || isTimeType) {
567 timeColumnOptions.push(c.name);
568 baseTimeColumnOptions.push(c.name);
569 if (!guess && heur.some(h => c.name.toLowerCase().includes(h)))
guess = c.name;
570 }
571 if (isTimeType) {
572 g = 'time';
573 timeColumns.push(c.name);
574 baseTimeColumns.push(c.name);
575 } else if (isNumeric) {
576 g = 'integer';
577 }
578 if (g === 'string') {
579 stringColumns.push(c.name);
580 baseStringColumns.push(c.name);
581 } else if (g === 'integer') {
582 integerColumns.push(c.name);
583 baseIntegerColumns.push(c.name);
584 }
585 groups[g].cols.push(c.name);
586 if (g !== 'string') {
587 const o = document.createElement('option');
588 o.value = c.name;
589 o.textContent = c.name;
590 orderSelect.appendChild(o);
591 }
592 });
593 timeColumns.forEach(name => {
594 const o = document.createElement('option');
595 o.value = name;
596 o.textContent = name;
597 xAxisSelect.appendChild(o);
598 });
599 timeColumnOptions.forEach(name => {
600 const o = document.createElement('option');
601 o.value = name;
602 o.textContent = name;
603 timeColumnSelect.appendChild(o);
604 });
605 xAxisSelect.value = '';
606 defaultTimeColumn = guess || timeColumnOptions[0] || '';
607 Object.keys(groups).forEach(key => {
608 const g = groups[key];
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll focus on collecting lines around collectParams with xval for the patch.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# nl -ba scubaduck/static/inde
x.html | sed -n '1006,1018p'
1006 payload.aggregate = document.getElementById('aggregate').value;
1007 payload.show_hits = document.getElementById('show_hits').checked;
1008 }
1009 if (graphTypeSel.value === 'timeseries') {
1010 const xval = document.getElementById('x_axis').value;
1011 if (xval) payload.x_axis = xval;
1012 payload.granularity = document.getElementById('granularity').value;
1013 payload.fill = document.getElementById('fill').value;
1014 }
1015 return payload;
1016 }
1017
1018 function paramsToSearch(params) {
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'm checking lines around 1058 for the ApplyParams changes.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# nl -ba scubaduck/static/inde
x.html | sed -n '1058,1072p'
1058 document.getElementById('limit').value = params.limit;
1059 }
1060 graphTypeSel.value = params.graph_type || 'samples';
1061 updateDisplayTypeUI();
1062 if (params.x_axis) {
1063 document.getElementById('x_axis').value = params.x_axis;
1064 } else {
1065 document.getElementById('x_axis').value = '';
1066 }
1067 if (params.granularity) document.getElementById('granularity').value =
params.granularity;
1068 if (params.fill) document.getElementById('fill').value = params.fill;
1069 if (params.group_by) {
1070 groupBy.chips.splice(0, groupBy.chips.length, ...params.group_by);
1071 groupBy.renderChips();
1072 }
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
I'll retrieve the line ranges for the recent server test changes.
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# nl -ba tests/test_server.py
| sed -n '330,378p'
330 "time_column": "created",
331 }
332 rv = client.post(
333 "/api/query", data=json.dumps(payload), content_type="applicatio
n/json"
334 )
335 data = rv.get_json()
336 assert rv.status_code == 200
337 assert len(data["rows"]) == 2
338
339
340 def test_integer_time_unit_ms(tmp_path: Path) -> None:
341 csv_file = tmp_path / "events.csv"
342 csv_file.write_text("created,event\n1704067200000,login\n17040708000
00,logout\n")
343 app = server.create_app(csv_file)
344 client = app.test_client()
345 payload = {
346 "table": "events",
347 "start": "2024-01-01 00:00:00",
348 "end": "2024-01-01 01:00:00",
349 "order_by": "created",
350 "columns": ["created", "event"],
351 "time_column": "created",
352 "time_unit": "ms",
353 }
354 rv = client.post(
355 "/api/query", data=json.dumps(payload), content_type="applicatio
n/json"
356 )
357 data = rv.get_json()
358 assert rv.status_code == 200
359 assert len(data["rows"]) == 2
360
361
362 def test_timeseries_default_xaxis_uses_time_column(tmp_path: Path) -> No
ne:
363 csv_file = tmp_path / "events.csv"
364 csv_file.write_text("created,event\n1704067200000,login\n17040708000
00,logout\n")
365 app = server.create_app(csv_file)
366 client = app.test_client()
367 payload = {
368 "table": "events",
369 "start": "2024-01-01 00:00:00",
370 "end": "2024-01-01 01:00:00",
371 "graph_type": "timeseries",
372 "granularity": "1 hour",
373 "columns": ["event"],
374 "aggregate": "Count",
375 "time_column": "created",
376 "time_unit": "ms",
377 }
378 rv = client.post(
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# nl -ba tests/test_server.py
| sed -n '378,398p'
378 rv = client.post(
379 "/api/query", data=json.dumps(payload), content_type="applicatio
n/json"
380 )
381 data = rv.get_json()
382 assert rv.status_code == 200
383 assert len(data["rows"]) == 2
384
385
386 def test_integer_time_unit_us_default_start_end(tmp_path: Path) -> None:
387 csv_file = tmp_path / "events.csv"
388 csv_file.write_text(
389 "created,event\n1704067200000000,login\n1704070800000000,logout\
n"
390 )
391 app = server.create_app(csv_file)
392 client = app.test_client()
393 payload = {
394 "table": "events",
395 "order_by": "created",
396 "columns": ["created", "event"],
397 "time_column": "created",
398 "time_unit": "us",
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# nl -ba tests/test_web.py | s
ed -n '96,118p'
96 assert len(data["rows"]) == 2
97
98
99 def test_time_column_dropdown(page: Any, server_url: str) -> None:
100 page.goto(server_url)
101 page.wait_for_selector("#time_column option", state="attached")
102 options = page.locator("#time_column option").all_inner_texts()
103 assert "timestamp" in options
104 assert "value" in options
105 assert page.input_value("#time_column") == "timestamp"
106
107
108 def test_time_unit_dropdown(page: Any, server_url: str) -> None:
109 page.goto(server_url)
110 page.wait_for_selector("#time_unit", state="attached")
111 opts = page.locator("#time_unit option").all_inner_texts()
112 assert "ms" in opts
113 assert page.input_value("#time_unit") == "s"
114
115
116 def test_x_axis_default_entry(page: Any, server_url: str) -> None:
117 page.goto(server_url)
118 page.wait_for_selector("#graph_type", state="attached")
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck# nl -ba tests/test_web.py | s
ed -n '118,132p'
118 page.wait_for_selector("#graph_type", state="attached")
119 select_value(page, "#graph_type", "timeseries")
120 page.wait_for_selector("#x_axis option", state="attached")
121 options = page.locator("#x_axis option").all_inner_texts()
122 assert "(default)" in options
123 assert page.input_value("#x_axis") == ""
124
125
126 def test_simple_filter(page: Any, server_url: str) -> None:
127 page.goto(server_url)
128 page.wait_for_selector("#order_by option", state="attached")
129 page.click("text=Add Filter")
130 filter_el = page.query_selector("#filters .filter:last-child")
131 assert filter_el
132 page.evaluate(
(scubaduck) root@4dc88f61e6c2:/workspace/scubaduck#
Time to open the PR and submit my changes!