Пример #1
0
 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]
Пример #2
0
 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 {}
Пример #3
0
 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')
Пример #4
0
 def find_by_time(cls, time: dtime) -> "AttendanceModel":
     return Session.query(cls).filter_by(time=time).first()
Пример #5
0
 def find_by_student(cls, student: StudentModel) -> "AttendanceModel":
     return Session.query(cls).filter_by(student=student).first()
Пример #6
0
 def find_by_date(cls, date: dt,
                  student: StudentModel) -> "AttendanceModel":
     return Session.query(cls).filter_by(date=date, student=student).first()
Пример #7
0
 def find_all(cls) -> List["StudentModel"]:
     return Session.query(cls).all()
Пример #8
0
 def find_by_id(cls, _id: int) -> "StudentModel":
     return Session.query(cls).filter_by(id=_id).first()
Пример #9
0
 def find_by_name(cls, name: str) -> "StudentModel":
     return Session.query(cls).filter_by(name=name).first()
Пример #10
0
 def find_by_username(cls, username: str) -> "TeacherModel":
     return Session.query(cls).filter_by(username=username).first()
Пример #11
0
 def find_all(cls) -> List["VideoFeedModel"]:
     return Session.query(cls).all()
Пример #12
0
 def find_by_url(cls, url: str) -> "VideoFeedModel":
     return Session.query(cls).filter_by(url=url).first()
Пример #13
0
 def find_by_id(cls, _id: str) -> "VideoFeedModel":
     return Session.query(cls).filter_by(id=_id).first()
Пример #14
0
 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()
Пример #15
0
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()
Пример #16
0
 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]