diff options
author | Gehad elrobey <gehadelrobey@gmail.com> | 2014-08-04 10:30:31 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-08-04 10:03:12 -0700 |
commit | 5076e431d5388b2d142628cb2c5a18a45e22666a (patch) | |
tree | 27ca8a81f5a74d11f720438e5f105f9f4bdade55 | |
parent | 4d6ff4c8d1836361900a257f25ce83d8e639745b (diff) | |
download | subsurface-5076e431d5388b2d142628cb2c5a18a45e22666a.tar.gz |
HTML: export yearly statistics to JSON files.
Save Yearly statistics as JSON data to the stats_files.
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/divelogexportdialog.cpp | 34 | ||||
-rw-r--r-- | qt-ui/divelogexportdialog.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index 33b037d17..03bdaf9cb 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -14,6 +14,7 @@ #include "worldmap-save.h" #include "save-html.h" #include "helpers.h" +#include "statistics.h" DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DiveLogExportDialog) @@ -85,11 +86,13 @@ void DiveLogExportDialog::exportHtmlInit(const QString &filename) QString json_dive_data = exportFiles + QDir::separator() + "file.json"; QString json_settings = exportFiles + QDir::separator() + "settings.json"; + QString stat_file = exportFiles + QDir::separator() + "stat.json"; QString photos_directory = exportFiles + QDir::separator() + "photos" + QDir::separator(); mainDir.mkdir(photos_directory); exportFiles += "/"; exportHTMLsettings(json_settings); + exportHTMLstatistics(stat_file); export_HTML(json_dive_data.toUtf8().data(), photos_directory.toUtf8().data(), ui->exportSelectedDives->isChecked(), ui->exportListOnly->isChecked()); QString searchPath = getSubsurfaceDataPath("theme"); @@ -130,6 +133,37 @@ void DiveLogExportDialog::exportHTMLsettings(const QString &filename) file.close(); } +void DiveLogExportDialog::exportHTMLstatistics(const QString &filename) +{ + QFile file(filename); + file.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream out(&file); + int i = 0; + out << "divestat=["; + while (stats_yearly != NULL && stats_yearly[i].period) { + out << "{"; + out << "\"YEAR\":\"" << stats_yearly[i].period << "\","; + out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\","; + out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\","; + out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\","; + out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\","; + out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\","; + out << "\"AVG_DEPTH\":\"" << get_depth_string(stats_yearly[i].avg_depth) << "\","; + out << "\"MIN_DEPTH\":\"" << get_depth_string(stats_yearly[i].min_depth) << "\","; + out << "\"MAX_DEPTH\":\"" << get_depth_string(stats_yearly[i].max_depth) << "\","; + out << "\"AVG_SAC\":\"" << get_volume_string(stats_yearly[i].avg_sac) << "\","; + out << "\"MIN_SAC\":\"" << get_volume_string(stats_yearly[i].min_sac) << "\","; + out << "\"MAX_SAC\":\"" << get_volume_string(stats_yearly[i].max_sac) << "\","; + out << "\"AVG_TEMP\":\"" << QString::number(stats_yearly[i].combined_temp / stats_yearly[i].combined_count, 'f', 1) << "\","; + out << "\"MIN_TEMP\":\"" << get_temp_units(stats_yearly[i].min_temp, NULL) << "\","; + out << "\"MAX_TEMP\":\"" << get_temp_units(stats_yearly[i].max_temp, NULL) << "\","; + out << "},"; + i++; + } + out << "]"; + file.close(); +} + void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton *button) { showExplanation(); diff --git a/qt-ui/divelogexportdialog.h b/qt-ui/divelogexportdialog.h index 11775053a..e398a5a05 100644 --- a/qt-ui/divelogexportdialog.h +++ b/qt-ui/divelogexportdialog.h @@ -25,6 +25,7 @@ private: void showExplanation(); void exportHtmlInit(const QString &filename); void exportHTMLsettings(const QString &filename); + void exportHTMLstatistics(const QString &filename); void copy_and_overwrite(const QString &fileName, const QString &newName); }; |