本文整理汇总了Python中analyticsclient.client.Client.courses方法的典型用法代码示例。如果您正苦于以下问题:Python Client.courses方法的具体用法?Python Client.courses怎么用?Python Client.courses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类analyticsclient.client.Client
的用法示例。
在下文中一共展示了Client.courses方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BasePresenter
# 需要导入模块: from analyticsclient.client import Client [as 别名]
# 或者: from analyticsclient.client.Client import courses [as 别名]
class BasePresenter(object):
"""
This is the base class for the pages and sets up the analytics client
for the presenters to use to access the data API.
"""
def __init__(self, course_id, timeout=settings.ANALYTICS_API_DEFAULT_TIMEOUT):
self.client = Client(base_url=settings.DATA_API_URL,
auth_token=settings.DATA_API_AUTH_TOKEN,
timeout=timeout)
self.course_id = course_id
self.course = self.client.courses(self.course_id)
def get_current_date(self):
return datetime.datetime.utcnow().strftime(Client.DATE_FORMAT)
@staticmethod
def parse_api_date(s):
""" Parse a string according to the API date format. """
return datetime.datetime.strptime(s, Client.DATE_FORMAT).date()
@staticmethod
def parse_api_datetime(s):
""" Parse a string according to the API datetime format. """
return datetime.datetime.strptime(s, Client.DATETIME_FORMAT)
@staticmethod
def strip_time(s):
return s[:-7]
@staticmethod
def sum_counts(data):
return sum(datum['count'] for datum in data)
示例2: CourseView
# 需要导入模块: from analyticsclient.client import Client [as 别名]
# 或者: from analyticsclient.client.Client import courses [as 别名]
class CourseView(LoginRequiredMixin, CourseValidMixin, CoursePermissionMixin, TemplateView):
"""
Base course view.
Adds conveniences such as course_id attribute, and handles 404s when retrieving data from the API.
"""
client = None
course = None
course_id = None
course_key = None
user = None
def dispatch(self, request, *args, **kwargs):
self.user = request.user
self.course_id = request.course_id
self.course_key = request.course_key
# some views will catch the NotFoundError to set data to a state that
# the template can rendering a loading error message for the section
try:
return super(CourseView, self).dispatch(request, *args, **kwargs)
except NotFoundError as e:
logger.error('The requested data from the Analytics Data API was not found: %s', e)
raise Http404
except ClientError as e:
logger.error('An error occurred while retrieving data from the Analytics Data API: %s', e)
raise
def get_context_data(self, **kwargs):
context = super(CourseView, self).get_context_data(**kwargs)
self.client = Client(base_url=settings.DATA_API_URL,
auth_token=settings.DATA_API_AUTH_TOKEN, timeout=5)
self.course = self.client.courses(self.course_id)
return context
示例3: BasePresenter
# 需要导入模块: from analyticsclient.client import Client [as 别名]
# 或者: from analyticsclient.client.Client import courses [as 别名]
class BasePresenter(object):
"""
This is the base class for the pages and sets up the analytics client
for the presenters to use to access the data API.
"""
def __init__(self, course_id, timeout=5):
self.client = Client(base_url=settings.DATA_API_URL,
auth_token=settings.DATA_API_AUTH_TOKEN,
timeout=timeout)
self.course_id = course_id
self.course = self.client.courses(self.course_id)
@staticmethod
def parse_api_date(s):
""" Parse a string according to the API date format. """
return datetime.datetime.strptime(s, Client.DATE_FORMAT).date()
@staticmethod
def parse_api_datetime(s):
""" Parse a string according to the API datetime format. """
return datetime.datetime.strptime(s, Client.DATETIME_FORMAT)
@staticmethod
def strip_time(s):
return s[:-7]
示例4: _update_active_students
# 需要导入模块: from analyticsclient.client import Client [as 别名]
# 或者: from analyticsclient.client.Client import courses [as 别名]
def _update_active_students(course_key, section_data):
auth_token = settings.ANALYTICS_DATA_TOKEN
base_url = settings.ANALYTICS_DATA_URL
section_data['active_student_count'] = 'N/A'
section_data['active_student_count_start'] = 'N/A'
section_data['active_student_count_end'] = 'N/A'
try:
client = Client(base_url=base_url, auth_token=auth_token)
course = client.courses(unicode(course_key))
recent_activity = course.recent_activity()
section_data['active_student_count'] = recent_activity['count']
def format_date(value):
return value.split('T')[0]
start = recent_activity['interval_start']
end = recent_activity['interval_end']
section_data['active_student_count_start'] = format_date(start)
section_data['active_student_count_end'] = format_date(end)
except (ClientError, KeyError) as e:
log.exception(e)
示例5: CourseView
# 需要导入模块: from analyticsclient.client import Client [as 别名]
# 或者: from analyticsclient.client.Client import courses [as 别名]
class CourseView(LoginRequiredMixin, CoursePermissionMixin, TemplateView):
"""
Base course view.
Adds conveniences such as course_id attribute, and handles 404s when retrieving data from the API.
"""
client = None
course = None
course_id = None
user = None
def dispatch(self, request, *args, **kwargs):
self.user = request.user
self.course_id = kwargs['course_id']
try:
return super(CourseView, self).dispatch(request, *args, **kwargs)
except NotFoundError:
raise Http404
def get_context_data(self, **kwargs):
context = super(CourseView, self).get_context_data(**kwargs)
self.client = Client(base_url=settings.DATA_API_URL,
auth_token=settings.DATA_API_AUTH_TOKEN, timeout=5)
self.course = self.client.courses(self.course_id)
return context
示例6: LearnerAnalyticsView
# 需要导入模块: from analyticsclient.client import Client [as 别名]
# 或者: from analyticsclient.client.Client import courses [as 别名]
#.........这里部分代码省略.........
course_key (CourseKey)
"""
course_usage_key = modulestore().make_course_usage_key(course_key)
all_blocks = get_blocks(
request,
course_usage_key,
user=request.user,
nav_depth=3,
requested_fields=['display_name', 'due', 'graded', 'format'],
block_types_filter=['sequential']
)
assignment_blocks = []
for (location, block) in all_blocks['blocks'].iteritems():
if block.get('graded', False):
assignment_blocks.append(block)
block['due'] = block['due'].isoformat() if block.get('due') is not None else None
block['location'] = unicode(location)
return assignment_blocks
def get_weekly_course_activity_count(self, course_key):
"""
Get the count of any course activity (total for all users) from previous 7 days.
Args:
course_key (CourseKey)
"""
cache_key = 'learner_analytics_{course_key}_weekly_activities'.format(course_key=course_key)
activities = cache.get(cache_key)
if not activities:
log.info('Weekly course activities for course {course_key} was not cached - fetching from Analytics API'
.format(course_key=course_key))
weekly_course_activities = self.analytics_client.courses(course_key).activity()
if not weekly_course_activities or 'any' not in weekly_course_activities[0]:
return 0
# weekly course activities should only have one item
activities = weekly_course_activities[0]
cache.set(cache_key, activities, LearnerAnalyticsView.seconds_to_cache_expiration())
return activities['any']
def consecutive_weeks_of_course_activity_for_user(self, username, course_key):
"""
Get the most recent count of consecutive days that a user has performed a course activity
Args:
username (str)
course_key (CourseKey)
"""
cache_key = 'learner_analytics_{username}_{course_key}_engagement_timeline'\
.format(username=username, course_key=course_key)
timeline = cache.get(cache_key)
if not timeline:
log.info('Engagement timeline for course {course_key} was not cached - fetching from Analytics API'
.format(course_key=course_key))
# TODO (LEARNER-3470): @jaebradley replace this once the Analytics client has an engagement timeline method
url = '{base_url}/engagement_timelines/{username}?course_id={course_key}'\
.format(base_url=settings.ANALYTICS_API_URL,
username=username,
course_key=urllib.quote_plus(unicode(course_key)))
headers = {'Authorization': 'Token {token}'.format(token=settings.ANALYTICS_API_KEY)}