-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabnhelper.h
260 lines (219 loc) · 7.23 KB
/
abnhelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* GnuDialer - Complete, free predictive dialer
*
* Complete, free predictive dialer for contact centers.
*
* Copyright (C) 2006, GnuDialer Project
*
* Heath Schultz <[email protected]>
* Richard Lyman <[email protected]>
*
* This program is free software, distributed under the terms of
* the GNU General Public License.
*/
#include <string>
#include <iostream>
#include <time.h>
#include "itos.h"
#include "DBConnection.h"
// The purpose of this class is to make it so that
// we can keep track of abandons and calls throughout
// the life of the campaign without having to constantly
// write to queues.conf. Doing so has proven to be a
// bad idea for a multitude of reasons.
// Each campaign will have an AbnHelper object
#ifndef ABNHELPER
#define ABNHELPER
class AbnHelper
{
public:
AbnHelper() {}
~AbnHelper() {}
void Read(const std::string &name)
{
DBConnection dbConn;
u_long serverId = std::stoull(getServerId());
ParsedQueueOperations queueOperations = dbConn.fetchAbnStats(name, serverId, 3);
calls = std::to_string(queueOperations.calls);
totalcalls = std::to_string(queueOperations.totalcalls);
abandons = std::to_string(queueOperations.abandons);
totalabandons = std::to_string(queueOperations.totalabandons);
disconnects = std::to_string(queueOperations.disconnects);
noanswers = std::to_string(queueOperations.noanswers);
busies = std::to_string(queueOperations.busies);
congestions = std::to_string(queueOperations.congestions);
ansmachs = std::to_string(queueOperations.ansmachs);
itsName = name;
// Convert updated_at field to datestring
time_t updatedAtTime = static_cast<time_t>(queueOperations.updated_at); // Assuming updated_at is a time_t
tm *updated_tm = localtime(&updatedAtTime);
datestring = std::to_string(updated_tm->tm_mon + 1) + "-" +
std::to_string(updated_tm->tm_mday) + "-" +
std::to_string(updated_tm->tm_year + 1900);
}
void Read_OBSOLETE(const std::string &name)
{
std::string tDateString;
// time_t thetime;
timeval tv;
gettimeofday(&tv, NULL);
time_t thetime = tv.tv_sec;
tm *ptm = localtime(&thetime);
tDateString = itos(ptm->tm_mon + 1) + "-" + itos(ptm->tm_mday) + "-" + itos(ptm->tm_year + 1900);
std::ifstream InFile;
std::string filename = "/tmp/" +
name + ".helper." +
tDateString;
// std::system(("touch " + filename).c_str());
// std::system(("chmod a+rw " + filename).c_str());
// InFile.open(filename.c_str(),std::ios::app);
InFile.open(std::string("/tmp/" + name + ".helper" + "." + tDateString).c_str());
if (!InFile)
{
calls = "0";
totalcalls = "0";
abandons = "0";
totalabandons = "0";
datestring = tDateString;
// add dialer stats
disconnects = "0";
noanswers = "0";
busies = "0";
congestions = "0";
ansmachs = "0";
}
else
{
std::getline(InFile, calls, '\n');
std::getline(InFile, totalcalls, '\n');
std::getline(InFile, abandons, '\n');
std::getline(InFile, totalabandons, '\n');
std::getline(InFile, datestring, '\n');
// add dialer stats
std::getline(InFile, disconnects, '\n');
std::getline(InFile, noanswers, '\n');
std::getline(InFile, busies, '\n');
std::getline(InFile, congestions, '\n');
std::getline(InFile, ansmachs, '\n');
// new day reset all the counters
if (datestring != tDateString)
{
calls = "0";
abandons = "0";
datestring = tDateString;
// add dialer stats
disconnects = "0";
noanswers = "0";
busies = "0";
congestions = "0";
ansmachs = "0";
}
}
}
void Write(const std::string &name)
{
DBConnection dbConn;
// Prepare ParsedQueueOperations struct with current values
ParsedQueueOperations queueOperations;
queueOperations.calls = std::stoi(calls);
queueOperations.totalcalls = std::stoi(totalcalls);
queueOperations.abandons = std::stoi(abandons);
queueOperations.totalabandons = std::stoi(totalabandons);
queueOperations.disconnects = std::stoi(disconnects);
queueOperations.noanswers = std::stoi(noanswers);
queueOperations.busies = std::stoi(busies);
queueOperations.congestions = std::stoi(congestions);
queueOperations.ansmachs = std::stoi(ansmachs);
ulong serverId = std::stoul(getServerId());
// Attempt to write to the database
if (!dbConn.updateAbnStats(name, serverId, queueOperations))
{
std::cerr << "Error updating abandon stats in the database!" << std::endl;
}
}
void Write_OBSOLETE(const std::string &name)
{
std::string tDateString;
// time_t thetime;
timeval tv;
gettimeofday(&tv, NULL);
time_t thetime = tv.tv_sec;
tm *ptm = localtime(&thetime);
tDateString = itos(ptm->tm_mon + 1) + "-" + itos(ptm->tm_mday) + "-" + itos(ptm->tm_year + 1900);
std::ofstream OutFile;
// OutFile.open(static_cast<std::string>("/tmp/" + name + ".helper").c_str());
OutFile.open(std::string("/tmp/" + name + ".helper" + "." + tDateString).c_str());
if (!OutFile)
{
std::cerr << "Error writing to abandon helper file!" << std::endl;
}
else
{
OutFile << calls << std::endl;
OutFile << totalcalls << std::endl;
OutFile << abandons << std::endl;
OutFile << totalabandons << std::endl;
OutFile << datestring << std::endl;
// add dialer stats
OutFile << disconnects << std::endl;
OutFile << noanswers << std::endl;
OutFile << busies << std::endl;
OutFile << congestions << std::endl;
OutFile << ansmachs << std::endl;
OutFile.close();
std::string filename = "/tmp/" + name + ".helper." + tDateString;
std::system(("chmod a+rw " + filename).c_str());
}
}
const std::string &GetCalls() const { return calls; }
const std::string &GetTotalCalls() const { return totalcalls; }
const std::string &GetAbandons() const { return abandons; }
const std::string &GetTotalAbandons() const { return totalabandons; }
const std::string &GetDateString() const { return datestring; }
// add dialer stats
const std::string &GetDisconnects() const { return disconnects; }
const std::string &GetNoanswers() const { return noanswers; }
const std::string &GetBusies() const { return busies; }
const std::string &GetCongestions() const { return congestions; }
const std::string &GetAnsmachs() const { return ansmachs; }
void IncrementDisconnects()
{
disconnects = itos(atoi(disconnects.c_str()) + 1);
}
void IncrementNoanswers()
{
noanswers = itos(atoi(noanswers.c_str()) + 1);
}
void IncrementBusies()
{
busies = itos(atoi(busies.c_str()) + 1);
}
void IncrementCongestions()
{
congestions = itos(atoi(congestions.c_str()) + 1);
}
void IncrementAnsmachs()
{
ansmachs = itos(atoi(ansmachs.c_str()) + 1);
}
void DecrementAnsmachs()
{
ansmachs = itos(atoi(ansmachs.c_str()) - 1);
}
void IncrementAbandons()
{
// std::cout << "Current abandons: " << abandons << std::endl;
abandons = itos(atoi(abandons.c_str()) + 1);
totalabandons = itos(atoi(totalabandons.c_str()) + 1);
// std::cout << "Abandons now: " << abandons << std::endl;
}
void AddCallsDialed(const unsigned int &numCalls)
{
calls = itos(atoi(calls.c_str()) + numCalls);
totalcalls = itos(atoi(totalcalls.c_str()) + numCalls);
}
private:
std::string calls, totalcalls, abandons, totalabandons, abndate, datestring, disconnects, noanswers, busies, congestions, ansmachs;
std::string itsName;
};
#endif