|
| 1 | +retrieve_sleepers_product <- function(network, |
| 2 | + domain, |
| 3 | + prodname_ms, |
| 4 | + site_code, |
| 5 | + tracker, |
| 6 | + url){ |
| 7 | + # creating a string which matches the names of processing kernels |
| 8 | + processing_func <- get(paste0('process_0_', |
| 9 | + # these names or based off of prod names in products.csv |
| 10 | + prodcode_from_prodname_ms(prodname_ms))) |
| 11 | + |
| 12 | + # tracking the "version" of the product |
| 13 | + rt <- tracker[[prodname_ms]][[site_code]]$retrieve |
| 14 | + |
| 15 | + held_dt <- as.POSIXct(rt$held_version, |
| 16 | + tz = 'UTC') |
| 17 | + |
| 18 | + # "deets" is a list of all the information originally from a row in products.csv |
| 19 | + deets <- list(prodname_ms = prodname_ms, |
| 20 | + site_code = site_code, |
| 21 | + component = rt$component, |
| 22 | + last_mod_dt = held_dt, |
| 23 | + url = url) |
| 24 | + |
| 25 | + # these "deets" are fed as arguments to wwhatever processing kernel is currently being called |
| 26 | + # remember, this "retrieve_product" function is being called, in the retrieve.R script, |
| 27 | + # in a loop over the product names from products.csv -- this is why the products.csv prod names |
| 28 | + # must match the end of the procesing kernels which are written to retrieve that product |
| 29 | + |
| 30 | + # if you're working on pkernels and not actually running this func, uncomment and run these lines: |
| 31 | + ## set_details = deets |
| 32 | + ## network = network |
| 33 | + ## domain = domain |
| 34 | + |
| 35 | + result <- do.call(processing_func, |
| 36 | + args = list(set_details = deets, |
| 37 | + network = network, |
| 38 | + domain = domain)) |
| 39 | + |
| 40 | + |
| 41 | + new_status <- evaluate_result_status(result) |
| 42 | + |
| 43 | + if('access_time' %in% names(result) && any(! is.na(result$access_time))){ |
| 44 | + deets$last_mod_dt <- result$access_time[! is.na(result$access_time)][1] |
| 45 | + } |
| 46 | + |
| 47 | + update_data_tracker_r(network = network, |
| 48 | + domain = domain, |
| 49 | + tracker_name = 'held_data', |
| 50 | + set_details = deets, |
| 51 | + new_status = new_status) |
| 52 | + |
| 53 | + source_urls <- get_source_urls(result_obj = result, |
| 54 | + processing_func = processing_func) |
| 55 | + |
| 56 | + write_metadata_r(murl = source_urls, |
| 57 | + network = network, |
| 58 | + domain = domain, |
| 59 | + prodname_ms = prodname_ms) |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +retrieve_usgs_sleeper_daily_q <- function(set_details) { |
| 64 | + if(grepl("w5", set_details$component) == TRUE) { |
| 65 | + q <- dataRetrieval::readNWISdv(siteNumbers = "01135300", |
| 66 | + parameterCd = "00060") |
| 67 | + } else if(grepl("w3", set_details$component) == TRUE) { |
| 68 | + q <- dataRetrieval::readNWISdv(siteNumbers = "01135150", |
| 69 | + parameterCd = "00060") |
| 70 | + } |
| 71 | + |
| 72 | + return(q) |
| 73 | +} |
0 commit comments