def calculateAcceleration( measurement1, measurement2 ): validUnitTypes = [ [ 'velocity', 'distance' ], [ 'distance', 'time' ], ] acceleration = RPNMeasurement( '1.0', 'meter/second^2' ) return acceleration.convert( 'meter/second^2' )
def calculateVelocity( measurement1, measurement2 ): validUnitTypes = [ [ 'length', 'time' ], [ 'velocity', 'time' ], [ 'acceleration', 'time' ], [ 'acceleration', 'distance' ], [ 'jerk', 'time' ], [ 'jerk', 'distance' ], [ 'jounce', 'time' ], [ 'jounce', 'distance' ] ] velocity = RPNMeasurement( '1.0', 'meter/second' ) return velocity.convert( 'meter/second' )
def calculateAcceleration( measurement1, measurement2 ): validUnitTypes = [ [ 'velocity', 'distance' ], [ 'velocity', 'time' ], [ 'distance', 'time' ], [ 'acceleration', 'time' ], [ 'acceleration', 'distance' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if 'acceleration' in arguments: acceleration = arguments[ 'acceleration' ] else: acceleration = RPNMeasurement( '1.0', 'meter/second^2' ) return acceleration.convert( 'meter/second^2' )
def subtract( self, time ): if isinstance( time, RPNMeasurement ): kneg = RPNMeasurement( fneg( time.getValue( ) ), time.getUnits( ) ) return self.add( kneg ) elif isinstance( time, RPNDateTime ): if self > time: delta = self - time factor = 1 else: delta = time - self factor = -1 if delta.days != 0: result = RPNMeasurement( delta.days * factor, 'day' ) result = result.add( RPNMeasurement( delta.seconds * factor, 'second' ) ) result = result.add( RPNMeasurement( delta.microseconds * factor, 'microsecond' ) ) elif delta.seconds != 0: result = RPNMeasurement( delta.seconds * factor, 'second' ) result = result.add( RPNMeasurement( delta.microseconds * factor, 'microsecond' ) ) else: result = RPNMeasurement( delta.microseconds * factor, 'microsecond' ) return result else: raise ValueError( 'incompatible type for subtracting from an absolute time' )
def getProduct( n ): if isinstance( n, RPNGenerator ): return getProduct( list( n ) ) elif isinstance( n[ 0 ], ( list, RPNGenerator ) ): return [ getProduct( arg ) for arg in n ] if not n: return 0 elif len( n ) == 1: return n[ 0 ] hasUnits = False for item in n: if isinstance( item, RPNMeasurement ): hasUnits = True break if hasUnits: result = RPNMeasurement( 1, { } ) for item in n: if isinstance( item, list ): return [ getProduct( arg ) for arg in item ] result = result.multiply( item ) return result else: if not n: return 0 if isinstance( n[ 0 ], list ): return [ getProduct( item ) for item in n ] else: return fprod( n )
def getPower( n, k ): if isinstance( n, RPNMeasurement ): result = RPNMeasurement( n ) return result.exponentiate( k ) else: return power( n, k )