Explorar o código

Export parameters to CSV and bump version to 0.1.2

LiuYang hai 17 horas
pai
achega
3000d142fc
Modificáronse 7 ficheiros con 37 adicións e 10 borrados
  1. 3 3
      README.md
  2. 1 1
      RELEASE.md
  3. 1 1
      pyproject.toml
  4. 1 1
      src/mlog_tool/__init__.py
  5. 1 1
      src/mlog_tool/cli.py
  6. 29 2
      src/mlog_tool/exporters.py
  7. 1 1
      uv.lock

+ 3 - 3
README.md

@@ -1,11 +1,11 @@
 # Python MLog Tool
 
-Python desktop and CLI tool for parsing Firmament `mlog` binary files, exporting each bus to CSV, and plotting signals in a Qt GUI.
+Python desktop and CLI tool for parsing Firmament `mlog` binary files, exporting buses and parameters to CSV, and plotting signals in a Qt GUI.
 
 ## Features
 
 - Parse binary `mlog` files into structured bus data.
-- Export each bus group to an individual CSV file.
+- Export each bus group to an individual CSV file and all parameters to a separate CSV file.
 - Inspect and compare signals in a `PySide6 + PyQtGraph` desktop GUI.
 - View parsed parameter groups directly in the GUI.
 - Build a platform-native single-file executable with `PyInstaller`.
@@ -135,7 +135,7 @@ The build script also creates a versioned copy that is convenient for release de
 ## Notes
 
 - The Qt GUI parses the selected log immediately after opening the file.
-- The generated CSV files are organized one bus per file.
+- CSV export writes one file per bus. When parameter groups are present, it also writes `parameters.csv` with `group`, `name`, `type`, and `value` columns (or `parameters_1.csv`, etc. if the name conflicts with a bus).
 - The left panel is split into `Parameters` and `Buses`.
 - Parameter details are viewed in the lower-right table and are not plottable.
 - Cursor mode supports left-click freeze and right-click release directly on the plot.

+ 1 - 1
RELEASE.md

@@ -2,7 +2,7 @@
 
 ## Current Version
 
-- `0.1.1`
+- `0.1.2`
 
 ## Release Steps
 

+ 1 - 1
pyproject.toml

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
 
 [project]
 name = "python-mlog-tool"
-version = "0.1.1"
+version = "0.1.2"
 description = "Parse MLog binaries, export bus data to CSV, and plot signals."
 readme = "README.md"
 requires-python = ">=3.10"

+ 1 - 1
src/mlog_tool/__init__.py

@@ -9,6 +9,6 @@ from .services import MLogService
 try:
     __version__ = version("python-mlog-tool")
 except PackageNotFoundError:
-    __version__ = "0.1.1"
+    __version__ = "0.1.2"
 
 __all__ = ["MLogParser", "MLogService", "ParsedLog", "__version__"]

+ 1 - 1
src/mlog_tool/cli.py

@@ -17,7 +17,7 @@ def build_parser() -> argparse.ArgumentParser:
     parse_cmd = subparsers.add_parser("parse", help="Parse a log file and print a summary.")
     parse_cmd.add_argument("log_file", type=Path, help="Path to a .bin or .log file.")
 
-    export_cmd = subparsers.add_parser("export", help="Parse a log file and export all buses to CSV.")
+    export_cmd = subparsers.add_parser("export", help="Parse a log file and export buses and parameters to CSV.")
     export_cmd.add_argument("log_file", type=Path, help="Path to a .bin or .log file.")
     export_cmd.add_argument("output_dir", type=Path, help="Directory for generated CSV files.")
 

+ 29 - 2
src/mlog_tool/exporters.py

@@ -1,14 +1,16 @@
-"""CSV export helpers for parsed bus data."""
+"""CSV export helpers for parsed bus data and parameters."""
 
 from __future__ import annotations
 
+import csv
 from pathlib import Path
 
+from .constants import TYPE_DISPLAY_NAMES
 from .models import ParsedLog
 
 
 class CsvExporter:
-    """Export each bus table in a parsed log to an individual CSV file."""
+    """Export each bus table and, when present, all parameters to CSV files."""
 
     def export_all(self, parsed_log: ParsedLog, output_dir: str | Path) -> list[Path]:
         output_path = Path(output_dir)
@@ -19,4 +21,29 @@ class CsvExporter:
             csv_path = output_path / f"{bus_name}.csv"
             bus_frame.frame.to_csv(csv_path, index=False)
             written_files.append(csv_path)
+
+        if parsed_log.header.parameter_groups:
+            # Keep bus filenames unchanged, even if a bus is named "parameters".
+            bus_filenames = {path.name.casefold() for path in written_files}
+            filename = "parameters.csv"
+            suffix = 1
+            while filename.casefold() in bus_filenames:
+                filename = f"parameters_{suffix}.csv"
+                suffix += 1
+
+            csv_path = output_path / filename
+            with csv_path.open("w", encoding="utf-8", newline="") as stream:
+                writer = csv.writer(stream)
+                writer.writerow(["group", "name", "type", "value"])
+                for group in parsed_log.header.parameter_groups:
+                    for parameter in group.parameters:
+                        writer.writerow(
+                            [
+                                group.name,
+                                parameter.name,
+                                TYPE_DISPLAY_NAMES.get(parameter.type_id, str(parameter.type_id)),
+                                parameter.value,
+                            ]
+                        )
+            written_files.append(csv_path)
         return written_files

+ 1 - 1
uv.lock

@@ -1048,7 +1048,7 @@ wheels = [
 
 [[package]]
 name = "python-mlog-tool"
-version = "0.1.1"
+version = "0.1.2"
 source = { editable = "." }
 dependencies = [
     { name = "matplotlib" },