# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-06-01 13:36
from __future__ import unicode_literals

from django.db import migrations
from api.models import UnitPrefix

# Add default values to database

# create default values for units
def load_units(apps, schema_editor):
    Unit = apps.get_model("api", "Unit")
    
    units = [
        Unit(name='Ampere', symbol='A'),
        Unit(name='Ampere Hour', symbol='Ah'),
        Unit(name='Becquerel', symbol='Bq'),
        Unit(name='byte', symbol='B'),
        Unit(name='Candela', symbol='cd'),
        Unit(name='Celsius', symbol='°C'),
        Unit(name='Coulomb', symbol='C'),
        Unit(name='degree', symbol='°'),
        Unit(name='Farad', symbol='F'),
        Unit(name='Gram', symbol='g'),
        Unit(name='Gray', symbol='Gy'),
        Unit(name='Henry', symbol='H'),
        Unit(name='Hertz', symbol='Hz'),
        Unit(name='Joule', symbol='J'),
        Unit(name='Katal', symbol='kat'),
        Unit(name='Kelvin', symbol='K'),
        Unit(name='Lumen', symbol='lm'),
        Unit(name='Lux', symbol='lx'),
        Unit(name='Meter', symbol='m'),
        Unit(name='Mol', symbol='mol'),
        Unit(name='Newton', symbol='N'),
        Unit(name='Ohm', symbol='Ω'),
        Unit(name='Pascal', symbol='Pa'),
        Unit(name='ppm/degC', symbol='ppm/°C'),
        Unit(name='Second', symbol='s'),
        Unit(name='Siemens', symbol='S'),
        Unit(name='Sievert', symbol='Sv'),
        Unit(name='Tesla', symbol='T'),
        Unit(name='Volt', symbol='V'),
        Unit(name='Watt', symbol='W'),
        Unit(name='Weber', symbol='Wb'),
    ]
    
    for unit in units:
        try:
            Unit.objects.get(name=unit.name)
        except Unit.DoesNotExist:
            print "Add ", unit.name
            unit.save()

# create default values for unit prefixes
def load_unit_prefixes(apps, schema_editor):
    UnitPrefix = apps.get_model("api", "UnitPrefix")

    prefixes = [
        UnitPrefix(name='yotta', symbol='Y', power='1E24'),
        UnitPrefix(name='zetta', symbol='Z', power='1E21'),
        UnitPrefix(name='exa', symbol='E', power='1E18'),
        UnitPrefix(name='peta', symbol='P', power='1E15'),
        UnitPrefix(name='tera', symbol='T', power='1E12'),
        UnitPrefix(name='giga', symbol='G', power='1E9'),
        UnitPrefix(name='mega', symbol='M', power='1E6'),
        UnitPrefix(name='kilo', symbol='k', power='1E3'),
        UnitPrefix(name='hecto', symbol='h', power='1E2'),
        UnitPrefix(name='deca', symbol='da', power='1E1'),
        UnitPrefix(name='-', symbol='', power='1E0'),
        UnitPrefix(name='deci', symbol='d', power='1E-1'),
        UnitPrefix(name='centi', symbol='c', power='1E-2'),
        UnitPrefix(name='milli', symbol='m', power='1E-3'),
        UnitPrefix(name='micro', symbol='µ', power='1E-6'),
        UnitPrefix(name='nano', symbol='n', power='1E-9'),
        UnitPrefix(name='pico', symbol='p', power='1E-12'),
        UnitPrefix(name='femto', symbol='f', power='1E-15'),
        UnitPrefix(name='atto', symbol='a', power='1E-18'),
        UnitPrefix(name='yocto', symbol='y', power='1E-24'),
        UnitPrefix(name='kibi', symbol='Ki', power='1024'),
        UnitPrefix(name='mebi', symbol='Mi', power='1024^2'),
        UnitPrefix(name='gibi', symbol='Gi', power='1024^3'),
        UnitPrefix(name='tebi', symbol='Ti', power='1024^4'),
        UnitPrefix(name='pebi', symbol='Pi', power='1024^5'),
        UnitPrefix(name='exbi', symbol='Ei', power='1024^6'),
        UnitPrefix(name='zebi', symbol='Zi', power='1024^7'),
        UnitPrefix(name='yobi', symbol='Yi', power='1024^8'),
    ]
    
    for prefix in prefixes:
        try:
            UnitPrefix.objects.get(name=prefix.name)
        except UnitPrefix.DoesNotExist:
            print "Add ", prefix.name
            prefix.save()

class Migration(migrations.Migration):

    dependencies = [
        ('api', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(load_units),
        migrations.RunPython(load_unit_prefixes)
    ]
