def filtertwInteractionsBufr(user_id, company_id, start_date, end_date, interaction_type, series_type, query_type, page_number, items_per_page, system_type, offset, code, chart_name): #print 'start is ' + str(time.time()) if start_date is not None: local_start_date_naive = datetime.fromtimestamp(float(start_date)) local_start_date = _str_from_date(local_start_date_naive, "short") #local_start_date = get_current_timezone().localize(local_start_date_naive, is_dst=None) #print 'start2 is ' + str(time.time()) if end_date is not None: local_end_date_naive = datetime.fromtimestamp(float(end_date)) local_end_date = _str_from_date(local_end_date_naive, "short") #print 'start3 is ' + str(time.time()) #local_end_date = get_current_timezone().localize(local_end_date_naive, is_dst=None) #print 'filter start us ' + str(local_start_date) + ' and edn is ' + str(local_end_date) #code = _get_code(company_id, system_type) try: interactions = [] company_field_qry = 'company_id' chart_name_qry = 'chart_name' system_type_qry = 'system_type' date_qry = 'date' querydict = {company_field_qry: company_id, system_type_qry: system_type, date_qry: local_start_date, chart_name_qry: chart_name} print 'qd is ' + str(querydict) analyticsIds = AnalyticsIds.objects(**querydict).only('results').first() #print 'start3 is ' + str(time.time()) if analyticsIds is None: return [] print 'interaction tupe is ' + interaction_type ids = analyticsIds['results'].get(interaction_type, None) print 'ids is ' + str(ids) publishedTweets = PublishedTweet.objects(interaction_id__in=ids).skip(offset).limit(items_per_page).order_by('published_date') #print 'start5 is ' + str(time.time()) #now do the calculations total = PublishedTweet.objects(interaction_id__in=ids).count() #len(leads) #print 'start6 is ' + str(time.time()) serializer = PublishedTweetSerializer(publishedTweets, many=True) return JsonResponse({'count' : total, 'results': serializer.data}) except Exception as e: return JsonResponse({'Error' : str(e)})
def saveBufrTwInteractionsToMaster(user_id=None, company_id=None, job_id=None, run_type=None): #behaves differently because it directly saves the data to the AnalyticsData collection if run_type == 'initial': tw_interactions = TempData.objects(Q(company_id=company_id) & Q(record_type='tw_interaction') & Q(source_system='bufr') & Q(job_id=job_id) ).only('source_record') else: tw_interactions = TempDataDelta.objects(Q(company_id=company_id) & Q(record_type='tw_interaction') & Q(source_system='bufr') & Q(job_id=job_id) ).only('source_record') company_query = 'company_id' interaction_id_query = 'interaction_id' tw_interactionsList = list(tw_interactions) tw_interactionsList = [i['source_record'] for i in tw_interactionsList] try: for interaction in tw_interactionsList: profile_id = interaction['profile_id'] published_date = datetime.fromtimestamp(float(interaction['sent_at'])) local_published_date = get_current_timezone().localize(published_date, is_dst=None) date = local_published_date.strftime('%Y-%m-%d') queryDict = {company_query : company_id, interaction_id_query: interaction['id']} publishedTweet = PublishedTweet.objects(**queryDict).first() if publishedTweet is None: #this tweet's record not found publishedTweet = PublishedTweet() publishedTweet.company_id = company_id publishedTweet.interaction_id = interaction['id'] publishedTweet.published_date = date publishedTweet.published_timestamp = interaction['sent_at'] publishedTweet.data = interaction publishedTweet.save() # except Exception as e: send_notification(dict(type='error', success=False, message=str(e)))