Пример #1
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)
}
Пример #2
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
}
Пример #3
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)
}