diff --git a/app/app.py b/app/app.py index d069d29..04a0c61 100644 --- a/app/app.py +++ b/app/app.py @@ -26,8 +26,10 @@ def country(id: str): else: outputs, country = country_model.get(id) + count = country_model.count(id) + return render_template('country.html', title='Country', outputs=outputs, - country=country) + country=country, count=count) @app.route('/countries') @@ -49,7 +51,12 @@ def author(id: str): entity = author_model.get(id) logger.debug(entity) - return render_template('author.html', title='Author', author=entity) + count = author_model.count(id) + + return render_template('author.html', + title='Author', + author=entity, + count=count) @app.route('/authors') @@ -69,7 +76,13 @@ def output_list(): entity = model.filter_type(result_type=result_type) else: entity = model.get() - return render_template('outputs.html', title='Output List', outputs=entity) + + count = model.count() + + return render_template('outputs.html', + title='Output List', + outputs=entity, + count=count) @app.route('/outputs/') diff --git a/app/model.py b/app/model.py index 0519a6d..480782e 100644 --- a/app/model.py +++ b/app/model.py @@ -45,9 +45,22 @@ def get(self, db): RETURN o as outputs, collect(DISTINCT c) as countries, collect(DISTINCT a) as authors; """ records, summary, keys = db.execute_query(query) - articles = [x.data() for x in records] + return [x.data() for x in records] - return articles + @connect_to_db + def count(self, db: Driver): + """Returns counts of the result types + + Arguments + --------- + db : Driver + """ + query = """ + MATCH (a:Author)-[b:author_of]->(o:Article) + RETURN o.result_type as result_type, count(o) as count + """ + records, summary, keys = db.execute_query(query) + return {x.data()['result_type']: x.data()['count'] for x in records} @connect_to_db def filter_type(self, db: Driver, result_type: str): @@ -55,7 +68,7 @@ def filter_type(self, db: Driver, result_type: str): Arguments --------- - dbL + db result_type: str """ query = """ @@ -172,6 +185,22 @@ def get(self, id, db, type=None): return results + @connect_to_db + def count(self, id: str, db: Driver): + """Returns counts of the result types + + Arguments + --------- + db : Driver + """ + query = """ + MATCH (a:Author)-[b:author_of]->(o:Article) + WHERE (a.uuid) = $uuid + RETURN o.result_type as result_type, count(o) as count + """ + records, summary, keys = db.execute_query(query, uuid=id) + return {x.data()['result_type']: x.data()['count'] for x in records} + class Output: @@ -282,3 +311,19 @@ def get(self, id: str, db: Driver, result_type=None): results, _, _ = db.execute_query(query, id=id) country = results[0].data()['country'] return outputs, country + + @connect_to_db + def count(self, id: str, db: Driver): + """Returns counts of the result types + + Arguments + --------- + db : Driver + """ + query = """ + MATCH (o:Article)-[:REFERS_TO]->(c:Country) + WHERE c.id = $id + RETURN o.result_type as result_type, count(o) as count + """ + records, _, _ = db.execute_query(query, id=id) + return {x.data()['result_type']: x.data()['count'] for x in records} diff --git a/app/templates/output_list.j2 b/app/templates/output_list.j2 index d29ca6c..239fbff 100644 --- a/app/templates/output_list.j2 +++ b/app/templates/output_list.j2 @@ -3,10 +3,22 @@
Filter by result type: