-
Notifications
You must be signed in to change notification settings - Fork 4
/
wintestplot.cpp
executable file
·204 lines (173 loc) · 5.43 KB
/
wintestplot.cpp
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
#include "wintestplot.h"
#include "ui_wintestplot.h"
#include "utilities.h"
WinTestPlot::WinTestPlot(QWidget *parent) :
QDialog(parent),
ui(new Ui::WinTestPlot)
{
ui->setupUi(this);
saveDefaultLabel();
}
WinTestPlot::~WinTestPlot()
{
delete ui;
}
void WinTestPlot::saveDefaultLabel()
{
n_read=ui->lbl_n_reads->text();
n_write=ui->lbl_b_writes->text();
rw_type=ui->lbl_rw_type->text();
}
void WinTestPlot::loadDefaultLabel()
{
ui->lbl_rw_type->setText("RW Type:");
ui->lbl_n_reads->setText("N° Read:");
ui->lbl_b_writes->setText("N° Write:");
avgData.clear();
}
void WinTestPlot::setupLables(const test_settings_t &test)
{
QString test_type;
get_string_from_test(&test_type,test);
ui->lbl_rw_type->setText(this->rw_type+" "+ test_type);
ui->lbl_n_reads->setText(this->n_read +" " +QString::number(test.n_read));
ui->lbl_b_writes->setText(this->n_write +" "+ QString::number(test.n_write));
if(test.type_test== AGGR)
ui->lbl_type_test->setText("Average throughput");
else
ui->lbl_type_test->setText("Average latency");
}
bool WinTestPlot::prepareForShowing(const test_settings_t& test)
{
if(!this->loadData(test))
return false;
setupAllPlotsAfterTest(avgData);
setupLables(test);
return true;
}
void WinTestPlot::on_pushButton_clicked()
{
ui->customPlot->clearPlottables();
loadDefaultLabel();
this->close();
}
bool WinTestPlot::loadData(const test_settings_t& test)
{
bool file=get_stat_from_file(avgData,test.type_test);
if (!file || avgData[0] == ERROR_FEW_DATA)
{
QString error_message;
if(!file)
error_message="File not found";
else
error_message="There are too few data!";
QMessageBox message(QMessageBox::Warning, "Error",
error_message,
QMessageBox::Ok ,
QDesktopWidget().screen());
message.exec();
return false;
}else
return file;
}
bool WinTestPlot::setupAllPlotsAfterTest(const QVector<double> data)
{
/*ASSUMO CHE I VALORI SIANO DIPOSTI IN QUESTO MODO:
* POSIZIONE VALORE
* 0 BFQ
* 1 CFQ
* 2 NOOP
* 3 DEADLINE
*/
if(data.length() > 4)
return false;
this->setupPlotAfterTest(ui->customPlot,data);
ui->customPlot->replot();
return true;
}
bool WinTestPlot::setData(QVector<sched_result_t> result, QString testo, type_test_t type)
{
//qDebug()<<result[0].sched<<result.length();
if(result[0].sched != BFQ || result.length() > 5)
return false;
if(type == AGGR)
{
avgData<<result[0].throug<<result[1].throug<<result[2].throug<<result[3].throug;
ui->lbl_type_test->setText("Average throughput");
}else
{
avgData<<result[0].lat<<result[1].lat<<result[2].lat<<result[3].lat;
ui->lbl_type_test->setText("Average latency");
}
//remove data and get a QString of it
QString date=QString("Date: "+testo.left(19));
testo.remove(0,19);
//get iteration if exists
QString iteration="";
if(type==STARTUP)
{
iteration=testo.right(13);
testo.remove(iteration);
}
ui->lbl_compare->setText(QString(testo + "\n" + date+"\t\t"+iteration));
ui->lbl_n_reads->setText("");
ui->lbl_b_writes->setText("");
ui->lbl_rw_type->setText("");
return true;
}
bool WinTestPlot::setGuiAfterData()
{
return this->setupAllPlotsAfterTest(avgData);
}
void WinTestPlot::setupPlotAfterTest(QCustomPlot *customPlot,const QVector<double> data)
{
QCPBars *avg = new QCPBars(customPlot->xAxis, customPlot->yAxis);
customPlot->addPlottable(avg);
// set names and colors:
QPen pen;
pen.setWidthF(1.5);
pen.setColor(QColor(255, 131, 0));
//Setting avg Bar
avg->setName("Average:");
avg->setPen(pen);
avg->setBrush(QColor(255, 131, 0, 50));
// prepare x axis with country labels:
QVector<double> ticks;
QVector<QString> labels;
/*latenza throughput read write*/
labels<<"BFQ"<<"CFQ"<<"NOOP"<<"DEADLINE";
ticks<<1<<3<<5<<7;
double max_value=get_max_from_data(data);
int offset = 5;
if(max_value<offset)
offset=max_value/4;
customPlot->yAxis->setRange(0,max_value+offset);
/*Impostazione asse X*/
customPlot->xAxis->setAutoTicks(false);
customPlot->xAxis->setAutoTickStep(false);
customPlot->xAxis->setTickStep(200);
customPlot->xAxis->setAutoTickLabels(false);
customPlot->xAxis->setTickVector(ticks);
customPlot->xAxis->setTickVectorLabels(labels);
customPlot->xAxis->setTickLabelRotation(0);
customPlot->xAxis->setTickLength(1, 3);
customPlot->xAxis->grid()->setVisible(true);
customPlot->xAxis->setRange(0, 8);
/*Impostazione asse Y*/
customPlot->yAxis->setPadding(2);
customPlot->yAxis->grid()->setSubGridVisible(true);
QPen gridPen;
gridPen.setStyle(Qt::SolidLine);
gridPen.setColor(QColor(0, 0, 0, 25));
customPlot->yAxis->grid()->setPen(gridPen);
gridPen.setStyle(Qt::DotLine);
customPlot->yAxis->grid()->setSubGridPen(gridPen);
/*Caricamento dati*/
avg->setData(ticks, data);
customPlot->axisRect()->setRangeDrag(Qt::Horizontal);
}
void WinTestPlot::closeEvent(QCloseEvent *event)
{
on_pushButton_clicked();
event->accept();
}