Coder Social home page Coder Social logo

patmagauran / datalog Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 119 KB

This is a statically accessible Data logging library intended for simulation systems. Log from anywhere in your code, and get updated Plots and CSV files automatically.

License: MIT License

C++ 100.00%

datalog's Introduction

DataLog

This is a statically accessible Data logging library intended for simulation systems. Log from anywhere in your code, and get updated Plots and CSV files automatically.

Features

  • Static interface to push a data point, a timestamp, or a control message
  • UI That provides realtime plotting, running in a separate thread
    • Plots are added as new data columns are added.
    • Plots are synced in the x-axis for easy comparison
  • Live CSV writer - Generates the csv on the fly, including support for a dynamic set of variables
  • Performance optimized - The library uses an optimized threading structure along with optimized data structures for max throughput
  • Automatically computes the simulation speed in realtime
  • Provides controls to pause/resume the simulation

Installing

This library depends on ImGui and ImPlot. Both libraries must first be installed into your project before this library can be used. However, they are only required for the UI component, and can easily be stripped away if you are only interested in the csv functionality.

Once those are installed, it is as simple as dropping all the files into your source structure and including DataLog.h wherever needed.

Usage

The library exposes 7 public methods:

  • initialize(str filename) - this must be caled prior to anything else. It starts the UI and csv logger. If you do not call this first, they will not start and nothing will be logged.
  • logData(str name, double value) - this logs a named datapoint. You can call this many times without issue
  • pushTimestamp(double ts) - this collects all the data points logged since the last timestamp and puts them together to be logged.
  • pushEvent(EventType event, str message) - this is mainly used to trigger pause, resume, and stop functionality.
  • isDone / isPaused - return whether the user has stopped / paused the run
  • cleanup() - cleanup - closes the plot ui and csv logger.

Demo code

#include "DataLog.h"

int main() {
    DataLog::initialize("Data.csv");

    long simTimeMs = 0;
    long value = 7;
    while (!DataLog::isDone()) {
        if (DataLog::isPaused()) continue;
        value += (value % 3);
        DataLog::logData("Value", value);
        DataLog::pushTimestamp(simTimeMs);

    }
    DataLog::cleanup();

}

Thread Safety

In its current form, it is designed for a single thread generating data. However, this can easily be modified by substituting the readerwriterqueue for the Concurrent queue, which is conviently by the same author as the readerwriter.

UI Demo

Shows the plot UI. Plots are dynamically generated and added and have synced X-axes for easy comparison

Structure

The library spawns three Separate threads

  • One that ingests and reformats data for the UI and CSV
  • One that runs the UI
  • One that runs the CSVwriter

The flow is as follows:

  • You call logData. The datapoint is added to a map in the datalog class
  • You call push timestamp - the data from the map is added to an object contianing it and the simulation timestamp. THis is pushed to a concurrent queue. The local map is cleared
  • The data ingestion thread dequeues from the map and reformats into appropriate forms for the UI and csv
    • for the UI: This is a map of the variable to two lists of values for x and y
    • For the CSV - Just gets pushed to the CSV's queue
  • The UI thread loads those arrays into ImPlot
  • The CSV thread dequeues row-by-row from its own queue and writes to the specified file. The ehader is dynamically updated as more columns are added.

License and dependencies

Please see the LICENSE file for more info on the license of this project.

Additionally, It relies on the following dependencies and awesome projects:

datalog's People

Contributors

patmagauran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.