<reponame>ShuHuang/batterydatabase<gh_stars>10-100
# -*- coding: utf-8 -*-
"""
Units and models for lengths.

:codeauthor: <NAME> (<EMAIL>)
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .quantity_model import QuantityModel
from .unit import Unit
from .dimension import Dimension
from ...parse.elements import W, I, R, Optional, Any, OneOrMore, Not, ZeroOrMore
from ...parse.actions import merge, join
import logging

log = logging.getLogger(__name__)


class Length(Dimension):
    """
    Dimension subclass for lengths.
    """
    pass


class LengthModel(QuantityModel):
    """
    Model for lengths.
    """
    dimensions = Length()


class LengthUnit(Unit):
    """
    Base class for units with dimensions of length.
    The standard value for length is defined to be a meter, implemented in the Meter class.
    """

    def __init__(self, magnitude=0.0, powers=None):
        super(LengthUnit, self).__init__(Length(), magnitude, powers)


class Meter(LengthUnit):
    """
    Class for meters.
    """

    def convert_value_to_standard(self, value):
        return value

    def convert_value_from_standard(self, value):
        return value

    def convert_error_to_standard(self, error):
        return error

    def convert_error_from_standard(self, error):
        return error


class CentiMeter(LengthUnit):
    """
    Class for meters.
    """

    def convert_value_to_standard(self, value):
        return value * 100

    def convert_value_from_standard(self, value):
        return value * 100

    def convert_error_to_standard(self, error):
        return error * 100

    def convert_error_from_standard(self, error):
        return error * 100


class MilliMeter(LengthUnit):
    """
    Class for meters.
    """

    def convert_value_to_standard(self, value):
        return value * 1000

    def convert_value_from_standard(self, value):
        return value * 1000

    def convert_error_to_standard(self, error):
        return error * 1000

    def convert_error_from_standard(self, error):
        return error * 1000


class Mile(LengthUnit):
    """
    Class for miles.
    """

    def convert_value_to_standard(self, value):
        return value * 1609.34

    def convert_value_from_standard(self, value):
        return value * 0.000621371

    def convert_error_to_standard(self, error):
        return error * 1609.34

    def convert_error_from_standard(self, error):
        return error * 0.000621371


class Angstrom(LengthUnit):
    """
    Class for Angstroms.
    """

    def convert_value_to_standard(self, value):
        return value * 10**(-10)

    def convert_value_from_standard(self, value):
        return value / 10**(-10)

    def convert_error_to_standard(self, error):
        return error * 10**(-10)

    def convert_error_from_standard(self, error):
        return error / 10**(-10)


units_dict = {R('m(eter(s)?)?', group=0): Meter, R('cm(eter(s)?)?', group=0): CentiMeter,R('mm(eter(s)?)?', group=0): MilliMeter, R('mile[s]?', group=0): Mile, R('Å', group=0): Angstrom}
Length.units_dict = units_dict

# -*- coding: utf-8 -*-
"""
Units and models for lengths.

:codeauthor: <NAME> (<EMAIL>)
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .quantity_model import QuantityModel
from .unit import Unit
from .dimension import Dimension
from ...parse.elements import W, I, R, Optional, Any, OneOrMore, Not, ZeroOrMore
from ...parse.actions import merge, join
import logging

log = logging.getLogger(__name__)


class Length(Dimension):
    """
    Dimension subclass for lengths.
    """
    pass


class LengthModel(QuantityModel):
    """
    Model for lengths.
    """
    dimensions = Length()


class LengthUnit(Unit):
    """
    Base class for units with dimensions of length.
    The standard value for length is defined to be a meter, implemented in the Meter class.
    """

    def __init__(self, magnitude=0.0, powers=None):
        super(LengthUnit, self).__init__(Length(), magnitude, powers)


class Meter(LengthUnit):
    """
    Class for meters.
    """

    def convert_value_to_standard(self, value):
        return value

    def convert_value_from_standard(self, value):
        return value

    def convert_error_to_standard(self, error):
        return error

    def convert_error_from_standard(self, error):
        return error


class CentiMeter(LengthUnit):
    """
    Class for meters.
    """

    def convert_value_to_standard(self, value):
        return value * 100

    def convert_value_from_standard(self, value):
        return value * 100

    def convert_error_to_standard(self, error):
        return error * 100

    def convert_error_from_standard(self, error):
        return error * 100


class MilliMeter(LengthUnit):
    """
    Class for meters.
    """

    def convert_value_to_standard(self, value):
        return value * 1000

    def convert_value_from_standard(self, value):
        return value * 1000

    def convert_error_to_standard(self, error):
        return error * 1000

    def convert_error_from_standard(self, error):
        return error * 1000


class Mile(LengthUnit):
    """
    Class for miles.
    """

    def convert_value_to_standard(self, value):
        return value * 1609.34

    def convert_value_from_standard(self, value):
        return value * 0.000621371

    def convert_error_to_standard(self, error):
        return error * 1609.34

    def convert_error_from_standard(self, error):
        return error * 0.000621371


class Angstrom(LengthUnit):
    """
    Class for Angstroms.
    """

    def convert_value_to_standard(self, value):
        return value * 10**(-10)

    def convert_value_from_standard(self, value):
        return value / 10**(-10)

    def convert_error_to_standard(self, error):
        return error * 10**(-10)

    def convert_error_from_standard(self, error):
        return error / 10**(-10)


units_dict = {R('m(eter(s)?)?', group=0): Meter, R('cm(eter(s)?)?', group=0): CentiMeter,R('mm(eter(s)?)?', group=0): MilliMeter, R('mile[s]?', group=0): Mile, R('Å', group=0): Angstrom}
Length.units_dict = units_dict
# -*- coding: utf-8 -*- Units and models for lengths.  :codeauthor: <NAME> (<EMAIL>) Dimension subclass for lengths. Model for lengths. Base class for units with dimensions of length.     The standard value for length is defined to be a meter, implemented in the Meter class. Class for meters. Class for meters. Class for meters. Class for miles. Class for Angstroms.