Change signature to compute user factors
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Wed, 29 Nov 2017 13:18:35 +0000 (16:18 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Wed, 29 Nov 2017 13:18:35 +0000 (16:18 +0300)
plugins/stats-collector/log-events/src/main/kotlin/com/intellij/stats/completion/events/CompletionStartedEvent.kt
plugins/stats-collector/src/com/intellij/sorting/MLCompletionSorter.kt
plugins/stats-collector/src/com/intellij/sorting/MLSorter.kt
plugins/stats-collector/src/com/intellij/stats/completion/CompletionTrackerInitializer.kt
plugins/stats-collector/src/com/intellij/stats/personalization/UserFactor.kt
plugins/stats-collector/src/com/intellij/stats/personalization/UserFactorsManager.kt

index faf1a4f0a5538bee3c700b98f74b0e0a70e47c0b..8df293d4d29b525a86bd1fc5cb658b87e851eae5 100644 (file)
@@ -31,7 +31,7 @@ class CompletionStartedEvent(
         @JvmField var performExperiment: Boolean,
         @JvmField var experimentVersion: Int,
         completionList: List<LookupEntryInfo>,
-        @JvmField var userFactors: Map<String, String>,
+        @JvmField var userFactors: Map<String, String?>,
         selectedPosition: Int)
 
     : LookupStateLogData(
index 776a68f3c930769720ae6009963d2c211d954b5a..43ac3f20b9b8266801f782238429654bf49653ae 100644 (file)
@@ -36,7 +36,7 @@ interface Ranker {
      * @param state
      * @param relevance map from LookupArranger.getRelevanceObjects
      */
-    fun rank(state: LookupElementInfo, relevance: Map<String, Any?>, userFactors: Map<String, Any>): Double?
+    fun rank(state: LookupElementInfo, relevance: Map<String, Any?>, userFactors: Map<String, Any?>): Double?
 
     companion object {
         fun getInstance(): Ranker = ServiceManager.getService(Ranker::class.java)
@@ -76,7 +76,7 @@ class MLRanker(val provider: FeatureTransformerProvider): Ranker {
     private val featureTransformer = provider.featureTransformer
     private val ranker = CompletionRanker()
     
-    override fun rank(state: LookupElementInfo, relevance: Map<String, Any?>, userFactors: Map<String, Any>): Double? {
+    override fun rank(state: LookupElementInfo, relevance: Map<String, Any?>, userFactors: Map<String, Any?>): Double? {
         val featureArray = featureTransformer.featureArray(state, relevance, userFactors)
         if (featureArray != null) {
             return ranker.rank(featureArray)
index 17a0742f0466b581147f77edc6d2254bb0ce33b2..473b8ef98aa937c382e709608750c13f13bd3c8b 100644 (file)
@@ -124,7 +124,9 @@ class MLSorter : CompletionFinalSorter() {
                                 relevanceObjects: Map<LookupElement, List<Pair<String, Any?>>>): Iterable<LookupElement>?
     {
         val prefixLength = lookup.prefixLength()
-        val userFactors = UserFactorsManager.getInstance(lookup.project).getAllFactors().associate { it.id to it.compute() }
+        val userFactors = UserFactorsManager.getInstance(lookup.project)
+                .getAllFactors()
+                .associate { it.id to it.compute(lookup.project) }
         return items
                 .mapIndexed { index, lookupElement ->
                     val relevance = relevanceObjects[lookupElement] ?: emptyList()
@@ -147,7 +149,7 @@ class MLSorter : CompletionFinalSorter() {
     private fun calculateElementRank(element: LookupElement,
                                      position: Int,
                                      relevance: List<Pair<String, Any?>>,
-                                     userFactors: Map<String, Any>,
+                                     userFactors: Map<String, Any?>,
                                      prefixLength: Int): Double? 
     {
         val cachedWeight = getCachedRankInfo(element, prefixLength, position)
index d93163b83f90fd022e795890ae308de6e112ac25..57d772632d3b3e350ddf779fff6fce0d29a0b796 100644 (file)
@@ -47,7 +47,7 @@ class CompletionTrackerInitializer(experimentHelper: WebServiceStatus): Applicat
             if (isUnitTestMode() && !isEnabledInTests) return@PropertyChangeListener
 
             val userFactors = UserFactorsManager.getInstance(lookup.project).getAllFactors()
-                    .associate { it.id to it.compute() }
+                    .associate { it.id to it.compute(lookup.project) }
             lookup.putUserData(UserFactorsManager.USER_FACTORS_KEY, userFactors)
             val shownTimesTracker = PositionTrackingListener(lookup)
             lookup.setPrefixChangeListener(shownTimesTracker)
index e00ea4d541c1efae0034407b7515da7be18a46ca..bca14af4218eb224e86a9a5966c8b74c1fd69a5a 100644 (file)
@@ -1,12 +1,14 @@
 package com.intellij.stats.personalization
 
+import com.intellij.openapi.project.Project
+
 /**
  * @author Vitaliy.Bibaev
  */
 interface UserFactor {
     val id: String
 
-    fun compute(): String
+    fun compute(project: Project): String?
 
     interface FeatureFactor : UserFactor {
         fun update(value: Any?)
index ce38300bee7b2af0ca5d306adcda79d380dbc2c8..6b331cc02d8980411c03a98a2030ea0788571b74 100644 (file)
@@ -8,7 +8,7 @@ import com.intellij.openapi.util.Key
  */
 interface UserFactorsManager {
   companion object {
-    val USER_FACTORS_KEY = Key.create<Map<String, String>>("com.intellij.stats.personalization.userFactors")
+    val USER_FACTORS_KEY = Key.create<Map<String, String?>>("com.intellij.stats.personalization.userFactors")
     fun getInstance(project: Project): UserFactorsManager = project.getComponent(UserFactorsManager::class.java)
   }