コード例 #1
0
 function get_view(done){
     viewer(opts,function(e,r){
         if(e) return done(e)
         var rows = r.rows
         var norows = rows.length === 0
         var alldone = r.total_rows === 0
         viewsize = r.total_rows
         //console.log(rows)
         if(norows || alldone){
             console.log('norows',norows,'alldone',alldone)
             return done(null,0)
         }
         deleter(rows,function(e,r){
             if(e) return done(e)
             return done(null)
         })
         return null
     })
 }
コード例 #2
0
function get_details(task,callback){
    var opts={}
    opts.db=task.couchdb.detector_display_db
    opts.reduce=false
    opts.include_docs=true
    if(task.components === undefined || task.components.length < 1){
        console.log(_.keys(task))
        console.log(task.components)
        return callback(null,task)
    }
    // make sure that the "detectors" array matches the couchdb
    // database's id requirements
    var patterns= {'wim':/(wim\.\d*\.[NSEW])/
                  ,'vds':/(\d{5,7})/
                  }

    opts.keys = task.components.map(function(v){
                    var result = patterns.wim.exec(v)
                    if(result && result[1]){
                        return result[1]
                    }
                    result=patterns.vds.exec(v)
                    if(result && result[1]){
                        return result[1]
                    }
                    return null
                })


    get_docs(opts,function(e,r){
        if(e) return callback(e,null)
        task.component_details = {}

        r.rows.forEach(function(row){
            var properties
            if(!row.doc){
                return null
                console.log(row)
                throw new Error(row)
            }
            if(row.doc.properties !== undefined){
                properties = check_property(row.doc.properties)
            }else{
                var years = Object.keys(row.doc)
                _.some(years,function(y){
                    properties =  check_property(row.doc[y].properties)
                    if(properties){
                        return true
                    }
                    return false
                })
            }
            task.component_details[row.id] = properties
            return null
        })

        return callback(e,task)
    })
    return null

}