From a58c650a27ce1780ff21e07985bef9e47c89b4b9 Mon Sep 17 00:00:00 2001
From: STEVAN Antoine <antoine.stevan@isae-supaero.fr>
Date: Thu, 30 May 2024 13:35:39 +0000
Subject: [PATCH] and `inbreeding watch` command (dragoon/komodo!131)

## output sample
let's say the current seed is `"b239e48345ac457b492cc164f58c010d07292c88e4791e607d91796baec7f334"` and the experiment has ID `fixed:0-single:3-5-50-10240`, and that we are watching both the creation of the first experiment and a few runs, e.g.
- `002d8de28913efbf7dbd111b817ae901fee2d47882ba7aa76d293c2d95d9652c`
- `015672b37c9cf1a6b475937987294f9a503a922ffbcfdfc5d18ef839fac91b8c`
- `080a51a17ac43fcbdf08f77f3bc993983fef589bd9672f04382af4b16dd09b13`

then the output would look like
```
b239e48  fixed:0-single:3-5-50-10240            at 2024-05-30 15:24:12
b239e48  fixed:0-single:3-5-50-10240  002d8de   at 2024-05-30 15:24:14
b239e48  fixed:0-single:3-5-50-10240  015672b   at 2024-05-30 15:24:16
b239e48  fixed:0-single:3-5-50-10240  080a51a   at 2024-05-30 15:24:18
```
---
 bins/inbreeding/mod.nu   |  1 +
 bins/inbreeding/watch.nu | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 bins/inbreeding/watch.nu

diff --git a/bins/inbreeding/mod.nu b/bins/inbreeding/mod.nu
index f3bdbd9d..4059fa7c 100644
--- a/bins/inbreeding/mod.nu
+++ b/bins/inbreeding/mod.nu
@@ -1,4 +1,5 @@
 export use build.nu
+export use watch.nu
 export use run.nu
 export use inspect.nu
 export use load.nu
diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu
new file mode 100644
index 00000000..69a5bdef
--- /dev/null
+++ b/bins/inbreeding/watch.nu
@@ -0,0 +1,20 @@
+use consts.nu CACHE
+use path.nu [ "remove-cache-prefix" ]
+
+export def main [] {
+    watch $CACHE { |op, path, new_path|
+        if $op != "Create" {
+            return
+        }
+
+        let now = date now | format date "%Y-%m-%d %H:%M:%S"
+        let p = $path | remove-cache-prefix | parse "{seed}/{exp}/{id}" | into record
+
+        if $p == {} {
+            let p = $path | remove-cache-prefix | parse "{seed}/{exp}" | into record
+            return $"($p.seed | str substring 0..7)  ($p.exp)            at ($now)"
+        }
+
+        $"($p.seed | str substring 0..7)  ($p.exp)  ($p.id | str substring 0..7)   at ($now)"
+    }
+}
-- 
GitLab