https://github.com/index333/gear
ギヤ比は一般には単に前後の比率で表します。
例えばフロント30T x リヤ20Tの場合
30➗20で1.50
欧米では伝統的にダルマ型自転車の前輪径に換算します。
30x20の場合
27x1.5=41インチギヤ
のように表現します。
欧米式の利点は小径車にも統一的に使えることです。
上の場合
20x1.5=30インチギヤとなります。
逆にロードレーサーの41インチギヤと同じ速度を小径車で得るには
30x15あるいは39x20という前後の組み合わせが必要となります。
ケーデンスを固定した時の時速で表したほうが直感的と思います。
まずタイヤ周長を選択します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.UI.Gtk | |
main = do | |
c <- getContents | |
let texts = lines c | |
initGUI | |
w <- windowNew | |
w `set` [windowDefaultWidth := 1000, windowDefaultHeight := 800] | |
sw <- scrolledWindowNew Nothing Nothing | |
vb <- vBoxNew True 0 | |
bs <- mapM (buttonNewWithLabel) texts | |
mapM_ (\b -> b `set` [buttonXalign := 0, buttonYalign := 0]) bs | |
mapM_ (\b -> (b `on` buttonActivated) (func b)) bs | |
mapM_ (containerAdd vb) bs | |
scrolledWindowAddWithViewport sw vb | |
containerAdd w sw | |
widgetShowAll w | |
(w `on`unrealize) mainQuit | |
mainGUI | |
func b = b `get` buttonLabel >>= putStrLn >> mainQuit |
$ cat tires
18-622 700x18C 2070 207
19-622 700x19C 2080 208
20-622 700x20C 2086 209
23-622 700x23C 2096 210
25-622 700x25C 2105 211
28-622 700x28C 2136 214
30-622 700x30C 2146 215
32-622 700x32C 2155 216
xx-xxx Tubular 2130 213
35-622 700x35C 2168 217
38-622 700x38C 2180 218
40-622 700x40C 2200 220
42-622 700x42C 2224 222
44-622 700x44C 2235 224
45-622 700x45C 2242 224
47-622 700x47C 2268 227
$ cat tires | runghc selectItem.hs > tmp
$ cat tmp
23-622 700x23C 2096 210
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.UI.Gtk | |
import MySpinBox | |
import Round | |
main = do | |
c <- getContents | |
let [_,_,a,_] = words c | |
let t = read a :: Double | |
let names = ["タイヤ周長(mm)", | |
"frontA(T)", | |
"frontB(T)", | |
"最大コグ(T)", | |
"cadens(/m)"] | |
let spmods = [(t,2000,2300,1,10), | |
(39,20,60,1,10), | |
(52,20,60,1,10), | |
(23,21,32,1,10), | |
(90,50,160,1,10)] | |
initGUI | |
window <- windowNew | |
hbox <- hBoxNew False 0 | |
vbox <- vBoxNew False 0 | |
boxPackStart vbox hbox PackNatural 0 | |
adjs <- mkAdjustments spmods | |
update adjs | |
spins <- myAddSpinButtons hbox names adjs | |
mapM_ (`set` [spinButtonDigits := 0]) spins | |
mapM_ (flip onValueChanged (update adjs)) adjs | |
containerAdd window vbox | |
widgetShowAll window | |
window `on` unrealize $ mainQuit | |
mainGUI | |
update adjs = do | |
l:fa:fb:m:c:_ <- mapM (`get` adjustmentValue) adjs | |
putStr "タイヤ周長(mm) = " | |
print l | |
mapM_ (disp l fa fb c) [11..m] | |
disp l fa fb c x = do | |
disp' l fa x c | |
putStr " " | |
disp' l fb x c | |
putStrLn "" | |
disp' l f r c = do | |
putStr $ show $ round f | |
putStr "x" | |
putStr $ show $ round r | |
putStr "=" | |
putStr $ show (kph l f r c) | |
putStr "km/h " | |
kph l f r c = round1 $ (l/1000^2) * (f / r) * (c * 60) |
Round モジュール、MySpinBox モジュールが必要です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Round where | |
roundN :: Int -> Double -> Double | |
roundN n d = fromIntegral (round (d * 10 ^ n)) / fromIntegral (10 ^ n) | |
round1,round2 :: Double -> Double | |
round1 = roundN 1 | |
round2 = roundN 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MySpinBox where | |
import Graphics.UI.Gtk | |
import Control.Monad | |
mkAdjustment :: (Double, Double, Double, Double, Double) -> IO Adjustment | |
mkAdjustment (v,l,u,s,p) = adjustmentNew v l u s p 0 | |
{- | |
:: Double value - the initial value. | |
-> Double lower - the minimum value. | |
-> Double upper - the maximum value. | |
-> Double stepIncrement - the step increment. | |
-> Double pageIncrement - the page increment. | |
-> Double pageSize - the page size. | |
-} | |
mkAdjustments :: [(Double, Double, Double, Double, Double)] -> | |
IO [Adjustment] | |
mkAdjustments = mapM mkAdjustment | |
myAddSpinButtons :: HBox -> [String] ->[Adjustment] -> IO [SpinButton] | |
myAddSpinButtons box names adjustments = do | |
zipWithM (\x y -> myAddSpinButton box x y) names adjustments | |
myAddSpinButton :: HBox -> String -> Adjustment -> IO SpinButton | |
myAddSpinButton box name adj = do | |
vbox <- vBoxNew False 0 | |
boxPackStart box vbox PackRepel 0 | |
label <- labelNew (Just name) | |
miscSetAlignment label 0.0 0.5 | |
boxPackStart vbox label PackNatural 0 | |
spinb <- spinButtonNew adj 10 1 | |
boxPackStart vbox spinb PackGrow 0 | |
return spinb |