mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Statistics: remove global state / calculate only when needed
Statistics were calculated into global variables every time the current dive was changed. Calculate statistics only when needed and into a structure provided by the caller. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
68fdc0b6f4
commit
97991e2b9f
7 changed files with 141 additions and 107 deletions
|
@ -75,42 +75,44 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
|
stats_summary_auto_free stats;
|
||||||
|
|
||||||
stats_t total_stats;
|
stats_t total_stats;
|
||||||
|
|
||||||
|
calculate_stats_summary(&stats);
|
||||||
total_stats.selection_size = 0;
|
total_stats.selection_size = 0;
|
||||||
total_stats.total_time.seconds = 0;
|
total_stats.total_time.seconds = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
out << "divestat=[";
|
out << "divestat=[";
|
||||||
if (hes.yearlyStatistics) {
|
if (hes.yearlyStatistics) {
|
||||||
while (stats_yearly != NULL && stats_yearly[i].period) {
|
while (stats.stats_yearly != NULL && stats.stats_yearly[i].period) {
|
||||||
out << "{";
|
out << "{";
|
||||||
out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
|
out << "\"YEAR\":\"" << stats.stats_yearly[i].period << "\",";
|
||||||
out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
|
out << "\"DIVES\":\"" << stats.stats_yearly[i].selection_size << "\",";
|
||||||
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats_yearly[i].total_time.seconds,
|
out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats.stats_yearly[i].total_time.seconds,
|
||||||
gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\",";
|
gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\",";
|
||||||
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
|
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\",";
|
||||||
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
|
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].shortest_time.seconds) << "\",";
|
||||||
out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\",";
|
out << "\"LONGEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].longest_time.seconds) << "\",";
|
||||||
out << "\"AVG_DEPTH\":\"" << get_depth_string(stats_yearly[i].avg_depth) << "\",";
|
out << "\"AVG_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].avg_depth) << "\",";
|
||||||
out << "\"MIN_DEPTH\":\"" << get_depth_string(stats_yearly[i].min_depth) << "\",";
|
out << "\"MIN_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].min_depth) << "\",";
|
||||||
out << "\"MAX_DEPTH\":\"" << get_depth_string(stats_yearly[i].max_depth) << "\",";
|
out << "\"MAX_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].max_depth) << "\",";
|
||||||
out << "\"AVG_SAC\":\"" << get_volume_string(stats_yearly[i].avg_sac) << "\",";
|
out << "\"AVG_SAC\":\"" << get_volume_string(stats.stats_yearly[i].avg_sac) << "\",";
|
||||||
out << "\"MIN_SAC\":\"" << get_volume_string(stats_yearly[i].min_sac) << "\",";
|
out << "\"MIN_SAC\":\"" << get_volume_string(stats.stats_yearly[i].min_sac) << "\",";
|
||||||
out << "\"MAX_SAC\":\"" << get_volume_string(stats_yearly[i].max_sac) << "\",";
|
out << "\"MAX_SAC\":\"" << get_volume_string(stats.stats_yearly[i].max_sac) << "\",";
|
||||||
if (stats_yearly[i].combined_count) {
|
if (stats.stats_yearly[i].combined_count) {
|
||||||
temperature_t avg_temp;
|
temperature_t avg_temp;
|
||||||
avg_temp.mkelvin = stats_yearly[i].combined_temp.mkelvin / stats_yearly[i].combined_count;
|
avg_temp.mkelvin = stats.stats_yearly[i].combined_temp.mkelvin / stats.stats_yearly[i].combined_count;
|
||||||
out << "\"AVG_TEMP\":\"" << get_temperature_string(avg_temp) << "\",";
|
out << "\"AVG_TEMP\":\"" << get_temperature_string(avg_temp) << "\",";
|
||||||
} else {
|
} else {
|
||||||
out << "\"AVG_TEMP\":\"0.0\",";
|
out << "\"AVG_TEMP\":\"0.0\",";
|
||||||
}
|
}
|
||||||
out << "\"MIN_TEMP\":\"" << (stats_yearly[i].min_temp.mkelvin == 0 ? 0 : get_temperature_string(stats_yearly[i].min_temp)) << "\",";
|
out << "\"MIN_TEMP\":\"" << (stats.stats_yearly[i].min_temp.mkelvin == 0 ? 0 : get_temperature_string(stats.stats_yearly[i].min_temp)) << "\",";
|
||||||
out << "\"MAX_TEMP\":\"" << (stats_yearly[i].max_temp.mkelvin == 0 ? 0 : get_temperature_string(stats_yearly[i].max_temp)) << "\",";
|
out << "\"MAX_TEMP\":\"" << (stats.stats_yearly[i].max_temp.mkelvin == 0 ? 0 : get_temperature_string(stats.stats_yearly[i].max_temp)) << "\",";
|
||||||
out << "},";
|
out << "},";
|
||||||
total_stats.selection_size += stats_yearly[i].selection_size;
|
total_stats.selection_size += stats.stats_yearly[i].selection_size;
|
||||||
total_stats.total_time.seconds += stats_yearly[i].total_time.seconds;
|
total_stats.total_time.seconds += stats.stats_yearly[i].total_time.seconds;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
exportHTMLstatisticsTotal(out, &total_stats);
|
exportHTMLstatisticsTotal(out, &total_stats);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* core logic for the Info & Stats page -
|
* core logic for the Info & Stats page -
|
||||||
* char *get_minutes(int seconds);
|
* char *get_minutes(int seconds);
|
||||||
* void process_all_dives();
|
* void calculate_stats_summary(struct stats_summary *out);
|
||||||
*/
|
*/
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -14,12 +14,7 @@
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
#include "statistics.h"
|
#include "statistics.h"
|
||||||
|
|
||||||
static stats_t stats;
|
|
||||||
stats_t stats_selection;
|
stats_t stats_selection;
|
||||||
stats_t *stats_monthly = NULL;
|
|
||||||
stats_t *stats_yearly = NULL;
|
|
||||||
stats_t *stats_by_trip = NULL;
|
|
||||||
stats_t *stats_by_type = NULL;
|
|
||||||
|
|
||||||
static void process_temperatures(struct dive *dp, stats_t *stats)
|
static void process_temperatures(struct dive *dp, stats_t *stats)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +86,13 @@ char *get_minutes(int seconds)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_all_dives()
|
/*
|
||||||
|
* Calculate a summary of the statistics and put in the stats_summary
|
||||||
|
* structure provided in the first parameter.
|
||||||
|
* Before first use, it should be initialized with init_stats_summary().
|
||||||
|
* After use, memory must be released with free_stats_summary().
|
||||||
|
*/
|
||||||
|
void calculate_stats_summary(struct stats_summary *out)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
struct dive *dp;
|
struct dive *dp;
|
||||||
|
@ -104,8 +105,8 @@ void process_all_dives()
|
||||||
int trip_iter = 0;
|
int trip_iter = 0;
|
||||||
dive_trip_t *trip_ptr = 0;
|
dive_trip_t *trip_ptr = 0;
|
||||||
unsigned int size, tsize;
|
unsigned int size, tsize;
|
||||||
|
stats_t stats = { 0 };
|
||||||
|
|
||||||
memset(&stats, 0, sizeof(stats));
|
|
||||||
if (dive_table.nr > 0) {
|
if (dive_table.nr > 0) {
|
||||||
stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds;
|
stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds;
|
||||||
stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm;
|
stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm;
|
||||||
|
@ -116,37 +117,33 @@ void process_all_dives()
|
||||||
* case (one dive per year or all dives during
|
* case (one dive per year or all dives during
|
||||||
* one month) for yearly and monthly statistics*/
|
* one month) for yearly and monthly statistics*/
|
||||||
|
|
||||||
free(stats_yearly);
|
|
||||||
free(stats_monthly);
|
|
||||||
free(stats_by_trip);
|
|
||||||
free(stats_by_type);
|
|
||||||
|
|
||||||
size = sizeof(stats_t) * (dive_table.nr + 1);
|
size = sizeof(stats_t) * (dive_table.nr + 1);
|
||||||
tsize = sizeof(stats_t) * (NUM_DIVEMODE + 1);
|
tsize = sizeof(stats_t) * (NUM_DIVEMODE + 1);
|
||||||
stats_yearly = malloc(size);
|
free_stats_summary(out);
|
||||||
stats_monthly = malloc(size);
|
out->stats_yearly = malloc(size);
|
||||||
stats_by_trip = malloc(size);
|
out->stats_monthly = malloc(size);
|
||||||
stats_by_type = malloc(tsize);
|
out->stats_by_trip = malloc(size);
|
||||||
if (!stats_yearly || !stats_monthly || !stats_by_trip || !stats_by_type)
|
out->stats_by_type = malloc(tsize);
|
||||||
|
if (!out->stats_yearly || !out->stats_monthly || !out->stats_by_trip || !out->stats_by_type)
|
||||||
return;
|
return;
|
||||||
memset(stats_yearly, 0, size);
|
memset(out->stats_yearly, 0, size);
|
||||||
memset(stats_monthly, 0, size);
|
memset(out->stats_monthly, 0, size);
|
||||||
memset(stats_by_trip, 0, size);
|
memset(out->stats_by_trip, 0, size);
|
||||||
memset(stats_by_type, 0, tsize);
|
memset(out->stats_by_type, 0, tsize);
|
||||||
stats_yearly[0].is_year = true;
|
out->stats_yearly[0].is_year = true;
|
||||||
|
|
||||||
/* Setting the is_trip to true to show the location as first
|
/* Setting the is_trip to true to show the location as first
|
||||||
* field in the statistics window */
|
* field in the statistics window */
|
||||||
stats_by_type[0].location = strdup(translate("gettextFromC", "All (by type stats)"));
|
out->stats_by_type[0].location = strdup(translate("gettextFromC", "All (by type stats)"));
|
||||||
stats_by_type[0].is_trip = true;
|
out->stats_by_type[0].is_trip = true;
|
||||||
stats_by_type[1].location = strdup(translate("gettextFromC", divemode_text_ui[OC]));
|
out->stats_by_type[1].location = strdup(translate("gettextFromC", divemode_text_ui[OC]));
|
||||||
stats_by_type[1].is_trip = true;
|
out->stats_by_type[1].is_trip = true;
|
||||||
stats_by_type[2].location = strdup(translate("gettextFromC", divemode_text_ui[CCR]));
|
out->stats_by_type[2].location = strdup(translate("gettextFromC", divemode_text_ui[CCR]));
|
||||||
stats_by_type[2].is_trip = true;
|
out->stats_by_type[2].is_trip = true;
|
||||||
stats_by_type[3].location = strdup(translate("gettextFromC", divemode_text_ui[PSCR]));
|
out->stats_by_type[3].location = strdup(translate("gettextFromC", divemode_text_ui[PSCR]));
|
||||||
stats_by_type[3].is_trip = true;
|
out->stats_by_type[3].is_trip = true;
|
||||||
stats_by_type[4].location = strdup(translate("gettextFromC", divemode_text_ui[FREEDIVE]));
|
out->stats_by_type[4].location = strdup(translate("gettextFromC", divemode_text_ui[FREEDIVE]));
|
||||||
stats_by_type[4].is_trip = true;
|
out->stats_by_type[4].is_trip = true;
|
||||||
|
|
||||||
/* this relies on the fact that the dives in the dive_table
|
/* this relies on the fact that the dives in the dive_table
|
||||||
* are in chronological order */
|
* are in chronological order */
|
||||||
|
@ -160,20 +157,20 @@ void process_all_dives()
|
||||||
|
|
||||||
if (current_year != tm.tm_year) {
|
if (current_year != tm.tm_year) {
|
||||||
current_year = tm.tm_year;
|
current_year = tm.tm_year;
|
||||||
process_dive(dp, &(stats_yearly[++year_iter]));
|
process_dive(dp, &(out->stats_yearly[++year_iter]));
|
||||||
stats_yearly[year_iter].is_year = true;
|
out->stats_yearly[year_iter].is_year = true;
|
||||||
} else {
|
} else {
|
||||||
process_dive(dp, &(stats_yearly[year_iter]));
|
process_dive(dp, &(out->stats_yearly[year_iter]));
|
||||||
}
|
}
|
||||||
stats_yearly[year_iter].selection_size++;
|
out->stats_yearly[year_iter].selection_size++;
|
||||||
stats_yearly[year_iter].period = current_year;
|
out->stats_yearly[year_iter].period = current_year;
|
||||||
|
|
||||||
/* stats_by_type[0] is all the dives combined */
|
/* stats_by_type[0] is all the dives combined */
|
||||||
stats_by_type[0].selection_size++;
|
out->stats_by_type[0].selection_size++;
|
||||||
process_dive(dp, &(stats_by_type[0]));
|
process_dive(dp, &(out->stats_by_type[0]));
|
||||||
|
|
||||||
process_dive(dp, &(stats_by_type[dp->dc.divemode + 1]));
|
process_dive(dp, &(out->stats_by_type[dp->dc.divemode + 1]));
|
||||||
stats_by_type[dp->dc.divemode + 1].selection_size++;
|
out->stats_by_type[dp->dc.divemode + 1].selection_size++;
|
||||||
|
|
||||||
if (dp->divetrip != NULL) {
|
if (dp->divetrip != NULL) {
|
||||||
if (trip_ptr != dp->divetrip) {
|
if (trip_ptr != dp->divetrip) {
|
||||||
|
@ -182,15 +179,15 @@ void process_all_dives()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stats_by_trip[0] is all the dives combined */
|
/* stats_by_trip[0] is all the dives combined */
|
||||||
stats_by_trip[0].selection_size++;
|
out->stats_by_trip[0].selection_size++;
|
||||||
process_dive(dp, &(stats_by_trip[0]));
|
process_dive(dp, &(out->stats_by_trip[0]));
|
||||||
stats_by_trip[0].is_trip = true;
|
out->stats_by_trip[0].is_trip = true;
|
||||||
stats_by_trip[0].location = strdup(translate("gettextFromC", "All (by trip stats)"));
|
out->stats_by_trip[0].location = strdup(translate("gettextFromC", "All (by trip stats)"));
|
||||||
|
|
||||||
process_dive(dp, &(stats_by_trip[trip_iter]));
|
process_dive(dp, &(out->stats_by_trip[trip_iter]));
|
||||||
stats_by_trip[trip_iter].selection_size++;
|
out->stats_by_trip[trip_iter].selection_size++;
|
||||||
stats_by_trip[trip_iter].is_trip = true;
|
out->stats_by_trip[trip_iter].is_trip = true;
|
||||||
stats_by_trip[trip_iter].location = dp->divetrip->location;
|
out->stats_by_trip[trip_iter].location = dp->divetrip->location;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* monthly statistics */
|
/* monthly statistics */
|
||||||
|
@ -202,14 +199,30 @@ void process_all_dives()
|
||||||
if (prev_month != current_month || prev_year != current_year)
|
if (prev_month != current_month || prev_year != current_year)
|
||||||
month_iter++;
|
month_iter++;
|
||||||
}
|
}
|
||||||
process_dive(dp, &(stats_monthly[month_iter]));
|
process_dive(dp, &(out->stats_monthly[month_iter]));
|
||||||
stats_monthly[month_iter].selection_size++;
|
out->stats_monthly[month_iter].selection_size++;
|
||||||
stats_monthly[month_iter].period = current_month;
|
out->stats_monthly[month_iter].period = current_month;
|
||||||
prev_month = current_month;
|
prev_month = current_month;
|
||||||
prev_year = current_year;
|
prev_year = current_year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_stats_summary(struct stats_summary *stats)
|
||||||
|
{
|
||||||
|
free(stats->stats_yearly);
|
||||||
|
free(stats->stats_monthly);
|
||||||
|
free(stats->stats_by_trip);
|
||||||
|
free(stats->stats_by_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_stats_summary(struct stats_summary *stats)
|
||||||
|
{
|
||||||
|
stats->stats_yearly = NULL;
|
||||||
|
stats->stats_monthly = NULL;
|
||||||
|
stats->stats_by_trip = NULL;
|
||||||
|
stats->stats_by_type = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* make sure we skip the selected summary entries */
|
/* make sure we skip the selected summary entries */
|
||||||
void process_selected_dives(void)
|
void process_selected_dives(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,10 +12,6 @@
|
||||||
#include "core/units.h"
|
#include "core/units.h"
|
||||||
#include "core/dive.h" // For MAX_CYLINDERS
|
#include "core/dive.h" // For MAX_CYLINDERS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int period;
|
int period;
|
||||||
|
@ -42,13 +38,22 @@ typedef struct
|
||||||
char *location;
|
char *location;
|
||||||
} stats_t;
|
} stats_t;
|
||||||
extern stats_t stats_selection;
|
extern stats_t stats_selection;
|
||||||
extern stats_t *stats_yearly;
|
|
||||||
extern stats_t *stats_monthly;
|
struct stats_summary {
|
||||||
extern stats_t *stats_by_trip;
|
stats_t *stats_yearly;
|
||||||
extern stats_t *stats_by_type;
|
stats_t *stats_monthly;
|
||||||
|
stats_t *stats_by_trip;
|
||||||
|
stats_t *stats_by_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern char *get_minutes(int seconds);
|
extern char *get_minutes(int seconds);
|
||||||
extern void process_all_dives();
|
extern void init_stats_summary(struct stats_summary *stats);
|
||||||
|
extern void free_stats_summary(struct stats_summary *stats);
|
||||||
|
extern void calculate_stats_summary(struct stats_summary *stats);
|
||||||
extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
|
extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
|
||||||
extern void process_selected_dives(void);
|
extern void process_selected_dives(void);
|
||||||
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
|
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
|
||||||
|
@ -57,4 +62,25 @@ void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For C++ code, provide a convenience version of stats_summary
|
||||||
|
* that initializes the structure on construction and frees
|
||||||
|
* resources when it goes out of scope. Apart from that, it
|
||||||
|
* can be used as a stats_summary replacement.
|
||||||
|
*/
|
||||||
|
#ifdef __cplusplus
|
||||||
|
struct stats_summary_auto_free : public stats_summary {
|
||||||
|
stats_summary_auto_free();
|
||||||
|
~stats_summary_auto_free();
|
||||||
|
};
|
||||||
|
inline stats_summary_auto_free::stats_summary_auto_free()
|
||||||
|
{
|
||||||
|
init_stats_summary(this);
|
||||||
|
}
|
||||||
|
inline stats_summary_auto_free::~stats_summary_auto_free()
|
||||||
|
{
|
||||||
|
free_stats_summary(this);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // STATISTICS_H
|
#endif // STATISTICS_H
|
||||||
|
|
|
@ -424,13 +424,7 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
editMode = IGNORE; // don't trigger on changes to the widgets
|
editMode = IGNORE; // don't trigger on changes to the widgets
|
||||||
|
|
||||||
// This method updates ALL tabs whenever a new dive or trip is
|
|
||||||
// selected.
|
|
||||||
// If exactly one trip has been selected, we show the location / notes
|
|
||||||
// for the trip in the Info tab, otherwise we show the info of the
|
|
||||||
// selected_dive
|
|
||||||
process_selected_dives();
|
process_selected_dives();
|
||||||
process_all_dives();
|
|
||||||
|
|
||||||
for (auto widget : extraWidgets) {
|
for (auto widget : extraWidgets) {
|
||||||
widget->updateData();
|
widget->updateData();
|
||||||
|
|
|
@ -207,8 +207,10 @@ QString TemplateLayout::generateStatistics()
|
||||||
QVariantList years;
|
QVariantList years;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (stats_yearly != NULL && stats_yearly[i].period) {
|
stats_summary_auto_free stats;
|
||||||
YearInfo year(stats_yearly[i]);
|
calculate_stats_summary(&stats);
|
||||||
|
while (stats.stats_yearly != NULL && stats.stats_yearly[i].period) {
|
||||||
|
YearInfo year(stats.stats_yearly[i]);
|
||||||
years.append(QVariant::fromValue(year));
|
years.append(QVariant::fromValue(year));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,13 +49,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
// this should have set up the informational preferences - let's grab
|
// this should have set up the informational preferences - let's grab
|
||||||
// the units from there
|
// the units from there
|
||||||
|
|
||||||
prefs.unit_system = git_prefs.unit_system;
|
prefs.unit_system = git_prefs.unit_system;
|
||||||
prefs.units = git_prefs.units;
|
prefs.units = git_prefs.units;
|
||||||
|
|
||||||
// populate the statistics
|
|
||||||
process_all_dives();
|
|
||||||
|
|
||||||
// now set up the export settings to create the HTML export
|
// now set up the export settings to create the HTML export
|
||||||
struct htmlExportSetting hes;
|
struct htmlExportSetting hes;
|
||||||
hes.themeFile = "sand.css";
|
hes.themeFile = "sand.css";
|
||||||
|
|
|
@ -176,13 +176,15 @@ void YearlyStatisticsModel::update_yearly_stats()
|
||||||
{
|
{
|
||||||
int i, month = 0;
|
int i, month = 0;
|
||||||
unsigned int j, combined_months;
|
unsigned int j, combined_months;
|
||||||
|
stats_summary_auto_free stats;
|
||||||
|
calculate_stats_summary(&stats);
|
||||||
|
|
||||||
for (i = 0; stats_yearly != NULL && stats_yearly[i].period; ++i) {
|
for (i = 0; stats.stats_yearly != NULL && stats.stats_yearly[i].period; ++i) {
|
||||||
YearStatisticsItem *item = new YearStatisticsItem(stats_yearly[i]);
|
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_yearly[i]);
|
||||||
combined_months = 0;
|
combined_months = 0;
|
||||||
for (j = 0; combined_months < stats_yearly[i].selection_size; ++j) {
|
for (j = 0; combined_months < stats.stats_yearly[i].selection_size; ++j) {
|
||||||
combined_months += stats_monthly[month].selection_size;
|
combined_months += stats.stats_monthly[month].selection_size;
|
||||||
YearStatisticsItem *iChild = new YearStatisticsItem(stats_monthly[month]);
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_monthly[month]);
|
||||||
item->children.append(iChild);
|
item->children.append(iChild);
|
||||||
iChild->parent = item;
|
iChild->parent = item;
|
||||||
month++;
|
month++;
|
||||||
|
@ -191,11 +193,10 @@ void YearlyStatisticsModel::update_yearly_stats()
|
||||||
item->parent = rootItem.get();
|
item->parent = rootItem.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stats.stats_by_trip != NULL && stats.stats_by_trip[0].is_trip == true) {
|
||||||
if (stats_by_trip != NULL && stats_by_trip[0].is_trip == true) {
|
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_by_trip[0]);
|
||||||
YearStatisticsItem *item = new YearStatisticsItem(stats_by_trip[0]);
|
for (i = 1; stats.stats_by_trip != NULL && stats.stats_by_trip[i].is_trip; ++i) {
|
||||||
for (i = 1; stats_by_trip != NULL && stats_by_trip[i].is_trip; ++i) {
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_by_trip[i]);
|
||||||
YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_trip[i]);
|
|
||||||
item->children.append(iChild);
|
item->children.append(iChild);
|
||||||
iChild->parent = item;
|
iChild->parent = item;
|
||||||
}
|
}
|
||||||
|
@ -204,12 +205,12 @@ void YearlyStatisticsModel::update_yearly_stats()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show the statistic sorted by dive type */
|
/* Show the statistic sorted by dive type */
|
||||||
if (stats_by_type != NULL && stats_by_type[0].selection_size) {
|
if (stats.stats_by_type != NULL && stats.stats_by_type[0].selection_size) {
|
||||||
YearStatisticsItem *item = new YearStatisticsItem(stats_by_type[0]);
|
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_by_type[0]);
|
||||||
for (i = 1; i <= NUM_DIVEMODE; ++i) {
|
for (i = 1; i <= NUM_DIVEMODE; ++i) {
|
||||||
if (stats_by_type[i].selection_size == 0)
|
if (stats.stats_by_type[i].selection_size == 0)
|
||||||
continue;
|
continue;
|
||||||
YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_type[i]);
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_by_type[i]);
|
||||||
item->children.append(iChild);
|
item->children.append(iChild);
|
||||||
iChild->parent = item;
|
iChild->parent = item;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue