-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_json.rb
More file actions
executable file
·43 lines (40 loc) · 1 KB
/
parse_json.rb
File metadata and controls
executable file
·43 lines (40 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# $Id$
require "rubygems"
require "json"
# get_json.rb で取得した JSON ファイルを解析して統計表形式に変換する
# 引数として、json ファイル名を指定すること
#
# USAGE: ./parse_json.rb *.json
puts <<EOF
{| class="wikitable sortable"
! nowrap | 時間帯
!編集回数
!編集ユーザ数
!編集ユーザ
EOF
count = 0
users = Hash.new( 0 )
ARGV.each do |f|
#p users
changes = JSON.load( open(f) )["query"]["recentchanges"]
cur_users = Hash.new(0)
changes.each do |e|
cur_users["[[特別:投稿記録/#{ e["user"] }|#{ e["user"] }]]"] += 1
users[ e["user"] ] += 1
end
t = File.basename( f, ".json" )
t = $1.dup.to_i if t =~ /-(\d\d?)$/
puts <<EOF
|-
| #{ t }時台
| #{ changes.size }
| #{ cur_users.size }
| #{ cur_users.keys.sort_by{|e| cur_users[e] }.reverse.join(", ") }
EOF
count += changes.size
end
puts "|}"
STDERR.puts users.inspect
STDERR.puts "#{ count } edits, #{ users.keys.size } users"