def test_entity_filter_model_fields_returns_only_fields_on_model(): fields = {"symbol": "QQQ", "last_id": 1200, "field1": "value1", "field2": 2} entity = Entity(Model.QUOTE, fields) filtered_fields = entity.filter_model_fields() assert len(filtered_fields) == 2 assert filtered_fields['symbol'] == "QQQ" assert filtered_fields['last_id'] == 1200
def test_entity_to_json_includes_fields_and_model(): fields = {"field1": "value1", "field2": 2} entity = Entity(Model.QUOTE, fields) json_str = entity.to_json() entity_from_json = json.loads(json_str) assert entity_from_json['field1'] == "value1" assert entity_from_json['field2'] == 2 assert entity_from_json['model'] == Model.QUOTE.name
def test_entity_filter_model_fields_applies_mapping_before_filtering(): fields = {"symbol": "QQQ", "last_id": 1200, "field1": 1234, "field2": 2} mappings = {"field1": "ask_id"} entity = Entity(Model.QUOTE, fields, mappings) filtered_fields = entity.filter_model_fields() assert len(filtered_fields) == 3 assert filtered_fields['symbol'] == "QQQ" assert filtered_fields['last_id'] == 1200 assert filtered_fields['ask_id'] == 1234
def quote(): quote = Entity( Model.QUOTE, json.loads(""" { "key": "MSFT", "delayed": false, "assetMainType": "EQUITY", "cusip": "594918104", "bid_price": 183.7, "ask_price": 183.88, "last_price": 183.7, "bid_size": 8, "ask_size": 1, "ask_id": "P", "bid_id": "P", "total_volume": 42146720, "trade_time": 71997, "quote_time": 71985, "last_id": "D", "timestamp": 1590879805110, "formated_timestamp": "2020-05-30 20:03:25.110000" } """)) return quote
def test_entity_is_created_with_mappings(): fields = {"field1": "value1", "field2": 2, "field3": "value3"} mappings = {"field1": "mapped_field1", "field3": "mapped_field3"} entity = Entity(Model.QUOTE, fields, mappings) assert entity['mapped_field1'] == "value1" assert entity['field2'] == 2 assert entity['mapped_field3'] == "value3" with pytest.raises(KeyError): entity['field1']
def pre_process(path, dict_path): with open(path) as f: reader = csv.reader(f, delimiter=' ') line_count = 0 for row in reader: if line_count > 0: synonyms = row[2].split("$") for word in synonyms: if word in entity_dic: e = entity_dic.get(word) e.entity.append(row[1]) else: e = Entity(word, [row[1]]) entity_dic.add_word(word, e) line_count += 1 entity_dic.make_automaton() cPickle.dump(entity_dic, open(dict_path, "wb"))
def load_data(fname: str) -> Dict[str, EntityContainer]: result = {} wb = load_workbook(filename=fname) for type_name in wb.sheetnames: if type_name == 'Карты действий': # TODO ПОПРАВИТЬ ФОРМАТ! continue sheet = wb[type_name] entity_list = [ Entity(name=name.value, score=int(score.value)) for name, score in zip(sheet['A'], sheet['C']) ] c = int(sheet['F1'].value[1:]) result[type_name] = EntityContainer(name=type_name, c=c, entity_list=entity_list) return result
def run(): connect() gc.collect() mqtt = connect_mqtt() gc.collect() entity_a = Entity("a", cfg.HUM_SENSOR_A, cfg.PUMP_A, cfg.TARGET_MOISTURE_A, cfg.WATER_TIME_A) entity_b = Entity("b", cfg.HUM_SENSOR_B, cfg.PUMP_B, cfg.TARGET_MOISTURE_B, cfg.WATER_TIME_B) entity_a.setup_homeassistant(mqtt) entity_b.setup_homeassistant(mqtt) air_state = AirState(pin=cfg.DHT_PIN, offset_temp=cfg.DHT_OFFSET_TEMP, offset_humid=cfg.DHT_OFFSET_HUMID) display = Display(scl=cfg.DISPLAY_SCL, sda=cfg.DISPLAY_SDA) gf = GreenFinger(mqtt, [entity_a, entity_b], air_state, display) gc.collect() print("RAM AFTER SETUP:", gc.mem_free()) gf.loop()
def _create_entity(self, element): return Entity(Model.QUOTE, element, self.mappings)
query = template.render(ontoClassX=ontoClassX, ontoClassY=ontoClassY, relationship=relationship) res = c.query(query) print "Wrong types:" for r in res: print ">>", r['y']['value'], "detected in", r['x']['value'] if __name__=='__main__': with open("models", "r") as ins: modelsPath = ins.read().splitlines()[0] included_extenstions = ['json'] file_names = [fn for fn in os.listdir(modelsPath) if any([fn.endswith(ext) for ext in included_extenstions])] for file in file_names: entity = Entity(os.path.abspath(os.path.join(modelsPath, file).replace("\\","/"))) #The check below is a special case of the cardinality check, so it's not needed #entity.checkRelationsExistance() entity.checkCardinality() entity.checkHirerarchy() env = Environment(loader=FileSystemLoader('tmpl')) c = Connection('http://triples.101companies.org:8080/openrdf-sesame/') c.use_repository('sandbox') c.addnamespace('onto', 'http://101companies.org/ontology#') c.addnamespace('res', 'http://101companies.org/resources#') #existanceCheck(env, 'Contribution', 'implements') #cardinalityCheck(env, 'Contribution', 'implements') typeCheck(env, 'Contribution', 'Feature', 'implements')
for r in res: print ">>", r['y']['value'], "detected in", r['x']['value'] if __name__ == '__main__': with open("models", "r") as ins: modelsPath = ins.read().splitlines()[0] included_extenstions = ['json'] file_names = [ fn for fn in os.listdir(modelsPath) if any([fn.endswith(ext) for ext in included_extenstions]) ] for file in file_names: entity = Entity( os.path.abspath(os.path.join(modelsPath, file).replace("\\", "/"))) #The check below is a special case of the cardinality check, so it's not needed #entity.checkRelationsExistance() entity.checkCardinality() entity.checkHirerarchy() env = Environment(loader=FileSystemLoader('tmpl')) c = Connection('http://triples.101companies.org:8080/openrdf-sesame/') c.use_repository('sandbox') c.addnamespace('onto', 'http://101companies.org/ontology#') c.addnamespace('res', 'http://101companies.org/resources#') #existanceCheck(env, 'Contribution', 'implements') #cardinalityCheck(env, 'Contribution', 'implements') typeCheck(env, 'Contribution', 'Feature', 'implements')
def test_centity(): print("Testing ..") e = Entity(entity_type=constants.INTERFACE, entity_name="test_if") print("e = " + str(e.getType()) + ", " + e.getName())
def test_entity_is_created_without_mappings(): fields = {"field1": "value1", "field2": 2} entity = Entity(Model.QUOTE, fields) assert entity['field1'] == "value1" assert entity['field2'] == 2
def test_entity_from_json_throws_error_when_invalid_model(): json_str = '{"model": "unknown", "field1": "value1", "field2": 2}' with pytest.raises(EntityException): Entity.from_json(json_str)
def test_entity_from_json_includes_fields_and_model(): json_str = '{"model": "QUOTE", "field1": "value1", "field2": 2}' entity_from_json = Entity.from_json(json_str) assert entity_from_json['field1'] == "value1" assert entity_from_json['field2'] == 2 assert entity_from_json['model'] == Model.QUOTE.name
def main(): with DBRepository(connection_pool) as repo: for message in sys.stdin: entity = Entity.from_json(message) repo.add(entity)