Esempio n. 1
0
func (p *TodayStat) Setup() {
	var debug_print_time = false

	var see_future_days = 1
	var show_days = 7
	var fetch_days = see_future_days + show_days + 1

	now := time.Now()
	stats, err := statdao.TodayStat(now.AddDate(0, 0, see_future_days), fetch_days)
	if err != nil {
		panic(err.Error())
	}

	// fill days
	p.Stats = []*model.SumStat{}
	for i := -show_days + 1; i <= see_future_days; i++ {
		key := now.AddDate(0, 0, i).Format("2006-01-02")
		var stat *model.SumStat
		for _, k := range stats {
			if k.Id == key {
				stat = k
			}
		}
		if nil == stat {
			stat = &model.SumStat{Id: key}
		}
		p.Stats = append(p.Stats, stat)
	}

	if debug_print_time {
		for _, k := range p.Stats {
			fmt.Println(">> p.Stats: ", k)
		}
	}

	if debug_print_time {
		for _, k := range p.Stats {
			fmt.Println(">> p.Stats: ", k)
		}
	}

	// 去年
	statslastyear, err2 := statdao.TodayStat(now.AddDate(-1, 0, see_future_days), fetch_days)
	p.LastYearStats = map[string]*model.SumStat{}
	if err2 != nil {
		panic(err.Error())
	} else if nil != statslastyear {
		for _, ss := range statslastyear {
			key := strings.Replace(ss.Id, last_year, current_year, -1)
			p.LastYearStats[key] = ss
		}
	}

	// p.Stats = stats
}
Esempio n. 2
0
func testLoad() {
	fmt.Println("---- start loading...")
	stats, err := statdao.TodayStat(time.Now(), 20)
	if err != nil {
		panic(err.Error())
	}
	fmt.Println(stats)
	if len(stats) > 0 {
		fmt.Println("-----------------")
		for i, s := range stats {
			fmt.Println(i, s.Id, s.NOrder, s.TotalPrice)
		}
	}
}