qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator(cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band(cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) sys.exit(1) finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None try: # image_data, image_size = n1mm_view_graphs.qso_summary_table(size, qso_band_modes) # image_data, image_size = n1mm_view_graphs.qso_rates_table(size, operator_qso_rates)
def load_data(size, q, last_qso_timestamp): """ load data from the database tables """ logging.debug('load data') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} db = None data_updated = False try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) logging.debug('old_timestamp = %d, timestamp = %d', last_qso_timestamp, last_qso_time) if last_qso_time != last_qso_timestamp: logging.debug('data updated!') data_updated = True q.put((CRAWL_MESSAGE, 3, message)) # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator(cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band(cursor) # load QSOs by Section # This has to be done even if no new QSO to advance gray line and since the map is always drawn. qsos_by_section = dataaccess.get_qsos_by_section(cursor) q.put((CRAWL_MESSAGE, 0, '')) logging.debug('load data done') except sqlite3.OperationalError as error: if error.args is not None and error.args[0].startswith('no such table'): q.put((CRAWL_MESSAGE, 0, 'database not ready', graphics.YELLOW, graphics.RED)) else: logging.error(error.args[0]) logging.exception(error) q.put((CRAWL_MESSAGE, 0, 'database read error', graphics.YELLOW, graphics.RED)) return finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None if data_updated: try: image_data, image_size = graphics.qso_summary_table(size, qso_band_modes) enqueue_image(q, QSO_COUNTS_TABLE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_table(size, operator_qso_rates) enqueue_image(q, QSO_RATES_TABLE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_graph(size, qso_operators) enqueue_image(q, QSO_OPERATORS_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_table(size, qso_operators) enqueue_image(q, QSO_OPERATORS_TABLE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_stations_graph(size, qso_stations) enqueue_image(q, QSO_STATIONS_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_bands_graph(size, qso_band_modes) enqueue_image(q, QSO_BANDS_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_modes_graph(size, qso_band_modes) enqueue_image(q, QSO_MODES_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_chart(size, qsos_per_hour) enqueue_image(q, QSO_RATE_CHART_IMAGE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.draw_map(size, qsos_by_section) enqueue_image(q, SECTIONS_WORKED_MAP_INDEX, image_data, image_size) gc.collect() except Exception as e: logging.exception(e) return last_qso_time
def create_images(size, image_dir, base_map, last_qso_timestamp): """ load data from the database tables """ logging.debug('load data') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} db = None data_updated = False try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) logging.debug('old_timestamp = %d, timestamp = %d', last_qso_timestamp, last_qso_time) if last_qso_time != last_qso_timestamp: logging.debug('data updated!') data_updated = True # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator( cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band( cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) return finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None if data_updated: try: image_data, image_size = graphics.qso_summary_table( size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_summary_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_table( size, operator_qso_rates) filename = makePNGTitle(image_dir, 'qso_rates_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_graph( size, qso_operators) filename = makePNGTitle(image_dir, 'qso_operators_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_table( size, qso_operators) filename = makePNGTitle(image_dir, 'qso_operators_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_stations_graph( size, qso_stations) filename = makePNGTitle(image_dir, 'qso_stations_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_bands_graph( size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_bands_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_modes_graph( size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_modes_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_chart( size, qsos_per_hour) filename = makePNGTitle(image_dir, 'qso_rates_chart') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) # map gets updated every time so grey line moves try: # There is a memory leak in the next code -- is there? image_data, image_size = graphics.draw_map(size, qsos_by_section, base_map) filename = makePNGTitle(image_dir, 'sections_worked_map') graphics.save_image(image_data, image_size, filename) gc.collect() except Exception as e: logging.exception(e) if data_updated: if config.POST_FILE_COMMAND is not None: os.system(config.POST_FILE_COMMAND) return last_qso_time
def create_images(size, image_dir, last_qso_timestamp): """ load data from the database tables """ logging.debug('load data') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} db = None data_updated = False try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # Handy routine to dump the database to help debug strange problems #if logging.getLogger().isEnabledFor(logging.DEBUG): # cursor.execute('SELECT timestamp, callsign, section, operator_id, operator.name FROM qso_log join operator WHERE operator.id = operator_id') # for row in cursor: # logging.debug('QSO: %s\t%s\t%s\t%s\t%s' % (row[0], row[1], row[2], row[3], row[4])) # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) logging.debug('old_timestamp = %d, timestamp = %d', last_qso_timestamp, last_qso_time) if last_qso_time != last_qso_timestamp: # last_qso_time is passed as the result and updated in call to this function. logging.debug('data updated!') data_updated = True # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator( cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band( cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) return finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None if data_updated: try: image_data, image_size = graphics.qso_summary_table( size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_summary_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_table( size, operator_qso_rates) filename = makePNGTitle(image_dir, 'qso_rates_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_graph( size, qso_operators) filename = makePNGTitle(image_dir, 'qso_operators_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_table( size, qso_operators) filename = makePNGTitle(image_dir, 'qso_operators_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_stations_graph( size, qso_stations) filename = makePNGTitle(image_dir, 'qso_stations_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_bands_graph( size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_bands_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_modes_graph( size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_modes_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_chart( size, qsos_per_hour) filename = makePNGTitle(image_dir, 'qso_rates_chart') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) # map gets updated every time so grey line moves try: # There is a memory leak in the next code -- is there? image_data, image_size = graphics.draw_map(size, qsos_by_section) filename = makePNGTitle(image_dir, 'sections_worked_map') graphics.save_image(image_data, image_size, filename) gc.collect() except Exception as e: logging.exception(e) #if data_updated: # Data is always updated since the sections map is always updated. Let rsync command handle this. if config.POST_FILE_COMMAND is not None: os.system(config.POST_FILE_COMMAND) return last_qso_time
def load_data(size, q, base_map, last_qso_timestamp): """ load data from the database tables """ logging.debug('load data') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} db = None data_updated = False try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) logging.debug('old_timestamp = %d, timestamp = %d', last_qso_timestamp, last_qso_time) if last_qso_time != last_qso_timestamp: logging.debug('data updated!') data_updated = True q.put((CRAWL_MESSAGE, 3, message)) # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator(cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band(cursor) # load QSOs by Section # This has to be done even if no new QSO to advance gray line and since the map is always drawn. qsos_by_section = dataaccess.get_qsos_by_section(cursor) q.put((CRAWL_MESSAGE, 0, '')) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) q.put((CRAWL_MESSAGE, 0, 'database read error', graphics.YELLOW, graphics.RED)) return finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None if data_updated: try: image_data, image_size = graphics.qso_summary_table(size, qso_band_modes) enqueue_image(q, QSO_COUNTS_TABLE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_table(size, operator_qso_rates) enqueue_image(q, QSO_RATES_TABLE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_graph(size, qso_operators) enqueue_image(q, QSO_OPERATORS_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_table(size, qso_operators) enqueue_image(q, QSO_OPERATORS_TABLE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_stations_graph(size, qso_stations) enqueue_image(q, QSO_STATIONS_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_bands_graph(size, qso_band_modes) enqueue_image(q, QSO_BANDS_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_modes_graph(size, qso_band_modes) enqueue_image(q, QSO_MODES_PIE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_chart(size, qsos_per_hour) enqueue_image(q, QSO_RATE_CHART_IMAGE_INDEX, image_data, image_size) except Exception as e: logging.exception(e) try: # There is a memory leak in the next code -- is there? image_data, image_size = graphics.draw_map(size, qsos_by_section, base_map) enqueue_image(q, SECTIONS_WORKED_MAP_INDEX, image_data, image_size) gc.collect() except Exception as e: logging.exception(e) return last_qso_time
# load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator( cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band( cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) sys.exit(1) finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None try: # image_data, image_size = n1mm_view_graphs.qso_summary_table(size, qso_band_modes) # image_data, image_size = n1mm_view_graphs.qso_rates_table(size, operator_qso_rates)
def create_images(size, image_dir, base_map, last_qso_timestamp): """ load data from the database tables """ logging.debug('load data') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} db = None data_updated = False try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) logging.debug('old_timestamp = %d, timestamp = %d', last_qso_timestamp, last_qso_time) if last_qso_time != last_qso_timestamp: logging.debug('data updated!') data_updated = True # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator(cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band(cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) return finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None if data_updated: try: image_data, image_size = graphics.qso_summary_table(size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_summary_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_table(size, operator_qso_rates) filename = makePNGTitle(image_dir, 'qso_rates_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_graph(size, qso_operators) filename = makePNGTitle(image_dir, 'qso_operators_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_operators_table(size, qso_operators) filename = makePNGTitle(image_dir, 'qso_operators_table') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_stations_graph(size, qso_stations) filename = makePNGTitle(image_dir, 'qso_stations_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_bands_graph(size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_bands_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_modes_graph(size, qso_band_modes) filename = makePNGTitle(image_dir, 'qso_modes_graph') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) try: image_data, image_size = graphics.qso_rates_chart(size, qsos_per_hour) filename = makePNGTitle(image_dir, 'qso_rates_chart') graphics.save_image(image_data, image_size, filename) except Exception as e: logging.exception(e) # map gets updated every time so grey line moves try: # There is a memory leak in the next code -- is there? image_data, image_size = graphics.draw_map(size, qsos_by_section, base_map) filename = makePNGTitle(image_dir, 'sections_worked_map') graphics.save_image(image_data, image_size, filename) gc.collect() except Exception as e: logging.exception(e) if data_updated: if config.POST_FILE_COMMAND is not None: os.system(config.POST_FILE_COMMAND) return last_qso_time
def main(): logging.info('dashboard startup') try: screen, size = graphics.init_display() except Exception as e: logging.exception('Could not initialize display.', exc_info=e) sys.exit(1) display_size = (size[0], size[1]) logging.debug('display setup') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} logging.debug('load data') db = None cursor = None try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator( cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band( cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) sys.exit(1) finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None try: # image_data, image_size = graphics.qso_summary_table(size, qso_band_modes) # image_data, image_size = graphics.qso_rates_table(size, operator_qso_rates) # image_data, image_size = graphics.qso_operators_graph(size, qso_operators) # image_data, image_size = graphics.qso_operators_table(size, qso_operators) # image_data, image_size = graphics.qso_stations_graph(size, qso_stations) # image_data, image_size = graphics.qso_bands_graph(size, qso_band_modes) # image_data, image_size = graphics.qso_modes_graph(size, qso_band_modes) # image_data, image_size = graphics.qso_rates_chart(size, qsos_per_hour) image_data, image_size = graphics.draw_map(size, qsos_by_section) # gc.collect() image = pygame.image.frombuffer(image_data, image_size, 'RGB') graphics.show_graph(screen, size, image) pygame.display.flip() # wait for a key press run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break elif event.type == pygame.KEYDOWN: if event.key == ord('q'): logging.debug('Q key pressed') run = False else: logging.debug('event key=%d', event.key) except Exception as e: logging.exception("Exception in main:", exc_info=e) pygame.display.quit() logging.info('one_chart exit')