<commit_before>package client

import (
	"github.com/oscp/openshift-monitoring/models"
	"log"
	"os"
	"github.com/cenkalti/rpc2"
)

func registerOnHub(h string, dc *models.DaemonClient) {
	log.Println("registring on the hub:", h)
	var rep string
	err := dc.Client.Call("register", dc.Daemon, &rep)
	if err != nil {
		log.Fatal("error registring on hub: ", err)
	}
	if rep != "ok" {
		log.Fatalf("expected the hub to answer with ok. he did with: %+v", rep)
	}
}

func unregisterOnHub(c *rpc2.Client) {
	var rep string
	host, _ := os.Hostname()
	err := c.Call("unregister", host, &rep)
	if err != nil {
		log.Fatalf("error when unregistring from hub: %s", err)
	}
	c.Close()
}

func handleCheckStarted(dc *models.DaemonClient) {
	dc.Daemon.StartedChecks++
	updateDaemonOnHub(dc)
}

func handleCheckFinished(dc *models.DaemonClient, ok bool) {
	if (ok) {
		dc.Daemon.SuccessfulChecks++
	} else {
		dc.Daemon.FailedChecks++
	}
	updateDaemonOnHub(dc)
}

func handleChecksStopped(dc *models.DaemonClient) {
	log.Println("stopped checks")

	dc.Daemon.StartedChecks = 0;
	dc.Daemon.FailedChecks = 0;
	dc.Daemon.SuccessfulChecks = 0;
	updateDaemonOnHub(dc)
}

func updateDaemonOnHub(dc *models.DaemonClient) {
	var rep string
	err := dc.Client.Call("updateCheckcount", dc.Daemon, &rep)<commit_msg>Bugfixes<commit_after>package client

import (
	"github.com/oscp/openshift-monitoring/models"
	"log"
	"os"
	"github.com/cenkalti/rpc2"
)

func registerOnHub(h string, dc *models.DaemonClient) {
	log.Println("registring on the hub:", h)
	var rep string
	err := dc.Client.Call("register", dc.Daemon, &rep)
	if err != nil {
		log.Fatal("error registring on hub: ", err)
	}
	if rep != "ok" {
		log.Fatalf("expected the hub to answer with ok. he did with: %+v", rep)
	}
}

func unregisterOnHub(c *rpc2.Client) {
	var rep string
	host, _ := os.Hostname()
	err := c.Call("unregister", host, &rep)
	if err != nil {
		log.Fatalf("error when unregistring from hub: %s", err)
	}
	c.Close()
}

func handleCheckStarted(dc *models.DaemonClient) {
	dc.Daemon.StartedChecks++
	updateDaemonOnHub(dc)
}

func handleCheckFinished(dc *models.DaemonClient, ok bool) {
	if (ok) {
		dc.Daemon.SuccessfulChecks++
	} else {
		dc.Daemon.FailedChecks++
	}
	updateDaemonOnHub(dc)
}

func handleChecksStopped(dc *models.DaemonClient) {
	log.Println("stopped checks")
	updateDaemonOnHub(dc)
}

func updateDaemonOnHub(dc *models.DaemonClient) {
	var rep string
	err := dc.Client.Call("updateCheckcount", dc.Daemon, &rep)
{'fraction_non_alphanumeric': 0.1470113085621971, 'fraction_numerical': 0.002827140549273021, 'mean_word_length': 4.578828828828829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4307524', 'n_tokens_mistral': 993, 'n_tokens_neox': 976, 'n_words': 209}