<commit_before>#!/usr/bin/env python3

# Akvo Reporting is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

""" Make a program from the given project id

Usage:

    python manage.py make_program project_id

"""

import datetime

from django.core.management.base import BaseCommand

from akvo.rsr.models import Project, ProjectHierarchy


class Command(BaseCommand):
    help = "Make a program from the given project id"

    def add_arguments(self, parser):
        parser.add_argument(
            "project_id",
            type=int,
            help="ID of the project from which to make a program",
        )

    def handle(self, *args, **options):
        project_id = options['project_id']
        assert not ProjectHierarchy.objects.filter(root_project_id=project_id).exists(), 'Program for the project already exists'

        project = Project.objects.get(id=project_id)
        program, created = ProjectHierarchy.objects.get_or_create(root_project=project, max_depth=2)<commit_msg>[#4523] Remove unused import<commit_after>#!/usr/bin/env python3

# Akvo Reporting is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

""" Make a program from the given project id

Usage:

    python manage.py make_program project_id

"""

from django.core.management.base import BaseCommand

from akvo.rsr.models import Project, ProjectHierarchy


class Command(BaseCommand):
    help = "Make a program from the given project id"

    def add_arguments(self, parser):
        parser.add_argument(
            "project_id",
            type=int,
            help="ID of the project from which to make a program",
        )

    def handle(self, *args, **options):
        project_id = options['project_id']
        assert not ProjectHierarchy.objects.filter(root_project_id=project_id).exists(), 'Program for the project already exists'

        project = Project.objects.get(id=project_id)
        program, created = ProjectHierarchy.objects.get_or_create(root_project=project, max_depth=2)
{'fraction_non_alphanumeric': 0.08558178752107926, 'fraction_numerical': 0.003372681281618887, 'mean_word_length': 3.4858223062381852, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2483967', 'n_tokens_mistral': 674, 'n_tokens_neox': 655, 'n_words': 224}