def get(self): parser = reqparse.RequestParser() parser.add_argument('brand') args = parser.parse_args() brand = args.get('brand') if not brand: return 'Specify a brand', 400 session = Session() models = session.query(car_table.c.model).distinct(car_table.c.model).filter(car_table.c.brand == brand).all() session.close() return [m[0] for m in models]
def get(self): parser = reqparse.RequestParser() parser.add_argument('brand') parser.add_argument('model') args = parser.parse_args() brand = args.get('brand') model = args.get('model') if not brand or not model: return 'Specify a brand and a model', 400 session = Session() data = session.query(car_table).filter_by(brand=brand).filter_by(model=model).all() session.close() if data: df = pd.DataFrame(data) stats_df = df[['price', 'year']].groupby('year').price.agg(['mean', 'min', 'max']) return stats_df.to_dict('index') return {}
def get(self): parser = reqparse.RequestParser() parser.add_argument('brand') parser.add_argument('model') args = parser.parse_args() brand = args.get('brand') model = args.get('model') session = Session() query = session.query(car_table).filter_by(brand=brand) session.close() if model: query = query.filter_by(model=model) data = query.all() df = pd.DataFrame(data) df['transmission'] = df['transmission'].apply(lambda x: x.name) df['fuel'] = df['fuel'].apply(lambda x: x.name) df['origin'] = df['origin'].apply(lambda x: x.name) df = df.drop(['scrapping_date'], axis=1) return df.to_dict('records')
def find_by_time(cls, time: dtime) -> "AttendanceModel": return Session.query(cls).filter_by(time=time).first()
def find_by_student(cls, student: StudentModel) -> "AttendanceModel": return Session.query(cls).filter_by(student=student).first()
def find_by_date(cls, date: dt, student: StudentModel) -> "AttendanceModel": return Session.query(cls).filter_by(date=date, student=student).first()
def find_all(cls) -> List["StudentModel"]: return Session.query(cls).all()
def find_by_id(cls, _id: int) -> "StudentModel": return Session.query(cls).filter_by(id=_id).first()
def find_by_name(cls, name: str) -> "StudentModel": return Session.query(cls).filter_by(name=name).first()
def find_by_username(cls, username: str) -> "TeacherModel": return Session.query(cls).filter_by(username=username).first()
def find_all(cls) -> List["VideoFeedModel"]: return Session.query(cls).all()
def find_by_url(cls, url: str) -> "VideoFeedModel": return Session.query(cls).filter_by(url=url).first()
def find_by_id(cls, _id: str) -> "VideoFeedModel": return Session.query(cls).filter_by(id=_id).first()
def find_all(cls) -> List["AttendanceModel"]: # for x in Session.query(cls, StudentModel).filter( # StudentAttendances.attendance_id == cls.id, # StudentAttendances.student_id == StudentModel.id).order_by(cls.date).all(): # print(f"Date: {x.AttendanceModel.date} Name: {x.StudentModel.name} Time: {x.AttendanceModel.time}") return Session.query(cls).all()
def get_users( db: Session = Depends(get_db), skip: int = 0, limit: int = 100 ) -> models.UserModel: return db.query(models.UserModel).offset(skip).limit(limit).all()
def get(self): session = Session() brands = session.query(car_table.c.brand).distinct(car_table.c.brand).all() session.close() return [b[0] for b in brands]