Skip to content

Instantly share code, notes, and snippets.

@saptarshiguha
Created March 29, 2018 04:00
Show Gist options
  • Save saptarshiguha/aed11a8b87a954efb5588f60d2833975 to your computer and use it in GitHub Desktop.
Save saptarshiguha/aed11a8b87a954efb5588f60d2833975 to your computer and use it in GitHub Desktop.
```{r}
releases <- local({
x <- fromJSON(file='https://product-details.mozilla.org/1.0/firefox_history_major_releases.json')
f <- rbindlist(Map(function(a,b){
data.table(version=a, from=b)
},names(x), x))
f$from<- as.Date(f$from)
f$to <- c(tail(f$from,-1)-1,as.Date('2025-01-01'))
f
})
```
```{r}
usefulr <- releases[from>='2016-07-01',]
```
```{r}
getD <- function(version,from,to){
query <- sprintf('
q = spark.sql("""
with a as (select
submission_date_s3 as date,
count(distinct(client_id)) as dauAll
from main_summary
where app_name=\'Firefox\'
and sample_id=\'42\'
and normalized_channel=\'release\'
and submission_date_s3>=\'%s\' and submission_date_s3<=\'%s\'
group by 1
order by 1
),
b as (select
submission_date_s3 as date,
count(distinct(client_id)) as dauLatest
from main_summary
where app_name=\'Firefox\'
and sample_id=\'42\'
and normalized_channel=\'release\'
and submission_date_s3>=\'%s\' and submission_date_s3<=\'%s\'
and substr(app_version,1,2)=\'%s\'
group by 1
order by 1
)
select a.date, a.dauAll*100 as dauAll, b.dauLatest*100 as dauLatest,
b.dauLatest/a.dauAll as pctLatest
from a join b
on a.date=b.date
order by 1
""")
q.toPandas()
',strftime(from,"%Y%m%d"),strftime(to,"%Y%m%d")
,strftime(from,"%Y%m%d"),strftime(to,"%Y%m%d"),substr(version,1,2))
r <- dbx(query)
r
}
d <- usefulr[, rbindlist(Map(function(v,f,t){
r <- getD(v,f,t)
r$v <- v
r$f <- f
r$t <- t
r$date <- as.Date(as.character(r$date),"%Y%m%d")
r
}, version,from,to))]
```
```{r}
pdf("Rplots.pdf",width=11)
xyplot(pctLatest*100 ~ date, data=d,type=c('g','l'),lwd=2,aspect=0.4,
scales=list(x=list(tick.num=25,format='%Y-%m-%d',rot=45),
y=list(tick.num=25, cex=0.6)),ylab='Guess What? (%)')
doff()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment