# Generated by Django 2.1.5 on 2019-02-19 05:51

from django.db import migrations

AQI_CATEGORY_THRESHOLDS = [
    # AQI
    {
        "abbreviation": "G",
        "lower_threshold_value": 0.0,
        "upper_threshold_value": 33.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 34.0,
        "upper_threshold_value": 66.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 67.0,
        "upper_threshold_value": 99.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 100.0,
        "upper_threshold_value": 149.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 150.0,
        "upper_threshold_value": 99999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA"
    },
    # PM2.5
    {
        "abbreviation": "G",
        "lower_threshold_value": 0,
        "upper_threshold_value": 9.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm2.5",
        "units": "ug/m3"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 10.0,
        "upper_threshold_value": 19.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm2.5",
        "units": "ug/m3"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 20.0,
        "upper_threshold_value": 24.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm2.5",
        "units": "ug/m3"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 25.0,
        "upper_threshold_value": 49.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm2.5",
        "units": "ug/m3"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 50.0,
        "upper_threshold_value": 99999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm2.5",
        "units": "ug/m3"
    },
    # PM10
    {
        "abbreviation": "G",
        "lower_threshold_value": 0,
        "upper_threshold_value": 19.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm10",
        "units": "ug/m3"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 20.0,
        "upper_threshold_value": 34.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm10",
        "units": "ug/m3"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 35.0,
        "upper_threshold_value": 49.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm10",
        "units": "ug/m3"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 50.0,
        "upper_threshold_value": 99.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm10",
        "units": "ug/m3"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 100.0,
        "upper_threshold_value": 99999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "pm10",
        "units": "ug/m3"
    },
    # CO
    {
        "abbreviation": "G",
        "lower_threshold_value": 0,
        "upper_threshold_value": 4999.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "co",
        "units": "ug/m3"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 5000.0,
        "upper_threshold_value": 7499.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "co",
        "units": "ug/m3"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 7500.0,
        "upper_threshold_value": 9999.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "co",
        "units": "ug/m3"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 10000.0,
        "upper_threshold_value": 19999.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "co",
        "units": "ug/m3"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 20000.0,
        "upper_threshold_value": 999999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "co",
        "units": "ug/m3"
    },
    # NO2
    {
        "abbreviation": "G",
        "lower_threshold_value": 0,
        "upper_threshold_value": 39.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "no2",
        "units": "ug/m3"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 40.0,
        "upper_threshold_value": 99.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "no2",
        "units": "ug/m3"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 100.0,
        "upper_threshold_value": 199.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "no2",
        "units": "ug/m3"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 200.0,
        "upper_threshold_value": 399.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "no2",
        "units": "ug/m3"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 400.0,
        "upper_threshold_value": 99999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "no2",
        "units": "ug/m3"
    },
    # O3
    {
        "abbreviation": "G",
        "lower_threshold_value": 0,
        "upper_threshold_value": 79.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "o3",
        "units": "ug/m3"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 80.0,
        "upper_threshold_value": 119.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "o3",
        "units": "ug/m3"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 120.0,
        "upper_threshold_value": 179.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "o3",
        "units": "ug/m3"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 180.0,
        "upper_threshold_value": 239.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "o3",
        "units": "ug/m3"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 240.0,
        "upper_threshold_value": 99999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "o3",
        "units": "ug/m3"
    },
    # SO2
    {
        "abbreviation": "G",
        "lower_threshold_value": 0,
        "upper_threshold_value": 99.99,
        "description": "Good",
        "background_colour": "#50F0E6",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "so2",
        "units": "ug/m3"
    }, {
        "abbreviation": "F",
        "lower_threshold_value": 100.0,
        "upper_threshold_value": 199.99,
        "description": "Fair",
        "background_colour": "#50CCAA",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "so2",
        "units": "ug/m3"
    }, {
        "abbreviation": "M",
        "lower_threshold_value": 200.0,
        "upper_threshold_value": 349.99,
        "description": "Moderate",
        "background_colour": "#F0E641",
        "foreground_colour": "#000000",
        "aqi_organization_id": "EUEEA",
        "pollutant": "so2",
        "units": "ug/m3"
    }, {
        "abbreviation": "P",
        "lower_threshold_value": 350.0,
        "upper_threshold_value": 499.99,
        "description": "Poor",
        "background_colour": "#FF5050",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "so2",
        "units": "ug/m3"
    }, {
        "abbreviation": "VP",
        "lower_threshold_value": 500.0,
        "upper_threshold_value": 99999.0,
        "description": "Very Poor",
        "background_colour": "#960032",
        "foreground_colour": "#FFFFFF",
        "aqi_organization_id": "EUEEA",
        "pollutant": "so2",
        "units": "ug/m3"
    }
]


def insert_aqi_categories(apps, schema_editor):
    AQICategoryThreshold = apps.get_model(
        'common', 'AQICategoryThreshold')
    for aqi in AQI_CATEGORY_THRESHOLDS:
        AQICategoryThreshold.objects.get_or_create(**aqi)


def revert_aqi_categories(apps, schema_editor):
    AQICategoryThreshold = apps.get_model(
        'common', 'AQICategoryThreshold')
    AQICategoryThreshold.objects.filter(aqi_organization_id="EUEEA").delete()


class Migration(migrations.Migration):

    dependencies = [
        ('common', '0003_au_aqi_index_tables_data'),
    ]

    operations = [
        migrations.RunPython(insert_aqi_categories, revert_aqi_categories),
    ]
