3 ms·
There are actually 2 dates,the 24th and the 25th, in the data sample. You can do this in a manner that's both fairly comprehensible and succint, for arbitrary
by Dn_Ab 11y ago
There are actually 2 dates,the 24th and the 25th, in the data sample.
You can do this in a manner that's both fairly comprehensible and succint, for arbitrary number of dates, using a Json TypeProvider in F#.
#r @"../Fsharp.Data.dll"
open FSharp.Data
open System
type PersonsData = JsonProvider<"../data.sample.json">
let dateTriple (d:PersonsData.Root) = d.Timestamp.Year, d.Timestamp.Month,d.Timestamp.Day
let info = PersonsData.Load ("./data.json")
let uniqueDates = info |> Array.map dateTriple |> set
let createCsv (d : PersonsData.Root seq) =
d |> Seq.filter (fun p -> Option.isSome p.Creditcard)
|> Seq.map (fun p -> sprintf "%s,%s" p.Name p.Creditcard.Value )
|> String.concat "\n"
info |> Seq.groupBy dateTriple
|> Seq.iter (fun ((y,m,d), data) ->
IO.File.WriteAllText (sprintf "%d%02d%02d.csv" y m d, createCsv data))
With the below as a sample (though dataset itself could have been used since it's not so large):
[{"name":"Quincy Gerhold","email":"laron.cremin@macejkovic.info","city":"Port Tiabury","mac":"64:d2:17:ff:28:13","timestamp":"2015-04-25 15:57:12 +0700","creditcard":null},{"name":"Lolita Hudson","email":"tracy.goodwin@schmidt.com","city":"Port Brookefurt","mac":"2d:20:78:41:8e:35","timestamp":"2015-04-25 23:20:21 +0700","creditcard":"1211-1221-1234-2201"}]
- arianvanp 11y agoIf I read correctly. It reads in sample data at compile time and constructs a type from that? `PersonsData` ? That's really cool.
- DCoder 11y agoVery cool. That's exactly what TypeProviders are for: https://msdn.microsoft.com/en-us/library/hh156509.aspx https://msdn.microsoft.com/en-us/library/hh156509.aspx