From 73d294a4dc2fc69d8c6dc1f0be94f8f9184b8298 Mon Sep 17 00:00:00 2001 From: yakamok <38737288+yakamok@users.noreply.github.com> Date: Tue, 13 Nov 2018 11:06:48 +0100 Subject: [PATCH] added max-min to archive the max nodes per day --- max-min.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 max-min.py diff --git a/max-min.py b/max-min.py new file mode 100644 index 0000000..32237c3 --- /dev/null +++ b/max-min.py @@ -0,0 +1,39 @@ +#add current node count to timeseries table +#can later be used to plot a graph showing daily max nodes on the network +#run every hour + +import sqlite3 +from sqlite3 import Error +import time + +DB_PATH = "vservdb/" + + +def age_calc(ustamp): + if (time.time() - ustamp) <= 14400 : + return True + else: + return False + + +def get_nodes_for_count(db_path): + conn = sqlite3.connect(db_path + 'yggindex.db') + query = conn.execute("select * from yggindex") + nodes = [] + for i in query.fetchall(): + if age_calc(i[2]): + nodes.append(i[1]) + return str(len(nodes)) + + +def add_to_timeseries(db_path): + # try: + conn = sqlite3.connect(db_path + "yggindex.db") + c = conn.cursor() + c.execute('''INSERT INTO timeseries(max) VALUES(''' + "'"\ + + get_nodes_for_count(db_path) + "'" + ''')''') + conn.commit() + conn.close() + + +add_to_timeseries(DB_PATH)