Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------
- // Just matching sample
- let select (es: Event list) =
- match es with
- | [x] -> x
- | {data = Request _}::_ -> List.last es
- | {data = Active (Active.Failure _)}::_ -> List.last es
- | _ -> List.last es
- //---------------------------------------------------------------
- // Heavy composition usage
- let run hour limit initial =
- let faults =
- Assets.State.Get.assets
- >> Assets.Get.platforms
- >> List.collect (fault 0)
- >> Assets.State.Add.events
- |> repeat
- let finalize =
- Assets.State.Get.assets
- >> Assets.Get.platforms
- >> List.collect (track "Finalize" limit)
- >> Assets.State.Add.events
- |> repeat
- >> hour >> applyf limit
- >> Assets.State.Get.assets
- >> Assets.State.To.platforms (degrade limit)
- [initial.assets.time..limit]
- |> List.fold hour (faults initial)
- |> finalize
- |> ignore
- //---------------------------------------------------------------
- // My big composition root where I configure the whole simulation
- let route ready threshold spares lifetimes rates limits durations =
- function
- | {data = Period z} as x ->
- match z with
- | Period.Check o -> Period.check o durations
- | Period.Replace -> Period.replace durations
- | Period.Stock -> Period.stock spares
- | Period.Mission -> Period.mission ready durations
- >> Outcome.map id (Period.initial x.time z)
- | {data = Request z} as y ->
- match z with
- | Request.Check x -> Request.check x y.time
- | Request.Refresh x -> Request.repair Low durations y.time x
- | Request.Repair x -> Request.repair High durations y.time x
- | Request.Recovery x -> Request.replace Fail x y.time
- | Request.Replace x -> Request.replace Low x y.time
- | Request.Mission xs -> Request.mission xs y.time
- | {data = Done _} -> pairf [] >> Enabled
- | {data = Active z} as y ->
- match z with
- | Active.Check x -> Active.check durations x y.time
- | Active.Refresh x -> Active.repair Low limits lifetimes rates x y.time
- | Active.Repair x -> Active.repair High limits lifetimes rates x y.time
- | Active.Recovery x -> Active.replace Fail limits lifetimes x y.time
- | Active.Replace x -> Active.replace Low limits lifetimes x y.time
- | Active.Mission x -> Active.mission threshold x y.time
- | Active.Failure x -> Active.failure durations x.platform x.block y.time
- //---------------------------------------------------------------
- // Detection of wear level
- module Detect =
- let level life = function
- | Fixable (l,h,f) ->
- [0;l;h;f]
- |> List.map ((-) f)
- |> List.rev
- |> List.findIndex ((<=) life)
- |> function
- | 0 -> Fail
- | 1 -> High
- | 2 -> Low
- | 3 -> Norm
- | _ -> crash "Wrong index"
- | Unfixable f ->
- [0;f]
- |> List.findIndex ((<=) life)
- |> function
- | 0 -> Fail
- | 1 -> Norm
- | _ -> crash "Wrong index"
- //---------------------------------------------------------------
- // Func that performs a repair of broken platforms
- let perform p (b:Block) =
- if b.level = Fail then crash "Failed Block in Repair: %A" b
- if b.status = Stopped then crash "Stopped Block in Repair: %A" b
- let active =
- let ends = duration + assets.time
- blockd p team b
- |> match team with
- | Low -> Active.Refresh
- | High -> Active.Repair
- | x -> crash "Not Low or High team in Request.repair but %A" x
- |> Create.active ends (Token.Time ends)
- let assets =
- assets
- |> Assets.Remove.team team
- |> Assets.Update.platform p.id
- (degrade assets.time
- >> Platform.Set.uptime assets.time
- >> Platform.Update.block b.id Block.stop
- >> Platform.Update.status)
- pair assets (active::track "Repair" assets.time p) |> Enabled
- //---------------------------------------------------------------
- // Funcs from Costs module
- let confidence (samples: float list) interval =
- let lenght = float samples.Length
- let freedom = max (lenght - 1.0) 1.0
- let theta = (interval + 1.0) / 2.0
- let mean = Statistics.Mean samples
- let stdev = Statistics.StandardDeviation samples
- let student = StudentT.InvCDF (0.0, 1.0, freedom, theta)
- let t = student * (stdev / sqrt lenght)
- (mean - t, mean + t)
- let indicators (data:float list) =
- let (lower,upper) = confidence data 0.95
- [List.sum data
- Statistics.Mean data
- Statistics.Median data
- Statistics.StandardDeviation data
- upper
- lower
- Statistics.Maximum data
- Statistics.UpperQuartile data
- Statistics.LowerQuartile data
- Statistics.Minimum data]
- let calculate data =
- data
- |> List.ofSeq
- |> List.group Get.block
- |> List.append ["!Total", List.ofSeq data]
- |> List.maps block
- |> List.sortf
- |> List.rev
- |> List.snd
Add Comment
Please, Sign In to add comment