This repository has been archived on 2024-06-08. You can view files and clone it, but cannot push or open issues or pull requests.
powd/plot.py

40 lines
968 B
Python
Raw Normal View History

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
2023-08-12 17:01:48 +05:30
cur.execute("SELECT difficulty FROM logs_avg ORDER BY difficulty") # LIMIT 100000")
# Retrieve query results
difficulty = cur.fetchall()
2023-08-12 17:01:48 +05:30
cur.execute("SELECT mean_time FROM logs_avg ORDER BY difficulty") # LIMIT 100000")
time = cur.fetchall()
2023-08-12 17:01:48 +05:30
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
2023-08-12 17:01:48 +05:30
# plt.figure(figsize=(4096, 4096))
plt.scatter(difficulty, time)
2023-08-12 17:01:48 +05:30
# cursor(hover=True)
plt.xlabel("Difficulty Factor (1e7)")
plt.ylabel("Time (1e7 μs)")
plt.show()