@@ -180,7 +180,7 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
180180 if show_progress :
181181 total = len (originalresults .items ())
182182 pbar = tqdm .tqdm (initial = 0 , total = total ,smoothing = 1 ,unit = " results" ,desc = "Processing " )
183-
183+ totalizecolumns = []
184184 # convert uris to human-friendly names
185185 for kuri , v in originalresults .items ():
186186 logger .info ( f"post-processing result { kuri } { v } " )
@@ -189,15 +189,15 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
189189 logger .info ( f"{ kattr = } { vattr = } " )
190190 # first try to convert the value to a name
191191 if isinstance (vattr , list ):
192- if totalize :
193- remappedvalue = len ( vattr )
194- else :
195- remappedvalue = []
196- for lv in vattr :
197- if resolvenames :
198- remappedvalue .append (self .resolve_uri_to_name (lv ))
199- else :
200- remappedvalue .append (lv )
192+ if totalize and kattr not in totalizecolumns :
193+ totalizecolumns . append ( kattr )
194+ print ( f"Going to totalize { kattr } " )
195+ remappedvalue = []
196+ for lv in vattr :
197+ if resolvenames :
198+ remappedvalue .append (self .resolve_uri_to_name (lv ))
199+ else :
200+ remappedvalue .append (lv )
201201 else :
202202 remappedvalue = self .resolve_uri_to_name (vattr ) if resolvenames else vattr
203203 # then check the attribute itself for one of the mappings we created while parsing the querystring to turn it into an oslc query
@@ -209,6 +209,13 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
209209 if kattr not in remappednames :
210210 remappedname = self .resolve_uri_to_name (kattr ) if resolvenames else kattr
211211 remappednames [kattr ] = remappedname
212+
213+ if kattr in totalizecolumns :
214+ print ( f"Totalizer replacing katter { kattr } with { remappedname } " )
215+ # remove the old name, add the new name
216+ totalizecolumns .remove (kattr )
217+ totalizecolumns .append (remappedname )
218+
212219 if remappednames [kattr ] is not None :
213220 v1 [remappednames [kattr ]] = remappedvalue
214221 else :
@@ -218,12 +225,29 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
218225
219226 if show_progress :
220227 pbar .update (1 )
221-
228+
222229 # if showing progress and pbar has been created (after the first set of results if paged)
223230 if show_progress and pbar is not None :
224231 # close off the progress bar
225232 pbar .close ()
226233 print ( "Processing completed" )
234+
235+ # fixup the totalized columns to ensure all entries are lengths even if empty or one (non-list) entry
236+ if totalize :
237+ for k ,v in mappedresult .items ():
238+ for tot in totalizecolumns :
239+ print ( f"Totalizing { tot = } " )
240+ vattr = v .get (tot )
241+ if not vattr :
242+ newv = 0
243+ print ( f"Replacing { vattr } with 0" )
244+ elif isinstance (vattr , list ):
245+ newv = len (vattr )
246+ print ( f"Replacing list { len (vattr )} with { newv = } " )
247+ else :
248+ newv = 1
249+ print ( f"Replacing { vattr } with { newv = } " )
250+ v [tot ]= newv
227251
228252 if isnulls or isnotnulls :
229253 logger .debug ( f"{ isnulls = } { isnotnulls = } " )
0 commit comments