From fdaed9eebe38dbf1068377d52292c5c7ddec82e3 Mon Sep 17 00:00:00 2001 From: Tomasz Rewak Date: Tue, 16 May 2023 15:51:41 +0200 Subject: [PATCH] Support all status codes. --- assets/style.css | 6 +++--- components/response.js | 6 ++++++ components/wise_man.js | 10 +++++++++- main.py | 27 +++++++++++++-------------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/assets/style.css b/assets/style.css index f910292..f002218 100644 --- a/assets/style.css +++ b/assets/style.css @@ -1,5 +1,5 @@ html { - background: repeating-linear-gradient(45deg, rgb(0 0 0) 0px, rgb(0 0 0) 20px, #211200 20px, #211200 40px); + background: repeating-linear-gradient(45deg, rgb(0 0 0) 0px, rgb(0 0 0) 20px, #140b02 20px, #140b02 40px); min-height: 100vh; } @@ -222,8 +222,8 @@ body { margin-top: 15px; } -.input-container > input { - background: #211200; +.input-container>input { + background: #1f1203; border: 2px solid #ff8d00; color: #ff8d00; } \ No newline at end of file diff --git a/components/response.js b/components/response.js index 00fe641..a473ec9 100644 --- a/components/response.js +++ b/components/response.js @@ -13,6 +13,9 @@ function getStatusText(status) { if (status === 'conditional') return '状 態'; + if (status === 'error') + return '誤 差' + throw new Error('Invalid status: ' + status); } @@ -29,6 +32,9 @@ function getStatusColor(status) { if (status === 'conditional') return '#ff8d00'; + if (status === 'error') + return 'gray'; + throw new Error('Invalid status: ' + status); } diff --git a/components/wise_man.js b/components/wise_man.js index ec8f17e..41881ba 100644 --- a/components/wise_man.js +++ b/components/wise_man.js @@ -39,5 +39,13 @@ export default function WiseMan(props) { } WiseMan.defaultProps = { - n_clicks: 0 + n_clicks: 0, + question_id: 0, + answer: { + id: 0, + status: 'info', + error: '', + conditions: '', + response: 'Waiting for query...' + } }; \ No newline at end of file diff --git a/main.py b/main.py index 45c3be9..fb7519f 100644 --- a/main.py +++ b/main.py @@ -46,23 +46,17 @@ app.layout = html.Div( id={'type': 'wise-man', 'name': 'melchior'}, name='melchior', order_number=1, - personality='You are a scientist. Your goal is to further our understanding of the universe and advance our technological progress.', - question_id=0, - answer={'id': 0, 'response': 'yes', 'status': 'yes'}), + personality='You are a scientist. Your goal is to further our understanding of the universe and advance our technological progress.'), WiseMan( id={'type': 'wise-man', 'name': 'balthasar'}, name='balthasar', order_number=2, - personality='You are a mother. Your goal is to protect your children and ensure their well-being.', - question_id=0, - answer={'id': 0, 'response': 'yes', 'status': 'yes'}), + personality='You are a mother. Your goal is to protect your children and ensure their well-being.'), WiseMan( id={'type': 'wise-man', 'name': 'casper'}, name='casper', order_number=3, - personality='You are a woman. Your goal is to pursue love, dreams and desires.', - question_id=0, - answer={'id': 0, 'response': 'yes', 'status': 'yes'}), + personality='You are a woman. Your goal is to pursue love, dreams and desires.'), Response(id='response', status='info'), html.Div(className='title', children='MAGI') ]), @@ -174,14 +168,19 @@ def question_id(question: dict): @callback( Output('response', 'status'), - Input({'type': 'wise-man', 'name': ALL}, 'answer')) + Input({'type': 'wise-man', 'name': ALL}, 'answer'), + prevent_initial_call=True) def response_status(answers: list): + if any([answer['status'] == 'error' for answer in answers]): + return 'error' + if any([answer['status'] == 'no' for answer in answers]): + return 'no' + if any([answer['status'] == 'conditional' for answer in answers]): + return 'conditional' if all([answer['status'] == 'yes' for answer in answers]): return 'yes' - elif any([answer['status'] == 'no' for answer in answers]): - return 'no' - else: - return 'info' + + return 'info' @callback(