@@ -180,7 +180,7 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
180
180
if show_progress :
181
181
total = len (originalresults .items ())
182
182
pbar = tqdm .tqdm (initial = 0 , total = total ,smoothing = 1 ,unit = " results" ,desc = "Processing " )
183
-
183
+ totalizecolumns = []
184
184
# convert uris to human-friendly names
185
185
for kuri , v in originalresults .items ():
186
186
logger .info ( f"post-processing result { kuri } { v } " )
@@ -189,15 +189,15 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
189
189
logger .info ( f"{ kattr = } { vattr = } " )
190
190
# first try to convert the value to a name
191
191
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 )
201
201
else :
202
202
remappedvalue = self .resolve_uri_to_name (vattr ) if resolvenames else vattr
203
203
# 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
209
209
if kattr not in remappednames :
210
210
remappedname = self .resolve_uri_to_name (kattr ) if resolvenames else kattr
211
211
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
+
212
219
if remappednames [kattr ] is not None :
213
220
v1 [remappednames [kattr ]] = remappedvalue
214
221
else :
@@ -218,12 +225,29 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
218
225
219
226
if show_progress :
220
227
pbar .update (1 )
221
-
228
+
222
229
# if showing progress and pbar has been created (after the first set of results if paged)
223
230
if show_progress and pbar is not None :
224
231
# close off the progress bar
225
232
pbar .close ()
226
233
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
227
251
228
252
if isnulls or isnotnulls :
229
253
logger .debug ( f"{ isnulls = } { isnotnulls = } " )
0 commit comments