IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28924


Ignore:
Timestamp:
Aug 16, 2010, 2:03:36 PM (16 years ago)
Author:
rhenders
Message:

Changes to incorporate addition of update labels to czartool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czartool/Gpc1Db.pm

    r28719 r28924  
    88use czartool::MySQLDb;
    99our @ISA = qw(czartool::MySQLDb);    # inherits from MySQLDb
     10
     11###########################################################################
     12#
     13# Returns the right join table and ID to join on for for a given stage TODO make private
     14#
     15###########################################################################
     16sub getJoinTableAndId {
     17    my ($self, $stage, $joinTable, $id) = @_;
     18
     19    ${$id} = $stage."_id";
     20
     21    if ($stage eq "chip") {${$joinTable}="chipProcessedImfile";}
     22    elsif ($stage eq "cam") {${$joinTable}="camProcessedExp";}
     23    elsif ($stage eq "fake") {${$joinTable}="fakeProcessedImfile";}
     24    elsif ($stage eq "warp") {${$joinTable}="warpSkyfile";}
     25    elsif ($stage eq "stack") {${$joinTable}="stackSumSkyfile";}
     26    elsif ($stage eq "diff") {${$joinTable}="diffSkyfile";}
     27    elsif ($stage eq "magic") {${$joinTable}="magicNodeResult";}
     28    elsif ($stage eq "magicDS") {${$id} = "magic_ds_id"; ${$joinTable}="magicDSFile";}
     29    elsif ($stage eq "dist") {${$joinTable}="distComponent";}
     30    else {
     31
     32        print "* ERROR: could nod find joinTable and ID for '$stage' stage\n";
     33        return 0;
     34    }
     35
     36    return 1;
     37}
    1038
    1139###########################################################################
     
    3058}
    3159
    32 
    3360###########################################################################
    3461#
     
    3764###########################################################################
    3865sub countFaults {
    39     my ($self, $label, $stage) = @_;
     66    my ($self, $label, $stage, $state) = @_;
    4067
    41 
    42     my $table = getTableForStage($self, $stage);
    43     my $joinTable;
    44     my $id = $stage."_id";
    45 
    46     if ($stage eq "chip") {$joinTable="chipProcessedImfile";}
    47     elsif ($stage eq "cam") {$joinTable="camProcessedExp";}
    48     elsif ($stage eq "fake") {$joinTable="fakeProcessedImfile";}
    49     elsif ($stage eq "warp") {$joinTable="warpSkyfile";}
    50     elsif ($stage eq "stack") {$joinTable="stackSumSkyfile";}
    51     elsif ($stage eq "diff") {$joinTable="diffSkyfile";}
    52     elsif ($stage eq "magic") {$joinTable="magicNodeResult";}
    53     elsif ($stage eq "magicDS") {$id = "magic_ds_id"; $joinTable="magicDSFile";}
    54     elsif ($stage eq "dist") {$joinTable="distComponent";}
    55     else {return -1;}
     68    my $table = undef;
     69    my $joinTable = undef;
     70    my $id = undef;
     71    $table = getTableForStage($self, $stage);
     72    if (!getJoinTableAndId($self, $stage, \$joinTable, \$id)) {return -1;}
    5673
    5774    my $faultCol =  $joinTable.".fault";
     
    6481        WHERE label LIKE '$label'
    6582        AND $faultCol != 0
    66         AND $stateCol = 'new'
     83        AND $stateCol = '$state'
    6784SQL
    6885
     
    85102SQL
    86103
    87         $query->execute;
     104    $query->execute;
    88105    my $priority = scalar $query->fetchrow_array();
    89106    if (!$priority) {return 50000;} # assume labels not given priority in gpc1 Db have highest priority
     
    100117
    101118    my $table = getTableForStage($self, $stage);
    102     if ($state eq "fault") {return countFaults($stage);}
     119    my $query = undef;
     120
     121    if ($state eq "update") {
     122
     123        if ($stage eq "dist") {return 0;}
     124        my $joinTable = undef;
     125        my $id = undef;
     126        if (!getJoinTableAndId($self, $stage, \$joinTable, \$id)) {return -1;}
     127
     128        if ($stage eq "chip" || $stage eq "fake" || $stage eq "warp" || $stage eq "diff" || $stage eq "magicDS") {
     129            $query = $self->{_db}->prepare(<<SQL);
     130            SELECT COUNT(state)
     131                FROM $table JOIN $joinTable
     132                USING($id)
     133                WHERE label LIKE '$label'
     134                AND state = 'update'
     135                AND data_state = 'update';
     136SQL
     137        }
     138        else {
     139       
     140            $query = $self->{_db}->prepare(<<SQL);
     141            SELECT COUNT(state)
     142                FROM $table JOIN $joinTable
     143                USING($id)
     144                WHERE label LIKE '$label'
     145                AND state = 'update';
     146SQL
     147        }
     148
     149    }
     150    else {
     151
     152        $query = $self->{_db}->prepare(<<SQL);
     153        SELECT COUNT(state) 
     154            FROM $table
     155            WHERE label LIKE '$label'
     156            AND state = '$state'
     157SQL
     158    }
    103159
    104160
    105     my $query = $self->{_db}->prepare(<<SQL);
    106     SELECT count(state) 
    107         FROM $table
    108         WHERE label LIKE '$label'
    109         AND state = '$state'
    110 SQL
    111 
    112         $query->execute;
     161    $query->execute;
    113162    return scalar $query->fetchrow_array();
    114163}
Note: See TracChangeset for help on using the changeset viewer.