//! Labels (docs/ask.feature AK6): whether a question's problem was really there in what one call sent, so the question //! can be calibrated on the person's own eye (calibrate.rs). A label belongs to a question and to the clips a call sent //! (by their hashes), never to one answer: the same question reworded, asked again of the same clips, has the same //! labels, which is what lets `raea ask try` measure new words. //! //! Where labels come from: //! - `raea ask verdict ANSWER WORD`: the person answers the question themselves, in its own terms (yes or no, an option, //! a level). Theirs counts first. //! - The feed: a note of the person's on the render (its copy in the project's feed, known by `record::ident`), pinned //! inside the window or not pinned at all, holding one of the question's label words, is a yes; an approved post (done) //! with no such note is a no. Read again by every `raea ask calibrate`. //! - Another eye (`verdict --eye agent`: an agent's own look) is kept as `eye:NAME` and never counted, as the //! fingerprint keeps another eye's readings (FP6d). use std::collections::HashMap; use std::path::{Path, PathBuf}; use raea_core_ask::{Kind, Question}; use serde::{Deserialize, Serialize}; use serde_json::Value; use crate::record; pub const FILE: &str = "labels.jsonl"; /// A note pinned at t covers 1.5 s before it to 0.5 s after (the fingerprint's span). const BEFORE: f64 = 1.5; const AFTER: f64 = 0.5; /// Whether a question's problem is there in one call's clips, and who said so. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct Label { pub question: String, /// the clips the call sent, by hash pub media: String, pub bad: bool, /// "verdict" (the person's), "note" or "approval" (read from the feed), or "eye:NAME" (kept, never counted) pub source: String, pub project: String, pub file: String, pub from: f64, pub to: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub note: Option, pub at: String, } impl Label { /// The person's own: a verdict, a note or an approval. pub fn counted(&self) -> bool { self.rank() > 0 } fn rank(&self) -> u8 { match self.source.as_str() { "verdict" => 3, "note" => 2, "approval" => 1, _ => 0, } } } /// The clips a call sent, as one key. pub fn media_key(call: &Value) -> String { let mut m: Vec<&str> = call["media"].as_array().into_iter().flatten().filter_map(Value::as_str).collect(); m.sort_unstable(); m.join("+") } /// The feed a call's render was posted to: its project's, else the nearest one above its file. fn feed_of(call: &Value) -> Option { let file = Path::new(call["file"].as_str().unwrap_or_default()); call["project"].as_str().map(Path::new).into_iter().chain(file.ancestors()).map(|d| d.join(".raea/feed")).find(|d| d.is_dir()) } /// A call's project: the folder holding its brief, else the folder holding the feed it was posted to, else its file's. pub fn project_of(call: &Value) -> String { if let Some(p) = call["project"].as_str() { return p.to_string(); } let home = feed_of(call).and_then(|f| f.parent()?.parent().map(Path::to_path_buf)); let file = Path::new(call["file"].as_str().unwrap_or_default()); home.as_deref().or(file.parent()).map(|p| p.display().to_string()).unwrap_or_default() } pub fn all() -> Vec