Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 646:fb49bf72ac2d
fix issue #7
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Oct 2013 08:58:45 +0100 |
parents | ec0b7a51d7bd |
children | 08eca5d86aad |
comparison
equal
deleted
inserted
replaced
645:75af92b18e23 | 646:fb49bf72ac2d |
---|---|
1299 boost::mutex::scoped_lock lock(mutex_); | 1299 boost::mutex::scoped_lock lock(mutex_); |
1300 db_->ClearTable("ExportedResources"); | 1300 db_->ClearTable("ExportedResources"); |
1301 } | 1301 } |
1302 | 1302 |
1303 | 1303 |
1304 void ServerIndex::GetStatistics(Json::Value& target, | 1304 void ServerIndex::GetStatisticsInternal(/* out */ uint64_t& compressedSize, |
1305 const std::string& publicId) | 1305 /* out */ uint64_t& uncompressedSize, |
1306 { | 1306 /* out */ unsigned int& countStudies, |
1307 boost::mutex::scoped_lock lock(mutex_); | 1307 /* out */ unsigned int& countSeries, |
1308 | 1308 /* out */ unsigned int& countInstances, |
1309 ResourceType type; | 1309 /* in */ int64_t id, |
1310 int64_t top; | 1310 /* in */ ResourceType type) |
1311 if (!db_->LookupResource(publicId, top, type)) | 1311 { |
1312 { | |
1313 throw OrthancException(ErrorCode_UnknownResource); | |
1314 } | |
1315 | |
1316 std::stack<int64_t> toExplore; | 1312 std::stack<int64_t> toExplore; |
1317 toExplore.push(top); | 1313 toExplore.push(id); |
1318 | 1314 |
1319 int countInstances = 0; | 1315 countInstances = 0; |
1320 int countSeries = 0; | 1316 countSeries = 0; |
1321 int countStudies = 0; | 1317 countStudies = 0; |
1322 uint64_t compressedSize = 0; | 1318 compressedSize = 0; |
1323 uint64_t uncompressedSize = 0; | 1319 uncompressedSize = 0; |
1324 | 1320 |
1325 while (!toExplore.empty()) | 1321 while (!toExplore.empty()) |
1326 { | 1322 { |
1327 // Get the internal ID of the current resource | 1323 // Get the internal ID of the current resource |
1328 int64_t resource = toExplore.top(); | 1324 int64_t resource = toExplore.top(); |
1373 toExplore.push(*it); | 1369 toExplore.push(*it); |
1374 } | 1370 } |
1375 } | 1371 } |
1376 } | 1372 } |
1377 | 1373 |
1374 if (countStudies == 0) | |
1375 { | |
1376 countStudies = 1; | |
1377 } | |
1378 | |
1379 if (countSeries == 0) | |
1380 { | |
1381 countSeries = 1; | |
1382 } | |
1383 } | |
1384 | |
1385 | |
1386 | |
1387 void ServerIndex::GetStatistics(Json::Value& target, | |
1388 const std::string& publicId) | |
1389 { | |
1390 boost::mutex::scoped_lock lock(mutex_); | |
1391 | |
1392 ResourceType type; | |
1393 int64_t top; | |
1394 if (!db_->LookupResource(publicId, top, type)) | |
1395 { | |
1396 throw OrthancException(ErrorCode_UnknownResource); | |
1397 } | |
1398 | |
1399 uint64_t uncompressedSize; | |
1400 uint64_t compressedSize; | |
1401 unsigned int countStudies; | |
1402 unsigned int countSeries; | |
1403 unsigned int countInstances; | |
1404 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, | |
1405 countSeries, countInstances, top, type); | |
1406 | |
1378 target = Json::objectValue; | 1407 target = Json::objectValue; |
1379 target["DiskSize"] = boost::lexical_cast<std::string>(compressedSize); | 1408 target["DiskSize"] = boost::lexical_cast<std::string>(compressedSize); |
1380 target["DiskSizeMB"] = boost::lexical_cast<unsigned int>(compressedSize / MEGA_BYTES); | 1409 target["DiskSizeMB"] = boost::lexical_cast<unsigned int>(compressedSize / MEGA_BYTES); |
1381 target["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize); | 1410 target["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize); |
1382 target["UncompressedSizeMB"] = boost::lexical_cast<unsigned int>(uncompressedSize / MEGA_BYTES); | 1411 target["UncompressedSizeMB"] = boost::lexical_cast<unsigned int>(uncompressedSize / MEGA_BYTES); |
1395 | 1424 |
1396 case ResourceType_Instance: | 1425 case ResourceType_Instance: |
1397 default: | 1426 default: |
1398 break; | 1427 break; |
1399 } | 1428 } |
1429 } | |
1430 | |
1431 | |
1432 void ServerIndex::GetStatistics(/* out */ uint64_t& compressedSize, | |
1433 /* out */ uint64_t& uncompressedSize, | |
1434 /* out */ unsigned int& countStudies, | |
1435 /* out */ unsigned int& countSeries, | |
1436 /* out */ unsigned int& countInstances, | |
1437 const std::string& publicId) | |
1438 { | |
1439 boost::mutex::scoped_lock lock(mutex_); | |
1440 | |
1441 ResourceType type; | |
1442 int64_t top; | |
1443 if (!db_->LookupResource(publicId, top, type)) | |
1444 { | |
1445 throw OrthancException(ErrorCode_UnknownResource); | |
1446 } | |
1447 | |
1448 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, | |
1449 countSeries, countInstances, top, type); | |
1400 } | 1450 } |
1401 | 1451 |
1402 | 1452 |
1403 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that) | 1453 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that) |
1404 { | 1454 { |