Showing
10 changed files
with
107 additions
and
264 deletions
| ... | @@ -3,7 +3,6 @@ import { useDispatch, useSelector } from 'react-redux'; | ... | @@ -3,7 +3,6 @@ import { useDispatch, useSelector } from 'react-redux'; |
| 3 | import { withRouter } from 'react-router-dom'; | 3 | import { withRouter } from 'react-router-dom'; |
| 4 | import HomeForm from '../../components/home/HomeForm'; | 4 | import HomeForm from '../../components/home/HomeForm'; |
| 5 | import { getPROFILE } from '../../modules/profile'; | 5 | import { getPROFILE } from '../../modules/profile'; |
| 6 | -import { analyzeBJ } from '../../lib/util/analyzeBJ'; | ||
| 7 | const HomeContainer = ({ history }) => { | 6 | const HomeContainer = ({ history }) => { |
| 8 | const dispatch = useDispatch(); | 7 | const dispatch = useDispatch(); |
| 9 | const { user, profile } = useSelector(({ user, profile }) => ({ | 8 | const { user, profile } = useSelector(({ user, profile }) => ({ | ... | ... |
| ... | @@ -18,22 +18,22 @@ | ... | @@ -18,22 +18,22 @@ |
| 18 | 18 | ||
| 19 | ## API Table | 19 | ## API Table |
| 20 | 20 | ||
| 21 | -| group | description | method | URL | Detail | Auth | | 21 | +| group | description | method | URL | Detail | Auth | |
| 22 | -| ------- | --------------------------- | --------- | ------------------------ | -------- | --------- | | 22 | +| ------- | --------------------------- | --------- | ----------------------- | -------- | --------- | |
| 23 | -| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token | | 23 | +| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token | |
| 24 | -| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token | | 24 | +| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token | |
| 25 | -| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None | | 25 | +| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None | |
| 26 | -| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token | | 26 | +| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token | |
| 27 | -| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token | | 27 | +| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token | |
| 28 | -| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None | | 28 | +| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None | |
| 29 | -| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None | | 29 | +| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None | |
| 30 | -| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None | | 30 | +| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None | |
| 31 | -| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN | | 31 | +| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN | |
| 32 | -| profile | 유저 정보 받아오기 | POST | api/profile/getprofile | 바로가기 | JWT | | 32 | +| profile | 유저 정보 받아오기 | POST | api/profile/getprofile | 바로가기 | JWT | |
| 33 | -| profile | 추천 문제 조회 | GET | api/profile/recommend:id | 바로가기 | None | | 33 | +| profile | 추천 문제 조회 | POST | api/profile/recommend | 바로가기 | None | |
| 34 | -| notify | 슬랙 메시지 전송 요청 | POST | api/notify/ | | 34 | +| notify | 슬랙 메시지 전송 요청 | POST | api/notify/ | |
| 35 | | slack | 바로가기 | Jwt Token | | 35 | | slack | 바로가기 | Jwt Token | |
| 36 | -| auth | 로그인 | POST | api/auth/login | 바로가기 | None | | 36 | +| auth | 로그인 | POST | api/auth/login | 바로가기 | None | |
| 37 | -| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token | | 37 | +| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token | |
| 38 | -| auth | 회원가입 | POST | api/auth/register | 바로가기 | None | | 38 | +| auth | 회원가입 | POST | api/auth/register | 바로가기 | None | |
| 39 | -| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None | | 39 | +| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None | | ... | ... |
| ... | @@ -1286,3 +1286,38 @@ | ... | @@ -1286,3 +1286,38 @@ |
| 1286 | ::ffff:127.0.0.1 - - [24/Jun/2020:11:31:05 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 16266 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" | 1286 | ::ffff:127.0.0.1 - - [24/Jun/2020:11:31:05 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 16266 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" |
| 1287 | ::ffff:127.0.0.1 - - [24/Jun/2020:11:39:21 +0000] "POST /api/profile/getprofile HTTP/1.1" 401 12 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" | 1287 | ::ffff:127.0.0.1 - - [24/Jun/2020:11:39:21 +0000] "POST /api/profile/getprofile HTTP/1.1" 401 12 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" |
| 1288 | ::ffff:127.0.0.1 - - [24/Jun/2020:11:39:22 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 16266 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" | 1288 | ::ffff:127.0.0.1 - - [24/Jun/2020:11:39:22 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 16266 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" |
| 1289 | +::ffff:127.0.0.1 - - [24/Jun/2020:13:41:48 +0000] "PATCH /api/profile/syncBJ HTTP/1.1" 200 33281 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" | ||
| 1290 | +::ffff:127.0.0.1 - - [24/Jun/2020:13:42:48 +0000] "PATCH /api/profile/syncBJ HTTP/1.1" 200 33281 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54" | ||
| 1291 | +::1 - - [24/Jun/2020:13:52:15 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1292 | +::1 - - [24/Jun/2020:13:53:07 +0000] "POST /api/profile/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0" | ||
| 1293 | +::1 - - [24/Jun/2020:13:54:22 +0000] "POST /api/profile/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0" | ||
| 1294 | +::1 - - [24/Jun/2020:13:54:40 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1295 | +::1 - - [24/Jun/2020:13:55:32 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1296 | +::1 - - [24/Jun/2020:13:57:11 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1297 | +::1 - - [24/Jun/2020:13:57:49 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1298 | +::1 - - [24/Jun/2020:13:58:26 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1299 | +::ffff:127.0.0.1 - - [24/Jun/2020:13:58:49 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1300 | +::1 - - [24/Jun/2020:13:58:59 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1301 | +::1 - - [24/Jun/2020:13:59:43 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1302 | +::1 - - [24/Jun/2020:14:00:09 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1303 | +::1 - - [24/Jun/2020:14:02:01 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1304 | +::1 - - [24/Jun/2020:14:02:52 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1305 | +::1 - - [24/Jun/2020:14:03:53 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1306 | +::1 - - [24/Jun/2020:14:04:43 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1307 | +::1 - - [24/Jun/2020:14:05:13 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1308 | +::1 - - [24/Jun/2020:14:07:09 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1309 | +::1 - - [24/Jun/2020:14:08:00 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1310 | +::1 - - [24/Jun/2020:14:09:35 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1311 | +::1 - - [24/Jun/2020:14:10:57 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1312 | +::1 - - [24/Jun/2020:14:11:19 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1313 | +::1 - - [24/Jun/2020:14:12:04 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1314 | +::1 - - [24/Jun/2020:14:15:21 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1315 | +::1 - - [24/Jun/2020:14:15:24 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1316 | +::1 - - [24/Jun/2020:14:15:27 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1317 | +::1 - - [24/Jun/2020:14:15:28 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1318 | +::1 - - [24/Jun/2020:14:15:30 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1319 | +::1 - - [24/Jun/2020:14:15:35 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1320 | +::1 - - [24/Jun/2020:14:15:38 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1321 | +::1 - - [24/Jun/2020:14:15:40 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1322 | +::1 - - [24/Jun/2020:14:19:33 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ||
| 1323 | +::1 - - [24/Jun/2020:14:19:36 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0" | ... | ... |
| 1 | const Router = require("koa-router"); | 1 | const Router = require("koa-router"); |
| 2 | const profile = new Router(); | 2 | const profile = new Router(); |
| 3 | const profileCtrl = require("./profile.ctrl"); | 3 | const profileCtrl = require("./profile.ctrl"); |
| 4 | - | ||
| 5 | profile.post("/solved:id"); | 4 | profile.post("/solved:id"); |
| 6 | profile.get("/solvednum:id"); | 5 | profile.get("/solvednum:id"); |
| 7 | -profile.get("/recommendps:id"); | 6 | +profile.post("/recommend", profileCtrl.recommend); |
| 8 | profile.patch("/syncBJ", profileCtrl.syncBJ); | 7 | profile.patch("/syncBJ", profileCtrl.syncBJ); |
| 9 | profile.post("/setprofile", profileCtrl.setProfile); | 8 | profile.post("/setprofile", profileCtrl.setProfile); |
| 10 | profile.post("/getprofile", profileCtrl.getProfile); | 9 | profile.post("/getprofile", profileCtrl.getProfile); | ... | ... |
| ... | @@ -2,6 +2,9 @@ const Profile = require("../../models/profile"); | ... | @@ -2,6 +2,9 @@ const Profile = require("../../models/profile"); |
| 2 | const mongoose = require("mongoose"); | 2 | const mongoose = require("mongoose"); |
| 3 | const getBJ = require("../../util/getBJ"); | 3 | const getBJ = require("../../util/getBJ"); |
| 4 | const Joi = require("joi"); | 4 | const Joi = require("joi"); |
| 5 | +const analyzeBJ = require("../../util/analyzeBJ"); | ||
| 6 | +const compareBJ = require("../../util/compareBJ"); | ||
| 7 | +const problem_set = require("../../data/problem_set"); | ||
| 5 | 8 | ||
| 6 | const { ObjectId } = mongoose.Types; | 9 | const { ObjectId } = mongoose.Types; |
| 7 | 10 | ||
| ... | @@ -95,9 +98,10 @@ exports.syncBJ = async function (ctx) { | ... | @@ -95,9 +98,10 @@ exports.syncBJ = async function (ctx) { |
| 95 | } | 98 | } |
| 96 | const BJID = await profile.getBJID(); | 99 | const BJID = await profile.getBJID(); |
| 97 | let BJdata = await getBJ.getBJ(BJID); | 100 | let BJdata = await getBJ.getBJ(BJID); |
| 101 | + let BJdata_date = await analyzeBJ.analyzeBJ(BJdata); | ||
| 98 | const updateprofile = await Profile.findOneAndUpdate( | 102 | const updateprofile = await Profile.findOneAndUpdate( |
| 99 | { username: username }, | 103 | { username: username }, |
| 100 | - { solvedBJ: BJdata }, | 104 | + { solvedBJ: BJdata, solvedBJ_date: BJdata_date }, |
| 101 | { new: true } | 105 | { new: true } |
| 102 | ).exec(); | 106 | ).exec(); |
| 103 | ctx.body = updateprofile; | 107 | ctx.body = updateprofile; |
| ... | @@ -105,3 +109,33 @@ exports.syncBJ = async function (ctx) { | ... | @@ -105,3 +109,33 @@ exports.syncBJ = async function (ctx) { |
| 105 | ctx.throw(500, e); | 109 | ctx.throw(500, e); |
| 106 | } | 110 | } |
| 107 | }; | 111 | }; |
| 112 | + | ||
| 113 | +/* | ||
| 114 | +POST /api/proflie/recommend | ||
| 115 | +{ | ||
| 116 | + username: 'userid' | ||
| 117 | +} | ||
| 118 | + */ | ||
| 119 | +exports.recommend = async (ctx) => { | ||
| 120 | + const { username } = ctx.request.body; | ||
| 121 | + | ||
| 122 | + if (!username) { | ||
| 123 | + ctx.status = 401; | ||
| 124 | + return; | ||
| 125 | + } | ||
| 126 | + try { | ||
| 127 | + const profile = await Profile.findByUsername(username); | ||
| 128 | + if (!profile) { | ||
| 129 | + ctx.status = 401; | ||
| 130 | + return; | ||
| 131 | + } | ||
| 132 | + let unsolved_data = compareBJ.compareBJ( | ||
| 133 | + profile.getBJdata(), | ||
| 134 | + problem_set.problem_set | ||
| 135 | + ); | ||
| 136 | + ctx.body = compareBJ.randomItem(unsolved_data); | ||
| 137 | + //데이터가 비었을 떄 예외처리 필요 | ||
| 138 | + } catch (e) { | ||
| 139 | + ctx.throw(500, e); | ||
| 140 | + } | ||
| 141 | +}; | ... | ... |
| ... | @@ -6,6 +6,7 @@ const ProfileSchema = new Schema({ | ... | @@ -6,6 +6,7 @@ const ProfileSchema = new Schema({ |
| 6 | username: { type: String, required: true, unique: true }, | 6 | username: { type: String, required: true, unique: true }, |
| 7 | userBJID: String, | 7 | userBJID: String, |
| 8 | solvedBJ: Object, | 8 | solvedBJ: Object, |
| 9 | + solvedBJ_date: Object, | ||
| 9 | friendList: [String], | 10 | friendList: [String], |
| 10 | slackWebHookURL: String, | 11 | slackWebHookURL: String, |
| 11 | }); | 12 | }); |
| ... | @@ -15,6 +16,9 @@ ProfileSchema.statics.findByUsername = function (username) { | ... | @@ -15,6 +16,9 @@ ProfileSchema.statics.findByUsername = function (username) { |
| 15 | ProfileSchema.methods.getBJID = function () { | 16 | ProfileSchema.methods.getBJID = function () { |
| 16 | return this.userBJID; | 17 | return this.userBJID; |
| 17 | }; | 18 | }; |
| 19 | +ProfileSchema.methods.getBJdata = function () { | ||
| 20 | + return this.solvedBJ; | ||
| 21 | +}; | ||
| 18 | 22 | ||
| 19 | ProfileSchema.methods.serialize = function () { | 23 | ProfileSchema.methods.serialize = function () { |
| 20 | const data = this.toJSON(); | 24 | const data = this.toJSON(); | ... | ... |
| 1 | -/* | 1 | +let moment = require("moment"); |
| 2 | -2. 현재 날짜와의 차이 => | ||
| 3 | -3. 오늘 푼 문제 => 앞에서부터 순회하면서 데이트 같은거 찾기 | ||
| 4 | -3. 최근 일주일간 푼 문제 수 => 앞에서부터 순회하면서 - 값이 | ||
| 5 | -4. 추천 문제 => 정규 셋에서 없는거 찾기 | ||
| 6 | -5. 날짜별로 묶기. | ||
| 7 | -데이터베이스에서 처리하자 | ||
| 8 | -*/ | ||
| 9 | - | ||
| 10 | -let moment = require('moment'); | ||
| 11 | 2 | ||
| 12 | exports.analyzeBJ = function (solvedBJ) { | 3 | exports.analyzeBJ = function (solvedBJ) { |
| 13 | try { | 4 | try { |
| 14 | if (solvedBJ) { | 5 | if (solvedBJ) { |
| 15 | - console.log(solvedBJ[0]); | ||
| 16 | let presentDate = moment(); | 6 | let presentDate = moment(); |
| 17 | - let presentDate_str = presentDate.format('YYYYMMDD'); | 7 | + let presentDate_str = presentDate.format("YYYYMMDD"); |
| 18 | - let latestDate = moment(solvedBJ[0].solved_date, 'YYYYMMDD'); | 8 | + let latestDate = moment(solvedBJ[0].solved_date, "YYYYMMDD"); |
| 19 | - let difflatest = presentDate.diff(latestDate, 'days'); | 9 | + let difflatest = presentDate.diff(latestDate, "days"); |
| 20 | 10 | ||
| 21 | let solvedBJbyDATE = {}; | 11 | let solvedBJbyDATE = {}; |
| 22 | for (let i = 0; i < solvedBJ.length; i++) { | 12 | for (let i = 0; i < solvedBJ.length; i++) { |
| ... | @@ -34,13 +24,13 @@ exports.analyzeBJ = function (solvedBJ) { | ... | @@ -34,13 +24,13 @@ exports.analyzeBJ = function (solvedBJ) { |
| 34 | ? solvedBJbyDATE[presentDate_str].length | 24 | ? solvedBJbyDATE[presentDate_str].length |
| 35 | : 0; | 25 | : 0; |
| 36 | let returnOBJ = { | 26 | let returnOBJ = { |
| 37 | - latestDate: latestDate.format('YYYYMMDD'), | 27 | + latestDate: latestDate.format("YYYYMMDD"), |
| 38 | difflatest: difflatest, | 28 | difflatest: difflatest, |
| 39 | latestNum: latestNum, | 29 | latestNum: latestNum, |
| 40 | presentNum: presentNum, | 30 | presentNum: presentNum, |
| 41 | solvedBJbyDATE: solvedBJbyDATE, | 31 | solvedBJbyDATE: solvedBJbyDATE, |
| 42 | }; | 32 | }; |
| 43 | - console.log(returnOBJ); | 33 | + |
| 44 | return returnOBJ; | 34 | return returnOBJ; |
| 45 | } | 35 | } |
| 46 | } catch (e) { | 36 | } catch (e) { | ... | ... |
| 1 | -/* | ||
| 2 | -집중을 해보자. | ||
| 3 | -새거와 데이터가 있다. | ||
| 4 | -데이터 기준으로 새거에 자료가 있으면 넘어가기 | ||
| 5 | -없으면 새 배열에 추가 | ||
| 6 | -키만 모아둔 리스트를 만들자. | ||
| 7 | -그렇게 해서 | ||
| 8 | -반복은 새거 길이만큼 | ||
| 9 | -데이터에 있으면 추가 X | ||
| 10 | -없으면 추가 | ||
| 11 | -그렇게 반환 | ||
| 12 | -*/ | ||
| 13 | - | ||
| 14 | exports.compareBJ = function (solvedBJ_new, problem_set) { | 1 | exports.compareBJ = function (solvedBJ_new, problem_set) { |
| 15 | try { | 2 | try { |
| 16 | let new_obj = []; | 3 | let new_obj = []; |
| 17 | - for (let i = 0; i < solvedBJ.length; i++) { | 4 | + for (let i = 0; i < solvedBJ_new.length; i++) { |
| 18 | - if (solvedBJ_new[i].problem_number in problem_set) { | 5 | + if (!problem_set.includes(String(solvedBJ_new[i].problem_number))) { |
| 19 | new_obj.push(solvedBJ_new[i]); | 6 | new_obj.push(solvedBJ_new[i]); |
| 20 | } | 7 | } |
| 21 | } | 8 | } |
| 22 | - console.log(new_obj); | 9 | + return new_obj; |
| 23 | } catch (e) { | 10 | } catch (e) { |
| 24 | console.log(e); | 11 | console.log(e); |
| 25 | } | 12 | } |
| 26 | }; | 13 | }; |
| 14 | + | ||
| 15 | +exports.randomItem = function (a) { | ||
| 16 | + return a[Math.floor(Math.random() * a.length)]; | ||
| 17 | +}; | ... | ... |
| 1 | var getBJ = require("./getBJ"); | 1 | var getBJ = require("./getBJ"); |
| 2 | var fs = require("fs"); | 2 | var fs = require("fs"); |
| 3 | 3 | ||
| 4 | -let dataset = [ | ||
| 5 | - "1517", | ||
| 6 | - "2448", | ||
| 7 | - "1891", | ||
| 8 | - "1074", | ||
| 9 | - "2263", | ||
| 10 | - "1780", | ||
| 11 | - "11728", | ||
| 12 | - "10816", | ||
| 13 | - "10815", | ||
| 14 | - "2109", | ||
| 15 | - "1202", | ||
| 16 | - "1285", | ||
| 17 | - "2138", | ||
| 18 | - "1080", | ||
| 19 | - "11399", | ||
| 20 | - "1931", | ||
| 21 | - "11047", | ||
| 22 | - "15666", | ||
| 23 | - "15665", | ||
| 24 | - "15664", | ||
| 25 | - "15663", | ||
| 26 | - "15657", | ||
| 27 | - "15656", | ||
| 28 | - "15655", | ||
| 29 | - "15654", | ||
| 30 | - "15652", | ||
| 31 | - "15651", | ||
| 32 | - "15650", | ||
| 33 | - "15649", | ||
| 34 | - "6603", | ||
| 35 | - "10971", | ||
| 36 | - "10819", | ||
| 37 | - "10973", | ||
| 38 | - "10974", | ||
| 39 | - "10972", | ||
| 40 | - "7576", | ||
| 41 | - "1248", | ||
| 42 | - "2529", | ||
| 43 | - "15661", | ||
| 44 | - "14501", | ||
| 45 | - "1759", | ||
| 46 | - "14391", | ||
| 47 | - "14889", | ||
| 48 | - "1182", | ||
| 49 | - "11723", | ||
| 50 | - "1748", | ||
| 51 | - "6064", | ||
| 52 | - "1107", | ||
| 53 | - "3085", | ||
| 54 | - "2309", | ||
| 55 | - "1748", | ||
| 56 | - "14500", | ||
| 57 | - "1107", | ||
| 58 | - "1476", | ||
| 59 | - "3085", | ||
| 60 | - "2309", | ||
| 61 | - "1261", | ||
| 62 | - "13549", | ||
| 63 | - "14226", | ||
| 64 | - "13913", | ||
| 65 | - "1697", | ||
| 66 | - "1967", | ||
| 67 | - "1167", | ||
| 68 | - "11725", | ||
| 69 | - "2250", | ||
| 70 | - "1991", | ||
| 71 | - "7562", | ||
| 72 | - "2178", | ||
| 73 | - "4963", | ||
| 74 | - "2667", | ||
| 75 | - "1707", | ||
| 76 | - "11724", | ||
| 77 | - "1260", | ||
| 78 | - "13023", | ||
| 79 | - "11652", | ||
| 80 | - "1377", | ||
| 81 | - "11004", | ||
| 82 | - "10825", | ||
| 83 | - "2751", | ||
| 84 | - "9461", | ||
| 85 | - "1699", | ||
| 86 | - "9095", | ||
| 87 | - "2225", | ||
| 88 | - "2133", | ||
| 89 | - "11727", | ||
| 90 | - "11726", | ||
| 91 | - "1463", | ||
| 92 | - "2748", | ||
| 93 | - "2747", | ||
| 94 | - "11656", | ||
| 95 | - "10824", | ||
| 96 | - "2743", | ||
| 97 | - "10820", | ||
| 98 | - "10808", | ||
| 99 | - "11655", | ||
| 100 | - "11720", | ||
| 101 | - "1008", | ||
| 102 | - "10951", | ||
| 103 | - "2557", | ||
| 104 | - "1021", | ||
| 105 | - "1966", | ||
| 106 | - "2164", | ||
| 107 | - "10799", | ||
| 108 | - "17413", | ||
| 109 | - "10866", | ||
| 110 | - "1158", | ||
| 111 | - "10845", | ||
| 112 | - "1406", | ||
| 113 | - "1874", | ||
| 114 | - "9012", | ||
| 115 | - "9093", | ||
| 116 | - "10828", | ||
| 117 | - "11721", | ||
| 118 | - "11719", | ||
| 119 | - "11718", | ||
| 120 | - "10953", | ||
| 121 | - "2558", | ||
| 122 | - "10814", | ||
| 123 | - "1181", | ||
| 124 | - "11651", | ||
| 125 | - "11650", | ||
| 126 | - "1427", | ||
| 127 | - "2108", | ||
| 128 | - "10989", | ||
| 129 | - "2751", | ||
| 130 | - "2750", | ||
| 131 | - "1436", | ||
| 132 | - "1018", | ||
| 133 | - "7568", | ||
| 134 | - "2231", | ||
| 135 | - "2798", | ||
| 136 | - "1002", | ||
| 137 | - "3053", | ||
| 138 | - "4153", | ||
| 139 | - "3009", | ||
| 140 | - "1085", | ||
| 141 | - "9020", | ||
| 142 | - "4948", | ||
| 143 | - "1929", | ||
| 144 | - "2581", | ||
| 145 | - "1978", | ||
| 146 | - "2292", | ||
| 147 | - "6064", | ||
| 148 | - "2775", | ||
| 149 | - "10250", | ||
| 150 | - "2869", | ||
| 151 | - "1011", | ||
| 152 | - "1193", | ||
| 153 | - "2839", | ||
| 154 | - "1712", | ||
| 155 | - "1316", | ||
| 156 | - "2941", | ||
| 157 | - "5622", | ||
| 158 | - "2908", | ||
| 159 | - "1152", | ||
| 160 | - "1157", | ||
| 161 | - "2675", | ||
| 162 | - "10809", | ||
| 163 | - "11720", | ||
| 164 | - "11654", | ||
| 165 | - "11729", | ||
| 166 | - "2447", | ||
| 167 | - "3052", | ||
| 168 | - "10818", | ||
| 169 | - "10872", | ||
| 170 | - "10870", | ||
| 171 | - "1065", | ||
| 172 | - "4673", | ||
| 173 | - "15596", | ||
| 174 | - "4344", | ||
| 175 | - "2920", | ||
| 176 | - "8958", | ||
| 177 | - "1546", | ||
| 178 | - "2577", | ||
| 179 | - "2562", | ||
| 180 | - "1110", | ||
| 181 | - "10951", | ||
| 182 | - "10952", | ||
| 183 | - "10871", | ||
| 184 | - "2439", | ||
| 185 | - "2438", | ||
| 186 | - "11022", | ||
| 187 | - "11021", | ||
| 188 | - "2742", | ||
| 189 | - "2741", | ||
| 190 | - "15552", | ||
| 191 | - "8393", | ||
| 192 | - "10950", | ||
| 193 | - "2739", | ||
| 194 | - "10817", | ||
| 195 | - "2884", | ||
| 196 | - "2753", | ||
| 197 | - "9498", | ||
| 198 | - "1330", | ||
| 199 | - "2588", | ||
| 200 | - "10430", | ||
| 201 | - "10869", | ||
| 202 | - "1008", | ||
| 203 | - "10998", | ||
| 204 | - "7287", | ||
| 205 | - "10172", | ||
| 206 | - "10171", | ||
| 207 | - "10718", | ||
| 208 | - "1001", | ||
| 209 | - "1000", | ||
| 210 | - "2557", | ||
| 211 | -]; | ||
| 212 | - | ||
| 213 | const test = async (userid) => { | 4 | const test = async (userid) => { |
| 214 | let lst = await getBJ.getBJ(userid); | 5 | let lst = await getBJ.getBJ(userid); |
| 215 | let return_lst = []; | 6 | let return_lst = []; | ... | ... |
-
Please register or login to post a comment