Negative temperature fixed

This commit is contained in:
Remy Moll 2020-11-29 21:52:28 +01:00
parent 1fa1d7cb67
commit eb817ac2ee
12 changed files with 283 additions and 120 deletions

View File

@ -43,6 +43,8 @@ class ChatBot():
"joke" : self.bot_tell_joke,
"meme" : self.bot_send_meme,
"news" : self.bot_send_news,
"shopping" : self.bot_shopping_list,
}
@ -203,7 +205,7 @@ class ChatBot():
def bot_emojify(self, *args):
"""Converts a string to emojis"""
if len(params) < 2:
if len(args) < 2:
return "Please send a separator as the first argument, and the text afterwards.\nExample:\n/emojify :heart: Example text"
sep = args[0]
@ -411,3 +413,41 @@ class ChatBot():
text = reddit.get_top(subreddit_name, number, "text")
return text
def bot_shopping_list(self, *args):
"""Shows a shopping list. Usage
add <aobject>
print
clear
remove <position>
"""
output = ""
# args = list(args)
if len(args) == 0:
return "Missing parameter(s)"
if args[0] == "print":
sl = self.persistence.global_action("read", "shopping_list")
for ind,thing in enumerate(sl):
output += str(ind+1) + ". " + thing + "\n"
elif args[0] == "clear":
self.persistence.global_action("write", "shopping_list", value=[])
output = "Cleared list."
elif args[0] == "add":
if len(args) == 1:
output = "Missing parameter"
add = " ".join(args[1:])
self.persistence.global_action("append_list", "shopping_list", value=add)
output = "Added " + add + "."
elif args[0] == "remove":
output = "Removed test."
return output
def bot_save_alias(self, *args):
"""Save a shortcut for special commands (+params)
usage: /alias sa shopping add
Means: /sa will now be treated as input /shopping add"""
return "Does this look finished to you?"

View File

@ -18,30 +18,50 @@ def text_converter(text, height):
digits = {
1 : [[0,0,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1]],
2 : [[1,1,1],[0,0,1],[1,1,1],[1,0,0],[1,1,1]],
3 : [[1,1,1],[0,0,1],[1,1,1],[0,0,1],[1,1,1]],
4 : [[1,0,1],[1,0,1],[1,1,1],[0,0,1],[0,0,1]],
5 : [[1,1,1],[1,0,0],[1,1,1],[0,0,1],[1,1,1]],
6 : [[1,1,1],[1,0,0],[1,1,1],[1,0,1],[1,1,1]],
7 : [[1,1,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1]],
8 : [[1,1,1],[1,0,1],[1,1,1],[1,0,1],[1,1,1]],
9 : [[1,1,1],[1,0,1],[1,1,1],[0,0,1],[1,1,1]],
0 : [[1,1,1],[1,0,1],[1,0,1],[1,0,1],[1,1,1]]
"1" : [[0,0,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1]],
"2" : [[1,1,1],[0,0,1],[1,1,1],[1,0,0],[1,1,1]],
"3" : [[1,1,1],[0,0,1],[1,1,1],[0,0,1],[1,1,1]],
"4" : [[1,0,1],[1,0,1],[1,1,1],[0,0,1],[0,0,1]],
"5" : [[1,1,1],[1,0,0],[1,1,1],[0,0,1],[1,1,1]],
"6" : [[1,1,1],[1,0,0],[1,1,1],[1,0,1],[1,1,1]],
"7" : [[1,1,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1]],
"8" : [[1,1,1],[1,0,1],[1,1,1],[1,0,1],[1,1,1]],
"9" : [[1,1,1],[1,0,1],[1,1,1],[0,0,1],[1,1,1]],
"0" : [[1,1,1],[1,0,1],[1,0,1],[1,0,1],[1,1,1]],
"-" : [[0,0,0],[0,0,0],[1,1,1],[0,0,0],[0,0,0]],
"-1" : [[0,0,1],[0,0,1],[1,1,1],[0,0,1],[0,0,1]],
}
##place of numbers, invariable
##place of numbers, invariant
digit_position = [[2,4], [2,10], [9,4], [9,10]]
def time_converter(time=""):
def time_converter(top="", bottom=""):
"""Converts 4-digit time to a pixel-matrix
returns: np.array((16, 16))"""
if time == "":
time = datetime.datetime.now().strftime("%H%M")
pixels = np.zeros((16,16),dtype=np.uint8)
time = "0" * (4 - len(str(time))) + str(time)
time_split = [int(i) for i in time]
pixels = np.zeros((16,16),dtype=np.uint8)
if bottom == "" or top == "":
top = datetime.datetime.now().strftime("%H")
bottom = datetime.datetime.now().strftime("%M")
if len(top) < 2:
top = "0" * (2 - len(top)) + top
if len(bottom) < 2:
bottom = "0" * (2 - len(bottom)) + bottom
if ("-" in top and len(top) > 2) or ("-" in bottom and len(bottom) > 2):
time_split = 4*["-"]
else:
time_split = [i for i in top] + [i for i in bottom]
if "-1" in top and len(top) != 2:
time_split = ["-1", top[-1]] + [i for i in bottom]
if "-1" in bottom and len(bottom) != 2:
time_split = [i for i in top] + ["-1", bottom[-1]]
print(time_split)
for i in range(4):
x = digit_position[i][0]
y = digit_position[i][1]

View File

@ -92,7 +92,7 @@ class OutputHandler():
if weather["show"] == "weather":
face2_3d = converter.weather_converter(weather["weather"])
else:
face2 = converter.time_converter(int(weather["low"]+weather["high"]))
face2 = converter.time_converter(top=weather["low"], bottom=weather["high"])
face2 = np.concatenate((face2[:8,...],2*face2[8:,...]))
face2_3d = self.matrix_add_depth(face2,[[0, 102, 255],[255, 102, 0]])

View File

@ -1,36 +1,33 @@
import time
import wrapper
import datetime
from threading import Thread
class ModuleWrapper():
class ClockWrapper(wrapper.Wrapper):
"""Wrapper for the CLOCK-functionality"""
def __init__(self, bot_module, clock_module):
def __init__(self, own_module, *other_modules):
""""""
super().__init__(own_module, *other_modules)
print("Initializing clock-functionality")
self.clock = clock_module
self.bot = bot_module
self.time_thread = Thread(target=self.mainloop)
self.time_thread.start()
self.weather = {"weather":"", "high":"", "low":"", "show":"temps"}
self.mainloop(15)
def mainloop(self):
def mainloop(self, sleep_delta):
"""Runs the showing of the clock-face periodically (better way?)"""
print("Starting clock mainloop")
prev_time = 0
prev_weather_time = datetime.datetime.fromtimestamp(0)
while True:
if prev_time == datetime.datetime.now().strftime("%H:%M"):
time.sleep(15)
else:
d = datetime.datetime.now() - prev_weather_time
self.prev_time = 0
self.prev_weather_time = datetime.datetime.fromtimestamp(0)
def perform_loop():
if self.prev_time != datetime.datetime.now().strftime("%H:%M"):
d = datetime.datetime.now() - self.prev_weather_time
mins_elapsed = int(d.total_seconds()/60)
if mins_elapsed >= 3*60:
# fetch new weather every 3 hours (hard coded)
prev_weather_time = datetime.datetime.now()
weather = self.bot.bot_show_weather("zurich")
weather = self.others[0].bot_show_weather("zurich")
l1 = weather[weather.find("</b>")+5:weather.find("\n")].replace (":","")
# current weather situation (icon): we pick the first line, remove the start string, remove :: indicating an emoji
@ -52,4 +49,6 @@ class ModuleWrapper():
prev_time = datetime.datetime.now().strftime("%H:%M")
self.clock.set_face(self.weather)
self.own.set_face(self.weather)
super().mainloop(sleep_delta,perform_loop)

View File

@ -2,84 +2,125 @@ import dash
import dash_bootstrap_components as dbc
import dash_html_components as html
import dash_core_components as dcc
import locale
locale.setlocale(locale.LC_TIME, "de_DE")
#from dash.dependencies import Input, Output
import datetime
ex_css = [dbc.themes.BOOTSTRAP, "static/test.css"]
app = dash.Dash(__name__, external_stylesheets=ex_css)
card_main = dbc.Card(
[
#dbc.CardImg(src="/assets/ball_of_sun.jpg", top=True, bottom=False,
# title="Image by Kevin Dinkel", alt='Learn Dash Bootstrap Card Component'),
dbc.CardBody(
class DashBoard():
""""""
def __init__(self, host_ip):
## pre-sets
self.today = datetime.date.today().strftime("%A, der %d. %B %Y")
self.inter_margin = "1em"
ex_css = [dbc.themes.BOOTSTRAP]
self.app = dash.Dash(__name__, external_stylesheets=ex_css)
self.set_layout()
self.app.run_server(host=host_ip)
def set_layout(self):
card_placeholder = dbc.Card(
[
html.H4("Learn Dash with Charming Data", className="card-title"),
html.H6("Lesson 1:", className="card-subtitle"),
html.P(
"Choose the year you would like to see on the bubble chart.",
className="card-text",
#dbc.CardImg(src="/assets/ball_of_sun.jpg", top=True, bottom=False,
# title="Image by Kevin Dinkel", alt='Learn Dash Bootstrap Card Component'),
dbc.CardBody(
[
html.H4("Learn Dash with Charming Data", className="card-title"),
html.H6("Lesson 1:", className="card-subtitle"),
html.P(
"Choose the year you would like to see on the bubble chart. Test this is a very long text that should hopefully have a line break.",
className="card-text",
),
html.P(
"Choose the year you would like to see on the bubble chart.",
className="card-text",
),
html.P(
"Choose the year you would like to see on the bubble chart.",
className="card-text",
),
html.P(
"Choose the year you would like to see on the bubble chart.",
className="card-text",
),
dbc.Button("Still not live I guess?", color="primary"),
dbc.CardLink("GirlsWhoCode", href="https://girlswhocode.com/", target="_blank"),
]
),
],
color="dark", # https://bootswatch.com/default/ for more card colors
inverse=True, # change color of text (black or white)
outline=False, # True = remove the block colors from the background and header
)
dbc.Button("Still not live I guess?", color="primary"),
# dbc.CardLink("GirlsWhoCode", href="https://girlswhocode.com/", target="_blank"),
]
),
],
color="dark", # https://bootswatch.com/default/ for more card colors
inverse=True, # change color of text (black or white)
outline=False, # True = remove the block colors from the background and header
)
card_weather = dbc.Card(
card_question = dbc.Card(
[
dbc.CardBody([
html.H4("Question 1", className="card-title"),
html.P("What was India's life expectancy in 1952?", className="card-text"),
dbc.ListGroup(
[
dbc.ListGroupItem("A. 55 years"),
dbc.ListGroupItem("B. 37 years"),
dbc.ListGroupItem("C. 49 years"),
], flush=True)
]),
], color="warning",
)
)
card_bot_stats = dbc.Card(
)
today = datetime.date.today().strftime("%d.%m.%Y")
tag = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"][datetime.datetime.today().weekday()]
card_header = dbc.Card(
[ dbc.CardImg(src="static/header.jpg", top=True, bottom=False,
title="Header", alt='Header image'),
dbc.CardBody([html.H4(self.today, className="card-title")]),
],
color="dark",
style = {"width" : "100%", "margin-bottom":self.inter_margin},
inverse=True,
)
string_header = tag + ", der " + today
card_shopping_list = dbc.Card(
[
dbc.CardBody([
html.H4("Shopping list:", className="card-title"),
# html.P("What was India's life expectancy in 1952?", className="card-text"),
dbc.ListGroup(
[
dbc.ListGroupItem("test"),
dbc.ListGroupItem("B. 37 years"),
dbc.ListGroupItem("C. 49 years"),
], flush=False)
]),
],
color="dark",
style = {"width" : "100%", "margin-bottom":self.inter_margin},
inverse=True,
)
app.layout = html.Div([
html.Header(children = [
html.H1(string_header)
],),
html.Div(
className = "content",
style = {"padding-top" : "32em"},
children = [
# dbc.Row([dbc.Col(card_main, width=3),
# dbc.Col(card_question, width=3)], justify="around"), # justify="start", "center", "end", "between", "around"
# dbc.CardGroup([card_main, card_question, card_graph]) # attaches cards with equal width and height columns
# dbc.CardDeck([card_main, card_question, card_graph]) # same as CardGroup but with gutter in between cards
dbc.CardColumns([ # Cards organised into Masonry-like columns
card_main,
card_question,card_question,card_question,card_question,
# card_graph,
# card_question,
# card_question,
])
])
])
self.app.layout = html.Div([
html.Div(
className = "content",
style={"padding":self.inter_margin},
children = [
# dbc.Row([dbc.Col(card_main, width=3),
# dbc.Col(card_question, width=3)], justify="around"), # justify="start", "center", "end", "between", "around"
card_header,
dbc.CardColumns([
card_shopping_list,
card_placeholder,
card_placeholder,
card_placeholder,
card_placeholder,
card_placeholder,
]),
])
])
if __name__ == "__main__":
app.run_server(host="0.0.0.0")
5
test = DashBoard(host_ip="0.0.0.0")

BIN
dashboard/static/header.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 KiB

View File

@ -25,7 +25,7 @@ header::before {
h1 {
font-size: calc(2.8em + 2.6vw);
font-weight: 650;
font-weight: 500;
letter-spacing: .01em;
padding: 6rem 0 0 4.5rem;
text-shadow: .022em .022em .022em #111;

View File

@ -1 +1,24 @@
### mmmh I'm not that far
import wrapper
from threading import Thread
import time
class DashBoardWrapper(wrapper.Wrapper):
def __init__(self, own_module, *other_modules):
""""""
super().__init__(own_module, other_modules)
print("Initializing DASHBOARD-functionality")
# mainloop
def mainloop(self):
super(DashBoardWrapper, self).mainloop(sleep_delta = 3600*3) #3hours refresh-cycle
self.set_weather()
self.set_shopping_list()
self.set_bot_logs()
self.set_joke()
self.bot.refresh()
def set_weather(self):
weather = self.bot.bot_show_weather("zurich")
...
self.own.set_weather(weather)

View File

@ -1,9 +1,12 @@
# functionality
import bot.main
import clock.main
import dashboard.main
# wrapper
import clock_wrapper
import bot_wrapper
import dashboard_wrapper
# misc.
from threading import Thread
@ -28,7 +31,7 @@ class Launcher():
def clock(self):
print("Launching clock-functionality")
self.clock = clock_wrapper.ModuleWrapper(self.bot_module, self.clock_module)
self.clock = clock_wrapper.ClockWrapper(self.clock_module, self.bot_module)
def chatbot(self):
@ -36,6 +39,10 @@ class Launcher():
self.bot = bot_wrapper.ModuleWrapper(self.bot_module, self.clock_module)
def dashboard(self):
print("Launching dashboard-functionality")
self.dashboard = dashboard_wrapper.DashBoardWrapper(self.dashboard_module, self.bot_module)
########################################################################
## Aand liftoff!
Launcher()

View File

@ -11,5 +11,11 @@
"clock" : {
"test":""
},
"dashboard" : {
"test":""
},
"global" : {
"shopping_list" : []
}
}

View File

@ -1,19 +1,37 @@
import json
import time
import os
import shutil
class Variables():
""""""
def __init__(self, module_name, file_name="persistence/persistent_vars.json", init_name="persistence/persistent_init.json", ):
self.path = file_name
self.init_path = init_name
self.last_action = ""
self.module = module_name
self.last_action = ""
# last performed action, if only reads are made, then the underlying var has not been changed
# and doesn't need to be read again
self.savefile = {}
if not os.path.exists(self.path):
shutil.copy(self.init_path, self.path)
def global_action(self, action, name, value=""):
old = self.module
self.module = "global"
action = getattr(self, action)
if value != "":
ret = action(name,value)
else:
ret = action(name)
self.module = old
return ret
def write(self, name, value):
pre = self.read("")
pre[self.module][name] = value
@ -28,23 +46,13 @@ class Variables():
def read(self, name):
if self.last_action == "read":
if name == "":
return self.savefile
else:
return self.savefile[self.module][name]
try:
if os.path.exists(self.path):
file_path = self.path
else:
file_path = self.init_path
file = open(file_path,"r")
vars = self.savefile
else:
file = open(self.path,"r")
vars = json.load(file)
file.close()
self.savefile = vars
self.last_action = "read"
except:
return None
if name != "":
vars = vars[self.module][name]
@ -53,9 +61,11 @@ class Variables():
def increment(self, name, inc=1):
pre = self.read(name)
plus1 = pre + inc
self.write(name, plus1)
if pre:
self.write(name, pre + inc)
else:
self.write(name, inc)
def append_list(self, name, value):
pre = self.read(name)

17
wrapper.py Normal file
View File

@ -0,0 +1,17 @@
import time
class Wrapper():
"""Wrapper skeleton for the modules (bot, clock dashboard...)"""
def __init__(self, own_module, *other_modules):
self.own = own_module
self.others = other_modules
def mainloop(self, sleep_delta, action):
"""sleep_delta in seconds sets the sleep period of the loop
action is a function that is performed every * seconds"""
while True:
action()
time.sleep(sleep_delta)