20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 | class NetworkDataImportComponent(DataImportComponent):
_component_name = "import_network_data"
_examples = [{"doc": "The default network_data onboarding component.", "args": {}}] # type: ignore
@classmethod
def get_data_type(cls) -> str:
return "network_data"
def render_onboarding_page(
self, st: "KiaraStreamlitAPI", options: DataImportOptions
) -> Union[None, JobDesc]:
_key = options.create_key("import", "network_data")
with st.expander(label="Select a table containing the edges", expanded=True):
key = options.create_key("import", "network_data", "from", "table", "edges")
selected_edges_table = self.get_component("select_table").render(
st=st, key=key, add_import_widget=True
)
with st.expander(
label="Select a table containing (optional) node information",
expanded=False,
):
key = options.create_key("import", "network_data", "from", "table", "nodes")
selected_nodes_table = self.get_component("select_table").render(
st=st, key=key, add_import_widget=True, add_no_value_option=True
)
with st.expander(label="Assemble options", expanded=True):
key_column, value_column = st.columns([1, 5])
# with key_column:
# st.write("Edges table")
# with value_column:
# if selected_edges_table:
# st.kiara.preview_table(selected_edges_table, height=200)
# else:
# st.write("*-- no edges table selected --*")
key_column, value_column = st.columns([1, 5])
with key_column:
st.write("Edge table options")
with value_column:
if selected_edges_table:
available_edge_coluns = selected_edges_table.data.column_names
else:
available_edge_coluns = []
edge_columns = st.columns([1, 1])
with edge_columns[0]:
default = 0
for idx, column in enumerate(available_edge_coluns):
if column.lower() in SOURCE_COLUMN_ALIAS_NAMES:
default = idx
break
edge_source_column = st.selectbox(
"Source column name",
available_edge_coluns,
key=f"{_key}_edge_source_column",
index=default,
)
with edge_columns[1]:
default = 0
for idx, column in enumerate(available_edge_coluns):
if column.lower() in TARGET_COLUMN_ALIAS_NAMES:
default = idx
break
edge_target_column = st.selectbox(
"Source target name",
available_edge_coluns,
key=f"{_key}_edge_target_column",
index=default,
)
key_column, value_column = st.columns([1, 5])
with key_column:
st.write("Node table options")
with value_column:
if selected_nodes_table:
available_node_coluns = selected_nodes_table.data.column_names
else:
available_node_coluns = []
node_columns = st.columns([1, 1])
with node_columns[0]:
default = 0
for idx, column in enumerate(available_node_coluns):
if column.lower() in NODE_ID_ALIAS_NAMES:
default = idx
break
node_id_column = st.selectbox(
"Node ID column name",
available_node_coluns,
key=f"{_key}_node_id_column",
index=default,
)
with node_columns[1]:
default = 0
for idx, column in enumerate(available_node_coluns):
if column.lower() in LABEL_ALIAS_NAMES:
default = idx
break
label_column = st.selectbox(
"Label column name",
available_node_coluns,
key=f"{_key}_label_column",
index=default,
)
if not selected_edges_table:
return None
inputs = {}
inputs["edges"] = selected_edges_table.value_id
inputs["nodes"] = (
selected_nodes_table.value_id if selected_nodes_table else None
)
inputs["source_column"] = edge_source_column
inputs["target_column"] = edge_target_column
inputs["id_column"] = node_id_column
inputs["label_column"] = label_column
job_desc = {
"operation": "assemble.network_data",
"inputs": inputs,
"doc": "Assemble a network_data value.",
}
return JobDesc(**job_desc)
|