-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
241 lines (228 loc) · 7.22 KB
/
index.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
const moment = require("moment");
const data = require("./functions/data/5th-sem.json");
const requestData = require("./playground/request.json");
/* var data = require("./functions/data/4th-sem.json");
function workingHours(time) {
if (time >= 9 && time <= 18) return true;
else return false;
}
function weekdays(day) {
if (day === "Saturday" || day === "Sunday") return true;
else return false;
}
*/
// console.log(requestData.queryResult.intent.displayName);
function setTimeZone() {
const indianTimeZone = moment
.utc()
.add(5, "hours")
.add(30, "minutes");
return indianTimeZone;
}
function isItToday(today, intentName) {
const indianTimeMoment = setTimeZone();
const day = indianTimeMoment.format("dddd");
const nextDay = indianTimeMoment.add(1, "days").format("dddd");
if (intentName === "showFullSchedule") {
if (today === day) return true;
else return false;
} else {
if (today === day) {
return "today";
} else if (today === nextDay) {
return "tomorrow";
} else return `on ${today}`;
}
}
function isToday(today) {
const indianTimeMoment = setTimeZone();
const day = indianTimeMoment.format("dddd");
const nextDay = indianTimeMoment.add(1, "days").format("dddd");
if (today === day) {
return "today";
} else if (today === nextDay) {
return "tomorrow";
} else return `on ${today}`;
}
console.log(isToday("Friday"));
// console.log(isItToday("Friday", "findLectureByTime"));
/*
function nextLectureIntentHandler() {
const indianTimeMoment = setTimeZone();
const currentHour = indianTimeMoment.hour();
// console.log("currentHour: ", currentHour);
let next = currentHour + 1;
// console.log("next: ", next);
let hourCode = "L" + next;
// console.log("hourCode", hourCode);
let day = indianTimeMoment.day();
// console.log("day: ", day);
let today = moment().format("dddd");
// console.log("today:", today);
// console.log(data[day]);
if (workingHours(next)) {
if (weekdays(today)) {
console.log("Enjoy your weekend Buddy!");
} else {
const classs = data[day][today][hourCode];
if (classs.type === "LAB") {
console.log("Next you have LAB");
console.log("For H1 Batch:");
console.log(
`${classs.h1.name} will be taken by ${classs.h1.Professor}`
);
console.log("For H2 Batch:");
console.log(
`${classs.h2.name} will be taken by ${classs.h2.Professor}`
);
console.log("For H1 Batch:");
console.log(
`${classs.h3.name} will be taken by ${classs.h3.Professor}`
);
} else if (classs.type == "Lecture") {
console.log(
`Next lecture is ${classs.name} which will be taken by ${
classs.Professor
}`
);
} else if (classs.type === "Free") {
console.log("It's your free time");
}
}
} else {
console.log("Please come back during working college hours");
}
}
function findLectureIntent(x) {
const indianTimeMoment = setTimeZone();
const currentHour = indianTimeMoment.hour();
let next = currentHour + 1;
let hourCode = "L" + next;
let day = indianTimeMoment.day();
console.log(day);
let today = moment().format("dddd");
const t = Object.entries(data[day].today).find(([key, value]) =>
value.Professor.includes(profName)
);
console.log(t);
}
findLectureIntent("Manish Chaturvedi");
// nextLectureIntentHandler();
profName;
// */
// function isItToday(today) {
// const indianTimeMoment = setTimeZone();
// const day = indianTimeMoment.format("dddd");
// const nextDay = indianTimeMoment.add(1, "days");
// console.log("nextDay ", nextDay.format("dddd"));
// console.log(nextDay.format("dddd"));
// // const tomorrow = moment().calender(null, { nextDay });
// // console.log(tomorrow);
// }
// if (isItToday("Monday")) {
// console.log("Its monday");
// } else console.log("its not monday");
// console.log(moment("2018-08-01T09:00:00+05:30").hour());
function timeConvert(t) {
return `${
t - 12 >= 0 ? `${t - 12 === 0 ? "12" : `${t - 12}`} PM` : `${t} AM`
}`;
}
function add1Day(day) {
return moment(day).add(1, "days");
}
const timezone = "2018-08-05T12:00:00+05:30";
// console.log("today", moment(timezone).format("dddd"));
// console.log("NextDay", add1Day(timezone).format("dddd"));
/*
function toArray(moData) {
// console.log(Object.keys(moData));
const ownProps = Object.keys(moData);
var i = ownProps.length;
var resArray = new Array(i);
while (i--) resArray[i] = [ownProps[i], moData[ownProps[i]]];
return resArray;
}
const indianTimeMoment = setTimeZone();
const today = moment("2018-08-10T00:26:06+05:30").format("dddd");
const day = moment(" 2018-08-10T00:26:06+05:30").day();
console.log("Today: ", today);
console.log("day: ", day);
// const today = "Thursday";
// const day = 4;
const result = {
title: `${today}'s schedule`,
items: {}
};
const entries = toArray(data[day][today]);
console.log(entries.length);
function displayDaySchedule() {
for (const entry of entries) {
// console.log("entry.length", entry.length);
const key = entry[0];
const value = entry[1];
// console.log(key, value);
if (value.type === "Lecture") {
result.items[
`${value.name} at ${timeConvert(parseInt(key.substring(1)))}`
] = {
synonyms: [`${value.name}`],
title: `At ${timeConvert(parseInt(key.substring(1)))}: ${value.name}`,
description: `By ${value.Professor} `
};
} else if (value.type === "LAB") {
result.items[`${value.h1.name}, ${value.h2.name}, ${value.h3.name}`] = {
synonyms: [`${value.h1.name} ${value.h2.name} ${value.h3.name}`],
title: `LAB Session`,
description:
"For H1 Batch, At " +
timeConvert(parseInt(key.substring(1))) +
" " +
value.h1.name +
" by " +
value.h1.Professor +
" \n " +
"For H2 Batch, At " +
timeConvert(parseInt(key.substring(1))) +
" " +
value.h2.name +
" by " +
value.h2.Professor +
" \n " +
"For h3 Batch, At " +
timeConvert(parseInt(key.substring(1))) +
" " +
value.h3.name +
" by " +
value.h3.Professor +
" \n "
};
} else if (value.type === "Free") {
// console.log(value.type, key.substring(1));
result.items[
`${value.name} at ${timeConvert(parseInt(key.substring(1)))}`
] = {
synonyms: [`${value.type}`],
title: `At ${timeConvert(parseInt(key.substring(1)))}: ${value.type}`,
description: `At ${timeConvert(
parseInt(key.substring(1))
)} Its your free time`
};
} else {
console.log("\n\nterminating the loop\n\n");
break;
}
}
}
displayDaySchedule();
console.log(result.items); */
/* description:
`For H1 Batch, At ${timeConvert(parseInt(key.substring(1)))} ${
value.h1.name
} by ${value.h1.Professor} ` +
`For H2 Batch, At ${timeConvert(parseInt(key.substring(1)))} ${
value.h2.name
} by ${value.h2.Professor} ` +
`For h3 Batch, At ${timeConvert(parseInt(key.substring(1)))} ${
value.h3.name
} by ${value.h3.Professor} ` */