Skip to content

Show date time variant #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,41 @@ const char kNoFileFoundedPage[] = R"(<!DOCTYPE html>

extern const char kWarningIcon[] = R"davis_delimeter(<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 156.262 144.407"><path d="M-109.166 7.227a2 2 0 0 0-.406.046c-3.195.03-6.176 1.695-7.785 4.483l-31.25 54.127-31.25 54.127h.002c-3.42 5.922 1.017 13.609 7.855 13.61h125.002c6.839-.001 11.277-7.688 7.857-13.61l-31.25-54.127-31.252-54.127c-1.465-2.539-4.079-4.164-6.978-4.45a2 2 0 0 0-.445-.077h-.004a2.006 2.006 0 0 0-.094-.002z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fff" d="M-109.165 9.227a7.081 7.081 0 0 0-6.46 3.529l-31.25 54.127-31.25 54.127c-2.674 4.631.777 10.609 6.126 10.61h125.002c5.348-.001 8.8-5.979 6.125-10.61l-31.25-54.127-31.252-54.127a7.079 7.079 0 0 0-5.79-3.53h-.001z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path d="M-109.26 11.225a5.073 5.073 0 0 0-4.632 2.53l-31.25 54.128-31.25 54.127c-1.953 3.381.488 7.609 4.393 7.61h125.002c3.905-.001 6.345-4.229 4.392-7.61l-31.25-54.127-31.252-54.127a5.073 5.073 0 0 0-4.152-2.531z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fc0" d="M140.053 125.83H16.209L47.17 72.204l30.961-53.626 30.961 53.626z"/><g transform="translate(.295 2.437) scale(.99073)"><circle cx="78.564" cy="111.117" r="8.817"/><path d="M78.564 42.955a8.817 8.817 0 0 0-8.818 8.816l3.156 37.461a5.662 5.662 0 0 0 11.325 0l3.154-37.46a8.817 8.817 0 0 0-8.817-8.817z"/></g></svg>)davis_delimeter";



extern const char kHtmlDateTimeModel[] = R"davis_delimeter(
<head>
<script src="%1" charset="utf-8"></script>
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
id="gd"></div></div>

<script>

var data = [
{
x: [%2],
y: [%3],
type: 'scatter'
}
];

var config = {
editable: true,
showLink: true,
plotlyServerURL: "https://chart-studio.plotly.com"
};

Plotly.newPlot('gd', data);

</script>
</body>
)davis_delimeter";



// *INDENT-ON*

} // namespace dvs end
Expand Down Expand Up @@ -988,6 +1023,37 @@ void showMatrixSizesAreNotTheSame() {
"Rows have different sizes in matrix");
}

void showDateTimeChart(const string& date_time_values,
const vector<double>& yValues) {

string out;
string davis_dir;
#ifdef _WIN32
davis_dir = "\\davis_htmls";
#elif __linux__
davis_dir = "/davis_htmls";
#endif
vector<string>args {ARGS_DATE_TIME_PAGE_SIZE, ""};
args[ARG_JS_NAME] = kPlotlyJsName;
args[ARG_DATE_TIME_VALUES] = date_time_values;

std::string values;
for (size_t i = 0; i < yValues.size(); ++i) {
std::string value = std::to_string(yValues[i]);
values.append(value);
if (i != yValues.size() - 1) {
values.append(",");
}
}

args[ARG_Y_DATE_TIME_VALUES] = values;
make_string(kHtmlDateTimeModel, args, out);
saveStringToFile(kReportPagePath, out);
openFileBySystem(kReportPagePath);


}


} // namespace dvs end

14 changes: 14 additions & 0 deletions davis_one/davis.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ enum ARGS_REPORT_PAGE_INDEX {
ARGS_REPORT_PAGE_SIZE
};

enum ARGS_DATE_TIME_PAGE_INDEX {
ARG_JS_NAME, //%1
ARG_DATE_TIME_VALUES, //%2
ARG_Y_DATE_TIME_VALUES, //%3
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_DATE_TIME_PAGE_SIZE
};


extern const char kHtmlModel[];
extern const char kColorMapDefaultPart[];
Expand All @@ -160,6 +168,9 @@ extern const char kNoFileFoundedPage[];

extern const char kWarningIcon[];

extern const char kHtmlDateTimeModel[];


} // namespace dvs end

namespace dvs {
Expand Down Expand Up @@ -332,6 +343,9 @@ void showReportFileEmpty();

void showMatrixSizesAreNotTheSame();

void showDateTimeChart(const string& date_time_values,
const vector<double>& yValues);


} // namespace dvs end

Expand Down
2 changes: 2 additions & 0 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ set(PROJECT_SOURCES
about_window.cpp
davis_gui.ui
about_window.ui
json_utils.h
json_utils.cpp
)

qt5_add_resources(PROJECT_SOURCES res.qrc)
Expand Down
6 changes: 6 additions & 0 deletions gui/date_time_formats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"dd/MM/yyyy hh:mm",
"yyyy/MM/dd hh:mm:ss",
"yyyy.MM.dd_hh:mm:ss",
"yyyy/MM/dd hh_mm_ss"
]
200 changes: 137 additions & 63 deletions gui/davis_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
#include "QFileDialog"
#include "QTextStream"
#include <QClipboard>
#include <QJsonArray>
#include "json_utils.h"
#include "QDateTime"
#include <QProcess>

DavisGUI::DavisGUI(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::DavisGUI),
m_copy_paste_action(new QAction("Вставить из буфера обмена")){
m_copy_paste_action(new QAction("Вставить из буфера обмена")) {
isAboutWindowShowed = false;
ui->setupUi(this);
ui->centralwidget->addAction(m_copy_paste_action);
Expand Down Expand Up @@ -62,7 +66,7 @@ DavisGUI::DavisGUI(QWidget* parent)
hbl->addWidget(qpbExit);
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);

connect(m_copy_paste_action,SIGNAL(triggered()),SLOT(pasteTextAdded()));
connect(m_copy_paste_action, SIGNAL(triggered()), SLOT(pasteTextAdded()));
}

DavisGUI::~DavisGUI() {
Expand All @@ -79,77 +83,131 @@ void DavisGUI::showAboutWindow() {
isAboutWindowShowed = true;
}

void DavisGUI::pasteTextAdded()
{
QClipboard *clipboard = QApplication::clipboard();
QString clipboardText = clipboard->text();
qDebug()<<clipboardText;
QStringList lines = clipboardText.split(QRegExp("[\r\n]+"));
void DavisGUI::pasteTextAdded() {
QClipboard* clipboard = QApplication::clipboard();
QString clipboardText = clipboard->text();
qDebug() << clipboardText;
QStringList lines = clipboardText.split(QRegExp("[\r\n]+"));
if (checkDateTimeVariant(lines) == false) {
readPlotText(lines);
};
}

void DavisGUI::readPlotText(QStringList &str_lines)
{
std::vector<double>lines;
std::vector<std::vector<double>> data;
char separator;
for (int i = 0; i < str_lines.size(); ++i) {
std::vector<double>values;
auto res = dvs::find_separator(str_lines[i].toStdString(), separator);
//qDebug() << "sep result: " << separator << "--->" << res;
bool is_one_value = false;
std::replace(str_lines[i].begin(), str_lines[i].end(), ',', '.');
if (res != dvs::GOOD_SEPARATOR) {
if (dvs::is_string_convertable_to_digit(str_lines[i].toStdString()) == false) {
continue;
} else {
is_one_value = true;
}
void DavisGUI::readPlotText(QStringList& str_lines) {
std::vector<double>lines;
std::vector<std::vector<double>> data;
char separator;
for (int i = 0; i < str_lines.size(); ++i) {
std::vector<double>values;
auto res = dvs::find_separator(str_lines[i].toStdString(), separator);
//qDebug() << "sep result: " << separator << "--->" << res;
bool is_one_value = false;
std::replace(str_lines[i].begin(), str_lines[i].end(), ',', '.');
if (res != dvs::GOOD_SEPARATOR) {
if (dvs::is_string_convertable_to_digit(str_lines[i].toStdString()) == false) {
continue;
} else {
is_one_value = true;
}
if (is_one_value == false) {
QStringList str_values = str_lines[i].split(separator);
for (int j = 0; j < str_values.size(); ++j) {
if (dvs::is_string_convertable_to_digit(str_values[j].toStdString()) == false) {
continue;
}
values.emplace_back(std::stod(str_values[j].toStdString()));
}
if (is_one_value == false) {
QStringList str_values = str_lines[i].split(separator);
for (int j = 0; j < str_values.size(); ++j) {
if (dvs::is_string_convertable_to_digit(str_values[j].toStdString()) == false) {
continue;
}
} else {
values.emplace_back(std::stod(str_lines[i].toStdString()));
values.emplace_back(std::stod(str_values[j].toStdString()));
}
data.emplace_back(values);
} else {
values.emplace_back(std::stod(str_lines[i].toStdString()));
}
data.emplace_back(values);
}

if (data.empty()) {
qDebug() << "Empty file";
return;
}
if (data.empty()) {
dvs::showReportFileEmpty();
return;
}

if (data.size() == 2 || data[0].size() == 2) { //chartXY
dv::show(data, "chartXY");
} else if (data.size() > 1 && data[0].size() > 1) {
if (action_heatmap->isChecked()) {
dv::show(data);
} else if (action_surface->isChecked()) {
dv::Config config;
config.typeVisual = dv::VISUALTYPE_SURFACE;
dv::show(data, "surface", config);
if (data.size() == 2 || data[0].size() == 2) { //chartXY
dv::show(data, "chartXY");
} else if (data.size() > 1 && data[0].size() > 1) {
if (action_heatmap->isChecked()) {
dv::show(data);
} else if (action_surface->isChecked()) {
dv::Config config;
config.typeVisual = dv::VISUALTYPE_SURFACE;
dv::show(data, "surface", config);
}
} else {
std::vector<double> showVector;
if (data.size() > 1 && data[0].size() == 1) {
std::vector<double> new_data(data.size());
for (size_t i = 0; i < new_data.size(); ++i) {
new_data[i] = data[i][0];
}
showVector = new_data;
} else {
std::vector<double> showVector;
if (data.size() > 1 && data[0].size() == 1) {
std::vector<double> new_data(data.size());
for (size_t i = 0; i < new_data.size(); ++i) {
new_data[i] = data[i][0];
showVector = data[0];
}
dv::Config config;
config.typeVisual = dv::VISUALTYPE_CHART;
dv::show(showVector, "chart", config);
}
}

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

QJsonArray jarr;
if(jsn::getJsonArrayFromFile("date_time_formats.json", jarr)==false){
jsn::getJsonArrayFromFile(":/date_time_formats.json", jarr);
}
qDebug() << jarr;
QString dates;
std::vector<double> values;

for (int i = 0; i < lines.size(); ++i) {
QString test = lines[i];
for (int j = 0; j < jarr.size(); ++j) {
int template_time_stamp_size = jarr[j].toString().size();
QString template_time_stamp = jarr[j].toString();
if (test.size() < template_time_stamp_size + 1) {
continue;
}
QString separator = QString(test[template_time_stamp_size]);
QString substr = test.mid(0, template_time_stamp_size);
QDateTime dt = QDateTime::fromString(substr, template_time_stamp);
if (dt.isValid()) {
//2013-10-04 22:23:00
qDebug() << dt.toString("yyyy-MM-dd hh:mm:ss");
dates.append("'");
dates.append(dt.toString("yyyy-MM-dd hh:mm:ss"));
dates.append("'");
if (i < lines.size() - 1) {
dates.append(",");
}
showVector = new_data;
} else {
showVector = data[0];

auto values_list = test.split(separator);
if (values_list.size() != 2) {
continue;
}
double value = values_list[1].toDouble();
qDebug()<<value;
values.emplace_back(value);

}
dv::Config config;
config.typeVisual = dv::VISUALTYPE_CHART;
dv::show(showVector, "chart", config);
}
}
if (values.size() == 0)
return false;
qDebug() << "check sizes: " << lines.size() << values.size();
if (lines.size() != values.size()) {
return false;
}
dvs::showDateTimeChart(dates.toStdString(), values);
return true;


}

void DavisGUI::dragEnterEvent(QDragEnterEvent* event) {
Expand All @@ -161,18 +219,32 @@ void DavisGUI::dragEnterEvent(QDragEnterEvent* event) {
}

void DavisGUI::dropEvent(QDropEvent* event) {
QString filePath = event->mimeData()->urls().first().toLocalFile();
QList<QUrl> file_list = event->mimeData()->urls();
if(file_list.size()>1){
qDebug()<<"file list size: "<<file_list.size();
return;
}
QString filePath = file_list.first().toLocalFile();
QFileInfo info(filePath);
qDebug() << "---file path--->" << filePath;
if (info.exists()) {
qDebug() << "exist";
QFile file(filePath);
QTextStream ts(&file);
ts.setCodec("UTF-8");
if (file.open(QIODevice::ReadWrite) == false) {
dvs::showReportFileNotFounded();
return;
};

QString suffix = info.suffix();
QStringList suffixes = {"jpg","bmp","png","svg","mp4","json"};
for(int i=0;i<suffixes.size();++i){
if(suffix == suffixes[i]){
QProcess process;
process.startDetached("cmd.exe", QStringList() << "/C" << filePath);
return;
}
}

QString line;
QStringList str_lines;
while (ts.readLineInto(&line)) {
Expand All @@ -183,7 +255,9 @@ void DavisGUI::dropEvent(QDropEvent* event) {
return;
}
file.close();
readPlotText(str_lines);
if (checkDateTimeVariant(str_lines) == false) {
readPlotText(str_lines);
};
} else {
qDebug() << "not exist";
dvs::showReportFileNotFounded();
Expand Down
Loading
Loading