121 lines
1.9 KiB
C++
Executable File
121 lines
1.9 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "stats.h"
|
|
#include <fstream>
|
|
#include "data.h"
|
|
#include "core/log.h"
|
|
|
|
|
|
namespace Stats
|
|
{
|
|
|
|
|
|
std::string stats_file;
|
|
|
|
|
|
void ReadStats(std::ifstream & file)
|
|
{
|
|
file >> stats_start;
|
|
file >> stat_global.all;
|
|
file >> stat_global.unique;
|
|
file >> stat_global.google;
|
|
file >> stat_global.yahoo;
|
|
|
|
size_t len;
|
|
file >> len;
|
|
|
|
Stats s;
|
|
long item_id;
|
|
|
|
for(size_t i = 0 ; i<len && !file.eof() ; ++i)
|
|
{
|
|
file >> item_id;
|
|
file >> s.all;
|
|
file >> s.google;
|
|
file >> s.yahoo;
|
|
|
|
stats_tab.insert( std::make_pair(item_id, s) );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReadStats()
|
|
{
|
|
if( stats_file.empty() )
|
|
return;
|
|
|
|
std::ifstream file(stats_file.c_str());
|
|
|
|
if( !file )
|
|
{
|
|
log << log1 << "Stats: I cannot open the stats file: " << stats_file << logend;
|
|
return;
|
|
}
|
|
|
|
ReadStats(file);
|
|
file.close();
|
|
|
|
log << log3 << "Stats: statistics loaded from: " << stats_file
|
|
<< " (" << stats_tab.size() << " items)" << logend;
|
|
}
|
|
|
|
|
|
|
|
|
|
void 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 << std::endl;
|
|
|
|
file << stats_tab.size() << std::endl;
|
|
|
|
std::map<long, Stats>::iterator i = stats_tab.begin();
|
|
|
|
for( ; i != stats_tab.end() ; ++i)
|
|
{
|
|
file << i->first << ' ';
|
|
file << i->second.all << ' ';
|
|
file << i->second.google << ' ';
|
|
file << i->second.yahoo << ' ';
|
|
file << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
void SaveStats()
|
|
{
|
|
if( stats_file.empty() )
|
|
return;
|
|
|
|
std::ofstream file(stats_file.c_str());
|
|
|
|
if( !file )
|
|
{
|
|
log << log1 << "Stats: I cannot open the stats file: " << stats_file << logend;
|
|
return;
|
|
}
|
|
|
|
SaveStats(file);
|
|
file.close();
|
|
|
|
log << log3 << "Stats: statistics saved to: " << stats_file << logend;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|