Average lobby time
Posted: Mon Oct 26, 2015 6:42 pm
What's the average lobby time of id lobbies? The median value would also be interesting to know.
That info is stored in files and the logs (of which the latter one gets erased/overwritten after x days). So nop, I cant do that.Stealer wrote:Each lobby has periodic messages for the number of players ("[System]: Waiting for 9 more players before the game will automatically start. (http://www.entgaming.net)"). Count the number of times that shows up and you should get the length of the lobby +/- like 15 seconds.
Gotta check if that data is available.You know when the game ended, the length of the game => Start of game
The end of the last game - the start of the next gives you the lobby time.
Code: Select all
from bs4 import BeautifulSoup #pip3 install beautifulsoup4
from enum import Enum
import re
from datetime import datetime
from datetime import timedelta
from urllib3 import PoolManager
import certifi
class web_adapter():
def __init__(self):
self.http = PoolManager(headers={'User Agent': "art/0"}
, cert_reqs='CERT_REQUIRED' # Force certificate check.
, ca_certs=certifi.where() # Path to the Certifi bundle.)
)
def get(self,url,data=None,headers={}):
r = self.http.request(method='GET', url=url, fields=data, headers=headers)
return r.data.decode("utf-8")
def post(self,url,data,headers={}):
r = self.http.request(method='POST', url=url, fields=data, headers=headers)
return r.data.decode("utf-8")
class STATS_GAME_TYPE(Enum):
islandDefense = 1
@classmethod
def get_url(self, game_type):
if game_type == STATS_GAME_TYPE.islandDefense:
return "https://entgaming.net/customstats/islanddefense/games/"
class stats_adapter():
def __init__(self):
self.web = web_adapter()
# https://entgaming.net/customstats/islanddefense/games/
# https://entgaming.net/customstats/islanddefense/games/2/
def _get_games(self,url):
games = []
raw_html = self.web.get(url)
soup = BeautifulSoup(raw_html, "html.parser")
table = soup.find_all('table')
trs = table[0].find_all('tr')
for i in range(1,len(trs)-1):
tds = trs[i].find_all('td')
try:
game_id = re.findall('.*/([0-9]+)/',tds[0].find('a')['href'])[0]
game_no = re.findall('#([0-9]+)', tds[0].text)[0]
type = tds[1].text
regexexp = re.findall('[0-9]+',tds[2].text)
duration = 0
for i in range(0, len(regexexp)):
duration += (60 ** (len(regexexp) - i - 1))*(int(regexexp[i]))
date = datetime.strptime(tds[3].text,'%d/%m/%Y, %H:%M')
games.append( { 'game_id' : game_id
, 'game_no': game_no
, 'type' : type
, 'duration' : duration
, 'end_date' : date
, 'start_date': date - timedelta(seconds=duration)
, 'creator' : tds[4].text
})
except:
pass
return games
def get_games(self,game_type,max_pages=50):
games = []
page = 1
while page <= max_pages:
while len(games) > 0:
yield games.pop()
url = STATS_GAME_TYPE.get_url(game_type)+str(page)+"/"
games = self._get_games(url)
page = page + 1
games = []
lobby_times = []
for x in stats_adapter().get_games(game_type=STATS_GAME_TYPE.islandDefense, max_pages=20):
games.append(x)
games.sort(key=lambda g: g['start_date'], reverse=True)
for i in range(0, len(games)-1):
lobby_times.append((games[i]['start_date'] - games[i+1]['start_date']).total_seconds()) # seconds is the resolution
print(len(games))
print((sum(lobby_times)/len(lobby_times))) # seconds / lobby