Exemplo n.º 1
0
    def act_speed(self, rpm=60, pref_unit=kmh):
        """ Return a speed unit that represents the travelling speed when
            turned at the given rpm.

            Keyword Arguments:
            rpm -- The rpm the wheel is turning (default 60)
            pref_unit -- The desired speed unit to be returned
        """
        self.circ = self._rolling_distance()
        calc = std()
        calc.speed = Unit(pref_unit)
        calc.distance = self.circ
        calc.distance.value *= rpm
        calc.time = (Unit(minute, 1))
        calc.calc()
        self.speed = calc.speed
        return self.speed
Exemplo n.º 2
0
 def __init__(self, time_string=None):
     super(FormattedTime, self).__init__()
     self.__vals = []
     self._formattedTime = time_string
     for v in self.definitions:
         self.__vals.append(Unit(v, 0))
     if time_string != None:
         self.set_time(time_string)
Exemplo n.º 3
0
    def speed(self, front_ring, rear_ring, cadence=60, pref_unit=kmh):
        """ Returns a speed_unit representing the achievable speed with
            the given arguments.

            Keyword arguments:
            front_ring -- A gear_ring or chain_ring object
            rear_ring -- A gear_ring or chain_ring object
            cadence -- Optional cadence argument (default 60)
            pref_unit -- the preferred rseulting speed unit.  Must be a
                         speed_unit object as defined in speed_units
                         (default kmh)
        """
        front_ring = self._ring_teeth(front_ring)
        rear_ring = self._ring_teeth(rear_ring)
        rpm = (float(front_ring) / rear_ring) * cadence
        speed = self.wheel.act_speed(rpm)
        speed = Unit(pref_unit, speed.convert_to(pref_unit))
        return speed
Exemplo n.º 4
0
    def speed(self, front_ring, rear_ring, cadence=60, pref_unit=kmh):
        """ Returns a speed_unit representing the achievable speed with
            the given arguments.

            Keyword arguments:
            front_ring -- A gear_ring or chain_ring object
            rear_ring -- A gear_ring or chain_ring object
            cadence -- Optional cadence argument (default 60)
            pref_unit -- the preferred rseulting speed unit.  Must be a
                         speed_unit object as defined in speed_units
                         (default kmh)
        """
        front_ring = self._ring_teeth(front_ring)
        rear_ring = self._ring_teeth(rear_ring)
        rpm = (float(front_ring) / rear_ring) * cadence
        speed = self.wheel.act_speed(rpm)
        speed = Unit(pref_unit, speed.convert_to(pref_unit))
        return speed
Exemplo n.º 5
0
    def calc(self):
        """ Calculate the unset value """

        # Calculate speed
        if self.speed.value == 0:
            if self.distance.value > 0 and self.time.value > 0:
                s = Unit(
                    speed_base,
                    self.distance.convert_to_base() /
                    self.time.convert_to_base())
                self.speed.value = s.convert_to(self.speed)
                return self.speed
            else:
                raise CalcError(self.speed.value, self.time.value,
                                self.distance.value)

        # Calculate distance
        if self.distance.value == 0:
            if self.speed.value > 0 and self.time.value > 0:
                d = Unit(
                    dist_base,
                    self.time.convert_to_base() / self.speed.convert_to_base())
                self.distance.value = d.convert_to(self.distance)
                return self.distance
            else:
                raise CalcError(self.speed.value, self.time.value,
                                self.distance.value)

        # Calculate time
        if self.time.value == 0:
            if self.speed.value > 0 and self.distance.value > 0:
                t = Unit(
                    time_base,
                    self.distance.convert_to_base() /
                    self.speed.convert_to_base())
                self.time.value = t.convert_to(self.time)
                return self.time
            else:
                raise CalcError(self.speed.value, self.time.value,
                                self.distance.value)
Exemplo n.º 6
0
class std(object):

    def __init__(self):
        self.speed = Unit(speed_base)
        self.distance = Unit(dist_base)
        self.time = Unit(time_base)

    def calc(self):
        """ Calculate the unset value """

        # Calculate speed
        if self.speed.value == 0:
            if self.distance.value > 0 and self.time.value > 0:
                s = Unit(speed_base,
                        self.distance.convert_to_base() /
                        self.time.convert_to_base())
                self.speed.value = s.convert_to(self.speed)
                return self.speed
            else:
                raise CalcError(self.speed.value, self.time.value,
                                self.distance.value)

        # Calculate distance
        if self.distance.value == 0:
            if self.speed.value > 0 and self.time.value > 0:
                d = Unit(dist_base,
                        self.time.convert_to_base() /
                        self.speed.convert_to_base())
                self.distance.value = d.convert_to(self.distance)
                return self.distance
            else:
                raise CalcError(self.speed.value, self.time.value,
                                self.distance.value)

        # Calculate time
        if self.time.value == 0:
            if self.speed.value > 0 and self.distance.value > 0:
                t = Unit(time_base,
                        self.distance.convert_to_base() /
                        self.speed.convert_to_base())
                self.time.value = t.convert_to(self.time)
                return self.time
            else:
                raise CalcError(self.speed.value, self.time.value,
                                self.distance.value)
Exemplo n.º 7
0
 def _rolling_distance(self):
     """ Return a float that represents the circumference of the wheel """
     return Unit(inch, self.rim_size.value * pi)
Exemplo n.º 8
0
 def __init__(self, rim_size=26):
     self.rim_size = Unit(inch, rim_size)
     self.circ = self._rolling_distance()
     self.speed = Unit(kmh)
Exemplo n.º 9
0
 def __init__(self):
     self.speed = Unit(speed_base)
     self.distance = Unit(dist_base)
     self.time = Unit(time_base)
Exemplo n.º 10
0
 def __init__(self):
     self.speed = Unit(speed_base)
     self.distance = Unit(dist_base)
     self.time = Unit(time_base)