# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-31 20:10
from __future__ import unicode_literals

from django.db import migrations


def adjust_data_forward(apps, schema_editor):
    BayesianNetworkNode = apps.get_model(
        "bayesian_networks", "BayesianNetworkNode")
    Y = BayesianNetworkNode.objects.get(
            name="Y", network__name="Clustering (Example)")
    Y_col_avg_logged = Y.columns.get(ref_column="avg_time_logged")
    Y_col_avg_logged.ref_column = "avg_time_pages"
    Y_col_avg_logged.save()


def adjust_data_backward(apps, schema_editor):
    BayesianNetworkNode = apps.get_model(
        "bayesian_networks", "BayesianNetworkNode")
    Y = BayesianNetworkNode.objects.get(
            name="Y", network__name="Clustering (Example)")
    Y_col_avg_time_pages = Y.columns.get(ref_column="avg_time_pages")
    Y_col_avg_time_pages.ref_column = "avg_time_logged"
    Y_col_avg_time_pages.save()

class Migration(migrations.Migration):

    dependencies = [
        ('examples', '0008_add_visits_to_pages'),
    ]

    operations = [
        migrations.RenameField(
            model_name='userinfo',
            old_name='avg_time_logged',
            new_name='avg_time_pages',
        ),
        migrations.RunPython(adjust_data_forward,
                             adjust_data_backward)
    ]
