Exemple #1
0
def update_cache(yearnums=0,
                 weeknum=0,
                 skipweek=False,
                 skiptiebreak=False,
                 skipoverall=False,
                 debug=False):
    yearnumlist = [yearnums]
    if isinstance(yearnums, list):
        yearnumlist = yearnums
    if yearnums == 0:
        yearnumlist = get_yearlist()

    weeknumdict = {}
    for yearnum in yearnumlist:
        if weeknum == 0:
            weeknumdict[yearnum] = get_weeklist(yearnum)
        else:
            weeknumdict[yearnum] = [weeknum]

    for yearnum in weeknumdict:
        for weeknum in weeknumdict[yearnum]:
            if not skipweek:
                print "Updating memcache week results      year %d, week %d." % (
                    yearnum, weeknum)
                if not debug: update_memcache_week_results(yearnum, weeknum)
            if not skiptiebreak:
                print "Updating memcache tiebreaks         year %d, week %d." % (
                    yearnum, weeknum)
                if not debug: update_memcache_tiebreak(yearnum, weeknum)
        if not skipoverall:
            print "Updating memcache overall results   year %d." % (yearnum)
            if not debug: update_memcache_overall_results(yearnum)
    def post(self, request):
        form = IndexForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            year_num = int(cd.get('year'))

        week_num = 0
        last_completed_week_num = 0
        last_inprogress_week_num = 0
        yearlist = get_yearlist()
        if year_num in yearlist:
            week_num = 0
            weeklist = get_weeklist(year_num, only_unlocked_picks=True)
            if len(weeklist) > 0:
                week_num = weeklist[-1]
            else:
                year_num = 0
            if year_num:
                db = Database()
                try:
                    for w in weeklist:
                        cr = CalculateResults(db.load_week_data(year_num, w))
                        week_state = cr.get_summary_state_of_all_games()
                        if week_state == FINAL:
                            last_completed_week_num = w
                        elif week_state == IN_PROGRESS:
                            last_inprogress_week_num = w
                except:
                    pass
        profile = get_profile_by_user(user=request.user)
        player_name, player_over_under_list = calc_weekly_points(year_num, request.user.username, overunder=True)
        compare_name, compare_over_under_list = calc_weekly_points(year_num, None, overunder=True)
        context = {
                'year_num': year_num,
                'week_num': week_num,
                'last_completed_week_num': last_completed_week_num,
                'last_inprogress_week_num': last_inprogress_week_num,
                'week_range': range(1, week_num + 1),
                'profile': profile,
                'player_name': player_name,
                'player_over_under_list': player_over_under_list,
                'player_color': '#009999',
                'compare_name': compare_name,
                'compare_over_under_list': compare_over_under_list,
                'compare_color': '#cc0099',
                'form': form,
                }

        return render(request,"pick10/index.html", context)
Exemple #3
0
def flush_cache(yearnums=0,
                weeknum=0,
                skipweek=False,
                skiptiebreak=False,
                skipoverall=False,
                debug=False):
    """Delete memcache contents based on arguments.
    """
    yearnumlist = [yearnums]
    if isinstance(yearnums, list):
        yearnumlist = yearnums
    if yearnums == 0:
        yearnumlist = get_yearlist()

    weeknumdict = {}
    for yearnum in yearnumlist:
        if weeknum == 0:
            weeknumdict[yearnum] = get_weeklist(yearnum)
        else:
            weeknumdict[yearnum] = [weeknum]

    for yearnum in weeknumdict:
        for weeknum in weeknumdict[yearnum]:
            if not skipweek:
                print "Flushing memcache week results      year %d, week %d." % (
                    yearnum, weeknum)
                for keytype in ('private', 'public'):
                    body_key = 'week_%s_%d_%d' % (keytype, yearnum, weeknum)
                    if cache.get(body_key) is not None:
                        print "  Flushing entry %s." % (body_key, )
                        if not debug: cache.delete(body_key)
            if not skiptiebreak:
                print "Flushing memcache tiebreaks         year %d, week %d." % (
                    yearnum, weeknum)
                for keytype in ('private', 'public'):
                    body_key = 'tiebreak_%s_%d_%d' % (keytype, yearnum,
                                                      weeknum)
                    if cache.get(body_key) is not None:
                        print "  Flushing entry %s." % (body_key, )
                        if not debug: cache.delete(body_key)
        if not skipoverall:
            print "Flushing memcache overall results   year %d." % (yearnum)
            for keytype in ('private', 'public'):
                body_key = 'overall_%s_%d' % (keytype, yearnum)
                if cache.get(body_key) is not None:
                    print "  Flushing entry %s." % (body_key, )
                    if not debug: cache.delete(body_key)
Exemple #4
0
def get_playernames_with_years(yearnums=0, debug=False):
    playerdict = {}
    if isinstance(yearnums, list):
        yearnumlist = yearnums
    if yearnums == 0:
        yearnumlist = get_yearlist()

    for yearnum in yearnumlist:
        if debug: print "Parsing %d spreadsheet..." % yearnum
        ss = get_poolspreadsheet(yearnum)
        for playername in ss.get_player_names():
            if playerdict.get(playername) is None:
                playerdict[playername] = [str(yearnum)]
            else:
                playerdict[playername].append(str(yearnum))

    outlines = []
    for playername in sorted(playerdict):
        years_string = ','.join(playerdict[playername])
        outline = "%s: %s" % (playername, years_string)
        if debug: print outline
        outlines.append(outline)

    return '\n'.join(outlines)