summaryrefslogtreecommitdiff
path: root/utils.py
blob: ac98f8ac8b4fc28503384b7b0a45fa13a24e5971 (plain)
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

def fl(number, precision=6):
	formatstring = '{:.'+str(precision)+'f}'
	return float(formatstring.format(number))


def depth(myList, counter):
	counter += 1
	depthList = []
	for item in myList:
		if isinstance(item, list):
			depthList.append(depth(item, counter))
		else:
			depthList.append(counter)
	return depthList

def flatten(pool):
	res = []
	for v in pool:
		if isinstance(v, list):
		  res += flatten(v)
		else:
			if isinstance(v, int) or isinstance(v, str) or isinstance(v, float):
				res.append(v)
	return res

def isOversliced(bars):
	targets = [bar > 0 and bar < 2.0 for bar in bars]
	return (True in targets)

def firstNonNegative(lst):
	for x in lst:
		if x >= 0:
			return x
	return 0

def lastNonPositive(lst):
	for x in list(reversed(lst)):
		if x <= 0:
			return x
	return 0