openreplay/backend/pkg/handlers/ios/tapRage.go
Alexander 45c956c489
Json logs format (#1952)
* feat(backend): try a new approach for logs formatting (http)

* feat(backend): added logger module

* feat(backend): added project/session info to /i endpoint

* feat(backend): found a solution for correct caller information

* feat(backend): finished logs for http handlers

* feat(backend): finished logs for mobile http handlers

* feat(backend): finished ender

* feat(backend): finished assets

* feat(backend): finished heuristics

* feat(backend): finished image-storage

* feat(backend): finished sink

* feat(backend): finished storage

* feat(backend): formatted logs in all services

* feat(backend): finished foss part

* feat(backend): added missed foss part

* feat(backend): fixed panic in memory manager and sink service

* feat(backend): connectors
2024-03-14 12:51:14 +01:00

70 lines
1.5 KiB
Go

package ios
import (
"encoding/json"
"openreplay/backend/pkg/handlers"
. "openreplay/backend/pkg/messages"
)
const TapTimeDiff = 300
const MinTapsInARow = 3
type TapRageDetector struct {
handlers.ReadyMessageStore
lastTimestamp uint64
lastLabel string
firstInARawTimestamp uint64
firstInARawSeqIndex uint64
countsInARow int
}
func (h *TapRageDetector) createPayload() string {
p, err := json.Marshal(struct{ Count int }{h.countsInARow})
if err != nil {
return ""
}
return string(p)
}
func (h *TapRageDetector) Build() Message {
if h.countsInARow >= MinTapsInARow {
event := &IOSIssueEvent{
Type: "tap_rage",
ContextString: h.lastLabel,
Timestamp: h.firstInARawTimestamp,
Payload: h.createPayload(),
}
event.Index = h.firstInARawSeqIndex // Associated Index/ MessageID ?
return event
}
h.lastTimestamp = 0
h.lastLabel = ""
h.firstInARawTimestamp = 0
h.firstInARawSeqIndex = 0
h.countsInARow = 0
return nil
}
func (h *TapRageDetector) Handle(message Message, timestamp uint64) Message {
var event Message = nil
switch m := message.(type) {
case *IOSClickEvent:
if h.lastTimestamp+TapTimeDiff < m.Timestamp && h.lastLabel == m.Label {
h.lastTimestamp = m.Timestamp
h.countsInARow += 1
return nil
}
event = h.Build()
if m.Label != "" {
h.lastTimestamp = m.Timestamp
h.lastLabel = m.Label
h.firstInARawTimestamp = m.Timestamp
h.firstInARawSeqIndex = m.Index
h.countsInARow = 1
}
case *IOSSessionEnd:
event = h.Build()
}
return event
}