Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plexosdb-mcp/src/plexosdb_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def add_object(
db = server_state.get_db(session_id)
class_enum = _parse_class_name(class_name)

collection_enum: CollectionEnum | None | bool = None
collection_enum: CollectionEnum | bool | None = None
try:
_ = get_default_collection(class_enum)
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion src/plexosdb-mcp/tests/test_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def add_object(
*,
description: str | None = None,
category: str | None = None,
collection_enum: CollectionEnum | None | bool = None,
collection_enum: CollectionEnum | bool | None = None,
) -> int:
"""Capture add_object inputs and return a stable object id."""
self.last_add_object = {
Expand Down
12 changes: 7 additions & 5 deletions src/plexosdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def add_object(
*,
description: str | None = None,
category: str | None = None,
collection_enum: CollectionEnum | None | Literal[False] = None,
collection_enum: CollectionEnum | Literal[False] | None = None,
) -> int:
"""Add an object to the database and append a system membership.

Expand Down Expand Up @@ -1376,15 +1376,17 @@ def add_report(
report_samples: bool | None = None,
write_flat_files: bool = False,
) -> None:
"""Add a report configuration to the database.
"""Add an output property configuration to an existing report.

Creates a new report in the database with the specified properties and output options.
Reports define what data will be available for post-processing after simulation runs.
Adds a property and its output options to the specified ``Report`` object.
The report object must already exist; call :meth:`add_object` first only when
creating a new report object. Reports define what data will be available for
post-processing after simulation runs.

Parameters
----------
object_name : str
Name of the report object to add the configuration to
Name of the existing report object to add the configuration to
property : str
Name of the property to report on
collection : CollectionEnum
Expand Down
7 changes: 3 additions & 4 deletions tests/test_plexos_to_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,9 @@ def test_materialize_single_solution_table_from_subset_skips_missing_period_entr
monkeypatch.setattr(
sr,
"_build_fallback_create_sql",
lambda _schema,
_table,
_ids,
dv_source="main.t_data_values": f'CREATE TABLE data."T" AS SELECT * FROM {dv_source}',
lambda _schema, _table, _ids, dv_source="main.t_data_values": (
f'CREATE TABLE data."T" AS SELECT * FROM {dv_source}'
),
)
monkeypatch.setattr(sr, "_copy_data_table_to_report", lambda *_args, **_kwargs: None)

Expand Down
39 changes: 39 additions & 0 deletions tests/test_plexosdb_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,42 @@ def test_adding_reports(db_base: PlexosDB):
parent_class=ClassEnum.System,
child_class=ClassEnum.Generator,
)


def test_add_report_property_to_existing_report(db_base: PlexosDB):
from plexosdb import ClassEnum, CollectionEnum

db: PlexosDB = db_base
report_object = "existing_report"
db.add_object(ClassEnum.Report, name=report_object)

report_properties = db.list_valid_properties_report(
CollectionEnum.Generators,
parent_class_enum=ClassEnum.System,
child_class_enum=ClassEnum.Generator,
)
first_property, second_property = report_properties[:2]

for report_property in (first_property, second_property):
db.add_report(
object_name=report_object,
property=report_property,
collection=CollectionEnum.Generators,
parent_class=ClassEnum.System,
child_class=ClassEnum.Generator,
)

configured_properties = db.query(
"""
SELECT property_report.name
FROM t_report AS report
JOIN t_object AS object ON object.object_id = report.object_id
JOIN t_property_report AS property_report
ON property_report.property_id = report.property_id
WHERE object.name = ?
ORDER BY property_report.name
""",
(report_object,),
)

assert [row[0] for row in configured_properties] == sorted((first_property, second_property))
Loading
Loading