Skip to content

Commit

Permalink
Merge pull request #16 from Trondheim-kommune/dev
Browse files Browse the repository at this point in the history
Version 1.1.9
  • Loading branch information
vegarab authored Aug 27, 2019
2 parents 9fc14b4 + 0e1e098 commit 2aa8e8a
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 89 deletions.
11 changes: 7 additions & 4 deletions chatbot/api/v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
})

conflict_model = api.model('Conflict', {
'conflict_id': fields.String(description='Document ID for conflict'),
'id': fields.String(description='Document ID for conflict'),
'title': fields.String(description='Title of conflict content')
})

Expand Down Expand Up @@ -87,14 +87,14 @@ class ConflictIDs(Resource):
@api.marshal_with(conflict_model)
def get(self):
conflict_ids = factory.get_collection(conflict_col).find()
return [models.Conflict(conflict['conflict_id'], conflict['title'])
return [models.Conflict(conflict['id'], conflict['title'])
for conflict in conflict_ids]

@api.marshal_with(delete_model)
@api.response(200, 'Success', delete_model)
@api.response(404, 'Conflict not found')
def delete(self, conflict_id):
result = factory.delete_document({"conflict_id": conflict_id},
result = factory.delete_document({'id': conflict_id},
conflict_col)
if result.deleted_count > 0:
return result
Expand Down Expand Up @@ -146,6 +146,9 @@ def delete(self, content_id):
factory.update_document(query, {'manually_changed': False}, manual_col)
factory.update_document(query, {'manually_changed': False}, prod_col)

# Delete conflict if there was one
factory.delete_document({'id': content_id}, conflict_col)

if result.deleted_count > 0:
return result
else:
Expand Down Expand Up @@ -193,7 +196,7 @@ def put(self, content_id):
.update(*index)

# delete this document from the conflict collection
query = {"conflict_id": content_id}
query = {'id': content_id}
factory.get_database().get_collection(conflict_col).delete_one(query)

if new_document['updatedExisting']:
Expand Down
2 changes: 1 addition & 1 deletion chatbot/api/v2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, user_input='', response_format='plain'):

class Conflict(object):
def __init__(self, conflict_id, title):
self.conflict_id = conflict_id
self.id = conflict_id
self.title = title


Expand Down
15 changes: 8 additions & 7 deletions chatbot/api/v2/test/test_v2_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_response(client):

def test_get_conflict_ids(client):
# Setup two conflicts
conflicts = [{"conflict_id": "test_conflict_id_{}".format(i),
conflicts = [{"id": "test_conflict_id_{}".format(i),
"title": "test_conflict_title_{}".format(i)}
for i in range(2)]

Expand All @@ -50,25 +50,26 @@ def test_get_conflict_ids(client):
response_data = json.loads(response.data.decode())

for conflict in conflicts:
assert conflict['conflict_id'] in [response['conflict_id']
for response in response_data]
assert conflict['id'] in [response['id']
for response in response_data]
finally:
for conflict in conflicts:
factory.delete_document({'conflict_id': conflict['conflict_id']},
factory.delete_document({'id': conflict['id']},
conflict_col)


def test_delete_conflict_ids(client):
conflict = {'conflict_id': 'test conflict id',
conflict = {'id': 'test conflict id',
'title': 'test title'}
factory.post_document(conflict, conflict_col)

try:
idx = conflict['conflict_id']
idx = conflict['id']
response = client.delete('/v2/conflict_ids/{}/'.format(idx))
print(response.data.decode())
assert json.loads(response.data.decode())['deleted_count'] > 0
finally:
factory.delete_document({'conflict_id': 'test conflict id'},
factory.delete_document({'id': 'test conflict id'},
conflict_col)


Expand Down
4 changes: 4 additions & 0 deletions chatbot/api/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from chatbot.api.server import app

if __name__ == '__main__':
app.run()
6 changes: 6 additions & 0 deletions chatbot/chat/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ <h1>Chatbot Boligadministrasjonen</h1>
<div class='msg bot'>
<p>Hei! Jeg er en chatbot som svarer for Boligadministrasjonen. Hva kan
jeg hjelpe deg med? </p>
</div>
<div class='msg bot'>
<p>Jeg forstår korte og konsise spørsmål best!</p>
</div>
</div>
Expand All @@ -22,6 +24,10 @@ <h1>Chatbot Boligadministrasjonen</h1>
<input id='user-input-submit' type='submit' value='Send'>
</form>
</div>
<div class='disclaimer'>
<p> Denne boten er en del av et pilot-prosjekt. Alle spørsmål vil bli
lagret - det frarådes derfor å oppgi personlige eller sensitiv data. </p>
</div>
</div>
<script src="scripts/chat.js"></script>
</body>
Expand Down
4 changes: 4 additions & 0 deletions chatbot/chat/scripts/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function getUserInput() {
*/
function query() {
var input = getUserInput();

// Don't do anything if the field is empty
if (!input) { return; }

populateChatWithMessage(input, "user")

http.open("POST", host+"v1/dialogflow/response", true);
Expand Down
9 changes: 7 additions & 2 deletions chatbot/chat/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ h1 {

margin: 20px auto;
width: 80%;
height: 900px;
height: 80vh;
max-height: 900px;
overflow: auto;
border-style: solid;
Expand All @@ -48,13 +48,13 @@ h1 {
.msg {
height: auto;
width: 100%;
max-height: 450px;
margin-bottom: 10px;
}

.user {
margin-left: auto;
margin-right: 0;
float: right;
}

.user p {
Expand Down Expand Up @@ -93,3 +93,8 @@ p {
flex-direction: row;
justify-content: center;
}

.disclaimer {
color: red;
margin: 5px auto;
}
9 changes: 3 additions & 6 deletions chatbot/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def insert_documents(data):
None)

if prod_doc and temp_doc:
if temp_doc["content"] != prod_doc["content"]:
if not temp_doc["content"] == prod_doc["content"]:
title = temp_doc["content"]["title"]
conflicts.append({"conflict_id": idx,
conflicts.append({"id": idx,
"title": title})

print("Conflicts: {}".format(conflicts))
factory.get_collection(conflict_col).create_index([("conflict_id", 1)],
factory.get_collection(conflict_col).create_index([("id", 1)],
unique=True)
for conflict in conflicts:
try:
Expand Down Expand Up @@ -101,9 +101,6 @@ def insert_documents(data):
factory.get_collection(unknown_col).create_index([("query_text", 1)],
unique=True)

if not conflicts:
factory.get_collection(conflict_col).drop()

return conflicts


Expand Down
2 changes: 1 addition & 1 deletion chatbot/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chatbot_website",
"version": "1.1.8",
"version": "1.1.9",
"private": true,
"homepage": "https://127.0.0.1/",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions chatbot/web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class App extends Component {

fetchAllConflictIDs = async () => {
const conflictDocs = await fetchData(
process.env.REACT_APP_SERVER_URL + 'v1/web/conflict_ids',
process.env.REACT_APP_SERVER_URL + 'v2/conflict_ids/',
'GET'
);
this.setState({ conflictDocs });
};

fetchAllUnknownQueries = async () => {
const queries = await fetchData(
process.env.REACT_APP_SERVER_URL + 'v1/web/unknown_queries',
process.env.REACT_APP_SERVER_URL + 'v2/unknown_queries/',
'GET'
);
this.setState({ queries });
Expand Down
2 changes: 1 addition & 1 deletion chatbot/web/src/components/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ const DocumentList = ({ docs, changeView, title }) => {
);
};

export default DocumentList;
export default DocumentList;
Loading

0 comments on commit 2aa8e8a

Please sign in to comment.