Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T#2948/progress percent export #3078

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export const useTranscriptPdfExport = () => {
pdfHelper.addTitle(doc, overallStats, 'Progress Snapshot', 165)
}

const addStat = (label, icon, x, num, totalNum = null) => {
const addStat = (label, icon, x, num, totalNum = null, endingText = null) => {
const currentY = doc.y
return doc.struct('Div', { title: `${label} stat` }, [
doc.struct('Span', { alt: `${label} stat icon` }, () => {
Expand All @@ -247,18 +247,23 @@ export const useTranscriptPdfExport = () => {
doc.struct('Span', () => {
doc.text(`${label}: `, x + 20, currentY, { continued: true })
.fillColor(pdfHelper.arrowColor5).fontSize(13)
.text(`${numFormat.pretty(num)} `, { continued: totalNum !== null })
.text(`${numFormat.pretty(num)} `, { continued: totalNum !== null || endingText !== null })
pdfHelper.resetTextStyle(doc)
if (totalNum !== null) {
doc.text(`/ ${numFormat.pretty(totalNum)} `, {})
doc.text(`/ ${numFormat.pretty(totalNum)} `, { continued: endingText !== null })
}
if (endingText !== null) {
doc.text(`${endingText}`, {})
}
})
])
}
overallStats.add(addStat(labelsConf.level, base64Images.trophy, 50, info.userLevel, info.totalLevels))
doc.moveUp()
overallStats.add(addStat(`${labelsConf.skill}s`, base64Images.arrowUp, 300, info.userSkillsCompleted, info.totalSkills))
overallStats.add(addStat(`${labelsConf.point}s`, base64Images.hat, 50, info.userPoints, info.totalPoints))
const skillsPercentage = ((info.userSkillsCompleted / info.totalSkills) * 100).toFixed(1)
const pointsPercentage = ((info.userPoints / info.totalPoints) * 100).toFixed(1)
overallStats.add(addStat(`${labelsConf.skill}s`, base64Images.arrowUp, 300, info.userSkillsCompleted, info.totalSkills, `(${skillsPercentage}%)`))
overallStats.add(addStat(`${labelsConf.point}s`, base64Images.hat, 50, info.userPoints, info.totalPoints, `(${pointsPercentage}%)`))
if (info.achievedBadges && info.achievedBadges.length > 0) {
doc.moveUp()
overallStats.add(addStat(`${labelsConf.badge}s`, base64Images.badge, 300, info.achievedBadges.length))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ describe('Transcript export tests', () => {
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 1 / 5 ')
expect(clean(doc.text)).to.include('Points: 100 / 600 ')
expect(clean(doc.text)).to.include('Skills: 0 / 3 ')
expect(clean(doc.text)).to.include('Points: 100 / 600 (16.7%)')
expect(clean(doc.text)).to.include('Skills: 0 / 3 (0.0%)')
expect(clean(doc.text)).to.not.include('Badges')

// should be a title on the 2nd page
Expand Down Expand Up @@ -155,8 +155,8 @@ describe('Transcript export tests', () => {
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 1 / 5 ')
expect(clean(doc.text)).to.include('Points: 600 / 2,600 ')
expect(clean(doc.text)).to.include('Skills: 6 / 26 ')
expect(clean(doc.text)).to.include('Points: 600 / 2,600 (23.1%)')
expect(clean(doc.text)).to.include('Skills: 6 / 26 (23.1%)')
expect(clean(doc.text)).to.not.include('Badges')

// should be a title on the 2nd-4th pages
Expand Down Expand Up @@ -204,8 +204,8 @@ describe('Transcript export tests', () => {
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 1 / 5 ')
expect(clean(doc.text)).to.include('Points: 600 / 2,600 ')
expect(clean(doc.text)).to.include('Skills: 6 / 26 ')
expect(clean(doc.text)).to.include('Points: 600 / 2,600 (23.1%)')
expect(clean(doc.text)).to.include('Skills: 6 / 26 (23.1%)')
expect(clean(doc.text)).to.include('Badges: 1 ')

// should be a title on the 2nd page
Expand Down Expand Up @@ -403,8 +403,8 @@ describe('Transcript export tests', () => {
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 600 / 21,000 ')
expect(clean(doc.text)).to.include('Skills: 6 / 210 ')
expect(clean(doc.text)).to.include('Points: 600 / 21,000 (2.9%)')
expect(clean(doc.text)).to.include('Skills: 6 / 210 (2.9%)')
expect(clean(doc.text)).to.not.include('Badges ')

// should be a title on the 2nd-4th pages
Expand Down Expand Up @@ -607,8 +607,8 @@ describe('Transcript export tests', () => {
expect(clean(doc.text)).to.include(user1)
expect(clean(doc.text)).to.not.include(user2)
expect(clean(doc.text)).to.include('Level: 1 / 5 ')
expect(clean(doc.text)).to.include('Points: 400 / 2,600 ')
expect(clean(doc.text)).to.include('Skills: 4 / 26 ')
expect(clean(doc.text)).to.include('Points: 400 / 2,600 (15.4%)')
expect(clean(doc.text)).to.include('Skills: 4 / 26 (15.4%)')
expect(clean(doc.text)).to.not.include('Badges')
})

Expand All @@ -624,8 +624,8 @@ describe('Transcript export tests', () => {
expect(clean(doc.text)).to.include(user2)
expect(clean(doc.text)).to.not.include(user1)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 200 / 2,600 ')
expect(clean(doc.text)).to.include('Skills: 2 / 26 ')
expect(clean(doc.text)).to.include('Points: 200 / 2,600 (7.7%)')
expect(clean(doc.text)).to.include('Skills: 2 / 26 (7.7%)')
expect(clean(doc.text)).to.not.include('Badges')
})

Expand Down Expand Up @@ -691,7 +691,7 @@ describe('Transcript export tests', () => {
cy.get('[data-cy="downloadTranscriptBtn"]').click()

cy.readTranscript(projName).then((doc) => {
expect(clean(doc.text)).to.include('Skills: 2 / 4 ')
expect(clean(doc.text)).to.include('Skills: 2 / 4 (50.0%)')
expect(clean(doc.text)).to.include('Achieved On')
expect(clean(doc.text)).to.not.include('Approver')
expect(clean(doc.text)).to.include(today)
Expand Down Expand Up @@ -722,7 +722,7 @@ describe('Transcript export tests', () => {
cy.get('[data-cy="downloadTranscriptBtn"]').click()

cy.readTranscript(projName).then((doc) => {
expect(clean(doc.text)).to.include('Skills: 2 / 4 ')
expect(clean(doc.text)).to.include('Skills: 2 / 4 (50.0%)')
expect(clean(doc.text)).to.include('Achieved On')
expect(clean(doc.text)).to.include('Approver')
expect(clean(doc.text)).to.include(today)
Expand Down Expand Up @@ -752,7 +752,7 @@ describe('Transcript export tests', () => {
cy.get('[data-cy="downloadTranscriptBtn"]').click()

cy.readTranscript(projName).then((doc) => {
expect(clean(doc.text)).to.include('Skills: 0 / 4 ')
expect(clean(doc.text)).to.include('Skills: 0 / 4 (0.0%)')
expect(clean(doc.text)).to.include('Achieved On')
expect(clean(doc.text)).to.not.include('Approver')
})
Expand Down
17 changes: 15 additions & 2 deletions service/src/main/java/skills/services/ExcelExportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import skills.services.admin.skillReuse.SkillReuseIdUtil
import skills.services.attributes.ExpirationAttrs
import skills.storage.model.SkillDef
import skills.storage.model.SkillRelDef
import skills.storage.repos.ProjDefRepo
import skills.storage.repos.UserAchievedLevelRepo
import skills.utils.InputSanitizer

Expand Down Expand Up @@ -67,23 +68,31 @@ class ExcelExportService {
@Autowired
SkillsAdminService skillsAdminService

@Autowired
ProjDefRepo projDefRepo

@Transactional(readOnly = true)
void exportUsersProgress(Workbook workbook, String projectId, String query, PageRequest pageRequest, int minimumPoints) {
String projectExportHeaderAndFooter = userCommunityService.replaceProjectDescriptorVar(exportHeaderAndFooter, userCommunityService.getProjectUserCommunity(projectId))
Sheet sheet = workbook.createSheet()
List<String> headers
if (userTagLabel) {
headers = ["User ID", "Last Name", "First Name", userTagLabel, "Level", "Current Points", "Points First Earned (UTC)", "Points Last Earned (UTC)"]
headers = ["User ID", "Last Name", "First Name", userTagLabel, "Level", "Current Points", "Percent Complete", "Points First Earned (UTC)", "Points Last Earned (UTC)"]
} else {
headers = ["User ID", "Last Name", "First Name", "Level", "Current Points", "Points First Earned (UTC)", "Points Last Earned (UTC)"]
headers = ["User ID", "Last Name", "First Name", "Level", "Current Points", "Percent Complete", "Points First Earned (UTC)", "Points Last Earned (UTC)"]
}
Integer columnNumber = 0
Integer rowNum = initializeSheet(sheet, headers, projectExportHeaderAndFooter)

CellStyle dateStyle = workbook.createCellStyle()
dateStyle.setDataFormat((short) 22) // NOTE: 14 = "mm/dd/yyyy"

CellStyle percentStyle = workbook.createCellStyle()
percentStyle.setDataFormat((short) 9)

Cell cell = null

Integer projectPoints = projDefRepo.getTotalPointsByProjectId(projectId) ?: 0
Stream<ProjectUser> projectUsers = adminUsersService.streamAllDistinctUsersForProject(projectId, query, pageRequest, minimumPoints)
try {
projectUsers.each { ProjectUser user ->
Expand All @@ -97,6 +106,10 @@ class ExcelExportService {
}
row.createCell(columnNumber++).setCellValue(user.userMaxLevel)
row.createCell(columnNumber++).setCellValue(user.totalPoints)
Double percentage = (user.totalPoints / projectPoints)
cell = row.createCell(columnNumber++)
cell.setCellStyle(percentStyle)
cell.setCellValue(percentage)

cell = row.createCell(columnNumber++)
cell.setCellStyle(dateStyle)
Expand Down
Loading
Loading