From 7b44a8866ffa363ce0329180a82f9c5cc95389a5 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 29 May 2024 15:09:07 +0200
Subject: [PATCH] refactor constants from `inbreeding load`

---
 bins/inbreeding/consts.nu |  4 ++++
 bins/inbreeding/load.nu   | 12 ++++--------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/bins/inbreeding/consts.nu b/bins/inbreeding/consts.nu
index 177d568c..708ac7ab 100644
--- a/bins/inbreeding/consts.nu
+++ b/bins/inbreeding/consts.nu
@@ -1,2 +1,6 @@
 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)"
diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu
index 9537b96b..c7b865e9 100644
--- a/bins/inbreeding/load.nu
+++ b/bins/inbreeding/load.nu
@@ -1,10 +1,6 @@
 use consts.nu
 use ../../.nushell error "error throw"
 
-const ARG_EXPERIMENT_FORMAT = "{seed}-{env}-{k}-{n}-{nb_bytes}"
-const EXPERIMENT_FORMAT = "{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}"
-const FULL_EXPERIMENT_FORMAT = $"{seed}(char path_sep)($EXPERIMENT_FORMAT)"
-
 def remove-cache-prefix []: path -> string {
     str replace $"($consts.CACHE)(char path_sep)" ''
 }
@@ -17,7 +13,7 @@ def get-experiments []: nothing -> list<string> {
         | ls $in
         | get name
         | each { remove-cache-prefix }
-        | parse $FULL_EXPERIMENT_FORMAT
+        | parse $consts.FULL_EXPERIMENT_FORMAT
         | reject timestamp strategy
         | each { values | str join '-' }
         | uniq
@@ -26,11 +22,11 @@ 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 $ARG_EXPERIMENT_FORMAT | into record
+    let exp = $experiment | parse $consts.ARG_EXPERIMENT_FORMAT | into record
     if $exp == {} {
         error throw {
             err: "invalid experiment",
-            label: $"should have format '($ARG_EXPERIMENT_FORMAT)', found ($experiment)",
+            label: $"should have format '($consts.ARG_EXPERIMENT_FORMAT)', found ($experiment)",
             span: (metadata $experiment).span,
         }
     }
@@ -54,7 +50,7 @@ export def main [
 
     $experiment_files
         | select name
-        | insert . { get name | remove-cache-prefix | parse $EXPERIMENT_FORMAT }
+        | insert . { get name | remove-cache-prefix | parse $consts.EXPERIMENT_FORMAT }
         | flatten --all
         | insert diversity {
             ls $in.name
-- 
GitLab