Skip to content

Instantly share code, notes, and snippets.

@nad2000
Created June 9, 2013 02:12
Show Gist options
  • Save nad2000/5737340 to your computer and use it in GitHub Desktop.
Save nad2000/5737340 to your computer and use it in GitHub Desktop.
Distribution of sample counts per gap value between the current sample and the previous one
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="6", user="postgres", host="192.168.132.111")
# dbListConnections(drv)
# dbGetInfo(drv)
# summary(con)
rs <- dbSendQuery(con,"
SELECT
delta, delta_cnt ,
round(100*delta_cnt::numeric/(sum(delta_cnt) OVER ()),2) \"delta %\"
FROM (
SELECT delta, count(*) AS delta_cnt FROM (
SELECT
flow_id,
last_time_sec-lag(last_time_sec)
OVER (partition by flow_id order by last_time_sec /* byte_count_1+byte_count_2*/) AS delta
FROM long_flow_samples ) AS d
WHERE delta IS NOT NULL -- AND delta != 0
GROUP BY delta
ORDER BY 1 DESC ) AS stats")
gaps <- fetch(rs,n=-1)
plot(
gaps$delta_cnt ~ gaps$delta,
col="red",
xlab="Gaps between samples (sec)",
ylab="Sample Counts",
main="Distribution of sample counts per gap value between the current sample and the previous one")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment