csv 形式の使用状況ログで使用状況イベントを解析するために、アクティブ パターンを使用しています。アクティブなパターン パーツは次のとおりです。ファイル全体の解析はうまく機能し、生成されるシーケンスにはあらゆる種類の UsageEvent が含まれます。
type SystemName = string
type SystemVersion = string
type MAC = string
type Category = string
type Game = string
type Setting = string
type StartupLocation = string
type UsageEvent =
| SystemStart of DateTime * SystemVersion * SystemName * MAC
| SystemEnd of DateTime
| GameStart of DateTime * Category * Game * Setting * StartupLocation
| GameEnd of DateTime * Category * Game
| Other
let (|SystemStart|SystemEnd|GameStart|GameEnd|Other|) (input : string list) =
match List.nth input 0 with
| "SystemStartedEvent" ->
SystemStart (DateTime.Parse (List.nth input 1), List.nth input 2, List.nth input 3, List.nth input 4)
| "SystemEndedEvent" ->
SystemEnd (DateTime.Parse (List.nth input 1))
| "GameStartedEvent" ->
GameStart (DateTime.Parse (List.nth input 1), List.nth input 2, List.nth input 3, List.nth input 4, List.nth input 5)
| "GameEndedEvent" ->
GameEnd (DateTime.Parse (List.nth input 1), List.nth input 2, List.nth input 3)
| _ ->
Other
私が抱えている問題は、おそらく ActivePattern を間違った方法で使用していることです。リストをたどって、いくつかのロジックに基づいてツリーを作成したいのですが、解析後にシーケンス内のエントリを一致させる方法がありません。
let CountSystemStart (entries : UsageEvent list) =
let rec loop sum = function
| SystemStart(_,_,_,_) -> sum + 1
| _ -> sum
loop 0 entries
ループ関数にはstring list
. ユニオンに含まれるデータを他にどのように使用できますか、または入力を照合してから通常の型に保存する必要がありますか?