From d7fef2f2252ec4d9433b776eeda7f43ce4e0dc3c Mon Sep 17 00:00:00 2001 From: "Svetlana.Zemlyanskaya" Date: Thu, 7 May 2020 13:52:45 +0200 Subject: [PATCH] LAB-29: don't report history position for new files GitOrigin-RevId: 7f563a9fbda277ea65d2b13e9ac4c3a460479391 --- .../intellij/filePrediction/history/FileHistoryManager.kt | 4 ++-- .../filePrediction/history/FilePredictionHistoryFeatures.kt | 4 +++- .../filePrediction/features/FilePredictionFeaturesTest.kt | 1 - .../features/history/FilePredictionHistoryFeaturesTest.kt | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/filePrediction/src/com/intellij/filePrediction/history/FileHistoryManager.kt b/plugins/filePrediction/src/com/intellij/filePrediction/history/FileHistoryManager.kt index 5d6df3df82c7..c10add89fab8 100644 --- a/plugins/filePrediction/src/com/intellij/filePrediction/history/FileHistoryManager.kt +++ b/plugins/filePrediction/src/com/intellij/filePrediction/history/FileHistoryManager.kt @@ -1,6 +1,6 @@ package com.intellij.filePrediction.history -data class FileHistoryFeatures(val position: Int, val uniGram: NextFileProbability, val biGram: NextFileProbability) +data class FileHistoryFeatures(val position: Int?, val uniGram: NextFileProbability, val biGram: NextFileProbability) data class NextFileProbability( val mle: Double, val minMle: Double, val maxMle: Double, val mleToMin: Double, val mleToMax: Double @@ -67,7 +67,7 @@ class FileHistoryManager(private var state: FilePredictionHistoryState, private val fileWasPreviouslyOpened = index in 0 until size val entry = if (fileWasPreviouslyOpened) state.recentFiles[index] else null - val position = if (fileWasPreviouslyOpened) size - index - 1 else -1 + val position = if (fileWasPreviouslyOpened) size - index - 1 else null val uniGram = helper.calculateUniGramProb(state.root, entry?.code) val biGram = helper.calculateBiGramProb(state.root, entry?.code, state.prevFile) return FileHistoryFeatures(position, uniGram, biGram) diff --git a/plugins/filePrediction/src/com/intellij/filePrediction/history/FilePredictionHistoryFeatures.kt b/plugins/filePrediction/src/com/intellij/filePrediction/history/FilePredictionHistoryFeatures.kt index 87434d09bce0..756e5b57777f 100644 --- a/plugins/filePrediction/src/com/intellij/filePrediction/history/FilePredictionHistoryFeatures.kt +++ b/plugins/filePrediction/src/com/intellij/filePrediction/history/FilePredictionHistoryFeatures.kt @@ -16,7 +16,9 @@ internal class FilePredictionHistoryFeatures: FilePredictionFeatureProvider { result["size"] = numerical(history.size()) val (position, uniGram, biGram) = history.calcHistoryFeatures(newFile.url) - result["position"] = numerical(position) + if (position != null) { + result["position"] = numerical(position) + } addNGramFeatures(uniGram, "uni", result) addNGramFeatures(biGram, "bi", result) return result diff --git a/plugins/filePrediction/test/com/intellij/filePrediction/features/FilePredictionFeaturesTest.kt b/plugins/filePrediction/test/com/intellij/filePrediction/features/FilePredictionFeaturesTest.kt index eaba0abdfa5e..cd6702ae5f17 100644 --- a/plugins/filePrediction/test/com/intellij/filePrediction/features/FilePredictionFeaturesTest.kt +++ b/plugins/filePrediction/test/com/intellij/filePrediction/features/FilePredictionFeaturesTest.kt @@ -40,7 +40,6 @@ class FilePredictionFeaturesTest : CodeInsightFixtureTestCase, size: Int, vararg expected: Pair) { + private fun doTest(openedFiles: List, size: Int, vararg expected: Pair) { doTestInternal(openedFiles, size, 5) { manager -> expected.forEach { assertEquals(it.second, manager.calcHistoryFeatures(it.first).position) } } @@ -25,11 +25,11 @@ class FilePredictionHistoryFeaturesTest : FilePredictionHistoryBaseTest() { } fun `test position of the file without history`() { - doTest(listOf(), 0, "file://a" to -1) + doTest(listOf(), 0, "file://a" to null) } fun `test position of the new file`() { - doTest(listOf("file://a"), 1, "file://b" to -1) + doTest(listOf("file://a"), 1, "file://b" to null) } fun `test position of the prev file`() {