示例#1
0
func (g *Guest) GetValue() float32 {

	var sum float32
	var totalWeight float32

	getPrice := func(o interface{}) interface{} {
		return o.(*Offer).Price
	}

	var boughtOffers offerSlice = lastOffers(g.boughtOffers, cognitiveLoad)
	var avgBought, boughtErr = util.Avg(util.Map(getPrice, boughtOffers))
	if boughtErr == nil {
		sum += avgBought * boughtWeight
		totalWeight += boughtWeight
	}

	var seenOffers offerSlice = lastOffers(g.seenOffers, cognitiveLoad)
	var avgSeen, seenErr = util.Avg(util.Map(getPrice, seenOffers))
	if seenErr == nil {
		sum += avgSeen * seenWeight
		totalWeight += seenWeight
	}

	{
		sum += g.value * valueWeight
		totalWeight += valueWeight
	}

	return sum / totalWeight
}
示例#2
0
func (g *Guest) getPreferredPlatform() *Platform {

	getPlatform := func(o interface{}) interface{} {
		return o.(*Offer).Platform
	}
	var offers offerSlice = lastOffers(g.boughtOffers, cognitiveLoad)
	platforms := util.Map(getPlatform, offers)

	platform, count := util.MaxOccur(platforms)

	if count <= cognitiveLoad/5 {
		return nil
	}
	return platform.(*Platform)
}
示例#3
0
func (g *Guest) getPreferredHotel() *Hotel {

	getHotel := func(o interface{}) interface{} {
		return o.(*Offer).Hotel
	}
	var offers offerSlice = lastOffers(g.boughtOffers, cognitiveLoad)
	hotels := util.Map(getHotel, offers)

	hotel, count := util.MaxOccur(hotels)

	if count <= cognitiveLoad/5 {
		return nil
	}
	return hotel.(*Hotel)
}