<reponame>ShahRutav/dmcontrol-generalization-benchmark
import json
import csv
import click
import os

def make_dir(directory):
	if not os.path.exists(directory):
	    os.makedirs(directory)
def get_action_repeat(domain_name):
    print("domain_name : ", domain_name)
    if 'Ant' in domain_name :
        action_repeat = 4
    elif 'Walker2d' in domain_name :
        action_repeat = 4
    elif 'Hopper' in domain_name :
        action_repeat = 2
    elif 'HalfCheetah' in domain_name :
        action_repeat = 1
    elif 'cartpole' in domain_name :
        action_repeat = 4
    elif 'reacher' in domain_name :
        action_repeat = 4
    elif 'cheetah' in domain_name :
        action_repeat = 4
    elif 'ball_in_cup' in domain_name :
        action_repeat = 4
    elif 'finger' in domain_name :
        action_repeat = 2
    elif 'walker' in domain_name :
        action_repeat = 2
    else :
        raise Exception
    return action_repeat
def get_ref_score(domain_name):
    print("domain_name : ", domain_name)
    if 'Ant' in domain_name :
        ref = 3879.7
    elif 'Walker2d' in domain_name :
        ref = 4592.3
    elif 'Hopper' in domain_name :
        ref = 3234.3
    elif 'HalfCheetah' in domain_name :
        ref = 12135.0
    else :
        raise Exception
    return ref

@click.command(help="")
@click.option('-d', '--directory', type=str, help='Directory', default="")
def main(directory):
	print(directory)
	# infile = r"/home/rutav/experiments_ferm/hammer-v0_4million_vil_camera/shaped-rad_sac-pixel-crop-01-09-hammer-v0-im84-b128-nu1-change_model-s809420-id38944/eval.log"
	infile = directory + "/eval.log"
	with open(infile) as f:
		f = f.readlines()

	make_dir(os.path.join(directory, 'logs'))
	with open(directory + '/logs/log.csv', 'w', newline='') as file:
		writer = csv.writer(file)
		writer.writerow(["episode", "episode_reward", "step"])
		iter_num = -1
		for line in f:
			# print(line['mjrl_success_rate'])
			if iter_num >= 0 : # Skipping with respect 0 iterations
				value = json.loads(line)
				writer.writerow([value['episode'], value["episode_reward"], value["step"]] )
			iter_num += 1 
			# print(value['success_rate_mjrl'], value["step"]) 


if __name__ == '__main__':
    main()
import json
import csv
import click
import os

def make_dir(directory):
	if not os.path.exists(directory):
	    os.makedirs(directory)
def get_action_repeat(domain_name):
    print("domain_name : ", domain_name)
    if 'Ant' in domain_name :
        action_repeat = 4
    elif 'Walker2d' in domain_name :
        action_repeat = 4
    elif 'Hopper' in domain_name :
        action_repeat = 2
    elif 'HalfCheetah' in domain_name :
        action_repeat = 1
    elif 'cartpole' in domain_name :
        action_repeat = 4
    elif 'reacher' in domain_name :
        action_repeat = 4
    elif 'cheetah' in domain_name :
        action_repeat = 4
    elif 'ball_in_cup' in domain_name :
        action_repeat = 4
    elif 'finger' in domain_name :
        action_repeat = 2
    elif 'walker' in domain_name :
        action_repeat = 2
    else :
        raise Exception
    return action_repeat
def get_ref_score(domain_name):
    print("domain_name : ", domain_name)
    if 'Ant' in domain_name :
        ref = 3879.7
    elif 'Walker2d' in domain_name :
        ref = 4592.3
    elif 'Hopper' in domain_name :
        ref = 3234.3
    elif 'HalfCheetah' in domain_name :
        ref = 12135.0
    else :
        raise Exception
    return ref

@click.command(help="")
@click.option('-d', '--directory', type=str, help='Directory', default="")
def main(directory):
	print(directory)
	# infile = r"/home/rutav/experiments_ferm/hammer-v0_4million_vil_camera/shaped-rad_sac-pixel-crop-01-09-hammer-v0-im84-b128-nu1-change_model-s809420-id38944/eval.log"
	infile = directory + "/eval.log"
	with open(infile) as f:
		f = f.readlines()

	make_dir(os.path.join(directory, 'logs'))
	with open(directory + '/logs/log.csv', 'w', newline='') as file:
		writer = csv.writer(file)
		writer.writerow(["episode", "episode_reward", "step"])
		iter_num = -1
		for line in f:
			# print(line['mjrl_success_rate'])
			if iter_num >= 0 : # Skipping with respect 0 iterations
				value = json.loads(line)
				writer.writerow([value['episode'], value["episode_reward"], value["step"]] )
			iter_num += 1 
			# print(value['success_rate_mjrl'], value["step"]) 


if __name__ == '__main__':
    main()
# infile = r"/home/rutav/experiments_ferm/hammer-v0_4million_vil_camera/shaped-rad_sac-pixel-crop-01-09-hammer-v0-im84-b128-nu1-change_model-s809420-id38944/eval.log" # print(line['mjrl_success_rate']) # Skipping with respect 0 iterations # print(value['success_rate_mjrl'], value["step"])