# Generated by Django 1.11.2 on 2017-07-23 18:20

import autoplanner.models
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Agent',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=500, verbose_name='Name')),
                ('start_time', models.DateTimeField(blank=True, db_index=True, default=None, help_text='Before this date, the agent cannot performany task.', null=True, verbose_name='Arrival time')),
                ('end_time', models.DateTimeField(blank=True, db_index=True, default=None, help_text='After this date, the agent cannot perform any task.', null=True, verbose_name='Leaving time')),
            ],
            options={
                'ordering': ('name',),
            },
        ),
        migrations.CreateModel(
            name='AgentCategoryPreferences',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('affinity', models.FloatField(blank=True, default=0.0, verbose_name='Affinity of the agent for the category.')),
                ('balancing_offset', models.FloatField(blank=True, default=0, verbose_name='Number of time units already done')),
                ('balancing_count', models.FloatField(blank=True, default=1.0, help_text='Blank if the agent cannot perform tasks of this category', null=True, verbose_name='If a task of this category performed by this agent counts twice, set this number to 2.0.')),
                ('agent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Agent')),
            ],
            options={
                'verbose_name': 'preference by agent and category',
                'verbose_name_plural': 'preferences by agent and category',
            },
        ),
        migrations.CreateModel(
            name='AgentTaskExclusion',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('agent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Agent')),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='Category',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=500, verbose_name='Name')),
                ('balancing_mode', models.CharField(blank=True, choices=[(None, 'No balancing'), ('time', 'Total task time'), ('number', 'Total task number')], default=None, max_length=10, null=True, verbose_name='Balancing mode')),
                ('balancing_tolerance', models.FloatField(blank=True, default=0.0, null=True, verbose_name='Tolerance for balancing the total duration (in seconds)|tasks across agents')),
                ('auto_affinity', models.FloatField(blank=True, default=0.0, verbose_name='Affinity for allocating successive tasks of the same category to the same agent')),
            ],
            options={
                'verbose_name': 'Category of tasks',
                'verbose_name_plural': 'Categories of tasks',
            },
        ),
        migrations.CreateModel(
            name='MaxTaskAffectation',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('mode', models.CharField(choices=[('min', 'At least this number of tasks'), ('max', 'At most this number of tasks')], default='max', max_length=3, verbose_name='Mode')),
                ('range_time_slice_days', models.IntegerField(default=2, verbose_name='Period length (days)')),
                ('range_time_slice_hours', models.IntegerField(default=0, verbose_name='Period length (hours)')),
                ('range_time_slice_seconds', models.IntegerField(default=0, verbose_name='Period length (seconds)')),
                ('task_maximum_count', models.IntegerField(default=1, verbose_name='Number of tasks in this range')),
                ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Category')),
            ],
            options={
                'verbose_name': 'Number of tasks performed by an agent in a category',
                'verbose_name_plural': 'Number of tasks performed by an agent in a category',
            },
        ),
        migrations.CreateModel(
            name='MaxTimeTaskAffectation',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('mode', models.CharField(choices=[('min', 'At least this number of tasks'), ('max', 'At most this number of tasks')], default='max', max_length=3, verbose_name='Mode')),
                ('range_time_slice_days', models.IntegerField(default=2, verbose_name='Period length (days)')),
                ('range_time_slice_hours', models.IntegerField(default=0, verbose_name='Period length (hours)')),
                ('range_time_slice_seconds', models.IntegerField(default=0, verbose_name='Period length (seconds)')),
                ('task_maximum_time_days', models.IntegerField(default=1, verbose_name='Total task time in this range (days)')),
                ('task_maximum_time_hours', models.IntegerField(default=0, verbose_name='Total task time in this range (hours)')),
                ('task_maximum_time_seconds', models.IntegerField(default=0, verbose_name='Total task time in this range (seconds)')),
                ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Category')),
            ],
            options={
                'verbose_name': 'Maximum time spent by an agent in a category',
                'verbose_name_plural': 'Maximum time spent by an agent in a category',
            },
        ),
        migrations.CreateModel(
            name='Organization',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=500, verbose_name='Name')),
                ('message', models.CharField(blank=True, default='', max_length=500, verbose_name='Message')),
                ('description', models.TextField(blank=True, default='', verbose_name='Description')),
                ('celery_task_id', models.CharField(blank=True, db_index=True, default=None, max_length=20, null=True, verbose_name='Celery task id')),
                ('celery_start', models.DateTimeField(blank=True, default=None, null=True, verbose_name='Celery start')),
                ('celery_end', models.DateTimeField(blank=True, default=None, null=True, verbose_name='Celery end')),
                ('access_token', models.CharField(default=autoplanner.models.default_token, max_length=300, validators=[django.core.validators.RegexValidator('^[a-zA-Z0-9]{1,300}$')], verbose_name='Access token')),
                ('max_compute_time', models.PositiveIntegerField(blank=True, default=None, help_text='Leave it blank if you do not want to set a limit', null=True, verbose_name='Maximum time, in seconds, for finding a solution')),
                ('admins', models.ManyToManyField(db_index=True, to=settings.AUTH_USER_MODEL, verbose_name='Administrators')),
            ],
        ),
        migrations.CreateModel(
            name='ScheduleRun',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.NullBooleanField(db_index=True, default=None, verbose_name='Is valid?')),
                ('is_selected', models.BooleanField(db_index=True, default=False, verbose_name='Selected?')),
                ('message', models.TextField(blank=True, default='', max_length=500, verbose_name='Result')),
                ('celery_task_id', models.CharField(blank=True, db_index=True, default=None, max_length=20, null=True, verbose_name='Celery task id')),
                ('celery_start', models.DateTimeField(blank=True, default=None, null=True, verbose_name='Computation start')),
                ('celery_end', models.DateTimeField(blank=True, default=None, null=True, verbose_name='Computation end')),
                ('process_id', models.IntegerField(blank=True, db_index=True, default=None, null=True, verbose_name='Process ID')),
                ('result_dict', models.TextField(blank=True, default=None, null=True, verbose_name='JSON-serialized result')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization')),
            ],
        ),
        migrations.CreateModel(
            name='Task',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=500, verbose_name='Name')),
                ('start_time', models.DateTimeField(db_index=True, default=autoplanner.models.default_day_start, verbose_name='Start time')),
                ('end_time', models.DateTimeField(db_index=True, default=autoplanner.models.default_day_end, verbose_name='End time')),
                ('fixed', models.BooleanField(db_index=True, default=False, verbose_name='Forced agent')),
                ('agent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='autoplanner.Agent')),
                ('categories', models.ManyToManyField(blank=True, db_index=True, to='autoplanner.Category')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization')),
                ('task_serie', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='autoplanner.Task')),
            ],
            options={
                'ordering': ('start_time', 'end_time'),
            },
        ),
        migrations.AddField(
            model_name='organization',
            name='current_schedule',
            field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='current_organizations', to='autoplanner.ScheduleRun'),
        ),
        migrations.AddField(
            model_name='maxtimetaskaffectation',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization'),
        ),
        migrations.AddField(
            model_name='maxtaskaffectation',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization'),
        ),
        migrations.AddField(
            model_name='category',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization'),
        ),
        migrations.AddField(
            model_name='agenttaskexclusion',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization'),
        ),
        migrations.AddField(
            model_name='agenttaskexclusion',
            name='task',
            field=models.ForeignKey(help_text='Select the task that cannot be performed by the agent.', on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Task', verbose_name='Task'),
        ),
        migrations.AddField(
            model_name='agentcategorypreferences',
            name='category',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Category'),
        ),
        migrations.AddField(
            model_name='agentcategorypreferences',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization'),
        ),
        migrations.AddField(
            model_name='agent',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='autoplanner.Organization'),
        ),
    ]
