def print_status(scouts, initial_display, jobs): global status state = {'page': 1, 'display': initial_display} # Start another thread to get user input. t = Thread(target=input_processor, name='input_processor', args=(state, )) t.daemon = True t.start() while True: time.sleep(1) if state['display'] == 'logs': continue lines = [] lines.append( "Job queue length: {} | Cached encounters: {} | Mem Usage: {}". format(jobs.qsize(), get_cached_count(), rss_mem_size())) if state['display'] == 'scouts': total_pages = print_scouts(lines, state, scouts) elif state['display'] == 'pokemon': total_pages = print_pokemon(lines, state) # Footer lines.append('Page {}/{}. Page number to switch pages. <enter> to ' 'toggle log view. "p" for Pokemon stats.'.format( state['page'], total_pages)) # Print lines os.system('cls' if os.name == 'nt' else 'clear') print('\n'.join(lines)).encode('utf-8')
def print_status(scouts, initial_display, jobs): global status global default_log_level state = {'page': 1, 'display': initial_display} default_log_level = logging.getLogger().getEffectiveLevel() if initial_display != 'logs': logging.getLogger().setLevel(logging.CRITICAL) # Start another thread to get user input. t = Thread(target=input_processor, name='input_processor', args=(state, )) t.daemon = True t.start() while True: time.sleep(1) if state['display'] == 'logs': continue lines = [] lines.append( "Accepting requests: {} | Job queue length: {} | Cached encounters: {} | Mem Usage: {}" .format(app_state.accept_new_requests, jobs.qsize(), get_cached_count(), rss_mem_size())) if state['display'] == 'scouts': total_pages = print_scouts(lines, state, scouts) elif state['display'] == 'pokemon': total_pages = print_pokemon(lines, state) elif state['display'] == 'queue': total_pages = print_job_queue(lines, state, jobs) # Encounters enctotal = 0 active = 0 for scout in scouts: enctotal = enctotal + (scout.acc.encounters_per_hour if scout.active else 0.0) active = active + (1 if scout.active else 0) if state['display'] == 'scouts': lines.append("") lines.append("Enc/hr Total: {:5.0f} ({} active)".format( enctotal, active)) lines.append("") # Footer lines.append('Page {}/{}. Page number to switch pages. <enter> to ' 'toggle log view. "p" for Pokemon stats.' ' "u" for queue.' ' "t" to toggle accepting new requests.'.format( state['page'], total_pages)) # Print lines os.system('cls' if os.name == 'nt' else 'clear') print('\n'.join(lines)).encode('utf-8')
def print_status(scouts, initial_display, jobs): global status state = { 'page': 1, 'display': initial_display } # Start another thread to get user input. t = Thread(target=input_processor, name='input_processor', args=(state,)) t.daemon = True t.start() while True: time.sleep(1) if state['display'] == 'logs': continue lines = [] lines.append( "Job queue length: {} | Cached encounters: {} | Mem Usage: {}".format( jobs.qsize(), get_cached_count(), rss_mem_size())) if state['display'] == 'scouts': total_pages = print_scouts(lines, state, scouts) elif state['display'] == 'pokemon': total_pages = print_pokemon(lines, state) # Footer lines.append('Page {}/{}. Page number to switch pages. <enter> to ' 'toggle log view. "p" for Pokemon stats.'.format( state['page'], total_pages)) # Print lines os.system('cls' if os.name == 'nt' else 'clear') print ('\n'.join(lines)).encode('utf-8')
def status(page=1): def td(cell): return "<td>{}</td>".format(cell) max_scouts_per_page = 25 max_page = int(math.ceil(len(scouts) / float(max_scouts_per_page))) lines = "<style> th,td { padding-left: 10px; padding-right: 10px; border: 1px solid #ddd; } table { border-collapse: collapse } td { text-align:center }</style>" lines += "<meta http-equiv='Refresh' content='5'>" lines += "Accepting requests: {} | Job queue length: {} | Cached encounters: {} | Mem Usage: {}".format( app_state.accept_new_requests, jobs.qsize(), get_cached_count(), rss_mem_size()) lines += "<br><br>" if cfg_get('proxies'): headers = [ '#', 'Scout', 'Proxy', 'Start', 'Warn', 'Active', 'Encounters', 'Enc/h', 'Errors', 'Last Encounter', 'Message' ] else: headers = [ '#', 'Scout', 'Start', 'Warn', 'Active', 'Encounters', 'Enc/h', 'Errors', 'Last Encounter', 'Message' ] lines += "<table><tr>" for h in headers: lines += "<th>{}</th>".format(h) lines += "</tr>" if page * max_scouts_per_page > len( scouts): #Page number is too great, set to last page page = max_page if page < 1: page = 1 for i in range((page - 1) * max_scouts_per_page, page * max_scouts_per_page): if i >= len(scouts): break lines += "<tr>" s = scouts[i].acc warn = s.get_state('warn') warn_str = '' if warn is None else ('Yes' if warn else 'No') lines += td(i + 1) lines += td(s.username) lines += td(s.proxy_url) if cfg_get('proxies') else "" lines += td(hr_tstamp(s.start_time)) lines += td(warn_str) lines += td('Yes' if scouts[i].active else 'No') lines += td(s.total_encounters) lines += td("{:5.1f}".format(s.encounters_per_hour)) lines += td(s.errors) lines += td(hr_tstamp(s.previous_encounter)) lines += td(s.last_msg.encode('utf-8')) lines += "</tr>" lines += "</table>" # Encounters enctotal = 0 active = 0 for scout in scouts: enctotal = enctotal + (scout.acc.encounters_per_hour if scout.active else 0.0) active = active + (1 if scout.active else 0) lines += "<br>" lines += "Enc/hr Total: {:5.0f} ({} active)".format(enctotal, active) lines += "<br>" if len( scouts ) > max_scouts_per_page: # Use pages if we have more than max_scouts_per_page lines += "Page: " if max_page > 1 and page > 1: lines += "<a href={}><</a> | ".format( url_for('status', page=page - 1)) for p in range(1, max_page + 1): if p == page: lines += str(p) else: url = url_for('status', page=p) lines += "<a href={}>{}</a>".format(url, p) if p < max_page: lines += " | " if max_page > 1 and page < max_page: lines += " | <a href={}>></a>".format( url_for('status', page=page + 1)) return lines