Первый этап готов

This commit is contained in:
Данила Мочалов 2023-05-14 15:26:22 +04:00
parent 5cdd7ec752
commit e04eefb8a2
14 changed files with 177 additions and 29 deletions

2
abitur_list_client/.env Normal file
View File

@ -0,0 +1,2 @@
dbPath='../controllers/'
#delete '/mongo' to switch to pgsql

View File

@ -1,4 +1,5 @@
const express = require('express')
require('dotenv').config()
const abiturRouter = require('./routes/abitur.routes')
const examResultRouter = require('./routes/examresult.routes')

View File

@ -5,6 +5,7 @@ const crypto = require('crypto');
const AbiturControllerInterface = require('../../controllers/interfaces/abitur.controller.interface');
const { ObjectId } = require('mongodb');
const e = require('express');
class AbiturController extends AbiturControllerInterface{
@ -39,7 +40,7 @@ class AbiturController extends AbiturControllerInterface{
// const newAbitur = await db.query('INSERT INTO abitur (id, first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *', [id, first_name, last_name, middle_name, email, hash])
// res.json(newAbitur.rows[0])
const {id, first_name, last_name, middle_name, email, password} = req.body
const {id, first_name, last_name, middle_name, email, password, exam_results, requests} = req.body
var hash = crypto.createHash('md5').update(password).digest('hex')
@ -51,10 +52,12 @@ class AbiturController extends AbiturControllerInterface{
last_name: last_name,
middle_name: middle_name,
email: email,
password: hash
password: hash,
exam_results: exam_results,
requests: requests
})
if (newAbitur!=null) res.json({id: 1})
res.json({id: 1})
}
async getAbiturs(req, res) {
// const abiturs = await db.query('SELECT * FROM abitur')
@ -116,7 +119,8 @@ class AbiturController extends AbiturControllerInterface{
// res.json(abiturs.rows)
const collection = mymongodb.collection('abiturs')
await collection.drop()
await collection.deleteMany({})
res.json({id: 1})
}
}

View File

@ -80,6 +80,23 @@ class ExamResultController extends ExamResultControllerInterface {
// const id = req.params.id
// const result = await db.query('select avg(result) from exam_result where id in (select exam_result_id from request_exam_result where request_id in (select id from request where specialization_id = $1))', [id])
// res.json(result.rows[0])
const title = req.params.id
const collection = mymongodb.collection('abiturs')
const answer = await collection.aggregate([
{ $match: { "requests.specialization": title } },
{ $unwind: "$requests" },
{ $unwind: "$requests.exam_results" },
{
$group: {
_id: {
specialization: "$requests.specialization"
},
avg_result: { $avg: "$requests.exam_results.result" }
}
}
]).toArray()
res.json(answer[0])
}
}

View File

@ -113,6 +113,8 @@ class RequestController extends RequestControllerInterface {
} }
}
)
res.json({id: 1})
}
async deleteRequest(req, res) {
// const id = req.params.id
@ -137,6 +139,20 @@ class RequestController extends RequestControllerInterface {
// const id = req.params.id
// const requests = await db.query('SELECT COUNT(*) FROM request WHERE specialization_id=$1', [id])
// res.json(requests.rows[0])
const title = req.params.id
const collection = mymongodb.collection('abiturs')
const answer = await collection.aggregate([
{ $unwind: "$requests" },
{ $match: { "requests.specialization": title } },
{
$group: {
_id: { firstname: "$first_name", lastname: "$last_name"},
count: { $sum: 1 }
}
}
]).toArray()
res.json(answer.length)
}
}

View File

@ -10,6 +10,7 @@
"dependencies": {
"axios": "^1.3.4",
"core-js": "^3.8.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mongodb": "^5.5.0",
"mongoose": "^7.1.1",
@ -2588,6 +2589,15 @@
}
}
},
"node_modules/@vue/cli-service/node_modules/dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
"dev": true,
"engines": {
"node": ">=10"
}
},
"node_modules/@vue/cli-shared-utils": {
"version": "5.0.8",
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/-/cli-shared-utils-5.0.8.tgz",
@ -4727,12 +4737,11 @@
}
},
"node_modules/dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
"dev": true,
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
"engines": {
"node": ">=10"
"node": ">=12"
}
},
"node_modules/dotenv-expand": {
@ -12186,6 +12195,14 @@
"webpack-merge": "^5.7.3",
"webpack-virtual-modules": "^0.4.2",
"whatwg-fetch": "^3.6.2"
},
"dependencies": {
"dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
"dev": true
}
}
},
"@vue/cli-shared-utils": {
@ -13944,10 +13961,9 @@
}
},
"dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
"dev": true
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
},
"dotenv-expand": {
"version": "5.1.0",

View File

@ -11,6 +11,7 @@
"dependencies": {
"axios": "^1.3.4",
"core-js": "^3.8.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mongodb": "^5.5.0",
"mongoose": "^7.1.1",

View File

@ -1,8 +1,8 @@
const Router = require('express')
const router = new Router()
const abiturController = require('../controllers/abitur.controller')
//const abiturController = require('../mongo/controllers/abitur.controller')
//const abiturController = require('../controllers/abitur.controller')
const abiturController = require(process.env.dbPath + 'abitur.controller')
router.post('/abitur', abiturController.createAbitur)
router.post('/abitur/manual', abiturController.createAbiturWithId)

View File

@ -1,8 +1,8 @@
const Router = require('express')
const router = new Router()
const educationformController = require('../controllers/educationform.controller')
//const educationformController = require('../mongo/controllers/educationform.controller')
//const educationformController = require('../controllers/educationform.controller')
const educationformController = require(process.env.dbPath + 'educationform.controller')
router.post('/educationform', educationformController.createEducationForm)
router.get('/educationform', educationformController.getEducationForms)

View File

@ -1,8 +1,8 @@
const Router = require('express')
const router = new Router()
const examResultController = require('../controllers/examresult.controller')
//const examResultController = require('../mongo/controllers/examresult.controller')
//const examResultController = require('../controllers/examresult.controller')
const examResultController = require(process.env.dbPath + 'examresult.controller')
router.post('/examresult', examResultController.createExamResult)
router.post('/examresult/manual', examResultController.createExamResultWithId)

View File

@ -1,8 +1,8 @@
const Router = require('express')
const router = new Router()
const requestController = require('..//controllers/request.controller')
//const requestController = require('../mongo/controllers/request.controller')
//const requestController = require('..//controllers/request.controller')
const requestController = require(process.env.dbPath + 'request.controller')
router.post('/request', requestController.createRequest)
router.post('/request/manual', requestController.createRequestWithId)

View File

@ -1,8 +1,8 @@
const Router = require('express')
const router = new Router()
const specializationController = require('../controllers/specialization.controller')
//const specializationController = require('../mongo/controllers/specialization.controller')
//const specializationController = require('../controllers/specialization.controller')
const specializationController = require(process.env.dbPath + 'specialization.controller')
router.post('/specialization', specializationController.createSpecialization)
router.get('/specialization', specializationController.getSpecializations)

View File

@ -183,8 +183,8 @@ export default {
let data = JSON.stringify({
"id": this.requestId,
"education_form": this.educationForm,
"specialization": this.specialization,
"education_form": this.educationForm['title'] ?? this.educationForm,
"specialization": this.specialization['title'] ?? this.specialization,
"exam_results": this.results,
"date": this.request['date'],
"abitur_id": localStorage.getItem('abiturId')
@ -200,7 +200,7 @@ export default {
data : data
};
axios.request(config)
await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
@ -239,7 +239,7 @@ export default {
data : data
};
axios.request(config)
await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})

View File

@ -39,7 +39,10 @@ export default {
methods: {
async getDestiny() {
if (this.specialization == null) return
if (localStorage.getItem('db') == 'mongo') {
await this.getMongoDestiny()
return
}
var time = performance.now()
var avg = (await axios.get('http://127.0.0.1:8080/api/examresult/avgBySpec/'+this.specialization['id'])).data
@ -57,6 +60,22 @@ export default {
this.destiny = 'ЗАПРОСОВ: ' + count['count'] + ', СРЕДНИЙ BALL: ' + avg['avg'] + '. ПОЗДРАВЛЯЮ! Время: ' + time + 'c.'
},
async getMongoDestiny() {
var time = performance.now()
var avg = (await axios.get('http://127.0.0.1:8080/api/examresult/avgBySpec/'+this.specialization['title'] ?? this.specialization)).data
console.log(avg['avg_result'])
var count = (await axios.get('http://127.0.0.1:8080/api/request/spec/'+this.specialization['title'])).data
console.log(count)
var time = (performance.now() - time) / 1000
if (count == null || avg == null) {
this.destiny = 'ТВОЯ ОТЧЕТНОСТЬ ПРОКЛЯТА. УБИРАЙСЯ!'
return
}
this.destiny = 'ЗАПРОСОВ: ' + count + ', СРЕДНИЙ BALL: ' + avg['avg_result'] + '. ПОЗДРАВЛЯЮ! Время: ' + time + 'c.'
},
async deleteAllAbiturs() {
try {
this.deleteAllMessage='Жнец идет за их душами...'
@ -77,6 +96,12 @@ export default {
if (this.specializations == null || this.specialization.length == 0) {
return
}
if (localStorage.getItem('db') == 'mongo') {
await this.generateMongoSlaves()
return
}
console.log(this.specializations)
// удалим старых, дорогу молодым емае
await this.deleteAllAbiturs()
@ -200,11 +225,77 @@ export default {
var matan = Math.floor(Math.random() * max);
console.log('matan end')
return matan
}
},
async generateMongoSlaves() {
// удалим старых, дорогу молодым емае
await this.deleteAllAbiturs()
this.magicMessage='Плодим, ждите...'
var averageTime = 0
for(const spec of this.specializations) {
// создаем бедных студентиков сто штучек оптовая цена
var oneSpecTime = performance.now()
for (let abiturNum = 0 + parseInt(spec['id'], 10) * 100; abiturNum < 100 + parseInt(spec['id'], 10) * 100; abiturNum++) {
let exam_results = [
{
"title": "Exam#" + abiturNum + "-1",
"result": this.getRandomInt(100)
},
{
"title": "Exam#" + abiturNum + "-2",
"result": this.getRandomInt(100)
},
{
"title": "Exam#" + abiturNum + "-3",
"result": this.getRandomInt(100)
}
]
let data = JSON.stringify({
"id": abiturNum,
"first_name": "Vasya " + abiturNum,
"last_name": "Pupkin " + abiturNum,
"middle_name": "Vasylyevich " + abiturNum,
"email": "mylo" + abiturNum,
"password": "parol" + abiturNum,
"exam_results": exam_results,
"requests": [
{
"exam_results": exam_results,
"date": Date.now(),
"specialization": spec['title'],
"education_form": "Заочная"
}
]
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'http://127.0.0.1:8080/api/abitur/manual',
headers: {
'Content-Type': 'application/json'
},
data : data
};
await axios.request(config)
}
oneSpecTime = performance.now() - oneSpecTime
averageTime += oneSpecTime
}
averageTime = averageTime / this.specializations.length / 1000
this.magicMessage='Наплодили! Среднее время на каждую специализацию: '+ averageTime + 'c.'
},
},
async created() {
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
this.specialization = this.specializations[0]
}