<commit_before>﻿namespace MagicTimes.Hub

open Countersoft.Gemini.Api
open Countersoft.Gemini.Commons.Entity
open Countersoft.Gemini.Commons.Dto
open System

module Session = 
    type SessionId = int
    
    type AddIssueId = 
        { id : SessionId
          issueId : int }
    
    type AddComment = 
        { id : SessionId
          comment : string }

module Settings = 
    type Settings = 
        { username : string
          apiKey : string }
    
    type ChangeSettings = 
        { Settings : Settings }

module Command = 
    type T = 
        | ChangeSettings of Settings.ChangeSettings
        | AddIssueId of Session.AddIssueId
        | AddComment of Session.AddComment
        | ResetSettings
        | LoadData

module HubModule = 
    open FSharp.Interop.Dynamic
    open Microsoft.AspNet.SignalR
    open Microsoft.AspNet.SignalR.Hubs
    open MagicTimes.Core
    
    let execute (x : Hub) command = 
        match command with
        | Command.LoadData -> 
            DataStore.Load "nfc.datastore.path"
            |> Option.toArray
            |> x.Clients.All?event
        command
    
    let printConnection (x : Hub) command = printfn "%s: %s" command x.Context.ConnectionId
    
    type CommandHub() as this = 
        inherit Hub()
        member this.Command(data : Command.T) = execute this data
        
        override this.OnConnected() = 
            printConnection this "CONNECTED"
            base.OnConnected()
        
        override this.OnDisconnected stop = 
            printConnection this "DISCONNECTED"
            base.OnDisconnected stop
        
        override this.OnReconnected() = 
            printConnection this "RECONNECTED"
            base.OnReconnected()<commit_msg>implemented event trigger, and wrapping of data for the events<commit_after>﻿namespace MagicTimes.Hub

open Countersoft.Gemini.Api
open Countersoft.Gemini.Commons.Entity
open Countersoft.Gemini.Commons.Dto
open System

module Session = 
    type SessionId = int
    
    type AddIssueId = 
        { id : SessionId
          issueId : int }
    
    type AddComment = 
        { id : SessionId
          comment : string }

module Settings = 
    type Settings = 
        { username : string
          apiKey : string }
    
    type ChangeSettings = 
        { Settings : Settings }

module Command = 
    type T = 
        | ChangeSettings of Settings.ChangeSettings
        | AddIssueId of Session.AddIssueId
        | AddComment of Session.AddComment
        | ResetSettings
        | LoadData

module HubModule = 
    open FSharp.Interop.Dynamic
    open Microsoft.AspNet.SignalR
    open Microsoft.AspNet.SignalR.Hubs
    open MagicTimes.Core
    
    type Event<'a> = 
        { ``type`` : string
          data : 'a }
    
    let wrap (name : string) (data : Option<'a>) = 
        { ``type`` = name.ToUpper()
          data = Option.toArray data }
    
    let event name (data:Option<'a>) (x : Hub) = wrap name data |> x.Clients.All?event

    let sendData = 
        "nfc.datastore.path"
        |> DataStore.Load
        |> event "RECIEVE_UPDATE"
    
    let execute (x : Hub) command = 
        match command with
        | Command.LoadData -> sendData x
        command
    
    let printConnection (x : Hub) command = printfn "%s: %s" command x.Context.ConnectionId
    let onConnect (x : Hub) = sendData x
    
    type CommandHub() as this = 
        inherit Hub()
        member this.Command(data : Command.T) = execute this data
        
        override this.OnConnected() = 
            printConnection this "CONNECTED"
            onConnect this
            base.OnConnected()
        
        override this.OnDisconnected stop = 
            printConnection this "DISCONNECTED"
            base.OnDisconnected stop
        
        override this.OnReconnected() = 
            printConnection this "RECONNECTED"
            onConnect this
            base.OnReconnected()
{'fraction_non_alphanumeric': 0.07461928934010152, 'fraction_numerical': 0.0, 'mean_word_length': 1.8892961876832846, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2943718', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1071, 'n_words': 289}