diff --git a/client/gui_rpc_server_ops.cpp b/client/gui_rpc_server_ops.cpp index 63a4dcbb1d..39ffd35e3c 100644 --- a/client/gui_rpc_server_ops.cpp +++ b/client/gui_rpc_server_ops.cpp @@ -614,10 +614,9 @@ static void handle_acct_mgr_info(GUI_RPC_CONN& grc) { static void handle_get_statistics(GUI_RPC_CONN& grc) { grc.mfout.printf("\n"); - for (std::vector::iterator i=gstate.projects.begin(); - i!=gstate.projects.end();++i - ) { - (*i)->write_statistics(grc.mfout,true); + for (unsigned int i=0; iwrite_statistics(grc.mfout); } grc.mfout.printf("\n"); } diff --git a/client/project.cpp b/client/project.cpp index b1547c8107..10f9c43c3c 100644 --- a/client/project.cpp +++ b/client/project.cpp @@ -551,9 +551,10 @@ void PROJECT::copy_state_fields(PROJECT& p) { use_symlinks = p.use_symlinks; } -// Write project statistic to project statistics file +// Write project statistic to GUI RPC reply // -int PROJECT::write_statistics(MIOFILE& out, bool /*gui_rpc*/) { +int PROJECT::write_statistics(MIOFILE& out) { + trim_statistics(); out.printf( "\n" " %s\n", @@ -831,3 +832,26 @@ bool PROJECT::waiting_until_min_rpc_time() { return (min_rpc_time > gstate.now); } +void PROJECT::trim_statistics() { + double cutoff = dday() - config.save_stats_days*86400; + // delete old stats; fill in the gaps if some days missing + // + while (!statistics.empty()) { + DAILY_STATS& ds = statistics[0]; + if (ds.day >= cutoff) { + break; + } + if (statistics.size() > 1) { + DAILY_STATS& ds2 = statistics[1]; + if (ds2.day <= cutoff) { + statistics.erase(statistics.begin()); + } else { + ds.day = cutoff; + break; + } + } else { + ds.day = cutoff; + break; + } + } +} diff --git a/client/project.h b/client/project.h index 980757812d..2c8f88b3df 100644 --- a/client/project.h +++ b/client/project.h @@ -305,8 +305,9 @@ struct PROJECT : PROJ_AM { std::vector statistics; int parse_statistics(MIOFILE&); int parse_statistics(FILE*); - int write_statistics(MIOFILE&, bool gui_rpc=false); + int write_statistics(MIOFILE&); int write_statistics_file(); + void trim_statistics(); void suspend(); void resume(); diff --git a/client/scheduler_op.cpp b/client/scheduler_op.cpp index f64513eb45..252458222c 100644 --- a/client/scheduler_op.cpp +++ b/client/scheduler_op.cpp @@ -608,28 +608,7 @@ int SCHEDULER_REPLY::parse(FILE* in, PROJECT* project) { // add new record if vector is empty or we have a new day // if (project->statistics.empty() || project->statistics.back().day!=dday()) { - double cutoff = dday() - config.save_stats_days*86400; - // delete old stats; fill in the gaps if some days missing - // - while (!project->statistics.empty()) { - DAILY_STATS& ds = project->statistics[0]; - if (ds.day >= cutoff) { - break; - } - if (project->statistics.size() > 1) { - DAILY_STATS& ds2 = project->statistics[1]; - if (ds2.day <= cutoff) { - project->statistics.erase(project->statistics.begin()); - } else { - ds.day = cutoff; - break; - } - } else { - ds.day = cutoff; - break; - } - } - + project->trim_statistics(); DAILY_STATS nds; project->statistics.push_back(nds); }