#source("/Users/User/Desktop/PROJECT_BSC/MetaclipR/metaclipR-master/R/metaclip-helpers.R")


#recipe<-read_yaml("/Users/User/Desktop/recipe_decadal_provenance.yml")



graph <- make_empty_graph(directed = TRUE)
emptygraph <- FALSE



#Dataset definitions, should be extracted from recipe!!!

Dataset.nodename = paste0("Dataset.", randomName())
DataProvider = "ECMWF" #Extract from the loaded data itself!!!
# DataProvider.URL = url,
Dataset.subclass = "SeasonalHindcast" #Should be defined accordingly to the loaded data
#Project = recipe$Analysis$Datasets$Reference$name
ModellingCenter = "ECMWF" #Extract from the loaded data itself!!!

Dataset.name<-paste0("ds:", Dataset.subclass)

#Add dataset node
graph <- add_vertices(graph,
                      nv = 1,
                      name = Dataset.nodename,
                      label = "SUNSET Sample Seasonal Dataset",
                      className = Dataset.name)


#Data Provider Node
DataProvider.nodename<-paste0("ds:",DataProvider)


graph <- my_add_vertices(graph,
                         nv=1,
                         name = DataProvider.nodename,
                         label = DataProvider,
                         className = "ds:DataProvider"
)

graph <- add_edges(graph, 
                   c(getNodeIndexbyName(graph, Dataset.nodename),
                     getNodeIndexbyName(graph, DataProvider.nodename)),
                   label = "ds:hadDataProvider")


ModellingCenter.nodename<-paste0("ds:",ModellingCenter)

#Add Modelling Center sublcass node
graph <- my_add_vertices(graph,
                         nv = 1,
                         name=ModellingCenter.nodename,
                         label = ModellingCenter,
                         className = "ds:ModellingCenter")

graph <- add_edges(graph, 
                   c(getNodeIndexbyName(graph, Dataset.nodename),
                     getNodeIndexbyName(graph, ModellingCenter.nodename)),
                   label = "ds:hadModellingCenter")

#Have to fix the fact that DataProvider and Modelling Center are the same?


#Add Project Node
#Project.nodename<-paste0("Project.", randomName())
#graph <- my_add_vertices(graph,
                   #      nv = 1,
                    #     name = Project.nodename,
                     #    label = Project,
                         className = "ds:Project")
#graph <- add_edges(graph, 
                   #c(getNodeIndexbyName(graph, Dataset.nodename),
                   #  getNodeIndexbyName(graph, Project.nodename)),
                  # label = "ds:hadProject")

metadata<- list("graph"=graph, "parentnodename"=Dataset.nodename)


graph2json(metadata$graph, "/esarchive/scratch/apuiggro/graph22.json")
plot(graph)

