Convert a finished [`SessionAggregate`] into a `sessions` table DataRow
(
agg: SessionAggregate,
file: &TranscriptFile,
subagent_count: i64,
)
| 263 | |
| 264 | /// Convert a finished [`SessionAggregate`] into a `sessions` table DataRow |
| 265 | fn session_aggregate_to_data_row( |
| 266 | agg: SessionAggregate, |
| 267 | file: &TranscriptFile, |
| 268 | subagent_count: i64, |
| 269 | ) -> DataRow { |
| 270 | let mut map = BTreeMap::new(); |
| 271 | map.insert( |
| 272 | "session_id".to_string(), |
| 273 | Value::Str(file.session_id.clone()), |
| 274 | ); |
| 275 | if let Some(project) = &file.project { |
| 276 | map.insert("project".to_string(), Value::Str(project.clone())); |
| 277 | } |
| 278 | |
| 279 | let mut put_str = |key: &str, value: Option<String>| { |
| 280 | if let Some(value) = value { |
| 281 | map.insert(key.to_string(), Value::Str(value)); |
| 282 | } |
| 283 | }; |
| 284 | put_str("cwd", agg.cwd); |
| 285 | put_str("git_branch", agg.git_branch); |
| 286 | put_str("version", agg.version); |
| 287 | put_str("title", agg.title); |
| 288 | put_str("first_timestamp", agg.first_timestamp); |
| 289 | put_str("last_timestamp", agg.last_timestamp); |
| 290 | put_str("pr_url", agg.pr_url); |
| 291 | |
| 292 | map.insert( |
| 293 | "user_message_count".to_string(), |
| 294 | Value::I64(agg.user_message_count), |
| 295 | ); |
| 296 | map.insert( |
| 297 | "assistant_message_count".to_string(), |
| 298 | Value::I64(agg.assistant_message_count), |
| 299 | ); |
| 300 | map.insert("subagent_count".to_string(), Value::I64(subagent_count)); |
| 301 | map.insert( |
| 302 | "total_input_tokens".to_string(), |
| 303 | Value::I64(agg.total_input_tokens), |
| 304 | ); |
| 305 | map.insert( |
| 306 | "total_output_tokens".to_string(), |
| 307 | Value::I64(agg.total_output_tokens), |
| 308 | ); |
| 309 | map.insert( |
| 310 | "total_cache_read_input_tokens".to_string(), |
| 311 | Value::I64(agg.total_cache_read_input_tokens), |
| 312 | ); |
| 313 | map.insert( |
| 314 | "total_cache_creation_input_tokens".to_string(), |
| 315 | Value::I64(agg.total_cache_creation_input_tokens), |
| 316 | ); |
| 317 | if let Some(n) = agg.pr_number { |
| 318 | map.insert("pr_number".to_string(), Value::I64(n)); |
| 319 | } |
| 320 | |
| 321 | DataRow::Map(map) |
| 322 | } |