-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaker.js
184 lines (176 loc) · 4.57 KB
/
faker.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
const faker = require('faker');
const moment = require('moment');
const bcrypt = require('bcryptjs');
const {v4: uuidv4} = require('uuid');
const db = require('./data/dbConfig');
const dayModel = require('./models/day_log')
let month = 1
let day = 0
const createAdmin = async () => {
const admins = [
{
admin: true,
email: 'jess@email.com',
username: 'Jess',
password: 'unit4',
}
]
admins.map(admin => {
setTimeout(async () => {
const hash = bcrypt.hashSync(admin.password, 10);
admin.password = hash;
admin.id = uuidv4();
return db('users')
.insert(admin)
.catch(err => console.log(err));
}, 1000);
})
}
const longMonths = [1, 3, 5, 7, 8, 10, 12]
const shortMonths = [4, 6, 9, 11]
let monthId
let weekId
const floodDays = async (id) => {
let week = 27
//flood my days
month = 7
day = 0
let dayOfWeek = 0
monthId = faker.random.uuid()
weekId = faker.random.uuid()
for (let i = 0; i < 61; i++) {
const sleepId = faker.random.uuid()
if (month === 2) {
if (day < 28) {
day++
} else {
day = 1
month++
monthId = faker.random.uuid()
}
} else if (shortMonths.includes(month)) {
if (day < 30) {
day++
} else {
day = 1
month++
monthId = faker.random.uuid()
}
} else if (longMonths.includes(month)) {
if (day < 31) {
day++
} else {
day = 1
if (month !== 12) {
month++
monthId = faker.random.uuid()
} else {
month = 1
monthId = faker.random.uuid()
}
}
}
const monthData = {
id: monthId,
users_id: id,
month_of_year: `${month}/2020`,
average_hours_slept: 7,
average_quality: 3,
}
const weekData = {
id: weekId,
users_id: id,
week_of_year: `${week}/2020`,
average_hours_slept: 7,
average_quality: 3,
}
const sleepData = {
id: sleepId,
users_id: id,
date: `2020-${month}-${day}`,
bedtime: `23:00:00`,
wake_time: `06:00:00`,
total_hours_slept: 7,
average_quality: 3,
month_log_id: monthId,
week_log_id: weekId,
}
const qualityData = {
id: faker.random.uuid(),
wake_score: 3,
day_score: 3,
bedtime_score: 3,
day_log_id: sleepId
}
if (dayOfWeek < 7) {
dayOfWeek++
} else {
dayOfWeek = 0;
week++
weekId = faker.random.uuid()
}
// console.log({monthId})
// console.log({month})
// console.log({weekId})
// console.log({dayOfWeek})
setTimeout(async () => {
// console.log({sleepData})
// console.log({qualityData})
await db('month_log')
.insert(monthData)
.catch(err => console.log(err));
await db('week_log')
.insert(weekData)
.catch(err => console.log(err));
await db('day_log')
.insert(sleepData)
.catch(err => console.log(err));
await db('quality_log')
.insert(qualityData)
.catch(err => console.log(err));
}, 1000);
}
}
const adminId = '036f18ad-a2c2-496b-8b64-ff4df3dd6aa4'
const floodAdminsData = () => {
floodDays(adminId)
}
// floodUsers()
// createAdmin()
// floodAdminsData()
// get week number by date
// console.log(moment('1-25-1995').month() + 1 )
// console.log(moment().format('YYYY-MM-DD') === moment().endOf('month').format('YYYY-MM-DD'))
// console.log(moment().date())
// console.log(moment('8-30-2020').week())
// const bedtime = new Date(`2020-09-18T23:00:00`).getTime()
// const formattedBedTime = moment(time).format('hh:mm:A')
//
// console.log(formattedTime)
// console.log(moment().format('MM-DD-YYYY'))
// console.log(moment('2020-09-25T00:00:00.000Z').day().format('d'))
// 11:59 PM => 1600574399000
// 00:00 => 1600488000000
// 11:59 AM => 1600531199000
// 12:00 => 1600531200000
const getSleptHours = (bedtime, wakeTime) => {
// using an arbitrary date to calculate hours slept
let tonight = '2020-09-19T'
let tomorrow = '2020-09-20T'
let startTime = '11:40:51'
let shorten = false;
let time1 = new Date(`${tonight}${startTime}`)
let time2 = new Date(`${tomorrow}${'07:40:11'}`)
console.log(time1.getTime())
if (time1.getTime() >= 1600488000000 && time1.getTime() <= 1600531200000) {
time1 = new Date(`${tomorrow}${startTime}`)
}
const now = moment(time1)
const end = moment(time2)
const duration = moment.duration(now.diff(end))
const hours = duration.asHours()
console.log({now})
console.log({end})
return Math.abs(hours)
}
console.log(getSleptHours())