diff options
Diffstat (limited to 'python/fatcat_web')
-rw-r--r-- | python/fatcat_web/routes.py | 15 | ||||
-rw-r--r-- | python/fatcat_web/search.py | 12 | ||||
-rw-r--r-- | python/fatcat_web/templates/container_view.html | 38 | ||||
-rw-r--r-- | python/fatcat_web/templates/container_view_coverage.html | 61 | ||||
-rw-r--r-- | python/fatcat_web/templates/entity_macros.html | 13 |
5 files changed, 110 insertions, 29 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index 3f5af621..d41d6bdf 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -15,6 +15,7 @@ from fatcat_web.auth import handle_token_login, handle_logout, load_user, handle from fatcat_web.cors import crossdomain from fatcat_web.search import * from fatcat_web.entity_helpers import * +from fatcat_web.graphics import * ### Generic Entity Views #################################################### @@ -737,6 +738,20 @@ def container_ident_ia_coverage_years_json(ident): histogram = [dict(year=h[0], in_ia=h[1], count=h[2]) for h in histogram] return jsonify({'container_id': ident, "histogram": histogram}) +@app.route('/container/<ident>/ia_coverage_years.svg', methods=['GET', 'OPTIONS']) +@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type']) +def container_ident_ia_coverage_years_svg(ident): + try: + container = api.get_container(ident) + except ApiException as ae: + abort(ae.status) + try: + histogram = get_elastic_container_histogram(container.ident) + except Exception as ae: + app.log.error(ae) + abort(503) + return ia_coverage_histogram(histogram).render_response() + @app.route('/release/<ident>.bib', methods=['GET']) def release_bibtex(ident): try: diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py index 523269ce..2ee76517 100644 --- a/python/fatcat_web/search.py +++ b/python/fatcat_web/search.py @@ -213,6 +213,11 @@ def get_elastic_container_stats(ident, issnl=None): preserved """ + # XXX: + ident = "iznnn644szdwva7khyxqzc73bi" + ident = "lx7svdzmc5dl3ay4zncjjrql7i" + ident = "sn27gkxlkbhuzeexoqyapc756a" + query = { "size": 0, "query": { @@ -296,6 +301,11 @@ def get_elastic_container_histogram(ident): (year, in_ia, count) """ + # XXX: + ident = "iznnn644szdwva7khyxqzc73bi" + ident = "lx7svdzmc5dl3ay4zncjjrql7i" + ident = "sn27gkxlkbhuzeexoqyapc756a" + query = { "aggs": { "year_in_ia": { @@ -346,7 +356,7 @@ def get_elastic_container_histogram(ident): resp.raise_for_status() # TODO: abort() resp = resp.json() - print(resp) + #print(resp) vals = [(h['key']['year'], h['key']['in_ia'], h['doc_count']) for h in resp['aggregations']['year_in_ia']['buckets']] vals = sorted(vals) diff --git a/python/fatcat_web/templates/container_view.html b/python/fatcat_web/templates/container_view.html index 87e70f2b..0efc18a0 100644 --- a/python/fatcat_web/templates/container_view.html +++ b/python/fatcat_web/templates/container_view.html @@ -3,18 +3,6 @@ {% import "entity_macros.html" as entity_macros %} {% extends "entity_base.html" %} -{% macro progress_color(frac) -%} -{% if frac >= 1 %} -green -{% elif frac > 0.95 %} -olive -{% elif frac < 0.5 %} -red -{% else %} -yellow -{% endif %} -{%- endmacro %} - {% block entity_main %} <div class="ui stackable mobile reversed grid centered"> @@ -69,7 +57,7 @@ yellow {% if container._stats %} <div class="ui segment attached"> <div style="text-align: center;"> - <div class="ui small center statistic"> + <div class="ui small statistic"> <div class="value">{{ "{:,}".format(container._stats.total) }}</div> <div class="label" style="text-transform: none;">Known Releases</div> </div> @@ -80,26 +68,26 @@ yellow {% set frac_preserved = container._stats.is_preserved/container._stats.total %} {% set frac_web = container._stats.in_web/container._stats.total %} - <div class="ui {{ progress_color(frac_kbart) }} progress" style="margin-bottom: 0.1em;"> - <div class="bar" style="width: {{ "{:.1f}".format(frac_kbart*100) }}%;"> - <div class="progress">{{ "{:.1f}".format(frac_kbart*100) }}%</div> + <div class="ui {{ entity_macros.progress_color(frac_web) }} progress" style="margin-bottom: 0.1em;"> + <div class="bar" style="width: {{ (frac_web*100)|int }}%;"> + <div class="progress">{{ (frac_web*100)|int }}%</div> </div> </div> - {{ "{:,}".format(container._stats.in_kbart ) }} preserved (dark) + {{ "{:,}".format(container._stats.in_web) }} preserved and available (bright) - <div class="ui {{ progress_color(frac_preserved) }} progress" style="margin-bottom: 0.1em;"> - <div class="bar" style="width: {{ "{:.1f}".format(frac_preserved*100) }}%;"> - <div class="progress">{{ "{:.1f}".format(frac_preserved*100) }}%</div> + <div class="ui {{ entity_macros.progress_color(frac_preserved) }} progress" style="margin-bottom: 0.1em;"> + <div class="bar" style="width: {{ (frac_preserved*100)|int }}%;"> + <div class="progress">{{ (frac_preserved*100)|int }}%</div> </div> </div> - {{ "{:,}".format(container._stats.is_preserved) }} preserved or available + {{ "{:,}".format(container._stats.is_preserved) }} preserved at all (bright or dark) - <div class="ui {{ progress_color(frac_web) }} progress" style="margin-bottom: 0.1em; margin-top: 1em;"> - <div class="bar" style="width: {{ "{:.1f}".format(frac_web*100) }}%;"> - <div class="progress">{{ "{:.1f}".format(frac_web*100) }}%</div> + <div class="ui {{ entity_macros.progress_color(frac_kbart) }} progress" style="margin-bottom: 0.1em; margin-top: 1em;"> + <div class="bar" style="width: {{ (frac_kbart*100)|int }}%;"> + <div class="progress">{{ (frac_kbart*100)|int }}%</div> </div> </div> - {{ "{:,}".format(container._stats.in_web) }} fulltext available to read + {{ "{:,}".format(container._stats.in_kbart ) }} preserved by Keeper (dark) {% endif %} </div> diff --git a/python/fatcat_web/templates/container_view_coverage.html b/python/fatcat_web/templates/container_view_coverage.html index eb9dba8a..db435181 100644 --- a/python/fatcat_web/templates/container_view_coverage.html +++ b/python/fatcat_web/templates/container_view_coverage.html @@ -6,10 +6,65 @@ {% block entity_main %} -<h3>Preservation Coverage By Year</h3> +<div class="ui centered grid"> + <div class="row"> + <div class="twelve wide column"> + <div class="ui large horizontal statistic"> + <div class="value">{{ "{:,}".format(container._stats.total) }}</div> + <div class="label" style="text-transform: none;">Known Releases</div> + </div> + {% if container._stats.total >= 1 %} -<img src="/container/{{ container.ident }}/ia_coverage_years.svg"> -<br><a href="/container/{{ container.ident }}/ia_coverage_years.json">Download as JSON</a> + {% set frac_kbart = container._stats.in_kbart/container._stats.total %} + {% set frac_preserved = container._stats.is_preserved/container._stats.total %} + {% set frac_web = container._stats.in_web/container._stats.total %} + + <div class="ui large {{ entity_macros.progress_color(frac_web) }} progress" style="margin-bottom: 0.1em;"> + <div class="bar" style="width: {{ (frac_web*100)|int }}%;"> + <div class="progress">{{ (frac_web*100)|int }}%</div> + </div> + <div class="label"> + {{ "{:,}".format(container._stats.in_web) }} preserved and available (bright) + </div> + </div> + + <br> + <div class="ui large {{ entity_macros.progress_color(frac_preserved) }} progress" style="margin-bottom: 0.1em;"> + <div class="bar" style="width: {{ (frac_preserved*100)|int }}%;"> + <div class="progress">{{ (frac_preserved*100)|int }}%</div> + </div> + <div class="label"> + {{ "{:,}".format(container._stats.is_preserved) }} preserved at all (bright or dark) + </div> + </div> + + <br> + <div class="ui large {{ entity_macros.progress_color(frac_kbart) }} progress" style="margin-bottom: 0.1em; margin-top: 1em;"> + <div class="bar" style="width: {{ (frac_kbart*100)|int }}%;"> + <div class="progress">{{ (frac_kbart*100)|int }}%</div> + </div> + <div class="label"> + {{ "{:,}".format(container._stats.in_kbart ) }} preserved by Keeper (dark) + </div> + </div> + + {% endif %} + </div> + </div> +</div> + +{% if container._stats.total >= 1 %} + <br> + <h2>Perpetual Access Coverage by Year</h2> + + <figure style="margin: 0 0 0 0;"> + <embed type="image/svg+xml" src="/container/{{ container.ident }}/ia_coverage_years.svg" /> + </figure> + + <div style="float: right;"> + <a href="/container/{{ container.ident }}/ia_coverage_years.json">Download as JSON</a> + </div> +{% endif %} {% endblock %} diff --git a/python/fatcat_web/templates/entity_macros.html b/python/fatcat_web/templates/entity_macros.html index 6124630c..fc199c21 100644 --- a/python/fatcat_web/templates/entity_macros.html +++ b/python/fatcat_web/templates/entity_macros.html @@ -221,3 +221,16 @@ {% endif %} </div> {% endmacro %} + +{% macro progress_color(frac) -%} +{% if frac >= 1 %} +green +{% elif frac > 0.95 %} +olive +{% elif frac < 0.5 %} +red +{% else %} +yellow +{% endif %} +{%- endmacro %} + |