VerityPy 1.1
Python library for Verity data profiling, quality control, remediation
optypes.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""
3Types for transform operation objects. Each operation category (OpCat)
4has one or more functions each of which is defined by an OpFunc object.
5
6Function setup_op_cats is a convenience method to make list
7transform_types which contains OpCat objects, each of which defines a category
8of transform operations (Ops), and contains a child list of OpFunc objects.
9"""
10
11__all__ = ['OpFunc', 'OpCat', 'setup_op_cats']
12__version__ = '1.1'
13__author__ = 'Geoffrey Malafsky'
14__email__ = 'gmalafsky@technikinterlytics.com'
15__date__ = '20240804'
16
17
18class OpFunc:
19 """
20 Function definition for defining transform operations.
21 This is intended to be used for the specification of available transform operations.
22 title: name of function such as ifEq
23 desc: description
24 param1req: true/false whether param1 is required to be set
25 param1typ: datatype of param1 if it is restricted to one type
26 param2req: true/false whether param2 is required to be set
27 param2typ: datatype of param2 if it is restricted to one type
28 param3req: true/false whether param3 is required to be set
29 param3typ: datatype of param3 if it is restricted to one type
30 """
31
32 title:str
33 desc:str
34 param1req: bool
35 param1typ: str
36 param2req: bool
37 param2typ: str
38 param3req: bool
39 param3typ: str
40
41 def __init__(self, title:str):
42 self.titletitle=title
43 self.descdesc=""
50
51
52class OpCat:
53 """
54 Category for transform operations grouped by either type of action performed
55 or datatype it is applied to. Categories include: assignment, conditional,
56 numeric, text, date. Member 'funcs' is a list of OpFunc objects.
57 """
58
59 category: str
60 funcs: list
61
62 def __init__(self, category:str):
63 self.categorycategory=category
64 self.funcsfuncs=[]
65
66
67def setup_op_cats() -> list:
68 """
69 Function to fill list with OpCat objects and for each their list of child OpFunc objects
70
71 Returns list of OpCat objects
72 """
73
74 transform_types:list=[]
75 try:
76 # ASSIGNMENT
77 oc = OpCat("assignment")
78 # --------
79 f = OpFunc("noOp")
80 f.desc= "No operation. Use to stop operations in conditional sequence."
81 oc.funcs.append(f)
82 # --------
83 f = OpFunc("setToValue")
84 f.desc= "Assign a fixed value. Param1: value"
85 f.param1req=True
86 f.param1typ="string"
87 oc.funcs.append(f)
88 # --------
89 f = OpFunc("setToIndex")
90 f.desc= "Assign a fixed value equal to the record's index in output set. "
91 f.desc += "Param1: optional as integer start index >=0. Default is 0. "
92 f.desc += "Application code must supply current record index to exectransform.do_transform. Default = 0. "
93 f.desc += "Assigned index = Param1 + current_record_index"
94 f.param1req=False
95 f.param1typ="int"
96 oc.funcs.append(f)
97 # --------
98 f=OpFunc("setToRef")
99 f.desc="Assigns the value of a referenced source field in the current record. Param1: title of field"
100 f.param1req=True
101 f.param1typ="string"
102 oc.funcs.append(f)
103 # --------
104 f=OpFunc("setToRandom")
105 f.desc = "Uses random number generator to produce a value scaled between the minimum and maximum values. "
106 f.desc += "Param1: optional as minimum. Default is 0. "
107 f.desc += "Param2: optional as maximum. Default is 1. If this is < min then set to min + 1. "
108 f.param1req=False
109 f.param1typ="real"
110 f.param2req=False
111 f.param2typ="real"
112 oc.funcs.append(f)
113 # --------
114 f=OpFunc("setToFreqList")
115 f.desc = "Applies a value from a list using relative frequencies of occurrence for a base value. "
116 f.desc += "Param1: relative frequencies of occurrence. Can use any real >0 and will be scaled to sum. "
117 f.desc += "Since list, enter delimited by pipe such as 2|7|.5|9 where the second list item "
118 f.desc += "occurs 37.8% percent (7/18.5) of the time. "
119 f.desc += "Param2: list of values correlated to Param1 frequencies and "
120 f.desc += "entered with pipe delimiter like red|green|blue|orange. "
121 f.desc += "Param3: optional. If used, either a reference field title to use as source of base value, or a real number 0.0-1.0 . "
122 f.desc += "Otherwise, the default is to use a random number."
123 f.param1req=True
124 f.param1typ="string"
125 f.param2req=True
126 f.param2typ="string"
127 f.param3req=False
128 f.param3typ="string"
129 oc.funcs.append(f)
130 # --------
131 f=OpFunc("lookup")
132 f.desc= "Assigns a value from a lookup list based on matching values to keys where keys can use wildcards. "\
133 "The match can be made to one, two, or three source fields in the record with field 1 always "\
134 "the current value while fields 2 and 3 are optional if set in Param2. "\
135 "Leave Param2 empty to use only 1 field as the match value. All selected fields must match their "\
136 "respective conditions for a lookup result to be assigned. "\
137 "The lookup dictionary has records each with properties: key1, key2, key3, value "\
138 "depending on how many keys are used which is set by Param1 and Param2. "\
139 "Keys can use front and/or back wildcard (*) like top*, *night, *state* to allow token matching. "\
140 "Param1: title of list that has been pre-loaded into array of lists as part of initialization. "\
141 "Param2: Field 2 title, or fields 2 and 3 titles. If both supplied use pipe to delimit as with field2|field3. "
142 f.param1req=True
143 f.param1typ="string"
144 f.param2req=False
145 f.param2typ="string"
146 oc.funcs.append(f)
147 transform_types.append(oc)
148 # CONDITIONAL
149 oc = OpCat("conditional")
150 # --------
151 f = OpFunc("ifEmpty")
152 f.desc= "If value is empty. Compares current value as string"
153 oc.funcs.append(f)
154 # --------
155 f = OpFunc("ifNotEmpty")
156 f.desc= "If value is not empty. Compares current value as string"
157 oc.funcs.append(f)
158 # --------
159 f = OpFunc("ifEq")
160 f.desc= "If equals. Compares current value as real number (converted from string) to Param1 "
161 f.desc += "(also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
162 f.param1req=True
163 f.param1typ="real"
164 oc.funcs.append(f)
165 # --------
166 f = OpFunc("ifNotEq")
167 f.desc= "If not equals. Compares current value as real number (converted from string) to Param1 "
168 f.desc += "(also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
169 f.param1req=True
170 f.param1typ="real"
171 oc.funcs.append(f)
172 # --------
173 f = OpFunc("ifGte")
174 f.desc= "If greater than or equals. Compares current value as real number (converted from string) "
175 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
176 f.param1req=True
177 f.param1typ="real"
178 oc.funcs.append(f)
179 # --------
180 f = OpFunc("ifNotGte")
181 f.desc= "If not greater than or equals. Compares current value as real number (converted from string) "
182 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
183 f.param1req=True
184 f.param1typ="real"
185 oc.funcs.append(f)
186 # --------
187 f = OpFunc("ifGt")
188 f.desc= "If greater than. Compares current value as real number (converted from string) "
189 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
190 f.param1req=True
191 f.param1typ="real"
192 oc.funcs.append(f)
193 # --------
194 f = OpFunc("ifNotGt")
195 f.desc= "If not greater than. Compares current value as real number (converted from string) "
196 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
197 f.param1req=True
198 f.param1typ="real"
199 oc.funcs.append(f)
200 # --------
201 f = OpFunc("ifLte")
202 f.desc= "If less than or equals. Compares current value as real number (converted from string) "
203 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
204 f.param1req=True
205 f.param1typ="real"
206 oc.funcs.append(f)
207 # --------
208 f = OpFunc("ifNotLte")
209 f.desc= "If not less than or equals. Compares current value as real number (converted from string) "
210 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
211 f.param1req=True
212 f.param1typ="real"
213 oc.funcs.append(f)
214 # --------
215 f = OpFunc("ifLt")
216 f.desc= "If less than. Compares current value as real number (converted from string) "
217 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
218 f.param1req=True
219 f.param1typ="real"
220 oc.funcs.append(f)
221 # --------
222 f = OpFunc("ifNotLt")
223 f.desc= "If not less than. Compares current value as real number (converted from string) "
224 f.desc += "to Param1 (also converted) from string or one of the char_aliases for PI (math.pi) or E (math.e)"
225 f.param1req=True
226 f.param1typ="real"
227 oc.funcs.append(f)
228 # --------
229 f = OpFunc("ifStrEq")
230 f.desc= "If strings are equal. Compares current value to Param1 as string or one of the char_aliases. "
231 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
232 f.desc += "with Strong|strENGTH|power . "
233 f.desc += "Param1: comparison value. "
234 f.desc += "Param2: optional whether case sensitive (default is false). "
235 f.param1req=True
236 f.param1typ="string"
237 f.param2req=False
238 f.param2typ="bool"
239 oc.funcs.append(f)
240 # --------
241 f = OpFunc("ifNotStrEq")
242 f.desc= "If strings are not equal. Compares current value to Param1 as string or one of the char_aliases. "
243 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
244 f.desc += "with Strong|strENGTH|power . "
245 f.desc += "Param1: comparison value. "
246 f.desc += "Param2: optional whether case sensitive (default is false). "
247 f.param1req=True
248 f.param1typ="string"
249 f.param2req=False
250 f.param2typ="bool"
251 oc.funcs.append(f)
252 # --------
253 f = OpFunc("ifStrStarts")
254 f.desc= "If current value starts with Param1. "
255 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
256 f.desc += "with Strong|strENGTH|power . "
257 f.desc += "Param1: comparison value. "
258 f.desc += "Param2: optional whether case sensitive (default is false). "
259 f.param1req=True
260 f.param1typ="string"
261 f.param2req=False
262 f.param2typ="bool"
263 oc.funcs.append(f)
264 # --------
265 f = OpFunc("ifNotStrStarts")
266 f.desc= "If current value not starts with Param1. "
267 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
268 f.desc += "with Strong|strENGTH|power . "
269 f.desc += "Param1: comparison value. "
270 f.desc += "Param2: optional whether case sensitive (default is false). "
271 f.param1req=True
272 f.param1typ="string"
273 f.param2req=False
274 f.param2typ="bool"
275 oc.funcs.append(f)
276 # --------
277 f = OpFunc("ifStrContains")
278 f.desc= "If current value contains Param1. "
279 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
280 f.desc += "with Strong|strENGTH|power . "
281 f.desc += "Param1: comparison value. "
282 f.desc += "Param2: optional whether case sensitive (default is false). "
283 f.desc += "Param3: optional whether remove all spaces from current value before comparing "
284 f.desc += "so 'this is me' becomes 'thisisme' (default is false). "
285 f.param1req=True
286 f.param1typ="string"
287 f.param2req=False
288 f.param2typ="bool"
289 f.param3req=False
290 f.param3typ="bool"
291 oc.funcs.append(f)
292 # --------
293 f = OpFunc("ifNotStrContains")
294 f.desc= "If current value not contains Param1. "
295 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
296 f.desc += "with Strong|strENGTH|power . "
297 f.desc += "Param1: comparison value. "
298 f.desc += "Param2: optional whether case sensitive (default is false). "
299 f.desc += "Param3: optional whether remove all spaces from current value before comparing "
300 f.desc += "so 'this is me' becomes 'thisisme' (default is false). "
301 f.param1req=True
302 f.param1typ="string"
303 f.param2req=False
304 f.param2typ="bool"
305 f.param3req=False
306 f.param3typ="bool"
307 oc.funcs.append(f)
308 # --------
309 f = OpFunc("ifStrEnds")
310 f.desc= "If current value ends with Param1. "
311 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
312 f.desc += "with Strong|strENGTH|power . "
313 f.desc += "Param1: comparison value. "
314 f.desc += "Param2: optional whether case sensitive (default is false). "
315 f.param1req=True
316 f.param1typ="string"
317 f.param2req=False
318 f.param2typ="bool"
319 oc.funcs.append(f)
320 # --------
321 f = OpFunc("ifNotStrEnds")
322 f.desc= "If current value not ends with Param1. "
323 f.desc += "You can specify multiple test strings by delimiting with pipe (no spacing) as "
324 f.desc += "with Strong|strENGTH|power . "
325 f.desc += "Param1: comparison value. "
326 f.desc += "Param2: optional whether case sensitive (default is false). "
327 f.param1req=True
328 f.param1typ="string"
329 f.param2req=False
330 f.param2typ="bool"
331 oc.funcs.append(f)
332 # --------
333 f= OpFunc("ifInt")
334 f.desc= "If integer. Param1 specifies if must be positive integer, negative, or any. "
335 f.desc += "Param1: optional ['any','positive','negative'] default=any"
336 f.param1req=False
337 f.param1typ="string"
338 oc.funcs.append(f)
339 # --------
340 f= OpFunc("ifNotInt")
341 f.desc= "If not integer. Param1 specifies if must be positive integer, negative, or any. "
342 f.desc += "Param1: optional ['any','positive','negative'] default=any"
343 f.param1req=False
344 f.param1typ="string"
345 oc.funcs.append(f)
346 # --------
347 f= OpFunc("ifReal")
348 f.desc= "If real. Param1 specifies if must be positive, negative, or any. "
349 f.desc += "Param1: optional ['any','positive','negative'] default=any"
350 f.param1req=False
351 f.param1typ="string"
352 oc.funcs.append(f)
353 # --------
354 f= OpFunc("ifNotReal")
355 f.desc= "If not real. Param1 specifies if must be positive, negative, or any. "
356 f.desc += "Param1: optional ['any','positive','negative'] default=any"
357 f.param1req=False
358 f.param1typ="string"
359 oc.funcs.append(f)
360 # --------
361 f= OpFunc("ifISODate")
362 f.desc= "If in ISO DateTime format of yyyyMMdd with optional time part of Thhmmss. "
363 f.desc += "Date part may use delimiters / or -. "
364 f.desc += "Time part may use delimiter :. Examples: 2024-03-24T14:33:05, 20240324T143305, 20240324"
365 oc.funcs.append(f)
366 # --------
367 f= OpFunc("ifNotISODate")
368 f.desc= "If not in ISO DateTime format of yyyyMMdd with optional time part of Thhmmss. "
369 f.desc += "Date part may use delimiters / or -. "
370 f.desc += "Time part may use delimiter :. Examples: 2024-03-24T14:33:05, 20240324T143305, 20240324"
371 oc.funcs.append(f)
372 # --------
373 f= OpFunc("ifDateFormat")
374 f.desc= "If in supplied date format. Date may use delimiters / or -. "
375 f.desc += "Param1: format with MMM for month abbreviation like Jan or Aug, "
376 f.desc += "and MONTH for full name like January. "
377 f.desc += "Formats: mmddyy, mmdyy,mdyy,mmddyyyy,mmdyyyy,mdyyyy,ddmmyy,ddmyy,dmyy,ddmmyyyy,ddmyyyy,dmyyyy,"
378 f.desc += "yymmdd,yymmd,yymd,yyyymmdd,yyyymmd,yyyymd,yyyyddd,yyyyMMMdd,ddMMMyyyy,"
379 f.desc += "MONTHdd,yyyy,ddMONTH,yyyy,yyyyMONTHdd,ddMONTHyyyy,yyMONTHdd,ddMONTHyy"
380 f.param1req=True
381 f.param1typ="string"
382 oc.funcs.append(f)
383 # --------
384 f= OpFunc("ifNotDateFormat")
385 f.desc= "If not in supplied date format. Date may use delimiters / or -. "
386 f.desc += "Param1: format with MMM for month abbreviation like Jan or Aug, "
387 f.desc += "and MONTH for full name like January. "
388 f.desc += "Formats: mmddyy, mmdyy,mdyy,mmddyyyy,mmdyyyy,mdyyyy,ddmmyy,ddmyy,dmyy,ddmmyyyy,ddmyyyy,dmyyyy,"
389 f.desc += "yymmdd,yymmd,yymd,yyyymmdd,yyyymmd,yyyymd,yyyyddd,yyyyMMMdd,ddMMMyyyy,"
390 f.desc += "MONTHdd,yyyy,ddMONTH,yyyy,yyyyMONTHdd,ddMONTHyyyy,yyMONTHdd,ddMONTHyy"
391 f.param1req=True
392 f.param1typ="string"
393 oc.funcs.append(f)
394 transform_types.append(oc)
395 # NUMERIC
396 oc = OpCat("numeric")
397 # --------
398 f= OpFunc("convertMainFrameNumber")
399 f.desc= "Converts a number in string representation in coded main frame format to string of real number. "
400 f.desc += "Encoded last character is indicator of this formatting including sign reversal if necessary. "
401 f.desc += "Always makes last 2 digits into decimal portion so no further divide by 100 is necessary. "
402 f.desc += "If special char is within input string it becomes the end char and the "
403 f.desc += "remaining suffix is discarded. Leading zeros are truncated so 000.12 becomes 0.12 . Codes are:"
404 f.desc += "{= 0, }= 0 and negate; "
405 f.desc += "a= 1, j= 1 and negate; "
406 f.desc += "b= 2, k= 2 and negate; "
407 f.desc += "c= 3, l= 3 and negate; "
408 f.desc += "d= 4, m= 4 and negate; "
409 f.desc += "e= 5, n= 5 and negate; "
410 f.desc += "f= 6, o= 6 and negate; "
411 f.desc += "g= 7, p= 7 and negate; "
412 f.desc += "h= 8, q= 8 and negate; "
413 f.desc += "i= 9, r= 9 and negate"
414 oc.funcs.append(f)
415 # --------
416 f= OpFunc("round")
417 f.desc= "Rounds number to specified number of decimal digits. If "
418 f.desc += "number digits=0 (default) then nearest integer made (real datatype ends .00). "
419 f.desc += "Midpoint goes to even number."
420 f.param1req= False
421 f.param1typ= "integer"
422 oc.funcs.append(f)
423 # --------
424 f= OpFunc("floor")
425 f.desc= "Returns the largest integral value less than or equal to number. "
426 f.desc += "If for a real datatype, will end with .00"
427 oc.funcs.append(f)
428 # --------
429 f= OpFunc("ceiling")
430 f.desc= "Returns the smallest integral value greater than or equal to number. "
431 f.desc += "If for a real datatype, will end with .00"
432 oc.funcs.append(f)
433 # --------
434 f= OpFunc("abs")
435 f.desc= "Returns absolute value"
436 oc.funcs.append(f)
437 # --------
438 f= OpFunc("negate")
439 f.desc= "Inverts sign"
440 oc.funcs.append(f)
441 # --------
442 f= OpFunc("mult")
443 f.desc= "Multiply current value by supplied number. May use special notations. "
444 f.desc += "Param1: number for operation"
445 f.desc += "Param2: optional boolean whether to clean number of non-numeric prefix and suffix characters. Default is true."
446 f.param1req= True
447 f.param1typ= "real"
448 f.param2req= False
449 f.param2typ= "bool"
450 oc.funcs.append(f)
451 # --------
452 f= OpFunc("div")
453 f.desc= "Divide current value by supplied number (current/x). May use special notations. "
454 f.desc += "Param1: number for operation. If =0 then result= 9.99 x 10^10 "
455 f.desc += "Param2: optional boolean whether to clean number of non-numeric prefix and suffix characters. Default is true."
456 f.param1req= True
457 f.param1typ= "real"
458 f.param2req= False
459 f.param2typ= "bool"
460 oc.funcs.append(f)
461 # --------
462 f= OpFunc("divfrom")
463 f.desc= "Divide current value from supplied number (x/current). May use special notations. "
464 f.desc += "Param1: number for operation. If =0 then result=0 while if current value=0 then result= 9.99 x 10^10 "
465 f.desc += "Param2: optional boolean whether to clean number of non-numeric prefix and suffix characters. Default is true."
466 f.param1req= True
467 f.param1typ= "real"
468 f.param2req= False
469 f.param2typ= "bool"
470 oc.funcs.append(f)
471 # --------
472 f= OpFunc("add")
473 f.desc= "Add current value by supplied number. May use special notations. "
474 f.desc += "Param1: number for operation"
475 f.desc += "Param2: optional boolean whether to clean number of non-numeric prefix and suffix characters. Default is true."
476 f.param1req= True
477 f.param1typ= "real"
478 f.param2req= False
479 f.param2typ= "bool"
480 oc.funcs.append(f)
481 # --------
482 f= OpFunc("subtract")
483 f.desc= "Subtract current value by supplied number (current-x). May use special notations. "
484 f.desc += "Param1: number for operation"
485 f.desc += "Param2: optional boolean whether to clean number of non-numeric prefix and suffix characters. Default is true."
486 f.param1req= True
487 f.param1typ= "real"
488 f.param2req= False
489 f.param2typ= "bool"
490 oc.funcs.append(f)
491 # --------
492 f= OpFunc("subtractFrom")
493 f.desc= "Subtract current value from supplied number (x-current). May use special notations. "
494 f.desc += "Param1: number for operation"
495 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
496 f.param1req= True
497 f.param1typ= "real"
498 f.param2req= False
499 f.param2typ= "bool"
500 oc.funcs.append(f)
501 # --------
502 f= OpFunc("multByRef")
503 f.desc= "Multiply current value by value of referenced field. "
504 f.desc += "Param1: source field title"
505 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
506 f.param1req= True
507 f.param1typ= "string"
508 f.param2req= False
509 f.param2typ= "bool"
510 oc.funcs.append(f)
511 # --------
512 f= OpFunc("divByRef")
513 f.desc= "Divide current value by value of referenced field (current/ref). "
514 f.desc += "If Param1=0 then result= 9.99 x 10^10"
515 f.desc += "Param1: source field title"
516 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
517 f.param1req= True
518 f.param1typ= "string"
519 f.param2req= False
520 f.param2typ= "bool"
521 oc.funcs.append(f)
522 # --------
523 f= OpFunc("divFromRef")
524 f.desc= "Divide current value from value of referenced field (ref/current). "
525 f.desc += "If current=0 then result= 9.99 x 10^10"
526 f.desc += "Param1: source field title"
527 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
528 f.param1req= True
529 f.param1typ= "string"
530 f.param2req= False
531 f.param2typ= "bool"
532 oc.funcs.append(f)
533 # --------
534 f= OpFunc("addByRef")
535 f.desc= "Add current value by value of referenced field. "
536 f.desc += "Param1: source field title"
537 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
538 f.param1req= True
539 f.param1typ= "string"
540 f.param2req= False
541 f.param2typ= "bool"
542 oc.funcs.append(f)
543 # --------
544 f= OpFunc("subtractByRef")
545 f.desc= "Subtract current value by value of referenced field (current-ref). "
546 f.desc += "Param1: source field title"
547 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
548 f.param1req= True
549 f.param1typ= "string"
550 f.param2req= False
551 f.param2typ= "bool"
552 oc.funcs.append(f)
553 # --------
554 f= OpFunc("subtractFromRef")
555 f.desc= "Subtract current value from value of referenced field (ref-current). "
556 f.desc += "Param1: source field title"
557 f.desc += "Param2: optional boolean whether to use cleanNumber before action. Default is true."
558 f.param1req= True
559 f.param1typ= "string"
560 f.param2req= False
561 f.param2typ= "bool"
562 oc.funcs.append(f)
563 # --------
564 f= OpFunc("multRefs")
565 f.desc= "Multiply referenced fields. "
566 f.desc += "Param1: first field title"
567 f.desc += "Param2: second field title or multiple field titles separated by commas like title2,title3,title4"
568 f.desc += "Param3: optional boolean whether to use cleanNumber before action. Default is true."
569 f.param1req= True
570 f.param1typ= "string"
571 f.param2req= True
572 f.param2typ= "string"
573 f.param3req= False
574 f.param3typ= "bool"
575 oc.funcs.append(f)
576 # --------
577 f= OpFunc("addRefs")
578 f.desc= "Add referenced fields. "
579 f.desc += "Param1: first field title"
580 f.desc += "Param2: second field title or multiple field titles separated by commas like title2,title3,title4"
581 f.desc += "Param3: optional boolean whether to use cleanNumber before action. Default is true."
582 f.param1req= True
583 f.param1typ= "string"
584 f.param2req= True
585 f.param2typ= "string"
586 f.param3req= False
587 f.param3typ= "bool"
588 oc.funcs.append(f)
589 # --------
590 f= OpFunc("log")
591 f.desc= "Base 10 log of current value. If value<0 then result= -10^10. "
592 f.desc += "If datatype is int then result uses FLOOR. "
593 oc.funcs.append(f)
594 # --------
595 f= OpFunc("ln")
596 f.desc= "Base E log of current value. If value<0 then result= -10^10. "
597 f.desc += "If datatype is int then result uses FLOOR. "
598 oc.funcs.append(f)
599 # --------
600 f= OpFunc("pow10")
601 f.desc= "Base 10 exponential of current value. "
602 oc.funcs.append(f)
603 # --------
604 f= OpFunc("powe")
605 f.desc= "Base E exponential of current value. "
606 oc.funcs.append(f)
607 # --------
608 f= OpFunc("setDecimal")
609 f.desc= "Sets number of decimal places for number. If <=0 then value is truncated to integer. "
610 f.desc += "If less than number's decimals, excess digits cut. If greater, decimal places padded right with 0. "
611 f.desc += "Param1: integer number of decimal places"
612 f.param1req= True
613 f.param1typ= "integer"
614 oc.funcs.append(f)
615 # --------
616 f= OpFunc("convertFromExp")
617 f.desc= "Convert a string representing exponential number into non-exponential number. "
618 f.desc += "String will be checked for format n.nnEsnn where n is integer digit, "
619 f.desc += "and s is an optional + or -. String can also have front - or be enclosed in parentheses. Examples: "
620 f.desc += "1.3E05 converted to 130000, -1.23e-1 converted to -0.123"
621 oc.funcs.append(f)
622 transform_types.append(oc)
623 # TEXT
624 oc = OpCat("text")
625 # --------
626 f= OpFunc("trim")
627 f.desc= "Remove whitespace left (i.e. front) and right (i.e. back)"
628 oc.funcs.append(f)
629 # --------
630 f= OpFunc("ltrim")
631 f.desc= "Remove whitespace left side (front). "
632 oc.funcs.append(f)
633 # --------
634 f= OpFunc("rtrim")
635 f.desc= "Remove whitespace right side (back). "
636 oc.funcs.append(f)
637 # --------
638 f= OpFunc("toLower")
639 f.desc= "Set to lower case. "
640 oc.funcs.append(f)
641 # --------
642 f= OpFunc("toUpper")
643 f.desc= "Set to upper case. "
644 oc.funcs.append(f)
645 # --------
646 f= OpFunc("toTitle")
647 f.desc= "Set to title case. "
648 oc.funcs.append(f)
649 # --------
650 f= OpFunc("front")
651 f.desc= "Take characters from front of string. "
652 f.desc += "Matching part is found in current value and then cut after its first occurrence, "
653 f.desc += "such as 'r' for value 'horse' yields 'hor'."
654 f.desc += "Param1: string to find match"
655 f.param1req= True
656 f.param1typ= "string"
657 oc.funcs.append(f)
658 # --------
659 f= OpFunc("before")
660 f.desc= "Take characters from before a string match. "
661 f.desc += "Matching part is found in current value and then cut before its first occurrence, "
662 f.desc += "such as 'r' for value 'horse' yields 'ho'."
663 f.desc += "Param1: string to find match"
664 f.param1req= True
665 f.param1typ= "string"
666 oc.funcs.append(f)
667 # --------
668 f= OpFunc("frontN")
669 f.desc= "Take N characters from front of string. "
670 f.desc += "Param1: number chars"
671 f.param1req= True
672 f.param1typ= "integer"
673 oc.funcs.append(f)
674 # --------
675 f= OpFunc("end")
676 f.desc= "Take characters from end of string including match. "
677 f.desc += "Matching part is found in current value and then cut at its first occurrence to end, "
678 f.desc += "such as 'r' for value 'horse' yields 'rse'."
679 f.desc += "Param1: string to find match"
680 f.param1req= True
681 f.param1typ= "string"
682 oc.funcs.append(f)
683 # --------
684 f= OpFunc("after")
685 f.desc= "Take characters from end of string after the match. "
686 f.desc += "Matching part is found in current value and then cut after its first occurrence to end, "
687 f.desc += "such as 'r' for value 'horse' yields 'se'."
688 f.desc += "Param1: string to find match"
689 f.param1req= True
690 f.param1typ= "string"
691 oc.funcs.append(f)
692 # --------
693 f= OpFunc("endN")
694 f.desc= "Take N characters from end of string. "
695 f.desc += "Param1: number chars"
696 f.param1req= True
697 f.param1typ= "integer"
698 oc.funcs.append(f)
699 # --------
700 f= OpFunc("mid")
701 f.desc= "Take characters from middle of string. "
702 f.desc += "Matching part is found in current value and then cut after its first occurrence, "
703 f.desc += "If Param2 not used, result is after cutting with Param1. "
704 f.desc += "If Param2 is used, then initial result is again cut after Param2's occurrence "
705 f.desc += "meaning result is string including Param1 and Param2 only. "
706 f.desc += "For value 'Semantics' Param1='m' and Param2='c' yields 'mantic'. "
707 f.desc += "For value 'mishmash' Param1='ma' and Param2='s' yields 'mas'."
708 f.desc += "Param1: string to find match"
709 f.desc += "Param2: optional string to find second match"
710 f.param1req= True
711 f.param1typ= "string"
712 f.param2req= False
713 f.param2typ= "string"
714 oc.funcs.append(f)
715 # --------
716 f= OpFunc("midN")
717 f.desc= "Take N characters from middle of string. Result is after cutting at Param1 character index from front of string. "
718 f.desc += "If Param2 not used, to end of string. "
719 f.desc += "For value 'Semantics' Param1='2' and Param2='6' yields 'mantic' , and "
720 f.desc += "for value 'mishmash' Param1='4' and Param2='3' yields 'mas'."
721 f.desc += "Param1: integer starting position using 0-based indexing"
722 f.desc += "Param2: optional second integer for number of characters to take"
723 f.param1req= True
724 f.param1typ= "integer"
725 f.param2req= False
726 f.param2typ= "integer"
727 oc.funcs.append(f)
728 # --------
729 f= OpFunc("charAt")
730 f.desc= "Take 1 character at position (0-based). "
731 f.desc += "Param1: number char"
732 f.param1req= True
733 f.param1typ= "integer"
734 oc.funcs.append(f)
735 # --------
736 f= OpFunc("prepend")
737 f.desc= "Add string to front of value. "
738 f.desc += "Param1: string to add"
739 f.param1req= True
740 f.param1typ= "string"
741 oc.funcs.append(f)
742 # --------
743 f= OpFunc("append")
744 f.desc= "Adds string to end of value. "
745 f.desc += "Param1: string to add"
746 f.param1req= True
747 f.param1typ= "string"
748 oc.funcs.append(f)
749 # --------
750 f= OpFunc("remove")
751 f.desc= "Removes all instances string from value. "
752 f.desc += "Param1: string to remove"
753 f.param1req= True
754 f.param1typ= "string"
755 oc.funcs.append(f)
756 # --------
757 f= OpFunc("replace")
758 f.desc= "Replaces all instances string in value. "
759 f.desc += "Param1: string to remove. "
760 f.desc += "Param2: string to insert"
761 f.param1req= True
762 f.param1typ= "string"
763 f.param2req= True
764 f.param2typ= "string"
765 oc.funcs.append(f)
766 # --------
767 f= OpFunc("setLength")
768 f.desc= "Sets value to specific length by cutting or padding characters as needed. "
769 f.desc += "Param1: integer character length. "
770 f.desc += "Param2: optional side to act on (cut or pad) if existing string is not N chars. "
771 f.desc += "Either left (i.e front) or right (i.e. back). Default is right. "
772 f.desc += "Param3: optional char to pad with if needed. Default is x. If longer than 1 char only first used."
773 f.param1req= True
774 f.param1typ= "integer"
775 f.param2req= False
776 f.param2typ= "string"
777 f.param3req= False
778 f.param3typ= "string"
779 oc.funcs.append(f)
780 transform_types.append(oc)
781 # DATE
782 oc = OpCat("date")
783 # --------
784 f= OpFunc("setToISODate")
785 f.desc= "Creates an ISO 8601 DateTime string yyyyMMddThhmmss. "
786 f.desc += "Param1: Either today for current date, now for current date and time, or ISO DateTime. "
787 f.desc += "Param2: optional for either 'today' or 'now' (ignored when Param1 is ISO dateTime) the number hours timezone offset from UTC (e.g. Dallas TX is -5, Kolkata India is +5.5, New York NY is -4), "
788 f.desc += "otherwise the computer's time zone is used so depends on server settings."
789 f.param1req= True
790 f.param1typ= "string"
791 f.param2req= False
792 f.param2typ= "real"
793 oc.funcs.append(f)
794 # --------
795 f= OpFunc("dateToISO")
796 f.desc= "Converts data in specified format to ISO 8601 date yyyyMMdd. "
797 f.desc += "Param1: format with MMM for month abbreviation like Jan or Aug, "
798 f.desc += "and MONTH for full name like January. "
799 f.desc += "Formats: mmddyy, mmdyy,mdyy,mmddyyyy,mmdyyyy,mdyyyy,ddmmyy,ddmyy,dmyy,ddmmyyyy,ddmyyyy,dmyyyy,"
800 f.desc += "yymmdd,yymmd,yymd,yyyymmdd,yyyymmd,yyyymd,yyyyddd,yyyyMMMdd,ddMMMyyyy,"
801 f.desc += "MONTHdd,yyyy,ddMONTH,yyyy,yyyyMONTHdd,ddMONTHyyyy,yyMONTHdd,ddMONTHyy"
802 f.param1req= True
803 f.param1typ= "string"
804 oc.funcs.append(f)
805 # --------
806 f= OpFunc("excelDateNumberToISO")
807 f.desc= "Converts a date in numeric excel format into ISO8601 yyyymmdd format with "
808 f.desc += "fractional days removed. Excel uses "
809 f.desc += "number days since January 1, 1900 as its counting base. "
810 f.desc += "Example: 44416 = 20210808, 42855 = 20170430"
811 oc.funcs.append(f)
812 transform_types.append(oc)
813 except RuntimeError as err:
814 print("error:",err)
815 return transform_types
__init__(self, str category)
Definition optypes.py:62