Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

DR3: the older commands' JSON reads as a Finding (Finding::of_value), and scene lint's findings are read through it

shinyobjectzebce4f28ab6c
diff --git a/core/facts/src/finding.rs b/core/facts/src/finding.rs
index 3bbe4f41..ab1b8a30 100644
--- a/core/facts/src/finding.rs
+++ b/core/facts/src/finding.rs
@@ -107,6 +107,28 @@ impl Finding {
self
}
+ /// A finding in the JSON the older commands write (`{check, level, says}` and what it is about: `part`, `into`,
+ /// `on`, `file`; scene lint, gen check, solid info): None for "ok", a pass. A `fix` that is an object says its
+ /// command (`run`) or else itself as JSON.
+ pub fn of_value(v: &serde_json::Value, by: &str) -> Option<Finding> {
+ let word = v["level"].as_str().unwrap_or("");
+ if word == "ok" {
+ return None;
+ }
+ let mut f = Finding::new(v["check"].as_str().unwrap_or(by), Level::of_word(word), v["says"].as_str().unwrap_or_default(), by);
+ for k in ["part", "into", "on", "file"] {
+ if let Some(name) = v[k].as_str() {
+ f = f.about(name, None);
+ }
+ }
+ f.fix = match &v["fix"] {
+ serde_json::Value::String(s) => Some(s.clone()),
+ o if o.is_object() => Some(o["run"].as_str().map_or_else(|| o.to_string(), str::to_string)),
+ _ => None,
+ };
+ Some(f)
+ }
+
/// One line: `error clips frames 120-139 seat, rider: the rider is 4 cm into the seat (fix: …)`.
pub fn line(&self) -> String {
let mut s = format!("{:<5} {}", self.level.word(), self.check);
@@ -177,6 +199,15 @@ mod tests {
assert_eq!(serde_json::from_value::<Finding>(j).unwrap(), f);
}
+ #[test]
+ fn the_older_commands_json_reads_as_findings_and_a_pass_as_none() {
+ let v = serde_json::json!({"check": "format", "level": "error", "file": "chair.fbx", "says": "raea loads glTF", "fix": {"run": "raea blender run convert.py"}});
+ let f = Finding::of_value(&v, "raea gen check").unwrap();
+ assert_eq!((f.level, f.about[0].name.as_str(), f.fix.as_deref()), (Level::Error, "chair.fbx", Some("raea blender run convert.py")));
+ assert_eq!(Finding::of_value(&serde_json::json!({"check": "expect.volume", "level": "warning", "says": "s", "fix": {"scale": 2}}), "x").unwrap().fix.as_deref(), Some("{\"scale\":2}"));
+ assert_eq!(Finding::of_value(&serde_json::json!({"check": "expect.volume", "level": "ok", "says": "within"}), "x"), None);
+ }
+
#[test]
fn findings_rank_worst_first_and_count() {
let fs = vec![Finding::new("a", Level::Note, "n", "x"), Finding::new("b", Level::Error, "e", "x"), Finding::new("c", Level::Warn, "w", "x")];
diff --git a/docs/direction.feature b/docs/direction.feature
index f0caae1a..839330ec 100644
--- a/docs/direction.feature
+++ b/docs/direction.feature
@@ -222,7 +222,7 @@ Feature: Direction that holds: one world of facts, findings and rules, so a pers
Scenario: DR3. One finding, for every command
Given the plan
| crate | file | lines | job |
- | raea-core-facts | core/facts/src/finding.rs | 200 | Finding, its JSON, its one-line text; the two old ranks mapped onto it |
+ | raea-core-facts | core/facts/src/finding.rs | 240 | Finding, its JSON, its one-line text; the two old ranks and the older commands' JSON read as it |
| raea-sys-contact | systems/contact/src/found.rs | 140 | the clipping check's and the lint's results as Findings about entities |
| raea-app-check | apps/check/src/lib.rs | 240 | raea check's Issue as Finding in its report (rule -> check, p -> level, at -> frames) |
# Fixed in the code (DR3): the plan gave raea check's Issue -> Finding a file of 150 lines in apps/direction. It is
diff --git a/systems/contact/src/found.rs b/systems/contact/src/found.rs
index 76f3cc78..8737065b 100644
--- a/systems/contact/src/found.rs
+++ b/systems/contact/src/found.rs
@@ -10,17 +10,13 @@ use serde_json::Value;
pub fn lint_findings(found: &[Value], frame: i64, by: &str) -> Vec<Finding> {
found
.iter()
- .filter(|v| v["level"].as_str().is_some_and(|l| l != "ok"))
- .map(|v| {
- let check = v["check"].as_str().unwrap_or("lint");
- let mut f = Finding::new(check, Level::of_word(v["level"].as_str().unwrap_or("")), v["says"].as_str().unwrap_or_default(), by).frames(frame, frame + 1);
- for k in ["part", "into", "on"] {
- if let Some(name) = v[k].as_str() {
- f = f.about(name, None);
- }
- }
+ .filter_map(|v| {
+ let mut f = Finding::of_value(v, by)?.frames(frame, frame + 1);
+ // the lint's fix is a move, said below
+ f.fix = None;
+ let check = f.check.clone();
let num = |k: &str| v[k].as_f64();
- if let Some(g) = num("gap").filter(|_| matches!(check, "sunk" | "floats")) {
+ if let Some(g) = num("gap").filter(|_| matches!(check.as_str(), "sunk" | "floats")) {
f = f.measure("gap", g, "m", None);
} else if let Some(d) = num("depth") {
f = f.measure("depth", d, "m", None);
@@ -30,7 +26,7 @@ pub fn lint_findings(found: &[Value], frame: i64, by: &str) -> Vec<Finding> {
if let Some((y, dy)) = v.get("fix").and_then(|x| Some((x.get("y")?.as_f64()?, x.get("dy")?.as_f64()?))) {
f = f.fix(format!("move it {dy:+.4} m in y, to y = {y}"));
}
- f
+ Some(f)
})
.collect()
}