-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from EBI-Metagenomics/Hotfix/Analysis-Summary
Made adjustments to support having analysis_summary inside the analys…
- Loading branch information
Showing
5 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
emgapi/migrations/0011_analysisjob_analysis_summary_json.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.18 on 2023-09-13 10:24 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('emgapi', '0010_runextraannotation'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='analysisjob', | ||
name='analysis_summary_json', | ||
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_JSON', null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
emgapianns/management/commands/import_analysis_summaries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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 | ||
|
||
try: | ||
start_index = (batch_number - 1) * batch_size | ||
end_index = batch_number * batch_size | ||
|
||
analysis_jobs = AnalysisJob.objects.all()[start_index:end_index] | ||
|
||
self.stdout.write(self.style.SUCCESS(f'Processing batch {batch_number} of {len(analysis_jobs)} records.')) | ||
|
||
updated_records = [] | ||
|
||
for analysis_job in analysis_jobs: | ||
analysis_summary = analysis_job.analysis_summary | ||
if analysis_summary: | ||
analysis_job.analysis_summary_json = analysis_summary | ||
updated_records.append(analysis_job) | ||
|
||
if updated_records: | ||
AnalysisJob.objects.bulk_update(updated_records, ['analysis_summary_json']) | ||
|
||
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.')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters