Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collectors #80

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ tasks {
systemProperty("jb.consents.confirmation.enabled", "false")
systemProperty("ide.mac.file.chooser.native", "false")
systemProperty("apple.laf.useScreenMenuBar", "false")
// VM options to include FUS collector
jvmArgs("-Dfus.internal.test.mode=true")
jvmArgs("-Didea.is.internal=true")
}

signPlugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.testspark.collectors

class CollectorsHelper {

val sessionIDRegex = """^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$""".toRegex()
val testIDRegex =
"""^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}_[0-9]{1,2}$""".toRegex()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector

class CoverageStatusShowedCollector : CounterUsagesCollector() {
private val groupId = "tests.coverage"
private val group = EventLogGroup(groupId, 1)

private val eventId = "coverage.status.showed"
private val sessionId = EventFields.StringValidatedByRegexp("id", CollectorsHelper().sessionIDRegex.pattern)

private val event = group.registerEvent(eventId, sessionId)

override fun getGroup() = group

fun logEvent(sessionId: String) {
event.log(sessionId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EnumEventField
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.eventLog.events.EventPair
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
import org.jetbrains.research.testspark.data.CodeType
import org.jetbrains.research.testspark.data.Technique

class FeedbackSentCollector : CounterUsagesCollector() {
private val groupId = "individual.tests"
private val group = EventLogGroup(groupId, 1)
private val eventId = "feedback.sent"
private val testId = EventFields.StringValidatedByRegexp("id", CollectorsHelper().testIDRegex.pattern)
private val technique: EnumEventField<Technique> = EventFields.Enum("technique", Technique::class.java)
private val level: EnumEventField<CodeType> = EventFields.Enum("level", CodeType::class.java)
private val isModified = EventFields.Boolean("is_modified")

private val event = group.registerVarargEvent(
eventId,
testId,
technique,
level,
isModified,
)

override fun getGroup() = group

fun logEvent(testId: String, technique: Technique, level: CodeType, isModified: Boolean) {
val data: List<EventPair<*>> = arrayListOf(
this.testId.with(testId),
this.technique.with(technique),
this.level.with(level),
this.isModified.with(isModified),
)
event.log(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EnumEventField
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.eventLog.events.IntEventField
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
import org.jetbrains.research.testspark.data.CodeType
import org.jetbrains.research.testspark.data.Technique

class GeneratedTestsCollector : CounterUsagesCollector() {
private val groupId = "tests.set"
private val group = EventLogGroup(groupId, 1)

private val eventId = "generated.tests"
private val count: IntEventField = IntEventField("count")
private val technique: EnumEventField<Technique> = EventFields.Enum("technique", Technique::class.java)
private val level: EnumEventField<CodeType> = EventFields.Enum("level", CodeType::class.java)

private val event = group.registerEvent(eventId, count, technique, level)

override fun getGroup() = group

fun logEvent(count: Int, technique: Technique, level: CodeType) {
event.log(count, technique, level)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EnumEventField
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.eventLog.events.EventPair
import com.intellij.internal.statistic.eventLog.events.IntEventField
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
import org.jetbrains.research.testspark.data.CodeType
import org.jetbrains.research.testspark.data.Technique

class IntegratedTestsCollector : CounterUsagesCollector() {
private val groupId = "tests.set"
private val group = EventLogGroup(groupId, 1)

private val eventId = "integrated.tests"
private val count: IntEventField = IntEventField("count")
private val technique: EnumEventField<Technique> = EventFields.Enum("technique", Technique::class.java)
private val level: EnumEventField<CodeType> = EventFields.Enum("level", CodeType::class.java)
private val modifiedTestsCount: IntEventField = IntEventField("modifiedTestsCount")

private val event = group.registerVarargEvent(eventId, count, technique, level, modifiedTestsCount)

override fun getGroup() = group

fun logEvent(count: Int, technique: Technique, level: CodeType, modifiedTestsCount: Int) {
val data: List<EventPair<*>> = arrayListOf(
this.count.with(count),
this.technique.with(technique),
this.level.with(level),
this.modifiedTestsCount.with(modifiedTestsCount),
)
event.log(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EnumEventField
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.eventLog.events.EventPair
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
import org.jetbrains.research.testspark.data.CodeType
import org.jetbrains.research.testspark.data.Technique

class LikedDislikedCollector : CounterUsagesCollector() {
private val groupId = "individual.tests"
private val group = EventLogGroup(groupId, 1)

private val eventId = "liked.disliked"
private val liked = EventFields.Boolean("liked")
private val testId = EventFields.StringValidatedByRegexp("id", CollectorsHelper().testIDRegex.pattern)
private val technique: EnumEventField<Technique> = EventFields.Enum("technique", Technique::class.java)
private val level: EnumEventField<CodeType> = EventFields.Enum("level", CodeType::class.java)
private val isModified = EventFields.Boolean("is_modified")

private val event = group.registerVarargEvent(
eventId,
liked,
testId,
technique,
level,
isModified,
)

override fun getGroup() = group

fun logEvent(liked: Boolean, testId: String, technique: Technique, level: CodeType, isModified: Boolean) {
val data: List<EventPair<*>> = arrayListOf(
this.liked.with(liked),
this.testId.with(testId),
this.technique.with(technique),
this.level.with(level),
this.isModified.with(isModified),
)
event.log(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EnumEventField
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.eventLog.events.LongEventField
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
import org.jetbrains.research.testspark.data.CodeType
import org.jetbrains.research.testspark.data.Technique

class TestGenerationFinishedCollector : CounterUsagesCollector() {
private val groupId = "tests.set"
private val group = EventLogGroup(groupId, 1)

private val eventId = "test.generation.finished"
private val durationMs: LongEventField = LongEventField("durationMs")
private val technique: EnumEventField<Technique> = EventFields.Enum("technique", Technique::class.java)
private val level: EnumEventField<CodeType> = EventFields.Enum("level", CodeType::class.java)

private val event = group.registerEvent(eventId, durationMs, technique, level)

override fun getGroup() = group

fun logEvent(durationMs: Long, technique: Technique, level: CodeType) {
event.log(durationMs, technique, level)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jetbrains.research.testspark.collectors

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EnumEventField
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
import org.jetbrains.research.testspark.data.CodeType
import org.jetbrains.research.testspark.data.Technique

class TestGenerationStartedCollector : CounterUsagesCollector() {
private val groupId = "tests.set"
private val group = EventLogGroup(groupId, 1)

private val eventId = "test.generation.started"
private val technique: EnumEventField<Technique> = EventFields.Enum("technique", Technique::class.java)
private val level: EnumEventField<CodeType> = EventFields.Enum("level", CodeType::class.java)

private val event = group.registerEvent(eventId, technique, level)

override fun getGroup() = group

fun logEvent(technique: Technique, level: CodeType) {
event.log(technique, level)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.intellij.ui.components.ActionLink
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBScrollPane
import com.intellij.util.ui.FormBuilder
import org.jetbrains.research.testspark.services.CollectorService
import org.jetbrains.research.testspark.services.SettingsApplicationService
import org.jetbrains.research.testspark.services.TestCaseDisplayService
import java.awt.Color
Expand Down Expand Up @@ -106,6 +107,8 @@ class CoverageRenderer(
false,
HintHint(editor, point),
)

project.service<CollectorService>().coverageStatusShowedCollector.logEvent(project.service<CollectorService>().data.id!!)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.jetbrains.research.testspark.data
/**
* Data about test objects that require test generators.
*/
class FragmentToTestData {
class CodeTypeWrapper {

// Variable which contains all code elements for which it is possible to request test generation.
var type: CodeType? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.testspark.data

class CollectorsData {
var id: String? = null
var testGenerationStartTime: Long? = null
var technique: Technique? = null
var codeType: CodeType? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.testspark.data

/**
* Enum representing different techniques.
*/
enum class Technique {
LLM, EA
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.intellij.util.ui.JBUI
import org.jetbrains.research.testspark.bundles.TestSparkBundle
import org.jetbrains.research.testspark.bundles.TestSparkLabelsBundle
import org.jetbrains.research.testspark.data.TestCase
import org.jetbrains.research.testspark.services.CollectorService
import org.jetbrains.research.testspark.services.ErrorService
import org.jetbrains.research.testspark.services.JavaClassBuilderService
import org.jetbrains.research.testspark.services.LLMChatService
Expand Down Expand Up @@ -162,7 +163,14 @@ class TestCasePanelFactory(
likeButton.icon = TestSparkIcons.likeSelected
}
dislikeButton.icon = TestSparkIcons.dislike
// TODO add implementation

project.service<CollectorService>().likedDislikedCollector.logEvent(
true,
getTestId(),
project.service<CollectorService>().data.technique!!,
project.service<CollectorService>().data.codeType!!,
testCase.testCode != initialCodes[currentRequestNumber - 1],
)
}

dislikeButton.addActionListener {
Expand All @@ -172,7 +180,14 @@ class TestCasePanelFactory(
dislikeButton.icon = TestSparkIcons.dislikeSelected
}
likeButton.icon = TestSparkIcons.like
// TODO add implementation

project.service<CollectorService>().likedDislikedCollector.logEvent(
false,
getTestId(),
project.service<CollectorService>().data.technique!!,
project.service<CollectorService>().data.codeType!!,
testCase.testCode != initialCodes[currentRequestNumber - 1],
)
}

copyButton.addActionListener {
Expand Down Expand Up @@ -401,6 +416,13 @@ class TestCasePanelFactory(
override fun run(indicator: ProgressIndicator) {
if (processStopped(project, indicator)) return

project.service<CollectorService>().feedbackSentCollector.logEvent(
project.service<CollectorService>().data.id!! + "_" + testCase.id,
project.service<CollectorService>().data.technique!!,
project.service<CollectorService>().data.codeType!!,
testCase.testCode != initialCodes[currentRequestNumber - 1],
)

val modifiedTest = project.service<LLMChatService>()
.testModificationRequest(
initialCodes[currentRequestNumber - 1],
Expand Down Expand Up @@ -514,6 +536,8 @@ class TestCasePanelFactory(
}
}

fun isGlobalModified(): Boolean = testCase.testCode != initialCodes[0]

/**
* Resets the language text field to the code from the last test run and updates the UI accordingly.
*/
Expand Down Expand Up @@ -668,6 +692,13 @@ class TestCasePanelFactory(
testCase.testCode = languageTextField.document.text
}

/**
* Retrieves the test ID by concatenating the workspace ID and the test case ID.
*
* @return The test ID as a string.
*/
private fun getTestId(): String = project.service<CollectorService>().data.id!! + "_" + testCase.id

/**
* A custom JTextField with a hint text that is displayed when the field is empty and not in focus.
*/
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jetbrains.research.testspark.services

import com.intellij.openapi.components.Service
import org.jetbrains.research.testspark.collectors.CoverageStatusShowedCollector
import org.jetbrains.research.testspark.collectors.FeedbackSentCollector
import org.jetbrains.research.testspark.collectors.GeneratedTestsCollector
import org.jetbrains.research.testspark.collectors.IntegratedTestsCollector
import org.jetbrains.research.testspark.collectors.LikedDislikedCollector
import org.jetbrains.research.testspark.collectors.TestGenerationFinishedCollector
import org.jetbrains.research.testspark.collectors.TestGenerationStartedCollector
import org.jetbrains.research.testspark.data.CollectorsData

@Service(Service.Level.PROJECT)
class CollectorService {
val feedbackSentCollector = FeedbackSentCollector()
val likedDislikedCollector = LikedDislikedCollector()
val coverageStatusShowedCollector = CoverageStatusShowedCollector()
val testGenerationStartedCollector = TestGenerationStartedCollector()
val testGenerationFinishedCollector = TestGenerationFinishedCollector()
val generatedTestsCollector = GeneratedTestsCollector()
val integratedTestsCollector = IntegratedTestsCollector()

val data: CollectorsData = CollectorsData()
}
Loading
Loading