示例#1
0
    def test_montlyreport(self):
        tracker = Tracker()
        def add_static(labels, **kwargs):
            for label in parse_query(labels):
                s = Statistic(label=label.get('lbl'), category=label.get('cat'),
                        dom_id=label.get('domid', ''), **kwargs)

                s.save()
        add_static("us_link1.com:links|es_link2.com:links|us_link2.com:links",
                counter=5)

        add_static("us_link1.com:links|es_link4.com:links|us_link3.com:links",
                counter=10)

        report = make_monthly_report_country()
        def ListEqual(list1, list2):
            if len(list1) != len(list2):
                return False
            for ele in list1:
                if ele not in list2:
                    return False
            return True
        self.assertTrue(ListEqual(report['us'].keys(), ['link1.com', 'link2.com',
            'link3.com']))
        self.assertTrue(ListEqual(report['es'].keys(), ['link4.com',
            'link2.com']))
        self.assertEqual(report['us']['link1.com'], 15)
        self.assertEqual(report['es']['link2.com'], 5)
        self.assertEqual(report['us']['link3.com'], 10)
        self.assertEqual(report['fr'], dict())
示例#2
0
def crazy_function(month=today.month, category='links', year=today.year):
    data = make_monthly_report_country(month=month, year=year, category=category)
    total = 0
    for country in data:
        if len(country.data_serialized) > total:
            total = len(country.data_serialized)

    #header
    total += 1

    final = ["" for a in range(total)]
    for country in data:
        if country.total() < 25:
            continue
        final[0] += "%s,%s," % (country.total(), country.country)
        for nline in range(len(country.data_serialized)):
            line = "%s,%s," % (country.data_serialized[nline][1], country.data_serialized[nline][0])
            try:
                final[nline+1] += line
            except IndexError:
                final.append(line)
        for n in range(nline+2, total):
            final[n] += ",,"
    f = open("/tmp/%s-%s.%s.csv" % (category, month, year), 'w')
    f.write("\n".join(final));f.close()
示例#3
0
def crazy_function(month=today.month, category='links', year=today.year):
    data = make_monthly_report_country(month=month,
                                       year=year,
                                       category=category)
    total = 0
    for country in data:
        if len(country.data_serialized) > total:
            total = len(country.data_serialized)

    #header
    total += 1

    final = ["" for a in range(total)]
    for country in data:
        if country.total() < 25:
            continue
        final[0] += "%s,%s," % (country.total(), country.country)
        for nline in range(len(country.data_serialized)):
            line = "%s,%s," % (country.data_serialized[nline][1],
                               country.data_serialized[nline][0])
            try:
                final[nline + 1] += line
            except IndexError:
                final.append(line)
        for n in range(nline + 2, total):
            final[n] += ",,"
    f = open("/tmp/%s-%s.%s.csv" % (category, month, year), 'w')
    f.write("\n".join(final))
    f.close()
示例#4
0
def monthly(request):
    today = datetime.datetime.today() 
    # ?month ?year
    month = int(request.GET.get('month', today.month))
    year = int(request.GET.get('year', today.year))

    # ?force would generate the statistics from that period
    force = request.GET.has_key('force')
    category = request.GET.get("tag", 'links')

    # Call the actuall procedure to get the report
    data = make_monthly_report_country(month=month, year=year, force=force,
            category=category)

    return render_to_response('monthly.html', {'report': data})
示例#5
0
def monthly(request):
    today = datetime.datetime.today()
    # ?month ?year
    month = int(request.GET.get('month', today.month))
    year = int(request.GET.get('year', today.year))

    # ?force would generate the statistics from that period
    force = request.GET.has_key('force')
    category = request.GET.get("tag", 'links')

    # Call the actuall procedure to get the report
    data = make_monthly_report_country(month=month,
                                       year=year,
                                       force=force,
                                       category=category)

    return render_to_response('monthly.html', {'report': data})
示例#6
0
    def test_montlyreport(self):
        tracker = Tracker()

        def add_static(labels, **kwargs):
            for label in parse_query(labels):
                s = Statistic(label=label.get('lbl'),
                              category=label.get('cat'),
                              dom_id=label.get('domid', ''),
                              **kwargs)

                s.save()

        add_static("us_link1.com:links|es_link2.com:links|us_link2.com:links",
                   counter=5)

        add_static("us_link1.com:links|es_link4.com:links|us_link3.com:links",
                   counter=10)

        report = make_monthly_report_country()

        def ListEqual(list1, list2):
            if len(list1) != len(list2):
                return False
            for ele in list1:
                if ele not in list2:
                    return False
            return True

        self.assertTrue(
            ListEqual(report['us'].keys(),
                      ['link1.com', 'link2.com', 'link3.com']))
        self.assertTrue(
            ListEqual(report['es'].keys(), ['link4.com', 'link2.com']))
        self.assertEqual(report['us']['link1.com'], 15)
        self.assertEqual(report['es']['link2.com'], 5)
        self.assertEqual(report['us']['link3.com'], 10)
        self.assertEqual(report['fr'], dict())
示例#7
0
def generate_country_report():
    make_monthly_report_country(category='links', force=True)
    make_monthly_report_country(category='search', force=True)
示例#8
0
def generate_country_report():
    make_monthly_report_country(category='links', force=True)
    make_monthly_report_country(category='search', force=True)