Open1

Discord のサーバーインサイトを解析する

ShunShun

サーバーインサイトの Message Activity の統計情報を扱う。
右上の Export CSV からデータを取得。
Message Activity

曜日別の統計情報として整理するコード

from pprint import pprint
import calendar
import csv
import datetime
import locale

locale.setlocale(locale.LC_TIME, 'ja_JP.UTF-8')
f = csv.reader(open('guild-message-activity.csv', 'r'), delimiter=',')
header = next(f)

stats = {}
for date, messages, communicators in f:
    d = datetime.datetime.strptime(date.split('T')[0], '%Y-%m-%d')
    weekday = calendar.day_name[d.weekday()]
    if stats.get(weekday) is None:
        stats[weekday] = {'messages':0, 'communicators': 0, 'count': 0}
    stats[weekday]['messages'] += float(messages)
    stats[weekday]['communicators'] += float(communicators)
    stats[weekday]['count'] += 1

for weekday in stats.keys():
    stats[weekday]['messages_average'] = stats[weekday]['messages']/stats[weekday]['count']
    stats[weekday]['communicators_average'] = stats[weekday]['communicators']/stats[weekday]['count']

pprint(stats)

結果

{'土曜日': {'communicators': 625.8786313484269,
         'communicators_average': 36.81639007931923,
         'count': 17,
         'messages': 21331.0,
         'messages_average': 1254.764705882353},
 '日曜日': {'communicators': 543.6991459222334,
         'communicators_average': 33.981196620139585,
         'count': 16,
         'messages': 17592.0,
         'messages_average': 1099.5},
 '月曜日': {'communicators': 567.9503939753585,
         'communicators_average': 35.4968996234599,
         'count': 16,
         'messages': 18023.0,
         'messages_average': 1126.4375},
 '木曜日': {'communicators': 543.8127146236017,
         'communicators_average': 31.988983213153038,
         'count': 17,
         'messages': 15181.0,
         'messages_average': 893.0},
 '水曜日': {'communicators': 588.6289350157732,
         'communicators_average': 34.625231471516074,
         'count': 17,
         'messages': 18742.0,
         'messages_average': 1102.4705882352941},
 '火曜日': {'communicators': 604.8147184390997,
         'communicators_average': 35.57733637877057,
         'count': 17,
         'messages': 18824.0,
         'messages_average': 1107.2941176470588},
 '金曜日': {'communicators': 694.3698280396145,
         'communicators_average': 40.84528400233027,
         'count': 17,
         'messages': 23547.0,
         'messages_average': 1385.1176470588234}}