-
Notifications
You must be signed in to change notification settings - Fork 1
/
Recommend.js
213 lines (182 loc) · 7.08 KB
/
Recommend.js
1
2
3
4
5
6
7
8
9
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
35
36
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// 학습시간 추천(학습계획표 추천)
// const { createConnection } = require("mysql");
var socket = io();
var id;
var a = [];
var jsonData;
socket.on('recMsg', (data)=> {
console.log(data);
id = data.userId;
//setTimeout(printTable(), 500);
});
var arr = [];
var count = 0;
class act{
constructor(name, classdate, start, long, alarm){
this.name = name;
this.classdate = classdate;
this.start = start;
this.long = long;
this.alarm = alarm;
}
}
function actSubmit1(){ // 버튼으로 입력받는 것 쪼개서함
arr[count] = new act();
var name1 = document.getElementById("act_name").value;
var time1 = document.getElementById("time_input").value;
var strn = name1 + " " + time1 + "시간";
var cvItime = parseInt(time1);
var tcount1 = parseInt(cvItime*2/3); // 몫
var tcount2 = (cvItime*2)%3;
var longArr = [];
for(var i = 0; i < tcount1; i++ ){
arr[count] = new act();
arr[count].name = name1;
arr[count].long = 3;
count++;
}
if((time1 *2) % 3 == 1){
//alert(tcount2);
arr[count-1].long += tcount2;
}else if(time1 % 3 != 0){
arr[count] = new act();
arr[count].name = name1;
arr[count].long = tcount2;
count++;
}
document.getElementById("rtn").append(strn);
document.getElementById("rtn").append(document.createElement("br"));
}
function Recommend(){ // 추천시간표에 추가해야할 활동내용
var query = "SELECT * FROM activity WHERE user = '"+`${id}`+"';";
socket.emit('query2', query);
socket.on('qanswer',(data)=>{
var i =0;
$.each(data,function(key1,value1){
a[i] = new act();
a[i].name = value1.name;
a[i].classdate = value1.classdate;
a[i].start = value1.start;
a[i].long = value1.long;
a[i].alarm = value1.alarm;
i++;
})
var rows = document.getElementById("time_table").getElementsByTagName("tr");
var cells = rows[4].getElementsByTagName("td");
//-------------------------위까지 기존 json파일 a배열에 집어넣음---------------------------------
var flag = true;
i = 0;
var alength = 0;
var x = 0;
var y = 0;
var repeat = 10000;
while(true){ // selectarr를 inputarr만큼 얻을 때 까지 반복
flag = true; // a arr에 값있는지 확인용
x = Math.floor(Math.random()*6)+1 //랜덤으로 요일 설정
y = Math.floor(Math.random()*30)+1 //랜덤으로 시간 설정
if((y+(arr[i].long)-1) > 30){
continue;
}
for(var j = 0; j < a.length ; j++){
var pStart = a[j].start; //기존시작점
var pEnd = a[j].start + a[j].long -1; //기존종료점
var nStart = y; //추가할 시작점
var nEnd = y+ arr[i].long -1; //추가할 종료점
if(a[j].name == arr[i].name && a[j].classdate == x){
flag = false;
break;
}
if(a[j].classdate == x && pStart <= nStart && pEnd >= nStart){
flag = false;
break;
} else if (a[j].classdate == x && pStart <= nEnd && pEnd >= nEnd ){
flag = false;
break;
} else if (a[j].classdate == x && pStart >= nStart && pEnd <= nEnd){
flag = false;
break;
}
}
if(flag == true){
alength = a.length; //a배열의 끝에 추가
a[alength] = new act(arr[i].name, x, y, arr[i].long, true);
i++;
if(i==arr.length){
break;
}
}
repeat--;
if(repeat==0){
alert("추가할 자리를 찾지 못했습니다.");
break;
}
}
//----------------랜덤한 좌표로 classdate start잡아서 a배열 뒤에 집어넣음--------------------
for (var num = 1; num <= 7; num++) {
$('tr','#time_table').each(function(row){ // #테이블ID값
if(row > 0 ){
mergeCount = mergeCount + 1;
$("tr:eq("+row+") > td:eq("+num+")").attr("rowspan",1);
$('td:eq('+num+')',$(this)).show(); //병합될 값들 숨김처리
}
})
}
var testArray = new Array();
var data = [];
var fortest = [];
for(var i = 0; i<a.length ; i++){
var rowcell = a[i].classdate;
var colcell = a[i].start;
for(var k = 0; k < a[i].long; k++){
var cells = rows[colcell+k].getElementsByTagName("td");
cells[rowcell].innerHTML = a[i].name;
}
data[i] = new Object();
fortest[i] = new Object();
fortest[i].name = a[i].name;
fortest[i].classdate = a[i].classdate;
fortest[i].start = a[i].start;
fortest[i].long = a[i].long;
fortest[i].alarm = "Y";
data[i].activities = fortest[i];
testArray.push(data[i]);
}
jsonData = JSON.stringify(testArray, null, 4);
for (var num = 1; num <= 7; num++) {
var mergeItem = "절대나올수없는값"; //병합구분값
var mergeCount = 0; //병합 수
var mergeRowNum = 0; //병합들num갈 r1w
$('tr','#time_table').each(function(row){ // #테이블ID값
if(row > 0 ){
var item = $(':eq(' + num +')',$(this)).html();
if(mergeItem != item ) {
mergeCount = 1;
mergeItem = item ;
mergeRowNum = row;
}else{
mergeCount = mergeCount + 1;
$("tr:eq("+mergeRowNum+") > td:eq("+num+")").attr("rowspan",mergeCount);
$('td:eq('+num+')',$(this)).hide(); //병합될 값들 숨김처리
}
}
})
}
// for(var i = 0 ; i< a.length; i++){
// var query = "INSERT IGNORE activity VALUES('" + `${id}` +"',"+ a[i].classdate + ", " + a[i].start + ", " + a[i].long+", '" + a[i].name + "') ";
// socket.emit('query', query);
// }
// socket.emit('jsondata', jsonData);
});
document.getElementById('recommend_button').style.display = 'none';
document.getElementById('save_button').style.display = 'inline-block';
}
function saveDB(){
for(var i = 0 ; i< a.length; i++){
var query = "INSERT IGNORE activity VALUES('" + `${id}` +"',"+ a[i].classdate + ", " + a[i].start + ", " + a[i].long+", '" + a[i].name + "') ";
socket.emit('query', query);
}
socket.emit('jsondata', jsonData);
}
function pageReload(){
window.location.reload();
}