navicat数据库管理工具对游戏激活用户和付费用户的统计管理

来源:互联网 发布:淘宝好的精品店 编辑:程序博客网 时间:2024/06/15 02:18

为什么要写这篇文章呢?这是因为有时候游戏发布之后,运营那边如果数据出现异常的话来问咱们技术的话,咱就拿数据说话哈......不然,运营只会把责任推给咱们技术了 唉!

好了,进入正题:

Java端代码:

public class StatisticsLog{    //private static final String path = "http://192.168.254.76:8080/gm/log";    private static final String SERVER_PATH = "http://42.96.170.133:10017/fishLog/log";//数据库服务器地址    private static final StatisticsLog instance = new StatisticsLog();    public static StatisticsLog getInstance(){        return instance;    }        public long firstBeginTime = 0;    public long beginTime;    public List<NameValuePair> staticInfo = new ArrayList<NameValuePair>();    public static final String RUNTIME_RECORD_NAME = "runInfo.data";//当游戏在用户手机运行(激活时),会产生的文件    public static final String FIRST_BEGIN_TIME_KEY = "firstTime";//定义开始游戏时间    public void buildLogInfo(Context activity, String curOperator){        beginTime = System.currentTimeMillis();        InputStream is = CommonFunc.readFileFromNativePlace(activity, RUNTIME_RECORD_NAME);//读取开始游戏的KEY        Properties properties = new Properties();        //如果开始游戏不为空或者时间不为0,直接取        if(null != is){            try{                properties.load(is);                Object firstTime = properties.get(FIRST_BEGIN_TIME_KEY);                if(null != firstTime){                    firstBeginTime = Long.parseLong((String) firstTime);                }            }catch(IOException e){                e.printStackTrace();            }        }        if(0 == firstBeginTime){            firstBeginTime = beginTime;            properties.put(FIRST_BEGIN_TIME_KEY, Long.toString(firstBeginTime));            OutputStream os = CommonFunc.getNativeFileOutputStream(activity, RUNTIME_RECORD_NAME);            if(null != os){                properties.save(os, "");            }        }        staticInfo.add(new BasicNameValuePair("fbt", Long.toString(firstBeginTime)));//添加字段key:首次启动客户端时间        staticInfo.add(new BasicNameValuePair("bt", Long.toString(beginTime)));//客户端启动时间        staticInfo.add(new BasicNameValuePair("ver", PhoneUtils.getAppVersionName(activity)));//版本号        staticInfo.add(new BasicNameValuePair("ch", Channel.getSonChannelID(activity)));//渠道号        staticInfo.add(new BasicNameValuePair("pt", android.os.Build.MODEL));//机型        staticInfo.add(new BasicNameValuePair("aVer", android.os.Build.VERSION.RELEASE));        String key = PhoneUtils.getIMEI(activity);        if(null == key || key.length() <= 0){            WifiManager wifiMgr = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);            WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());            if(null != info){                key = info.getMacAddress();            }else{                key = "unkown";            }        }        staticInfo.add(new BasicNameValuePair("key", key));//imei/mac        staticInfo.add(new BasicNameValuePair("imsi", PhoneUtils.getIMSI(activity)));//IMSI        staticInfo.add(new BasicNameValuePair("operatorName", null == curOperator? "" : curOperator));    }    //发送打印日志    public void sendSelfLog(String tag){        try {            HttpPost httpRequest = new HttpPost(SERVER_PATH);            // Post运作传送变数必须用NameValuePair[]阵列储存            // 传参数 服务端获取的方法为request.getParameter("name")            List<NameValuePair> params = new ArrayList<NameValuePair>(staticInfo);            params.add(new BasicNameValuePair("ct", Long.toString(System.currentTimeMillis())));            params.add(new BasicNameValuePair("tag", tag));                        // 发出HTTP request            httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));            // 取得HTTP response            HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);            // 若状态码为200 ok            if(httpResponse.getStatusLine().getStatusCode() == 200){                // 取出回应字串                // String                // strResult=EntityUtils.toString(httpResponse.getEntity());            }else{                // textView1.setText("Error Response"+httpResponse.getStatusLine().toString());            }        } catch (Exception e) {            e.printStackTrace();        }    }}

代码中有2处一处是从文件读取字段:

 public static InputStream readFileFromNativePlace(Context activity, String name){        try{            File file = activity.getFileStreamPath(name);            if(file.exists()){                return activity.openFileInput(name);            }            return null;                    }catch(FileNotFoundException e){            e.printStackTrace();            return null;        }    }

还有一处是从文件得到字段:

  public static OutputStream getNativeFileOutputStream(Context activity, String name){        try{            return activity.openFileOutput(name, Context.MODE_PRIVATE);        }catch(FileNotFoundException e){            e.printStackTrace();            return null;        }    }

定义一个静态的方法,以便供C++调用:

public static void sendLog(String tag){        StatisticsLog.getInstance().sendSelfLog(tag);    }

Java这边如何使用呢,看代码:

StatisticsLog.getInstance().buildLogInfo(this, Channel.curOperator);StatisticsLog.getInstance().sendSelfLog("begin");sendLog("created");


C++端代码:

void MyGame::sendTestLog(const char* tag){#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)     JniMethodInfo t;    if (JniHelper::getStaticMethodInfo(t, "skt/board/fish/Fish", "sendLog", "(Ljava/lang/String;)V"))    {        CCLog("jni:have sendLog");         jstring stringArg1 = t.env->NewStringUTF(tag);        t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1);        t.env->DeleteLocalRef(stringArg1);        t.env->DeleteLocalRef(t.classID);    }else{        CCLog("jni:not have sendLog");    }#endif}

里面的参数就别不多说了,不懂的看我以前的文章,Cocos2d-x利用jni调用java层代码

使用方法和java一样,在需要记录的地方调用方法就行,比如需要在启动游戏记录,找到位置,直接调用方法

MyGame::getInstance()->sendTestLog("begin");


代码这块就到这了,那么统计的数据到哪了?开头不是定义了一个数据库服务器地址吗?那个就是了,这里需要一个小工具:navicat

打开自己的目录界面显示如下:


看到了吗 自己的定义的字段以及手机类型,这样就容易找出运营异常的情况了,比如付费转换率和用户激活率的问题

0 0