logqbit 0.4__tar.gz → 0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- logqbit-0.5/PKG-INFO +96 -0
- logqbit-0.5/README.md +74 -0
- {logqbit-0.4 → logqbit-0.5}/pyproject.toml +11 -7
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/cli.py +29 -26
- logqbit-0.5/src/logqbit/dataframe.py +147 -0
- logqbit-0.5/src/logqbit/gui/__init__.py +1 -0
- {logqbit-0.4/src/logqbit → logqbit-0.5/src/logqbit/gui}/browser.py +40 -6
- {logqbit-0.4/src/logqbit → logqbit-0.5/src/logqbit/gui}/live_plotter.py +6 -1
- {logqbit-0.4/src/logqbit → logqbit-0.5/src/logqbit/gui}/plotter.py +14 -3
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/logfolder.py +65 -117
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/metadata.py +6 -0
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/registry.py +36 -5
- logqbit-0.5/tests/conftest.py +21 -0
- {logqbit-0.4 → logqbit-0.5}/tests/test_browser.py +16 -4
- logqbit-0.5/tests/test_dataframe.py +58 -0
- {logqbit-0.4 → logqbit-0.5}/tests/test_flush_issue.py +1 -1
- {logqbit-0.4 → logqbit-0.5}/tests/test_live_plotter.py +3 -4
- {logqbit-0.4 → logqbit-0.5}/tests/test_logfolder.py +53 -0
- {logqbit-0.4 → logqbit-0.5}/tests/test_plotter.py +5 -1
- {logqbit-0.4 → logqbit-0.5}/tests/test_registry.py +74 -0
- logqbit-0.4/PKG-INFO +0 -185
- logqbit-0.4/README.md +0 -164
- {logqbit-0.4 → logqbit-0.5}/.gitignore +0 -0
- {logqbit-0.4 → logqbit-0.5}/LICENSE +0 -0
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/__init__.py +0 -0
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/assets/browser.svg +0 -0
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/assets/live_plotter.svg +0 -0
- {logqbit-0.4/src/logqbit → logqbit-0.5/src/logqbit/gui}/detail_view.py +0 -0
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/misc/svg2ico.py +0 -0
- {logqbit-0.4 → logqbit-0.5}/src/logqbit/templates/move_from_labrad.py +0 -0
- {logqbit-0.4 → logqbit-0.5}/tests/for_all_pythons.ps1 +0 -0
- {logqbit-0.4 → logqbit-0.5}/tests/test_metadata.py +0 -0
logqbit-0.5/PKG-INFO
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: logqbit
|
|
3
|
+
Version: 0.5
|
|
4
|
+
Summary: Simple data logger and live plotter for lab-scale experiments.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Qiujv/logqbit
|
|
6
|
+
Author-email: Qiujv <qiujv@outlook.com>
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: numba>=0.65.0
|
|
10
|
+
Requires-Dist: numpy>=2.3.3
|
|
11
|
+
Requires-Dist: pandas>=2.3.3
|
|
12
|
+
Requires-Dist: pyarrow>=21.0.0
|
|
13
|
+
Requires-Dist: pyqtgraph>=0.14.0
|
|
14
|
+
Requires-Dist: pyside6>=6.9.3
|
|
15
|
+
Requires-Dist: ruamel-yaml>=0.18.15
|
|
16
|
+
Requires-Dist: send2trash>=1.8.3
|
|
17
|
+
Requires-Dist: tqdm>=4.67.1
|
|
18
|
+
Requires-Dist: typing-extensions>=4.15.0
|
|
19
|
+
Provides-Extra: labrad
|
|
20
|
+
Requires-Dist: pylabrad>=0.98.3; extra == 'labrad'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# LogQbit
|
|
24
|
+
|
|
25
|
+
LogQbit 是一个面向实验室场景的轻量数据记录工具包,适合记录中小规模实验数据。
|
|
26
|
+
|
|
27
|
+
它的核心设计目标是:
|
|
28
|
+
|
|
29
|
+
- 用简单的接口和运行逻辑实验数据。
|
|
30
|
+
- 基于目录的实验数据组织,用通用可读的格式储存数据。
|
|
31
|
+
- 在需要时再启用浏览器和实时绘图等 GUI 能力。
|
|
32
|
+
|
|
33
|
+
完整文档见:https://qiujv.github.io/logqbit/
|
|
34
|
+
|
|
35
|
+
## 安装
|
|
36
|
+
|
|
37
|
+
常规安装:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install logqbit
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
如果你不想让安装过程修改当前 Python 环境,可以跳过依赖解析:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install --no-deps logqbit
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
通常 `logqbit.logfolder.LogFolder`、`logqbit.registry.Registry` 等核心接口仍然可用;
|
|
50
|
+
但浏览器、实时绘图和快捷方式等 GUI 功能仍然依赖 `PySide6`、`pyqtgraph` 等组件。
|
|
51
|
+
|
|
52
|
+
更详细的安装说明见:https://qiujv.github.io/logqbit/install/
|
|
53
|
+
|
|
54
|
+
## 用例
|
|
55
|
+
|
|
56
|
+
### 用例 1:记录一组实验数据
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from pathlib import Path
|
|
60
|
+
|
|
61
|
+
from logqbit.logfolder import LogFolder
|
|
62
|
+
|
|
63
|
+
lf = LogFolder.new("./demo_data", title="My Experiment")
|
|
64
|
+
|
|
65
|
+
lf.add_row(x=0.0, y=1.2)
|
|
66
|
+
lf.add_row(x=1.0, y=1.8)
|
|
67
|
+
lf.flush()
|
|
68
|
+
|
|
69
|
+
lf.meta.plot_axes = ["x"]
|
|
70
|
+
lf.const["temperature"] = "300 K"
|
|
71
|
+
|
|
72
|
+
print(lf.df)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 用例 2:打开数据查看器
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
logqbit browser
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
或者也可以通过 `logqbit shortcuts` 创建桌面快捷方式(仅 Windows 可用)。
|
|
82
|
+
|
|
83
|
+
### 用例 3:快速生成示例数据并打开浏览器
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
logqbit browser-demo
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
这会在当前目录创建 `logqbit_example/`,生成多组示例数据,并启动图形化浏览器。
|
|
90
|
+
|
|
91
|
+
更多内容:
|
|
92
|
+
|
|
93
|
+
- 文档首页:https://qiujv.github.io/logqbit/
|
|
94
|
+
- 命令行工具:https://qiujv.github.io/logqbit/cli/
|
|
95
|
+
- LabRAD 迁移:https://qiujv.github.io/logqbit/migration_guide/
|
|
96
|
+
- Python API:https://qiujv.github.io/logqbit/api/
|
logqbit-0.5/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# LogQbit
|
|
2
|
+
|
|
3
|
+
LogQbit 是一个面向实验室场景的轻量数据记录工具包,适合记录中小规模实验数据。
|
|
4
|
+
|
|
5
|
+
它的核心设计目标是:
|
|
6
|
+
|
|
7
|
+
- 用简单的接口和运行逻辑实验数据。
|
|
8
|
+
- 基于目录的实验数据组织,用通用可读的格式储存数据。
|
|
9
|
+
- 在需要时再启用浏览器和实时绘图等 GUI 能力。
|
|
10
|
+
|
|
11
|
+
完整文档见:https://qiujv.github.io/logqbit/
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
常规安装:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install logqbit
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
如果你不想让安装过程修改当前 Python 环境,可以跳过依赖解析:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install --no-deps logqbit
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
通常 `logqbit.logfolder.LogFolder`、`logqbit.registry.Registry` 等核心接口仍然可用;
|
|
28
|
+
但浏览器、实时绘图和快捷方式等 GUI 功能仍然依赖 `PySide6`、`pyqtgraph` 等组件。
|
|
29
|
+
|
|
30
|
+
更详细的安装说明见:https://qiujv.github.io/logqbit/install/
|
|
31
|
+
|
|
32
|
+
## 用例
|
|
33
|
+
|
|
34
|
+
### 用例 1:记录一组实验数据
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from pathlib import Path
|
|
38
|
+
|
|
39
|
+
from logqbit.logfolder import LogFolder
|
|
40
|
+
|
|
41
|
+
lf = LogFolder.new("./demo_data", title="My Experiment")
|
|
42
|
+
|
|
43
|
+
lf.add_row(x=0.0, y=1.2)
|
|
44
|
+
lf.add_row(x=1.0, y=1.8)
|
|
45
|
+
lf.flush()
|
|
46
|
+
|
|
47
|
+
lf.meta.plot_axes = ["x"]
|
|
48
|
+
lf.const["temperature"] = "300 K"
|
|
49
|
+
|
|
50
|
+
print(lf.df)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 用例 2:打开数据查看器
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
logqbit browser
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
或者也可以通过 `logqbit shortcuts` 创建桌面快捷方式(仅 Windows 可用)。
|
|
60
|
+
|
|
61
|
+
### 用例 3:快速生成示例数据并打开浏览器
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
logqbit browser-demo
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
这会在当前目录创建 `logqbit_example/`,生成多组示例数据,并启动图形化浏览器。
|
|
68
|
+
|
|
69
|
+
更多内容:
|
|
70
|
+
|
|
71
|
+
- 文档首页:https://qiujv.github.io/logqbit/
|
|
72
|
+
- 命令行工具:https://qiujv.github.io/logqbit/cli/
|
|
73
|
+
- LabRAD 迁移:https://qiujv.github.io/logqbit/migration_guide/
|
|
74
|
+
- Python API:https://qiujv.github.io/logqbit/api/
|
|
@@ -4,6 +4,7 @@ dynamic = ["version"]
|
|
|
4
4
|
description = "Simple data logger and live plotter for lab-scale experiments."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
|
+
authors = [{ name = "Qiujv", email = "qiujv@outlook.com" }]
|
|
7
8
|
dependencies = [
|
|
8
9
|
"numba>=0.65.0",
|
|
9
10
|
"numpy>=2.3.3",
|
|
@@ -24,13 +25,8 @@ Homepage = "https://github.com/Qiujv/logqbit"
|
|
|
24
25
|
logqbit = "logqbit.cli:main"
|
|
25
26
|
|
|
26
27
|
[project.gui-scripts]
|
|
27
|
-
logqbit-live-plotter = "logqbit.live_plotter:main"
|
|
28
|
-
logqbit-browser = "logqbit.browser:main"
|
|
29
|
-
|
|
30
|
-
[project.optional-dependencies]
|
|
31
|
-
labrad = [
|
|
32
|
-
"pylabrad>=0.98.3",
|
|
33
|
-
]
|
|
28
|
+
logqbit-live-plotter = "logqbit.gui.live_plotter:main"
|
|
29
|
+
logqbit-browser = "logqbit.gui.browser:main"
|
|
34
30
|
|
|
35
31
|
[build-system]
|
|
36
32
|
requires = ["hatchling", "hatch-vcs"]
|
|
@@ -50,6 +46,14 @@ dev = [
|
|
|
50
46
|
"ipykernel>=6.30.1",
|
|
51
47
|
"ipywidgets>=8.1.7",
|
|
52
48
|
"matplotlib>=3.10.7",
|
|
49
|
+
"mkdocs>=1.6.1",
|
|
50
|
+
"mkdocstrings[python]>=0.29.1",
|
|
53
51
|
"pytest>=8.4.2",
|
|
54
52
|
"pytest-cov>=7.0.0",
|
|
53
|
+
"ruff>=0.15.12",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[project.optional-dependencies]
|
|
57
|
+
labrad = [
|
|
58
|
+
"pylabrad>=0.98.3",
|
|
55
59
|
]
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Command-line interface for logqbit utilities."""
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
-
import shutil
|
|
5
4
|
import subprocess
|
|
6
5
|
import sys
|
|
7
6
|
from importlib.resources import files
|
|
@@ -51,8 +50,8 @@ def copy_template(template_name: str, output_path: Path | None = None) -> int:
|
|
|
51
50
|
output_path.write_bytes(src.read())
|
|
52
51
|
|
|
53
52
|
print(f"✓ Template copied to: {output_path}")
|
|
54
|
-
print(
|
|
55
|
-
print(
|
|
53
|
+
print("\nNext steps:")
|
|
54
|
+
print(" 1. Edit the file to configure your paths")
|
|
56
55
|
print(f" 2. Run: python {output_path.name}")
|
|
57
56
|
|
|
58
57
|
return 0
|
|
@@ -62,6 +61,19 @@ def copy_template(template_name: str, output_path: Path | None = None) -> int:
|
|
|
62
61
|
return 1
|
|
63
62
|
|
|
64
63
|
|
|
64
|
+
def _windows_gui_python_executable() -> Path:
|
|
65
|
+
exe = Path(sys.executable)
|
|
66
|
+
if sys.platform == "win32" and exe.name.lower() != "pythonw.exe":
|
|
67
|
+
pythonw = exe.with_name("pythonw.exe")
|
|
68
|
+
if pythonw.exists():
|
|
69
|
+
return pythonw
|
|
70
|
+
return exe
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _powershell_single_quoted(value: object) -> str:
|
|
74
|
+
return "'" + str(value).replace("'", "''") + "'"
|
|
75
|
+
|
|
76
|
+
|
|
65
77
|
def create_shortcuts(output_dir: Path | None = None) -> int:
|
|
66
78
|
"""Create desktop shortcuts for logqbit-browser and logqbit-live-plotter.
|
|
67
79
|
|
|
@@ -75,20 +87,8 @@ def create_shortcuts(output_dir: Path | None = None) -> int:
|
|
|
75
87
|
Exit code (0 for success, 1 for error)
|
|
76
88
|
"""
|
|
77
89
|
try:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
plotter_exe = shutil.which("logqbit-live-plotter")
|
|
81
|
-
|
|
82
|
-
if not browser_exe:
|
|
83
|
-
print("Error: logqbit-browser.exe not found in PATH", file=sys.stderr)
|
|
84
|
-
print("Please ensure logqbit is installed.", file=sys.stderr)
|
|
85
|
-
return 1
|
|
86
|
-
|
|
87
|
-
if not plotter_exe:
|
|
88
|
-
print("Error: logqbit-live-plotter.exe not found in PATH", file=sys.stderr)
|
|
89
|
-
print("Please ensure logqbit is installed.", file=sys.stderr)
|
|
90
|
-
return 1
|
|
91
|
-
|
|
90
|
+
gui_python = _windows_gui_python_executable()
|
|
91
|
+
|
|
92
92
|
# Get icon paths from package
|
|
93
93
|
assets_dir = files("logqbit") / "assets"
|
|
94
94
|
browser_svg = assets_dir / "browser.svg"
|
|
@@ -126,7 +126,7 @@ def create_shortcuts(output_dir: Path | None = None) -> int:
|
|
|
126
126
|
try:
|
|
127
127
|
svg_to_ico(svg_str, ico_str)
|
|
128
128
|
print(f" ✓ Created: {ico_path}")
|
|
129
|
-
except (PermissionError, OSError)
|
|
129
|
+
except (PermissionError, OSError):
|
|
130
130
|
# Package directory might be read-only, try user's local data dir
|
|
131
131
|
import tempfile
|
|
132
132
|
temp_ico = Path(tempfile.gettempdir()) / f"logqbit_{name}.ico"
|
|
@@ -174,13 +174,15 @@ def create_shortcuts(output_dir: Path | None = None) -> int:
|
|
|
174
174
|
shortcuts = [
|
|
175
175
|
{
|
|
176
176
|
"name": "LogQbit Browser",
|
|
177
|
-
"target":
|
|
177
|
+
"target": gui_python,
|
|
178
|
+
"arguments": "-m logqbit.gui.browser",
|
|
178
179
|
"icon": str(browser_ico),
|
|
179
180
|
"output": output_dir / "LogQbit Browser.lnk"
|
|
180
181
|
},
|
|
181
182
|
{
|
|
182
183
|
"name": "LogQbit Live Plotter",
|
|
183
|
-
"target":
|
|
184
|
+
"target": gui_python,
|
|
185
|
+
"arguments": "-m logqbit.gui.live_plotter",
|
|
184
186
|
"icon": str(plotter_ico),
|
|
185
187
|
"output": output_dir / "LogQbit Live Plotter.lnk"
|
|
186
188
|
}
|
|
@@ -190,9 +192,10 @@ def create_shortcuts(output_dir: Path | None = None) -> int:
|
|
|
190
192
|
# PowerShell script to create shortcut with icon
|
|
191
193
|
ps_script = f"""
|
|
192
194
|
$WshShell = New-Object -ComObject WScript.Shell
|
|
193
|
-
$Shortcut = $WshShell.CreateShortcut(
|
|
194
|
-
$Shortcut.TargetPath =
|
|
195
|
-
$Shortcut.
|
|
195
|
+
$Shortcut = $WshShell.CreateShortcut({_powershell_single_quoted(sc['output'])})
|
|
196
|
+
$Shortcut.TargetPath = {_powershell_single_quoted(sc['target'])}
|
|
197
|
+
$Shortcut.Arguments = {_powershell_single_quoted(sc['arguments'])}
|
|
198
|
+
$Shortcut.IconLocation = {_powershell_single_quoted(sc['icon'])}
|
|
196
199
|
$Shortcut.Save()
|
|
197
200
|
"""
|
|
198
201
|
|
|
@@ -349,7 +352,7 @@ def create_example_data() -> int:
|
|
|
349
352
|
print("\nLaunching browser...")
|
|
350
353
|
|
|
351
354
|
# Launch browser directly
|
|
352
|
-
from logqbit.browser import main as browser_main
|
|
355
|
+
from logqbit.gui.browser import main as browser_main
|
|
353
356
|
return browser_main([str(example_dir)])
|
|
354
357
|
|
|
355
358
|
except ImportError as exc:
|
|
@@ -400,7 +403,7 @@ def main() -> int:
|
|
|
400
403
|
)
|
|
401
404
|
|
|
402
405
|
# browser-demo command
|
|
403
|
-
|
|
406
|
+
subparsers.add_parser(
|
|
404
407
|
"browser-demo",
|
|
405
408
|
help="Create example data and launch browser",
|
|
406
409
|
)
|
|
@@ -422,7 +425,7 @@ def main() -> int:
|
|
|
422
425
|
return copy_template(args.template, args.output)
|
|
423
426
|
|
|
424
427
|
elif args.command == "browser":
|
|
425
|
-
from logqbit.browser import main as browser_main
|
|
428
|
+
from logqbit.gui.browser import main as browser_main
|
|
426
429
|
directory = str(args.directory) if args.directory else None
|
|
427
430
|
browser_args = [directory] if directory else []
|
|
428
431
|
return browser_main(browser_args)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
import time
|
|
3
|
+
import uuid
|
|
4
|
+
import warnings
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DataFrameBuffer:
|
|
11
|
+
"""Buffer appended dataframe rows and persist them to a feather file.
|
|
12
|
+
|
|
13
|
+
The background thread has a small state machine:
|
|
14
|
+
wait until data becomes dirty, wait the current autosave interval to batch
|
|
15
|
+
nearby appends, then write if the buffer is still dirty. ``flush()`` skips
|
|
16
|
+
that delay and writes synchronously on the caller's thread.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, path: str | Path, autosave_interval: float = 0.2):
|
|
20
|
+
self.path = Path(path)
|
|
21
|
+
self._autosave_interval = autosave_interval
|
|
22
|
+
self._segs: list[pd.DataFrame] = []
|
|
23
|
+
if self.path.exists():
|
|
24
|
+
self._segs.append(pd.read_feather(self.path))
|
|
25
|
+
self._records: list[dict[str, float | int | str]] = []
|
|
26
|
+
|
|
27
|
+
self._dirty = False
|
|
28
|
+
self._closed = False
|
|
29
|
+
self._condition = threading.Condition()
|
|
30
|
+
self._thread = threading.Thread(target=self._run, daemon=True)
|
|
31
|
+
self._thread.start()
|
|
32
|
+
|
|
33
|
+
def get_df(self) -> pd.DataFrame:
|
|
34
|
+
with self._condition:
|
|
35
|
+
df = self._get_df_locked()
|
|
36
|
+
return df
|
|
37
|
+
|
|
38
|
+
def add_one_row(self, kwargs: dict[str, float | int | str]):
|
|
39
|
+
with self._condition:
|
|
40
|
+
self._records.append(kwargs)
|
|
41
|
+
self._mark_dirty_locked()
|
|
42
|
+
|
|
43
|
+
def add_multi_rows(self, df: pd.DataFrame):
|
|
44
|
+
with self._condition:
|
|
45
|
+
if self._records:
|
|
46
|
+
self._segs.append(pd.DataFrame.from_records(self._records))
|
|
47
|
+
self._records = []
|
|
48
|
+
self._segs.append(df)
|
|
49
|
+
self._mark_dirty_locked()
|
|
50
|
+
|
|
51
|
+
def flush(self) -> pd.DataFrame:
|
|
52
|
+
"""Flush pending rows immediately, blocking until the save finishes."""
|
|
53
|
+
with self._condition:
|
|
54
|
+
if not self._dirty:
|
|
55
|
+
return self._get_df_locked()
|
|
56
|
+
return self._write_locked()
|
|
57
|
+
|
|
58
|
+
def close(self) -> None:
|
|
59
|
+
"""Flush pending rows and stop the autosave thread."""
|
|
60
|
+
with self._condition:
|
|
61
|
+
if self._closed:
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
self.flush()
|
|
65
|
+
|
|
66
|
+
with self._condition:
|
|
67
|
+
self._closed = True
|
|
68
|
+
self._condition.notify_all()
|
|
69
|
+
if self._thread.is_alive() and self._thread is not threading.current_thread():
|
|
70
|
+
self._thread.join(timeout=2)
|
|
71
|
+
|
|
72
|
+
def _mark_dirty_locked(self) -> None:
|
|
73
|
+
was_dirty = self._dirty
|
|
74
|
+
self._dirty = True
|
|
75
|
+
if not was_dirty:
|
|
76
|
+
self._condition.notify_all()
|
|
77
|
+
|
|
78
|
+
def _get_df_locked(self) -> pd.DataFrame:
|
|
79
|
+
if self._records:
|
|
80
|
+
self._segs.append(pd.DataFrame.from_records(self._records))
|
|
81
|
+
self._records = []
|
|
82
|
+
|
|
83
|
+
if len(self._segs) == 0:
|
|
84
|
+
return pd.DataFrame({})
|
|
85
|
+
if len(self._segs) == 1:
|
|
86
|
+
return self._segs[0]
|
|
87
|
+
|
|
88
|
+
df = pd.concat(self._segs)
|
|
89
|
+
self._segs = [df]
|
|
90
|
+
return df
|
|
91
|
+
|
|
92
|
+
def _run(self) -> None:
|
|
93
|
+
while True:
|
|
94
|
+
with self._condition:
|
|
95
|
+
while not self._dirty and not self._closed:
|
|
96
|
+
self._condition.wait()
|
|
97
|
+
|
|
98
|
+
if self._closed:
|
|
99
|
+
return
|
|
100
|
+
|
|
101
|
+
self._condition.wait(timeout=self._autosave_interval)
|
|
102
|
+
if self._closed:
|
|
103
|
+
return
|
|
104
|
+
if self._dirty:
|
|
105
|
+
self._write_locked()
|
|
106
|
+
|
|
107
|
+
def _write_locked(
|
|
108
|
+
self,
|
|
109
|
+
max_retries: int = 3,
|
|
110
|
+
retry_delay: float = 0.1,
|
|
111
|
+
) -> pd.DataFrame:
|
|
112
|
+
df = self._get_df_locked()
|
|
113
|
+
tmp = self.path.with_suffix(f".{uuid.uuid4().hex[:8]}.tmp")
|
|
114
|
+
df.to_feather(tmp)
|
|
115
|
+
self._replace_tmp(tmp, max_retries=max_retries, retry_delay=retry_delay)
|
|
116
|
+
self._dirty = False
|
|
117
|
+
self._autosave_interval = self._autosave_interval_for_rows(df.shape[0])
|
|
118
|
+
return df
|
|
119
|
+
|
|
120
|
+
def _autosave_interval_for_rows(self, row_count: int) -> float:
|
|
121
|
+
if row_count < 1000:
|
|
122
|
+
return 0.1
|
|
123
|
+
if row_count < 10000:
|
|
124
|
+
return 0.2
|
|
125
|
+
if row_count < 100000:
|
|
126
|
+
return 0.5
|
|
127
|
+
return 1.0
|
|
128
|
+
|
|
129
|
+
def _replace_tmp(
|
|
130
|
+
self,
|
|
131
|
+
tmp: Path,
|
|
132
|
+
max_retries: int,
|
|
133
|
+
retry_delay: float,
|
|
134
|
+
) -> None:
|
|
135
|
+
for attempt in range(max_retries):
|
|
136
|
+
try:
|
|
137
|
+
tmp.replace(self.path)
|
|
138
|
+
return
|
|
139
|
+
except PermissionError:
|
|
140
|
+
if attempt < max_retries - 1:
|
|
141
|
+
time.sleep(retry_delay)
|
|
142
|
+
retry_delay *= 2 # Exponential backoff
|
|
143
|
+
else:
|
|
144
|
+
warnings.warn(
|
|
145
|
+
f"Failed to replace {self.path} after {max_retries} attempts"
|
|
146
|
+
)
|
|
147
|
+
raise
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""GUI components for LogQbit."""
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
|
+
import os
|
|
6
7
|
import shutil
|
|
7
8
|
import subprocess
|
|
8
9
|
import sys
|
|
10
|
+
import threading
|
|
9
11
|
from collections.abc import Iterable
|
|
10
12
|
from dataclasses import dataclass, field
|
|
11
13
|
from importlib.resources import files
|
|
@@ -51,17 +53,19 @@ try: # pragma: no cover - fallback for direct execution
|
|
|
51
53
|
RecordDetailWindow,
|
|
52
54
|
record_watch_paths,
|
|
53
55
|
)
|
|
54
|
-
from
|
|
55
|
-
from
|
|
56
|
+
from ..logfolder import LogFolder
|
|
57
|
+
from ..metadata import LogMetadata
|
|
58
|
+
from .plotter import warmup_plotter_jit
|
|
56
59
|
except ImportError: # pragma: no cover - fallback for direct execution
|
|
60
|
+
from detail_view import PandasTableModel # type: ignore # noqa: F401
|
|
57
61
|
from detail_view import ( # type: ignore
|
|
58
|
-
PandasTableModel,
|
|
59
62
|
RecordDetailView,
|
|
60
63
|
RecordDetailWindow,
|
|
61
64
|
record_watch_paths,
|
|
62
65
|
)
|
|
63
|
-
from logfolder import LogFolder # type: ignore
|
|
64
|
-
from metadata import LogMetadata # type: ignore
|
|
66
|
+
from logqbit.logfolder import LogFolder # type: ignore # noqa: F401
|
|
67
|
+
from logqbit.metadata import LogMetadata # type: ignore
|
|
68
|
+
from plotter import warmup_plotter_jit # type: ignore
|
|
65
69
|
|
|
66
70
|
logger = logging.getLogger(__name__)
|
|
67
71
|
|
|
@@ -81,6 +85,10 @@ SETTINGS_ORG = "LogQbit"
|
|
|
81
85
|
SETTINGS_APP = "LogBrowser"
|
|
82
86
|
SETTINGS_RECENT_DIRS_KEY = "recent/directories"
|
|
83
87
|
SETTINGS_THEME_KEY = "ui/theme"
|
|
88
|
+
DISABLE_RECENT_DIRS_ENV = "LOGQBIT_BROWSER_DISABLE_RECENT_DIRS"
|
|
89
|
+
DISABLE_JIT_WARMUP_ENV = "LOGQBIT_BROWSER_DISABLE_JIT_WARMUP"
|
|
90
|
+
|
|
91
|
+
_plotter_jit_warmup_started = False
|
|
84
92
|
|
|
85
93
|
def _load_window_icon() -> QIcon:
|
|
86
94
|
try:
|
|
@@ -96,6 +104,28 @@ def _load_window_icon() -> QIcon:
|
|
|
96
104
|
WINDOW_ICON = _load_window_icon()
|
|
97
105
|
|
|
98
106
|
|
|
107
|
+
def _start_plotter_jit_warmup() -> None:
|
|
108
|
+
global _plotter_jit_warmup_started
|
|
109
|
+
if _plotter_jit_warmup_started:
|
|
110
|
+
return
|
|
111
|
+
if os.environ.get(DISABLE_JIT_WARMUP_ENV):
|
|
112
|
+
return
|
|
113
|
+
_plotter_jit_warmup_started = True
|
|
114
|
+
|
|
115
|
+
def run_warmup() -> None:
|
|
116
|
+
try:
|
|
117
|
+
warmup_plotter_jit()
|
|
118
|
+
except Exception as exc: # pragma: no cover - defensive
|
|
119
|
+
logger.debug("Failed to warm up plotter JIT: %s", exc)
|
|
120
|
+
|
|
121
|
+
thread = threading.Thread(
|
|
122
|
+
target=run_warmup,
|
|
123
|
+
name="logqbit-plotter-jit-warmup",
|
|
124
|
+
daemon=True,
|
|
125
|
+
)
|
|
126
|
+
thread.start()
|
|
127
|
+
|
|
128
|
+
|
|
99
129
|
def _next_export_logfolder_path(parent_path: Path) -> Path:
|
|
100
130
|
parent_path = Path(parent_path)
|
|
101
131
|
max_index = max(
|
|
@@ -401,6 +431,9 @@ class SettingsManager:
|
|
|
401
431
|
self._settings.sync()
|
|
402
432
|
|
|
403
433
|
def update_recent_directories(self, path: Path) -> list[Path]:
|
|
434
|
+
if os.environ.get(DISABLE_RECENT_DIRS_ENV):
|
|
435
|
+
return self.load_recent_directories()
|
|
436
|
+
|
|
404
437
|
self.load_recent_directories()
|
|
405
438
|
|
|
406
439
|
resolved = Path(path)
|
|
@@ -564,6 +597,7 @@ class LogBrowserWindow(QMainWindow):
|
|
|
564
597
|
self._update_window_title()
|
|
565
598
|
self._sync_directory_watcher()
|
|
566
599
|
self.refresh_logs()
|
|
600
|
+
QTimer.singleShot(500, _start_plotter_jit_warmup)
|
|
567
601
|
|
|
568
602
|
def _build_ui(self) -> None:
|
|
569
603
|
central = QWidget(self)
|
|
@@ -915,7 +949,7 @@ class LogBrowserWindow(QMainWindow):
|
|
|
915
949
|
"""Launch a new browser window in a separate process."""
|
|
916
950
|
try:
|
|
917
951
|
subprocess.Popen(
|
|
918
|
-
[sys.executable, "-m", "logqbit.browser", str(directory)],
|
|
952
|
+
[sys.executable, "-m", "logqbit.gui.browser", str(directory)],
|
|
919
953
|
cwd=Path.cwd(),
|
|
920
954
|
start_new_session=True, # Detach from parent process
|
|
921
955
|
)
|
|
@@ -14,7 +14,6 @@ from numba import njit, prange
|
|
|
14
14
|
from PySide6.QtCore import QEvent, Qt, Signal
|
|
15
15
|
from PySide6.QtGui import QColor, QIcon
|
|
16
16
|
from PySide6.QtWidgets import (
|
|
17
|
-
QAbstractItemView,
|
|
18
17
|
QHBoxLayout,
|
|
19
18
|
QLabel,
|
|
20
19
|
QListView,
|
|
@@ -117,6 +116,20 @@ def _build_grids_rect(ys, zs, col_starts, col_sizes, max_ny, nx_col, top_y, step
|
|
|
117
116
|
return z_final, y_final
|
|
118
117
|
|
|
119
118
|
|
|
119
|
+
def warmup_plotter_jit() -> None:
|
|
120
|
+
"""Compile numba-backed 2D plotting helpers before the first real plot."""
|
|
121
|
+
x = np.array([0.0, 0.0, 1.0, 1.0], dtype=np.float64)
|
|
122
|
+
y = np.array([0.0, 1.0, 0.0, 1.0], dtype=np.float64)
|
|
123
|
+
z = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float64)
|
|
124
|
+
col_starts = np.array([0, 2], dtype=np.int64)
|
|
125
|
+
col_sizes = np.array([2, 2], dtype=np.int64)
|
|
126
|
+
top_y = np.array([2.0, 2.0], dtype=np.float64)
|
|
127
|
+
step_c = np.array([1.0, 1.0], dtype=np.float64)
|
|
128
|
+
|
|
129
|
+
_is_lexsorted(x, y)
|
|
130
|
+
_build_grids_rect(y, z, col_starts, col_sizes, 2, 2, top_y, step_c)
|
|
131
|
+
|
|
132
|
+
|
|
120
133
|
class TagBar(QWidget):
|
|
121
134
|
"""
|
|
122
135
|
Single QListWidget holding axes / fields / ignored items in one row,
|
|
@@ -514,5 +527,3 @@ class PlotManager:
|
|
|
514
527
|
cmap = pg.colormap.get("CET-D1")
|
|
515
528
|
return cmap
|
|
516
529
|
|
|
517
|
-
|
|
518
|
-
|