Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
shakhzod2000 authored Nov 20, 2024
1 parent 0548c72 commit 3ccd698
Show file tree
Hide file tree
Showing 63 changed files with 13,753 additions and 0 deletions.
79 changes: 79 additions & 0 deletions quiz/static/JS/allQuestions_2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// allQuestions_2.js is a file that contains all questions and answers of the first 30 questions of the test.
import questions1 from './questions1.js';
import questions2 from './questions2.js';
import questions3 from './questions3.js';
import questions4 from './questions4.js';
import questions5 from './questions5.js';
import questions6 from './questions6.js';
import questions7 from './questions7.js';
import questions8 from './questions8.js';
import questions9 from './questions9.js';
import questions10 from './questions10.js';
import questions11 from './questions11.js';
import questions12 from './questions12.js';
import questions13 from './questions13.js';
import questions14 from './questions14.js';
import questions15 from './questions15.js';
import questions16 from './questions16.js';
import questions17 from './questions17.js';
import questions18 from './questions18.js';
import questions19 from './questions19.js';
import questions20 from './questions20.js';
import questions21 from './questions21.js';
import questions22 from './questions22.js';
import questions23 from './questions23.js';
import questions24 from './questions24.js';
import questions25 from './questions25.js';
import questions26 from './questions26.js';
import questions27 from './questions27.js';
import questions28 from './questions28.js';
import questions29 from './questions29.js';
import questions30 from './questions30.js';

import savollar1 from './savollar1.js';
import savollar2 from './savollar2.js';
import savollar3 from './savollar3.js';
import savollar4 from './savollar4.js';
import savollar5 from './savollar5.js';
import savollar6 from './savollar6.js';
import savollar7 from './savollar7.js';
import savollar8 from './savollar8.js';
import savollar9 from './savollar9.js';
import savollar10 from './savollar10.js';
import savollar11 from './savollar11.js';
import savollar12 from './savollar12.js';
import savollar13 from './savollar13.js';
import savollar14 from './savollar14.js';
import savollar15 from './savollar15.js';
import savollar16 from './savollar16.js';
import savollar17 from './savollar17.js';
import savollar18 from './savollar18.js';
import savollar19 from './savollar19.js';
import savollar20 from './savollar20.js';
import savollar21 from './savollar21.js';
import savollar22 from './savollar22.js';
import savollar23 from './savollar23.js';
import savollar24 from './savollar24.js';
import savollar25 from './savollar25.js';
import savollar26 from './savollar26.js';
import savollar27 from './savollar27.js';
import savollar28 from './savollar28.js';
import savollar29 from './savollar29.js';
import savollar30 from './savollar30.js';


const allQuestions_2 = {
questions1, questions2, questions3, questions4, questions5, questions6,
questions7, questions8, questions9, questions10, questions11, questions12,
questions13, questions14, questions15, questions16, questions17, questions18,
questions19, questions20, questions21, questions22, questions23, questions24,
questions25, questions26, questions27, questions28, questions29, questions30,

savollar1, savollar2, savollar3, savollar4, savollar5, savollar6,
savollar7, savollar8, savollar9, savollar10, savollar11, savollar12,
savollar13, savollar14, savollar15, savollar16, savollar17, savollar18,
savollar19, savollar20, savollar21, savollar22, savollar23, savollar24,
savollar25, savollar26, savollar27, savollar28, savollar29, savollar30
};

export default allQuestions_2;
114 changes: 114 additions & 0 deletions quiz/static/JS/insert_questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// insert_questions.js
import mysql from 'mysql';
import allQuestions_2 from './allQuestions_2.js';

const connection = mysql.createConnection({
host: 'essential-db-1.cnoi0w6aiqm7.us-east-1.rds.amazonaws.com',
user: 'admin',
password: '1ecg&xDvx',
database: 'essential_words'
});

connection.connect();

async function insertQuestions() {
try {
const quizId = await new Promise((resolve, reject) => {
connection.query('SELECT id FROM quizzes WHERE book = ?', ['E3'], function (error, results) {
if (error) return reject(error);
console.log('Quiz inserted with ID:', results.insertId);
resolve(results[0].id);
});
});

let questionCount = 0;

for (let unitNumber = 1; unitNumber <= 30; unitNumber++) {
const questionsDe = allQuestions_2[`questions${unitNumber}`] || [];

console.log(`Processing unit ${unitNumber}:`);

// Insert German questions
for (const question of questionsDe) {
console.log('Inserting German question:', question);
if (questionCount >= 600) break;
questionCount++;

const questionId = await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO questions (quiz_id, numb, question, answer, unit, language) VALUES (?, ?, ?, ?, ?, ?)',
[quizId, question.numb, question.question, question.answer, unitNumber, 'De'],
function (error, results) {
if (error) return reject(error);
console.log('Question inserted with ID:', results.insertId);
resolve(results.insertId);
}
);
});

for (const option of question.options) {
console.log('Inserting option:', option, 'for question ID:', questionId);
await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO options (question_id, option_text) VALUES (?, ?)',
[questionId, option],
function (error) {
if (error) return reject(error);
console.log('Option inserted for question ID:', questionId);
resolve();
}
);
});
}
}
}

questionCount = 0; // Reset question count

for (let unitNumber = 1; unitNumber <= 30; unitNumber++) {
const questionsEn = allQuestions_2[`savollar${unitNumber}`] || [];

// Insert English/Uzbek questions
for (const question of questionsEn) {
console.log('Inserting English/Uzbek question:', question);
if (questionCount >= 600) break;
questionCount++;

const questionId = await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO questions (quiz_id, numb, question, answer, unit, language) VALUES (?, ?, ?, ?, ?, ?)',
[quizId, question.numb, question.question, question.answer, unitNumber, 'En'],
function (error, results) {
if (error) return reject(error);
console.log('Question inserted with ID:', results.insertId);
resolve(results.insertId);
}
);
});

for (const option of question.options) {
console.log('Inserting option:', option, 'for question ID:', questionId);
await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO options (question_id, option_text) VALUES (?, ?)',
[questionId, option],
function (error) {
if (error) return reject(error);
console.log('Option inserted for question ID:', questionId);
resolve();
}
);
});
}
}
}

console.log(`Total questions inserted: ${questionCount} * 2`);
} catch (error) {
console.error('Error inserting questions:', error);
} finally {
connection.end();
}
}

insertQuestions();
114 changes: 114 additions & 0 deletions quiz/static/JS/insert_questions_root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// insert_questions.js
import mysql from 'mysql';
import allQuestions_2 from './allQuestions_2.js';

const connection = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: '1ecg&xDvx',
database: 'essential_words'
});

connection.connect();

async function insertQuestions() {
try {
const quizId = await new Promise((resolve, reject) => {
connection.query('SELECT id FROM quizzes WHERE book = ?', ['E3'], function (error, results) {
if (error) return reject(error);
console.log('Quiz inserted with ID:', results.insertId);
resolve(results[0].id);
});
});

let questionCount = 0;

for (let unitNumber = 1; unitNumber <= 30; unitNumber++) {
const questionsDe = allQuestions_2[`questions${unitNumber}`] || [];

console.log(`Processing unit ${unitNumber}:`);

// Insert German questions
for (const question of questionsDe) {
console.log('Inserting German question:', question);
if (questionCount >= 600) break;
questionCount++;

const questionId = await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO questions (quiz_id, numb, question, answer, unit, language) VALUES (?, ?, ?, ?, ?, ?)',
[quizId, question.numb, question.question, question.answer, unitNumber, 'De'],
function (error, results) {
if (error) return reject(error);
console.log('Question inserted with ID:', results.insertId);
resolve(results.insertId);
}
);
});

for (const option of question.options) {
console.log('Inserting option:', option, 'for question ID:', questionId);
await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO options (question_id, option_text) VALUES (?, ?)',
[questionId, option],
function (error) {
if (error) return reject(error);
console.log('Option inserted for question ID:', questionId);
resolve();
}
);
});
}
}
}

questionCount = 0; // Reset question count

for (let unitNumber = 1; unitNumber <= 30; unitNumber++) {
const questionsEn = allQuestions_2[`savollar${unitNumber}`] || [];

// Insert English/Uzbek questions
for (const question of questionsEn) {
console.log('Inserting English/Uzbek question:', question);
if (questionCount >= 600) break;
questionCount++;

const questionId = await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO questions (quiz_id, numb, question, answer, unit, language) VALUES (?, ?, ?, ?, ?, ?)',
[quizId, question.numb, question.question, question.answer, unitNumber, 'En'],
function (error, results) {
if (error) return reject(error);
console.log('Question inserted with ID:', results.insertId);
resolve(results.insertId);
}
);
});

for (const option of question.options) {
console.log('Inserting option:', option, 'for question ID:', questionId);
await new Promise((resolve, reject) => {
connection.query(
'INSERT INTO options (question_id, option_text) VALUES (?, ?)',
[questionId, option],
function (error) {
if (error) return reject(error);
console.log('Option inserted for question ID:', questionId);
resolve();
}
);
});
}
}
}

console.log(`Total questions inserted: ${questionCount} * 2`);
} catch (error) {
console.error('Error inserting questions:', error);
} finally {
connection.end();
}
}

insertQuestions();
Loading

0 comments on commit 3ccd698

Please sign in to comment.