Search in sources :

Example 1 with LiteracySkill

use of ai.elimu.model.enums.content.LiteracySkill in project webapp by elimu-ai.

the class ApplicationListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("contributor.getLocale(): " + contributor.getLocale());
    // List count of active Android applications for each EGRA/EGMA skill
    List<Application> activeApplications = applicationDao.readAllByStatus(contributor.getLocale(), ApplicationStatus.ACTIVE);
    logger.info("activeApplications.size(): " + activeApplications.size());
    Map<LiteracySkill, Integer> literacySkillCountMap = new LinkedHashMap<>();
    for (LiteracySkill literacySkill : LiteracySkill.values()) {
        literacySkillCountMap.put(literacySkill, 0);
    }
    for (Application application : activeApplications) {
        for (LiteracySkill literacySkill : application.getLiteracySkills()) {
            int count = literacySkillCountMap.get(literacySkill);
            literacySkillCountMap.put(literacySkill, count + 1);
        }
    }
    model.addAttribute("literacySkillCountMap", literacySkillCountMap);
    int maxLiteracySkillCount = 0;
    Collection<Integer> literacySkillCountCollection = literacySkillCountMap.values();
    for (int count : literacySkillCountCollection) {
        if (count > maxLiteracySkillCount) {
            maxLiteracySkillCount = count;
        }
    }
    model.addAttribute("maxLiteracySkillCount", maxLiteracySkillCount);
    Map<NumeracySkill, Integer> numeracySkillCountMap = new LinkedHashMap<>();
    for (NumeracySkill numeracySkill : NumeracySkill.values()) {
        numeracySkillCountMap.put(numeracySkill, 0);
    }
    for (Application application : activeApplications) {
        for (NumeracySkill numeracySkill : application.getNumeracySkills()) {
            int count = numeracySkillCountMap.get(numeracySkill);
            numeracySkillCountMap.put(numeracySkill, count + 1);
        }
    }
    model.addAttribute("numeracySkillCountMap", numeracySkillCountMap);
    int maxNumeracySkillCount = 0;
    Collection<Integer> numeracySkillCountCollection = numeracySkillCountMap.values();
    for (int count : numeracySkillCountCollection) {
        if (count > maxNumeracySkillCount) {
            maxNumeracySkillCount = count;
        }
    }
    model.addAttribute("maxNumeracySkillCount", maxNumeracySkillCount);
    List<Application> applications = applicationDao.readAll(contributor.getLocale());
    model.addAttribute("applications", applications);
    return "admin/application/list";
}
Also used : LiteracySkill(ai.elimu.model.enums.content.LiteracySkill) NumeracySkill(ai.elimu.model.enums.content.NumeracySkill) Contributor(ai.elimu.model.Contributor) Application(ai.elimu.model.admin.Application) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.Contributor)1 Application (ai.elimu.model.admin.Application)1 LiteracySkill (ai.elimu.model.enums.content.LiteracySkill)1 NumeracySkill (ai.elimu.model.enums.content.NumeracySkill)1 LinkedHashMap (java.util.LinkedHashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1