comparison PerfsDb/DbPopulator.py @ 163:53575aa2614b

added stats during db creation
author am@osimis.io
date Mon, 20 Aug 2018 14:54:32 +0200
parents dbc42a03ee75
children 1ff0d830bb87
comparison
equal deleted inserted replaced
162:dbc42a03ee75 163:53575aa2614b
1 import typing 1 import typing
2 import time 2 import time
3 import csv
4 import os
3 from orthancRestApi import OrthancClient 5 from orthancRestApi import OrthancClient
4 from TestResult import TestResult 6 from TestResult import TestResult
5 from DbSize import DbSize 7 from DbSize import DbSize
6 8
7 class DbPopulator: 9 class DbPopulator:
10 self._orthanc = orthanc 12 self._orthanc = orthanc
11 self._dbSize = dbSize 13 self._dbSize = dbSize
12 self._sourceInstanceId = None 14 self._sourceInstanceId = None
13 self._fileCounter = 0 15 self._fileCounter = 0
14 16
15 def populate(self): 17 def populate(self, label: str):
16 self._sourceInstanceId = self._orthanc.uploadDicomFile("../Database/DummyCT.dcm") 18 self._sourceInstanceId = self._orthanc.uploadDicomFile("../Database/DummyCT.dcm")
17 19
18 if self._dbSize == DbSize.Tiny: 20 if self._dbSize == DbSize.Tiny:
19 patientCount = 1 21 patientCount = 1
20 smallStudiesPerPatient = 2 22 smallStudiesPerPatient = 2
68 # used in TestFindStudyByStudyDescription1Result 70 # used in TestFindStudyByStudyDescription1Result
69 # used in TestFindStudyByPatientId1Result 71 # used in TestFindStudyByPatientId1Result
70 # used in TestToolsFindStudyByStudyInstanceUID 72 # used in TestToolsFindStudyByStudyInstanceUID
71 self.createStudy(studyIndex=99999, patientIndex=99999, seriesCount=1, instancesPerSeries=1) 73 self.createStudy(studyIndex=99999, patientIndex=99999, seriesCount=1, instancesPerSeries=1)
72 74
73 # then, add data to make the DB "large" or "small" 75 with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Results/db-init-" + label), 'w', newline='') as resultFile:
74 for patientIndex in range(0, patientCount): 76 resultWriter = csv.writer(resultFile)
75 studyIndex=0 77 resultWriter.writerow(["patientCount", "filesCount", "duration", "files/sec"])
76 print("Generating data for patient " + str(patientIndex)) 78 # then, add data to make the DB "large" or "small"
77 for i in range(0, smallStudiesPerPatient): 79 for patientIndex in range(0, patientCount):
78 print("Generating small study " + str(i)) 80 studyIndex=0
79 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=seriesPerSmallStudy, instancesPerSeries=instancesPerSmallSeries) 81 print("Generating data for patient " + str(patientIndex))
80 studyIndex+=1 82 fileCounterAtPatientStart = self._fileCounter
81 for i in range(0, largeStudiesPerPatient): 83 startTimePatient = time.time()
82 print("Generating large study " + str(i)) 84
83 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=seriesPerLargeStudy, instancesPerSeries=instancesPerLargeSeries) 85 for i in range(0, smallStudiesPerPatient):
84 studyIndex+=1 86 print("Generating small study " + str(i))
87 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=seriesPerSmallStudy, instancesPerSeries=instancesPerSmallSeries)
88 studyIndex+=1
89 for i in range(0, largeStudiesPerPatient):
90 print("Generating large study " + str(i))
91 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=seriesPerLargeStudy, instancesPerSeries=instancesPerLargeSeries)
92 studyIndex+=1
93
94 endTimePatient = time.time()
95 print("STATS: uploaded {n} files in {s:.2f} seconds; {x:.2f} files/sec".format(
96 n=self._fileCounter - fileCounterAtPatientStart,
97 s=endTimePatient - startTimePatient,
98 x=(self._fileCounter - fileCounterAtPatientStart)/(endTimePatient - startTimePatient)
99 ))
100 resultWriter.writerow([
101 patientIndex,
102 self._fileCounter - fileCounterAtPatientStart,
103 endTimePatient - startTimePatient,
104 (self._fileCounter - fileCounterAtPatientStart)/(endTimePatient - startTimePatient)
105 ])
106 resultFile.flush()
85 107
86 endTime = time.time() 108 endTime = time.time()
87 print("Generation completed. Elapsed time: {duration:.2f} sec".format(duration=endTime-startTime)) 109 print("Generation completed. Elapsed time: {duration:.2f} sec".format(duration=endTime-startTime))
88 print("Uploaded {n} files -> {p:.2f} files/sec".format(n=self._fileCounter, p=self._fileCounter/(endTime-startTime))) 110 print("Uploaded {n} files -> {p:.2f} files/sec".format(n=self._fileCounter, p=self._fileCounter/(endTime-startTime)))
89 111