<commit_before>import sys
import logging

from modularodm import Q

from website.app import init_app
from website.models import Node, NodeLog

logger = logging.getLogget(__name__)
logging.basicConfig(level=logging.WARN)

PRIMARY_INSTITUTION_CHANGED = 'primary_institution_changed'
PRIMARY_INSTITUTION_REMOVED = 'primary_institution_removed'

def migrate_logs(dry_run):
    added_logs = NodeLog.find(Q('action', 'eq', PRIMARY_INSTITUTION_CHANGED))
    for log in added_logs:
        logger.warn('Log with id <{}> being updated for affiliation added').format(log._id)
        if not dry_run:
            log.action = NodeLog.AFFILIATED_INSTITUTION_ADDED
            log.save()
    removed_logs = NodeLog.find(Q('action', 'eq', PRIMARY_INSTITUTION_REMOVED))
    for log in removed_logs:
        logger.warn('Log with id <{}> being updated for affiliation removed').format(log._id)
        if not dry_run:
            log.action = NodeLog.AFFILIATED_INSTITUTION_REMOVED
            log.save()

def migrate_nodes(dry_run):
    nodes = Node.find(Q('primary_institution', 'ne', None))
    for node in nodes:
        logger.warn('Node with id <{}> and title <{}> being updated').format(node._id, node.title)
        if not dry_run:
            inst = node.primary_institution
            if inst not in node.affiliated_institutions:
                node.affiliated_institutions.append(inst)<commit_msg>fix script problems<commit_after>import sys
import logging

from modularodm import Q

from website.app import init_app
from website.models import Node, NodeLog

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.WARN)

PRIMARY_INSTITUTION_CHANGED = 'primary_institution_changed'
PRIMARY_INSTITUTION_REMOVED = 'primary_institution_removed'

def migrate_logs(dry_run):
    added_logs = NodeLog.find(Q('action', 'eq', PRIMARY_INSTITUTION_CHANGED))
    for log in added_logs:
        logger.warn('Log with id <{}> being updated for affiliation added'.format(log._id))
        if not dry_run:
            log.action = NodeLog.AFFILIATED_INSTITUTION_ADDED
            log.save()
    removed_logs = NodeLog.find(Q('action', 'eq', PRIMARY_INSTITUTION_REMOVED))
    for log in removed_logs:
        logger.warn('Log with id <{}> being updated for affiliation removed'.format(log._id))
        if not dry_run:
            log.action = NodeLog.AFFILIATED_INSTITUTION_REMOVED
            log.save()

def migrate_nodes(dry_run):
    nodes = Node.find(Q('primary_institution', 'ne', None))
    for node in nodes:
        logger.warn('Node with id <{}> and title <{}> being updated'.format(node._id, node.title))
        if not dry_run:
            inst = node.primary_institution
            if inst not in node.affiliated_institutions:
                node.affiliated_institutions.append(inst)
{'fraction_non_alphanumeric': 0.09591982820329277, 'fraction_numerical': 0.0, 'mean_word_length': 3.5595432300163132, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2268000', 'n_tokens_mistral': 898, 'n_tokens_neox': 860, 'n_words': 199}