MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / processItems

Method processItems

app/src/CSV/Export.cpp:88–126  ·  view source on GitHub ↗

* @brief Processes a batch of CSV frames, creating the file if needed. */

Source from the content-addressed store, hash-verified

86 * @brief Processes a batch of CSV frames, creating the file if needed.
87 */
88void CSV::ExportWorker::processItems(const std::vector<DataModel::TimestampedFramePtr>& items)
89{
90 if (items.empty())
91 return;
92
93 if (!m_csvFile.isOpen()) {
94 if (!m_templateFrame.groups.empty())
95 createCsvFile(m_templateFrame);
96 else
97 createCsvFile((*items.begin())->data);
98
99 if (m_schema.columns.empty())
100 return;
101
102 m_referenceTimestamp = (*items.begin())->timestamp;
103 resetMonotonicClock();
104 }
105
106 const int colCount = static_cast<int>(m_schema.columns.size());
107
108 for (const auto& i : items) {
109 const qint64 nanoseconds = monotonicFrameNs(i->timestamp, m_referenceTimestamp);
110 const double seconds = static_cast<double>(nanoseconds) / 1'000'000'000.0;
111 m_textStream << QString::number(seconds, 'f', 9);
112
113 for (const auto& g : i->data.groups)
114 for (const auto& d : g.datasets)
115 m_lastFinalValues[d.uniqueId] = d.value.simplified();
116
117 for (int j = 0; j < colCount; ++j) {
118 const int uid = m_schema.columns[static_cast<size_t>(j)].uniqueId;
119 m_textStream << ',' << escapeCsvField(m_lastFinalValues.value(uid, QString()));
120 }
121
122 m_textStream << '\n';
123 }
124
125 m_textStream.flush();
126}
127
128/**
129 * @brief Creates a new CSV file and writes the header row from the frame schema.

Callers

nothing calls this directly

Calls 7

escapeCsvFieldFunction · 0.85
emptyMethod · 0.80
beginMethod · 0.80
isOpenMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected