mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[stats-collector] minor
This commit is contained in:
+7
-8
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package com.intellij.stats.events.completion
|
||||
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.io.*
|
||||
|
||||
data class EventLine(val event: LogEvent, val line: String)
|
||||
|
||||
@@ -24,11 +23,11 @@ open class SessionsInputSeparator(input: InputStream,
|
||||
output: OutputStream,
|
||||
error: OutputStream) {
|
||||
|
||||
private val inputReader = java.io.BufferedReader(java.io.InputStreamReader(input))
|
||||
private val outputWriter = java.io.BufferedWriter(java.io.OutputStreamWriter(output))
|
||||
private val errorWriter = java.io.BufferedWriter(java.io.OutputStreamWriter(error))
|
||||
private val inputReader = BufferedReader(InputStreamReader(input))
|
||||
private val outputWriter = BufferedWriter(OutputStreamWriter(output))
|
||||
private val errorWriter = BufferedWriter(OutputStreamWriter(error))
|
||||
|
||||
var session = mutableListOf<com.intellij.stats.events.completion.EventLine>()
|
||||
var session = mutableListOf<EventLine>()
|
||||
var currentSessionUid = ""
|
||||
|
||||
fun processInput() {
|
||||
@@ -57,7 +56,7 @@ open class SessionsInputSeparator(input: InputStream,
|
||||
errorWriter.flush()
|
||||
}
|
||||
|
||||
private fun processCompletionSession(session: List<com.intellij.stats.events.completion.EventLine>) {
|
||||
private fun processCompletionSession(session: List<EventLine>) {
|
||||
if (session.isEmpty()) return
|
||||
|
||||
var isValidSession = false
|
||||
@@ -72,7 +71,7 @@ open class SessionsInputSeparator(input: InputStream,
|
||||
onSessionProcessingFinished(session, isValidSession)
|
||||
}
|
||||
|
||||
open protected fun onSessionProcessingFinished(session: List<com.intellij.stats.events.completion.EventLine>, isValidSession: Boolean) {
|
||||
open protected fun onSessionProcessingFinished(session: List<EventLine>, isValidSession: Boolean) {
|
||||
val writer = if (isValidSession) outputWriter else errorWriter
|
||||
session.forEach {
|
||||
writer.write(it.line)
|
||||
|
||||
+6
-7
@@ -19,14 +19,14 @@ import com.google.gson.Gson
|
||||
|
||||
object JsonSerializer {
|
||||
private val gson = Gson()
|
||||
fun toJson(obj: Any) = com.intellij.stats.events.completion.JsonSerializer.gson.toJson(obj)
|
||||
fun <T> fromJson(json: String, clazz: Class<T>) = com.intellij.stats.events.completion.JsonSerializer.gson.fromJson(json, clazz)
|
||||
fun toJson(obj: Any) = gson.toJson(obj)
|
||||
fun <T> fromJson(json: String, clazz: Class<T>) = gson.fromJson(json, clazz)
|
||||
}
|
||||
|
||||
|
||||
object LogEventSerializer {
|
||||
|
||||
val actionClassMap: Map<Action, Class<out LogEvent>> = mapOf(
|
||||
private val actionClassMap: Map<Action, Class<out LogEvent>> = mapOf(
|
||||
Action.COMPLETION_STARTED to CompletionStartedEvent::class.java,
|
||||
Action.TYPE to TypeEvent::class.java,
|
||||
Action.DOWN to DownPressedEvent::class.java,
|
||||
@@ -39,8 +39,7 @@ object LogEventSerializer {
|
||||
)
|
||||
|
||||
fun toString(event: LogEvent): String {
|
||||
return "${event.timestamp}\t${event.recorderId}\t${event.userUid}\t${event.sessionUid}\t${event.actionType}\t${com.intellij.stats.events.completion.JsonSerializer.toJson(
|
||||
event)}"
|
||||
return "${event.timestamp}\t${event.recorderId}\t${event.userUid}\t${event.sessionUid}\t${event.actionType}\t${JsonSerializer.toJson(event)}"
|
||||
}
|
||||
|
||||
fun fromString(line: String): LogEvent? {
|
||||
@@ -60,10 +59,10 @@ object LogEventSerializer {
|
||||
val sessionUid = items[3]
|
||||
val actionType = Action.valueOf(items[4])
|
||||
|
||||
val clazz = com.intellij.stats.events.completion.LogEventSerializer.actionClassMap[actionType] ?: return null
|
||||
val clazz = actionClassMap[actionType] ?: return null
|
||||
|
||||
val json = line.substring(start + 1)
|
||||
val obj = com.intellij.stats.events.completion.JsonSerializer.fromJson(json, clazz)
|
||||
val obj = JsonSerializer.fromJson(json, clazz)
|
||||
|
||||
obj.userUid = userUid
|
||||
obj.timestamp = timestamp
|
||||
|
||||
Reference in New Issue
Block a user