2010-07-27 22:41:56 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-06-16 18:07:44 +02:00
|
|
|
* Copyright (c) 2010-2021, Tomasz Sowa
|
2010-07-27 22:41:56 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2010-07-27 22:41:56 +02:00
|
|
|
*/
|
|
|
|
|
2010-09-30 00:41:34 +02:00
|
|
|
#ifndef headerfile_winix_plugins_stats_stats
|
|
|
|
#define headerfile_winix_plugins_stats_stats
|
2010-07-27 22:41:56 +02:00
|
|
|
|
|
|
|
#include <string>
|
2010-08-10 18:12:50 +02:00
|
|
|
#include <map>
|
|
|
|
#include <fstream>
|
|
|
|
#include "core/config.h"
|
2021-06-16 18:07:44 +02:00
|
|
|
#include "core/winixmodeldeprecated.h"
|
2018-11-21 12:03:53 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
2010-07-27 22:41:56 +02:00
|
|
|
|
|
|
|
namespace Stats
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
struct Stats : public WinixModelDeprecated
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
Stats();
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void ReadStats();
|
|
|
|
void SaveStats();
|
|
|
|
void PeriodicSave();
|
|
|
|
void ReadConfig(Config * config);
|
|
|
|
void RemoveItem(long id);
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// file name for reading/saving statistics
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring stats_file;
|
|
|
|
std::string astats_file;
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// when the statistics start
|
|
|
|
time_t stats_start;
|
|
|
|
|
|
|
|
int global_all;
|
|
|
|
int global_unique;
|
|
|
|
|
|
|
|
int global_google;
|
|
|
|
int global_yahoo;
|
2010-08-28 23:19:30 +02:00
|
|
|
int global_bing;
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
// statistics for files/dirs
|
|
|
|
struct ItemStats
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
int all;
|
|
|
|
int google;
|
|
|
|
int yahoo;
|
2010-08-28 23:19:30 +02:00
|
|
|
int bing;
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
ItemStats()
|
|
|
|
{
|
|
|
|
all = 0;
|
|
|
|
google = 0;
|
|
|
|
yahoo = 0;
|
2010-08-28 23:19:30 +02:00
|
|
|
bing = 0;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
};
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// <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);
|
|
|
|
|
|
|
|
};
|
2010-07-27 22:41:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
} // namespace
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
#endif
|