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