Created
February 5, 2014 18:13
-
-
Save vasily-kirichenko/8829821 to your computer and use it in GitHub Desktop.
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
open System | |
type Cylinder = | |
| FourFourEight | |
| SixSixTwelve | |
| ThreeThreeSix | |
| TwoTwoTwo | |
type CylinderMeasurement = | |
{ WidthA: float | |
WidthB: float | |
Height: float | |
Id: int | |
LoadPounds: int | |
Psi: double | |
Cylinder: Cylinder } | |
module calcPsi = | |
// Update the PSI, and return the original cylinder information. | |
let calculatePsi cyl = | |
let wa, wb, h = cyl.WidthA, cyl.WidthB, cyl.Height | |
let basearea = | |
match cyl.Cylinder with | |
| FourFourEight -> Math.PI * ((wa + wb) / 2.) / 2. * ((wa + wb) / 2. / 2.) | |
| SixSixTwelve -> Math.PI * ((wa + wb) / 2.) / 2. * ((wa + wb) / 2. / 2.) | |
| ThreeThreeSix -> wa * wb | |
| TwoTwoTwo -> ((wa + wb) / 2.) * ((wa + wb) / 2.) | |
let ratio = | |
if (h > 0. && (wa + wb > 0.)) | |
then Some(Math.Round(h / ((wa + wb) / 2.), 2)) | |
else None | |
let tFactor = | |
match ratio with | |
| Some r when r > 1.94 || r < 1. -> 1. | |
| _ -> 0.979 | |
{ cyl with Psi = Math.Round((float) cyl.LoadPounds / basearea / 1000. * tFactor, 2) * 1000. } | |
let getPsi = Array.Parallel.map calculatePsi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment