Select to view content in your preferred language

# Database/ field editing performance regarding contingent values?

311
0
09-07-2023 01:24 PM
by
Regular Contributor

Hi,

I have a quick question regarding contingent values and the potential impacts that it may have on performance either with editing in the field or the database itself. I have a script that creates all potential combinations and adds them as contingent values. Depending on what limitations or restrictions I set, I get a varying number of possible outcomes ranging from 300 to over 1000. Here is part of the script that I have that creates all possible combinations and returns a list of strings that are then added as contingent values.

from itertools import permutations, combinations

# Contingent values function
def CreateContingentStringValues( Fields, Condition, DomainType, DomainCodes, Constraints, SetNullConditions,  ExistingValues ):
Equal, NotEqual, GreatThan, LessThan = '=', '!=', '>', '<'
FieldIndexing = { fieldname : index for index, fieldname in enumerate( Fields ) }

Combinations = None
if len( Fields ) >= 2:
if Condition == NotEqual:
Combinations = list( list( combinations( DomainCodes, len( Fields ) ) ) )
elif Condition == Equal:
Combinations = list( list( permutations( DomainCodes, len( Fields ) ) ) )
elif Condition in [ GreatThan, LessThan ]:
pass

ValidCombinations = []
if Combinations:
for Combination in Combinations:
ValidateCombinations = len( set( Constraints ).intersection( set( Combination ) ) ) < 2
CombinationOrder = [ Constraints[ value ] for value in Combination if value in Constraints ]
SortedOrder = sorted( CombinationOrder, reverse = True )
ValidateOrder = all( [ True if any( [ a == b, a > b ] ) else False for a, b in zip( SortedOrder, CombinationOrder ) ] )
if all( [ ValidateCombinations, SetNullConditions not in Combination, ValidateOrder ] ):
ValidCombinations += [ Combination ]

ValuesString = [ ]
if ValidCombinations:
for Combination in ValidCombinations:
FieldValueDict = dict( zip(  Fields, Combination ) )
ListStrFieldNameValue = [ f'{ FieldName } { DomainType } { FieldValueDict[ FieldName ] }' for FieldName in FieldValueDict ]
StrValue = ';'.join( ListStrFieldNameValue )
if StrValue not in ExistingValues:
ValuesString += [ StrValue ]

if type( SetNullConditions ) is str:
ListStrFieldNameValue = [ f'{ FieldName } { DomainType } { SetNullConditions }'  if FieldIndexing[ FieldName ] == 0 else  f'{ FieldName } NULL { SetNullConditions }' for FieldName in FieldIndexing ]
StrValue = ';'.join( ListStrFieldNameValue )
if StrValue not in ExistingValues:
ValuesString += [ StrValue ]

return ValuesString

It works but my concern is the impact that it may have on our field editors. Any help or input would be greatly appreciated.

0 Replies