Skip to content

Commit

Permalink
Merge pull request #8 from levshuster/Database-Based
Browse files Browse the repository at this point in the history
Move over to PostgreSQL Backend
  • Loading branch information
levshuster authored Oct 16, 2024
2 parents 36bf0fb + 0cd4310 commit 49457a2
Show file tree
Hide file tree
Showing 55 changed files with 16,682 additions and 78 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# other
chromedriver
.streamlit/
.obsidian/
names/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.analysis.extraPaths": [
"./Helper Functions/Python"
]
}
102 changes: 102 additions & 0 deletions Back End/Database/database_structure.dbml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
Project debate_bias_calc {
database_type: 'PostgreSQL'
Note: 'Description of the project'
}

Table tournament_group.details {
id integer [primary key]
name text
updated timestamp
url text
parent_group integer [ref: > tournament_group.details.id]
to_scrape bool
details json
Note: "Examples: Washington State, TOC qualifiers, Urban Debate Leage, etc."
}

Table tournament_group.bindings {
group integer [ref: > tournament_group.details.id]
tournament integer [ref: > tournament.id]
}

Table tournament {
id integer [primary key]
name text
url text
updated timestamp
details json
to_scrape bool
leaf bool [note: 'to_scrape is false and leaf is true IFF tournament has never been scraped but is refered to by a round that came up when scraping a judge']
Note: "Examples: UPS invitational, Rose City Round Robin, etc."
}

Table division {
id integer
tournament integer [ref: > tournament.id]
division_name text
format text [note: "Policy, LD, Public Forum"]
level text [note: "Open, Novice, Varsity"]
round text [note: "Semi-Final, Round 1, 3"]
is_elimination bool
url text
date datetime
details json
to_scrape bool
leaf bool [note: 'to_scrape is false and leaf is true IFF division has never been scraped but is refered to by a round that came up when scraping a judge']
Note: "Example: Novice Public Forum, Varsity Policy, Open Dramatic Interp"
}

Table pairing.team {
url text [primary key]
to_scrape bool
}

Table pairing.debater {
name text
school text
first_name text [ref: > gender_binding.first_name]
team text [ref: > pairing.team.url]
}

Table pairing.judge {
url text [primary key]
id integer [ref: > judge.id]
to_scrape bool
}

Table pairing.votes {
judge integer [ref: > pairing.judge.url]
team text [ref: <> pairing.team.url]
division integer [ref: > division.id]
tournament integer [ref: > tournament.id]
won bool
side text
}

Table pairing.speaker_points {
judge integer [ref: > pairing.judge.id]
team text [ref: <> pairing.debater.team]
partial_name text [ref: <> pairing.debater.name]
division integer [ref: > division.id]
tournament integer [ref: > tournament.id]
value decimal
Note: "Partial name is most often just the debater last name, so JOIN pairing.debater ON team=team and partial_name IN name"
}

Table judge {
id integer [primary key]
name text
first_name text [ref: > gender_binding.first_name]
url text
to_scrape bool
updated timestamp
details json
}

Table gender_binding {
first_name text [primary key]
gender text
confidance decimal
updated timestamp
source text
}
176 changes: 176 additions & 0 deletions Back End/Database/debate_bias_calc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
CREATE SCHEMA "tournament_group";

CREATE SCHEMA "pairing";

CREATE TABLE "tournament_group"."details" (
"id" integer PRIMARY KEY,
"name" text,
"updated" timestamp,
"url" text,
"parent_group" integer,
"to_scrape" bool,
"details" json
);

CREATE TABLE "tournament_group"."bindings" (
"group" integer,
"tournament" integer
);

CREATE TABLE "tournament" (
"id" integer PRIMARY KEY,
"name" text,
"url" text,
"updated" timestamp,
"details" json,
"to_scrape" bool,
"leaf" bool
);

CREATE TABLE "division" (
"id" integer,
"tournament" integer,
"division_name" text,
"format" text,
"level" text,
"round" text,
"is_elimination" bool,
"url" text,
"date" datetime,
"details" json,
"to_scrape" bool,
"leaf" bool
);

CREATE TABLE "judge" (
"id" integer PRIMARY KEY,
"name" text,
"first_name" text,
"url" text,
"to_scrape" bool,
"updated" timestamp,
"details" json
);

CREATE TABLE "gender_binding" (
"first_name" text PRIMARY KEY,
"gender" text,
"confidance" decimal,
"updated" timestamp,
"source" text
);

CREATE TABLE "pairing"."team" (
"url" text PRIMARY KEY,
"to_scrape" bool
);

CREATE TABLE "pairing"."debater" (
"name" text,
"school" text,
"first_name" text,
"team" text
);

CREATE TABLE "pairing"."judge" (
"url" text PRIMARY KEY,
"id" integer,
"to_scrape" bool
);

CREATE TABLE "pairing"."votes" (
"judge" integer,
"team" text,
"division" integer,
"tournament" integer,
"won" bool,
"side" text
);

CREATE TABLE "pairing"."speaker_points" (
"judge" integer,
"team" text,
"partial_name" text,
"division" integer,
"tournament" integer,
"value" decimal
);

COMMENT ON TABLE "tournament_group"."details" IS 'Examples: Washington State, TOC qualifiers, Urban Debate Leage, etc.';

COMMENT ON TABLE "tournament" IS 'Examples: UPS invitational, Rose City Round Robin, etc.';

COMMENT ON COLUMN "tournament"."leaf" IS 'to_scrape is false and leaf is true IFF tournament has never been scraped but is refered to by a round that came up when scraping a judge';

COMMENT ON TABLE "division" IS 'Example: Novice Public Forum, Varsity Policy, Open Dramatic Interp';

COMMENT ON COLUMN "division"."format" IS 'Policy, LD, Public Forum';

COMMENT ON COLUMN "division"."level" IS 'Open, Novice, Varsity';

COMMENT ON COLUMN "division"."round" IS 'Semi-Final, Round 1, 3';

COMMENT ON COLUMN "division"."leaf" IS 'to_scrape is false and leaf is true IFF division has never been scraped but is refered to by a round that came up when scraping a judge';

COMMENT ON TABLE "pairing"."speaker_points" IS 'Partial name is most often just the debater last name, so JOIN pairing.debater ON team=team and partial_name IN name';

ALTER TABLE "tournament_group"."details" ADD FOREIGN KEY ("parent_group") REFERENCES "tournament_group"."details" ("id");

ALTER TABLE "tournament_group"."bindings" ADD FOREIGN KEY ("group") REFERENCES "tournament_group"."details" ("id");

ALTER TABLE "tournament_group"."bindings" ADD FOREIGN KEY ("tournament") REFERENCES "tournament" ("id");

ALTER TABLE "division" ADD FOREIGN KEY ("tournament") REFERENCES "tournament" ("id");

ALTER TABLE "pairing"."debater" ADD FOREIGN KEY ("first_name") REFERENCES "gender_binding" ("first_name");

ALTER TABLE "pairing"."debater" ADD FOREIGN KEY ("team") REFERENCES "pairing"."team" ("url");

ALTER TABLE "pairing"."judge" ADD FOREIGN KEY ("id") REFERENCES "judge" ("id");

ALTER TABLE "pairing"."votes" ADD FOREIGN KEY ("judge") REFERENCES "pairing"."judge" ("url");

CREATE TABLE "pairing"."team_votes" (
"team_url" text,
"votes_team" text,
PRIMARY KEY ("team_url", "votes_team")
);

ALTER TABLE "pairing"."team_votes" ADD FOREIGN KEY ("team_url") REFERENCES "pairing"."team" ("url");

ALTER TABLE "pairing"."team_votes" ADD FOREIGN KEY ("votes_team") REFERENCES "pairing"."votes" ("team");


ALTER TABLE "pairing"."votes" ADD FOREIGN KEY ("division") REFERENCES "division" ("id");

ALTER TABLE "pairing"."votes" ADD FOREIGN KEY ("tournament") REFERENCES "tournament" ("id");

ALTER TABLE "pairing"."speaker_points" ADD FOREIGN KEY ("judge") REFERENCES "pairing"."judge" ("id");

CREATE TABLE "pairing"."debater_speaker_points" (
"debater_team" text,
"speaker_points_team" text,
PRIMARY KEY ("debater_team", "speaker_points_team")
);

ALTER TABLE "pairing"."debater_speaker_points" ADD FOREIGN KEY ("debater_team") REFERENCES "pairing"."debater" ("team");

ALTER TABLE "pairing"."debater_speaker_points" ADD FOREIGN KEY ("speaker_points_team") REFERENCES "pairing"."speaker_points" ("team");


CREATE TABLE "pairing"."debater_speaker_points(1)" (
"debater_name" text,
"speaker_points_partial_name" text,
PRIMARY KEY ("debater_name", "speaker_points_partial_name")
);

ALTER TABLE "pairing"."debater_speaker_points(1)" ADD FOREIGN KEY ("debater_name") REFERENCES "pairing"."debater" ("name");

ALTER TABLE "pairing"."debater_speaker_points(1)" ADD FOREIGN KEY ("speaker_points_partial_name") REFERENCES "pairing"."speaker_points" ("partial_name");


ALTER TABLE "pairing"."speaker_points" ADD FOREIGN KEY ("division") REFERENCES "division" ("id");

ALTER TABLE "pairing"."speaker_points" ADD FOREIGN KEY ("tournament") REFERENCES "tournament" ("id");

ALTER TABLE "judge" ADD FOREIGN KEY ("first_name") REFERENCES "gender_binding" ("first_name");
12 changes: 12 additions & 0 deletions Back End/Database/debate_bias_calc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions Back End/Database/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Install PostgreSQL

https://wiki.postgresql.org/wiki/Homebrew

# Start postgres Service
Linux - `sudo service postgresql start`

# Load Database Schema

```bash
createdb debate_db

psql -d debate_db -f debate_bias_calc.sql # some unique constraint error are fine here

sudo -u postgres psql -d debate_db
CREATE USER debate_bias_user WITH PASSWORD 'debate_bias_user';

GRANT ALL ON ALL TABLES IN SCHEMA public TO debate_bias_user;
GRANT ALL ON ALL TABLES IN SCHEMA pairing TO debate_bias_user;
GRANT USAGE ON SCHEMA pairing TO debate_bias_user;

ALTER TABLE pairing.debater DROP CONSTRAINT debater_first_name_fkey;
ALTER TABLE pairing.judge DROP CONSTRAINT judge_id_fkey;
ALTER TABLE pairing.votes DROP CONSTRAINT votes_judge_fkey;
ALTER TABLE judge DROP CONSTRAINT judge_first_name_fkey;

\q


```

# load in bogus data

```psql
INSERT INTO tournament (id, name, url, updated, details, to_scrape)
VALUES
(1, 'Bogus Invitational', 'https://www.example.com/tournament/1', CURRENT_TIMESTAMP, '{"location": "Example City", "date": "2024-10-01"}', FALSE),
(2, 'Fictional Championship', 'https://www.example.com/tournament/2', CURRENT_TIMESTAMP, '{"location": "Sample Town", "date": "2024-11-15"}', FALSE);
```

# Other Useful Commands
`psql -d debate_db`
`dropdb debate_db`
`psql -d debate_db -f ../../../Back\ End/Database/debate_bias_calc.sql`
10 changes: 10 additions & 0 deletions Front End/GUI/Home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import streamlit as st
import pandas as pd

st.set_page_config(
page_title="Debate Bias Calc",
page_icon="🗣",
)

"# Debate Judge Bias Calculator"
"THis is also a test"
Loading

0 comments on commit 49457a2

Please sign in to comment.