diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-10-02 12:53:42 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-10-02 12:53:42 +0200 |
commit | 4eabc96311e54a947dc445c7b4227d4498b60c5f (patch) | |
tree | 37b497e91d0a33f544be34029631b7b4f75d5590 /bin/plot_generator.py | |
parent | 5d5c46d6c3fa968db26eb1b7e49d823023a846c1 (diff) |
black(1)
Diffstat (limited to 'bin/plot_generator.py')
-rw-r--r-- | bin/plot_generator.py | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/bin/plot_generator.py b/bin/plot_generator.py index 458271d..69df7d2 100644 --- a/bin/plot_generator.py +++ b/bin/plot_generator.py @@ -7,14 +7,11 @@ import pprint import json import matplotlib.pyplot as plt -if __name__ == '__main__': +if __name__ == "__main__": # OPTION RECOGNITION opt = dict() - optspec = ( - "bench_filename= " - "result_filename= " - ) + optspec = "bench_filename= " "result_filename= " opt_bench_filename = None opt_result_filename = None try: @@ -28,19 +25,19 @@ if __name__ == '__main__': sys.exit(-1) if "bench_filename" in opt: - opt_bench_filename = opt['bench_filename'] + opt_bench_filename = opt["bench_filename"] else: sys.exit(-1) if "result_filename" in opt: - opt_result_filename = opt['result_filename'] + opt_result_filename = opt["result_filename"] else: print("wth") sys.exit(-1) - with open(opt_bench_filename, 'r') as f: + with open(opt_bench_filename, "r") as f: configurations = json.load(f) - with open(opt_result_filename, 'r') as f: + with open(opt_result_filename, "r") as f: sequence_line = f.readline() begin_sequence = sequence_line.rfind("Resulting Sequence: ") + 20 @@ -58,7 +55,7 @@ if __name__ == '__main__': state_name_pos = function_line.find("Power-Function for state ") + 25 state_name_end = function_line.find(":") state_name = function_line[state_name_pos:state_name_end] - function_string = function_line[state_name_end+1:-1] + function_string = function_line[state_name_end + 1 : -1] pow_function_dict[state_name] = function_string function_line = f.readline() new_line = "\n" @@ -66,25 +63,36 @@ if __name__ == '__main__': new_line = f.readline() function_line = new_line dur_function_dict = dict() - while function_line != "\n" and function_line != "" and "THIS RESULT IS NOT ACCURATE." not in function_line: + while ( + function_line != "\n" + and function_line != "" + and "THIS RESULT IS NOT ACCURATE." not in function_line + ): state_name_pos = function_line.find("Duration-Function for state ") + 28 state_name_end = function_line.find(":") state_name = function_line[state_name_pos:state_name_end] - function_string = function_line[state_name_end+1:-1] + function_string = function_line[state_name_end + 1 : -1] dur_function_dict[state_name] = function_string function_line = f.readline() - param_names = configurations[0]['offline_aggregates']['paramkeys'][0] + param_names = configurations[0]["offline_aggregates"]["paramkeys"][0] for num_fig in range(0, min(4, len(configurations))): rand_config_no = np.random.randint(0, len(configurations), 1)[0] rand_conf = configurations[rand_config_no] - rand_signal = np.array(rand_conf['offline'][0]['uW']) - rand_param = rand_conf['offline_aggregates']['param'][0] + rand_signal = np.array(rand_conf["offline"][0]["uW"]) + rand_param = rand_conf["offline_aggregates"]["param"][0] rand_max_pow = max(rand_signal) # pprint.pprint(rand_param) pretty_rand_param = pprint.pformat(rand_param) - print(str(param_names) + "(" + str(rand_config_no) + ")" + "\n" + pretty_rand_param) + print( + str(param_names) + + "(" + + str(rand_config_no) + + ")" + + "\n" + + pretty_rand_param + ) time = 0 next_time = 0 rand_stepper = 0 @@ -97,8 +105,12 @@ if __name__ == '__main__': curr_dur_func = dur_function_dict[curr_state_name] for num_param, name in enumerate(param_names): replace_string = "parameter(" + name + ")" - curr_pow_func = curr_pow_func.replace(replace_string, str(rand_param[num_param])) - curr_dur_func = curr_dur_func.replace(replace_string, str(rand_param[num_param])) + curr_pow_func = curr_pow_func.replace( + replace_string, str(rand_param[num_param]) + ) + curr_dur_func = curr_dur_func.replace( + replace_string, str(rand_param[num_param]) + ) pow = eval(curr_pow_func) dur = eval(curr_dur_func) next_time = time + dur @@ -109,15 +121,15 @@ if __name__ == '__main__': rand_stepper = rand_stepper + 1 time = next_time - with open("res_conf_" + str(num_fig) + "_signal.txt", 'w') as f: + with open("res_conf_" + str(num_fig) + "_signal.txt", "w") as f: f.write("x,y\n") for x, y in enumerate(rand_signal): f.write(str(x) + "," + str(y) + "\n") - with open("res_conf_" + str(num_fig) + "_fit.txt", 'w') as f: + with open("res_conf_" + str(num_fig) + "_fit.txt", "w") as f: f.write("x,y\n") for x, y in resulting_coords: f.write(str(x) + "," + str(y) + "\n") plt.plot(rand_signal) plt.plot([x for x, y in resulting_coords], [y for x, y in resulting_coords]) - plt.savefig("res_conf_" + str(num_fig) + "_pic.pdf", format='pdf', dpi=300) + plt.savefig("res_conf_" + str(num_fig) + "_pic.pdf", format="pdf", dpi=300) plt.clf() |