annotate PerfsDb/DbPopulator.py @ 158:df1f9946571c

perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
author am@osimis.io
date Fri, 17 Aug 2018 11:58:26 +0200
parents f1a75985caa8
children 27b3b0df5f90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
1 import typing
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
2 from orthancRestApi import OrthancClient
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
3
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
4 from DbSize import DbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
5
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6 class DbPopulator:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8 def __init__(self, orthanc: OrthancClient, dbSize: DbSize):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 self._orthanc = orthanc
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 self._dbSize = dbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 self._sourceInstanceId = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13 def populate(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 self._sourceInstanceId = self._orthanc.uploadDicomFile("../Database/DummyCT.dcm")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
16 if self._dbSize == DbSize.Tiny:
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
17 patientCount = 1
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
18 smallStudiesPerPatient = 2
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
19 largeStudiesPerPatient = 1
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
20 instancesPerLargeSeries = 5
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
21 elif self._dbSize == DbSize.Small:
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
22 patientCount = 20
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
23 smallStudiesPerPatient = 2
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
24 largeStudiesPerPatient = 1
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
25 instancesPerLargeSeries = 300
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
26 elif self._dbSize == DbSize.Medium:
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
27 patientCount = 1000
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
28 smallStudiesPerPatient = 2
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
29 largeStudiesPerPatient = 1
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
30 instancesPerLargeSeries = 500
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
31 elif self._dbSize == DbSize.Large:
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
32 patientCount = 20000
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
33 smallStudiesPerPatient = 4
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
34 largeStudiesPerPatient = 8
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
35 instancesPerLargeSeries = 500
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
36 else:
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
37 raise NotImplementedError
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
39 # first add data that are the same in small and large DBs (and that can be used in tests for comparing the same things !!)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
40
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
41 # used in TestFindStudyByPatientId5Results
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
42 self.createStudy(studyIndex=99994, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
43 self.createStudy(studyIndex=99995, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
44 self.createStudy(studyIndex=99996, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
45 self.createStudy(studyIndex=99997, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
46 self.createStudy(studyIndex=99998, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
47
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
48 # used in TestFindStudyByStudyDescription1Result
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
49 # used in TestFindStudyByPatientId1Result
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
50 self.createStudy(studyIndex=99999, patientIndex=99999, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
51
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
52 # then, add data to make the DB "large" or "small"
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
53 for patientIndex in range(0, patientCount):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
54 studyIndex=0
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
55 print("Generating data for patient " + str(patientIndex))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
56 for i in range(0, smallStudiesPerPatient):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
57 print("Generating small study " + str(i))
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
58 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=2, instancesPerSeries=instancesPerLargeSeries)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
59 studyIndex+=1
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
60 for i in range(0, largeStudiesPerPatient):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
61 print("Generating large study " + str(i))
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
62 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=4, instancesPerSeries=instancesPerLargeSeries)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
63 studyIndex+=1
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
64
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
65 print("Generation completed")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
66
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
67 def createStudy(self, studyIndex: int, patientIndex: int, seriesCount: int, instancesPerSeries: int):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
68 for seriesIndex in range(0, seriesCount):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
69 for instanceIndex in range(0, instancesPerSeries):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
70 dicomFile = self.createDicomFile(patientIndex=patientIndex, studyIndex=studyIndex, seriesIndex=seriesIndex, instanceIndex=instanceIndex)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
71 self._orthanc.uploadDicom(dicomFile)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
72
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
73 def createDicomFile(self, patientIndex: int, studyIndex: int, seriesIndex: int, instanceIndex: int) -> object:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
74 return self._orthanc.instances.modify(
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
75 instanceId=self._sourceInstanceId,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
76 replaceTags={
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
77 "PatientName": "Patient-" + str(patientIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
78 "PatientID": str(patientIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
79 "StudyDescription": str(patientIndex) + "-" + str(studyIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
80 "SeriesDescription": str(patientIndex) + "-" + str(studyIndex) + "-" + str(seriesIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
81 "SOPInstanceUID": str(patientIndex) + "." + str(studyIndex) + "." + str(seriesIndex) + "." + str(instanceIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
82 "StudyInstanceUID": str(patientIndex) + "." + str(studyIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
83 "SeriesInstanceUID": str(patientIndex) + "." + str(studyIndex) + "." + str(seriesIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
84 "SeriesNumber": str(seriesIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
85 "InstanceNumber": str(instanceIndex)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
86 },
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
87 deleteOriginal=False
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
88 )