From 36300cd6a41a9fa70830ba8bf1f4295711e03d28 Mon Sep 17 00:00:00 2001 From: "Achim D. Brucker" Date: Sat, 24 Jun 2017 22:11:58 +0100 Subject: [PATCH] Initial commit: simple example. --- example.fsx | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 example.fsx diff --git a/example.fsx b/example.fsx new file mode 100644 index 0000000..4bd8f07 --- /dev/null +++ b/example.fsx @@ -0,0 +1,57 @@ +// reference the type provider dll +#r "./packages/SQLProvider/lib/FSharp.Data.SqlProvider.dll" +open FSharp.Data.Sql + +// static (compile time) ResolutionPath and ConnectionString +let [] ResolutionPath = __SOURCE_DIRECTORY__ + @"/lib" +let [] ConnectionString = "Data Source=" + + __SOURCE_DIRECTORY__ + @"/data/extensions.sqlite;Version=3" + + + +// create a type alias with the connection string and database vendor settings +type Sql = SqlDataProvider< + ConnectionString = ConnectionString, + DatabaseVendor = Common.DatabaseProviderTypes.SQLITE, + ResolutionPath = ResolutionPath, + IndividualsAmount = 500, + UseOptionTypes = true > + +let Ctx = Sql.GetDataContext() // ResolutionPath,ConnectionString) // dynamic ResolutionPath and ConnectionString + +let getDownloads extid = query { + for order in Ctx.Main.Extension do + where (order.Extid = Some extid) + select (order.Date, order.Downloads) + } |> Seq.filter (fun (date, download) -> date.IsSome && download.IsSome) + |> Seq.map (fun (date, download) -> (System.DateTime.Parse(date.Value), + download.Value)) + |> Seq.toArray + +let customers = + Ctx.Main.Extension + |> Seq.map(fun c -> c.Extid) + |> Seq.toList + + +#load "packages/FsLab/Themes/DefaultWhite.fsx" +#load "packages/FsLab/FsLab.fsx" + +open Deedle +open FSharp.Data +open XPlot.GoogleCharts +open XPlot.GoogleCharts.Deedle + +let ExtIds = ["aaagbdompnfgjaokopkpaceijcapjdde" + "aaahoedfmconkhncmkajlkallgnkjibh" + "aaahpjmadckbgmdbflcgblcnimbpfefg" + "aaaidlpoefeeklbhpndokmfipimojimj" + "aaaikdbhdiebhdogngakgnmjgpkpcmln" + ] + +(List.map (fun e -> (series (getDownloads e))) ExtIds) + |> Chart.Line + |> Chart.WithOptions (Options(legend=Legend(position="bottom"))) + |> Chart.WithLabels ExtIds + +