Skip to content

Commit

Permalink
multi selection display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhamel committed Dec 6, 2024
1 parent 027a18c commit 527f268
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/component/segment_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ async fn segment_panel_score_id(conn: &sqlx::Pool<Postgres>, id: i32, edit: bool
}
});

let geom_json = match serde_json::to_string(&[score.geom.clone()]) {
let geom_json = match serde_json::to_string(&score.geom.clone()) {
Ok(geom) => geom,
Err(e) => {
eprintln!("Error while serializing geom: {}", e);
Expand Down
28 changes: 17 additions & 11 deletions src/db/cyclability_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct CyclabilityScore {
pub way_ids: Vec<i64>,
pub created_at: DateTime<Local>,
pub photo_path_thumbnail: Option<String>,
pub geom: Vec<[f64; 2]>,
pub geom: Vec<Vec<[f64; 2]>>,
pub user_id: Option<Uuid>,
}

Expand Down Expand Up @@ -263,16 +263,23 @@ impl CyclabilityScore {

impl From<&CyclabilityScoreDb> for CyclabilityScore {
fn from(response: &CyclabilityScoreDb) -> Self {
let re = Regex::new(r"(-?\d+\.*\d*) (-?\d+\.*\d*)").unwrap();
let points = re
.captures_iter(response.geom.as_str())
.map(|cap| {
let x = cap[1].parse::<f64>().unwrap();
let y = cap[2].parse::<f64>().unwrap();
let re = Regex::new(r"(-?\d+\.\d+) (-?\d+\.\d+)").unwrap();
let mut points = Vec::new();

println!("geom {}", response.geom);
for line in response.geom.split("),(") {
let line_points = re
.captures_iter(line)
.map(|cap| {
let x = cap[1].parse::<f64>().unwrap();
let y = cap[2].parse::<f64>().unwrap();
[x, y]
})
.collect::<Vec<[f64; 2]>>();
points.push(line_points);
}
println!("points {:?}", points);

[x, y]
})
.collect::<Vec<[f64; 2]>>();
CyclabilityScore {
id: response.id,
name: response.name.clone(),
Expand All @@ -286,7 +293,6 @@ impl From<&CyclabilityScoreDb> for CyclabilityScore {
}
}
}

impl From<CyclabilityScoreDb> for CyclabilityScore {
fn from(response: CyclabilityScoreDb) -> Self {
CyclabilityScore::from(&response)
Expand Down

0 comments on commit 527f268

Please sign in to comment.