Exemplo n.º 1
0
def upload_file():
    report_file = request.files['payroll']
    pd_data = pd.read_csv(report_file)

    if type(read_data()) != str:
        if report_exists(read_data(), pd_data):
            flash('Sorry this report already exist')
            abort(409)
    # str = pprint.pformat(data, depth=5)
    # return Response(str, mimetype="text/text")
    save_data(pd_data)
    return redirect('/')
Exemplo n.º 2
0
    def test_overwrite_previous(self):
        from crawl import to_epoch
        from models import Metric, Datapoint, save_data

        when = datetime.combine(date(2011, 9, 3), time())
        save_data('python', {when: {
            ('language', 'german'): 45,
        }})

        save_data('python', {when: {
            ('language', 'english'): 13,
            ('language', 'german'): 22,
        }})

        m_german = Metric.objects.get(name='language', value='german')

        self.assertEqual(Datapoint.objects.count(), 2)
        self.assertEqual(Datapoint.objects.get(metric=m_german).count, 22)
Exemplo n.º 3
0
    def test_dump_results(self):
        from crawl import to_epoch
        from models import Metric, Datapoint, save_data

        when = datetime.combine(date(2011, 9, 3), time())
        save_data('python', {when: {
            ('language', 'english'): 13,
            ('language', 'german'): 22,
            None: 35,
        }})

        self.assertEqual(Datapoint.objects.count(), 3)
        m_german = Metric.objects.get(name='language', value='german')
        dp_german = Datapoint.objects.get(metric=m_german)
        self.assertEqual(dp_german.time, when)
        self.assertEqual(dp_german.keyword.name, 'python')
        self.assertEqual(dp_german.count, 22)

        dp_totals = Datapoint.objects.get(metric=None)
        self.assertEqual(dp_totals.count, 35)