Fixed function using the wrong dictionary on iteration
This commit is contained in:
parent
2eed0e4776
commit
331f62f9bd
|
@ -1,6 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
# Constantes para indexar os tuplos:
|
# Constantes para indexar os tuplos:
|
||||||
NAME, DATE, OPEN, MAX, MIN, CLOSE, VOLUME = 0, 1, 2, 3, 4, 5, 6
|
NAME, DATE, OPEN, MAX, MIN, CLOSE, VOLUME = 0, 1, 2, 3, 4, 5, 6
|
||||||
|
|
||||||
|
@ -10,11 +9,11 @@ def main():
|
||||||
# Show just first and last tuples:
|
# Show just first and last tuples:
|
||||||
print("first:", lst[1])
|
print("first:", lst[1])
|
||||||
print("last:", lst[-1])
|
print("last:", lst[-1])
|
||||||
|
|
||||||
print("a) totVol=", totalVolume(lst))
|
print("a) totVol=", totalVolume(lst))
|
||||||
|
|
||||||
print("b) maxVal=", maxValorization(lst))
|
print("b) maxVal=", maxValorization(lst))
|
||||||
|
|
||||||
stocksDic = stocksByDateByName(lst)
|
stocksDic = stocksByDateByName(lst)
|
||||||
print("c) CSCO@11:", stocksDic['2020-10-12']['CSCO'])
|
print("c) CSCO@11:", stocksDic['2020-10-12']['CSCO'])
|
||||||
print("c) AMZN@22:", stocksDic['2020-10-22']['AMZN'])
|
print("c) AMZN@22:", stocksDic['2020-10-22']['AMZN'])
|
||||||
|
@ -33,7 +32,7 @@ def loadStockFile(filename):
|
||||||
name = parts[NAME]
|
name = parts[NAME]
|
||||||
date = parts[DATE]
|
date = parts[DATE]
|
||||||
tup = (name, date, float(parts[OPEN]), float(parts[MAX]),
|
tup = (name, date, float(parts[OPEN]), float(parts[MAX]),
|
||||||
float(parts[MIN]), float(parts[CLOSE]), int(parts[VOLUME]))
|
float(parts[MIN]), float(parts[CLOSE]), int(parts[VOLUME]))
|
||||||
lst.append(tup)
|
lst.append(tup)
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ def loadStockFile(filename):
|
||||||
def totalVolume(lst):
|
def totalVolume(lst):
|
||||||
totVol = {}
|
totVol = {}
|
||||||
# Complete ...
|
# Complete ...
|
||||||
for tup in totVol:
|
for tup in lst:
|
||||||
if tup[NAME] not in totVol:
|
if tup[NAME] not in totVol:
|
||||||
totVol[tup[NAME]] = tup[VOLUME]
|
totVol[tup[NAME]] = tup[VOLUME]
|
||||||
else:
|
else:
|
||||||
|
@ -62,7 +61,7 @@ def maxValorization(lst):
|
||||||
if re.match(pat, dia):
|
if re.match(pat, dia):
|
||||||
dia = dia[1]
|
dia = dia[1]
|
||||||
if data == int(dia):
|
if data == int(dia):
|
||||||
maxcomp = tup[OPEN]/tup[CLOSE] * 100
|
maxcomp = tup[OPEN] / tup[CLOSE] * 100
|
||||||
if maxcomp > maxDiario:
|
if maxcomp > maxDiario:
|
||||||
maxDiario = maxcomp
|
maxDiario = maxcomp
|
||||||
maxDiarioComp = tup[NAME]
|
maxDiarioComp = tup[NAME]
|
||||||
|
|
Loading…
Reference in New Issue