csv update
This commit is contained in:
@@ -2239,7 +2239,12 @@ pub async fn export_assets(
|
|||||||
}
|
}
|
||||||
"csv" => {
|
"csv" => {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
s.push_str("id,row_id,asset_type,asset_name,video_name,side,in_scope,deleted,modified,lat,lng,start_lat,start_lng,end_lat,end_lng,link_pair_id,link_locked,image_path,image_path1,image_path2,image_path3\n");
|
// Bbox columns are appended after the existing schema so older
|
||||||
|
// spreadsheets that anchor on the first 21 columns keep working.
|
||||||
|
// Each row populates only the slots its asset_type uses (fixed
|
||||||
|
// assets fill the unprefixed `bbox_*`, range assets fill
|
||||||
|
// `start_/mid_/end_bbox_*`); unused slots stay empty.
|
||||||
|
s.push_str("id,row_id,asset_type,asset_name,video_name,side,in_scope,deleted,modified,lat,lng,start_lat,start_lng,end_lat,end_lng,link_pair_id,link_locked,image_path,image_path1,image_path2,image_path3,bbox_x1,bbox_y1,bbox_x2,bbox_y2,start_bbox_x1,start_bbox_y1,start_bbox_x2,start_bbox_y2,mid_bbox_x1,mid_bbox_y1,mid_bbox_x2,mid_bbox_y2,end_bbox_x1,end_bbox_y1,end_bbox_x2,end_bbox_y2\n");
|
||||||
let csv_q = |v: Option<&str>| -> String {
|
let csv_q = |v: Option<&str>| -> String {
|
||||||
let s = v.unwrap_or("");
|
let s = v.unwrap_or("");
|
||||||
if s.contains(',') || s.contains('"') || s.contains('\n') {
|
if s.contains(',') || s.contains('"') || s.contains('\n') {
|
||||||
@@ -2250,9 +2255,20 @@ pub async fn export_assets(
|
|||||||
};
|
};
|
||||||
let f = |o: Option<f64>| o.map(|v| v.to_string()).unwrap_or_default();
|
let f = |o: Option<f64>| o.map(|v| v.to_string()).unwrap_or_default();
|
||||||
let i = |o: Option<i64>| o.map(|v| v.to_string()).unwrap_or_default();
|
let i = |o: Option<i64>| o.map(|v| v.to_string()).unwrap_or_default();
|
||||||
|
let bb = |o: Option<&(f64, f64, f64, f64)>| -> String {
|
||||||
|
match o {
|
||||||
|
Some((x1, y1, x2, y2)) => format!("{},{},{},{}", x1, y1, x2, y2),
|
||||||
|
None => ",,,".to_string(),
|
||||||
|
}
|
||||||
|
};
|
||||||
for a in &assets {
|
for a in &assets {
|
||||||
|
let slots = bbox_by_asset_all.get(&a.id);
|
||||||
|
let bb_fixed = slots.and_then(|m| m.get("fixed"));
|
||||||
|
let bb_start = slots.and_then(|m| m.get("start"));
|
||||||
|
let bb_mid = slots.and_then(|m| m.get("mid"));
|
||||||
|
let bb_end = slots.and_then(|m| m.get("end"));
|
||||||
s.push_str(&format!(
|
s.push_str(&format!(
|
||||||
"{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}\n",
|
"{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}\n",
|
||||||
a.id,
|
a.id,
|
||||||
csv_q(Some(&a.row_id)),
|
csv_q(Some(&a.row_id)),
|
||||||
a.asset_type,
|
a.asset_type,
|
||||||
@@ -2274,6 +2290,10 @@ pub async fn export_assets(
|
|||||||
csv_q(a.image_path1.as_deref()),
|
csv_q(a.image_path1.as_deref()),
|
||||||
csv_q(a.image_path2.as_deref()),
|
csv_q(a.image_path2.as_deref()),
|
||||||
csv_q(a.image_path3.as_deref()),
|
csv_q(a.image_path3.as_deref()),
|
||||||
|
bb(bb_fixed),
|
||||||
|
bb(bb_start),
|
||||||
|
bb(bb_mid),
|
||||||
|
bb(bb_end),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
|
|||||||
Reference in New Issue
Block a user