<commit_before># -*- encoding: utf-8 -*-

# Dissemin: open access policy enforcement tool
# Copyright (C) 2014 <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

from __future__ import absolute_import
from __future__ import unicode_literals

from statistics.models import AccessStatistics

from backend.crossref import consolidate_publication
from backend.orcid import OrcidPaperSource
from backend.utils import run_only_once
from celery import shared_task
from celery.utils.log import get_task_logger
from django.utils import timezone
from papers.errors import MetadataSourceException
from papers.models import Department
from papers.models import Institution
from papers.models import Paper
from papers.models import PaperWorld
from papers.models import Researcher
from publishers.models import Journal
from publishers.models import Publisher

logger = get_task_logger(__name__)


def update_researcher_task(r, task_name):
    """
    Update the task identifier associated to a given researcher.
    This also updates the 'last_harvest' field.
    """
    r.current_task = task_name
    r.last_harvest = timezone.now()
    r.save(update_fields=['current_task', 'last_harvest'])


@shared_task(name='init_profile_from_orcid')
@run_only_once('researcher', keys=['pk'])
def init_profile_from_orcid(pk):
    """
    Populates the profile from ORCID and Crossref

    This task is intended to be very quick, so that users
    can see their ORCID publications quickly.<commit_msg>Remove unused imports<commit_after># -*- encoding: utf-8 -*-

# Dissemin: open access policy enforcement tool
# Copyright (C) 2014 <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

from __future__ import absolute_import
from __future__ import unicode_literals

from statistics.models import AccessStatistics

from backend.crossref import consolidate_publication
from backend.orcid import OrcidPaperSource
from backend.utils import run_only_once
from celery import shared_task
from celery.utils.log import get_task_logger
from django.utils import timezone
from papers.errors import MetadataSourceException
from papers.models import Paper
from papers.models import PaperWorld
from papers.models import Researcher
from publishers.models import Journal
from publishers.models import Publisher

logger = get_task_logger(__name__)


def update_researcher_task(r, task_name):
    """
    Update the task identifier associated to a given researcher.
    This also updates the 'last_harvest' field.
    """
    r.current_task = task_name
    r.last_harvest = timezone.now()
    r.save(update_fields=['current_task', 'last_harvest'])


@shared_task(name='init_profile_from_orcid')
@run_only_once('researcher', keys=['pk'])
def init_profile_from_orcid(pk):
    """
    Populates the profile from ORCID and Crossref

    This task is intended to be very quick, so that users
    can see their ORCID publications quickly.
{'fraction_non_alphanumeric': 0.061625977719838826, 'fraction_numerical': 0.008058781701825076, 'mean_word_length': 4.869262865090404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1150895', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1103, 'n_words': 491}