()
| 24 | |
| 25 | |
| 26 | def gen_chord_data(): |
| 27 | # This function generates the dataset for the chord graph in the documentation |
| 28 | # showing relationships between BBOT modules and their consumed/produced event types |
| 29 | preloaded_mods = sorted(MODULE_LOADER.preloaded().items(), key=lambda x: x[0]) |
| 30 | |
| 31 | entity_lookup_table = {} |
| 32 | rels = [] |
| 33 | entities = {} |
| 34 | entity_counter = 1 |
| 35 | |
| 36 | def add_entity(entity, parent_id): |
| 37 | if entity not in entity_lookup_table: |
| 38 | nonlocal entity_counter |
| 39 | e_id = entity_counter |
| 40 | entity_counter += 1 |
| 41 | entity_lookup_table[entity] = e_id |
| 42 | entity_lookup_table[e_id] = entity |
| 43 | entities[e_id] = {"id": e_id, "name": entity, "parent": parent_id, "consumes": [], "produces": []} |
| 44 | return entity_lookup_table[entity] |
| 45 | |
| 46 | # create entities for all the modules and event types |
| 47 | for module, preloaded in preloaded_mods: |
| 48 | watched = [e for e in preloaded["watched_events"] if e != "*"] |
| 49 | produced = [e for e in preloaded["produced_events"] if e != "*"] |
| 50 | if watched or produced: |
| 51 | m_id = add_entity(module, 99999999) |
| 52 | for event_type in watched: |
| 53 | e_id = add_entity(event_type, 88888888) |
| 54 | entities[m_id]["consumes"].append(e_id) |
| 55 | entities[e_id]["consumes"].append(m_id) |
| 56 | for event_type in produced: |
| 57 | e_id = add_entity(event_type, 88888888) |
| 58 | entities[m_id]["produces"].append(e_id) |
| 59 | entities[e_id]["produces"].append(m_id) |
| 60 | |
| 61 | def add_rel(incoming, outgoing, t): |
| 62 | if incoming == "*" or outgoing == "*": |
| 63 | return |
| 64 | i_id = entity_lookup_table[incoming] |
| 65 | o_id = entity_lookup_table[outgoing] |
| 66 | rels.append({"source": i_id, "target": o_id, "type": t}) |
| 67 | |
| 68 | # create all the module <--> event type relationships |
| 69 | for module, preloaded in preloaded_mods: |
| 70 | for event_type in preloaded["watched_events"]: |
| 71 | add_rel(module, event_type, "consumes") |
| 72 | for event_type in preloaded["produced_events"]: |
| 73 | add_rel(event_type, module, "produces") |
| 74 | |
| 75 | # write them to JSON files |
| 76 | data_dir = Path(__file__).parent.parent.parent / "docs" / "data" / "chord_graph" |
| 77 | data_dir.mkdir(parents=True, exist_ok=True) |
| 78 | entity_file = data_dir / "entities.json" |
| 79 | rels_file = data_dir / "rels.json" |
| 80 | |
| 81 | entities = [ |
| 82 | {"id": 77777777, "name": "root"}, |
| 83 | {"id": 99999999, "name": "module", "parent": 77777777}, |
no test coverage detected
searching dependent graphs…