Пример #1
0
def test_rdate_datagrid(mocker):
    mocker.patch.object(GsSession.__class__, 'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id', 'secret'))
    name = 'Testing'
    SPX = get_test_entity('MA4B66MW5E27U8P32SB')
    close = DataCoordinate(
        measure=DataMeasure.CLOSE_PRICE,
        frequency=DataFrequency.DAILY,
    )

    last_trade_price = DataCoordinate(
        measure=DataMeasure.TRADE_PRICE,
        frequency=DataFrequency.REAL_TIME,
    )
    rows = [
        DataRow(SPX),
    ]
    columns = [
        DataColumn(name="1d Chg (RT)",
                   processor=ChangeProcessor(AppendProcessor(close, last_trade_price,
                                                             start=RelativeDate("-1d",
                                                                                base_date=date(2021, 1, 22)))))
    ]

    datagrid = DataGrid(name=name, rows=rows, columns=columns)
    start_date = datagrid.columns[0].processor.children['a'].start
    assert start_date.base_date == RelativeDate('-1d', base_date=date(2021, 1, 22)).base_date
    assert start_date.rule == RelativeDate('-1d').rule

    datagrid.initialize()
    datagrid.poll()
    assert str(datagrid._data_queries[0].query.start) == '2021-01-21'

    as_dict = datagrid.as_dict()
    start = as_dict['parameters']['columns'][0]['parameters']['a']['parameters']['start']
    assert start['type'] == 'relativeDate'
    assert start['value'] == {'rule': '-1d', 'baseDate': '2021-01-22'}

    # Check that base_date is not persisted when not passed in.
    columns = [
        DataColumn(name="1d Chg (RT)",
                   processor=ChangeProcessor(AppendProcessor(close, last_trade_price,
                                                             start=RelativeDate("-1d"))))
    ]
    datagrid = DataGrid(name=name, rows=rows, columns=columns)
    as_dict = datagrid.as_dict()
    start = as_dict['parameters']['columns'][0]['parameters']['a']['parameters']['start']
    assert start['type'] == 'relativeDate'
    assert start['type'] == 'relativeDate'
    assert start['value'] == {'rule': '-1d'}
Пример #2
0
 def get_datagrids(cls, limit: int = 10, **kwargs) -> List[DataGrid]:
     raw_datagrids = get(
         GsSession.current._get(
             f'{API}?limit={limit}&orderBy=>lastUpdatedTime&{urllib.parse.urlencode(kwargs)}'
         ), 'results', [])
     return [
         DataGrid.from_dict(raw_datagrid) for raw_datagrid in raw_datagrids
     ]
Пример #3
0
 def get_your_datagrids(cls, limit: int = 10, **kwargs) -> List[DataGrid]:
     user_id = GsSession.current._get('/users/self')['id']
     raw_datagrids = get(
         GsSession.current._get(
             f'{API}?limit={limit}&ownerId={user_id}&orderBy=>lastUpdatedTime&{urllib.parse.urlencode(kwargs)}'
         ), 'results', [])
     return [
         DataGrid.from_dict(raw_datagrid) for raw_datagrid in raw_datagrids
     ]
Пример #4
0
    def get_test_datagrid(self):
        spx, aapl, amzn = self.get_test_entities()
        datagrid = DataGrid('Test DataGrid', rows=[], columns=[DataColumn('Name', None), DataColumn('Value', None)])

        results = [
            [DataCell('Name', None, None, None, 0, 0), DataCell('Value', None, None, None, 1, 0)],
            [DataCell('Name', None, None, None, 0, 1), DataCell('Value', None, None, None, 1, 1)],
            [DataCell('Name', None, None, None, 0, 2), DataCell('Value', None, None, None, 1, 2)],
        ]

        results[0][0].value = ProcessorResult(True, spx.name)
        results[0][1].value = ProcessorResult(True, np.float64(10))
        results[1][0].value = ProcessorResult(True, aapl.name)
        results[1][1].value = ProcessorResult(True, np.float64(0))
        results[2][0].value = ProcessorResult(True, amzn.name)
        results[2][1].value = ProcessorResult(True, np.float64(-10))

        datagrid.results = results
        return datagrid
Пример #5
0
def test_simple_datagrid():
    name = 'Testing'
    SPX = get_test_entity('MA4B66MW5E27U8P32SB')
    rows = [
        DataRow(SPX),
    ]
    columns = [
        DataColumn(name="Name", processor=EntityProcessor(field="short_name"))
    ]

    datagrid = DataGrid(name=name, rows=rows, columns=columns)

    assert datagrid.name == name
    assert datagrid.rows == rows
    assert datagrid.columns == columns

    assert datagrid.is_initialized is False
    assert len(datagrid.results) == 0
    datagrid.initialize()
    assert datagrid.is_initialized is True
    assert len(datagrid.results) > 0
Пример #6
0
 def update_datagrid(cls, datagrid: DataGrid):
     datagrid_json = json.dumps(datagrid.as_dict())
     datagrid = GsSession.current._put(f'{API}/{datagrid.id_}',
                                       datagrid_json,
                                       request_headers=DATAGRID_HEADERS)
     return DataGrid.from_dict(datagrid)
Пример #7
0
 def create_datagrid(cls, datagrid: DataGrid) -> DataGrid:
     datagrid_json = json.dumps(datagrid.as_dict())
     response = GsSession.current._post(f'{API}',
                                        datagrid_json,
                                        request_headers=DATAGRID_HEADERS)
     return DataGrid.from_dict(response)
Пример #8
0
 def get_datagrid(cls, datagrid_id: str) -> DataGrid:
     raw_datagrid = GsSession.current._get(f'{API}/{datagrid_id}')
     return DataGrid.from_dict(raw_datagrid)