#!/usr/bin/env python

# Simple calculator for speed at 1000 rpm and revlimit
# Examples:
# Audi A6 3.0:   utvxl.py 235 45 17 6800 4.375 3.5 1.889 1.320 1.034 0.857 0.730
# Audi A6 2.7t:  utvxl.py 235 45 17 6500 4.111 3.5 1.889 1.231 0.987 0.806 0.684
# Saab 9-5 Aero: utvxl.py 225 45 17 6200 4.05 3.388 1.758 1.178 0.894 0.659


import math
import sys


# Calculates speed in km/h
def calculateSpeed(rpm, tireOmkrets, totalGearRatio):
	return (rpm * 60 * tireOmkrets / totalGearRatio) / 1000


if 7 > len(sys.argv):
	sys.exit("Usage: " + sys.argv[0] + " tireWidth(mm) tireProfile(%) wheelDiameter(inch) revLimit(rpm) finalDriveRatio gearRatio1 gearRatio2 [..]")

# All measurements in meters
inch = 25.4 / 1000
tireWidth = float(sys.argv[1]) / 1000
tireProfile = float(sys.argv[2]) / 100
tireHeight = tireProfile * tireWidth
wheelDiameter = float(sys.argv[3]) * inch
tireDiameter = tireHeight * 2 + wheelDiameter
tireOmkrets = tireDiameter * math.pi

revLimit = float(sys.argv[4])
finalDriveRatio = float(sys.argv[5])
gearRatios = (float(gearRatioStr) for gearRatioStr in sys.argv[6::])

print "gear\tratio\ttotRa\tspd@1k\tspd@lim"

gear = 1
for gearRatio in gearRatios:
	totalGearRatio = finalDriveRatio * gearRatio
	print ("%d\t%6.3f\t%6.3f\t%6.3f\t%7.3f" %
		(gear, gearRatio, totalGearRatio, calculateSpeed(1000, tireOmkrets, totalGearRatio), calculateSpeed(revLimit, tireOmkrets, totalGearRatio)))
	gear += 1

