def get_blocks_found_data(num_blocks): ## # Returns data needed to create a *blocks found* chart over the past num_blocks history blocks_found_data = [] latest_blocks = Pool_blocks.get_last_n(num_blocks) for block in iter(latest_blocks): blockdata = {} blockdata["time"] = block.timestamp.strftime('%s') blockdata["height"] = block.height blocks_found_data.append(blockdata) return blocks_found_data
def get_graph_rate_data(num_blocks): ## # Returns data needed to create a *graph rate* chart over the past num_blocks history graph_rate_data = [] latest_blocks = Pool_blocks.get_last_n(num_blocks) for i in range(0, num_blocks - 5): # rolling 5-block window ratedata = {} ts1 = latest_blocks[i].timestamp ts2 = latest_blocks[i + 5].timestamp difficulty = latest_blocks[i + 5].total_difficulty - latest_blocks[ i + 4].total_difficulty # XXX TODO: This isnt right gps = calculate_graph_rate(difficulty, ts1, ts2, 5) ratedata["height"] = latest_blocks[i + 5].height ratedata["gps"] = gps ratedata["timestamp"] = ts2.strftime('%s') graph_rate_data.append(ratedata) return graph_rate_data
def get_stats(): ## # Get current Network Info as seen by our grin node stats_json = {} last_n = 10 # Look at shares from the last N blocks to calculate avg time between # Get the poolblocks from the DB latest_blocks = Pool_blocks.get_last_n(last_n) # Latest poolblock height stats_json["height"] = latest_blocks[-1].height # Latest poolblock hash stats_json["latest_hash"] = latest_blocks[-1].hash # Latest poolblock timestamp stats_json["latest_timestamp"] = latest_blocks[-1].timestamp.strftime('%s') # Avg time between poolblocks found_every = (latest_blocks[-1].timestamp - latest_blocks[0].timestamp).strftime('%s') stats_json["found_every"] = found_every # XXX TODO: # # Pool graph rate # stats_json["graph_rate"] = calculate_graph_rate(latest_difficulty, latest_blocks[0].timestamp, latest_blocks[-1].timestamp, last_n) return stats_json