the first part of reimplementing has been done

now we have app object and singletons are only: log logn plugin and app



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-08-10 16:12:50 +00:00
parent 6897192364
commit 217cf1420b
191 changed files with 9529 additions and 7250 deletions

View File

@@ -8,30 +8,42 @@
*/
#include "stats.h"
#include <fstream>
#include "data.h"
#include "core/log.h"
#include <ctime>
namespace Stats
{
std::string stats_file;
Stats::Stats()
{
global_all = 0;
global_unique = 0;
global_google = 0;
global_yahoo = 0;
req_save_freq = 1000;
req_current = 0;
stats_start = time(0);
}
void ReadStats(std::ifstream & file)
void Stats::ReadStats(std::ifstream & file)
{
file >> stats_start;
file >> stat_global.all;
file >> stat_global.unique;
file >> stat_global.google;
file >> stat_global.yahoo;
file >> global_all;
file >> global_unique;
file >> global_google;
file >> global_yahoo;
size_t len;
file >> len;
Stats s;
ItemStats s;
long item_id;
for(size_t i = 0 ; i<len && !file.eof() ; ++i)
@@ -48,7 +60,7 @@ void ReadStats(std::ifstream & file)
void ReadStats()
void Stats::ReadStats()
{
if( stats_file.empty() )
return;
@@ -57,7 +69,7 @@ void ReadStats()
if( !file )
{
log << log1 << "Stats: I cannot open the stats file: " << stats_file << logend;
log << log1 << "Stats: I cannot open a file: " << stats_file << logend;
return;
}
@@ -71,19 +83,19 @@ void ReadStats()
void SaveStats(std::ofstream & file)
void Stats::SaveStats(std::ofstream & file)
{
file << stats_start << std::endl;
file << stat_global.all << ' ';
file << stat_global.unique << ' ';
file << stat_global.google << ' ';
file << stat_global.yahoo << ' ';
file << global_all << ' ';
file << global_unique << ' ';
file << global_google << ' ';
file << global_yahoo << ' ';
file << std::endl;
file << stats_tab.size() << std::endl;
std::map<long, Stats>::iterator i = stats_tab.begin();
StatsTab::iterator i = stats_tab.begin();
for( ; i != stats_tab.end() ; ++i)
{
@@ -96,7 +108,7 @@ void SaveStats(std::ofstream & file)
}
void SaveStats()
void Stats::SaveStats()
{
if( stats_file.empty() )
return;
@@ -105,7 +117,7 @@ void SaveStats()
if( !file )
{
log << log1 << "Stats: I cannot open the stats file: " << stats_file << logend;
log << log1 << "Stats: I cannot open a file: " << stats_file << logend;
return;
}
@@ -115,6 +127,49 @@ void SaveStats()
log << log3 << "Stats: statistics saved to: " << stats_file << logend;
}
void Stats::PeriodicSave()
{
req_current += 1;
if( req_save_freq != 0 && req_current >= req_save_freq )
{
SaveStats();
req_current = 0;
}
}
void Stats::ReadConfig(Config * config)
{
stats_file = config->Text("stats_file");
req_save_freq = config->Int("stats_req_save_freq", req_save_freq);
if( stats_file.empty() )
{
log << log1 << "you should set stats_file in your config to keep statistics between restarting winix" << logend;
}
else
{
log << log2 << "Stats: stats_file: " << stats_file << logend;
log << log2 << "Stats: statistics will be saved after each " << req_save_freq << " requests" << logend;
}
}
void Stats::RemoveItem(long id)
{
StatsTab::iterator i = stats_tab.find(id);
if( i == stats_tab.end() )
return;
stats_tab.erase(i);
log << log3 << "Stats: statistics erased for item: " << id << logend;
}
} // namespace