Forráskód Böngészése

ADD: statistics for Fall contest

zhangxin 8 éve
szülő
commit
acb7069d95

+ 38 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/dao/ContestDao.java

@@ -54,4 +54,42 @@ public interface ContestDao extends CrudRepository<Contest, Long> {
     @Query(value = "SELECT uni_loc FROM university WHERE uni_name = :university", nativeQuery = true)
     String findAreaByUniversity(@Param("university") String university);
 
+    @Query("SELECT u.school, COUNT(distinct u.id) FROM User u, Group2Worker g2w " +
+            "WHERE u.id = g2w.participantId " +
+            "AND g2w.groupId in(309, 310, 311, 312, 313, 314) " +
+            "GROUP BY u.school ORDER BY COUNT(distinct u.id) DESC")
+    List<Object[]> CountAllBySchoolOfFall();
+
+
+
+    @Query("SELECT u.school, COUNT(distinct u.id) FROM User u, Group2Worker g2w " +
+            "WHERE u.id = g2w.participantId " +
+            "AND g2w.groupId = :groupId " +
+            "GROUP BY u.school ORDER BY COUNT(distinct u.id) DESC")
+    List<Object[]> CountBySchoolOfFall(@Param("groupId") Long groupId);
+
+    @Query("SELECT un.location, COUNT(distinct u.id) FROM User u, AssignedTask at, University un " +
+            "WHERE at.taskId in(953,931,930,915,872) " +
+            "AND u.id = at.participantId " +
+            "AND at.score != 0 " +
+            "AND u.school LIKE un.name " +
+            "GROUP BY un.location " +
+            "ORDER BY COUNT(distinct u.id) DESC")
+    List<Object[]> CountByActiveofFall();
+
+    @Query("SELECT un.location, COUNT(distinct u.id) FROM University un, User u, Group2Worker g2w " +
+            "WHERE u.id = g2w.participantId " +
+            "AND g2w.groupId in(309, 310, 311, 312, 313, 314) " +
+            "AND u.school LIKE un.name " +
+            "GROUP BY un.location " +
+            "ORDER BY COUNT(distinct u.id) DESC")
+    List<Object[]> CountAllByLocationOfFall();
+
+    @Query("SELECT un.location, COUNT(distinct u.id) FROM University un, User u, Group2Worker g2w " +
+            "WHERE u.id = g2w.participantId " +
+            "AND g2w.groupId = :groupId " +
+            "AND u.school LIKE un.name " +
+            "GROUP BY un.location " +
+            "ORDER BY COUNT(distinct u.id) DESC")
+    List<Object[]> CountByLocationOfFall(@Param("groupId") Long groupId);
 }

+ 1 - 1
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/models/Univeristy.java → mooctest-site-server/src/main/java/cn/iselab/mooctest/site/models/University.java

@@ -11,7 +11,7 @@ import javax.persistence.Table;
 
 @Entity
 @Table(name = "university")
-public class Univeristy {
+public class University {
 
     @Id
     private Long id;

+ 2 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/ContestService.java

@@ -27,4 +27,6 @@ public interface ContestService {
     List<ContestMentor> addContestMentor(Long examId, Long userId, List<ContestMentorVO> contestMentorVOS, Byte role);
 
     List<ContestMentor> getContestMnetor(Long contestId, Long userId, Byte role);
+
+    ContestStatistics getContestStatisticsOfFall(Long groupId);
 }

+ 93 - 9
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/impl/ContestServiceImpl.java

@@ -7,8 +7,8 @@ import cn.iselab.mooctest.site.dao.WorkerDao;
 import cn.iselab.mooctest.site.data.ContestStatistics;
 import cn.iselab.mooctest.site.models.Contest;
 import cn.iselab.mooctest.site.models.ContestMentor;
-import cn.iselab.mooctest.site.models.Worker;
 import cn.iselab.mooctest.site.models.SignRecord;
+import cn.iselab.mooctest.site.models.Worker;
 import cn.iselab.mooctest.site.service.ContestService;
 import cn.iselab.mooctest.site.web.data.ContestMentorVO;
 import org.apache.commons.collections.IteratorUtils;
@@ -55,6 +55,90 @@ public class ContestServiceImpl implements ContestService {
         return contestDao.findByWorkerId(workerId);
     }
 
+    /*
+    * 2017秋季赛统计数据
+    * */
+    @Override
+    @Cacheable(value = "getContestStatisticsOfFall")
+    public ContestStatistics getContestStatisticsOfFall(Long groupId) {
+        ContestStatistics contestStatistics = new ContestStatistics();
+
+        List<Object[]> locationResult;
+        Map<String, Long> locationMap;
+        List<Object[]> schoolResult;
+        Map<String, Long> schoolMap;
+
+        if (groupId == 0) {
+            locationResult = contestDao.CountAllByLocationOfFall();
+            locationMap = new HashMap<>();
+            for (Object[] result : locationResult) {
+                if (StringUtils.isEmpty((String) result[0])) {
+                    long count = locationMap.getOrDefault("未知", 0L);
+                    locationMap.put("未知", count + (Long) result[1]);
+                } else {
+                    locationMap.put((String) result[0], (Long) result[1]);
+                }
+            }
+
+            schoolResult = contestDao.CountAllBySchoolOfFall();
+            schoolMap = new HashMap<>();
+            for (Object[] result : schoolResult) {
+                if (StringUtils.isEmpty((String) result[0])) {
+                    long count = schoolMap.getOrDefault("未知", 0L);
+                    schoolMap.put("未知", count + (Long) result[1]);
+                } else {
+                    schoolMap.put((String) result[0], (Long) result[1]);
+                }
+            }
+            contestStatistics.setSchoolData(schoolMap);
+            contestStatistics.setLocationData(locationMap);
+        } else {
+            locationResult = contestDao.CountByLocationOfFall(groupId);
+            locationMap = new HashMap<>();
+            for (Object[] result : locationResult) {
+                if (StringUtils.isEmpty((String) result[0])) {
+                    long count = locationMap.getOrDefault("未知", 0L);
+                    locationMap.put("未知", count + (Long) result[1]);
+                } else {
+                    locationMap.put((String) result[0], (Long) result[1]);
+                }
+            }
+
+            schoolResult = contestDao.CountBySchoolOfFall(groupId);
+            schoolMap = new HashMap<>(schoolResult.size());
+            for (Object[] result : schoolResult) {
+                if (StringUtils.isEmpty((String) result[0])) {
+                    long count = schoolMap.getOrDefault("未知", 0L);
+                    schoolMap.put("未知", count + (Long) result[1]);
+                } else {
+                    schoolMap.put((String) result[0], (Long) result[1]);
+                }
+            }
+            contestStatistics.setSchoolData(schoolMap);
+            contestStatistics.setLocationData(locationMap);
+        }
+
+        List<Object[]> activeResult = contestDao.CountByActiveofFall();
+        Map<String, Long> activeMap = new HashMap<>();
+
+        for (Object[] result : activeResult) {
+            if (StringUtils.isEmpty((String) result[0])) {
+                long count = activeMap.getOrDefault("未知", 0L);
+                activeMap.put("未知", count + (Long) result[1]);
+                continue;
+            } else {
+                activeMap.put((String) result[0], (Long) result[1]);
+            }
+        }
+
+        contestStatistics.setActiveData(activeMap);
+
+        return contestStatistics;
+    }
+
+    /*
+    * 2017夏季赛统计数据
+    * */
     @Override
     @Cacheable(value = "getContestStatistics")
     public ContestStatistics getContestStatistics(Long contestId) {
@@ -143,20 +227,20 @@ public class ContestServiceImpl implements ContestService {
         System.out.println("sign record size: " + signRecords.size());
 
         int count = 0;
-        for (int i = 0; i < workers.size(); i ++) {
+        for (int i = 0; i < workers.size(); i++) {
             Worker worker = workers.get(i);
             if (worker.getInformation() != null) {
                 continue;
             }
             String mobile = worker.getMobile();
             String email = worker.getEmail();
-            for (int j = 0; j < signRecords.size(); j ++) {
+            for (int j = 0; j < signRecords.size(); j++) {
                 SignRecord record = signRecords.get(j);
                 if (email == null) {
                     if (mobile != null) {
                         if (mobile.equals(record.getStuTel())) {
                             worker.setInformation(record.getStuSchool());
-                            count ++;
+                            count++;
                             break;
                         }
                     }
@@ -164,14 +248,14 @@ public class ContestServiceImpl implements ContestService {
                     if (email != null) {
                         if (email.equals(record.getStuEmail())) {
                             worker.setInformation(record.getStuSchool());
-                            count ++;
+                            count++;
                             break;
                         }
                     }
                 } else if (email != null && mobile != null) {
                     if (email.equals(record.getStuEmail()) || mobile.equals(record.getStuTel())) {
                         worker.setInformation(record.getStuSchool());
-                        count ++;
+                        count++;
                         break;
                     }
                 }
@@ -186,7 +270,7 @@ public class ContestServiceImpl implements ContestService {
         List<Worker> workers = workerDao.getContestWorkerList();
         System.out.println(workers.size());
 
-        for (int i = 0; i < workers.size(); i ++) {
+        for (int i = 0; i < workers.size(); i++) {
             Worker worker = workers.get(i);
             if (worker.getLocation() == null && worker.getInformation() != null) {
                 String area = contestDao.findAreaByUniversity(worker.getInformation());
@@ -202,7 +286,7 @@ public class ContestServiceImpl implements ContestService {
 
     @Override
     public List<ContestMentor> addContestMentor(Long examId, Long userId, List<ContestMentorVO> contestMentorVOS, Byte role) {
-        contestMentorDao.delete(contestMentorDao.findByExamIdAndParticipantIdAndRole(examId,userId,role));
+        contestMentorDao.delete(contestMentorDao.findByExamIdAndParticipantIdAndRole(examId, userId, role));
         List<ContestMentor> contestMentors = new ArrayList<>();
         contestMentorVOS.stream().forEach(enterContestVO -> {
             ContestMentor contestMentor = new ContestMentor();
@@ -218,7 +302,7 @@ public class ContestServiceImpl implements ContestService {
 
     @Override
     public List<ContestMentor> getContestMnetor(Long contestId, Long userId, Byte role) {
-        return contestMentorDao.findByExamIdAndParticipantIdAndRole(contestId,userId,role);
+        return contestMentorDao.findByExamIdAndParticipantIdAndRole(contestId, userId, role);
     }
 
 }

+ 14 - 7
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/ctrl/ContestController.java

@@ -38,7 +38,7 @@ public class ContestController {
     @RequestMapping(value = UrlConstants.API + "contest/enter/{contestId}", method = RequestMethod.POST)
     public boolean enterContest(@PathVariable("contestId") Long contestId) {
         User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
-        return contestLogic.enterContest(contestId,user.getId());
+        return contestLogic.enterContest(contestId, user.getId());
     }
 
     @RequestMapping(value = UrlConstants.API + "contest/mentors/{contestId}/{role}", method = RequestMethod.POST)
@@ -46,14 +46,14 @@ public class ContestController {
                                                   @PathVariable("role") Byte role,
                                                   @RequestBody List<ContestMentorVO> contestMentorVOS) {
         User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
-        return contestLogic.addContestMentor(contestId,user.getId(), contestMentorVOS, role);
+        return contestLogic.addContestMentor(contestId, user.getId(), contestMentorVOS, role);
     }
 
     @RequestMapping(value = UrlConstants.API + "contest/mentors/{contestId}", method = RequestMethod.GET)
     public List<ContestMentorVO> getContestMentor(@PathVariable("contestId") Long contestId, @RequestParam(name = "role") Byte role) {
         User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
         examLogic.getExamByIdAndParticipantIdIfPermited(contestId, user.getId());
-        return contestLogic.getContestMentor(contestId,user.getId(),role);
+        return contestLogic.getContestMentor(contestId, user.getId(), role);
     }
 
     @RequestMapping(value = UrlConstants.API + "contest", method = RequestMethod.GET)
@@ -67,16 +67,16 @@ public class ContestController {
         Integer rowsOnPage = Integer.parseInt(rowsOnPageStr);
 
         Pageable pageable = new PageRequest(activePage - 1, rowsOnPage);
-        return contestLogic.getContestList(user.getId(),pageable);
+        return contestLogic.getContestList(user.getId(), pageable);
     }
 
     @RequestMapping(value = UrlConstants.API + "contest/enterWithoutLogin/{contestId}", method = RequestMethod.POST)
     public Boolean enterContestWithoutLogin(@PathVariable("contestId") Long contestId, @RequestBody EnterContestVO enterContestVO) {
         User user = userService.findByEmail(enterContestVO.getEmail());
-        if(user.getPassword()!=enterContestVO.getPassword()){
+        if (user.getPassword() != enterContestVO.getPassword()) {
             throw new UnauthorizedException("unauthorized");
         }
-        return contestLogic.enterContest(contestId,user.getId());
+        return contestLogic.enterContest(contestId, user.getId());
     }
 
     @RequestMapping(value = UrlConstants.API_WORKER + "contest", method = RequestMethod.POST)
@@ -96,11 +96,18 @@ public class ContestController {
         return contestLogic.findByYear(year);
     }
 
+    //夏季预选赛
     @RequestMapping(value = UrlConstants.API_COMMON + "contest/statistics/{contestId:\\d+}", method = RequestMethod.GET)
-    public String getContestStatistics(@PathVariable("contestId") Long contestId){
+    public String getContestStatistics(@PathVariable("contestId") Long contestId) {
         return "receive(" + contestLogic.getContestStatistics(contestId) + ")";
     }
 
+    //秋季预选赛
+    @RequestMapping(value = UrlConstants.API_COMMON + "contest/statisticsOfFall/{groupId}", method = RequestMethod.GET)
+    public String getContestStatisticsOfFall(@PathVariable("groupId") Long groupId) {
+        return "receive(" + contestLogic.getContestStatisticsOfFall(groupId) + ")";
+    }
+
     @RequestMapping(value = UrlConstants.API_COMMON + "contest/sycn", method = RequestMethod.GET)
     public String sycnStudentInfo() {
         System.out.println("同步学生信息");

+ 6 - 5
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/ContestLogic.java

@@ -1,15 +1,14 @@
 package cn.iselab.mooctest.site.web.logic;
 
-import cn.iselab.mooctest.site.web.data.ContestVO;
-
-import java.util.List;
-
 import cn.iselab.mooctest.site.web.data.ContestMentorVO;
+import cn.iselab.mooctest.site.web.data.ContestVO;
 import cn.iselab.mooctest.site.web.data.ExamVO;
-import net.sf.json.*;
+import net.sf.json.JSONObject;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 
+import java.util.List;
+
 /**
  * Created by lishuying on 17/3/30.
  */
@@ -31,4 +30,6 @@ public interface ContestLogic {
     String sycnStudentArea();
 
     Page<ExamVO> getContestList(Long userId, Pageable pageable);
+
+    JSONObject getContestStatisticsOfFall(Long groupId);
 }

+ 20 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/ContestLogicImpl.java

@@ -112,6 +112,9 @@ public class ContestLogicImpl implements ContestLogic {
         return contestVOWrapper.wrap(contestService.findByWorkerId(workerId));
     }
 
+    /*
+    * 2017夏季赛统计数据
+    * */
     @Override
     public JSONObject getContestStatistics(Long contestId) {
         ContestStatistics contestStatistics = contestService.getContestStatistics(contestId);
@@ -125,6 +128,22 @@ public class ContestLogicImpl implements ContestLogic {
         return result;
     }
 
+    /*
+     * 2017秋季赛统计数据
+     */
+    @Override
+    public JSONObject getContestStatisticsOfFall(Long groupId) {
+        ContestStatistics contestStatistics =  contestService.getContestStatisticsOfFall(groupId);
+        JSONObject result = null;
+        if (contestStatistics != null) {
+            result = new JSONObject();
+            result.put("schoolData", contestStatistics.getSchoolData());
+            result.put("locationData", contestStatistics.getLocationData());
+            result.put("activeData", contestStatistics.getActiveData());
+        }
+        return result;
+    }
+
     @Override
     public String sycnStudentInfo() {
         return contestService.sycnStudentInfo();
@@ -146,4 +165,5 @@ public class ContestLogicImpl implements ContestLogic {
         });
         return examVOPage;
     }
+
 }