예제 #1
0
def trends_json(request):
   if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         if GET.has_key('tag'):
            filt = eStats.create_guid_filter(GET['tag'],False,filt)    
         if GET.has_key('notebook'):
            filt = eStats.create_guid_filter(GET['notebook'],True,filt)    
         #if the time frame is across multiple years then use months
         formattedTrend = [["Date","Notes"]]
         if (endDate.year - startDate.year) > 1:
            dateTrends = eStats.get_date_trends(True,filt)
            for dt in rrule.rrule(rrule.MONTHLY, dtstart=startDate, 
                                                 until=endDate):
               formattedTrend.append([dt.strftime("%b \'%y"),
                                     dateTrends[dt.strftime("%b \'%y")]])
         else:
            dateTrends = eStats.get_date_trends(False,filt)
            for dt in rrule.rrule(rrule.DAILY, dtstart=startDate, 
                                               until=endDate):
               formattedTrend.append([dt.strftime("%d %b"),
                                     dateTrends[dt.strftime("%d %b")]])
         jsonText = json.dumps({'data': formattedTrend,
                                'title': "Total Notes"})
         return HttpResponse(jsonText,content_type='application/json')
예제 #2
0
def geo_loc_json(request):
    if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         noteMetadata = eStats.get_note_metadata(filt)
         if noteMetadata is None:
            return HttpResponse({},content_type='application/json')
         jsonText = json.dumps({'points' : noteMetadata['geoLocations']})
         return HttpResponse(jsonText,content_type='application/json')
예제 #3
0
def word_count_json(request):
    if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         if GET.has_key('tag'):
            filt = eStats.create_guid_filter(GET['tag'],False,filt)    
         if GET.has_key('notebook'):
            filt = eStats.create_guid_filter(GET['notebook'],True,filt)    
         wordCount = eStats.get_word_count(filt, numWords=200)
         #what happens when no data?
         jsonText = json.dumps({'words' : wordCount})
         return HttpResponse(jsonText,content_type='application/json')
예제 #4
0
def notebook_count_json(request):
    if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         qStats = eStats.get_quick_stats(filt)
         if qStats is None:
            return HttpResponse({},content_type='application/json')
         guidToNameMap = eStats.get_guid_map(notebookNames=True)
         noteFrequency = qStats['notebookCounts']
         notebookArray = [[k,v] for k,v in noteFrequency.iteritems()]
         jsonText = json.dumps({'keyToDisplayMap': guidToNameMap,
                                'noteArray': notebookArray,
                                'displayObjectName': 'Notebook',
                                'evernoteSearchParam' : 'b'})
         return HttpResponse(jsonText,content_type='application/json')
예제 #5
0
def day_count_json(request):
    if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         noteMetadata = eStats.get_note_metadata(filt)
         if noteMetadata is None:
            return HttpResponse({},content_type='application/json')
         dayFrequency = noteMetadata['dayCounter']
         intToDayMap = {0: "Sunday", 1: "Monday", 2: "Tuesday",
                        3: "Wednesday", 4: "Thursday", 5: "Friday",
                        6: "Saturday"}
         daysArray = [[x,0] for x in intToDayMap.values()]
         for (k,v) in dayFrequency.iteritems():
            daysArray[k][1] = v
         jsonText = json.dumps({'categoryCounts': daysArray,
                                'categoryTitle': 'Day'})
         return HttpResponse(jsonText,content_type='application/json')
예제 #6
0
def month_count_json(request):
    if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         noteMetadata = eStats.get_note_metadata(filt)
         if noteMetadata is None:
            return HttpResponse({},content_type='application/json')
         monthFrequency = noteMetadata['monthCounter']
         intToMonthMap = {1: "January", 2: "February", 3: "March",
                          4: "April", 5: "May", 6: "June",
                          7: "July", 8: "August", 9: "September",
                         10: "October", 11: "November", 12: "December"}
         monthsArray = [[x,0] for x in intToMonthMap.values()]
         for (k,v) in monthFrequency.iteritems():
            monthsArray[k-1][1] = v
         jsonText = json.dumps({'categoryCounts': monthsArray,
                                'categoryTitle': 'Month'})
         return HttpResponse(jsonText,content_type='application/json')