def group_compare(request): cluster = get_object_or_404(Cluster, pk=3) #load csv into pandas.DataFrame dic = rc.filter_by_cluster(utils.get_whole_survey(), cluster) df = dic['df'] size_str = "%d / %d" % (len(df.index), dic['orig_size']) clusters_dict = clustering.get_subclusters_length(cluster, dic['df']) #load questions textfile into list file2_ = open( os.path.join(settings.BASE_DIR, 'clusters/RSQquestionchoices.txt')) dic_source = rt.read(file2_) about = dic_source['about'] questions_txt = dic_source['questions'] file2_.close() #get cluster questions as strings questions_strs = get_questions_as_str(questions_txt) #get charts charts = get_charts(df, questions_txt, cluster, 'a') context = { 'cluster': cluster, 'charts': charts, #'compare_chart': compare_chart, 'df_size': size_str, #no of rows in df 'questions_strs': questions_strs, 'about': about, 'subcluster_values': list(clusters_dict.values()), 'num_of_clusters': cluster.num_of_clusters, 'compare': False, } return render(request, 'clusters/group_compare.html', context)
def subclusters_list(request, cluster_id): cluster = get_object_or_404(Cluster, pk=cluster_id) dic = rc.filter_by_cluster(dataframeAll, cluster) clusters_dict = clustering.get_subclusters(cluster, dic['df']) context = { 'cluster_id': cluster_id, 'subcluster_values': list(clusters_dict.values()), } return render(request, 'clusters/subcluster_list.html', context)
def json3(request, cluster_id, question_id): cluster = get_object_or_404(Cluster, pk=cluster_id) #load csv into pandas.DataFrame dic = rc.filter_by_cluster(utils.get_whole_survey(), cluster) df = dic['df'] output = rc2.get_data_for_map3(df, question_id) return JsonResponse(output, safe=False)
def increase_num_of_clusters(request, cluster_id): cluster = get_object_or_404(Cluster, pk=cluster_id) cluster.num_of_clusters += 1 cluster.save() dic = rc.filter_by_cluster(dataframeAll, cluster) clustering.get_subclusters(cluster, dic['df'], refresh=True) print "increased_num_of_clusters" return redirect('/clusters/' + cluster_id + '/stats')
def json2(request, cluster_id, subcluster_id, question_id, choice_id): """ creates json for map change """ cluster = get_object_or_404(Cluster, pk=cluster_id) #load csv into pandas.DataFrame dic = rc.filter_by_cluster(utils.get_whole_survey(), cluster) df = dic['df'] if subcluster_id != 'a': #if is subcluster, then filter subcluster tempdf = clustering.get_subcluster_list(cluster, df) df = clustering.filter_by_subcluster(tempdf, subcluster_id) output = rc2.get_data_for_map2(df, question_id, choice_id) return JsonResponse(output, safe=False)
def json1(request, cluster_id, subcluster_id): """ used for map """ cluster = get_object_or_404(Cluster, pk=cluster_id) #load csv into pandas.DataFrame dic = rc.filter_by_cluster(utils.get_whole_survey(), cluster) df = dic['df'] if subcluster_id != 'a': df = clustering.get_subclusters(cluster, df)[int(subcluster_id)] #load questions textfile into list file2_ = open( os.path.join(settings.BASE_DIR, 'clusters/RSQquestionchoices.txt')) dic_source = rt.read(file2_) about = dic_source['about'] questions_txt = dic_source['questions'] file2_.close() output = rc2.get_data_for_map(df, questions_txt['WARD']) return JsonResponse(output, safe=False)
def detail(request, cluster_id): cluster = get_object_or_404(Cluster, pk=cluster_id) #load csv into pandas.DataFrame dic = rc.filter_by_cluster(utils.get_whole_survey(), cluster) df = dic['df'] group_size = len(df.index) survey_size = dic['orig_size'] if group_size == 0: return render(request, 'clusters/emptygroup.html', {'cluster': cluster}) clusters_dict = clustering.get_subclusters_length(cluster, dic['df']) #load questions textfile into list file2_ = open( os.path.join(settings.BASE_DIR, 'clusters/RSQquestionchoices.txt')) dic_source = rt.read(file2_) file2_.close() about = dic_source['about'] questions_txt = dic_source['questions'] #get cluster questions as strings questions_strs = get_questions_as_str(questions_txt) #get charts charts = get_charts(df, questions_txt, cluster, 'a') context = { 'cluster': cluster, 'subcluster_id': 'a', 'charts': charts, 'group_size': group_size, #no of rows in df 'survey_size': survey_size, 'questions_strs': questions_strs, 'about': about, 'subcluster_values': list(clusters_dict.values()), 'num_of_clusters': cluster.num_of_clusters, 'compare': False, } return render(request, 'clusters/detail.html', context)
def subcluster_detail(request, cluster_id, subcluster_id): cluster = get_object_or_404(Cluster, pk=cluster_id) #load csv into pandas.DataFrame dic = rc.filter_by_cluster(utils.get_whole_survey(), cluster) df = dic['df'] df = clustering.get_subclusters(cluster, df)[0] #dicitonary size_str = "%d / %d" % (len(df.index), dic['orig_size']) clusters_dict = clustering.get_subclusters_length(cluster, dic['df']) #load questions textfile into list file2_ = open( os.path.join(settings.BASE_DIR, 'clusters/RSQquestionchoices.txt')) dic_source = rt.read(file2_) about = dic_source['about'] questions_txt = dic_source['questions'] file2_.close() #get cluster questions as strings questions_strs = get_questions_as_str(questions_txt) #get charts charts = get_charts(df, questions_txt, cluster, subcluster_id) context = { 'cluster': cluster, 'subcluster_id': subcluster_id, 'charts': charts, 'group_size': len(df.index), #no of rows in df 'survey_size': dic['orig_size'], 'questions_strs': questions_strs, 'about': about, 'subcluster_values': list(clusters_dict.values()), 'num_of_clusters': cluster.num_of_clusters, 'issubcluster': True, } return render(request, 'clusters/detail.html', context)