Пример #1
0
class PlayerService:
    def __init__(self):
        self.log = Log()
        self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                    config.AZURE_STORAGE_ACCOUNT_KEY,
                                    config.AZURE_STORAGE_SUMMARY_TABLE_NAME)

    def getPlayer(self, gamertag):
        player = {"gamertag": gamertag, "stats": self.getStats(gamertag)}
        return player

    def getStats(self, gamertag):
        stats = []
        count_type = gamertag + "matchwon"
        count = self.summary.getCount(count_type)
        stats.append({"Wins": count})

        count_type = gamertag + "matchtied"
        count = self.summary.getCount(count_type)
        stats.append({"Ties": count})

        count_type = gamertag + "matchlost"
        count = self.summary.getCount(count_type)
        stats.append({"Lost": count})

        count_type = gamertag + "matchDNF"
        count = self.summary.getCount(count_type)
        stats.append({"DNF": count})

        return stats
Пример #2
0
 def __init__(self):
     self.log = Log()
     self.msgQueue = Queue(account_name=config.AZURE_STORAGE_ACCOUNT_NAME,
                           account_key=config.AZURE_STORAGE_ACCOUNT_KEY,
                           queue_name=config.HALO_QUEUE_MATCH)
     self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                 config.AZURE_STORAGE_ACCOUNT_KEY,
                                 config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
Пример #3
0
def increment_match_count(gamertag, amount = 1):
    """
    Get the count of matches we are aware of for a given player.
    """
    summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
    count = get_match_count(gamertag)
    count = count + amount
    count_type = gamertag + "_match"
    summary.updateCount(count_type, count)
Пример #4
0
 def __init__(self):
   self.log = Log()
   self.log.debug("Storage account for analyzer: {0}".format(config.AZURE_STORAGE_ACCOUNT_NAME))
   self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME)
   self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
   self.keep_running = bool(config.ANALYZER_KEEP_RUNNING)
   self.log.debug("Analyzer keep running: {0}".format(self.keep_running))
   if self.keep_running:
     self.sleep_time = float(config.ANALYZER_SLEEP_TIME)
     self.log.debug("Sleep time between analyses: {0}".format(self.sleep_time))
Пример #5
0
def printSummary():
  table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
  queue_service = getQueueService()
  summary = "Queue Length is approximately: " + queue_service.getLength() + "\n\n"
  summary = summary + "Processed events:\n"
  summary = summary + "Errors: " + str(table.getCount("ERROR")) + "\n"
  summary = summary + "Warnings: " + str(table.getCount("WARNING")) + "\n"
  summary = summary + "Infos: " + str(table.getCount("INFO")) + "\n"
  summary = summary + "Debugs: " + str(table.getCount("DEBUG")) + "\n"
  summary = summary + "Others: " + str(table.getCount("OTHER")) + "\n"
  print(summary)
  notify.info(summary)
Пример #6
0
class MatchAnalyzer:
    def __init__(self):
        self.log = Log()
        self.msgQueue = Queue(account_name=config.AZURE_STORAGE_ACCOUNT_NAME,
                              account_key=config.AZURE_STORAGE_ACCOUNT_KEY,
                              queue_name=config.HALO_QUEUE_MATCH)
        self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                    config.AZURE_STORAGE_ACCOUNT_KEY,
                                    config.AZURE_STORAGE_SUMMARY_TABLE_NAME)

    def processMatch(self, match):
        gamertag = match["Players"][0]["Player"]["Gamertag"]
        result_code = match["Players"][0]["Result"]
        if result_code == 3:
            result = 'won'
        elif result_code == 2:
            result = 'tied'
        elif result_code == 1:
            result = 'lost'
        else:
            result = 'DNF'
        count_type = gamertag + 'match' + result
        count = self.summary.getCount(count_type)
        count = count + 1
        self.summary.updateCount(count_type, count)
        print(count_type + ' is now ' + str(count))

    def fullAnalysis(self):
        while True:
            matches = self.msgQueue.dequeue()
            if len(matches) > 0:
                for match_event_raw in matches:
                    match_event = json.loads(match_event_raw.message_text)
                    match = json.loads(match_event["data"])
                    # print("Processing:\n" + json.dumps(match, sort_keys=True, indent=4))
                    try:
                        self.processMatch(match)
                        self.msgQueue.delete(match_event_raw)
                    except:
                        e = sys.exc_info()[0]
                        self.log.error("Could not process: " +
                                       match_event_raw.message_text +
                                       " because %s" % e)
                        traceback.print_exc(file=sys.stdout)
            else:
                break

    def getPlayerStats(self, gamertag):
        stats = {}
        stats.player = {"gamertag": gamertag}
        count_type = gamertag + "won"
        count = self.summary, getCount(count_type)
        print(str(count), wins)
Пример #7
0
class Analyzer:
  def __init__(self):
    self.log = Log()
    self.log.debug("Storage account for analyzer: {0}".format(config.AZURE_STORAGE_ACCOUNT_NAME))
    self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME)
    self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
    self.keep_running = bool(config.ANALYZER_KEEP_RUNNING)
    self.log.debug("Analyzer keep running: {0}".format(self.keep_running))
    if self.keep_running:
      self.sleep_time = float(config.ANALYZER_SLEEP_TIME)
      self.log.debug("Sleep time between analyses: {0}".format(self.sleep_time))

  def incrementCount(self, event_type):
    count = self.summary.getCount(event_type)
    count = count + 1
    self.summary.updateCount(event_type, count)
    self.log.info(event_type + " count is now " + str(count))

  def processEvent(self, message):
    msg = message.message_text

    split = msg.find(" - ")
    if (not split):
      event_type = "OTHER"
    else:
      event_type = msg[:split]    
      
    # Sleep to simulated a longer running process
    time.sleep(self.sleep_time)

    self.incrementCount(event_type)

  def fullAnalysis(self):
    hostname = socket.gethostname()
    msg = hostname + ': Analyzing log event queue'
    notify.info(msg)
    while True:
      events = self.msgQueue.dequeue()
      if len(events) > 0:
        for event in events:
          self.log.info("Dequeued: " + event.message_text)
          try:
            self.processEvent(event)
            self.msgQueue.delete(event)
            self.log.info("Counted and deleted: " + event.message_text)
          except:
            e = sys.exc_info()[0]
            self.log.error("Could not process: " + event.message_text + " because %s" % e)
            traceback.print_exc(file=sys.stdout)
      else:
          break
      time.sleep(self.sleep_time)   
Пример #8
0
def updateSlack():
  log = Log()
  table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
  queue_service = getQueueService()
  summary = "Processing Status [" + str(time.ctime()) + "]\n\n"
  summary = summary + "Queue Length is approximately: " + queue_service.getLength() + "\n"
  summary = summary + "Errors: " + str(table.getCount("ERROR")) + "\n"
  summary = summary + "Warnings: " + str(table.getCount("WARNING")) + "\n"
  summary = summary + "Infos: " + str(table.getCount("INFO")) + "\n"
  summary = summary + "Debugs: " + str(table.getCount("DEBUG")) + "\n"
  summary = summary + "Others: " + str(table.getCount("OTHER")) + "\n"
  print(summary)
  notify.info(summary)
Пример #9
0
 def __init__(self):
     self.log = Log()
     self.log.debug("Storage account for analyzer: {0}".format(
         config.AZURE_STORAGE_ACCOUNT_NAME))
     self.msgQueue = Queue(account_name=config.AZURE_STORAGE_ACCOUNT_NAME,
                           account_key=config.AZURE_STORAGE_ACCOUNT_KEY,
                           queue_name=config.AZURE_STORAGE_QUEUE_NAME)
     self.current_length = self.msgQueue.getLength()
     self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                 config.AZURE_STORAGE_ACCOUNT_KEY,
                                 config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
     self.sleep_time = float(config.ANALYZER_SLEEP_TIME)
     self.log.debug("Sleep time between analyses: {0}".format(
         self.sleep_time))
Пример #10
0
class TestSummaryTable(unittest.TestCase):

  @classmethod
  def setUpClass(self):
    self.event_type = "test"
    self.table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, 'testharness')

  def test_create(self):
    raised = False
    try: 
      self.table.getCount(self.event_type)
    except Exception, err:
      sys.stderr.write('ERROR: %sn' % str(err))
      raised = True
    self.assertFalse(raised, 'Exception raised')
Пример #11
0
class MatchAnalyzer:

    def __init__(self):
        self.log = Log()
        self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.HALO_QUEUE_MATCH)
        self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)

    def processMatch(self, match):
        gamertag = match["Players"][0]["Player"]["Gamertag"]
        result_code = match["Players"][0]["Result"]
        if result_code == 3:
            result = 'won'
        elif result_code == 2:
            result = 'tied'
        elif result_code == 1:
            result = 'lost'
        else:
            result = 'DNF'
        count_type = gamertag + 'match' + result
        count = self.summary.getCount(count_type)
        count = count + 1
        self.summary.updateCount(count_type, count)
        print(count_type + ' is now ' + str(count))
        
    def fullAnalysis(self):
        while True:
            matches = self.msgQueue.dequeue()
            if len(matches) > 0:
                for match_event_raw in matches:
                    match_event = json.loads(match_event_raw.message_text)
                    match = json.loads(match_event["data"])
                    # print("Processing:\n" + json.dumps(match, sort_keys=True, indent=4))
                    try:
                        self.processMatch(match)
                        self.msgQueue.delete(match_event_raw)
                    except:
                        e = sys.exc_info()[0]
                        self.log.error("Could not process: " + match_event_raw.message_text + " because %s" % e)
                        traceback.print_exc(file=sys.stdout)
            else:
                break

    def getPlayerStats(self, gamertag):
        stats = {}
        stats.player = { "gamertag": gamertag }
        count_type = gamertag + "won"
        count = self.summary,getCount(count_type)
        print(str(count), wins)
Пример #12
0
class TestSummaryTable(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.event_type = "test"
        self.table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                  config.AZURE_STORAGE_ACCOUNT_KEY,
                                  'testharness')

    def test_create(self):
        raised = False
        try:
            self.table.getCount(self.event_type)
        except Exception, err:
            sys.stderr.write('ERROR: %sn' % str(err))
            raised = True
        self.assertFalse(raised, 'Exception raised')
Пример #13
0
class Analyzer:
  def __init__(self):
    self.log = Log()
    self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME)
    self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)

  def incrementCount(self, event_type):
    count = self.summary.getCount(event_type)
    count = count + 1
    self.summary.updateCount(event_type, count)
    self.log.info(event_type + " count is now " + str(count))

  def processEvent(self, message):
    msg = message.message_text

    if msg.startswith("ERROR"):
      event_type = "ERROR"
    elif msg.startswith("WARNING"):
      event_type = "WARNING"
    elif msg.startswith("INFO"):
      event_type = "INFO"
    elif msg.startswith("DEBUG"):
      event_type = "DEBUG"
    else:
      event_type = "OTHER"

    self.incrementCount(event_type)

  def fullAnalysis(self):
    hostname = socket.gethostname()
    msg = hostname + ': Analyzing log event queue'
    notify.info(msg)
    while True:
      events = self.msgQueue.dequeue()
      if len(events) > 0:
        for event in events:
          self.log.info("Dequeued: " + event.message_text)
          try:
            self.processEvent(event)
            self.msgQueue.delete(event)
            self.log.info("Counted and deleted: " + event.message_text)
          except:
            e = sys.exc_info()[0]
            self.log.error("Could not process: " + event.message_text + " because %s" % e)
            traceback.print_exc(file=sys.stdout)
      else:
        break 
Пример #14
0
 def __init__(self):
   self.log = Log()
   self.log.info("Storage account: {0}".format(config.AZURE_STORAGE_ACCOUNT_NAME))
   self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME)
   self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
   self.keep_running = bool(config.ANALYZER_KEEP_RUNNING)
   self.log.info("Keep running: {0}".format(self.keep_running))
   if self.keep_running:
     self.sleep_time = float(config.ANALYZER_SLEEP_TIME)
     self.log.info("Sleep time between analyses: {0}".format(self.sleep_time))
Пример #15
0
def createTable():
    log.debug("Creating table named: " +
              config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
    table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                         config.AZURE_STORAGE_ACCOUNT_KEY,
                         config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
Пример #16
0
def getTableService():
    return SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                        config.AZURE_STORAGE_ACCOUNT_KEY,
                        config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
Пример #17
0
 def __init__(self):
     self.log = Log()
     self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                 config.AZURE_STORAGE_ACCOUNT_KEY,
                                 config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
Пример #18
0
 def setUpClass(self):
   self.event_type = "test"
   self.table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, 'testharness')
Пример #19
0
    if not (0 < dist < sys.maxsize):
        print("continue")
        continue

    print("good loop")

    if dist <= 2000:
        if len(listSmall) < 5:
            print("list small:", dist)
            values = valuesCalculator(graph, source, target)
            listSmall.update({(source.index, target.index): values})
    elif 2000 < dist <= 5000:
        if len(listMedium) < 5:
            print("list medium:", dist)
            values = valuesCalculator(graph, source, target)
            listMedium.update({(source.index, target.index): values})
    else:
        if len(listBig) < 5:
            print("list big:", dist)
            values = valuesCalculator(graph, source, target)
            listBig.update({(source.index, target.index): values})

    if len(listSmall) == 5 and len(listMedium) == 5 and len(listBig) == 5:
        condition = not condition
        summary = {**listSmall, **listMedium, **listBig}

print(summary)
app = SummaryTable(summary)
app.mainloop()
Пример #20
0
 def setUpClass(self):
     self.event_type = "test"
     self.table = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                               config.AZURE_STORAGE_ACCOUNT_KEY,
                               'testharness')
Пример #21
0
def get_match_count(gamertag):
    summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
    count_type = gamertag + "_match"
    return summary.getCount(count_type)
Пример #22
0
 def __init__(self):
     self.log = Log()
     self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.HALO_QUEUE_MATCH)
     self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME, config.AZURE_STORAGE_ACCOUNT_KEY, config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
Пример #23
0
class Analyzer:

    time_since_last_event = None
    last_event_time = time.time()
    current_length = 0
    last_length = 0
    max_length = 10

    def __init__(self):
        self.log = Log()
        self.log.debug("Storage account for analyzer: {0}".format(
            config.AZURE_STORAGE_ACCOUNT_NAME))
        self.msgQueue = Queue(account_name=config.AZURE_STORAGE_ACCOUNT_NAME,
                              account_key=config.AZURE_STORAGE_ACCOUNT_KEY,
                              queue_name=config.AZURE_STORAGE_QUEUE_NAME)
        self.current_length = self.msgQueue.getLength()
        self.summary = SummaryTable(config.AZURE_STORAGE_ACCOUNT_NAME,
                                    config.AZURE_STORAGE_ACCOUNT_KEY,
                                    config.AZURE_STORAGE_SUMMARY_TABLE_NAME)
        self.sleep_time = float(config.ANALYZER_SLEEP_TIME)
        self.log.debug("Sleep time between analyses: {0}".format(
            self.sleep_time))

    def incrementCount(self, event_type):
        count = self.summary.getCount(event_type)
        count = count + 1
        self.summary.updateCount(event_type, count)
        self.log.info(event_type + " count is now " + str(count))

    def processEvent(self, message):
        # Sleep to simulated a longer running process
        time.sleep(self.sleep_time)

        data = json.loads(message.message_text)
        event_type = data["type"]
        now = time.time() * 1000.0
        duration = now - data["time"]
        print("Duration of last event processing: " + str(duration))

        self.incrementCount(event_type)
        self.summary.updateLastProcessingTime(duration)

    def fullAnalysis(self):
        hostname = socket.gethostname()
        msg = hostname + ': Analyzing log event queue'
        notify.info(msg)
        while True:
            self.last_length = self.current_length
            self.current_length = self.msgQueue.getLength()
            if self.current_length > 0:
                events = self.msgQueue.dequeue()
                if len(events) > 0:
                    now = time.time()
                    for event in events:
                        self.time_since_last_event = now - self.last_event_time
                        self.last_event_time = now
                        self.log.info("Dequeued: " + event.message_text)
                        try:
                            self.processEvent(event)
                            self.msgQueue.delete(event)
                            self.current_length = self.current_length - 1
                            self.log.info("Counted and deleted: " +
                                          event.message_text)
                        except:
                            e = sys.exc_info()
                            self.log.error("Could not process: " +
                                           event.message_text +
                                           " because %s" % e[0])
                            self.log.error(traceback.format_tb(e[2]))
            time.sleep(self.sleep_time)