-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhistorystatistics.cpp
More file actions
87 lines (77 loc) · 2.28 KB
/
historystatistics.cpp
File metadata and controls
87 lines (77 loc) · 2.28 KB
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
#include "historystatistics.h"
HistoryStatistics::HistoryStatistics(QObject *parent) : QObject(parent)
{
QFile file("statistics.log");
if(file.open(QFile::ReadOnly | QFile::Text)){
QTextStream in(&file);
while(!in.atEnd()){
QString key;
int value;
in>>key>>value;
if(key.isEmpty()){
continue;
}
record[key]=value;
qDebug()<<key<<": "<<value<<endl;
}
file.close();
}
else{
qDebug()<<tr("error: can't open statistic file")<<endl;
}
}
HistoryStatistics::~HistoryStatistics(){
qDebug()<<tr("destory HistoryStatistics")<<endl;
QFile file("statistics.log");
if(file.open(QFile::WriteOnly | QFile::Text)){
QTextStream out(&file);
for(QMap<QString,int>::const_iterator it = record.cbegin(); it != record.cend(); ++it){
out<<it.key()<<" "<<it.value()<<endl;
qDebug()<<it.key()<<": "<<it.value()<<endl;
}
out.flush();
file.close();
}
else{
qDebug()<<tr("error: can't open statistic file for update log")<<endl;
qDebug()<<file.error()<<endl;
qDebug()<<file.errorString()<<endl;
}
}
void HistoryStatistics::on_encode_triggered(int cnt){
record["encodeTimes"]+=1;
if(cnt>0){
record["encodeSuccessTimes"]+=1;
record["encodeBytesCount"]+=cnt;
}
}
void HistoryStatistics::on_decode_triggered(int cnt){
record["decodeTimes"]+=1;
if(cnt>0){
record["decodeSuccessTimes"]+=1;
record["decodeBytesCount"]+=cnt;
}
}
int HistoryStatistics::getDecodeBytesCount()const{
return record["decodeBytesCount"];
}
int HistoryStatistics::getEncodeBytesCount()const{
return record["encodeBytesCount"];
}
int HistoryStatistics::getDecodeTimes()const{
return record["decodeTimes"];
}
int HistoryStatistics::getEncodeTimes()const{
return record["encodeTimes"];
}
int HistoryStatistics::getDecodeSuccessTimes()const{
return record["decodeSuccessTimes"];
}
int HistoryStatistics::getEncodeSuccessTimes()const{
return record["encodeSuccessTimes"];
}
void HistoryStatistics::on_clearLog_triggered(){
for(QMap<QString,int>::iterator it = record.begin(); it != record.end(); ++it){
it.value()=0;
}
}