This repository was archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
72 lines (58 loc) · 2.41 KB
/
Program.fs
File metadata and controls
72 lines (58 loc) · 2.41 KB
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
namespace Bascplain
module Program =
open Analysis
open Charts
open Matchers
open Loader
open System
open Suave
open Suave.DotLiquid
open Suave.Filters
open Suave.Operators
type LineChartModel = { Property: string; Expressions: string[]; ChartHtml: string; }
let mkAnalysisEngine rs es =
let ms = es |> Array.map parseMatchExpression
analyzeIntoMatcherGroupsT ms rs
/// **Description**
///
/// **Parameters**
/// * `p` - Title of the chart
/// * `k` - Chart creation function
/// * `z` - Analysis engine `string [] -> 'a`
/// * `x` - Expression list in query
///
/// **Output Type**
/// * `WebPart<HttpContext>`
///
/// **Exceptions**
///
let mkLineChartPage p k z (x : string) =
let mkPageWithExpressions es = page "lines.htm" { Property = p; Expressions = es; ChartHtml = k <| z es; }
let mkPageFromForm (req:HttpRequest) =
let getNthFormData n = match req.formData(sprintf "expression%d" n) with
| Choice2Of2 _ -> None
| Choice1Of2 a -> Some a
let es = Seq.initInfinite id |> Seq.map getNthFormData |> Seq.takeWhile Option.isSome |> Seq.choose id |> Seq.toArray
mkPageWithExpressions <| es
choose [
GET >=> (mkPageWithExpressions <| x.Split[|';'|])
POST >=> request mkPageFromForm
]
let webApp z =
choose [
path "/" >=> page "home.htm" null
pathScan "/nav/%s" <| mkLineChartPage "NAV" getNavChart z
pathScan "/weight/%s" <| mkLineChartPage "Weight" getWeightChart z
pathScan "/return/%s" <| mkLineChartPage "Daily returns" getDailyReturnChart z
pathScan "/performance/%s" <| mkLineChartPage "Total performance" getPerformanceChart z
]
[<EntryPoint>]
let main argv =
let d = match argv with
| [|d'|] -> d'
| _ -> printf "Enter CSV directory: "; Console.ReadLine()
setTemplatesDir "./liquid"
let r = loadDirectoryForAnalysis d
//let c = {defaultConfig with bindings = [HttpBinding.createSimple HTTP "0.0.0.0" 9000] }
startWebServer defaultConfig (webApp (mkAnalysisEngine r))
0 // return an integer exit code