示例#1
0
 def test_delete(self):
     param = dict(freq='q', name='GDP_yoy', start_date=None, end_date=None)
     count_before_delete = DatapointOperations.select(**param).count()
     assert count_before_delete > 0
     DatapointOperations.delete(**param)
     count_after_delete = DatapointOperations.select(**param).count()
     assert count_after_delete == 0
示例#2
0
文件: views.py 项目: mini-kep/db
    def delete(self):
        """Delete datapoints.

        Responses:
            403:
                Failed to authenticate correctly.
            200:
                Returns empty dictionary on success.
        """

        authorise()
        args = SimplifiedArgs()
        DatapointOperations.delete(**args.get_query_parameters())
        return jsonify({})
示例#3
0
 def test_wrong_params_fetch_zero_results(self):
     params = dict(freq='biba',
                   name='boba',
                   start_date=date(year=2005, month=1, day=1),
                   end_date=date(year=2006, month=1, day=1))
     number_of_results = DatapointOperations.select(**params).count()
     self.assertEqual(number_of_results, 0)
示例#4
0
文件: views.py 项目: mini-kep/db
def spline():
    args = RequestArgs()
    data = DatapointOperations.select(**args.get_query_parameters())
    png_output = image.make_png(data)
    response = make_response(png_output)
    response.headers['Content-Type'] = 'image/png'
    return response
示例#5
0
文件: views.py 项目: mini-kep/db
    def post(self):
        """Upload incoming data to database.

        Responses:
            400:
                Something went wrong in during query.
            403:
                Failed to authenticate correctly.
            200:
                Returns empty dictionary on success.
        """
        authorise()
        try:
            data = json.loads(request.data)
            for datapoint in data:
                DatapointOperations.upsert(datapoint)
            db.session.commit()
            return jsonify({})
        except BaseException:
            db.session.rollback()
            return abort(400)
示例#6
0
 def test_data_is_fetching(self):
     params = dict(freq='m',
                   name='CPI_ALCOHOL_rog',
                   start_date=date(year=2016, month=6, day=1),
                   end_date=date(year=2016, month=7, day=1))
     datapoint = DatapointOperations.select(**params).first()
     self.assertEqual(
         datapoint.serialized, {
             "date": "2016-06-30",
             "freq": "m",
             "name": "CPI_ALCOHOL_rog",
             "value": 100.6
         })
示例#7
0
文件: views.py 项目: mini-kep/db
    def get(self):
        """
        Select time series data as json.

        Responses:
            422:
                Bad arguments, eg start_date > end_date
            200:
                Sent json.
       """
        args = RequestArgs()
        data = DatapointOperations.select(**args.get_query_parameters())
        return publish_json(data)
示例#8
0
文件: views.py 项目: mini-kep/db
def get_dataframe():
    """Get csv file readable as pd.DataFrame based on variable names.

    URL examples:

         api/frame?freq=a&names=GDP_yoy,CPI_rog&start_date=2013-12-31
         api/frame?freq=a&start_date=2013-12-31
         api/frame?freq=a

    """
    args = RequestFrameArgs()
    data = DatapointOperations.select_frame(**args.get_query_parameters())
    csv_str = utils.DictionaryRepresentation(data, args.names).to_csv()
    return no_download(csv_str)
示例#9
0
 def test_get_data_for_spline(self):
     incoming_args = dict(freq='d',
                          name='USDRUR_CB',
                          start_date='2016-10-29',
                          end_date='2016-12-31')
     # setup
     req = SimRequest(**incoming_args)
     args = RequestArgs(req)
     query_data = DatapointOperations.select(**args.get_query_parameters())
     # call
     data = image.get_data_for_spline(query_data)
     # check
     assert date(2016, 10, 29) in data["x"]
     assert 62.9037 in data["y"]
     assert date(2016, 12, 31) in data["x"]
     assert 60.6569 in data["y"]
示例#10
0
    def get(self):
        """
        Select time series data as csv or json.

        Responses:
            422:
                Bad arguments, eg start_date > end_date
            200:
                Sent json or csv.
       """
        args = RequestArgs()
        data = DatapointOperations.select(**args.query_param)
        if args.format == 'json':
            return publish_json(data)
        else:
            return publish_csv(data)
示例#11
0
def get_dataframe():
    """Get csv file readable as pd.DataFrame based on many of all variabel names.

    URL examples:

         api/frame?freq=a&names=GDP_yoy,CPI_rog&start_date=2013-12-31
         api/frame?freq=a&start_date=2013-12-31
         api/frame?freq=a

    FIXME:
        Application hangs on a large query like

        api/frame?freq=q
    """
    args = RequestFrameArgs()
    param = args.query_param
    if not args.names:
        param['names'] = Allowed.names(args.freq)
    data = DatapointOperations.select_frame(**param)
    csv_str = utils.DictionaryRepresentation(data, param['names']).to_csv()
    return no_download(csv_str)
示例#12
0
文件: views.py 项目: shashi12533/db
def time_series_api_interface(domain, varname, freq, inner_path=''):
    this_variable = Indicator(domain, varname, freq, inner_path)
    data = DatapointOperations.select(**this_variable.query_param)
    return publish_csv(data)
示例#13
0
 def test_upsert_updates_value_for_existing_row(self):
     DatapointOperations.upsert(self.dp1_dict)
     DatapointOperations.upsert(self.dp1_dict_updated)
     datapoint = DatapointOperations.select(**self.dp1_search_param).first()
     assert datapoint.serialized == self.dp1_dict_updated
示例#14
0
 def test_after_upsert_datapoint_found(self):
     DatapointOperations.upsert(self.dp1_dict)
     datapoint = DatapointOperations.select(**self.dp1_search_param).first()
     assert datapoint.serialized, self.dp1_dict
示例#15
0
 def test_before_upsert_datapoint_not_found(self):
     datapoints_count = DatapointOperations.select(
         **self.dp1_search_param).count()
     assert datapoints_count == 0