Skip to content

Commit

Permalink
Merge pull request #167 from cuappdev/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Aayush-Agnihotri authored Oct 25, 2024
2 parents de53512 + d3b53e1 commit c128cb6
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 120 deletions.
26 changes: 19 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.9
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.3
hooks:
- id: flake8
# Run the linter.
- id: ruff
args: [--fix]
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0
hooks:
- id: bandit
16 changes: 6 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import sentry_sdk
from flask import Flask, render_template, redirect, url_for
from flask import Flask, render_template
from flask_apscheduler import APScheduler
from flask_graphql import GraphQLView
from graphene import Schema
Expand All @@ -16,6 +16,8 @@
from src.scrapers.activities_scraper import fetch_activity
from src.utils.utils import create_gym_table
from src.models.openhours import OpenHours
from flasgger import Swagger


sentry_sdk.init(
dsn="https://2a96f65cca45d8a7c3ffc3b878d4346b@o4507365244010496.ingest.us.sentry.io/4507850536386560",
Expand All @@ -31,6 +33,7 @@
app = Flask(__name__)
app.debug = True
schema = Schema(query=Query, mutation=Mutation)
swagger = Swagger(app)

# Scheduler
scheduler = APScheduler()
Expand Down Expand Up @@ -81,15 +84,8 @@ def scrape_capacities():
def scrape_classes():
logging.info("Scraping classes from group-fitness-classes...")

fetch_classes(3)


# Scrape classes every hour
@scheduler.task("interval", id="scrape_classes", seconds=3600)
def scrape_classes():
logging.info("Scraping classes from group-fitness-classes...")

fetch_classes(3)
fetch_classes(10)


# Create database and fill it with data
Expand All @@ -108,4 +104,4 @@ def scrape_classes():
schema_file.close()

if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
app.run(host="127.0.0.1", port=5000)
7 changes: 3 additions & 4 deletions manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from app import app#, db
from flask_migrate import MigrateCommand
from app import app # , db

# Build manager
#migrate = Migrate(app, db)
# migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command("db", MigrateCommand)

Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Flask-GraphQL==2.0.0
Flask-Migrate==2.4.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.3.1
Flask-RESTful==0.3.10
flasgger==0.9.7.1
google-auth==1.12.0
graphene==2.1.3
graphene-sqlalchemy==2.3.0
Expand All @@ -38,7 +40,7 @@ itsdangerous==2.0
jedi==0.18.2
Jinja2==3.0
lxml==4.9.2
Mako==1.0.9
Mako==1.1.0
MarkupSafe==2.1.1
marshmallow==3.0.0rc4
marshmallow-sqlalchemy==0.16.2
Expand Down Expand Up @@ -77,4 +79,4 @@ wasmer-compiler-cranelift==1.1.0
wcwidth==0.2.6
Werkzeug==2.2.2
zipp==3.15.0
sentry-sdk==2.13.0
sentry-sdk==2.13.0
55 changes: 49 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ type CreateGiveaway {
giveaway: Giveaway
}

type CreateReport {
report: Report
}

type CreateUser {
user: User
}

scalar DateTime

type EnterGiveaway {
giveawayInstance: GiveawayInstance
enum DayOfWeekEnum {
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
}

type Equipment {
Expand Down Expand Up @@ -141,12 +151,15 @@ type Gym {
facilities: [Facility]
hours: [OpenHours]
classes: [ClassInstance]
reports: [Report]
}

type Mutation {
createGiveaway(name: String!): CreateGiveaway
createUser(instagram: String, netId: String!): CreateUser
enterGiveaway(giveawayId: Int!, userNetId: String!): EnterGiveaway
createGiveaway(name: String!): Giveaway
createUser(email: String!, name: String!, netId: String!): User
enterGiveaway(giveawayId: Int!, userNetId: String!): GiveawayInstance
setWorkoutGoals(userId: Int!, workoutGoal: [String]!): User
logWorkout(userId: Int!, workoutTime: DateTime!): Workout
}

type OpenHours {
Expand Down Expand Up @@ -178,12 +191,42 @@ enum PriceType {
type Query {
getAllGyms: [Gym]
getUsersByGiveawayId(id: Int): [User]
getWeeklyWorkoutDays(id: Int): [String]
getWorkoutsById(id: Int): [Workout]
activities: [Activity]
}

type Report {
id: ID!
createdAt: DateTime!
description: String!
gymId: Int!
issue: ReportType!
userId: Int!
gym: Gym
user: User
}

enum ReportType {
INACCURATE_EQUIPMENT
INCORRECT_HOURS
INACCURATE_DESCRIPTION
WAIT_TIMES_NOT_UPDATED
OTHER
}

type User {
id: ID!
instagram: String
email: String!
netId: String!
name: String!
workoutGoal: [DayOfWeekEnum]
giveaways: [Giveaway]
reports: [Report]
}

type Workout {
id: ID!
workoutTime: DateTime!
userId: Int!
}
3 changes: 2 additions & 1 deletion src/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging, os
import logging
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
Expand Down
21 changes: 4 additions & 17 deletions src/models/classes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import datetime
from src.database import Base
from sqlalchemy import (
Table,
Column,
DateTime,
ForeignKey,
Integer,
Float,
String,
Boolean,
func,
)
from sqlalchemy import Table, Column, DateTime, ForeignKey, Integer, String, Boolean
from sqlalchemy.orm import backref, relationship

classes_to_gyms = Table(
Expand All @@ -31,8 +20,8 @@ class Class(Base):
__tablename__ = "class"

id = Column(Integer, primary_key=True)
name = Column(String(), nullable=False)
description = Column(String(), nullable=False)
name = Column(String, nullable=False)
description = Column(String, nullable=False)
class_instances = relationship("ClassInstance", back_populates="class_")

def __init__(self, **kwargs):
Expand All @@ -46,7 +35,7 @@ def serialize(self):
"name": self.name,
"description": self.description,
}


class ClassInstance(Base):
__tablename__ = "class_instance"
Expand Down Expand Up @@ -86,5 +75,3 @@ def serialize(self):
"start_time": self.start_time,
"end_time": self.end_time,
}


53 changes: 26 additions & 27 deletions src/models/equipment.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import enum
from sqlalchemy import Column, String, Enum, Integer, ForeignKey
from sqlalchemy.orm import relationship
from src.database import Base


class EquipmentType(enum.Enum):

cardio = 0
racks_and_benches = 1
selectorized = 2
multi_cable = 3
free_weights = 4
miscellaneous = 5
plate_loaded = 6
cardio = 0
racks_and_benches = 1
selectorized = 2
multi_cable = 3
free_weights = 4
miscellaneous = 5
plate_loaded = 6


class AccessibilityType(enum.Enum):

wheelchair = 0

class Equipment(Base):

__tablename__ = "equipment"
wheelchair = 0

id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
equipment_type = Column(Enum(EquipmentType), nullable=False)
facility_id = Column(Integer, ForeignKey("facility.id"), nullable=False)
quantity = Column(Integer, nullable=True)
accessibility = Column(Enum(AccessibilityType), nullable=True)

def __init__(self, **kwargs):
self.id = kwargs.get("id")
self.name = kwargs.get("name")
self.equipment_type = kwargs.get("equipment_type")
self.facility_id = kwargs.get("facility_id")
self.quantity = kwargs.get("quantity")
self.accessibility = kwargs.get("accessibility")

class Equipment(Base):

__tablename__ = "equipment"

id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
equipment_type = Column(Enum(EquipmentType), nullable=False)
facility_id = Column(Integer, ForeignKey("facility.id"), nullable=False)
quantity = Column(Integer, nullable=True)
accessibility = Column(Enum(AccessibilityType), nullable=True)

def __init__(self, **kwargs):
self.id = kwargs.get("id")
self.name = kwargs.get("name")
self.equipment_type = kwargs.get("equipment_type")
self.facility_id = kwargs.get("facility_id")
self.quantity = kwargs.get("quantity")
self.accessibility = kwargs.get("accessibility")
3 changes: 0 additions & 3 deletions src/models/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from sqlalchemy import Column, String, Enum, Integer, ForeignKey
from sqlalchemy.orm import relationship
from src.database import Base
from src.models.openhours import OpenHours
from src.models.equipment import Equipment
from src.models.capacity import Capacity


class FacilityType(enum.Enum):
Expand Down
3 changes: 1 addition & 2 deletions src/models/giveaway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sqlalchemy import Column, Integer, Float, ForeignKey, String
from sqlalchemy import Column, Integer, ForeignKey, String
from sqlalchemy.orm import relationship
from src.database import Base
from src.models.user import User


class Giveaway(Base):
Expand Down
3 changes: 1 addition & 2 deletions src/models/gym.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from sqlalchemy import Column, Float, String, Integer
from sqlalchemy.orm import relationship
from src.database import Base
from src.models.openhours import OpenHours
from src.models.classes import ClassInstance, Class


class Gym(Base):
Expand Down Expand Up @@ -31,6 +29,7 @@ class Gym(Base):
facilities = relationship("Facility")
hours = relationship("OpenHours")
classes = relationship("ClassInstance", back_populates="gym")
reports = relationship("Report", back_populates="gym")
image_url = Column(String, nullable=True)
latitude = Column(Float, nullable=False)
longitude = Column(Float, nullable=False)
Expand Down
2 changes: 1 addition & 1 deletion src/models/openhours.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import enum
from sqlalchemy import Boolean, Column, Enum, Integer, Float, ForeignKey
from sqlalchemy import Boolean, Column, Enum, Integer, ForeignKey
from src.database import Base


Expand Down
Loading

0 comments on commit c128cb6

Please sign in to comment.