Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made adjustments to support having analysis_summary inside the analys… #326

Merged
merged 9 commits into from
Sep 14, 2023
18 changes: 18 additions & 0 deletions emgapi/migrations/0011_analysisjob_job_operator_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-09-12 17:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0010_runextraannotation'),
]

operations = [
migrations.AddField(
model_name='analysisjob',
name='job_operator_2',
field=models.CharField(blank=True, db_column='JOB_OPERATOR_2', max_length=15, null=True),
),
]
17 changes: 17 additions & 0 deletions emgapi/migrations/0012_remove_analysisjob_job_operator_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.18 on 2023-09-12 17:36

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0011_analysisjob_job_operator_2'),
]

operations = [
migrations.RemoveField(
model_name='analysisjob',
name='job_operator_2',
),
]
18 changes: 18 additions & 0 deletions emgapi/migrations/0013_analysisjob_analysis_summary_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-09-12 17:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0012_remove_analysisjob_job_operator_2'),
]

operations = [
migrations.AddField(
model_name='analysisjob',
name='analysis_summary_two',
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_TWO', null=True),
),
]
22 changes: 22 additions & 0 deletions emgapi/migrations/0014_auto_20230912_1741.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.18 on 2023-09-12 17:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0013_analysisjob_analysis_summary_two'),
]

operations = [
migrations.RemoveField(
model_name='analysisjob',
name='analysis_summary_two',
),
migrations.AddField(
model_name='analysisjob',
name='analysis_summary_json',
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_JSON', null=True),
),
]
22 changes: 22 additions & 0 deletions emgapi/migrations/0015_auto_20230912_1748.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.18 on 2023-09-12 17:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0014_auto_20230912_1741'),
]

operations = [
migrations.RemoveField(
model_name='analysisjob',
name='analysis_summary_json',
),
migrations.AddField(
model_name='analysisjob',
name='analysis_summary_umbers_of_last_hearth',
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_UMBERS_OF_LAST_HEARTH', null=True),
),
]
22 changes: 22 additions & 0 deletions emgapi/migrations/0016_auto_20230912_1749.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we squash these multiple migrations? (Or since they look like temporary testing things, delete all of the migration files, reset the sqlite EMG fixture to the one from the client repo, and run makemigrations again to just get a single migration with the needed schema changes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SandyRogers I've squashed the migrations

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.18 on 2023-09-12 17:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0015_auto_20230912_1748'),
]

operations = [
migrations.RemoveField(
model_name='analysisjob',
name='analysis_summary_umbers_of_last_hearth',
),
migrations.AddField(
model_name='analysisjob',
name='analysis_summary_json',
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_JSON', null=True),
),
]
2 changes: 2 additions & 0 deletions emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,8 @@ def _custom_pk(self):
blank=True, null=True)
job_operator = models.CharField(
db_column='JOB_OPERATOR', max_length=15, blank=True, null=True)
analysis_summary_json = models.JSONField(
db_column='ANALYSIS_SUMMARY_JSON', blank=True, null=True)
pipeline = models.ForeignKey(
Pipeline, db_column='PIPELINE_ID', blank=True, null=True,
related_name='analyses', on_delete=models.CASCADE)
Expand Down
34 changes: 34 additions & 0 deletions emgapianns/management/commands/import_analysis_summaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.core.management.base import BaseCommand
from emgapi.models import AnalysisJob


class Command(BaseCommand):
help = 'Copy values from analysis_summary to analysis_summary_json for a specified batch of AnalysisJob records'

def add_arguments(self, parser):
parser.add_argument('batch_number', type=int, help='Batch number to process')

def handle(self, *args, **options):
batch_number = options['batch_number']
batch_size = 10000 # Set your desired batch size here

try:
# Calculate the starting and ending index for the batch
start_index = (batch_number - 1) * batch_size
end_index = batch_number * batch_size

# Get AnalysisJob records for the specified batch
analysis_jobs = AnalysisJob.objects.all()[start_index:end_index]

# Print the number of records in the batch
self.stdout.write(self.style.SUCCESS(f'Processing batch {batch_number} of {len(analysis_jobs)} records.'))

for analysis_job in analysis_jobs:
SandyRogers marked this conversation as resolved.
Show resolved Hide resolved
analysis_summary = analysis_job.analysis_summary
if analysis_summary:
analysis_job.analysis_summary_json = analysis_summary
analysis_job.save()

self.stdout.write(self.style.SUCCESS(f'Values copied successfully for batch {batch_number}.'))
except AnalysisJob.DoesNotExist:
self.stdout.write(self.style.ERROR('AnalysisJob table does not exist or is empty.'))
14 changes: 13 additions & 1 deletion emgapianns/management/commands/import_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from emgapi import models as emg_models
from emgapianns.management.lib.uploader_exceptions import UnexpectedVariableName
from ..lib import EMGBaseCommand
from emgapi.models import AnalysisJob

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,7 +86,18 @@ def import_qc(reader, job, emg_db):
defaults={'var_val_ucv': row[1]}
)

anns.append(job_ann)
analysis_job = AnalysisJob.objects.get(job_id=job)
analysis_summary = analysis_job.analysis_summary_json or []
analysis_summary.append({
'key': job_ann.var.var_name,
'value': job_ann.var_val_ucv,
})

# Update analysis_summary_json with the modified array
analysis_job.analysis_summary_json = analysis_summary
analysis_job.save()

anns.append(job_ann)
logger.info("Total %d Annotations for Run: %s" % (len(anns), job))

@staticmethod
Expand Down
Loading