예제 #1
0
 def championship(self,
                  cs_id=None,
                  event_id=None,
                  event_session_id=None,
                  point_schema_id=None,
                  team_score=0,
                  curr_url=None):
     if not cs_id is None: cs_id = int(cs_id)
     if not event_id is None: event_id = int(event_id)
     if cs_id is None:
         csResTmp = db.csGetSeasons(__sync=True)()
         if len(csResTmp['seasons']) > 0:
             if event_id is None:
                 cs_id = csResTmp['seasons'][0]['id']
             else:
                 for e in csResTmp['events']:
                     if e['id'] == event_id:
                         cs_id = e['cs_id']
                         break
     csRes = db.csGetSeasons(__sync=True, cs_id=cs_id)()
     r = championshipTemplate.render(seasons=csRes['seasons'],
                                     events=csRes['events'],
                                     players=csRes['players'],
                                     teams=csRes['teams'],
                                     cs_id=cs_id,
                                     event_id=event_id,
                                     features=self.features(),
                                     team_score=team_score)
     return baseTemplate.render(base=r,
                                pagination=None,
                                src="cs",
                                rootpage=self.rootpage,
                                features=self.features(),
                                pygal=False,
                                curr_url=curr_url)
예제 #2
0
 def mainpage(self, curr_url=None):
     r = mainPageTemplate.render(features=self.features())
     return baseTemplate.render(base=r,
                                pagination=None,
                                src="main",
                                rootpage=self.rootpage,
                                features=self.features(),
                                pygal=False,
                                curr_url=curr_url)
예제 #3
0
    def statistics(self,
                   servers=None,
                   date_from=None,
                   date_to=None,
                   tracks=None,
                   cars=None,
                   curr_url=None):

        date_from = self.toTimestamp(date_from)
        date_to = self.toTimestamp(date_to,
                                   24 * 60 * 60)  # to should be inclusive

        if not servers is None:
            servers = servers.split(",")

        if not tracks is None:
            tracks = tracks.split(",")

        if not cars is None:
            cars = cars.split(",")

        stats = db.statistics(__sync=True,
                              servers=servers,
                              startDate=date_from[0],
                              endDate=date_to[0],
                              tracks=tracks,
                              cars=cars)()
        allservers = sorted(db.allservers(__sync=True)())
        alltracks = sorted(db.alltracks(__sync=True)(),
                           key=lambda x: x['uitrack'])
        allcars = sorted(db.allcars(__sync=True)(), key=lambda x: x['uicar'])

        self.lastStat = stats
        r = statisticsTemplate.render(stats=stats,
                                      currservers=servers,
                                      servers=allservers,
                                      date_from=date_from,
                                      date_to=date_to,
                                      currtracks=tracks,
                                      tracks=alltracks,
                                      currcars=cars,
                                      cars=allcars,
                                      http_server=self,
                                      features=self.features(),
                                      curr_url=curr_url)
        return baseTemplate.render(base=r,
                                   pagination=None,
                                   src="stats",
                                   rootpage=self.rootpage,
                                   features=self.features(),
                                   pygal=True,
                                   curr_url=curr_url)
예제 #4
0
 def playerdetails(self, pid, curr_url=None):
     res = db.playerDetails(__sync=True, playerid=pid)()
     if self.isAdmin():
         res['groups'] = db.allgroups(__sync=True)()
     r = plyDetailsTemplate.render(http_server=self,
                                   ply=res,
                                   features=self.features())
     return baseTemplate.render(base=r,
                                pagination=None,
                                src="players",
                                rootpage=self.rootpage,
                                features=self.features(),
                                pygal=False,
                                curr_url=curr_url)
예제 #5
0
 def sessiondetails(self,
                    sessionid=None,
                    playerInSessionId=None,
                    curr_url=None):
     if not sessionid is None:
         sesId = int(sessionid)
         res = db.sessionDetails(__sync=True, sessionid=sesId)()
         csres = db.csGetSeasons(__sync=True)()
         r = sesDetailsTemplate.render(
             s=res,
             features=self.features(),
             events=csres['events'],
             point_schemata=csres['point_schemata'],
             session_id=sesId)
         return baseTemplate.render(base=r,
                                    pagination=None,
                                    src="sesstat",
                                    rootpage=self.rootpage,
                                    features=self.features(),
                                    pygal=False,
                                    curr_url=curr_url)
     elif not playerInSessionId is None:
         pisId = int(playerInSessionId)
         res = db.playerInSessionDetails(__sync=True, pisId=pisId)()
         res['sectorCount'] = 0
         for l in res['laps']:
             c = len(list(filter(lambda x: not x is None, l['sectors'])))
             if c > res['sectorCount']:
                 res['sectorCount'] = c
         r = pisDetailsTemplate.render(res=res, features=self.features())
         return baseTemplate.render(base=r,
                                    pagination=None,
                                    src="sesstat",
                                    rootpage=self.rootpage,
                                    features=self.features(),
                                    pygal=False,
                                    curr_url=curr_url)
예제 #6
0
 def lapdetails(self, lapid, cmpbits=None, cmp_lapid=None, curr_url=None):
     lapid = int(lapid)
     cmpbits = cmpbits if cmpbits is None else int(cmpbits)
     details = db.lapDetails(__sync=True, lapid=lapid,
                             withHistoryInfo=True)()
     r = lapDetailsTableTemplate.render(lapdetails=details,
                                        cmpbits=cmpbits,
                                        features=self.features(),
                                        http_server=self,
                                        cmp_lapid=cmp_lapid,
                                        curr_url=curr_url)
     return baseTemplate.render(base=r,
                                pagination=None,
                                src="lapstat",
                                rootpage=self.rootpage,
                                features=self.features(),
                                pygal=True,
                                curr_url=curr_url)
예제 #7
0
 def players(self, search_pattern="", page=0, orderby=None, curr_url=None):
     page = int(page)
     nip = self.itemsPerPage
     orderby_src = {'0': 'lastseen', '1': 'drivername'}
     orderby = orderby_src.get(orderby, 'lastseen')
     res = db.getPlayers(__sync=True,
                         limit=[page * nip + 1, nip],
                         searchPattern=search_pattern,
                         orderby=orderby)()
     #acdebug("page=%d nip=%d count=%d", page, nip, res['count'])
     r = playersTemplate.render(res=res,
                                search_pattern=search_pattern,
                                features=self.features(),
                                caller="players")
     return baseTemplate.render(
         base=r,
         pagination=(page, (res['count'] + nip - 1) // nip),
         src="players",
         rootpage=self.rootpage,
         features=self.features(),
         pygal=False,
         curr_url=curr_url)
예제 #8
0
    def sessionstat(self,
                    track="(all)",
                    page=0,
                    start=None,
                    stop=None,
                    session_types=None,
                    num_players=None,
                    num_laps=None,
                    curr_url=None):
        tracks = [dict(track="(all)", uitrack="(all)")] + sorted(
            db.alltracks(__sync=True)(), key=lambda x: x['uitrack'])
        currtrack = track
        from_time = self.toTimestamp(start)
        to_time = self.toTimestamp(stop,
                                   24 * 60 * 60)  # to should be inclusive
        page = int(page)
        nip = self.itemsPerPage
        if session_types == None:
            session_types = "Practice,Race,Qualify"
        session_types = session_types.split(",")
        if num_players is None:
            num_players = 0
        num_players = int(num_players)
        if num_laps is None:
            num_laps = 0
        num_laps = int(num_laps)

        res = db.sessionStats(
            __sync=True,
            limit=[page * nip + 1, nip],
            tracks=None if currtrack == "(all)" else currtrack,
            sessionTypes=session_types,
            ego_guid=None,
            minSessionStartTime=[from_time[0], to_time[0]],
            minNumPlayers=num_players,
            minNumLaps=num_laps,
            multiplayer=[0, 1])()
        if not res is None:
            totalPages = (res['numberOfSessions'] + nip - 1) // nip
            r = sesStatTableTemplate.render(
                sesStatRes=res['sessions'],
                tracks=tracks,
                currtrack=currtrack,
                datespan=[from_time[1], to_time[1]],
                session_types=session_types,
                num_players=num_players,
                num_laps=num_laps,
                features=self.features())
        else:
            totalPages = 1
            r = sesStatTableTemplate.render(sesStatRes=[],
                                            tracks=tracks,
                                            currtrack=currtrack,
                                            features=self.features())
        return baseTemplate.render(base=r,
                                   pagination=(page, totalPages),
                                   src="sesstat",
                                   rootpage=self.rootpage,
                                   features=self.features(),
                                   pygal=False,
                                   curr_url=curr_url)
예제 #9
0
 def lapstat(self,
             track=None,
             cars=None,
             page=0,
             valid=None,
             date_from=None,
             date_to=None,
             tyres=None,
             currservers=None,
             ranking=None,
             groups=None,
             curr_url=None):
     if not currservers is None:
         currservers = currservers.split(",")
         server = currservers[0] if len(currservers) else None
     else:
         server = None
     ccTrack, ccCars = db.currentCombo(__sync=True, server=server)()
     currtrack = track
     currcars = cars
     if currtrack is None:
         currtrack = ccTrack
     if currcars is None:
         currcars = ccCars
     else:
         currcars = currcars.split(",")
     if not valid is None:
         try:
             valid = set(map(int, valid.split(",")))
         except ValueError:
             valid = set([1, 2])
     else:
         valid = set([1, 2])
     if ranking is None:
         ranking = 0
     else:
         ranking = int(ranking)
     if groups is None:
         groups = []
     else:
         groups = [int(x) for x in groups.split(",")]
     allgroups = db.allgroups(__sync=True)()
     date_from = self.toTimestamp(date_from)
     date_to = self.toTimestamp(date_to, 24 * 60 * 60)
     try:
         page = int(page)
     except TypeError as e:
         acerror("Caught type error while converting lapstat page argument")
         acerror("  page=%s", repr(page))
         raise (e)
     tracks = sorted(db.alltracks(__sync=True)(),
                     key=lambda x: x['uitrack'])
     cars = sorted(db.allcars(__sync=True)(), key=lambda x: x['uicar'])
     servers = sorted(db.allservers(__sync=True)())
     if not tyres is None:
         tyre_list = tyres.split(",")
     else:
         tyre_list = None
     nip = self.itemsPerPage
     res = db.lapStats(__sync=True,
                       mode="top-extended",
                       limit=[page * nip + 1, nip],
                       track=currtrack,
                       cars=currcars,
                       ego_guid=None,
                       valid=list(valid),
                       tyre_list=tyre_list,
                       minSessionStartTime=[date_from[0], date_to[0]],
                       artint=0,
                       server=server,
                       group_by_guid=ranking,
                       groups=groups)()
     if not res is None:
         count = 0
         for i, s in enumerate(res['bestSectors']):
             if not s is None:
                 count = i + 1
         totalPages = (res['totalNumLaps'] + nip - 1) // nip
         lapStatRes = res['laps']
         bestSectors = res['bestSectors']
     else:
         totalPages = 1
         count = 0
         lapStatRes = []
         bestSectors = []
     r = lapStatTableTemplate.render(lapStatRes=lapStatRes,
                                     bestSectors=bestSectors,
                                     count=count,
                                     tracks=tracks,
                                     cars=cars,
                                     currtrack=currtrack,
                                     currcars=currcars,
                                     valid=valid,
                                     date_from=date_from,
                                     date_to=date_to,
                                     tyres=tyres,
                                     currservers=currservers,
                                     servers=servers,
                                     ranking=ranking,
                                     currgroups=groups,
                                     groups=allgroups,
                                     features=self.features())
     return baseTemplate.render(base=r,
                                pagination=(page, totalPages),
                                src="lapstat",
                                rootpage=self.rootpage,
                                features=self.features(),
                                pygal=False,
                                curr_url=curr_url)