Mercurial > hg > orthanc-tests
annotate PerfsDb/DbPopulator.py @ 159:616da104a996
fix for ubuntu 18.04
author | am@osimis.io |
---|---|
date | Fri, 17 Aug 2018 14:49:59 +0200 |
parents | df1f9946571c |
children | 27b3b0df5f90 |
rev | line source |
---|---|
156 | 1 import typing |
2 from orthancRestApi import OrthancClient | |
3 | |
4 from DbSize import DbSize | |
5 | |
6 class DbPopulator: | |
7 | |
8 def __init__(self, orthanc: OrthancClient, dbSize: DbSize): | |
9 self._orthanc = orthanc | |
10 self._dbSize = dbSize | |
11 self._sourceInstanceId = None | |
12 | |
13 def populate(self): | |
14 self._sourceInstanceId = self._orthanc.uploadDicomFile("../Database/DummyCT.dcm") | |
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 | 23 smallStudiesPerPatient = 2 |
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 | 33 smallStudiesPerPatient = 4 |
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 | 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 | 40 |
41 # used in TestFindStudyByPatientId5Results | |
42 self.createStudy(studyIndex=99994, patientIndex=99998, seriesCount=1, instancesPerSeries=1) | |
43 self.createStudy(studyIndex=99995, patientIndex=99998, seriesCount=1, instancesPerSeries=1) | |
44 self.createStudy(studyIndex=99996, patientIndex=99998, seriesCount=1, instancesPerSeries=1) | |
45 self.createStudy(studyIndex=99997, patientIndex=99998, seriesCount=1, instancesPerSeries=1) | |
46 self.createStudy(studyIndex=99998, patientIndex=99998, seriesCount=1, instancesPerSeries=1) | |
47 | |
48 # used in TestFindStudyByStudyDescription1Result | |
49 # used in TestFindStudyByPatientId1Result | |
50 self.createStudy(studyIndex=99999, patientIndex=99999, seriesCount=1, instancesPerSeries=1) | |
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 | 53 for patientIndex in range(0, patientCount): |
54 studyIndex=0 | |
55 print("Generating data for patient " + str(patientIndex)) | |
56 for i in range(0, smallStudiesPerPatient): | |
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 | 59 studyIndex+=1 |
60 for i in range(0, largeStudiesPerPatient): | |
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 | 63 studyIndex+=1 |
64 | |
65 print("Generation completed") | |
66 | |
67 def createStudy(self, studyIndex: int, patientIndex: int, seriesCount: int, instancesPerSeries: int): | |
68 for seriesIndex in range(0, seriesCount): | |
69 for instanceIndex in range(0, instancesPerSeries): | |
70 dicomFile = self.createDicomFile(patientIndex=patientIndex, studyIndex=studyIndex, seriesIndex=seriesIndex, instanceIndex=instanceIndex) | |
71 self._orthanc.uploadDicom(dicomFile) | |
72 | |
73 def createDicomFile(self, patientIndex: int, studyIndex: int, seriesIndex: int, instanceIndex: int) -> object: | |
74 return self._orthanc.instances.modify( | |
75 instanceId=self._sourceInstanceId, | |
76 replaceTags={ | |
77 "PatientName": "Patient-" + str(patientIndex), | |
78 "PatientID": str(patientIndex), | |
79 "StudyDescription": str(patientIndex) + "-" + str(studyIndex), | |
80 "SeriesDescription": str(patientIndex) + "-" + str(studyIndex) + "-" + str(seriesIndex), | |
81 "SOPInstanceUID": str(patientIndex) + "." + str(studyIndex) + "." + str(seriesIndex) + "." + str(instanceIndex), | |
82 "StudyInstanceUID": str(patientIndex) + "." + str(studyIndex), | |
83 "SeriesInstanceUID": str(patientIndex) + "." + str(studyIndex) + "." + str(seriesIndex), | |
84 "SeriesNumber": str(seriesIndex), | |
85 "InstanceNumber": str(instanceIndex) | |
86 }, | |
87 deleteOriginal=False | |
88 ) |