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:
@@ -1,18 +1,84 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
bot.o: bot.h
|
||||
init.o: ../../core/log.h ../../core/request.h ../../core/requesttypes.h
|
||||
init.o: ../../core/session.h ../../core/item.h ../../core/error.h
|
||||
init.o: ../../core/log.h ../../core/user.h ../../core/rebus.h
|
||||
init.o: ../../core/plugindata.h ../../core/function.h ../../core/thread.h
|
||||
init.o: ../../core/compress.h ../../core/acceptencodingparser.h
|
||||
init.o: ../../core/acceptbaseparser.h ../../core/htmlfilter.h
|
||||
init.o: ../../core/postmultiparser.h ../../core/ticket.h ../../core/config.h
|
||||
init.o: ../../confparser/confparser.h ../../core/db.h ../../core/group.h
|
||||
init.o: ../../core/dircontainer.h ../../core/ugcontainer.h stats.h
|
||||
init.o: templates.h ../../core/plugin.h ../../core/request.h data.h
|
||||
init.o: ../../core/plugindata.h ../../core/pluginmsg.h
|
||||
stats.o: stats.h data.h ../../core/plugindata.h ../../core/log.h
|
||||
templates.o: templates.h ../../core/plugin.h ../../core/request.h data.h
|
||||
templates.o: stats.h ../../core/plugindata.h ../../core/pluginmsg.h
|
||||
templates.o: ../../core/log.h ../../core/plugindata.h ../../../ezc/src/ezc.h
|
||||
templates.o: ../../core/misc.h ../../core/item.h
|
||||
init.o: ../../core/log.h ../../core/user.h ../../core/plugindata.h
|
||||
init.o: ../../core/rebus.h ../../core/thread.h ../../core/compress.h
|
||||
init.o: ../../core/acceptencodingparser.h ../../core/acceptbaseparser.h
|
||||
init.o: ../../core/htmlfilter.h ../../core/postmultiparser.h
|
||||
init.o: ../../core/config.h ../../core/confparser.h ../../core/ticket.h
|
||||
init.o: ../../core/config.h ../../core/db.h ../../core/group.h
|
||||
init.o: ../../core/dircontainer.h ../../core/ugcontainer.h bot.h stats.h
|
||||
init.o: templates.h ../../core/plugin.h ../../core/pluginmsg.h
|
||||
init.o: ../../core/request.h ../../core/system.h ../../core/dirs.h
|
||||
init.o: ../../core/db.h ../../core/mounts.h ../../core/mount.h
|
||||
init.o: ../../core/users.h ../../core/lastcontainer.h ../../core/groups.h
|
||||
init.o: ../../core/loadavg.h ../../core/sessionmanager.h
|
||||
init.o: ../../core/sessioncontainer.h ../../functions/functions.h
|
||||
init.o: ../../functions/functionbase.h ../../core/item.h ../../core/system.h
|
||||
init.o: ../../core/notify.h ../../templatesnotify/templatesnotify.h
|
||||
init.o: ../../../ezc/src/ezc.h ../../core/mount.h ../../core/locale.h
|
||||
init.o: ../../templates/misc.h ../../templates/localefilter.h
|
||||
init.o: ../../core/locale.h ../../functions/functionparser.h
|
||||
init.o: ../../functions/adduser.h ../../functions/cat.h
|
||||
init.o: ../../functions/chmod.h ../../functions/privchanger.h
|
||||
init.o: ../../functions/chown.h ../../functions/cp.h
|
||||
init.o: ../../functions/createthread.h ../../functions/createticket.h
|
||||
init.o: ../../functions/default.h ../../functions/download.h
|
||||
init.o: ../../functions/editticket.h ../../functions/emacs.h
|
||||
init.o: ../../functions/last.h ../../functions/login.h
|
||||
init.o: ../../functions/logout.h ../../functions/ls.h ../../functions/mkdir.h
|
||||
init.o: ../../functions/mv.h ../../functions/node.h ../../functions/priv.h
|
||||
init.o: ../../functions/reload.h ../../functions/rm.h ../../functions/run.h
|
||||
init.o: ../../functions/subject.h ../../functions/funthread.h
|
||||
init.o: ../../core/thread.h ../../functions/funticket.h
|
||||
init.o: ../../functions/uname.h ../../functions/upload.h
|
||||
init.o: ../../functions/who.h ../../templates/templates.h
|
||||
init.o: ../../templates/patterncacher.h ../../core/item.h
|
||||
init.o: ../../templates/misc.h ../../templates/ckeditorgetparser.h
|
||||
init.o: ../../core/httpsimpleparser.h ../../core/log.h
|
||||
init.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h
|
||||
init.o: statssession.h ../../core/plugindata.h
|
||||
stats.o: stats.h ../../core/log.h
|
||||
templates.o: templates.h ../../core/plugin.h ../../core/pluginmsg.h
|
||||
templates.o: ../../core/log.h ../../core/plugindata.h ../../core/config.h
|
||||
templates.o: ../../core/confparser.h ../../core/request.h ../../core/system.h
|
||||
templates.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h
|
||||
templates.o: ../../core/db.h ../../core/mounts.h ../../core/mount.h
|
||||
templates.o: ../../core/error.h ../../core/users.h ../../core/user.h
|
||||
templates.o: ../../core/ugcontainer.h ../../core/lastcontainer.h
|
||||
templates.o: ../../core/groups.h ../../core/group.h ../../core/rebus.h
|
||||
templates.o: ../../core/loadavg.h ../../core/sessionmanager.h
|
||||
templates.o: ../../core/sessioncontainer.h ../../core/session.h
|
||||
templates.o: ../../functions/functions.h ../../functions/functionbase.h
|
||||
templates.o: ../../core/item.h ../../core/db.h ../../core/thread.h
|
||||
templates.o: ../../core/ticket.h ../../core/request.h
|
||||
templates.o: ../../core/requesttypes.h ../../core/compress.h
|
||||
templates.o: ../../core/acceptencodingparser.h ../../core/acceptbaseparser.h
|
||||
templates.o: ../../core/htmlfilter.h ../../core/postmultiparser.h
|
||||
templates.o: ../../core/config.h ../../core/system.h ../../core/notify.h
|
||||
templates.o: ../../templatesnotify/templatesnotify.h ../../../ezc/src/ezc.h
|
||||
templates.o: ../../core/mount.h ../../core/locale.h ../../templates/misc.h
|
||||
templates.o: ../../templates/localefilter.h ../../core/locale.h
|
||||
templates.o: ../../functions/functionparser.h ../../functions/adduser.h
|
||||
templates.o: ../../functions/cat.h ../../functions/chmod.h
|
||||
templates.o: ../../functions/privchanger.h ../../functions/chown.h
|
||||
templates.o: ../../functions/cp.h ../../functions/createthread.h
|
||||
templates.o: ../../functions/createticket.h ../../functions/default.h
|
||||
templates.o: ../../functions/download.h ../../functions/editticket.h
|
||||
templates.o: ../../functions/emacs.h ../../functions/last.h
|
||||
templates.o: ../../functions/login.h ../../functions/logout.h
|
||||
templates.o: ../../functions/ls.h ../../functions/mkdir.h
|
||||
templates.o: ../../functions/mv.h ../../functions/node.h
|
||||
templates.o: ../../functions/priv.h ../../functions/reload.h
|
||||
templates.o: ../../functions/rm.h ../../functions/run.h
|
||||
templates.o: ../../functions/subject.h ../../functions/funthread.h
|
||||
templates.o: ../../core/thread.h ../../functions/funticket.h
|
||||
templates.o: ../../functions/uname.h ../../functions/upload.h
|
||||
templates.o: ../../functions/who.h ../../templates/templates.h
|
||||
templates.o: ../../templates/patterncacher.h ../../core/item.h
|
||||
templates.o: ../../templates/misc.h ../../templates/ckeditorgetparser.h
|
||||
templates.o: ../../core/httpsimpleparser.h ../../core/log.h
|
||||
templates.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h
|
||||
templates.o: ../../core/misc.h stats.h
|
||||
|
@@ -1 +1 @@
|
||||
o = init.o stats.o templates.o
|
||||
o = bot.o init.o stats.o templates.o
|
||||
|
45
plugins/stats/bot.cpp
Executable file
45
plugins/stats/bot.cpp
Executable file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "bot.h"
|
||||
|
||||
namespace Stats
|
||||
{
|
||||
|
||||
|
||||
|
||||
void Bot::SetBrowserName(const char * name)
|
||||
{
|
||||
browser_name = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Bot::BrowserNameHas(const char * name)
|
||||
{
|
||||
return strstr(browser_name, name) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Bot::IsGoogle()
|
||||
{
|
||||
return BrowserNameHas("Googlebot") && BrowserNameHas("www.google.com");
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Bot::IsYahoo()
|
||||
{
|
||||
return BrowserNameHas("Yahoo!") && BrowserNameHas("yahoo.com");
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
40
plugins/stats/bot.h
Executable file
40
plugins/stats/bot.h
Executable file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmsluplugin_stats_bot
|
||||
#define headerfilecmsluplugin_stats_bot
|
||||
|
||||
|
||||
namespace Stats
|
||||
{
|
||||
|
||||
|
||||
|
||||
struct Bot
|
||||
{
|
||||
void SetBrowserName(const char * name);
|
||||
|
||||
bool IsGoogle();
|
||||
bool IsYahoo();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
const char * browser_name;
|
||||
|
||||
bool BrowserNameHas(const char * name);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
@@ -8,15 +8,16 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <map>
|
||||
#include "core/log.h"
|
||||
#include "core/request.h"
|
||||
#include "core/config.h"
|
||||
#include "core/db.h"
|
||||
|
||||
#include "bot.h"
|
||||
#include "stats.h"
|
||||
#include "templates.h"
|
||||
#include "data.h"
|
||||
#include "statssession.h"
|
||||
|
||||
|
||||
extern "C" void Init(PluginInfo &);
|
||||
const char plugin_name[] = "stats";
|
||||
@@ -25,126 +26,86 @@ const char plugin_name[] = "stats";
|
||||
namespace Stats
|
||||
{
|
||||
|
||||
// when the statistics start
|
||||
time_t stats_start;
|
||||
|
||||
|
||||
// statistics for all pages
|
||||
StatsGlobal stat_global;
|
||||
|
||||
// statistics for one item
|
||||
// <item_id, Stats>
|
||||
std::map<long, Stats> stats_tab;
|
||||
|
||||
|
||||
// when to save the config (how many requests should have gone)
|
||||
// (for safety: power failure etc)
|
||||
// default: 1000
|
||||
// you can set: stats_req_save_freq in the config file to overwrite it
|
||||
// 0 - turn it off
|
||||
int req_save_freq = 1000;
|
||||
int req_current = 0; // helper
|
||||
Stats stats;
|
||||
Bot bot;
|
||||
long current_item_id;
|
||||
|
||||
|
||||
|
||||
|
||||
long ItemId()
|
||||
|
||||
void CalcItemId(Request * request)
|
||||
{
|
||||
long item_id;
|
||||
|
||||
if( request.is_item )
|
||||
item_id = request.item.id;
|
||||
if( request->is_item )
|
||||
current_item_id = request->item.id;
|
||||
else
|
||||
item_id = request.dir_table.back()->id;
|
||||
|
||||
return item_id;
|
||||
if( !request->dir_table.empty() )
|
||||
current_item_id = request->dir_table.back()->id;
|
||||
else
|
||||
current_item_id = -1;
|
||||
}
|
||||
|
||||
|
||||
void CheckSaving()
|
||||
{
|
||||
req_current += 1;
|
||||
|
||||
if( req_save_freq != 0 && req_current >= req_save_freq )
|
||||
|
||||
|
||||
void UpdateStats(PluginInfo & info, Stats::ItemStats & item_stats)
|
||||
{
|
||||
bot.SetBrowserName(info.request->env_http_user_agent);
|
||||
|
||||
stats.global_all += 1;
|
||||
item_stats.all += 1;
|
||||
|
||||
if( bot.IsGoogle() )
|
||||
{
|
||||
SaveStats();
|
||||
req_current = 0;
|
||||
stats.global_google += 1;
|
||||
item_stats.google += 1;
|
||||
}
|
||||
|
||||
if( bot.IsYahoo() )
|
||||
{
|
||||
stats.global_yahoo += 1;
|
||||
item_stats.yahoo += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool BrowserHas(const char * name)
|
||||
{
|
||||
const char * is = strstr(request.env_http_user_agent, name);
|
||||
return is != 0;
|
||||
}
|
||||
|
||||
|
||||
bool IsGoogle()
|
||||
{
|
||||
return BrowserHas("Googlebot") && BrowserHas("www.google.com");
|
||||
}
|
||||
|
||||
|
||||
bool IsYahoo()
|
||||
{
|
||||
return BrowserHas("Yahoo!") && BrowserHas("yahoo.com");
|
||||
}
|
||||
|
||||
|
||||
void UpdateStats(Stats & item_stats)
|
||||
{
|
||||
stat_global.all += 1;
|
||||
item_stats.all += 1;
|
||||
|
||||
if( IsGoogle() )
|
||||
{
|
||||
stat_global.google += 1;
|
||||
item_stats.google += 1;
|
||||
}
|
||||
|
||||
if( IsYahoo() )
|
||||
{
|
||||
stat_global.yahoo += 1;
|
||||
item_stats.yahoo += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ContentMake(PluginInfo & info)
|
||||
{
|
||||
StatsData * d = 0;
|
||||
StatsSession * stats_session = 0;
|
||||
|
||||
long id = ItemId();
|
||||
CalcItemId(info.request);
|
||||
|
||||
if( info.plugin_data_base )
|
||||
d = reinterpret_cast<StatsData*>(info.plugin_data_base);
|
||||
|
||||
// this simply prevents F5 (refresh) from a webbrowser
|
||||
if( d && d->last_visited != -1 && d->last_visited == id )
|
||||
if( current_item_id == - 1 || !info.plugin_data_base )
|
||||
return;
|
||||
|
||||
if( d )
|
||||
d->last_visited = id;
|
||||
stats_session = reinterpret_cast<StatsSession*>(info.plugin_data_base);
|
||||
|
||||
UpdateStats(stats_tab[id]);
|
||||
// this simply prevents F5 (refresh) from a webbrowser
|
||||
if( stats_session->last_visited != -1 &&
|
||||
stats_session->last_visited == current_item_id )
|
||||
return;
|
||||
|
||||
if( d && !d->calculated )
|
||||
stats_session->last_visited = current_item_id;
|
||||
|
||||
UpdateStats(info, stats.stats_tab[current_item_id]);
|
||||
|
||||
if( !stats_session->calculated )
|
||||
{
|
||||
stat_global.unique += 1;
|
||||
d->calculated = true;
|
||||
stats.global_unique += 1;
|
||||
stats_session->calculated = true;
|
||||
}
|
||||
|
||||
CheckSaving();
|
||||
stats.PeriodicSave();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionCreated(PluginInfo & info)
|
||||
{
|
||||
StatsData * d = new StatsData();
|
||||
request.session->plugin_data.Assign(d);
|
||||
StatsSession * d = new StatsSession();
|
||||
info.request->session->plugin_data.Assign(d);
|
||||
|
||||
log << log3 << "created stats plugin data"
|
||||
<< ", plugin id: " << info.plugin_id
|
||||
@@ -164,43 +125,18 @@ void RemoveSession(PluginInfo & info)
|
||||
|
||||
|
||||
|
||||
void ReadConfig()
|
||||
|
||||
void Close(PluginInfo & info)
|
||||
{
|
||||
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_file: " << stats_file << logend;
|
||||
|
||||
stats_start = time(0); // it will be overwritten if the config file exists
|
||||
ReadStats();
|
||||
stats.SaveStats();
|
||||
}
|
||||
|
||||
|
||||
void Close()
|
||||
{
|
||||
SaveStats();
|
||||
}
|
||||
|
||||
|
||||
void RemoveItem(long id)
|
||||
{
|
||||
std::map<long, Stats>::iterator i = stats_tab.find(id);
|
||||
|
||||
if( i == stats_tab.end() )
|
||||
return;
|
||||
|
||||
stats_tab.erase(i);
|
||||
log << log3 << "Stats: removed stats for item.id: " << id << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RemoveFile(PluginInfo & info)
|
||||
{
|
||||
RemoveItem(info.l1);
|
||||
stats.RemoveItem(info.l1);
|
||||
}
|
||||
|
||||
|
||||
@@ -210,16 +146,17 @@ Db::ItemQuery query;
|
||||
std::vector<long> items;
|
||||
size_t i;
|
||||
|
||||
// !! may only files can be retrieved here?
|
||||
query.SetAll(false, false);
|
||||
query.WhereParentId(info.l1);
|
||||
db.GetItems(items, query);
|
||||
info.db->GetItems(items, query);
|
||||
|
||||
// removing childs
|
||||
for(i=0 ; i<items.size() ; ++i)
|
||||
RemoveItem(items[i]);
|
||||
stats.RemoveItem(items[i]);
|
||||
|
||||
// removing the directory
|
||||
RemoveItem(info.l1);
|
||||
stats.RemoveItem(info.l1);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,6 +164,7 @@ size_t i;
|
||||
|
||||
|
||||
|
||||
|
||||
void Init(PluginInfo & info)
|
||||
{
|
||||
using namespace Stats;
|
||||
@@ -235,11 +173,13 @@ using namespace Stats;
|
||||
plugin.Assign(WINIX_CONTENT_MAKE, ContentMake);
|
||||
plugin.Assign(WINIX_SESSION_CREATED, SessionCreated);
|
||||
plugin.Assign(WINIX_SESSION_REMOVE, RemoveSession);
|
||||
plugin.Assign(WINIX_PLUGIN_INIT, ReadConfig);
|
||||
plugin.Assign(WINIX_CLOSE, Close);
|
||||
plugin.Assign(WINIX_FILE_REMOVED, RemoveFile);
|
||||
plugin.Assign(WINIX_DIR_PREPARE_TO_REMOVE, RemoveDir);
|
||||
|
||||
stats.ReadConfig(info.config);
|
||||
stats.ReadStats();
|
||||
|
||||
info.p1 = (void*)plugin_name;
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
@@ -11,50 +11,79 @@
|
||||
#define headerfilecmsluplugin_stats_stats
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include "core/config.h"
|
||||
|
||||
|
||||
namespace Stats
|
||||
{
|
||||
|
||||
|
||||
struct StatsGlobal
|
||||
{
|
||||
int all;
|
||||
int unique;
|
||||
|
||||
int google;
|
||||
int yahoo;
|
||||
|
||||
StatsGlobal()
|
||||
{
|
||||
all = 0;
|
||||
unique = 0;
|
||||
google = 0;
|
||||
yahoo = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Stats
|
||||
{
|
||||
int all;
|
||||
int google;
|
||||
int yahoo;
|
||||
Stats();
|
||||
|
||||
Stats()
|
||||
void ReadStats();
|
||||
void SaveStats();
|
||||
void PeriodicSave();
|
||||
void ReadConfig(Config * config);
|
||||
void RemoveItem(long id);
|
||||
|
||||
// file name for reading/saving statistics
|
||||
std::string stats_file;
|
||||
|
||||
// when the statistics start
|
||||
time_t stats_start;
|
||||
|
||||
int global_all;
|
||||
int global_unique;
|
||||
|
||||
int global_google;
|
||||
int global_yahoo;
|
||||
|
||||
|
||||
|
||||
// statistics for files/dirs
|
||||
struct ItemStats
|
||||
{
|
||||
all = 0;
|
||||
google = 0;
|
||||
yahoo = 0;
|
||||
}
|
||||
int all;
|
||||
int google;
|
||||
int yahoo;
|
||||
|
||||
ItemStats()
|
||||
{
|
||||
all = 0;
|
||||
google = 0;
|
||||
yahoo = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// <item_id, Item_stats>
|
||||
typedef std::map<long, ItemStats> StatsTab;
|
||||
StatsTab stats_tab;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// when to save the config (how many requests should have gone)
|
||||
// (for safety: power failure etc)
|
||||
// default: 1000
|
||||
// you can set: stats_req_save_freq in the config file to overwrite it
|
||||
// 0 - turn it off
|
||||
int req_save_freq;
|
||||
int req_current; // helper
|
||||
|
||||
|
||||
void ReadStats(std::ifstream & file);
|
||||
void SaveStats(std::ofstream & file);
|
||||
|
||||
};
|
||||
|
||||
extern std::string stats_file;
|
||||
|
||||
void ReadStats();
|
||||
void SaveStats();
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -10,10 +10,7 @@
|
||||
#ifndef headerfilecmsluplugin_stats_data
|
||||
#define headerfilecmsluplugin_stats_data
|
||||
|
||||
#include "stats.h"
|
||||
#include <map>
|
||||
#include "core/plugindata.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
namespace Stats
|
||||
@@ -21,31 +18,19 @@ namespace Stats
|
||||
|
||||
|
||||
// session data for the plugin
|
||||
struct StatsData : public PluginDataBase
|
||||
struct StatsSession : public PluginDataBase
|
||||
{
|
||||
// whether this session has been calculated
|
||||
bool calculated;
|
||||
long last_visited;
|
||||
|
||||
StatsData()
|
||||
StatsSession()
|
||||
{
|
||||
calculated = false;
|
||||
last_visited = -1;
|
||||
}
|
||||
};
|
||||
|
||||
extern time_t stats_start;
|
||||
|
||||
// statistics for all pages
|
||||
extern StatsGlobal stat_global;
|
||||
|
||||
// statistics for one item
|
||||
// <item_id, Stats>
|
||||
extern std::map<long, Stats> stats_tab;
|
||||
|
||||
|
||||
long ItemId();
|
||||
|
||||
|
||||
} // namespace
|
||||
|
@@ -9,56 +9,60 @@
|
||||
|
||||
#include "templates.h"
|
||||
#include "ezc.h"
|
||||
#include "data.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
#include "stats.h"
|
||||
|
||||
|
||||
namespace Stats
|
||||
{
|
||||
extern long current_item_id;
|
||||
extern Stats stats;
|
||||
|
||||
|
||||
void stats_from(Ezc::Info & i)
|
||||
{
|
||||
i.out << DateToStrWithoutHours(stats_start);
|
||||
i.out << DateToStrWithoutHours(stats.stats_start);
|
||||
|
||||
}
|
||||
|
||||
void stats_all(Ezc::Info & i)
|
||||
{
|
||||
i.out << stat_global.all;
|
||||
i.out << stats.global_all;
|
||||
}
|
||||
|
||||
|
||||
void stats_unique(Ezc::Info & i)
|
||||
{
|
||||
i.out << stat_global.unique;
|
||||
i.out << stats.global_unique;
|
||||
}
|
||||
|
||||
|
||||
void stats_google(Ezc::Info & i)
|
||||
{
|
||||
i.out << stat_global.google;
|
||||
i.out << stats.global_google;
|
||||
}
|
||||
|
||||
|
||||
void stats_yahoo(Ezc::Info & i)
|
||||
{
|
||||
i.out << stat_global.yahoo;
|
||||
i.out << stats.global_yahoo;
|
||||
}
|
||||
|
||||
|
||||
void stats_item_all(Ezc::Info & i)
|
||||
{
|
||||
i.out << stats_tab[ItemId()].all;
|
||||
i.out << stats.stats_tab[current_item_id].all;
|
||||
}
|
||||
|
||||
|
||||
void stats_item_google(Ezc::Info & i)
|
||||
{
|
||||
i.out << stats_tab[ItemId()].google;
|
||||
i.out << stats.stats_tab[current_item_id].google;
|
||||
}
|
||||
|
||||
void stats_item_yahoo(Ezc::Info & i)
|
||||
{
|
||||
i.out << stats_tab[ItemId()].yahoo;
|
||||
i.out << stats.stats_tab[current_item_id].yahoo;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,12 +70,6 @@ void stats_item_yahoo(Ezc::Info & i)
|
||||
|
||||
void CreateFunctions(PluginInfo & info)
|
||||
{
|
||||
if( !info.p1 )
|
||||
{
|
||||
log << log1 << "S: functions object doesn't set" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
Ezc::Functions * fun = reinterpret_cast<Ezc::Functions*>(info.p1);
|
||||
|
||||
fun->Insert("stats_from", stats_from);
|
||||
|
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "core/plugin.h"
|
||||
|
||||
|
||||
|
||||
namespace Stats
|
||||
{
|
||||
|
||||
|
Reference in New Issue
Block a user