Example #1
0
        key = line.strip()
    else:
        q_value = np.array(json.loads(line.strip()))
        if np.sum(q_value) == 0:
            quality_json = '0'
        else:
            quality_dict = {}
            for j, q in enumerate(q_value):
                if q != 0:
                    quality_dict[j] = q
            quality_json = json.dumps(quality_dict)

        # Insert a row of data
        c.execute(
            "INSERT INTO t_quality VALUES " + "('%s', '%s', %d, '%s', %d)" %
            ((KoreanChess.compress_state_key(key), quality_json, len(q_value),
              datetime.datetime.now().strftime('%Y-%m-%d %H:%I:%S'), 1)))
    i += 1

q_file.close()

# Save (commit) the changes
conn.commit()

# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
conn = sqlite3.connect('./q_red.db')

c = conn.cursor()
Example #2
0
import sqlite3
import os
import json
import numpy as np
import datetime
from env.korean_chess import KoreanChess

q_file = open('./q_blue_with_data.txt')
compress_q_file = open('./q_blue_with_data_comp.txt', mode='w')
i = 0
key = None
for line in q_file:
    if i % 2 is 0:
        key = line.strip()
        compress_q_file.write(KoreanChess.compress_state_key(key) + "\n")
    else:
        compress_q_file.write(line.strip() + "\n")
    i += 1

compress_q_file.close()
q_file.close()

q_file = open('./q_red_with_data.txt')
compress_q_file = open('./q_red_with_data_comp.txt', mode='w')
i = 0
key = None
for line in q_file:
    if i % 2 is 0:
        key = line.strip()
        compress_q_file.write(KoreanChess.compress_state_key(key) + "\n")
    else: