I am running a mini project for remote sensing water level in the underground tank. I am collecting data and uploading it using an ESP8266 Wifi to supabase into a table > reading the tables using python and plotting the data using streamlit.
But for some reason on a given run, it shows the correct local IST timing in the chart, on other runs it plots a different UTC timestamp seemingly randomly. I am unable to troubleshoot the problem. Any help would be appreciated.
Below is my code(Ignore the redundancies, I am still learning to code and will progressively iron out the code with time):
from supabase import create_client
import pandas as pd
import streamlit as st
import plotly.express as px
from datetime import datetime, timedelta
API_URL = [redacted]
API_KEY = [redacted]
supabaseList = supabase.table('Water Level').select('*').execute().data
# time range variables updation to put in x axis range parameters
today = datetime.now()
today = today + \
timedelta(minutes = 30)
present_date = today.strftime("%Y-%m-%d %X")
hrs48 = today - \
timedelta(days = 2)
back_date = hrs48.strftime("%Y-%m-%d %X")
df = pd.DataFrame()
for row in supabaseList:
row["created_at"] = row["created_at"].split(".")[0]
row["time"] = row["created_at"].split("T")[1]
row["date"] = row["created_at"].split("T")[0]
row["DateTime"] = row["created_at"]
df = df.append(row, ignore_index=True)
orignal_title = '<h1 style="font-family:Helvetica; color:Black; font-size: 45px; text-align: center">[Redacted]</p>'
st.markdown(orignal_title, unsafe_allow_html=True)
st.text("")
custom_range = [back_date, present_date]
st.write(custom_range)
fig = px.area(df, x="DateTime", y="water_level", title='',markers=False)
fig.update_layout(
title={
'text': "Water level in %",
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'})
fig.update_layout(yaxis_range=[0,120])
fig.update_layout(xaxis_range=custom_range)
#Add Horizontal line for pump trigger level
fig.add_hline(y=80, line_width=3, line_color="black",
annotation_text="Pump Start Level",
annotation_position="top left",
annotation_font_size=15,
annotation_font_color="black"
)
st.plotly_chart(fig,use_container_width=True)
I am expecting it to always plot in IST timestamps, but it prints out UTC on seemingly random runs.