Skip to content

Instantly share code, notes, and snippets.

@lawrencegripper

lawrencegripper/draw.py Secret

Last active Jun 21, 2021
Embed
What would you like to do?
graph_handler
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')
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