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

Fix bugs #98

Merged
merged 5 commits into from
Feb 15, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import kotlinx.serialization.Serializable
* @param type The log type. By default, it is set to "default".
*/
@Serializable
data class Log(val logPaths: List<String>, val type: String = "default")
data class Log(val logPaths: List<String>, val isInPluginDirectory: Boolean = false, val type: String = "default")
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package org.jetbrains.research.tasktracker.requests
import com.intellij.openapi.diagnostic.Logger
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.request.forms.*
import io.ktor.client.statement.*
import io.ktor.http.*
import org.apache.http.client.utils.URIBuilder
import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig.Companion.getRoute
Expand All @@ -15,6 +15,7 @@ object FileRequests {

private val client = HttpClient(CIO)
private val logger: Logger = Logger.getInstance(FileRequests::class.java)
private const val TIMEOUT: Long = 15_000 // 15 seconds

@Suppress("TooGenericExceptionCaught")
suspend fun sendFile(file: File, logFileType: String): Boolean {
Expand All @@ -35,6 +36,11 @@ object FileRequests {
)
}
)
},
block = {
timeout {
requestTimeoutMillis = TIMEOUT
}
}
)
return response.status.isSuccess()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package org.jetbrains.research.tasktracker.tracking

import com.intellij.openapi.application.PathManager
import org.jetbrains.research.tasktracker.config.content.Log
import java.io.File
import java.nio.file.Path
import kotlin.io.path.Path

class ExternalLogger(private val root: Path, private val log: Log) : Loggable() {
class ExternalLogger(private val projectRoot: Path, private val log: Log) : Loggable() {
override val logFileType: String = log.type

override fun getLogFiles(): List<File> = log.logPaths.map {
val root: Path = if (log.isInPluginDirectory) {
Path(PathManager.getPluginsPath())
} else {
projectRoot
}
root.resolve(it).toFile()
}.filter { it.exists() }
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.jetbrains.research.tasktracker.tracking

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorTracker
Expand Down Expand Up @@ -52,17 +53,15 @@ class TrackingService : Disposable {
trackers.forEach {
it.stopTracking()
}
ApplicationManager.getApplication().invokeAndWait {
runBlocking {
val result = trackers.all {
it.send()
}.and(
logs.all { it.send() }
)
trackers.clear()
logs.clear()
if (result) success.invoke() else failure.invoke()
}
CoroutineScope(Dispatchers.IO).launch {
val result = trackers.all {
it.send()
}.and(
logs.all { it.send() }
)
trackers.clear()
logs.clear()
if (result) success.invoke() else failure.invoke()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package org.jetbrains.research.tasktracker.tracking.logger
import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorAction
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorData
import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage
import org.joda.time.DateTime

class FileEditorLogger(project: Project) : BaseLogger() {
override val logPrinterFilename: String = "file_editor_${project.hashCode()}_${project.name}"
override val logPrinterFilename: String =
"file_editor_${project.hashCode()}_${project.name}_${GlobalPluginStorage.currentResearchId}"
override val loggedData: LoggedData<*, *>
get() = FileEditorLoggedData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package org.jetbrains.research.tasktracker.tracking.logger
import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowAction
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowData
import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage
import org.joda.time.DateTime

class ToolWindowLogger(val project: Project) : BaseLogger() {
override val logPrinterFilename: String = "tool_window_${project.hashCode()}_${project.name}"
override val logPrinterFilename: String =
"tool_window_${project.hashCode()}_${project.name}_${GlobalPluginStorage.currentResearchId}"
override val loggedData: LoggedData<*, *>
get() = ToolWindowLoggedData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.jetbrains.research.tasktracker.ui.main.panel.template.WebcamChoicePag
import org.jetbrains.research.tasktracker.util.UIBundle
import java.awt.BorderLayout
import java.awt.FlowLayout
import java.awt.event.ActionListener

/**
* The class is intended to manage JCEF and Swing components simultaneously,
Expand Down Expand Up @@ -177,7 +176,7 @@ class MainPluginPanelFactory : ToolWindowFactory {

fun openExternalUrl(url: String) = mainWindow.openExternalUrl(url)

fun setNextAction(listener: ActionListener) = nextButton.setListener(listener)
fun setNextAction(listener: () -> Unit = {}) = nextButton.setListener(listener)

fun setBackAction(listener: ActionListener) = backButton.setListener(listener)
fun setBackAction(listener: () -> Unit = {}) = backButton.setListener(listener)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig
import org.jetbrains.research.tasktracker.ui.main.panel.models.ButtonState
import org.jetbrains.research.tasktracker.ui.main.panel.models.LinkType
import org.jetbrains.research.tasktracker.util.UIBundle
import java.awt.event.ActionListener
import java.io.File
import javax.swing.JButton

Expand Down Expand Up @@ -55,20 +54,22 @@ fun MainPluginWindow.jslinkProcess(type: LinkType, action: (param: String) -> Un
* Creates new JButton state and return previous JButton state.
*/
fun JButton.changeState(buttonState: ButtonState) {
buttonState.actionListener?.let {
setListener(buttonState.actionListener)
}
addActionListener(buttonState.actionListener)
this.text = buttonState.text
isVisible = buttonState.isVisibleProp
}

fun JButton.getState(): ButtonState = ButtonState(text, isVisible, actionListeners.firstOrNull())

fun JButton.setListener(listener: ActionListener) {
fun JButton.setListener(listener: () -> Unit = {}) {
actionListeners.forEach {
removeActionListener(it)
}
addActionListener(listener)
addActionListener {
isEnabled = false
listener.invoke()
isEnabled = true
}
}

/**
Expand All @@ -82,7 +83,7 @@ fun saveAgreements(agreementString: String) {
agreementFile.writeText(agreementString)
}

fun<T> Promise<T>.runOnSuccess(task: (response: T) -> Unit) =
fun <T> Promise<T>.runOnSuccess(task: (response: T) -> Unit) =
onSuccess {
ApplicationManager.getApplication().invokeLater {
task(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typealias Panel = MainPluginPanelFactory
* A page for collecting user data, and checkboxes for user agreement acceptance.
*/
fun Panel.agreementAcceptance() {
GlobalPluginStorage.resetSession()
loadBasePage(AgreementTemplate.loadCurrentTemplate(), "ui.button.next", false)
setNextAction {
checkAgreementInputs().runOnSuccess {
Expand Down Expand Up @@ -129,12 +130,15 @@ fun Panel.survey(id: String) {

fun Panel.serverErrorPage() {
loadBasePage(ServerErrorPage(), "ui.button.welcome", false)
setNextAction {
agreementAcceptance()
}
}

fun Panel.finalPage() {
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome", false)
setNextAction {
welcomePage()
agreementAcceptance()
}
}

Expand Down Expand Up @@ -174,7 +178,7 @@ fun Panel.processScenario() {
null -> {
scenario.reset()
loadBasePage(LoadTemplate())
GlobalScope.launch {
ApplicationManager.getApplication().invokeLater {
trackingService.stopTracking(::finalPage, ::serverErrorPage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ object GlobalPluginStorage {
var agreementChecker: AgreementChecker? = null
var userId: Int? = null
var currentResearchId: Int? = null

fun resetSession() {
userId = null
currentResearchId = null
agreementChecker = null
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pluginName: Refactoring course
pluginDescription: "We want to track your progress through the code refactoring course in order to collect data on file changes during the course completion. Please, when you are ready, press the next button."
researchId: "RefactoringCourse"
pluginName: "Kotlin Introduction"
pluginDescription: "We want to track your progress through the kotlin introduction course in order to collect data on file changes during the course completion. Please, when you are ready, press the next button."
researchId: "Kotlin Introduction"
logs:
- logPaths:
- "eduAssistant.log"
type: "ai"
- "edu-assistant/eduAssistant.log"
type: "assistant"
isInPluginDirectory: true
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tasks:
- description: description
- description: "Take the kotlin introduction course, and after that, press the next button."
files:
- extension: KOTLIN
filename: Main
Expand Down Expand Up @@ -57,4 +57,4 @@ tasks:
relativePath: WarmUp/task/src/main/kotlin/jetbrains/kotlin/course/warmup
sourceSet: SRC
id: main
name: example
name: "Kotlin Introduction"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.createDirectories

private const val FILE_DIRECTORY = "/tmp/files/"
private const val FILE_DIRECTORY = "/data/tt-files/"

suspend inline fun PipelineContext<Unit, ApplicationCall>.createLogFile(
logFileType: String,
Expand Down
Loading