Skip to content

Commit

Permalink
Refatora alguns código relacionado com a criação dos indicadores e de…
Browse files Browse the repository at this point in the history
…versos ajustes na apresentação do gráfico.
  • Loading branch information
gitnnolabs committed Aug 13, 2024
1 parent 20bf75d commit 7120a24
Show file tree
Hide file tree
Showing 13 changed files with 818 additions and 369 deletions.
18 changes: 18 additions & 0 deletions core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,21 @@ def parse_string_to_dicts(input_string, split_caracter=",", ret_type="list"):
ret_items.update({parts[0]: parts[1]})

return ret_items


def replace_spaces_broken_lines(dictionary):
"""
Replaces spaces in dictionary keys with newlines.
Args:
dictionary: The dictionary with keys that may contain spaces.
Returns:
A new dictionary with the modified keys.
"""

new_dict = {}
for key, value in dictionary.items():
new_key = key.replace(" ", "\n")
new_dict[new_key] = value
return new_dict
1 change: 1 addition & 0 deletions index/ocabr/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<field name="record_status" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="directory_type" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="practice" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="classification" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="action" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="category" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="institutional_contribution" type="string" indexed="true" stored="true" multiValued="false"/>
Expand Down
1 change: 1 addition & 0 deletions index/ocabr/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<str name="facet.field">type</str>
<str name="facet.field">record_status</str>
<str name="facet.field">practice</str>
<str name="facet.field">classification</str>
<str name="facet.field">action</str>
<!-- melhor ficar só na pesquisa -->
<str name="facet.field">institutions</str>
Expand Down
37 changes: 20 additions & 17 deletions indicator/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
fill_range=True,
fill_range_value=0,
solr_instance=None,
include_all=False
include_all=False,
):
"""Initializes the instance indicator class.
Expand Down Expand Up @@ -182,7 +182,7 @@ def get_keys(self):
"""
return self.get_facet(self.facet_by).keys()

def dynamic_filters(self):
def dynamic_filters(self, key_list=None):
"""
This get the facets in index and update the filters attribute.
Expand All @@ -203,9 +203,16 @@ def dynamic_filters(self):

for context in self.context_by:
context_result = self.get_facet(context, result)
context_list.append(
['%s:"%s"' % (context, keys) for keys in context_result.keys()]
)
if key_list:
inter_list=[]
for key in context_result.keys():
if key in key_list:
inter_list.append('%s:"%s"' % (context, key))
context_list.append(inter_list)
else:
context_list.append(
['%s:"%s"' % (context, keys) for keys in context_result.keys()]
)

context_prod = self._product(*context_list)

Expand All @@ -216,7 +223,7 @@ def dynamic_filters(self):

self.logger.info(self.filters)

def generate(self):
def generate(self, key_list=None):
"""This will produce the discrete mathematics based on filters to index.
Args:
Expand All @@ -242,16 +249,16 @@ def generate(self):
"""
ret = []
q_list = []

if self.context_by:
self.dynamic_filters()
self.dynamic_filters(key_list)

for filter in self.filters:
filters = {}
# add the default filter
filters.update(filter)
filters.update(self.default_filter)

if self.range_filter:
filters.update(
{
Expand Down Expand Up @@ -506,12 +513,10 @@ def get_data(self, rows=10000, files_by_year=False):
for char in unwanted_chars:
clq = clq.replace(char, "_")

self.logger.info(
"Filter: %s (%s)" % (q, len(data))
)
self.logger.info("Filter: %s (%s)" % (q, len(data)))

yield (
"%s" % (str(re.sub(r'_{2,}', '_', clq.lower()))),
"%s" % (str(re.sub(r"_{2,}", "_", clq.lower()))),
data,
)
else:
Expand All @@ -531,11 +536,9 @@ def get_data(self, rows=10000, files_by_year=False):
for char in unwanted_chars:
clq = clq.replace(char, "_")

self.logger.info(
"Filter: %s (%s)" % (q, len(data))
)
self.logger.info("Filter: %s (%s)" % (q, len(data)))

yield (
"%s" % (str(re.sub(r'_{2,}', '_', clq.lower()))),
"%s" % (str(re.sub(r"_{2,}", "_", clq.lower()))),
data,
)
Loading

0 comments on commit 7120a24

Please sign in to comment.