<commit_before>package com.ternaryop.photoshelf.service

import android.app.IntentService
import android.content.Context
import android.content.Intent
import com.ternaryop.photoshelf.EXTRA_ACTION
import com.ternaryop.photoshelf.EXTRA_BLOG_NAME
import com.ternaryop.photoshelf.EXTRA_TYPE
import com.ternaryop.photoshelf.api.birthday.FindParams
import com.ternaryop.photoshelf.event.CounterEvent
import com.ternaryop.photoshelf.util.network.ApiManager
import com.ternaryop.tumblr.android.TumblrManager
import com.ternaryop.tumblr.draftCount
import com.ternaryop.tumblr.queueCount
import com.ternaryop.utils.date.dayOfMonth
import com.ternaryop.utils.date.month
import org.greenrobot.eventbus.EventBus
import java.util.Calendar

/**
 * Created by dave on 28/10/17.
 * Handle counters retrieval
 */
class CounterIntentService : IntentService("counterIntent") {

    override fun onHandleIntent(intent: Intent?) {
        if (intent == null) {
            return
        }
        val selectedBlogName = intent.getStringExtra(EXTRA_BLOG_NAME)
        val type = intent.getIntExtra(EXTRA_TYPE, CounterEvent.NONE)
        val action = intent.getStringExtra(EXTRA_ACTION)

        if (ACTION_FETCH_COUNTER == action) {
            fetchCounterByType(type, selectedBlogName)
        }
    }

    private fun fetchCounterByType(type: Int, blogName: String) {
        Thread(Runnable {
            if (EventBus.getDefault().hasSubscriberForEvent(CounterEvent::class.java)) {
                EventBus.getDefault().post(CounterEvent(type, getCount(type, blogName)))
            }
        }).start()
    }

    private fun getCount(type: Int, blogName: String): Int {
        try {
            return when (type) {
                CounterEvent.BIRTHDAY -> birthdayCount()
                CounterEvent.DRAFT -> TumblrManager.getInstance(applicationContext).draftCount(blogName)
                CounterEvent.SCHEDULE -> TumblrManager.getInstance(applicationContext).queueCount(blogName)
                CounterEvent.NONE -> 0
                else -> -1
            }
        } catch (ignored: Exception) {
        }

        return 0
    }

    private fun birthdayCount(): Int {
        val now = Calendar.getInstance()
        return ApiManager.birthdayService(applicationContext).findByDate(
            FindParams(onlyTotal = true, month = now.month + 1, dayOfMonth = now.dayOfMonth).toQueryMap())
            .map { it.response.total.toInt() }
            .blockingGet()
    }

    companion object {
        private const val ACTION_FETCH_COUNTER = "fetchCounter"

        fun fetchCounter(context: Context,
                         blogName: String,
                         type: Int) {
            val intent = Intent(context, CounterIntentService::class.java)
            intent.putExtra(EXTRA_TYPE, type)
            intent.putExtra(EXTRA_BLOG_NAME, blogName)
            intent.putExtra(EXTRA_ACTION, ACTION_FETCH_COUNTER)

            context.startService(intent)
        }
    }
}
<commit_msg>removed unnecessary call to map<commit_after>package com.ternaryop.photoshelf.service

import android.app.IntentService
import android.content.Context
import android.content.Intent
import com.ternaryop.photoshelf.EXTRA_ACTION
import com.ternaryop.photoshelf.EXTRA_BLOG_NAME
import com.ternaryop.photoshelf.EXTRA_TYPE
import com.ternaryop.photoshelf.api.birthday.FindParams
import com.ternaryop.photoshelf.event.CounterEvent
import com.ternaryop.photoshelf.util.network.ApiManager
import com.ternaryop.tumblr.android.TumblrManager
import com.ternaryop.tumblr.draftCount
import com.ternaryop.tumblr.queueCount
import com.ternaryop.utils.date.dayOfMonth
import com.ternaryop.utils.date.month
import org.greenrobot.eventbus.EventBus
import java.util.Calendar

/**
 * Created by dave on 28/10/17.
 * Handle counters retrieval
 */
class CounterIntentService : IntentService("counterIntent") {

    override fun onHandleIntent(intent: Intent?) {
        if (intent == null) {
            return
        }
        val selectedBlogName = intent.getStringExtra(EXTRA_BLOG_NAME)
        val type = intent.getIntExtra(EXTRA_TYPE, CounterEvent.NONE)
        val action = intent.getStringExtra(EXTRA_ACTION)

        if (ACTION_FETCH_COUNTER == action) {
            fetchCounterByType(type, selectedBlogName)
        }
    }

    private fun fetchCounterByType(type: Int, blogName: String) {
        Thread(Runnable {
            if (EventBus.getDefault().hasSubscriberForEvent(CounterEvent::class.java)) {
                EventBus.getDefault().post(CounterEvent(type, getCount(type, blogName)))
            }
        }).start()
    }

    private fun getCount(type: Int, blogName: String): Int {
        try {
            return when (type) {
                CounterEvent.BIRTHDAY -> birthdayCount()
                CounterEvent.DRAFT -> TumblrManager.getInstance(applicationContext).draftCount(blogName)
                CounterEvent.SCHEDULE -> TumblrManager.getInstance(applicationContext).queueCount(blogName)
                CounterEvent.NONE -> 0
                else -> -1
            }
        } catch (ignored: Exception) {
        }

        return 0
    }

    private fun birthdayCount(): Int {
        val now = Calendar.getInstance()
        return ApiManager.birthdayService(applicationContext).findByDate(
            FindParams(onlyTotal = true, month = now.month + 1, dayOfMonth = now.dayOfMonth).toQueryMap())
            .blockingGet()
            .response.total.toInt()
    }

    companion object {
        private const val ACTION_FETCH_COUNTER = "fetchCounter"

        fun fetchCounter(context: Context,
                         blogName: String,
                         type: Int) {
            val intent = Intent(context, CounterIntentService::class.java)
            intent.putExtra(EXTRA_TYPE, type)
            intent.putExtra(EXTRA_BLOG_NAME, blogName)
            intent.putExtra(EXTRA_ACTION, ACTION_FETCH_COUNTER)

            context.startService(intent)
        }
    }
}

{'fraction_non_alphanumeric': 0.09033227583903823, 'fraction_numerical': 0.0033394556687259976, 'mean_word_length': 2.6771025168815226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4266311', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1656, 'n_words': 305}