곽병민

Get_data_from_DB

1 +const config = require('./config')
2 +const mongoose = require("mongoose");
3 +const { range } = require("express/lib/request");
4 +const xlsx = require("xlsx");
5 +const fs = require('fs')
6 +
7 +
8 +
9 +const connect = mongoose.connect(config.url,
10 + {
11 + useNewUrlParser: true,
12 + useUnifiedTopology: true,
13 + })
14 + .then(() => console.log("DB : Succesfully Connected"))
15 + .catch((err) => console.log(err.message));
16 +
17 +
18 +var express = require('express');
19 +
20 +const { Subinfo } = require('./models/model');
21 +var request = require('request');
22 +
23 +
24 +var departmentinfo = '컴퓨터공학과'
25 +var gradeinfo = '2학년1학기'
26 +var name = []
27 +var time = []
28 +var prof = []
29 +
30 +Subinfo.find({ department: `${departmentinfo}`, grade: `${gradeinfo}` }).then((sub) => {
31 + if (sub) {
32 + for (var i in sub) {
33 + if (sub[i]['choice'] == '필수') {
34 + name.push(sub[i]['name'])
35 +
36 + var random_num = (Math.floor(Math.random() * (sub[i]['subject'].length)))
37 + sub[i]['subject'][random_num]['time']
38 +
39 + if (time.length > 0) {
40 + while (true) {
41 + try {
42 + var tmp = 0
43 + var random_num = (Math.floor(Math.random() * (sub[i]['subject'].length)))
44 +
45 + for (var j in time) {
46 + if (time[j].slice(0, 13) == sub[i]['subject'][random_num]['time'].slice(0, 13)) {
47 + tmp = 1
48 + break
49 + }
50 + }
51 + if (tmp == 0) {
52 + break
53 + }
54 + }
55 + catch (err) {
56 + console.error(err);
57 + }
58 + }
59 + }
60 + time.push(sub[i]['subject'][random_num]['time'])
61 + prof.push(sub[i]['subject'][random_num]['prof'])
62 +
63 + }
64 + }
65 + console.log(name)
66 + console.log(time)
67 + console.log(prof)
68 + }
69 + else {
70 + console.log(err)
71 + }
72 +})
73 +
74 +//console.log(Math.floor(Math.random() * (10)))
...\ No newline at end of file ...\ No newline at end of file