<commit_before>"""
This will update node links on POPULAR_LINKS_NODE and NEW_AND_NOTEWORTHY_LINKS_NODE.
"""
import sys
import logging
import datetime
import dateutil
import operator
import requests
from modularodm import Q
from website.app import init_app
from website import models
from framework.auth.core import Auth
from scripts import utils as script_utils
from framework.mongo import database as db
from framework.transactions.context import TokuTransaction
from website.project.model import Pointer
from website.discovery.views import popular_activity_json
from website.settings import POPULAR_LINKS_NODE, NEW_AND_NOTEWORTHY_LINKS_NODE, NEW_AND_NOTEWORTHY_CONTRIBUTOR_BLACKLIST

logger = logging.getLogger(__name__)


def get_new_and_noteworthy_nodes():
    """ Fetches nodes created in the last month and returns 25 sorted by highest log activity """
    today = datetime.datetime.now()
    last_month = (today - dateutil.relativedelta.relativedelta(months=1))
    data = db.node.find({'date_created': {'$gt': last_month}, 'is_public': True, 'is_registration': False})
    node_log_count_mapping = {}
    for new_node in data:
        node_log_count_mapping[new_node['_id']] = len(new_node['logs'])
    sort_by_log_count = sorted(node_log_count_mapping.items(), key=operator.itemgetter(1), reverse=True)
    sorted_node_ids = [node[0] for node in sort_by_log_count]
    return sorted_node_ids[:25]

def is_eligible_node(node):
    """
    Check to ensure that node is not the POPULAR or NEW_AND_NOTEWORTHY LINKS_NODE.
    Ensures QA members are not contributors
    """
    if node._id == POPULAR_LINKS_NODE or node._id == NEW_AND_NOTEWORTHY_LINKS_NODE:
        return False<commit_msg>Just sort by ids instead of using intermediate dictionary.<commit_after>"""
This will update node links on POPULAR_LINKS_NODE and NEW_AND_NOTEWORTHY_LINKS_NODE.
"""
import sys
import logging
import datetime
import dateutil
import operator
import requests
from modularodm import Q
from website.app import init_app
from website import models
from framework.auth.core import Auth
from scripts import utils as script_utils
from framework.mongo import database as db
from framework.transactions.context import TokuTransaction
from website.project.model import Pointer
from website.discovery.views import popular_activity_json
from website.settings import POPULAR_LINKS_NODE, NEW_AND_NOTEWORTHY_LINKS_NODE, NEW_AND_NOTEWORTHY_CONTRIBUTOR_BLACKLIST

logger = logging.getLogger(__name__)


def get_new_and_noteworthy_nodes():
    """ Fetches nodes created in the last month and returns 25 sorted by highest log activity """
    today = datetime.datetime.now()
    last_month = (today - dateutil.relativedelta.relativedelta(months=1))
    data = db.node.find({'date_created': {'$gt': last_month}, 'is_public': True, 'is_registration': False})
    noteworthy_nodes = sorted(data, key=lambda node: len(node['logs']), reverse=True)[:25]
    return [each['_id'] for each in noteworthy_nodes]

def is_eligible_node(node):
    """
    Check to ensure that node is not the POPULAR or NEW_AND_NOTEWORTHY LINKS_NODE.
    Ensures QA members are not contributors
    """
    if node._id == POPULAR_LINKS_NODE or node._id == NEW_AND_NOTEWORTHY_LINKS_NODE:
        return False
{'fraction_non_alphanumeric': 0.07510003077870114, 'fraction_numerical': 0.003693444136657433, 'mean_word_length': 5.435643564356436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7550450', 'n_tokens_mistral': 1016, 'n_tokens_neox': 967, 'n_words': 294}