Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r "FSharp.Data.2.3.0/lib/net40/FSharp.Data.dll"
- open System
- open System.IO
- open System.Threading
- open FSharp.Data
- open System.Net
- open System.IO
- type Test = JsonProvider<"sample.json">
- let olivier = Test.GetSamples()
- let parcours (t:JsonProvider<"sample.json">.L []) =
- [for event in t do
- let mutable b = 0.0M
- let mutable c = 0.0M
- let mutable counter = true
- let mutable d = 0
- for ev in event.L do
- match ev.S with
- |Some s -> if counter then
- b <- s
- counter <- not(counter)
- else
- c <- s
- |None -> ()
- match ev.N with
- |Some n -> d <- n
- |None -> ()
- yield (b,c,d)]
- let realparcours (tableau:JsonProvider<"sample.json">.Root []) =
- [for elem in tableau do
- yield parcours elem.Result.M.Xxbtzeur.M.Bids.L
- yield parcours elem.Result.M.Xxbtzeur.M.Asks.L
- ]
- let printer truc =
- let (a,b,c) = truc
- a.ToString() + " | " + b.ToString() + " | " + c.ToString()
- let afficher aList =
- let rec affichage liste s =
- match liste with
- |[] -> s
- |[hd] -> s + (printer hd)
- |hd1::hd2::tl -> affichage tl (s + (printer hd1) + " || " + (printer hd2) + Environment.NewLine)
- in affichage aList ""
- let beautify (aList:('a * 'b * 'c) list List) =
- let size = aList.Length
- let mutable s = Array.create size ""
- let rec beau (liste:('a * 'b * 'c) list List) counter =
- match liste with
- |[] -> s
- |hd::tl -> s.[counter] <- (afficher hd)
- beau tl (counter + 1)
- in beau aList 0
- let json = olivier |> realparcours |> beautify
- printfn "%s" json.[0]
- File.WriteAllLines("test.txt",json)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement