2 Achegas a1e21df6af ... 94d4aecd33

Autor SHA1 Mensaxe Data
  Kurtzmusch 94d4aecd33 updated stable_net function %!s(int64=4) %!d(string=hai) anos
  Kurtzmusch 1e92ebe9a6 added .gitignore file %!s(int64=4) %!d(string=hai) anos
Modificáronse 2 ficheiros con 42 adicións e 17 borrados
  1. 1 0
      .gitignore
  2. 41 17
      plot-crypto

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.swp

+ 41 - 17
plot-crypto

@@ -28,43 +28,67 @@ def compile_prices(ticker):
 	
 	return prices
 
-
-def compile_stable_ins(t):
-	
+def aggregate_stable_outs():
 	txs_db = {}
 	txs_objs = {}
 	for ticker in stable_tickers:
 		txs_db[ticker] = open('dbs/crypto-txs-'+ticker+'.db.json', 'r')
 		txs_objs[ticker] = json.load(txs_db[ticker])
 		txs_db[ticker].close()
-	ins = {'timestamps': [], 'values': []}
 	
-	#TODO
+	aggregated_outs = {} # [timestamp] = net_val
+	for ticker in stable_tickers:
+		for timestamp in txs_objs[ticker]:
+			aggregated_outs[timestamp] = 0
+	for ticker in stable_tickers:
+		for timestamp, accumulator in txs_objs[ticker].items():
+			aggregated_outs[timestamp] += accumulator['out']
 	
-	return ins
-
+	return aggregated_outs
 
-def compile_stable_net(t):
-	
+def aggregate_stable_ins():
 	txs_db = {}
 	txs_objs = {}
 	for ticker in stable_tickers:
 		txs_db[ticker] = open('dbs/crypto-txs-'+ticker+'.db.json', 'r')
 		txs_objs[ticker] = json.load(txs_db[ticker])
 		txs_db[ticker].close()
-	nets = {'timestamps': [], 'values': []}
 	
-	stable_nets = {} # [timestamp] = net_val
+	aggregated_ins = {} # [timestamp] = net_val
 	for ticker in stable_tickers:
 		for timestamp in txs_objs[ticker]:
-			stable_nets[timestamp] = 0
+			aggregated_ins[timestamp] = 0
 	for ticker in stable_tickers:
 		for timestamp, accumulator in txs_objs[ticker].items():
-			stable_nets[timestamp] += accumulator['in'] - accumulator['out']
+			aggregated_ins[timestamp] += accumulator['in']
+	
+	return aggregated_ins
+
+
+def compile_stable_ins(t):
+	
+	txs_db = {}
+	txs_objs = {}
+	for ticker in stable_tickers:
+		txs_db[ticker] = open('dbs/crypto-txs-'+ticker+'.db.json', 'r')
+		txs_objs[ticker] = json.load(txs_db[ticker])
+		txs_db[ticker].close()
+	ins = {'timestamps': [], 'values': []}
+	
+	#TODO
+	
+	return ins
+
+def compile_stable_net(t):
+	
+	ins = aggregate_stable_ins()
+	outs = aggregate_stable_outs()
+	
+	nets = {'timestamps': [], 'values': []}
 	
-	for timestamp, net in stable_nets.items():
+	for timestamp in ins:
 		nets['timestamps'].append( int(timestamp)//3600 )
-		nets['values'].append( net )
+		nets['values'].append( ins[timestamp] - outs[timestamp] )
 	
 	return nets
 
@@ -107,11 +131,11 @@ def compile_dif_net(ticker):
 	#TODO
 
 
-functions = { '--i': compile_ins, '--n': compile_net, '--di': compile_dif_ins, '--dn': compile_dif_net, '--si': compile_stable_ins, '--sn': compile_stable_net }
+functions = { '--i': compile_ins, '--n': compile_net, '--di': compile_dif_ins, '--dn': compile_dif_net, '--si': compile_stable_ins, '--sn': compile_stable_net, '--sn2': compile_stable_net2 }
 
 def main():
 	argv = sys.argv[1:]
-	opts, args = getopt.getopt(argv, '', longopts=['i','n','di','dn','si','sn'])
+	opts, args = getopt.getopt(argv, '', longopts=['i','n','di','dn','si','sn', 'sn2'])
 	print(opts)
 	if len(args) < 1:
 		print("error: no ticker")