Ejemplo n.º 1
0
func insertAndAssociateNodeToParent(node *model.Node, parent model.Node) {
	db := persistence.GetDatabase().DbMap()
	node.ParentId = parent.Id
	parent.ChildrenCount++
	db.Update(&parent)
	db.Insert(&node)
}
Ejemplo n.º 2
0
func UpdateFeedback(node model.Node, feedback float64) {
	db := persistence.GetDatabase().DbMap()
	avg := node.LocalFeedbackAverage
	fc := node.FeedbackCount
	newAvg := computeNewAverage(avg, float64(fc), feedback)
	node.LocalFeedbackAverage = newAvg
	node.FeedbackCount = fc + 1
	db.Update(&node)
}
Ejemplo n.º 3
0
func FindOrCreateNode(name string, parent model.Node) model.Node {
	db := persistence.GetDatabase().DbMap()
	node := model.Node{}
	db.SelectOne(&node, "select * from nodes where Name=? and ParentId=?", name, parent.Id)
	if node.Id == 0 {
		node.Name = name
		insertAndAssociateNodeToParent(&node, parent)
	}
	return node
}
Ejemplo n.º 4
0
func updateRequestForNodeChain(nodes []model.Node) {
	db := persistence.GetDatabase().DbMap()
	n := len(nodes)
	for _, node := range nodes {
		if n--; n > 0 {
			node.ThroughRequestCount++
		} else {
			node.RequestCount++
		}
		db.Update(&node)
	}
}
Ejemplo n.º 5
0
func propagateFeedback(nodes []model.Node) {
	db := persistence.GetDatabase().DbMap()
	if len(nodes) <= 2 {
		return
	}
	for i := len(nodes) - 2; i >= 0; i-- {

	}
	for _, node := range nodes {
		node.RequestCount++
		db.Update(&node)
	}
}