INSTINCT Code Coverage Report


Directory: src/
File: Navigation/GNSS/Positioning/Observation.cpp
Date: 2025-07-19 10:51:51
Exec Total Coverage
Lines: 24 77 31.2%
Functions: 3 8 37.5%
Branches: 18 106 17.0%

Line Branch Exec Source
1 #include "Observation.hpp"
2 #include <array>
3 #include <cstddef>
4 #include <unordered_set>
5
6 #include "Navigation/GNSS/Core/SatelliteIdentifier.hpp"
7
8 namespace NAV
9 {
10
11 23582 size_t Observations::countObservations(const SatSigId& satSigId, const GnssObs::ObservationType& obsType) const
12 {
13
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 23579 times.
23582 if (!signals.contains(satSigId)) { return 0; }
14
15 23579 const auto& recvObs = signals.at(satSigId).recvObs;
16 23579 return static_cast<size_t>(std::ranges::count_if(recvObs, [&obsType](const auto& obs) {
17 47158 return obs.second->obs.contains(obsType);
18 23579 }));
19 }
20
21 5445 void Observations::recalcObservableCounts([[maybe_unused]] const std::string& nameId)
22 {
23 5445 std::array<std::unordered_set<SatId>, GnssObs::ObservationType_COUNT> nMeasUniqueSat;
24 5445 systems.clear();
25 5445 satellites.clear();
26
1/2
✓ Branch 1 taken 5445 times.
✗ Branch 2 not taken.
5445 nObservables.fill(0);
27
1/2
✓ Branch 1 taken 5445 times.
✗ Branch 2 not taken.
5445 nObservablesUniqueSatellite.fill(0);
28
29
2/2
✓ Branch 7 taken 269936 times.
✓ Branch 8 taken 5445 times.
275368 for (const auto& [satSigId, sigObs] : signals)
30 {
31
1/2
✓ Branch 1 taken 269939 times.
✗ Branch 2 not taken.
269938 auto satId = satSigId.toSatId();
32
1/2
✓ Branch 1 taken 269938 times.
✗ Branch 2 not taken.
269939 satellites.insert(satId);
33
1/2
✓ Branch 1 taken 269937 times.
✗ Branch 2 not taken.
269938 systems.insert(satId.satSys);
34
35 269937 const auto& recvObs = sigObs.recvObs.begin();
36
2/2
✓ Branch 7 taken 704038 times.
✓ Branch 8 taken 269923 times.
973970 for (const auto& obs : recvObs->second->obs)
37 {
38 704037 auto obsType = static_cast<size_t>(obs.first);
39
1/2
✓ Branch 1 taken 704033 times.
✗ Branch 2 not taken.
704037 nObservables.at(obsType)++;
40
2/4
✓ Branch 1 taken 704032 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 704034 times.
✗ Branch 5 not taken.
704033 nMeasUniqueSat.at(obsType).insert(satId);
41 }
42 }
43
44
2/2
✓ Branch 0 taken 16335 times.
✓ Branch 1 taken 5445 times.
21780 for (size_t obsType = 0; obsType < GnssObs::ObservationType_COUNT; obsType++)
45 {
46
2/4
✓ Branch 1 taken 16335 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 16335 times.
✗ Branch 6 not taken.
16335 nObservablesUniqueSatellite.at(obsType) = nMeasUniqueSat.at(obsType).size();
47 }
48
49 #if LOG_LEVEL <= LOG_LEVEL_DATA
50 LOG_DATA("{}: systems: [{}]", nameId, fmt::join(systems, ", "));
51 LOG_DATA("{}: satellites: [{}]", nameId, fmt::join(satellites, ", "));
52 std::string observables;
53 std::string observablesUnique;
54 for (size_t obsType = 0; obsType < GnssObs::ObservationType_COUNT; obsType++)
55 {
56 observables += fmt::format("{} {}", nObservables.at(obsType), static_cast<GnssObs::ObservationType>(obsType));
57 observablesUnique += fmt::format("{} {} [{}]", nObservablesUniqueSatellite.at(obsType),
58 static_cast<GnssObs::ObservationType>(obsType), fmt::join(nMeasUniqueSat.at(obsType), ", "));
59 if (obsType < GnssObs::ObservationType_COUNT - 1)
60 {
61 observables += ", ";
62 observablesUnique += ", ";
63 }
64 }
65 LOG_DATA("{}: nObservables: {}", nameId, observables);
66 LOG_DATA("{}: nObservablesUniqueSatellite: {}", nameId, observablesUnique);
67 #endif
68 5445 }
69
70 bool Observations::removeSignal(const SatSigId& satSigId, [[maybe_unused]] const std::string& nameId)
71 {
72 bool somethingRemoved = false;
73 if (signals.contains(satSigId))
74 {
75 LOG_DATA("{}: Erasing signal [{}]", nameId, satSigId);
76 signals.erase(satSigId);
77 somethingRemoved = true;
78 }
79 if (somethingRemoved) { recalcObservableCounts(nameId); }
80 return somethingRemoved;
81 }
82
83 bool Observations::removeSignal(const SatSigId& satSigId, const GnssObs::ObservationType& obsType, [[maybe_unused]] const std::string& nameId)
84 {
85 bool somethingRemoved = false;
86 if (signals.contains(satSigId))
87 {
88 LOG_DATA("{}: Erasing signal [{}][{}]", nameId, satSigId, obsType);
89 size_t emptyReceiver = 0;
90 for (auto& recvObs : signals.at(satSigId).recvObs)
91 {
92 if (recvObs.second->obs.contains(obsType))
93 {
94 recvObs.second->obs.erase(obsType);
95 }
96 if (recvObs.second->obs.empty()) { emptyReceiver++; }
97 }
98 if (emptyReceiver == signals.at(satSigId).recvObs.size())
99 {
100 signals.erase(satSigId);
101 }
102 somethingRemoved = true;
103 }
104 if (somethingRemoved) { recalcObservableCounts(nameId); }
105 return somethingRemoved;
106 }
107
108 bool Observations::removeSatellite(const SatId& satId, [[maybe_unused]] const std::string& nameId)
109 {
110 std::vector<SatSigId> toRemove;
111 for (const auto& signal : signals)
112 {
113 if (signal.first.toSatId() == satId)
114 {
115 toRemove.push_back(signal.first);
116 }
117 }
118 for (const auto& satSigId : toRemove)
119 {
120 LOG_DATA("{}: Erasing signal [{}]", nameId, satSigId);
121 signals.erase(satSigId);
122 }
123 if (!toRemove.empty()) { recalcObservableCounts(nameId); }
124 return !toRemove.empty();
125 }
126
127 bool Observations::removeMeasurementsFor(const Code& code, const GnssObs::ObservationType& obsType, [[maybe_unused]] const std::string& nameId)
128 {
129 LOG_DATA("{}: Searching observations to remove on [{}][{}]", nameId, code, obsType);
130 bool somethingRemoved = false;
131 for (auto& [satSigId, sigObs] : signals)
132 {
133 if (satSigId.code != code) { continue; }
134
135 for (size_t i = 0; i < sigObs.recvObs.size(); i++)
136 {
137 if (!sigObs.recvObs.contains(i)) { continue; }
138 auto& recvObs = sigObs.recvObs.at(i);
139 if (recvObs->obs.contains(obsType))
140 {
141 recvObs->obs.erase(obsType);
142 LOG_DATA("{}: Erasing observation [{}][{}] of receiver '{}'", nameId, satSigId, obsType, i);
143 somethingRemoved = true;
144 }
145 }
146 }
147 if (somethingRemoved) { recalcObservableCounts(nameId); }
148 return somethingRemoved;
149 }
150
151 bool Observations::removeObsType(const GnssObs::ObservationType& obsType, [[maybe_unused]] const std::string& nameId)
152 {
153 LOG_DATA("{}: Searching observations to remove on [{}]", nameId, obsType);
154 bool somethingRemoved = false;
155 for (auto& [satSigId, sigObs] : signals)
156 {
157 for (size_t i = 0; i < sigObs.recvObs.size(); i++)
158 {
159 if (!sigObs.recvObs.contains(i)) { continue; }
160 auto& recvObs = sigObs.recvObs.at(i);
161 if (recvObs->obs.contains(obsType))
162 {
163 recvObs->obs.erase(obsType);
164 LOG_DATA("{}: Erasing observation [{}][{}] of receiver '{}'", nameId, satSigId, obsType, i);
165 somethingRemoved = true;
166 }
167 }
168 }
169 if (somethingRemoved) { recalcObservableCounts(nameId); }
170 return somethingRemoved;
171 }
172
173 } // namespace NAV
174