def get_schools(request): """ This function gets all schools and classes in the database Args: None Returns: school_info(dict) = It contains schoolinfo and it's associated classes and student info """ try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) parent_level = data.get('parentLevel', -2) objSchoolDetails = SchoolDetails(user, parent_level) objSchoolData = objSchoolDetails.getPageData() response = construct_response( 0, 'Schools details', 'School details fetched successfully', objSchoolData) response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') else: response = construct_response(1111, 'wrong request', 'wrong request', '') response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: logger.error(e)
def get_trend_data(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') params = json.loads(body_unicode) # print ("Data:", params) start_timestamp = params.get('startTimestamp', '') # start = datetime.datetime.fromtimestamp(start_timestamp) end_timestamp = params.get('endTimestamp', '') # end = datetime.datetime.fromtimestamp(end_timestamp) topic_id = params.get('contentId') channel_id = params.get('channelId') level = params.get('level') item_id = params.get('itemId') item_channel_id = params.get('itemChannelId') std = params.get('std') filetr_contetusage = params.get('filetrcontetusage') objTrendDetails = TrendDetails(user, start_timestamp, end_timestamp, level, item_id, item_channel_id, std, topic_id, channel_id, filetr_contetusage) res = objTrendDetails.get_trend() response = construct_response(0, '', '', res) response_text = json.dumps(response, ensure_ascii=False) else: response = construct_response(1111, 'wrong request', 'wrong request', '') response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: logger.error(e)
def get_lesson_page_data(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) lesson_id = data.get('lessonID') startTimestamp = data.get('startTimestamp', 0) endTimestamp = data.get('endTimestamp', 0) if not lesson_id: response = construct_response(2001, '', '', {}) response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') objlesson_mastery = LessonMastery(lesson_id, startTimestamp, endTimestamp) objlesson_mastery_data = objlesson_mastery.get_lesson_mastery_data( ) response = construct_response(0, '', '', objlesson_mastery_data) response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') else: response = construct_response(1111, 'wrong request', 'wrong request', '') response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: logger.error(e)
def get_page_data_view(request): """ This function implements the request receiving and response sending for get page data """ try: user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) startTimestamp = data.get('startTimestamp', 0) endTimestamp = data.get('endTimestamp', 0) # topicID = data.get('contentId', '').strip() parentLevel = data.get('parentLevel', -1) parentID = int(data.get('parentId', '').strip()) flag = data.get('flag', -1) # channelID = data.get('channelId', '').strip() objUserSession = userSessionPageData(user, parentID, parentLevel, startTimestamp, endTimestamp, flag) objUserSessionData = objUserSession.getPageData() response_object = construct_response(0, "", "", objUserSessionData) response_text = json.dumps(response_object, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: traceback.print_exc() print(e) logger.error(e)
def get_exams(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) parent_level = data.get('parentLevel', -2) objSchoolDetails = Exam_details(user, parent_level) objSchoolData = objSchoolDetails.getPageData() response = construct_response(0, '', '', objSchoolData); response_text = json.dumps(response,ensure_ascii=False) return HttpResponse(response_text,content_type='application/json') else: response = construct_response(1111,'wrong request','wrong request','') response_text = json.dumps(response,ensure_ascii=False) return HttpResponse(response_text,content_type='application/json') except Exception as e: logger.error(e)
def get_sync_report_school(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) parent_level = data.get('parentLevel', -2) cities = getCities() response = construct_response(0, '', '', cities) response_text = json.dumps(response,ensure_ascii=False) return HttpResponse(response_text,content_type='application/json') else: response = construct_response(1111,'wrong request','wrong request','') response_text = json.dumps(response,ensure_ascii=False) return HttpResponse(response_text,content_type='application/json') except Exception as e: logger.error(e)
def get_contentusage_page_data(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) startTimestamp = data.get('startTimestamp', 0) endTimestamp = data.get('endTimestamp', 0) topicID = data.get('contentId', '') parentLevel = data.get('parentLevel', '') parentID = int(data.get('parentId', '').strip()) channelID = data.get('channelId', '') filtercriteriaflag = data.get('std', '') filetrcontetusage = data.get('filetrcontetusage', '') current_time = data.get('current', '') level = data.get('level', '') filterdict = data.get('levelDict', '') if level == 3 or level == 2: filetrcontetusage = filterdict[str(level)] objContentUsage = ContentUsageData(user, parentLevel, topicID, channelID, startTimestamp, endTimestamp, filtercriteriaflag, filetrcontetusage, current_time, level) objContentUsageData = objContentUsage.pageData() response_object = construct_response( 0, "Content usage meta", "Get the content usage meta successfully", objContentUsageData) response_text = json.dumps(response_object, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') else: response = construct_response(1111, 'wrong request', 'wrong request', '') response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: logger.error(e)
def get_sync_data(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) user_id = request.user.id print("user_id",user_id) selected_city = data.get('selected_city') # startTimestamp = data.get('startTimestamp', 0) # endTimestamp = data.get('endTimestamp', 0) # if not user_id: # print("ALLLLLL") # response = construct_response(2001, '', '', {}); # response_text = json.dumps(response,ensure_ascii=False) # return HttpResponse(response_text,content_type='application/json') temp_data = getSyncData(selected_city,user_id) # print(temp_data) data['rows'] = temp_data[0] data['columns'] = get_user_content() data['bit'] = get_bit(user_id) print(str(temp_data[1]).replace("'","").replace("[","").replace("]","")+" school servers has not been synced last from 20 days.") if len(temp_data[1]) == 0: data['alert'] = "All servers are synced successfully." else: data['alert'] = (str(temp_data[1]).replace("'","").replace("[","").replace("]","")+" school servers has not been synced last from 20 days.") response = construct_response(0, '', '', data) response_text = json.dumps(response,ensure_ascii=False) return HttpResponse(response_text,content_type='application/json') else: response = construct_response(1111,'wrong request','wrong request','') response_text = json.dumps(response,ensure_ascii=False) return HttpResponse(response_text,content_type='application/json') except Exception as e: logger.error(e)
def get_contentusage_page_meta(request): try: if request.method == 'POST': user = request.user body_unicode = request.body.decode('utf-8') data = json.loads(body_unicode) parent_level = data.get('parentLevel', -2) content_id = data.get('contentId', '') channel_id = data.get('channelId', '') previouscontent_id = data.get('previousContentID', '') previouschannel_id = data.get('previousChannelID', '') objContentUsage = ContentUsageMeta(user, parent_level, content_id, channel_id, previouscontent_id, previouschannel_id) objContentUsageData = objContentUsage.pageMeta(METRICS) response_text = json.dumps(objContentUsageData, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') else: response = construct_response(1111, 'wrong request', 'wrong request', '') response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: logger.error(e)
def get_trend_data_view(request): """ This function is used to show the mastery data in a graphical format """ try: if request.method == 'POST': body_unicode = request.body.decode('utf-8') params = json.loads(body_unicode) start_timestamp = params.get('startTimestamp', '') start = datetime.datetime.fromtimestamp(start_timestamp) end_timestamp = params.get('endTimestamp', '') end = datetime.datetime.fromtimestamp(end_timestamp) level = params.get('level') item_id = params.get('itemId') data = None content = None total_students = 1.0 if level == -1 or level == 0: pass elif level == 1: school = UserInfoSchool.objects.filter( school_id=item_id).first() total_students = school.total_students data = School.objects.filter(school_id=item_id, date__gte=start, date__lte=end).order_by('date') # else: # data = School.objects.filter(school_id=item_id,date__gte=start,date__lte=end).order_by('date') # print(data) elif level == 2: classroom = UserInfoClass.objects.filter( class_id=item_id).first() total_students = classroom.total_students # if topic_id == "-1": # data = Class.objects.filter(class_id=item_id,date__gte=start,date__lte=end).order_by('date') # else: data = Class.objects.filter(class_id=item_id, date__gte=start, date__lte=end).order_by('date') elif level == 3: # if topic_id == "-1": # data = Student.objects.filter(student_id=item_id,date__gte=start,date__lte=end).order_by('date') # else: data = Student.objects.filter(student_id=item_id, date__gte=start, date__lte=end).order_by('date') res = {} series = [] series.append({ 'name': '# Total Active Usage', 'isPercentage': False }) series.append({'name': '# Avg Active Usage', 'isPercentage': True}) points = [] total_usersession_usage = 0 # print ("data:", data) for ele in data: temp = [] # print("ele.total_usage:", ele.total_usage) total_usersession_usage += ele.total_usage k = time.mktime(ele.date.timetuple()) temp.append(time.mktime(ele.date.timetuple())) # temp.append(mastered_topics) # print("total_usersession_usage:", total_usersession_usage) p = total_usersession_usage k = total_usersession_usage / (total_students) # print ("k:", k) a, b = divmod(p, 60) h, m = divmod(a, 60) temp.append(h) m, s = divmod(k, 60) h, m = divmod(m, 60) temp.append(h) points.append(temp) # print ("temp:", temp) res['series'] = series res['points'] = points #data_str = serializers.serialize('json', data) response = construct_response(0, '', '', res) response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') else: response = construct_response(1111, 'wrong request', 'wrong request', '') response_text = json.dumps(response, ensure_ascii=False) return HttpResponse(response_text, content_type='application/json') except Exception as e: logger.error(e)