@@ -6,44 +6,60 @@ import kotlinx.coroutines.withContext
66import org.wikipedia.WikipediaApp
77import org.wikipedia.auth.AccountUtil
88import org.wikipedia.dataclient.ServiceFactory
9+ import org.wikipedia.dataclient.okhttp.HttpStatusException
910import org.wikipedia.page.PageTitle
1011
1112object MachineGeneratedArticleDescriptionsAnalyticsHelper {
1213
1314 private const val MACHINE_GEN_DESC_SUGGESTIONS = " machineSuggestions"
15+ private var apiFailed = false
1416 val machineGeneratedDescriptionsABTest = MachineGeneratedArticleDescriptionABCTest ()
15-
17+ var apiOrderList = emptyList<String >()
18+ var displayOrderList = emptyList<String >()
19+ var chosenSuggestion = " "
1620 var isUserExperienced = false
1721 var isUserInExperiment = false
22+ private var startTime = 0L
1823
1924 fun articleDescriptionEditingStart (context : Context ) {
2025 log(context, " ArticleDescriptionEditing.start" )
26+ startTime = System .currentTimeMillis()
27+ }
28+
29+ fun resetTimer () {
30+ startTime = System .currentTimeMillis()
2131 }
2232
2333 fun articleDescriptionEditingEnd (context : Context ) {
24- log(context, " ArticleDescriptionEditing.end" )
34+ log(context, " ArticleDescriptionEditing.end.timeSpentMs. ${ System .currentTimeMillis() - startTime} " )
2535 }
2636
27- fun logAttempt (context : Context , finalDescription : String , wasSuggestionModified : Boolean , title : PageTitle ) {
28- log(context, composeLogString(title) + " .attempt:$finalDescription .modified:$wasSuggestionModified " )
37+ fun logAttempt (context : Context , finalDescription : String , wasChosen : Boolean , wasModified : Boolean , title : PageTitle ) {
38+ log(
39+ context, composeLogString(title) + " .attempt:$finalDescription .suggestionChosen:${if (! wasChosen) - 1 else displayOrderList.indexOf(chosenSuggestion) + 1 } " +
40+ " .api.${apiOrderList.indexOf(chosenSuggestion) + 1 } .modified:$wasModified "
41+ )
2942 }
3043
3144 fun logSuccess (context : Context , finalDescription : String , wasChosen : Boolean , wasModified : Boolean , title : PageTitle , revId : Long ) {
32- log(context, composeLogString(title) + " .success:$finalDescription .suggestionChosen:$wasChosen .modified:$wasModified .revId:$revId " )
45+ log(context, composeLogString(title) + " .success:$finalDescription .suggestionChosen:${if (! wasChosen) - 1 else displayOrderList.indexOf(
46+ chosenSuggestion) + 1 } .api.${apiOrderList.indexOf(chosenSuggestion) + 1 } .modified:$wasModified .revId:$revId " )
3347 }
3448
35- fun logSuggestionsReceived (context : Context , suggestionsList : List <String >, isBlp : Boolean , title : PageTitle ) {
36- val suggestions = suggestionsList.joinToString(" |" )
37- log(context, composeLogString(title) + " .blp:$isBlp .count:${suggestionsList.size} .suggestions:$suggestions " )
49+ fun logSuggestionsReceived (context : Context , isBlp : Boolean , title : PageTitle ) {
50+ apiFailed = false
51+ log(context, composeLogString(title) + " .blp:$isBlp .count:${apiOrderList.size} .api1:${apiOrderList.first()} " +
52+ if (apiOrderList.size > 1 ) " .api2.${apiOrderList.last()} " else " " )
3853 }
3954
40- fun logSuggestionsShown (context : Context , suggestionsList : List < String >, title : PageTitle ) {
41- val suggestions = suggestionsList.joinToString( " | " )
42- log(context, composeLogString(title) + " .count: ${suggestionsList.size} .displayOrder: $suggestions " )
55+ fun logSuggestionsShown (context : Context , title : PageTitle ) {
56+ log(context, composeLogString(title) + " .count: ${displayOrderList.size} .display1: ${displayOrderList.first()} " +
57+ if (displayOrderList.size > 1 ) " .display2. ${displayOrderList.last()} " else " " )
4358 }
4459
45- fun logSuggestionSelected (context : Context , suggestion : String , title : PageTitle ) {
46- log(context, composeLogString(title) + " .selected:$suggestion " )
60+ fun logSuggestionChosen (context : Context , suggestion : String , title : PageTitle ) {
61+ chosenSuggestion = suggestion
62+ log(context, composeLogString(title) + " .selected:$suggestion .${getOrderString()} " )
4763 }
4864
4965 fun logSuggestionsDismissed (context : Context , title : PageTitle ) {
@@ -52,7 +68,7 @@ object MachineGeneratedArticleDescriptionsAnalyticsHelper {
5268
5369 fun logSuggestionReported (context : Context , suggestion : String , reportReasonsList : List <String >, title : PageTitle ) {
5470 val reportReasons = reportReasonsList.joinToString(" |" )
55- log(context, composeLogString(title) + " .reportDialog.$suggestion .reasons:$reportReasons .reported" )
71+ log(context, composeLogString(title) + " .reportDialog.$suggestion .${getOrderString()} . reasons:$reportReasons .reported" )
5672 }
5773
5874 fun logReportDialogDismissed (context : Context ) {
@@ -67,13 +83,24 @@ object MachineGeneratedArticleDescriptionsAnalyticsHelper {
6783 log(context, " $MACHINE_GEN_DESC_SUGGESTIONS .groupAssigned:$testGroup " )
6884 }
6985
86+ fun logApiFailed (context : Context , throwable : Throwable , title : PageTitle ) {
87+ if (throwable is HttpStatusException ) {
88+ log(context, " Api failed with response code ${throwable.code} for : ${composeLogString(title)} " )
89+ }
90+ apiFailed = true
91+ }
92+
7093 private fun log (context : Context , logString : String ) {
71- if (! isUserInExperiment) {
94+ if (! isUserInExperiment || apiFailed ) {
7295 return
7396 }
7497 EventPlatformClient .submit(BreadCrumbLogEvent (BreadCrumbViewUtil .getReadableScreenName(context), logString))
7598 }
7699
100+ private fun getOrderString (): String {
101+ return " api.${apiOrderList.indexOf(chosenSuggestion) + 1 } .display.${displayOrderList.indexOf(chosenSuggestion) + 1 } "
102+ }
103+
77104 private fun composeLogString (title : PageTitle ): String {
78105 return " ${composeGroupString()} .lang:${title.wikiSite.languageCode} .title:${title.prefixedText} "
79106 }
0 commit comments