Example #1
0
def test_cross_log_boundary():
  '''
    Recover round from previous file *IF*
    - current filename came after previous filename, based on date in name
    - last round in previous filename is *not* empty

  '''
  logfile_1 = 'consolelog-16-02-27-01.txt'
  logfile_2 = 'consolelog-16-02-29-01.txt'
  logfile_3 = 'consolelog-16-03-04-01.txt'

  events_1 = [
      EventRequestMap('ctf_IceBeam', 0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),
  ]

  events_2 = [
      EventScore('Terminator', 'Alpha', 0),
      EventScore('Jim', 'Bravo', 0),

      EventRequestMap('ctf_Ash', 0),
      EventBareLog('ASH', 0),
  ]

  events_3 = [
      EventScore('Blain', 'Alpha', 0),
      EventShutdown(0)
  ]

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop',
      'ctf_Ash': 'ASH',
  }

  round_manager = FakeRoundManager(old_logfile_rounds={})

  decorated_events_1 = list(decorate_events(events_1,
                                            map_titles=map_titles,
                                            round_manager=round_manager,
                                            logfile=logfile_1))
  decorated_events_2 = list(decorate_events(events_2,
                                            map_titles=map_titles,
                                            round_manager=round_manager,
                                            logfile=logfile_2))
  decorated_events_3 = list(decorate_events(events_3,
                                            map_titles=map_titles,
                                            round_manager=round_manager,
                                            logfile=logfile_3))

  decorated_events = decorated_events_1 + decorated_events_2 + decorated_events_3

  assert decorated_events == [
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', 1),
      DecoratedEvent(EventScore('Terminator', 'Alpha', 0), 'ctf_IceBeam', 1),
      DecoratedEvent(EventScore('Jim', 'Bravo', 0), 'ctf_IceBeam', 1),
      DecoratedEvent(EventScore('Blain', 'Alpha', 0), 'ctf_Ash', 2),
  ]

  assert round_manager.finalized_rounds == {1, 2}
Example #2
0
def test_ignore_map():
  events = [
      EventRequestMap('ctf_IceBeam', 0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),

      EventRequestMap('ctf_Ash', 0),
      EventBareLog('ASH', 0),
      EventScore('Foobar', 'Alpha', 0),

      EventRequestMap('Bunker', 0),
      EventBareLog('BUNKER MAP', 0),
      EventScore('Foobar', 'Alpha', 0),
  ]

  ignore_maps = ['ctf_Ash']

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop',
      'ctf_Ash': 'ASH',
      'Bunker': 'BUNKER MAP',
  }

  assert list(decorate_events(events, ignore_maps=ignore_maps, map_titles=map_titles)) == [
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', None),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'Bunker', None),
  ]
Example #3
0
def test_ignore_events_outside_of_round():
  events = [
      EventScore('Foobar', 'Alpha', 0),
  ]

  round_manager = FakeRoundManager()

  assert list(decorate_events(events, round_manager=round_manager)) == []
Example #4
0
def test_ignore_players():
  events = [
      EventPlayerJoin('Joe', None, None, None),
      EventPlayerJoin('Major', None, None, None),
      Kill('Major', 'Zombie', 'MP5', 0),
      Kill('Zombie', 'Major', 'MP5', 0)
  ]

  ignore_players = ['Major']

  assert list(decorate_events(events, ignore_players=ignore_players)) == [
      DecoratedEvent(EventPlayerJoin('Joe', None, None, None), None, None)
  ]
Example #5
0
def test_restart_map_change():
  events = [
      EventRequestMap('ctf_IceBeam', 0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),
      EventRestart(0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),
  ]

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop'
  }

  assert list(decorate_events(events, map_titles)) == [
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', None),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', None),
  ]
Example #6
0
def update_events(r, keys, retention, filemanager, server, verbose):

    # Get raw events out of logs
    parse = ParseEvents(retention, filemanager, r, keys)

    # Manager of HWID <-> Name mappings
    hwid = Hwid(r, keys, verbose)

    # GeoIP lookups
    try:
        geoip_obj = geoip2.database.Reader(
            pkg_resources.resource_filename('piestats.update',
                                            'GeoLite2-Country.mmdb'))
    except Exception as e:
        print 'Failed loading geoip file %s' % e

    # Connect to ftp/ssh or no-op if getting local files
    with filemanager.initialize():

        # Apply events with this
        with MultiProcApplyEvents(r=r, keys=keys, hwid=hwid,
                                  geoip=geoip_obj) as apply_events:

            # Need to get these
            map_titles, flag_score_maps = parse.build_map_names()

            # Maintain round state with this
            round_manager = RoundManager(r=r,
                                         keys=keys,
                                         flag_score_maps=flag_score_maps)

            # Maybe the last round is empty. Delete it if so
            round_manager.tweak_last_round()

            for logfile, events in parse.get_events():
                for decorated_event in decorate_events(
                        events,
                        map_titles=map_titles,
                        ignore_maps=server.ignore_maps,
                        ignore_players=server.ignore_players,
                        round_manager=round_manager,
                        logfile=logfile):
                    apply_events.apply(decorated_event)
Example #7
0
def test_kill():
  round_manager = FakeRoundManager()

  events = [
      EventNextMap('ctf_IceBeam', 0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      Kill('Blain', 'Zombie', 'MP5', 0)
  ]

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop'
  }

  decorated_events = list(decorate_events(events, map_titles=map_titles, round_manager=round_manager))
  assert len(decorated_events) == 1

  my_kill = decorated_events[0]

  assert my_kill.map == 'ctf_IceBeam'
  assert my_kill.round_id == 1
Example #8
0
def test_round_1():
  round_manager = FakeRoundManager()

  events = [
      EventNextMap('ctf_IceBeam', 0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),

      EventNextMap('ctf_Ash', 0),
      EventBareLog('ASH', 0),
      EventScore('Foobar', 'Alpha', 0),
  ]

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop',
      'ctf_Ash': 'ASH'
  }

  assert list(decorate_events(events, map_titles=map_titles, round_manager=round_manager)) == [
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', 1),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_Ash', 2),
  ]
Example #9
0
def test_normal_map_change():
  events = [
      EventScore('Foobar', 'Alpha', 0),
      EventNextMap('ctf_IceBeam', 0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),
      EventNextMap('ctf_Ash', 0),
      EventScore('Foobar', 'Alpha', 0),
      EventBareLog('ASH', 0),
      EventScore('Foobar', 'Alpha', 0),
  ]

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop',
      'ctf_Ash': 'ASH'
  }

  assert list(decorate_events(events, map_titles)) == [
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), None, None),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', None),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', None),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_Ash', None),
  ]
Example #10
0
def test_round_recover():
  logfile = 'consolelog1.txt'

  round_manager = FakeRoundManager(old_logfile_rounds={
      logfile: Round(map='ctf_IceBeam', round_id=5)
  })

  events = [
      EventScore('Foobar', 'Alpha', 0),
      EventRestart(0),
      EventBareLog('IceBeam by Zakath, Suow, Poop', 0),
      EventScore('Foobar', 'Alpha', 0),
  ]

  map_titles = {
      'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop',
  }

  assert list(decorate_events(events, map_titles=map_titles, round_manager=round_manager, logfile=logfile)) == [
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', 5),
      DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', 6),
  ]

  assert round_manager.finalized_rounds == {5}