diff --git a/checkin_notes b/checkin_notes index 15290b74b2..e457831c18 100755 --- a/checkin_notes +++ b/checkin_notes @@ -10285,3 +10285,18 @@ David 10 Aug 2005 bbcode.php sched/ db_purge.C + +David 10 Aug 2005 + - changed logic of some daily-stats-related code + in attempt to fix crash on VC 8 + - rename STATISTIC to DAILY_STATS + + client/ + client_types.C,h + cs_account.C + scheduler_op.C + clientgui/ + ViewStatistics.cpp + lib/ + gui_rpc_client.h + gui_rpc_client_ops.C diff --git a/client/client_types.C b/client/client_types.C index 1d8656ddd4..c5fe1cfa6e 100644 --- a/client/client_types.C +++ b/client/client_types.C @@ -331,7 +331,7 @@ int PROJECT::write_statistics(MIOFILE& out, bool /*gui_rpc*/) { master_url ); - for (std::vector::iterator i=statistics.begin(); + for (std::vector::iterator i=statistics.begin(); i!=statistics.end(); ++i ) { out.printf( diff --git a/client/client_types.h b/client/client_types.h index e19f16c61c..fffbed078d 100644 --- a/client/client_types.h +++ b/client/client_types.h @@ -132,12 +132,16 @@ struct FILE_REF { // statistics at a specific day // -struct STATISTIC { +struct DAILY_STATS { double user_total_credit; double user_expavg_credit; double host_total_credit; double host_expavg_credit; double day; + + void clear(); + DAILY_STATS() {clear();} + int parse(FILE*); }; // reasons for attach failure @@ -316,7 +320,7 @@ public: bool waiting_until_min_rpc_time(); // statistic of the last x days - std::vector statistics; + std::vector statistics; int parse_statistics(MIOFILE&); int parse_statistics(FILE*); int write_statistics(MIOFILE&, bool gui_rpc=false); diff --git a/client/cs_account.C b/client/cs_account.C index fba5c55aed..ac66a16527 100644 --- a/client/cs_account.C +++ b/client/cs_account.C @@ -222,31 +222,40 @@ int CLIENT_STATE::parse_account_files() { return 0; } +void DAILY_STATS::clear() { + memset(this, 0, sizeof(DAILY_STATS)); +} + +int DAILY_STATS::parse(FILE* in) { + char buf[256]; + clear(); + while (fgets(buf, 256, in)) { + if (match_tag(buf, "")) return 0; + else if (parse_double(buf, "", day)) continue; + else if (parse_double(buf, "", user_total_credit)) continue; + else if (parse_double(buf, "", user_expavg_credit)) continue; + else if (parse_double(buf, "", host_total_credit)) continue; + else if (parse_double(buf, "", host_expavg_credit)) continue; + } + return ERR_XML_PARSE; +} + // parse an statistics_*.xml file // int PROJECT::parse_statistics(FILE* in) { - SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_STATE); - - bool open_daily_statistics=false; + int retval; char buf[256]; + SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_STATE); + while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; else if (match_tag(buf, "")) continue; else if (match_tag(buf, "")) { - if (open_daily_statistics) break; - open_daily_statistics=true; - statistics.push_back(STATISTIC()); - continue; - } - else if (parse_double(buf, "", statistics.back().day)) continue; - else if (parse_double(buf, "", statistics.back().user_total_credit)) continue; - else if (parse_double(buf, "", statistics.back().user_expavg_credit)) continue; - else if (parse_double(buf, "", statistics.back().host_total_credit)) continue; - else if (parse_double(buf, "", statistics.back().host_expavg_credit)) continue; - else if (match_tag(buf, "")) { - if (!open_daily_statistics) break; - open_daily_statistics=false; + DAILY_STATS daily_stats; + retval = daily_stats.parse(in); + if (retval) return retval; + statistics.push_back(daily_stats); continue; } else if (parse_str(buf, "", master_url, sizeof(master_url))) { @@ -283,7 +292,7 @@ int CLIENT_STATE::parse_statistics_files() { "Project for statistic file %s not found - ignoring", name.c_str() ); } else { - for (std::vector::const_iterator i=temp->statistics.begin(); + for (std::vector::const_iterator i=temp->statistics.begin(); i!=temp->statistics.end(); ++i ) { project->statistics.push_back(*i); @@ -309,7 +318,7 @@ int PROJECT::write_statistics_file() { master_url ); - for (std::vector::iterator i=statistics.begin(); + for (std::vector::iterator i=statistics.begin(); i!=statistics.end(); ++i ) { fprintf(f, diff --git a/client/scheduler_op.C b/client/scheduler_op.C index b066ebe2b2..3404dd080e 100644 --- a/client/scheduler_op.C +++ b/client/scheduler_op.C @@ -573,19 +573,21 @@ int SCHEDULER_REPLY::parse(FILE* in, PROJECT* project) { // check if vector is empty or we have a new day if (project->statistics.empty() || project->statistics.back().day!=dday()) { + // check if max. number of statistics already saved while (project->statistics.size()>30) { project->statistics.erase(project->statistics.begin()); } - project->statistics.push_back(STATISTIC()); + DAILY_STATS nds; + project->statistics.push_back(nds); } - - project->statistics.back().day=dday(); - project->statistics.back().user_total_credit=project->user_total_credit; - project->statistics.back().user_expavg_credit=project->user_expavg_credit; - project->statistics.back().host_total_credit=project->host_total_credit; - project->statistics.back().host_expavg_credit=project->host_expavg_credit; + DAILY_STATS& ds = project->statistics.back(); + ds.day=dday(); + ds.user_total_credit=project->user_total_credit; + ds.user_expavg_credit=project->user_expavg_credit; + ds.host_total_credit=project->host_total_credit; + ds.host_expavg_credit=project->host_expavg_credit; project->write_statistics_file(); diff --git a/clientgui/ViewStatistics.cpp b/clientgui/ViewStatistics.cpp index 3204536c97..8702e6543e 100644 --- a/clientgui/ViewStatistics.cpp +++ b/clientgui/ViewStatistics.cpp @@ -156,7 +156,7 @@ void CPaintStatistics::OnPaint(wxPaintEvent& WXUNUSED(event)) { //Find minimum/maximum value double min_val=10e32, max_val=0; - for (std::vector::const_iterator j=(*i)->statistics.begin(); + for (std::vector::const_iterator j=(*i)->statistics.begin(); j!=(*i)->statistics.end();++j) { if (m_SelectedStatistic==0) { @@ -207,7 +207,7 @@ void CPaintStatistics::OnPaint(wxPaintEvent& WXUNUSED(event)) { //Draw day numbers and lines marking the days wxCoord xpos=rectangle_x_start; - for (std::vector::const_iterator j=(*i)->statistics.begin(); j!=(*i)->statistics.end(); ++j) { + for (std::vector::const_iterator j=(*i)->statistics.begin(); j!=(*i)->statistics.end(); ++j) { double day=dday()-j->day; day=day/(60*60*24); dc.SetPen(wxPen(wxColour (0 , 0 , 0) , 1 , wxSOLID)); @@ -230,7 +230,7 @@ void CPaintStatistics::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxCoord last_x=rectangle_x_start, last_y=0, xpos=rectangle_x_start, ypos=0; - for (std::vector::const_iterator j=(*i)->statistics.begin(); j!=(*i)->statistics.end(); ++j) { + for (std::vector::const_iterator j=(*i)->statistics.begin(); j!=(*i)->statistics.end(); ++j) { ypos=rectangle_y_end - 1 - (yscale * (j->user_total_credit-min_val)); if (m_SelectedStatistic==0) { diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index 5239daf54d..f580293923 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -102,12 +102,14 @@ struct GUI_URL { // statistics at a specific day // -struct STATISTIC { +struct DAILY_STATS { double user_total_credit; double user_expavg_credit; double host_total_credit; double host_expavg_credit; double day; + + int parse(MIOFILE&); }; @@ -145,7 +147,7 @@ public: void get_name(std::string&); // statistic of the last x days - std::vector statistics; + std::vector statistics; }; class APP { diff --git a/lib/gui_rpc_client_ops.C b/lib/gui_rpc_client_ops.C index eaa1a561aa..40834bb337 100644 --- a/lib/gui_rpc_client_ops.C +++ b/lib/gui_rpc_client_ops.C @@ -1002,6 +1002,19 @@ int RPC_CLIENT::get_disk_usage(PROJECTS& p) { return 0; } +int DAILY_STATS::parse(MIOFILE& in) { + char buf[256]; + while (in.fgets(buf, 256)) { + if (match_tag(buf, "")) return 0; + else if (parse_double(buf, "", day)) continue; + else if (parse_double(buf, "", user_total_credit)) continue; + else if (parse_double(buf, "", user_expavg_credit)) continue; + else if (parse_double(buf, "", host_total_credit)) continue; + else if (parse_double(buf, "", host_expavg_credit)) continue; + } + return ERR_XML_PARSE; +} + int RPC_CLIENT::get_statistics(PROJECTS& p) { char buf[256]; RPC rpc(this); @@ -1022,16 +1035,10 @@ int RPC_CLIENT::get_statistics(PROJECTS& p) { if (match_tag(buf, "")) break; else if (parse_str(buf, "", p.projects.back()->master_url)) continue; else if (match_tag(buf, "")) { - p.projects.back()->statistics.push_back(STATISTIC()); - - while (rpc.fin.fgets(buf, 256)) { - if (match_tag(buf, "")) break; - else if (parse_double(buf, "", p.projects.back()->statistics.back().day)) continue; - else if (parse_double(buf, "", p.projects.back()->statistics.back().user_total_credit)) continue; - else if (parse_double(buf, "", p.projects.back()->statistics.back().user_expavg_credit)) continue; - else if (parse_double(buf, "", p.projects.back()->statistics.back().host_total_credit)) continue; - else if (parse_double(buf, "", p.projects.back()->statistics.back().host_expavg_credit)) continue; - } + DAILY_STATS ds; + retval = ds.parse(rpc.fin); + if (retval) return retval; + p.projects.back()->statistics.push_back(ds); } } }