This repository has been archived by the owner on Jan 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.cpp
76 lines (60 loc) · 1.67 KB
/
worker.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
#include "worker.h"
#include <QTimer>
#include <QEventLoop>
#include <QThread>
#include <QDebug>
#include<input_file.h>
#include<struttura_dati.h>
#include<water_reading.h>
#include<visualizzaione.h>
Worker::Worker(QObject *parent) :
QObject(parent)
{
_working =false;
_abort = false;
}
void Worker::requestWork()
{
mutex.lock();
_working = true;
_abort = false;
qDebug()<<"Request di inizio lavoro "<<thread()->currentThreadId();
mutex.unlock();
emit workRequested();
}
void Worker::abort()
{
mutex.lock();
if (_working) {
_abort = true;
qDebug()<<"richiesta abort "<<thread()->currentThreadId();
}
mutex.unlock();
}
void Worker::doWork()
{
qDebug()<<"processo iniziato "<<thread()->currentThreadId();
for (auto x: Struttura_dati::Wreading)
{
Struttura_dati::map[x.first];
for (int month = 1; month <= 12; month++)
{
std::vector<double>consum_daily = visualizzaione::monthly(month,x.first); //acquisto i valori
//salvo nella mappa
//mi salvo la media di questo utente
double avg = 0;
for (size_t n = 0; n < consum_daily.size(); n++)
{
Struttura_dati::map.at(x.first).push_back(consum_daily.at(n));
Struttura_dati::avg_for_index.push_back(consum_daily.at(n));
}
consum_daily.clear();
consum_daily.shrink_to_fit();
}//for tutti i mesi
}//for id
mutex.lock();
_working = false;
mutex.unlock();
qDebug()<<"processo finito"<<thread()->currentThreadId();
emit finished();
}