PolledCSVLogger
PolledCSVLoggers log data to disk by polling the UI state at a specified interval.
Usage
PolledCSVLogger components use the structured DataSource
under the hood, similar to LineChart
components. This is provided along with the column name and optional accessors for structured data.
The logging interval is specified as a period measured in milliseconds. The current value of the variable at the end of that period will be recorded, regardless if it has updated since the last log entry.
A timestamp column is automatically generated with the format hour:minute:second.millisecond
.
By default, this component renders buttons for selecting the file save location, as well as starting/stopping the log recording. The file selection process is handled by the OS's native save dialog menu.
This snippet shows how to log a single-value temperature message, and how to put elements of a structured message in different columns using accessor syntax with the DataSource
.
import { PolledCSVLogger } from '@electricui/components-desktop-blueprint-timeseries'import { useMessageDataSource } from '@electricui/core-timeseries' const OverviewPage = () => { const tempDS = useMessageDataSource ('temp') const accDS = useMessageDataSource ('accel') return ( <React .Fragment > <PolledCSVLogger interval ={10} columns ={[ { dataSource : tempDS , column : 'tempC' }, { dataSource : accDS , column : 'accX', accessor : event => event [0] }, { dataSource : accDS , column : 'accY', accessor : event => event [1] }, { dataSource : accDS , column : 'accZ', accessor : event => event [2] }, ]} /> </React .Fragment > )}
The resulting log file is formatted with the columns in order listed in the columns
array with the full precision available.
timestamp | tempC | accX | accY | accZ |
---|---|---|---|---|
01:55:45.341 | 35.5625 | -0.112605400383472 | 5.77302122116089 | 7.95931053161621 |
01:55:45.351 | 35.5625 | -0.09406453371048 | 5.75108909606934 | 7.95682287216187 |
01:55:45.361 | 35.5625 | -0.109316825866699 | 5.75300598144531 | 7.93924474716187 |
01:55:45.372 | 35.5650 | -0.09470234811306 | 5.7453989982605 | 7.92565870285034 |
... | ... | ... | ... | ... |
Button Text
The component provides buttons for selecting the save location, and starting/stopping the log.
The text on these buttons is configurable by providing a string to the props: selectSaveLocationText
, startLoggingText
, stopLoggingText
.
<PolledCSVLogger startLoggingText ="Start Recording" stopLoggingText ="Stop Recording" selectSaveLocationText ="Select Destination Folder" interval ={10} columns ={[{ dataSource : tempDS , column : 'tempC' }]}/>
The selectSaveLocationMessage
prop accepts a string which is used in the path selection dialog.
Timestamp Column
The default column can be configured by the developer.
timestampColumnName
prop accepts a string used in the CSV header.
timestampColumnFormat
accepts a string describing the timestamp value formatting. Options here.
<PolledCSVLogger timestampColumnName ="Time" timestampColumnFormat ="HH:mm:ss" interval ={10} columns ={[{ dataSource : tempDS , column : 'tempC' }]}/>
Time | tempC |
---|---|
17:42:06 | 35.025 |
17:42:07 | 35.525 |
17:42:08 | 36.125 |
... | ... |
Beware of using lower precision timing data than the
interval
period (formatting millisecond scale entries with only a seconds field for example).Handling and post-processing data with duplicated timestamp values is painful for everyone.