<commit_before>package com.nearsoft.pikmail.api

import com.mixpanel.mixpanelapi.ClientDelivery
import com.mixpanel.mixpanelapi.MessageBuilder
import com.mixpanel.mixpanelapi.MixpanelAPI
import org.json.JSONObject


class AnalyticsManager {

    private val messageBuilder: MessageBuilder = MessageBuilder(System.getenv("MIXPANEL_TOKEN"))
    private val mixpanel = MixpanelAPI()

    fun trackSuccess(email: String, remoteIp: String?, size: Int?) = track(email, EventType.SUCCESS, remoteIp, "Size" to size)

    fun trackError(email: String, remoteIp: String?, throwable: Throwable) = track(email, EventType.ERROR, remoteIp, "Message" to throwable.message)

    private fun track(distinctId: String, eventType: EventType, remoteIp: String?, vararg properties: Pair<String, Any?>) {
        val delivery = ClientDelivery().apply {
            addMessage(messageBuilder.set(distinctId, JSONObject(mapOf("\$email" to distinctId))))
            addMessage(messageBuilder.event(distinctId, eventType.name, JSONObject(mapOf(*properties, "RemoteIp" to remoteIp))))
            addMessage(messageBuilder.increment(distinctId, mapOf("Counter" to 1L)))
        }
        mixpanel.deliver(delivery)
    }

    private enum class EventType { SUCCESS, ERROR }

}<commit_msg>Add error counter.<commit_after>package com.nearsoft.pikmail.api

import com.mixpanel.mixpanelapi.ClientDelivery
import com.mixpanel.mixpanelapi.MessageBuilder
import com.mixpanel.mixpanelapi.MixpanelAPI
import org.json.JSONObject


class AnalyticsManager {

    private val messageBuilder: MessageBuilder = MessageBuilder(System.getenv("MIXPANEL_TOKEN"))
    private val mixpanel = MixpanelAPI()

    fun trackSuccess(email: String, remoteIp: String?, size: Int?) = track(email, EventType.SUCCESS, remoteIp, "Size" to size)

    fun trackError(email: String, remoteIp: String?, throwable: Throwable) = track(email, EventType.ERROR, remoteIp, "Message" to throwable.message)

    private fun track(distinctId: String, eventType: EventType, remoteIp: String?, vararg properties: Pair<String, Any?>) {
        val delivery = ClientDelivery().apply {
            addMessage(messageBuilder.set(distinctId, JSONObject(mapOf("\$email" to distinctId))))
            addMessage(messageBuilder.event(distinctId, eventType.name, JSONObject(mapOf(*properties, "RemoteIp" to remoteIp))))
            addMessage(messageBuilder.increment(distinctId, mapOf((if (eventType == EventType.SUCCESS) "Counter" else "ErrorCounter") to 1L)))
        }
        mixpanel.deliver(delivery)
    }

    private enum class EventType { SUCCESS, ERROR }

}
{'fraction_non_alphanumeric': 0.10823347506764593, 'fraction_numerical': 0.0007730962504831851, 'mean_word_length': 4.8157303370786515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2012886', 'n_tokens_mistral': 755, 'n_tokens_neox': 733, 'n_words': 173}