Skip to content

Commit

Permalink
post review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-prosser committed Oct 10, 2023
1 parent 5726dd9 commit c53fae8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
15 changes: 13 additions & 2 deletions api/src/resources/dataset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::{DateTime, Utc};
use ordered_float::NotNan;
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -17,7 +18,7 @@ use std::{
str::FromStr,
};

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Dataset {
pub id: Id,
pub name: Name,
Expand All @@ -34,7 +35,17 @@ pub struct Dataset {
pub entity_defs: Vec<EntityDef>,
pub label_defs: Vec<LabelDef>,
pub label_groups: Vec<LabelGroup>,
pub num_reviewed: Option<f64>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct DatasetStats {
pub num_reviewed: NotNan<f64>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct DatasetAndStats {
pub dataset: Dataset,
pub stats: DatasetStats,
}

impl Dataset {
Expand Down
30 changes: 14 additions & 16 deletions cli/src/commands/get/datasets.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::collections::HashMap;

use anyhow::{Context, Result};
use log::info;
use reinfer_client::{
resources::dataset::StatisticsRequestParams, Client, CommentFilter, DatasetIdentifier,
resources::dataset::{DatasetAndStats, DatasetStats, StatisticsRequestParams},
Client, CommentFilter, DatasetIdentifier,
};
use structopt::StructOpt;

Expand All @@ -25,7 +24,7 @@ pub fn get(client: &Client, args: &GetDatasetsArgs, printer: &Printer) -> Result
dataset,
include_stats,
} = args;
let mut datasets = if let Some(dataset) = dataset {
let datasets = if let Some(dataset) = dataset {
vec![client
.get_dataset(dataset.clone())
.context("Operation to list datasets has failed.")?]
Expand All @@ -39,7 +38,7 @@ pub fn get(client: &Client, args: &GetDatasetsArgs, printer: &Printer) -> Result
datasets
};

let mut dataset_stats: HashMap<_, _> = HashMap::new();
let mut dataset_stats = Vec::new();
if *include_stats {
datasets.iter().try_for_each(|dataset| -> Result<()> {
info!("Getting statistics for dataset {}", dataset.full_name().0);
Expand All @@ -56,18 +55,17 @@ pub fn get(client: &Client, args: &GetDatasetsArgs, printer: &Printer) -> Result
)
.context("Could not get statistics for dataset")?;

dataset_stats.insert(dataset.id.clone(), stats);
let dataset_and_stats = DatasetAndStats {
dataset: dataset.clone(),
stats: DatasetStats {
num_reviewed: stats.num_comments
}
};
dataset_stats.push(dataset_and_stats);
Ok(())
})?;

datasets.iter_mut().for_each(|dataset| {
dataset.num_reviewed = if let Some(stats) = dataset_stats.get(&dataset.id).cloned() {
Some(*stats.num_comments)
} else {
None
}
});
printer.print_resources(&dataset_stats)
} else {
printer.print_resources(&datasets)
}

printer.print_resources(&datasets)
}
32 changes: 25 additions & 7 deletions cli/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use super::thousands::Thousands;
use colored::Colorize;
use prettytable::{format, row, Row, Table};
use reinfer_client::{
resources::quota::Quota, Bucket, Dataset, Project, Source, Statistics, Stream, User,
resources::{dataset::DatasetAndStats, quota::Quota},
Bucket, Dataset, Project, Source, Statistics, Stream, User,
};
use serde::{Serialize, Serializer};

Expand Down Expand Up @@ -89,7 +90,7 @@ impl DisplayTable for Quota {

impl DisplayTable for Dataset {
fn to_table_headers() -> Row {
row![bFg => "Name", "ID", "Updated (UTC)", "Title", "Num Reviewed"]
row![bFg => "Name", "ID", "Updated (UTC)", "Title"]
}

fn to_table_row(&self) -> Row {
Expand All @@ -99,11 +100,28 @@ impl DisplayTable for Dataset {
self.id.0,
self.updated_at.format("%Y-%m-%d %H:%M:%S"),
self.title,
if let Some(num_reviewed) = &self.num_reviewed {
num_reviewed.to_string().as_str().into()
} else {
"none".dimmed()
}
]
}
}

impl DisplayTable for DatasetAndStats {
fn to_table_headers() -> Row {
row![bFg => "Name", "ID", "Updated (UTC)", "Title", "Num Reviewed"]
}

fn to_table_row(&self) -> Row {
let full_name = format!(
"{}{}{}",
self.dataset.owner.0.dimmed(),
"/".dimmed(),
self.dataset.name.0
);
row![
full_name,
self.dataset.id.0,
self.dataset.updated_at.format("%Y-%m-%d %H:%M:%S"),
self.dataset.title,
self.stats.num_reviewed
]
}
}
Expand Down

0 comments on commit c53fae8

Please sign in to comment.