ben7th / yuwan_counter_service

斗鱼直播统计的后端存储服务
1 stars 1 forks source link

三个简单统计 #6

Open ben7th opened 9 years ago

ben7th commented 9 years ago
  1. 房间关注数分时统计
  2. 房间观众数分时统计
  3. 记录房间鱼丸总数并进行分时统计
fushang318 commented 9 years ago

希望对房间状态进行分时统计(每月,每周,每天,每小时,每分钟的状态)(时间段内的第一条 room_status 记录)

结果如下:

{
  "2015-02-10" => {
    # 房间关注数
    "follow_count"  => 11,
    # 房间观众数
    "online_number" => 11,
    # 房间鱼丸总数
    "yuwan_count"   => "1T"
  },
  "2015-02-11" => {
    # 房间关注数
    "follow_count"  => 11,
    # 房间观众数
    "online_number" => 11,
    # 房间鱼丸总数
    "yuwan_count"   => "1T"
  },
  "2015-02-12" => {
    # 房间关注数
    "follow_count"  => 11,
    # 房间观众数
    "online_number" => 11,
    # 房间鱼丸总数
    "yuwan_count"   => "1T"
  }
}
fushang318 commented 9 years ago

模型方法

result = RoomStatus.stat(room_id, time_str_type, start_time_str, end_time_str)

# result 结构举例
# time_str_type: 'day', 还可以是 ('month' , 'week', 'hour', 'minute')
# start_time_str = '2015-02-10'
# end_time_str = '2015-02-12'
{
  "2015-02-10" => {
    # 查询该时间段内的第一条 room_status 记录
    # 房间关注数
    "follow_count"  => 11,
    # 房间观众数
    "online_number" => 11,
    # 房间鱼丸总数
    "yuwan_count"   => "1T"
  },
  "2015-02-11" => {
    # 房间关注数
    "follow_count"  => 11,
    # 房间观众数
    "online_number" => 11,
    # 房间鱼丸总数
    "yuwan_count"   => "1T"
  },
  "2015-02-12" => {
    # 房间关注数
    "follow_count"  => 11,
    # 房间观众数
    "online_number" => 11,
    # 房间鱼丸总数
    "yuwan_count"   => "1T"
  }
}

http api

url 
  /api/room_status/stat
method
  get 
params
 room_id
  # 指定按什么时间段统计,可以是 month | week | day | hour | minute
  by

  # 起始时间,同模型方法接收的参数格式一致
  start

  # 结束时间,同模型方法接收的参数格式一致
  end

response
  {
    :by => "day",
    :data => {
      "2015-02-10" => {
        # 查询该时间段内的第一条 room_status 记录
        # 房间关注数
        "follow_count"  => 11,
        # 房间观众数
        "online_number" => 11,
        # 房间鱼丸总数
        "yuwan_count"   => "1T"
      },
      "2015-02-11" => {
        # 房间关注数
        "follow_count"  => 11,
        # 房间观众数
        "online_number" => 11,
        # 房间鱼丸总数
        "yuwan_count"   => "1T"
      },
      "2015-02-12" => {
        # 房间关注数
        "follow_count"  => 11,
        # 房间观众数
        "online_number" => 11,
        # 房间鱼丸总数
        "yuwan_count"   => "1T"
      }
    }

  }