Page 1 of 1

Average lobby time

Posted: Mon Oct 26, 2015 6:42 pm
by Lynx
What's the average lobby time of id lobbies? The median value would also be interesting to know.

Re: Average lobby time

Posted: Mon Oct 26, 2015 7:49 pm
by aRt)Y
Can pull dat data tomorrow night or by the weekend.

Re: Average lobby time

Posted: Mon Oct 26, 2015 7:56 pm
by Lynx
Thanks

Re: Average lobby time

Posted: Tue Oct 27, 2015 5:18 pm
by aRt)Y
Actually, such data is not logged.

Re: Average lobby time

Posted: Tue Oct 27, 2015 6:08 pm
by Lynx
GG.

Re: Average lobby time

Posted: Tue Oct 27, 2015 7:22 pm
by FollowingPath
It doesn't log the amount of games created each day?

Re: Average lobby time

Posted: Tue Oct 27, 2015 7:25 pm
by aRt)Y
That data can be pulled. Though, you can't tell the avg. wating time as games can fill fast at a certain time and just one game waiting in limbo later on.

Re: Average lobby time

Posted: Tue Oct 27, 2015 8:11 pm
by Lynx
You can tell the average lobby from that info, but not the median. Which might be more interesting.

Re: Average lobby time

Posted: Tue Oct 27, 2015 11:27 pm
by Stealer
@art)y Can't you just compute it?

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.

You'll have to do some logic so that it compares the start of ID#65 to the end of ID#64 since games don't always end in order.

--
@art)y Can't you just compute it?

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.


Sample lobby:: http://storage.entgaming.net/replay/download.php?f=6698771.txt&fc=6698771.txt

Re: Average lobby time

Posted: Wed Oct 28, 2015 6:37 am
by aRt)Y
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.
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.

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.
Gotta check if that data is available.

Re: Average lobby time

Posted: Fri Oct 30, 2015 9:37 pm
by Stealer

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


@art)y the date provided on the stats page is end of game and the stats page also provides duration of the game.
Subtract end date by duration and you get the start time (with resolution in seconds).

Just take the above script and modify max pages to be whatever you want.

At 20 you get that each lobby is roughly 1/2 hour.
@lynx you'd need Python3 and to install beautifulsoup4 but the lobby_times global is a list of numbers so you can do w.e stats you want.