github_analytics/push_data/
mod.rs

1use std::collections::HashMap;
2
3use eyre::Result;
4use influxdb::{Client, InfluxDbWriteable, WriteQuery};
5
6use crate::models::Interaction;
7
8/// Push the data to the influxdb database.
9///
10/// # Arguments
11///
12/// * `repo_infos` - A HashMap containing the interactions
13pub async fn push_data(repo_infos: &HashMap<String, Vec<Interaction>>) -> Result<()> {
14    let client = Client::new("http://localhost:8086", "test");
15    let interactions = repo_infos
16        .clone()
17        .into_values()
18        .flatten()
19        .map(|inter| inter.into_query("interaction"))
20        .collect::<Vec<WriteQuery>>();
21
22    let write_result = client.query(interactions).await;
23    write_result.unwrap();
24
25    Ok(())
26}