File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
ide-common/src/main/kotlin/org/digma/intellij/plugin/engagement Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff 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 >()
Original file line number Diff line number Diff 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(
You can’t perform that action at this time.
0 commit comments