<commit_before># -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-04-08 04:56
from __future__ import unicode_literals

import datetime

from django.db import migrations


def migrate_keeping_pace(apps, schema_editor):
    Application = apps.get_model('oauth2_provider', 'Application')
    Study = apps.get_model('studies', 'Study')
    StudyGrant = apps.get_model('studies', 'StudyGrant')
    Member = apps.get_model('open_humans', 'Member')
    OAuth2DataRequestProject = apps.get_model('private_sharing',
                                              'OAuth2DataRequestProject')
    DataRequestProjectMember = apps.get_model('private_sharing',
                                              'DataRequestProjectMember')

    project = OAuth2DataRequestProject()

    project.is_study = True
    project.name = 'Keeping Pace'
    project.slug = 'keeping-pace'
    project.leader = 'Dr. <NAME>'
    project.organization = 'New York University'
    project.is_academic_or_nonprofit = True
    project.contact_email = ''
    project.info_url = 'https://keeping-pace.chunaralab.com/'
    project.short_description = ('Dynamic Assessment of Environment and '
                                 'Exercise Using Personal Health Data')
    project.long_description = ('Dynamic Assessment of Environment and '
                                'Exercise Using Personal Health Data')
    project.active = True
    # project.badge_image = ''
    project.request_sources_access = ['runkeeper']
    project.request_message_permission = False
    project.request_username_access = False
    project.coordinator = Member.objects.get(user__username='rumichunara')
    project.approved = True
    project.created = datetime.datetime(2015, 6, 23, 6, 15, 1, 544000)

    project.enrollment_url = 'https://keeping-pace.chunaralab.com/'
    project.redirect_url = ('https://keeping-pace.chunaralab.com'
                            '/accounts/openhumans/login/callback/')

    project.application = Application.objects.get(name='Keeping Pace')

    project.save()

    # Delete original Study
    Study.objects.all().delete()

    for grant in StudyGrant.objecs.all():
        if grant.revoked:
            continue

        project_member = DataRequestProjectMember()

        project_member.project = project
        project_member.member = grant.member_id
        project_member.sources_shared = ['runkeeper']
        project_member.joined = True
        project_member.authorized = True

        project_member.save()

    # Delete original StudyGrants
    StudyGrant.objects.all().delete()
<commit_msg>🐛 fix typo; reorder operations<commit_after># -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-04-08 04:56
from __future__ import unicode_literals

import datetime

from django.db import migrations


def migrate_keeping_pace(apps, schema_editor):
    Application = apps.get_model('oauth2_provider', 'Application')
    Study = apps.get_model('studies', 'Study')
    StudyGrant = apps.get_model('studies', 'StudyGrant')
    Member = apps.get_model('open_humans', 'Member')
    OAuth2DataRequestProject = apps.get_model('private_sharing',
                                              'OAuth2DataRequestProject')
    DataRequestProjectMember = apps.get_model('private_sharing',
                                              'DataRequestProjectMember')

    project = OAuth2DataRequestProject()

    project.is_study = True
    project.name = 'Keeping Pace'
    project.slug = 'keeping-pace'
    project.leader = 'Dr. <NAME>'
    project.organization = 'New York University'
    project.is_academic_or_nonprofit = True
    project.contact_email = ''
    project.info_url = 'https://keeping-pace.chunaralab.com/'
    project.short_description = ('Dynamic Assessment of Environment and '
                                 'Exercise Using Personal Health Data')
    project.long_description = ('Dynamic Assessment of Environment and '
                                'Exercise Using Personal Health Data')
    project.active = True
    # project.badge_image = ''
    project.request_sources_access = ['runkeeper']
    project.request_message_permission = False
    project.request_username_access = False
    project.coordinator = Member.objects.get(user__username='rumichunara')
    project.approved = True
    project.created = datetime.datetime(2015, 6, 23, 6, 15, 1, 544000)

    project.enrollment_url = 'https://keeping-pace.chunaralab.com/'
    project.redirect_url = ('https://keeping-pace.chunaralab.com'
                            '/accounts/openhumans/login/callback/')

    project.application = Application.objects.get(name='Keeping Pace')

    project.save()

    for grant in StudyGrant.objects.all():
        if grant.revoked:
            continue

        print 'Migrating StudyGrant for member ID "{}"'.format(grant.member_id)

        project_member = DataRequestProjectMember()

        project_member.project = project
        project_member.member = grant.member_id
        project_member.sources_shared = ['runkeeper']
        project_member.joined = True
        project_member.authorized = True

        project_member.save()

    # Delete original Study
    Study.objects.all().delete()

    # Delete original StudyGrants
    StudyGrant.objects.all().delete()

{'fraction_non_alphanumeric': 0.10081485692628388, 'fraction_numerical': 0.014023119196513171, 'mean_word_length': 2.8108303249097473, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5517689', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1420, 'n_words': 295}