def display_score(self, queue=None, depth=0, table=None, printer=None): flag = False if queue is None: queue = self.get_root() flag = True table = PrettyTable([ "QUEUE", "PENDING AVG", "PENDING DIV", "MEMORY USAGE AVG(Q)", "MEMORY USAGE AVG(C)", "MEMORY USAGE DIV" ]) if table is not None: table.add_row([ queue.tag, 0 if queue.data.get_pending() == 0 else "%.3f" % queue.data.get_pending(), 0 if queue.data.get_pending_div() == 0 else "%.3f" % queue.data.get_pending_div(), 0 if queue.data.get_mem_usage() == 0 else "%.3f" % queue.data.get_mem_usage(), 0 if queue.data.cal_queue_memory_usage() == 0 else "%.3f" % queue.data.cal_queue_memory_usage(), 0 if queue.data.get_mem_usage_div() == 0 else "%.3f" % queue.data.get_mem_usage_div() ]) if not self.is_leaf(queue.tag): children = self.tree.children(queue.tag) for child in children: self.display_score(child, depth + 1, table) if flag: if printer is None: print('------------' + utils.get_str_time() + ' SCORE ----------') print table else: printer.write('\n------------' + utils.get_str_time() + ' SCORE ----------\n') printer.write(str(table))
def write_score_top_down_old(self, queue=None, depth=0, output=None): if queue is None: queue = self.get_root() output.writelines( ('\n---------', utils.get_str_time(), ' SCORE ---------\n')) output.writelines(24 * ' ' + ' SLOWDOWN MEMORY USAGE\n') output.writelines('QUEUE NAME' + 16 * ' ' + ' AVG DIV AVG DIV\n') if depth >= 0: output.writelines(queue.tag + (22 - len(queue.tag))*' ' + \ '%8.3f' % queue.data.get_slowdown() + \ ' %8.3f ' % queue.data.get_slowdown_div() + \ ' %8.3f' % queue.data.get_mem_usage() + \ ' %8.3f' % queue.data.get_mem_usage_div() + '\n') """ output.writelines( (queue.tag, ' (slowdown: %.3f' % queue.data.get_slowdown(), \ ' div: %.3f)' % queue.data.get_slowdown_div(), \ ' (mem usage: %.3f' % queue.data.get_mem_usage(), \ ' div: %.3f)' % queue.data.get_mem_usage_div(), '\n')) """ else: output.writelines(('-'*depth + queue.tag, ' (slowdown: %.3f' % queue.data.get_slowdown(), \ ' div: %.3f)' % queue.data.get_slowdown_div(), \ ' (mem usage: %.3f' % queue.data.get_mem_usage(), \ ' div: %.3f)' % queue.data.get_mem_usage_div(), '\n')) if self.is_leaf(queue.tag) == False: children = self.tree.children(queue.tag) for child in children: self.write_score_top_down(child, depth + 2, output)
def display_score_old(self, queue=None, depth=0): if queue is None: queue = self.get_root() print('------------' + utils.get_str_time() + ' SCORE ----------') print(24 * ' ' + ' SLOWDOWN MEMORY USAGE ') print('QUEUE NAME' + 16 * ' ' + ' AVG DIV AVG DIV') if depth >= 0: print(queue.tag + (22 - len(queue.tag))*' ' + \ '%8.3f' % queue.data.get_slowdown(), \ ' %8.3f ' % queue.data.get_slowdown_div(), \ ' %8.3f' % queue.data.get_mem_usage(), \ ' %8.3f' % queue.data.get_mem_usage_div()) """ print(queue.tag, '(slowdown: %.3f' % queue.data.get_slowdown(), \ 'div: %.3f)' % queue.data.get_slowdown_div(), \ '(mem usage: %.3f' % queue.data.get_mem_usage(), \ 'div: %.3f)' % queue.data.get_mem_usage_div()) """ else: print('-'*depth + queue.tag, '(slowdown: %.3f' % queue.data.get_slowdown(), \ 'div: %.3f)' % queue.data.get_slowdown_div(), \ '(mem usage: %.3f' % queue.data.get_mem_usage(), \ 'div: %.3f)' % queue.data.get_mem_usage_div()) if self.is_leaf(queue.tag) == False: children = self.tree.children(queue.tag) for child in children: self.display_score(child, depth + 2)
def fire(self, data): self.loggings.log('Fire') rec_array = [] new_msgs_dict = self.platform.get_new_msgs() meta = self.default_meta() meta['platform'] = self.platform.class_name for convo_name in new_msgs_dict: ''' expect these types of data (aka medium) to record: -text -img -meta For GroupMe_web: -images are expected when there is an empty line with perhaps just a space character. -emoticons don't appear at all.. just the username and its avatar proceeds it. -message sent times are grouped and always say AM or PM. It assumes the closest specified day of the week or it uses actual date. ALL caps. -A line is a message if it is proceeded by a username. TUE, 4:15 PM Avatar User 1 Name testing message 2, blah ''' # iterate the array of new messages from oldest to newest meta['convo_name'] = convo_name for line in new_msgs_dict[convo_name]: if self.platform.is_timestamp(line): meta['sent_time'] = self.platform.parse_timestamp(line) continue if self.platform.is_username(line): meta['sender'] = self.alias_dict[line] continue if line == 'Avatar': continue rec_time = utils.get_str_time() rec_time_str = utils.datetime2str(rec_time) meta['rec_time'] = rec_time_str.split('-') if line == ' ': meta['medium'] = 'img' '''TODO''' else: meta['medium'] = 'txt' f = utils.mktxt('../database/files/', rec_time_str + '-raw_text.txt', log=0) utils.write_2_file(f, line, no_time=True) utils.pickle_sto('../database/files/', rec_time_str + '-meta.pkl', meta) self.loggings.log(str(meta)) rec_array.append(rec_time) self.skull.publish(self.name, rec_array)
def display_prediction(self, queue=None, depth=0, table=None, printer=None): flag = False if queue is None: queue = self.get_root() flag = True table = PrettyTable([ "QUEUE", "DESIRED CAPACITY(Q)", "DESIRED CAPACITY(C)", "ABS CAPACITY" ]) if table is not None: table.add_row([ queue.tag, str(0 if queue.data.wish.capacity == 0 else "%.3f" % (100 * queue.data.wish.capacity)) + " %", 0 if queue.data.wish.abs_capacity == 0 else "%.3f" % queue.data.wish.abs_capacity, str(0 if queue.data.config.abs_capacity == 0 else "%.3f" % queue.data.config.abs_capacity) + " %" ]) if not self.is_leaf(queue.tag): children = self.tree.children(queue.tag) for child in children: self.display_prediction(child, depth + 1, table) if flag: if printer is None: print('------------' + utils.get_str_time() + ' PREDICTION ----------') print table else: printer.write('\n------------' + utils.get_str_time() + ' PREDICTION ----------\n') printer.write(str(table))
def write_prediction_top_down(self, queue=None, depth=0, output=None): if queue is None: queue = self.get_root() output.writelines(('\n---------', utils.get_str_time(), ' PREDICTION---------\n')) output.writelines('QUEUE NAME DESIRED CAPACITY\n') if depth >= 0: output.writelines(queue.tag + (22 - len(queue.tag)) * ' ' + ' %8.3f' % queue.data.wish.capacity + '\n') # output.writelines( (queue.tag, ' desired capacity: %.3f' % queue.data.wish.capacity, '\n')) else: output.writelines(('-'*depth + queue.tag, \ ' desired capacity: %.3f' % queue.data.wish.capacity, '\n')) if self.is_leaf(queue.tag) == False: children = self.tree.children(queue.tag) for child in children: self.write_prediction_top_down(child, depth + 2, output)
def display_prediction(self, queue=None, depth=0): if queue is None: queue = self.get_root() print('------------' + utils.get_str_time() + ' PREDICTION ----------') print('QUEUE NAME DESIRED CAPACITY') if depth >= 0: print(queue.tag + (22 - len(queue.tag)) * ' ', ' %8.3f' % queue.data.wish.capacity) # print(queue.tag, 'desired capacity: %.3f' % queue.data.wish.capacity) else: print('-' * depth + queue.tag, 'desired capacity: %.3f' % queue.data.wish.capacity) if self.is_leaf(queue.tag) == False: children = self.tree.children(queue.tag) for child in children: self.display_prediction(child, depth + 2)
def write_score_top_down(self, queue=None, depth=0, output=None): if queue is None: queue = self.get_root() output.writelines( ('\n---------', utils.get_str_time(), ' SCORE ---------\n')) output.writelines(24 * ' ' + ' PENDING MEMORY USAGE\n') output.writelines('QUEUE NAME' + 16 * ' ' + ' AVG DIV AVG DIV\n') output.writelines(queue.tag + (22 - len(queue.tag))*' ' + \ '%8.3f' % queue.data.get_pending() + \ ' %8.3f ' % queue.data.get_pending_div() + \ ' %8.3f' % queue.data.get_mem_usage() + \ ' %8.3f' % queue.data.get_mem_usage_div() + '\n') if self.is_leaf(queue.tag) == False: children = self.tree.children(queue.tag) for child in children: self.write_score_top_down(child, depth + 2, output)