Beispiel #1
0
func init() {
	observer.Observe("config.loaded", func(msg interface{}) {
		logfile, err := os.OpenFile(path.Join(config.DataPath, "impression.log"),
			os.O_CREATE|os.O_WRONLY|os.O_APPEND,
			0666)
		if err != nil {
			panic(err)
		}
		logger = log.New(logfile, "", log.Ldate|log.Ltime|log.Lmicroseconds)

		err = Load()
		if err != nil {
			panic(err)
		}
	})

	observer.Observe("player.played", func(msg interface{}) {
		song := msg.(*library.Song)
		log.Printf("Played %v", song)
		Log(song, 1)
	})

	observer.Observe("player.skip", func(msg interface{}) {
		song := msg.(*library.Song)
		log.Printf("Skipped %v", song)
		Log(song, -2)
	})

}
Beispiel #2
0
func init() {
	observer.Observe("config.loaded", func(msg interface{}) {
		if config.Config.WeatherUndergroundKey == "" {
			log.Printf("env: sensor: weather [disabled] - No Weather Underground Key in Config")
			return
		}
		var weatherSensor WeatherSensor
		env.RegisterSensor(&weatherSensor)
		log.Printf("env: sensor: weather [enabled] - OK")
	})
}
Beispiel #3
0
func karmaSong() func() (library.Song, error) {
	log.Println("karmaSong")

	var impressionsByKey map[int][]string = invertMap(karma.SongKarma)
	impressionKeys := keys(impressionsByKey)
	sort.Ints(impressionKeys)

	log.Println("impressions prepped")
	songCh := make(chan *library.Song)
	observer.Observe("library.loaded", func(msg interface{}) {
		go func() {
			for i := len(impressionKeys) - 1; i >= 0; i-- {
				log.Printf("impression key: %v", impressionKeys[i])
				for _, hash := range impressionsByKey[impressionKeys[i]] {
					log.Printf("impression hash: %q", hash)
					song, err := library.ByHash(hash)
					if err != nil {
						continue
					}
					log.Printf("karmaSong karma:%d song:%v", impressionKeys[i], song)
					songCh <- song
				}
			}
			close(songCh)
		}()
	})

	return func() (library.Song, error) {
		nextSong, ok := <-songCh
		if ok {
			return *nextSong, nil
		} else {
			return library.Song{}, fmt.Errorf("NoSong")
		}
	}
}
Beispiel #4
0
func main() {
	observer.Observe("library.loaded", func(msg interface{}) {
		fmt.Println("initializing graph building")
		// Load unique paths
		pathsm := make(map[string]bool)
		for _, song := range library.Songs {
			path_parts := strings.Split(song.Path, "/")
			plen := len(path_parts)
			partial_path := ""
			for p, path_part := range path_parts {
				if p > 0 {
					partial_path += "/"
				}
				if p == plen-1 {
					break
				}
				partial_path += path_part
				pathsm[partial_path] = true
			}
		}

		var paths []string
		for path := range pathsm {
			paths = append(paths, path)
		}
		sort.Strings(paths)
		fmt.Printf("paths: %d\n", len(paths))

		graph := make([][]int, len(library.Songs))
		for i := range library.Songs {
			graph[i] = make([]int, len(paths))
		}

		fmt.Println("connecting edges")
		m := 0
		c := 0
		// Connect edges
		for _, song := range library.Songs {
			// find connected songs
			c += 1
			for k, path := range paths {
				if strings.HasPrefix(song.Path, path) {
					graph[songIdx(song)][k] += 1
					m += 1
				}
			}
		}
		fmt.Printf("consider: %d\n", c)
		fmt.Printf("matching: %d\n", m)

		// output graph
		filename := "graph.csv"
		f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
		if err != nil {
			panic(err)
		}
		defer f.Close()
		for row := 0; row < len(library.Songs); row += 1 {
			write(f, strconv.Itoa(row))
			for col := 0; col < len(paths); col += 1 {
				//if graph[row][col] != 0 {
				//  fmt.Printf("%d - %d : %d", row, col, graph[row][col])
				//}
				write(f, ",")
				write(f, strconv.Itoa(graph[row][col]))
			}
			write(f, "\n")
		}
		fmt.Println("done")

	})

	library.Load()
}