| 1 |
<resource schema="dc" resdir="__system"> |
| 2 |
<meta name="description">DaCHS predefined procedures. Whatever is in here |
| 3 |
will also end up in the reference documentation, so that's where you |
| 4 |
should look if you just want to use this.</meta> |
| 5 |
|
| 6 |
<!-- ################################################ |
| 7 |
apply and rowfilter proc defs --> |
| 8 |
|
| 9 |
<procDef type="apply" id="printRow"> |
| 10 |
<doc> |
| 11 |
Print the current row to standard output. |
| 12 |
|
| 13 |
This is the equivalent of the printf-debugger. It is much like the |
| 14 |
-d command line switch to gavo imp, but you can see the effects |
| 15 |
of row filters, var settings, potentially earlier proc applications, etc. |
| 16 |
</doc> |
| 17 |
<code> |
| 18 |
print vars |
| 19 |
</code> |
| 20 |
</procDef> |
| 21 |
|
| 22 |
|
| 23 |
<procDef id="debug"> |
| 24 |
<doc> |
| 25 |
Give a python debugger prompt. |
| 26 |
|
| 27 |
This drops you in the python debugger. See vars for what's coming |
| 28 |
from the grammar, result for what's been mapped at this point. |
| 29 |
|
| 30 |
Type cont to continue. |
| 31 |
</doc> |
| 32 |
<code> |
| 33 |
import pdb; pdb.set_trace() |
| 34 |
</code> |
| 35 |
</procDef> |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
<procDef type="apply" id="simpleSelect"> |
| 40 |
<doc> |
| 41 |
Fill variables from a simple database query. |
| 42 |
|
| 43 |
The idea is to obtain a set of values from the data base into some |
| 44 |
columns within vars (i.e., available for mapping) based on comparing |
| 45 |
a single input value against a database column. The query should |
| 46 |
always return exactly one row. If more rows are returned, the |
| 47 |
first one will be used (which makes the whole thing a bit of a gamble), |
| 48 |
if none are returned, a ValidationError is raised. |
| 49 |
</doc> |
| 50 |
<setup> |
| 51 |
<par key="assignments"><description><![CDATA[mapping from database |
| 52 |
column names to vars column names, in the format |
| 53 |
{<db colname>:<vars name>}"]]></description></par> |
| 54 |
<par key="table" description="name of the database table to query"/> |
| 55 |
<par key="column" description="the column to compare the input value |
| 56 |
against"/> |
| 57 |
<par key="errCol">'<unknown>'</par> |
| 58 |
<par key="val" late="True"/> |
| 59 |
<code> |
| 60 |
assignments = utils.parseAssignments(assignments) |
| 61 |
dbNames, recNames = assignments.keys(), assignments.values() |
| 62 |
query = "SELECT %s FROM %s WHERE %s=%%(val)s"%( |
| 63 |
", ".join(dbNames), table, column) |
| 64 |
|
| 65 |
def parseDestWithDefault(dest, defRe=re.compile(r"(\w+)\((.*)\)")): |
| 66 |
"""returns name, default from dests like bla(0). |
| 67 |
|
| 68 |
This can be used to provide defaulted targets to assignments parsed |
| 69 |
with _parseAssignments. |
| 70 |
""" |
| 71 |
mat = defRe.match(dest) |
| 72 |
if mat: |
| 73 |
return mat.groups() |
| 74 |
else: |
| 75 |
return dest, None |
| 76 |
</code> |
| 77 |
</setup> |
| 78 |
<code><![CDATA[ |
| 79 |
try: |
| 80 |
with base.AdhocQuerier(base.getAdminConn) as querier: |
| 81 |
res = querier.connection.query(query, {"val": val}).fetchall()[0] |
| 82 |
for name, resVal in zip(recNames, res): |
| 83 |
name, default = parseDestWithDefault(name) |
| 84 |
if resVal is None: |
| 85 |
vars[name] = default |
| 86 |
else: |
| 87 |
vars[name] = resVal |
| 88 |
except IndexError: |
| 89 |
raise base.ValidationError("The item %s didn't match" |
| 90 |
" any data. Since this data is required for further" |
| 91 |
" operations, I'm giving up"%val, errCol) |
| 92 |
except base.DBError, msg: |
| 93 |
raise base.ValidationError("Internal error (%s)"%msg, "<unknown>") |
| 94 |
]]></code> |
| 95 |
</procDef> |
| 96 |
|
| 97 |
<procDef type="apply" id="resolveObject"> |
| 98 |
<setup> |
| 99 |
<par key="ignoreUnknowns" description="Return Nones for unknown |
| 100 |
objects? (if false, ValidationErrors will be raised)">True</par> |
| 101 |
<par key="logUnknowns" description="Write unresolved object names |
| 102 |
to the info log">False</par> |
| 103 |
<par key="identifier" late="True" |
| 104 |
description="The identifier to be resolved."/> |
| 105 |
<code> |
| 106 |
from gavo.protocols import simbadinterface |
| 107 |
resolver = simbadinterface.Sesame() |
| 108 |
</code> |
| 109 |
</setup> |
| 110 |
<doc> |
| 111 |
Resolve identifiers to simbad positions. |
| 112 |
|
| 113 |
It caches query results (positive as well as negative ones) in |
| 114 |
cacheDir. To avoid flooding simbad with repetitive requests, it |
| 115 |
raises an error if this directory is not writable. |
| 116 |
|
| 117 |
It leaves J2000.0 positions as floats in the simbadAlpha and |
| 118 |
simbadDelta variables. |
| 119 |
</doc> |
| 120 |
<code> |
| 121 |
ra, dec = None, None |
| 122 |
try: |
| 123 |
ra, dec = resolver.getPositionFor(identifier) |
| 124 |
except KeyError: |
| 125 |
if logUnknowns: |
| 126 |
base.ui.notifyInfo("Identifier did not resolve: %s"%identifier) |
| 127 |
if not ignoreUnknowns: |
| 128 |
raise base.Error("resolveObject could not resolve object" |
| 129 |
" %s."%identifier) |
| 130 |
vars["simbadAlpha"] = ra |
| 131 |
vars["simbadDelta"] = dec |
| 132 |
</code> |
| 133 |
</procDef> |
| 134 |
|
| 135 |
<procDef type="apply" id="mapValue"> |
| 136 |
<doc><![CDATA[ |
| 137 |
is an apply proc that translates values via a utils.NameMap |
| 138 |
|
| 139 |
Destination may of course be the source field (though that messes |
| 140 |
up idempotency of macro expansion, which shouldn't usually hurt). |
| 141 |
|
| 142 |
The format of the mapping file is:: |
| 143 |
|
| 144 |
<target key><tab><source keys> |
| 145 |
|
| 146 |
where source keys is a whitespace-seperated list of values that should |
| 147 |
be mapped to target key (sorry the sequence's a bit unusual). |
| 148 |
|
| 149 |
A source key must be encoded quoted-printable. This usually doesn't |
| 150 |
matter except when it contains whitespace (a blank becomes =20) or equal |
| 151 |
signs (which become =3D). |
| 152 |
|
| 153 |
Here's an example application for a filter that's supposed to translate |
| 154 |
some botched object names:: |
| 155 |
|
| 156 |
<apply name="cleanObject" procDef="//procs#mapValue"> |
| 157 |
<bind name="destination">"cleanedObject"</bind> |
| 158 |
<bind name="failuresMapThrough">True</bind> |
| 159 |
<bind name="value">@preObject</bind> |
| 160 |
<bind name="sourceName">"flashheros/res/namefixes.txt"</bind> |
| 161 |
</apply> |
| 162 |
|
| 163 |
The input could look like this, with a Tab char written as " <TAB> " |
| 164 |
for clarity:: |
| 165 |
|
| 166 |
alp Cyg <TAB> aCyg alphaCyg |
| 167 |
Nova Cygni 1992 <TAB> Nova=20Cygni=20'92 Nova=20Cygni |
| 168 |
]]></doc> |
| 169 |
<setup> |
| 170 |
<par key="destination" description="name of the field the mapped |
| 171 |
value should be written into"/> |
| 172 |
<par key="logFailures" description="Log non-resolved names?">False</par> |
| 173 |
<par key="failuresAreNone" description="Rather than raise an error, |
| 174 |
yield NULL for values not in the mapping">False</par> |
| 175 |
<par key="failuresMapThrough" description="Rather than raise an error, |
| 176 |
yield the input value if it is not in the mapping (this is for |
| 177 |
'fix some'-like functions and only works when failureAreNone is False)" |
| 178 |
>False</par> |
| 179 |
<par key="sourceName" description="An inputsDir-relative path to |
| 180 |
the NameMap source file."/> |
| 181 |
<par key="value" late="True" description="The value to be mapped."/> |
| 182 |
<code> |
| 183 |
map = utils.NameMap(os.path.join( |
| 184 |
base.getConfig("inputsDir"), sourceName)) |
| 185 |
</code> |
| 186 |
</setup> |
| 187 |
<code> |
| 188 |
try: |
| 189 |
vars[destination] = map.resolve(str(value)) |
| 190 |
except KeyError: |
| 191 |
if logFailures: |
| 192 |
base.ui.notifyWarning("Name %s could not be mapped\n"%value) |
| 193 |
if failuresAreNone: |
| 194 |
vars[destination] = None |
| 195 |
elif failuresMapThrough: |
| 196 |
vars[destination] = value |
| 197 |
else: |
| 198 |
raise base.LiteralParseError(destination, value, |
| 199 |
hint="It's not in the keys of the underlying map, which are: "+ |
| 200 |
(" ".join(map.namesDict))) |
| 201 |
</code> |
| 202 |
</procDef> |
| 203 |
|
| 204 |
<procDef type="apply" id="fullQuery"> |
| 205 |
<doc><![CDATA[ |
| 206 |
runs a free query against the data base and enters the first result |
| 207 |
record into vars. |
| 208 |
|
| 209 |
locals() will be passed as data, so you can define more bindings |
| 210 |
and refer to their keys in the query. |
| 211 |
]]></doc> |
| 212 |
<setup> |
| 213 |
<par key="query" description="an SQL query"/> |
| 214 |
<par key="errCol" description="a column name to use when raising a |
| 215 |
ValidationError on failure." |
| 216 |
>'<unknown>'</par> |
| 217 |
</setup> |
| 218 |
<code> |
| 219 |
with base.getTableConn() as conn: |
| 220 |
cursor = conn.query(query, locals()) |
| 221 |
keys = [f[0] for f in cursor.description] |
| 222 |
res = list(cursor) |
| 223 |
if not res: |
| 224 |
raise base.ValidationError("Could not find a matching row", |
| 225 |
errCol) |
| 226 |
vars.update(dict(zip(keys, res[0]))) |
| 227 |
</code> |
| 228 |
</procDef> |
| 229 |
|
| 230 |
<procDef type="apply" id="dictMap"> |
| 231 |
<doc> |
| 232 |
Maps input values through a dictionary. |
| 233 |
|
| 234 |
The dictionary is given in its python form here. This apply |
| 235 |
only operates on the rawdict, i.e., the value in vars is changed, |
| 236 |
while nothing is changed in the rowdict. |
| 237 |
</doc> |
| 238 |
<setup> |
| 239 |
<par key="mapping" description="Python dictionary literal giving |
| 240 |
the mapping"/> |
| 241 |
<par key="default" description="Default value for missing keys. |
| 242 |
Leave this at ``KeyError`` to raise an error. Set it to |
| 243 |
``base.NotGiven`` to make DaCHS retain unmapped values when |
| 244 |
they don't appear in the mapping.">KeyError</par> |
| 245 |
<par key="key" description="Name of the input key to map"/> |
| 246 |
<code> |
| 247 |
def doTheMap(vars): |
| 248 |
newVal = mapping.get(vars[key], default) |
| 249 |
|
| 250 |
if newVal is KeyError: |
| 251 |
raise base.ValidationError("dictMap saw %s, which it was" |
| 252 |
" not prepared to see."%repr(vars[key]), |
| 253 |
colName=key, |
| 254 |
hint="This dictMap knows the keys %s"%mapping.keys()) |
| 255 |
elif newVal is base.NotGiven: |
| 256 |
newVal = vars[key] |
| 257 |
|
| 258 |
vars[key] = newVal |
| 259 |
</code> |
| 260 |
</setup> |
| 261 |
<code> |
| 262 |
doTheMap(vars) |
| 263 |
</code> |
| 264 |
</procDef> |
| 265 |
|
| 266 |
|
| 267 |
<procDef id="expandIntegers" type="rowfilter"> |
| 268 |
<doc> |
| 269 |
A row processor that produces copies of rows based on integer indices. |
| 270 |
|
| 271 |
The idea is that sometimes rows have specifications like "Star 10 |
| 272 |
through Star 100". These are a pain if untreated. A RowExpander |
| 273 |
could create 90 individual rows from this. |
| 274 |
</doc> |
| 275 |
<setup> |
| 276 |
<par key="startName" description="column containing the start value"/> |
| 277 |
<par key="endName" description="column containing the end value"/> |
| 278 |
<par key="indName" description="name the counter should appear under"/> |
| 279 |
</setup> |
| 280 |
<code> |
| 281 |
try: |
| 282 |
lowerInd = int(row[startName]) |
| 283 |
upperInd = int(row[endName]) |
| 284 |
except (ValueError, TypeError): # either one not given |
| 285 |
yield row |
| 286 |
return |
| 287 |
for ind in range(lowerInd, upperInd+1): |
| 288 |
newRow = row.copy() |
| 289 |
newRow[indName] = ind |
| 290 |
yield newRow |
| 291 |
</code> |
| 292 |
</procDef> |
| 293 |
|
| 294 |
|
| 295 |
<procDef id="expandDates" type="rowfilter"> |
| 296 |
<deprecated> |
| 297 |
Since this is probably only use useful with inputDDs, we will |
| 298 |
probably remove this soon unless you protest. |
| 299 |
</deprecated> |
| 300 |
<doc> |
| 301 |
is a row generator to expand time ranges. |
| 302 |
|
| 303 |
The finished dates are left in destination as datetime.datetime |
| 304 |
instances |
| 305 |
</doc> |
| 306 |
<setup> |
| 307 |
<par key="dest" description="name of the column the time should |
| 308 |
appear in">'curTime'</par> |
| 309 |
<par key="start" description="the start date(time), as either |
| 310 |
a datetime object or a column ref"/> |
| 311 |
<par key="end" description="the end date(time)"/> |
| 312 |
<par key="hrInterval" late="True" description="difference |
| 313 |
between generated timestamps in hours">24</par> |
| 314 |
<code> |
| 315 |
def _parseTime(val, fieldName): |
| 316 |
try: |
| 317 |
val = val |
| 318 |
if isinstance(val, datetime.datetime): |
| 319 |
return val |
| 320 |
elif isinstance(val, datetime.date): |
| 321 |
return datetime.datetime(val.year, val.month, val.day) |
| 322 |
else: |
| 323 |
return utils.parseISODT(val) |
| 324 |
except Exception, msg: |
| 325 |
raise base.ValidationError("Bad date from %s (%s)"%(fieldName, |
| 326 |
unicode(msg)), dest) |
| 327 |
</code> |
| 328 |
</setup> |
| 329 |
<code><![CDATA[ |
| 330 |
stampTime = _parseTime(row[start], "start") |
| 331 |
endTime = _parseTime(row[end], "end") |
| 332 |
endTime = endTime+datetime.timedelta(hours=23) |
| 333 |
|
| 334 |
try: |
| 335 |
interval = float(hrInterval) |
| 336 |
except ValueError: |
| 337 |
raise base.ValidationError("Not a time interval: '%s'"%hrInterval, |
| 338 |
"hrInterval") |
| 339 |
if interval<0.01: |
| 340 |
interval = 0.01 |
| 341 |
interval = datetime.timedelta(hours=interval) |
| 342 |
|
| 343 |
try: |
| 344 |
matchLimit = 100000 #getQueryMeta()["dbLimit"] |
| 345 |
except ValueError: |
| 346 |
matchLimit = 1000000 |
| 347 |
while stampTime<=endTime: |
| 348 |
matchLimit -= 1 |
| 349 |
if matchLimit<0: |
| 350 |
break |
| 351 |
newRow = row.copy() |
| 352 |
newRow[dest] = stampTime |
| 353 |
yield newRow |
| 354 |
stampTime = stampTime+interval |
| 355 |
]]></code> |
| 356 |
</procDef> |
| 357 |
|
| 358 |
|
| 359 |
<procDef id="expandComma" type="rowfilter"> |
| 360 |
<doc> |
| 361 |
A row generator that reads comma separated values from a |
| 362 |
field and returns one row with a new field for each of them. |
| 363 |
</doc> |
| 364 |
<setup> |
| 365 |
<par key="srcField" description="Name of the column containing |
| 366 |
the full string"/> |
| 367 |
<par key="destField" description="Name of the column the individual |
| 368 |
columns are written to"/> |
| 369 |
</setup> |
| 370 |
<code> |
| 371 |
src = row[srcField] |
| 372 |
if src is not None and src.strip(): |
| 373 |
for item in src.split(","): |
| 374 |
item = item.strip() |
| 375 |
if not item: |
| 376 |
continue |
| 377 |
newRow = row.copy() |
| 378 |
newRow[destField] = item |
| 379 |
yield newRow |
| 380 |
</code> |
| 381 |
</procDef> |
| 382 |
|
| 383 |
|
| 384 |
<!--############################################################ |
| 385 |
Core phrase makers and friends --> |
| 386 |
|
| 387 |
<procDef id="makeRangeQuery" type="phraseMaker"> |
| 388 |
<doc> |
| 389 |
A phraseMaker that makes a pair of inputKeys into a range query, |
| 390 |
possibly half-open. |
| 391 |
|
| 392 |
The name of the column queried can be passed in the late parameter |
| 393 |
colName; the default is the name of the first inputKey minus the |
| 394 |
last four characters. This looks weird but complements the |
| 395 |
rangeCondDesc stream below. |
| 396 |
</doc> |
| 397 |
<setup> |
| 398 |
<par key="colName" late="True" description="The name of the column queried |
| 399 |
against">inputKeys[0].name[:-4]</par> |
| 400 |
</setup> |
| 401 |
<code><![CDATA[ |
| 402 |
minKey, maxKey = inputKeys |
| 403 |
minVal, maxVal = inPars.get(minKey.name), inPars.get(maxKey.name) |
| 404 |
if minVal is None: |
| 405 |
yield "%s<=%%(%s)s"%(colName, |
| 406 |
base.getSQLKey(maxKey.name, maxVal, outPars)) |
| 407 |
elif maxVal is None: |
| 408 |
yield "%s>=%%(%s)s"%(colName, |
| 409 |
base.getSQLKey(minKey.name, minVal, outPars)) |
| 410 |
else: |
| 411 |
yield "%s BETWEEN %%(%s)s AND %%(%s)s"%(colName, |
| 412 |
base.getSQLKey(minKey.name, minVal, outPars), |
| 413 |
base.getSQLKey(maxKey.name, maxVal, outPars)) |
| 414 |
]]></code> |
| 415 |
</procDef> |
| 416 |
|
| 417 |
<STREAM id="rangeCond"> |
| 418 |
<doc> |
| 419 |
A condDesc that expresses a range and has an InputKey each for min |
| 420 |
and max. |
| 421 |
|
| 422 |
Specify the following macros when replaying: |
| 423 |
|
| 424 |
* name -- the column name in the core's queried table |
| 425 |
* groupdesc -- a terse phrase describing the range. This will be |
| 426 |
used in the description of both the input keys and the group |
| 427 |
* grouplabel -- a label (include the unit, it is not taken from InputKey) |
| 428 |
written in front of the form group |
| 429 |
|
| 430 |
groupdesc has to work after "Range of", "Lower bound of", and |
| 431 |
"Upper bound of". Do not include a concluding period. |
| 432 |
</doc> |
| 433 |
|
| 434 |
<condDesc combining="True" joiner="AND"> |
| 435 |
<inputKey name="\name\+_min" original="\name" |
| 436 |
tablehead="Min \grouplabel" |
| 437 |
description="Lower bound of \groupdesc"> |
| 438 |
<property name="cssClass">formkey_min</property> |
| 439 |
</inputKey> |
| 440 |
<inputKey name="\name\+_max" original="\name" |
| 441 |
tablehead="Max \grouplabel" |
| 442 |
description="Upper bound of \groupdesc"> |
| 443 |
<property name="cssClass">formkey_max</property> |
| 444 |
</inputKey> |
| 445 |
<group name="mf\name"> |
| 446 |
<description>Range of \groupdesc. If you only specify one bound, |
| 447 |
you get a half-infinite interval.</description> |
| 448 |
<property name="label">\grouplabel</property> |
| 449 |
<property name="style">compact</property> |
| 450 |
</group> |
| 451 |
<phraseMaker procDef="//procs#makeRangeQuery"/> |
| 452 |
</condDesc> |
| 453 |
</STREAM> |
| 454 |
|
| 455 |
<STREAM id="negatableBoolean"> |
| 456 |
<doc> |
| 457 |
A condDesc over a boolean column. |
| 458 |
|
| 459 |
By default, DaCHS does not distinguish between False and NULL when |
| 460 |
auto-generating input keys from boolean columns. That is, you can |
| 461 |
check a checkbox and will get everything where the column is |
| 462 |
true. If you do not check it, however, you will get everything, i.e., |
| 463 |
rows in which the column is any of NULL, True, or False. That's pretty |
| 464 |
much the semantics of HTML checkboxes. |
| 465 |
|
| 466 |
However, when you want people to be able to explicitly say “this should |
| 467 |
be off“, you need to be a bit more cunning. That is what this |
| 468 |
stream does; when you have a boolean column ``my_bool``, you can |
| 469 |
have:: |
| 470 |
|
| 471 |
<FEED source="//procs#negatableBoolean" column="my_bool"/> |
| 472 |
|
| 473 |
next to your other condDescs in the dbCore. This will then |
| 474 |
produce a three-way selection between Yes, No, and ANY. |
| 475 |
</doc> |
| 476 |
|
| 477 |
<condDesc> |
| 478 |
<inputKey original="\column" type="text" required="False" |
| 479 |
multiplicity="single"> |
| 480 |
<values> |
| 481 |
<option>Yes</option> |
| 482 |
<option>No</option> |
| 483 |
</values> |
| 484 |
</inputKey> |
| 485 |
<phraseMaker> |
| 486 |
<code> |
| 487 |
colName = inputKeys[0].name |
| 488 |
val = inPars[colName] |
| 489 |
if val=="No": |
| 490 |
yield f"NOT {colName}" |
| 491 |
elif val=="Yes": |
| 492 |
yield f"{colName}" |
| 493 |
# Fall though: Ignore the input (that includes the ANY option) |
| 494 |
</code> |
| 495 |
</phraseMaker> |
| 496 |
</condDesc> |
| 497 |
|
| 498 |
</STREAM> |
| 499 |
|
| 500 |
|
| 501 |
<!-- #################################### |
| 502 |
licenses and top-level streams --> |
| 503 |
|
| 504 |
<STREAM id="license-cc0"> |
| 505 |
<doc> |
| 506 |
Include this stream with a @what (a short phrase saying what |
| 507 |
is released) to make your resource released under Creative |
| 508 |
Commons-0 (a.k.a. public domain). This will generate the |
| 509 |
rights and rightsURI metadata items. It needs to live in the |
| 510 |
toplevel /resource element. |
| 511 |
|
| 512 |
Example:: |
| 513 |
|
| 514 |
<FEED source="//procs#license-cc0" what="the HSOY catalogue"/> |
| 515 |
</doc> |
| 516 |
<meta name="rights" format="rst">\\RSTcc0{\what}</meta> |
| 517 |
<meta name="rights.rightsURI" |
| 518 |
>https://spdx.org/licenses/CC0-1.0.html</meta> |
| 519 |
</STREAM> |
| 520 |
|
| 521 |
<STREAM id="license-cc-by"> |
| 522 |
<doc> |
| 523 |
Include this stream with a @what (a short phrase saying what |
| 524 |
is licensed) to make your resource licensed under Creative |
| 525 |
Commons Attribution (CC-BY). This will generate the |
| 526 |
rights and rightsURI metadata items. It needs to live in the |
| 527 |
toplevel /resource element. |
| 528 |
|
| 529 |
Example:: |
| 530 |
|
| 531 |
<FEED source="//procs#license-cc-by" what="the HSOY catalogue"/> |
| 532 |
</doc> |
| 533 |
<meta name="rights" format="rst">\\RSTccby{\what}</meta> |
| 534 |
<meta name="rights.rightsURI" |
| 535 |
>https://spdx.org/licenses/CC-BY-4.0.html</meta> |
| 536 |
</STREAM> |
| 537 |
|
| 538 |
<STREAM id="license-cc-by-sa"> |
| 539 |
<doc> |
| 540 |
Include this stream with a @what (a short phrase saying what |
| 541 |
is licensed) to make your resource licensed under Creative |
| 542 |
Commons Attribution Share Alike (CC-BY-SA). This will generate |
| 543 |
the rights and rightsURI metadata items. It needs |
| 544 |
to live in the toplevel /resource element. |
| 545 |
|
| 546 |
Example:: |
| 547 |
|
| 548 |
<FEED source="//procs#license-cc-by-sa" what="the HSOY catalogue"/> |
| 549 |
</doc> |
| 550 |
<meta name="rights" format="rst">\\RSTccbysa{\what}</meta> |
| 551 |
<meta name="rights.rightsURI" |
| 552 |
>https://spdx.org/licenses/CC-BY-SA-4.0.html</meta> |
| 553 |
</STREAM> |
| 554 |
|
| 555 |
|
| 556 |
<!-- ############################# |
| 557 |
Streams for table management and such --> |
| 558 |
|
| 559 |
<NXSTREAM id="declare-indexes-from"> |
| 560 |
<doc> |
| 561 |
Tells DaCHS to copy the index declarations from tables a view |
| 562 |
derives from (meaning; feeding this probably does not make any sense |
| 563 |
outside of a view declaration). |
| 564 |
|
| 565 |
Since DaCHS does not have a good way to guess which tables you derive from |
| 566 |
(in the end), you have to give blank-separated RD#id references to them in |
| 567 |
the sourceTables attribute. |
| 568 |
|
| 569 |
The proc will declare all indexes over columns that appear to be in the |
| 570 |
View (by name). That's a rough heuristics which works in most cases. If |
| 571 |
it doesn't work for you, you can always declare the indexes manually. |
| 572 |
|
| 573 |
Note that this will only see columns that are declared lexically |
| 574 |
before the FEED; you will thus typically want to include this at |
| 575 |
the end of the view definition. |
| 576 |
|
| 577 |
Example:: |
| 578 |
|
| 579 |
<FEED source="//procs#declare-indexes-from" |
| 580 |
sourceTables="res1/q#table1 res14#othertable"/> |
| 581 |
</doc> |
| 582 |
<LOOP> |
| 583 |
<codeItems> |
| 584 |
from gavo import rscdef |
| 585 |
|
| 586 |
for td in [ |
| 587 |
context.resolveId(otherId, forceType=rscdef.TableDef) |
| 588 |
for otherId in \quote{\sourceTables}.split()]: |
| 589 |
for index in td.indices: |
| 590 |
for colName in index.columns: |
| 591 |
if colName not in context.replayTarget.columns: |
| 592 |
break |
| 593 |
else: |
| 594 |
# All columns in the index are seen in the view: yield |
| 595 |
# the index metadata |
| 596 |
if not index.columns: |
| 597 |
from gavo import base |
| 598 |
base.ui.notifyWarning( |
| 599 |
f"While copying indexes from {td.getFullId()}: Index" |
| 600 |
f" {index.name} has no columns. Ignoring.") |
| 601 |
continue |
| 602 |
|
| 603 |
yield { |
| 604 |
"columns": ",".join(index.columns), |
| 605 |
"kind": index.kind, |
| 606 |
"metaOnly": "True", |
| 607 |
} |
| 608 |
</codeItems> |
| 609 |
<events> |
| 610 |
<index columns="\\columns" kind="\\kind" metaOnly="True"/> |
| 611 |
</events> |
| 612 |
</LOOP> |
| 613 |
</NXSTREAM> |
| 614 |
|
| 615 |
|
| 616 |
<STREAM id="witherror"> |
| 617 |
<doc><![CDATA[ |
| 618 |
Declare a column and an error on that column. |
| 619 |
|
| 620 |
The idea is that you write something like:: |
| 621 |
|
| 622 |
<FEED source="//procs#witherror |
| 623 |
name="rv" type="double precision" |
| 624 |
unit="km/s" ucd="spect.dopplerVeloc" |
| 625 |
tablehead="RV_S" |
| 626 |
description="Radial velocity derived by the Serval pipeline" |
| 627 |
verbLevel="1"/> |
| 628 |
|
| 629 |
and you get a reasonably defined column err_<name> for almost |
| 630 |
free. Plus, if one day we have proper annotation for value/error |
| 631 |
pairs, DaCHS will spit that out, too. |
| 632 |
|
| 633 |
This stream has the common attributes of column as parameters: |
| 634 |
name, type, unit, ucd, tablehead, description, and verbLevel. |
| 635 |
Errors are always verbLevel at this point. The minimum you have to |
| 636 |
define is name and description. |
| 637 |
]]></doc> |
| 638 |
<DEFAULTS type="real" ucd="" unit="" tablehead="" verbLevel="15"/> |
| 639 |
<column name="\name" type="\type" |
| 640 |
unit="\unit" ucd="\ucd" |
| 641 |
tablehead="\tablehead" |
| 642 |
description="\description" |
| 643 |
verbLevel="\verbLevel"/> |
| 644 |
<column name="err_\name" type="real" |
| 645 |
unit="\unit" ucd="\if{\ucd}{stat.error;\ucd}" |
| 646 |
tablehead="\if{\tablehead}{Err. \tablehead}" |
| 647 |
description="Uncertainty in \name" |
| 648 |
verbLevel="30"/> |
| 649 |
</STREAM> |
| 650 |
|
| 651 |
</resource> |