-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarise_times.fsx
211 lines (174 loc) · 5.52 KB
/
summarise_times.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#r "nuget: CliWrap, 3.6.0"
#r "nuget: MSBuild.StructuredLogger, 2.1.746"
#r "nuget: Deedle, 3.0.0"
#r "nuget: FSharp.Data"
#I "C:/Users/janus/.nuget/packages/deedle/3.0.0"
#load "Deedle.fsx"
#r "nuget: Microsoft.Data.Analysis, 0.20.1"
open CliWrap
sd
let go (csv : string) =
let df = Frame.ReadCsv(csv)
df
go "C:/projekty/fsharp/.cache/fsprojects__fantomas/18f31541/src/Fantomas/times.csv"
// for d in df do
// printfn $"%+A{d}"
// let parseDuration (x : CsvRow) =
// TimeSpan.FromSeconds(System.Double.Parse(x["Duration(s)"]))
// let byId =
// data.Rows
// |> Seq.map (fun x -> x["Id"], x)
// |> readOnlyDict
// let roots =
// data.Rows
// |> Seq.filter (fun x -> x["Name"] = "FSC compilation")
// |> Seq.map (fun x ->
// {
// Project = x["project"]
// StartTime = x["StartTime"]
// Duration = x |> parseDuration
// Id = x["Id"]
// }
// )
// |> Seq.toArray
// let rootIds = roots |> Array.map (fun r -> r.Id)
// let summary
// let groups =
// data.Rows
// |> Seq.toArray
// |> Array.groupBy findRoot
// let sumBy (x : CsvRow seq) (g) =
// x
// |> Seq.groupBy g
// |> Seq.map (fun (key, items) ->
// key,
// items |> Seq.sumBy (fun x -> (parseDuration x).TotalMilliseconds)
// )
// |> Seq.toArray
// let sums =
// groups
// let data =
// data.Rows
// |> Seq.filter (fun x -> rootIds |> Array.contains x["ParentId"])
// |> Seq.filter (fun x -> System.String.IsNullOrEmpty(x["fileName"]))
// |> Seq.groupBy (fun x -> x["ParentId"])
// |> readOnlyDict
// |> Seq.map (fun x ->
// {
// Name = x["Name"]
// Duration = x |> parseDuration
// }
// )
// |> Seq.toArray
// for d in data do
// printfn $"%+A{d}"
// match fsi.CommandLineArgs with
// | [|_; csv|] -> go csv
// | args -> failwith $"Usage: 'script path' csv"
// type Row =
// {
// Name : string
// Duration : TimeSpan
// }
// type Run =
// {
// Project : string
// StartTime : string
// Duration : TimeSpan
// Id : string
// }
// type Metrics = Metrics of Map<string, double>
// with
// member this.Value = match this with Metrics m -> m
// member this.Get(name) = this.Value |> Map.find name
// static member Average(items : Metrics[]) =
// items
// |> Array.collect (fun m -> m.Value |> Seq.toArray)
// |> Array.map (fun (KeyValue(k,v)) -> k, v)
// |> Array.groupBy (fun (k,v) -> k)
// |> Array.map (fun (k, values) -> k, values |> Array.map snd |> Array.average)
// |> Map.ofArray
// type EntryKey =
// {
// Name : string
// FileName : string
// }
// type Entry =
// {
// Key : EntryKey
// Metrics : Metrics
// }
// let rootKey = {Name = "FCS Compilation"; FileName = null}
// type Summary =
// {
// Entries : Entry[]
// Project : string
// }
// module Summary =
// let find (key : EntryKey) (summary : Summary) =
// summary.Entries |> Array.find (fun e -> e.Key = key)
// let root (summary : Summary) = summary |> find rootKey
// let rec findRoot (x : CsvRow) =
// if String.IsNullOrEmpty(x["ParentId"]) then
// x["Id"]
// else
// let parent = byId[x["ParentId"]]
// findRoot parent
// let extractSummaries (entries : CsvRow[]) : Summary[] =
// let go (csv : string) =
// let data =
// CsvFile
// .Load(csv)
// .Cache()
// let parseDuration (x : CsvRow) =
// TimeSpan.FromSeconds(System.Double.Parse(x["Duration(s)"]))
// let byId =
// data.Rows
// |> Seq.map (fun x -> x["Id"], x)
// |> readOnlyDict
// let roots =
// data.Rows
// |> Seq.filter (fun x -> x["Name"] = "FSC compilation")
// |> Seq.map (fun x ->
// {
// Project = x["project"]
// StartTime = x["StartTime"]
// Duration = x |> parseDuration
// Id = x["Id"]
// }
// )
// |> Seq.toArray
// let rootIds = roots |> Array.map (fun r -> r.Id)
// let summary
// let groups =
// data.Rows
// |> Seq.toArray
// |> Array.groupBy findRoot
// let sumBy (x : CsvRow seq) (g) =
// x
// |> Seq.groupBy g
// |> Seq.map (fun (key, items) ->
// key,
// items |> Seq.sumBy (fun x -> (parseDuration x).TotalMilliseconds)
// )
// |> Seq.toArray
// let sums =
// groups
// let data =
// data.Rows
// |> Seq.filter (fun x -> rootIds |> Array.contains x["ParentId"])
// |> Seq.filter (fun x -> System.String.IsNullOrEmpty(x["fileName"]))
// |> Seq.groupBy (fun x -> x["ParentId"])
// |> readOnlyDict
// |> Seq.map (fun x ->
// {
// Name = x["Name"]
// Duration = x |> parseDuration
// }
// )
// |> Seq.toArray
// for d in data do
// printfn $"%+A{d}"
// match fsi.CommandLineArgs with
// | [|_; csv|] -> go csv
// | args -> failwith $"Usage: 'script path' csv"