Exemplo n.º 1
0
    def create_agg_directory(self):
        global aggregate_id
        global aggdir

        aggregate_id = self.aggregate_field.get()
        aggdir = temppath + "\\" + aggregate_id
        print "Aggregate project ID: ", aggregate_id

        # Create storage directory
        if os.path.isdir(aggdir) is False:
            ra.aggdirectory(temppath, aggregate_id)
            print "Directory for aggregate project ID " + aggregate_id + " created."
        else:
            print "Directory already exists, copying required files..."

        # Copy RBD Merge tool and RBD Template files to the Aggregates directory
        ra.cp(
            const.RBD_MERGE,
            temppath + "\\" + aggregate_id + r"\Templates\2017 RBD Merge.xls")
        ra.cp(
            const.RBD_TEMPLATE, temppath + "\\" + aggregate_id +
            r"\Templates\2017 RBD Template.xls")

        # Make file confirmation button active
        self.confirm_button.config(highlightbackground="dark gray",
                                   highlightthickness=1,
                                   state="normal")
Exemplo n.º 2
0
def get_merge_temp(contract):
    '''
    Get the appropriate Mail Merge Template file.
    '''
    merge_template = const.MERGE_TEMPLATE % contract['SurveyType']
    ra.cp(merge_template, temp_path)
    merge_temp = temp_path + '\\%s' % contract['SurveyType'] + ' Mail Merge.csv'

    return merge_temp
Exemplo n.º 3
0
def prep_clones(contract, path):
    '''
    Get the appropriate Excel and Word template file
    and copy them to the temporary clone directory.
    '''
    contractdir = const.CONTRACTDIR % contract['ProjectID']
    temp_path = contractdir + '\\clones'

    excel_temp = const.EXCEL_TEMPLATE % contract['SurveyType']
    ra.cp(excel_temp, temp_path)

    word_temp = const.WORD_TEMPLATE % contract['SurveyType']
    ra.cp(word_temp, temp_path)

    return 0
Exemplo n.º 4
0
    def create_aggregate(self, files):
        aggregate_path = temppath + "\\" + aggregate_id + r"\%s.txt" % aggregate_id  # Path to aggregate file
        aggregate_log = open(aggregate_path, 'w')

        # Write initial file to new aggregate filename
        first_path = temppath + "\\" + aggregate_id + r'\Files' + r'\%s.txt' % files[
            0]
        start = open(first_path)
        for i, line in enumerate(start):
            line.strip()
            aggregate_log.write(line)
        start.close()
        aggregate_log.close()
        print "Wrote " + files[
            0] + '.txt to new aggregate file, ' + aggregate_id + '.txt'

        # Make iterable and skip first file
        iterfiles = iter(files)
        next(iterfiles)

        # Remove headers and combine remaining files
        for item in iterfiles:
            path = temppath + "\\" + aggregate_id + r'\Files' + r'\%s.txt' % item
            piece = open(path)
            aggregate_log = open(aggregate_path, 'a')
            for i, line in enumerate(piece):
                if i > 0:
                    line.strip()
                    aggregate_log.write(line)
            piece.close()
            aggregate_log.close()
            print "Wrote " + item + '.txt to new aggregate file, ' + aggregate_id + '.txt'

        # Copy new file to Data Files directory
        ra.cp(aggregate_path, datapath % aggregate_id)
        print "Aggregate file with Project ID " + aggregate_id + " was copied to the Data Files folder."
Exemplo n.º 5
0
def run_xl_report(contract):
    '''
    Runs the Excel portion of the final report.
    '''
    # Define global variables
    global temp_path
    global rbd_path
    global rbda_path
    global banners_1
    global banners_2
    global excel_temp
    global word_temp
    global excel_report
    global word_report
    global excel_pdf
    global merge_temp
    global mail_merge
    global prereqs

    # Start Progress bar
    ui.progress_bar()

    print "\nGathering resources...",
    # Get the paths before we start
    temp_path = get_temp_path(contract)
    rbd_path = get_RBD(contract, temp_path)
    rbda_path = get_RBD_A(contract, temp_path)
    banners_1 = get_banners_1(contract)
    banners_2 = get_banners_2(contract)
    excel_temp = get_excel_temp(contract, temp_path)
    word_temp = get_word_temp(contract, temp_path)
    excel_report = get_excel_report(contract)
    word_report = get_word_report(contract)
    excel_pdf = get_excel_pdf(contract)
    merge_temp = get_merge_temp(contract)
    mail_merge = get_mail_merge(contract)
    print "Success!"

    # Verify that the prepwork module was run first.
    print "\nVerifying prerequisites...",
    prereqs = os.path.isdir(temp_path)

    if prereqs is False:
        check_prereqs(prereqs)
    #     print "\n>> You must run the prep work module (cahpsprep.py) before running this module."
    #     print ">> This is because several files are created within the prep work module that are required to successfully create contract reports."
    #     print ">> This program will now quit. Please run the prepwork module first."
    #     print ">> Goodbye!"
    #     sys.exit()
    else:
        print "Success!"
        # Update Verify Check status
        ui.verify_check.config(fg="#60E83B")
        ui.verify_check_text.config(fg="#60E83B")
        time.sleep(0.1)
        ui.progress.step()
        ui.progress.update()

    # Make sure we have all the required inputs
    try:
        assert os.path.exists(rbd_path)
    except AssertionError:
        print "Oops! It looks like you don't have an RBD for this contract."
        print "Try again once you have an RBD available."
    try:
        assert os.path.exists(banners_1)
        assert os.path.exists(banners_2)
    except AssertionError:
        print "Banners not found. Please check the contract directory"
        print "as they may have been moved or renamed."

    # Copy appropriate Excel & Word templates to contract folder
    print "Cloning templates...",
    cp(excel_temp, excel_report)
    cp(word_temp, word_report)
    cp(merge_temp, mail_merge)
    print "Success!"

    #pdb.set_trace()
    # Begin Excel report production
    print "\nBeginning Excel Report production..."
    ui.progress.update()
    with excel.xlconnection() as xlapp:

        # Open the Excel report
        #begin_excel(contract, xlapp)
        print ">> Opening Excel workbook...",
        global xlrpt
        xlrpt = excel.open_workbook(xlapp, excel_report)
        print "Success!"

        # Find the tabs you want to paste data into
        global banners_1_dst
        global banners_2_dst
        global rbd_dst
        global rbd2_dst

        banners_1_dst = excel.get_tab(xlrpt, "Banners1")
        banners_2_dst = excel.get_tab(xlrpt, "Banners2")
        rbd_dst = excel.get_tab(xlrpt, "RBD")
        if contract['SurveyType'] == 'MCS CCC':
            rbd2_dst = excel.get_tab(xlrpt, "RBD2")

        # # Get .csv core banner set 1
        apply_banner1(contract, xlapp)
        # banners_1_src = excel.open_workbook(xlapp, banners_1)
        # banners_1_data_src = excel.get_tab(banners_1_src, "%s Banners1" %
        #                                    contract['ProjectID'])
        # # Copy core banners to Banners1 tab
        # excel.paste_range(banners_1_data_src, "A:Y", banners_1_dst, "A:Y")
        # # Remove '-' from Wincross tab
        # excel.replace_zeros(banners_1_dst, "A:Y")
        # # Close core banner file
        # print ">> Applying Banner Set 1...",
        # del banners_1_data_src
        # excel.close_workbook(banners_1_src, False)
        # print "Success!"

        # # Get .csv core banner set 2
        apply_banner2(contract, xlapp)
        # banners_2_src = excel.open_workbook(xlapp, banners_2)
        # banners_2_data_src = excel.get_tab(banners_2_src, "%s Banners2" %
        #                                    contract['ProjectID'])
        # # Copy core banners to Banners2 tab
        # excel.paste_range(banners_2_data_src, "A:Y", banners_2_dst, "A:Y")
        # # Remove '-' from Wincross tab
        # excel.replace_zeros(banners_2_dst, "A:Y")
        # # Close core banner file
        # print ">> Applying Banner Set 2...",
        # del banners_2_data_src
        # excel.close_workbook(banners_2_src, False)
        # print "Success!"

        # # Get RBD
        apply_rbd(contract, xlapp)
        # if contract['SurveyType'] == 'MCS CCC':
        #     rbdbooksrc = excel.open_workbook(xlapp, rbda_path)
        #     rbdtabsrc = excel.get_tab(rbdbooksrc, "RoundsByDispoCAHPS2017")
        #     rbd2booksrc = excel.open_workbook(xlapp, rbd_path)
        #     rbd2tabsrc = excel.get_tab(rbd2booksrc, "RoundsByDispoCAHPS2017")
        #     excel.paste_range(rbd2tabsrc, "A:AA", rbd2_dst, "A:AA")
        #     del rbd2tabsrc
        #     excel.close_workbook(rbd2booksrc, False)
        # else:
        #     rbdbooksrc = excel.open_workbook(xlapp, rbd_path)
        #     rbdtabsrc = excel.get_tab(rbdbooksrc, "RoundsByDispoCAHPS2017")
        # # Copy RBD to RBD tab
        # excel.paste_range(rbdtabsrc, "A:AA", rbd_dst, "A:AA")
        # # Close RBD file
        # print ">> Applying RBD file...",
        # del rbdtabsrc
        # excel.close_workbook(rbdbooksrc, False)
        # print "Success!"

        # # Group sheets for PDF
        # create_xl_pdf(contract, xlrpt)
        # if contract['SurveyType'] == 'CAS':
        #     allsheets = const.ALL_CAS_SHEETS
        # elif contract['SurveyType'] == 'MAS':
        #     allsheets = const.ALL_MAS_SHEETS
        # elif contract['SurveyType'] == 'MCS':
        #     allsheets = const.ALL_MCS_SHEETS
        # elif contract['SurveyType'] == 'MCS CCC':
        #     allsheets = const.ALL_MCS_CCC_SHEETS
        # else:
        #     return 1
        # print ">> Grouping sheets for PDF report...",
        # group = excel.group_sheets(xlrpt, allsheets)

        # # Export Excel report to PDF
        # print ">> Exporting to PDF...",
        # excel.export_excel_pdf(group, excel_pdf)
        # print "Success!"

        # # Create a MergeData file
        create_merge(contract, xlapp)
        # mergecsv = excel.open_workbook(xlapp, mail_merge)
        # mergedatadst = excel.get_tab(mergecsv, 1)
        # mergedatasrc = excel.get_tab(xlrpt, "MergeData")
        # srcdata = mergedatasrc.Range("1:2")
        # srcdata.Copy()
        # mergedatadst.Range("1:2").PasteSpecial(
        #     Paste=-4122,
        #     Operation=-4142,
        #     SkipBlanks=False,
        #     Transpose=False)
        # mergedatadst.Range("1:2").PasteSpecial(
        #     Paste=-4163,
        #     Operation=-4142,
        #     SkipBlanks=False,
        #     Transpose=False)
        # print ">> Creating MergeData file...",
        # mergecsv.SaveAs(Filename=mail_merge)
        # excel.close_workbook(mergecsv)
        # print "Success!"

        # Cleanup and closing
        print ">> Beginning cleanup procedures...",
        mergedatasrc.Select(Replace=True)
        mergedatasrc.Range("A1").Select()
        excel.close_workbook(xlrpt)

        # Test for correct PDF
        global finrpt
        print "\n>> Opening files to create PDF...",
        finrpt = excel.open_workbook(xlapp, excel_report)
        print "Success!"

        create_xl_pdf(contract, finrpt)

        excel.close_workbook(finrpt)
        excel.quit_xl_app(xlapp)
        print "Success!"

    # End Excel report production
    return 0
Exemplo n.º 6
0
def copy_banners():
    '''
    Check the process status for copying the banners to the Reporting folder and 
    and update the labels.
    '''
    # Update Banner Check status
    ui.copy_banner.config(fg="#B68C14")
    ui.copy_banner_text.config(fg="#B68C14")
    time.sleep(0.1)
    ui.progress.step()
    ui.progress.update()

    status = 0

    orig_path = r"\\10.10.210.24\PM2018_Peak10\Analytics CAHPS\Banners\%s" % contract[
        'ProjectID']
    reporting_dir = r"\\10.10.210.24\PM2018_Peak10\Analytics CAHPS\Reporting\%s" % contract[
        'ProjectID']
    reporting_path = reporting_dir + '\\Banners\\'
    htm_path = orig_path + '\\Banners\\' + '%s' % contract[
        'ProjectID'] + ' Banners.htm'
    pdf_path = orig_path + '\\Banners\\' + '%s' % contract[
        'ProjectID'] + ' Banners.pdf'
    csv1_path = orig_path + '\\Banners\\' + '%s' % contract[
        'ProjectID'] + ' Banners1.csv'
    csv2_path = orig_path + '\\Banners\\' + '%s' % contract[
        'ProjectID'] + ' Banners2.csv'
    logo_path = r"\\10.10.210.24\PM2018_Peak10\Analytics CAHPS\Banners\%s\Banners\logo.png" % contract[
        'ProjectID']
    print htm_path
    print pdf_path
    print csv1_path
    print csv2_path
    print logo_path

    # Copy Banners to Reporting folder
    print ">> Creating Reporting folder copies...",
    try:
        ra.cp(htm_path, reporting_path)
        ra.cp(pdf_path, reporting_path)
        ra.cp(csv1_path, reporting_path)
        ra.cp(csv2_path, reporting_path)
        ra.cp(logo_path, reporting_path)
    except IOError:
        pass
        status = 1
    print "Success!"

    if status == 0:
        # Update Banner Check status
        ui.copy_banner.config(fg="#60E83B")
        ui.copy_banner_text.config(fg="#60E83B")
        time.sleep(0.1)
        ui.progress.step()
        ui.progress.update()
    else:
        # Update Copy Banner status
        ui.copy_banner.config(fg="#E8483B")
        ui.copy_banner_text.config(fg="#E8483B")
        ui.cbanner_passfail.set(ui.failpass)
        time.sleep(0.1)
        ui.progress.step()
        ui.progress.update()
Exemplo n.º 7
0
def check_copies():
    '''
    Check the process status for copying the data and 
    RBD files and update the labels.
    '''
    # Update Copy Check status
    ui.copy_check.config(fg="#B68C14")
    ui.copy_check_text.config(fg="#B68C14")
    time.sleep(0.1)
    ui.progress.step()
    ui.progress.update()

    status = 0

    # Copy text data and RBD to Data folder
    print ">> Creating Data folder copies...",
    try:
        ra.cp(
            r"\\10.10.210.24\PM2018_Peak10\Analytics CAHPS\Data Files\%s.txt" %
            contract['ProjectID'], textdata)
        ''' ra.cp(r"\\P10-FILESERV-01.sphanalytics.org\PM2017_Peak10\Analytics 2017\Analytics CAHPS\RBD\%sRBD.xls" % contract['ProjectID'],
            rbd_path) 
        if contract['SurveyType'] == 'MCS CCC':
            ra.cp(r"\\P10-FILESERV-01.sphanalytics.org\PM2017_Peak10\Analytics 2017\Analytics CAHPS\RBD\%sRBD_A.xls" %
                contract['ProjectID'], rbda_path)'''
    except IOError:
        pass
        status = 1
    print "Success!"

    # Copy text data and RBD to clones folder
    print ">> Cloning text data...",
    try:
        ra.cp(
            r"\\10.10.210.24\PM2018_Peak10\Analytics CAHPS\Data Files\%s.txt" %
            contract['ProjectID'], temp_path)
        '''ra.cp(r"\\P10-FILESERV-01.sphanalytics.org\PM2017_Peak10\Analytics 2017\Analytics CAHPS\RBD\%sRBD.xls" % contract['ProjectID'],
            temp_path)
        if contract['SurveyType'] == 'MCS CCC':
            ra.cp(r"\\P10-FILESERV-01.sphanalytics.org\PM2017_Peak10\Analytics 2017\Analytics CAHPS\RBD\%sRBD_A.xls" %
                contract['ProjectID'], temp_path)'''
    except IOError:
        pass
        status = 1
    print "Success!"

    if status == 0:
        # Update Copy Check status
        ui.copy_check.config(fg="#60E83B")
        ui.copy_check_text.config(fg="#60E83B")
        time.sleep(0.1)
        ui.progress.step()
        ui.progress.update()
    else:
        # Update Copy Check status
        ui.copy_check.config(fg="#E8483B")
        ui.copy_check_text.config(fg="#E8483B")
        ui.copy_passfail.set(ui.failpass)
        time.sleep(0.1)
        ui.progress.step()
        ui.progress.update()
Exemplo n.º 8
0
    def confirm_files(self):
        global files
        global entries
        files = []
        entries = []

        # FILE 01
        if len(self.id_field_1.get()) == 0:
            pass
        else:
            files.append(self.id_field_1.get())
        # FILE 02
        if len(self.id_field_2.get()) == 0:
            pass
        else:
            files.append(self.id_field_2.get())
        # FILE 03
        if len(self.id_field_3.get()) == 0:
            pass
        else:
            files.append(self.id_field_3.get())
        # FILE 04
        if len(self.id_field_4.get()) == 0:
            pass
        else:
            files.append(self.id_field_4.get())
        # FILE 05
        if len(self.id_field_5.get()) == 0:
            pass
        else:
            files.append(self.id_field_5.get())
        # FILE 06
        if len(self.id_field_6.get()) == 0:
            pass
        else:
            files.append(self.id_field_6.get())
        # FILE 07
        if len(self.id_field_7.get()) == 0:
            pass
        else:
            files.append(self.id_field_7.get())
        # FILE 08
        if len(self.id_field_8.get()) == 0:
            pass
        else:
            files.append(self.id_field_8.get())
        # FILE 09
        if len(self.id_field_9.get()) == 0:
            pass
        else:
            files.append(self.id_field_9.get())
        # FILE 10
        if len(self.id_field_10.get()) == 0:
            pass
        else:
            files.append(self.id_field_10.get())
        # FILE 11
        if len(self.id_field_11.get()) == 0:
            pass
        else:
            files.append(self.id_field_11.get())
        # FILE 12
        if len(self.id_field_12.get()) == 0:
            pass
        else:
            files.append(self.id_field_12.get())
        # FILE 13
        if len(self.id_field_13.get()) == 0:
            pass
        else:
            files.append(self.id_field_13.get())
        # FILE 14
        if len(self.id_field_14.get()) == 0:
            pass
        else:
            files.append(self.id_field_14.get())
        # FILE 15
        if len(self.id_field_15.get()) == 0:
            pass
        else:
            files.append(self.id_field_15.get())
        # FILE 16
        if len(self.id_field_16.get()) == 0:
            pass
        else:
            files.append(self.id_field_16.get())
        # FILE 17
        if len(self.id_field_17.get()) == 0:
            pass
        else:
            files.append(self.id_field_17.get())
        # FILE 18
        if len(self.id_field_18.get()) == 0:
            pass
        else:
            files.append(self.id_field_18.get())
        # FILE 19
        if len(self.id_field_19.get()) == 0:
            pass
        else:
            files.append(self.id_field_19.get())
        # FILE 20
        if len(self.id_field_20.get()) == 0:
            pass
        else:
            files.append(self.id_field_20.get())

        print "Text data files will be copied for the following projects:"
        for item in files:
            pull_data = datapath % item
            print ">> " + item
            try:
                assert os.path.isfile(
                    pull_data)  # Ensure the file actually exists
            except IOError, AssertionError:
                print "The file " + pull_data + "was not found."

            # Copy data files to Aggregate directory
            copydata = temppath + "\\" + aggregate_id + r"\Files\%s.txt" % item
            ra.cp(pull_data, copydata)
            print "Copied text data for Project ID #" + item + " to Aggregate directory"