Skip to content

Commit

Permalink
Merge pull request #32 from ClimateCompatibleGrowth/issue_31
Browse files Browse the repository at this point in the history
Adds badges to result type buttons
  • Loading branch information
willu47 authored Oct 21, 2024
2 parents 2065ad2 + 6d0219e commit ba79964
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
19 changes: 16 additions & 3 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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/<id>')
Expand Down
51 changes: 48 additions & 3 deletions app/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,30 @@ 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):
"""Returns all outputs with ordered authors filtering on result type
Arguments
---------
dbL
db
result_type: str
"""
query = """
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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}
20 changes: 16 additions & 4 deletions app/templates/output_list.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
<div class="row">
<h5>Filter by result type: </h5>
<div class="btn-group" id="filter_button" role="group" aria-label="Filter research type">
<a href="?type=publication" class="btn btn-primary">publication</a>
<a href="?type=dataset" class="btn btn-primary">dataset</a>
<a href="?type=software" class="btn btn-primary">tools</a>
<a href="?type=other" class="btn btn-primary">other</a>
<a href="?type=publication" class="btn btn-primary">
publication
<span class="badge text-bg-secondary">{{count.publication}}</span>
</a>
<a href="?type=dataset" class="btn btn-primary">
dataset
<span class="badge text-bg-secondary">{{count.dataset}}</span>
</a>
<a href="?type=software" class="btn btn-primary">
tools
<span class="badge text-bg-secondary">{{count.software}}</span>
</a>
<a href="?type=other" class="btn btn-primary">
other
<span class="badge text-bg-secondary">{{count.other}}</span>
</a>
</div>
</div>

Expand Down

0 comments on commit ba79964

Please sign in to comment.