better stats-managing, clock functionality.
This commit is contained in:
parent
3ec1744a15
commit
b2007f2111
@ -1,5 +1,4 @@
|
|||||||
import requests
|
import requests
|
||||||
# import api.keys
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class WeatherFetch():
|
class WeatherFetch():
|
||||||
@ -59,3 +58,25 @@ class WeatherFetch():
|
|||||||
ret_weather = self.last_weather
|
ret_weather = self.last_weather
|
||||||
|
|
||||||
return ret_weather
|
return ret_weather
|
||||||
|
|
||||||
|
# def get_weather_by_city(self, city):
|
||||||
|
# loc = get_coords_from_city(self, city)
|
||||||
|
# weather = self.show_weather(loc)
|
||||||
|
# return weather
|
||||||
|
|
||||||
|
|
||||||
|
# def get_coords_from_city(self, city):
|
||||||
|
# url = "https://devru-latitude-longitude-find-v1.p.rapidapi.com/latlon.php"
|
||||||
|
# data = {"location": city}
|
||||||
|
# headers = {
|
||||||
|
# "x-rapidapi-key" : "d4e0ab7ab3mshd5dde5a282649e0p11fd98jsnc93afd98e3aa",
|
||||||
|
# "x-rapidapi-host" : "devru-latitude-longitude-find-v1.p.rapidapi.com",
|
||||||
|
# }
|
||||||
|
|
||||||
|
# #try:
|
||||||
|
# resp = requests.request("GET", url, headers=headers, params=data)
|
||||||
|
# result = resp.text
|
||||||
|
# #except:
|
||||||
|
# # result = "???"
|
||||||
|
# return result
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from .template import *
|
from .template import *
|
||||||
import time
|
import time
|
||||||
import numpy
|
import numpy
|
||||||
|
from PIL import Image
|
||||||
|
import io
|
||||||
|
|
||||||
CHOOSE, ADDARG = range(2)
|
CHOOSE, ADDARG = range(2)
|
||||||
MESSAGE, WAKE, ALARM, IMAGE, ART = range(3,8)
|
MESSAGE, WAKE, ALARM, IMAGE, ART = range(3,8)
|
||||||
@ -59,7 +61,7 @@ class Clock(BotFunc):
|
|||||||
query.answer()
|
query.answer()
|
||||||
|
|
||||||
query.edit_message_text("Ok. How long should it blink? (In seconds)")
|
query.edit_message_text("Ok. How long should it blink? (In seconds)")
|
||||||
self.next_state = {"ALARM" : "What frequency (Hertz)"}
|
self.next_state = {ALARM : "What frequency (Hertz)"}
|
||||||
return ADDARG
|
return ADDARG
|
||||||
|
|
||||||
def show_message(self, update: Update, context: CallbackContext) -> None:
|
def show_message(self, update: Update, context: CallbackContext) -> None:
|
||||||
@ -74,7 +76,7 @@ class Clock(BotFunc):
|
|||||||
query.answer()
|
query.answer()
|
||||||
|
|
||||||
query.edit_message_text("How long (in minutes) should the image be displayed?")
|
query.edit_message_text("How long (in minutes) should the image be displayed?")
|
||||||
self.next_state = {"IMAGE" : "Please send me the photo to display."}
|
self.next_state = {IMAGE : "Please send me the photo to display."}
|
||||||
return ADDARG
|
return ADDARG
|
||||||
|
|
||||||
def art_gallery(self, update: Update, context: CallbackContext) -> None:
|
def art_gallery(self, update: Update, context: CallbackContext) -> None:
|
||||||
@ -98,7 +100,7 @@ class Clock(BotFunc):
|
|||||||
duration = update.message.text
|
duration = update.message.text
|
||||||
|
|
||||||
def output(duration):
|
def output(duration):
|
||||||
self.clock.set_brightness(value=0.1)
|
self.clock.set_brightness(value=1)
|
||||||
start_color = numpy.array([153, 0, 51])
|
start_color = numpy.array([153, 0, 51])
|
||||||
end_color = numpy.array([255, 255, 0])
|
end_color = numpy.array([255, 255, 0])
|
||||||
empty = numpy.zeros((16,32))
|
empty = numpy.zeros((16,32))
|
||||||
@ -137,19 +139,37 @@ class Clock(BotFunc):
|
|||||||
if not(duration == 0 or frequency == 0):
|
if not(duration == 0 or frequency == 0):
|
||||||
update.message.reply_text("Now blinking")
|
update.message.reply_text("Now blinking")
|
||||||
self.clock.run(output,(duration, frequency))
|
self.clock.run(output,(duration, frequency))
|
||||||
print("DOOONE")
|
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def exec_show_image(self, update: Update, context: CallbackContext) -> None:
|
def exec_show_image(self, update: Update, context: CallbackContext) -> None:
|
||||||
duration = self.additional_argument
|
duration = self.additional_argument
|
||||||
img = update.message.photo
|
i = update.message.photo
|
||||||
|
img = update.message.photo[0]
|
||||||
|
bot = img.bot
|
||||||
|
id = img.file_id
|
||||||
|
|
||||||
|
file = bot.getFile(id).download_as_bytearray()
|
||||||
|
width = self.clock.IO.width
|
||||||
|
height = self.clock.IO.height
|
||||||
|
|
||||||
|
img = Image.open(io.BytesIO(file))
|
||||||
|
im_height = img.height
|
||||||
|
im_width = img.width
|
||||||
|
|
||||||
|
scalex = im_width // width
|
||||||
|
scaley = im_height // height
|
||||||
|
scale = min(scalex, scaley)
|
||||||
|
|
||||||
|
t = img.resize((width, height),box=(0,0,width*scale,height*scale))
|
||||||
|
a = numpy.asarray(t)
|
||||||
|
|
||||||
def output(image, duration):
|
def output(image, duration):
|
||||||
self.clock.IO.set_matrix_rgb([100,0,0])
|
self.clock.IO.set_matrix(image)
|
||||||
|
time.sleep(int(duration) * 60)
|
||||||
|
|
||||||
self.clock.run(output,("image", duration))
|
self.clock.run(output,(a, duration))
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Help(BotFunc):
|
|||||||
# ]
|
# ]
|
||||||
},
|
},
|
||||||
fallbacks=[CommandHandler('help', self.entry_point)],
|
fallbacks=[CommandHandler('help', self.entry_point)],
|
||||||
# conversation_timeout=5,
|
conversation_timeout=15,
|
||||||
)
|
)
|
||||||
return conv_handler
|
return conv_handler
|
||||||
|
|
||||||
@ -92,10 +92,11 @@ class Help(BotFunc):
|
|||||||
|
|
||||||
query.edit_message_text(
|
query.edit_message_text(
|
||||||
text= message,
|
text= message,
|
||||||
#reply_markup = reply_markup,
|
reply_markup = reply_markup,
|
||||||
parse_mode = ParseMode.MARKDOWN_V2
|
parse_mode = ParseMode.MARKDOWN_V2
|
||||||
)
|
)
|
||||||
return ConversationHandler.END #EXECUTE
|
return EXECUTE
|
||||||
|
|
||||||
|
|
||||||
def execute_now(self, update: Update, context: CallbackContext) -> None:
|
def execute_now(self, update: Update, context: CallbackContext) -> None:
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
@ -105,9 +106,10 @@ class Help(BotFunc):
|
|||||||
for func in funcs:
|
for func in funcs:
|
||||||
if name == func.entry_points[0].command[0]:
|
if name == func.entry_points[0].command[0]:
|
||||||
break
|
break
|
||||||
callback = func.entry_points[0].callback
|
callback = func.entry_points[0].handle_update
|
||||||
func.callback(update, context)
|
callback(update, context.dispatcher, check_result=True, context=context)
|
||||||
return FIRST
|
return ConversationHandler.END
|
||||||
|
|
||||||
|
|
||||||
def timeout(self, update: Update, context: CallbackContext) -> None:
|
def timeout(self, update: Update, context: CallbackContext) -> None:
|
||||||
"""For dying conversation. Currently unused."""
|
"""For dying conversation. Currently unused."""
|
||||||
|
@ -40,7 +40,7 @@ class Search(BotFunc):
|
|||||||
# formating
|
# formating
|
||||||
self.results = results
|
self.results = results
|
||||||
first = results[0]
|
first = results[0]
|
||||||
message = first["text"] + "\n(" + first["url"] + ")\n"
|
message = first["text"] + "\n(" + first["url"] + ")\n\n"
|
||||||
|
|
||||||
update.message.reply_text(text = message, reply_markup=reply_markup)
|
update.message.reply_text(text = message, reply_markup=reply_markup)
|
||||||
return MORE
|
return MORE
|
||||||
@ -52,7 +52,7 @@ class Search(BotFunc):
|
|||||||
|
|
||||||
message = ""
|
message = ""
|
||||||
for r in self.results:
|
for r in self.results:
|
||||||
message += r["text"] + "\n(" + r["url"] + ")\n"
|
message += r["text"] + "\n(" + r["url"] + ")\n\n"
|
||||||
|
|
||||||
query.edit_message_text(message)
|
query.edit_message_text(message)
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
@ -31,10 +31,10 @@ class OutputHandler():
|
|||||||
|
|
||||||
# reshape to the main size: (eg 32x16) (always aligns the given matrix on top left.)
|
# reshape to the main size: (eg 32x16) (always aligns the given matrix on top left.)
|
||||||
|
|
||||||
|
if len(matrix.shape) != 3:
|
||||||
# add depth (rgb values)
|
# add depth (rgb values)
|
||||||
r3 = self.matrix_add_depth(matrix,colors)
|
matrix = self.matrix_add_depth(matrix,colors)
|
||||||
self.set_matrix_rgb(r3,quadrant)
|
self.set_matrix_rgb(matrix,quadrant)
|
||||||
|
|
||||||
|
|
||||||
def matrix_add_depth(self, matrix, colors = []):
|
def matrix_add_depth(self, matrix, colors = []):
|
||||||
|
@ -40,6 +40,7 @@ class DashBoard():
|
|||||||
|
|
||||||
@self.app.callback(Output('layout-update','children'), Input('interval-component','n_intervals'))
|
@self.app.callback(Output('layout-update','children'), Input('interval-component','n_intervals'))
|
||||||
def update_layout(n):
|
def update_layout(n):
|
||||||
|
self.set_stats()
|
||||||
kids = [
|
kids = [
|
||||||
self.card_header(),
|
self.card_header(),
|
||||||
dbc.CardColumns([
|
dbc.CardColumns([
|
||||||
@ -91,55 +92,14 @@ class DashBoard():
|
|||||||
|
|
||||||
|
|
||||||
def card_bot_stats(self):
|
def card_bot_stats(self):
|
||||||
def cleanse_graph(category):
|
if not self.stat_graph:
|
||||||
x = self.persistence["bot"][category]["hour"]
|
self.set_stats()
|
||||||
y = self.persistence["bot"][category]["count"]
|
|
||||||
xn = range(x[0], x[-1]+1)
|
|
||||||
yn = []
|
|
||||||
count = 0
|
|
||||||
for x_i in xn:
|
|
||||||
if x_i in x:
|
|
||||||
yn.append(y[count])
|
|
||||||
count += 1
|
|
||||||
else:
|
|
||||||
yn.append(0)
|
|
||||||
xn = [i - int(x[0]) for i in xn]
|
|
||||||
return xn, yn
|
|
||||||
|
|
||||||
xs, ys = cleanse_graph("send_activity")
|
|
||||||
xr, yr = cleanse_graph("receive_activity")
|
|
||||||
xe, ye = cleanse_graph("execute_activity")
|
|
||||||
|
|
||||||
fig = go.Figure()
|
|
||||||
fig.add_trace(go.Scatter(x=xr, y=yr, mode="lines", text="Gelesen", line=dict(width=4)))
|
|
||||||
fig.add_trace(go.Scatter(x=xs, y=ys, mode="lines", text="Gesendet", line=dict(width=4)))
|
|
||||||
fig.add_trace(go.Scatter(x=xe, y=ye, mode="lines", text="Ausgeführt", line=dict(width=4)))
|
|
||||||
|
|
||||||
fig.update_xaxes(showgrid=False)
|
|
||||||
fig.update_yaxes(showgrid=False)
|
|
||||||
fig.layout.update(
|
|
||||||
xaxis = {
|
|
||||||
'showgrid': False, # thin lines in the background
|
|
||||||
'zeroline': False, # thick line at x=0
|
|
||||||
'visible': False, # numbers below
|
|
||||||
}, # the same for yaxis
|
|
||||||
yaxis = {
|
|
||||||
'showgrid': False, # thin lines in the background
|
|
||||||
'zeroline': False, # thick line at x=0
|
|
||||||
'visible': False, # numbers below
|
|
||||||
}, # the same for yaxis
|
|
||||||
|
|
||||||
showlegend=False,
|
|
||||||
margin=dict(l=0, r=0, t=0, b=0),
|
|
||||||
paper_bgcolor='rgba(0,0,0,0)',
|
|
||||||
plot_bgcolor='rgba(0,0,0,0)',
|
|
||||||
)
|
|
||||||
|
|
||||||
card = dbc.Card(
|
card = dbc.Card(
|
||||||
[
|
[
|
||||||
dbc.CardBody([
|
dbc.CardBody([
|
||||||
html.H4("Statistiken", className="card-title"),
|
html.H4("Statistiken", className="card-title"),
|
||||||
dcc.Graph(figure=fig,config={'displayModeBar': False})
|
dcc.Graph(figure=self.stat_graph, config={'displayModeBar': False})
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
color="dark",
|
color="dark",
|
||||||
@ -147,6 +107,7 @@ class DashBoard():
|
|||||||
)
|
)
|
||||||
return card
|
return card
|
||||||
|
|
||||||
|
|
||||||
def card_weather(self):
|
def card_weather(self):
|
||||||
def weather_item(name, overview, temps):
|
def weather_item(name, overview, temps):
|
||||||
if len(temps) == 2:
|
if len(temps) == 2:
|
||||||
@ -258,3 +219,51 @@ class DashBoard():
|
|||||||
)
|
)
|
||||||
return card
|
return card
|
||||||
|
|
||||||
|
|
||||||
|
######### helper:
|
||||||
|
def set_stats(self):
|
||||||
|
def cleanse_graph(category):
|
||||||
|
x = self.persistence["bot"][category]["hour"]
|
||||||
|
y = self.persistence["bot"][category]["count"]
|
||||||
|
xn = range(x[0], x[-1]+1)
|
||||||
|
yn = []
|
||||||
|
count = 0
|
||||||
|
for x_i in xn:
|
||||||
|
if x_i in x:
|
||||||
|
yn.append(y[count])
|
||||||
|
count += 1
|
||||||
|
else:
|
||||||
|
yn.append(0)
|
||||||
|
xn = [i - int(x[0]) for i in xn]
|
||||||
|
return xn, yn
|
||||||
|
|
||||||
|
xs, ys = cleanse_graph("send_activity")
|
||||||
|
xr, yr = cleanse_graph("receive_activity")
|
||||||
|
xe, ye = cleanse_graph("execute_activity")
|
||||||
|
|
||||||
|
fig = go.Figure()
|
||||||
|
fig.add_trace(go.Scatter(x=xr, y=yr, mode="lines", text="Gelesen", line=dict(width=4)))
|
||||||
|
fig.add_trace(go.Scatter(x=xs, y=ys, mode="lines", text="Gesendet", line=dict(width=4)))
|
||||||
|
fig.add_trace(go.Scatter(x=xe, y=ye, mode="lines", text="Ausgeführt", line=dict(width=4)))
|
||||||
|
|
||||||
|
fig.update_xaxes(showgrid=False)
|
||||||
|
fig.update_yaxes(showgrid=False)
|
||||||
|
fig.layout.update(
|
||||||
|
xaxis = {
|
||||||
|
'showgrid': False, # thin lines in the background
|
||||||
|
'zeroline': False, # thick line at x=0
|
||||||
|
'visible': False, # numbers below
|
||||||
|
}, # the same for yaxis
|
||||||
|
yaxis = {
|
||||||
|
'showgrid': False, # thin lines in the background
|
||||||
|
'zeroline': False, # thick line at x=0
|
||||||
|
'visible': False, # numbers below
|
||||||
|
}, # the same for yaxis
|
||||||
|
|
||||||
|
showlegend=False,
|
||||||
|
margin=dict(l=0, r=0, t=0, b=0),
|
||||||
|
paper_bgcolor='rgba(0,0,0,0)',
|
||||||
|
plot_bgcolor='rgba(0,0,0,0)',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.stat_graph = fig
|
||||||
|
Loading…
x
Reference in New Issue
Block a user