endoreg-db 0.5.3__py3-none-any.whl → 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of endoreg-db might be problematic. Click here for more details.
- endoreg_db/admin.py +90 -1
- endoreg_db/case_generator/case_generator.py +159 -0
- endoreg_db/case_generator/lab_sample_factory.py +33 -0
- endoreg_db/case_generator/utils.py +30 -0
- endoreg_db/data/__init__.py +50 -4
- endoreg_db/data/ai_model/data.yaml +7 -0
- endoreg_db/data/{label → ai_model_label}/label/data.yaml +27 -1
- endoreg_db/data/ai_model_label/label-set/data.yaml +21 -0
- endoreg_db/data/ai_model_meta/default_multilabel_classification.yaml +5 -0
- endoreg_db/data/ai_model_video_segmentation_label/base_segmentation.yaml +176 -0
- endoreg_db/data/ai_model_video_segmentation_labelset/data.yaml +20 -0
- endoreg_db/data/center/data.yaml +35 -5
- endoreg_db/data/contraindication/bleeding.yaml +11 -0
- endoreg_db/data/distribution/numeric/data.yaml +14 -0
- endoreg_db/data/endoscope/data.yaml +93 -0
- endoreg_db/data/examination_indication/endoscopy.yaml +8 -0
- endoreg_db/data/examination_indication_classification/endoscopy.yaml +8 -0
- endoreg_db/data/examination_indication_classification_choice/endoscopy.yaml +101 -0
- endoreg_db/data/finding/data.yaml +141 -0
- endoreg_db/data/finding_intervention/endoscopy.yaml +138 -0
- endoreg_db/data/finding_intervention_type/endoscopy.yaml +15 -0
- endoreg_db/data/finding_location_classification/colonoscopy.yaml +46 -0
- endoreg_db/data/finding_location_classification_choice/colonoscopy.yaml +240 -0
- endoreg_db/data/finding_morphology_classification/colonoscopy.yaml +48 -0
- endoreg_db/data/finding_morphology_classification_choice/colon_lesion_circularity_default.yaml +34 -0
- endoreg_db/data/finding_morphology_classification_choice/colon_lesion_nice.yaml +20 -0
- endoreg_db/data/finding_morphology_classification_choice/colon_lesion_paris.yaml +65 -0
- endoreg_db/data/finding_morphology_classification_choice/colon_lesion_planarity_default.yaml +56 -0
- endoreg_db/data/finding_morphology_classification_choice/colon_lesion_surface_intact_default.yaml +39 -0
- endoreg_db/data/finding_morphology_classification_choice/colonoscopy_size.yaml +57 -0
- endoreg_db/data/finding_morphology_classification_type/colonoscopy.yaml +79 -0
- endoreg_db/data/finding_type/data.yaml +30 -0
- endoreg_db/data/gender/data.yaml +17 -0
- endoreg_db/data/lab_value/cardiac_enzymes.yaml +7 -1
- endoreg_db/data/lab_value/coagulation.yaml +6 -1
- endoreg_db/data/lab_value/electrolytes.yaml +39 -1
- endoreg_db/data/lab_value/gastrointestinal_function.yaml +12 -0
- endoreg_db/data/lab_value/hematology.yaml +17 -2
- endoreg_db/data/lab_value/hormones.yaml +6 -0
- endoreg_db/data/lab_value/lipids.yaml +12 -3
- endoreg_db/data/lab_value/misc.yaml +5 -2
- endoreg_db/data/lab_value/renal_function.yaml +2 -1
- endoreg_db/data/lx_client_tag/base.yaml +54 -0
- endoreg_db/data/lx_client_type/base.yaml +30 -0
- endoreg_db/data/lx_permission/base.yaml +24 -0
- endoreg_db/data/lx_permission/endoreg.yaml +52 -0
- endoreg_db/data/medication_indication/anticoagulation.yaml +44 -49
- endoreg_db/data/names_first/first_names.yaml +51 -0
- endoreg_db/data/names_last/last_names.yaml +51 -0
- endoreg_db/data/network_device/data.yaml +30 -0
- endoreg_db/data/organ/data.yaml +29 -0
- endoreg_db/data/pdf_type/data.yaml +2 -1
- endoreg_db/data/report_reader_flag/ukw-examination-generic.yaml +4 -0
- endoreg_db/forms/__init__.py +3 -1
- endoreg_db/forms/examination_form.py +11 -0
- endoreg_db/forms/patient_finding_intervention_form.py +19 -0
- endoreg_db/forms/patient_form.py +26 -0
- endoreg_db/management/commands/__init__.py +0 -0
- endoreg_db/management/commands/load_ai_model_data.py +57 -23
- endoreg_db/management/commands/load_ai_model_label_data.py +59 -0
- endoreg_db/management/commands/load_base_db_data.py +160 -118
- endoreg_db/management/commands/{load_endoscope_type_data.py → load_contraindication_data.py} +3 -7
- endoreg_db/management/commands/load_disease_data.py +29 -7
- endoreg_db/management/commands/load_endoscope_data.py +68 -0
- endoreg_db/management/commands/load_examination_indication_data.py +65 -0
- endoreg_db/management/commands/load_finding_data.py +171 -0
- endoreg_db/management/commands/load_lab_value_data.py +3 -3
- endoreg_db/management/commands/load_lx_data.py +64 -0
- endoreg_db/management/commands/load_medication_data.py +83 -21
- endoreg_db/management/commands/load_name_data.py +37 -0
- endoreg_db/management/commands/{load_endoscopy_processor_data.py → load_organ_data.py} +7 -9
- endoreg_db/migrations/0001_initial.py +1206 -728
- endoreg_db/migrations/0002_alter_frame_image_alter_rawframe_image.py +23 -0
- endoreg_db/migrations/0003_alter_frame_image_alter_rawframe_image.py +23 -0
- endoreg_db/migrations/0004_alter_rawvideofile_file_alter_video_file.py +25 -0
- endoreg_db/migrations/0005_rawvideofile_frame_count_and_more.py +33 -0
- endoreg_db/migrations/0006_frame_extracted_rawframe_extracted.py +23 -0
- endoreg_db/migrations/0007_rename_pseudo_patient_video_patient_and_more.py +24 -0
- endoreg_db/migrations/0008_remove_reportfile_patient_examination_and_more.py +48 -0
- endoreg_db/models/__init__.py +331 -28
- endoreg_db/models/ai_model/__init__.py +1 -0
- endoreg_db/models/ai_model/ai_model.py +103 -0
- endoreg_db/models/ai_model/lightning/__init__.py +3 -0
- endoreg_db/models/ai_model/lightning/inference_dataset.py +53 -0
- endoreg_db/models/ai_model/lightning/multilabel_classification_net.py +155 -0
- endoreg_db/models/ai_model/lightning/postprocess.py +53 -0
- endoreg_db/models/ai_model/lightning/predict.py +172 -0
- endoreg_db/models/ai_model/lightning/prediction_visualizer.py +55 -0
- endoreg_db/models/ai_model/lightning/preprocess.py +68 -0
- endoreg_db/models/ai_model/lightning/run_visualizer.py +21 -0
- endoreg_db/models/ai_model/model_meta.py +232 -6
- endoreg_db/models/ai_model/model_type.py +13 -3
- endoreg_db/models/annotation/__init__.py +31 -2
- endoreg_db/models/annotation/anonymized_image_annotation.py +73 -18
- endoreg_db/models/annotation/binary_classification_annotation_task.py +94 -57
- endoreg_db/models/annotation/image_classification.py +73 -14
- endoreg_db/models/annotation/video_segmentation_annotation.py +52 -0
- endoreg_db/models/annotation/video_segmentation_labelset.py +20 -0
- endoreg_db/models/case/__init__.py +1 -0
- endoreg_db/models/{persons/patient/case → case}/case.py +4 -0
- endoreg_db/models/case_template/__init__.py +10 -1
- endoreg_db/models/case_template/case_template.py +57 -13
- endoreg_db/models/case_template/case_template_rule.py +5 -5
- endoreg_db/models/case_template/case_template_rule_value.py +19 -4
- endoreg_db/models/center/__init__.py +7 -0
- endoreg_db/models/center/center.py +31 -5
- endoreg_db/models/center/center_product.py +0 -1
- endoreg_db/models/center/center_resource.py +16 -2
- endoreg_db/models/center/center_waste.py +6 -1
- endoreg_db/models/contraindication/__init__.py +21 -0
- endoreg_db/models/data_file/__init__.py +38 -5
- endoreg_db/models/data_file/base_classes/__init__.py +6 -1
- endoreg_db/models/data_file/base_classes/abstract_frame.py +64 -15
- endoreg_db/models/data_file/base_classes/abstract_pdf.py +136 -0
- endoreg_db/models/data_file/base_classes/abstract_video.py +744 -138
- endoreg_db/models/data_file/base_classes/frame_helpers.py +17 -0
- endoreg_db/models/data_file/base_classes/prepare_bulk_frames.py +19 -0
- endoreg_db/models/data_file/base_classes/utils.py +80 -0
- endoreg_db/models/data_file/frame.py +22 -38
- endoreg_db/models/data_file/import_classes/__init__.py +4 -18
- endoreg_db/models/data_file/import_classes/raw_pdf.py +162 -90
- endoreg_db/models/data_file/import_classes/raw_video.py +239 -294
- endoreg_db/models/data_file/metadata/__init__.py +10 -0
- endoreg_db/models/data_file/metadata/pdf_meta.py +4 -0
- endoreg_db/models/data_file/metadata/sensitive_meta.py +265 -6
- endoreg_db/models/data_file/metadata/video_meta.py +116 -50
- endoreg_db/models/data_file/report_file.py +30 -63
- endoreg_db/models/data_file/video/__init__.py +6 -2
- endoreg_db/models/data_file/video/video.py +187 -16
- endoreg_db/models/data_file/video_segment.py +162 -55
- endoreg_db/models/disease.py +25 -2
- endoreg_db/models/emission/__init__.py +5 -1
- endoreg_db/models/emission/emission_factor.py +71 -6
- endoreg_db/models/event.py +51 -0
- endoreg_db/models/examination/__init__.py +6 -1
- endoreg_db/models/examination/examination.py +53 -12
- endoreg_db/models/examination/examination_indication.py +170 -0
- endoreg_db/models/examination/examination_time.py +31 -5
- endoreg_db/models/examination/examination_time_type.py +28 -4
- endoreg_db/models/examination/examination_type.py +28 -6
- endoreg_db/models/finding/__init__.py +11 -0
- endoreg_db/models/finding/finding.py +75 -0
- endoreg_db/models/finding/finding_intervention.py +60 -0
- endoreg_db/models/finding/finding_location_classification.py +94 -0
- endoreg_db/models/finding/finding_morphology_classification.py +89 -0
- endoreg_db/models/finding/finding_type.py +22 -0
- endoreg_db/models/hardware/endoscope.py +16 -0
- endoreg_db/models/hardware/endoscopy_processor.py +31 -19
- endoreg_db/models/label/label.py +35 -7
- endoreg_db/models/laboratory/lab_value.py +12 -3
- endoreg_db/models/logging/__init__.py +8 -1
- endoreg_db/models/lx/__init__.py +4 -0
- endoreg_db/models/lx/client.py +57 -0
- endoreg_db/models/lx/identity.py +34 -0
- endoreg_db/models/lx/permission.py +18 -0
- endoreg_db/models/lx/user.py +16 -0
- endoreg_db/models/medication/__init__.py +19 -1
- endoreg_db/models/medication/medication.py +7 -122
- endoreg_db/models/medication/medication_indication.py +50 -0
- endoreg_db/models/medication/medication_indication_type.py +34 -0
- endoreg_db/models/medication/medication_intake_time.py +26 -0
- endoreg_db/models/medication/medication_schedule.py +37 -0
- endoreg_db/models/network/__init__.py +7 -1
- endoreg_db/models/network/network_device.py +13 -8
- endoreg_db/models/organ/__init__.py +38 -0
- endoreg_db/models/other/__init__.py +19 -1
- endoreg_db/models/other/distribution/__init__.py +44 -0
- endoreg_db/models/other/distribution/base_value_distribution.py +20 -0
- endoreg_db/models/other/distribution/date_value_distribution.py +91 -0
- endoreg_db/models/other/distribution/multiple_categorical_value_distribution.py +32 -0
- endoreg_db/models/other/distribution/numeric_value_distribution.py +97 -0
- endoreg_db/models/other/distribution/single_categorical_value_distribution.py +22 -0
- endoreg_db/models/other/distribution.py +1 -211
- endoreg_db/models/other/material.py +4 -0
- endoreg_db/models/other/transport_route.py +2 -1
- endoreg_db/models/patient/__init__.py +24 -0
- endoreg_db/models/patient/patient_examination.py +182 -0
- endoreg_db/models/patient/patient_finding.py +143 -0
- endoreg_db/models/patient/patient_finding_intervention.py +26 -0
- endoreg_db/models/patient/patient_finding_location.py +120 -0
- endoreg_db/models/patient/patient_finding_morphology.py +166 -0
- endoreg_db/models/persons/__init__.py +29 -2
- endoreg_db/models/persons/examiner/examiner.py +48 -4
- endoreg_db/models/persons/patient/__init__.py +1 -1
- endoreg_db/models/persons/patient/patient.py +227 -54
- endoreg_db/models/persons/patient/patient_disease.py +6 -0
- endoreg_db/models/persons/patient/patient_event.py +31 -1
- endoreg_db/models/persons/patient/patient_examination_indication.py +32 -0
- endoreg_db/models/persons/patient/patient_lab_sample.py +4 -2
- endoreg_db/models/persons/patient/patient_lab_value.py +37 -16
- endoreg_db/models/persons/patient/patient_medication.py +27 -12
- endoreg_db/models/persons/patient/patient_medication_schedule.py +62 -2
- endoreg_db/models/prediction/__init__.py +7 -1
- endoreg_db/models/prediction/image_classification.py +20 -6
- endoreg_db/models/prediction/video_prediction_meta.py +151 -89
- endoreg_db/models/product/__init__.py +10 -1
- endoreg_db/models/product/product.py +15 -2
- endoreg_db/models/product/product_group.py +8 -0
- endoreg_db/models/product/product_material.py +4 -0
- endoreg_db/models/product/product_weight.py +12 -0
- endoreg_db/models/product/reference_product.py +19 -3
- endoreg_db/models/quiz/__init__.py +8 -1
- endoreg_db/models/report_reader/__init__.py +6 -1
- endoreg_db/serializers/__init__.py +1 -1
- endoreg_db/serializers/annotation.py +2 -5
- endoreg_db/serializers/frame.py +1 -5
- endoreg_db/serializers/patient.py +26 -3
- endoreg_db/serializers/prediction.py +2 -7
- endoreg_db/serializers/raw_video_meta_validation.py +13 -0
- endoreg_db/serializers/video.py +6 -13
- endoreg_db/serializers/video_segmentation.py +492 -0
- endoreg_db/templates/admin/patient_finding_intervention.html +253 -0
- endoreg_db/templates/admin/start_examination.html +12 -0
- endoreg_db/templates/timeline.html +176 -0
- endoreg_db/urls.py +173 -0
- endoreg_db/utils/__init__.py +36 -1
- endoreg_db/utils/dataloader.py +45 -19
- endoreg_db/utils/dates.py +39 -0
- endoreg_db/utils/hashs.py +122 -4
- endoreg_db/utils/names.py +74 -0
- endoreg_db/utils/parse_and_generate_yaml.py +46 -0
- endoreg_db/utils/pydantic_models/__init__.py +6 -0
- endoreg_db/utils/pydantic_models/db_config.py +57 -0
- endoreg_db/utils/validate_endo_roi.py +19 -0
- endoreg_db/utils/validate_subcategory_dict.py +91 -0
- endoreg_db/utils/video/__init__.py +13 -0
- endoreg_db/utils/video/extract_frames.py +121 -0
- endoreg_db/utils/video/transcode_videofile.py +111 -0
- endoreg_db/views/__init__.py +2 -0
- endoreg_db/views/csrf.py +7 -0
- endoreg_db/views/patient_views.py +90 -0
- endoreg_db/views/raw_video_meta_validation_views.py +38 -0
- endoreg_db/views/report_views.py +96 -0
- endoreg_db/views/video_segmentation_views.py +149 -0
- endoreg_db/views/views_for_timeline.py +46 -0
- endoreg_db/views.py +0 -3
- endoreg_db-0.6.1.dist-info/METADATA +151 -0
- endoreg_db-0.6.1.dist-info/RECORD +420 -0
- {endoreg_db-0.5.3.dist-info → endoreg_db-0.6.1.dist-info}/WHEEL +1 -1
- endoreg_db/data/active_model/data.yaml +0 -3
- endoreg_db/data/label/label-set/data.yaml +0 -18
- endoreg_db/management/commands/delete_legacy_images.py +0 -19
- endoreg_db/management/commands/delete_legacy_videos.py +0 -17
- endoreg_db/management/commands/extract_legacy_video_frames.py +0 -18
- endoreg_db/management/commands/import_legacy_images.py +0 -94
- endoreg_db/management/commands/import_legacy_videos.py +0 -76
- endoreg_db/management/commands/load_label_data.py +0 -67
- endoreg_db/migrations/0002_anonymizedimagelabel_anonymousimageannotation_and_more.py +0 -55
- endoreg_db/migrations/0003_anonymousimageannotation_original_image_url_and_more.py +0 -39
- endoreg_db/migrations/0004_alter_rawpdffile_file.py +0 -20
- endoreg_db/migrations/0005_uploadedfile_alter_rawpdffile_file_anonymizedfile.py +0 -40
- endoreg_db/migrations/0006_alter_rawpdffile_file.py +0 -20
- endoreg_db/migrations/0007_networkdevicelogentry_datetime_and_more.py +0 -43
- endoreg_db/migrations/0008_networkdevicelogentry_aglnet_ip_and_more.py +0 -28
- endoreg_db/migrations/0009_alter_networkdevicelogentry_vpn_service_status.py +0 -18
- endoreg_db/migrations/0010_remove_networkdevicelogentry_hostname.py +0 -17
- endoreg_db/models/legacy_data/__init__.py +0 -3
- endoreg_db/models/legacy_data/image.py +0 -34
- endoreg_db/models/patient_examination/__init__.py +0 -35
- endoreg_db/utils/video_metadata.py +0 -87
- endoreg_db-0.5.3.dist-info/METADATA +0 -28
- endoreg_db-0.5.3.dist-info/RECORD +0 -319
- /endoreg_db/{models/persons/patient/case → case_generator}/__init__.py +0 -0
- /endoreg_db/data/{label → ai_model_label}/label-type/data.yaml +0 -0
- /endoreg_db/data/{model_type → ai_model_type}/data.yaml +0 -0
- /endoreg_db/{data/distribution/numeric/.init → management/__init__.py} +0 -0
- /endoreg_db/management/commands/{load_report_reader_flag.py → load_report_reader_flag_data.py} +0 -0
- {endoreg_db-0.5.3.dist-info → endoreg_db-0.6.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
'''Model for the medication.'''
|
|
1
2
|
from django.db import models
|
|
2
3
|
|
|
4
|
+
|
|
3
5
|
class MedicationManager(models.Manager):
|
|
6
|
+
'''Manager for the medication model.'''
|
|
4
7
|
def get_by_natural_key(self, name):
|
|
8
|
+
'''Retrieve a medication by its natural key.'''
|
|
5
9
|
return self.get(name=name)
|
|
6
10
|
|
|
7
11
|
class Medication(models.Model):
|
|
12
|
+
'''Model representing a medication.'''
|
|
8
13
|
name = models.CharField(max_length=255, unique=True)
|
|
9
14
|
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
10
15
|
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
@@ -20,129 +25,9 @@ class Medication(models.Model):
|
|
|
20
25
|
objects = MedicationManager()
|
|
21
26
|
|
|
22
27
|
def natural_key(self):
|
|
28
|
+
'''Return the natural key for the medication.'''
|
|
23
29
|
return (self.name,)
|
|
24
30
|
|
|
25
31
|
def __str__(self):
|
|
26
|
-
return self.name
|
|
27
|
-
|
|
28
|
-
class MedicationScheduleManager(models.Manager):
|
|
29
|
-
def get_by_natural_key(self, name):
|
|
30
|
-
return self.get(name=name)
|
|
31
|
-
|
|
32
|
-
class MedicationSchedule(models.Model):
|
|
33
|
-
name = models.CharField(max_length=255)
|
|
34
|
-
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
35
|
-
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
36
|
-
description = models.TextField(blank=True, null=True)
|
|
37
|
-
medication = models.ForeignKey("Medication", on_delete=models.CASCADE)
|
|
38
|
-
unit = models.ForeignKey("Unit", on_delete=models.CASCADE)
|
|
39
|
-
therapy_duration_d = models.FloatField(blank=True, null=True)
|
|
40
|
-
dose = models.FloatField()
|
|
41
|
-
intake_times = models.ManyToManyField(
|
|
42
|
-
"MedicationIntakeTime",
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
objects = MedicationScheduleManager()
|
|
46
|
-
|
|
47
|
-
def natural_key(self):
|
|
48
|
-
return (self.name,)
|
|
49
|
-
|
|
50
|
-
def __str__(self):
|
|
51
|
-
return self.name
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
class MedicationIntakeTimeManager(models.Manager):
|
|
55
|
-
def get_by_natural_key(self, name):
|
|
56
|
-
return self.get(name=name)
|
|
57
|
-
|
|
58
|
-
class MedicationIntakeTime(models.Model):
|
|
59
|
-
name = models.CharField(max_length=255)
|
|
60
|
-
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
61
|
-
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
62
|
-
repeats = models.CharField(max_length=20, default = "daily")
|
|
63
|
-
time = models.TimeField()
|
|
64
|
-
|
|
65
|
-
objects = MedicationIntakeTimeManager()
|
|
66
|
-
|
|
67
|
-
def natural_key(self):
|
|
68
|
-
return (self.name,)
|
|
69
|
-
|
|
70
|
-
def __str__(self):
|
|
71
|
-
return self.name
|
|
72
|
-
|
|
73
|
-
# IMPLEMENT MEDICATION INDICATION TYPE
|
|
74
|
-
class MedicationIndicationTypeManager(models.Manager):
|
|
75
|
-
def get_by_natural_key(self, name):
|
|
76
|
-
return self.get(name=name)
|
|
77
|
-
|
|
78
|
-
class MedicationIndicationType(models.Model):
|
|
79
|
-
name = models.CharField(max_length=255, unique=True)
|
|
80
|
-
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
81
|
-
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
82
|
-
|
|
83
|
-
objects = MedicationIndicationTypeManager()
|
|
84
|
-
|
|
85
|
-
def natural_key(self):
|
|
86
|
-
return (self.name,)
|
|
87
|
-
|
|
88
|
-
def __str__(self):
|
|
89
|
-
return self.name
|
|
90
|
-
|
|
91
|
-
@classmethod
|
|
92
|
-
def get_random_indication_by_type(cls, name) -> "MedicationIndication":
|
|
93
|
-
return cls.objects.get(name=name).medication_indications.order_by('?').first()
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def get_random_medication_indication(self):
|
|
97
|
-
from endoreg_db.models import MedicationIndication
|
|
98
|
-
return MedicationIndication.objects.filter(indication_type=self).order_by('?').first()
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
class MedicationIndicationManager(models.Manager):
|
|
102
|
-
def get_by_natural_key(self, name):
|
|
103
|
-
return self.get(name=name)
|
|
104
|
-
|
|
105
|
-
class MedicationIndication(models.Model):
|
|
106
|
-
name = models.CharField(max_length=255, unique=True)
|
|
107
|
-
indication_type = models.ForeignKey(
|
|
108
|
-
"MedicationIndicationType", on_delete=models.CASCADE, related_name="medication_indications"
|
|
109
|
-
)
|
|
110
|
-
medication_schedules = models.ManyToManyField(
|
|
111
|
-
"MedicationSchedule"
|
|
112
|
-
)
|
|
113
|
-
diseases = models.ManyToManyField(
|
|
114
|
-
"Disease"
|
|
115
|
-
)
|
|
116
|
-
events = models.ManyToManyField(
|
|
117
|
-
"Event"
|
|
118
|
-
)
|
|
119
|
-
classification_choices = models.ManyToManyField(
|
|
120
|
-
"DiseaseClassificationChoice"
|
|
121
|
-
)
|
|
122
|
-
sources = models.ManyToManyField(
|
|
123
|
-
"InformationSource"
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
def get_indication_links(self):
|
|
127
|
-
links = {
|
|
128
|
-
"medication_schedules": self.medication_schedules,
|
|
129
|
-
"diseases": self.diseases,
|
|
130
|
-
"events": self.events,
|
|
131
|
-
"classification_choices": self.classification_choices
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
objects = MedicationIndicationManager()
|
|
135
|
-
|
|
136
|
-
def natural_key(self):
|
|
137
|
-
return (self.name,)
|
|
138
|
-
|
|
139
|
-
def __str__(self):
|
|
140
|
-
return self.name
|
|
32
|
+
return str(self.name)
|
|
141
33
|
|
|
142
|
-
def create_patient_medication_schedules(self, patient):
|
|
143
|
-
from endoreg_db.models import PatientMedicationSchedule
|
|
144
|
-
for medication_schedule in self.medication_schedules.all():
|
|
145
|
-
PatientMedicationSchedule.objects.create(
|
|
146
|
-
patient=patient,
|
|
147
|
-
medication_schedule=medication_schedule
|
|
148
|
-
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Model for medication indication."""
|
|
2
|
+
|
|
3
|
+
from django.db import models
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MedicationIndicationManager(models.Manager):
|
|
7
|
+
"""Manager for the medication indication model."""
|
|
8
|
+
|
|
9
|
+
def get_by_natural_key(self, name):
|
|
10
|
+
"""Retrieve a medication indication by its natural key."""
|
|
11
|
+
return self.get(name=name)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MedicationIndication(models.Model):
|
|
15
|
+
"""Model representing a medication indication."""
|
|
16
|
+
|
|
17
|
+
name = models.CharField(max_length=255, unique=True)
|
|
18
|
+
indication_type = models.ForeignKey(
|
|
19
|
+
"MedicationIndicationType",
|
|
20
|
+
on_delete=models.CASCADE,
|
|
21
|
+
related_name="medication_indications",
|
|
22
|
+
)
|
|
23
|
+
medication_schedules = models.ManyToManyField(
|
|
24
|
+
"MedicationSchedule",
|
|
25
|
+
)
|
|
26
|
+
diseases = models.ManyToManyField("Disease")
|
|
27
|
+
events = models.ManyToManyField("Event")
|
|
28
|
+
disease_classification_choices = models.ManyToManyField(
|
|
29
|
+
"DiseaseClassificationChoice"
|
|
30
|
+
)
|
|
31
|
+
sources = models.ManyToManyField("InformationSource")
|
|
32
|
+
|
|
33
|
+
def get_indication_links(self) -> dict:
|
|
34
|
+
"""Return a dictionary of all linked objects for this medication indication."""
|
|
35
|
+
links = {
|
|
36
|
+
"medication_schedules": self.medication_schedules,
|
|
37
|
+
"diseases": self.diseases,
|
|
38
|
+
"events": self.events,
|
|
39
|
+
"disease_classification_choices": self.disease_classification_choices,
|
|
40
|
+
}
|
|
41
|
+
return links
|
|
42
|
+
|
|
43
|
+
objects = MedicationIndicationManager()
|
|
44
|
+
|
|
45
|
+
def natural_key(self):
|
|
46
|
+
"""Return the natural key for the medication indication."""
|
|
47
|
+
return (self.name,)
|
|
48
|
+
|
|
49
|
+
def __str__(self):
|
|
50
|
+
return str(self.name)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'''Model for medication indication type.'''
|
|
2
|
+
from django.db import models
|
|
3
|
+
|
|
4
|
+
class MedicationIndicationTypeManager(models.Manager):
|
|
5
|
+
'''Manager for the medication indication type model.'''
|
|
6
|
+
def get_by_natural_key(self, name):
|
|
7
|
+
'''Retrieve a medication indication type by its natural key.'''
|
|
8
|
+
return self.get(name=name)
|
|
9
|
+
|
|
10
|
+
class MedicationIndicationType(models.Model):
|
|
11
|
+
'''Model representing a medication indication type.'''
|
|
12
|
+
name = models.CharField(max_length=255, unique=True)
|
|
13
|
+
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
14
|
+
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
15
|
+
|
|
16
|
+
objects = MedicationIndicationTypeManager()
|
|
17
|
+
|
|
18
|
+
def natural_key(self):
|
|
19
|
+
'''Return the natural key for the medication indication type.'''
|
|
20
|
+
return (self.name,)
|
|
21
|
+
|
|
22
|
+
def __str__(self):
|
|
23
|
+
return str(self.name)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def get_random_indication_by_type(cls, name) -> "MedicationIndication":
|
|
27
|
+
'''Return a random medication indication of the given type.'''
|
|
28
|
+
return cls.objects.get(name=name).medication_indications.order_by('?').first()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_random_medication_indication(self):
|
|
32
|
+
'''Return a random medication indication of this type.'''
|
|
33
|
+
from endoreg_db.models import MedicationIndication
|
|
34
|
+
return MedicationIndication.objects.filter(indication_type=self).order_by('?').first()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'''Model for medication intake time'''
|
|
2
|
+
from django.db import models
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MedicationIntakeTimeManager(models.Manager):
|
|
6
|
+
'''Manager for the medication intake time model.'''
|
|
7
|
+
def get_by_natural_key(self, name):
|
|
8
|
+
'''Retrieve a medication intake time by its natural key.'''
|
|
9
|
+
return self.get(name=name)
|
|
10
|
+
|
|
11
|
+
class MedicationIntakeTime(models.Model):
|
|
12
|
+
'''Model representing a medication intake time.'''
|
|
13
|
+
name = models.CharField(max_length=255)
|
|
14
|
+
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
15
|
+
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
16
|
+
repeats = models.CharField(max_length=20, default = "daily")
|
|
17
|
+
time = models.TimeField()
|
|
18
|
+
|
|
19
|
+
objects = MedicationIntakeTimeManager()
|
|
20
|
+
|
|
21
|
+
def natural_key(self):
|
|
22
|
+
'''Return the natural key for the medication intake time.'''
|
|
23
|
+
return (self.name,)
|
|
24
|
+
|
|
25
|
+
def __str__(self):
|
|
26
|
+
return self.name + " at " + str(self.time) + " (" + self.repeats + ")"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'''Model for the medication schedule.'''
|
|
2
|
+
from typing import List
|
|
3
|
+
from django.db import models
|
|
4
|
+
|
|
5
|
+
class MedicationScheduleManager(models.Manager):
|
|
6
|
+
'''Manager for the medication schedule model.'''
|
|
7
|
+
def get_by_natural_key(self, name):
|
|
8
|
+
'''Retrieve a medication schedule by its natural key.'''
|
|
9
|
+
return self.get(name=name)
|
|
10
|
+
|
|
11
|
+
class MedicationSchedule(models.Model):
|
|
12
|
+
'''Model representing a medication schedule.'''
|
|
13
|
+
name = models.CharField(max_length=255)
|
|
14
|
+
name_de = models.CharField(max_length=255, blank=True, null=True)
|
|
15
|
+
name_en = models.CharField(max_length=255, blank=True, null=True)
|
|
16
|
+
description = models.TextField(blank=True, null=True)
|
|
17
|
+
medication = models.ForeignKey("Medication", on_delete=models.CASCADE)
|
|
18
|
+
unit = models.ForeignKey("Unit", on_delete=models.CASCADE)
|
|
19
|
+
therapy_duration_d = models.FloatField(blank=True, null=True)
|
|
20
|
+
dose = models.FloatField()
|
|
21
|
+
intake_times = models.ManyToManyField(
|
|
22
|
+
"MedicationIntakeTime",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
objects = MedicationScheduleManager()
|
|
26
|
+
|
|
27
|
+
def natural_key(self):
|
|
28
|
+
'''Return the natural key for the medication schedule.'''
|
|
29
|
+
return (self.name,)
|
|
30
|
+
|
|
31
|
+
def __str__(self):
|
|
32
|
+
return str(self.name)
|
|
33
|
+
|
|
34
|
+
def get_intake_times(self) -> List["MedicationIntakeTime"]:
|
|
35
|
+
'''Return a list of all intake times for this medication schedule.'''
|
|
36
|
+
return [_ for _ in self.intake_times.all()] # type: ignore # pylint: disable=E1101
|
|
37
|
+
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import subprocess
|
|
3
2
|
from django.db import models
|
|
4
3
|
|
|
4
|
+
# Django db class to store network devices (e.g., servers, clients, switches, etc.)
|
|
5
|
+
|
|
5
6
|
class NetworkDeviceManager(models.Manager):
|
|
6
|
-
|
|
7
|
+
"""Custom manager for NetworkDevice that defines name as natural key."""
|
|
7
8
|
def get_by_natural_key(self, name):
|
|
9
|
+
"""Return the network device with the given name as its natural key."""
|
|
8
10
|
return self.get(name=name)
|
|
9
11
|
|
|
10
12
|
class NetworkDevice(models.Model):
|
|
13
|
+
"""Django model representing a network device."""
|
|
11
14
|
name = models.CharField(max_length=255)
|
|
12
15
|
ip = models.GenericIPAddressField(blank=True, null=True)
|
|
13
16
|
description = models.CharField(max_length=255)
|
|
@@ -18,21 +21,23 @@ class NetworkDevice(models.Model):
|
|
|
18
21
|
objects = NetworkDeviceManager()
|
|
19
22
|
|
|
20
23
|
def __str__(self):
|
|
21
|
-
|
|
24
|
+
"""Return the device name."""
|
|
25
|
+
return str(self.name)
|
|
22
26
|
|
|
27
|
+
# pylint: disable=too-few-public-methods
|
|
23
28
|
class Meta:
|
|
29
|
+
"""Meta options for the NetworkDevice model."""
|
|
24
30
|
db_table = 'network_devices'
|
|
25
31
|
ordering = ['name']
|
|
26
32
|
|
|
27
33
|
def natural_key(self):
|
|
34
|
+
"""Return a tuple representing the natural key for this network device."""
|
|
28
35
|
return (self.name,)
|
|
29
36
|
|
|
30
37
|
def ping(self):
|
|
38
|
+
"""Check device availability by sending one ping request."""
|
|
31
39
|
target_ip = self.ip
|
|
32
40
|
|
|
33
|
-
# Import the required module
|
|
34
|
-
import subprocess
|
|
35
|
-
|
|
36
41
|
# Define the command
|
|
37
42
|
command = ['ping', '-c', '1', target_ip]
|
|
38
43
|
|
|
@@ -49,5 +54,5 @@ class NetworkDevice(models.Model):
|
|
|
49
54
|
self.online = return_code == 0
|
|
50
55
|
self.save()
|
|
51
56
|
return self.online
|
|
52
|
-
|
|
57
|
+
|
|
53
58
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Module for Organ models."""
|
|
2
|
+
from django.db import models
|
|
3
|
+
|
|
4
|
+
class OrganManager(models.Manager):
|
|
5
|
+
"""Manager for Organ model."""
|
|
6
|
+
|
|
7
|
+
def get_by_natural_key(self, name):
|
|
8
|
+
"""Retrieve an Organ by its natural key."""
|
|
9
|
+
return self.get(name=name)
|
|
10
|
+
|
|
11
|
+
def all_names(self):
|
|
12
|
+
"""Return a list of all organ names."""
|
|
13
|
+
return list(self.all().values_list('name', flat=True))
|
|
14
|
+
|
|
15
|
+
class Organ(models.Model):
|
|
16
|
+
"""Model representing an organ."""
|
|
17
|
+
|
|
18
|
+
name = models.CharField(max_length=100, unique=True)
|
|
19
|
+
name_de = models.CharField(max_length=100, blank=True, null=True)
|
|
20
|
+
name_en = models.CharField(max_length=100, blank=True, null=True)
|
|
21
|
+
description = models.TextField(blank=True, null=True)
|
|
22
|
+
description_de = models.TextField(blank=True, null=True)
|
|
23
|
+
description_en = models.TextField(blank=True, null=True)
|
|
24
|
+
|
|
25
|
+
location_choices = models.ManyToManyField(
|
|
26
|
+
'FindingLocationClassificationChoice',
|
|
27
|
+
blank=True, related_name='organs'
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
objects = OrganManager()
|
|
31
|
+
|
|
32
|
+
def natural_key(self):
|
|
33
|
+
"""Return the natural key for the organ."""
|
|
34
|
+
return (self.name,)
|
|
35
|
+
|
|
36
|
+
def __str__(self):
|
|
37
|
+
"""Return string representation of the organ."""
|
|
38
|
+
return str(self.name)
|
|
@@ -2,4 +2,22 @@ from .material import Material
|
|
|
2
2
|
from .resource import Resource
|
|
3
3
|
from .transport_route import TransportRoute
|
|
4
4
|
from .waste import Waste
|
|
5
|
-
from .distribution import
|
|
5
|
+
from .distribution import (
|
|
6
|
+
BaseValueDistribution,
|
|
7
|
+
NumericValueDistribution,
|
|
8
|
+
SingleCategoricalValueDistribution,
|
|
9
|
+
MultipleCategoricalValueDistribution,
|
|
10
|
+
DateValueDistribution,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
'Material',
|
|
15
|
+
'Resource',
|
|
16
|
+
'TransportRoute',
|
|
17
|
+
'Waste',
|
|
18
|
+
'BaseValueDistribution',
|
|
19
|
+
'NumericValueDistribution',
|
|
20
|
+
'SingleCategoricalValueDistribution',
|
|
21
|
+
'MultipleCategoricalValueDistribution',
|
|
22
|
+
'DateValueDistribution',
|
|
23
|
+
]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'''Module for distribution models.'''
|
|
2
|
+
|
|
3
|
+
from .base_value_distribution import BaseValueDistribution
|
|
4
|
+
from .numeric_value_distribution import NumericValueDistribution
|
|
5
|
+
from .single_categorical_value_distribution import SingleCategoricalValueDistribution
|
|
6
|
+
from .multiple_categorical_value_distribution import MultipleCategoricalValueDistribution
|
|
7
|
+
from .date_value_distribution import DateValueDistribution
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'BaseValueDistribution',
|
|
12
|
+
'NumericValueDistribution',
|
|
13
|
+
'SingleCategoricalValueDistribution',
|
|
14
|
+
'MultipleCategoricalValueDistribution',
|
|
15
|
+
'DateValueDistribution',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
# Example Usage
|
|
19
|
+
# Numeric distribution for age
|
|
20
|
+
# age_distribution = NumericValueDistribution.objects.create(
|
|
21
|
+
# name='Age Distribution',
|
|
22
|
+
# distribution_type='normal',
|
|
23
|
+
# min_value=0,
|
|
24
|
+
# max_value=100,
|
|
25
|
+
# mean=50,
|
|
26
|
+
# std_dev=15
|
|
27
|
+
# )
|
|
28
|
+
|
|
29
|
+
# # Single categorical distribution for gender
|
|
30
|
+
# gender_distribution = SingleCategoricalValueDistribution.objects.create(
|
|
31
|
+
# name='Gender Distribution',
|
|
32
|
+
# categories={'male': 0.5, 'female': 0.5}
|
|
33
|
+
# )
|
|
34
|
+
|
|
35
|
+
# # Multiple categorical distribution for symptoms
|
|
36
|
+
# symptoms_distribution = MultipleCategoricalValueDistribution.objects.create(
|
|
37
|
+
# name='Symptoms Distribution',
|
|
38
|
+
# categories={'fever': 0.3, 'cough': 0.4, 'fatigue': 0.2, 'nausea': 0.1},
|
|
39
|
+
# min_count=1,
|
|
40
|
+
# max_count=3,
|
|
41
|
+
# count_distribution_type='normal',
|
|
42
|
+
# count_mean=2,
|
|
43
|
+
# count_std_dev=0.5
|
|
44
|
+
# )
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
|
|
3
|
+
class BaseValueDistribution(models.Model):
|
|
4
|
+
"""
|
|
5
|
+
Abstract base class for value distributions.
|
|
6
|
+
"""
|
|
7
|
+
name = models.CharField(max_length=100)
|
|
8
|
+
|
|
9
|
+
class Meta:
|
|
10
|
+
abstract = True
|
|
11
|
+
|
|
12
|
+
def generate_value(self):
|
|
13
|
+
"""
|
|
14
|
+
Generate a value based on the distribution rules.
|
|
15
|
+
Must be implemented by subclasses.
|
|
16
|
+
"""
|
|
17
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
18
|
+
|
|
19
|
+
def natural_key(self):
|
|
20
|
+
return (self.name,)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'''Model for date value distribution'''
|
|
2
|
+
|
|
3
|
+
from datetime import date, timedelta
|
|
4
|
+
from django.db import models
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from .base_value_distribution import BaseValueDistribution
|
|
8
|
+
|
|
9
|
+
class DateValueDistributionManager(models.Manager):
|
|
10
|
+
'''Object manager for DateValueDistribution'''
|
|
11
|
+
def get_by_natural_key(self, name):
|
|
12
|
+
'''Retrieve a DateValueDistribution by its natural key.'''
|
|
13
|
+
return self.get(name=name)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DateValueDistribution(BaseValueDistribution):
|
|
17
|
+
"""
|
|
18
|
+
Assign date values based on specified distribution.
|
|
19
|
+
Expects distribution_type (uniform, normal) and mode (date, timedelta) and based on this either
|
|
20
|
+
date_min, date_max, date_mean, date_std_dev or
|
|
21
|
+
timedelta_days_min, timedelta_days_max, timedelta_days_mean, timedelta_days_std_dev
|
|
22
|
+
"""
|
|
23
|
+
objects = DateValueDistributionManager()
|
|
24
|
+
name = models.CharField(max_length=100)
|
|
25
|
+
name_de = models.CharField(max_length=100, blank=True, null=True)
|
|
26
|
+
name_en = models.CharField(max_length=100, blank=True, null=True)
|
|
27
|
+
description = models.TextField(blank=True, null=True)
|
|
28
|
+
DISTRIBUTION_CHOICES = [
|
|
29
|
+
('uniform', 'Uniform'),
|
|
30
|
+
('normal', 'Normal'),
|
|
31
|
+
]
|
|
32
|
+
MODE_CHOICES = [
|
|
33
|
+
('date', 'Date'),
|
|
34
|
+
('timedelta', 'Timedelta'),
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
distribution_type = models.CharField(max_length=20, choices=DISTRIBUTION_CHOICES)
|
|
38
|
+
mode = models.CharField(max_length=20, choices=MODE_CHOICES)
|
|
39
|
+
|
|
40
|
+
# Date-related fields
|
|
41
|
+
date_min = models.DateField(blank=True, null=True)
|
|
42
|
+
date_max = models.DateField(blank=True, null=True)
|
|
43
|
+
date_mean = models.DateField(blank=True, null=True)
|
|
44
|
+
date_std_dev = models.IntegerField(blank=True, null=True) # Standard deviation in days
|
|
45
|
+
|
|
46
|
+
# Timedelta-related fields
|
|
47
|
+
timedelta_days_min = models.IntegerField(blank=True, null=True)
|
|
48
|
+
timedelta_days_max = models.IntegerField(blank=True, null=True)
|
|
49
|
+
timedelta_days_mean = models.IntegerField(blank=True, null=True)
|
|
50
|
+
timedelta_days_std_dev = models.IntegerField(blank=True, null=True)
|
|
51
|
+
|
|
52
|
+
def generate_value(self):
|
|
53
|
+
if self.mode == 'date':
|
|
54
|
+
return self._generate_date_value()
|
|
55
|
+
elif self.mode == 'timedelta':
|
|
56
|
+
return self._generate_timedelta_value()
|
|
57
|
+
else:
|
|
58
|
+
raise ValueError("Unsupported mode")
|
|
59
|
+
|
|
60
|
+
def _generate_date_value(self):
|
|
61
|
+
#UNTESTED
|
|
62
|
+
if self.distribution_type == 'uniform':
|
|
63
|
+
start_date = self.date_min.toordinal()
|
|
64
|
+
end_date = self.date_max.toordinal()
|
|
65
|
+
random_ordinal = np.random.randint(start_date, end_date)
|
|
66
|
+
return date.fromordinal(random_ordinal)
|
|
67
|
+
elif self.distribution_type == 'normal':
|
|
68
|
+
mean_ordinal = self.date_mean.toordinal()
|
|
69
|
+
std_dev_days = self.date_std_dev
|
|
70
|
+
random_ordinal = int(np.random.normal(mean_ordinal, std_dev_days))
|
|
71
|
+
random_ordinal = np.clip(random_ordinal, self.date_min.toordinal(), self.date_max.toordinal())
|
|
72
|
+
return date.fromordinal(random_ordinal)
|
|
73
|
+
else:
|
|
74
|
+
raise ValueError("Unsupported distribution type")
|
|
75
|
+
|
|
76
|
+
def _generate_timedelta_value(self):
|
|
77
|
+
if self.distribution_type == 'uniform':
|
|
78
|
+
random_days = np.random.randint(self.timedelta_days_min, self.timedelta_days_max + 1)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
elif self.distribution_type == 'normal':
|
|
82
|
+
random_days = int(np.random.normal(self.timedelta_days_mean, self.timedelta_days_std_dev))
|
|
83
|
+
random_days = np.clip(random_days, self.timedelta_days_min, self.timedelta_days_max)
|
|
84
|
+
|
|
85
|
+
else:
|
|
86
|
+
raise ValueError("Unsupported distribution type")
|
|
87
|
+
|
|
88
|
+
current_date = date.today()
|
|
89
|
+
generated_date = current_date - timedelta(days=random_days)
|
|
90
|
+
print(generated_date)
|
|
91
|
+
return(generated_date)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
import numpy as np
|
|
3
|
+
from .base_value_distribution import BaseValueDistribution
|
|
4
|
+
|
|
5
|
+
class MultipleCategoricalValueDistributionManager(models.Manager):
|
|
6
|
+
def get_by_natural_key(self, name):
|
|
7
|
+
return self.get(name=name)
|
|
8
|
+
|
|
9
|
+
class MultipleCategoricalValueDistribution(BaseValueDistribution):
|
|
10
|
+
"""
|
|
11
|
+
Multiple categorical value distribution model.
|
|
12
|
+
Assigns a specific number or varying number of values based on probabilities.
|
|
13
|
+
"""
|
|
14
|
+
objects = MultipleCategoricalValueDistributionManager()
|
|
15
|
+
categories = models.JSONField() # { "category": "probability", ... }
|
|
16
|
+
min_count = models.IntegerField()
|
|
17
|
+
max_count = models.IntegerField()
|
|
18
|
+
count_distribution_type = models.CharField(max_length=20, choices=[('uniform', 'Uniform'), ('normal', 'Normal')])
|
|
19
|
+
count_mean = models.FloatField(null=True, blank=True)
|
|
20
|
+
count_std_dev = models.FloatField(null=True, blank=True)
|
|
21
|
+
|
|
22
|
+
def generate_value(self):
|
|
23
|
+
if self.count_distribution_type == 'uniform':
|
|
24
|
+
count = np.random.randint(self.min_count, self.max_count + 1)
|
|
25
|
+
elif self.count_distribution_type == 'normal':
|
|
26
|
+
count = int(np.random.normal(self.count_mean, self.count_std_dev))
|
|
27
|
+
count = np.clip(count, self.min_count, self.max_count)
|
|
28
|
+
else:
|
|
29
|
+
raise ValueError("Unsupported count distribution type")
|
|
30
|
+
|
|
31
|
+
categories, probabilities = zip(*self.categories.items())
|
|
32
|
+
return list(np.random.choice(categories, size=count, p=probabilities))
|