Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.70 KB | None | 0 0
  1. #r "FSharp.Data.2.3.0/lib/net40/FSharp.Data.dll"
  2.  
  3. open System
  4. open System.IO
  5. open System.Threading
  6. open FSharp.Data
  7. open System.Net
  8. open System.IO
  9.  
  10. type Test = JsonProvider<"sample.json">
  11. let olivier = Test.GetSamples()
  12.  
  13. let parcours (t:JsonProvider<"sample.json">.L []) =
  14.   [for event in t do
  15.     let mutable b = 0.0M
  16.     let mutable c = 0.0M
  17.     let mutable counter = true
  18.     let mutable d = 0
  19.     for ev in event.L do
  20.       match ev.S  with
  21.         |Some s ->  if counter then
  22.                       b <- s
  23.                       counter <- not(counter)
  24.                     else
  25.                       c <- s
  26.         |None -> ()
  27.       match ev.N with
  28.         |Some n -> d <- n
  29.         |None -> ()
  30.     yield (b,c,d)]
  31.  
  32.  
  33. let realparcours (tableau:JsonProvider<"sample.json">.Root []) =
  34.   [for elem in tableau do
  35.     yield parcours elem.Result.M.Xxbtzeur.M.Bids.L
  36.     yield parcours elem.Result.M.Xxbtzeur.M.Asks.L
  37.   ]
  38.  
  39. let printer truc =
  40.   let (a,b,c) = truc
  41.   a.ToString() + " | " + b.ToString() + " | " + c.ToString()
  42.  
  43. let afficher aList =
  44.   let rec affichage liste s =
  45.     match liste with
  46.     |[] -> s
  47.     |[hd] -> s + (printer hd)
  48.     |hd1::hd2::tl -> affichage tl (s + (printer hd1) + " || " + (printer hd2) + Environment.NewLine)
  49.   in affichage aList ""
  50.  
  51. let beautify (aList:('a * 'b * 'c) list List) =
  52.  let size = aList.Length
  53.  let mutable s = Array.create size ""
  54.  let rec beau (liste:('a * 'b * 'c) list List) counter =
  55.     match liste with
  56.       |[] -> s
  57.       |hd::tl -> s.[counter] <- (afficher  hd)
  58.                  beau tl (counter + 1)
  59.   in beau aList 0
  60.  
  61. let json =  olivier |> realparcours |> beautify
  62.  
  63. printfn "%s" json.[0]
  64.  
  65. File.WriteAllLines("test.txt",json)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement