IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15108


Ignore:
Timestamp:
Sep 28, 2007, 6:05:49 PM (19 years ago)
Author:
jhoblitt
Message:

twiddle with -pendingimfile to try and report equal numbers of entires for each camera instead of purely listing by order of insertion

File:
1 edited

Legend:

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

    r15062 r15108  
    218218    }
    219219
    220     psString query = pxDataGet("pztool_pendingimfile.sql");
    221     if (!query) {
    222         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    223         return false;
    224     }
    225 
    226     if (config->where) {
    227         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzPendingImfile");
    228         psStringAppend(&query, " AND %s", whereClause);
    229         psFree(whereClause);
    230     }
    231 
    232     // treat limit == 0 as "no limit"
    233     if (limit) {
    234         psString limitString = psDBGenerateLimitSQL(limit);
    235         psStringAppend(&query, " %s", limitString);
    236         psFree(limitString);
    237     }
    238 
    239     if (!p_psDBRunQuery(config->dbh, query)) {
    240         psError(PS_ERR_UNKNOWN, false, "database error");
     220    // get a list of cameras we've seen exps for
     221    if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM summitExp")) {
     222        psError(PS_ERR_UNKNOWN, false, "database error");
     223        return false;
     224    }
     225
     226    psArray *cameras = p_psDBFetchResult(config->dbh);
     227    if (!cameras) {
     228        psError(PS_ERR_UNKNOWN, false, "database error");
     229        return false;
     230    }
     231    if (!psArrayLength(cameras)) {
     232        psTrace("pztool", PS_LOG_INFO, "no rows found");
     233        psFree(cameras);
     234        return true;
     235    }
     236
     237    for (long i = 0; i < psArrayLength(cameras); i++) {
     238        psString query = pxDataGet("pztool_pendingimfile.sql");
     239        if (!query) {
     240            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     241            return false;
     242        }
     243
     244        psString camera = psMetadataLookupStr(&status, cameras->data[i], "camera");
     245        psStringAppend(&query, " WHERE camera = \"%s\"", camera);
     246
     247        if (config->where) {
     248            psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzPendingImfile");
     249            psStringAppend(&query, " AND %s", whereClause);
     250            psFree(whereClause);
     251        }
     252
     253
     254        // treat limit == 0 as "no limit"
     255        if (limit) {
     256            // divide limit by the number of cameras
     257            psString limitString = psDBGenerateLimitSQL((limit / psArrayLength(cameras) || 1));
     258            psStringAppend(&query, " %s", limitString);
     259            psFree(limitString);
     260        }
     261
     262        if (!p_psDBRunQuery(config->dbh, query)) {
     263            psError(PS_ERR_UNKNOWN, false, "database error");
     264            psFree(query);
     265            return false;
     266        }
    241267        psFree(query);
    242         return false;
    243     }
    244     psFree(query);
    245 
    246     psArray *output = p_psDBFetchResult(config->dbh);
    247     if (!output) {
    248         psError(PS_ERR_UNKNOWN, false, "database error");
    249         return false;
    250     }
    251     if (!psArrayLength(output)) {
    252         psTrace("pztool", PS_LOG_INFO, "no rows found");
    253         psFree(output);
    254         return true;
    255     }
    256 
    257     bool simple = false;
    258     {
    259         bool status = false;
    260         simple = psMetadataLookupBool(&status, config->args, "-simple");
    261         if (!status) {
    262             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     268
     269        psArray *output = p_psDBFetchResult(config->dbh);
     270        if (!output) {
     271            psError(PS_ERR_UNKNOWN, false, "database error");
     272            return false;
     273        }
     274        if (!psArrayLength(output)) {
     275            psTrace("pztool", PS_LOG_INFO, "no rows found");
    263276            psFree(output);
    264             return false;
    265         }
    266     }
    267 
    268     // negative simple so the default is true
    269     if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) {
    270         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    271         psFree(output);
    272         return false;
    273     }
    274 
    275     psFree(output);
     277            return true;
     278        }
     279
     280        bool simple = false;
     281        {
     282            bool status = false;
     283            simple = psMetadataLookupBool(&status, config->args, "-simple");
     284            if (!status) {
     285                psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     286                psFree(output);
     287                return false;
     288            }
     289        }
     290
     291        // negative simple so the default is true
     292        if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) {
     293            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     294            psFree(output);
     295            return false;
     296        }
     297
     298        psFree(output);
     299    }
    276300
    277301    return true;
Note: See TracChangeset for help on using the changeset viewer.