- separate the graph indexing manipulation from the database writing - remove redundant cluster user index mapping, we already do that to get the edge lists Signed-off-by: Mitchell Joblin <mitchell.joblin.ext@xxxxxxxxxxx> --- codeface/R/cluster/persons.r | 18 ++---------------- codeface/R/db.r | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/codeface/R/cluster/persons.r b/codeface/R/cluster/persons.r index c1fd1b1..a1d9328 100755 --- a/codeface/R/cluster/persons.r +++ b/codeface/R/cluster/persons.r @@ -695,20 +695,8 @@ save.group <- function(conf, .tags, .iddb, idx, .prank, .filename=NULL, label) { } -## Write clusters into the database +## Prepare graph data for database and insert store.graph.db <- function(conf, baselabel, idx, .iddb, g.reg, g.tr, j) { - cluster.id <- get.clear.cluster.id(conf, conf$range.id, baselabel, j) - - users.df <- lapply(idx, function(index.local) { - person.id <- .iddb[index.local,]$ID.orig - return(data.frame(id=NA, personId=person.id, clusterId=cluster.id)) - }) - users.df <- do.call(rbind, users.df) - - dbWriteTable(conf$con, "cluster_user_mapping", users.df, append=TRUE, row.names=FALSE) - - ## TODO: Insert the generated dot files into the database - ## Construct a systematic representation of the graph for the data base edges <- get.data.frame(g.reg, what="edges") colnames(edges) <- c("fromId", "toId") @@ -731,9 +719,7 @@ store.graph.db <- function(conf, baselabel, idx, .iddb, g.reg, g.tr, j) { if (dim(edges)[1] > 0) { ## Only write an edge list if the cluster has any edges, actually edges <- gen.weighted.edgelist(edges) - edges <- cbind(clusterId=cluster.id, edges) - - dbWriteTable(conf$con, "edgelist", edges, append=TRUE, row.names=FALSE) + write.graph.db(conf, conf$range.id, baselabel, edges, j) } } diff --git a/codeface/R/db.r b/codeface/R/db.r index 3e389e3..1e6023b 100644 --- a/codeface/R/db.r +++ b/codeface/R/db.r @@ -424,3 +424,20 @@ clusters.2.communities <- function(cluster.list, cluster.method, map) { return(comm) } + + +## Write graph data into the database +write.graph.db <- function(conf, range.id, baselabel, edgelist, j) { + ## Get a unique cluster id + cluster.id <- get.clear.cluster.id(conf, range.id, baselabel, j) + + ## Get all ids and write the user cluster mapping + users <- unique(c(edgelist$fromId, edgelist$toId)) + users.df <- data.frame(id=NA, personId=users, clusterId=cluster.id) + dbWriteTable(conf$con, "cluster_user_mapping", users.df, append=TRUE, row.names=FALSE) + + ## Write edge list into database + edgelist <- cbind(clusterId=cluster.id, edgelist) + dbWriteTable(conf$con, "edgelist", edgelist, append=TRUE, row.names=FALSE) + ## TODO: Insert the generated dot files into the database +} -- 1.8.3.2