Exemplo n.º 1
0
func init() {
	var err error
	hostName, err = os.Hostname()
	if err != nil {
		log.Fatal("Can't get the hostname of the local machine:", err)
	}
}
Exemplo n.º 2
0
func GetTrainerCorrelations(trainingFile string, TimeRangeToStudySecs int64) TrainerInt {
	log.Debug("Initializing trainer...")

	TimeRangeToStudySecs *= tsMultToSecs
	feedsFile, err := os.Open(trainingFile)
	log.Debug("File:", trainingFile)
	if err != nil {
		log.Fatal("Problem reading the logs file")
	}

	scanner := bufio.NewScanner(feedsFile)

	feeds := &TrainerCorrelations{
		feeds:                 make(map[string][]*charont.CurrVal),
		centroidsCurr:         make(map[string][][]float64),
		centroidsCurrSell:     make(map[string][][]float64),
		centroidsForAsk:       make(map[string][]int),
		centroidsForSell:      make(map[string][]int),
		maxWinByCentroid:      make(map[string][]float64),
		maxLossByCentroid:     make(map[string][]float64),
		maxWinByCentroidSell:  make(map[string][]float64),
		maxLossByCentroidSell: make(map[string][]float64),
	}

	i := 0
	for {
		var feed *charont.CurrVal

		if !scanner.Scan() {
			break
		}
		lineParts := strings.SplitN(scanner.Text(), ":", 2)
		curr := lineParts[0]
		if len(lineParts) < 2 {
			log.Error("The line:", i, "can't be parsed")
			continue
		}
		if err := json.Unmarshal([]byte(lineParts[1]), &feed); err != nil {
			log.Error("The feeds response body is not a JSON valid, Error:", err, "Line:", i)
			continue
		}

		if _, ok := feeds.feeds[curr]; !ok {
			feeds.feeds[curr] = []*charont.CurrVal{}
		}
		feeds.feeds[curr] = append(feeds.feeds[curr], feed)
		i++
		if i%10000 == 0 {
			log.Debug("Lines:", i)
		}
	}

	for curr, scores := range feeds.feeds {
		log.Debug("Curr:", curr, "Scores:", len(scores))
	}

	feeds.studyCurrencies(TimeRangeToStudySecs)

	return feeds
}
Exemplo n.º 3
0
Arquivo: cfg.go Projeto: postfix/pit
// loadSection loads a section of the config file
func loadSection(name string) (section *configparser.Section) {
	if section, ok := sections[name]; ok {
		return section
	}

	if cfg == nil {
		log.Fatal("Configuration file not yet loaded, call to the Init method before try to use the config manager")
	}

	if sec, err := cfg.Section(name); err == nil {
		sections[name] = sec

	} else {
		log.Fatal("Configuration subsection:", name, "can't be parsed")
	}

	return sections[name]
}
Exemplo n.º 4
0
func (im *Model) registerHostName(hostName string) {
	attribs := []dynamodb.Attribute{
		*dynamodb.NewStringAttribute(cPrimKey, hostName),
		*dynamodb.NewStringAttribute("ts", fmt.Sprintf("%d", time.Now().Unix())),
	}

	if _, err := im.table.PutItem(hostName, cPrimKey, attribs); err != nil {
		log.Fatal("The hostname can't be registered on the instances table, Error:", err)
	}
}
Exemplo n.º 5
0
func parseLine(line string) (recordID uint64, values map[uint64]uint8) {
	parts := strings.SplitN(line, ":", 2)
	recordIDOrig, _ := strconv.ParseInt(parts[0], 10, 64)
	recordID = uint64(recordIDOrig)

	valuesAux := make(map[string]uint8)
	if len(parts) < 2 {
		log.Fatal(line)
	}
	json.Unmarshal([]byte(parts[1]), &valuesAux)
	values = make(map[uint64]uint8)
	for k, v := range valuesAux {
		kI, _ := strconv.ParseInt(k, 10, 64)
		values[uint64(kI)] = v
	}

	return
}