Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
81b6492
Update version 2
anhtqweb Mar 8, 2021
d42541b
Add basic flask app
anhtqweb Mar 10, 2021
f330ffb
Made changes to the visuals of the interface
anhtqweb Mar 24, 2021
754bc40
Added gitignore
anhtqweb Mar 24, 2021
fa06faa
modified gitignore file
anhtqweb Mar 24, 2021
aa2100d
Reorganized medication area and made appropriate changes to variables…
anhtqweb Mar 26, 2021
bf1af94
Made UI works with upto 4 types of medications
anhtqweb Mar 29, 2021
c1863af
move everything to new game directory
anhtqweb Apr 2, 2021
39928e9
Added files from bitbucket
anhtqweb Apr 2, 2021
9a6857f
Readded bitbucket files
anhtqweb Apr 3, 2021
5f4414a
Rename folder to Chatbox
anhtqweb Apr 3, 2021
ad03bd3
delete new folder
anhtqweb Apr 3, 2021
c5dd1e6
update ajax post in javascript file
anhtqweb Apr 6, 2021
5f24a33
Partial update for demo
anhtqweb Apr 8, 2021
ca8e373
Made chat area scrollable
anhtqweb Apr 11, 2021
b54e387
Added tutorial
anhtqweb Apr 19, 2021
d186b2d
Added code to genereate medsorting layout
anhtqweb Apr 20, 2021
b69b19a
Add new actions for agent: show image as pop up, questioning state
anhtqweb Apr 28, 2021
dd0bb11
add features for demo
anhtqweb Apr 28, 2021
bf94d13
Fix bugs from previous commit
anhtqweb May 4, 2021
04acfcb
Convert javascript to jquery
anhtqweb May 6, 2021
feee510
Fix bug click on calendar with empty hand still add a medication
anhtqweb May 6, 2021
e9a9872
Add comments
anhtqweb May 6, 2021
cc00862
Remove game folder
anhtqweb May 6, 2021
ea67cad
Create README.md
anhtqweb May 6, 2021
ec5fad8
Add comments for sayText
anhtqweb May 7, 2021
f10fbd6
Merge branch 'Version2' of https://github.com/FandM-CARES/Medication_…
anhtqweb May 7, 2021
d1de393
Update README.md
anhtqweb May 7, 2021
bb2f0e0
Update README.md
anhtqweb May 7, 2021
93db7ee
Update README.md
anhtqweb May 7, 2021
77f5b82
Update README.md
anhtqweb May 10, 2021
ae9082f
Update README.md
anhtqweb May 10, 2021
c54a125
Update README.md
anhtqweb May 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/*
game/flask_session/*
Chatbox/flask_session/*
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\tranq\\AppData\\Local\\Programs\\Python\\Python39\\python.exe"
}
Binary file added Chatbox/__pycache__/bot.cpython-39.pyc
Binary file not shown.
Binary file added Chatbox/__pycache__/sessionManager.cpython-39.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions Chatbox/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class botmessage(object):
def __init__(self, sessId):
self.sessID = sessId
self.botOutput = sessId

def botmes(self, userInput):
if userInput == "Hello":
#mess = botmessage(sessionID)
botOutput = "Hi " + self.sessID
return botOutput
else:
#messtwo = botmessage(sessionID)
botOutput = "Bye " + self.sessID
return botOutput
183 changes: 183 additions & 0 deletions Chatbox/chatbox_flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import uuid
from flask import Flask, render_template, jsonify, request, session, redirect, url_for
from flask_session import Session

import os

app = Flask(__name__)
app.secret_key = os.urandom(24)
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

# separate route to deal with tutorial
@app.route("/tutorial", methods=["GET", "POST"])
def tutorial():
# tutorial action followed by a hint message
actionList = [{"name":"pointAt", "args":"aspirin"}, {"name":"pointAt", "args":"monday noon"}]
hintList = ["first click on an aspirin pill to grab", "now click on the highlighted position on a calendar to drop the pill"]

if request.method == "POST":
pos = int(request.form["position"]) # get current step in list of tutorial actions
response = request.form["response"]
proceed = False

# only proceeds if user remove from container or add to grid
# TODO: make it more dynamic
if "remove_from_container aspirin" in response or "add_to_grid" in response:
proceed = True

# check if the current action is the last or not
if pos < len(actionList):
output = {"action": actionList[pos], "hint": hintList[pos], "proceed": proceed}
else:
output = None
return jsonify(output)

# route for communicating back and forth between UI and server
@app.route("/message", methods=["GET", "POST"])
def message():
if request.method == "POST":
print(request.form["botm"])
message = request.form["botm"]

# data to send to UI (may be combined into 1 variable)
action = {}
hint = ""
start = ""
state = "speaking"
time_mapping = ["none", "morning", "noon", "afternoon", "evening"]
day_mapping = {"mon":"Monday", "tue":"Tuesday", "wed":"Wednesday", "thu":"Thursday", "fri":"Friday",
"sat":"Saturday", "sun":"Sunday"}

# functions to check for invalid user action (may be moved to a separate route)
# check if number of 1 type medication is too large for a time in a day
def numCheck():
print(session.get("calendar_count"))
for position, medCount in session.get("calendar_count").items():
for med, count in medCount.items():
if count > 2:
return (med, position, count)
return None

# check if ibuprofen and aspirin are in the same position (used together)
def interactionCheck():
for position, medCount in session.get("calendar_count").items():
if "ibuprofen" in medCount and "aspirin" in medCount and medCount["ibuprofen"] > 0 and medCount["aspirin"] > 0:
return position
return None

# manually respond to user action/message
if "hello" in message:
start = "hello"
elif "bye" in message or "goodbye" in message:
state = "sleeping"
start = "see ya later!"
elif "thank you" in message:
start = "you are welcome!"
elif "no" in message and session.get("toUser")[-1]["state"] == "questioning": # may include problem/question type?
state = "speaking"
hint = "here is an image to help"
action = {"name":"showImage", "args":"static/pill_interaction.png"}
elif "what" in message and session.get("toUser")[-1]["state"] == "questioning":
state = "questioning"
hint = "Do you remember the interaction for the blue pill?"
elif "add_to_grid" in message:
messageList = message[1:-1].split(" ")
med = messageList[1]
position = messageList[2][:3].lower() + str(time_mapping.index(messageList[-1]))

# increase number of pill in calendar position
if position not in session.get("calendar_count"):
session.get("calendar_count")[position] = {med: 1}
else:
if med in session.get("calendar_count")[position]:
session.get("calendar_count")[position][med] += 1
else:
session.get("calendar_count")[position][med] = 1

# check if ibuprofen is used in the morning
if med == "ibuprofen" and messageList[-1] == "morning":
hint = "ibuprofen should not be used in the morning"
action = {"name":"pointAt", "args": messageList[2] + " " + messageList[-1]}
else:
# check if there are no position with more than 2 pills of any type
overdose = numCheck()
if overdose != None:
day = day_mapping[overdose[1][:3]]
time = time_mapping[int(overdose[1][-1])]
hint = "too many " + overdose[0] + " on " + day + " " + time
action = {"name":"pointAt", "args":day + " " + time}
# check for interaction conflict is there is any
else:
incompatible = interactionCheck()
print(incompatible)
if incompatible != None:
day = day_mapping[incompatible[:3]]
time = time_mapping[int(incompatible[-1])]
state = "questioning"
hint = "huhhhhhh????"

elif "remove_from_grid" in message:
messageList = message[1:-1].split(" ")
med = messageList[1]
position = messageList[2][:3].lower() + str(time_mapping.index(messageList[-1]))
# decrease number of pills of a type in a calendar positon
session.get("calendar_count")[position][med] -= 1
if (session.get("calendar_count")[position][med] < 0):
session.get("calendar_count")[position][med] = 0

output = {"start": start, "action": action, "hint": hint, "state":state, "userInput":message}
# keep track of past conversation between user and agent
session.get("fromUser").append(message)
session.get("toUser").append(output)
return jsonify(output)

#################### PREVIOUS PROJECT CODE #######################
#Session Manager
# @app.route('/processOne', methods=['GET', 'POST'])
# def processOne():
# # Session Manager
# # @app.route('/process', methods=['GET', 'POST'])
# # def process():
# userm = request.form['botm']
# botm = sessionManage(userm, session['user'])
# state = botm['state']
# hint = botm['hint']

# return jsonify(botm)

# @app.route('/processTwo', methods=['GET', 'POST'])
# def processTwo():
# print ("process two being called")
# message = newSessionTwo(session['user'])
# output = {'start': message}
# print (message)
# return jsonify(output)
#############################################################

# initializes the game at the beginning
@app.route('/startgame', methods=['GET', 'POST'])
def startgame():
# message = newSession(session['user'])
session["calendar_count"] = {}
session["fromUser"] = []
session["toUser"] = []

# configurations for med sorting game
if "events" not in session:
session["events"] = [{"name": "exercise", "day": "mon", "time":"1"}, {"name":"appointment", "day":"thu", "time":"2"},
{"name":"work", "day":"sat","time":"3"}]

if "medications" not in session:
session["medications"] = [{"name":"ibuprofen", "color":"red", "number":"11"}, {"name":"aspirin", "color":"blue", "number":"15"},
{"name":"albuterol", "color":"green", "number":"7"}]

output = {"events": session.get("events"), "medications": session.get("medications"), "hint":"Game started! Do you want to see the tutorial?"}
return jsonify(output)

@app.route('/', methods=['GET'])
def chatbox():
return render_template("index.html")

if __name__ == "__main__":
app.run(debug=True)
38 changes: 38 additions & 0 deletions Chatbox/sessionManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys, os
cur = os.path.dirname(os.path.realpath(__file__)) + "/"
sys.path.insert(0, cur + "../")

# from Chatbox.bot import botmessage
# import planners.pyhop.pyhop
# import game.game
# from model.maze import operators
# from model.maze import methods
# import csv

# sessionDictionary = {}

# def newSession(sessionID):
# ph = planners.pyhop.pyhop.Pyhop('hoppity')
# #if (trial == 0):
# session = game.game.GenericPyhopGame('model/lightbulb/game.config', ph)
# sessionDictionary[sessionID] = session
# output = session.start_game(sessionID)


# return output

# def newSessionTwo(sessionID):
# ph = planners.pyhop.pyhop.Pyhop('hoppity')
# session = game.game.GenericPyhopGame('model/maze/game.config', ph)
# sessionDictionary[sessionID] = session
# output = session.start_game(sessionID)

# return output

# def sessionManage(userInput, sessionID):
# if sessionID in sessionDictionary:
# session = sessionDictionary[sessionID]
# output = session.handle_user_input(userInput)
# else:
# output = "No game initialized"
# return output
38 changes: 38 additions & 0 deletions Chatbox/static/avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function animateAvatar(state) {
switch(state) {
// add new questioning state in which some question marks appear over avatar's head
case "questioning":
$("#eye1, #eye2").removeClass('eye-down eye-sleep').addClass('eye');
$(".ball").css("animation", "bounce 2s ease-out 3");
$(".shadow").css("animation", "shadow-bounce 2s ease-out 3");
$("#questionMark").css("visibility", "visible").css("animation", "wobble 1s 3 both");
break;
case "speaking":
$("#eye1, #eye2").removeClass('eye-down eye-sleep').addClass('eye');
$(".ball").css("animation", "bounce 2s ease-out 2");
$(".shadow").css("animation", "shadow-bounce 2s ease-out 2");
$("#questionMark").css("visibility", "hidden");
break;
case "thinking":
$("#eye1, #eye2").removeClass('eye eye-sleep').addClass('eye-down');
$(".ball").css("animation", "lil-bounce 2s linear infinite");
$(".shadow").css("animation", "shadow-lil-bounce 2s linear infinite");
$("#questionMark").css("visibility", "hidden");
break;
case "listening":
$("#eye1, #eye2").removeClass('eye-down eye-sleep').addClass('eye');
$(".ball").css("animation", "breathe 3s linear infinite");
$(".shadow").css("animation", "none");
$("#questionMark").css("visibility", "hidden");
break;
case "sleeping":
$("#eye1, #eye2").removeClass('eye eye-down').addClass('eye-sleep');
$(".ball").css("animation", "to-roll 1s, roll 5s linear infinite");
$(".shadow").css("animation", "shadow-roll 5s linear infinite");
$("#questionMark").css("visibility", "hidden");
break;
default:
// TODO output to debug log
console.log("unknown state: " + state);
}
}
Loading