Skip to content

Commit

Permalink
Merge pull request #256 from gitnnolabs/indicators_improvements
Browse files Browse the repository at this point in the history
Realiza melhorias no processamento dos indicadores ajusta dados no índice.
  • Loading branch information
gitnnolabs authored Dec 1, 2023
2 parents 24cf6a5 + 75d2455 commit 32b42a3
Show file tree
Hide file tree
Showing 10 changed files with 596 additions and 14 deletions.
2 changes: 1 addition & 1 deletion article/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def prepare_thematic_level_2(self, obj):
return thematics

def prepare_programs(self, obj):
return ["AGRONOMIA".title(), "AGRONEGÓCIO".title()]
return []

def get_model(self):
return models.Article
Expand Down
8 changes: 4 additions & 4 deletions article/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def load_openalex(user_id, date=2012, length=None, country="BR"):
logger.info(f"Unexpected error: {e}")


@celery_app.task(name=_("ArticleSource to Article"))
@celery_app.task(name=_("Load ArticleSource to Article"))
def article_source_to_article(
user_id,
source_name="OPENALEX",
Expand Down Expand Up @@ -597,7 +597,7 @@ def load_sucupira(production_file_csv, detail_file_csv, authors):
)


@celery_app.task(name="Match between institutions and affiliations")
@celery_app.task(name="Match between contributor institutions and set corresponding affiliations")
def match_contrib_inst_aff(user_id):
"""
This task loop to all contributor looking for contributor.institutions and find the affiliation
Expand Down Expand Up @@ -638,8 +638,8 @@ def match_contrib_aff_source_with_inst_MEC(user_id):
aff.save()


@celery_app.task(name="Load concepts")
def load_concepts(user_id, delete=True):
@celery_app.task(name="Load OpenAlex Concepts")
def load_openalex_concepts(user_id, delete=True):
"""
This task add the concepts from a .csv file and Related theme between Concepts and Thematic Area(CAPES)
Expand Down
517 changes: 517 additions & 0 deletions django_celery_beat/scripts/create_tasks.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion django_celery_beat/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class PeriodicTaskAdmin(ModelAdmin):
celery_app = current_app
date_hierarchy = "start_time"
list_display = (
"__str__",
"name",
"description",
"enabled",
"interval",
"start_time",
Expand Down
15 changes: 15 additions & 0 deletions education_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ class EducationIndex(indexes.SearchIndex, indexes.Indexable):
model_attr="institutional_contribution", null=True
)

# control fields
created = indexes.CharField(null=False)
updated = indexes.CharField(null=False)
creator = indexes.CharField(null=False)
updated_by = indexes.CharField(null=False)

def prepare_created(self, obj):
return obj.created.isoformat()

def prepare_updated(self, obj):
return obj.updated.isoformat()

def prepare_creator(self, obj):
return obj.creator

def prepare_record_type(self, obj):
return "directory"

Expand Down
15 changes: 15 additions & 0 deletions event_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ class EventIndex(indexes.SearchIndex, indexes.Indexable):
model_attr="institutional_contribution", null=True
)

# control fields
created = indexes.CharField(null=False)
updated = indexes.CharField(null=False)
creator = indexes.CharField(null=False)
updated_by = indexes.CharField(null=False)

def prepare_created(self, obj):
return obj.created.isoformat()

def prepare_updated(self, obj):
return obj.updated.isoformat()

def prepare_creator(self, obj):
return obj.creator

def prepare_record_type(self, obj):
return "directory"

Expand Down
12 changes: 8 additions & 4 deletions indicator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# sciprod.generate_indicators(creator, filter_by, group_by, begin_year, end_year)


@celery_app.task(bind=True, name=_("Geração de indicadores científicos"))
@celery_app.task(bind=True, name=_("Generate scientific indicator"))
def task_generate_article_indicators(self, user_id, indicators):
"""
This task receive a indicators list, something like:
Expand All @@ -60,6 +60,9 @@ def task_generate_article_indicators(self, user_id, indicators):

user = User.objects.get(id=user_id)

models.Indicator.objects.all().delete()
models.IndicatorFile.objects.all().delete()

for ind in indicators:
ind = indicator.Indicator(**ind)
serie_list = []
Expand All @@ -86,16 +89,17 @@ def task_generate_article_indicators(self, user_id, indicators):
serie_json = json.dumps(
{"keys": [key for key in ind.get_keys()], "series": serie_list}
)

# check if the indicator file existe and if ids is not empty.
if ind.get_ids() and not models.IndicatorFile.objects.filter(
if not models.IndicatorFile.objects.filter(
data_ids=ind.get_ids()
):

indicator_model = models.Indicator(
title=ind.title,
creator=user,
summarized=serie_json,
record_status="PUBLISHED",
record_status= "PUBLISHED" if ind.get_ids() else "NOT PUBLISHED",
description=ind.description,
)

Expand Down
15 changes: 15 additions & 0 deletions infrastructure_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ class InfraStructureIndex(indexes.SearchIndex, indexes.Indexable):
model_attr="institutional_contribution", null=True
)

# control fields
created = indexes.CharField(null=False)
updated = indexes.CharField(null=False)
creator = indexes.CharField(null=False)
updated_by = indexes.CharField(null=False)

def prepare_created(self, obj):
return obj.created.isoformat()

def prepare_updated(self, obj):
return obj.updated.isoformat()

def prepare_creator(self, obj):
return obj.creator

def prepare_record_type(self, obj):
return "directory"

Expand Down
15 changes: 15 additions & 0 deletions policy_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ class PolicyIndex(indexes.SearchIndex, indexes.Indexable):
institutional_contribution = indexes.CharField(
model_attr="institutional_contribution", null=True
)

# control fields
created = indexes.CharField(null=False)
updated = indexes.CharField(null=False)
creator = indexes.CharField(null=False)
updated_by = indexes.CharField(null=False)

def prepare_created(self, obj):
return obj.created.isoformat()

def prepare_updated(self, obj):
return obj.updated.isoformat()

def prepare_creator(self, obj):
return obj.creator

def prepare_record_type(self, obj):
return "directory"
Expand Down
8 changes: 4 additions & 4 deletions search/templates/indicator/indicator_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ <h2 style="margin-bottom: 5px;">{{ object.title }}</h2>
<a class="nav-link" id="ex2-tab-2" data-toggle="tab" href="#ex2-tabs-2" role="tab"
aria-controls="ex2-tabs-2" aria-selected="false">Dados</a>
</li>
<li class="nav-item" role="presentation">
<!-- <li class="nav-item" role="presentation">
<a class="nav-link" id="ex2-tab-3" data-toggle="tab" href="#ex2-tabs-3" role="tab"
aria-controls="ex2-tabs-3" aria-selected="false">Sobre</a>
</li>
</li> -->
</ul>
<!-- Tabs navs -->

Expand All @@ -106,9 +106,9 @@ <h2 style="margin-bottom: 5px;">{{ object.title }}</h2>
<div class="tab-pane fade" id="ex2-tabs-2" role="tabpanel" aria-labelledby="ex2-tab-2">
Download dados brutos: <a href="{% get_media_prefix %}{{ object.indicator_file.raw_data }}">{{ object.indicator_file }}</a>
</div>
<div class="tab-pane fade" id="ex2-tabs-3" role="tabpanel" aria-labelledby="ex2-tab-3">
<!-- <div class="tab-pane fade" id="ex2-tabs-3" role="tabpanel" aria-labelledby="ex2-tab-3">
sobre
</div>
</div> -->
</div>

<br>
Expand Down

0 comments on commit 32b42a3

Please sign in to comment.