Skip to content

Commit 709a883

Browse files
authored
Date time multichart from group of files (#155)
1 parent f325519 commit 709a883

File tree

4 files changed

+121
-92
lines changed

4 files changed

+121
-92
lines changed

davis_one/davis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace dvs {
4343
const char kHtmlModel[] =
4444
R"(
4545
<head>
46+
<title>DAVIS</title>
4647
<script src="./%8" charset="utf-8"></script>
4748
%13
4849
</head>

gui/davis_gui.cpp

Lines changed: 110 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,83 @@ Skins DavisGUI::checkSkin() {
392392
return skin;
393393
}
394394

395+
bool DavisGUI::getDateTimeData(const QStringList& lines,
396+
QString& dates,
397+
std::vector<double>& values,
398+
std::vector<double>& force,
399+
std::vector<std::vector<double>>& multicharts) {
400+
QJsonArray jarr;
401+
if (jsn::getJsonArrayFromFile("date_time_formats.json", jarr) == false) {
402+
jsn::getJsonArrayFromFile(":/date_time_formats.json", jarr);
403+
}
404+
405+
for (int i = 0; i < lines.size(); ++i) {
406+
QString test = lines[i];
407+
test.replace("'", "");
408+
for (int j = 0; j < jarr.size(); ++j) {
409+
int template_time_stamp_size = jarr[j].toString().size();
410+
QString template_time_stamp = jarr[j].toString();
411+
if (test.size() < template_time_stamp_size + 1) {
412+
continue;
413+
}
414+
QString separator = QString(test[template_time_stamp_size]);
415+
QString substr = test.mid(0, template_time_stamp_size);
416+
QDateTime dt = QDateTime::fromString(substr, template_time_stamp);
417+
if (dt.isValid()) {
418+
dates.append("'");
419+
dates.append(dt.toString("yyyy-MM-dd hh:mm:ss"));
420+
dates.append("'");
421+
if (i < lines.size() - 1) {
422+
dates.append(",");
423+
}
424+
auto values_list = test.split(separator);
425+
//Clear empty values
426+
for (int ch = 0; ch < values_list.size(); ++ch) {
427+
if (values_list[ch].isEmpty()) {
428+
values_list.removeAt(ch);
429+
}
430+
}
431+
if (values_list.size() < 2) {
432+
continue;
433+
}
434+
if (values_list.size() > 3) {
435+
std::vector<double> temp(values_list.size() - 1);
436+
for (int j = 1; j < values_list.size(); ++j) {
437+
temp[j - 1] = values_list[j].toDouble();
438+
}
439+
multicharts.push_back(temp);
440+
}
441+
double value = values_list[1].toDouble();
442+
values.emplace_back(value);
443+
if (values_list.size() == 3) {
444+
double value = values_list[2].toDouble();
445+
force.emplace_back(value);
446+
}
447+
}
448+
}
449+
}
450+
return true;
451+
}
452+
453+
QStringList DavisGUI::getLinesFromFile(const QString& pathToFile) {
454+
QFile file(pathToFile);
455+
QTextStream ts(&file);
456+
ts.setCodec("UTF-8");
457+
if (file.open(QIODevice::ReadWrite) == false) {
458+
return QStringList();
459+
};
460+
QString line;
461+
QStringList str_lines;
462+
while (ts.readLineInto(&line)) {
463+
str_lines.append(line);
464+
}
465+
if (str_lines.empty()) {
466+
return QStringList();
467+
}
468+
file.close();
469+
return str_lines;
470+
}
471+
395472
void DavisGUI::setMaxStyleWindow(int animDuration) {
396473
m_isMinStyleWindow = false;
397474
hideElementsDuringResize();
@@ -664,70 +741,12 @@ void DavisGUI::readPlotText(QStringList& str_lines, QString title) {
664741

665742
bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
666743

667-
QJsonArray jarr;
668-
if (jsn::getJsonArrayFromFile("date_time_formats.json", jarr) == false) {
669-
jsn::getJsonArrayFromFile(":/date_time_formats.json", jarr);
670-
}
671-
qDebug() << jarr;
744+
672745
QString dates;
673746
std::vector<double> values;
674747
std::vector<double> force;
675748
std::vector<std::vector<double>> multicharts;
676-
677-
for (int i = 0; i < lines.size(); ++i) {
678-
QString test = lines[i];
679-
test.replace("'", "");
680-
for (int j = 0; j < jarr.size(); ++j) {
681-
int template_time_stamp_size = jarr[j].toString().size();
682-
QString template_time_stamp = jarr[j].toString();
683-
if (test.size() < template_time_stamp_size + 1) {
684-
continue;
685-
}
686-
QString separator = QString(test[template_time_stamp_size]);
687-
QString substr = test.mid(0, template_time_stamp_size);
688-
QDateTime dt = QDateTime::fromString(substr, template_time_stamp);
689-
if (dt.isValid()) {
690-
//2013-10-04 22:23:00
691-
//qDebug() << dt.toString("yyyy-MM-dd hh:mm:ss");
692-
dates.append("'");
693-
dates.append(dt.toString("yyyy-MM-dd hh:mm:ss"));
694-
dates.append("'");
695-
if (i < lines.size() - 1) {
696-
dates.append(",");
697-
}
698-
699-
auto values_list = test.split(separator);
700-
//Clear empty values
701-
for (int ch = 0; ch < values_list.size(); ++ch) {
702-
if (values_list[ch].isEmpty()) {
703-
values_list.removeAt(ch);
704-
}
705-
}
706-
707-
708-
if (values_list.size() < 2) {
709-
continue;
710-
}
711-
if (values_list.size() > 3) {
712-
std::vector<double> temp(values_list.size() - 1);
713-
for (int j = 1; j < values_list.size(); ++j) {
714-
temp[j - 1] = values_list[j].toDouble();
715-
}
716-
multicharts.push_back(temp);
717-
}
718-
719-
double value = values_list[1].toDouble();
720-
//qDebug() << value;
721-
values.emplace_back(value);
722-
if (values_list.size() == 3) {
723-
double value = values_list[2].toDouble();
724-
//qDebug() << value;
725-
force.emplace_back(value);
726-
}
727-
728-
}
729-
}
730-
}
749+
getDateTimeData(lines, dates, values, force, multicharts);
731750

732751
if (multicharts.empty() == false) {
733752
dvs::transponeMatrix(multicharts);
@@ -737,7 +756,6 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
737756

738757
if (values.size() == 0)
739758
return false;
740-
qDebug() << "check sizes: " << lines.size() << values.size();
741759

742760
if (force.empty() == false) {
743761
dvs::showCloudOfPointsChartStr(dates.toStdString(), values, force, action_fitPlotToAllWindow->isChecked());
@@ -746,7 +764,6 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
746764
dvs::showDateTimeChart(dates.toStdString(), values, action_fitPlotToAllWindow->isChecked());
747765
return true;
748766

749-
750767
}
751768

752769
void DavisGUI::selectAndShowFiles() {
@@ -765,21 +782,9 @@ void DavisGUI::selectAndShowFiles() {
765782
bool DavisGUI::isFileContainsSingleChart(const QString& pathToFile,
766783
std::vector<double>& outX,
767784
std::vector<double>& outY) {
768-
QFile file(pathToFile);
769-
QTextStream ts(&file);
770-
ts.setCodec("UTF-8");
771-
if (file.open(QIODevice::ReadWrite) == false) {
772-
return false;
773-
};
774-
QString line;
775-
QStringList str_lines;
776-
while (ts.readLineInto(&line)) {
777-
str_lines.append(line);
778-
}
779-
if (str_lines.empty()) {
780-
return false;
781-
}
782-
file.close();
785+
786+
QStringList str_lines = getLinesFromFile(pathToFile);
787+
783788

784789
std::vector<std::vector<double>> data;
785790
char separator;
@@ -832,8 +837,6 @@ bool DavisGUI::isFileContainsSingleChart(const QString& pathToFile,
832837

833838
}
834839
}
835-
//qDebug() << outX;
836-
//qDebug() << outY;
837840
return true;
838841
}
839842

@@ -895,24 +898,41 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
895898
if (file_list.isEmpty()) {
896899
return;
897900
}
898-
QString all_chart_blocks;
899-
const QString trace_name = "trace%1";
900-
QString all_traces_names;
901+
901902
if (file_list.size() > 1) {
902-
QStringList onlySingleChartList;
903-
qDebug() << "file list size: " << file_list.size();
903+
QVector<QString> dates_list;
904+
std::vector<std::vector<double>> all_values;
905+
for (int i = 0; i < file_list.size(); ++i) {
906+
QStringList lines;
907+
QString dates;
908+
std::vector<double> values;
909+
std::vector<double> force;
910+
std::vector<std::vector<double>> multicharts;
911+
lines = getLinesFromFile(file_list[i]);
912+
913+
getDateTimeData(lines, dates, values, force, multicharts);
914+
if (dates.isEmpty() == false) {
915+
dates_list.append(dates);
916+
all_values.emplace_back(values);
917+
}
918+
}
919+
if (dates_list.isEmpty() == false) {
920+
dvs::showDateTimeMultichart(dates_list[0].toStdString(), all_values, true);
921+
return;
922+
}
923+
924+
904925
std::vector<std::vector<double>> data;
905926
std::vector<double> x_values;
906927
for (int i = 0; i < file_list.size(); ++i) {
907928
std::vector<double> outX, outY;
908-
if(isFileContainsSingleChart(file_list[i], outX, outY)){
909-
//dv::show(outX,outY);
910-
if(i==0)x_values = outX;
911-
data.push_back(outY);
929+
if (isFileContainsSingleChart(file_list[i], outX, outY)) {
930+
if (i == 0)
931+
x_values = outX;
932+
data.push_back(outY);
912933
};
913-
914934
}
915-
dvs::showDateTimeMultichart(dvs::vectorToString(x_values),data,true);
935+
dvs::showDateTimeMultichart(dvs::vectorToString(x_values), data, true);
916936
return;
917937
}
918938
QString filePath = file_list.first();

gui/davis_gui.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class DavisGUI : public QMainWindow {
5151
void selectAndShowFiles();
5252
bool checkDateTimeVariant(const QStringList& lines);
5353
bool isFileContainsSingleChart(const QString& pathToFile,
54-
std::vector<double> &outX,
55-
std::vector<double> &outY);
54+
std::vector<double>& outX,
55+
std::vector<double>& outY);
5656
void visualizeFiles(const QStringList& file_list);
5757
void hideElementsDuringResize();
5858
void saveSettings(const QString& fileName);
@@ -62,6 +62,13 @@ class DavisGUI : public QMainWindow {
6262
void matrixAnalyzer(std::vector<std::vector<double>>& matrix,
6363
const bool isRow);
6464
Skins checkSkin();
65+
bool getDateTimeData(const QStringList& lines,
66+
QString& dates,
67+
std::vector<double>& values,
68+
std::vector<double>& force,
69+
std::vector<std::vector<double>>& multicharts);
70+
71+
QStringList getLinesFromFile(const QString& pathToFile);
6572

6673

6774
private slots:

plotly_maker/html_parts.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace dvs {
66
const char kHtmlModel[] =
77
R"(
88
<head>
9+
<title>DAVIS</title>
910
<script src="./%8" charset="utf-8"></script>
1011
%13
1112
</head>

0 commit comments

Comments
 (0)