39 lines
968 B
Python
39 lines
968 B
Python
import psycopg2
|
|
import matplotlib.pyplot as plt
|
|
from mplcursors import cursor # separate package must be installed
|
|
|
|
# Connect to your postgres DB
|
|
conn = psycopg2.connect("postgres://postgres:password@localhost:5420/postgres")
|
|
|
|
# Open a cursor to perform database operations
|
|
cur = conn.cursor()
|
|
|
|
# Execute a query
|
|
cur.execute("SELECT difficulty FROM logs_avg ORDER BY difficulty") # LIMIT 100000")
|
|
# Retrieve query results
|
|
difficulty = cur.fetchall()
|
|
|
|
cur.execute("SELECT mean_time FROM logs_avg ORDER BY difficulty") # LIMIT 100000")
|
|
time = cur.fetchall()
|
|
|
|
|
|
def norm(arr) -> [int]:
|
|
elements = []
|
|
d = 10**7
|
|
for (a,) in arr:
|
|
p = a / d
|
|
elements.append(p)
|
|
|
|
return elements
|
|
|
|
|
|
time = norm(time)
|
|
difficulty = norm(difficulty)
|
|
|
|
# reproducible sample data as a pandas dataframe
|
|
# plt.figure(figsize=(4096, 4096))
|
|
plt.scatter(difficulty, time)
|
|
# cursor(hover=True)
|
|
plt.xlabel("Difficulty Factor (1e7)")
|
|
plt.ylabel("Time (1e7 μs)")
|
|
plt.show()
|