diff --git a/README.rst b/README.rst index a849a55..e2f9079 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,7 @@ Go to http://graph.driveshare.org to see network statistics. Built using the Fla **API** -Go to http://graph.driveshare.org/api/summary/ to see daily summaries for the build with the specified btc address over the past 30 days. +Go to http://graph.driveshare.org/api/summary/ to see daily summaries for the build with the specified btc address over the past 30 days. Ubuntu Digital Ocean Node diff --git a/driveshare_graph/app.py b/driveshare_graph/app.py index 51068f5..26a4a92 100644 --- a/driveshare_graph/app.py +++ b/driveshare_graph/app.py @@ -57,11 +57,11 @@ def daily_data(): return json_totals -@app.route("/api/summary/") -def api_summary(btc_addr): +@app.route("/api/summary/") +def api_summary(nodeid): conn = sqlite3.connect('summary.db') cursor = conn.cursor() - json_summary = farmer_summary.json_month_summary(cursor, btc_addr) + json_summary = farmer_summary.json_month_summary(cursor, nodeid) return json_summary diff --git a/driveshare_graph/farmer_summary.py b/driveshare_graph/farmer_summary.py index aeade78..c52c886 100644 --- a/driveshare_graph/farmer_summary.py +++ b/driveshare_graph/farmer_summary.py @@ -73,7 +73,7 @@ def create_daily_summary(conn, cursor, collection, date): for doc in collection.find({'time': {'$gte': date, '$lt': next_date}}): doc_time = time.mktime(doc['time'].timetuple()) for farmer in doc['farmers']: - auth_address = farmer['btc_addr'] + auth_address = farmer['nodeid'] if (auth_address in first_dates): if last_dates[auth_address] == previous_time: uptimes[auth_address] += doc_time - previous_time @@ -126,26 +126,26 @@ def assign_points(conn, cursor, date): conn.commit() -def average_height(btc_address, first_date, last_date, collection): +def average_height(nodeid, first_date, last_date, collection): """Returns the average height of the specified btc address between the first_date and last_date. Args: - btc_address: btc_address (authentication address) for farmer + nodeid: nodeid (authentication address) for farmer first_date: first datetime in date range last_date: last datetime in date range collection: MongoDB collection of data on farmers Returns: - avg_height: average height of the build with btc_address between + avg_height: average height of the build with nodeid between first_date and last_date """ pipeline = [ - {'$match': {'farmers.btc_addr': btc_address, + {'$match': {'farmers.nodeid': nodeid, 'time': {'$gte': first_date, '$lt': last_date}}}, - {'$project': {'_id': 0, 'farmers.btc_addr': 1, 'farmers.height': 1}}, + {'$project': {'_id': 0, 'farmers.nodeid': 1, 'farmers.height': 1}}, {'$unwind': '$farmers'}, - {'$match': {'farmers.btc_addr': btc_address}} + {'$match': {'farmers.nodeid': nodeid}} ] height_array = [] for doc in collection.aggregate(pipeline): @@ -208,8 +208,8 @@ def end_date(farmers_collection): # pragma: no cover return last_date -def json_month_summary(cursor, btc_addr): - """Return json summary for btc_addr in the past month""" +def json_month_summary(cursor, nodeid): + """Return json summary for nodeid in the past month""" summaries = [] current_date = dt.datetime.now() - timedelta(days = 1) last_date = dt.datetime(current_date.year, current_date.month, current_date.day, 0, 0, 0) @@ -217,7 +217,7 @@ def json_month_summary(cursor, btc_addr): day_count = (last_date - first_date).days + 1 for single_date in (first_date + timedelta(days=n) for n in range(day_count)): cursor.execute('SELECT date, uptime, duration, height, points FROM summaries ' - 'WHERE auth_address = ? AND date = ?', (str(btc_addr), str(single_date),)) + 'WHERE auth_address = ? AND date = ?', (str(nodeid), str(single_date),)) data = cursor.fetchone() if (data is not None): date = data[0] diff --git a/driveshare_graph/update_summary.py b/driveshare_graph/update_summary.py index a408e97..e03b1cb 100644 --- a/driveshare_graph/update_summary.py +++ b/driveshare_graph/update_summary.py @@ -1,5 +1,6 @@ import farmer_summary import sqlite3 +import datetime from pymongo import MongoClient from time import sleep @@ -9,6 +10,8 @@ cursor = conn.cursor() client = MongoClient('localhost', 27017) collection = client['GroupB']['farmers'] + # farmer_summary.create_summary_table(conn, cursor) + # farmer_summary.init_table(conn, cursor, collection) farmer_summary.update_table(conn, cursor, collection) sleep(86400) conn.close() diff --git a/driveshare_graph/uptime.py b/driveshare_graph/uptime.py index fbc9033..1706b56 100644 --- a/driveshare_graph/uptime.py +++ b/driveshare_graph/uptime.py @@ -41,15 +41,15 @@ def init_farmers_table(conn, cursor, collection): for doc in collection.find({}).sort('time', 1): doc_time = time.mktime(doc['time'].timetuple()) for farmer in doc['farmers']: - btc_address = farmer['btc_addr'] - if (btc_address in first_dates): - if last_dates[btc_address] == previous_time: - uptimes[btc_address] += doc_time - previous_time - last_dates[btc_address] = doc_time + nodeid = farmer['nodeid'] + if (nodeid in first_dates): + if last_dates[nodeid] == previous_time: + uptimes[nodeid] += doc_time - previous_time + last_dates[nodeid] = doc_time else: - first_dates[btc_address] = doc_time - last_dates[btc_address] = doc_time - uptimes[btc_address] = 0 + first_dates[nodeid] = doc_time + last_dates[nodeid] = doc_time + uptimes[nodeid] = 0 previous_time = doc_time for key, value in first_dates.iteritems(): @@ -101,7 +101,7 @@ def update_farmers_table(conn, cursor, collection): for doc in collection.find({'time': {'$gt': last_date}}).sort('time', 1): doc_time = timestamp_from_dt(doc['time']) for farmer in doc['farmers']: - address = farmer['btc_addr'] + address = farmer['nodeid'] if address_in_db(cursor, address): cursor.execute('''SELECT MAX(last_date) FROM farmers WHERE address=?''', (str(address),)) @@ -185,7 +185,7 @@ def uptime_distribution(cursor, collection): # pragma: no cover """ begin_date = dt.datetime.now() - timedelta(days = 7) farmers = collection.find({'time': {'$gte': begin_date}} - ).distinct('farmers.btc_addr') + ).distinct('farmers.nodeid') distribution = {0: 0, 5: 0, 10: 0, 15: 0, 20: 0, 25: 0, 30: 0, 35: 0, 40: 0, 45: 0, 50: 0, 55: 0, 60: 0, 65: 0, 70: 0, 75: 0, 80: 0, 85: 0, 90: 0, 95: 0} @@ -211,7 +211,7 @@ def active_average_uptime(cursor, collection): # pragma: no cover """ begin_date = dt.datetime.now() - timedelta(days=7) farmers = collection.find({'time': {'$gte':begin_date}} - ).distinct('farmers.btc_addr') + ).distinct('farmers.nodeid') uptime_percentages = [] for farmer in farmers: cursor.execute('''SELECT (uptime / (last_date - first_date)) * 100