コード例 #1
0
def readParam():
    SYSTEM.clear()
    LOGGER.show('info', (
        '#===============================================================================================#'
    ))
    LOGGER.show('info', ('#\tStarting Reporting Process\t\t\t\t\t\t\t\t#'))
    LOGGER.show('info', (
        '#\t\tFor Processing System needs two files in data folder \t\t\t\t#'))
    LOGGER.show(
        'info',
        ('#\t\t1. catelogId.xml\t\t [Eg. ./data/APL977-a80en.xml] \t\t\t#'))
    LOGGER.show('info', (
        '#\t\t2. catelogId-progress.xlsx\t [Eg. ./data/APL977-a80en-progress.xlsx] \t#'
    ))
    LOGGER.show('info', (
        '#===============================================================================================#'
    ))
    LOGGER.show('info', (''))
    catalogId = 'APL977-a80en'
    summaryMode = 'a'

    catalogId = SYSTEM.acceptValidInput('Enter Valid CatlogueId : ', [])
    summaryMode = SYSTEM.acceptValidInput(
        'Report Mode : Detailed / Compact / Summary / Anayltics[D/C/S/A] : ',
        ['D', 'C', 'S', 'A', 'd', 'c', 's', 'a'])

    LOGGER.show('info', (''))
    catalogId = catalogId.strip()
    courseXml = pkgImporter.getFileWithPath('data/' + catalogId + '.xml')
    courseData = pkgImporter.getFileWithPath('data/' + catalogId + '.json')
    courseProgress = pkgImporter.getFileWithPath('data/' + catalogId +
                                                 '-progress.xlsx')

    isExist1 = SYSTEM.fileExist(courseXml)
    if isExist1 == False:
        LOGGER.show('error', ('File %s does not exists' % (courseXml)))

    isExist2 = SYSTEM.fileExist(courseProgress)
    if isExist2 == False:
        LOGGER.show('error', ('File %s does not exists' % (courseProgress)))

    if isExist1 == True and isExist2 == True:
        CONVERTOR.convert(courseXml, courseData)
    else:
        catalogId = None

    return {
        'catalogId': catalogId,
        'courseData': courseData,
        'courseProgress': courseProgress,
        'summaryMode': summaryMode
    }
コード例 #2
0
def generateReport(catalog):
    printLine = ''
    assessedLesson = 0
    jsonCourseData = FILE_IO.readData(catalog['courseData'])['course']
    jsonProgressData = EXCEL.readData(catalog['courseProgress'])
    courseData = getCourseData(jsonCourseData)
    passingPercent = jsonCourseData["assessment"]['@passingPercentage']

    for user in jsonProgressData['data']:
        reportHeader = []
        reportBody = []
        reportCompact = []
        reportFooter = []
        score = 0
        aCtr = 0
        lCtr = 0
        tQctr = 0
        mCtr = 0
        plData = parseUserResult(user['CORE_LESSON'])
        lessonStatus = plData['lessonStatus']
        hasTestOut = str(jsonCourseData['assessment']['@lessonType'] ==
                         'personalizedLearning')
        reportHeader.append(
            '<h4>User Name : %s %s [%s]</h4>' %
            (user['FIRSTNAME'], user['LASTNAME'], user['USER_ID']))

        # =========

        testoutTaken = True if len(plData['testoutData']) > 0 else False

        if testoutTaken == True:
            reportBody.append('<table>')
            reportCompact.append('<table>')
            for lesson in courseData:
                reportBody.append(
                    '<tr class="lessonNode"> <td>Lesson Id</td> <td> %s </td>  <td>Lesson Title</td> <td> %s </td>  </tr>'
                    % (lesson['lessonId'], lesson['title']))
                lCtr += 1
                if lesson['assessment'] == None:
                    reportBody.append(
                        '<tr> <td colspan="2">Assessment</td> <td colspan="2"> Not Available - Mandatory Lesson  </td>  </tr>'
                    )
                else:
                    correctCtr = 0
                    questions = lesson['assessment']['question']
                    assessmentData = normalizeData(plData['testoutData'][aCtr],
                                                   len(questions))
                    poolSize = int(lesson['assessment']['@poolSize'])
                    reportBody.append(
                        '<tr> <td>Questions Available</td> <td> [%d] </td> <td> Pooled </td> <td> [%s]  </td>  </tr>'
                        % (len(questions), poolSize))
                    reportCompact.append(
                        '<tr class="lessonNode"> <td>Lesson Id</td> <td> %s </td>  <td>Lesson Title</td> <td> %s </td>  </tr>'
                        % (lesson['lessonId'], lesson['title']))
                    reportCompact.append(
                        '<tr> <td>Questions Available : [%d] </td> <td> Pooled : [%d] </td>'
                        % (len(questions), poolSize))

                    qCtr = 0
                    assessedLesson += 1
                    for question in questions:
                        pooledClass = 'pooled' if len(
                            assessmentData[qCtr]
                            ['optionIdx']) > 0 else 'not-pooled'
                        reportBody.append(
                            '<tr class="%s"><td colspan="2">%d %s </td> <td colspan="2">'
                            % (pooledClass,
                               (qCtr + 1), question['questionText']['p']))

                        cCtr = 0
                        tQctr += 1
                        correctChoice = []
                        for choice in question['choice']:
                            isCorrect = choice['@isCorrect'] == 'true'
                            if isCorrect:
                                correctChoice.append(str(choice['@choiceId']))

                            reportBody.append(
                                '<div class="row"> <span class="col1">%s</span> <span class="col2"> %s </span></div>'
                                % (choice['@choiceId'], choice['#text']))
                            cCtr += 1

                        result = getResult(correctChoice,
                                           assessmentData[qCtr]['optionIdx'])

                        if result == 'Passed':
                            score += 1
                            mCtr += 1
                            correctCtr += 1

                        elif result == 'NotPassed':
                            mCtr += 1

                        sOption = []
                        for s in assessmentData[qCtr]['optionIdx']:
                            sOption.append(str(s))

                        userDetail = {
                            'userId': user['USER_ID'],
                            'userName':
                            user['FIRSTNAME'] + ' ' + user['LASTNAME'],
                            'result': result
                        }
                        if question.has_key('userDetail') == False:
                            question['userDetail'] = []

                        question['userDetail'].append(userDetail)

                        reportBody.append(
                            '<br>Correct : %s Selected : %s Result : %s </td></tr>'
                            % (str(correctChoice), str(sOption), result))
                        qCtr += 1

                    aCtr += 1
                    reportCompact.append(
                        '<td>Correct : [%s]</td> <td>Incorrect : [%s]  </td></tr>'
                        % (correctCtr, (poolSize - correctCtr)))
            reportBody.append('</table>')
            reportCompact.append('</table>')

        reportFooter.append(
            '<br><br><table class="summary"><thead><th colspan="2">Summary</th></thead>'
        )

        if testoutTaken == True:
            percObtained = score * 100 / mCtr

            status = 'NOT PASSED'
            if percObtained >= int(passingPercent):
                status = 'PASSED   '

            reportFooter.append(
                '<tr> <td>Total Lesson in the course</td> <td> %d </td> </tr>'
                % (lCtr))
            reportFooter.append(
                '<tr> <td class="align-right">Testout Lesson</td> <td> %d </td> </tr>'
                % (aCtr))
            reportFooter.append(
                '<tr> <td class="align-right">Mandatory Lesson</td> <td> %d </td> </tr>'
                % (lCtr - aCtr))
            reportFooter.append(
                '<tr> <td>Total Question in the course</td> <td>%d </td> </tr>'
                % (tQctr))
            reportFooter.append(
                '<tr> <td class="align-right">Questions Offered</td> <td> %d </td> </tr>'
                % (mCtr))
            reportFooter.append(
                '<tr> <td class="align-right">Correct Answered</td> <td> %d </td> </tr>'
                % (score))
            reportFooter.append(
                '<tr> <td class="align-right">Incorrect Answered</td> <td> %d </td> </tr>'
                % (mCtr - score))
            reportFooter.append(
                '<tr> <td>Last Question Attempted</td> <td> %s </td> </tr>' %
                (plData['lastQuestion']))
            reportFooter.append(
                '<tr> <td>Passing Percent</td> <td> %s </td> </tr>' %
                (passingPercent))
            reportFooter.append(
                '<tr> <td>Obtained Percent</td> <td> %d </td> </tr>' %
                (percObtained))
            reportFooter.append(
                '<tr> <td>Result Status</td> <td> %s </td> </tr>' % (status))

        tstStatus = 'DONE' if plData['plStatus'].upper(
        ) == 'RESULT' else plData['plStatus'].upper()

        reportFooter.append(
            '<tr> <td>Testout Status</td> <td> %s </td> </tr>' % (tstStatus))
        reportFooter.append('<tr> <td>Lesson Status</td> <td> %s </td> </tr>' %
                            (lessonStatus))
        reportFooter.append('</table><hr>')

        # ======
        if catalog['summaryMode'] == 'c':
            reportBody = reportCompact

        repo = userData(reportHeader, reportBody, reportFooter, courseData,
                        catalog['summaryMode'])
        printLine += repo.getReport()

    reportFile = catalog['catalogId'] + '-detail'
    if catalog['summaryMode'] == 'c':
        reportFile = catalog['catalogId'] + '-compact'
    elif catalog['summaryMode'] == 's':
        reportFile = catalog['catalogId'] + '-summary'
    elif catalog['summaryMode'] == 'a':
        reportFile = catalog['catalogId'] + '-analytics'

    reportFile = pkgImporter.getFileWithPath('data/' + reportFile + '-report')

    htmlText = '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title> <style>body {font-family: Verdana, Geneva, Tahoma, sans-serif;}table {width: 100%; height: 100%;border-spacing: 0.5rem;border-collapse: collapse;}thead {background: blue;}tfoot {background: yellow;} td,th {border: 1px solid #999;padding: 0.5rem;vertical-align: top;width: 25%;} .userNode {background:red;} .lessonNode {background:orange;} .summary{ width:50%; text-align: center; margin:auto;} .align-right{text-align:right;} .not-pooled{background: gray;opacity: 0.5;} .row{display: inline-table; width:100%;} .row .col1{width:10%;display: -webkit-inline-box;} .row .col2{width:90%;display: -webkit-inline-box;} .col1, .col2, .col3 {width:33%;}</style></head>\n'
    htmlText += '<body>\n'
    htmlText += ('<h2>%s</h2>' % jsonCourseData['title'])
    htmlText += (
        '<p>Course Name : %s  <br>System Id : %s </br> Assessment Mode : %s  <br>Pooling : %s  <br>Randomized on : %s</p>'
        % (jsonCourseData['@catalogId'], jsonCourseData['@systemId'],
           hasTestOut, jsonCourseData["assessment"]['@pooling'],
           jsonCourseData["assessment"]['@randomize']))

    if catalog['summaryMode'] != 'a':
        htmlText += printLine

    if catalog['summaryMode'] == 'a' or catalog['summaryMode'] == 'd':
        htmlText += repo.getAnalytics()

    htmlText += ('<p class="align-right">Generated on %s</p>' %
                 (datetime.datetime.now().strftime("%Y-%m-%d %H:%M")))
    htmlText += '\n</body>'

    FILE_IO.writeFile(reportFile + '.html', htmlText)

    LOGGER.show('info', ('Report created  %s.html ' % (reportFile)))
    SYSTEM.remove(catalog['courseData'])
コード例 #3
0
ファイル: reporter.py プロジェクト: ashanchan/project
def generateReport(catalog):
    lBreaker = (
        '======================================================================'
    )
    qBreaker = ('-------------------------------------')
    printLine = ''
    assessedLesson = 0

    jsonCourseData = FILE_IO.readData(catalog['courseData'])['course']
    jsonProgressData = EXCEL.readData(catalog['courseProgress'])
    courseData = getCourseData(jsonCourseData)
    passingPercent = jsonCourseData["assessment"]['@passingPercentage']

    for user in jsonProgressData['data']:
        reportHeader = []
        reportBody = []
        reportCompact = []
        reportFooter = []
        score = 0
        aCtr = 0
        lCtr = 0
        tQctr = 0
        mCtr = 0
        plData = parseUserResult(user['CORE_LESSON'])
        lessonStatus = plData['lessonStatus']

        reportHeader.append(lBreaker)
        reportHeader.append(
            'User Id\t\t\t : %s \t Name : %s %s' %
            (user['USER_ID'], user['FIRSTNAME'], user['LASTNAME']))
        reportHeader.append('Course Name \t : %s ' %
                            (jsonCourseData['@catalogId']))
        reportHeader.append('System Id \t\t : %s ' %
                            (jsonCourseData['@systemId']))
        reportHeader.append('Has Assessment \t : %s ' %
                            (str(jsonCourseData['assessment']['@lessonType'] ==
                                 'personalizedLearning')))
        reportHeader.append('Pooling \t\t : %s ' %
                            (jsonCourseData["assessment"]['@pooling']))
        reportHeader.append('Randomized on \t : %s ' %
                            (jsonCourseData["assessment"]['@randomize']))
        reportHeader.append(lBreaker)
        # =========
        testoutTaken = True if len(plData['testoutData']) > 0 else False

        if testoutTaken == True:
            for lesson in courseData:
                reportBody.append('Lesson Id\t\t : %s ' % (lesson['lessonId']))
                reportBody.append('Lesson title\t : %s ' % (lesson['title']))
                lCtr += 1
                if lesson['assessment'] == None:
                    reportBody.append(
                        'Assessment\t\t : Not Available - Mandatory Lesson ')
                else:
                    correctCtr = 0
                    questions = lesson['assessment']['question']
                    assessmentData = normalizeData(plData['testoutData'][aCtr],
                                                   len(questions))
                    poolSize = int(lesson['assessment']['@poolSize'])
                    reportBody.append(
                        'Assessment\t\t : Questions Available : [%d] \t Pooled : [%s] '
                        % (len(questions), poolSize))

                    reportCompact.append('Lesson title\t : %s ' %
                                         (lesson['title']))
                    reportCompact.append(
                        '\tQuestions\t : Available\t : [%d] \t Pooled\t\t : [%s] '
                        % (len(questions), poolSize))

                    qCtr = 0
                    assessedLesson += 1
                    for question in questions:
                        reportBody.append(qBreaker)
                        reportBody.append(
                            '\t %d %s ' %
                            ((qCtr + 1), question['questionText']['p']))

                        cCtr = 0
                        tQctr += 1
                        correctChoice = []
                        for choice in question['choice']:
                            isCorrect = choice['@isCorrect'] == 'true'
                            if isCorrect:
                                correctChoice.append(str(choice['@choiceId']))

                            reportBody.append(
                                '\t\t %s\t%s ' %
                                (choice['@choiceId'], choice['#text']))

                            cCtr += 1

                        result = getResult(correctChoice,
                                           assessmentData[qCtr]['optionIdx'])

                        if result == 'Correct':
                            score += 1
                            mCtr += 1
                            correctCtr += 1
                        elif result == 'Incorrect':
                            mCtr += 1

                        sOption = []
                        for s in assessmentData[qCtr]['optionIdx']:
                            sOption.append(str(s))

                        reportBody.append(
                            '\t\t\tcorrect : %s \t selected : %s \t result : [%s]   '
                            % (str(correctChoice), str(sOption), result))
                        qCtr += 1

                    aCtr += 1
                    reportCompact.append(
                        '\t\t\t\t : Correct\t\t : [%s] \t Incorrect\t : [%s]' %
                        (correctCtr, (poolSize - correctCtr)))
                    reportCompact.append('')

                reportBody.append(lBreaker)
        reportCompact.append(lBreaker)
        reportFooter.append('')
        reportFooter.append(
            '\t\t*********************************************************')
        reportFooter.append('\t\t\t                    SUMMARY ')
        reportFooter.append(
            '\t\t*********************************************************')

        if testoutTaken == True:
            percObtained = score * 100 / mCtr

            status = 'NOT PASSED'
            if percObtained >= int(passingPercent):
                status = 'PASSED   '

            reportFooter.append(
                '\t\t*\tTotal Lesson in the course\t\t : [%d] \t\t\t\t*' %
                (lCtr))
            reportFooter.append(
                '\t\t*\t\tTestout Lesson   \t\t\t : [%d] \t\t\t\t*' % (aCtr))
            reportFooter.append(
                '\t\t*\t\tMandatory Lesson \t\t\t : [%d] \t\t\t\t*' %
                (lCtr - aCtr))
            reportFooter.append(
                '\t\t*\tTotal Question in the course\t : [%d] \t\t\t*' %
                (tQctr))
            reportFooter.append(
                '\t\t*\t\t\t\tQuestions Offered\t : [%d] \t\t\t*' % (mCtr))
            reportFooter.append(
                '\t\t*\t\t\t\tCorrect Answered\t : [%d]  \t\t\t*' % (score))
            reportFooter.append(
                '\t\t*\t\t\t\tIncorrect Answered\t : [%d]  \t\t\t*' %
                (mCtr - score))
            reportFooter.append(
                '\t\t*\tPassing Percent\t\t\t\t\t : [%s] \t\t\t*' %
                (passingPercent))
            reportFooter.append(
                '\t\t*\tObtained Percent\t\t\t\t : [%d]  \t\t\t*' %
                (percObtained))
            reportFooter.append('\t\t*\tResult Status\t\t\t\t\t : [%s]\t\t*' %
                                (status))
            reportFooter.append(
                '\t\t*\tLast Question Attempted\t\t\t : [%s]\t\t\t\t*' %
                (plData['lastQuestion']))

        tstStatus = 'DONE' if plData['plStatus'].upper(
        ) == 'RESULT' else plData['plStatus'].upper()

        reportFooter.append('\t\t*\tTestout Status\t\t\t\t\t : [%s]    \t\t*' %
                            (tstStatus))
        reportFooter.append('\t\t*\tLesson Status\t\t\t\t\t : [%s] \t\t*' %
                            (lessonStatus))
        reportFooter.append(
            '\t\t*********************************************************')
        reportFooter.append('')

        # ======
        if catalog['summaryMode'] == 'c':
            reportBody = reportCompact

        repo = userData(reportHeader, reportBody, reportFooter,
                        catalog['summaryMode'])
        printLine += repo.getReport()

    reportFile = catalog['catalogId']
    reportFile = pkgImporter.getFileWithPath('data/' + reportFile +
                                             '-report.txt')

    FILE_IO.writeFile(reportFile, printLine)
    LOGGER.show('info', ('Report created  %s ' % (reportFile)))
    SYSTEM.remove(catalog['courseData'])