本文整理匯總了Golang中github.com/coduno/api/model.Result.Skills方法的典型用法代碼示例。如果您正苦於以下問題:Golang Result.Skills方法的具體用法?Golang Result.Skills怎麽用?Golang Result.Skills使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coduno/api/model.Result
的用法示例。
在下文中一共展示了Result.Skills方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
RegisterResulter(Average, func(ctx context.Context, resultKey *datastore.Key) error {
var result model.Result
if err := datastore.Get(ctx, resultKey, &result); err != nil {
return err
}
var challenge model.Challenge
if err := datastore.Get(ctx, result.Challenge, &challenge); err != nil {
return err
}
var tasks model.Tasks
if err := datastore.GetMulti(ctx, challenge.Tasks, &tasks); err != nil {
return err
}
weightSum := model.Skills{} // this could be SkillWeights, but would need more conversions
average := model.Skills{}
for i, task := range tasks {
taskResult, err := Tasker(task.Tasker).Call(ctx, challenge.Tasks[i], resultKey.Parent().Parent())
if err != nil {
return err
}
average = average.Add(taskResult.Mul(model.Skills(task.SkillWeights)))
weightSum = weightSum.Add(model.Skills(task.SkillWeights))
}
result.Skills = average.Div(weightSum)
result.Computed = time.Now()
_, err := result.Put(ctx, resultKey)
return err
})
}