Skip to content

Commit

Permalink
#2948 Initial changes to exports
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalizer committed Jan 8, 2025
1 parent 1490063 commit a03e906
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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
12 changes: 10 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,15 +68,18 @@ 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)
Expand All @@ -84,6 +88,8 @@ class ExcelExportService {
dateStyle.setDataFormat((short) 22) // NOTE: 14 = "mm/dd/yyyy"

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 +103,8 @@ class ExcelExportService {
}
row.createCell(columnNumber++).setCellValue(user.userMaxLevel)
row.createCell(columnNumber++).setCellValue(user.totalPoints)
Double percentage = (user.totalPoints / projectPoints) * 100
row.createCell(columnNumber++).setCellValue(percentage)

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

0 comments on commit a03e906

Please sign in to comment.