Example #1
0
def strava_pick(ctx, limit, before, after):
    """Getting GPX file by picked activity and upload to Strava"""
    new_time = ctx.obj['new_time']
    client = ctx.obj['client']

    define_units()
    kilometers = unit('km')

    activities = []
    Activity = collections.namedtuple('Activity', [
        'id', 'start_date_local', 'name', 'moving_time', 'distance',
        'total_elevation_gain'
    ])

    with Halo(text='Fetch activities from Strava', spinner='dots'):
        fetched_activities = client.get_activities(before, after, limit)

    for activity in fetched_activities:
        activities.append(
            Activity(id=activity.id,
                     start_date_local=activity.start_date_local,
                     name=activity.name,
                     moving_time=activity.moving_time,
                     distance=kilometers(activity.distance),
                     total_elevation_gain=activity.total_elevation_gain))

    title = 'Please choose your activity'
    option, index = pick(options=activities,
                         title=title,
                         options_map_func=get_label)

    update_activity(client, option.id, new_time)
Example #2
0
def test_pow():
    """Exponentiation of quantities."""
    REGISTRY.clear()
    define_units()
    
    m_unit = unit('m')
    m_quant = Quantity(2, m_unit)
    
    assert (m_quant ** 2 == m_quant * m_quant == pow(m_quant, 2))
    
    cm_unit = unit('cm')
    cm_quant = Quantity(2, cm_unit)
    
    assert within_epsilon(cm_quant ** 2, cm_quant * cm_quant)
    assert within_epsilon(cm_quant ** 2, pow(cm_quant, 2))
Example #3
0
def test_pow():
    """Exponentiation of quantities."""
    REGISTRY.clear()
    define_units()

    m_unit = unit('m')
    m_quant = Quantity(2, m_unit)

    assert (m_quant ** 2 ==
            m_quant * m_quant ==
            pow(m_quant, 2))

    cm_unit = unit('cm')
    cm_quant = Quantity(2, cm_unit)

    assert within_epsilon(cm_quant ** 2, cm_quant * cm_quant)
    assert within_epsilon(cm_quant ** 2, pow(cm_quant, 2))
Example #4
0
def setup_module(module):
    # Disable warning about not using module.
    # pylint: disable=W0613
    """Called by py.test before running any of the tests here."""
    define_units()
Example #5
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
from units import unit
from units.predefined import define_units

define_units()

whiteSpace = "   "
decorator = "-" * 35
invalidInput = "\n{} [-] Invalid input".format(whiteSpace)

# Defining some types of measurement with their units in lists
conversions = ['Length', 'Weight', 'Volume', 'Time', 'Computer']

length = [('Millimeters', 'mm'), ('Centimeters', 'cm'),
			('Decimeters', 'dm'), ('Meters', 'm'),
			('Kilometers', 'km'), ('Inches', 'inch'),
			('Feet', 'ft'), ('Yards', 'yd'),
			('Fathoms', 'fathom'), ('Rods', 'rd'),
			('Furlong', 'fur'), ('Leagues', 'league'),
			('Miles', 'mi'), ('Nautical Miles', 'NM'),
			('Cables', 'cable'), ('Lighth Years', 'ly'),
			('Astronomical Units', 'AU'), ('Parsec', 'pc')
			]

weight = [('Miligrams', 'mg'), ('Centigrams', 'cg'), 
			('Decigrams', 'dg'), ('Grams', 'g'), 
			('Kilograms', 'kg'), ('Ounces', 'oz'),
			('Pounds', 'lb'), ('Tons', 'ton'),
			('Metric Ton', 'tonne'), ('Grains', 'grain'), 
			('Drams', 'dr'), ('Hundredweight (Quintal)', 'cwt')
Example #6
0
def setup_module(module):
    # Disable warning about not using module.
    # pylint: disable=W0613
    """Called by py.test before running any of the tests here."""
    define_units()
Example #7
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scimap.  If not, see <http://www.gnu.org/licenses/>.

# flake8: noqa

import math
import datetime as dt
import unittest
import os

from units import unit, predefined
predefined.define_units()

from electrochem.electrode import CathodeLaminate, CoinCellElectrode
from electrochem.galvanostatrun import GalvanostatRun
from electrochem import electrochem_units
from electrochem import biologic
from tests.cases import ScimapTestCase

testdir = os.path.join(os.path.dirname(__file__), 'testdata')
mptfile = os.path.join(testdir, 'NEI-C10_4cycles_C14.mpt')
# eclab-test-data.mpt
mprfile = os.path.join(testdir, 'NEI-C10_4cycles_C14.mpr')

class ElectrochemUnitsTest(ScimapTestCase):
    """Check that various values for current, capacity, etc are compatible."""
    def setUp(self):
Example #8
0
File: gui.py Project: jyn514/units
#!/usr/bin/env python
import tkinter as tk
from units import predefined, REGISTRY  # requires pip package; TODO: bundle

predefined.define_units()


class App:
    def __init__(self, root):

        top_frame = tk.Frame(root)
        top_frame.pack()

        self.number = tk.DoubleVar()  # floating point
        self.number_button = tk.Entry(top_frame, textvariable=self.number)
        self.number_button.pack(side='left')

        self.from_units = tk.StringVar()
        self.from_units.set("m")

        self.from_units_button = tk.Entry(top_frame,
                                          textvariable=self.from_units)
        self.from_units_button.pack(side='right')

        self.convert_button = tk.Button(root,
                                        text="Convert",
                                        command=self.convert)
        self.convert_button.pack(side='bottom')

        middle_frame = tk.Frame(root)
        middle_frame.pack(side='bottom')