Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 218 additions & 68 deletions Week2/QA-session-content/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Week2/QA-session-content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"epic_todolist": "file:",
"faker": "^4.1.0",
"knex": "^2.4.0",
"mysql": "^2.18.1",
Expand Down
17 changes: 17 additions & 0 deletions Week2/assignment/Aggregate-Functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
host: 'localhost',
user: 'hyfuser',
password: 'hyfpassword'
});


export const aggreg = async() => {
connection.query("SELECT paper_title, COUNT(author_id) AS author_count FROM research_papers GROUP BY paper_title");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rework: based on the current table schema, you always get one author per paper, as author_id in paper table accepts only one int. You need to use the relationship table.

connection.query("SELECT COUNT(research_papers.paper_id) FROM research_papers INNER JOIN authors on authors.author_id = research_papers.author_id WHERE authors.gender = 'female'");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection.query("SELECT COUNT(research_papers.paper_id) FROM research_papers INNER JOIN authors on authors.author_id = research_papers.author_id WHERE authors.gender = 'female'");
Needs rework: same here, you need to use the relationship table. And be careful: what if several female authors are writing the same paper? Will the same paper be counted multiple times?

connection.query("SELECT university, FROM authors GROUP BY university");
connection.query("SELECT university, COUNT(paper_id) FROM authors GROUP BY university");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection.query("SELECT university, COUNT(paper_id) FROM authors GROUP BY university");
Needs rework: you have changed your table schemas to have the relationship table, and there's no paper_id column in authors. So you have to write this query using the relationship table. And be careful: what if several authors from the same university are writing the same paper? Will the same paper be counted multiple times?

connection.query("SELECT university, MIN(h_index), MAX(h_index) FROM authors GROUP BY university");

};
12 changes: 12 additions & 0 deletions Week2/assignment/Joins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
host: 'localhost',
user: 'hyfuser',
password: 'hyfpassword'
});

export const joins = async() => {
connection.query("SELECT author_name, mentor FROM authors");
connection.query("SELECT authors.author_name, research_papers.paper_title FROM authors LEFT JOIN research_papers ON authors.author_id = research_papers. author_id");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rework: what if a paper has several different authors? You should use the relationship table.

};
31 changes: 31 additions & 0 deletions Week2/assignment/Keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
host: 'localhost',
user: 'hyfuser',
password: 'hyfpassword'
});

try {
await connection.query('CREATE DATABASE IF NOT EXISTS week2');
await connection.query('USE week2');

await connection.query(`
CREATE TABLE IF NOT EXISTS authors (
author_id INT AUTO_INCREMENT PRIMARY KEY,
author_name VARCHAR(50) NOT NULL,
university TEXT,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: TEXT is for long text. VARCHAR should be enough for university name.

date_of_birth DATE NOT NULL,
h_index INT NOT NULL,
paper_id INT,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need rework: if an author write several papers, is paper_id a good idea to have in the author table?

You can re-think about the relationship between papers and authors.

mentor INT,
gender ENUM("male","female","other"),
FOREIGN KEY (mentor) REFERENCES authors(author_id)
)`);


} catch (error) {
console.error(error);
}

connection.end();
72 changes: 72 additions & 0 deletions Week2/assignment/Relationships.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
host: 'localhost',
user: 'hyfuser',
password: 'hyfpassword'
});

export const relationships = async() => {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you export those functions but I didn't see you use them?

await connection.query(`
CREATE TABLE IF NOT EXISTS research_papers (
paper_id INT AUTO_INCREMENT PRIMARY KEY,
paper_title VARCHAR(100) NOT NULL,
conference TEXT,
author_id INT,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have a new table for the relationship between authors and papers, you don't need author_id column in paper table, as one paper can be written by several authors.

FOREIGN KEY (author_id) REFERENCES authors(author_id)
)`);


await connection.query(`
INSERT INTO authors (author_name, university, date_of_birth, h_index, gender) VALUES
('Alice Smith', 'MIT', '1980-05-14', 32, 'female'),
('Bob Johnson', 'Stanford', '1975-03-22', 40, 'male'),
('Carol White', 'Harvard', '1982-07-11', 28, 'female'),
('David Brown', 'Cambridge', '1990-01-09', 18, 'male'),
('Eve Davis', 'Oxford', '1987-11-29', 35, 'female'),
('Frank Miller', 'ETH Zurich', '1978-08-30', 30, 'male'),
('Grace Wilson', 'Caltech', '1985-09-20', 25, 'female'),
('Henry Moore', 'Princeton', '1991-04-17', 22, 'male'),
('Ivy Taylor', 'Yale', '1983-02-13', 27, 'female'),
('Jack Anderson', 'Columbia', '1986-06-06', 29, 'male'),
('Karen Thomas', 'UCLA', '1979-12-19', 31, 'female'),
('Leo Jackson', 'Toronto', '1988-10-23', 19, 'male'),
('Mona Lewis', 'TUM', '1993-03-03', 21, 'female'),
('Nina Harris', 'Sorbonne', '1990-09-09', 24, 'female'),
('Oscar Martin', 'EPFL', '1984-04-04', 33, 'male')
`);

await connection.query(
`INSERT INTO research_Papers (paper_title, conference, publish_date, author_id) VALUES
('Quantum AI', 'NeurIPS', '2020-12-01', 1),
('Deep Learning Optimization', 'ICML', '2021-07-10', 1),
('Neural Graphs', 'CVPR', '2019-06-15', 2),
('Bioinformatics Trends', 'RECOMB', '2022-04-03', 3),
('Genetic Algorithms', 'GECCO', '2018-07-28', 3),
('Quantum Circuits', 'QIP', '2020-01-20', 4),
('AI in Medicine', 'MedConf', '2021-11-12', 5),
('Secure ML', 'IEEE S&P', '2022-05-06', 6),
('Blockchain Systems', 'CryptoCon', '2019-08-08', 6),
('Data Visualization', 'VIS', '2020-10-15', 7),
('NLP Advancements', 'ACL', '2021-08-20', 8),
('Ethics of AI', 'AAAI', '2020-02-14', 9),
('Robotics Control', 'ICRA', '2018-05-30', 10),
('Swarm Intelligence', 'ANTS', '2021-09-01', 10),
('3D Vision', 'SIGGRAPH', '2019-07-15', 11),
('Cloud Security', 'USENIX', '2022-01-10', 12),
('Edge Computing', 'EdgeConf', '2021-03-22', 12),
('IoT Protocols', 'IoTConf', '2020-06-13', 13),
('Image Compression', 'ICIP', '2019-09-09', 14),
('Virtual Reality', 'VRConf', '2021-12-05', 14),
('BioNLP', 'EMNLP', '2019-11-11', 15),
('AI+Law', 'LAWConf', '2022-02-18', 15),
('Graph Theory AI', 'NeurIPS', '2021-07-07', 5),
('Medical Robotics', 'MedConf', '2022-03-04', 7),
('AI for Education', 'EDM', '2020-04-20', 8),
('Data Ethics', 'FAT*', '2019-05-25', 9),
('ML at Scale', 'BigDataConf', '2021-10-30', 11),
('Vision & Language', 'CVPR', '2022-06-01', 13),
('Quantum ML', 'QMLConf', '2020-12-12', 2),
('Adversarial Attacks', 'BlackHat', '2021-01-09', 4)`);
}
148 changes: 148 additions & 0 deletions Week2/assignment/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Week2/assignment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "assignment",
"version": "1.0.0",
"main": "authors.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"assignment": "file:",
"mysql2": "^3.14.1"
}
}