This file contains hidden or 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
| using (var conn = new SqlConnection(@"Data Source=(LocalDb)\v11.0;Initial Catalog=Master;Integrated Security=True")) | |
| { | |
| conn.Open(); | |
| var cmd = new SqlCommand(); | |
| cmd.Connection = conn; | |
| cmd.CommandText = string.Format(@" | |
| IF EXISTS(SELECT * FROM sys.databases WHERE name='{0}') | |
| BEGIN | |
| ALTER DATABASE [{0}] |
This file contains hidden or 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
| [<Test>] | |
| member this.``Given a hot aggregate, a hot aggregate will be detected``() = | |
| let treshold = 4 | |
| let secondsInWindow = 5 | |
| let eventStream = createEventStream [0; 1; 2; 10; 11; 12; 13; 14; 60; 90] | |
| streamIsHot eventStream treshold secondsInWindow |> should equal true |
This file contains hidden or 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
| let streamIsHot (events : seq<Event>) treshold secondsInWindow = | |
| let folder acc e = | |
| let detect acc e = | |
| let windowFilter = (fun x -> x >= e.Timestamp.AddSeconds(- float secondsInWindow)) | |
| let window = e.Timestamp :: acc.Window |> List.filter windowFilter | |
| let hot = (window |> Seq.length) > treshold | |
| { acc with Hot = hot; Window = window } | |
| match acc.Hot with | |
| | true -> acc |
This file contains hidden or 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
| type PocketLabel = Miss | Win | |
| type Pocket = { Label : PocketLabel } | |
| type PhysicalWheel = Pocket seq |
This file contains hidden or 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
| let (physicalWheel : PhysicalWheel) = | |
| [ | |
| { Label = Miss }; | |
| { Label = Miss }; | |
| { Label = Win }; | |
| { Label = Miss } | |
| ] |> Seq.ofList |
This file contains hidden or 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
| let rng = new Random() | |
| let randomIndex (rng : Random) physicalWheel = | |
| rng.Next(0, physicalWheel |> Seq.length) | |
| let spin physicalWheel rng = | |
| physicalWheel |> Seq.nth (randomIndex rng physicalWheel) |
This file contains hidden or 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
| let spin physicalWheel rng times = | |
| [1 .. times] |> List.map (fun x -> spin physicalWheel rng) |
This file contains hidden or 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
| let results = spin physicalWheel rng 1000000 |
This file contains hidden or 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
| let groupedResults = | |
| results | |
| |> Seq.groupBy (fun x -> x.Label) | |
| |> Seq.map (fun (x, y) -> (x, (y |> Seq.length))) | |
| printfn "%A" groupedResults |
This file contains hidden or 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
| seq [(Miss, 750505); (Win, 249495)] |