def make_report_qualtrics(
    d, d_unmatched, data_level, course_data_filepath, course_row_index, template_filepath, plotting=True
):
    """
    Run the run_qualtrics() function to produce the entire set of saved plots.
    """

    # import the HTML template
    template = open(template_filepath, "r")
    html_template_string = template.read()

    print("course_row_index = {} (make_report_qualtrics)".format(course_row_index))

    # generate all the plots and metadata
    template_fill_data = P.run_qualtrics(d, d_unmatched, data_level, course_data_filepath, course_row_index, plotting)

    # create a new HTML document
    html_new_report = html_template_string  # initialize the new report prior to subsituting in content
    for var in list(template_fill_data.keys()):
        #        print var
        html_new_report = html_new_report.replace("{" + var + "}", template_fill_data[var])

    template.close()
    single_course_data = P.F.Import.course_data.irow(course_row_index)
    _directory_report = single_course_data["Directory"]
    if _directory_report[-1] != "\\":
        _directory_report += "\\"
    _course_title = single_course_data["Course_Title"]
    _course_number = single_course_data["Course_Number"]
    _ugly_name = single_course_data["Ugly_name"]

    # Create and save the new HTML report file

    _filename_report = _directory_report + "ECLASS_Report_" + _ugly_name + ".html"
    report = open(_filename_report, "w")
    report.write(html_new_report)
    report.close()
def make_report(class_name="Western_Michigan_University_Physics_1140_General_Physics_1_Lab", directory="empty"):

    #    class_name = 'Western_Michigan_University_Physics_1140_General_Physics_1_Lab'

    # make a directory with the date and time
    if directory == "empty":
        today = dt.datetime.now()
        if _user == "Ben":
            _directory_date = _directory_html + today.strftime("%Y-%m-%d %H.%M.%S %p") + "\\"
        elif _user == "Takako":
            _directory_date = _directory_html + today.strftime("%Y-%m-%d %H.%M.%S %p") + "/"
    else:
        _directory_date = directory

    if os.path.isdir(_directory_date) == False:
        os.mkdir(_directory_date)

    # make a subdirectory for the report for the school.
    # The HTML file is saved within this directory
    if _user == "Ben":
        _directory_report = (
            _directory_date
            + P.get_readable_institution(class_name)
            + " "
            + P.get_readable_course_name(class_name)
            + "\\"
        )
    elif _user == "Takako":
        _directory_report = (
            _directory_date
            + P.get_readable_institution(class_name)
            + " "
            + P.get_readable_course_name(class_name)
            + "/"
        )
    if os.path.isdir(_directory_report) == False:
        os.mkdir(_directory_report)

    # Create a sub-sub-directory for all the plots and maybe tables.
    # I am not sure how to best incorporate the tables at this point.  Does pandas
    # have an HTML export for the pandas DataFrames?
    if _user == "Ben":
        _directory_graphics = _directory_report + "Graphics\\"
    elif _user == "Takako":
        _directory_graphics = _directory_report + "Graphics/"
    if os.path.isdir(_directory_graphics) == False:
        os.mkdir(_directory_graphics)

    # Make the graphics
    # make_graphics(data=[], directory_graphics = _directory_graphics)

    # Save the HTML report within the subdirectory for the course
    # Save hte accompanying graphics within the subdirectory for course\graphics

    # Load the HTML Template
    template = open(_filename_template, "r")

    # Make all the graphics and get the info from the data set
    template_fill_data = P.run(class_name=class_name, graphics_directory=_directory_graphics)
    print(template_fill_data)

    if template_fill_data == "error":
        return "error"

    html_template_string = template.read()
    html_new_report = html_template_string  # initialize the new report prior to subsituting in content
    for var in list(template_fill_data.keys()):
        #        print var
        html_new_report = html_new_report.replace("{" + var + "}", template_fill_data[var])

    #        print template_fill_data[var]
    #    grade_table_html = P.run()
    #
    #    html_new_report = html_new_report.replace('{GRADE_TABLE}',grade_table_html)

    template.close()

    #    print html_new_report

    # Create and save the new HTML report file
    _filename_report = _directory_report + "ECLASS_Report_" + P.get_readable_course_name(class_name) + ".html"
    report = open(_filename_report, "w")
    report.write(html_new_report)
    report.close()