<commit_before>package main

import (
	"bytes"
	"flag"
	"fmt"
	"log"
	"math/rand"
	"net/http"
	"os"
	"text/template"
	"time"
)

var reportTemplate *template.Template

func init() {
	reportTemplate = template.Must(template.New("reportTemplate").Parse(reportTemplateText))
}

func transmit(url string, serial int, epoch int64) {
	content := map[string]interface{}{}
	content["epoch"] = epoch
	content["serial"] = serial
	content["timestamp"] = time.Now().Unix()

	data := [rows][columns]int32{}
	for row := 0; row < rows; row++ {
		for column := 0; column < columns; column++ {
			data[row][column] = rand.Int31()
		}
	}
	content["data"] = data

	buf := bytes.Buffer{}
	reportTemplate.Execute(&buf, content)

	resp, err := http.Post(url, "application/xml", &buf)
	if err != nil {
		log.Println("Error:", err)
		if len(buf.Bytes()) > 0 {
			log.Println("Data:")
			log.Println(string(buf.Bytes()))
		}
		return
	}

	defer resp.Body.Close()

	if resp.StatusCode == http.StatusOK {
		log.Printf("eGauge simulator #%d with serial 0x%08x successfully sent data.\n", serial, serial)
	} else {
		log.Printf("eGauge simulator #%d with serial 0x%08x received HTTP error code %s.\n", serial, serial, resp.Status)
	}
}

func simulate(url string, serial int) {
	epoch := time.Now().Unix()

	log.Printf("Starting eGauge simulator #%d with serial 0x%08x at time 0x%08x.\n", serial, serial, epoch)

	for {
		// Data "gathering" time
		time.Sleep(time.Minute)

		go transmit(url, serial, epoch)
	}
}

func main() {
	num := flag.Int("n", 1, "Number of eGauges.")
	flag.Parse()

	isFatalError := false

	// Check for remote URL
	if flag.NArg() != 1 {
		fmt.Println("Error: Remote URL must be specified.")
		isFatalError = true
	}<commit_msg>Added landingzone error message logging in egaugesimulator.<commit_after>package main

import (
	"bytes"
	"flag"
	"fmt"
	"log"
	"math/rand"
	"net/http"
	"os"
	"text/template"
	"time"
)

var reportTemplate *template.Template

func init() {
	reportTemplate = template.Must(template.New("reportTemplate").Parse(reportTemplateText))
}

func transmit(url string, serial int, epoch int64) {
	content := map[string]interface{}{}
	content["epoch"] = epoch
	content["serial"] = serial
	content["timestamp"] = time.Now().Unix()

	data := [rows][columns]int32{}
	for row := 0; row < rows; row++ {
		for column := 0; column < columns; column++ {
			data[row][column] = rand.Int31()
		}
	}
	content["data"] = data

	buf := bytes.Buffer{}
	reportTemplate.Execute(&buf, content)

	resp, err := http.Post(url, "application/xml", &buf)
	if err != nil {
		log.Println("Error:", err)
		if len(buf.Bytes()) > 0 {
			log.Println("Data:")
			log.Println(string(buf.Bytes()))
		}
		return
	}

	defer resp.Body.Close()

	if resp.StatusCode == http.StatusOK {
		log.Printf("eGauge simulator #%d with serial 0x%08x successfully sent data.\n", serial, serial)
	} else {
		log.Printf("eGauge simulator #%d with serial 0x%08x received HTTP error code %s:\n", serial, serial, resp.Status)

		buf := new(bytes.Buffer)
		buf.ReadFrom(resp.Body)
		log.Println(string(buf.Bytes()))
	}
}

func simulate(url string, serial int) {
	epoch := time.Now().Unix()

	log.Printf("Starting eGauge simulator #%d with serial 0x%08x at time 0x%08x.\n", serial, serial, epoch)

	for {
		// Data "gathering" time
		time.Sleep(time.Minute)

		go transmit(url, serial, epoch)
	}
}

func main() {
	num := flag.Int("n", 1, "Number of eGauges.")
	flag.Parse()

	isFatalError := false

	// Check for remote URL
	if flag.NArg() != 1 {
		fmt.Println("Error: Remote URL must be specified.")
		isFatalError = true
	}
{'fraction_non_alphanumeric': 0.1671792004473022, 'fraction_numerical': 0.012859938495946324, 'mean_word_length': 4.067988668555241, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7455636', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1278, 'n_words': 326}