Skip to content

Instantly share code, notes, and snippets.

@lawrencegripper
Last active June 21, 2021 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencegripper/9581ee2c654a8171af0e376628200467 to your computer and use it in GitHub Desktop.
Save lawrencegripper/9581ee2c654a8171af0e376628200467 to your computer and use it in GitHub Desktop.
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