pub fn get_radar_images(&self, id: u32) -> Result { let sql = "SELECT layer_type, radar_type_id, image FROM radar_layer WHERE radar_id = (?)"; let mut stmt = self.conn.prepare(sql)?; dbg!(&sql); let mut layers = Vec::new(); let params = params![id]; let mut rows = stmt.query(params)?; while let Some(row) = rows.next()? { let layer_type: String = row.get(0)?; let radar_type_id: u8 = row.get(1)?; let layer = RadarImageFeatureLayer { feature: RadarImageFeature::from_str(&layer_type)?, radar_type: RadarType::from_id(radar_type_id as char)?, png_buf: row.get(2)?, }; layers.push(layer); } let sql = "SELECT radar_id, radar_type_id, image, timestamp FROM radar_image WHERE radar_id = (?)"; let mut stmt = self.conn.prepare(sql)?; let mut images = Vec::new(); let mut rows = stmt.query(params)?; while let Some(row) = rows.next()? { dbg!(&row); let radar_type_id: u8 = row.get(1)?; let image = RadarImageTopLayer { radar_id: row.get(0)?, radar_type: RadarType::from_id(radar_type_id as char)?, png_buf: row.get(2)?, datetime: Utc.timestamp_opt(row.get(3)?, 0).unwrap(), }; images.push(image); } dbg!(images.iter().map(|i| i.datetime).count()); let mut image_map = RadarImageMap::new(); for image in images { if !image_map.contains_key(&image.radar_type) { let images = RadarImageComponents { top_layers: Vec::new(), feature_layers: Vec::new(), legend: self.get_radar_legend(&image.radar_type)?, }; image_map.insert(image.radar_type, images); } image_map .entry(image.radar_type) .and_modify(|i| i.top_layers.push(image)); } for layer in layers { image_map .entry(layer.radar_type) .and_modify(|i| i.feature_layers.push(layer)); } dbg!(&image_map.keys()); Ok(image_map) } impl From> for Radar { fn from(row: Row) -> Self { let images: Vec = row.get(8).unwrap(); let images = bincode::deserialize(&images).unwrap(); Self { id: row.get(0).unwrap(), name: row.get(1).unwrap(), full_name: row.get(2).unwrap(), latitude: row.get(3).unwrap(), longitude: row.get(4).unwrap(), state: row.get(5).unwrap(), r#type: row.get(6).unwrap(), group: row.get(7).unwrap(), images, } } }