#14614 Orion Events: Add menu item for importing events from file

Add RicImportOrionEventsFeature to File -> Import -> Well Data and the well
path collection context menu. The feature opens a file dialog and launches
the Python interpreter asynchronously with the new --apply mode of the
rips.orion_events CLI, which connects back to the running instance through
RESINSIGHT_GRPC_PORT and applies the events to the well event timeline.
Output is shown in the Process Monitor panel.
This commit is contained in:
Kristian Bendiksen committed 2026-08-28 13:22:33 +02:00
1 parent 5f0c3f8a54
commit b00471dce2
7 files changed
+260 -1

No files matched your search

+53 -1
View File
@@ -2252,14 +2252,63 @@ _COMPLETION_EVENT_TYPES = (
# ---------------------------------------------------------------------------
def _apply_to_running_instance(document: OrionDocument) -> int:
"""Apply a parsed document to the well event timeline of a running
ResInsight instance found through the RESINSIGHT_GRPC_PORT environment
variable. Returns a process exit code."""
import rips
resinsight = rips.Instance.find()
if resinsight is None:
print("Error: no running ResInsight instance found")
return 1
project = resinsight.project
well_path_collections = project.descendants(rips.WellPathCollection)
if not well_path_collections:
print("Error: the project has no well path collection")
return 1
timeline = well_path_collections[0].event_timeline()
# A case is only needed to materialize FILTER declarations; default to the
# first case when one is loaded.
cases = project.cases()
case = cases[0] if cases else None
try:
report = apply_orion_document(
document, timeline, project, case=case, on_unknown_well="warn"
)
except RipsError as exc:
print(f"Error: {exc}")
return 1
print(f" Events applied: {report.events_applied}")
print(f" Events skipped: {report.events_skipped}")
if report.report_dates:
print(f" Report dates: {', '.join(report.report_dates)}")
for warning in report.warnings:
print(f" Warning: {warning}")
for error in report.errors:
print(f" Error: {error}")
return 1 if report.errors else 0
def _cli(argv: Optional[List[str]] = None) -> int:
import argparse
arg_parser = argparse.ArgumentParser(
prog="python3 -m rips.orion_events",
description="Validate an ORIONEVENTS file (parse only; no ResInsight needed).",
description="Validate an ORIONEVENTS file (parse only; no ResInsight "
"needed), and optionally apply it to a running ResInsight instance.",
)
arg_parser.add_argument("file", help="path to the ORIONEVENTS file")
arg_parser.add_argument(
"--apply",
action="store_true",
help="apply the events to a running ResInsight instance after validating",
)
args = arg_parser.parse_args(argv)
try:
@@ -2292,6 +2341,9 @@ def _cli(argv: Optional[List[str]] = None) -> int:
normalized = coalesce_orion_document(document)
for warning in normalized.warnings:
print(f" Warning line {warning.loc.line}: {warning.message}")
if args.apply:
return _apply_to_running_instance(document)
return 0
@@ -1001,6 +1001,85 @@ class TestValidatorCli:
assert "Error" in capsys.readouterr().out
class FakeWellPathCollection:
def __init__(self, timeline):
self._timeline = timeline
def event_timeline(self):
return self._timeline
class FakeCliProject(FakeProject):
"""A project whose well path collections are discoverable via descendants."""
def __init__(self, names, cases=(), collections=()):
super().__init__(names, cases)
self._collections = list(collections)
def descendants(self, cls):
return self._collections
class FakeInstance:
def __init__(self, project):
self.project = project
class TestApplyCli:
def _write(self, tmp_path, text):
path = tmp_path / "events.orion"
path.write_text(text)
return str(path)
def test_apply_exits_zero_and_reports_applied_events(
self, tmp_path, capsys, monkeypatch
):
timeline = FakeTimeline()
project = FakeCliProject(
("55_33-A-1", "55_33-A-2"),
collections=[FakeWellPathCollection(timeline)],
)
monkeypatch.setattr(
rips.Instance, "find", staticmethod(lambda: FakeInstance(project))
)
path = self._write(tmp_path, SAMPLE)
assert _cli([path, "--apply"]) == 0
out = capsys.readouterr().out
assert "Events applied: 4" in out
assert len(timeline.perf_calls) == 2
assert len(timeline.keyword_calls) == 2
def test_apply_without_running_instance_exits_nonzero(
self, tmp_path, capsys, monkeypatch
):
monkeypatch.setattr(rips.Instance, "find", staticmethod(lambda: None))
path = self._write(tmp_path, SAMPLE)
assert _cli([path, "--apply"]) == 1
assert "no running ResInsight instance" in capsys.readouterr().out
def test_apply_without_well_path_collection_exits_nonzero(
self, tmp_path, capsys, monkeypatch
):
project = FakeCliProject(("55_33-A-1",), collections=[])
monkeypatch.setattr(
rips.Instance, "find", staticmethod(lambda: FakeInstance(project))
)
path = self._write(tmp_path, SAMPLE)
assert _cli([path, "--apply"]) == 1
assert "no well path collection" in capsys.readouterr().out
def test_validate_only_does_not_contact_instance(
self, tmp_path, capsys, monkeypatch
):
def fail():
raise AssertionError("Instance.find must not be called")
monkeypatch.setattr(rips.Instance, "find", staticmethod(fail))
path = self._write(tmp_path, SAMPLE)
assert _cli([path]) == 0
assert "OK" in capsys.readouterr().out
# ---------------------------------------------------------------------------
# Layer B: applying
# ---------------------------------------------------------------------------