import sys
import json
from cassandra.cluster import Cluster

sys.path.append("config/db")

from db_read_csv_txs import db_insert_csv_txs
import os


config = json.load(open("./settings.json"))

cluster = Cluster(config['cassandra_addresses'],
                    port=config['cassandra_port'])
session = cluster.connect(config['cassandra_keyspace'])
print(f"Connection OK")

file = "/home/osboxes/Downloads/zec_tx_inputs.csv"
num_rows = 128

db_insert_csv_txs(config, file, skip=0, limit=num_rows)

algorithms = [
    'rik_merge',
    'sve_merge',
    'hoc_merge',
    'nik_merge',
    'rob_merge',
    'agf_merge',
    'agf_opt_merge',
    'che_merge',
    'ale_merge',
    'nik_rew_merge_skip'
]

for algo in algorithms:
    os.system(f"mkdir -p benchmarks/partition/{algo}")

for i in range(16):
    for algo in algorithms:
        os.system(f"ALGO={algo} ./submit_partition.sh | sed '1d' | sed '2d' > benchmarks/partition/{algo}/{num_rows}.txt")
        os.system(f"rm -rf ./checkpoints")
    #os.system(f"./submit_graph.sh | sed '1d' | sed '2d' > benchmarks/graph/{num_rows}.txt")
    #os.system(f"rm -rf ./checkpoints")

    db_insert_csv_txs(config, file, skip=num_rows, limit=num_rows*2)
    num_rows = num_rows*2
    print(num_rows)
