Fix comments
This commit is contained in:
@@ -79,11 +79,16 @@ class RingQueue:
|
||||
|
||||
class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
"""
|
||||
チャットの勢いを計算するクラス
|
||||
チャットの勢いを計算する。
|
||||
|
||||
一定期間のチャットデータのうち、最初のチャットの投稿時刻と
|
||||
最後のチャットの投稿時刻の差を、チャット数で割り返し
|
||||
1分あたりの速度に換算する。
|
||||
|
||||
Parameter
|
||||
----------
|
||||
capacity : int
|
||||
格納するチャットブロックの数
|
||||
RingQueueに格納するチャット勢い算出用データの最大数
|
||||
"""
|
||||
|
||||
def __init__(self, capacity = 10):
|
||||
@@ -104,15 +109,15 @@ class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
|
||||
def _calc_speed(self):
|
||||
"""
|
||||
RingQueue内のチャットデータリストから、
|
||||
RingQueue内のチャット勢い算出用データリストを元に、
|
||||
チャット速度を計算して返す
|
||||
|
||||
Return
|
||||
---------------------------
|
||||
チャット速度(1分間で換算したチャット数)
|
||||
チャット速度(1分間で換算したチャット数)
|
||||
"""
|
||||
try:
|
||||
#キュー内のactionsの総チャット数
|
||||
#キュー内の総チャット数
|
||||
total = sum(item['chat_count'] for item in self.items)
|
||||
#キュー内の最初と最後のチャットの時間差
|
||||
duration = (self.items[self.last_pos]['endtime']
|
||||
@@ -123,9 +128,12 @@ class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
except IndexError:
|
||||
return 0
|
||||
|
||||
def _put_chatdata(self,actions):
|
||||
def _put_chatdata(self, actions):
|
||||
"""
|
||||
チャットデータからタイムスタンプを読み取り、RingQueueに投入する。
|
||||
チャットデータからタイムスタンプを読み取り、勢い測定用のデータを組み立て、
|
||||
RingQueueに投入する。
|
||||
200円以上のスパチャはtickerとmessageの2つのデータが生成されるが、
|
||||
tickerの方は時刻データの場所が異なることを利用し、勢いの集計から除外している。
|
||||
Parameter
|
||||
---------
|
||||
actions : List[dict]
|
||||
@@ -133,9 +141,7 @@ class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
"""
|
||||
def _put_emptydata():
|
||||
'''
|
||||
enqueue empty data when no chat data.
|
||||
Return: int
|
||||
speed value after enqueueing empty data
|
||||
チャットデータがない場合に空のデータをキューに投入する。
|
||||
'''
|
||||
timestamp_now = calendar.timegm(datetime.datetime.
|
||||
now(pytz.utc).utctimetuple())
|
||||
@@ -147,7 +153,7 @@ class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
|
||||
def _get_timestamp(action :dict):
|
||||
"""
|
||||
チャットデータのtimestampUsecを読み取る
|
||||
チャットデータから時刻データを取り出す。
|
||||
"""
|
||||
try:
|
||||
item = action['addChatItemAction']['item']
|
||||
@@ -160,7 +166,7 @@ class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
_put_emptydata()
|
||||
return
|
||||
|
||||
#actions内の時刻データを持つチャットデータの数(tickerは除く)
|
||||
#actions内の時刻データを持つチャットデータの数
|
||||
counter=0
|
||||
#actions内の最初のチャットデータの時刻
|
||||
starttime= None
|
||||
@@ -185,7 +191,7 @@ class SpeedCalculator(ChatProcessor, RingQueue):
|
||||
#チャットの数をインクリメント
|
||||
counter += 1
|
||||
|
||||
#チャット速度用のデータをリングキューに送る
|
||||
#チャット速度用のデータをRingQueueに送る
|
||||
if starttime is None or endtime is None:
|
||||
_put_emptydata()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user