송용우

Merge commit '309989fc' into develop

......@@ -3,7 +3,6 @@ import { useDispatch, useSelector } from 'react-redux';
import { withRouter } from 'react-router-dom';
import HomeForm from '../../components/home/HomeForm';
import { getPROFILE } from '../../modules/profile';
import { analyzeBJ } from '../../lib/util/analyzeBJ';
const HomeContainer = ({ history }) => {
const dispatch = useDispatch();
const { user, profile } = useSelector(({ user, profile }) => ({
......
......@@ -19,7 +19,7 @@
## API Table
| group | description | method | URL | Detail | Auth |
| ------- | --------------------------- | --------- | ------------------------ | -------- | --------- |
| ------- | --------------------------- | --------- | ----------------------- | -------- | --------- |
| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token |
| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token |
| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None |
......@@ -30,7 +30,7 @@
| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None |
| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN |
| profile | 유저 정보 받아오기 | POST | api/profile/getprofile | 바로가기 | JWT |
| profile | 추천 문제 조회 | GET | api/profile/recommend:id | 바로가기 | None |
| profile | 추천 문제 조회 | POST | api/profile/recommend | 바로가기 | None |
| notify | 슬랙 메시지 전송 요청 | POST | api/notify/ |
| slack | 바로가기 | Jwt Token |
| auth | 로그인 | POST | api/auth/login | 바로가기 | None |
......
......@@ -1286,3 +1286,38 @@
::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"
::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"
::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"
::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"
::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"
::1 - - [24/Jun/2020:13:52:15 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:53:07 +0000] "POST /api/profile/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:54:22 +0000] "POST /api/profile/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:54:40 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:55:32 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:57:11 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:57:49 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:58:26 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::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"
::1 - - [24/Jun/2020:13:58:59 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:59:43 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:00:09 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:02:01 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:02:52 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:03:53 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:04:43 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:05:13 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:07:09 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:08:00 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:09:35 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:10:57 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:11:19 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:12:04 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:21 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:24 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:27 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:28 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:30 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:35 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:38 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:15:40 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:19:33 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:19:36 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
......
const Router = require("koa-router");
const profile = new Router();
const profileCtrl = require("./profile.ctrl");
profile.post("/solved:id");
profile.get("/solvednum:id");
profile.get("/recommendps:id");
profile.post("/recommend", profileCtrl.recommend);
profile.patch("/syncBJ", profileCtrl.syncBJ);
profile.post("/setprofile", profileCtrl.setProfile);
profile.post("/getprofile", profileCtrl.getProfile);
......
......@@ -2,6 +2,9 @@ const Profile = require("../../models/profile");
const mongoose = require("mongoose");
const getBJ = require("../../util/getBJ");
const Joi = require("joi");
const analyzeBJ = require("../../util/analyzeBJ");
const compareBJ = require("../../util/compareBJ");
const problem_set = require("../../data/problem_set");
const { ObjectId } = mongoose.Types;
......@@ -95,9 +98,10 @@ exports.syncBJ = async function (ctx) {
}
const BJID = await profile.getBJID();
let BJdata = await getBJ.getBJ(BJID);
let BJdata_date = await analyzeBJ.analyzeBJ(BJdata);
const updateprofile = await Profile.findOneAndUpdate(
{ username: username },
{ solvedBJ: BJdata },
{ solvedBJ: BJdata, solvedBJ_date: BJdata_date },
{ new: true }
).exec();
ctx.body = updateprofile;
......@@ -105,3 +109,33 @@ exports.syncBJ = async function (ctx) {
ctx.throw(500, e);
}
};
/*
POST /api/proflie/recommend
{
username: 'userid'
}
*/
exports.recommend = async (ctx) => {
const { username } = ctx.request.body;
if (!username) {
ctx.status = 401;
return;
}
try {
const profile = await Profile.findByUsername(username);
if (!profile) {
ctx.status = 401;
return;
}
let unsolved_data = compareBJ.compareBJ(
profile.getBJdata(),
problem_set.problem_set
);
ctx.body = compareBJ.randomItem(unsolved_data);
//데이터가 비었을 떄 예외처리 필요
} catch (e) {
ctx.throw(500, e);
}
};
......
export const problem_set = [
exports.problem_set = [
"1517",
"2448",
"1891",
......
......@@ -6,6 +6,7 @@ const ProfileSchema = new Schema({
username: { type: String, required: true, unique: true },
userBJID: String,
solvedBJ: Object,
solvedBJ_date: Object,
friendList: [String],
slackWebHookURL: String,
});
......@@ -15,6 +16,9 @@ ProfileSchema.statics.findByUsername = function (username) {
ProfileSchema.methods.getBJID = function () {
return this.userBJID;
};
ProfileSchema.methods.getBJdata = function () {
return this.solvedBJ;
};
ProfileSchema.methods.serialize = function () {
const data = this.toJSON();
......
/*
2. 현재 날짜와의 차이 =>
3. 오늘 푼 문제 => 앞에서부터 순회하면서 데이트 같은거 찾기
3. 최근 일주일간 푼 문제 수 => 앞에서부터 순회하면서 - 값이
4. 추천 문제 => 정규 셋에서 없는거 찾기
5. 날짜별로 묶기.
데이터베이스에서 처리하자
*/
let moment = require('moment');
let moment = require("moment");
exports.analyzeBJ = function (solvedBJ) {
try {
if (solvedBJ) {
console.log(solvedBJ[0]);
let presentDate = moment();
let presentDate_str = presentDate.format('YYYYMMDD');
let latestDate = moment(solvedBJ[0].solved_date, 'YYYYMMDD');
let difflatest = presentDate.diff(latestDate, 'days');
let presentDate_str = presentDate.format("YYYYMMDD");
let latestDate = moment(solvedBJ[0].solved_date, "YYYYMMDD");
let difflatest = presentDate.diff(latestDate, "days");
let solvedBJbyDATE = {};
for (let i = 0; i < solvedBJ.length; i++) {
......@@ -34,13 +24,13 @@ exports.analyzeBJ = function (solvedBJ) {
? solvedBJbyDATE[presentDate_str].length
: 0;
let returnOBJ = {
latestDate: latestDate.format('YYYYMMDD'),
latestDate: latestDate.format("YYYYMMDD"),
difflatest: difflatest,
latestNum: latestNum,
presentNum: presentNum,
solvedBJbyDATE: solvedBJbyDATE,
};
console.log(returnOBJ);
return returnOBJ;
}
} catch (e) {
......
/*
집중을 해보자.
새거와 데이터가 있다.
데이터 기준으로 새거에 자료가 있으면 넘어가기
없으면 새 배열에 추가
키만 모아둔 리스트를 만들자.
그렇게 해서
반복은 새거 길이만큼
데이터에 있으면 추가 X
없으면 추가
그렇게 반환
*/
exports.compareBJ = function (solvedBJ_new, problem_set) {
try {
let new_obj = [];
for (let i = 0; i < solvedBJ.length; i++) {
if (solvedBJ_new[i].problem_number in problem_set) {
for (let i = 0; i < solvedBJ_new.length; i++) {
if (!problem_set.includes(String(solvedBJ_new[i].problem_number))) {
new_obj.push(solvedBJ_new[i]);
}
}
console.log(new_obj);
return new_obj;
} catch (e) {
console.log(e);
}
};
exports.randomItem = function (a) {
return a[Math.floor(Math.random() * a.length)];
};
......
var getBJ = require("./getBJ");
var fs = require("fs");
let dataset = [
"1517",
"2448",
"1891",
"1074",
"2263",
"1780",
"11728",
"10816",
"10815",
"2109",
"1202",
"1285",
"2138",
"1080",
"11399",
"1931",
"11047",
"15666",
"15665",
"15664",
"15663",
"15657",
"15656",
"15655",
"15654",
"15652",
"15651",
"15650",
"15649",
"6603",
"10971",
"10819",
"10973",
"10974",
"10972",
"7576",
"1248",
"2529",
"15661",
"14501",
"1759",
"14391",
"14889",
"1182",
"11723",
"1748",
"6064",
"1107",
"3085",
"2309",
"1748",
"14500",
"1107",
"1476",
"3085",
"2309",
"1261",
"13549",
"14226",
"13913",
"1697",
"1967",
"1167",
"11725",
"2250",
"1991",
"7562",
"2178",
"4963",
"2667",
"1707",
"11724",
"1260",
"13023",
"11652",
"1377",
"11004",
"10825",
"2751",
"9461",
"1699",
"9095",
"2225",
"2133",
"11727",
"11726",
"1463",
"2748",
"2747",
"11656",
"10824",
"2743",
"10820",
"10808",
"11655",
"11720",
"1008",
"10951",
"2557",
"1021",
"1966",
"2164",
"10799",
"17413",
"10866",
"1158",
"10845",
"1406",
"1874",
"9012",
"9093",
"10828",
"11721",
"11719",
"11718",
"10953",
"2558",
"10814",
"1181",
"11651",
"11650",
"1427",
"2108",
"10989",
"2751",
"2750",
"1436",
"1018",
"7568",
"2231",
"2798",
"1002",
"3053",
"4153",
"3009",
"1085",
"9020",
"4948",
"1929",
"2581",
"1978",
"2292",
"6064",
"2775",
"10250",
"2869",
"1011",
"1193",
"2839",
"1712",
"1316",
"2941",
"5622",
"2908",
"1152",
"1157",
"2675",
"10809",
"11720",
"11654",
"11729",
"2447",
"3052",
"10818",
"10872",
"10870",
"1065",
"4673",
"15596",
"4344",
"2920",
"8958",
"1546",
"2577",
"2562",
"1110",
"10951",
"10952",
"10871",
"2439",
"2438",
"11022",
"11021",
"2742",
"2741",
"15552",
"8393",
"10950",
"2739",
"10817",
"2884",
"2753",
"9498",
"1330",
"2588",
"10430",
"10869",
"1008",
"10998",
"7287",
"10172",
"10171",
"10718",
"1001",
"1000",
"2557",
];
const test = async (userid) => {
let lst = await getBJ.getBJ(userid);
let return_lst = [];
......