提交 697a290a authored 作者: blu's avatar blu

big refacting of communitation architect

上级 5391e33d
...@@ -36,7 +36,7 @@ void ftime2ctime(fs::file_time_type ftime) ...@@ -36,7 +36,7 @@ void ftime2ctime(fs::file_time_type ftime)
std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl; std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl;
} }
vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileName, list<long> &tsRing, list<long> &tsNeedProc) vector<long> LoadVideoFiles(string path, int days, int maxSlices, map<long, string> &ts2fileName, list<long> &tsRing, list<long> &tsNeedProc)
{ {
vector<long> v; vector<long> v;
// get current timestamp // get current timestamp
...@@ -60,10 +60,10 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam ...@@ -60,10 +60,10 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam
// check old files // check old files
if(ts - now > days * 24 * 60 * 60) { if(ts - now > days * 24 * 60 * 60) {
spdlog::info("file {} old that {} days", entry.path().c_str(), days); spdlog::info("file {} old that {} days", entry.path().c_str(), days);
tsNeedProc.push_back(ts); tsNeedProc.insert(std::upper_bound(tsNeedProc.begin(), tsNeedProc.end(), ts), ts);
} }
else { else {
tsRing.insert(std::lower_bound(tsRing.begin(), tsRing.end(), ts), ts); tsRing.insert(std::upper_bound(tsRing.begin(), tsRing.end(), ts), ts);
} }
// add to map // add to map
...@@ -73,6 +73,26 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam ...@@ -73,6 +73,26 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam
catch(exception &e) { catch(exception &e) {
spdlog::error("LoasdVideoFiles exception : {}", e.what()); spdlog::error("LoasdVideoFiles exception : {}", e.what());
} }
// skip old items
list<long>olds;
int delta = maxSlices - tsRing.size();
int skip = delta < 0? (-delta):0;
spdlog::info("LoasdVideoFiles max: {}, current: {}, skip: {}",maxSlices, tsRing.size(), skip);
int idx = 0;
list<long>::iterator pos = tsRing.begin();
for(auto &i:tsRing) {
if(idx < skip) {
idx++;
pos++;
continue;
}
v.push_back(i);
}
// merge
if(skip > 0) {
tsNeedProc.insert(std::upper_bound(tsNeedProc.begin(), tsNeedProc.end(), tsRing.front()), tsRing.begin(), pos);
}
return v; return v;
} }
...@@ -85,9 +105,9 @@ int main(int argc, const char *argv[]) ...@@ -85,9 +105,9 @@ int main(int argc, const char *argv[])
list<long> tsProcess; list<long> tsProcess;
map<long, string> ts2fileName; map<long, string> ts2fileName;
LoadVideoFiles(path, 2, ts2fileName, tsRing, tsProcess); auto v = LoadVideoFiles(path, 2, 3, ts2fileName, tsRing, tsProcess);
for(auto &i:tsRing) { for(auto &i:v) {
spdlog::info("tsRing: {} file: {}", i, ts2fileName[i]); spdlog::info("tsRing: {} file: {}", i, ts2fileName[i]);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论