DataType

Enum DataType 

Source
pub enum DataType {
Show 35 variants EA(Vec<f32>), EL(Vec<f32>), ER(Vec<f32>), PI(Vec<u32>), PR(Vec<u32>), PG(Vec<u32>), T0(Vec<f32>), T1(Vec<f32>), TH(Vec<f32>), AX(Vec<f32>), AY(Vec<f32>), AZ(Vec<f32>), GX(Vec<f32>), GY(Vec<f32>), GZ(Vec<f32>), MX(Vec<i32>), MY(Vec<i32>), MZ(Vec<i32>), BV(Vec<f32>), BATLV(Vec<u32>), AK(Vec<String>), RD(Vec<String>), TL(String), TX(Vec<String>), TxTlLc((String, f32)), TxLcLm(Vec<f32>), EM(Vec<String>), HR(Vec<i32>), BI(Vec<i32>), SA(Vec<f32>), SF(Vec<f32>), SR(Vec<f32>), UN(Vec<String>), LM(String), RB(String),
}
Expand description

Emotibit data type

Variants§

§

EA(Vec<f32>)

EDA- Electrodermal Activity

§

EL(Vec<f32>)

EDL- Electrodermal Level

§

ER(Vec<f32>)

EDR- Electrodermal Response (EmotiBit V4+ combines ER into EA signal)

§

PI(Vec<u32>)

PPG Infrared

§

PR(Vec<u32>)

PPG Red

§

PG(Vec<u32>)

PPG Green

§

T0(Vec<f32>)

Temperature 0

§

T1(Vec<f32>)

Temperature 1

§

TH(Vec<f32>)

Temperature via Medical-grade Thermopile (only on EmotiBit MD)

§

AX(Vec<f32>)

Accelerometer X

§

AY(Vec<f32>)

Accelerometer Y

§

AZ(Vec<f32>)

Accelerometer Z

§

GX(Vec<f32>)

Gyroscope X

§

GY(Vec<f32>)

Gyroscope Y

§

GZ(Vec<f32>)

Gyroscope Z

§

MX(Vec<i32>)

Magnetometer X

§

MY(Vec<i32>)

Magnetometer Y

§

MZ(Vec<i32>)

Magnetometer Z

§

BV(Vec<f32>)

Battery Voltage

§

BATLV(Vec<u32>)

Battery Percentage Remaining (B%)

§

AK(Vec<String>)

§

RD(Vec<String>)

Request Data, TypeTag in Payload

§

TL(String)

§

TX(Vec<String>)

§

TxTlLc((String, f32))

§

TxLcLm(Vec<f32>)

§

EM(Vec<String>)

§

HR(Vec<i32>)

Heart Rate

§

BI(Vec<i32>)

Heart Inter-beat Interval

§

SA(Vec<f32>)

Skin Conductance Response (SCR) Amplitude

§

SF(Vec<f32>)

Skin Conductance Response (SCR) Frequency

§

SR(Vec<f32>)

Skin Conductance Response (SCR) Rise Time

§

UN(Vec<String>)

User Note

§

LM(String)

LSL Marker/message

§

RB(String)

Record begin (Include timestamp in Data)

Implementations§

Source§

impl DataType

Source

pub fn as_str(&self) -> &'static str

Examples found in repository?
examples/to_csv.rs (line 62)
13fn read_write(path_buf: Option<PathBuf>) -> Result<()> {
14    let filename: &str = path_buf
15        .as_ref()
16        .and_then(|name| name.file_stem())
17        .and_then(|name| name.to_str())
18        .unwrap_or("default");
19
20    let (datapackets, errors): (Vec<_>, Vec<_>) = parser::get_packets(
21        &path_buf
22            .as_ref()
23            .unwrap()
24            .clone()
25            .into_os_string()
26            .into_string()
27            .unwrap(),
28    )?
29    .into_iter()
30    .partition(Result::is_ok);
31
32    let mut output_file = path_buf.clone().unwrap();
33    output_file.set_file_name(format!("{}_ERROR.csv", filename));
34
35    // Write Errors
36    let mut output = File::create(output_file.clone())?;
37    for err in errors.into_iter().filter_map(|result| result.err()) {
38        writeln!(output, "{}", err)?;
39    }
40
41    // Write TimeSyncs
42    output_file.set_file_name(format!("{}_timesyncs.csv", filename));
43    let mut writer = writer::WriterBuilder::new().from_path(output_file.to_str().unwrap())?;
44    match parser::find_syncs(&datapackets) {
45        Ok(syncs) => {
46            let header =
47                StringRecord::from(vec!["RD", "TS_received", "TS_sent", "AK", "RoundTrip"]);
48            writer.write(&header)?;
49            for packet in syncs {
50                writer.write(&packet)?;
51            }
52        }
53        Err(e) => {
54            writer.write(&StringRecord::from(vec![format!("{:?}", e)]))?;
55        }
56    }
57
58    // Extract TypeTags
59    let set: HashSet<&str> = HashSet::from_iter(
60        datapackets
61            .iter()
62            .map(|result| result.as_ref().unwrap().data_type.as_str()),
63    );
64
65    // Write TimeSyncsMap
66    output_file.set_file_name(format!("{}_timeSyncMap.csv", filename));
67    let mut writer = writer::WriterBuilder::new().from_path(output_file.to_str().unwrap())?;
68    let syncmap = parser::generate_sync_map(&datapackets);
69    match &syncmap {
70        Ok(map) => {
71            let header = StringRecord::from(vec![
72                "TE0",
73                "TE1",
74                "TL0",
75                "TL1",
76                "TimeSyncsReceived",
77                "EmotiBitStartTime",
78                "EmotiBitEndTime",
79                "DataParserVersion",
80            ]);
81            writer.write(&header)?;
82            writer.write(map)?;
83        }
84        Err(e) => {
85            writer.write(&StringRecord::from(vec![format!("{:?}", e)]))?;
86        }
87    }
88
89    // Write Packets
90    let packets: Vec<DataPacket> = match syncmap {
91        Ok(map) => datapackets
92            .into_iter()
93            .filter_map(|result| result.ok())
94            .map(|p| p.inject_host_timestamp(&map))
95            .collect(),
96        Err(_) => datapackets
97            .into_iter()
98            .filter_map(|result| result.ok())
99            .collect(),
100    };
101
102    for t in set.iter() {
103        output_file.set_file_name(format!("{}_{}.csv", filename, t));
104        let mut writer = writer::WriterBuilder::new().from_path(output_file.to_str().unwrap())?;
105        let header = StringRecord::from(vec![
106            "LocalTimestamp",
107            "EmotiBitTimestamp",
108            "PacketNumber",
109            "DataLength",
110            "TypeTag",
111            "ProtocolVersion",
112            "DataReliability",
113            t,
114        ]);
115        writer.write(&header)?;
116        for packet in packets.iter().filter(|x| x.data_type.as_str() == *t) {
117            writer.write(packet)?;
118        }
119    }
120
121    Ok(())
122}
Source

pub fn payload(&self) -> Vec<String>

Trait Implementations§

Source§

impl Clone for DataType

Source§

fn clone(&self) -> DataType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DataType

Source§

fn eq(&self, other: &DataType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DataType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.