Changeset 19 for src/main/webapp/utilstable.xhtml
- Timestamp:
- 09/28/20 09:29:02 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/webapp/utilstable.xhtml
r18 r19 27 27 <thead> 28 28 <tr> 29 <th align="center"> run nr</th>30 <th align="center">accepted bid (s)</th>29 <th align="center">sess / agree</th> 30 <th align="center">accepted bid in session</th> 31 31 <th align="center">party utility - penalty</th> 32 32 </tr> … … 206 206 for (var nr in results) { 207 207 var result = results[nr]; 208 var row = table.insertRow(-1); //-1 = end 209 fillRow(row, nr, results[nr]); 208 fillBids(table, nr, result); 210 209 } 211 210 setStatus("done"); 212 211 } 213 212 214 /** 215 @return true if object1, object2 are 'deep equal'. That means, 216 if they are dicts then we check that the keys and their values are equal, 217 recursively. 218 */ 219 function deepEqual(object1, object2) { 220 const keys1 = Object.keys(object1); 221 const keys2 = Object.keys(object2); 222 223 if (keys1.length !== keys2.length) { 224 return false; 225 } 226 227 for (const key of keys1) { 228 const val1 = object1[key]; 229 const val2 = object2[key]; 230 const areObjects = isObject(val1) && isObject(val2); 231 if ( 232 areObjects && !deepEqual(val1, val2) || !areObjects && val1 !== val2 233 ) { 234 return false; 235 } 236 } 237 238 return true; 239 } 240 241 function isObject(object) { 242 return object != null && typeof object === 'object'; 243 } 244 245 /** 246 @param list the list to add value to 247 @param value the value to add 248 @return list with the value added, but only if not already in list. 249 Uses deepEqual to check equality of list members 250 */ 251 function addSet(list, value) { 252 for (const v of list) { 253 if (deepEqual(v, value)) 254 return list; 255 } 256 return list.concat(value); 257 } 213 /** 214 @param table the table to add the bid results to 215 @param nr the session number 216 @param results the results for this sess 217 Add rows for all the bids 218 */ 219 function fillBids(table, nr, result) { 220 // collect unique bids in agreements. 221 var agreements = result['agreements']; 222 223 if (Object.keys(agreements).length == 0) { 224 fillRow(table.insertRow(-1), nr, result, {}); 225 return; 226 } 227 228 var bids = []; 229 for (const pid in agreements) { 230 bids=addSet(bids, agreements[pid]['issuevalues']); 231 } 232 233 var dealnr='A'.charCodeAt(0); 234 for (const bid of bids) { 235 fillRow(table.insertRow(-1), nr+String.fromCharCode(dealnr++), result, bid); 236 } 237 } 238 239 240 258 241 259 242 /** … … 262 245 @param result a single json result from the APP results section. 263 246 Contains participants, agreements and error 264 */ 265 function fillRow(row, nr, result) { 247 @param agreedbid the bid to show in this row. If {}, no agreement was reached. 248 */ 249 function fillRow(row, nr, result, agreedbid) { 266 250 row.insertCell(0).innerHTML = nr; 267 251 … … 275 259 return; 276 260 } 277 278 // collect unique bids in agreements. 279 var agreements = result['agreements']; 280 var bids = []; 281 for (const pid in agreements) { 282 bids=addSet(bids, agreements[pid]['issuevalues']); 283 } 284 285 261 286 262 // a dict, keys are party ids. 287 // FIXME this does not work ok with MOPAC. 288 row.insertCell(-1).innerHTML = JSON.stringify(bids); 289 var agreedbid={}; 290 if (bids.length>0) agreedbid = bids[0]; 263 row.insertCell(-1).innerHTML = JSON.stringify(agreedbid); 291 264 292 265 // fill in the columns. If SHAOP, only the even parties 293 var stepsize = SHAOP? 2:1; 294 for (var n=0; n<result['participants'].length; n=n+stepsize) { 295 var party = result['participants'][n] 296 var profile =party['profile']; 297 var penalty=result['penalties'][n]; 266 // FIXME this can't be with a MAP 267 const participants = result['participants']; 268 for (var pid in participants) { 269 var partyandprofile = result['participants'][pid]; 270 var profile =partyandprofile['profile']; 271 var penalty=result['penalties'][pid]; 272 if (penalty==undefined) penalty=0; 298 273 // make short name for readability 299 var partyname = party ['party']['partyref'];274 var partyname = partyandprofile['party']['partyref']; 300 275 partyname = partyname.split('/'); 301 276 partyname = partyname[partyname.length-1]; 302 addUtilityCell(row.insertCell(-1), agreedbid, partyname, profile,penalty); 277 278 // we set bid to agreedbid only if party accepted agreedbid. 279 var bid = {}; 280 if (pid in result['agreements'] && deepEqual(agreedbid, result['agreements'][pid]['issuevalues'] ) ) 281 bid = agreedbid; 282 addUtilityCell(row.insertCell(-1), bid, partyname, profile, penalty); 303 283 } 304 284 } … … 410 390 } 411 391 392 /************ util functions to compare dict objects **************/ 393 /** 394 @return true if object1, object2 are 'deep equal'. That means, 395 if they are dicts then we check that the keys and their values are equal, 396 recursively. 397 */ 398 function deepEqual(object1, object2) { 399 const keys1 = Object.keys(object1); 400 const keys2 = Object.keys(object2); 401 402 if (keys1.length !== keys2.length) { 403 return false; 404 } 405 406 for (const key of keys1) { 407 const val1 = object1[key]; 408 const val2 = object2[key]; 409 const areObjects = isObject(val1) && isObject(val2); 410 if ( 411 areObjects && !deepEqual(val1, val2) || !areObjects && val1 !== val2 412 ) { 413 return false; 414 } 415 } 416 417 return true; 418 } 419 420 function isObject(object) { 421 return object != null && typeof object === 'object'; 422 } 423 424 /** 425 @param list the list to add value to 426 @param value the value to add 427 @return list with the value added, but only if not already in list. 428 Uses deepEqual to check equality of list members 429 */ 430 function addSet(list, value) { 431 for (const v of list) { 432 if (deepEqual(v, value)) 433 return list; 434 } 435 return list.concat(value); 436 } 412 437 413 438 ]]>
Note:
See TracChangeset
for help on using the changeset viewer.