[and] Updated some statistics code.

This commit is contained in:
Dmitry Kunin 2013-08-30 13:29:07 +03:00 committed by Alex Zolotarev
parent b812c58f04
commit 4de1760c75
3 changed files with 37 additions and 27 deletions

View file

@ -6,9 +6,8 @@ import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import com.mapswithme.maps.MWMApplication;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipData;
@ -17,6 +16,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -133,6 +133,7 @@ final public class Utils
if (null == object) throw new NullPointerException("Argument here must not be NULL");
}
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static void copyTextToClipboard(Context context, String text)
{
@ -154,19 +155,23 @@ final public class Utils
public static <K,V> String mapPrettyPrint(Map<K, V> map)
{
if (map == null) return "[null]";
if (map.isEmpty()) return "[]";
if (map == null)
return "[null]";
if (map.isEmpty())
return "[]";
final StringBuilder sb = new StringBuilder("[");
String joined = "";
for (final K key : map.keySet())
sb.append(String.valueOf(key))
.append('=')
.append(map.get(key))
.append(", ");
{
final String keyVal = key + "=" + map.get(key);
if (joined.length() > 0)
joined = TextUtils.join(",", new Object[] { joined, keyVal });
else
joined = keyVal;
}
// Replace last ', ' with ']'.
sb.replace(sb.length() - 2, sb.length() - 1, "]");
return sb.toString();
return "[" + joined + "]";
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)

View file

@ -1,5 +1,6 @@
package com.mapswithme.util.log;
import android.text.TextUtils;
import android.util.Log;
public class SimpleLogger extends Logger
@ -33,13 +34,7 @@ public class SimpleLogger extends Logger
private static String join(Object ... args)
{
final StringBuilder sb = new StringBuilder(" (");
if (args != null)
{
for (Object o : args)
sb.append(o).append(',');
}
return sb.toString() + ")";
return TextUtils.join(",", args);
}
private SimpleLogger() {};

View file

@ -3,11 +3,15 @@ package com.mapswithme.util.statistics;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import com.mapswithme.maps.R;
import com.mapswithme.maps.MWMApplication;
import com.mapswithme.maps.api.ParsedMmwRequest;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.util.MathUtils;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.SimpleLogger;
import com.mapswithme.util.log.StubLogger;
public enum Statistics
{
@ -24,7 +28,8 @@ public enum Statistics
private EventBuilder mEventBuilder;
private StatisticsEngine mStatisticsEngine;
// Statistics params
private boolean DEBUG = true;
private final boolean DEBUG = false;
private final Logger mLogger = DEBUG ? SimpleLogger.get("MwmStatistics") : StubLogger.get();
// Statistics counters
private int mBookmarksCreated= 0;
private int mSharedTimes = 0;
@ -43,7 +48,12 @@ public enum Statistics
public void trackIfEnabled(Context context, Event event)
{
if (isStatisticsEnabled(context))
{
event.post();
mLogger.d("Posted event:", event);
}
else
mLogger.d("Skipped event:", event);
}
public void trackCountryDownload(Context context)
@ -145,12 +155,12 @@ public enum Statistics
{
ensureConfigured(MWMApplication.get());
//@formatter:off
getEventBuilder().reset()
.setName("Api Called")
.addParam("Caller Package", request.getCallerInfo().packageName)
.getEvent()
.post();
final Event event = getEventBuilder().reset()
.setName("API called")
.addParam("Caller ID", request.getCallerInfo().packageName)
.getEvent();
//@formatter:on
trackIfEnabled(MWMApplication.get(), event);
}
}
@ -196,12 +206,12 @@ public enum Statistics
if (MWMApplication.get().isProVersion())
{
// Number of sets
BookmarkManager manager = BookmarkManager.getBookmarkManager(activity);
final BookmarkManager manager = BookmarkManager.getBookmarkManager(activity);
final int categoriesCount = manager.getCategoriesCount();
if (categoriesCount > 0)
{
// Calculate average num of bmks in category
double[] sizes = new double[categoriesCount];
final double[] sizes = new double[categoriesCount];
for (int catIndex = 0; catIndex < categoriesCount; catIndex++)
sizes[catIndex] = manager.getCategoryById(catIndex).getSize();
final double average = MathUtils.average(sizes);