• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

diffed-places / pipeline / 26360792955

24 May 2026 12:06PM UTC coverage: 93.495% (-0.7%) from 94.237%
26360792955

push

github

web-flow
Compute spatial distance for place matching (#263)

13 of 40 new or added lines in 1 file covered. (32.5%)

3205 of 3428 relevant lines covered (93.49%)

228.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.25
/src/diff_places.rs
1
use crate::places::{Place, PlaceIndex};
2
use crate::s2_util::MergedCellRanges;
3
use crate::{make_progress_bar, match_distance};
4
use anyhow::Result;
5
use indicatif::MultiProgress;
6
use rayon::prelude::*;
7
use s2::{cap::Cap, cell::Cell, cellid::CellID, region::RegionCoverer};
8
use std::path::{Path, PathBuf};
9
use std::sync::atomic::{AtomicU64, Ordering};
10

11
pub fn diff_places(
1✔
12
    _coverage: &Path,
1✔
13
    atp: &Path,
1✔
14
    osm: &Path,
1✔
15
    progress: &MultiProgress,
1✔
16
    workdir: &Path,
1✔
17
) -> Result<PathBuf> {
1✔
18
    assert!(workdir.exists());
1✔
19

20
    let out_path = workdir.join("diff.parquet");
1✔
21
    if out_path.exists() {
1✔
22
        return Ok(out_path);
×
23
    }
1✔
24

25
    // TODO: Open out_path for writing.
26

27
    let coverer = RegionCoverer {
1✔
28
        max_cells: 16,
1✔
29
        min_level: 12,
1✔
30
        max_level: s2::cellid::MAX_LEVEL as u8,
1✔
31
        level_mod: 1,
1✔
32
    };
1✔
33
    let atp_places = PlaceIndex::open(atp, 1)?;
1✔
34
    let num_atp_places = atp_places.total_rows() as u64;
1✔
35
    let progress_bar = make_progress_bar(progress, "diff     ", num_atp_places, "features");
1✔
36
    let osm_places = PlaceIndex::open(osm, 32)?;
1✔
37

38
    let num_atp_features = AtomicU64::new(0);
1✔
39
    let num_candidates = AtomicU64::new(0);
1✔
40

41
    // TODO: Use this to parallelize, once we have the matching logic in place.
42
    let _ = atp_places.scan().par_bridge(); // .try_for_each(|place| {}
1✔
43

44
    let region = CellID::from_token("479ab6e4"); // Rapperswil SG, Switzerland
1✔
45
    atp_places
1✔
46
        .query(
1✔
47
            region.range_min()..=region.range_max(),
1✔
48
            crate::MatchMask::SHOP,
1✔
49
        )?
1✔
50
        //.par_bridge()
51
        .try_for_each(|place| {
1✔
NEW
52
            let place = place?;
×
NEW
53
            num_atp_features.fetch_add(1, Ordering::Relaxed);
×
NEW
54
            println!(
×
55
                "\n*** Find best match for AllThePlaces feature: {:?}",
56
                place
57
            );
NEW
58
            let s2_cell = Cell::from(CellID(place.s2_cell_id));
×
NEW
59
            let center = s2_cell.center();
×
NEW
60
            let radius = match_distance(&place.mask);
×
NEW
61
            let cap = Cap::from_center_chordangle(&center, &radius);
×
NEW
62
            let covering = coverer.covering(&cap);
×
NEW
63
            for (lo, hi) in MergedCellRanges::new(covering) {
×
NEW
64
                for candidate in osm_places.query(lo..=hi, place.mask)? {
×
NEW
65
                    let candidate = candidate?;
×
NEW
66
                    num_candidates.fetch_add(1, Ordering::Relaxed);
×
NEW
67
                    let candidate_center =
×
NEW
68
                        s2::point::Point(CellID(candidate.s2_cell_id).raw_point().normalize());
×
NEW
69
                    let distance =
×
NEW
70
                        (center.distance(&candidate_center).rad() * 6_371_000.0 + 0.5) as i32;
×
NEW
71
                    if let Some(score) = match_places(&place, &candidate, distance) {
×
NEW
72
                        println!(
×
NEW
73
                            "  - {:?} distance: {} meters, score: {}",
×
NEW
74
                            candidate, distance, score
×
NEW
75
                        );
×
NEW
76
                    }
×
77
                    // TODO: Compute match score between candidate and place.
78
                }
79
            }
80
            // progress_bar.inc(1);
NEW
81
            Ok::<(), anyhow::Error>(())
×
NEW
82
        })?;
×
83

84
    progress_bar.finish_with_message(format!(
1✔
85
        "{} atp features, {} osm candidates",
86
        num_atp_features.load(Ordering::SeqCst),
1✔
87
        num_candidates.load(Ordering::SeqCst)
1✔
88
    ));
89

90
    Ok(out_path)
1✔
91
}
1✔
92

93
// TODO: Implement.
NEW
94
fn match_places(_a: &Place, _b: &Place, _distance_meters: i32) -> Option<f64> {
×
NEW
95
    Some(1.0)
×
NEW
96
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc