It was a project involving R and Cassandra to represent the customers on Google Maps.
================================================================
--// Full Code
================================================================
library(shiny)
library(RODBC)
library(RCassandra)
library(googleVis)
library(dplyr)
library(magrittr)
# getMapData(testConnection)
getMapData <- function(connection){
#RC.read.table(connection, c.family, convert = TRUE, na.strings = "select Latitude, Lon, suburb, typeOfSale, category from tbReckonGoogle", as.is = FALSE, dec = ".")
RC.read.table(connection, "tbReckonGoogle")
}
# sqlQuery(connection, "select Distinct
#
#
#
#
#
# from Onyx.dbo.zOnyxCustomerView c
# inner join tbNZPostcode p on c.vchPostCode = p.postcode and charindex(replace(dbo.
# inner join vCustomerproduct CP on CP.iOwnerId = c.iOnyxId
# inner join ProductMaster PM ON PM.chProductNumber = CP.chProductNumber
# inner join vReferenceDefinition rd1 ON rd1.iParameterId = PM.vchUser1
# inner join vReferenceDefinition rd2 ON rd2.iParameterId = PM.vchUser2
# where chCountryCode = 'NZ'
#
#
#
# and rd1.vchParameterDesc in ('Quicken', 'Quickbooks')
#
#}
# filterMapData(gps, "Epsom", "All", "All")
# filterMapData(gps, "Remuera", "QuickBooks", "Full Version")
# filterMapData(gps, "All", "All", "All")
filterMapData <- function (gpsData, gpsSuburb, gpsCategory, gpsTypeOfSale) {
gpsData %>%
filter((gpsSuburb == suburb | gpsSuburb == "All") &
(gpsCategory == category | gpsCategory == "All") &
(gpsTypeOfSale == typeOfSale | gpsTypeOfSale == "All"))
}
# sampleMapData(gps, 10)
sampleMapData <- function (gpsData, topCount) {
maxTopCount <- nrow(gpsData)
topCount <- min(topCount, maxTopCount)
gpsData %>%
sample_n(topCount)
}
# drawMapData(gps)
drawMapData <- function (gpsData) {
gpsData %>%
gvisMap(options=list(showTip=
mapType='normal',
width=400,
height=1000))
}
# createMap(gps, "Epsom", "All", "All", 10)
createMap <- function (mapData, gpsSuburb, gpsCategory, gpsTypeOfSale, topCount) {
mapData %>%
filterMapData(gpsSuburb, gpsCategory, gpsTypeOfSale) %>%
sampleMapData(topCount) %>%
drawMapData
}
# materialise the GPS map data from Onyx
#connection <- odbcConnect("STAONYX", uid="usr_studioR", pwd="******")
#connection <- odbcConnect("Cassandra", uid="usr_studioR", pwd="******")
#connection <- odbcConnect("10.64.12.248")
#connection <- RC.connect(host = "10.64.12.40", port = 9042)
connection <- RC.connect("10.64.12.40")
RC.use(connection, "onyxdb")
gps <- getMapData(connection)
shinyServer(function(input, output) {
output$map <- renderGvis({
gps %>%
createMap(input$neighbours,
})
})