Skip to content
26 changes: 17 additions & 9 deletions crates/analysis/src/tools/network_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct Network<'a> {
unit_m: f64,
snap_m: f64,
notes: Vec<String>,
/// What building it lost, with codes: segments it couldn't read.
losses: Vec<rustgis_data::loss::LossMessage>,
}

/// Reads the `network`, `costField`, `units` and `snapDistance` parameters and builds (or reuses)
Expand Down Expand Up @@ -88,19 +90,25 @@ fn network<'a>(inp: &'a dyn Inputs, p: &Json, tool: &str) -> Result<Network<'a>,
ds.name
));
}
// Left out of the network, as the route command leaves them out of its own.
let mut losses = Vec::new();
if graph.skipped_segments() > 0 {
notes.push(format!(
"{tool}: {} segment(s) of '{}' with invalid coordinates were left out of the network",
graph.skipped_segments(),
ds.name
));
losses.push(rustgis_data::loss::LossMessage {
code: rustgis_data::loss::LossCode::DroppedGeometry,
text: format!(
"{tool}: {} segment(s) of '{}' with invalid coordinates were left out of the network",
graph.skipped_segments(),
ds.name
Comment on lines +93 to +101

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The segments are now coded dropped.geometry, and that's right. But the same tool's input notes further down (lines 166-175: no usable point, several points, too far from the network) also leave features out of the run, and they stay plain. The geocoder's "no usable position" in this PR is coded dropped.feature, and the PR body's "Kept plain on purpose" list doesn't name these three. Either code them DroppedFeature the way the geocoder does, or add them to the kept-plain list with the reason.

Confidence: medium. Read from the PR body and the surrounding code; not run.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass. A point with no usable point had none to lose, and one too far from the network is the snap distance asked for. Both are listed under Kept plain. A multipoint left out could be coded with it.

),
});
}
if graph.segments() == 0 {
// What left no lines is said with it: the notes would be lost with the run.
let why = if notes.is_empty() { String::new() } else { format!(" ({})", notes.join("; ")) };
let said: Vec<&str> = notes.iter().map(String::as_str).chain(losses.iter().map(|l| l.text.as_str())).collect();
let why = if said.is_empty() { String::new() } else { format!(" ({})", said.join("; ")) };
return Err(format!("'{}' has no lines to search{why}", ds.name));
}
Ok(Network { ds, graph, unit_m, snap_m, notes })
Ok(Network { ds, graph, unit_m, snap_m, notes, losses })
}

/// The features of a point layer moved onto the network, in layer order, as (feature id, place),
Expand Down Expand Up @@ -350,7 +358,7 @@ pub(super) fn service_area(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, Str
facilities.len()
)];
messages.append(&mut net.notes);
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
Ok(ToolResult { losses: std::mem::take(&mut net.losses), output: Output::Layer(out), messages })
}

/// OD Cost Matrix: the cost and length of the cheapest way from each origin to each destination,
Expand Down Expand Up @@ -494,7 +502,7 @@ pub(super) fn od_cost_matrix_on(inp: &dyn Inputs, p: &Json, threads: Option<usiz
});
}
messages.append(&mut net.notes);
Ok(ToolResult { losses: Vec::new(), output: Output::Table(out), messages })
Ok(ToolResult { losses: std::mem::take(&mut net.losses), output: Output::Table(out), messages })
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions crates/data/src/ogc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5210,6 +5210,16 @@ pub enum Assumed {
}

impl Assumed {
/// Its loss code: `assumed.crs` when the answer is read in a system it didn't name or named
/// otherwise. An answer that named none, read in the one asked for, and one read as it named,
/// assume nothing past the request.
pub fn loss(self) -> Option<crate::loss::LossCode> {
match self {
Assumed::Unnamed | Assumed::NotDegrees => None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnamed is returned at ogc.rs:5307 when the answer names no system and its positions can't be checked against the layer's bounds. The template says those answers are "read in the system they were asked for". That is an unverified assumption about the system, which the doc comment's first clause ("a system it didn't name") would code as assumed.crs. This arm exempts it, on the reading that a request's own system is not "past the request". That reading is defensible, but it means a strict run passes an answer whose system was never checked. Could you confirm the exemption is intended, and say so in the doc comment? If it is, the doc comment's first sentence should be narrowed to match.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass: the reading is as the doc comment gives it. A request's own system is what the answer is read in, and nothing past it is assumed, as the feature-service reader reads a page.

Assumed::Unread | Assumed::InDegrees | Assumed::InAsked | Assumed::DegreesUnnamed => Some(crate::loss::LossCode::AssumedCrs),
}
}

/// Its notice, `{n}` the number of answers.
pub fn template(self) -> &'static str {
match self {
Expand Down
8 changes: 7 additions & 1 deletion crates/engine/src/circle_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,13 @@ mod tests {
s.notices.clear();
s.run("share.exportLayer", &json!({"layer":id,"path":path})).unwrap();
assert_eq!(s.notices.iter().filter(|n| n.text.starts_with("2 circle")).count(), 1);
assert_eq!(s.notices.iter().filter(|n| n.text.starts_with("1 rotated box")).count(), 1);
assert_eq!(
s.notices
.iter()
.filter(|n| n.text.starts_with("1 rotated box") && n.loss() == Some(rustgis_data::loss::LossCode::ApproximatedCurve))
.count(),
1
);
if ext == "geojson" {
let text = std::fs::read_to_string(&path).unwrap();
let j: Value = serde_json::from_str(&text).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub(crate) fn export_work(s: &Session, p: &Value) -> Result<super::exports::Work
s,
other.into_iter().map(|n| (n.severity, rustgis_data::loss::Note { loss: n.loss(), text: n.text })).collect(),
);
for note in notes.into_iter().chain(construction_notes.into_iter().map(rustgis_data::loss::Note::plain)) {
for note in notes.into_iter().chain(construction_notes) {
s.say(note);
}
spend(s, spent);
Expand Down
11 changes: 7 additions & 4 deletions crates/engine/src/cmd/geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn find_place(s: &mut Session, p: &Value) -> CmdResult {
{
let found = crate::render::rustgis_tiles::geocode::search_blocking(&g, query, limit)?;
if found.skipped > 0 {
s.warn(skipped_notice(found.skipped));
s.say(skipped_notice(found.skipped));
}
if found.limited > 0 {
s.notify(format!("Search candidates not shown: {} (limit {limit}).", found.limited), false);
Expand Down Expand Up @@ -137,8 +137,11 @@ pub fn addresses(s: &Session, p: &Value) -> Result<(Vec<String>, Vec<String>), S

/// What a run says of the places the geocoder answered with but gave no usable position for
/// (they are left out, so an address may be "not found" because of them).
pub fn skipped_notice(n: usize) -> String {
format!("{n} of the geocoder's places had no usable position (no coordinate, or an unreadable one) and were left out")
pub fn skipped_notice(n: usize) -> rustgis_data::loss::Note {
rustgis_data::loss::Note::loss(
rustgis_data::loss::LossCode::DroppedFeature,
format!("{n} of the geocoder's places had no usable position (no coordinate, or an unreadable one) and were left out"),
)
}

/// The addresses past what a run may send.
Expand Down Expand Up @@ -200,7 +203,7 @@ fn geocode(s: &mut Session, p: &Value) -> CmdResult {
check_batch(&g, distinct.len())?;
let l = lookup(&g, &distinct)?;
if l.skipped > 0 {
s.warn(skipped_notice(l.skipped));
s.say(skipped_notice(l.skipped));
}
if l.limited > 0 {
s.notify(
Expand Down
30 changes: 21 additions & 9 deletions crates/engine/src/cmd/gp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ fn inputs_of<'a>(
}
}
let mut left_out_whole = std::collections::HashSet::new();
let work = work_inputs(&snap.map, &snap.tables, spec, params, &mut full, &mut messages, &mut left_out_whole)?;
let work = work_inputs(&snap.map, &snap.tables, spec, params, &mut full, &mut messages, &mut losses, &mut left_out_whole)?;
let mut rows = env_inputs(&snap.map, &full, &snap.env, params)?;
narrow_to_queries(&snap.map, spec, params, &full, &mut rows, &mut messages)?;
let unread = if work == Crs::LonLat { std::collections::HashSet::new() } else { attributes_only(spec, params) };
Expand Down Expand Up @@ -2056,27 +2056,37 @@ fn work_inputs(
params: &Value,
full: &mut std::collections::HashMap<String, Dataset>,
messages: &mut Vec<String>,
losses: &mut Vec<LossMessage>,
left_out_whole: &mut std::collections::HashSet<String>,
) -> Result<Crs, String> {
// A loss with its code; the rest as messages.
let mut say = |said: Vec<rustgis_data::loss::Note>| {
for note in said {
match note.loss {
Some(code) => losses.push(LossMessage { code, text: note.text }),
None => messages.push(note.text),
}
}
};
let work = work_system(map, spec, params, full);
if work != Crs::LonLat {
match inputs_in(map, tables, spec, params, full, work, left_out_whole) {
Ok((converted, said)) => {
full.extend(converted);
messages.extend(said);
say(said);
return Ok(work);
}
Err(e) => {
// A Cancel isn't a place that can't be held.
rustgis_data::progress::check().map_err(|e| e.to_string())?;
let name = spec.map_or("The tool", |t| t.name);
messages.push(format!("{name} worked in longitude/latitude, not {}: {e}", work.label()));
say(vec![rustgis_data::loss::Note::plain(format!("{name} worked in longitude/latitude, not {}: {e}", work.label()))]);
}
}
}
let (converted, said) = inputs_in(map, tables, spec, params, full, Crs::LonLat, left_out_whole)?;
full.extend(converted);
messages.extend(said);
say(said);
Ok(Crs::LonLat)
}

Expand All @@ -2093,7 +2103,7 @@ fn inputs_in(
full: &std::collections::HashMap<String, Dataset>,
work: Crs,
left_out_whole: &mut std::collections::HashSet<String>,
) -> Result<(std::collections::HashMap<String, Dataset>, Vec<String>), String> {
) -> Result<(std::collections::HashMap<String, Dataset>, Vec<rustgis_data::loss::Note>), String> {
let mut converted = std::collections::HashMap::new();
// The converted inputs with edges that bend ([`bent_edges`]): name, how many, how far.
let mut bent: Vec<(String, usize, f64)> = Vec::new();
Expand Down Expand Up @@ -2212,19 +2222,21 @@ fn inputs_in(
let name = spec.map_or("The tool", |t| t.name);
let n: usize = unplaced.iter().map(|(_, n)| n).sum();
let layers = unplaced.iter().map(|(layer, n)| format!("'{layer}' ({n})")).collect::<Vec<_>>().join(", ");
said.push(format!(
// Counted over each whole layer, before the run's rows are narrowed to a selection: some may
// be rows the tool doesn't read, so it isn't a coded loss.
said.push(rustgis_data::loss::Note::plain(format!(
"{name}: {n} feature(s) of {layers} have a place that can't be given in longitude/latitude, so the tool reads them without their geometry"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-raising the wording point from the earlier thread, since the code it points at has changed and the problem remains. The notice is now plain, but its text still says the tool reads every counted feature. The count is of each whole layer, and the comment above says some of those rows aren't read. A plain notice that misstates what the run did is still a wrong notice. Suggested wording:

Suggested change
"{name}: {n} feature(s) of {layers} have a place that can't be given in longitude/latitude, so the tool reads them without their geometry"
"{name}: {n} feature(s) of {layers} have a place that can't be given in longitude/latitude, so any of them the tool reads have no geometry"

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass: the wording, now on a plain notice.

));
)));
}
if !bent.is_empty() {
let name = spec.map_or("The tool", |t| t.name);
let n: usize = bent.iter().map(|(_, n, _)| n).sum();
let far = bent.iter().map(|(.., far)| *far).fold(0.0, f64::max);
let layers = bent.iter().map(|(layer, n, _)| format!("'{layer}' ({n})")).collect::<Vec<_>>().join(", ");
said.push(format!(
said.push(rustgis_data::loss::Note::plain(format!(
"{name}: {n} edge(s) of {layers}, converted into {}, are taken straight there, up to {far:.0} m from where a run in longitude/latitude takes them (straight on a Web Mercator map); their vertices are where they were",
work.label()
));
)));
}
Ok((converted, said))
}
Expand Down
8 changes: 4 additions & 4 deletions crates/engine/src/cmd/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ fn export_3d(s: &mut Session, p: &Value) -> CmdResult {
let (bytes, report, construction_notes) = stl_bytes(s, p)?;
rustgis_data::io::write_atomic(Path::new(&path), &bytes).map_err(|e| format!("{path}: {e}"))?;
for note in construction_notes {
s.notify(note, false);
s.say(note);
}
s.retain_written_notices(written);
s.notify_written(format!("Exported {path}"));
Expand All @@ -1242,7 +1242,7 @@ fn export_3d(s: &mut Session, p: &Value) -> CmdResult {
let (obj, construction_notes) = obj_text(s, p)?;
rustgis_data::io::write_atomic(Path::new(&path), obj.as_bytes()).map_err(|e| format!("{path}: {e}"))?;
for note in construction_notes {
s.notify(note, false);
s.say(note);
}
s.retain_written_notices(written);
s.notify_written(format!("Exported {path}"));
Expand Down Expand Up @@ -1616,7 +1616,7 @@ fn ring_area(r: &[(f64, f64)]) -> f64 {
}

/// A feature layer as Wavefront OBJ text.
fn obj_text(s: &mut Session, p: &Value) -> Result<(String, Vec<String>), String> {
fn obj_text(s: &mut Session, p: &Value) -> Result<(String, Vec<rustgis_data::loss::Note>), String> {
let mesh = layer_mesh(s, p, true)?;
mesh_notices(s, &mesh);
let mut obj = String::new();
Expand Down Expand Up @@ -1709,7 +1709,7 @@ pub(crate) fn fanned_caps_note(n: usize) -> String {
}

/// A feature layer as binary STL, noting what it leaves out.
fn stl_bytes(s: &mut Session, p: &Value) -> Result<(Vec<u8>, StlReport, Vec<String>), String> {
fn stl_bytes(s: &mut Session, p: &Value) -> Result<(Vec<u8>, StlReport, Vec<rustgis_data::loss::Note>), String> {
let mesh = layer_mesh(s, p, false)?;
let (bytes, report) = mesh_stl(&mesh, MAX_STL_TRIANGLES)?;
mesh_notices(s, &mesh);
Expand Down
8 changes: 6 additions & 2 deletions crates/engine/src/cmd/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,12 +1231,16 @@ fn convert(s: &mut Session, p: &Value) -> CmdResult {
a.min_scale = min_scale;
a.max_scale = max_scale;
}
// Text cut, and labels of features it can't place, are lost from the annotation.
if let Some(note) = cut_note {
s.notify(note, false);
s.say(rustgis_data::loss::Note::loss(rustgis_data::loss::LossCode::ChangedCut, note));
}
for note in [flattened_note, repeated_note, astray_note, unplaced_note, unplaced_features_note].into_iter().flatten() {
for note in [flattened_note, repeated_note, astray_note, unplaced_note].into_iter().flatten() {
s.notify_text(note, false);
}
if let Some(note) = unplaced_features_note {
s.notify_loss(rustgis_data::loss::LossCode::DroppedFeature, note);
}
if let Some((_, unread)) = &whole {
unread.say(s);
}
Expand Down
6 changes: 5 additions & 1 deletion crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4504,7 +4504,11 @@ pub(crate) fn duckdb_parts(
origin: impl Fn(rustgis_data::source::Family) -> rustgis_map::source::DuckdbOrigin,
) -> Vec<Converted> {
if out.skipped > 0 {
s.notify(format!("{name}: {} rows without a geometry were left out", out.skipped), false);
// A row is a layer's feature: one without geometry isn't added, and its values go with it.
s.say(rustgis_data::loss::Note::loss(
rustgis_data::loss::LossCode::DroppedFeature,
format!("{name}: {} rows without a geometry were left out", out.skipped),
));
}
// Z and M values are dropped as DuckDB writes the result: one notice for all its parts.
let zm = out.parts.iter().fold(0u64, |n, p| n.saturating_add(p.zm_dropped));
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ fn write(s: &mut Session, path: PathBuf) -> CmdResult {
s.notify_written(format!("Saved {}", path.display()));
crate::durable::notify(s, &report);
for note in construction_notes {
s.notify(note, false);
s.say(note);
}
s.retain_written_notices(written);
s.path = Some(destination);
Expand Down
6 changes: 5 additions & 1 deletion crates/engine/src/cmd/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ pub(super) fn read_notices(s: &mut Session, name: &str, layer: &mut RasterLayer)
false,
);
} else {
s.notify(format!("{name}: {count} rounded as the file was read: {held}, so an export writes the rounded values"), false);
// Read whole, the count is of every value rounded.
s.say(rustgis_data::loss::Note::loss(
rustgis_data::loss::LossCode::ChangedRounded,
format!("{name}: {count} rounded as the file was read: {held}, so an export writes the rounded values"),
));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ pub fn features_answer(s: &mut Session, name: &str, url: &str, bytes: Vec<u8>, b
let (bytes, assumed) = rustgis_data::ogc::place_answer(bytes, url, bounds);
// Once per kind with a count over the command (a service group reads many answers).
if let Some(assumed) = assumed {
s.notify_counted(None, assumed.template(), 1);
s.notify_counted(assumed.loss(), assumed.template(), 1);
}
bytes
}
Expand Down
8 changes: 6 additions & 2 deletions crates/engine/src/cmd/sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,17 @@ pub fn commands() -> Vec<C> {
pub fn share_bytes(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Vec<u8>, String), String> {
let (name, bytes, source, notes) = share_output(s, kind, p)?;
for note in notes {
s.notify(note, false);
s.say(note);
}
Ok((name, bytes, source))
}

/// Shared-item construction notes are deferred when a front end still needs to deliver bytes.
pub(crate) fn share_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Vec<u8>, String, Vec<String>), String> {
pub(crate) fn share_output(
s: &mut Session,
kind: &str,
p: &Value,
) -> Result<(String, Vec<u8>, String, Vec<rustgis_data::loss::Note>), String> {
let what = match kind {
"webMap" => "The web map",
"webLayer" => "The web layer",
Expand Down
Loading
Loading