Last active
February 24, 2017 20:14
-
-
Save ErikSchierboom/4ce15d4349c664374e16e223373f37ac to your computer and use it in GitHub Desktop.
This file contains 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
source https://www.nuget.org/api/v2 | |
nuget FSharp.Data | |
nuget xplot.googlecharts |
This file contains 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
#load "packages/FsLab/Themes/DefaultWhite.fsx" | |
#load "packages/FsLab/FsLab.fsx" | |
open Deedle | |
open FSharp.Data | |
open XPlot.GoogleCharts | |
open XPlot.GoogleCharts.Deedle | |
type TracksJsonProvider = JsonProvider<"http://x.exercism.io/tracks"> | |
type ConfigJsonProvider = JsonProvider<"https://raw.githubusercontent.com/exercism/xcsharp/master/config.json"> | |
let tracks = | |
TracksJsonProvider.GetSample().Tracks | |
|> Array.filter (fun track -> track.Active) | |
let rawGithubContent (file: string) = file.Replace("github.com", "raw.githubusercontent.com") | |
let trackConfigFile (repository: string) = | |
sprintf "%s/master/config.json" repository | |
|> rawGithubContent | |
let trackConfig (repository: string) = ConfigJsonProvider.Load(trackConfigFile repository) | |
let trackConfigs = | |
tracks | |
|> Seq.map (fun track -> trackConfig track.Repository) | |
|> Seq.toList | |
let numberOfExercisesByTrack = | |
trackConfigs | |
|> List.map (fun track -> track.Language, string track.Exercises.Length) | |
let numberOfDifficultiesByTrack = | |
trackConfigs | |
|> List.map (fun track -> track.Language, track.Exercises |> Seq.distinctBy (fun x -> x.Difficulty) |> Seq.length |> string) | |
let averageDifficultyByTrack = | |
trackConfigs | |
|> List.map (fun track -> track.Language, track.Exercises |> Seq.map (fun x -> float x.Difficulty) |> Seq.average |> string) | |
[numberOfExercisesByTrack; numberOfDifficultiesByTrack] | |
|> Chart.Table | |
|> Chart.WithLabels ["Track"; "# Exercises"; "# Difficulties"] | |
//type MyCsvType = CsvProvider<Schema = "A (int), B (string), C (date option)", HasHeaders=false> | |
// you can build the rows themselves | |
//let myCsv = new MyCsvType( [ MyCsvType.Row(1, "a", None) | |
// MyCsvType.Row(2, "B", Some DateTime.Now) ]) | |
//// or, for your scenario, you probably want to define a conversion function | |
//// from your record type to the CSV provider's type | |
//let buildRowFromObject obj = MyCsvType.Row(obj.A, obj.B, obj.C) | |
//let buildTableFromObjects = (Seq.map buildRowFromObject) >> Seq.toList >> MyCsvType | |
//let myCsv = someSequenceOfObjects |> buildTableFromObjects | |
//myCsv.SaveToString() | |
// http://fsharp.github.io/FSharp.Data/reference/fsharp-data-runtime-caching.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment