def test_add_data_json(self): """ Test add process data into """ # Fake answer definition httpretty.register_uri( httpretty.POST, 'http://%s:%s/TemporalDataManagerWebApp/webapi/processdata/portfolio_interpolation/JSON' % (TEST_HOST, TEST_PORT), body='OK', status=200) ntdm = NonTemporalDataMgr() results = ntdm.add_data( str([ "00006100000B005FC4", "00006200000B005FCB", "00006300000B005FCE", "00006400000B005FC6", "00006500000B005FC7", "00006600000B005FD0", "00006700000B005FCF", "00006900000B005FC5", "00006A00000B005FC9", "00006B00000B005FCA", "00006C00000B005FCC", "00006D00000B005FCD", "00006E00000B005FC8" ]), "portfolio_interpolation", "JSON", "JSON_name") if not results['status']: self.fail()
def create(data, process_id, name, data_type=None): """ Create a process data :param data: data to store :param process_id: id of the process to bind this data to :param name: name of the process data :param data_type: data_type (deprecated) of the data to store :type data: any :type process_id: str or int :type name: str :type data_type: str or None :return: execution status :raise ValueError: if data_type is not handled :raise TypeError: data content type is not handled """ ntdm = NonTemporalDataMgr() return ntdm.add_data(data=data, process_id=process_id, data_type=data_type, name=name)
def test_add_data_csv(self): """ Test add process data into """ # Fake answer definition httpretty.register_uri( httpretty.POST, 'http://%s:%s/TemporalDataManagerWebApp/webapi/processdata/exec4' % (TEST_HOST, TEST_PORT), body='OK', status=200) ntdm = NonTemporalDataMgr() # Create the test file with open('/tmp/test.csv', 'w') as opened_file: opened_file.write('timestamp;value\n') opened_file.write('2015-01-01T00:00:01.0;1\n') opened_file.write('2015-01-01T00:00:02.0;2\n') opened_file.write('2015-01-01T00:00:03.0;3\n') opened_file.write('2015-01-01T00:00:04.0;5\n') opened_file.write('2015-01-01T00:00:05.0;8\n') opened_file.write('2015-01-01T00:00:06.0;13\n') results = ntdm.add_data("/tmp/test.csv", "exec4", "CSV") if not results['status']: self.fail()
def delete(process_id): """ Delete a process data :param process_id: the process data id to delete :type process_id: int or str :return: the status of deletion (True=deleted, False otherwise) :rtype: bool """ ntdm = NonTemporalDataMgr() ntdm.remove_data(process_id=process_id)
def test_download_data(): """ Not implemented """ # Fake answer definition httpretty.register_uri( httpretty.GET, 'http://%s:%s/TemporalDataManagerWebApp/webapi/processdata/id/download/1' % (TEST_HOST, TEST_PORT), status=200) ntdm = NonTemporalDataMgr() ntdm.download_data("1")
def test_remove_data(): """ Not implemented """ ntdm = NonTemporalDataMgr() # Fake answer definition httpretty.register_uri( httpretty.DELETE, 'http://%s:%s/TemporalDataManagerWebApp/webapi/processdata/exec4' % (TEST_HOST, TEST_PORT), status=204, content_type='text/json') ntdm.remove_data("exec4")
def main_test(): """ Functional test entry point """ tdm = TemporalDataMgr() ntdm = NonTemporalDataMgr() nb_tsuid = 0 tsuid_list = [] answer = input( 'output functional Identifiers [0] or tsuids [1] (default value : 1) :' ) or '1' if answer == '0': tsuids_out = False elif answer == '1': tsuids_out = True else: raise ValueError(TypeError) answer = input( 'input list of tsuids [0] or dataset name [1] (default value : 0) :' ) or '0' if answer == '0': print('Example tsuid_list 1 (benchmark) = ') print( '[000069000009000AE3, 00006E000009000AE8, 00006A000009000AE4, 00006B000009000AE5,' ' 00006C000009000AE6, 00006D000009000AE7, 000066000009000AE0, 000068000009000AE2 ]' ) print('Example tsuid_list 2 (functional ids) = ') print('[00001F00000B000BFE, 00008300000B000BFF, 00008400000B000C08]') print('Enter your list of tsuids :') tsuid = input('tsuid no 1 [ENTER to quit]: ') while tsuid != '': if tsuid != '': nb_tsuid += 1 tsuid_list.append(tsuid) tsuid = input('tsuid no ' + str(nb_tsuid + 1) + '[ENTER to quit]: ') else: print('Example dataset : dsCorrMat') tsuid_list = input('dataset_name: ') if tsuid_list: sd_temp = input('start date (yyyy-mm-dd) : ') ed_temp = input('end date (yyyy-mm-dd): ') if sd_temp and ed_temp: sd = int(time.mktime(time.strptime(sd_temp, "%Y-%m-%d"))) ed = int(time.mktime(time.strptime(ed_temp, "%Y-%m-%d"))) # Correlation Matrix computation and display print('Correlation Matrix (pearson) = ') print(pearson_correlation_matrix(tdm, tsuid_list, tsuids_out)) print('PROCESS ID name : PearsonCorrelationMatrix') else: print('Start date / end date missing') else: print('tsuids list or dataset missing')
def test_get_data(): """ Requests for the meta data associated to a TS """ ntdm = NonTemporalDataMgr() # Fake answer definition httpretty.register_uri( httpretty.GET, 'http://%s:%s/TemporalDataManagerWebApp/webapi/processdata/exec4' % (TEST_HOST, TEST_PORT), body= '[{"id":1,"processId":"exec4","dataType":"CSV","name":"distance_matrix.csv"}]', status=200, content_type='text/json') ntdm.get_data("exec4")
def list(process_id): """ Reads the ProcessData resource list matching the process_id. :param process_id: processId of the filtered resources. It can be the ID of an executable algorithm, or any other data producer identifier. :type process_id: int or str :return: the data without BLOB content: list of resources matching the process_id. Each resource is a dict mapping the ProcessData json from RestFul API: dict with entries: - id - processId - name - dataType :rtype: list """ ntdm = NonTemporalDataMgr() return ntdm.get_data(process_id=process_id)
def read(process_data_id): """ Reads the data blob content: for the unique process_data row identified by id. :param process_data_id: the id key of the raw process_data to get data from :return: the content data stored. :rtype: bytes or str or object :raise IkatsNotFoundError: no resource identified by ID :raise IkatsException: failed to read """ response = None try: ntdm = NonTemporalDataMgr() response = ntdm.download_data(process_data_id) if response.status == 200: # Reads the data returned by the service. # default_content is only used if the content_type is unknown by RestClientResponse return response.get_appropriate_content( default_content=response.text) elif response.status == 404: msg = "IkatsProcessData::read({}) resource not found : HTTP response={}" raise IkatsNotFoundError(msg.format(process_data_id, response)) else: msg = "IkatsProcessData::read({}) failed : HTTP response={}" raise IkatsException(msg.format(process_data_id, response)) except IkatsException: raise except Exception as exception: msg = "IkatsProcessData::read({}) failed : unexpected error. got response={}" raise IkatsException(msg.format(exception, response))
def test_add_data_any(self): """ Test add process data into """ # Fake answer definition httpretty.register_uri( httpretty.POST, 'http://%s:%s/TemporalDataManagerWebApp/webapi/processdata' % (TEST_HOST, TEST_PORT), body='12', status=200) ntdm = NonTemporalDataMgr() data_to_send = "Any opaque data" results = ntdm.add_data(data=data_to_send, data_type=None, name="Name_of_data", process_id=42) if not results['status']: self.fail()
def get_non_temporal_manager(self): """ Gets the non temporal manager from the singleton configuration Note: new instance is created each time this method is called """ return NonTemporalDataMgr(self.host, self.port)