[codeface] [PATCH v2 17/24] Fix ML test by introducing a release range

  • From: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
  • To: codeface@xxxxxxxxxxxxx
  • Date: Thu, 1 Dec 2016 17:11:11 +0100

As there are no cycles (i.e., release ranges) in the database for the
ML test project, the subsetting of the result in the function
'get.cycles.con' throws an error.

The problem is fixed by introducing a single revision range for the ML
test project and the needed functions for inserting everything into the
database.

Fix trailing whitespace along the way.

Signed-off-by: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
---
 codeface/R/db.r               | 35 +++++++++++++++++++++++++++++++----
 codeface/R/ml/test_analysis.r |  8 ++++++--
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/codeface/R/db.r b/codeface/R/db.r
index a881656..22b91ca 100644
--- a/codeface/R/db.r
+++ b/codeface/R/db.r
@@ -137,6 +137,19 @@ get.revision.id <- function(conf, tag) {
   return(res$id)
 }
 
+gen.revision.id <- function(conf, tag, date) {
+  ## add new revision
+  dat <- data.frame(type='release', tag=tag, date=date, projectId=conf$pid)
+  dbWriteTable(conf$con, "release_timeline", dat, row.names=FALSE, append=TRUE)
+
+  ## get ID of the newly added revision
+  res <- dbGetQuery(conf$con, str_c("SELECT id FROM release_timeline ",
+                               "WHERE projectId=", sq(conf$pid),
+                               " AND tag=", sq(tag),
+                               " AND type='release'"))
+  return(res$id)
+}
+
 get.range.id <- function(conf, tag.start, tag.end) {
   start.id <- get.revision.id(conf, tag.start)
   end.id <- get.revision.id(conf, tag.end)
@@ -148,6 +161,20 @@ get.range.id <- function(conf, tag.start, tag.end) {
   return(res$id[1])
 }
 
+gen.range.id <- function(conf, start, end, rc = NA) {
+  ## add new release range
+  dat <- data.frame(releaseStartId=start, releaseEndId=end,
+                    projectId=conf$pid, releaseRCStartId=rc)
+  dbWriteTable(conf$con, "release_range", dat, row.names=FALSE, append=TRUE)
+
+  ## get ID of the newly added release
+  res <- dbGetQuery(conf$con, str_c("SELECT id FROM release_range ",
+                               "WHERE projectId=", sq(conf$pid),
+                               " AND releaseStartId=", sq(start),
+                               " AND releaseEndId=", sq(end)))
+  return(res$id)
+}
+
 # Get release and release candidate dates for a given project
 get.release.rc.dates <- function(conf) {
   res <- dbGetQuery(conf$con,
@@ -339,7 +366,7 @@ get.graph.data.local <- function(con, p.id, range.id, 
cluster.method=NULL) {
     rank=NULL
   }
   else {
-    ## get graph communities 
+    ## get graph communities
     local.comm <- get.communities.local(con, p.id, range.id, id.map,
                                         cluster.method)
   }
@@ -363,7 +390,7 @@ get.communities.local <- function(con, p.id, range.id, 
id.map, cluster.method){
                            prank=TRUE, technique=0))
   ## get the cluster members
   cluster.mem <- lapply(cluster.data, function(cluster) cluster$personId)
-  ## reconstruct igraph style communities object 
+  ## reconstruct igraph style communities object
   comm <- clusters.2.communities(cluster.mem, cluster.method, id.map)
 
   ## rank
@@ -397,7 +424,7 @@ get.index.map <- function(ids) {
 ## Remap all ids in the given a mapping
 ## Args:
 ##  ids: id index vector (non-consecutive)
-##  map: environment (hash table) mapping global index to consecutive local 
+##  map: environment (hash table) mapping global index to consecutive local
 ##       index
 ## Returns:
 ##  edgelist: edge list with remapped node index
@@ -415,7 +442,7 @@ map.ids <- function(ids, map){
 ## Create communities object from clusters list
 ## Args:
 ##  clusters: list of global personId vectors mapping people to clusters
-##  map: environment (hash table) to map non-consecutive global index to 
+##  map: environment (hash table) to map non-consecutive global index to
 ##       consecutive local index
 ## Returns:
 ##  comm: igraph-like communities object; NULL if there are no communities
diff --git a/codeface/R/ml/test_analysis.r b/codeface/R/ml/test_analysis.r
index 8a7871c..1b4e7a4 100644
--- a/codeface/R/ml/test_analysis.r
+++ b/codeface/R/ml/test_analysis.r
@@ -42,14 +42,18 @@ test.check.corpus.precon <- function() {
 test.global.analysis <- function () {
   project.name <- "test_mail"
   analysis.method <- "none"
+  start.date <- "2000-01-01"
+  end.date <- "2020-01-01"
+
   conf$pid <- gen.clear.project.id.con(conf$con, project.name, analysis.method)
+  start.id <- gen.revision.id(conf, "v1.0", start.date)
+  end.id <- gen.revision.id(conf, "v1.1", end.date)
+  range <- gen.range.id(conf, start.id, end.id)
 
   ## Run analysis
   dispatch.all(conf, path, res.dir)
 
   ## Query for edgelist
-  start.date <- "2000-01-01"
-  end.date <- "2020-01-01"
   edgelist <- query.mail.edgelist(conf$con, conf$pid, start.date, end.date)
 
   ## Get author id to name mapping
-- 
2.10.2


Other related posts:

  • » [codeface] [PATCH v2 17/24] Fix ML test by introducing a release range - Claus Hunsen