<commit_before>// Package sunriseset provides sunrise and sunset events for the location provided.
package sunriseset

import (
	"fmt"
	"github.com/danward79/sunrise"
	"github.com/robfig/cron"
	"time"
)

//Loc stores data about the location of sunrise and set required.
type Loc struct {
	location  *sunrise.Location
	formatStr string
	cronSch   *cron.Cron
}

//New returns a new location
func New(latitude float64, longitude float64) *Loc {
	return &Loc{location: sunrise.NewLocation(latitude, longitude), formatStr: "Jan 2 15:04:05", cronSch: cron.New()}
}

//Start the process
func (l *Loc) Start() chan map[string]interface{} {
	chOut := make(chan map[string]interface{})

	//Is it before or after todays sunrise/sunset?
	l.location.Today()
	tSunrise := l.location.Sunrise()
	if time.Now().After(tSunrise) {
		tSunrise = l.nextSunrise()
	}

	l.location.Today()
	tSunset := l.location.Sunset()
	if time.Now().After(tSunset) {
		tSunset = l.nextSunset()
	}

	//Schedule cron
	l.scheduleNext(tSunrise, true, chOut)
	l.scheduleNext(tSunset, false, chOut)
	l.cronSch.Start()
	//TODO: Need to work out how to remove completed jobs or reschedule existing jobs.
	l.test(time.Now(), chOut)

	return chOut
}

//send a sunrise or sunset event to the output channel
func send(s string, t string, ch chan map[string]interface{}) {
	m := make(map[string]interface{})
	m["location"] = s
	m["state"] = t
	ch <- m
}

//test to make sure it is all working
func (l *Loc) test(t time.Time, ch chan map[string]interface{}) {

	t = t.Add(10 * time.Second)
	//Second, Minute, Hour, Dom, Month, Dow
	l.cronSch.AddFunc(cronFormat(t), func() {

		send("sunrise", fmt.Sprintf("%d", -1), ch)
		l.test(time.Now().Add(10*time.Second), ch)

	})

	for k, v := range l.cronSch.Entries() {
		fmt.Println(k, v)
	}

}
<commit_msg>Refactored and a few errors fixed<commit_after>// Package sunriseset provides sunrise and sunset events for the location provided.
package sunriseset

import (
	"fmt"
	"github.com/danward79/sunrise"
	"github.com/robfig/cron"
	"time"
)

//Loc stores data about the location of sunrise and set required.
type Loc struct {
	location  *sunrise.Location
	formatStr string
	cronSch   *cron.Cron
}

//New returns a new location
func New(latitude float64, longitude float64) *Loc {
	return &Loc{location: sunrise.NewLocation(latitude, longitude), formatStr: "Jan 2 15:04:05", cronSch: cron.New()}
}

//Start the process
func (l *Loc) Start() chan map[string]interface{} {
	chOut := make(chan map[string]interface{})

	//Is it before or after todays sunrise/sunset?
	l.location.Today()
	tSunrise := l.location.Sunrise()
	if time.Now().After(tSunrise) {
		tSunrise = l.nextSunrise()
	}

	l.location.Today()
	tSunset := l.location.Sunset()
	if time.Now().After(tSunset) {
		tSunset = l.nextSunset()
	}

	//Schedule cron
	l.scheduleNext(tSunrise, true, chOut)
	l.scheduleNext(tSunset, false, chOut)
	l.cronSch.Start()
	//TODO: Need to work out how to remove completed jobs or reschedule existing jobs.

	return chOut
}

//send a sunrise or sunset event to the output channel
func send(s string, t string, ch chan map[string]interface{}) {
	m := make(map[string]interface{})
	m["location"] = s
	m["state"] = t
	ch <- m
}

{'fraction_non_alphanumeric': 0.13817841547099188, 'fraction_numerical': 0.009669369931378666, 'mean_word_length': 4.2061688311688314, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2857700', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1150, 'n_words': 335}