Skip to content

Commit

Permalink
Set new parser standard
Browse files Browse the repository at this point in the history
There has been talks of making this project into a library
and letting each forward model creator manage there own forward model.
For this we need a prorper and clear standard that each project can inherit and abide by.

What better way then starting with the parser standard.
New parser standard:
- uses three main cammands, run, lint, and schema
- retains backwards compatibility with old adhoc version
- library is plug-n-play
  • Loading branch information
sregales-TNO committed May 27, 2024
1 parent 0c43c93 commit 75b9b0e
Show file tree
Hide file tree
Showing 27 changed files with 755 additions and 458 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ fm_well_constraints = "everest_models.jobs.fm_well_constraints.cli:main_entry_po
fm_well_filter = "everest_models.jobs.fm_well_filter.cli:main_entry_point"
fm_well_trajectory = "everest_models.jobs.fm_well_trajectory.cli:main_entry_point"
fm_well_swapping = "everest_models.jobs.fm_well_swapping.cli:main_entry_point"
fm_track_well_switch = "everest_models.jobs.fm_track_well_switch.cli:main_entry_point"
fm_update_dates = "everest_models.jobs.fm_update_dates.cli:main_entry_point"
fm_adjust_well_status = "everest_models.jobs.fm_adjust_well_status.cli:main_entry_point"

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
2 changes: 2 additions & 0 deletions src/everest_models/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
fm_strip_dates,
fm_well_constraints,
fm_well_filter,
fm_well_swapping,
fm_well_trajectory,
)

Expand All @@ -32,4 +33,5 @@
"fm_well_constraints",
"fm_well_filter",
"fm_well_trajectory",
"fm_well_swapping",
]
2 changes: 1 addition & 1 deletion src/everest_models/jobs/fm_well_swapping/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from everest_models.jobs.fm_add_templates.cli import main_entry_point
from everest_models.jobs.fm_well_swapping.cli import main_entry_point

__all__ = ["main_entry_point"]
53 changes: 6 additions & 47 deletions src/everest_models/jobs/fm_well_swapping/cli.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,32 @@
#!/usr/bin/env python

import logging
from argparse import Namespace
from typing import Dict, List, NamedTuple, Optional, Sequence, Tuple
from typing import Optional, Sequence

from .models import validate_priorities_and_state_initial_same_wells
from .parser import build_argument_parser
from .state_processor import StateProcessor
from .tasks import (
clean_parsed_data,
determine_index_states,
duration_to_dates,
inject_well_operations,
sorted_well_priorities,
)

logger = logging.getLogger(__name__)


class Data(NamedTuple):
priorities: Tuple[Tuple[str, ...], ...]
initial_states: Dict[str, str]
n_max_wells: Tuple[int, ...]
n_switch_states: Tuple[int, ...]
state_duration: Tuple[int, ...]
errors: List[str]


def clean_incoming_data(options: Namespace) -> Data:
errors: List[str] = []
if not (
priorities := sorted_well_priorities(
options.priorities or options.config.index_priorities
)
):
errors.append("no priorities")
try:
validate_priorities_and_state_initial_same_wells(
set(priorities[0]), set(options.config.state.wells)
)
except ValueError as e:
errors.append(str(e))

if not (
constraints := options.config.rescale_constraints(options.constraints)
if options.constraints
else options.config.constraints
):
errors.append("no constraints")

return Data(
priorities,
options.config.initial_states(priorities[0]),
**constraints,
errors=errors,
)


def main_entry_point(args: Optional[Sequence[str]] = None):
args_parser = build_argument_parser()
options = args_parser.parse_args(args)
data = clean_incoming_data(options)
data = clean_parsed_data(options)
if data.errors:
args_parser.error("\n".join(data.errors))

if args and args[0] == "parse":
if data.lint_only:
args_parser.exit()

inject_well_operations(
options.input.to_dict(),
data.wells.to_dict(),
zip(
duration_to_dates(
data.state_duration,
Expand All @@ -86,7 +45,7 @@ def main_entry_point(args: Optional[Sequence[str]] = None):
),
),
)
options.input.json_dump(options.output)
data.wells.json_dump(options.output)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 75b9b0e

Please sign in to comment.