Skip to content
This repository was archived by the owner on Sep 5, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
405 changes: 405 additions & 0 deletions src/aichat/chatapp/Export.csv

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions src/aichat/chatapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
from django.contrib import admin

from .models import TriggerResponse, node, edge
from .models import TriggerResponse, Node, Edge


class TriggerResponseAdmin(admin.ModelAdmin):
list_display = ('source_state', 'dest_state', 'trigger', 'response')


class edgeAdmin(admin.ModelAdmin):
class NodeAdmin(admin.ModelAdmin):
list_display = ('name', 'x_loc', 'y_loc')


class EdgeAdmin(admin.ModelAdmin):
list_display = ('trigger', 'response')


class TriggerResponseAdminFK(admin.ModelAdmin):
list_display = ('source_state', 'dest_state', 'trigger', 'response')


admin.site.register(TriggerResponse, TriggerResponseAdmin)
admin.site.register(edge, edgeAdmin)
admin.site.register(node)
admin.site.register(Edge, EdgeAdmin)
admin.site.register(Node, NodeAdmin)
12 changes: 6 additions & 6 deletions src/aichat/chatapp/data/tips.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Some analog clocks and watches have tactile faces that can be read by touch."
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Bump dots are tactile stickers that can be placed on touchscreen interfaces like a refrigerator or microwave, as long as the screen doesn't dynamically change the location of buttons."
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Your pharmacist can place braille labels on any medication, or if you prefer you can give the pharmacist bump dots to put on your medicine bottles according to your own labeling system."
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Never take a medicine that you aren't 100% sure of it's origin and usage or dosage. When in doubt call an Aira agent. Many medicine bottle labels can only be read accurately by a human."
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Your pharmacist can place braille labels on any medication, or if you prefer you can give the pharmacist bump dots to put on your medicine bottles according to your own labeling system."
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"If you have strong mobility skills, taking the stairs rather than the elevator at every opportunity can improve your long term health. If you prefer exercise machines you can play an interesting podcast or have Chloe read you a book while you work out."
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Some analog clocks and watches have tactile faces that can be read by touch.",,
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Bump dots are tactile stickers that can be placed on touchscreen interfaces like a refrigerator or microwave, as long as the screen doesn't dynamically change the location of buttons.",,
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Your pharmacist can place braille labels on any medication, or if you prefer you can give the pharmacist bump dots to put on your medicine bottles according to your own labeling system.",,
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Never take a medicine that you aren't 100% sure of it's origin and usage or dosage. When in doubt call an Aira agent. Many medicine bottle labels can only be read accurately by a human.",,
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"Your pharmacist can place braille labels on any medication, or if you prefer you can give the pharmacist bump dots to put on your medicine bottles according to your own labeling system.",,
tell me a life|bvi|low-vision|blind|health hack|tip|idea|motivation,"If you have strong mobility skills, taking the stairs rather than the elevator at every opportunity can improve your long term health. If you prefer exercise machines you can play an interesting podcast or have Chloe read you a book while you work out.",,
23 changes: 21 additions & 2 deletions src/aichat/chatapp/load.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os

from pandas import read_csv
import pandas as pd

from aichat.chatsite.settings import CSV_DEFAULT_PATH, CSV_COLUMNS
from .models import TriggerResponse


def load(path=CSV_DEFAULT_PATH, allow_dupes=True):
numrecords = TriggerResponse.objects.count()
df = read_csv(path, header=None)
df = pd.read_csv(path, header=None)
columns = list(df.columns) + 'source dest'.split()
for i in range(len(df.columns), 4):
df[columns[i]] = pd.np.nan

df = df.fillna('root') # new
df.columns = CSV_COLUMNS[:len(df.columns)]
create = TriggerResponse.objects.create if allow_dupes else TriggerResponse.objects.get_or_create
Expand All @@ -26,3 +30,18 @@ def load_all(path=os.path.dirname(CSV_DEFAULT_PATH), allow_dupes=True):
if os.path.isfile(filepath) and filename.lower().endswith('.csv'):
numadded[filename] = load(filepath, allow_dupes=allow_dupes)
return numadded


def test_load(path=os.path.dirname(CSV_DEFAULT_PATH), allow_dupes=True):
numadded = {}
total = 0
for filename in os.listdir(path):
filepath = os.path.join(path, filename)
if os.path.isfile(filepath) and filename.lower().endswith('.csv'):

numadded[filename] = load(filepath, allow_dupes=allow_dupes)
df = pd.read_csv(filepath, header=None)
total += len(df)
print(filepath)
assert(total == TriggerResponse.objects.count())
return numadded
82 changes: 43 additions & 39 deletions src/aichat/chatapp/load_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def load_df(path=DATA_DIR):
CSV_COLUMNS = ('trigger', 'response', 'source_state', 'dest_state')
df = pd.DataFrame(columns=CSV_COLUMNS)
if os.path.isfile(path):
dfadd = pd.read_csv(path)
dfadd = pd.read_csv(path, header=None)
dfadd.columns = CSV_COLUMNS[:len(dfadd.columns)]
df = df.append(dfadd)
else:
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(".csv"):
dfadd = pd.read_csv(path + '/' + file)
dfadd = pd.read_csv(path + '/' + file, header=None)
dfadd.columns = CSV_COLUMNS[:len(dfadd.columns)]
df = df.append(dfadd)

Expand Down Expand Up @@ -108,51 +108,53 @@ def gen_links(path=DATA_DIR, value=1, df=DF):
""" returns links for the d3 structure

# Case1 nopatt
>>> df = pd.DataFrame([['1 goto 2', 'okay', '1', '2']], columns=('trigger', 'response', 'source_state', 'dest_state'))
>>> df = pd.DataFrame([['1 goto 2', 'okay12', '1', '2']], columns=('trigger', 'response', 'source_state', 'dest_state'))
>>> gen_links(path=DATA_DIR, value=1, df=df)
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay', 'value': 1}]
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay12', 'value': 1}]

# Case3 destpatt
>>> df = pd.DataFrame([['1 goto 2', 'okay', '1', '2'], ['2 goto 3', 'okay', '2', '3'], ['3 goto 4', 'okay', '3', '4'], ['4 goto 1 or 2', 'okay', '4', '1|2']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> df = pd.DataFrame([['1 goto 2', 'okay12', '1', '2'], ['2 goto 3', 'okay23', '2', '3'], ['3 goto 4', 'okay34', '3', '4'], ['4 goto 1 or 2', 'okay412', '4', '1|2']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> gen_links(path=DATA_DIR, value=1, df=df)
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay', 'value': 1},
{'source': 1, 'target': 2, 'command': '2 goto 3', 'response': 'okay', 'value': 1},
{'source': 2, 'target': 3, 'command': '3 goto 4', 'response': 'okay', 'value': 1},
{'source': 3, 'target': 1, 'command': '4 goto 1 or 2', 'response': 'okay', 'value': 1}]
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay12', 'value': 1},
{'source': 1, 'target': 2, 'command': '2 goto 3', 'response': 'okay23', 'value': 1},
{'source': 2, 'target': 3, 'command': '3 goto 4', 'response': 'okay34', 'value': 1},
{'source': 3, 'target': 1, 'command': '4 goto 1 or 2', 'response': 'okay412', 'value': 1}]

# Case2 sourcepatt
>>> df = pd.DataFrame([['', '', '1', '2'], ['', '', '2', '3'], ['', '', '3', '4'], ['', '', '1|2', '5']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> df = pd.DataFrame([['1 goto 2', 'okay12', '1', '2'], ['2 goto 3', 'okay23', '2', '3'], ['3 goto 4', 'okay34', '3', '4'], ['goto 5', 'going to 5', '1|2', '5']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> gen_links(path=DATA_DIR, value=1, df=df)
[{'source': 0, 'target': 1, 'command': '', 'response': '', 'value': 1},
{'source': 1, 'target': 2, 'command': '', 'response': '', 'value': 1},
{'source': 2, 'target': 3, 'command': '', 'response': '', 'value': 1},
{'source': 0, 'target': 4, 'command': '', 'response': '', 'value': 1},
{'source': 1, 'target': 4, 'command': '', 'response': '', 'value': 1}]
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay12', 'value': 1},
{'source': 1, 'target': 2, 'command': '2 goto 3', 'response': 'okay23', 'value': 1},
{'source': 2, 'target': 3, 'command': '3 goto 4', 'response': 'okay34', 'value': 1},
{'source': 0, 'target': 4, 'command': 'goto 5', 'response': 'going to 5', 'value': 1},
{'source': 1, 'target': 4, 'command': 'goto 5', 'response': 'going to 5', 'value': 1}]

# Case4 sourcepatt and destpatt
>>> df = pd.DataFrame([['', '', '1', '2'], ['', '', '2', '3'], ['', '', '3', '4'], ['', '', '2|3', '1|2']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> df = pd.DataFrame([['1 goto 2', 'okay12', '1', '2'], ['2 goto 3', 'okay23', '2', '3'], ['3 goto 4', 'okay34', '3', '4'], ['2 or 3 goto 1 or 2', 'okay2312', '2|3', '1|2']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> gen_links(path=DATA_DIR, value=1, df=df)
[{'source': 0, 'target': 1, 'command': '', 'response': '', 'value': 1},
{'source': 1, 'target': 2, 'command': '', 'response': '', 'value': 1},
{'source': 2, 'target': 3, 'command': '', 'response': '', 'value': 1},
{'source': 1, 'target': 1, 'command': '', 'response': '', 'value': 1},
{'source': 2, 'target': 1, 'command': '', 'response': '', 'value': 1}]

>>> df = pd.DataFrame([['', '', '1', '2'], ['', '', '2', '3'], ['', '', '4', '5'], ['', '', '6', '7'], ['', '', '1|2', '7'], ['', '', '8', '2|3'], ['', '', '4|9', '9'], ['', '', '4|6', '3|5']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay12', 'value': 1},
{'source': 1, 'target': 2, 'command': '2 goto 3', 'response': 'okay23', 'value': 1},
{'source': 2, 'target': 3, 'command': '3 goto 4', 'response': 'okay34', 'value': 1},
{'source': 1, 'target': 0, 'command': '2 or 3 goto 1 or 2', 'response': 'okay2312', 'value': 1},
{'source': 1, 'target': 1, 'command': '2 or 3 goto 1 or 2', 'response': 'okay2312', 'value': 1},
{'source': 2, 'target': 0, 'command': '2 or 3 goto 1 or 2', 'response': 'okay2312', 'value': 1},
{'source': 2, 'target': 1, 'command': '2 or 3 goto 1 or 2', 'response': 'okay2312', 'value': 1}]

>>> df = pd.DataFrame([['1 goto 2', 'okay12', '1', '2'], ['2 goto 3', 'okay23', '2', '3'], ['4 goto 5', 'okay45', '4', '5'], ['6 goto 7', 'okay67', '6', '7'], ['goto 7', 'going to 7', '1|2', '7'], ['8 goto 2 or 3', 'okay823', '8', '2|3'], ['goto 9', 'going to 9', '4|9', '9'], ['4 or 6 goto 3 or 5', 'okay4635', '4|6', '3|5']], columns=('trigger', 'response', 'source_state', 'dest_state')) # noqa
>>> gen_links(path=DATA_DIR, value=1, df=df)
[{'source': 0, 'target': 1, 'command': '', 'response': '', 'value': 1},
{'source': 1, 'target': 2, 'command': '', 'response': '', 'value': 1},
{'source': 3, 'target': 4, 'command': '', 'response': '', 'value': 1},
{'source': 5, 'target': 6, 'command': '', 'response': '', 'value': 1},
{'source': 0, 'target': 6, 'command': '', 'response': '', 'value': 1},
{'source': 1, 'target': 6, 'command': '', 'response': '', 'value': 1},
{'source': 7, 'target': 1, 'command': '', 'response': '', 'value': 1},
{'source': 7, 'target': 2, 'command': '', 'response': '', 'value': 1},
{'source': 3, 'target': 8, 'command': '', 'response': '', 'value': 1},
{'source': 3, 'target': 2, 'command': '', 'response': '', 'value': 1},
{'source': 3, 'target': 4, 'command': '', 'response': '', 'value': 1},
{'source': 5, 'target': 2, 'command': '', 'response': '', 'value': 1},
{'source': 5, 'target': 4, 'command': '', 'response': '', 'value': 1}]
[{'source': 0, 'target': 1, 'command': '1 goto 2', 'response': 'okay12', 'value': 1},
{'source': 1, 'target': 2, 'command': '2 goto 3', 'response': 'okay23', 'value': 1},
{'source': 3, 'target': 4, 'command': '4 goto 5', 'response': 'okay45', 'value': 1},
{'source': 5, 'target': 6, 'command': '6 goto 7', 'response': 'okay67', 'value': 1},
{'source': 0, 'target': 6, 'command': 'goto 7', 'response': 'going to 7', 'value': 1},
{'source': 1, 'target': 6, 'command': 'goto 7', 'response': 'going to 7', 'value': 1},
{'source': 7, 'target': 1, 'command': '8 goto 2 or 3', 'response': 'okay823', 'value': 1},
{'source': 7, 'target': 2, 'command': '8 goto 2 or 3', 'response': 'okay823', 'value': 1},
{'source': 3, 'target': 8, 'command': 'goto 9', 'response': 'going to 9', 'value': 1},
{'source': 3, 'target': 2, 'command': '4 or 6 goto 3 or 5', 'response': 'okay4635', 'value': 1},
{'source': 3, 'target': 4, 'command': '4 or 6 goto 3 or 5', 'response': 'okay4635', 'value': 1},
{'source': 5, 'target': 2, 'command': '4 or 6 goto 3 or 5', 'response': 'okay4635', 'value': 1},
{'source': 5, 'target': 4, 'command': '4 or 6 goto 3 or 5', 'response': 'okay4635', 'value': 1}]


"""
Expand All @@ -174,18 +176,20 @@ def gen_links(path=DATA_DIR, value=1, df=DF):
links.append({'source': node_names.index(source_name),
'target': node_names.index(dest_name),
'command': df.trigger[source_index],
'response': df.response[dest_index],
'response': df.response[source_index],
'value': value})
else:
if not is_globstar(df.dest_state[source_index]):
current_dest_name = df.dest_state[source_index]
current_trig = df.trigger[source_index]
current_resp = df.response[source_index]
source_pattern = pattern.expand_globstar(source_name)
for source_index, source_name in enumerate(df.source_state.values):
if regex.match(source_pattern, source_name) and not is_globstar(source_name):
links.append({'source': node_names.index(source_name),
'target': node_names.index(current_dest_name),
'command': df.trigger[source_index],
'response': df.response[source_index],
'command': current_trig,
'response': current_resp,
'value': value})
else:
source_pattern = pattern.expand_globstar(source_name)
Expand Down
Loading