Commit | Line | Data |
---|---|---|
b7cd987d BA |
1 | require(RPostgreSQL) |
2 | ||
3 | ############################## | |
4 | # Follow steps in README first | |
5 | ############################## | |
6 | ||
7 | nb_curves_per_request <- 100 #curves per (select) request | |
8 | ||
9 | # Init connection with DB | |
10 | driver <- PostgreSQL(fetch.default.rec = nb_curves_per_request) | |
11 | con <- dbConnect(driver, user="irsdi", password="irsdi2017", | |
12 | host="localhost", port="5432", dbname="edf25m") | |
13 | ||
14 | # Fill associative array, map index to identifier | |
15 | indexToID_inDB <- as.character( | |
16 | dbGetQuery(con, 'SELECT DISTINCT id FROM series')[,"id"] ) | |
17 | ||
18 | # Function to retrieve curves within some indices range | |
19 | getCurves <- function(indices) | |
20 | { | |
21 | indices = indices[ indices <= length(indexToID_inDB) ] | |
22 | if (length(indices) == 0) | |
23 | return (NULL) | |
24 | request <- "SELECT curve FROM series WHERE id in (" | |
25 | for (i in seq_along(indices)) | |
26 | { | |
27 | request <- paste(request, indexToID_inDB[ indices[i] ], sep="") | |
28 | if (i < length(indices)) | |
29 | request <- paste(request, ",", sep="") | |
30 | } | |
31 | request <- paste(request, ")", sep="") | |
32 | df_series <- dbGetQuery(con, request) | |
33 | ||
34 | #weird result: an integer, and then string "{val1,val2,val3,...,valD}" :/ | |
35 | #print(summary(df_series)) | |
36 | df_series | |
37 | # matrix(df_series[,"value"], ncol=length(indices)) | |
38 | } | |
39 | ||
40 | # Test | |
41 | #curves <- getCurves(c(1:3,7,11)) | |
42 | library(epclust) | |
43 | res <- claws(getCurves, 50, 15, 500, 500, random=FALSE, ncores_clust=3, verbose=TRUE) | |
44 | ||
45 | dbDisconnect(con) | |
46 | unlink(temp_file) |