From 49f663ec0cf967037bfc0e3607f33e7d0bcae8e9 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 15:33:33 +0200 Subject: [PATCH] parse with regex --- bins/inbreeding/consts.nu | 14 +++++++++++--- bins/inbreeding/inspect.nu | 3 ++- bins/inbreeding/load.nu | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bins/inbreeding/consts.nu b/bins/inbreeding/consts.nu index 708ac7ab..96aa84ac 100644 --- a/bins/inbreeding/consts.nu +++ b/bins/inbreeding/consts.nu @@ -1,6 +1,14 @@ export const BIN = "./target/release/inbreeding" export const CACHE = ($nu.home-path | path join .cache komodo inbreeding) -export const ARG_EXPERIMENT_FORMAT = "{seed}-{env}-{k}-{n}-{nb_bytes}" -export const EXPERIMENT_FORMAT = "{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}" -export const FULL_EXPERIMENT_FORMAT = $"{seed}(char path_sep)($EXPERIMENT_FORMAT)" +const FMT = { + env: "(?<env>.*)", + seed: "(?<seed>[a-zA-Z0-9]*)", + params: '(?<k>\d+)-(?<n>\d+)-(?<nb_bytes>\d+)', + timestamp: '(?<timestamp>\d+)', + strat: "(?<strategy>.*)" , +} + +export const ARG_EXPERIMENT_FORMAT = $FMT.seed + '-' + $FMT.env + '-' + $FMT.params +export const EXPERIMENT_FORMAT = $FMT.timestamp + '-' + $FMT.env + '-' + $FMT.strat + '-' + $FMT.params +export const FULL_EXPERIMENT_FORMAT = $FMT.seed + (char path_sep) + $EXPERIMENT_FORMAT diff --git a/bins/inbreeding/inspect.nu b/bins/inbreeding/inspect.nu index 8fe9d548..0df2ea82 100644 --- a/bins/inbreeding/inspect.nu +++ b/bins/inbreeding/inspect.nu @@ -25,7 +25,8 @@ export def main [seed: int@get-seeds]: [ | select name m | update name { remove-cache-prefix - | parse $consts.FULL_EXPERIMENT_FORMAT + | parse --regex $consts.FULL_EXPERIMENT_FORMAT + | reject seed } | flatten --all name } diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu index 3c2c5cd7..894b2940 100644 --- a/bins/inbreeding/load.nu +++ b/bins/inbreeding/load.nu @@ -10,7 +10,7 @@ def get-experiments []: nothing -> list<string> { | ls $in | get name | each { remove-cache-prefix } - | parse $consts.FULL_EXPERIMENT_FORMAT + | parse --regex $consts.FULL_EXPERIMENT_FORMAT | reject timestamp strategy | each { values | str join '-' } | uniq @@ -19,7 +19,7 @@ def get-experiments []: nothing -> list<string> { export def main [ experiment: string@get-experiments, ]: nothing -> table<strategy: string, diversity: table<x: int, y: float, e: float>> { - let exp = $experiment | parse $consts.ARG_EXPERIMENT_FORMAT | into record + let exp = $experiment | parse --regex $consts.ARG_EXPERIMENT_FORMAT | into record if $exp == {} { error throw { err: "invalid experiment", @@ -47,7 +47,7 @@ export def main [ $experiment_files | select name - | insert . { get name | remove-cache-prefix | parse $consts.EXPERIMENT_FORMAT } + | insert . { get name | remove-cache-prefix | parse --regex $consts.EXPERIMENT_FORMAT } | flatten --all | insert diversity { ls $in.name -- GitLab