Skip to content

feat: Create datawriter class#22

Open
M1KUS3Q wants to merge 13 commits into
mainfrom
feat/create-datawriter-class
Open

feat: Create datawriter class#22
M1KUS3Q wants to merge 13 commits into
mainfrom
feat/create-datawriter-class

Conversation

@M1KUS3Q

@M1KUS3Q M1KUS3Q commented Jun 8, 2026

Copy link
Copy Markdown

Create DataWriter class and Marker, EEGData struct stubs, along with 2 basic unit tests for the DataWriter.

resolves #7

@M1KUS3Q M1KUS3Q linked an issue Jun 8, 2026 that may be closed by this pull request
Comment thread include/DataWriter.hpp Outdated
Comment thread include/DataWriter.hpp Outdated
Comment thread include/DataWriter.hpp Outdated
Comment thread src/DataWriter.cpp Outdated
Comment thread src/DataWriter.cpp Outdated
Comment thread src/DataWriter.cpp Outdated

@MichalSzandar MichalSzandar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Create IDataFormatStrategy virtual class
  • add unique_ptr< IDataFormatStrategy> in DataWriter

Comment thread include/datawriter/DataWriter.hpp Outdated
Comment thread src/datawriter/DataWriter.cpp Outdated
Comment on lines +70 to +81
EEGData eegData;
while (eegQueue->try_dequeue(eegData)) {
writeEEGData(eegData);
}
}

if (markerQueue) {
Marker marker;
while (markerQueue->try_dequeue(marker)) {
writeMarker(marker);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't repeat yourself

Comment thread src/datawriter/DataWriter.cpp Outdated
Comment on lines +84 to +97
void DataWriter::writeEEGData(const EEGData& data) {
outputFile << "eeg," << data.timestamp << ",\"";
for (std::size_t index = 0; index < data.channels.size(); ++index) {
if (index > 0) {
outputFile << ',';
}
outputFile << data.channels[index];
}
outputFile << '"' << '\n';
}

void DataWriter::writeMarker(const Marker& marker) {
outputFile << "marker," << marker.timestamp << ",\"" << marker.eventName << '"' << '\n';
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move those to CSVFormatStrategy

@M1KUS3Q M1KUS3Q requested a review from MichalSzandar June 11, 2026 14:12
return wroteData;
}

DataWriter::DataWriter() : formatStrategy(std::make_unique<CSVFormatStrategy>()) {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass IDataFormatStrategy as argument for DataWriter constructor, delete default constructor.

Comment on lines +19 to +22
virtual void writeHeader(std::ofstream& outputFile) const = 0;
virtual void writeEEGData(std::ofstream& outputFile, const EEGData& data) const = 0;
virtual void writeMarker(std::ofstream& outputFile, const Marker& marker) const = 0;
};

@MichalSzandar MichalSzandar Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that you force every strategy to use std::ofstream as a way to save data which is not good, because in other strategies like FifFormatStrategy we're (most likely) going to use Fiffstream to save our data. I think it would be better to add open(std::string filepath) function as I suggested in the UML diagram.

Comment thread include/EEGData.hpp
Comment on lines +1 to +20
#ifndef EEGDATA_HPP
#define EEGDATA_HPP

#include <utility>
#include <vector>

struct EEGData {
std::vector<float> channels;
double timestamp = 0.0;

EEGData() = default;

EEGData(const std::vector<float>& channelValues, double sampleTimestamp)
: channels(channelValues), timestamp(sampleTimestamp) {}

EEGData(std::vector<float>&& channelValues, double sampleTimestamp)
: channels(std::move(channelValues)), timestamp(sampleTimestamp) {}
};

#endif // EEGDATA_HPP No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider moving EEGData and Marker classes to seperate directory like include/data_structures or something like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create DataWriter class

2 participants