Skip to content

Commit e657a28

Browse files
authored
Cloud of points (#145)
1 parent 4a1293f commit e657a28

File tree

11 files changed

+299
-67
lines changed

11 files changed

+299
-67
lines changed

common_utils/common_constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ const char kPlotlyJsName[] = "plotly-2.32.0.min.js";
99
const char kPlotlyJsResourcePath[] = "plotly_maker/plotly-2.32.0.min.js";
1010
const char kWarningPagePath[] = "./davis_htmls/warning_js_absent.html";
1111
const char kReportPagePath[] = "./davis_htmls/report.html";
12+
const char kCloudPagePath[] = "./davis_htmls/cloud_of_points.html";
1213
//#STOP_GRAB_TO_DVS_NAMESPACE
1314
}

common_utils/common_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern const char kPlotlyJsResourcePath[];
1010
extern const char kPlotlyJsWorkPath[];
1111
extern const char kWarningPagePath[];
1212
extern const char kReportPagePath[];
13+
extern const char kCloudPagePath[];
1314
//#STOP_GRAB_TO_DVS_NAMESPACE
1415
}
1516

davis_one/davis.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const char kPlotlyJsName[] = "plotly-2.32.0.min.js";
2929
const char kPlotlyJsResourcePath[] = "plotly_maker/plotly-2.32.0.min.js";
3030
const char kWarningPagePath[] = "./davis_htmls/warning_js_absent.html";
3131
const char kReportPagePath[] = "./davis_htmls/report.html";
32+
const char kCloudPagePath[] = "./davis_htmls/cloud_of_points.html";
3233

3334
} // namespace dvs end
3435

@@ -461,6 +462,48 @@ Plotly.newPlot('gd', data, layout, config);
461462
)davis_delimeter";
462463

463464

465+
466+
extern const char kHtmlCloudOfPoints[] = R"davis_delimeter(
467+
468+
<head>
469+
<script src="%1" charset="utf-8"></script>
470+
</head>
471+
<body><div style = "display: flex;
472+
align-items:center;height:100%; width:100%;background:#dddfd4;
473+
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
474+
id="gd"></div></div>
475+
<script>
476+
var trace = {
477+
x:[%2],
478+
y:[%3],
479+
mode: 'markers',
480+
481+
marker: {
482+
size: 10,
483+
color:[%4],
484+
colorbar:{},
485+
colorscale: ''
486+
}
487+
};
488+
var data = [trace];
489+
490+
var config = {
491+
editable: true,
492+
showLink: true,
493+
plotlyServerURL: "https://chart-studio.plotly.com"
494+
};
495+
496+
var layout = {};
497+
498+
Plotly.newPlot('gd', data,layout,config);
499+
</script>
500+
</body>
501+
502+
)davis_delimeter";
503+
504+
505+
506+
464507
// *INDENT-ON*
465508

466509
} // namespace dvs end
@@ -1178,6 +1221,46 @@ void addTraceBlockToGlobal(const vector<double>& xValues, const vector<double>&
11781221
dvs::allChartBlocks.emplace_back(filled_trace_block);
11791222
}
11801223

1224+
void showCloudOfPointsChart(const vector<double>& xValues,
1225+
const vector<double>& yValues,
1226+
const vector<double>& colorValues) {
1227+
string out;
1228+
string davis_dir;
1229+
#ifdef _WIN32
1230+
davis_dir = "\\davis_htmls";
1231+
#elif __linux__
1232+
davis_dir = "/davis_htmls";
1233+
#endif
1234+
vector<string>args {ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""};
1235+
args[ARG_JS_COF_NAME] = kPlotlyJsName;
1236+
args[ARG_X_CLOUD_OF_POINTS] = vectorToString(xValues);
1237+
args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues);
1238+
args[ARG_COLOR_CLOUD_OF_POINTS] = vectorToString(colorValues);
1239+
make_string(kHtmlCloudOfPoints, args, out);
1240+
saveStringToFile(kCloudPagePath, out);
1241+
openFileBySystem(kCloudPagePath);
1242+
}
1243+
1244+
void showCloudOfPointsChartStr(const std::string& xValues,
1245+
const vector<double>& yValues,
1246+
const vector<double>& colorValues) {
1247+
string out;
1248+
string davis_dir;
1249+
#ifdef _WIN32
1250+
davis_dir = "\\davis_htmls";
1251+
#elif __linux__
1252+
davis_dir = "/davis_htmls";
1253+
#endif
1254+
vector<string>args {ARGS_CLOUD_OF_POINTS_PAGE_SIZE, ""};
1255+
args[ARG_JS_COF_NAME] = kPlotlyJsName;
1256+
args[ARG_X_CLOUD_OF_POINTS] = xValues;
1257+
args[ARG_Y_CLOUD_OF_POINTS] = vectorToString(yValues);
1258+
args[ARG_COLOR_CLOUD_OF_POINTS] = vectorToString(colorValues);
1259+
make_string(kHtmlCloudOfPoints, args, out);
1260+
saveStringToFile(kCloudPagePath, out);
1261+
openFileBySystem(kCloudPagePath);
1262+
}
1263+
11811264

11821265
} // namespace dvs end
11831266

davis_one/davis.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern const char kPlotlyJsResourcePath[];
2525
extern const char kPlotlyJsWorkPath[];
2626
extern const char kWarningPagePath[];
2727
extern const char kReportPagePath[];
28+
extern const char kCloudPagePath[];
2829

2930
} // namespace dvs end
3031

@@ -156,6 +157,15 @@ enum ARGS_MULTI_CHARTS_PAGE {
156157
ARGS_MULTI_CHARTS_PAGE_SIZE
157158
};
158159

160+
enum ARGS_CLOUD_OF_POINTS_PAGE {
161+
ARG_JS_COF_NAME,
162+
ARG_X_CLOUD_OF_POINTS,
163+
ARG_Y_CLOUD_OF_POINTS,
164+
ARG_COLOR_CLOUD_OF_POINTS,
165+
// ADD NEW ENUM BEFORE THIS COMMENT
166+
ARGS_CLOUD_OF_POINTS_PAGE_SIZE
167+
};
168+
159169

160170
extern const char kHtmlModel[];
161171
extern const char kColorMapDefaultPart[];
@@ -182,6 +192,7 @@ extern const char kHtmlDateTimeModel[];
182192

183193
extern const char kHtmlMultiChartBlock[];
184194
extern const char kHtmlMultiChartModel[];
195+
extern const char kHtmlCloudOfPoints[];
185196

186197

187198
} // namespace dvs end
@@ -370,6 +381,15 @@ void showDateTimeChart(const string& date_time_values,
370381
void addTraceBlockToGlobal(const vector<double>& yValues, const string& traceName);
371382
void addTraceBlockToGlobal(const vector<double>& xValues, const vector<double>& yValues, const string& traceName);
372383

384+
void showCloudOfPointsChart(const vector<double>& xValues,
385+
const vector<double>& yValues,
386+
const vector<double>& colorValues);
387+
388+
389+
void showCloudOfPointsChartStr(const string& xValues,
390+
const vector<double>& yValues,
391+
const vector<double>& colorValues);
392+
373393

374394
} // namespace dvs end
375395

gui/davis_gui.cpp

Lines changed: 82 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ void DavisGUI::readJsonToPlot(const QString& pathToFile) {
257257
jsn::getJsonObjectFromFile(":/user_keys_list.json", user_stamp_keys);
258258
}
259259

260-
if(user_stamp_keys.keys().contains("matrix_to_matrix")){
261-
matrix_to_matrix_stamps = user_stamp_keys.value("matrix_to_matrix").toArray();
262-
}else{
263-
QJsonObject user_stamp_keys;
264-
jsn::getJsonObjectFromFile(":/user_keys_list.json", user_stamp_keys);
265-
matrix_to_matrix_stamps = user_stamp_keys.value("matrix_to_matrix").toArray();
260+
if (user_stamp_keys.keys().contains("matrix_to_matrix")) {
261+
matrix_to_matrix_stamps = user_stamp_keys.value("matrix_to_matrix").toArray();
262+
} else {
263+
QJsonObject user_stamp_keys;
264+
jsn::getJsonObjectFromFile(":/user_keys_list.json", user_stamp_keys);
265+
matrix_to_matrix_stamps = user_stamp_keys.value("matrix_to_matrix").toArray();
266266
}
267267

268268
QJsonValue jv;
@@ -276,52 +276,52 @@ void DavisGUI::readJsonToPlot(const QString& pathToFile) {
276276

277277
for (int i = 0; i < result.size(); ++i) {
278278

279-
//Проверяем является ли объект MATRIX TO MATRIX типом
280-
//qDebug()<<"MATRIX TO MATRIX: "<<matrix_to_matrix_stamps;
281-
for(int j=0; j<matrix_to_matrix_stamps.size(); ++j){
282-
auto obj = result[i].toObject();
283-
QStringList check_keys;
284-
285-
check_keys<<matrix_to_matrix_stamps[j].toObject().value("attribute_key").toString();
286-
check_keys<<matrix_to_matrix_stamps[j].toObject().value("x_values").toString();
287-
check_keys<<matrix_to_matrix_stamps[j].toObject().value("y_values").toString();
288-
289-
bool is_matrix_to_matrix_result = jsn::isObjectMatrixToMatrixType(
290-
check_keys,
291-
obj
292-
);
293-
//qDebug()<<matrix_to_matrix_stamps[j].toObject().keys();
294-
if(is_matrix_to_matrix_result){
295-
if(check_keys.size()!=3){
296-
qDebug()<<"********************** MATRIX TO MATRIX KEYS EXCEPTION ***************************";
297-
continue;
298-
};
299-
qDebug()<<"MATRIX_TO_MATRIX_PROCESS.......";
300-
// 0 - atr metadata
301-
// 1 - x array of arrays values
302-
// 2 - y array of arrays values
303-
auto attr_arr = obj.value(check_keys[0]).toArray();
304-
auto x_arr = obj.value(check_keys[1]).toArray();
305-
auto y_arr = obj.value(check_keys[2]).toArray();
306-
if(x_arr.size()!=y_arr.size()){
307-
qDebug()<<"********************** MATRIX TO MATRIX ARRAY ARRAY SIZES EXCEPTION ***************************";
308-
continue;
309-
};
310-
for(int k=0;k<x_arr.size();++k){
311-
auto attr = attr_arr[k].toObject();
312-
auto x_vals = jsn::getVectorDoubleFromJsonArray(x_arr[k].toArray()).toStdVector();
313-
auto y_vals = jsn::getVectorDoubleFromJsonArray(y_arr[k].toArray()).toStdVector();
314-
dv::Config conf;
315-
conf.chart.yLabel = attr.value("type").toString().toStdString();
316-
conf.chart.title = attr.value("instrument").toString().toStdString();
317-
318-
dv::show(x_vals,y_vals,QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm_ss_zz").toStdString(),conf);
279+
//Проверяем является ли объект MATRIX TO MATRIX типом
280+
//qDebug()<<"MATRIX TO MATRIX: "<<matrix_to_matrix_stamps;
281+
for (int j = 0; j < matrix_to_matrix_stamps.size(); ++j) {
282+
auto obj = result[i].toObject();
283+
QStringList check_keys;
284+
285+
check_keys << matrix_to_matrix_stamps[j].toObject().value("attribute_key").toString();
286+
check_keys << matrix_to_matrix_stamps[j].toObject().value("x_values").toString();
287+
check_keys << matrix_to_matrix_stamps[j].toObject().value("y_values").toString();
288+
289+
bool is_matrix_to_matrix_result = jsn::isObjectMatrixToMatrixType(
290+
check_keys,
291+
obj
292+
);
293+
//qDebug()<<matrix_to_matrix_stamps[j].toObject().keys();
294+
if (is_matrix_to_matrix_result) {
295+
if (check_keys.size() != 3) {
296+
qDebug() << "********************** MATRIX TO MATRIX KEYS EXCEPTION ***************************";
297+
continue;
298+
};
299+
qDebug() << "MATRIX_TO_MATRIX_PROCESS.......";
300+
// 0 - atr metadata
301+
// 1 - x array of arrays values
302+
// 2 - y array of arrays values
303+
auto attr_arr = obj.value(check_keys[0]).toArray();
304+
auto x_arr = obj.value(check_keys[1]).toArray();
305+
auto y_arr = obj.value(check_keys[2]).toArray();
306+
if (x_arr.size() != y_arr.size()) {
307+
qDebug() << "********************** MATRIX TO MATRIX ARRAY ARRAY SIZES EXCEPTION ***************************";
308+
continue;
309+
};
310+
for (int k = 0; k < x_arr.size(); ++k) {
311+
auto attr = attr_arr[k].toObject();
312+
auto x_vals = jsn::getVectorDoubleFromJsonArray(x_arr[k].toArray()).toStdVector();
313+
auto y_vals = jsn::getVectorDoubleFromJsonArray(y_arr[k].toArray()).toStdVector();
314+
dv::Config conf;
315+
conf.chart.yLabel = attr.value("type").toString().toStdString();
316+
conf.chart.title = attr.value("instrument").toString().toStdString();
317+
318+
dv::show(x_vals, y_vals, QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm_ss_zz").toStdString(), conf);
319+
}
320+
return;// выход если это был MATRIX_TO_MATRIX_TYPE
321+
}
319322
}
320-
return;// выход если это был MATRIX_TO_MATRIX_TYPE
321-
}
322-
}
323323

324-
auto json_object_result = jsn::isJsonObjectContainsUserKeys(result[i].toObject(),
324+
auto json_object_result = jsn::isJsonObjectContainsUserKeys(result[i].toObject(),
325325
service_json_keys,
326326
user_stamp_keys);
327327

@@ -358,9 +358,8 @@ void DavisGUI::readJsonToPlot(const QString& pathToFile) {
358358

359359

360360
bool DavisGUI::mayBeShowMatrixToMatrix(QJsonArray& stamps,
361-
QJsonObject& obj)
362-
{
363-
return false;
361+
QJsonObject& obj) {
362+
return false;
364363
}
365364

366365
Skins DavisGUI::checkSkin() {
@@ -593,6 +592,21 @@ void DavisGUI::readPlotText(QStringList& str_lines, QString title) {
593592
return;
594593
}
595594

595+
if (data[0].size() == 3) {
596+
qDebug() << "CLOUD_OF_POINTS........";
597+
std::vector<double>x(data.size(), 0);
598+
std::vector<double>y(data.size(), 0);
599+
std::vector<double>color(data.size(), 0);
600+
for (size_t i = 0; i < data.size(); ++i) {
601+
x[i] = data[i][0];
602+
y[i] = data[i][1];
603+
color[i] = data[i][2];
604+
}
605+
dvs::showCloudOfPointsChart(x, y, color);
606+
return;
607+
}
608+
609+
596610
if (data.size() == 2 || data[0].size() == 2) { //chartXY
597611
dv::Config config;
598612
config.chart.title = title.toStdString();
@@ -635,6 +649,7 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
635649
qDebug() << jarr;
636650
QString dates;
637651
std::vector<double> values;
652+
std::vector<double> force;
638653

639654
for (int i = 0; i < lines.size(); ++i) {
640655
QString test = lines[i];
@@ -649,7 +664,7 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
649664
QDateTime dt = QDateTime::fromString(substr, template_time_stamp);
650665
if (dt.isValid()) {
651666
//2013-10-04 22:23:00
652-
qDebug() << dt.toString("yyyy-MM-dd hh:mm:ss");
667+
//qDebug() << dt.toString("yyyy-MM-dd hh:mm:ss");
653668
dates.append("'");
654669
dates.append(dt.toString("yyyy-MM-dd hh:mm:ss"));
655670
dates.append("'");
@@ -658,12 +673,17 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
658673
}
659674

660675
auto values_list = test.split(separator);
661-
if (values_list.size() != 2) {
676+
if (values_list.size() < 2 || values_list.size() > 3) {
662677
continue;
663678
}
664679
double value = values_list[1].toDouble();
665-
qDebug() << value;
680+
//qDebug() << value;
666681
values.emplace_back(value);
682+
if (values_list.size() == 3) {
683+
double value = values_list[2].toDouble();
684+
//qDebug() << value;
685+
force.emplace_back(value);
686+
}
667687

668688
}
669689
}
@@ -674,6 +694,10 @@ bool DavisGUI::checkDateTimeVariant(const QStringList& lines) {
674694
if (lines.size() != values.size()) {
675695
return false;
676696
}
697+
if (force.empty() == false) {
698+
dvs::showCloudOfPointsChartStr(dates.toStdString(), values, force);
699+
return true;
700+
}
677701
dvs::showDateTimeChart(dates.toStdString(), values);
678702
return true;
679703

@@ -894,6 +918,8 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
894918
QString line;
895919
QStringList str_lines;
896920
while (ts.readLineInto(&line)) {
921+
if (line.isEmpty())
922+
continue;
897923
str_lines.append(line);
898924
}
899925
if (str_lines.empty()) {

gui/davis_gui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DavisGUI : public QMainWindow {
5959
QJsonObject loadSettings(const QString& fileName);
6060
void applySettings(const QJsonObject& settings);
6161
void readJsonToPlot(const QString& pathToFile);
62-
bool mayBeShowMatrixToMatrix(QJsonArray &stamps,
62+
bool mayBeShowMatrixToMatrix(QJsonArray& stamps,
6363
QJsonObject& obj);
6464
Skins checkSkin();
6565

0 commit comments

Comments
 (0)