Bash stats the longest 10 plays/statistics Percentage of players who have been inactive in a single day

Source: Internet
Author: User

1, the client of a game will report to the server every 5 minutes of the player's account points, if the two times reported time interval of less than 5 minutes, think that the player in the 5 minutes online, assuming the format of the report data is as follows:

IP Datetime Score

223.152.112.238 2014-08-22 12:01:35 54232

Existing day of data, according to the order of time to save, a rough estimate of the number of players in the million, please use as few hardware resources to complete the following requests, statistics online for the longest 10 players, if the player two times the same points, think the player in the 5min online time is inactive, Please count the percentage of players who have been inactive for a day.

The Game_user_calculate.bash file code is as follows:

#!/bin/bash# first count how many users, that is, how many ipsed ' 1d ' log_all > Log_all_1awk ' {ip[$1]++}end{for (i in IP) {print I, Ip[i]}} ' Log_all_1 & Gt Userawk ' {ip[$1]++}end{for (i in IP) {print i}} ' Log_all_1 > useruser_count= ' Cat user | Wc-l ' #把每个用户的记录提取出来for (i=1;i<= $user _count;i++);d o# Remove each ipone_user= ' sed-n ' $i "P user" #根据ip筛选出属于此ip的报告记录, and count the number of reports list_count= ' grep ' $one _user "Log_all_1 | Wc-l ' #根据ip筛选出属于此ip的报告记录 and count the number of fractions from the fourth column score_count= ' grep ' $one _user "Log_all_1 | awk ' {print $4} ' | Sort-u | Wc-l ' #将每个用户的报告总次数写入行首sed-i ' $i {s/^/$list _count/} "user# writes the number of different scores per user to the end of the line Sed-i" $i {s/$/$score _count/} "user done# has Records the number of reported times and user IP files and different scores of the file user, sorted by the number of records from large to small, and take the IP field, and output the top 10 echo "The first users online is" sort-n-r-k 1 user | awk ' {print $} ' | Sed-n ' 1,10p ' | Cat-n#-n is sorted numerically #-r is descending, default is ascending #-k specify number of columns # count the total number of players who have been inactive for a day, nowake= ' awk ' {print $} ' user | grep "1" | Wc-l ' #计算不活跃状态玩家的百分比echo Percentage of no active Users is: ' awk ' begin{printf '%.2f%\n ', (' $nowake '/' $user _count ') *100} '

The log file is as follows:

IP Datetime Score
223.152.112.238 2014-08-22 12:01:35 54232
223.152.112.238 2014-08-22 12:06:35 54232
223.152.112.238 2014-08-22 12:11:35 54232
223.152.112.238 2014-08-22 12:17:35 54232
223.152.112.236 2014-08-22 12:01:35 54232
223.152.112.236 2014-08-22 12:06:35 54231
223.152.112.236 2014-08-22 12:15:35 54232
223.152.112.237 2014-08-22 12:01:35 54232
223.152.112.237 2014-08-22 12:06:35 54232
223.152.112.237 2014-08-22 12:11:35 5420
223.152.112.237 2014-08-22 12:16:35 54232
223.152.112.237 2014-08-22 12:29:35 54232
223.152.112.237 2014-08-22 12:34:35 54232

Bash stats the longest 10 plays/statistics Percentage of players who have been inactive for a day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.