| 283 | } // namespace details |
| 284 | |
| 285 | void TrackArchiveReader::ParseUserTracksFromFile(string const & logFile, UserToTrack & userToTrack) const |
| 286 | { |
| 287 | // Read file content |
| 288 | FileReader reader(logFile); |
| 289 | string archiveData; |
| 290 | reader.ReadAsString(archiveData); |
| 291 | |
| 292 | // Unzip data |
| 293 | using Inflate = coding::ZLib::Inflate; |
| 294 | Inflate inflate(Inflate::Format::GZip); |
| 295 | string logData; |
| 296 | inflate(archiveData.data(), archiveData.size(), back_inserter(logData)); |
| 297 | |
| 298 | // Parse log |
| 299 | TemporaryFile tmpArchiveFile("" /* empty prefix */, kTmpArchiveFileNameTemplate); |
| 300 | stringstream logParser; |
| 301 | logParser << logData; |
| 302 | |
| 303 | size_t linesCount = 0; |
| 304 | size_t errorsCount = 0; |
| 305 | for (string line; getline(logParser, line); ++linesCount) |
| 306 | { |
| 307 | optional<details::UserTrackInfo> data = details::ParseLogRecord(line, tmpArchiveFile); |
| 308 | |
| 309 | if (data) |
| 310 | { |
| 311 | Track & track = userToTrack[data->m_userId]; |
| 312 | track.insert(track.end(), data->m_track.cbegin(), data->m_track.cend()); |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | ++errorsCount; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | LOG(LINFO, ("Process", linesCount, "log records")); |
| 321 | if (errorsCount == 0) |
| 322 | LOG(LINFO, ("All records are parsed successfully")); |
| 323 | else |
| 324 | LOG(LERROR, ("Unable to parse", errorsCount, "records")); |
| 325 | } |
| 326 | } // namespace track_analyzing |
nothing calls this directly
no test coverage detected