Created
April 7, 2016 13:54
-
-
Save adamml/8908edb9af70837c0ae2e78704cbb227 to your computer and use it in GitHub Desktop.
Observatory bulletin for Jupyter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install.packages("RCassandra", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") | |
library(RCassandra) | |
#Function to make sure we're dealing with a month and | |
#year for which we have data | |
fixMonthYear <- function(year,month){ | |
nowDate <- Sys.Date() | |
nowYear <- strtoi(substr(nowDate,1,4)) | |
nowMonth <- strtoi(substr(nowDate,6,7)) | |
if(year < 2015) { | |
year = 2015 | |
month = 10 | |
} | |
else if (year == 2015 && month < 10){ | |
month = 10 | |
} | |
else if (year == nowYear && month >= nowMonth){ | |
month = nowMonth - 1 | |
if(month == 0) | |
{ | |
month = 12 | |
year = year - 1 | |
} | |
} | |
else if (year > nowYear){ | |
month = nowMonth - 1 | |
year = nowYear | |
if(month == 0) | |
{ | |
month = 12 | |
year = year - 1 | |
} | |
} | |
return(c(year,month)) | |
} | |
#How many days are there in a month? | |
#TODO: Fix for leap years | |
lookupDaysOfMonth <- function(month){ | |
days <- c(31,28,31,30,31,30,31,31,30,31,30,31) | |
return(days[c(month)]) | |
} | |
#Get the month name | |
lookupMonthString <- function(month){ | |
months <- c("January","February","March","April","May","June","July","August","September","October","November","Devcember") | |
return(days[c(months)]) | |
} | |
spiddalBulletin <- function(year,month){ | |
#TODO: Invocation checks | |
#Check the year and month supplied are in range, if not - fix them | |
ym <- fixMonthYear(year,month) | |
year = ym[1] | |
month = ym[2] | |
#Connect to Cassandra DB | |
rc <- RC.connect(host = "xxx.xx.x.xx", port = xxxxx) | |
RC.cluster.name(rc) | |
RC.use(rc, "das") | |
print(RC.get.range.slices(rc, "fluorometer", limit=0)) | |
print(RC.get.range(rc, "fluorometer","WL-ECO-FLNTU-3137",limit=10)) | |
print(RC.get.range(rc, "fluorometer","spiddal-fluorometer",limit=10)) | |
RC.close(rc) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment