def snadashboard(request): context = RequestContext(request) course_code = request.GET.get('course_code') if UnitOfferingMembership.is_admin(request.user, course_code): platform = request.GET.get('platform') title = "SNA Dashboard: %s (Platform: %s)" % (course_code, platform) show_dashboardnav = True posts_timeline = get_timeseries('created', platform, course_code) shares_timeline = get_timeseries('shared', platform, course_code) likes_timeline = get_timeseries('liked', platform, course_code) comments_timeline = get_timeseries('commented', platform, course_code) sna_json = sna_buildjson(platform, course_code, relationshipstoinclude="'mentioned','liked','shared','commented'") #sna_neighbours = getNeighbours(sna_json) centrality = getCentrality(sna_json) context_dict = { 'show_dashboardnav':show_dashboardnav,'course_code':course_code, 'platform':platform, 'title': title, 'sna_json': sna_json, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline, 'centrality': centrality } return render_to_response('dashboard/snadashboard.html', context_dict, context) else: raise PermissionDenied
def snadashboard(request): context = RequestContext(request) unit_id = request.GET.get('unit') unit = UnitOffering.objects.get(id=unit_id) if UnitOfferingMembership.is_admin(request.user, unit): platform = request.GET.get('platform') title = "SNA Dashboard: {} {} (Platform: {})".format( unit.code, unit.name, platform) # Activity Time line data (verbs and platform) timeline_data = get_verb_timeline_data(unit, platform, None) sna_json = sna_buildjson(platform, unit, relationshipstoinclude = "'%s', '%s', '%s', '%s'" % (xapi_settings.VERB_MENTIONED, xapi_settings.VERB_LIKED, \ xapi_settings.VERB_SHARED, xapi_settings.VERB_COMMENTED)) #sna_neighbours = getNeighbours(sna_json) centrality = get_centrality(sna_json) context_dict = { 'show_dashboardnav': True, 'unit': unit, 'platform': platform, 'title': title, 'sna_json': sna_json, 'centrality': centrality, 'course_id': unit.id, 'posts_timeline': timeline_data['posts'], 'shares_timeline': timeline_data['shares'], 'likes_timeline': timeline_data['likes'], 'comments_timeline': timeline_data['comments'] } return render_to_response('dashboard/snadashboard.html', context_dict, context) # platform = request.GET.get('platform') # title = "SNA Dashboard: {} {} (Platform: {})".format(unit.code, unit.name, platform) # show_dashboardnav = True # posts_timeline = get_timeseries('created', platform, unit) # shares_timeline = get_timeseries('shared', platform, unit) # likes_timeline = get_timeseries('liked', platform, unit) # comments_timeline = get_timeseries('commented', platform, unit) # sna_json = sna_buildjson(platform, unit, relationshipstoinclude="'mentioned','liked','shared','commented'") # #sna_neighbours = getNeighbours(sna_json) # centrality = get_centrality(sna_json) # context_dict = {'show_dashboardnav': show_dashboardnav, 'unit': unit, 'platform': platform, 'title': title, # 'sna_json': sna_json, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, # 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline, # 'centrality': centrality} # return render_to_response('dashboard/snadashboard.html', context_dict, context) else: raise PermissionDenied
def offering_members(request, course_code): if UnitOfferingMembership.is_admin(request.user, course_code): unit = UnitOffering.objects.get(code=course_code) members = unit.users.all() return render(request, "clatoolkit/offering_members.html", {"unit": unit, "members": members}) else: raise PermissionDenied()
def cadashboard(request): context = RequestContext(request) platform = None no_topics = 3 if request.method == 'POST': unit_id = request.POST['unit'] platform = request.POST['platform'] no_topics = int(request.POST['no_topics']) else: unit_id = request.GET.get('unit') platform = request.GET.get('platform') unit = UnitOffering.objects.get(id=unit_id) if UnitOfferingMembership.is_admin(request.user, unit): title = "Content Analysis Dashboard: %s (Platform: %s)" % (unit.code, platform) # timeline_data = get_verb_timeline_data(unit, None) timeline_data = get_verb_timeline_data(unit, platform, None) # Word Cloud tags = get_wordcloud(platform, unit) # Sentiments pie chart sentiments = getClassifiedCounts(platform, unit, classifier="VaderSentiment") # Community of Inquiry coi = getClassifiedCounts(platform, unit, classifier="NaiveBayes_t1.model") topic_model_output, sentimenttopic_piebubblesdataset = nmf( platform, no_topics, unit, start_date=None, end_date=None) context_dict = { 'show_dashboardnav': True, 'unit': unit, 'platform': platform, 'title': title, 'posts_timeline': timeline_data['posts'], 'shares_timeline': timeline_data['shares'], 'likes_timeline': timeline_data['likes'], 'comments_timeline': timeline_data['comments'], 'sentiments': sentiments, 'coi': coi, 'tags': tags, 'no_topics': no_topics, 'topic_model_output': topic_model_output, 'sentimenttopic_piebubblesdataset': sentimenttopic_piebubblesdataset } return render_to_response('dashboard/cadashboard.html', context_dict, context) else: raise PermissionDenied
def update_offering(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): if request.method == "POST": form = CreateOfferingForm(request.POST, instance=unit) if form.is_valid(): # Get provider ID and set it to unit post_data = request.POST.copy() provider = post_data.pop("provider")[0] app = ClientApp.objects.get(provider=provider) unit.lrs_provider = app # Start & end date start_date = post_data.pop("start_date")[0] end_date = post_data.pop("end_date")[0] from datetime import datetime as dt client_format = '%d / %m / %Y' database_format = '%Y-%m-%d' # Create a Date object start_date = dt.strptime(start_date, client_format) end_date = dt.strptime(end_date, client_format) # Get formatted date string start_date = start_date.strftime(database_format) end_date = end_date.strftime(database_format) # Create a Date object whose format suits database column format start_date = dt.strptime(start_date, database_format) end_date = dt.strptime(end_date, database_format) unit.start_date = start_date unit.end_date = end_date unit = form.save() return render(request, 'clatoolkit/createoffering_success.html', { 'verb': 'updated', 'unit': unit }) else: # Get LRS provider and set it form = CreateOfferingForm( instance=unit, initial={'provider': unit.lrs_provider.provider}) return render(request, "clatoolkit/createoffering.html", { 'verb': 'Update', 'form': form }) else: raise PermissionDenied()
def offering_members(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): members = unit.users.all() return render(request, "clatoolkit/offering_members.html", {"unit": unit, "members": members}) else: raise PermissionDenied()
def offering_members(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): members = unit.users.all() return render(request, "clatoolkit/offering_members.html", { "unit": unit, "members": members }) else: raise PermissionDenied()
def update_offering(request, course_code): if UnitOfferingMembership.is_admin(request.user, course_code): unit = UnitOffering.objects.get(code=course_code) if request.method == "POST": form = CreateOfferingForm(request.POST, instance=unit) if form.is_valid(): unit = form.save() return render(request, 'clatoolkit/createoffering_success.html', {'verb': 'updated', 'unit': unit}) else: form = CreateOfferingForm(instance=unit) return render(request, "clatoolkit/createoffering.html", {'verb': 'Update', 'form': form}) else: raise PermissionDenied()
def update_offering(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): if request.method == "POST": form = CreateOfferingForm(request.POST, instance=unit) if form.is_valid(): # Get provider ID and set it to unit post_data = request.POST.copy() provider = post_data.pop("provider")[0] app = ClientApp.objects.get(provider = provider) unit.lrs_provider = app # Start & end date start_date = post_data.pop("start_date")[0] end_date = post_data.pop("end_date")[0] from datetime import datetime as dt client_format = '%d / %m / %Y' database_format = '%Y-%m-%d' # Create a Date object start_date = dt.strptime(start_date, client_format) end_date = dt.strptime(end_date, client_format) # Get formatted date string start_date = start_date.strftime(database_format) end_date = end_date.strftime(database_format) # Create a Date object whose format suits database column format start_date = dt.strptime(start_date, database_format) end_date = dt.strptime(end_date, database_format) unit.start_date = start_date unit.end_date = end_date unit = form.save() return render(request, 'clatoolkit/createoffering_success.html', {'verb': 'updated', 'unit': unit}) else: # Get LRS provider and set it form = CreateOfferingForm(instance=unit, initial = {'provider': unit.lrs_provider.provider}) return render(request, "clatoolkit/createoffering.html", {'verb': 'Update', 'form': form}) else: raise PermissionDenied()
def cadashboard(request): context = RequestContext(request) course_code = None platform = None no_topics = 3 if request.method == 'POST': course_code = request.POST['course_code'] platform = request.POST['platform'] no_topics = int(request.POST['no_topics']) else: course_code = request.GET.get('course_code') platform = request.GET.get('platform') if UnitOfferingMembership.is_admin(request.user, course_code): title = "Content Analysis Dashboard: %s (Platform: %s)" % (course_code, platform) show_dashboardnav = True posts_timeline = get_timeseries('created', platform, course_code) shares_timeline = get_timeseries('shared', platform, course_code) likes_timeline = get_timeseries('liked', platform, course_code) comments_timeline = get_timeseries('commented', platform, course_code) tags = get_wordcloud(platform, course_code) sentiments = getClassifiedCounts(platform, course_code, classifier="VaderSentiment") coi = getClassifiedCounts(platform, course_code, classifier="NaiveBayes_t1.model") topic_model_output, sentimenttopic_piebubblesdataset = nmf(platform, no_topics, course_code, start_date=None, end_date=None) context_dict = {'show_dashboardnav':show_dashboardnav, 'course_code':course_code, 'platform':platform, 'title': title, 'course_code':course_code, 'platform':platform, 'sentiments': sentiments, 'coi': coi, 'tags': tags, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline, 'no_topics': no_topics, 'topic_model_output': topic_model_output, 'sentimenttopic_piebubblesdataset':sentimenttopic_piebubblesdataset } return render_to_response('dashboard/cadashboard.html', context_dict, context) else: raise PermissionDenied
def dashboard(request): context = RequestContext(request) course_code = request.GET.get('course_code') # If the user is an admin for the course if UnitOfferingMembership.is_admin(request.user, course_code): platform = request.GET.get('platform') title = "Activity Dashboard: %s (Platform: %s)" % (course_code, platform) show_dashboardnav = True profiling = "" profiling = profiling + "| Verb Timelines %s" % (str(datetime.datetime.now())) posts_timeline = get_timeseries('created', platform, course_code) shares_timeline = get_timeseries('shared', platform, course_code) likes_timeline = get_timeseries('liked', platform, course_code) comments_timeline = get_timeseries('commented', platform, course_code) show_allplatforms_widgets = False twitter_timeline = "" facebook_timeline = "" forum_timeline = "" youtube_timeline = "" diigo_timeline = "" blog_timeline = "" github_timeline = "" trello_timeline = "" profiling = profiling + "| Platform Timelines %s" % (str(datetime.datetime.now())) platformclause = "" #TODO: This will need to change upon implementation of teaching periods if platform != "all": platformclause = " AND clatoolkit_learningrecord.xapi->'context'->>'platform'='%s'" % (platform) else: twitter_timeline = get_timeseries_byplatform("Twitter", course_code) facebook_timeline = get_timeseries_byplatform("Facebook", course_code) forum_timeline = get_timeseries_byplatform("Forum", course_code) youtube_timeline = get_timeseries_byplatform("YouTube", course_code) diigo_timeline = get_timeseries_byplatform("Diigo", course_code) blog_timeline = get_timeseries_byplatform("Blog", course_code) github_timeline = get_timeseries_byplatform("GitHub", course_code) trello_timeline = get_timeseries_byplatform("trello", course_code) show_allplatforms_widgets = True profiling = profiling + "| Pies %s" % (str(datetime.datetime.now())) cursor = connection.cursor() cursor.execute("""SELECT clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US' as verb, count(clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US') as counts FROM clatoolkit_learningrecord WHERE clatoolkit_learningrecord.course_code='%s' %s GROUP BY clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US'; """ % (course_code, platformclause)) result = cursor.fetchall() activity_pie_series = "" for row in result: activity_pie_series = activity_pie_series + "['%s', %s]," % (row[0],row[1]) cursor = connection.cursor() cursor.execute("""SELECT clatoolkit_learningrecord.xapi->'context'->>'platform' as platform, count(clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US') as counts FROM clatoolkit_learningrecord WHERE clatoolkit_learningrecord.course_code='%s' GROUP BY clatoolkit_learningrecord.xapi->'context'->>'platform'; """ % (course_code)) result = cursor.fetchall() platformactivity_pie_series = "" for row in result: platformactivity_pie_series = platformactivity_pie_series + "['%s', %s]," % (row[0],row[1]) #active members table profiling = profiling + "| Active Members %s" % (str(datetime.datetime.now())) activememberstable = get_active_members_table(platform, course_code) #get_cached_active_users(platform, course_code) profiling = profiling + "| Top Content %s" % (str(datetime.datetime.now())) topcontenttable = get_cached_top_content(platform, course_code) #get_top_content_table(platform, course_code) profiling = profiling + "| End Top Content %s" % (str(datetime.datetime.now())) context_dict = {'profiling': profiling, 'show_dashboardnav':show_dashboardnav, 'course_code':course_code, 'platform':platform, 'twitter_timeline': twitter_timeline, 'facebook_timeline': facebook_timeline, 'forum_timeline': forum_timeline, 'youtube_timeline':youtube_timeline, 'diigo_timeline':diigo_timeline, 'blog_timeline':blog_timeline, 'github_timeline': github_timeline, 'trello_timeline': trello_timeline, 'show_allplatforms_widgets': show_allplatforms_widgets, 'platformactivity_pie_series': platformactivity_pie_series, 'title': title, 'activememberstable': activememberstable, 'topcontenttable': topcontenttable, 'activity_pie_series': activity_pie_series, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline } return render_to_response('dashboard/dashboard.html', context_dict, context) else: raise PermissionDenied
def dashboard(request): context = RequestContext(request) unit_id = request.GET.get('unit') unit = UnitOffering.objects.get(id=unit_id) # If the user is an admin for the course if UnitOfferingMembership.is_admin(request.user, unit): # user = request.user platform = request.GET.get('platform') title = "Activity Dashboard: %s (Platform: %s)" % (unit.code, platform) show_dashboardnav = True # A flag for showing a platform activity time series and pie chart show_allplatforms_widgets = True if platform != "all": show_allplatforms_widgets = False activity_pie_series = get_verb_pie_data(unit, platform=platform) platformactivity_pie_series = get_platform_pie_data(unit) # Activity Time line data (verbs and platform) timeline_data = get_verb_timeline_data(unit, platform, None) platform_timeline_data = get_platform_timeline_data( unit, platform, None) # p = platform if platform != "all" else None activememberstable = get_active_members_table(unit, platform) topcontenttable = get_cached_top_content(platform, unit) context_dict = { 'title': title, 'course_code': unit.code, 'platform': platform, 'show_dashboardnav': show_dashboardnav, 'activememberstable': activememberstable, 'unit': unit, 'topcontenttable': topcontenttable, 'show_allplatforms_widgets': show_allplatforms_widgets, 'posts_timeline': timeline_data['posts'], 'shares_timeline': timeline_data['shares'], 'likes_timeline': timeline_data['likes'], 'comments_timeline': timeline_data['comments'], 'twitter_timeline': platform_timeline_data[xapi_settings.PLATFORM_TWITTER], 'facebook_timeline': platform_timeline_data[xapi_settings.PLATFORM_FACEBOOK], 'youtube_timeline': platform_timeline_data[xapi_settings.PLATFORM_YOUTUBE], 'blog_timeline': platform_timeline_data[xapi_settings.PLATFORM_BLOG], 'trello_timeline': platform_timeline_data[xapi_settings.PLATFORM_TRELLO], 'github_timeline': platform_timeline_data[xapi_settings.PLATFORM_GITHUB], 'forum_timeline': [], 'diigo_timeline': [], 'activity_pie_series': activity_pie_series, 'platformactivity_pie_series': platformactivity_pie_series } return render_to_response('dashboard/dashboard.html', context_dict, context) else: raise PermissionDenied