From 46dbfcfecac074bdf973e8c8631a6ad0d034e265 Mon Sep 17 00:00:00 2001 From: Philip ABBET <philip.abbet@idiap.ch> Date: Mon, 29 Jan 2018 11:12:42 +0100 Subject: [PATCH] Add the 'load_data_index_db' function --- beat/backend/python/data.py | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/beat/backend/python/data.py b/beat/backend/python/data.py index 5bf4aa5..544b989 100755 --- a/beat/backend/python/data.py +++ b/beat/backend/python/data.py @@ -1077,6 +1077,39 @@ def load_data_index(cache_root, hash_path): #---------------------------------------------------------- +def load_data_index_db(cache_root, hash_path): + filename = os.path.join(cache_root, hash_path) + + if not os.path.exists(filename): + return None + + retval = [] + + with open(filename, 'rb') as f: + data = json.loads(f.read()) + + current = data[0] + + column_names = current.keys() + + for col in range(0, len(column_names)): + retval.append([0]) + + for row, entry in enumerate(data[1:]): + for col, name in enumerate(column_names): + if entry[name] != current[name]: + retval[col].append(row + 1) + current[name] = entry[name] + + for col in range(0, len(column_names)): + retval[col].append(len(data)) + + return retval + + +#---------------------------------------------------------- + + def _foundCommonIndices(lst): """Returns the list of common indices, given a list of list of indices """ @@ -1103,9 +1136,10 @@ def foundSplitRanges(lst, n_split): c = 0 s = 0 for i in range(1, len(ci_lst)): - if (ci_lst[i] - ci_lst[s] >= average_length and c < n_split - 1) or \ - len(ci_lst) - i <= n_split - c: + if (ci_lst[i] >= (c + 1) * average_length and c < n_split - 1): res.append((ci_lst[s], ci_lst[i] - 1)) s = i c += 1 + elif i == len(ci_lst) - 1: + res.append((ci_lst[s], ci_lst[i] - 1)) return res -- GitLab