IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15167


Ignore:
Timestamp:
Oct 2, 2007, 4:48:49 PM (19 years ago)
Author:
jhoblitt
Message:

improve -pendingimfile's handling of the case where one camera is out of imfiles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pztool.c

    r15156 r15167  
    3737
    3838static bool copydoneCompleteExp(pxConfig *config);
    39 static psArray *pzGetKnownCameras(pxConfig *config);
     39static psArray *pzGetPendingCameras(pxConfig *config);
    4040static psArray *pzArrayZip(psArray *arraySet);
    4141
     
    220220    }
    221221
    222     psArray *cameras = pzGetKnownCameras(config);
     222    psArray *cameras = pzGetPendingCameras(config);
    223223    if (!cameras) {
    224224        psError(PXTOOLS_ERR_DATA, false, "failed to find any cameras");
     
    229229    psArray *cameraImfiles = psArrayAlloc(0);
    230230
     231    // the total number of imfiles retreived so far
     232    long imfiles = 0;
     233    // any slots left over by a query returning less than the per camera limit
     234    long leftOvers = 0;
    231235    for (long i = 0; i < psArrayLength(cameras); i++) {
    232236        psString query = pxDataGet("pztool_pendingimfile.sql");
     
    250254        if (limit) {
    251255            // in the case where the limit asked for is less then the number of
    252             // cameras we have, return 1 imfile per camera
     256            // cameras we have, return 1 imfile per camera and we'll stop
     257            // making per camera queries when we have reached limit.
    253258            if (limit < psArrayLength(cameras)) {
    254259                camLimit = 1;
    255260            } else {
    256261                camLimit = limit / psArrayLength(cameras);
    257                 // add the modulous to the first camera in the list
     262                // add the modulous to the first camera in the list, so if
     263                // limit is not even divsable by the number of cameras, the
     264                // left overs don't get dropped on the floor
    258265                if (i == 0) {
    259266                    camLimit += limit % psArrayLength(cameras);
     
    264271        // treat limit == 0 as "no limit"
    265272        if (camLimit) {
     273            // pickup the left overs from the prevous camera
     274            camLimit += leftOvers;
     275
    266276            // divide limit by the number of cameras
    267277            psString limitString = psDBGenerateLimitSQL(camLimit);
     
    290300        }
    291301
     302        // if we got less rows then the limit for this camera, give the extra
     303        // slots to the next camera.
     304        if (camLimit) {
     305            leftOvers = camLimit - psArrayLength(result);
     306        }
     307
     308        // update the total count of imfiles fetched
     309        imfiles += psArrayLength(result);
     310
    292311        // add this query into the array of result set
    293312        psArrayAdd(cameraImfiles, 0, result);
    294313        psFree(result);
     314
     315        // check to see if we've retreived enough imfiles
     316        if (imfiles >= limit) {
     317            break;
     318        }
    295319    }
    296320
     
    601625}
    602626
    603 static psArray *pzGetKnownCameras(pxConfig *config)
     627static psArray *pzGetPendingCameras(pxConfig *config)
    604628{
    605629    // get a list of cameras we've seen exps for
    606     if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM summitExp")) {
     630    if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM pzPendingImfile")) {
    607631        psError(PS_ERR_UNKNOWN, false, "database error");
    608632        return false;
Note: See TracChangeset for help on using the changeset viewer.