cardamon 0.0.1

Cardamon is a tool to help development teams measure the power consumption and carbon emissions of their software.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
use crate::{
    dao::{self, pagination::Page},
    entities::{iteration, metrics},
};
use itertools::{Itertools, MinMaxResult};
use sea_orm::DatabaseConnection;
use std::collections::{hash_map::Entry, HashMap};

pub enum ScenarioSelection {
    All,
    InRun(String),
    InRange { from: i64, to: i64 },
    Search(String),
}

pub enum RunSelection {
    All,
    InRange { from: i64, to: i64 },
}

/// # DatasetBuilder
///
/// The DatasetBuilder allows you to construct a Dataset. There are 2 paths you can follow to build
/// a Dataset which are useful in different uses within Cardamon. These paths exist to stop you from
/// creating an inconsistent Dataset. The sections that follow provide an explaination of each path:
///
///```text
/// [Figure 1 - DatasetBuilder flow]
///
///                         [Single scenario, page runs]
///
///                     ----- DatasetRow ----- DatasetColPager --
///                    |                                         |
/// DatasetBuilder --- +                                         + --- Dataset
///                    |                                         |
///                     -- DatasetRowPager ----- DatasetRows ----
///
///                      [Multiple scenarios, summaries results]
///```
///
/// ## 1 - Single scenario, pagination over runs
///
/// The first creates a Dataset focused on a single scenario and includes some subset of it's most
/// recent runs. This supports the use-case where a user has clicked a single scenario in the UI
/// and wants to view all the times that scenario has been run.
///
/// Example: scenario_runs_by_page("add_10_items", 3, 2)
///  ================================================================================
/// ||  scenarios   || run_1  | run_2  | run_3  |   run_4   |   run_5   |   run_6   ||
/// ||--------------||--------|--------|--------|-----------|-----------|-----------||
/// ||              ||        |        |        | ********************************* ||
/// || add_10_items || <data> | <data> | <data> | * <data>  |  <data>   |  <data> * ||
/// ||              ||        |        |        | ********************************* ||
///  ================================================================================
///
/// ## 2 - Multiple scenarios, 'n' most recent runs_all
///
/// The second creates a Dataset containining some subset of scenarios and the last 'n' times they
/// were run. This is useful when building a summary of a set of scenarios, for example when a user
/// runs cardamon from the CLI.
///
/// Example: last 3 runs of [add_10_items, add_10_users, checkout]
///  ============================================
/// ||  scenarios   || run_1  | run_2  | run_3  ||
/// ||--------------||--------------------------||
/// || add_10_items || <data> | <data> |        ||
/// || add_10_users ||        | <data> | <data> ||
/// || checkout     || <data> |        | <data> ||
///  ============================================
///
///
/// # Example uses
///
/// Example: fetch 3rd page (page size = 5) in runs for add_10_items scenario
///
///```ignore
/// DatasetBuilder::new(&dao_service)
///     .scenario("add_10_items")
///     .runs_all()
///     .page(3, 5)
///     .await?
///```
///
/// Example: fetch the 2nd page of scenarios that match "items" and summarise the last 5 runs
///
/// ```ignore
/// DatasetBuilder::new(&dao_service)
///     .scenarios_by_name("items")
///     .page(2, 5)
///     .last_n_runs(5)
///     .await?
///```
///

pub struct DatasetBuilder<'a> {
    db: &'a DatabaseConnection,
}
impl<'a> DatasetBuilder<'a> {
    pub fn new(db: &'a DatabaseConnection) -> Self {
        DatasetBuilder { db }
    }

    /// Returns a single scenario.
    pub fn scenario(&self, scenario: &str) -> DatasetRow {
        DatasetRow {
            scenario: scenario.to_string(),
            db: self.db,
        }
    }

    /// Returns all scenarios.
    pub fn scenarios_all(&self) -> DatasetRowPager {
        DatasetRowPager {
            scenario_selection: ScenarioSelection::All,
            db: self.db,
        }
    }

    /// Returns all scenarios that were executed in a single run.
    pub fn scenarios_in_run(&self, run: i32) -> DatasetRowPager {
        DatasetRowPager {
            scenario_selection: ScenarioSelection::InRun(run.to_string()),
            db: self.db,
        }
    }

    /// Returns all scenarios that were executed at some time within the given time range.
    ///
    /// * Arguments
    /// - from: unix timestamp in millis
    /// - to: unix timestamp n millis
    pub fn scenarios_in_range(&self, from: i64, to: i64) -> DatasetRowPager {
        DatasetRowPager {
            scenario_selection: ScenarioSelection::InRange { from, to },
            db: self.db,
        }
    }

    /// Returns a DatasetRowPager all scenarios that match the given name. This function does not fetch these
    /// scenarios, it just defines the maximum set of scenarios which can be filtered in subsequent
    /// steps.
    pub fn scenarios_by_name(&self, name: &str) -> DatasetRowPager {
        DatasetRowPager {
            scenario_selection: ScenarioSelection::Search(name.to_string()),
            db: self.db,
        }
    }
}

/// The DatasetRowPager defines an incomplete Dataset which includes set of scenarios (rows)
/// without any runs.
///
/// It provides functions to select a subset within that range of scenarios.
pub struct DatasetRowPager<'a> {
    scenario_selection: ScenarioSelection,
    db: &'a DatabaseConnection,
}
impl<'a> DatasetRowPager<'a> {
    /// Returns a DatasetRows object which defined the full set of scenarios defined by this
    /// DatasetRowPager.
    pub fn all(self) -> DatasetRows<'a> {
        DatasetRows {
            scenario_selection: self.scenario_selection,
            scenario_page: None,
            db: self.db,
        }
    }

    /// Returns a DatasetRows object which defines a subset of the scenarios defined by this
    /// DatasetRowPager.
    pub fn page(self, page_size: u64, page_num: u64) -> DatasetRows<'a> {
        let scenario_page = Page {
            size: page_size,
            num: page_num,
        };

        DatasetRows {
            scenario_selection: self.scenario_selection,
            scenario_page: Some(scenario_page),
            db: self.db,
        }
    }
}

/// The DatasetRows defines an incomplete Dataet defining a set of scenarios (rows) without any
/// runs. This contains an optional Page object which defines some subset of this set of scenarios.
/// If no Page is provided then DatasetRows defines the full range of scenarios instead of a single
/// page within it.
///
/// Example: page 2 (page size = 2) of the rows containing 4 scenarios.
///  ================================
/// ||     scenarios    || runs ... ||
/// ||------------------||----------||
/// ||   add_10_items   ||          ||
/// ||   add_10_users   ||          ||
/// || **************** ||    ...   ||
/// || * checkout     * ||          ||
/// || * search_item  * ||          ||
/// || **************** ||          ||
///  ================================
///
pub struct DatasetRows<'a> {
    scenario_selection: ScenarioSelection,
    scenario_page: Option<Page>,
    db: &'a DatabaseConnection,
}
impl<'a> DatasetRows<'a> {
    /// Returns a Dataset which contains the iterations and metrics collected in the last 'n' runs
    /// of each scenario.
    ///
    /// This function is async as it uses the dao_service to fetch the results from the db.
    pub async fn last_n_runs(&self, n: u64) -> anyhow::Result<Dataset> {
        let scenarios = match &self.scenario_selection {
            ScenarioSelection::All => dao::scenario::fetch_all(&self.scenario_page, self.db).await,
            ScenarioSelection::Search(name) => {
                dao::scenario::fetch_by_name(name, &self.scenario_page, self.db).await
            }
            ScenarioSelection::InRun(run) => {
                dao::scenario::fetch_in_run(run, &self.scenario_page, self.db).await
            }
            ScenarioSelection::InRange { from, to } => {
                dao::scenario::fetch_in_range(*from, *to, &self.scenario_page, self.db).await
            }
        }?;

        // for each scenario get the associated iterations in the last n runs
        let mut iterations = vec![];
        for scenario in scenarios {
            let scenario_iterations =
                dao::iteration::fetch_runs_last_n(&scenario.scenario_name, n, self.db).await?;
            iterations.extend(scenario_iterations);
        }

        // marry up iterations with metrics
        // TODO: read from cache table first
        let mut iterations_with_metrics = vec![];
        for it in iterations {
            let metrics =
                dao::metrics::fetch_within(it.run_id, it.start_time, it.stop_time, self.db).await?;
            iterations_with_metrics.push(IterationWithMetrics::new(it, metrics));
        }

        // TODO: cache the iterations/metrics data

        Ok(Dataset::new(iterations_with_metrics))
    }
}

/// The DatasetRow defines an incomplete Dataset with a single scenario (row) without any runs.
/// This object provides functions for defining a range of runs to include for the scenario.
pub struct DatasetRow<'a> {
    scenario: String,
    db: &'a DatabaseConnection,
}
impl<'a> DatasetRow<'a> {
    /// Return a DataColPager which includes all the runs for this scenario.
    pub fn runs_all(self) -> DatasetColPager<'a> {
        DatasetColPager {
            scenario: self.scenario,
            run_selection: RunSelection::All,
            db: self.db,
        }
    }

    /// Return a DatasetColPager which includes only those runs which were executed within the
    /// given time range.
    ///
    /// * Arguments
    /// - from: unix timestamp in millis
    /// - to: unix timestamp in millis
    pub fn runs_in_range(self, from: i64, to: i64) -> DatasetColPager<'a> {
        DatasetColPager {
            scenario: self.scenario,
            run_selection: RunSelection::InRange { from, to },
            db: self.db,
        }
    }
}

/// The DatasetColPager defines an incomplete Dataset which includes a single scenario (row) and
/// range of runs for that scenario.
///
/// It provides a single function to select a single page within that range of runs.
pub struct DatasetColPager<'a> {
    scenario: String,
    run_selection: RunSelection,
    db: &'a DatabaseConnection,
}
impl<'a> DatasetColPager<'a> {
    pub async fn page(&self, page_size: u64, page_num: u64) -> anyhow::Result<Dataset> {
        let page = Page::new(page_size, page_num);

        let iterations = match self.run_selection {
            RunSelection::All => {
                dao::iteration::fetch_runs_all(&self.scenario, &Some(page), self.db).await
            }

            RunSelection::InRange { from, to } => {
                dao::iteration::fetch_runs_in_range(&self.scenario, from, to, &Some(page), self.db)
                    .await
            }
        }?;

        // marry up iterations with metrics
        // TODO: read from cache table first
        let mut iterations_with_metrics = vec![];
        for it in iterations {
            let metrics =
                dao::metrics::fetch_within(it.run_id, it.start_time, it.stop_time, self.db).await?;
            iterations_with_metrics.push(IterationWithMetrics::new(it, metrics));
        }

        // TODO: cache the iterations/metrics data
        //

        Ok(Dataset::new(iterations_with_metrics))
    }
}

// ////////////////////////////////////////////////////////////////////////////////////////////////
//  DATASET
//  ///////////////////////////////////////////////////////////////////////////////////////////////

/// Associates a single ScenarioIteration with all the metrics captured for it.
#[derive(Debug)]
pub struct IterationWithMetrics {
    iteration: iteration::Model,
    metrics: Vec<metrics::Model>,
}
impl IterationWithMetrics {
    pub fn new(iteration: iteration::Model, metrics: Vec<metrics::Model>) -> Self {
        Self { iteration, metrics }
    }

    pub fn iteration(&self) -> &iteration::Model {
        &self.iteration
    }

    pub fn metrics(&self) -> &[metrics::Model] {
        &self.metrics
    }

    pub fn accumulate_by_process(&self) -> Vec<ProcessMetrics> {
        let mut metrics_by_process: HashMap<String, Vec<&metrics::Model>> = HashMap::new();
        for metric in self.metrics.iter() {
            let proc_id = metric.process_id.clone();
            metrics_by_process
                .entry(proc_id)
                .and_modify(|v| v.push(metric))
                .or_insert(vec![metric]); // if entry doesn't exist then create a new vec
        }

        metrics_by_process
            .into_iter()
            .map(|(process_id, metrics)| {
                let cpu_usage_minmax = metrics.iter().map(|m| m.cpu_usage).minmax();
                let cpu_usage_total = metrics.iter().fold(0.0, |acc, m| acc + m.cpu_usage);
                let cpu_usage_mean = cpu_usage_total / metrics.len() as f64;

                ProcessMetrics {
                    process_id,
                    cpu_usage_minmax,
                    cpu_usage_mean,
                    cpu_usage_total,
                }
            })
            .collect()
    }
}

/// Read-only struct containing metrics for a single process.
#[derive(Debug)]
pub struct ProcessMetrics {
    process_id: String,
    cpu_usage_minmax: MinMaxResult<f64>,
    cpu_usage_mean: f64,
    cpu_usage_total: f64,
}
impl ProcessMetrics {
    pub fn process_id(&self) -> &str {
        &self.process_id
    }

    pub fn cpu_usage_minmax(&self) -> &MinMaxResult<f64> {
        &self.cpu_usage_minmax
    }

    pub fn cpu_usage_mean(&self) -> f64 {
        self.cpu_usage_mean
    }

    pub fn cpu_usage_total(&self) -> f64 {
        self.cpu_usage_total
    }
}

/// Data in cardamon is organised as a table. Each row is a scenario and each column is a run
/// of that scenario.
///
/// Example: Dataset containing the most recent 3 runs of 3 different scenarios.
///  ============================================
/// ||  scenarios   || run_1  | run_2  | run_3  ||
/// ||--------------||--------------------------||
/// || add_10_items || <data> | <data> |        ||
/// || add_10_users ||        | <data> | <data> ||
/// || checkout     || <data> |        | <data> ||
///  ============================================
///
/// Example: Dataset containing the 2nd page of runs for the `add_10_items` scenario.
///  ================================================================================
/// ||  scenarios   || run_1  | run_2  | run_3  |   run_4   |   run_5   |   run_6   ||
/// ||--------------||--------|--------|--------|-----------|-----------|-----------||
/// ||              ||        |        |        | ********************************* ||
/// || add_10_items || <data> | <data> | <data> | * <data>  |  <data>   |  <data> * ||
/// ||              ||        |        |        | ********************************* ||
///  ================================================================================
///
pub struct Dataset {
    data: Vec<IterationWithMetrics>,
}
impl<'a> Dataset {
    pub fn new(data: Vec<IterationWithMetrics>) -> Self {
        Self { data }
    }

    pub fn data(&'a self) -> &'a [IterationWithMetrics] {
        &self.data
    }

    pub fn by_scenario(&'a self) -> Vec<ScenarioDataset<'a>> {
        // get all the scenarios in the dataset
        let scenario_names = self
            .data
            .iter()
            .map(|x| &x.iteration.scenario_name)
            .unique()
            .collect::<Vec<_>>();

        scenario_names
            .into_iter()
            .map(|scenario_name| {
                let data = self
                    .data
                    .iter()
                    .filter(|x| &x.iteration.scenario_name == scenario_name)
                    .collect::<Vec<_>>();

                ScenarioDataset {
                    scenario_name,
                    data,
                }
            })
            .collect::<Vec<_>>()
    }
    /// Returns the total number of unique scenarios in the dataset
    pub fn total_unique_scenarios(&self) -> usize {
        self.data
            .iter()
            .map(|x| &x.iteration.scenario_name)
            .collect::<std::collections::HashSet<_>>()
            .len()
    }
    /// Returns a paginated list of unique scenarios
    pub fn paginated_unique_scenarios(&self, page: u32, limit: u32) -> Vec<String> {
        let unique_scenarios: Vec<String> = self
            .data
            .iter()
            .map(|x| x.iteration.scenario_name.clone())
            .collect::<std::collections::HashSet<_>>()
            .into_iter()
            .collect();

        let total_items = unique_scenarios.len();
        let start = (page * limit) as usize;

        if start >= total_items {
            return Vec::new(); // Return an empty vector if start index is out of bounds
        }

        let end = std::cmp::min(start + limit as usize, total_items);
        unique_scenarios[start..end].to_vec()
    }

    /// Returns the last N runs for a specific scenario
    pub fn last_n_runs_for_scenario(
        &self,
        scenario_name: &str,
        n: usize,
    ) -> Vec<&IterationWithMetrics> {
        self.data
            .iter()
            .filter(|x| x.iteration.scenario_name == scenario_name)
            .collect::<Vec<_>>()
            .into_iter()
            .rev()
            .take(n)
            .collect()
    }

    /// Returns the total number of pages given a limit per page
    pub fn total_pages(&self, limit: u32) -> u32 {
        let total_scenarios = self.total_unique_scenarios() as u32;
        (total_scenarios as f64 / limit as f64).ceil() as u32
    }
}

/// Dataset containing data associated with a single scenario but potentially containing data
/// taken from multiple cardamon runs.
///
/// Guarenteed to contain only data associated with a single scenario.
#[derive(Debug)]
pub struct ScenarioDataset<'a> {
    scenario_name: &'a str,
    data: Vec<&'a IterationWithMetrics>,
}
impl<'a> ScenarioDataset<'a> {
    pub fn scenario_name(&'a self) -> &'a str {
        self.scenario_name
    }

    pub fn data(&'a self) -> &'a [&'a IterationWithMetrics] {
        &self.data
    }

    pub fn by_run(&'a self) -> Vec<RunDataset<'a>> {
        let runs = self
            .data
            .iter()
            .map(|x| &x.iteration.run_id)
            .unique()
            .collect::<Vec<_>>();

        runs.into_iter()
            .map(|run_id| {
                let data = self
                    .data
                    .iter()
                    .filter(|x| &x.iteration.run_id == run_id)
                    .cloned()
                    .collect::<Vec<_>>();

                RunDataset {
                    scenario_name: self.scenario_name,
                    run_id: *run_id,
                    data,
                }
            })
            .collect::<Vec<_>>()
    }
}

/// Dataset containing data associated with a single scenario in a single cardamon run but
/// potentially containing data taken from multiple scenario iterations.
///
/// Guarenteed to contain only data associated with a single scenario and cardamon run.
#[derive(Debug)]
pub struct RunDataset<'a> {
    scenario_name: &'a str,
    run_id: i32,
    data: Vec<&'a IterationWithMetrics>,
}
impl<'a> RunDataset<'a> {
    pub fn scenario_name(&'a self) -> &'a str {
        self.scenario_name
    }

    pub fn run_id(&'a self) -> i32 {
        self.run_id
    }

    pub fn by_iterations(&'a self) -> &'a [&'a IterationWithMetrics] {
        &self.data
    }

    pub fn averaged(&'a self) -> Vec<ProcessMetrics> {
        let all_process_metrics = self
            .data
            .iter()
            .flat_map(|i| i.accumulate_by_process())
            .collect::<Vec<_>>();

        let mut process_metrics_to_iterations: HashMap<String, Vec<ProcessMetrics>> =
            HashMap::new();
        for process_metrics in all_process_metrics.into_iter() {
            let proc_id = process_metrics.process_id.clone();
            let entry = process_metrics_to_iterations.entry(proc_id);
            match entry {
                Entry::Occupied(_) => {
                    entry.and_modify(|v| v.push(process_metrics));
                }
                Entry::Vacant(_) => {
                    entry.or_insert(vec![process_metrics]);
                }
            }
        }

        // average across iterations
        process_metrics_to_iterations
            .into_iter()
            .flat_map(|(_, process_metrics)| {
                process_metrics.into_iter().reduce(|a, b| {
                    let a_minmax = match a.cpu_usage_minmax {
                        MinMaxResult::NoElements => None,
                        MinMaxResult::OneElement(val) => Some((val, val)),
                        MinMaxResult::MinMax(min, max) => Some((min, max)),
                    };
                    let b_minmax = match b.cpu_usage_minmax {
                        MinMaxResult::NoElements => None,
                        MinMaxResult::OneElement(val) => Some((val, val)),
                        MinMaxResult::MinMax(min, max) => Some((min, max)),
                    };

                    let cpu_usage_minmax = if a_minmax.is_some() && b_minmax.is_some() {
                        let (a_min, a_max) = a_minmax.unwrap();
                        let (b_min, b_max) = b_minmax.unwrap();
                        MinMaxResult::MinMax(a_min + b_min / 2.0, a_max + b_max / 2.0)
                    } else {
                        MinMaxResult::NoElements
                    };

                    ProcessMetrics {
                        process_id: a.process_id,
                        cpu_usage_minmax,
                        cpu_usage_mean: a.cpu_usage_mean + b.cpu_usage_mean / 2.0,
                        cpu_usage_total: a.cpu_usage_total + b.cpu_usage_total / 2.0,
                    }
                })
            })
            .collect::<Vec<_>>()
    }
}

#[cfg(test)]
mod tests {
    //     use crate::dao::{DataAccessService, LocalDataAccessService};
    //     use sqlx::SqlitePool;
    //
    //     #[sqlx::test(
    //         migrations = "./migrations",
    //         fixtures(
    //             "../fixtures/runs.sql",
    //             "../fixtures/scenario_iterations.sql",
    //             "../fixtures/cpu_metrics.sql"
    //         )
    //     )]
    //     async fn datasets_work(pool: SqlitePool) -> anyhow::Result<()> {
    //         let dao_service = LocalDataAccessService::new(pool.clone());
    //         let observation_dataset = dao_service
    //             .fetch_observation_dataset(vec!["scenario_2"], 2)
    //             .await?;
    //
    //         assert_eq!(observation_dataset.data().len(), 4);
    //
    //         let scenario_datasets = observation_dataset.by_scenario();
    //         assert_eq!(scenario_datasets.len(), 1);
    //
    //         for scenario_dataset in scenario_datasets.iter() {
    //             // println!("{:?}", scenario_dataset);
    //             let run_datasets = scenario_dataset.by_run();
    //             assert_eq!(run_datasets.len(), 2);
    //
    //             for run_dataset in run_datasets.iter() {
    //                 // println!("{:?}", run_dataset);
    //                 let avg = run_dataset.averaged();
    //                 assert_eq!(avg.len(), 2);
    //             }
    //         }
    //
    //         pool.close().await;
    //         Ok(())
    //     }
}