install.packages("lubridate")
install.packages("strinr")
library("lubridate")
library("stringr")
library("RODBC")
bdt <- as.POSIXlt("2013-03-28 00:00:00", format="%Y-%m-%d %H:%M:%S")
loopset <- seq(bdt, as.POSIXlt("2013-04-05 00:00:00"), by=3600)
for(i in loopset)
{
tmp <- as.POSIXlt(i, origin="1970-01-01")
ymd <- format(tmp, format="%Y-%m-%d")
hh <- str_sub(str_replace(paste("00", hour(tmp)), " ", ""), -2, -1)
#mi <- str_sub(str_replace(paste("00", minute(tmp)), " ", ""), -2, -1)
#dt <- paste(ymd, " ", hh, ":", mi, ":00", sep = "")
#print(dt)
sql1 <- paste(
"select acnt1, acnt2 ",
"from temp.dbo.sna_animal ",
"where std_dt = '",ymd,"' ",
"and hh = '", hh, "'",
sep = "")
#print(sql1)
edgelist <- sqlQuery(conn, sql1)
g <- graph.data.frame(edgelist, directed=T)
sql2 <- paste(
"insert temp.dbo.sna_result_01 values(",
"'", dt, "',",
graph.density(g), ",",
transitivity(g), ",",
reciprocity(g), ",",
clusters(g, mode="strong")$no, ",'",
hh, "')"
, sep = "")
print(sql2)
sqlQuery(conn, sql2)
}