| from supabase import create_client |
| from dotenv import load_dotenv |
| load_dotenv() |
| import os |
|
|
| SUPABASE_URL = os.getenv("SUPABASE_URL") |
| SUPABASE_KEY = os.getenv("SUPABASE_KEY") |
|
|
| supabase = create_client(SUPABASE_URL, SUPABASE_KEY) |
|
|
| def get_all_logs(): |
| try: |
| response = supabase.table("student_skills").select("user_id, skill").execute() |
| return [(item["user_id"], item["skill"]) for item in response.data] |
| except Exception as e: |
| print(f"Supabase Fetch Error: {e}") |
| return [] |
|
|
| def add_skill(user_id, skill): |
| |
| existing = supabase.table("student_skills")\ |
| .select("*")\ |
| .eq("user_id", user_id)\ |
| .eq("skill", skill)\ |
| .execute() |
| |
| if not existing.data: |
| supabase.table("student_skills")\ |
| .insert({"user_id": user_id, "skill": skill})\ |
| .execute() |
| print(f"Skill '{skill}' added for user {user_id}") |
|
|
| def init_db(): |
| supabase = create_client(SUPABASE_URL, SUPABASE_KEY) |
|
|
|
|
| def create_user(email, password, username): |
| try: |
| res = supabase.auth.sign_up({ |
| "email": email, |
| "password": password, |
| "options": { |
| "data": { |
| "username": username |
| } |
| } |
| }) |
| return "Registration successful! Connect with your email." |
| except Exception as e: |
| return f"Error: {str(e)}" |
| |
| def login(email, password): |
| try: |
| res = supabase.auth.sign_in_with_password({ |
| "email": email, |
| "password": password |
| }) |
| if res.user is not None: |
| return res.user.id |
| return None |
| except Exception as e: |
| print(f"Error during login: {e}") |
| return None |
| |
| |
| HIERARCHY = { |
| "Arithmetic Operations": {1: ["whole numbers", "ordering", "number line"], 2: ["integers"], 3: ["decimals"], 4: ["order of operations"]}, |
| "Fractions Decimals Percents": {1: ["equivalent fractions", "conversion"], 2: ["fraction", "decimal"], 3: ["mixed fractions"], 4: ["percent", "ratio", "rate"]}, |
| "Algebra Basics": {1: ["expression", "terms"], 2: ["like terms", "distributive"], 3: ["simplifying"], 4: ["polynomial"]}, |
| "Equations and Inequalities": {1: ["one step", "two step"], 2: ["solving"], 3: ["multi", "more than two"], 4: ["inequality"]}, |
| "Linear Functions": {1: ["pattern", "table"], 2: ["slope"], 3: ["graph"], 4: ["write linear equation", "from situation"]}, |
| "Systems of Equations": {3: ["graphing"], 4: ["substitution", "system"]}, |
| "Geometry": {1: ["angles", "triangle", "polygon"], 2: ["perimeter", "area"], 3: ["volume"], 4: ["surface area", "3d"]}, |
| "Statistics": {1: ["mean", "median", "mode"], 2: ["range"], 3: ["plot", "histogram"], 4: ["scatter", "sampling"]}, |
| "Probability": {1: ["single"], 2: ["venn"], 3: ["two"], 4: ["combinatorics", "counting"]}, |
| "Advanced Algebra": {2: ["factoring"], 3: ["quadratic"], 4: ["quadratic formula"]} |
| } |
|
|
| CLUSTERS = { |
| "Arithmetic Operations": ["addition", "subtraction", "multiplication", "division", "order of operations", "computation", "estimation"], |
| "Fractions Decimals Percents": ["fraction", "decimal", "percent", "ratio", "rate"], |
| "Number Theory": ["prime", "factor", "multiple", "divisibility", "gcf", "lcm", "odd", "even"], |
| "Algebra Basics": ["expression", "like terms", "distributive", "polynomial", "simplifying"], |
| "Equations and Inequalities": ["equation", "inequality", "solving", "variable"], |
| "Linear Functions": ["linear", "slope", "y-intercept", "graph", "table"], |
| "Systems of Equations": ["system"], |
| "Geometry": ["angle", "triangle", "polygon", "circle", "perimeter", "area", "volume", "surface area", "prism", "cone", "sphere"], |
| "Statistics": ["mean", "median", "mode", "range", "plot", "histogram", "scatter"], |
| "Probability": ["probability", "venn", "combinatorics", "counting"], |
| "Transformations": ["rotation", "reflection", "translation", "symmetry"], |
| "Coordinate Geometry": ["coordinate", "distance", "midpoint"], |
| "Advanced Algebra": ["quadratic", "factoring", "trinomials"] |
| } |
|
|
| def assign_cluster(skill): |
| skill_lower = skill.lower() |
| for cluster, keywords in CLUSTERS.items(): |
| if any(keyword in skill_lower for keyword in keywords): |
| return cluster |
| return "Other" |
|
|
| def assign_hierarchy(skill): |
| skill_lower = skill.lower() |
| for domain, levels in HIERARCHY.items(): |
| for level, keywords in levels.items(): |
| if any(keyword in skill_lower for keyword in keywords): |
| return domain, level |
| return "Other", -1 |
| |
| |
|
|
| |
|
|