├── .gitignore ├── .idea ├── artifacts │ ├── ACManager_war.xml │ └── ACManager_war_exploded.xml ├── compiler.xml ├── encodings.xml ├── kotlinc.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── workspace.xml ├── .travis.yml ├── ACManager.iml ├── Dockerfile ├── LICENSE ├── Readme.md ├── docker ├── db │ └── init1.sql └── docker-compose.yml ├── pom.xml ├── src ├── main │ ├── java │ │ ├── com │ │ │ ├── wzh │ │ │ │ ├── FileCaptureFilter.java │ │ │ │ └── FileCaptureResponseWrapper.java │ │ │ └── zzkun │ │ │ │ ├── controller │ │ │ │ ├── AcmerInfoController.java │ │ │ │ ├── AssignController.java │ │ │ │ ├── AuthController.java │ │ │ │ ├── ContestController.java │ │ │ │ ├── CptController.java │ │ │ │ ├── MainController.java │ │ │ │ ├── OJContestController.java │ │ │ │ ├── RatingController.java │ │ │ │ ├── StatisticController.java │ │ │ │ ├── TrainingController.java │ │ │ │ ├── UserACController.java │ │ │ │ └── api │ │ │ │ │ ├── ContestApi.kt │ │ │ │ │ ├── CptApi.kt │ │ │ │ │ ├── RatingApi.kt │ │ │ │ │ ├── SystemApi.kt │ │ │ │ │ ├── TrainingApi.java │ │ │ │ │ ├── UserACApi.kt │ │ │ │ │ └── UserApi.kt │ │ │ │ ├── dao │ │ │ │ ├── AcmerInfoRepo.java │ │ │ │ ├── AssignResultRepo.java │ │ │ │ ├── BCUserInfoRepo.java │ │ │ │ ├── CFUserInfoRepo.java │ │ │ │ ├── ContestRepo.java │ │ │ │ ├── CptTreeRepo.java │ │ │ │ ├── ExtOjLinkRepo.java │ │ │ │ ├── ExtOjPbInfoRepo.java │ │ │ │ ├── FixedTeamRepo.java │ │ │ │ ├── OJContestRepo.java │ │ │ │ ├── RatingRecordRepo.java │ │ │ │ ├── StageRepo.java │ │ │ │ ├── SystemStateRepo.java │ │ │ │ ├── TrainingRepo.java │ │ │ │ ├── UJoinTRepo.java │ │ │ │ ├── UserACPbRepo.java │ │ │ │ └── UserRepo.java │ │ │ │ ├── model │ │ │ │ ├── ACMerInfo.java │ │ │ │ ├── AssignResult.java │ │ │ │ ├── BCUserInfo.java │ │ │ │ ├── CFUserInfo.java │ │ │ │ ├── Contest.java │ │ │ │ ├── CptTree.java │ │ │ │ ├── ExtOjLink.java │ │ │ │ ├── ExtOjPbInfo.java │ │ │ │ ├── FixedTeam.java │ │ │ │ ├── OJContest.java │ │ │ │ ├── OJType.java │ │ │ │ ├── PbStatus.java │ │ │ │ ├── RatingRecord.java │ │ │ │ ├── Stage.java │ │ │ │ ├── SystemState.java │ │ │ │ ├── TeamRanking.java │ │ │ │ ├── Training.java │ │ │ │ ├── UJoinT.java │ │ │ │ ├── User.java │ │ │ │ └── UserACPb.java │ │ │ │ ├── service │ │ │ │ ├── CFBCService.java │ │ │ │ ├── ContestSearchService.kt │ │ │ │ ├── ExtOjService.kt │ │ │ │ ├── OJContestService.java │ │ │ │ ├── RatingService.java │ │ │ │ ├── SystemService.kt │ │ │ │ ├── TeamAssignService.java │ │ │ │ ├── TrainingService.java │ │ │ │ ├── UserService.java │ │ │ │ └── extoj │ │ │ │ │ ├── CFService.kt │ │ │ │ │ ├── HDUService.kt │ │ │ │ │ ├── IExtOJAdapter.kt │ │ │ │ │ ├── POJService.kt │ │ │ │ │ ├── UVaService.kt │ │ │ │ │ └── VJudgeService.kt │ │ │ │ └── util │ │ │ │ ├── cluster │ │ │ │ └── AgnesClusterer.java │ │ │ │ ├── cpt │ │ │ │ ├── Node.kt │ │ │ │ ├── NodeAnalyser.kt │ │ │ │ └── NodeBuilder.kt │ │ │ │ ├── dataproc │ │ │ │ ├── DataLinerStder.kt │ │ │ │ ├── DataStder.java │ │ │ │ └── RawData.java │ │ │ │ ├── date │ │ │ │ ├── LocalDateConverter.java │ │ │ │ ├── LocalDateTimeConverter.java │ │ │ │ ├── MyDateFormater.kt │ │ │ │ └── ScheduledManager.kt │ │ │ │ ├── elo │ │ │ │ └── MyELO.java │ │ │ │ ├── geetest │ │ │ │ ├── GeetestConfig.java │ │ │ │ ├── GeetestLib.java │ │ │ │ ├── StartCaptchaServlet.java │ │ │ │ └── VerifyLoginServlet.java │ │ │ │ ├── prob │ │ │ │ └── PbDiffCalcer.kt │ │ │ │ ├── rank │ │ │ │ ├── RankCalculator.java │ │ │ │ ├── RankParser.java │ │ │ │ └── VJRankParser.java │ │ │ │ ├── uhunt │ │ │ │ ├── UHuntAnalyser.kt │ │ │ │ ├── UHuntTreeNode.kt │ │ │ │ └── UhuntTreeManager.java │ │ │ │ └── web │ │ │ │ ├── BCWebGetter.java │ │ │ │ ├── CFWebGetter.kt │ │ │ │ ├── HDUWebGetter.kt │ │ │ │ ├── HttpUtil.kt │ │ │ │ ├── POJWebGetter.kt │ │ │ │ ├── UHuntWebGetter.java │ │ │ │ └── VJudgeWebGetter.kt │ │ └── jskills │ │ │ ├── GameInfo.java │ │ │ ├── Guard.java │ │ │ ├── IPlayer.java │ │ │ ├── ISupportPartialPlay.java │ │ │ ├── ISupportPartialUpdate.java │ │ │ ├── ITeam.java │ │ │ ├── PairwiseComparison.java │ │ │ ├── PartialPlay.java │ │ │ ├── Player.java │ │ │ ├── RankSorter.java │ │ │ ├── Rating.java │ │ │ ├── SkillCalculator.java │ │ │ ├── Team.java │ │ │ ├── TrueSkillCalculator.java │ │ │ ├── elo │ │ │ ├── DuellingEloCalculator.java │ │ │ ├── EloRating.java │ │ │ ├── FideEloCalculator.java │ │ │ ├── FideKFactor.java │ │ │ ├── GaussianEloCalculator.java │ │ │ ├── GaussianKFactor.java │ │ │ ├── KFactor.java │ │ │ └── TwoPlayerEloCalculator.java │ │ │ ├── factorgraphs │ │ │ ├── DefaultVariable.java │ │ │ ├── Factor.java │ │ │ ├── FactorGraph.java │ │ │ ├── FactorGraphLayer.java │ │ │ ├── FactorGraphLayerBase.java │ │ │ ├── FactorList.java │ │ │ ├── KeyedVariable.java │ │ │ ├── Message.java │ │ │ ├── Schedule.java │ │ │ ├── ScheduleLoop.java │ │ │ ├── ScheduleSequence.java │ │ │ ├── ScheduleStep.java │ │ │ └── Variable.java │ │ │ ├── numerics │ │ │ ├── GaussianDistribution.java │ │ │ ├── MathUtils.java │ │ │ └── Range.java │ │ │ └── trueskill │ │ │ ├── DrawMargin.java │ │ │ ├── FactorGraphTrueSkillCalculator.java │ │ │ ├── TrueSkillFactorGraph.java │ │ │ ├── TruncatedGaussianCorrectionFunctions.java │ │ │ ├── TwoPlayerTrueSkillCalculator.java │ │ │ ├── TwoTeamTrueSkillCalculator.java │ │ │ ├── factors │ │ │ ├── GaussianFactor.java │ │ │ ├── GaussianGreaterThanFactor.java │ │ │ ├── GaussianLikelihoodFactor.java │ │ │ ├── GaussianPriorFactor.java │ │ │ ├── GaussianWeightedSumFactor.java │ │ │ └── GaussianWithinFactor.java │ │ │ └── layers │ │ │ ├── IteratedTeamDifferencesInnerLayer.java │ │ │ ├── PlayerPerformancesToTeamPerformancesLayer.java │ │ │ ├── PlayerPriorValuesToSkillsLayer.java │ │ │ ├── PlayerSkillsToPerformancesLayer.java │ │ │ ├── TeamDifferencesComparisonLayer.java │ │ │ ├── TeamPerformancesToTeamPerformanceDifferencesLayer.java │ │ │ └── TrueSkillFactorGraphLayer.java │ └── resources │ │ ├── common-logging.properties │ │ ├── jdbc.properties │ │ ├── log4j.properties │ │ ├── real_jdbc.properties │ │ ├── springmvc-servlet.xml │ │ └── uhunt │ │ ├── 2016sum.csv │ │ ├── aoapc.csv │ │ └── pblist.json └── test │ └── java │ └── com │ └── zzkun │ ├── MyTest.java │ ├── MyTest2.java │ ├── controller │ └── AuthControllerTest.java │ ├── dao │ ├── AssignResultRepoTest.java │ ├── ContestRepoTest.java │ ├── ExtOjLinkRepoTest.java │ ├── FixedTeamRepoTest.java │ ├── RatingRecordRepoTest.java │ ├── StageRepoTest.java │ ├── TrainingRepoTest.java │ ├── UJoinTRepoTest.java │ ├── UserACPbRepoTest.java │ └── UserRepoTest.java │ ├── service │ ├── CFBCServiceTest.java │ ├── ContestSearchServiceTest.kt │ ├── OJContestServiceTest.java │ ├── RatingServiceTest.java │ ├── UVaServiceTest.java │ └── extoj │ │ ├── ExtOjServiceTest.kt │ │ ├── UVaExtOjServiceTest.kt │ │ └── VJudgeServiceTest.kt │ ├── uhunt │ ├── UHuntWebGetterTest.java │ └── UhuntTreeManagerTest.java │ └── util │ ├── JsonTest.java │ ├── assign │ └── TeamAssignServiceTest.java │ ├── bcapi │ └── BCWebGetterTest.java │ ├── cfapi │ └── CFWebGetterTest.java │ ├── cluster │ └── AgnesClustererTest.java │ ├── elo │ └── MyELOTest.java │ ├── rank │ ├── RankCalculatorTest.java │ └── VJRankParserTest.java │ └── web │ ├── HDUWebGetterTest.kt │ ├── HttpUtilTest.java │ └── VJudgeWebGetterTest.kt ├── temp └── vjudge └── web └── WEB-INF ├── cache └── userId_.html ├── jsp ├── RandomTeam.jsp ├── cpt_detail.jsp ├── cpt_pidsinfo.jsp ├── default.css ├── directionOfAcmer.jsp ├── fixed.jsp ├── footerInfo.jsp ├── gamelist.jsp ├── importComp.jsp ├── index.jsp ├── last_teamResult.jsp ├── login.jsp ├── lost.jsp ├── oj_recent_contest.jsp ├── page_404.jsp ├── ranklist_score.jsp ├── rg.jsp ├── search_contest.jsp ├── special_training.jsp ├── special_training_detail.jsp ├── special_training_rule.jsp ├── stagelist.jsp ├── tablefile.jsp ├── tablefile_userac.jsp ├── teamResult.jsp ├── topBar.jsp ├── trainingUser.jsp ├── training_statistics.jsp ├── training_topbar.jsp ├── trainingsetlist.jsp ├── user_ac_detail.jsp └── userdetail.jsp └── web.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | out/ 3 | classes/ 4 | lib/ 5 | .idea/libraries -------------------------------------------------------------------------------- /.idea/artifacts/ACManager_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: required 3 | 4 | services: 5 | - docker 6 | 7 | install: 8 | - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V 9 | 10 | script: 11 | - mvn clean package -Dmaven.test.skip=true 12 | 13 | after_success: 14 | - docker build -t kun368/acmanager:$TRAVIS_BRANCH . 15 | - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 16 | - docker push kun368/acmanager:$TRAVIS_BRANCH 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tomcat:8-jre8 2 | 3 | RUN rm -rf /usr/local/tomcat/webapps/ROOT 4 | COPY ./target/ACManager.war /usr/local/tomcat/webapps/ROOT.war 5 | EXPOSE 8080 -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # ACM集训队管理系统 2 | 3 | [![Build Status](https://travis-ci.org/kun368/ACManager.svg?branch=master)](https://travis-ci.org/kun368/ACManager) 4 | [![codebeat badge](https://codebeat.co/badges/49176421-bc21-4672-ad36-d7b275ad2afa)](https://codebeat.co/projects/github-com-kun368-acmanager-master) 5 | [![Release Version](https://img.shields.io/badge/release-1.1.0-red.svg)](https://github.com/kun368/ACManager/releases) 6 | [![Language](https://img.shields.io/badge/language-java-orange.svg)](https://github.com/kun368/ACManager) 7 | [![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven/apache-maven.svg)](https://github.com/kun368/ACManager) 8 | [![GPL Licence](https://badges.frapsoft.com/os/gpl/gpl.svg?v=103)](https://opensource.org/licenses/GPL-3.0/) 9 | 10 | ## 项目简介 11 | 12 | 提供 ACM 集训队日常做题、比赛、题目分析、队员评价与选拔等功能,目前已上线稳定运行2年。 13 | 14 | - 毕设题目:ACM智能集训管理系统设计与DevOps实践 15 | - Wiki文档(同步毕设撰写中):[https://github.com/kun368/ACManager/wiki](https://github.com/kun368/ACManager/wiki) 16 | - Docker镜像(自动构建):[https://hub.docker.com/r/kun368/acmanager/](https://hub.docker.com/r/kun368/acmanager/) 17 | 18 | ## 主要功能 19 | 20 | - 队员 UVa、HDU、POJ 等 OnlineJudge AC 题目统计与分析 21 | - 队员 Codeforces / BestCoder / TopCoder 的 Rating 统计 22 | - 日常比赛训练结果导入和分析 23 | - 完善的的集训、阶段、比赛类型管理 24 | - 队员、队伍管理,量化分析评价 25 | - 随机组队赛智能分队 26 | - 各大 OnlineJudge 近期比赛汇总 27 | - 队员毕业去向统计 28 | - 提供 RESTful API 29 | 30 | ## 技术栈 31 | 32 | - 前端:JSP、JQuery、Bootstrap、Vue.js 33 | - 后端:Java8、Kotlin、Spring、SpringMVC 34 | - 数据:MySql、Druid、Hibernate、Spring Data JPA 35 | - 搜索:Lucene 36 | - 服务器:Tomcat、Nginx 37 | - 开发工具:Maven、IntelliJ IDEA、JRebel 38 | - 算法:Agnes、TrueSkill、KMP、DFS 39 | - 持续集成:Docker、Docker-Compose、Travis 40 | 41 | ## 线上网站 42 | 43 | - [http://192.168.119.213:8080/ACManager/](http://192.168.119.213:8080/ACManager/) 44 | - [http://cise.sdust.edu.cn/acmanager/](http://cise.sdust.edu.cn/acmanager/) 45 | -------------------------------------------------------------------------------- /docker/db/init1.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS acmanager DEFAULT CHARSET utf8 COLLATE utf8_general_ci; 2 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | acmanagerdb: 5 | image: mysql:5.7 6 | restart: always 7 | ports: 8 | - 3307:3306 9 | environment: 10 | MYSQL_ROOT_PASSWORD: 123456 11 | volumes: 12 | - ./db:/docker-entrypoint-initdb.d 13 | 14 | acmanager-server: 15 | image: kun368/acmanager:master 16 | ports: 17 | - 8105:8080 18 | depends_on: 19 | - acmanagerdb 20 | links: 21 | - acmanagerdb -------------------------------------------------------------------------------- /src/main/java/com/wzh/FileCaptureFilter.java: -------------------------------------------------------------------------------- 1 | package com.wzh; 2 | 3 | /** 4 | * Created by wzh on 2017/5/24. 5 | */ 6 | import java.io.File; 7 | import java.io.IOException; 8 | import javax.servlet.Filter; 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.FilterConfig; 11 | import javax.servlet.ServletException; 12 | import javax.servlet.ServletRequest; 13 | import javax.servlet.ServletResponse; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | public class FileCaptureFilter implements Filter{ 18 | 19 | private String protDirPath; 20 | private FilterConfig filterConfig; 21 | 22 | @Override 23 | public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException { 24 | // 25 | // LoginUser loginUser = (LoginUser) ((HttpServletRequest)request).getSession().getAttribute(LoginConstant.USER); 26 | // if (loginUser == null) 27 | // throw new NoLoginException(); 28 | System.out.print(request.getLocalAddr()); 29 | String fileName = "/cache/userId_.html"; 30 | File file = new File(filterConfig.getServletContext().getRealPath(fileName)); 31 | // 判断缓存文件是否存在或者是否重新设置了缓存内容 32 | if (!file.exists()) {// 如果缓存文件不存在 33 | fileName=protDirPath+fileName; 34 | FileCaptureResponseWrapper wrapper = new FileCaptureResponseWrapper((HttpServletResponse)response); 35 | chain.doFilter(request, wrapper); 36 | //得到的html 页面结果字符串 37 | //String html = responseWrapper.toString(); 38 | // 写成html 文件 39 | wrapper.writeFile(fileName); 40 | // back to browser 41 | wrapper.writeResponse(); 42 | 43 | }else{ 44 | // 转发至缓存文件 45 | request.getRequestDispatcher(fileName).forward(request, response); 46 | } 47 | } 48 | 49 | @Override 50 | public void destroy() { 51 | // TODO Auto-generated method stub 52 | } 53 | 54 | @Override 55 | public void init(FilterConfig arg0) throws ServletException { 56 | this.filterConfig=arg0; 57 | protDirPath = arg0.getServletContext().getRealPath("/"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/wzh/FileCaptureResponseWrapper.java: -------------------------------------------------------------------------------- 1 | package com.wzh; 2 | 3 | /** 4 | * Created by wzh on 2017/5/24. 5 | */ 6 | import java.io.CharArrayWriter; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.io.OutputStreamWriter; 10 | import java.io.PrintWriter; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpServletResponseWrapper; 13 | 14 | public class FileCaptureResponseWrapper extends HttpServletResponseWrapper { 15 | private CharArrayWriter output; 16 | private HttpServletResponse response; 17 | 18 | public String toString() { 19 | return output.toString(); 20 | } 21 | 22 | public FileCaptureResponseWrapper(HttpServletResponse response) { 23 | super(response); 24 | this.response = response; 25 | output = new CharArrayWriter(); 26 | // 这个是包装PrintWriter的,让所有结果通过这个PrintWriter写入到bufferedWriter中 27 | } 28 | 29 | // 覆写getWriter() 30 | public PrintWriter getWriter() { 31 | return new PrintWriter(output); 32 | } 33 | /** 34 | * 获取原始的HTML页面内容。 35 | * @return 36 | */ 37 | public String getResult() { 38 | return output.toString(); 39 | } 40 | 41 | public void writeFile(String fileName) throws IOException { 42 | /* FileWriter fw = new FileWriter(fileName,"utf-8"); 43 | fw.write( output.toCharArray(),"utf-8" ); 44 | PrintWriter writer = new PrintWriter(new OutputStreamWriter(new 45 | FileOutputStream(fileName),"utf-8"));*/ 46 | FileOutputStream fos = new FileOutputStream(fileName); 47 | OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); 48 | osw.write(output.toCharArray()); 49 | osw.close(); 50 | } 51 | 52 | public void writeResponse() throws IOException { 53 | PrintWriter out = response.getWriter(); 54 | // 重置响应输出的内容长度 55 | response.setContentLength(-1); 56 | out.print(output.toCharArray()); 57 | out.flush(); 58 | out.close(); 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/AcmerInfoController.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | /** 8 | * Created by wzh on 2017/5/23. 9 | */ 10 | @Controller 11 | @RequestMapping("/acmer") 12 | public class AcmerInfoController { 13 | @RequestMapping("/infos") 14 | public String AcmerInfo(Model model){ 15 | //model.addAttribute("list", ojContestService.getRecents()); 16 | return "directionOfAcmer"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/MainController.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * Created by kun on 2016/7/5. 8 | */ 9 | @Controller 10 | public class MainController { 11 | 12 | @RequestMapping("/") 13 | public String index() { 14 | return "index"; 15 | } 16 | 17 | @RequestMapping("/404") 18 | public String page404() { 19 | return "page_404"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/OJContestController.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import com.zzkun.service.OJContestService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.ResponseBody; 9 | 10 | /** 11 | * Created by Administrator on 2016/8/3. 12 | */ 13 | @Controller 14 | @RequestMapping("/oj") 15 | public class OJContestController { 16 | 17 | @Autowired private OJContestService ojContestService; 18 | 19 | @RequestMapping("/recentContest") 20 | public String recentContest(Model model) { 21 | model.addAttribute("list", ojContestService.getRecents()); 22 | return "oj_recent_contest"; 23 | } 24 | 25 | @RequestMapping(value = "/update", produces = "text/html;charset=UTF-8") 26 | @ResponseBody 27 | public String update() { 28 | ojContestService.flushOJContests(); 29 | return "更新成功!"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/RatingController.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import com.zzkun.model.Training; 4 | import com.zzkun.service.RatingService; 5 | import com.zzkun.service.TrainingService; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | /** 15 | * Created by kun on 2016/8/16. 16 | */ 17 | @Controller 18 | @RequestMapping("/rating") 19 | public class RatingController { 20 | 21 | private static final Logger logger = LoggerFactory.getLogger(RatingController.class); 22 | 23 | @Autowired private RatingService ratingService; 24 | @Autowired private TrainingService trainingService; 25 | 26 | @RequestMapping(value = "/updateTraining/{trainingId}", produces = "text/html;charset=UTF-8") 27 | @ResponseBody 28 | public String updateTraining(@PathVariable Integer trainingId) { 29 | Training training = trainingService.getTrainingById(trainingId); 30 | ratingService.flushTrainingUserRating(training); 31 | return "更新完毕~"; 32 | } 33 | 34 | @RequestMapping(value = "/updateTrainingTeam/{trainingId}", produces = "text/html;charset=UTF-8") 35 | @ResponseBody 36 | public String updateTrainingTeam(@PathVariable Integer trainingId) { 37 | Training training = trainingService.getTrainingById(trainingId); 38 | ratingService.flushTrainingTeamRating(training); 39 | return "更新完毕~"; 40 | } 41 | 42 | @RequestMapping(value = "/updateGlobal", produces = "text/html;charset=UTF-8") 43 | @ResponseBody 44 | public String updateGlobal() { 45 | ratingService.flushGlobalUserRating(); 46 | return "更新完毕~"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/StatisticController.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import com.zzkun.model.RatingRecord; 4 | import com.zzkun.model.User; 5 | import com.zzkun.service.CFBCService; 6 | import com.zzkun.service.RatingService; 7 | import com.zzkun.service.UserService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | import org.springframework.web.bind.annotation.SessionAttribute; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * uva相关控制器 19 | * Created by kun on 2016/7/14. 20 | */ 21 | @Controller 22 | @RequestMapping("/statistics") 23 | public class StatisticController { 24 | 25 | @Autowired private CFBCService cfbcService; 26 | @Autowired private UserService userService; 27 | @Autowired private RatingService ratingService; 28 | 29 | 30 | @RequestMapping("/showTable") 31 | public String showTable(Model model) { 32 | List users = userService.allNormalNotNullUsers(); 33 | model.addAttribute("users", users); 34 | model.addAttribute("cfInfoMap", cfbcService.getCFUserInfoMap()); 35 | model.addAttribute("bcInfoMap", cfbcService.getBCUserInfoMap()); 36 | model.addAttribute("ratingMap", 37 | ratingService.getRatingMap(RatingRecord.Scope.Global, 1, RatingRecord.Type.Personal)); 38 | model.addAttribute("playcntMap", 39 | ratingService.getPlayCnt(RatingRecord.Scope.Global, 1, RatingRecord.Type.Personal)); 40 | model.addAttribute("playDuration", 41 | ratingService.getPlayDuration(RatingRecord.Scope.Global, 1, RatingRecord.Type.Personal)); 42 | return "tablefile"; 43 | } 44 | 45 | @RequestMapping(value = "/updateCFBC", produces = "text/html;charset=UTF-8") 46 | @ResponseBody 47 | public String updateCFBC(@SessionAttribute(required = false) User user) { 48 | System.out.println(user.getBcname()); 49 | if(user == null) 50 | return "您没有登录!"; 51 | if(user.isACMer()){ 52 | 53 | } 54 | else{ 55 | if(user.getBcname()!=null){ 56 | synchronized (this) { 57 | cfbcService.flushBCUserInfoByName(user.getBcname()); 58 | } 59 | } 60 | if(user.getCfname()!=null){ 61 | synchronized (this) { 62 | //cfbcService.flushCFUserInfoByName(user.getCfname()); 63 | } 64 | } 65 | } 66 | synchronized (this) { 67 | cfbcService.flushCFUserInfos(); 68 | cfbcService.flushBCUserInfos(); 69 | } 70 | return "恭喜,更新完毕!"; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/UserACController.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import com.zzkun.model.User; 4 | import com.zzkun.service.CFBCService; 5 | import com.zzkun.service.ExtOjService; 6 | import com.zzkun.service.UserService; 7 | import com.zzkun.util.uhunt.UHuntAnalyser; 8 | import com.zzkun.util.uhunt.UHuntTreeNode; 9 | import com.zzkun.util.uhunt.UhuntTreeManager; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.ui.Model; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.ResponseBody; 18 | import org.springframework.web.bind.annotation.SessionAttribute; 19 | 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | 24 | @Controller 25 | @RequestMapping("/userac") 26 | public class UserACController { 27 | 28 | private static final Logger logger = LoggerFactory.getLogger(UserACController.class); 29 | 30 | @Autowired private CFBCService cfbcService; 31 | @Autowired private UserService userService; 32 | @Autowired private ExtOjService extOjService; 33 | @Autowired private UhuntTreeManager uhuntTreeManager; 34 | @Autowired private UHuntAnalyser uHuntAnalyser; 35 | 36 | 37 | @RequestMapping("/showTable") 38 | public String showTable(Model model) { 39 | List users = userService.allNormalNotNullUsers(); 40 | List bookNodes = uhuntTreeManager.getBookNodes(); 41 | Map> statistic = uHuntAnalyser.userStatistic(users, bookNodes); 42 | model.addAttribute("users", users); 43 | model.addAttribute("userACMap", extOjService.getUserPerOjACMap(users)); 44 | model.addAttribute("bookNodes", bookNodes); 45 | model.addAttribute("statistic", statistic); 46 | model.addAttribute("cfInfoMap", cfbcService.getCFUserInfoMap()); 47 | model.addAttribute("bcInfoMap", cfbcService.getBCUserInfoMap()); 48 | return "tablefile_userac"; 49 | } 50 | 51 | @RequestMapping("/{username}/list") 52 | public String list(@PathVariable String username, 53 | Model model) { 54 | User user = userService.getUserByUsername(username); 55 | model.addAttribute("username", username); 56 | model.addAttribute("curUser", user); 57 | return "user_ac_detail"; 58 | } 59 | 60 | @RequestMapping(value = "/updatedb", produces = "text/html;charset=UTF-8") 61 | @ResponseBody 62 | public String updatedb(@SessionAttribute(required = false) User user) { 63 | if(user == null){ 64 | return "您没有登录"; 65 | } 66 | if(user.isAdmin()){ 67 | extOjService.flushACDB(); 68 | } 69 | else{ 70 | extOjService.flushACDByUser(user); 71 | } 72 | return "更新完毕,久等了......"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/api/ContestApi.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller.api 2 | //hello 3 | import com.alibaba.fastjson.JSONArray 4 | import com.alibaba.fastjson.JSONObject 5 | import com.zzkun.controller.TrainingController 6 | import com.zzkun.service.TrainingService 7 | import com.zzkun.util.date.MyDateFormater 8 | import com.zzkun.util.rank.RankCalculator 9 | import org.slf4j.LoggerFactory 10 | import org.springframework.beans.factory.annotation.Autowired 11 | import org.springframework.web.bind.annotation.PathVariable 12 | import org.springframework.web.bind.annotation.RequestMapping 13 | import org.springframework.web.bind.annotation.RequestMethod 14 | import org.springframework.web.bind.annotation.RestController 15 | 16 | /** 17 | * Created by kun on 2016/8/30. 18 | */ 19 | @RestController 20 | @RequestMapping("/api/contest") 21 | open class ContestApi { 22 | 23 | private val logger = LoggerFactory.getLogger(TrainingController::class.java) 24 | 25 | @Autowired val trainingService: TrainingService? = null 26 | 27 | @RequestMapping(value = ["/{contestId}/statistic"], 28 | method = [(RequestMethod.GET)], 29 | produces = ["text/html;charset=UTF-8"]) 30 | fun statistic(@PathVariable contestId: Int?): String { 31 | logger.info("调用比赛详情API:{}", contestId) 32 | 33 | val contest = trainingService?.getContest(contestId) ?: 34 | return "contestId is InValid" 35 | val training = contest.stage.training 36 | val calculator = RankCalculator(contest, 0) 37 | val score = calculator.teamScore 38 | val rank = calculator.teamRank 39 | 40 | val result = JSONObject(true) 41 | result.put("id", contest.id) 42 | result.put("name", contest.name) 43 | result.put("startTime", MyDateFormater.toStr1(contest.startTime)) 44 | result.put("endTime", MyDateFormater.toStr1(contest.endTime)) 45 | result.put("addTime", MyDateFormater.toStr1(contest.addTime)) 46 | result.put("problemCount", contest.pbCnt) 47 | result.put("type", contest.type) 48 | result.put("source", contest.source) 49 | result.put("sourceDetail", contest.sourceDetail) 50 | result.put("sourceUrl", contest.sourceUrl) 51 | result.put("stageId", contest.stage.id) 52 | result.put("trainingId", training.id) 53 | val array = JSONArray() 54 | result.put("ranking", array) 55 | for (i in 0..contest.ranks.size - 1) { 56 | val teamRanking = contest.ranks[i] 57 | val team = JSONObject() 58 | team.put("account", teamRanking.account) 59 | team.put("teamName", teamRanking.teamName) 60 | team.put("isLoaclTeam", teamRanking.localTeam) 61 | team.put("member", teamRanking.member) 62 | team.put("solvedCount", teamRanking.solvedCount) 63 | team.put("penalty", teamRanking.calcSumPenalty()) 64 | team.put("score", score[i]) 65 | team.put("rank", rank[i]) 66 | array.add(team) 67 | } 68 | return result.toJSONString() 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/api/RatingApi.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller.api 2 | 3 | import com.alibaba.fastjson.JSONArray 4 | import com.alibaba.fastjson.JSONObject 5 | import com.zzkun.model.RatingRecord 6 | import com.zzkun.service.RatingService 7 | import com.zzkun.service.UserService 8 | import jskills.Rating 9 | import org.springframework.beans.factory.annotation.Autowired 10 | import org.springframework.web.bind.annotation.PathVariable 11 | import org.springframework.web.bind.annotation.RequestMapping 12 | import org.springframework.web.bind.annotation.RequestMethod 13 | import org.springframework.web.bind.annotation.RestController 14 | 15 | /** 16 | * Created by kun on 2016/8/30. 17 | */ 18 | @RestController 19 | @RequestMapping("/api/rating") 20 | open class RatingApi( 21 | @Autowired private val ratingService: RatingService, 22 | @Autowired private val userService: UserService) { 23 | 24 | @RequestMapping(value = ["/training/{trainingId}/username/{name}"], 25 | method = arrayOf(RequestMethod.GET), 26 | produces = arrayOf("text/html;charset=UTF-8")) 27 | fun trainingUser(@PathVariable trainingId: Int?, 28 | @PathVariable name: String): String { 29 | val user = userService.getUserByUsername(name) 30 | val list = ratingService.getPersonalRatingHistory(RatingRecord.Scope.Training, trainingId, user?.realName) 31 | val result = JSONObject() 32 | val array = JSONArray() 33 | result["result"] = array 34 | result["requestTraining"] = trainingId 35 | result["requestUsername"] = name 36 | if(list != null) { 37 | for ( record in list) { 38 | if (!record.partIn) 39 | continue 40 | val recordObj = JSONObject() 41 | val rating = Rating(record.mean!!, record.standardDeviation!!) 42 | recordObj.put("contestId", record.contest.id) 43 | recordObj.put("contestName", record.contest.name) 44 | recordObj.put("contestStartTime", record.contest.startTime) 45 | recordObj.put("contestEndTime", record.contest.endTime) 46 | recordObj.put("mean", record.mean) 47 | recordObj.put("standardDeviation", record.standardDeviation) 48 | recordObj.put("conservativeRating", record.conservativeRating) 49 | recordObj.put("myRating", rating.myRating) 50 | recordObj.put("playDuration", record.userPlayDuration) 51 | recordObj.put("playRankSum", record.userRankSum) 52 | recordObj.put("generateTime", record.generateTime) 53 | array.add(recordObj) 54 | } 55 | } 56 | return result.toJSONString() 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/api/SystemApi.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller.api 2 | 3 | import com.alibaba.fastjson.JSONArray 4 | import com.zzkun.service.SystemService 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.web.bind.annotation.RequestMapping 7 | import org.springframework.web.bind.annotation.RequestMethod 8 | import org.springframework.web.bind.annotation.RestController 9 | 10 | /** 11 | * Created by Administrator on 2017/2/21 0021. 12 | */ 13 | @RestController 14 | @RequestMapping("/api/system") 15 | open class SystemApi( 16 | @Autowired private val systemService: SystemService) { 17 | 18 | @RequestMapping(value = ["/stateHistory"], 19 | method = [(RequestMethod.GET)], 20 | produces = ["text/html;charset=UTF-8"]) 21 | fun stateHistory(): String { 22 | return JSONArray(systemService.stateHistory()).toJSONString() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/api/TrainingApi.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller.api; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.zzkun.model.Contest; 6 | import com.zzkun.model.Stage; 7 | import com.zzkun.model.Training; 8 | import com.zzkun.service.TrainingService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by kun on 2016/8/25. 19 | */ 20 | @RestController 21 | @RequestMapping("/api/training") 22 | public class TrainingApi { 23 | 24 | @Autowired private TrainingService trainingService; 25 | 26 | @RequestMapping(value = "/{trainingId}/list", 27 | method = RequestMethod.GET, 28 | produces = "text/html;charset=UTF-8") 29 | public String list(@PathVariable Integer trainingId) { 30 | Training training = trainingService.getTrainingById(trainingId); 31 | if(training == null) 32 | return ""; 33 | List stageList = training.getStageList(); 34 | 35 | JSONObject object = new JSONObject(true); 36 | object.put("id", training.getId()); 37 | object.put("name", training.getName()); 38 | object.put("startDate", training.getStartDate()); 39 | object.put("endDate", training.getEndDate()); 40 | object.put("addTime", training.getAddTime()); 41 | JSONArray stageArray = new JSONArray(); 42 | object.put("stageList", stageArray); 43 | for (Stage stage : stageList) { 44 | JSONObject stageObject = new JSONObject(true); 45 | stageObject.put("id", stage.getId()); 46 | stageObject.put("name", stage.getName()); 47 | stageObject.put("startDate", stage.getStartDate()); 48 | stageObject.put("endDate", stage.getEndDate()); 49 | JSONArray contestIdArray = new JSONArray(); 50 | stageObject.put("contestIdList", contestIdArray); 51 | for (Contest contest : stage.getContestList()) 52 | contestIdArray.add(contest.getId()); 53 | stageArray.add(stageObject); 54 | } 55 | return object.toJSONString(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/api/UserACApi.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller.api 2 | 3 | import com.alibaba.fastjson.JSONObject 4 | import com.zzkun.dao.ExtOjLinkRepo 5 | import com.zzkun.model.OJType 6 | import com.zzkun.service.ExtOjService 7 | import com.zzkun.service.UserService 8 | import com.zzkun.util.uhunt.UHuntAnalyser 9 | import org.springframework.beans.factory.annotation.Autowired 10 | import org.springframework.web.bind.annotation.PathVariable 11 | import org.springframework.web.bind.annotation.RequestMapping 12 | import org.springframework.web.bind.annotation.RequestMethod 13 | import org.springframework.web.bind.annotation.RestController 14 | 15 | /** 16 | * Created by kun on 2016/9/30. 17 | */ 18 | @RestController 19 | @RequestMapping("/api/userac") 20 | class UserACApi { 21 | 22 | @Autowired lateinit var userService: UserService 23 | @Autowired lateinit var extojService: ExtOjService 24 | @Autowired lateinit var extojLinkRepo: ExtOjLinkRepo 25 | @Autowired lateinit var uhuntAnalyser: UHuntAnalyser 26 | 27 | @RequestMapping(value = ["/{username}/list"], 28 | method = [(RequestMethod.GET)]) 29 | fun list(@PathVariable username: String): String { 30 | val user = userService.getUserByUsername(username) 31 | val list = extojService.getUserAC(user) 32 | val map = mutableMapOf>() 33 | val set = mutableSetOf() 34 | val visited = mutableSetOf() 35 | list.forEach { 36 | val oj = it.ojName.toString() 37 | val id = it.ojPbId 38 | if(!visited.contains(oj+id)){ 39 | visited.add(oj + id) 40 | set.add(oj) 41 | if(!map.contains(oj)) 42 | map[oj] = mutableListOf() 43 | map[oj]?.add(id) 44 | } 45 | } 46 | val json = JSONObject(true) 47 | json["ojs"] = set.toList() 48 | json["ac"] = map as Map? 49 | return json.toString() 50 | } 51 | 52 | @RequestMapping(value = ["/url/{oj}/{pid}"], method = [(RequestMethod.GET)]) 53 | fun url(@PathVariable oj: String, @PathVariable pid: String): String { 54 | val type = OJType.valueOf(oj) 55 | val link = extojLinkRepo.findOne(type).problemLink 56 | if(type == OJType.UVA) { 57 | return String.format(link, uhuntAnalyser.numToPid(pid)) 58 | } else if(type == OJType.CodeForces || type == OJType.Gym) { 59 | return String.format(link, pid.substring(0, pid.length-1), pid.substring(pid.length-1)) 60 | } 61 | return String.format(link, pid) 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/controller/api/UserApi.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller.api 2 | 3 | import com.alibaba.fastjson.JSONObject 4 | import com.zzkun.model.User 5 | import com.zzkun.service.UserService 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.web.bind.annotation.PathVariable 8 | import org.springframework.web.bind.annotation.RequestMapping 9 | import org.springframework.web.bind.annotation.RequestMethod 10 | import org.springframework.web.bind.annotation.RestController 11 | import java.util.* 12 | 13 | 14 | fun User.toJson(): JSONObject { 15 | val user = this 16 | val res = LinkedHashMap() 17 | res["id"] = user.id 18 | res["username"] = user.username 19 | res["realName"] = user.realName 20 | res["uvaId"] = user.uvaId 21 | res["cfname"] = user.cfname 22 | res["vjname"] = user.vjname 23 | res["bcname"] = user.bcname 24 | res["hduName"] = user.hduName 25 | res["pojName"] = user.pojName 26 | res["major"] = user.major 27 | res["blogUrl"] = user.blogUrl 28 | res["type"] = user.type.toString() 29 | res["typeChs"] = user.type.toShortStr() 30 | return JSONObject(res) 31 | } 32 | 33 | @RestController 34 | @RequestMapping("/api/user") 35 | class UserApi( 36 | @Autowired val userService: UserService) { 37 | 38 | @RequestMapping(value = ["/{username}/detail"], 39 | method = [(RequestMethod.GET)], 40 | produces = ["text/html;charset=UTF-8"]) 41 | fun detail(@PathVariable username: String): String { 42 | return userService.getUserByUsername(username).toJson().toString() 43 | } 44 | 45 | @RequestMapping(value = ["/{userId}/detailById"], 46 | method = [(RequestMethod.GET)], 47 | produces = ["text/html;charset=UTF-8"]) 48 | fun detailById(@PathVariable userId: Int): String { 49 | return userService.getUserById(userId).toJson().toString() 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/AcmerInfoRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.ACMerInfo; 4 | import com.zzkun.model.OJContest; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by wzh on 2017/5/23. 11 | */ 12 | /* 13 | public interface AcmerInfoRepo extends JpaRepository{ 14 | @Override 15 | List findAll(); 16 | 17 | @Override 18 | List save(Iterable iterable); 19 | 20 | @Override 21 | void deleteAll(); 22 | } 23 | */ 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/AssignResultRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.AssignResult; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by kun on 2016/7/14. 12 | */ 13 | public interface AssignResultRepo extends JpaRepository { 14 | @Override 15 | List findAll(); 16 | 17 | @Override 18 | AssignResult findOne(Integer integer); 19 | 20 | @Override 21 | long count(); 22 | 23 | @Override 24 | void delete(Integer integer); 25 | 26 | @Override 27 | S save(S entity); 28 | 29 | @Override 30 | Page findAll(Pageable pageable); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/BCUserInfoRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.BCUserInfo; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by kun on 2016/8/10. 10 | */ 11 | public interface BCUserInfoRepo extends JpaRepository { 12 | @Override 13 | List findAll(); 14 | 15 | @Override 16 | List save(Iterable iterable); 17 | 18 | @Override 19 | S save(S s); 20 | 21 | @Override 22 | BCUserInfo findOne(String s); 23 | 24 | @Override 25 | void delete(String s); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/CFUserInfoRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.CFUserInfo; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Administrator on 2016/8/5. 10 | */ 11 | public interface CFUserInfoRepo extends JpaRepository { 12 | @Override 13 | List findAll(); 14 | 15 | @Override 16 | S save(S entity); 17 | 18 | @Override 19 | CFUserInfo findOne(String integer); 20 | 21 | @Override 22 | List save(Iterable iterable); 23 | 24 | @Override 25 | long count(); 26 | 27 | @Override 28 | void delete(String integer); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/ContestRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Contest; 4 | import org.springframework.data.domain.Example; 5 | import org.springframework.data.jpa.domain.Specification; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by kun on 2016/7/13. 13 | */ 14 | public interface ContestRepo 15 | extends JpaRepository, JpaSpecificationExecutor { 16 | @Override 17 | List findAll(); 18 | 19 | @Override 20 | Contest findOne(Integer integer); 21 | 22 | @Override 23 | S save(S entity); 24 | 25 | @Override 26 | void delete(Integer integer); 27 | 28 | @Override 29 | long count(); 30 | 31 | @Override 32 | List findAll(Specification spec); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/CptTreeRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.CptTree; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Administrator on 2017/2/23 0023. 10 | */ 11 | public interface CptTreeRepo extends JpaRepository { 12 | 13 | @Override 14 | List findAll(); 15 | 16 | @Override 17 | S save(S s); 18 | 19 | @Override 20 | CptTree findOne(Integer integer); 21 | 22 | @Override 23 | long count(); 24 | 25 | @Override 26 | void deleteAll(); 27 | 28 | CptTree findByName(String name); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/ExtOjLinkRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.ExtOjLink; 4 | import com.zzkun.model.OJType; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by kun on 2016/10/31. 11 | */ 12 | public interface ExtOjLinkRepo extends JpaRepository { 13 | 14 | @Override 15 | List findAll(); 16 | 17 | @Override 18 | ExtOjLink findOne(OJType ojType); 19 | 20 | @Override 21 | long count(); 22 | 23 | @Override 24 | S save(S s); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/ExtOjPbInfoRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.ExtOjPbInfo; 4 | import com.zzkun.model.OJType; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by kun on 2016/10/15. 11 | */ 12 | public interface ExtOjPbInfoRepo extends JpaRepository { 13 | @Override 14 | List findAll(); 15 | 16 | @Override 17 | List save(Iterable iterable); 18 | 19 | @Override 20 | S save(S s); 21 | 22 | @Override 23 | ExtOjPbInfo findOne(Long aLong); 24 | 25 | ExtOjPbInfo findByOjNameAndPid(OJType ojName, String pid); 26 | 27 | ExtOjPbInfo findByOjNameAndNum(OJType ojName, String num); 28 | 29 | List findByOjName(OJType ojName); 30 | 31 | @Override 32 | void deleteAll(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/FixedTeamRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.FixedTeam; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Administrator on 2016/7/30. 10 | */ 11 | public interface FixedTeamRepo extends JpaRepository { 12 | 13 | @Override 14 | List findAll(); 15 | 16 | @Override 17 | List save(Iterable iterable); 18 | 19 | @Override 20 | S save(S entity); 21 | 22 | @Override 23 | FixedTeam findOne(Integer integer); 24 | 25 | @Override 26 | long count(); 27 | 28 | @Override 29 | void delete(Integer integer); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/OJContestRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.OJContest; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by kun on 2016/8/7. 10 | */ 11 | public interface OJContestRepo extends JpaRepository { 12 | 13 | @Override 14 | List findAll(); 15 | 16 | @Override 17 | List save(Iterable iterable); 18 | 19 | @Override 20 | void deleteAll(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/RatingRecordRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.RatingRecord; 4 | import org.springframework.data.domain.Example; 5 | import org.springframework.data.jpa.domain.Specification; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by kun on 2016/8/13. 13 | */ 14 | public interface RatingRecordRepo 15 | extends JpaRepository, JpaSpecificationExecutor { 16 | @Override 17 | List findAll(); 18 | 19 | @Override 20 | List save(Iterable iterable); 21 | 22 | @Override 23 | void deleteInBatch(Iterable iterable); 24 | 25 | @Override 26 | void delete(Iterable entities); 27 | 28 | @Override 29 | S save(S entity); 30 | 31 | @Override 32 | RatingRecord findOne(Long integer); 33 | 34 | @Override 35 | RatingRecord findOne(Specification spec); 36 | 37 | @Override 38 | List findAll(Specification spec); 39 | 40 | @Override 41 | long count(Specification spec); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/StageRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Stage; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by kun on 2016/7/13. 11 | */ 12 | public interface StageRepo extends JpaRepository { 13 | 14 | @Override 15 | List findAll(); 16 | 17 | @Override 18 | S save(S entity); 19 | 20 | @Override 21 | Stage findOne(Integer integer); 22 | 23 | @Override 24 | long count(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/SystemStateRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.SystemState; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.time.LocalDate; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Administrator on 2017/2/21 0021. 11 | */ 12 | public interface SystemStateRepo extends JpaRepository { 13 | 14 | @Override 15 | List findAll(); 16 | 17 | @Override 18 | S save(S s); 19 | 20 | @Override 21 | SystemState findOne(LocalDate localDate); 22 | 23 | @Override 24 | long count(); 25 | 26 | @Override 27 | void delete(LocalDate localDate); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/TrainingRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Training; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Administrator on 2016/7/20. 10 | */ 11 | public interface TrainingRepo extends JpaRepository { 12 | @Override 13 | S save(S s); 14 | 15 | @Override 16 | Training findOne(Integer integer); 17 | 18 | @Override 19 | List findAll(); 20 | 21 | @Override 22 | void delete(Integer integer); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/UJoinTRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Training; 4 | import com.zzkun.model.UJoinT; 5 | import com.zzkun.model.User; 6 | import org.springframework.data.domain.Example; 7 | import org.springframework.data.jpa.repository.JpaRepository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Administrator on 2016/7/21. 13 | */ 14 | public interface UJoinTRepo extends JpaRepository { 15 | 16 | @Override 17 | S save(S s); 18 | 19 | @Override 20 | UJoinT findOne(Integer integer); 21 | 22 | UJoinT findByUserAndTraining(User user, Training training); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/UserACPbRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.OJType; 4 | import com.zzkun.model.User; 5 | import com.zzkun.model.UserACPb; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by kun on 16-9-11. 12 | */ 13 | public interface UserACPbRepo extends JpaRepository { 14 | 15 | @Override 16 | List findAll(); 17 | 18 | 19 | // List findByUserAndOjName(User user, OJType ojName); 20 | 21 | @Override 22 | List save(Iterable iterable); 23 | 24 | @Override 25 | S save(S s); 26 | 27 | @Override 28 | UserACPb findOne(Long aLong); 29 | 30 | @Override 31 | long count(); 32 | 33 | @Override 34 | void deleteAll(); 35 | 36 | List findByUser(User user); 37 | 38 | long countByOjNameAndOjPbId(OJType ojName, String ojPbId); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/dao/UserRepo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by kun on 2016/7/6. 10 | */ 11 | public interface UserRepo extends JpaRepository { 12 | 13 | @Override 14 | List findAll(); 15 | 16 | @Override 17 | User findOne(Integer integer); 18 | 19 | @Override 20 | long count(); 21 | 22 | @Override 23 | S save(S entity); 24 | 25 | @Override 26 | List save(Iterable iterable); 27 | 28 | User findByUsername(String username); 29 | 30 | User findByVjname(String vjname); 31 | 32 | User findByBcname(String bcname); 33 | 34 | User findByUvaId(Integer uvaid); 35 | 36 | User findByRealName(String realName); 37 | 38 | @Override 39 | List findAll(Iterable iterable); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/ACMerInfo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | /** 4 | * Created by wzh on 2017/5/23. 5 | */ 6 | public class ACMerInfo { 7 | private String name; 8 | private String work; 9 | private String major; 10 | 11 | public String getMajor() { 12 | return major; 13 | } 14 | 15 | public String getWork() { 16 | return work; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setWork(String work) { 24 | this.work = work; 25 | } 26 | 27 | public void setMajor(String major) { 28 | this.major = major; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/AssignResult.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | import java.time.LocalDate; 6 | import java.util.*; 7 | 8 | /** 9 | * 随机分队结果 10 | * Created by kun on 2016/7/14. 11 | */ 12 | @Entity 13 | @Table(name = "assign_result") 14 | public class AssignResult implements Serializable { 15 | 16 | public enum Type { 17 | RANDOM, 18 | NoRepeat 19 | } 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Integer id; 24 | 25 | private LocalDate date = LocalDate.now(); 26 | 27 | @Lob 28 | private ArrayList> teamList = new ArrayList<>(); 29 | 30 | @Lob 31 | private ArrayList accountList = new ArrayList<>(); 32 | 33 | @Enumerated(EnumType.STRING) 34 | private Type type; 35 | 36 | @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) 37 | @JoinColumn(name = "trainingId") 38 | private Training training; 39 | 40 | public AssignResult() { 41 | } 42 | 43 | public Integer getId() { 44 | return id; 45 | } 46 | 47 | public void setId(Integer id) { 48 | this.id = id; 49 | } 50 | 51 | public LocalDate getDate() { 52 | return date; 53 | } 54 | 55 | public void setDate(LocalDate date) { 56 | this.date = date; 57 | } 58 | 59 | public ArrayList> getTeamList() { 60 | return teamList; 61 | } 62 | 63 | public void setTeamList(ArrayList> teamList) { 64 | this.teamList = teamList; 65 | } 66 | 67 | public Type getType() { 68 | return type; 69 | } 70 | 71 | public void setType(Type type) { 72 | this.type = type; 73 | } 74 | 75 | public ArrayList getAccountList() { 76 | return accountList; 77 | } 78 | 79 | public void setAccountList(ArrayList accountList) { 80 | this.accountList = accountList; 81 | } 82 | 83 | public Training getTraining() { 84 | return training; 85 | } 86 | 87 | public void setTraining(Training training) { 88 | this.training = training; 89 | } 90 | 91 | public void setAccount(Integer pos, String account) { 92 | if(pos >= teamList.size()) return; 93 | if(accountList == null) 94 | accountList = new ArrayList<>(); 95 | while(accountList.size() < teamList.size()) 96 | accountList.add(""); 97 | accountList.set(pos, account); 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return "AssignResult{" + 103 | "id=" + id + 104 | ", date=" + date + 105 | ", teamList=" + teamList + 106 | ", accountList=" + accountList + 107 | ", type=" + type + 108 | ", training=" + training + 109 | '}'; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/BCUserInfo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | import java.time.LocalDateTime; 7 | 8 | /** 9 | * Created by kun on 2016/8/9. 10 | */ 11 | @Entity 12 | @Table(name = "bc_user_info") 13 | public class BCUserInfo { 14 | 15 | @Id 16 | private String bcname; 17 | 18 | private Integer rating; 19 | 20 | private LocalDateTime updateTime; 21 | 22 | public BCUserInfo() { 23 | } 24 | 25 | public BCUserInfo(String bcname, Integer rating) { 26 | this.bcname = bcname; 27 | this.rating = rating; 28 | updateTime = LocalDateTime.now(); 29 | } 30 | 31 | public String getBcname() { 32 | return bcname; 33 | } 34 | 35 | public void setBcname(String bcname) { 36 | this.bcname = bcname; 37 | } 38 | 39 | public Integer getRating() { 40 | return rating; 41 | } 42 | 43 | public void setRating(Integer rating) { 44 | this.rating = rating; 45 | updateTime = LocalDateTime.now(); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "BCUserInfo{" + 51 | "bcname='" + bcname + '\'' + 52 | ", rating=" + rating + 53 | ", updateTime=" + updateTime + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/CFUserInfo.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by Administrator on 2016/7/31. 10 | */ 11 | @Entity 12 | @Table(name = "cf_user_info") 13 | public class CFUserInfo implements Serializable { 14 | 15 | @Id 16 | private String cfname; 17 | 18 | private Integer rating; 19 | 20 | private Integer maxRating; 21 | 22 | private String rank; 23 | 24 | private String maxRank; 25 | 26 | public CFUserInfo() { 27 | } 28 | 29 | public CFUserInfo(String cfname, Integer rating, Integer maxRating, String rank, String maxRank) { 30 | this.cfname = cfname; 31 | this.rating = rating; 32 | this.maxRating = maxRating; 33 | this.rank = rank; 34 | this.maxRank = maxRank; 35 | } 36 | 37 | public String getCfname() { 38 | return cfname; 39 | } 40 | 41 | public void setCfname(String cfname) { 42 | this.cfname = cfname; 43 | } 44 | 45 | public Integer getRating() { 46 | return rating; 47 | } 48 | 49 | public void setRating(Integer rating) { 50 | this.rating = rating; 51 | } 52 | 53 | public Integer getMaxRating() { 54 | return maxRating; 55 | } 56 | 57 | public void setMaxRating(Integer maxRating) { 58 | this.maxRating = maxRating; 59 | } 60 | 61 | public String getRank() { 62 | return rank; 63 | } 64 | 65 | public void setRank(String rank) { 66 | this.rank = rank; 67 | } 68 | 69 | public String getMaxRank() { 70 | return maxRank; 71 | } 72 | 73 | public void setMaxRank(String maxRank) { 74 | this.maxRank = maxRank; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CFUserInfo{" + 80 | "cfname='" + cfname + '\'' + 81 | ", rating=" + rating + 82 | ", maxRating=" + maxRating + 83 | ", rank='" + rank + '\'' + 84 | ", maxRank='" + maxRank + '\'' + 85 | '}'; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/ExtOjLink.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * Created by kun on 2016/10/31. 8 | */ 9 | @Entity 10 | @Table(name = "extoj_link") 11 | public class ExtOjLink implements Serializable { 12 | 13 | @Id 14 | @Enumerated(value = EnumType.STRING) 15 | private OJType oj; 16 | 17 | @Column(length = 1024) 18 | private String indexLink; 19 | 20 | @Column(length = 1024) 21 | private String userInfoLink; 22 | 23 | @Column(length = 1024) 24 | private String pbStatusLink; 25 | 26 | @Column(length = 1024) 27 | private String problemLink; 28 | 29 | public ExtOjLink() { 30 | } 31 | 32 | public OJType getOj() { 33 | return oj; 34 | } 35 | 36 | public void setOj(OJType oj) { 37 | this.oj = oj; 38 | } 39 | 40 | public String getIndexLink() { 41 | return indexLink; 42 | } 43 | 44 | public void setIndexLink(String indexLink) { 45 | this.indexLink = indexLink; 46 | } 47 | 48 | public String getUserInfoLink() { 49 | return userInfoLink; 50 | } 51 | 52 | public void setUserInfoLink(String userInfoLink) { 53 | this.userInfoLink = userInfoLink; 54 | } 55 | 56 | public String getPbStatusLink() { 57 | return pbStatusLink; 58 | } 59 | 60 | public void setPbStatusLink(String pbStatusLink) { 61 | this.pbStatusLink = pbStatusLink; 62 | } 63 | 64 | public String getProblemLink() { 65 | return problemLink; 66 | } 67 | 68 | public void setProblemLink(String problemLink) { 69 | this.problemLink = problemLink; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "ExtOjLink{" + 75 | "oj=" + oj + 76 | ", indexLink='" + indexLink + '\'' + 77 | ", userInfoLink='" + userInfoLink + '\'' + 78 | ", pbStatusLink='" + pbStatusLink + '\'' + 79 | ", problemLink='" + problemLink + '\'' + 80 | '}'; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/OJContest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | 7 | /** 8 | * acmicpc info 网站上的近期oj比赛 9 | * Created by Administrator on 2016/8/3. 10 | */ 11 | @Entity 12 | @Table(name = "oj_contest") 13 | public class OJContest { 14 | 15 | @Id 16 | private Integer id; 17 | 18 | private String oj; 19 | private String link; 20 | private String name; 21 | private String start_time; 22 | private String week; 23 | private String access; 24 | 25 | public Integer getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Integer id) { 30 | this.id = id; 31 | } 32 | 33 | public String getOj() { 34 | return oj; 35 | } 36 | 37 | public void setOj(String oj) { 38 | this.oj = oj; 39 | } 40 | 41 | public String getLink() { 42 | return link; 43 | } 44 | 45 | public void setLink(String link) { 46 | this.link = link; 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public void setName(String name) { 54 | this.name = name; 55 | } 56 | 57 | public String getStart_time() { 58 | return start_time; 59 | } 60 | 61 | public void setStart_time(String start_time) { 62 | this.start_time = start_time; 63 | } 64 | 65 | public String getWeek() { 66 | return week; 67 | } 68 | 69 | public void setWeek(String week) { 70 | this.week = week; 71 | } 72 | 73 | public String getAccess() { 74 | return access; 75 | } 76 | 77 | public void setAccess(String access) { 78 | this.access = access; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "OJContest{" + 84 | "id=" + id + 85 | ", oj='" + oj + '\'' + 86 | ", link='" + link + '\'' + 87 | ", name='" + name + '\'' + 88 | ", start_time='" + start_time + '\'' + 89 | ", week='" + week + '\'' + 90 | ", access='" + access + '\'' + 91 | '}'; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/OJType.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | /** 4 | * Created by kun on 2016/10/15. 5 | */ 6 | public enum OJType { 7 | POJ, 8 | ZOJ, 9 | UVALive, 10 | SGU, 11 | URAL, 12 | HUST, 13 | SPOJ, 14 | HDU, 15 | HYSBZ, 16 | UVA, 17 | CodeForces, 18 | Aizu, 19 | LightOJ, 20 | UESTC, 21 | NBUT, 22 | FZU, 23 | CSU, 24 | SCU, 25 | ACdream, 26 | CodeChef, 27 | Gym, 28 | OpenJudge, 29 | HihoCoder, 30 | UESTC_old, 31 | 32 | Null, 33 | SUM, 34 | Vjudge, 35 | OpenJ_Bailian 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/PbStatus.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 题目的一个人解题情况 7 | * Created by Administrator on 2016/6/27. 8 | */ 9 | public class PbStatus implements Serializable, Comparable { 10 | 11 | private static final long serialVersionUID = 8822201624970861661L; 12 | 13 | private boolean solved; 14 | private int time; 15 | private int waCount; 16 | 17 | public PbStatus(boolean solved, int time, int waCount) { 18 | this.solved = solved; 19 | this.time = time; 20 | this.waCount = waCount; 21 | } 22 | 23 | public boolean isSolved() { 24 | return solved; 25 | } 26 | 27 | public void setSolved(boolean solved) { 28 | this.solved = solved; 29 | } 30 | 31 | public int getTime() { 32 | return time; 33 | } 34 | 35 | public void setTime(int time) { 36 | this.time = time; 37 | } 38 | 39 | public int getWaCount() { 40 | return waCount; 41 | } 42 | 43 | public void setWaCount(int waCount) { 44 | this.waCount = waCount; 45 | } 46 | 47 | public int calcPenalty() { 48 | if(!isSolved()) return 0; 49 | return time + 1200 * waCount + 600 * (waCount) * (waCount - 1) / 2; 50 | } 51 | 52 | private static String getHTime(int time) { 53 | int s = time % 60; 54 | time /= 60; 55 | int m = time % 60; 56 | time /= 60; 57 | int h = time; 58 | return String.format("%d:%02d:%02d", h, m, s); 59 | } 60 | 61 | public String toHString() { 62 | String s = ""; 63 | if(solved) { 64 | s += getHTime(time); 65 | if(waCount > 0) 66 | s += " (-" + waCount + ")"; 67 | } else { 68 | if(waCount > 0) 69 | s += " (-" + waCount + ")"; 70 | } 71 | return s; 72 | } 73 | 74 | 75 | @Override 76 | public String toString() { 77 | return "PbStatus{" + 78 | "solved=" + solved + 79 | ", time=" + time + 80 | ", waCount=" + waCount + 81 | '}'; 82 | } 83 | 84 | @Override 85 | public int compareTo(PbStatus o) { 86 | if(waCount != o.waCount) 87 | return Integer.compare(waCount, o.waCount); 88 | return Integer.compare(o.time, time); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/SystemState.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | import java.io.Serializable; 7 | import java.time.LocalDate; 8 | 9 | /** 10 | * Created by Administrator on 2017/2/21 0021. 11 | */ 12 | @Entity 13 | @Table(name = "system_state") 14 | public class SystemState implements Serializable { 15 | 16 | @Id 17 | private LocalDate date; 18 | 19 | private Long userCount; 20 | 21 | private Long sumACCount; 22 | 23 | private Long sumContestCount; 24 | 25 | public SystemState() { 26 | } 27 | 28 | public SystemState(LocalDate date, Long userCount, Long sumACCount, Long sumContestCount) { 29 | this.date = date; 30 | this.userCount = userCount; 31 | this.sumACCount = sumACCount; 32 | this.sumContestCount = sumContestCount; 33 | } 34 | 35 | public LocalDate getDate() { 36 | return date; 37 | } 38 | 39 | public void setDate(LocalDate date) { 40 | this.date = date; 41 | } 42 | 43 | public Long getUserCount() { 44 | return userCount; 45 | } 46 | 47 | public void setUserCount(Long userCount) { 48 | this.userCount = userCount; 49 | } 50 | 51 | public Long getSumACCount() { 52 | return sumACCount; 53 | } 54 | 55 | public void setSumACCount(Long sumACCount) { 56 | this.sumACCount = sumACCount; 57 | } 58 | 59 | public Long getSumContestCount() { 60 | return sumContestCount; 61 | } 62 | 63 | public void setSumContestCount(Long sumContestCount) { 64 | this.sumContestCount = sumContestCount; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "SystemState{" + 70 | "date=" + date + 71 | ", userCount=" + userCount + 72 | ", sumACCount=" + sumACCount + 73 | ", sumContestCount=" + sumContestCount + 74 | '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/UJoinT.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import org.hibernate.annotations.GenericGenerator; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by Administrator on 2016/7/21. 10 | */ 11 | @Entity 12 | @Table(name = "user_join_training") 13 | public class UJoinT implements Serializable { 14 | 15 | public enum Status { 16 | Pending, Success, Reject 17 | } 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private Integer id; 22 | 23 | @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) 24 | @JoinColumn(name = "userId") 25 | private User user; 26 | 27 | @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) 28 | @JoinColumn(name = "trainingId") 29 | private Training training; 30 | 31 | @Enumerated(value = EnumType.STRING) 32 | private Status status; 33 | 34 | public UJoinT() { 35 | } 36 | 37 | public UJoinT(User user, Training training, Status status) { 38 | this.user = user; 39 | this.training = training; 40 | this.status = status; 41 | } 42 | 43 | public Integer getId() { 44 | return id; 45 | } 46 | 47 | public void setId(Integer id) { 48 | this.id = id; 49 | } 50 | 51 | public User getUser() { 52 | return user; 53 | } 54 | 55 | public void setUser(User user) { 56 | this.user = user; 57 | } 58 | 59 | public Training getTraining() { 60 | return training; 61 | } 62 | 63 | public void setTraining(Training training) { 64 | this.training = training; 65 | } 66 | 67 | public Status getStatus() { 68 | return status; 69 | } 70 | 71 | public void setStatus(Status status) { 72 | this.status = status; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "UJoinT{" + 78 | "id=" + id + 79 | ", user=" + user + 80 | ", training=" + training + 81 | ", status=" + status + 82 | '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/model/UserACPb.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.model; 2 | 3 | import org.apache.commons.lang3.builder.CompareToBuilder; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by kun on 2016/9/29. 11 | */ 12 | @Entity 13 | @Table(name = "user_ac_pb") 14 | public class UserACPb implements Serializable, Comparable { 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | 20 | @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) 21 | @JoinColumn(name = "userId") 22 | private User user; 23 | 24 | @Enumerated(EnumType.STRING) 25 | private OJType ojName; 26 | 27 | private String ojPbId; //存的是ExtOjPbInfo的num 28 | 29 | ///------- 30 | 31 | 32 | public UserACPb() { 33 | } 34 | 35 | public Long getId() { 36 | return id; 37 | } 38 | 39 | public void setId(Long id) { 40 | this.id = id; 41 | } 42 | 43 | public User getUser() { 44 | return user; 45 | } 46 | 47 | public void setUser(User user) { 48 | this.user = user; 49 | } 50 | 51 | public OJType getOjName() { 52 | return ojName; 53 | } 54 | 55 | public void setOjName(OJType ojName) { 56 | this.ojName = ojName; 57 | } 58 | 59 | public String getOjPbId() { 60 | return ojPbId; 61 | } 62 | 63 | public void setOjPbId(String ojPbId) { 64 | this.ojPbId = ojPbId; 65 | } 66 | 67 | public UserACPb(User user, OJType ojName, String ojPbId) { 68 | this.user = user; 69 | this.ojName = ojName; 70 | this.ojPbId = ojPbId; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return "UserACPb{" + 76 | "id=" + id + 77 | ", userId=" + user.getId() + 78 | ", ojName=" + ojName + 79 | ", ojPbId='" + ojPbId + '\'' + 80 | '}'; 81 | } 82 | 83 | //--------------- 84 | 85 | @Override 86 | public int compareTo(@NotNull UserACPb o) { 87 | return new CompareToBuilder() 88 | .append(user, o.user) 89 | .append(ojName, o.ojName) 90 | .append(ojPbId, o.ojPbId) 91 | .toComparison(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/ContestSearchService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service 2 | 3 | import com.zzkun.dao.ContestRepo 4 | import com.zzkun.model.Contest 5 | import org.slf4j.LoggerFactory 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.stereotype.Service 8 | import java.util.* 9 | import java.util.regex.Pattern 10 | 11 | /** 12 | * Created by kun36 on 2016/12/29. 13 | */ 14 | @Service 15 | open class ContestSearchService { 16 | 17 | companion object { 18 | private val logger = LoggerFactory.getLogger(ContestSearchService::class.java) 19 | private val splitPattern = Pattern.compile(";|,|,|;|\\s+") 20 | } 21 | 22 | @Autowired lateinit private var contestRepo : ContestRepo 23 | 24 | fun splitParms(str: String): List { 25 | return str.split(splitPattern) 26 | .filter(String::isNotBlank) 27 | .map(String::trim) 28 | } 29 | 30 | fun find(qu: String): List { 31 | val parms = splitParms(qu) 32 | val keys = HashMap() 33 | contestRepo.findAll().forEach { 34 | keys[it.id] = "${it.name}|${it.source}|${it.sourceDetail}|${it.sourceUrl}" 35 | if(it.id == 142) 36 | println(keys[it.id]) 37 | } 38 | val ok = ArrayList() 39 | for ((key, value) in keys) { 40 | val flag = parms.all { value.contains(it, true) } 41 | if(flag) 42 | ok.add(key) 43 | } 44 | return ok.reversed() 45 | .map { contestRepo.findOne(it) } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/OJContestService.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.service; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.zzkun.dao.OJContestRepo; 7 | import com.zzkun.model.OJContest; 8 | import com.zzkun.util.web.HttpUtil; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Comparator; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by Administrator on 2016/8/3. 20 | */ 21 | @Service 22 | public class OJContestService { 23 | 24 | private static final Logger logger = LoggerFactory.getLogger(OJContestService.class); 25 | 26 | @Autowired private HttpUtil httpUtil; 27 | @Autowired private OJContestRepo ojContestRepo; 28 | 29 | private List getWebDate() { 30 | List list = new ArrayList<>(); 31 | try { 32 | String str = httpUtil.readURL("http://contests.acmicpc.info/contests.json"); 33 | JSONArray array = JSON.parseArray(str); 34 | for(int i = 0; i < array.size(); ++i) { 35 | JSONObject object = array.getJSONObject(i); 36 | OJContest contest = new OJContest(); 37 | contest.setId(object.getInteger("id")); 38 | contest.setAccess(object.getString("access")); 39 | contest.setLink(object.getString("link")); 40 | contest.setName(object.getString("name")); 41 | contest.setOj(object.getString("oj")); 42 | contest.setStart_time(object.getString("start_time")); 43 | contest.setWeek(object.getString("week")); 44 | list.add(contest); 45 | } 46 | return list; 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | return list; 51 | } 52 | 53 | public synchronized void flushOJContests() { 54 | logger.info("开始更新近期比赛..."); 55 | List webDate = getWebDate(); 56 | if(webDate == null || webDate.isEmpty()) 57 | return; 58 | ojContestRepo.deleteAll(); 59 | ojContestRepo.save(webDate); 60 | } 61 | 62 | public List getRecents() { 63 | List all = ojContestRepo.findAll(); 64 | all.sort(Comparator.comparing(OJContest::getStart_time)); 65 | return all; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/SystemService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service 2 | 3 | import com.zzkun.dao.ContestRepo 4 | import com.zzkun.dao.SystemStateRepo 5 | import com.zzkun.dao.UserACPbRepo 6 | import com.zzkun.dao.UserRepo 7 | import com.zzkun.model.SystemState 8 | import org.slf4j.LoggerFactory 9 | import org.springframework.beans.factory.annotation.Autowired 10 | import org.springframework.stereotype.Service 11 | import java.time.LocalDate 12 | 13 | /** 14 | * Created by Administrator on 2017/2/21 0021. 15 | */ 16 | @Service 17 | class SystemService( 18 | @Autowired private val systemStateRepo: SystemStateRepo, 19 | @Autowired private val userRepo: UserRepo, 20 | @Autowired private val contestRepo: ContestRepo, 21 | @Autowired private val userACPbRepo: UserACPbRepo) { 22 | 23 | companion object { 24 | private val logger = LoggerFactory.getLogger(SystemService::class.java) 25 | } 26 | 27 | private fun curState(): SystemState { 28 | return SystemState( 29 | LocalDate.now(), 30 | userRepo.count(), 31 | userACPbRepo.count(), 32 | contestRepo.count() 33 | ) 34 | } 35 | 36 | fun saveCurState() { 37 | val cur = curState() 38 | systemStateRepo.save(cur) 39 | logger.info("保存当前系统状态${cur}") 40 | } 41 | 42 | fun stateHistory(): List { 43 | return systemStateRepo 44 | .findAll() 45 | .sortedBy { it.date } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/extoj/CFService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.ExtOjLinkRepo 4 | import com.zzkun.model.* 5 | import com.zzkun.util.web.CFWebGetter 6 | import org.slf4j.LoggerFactory 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.stereotype.Service 9 | 10 | 11 | @Service 12 | class CFService : IExtOJAdapter { 13 | 14 | companion object { 15 | private val logger = LoggerFactory.getLogger(CFService::class.java) 16 | } 17 | 18 | @Autowired lateinit var cfWebGetter : CFWebGetter 19 | @Autowired lateinit var extOjLinkRepo: ExtOjLinkRepo 20 | 21 | override fun getOjLink(): ExtOjLink { 22 | return extOjLinkRepo.findOne(getOjType()) 23 | } 24 | 25 | override fun getOjType(): OJType { 26 | return OJType.CodeForces 27 | } 28 | 29 | override fun getUserACPbsOnline(user: User, link: String): List { 30 | val acPbs = cfWebGetter.userACPbs(user.cfname, link) 31 | return acPbs.map { UserACPb(user, OJType.CodeForces, it) } .toList() 32 | } 33 | 34 | override fun getAllPbInfoOnline(link: String): List { 35 | return emptyList() 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/extoj/HDUService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.ExtOjLinkRepo 4 | import com.zzkun.model.* 5 | import com.zzkun.util.web.HDUWebGetter 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.stereotype.Service 8 | 9 | 10 | @Service 11 | open class HDUService : IExtOJAdapter { 12 | 13 | @Autowired lateinit var hduWebGetter : HDUWebGetter 14 | @Autowired lateinit var extOjLinkRepo: ExtOjLinkRepo 15 | 16 | override fun getOjType(): OJType { 17 | return OJType.HDU 18 | } 19 | 20 | override fun getOjLink(): ExtOjLink { 21 | return extOjLinkRepo.findOne(getOjType()) 22 | } 23 | 24 | override fun getUserACPbsOnline(user: User, link: String): List { 25 | val acPbs = hduWebGetter.userACPbs(user.hduName, link) 26 | return acPbs.map { UserACPb(user, OJType.HDU, it) } .toList() 27 | } 28 | 29 | override fun getAllPbInfoOnline(link: String): List { 30 | return hduWebGetter.allPbInfo(link) 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/extoj/IExtOJAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.model.* 4 | 5 | interface IExtOJAdapter { 6 | /** 7 | * 在线获取某用户本OJ所有AC的题目 8 | */ 9 | fun getUserACPbsOnline(user: User, link: String): List 10 | 11 | /** 12 | * 在线获取某用户本OJ所有题目信息 13 | */ 14 | fun getAllPbInfoOnline(link: String): List 15 | 16 | /** 17 | * 从数据库中读取oj链接 18 | */ 19 | fun getOjLink(): ExtOjLink 20 | 21 | fun getOjType(): OJType 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/extoj/POJService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.ExtOjLinkRepo 4 | import com.zzkun.model.* 5 | import com.zzkun.util.web.POJWebGetter 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.stereotype.Service 8 | 9 | /** 10 | * Created by kun on 2016/10/20. 11 | */ 12 | @Service 13 | class POJService : IExtOJAdapter { 14 | 15 | @Autowired lateinit var pojWebGetter: POJWebGetter 16 | @Autowired lateinit var extOjLinkRepo: ExtOjLinkRepo 17 | 18 | override fun getOjType(): OJType { 19 | return OJType.POJ 20 | } 21 | 22 | override fun getOjLink(): ExtOjLink { 23 | return extOjLinkRepo.findOne(getOjType()) 24 | } 25 | 26 | 27 | override fun getUserACPbsOnline(user: User, link: String): List { 28 | val acPbs = pojWebGetter.userACPbs(user.pojName, link) 29 | return acPbs.map { UserACPb(user, OJType.POJ, it) } .toList() 30 | } 31 | 32 | override fun getAllPbInfoOnline(link: String): List { 33 | return pojWebGetter.allPbInfo(link) 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/extoj/UVaService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.ExtOjLinkRepo 4 | import com.zzkun.model.* 5 | import com.zzkun.util.uhunt.UHuntAnalyser 6 | import com.zzkun.util.web.UHuntWebGetter 7 | import org.slf4j.LoggerFactory 8 | import org.springframework.beans.factory.annotation.Autowired 9 | import org.springframework.stereotype.Service 10 | 11 | /** 12 | * Created by kun on 2016/9/29. 13 | */ 14 | @Service 15 | open class UVaService : IExtOJAdapter { 16 | 17 | 18 | companion object { 19 | private val logger = LoggerFactory.getLogger(UVaService::class.java) 20 | } 21 | 22 | @Autowired lateinit var uHuntWebGetter: UHuntWebGetter 23 | @Autowired lateinit var uhuntAnalyser : UHuntAnalyser 24 | @Autowired lateinit var extOjLinkRepo: ExtOjLinkRepo 25 | 26 | override fun getOjType(): OJType { 27 | return OJType.UVA 28 | } 29 | 30 | override fun getOjLink(): ExtOjLink { 31 | return extOjLinkRepo.findOne(getOjType()) 32 | } 33 | 34 | 35 | override fun getUserACPbsOnline(user: User, link: String): List { 36 | try { 37 | val list = uHuntWebGetter.userACSubmits(user.uvaId, link) 38 | return list.map { UserACPb(user, OJType.UVA, uhuntAnalyser.pidToNum(it.toString())) } 39 | } catch(e: Exception) { 40 | e.printStackTrace() 41 | } 42 | return emptyList() 43 | } 44 | 45 | override fun getAllPbInfoOnline(link: String): List { 46 | return uHuntWebGetter.allPbInfo() ?: uHuntWebGetter.allPbInfo2(link) 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/service/extoj/VJudgeService.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.ExtOjLinkRepo 4 | import com.zzkun.model.* 5 | import com.zzkun.util.web.VJudgeWebGetter 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.stereotype.Service 8 | 9 | @Service 10 | open class VJudgeService : IExtOJAdapter { 11 | 12 | @Autowired lateinit var vjudgeWebGetter : VJudgeWebGetter 13 | @Autowired lateinit var extOjLinkRepo: ExtOjLinkRepo 14 | 15 | override fun getOjType(): OJType { 16 | return OJType.Vjudge 17 | } 18 | 19 | override fun getOjLink(): ExtOjLink { 20 | return extOjLinkRepo.findOne(getOjType()) 21 | } 22 | 23 | override fun getUserACPbsOnline(user: User, link: String): List { 24 | try { 25 | val acMap = vjudgeWebGetter.getUserACMap(user.vjname, link) 26 | val res = arrayListOf() 27 | for((key, value) in acMap) { 28 | for(pbId in value) { 29 | val cur = try { UserACPb(user, OJType.valueOf(key), pbId) } catch (e: Exception) { null } 30 | if(cur != null) res.add(cur) 31 | } 32 | } 33 | return res 34 | } catch(e: Exception) { 35 | e.printStackTrace() 36 | } 37 | return emptyList() 38 | } 39 | 40 | override fun getAllPbInfoOnline(link: String): List { 41 | return emptyList() 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/cluster/AgnesClusterer.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.cluster; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.*; 7 | 8 | 9 | /** 10 | * Agnes聚类算法实现 11 | * Created by Administrator on 2016/8/4. 12 | */ 13 | public class AgnesClusterer { 14 | 15 | private static final Logger logger = LoggerFactory.getLogger(AgnesClusterer.class); 16 | 17 | private List> list = null; 18 | private List dis = null; 19 | 20 | /** 21 | * 构造函数 22 | * @param val 需要进行聚类的数组元数据 23 | */ 24 | public AgnesClusterer(final double[] val) { 25 | list = new ArrayList<>(); 26 | dis = new ArrayList<>(); 27 | double[] copyVal = Arrays.copyOf(val, val.length); 28 | Arrays.sort(copyVal); 29 | for(int i = 0; i < copyVal.length; ++i) { 30 | list.add(new ArrayList<>(Collections.singletonList(copyVal[i]))); 31 | if(i < val.length-1) 32 | dis.add(Math.abs(copyVal[i+1] - copyVal[i])); 33 | } 34 | } 35 | 36 | private void updateDis(int pos) { 37 | List disList = new ArrayList<>(); 38 | double sum = 0; 39 | for (Double a : list.get(pos)) 40 | for (Double b : list.get(pos + 1)) { 41 | disList.add(Math.abs(a - b)); 42 | sum += Math.abs(a - b); 43 | } 44 | double ans = disList.isEmpty() ? 0 : sum / disList.size(); 45 | dis.set(pos, ans); 46 | } 47 | 48 | public boolean clusterOne(double disLimit) { 49 | if(list.size() <= 1) 50 | return false; 51 | double minDis = Double.MAX_VALUE; 52 | int minPos = 0; 53 | for(int i = 0; i < dis.size(); ++i) { 54 | if(dis.get(i) < minDis) { 55 | minDis = dis.get(i); 56 | minPos = i; 57 | } 58 | } 59 | //logger.info("当前最小距离:{}", minDis); 60 | if(minDis > disLimit) { 61 | //logger.info("当前距离大于阈值{}", disLimit); 62 | return false; 63 | } 64 | list.get(minPos).addAll(list.get(minPos+1)); 65 | list.remove(minPos+1); 66 | dis.remove(minPos); 67 | if(minPos > 0) updateDis(minPos-1); 68 | if(minPos < list.size()-1) updateDis(minPos); 69 | //logger.info("单次聚类完成,剩余类数:{}", list.size()); 70 | //logger.info("当前结果:{}", list); 71 | return true; 72 | } 73 | 74 | 75 | public Map clusterWithLimit(double disLimit, boolean inv) { 76 | while(clusterOne(disLimit)); 77 | Map map = new HashMap<>(); 78 | for(int i = 0; i < list.size(); ++i) { 79 | for (Double val :list.get(i)) { 80 | map.put(val, inv ? (list.size()-i) : i + 1); 81 | } 82 | } 83 | return map; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/cpt/Node.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.cpt 2 | 3 | import com.alibaba.fastjson.JSON 4 | import java.util.* 5 | 6 | enum class NodeType { 7 | LEAF, LIST 8 | } 9 | 10 | class Node( 11 | val deep: Int, 12 | val id: Int, 13 | var name: String, 14 | val type: NodeType) : Comparable { 15 | 16 | var son: ArrayList = ArrayList() 17 | 18 | override fun compareTo(other: Node): Int { 19 | return id.compareTo(other.id) 20 | } 21 | 22 | override fun toString(): String { 23 | return "Node(deep=$deep, id=$id, name='$name', type=$type, son=$son)" 24 | } 25 | 26 | fun toJsonString(): String { 27 | return JSON.toJSONString(this) 28 | } 29 | 30 | private var pids: Set? = null 31 | 32 | fun allPids(): Set { 33 | if(pids != null) 34 | return pids!! 35 | val pids = HashSet() 36 | val qu = ArrayDeque() 37 | qu.addLast(this) 38 | while (qu.isNotEmpty()) { 39 | val cur = qu.pollFirst()!! 40 | if (cur.type == NodeType.LEAF) { 41 | pids.add(cur.name) 42 | continue 43 | } 44 | for (son in cur.son) 45 | qu.addLast(son) 46 | } 47 | this.pids = pids 48 | return pids 49 | } 50 | 51 | fun deepKSons(k: Int): List { 52 | val res = ArrayList() 53 | val qu = ArrayDeque() 54 | qu.addLast(this) 55 | while (qu.isNotEmpty()) { 56 | val cur = qu.pollFirst()!! 57 | if (cur.deep == this.deep + k) { 58 | res.add(cur) 59 | continue 60 | } 61 | for (son in cur.son) 62 | qu.addLast(son) 63 | } 64 | return res 65 | } 66 | 67 | fun findSon(id: Int): Node? { 68 | val qu = ArrayDeque() 69 | qu.addLast(this) 70 | while (qu.isNotEmpty()) { 71 | val cur = qu.pollFirst()!! 72 | if (cur.id == id) 73 | return cur 74 | for (son in cur.son) 75 | qu.addLast(son) 76 | } 77 | return null 78 | } 79 | 80 | fun deleteSon(id: Int): Node { 81 | val qu = ArrayDeque() 82 | qu.addLast(this) 83 | val deleted = false 84 | while (!deleted && qu.isNotEmpty()) { 85 | val cur = qu.pollFirst()!! 86 | for (son in cur.son) { 87 | if (son.id == id) { 88 | cur.son.remove(son) 89 | break 90 | } 91 | qu.addLast(son) 92 | } 93 | } 94 | return this 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/cpt/NodeBuilder.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.cpt 2 | 3 | import com.alibaba.fastjson.JSON 4 | import com.alibaba.fastjson.JSONObject 5 | import com.zzkun.model.OJType 6 | import java.util.* 7 | 8 | /** 9 | * 规则: 10 | * 不含表头,4列,英文逗号分隔无空格,分别为: 11 | * id:当前节点id;根节点必为0,且出现在第0行;保证id唯一 12 | * pid:父节点id;根节点的父节点为0;父节点需出现在子节点之前 13 | * name:当前节点名字,如章节名;若为叶节点(题目)则为题目编号(int) 14 | * type:类型;大写;叶节点(题目)为LEAF,其余为LIST 15 | */ 16 | fun parseCSV(txt: List): Node? { 17 | var root: Node? = null 18 | val id2Node = HashMap() 19 | for (s in txt) { 20 | if(s.isBlank()) 21 | continue 22 | 23 | val split = s.split(",") 24 | val id = split[0].trim().toInt() 25 | val pid = split[1].trim().toInt() 26 | val name = split[2].trim() 27 | val type = NodeType.valueOf(split[3].trim()) 28 | 29 | val pdeep = id2Node[pid]?.deep ?:-1 30 | val cur = Node(pdeep + 1, id, name, type) 31 | 32 | id2Node[pid]?.son?.add(cur) 33 | id2Node[id] = cur 34 | if(id == 0) 35 | root = cur 36 | } 37 | return root 38 | } 39 | 40 | fun parseJson(str: String?): Node? { 41 | try { 42 | return jsonDFS(JSON.parseObject(str)) 43 | } 44 | catch (e: Exception) { 45 | e.printStackTrace() 46 | return null 47 | } 48 | } 49 | 50 | private fun jsonDFS(json: JSONObject): Node? { 51 | val deep = json.getInteger("deep") 52 | val id = json.getInteger("id") 53 | val name = json.getString("name") 54 | val type = NodeType.valueOf(json.getString("type")) 55 | 56 | val res = Node(deep, id, name, type) 57 | if(type == NodeType.LEAF) 58 | return res 59 | val son = json.getJSONArray("son") 60 | if(son != null) { 61 | for (i in son.indices) 62 | res.son.add(jsonDFS(son.getJSONObject(i))!!) 63 | } 64 | return res 65 | } 66 | 67 | fun parsePids(ojType: OJType, list: List): Node { 68 | val root = Node(0, 0, ojType.toString(), NodeType.LIST) 69 | val map = TreeMap>() 70 | for (s in list) { 71 | val sb = StringBuilder() 72 | for (c in s) { 73 | if (c.isDigit()) sb.append(c) 74 | else break 75 | } 76 | val num = sb.toString().toInt() 77 | if (!map.contains(num / 100)) 78 | map[num / 100] = ArrayList() 79 | map[num / 100]?.add(sb.toString()) 80 | } 81 | var count = 0 82 | for ((k, v) in map) { 83 | val vol = Node(1, ++count, "Volume #$k", NodeType.LIST) 84 | v.map { Node(2, ++count, "$it@$ojType", NodeType.LEAF) } 85 | .forEach { vol.son.add(it) } 86 | root.son.add(vol) 87 | } 88 | return root 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/dataproc/DataLinerStder.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.dataproc 2 | 3 | /** 4 | * Created by Administrator on 2017/3/11 0011. 5 | */ 6 | fun std(datas: List, limit: Int): DoubleArray { 7 | val res = DoubleArray(datas.size, {0.0}) 8 | val best = datas 9 | .filter { it.isValid } 10 | .map { it.data } 11 | .max() 12 | if (best != null) { 13 | datas.indices 14 | .filter { datas[it].isValid } 15 | .forEach { res[it] = 1.0 - (best - datas[it].data) / limit } 16 | } 17 | for (i in res.indices) { 18 | if (!datas[i].isValid) 19 | continue 20 | if (res[i] < 0) 21 | res[i] = 0.0 22 | res[i] = 60.0 + 40.0 * res[i] 23 | } 24 | return res 25 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/dataproc/DataStder.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.dataproc; 2 | 3 | import java.util.List; 4 | import java.util.function.Supplier; 5 | import java.util.stream.DoubleStream; 6 | 7 | /** 8 | * 计算数据标准分 9 | * Created by kun on 2016/7/13. 10 | */ 11 | public class DataStder { 12 | 13 | /** 14 | * 计算数据标准分 15 | * 时间复杂度:O(N) 16 | * 17 | * @param list 原始数据list 18 | * @param alpha 放大倍数 19 | * @param beta 基准分 20 | * @return 每个数据的标准分 21 | */ 22 | public static double[] std(List list, double alpha, double beta) { 23 | double[] ans = new double[list.size()]; 24 | //计算平均值和标准差 25 | Supplier stream = 26 | () -> list.stream().filter(RawData::isValid).mapToDouble(RawData::getData); 27 | int cnt = (int) stream.get().count(); 28 | if (cnt == 0) return ans; 29 | if (cnt == 1) { 30 | for (int i = 0; i < list.size(); ++i) 31 | if (list.get(i).isValid()) 32 | ans[i] = beta; 33 | return ans; 34 | } 35 | double avg = stream.get().summaryStatistics().getAverage(); 36 | double std = stream.get().map(x -> Math.pow(x - avg, 2)).sum(); 37 | std = Math.sqrt(std / (cnt - 1)); 38 | //计算标准分 39 | for (int i = 0; i < list.size(); ++i) { 40 | if (list.get(i).isValid()) { 41 | ans[i] = std == 0 ? 0 : (list.get(i).getData() - avg) / std; 42 | ans[i] = alpha * ans[i] + beta; 43 | } 44 | } 45 | return ans; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/dataproc/RawData.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.dataproc; 2 | 3 | 4 | /** 5 | * Created by kun on 2016/7/13. 6 | */ 7 | public class RawData { 8 | 9 | private Double data; 10 | private boolean valid; 11 | 12 | public RawData(Double data, boolean valid) { 13 | this.data = data; 14 | this.valid = valid; 15 | } 16 | 17 | public Double getData() { 18 | return data; 19 | } 20 | 21 | public void setData(Double data) { 22 | this.data = data; 23 | } 24 | 25 | public boolean isValid() { 26 | return valid; 27 | } 28 | 29 | public void setValid(boolean valid) { 30 | this.valid = valid; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "RawData{" + 36 | "data=" + data + 37 | ", valid=" + valid + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/date/LocalDateConverter.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.date; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | 5 | import java.time.LocalDate; 6 | 7 | /** 8 | * Created by kun on 2016/9/16. 9 | */ 10 | public class LocalDateConverter implements Converter { 11 | @Override 12 | public LocalDate convert(String s) { 13 | return LocalDate.parse(s); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/date/LocalDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.date; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | /** 8 | * Created by kun on 2016/9/16. 9 | */ 10 | public class LocalDateTimeConverter implements Converter { 11 | @Override 12 | public LocalDateTime convert(String s) { 13 | return MyDateFormater.INSTANCE.toDT1(s); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/date/MyDateFormater.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.date 2 | 3 | 4 | import java.time.LocalDateTime 5 | import java.time.format.DateTimeFormatter 6 | 7 | 8 | object MyDateFormater { 9 | 10 | private val f1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") 11 | 12 | //时间转为字符串 13 | fun toStr1(dateTime: LocalDateTime): String { 14 | return dateTime.format(f1) 15 | } 16 | 17 | fun toDT1(str: String): LocalDateTime { 18 | return LocalDateTime.parse(str.trim { it <= ' ' }, f1) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/geetest/GeetestConfig.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.geetest; 2 | 3 | /** 4 | * GeetestWeb配置文件 5 | * 6 | * 7 | */ 8 | public class GeetestConfig { 9 | 10 | // 填入自己的captcha_id和private_key 11 | private static final String captcha_id = "258269bb69779a51dc96047af8f9ab51"; 12 | private static final String private_key = "d67e592a0f8672bde7fac3daf658bcf5"; 13 | 14 | public static final String getCaptcha_id() { 15 | return captcha_id; 16 | } 17 | 18 | public static final String getPrivate_key() { 19 | return private_key; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/geetest/StartCaptchaServlet.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.geetest; 2 | 3 | 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | /** 12 | * 使用Get的方式返回challenge和capthca_id,此方式以实现前后端完全分离的开发模式 13 | */ 14 | @Component 15 | public class StartCaptchaServlet { 16 | 17 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 18 | GeetestLib gtSdk = new GeetestLib(GeetestConfig.getCaptcha_id(), GeetestConfig.getPrivate_key()); 19 | String resStr = "{}"; 20 | //自定义userid 21 | String userid = "test"; 22 | //进行验证预处理 23 | int gtServerStatus = gtSdk.preProcess(userid); 24 | //将服务器状态设置到session中 25 | request.getSession().setAttribute(gtSdk.gtServerStatusSessionKey, gtServerStatus); 26 | //将userid设置到session中 27 | request.getSession().setAttribute("userid", userid); 28 | resStr = gtSdk.getResponseStr(); 29 | PrintWriter out = response.getWriter(); 30 | out.println(resStr); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/geetest/VerifyLoginServlet.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.geetest; 2 | 3 | 4 | 5 | import com.alibaba.fastjson.JSONException; 6 | import com.alibaba.fastjson.JSONObject; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | import java.io.PrintWriter; 15 | 16 | 17 | /** 18 | * 使用post方式,返回验证结果, request表单中必须包含challenge, validate, seccode 19 | */ 20 | @Component 21 | public class VerifyLoginServlet { 22 | 23 | public boolean doPost(HttpServletRequest request, 24 | HttpServletResponse response) throws ServletException, IOException { 25 | 26 | GeetestLib gtSdk = new GeetestLib(GeetestConfig.getCaptcha_id(), GeetestConfig.getPrivate_key()); 27 | 28 | String challenge = request.getParameter(GeetestLib.fn_geetest_challenge); 29 | String validate = request.getParameter(GeetestLib.fn_geetest_validate); 30 | String seccode = request.getParameter(GeetestLib.fn_geetest_seccode); 31 | 32 | //从session中获取gt-server状态 33 | int gt_server_status_code = (Integer) request.getSession().getAttribute(gtSdk.gtServerStatusSessionKey); 34 | 35 | //从session中获取userid 36 | String userid = (String)request.getSession().getAttribute("userid"); 37 | 38 | int gtResult = 0; 39 | 40 | if (gt_server_status_code == 1) { 41 | //gt-server正常,向gt-server进行二次验证 42 | 43 | gtResult = gtSdk.enhencedValidateRequest(challenge, validate, seccode, userid); 44 | System.out.println(gtResult); 45 | } else { 46 | // gt-server非正常情况下,进行failback模式验证 47 | 48 | System.out.println("failback:use your own server captcha validate"); 49 | gtResult = gtSdk.failbackValidateRequest(challenge, validate, seccode); 50 | System.out.println(gtResult); 51 | } 52 | return gtResult == 1; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/prob/PbDiffCalcer.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.prob 2 | 3 | import com.zzkun.dao.ExtOjPbInfoRepo 4 | import com.zzkun.dao.UserACPbRepo 5 | import com.zzkun.model.OJType 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.stereotype.Component 8 | import java.util.* 9 | 10 | /** 11 | * Created by Administrator on 2017/2/26 0026. 12 | */ 13 | @Component 14 | open class PbDiffCalcer( 15 | @Autowired private val extOjPbInfoRepo: ExtOjPbInfoRepo, 16 | @Autowired private val userACPbRepo: UserACPbRepo) { 17 | 18 | @Suppress("UNUSED_PARAMETER") 19 | fun calcPbDiff(ojName: OJType, pbId: String, pbNum: String): Double { 20 | // val info = extOjPbInfoRepo.findByOjNameAndPid(ojName, pbId) 21 | // val weAC = userACPbRepo.countByOjNameAndOjPbId(ojName, pbNum) 22 | // val res = (DEFAULT_MAX - log(1.0 + info.dacu)) / log(1.7 + weAC) 23 | // println("${ojName},${pbId},${pbNum},${info.dacu},${info.ac},${weAC}") 24 | // return res 25 | return 1.0; 26 | } 27 | 28 | fun allPbDiff(): HashMap { 29 | val res = HashMap() 30 | val list = extOjPbInfoRepo.findAll() 31 | list.forEach { 32 | res["${it.num}@${it.ojName}"] = calcPbDiff(it.ojName, it.pid, it.num) 33 | } 34 | return res 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/rank/RankParser.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.rank; 2 | 3 | import com.zzkun.model.Contest; 4 | 5 | /** 6 | * Created by kun on 2016/8/16. 7 | */ 8 | public interface RankParser { 9 | Contest parseRank(Contest contest); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/uhunt/UHuntAnalyser.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.uhunt 2 | 3 | import com.google.common.collect.HashBiMap 4 | import com.zzkun.dao.ExtOjPbInfoRepo 5 | import com.zzkun.model.OJType 6 | import com.zzkun.model.User 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.stereotype.Component 9 | import java.util.* 10 | 11 | /** 12 | * uhunt数据分析工具类,依赖于dao 13 | * Created by kun on 2016/7/5. 14 | */ 15 | @Component 16 | open class UHuntAnalyser { 17 | 18 | companion object { 19 | private val pid2Num = HashBiMap.create(5120) 20 | } 21 | 22 | @Autowired lateinit var extOjPbInfoRepo: ExtOjPbInfoRepo 23 | 24 | /** 25 | * 分析用户各个节点做题数量 26 | * 时间复杂度:O(所有节点总题数) 27 | * @param acPbs 用户所有AC题目uvanum List 28 | * @param nodes 节点信息,可通过ChapterManager获得 29 | * @return 用户各个节点做题量 30 | */ 31 | fun calcNodesCount(acPbs: Set, 32 | nodes: List): List { 33 | val res = ArrayList() 34 | val has = HashSet() //去重set 35 | nodes.forEach { 36 | var cnt = 0 37 | it.pids.filter { acPbs.contains(it) && !has.contains(it) }.forEach { ++cnt; has.add(it) } 38 | res.add(cnt) 39 | } 40 | return res 41 | } 42 | 43 | fun userStatistic(users: List, 44 | nodes: List): Map> { 45 | val res = HashMap>() 46 | users.forEach { 47 | val acSet = it.acPbList 48 | .filter { it.ojName == OJType.UVA } 49 | .map { it.ojPbId.toInt() } 50 | .toHashSet() 51 | val list = calcNodesCount(acSet, nodes) 52 | res[it.id] = list 53 | } 54 | return res 55 | } 56 | 57 | // uvapid -> uva题号 58 | fun pidToNum(pid: String): String? { 59 | if (!pid2Num.containsKey(pid)) { 60 | pid2Num.put(pid, extOjPbInfoRepo.findByOjNameAndPid(OJType.UVA, pid).num) 61 | } 62 | return pid2Num[pid] 63 | } 64 | 65 | fun numToPid(num: String): String? { 66 | if(!pid2Num.containsValue(num)) { 67 | pid2Num.put(extOjPbInfoRepo.findByOjNameAndNum(OJType.UVA, num).pid, num) 68 | } 69 | return pid2Num.inverse()[num] 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/uhunt/UHuntTreeNode.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.uhunt 2 | 3 | import java.io.Serializable 4 | import java.util.* 5 | 6 | /** 7 | * Created by kun on 2016/7/5. 8 | */ 9 | class UHuntTreeNode : Comparable, Serializable { 10 | 11 | var deep: Int = 0 12 | var id: Int = 0 13 | var name: String = "" 14 | var type: String = "" 15 | var son: ArrayList = ArrayList() 16 | var pids: ArrayList = ArrayList() 17 | 18 | constructor() { 19 | } 20 | 21 | constructor(deep: Int, id: Int, name: String, type: String) { 22 | this.deep = deep 23 | this.id = id 24 | this.name = name 25 | this.type = type 26 | } 27 | 28 | override fun compareTo(other: UHuntTreeNode): Int { 29 | return Integer.compare(id, other.id) 30 | } 31 | 32 | override fun toString(): String { 33 | return "UHuntTreeNode(deep=$deep, id=$id, name='$name', type='$type', son=${son.size}, pids=${pids.size})" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/uhunt/UhuntTreeManager.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.uhunt; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.TreeMap; 12 | 13 | /** 14 | * uva章节树配置文件,解析类 15 | * Created by kun on 2016/7/5. 16 | */ 17 | @Component 18 | public class UhuntTreeManager { 19 | 20 | private final List pbs = new ArrayList<>(); //临时数组 21 | private UHuntTreeNode root; 22 | 23 | private List chapterMap; 24 | private List bookMap; 25 | 26 | public UhuntTreeManager() { 27 | //加载初始章节配置文件 28 | File file = new File(getClass().getClassLoader().getResource("uhunt/aoapc.csv").getFile()); 29 | try { 30 | List lines = FileUtils.readLines(file, "utf8"); 31 | parseTree(lines); 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | /** 38 | * 解析Uhunt题目树 39 | * @param config 配置文本 40 | */ 41 | public void parseTree(List config) { 42 | root = new UHuntTreeNode(0, 0, "root", "nil"); 43 | Map nodes = new TreeMap<>(); 44 | nodes.put(0, root); 45 | for(int i = 1; i < config.size(); ++i) { 46 | String line = config.get(i); 47 | String[] split = line.split(","); 48 | UHuntTreeNode cur = new UHuntTreeNode(); 49 | UHuntTreeNode fa = nodes.get(Integer.parseInt(split[1])); 50 | cur.setDeep(fa.getDeep() + 1); 51 | cur.setId(Integer.parseInt(split[0])); 52 | cur.setName(split[2]); 53 | cur.setType(split[3]); 54 | fa.getSon().add(cur); 55 | nodes.put(cur.getId(), cur); 56 | } 57 | pbs.clear(); 58 | chapterMap = null; 59 | bookMap = null; 60 | } 61 | 62 | public List getCptNodes() { 63 | if(chapterMap == null) { 64 | pbs.clear(); 65 | chapterMap = new ArrayList<>(); 66 | dfsDirPb(root, 2, chapterMap); 67 | } 68 | return chapterMap; 69 | } 70 | 71 | public List getBookNodes() { 72 | if(bookMap == null) { 73 | pbs.clear(); 74 | bookMap = new ArrayList<>(); 75 | dfsDirPb(root, 1, bookMap); 76 | } 77 | return bookMap; 78 | } 79 | 80 | private void dfsDirPb(UHuntTreeNode cur, int deep, List result) { 81 | if("uva".equals(cur.getType())) { 82 | pbs.add(Integer.parseInt(cur.getName())); 83 | return; 84 | } 85 | for(UHuntTreeNode son : cur.getSon()) { 86 | dfsDirPb(son, deep, result); 87 | } 88 | if(cur.getDeep() == deep) { 89 | cur.getPids().clear(); 90 | cur.getPids().addAll(pbs); 91 | result.add(cur); 92 | pbs.clear(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/web/BCWebGetter.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.web; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.zzkun.model.BCUserInfo; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by kun on 2016/8/9. 17 | */ 18 | @Component 19 | public class BCWebGetter { 20 | 21 | private static final Logger logger = LoggerFactory.getLogger(BCWebGetter.class); 22 | 23 | @Autowired private HttpUtil httpUtil; 24 | 25 | public BCUserInfo getBCUserInfo(String bcname) { 26 | logger.info("开始获取用户BC信息:{}", bcname); 27 | try { 28 | String str = httpUtil.readURL("http://bestcoder.hdu.edu.cn/api/api.php?type=user-rating&user=" + bcname); 29 | JSONArray array = JSON.parseArray(str); 30 | JSONObject object = array.getJSONObject(array.size() - 1); 31 | logger.info("获取{}的最后一次比赛信息:{}", bcname, object); 32 | return new BCUserInfo(bcname, object.getInteger("rating")); 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | return null; 37 | } 38 | 39 | public List getBCUserInfos(List nameList) { 40 | List list = new ArrayList<>(nameList.size()); 41 | for (String s : nameList) { 42 | BCUserInfo info = getBCUserInfo(s); 43 | if(info != null) list.add(info); 44 | } 45 | return list; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/zzkun/util/web/VJudgeWebGetter.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.web 2 | 3 | import com.alibaba.fastjson.JSON 4 | import com.alibaba.fastjson.JSONObject 5 | import org.slf4j.LoggerFactory 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.stereotype.Component 8 | import java.util.* 9 | 10 | 11 | /** 12 | * Created by kun on 2016/9/29. 13 | */ 14 | @Component 15 | open class VJudgeWebGetter { 16 | 17 | companion object { 18 | val logger = LoggerFactory.getLogger(VJudgeWebGetter::class.java) 19 | } 20 | 21 | @Autowired private lateinit var httpUtil: HttpUtil 22 | 23 | fun getUserACMap(vjname: String?, link: String): Map> { 24 | if(vjname == null) 25 | return HashMap() 26 | val url = String.format(link, vjname) 27 | // logger.info("开始爬取vjudge用户${vjname}AC纪录${url}") 28 | // val jsonStr = httpUtil.readURL(url) 29 | val jsonStr = httpUtil.readHttpsURL(url) 30 | val acmap: JSONObject? = JSON.parseObject(jsonStr)?.getJSONObject("acRecords") 31 | val res = HashMap>() 32 | if(acmap != null) { 33 | for(key in acmap.keys) { 34 | val pbList = ArrayList() 35 | val pbs = acmap.getJSONArray(key) 36 | for(i in pbs.indices) 37 | pbList.add(pbs.getString(i)) 38 | res[key] = pbList 39 | } 40 | } 41 | logger.info("获取vjudge用户${vjname}共${res.size}个oj的纪录") 42 | return res 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/jskills/Guard.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | /** 4 | * Verifies argument contracts. 5 | *

6 | * These are used until I figure out how to do this better in Java 7 | */ 8 | public class Guard { 9 | 10 | /** 11 | * No instances allowed 12 | */ 13 | private Guard() { } 14 | 15 | public static void argumentNotNull(Object value, String parameterName) { 16 | if (value == null) { 17 | throw new NullPointerException(parameterName); 18 | } 19 | } 20 | 21 | public static void argumentIsValidIndex(int index, int count, String parameterName) { 22 | if ((index < 0) || (index >= count)) { 23 | throw new IndexOutOfBoundsException(parameterName); 24 | } 25 | } 26 | 27 | public static void argumentInRangeInclusive(double value, double min, double max, String parameterName) { 28 | if ((value < min) || (value > max)) { 29 | throw new IndexOutOfBoundsException(parameterName); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/jskills/IPlayer.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | public interface IPlayer { } 4 | -------------------------------------------------------------------------------- /src/main/java/jskills/ISupportPartialPlay.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | /** 4 | * Indicates support for allowing partial play (where a player only plays a part 5 | * of the time). 6 | */ 7 | public interface ISupportPartialPlay { 8 | /** 9 | * Indicates the percent of the time the player should be weighted where 0.0 10 | * indicates the player didn't play and 1.0 indicates the player played 100% 11 | * of the time. 12 | */ 13 | public double getPartialPlayPercentage(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/jskills/ISupportPartialUpdate.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | /** 4 | * Indicates support for allowing partial update (where a player only gets part 5 | * of the calculated skill update). 6 | */ 7 | public interface ISupportPartialUpdate { 8 | /** 9 | * Indicated how much of a skill update a player should receive where 0.0 10 | * represents no update and 1.0 represents 100% of the update. 11 | */ 12 | public double getPartialUpdatePercentage(); 13 | } -------------------------------------------------------------------------------- /src/main/java/jskills/ITeam.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | import java.util.Map; 4 | 5 | public interface ITeam extends Map { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/jskills/PairwiseComparison.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | import java.util.TreeMap; 4 | 5 | /** 6 | * Represents a comparison between two players. 7 | *

8 | * The actual values for the enum were chosen so that the also correspond to the 9 | * multiplier for updates to means. 10 | */ 11 | public enum PairwiseComparison{ 12 | WIN(1), 13 | DRAW(0), 14 | LOSE(-1); 15 | 16 | public final int multiplier; 17 | 18 | PairwiseComparison(int multiplier) { this.multiplier = multiplier; } 19 | 20 | private static TreeMap revmap = new TreeMap(); 21 | static { for (PairwiseComparison pc : PairwiseComparison.values()) 22 | revmap.put(pc.multiplier, pc); 23 | } 24 | 25 | public static PairwiseComparison fromMultiplier(int multiplier) { 26 | return revmap.get(multiplier); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/jskills/PartialPlay.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | public class PartialPlay { 4 | 5 | public static double getPartialPlayPercentage(Object player) { 6 | // If the player doesn't support the interface, assume 1.0 == 100% 7 | if (player instanceof ISupportPartialPlay) { 8 | double partialPlayPercentage = ((ISupportPartialPlay) player) 9 | .getPartialPlayPercentage(); 10 | 11 | // HACK to get around bug near 0 12 | final double smallestPercentage = 0.0001; 13 | if (partialPlayPercentage < smallestPercentage) { 14 | partialPlayPercentage = smallestPercentage; 15 | } 16 | 17 | return partialPlayPercentage; 18 | } 19 | return 1.0; 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/jskills/RankSorter.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Helper class to sort ranks in non-decreasing order. 7 | */ 8 | public class RankSorter { 9 | 10 | /** 11 | * Returns a list of all the elements in items, sorted in non-descending 12 | * order, according to itemRanks. Uses a stable sort, and also sorts 13 | * itemRanks (in place) 14 | * 15 | * @param items 16 | * The items to sort according to the order specified by ranks. 17 | * @param itemRanks 18 | * The ranks for each item where 1 is first place. 19 | * @return the items sorted according to their ranks 20 | */ 21 | public static List sort(Collection items, int[] itemRanks) { 22 | Guard.argumentNotNull(items, "items"); 23 | Guard.argumentNotNull(itemRanks, "itemRanks"); 24 | 25 | int lastObserverdRank = 0; 26 | boolean needToSort = false; 27 | 28 | for (int currentRank : itemRanks) { 29 | // We're expecting ranks to go up (e.g. 1, 2, 2, 3, ...) 30 | // If it goes down, then we've got to sort it. 31 | if (currentRank < lastObserverdRank) { 32 | needToSort = true; 33 | break; 34 | } 35 | 36 | lastObserverdRank = currentRank; 37 | } 38 | 39 | // Don't bother doing more work, it's already in a good order 40 | if (!needToSort) return new ArrayList(items); 41 | 42 | // Get the existing items as an indexable list. 43 | List itemsInList = new ArrayList(items); 44 | 45 | // item -> rank 46 | final Map itemToRank = new HashMap(); 47 | for (int i = 0; i < itemsInList.size(); i++) 48 | itemToRank.put(itemsInList.get(i), itemRanks[i]); 49 | 50 | Collections.sort(itemsInList, new Comparator() { 51 | public int compare(T o1, T o2) { 52 | return itemToRank.get(o1).compareTo(itemToRank.get(o2)); 53 | } 54 | }); 55 | 56 | Arrays.sort(itemRanks); 57 | return itemsInList; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/jskills/SkillCalculator.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | import jskills.numerics.Range; 4 | 5 | import java.util.Collection; 6 | import java.util.EnumSet; 7 | import java.util.Map; 8 | 9 | /** 10 | * Base class for all skill calculator implementations. 11 | */ 12 | public abstract class SkillCalculator { 13 | 14 | public enum SupportedOptions { PartialPlay, PartialUpdate } 15 | 16 | private final EnumSet supportedOptions; 17 | private final Range playersPerTeamAllowed; 18 | private final Range totalTeamsAllowed; 19 | 20 | protected SkillCalculator(EnumSet supportedOptions, 21 | Range totalTeamsAllowed, 22 | Range playerPerTeamAllowed) { 23 | this.supportedOptions = supportedOptions; 24 | this.totalTeamsAllowed = totalTeamsAllowed; 25 | this.playersPerTeamAllowed = playerPerTeamAllowed; 26 | } 27 | 28 | public boolean isSupported(SupportedOptions option) { 29 | return supportedOptions.contains(option); 30 | } 31 | 32 | /** 33 | * Calculates new ratings based on the prior ratings and team ranks. 34 | * 35 | * @param gameInfo Parameters for the game. 36 | * @param teams A mapping of team players and their ratings. 37 | * @param teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2) 38 | * @return All the players and their new ratings. 39 | */ 40 | public abstract Map calculateNewRatings(GameInfo gameInfo, 41 | Collection teams, int... teamRanks); 42 | 43 | /** 44 | * Calculates the match quality as the likelihood of all teams drawing. 45 | * 46 | * @param gameInfo Parameters for the game. 47 | * @param teams A mapping of team players and their ratings. 48 | * @return The quality of the match between the teams as a percentage (0% = bad, 100% = well matched). 49 | */ 50 | public abstract double calculateMatchQuality(GameInfo gameInfo, Collection teams); 51 | 52 | protected void validateTeamCountAndPlayersCountPerTeam(Collection teams) { 53 | validateTeamCountAndPlayersCountPerTeam(teams, totalTeamsAllowed, playersPerTeamAllowed); 54 | } 55 | 56 | private static void validateTeamCountAndPlayersCountPerTeam(Collection teams, 57 | Range totalTeams, 58 | Range playersPerTeam) { 59 | Guard.argumentNotNull(teams, "teams"); 60 | int countOfTeams = 0; 61 | for (ITeam currentTeam : teams) { 62 | if (!playersPerTeam.isInRange(currentTeam.size())) { 63 | throw new IllegalArgumentException(); 64 | } 65 | countOfTeams++; 66 | } 67 | 68 | if (!totalTeams.isInRange(countOfTeams)) { 69 | throw new IllegalArgumentException(); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/jskills/Team.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | 8 | /** 9 | * Helper class for working with a single team. 10 | */ 11 | public class Team extends HashMap implements ITeam { 12 | 13 | /** Generated UID for serialization **/ 14 | private static final long serialVersionUID = -5274158841312594600L; 15 | 16 | /** 17 | * Constructs a new team. 18 | */ 19 | public Team() { } 20 | 21 | /** 22 | * Constructs a Team and populates it with the specified player. 23 | * 24 | * @param player The player to add. 25 | * @param rating The rating of the player. 26 | */ 27 | public Team(IPlayer player, Rating rating) { addPlayer(player, rating); } 28 | 29 | /** 30 | * Adds the player to the team. 31 | * 32 | * @param player The player to add. 33 | * @param rating The rating of the player 34 | * @return The instance of the team (for chaining convenience). 35 | */ 36 | public Team addPlayer(IPlayer player, Rating rating) { 37 | put(player, rating); 38 | return this; 39 | } 40 | 41 | /** 42 | * Concatenates multiple teams into a list of teams. 43 | * 44 | * @param teams The teams to concatenate together. 45 | * @return A sequence of teams. 46 | */ 47 | public static Collection concat(ITeam... teams) { 48 | List teamslist = new ArrayList(); 49 | for (ITeam team : teams) teamslist.add(team); 50 | return teamslist; 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/jskills/TrueSkillCalculator.java: -------------------------------------------------------------------------------- 1 | package jskills; 2 | 3 | import jskills.trueskill.FactorGraphTrueSkillCalculator; 4 | 5 | import java.util.Collection; 6 | import java.util.Map; 7 | 8 | /** 9 | * Calculates a TrueSkill rating using {@link FactorGraphTrueSkillCalculator}. 10 | */ 11 | public class TrueSkillCalculator { 12 | 13 | /** Static usage only **/ private TrueSkillCalculator() {} 14 | // Keep a singleton around 15 | private static final SkillCalculator calculator = new FactorGraphTrueSkillCalculator(); 16 | 17 | /** 18 | * Calculates new ratings based on the prior ratings and team ranks. 19 | * 20 | * @param gameInfo Parameters for the game. 21 | * @param teams A mapping of team players and their ratings. 22 | * @param teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2) 23 | * @return All the players and their new ratings. 24 | */ 25 | public static Map calculateNewRatings(GameInfo gameInfo, Collection teams, int... teamRanks) { 26 | // Just punt the work to the full implementation 27 | return calculator.calculateNewRatings(gameInfo, teams, teamRanks); 28 | } 29 | 30 | /** 31 | * Calculates the match quality as the likelihood of all teams drawing. 32 | * 33 | * @param gameInfo Parameters for the game. 34 | * @param teams A mapping of team players and their ratings. 35 | * @return The match quality as a percentage (between 0.0 and 1.0). 36 | */ 37 | public static double calculateMatchQuality(GameInfo gameInfo, Collection teams) { 38 | // Just punt the work to the full implementation 39 | return calculator.calculateMatchQuality(gameInfo, teams); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/jskills/elo/EloRating.java: -------------------------------------------------------------------------------- 1 | package jskills.elo; 2 | 3 | import jskills.Rating; 4 | 5 | /** 6 | * An Elo rating represented by a single number (mean). 7 | */ 8 | public class EloRating extends Rating { 9 | public EloRating(double rating) { super(rating, 0); } 10 | } -------------------------------------------------------------------------------- /src/main/java/jskills/elo/FideEloCalculator.java: -------------------------------------------------------------------------------- 1 | package jskills.elo; 2 | 3 | import jskills.GameInfo; 4 | 5 | /** 6 | * Including ELO's scheme as a simple comparison. See 7 | * http://en.wikipedia.org/wiki/Elo_rating_system#Theory for more details 8 | */ 9 | public class FideEloCalculator extends TwoPlayerEloCalculator { 10 | 11 | public FideEloCalculator() { this(new FideKFactor()); } 12 | 13 | public FideEloCalculator(FideKFactor kFactor) { super(kFactor); } 14 | 15 | @Override 16 | protected double getPlayerWinProbability(GameInfo gameInfo, double playerRating, double opponentRating) { 17 | double ratingDifference = opponentRating - playerRating; 18 | 19 | return 1.0 / 20 | (1.0 + Math.pow(10.0, ratingDifference / (2 * gameInfo.getBeta()))); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/jskills/elo/FideKFactor.java: -------------------------------------------------------------------------------- 1 | package jskills.elo; 2 | 3 | /** @see http://ratings.fide.com/calculator_rtd.phtml for details **/ 4 | public class FideKFactor extends KFactor { 5 | 6 | public FideKFactor() { super(-1.); } 7 | 8 | public double getValueForRating(double rating) { 9 | if (rating < 2400) return 15; 10 | return 10; 11 | } 12 | 13 | /** Indicates someone who has played less than 30 games. **/ 14 | public static class Provisional extends FideKFactor { 15 | 16 | public Provisional() { super(); } 17 | 18 | @Override 19 | public double getValueForRating(double rating) { return 25; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/jskills/elo/GaussianEloCalculator.java: -------------------------------------------------------------------------------- 1 | package jskills.elo; 2 | 3 | import jskills.GameInfo; 4 | import jskills.numerics.GaussianDistribution; 5 | 6 | public class GaussianEloCalculator extends TwoPlayerEloCalculator { 7 | // From the paper 8 | private static final KFactor StableKFactor = new KFactor(24); 9 | 10 | public GaussianEloCalculator() { super(StableKFactor); } 11 | 12 | @Override 13 | protected double getPlayerWinProbability(GameInfo gameInfo, 14 | double playerRating, double opponentRating) { 15 | double ratingDifference = playerRating - opponentRating; 16 | 17 | // See equation 1.1 in the TrueSkill paper 18 | return GaussianDistribution.cumulativeTo( 19 | ratingDifference / (Math.sqrt(2) * gameInfo.getBeta())); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/jskills/elo/GaussianKFactor.java: -------------------------------------------------------------------------------- 1 | package jskills.elo; 2 | 3 | import jskills.GameInfo; 4 | 5 | public class GaussianKFactor extends KFactor { 6 | // From paper 7 | static final double StableDynamicsKFactor = 24.0; 8 | 9 | public GaussianKFactor() { super(StableDynamicsKFactor); } 10 | 11 | public GaussianKFactor(GameInfo gameInfo, double latestGameWeightingFactor) { 12 | super(latestGameWeightingFactor * gameInfo.getBeta() 13 | * Math.sqrt(Math.PI)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/jskills/elo/KFactor.java: -------------------------------------------------------------------------------- 1 | package jskills.elo; 2 | 3 | public class KFactor { 4 | private final double value; 5 | 6 | public KFactor(double exactKFactor) { value = exactKFactor; } 7 | 8 | public double getValueForRating(double rating) { return value; } 9 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/DefaultVariable.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public class DefaultVariable extends Variable { 4 | 5 | public DefaultVariable() { super(null, "Default"); } 6 | 7 | @Override 8 | public void setValue(TValue value) { 9 | throw new UnsupportedOperationException(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/Factor.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | import java.util.*; 4 | 5 | import static jskills.Guard.argumentIsValidIndex; 6 | 7 | public abstract class Factor { 8 | 9 | protected final List> messages = new ArrayList>(); 10 | 11 | private final Map, Variable> messageToVariableBinding = 12 | new HashMap, Variable>(); 13 | 14 | private final String name; 15 | protected final List> variables = new ArrayList>(); 16 | 17 | protected Factor(String name) { this.name = "Factor[" + name + "]"; } 18 | 19 | /** Returns the log-normalization constant of that factor **/ 20 | public abstract double getLogNormalization(); 21 | 22 | /** Returns the number of messages that the factor has **/ 23 | public int getNumberOfMessages() { return messages.size(); } 24 | 25 | protected List> getVariables() { 26 | return Collections.unmodifiableList(variables); 27 | } 28 | 29 | protected List> getMessages() { 30 | return Collections.unmodifiableList(messages); 31 | } 32 | 33 | /** Update the message and marginal of the i-th variable that the factor is connected to **/ 34 | public double updateMessage(int messageIndex) { 35 | argumentIsValidIndex(messageIndex, messages.size(), "messageIndex"); 36 | return updateMessage(messages.get(messageIndex), messageToVariableBinding.get(messages.get(messageIndex))); 37 | } 38 | 39 | protected double updateMessage(Message message, Variable variable) { 40 | throw new UnsupportedOperationException(); 41 | } 42 | 43 | /** Resets the marginal of the variables a factor is connected to **/ 44 | public void ResetMarginals() { 45 | for(Variable variable : messageToVariableBinding.values()) 46 | variable.resetToPrior(); 47 | } 48 | 49 | /** 50 | * Sends the ith message to the marginal and returns the log-normalization 51 | * constant 52 | **/ 53 | public double sendMessage(int messageIndex) { 54 | argumentIsValidIndex(messageIndex, messages.size(), "messageIndex"); 55 | 56 | Message message = messages.get(messageIndex); 57 | Variable variable = messageToVariableBinding.get(message); 58 | return sendMessage(message, variable); 59 | } 60 | 61 | protected abstract double sendMessage(Message message, Variable variable); 62 | 63 | public abstract Message createVariableToMessageBinding(Variable variable); 64 | 65 | protected Message createVariableToMessageBinding(Variable variable, Message message) { 66 | messages.add(message); 67 | messageToVariableBinding.put(message, variable); 68 | variables.add(variable); 69 | 70 | return message; 71 | } 72 | 73 | @Override 74 | public String toString() { return name != null ? name : super.toString(); } 75 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/FactorGraph.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public abstract class FactorGraph> { } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/FactorGraphLayer.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | public abstract class FactorGraphLayer, TValue, 8 | TBaseVariable extends Variable, TInputVariable extends Variable, TFactor extends Factor, 9 | TOutputVariable extends Variable> extends FactorGraphLayerBase { 10 | 11 | private final List localFactors; 12 | private final List> outputVariablesGroups; 13 | private List> inputVariablesGroups; 14 | protected TParentFactorGraph parentFactorGraph; 15 | 16 | protected FactorGraphLayer(TParentFactorGraph parentGraph) { 17 | this.localFactors = new ArrayList(); 18 | this.outputVariablesGroups = new ArrayList>(); 19 | this.inputVariablesGroups = new ArrayList>(); 20 | this.parentFactorGraph = parentGraph; 21 | } 22 | 23 | protected List> getInputVariablesGroups() { 24 | return inputVariablesGroups; 25 | } 26 | 27 | protected Schedule ScheduleSequence(Collection> itemsToSequence, 28 | String nameFormat, Object... args) { 29 | final String formattedName = String.format(nameFormat, args); 30 | return new ScheduleSequence(formattedName, itemsToSequence); 31 | } 32 | 33 | protected void AddLayerFactor(TFactor factor) { 34 | localFactors.add(factor); 35 | } 36 | 37 | public TParentFactorGraph getParentFactorGraph() { return parentFactorGraph; } 38 | 39 | public List> getOutputVariablesGroups(){ 40 | return outputVariablesGroups; 41 | } 42 | 43 | public void addOutputVariableGroup(List group) { 44 | outputVariablesGroups.add(group); 45 | } 46 | 47 | public void addOutputVariable(TOutputVariable var) { 48 | List g = new ArrayList(1); g.add(var); 49 | addOutputVariableGroup(g); 50 | } 51 | 52 | public List getLocalFactors() { 53 | return localFactors; 54 | } 55 | 56 | @Override 57 | @SuppressWarnings("unchecked") // TODO there has to be a safer way to do this 58 | public Collection> getUntypedFactors() { 59 | return (Collection>) localFactors; 60 | } 61 | 62 | @Override 63 | @SuppressWarnings("unchecked") // TODO there has to be a safer way to do this 64 | public void setRawInputVariablesGroups(Object value) { 65 | inputVariablesGroups = (List>)value; 66 | } 67 | 68 | @Override 69 | public Object getRawOutputVariablesGroups() { 70 | return outputVariablesGroups; 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/FactorGraphLayerBase.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | import java.util.Collection; 4 | 5 | public abstract class FactorGraphLayerBase { 6 | 7 | public abstract Collection> getUntypedFactors(); 8 | public abstract void buildLayer(); 9 | 10 | public Schedule createPriorSchedule() 11 | { 12 | return null; 13 | } 14 | 15 | public Schedule createPosteriorSchedule() 16 | { 17 | return null; 18 | } 19 | 20 | public abstract void setRawInputVariablesGroups(Object value); 21 | public abstract Object getRawOutputVariablesGroups(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/FactorList.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Helper class for computing the factor graph's normalization constant. 8 | */ 9 | public class FactorList { 10 | 11 | private final List> factors = new ArrayList>(); 12 | 13 | public double getLogNormalization() { 14 | // TODO can these 3 loops be rolled into 1? 15 | for(Factor f : factors) f.ResetMarginals(); 16 | 17 | double sumLogZ = 0.0; 18 | for(Factor f : factors) { 19 | for (int j = 0; j < f.getNumberOfMessages(); j++) 20 | sumLogZ += f.sendMessage(j); 21 | } 22 | 23 | double sumLogS = 0; 24 | for(Factor f : factors) sumLogS += f.getLogNormalization(); 25 | 26 | return sumLogZ + sumLogS; 27 | } 28 | 29 | public int size() { return factors.size(); } 30 | 31 | public Factor addFactor(Factor factor) { 32 | factors.add(factor); 33 | return factor; 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/KeyedVariable.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public class KeyedVariable extends Variable { 4 | 5 | private final TKey key; 6 | 7 | public KeyedVariable(TKey key, TValue prior, String name, Object... args) { 8 | super(prior, name, args); 9 | this.key = key; 10 | } 11 | 12 | public TKey getKey() { 13 | return key; 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/Message.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public class Message { 4 | 5 | private final String nameFormat; 6 | private final Object[] nameFormatArgs; 7 | 8 | private T value; 9 | 10 | public Message() { this(null, null, (Object[])null); } 11 | 12 | public Message(T value, String nameFormat, Object... args) { 13 | this.nameFormat = nameFormat; 14 | nameFormatArgs = args; 15 | this.value = value; 16 | } 17 | 18 | public T getValue() { 19 | return value; 20 | } 21 | 22 | public void setValue(T value) { 23 | this.value = value; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return (nameFormat == null) ? 29 | super.toString() : 30 | String.format(nameFormat, nameFormatArgs); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/Schedule.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public abstract class Schedule { 4 | private final String name; 5 | 6 | protected Schedule(String name) { 7 | this.name = name; 8 | } 9 | 10 | public abstract double visit(int depth, int maxDepth); 11 | 12 | public double visit() { return visit(-1, 0); } 13 | 14 | @Override public String toString() { 15 | return name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/ScheduleLoop.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public class ScheduleLoop extends Schedule { 4 | 5 | private static final int MAX_ITERATIONS = 100; 6 | 7 | private final double maxDelta; 8 | private final Schedule scheduleToLoop; 9 | 10 | public ScheduleLoop(String name, Schedule scheduleToLoop, double maxDelta) { 11 | super(name); 12 | this.scheduleToLoop = scheduleToLoop; 13 | this.maxDelta = maxDelta; 14 | } 15 | 16 | @Override 17 | public double visit(int depth, int maxDepth) { 18 | double delta = scheduleToLoop.visit(depth + 1, maxDepth); 19 | for(int totalIterations = 1; delta > maxDelta; totalIterations++) { 20 | delta = scheduleToLoop.visit(depth + 1, maxDepth); 21 | if(totalIterations > MAX_ITERATIONS) 22 | throw new RuntimeException(String.format( 23 | "Maximum iterations (%d) reached.", MAX_ITERATIONS)); 24 | } 25 | 26 | return delta; 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/ScheduleSequence.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | import java.util.Collection; 4 | 5 | import static java.lang.Math.max; 6 | 7 | public class ScheduleSequence 8 | extends Schedule { 9 | private final Collection> schedules; 10 | 11 | public ScheduleSequence(String name, Collection> schedules) { 12 | super(name); 13 | this.schedules = schedules; 14 | } 15 | 16 | @Override 17 | public double visit(int depth, int maxDepth) { 18 | double maxDelta = 0; 19 | 20 | for (Schedule schedule : schedules) 21 | maxDelta = max(schedule.visit(depth + 1, maxDepth), maxDelta); 22 | 23 | return maxDelta; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/ScheduleStep.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public class ScheduleStep extends Schedule { 4 | private final Factor factor; 5 | private final int index; 6 | 7 | public ScheduleStep(String name, Factor factor, int index) { 8 | super(name); 9 | this.factor = factor; 10 | this.index = index; 11 | } 12 | 13 | @Override 14 | public double visit(int depth, int maxDepth) { 15 | return factor.updateMessage(index); 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/jskills/factorgraphs/Variable.java: -------------------------------------------------------------------------------- 1 | package jskills.factorgraphs; 2 | 3 | public class Variable 4 | { 5 | private final String name; 6 | private final TValue prior; 7 | private TValue value; 8 | 9 | public Variable(TValue prior, String name, Object... args) { 10 | this.name = "Variable[" + String.format(name, args) + "]"; 11 | this.prior = prior; 12 | resetToPrior(); 13 | } 14 | 15 | public TValue getValue() { 16 | return value; 17 | } 18 | 19 | public void setValue(TValue value) { 20 | this.value = value; 21 | } 22 | 23 | public void resetToPrior() { value = prior; } 24 | 25 | @Override public String toString() { return name; } 26 | } -------------------------------------------------------------------------------- /src/main/java/jskills/numerics/MathUtils.java: -------------------------------------------------------------------------------- 1 | package jskills.numerics; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * For all the functions that aren't in java.lang.Math 7 | */ 8 | public final class MathUtils { 9 | 10 | /** Don't allow instantiation **/ 11 | private MathUtils() { } 12 | 13 | /** Square a number **/ 14 | public static double square(double x) { return x*x; } 15 | 16 | 17 | public static double mean(Collection collection) { 18 | double ret = 0; 19 | for(Double d : collection) ret += d.doubleValue(); 20 | return ret/collection.size(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/jskills/numerics/Range.java: -------------------------------------------------------------------------------- 1 | package jskills.numerics; 2 | 3 | /** 4 | * A very limited implementation of an immutable range of Integers, including 5 | * endpoints. There is no such thing as an empty range. 6 | *

7 | * The whole purpose of this class is to make the code for the 8 | * SkillCalculator(s) look a little cleaner 9 | *

10 | * Derived classes can't use this class's static ctors they way they could in 11 | * C#, so I'm going to eschew the relative type safety afforded by Moser's 12 | * scheme and make this class final. A Range is a Range is a Range. 13 | */ 14 | public final class Range { 15 | 16 | private final int min; 17 | private final int max; 18 | 19 | public Range(int min, int max) { 20 | if (min > max) throw new IllegalArgumentException(); 21 | 22 | this.min = min; 23 | this.max = max; 24 | } 25 | 26 | public int getMin() { 27 | return min; 28 | } 29 | 30 | public int getMax() { 31 | return max; 32 | } 33 | 34 | public boolean isInRange(int value) { 35 | return (min <= value) && (value <= max); 36 | } 37 | 38 | // REVIEW: It's probably bad form to have access statics via a derived 39 | // class, but the syntax looks better :-) 40 | 41 | // It's bad form in Java to the point where it won't compile. Using statics 42 | // through derived classes gets you a warning, but accessing generic types 43 | // (T) won't compile. 44 | 45 | public static Range inclusive(int min, int max) { 46 | return new Range(min, max); 47 | } 48 | 49 | public static Range exactly(int value) { 50 | return new Range(value, value); 51 | } 52 | 53 | public static Range atLeast(int minimumValue) { 54 | return new Range(minimumValue, Integer.MAX_VALUE); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) return true; 60 | if (o == null || getClass() != o.getClass()) return false; 61 | 62 | Range range = (Range) o; 63 | 64 | return getMin() == range.getMin() && getMax() == range.getMax(); 65 | 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | int result = getMin(); 71 | result = 31 * result + getMax(); 72 | return result; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return String.format("[%d, %d]", this.min, this.max); 78 | } 79 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/DrawMargin.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill; 2 | 3 | import static jskills.numerics.GaussianDistribution.inverseCumulativeTo; 4 | 5 | public class DrawMargin { 6 | 7 | public static double GetDrawMarginFromDrawProbability(double drawProbability, double beta) { 8 | 9 | /* 10 | * Derived from TrueSkill technical report (MSR-TR-2006-80), page 6 11 | * 12 | * draw probability = 2 * CDF(margin/(sqrt(n1+n2)*beta)) -1 13 | * implies 14 | * margin = inversecdf((draw probability + 1)/2) * sqrt(n1+n2) * beta 15 | * where n1 and n2 are the number of players on each team 16 | */ 17 | return inverseCumulativeTo(.5 * (drawProbability + 1), 0, 1) * Math.sqrt(1 + 1) * beta; 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/factors/GaussianFactor.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill.factors; 2 | 3 | import jskills.factorgraphs.Factor; 4 | import jskills.factorgraphs.Message; 5 | import jskills.factorgraphs.Variable; 6 | import jskills.numerics.GaussianDistribution; 7 | 8 | import static jskills.numerics.GaussianDistribution.logProductNormalization; 9 | 10 | public abstract class GaussianFactor extends Factor { 11 | 12 | GaussianFactor(String name) { super(name); } 13 | 14 | /** Sends the factor-graph message with and returns the log-normalization constant **/ 15 | @Override 16 | protected double sendMessage(Message message, Variable variable) { 17 | GaussianDistribution marginal = variable.getValue(); 18 | GaussianDistribution messageValue = message.getValue(); 19 | double logZ = logProductNormalization(marginal, messageValue); 20 | variable.setValue(marginal.mult(messageValue)); 21 | return logZ; 22 | } 23 | 24 | @Override 25 | public Message createVariableToMessageBinding(Variable variable) { 26 | return createVariableToMessageBinding(variable, new Message<>(GaussianDistribution.fromPrecisionMean(0, 0), 27 | "message from %s to %s", this, variable)); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/factors/GaussianPriorFactor.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill.factors; 2 | 3 | import jskills.factorgraphs.Message; 4 | import jskills.factorgraphs.Variable; 5 | import jskills.numerics.GaussianDistribution; 6 | 7 | import static jskills.numerics.GaussianDistribution.sub; 8 | 9 | /** 10 | * Supplies the factor graph with prior information. 11 | * See the accompanying math paper for more details. 12 | */ 13 | public class GaussianPriorFactor extends GaussianFactor { 14 | 15 | private final GaussianDistribution newMessage; 16 | 17 | public GaussianPriorFactor(double mean, double variance, Variable variable) 18 | { 19 | super(String.format("Prior value going to %s", variable)); 20 | newMessage = new GaussianDistribution(mean, Math.sqrt(variance)); 21 | createVariableToMessageBinding(variable, new Message<>(GaussianDistribution.fromPrecisionMean(0, 0), 22 | "message from %s to %s", this, variable)); 23 | } 24 | 25 | @Override 26 | protected double updateMessage(Message message, Variable variable) { 27 | GaussianDistribution oldMarginal = new GaussianDistribution(variable.getValue()); 28 | Message oldMessage = message; 29 | GaussianDistribution newMarginal = 30 | GaussianDistribution.fromPrecisionMean( 31 | oldMarginal.getPrecisionMean() + newMessage.getPrecisionMean() - oldMessage.getValue().getPrecisionMean(), 32 | oldMarginal.getPrecision() + newMessage.getPrecision() - oldMessage.getValue().getPrecision()); 33 | variable.setValue(newMarginal); 34 | message.setValue(newMessage); 35 | return sub(oldMarginal, newMarginal); 36 | } 37 | 38 | @Override public double getLogNormalization() { return 0; } 39 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/layers/PlayerPriorValuesToSkillsLayer.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill.layers; 2 | 3 | import jskills.IPlayer; 4 | import jskills.ITeam; 5 | import jskills.Rating; 6 | import jskills.factorgraphs.*; 7 | import jskills.numerics.GaussianDistribution; 8 | import jskills.numerics.MathUtils; 9 | import jskills.trueskill.TrueSkillFactorGraph; 10 | import jskills.trueskill.factors.GaussianPriorFactor; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | import java.util.List; 15 | import java.util.Map.Entry; 16 | 17 | // We intentionally have no Posterior schedule since the only purpose here is to 18 | public class PlayerPriorValuesToSkillsLayer extends 19 | TrueSkillFactorGraphLayer, 20 | GaussianPriorFactor, 21 | KeyedVariable> { 22 | 23 | private final Collection teams; 24 | 25 | public PlayerPriorValuesToSkillsLayer(TrueSkillFactorGraph parentGraph, Collection teams) { 26 | super(parentGraph); 27 | this.teams = teams; 28 | } 29 | 30 | @Override 31 | public void buildLayer() { 32 | for(ITeam currentTeam : teams) { 33 | List> currentTeamSkills = new ArrayList<>(); 34 | 35 | for(Entry currentTeamPlayer : currentTeam.entrySet()) { 36 | KeyedVariable playerSkill = 37 | createSkillOutputVariable(currentTeamPlayer.getKey()); 38 | AddLayerFactor(createPriorFactor(currentTeamPlayer.getKey(), currentTeamPlayer.getValue(), playerSkill)); 39 | currentTeamSkills.add(playerSkill); 40 | } 41 | 42 | addOutputVariableGroup(currentTeamSkills); 43 | } 44 | } 45 | 46 | @Override 47 | public Schedule createPriorSchedule() { 48 | Collection> schedules = new ArrayList<>(); 49 | for (GaussianPriorFactor prior : getLocalFactors()) { 50 | schedules.add(new ScheduleStep<>("Prior to Skill Step", prior, 0)); 51 | } 52 | return ScheduleSequence(schedules, "All priors"); 53 | } 54 | 55 | private GaussianPriorFactor createPriorFactor(IPlayer player, Rating priorRating, 56 | Variable skillsVariable) { 57 | return new GaussianPriorFactor(priorRating.getMean(), 58 | MathUtils.square(priorRating.getStandardDeviation()) + 59 | MathUtils.square(getParentFactorGraph().getGameInfo().getDynamicsFactor()), skillsVariable); 60 | } 61 | 62 | private KeyedVariable createSkillOutputVariable(IPlayer key) { 63 | return new KeyedVariable<>(key, GaussianDistribution.UNIFORM, "%s's skill", key.toString()); 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/layers/TeamDifferencesComparisonLayer.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill.layers; 2 | 3 | import jskills.GameInfo; 4 | import jskills.factorgraphs.DefaultVariable; 5 | import jskills.factorgraphs.Variable; 6 | import jskills.numerics.GaussianDistribution; 7 | import jskills.trueskill.DrawMargin; 8 | import jskills.trueskill.TrueSkillFactorGraph; 9 | import jskills.trueskill.factors.GaussianFactor; 10 | import jskills.trueskill.factors.GaussianGreaterThanFactor; 11 | import jskills.trueskill.factors.GaussianWithinFactor; 12 | 13 | public class TeamDifferencesComparisonLayer extends 14 | TrueSkillFactorGraphLayer, GaussianFactor, DefaultVariable> { 15 | 16 | private final double epsilon; 17 | private final int[] teamRanks; 18 | 19 | public TeamDifferencesComparisonLayer(TrueSkillFactorGraph parentGraph, int[] teamRanks) { 20 | super(parentGraph); 21 | this.teamRanks = teamRanks; 22 | final GameInfo gameInfo = parentFactorGraph.getGameInfo(); 23 | epsilon = DrawMargin.GetDrawMarginFromDrawProbability(gameInfo.getDrawProbability(), gameInfo.getBeta()); 24 | } 25 | 26 | @Override 27 | public void buildLayer() { 28 | for (int i = 0; i < getInputVariablesGroups().size(); i++) { 29 | boolean isDraw = (teamRanks[i] == teamRanks[i + 1]); 30 | Variable teamDifference = getInputVariablesGroups().get(i).get(0); 31 | 32 | GaussianFactor factor = 33 | isDraw 34 | ? (GaussianFactor) new GaussianWithinFactor(epsilon, teamDifference) 35 | : new GaussianGreaterThanFactor(epsilon, teamDifference); 36 | 37 | AddLayerFactor(factor); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/layers/TeamPerformancesToTeamPerformanceDifferencesLayer.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill.layers; 2 | 3 | import jskills.factorgraphs.Variable; 4 | import jskills.numerics.GaussianDistribution; 5 | import jskills.trueskill.TrueSkillFactorGraph; 6 | import jskills.trueskill.factors.GaussianWeightedSumFactor; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class TeamPerformancesToTeamPerformanceDifferencesLayer extends 12 | TrueSkillFactorGraphLayer, 13 | GaussianWeightedSumFactor, 14 | Variable> { 15 | 16 | public TeamPerformancesToTeamPerformanceDifferencesLayer(TrueSkillFactorGraph parentGraph) 17 | { 18 | super(parentGraph); 19 | } 20 | 21 | @Override 22 | public void buildLayer() { 23 | for (int i = 0; i < getInputVariablesGroups().size() - 1; i++) { 24 | Variable strongerTeam = getInputVariablesGroups().get(i).get(0); 25 | Variable weakerTeam = getInputVariablesGroups().get(i + 1).get(0); 26 | 27 | Variable currentDifference = createOutputVariable(); 28 | AddLayerFactor(createTeamPerformanceToDifferenceFactor(strongerTeam, weakerTeam, currentDifference)); 29 | 30 | // REVIEW: Does it make sense to have groups of one? 31 | addOutputVariable(currentDifference); 32 | } 33 | } 34 | 35 | private GaussianWeightedSumFactor createTeamPerformanceToDifferenceFactor(final Variable strongerTeam, 36 | final Variable weakerTeam, 37 | Variable output) { 38 | List> teams = new ArrayList>(){ 39 | private static final long serialVersionUID = -50768988200855179L; { 40 | add(strongerTeam); 41 | add(weakerTeam); 42 | }}; 43 | return new GaussianWeightedSumFactor(output, teams, new double[] {1.0, -1.0}); 44 | } 45 | 46 | private Variable createOutputVariable() { 47 | return new Variable<>(GaussianDistribution.UNIFORM, "Team performance difference"); 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/jskills/trueskill/layers/TrueSkillFactorGraphLayer.java: -------------------------------------------------------------------------------- 1 | package jskills.trueskill.layers; 2 | 3 | import jskills.factorgraphs.Factor; 4 | import jskills.factorgraphs.FactorGraphLayer; 5 | import jskills.factorgraphs.Variable; 6 | import jskills.numerics.GaussianDistribution; 7 | import jskills.trueskill.TrueSkillFactorGraph; 8 | 9 | public abstract class TrueSkillFactorGraphLayer, 10 | TFactor extends Factor, 11 | TOutputVariable extends Variable> 12 | extends FactorGraphLayer, TInputVariable, 13 | TFactor, TOutputVariable> 14 | { 15 | public TrueSkillFactorGraphLayer(TrueSkillFactorGraph parentGraph) 16 | { 17 | super(parentGraph); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/resources/common-logging.properties: -------------------------------------------------------------------------------- 1 | org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger -------------------------------------------------------------------------------- /src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.cj.jdbc.Driver 2 | jdbc.url=jdbc:mysql://acmanagerdb:3306/acmanager?characterEncoding=utf8&useSSL=false&serverTimezone=GMT 3 | jdbc.username=root 4 | jdbc.password=123456 -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kun368/ACManager/137388ba23df959f262fdb075e35873a98b6accd/src/main/resources/log4j.properties -------------------------------------------------------------------------------- /src/main/resources/real_jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.cj.jdbc.Driver 2 | #jdbc.url = jdbc:mysql://localhost:3306/acmanager?characterEncoding=utf8&useSSL=true&serverTimezone=GMT 3 | #jdbc.username = root 4 | #jdbc.password = zzk1811007 5 | #jdbc.url = jdbc:mysql://120.27.4.153:3306/acmanager?characterEncoding=utf8&useSSL=true 6 | #jdbc.username = root 7 | #jdbc.password = zzk1811007hehe 8 | jdbc.url=jdbc:mysql://192.168.119.213:3306/acmanager?characterEncoding=utf8&useSSL=true 9 | jdbc.username=root 10 | jdbc.password=soft1234 -------------------------------------------------------------------------------- /src/main/resources/uhunt/2016sum.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kun368/ACManager/137388ba23df959f262fdb075e35873a98b6accd/src/main/resources/uhunt/2016sum.csv -------------------------------------------------------------------------------- /src/test/java/com/zzkun/controller/AuthControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.controller; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Created by wzh on 2017/7/1. 9 | */ 10 | public class AuthControllerTest { 11 | @Test 12 | public void doModify() throws Exception { 13 | 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/AssignResultRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | /** 10 | * Created by kun on 2016/7/14. 11 | */ 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 14 | public class AssignResultRepoTest { 15 | 16 | @Autowired 17 | private AssignResultRepo assignResultRepo; 18 | 19 | @Test 20 | public void findAll() throws Exception { 21 | 22 | } 23 | 24 | @Test 25 | public void findOne() throws Exception { 26 | 27 | } 28 | 29 | @Test 30 | public void count() throws Exception { 31 | System.out.println(assignResultRepo.count()); 32 | } 33 | 34 | @Test 35 | public void delete() throws Exception { 36 | 37 | } 38 | 39 | @Test 40 | public void save() throws Exception { 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/ContestRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Contest; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | import javax.persistence.criteria.Predicate; 11 | import java.util.List; 12 | 13 | /** 14 | * Created by kun on 2016/7/13. 15 | */ 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 18 | public class ContestRepoTest { 19 | 20 | @Autowired 21 | private ContestRepo contestRepo; 22 | 23 | @Test 24 | public void findAll() throws Exception { 25 | // List all = contestRepo.findAll(); 26 | // for (Contest contest : all) { 27 | // System.out.println(contest); 28 | // System.out.println(contest.getRanks()); 29 | // } 30 | // Contest contest = new Contest(); 31 | // contest.setAddUid(1); 32 | // List all = contestRepo.findAll(Example.of(contest)); 33 | // System.out.println(all); 34 | List list = contestRepo.findAll((root, query, cb) -> { 35 | Predicate p1 = cb.equal(root.get("addUid").as(Integer.class), 1); 36 | return query.where(p1).getRestriction(); 37 | }); 38 | System.out.println(list); 39 | } 40 | 41 | @Test 42 | public void findOne() throws Exception { 43 | // Contest one = contestRepo.findOne(1); 44 | // System.out.println(one); 45 | // System.out.println(one.getRanks()); 46 | // Pair pair = one.calcTemesStdScore(-20, 100); 47 | // System.out.println(Arrays.toString(pair.getLeft())); 48 | // System.out.println(Arrays.toString(pair.getRight())); 49 | } 50 | 51 | @Test 52 | public void save() throws Exception { 53 | // List list = FileUtils.readLines(new File("temp/rank"), "utf8"); 54 | // Contest contest = vjRankParser.parseRank(list, new HashMap<>()); 55 | // contestRepo.save(contest); 56 | } 57 | 58 | @Test(timeout = 10000) 59 | public void calcTemesStdScore() throws Exception { 60 | // List list = FileUtils.readLines(new File("temp/rank"), "utf8"); 61 | // for(int i = 0; i < 1000; ++i) { 62 | // Contest contest = vjRankParser.parseRank(list, new HashMap<>()); 63 | // double[] doubles = contest.calcTaamScore(20, 100); 64 | // assertEquals(doubles.length, contest.getRanks().size()); 65 | // } 66 | } 67 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/ExtOjLinkRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.ExtOjLink; 4 | import com.zzkun.model.OJType; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by kun on 2016/10/31. 15 | */ 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 18 | public class ExtOjLinkRepoTest { 19 | 20 | @Autowired private ExtOjLinkRepo repo; 21 | 22 | @Test 23 | public void findAll() throws Exception { 24 | List all = repo.findAll(); 25 | System.out.println(all); 26 | } 27 | 28 | @Test 29 | public void findOne() throws Exception { 30 | ExtOjLink link = new ExtOjLink(); 31 | link.setOj(OJType.HDU); 32 | link.setIndexLink("http://acm.hdu.edu.cn/"); 33 | link.setPbStatusLink("http://acm.hdu.edu.cn/statistic.php?pid=%s"); 34 | link.setProblemLink("http://acm.hdu.edu.cn/showproblem.php?pid=%s"); 35 | link.setUserInfoLink("http://acm.hdu.edu.cn/userstatus.php?user=%s"); 36 | repo.save(link); 37 | } 38 | 39 | @Test 40 | public void count() throws Exception { 41 | 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/FixedTeamRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.FixedTeam; 4 | import com.zzkun.model.User; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | import static org.junit.Assert.*; 16 | 17 | /** 18 | * Created by kun on 2016/8/19. 19 | */ 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 22 | public class FixedTeamRepoTest { 23 | 24 | @Autowired private FixedTeamRepo fixedTeamRepo; 25 | @Autowired private TrainingRepo trainingRepo; 26 | @Autowired private UserRepo userRepo; 27 | 28 | @Test 29 | public void findAll() throws Exception { 30 | 31 | } 32 | 33 | @Test 34 | public void save() throws Exception { 35 | } 36 | 37 | @Test 38 | public void findOne() throws Exception { 39 | } 40 | 41 | @Test 42 | public void count() throws Exception { 43 | } 44 | 45 | @Test 46 | public void delete() throws Exception { 47 | 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/RatingRecordRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * Created by kun on 2016/8/14. 13 | */ 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 16 | public class RatingRecordRepoTest { 17 | 18 | @Autowired private RatingRecordRepo ratingRecordRepo; 19 | 20 | @Test 21 | public void findAll() throws Exception { 22 | 23 | } 24 | 25 | @Test 26 | public void save() throws Exception { 27 | 28 | } 29 | 30 | @Test 31 | public void deleteInBatch() throws Exception { 32 | 33 | } 34 | 35 | @Test 36 | public void save1() throws Exception { 37 | 38 | } 39 | 40 | @Test 41 | public void findOne() throws Exception { 42 | 43 | } 44 | 45 | @Test 46 | public void findOne1() throws Exception { 47 | 48 | } 49 | 50 | @Test 51 | public void findAll1() throws Exception { 52 | 53 | } 54 | 55 | @Test 56 | public void count() throws Exception { 57 | 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/StageRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Stage; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by kun on 2016/7/13. 14 | */ 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 17 | public class StageRepoTest { 18 | 19 | @Autowired 20 | private StageRepo stageRepo; 21 | 22 | @Test 23 | public void findAll() throws Exception { 24 | List all = stageRepo.findAll(); 25 | System.out.println(all); 26 | } 27 | 28 | @Test 29 | public void save() throws Exception { 30 | 31 | } 32 | 33 | @Test 34 | public void findOne() throws Exception { 35 | 36 | } 37 | 38 | @Test 39 | public void findByTrainingId() throws Exception { 40 | // System.out.println(stageRepo.findByTrainingId(1)); 41 | } 42 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/TrainingRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.Training; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | import java.time.LocalDate; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Created by Administrator on 2016/7/20. 16 | */ 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 19 | public class TrainingRepoTest { 20 | 21 | @Autowired private TrainingRepo trainingRepo; 22 | 23 | @Test 24 | public void save() throws Exception { 25 | Training training = new Training(); 26 | training.setStartDate(LocalDate.now()); 27 | training.setEndDate(LocalDate.now()); 28 | training.setName("第10次集训"); 29 | training.setRemark("第10次集训开始啦~~~"); 30 | trainingRepo.save(training); 31 | } 32 | 33 | @Test 34 | public void findOne() throws Exception { 35 | Training one = trainingRepo.findOne(2); 36 | System.out.println(one); 37 | System.out.println(one.getStageList()); 38 | } 39 | 40 | @Test 41 | public void findAll() throws Exception { 42 | System.out.println(trainingRepo.findAll()); 43 | } 44 | 45 | @Test 46 | public void delete() throws Exception { 47 | 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/UJoinTRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.UJoinT; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Example; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * Created by Administrator on 2016/7/21. 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 21 | public class UJoinTRepoTest { 22 | 23 | @Autowired private UJoinTRepo uJoinTRepo; 24 | 25 | 26 | @Test 27 | public void save() throws Exception { 28 | // List list = Arrays.asList(92, 99, 103); 29 | // for (Integer integer : list) { 30 | // UJoinT cur = new UJoinT(integer, 4, UJoinT.Status.Pending); 31 | // uJoinTRepo.save(cur); 32 | // } 33 | } 34 | 35 | @Test 36 | public void findOne() throws Exception { 37 | 38 | } 39 | 40 | @Test 41 | public void findByUserIdAndTrainingId() throws Exception { 42 | // UJoinT res = uJoinTRepo.findByUserIdAndTrainingId(2, 1); 43 | // System.out.println(res); 44 | // res.setStatus(UJoinT.Status.Success); 45 | // uJoinTRepo.save(res); 46 | // System.out.println(res); 47 | } 48 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/UserACPbRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.OJType; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | /** 11 | * Created by Administrator on 2017/2/26 0026. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 15 | public class UserACPbRepoTest { 16 | 17 | @Autowired private UserACPbRepo repo; 18 | 19 | @Test 20 | public void countByOjNameAndOjPbId() throws Exception { 21 | for(int i = 1001; i <= 1200; ++i) { 22 | long l = repo.countByOjNameAndOjPbId(OJType.HDU, Integer.toString(i)); 23 | System.out.println(i + " " + l); 24 | } 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/dao/UserRepoTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.dao; 2 | 3 | import com.zzkun.model.User; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.PageRequest; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | /** 13 | * Created by kun on 2016/7/7. 14 | */ 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 17 | public class UserRepoTest { 18 | 19 | @Autowired 20 | private UserRepo userRepo; 21 | 22 | 23 | @Test 24 | public void findAll() throws Exception { 25 | System.out.println(userRepo.findAll()); 26 | } 27 | 28 | @Test 29 | public void count() throws Exception { 30 | System.out.println(userRepo.count()); 31 | } 32 | 33 | @Test 34 | public void findOne() throws Exception { 35 | System.out.println(userRepo.findByUsername("abc")); 36 | } 37 | 38 | @Test 39 | public void save() throws Exception { 40 | // File file = new File(getClass().getClassLoader().getResource("uhunt/2016sum.csv").getFile()); 41 | // List lines = FileUtils.readLines(file, "utf8"); 42 | // for (String line : lines) { 43 | // String[] split = line.split(","); 44 | // User user = new User(split[2], "123456", split[1], Integer.parseInt(split[0]), split[2], split[3], User.Type.New); 45 | // userRepo.save(user); 46 | // } 47 | // User user = new User("456", "456"); 48 | // userRepo.save(user); 49 | } 50 | 51 | // @Test 52 | // public void deleteAllInBatch() throws Exception { 53 | // userRepo.deleteAllInBatch(); 54 | // } 55 | 56 | @Test 57 | public void findByUvaId() throws Exception { 58 | User user = userRepo.findByUvaId(66666); 59 | System.out.println(user); 60 | } 61 | 62 | @Test 63 | public void findAll_pager() throws Exception { 64 | PageRequest pageRequest = new PageRequest(0, 2); 65 | Page all = userRepo.findAll(pageRequest); 66 | System.out.println(all.getContent()); 67 | } 68 | 69 | @Test 70 | public void findByRealName() throws Exception { 71 | User user = userRepo.findByRealName("张正锟"); 72 | System.out.println(user); 73 | } 74 | 75 | @Test 76 | public void mytest() throws Exception { 77 | User user = userRepo.findByUsername("kun368"); 78 | System.out.println(user); 79 | System.out.println(user.getuJoinTList()); 80 | System.out.println(user.getAcPbList()); 81 | } 82 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/CFBCServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.service; 2 | 3 | import com.zzkun.model.CFUserInfo; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * Created by Administrator on 2016/8/5. 14 | */ 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 17 | public class CFBCServiceTest { 18 | 19 | @Autowired private CFBCService CFBCService; 20 | 21 | @Test 22 | public void flushCFUserInfo() throws Exception { 23 | CFBCService.flushCFUserInfos(); 24 | } 25 | 26 | @Test 27 | public void getCFUserInfoMap() throws Exception { 28 | Map map = CFBCService.getCFUserInfoMap(); 29 | System.out.println(map); 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/ContestSearchServiceTest.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service 2 | 3 | import org.junit.Test 4 | import org.junit.runner.RunWith 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.test.context.ContextConfiguration 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 8 | 9 | /** 10 | * Created by kun36 on 2016/12/29. 11 | */ 12 | @RunWith(SpringJUnit4ClassRunner::class) 13 | @ContextConfiguration(locations = arrayOf("classpath*:springmvc-servlet.xml")) 14 | class ContestSearchServiceTest { 15 | 16 | @Autowired lateinit var serv : ContestSearchService 17 | 18 | @Test 19 | fun splitParms() { 20 | 21 | } 22 | 23 | @Test 24 | fun find() { 25 | val list = serv.find("大学生") 26 | println(list) 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/OJContestServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.service; 2 | 3 | import com.zzkun.model.OJContest; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Created by Administrator on 2016/8/3. 16 | */ 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 19 | public class OJContestServiceTest { 20 | 21 | @Autowired private OJContestService ojContestService; 22 | 23 | @Test 24 | public void getRecents() throws Exception { 25 | List recents = ojContestService.getRecents(); 26 | System.out.println(recents); 27 | } 28 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/RatingServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.service; 2 | 3 | import com.zzkun.model.Contest; 4 | import com.zzkun.model.RatingRecord; 5 | import jskills.Rating; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by kun on 2016/8/18. 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 21 | public class RatingServiceTest { 22 | 23 | @Autowired private RatingService ratingService; 24 | 25 | @Autowired private TrainingService trainingService; 26 | 27 | @Test 28 | public void generateRating() throws Exception { 29 | Contest contest = trainingService.getContest(135); 30 | List contestList = new ArrayList<>(); 31 | contestList.add(contest); 32 | List list = ratingService.generateRating(contestList, RatingRecord.Scope.Global, 1, RatingRecord.Type.Personal, 1.0); 33 | System.out.println(list); 34 | Collections.sort(list, (o1, o2) -> { 35 | Rating rating1 = new Rating(o1.getMean(), o1.getStandardDeviation()); 36 | Rating rating2 = new Rating(o2.getMean(), o2.getStandardDeviation()); 37 | return Double.compare(rating2.getConservativeRating(), rating1.getConservativeRating()); 38 | }); 39 | for (RatingRecord record : list) { 40 | Rating rating = new Rating(record.getMean(), record.getStandardDeviation()); 41 | System.out.println(record.getIdentifier() + ": " + rating.getMean() + "\t " + rating.getStandardDeviation() + "\t " + rating.getConservativeRating()); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/UVaServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.service; 2 | 3 | import com.zzkun.service.extoj.UVaService; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | /** 10 | * Created by kun on 2016/7/14. 11 | */ 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 14 | public class UVaServiceTest { 15 | 16 | @Autowired private UVaService uVaService; 17 | 18 | // @Test 19 | // public void getBookName() throws Exception { 20 | // List bookName = uVaService.getBookName(); 21 | // System.out.println(bookName); 22 | // } 23 | // 24 | // @Test 25 | // public void getChapterName() throws Exception { 26 | // List chapterName = uVaService.getChapterName(); 27 | // System.out.println(chapterName); 28 | // } 29 | // 30 | 31 | 32 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/extoj/ExtOjServiceTest.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.UserRepo 4 | import com.zzkun.service.ExtOjService 5 | import org.junit.Test 6 | import org.junit.runner.RunWith 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.test.context.ContextConfiguration 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 10 | 11 | /** 12 | * Created by kun on 2016/9/30. 13 | */ 14 | @RunWith(SpringJUnit4ClassRunner::class) 15 | @ContextConfiguration(locations = arrayOf("classpath*:springmvc-servlet.xml")) 16 | class ExtOjServiceTest { 17 | 18 | @Autowired 19 | lateinit var extOjService: ExtOjService 20 | 21 | @Autowired 22 | lateinit var userRepo: UserRepo 23 | 24 | 25 | @Test 26 | fun flushACDB() { 27 | extOjService.flushACDB() 28 | } 29 | 30 | @Test 31 | fun getUserAC() { 32 | val user = userRepo.findByUsername("kun368") 33 | val list = extOjService.getUserAC(user) 34 | list.forEach(::println) 35 | } 36 | 37 | @Test 38 | fun flushPbInfoDB() { 39 | extOjService.flushPbInfoDB() 40 | } 41 | 42 | @Test 43 | fun test1() { 44 | extOjService.flushPbInfoOfCpt() 45 | } 46 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/extoj/UVaExtOjServiceTest.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.UserRepo 4 | import org.junit.Test 5 | import org.junit.runner.RunWith 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.test.context.ContextConfiguration 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 9 | 10 | /** 11 | * Created by kun on 2016/9/29. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner::class) 14 | @ContextConfiguration(locations = arrayOf("classpath*:springmvc-servlet.xml")) 15 | class UVaExtOjServiceTest { 16 | 17 | @Autowired 18 | lateinit var uVaUserACService: UVaService 19 | 20 | @Autowired 21 | lateinit var userRepo: UserRepo 22 | 23 | @Test 24 | fun userACPbs() { 25 | // val user = userRepo.findByUsername("kun368") 26 | // val list = uVaUserACService.getUserACPbsOnline(user) 27 | // for(i in list) { 28 | // println("${i.ojName}__${i.ojPbId}") 29 | // } 30 | // println(list.size) 31 | } 32 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/service/extoj/VJudgeServiceTest.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.service.extoj 2 | 3 | import com.zzkun.dao.UserRepo 4 | import org.junit.Test 5 | import org.junit.runner.RunWith 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.test.context.ContextConfiguration 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 9 | 10 | /** 11 | * Created by kun on 2016/9/29. 12 | */ 13 | 14 | @RunWith(SpringJUnit4ClassRunner::class) 15 | @ContextConfiguration(locations = arrayOf("classpath*:springmvc-servlet.xml")) 16 | class VJudgeServiceTest { 17 | 18 | @Autowired 19 | lateinit var vjudgeService: VJudgeService 20 | 21 | @Autowired 22 | lateinit var userRepo: UserRepo 23 | 24 | @Test 25 | fun userACPbs() { 26 | // val user = userRepo.findByUsername("kun368") 27 | // val list = vjudgeService.getUserACPbsOnline(user) 28 | // for (acPb in list) { 29 | // println(acPb) 30 | // } 31 | // println(list.size) 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/uhunt/UHuntWebGetterTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.uhunt; 2 | 3 | import com.zzkun.util.web.UHuntWebGetter; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | /** 11 | * Created by kun on 2016/7/7. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 15 | public class UHuntWebGetterTest { 16 | 17 | @Autowired 18 | private UHuntWebGetter webGetter; 19 | 20 | @Test 21 | public void allPbInfo() throws Exception { 22 | // List list = webGetter.allPbInfo(); 23 | // System.out.println(list); 24 | } 25 | 26 | @Test 27 | public void allPbInfo2() throws Exception { 28 | // List list = webGetter.allPbInfo2(link); 29 | // System.out.println(list); 30 | } 31 | 32 | @Test 33 | public void uname2uid() throws Exception { 34 | 35 | } 36 | 37 | @Test 38 | public void userACSubmits() throws Exception { 39 | // List list = webGetter.userACSubmits(617781, link); 40 | // System.out.println(list); 41 | // System.out.println(list.size()); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/uhunt/UhuntTreeManagerTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.uhunt; 2 | 3 | import com.zzkun.util.uhunt.UhuntTreeManager; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | /** 11 | * Created by kun on 2016/7/8. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 15 | public class UhuntTreeManagerTest { 16 | 17 | @Autowired 18 | private UhuntTreeManager uhuntTreeManager; 19 | 20 | @Test 21 | public void getChapterMap() throws Exception { 22 | System.out.println(uhuntTreeManager.getCptNodes()); 23 | } 24 | 25 | @Test 26 | public void getBookMap() throws Exception { 27 | System.out.println(uhuntTreeManager.getBookNodes()); 28 | } 29 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/assign/TeamAssignServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.assign; 2 | 3 | import com.zzkun.dao.UserRepo; 4 | import com.zzkun.model.AssignResult; 5 | import com.zzkun.model.User; 6 | import com.zzkun.service.TeamAssignService; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by Administrator on 2016/7/25. 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 21 | public class TeamAssignServiceTest { 22 | 23 | @Autowired private UserRepo userRepo; 24 | 25 | @Autowired private TeamAssignService teamAssignService; 26 | 27 | @Test 28 | public void assign() throws Exception { 29 | List all = userRepo.findAll(); 30 | List users = new ArrayList<>(); 31 | for (User user : all) 32 | users.add(user.getId()); 33 | teamAssignService.assign(users, 5, AssignResult.Type.NoRepeat); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/bcapi/BCWebGetterTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.bcapi; 2 | 3 | import com.zzkun.util.web.BCWebGetter; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | /** 11 | * Created by kun on 2016/8/9. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 15 | public class BCWebGetterTest { 16 | 17 | @Autowired private BCWebGetter bcWebGetter; 18 | 19 | @Test 20 | public void getBCUserInfo() throws Exception { 21 | for(int i = 0; i < 100; ++i) 22 | System.out.println(bcWebGetter.getBCUserInfo("RongeRace")); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/cfapi/CFWebGetterTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.cfapi; 2 | 3 | import com.zzkun.model.CFUserInfo; 4 | import com.zzkun.util.web.CFWebGetter; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by Administrator on 2016/7/31. 16 | */ 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 19 | public class CFWebGetterTest { 20 | 21 | @Autowired private CFWebGetter cfWebGetter; 22 | 23 | @Test 24 | public void getUserInfos() throws Exception { 25 | List list = cfWebGetter.getUserInfos(Arrays.asList("kun368", "tourist", "12313456465431321")); 26 | System.out.println(list); 27 | } 28 | 29 | @Test 30 | public void getUserInfos2() throws Exception { 31 | List list = cfWebGetter.getUserInfos2(Arrays.asList("kun368", "tourist", "12313456465431321")); 32 | System.out.println(list); 33 | } 34 | 35 | @Test 36 | public void userACPbs() throws Exception { 37 | List userACPbs = cfWebGetter.userACPbs("kun368", "http://codeforces.com/api/user.status?handle=%s"); 38 | System.out.println(userACPbs); 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/cluster/AgnesClustererTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.cluster; 2 | 3 | import com.zzkun.service.TrainingService; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | /** 11 | * Created by Administrator on 2016/8/4. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 15 | public class AgnesClustererTest { 16 | 17 | @Autowired private TrainingService trainingService; 18 | 19 | 20 | @Test 21 | public void cluster() throws Exception { 22 | // Contest contest = trainingService.getContest(7); 23 | // double[] left = trainingService.calcTaamScore(contest).getLeft(); 24 | // System.out.println(Arrays.toString(left)); 25 | // 26 | // for(int i = 0; i < 100; ++i) { 27 | // AgnesClusterer clusterer = new AgnesClusterer(left); 28 | // clusterer.clusterAll(); 29 | // } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/elo/MyELOTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.elo; 2 | 3 | import jskills.Rating; 4 | import org.apache.commons.lang3.tuple.Pair; 5 | import org.junit.Test; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Created by kun on 2016/8/13. 16 | */ 17 | public class MyELOTest { 18 | 19 | private MyELO myELO = new MyELO(); 20 | 21 | @Test 22 | public void calcPersonal() throws Exception { 23 | // List> list = new ArrayList<>(); 24 | // list.add(Pair.of("zzk", 1)); 25 | // list.add(Pair.of("heheda", 2)); 26 | // list.add(Pair.of("nihao", 3)); 27 | // Map map = myELO.calcPersonal(new HashMap<>(), list); 28 | // System.out.println(map); 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/rank/RankCalculatorTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.rank; 2 | 3 | import com.zzkun.service.TrainingService; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | /** 11 | * Created by kun on 2016/8/28. 12 | */ 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 15 | public class RankCalculatorTest { 16 | 17 | @Autowired private TrainingService trainingService; 18 | 19 | @Test 20 | public void calcAll() throws Exception { 21 | // Contest contest = trainingService.getContest(155); 22 | // RankCalculator calculator = new RankCalculator(contest); 23 | // calculator.calcAll(); 24 | // double[] teamScore = calculator.getTeamScore(); 25 | // int[] teamRank = calculator.getTeamRank(); 26 | // System.out.println(Arrays.toString(teamScore)); 27 | // System.out.println(Arrays.toString(teamRank)); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/rank/VJRankParserTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.rank; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * Created by kun on 2016/7/13. 7 | */ 8 | public class VJRankParserTest { 9 | 10 | VJRankParser parser = new VJRankParser(); 11 | 12 | @Test 13 | public void parse() throws Exception { 14 | // List list = FileUtils.readLines(new File("temp/rank"), "utf8"); 15 | // Contest contest = parser.parseRank(list, new HashMap<>()); 16 | // System.out.println(contest); 17 | } 18 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/web/HDUWebGetterTest.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.web 2 | 3 | import org.junit.Test 4 | 5 | /** 6 | * Created by kun on 2016/10/22. 7 | */ 8 | class HDUWebGetterTest { 9 | @Test 10 | fun userACPbs() { 11 | 12 | } 13 | 14 | @Test 15 | fun allPbInfo() { 16 | 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/web/HttpUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.web; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * Created by kun on 2016/7/13. 13 | */ 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration(locations = "classpath*:springmvc-servlet.xml") 16 | public class HttpUtilTest { 17 | 18 | @Autowired 19 | private HttpUtil httpUtil; 20 | 21 | @Test 22 | public void readURL() throws Exception { 23 | System.out.println(httpUtil.readURL("http://acm.zzkun.com")); 24 | } 25 | } -------------------------------------------------------------------------------- /src/test/java/com/zzkun/util/web/VJudgeWebGetterTest.kt: -------------------------------------------------------------------------------- 1 | package com.zzkun.util.web 2 | 3 | import org.junit.Test 4 | import org.junit.runner.RunWith 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.test.context.ContextConfiguration 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 8 | 9 | /** 10 | * Created by kun36 on 2016/12/28. 11 | */ 12 | 13 | @RunWith(SpringJUnit4ClassRunner::class) 14 | @ContextConfiguration(locations = arrayOf("classpath*:springmvc-servlet.xml")) 15 | class VJudgeWebGetterTest { 16 | 17 | @Autowired lateinit var getter: VJudgeWebGetter 18 | 19 | 20 | @Test 21 | fun getUserACMap() { 22 | val map = getter.getUserACMap("Chengrui1996", "http://vjudge.net/user/%s") 23 | println(map) 24 | } 25 | } -------------------------------------------------------------------------------- /temp/vjudge: -------------------------------------------------------------------------------- 1 | Rank Id Solve Penalty A B C D E F 2 | 1 Chengrui1996(王成瑞) 5 6:52:23 0:21:22 0:30:09 1:37:04 0:46:33 2:57:15(-2) 3 | 2 AC_Arthur(王伟铸) 4 4:23:31 0:10:21 0:32:44 1:29:54 2:10:32 4 | 3 aozil110(杨康) 4 6:06:42 0:10:07(-1) 0:21:09(-1) 1:37:21(-1) 2:58:05 5 | 4 Lanius_(马中行) 4 11:58:35 0:18:21(-1) 0:34:06 3:32:37 6:53:31(-1) 6 | 5 wangjinhao(王锦浩) 4 15:11:22 0:20:20 0:39:14(-1) 12:01:53 1:29:55(-1) 7 | 6 fan_cheng(樊程) 4 33:29:56 0:10:42 0:24:14 16:47:17(-1) 15:47:43 (-1)  (-1) 8 | 7 Jindong_s(孙近东) 4 34:31:15 0:12:43 0:34:45(-1) 18:02:14 15:21:33 9 | 8 tzf(田宗飞) 3 6:19:11 0:25:56(-1) 0:38:28 3:14:47(-5) 10 | 9 xuziye0327(马禺喆) 3 6:37:35 1:38:19 1:47:31  (-2) 3:11:45 11 | 10 wang648979(王文晖) 3 6:40:20 1:34:42(-1) 1:48:47  (-2) 1:56:51(-3) 12 | 11 J_song(宋锦鹏) 3 7:38:06 2:05:04(-1) 2:47:32(-1) 1:45:30(-1) 13 | 12 kim0403(王荣勋) 3 7:48:43 0:31:05(-3) 0:55:41 2:21:57(-9) 14 | 13 xvzhitao(徐芝涛) 3 13:36:55 1:12:00(-4) 2:06:44(-2) 6:38:11(-5) 15 | 14 shao123(邵国锋) 3 17:10:50 0:45:36 1:00:00(-1) 15:05:14 16 | 15 TianTengtt(田腾) 3 17:51:45 0:10:21 0:22:24 15:59:00(-4) 17 | 16 BLGAY(王硕) 3 18:11:01 0:12:04 0:27:40(-1) 16:11:17(-3) 18 | 17 cleverlove(李震) 3 19:10:49 0:18:06 0:40:25(-1) 16:32:18(-4) 19 | 18 woshichaoren000(张成泽) 3 21:07:18 0:18:46 2:21:58(-5) 16:26:34(-1) 20 | 19 cccoconut(程晓华) 3 38:45:00 0:23:13(-1) 16:44:35(-4) 17:57:12(-6) 21 | 20 201501061022(秦培发) 2 0:50:05 0:21:14 0:28:51  (-2) 22 | 21 YIJIA(庞逸卿) 2 0:50:54 0:20:08 0:30:46 23 | 22 fanhuanji(郭孝通) 2 1:02:59 0:16:24 0:26:35(-1)  (-5) 24 | 23 201401061041(周俊) 2 1:41:41 0:37:19 0:44:22(-1)  (-1) 25 | 24 lsltbh(盛振婷) 2 1:53:28 0:18:25 1:15:03(-1) 26 | 25 leehaoze(李浩泽) 2 2:09:13 0:25:52(-1) 1:23:21 27 | 26 yyAC(姜悦怡) 2 2:26:30 0:45:19 1:21:11(-1) 28 | 27 test1997(牛余庆) 2 4:39:58 0:52:29 2:47:29(-3) 29 | 28 201501060925(袁月平) 2 4:52:52 1:58:45(-4) 1:34:07 30 | 29 Yangssenleo(杨磊) 2 6:53:27 0:29:54 3:23:33(-9) 31 | 30 KSGT00519750(林威锟) 2 29:20:34 14:34:27 14:46:07 32 | 31 201501140625(吴健伟) 1 0:20:10 0:20:10  (-3) 33 | 32 Coder_Yang(杨旭) 1 1:30:55  (-2) 1:10:55(-1) 34 | 33 Incredible_(尹冰) 1 2:20:18 1:40:18(-2) 35 | 34 chenxue(陈雪) 1 15:32:13 15:32:13 -------------------------------------------------------------------------------- /web/WEB-INF/cache/userId_.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kun368/ACManager/137388ba23df959f262fdb075e35873a98b6accd/web/WEB-INF/cache/userId_.html -------------------------------------------------------------------------------- /web/WEB-INF/jsp/directionOfAcmer.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: wzh 4 | Date: 2017/5/23 5 | Time: 20:16 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 10 | 11 | 12 | 13 | 历届队员去向 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |

29 | 30 |
31 |
32 |
33 |
34 | 37 |
38 |
39 |
40 |
41 | 42 | 43 |
44 |
45 |
46 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
专业姓名工作去向
${contest.oj}${contest.name}${contest.start_time}${contest.week}${contest.access}
70 |
71 |
72 |
73 |
74 |
75 | 76 | 77 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /web/WEB-INF/jsp/footerInfo.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%--
--%> 4 | <%----%> 5 | <%--
--%> 6 |
7 |
8 |
9 |
10 |

11 | Developer: 12 | Geekun | 13 | Kela | 14 | Yang 15 |   16 | GitHub: 17 |

18 |

19 |

20 |

All Copyright Reserved ©2016-2017 SDUST ACM Team.

21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /web/WEB-INF/jsp/lost.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: Administrator 4 | Date: 2016/7/7 5 | Time: 9:27 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 10 | 11 | 12 | 13 | 账号密码找回 - ACManager 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 |
36 | 41 |

42 | 如果您忘记密码:由于密码已经加密,只能重新设定,请将您的新密码在 43 | 此处 44 | 用SHA1加密后,联系管理员(QQ1004788567)修改。 45 |

46 |
47 |

48 | 如果您忘记账号:请在下面的对应表中查找是否有您的信息,如果没有请重新注册。 49 |

50 |
51 | 52 |

${useri.username}    -    ${useri.realName}    -    ${useri.major}

53 |
54 |
55 |
56 |
57 |
58 |
59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /web/WEB-INF/jsp/page_404.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: Administrator 4 | Date: 2016/7/8 5 | Time: 8:56 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 10 | 11 | 12 | 13 | 404 - ACManager 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
31 |
32 |
33 |
34 | 37 |
38 |
39 |
40 |
41 | 42 | 43 |
44 |
45 |
46 |
47 | 48 |
49 |
50 |
51 |
52 |
53 | 54 | 55 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /web/WEB-INF/jsp/training_topbar.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: kun 4 | Date: 2016/8/21 5 | Time: 18:10 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | -------------------------------------------------------------------------------- /web/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | springmvc 9 | org.springframework.web.servlet.DispatcherServlet 10 | 11 | contextConfigLocation 12 | classpath:springmvc-servlet.xml 13 | 14 | 1 15 | 16 | 17 | springmvc 18 | / 19 | 20 | 21 | CharacterEncodingFilter 22 | org.springframework.web.filter.CharacterEncodingFilter 23 | 24 | encoding 25 | utf-8 26 | 27 | 28 | 29 | CharacterEncodingFilter 30 | /* 31 | 32 | 33 | 34 | 404 35 | /404 36 | 37 | 38 | --------------------------------------------------------------------------------