FilterClause.php 4.86 KB
Newer Older
Frank Winkler's avatar
Frank Winkler committed
1 2 3 4 5 6 7 8 9 10
<?php

  function getFilterClause($filterObject, &$sql, &$attributes) {

    $filterArray = [
      'LIVE' => ['STATUS = :status',':status'],
      'NOT_LIVE' => ['STATUS <> :status',':status'],
      'START' => ['START >= :start',':start'],
      'JOB_START' => ['START = :jobstart',':jobstart'],
      'END' => ['START <= :end',':end'],
Ziwen Su's avatar
Ziwen Su committed
11 12
      'EXCLUSIVE' => ['EXCLUSIVE = :exc', ':exc'],
      'JID' => ['JID = :jobid',':jobid'],
Frank Winkler's avatar
Frank Winkler committed
13 14
      'PROJECT' => ['PROJECT = :project',':project'],
      'USER' => ['USER = :user',':user'],
Ziwen Su's avatar
Ziwen Su committed
15
      'STATUS' => ['STATUS = :status', ':status'],
Ziwen Su's avatar
Ziwen Su committed
16 17
      'PARTITION' => ['P_PARTITION LIKE :partition',':partition'],
      'JOB' => ['NAME LIKE :job',':job'],
Frank Winkler's avatar
Frank Winkler committed
18 19 20

      'NODENAME' => ['(NODELIST LIKE :node1 OR CPULIST LIKE :node2)', [':node1', ':node2']],

Ziwen Su's avatar
Ziwen Su committed
21
      'TAGS' => ['TAGS = :tags',':tags'],
22 23 24 25 26 27
      'NUM_NODES_INT' => ['NUM_NODES BETWEEN :min_nodes AND :max_nodes', 'NUM_NODES >=:min_nodes', 'NUM_NODES <=:max_nodes', [':min_nodes', ':max_nodes']],
      'NUM_CORES_INT' => ['NUM_CORES BETWEEN :min_cores AND :max_cores', 'NUM_CORES >=:min_cores', 'NUM_CORES <=:max_cores', [':min_cores', ':max_cores']],
      'WALLTIME_INT' => ['WALLTIME BETWEEN :min_walltime AND :max_walltime', 'WALLTIME >=:min_walltime', 'WALLTIME <=:max_walltime', [':min_walltime', ':max_walltime']],
      'PENDING_INT' => ['(START-SUBMIT) BETWEEN :min_pending AND :max_pending', '(START-SUBMIT) >=:min_pending', '(START-SUBMIT) <=:max_pending', [':min_pending', ':max_pending']],
      'DURATION_INT' => ['(END-START) BETWEEN :min_duration AND :max_duration', '(END-START) >=:min_duration', '(END-START) <=:max_duration', [':min_duration', ':max_duration']],
      'CORE_DURATION_INT' => ['(NUM_CORES*(END-START)) BETWEEN :min_core_duration AND :max_core_duration', '(NUM_CORES*(END-START)) >=:min_core_duration', '(NUM_CORES*(END-START)) <=:max_core_duration', [':min_core_duration', ':max_core_duration']],
28 29 30 31 32

      'IPC_MAX' => ['ipc_mean_per_core <= :ipcmax',':ipcmax'],
      'FLOPS_MAX' => ['flops_any_mean_per_core <= :flopsmax',':flopsmax'],
      'MEM_BW_MAX' => ['mem_bw_mean_per_socket <= :membwmax',':membwmax'],

Frank Winkler's avatar
Frank Winkler committed
33 34 35 36 37
    ];

    $filter = json_decode($filterObject);
    //print_r($filter);
    foreach($filter as $key => $value) {
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

      if ( $key == "FOOTPRINT1_S" || $key == "FOOTPRINT2_S" ) {
        //convert string to array
        $items = explode(" ", $value);

        if ( sizeof($items) >= 2 ) {
          $column_name = convertSelectedFootprintToSQLColumn($items[0]);

          if ( sizeof($items) == 2 ) {
            $attribute_key = ":fp_".$items[0];
            $sql .= "AND ".$column_name." = ".$attribute_key." ";
            $attributes[$attribute_key] = $items[1];
          }

          if ( sizeof($items) == 3 ) {
            $attribute_key1 = ":fp1_".$items[0];
            $attribute_key2 = ":fp2_".$items[0];
Ziwen Su's avatar
Ziwen Su committed
55
            if ( !is_numeric($items[2]) ){
Ziwen Su's avatar
Ziwen Su committed
56 57
              $sql .= "AND ".$column_name." >= ".$attribute_key1." ";
              $attributes[$attribute_key1] = $items[1];
Ziwen Su's avatar
Ziwen Su committed
58
            } elseif ( !is_numeric($items[1]) ){
Ziwen Su's avatar
Ziwen Su committed
59 60 61 62 63 64 65
              $sql .= "AND ".$column_name." <= ".$attribute_key2." ";
              $attributes[$attribute_key2] = $items[2];
            } else{
              $sql .= "AND ".$column_name." BETWEEN ".$attribute_key1." AND ".$attribute_key2." ";
              $attributes[$attribute_key1] = $items[1];
              $attributes[$attribute_key2] = $items[2];
            }
66 67
          }
        }
Frank Winkler's avatar
Frank Winkler committed
68 69 70
      } elseif ( $key == "NODENAME" ) {
        $sql .= "AND ".$filterArray[$key][0]." ";
        $attributes[$filterArray[$key][1][0]] = $value;
71
        $attributes[$filterArray[$key][1][1]] = $value;  
72
      } elseif ( strpos($key, '_INT') !== false ) {
73 74 75 76 77 78 79 80 81 82 83 84
        $items = explode(" ", $value);
        if ( !is_numeric($items[1]) ){
          $sql .= "AND ".$filterArray[$key][1]." ";
          $attributes[$filterArray[$key][3][0]] = $items[0];
        } elseif( !is_numeric($items[0]) ){
          $sql .= "AND ".$filterArray[$key][2]." ";
          $attributes[$filterArray[$key][3][1]] = $items[1];
        } else{
          $sql .= "AND ".$filterArray[$key][0]." ";
          $attributes[$filterArray[$key][3][0]] = $items[0];
          $attributes[$filterArray[$key][3][1]] = $items[1];
        }
85
      } elseif ( $filterArray[$key] ) {
Frank Winkler's avatar
Frank Winkler committed
86 87 88 89 90 91
        $sql .= "AND ".$filterArray[$key][0]." ";
        $attributes[$filterArray[$key][1]] = $value;
      }
    }
  }

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  function convertSelectedFootprintToSQLColumn($footprint)
  {
    $footprint_c = $footprint;

    if ( $footprint == "states" )
      $footprint_c = "STATUS";
    else if ( $footprint == "tags" )
      $footprint_c = "TAGS";
    else if ( $footprint == "duration" )
      $footprint_c = "(END-START)";
    else if ( $footprint == "core_time" )
      $footprint_c = "(NUM_CORES*(END-START))";
    else if ( $footprint == "pending" )
      $footprint_c = "(START-SUBMIT)";
    else
      $footprint_c = $footprint;

    return $footprint_c;
  }
Frank Winkler's avatar
Frank Winkler committed
111
?>