Add grades
This commit is contained in:
parent
e4acd91237
commit
6d6100eaf4
|
@ -27,26 +27,12 @@ async function run() {
|
||||||
}
|
}
|
||||||
console.log(`Table found: ${studentsTable.name}`)
|
console.log(`Table found: ${studentsTable.name}`)
|
||||||
|
|
||||||
const subjectTable = await createTable(apiKey, app._id, {
|
const students = [],
|
||||||
schema: {
|
subjects = []
|
||||||
Name: {
|
|
||||||
name: "Name",
|
|
||||||
type: "string",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
name: "Subjects",
|
|
||||||
})
|
|
||||||
|
|
||||||
for (let i = 0; i < SUBJECT_COUNT; i++) {
|
|
||||||
await createRow(apiKey, app._id, subjectTable, {
|
|
||||||
Name: generator.profession(),
|
|
||||||
})
|
|
||||||
console.log(`Subject ${i + 1} of ${SUBJECT_COUNT} created`)
|
|
||||||
await sleep(50)
|
|
||||||
}
|
|
||||||
|
|
||||||
let studentNumber = studentsTable.schema["Auto ID"].lastID
|
let studentNumber = studentsTable.schema["Auto ID"].lastID
|
||||||
for (let i = 0; i < STUDENT_COUNT; i++) {
|
for (let i = 0; i < STUDENT_COUNT; i++) {
|
||||||
|
students.push(
|
||||||
await createRow(apiKey, app._id, studentsTable, {
|
await createRow(apiKey, app._id, studentsTable, {
|
||||||
"Student Number": (++studentNumber).toString(),
|
"Student Number": (++studentNumber).toString(),
|
||||||
"First Name": generator.first(),
|
"First Name": generator.first(),
|
||||||
|
@ -57,8 +43,77 @@ async function run() {
|
||||||
"Home Number": generator.phone(),
|
"Home Number": generator.phone(),
|
||||||
"Attendance_(%)": generator.integer({ min: 0, max: 100 }),
|
"Attendance_(%)": generator.integer({ min: 0, max: 100 }),
|
||||||
})
|
})
|
||||||
|
)
|
||||||
console.log(`Row ${i + 1} of ${STUDENT_COUNT} created`)
|
console.log(`Row ${i + 1} of ${STUDENT_COUNT} created`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const subjectTable = await createTable(apiKey, app._id, {
|
||||||
|
schema: {
|
||||||
|
Name: {
|
||||||
|
name: "Name",
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Subjects",
|
||||||
|
primaryDisplay: "Name",
|
||||||
|
})
|
||||||
|
|
||||||
|
for (let i = 0; i < SUBJECT_COUNT; i++) {
|
||||||
|
subjects.push(
|
||||||
|
await createRow(apiKey, app._id, subjectTable, {
|
||||||
|
Name: generator.profession(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
console.log(`Subject ${i + 1} of ${SUBJECT_COUNT} created`)
|
||||||
|
await sleep(50)
|
||||||
|
}
|
||||||
|
|
||||||
|
const gradesTable = await createTable(apiKey, app._id, {
|
||||||
|
schema: {
|
||||||
|
Score: {
|
||||||
|
name: "Score",
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
Student: {
|
||||||
|
name: "Student",
|
||||||
|
tableId: studentsTable._id,
|
||||||
|
constraints: {
|
||||||
|
presence: true,
|
||||||
|
type: "array",
|
||||||
|
},
|
||||||
|
fieldName: "Grades",
|
||||||
|
relationshipType: "one-to-many",
|
||||||
|
type: "link",
|
||||||
|
},
|
||||||
|
Subject: {
|
||||||
|
name: "Subject",
|
||||||
|
tableId: subjectTable._id,
|
||||||
|
constraints: {
|
||||||
|
presence: true,
|
||||||
|
type: "array",
|
||||||
|
},
|
||||||
|
fieldName: "Grades",
|
||||||
|
relationshipType: "one-to-many",
|
||||||
|
type: "link",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Grades",
|
||||||
|
})
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
for (const student of students) {
|
||||||
|
for (const subject of subjects) {
|
||||||
|
await createRow(apiKey, app._id, gradesTable, {
|
||||||
|
Score: generator.integer({ min: 0, max: 100 }),
|
||||||
|
Student: [student],
|
||||||
|
Subject: [subject],
|
||||||
|
})
|
||||||
|
console.log(
|
||||||
|
`Grade ${++i} of ${students.length * subjects.length} created`
|
||||||
|
)
|
||||||
|
await sleep(20)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(err => {
|
run().catch(err => {
|
||||||
|
|
Loading…
Reference in New Issue