Skip to content

Commit c3e946c

Browse files
committed
posthog engagment score
1 parent 42256ce commit c3e946c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/engagement/EngagementScorePersistence.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class EngagementScoreData {
3232
@OptionTag(converter = LocalDateConverter::class)
3333
var lastEventTime: LocalDate? = null
3434

35-
//using string as day and not LocalDate because its it's a bit messy to serialise LocalDate as map keys
35+
//using string as day and not LocalDate because it's a bit messy to serialise LocalDate as map keys
3636
// with this persistence framework.
3737
@get:XMap(keyAttributeName = "day", valueAttributeName = "count")
3838
var meaningfulActionsCounters = mutableMapOf<String, Int>()

ide-common/src/main/kotlin/org/digma/intellij/plugin/engagement/EngagementScoreService.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,20 @@ class EngagementScoreService(private val cs: CoroutineScope) : DisposableAdaptor
6666

6767
private fun sendEvent() {
6868

69+
//compute average that includes up to the last day, exclude today.
70+
val daysForAverage = service<EngagementScorePersistence>().state.meaningfulActionsCounters.filter {
71+
LocalDate.parse(it.key) != today()
72+
}
73+
74+
if (daysForAverage.isEmpty()){
75+
return
76+
}
6977

70-
val activeDays = service<EngagementScorePersistence>().state.meaningfulActionsCounters.size
71-
val average = service<EngagementScorePersistence>().state.meaningfulActionsCounters.values.average().roundToLong()
78+
79+
val activeDays = daysForAverage.size
80+
val average = daysForAverage.values.average().let {
81+
if (it.isNaN()) 0 else it.roundToLong()
82+
}
7283

7384
//todo: when ActivityMonitor is changed to application service this coroutine can be removed and just send the event
7485
//this is just a technical debt that we have:
@@ -91,7 +102,7 @@ class EngagementScoreService(private val cs: CoroutineScope) : DisposableAdaptor
91102

92103
project?.let {
93104

94-
//update last event time only if really send the event
105+
//update last event time only if really sent the event
95106
service<EngagementScorePersistence>().state.lastEventTime = today()
96107

97108
ActivityMonitor.getInstance(it).registerCustomEvent(

0 commit comments

Comments
 (0)