Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 440:23e5b35e3c5c
statistics for patient/studies/series/instances
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 15 May 2013 17:44:15 +0200 |
parents | 7bbe77cb9e12 |
children | 3b735fdf320b |
comparison
equal
deleted
inserted
replaced
439:081a44d5110b | 440:23e5b35e3c5c |
---|---|
46 | 46 |
47 #include <boost/lexical_cast.hpp> | 47 #include <boost/lexical_cast.hpp> |
48 #include <stdio.h> | 48 #include <stdio.h> |
49 #include <glog/logging.h> | 49 #include <glog/logging.h> |
50 | 50 |
51 static const uint64_t MEGA_BYTES = 1024 * 1024; | |
52 | |
51 namespace Orthanc | 53 namespace Orthanc |
52 { | 54 { |
53 namespace Internals | 55 namespace Internals |
54 { | 56 { |
55 class ServerIndexListener : public IServerIndexListener | 57 class ServerIndexListener : public IServerIndexListener |
513 } | 515 } |
514 | 516 |
515 | 517 |
516 void ServerIndex::ComputeStatistics(Json::Value& target) | 518 void ServerIndex::ComputeStatistics(Json::Value& target) |
517 { | 519 { |
518 static const uint64_t MB = 1024 * 1024; | |
519 | |
520 boost::mutex::scoped_lock lock(mutex_); | 520 boost::mutex::scoped_lock lock(mutex_); |
521 target = Json::objectValue; | 521 target = Json::objectValue; |
522 | 522 |
523 uint64_t cs = currentStorageSize_; | 523 uint64_t cs = currentStorageSize_; |
524 assert(cs == db_->GetTotalCompressedSize()); | 524 assert(cs == db_->GetTotalCompressedSize()); |
525 uint64_t us = db_->GetTotalUncompressedSize(); | 525 uint64_t us = db_->GetTotalUncompressedSize(); |
526 target["TotalDiskSpace"] = boost::lexical_cast<std::string>(cs); | 526 target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs); |
527 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); | 527 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); |
528 target["TotalDiskSpaceMB"] = boost::lexical_cast<unsigned int>(cs / MB); | 528 target["TotalDiskSizeMB"] = boost::lexical_cast<unsigned int>(cs / MEGA_BYTES); |
529 target["TotalUncompressedSizeMB"] = boost::lexical_cast<unsigned int>(us / MB); | 529 target["TotalUncompressedSizeMB"] = boost::lexical_cast<unsigned int>(us / MEGA_BYTES); |
530 | 530 |
531 target["CountPatients"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Patient)); | 531 target["CountPatients"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Patient)); |
532 target["CountStudies"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Study)); | 532 target["CountStudies"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Study)); |
533 target["CountSeries"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Series)); | 533 target["CountSeries"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Series)); |
534 target["CountInstances"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Instance)); | 534 target["CountInstances"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Instance)); |
999 { | 999 { |
1000 LOG(WARNING) << "No limit on the size of the storage area"; | 1000 LOG(WARNING) << "No limit on the size of the storage area"; |
1001 } | 1001 } |
1002 else | 1002 else |
1003 { | 1003 { |
1004 LOG(WARNING) << "At most " << (size / (1024 * 1024)) << "MB will be used for the storage area"; | 1004 LOG(WARNING) << "At most " << (size / MEGA_BYTES) << "MB will be used for the storage area"; |
1005 } | 1005 } |
1006 | 1006 |
1007 StandaloneRecycling(); | 1007 StandaloneRecycling(); |
1008 } | 1008 } |
1009 | 1009 |
1242 void ServerIndex::DeleteExportedResources() | 1242 void ServerIndex::DeleteExportedResources() |
1243 { | 1243 { |
1244 boost::mutex::scoped_lock lock(mutex_); | 1244 boost::mutex::scoped_lock lock(mutex_); |
1245 db_->ClearTable("ExportedResources"); | 1245 db_->ClearTable("ExportedResources"); |
1246 } | 1246 } |
1247 | |
1248 | |
1249 void ServerIndex::GetStatistics(Json::Value& target, | |
1250 const std::string& publicId) | |
1251 { | |
1252 boost::mutex::scoped_lock lock(mutex_); | |
1253 | |
1254 ResourceType type; | |
1255 int64_t top; | |
1256 if (!db_->LookupResource(publicId, top, type)) | |
1257 { | |
1258 throw OrthancException(ErrorCode_UnknownResource); | |
1259 } | |
1260 | |
1261 std::stack<int64_t> toExplore; | |
1262 toExplore.push(top); | |
1263 | |
1264 int countInstances = 0; | |
1265 int countSeries = 0; | |
1266 int countStudies = 0; | |
1267 uint64_t compressedSize = 0; | |
1268 uint64_t uncompressedSize = 0; | |
1269 | |
1270 while (!toExplore.empty()) | |
1271 { | |
1272 // Get the internal ID of the current resource | |
1273 int64_t resource = toExplore.top(); | |
1274 toExplore.pop(); | |
1275 | |
1276 ResourceType thisType = db_->GetResourceType(resource); | |
1277 | |
1278 if (thisType == ResourceType_Instance) | |
1279 { | |
1280 std::list<FileContentType> f; | |
1281 db_->ListAvailableAttachments(f, resource); | |
1282 | |
1283 for (std::list<FileContentType>::const_iterator | |
1284 it = f.begin(); it != f.end(); it++) | |
1285 { | |
1286 FileInfo attachment; | |
1287 if (db_->LookupAttachment(attachment, resource, *it)) | |
1288 { | |
1289 compressedSize += attachment.GetCompressedSize(); | |
1290 uncompressedSize += attachment.GetUncompressedSize(); | |
1291 } | |
1292 } | |
1293 | |
1294 countInstances++; | |
1295 } | |
1296 else | |
1297 { | |
1298 switch (thisType) | |
1299 { | |
1300 case ResourceType_Study: | |
1301 countStudies++; | |
1302 break; | |
1303 | |
1304 case ResourceType_Series: | |
1305 countSeries++; | |
1306 break; | |
1307 | |
1308 default: | |
1309 break; | |
1310 } | |
1311 | |
1312 // Tag all the children of this resource as to be explored | |
1313 std::list<int64_t> tmp; | |
1314 db_->GetChildrenInternalId(tmp, resource); | |
1315 for (std::list<int64_t>::const_iterator | |
1316 it = tmp.begin(); it != tmp.end(); it++) | |
1317 { | |
1318 toExplore.push(*it); | |
1319 } | |
1320 } | |
1321 } | |
1322 | |
1323 target = Json::objectValue; | |
1324 target["DiskSize"] = boost::lexical_cast<std::string>(compressedSize); | |
1325 target["DiskSizeMB"] = boost::lexical_cast<unsigned int>(compressedSize / MEGA_BYTES); | |
1326 target["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize); | |
1327 target["UncompressedSizeMB"] = boost::lexical_cast<unsigned int>(uncompressedSize / MEGA_BYTES); | |
1328 | |
1329 switch (type) | |
1330 { | |
1331 // Do NOT add "break" below this point! | |
1332 case ResourceType_Patient: | |
1333 target["CountStudies"] = countStudies; | |
1334 | |
1335 case ResourceType_Study: | |
1336 target["CountSeries"] = countSeries; | |
1337 | |
1338 case ResourceType_Series: | |
1339 target["CountInstances"] = countInstances; | |
1340 | |
1341 case ResourceType_Instance: | |
1342 default: | |
1343 break; | |
1344 } | |
1345 } | |
1247 } | 1346 } |