Exemple #1
0
func fakeImportFromDevice(db *db.DB) error {

	genRandomEntry := func(lastTime time.Time) omron.Entry {
		return omron.Entry{
			Time:  lastTime.Add(8 + time.Hour*12),
			Sys:   100 + rand.Intn(60),
			Dia:   60 + rand.Intn(35),
			Pulse: 60 + rand.Intn(40),
			Bank:  rand.Intn(1),
		}
	}

	genIncrEntry := func(e omron.Entry) omron.Entry {
		k := rand.Intn(10) + 1
		return omron.Entry{
			Time:  e.Time.Add((15 + time.Duration(rand.Intn(60))) * time.Second),
			Sys:   e.Sys - 5 + rand.Intn(k),
			Dia:   e.Dia - 5 + rand.Intn(k),
			Pulse: e.Pulse - 5 + rand.Intn(k),
			Bank:  e.Bank,
		}

	}

	all := make([]omron.Entry, 500)
	t := time.Now().Add(-300 * time.Hour * 24)
	for i := range all {
		if i%3 == 0 {
			e := genRandomEntry(t)
			t = e.Time
			all[i] = e
		} else {
			e := genIncrEntry(all[i-1])
			t = e.Time
			all[i] = e
		}

	}

	sort.Sort(omron.ByTime(all))
	// data, err := json.MarshalIndent(all, "", "  ")
	// lg.Infoln(string(data))
	// if err != nil {
	// lg.Fatal(err)
	// }
	// os.Exit(1)

	db.Update(func(tx *bolt.Tx) error {
		tx.DeleteBucket([]byte(entriesBucketName))
		return nil
	})

	return db.SaveEntries(all)
}
Exemple #2
0
func importFromDevice(db *db.DB) error {

	if err := omronread.Open(); err != nil {
		return err
	}
	defer func() {
		if err := omronread.Close(); err != nil {
			lg.Errorln(err)
		}
	}()

	var all []omron.Entry

	{
		entries, err := omronread.Read(0)
		if err != nil {
			return err
		}
		all = append(all, entries...)

	}

	{
		entries, err := omronread.Read(1)
		if err != nil {
			return err
		}
		all = append(all, entries...)
	}
	sort.Sort(omron.ByTime(all))
	// data, err := json.MarshalIndent(all, "", "  ")
	// if err != nil {
	// lg.Fatal(err)
	// }
	return db.SaveEntries(all)

}