4 data
This commit is contained in:
260
4/data.js
260
4/data.js
@ -0,0 +1,260 @@
|
||||
import * as crypto from 'node:crypto'
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
const GenMaxUInt = (max) => Math.floor(Math.random() * max)
|
||||
const GenInt = (from, to) => Math.floor(Math.random() * (to - from) + from)
|
||||
|
||||
const male_full_name = [
|
||||
"Семенов Дмитрий Романович",
|
||||
"Захаров Сергей Григорьевич",
|
||||
"Панов Артём Маркович",
|
||||
"Исаев Владимир Елисеевич",
|
||||
"Кириллов Степан Дмитриевич",
|
||||
"Никитин Георгий Егорович",
|
||||
"Терехов Даниил Давидович",
|
||||
"Николаев Роман Артёмович",
|
||||
"Соболев Сергей Васильевич",
|
||||
"Афанасьев Серафим Тимофеевич",
|
||||
]
|
||||
|
||||
const female_full_name = [
|
||||
"Макарова Виктория Глебовна",
|
||||
"Фролова Александра Владимировна",
|
||||
"Сычева Валерия Дмитриевна",
|
||||
"Плотникова Милана Марковна",
|
||||
"Носкова Таисия Тимуровна",
|
||||
"Чернышева Алиса Михайловна",
|
||||
"Михайлова Мария Яковлевна",
|
||||
"Никитина Ева Владимировна",
|
||||
"Лобанова Василиса Тимофеевна",
|
||||
"Князева Анна Данииловна",
|
||||
]
|
||||
|
||||
function GenFullName() {
|
||||
const sex = GenMaxUInt(2) ? 'male' : 'female'
|
||||
|
||||
|
||||
let full_name
|
||||
|
||||
if (sex == 'male') {
|
||||
full_name = male_full_name
|
||||
} else {
|
||||
full_name = female_full_name
|
||||
}
|
||||
const l = full_name.length
|
||||
const name_i = GenMaxUInt(l)
|
||||
const surname_i = GenMaxUInt(l)
|
||||
const middle_name_i = GenMaxUInt(l)
|
||||
const [name] = full_name[name_i].split(' ')
|
||||
const [, surname] = full_name[surname_i].split(' ')
|
||||
const [, , middle_name] = full_name[middle_name_i].split(' ')
|
||||
|
||||
return `'${name} ${surname} ${middle_name}'`
|
||||
}
|
||||
|
||||
const food_product_names = [
|
||||
'хлеб',
|
||||
'картофель',
|
||||
'яйца',
|
||||
'лук',
|
||||
'чеснок',
|
||||
'соль',
|
||||
'сахар',
|
||||
'масло',
|
||||
'макароны',
|
||||
'молоко',
|
||||
]
|
||||
|
||||
const drug_names = [
|
||||
"парацетамол",
|
||||
"ибупрофен",
|
||||
"аспирин",
|
||||
"левомеколь",
|
||||
"активированный уголь",
|
||||
"но-шпа",
|
||||
"цитрамон",
|
||||
"лоратадин",
|
||||
"кагоцел",
|
||||
"амоксициллин",
|
||||
]
|
||||
|
||||
const street_names = [
|
||||
"Улица Ленина",
|
||||
"Проспект Мира",
|
||||
"Улица Гагарина",
|
||||
"Набережная Реки Фонтанки",
|
||||
"Бульвар Космонавтов",
|
||||
"Переулок Строителей",
|
||||
"Проезд Шевченко",
|
||||
"Улица 8 Марта",
|
||||
"Микрорайон Солнечный",
|
||||
"Шоссе Энтузиастов",
|
||||
]
|
||||
|
||||
function GenPassport() {
|
||||
let res = ''
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
res += GenMaxUInt(10)
|
||||
}
|
||||
return `'` + res.slice(0, 4) + ' ' + res.slice(4) + `'`
|
||||
}
|
||||
|
||||
function GenAddress() {
|
||||
return `'` + street_names[GenMaxUInt(street_names.length)] + ' ' + GenMaxUInt(100) + `'`
|
||||
}
|
||||
|
||||
function GenPasswdHash() {
|
||||
return `decode('${crypto.randomBytes(32).toString('base64')}', 'base64')`
|
||||
}
|
||||
|
||||
function GenEmail() {
|
||||
return `'${GenMaxUInt(1000)}@mephi.ru'`
|
||||
}
|
||||
|
||||
function GenPhone() {
|
||||
let res = `'+7`
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
res += GenMaxUInt(10)
|
||||
}
|
||||
return res + `'`
|
||||
}
|
||||
|
||||
const billing = [
|
||||
'сбербанк',
|
||||
'тинкофф',
|
||||
'ипб',
|
||||
]
|
||||
|
||||
function GenBillingAccount() {
|
||||
return `'${billing[GenMaxUInt(billing.length)]}'`
|
||||
}
|
||||
|
||||
function GenTimestamp() {
|
||||
const start = new Date(2024, 0, 1).getTime()
|
||||
const end = new Date(2026, 0, 1).getTime()
|
||||
|
||||
return `'${new Date(GenInt(start, end)).toISOString()}'`
|
||||
}
|
||||
|
||||
function GenIntervalHours(max = 6) {
|
||||
return `'${GenInt(1, max)} hours'`
|
||||
}
|
||||
|
||||
function GenPrice(max = 1000) {
|
||||
return (Math.random() * max + 10).toFixed(2)
|
||||
}
|
||||
|
||||
const ClassTypes = ['Theory', 'Practice']
|
||||
const RegistrationStatuses = ['NotPaid', 'Paid']
|
||||
const EquipmentUsageTypes = ['PayOnce', 'PayMonthly']
|
||||
|
||||
function Values(callback) {
|
||||
let res = 'VALUES\n'
|
||||
const count = 5
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
res += callback()
|
||||
|
||||
if (i == count - 1) {
|
||||
res += ';\n\n'
|
||||
} else {
|
||||
res += ',\n'
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
// Master
|
||||
let script = 'INSERT INTO "Master" (full_name, passwd_hash, passport, readme) ' + Values(() => {
|
||||
return `(${GenFullName()}, ${GenPasswdHash()}, ${GenPassport()}, 'aboba')`
|
||||
})
|
||||
|
||||
// Client
|
||||
script += 'INSERT INTO "Client" (full_name, passwd_hash, phone, email, billing_account) ' + Values(() => {
|
||||
return `(${GenFullName()}, ${GenPasswdHash()}, ${GenPassport()}, ${GenPhone()}, ${GenBillingAccount()})`
|
||||
})
|
||||
|
||||
// Studio
|
||||
script += 'INSERT INTO "Studio" (address, capacity, begin_date, duration) ' + Values(() => {
|
||||
return `(${GenAddress()}, ${GenInt(10, 80)}, ${GenTimestamp()}, ${GenIntervalHours(12)})`
|
||||
})
|
||||
|
||||
// Course
|
||||
script += 'INSERT INTO "Course" ("Master_id", name, price, duration) ' + Values(() => {
|
||||
return `(${GenInt(1, 6)}, 'курс ${GenMaxUInt(100)}', ${GenPrice()}, ${GenIntervalHours(20)})`
|
||||
})
|
||||
|
||||
// Class
|
||||
script += 'INSERT INTO "Class" (begin_date, "Course_id", "Studio_id", name, type, duration) ' + Values(() => {
|
||||
return `(${GenTimestamp()}, ${GenInt(1, 6)}, ${GenInt(1, 6)}, 'занятие ${GenMaxUInt(100)}', '${ClassTypes[GenMaxUInt(ClassTypes.length)]}', ${GenIntervalHours()})`
|
||||
})
|
||||
|
||||
// Class_Master
|
||||
script += `INSERT INTO "Class_Master" ("Class_begin_date", "Class_Course_id", "Master_id")
|
||||
SELECT begin_date, "Course_id", ${GenInt(1, 6)} FROM "Class" LIMIT 1;\n\n`
|
||||
|
||||
// Registration
|
||||
script += 'INSERT INTO "Registration" ("Client_id", "Course_id", date, status) ' + Values(() => {
|
||||
return `(${GenInt(6, 11)}, ${GenInt(1, 6)}, ${GenTimestamp()}, '${RegistrationStatuses[GenMaxUInt(RegistrationStatuses.length)]}')`
|
||||
})
|
||||
|
||||
// FoodProductEnum
|
||||
script += 'INSERT INTO "FoodProductEnum" (name, avg_price) ' + Values(() => {
|
||||
return `('${food_product_names[GenMaxUInt(food_product_names.length)]}', ${GenPrice(200)})`
|
||||
})
|
||||
|
||||
// FoodProduct
|
||||
script += `INSERT INTO "FoodProduct" ("FoodProductEnum_id", "Class_begin_date", "Class_Course_id", buy_price, buy_date, delivery_price, delivery_date, expires_date)
|
||||
SELECT ${GenInt(1, 6)}, begin_date, "Course_id", ${GenPrice()}, ${GenTimestamp()}, ${GenPrice()}, ${GenTimestamp()}, ${GenTimestamp()} FROM "Class" LIMIT 1;\n\n`
|
||||
|
||||
// Equipment
|
||||
script += 'INSERT INTO "Equipment" ("Studio_id", name, usage_price, usage_type, delivery_price, delivery_date) ' + Values(() => {
|
||||
return `(${GenInt(1, 6)}, 'оборудование ${GenMaxUInt(100)}', ${GenPrice(300)}, '${EquipmentUsageTypes[GenMaxUInt(EquipmentUsageTypes.length)]}', ${GenPrice(200)}, ${GenTimestamp()})`
|
||||
})
|
||||
|
||||
// Class_Equipment
|
||||
script += `INSERT INTO "Class_Equipment" ("Class_begin_date", "Class_Course_id", "Equipment_id")
|
||||
SELECT begin_date, "Course_id", ${GenInt(1, 6)} FROM "Class" LIMIT 1;\n\n`
|
||||
|
||||
// DrugEnum
|
||||
script += 'INSERT INTO "DrugEnum" (name, avg_price) ' + Values(() => {
|
||||
return `('${drug_names[GenMaxUInt(drug_names.length)]}', ${GenPrice(500)})`
|
||||
})
|
||||
|
||||
// Drug
|
||||
script += 'INSERT INTO "Drug" ("DrugEnum_id", "Course_id", buy_price, buy_date, delivery_price, delivery_date, expires_date) ' + Values(() => {
|
||||
return `(${GenInt(1, 6)}, ${GenInt(1, 6)}, ${GenPrice()}, ${GenTimestamp()}, ${GenPrice()}, ${GenTimestamp()}, ${GenTimestamp()})`
|
||||
})
|
||||
|
||||
// ActivityLog
|
||||
script += 'INSERT INTO "ActivityLog" ("Person_id", action) ' + Values(() => {
|
||||
return `(${GenInt(1, 10)}, 'login')`
|
||||
})
|
||||
|
||||
const tables = [
|
||||
'Person',
|
||||
'Client',
|
||||
'Master',
|
||||
'Studio',
|
||||
'Course',
|
||||
'Class',
|
||||
'Class_Master',
|
||||
'Registration',
|
||||
'FoodProductEnum',
|
||||
'FoodProduct',
|
||||
'Equipment',
|
||||
'Class_Equipment',
|
||||
'DrugEnum',
|
||||
'Drug',
|
||||
'DrugIntolerance',
|
||||
'ActivityLog'
|
||||
]
|
||||
|
||||
for (const table of tables) {
|
||||
script += `SELECT * FROM "${table}";\n`
|
||||
}
|
||||
|
||||
fs.writeFileSync('data.sql', script)
|
||||
|
||||
Reference in New Issue
Block a user