<commit_before>import argparse
import shutil
import os

import matplotlib.pyplot as plt
import pandas as pd

from library.api import API_HOST, get_token, fetch_objects
from library.settings import ITEM_FORMAT, OPTION_FORMAT, STEP_FORMAT
from library.utils import (html2latex, create_answer_matrix, get_course_structure,
                           get_course_submissions, get_step_options,
                           get_item_statistics, get_question, process_step_url, process_options_with_name,
                           get_video_peaks, get_video_stats)


class ExternalCourseReport:
    default_project_folder = 'default'
    default_report_name = 'course-report'
    course_project_folder = 'course-{}'
    course_report_name = 'course-{}-report'

    def __init__(self):
        self.course_id = 0

    def get_parser(self):
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--course', type=int, help='course id')
        parser.add_argument('-n', '--nocache', action='store_true', help='no cache when generate latex report')
        parser.add_argument('-u', '--update', action='store_true', help='update project when compile latex report')
        return parser

    def build(self):
        args = self.get_parser().parse_args()

        if args.course:
            self.course_id = args.course
            cached = not bool(args.nocache)
            update = bool(args.update)

            print('Course {} processing...'.format(self.course_id))

            base = 'latex/'
            directory_name = self.course_project_folder.format(self.course_id)
            full_directory = base + directory_name

            if not os.path.exists(full_directory):
                shutil.copytree(base + self.default_project_folder, full_directory)

            self.generate_latex_report(full_directory + '/generated/', cached=cached)
            self.compile_latex_report(full_directory, update=update)

    def generate_latex_report(self, directory, cached=True):
        pass

    def compile_latex_report(self, directory, update=True):
        latex_command = 'pdflatex -synctex=1 -interaction=nonstopmode {}.tex'.format(self.default_report_name)

        os.chdir(directory)

        if update:
            os.system('cp -rf ../{}/* .'.format(self.default_project_folder))

        # Launch LaTeX three times
        os.system(latex_command)
        os.system(latex_command)
        os.system(latex_command)

        report_name = self.course_report_name.format(self.course_id)
        os.system('cp {}.pdf ../../pdf/{}.pdf'.format(self.default_report_name, report_name))


class ItemReport(ExternalCourseReport):
    default_project_folder = 'default-item'
    default_report_name = 'course-item-report'
    course_project_folder = 'course-{}-item'
    course_report_name = 'course-{}-item-report'<commit_msg>fix copy files and directory<commit_after>import argparse
import shutil
import os

import matplotlib.pyplot as plt
import pandas as pd

from library.api import API_HOST, get_token, fetch_objects
from library.settings import ITEM_FORMAT, OPTION_FORMAT, STEP_FORMAT
from library.utils import (html2latex, create_answer_matrix, get_course_structure,
                           get_course_submissions, get_step_options,
                           get_item_statistics, get_question, process_step_url, process_options_with_name,
                           get_video_peaks, get_video_stats)


class ExternalCourseReport:
    default_project_folder = 'default'
    default_report_name = 'course-report'
    course_project_folder = 'course-{}'
    course_report_name = 'course-{}-report'

    def __init__(self):
        self.course_id = 0

    def get_parser(self):
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--course', type=int, help='course id')
        parser.add_argument('-n', '--nocache', action='store_true', help='no cache when generate latex report')
        parser.add_argument('-u', '--update', action='store_true', help='update project when compile latex report')
        return parser

    def build(self):
        args = self.get_parser().parse_args()

        if args.course:
            self.course_id = args.course
            cached = not bool(args.nocache)
            update = bool(args.update)

            print('Course {} processing...'.format(self.course_id))

            base = 'latex/'
            directory_name = self.course_project_folder.format(self.course_id)
            full_directory = base + directory_name

            if update:
                shutil.rmtree(full_directory)
            if not os.path.exists(full_directory):
                shutil.copytree(base + self.default_project_folder, full_directory)

            self.generate_latex_report(full_directory + '/generated/', cached=cached)
            self.compile_latex_report(full_directory)

    def generate_latex_report(self, directory, cached=True):
        pass

    def compile_latex_report(self, directory):
        latex_command = 'pdflatex -synctex=1 -interaction=nonstopmode {}.tex'.format(self.default_report_name)

        # Launch LaTeX three times
        os.chdir(directory)
        os.system(latex_command)
        os.system(latex_command)
        os.system(latex_command)

        report_name = self.course_report_name.format(self.course_id)
        shutil.copy('{}.pdf'.format(self.default_report_name),
                    '../../pdf/{}.pdf'.format(report_name))


class ItemReport(ExternalCourseReport):
    default_project_folder = 'default-item'
    default_report_name = 'course-item-report'
    course_project_folder = 'course-{}-item'
    course_report_name = 'course-{}-item-report'
{'fraction_non_alphanumeric': 0.10285311729482212, 'fraction_numerical': 0.0010567101091933778, 'mean_word_length': 2.9246717346233586, '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': '5820556', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1624, 'n_words': 315}