Commit cfd80e29 authored by Martin Beseda's avatar Martin Beseda

ENH: Added error detection when data for further program starts are missing in some CSV files.

parent 8a24d4b4
......@@ -1130,6 +1130,10 @@ class FilenameArgsContainer:
def get_num_of_params(self):
return self.__params_values_dic_len
def get_pattern_for_params(self, x_lab=None, func_lab=None, keys_lst=None, config_lst=None):
#TODO dopsat
pass
class OptimalAndDefaultValsContainer:
def __init__(self,
......@@ -1408,7 +1412,8 @@ class DataContainer:
default_x_val=None,
global_default_label=None,
global_default_x_val=None,
optim_func=min):
optim_func=min,
filename_args=None):
# TODO prepsat pomoci design pattern strategy!
# TODO overit vstup pro global*** parametry
......@@ -1547,7 +1552,6 @@ class DataContainer:
single_prog_start_data_tmp = list()
for iter_ind in range(len(singleProgramStart)):
print(prog_start_ind, iter_ind)
# Vyberu data pro vychozi label
def_label = default_label_val
try:
......@@ -1558,27 +1562,43 @@ class DataContainer:
for i in range(self.get_evaluated_vars_num())]
def_label = [global_default_label]*self.get_evaluated_vars_num()
print('asdf3')
a=1
# CHYBI DATA PRO 2. BEH v 24_21_18.csv!
# Vyberu data pro vychozi x value pro kazdou iteraci
#
# Pokud neni iterace pro optimum z nadrazeneho regionu, vezme se globalni optimum
# (z config souboru)
def_x_val_tmp = [def_label_tmp[i]['singleProgramStarts'][prog_start_ind]
for i in range(self.get_evaluated_vars_num())]
#def_x_val_tmp = [def_label_tmp[i]['singleProgramStarts'][prog_start_ind]
# for i in range(self.get_evaluated_vars_num())]
def_x_val_tmp = []
for i in range(self.get_evaluated_vars_num()):
try:
def_x_val_tmp.append(def_label_tmp[i]['singleProgramStarts'][prog_start_ind])
except IndexError:
utils.print_err('Loading default values - check your CSV files with measured '
'data \n'
'corresponding to following settings. Data for {}. program start '
'are probably missing.\n\n'
''
'Region: {}\n'
'Default func-value: {}'.format(prog_start_ind,
self.get_region_name(),
def_label[i]))
# TODO dopsat auto detekci souboru s chybejicimi daty
#if filename_args:
# pattern_tmp = filename_args.get_pattern_for_params(func_lab=def_label[i_tmp])
#tmp = utils.find_str_in_files('{}/{}'self.get_region_name())
def_x_val_tup = []
print('asdf2')
for i in range(self.get_evaluated_vars_num()):
item_added = False
for tup in def_x_val_tmp[i]:
if tup[0] == default_x_val[i]:
def_x_val_tup.append(tup)
item_added = True
print('asdf')
# Kontrola, jestli byly nalezene hodnoty pro vsechny vyhodnocovane promenne
if not item_added:
......
......@@ -238,7 +238,8 @@ if __name__ == '__main__':
def_label_val,
def_keys,
def_x_val,
optim_func=min)
optim_func=min,
filename_args=file_name_args)
loaded_data_nested = {}
loaded_data_avg_nested = {}
......@@ -303,7 +304,8 @@ if __name__ == '__main__':
default_keys=def_keys,
global_default_label=def_label_val,
global_default_x_val=def_x_val,
optim_func=min)
optim_func=min,
filename_args=file_name_args)
if detailed_info:
default_optimal_vals_full_nested[func] = loaded_data_tmp.get_optimal_and_default_vals('full',
......@@ -312,7 +314,8 @@ if __name__ == '__main__':
default_keys=def_keys,
global_default_label=def_label_val,
global_default_x_val=def_x_val,
optim_func=min)
optim_func=min,
filename_args=file_name_args)
else:
default_optimal_vals_avg_nested[func] = loaded_data_tmp.get_optimal_and_default_vals('avg',
......@@ -320,7 +323,8 @@ if __name__ == '__main__':
default_x_val=None,
global_default_label=def_label_val,
global_default_x_val=def_x_val,
optim_func=min)
optim_func=min,
filename_args=file_name_args)
if detailed_info:
default_optimal_vals_full_nested[func] = loaded_data_tmp.get_optimal_and_default_vals('full',
......@@ -328,7 +332,8 @@ if __name__ == '__main__':
default_x_val=None,
global_default_label=def_label_val,
global_default_x_val=def_x_val,
optim_func=min)
optim_func=min,
filename_args=file_name_args)
utils.print_info('Data succesfully loaded.')
......
......@@ -10,7 +10,8 @@ import traceback
from math import log10, floor
import re
import numpy as np
import glob
import mmap
first_cap_re = re.compile('(.)([A-Z][a-z]+)')
all_cap_re = re.compile('([a-z0-9])([A-Z])')
......@@ -189,3 +190,15 @@ def remove_outliers(data, m=1.5):
mean = np.mean(data)
std = np.std(data)
return [e for e in data if (abs(e - mean) < m * std)] if std else data
def find_str_in_files(filename_pattern_path, string, contains_str=True):
files = glob.glob(filename_pattern_path)
for f in files:
with open(f, 'rb', 0) as file,\
mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s:
found_tmp = s.find(string)
if (found_tmp == -1 and contains_str) or (found_tmp != -1 and contains_str is False):
files.remove(f)
return files
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment