EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StatisticMgr.cpp
Go to the documentation of this file.
1 
12 #include "StatisticMgr.h"
14 
15 
17 : m_counter(3) // do first update 15m after server starts
18 {
20 }
21 
23 {
24  // save current data to db before exit.
25  SaveData();
26  sLog.Warning(" StatisticMgr", "Statistics Manager has been closed." );
27 }
28 
30 {
31  //ClearAll();
32  // reset current data for new session
34  sLog.Blue( " StatisticMgr", "Statistics Manager Initialized." );
35  return 1;
36 }
37 
39 {
41 }
42 
44 {
45  // return current data?
46 }
47 
48 // called every 15m by ConsoleCommands::UpdateStatus() from EntityList::Process()
50 {
51  SaveData();
52 
53  // check timers and manipulate data accordingly...
54  // this system is currently inaccurate. priority level: low
55  if (++m_counter > 4) { // every hour? provided proc call is 15m
56  m_counter = 0;
57  // every [increment][time] save stat history data
58  CompileData();
59  //sEntityList.ResetStartTime();
60  }
61  /*
62  * SELECT timeStamp, timeSpan, pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket FROM srvStatisticData
63  * SELECT month, pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket FROM srvStatisticHistory
64  */
65 }
66 
68 {
69  m_data.span = sEntityList.GetMinutes();
71 }
72 
73 void StatisticMgr::Add(uint8 key, double value)
74 {
75  m_data.span = sEntityList.GetMinutes();
76  switch(key) {
77  case Stat::pcBounties:
78  m_data.pcBounties += value;
79  break;
80  case Stat::npcBounties:
81  m_data.npcBounties += value;
82  break;
83  case Stat::oreMined:
84  m_data.oreMined += value;
85  break;
86  case Stat::iskMarket:
87  m_data.iskMarket += value;
88  break;
89  default:
90  sLog.Error("StatisticMgr::Add()", "Default reached for key %u.", key );
91  break;
92  }
93 }
94 
96 {
97  m_data.span = sEntityList.GetMinutes();
98  switch(key) {
99  case Stat::pcShots:
100  ++m_data.pcShots;
101  break;
102  case Stat::ramJobs:
103  ++m_data.ramJobs;
104  break;
105  case Stat::pcMissiles:
106  ++m_data.pcMissiles;
107  break;
108  case Stat::shipsSalvaged:
110  break;
111  case Stat::sitesScanned:
113  break;
116  break;
117  default:
118  sLog.Error("StatisticMgr::Increment()", "Default reached for key %u.", key );
119  break;
120  }
121 }
122 
124 {
125  m_data.span = sEntityList.GetMinutes();
126  sLog.Cyan(" StatisticMgr", " Time Span: %u minutes", m_data.span);
127  sLog.Cyan(" StatisticMgr", " PC Shots Fired: %u", m_data.pcShots);
128  sLog.Cyan(" StatisticMgr", " PC Missiles Fired: %u", m_data.pcMissiles);
129  sLog.Cyan(" StatisticMgr", " Scan Probes Launched: %u", m_data.probesLaunched);
130  sLog.Cyan(" StatisticMgr", " Cosmic Signals Scanned: %u", m_data.sitesScanned);
131  sLog.Cyan(" StatisticMgr", " PC Bounties Paid: %.2f isk", m_data.pcBounties);
132  sLog.Cyan(" StatisticMgr", " NPC Bounties Paid: %.2f isk", m_data.npcBounties);
133  sLog.Cyan(" StatisticMgr", " Ore Mined: %.2f m3", m_data.oreMined);
134  sLog.Cyan(" StatisticMgr", " ISK Spent in Market: %.2f isk", m_data.iskMarket);
135  sLog.Cyan(" StatisticMgr", " Ships Salvaged: %u", m_data.shipsSalvaged);
136  sLog.Cyan(" StatisticMgr", " R.A.M. Jobs: %u", m_data.ramJobs);
137 }
138 
140 {
141  DBQueryResult* res = new DBQueryResult();
142  DBResultRow row;
143  ManagerDB::GetStatisticData(*res, sEntityList.GetStartTime());
144  if (res->GetRowCount() > 0) {
145  StatisticData data = StatisticData();
146  while (res->GetRow(row)) {
147  //SELECT pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket, sitesScanned, probesLaunched FROM srvStatisticData
148  data.pcShots += row.GetInt(0);
149  data.pcMissiles += row.GetInt(1);
150  data.ramJobs += row.GetInt(2);
151  data.shipsSalvaged += row.GetInt(3);
152  data.pcBounties += row.GetFloat(4);
153  data.npcBounties += row.GetFloat(5);
154  data.oreMined += row.GetFloat(6);
155  data.iskMarket += row.GetFloat(7);
156  data.sitesScanned += row.GetInt(8);
157  data.probesLaunched += row.GetInt(9);
158  }
159 
160  if (data.pcShots == 0)
161  if (data.pcMissiles == 0)
162  if (data.iskMarket == 0)
163  if (data.oreMined == 0)
164  if (data.shipsSalvaged == 0)
165  if (data.ramJobs == 0)
166  if (data.pcBounties == 0)
167  if (data.npcBounties == 0)
168  if (data.probesLaunched == 0)
169  if (data.sitesScanned == 0)
170  return;
171 
172  // data has been compiled for this running session. save to history.
174  }
175 
176  SafeDelete(res);
177 }
178 
179 
unsigned __int8 uint8
Definition: eve-compat.h:46
static void GetStatisticData(DBQueryResult &res, int64 starttime)
Definition: ManagerDB.cpp:714
float GetFloat(uint32 index) const
Definition: dbcore.cpp:682
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
StatisticData m_data
Definition: StatisticMgr.h:61
#define sEntityList
Definition: EntityList.h:208
uint16 shipsSalvaged
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
uint16 probesLaunched
void Increment(uint8 key)
static void SaveStatisticData(StatisticData &data)
Definition: ManagerDB.cpp:723
void CompileData()
void Add(uint8 key, double value)
size_t GetRowCount()
Definition: dbcore.h:72
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type() key(value)-Send an OnRemoteMessage" ) COMMAND( setbpattr
static void UpdateStatisticHistory(StatisticData &data)
Definition: ManagerDB.cpp:737