def sort_data(dataset): print("Sorting data into database...") sort_data_time_start = time.time() sql_connection = sqlite3.connect(database.db_name) cur = sql_connection.cursor() # Lets not f**k up sorted data by creating duplicate data if cur.execute('select count(*) from data;').fetchall()[0][0] != 0: print("There is already rows in the table...") return for set_num, data in enumerate(dataset): print("Sorting set",set_num) sort_data_set_time_start = time.time() for section_number, section in enumerate(data.get_values()): try: threshold = jmath.get_peak_threshold(section) except ZeroDivisionError: # Skip section if stddev is not possible break for pos, value in enumerate(section): classification = 'peak' if value > threshold else 'nopeak' cur.execute("insert into data ('value','vector','class') values (?,?,?)",[value, json.dumps(get_vector(section, pos, jmath.vector_length)), classification]) sql_connection.commit() print("Sorting set",set_num,"took",time.time()-sort_data_set_time_start,"seconds...") sql_connection.close() print("Sorting all sets took",time.time()-sort_data_time_start,"seconds...")
def get_classification(numbers, value): if value > jmath.get_peak_threshold(numbers): return "peak" return "nopeak"