Graph health (vaultkg.analysis)¶
vaultkg.analysis
¶
analysis.py -- graph-health metrics for a built vault graph.
Every figure here is computed from the stored graph with plain graph algorithms: degree counts, connected components and articulation points. No model reads the notes, so a report on the same build is always the same report.
The note graph used throughout collapses heading targets onto their note and
ignores CONTAINS and TAGGED: two notes are linked when one links,
embeds or typed-links the other.
VaultHealth(notes, titles, links=dict(), in_links=dict(), out_links=dict(), wanted=dict(), typed=dict(), tags=Counter(), ambiguous=0, frontmatter_errors=dict())
dataclass
¶
Graph-health figures for one vault.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notes
|
list[str]
|
Note ids. |
required |
links
|
dict[tuple[str, str], set[str]]
|
Directed note -> note pairs with their relations. |
dict()
|
in_links
|
dict[str, set[str]]
|
Note id -> distinct notes linking to it. |
dict()
|
out_links
|
dict[str, set[str]]
|
Note id -> distinct notes it links to. |
dict()
|
wanted
|
dict[str, set[str]]
|
Missing target -> distinct notes linking to it. |
dict()
|
typed
|
dict[str, list[tuple[str, str]]]
|
Typed relation -> |
dict()
|
tags
|
Counter[str]
|
Tag id -> number of notes tagged. |
Counter()
|
ambiguous
|
int
|
Links resolved among several same-named notes. |
0
|
frontmatter_errors
|
dict[str, str]
|
Note id -> YAML error. |
dict()
|
bridges()
¶
Articulation notes: removing one splits its component. With degree.
Iterative Tarjan, so a long chain of notes cannot hit the recursion limit.
Source code in src/vaultkg/analysis.py
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 | |
components()
¶
Connected components of linked notes, largest first (orphans excluded).
Source code in src/vaultkg/analysis.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
dead_ends()
¶
Notes other notes link to that link to nothing themselves.
Source code in src/vaultkg/analysis.py
70 71 72 | |
hubs(top=10)
¶
Notes with the most distinct notes linking in.
Source code in src/vaultkg/analysis.py
74 75 76 77 | |
metrics()
¶
Scalar health figures, for snapshots and --json output.
Source code in src/vaultkg/analysis.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
orphans()
¶
Notes with no link in or out.
Source code in src/vaultkg/analysis.py
66 67 68 | |
note_of(node_id)
¶
The note: id a link target belongs to, or None if it is not a note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The owning note id. |
Source code in src/vaultkg/analysis.py
26 27 28 29 30 31 32 33 34 35 36 | |
render_report(health, stats, *, top=15)
¶
Markdown graph-health report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health
|
VaultHealth
|
Figures from :func: |
required |
stats
|
dict[str, Any]
|
|
required |
top
|
int
|
Rows per ranked list. |
15
|
Returns:
| Type | Description |
|---|---|
str
|
Markdown, first line |
Source code in src/vaultkg/analysis.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
vault_health(con)
¶
Read the note graph out of a built store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
Connection
|
Connection to the vault's |
required |
Returns:
| Type | Description |
|---|---|
VaultHealth
|
The vault's health figures. |
Source code in src/vaultkg/analysis.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |