feat(v2): add fall event regression engine
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package fall
|
||||
|
||||
type policy struct {
|
||||
suspectWindowSeconds float64
|
||||
requireRapidDrop bool
|
||||
rapidDropAt map[string]float64
|
||||
}
|
||||
|
||||
func newPolicy(suspectWindowSeconds float64, requireRapidDrop bool) *policy {
|
||||
return &policy{
|
||||
suspectWindowSeconds: suspectWindowSeconds,
|
||||
requireRapidDrop: requireRapidDrop,
|
||||
rapidDropAt: make(map[string]float64),
|
||||
}
|
||||
}
|
||||
|
||||
func (policy *policy) evaluate(trackID string, poseEvidence PoseEvidence, now float64, state State) Evidence {
|
||||
if !poseEvidence.Accepted {
|
||||
delete(policy.rapidDropAt, trackID)
|
||||
return Evidence{}
|
||||
}
|
||||
if poseEvidence.RapidVerticalChange {
|
||||
policy.rapidDropAt[trackID] = now
|
||||
}
|
||||
candidate := false
|
||||
if state == Suspect {
|
||||
candidate = poseEvidence.HorizontalPose
|
||||
} else if poseEvidence.HorizontalPose {
|
||||
if !policy.requireRapidDrop {
|
||||
candidate = true
|
||||
} else if droppedAt, found := policy.rapidDropAt[trackID]; found {
|
||||
candidate = now-droppedAt <= policy.suspectWindowSeconds
|
||||
}
|
||||
}
|
||||
recovery := (state == Confirmed || state == Recovering) && !poseEvidence.HorizontalPose && !poseEvidence.RapidVerticalChange
|
||||
return Evidence{Accepted: true, IsFallCandidate: candidate, IsRecoveryCandidate: recovery}
|
||||
}
|
||||
Reference in New Issue
Block a user