88class Processing extends Page {
99 public static $ dispatch = array (
1010 array ('/:id ' , 'get ' , '_results ' ),
11+ array ('/visit/:visit ' , 'get ' , '_results_for_visit ' ),
1112 array ('/status ' , 'post ' , '_statuses ' ),
1213
1314 array ('/messages/status ' , 'post ' , '_ap_message_status ' ),
@@ -34,7 +35,15 @@ class Processing extends Page {
3435 'map ' => '\d+ ' ,
3536 'n ' => '\d+ ' ,
3637 'sampleGroupId ' => '\d+ ' ,
37- 'resultCount ' => '\d+ '
38+ 'resultCount ' => '\d+ ' ,
39+ 'pipeline ' => '[\w\s\+]+ ' ,
40+ 'spacegroup ' => '(\w|\s|\-|\/)+ ' ,
41+ 'resolution ' => '[\d\.]+ ' ,
42+ 'completeness ' => '[\d\.]+ ' ,
43+ 'anomcompleteness ' => '[\d\.]+ ' ,
44+ 'rmeas ' => '[\d\.]+ ' ,
45+ 'cchalf ' => '[\d\.]+ ' ,
46+ 'ccanom ' => '[\d\.]+ ' ,
3847 );
3948
4049 /**
@@ -47,6 +56,8 @@ class Processing extends Page {
4756 0 => 3 ,
4857 );
4958
59+ const EVTOA = 12398.4198 ;
60+
5061 function _map_status ($ status ) {
5162 foreach ($ this ->status_mapping as $ state => $ value ) {
5263 if ($ status == $ state ) {
@@ -238,6 +249,198 @@ function _statuses() {
238249 $ this ->_output ($ out );
239250 }
240251
252+ function _results_for_visit () {
253+ if (!($ this ->has_arg ('visit ' ))) {
254+ $ this ->_error ('No visit specified ' );
255+ }
256+ $ pattern = '/([A-z]+)(\d+)-(\d+)/ ' ;
257+ preg_match ($ pattern , $ this ->arg ('visit ' ), $ matches );
258+ if (!sizeof ($ matches ))
259+ $ this ->_error ('No such visit ' );
260+
261+ $ info = $ this ->db ->pq ("SELECT s.sessionid FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE p.proposalcode=:1 AND p.proposalnumber=:2 AND s.visit_number=:3 " , array ($ matches [1 ], $ matches [2 ], $ matches [3 ]));
262+
263+ if (!sizeof ($ info )) {
264+ $ this ->_error ('No such visit ' );
265+ }
266+
267+ $ args = array ($ info [0 ]['SESSIONID ' ]);
268+
269+ $ where = 'dc.sessionid=:1 AND dc.overlap = 0 AND dc.axisrange > 0 AND dc.numberOfImages > 150 AND app.processingstatus = 1 ' ;
270+
271+ if ($ this ->has_arg ('pipeline ' )) {
272+ $ st = sizeof ($ args );
273+ $ where .= " AND app.processingprograms = : " . ($ st + 1 );
274+ array_push ($ args , $ this ->arg ('pipeline ' ));
275+ }
276+
277+ if ($ this ->has_arg ('spacegroup ' )) {
278+ $ st = sizeof ($ args );
279+ $ where .= " AND REPLACE(ap.spacegroup,' ','') = : " . ($ st + 1 );
280+ array_push ($ args , $ this ->arg ('spacegroup ' ));
281+ }
282+
283+ if ($ this ->has_arg ('resolution ' )) {
284+ $ st = sizeof ($ args );
285+ $ where .= " AND apssover.resolutionlimithigh <= : " . ($ st + 1 );
286+ array_push ($ args , $ this ->arg ('resolution ' ));
287+ }
288+
289+ if ($ this ->has_arg ('completeness ' )) {
290+ $ st = sizeof ($ args );
291+ $ where .= " AND apssover.completeness >= : " . ($ st + 1 );
292+ array_push ($ args , $ this ->arg ('completeness ' ));
293+ }
294+
295+ if ($ this ->has_arg ('anomcompleteness ' )) {
296+ $ st = sizeof ($ args );
297+ $ where .= " AND apssover.anomalousCompleteness >= : " . ($ st + 1 );
298+ array_push ($ args , $ this ->arg ('anomcompleteness ' ));
299+ }
300+
301+ if ($ this ->has_arg ('rmeas ' )) {
302+ $ st = sizeof ($ args );
303+ $ where .= " AND apssinner.rmeasalliplusiminus <= : " . ($ st + 1 );
304+ array_push ($ args , $ this ->arg ('rmeas ' ));
305+ }
306+
307+ if ($ this ->has_arg ('cchalf ' )) {
308+ $ st = sizeof ($ args );
309+ $ where .= " AND apssouter.cchalf >= : " . ($ st + 1 );
310+ array_push ($ args , $ this ->arg ('cchalf ' ));
311+ }
312+
313+ if ($ this ->has_arg ('ccanom ' )) {
314+ $ st = sizeof ($ args );
315+ $ where .= " AND apssinner.ccanomalous >= : " . ($ st + 1 );
316+ array_push ($ args , $ this ->arg ('ccanom ' ));
317+ }
318+
319+ if ($ this ->has_arg ('s ' )) {
320+ $ st = sizeof ($ args );
321+ $ where .= " AND (CONCAT(dc.imageprefix,'_',dc.datacollectionnumber) LIKE CONCAT('%',: " . ($ st + 1 ) . ",'%') OR smp.name LIKE CONCAT('%',: " . ($ st + 2 ) . ",'%')) " ;
322+ array_push ($ args , $ this ->arg ('s ' ));
323+ array_push ($ args , $ this ->arg ('s ' ));
324+ }
325+
326+ $ start = 0 ;
327+ $ pp = $ this ->has_arg ('per_page ' ) ? $ this ->arg ('per_page ' ) : 15 ;
328+
329+ if ($ this ->has_arg ('page ' )) {
330+ $ pg = $ this ->arg ('page ' ) - 1 ;
331+ $ start = $ pg * $ pp ;
332+ }
333+
334+ $ order = 'id DESC ' ;
335+
336+ if ($ this ->has_arg ('sort_by ' )) {
337+ $ cols = array (
338+ 'PREFIX ' => 'prefix ' , 'SAMPLE ' => 'sample ' ,
339+ 'ENERGY ' => 'energy ' , 'RESOLUTION ' => 'resolution ' , 'CELL ' => 'cell_a ' ,
340+ 'RES ' => 'overallrhigh ' , 'INNERRMEAS ' => 'innerrmeas ' ,
341+ 'COMPLETENESS ' => 'overallcompleteness ' , 'ANOMCOMPLETENESS ' => 'anomoverallcompleteness ' ,
342+ 'INNERCCANOM ' => 'innerccanom ' , 'OUTERCCHALF ' => 'outercchalf ' ,
343+ 'SG ' => 'sg ' , 'PIPELINE ' => 'pipeline '
344+ );
345+ $ dir = $ this ->has_arg ('order ' ) ? ($ this ->arg ('order ' ) == 'asc ' ? 'ASC ' : 'DESC ' ) : 'ASC ' ;
346+ if (array_key_exists ($ this ->arg ('sort_by ' ), $ cols ))
347+ $ order = $ cols [$ this ->arg ('sort_by ' )] . ' ' . $ dir ;
348+ }
349+
350+ $ jobs = $ this ->db ->pq (
351+ "SELECT dc.datacollectionid as id,
352+ CONCAT(dc.imageprefix, '_', dc.datacollectionnumber) as prefix,
353+ " .self ::EVTOA ."/dc.wavelength as energy,
354+ dc.resolution,
355+ smp.name as sample,
356+ smp.blsampleid,
357+ app.processingprograms as pipeline,
358+ app.autoprocprogramid as aid,
359+ REPLACE(ap.spacegroup,' ','') as sg,
360+ ap.refinedcell_a as cell_a,
361+ ap.refinedcell_b as cell_b,
362+ ap.refinedcell_c as cell_c,
363+ ap.refinedcell_alpha as cell_al,
364+ ap.refinedcell_beta as cell_be,
365+ ap.refinedcell_gamma as cell_ga,
366+ apssover.resolutionlimithigh as overallrhigh,
367+ apssover.resolutionlimitlow as overallrlow,
368+ apssinner.resolutionlimithigh as innerrhigh,
369+ apssinner.resolutionlimitlow as innerrlow,
370+ apssouter.resolutionlimithigh as outerrhigh,
371+ apssouter.resolutionlimitlow as outerrlow,
372+ apssover.completeness as overallcompleteness,
373+ apssinner.completeness as innercompleteness,
374+ apssouter.completeness as outercompleteness,
375+ apssover.anomalouscompleteness as anomoverallcompleteness,
376+ apssinner.anomalouscompleteness as anominnercompleteness,
377+ apssouter.anomalouscompleteness as anomoutercompleteness,
378+ apssinner.rmeasalliplusiminus as innerrmeas,
379+ apssouter.cchalf as outercchalf,
380+ apssinner.ccanomalous as innerccanom
381+ FROM datacollection dc
382+ LEFT OUTER JOIN blsample smp ON dc.blsampleid = smp.blsampleid
383+ INNER JOIN processingjob pj ON dc.datacollectionid = pj.datacollectionid
384+ INNER JOIN autoprocprogram app ON pj.processingjobid = app.processingjobid
385+ INNER JOIN autoproc ap ON app.autoprocprogramid=ap.autoprocprogramid
386+ INNER JOIN autoprocscaling aps ON ap.autoprocid = aps.autoprocid
387+ INNER JOIN autoprocscalingstatistics apssover ON aps.autoprocscalingid = apssover.autoprocscalingid AND apssover.scalingStatisticsType='overall'
388+ INNER JOIN autoprocscalingstatistics apssinner ON aps.autoprocscalingid = apssinner.autoprocscalingid AND apssinner.scalingStatisticsType='innerShell'
389+ INNER JOIN autoprocscalingstatistics apssouter ON aps.autoprocscalingid = apssouter.autoprocscalingid AND apssouter.scalingStatisticsType='outerShell'
390+ WHERE $ where
391+ ORDER BY $ order " ,
392+ $ args
393+ );
394+
395+ // Only take one processing job per data collection id
396+ $ data = array ();
397+ $ dcids = array ();
398+ foreach ($ jobs as $ job ) {
399+ $ dcid = $ job ['ID ' ];
400+ if (!(in_array ($ dcid , $ dcids ))) {
401+ array_push ($ data , $ job );
402+ array_push ($ dcids , $ dcid );
403+ }
404+ }
405+
406+ // Strip down data to only the page needed
407+ $ tot = sizeof ($ data );
408+ $ data = array_slice ($ data , $ start , $ pp );
409+
410+ // Add classes to highlight fields in red/yellow/green
411+ foreach ($ data as &$ d ) {
412+ foreach (array ('OVERALL ' , 'INNER ' , 'OUTER ' ) as $ s ) {
413+ $ c = $ d [$ s .'COMPLETENESS ' ];
414+ $ d [$ s .'COMPLETENESSCLASS ' ] = $ c > 95 ? 'active ' : ($ c > 80 ? 'minor ' : 'inactive ' );
415+ $ c = $ d ['ANOM ' .$ s .'COMPLETENESS ' ];
416+ $ d ['ANOM ' .$ s .'COMPLETENESSCLASS ' ] = $ c > 95 ? 'active ' : ($ c > 80 ? 'minor ' : 'inactive ' );
417+ }
418+ }
419+
420+ // Set number of decimal places
421+ $ nf = array (
422+ 0 => array ('ENERGY ' ),
423+ 2 => array (
424+ 'RESOLUTION ' , 'INNERRMEAS ' , 'OUTERCCHALF ' , 'INNERCCANOM ' ,
425+ 'CELL_A ' , 'CELL_B ' , 'CELL_C ' , 'CELL_AL ' , 'CELL_BE ' , 'CELL_GA ' ,
426+ 'OVERALLRHIGH ' , 'OVERALLRLOW ' , 'INNERRHIGH ' , 'INNERRLOW ' , 'OUTERRHIGH ' , 'OUTERRLOW ' ,
427+ 'OVERALLCOMPLETENESS ' , 'INNERCOMPLETENESS ' , 'OUTERCOMPLETENESS ' ,
428+ 'ANOMOVERALLCOMPLETENESS ' , 'ANOMINNERCOMPLETENESS ' , 'ANOMOUTERCOMPLETENESS '
429+ )
430+ );
431+
432+ foreach ($ nf as $ nff => $ cols ) {
433+ foreach ($ cols as $ c ) {
434+ foreach ($ data as &$ d ) {
435+ $ d [$ c ] = number_format ($ d [$ c ], $ nff );
436+ }
437+ }
438+ }
439+
440+ $ this ->_output (array ('total ' => $ tot , 'data ' => $ data ));
441+
442+ }
443+
241444 /**
242445 * Auto processing results
243446 * (Integration results only)
0 commit comments