Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Feb 7, 2025
1 parent b8c1bf4 commit a163b0f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
40 changes: 23 additions & 17 deletions src/obr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def run(ctx: click.Context, **kwargs):
"-g", "--generate", is_flag=True, help="Call generate directly after init."
)
@click.option("-c", "--config", required=True, help="Path to configuration file.")
@click.option("-e", "--env", is_flag=True, help="Shows required environment variables and exits.")
@click.option(
"-e", "--env", is_flag=True, help="Shows required environment variables and exits."
)
@click.option(
"-t",
"--tasks",
Expand Down Expand Up @@ -292,7 +294,7 @@ def init(ctx: click.Context, **kwargs):

config_str = read_yaml(kwargs)
config_str = config_str.replace("\n\n", "\n")
if (kwargs.get("env")):
if kwargs.get("env"):
sys.exit(0)

config = yaml.safe_load(config_str)
Expand Down Expand Up @@ -459,7 +461,7 @@ def postProcess(ctx: click.Context, **kwargs):
from copy import deepcopy
import json

def convert_to_numbers(df):
def convert_to_numbers(df):
"""convert all columns to float if they dont have Name in it"""
return df.astype({col: "float" for col in df.columns if not "Name" in col})

Expand All @@ -475,12 +477,14 @@ def convert_to_numbers(df):
matcher_args = {"transpEqn": ["name"]}
matcher_regex = {}

for m in d['matcher']:
matcher[m['name']] = lambda args, regex: customMatcher(args['name'], regex.format(**args))
matcher_args[m['name']] = deepcopy(m['args'])
matcher_regex[m['name']] = deepcopy(m['regexp'])
for m in d["matcher"]:
matcher[m["name"]] = lambda args, regex: customMatcher(
args["name"], regex.format(**args)
)
matcher_args[m["name"]] = deepcopy(m["args"])
matcher_regex[m["name"]] = deepcopy(m["regexp"])

queries: list[Query] = build_filter_query(d['queries'])
queries: list[Query] = build_filter_query(d["queries"])
query_results = project.query(jobs=filtered_jobs, query=queries)

records = []
Expand All @@ -489,32 +493,34 @@ def convert_to_numbers(df):
log = get_latest_log(job)
if not log:
continue
log_path = Path(job.path)/ "case"/ log
log_path = Path(job.path) / "case" / log

record = query_results[job.id]
record['jobid'] = job.id
for l in d['log']:
record["jobid"] = job.id
for l in d["log"]:
try:
matcher_name = l['matcher']
pass_args = {k:v for k,v in zip(matcher_args[matcher_name], l['args'])}
matcher_name = l["matcher"]
pass_args = {
k: v for k, v in zip(matcher_args[matcher_name], l["args"])
}
if m_regex := matcher_regex.get(matcher_name):
m = matcher[matcher_name](pass_args, matcher_regex[matcher_name])
else:
m = matcher[matcher_name](pass_args)

log_file_parser = LogFile(log_path, matcher=[m])
log_file_parser = LogFile(log_path, matcher=[m])
df = convert_to_numbers(log_file_parser.parse_to_df())
for col in df.columns:
try:
record[col] = df.iloc[1:][col].mean()
record[col] = df.iloc[1:][col].mean()
except:
pass
except Exception as e:
print(e)
if record:
records.append(record)
with open('postpro.json', 'w') as f:

with open("postpro.json", "w") as f:
json.dump(records, f)
logger.success("Successfully applied")

Expand Down
7 changes: 5 additions & 2 deletions src/obr/core/parse_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ def read_yaml(kwargs: dict) -> str:
config_str = add_includes(yaml_location, config_str)

return parse_special_variables(
parse_special_variables(config_str, dict(os.environ), "env", kwargs.get("env", False)),
parse_special_variables(
config_str, dict(os.environ), "env", kwargs.get("env", False)
),
{"location": str(yaml_location)},
"yaml", kwargs.get("env", False)
"yaml",
kwargs.get("env", False),
)


Expand Down
Empty file removed src/obr/postPro/__init__.py
Empty file.
1 change: 0 additions & 1 deletion src/obr/postPro/postPro.py

This file was deleted.

0 comments on commit a163b0f

Please sign in to comment.