Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from Open-EO/develop
Browse files Browse the repository at this point in the history
Merging Develop
  • Loading branch information
pramitghosh authored Aug 22, 2018
2 parents 087e3ee + fb3d640 commit fcf0ad4
Show file tree
Hide file tree
Showing 16 changed files with 508 additions and 240 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ Collate:
'MapServerMap-class.R'
'MapServerWeb-class.R'
'ProcessGraph-class.R'
'Product-class.R'
'Product-class.R'
'R2Generic-class.R'
'data.R'
'processes.R'
'Server-class.R'
'Service-class.R'
'Udf-class.R'
'User-class.R'
'View-class.R'
'api_processes.R'
Expand All @@ -75,5 +76,4 @@ Collate:
'api_job.R'
'api_data.R'
'api.R'
'prepare_UDF.R'
'serializer_proxy.R'
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export(R2Generic)
export(Service)
export(SpaceView)
export(TimeView)
export(UdfTransaction)
export(User)
export(View)
export(code)
export(createServerInstance)
export(create_dimensionality)
export(create_dimensionality_modifier)
export(exists.Service)
export(exists.Udf)
export(exists.User)
export(getCollectionFromImageryStatement)
export(is.MapServerConfig)
Expand All @@ -37,12 +39,11 @@ export(is.MapServerWeb)
export(is.Process)
export(is.Product)
export(is.Service)
export(is.Udf)
export(is.User)
export(loadSentinel2Data)
export(raster_collection_export)
export(read_legend)
export(serializer_proxy)
export(udf_export)
export(write_generics)
exportMethods(crs)
exportMethods(extent)
Expand Down
31 changes: 31 additions & 0 deletions R/Collection-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' intermediate results from one process to an other (the result of a process is a Collection).
#'
#' @field dimensions A dimensionality object containing information about the existence of dimensions
#' @field space A tibble containing an index and the geometry
#' @importFrom R6 R6Class
#' @export
Collection <- R6Class(
Expand Down Expand Up @@ -657,3 +658,33 @@ crs.Collection = function(x, ...) {

}

is.st_raster = function(x) {
dims = x$dimensions
return(dims$space && dims$time && dims$raster)
}
# what about multiband / attribute ?

is.st_feature = function(x) {
dims = x$dimensions
return(dims$space && dims$time && dims$feature)
}

is.raster = function(x) {
dims = x$dimensions
return(dims$space && dims$raster && !dims$time)
}

is.feature = function(x) {
dims = x$dimensions
return(dims$space && dims$feature && !dims$time)
}

is.timeseries = function(x) {
dims = x$dimensions
return(dims$time && !dims$space && !dims$raster && !dims$feature)
}

is.scalar = function(x) {
dims = x$dimensions
return(!dims$time && !dims$space && !dims$raster && !dims$feature)
}
28 changes: 22 additions & 6 deletions R/Job-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
#'
#' @field job_id The unique identifier of the job
#' @field status The current status in the job lifecycle
#' @field process_graph graph of nested processes that is executable
#' @field view Spatio-Temporal Extent to be used for the calculation
#' @field process_graph graph of nested processes that is executable (ExecutableProcess)
#' @field view Spatio-Temporal Extent to be used for the calculation (currently not in use)
#' @field submitted Timestamp when the job was submitted to the server
#' @field user_id The user who owns the job
#' @field consumed_credits For accounting and billing the amount of credits consumed by this job
#' @field filePath The system filepath that links to the stored JSON process graph
#' @field last_update Timestamp when the job was last updated
#' @field output output configuration like output$format copied from the process graph (pg)
#' @field results Contains the result of the process_graph after execution (Collection)
#' @field persistent Whether or not the job is stored in database
#' @field output list containing the output configuration like format (or additional GDAL commands)
#'
#' @include Process-class.R
#' @importFrom R6 R6Class
Expand All @@ -31,9 +35,9 @@ Job <- R6Class(
last_update=NULL,
user_id=NULL,
consumed_credits=NULL,
output=NULL,
results = NULL,
persistent = FALSE,
output=NULL, # output configuration like output$format copied from the process graph (pg)
results = NULL, # contains the results of the process_graph after execution
persistent = FALSE, # whether or not the job is stored in data base

# functions ----
initialize = function(job_id=NULL,process_graph=NULL,user_id = NULL) {
Expand Down Expand Up @@ -304,4 +308,16 @@ exists.Job = function(job_id) {
} else {
return(FALSE)
}
}

syncJobId = function() {
randomString = paste("SYNC",createAlphaNumericId(n=1,length=11),sep="")


if (exists.Job(randomString)) {
# if id exists get a new one (recursive)
return(syncJobId())
} else {
return(randomString)
}
}
22 changes: 22 additions & 0 deletions R/R2Generic-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,25 @@ R2Generic = R6Class(

)
)

#' Write generics to disk
#'
#' @description This function writes rasters in a consistent directory structure to disk in generic GeoTIFF formats.
#' It takes as input an object of class `Collection` and the path where the files are to be written to disk. Once the files
#' have been written to disk, it can be loaded into a `stars` object by the user after which custom functions could
#' be applied to it.
#'
#' @param collection_obj Object of class Collection as produced in the previous step while executing the process graph before encountering the UDF
#' @param dir_name Path where the generics are to be written to disk. This could be obtained from the UDF process if it is defined by the user while registering it.
#'
#' @export
#'
write_generics = function(collection_obj, dir_name = "disk") #dir_name could be obtained if it is defined while registering the UDF
{
scene_table = collection_obj$getData()
R2G_obj = R2Generic$new(scenes = scene_table)
R2G_obj$write_scenes(dir_name = dir_name)

R2G_obj$legend_to_disk(dir_name)

}
14 changes: 13 additions & 1 deletion R/Server-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ OpenEOServer <- R6Class(
sqlite.path = NULL,

udf_transactions.path = NULL,
udf_cleanup = TRUE,

api.port = NULL,
host = NULL,
baseserver.url = "http:localhost:8000/api/",
baseserver.url = "http://localhost:8000/api/",
mapserver.url = NULL, #assuming here a url, if not specified the backend is probably started with docker-compose

processes = NULL,
Expand Down Expand Up @@ -190,6 +191,16 @@ OpenEOServer <- R6Class(
)")
}

if (!dbExistsTable(con,"udf")) {
dbExecute(con, "create table udf (
udf_id text,
job_id text,
start_date datetime default current_timestamp,
end_date datetime,
status text
)")
}

dbDisconnect(con)
},

Expand Down Expand Up @@ -264,6 +275,7 @@ OpenEOServer <- R6Class(
}, error = function(e) {
cat(str(e))
}, finally={
removeJobsUdfData(job)
logToConsole()
})

Expand Down
Loading

0 comments on commit fcf0ad4

Please sign in to comment.