Exemplo n.º 1
0
        for file in os.listdir(statsDir):
            if file.endswith('.json'):
                uuid = file[:-5] # cut off '.json' extension
                if (not uuid in players) and (not uuid in excludePlayers):
                    players[uuid] = {}
    except Exception as e:
        print('failed to read player data directory: ' + statsDir)
        handle_error(e, True)

# init event stats
eventStats = []
eventStatByName = dict()
activeEvents = set()

for e in events:
    eventStat = mcstats.EventStat(e.name, e.title, e.stat, e.startTime, e.endTime)

    # load the initial ranking if available
    eventDataFile = os.path.join(dbEventsPath, e.name + '.json')
    if os.path.isfile(eventDataFile):
        with open(eventDataFile) as f:
            eventData = json.load(f)
            eventStat.initialRanking = eventData['initialRanking']
    elif eventStat.hasStarted():
        print('event \"' + e.name + '\" has already started, but no initial ranking is available')

    eventStats.append(eventStat)
    eventStatByName[e.name] = eventStat

    if not eventStat.hasEnded():
        activeEvents.add(e.name)
Exemplo n.º 2
0
if args.stop_event:
    ename = args.stop_event
    if not ename in eventStatByName:
        handle_error('no such event to stop: ' + ename, True)
    elif not eventStatByName[ename].active:
        handle_error('event already stopped: ' + ename, True)

# start new event
if args.start_event:
    ename = args.start_event
    if ename in eventStatByName:
        handle_error('cannot restart existing event: ' + ename, True)

    # register
    # all sanity checks (event stat exists, etc.) have been done before
    e = mcstats.EventStat(
        ename, args.event_title, statByName[args.event_stat])

    eventStats.append(e)
    eventStatByName[ename] = e
    activeEvents.add(ename)

    print('started event: ' + args.event_title + ' (' + ename + ')')

# update player data
serverVersion = 0
hof = mcstats.Ranking()

for uuid, player in players.items():
    # check if data file is available
    dataFilename = mcStatsDir + '/' + uuid + '.json'
    if not os.path.isfile(dataFilename):
Exemplo n.º 3
0
except Exception as e:
    print('failed to read event data directory: ' + dbEventsPath)
    handle_error(e, True)

# possibly start events
for e in events:
    if mcstats.now >= e.startTime and mcstats.now < e.endTime:
        # this event should be running
        if not e.name in activeEvents:
            if e.name in eventStatByName:
                handle_error('ERROR: duplicate event ' + e.name)
                continue

            # ... but it's not - start it
            eventStat = mcstats.EventStat(e.name, e.title, e.stat)
            eventStats.append(eventStat)
            eventStatByName[e.name] = eventStat
            activeEvents.add(e.name)
            print('event "' + e.title + '" (' + e.name + ') has started!')

# update player data
serverVersion = 0
hof = mcstats.Ranking()

for uuid, player in players.items():
    # check if any data files are available and get basic data
    last = 0
    playtimeTicks = 0
    version = 0
    datasets = []