Beispiel #1
0
def update_hi ( req ):

    # first, work out the template hi file
    # lets try to memoize it, avoid the multi-second runtime mono job incurs us
    thi = plug_hitotext.HiToText ( req, overridepath=paths.templatepath ( req ) )
    memofile = "./runtime/plugins/hitotext/memoize/" + req [ 'gamename' ] + '.memo'

    if os.path.exists ( memofile ):
        logging.debug ( 'HiToText %s - use memoize templates' % ( req [ 'gamename' ] ) )

        f = open ( memofile, 'r' )
        memo = f.read()
        f.close()

        thi.rows = json.loads ( memo )
    else:
        logging.debug ( 'HiToText %s - generate memoize templates' % ( req [ 'gamename' ] ) )

        req [ '_hitotext' ] = thi
        thi.analyze()

        f = open ( memofile, 'w' )
        f.write ( json.dumps ( thi.rows ) )
        f.close()

    # second, work out the scores in the submitted
    hi = plug_hitotext.HiToText ( req )
    req [ '_hitotext' ] = hi
    hi.analyze()

    # how many slots in the table?
    n = len ( hi.rows )

    # for each entry in table
    #   does it look like a new entry? is it already in the template?
    #     if new, send it to singleserver

    for i in range ( n ):

        found = False
        for t in range ( n ):
            if hi.rows [ i ][ 'score' ] == thi.rows [ t ][ 'score' ] and hi.rows [ i ][ 'shortname' ] == thi.rows [ t ][ 'shortname' ]:
                found = True

        if found == False:
            logging.debug ( "%s - incoming slot %d is %s: %s -> looks new" % ( req [ 'gamename' ], i, hi.rows [ i ] [ 'shortname' ], hi.rows [ i ][ 'score' ] ) )
            singlescore_handler.update_hi ( req, int ( hi.rows [ i ][ 'score' ] ) )
        else:
            logging.debug ( "%s - incoming slot %d is %s: %s -> looks like looper" % ( req [ 'gamename' ], i, hi.rows [ i ][ 'shortname' ], hi.rows [ i ][ 'score' ] ) )

    thi.done ( req )
    hi.done ( req )

    return
Beispiel #2
0
def submit_data ( req, argdict ):
    global conf

    argdict [ 'score' ] = int( argdict [ 'score' ] )

    if True:
        logging.debug ( "First update_hi - for actual current month" )
        singlescore_handler.update_hi ( req, score_int = argdict [ 'score' ] )

    if conf [ 'alltime' ]:
        logging.debug ( "Second update_hi - for ALLT.IM" )
        req [ '_backdate' ] = 'ALLTIM'
        singlescore_handler.update_hi ( req, score_int = argdict [ 'score' ] )

    return
def update_hi ( req ):

    # how many slots in the table?
    n = modulemap.gamemap [ req [ 'gamename' ] ][ 'module' ].get_table_slots ( req )

    # keep a copy of bindata since get_hi is destructive right now .. why oh why?!
    bindata = req [ '_bindata' ]

    # get the template table bits..
    template = get_hi ( req )
    thi = list()
    for i in range ( n ):
        d = modulemap.gamemap [ req [ 'gamename' ] ][ 'module' ].get_table_slot_dict ( req, template, i )
        thi.append ( d )

        logging.debug ( "%s template slot %d is %s: %s" % ( req [ 'gamename' ], i, d [ 'shortname' ], d [ 'score' ] ) )

    req [ '_bindata' ] = bindata

    # with luck, we can parse out a single entries block and send that to single-handler; do this once per entry
    # in the hi table, that looks like a new entry

    # for each entry in table
    #   does it look like a new entry? is it already in the template?
    #     if new, send it to singleserver

    for i in range ( n ):
        d = modulemap.gamemap [ req [ 'gamename' ] ][ 'module' ].get_table_slot_dict ( req, bindata, i )

        found = False
        for t in range ( n ):
            if d [ 'score' ] == thi [ t ][ 'score' ] and d [ 'shortname' ] == thi [ t ][ 'shortname' ]:
                found = True

        if found == False:
            logging.debug ( "%s - incoming slot %d is %s: %s -> looks new" % ( req [ 'gamename' ], i, d [ 'shortname' ], d [ 'score' ] ) )
            singlescore_handler.update_hi ( req, int ( d [ 'score' ] ) )
        else:
            logging.debug ( "%s - incoming slot %d is %s: %s -> looks like looper" % ( req [ 'gamename' ], i, d [ 'shortname' ], d [ 'score' ] ) )
Beispiel #4
0
#!/usr/bin/python

import sys
import os

os.chdir ( "/home/skeezix/compo4all" )
sys.path.append ( os.getcwd() )

import modulemap
import singlescore_handler

if len ( sys.argv ) <= 1:
    print "./foo prid gamename scorenum"
    print "run from spagserver.py location"
    sys.exit ( 0 )

req = dict()
req [ 'prid' ] = sys.argv [ 1 ]
req [ 'gamename' ] = sys.argv [ 2 ]
hi = int( sys.argv [ 3 ] )

print "Attempting insert of score %s" % ( hi )

singlescore_handler.update_hi ( req, score_int=hi )