diff --git a/attribute_categories.py b/attribute_categories.py index 1ca0c10..45456b2 100644 --- a/attribute_categories.py +++ b/attribute_categories.py @@ -32,15 +32,25 @@ relationship_categories = { 'Fine-grained': { - 'Nuclear family': ['FN'], - 'Other family': ['FO'], - 'Family servant': ['FS'], - 'Close friend': ['TC'], - 'Other acquaintance': ['T'] + 'Nuclear Family Member': ['FN'], + 'Other Family Member': ['FO'], + 'Family Servant': ['FS'], + 'Close Friend': ['TC'], + 'Other Acquaintance': ['T'] }, 'Grouped': { 'Family': ['FN', 'FO', 'FS'], 'Friends': ['TC'], 'Other relationships': ['T'] } -} \ No newline at end of file +} + +relationship_labels = { + 'FN' : 'Nuclear Family Members', + 'FO' : 'Other Family Member', + 'FS' : 'Family Servant', + 'TC' : 'Close Friend', + 'T' : 'Other Acquaintance' +} + + diff --git a/data_parser.py b/data_parser.py index 941710d..f5d36a9 100644 --- a/data_parser.py +++ b/data_parser.py @@ -4,7 +4,7 @@ import plotly.express as px import string from pos_categories import pos_categories, pos_labels, pos_dittos -from attribute_categories import rank_categories, relationship_categories +from attribute_categories import rank_categories, relationship_categories, relationship_labels class DataParser(): df = None @@ -30,6 +30,7 @@ def __init__(self): self.pos_labels = pos_labels self.pos_dittos = pos_dittos self.relationship_categories = relationship_categories + self.relationship_labels = relationship_labels return # Transforms xml-file into a BeautifulSoup-object @@ -196,4 +197,4 @@ def get_name(self, ids): tmp = person[['FirstName','LastName']] names = senders.join(tmp, on='Sender').reset_index(drop=True) - return names \ No newline at end of file + return names diff --git a/layout_cust.py b/layout_cust.py index ba5ec7d..f7f0c60 100644 --- a/layout_cust.py +++ b/layout_cust.py @@ -85,12 +85,20 @@ html.P('The custom POS groups you have saved for this session', style={'fontWeight':'bold'}), html.Div(id='cust_pos_groups')])]), dcc.Tab( - label='Other', + label='Relationships', children=[ html.Div( style={'padding': '20px'}, children=[ - html.H5('You can later add other groups as well.')])]) + html.H5('Add a new custom relationship grouping'), + dcc.Input(id="relationship_group_name", type="text", placeholder="Name for new group"), + dcc.Input(id="relationship_group_tags", type="text", placeholder="Tags for new group as ; separated list", style={'width': '100%'}), + html.Br(), + html.Button('Add group', id='add_relationship_group_button', n_clicks = 0), + html.Br(), + html.Br(), + html.P('The custom relationship groups you have saved for this session', style={'fontWeight':'bold'}), + html.Div(id='cust_relationship_groups')])]) ]) ]) @@ -123,3 +131,30 @@ def view_pos_groups(data): children.append(html.P('{}: {}'.format(n, ', '.join(list(t))))) return children + +@app.callback( + Output('session', 'data'), + Input('add_relationship_group_button', 'n_clicks'), + [State('relationship_group_name', 'value')], + [State('relationship_group_tags', 'value')], + State('session', 'data')) +def add_relationship_group(n_clicks, name, tags, data): + + if n_clicks > 0: + if data is None: + data = dict() + tags = tags.split(';') + data[name] = tags + + return data + +@app.callback( + Output('cust_relationship_groups', 'children'), + Input('session', 'data')) +def view_relationship_groups(data): + if data is not None: + children = [] + for (n, t) in data.items(): + children.append(html.P('{}: {}'.format(n, ', '.join(list(t))))) + + return children