Exemple #1
0
def niki_interest_subscription_dates(request):
    """
    Return subscription dates and subscription count per date
    widget url: http://www.yourdomain.com/script?start_date={date_start}&end_date={date_end}
    """
    project_id = request.GET.get('project')
    start_str = request.GET.get('start_date')
    start = util.datestr_to_datetime(start_str)
    end_str = request.GET.get('end_date')
    end = util.datestr_to_datetime(end_str)

    project = InterestProject.objects.get(nikiProjectId=project_id)
    account = project.interestAccount
    ids = interestmanager.getIdsByProjectBetween(account, project_id, start, end)
    chart_data = ""
    if len(ids) > 0:
        subscriptions = interestmanager.getByIds(account, ids)
        dates = []  # list array of dates
        for subscription in subscriptions:
            posted = str(subscription.posted)[:-4]  # strip off time part
            dates.append(datetime.strptime(posted, "%Y%m%d"))
        counts = Counter(dates)
        # fill in the date gaps (create entries for non existing dates between start & end
        for single_date in daterange(start, end):
            if single_date not in counts:
                counts[single_date] = 0
        for key, value in counts.items():
            chart_data += "{},{}\n".format(datetime.strftime(key, "%Y%m%d"), value)

    result = "Date, Subscriptions\n"
    result += chart_data
    result += "Cumulative,0\n"
    result += "YAxisShow,1\n"
    return HttpResponse(result)
Exemple #2
0
def niki_interest_table(request):
    project_id = request.GET.get('project')
    start_str = request.GET.get('start_date')
    start = util.datestr_to_datetime(start_str)
    end_str = request.GET.get('end_date')
    end = util.datestr_to_datetime(end_str)

    nip = InterestProject.objects.get(nikiProjectId=project_id)
    project = nip.project
    occurrences = interestmanager.get_count_by_housetype(project, start, end)
    alltypes = nikimanager.getHouseTypes(project.nikiProject)
    for housetype in alltypes:
        if not housetype.get('name') in occurrences:
            occurrences[housetype.get('name')] = 0
    result = "Woningtype,Interesse\n"
    for key, value in occurrences.iteritems():
        if not key == "notype":
            result += "{},{}\n".format(key, value)
    result += "Geen specificatie,{}".format(occurrences.get('notype'))
    return HttpResponse(result)