Skip to content

Commit

Permalink
Merge pull request #359 from streamsync-cloud/dev
Browse files Browse the repository at this point in the history
chore: Merge for release
  • Loading branch information
ramedina86 authored Mar 27, 2024
2 parents f6d2668 + c999f16 commit e3d76d7
Show file tree
Hide file tree
Showing 23 changed files with 1,016 additions and 343 deletions.
82 changes: 80 additions & 2 deletions apps/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# EVENT HANDLERS


def handle_timer_tick(state: StreamsyncState):
df = state["random_df"]
for i in range(5):
Expand Down Expand Up @@ -80,6 +79,75 @@ def _get_story_text():
with open("assets/story.txt", "r") as f:
return f.read()

def handle_chat_message(payload, state):
if payload == "pdf":
return {
"text": "In this demo you can find only this PDF file.",
"actions": [{
"subheading": "Resource",
"name": "Neon Feathers",
"desc": "Click to open",
"data": "open_pdf"
}]
}
elif payload == "web":
return {
"text": "In this demo you can find only this web link.",
"actions": [{
"subheading": "Resource",
"name": "Streamsync",
"desc": "Click to open",
"data": "open_web"
}]
}

elif payload == "highlight" and state["chat_bot"]["show_pdf"]:
state["chat_bot"]["pdf"]["highlights"] = ["FeatherByte", "SynthoCorp"];
return "I have highlighted some interesting parts of the story."
elif payload == "help":
return "You can type `pdf` or `web` to see what these components can do."
else:
return "I don't understand that command. Type 'help' to see what is possible."

def _show_chatbot_resource(name, resource, state):
if name == "pdf":
state["chat_bot"]['pdf']['source'] = resource
state["chat_bot"]["show_pdf"] = True
state["chat_bot"]["show_web"] = False
elif name == "web":
state["chat_bot"]['web']['url'] = resource
state["chat_bot"]["show_pdf"] = False
state["chat_bot"]["show_web"] = True

def handle_chat_action(payload, state):
if payload == "open_pdf":
_show_chatbot_resource("pdf", "static/neon_feathers.pdf", state)
return "I hope you will enjoy the story. Now you can type `highlight` to see what I can show you."
if payload == "open_web":
_show_chatbot_resource("web", "https://streamsync.cloud/", state)
return {
"text": "This is Streamsync documentation. You can find more information about Streamsync here.",
"actions": [{
"subheading": "Resource",
"name": "Components",
"desc": "Click to open",
"data": "open_web_components"
}, {
"subheading": "Tutorial",
"name": "Quick start",
"desc": "Click to open",
"data": "open_web_tutorial"
}]
}
if payload == "open_web_components":
_show_chatbot_resource("web", "https://streamsync.cloud/component-list.html", state)
return "You can find all components here."
if payload == "open_web_tutorial":
_show_chatbot_resource("web", "https://www.streamsync.cloud/component-list.html", state)
return "You can find quick start tutorial here."

return "I don't understand that command. Type 'help' to see what is possible."

# UPDATES


Expand Down Expand Up @@ -150,7 +218,17 @@ def _update_scatter_chart(state):
"min_length": 25,
"min_weight": 300,
},
"metrics": {}
"metrics": {},
"chat_bot": {
"show_web": False,
"show_pdf": False,
"pdf": {
"source": "",
},
"web": {
"url": "",
},
}
})

update(initial_state, None)
Binary file added apps/hello/static/neon_feathers.pdf
Binary file not shown.
21 changes: 11 additions & 10 deletions apps/hello/test_app.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import os
import pandas as pd
import main
import pytest


class TestApp:

app_state = main.ss.initial_state
@pytest.fixture(autouse=True)
def before(self):
os.chdir(os.path.dirname(__file__))
import main
self.app_state = main.initial_state
yield

def test_handle_timer_tick(self):
import main
main.handle_timer_tick(self.app_state)
df1 = self.app_state["random_df"].to_dict()
main.handle_timer_tick(self.app_state)
df2 = self.app_state["random_df"].to_dict()
assert df1 != df2

def test_highlighted_members(self):
hml = self.app_state["highlighted_members"]
assert isinstance(hml, list)
assert len(hml) > 0

def test_metrics(self):

import main
data = {
"weight_g": [3000, 3500, 3200, 3100, 2900, 3300],
"length_cm": [50, 52, 51, 48, 47, 53],
Expand All @@ -39,4 +40,4 @@ def test_metrics(self):
assert self.app_state["metrics"]["average_weight_note"] == "+Acceptable"
assert self.app_state["metrics"]["average_length_note"] == "+Acceptable"
assert self.app_state["metrics"]["average_bmi_note"] == "-Overweight"
assert self.app_state["metrics"]["diversity_note"] == "-Not diverse"
assert self.app_state["metrics"]["diversity_note"] == "-Not diverse"
Loading

0 comments on commit e3d76d7

Please sign in to comment.