-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackOregonDbStatusLogger.R
More file actions
executable file
·36 lines (25 loc) · 1.07 KB
/
hackOregonDbStatusLogger.R
File metadata and controls
executable file
·36 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/Rscript
#hackOregonStatusLogger.R
mess <- commandArgs(trailingOnly=TRUE)[1]
source("~/data_infrastructure/orestar_scrape/dbi.R")
dbname = "hackoregon"
# dbname="hack_oregon"
allStats=NULL
if(dbTableExists(tableName="hack_oregon_db_status", dbname=dbname)){
allStats = dbiRead(query="select * from hack_oregon_db_status", dbname=dbname)
}
allTabRes = dbiRead(query="SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;", dbname=dbname)
allTables = allTabRes[allTabRes$table_schema=="public","table_name"]
allTableLengths = c()
for(tn in allTables){
allTableLengths = c(allTableLengths,
dbiRead(query=paste("select count(*) from",tn), dbname=dbname)[1,1])
}
newRow = as.data.frame(matrix(data=allTableLengths, nrow=1, dimnames=list(NULL,allTables)))
newRow = cbind(newRow, date=as.Date(Sys.time()))
if(!is.null(mess)) newRow = cbind(newRow, event_at_log_time=mess)
library(plyr)
dfout = rbind.fill(allStats, newRow)
dbiWrite(tabla=dfout, name="hack_oregon_db_status", dbname=dbname, appendToTable=FALSE)