[PyCharm Tables] PY-75715 FUS collector for "evaluate expression" and formatting in the new data view #PY-75715 Fixed

* Added logging split to track if slicing or formatting was applied
* Introduced a field to indicate whether the table is new or legacy

GitOrigin-RevId: 9cfec94b7b3ef83f5134eea4287f8abfe347f702
This commit is contained in:
Natalia.Murycheva
2024-09-10 12:02:09 +02:00
committed by intellij-monorepo-bot
parent 4a0aa4b0e1
commit 1b02aac09f
4 changed files with 45 additions and 18 deletions

View File

@@ -31,7 +31,7 @@ public class PyDataViewDialog extends DialogWrapper {
myMainPanel = new JPanel(new GridBagLayout());
myDataViewerPanel = new PyDataViewerPanel(project, value.getFrameAccessor());
myDataViewerPanel.apply(value, false);
myDataViewerPanel.apply(value, false, /* commandSource = */ null);
myDataViewerPanel.setPreferredSize(JBUI.size(TABLE_DEFAULT_WIDTH, TABLE_DEFAULT_HEIGHT));
myMainPanel.add(myDataViewerPanel, createDataViewPanelConstraints());

View File

@@ -23,7 +23,6 @@ import com.jetbrains.python.debugger.*
import com.jetbrains.python.debugger.array.AbstractDataViewTable
import com.jetbrains.python.debugger.array.AsyncArrayTableModel
import com.jetbrains.python.debugger.array.JBTableWithRowHeaders
import com.jetbrains.python.debugger.statistics.PyDataViewerCollector
import java.awt.BorderLayout
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
@@ -35,13 +34,13 @@ import javax.swing.JPanel
open class PyDataViewerPanel(@JvmField protected val project: Project, val frameAccessor: PyFrameAccessor) :
JPanel(BorderLayout()), Disposable {
val sliceTextField: EditorTextField = createEditorField()
val sliceTextField: EditorTextField = createEditorField(TextFieldCommandSource.SLICING)
protected val tablePanel = JPanel(BorderLayout())
protected var table: AbstractDataViewTable? = null
private var formatTextField: EditorTextField = createEditorField()
private var formatTextField: EditorTextField = createEditorField(TextFieldCommandSource.FORMATTING)
private var colored: Boolean = PyDataView.isColoringEnabled(project)
@@ -160,7 +159,7 @@ open class PyDataViewerPanel(@JvmField protected val project: Project, val frame
return mainTable
}
private fun createEditorField(): EditorTextField {
private fun createEditorField(commandSource: TextFieldCommandSource): EditorTextField {
return object : EditorTextField(EditorFactory.getInstance().createDocument(""), project, PythonFileType.INSTANCE, false, true) {
override fun createEditor(): EditorEx {
val editor = super.createEditor()
@@ -168,7 +167,7 @@ open class PyDataViewerPanel(@JvmField protected val project: Project, val frame
editor.getContentComponent().addKeyListener(object : KeyAdapter() {
override fun keyPressed(e: KeyEvent) {
if (e.keyCode == KeyEvent.VK_ENTER) {
apply(sliceTextField.getText(), false)
apply(sliceTextField.getText(), false, commandSource)
}
}
})
@@ -177,18 +176,14 @@ open class PyDataViewerPanel(@JvmField protected val project: Project, val frame
}
}
fun apply(name: String?, modifier: Boolean) {
fun apply(name: String?, modifier: Boolean, commandSource: TextFieldCommandSource? = null) {
ApplicationManager.getApplication().executeOnPooledThread {
val debugValue = getDebugValue(name, true, modifier)
ApplicationManager.getApplication().invokeLater { debugValue?.let { apply(it, modifier) } }
}
if (!modifier) {
PyDataViewerCollector.SLICING_APPLIED_EVENT.log()
ApplicationManager.getApplication().invokeLater { debugValue?.let { apply(it, modifier, commandSource) } }
}
}
open fun apply(debugValue: PyDebugValue, modifier: Boolean) {
open fun apply(debugValue: PyDebugValue, modifier: Boolean, commandSource: TextFieldCommandSource? = null) {
errorLabel.visible(false)
val type = debugValue.type
val strategy = DataViewStrategy.getStrategy(type)

View File

@@ -0,0 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.debugger.containerview
enum class TextFieldCommandSource {
SLICING,
FORMATTING
}

View File

@@ -9,15 +9,24 @@ import com.intellij.openapi.project.Project
object PyDataViewerCollector : CounterUsagesCollector() {
private val GROUP = EventLogGroup("python.dataview", 3)
private val GROUP = EventLogGroup("python.dataview", 4)
/* Fields */
private val DATA_TYPE_FIELD = EventFields.Enum<DataType>("type")
private val DIMENSIONS_FIELD = EventFields.Enum<DataDimensions>("dimensions")
private val ROWS_COUNT_FIELD = RoundedIntEventField("rows_count")
private val COLUMNS_COUNT_FIELD = RoundedIntEventField("columns_count")
private val IS_NEW_TABLE_FIELD = EventFields.Boolean("is_new_table")
private val DATA_OPENED_EVENT = GROUP.registerVarargEvent("data.opened", DATA_TYPE_FIELD, DIMENSIONS_FIELD, ROWS_COUNT_FIELD, COLUMNS_COUNT_FIELD)
val SLICING_APPLIED_EVENT = GROUP.registerEvent("slicing.applied")
/* Events */
private val DATA_OPENED_EVENT = GROUP.registerVarargEvent("data.opened",
DATA_TYPE_FIELD,
DIMENSIONS_FIELD,
ROWS_COUNT_FIELD,
COLUMNS_COUNT_FIELD,
IS_NEW_TABLE_FIELD)
val SLICING_APPLIED_EVENT = GROUP.registerEvent("slicing.applied", IS_NEW_TABLE_FIELD)
val FORMATTING_APPLIED_EVENT = GROUP.registerEvent("formatting.applied", IS_NEW_TABLE_FIELD)
enum class DataType(private val typeName: String?) {
ARRAY("ndarray"),
@@ -61,11 +70,27 @@ object PyDataViewerCollector : CounterUsagesCollector() {
override fun getGroup() = GROUP
fun logDataOpened(project: Project?, type: String?, dimensions: Int?, rowsCount: Int, columnsCount: Int) {
fun logDataOpened(
project: Project?,
type: String?,
dimensions: Int?,
rowsCount: Int,
columnsCount: Int,
isNewTable: Boolean,
) {
DATA_OPENED_EVENT.log(project,
DATA_TYPE_FIELD.with(DataType.getDataType(type)),
DIMENSIONS_FIELD.with(DataDimensions.getDataDimensions(dimensions)),
ROWS_COUNT_FIELD.with(rowsCount),
COLUMNS_COUNT_FIELD.with(columnsCount))
COLUMNS_COUNT_FIELD.with(columnsCount),
IS_NEW_TABLE_FIELD.with(isNewTable))
}
fun logDataSlicingApplied(isNewTable: Boolean) {
SLICING_APPLIED_EVENT.log(isNewTable)
}
fun logDataFormattingApplied(isNewTable: Boolean) {
FORMATTING_APPLIED_EVENT.log(isNewTable)
}
}