naneos.frames
pandas DataFrame helpers for NaneosDeviceDataPoint lists.
Frames are indexed by unix_timestamp (ms) and keyed by serial number in the dict[int, pd.DataFrame] structures that flow from the managers to the upload.
add_data_points_to_dict(devices, points)
Append data points to the per-serial frames, one pandas round per device.
Source code in src/naneos/frames.py
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 | |
add_to_existing_naneos_data(data, new_data)
Merge a second dict of frames into the first, concatenating per serial.
Source code in src/naneos/frames.py
146 147 148 149 150 151 152 153 154 155 156 | |
aggregate_duplicate_index(df)
Collapse rows that share an index label into one row per label.
Used by the upload after the index has been rounded to whole seconds: a device read at 10 Hz or 100 Hz must still reach the backend at 1 Hz. Measurements are averaged, device_status is OR-ed so that an error flagged in any sample survives, everything else keeps its last known value.
Source code in src/naneos/frames.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
device_type_of(df, default=DeviceType.P2)
The device type recorded in a frame, or default when none is known.
Source code in src/naneos/frames.py
247 248 249 250 251 252 253 254 | |
sort_and_clean_naneos_data(data, serial_only=None)
Prepare gathered frames for the upload.
Per device: keep only the rows of the best connection type (serial over BLE link), sort by time, drop duplicate timestamps (last wins) and settle on one device type. Devices listed in serial_only are restricted to their serial rows even if none arrived.
Source code in src/naneos/frames.py
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 211 | |
to_pandas_df(points)
Build a single DataFrame from many data points, indexed by unix_timestamp.
Points are converted in one batch: a DataFrame construction, an astype and a concat per point is the single most expensive thing this library does on a Raspberry Pi Zero 2 W.
Source code in src/naneos/frames.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |