Created
January 28, 2024 00:45
-
-
Save jkone27/a3ba6c5761eaf2c4d66c084a8e01ddcd to your computer and use it in GitHub Desktop.
use spectre console and csv to display workshop stats and partecipants in a table in fsharp scripts fsx
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
#r "nuget: FSharp.Data" | |
#r "nuget: EluciusFTW.SpectreCoff" | |
open FSharp.Data | |
open SpectreCoff | |
open System | |
type ``💁`` = CsvProvider<"./workshop.csv"> | |
let sample = ``💁``.GetSample() | |
// let columns = | |
// sample.Headers | |
// |> Option.toList | |
// |> Seq.collect id // fun x -> x | |
// |> Seq.map Edgy | |
// |> Seq.map column | |
// |> Seq.toList | |
let headers = | |
[ "Name"; "Timestamp"; "My programming experience" ] | |
|> List.map Edgy | |
|> List.map column | |
let rowsData = | |
sample.Rows | |
|> Seq.map (fun r -> | |
let nameAlias = | |
r.``Email Address``.Split('@')[0] | |
|> Seq.mapi (fun i x -> if i < 4 then x else '*') | |
|> Seq.toArray | |
|> (fun x -> new String(x)) | |
let date = r.Timestamp.Date.ToString("yyyy-MM-dd") | |
{| Name = nameAlias | |
Date = date | |
ProgrExp = r.``My programming experience`` |}) | |
let rows = | |
rowsData | |
|> Seq.map (fun x -> Strings [ x.Name; x.Date; x.ProgrExp ]) | |
|> Seq.toList | |
let powerTable = table headers rows | |
"Create, Code, Reboot" |> figlet |> toConsole | |
"SUNDAY 28 @ Sexyland, take your laptot" |> Calm |> toConsole | |
powerTable |> toOutputPayload |> toConsole | |
let chartItems = | |
rowsData | |
|> Seq.groupBy (fun x -> x.ProgrExp) | |
|> Seq.map (fun (g, items) -> (g, items |> Seq.length |> float)) | |
|> Seq.sortByDescending (fun x -> x |> snd) | |
|> Seq.map ChartItem | |
|> Seq.toList | |
let chart = chartItems |> barChart "Experiences" | |
let header = P "EXPERIENCES" |> toMarkedUpString | |
chart |> panel header |> toConsole |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment