Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/schema/metadata.py: 100%
293 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-14 02:13 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-14 02:13 +0000
1from marshmallow import Schema, fields, validate
3from daiquiri.core.schema.validators import ValidatedRegexp, OneOf
6# Helper to paginate a schema
7def paginated(schema):
8 class PaginatedSchema(Schema):
9 total = fields.Int()
10 rows = fields.Nested(schema, many=True)
12 cls_name = f"Paginated<{schema.__name__}>"
13 PaginatedSchema.__name__ = cls_name
14 PaginatedSchema.__qualname__ = cls_name
16 return PaginatedSchema
19# Users
20class UserSchema(Schema):
21 user = fields.Str()
22 personid = fields.Int()
23 login = fields.Str()
24 permissions = fields.List(fields.Str())
25 groups = fields.List(fields.Str())
26 fullname = fields.Str()
27 givenname = fields.Str()
28 familyname = fields.Str()
29 is_staff = fields.Bool()
32class UserCacheSchema(Schema):
33 cache = fields.Dict()
36# Proposals
37class ProposalSchema(Schema):
38 proposalid = fields.Int()
39 proposal = fields.Str()
40 start = fields.DateTime()
41 title = fields.Str()
42 visits = fields.Int()
45# Visits
46class SessionSchema(Schema):
47 blsessionid = fields.Int()
48 proposalid = fields.Int()
49 session = fields.Str()
50 startdate = fields.DateTime()
51 enddate = fields.DateTime()
52 proposal = fields.Str()
53 beamlinename = fields.Str()
54 active = fields.Bool()
56 class Meta:
57 datetimeformat = "%d-%m-%Y %H:%M"
60# Components
61class NewComponentSchema(Schema):
62 name = ValidatedRegexp(
63 "word-dash-space",
64 metadata={"title": "Name"},
65 validate=validate.Length(max=255),
66 required=True,
67 )
68 acronym = ValidatedRegexp(
69 "word-dash",
70 metadata={"title": "Acronym"},
71 validate=validate.Length(max=45),
72 required=True,
73 )
74 molecularmass = fields.Float(metadata={"title": "Mass", "unit": "Da"})
75 density = fields.Float(metadata={"title": "Density", "unit": "kg/m3"})
76 sequence = ValidatedRegexp(
77 "smiles", metadata={"title": "SMILES", "description": "Chemical composition"}
78 )
80 class Meta:
81 uiorder = ["name", "acronym", "molecularmass", "density", "sequence"]
84class ComponentSchema(NewComponentSchema):
85 componentid = fields.Int()
86 name = ValidatedRegexp("word-dash-space", metadata={"title": "Name"})
87 acronym = ValidatedRegexp(
88 "word-dash",
89 metadata={"title": "Acronym", "description": "A short name for the component"},
90 )
91 samples = fields.Int()
92 datacollections = fields.Int()
95# Samples
96class NewSampleSchema(Schema):
97 name = ValidatedRegexp(
98 "word-dash",
99 metadata={"title": "Name"},
100 validate=validate.Length(max=100),
101 required=True,
102 )
103 # FIXME: Name length is not consistent with the size found in ispyb (100)
104 offsetx = fields.Int(metadata={"title": "X Offset"}, dump_default=0)
105 offsety = fields.Int(metadata={"title": "Y Offset"}, dump_default=0)
106 positions = fields.Dict(keys=fields.Str(), values=fields.Float())
107 componentid = fields.Int(metadata={"title": "Component"})
108 comments = ValidatedRegexp(
109 "word-special",
110 metadata={"title": "Comments"},
111 validate=validate.Length(max=1024),
112 allow_none=True,
113 )
115 class Meta:
116 uiorder = ["componentid", "name", "offsetx", "offsety", "comments", "positions"]
117 uischema = {
118 "positions": {"classNames": "hidden-row", "ui:widget": "hidden"},
119 "offsetx": {"classNames": "hidden-row", "ui:widget": "hidden"},
120 "offsety": {"classNames": "hidden-row", "ui:widget": "hidden"},
121 "componentid": {
122 "ui:widget": "connectedSelect",
123 "ui:options": {
124 "selector": "components",
125 "key": "acronym",
126 "value": "componentid",
127 },
128 },
129 }
132class SampleSchema(NewSampleSchema):
133 name = ValidatedRegexp("word-dash", metadata={"title": "Name"})
134 offsetx = fields.Int(metadata={"title": "X Offset"})
135 offsety = fields.Int(metadata={"title": "Y Offset"})
136 sampleid = fields.Int()
137 component = fields.Str()
138 subsamples = fields.Int()
139 datacollections = fields.Int()
140 queued = fields.Bool()
141 extrametadata = fields.Dict(
142 keys=ValidatedRegexp("word-dash"),
143 metadata={"title": "Metadata", "propertyNames": {"pattern": "^[A-z0-9-]+$"}},
144 )
146 class Meta:
147 uischema = {
148 "componentid": {
149 "ui:widget": "connectedSelect",
150 "ui:options": {
151 "selector": "components",
152 "key": "acronym",
153 "value": "componentid",
154 },
155 },
156 }
159class NewSubSampleSchema(Schema):
160 sampleid = fields.Int(required=True)
161 name = ValidatedRegexp("word-dash-space", metadata={"title": "Name"})
162 type = OneOf(["roi", "poi", "loi"], metadata={"title": "Type"})
163 source = OneOf(
164 ["manual", "auto", "reference"],
165 metadata={"title": "Source"},
166 dump_default="manual",
167 )
168 comments = ValidatedRegexp(
169 "word-special", metadata={"title": "Comments"}, allow_none=True
170 )
171 x = fields.Int()
172 y = fields.Int()
173 x2 = fields.Int()
174 y2 = fields.Int()
175 positions = fields.Dict(keys=fields.Str(), values=fields.Float())
178class SubSampleSchema(NewSubSampleSchema):
179 sampleid = fields.Int()
180 sample = fields.Str()
181 subsampleid = fields.Int()
182 datacollections = fields.Int()
183 queued = fields.Bool()
184 extrametadata = fields.Dict(
185 keys=ValidatedRegexp("word-dash"),
186 metadata={"title": "Metadata", "propertyNames": {"pattern": "^[A-z0-9-]+$"}},
187 )
190class SampleTags(Schema):
191 tags = fields.List(fields.Str())
194class NewSampleImageSchema(Schema):
195 sampleid = fields.Int(required=True)
196 offsetx = fields.Int()
197 offsety = fields.Int()
198 scalex = fields.Float()
199 scaley = fields.Float()
200 rotation = fields.Float()
201 positions = fields.Dict(keys=fields.Str(), values=fields.Float())
204class SampleImageSchema(NewSampleImageSchema):
205 sampleimageid = fields.Int()
206 sampleid = fields.Int()
207 url = fields.Str()
208 positions = fields.Dict(keys=fields.Str(), values=fields.Float())
209 width = fields.Int()
210 height = fields.Int()
213class NewSampleActionPositionSchema(Schema):
214 sampleactionid = fields.Int(required=True)
215 posx = fields.Int(required=True)
216 posy = fields.Int(required=True)
217 type = OneOf(["reference", "real"], required=True)
218 id = fields.Int(required=True)
221class SampleActionPositionSchema(NewSampleActionPositionSchema):
222 sampleactionpositionid = fields.Int()
225class SampleActionSchema(Schema):
226 sampleactionid = fields.Int()
227 actiontype = fields.Str()
228 status = fields.Str()
229 message = fields.Str()
230 positions = fields.List(fields.Nested(SampleActionPositionSchema))
231 has_result = fields.Bool()
234# Datacollections
235class DataCollectionSchema(Schema):
236 sessionid = fields.Int()
237 datacollections = fields.Int()
238 datacollectionid = fields.Int(required=True)
239 datacollectiongroupid = fields.Int()
240 sampleid = fields.Int()
241 sample = fields.Str()
242 subsampleid = fields.Int()
243 starttime = fields.DateTime()
244 datacollectionplanid = fields.Int()
245 endtime = fields.DateTime()
246 duration = fields.Int()
247 experimenttype = fields.Str()
248 datacollectionnumber = fields.Int()
249 runstatus = fields.Str()
251 # Paths
252 filetemplate = fields.Str()
253 imagedirectory = fields.Str()
255 # DC Params
256 exposuretime = fields.Float()
257 wavelength = fields.Float()
258 transmission = fields.Float()
259 numberofimages = fields.Float()
260 numberofpasses = fields.Int()
262 # Beam position and size
263 xbeam = fields.Float()
264 ybeam = fields.Float()
265 beamsizeatsamplex = fields.Float()
266 beamsizeatsampley = fields.Float()
268 # Gridinfo columns
269 steps_x = fields.Int()
270 steps_y = fields.Int()
271 dx_mm = fields.Float()
272 dy_mm = fields.Float()
273 patchesx = fields.Int()
274 patchesy = fields.Int()
276 # Snapshots
277 snapshots = fields.Dict(keys=fields.Str(), values=fields.Bool())
279 comments = fields.Str(metadata={"title": "Comments"})
281 class Meta:
282 datetimeformat = "%d-%m-%Y %H:%M:%S"
285class DataCollectionAttachmentSchema(Schema):
286 datacollectionfileattachmentid = fields.Int()
287 dataCollectionid = fields.Int()
288 filename = fields.Str()
289 filetype = fields.Str()
292class NewDataCollectionPlanSchema(Schema):
293 sampleid = fields.Int(required=True)
294 experimentkind = fields.Str()
295 energy = fields.Float()
296 exposuretime = fields.Float()
297 planorder = fields.Int()
298 scanparameters = fields.Dict(required=True)
301class DataCollectionPlanSchema(NewDataCollectionPlanSchema):
302 datacollectionplanid = fields.Int()
303 timestamp = fields.DateTime()
304 sampleid = fields.Int()
305 subsampleid = fields.Int()
306 sample = fields.Str()
307 component = fields.Str()
308 subsampleid = fields.Int()
309 datacollectionid = fields.Int()
310 containerqueuesampleid = fields.Int()
311 queued = fields.Bool()
312 status = fields.Str()
313 linked = fields.Bool()
314 scanparameters = fields.Dict()
317class ScanQualityIndicatorsSchema(Schema):
318 point = fields.List(fields.Int(), metadata={"description": "Scan point"})
319 total = fields.List(fields.Float(), metadata={"description": "Total signal"})
320 spots = fields.List(fields.Int(), metadata={"description": "Number of spots"})
321 autoprocprogramid = fields.List(fields.Int())
324# XRF Maps
325class NewXRFMapSchema(Schema):
326 maproiid = fields.Int(required=True, metadata={"description": "The roiid"})
327 subsampleid = fields.Int(
328 required=True, metadata={"description": "Object this map relates to"}
329 )
330 datacollectionid = fields.Int(required=True)
333class XRFMapHistogramSchema(Schema):
334 bins = fields.List(fields.Float())
335 hist = fields.List(fields.Float())
336 width = fields.List(fields.Float())
339class XRFMapSchema(NewXRFMapSchema):
340 maproiid = fields.Int(metadata={"description": "The roiid"})
341 subsampleid = fields.Int(metadata={"description": "Object this map relates to"})
342 datacollectionid = fields.Int()
343 datacollectiongroupid = fields.Int()
344 datacollectionnumber = fields.Int()
345 mapid = fields.Int(metadata={"description": "The id of the map"})
346 sampleid = fields.Int()
347 w = fields.Int(metadata={"description": "Width of the map"})
348 h = fields.Int(metadata={"description": "Height of the map"})
349 snaked = fields.Bool(
350 metadata={
351 "description": "Whether the map is collected interleaved left to right"
352 }
353 )
354 orientation = fields.Str(
355 metadata={
356 "description": "Wehther the map is collected horizontally or vertically"
357 }
358 )
359 element = fields.Str()
360 edge = fields.Str()
361 scalar = fields.Str()
362 composites = fields.Int()
364 points = fields.Int(metadata={"description": "Number of completed points"})
366 opacity = fields.Float()
367 min = fields.Float()
368 max = fields.Float()
369 colourmap = fields.String()
370 scale = fields.String()
371 autoscale = fields.Bool()
373 url = fields.Str()
376class XRFMapHistogramSchema(Schema):
377 mapid = fields.Int()
378 histogram = fields.Nested(
379 XRFMapHistogramSchema, metadata={"description": "Histogram of the map points"}
380 )
383class XRFMapValueSchema(Schema):
384 mapid = fields.Int()
385 x = fields.Int()
386 y = fields.Int()
387 value = fields.Float()
390# XRF Composite Maps
391class NewXRFCompositeMapSchema(Schema):
392 subsampleid = fields.Int(
393 required=True, metadata={"description": "Object this map relates to"}
394 )
395 r = fields.Int(required=True)
396 g = fields.Int(required=True)
397 b = fields.Int(required=True)
398 ropacity = fields.Float()
399 gopacity = fields.Float()
400 bopacity = fields.Float()
403class XRFCompositeMapSchema(NewXRFCompositeMapSchema):
404 compositeid = fields.Int(metadata={"description": "The id of the composite map"})
405 subsampleid = fields.Int()
406 sampleid = fields.Int()
407 opacity = fields.Float()
408 r = fields.Int()
409 g = fields.Int()
410 b = fields.Int()
411 rroi = fields.Str()
412 groi = fields.Str()
413 broi = fields.Str()
415 url = fields.Str()
418# XRF Map ROIs
419class NewXRFMapROISchema(Schema):
420 sampleid = fields.Int(
421 required=True, metadata={"title": "Sample ROI is associated to"}
422 )
423 element = ValidatedRegexp(
424 "word-dash",
425 required=True,
426 metadata={"title": "Element"},
427 validate=validate.Length(max=2),
428 )
429 edge = ValidatedRegexp(
430 "word-dash",
431 required=True,
432 metadata={"title": "Edge"},
433 validate=validate.Length(max=3),
434 )
435 start = fields.Float(
436 required=True,
437 metadata={"title": "Start", "description": "Start Energy of ROI", "unit": "eV"},
438 )
439 end = fields.Float(
440 required=True,
441 metadata={"title": "End", "description": "End Energy of ROI", "unit": "eV"},
442 )
444 class Meta:
445 uiorder = ["element", "edge", "start", "end", "sampleid"]
446 uischema = {"sampleid": {"classNames": "hidden-row", "ui:widget": "hidden"}}
449class XRFMapROISchema(NewXRFMapROISchema):
450 maproiid = fields.Int()
451 maps = fields.Int()
453 class Meta:
454 uiorder = ["maproiid", "element", "edge", "start", "end", "maps", "sampleid"]
455 uischema = {
456 "maproiid": {"classNames": "hidden-row", "ui:widget": "hidden"},
457 "maps": {"classNames": "hidden-row", "ui:widget": "hidden"},
458 "sampleid": {"classNames": "hidden-row", "ui:widget": "hidden"},
459 }
462# Auto Processing
463class AutoProcProgramSchema(Schema):
464 autoprocprogramid = fields.Int(required=True)
465 datacollectionid = fields.Int()
466 status = fields.Int()
467 message = fields.Str()
468 starttime = fields.DateTime()
469 endtime = fields.DateTime()
470 duration = fields.Int()
471 programs = fields.Str()
472 automatic = fields.Int()
473 warnings = fields.Int()
474 errors = fields.Int()
477class AutoProcProgramAttachmentSchema(Schema):
478 autoprocprogramattachmentid = fields.Int(required=True)
479 autoprocprogramid = fields.Int(required=True)
480 filetype = fields.Str()
481 filename = fields.Str()
482 filepath = fields.Str()
483 rank = fields.Int()
486class AutoProcProgramMessageSchema(Schema):
487 autoprocprogrammessageid = fields.Int(required=True)
488 autoprocprogramid = fields.Int(required=True)
489 timestamp = fields.DateTime()
490 severity = fields.Str()
491 message = fields.Str()
492 description = fields.Str()