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
//! BigML dataset support.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use super::id::*;
use super::source::Field;
use super::status::*;
use super::{Resource, ResourceCommon, Source};

/// A BigML dataset. Basically a table of data with named columns.
///
/// TODO: Still lots of missing fields.
#[derive(Clone, Debug, Deserialize, Resource, Serialize)]
#[api_name = "dataset"]
pub struct Dataset {
    /// Common resource information. These fields will be serialized at the
    /// top-level of this structure by `serde`.
    #[serde(flatten)]
    pub common: ResourceCommon,

    /// The ID of this resource.
    pub resource: Id<Dataset>,

    /// The current status of this execution.
    pub status: GenericStatus,

    /// The number of columns in the dataset.
    pub columns: usize,

    /// Field IDs excluded when building this dataset.
    pub excluded_fields: Vec<String>,

    /// The number of fields of each type. This includes a few odd things
    /// like "preferred", so we represent it as a string.
    pub field_types: HashMap<String, u64>,

    /// Metadata describing each field. Will be empty while object is being
    /// created.
    #[serde(default)]
    pub fields: HashMap<String, Field>,

    /// Field IDs included when building this dataset.
    pub input_fields: Vec<String>,

    /// The number of rows in this dataset.
    pub rows: usize,

    /// Placeholder to allow extensibility without breaking the API.
    #[serde(skip)]
    _placeholder: (),
}

/// Arguments used to create a dataset.
#[derive(Debug, Serialize)]
pub struct Args {
    /// The ID of the BigML `Source` from which to import data.
    pub source: Id<Source>,

    /// The name of this dataset.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// User-defined tags.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub tags: Vec<String>,

    /// Placeholder to allow extensibility without breaking the API.
    #[serde(skip)]
    _placeholder: (),
}

impl Args {
    /// Create a new `Args`.
    pub fn from_source(source: Id<Source>) -> Args {
        Args {
            source,
            name: None,
            tags: vec![],
            _placeholder: (),
        }
    }
}

impl super::Args for Args {
    type Resource = Dataset;
}