func insertAndAssociateNodeToParent(node *model.Node, parent model.Node) { db := persistence.GetDatabase().DbMap() node.ParentId = parent.Id parent.ChildrenCount++ db.Update(&parent) db.Insert(&node) }
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) }
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 }
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) } }
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) } }