-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_utils.py
77 lines (63 loc) · 2.47 KB
/
main_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
main_utils.py contains useful functions required in the main Flask app.
"""
import sys
def create_imgpath(filename_arr, UPLOAD_FOLDER):
"""
Creates path to image.
:param filename_arr str: Array containing lits of filenames.
:param UPLOAD_FOLDER str: Path to folder where image should be saved.
:return: String of the image path.
"""
if len(filename_arr) == 0 :
imgpath = ''
else:
imgpath = UPLOAD_FOLDER + filename_arr[-1]
return imgpath
def split_strings(key_list, strings_to_split, delim):
"""
Splits strings in a dictionary.
:param key_list str: List of keys to iterate over.
:param strings_to_split str: Dictionary of strings to split.
:param delim str: Delimiter for splitting the string.
:return: Array of the split strings.
"""
splitResultsArr = []
# if(type(strings_to_split) != 'str'):
# raise ValueError('Array values needs to be string!')
# else:
for x in key_list:
splitResultsArr.append(strings_to_split[x].rsplit(delim, 1))
return splitResultsArr
def categorise_symbols(unsorted_dict, key_list, results_dict, arr_index):
"""
Categorise items in a dictionary.
:param unsorted_dict str: Dictionary of unsorted items.
:param key_list str: List of keys to iterate over.
:param results_dict str: Dictionary with predefined key categories to append new items to.
:param arr_index int: Indicates which index value of the array to append to the dictionary.
:return: Dictionary with categorised items.
"""
for i in range(len(unsorted_dict)):
for k in key_list:
if (unsorted_dict[i][0] == "barline"):
results_dict["barline"].append(unsorted_dict[i][0])
break
elif (unsorted_dict[i][0] == k):
results_dict[k].append(unsorted_dict[i][arr_index])
return results_dict
def translate_notes(arr_to_translate, key_list, translation_reference, notation):
"""
Creates new array with translated items.
:param arr_to_translate str: Array of items to translate.
:param key_list str: List of keys to iterate over.
:param translation_reference str: Dictionary containing reference for translations.
:param notation int: Indicates which index position to reference translation from dictionary.
:return: Array with translated items.
"""
translation_results = []
for i in range(len(arr_to_translate)):
for k in key_list:
if (arr_to_translate[i][0][:1] == k) :
translation_results.append(translation_reference[k][notation])
return translation_results