@@ -355,15 +355,24 @@ public Map<String, Integer> statsMediaAssets() {
355355
356356 public JSONObject statsAnnotations (Shepherd myShepherd ) {
357357 JSONObject sa = new JSONObject ();
358+ // List<Task> is ordered 'created desc'
358359 Map <Annotation , List <Task > > atm = this .getAnnotationTaskMap (myShepherd );
359360 int numTasks = 0 ;
361+ int numLatestTasks = 0 ;
360362 JSONObject encData = new JSONObject ();
361363
362364 for (Annotation ann : atm .keySet ()) {
363365 Encounter enc = ann .findEncounter (myShepherd );
364366 if ((enc != null ) && !encData .has (enc .getId ()))
365367 encData .put (enc .getId (), new JSONArray ());
368+ // trivial annots will not be sent correctly to ident (no iaClass etc)
369+ // so we skip them in counts as if not sent
370+ if (ann .isTrivial ()) {
371+ sa .put (ann .getId (), 0 );
372+ continue ;
373+ }
366374 sa .put (ann .getId (), Util .collectionSize (atm .get (ann )));
375+ boolean latestTask = true ; // only for first (most recent) task
367376 for (Task atask : atm .get (ann )) {
368377 String status = atask .getStatus (myShepherd );
369378 if (sa .has (status )) {
@@ -372,17 +381,29 @@ public JSONObject statsAnnotations(Shepherd myShepherd) {
372381 sa .put (status , 1 );
373382 }
374383 numTasks ++;
384+ // this records only most recent task statuses like: numLatestTask_complete
385+ if (latestTask ) {
386+ String latestStatus = "numLatestTask_" + atask .getStatus (myShepherd );
387+ if (sa .has (latestStatus )) {
388+ sa .put (latestStatus , sa .optInt (latestStatus , 0 ) + 1 );
389+ } else {
390+ sa .put (latestStatus , 1 );
391+ }
392+ numLatestTasks ++;
393+ }
375394 if (enc != null ) {
376395 JSONArray arr = new JSONArray ();
377396 arr .put (atask .getId ());
378397 arr .put (status );
379398 arr .put (ann .getIAClass ());
380399 encData .getJSONArray (enc .getId ()).put (arr );
381400 }
401+ latestTask = false ;
382402 }
383403 }
384404 sa .put ("encounterTaskInfo" , encData );
385405 sa .put ("numTasks" , numTasks );
406+ sa .put ("numLatestTasks" , numLatestTasks );
386407 return sa ;
387408 }
388409
@@ -553,12 +574,12 @@ public JSONObject iaSummaryJson(Shepherd myShepherd) {
553574 int numIdentificationComplete = 0 ;
554575 int numIdentificationTotal = 0 ;
555576 // getOverallStatus() in imports.jsp is a nightmare. attempt to replicate here.
556- if (statsAnn .optInt ("numTasks " , -1 ) >= 0 )
557- numIdentificationTotal = statsAnn .optInt ("numTasks " );
577+ if (statsAnn .optInt ("numLatestTasks " , -1 ) >= 0 )
578+ numIdentificationTotal = statsAnn .optInt ("numLatestTasks " );
558579 // who is the genius who made this be 'completed' versus the (seemingly universal?) 'complete'
559580 // (it may well have been me)
560- if (statsAnn .optInt ("completed " , -1 ) >= 0 )
561- numIdentificationComplete = statsAnn .optInt ("completed " );
581+ if (statsAnn .optInt ("numLatestTask_completed " , -1 ) >= 0 )
582+ numIdentificationComplete = statsAnn .optInt ("numLatestTask_completed " );
562583 // TODO do we have to deal with errors as "completed" somehow?
563584 pj .put ("identificationNumberComplete" , numIdentificationComplete );
564585 pj .put ("identificationNumTotal" , numIdentificationTotal );
0 commit comments