Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database branch #35

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 54 additions & 0 deletions AI_Website/backend_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,57 @@ def create_admin():
if __name__ == '__main__':
db.create_all()
app.run(debug=True)


@app.route('/teacherDashboard', methods = ['POST'])
def teacher_dashboard():
#USE SQLALCHEMY TO ACCESS THE DATABASE

# Import the dependencies
from pathlib import Path
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine

# Create a reference to the dataset
database_path = Path("!!TO ADD DATABASE PATH!!")
# Create Database Connection
engine = create_engine(f"sqlite:///{database_path}")
#MAY NEED TO REVISE THIS FOR RENDER TOO.

# Declare a Base using `automap_base()`
Base = automap_base()

# Use the Base class to reflect the database tables
Base.prepare(autoload_with=engine)

# Print all of the classes mapped to the Base
Base.classes.keys()

# Create a session
session = Session(engine)

# Query relevant records in the the Database
queryDf = engine.execute("SELECT * FROM icecreamstore;")
summaryDf = jsonify(queryDf)

for record in data:
print(record)





#see https://stackoverflow.com/questions/60889087/how-to-fetch-data-from-postgresql-database-using-flask-and-display-html-tables

#1. From your db you read (select) your table and create a dataframe
#2. return jsonify( version of the dataframe) convert the df into a json object
#that is going to be used in the js code later
#other way to convert df to json is df.to_json()



#push to API
#use that dataframe in javascript code.


1 change: 1 addition & 0 deletions AI_Website/project3.json

Large diffs are not rendered by default.

Binary file added AI_Website/project3Data.xlsx
Binary file not shown.
94 changes: 94 additions & 0 deletions AI_Website/teacherScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
////1. read in data

//READ AND PROCESS THE STUDENT METADATA
let studentData = "../project3.json";


function essayPrint(id2, essay2){
console.log(indivStudent.filter(o => o.student_name == id2 ))
console.log(essay2)//indivStudent[id2]["essay"])
var headingElement = document.getElementById("studentEssayToPrint")
headingElement.textContent = essay2 // indivStudent[id2]["essay"]
}

//loop over and key-value pair.


//step 3: option change

function optionChanged(id){
//buildCharts(id)
intialProcess(id)
console.log(id)
}

function option2Changed (id2){
essayPrint(id2)
}



//STEP 1
function intialProcess(id) {
//get data
d3.json(studentData).then(function (data) {
//create empty studentArray to eventually save name
let studentArray = []
let dict_test = {}

//extract names
for (let index = 0; index < data.length; index++){
//save student name
let studentName = data[index]["student_name"];
//add student name to array of student names
studentArray.push(studentName)
}
//print array to check that worked
console.log(studentArray)

//create drop-down menu for the student name selection
let namesSelect = d3.select("#selDataset");

//append the student name to the drop-down
for (let index = 0; index < studentArray.length; index++) {
const element = studentArray[index];

// Append the text id, add a property to it. (WHAT IS THIS DOING?)
namesSelect.append("option").text(element).property("value", element);
}

//create drop-down menu for the essay selection for given student
let essaySelect = d3.select("#selEssay");

//save indivStudent as global variable so can be called by subsequent functions
globalThis.indivStudent = data.filter(o => o.student_name == id )
//check that this worked
console.log(indivStudent)

//reset essaySelect so only contains current student (not previous)
essaySelect = essaySelect.html("")
//append student essay to dropdown.
for (let index = 0; index < indivStudent.length; index++) {
const element1 = indivStudent[index].essay_set
console.log(element1)

// Append the text id, add a property to it. (WHAT IS THIS DOING?)
essaySelect.append("option").text(element1).property("value", element1)
}
essayPrint(id, essay)
//let essayPrint = indivStudent.filter(o => o.essay_set == element1)
}
)
}






intialProcess ('Leora Roakes')
// essayPrint(id2)
// optionChanged(id)
// option2Changed(id2)


76 changes: 76 additions & 0 deletions AI_Website/templates/teacherDashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dropdown Events</title>

<!-- <script src="project3.js"></script> -->
<script src="https://d3js.org/d3.v5.min.js"></script>
<!-- load plotly -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<!-- load teacher wrangle javascript -->
<!-- <script src="../test.js"></script> -->
<script src="../teacherScript.js"></script>

</head>



<body>

<div class="container">
<div class="row">
<div class="col-md-12 jumbotron text-center">
<h1>Individual Students' Essays</h1>
<p>Use the drop-down menus to see the full essays written by each student.</p>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="well">
<h3>Name and Essay Selection:</h3>
<select id="selDataset" onchange="optionChanged(this.value)"></select>
<select id="selEssay" onchange="option2Changed(this.value)"></select>
</div>
</div>
</div>
</div>
<div class = col-md-5></div>
<div></div>
<p>
</p>
<div class = col-md-5></div>
<h3> Student Essay: </h3>
<div id = "studentEssayToPrint"></div>
<p> </p>
<!-- <div class="col-md-5">
<div id="bar"></div>
</div>
<div class="col-md-5">
<div id="gauge"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="bubble"></div>
</div>
</div> -->
<div class="row">
<div class="col-md-12">
<div id="table"></div>
</div>
</div>
</div>




<!-- load d3 -->


</body>

</html>

126 changes: 126 additions & 0 deletions primary/rawData/databaseData/ERD-Textual Detectives.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/TBTB9r
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.

-- Modify this code to update the DB schema diagram.
-- To reset the sample schema, replace everything with
-- two dots ('..' - without quotes).

CREATE TABLE "essay_raw" (
"essayid_sql" int NOT NULL,
"essay" varchar NOT NULL,
CONSTRAINT "pk_essay_raw" PRIMARY KEY (
"essayid_sql"
)
);

CREATE TABLE "student_id" (
"student_name" text NOT NULL,
"student_id" int NOT NULL,
CONSTRAINT "pk_student_id" PRIMARY KEY (
"student_id"
)
);

CREATE TABLE "teacher_id" (
"teacher_name" text NOT NULL,
"teacher_id" int NOT NULL,
CONSTRAINT "pk_teacher_id" PRIMARY KEY (
"teacher_id"
)
);

CREATE TABLE "essay_metadata" (
"essayid_sql" int NOT NULL,
"essay_id" int NOT NULL,
"essay_set" int NOT NULL,
"ai_llm" text NOT NULL,
"ai_generated" int NOT NULL,
"student_id" int NOT NULL
);

CREATE TABLE "essay_tokens" (
"essayid_sql" int NOT NULL,
"word_tokens" varchar NOT NULL,
"setence_tokens" varchar NOT NULL,
"lemmatized_word_tokens" text NOT NULL
);

CREATE TABLE "essay_features_continuous" (
"essayid_sql" int NOT NULL,
"total_word_count" numeric NOT NULL,
"avg_word_length" numeric NOT NULL,
"avg_sentence_length1" numeric NOT NULL,
"TTR" numeric NOT NULL,
"stop_word_count" numeric NOT NULL,
"unique_word_count" numeric NOT NULL,
"rare_word_count" numeric NOT NULL,
"avg_sentence_length2" numeric NOT NULL,
"avg_parse_tree_depth" numeric NOT NULL,
"parse_tree_depth_variation" numeric NOT NULL,
"avg_adjectives_per_sentence" numeric NOT NULL,
"avg_adverbs_per_sentence" numeric NOT NULL,
"avg_verbs_per_sentence" numeric NOT NULL,
"avg_nouns_per_sentence" numeric NOT NULL,
"unknown" numeric NOT NULL,
"flesch_reading_ease" numeric NOT NULL,
"flesch_kincaid_grade_level" numeric NOT NULL,
"sentiment_polarity" numeric NOT NULL,
"sentiment_subjectivity" numeric NOT NULL,
"perplexity" numeric NOT NULL
);

CREATE TABLE "essay_features_string" (
"essayid_sql" int NOT NULL,
"word_freq" varchar NOT NULL,
"bigram_freq" varchar NOT NULL,
"trigram_freq" varchar NOT NULL
);

CREATE TABLE "teacher_student" (
"teacher_id" int NOT NULL,
-- foreign key
"student_id" int NOT NULL
);

CREATE TABLE "student_metadata" (
"student_id" int NOT NULL,
"student_pseudonym" varchar NOT NULL,
"student_grade" int NOT NULL
);

-- student_teachers int FK >-< teacher_id.teacher_id REMOVED AND ADDED DIFF TABLE
-- student_essays int FK -< essay_raw.essayid_sql REMOVED AND ADDED TO ESSAY TABLE
CREATE TABLE "teacher_metadata" (
-- foreign key
"teacher_id" int NOT NULL,
"teacher_grades" int NOT NULL
);

ALTER TABLE "essay_metadata" ADD CONSTRAINT "fk_essay_metadata_essayid_sql" FOREIGN KEY("essayid_sql")
REFERENCES "essay_raw" ("essayid_sql");

ALTER TABLE "essay_metadata" ADD CONSTRAINT "fk_essay_metadata_student_id" FOREIGN KEY("student_id")
REFERENCES "student_id" ("student_id");

ALTER TABLE "essay_tokens" ADD CONSTRAINT "fk_essay_tokens_essayid_sql" FOREIGN KEY("essayid_sql")
REFERENCES "essay_raw" ("essayid_sql");

ALTER TABLE "essay_features_continuous" ADD CONSTRAINT "fk_essay_features_continuous_essayid_sql" FOREIGN KEY("essayid_sql")
REFERENCES "essay_raw" ("essayid_sql");

ALTER TABLE "essay_features_string" ADD CONSTRAINT "fk_essay_features_string_essayid_sql" FOREIGN KEY("essayid_sql")
REFERENCES "essay_raw" ("essayid_sql");

ALTER TABLE "teacher_student" ADD CONSTRAINT "fk_teacher_student_teacher_id" FOREIGN KEY("teacher_id")
REFERENCES "teacher_id" ("teacher_id");

ALTER TABLE "teacher_student" ADD CONSTRAINT "fk_teacher_student_student_id" FOREIGN KEY("student_id")
REFERENCES "student_id" ("student_id");

ALTER TABLE "student_metadata" ADD CONSTRAINT "fk_student_metadata_student_id" FOREIGN KEY("student_id")
REFERENCES "student_id" ("student_id");

ALTER TABLE "teacher_metadata" ADD CONSTRAINT "fk_teacher_metadata_teacher_id" FOREIGN KEY("teacher_id")
REFERENCES "teacher_id" ("teacher_id");

18 changes: 18 additions & 0 deletions primary/rawData/databaseData/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SELECT e.essayid_sql, e.essay, em.essay_set, em.ai_llm, em.ai_generated
FROM essay_raw e
JOIN essay_metadata em ON e.essayid_sql = em.essay_id;


SELECT tm.teacher_id, tm.teacher_grades, sm.student_id, sm.student_grade
FROM teacher_metadata tm
JOIN student_metadata sm ON tm.teacher_id = tm.teacher_id;


SELECT tm.teacher_id, tm.teacher_grades, sm.student_id, sm.student_grade
FROM teacher_metadata tm
JOIN student_metadata sm ON tm.teacher_id = sm.teacher_id;

SELECT essayid_sql, essay
FROM essay_raw;


Binary file added primary/rawData/project3ProofOfConcept.xlsx
Binary file not shown.
Loading