Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Last active October 26, 2021 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/4c21eb5b4244e9b27fa41694105689ed to your computer and use it in GitHub Desktop.
Save tonymorris/4c21eb5b4244e9b27fa41694105689ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env runhaskell
module Main where
import Text.Printf(printf)
import Data.List(intercalate)
import Data.Bool (bool)
kg2lb =
(*2.2)
lb2kg =
(/2.2)
usg2lb =
(*6)
lbin2iu =
(/1000)
----
vhtin_bew_lb ::
Double
vhtin_bew_lb =
1803 -- pounds
vhtin_bew_kg =
lb2kg vhtin_bew_lb
vhtin_arm_in ::
Double
vhtin_arm_in =
36.97 -- inches
vhtin_mom_lbin ::
Double
vhtin_mom_lbin =
vhtin_bew_lb * vhtin_arm_in
vhtin_mom_iu =
lbin2iu vhtin_mom_lbin
row1_arm_in = 37
row2_arm_in = 74
baga_arm_in = 97
bagb_arm_in = 115
hatshelf_arm_in = 130
fuel_arm_in = 48
mtow_limit_lb = 2950
baga_limit_lb = 120
hatshelf_limit_lb = 25
bagb_hatshelf_limit_lb = 80
----
mtow_limit_kg = lb2kg mtow_limit_lb
baga_limit_kg = lb2kg baga_limit_lb
hatshelf_limit_kg = lb2kg hatshelf_limit_lb
bagb_hatshelf_limit_kg = lb2kg bagb_hatshelf_limit_lb
pax1_kg = 82 -- kg
pax2_kg = 80 -- kg
pax3_kg = 120 -- kg
pax4_kg = 0 -- kg
baga_kg = 25 -- kg
bagb_kg = 9.8 -- kg
hatshelf_kg = 0 -- kg
fuel_usable_usg = 75
pax1_lb = kg2lb pax1_kg
pax2_lb = kg2lb pax2_kg
pax3_lb = kg2lb pax3_kg
pax4_lb = kg2lb pax4_kg
baga_lb = kg2lb baga_kg
bagb_lb = kg2lb bagb_kg
hatshelf_lb = kg2lb hatshelf_kg
fuel_usable_lb = usg2lb fuel_usable_usg
row1_lb =
pax1_lb + pax2_lb
row2_lb =
pax3_lb + pax4_lb
row1_kg =
lb2kg row1_lb
row2_kg =
lb2kg row2_lb
vhtin_zfw_lb =
vhtin_bew_lb + row1_lb + row2_lb + baga_lb + bagb_lb
vhtin_zfw_kg =
lb2kg vhtin_zfw_lb
row1_mom_lbin =
row1_lb * row1_arm_in
row1_mom_iu =
lbin2iu row1_mom_lbin
row2_mom_lbin =
row2_lb * row2_arm_in
row2_mom_iu =
lbin2iu row2_mom_lbin
baga_mom_lbin =
baga_lb * baga_arm_in
baga_mom_iu =
lbin2iu baga_mom_lbin
bagb_mom_lbin =
bagb_lb * bagb_arm_in
bagb_mom_iu =
lbin2iu bagb_mom_lbin
hatshelf_mom_lbin =
hatshelf_lb * hatshelf_arm_in
hatshelf_mom_iu =
lbin2iu hatshelf_mom_lbin
fuel_usable_kg =
lb2kg fuel_usable_lb
fuel_usable_mom_lbin =
fuel_usable_lb * fuel_arm_in
fuel_usable_mom_iu =
lbin2iu fuel_usable_mom_lbin
vhtin_zfw_lbin =
sum [
vhtin_mom_lbin
, row1_mom_lbin
, row2_mom_lbin
, baga_mom_lbin
, bagb_mom_lbin
, hatshelf_mom_lbin
]
vhtin_zfw_iu =
lbin2iu vhtin_zfw_lbin
vhtin_zfw_in =
vhtin_zfw_lbin / vhtin_zfw_lb
vhtin_auw_lb =
vhtin_zfw_lb + fuel_usable_lb
vhtin_auw_kg =
lb2kg vhtin_auw_lb
vhtin_auw_lbin =
sum [
vhtin_zfw_lbin
, fuel_usable_mom_lbin
]
vhtin_auw_iu =
lbin2iu vhtin_auw_lbin
vhtin_auw_in =
vhtin_auw_lbin / vhtin_auw_lb
mtow_margin_lb =
mtow_limit_lb - vhtin_auw_lb
mtow_margin_kg =
mtow_limit_kg - vhtin_auw_kg
baga_margin_lb =
baga_limit_lb - baga_lb
baga_margin_kg =
baga_limit_kg - baga_kg
hatshelf_margin_lb =
hatshelf_limit_lb - hatshelf_lb
hatshelf_margin_kg =
hatshelf_limit_kg - hatshelf_kg
bagb_hatshelf_margin_lb =
bagb_hatshelf_limit_lb - (bagb_lb + hatshelf_lb)
bagb_hatshelf_margin_kg =
bagb_hatshelf_limit_kg - (bagb_kg + hatshelf_kg)
----
main ::
IO ()
main =
let printRowAny sep cs =
let pad c z n = (\x -> replicate (n - length x) c ++ x) (take n z)
padsp = pad ' '
in sep : intercalate [sep] (fmap (uncurry padsp) cs) <> [sep]
printWBRow sep c1 c2 c3 c4 c5 c6 c7 =
printRowAny sep (fmap (\(x, y) -> (x <> " ", y)) [(c1, 13), (c2, 9),
(c3, 9), (c4, 10), (c5, 11), (c6, 8), (c7, 7)])
printWBHeader c =
printWBRow '+' (repeat c) (repeat c) (repeat c)
(repeat c) (repeat c) (repeat c) (repeat c)
printWBRow' ::
String
-> Double
-> Double
-> Double
-> Double
-> Double
-> Maybe Double
-> String
printWBRow' n a b c d e z =
let z' =
case z of
Nothing ->
""
Just z' ->
printf "%.2f" z'
in printWBRow '|' n (printf "%.1f" a) (printf "%.1f" b) (printf "%.2f" c)
(printf "%.1f" d) (printf "%.3f" e) z'
printWBRow'0 n a b c d e =
printWBRow' n a b c d e Nothing
printWBRow'1 n a b c d e z =
printWBRow' n a b c d e (Just z)
wb =
[
printWBHeader '-'
, printWBRow '|' "" "Wt (lb)" "Wt (kg)" "Arm (in)" "Mom lb/in" "Mom IU" "USG"
, printWBHeader '-'
, printWBRow'0 "BEW" vhtin_bew_lb vhtin_bew_kg vhtin_arm_in vhtin_mom_lbin
vhtin_mom_iu
, printWBRow'0 "Row 1" row1_lb row1_kg row1_arm_in row1_mom_lbin row1_mom_iu
, printWBRow'0 "Row 2" row2_lb row2_kg row2_arm_in row2_mom_lbin row2_mom_iu
, printWBRow'0 "Bag A" baga_lb baga_kg baga_arm_in baga_mom_lbin baga_mom_iu
, printWBRow'0 "Bag B" bagb_lb bagb_kg bagb_arm_in bagb_mom_lbin bagb_mom_iu
, printWBRow'0 "Hatshelf" hatshelf_lb hatshelf_kg hatshelf_arm_in
hatshelf_mom_lbin hatshelf_mom_iu
, printWBHeader '='
, printWBRow'0 "ZFW" vhtin_zfw_lb vhtin_zfw_kg vhtin_zfw_in vhtin_zfw_lbin
vhtin_zfw_iu
, printWBHeader '-'
, printWBRow'1 "Fuel Usable" fuel_usable_lb fuel_usable_kg fuel_arm_in
fuel_usable_mom_lbin fuel_usable_mom_iu fuel_usable_usg
, printWBHeader '='
, printWBRow'0 "AUW" vhtin_auw_lb vhtin_auw_kg vhtin_auw_in vhtin_auw_lbin
vhtin_auw_iu
, printWBHeader '-'
]
printLimitHeader c =
printLimitRow '+' (repeat c) (repeat c) (repeat c) (repeat c) (repeat c)
(repeat c)
printLimitRow sep c1 c2 c3 c4 c5 c6 =
printRowAny sep (fmap (\(x, y) -> (x <> " ", y)) [(c1, 13), (c2, 11),
(c3, 11), (c4, 13), (c5, 13), (c6, 7)])
printLimitRow' ::
String
-> Double
-> Double
-> Double
-> Double
-> String
printLimitRow' n c1 c2 c3 c4 =
printLimitRow '|' n (printf "%.1f" c1) (printf "%.1f" c2) (printf "%.1f" c3)
(printf "%.1f" c4) (if c3 < 0 then "FAIL" else "PASS")
limits =
[
printLimitHeader '-'
, printLimitRow '|' "LIMIT" "Max (lb)" "Max (kg)" "Margin (lb)"
"Margin (kg)" "Check"
, printLimitHeader '-'
, printLimitRow' "MTOW" mtow_limit_lb mtow_limit_kg mtow_margin_lb
mtow_margin_kg
, printLimitRow' "BagA" baga_limit_lb baga_limit_kg baga_margin_lb
baga_margin_kg
, printLimitRow' "Hat." hatshelf_limit_lb hatshelf_limit_kg
hatshelf_margin_lb hatshelf_margin_kg
, printLimitRow' "BagB & Hat." bagb_hatshelf_limit_lb bagb_hatshelf_limit_kg
bagb_hatshelf_margin_lb bagb_hatshelf_margin_kg
, printLimitHeader '-'
]
newlines =
putStrLn . intercalate "\n"
nl =
putStrLn ""
title =
let c =
'*'
hdr =
printRowAny c [(repeat c, 31)]
in [
hdr
, printRowAny c [("VH-TIN, Tony, Tommy, Ben ", 31)]
, hdr
]
in do newlines title
nl
newlines wb
nl
nl
newlines limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment