graph_handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df_source = pd.read_sql_query("SELECT * FROM temperatures WHERE time > date('now', '-72 hours')",sql_con) | |
# convert time to datetime type | |
df_source['time'] = pd.to_datetime(df_source['time']) | |
df_1 = df_source.loc[df_source.name == '1'] | |
df_2 = df_source.loc[df_source.name == '2'] | |
import matplotlib.pyplot as plt | |
from matplotlib import dates | |
fig, ax = plt.subplots() | |
ax.xaxis.set_major_formatter(dates.DateFormatter("%dth %H:%M")) | |
ax.set_ylim([34,41]) | |
plt.title('Temps last 3 days') | |
plt.xlabel('DateTime') | |
plt.ylabel('Temp c') | |
plt.xticks(rotation='vertical') | |
ax.plot(df_freya.time, df_freya.temperature, marker='o', label='1') | |
ax.legend() | |
ax.plot(df_rory.time, df_rory.temperature, marker='o', label='2') | |
ax.legend() | |
plt.axhline(38, color='red', ls='dotted') | |
plt.axhline(36.4, color='green', ls='dotted') | |
plt.tight_layout() | |
plt.savefig('./run/temps.jpg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def graphs(ctx: ChatContext) -> None: | |
exec(open("graphs.py").read()) | |
# str(Path(__file__).parent.absolute() / 'temps.jpg') | |
attachmentTemps = {"filename": '/signald/temps.jpg', # cos is't the path in the signald container that matters here | |
"width": "250", | |
"height": "250"} | |
attachmentTimeline1 = {"filename": '/signald/timeline1.png', # cos is't the path in the signald container that matters here | |
"width": "250", | |
"height": "250"} | |
attachmentTimeline2 = {"filename": '/signald/timeline2.png', # cos is't the path in the signald container that matters here | |
"width": "250", | |
"height": "250"} | |
await ctx.message.reply(body="Temp graphs for the last 3 days, last 12 hours timeline", attachments=[attachmentTemps, attachmentTimeline1, attachmentTimeline2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment