Exemplo n.º 1
0
class UpdateDBViewer(AdminViewer):
    def __init__(self, request):
        super(UpdateDBViewer, self).__init__(request)
        #self.layout.main_menu = make_main_menu(self.request).render()
        #self.layout.ctx_menu = make_ctx_menu(self.request).output()
        make_context_menu(self.request)

        self.games = NFLGameManager(self.request.db)
        self.odds = NFLOddsManager(self.request.db)
        self.bets = BetsManager(self.request.db)

        settings = self.get_app_settings()
        url = settings['vignewton.nfl.odds.url']
        self.odds.oddscache.set_url(url)
        url = settings['vignewton.nfl.schedule.url']
        self.games.schedules.set_url(url)

        self.mgr = UpdateDBManager(self.request.db)

        self.context = self.request.matchdict['context']
        # make dispatch table
        self._cntxt_meth = dict(
            main=self.main_view,
            games=self.update_games,
            odds=self.update_odds,
            bets=self.determine_bets,
            report=self.show_update_report,
        )

        if self.context in self._cntxt_meth:
            self._cntxt_meth[self.context]()
        else:
            msg = 'Undefined Context: %s' % self.context
            self.layout.content = '<b>%s</b>' % msg

    def main_view(self):
        self.layout.header = 'Main Update View'
        self.layout.content = 'Main Update View'

    def update_games(self):
        updated = self.games.update_games()
        if updated:
            self.layout.content = 'Game Schedule updated.'
        else:
            self.layout.content = 'No need to update yet.'

    def update_odds(self):
        olist, updated = self.odds.update_current_odds()
        if updated:
            self.layout.content = 'Game Odds updated.'
        else:
            self.layout.content = 'No need to update yet.'

    def determine_bets(self):
        template = 'vignewton:templates/admin-determine-bets.mako'
        clist = self.bets.determine_bets()
        env = dict(bm=self.bets, clist=clist)
        content = self.render(template, env)
        self.layout.content = content

    def show_update_report(self):
        reports = self.mgr.get_all()
        template = 'vignewton:templates/admin-full-update-report.mako'
        env = dict(reports=reports)
        content = self.render(template, env)
        self.layout.content = content
Exemplo n.º 2
0
class UpdateDBViewer(AdminViewer):
    def __init__(self, request):
        super(UpdateDBViewer, self).__init__(request)
        #self.layout.main_menu = make_main_menu(self.request).render()
        #self.layout.ctx_menu = make_ctx_menu(self.request).output()
        make_context_menu(self.request)
        
        self.games = NFLGameManager(self.request.db)
        self.odds = NFLOddsManager(self.request.db)
        self.bets = BetsManager(self.request.db)
        
        settings = self.get_app_settings()
        url = settings['vignewton.nfl.odds.url']
        self.odds.oddscache.set_url(url)
        url = settings['vignewton.nfl.schedule.url']
        self.games.schedules.set_url(url)
        
        self.mgr = UpdateDBManager(self.request.db)
        
        self.context = self.request.matchdict['context']
        # make dispatch table
        self._cntxt_meth = dict(
            main=self.main_view,
            games=self.update_games,
            odds=self.update_odds,
            bets=self.determine_bets,
            report=self.show_update_report,
            )

        if self.context in self._cntxt_meth:
            self._cntxt_meth[self.context]()
        else:
            msg = 'Undefined Context: %s' % self.context
            self.layout.content = '<b>%s</b>' % msg


    def main_view(self):
        self.layout.header = 'Main Update View'
        self.layout.content = 'Main Update View'


    def update_games(self):
        updated = self.games.update_games()
        if updated:
            self.layout.content = 'Game Schedule updated.'
        else:
            self.layout.content = 'No need to update yet.'

    def update_odds(self):
        olist, updated = self.odds.update_current_odds()
        if updated:
            self.layout.content = 'Game Odds updated.'
        else:
            self.layout.content = 'No need to update yet.'
            

    def determine_bets(self):
        template = 'vignewton:templates/admin-determine-bets.mako'
        clist = self.bets.determine_bets()
        env = dict(bm=self.bets, clist=clist)
        content = self.render(template, env)
        self.layout.content = content
        
    def show_update_report(self):
        reports = self.mgr.get_all()
        template = 'vignewton:templates/admin-full-update-report.mako'
        env = dict(reports=reports)
        content = self.render(template, env)
        self.layout.content = content
Exemplo n.º 3
0
class UpdateDBManager(object):
    def __init__(self, session):
        self.session = session
        self.games = NFLGameManager(self.session)
        self.odds = NFLOddsManager(self.session)
        self.bets = BetsManager(self.session)

    def set_schedule_url(self, url):
        self.games.schedules.set_url(url)

    def set_schedule_ttl(self, **kw):
        self.games.schedules.set_ttl(**kw)

    def set_odds_url(self, url):
        self.odds.oddscache.set_url(url)

    def set_odds_ttl(self, **kw):
        self.odds.oddscache.set_ttl(**kw)

    def query(self):
        return self.session.query(UpdateReport)

    def get(self, report_id):
        return self.query().get(report_id)

    def _order_desc_filter(self, query):
        return query.order_by(UpdateReport.created.desc())

    def get_latest(self):
        q = self.query()
        q = self._order_desc_filter(q)
        return q.first()

    def get_all(self):
        q = self.query()
        q = self._order_desc_filter(q)
        return q.all()

    def _add_report(self, content):
        with transaction.manager:
            now = datetime.now()
            ur = UpdateReport()
            ur.created = now
            ur.content = content
            self.session.add(ur)
        return self.session.merge(ur)

    def _update_database(self):
        games_updated = self.games.update_games()
        #games_updated = False
        oddslist, odds_updated = self.odds.update_current_odds()
        determined = self.bets.determine_bets()
        oddslist = [serialize_odds(o) for o in oddslist]
        determined = [serialize_closed_bet(b) for b in determined]
        data = dict(games_updated=games_updated,
                    odds_updated=odds_updated,
                    oddslist=oddslist,
                    determined=determined)
        return data

    def update(self):
        content = self._update_database()
        report = self._add_report(content)
        return report
Exemplo n.º 4
0
class UpdateDBManager(object):
    def __init__(self, session):
        self.session = session
        self.games = NFLGameManager(self.session)
        self.odds = NFLOddsManager(self.session)
        self.bets = BetsManager(self.session)

    def set_schedule_url(self, url):
        self.games.schedules.set_url(url)

    def set_schedule_ttl(self, **kw):
        self.games.schedules.set_ttl(**kw)
        
    def set_odds_url(self, url):
        self.odds.oddscache.set_url(url)

    def set_odds_ttl(self, **kw):
        self.odds.oddscache.set_ttl(**kw)
        
    def query(self):
        return self.session.query(UpdateReport)

    def get(self, report_id):
        return self.query().get(report_id)

    def _order_desc_filter(self, query):
        return query.order_by(UpdateReport.created.desc())
    
    def get_latest(self):
        q = self.query()
        q = self._order_desc_filter(q)
        return q.first()

    def get_all(self):
        q = self.query()
        q = self._order_desc_filter(q)
        return q.all()
    

    def _add_report(self, content):
        with transaction.manager:
            now = datetime.now()
            ur = UpdateReport()
            ur.created = now
            ur.content = content
            self.session.add(ur)
        return self.session.merge(ur)
    
    def _update_database(self):
        games_updated = self.games.update_games()
        #games_updated = False
        oddslist, odds_updated = self.odds.update_current_odds()
        determined = self.bets.determine_bets()
        oddslist = [serialize_odds(o) for o in oddslist]
        determined = [serialize_closed_bet(b) for b in determined]
        data = dict(games_updated=games_updated,
                    odds_updated=odds_updated,
                    oddslist=oddslist, determined=determined)
        return data

    def update(self):
        content = self._update_database()
        report = self._add_report(content)
        return report