-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeasurements.cpp
210 lines (180 loc) · 6.55 KB
/
measurements.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
205
206
207
208
209
210
#include "measurements.h"
#include <cmath>
#include <set>
Measurements::Measurements(QObject *parent)
: QObject(parent), mMeasurements({}), mPositions({}), mBss({}),
mCurrentBss({}) {}
const QVector<Measurement> Measurements::measurements() const {
return mMeasurements;
}
const QVector<Position> Measurements::positions() const { return mPositions; }
const QVector<Bss> Measurements::bsss() const { return mBss; }
const QVector<MeasurementType> Measurements::measurementTypes() const {
return mMeasurementTypes;
}
qreal Measurements::maxZAt(int index) const {
if (index < 0 || index >= mPositions.size())
return NAN;
auto pos = mPositions.at(index);
double max_z = -INFINITY;
for (auto bss : mCurrentBss) {
auto iter = std::find_if(mMeasurements.begin(), mMeasurements.end(),
[pos, bss, this](Measurement measurement) -> bool {
return measurement.pos == pos &&
measurement.bss == bss &&
measurement.measurementType ==
this->mCurrentMeasurementType;
});
if (iter != mMeasurements.end())
max_z = std::max(max_z, static_cast<double>(iter->value));
}
if (std::isinf(max_z)) {
return NAN;
}
return max_z;
}
int Measurements::countAt(int index) const {
auto position = mPositions.at(index);
return std::count_if(mMeasurements.begin(), mMeasurements.end(),
[position](Measurement measurement) -> bool {
return measurement.pos == position;
});
}
QVector<Measurement> Measurements::measurementsAt(Position position) const {
QVector<Measurement> ret;
auto pos_iter = std::find(mPositions.begin(), mPositions.end(), position);
if (pos_iter != mPositions.end()) {
for (auto measurement : mMeasurements) {
if (measurement.pos == *pos_iter) {
ret.push_back(measurement);
}
}
}
return ret;
}
void Measurements::newMeasurementsAtPosition(
Position position, const QVector<MeasurementEntry> &values) {
auto pos_iter = std::find(mPositions.begin(), mPositions.end(), position);
if (pos_iter != mPositions.end()) {
emit preMeasurementAppended(mMeasurements.size(), values.size());
for (auto value : values) {
auto bss_iter = std::find(mBss.begin(), mBss.end(), value.bss);
if (bss_iter == mBss.end()) {
emit preBssAppended(mBss.size());
mBss.push_back(value.bss);
emit postBssAppended();
bss_iter = &(mBss.last());
}
auto type_iter =
std::find(mMeasurementTypes.begin(), mMeasurementTypes.end(),
value.measurementType);
if (type_iter == mMeasurementTypes.end()) {
emit preTypeAppended(mMeasurementTypes.size());
mMeasurementTypes.push_back(value.measurementType);
emit postTypeAppended();
type_iter = &(mMeasurementTypes.last());
}
mMeasurements.push_back(
Measurement{*(pos_iter), *(bss_iter), *(type_iter), value.value});
}
emit postMeasurementAppended();
emit positionChanged(std::distance(mPositions.begin(), pos_iter));
emit heatMapChanged();
}
}
void Measurements::addPosition(Position position) {
auto pos_iter = std::find_if(
mPositions.begin(), mPositions.end(),
[position](Position pos) -> bool { return pos == position; });
if (pos_iter == mPositions.end()) {
emit prePositionAppended(mPositions.size());
mPositions.push_back(position);
emit postPositionAppended();
}
}
QVector<Measurement> Measurements::removePosition(Position position) {
QVector<Measurement> measurementsRemoved;
auto pos_iter = std::find_if(
mPositions.begin(), mPositions.end(),
[position](Position pos) -> bool { return pos == position; });
if (pos_iter == mPositions.end()) {
return measurementsRemoved;
}
auto iter = mMeasurements.begin();
while (iter != mMeasurements.end()) {
if (iter->pos == *(pos_iter)) {
int i = std::distance(mMeasurements.begin(), iter);
emit preMeasurementRemoved(i);
measurementsRemoved.append(*iter);
mMeasurements.removeAt(i);
emit postMeasurementRemoved();
} else {
++iter;
}
}
auto bss_iter = mBss.begin();
while (bss_iter != mBss.end()) {
auto bss_count = std::count_if(mMeasurements.begin(), mMeasurements.end(),
[bss_iter](Measurement measurement) -> bool {
return measurement.bss == *bss_iter;
});
if (bss_count <= 0) {
auto bss_index = std::distance(mBss.begin(), bss_iter);
emit preBssRemoved(bss_index);
mBss.removeAt(bss_index);
emit postBssRemoved();
} else {
++bss_iter;
}
}
auto type_iter = mMeasurementTypes.begin();
while (type_iter != mMeasurementTypes.end()) {
auto type_count =
std::count_if(mMeasurements.begin(), mMeasurements.end(),
[type_iter](Measurement measurement) -> bool {
return measurement.measurementType == *type_iter;
});
if (type_count <= 0) {
auto type_index = std::distance(mMeasurementTypes.begin(), type_iter);
emit preTypeRemoved(type_index);
mMeasurementTypes.removeAt(type_index);
emit postTypeRemoved();
} else {
++type_iter;
}
}
auto pos_index = std::distance(mPositions.begin(), pos_iter);
emit prePositionRemoved(pos_index);
mPositions.removeAt(pos_index);
emit postPositionRemoved();
if (measurementsRemoved.size() > 0)
emit heatMapChanged();
return measurementsRemoved;
}
void Measurements::updatePosition(Position oldPosition, Position newPosition) {
auto pos_iter = std::find(mPositions.begin(), mPositions.end(), oldPosition);
if (pos_iter != mPositions.end()) {
for (auto iter = mMeasurements.begin(); iter != mMeasurements.end();
++iter) {
if (iter->pos == *pos_iter) {
iter->pos.pos = newPosition.pos;
}
}
pos_iter->pos = newPosition.pos;
emit positionChanged(std::distance(mPositions.begin(), pos_iter));
emit heatMapChanged();
}
}
void Measurements::selectedBssChanged(QVector<Bss> selectedBss) {
mCurrentBss = {};
for (auto a : selectedBss) {
mCurrentBss.push_back(a);
}
emit heatMapChanged();
}
void Measurements::selectedTypeChanged(MeasurementType selectedType) {
if (mCurrentMeasurementType == selectedType)
return;
mCurrentMeasurementType = selectedType;
emit heatMapChanged();
}