本文整理汇总了Python中api_db_utils.APIDB.get_course_sessions方法的典型用法代码示例。如果您正苦于以下问题:Python APIDB.get_course_sessions方法的具体用法?Python APIDB.get_course_sessions怎么用?Python APIDB.get_course_sessions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_db_utils.APIDB
的用法示例。
在下文中一共展示了APIDB.get_course_sessions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coach_course_subscription_details
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def coach_course_subscription_details(req, uskey_subscription):
"""
``GET`` @ |ca| + ``/subscriptions/<uskey_subscription>``
GET a subscription. |uroleOT|
"""
subscription = req.model
user = subscription.member.get()
res = sanitize_json(subscription.to_dict(), ['id', 'start_date', 'profile_level', 'observations', 'disabled_exercises','max_level','profile'])
res['user'] = sanitize_json(user, ['id', 'name', 'picture'])
sessions = APIDB.get_course_sessions(subscription.course.get())
res_list = []
added_activities = []
for session in sessions:
activities = APIDB.get_session_exercises(session)
for activity in activities:
if activity.id not in added_activities:
added_activities.append(activity.id)
j_activity = activity.to_dict()
level_count = len(activity.levels)
j_activity['level_count'] = level_count
# this is already a json, see docs in the model
res_list.append(j_activity)
res['activities'] = sanitize_list(res_list,allowed=['id', 'name', 'level_count'])
return res
示例2: coach_course_session_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def coach_course_session_list(req, uskey_course):
"""
``GET`` @ |ca| + ``/course/<uskey_course>/sessions``
List of the sessions of a course. |uroleOT|
"""
course = req.model
j_req = json_from_paginated_request(req, (('status', None), ('type', None),
('from', None),
('to', None)))
# date_to_js_timestamp(datetime.datetime.now())))
page = int(j_req['page'])
size = int(j_req['size'])
status = j_req['status']
try:
date_from = datetime.datetime.fromtimestamp(long(j_req['from']) / 1000)
except Exception as e:
date_from = None
try:
date_to = datetime.datetime.fromtimestamp(long(j_req['to']) / 1000)
except Exception as e:
date_to = None
# raise BadParameters("Problems with the data format %s" % e.message)
session_type = j_req['type']
sessions, total = APIDB.get_course_sessions(course, date_from=date_from, date_to=date_to, session_type=session_type,
status=status,
paginated=True, page=page, size=size)
res_list = []
for session in sessions:
res_obj = session.to_dict()
res_obj['status'] = session.status
# res_obj['participated'] = APIDB.user_participated_in_session(req.user, session)
session_participations = APIDB.get_session_participations(session, count_only=True)
course_subscribers = APIDB.get_course_subscribers(course, count_only=True)
res_obj['participation_count'] = session_participations
if course_subscribers:
res_obj['participation_percent'] = 100 * (float(session_participations) / float(course_subscribers))
else:
res_obj['participation_percent'] = 0
# res_obj['actnoivity_count'] = session.activity_count
# TODO: check the 'url' here
allowed = ['id', 'name', 'status', 'participation_count',
'session_type', 'participation_percent', 'max_level', 'profile']
course_type = session.course.get().course_type
if course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course_type == "PROGRAM":
allowed += ["week_no", "day_no"]
res_list.append(sanitize_json(res_obj, allowed=allowed))
return dict(total=total, results=res_list)
示例3: trainee_course_performances
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def trainee_course_performances(req, uskey_course):
"""
``GET`` @ |ta| + ``/course/<uskey_course>/performances``
Gets the score of the course. The completenss of the course
"""
course = req.model
sessions = APIDB.get_course_sessions(course)
tot = len(sessions)
if not tot:
return dict(score=0.0)
sum = 0.0
for session in sessions:
participation = APIDB.get_participation(req.user, session)
if participation:
sum += float(participation.max_completeness)
return dict(score=sum / tot)
示例4: trainee_course_session_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def trainee_course_session_list(req, uskey_course):
"""
``GET`` @ |ta| + ``/courses/<uskey_course>/sessions``
List of the session of a course. |uroleM|
"""
# TODO: test
course = req.model
j_req = json_from_paginated_request(req, (('status', 'UPCOMING'), ('type', None),
('from', None),
('to', None)))
page = int(j_req['page'])
size = int(j_req['size'])
try:
date_from = datetime.datetime.fromtimestamp(long(j_req['from']) / 1000)
except Exception as e:
date_from = None
try:
date_to = datetime.datetime.fromtimestamp(long(j_req['to']) / 1000)
except Exception as e:
date_to = None
session_type = j_req['type']
sessions, total = APIDB.get_course_sessions(course, date_from=date_from, date_to=date_to, session_type=session_type,
paginated=True, page=page, size=size)
res_list = []
for session in sessions:
res_obj = session.to_dict()
res_obj['status'] = session.status
res_obj['participated'] = APIDB.user_participated_in_session(req.user, session)
res_obj['participation_count'] = APIDB.user_participation_details(req.user, session, count_only=True)
# res_obj['actnoivity_count'] = session.activity_count
res_obj['max_score'] = APIDB.session_completeness(req.user, session)
allowed = ['id', 'name', 'status', 'participation_count',
'session_type']
course_type = session.course.get().course_type
if session.session_type == "SINGLE":
allowed += ['url']
if course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course_type == "PROGRAM":
allowed += ["week_no", "day_no"]
res_list.append(sanitize_json(res_obj, allowed=allowed))
return dict(total=total, results=res_list)
示例5: trainee_course_detail
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def trainee_course_detail(req, uskey_course):
"""
``GET`` @ |ta| + ``/courses/<uskey_course>``
Detail of a course. |uroleM|
"""
course = req.model
j_course = course.to_dict()
j_course["trainers"] = sanitize_list(APIDB.get_course_trainers(course), allowed=["id", "name", "picture"])
j_course["subscriber_count"] = APIDB.get_course_subscribers(course, count_only=True)
j_course["session_count"] = APIDB.get_course_sessions(course, count_only=True)
allowed = ["id", "name", "description", "trainers", "subscriber_count", "session_count", "course_type"]
if course.course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course.course_type == "PROGRAM":
allowed += ["week_no", "day_no"]
return sanitize_json(j_course, allowed=allowed)
示例6: coach_course_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def coach_course_list(req, uskey_club):
"""
``GET`` @ |ca| + ``/clubs/<uskey_club>/courses``
List of the courses of a club. |uroleOT|
"""
club = req.model
j_req = json_from_paginated_request(req, (('courseType', None), ('activeOnly', None),))
page = int(j_req['page'])
size = int(j_req['size'])
course_type = j_req['courseType']
active_only = j_req['activeOnly'] == "true"
courses, total = APIDB.get_club_courses(club, course_type=course_type, active_only=active_only,
paginated=True, page=page, size=size)
res_courses = []
for course in courses:
j_course = course.to_dict()
j_course["trainers"] = sanitize_list(APIDB.get_course_trainers(course), allowed=["id", "name", "picture"])
j_course["subscriber_count"] = APIDB.get_course_subscribers(course, count_only=True)
sessions_total = APIDB.get_course_sessions(course)
j_course['session_count'] = len(sessions_total)
sessions_finished = [session for session in sessions_total if session.status == "FINISHED"]
# logger.debug("%s %s %s", len(sessions_total), len(sessions_finished),long(sessions_finished)/long(sessions_total) * 100 )
if len(sessions_total) > 0:
j_course['completeness'] = long(len(sessions_finished)) / long(len(sessions_total)) * 100
else:
j_course['completeness'] = 0
allowed = ["id", "name", "description", "trainers", "subscriber_count", "session_count", "course_type",
"completeness", "profile", "max_level"]
if course.course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course.course_type == "PROGRAM":
allowed += ["duration"]
res_course = sanitize_json(j_course, allowed=allowed)
res_courses.append(res_course)
ret = {}
ret['results'] = res_courses
ret['total'] = total
return ret
示例7: trainee_course_list
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def trainee_course_list(req, uskey_club):
"""
``GET`` @ |ta| + ``/clubs/<uskey_club>/courses``
List of the courses of a club
"""
club = req.model
j_req = json_from_paginated_request(req, (('course_type', None), 'activeOnly', ('subscribed', False)))
page = int(j_req['page'])
size = int(j_req['size'])
course_type = j_req['course_type']
active_only = j_req['activeOnly'] == "True"
subscribed = j_req['subscribed'] == "True"
if subscribed:
courses, total = APIDB.get_club_courses_im_subscribed_to(club, course_type=course_type, active_only=active_only,
paginated=True, page=page, size=size)
else:
courses, total = APIDB.get_club_courses(club, course_type=course_type, active_only=active_only,
paginated=True, page=page, size=size)
res_courses = []
for course in courses:
j_course = course.to_dict()
j_course["trainers"] = sanitize_list(APIDB.get_course_trainers(course), allowed=["id", "name", "picture"])
j_course["subscriber_count"] = APIDB.get_course_subscribers(course, count_only=True)
j_course["session_count"] = APIDB.get_course_sessions(course, count_only=True)
allowed = ["id", "name", "description", "trainers", "subscriber_count", "session_count", "course_type"]
if course.course_type == "SCHEDULED":
allowed += ["start_date", "end_date"]
elif course.course_type == "PROGRAM":
allowed += ["week_no", "day_no"]
res_course = sanitize_json(j_course, allowed=allowed)
res_courses.append(res_course)
ret = {}
ret['results'] = res_courses
ret['total'] = total
return ret
示例8: coach_course_detail
# 需要导入模块: from api_db_utils import APIDB [as 别名]
# 或者: from api_db_utils.APIDB import get_course_sessions [as 别名]
def coach_course_detail(req, uskey_course):
"""
``GET`` @ |ca| + ``/courses/<uskey_course>``
Detail of a course. |uroleOT|
"""
course = req.model
j_course = course.to_dict()
j_course['trainers'] = sanitize_list(APIDB.get_course_trainers(course), allowed=['id', 'name', 'picture'])
j_course['subscriber_count'] = APIDB.get_course_subscribers(course, count_only=True)
# the filter on status does not work, this is an "expensive" workaround
sessions_total = APIDB.get_course_sessions(course)
j_course['session_count'] = len(sessions_total)
sessions_finished = [session for session in sessions_total if session.status == "FINISHED"]
# logger.debug("%s %s %s", len(sessions_total), len(sessions_finished),long(sessions_finished)/long(sessions_total) * 100 )
if len(sessions_total) > 0:
j_course['completeness'] = long(len(sessions_finished)) / long(len(sessions_total)) * 100
else:
j_course['completeness'] = 0
return sanitize_json(j_course, ['id', 'name', 'description', 'start_date', 'end_date', 'duration',
'trainers', 'course_type', 'subscriber_count', 'session_count', 'completeness',
"profile", 'max_level'],
except_on_missing=False)