-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[map][tracking] Archieve tracker - bicycles, pedestrians, cars.
- Loading branch information
1 parent
f544be9
commit 15ff0c2
Showing
36 changed files
with
1,303 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ omim_link_libraries( | |
coding | ||
base | ||
stats_client | ||
oauthcpp | ||
${LIBZ} | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ omim_link_libraries( | |
minizip | ||
succinct | ||
stats_client | ||
oauthcpp | ||
${Qt5Widgets_LIBRARIES} | ||
${LIBZ} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ omim_link_libraries( | |
base | ||
jansson | ||
stats_client | ||
oauthcpp | ||
${LIBZ} | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ omim_link_libraries( | |
icu | ||
expat | ||
stats_client | ||
oauthcpp | ||
freetype | ||
gmock | ||
stb_image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ omim_link_libraries( | |
base | ||
expat | ||
stats_client | ||
oauthcpp | ||
freetype | ||
stb_image | ||
sdf_image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ omim_link_libraries( | |
coding | ||
base | ||
stats_client | ||
oauthcpp | ||
${LIBZ} | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ omim_link_libraries( | |
mwm_diff | ||
bsdiff | ||
platform | ||
oauthcpp | ||
coding | ||
base | ||
stats_client | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ omim_link_libraries( | |
coding | ||
base | ||
stats_client | ||
oauthcpp | ||
gflags | ||
${LIBZ} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ omim_link_libraries( | |
succinct | ||
pugixml | ||
stats_client | ||
oauthcpp | ||
${LIBZ} | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ omim_link_libraries( | |
geometry | ||
base | ||
stats_client | ||
oauthcpp | ||
jansson | ||
${LIBZ}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ omim_link_libraries( | |
base | ||
expat | ||
stats_client | ||
oauthcpp | ||
freetype | ||
stb_image | ||
sdf_image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ omim_link_libraries( | |
storage | ||
indexer | ||
platform | ||
oauthcpp | ||
coding | ||
geometry | ||
base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#include "tracking/archival_file.hpp" | ||
|
||
#include "platform/platform.hpp" | ||
|
||
#include "coding/zip_creator.hpp" | ||
|
||
#include "base/assert.hpp" | ||
#include "base/file_name_utils.hpp" | ||
#include "base/logging.hpp" | ||
|
||
#include <exception> | ||
|
||
#include "defines.hpp" | ||
|
||
namespace | ||
{ | ||
#ifdef DEBUG | ||
size_t constexpr kMaxFilesTotalSizeToSendBytes = 100 * 1024; // 0.1 Mb | ||
#else | ||
size_t constexpr kMaxFilesTotalSizeToSendBytes = 1000 * 1024; // 1 Mb | ||
#endif | ||
|
||
char constexpr kDelimiter = '_'; | ||
} // namespace | ||
|
||
namespace tracking | ||
{ | ||
namespace archival_file | ||
{ | ||
void FilesAccumulator::HandleFile(std::string const & fileName) | ||
{ | ||
uint64_t fileSize = 0; | ||
if (!Platform::GetFileSizeByFullPath(fileName, fileSize)) | ||
{ | ||
LOG(LDEBUG, ("File does not exist", fileName)); | ||
return; | ||
} | ||
if (fileSize == 0) | ||
{ | ||
LOG(LDEBUG, ("File is empty", fileName)); | ||
base::DeleteFileX(fileName); | ||
return; | ||
} | ||
if (fileSize > kMaxFilesTotalSizeToSendBytes) | ||
{ | ||
LOG(LDEBUG, ("File is too large", fileName, fileSize)); | ||
base::DeleteFileX(fileName); | ||
return; | ||
} | ||
|
||
FileInfo const meta = ParseArchiveFilename(fileName); | ||
auto const insData = m_filesByType.emplace(meta.m_trackType, FilesBatch()); | ||
auto const it = insData.first; | ||
auto & fileBatch = it->second; | ||
if (!insData.second) | ||
{ | ||
if (fileBatch.m_totalSize + fileSize > kMaxFilesTotalSizeToSendBytes) | ||
return; | ||
} | ||
|
||
fileBatch.m_totalSize += fileSize; | ||
fileBatch.m_files.push_back(fileName); | ||
} | ||
|
||
std::vector<std::string> FilesAccumulator::PrepareArchives(std::string const & path) | ||
{ | ||
std::vector<std::string> archives; | ||
try | ||
{ | ||
for (auto const & it : m_filesByType) | ||
{ | ||
if (it.second.m_files.empty()) | ||
continue; | ||
std::string const archivePath = | ||
base::JoinPath(path, base::GetNameFromFullPathWithoutExt(it.second.m_files[0]) + | ||
ARCHIVE_TRACKS_ZIPPED_FILE_EXTENSION); | ||
|
||
if (CreateZipFromFiles(it.second.m_files, archivePath, CompressionLevel::NoCompression)) | ||
archives.emplace_back(archivePath); | ||
} | ||
} | ||
catch (std::exception const & e) | ||
{ | ||
LOG(LWARNING, ("Error while archiving files", e.what())); | ||
} | ||
return archives; | ||
} | ||
|
||
void FilesAccumulator::DeleteProcessedFiles() | ||
{ | ||
for (auto const & it : m_filesByType) | ||
{ | ||
for (auto const & file : it.second.m_files) | ||
base::DeleteFileX(file); | ||
} | ||
} | ||
|
||
std::string GetArchiveFilename(uint8_t protocolVersion, std::chrono::seconds timestamp, | ||
routing::RouterType const & trackType) | ||
{ | ||
std::string filename; | ||
size_t constexpr kTrackFilenameSize = 20; | ||
filename.reserve(kTrackFilenameSize); // All filename parts have fixed length. | ||
filename = std::to_string(protocolVersion) + kDelimiter + std::to_string(timestamp.count()) + | ||
kDelimiter + std::to_string(static_cast<uint8_t>(trackType)) + | ||
ARCHIVE_TRACKS_FILE_EXTENSION; | ||
CHECK_EQUAL(filename.size(), kTrackFilenameSize, ()); | ||
return filename; | ||
} | ||
|
||
FileInfo ParseArchiveFilename(std::string const & fileName) | ||
{ | ||
std::string const metaData = base::GetNameFromFullPathWithoutExt(fileName); | ||
size_t const indexFirstDelim = metaData.find(kDelimiter); | ||
size_t const indexLastDelim = metaData.rfind(kDelimiter); | ||
if (indexFirstDelim != 1 || indexLastDelim != 12) | ||
{ | ||
LOG(LWARNING, ("Could not find delimiters in filename", fileName)); | ||
return {}; | ||
} | ||
|
||
try | ||
{ | ||
FileInfo res; | ||
res.m_protocolVersion = static_cast<uint32_t>(std::stoul(metaData.substr(0, indexFirstDelim))); | ||
res.m_timestamp = | ||
std::stoul(metaData.substr(indexFirstDelim + 1, indexLastDelim - indexFirstDelim - 1)); | ||
res.m_trackType = | ||
static_cast<routing::RouterType>(std::stoul(metaData.substr(indexLastDelim + 1))); | ||
return res; | ||
} | ||
catch (std::exception const & e) | ||
{ | ||
LOG(LWARNING, ("Error while parsing filename", e.what())); | ||
} | ||
return {}; | ||
} | ||
} // namespace archival_file | ||
} // namespace tracking |
Oops, something went wrong.