def __init__(self, client):
     AppResponse.__init__(self, client)
     self.dependency(js='jquery2')
     self.dependency(css='fontawesome')
     self.__idx = int(client.arg("idx"))
     self.data = Data()
     self.standings = Standings(self.data)
    def __init__(self, client):
        AppResponse.__init__(self, client)
        self.dependency(js='jquery2')
        self.dependency(css='fontawesome')
        self.__idx = int(client.arg('idx'))
        self.__mode = client.arg('mode')
        assert self.__mode in ['round', 'series', 'form'], 'invalid mode arg'

        self.__part = 0
        if self.__mode == 'series':
            self.__part = int(client.arg('part'))

        self.data = Data()
        self.standings = Standings(self.data)
Esempio n. 3
0
 def test_show_wrong_arg(self):
     try:
         Standings(server).show(None)
     except TypeError:
         pass
Esempio n. 4
0
 def test_get_eastern_standings(self):
     self.assertIsNotNone(Standings(server).get_eastern_standings())
Esempio n. 5
0
 def test_get_standings_correct_argument(self):
     a = Standings(server)
     self.assertIsNotNone(a.get_standings(server.get_all_standings()))
Esempio n. 6
0
 def test_get_standings_wrong_argument(self):
     try:
         Standings(server).get_standings(None)
     except TypeError:
         pass
Esempio n. 7
0
 def test_init(self):
     self.assertIsNotNone(Standings(server))
class StandingsView(AppResponse):


    def __init__(self, client):
        AppResponse.__init__(self, client)
        self.dependency(js='jquery2')
        self.dependency(css='fontawesome')
        self.__idx = int(client.arg('idx'))
        self.__mode = client.arg('mode')
        assert self.__mode in ['round', 'series', 'form'], 'invalid mode arg'

        self.__part = 0
        if self.__mode == 'series':
            self.__part = int(client.arg('part'))

        self.data = Data()
        self.standings = Standings(self.data)


    def get_round(self, idx):
        return idx


    def gen_table(self, results, title, separator=False, missing=None, cutoff=1000):
        header = [
            u'<table width="480" border="1" cellspacing="0" cellpadding="5" bordercolor="black" background="%s">' % self.data.get_imageurl('img/pattern.jpg'),
            u'<tr><td border="0">',
            u'<table width="100%" cellpadding="2" cellspacing="0" border="0">',
            u'<tr><td align="center" colspan="8">[b][size=22][color=white]',
            u'%sFILLER' % title,
            u'[/color][/size][/b]</td></tr>',

            u'<tr height="5"></tr>',
            u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>',
            u'<tr>',
            u'<td bgcolor="white" align="center"><img title="Plassering" src="%s"/></td>' % self.data.get_imageurl("img/icon-trophy.png"),
            u'<td bgcolor="white"><img title="Deltagernavn" src="%s"/> <img title="Jackpot" src="%s"/></td>' % (self.data.get_imageurl("img/icon-player.png"), self.data.get_imageurl("img/icon-ball-crop-high.png")),
            u'<td bgcolor="white" align="center"><img title="Sluttresultat" src="%s"/></td>' % self.data.get_imageurl("img/icon-whistle.png"),
            u'<td bgcolor="white" align="center"><img title="Pauseresultat" src="%s"/></td>' % self.data.get_imageurl("img/icon-clock.png"),
            u'<td bgcolor="white" align="center"><img title="M&aring;lscorere" src="%s"/></td>' % self.data.get_imageurl("img/icon-goal.png"),
            u'<td bgcolor="white" align="center"><img title="Tippetegn HUB" src="%s"/></td>' % self.data.get_imageurl("img/icon-tipping.png"),
            u'<td bgcolor="white" align="center"><img title="Poeng" src="%s"/></td>' % self.data.get_imageurl("img/icon-score.png"),
            u'<td bgcolor="white"></td></tr>',
            u'</tr>',
            u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>'
        ]

        html = []
        html += [ u'<div align="center">\n' ]
        html += header

        idx = 1
        plass = 1
        prevscore = 0
        block = 0
        for line, score in enumerate(results):

            if score[0] != prevscore:
                if line > 50 and block == 0:
                    block += 1
                    html += [
                        u'</td></tr>',
                        u'</table>',
                        u'</td></tr>',
                        u'</table>\n</div>\n',
                    ]
                    html += [ u'<div align="center">\n' ]
                    html += header
                if separator and plass <= 3 and idx > 3:
                    html += [
                        u'<tr height="5"></tr>',
                        u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>'
                    ]
                plass = idx

            if plass > cutoff:
                continue

            html += [
                u'<tr height="5"></tr>',
                u'<tr>',
                u'<td bgcolor="white" align="center">[size=12][b]%d[/b][/size]</td>' % plass
            ]

            html += [
                u'<td bgcolor="white">[size=12][b]%s[/b][/size]' % score[5]
            ]
            for jackpot in score[7].split('\n'):
                if not jackpot: continue
                if jackpot == u'': continue
                if not separator: jackpot = u'Jackpot!'
                html += [
                    u' <img title="%s" src="%s"/>' % (jackpot, self.data.get_imageurl("img/icon-ball-crop.png"))
                ]
            html += [
                u'</td>'
            ]

            html += [
                u'<td bgcolor="white" align="center">[size=12][b]%d[/b][/size]</td>' % score[1],
                u'<td bgcolor="white" align="center">[size=12][b]%d[/b][/size]</td>' % score[2],
                u'<td bgcolor="white" align="center">[size=12][b]%d[/b][/size]</td>' % score[3],
                u'<td bgcolor="white" align="center">[size=12][b]%d[/b][/size]</td>' % score[4],
                u'<td bgcolor="white" align="center">[size=12][b]%d[/b][/size]</td>' % score[0]
            ]
            if score[1] > 0:
                html += [
                    u'<td bgcolor="white" align="center"><img src="%s" title="%s"/></td>' % (self.data.get_imageurl("img/icon-stats-crop.png"), score[6].replace('\n', ' || ')),
                ]
            else:
                html += [
                    u'<td bgcolor="white"></td>'
                ]
            html += [
                u'</tr>'
            ]
            idx += 1
            prevscore = score[0]

        html += [
            u'</table>',
            u'</td></tr>',
            u'</table>',
            u'\n</div>'
        ]

        contents = ''.join(html)
        contents = contents.replace(r'<', u'&lt;')
        contents = contents.replace(r'>', u'&gt;')

        return contents


    def html(self):
        self.data.load()

        matches = self.data.get_matches_section()
        match = matches[self.__idx]
        missing = {}

        if self.__mode == 'round':
            separator = False
            results = self.standings.get_score(self.__idx, missing)
            title = u'Runde %d:\n%s' % (self.get_round(self.__idx), match['game'])

        elif self.__mode == 'series':
            separator = True
            title = u'Tabell, runde %d' % (self.get_round(self.__idx))
            results = self.standings.get_score(1, missing)
            matchname = matches[1]['game']
            for i in range(0, len(results)):
                results[i] = (results[i][0],
                              results[i][1],
                              results[i][2],
                              results[i][3],
                              results[i][4],
                              results[i][5],
                              u'%d: %s (%d)' % (self.get_round(1), matchname, results[i][0]),
                              results[i][7],
                              results[i][8])

            if self.__idx > 1:
                for i in range(2, self.__idx+1):
                    matchname = u'%d: %s' % (self.get_round(i), matches[i]['game'])
                    newscore = self.standings.get_score(i, missing)
                    results = self.standings.merge_scores(results, newscore, matchname)

            for i in range(0, len(results)):
                results[i] = (results[i][0],
                              results[i][1],
                              results[i][2],
                              results[i][3],
                              results[i][4],
                              results[i][5],
                              u'Fra %d tips:\n%s' % (results[i][8] + missing.get(results[i][5], 0), results[i][6]),
                              results[i][7],
                              results[i][8])

        elif self.__mode == 'form':
            kamper = 6
            separator = True
            first = max(self.__idx - kamper + 1, 1)
            title = u'Formtabell, runde %d-%d' % (self.get_round(first), self.get_round(self.__idx))
            results = self.standings.get_score(first, missing)
            matchname = matches[first]['game']
            for i in range(0, len(results)):
                results[i] = (results[i][0],
                              results[i][1],
                              results[i][2],
                              results[i][3],
                              results[i][4],
                              results[i][5],
                              u'%d: %s (%d)' % (self.get_round(1), matchname, results[i][0]),
                              results[i][7],
                              results[i][8])

            if self.__idx > 1:
                for i in range(first+1, self.__idx+1):
                    matchname = u'%d: %s' % (self.get_round(i), matches[i]['game'])
                    newscore = self.standings.get_score(i, missing)
                    results = self.standings.merge_scores(results, newscore, matchname)
            for i in range(0, len(results)):
                results[i] = (results[i][0],
                              results[i][1],
                              results[i][2],
                              results[i][3],
                              results[i][4],
                              results[i][5],
                              u'Fra %d tips:\n%s' % (results[i][8] + missing.get(results[i][5], 0), results[i][6]),
                              results[i][7],
                              results[i][8])

        cutoff = 1000
        if self.__mode == 'form': cutoff = 10

        contents = self.gen_table(results, title, separator, missing, cutoff)

        if self.__mode == 'round':
            contents = contents.replace('FILLER', '')
        elif self.__mode == 'series':
            parts = contents.split(u'&lt;/div&gt;')
            for idx, part in enumerate(parts):
                parts[idx] = part.replace('FILLER', ', %d/2' % (idx+1))
            if self.__part > 0:
                contents = parts[self.__part-1] + u'&lt;/div&gt;'
            else:
                contents = u'&lt;/div&gt;'.join(parts)

        elif self.__mode == 'form':
            contents = contents.replace('FILLER', ', topp 10')

        body = []
        body += self.html_heading()
        body += self.html_body_open()
        body += [u'<pre>']

        body += [contents]

        body += [u'</pre>']
        body += self.html_body_close()
        return body
class StandingsView(AppResponse):


    def __init__(self, client):
        AppResponse.__init__(self, client)
        self.dependency(js='jquery2')
        self.dependency(css='fontawesome')
        self.__idx = int(client.arg("idx"))
        self.data = Data()
        self.standings = Standings(self.data)


    def get_round(self, idx):
        return idx


    def html_tableheader(self):
        html = [
            u'<tr height="5"></tr>',
            u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>',
            u'<tr>',
            u'    <td bgcolor="white" align="center"><img title="Plassering" src="%s"/></td>' % self.data.get_imageurl(u'img/icon-trophy.png'),
            u'    <td bgcolor="white" align="left"><img title="Deltagernavn" src="%s"/> <img src="%s" title="Jackpot"/></td>' % (self.data.get_imageurl(u'img/icon-player.png'), self.data.get_imageurl(u'img/icon-ball-crop-high.png')),
            u'    <td bgcolor="white" align="center"><img title="Sluttresultat" src="%s"/></td>' % self.data.get_imageurl(u'img/icon-whistle.png'),
            u'    <td bgcolor="white" align="center"><img title="Pauseresultat" src="%s"/></td>' % self.data.get_imageurl(u'img/icon-clock.png'),
            u'    <td bgcolor="white" align="center"><img title="M&aring;lscorere" src="%s"/></td>' % self.data.get_imageurl(u'img/icon-goal.png'),
            u'    <td bgcolor="white" align="center"><img title="Tippetegn HUB" src="%s"/></td>' % self.data.get_imageurl(u'img/icon-tipping.png'),
            u'    <td bgcolor="white" align="center"><img title="Poeng" src="%s"/></td>' % self.data.get_imageurl(u'img/icon-score.png'),
            u'    <td bgcolor="white"></td></tr>',
            u'</tr>',
            u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>'
        ]
        return html


    def html(self):
        self.data.load()

        html = []
        html += self.html_heading()
        html += self.html_body_open()
        html += self.html_header('Resultater', sections=[{'link':'MatchBetting.py','title':'Kamp-indeks'}])
        html += self.html_content_open()

        html += [
            u'<div align="center">'
        ]

        matches = self.data.get_matches_section()
        match = matches[self.__idx]

        # round score

        html += [
            u'<table width="480" border="0" cellspacing="0" cellpadding="0"><tr>'
        ]

        if self.__idx > 1:
            html += [
                u'<td align="left"><a href="StandingsView.py?idx=%d"><i class="fa fa-arrow-left"></i></a> <a href="StandingsView.py?idx=%d">%s</a></td>' % (self.__idx-1, self.__idx-1, matches[self.__idx-1]['game'])
            ]
        else:
            html += [
                u'<td align="left"></td>'
            ]
        if self.__idx < (len(matches)-1) and 'result' in matches[self.__idx + 1]:
            html += [
                u'<td align="right"><a href="StandingsView.py?idx=%d">%s</a> <a href="StandingsView.py?idx=%d"><i class="fa fa-arrow-right"></i></a></td>' % (self.__idx+1, matches[self.__idx+1]['game'], self.__idx+1)
            ]
        else:
            html += [
                u'<td align="right"></td>'
            ]
        html += [
            u'</tr></table><br/><p>'
        ]
        html += [
            u'<table width=480 border="1" cellspacing="0" cellpadding="5" bordercolor="black" background="%s">' % self.data.get_imageurl(u'img/pattern.jpg'),
            u'<tr><td border="0">',
            u'<table width="100%" cellpadding="2" cellspacing="0" border="0">',
            u'<tr><td align="center" colspan="8"><b><font size="+3" color="white">',
            u'Runde %d:<br>' % self.get_round(self.__idx),
            match['game'],
            u'</font></b></td></tr>'
        ]

        html += self.html_tableheader()

        idx = 1
        plass = 1
        prevscore = 0
        for score in self.standings.get_score(self.__idx, dict()):
            if score[0] != prevscore:
                plass = idx

            html += [
                u'<tr height="5"></tr>',
                u'<tr>',
                u'<td bgcolor="white" align="center">%d</td>' % plass]
            if score[6]:
                html += [
                    u'<td bgcolor=white>%s' % score[5]
                ]
                for jackpot in score[7].split('\n'):
                    if jackpot != '':
                        html += [
                            ' <img src="%s" title="Jackpot!"/>' % self.data.get_imageurl(u'img/icon-ball-crop.png')
                        ]
                html += [u'</td>']
            else:
                html += [
                    u'<td bgcolor="white">%s</td>' % score[5]
                ]
            html += [
                u'<td bgcolor="white" align="center">%d</td>' % score[1],
                u'<td bgcolor="white" align="center">%d</td>' % score[2],
                u'<td bgcolor="white" align="center">%d</td>' % score[3],
                u'<td bgcolor="white" align="center">%d</td>' % score[4],
                u'<td bgcolor="white" align="center">%d</td>' % score[0]
            ]

            if score[0] == 1:
                html += [ u'<td bgcolor="white"></td>' ]
            else:
                html += [ u'<td bgcolor="white" align="center"><img src="%s" title="%s"/></td>' % (self.data.get_imageurl(u'img/icon-stats-crop.png'), score[6]) ]
            html += [
                u'</tr>'
            ]
            idx += 1
            prevscore = score[0]

        html += [
            u'</table>',
            u'</td></tr>',
            u'</table>',
        ]

        html += [
            u'<table width=480 border="1" cellspacing=0 cellpadding=5 bordercolor="white">',
            u'<tr><td align=right><a title="BBCode" target="_blank" href="StandingsBBCode.py?idx=%d&mode=round"><i class="fa fa-code"></i></a></td></tr>' % self.__idx,
            u'</table>',
            u'<p>'
        ]

        # series standings
        misses = {}
        score = self.standings.get_score(1, misses)
        matchname = matches[1]['game']
        for i in range(0, len(score)):
            score[i] = (score[i][0],
                        score[i][1],
                        score[i][2],
                        score[i][3],
                        score[i][4],
                        score[i][5],
                        u'%d: %s (%d)' % (self.get_round(1), matchname, score[i][0]),
                        score[i][7],
                        score[i][8])

        if self.__idx > 1:
            for i in range(2, self.__idx+1):
                matchname = u'%d: %s' % (self.get_round(i), matches[i]['game'])
                newscore = self.standings.get_score(i, misses)
                score = self.standings.merge_scores(score, newscore, matchname)

        html += [
            u'<table width=480 border="1" cellspacing=0 cellpadding=5 bordercolor="black" background="%s">' % self.data.get_imageurl(u'img/pattern.jpg'),
            u'<tr><td border=0>',
            u'<table width="100%" cellpadding="2" cellspacing=0 border="0">',
            u'<tr><td align="center" colspan="8"><b><font size=+3 color=white>',
            u'Tabell, runde %d' % self.get_round(self.__idx),
            u'</font></b></td></tr>'
        ]

        html += self.html_tableheader()

        idx = 1
        plass = 1
        prevscore = 0
        for entry in score:
            if entry[0] != prevscore:
                if plass <= 3 and idx > 3:
                    html += [
                        u'<tr height="5"></tr>',
                        u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>'
                    ]
                plass = idx

            html += [
                u'<tr height="5"></tr>',
                u'<tr>',
                u'<td bgcolor="white" align="center">%d</td>' % plass
            ]
            if entry[7]:
                html += [
                    u'<td bgcolor="white">%s' % entry[5]
                ]
                for jackpot in entry[7].split('\n'):
                    html += [
                        ' <img src="%s" title="%s"/>' % (self.data.get_imageurl(u'img/icon-ball-crop.png'), jackpot)
                    ]
                html += [u'</td>']
            else:
                html += [
                    u'<td bgcolor="white">%s</td>' % entry[5]
                ]
            html += [
                u'<td bgcolor="white" align="center">%d</td>' % entry[1],
                u'<td bgcolor="white" align="center">%d</td>' % entry[2],
                u'<td bgcolor="white" align="center">%d</td>' % entry[3],
                u'<td bgcolor="white" align="center">%d</td>' % entry[4],
                u'<td bgcolor="white" align="center">%d</td>' % entry[0]
            ]
            if entry[1] == 0:
                html += [
                    u'<td bgcolor="white"></td>'
                ]
            else:
                html += [
                    u'<td bgcolor="white" align="center"><img src="%s" title="%s"/></td>' % (self.data.get_imageurl(u'img/icon-stats-crop.png'), u'Fra %d tips:\n%s' % (entry[8] + misses.get(entry[5], 0), entry[6]))
                ]
            html += [
                u'</tr>'
            ]
            idx += 1
            prevscore = entry[0]


        html += [
            u'</table>',
            u'</td></tr>',
            u'</table>'
        ]
        html += [
            u'<table width=480 border="1" cellspacing=0 cellpadding=5 bordercolor="white">',
            u'<tr><td align=right><a title="BBCode 1/2" target="_blank" href="StandingsBBCode.py?idx=%d&mode=series&part=1"><i class="fa fa-code"></i></a> ' % self.__idx,
            u'<a title="BBCode 2/2" target="_blank" href="StandingsBBCode.py?idx=%d&mode=series&part=2"><i class="fa fa-code"></i></a></td></tr>' % self.__idx,
            u'</table>',
            u'<p>'
        ]

        # formtabell

        formlength = 6
        first = max(self.__idx - formlength + 1, 1)

        misses = {}
        score = self.standings.get_score(first, misses)
        matchname = matches[first]['game']
        for i in range(0, len(score)):
            score[i] = (score[i][0],
                        score[i][1],
                        score[i][2],
                        score[i][3],
                        score[i][4],
                        score[i][5],
                        u'%d: %s (%d)' % (self.get_round(first), matchname, score[i][0]),
                        score[i][7],
                        score[i][8])

        if self.__idx > 1:
            for i in range(first+1, self.__idx+1):
                matchname = u'%d: %s' % (self.get_round(i), matches[i]['game'])
                newscore = self.standings.get_score(i, misses)
                score = self.standings.merge_scores(score, newscore, matchname)

        html += [
            u'<table width=480 border="1" cellspacing=0 cellpadding=5 bordercolor="black" background="%s">' % self.data.get_imageurl(u'img/pattern.jpg'),
            u'<tr><td border=0>',
            u'<table width="100%" cellpadding="2" cellspacing=0 border="0">',
            u'<tr><td align="center" colspan="8"><b><font size=+3 color=white>',
            u'Formtabell, runde %d-%d' % (self.get_round(first), self.get_round(self.__idx)),
            u'</font></b></td></tr>'
        ]

        html += self.html_tableheader()

        idx = 1
        plass = 1
        prevscore = 0
        for entry in score:
            if entry[0] != prevscore:
                if plass <= 3 and idx > 3:
                    html += [
                        u'<tr height="5"></tr>',
                        u'<tr height="0" bgcolor="black"><td colspan="8"></td></tr>'
                    ]
                plass = idx

            html += [
                u'<tr height="5"></tr>',
                u'<tr>',
                u'<td bgcolor=white align=center>%d</td>' % plass
            ]
            if entry[7]:
                html += [
                    u'<td bgcolor=white>%s' % entry[5]
                ]
                for jackpot in entry[7].split('\n'):
                    html += [
                        ' <img src="%s" title="%s"/>' % (self.data.get_imageurl(u'img/icon-ball-crop.png'), jackpot)
                    ]
                html += [u'</td>']
            else:
                html += [
                    u'<td bgcolor=white>%s</td>' % entry[5]
                ]
            html += [
                u'<td bgcolor=white align=center>%d</td>' % entry[1],
                u'<td bgcolor=white align=center>%d</td>' % entry[2],
                u'<td bgcolor=white align=center>%d</td>' % entry[3],
                u'<td bgcolor=white align=center>%d</td>' % entry[4],
                u'<td bgcolor=white align=center>%d</td>' % entry[0]
            ]
            if entry[1] == 0:
                html += [
                    u'<td bgcolor=white></td>'
                ]
            else:
                html += [
                    u'<td bgcolor=white align=center><img src="%s" title="%s"/></td>' % (self.data.get_imageurl(u'img/icon-stats-crop.png'), u'Fra %d tips:\n%s' % (entry[8] + misses.get(entry[5], 0), entry[6]))
                ]
            html += [
                u'</tr>'
            ]
            idx += 1
            prevscore = entry[0]


        html += [
            u'</table>',
            u'</td></tr>',
            u'</table>'
        ]
        html += [
            u'<table width=480 border="1" cellspacing=0 cellpadding=5 bordercolor="white">',
            u'<tr><td align=right><a title="BBCode top10" target="_blank" href="StandingsBBCode.py?idx=%d&mode=form"><i class="fa fa-code"></i></a></td></tr>' % self.__idx,
            u'</table>'
        ]

        html += [
            u'</div>'
        ]

        html += self.html_content_close()
        html += self.html_footer()
        html += self.html_body_close()
        return html
Esempio n. 10
0
def standings():
    global standings_buff
    if date is None:
        set_data()
    while True:
        stdscr.clear()
        stdscr.refresh()

        title = "STANDINGS"
        all_st = "1. All standings"
        western = "2. Western conference standings"
        eastern = "3. Eastern conference standings"
        back = "4. Back"
        enter_message = "Enter your choice: "

        stdscr.clear()
        stdscr.refresh()

        to_print = []
        to_print.extend((all_st, western, eastern, back, enter_message))

        start_x = 5

        start_y = 2

        print_title(start_y, start_x, title)

        for item in to_print:
            start_y += 2
            stdscr.addstr(start_y, start_x, item)

        curses.echo()

        stdscr.move(start_y, start_x + len(enter_message))

        tmp = stdscr.getstr(start_y, start_x + len(enter_message), 1)

        option = int(tmp.decode("utf-8"))

        if option == 4:
            return
        elif option != 3 and option != 2 and option != 1:
            wrong_oprion()
            continue
        try:
            standings_var = Standings(server)
            if option == 1:
                standings_buff = standings_var.get_all_standings()
            elif option == 2:
                standings_buff = standings_var.get_western_standings()
            elif option == 3:
                standings_buff = standings_var.get_eastern_standings()

            standings_var.show(standings_buff)
            break
        except NoDataFoundError:
            msg = "No standings information on given date, please change date and try again."
            print_middle(msg)
            stdscr.getch()
        except ConnectionError:
            msg = "Cannot connect to the server"
            print_middle(msg)
            stdscr.getch()
        except TypeError as err:
            msg = 'Type error {}'.format(err)
            print_middle(msg)
            stdscr.getch()
        return