<commit_before><commit_msg>associate existing ROIs to the proper ROIsAnnotationStep object<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


def assign_rois_annotation_step(apps, schema_editor):
    ROIsAnnotationStep = apps.get_model('reviews_manager', 'ROIsAnnotationStep')

    annotation_steps = ROIsAnnotationStep.objects.all()
    for step in annotation_steps:
        slide = step.slide
        for slice in slide.slices.all():
            slice.annotation_step = step
            slice.save()
            for core in slice.cores.all():
                core.annotation_step = step
                core.save()
                for focus_region in core.focus_regions.all():
                    focus_region.annotation_step = step
                    focus_region.save()


def remove_rois_annotation_step(apps, schema_editor):
    Slice = apps.get_model('rois_manager', 'Slice')

    for slice in Slice.objects.all():
        slice.annotation_step = None
        slice.save()
        for core in slice.cores.all():
            core.annotation_step = None
            core.save()
            for focus_region in core.focus_regions.all():
                focus_region.annotation_step = None
                focus_region.save()


class Migration(migrations.Migration):

    dependencies = [
        ('rois_manager', '0009_auto_20161215_0940'),
    ]

    operations = [
        migrations.RunPython(assign_rois_annotation_step, remove_rois_annotation_step)
    ]
{'fraction_non_alphanumeric': 0.0867579908675799, 'fraction_numerical': 0.011089367253750815, 'mean_word_length': 2.4943052391799543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4821130', 'n_tokens_mistral': 445, 'n_tokens_neox': 415, 'n_words': 89}