송용우

Merge commit '9f7a8157' into develop

This diff is collapsed. Click to expand it.
......@@ -8,8 +8,9 @@
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"immer": "^7.0.1",
"immer": "^7.0.5",
"include-media": "^1.4.9",
"moment": "^2.27.0",
"open-color": "^1.7.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
......
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import styled from 'styled-components';
import palette from '../../lib/styles/palette';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
......
import React from 'react';
import styled from 'styled-components';
import Button from '../common/Button';
import palette from '../../lib/styles/palette';
import BJIDForm from './BJIDForm';
import SlackForm from './SlackForm';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
const SettingFormBlock = styled.div`
h3 {
margin: 0;
color: ${palette.gray[8]};
margin-bottom: 1rem;
}
background: ${palette.gray[2]};
margin: 0 auto;
display: flex;
flex-direction: column;
`;
const StyledInput = styled.input`
font-size: 1rem;
border: none;
border-bottom: 1px solid ${palette.gray[5]};
padding-bottom: 0.5rem;
outline: none;
&:focus {
color: $oc-teal-7;
border-bottom: 1px solid ${palette.gray[7]};
}
& + & {
margin-top: 1rem;
}
`;
const SectionContainer = styled.div`
display: flex;
`;
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
......@@ -48,7 +18,13 @@ const useStyles = makeStyles((theme) => ({
},
}));
const SettingForm = ({ onChange, onBJIDSubmit, profile, onSyncBJIDSubmit }) => {
const SettingForm = ({
onChange,
onBJIDSubmit,
onSlackURLSubmit,
profile,
onSyncBJIDSubmit,
}) => {
const classes = useStyles();
return (
<div className={classes.root}>
......@@ -68,6 +44,16 @@ const SettingForm = ({ onChange, onBJIDSubmit, profile, onSyncBJIDSubmit }) => {
/>
</Paper>
</Grid>
<Grid container item xs={12}>
<Paper className={classes.paper} elevation={3}>
<SlackForm
profile={profile}
onChange={onChange}
onSlackURLSubmit={onSlackURLSubmit}
/>
</Paper>
</Grid>
</Grid>
</div>
);
......
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
const useStyles = makeStyles((theme) => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
},
}));
const SlackForm = ({ onChange, profile, onSlackURLSubmit }) => {
const classes = useStyles();
return (
<div>
<form onSubmit={onSlackURLSubmit}>
<TextField
name="slackWebHookURL"
onChange={onChange}
value={profile.slackWebHookURL}
placeholder="슬랙 Webhook URL"
label="슬랙 Webhook URL"
/>
<Button variant="outlined" type="submit">
등록
</Button>
</form>
</div>
);
};
export default SlackForm;
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { withRouter } from 'react-router-dom';
import HomeForm from '../../components/home/HomeForm';
......@@ -6,16 +6,12 @@ import { getPROFILE } from '../../modules/profile';
import { analyzeBJ } from '../../lib/util/analyzeBJ';
const HomeContainer = ({ history }) => {
const dispatch = useDispatch();
const [isLogin, setLogin] = useState(false);
const { user, profile } = useSelector(({ user, profile }) => ({
user: user.user,
profile: profile,
}));
useEffect(() => {}, [profile.solvedBJ]);
useEffect(() => {
analyzeBJ(profile.solvedBJ);
}, [profile.solvedBJ]);
useEffect(() => {
setLogin(true);
if (user) {
let username = user.username;
dispatch(getPROFILE({ username }));
......
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { withRouter } from 'react-router-dom';
import {
......@@ -7,6 +7,7 @@ import {
getPROFILE,
syncBJID,
initializeProfile,
setSLACK,
} from '../../modules/profile';
import SettingForm from '../../components/setting/SettingForm';
......@@ -32,6 +33,12 @@ const SettingContainer = ({ history }) => {
let username = profile.username;
dispatch(syncBJID({ username }));
};
const onSlackURLSubmit = (e) => {
e.preventDefault();
let username = profile.username;
let slackWebHookURL = profile.slackWebHookURL;
dispatch(setSLACK({ username, slackWebHookURL }));
};
const onBJIDSubmit = (e) => {
e.preventDefault();
......@@ -60,6 +67,7 @@ const SettingContainer = ({ history }) => {
onChange={onChange}
onBJIDSubmit={onBJIDSubmit}
onSyncBJIDSubmit={onSyncBJIDSubmit}
onSlackURLSubmit={onSlackURLSubmit}
profile={profile}
></SettingForm>
);
......
......@@ -5,7 +5,8 @@ export const setBJID = ({ username, userBJID }) =>
username: username,
userBJID: userBJID,
});
export const setPROFILE = (postdata) =>
client.post('api/profile/setprofile', postdata);
export const getPROFILE = ({ username }) =>
client.post('api/profile/getprofile', { username });
......
/*
1. 날짜 순 정렬
2. 현재 날짜와의 차이
3. 최근 일주일간 푼 문제 수
4. 추천 문제
*/
exports.analyzeBJ = function (solvedBJ) {
console.log(typeof solvedBJ);
if (solvedBJ) {
solvedBJ.sort(function (a, b) {
return a.solvedDate > b.solvedDate
? -1
: a.solvedDate < b.solvedDate
? 1
: 0;
});
console.log(solvedBJ);
}
};
......@@ -12,6 +12,11 @@ const [SET_BJID, SET_BJID_SUCCESS, SET_BJID_FAILURE] = createRequestActionTypes(
'profile/SET_BJID',
);
const [
SET_SLACK,
SET_SLACK_SUCCESS,
SET_SLACK_FAILURE,
] = createRequestActionTypes('/profile/SET_SLACK');
const [
GET_PROFILE,
GET_PROFILE_SUCCESS,
GET_PROFILE_FAILURE,
......@@ -26,6 +31,13 @@ export const initializeProfile = createAction(INITIALIZE);
export const syncBJID = createAction(SYNC_BJID, ({ username }) => ({
username,
}));
export const setSLACK = createAction(
SET_SLACK,
({ username, slackWebHookURL }) => ({
username,
slackWebHookURL,
}),
);
export const setBJID = createAction(SET_BJID, ({ username, userBJID }) => ({
username,
userBJID,
......@@ -45,14 +57,17 @@ const initialState = {
solvedBJ: '',
friendList: [],
profileError: '',
slackWebHookURL: '',
};
const getPROFILESaga = createRequestSaga(GET_PROFILE, profileAPI.getPROFILE);
const setBJIDSaga = createRequestSaga(SET_BJID, profileAPI.setBJID);
const setSLACKSaga = createRequestSaga(SET_SLACK, profileAPI.setPROFILE);
const syncBJIDSaga = createRequestSaga(SYNC_BJID, profileAPI.syncBJ);
export function* profileSaga() {
yield takeLatest(SET_BJID, setBJIDSaga);
yield takeLatest(GET_PROFILE, getPROFILESaga);
yield takeLatest(SYNC_BJID, syncBJIDSaga);
yield takeLatest(SET_SLACK, setSLACKSaga);
}
export default handleActions(
......@@ -64,7 +79,9 @@ export default handleActions(
}),
[GET_PROFILE_SUCCESS]: (
state,
{ payload: { username, userBJID, solvedBJ, friendList } },
{
payload: { username, userBJID, solvedBJ, friendList, slackWebHookURL },
},
) => ({
...state,
username: username,
......@@ -72,6 +89,7 @@ export default handleActions(
solvedBJ: solvedBJ,
friendList: friendList,
profileError: null,
slackWebHookURL: slackWebHookURL,
}),
[GET_PROFILE_FAILURE]: (state, { payload: error }) => ({
...state,
......@@ -87,6 +105,15 @@ export default handleActions(
...state,
profileError: error,
}),
[SET_SLACK_SUCCESS]: (state, { payload: { slackWebHookURL } }) => ({
...state,
slackWebHookURL: slackWebHookURL,
profileError: null,
}),
[SET_SLACK_FAILURE]: (state, { payload: error }) => ({
...state,
profileError: error,
}),
[SYNC_BJID_SUCCESS]: (state, { payload: { solvedBJ } }) => ({
...state,
solvedBJ,
......
import React from 'react';
import HeaderContainer from '../containers/common/HeaderContainer';
import SettingForm from '../components/setting/SettingForm';
import SettingContainer from '../containers/setting/SettingContainer';
const SettingPage = () => {
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
export const problem_set = [
"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",
];
/*
2. 현재 날짜와의 차이 =>
3. 오늘 푼 문제 => 앞에서부터 순회하면서 데이트 같은거 찾기
3. 최근 일주일간 푼 문제 수 => 앞에서부터 순회하면서 - 값이
4. 추천 문제 => 정규 셋에서 없는거 찾기
5. 날짜별로 묶기.
데이터베이스에서 처리하자
*/
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 solvedBJbyDATE = {};
for (let i = 0; i < solvedBJ.length; i++) {
if (!(solvedBJ[i].solved_date in solvedBJbyDATE)) {
solvedBJbyDATE[solvedBJ[i].solved_date] = [];
solvedBJbyDATE[solvedBJ[i].solved_date].push(solvedBJ[i]);
} else {
solvedBJbyDATE[solvedBJ[i].solved_date].push(solvedBJ[i]);
}
}
let latestNum = solvedBJbyDATE[solvedBJ[0].solved_date].length;
let presentNum =
presentDate_str in solvedBJbyDATE
? solvedBJbyDATE[presentDate_str].length
: 0;
let returnOBJ = {
latestDate: latestDate.format('YYYYMMDD'),
difflatest: difflatest,
latestNum: latestNum,
presentNum: presentNum,
solvedBJbyDATE: solvedBJbyDATE,
};
console.log(returnOBJ);
return returnOBJ;
}
} catch (e) {
console.log(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) {
new_obj.push(solvedBJ_new[i]);
}
}
console.log(new_obj);
} catch (e) {
console.log(e);
}
};
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 = [];
for (let i = 0; i < lst.length; i++) {
return_lst.push(lst[i].problem_number);
}
var stringJson = JSON.stringify(return_lst) + "\n";
fs.open("test.json", "a", "666", function (err, id) {
if (err) {
console.log("file open err!!");
} else {
fs.write(id, stringJson, null, "utf8", function (err) {
console.log("file was saved!");
});
}
});
};
/*
*/
test("jwseo001");
[
"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"
]