A search interface for the Performing Patents Otherwise publication as part of the Politics of Patents case study (part of Copim WP6): this parses data from the archive of RTF files and provides additional data from the European Patent Office OPS API. https://patents.copim.ac.uk
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # @name: data.py
  2. # @creation_date: 2022-09-14
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: data route for data
  6. # @acknowledgements:
  7. # pycountry module for country data: https://pypi.org/project/pycountry/
  8. # data formatted for Chart.js: https://www.chartjs.org/docs/latest/
  9. from flask import Blueprint, render_template, request
  10. import random
  11. import pycountry
  12. from . import solr
  13. data = Blueprint('data', __name__)
  14. # route for main data page
  15. @data.route('/data/')
  16. def main_data():
  17. core = 'all'
  18. total_number = solr.get_total_number(core)
  19. year_data = solr.get_term_data('year', core)
  20. country_data = solr.get_term_data('country', core)
  21. # parse all the year data
  22. year_labels = []
  23. year_numbers = []
  24. year_dataset = []
  25. for i in range(0, len(year_data)):
  26. if i % 2:
  27. year_numbers.append(year_data[i])
  28. random_colour = "#" + "%06x" % random.randint(0, 0xFFFFFF)
  29. year_dict = {"label": "number of records", "data": year_numbers, "backgroundColor": random_colour}
  30. else:
  31. year_labels.append(year_data[i])
  32. year_dataset.append(year_dict)
  33. # parse all the country data
  34. country_labels = []
  35. country_numbers = []
  36. country_dataset = []
  37. background_colours = []
  38. for i in range(0, len(country_data)):
  39. if i % 2:
  40. country_numbers.append(country_data[i])
  41. x = 0
  42. while x <= len(country_data):
  43. random_colour = "#" + "%06x" % random.randint(0, 0xFFFFFF)
  44. background_colours.append(random_colour)
  45. x += 1
  46. country_dict = {"label": "number of records", "data": country_numbers, "backgroundColor": background_colours}
  47. else:
  48. country = pycountry.countries.get(alpha_2=country_data[i])
  49. if country is not None:
  50. country_labels.append(country.name)
  51. country_data[i] = country
  52. else:
  53. country = pycountry.historic_countries.get(alpha_2=country_data[i])
  54. if country is not None:
  55. country_data[i] = country
  56. country_labels.append(country.name)
  57. else:
  58. country_labels.append(country_data[i])
  59. country_dataset.append(country_dict)
  60. return render_template('data.html', total_number=total_number, year_data=year_data, year_labels=year_labels, year_dataset=year_dataset, country_data=country_data, country_labels=country_labels, country_dataset=country_dataset)