一种打点逻辑的实现方案

栏目: ASP.NET · 发布时间: 7年前

项目中经常需要做打点。下面是一种打点逻辑的实现方案,例子如下所示:
    public static void main(String[] args) {
        // 1. 新建一个统计项
        StatisticPipeLine pipeLine = StatisticPipeLine.create("game_statistic");
 
        // 标记一些动作
        // 默认提供了开始-结束计时动作(TimerAction)、计数器动作(CounterAction)、枚举动作(EnumAction)
        pipeLine.put(EnumAction.fromValue(5), "entrance")
                .put(CounterAction.zero(), "counter")
                .put(TimerAction.Start.fromCurrentTimestamp(), "start_click");
 
        // 模拟耗时操作
        sleep(2000);
 
        // 结束计时
        pipeLine.put(TimerAction.End.fromStart("start_click"), "show_ui");
 
        // 计数器+1
        pipeLine.put(CounterAction.increase("counter")); // should print counter=1
 
        // 模拟耗时操作
        sleep(1000);
 
        // 结束计时
        pipeLine.put(TimerAction.End.fromStart("start_click"), "show_video");
 
        // 获得统计结果
        Map<String, Object> assemble = pipeLine.assemble();
 
        // 结果为 {show_video=3005, counter=1, entrance=5, show_ui=2002}
        System.out.println(assemble);
    }
代码在: https://github.com/legendmohe/StatisticPipeLine

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Programming the Mobile Web

Programming the Mobile Web

Maximiliano Firtman / O'Reilly Media / 2010-07-23 / $44.99

* Learn how to use your existing skills to move into mobile web development * Discover the new possibilities of mobile web development, and understand its limitations * Get detailed coverage of ......一起来看看 《Programming the Mobile Web》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具