]> code.communitydata.science - rises_declines_wikia_code.git/blob - 00_select_wikis.R
add copy of the GPL
[rises_declines_wikia_code.git] / 00_select_wikis.R
1 #!usr/bin/env Rscript
2
3 ## Script used to choose the top 1% of wikis to analyze
4
5 # Copyright (C) 2018  Nathan TeBlunthuis
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
20 library("ggplot2")
21 library("data.table")
22 counts.dir <- "../wikiq_wikia_2010_unique_editors/"
23 files <- list.files(counts.dir)
24 read.count.file <- function(f){
25     return(read.csv(paste0(counts.dir,f),header=FALSE))
26 }
27 dbname <- gsub("\\.editors",'',files)
28 counts <- c(sapply(files,read.count.file))
29 counts <- unlist(counts,use.names=FALSE)
30 dt <- data.table(wiki=dbname,n.editors=counts)
31
32
33 #ggplot(dt,aes(x=n.editors)) + stat_ecdf(geom="step") + scale_x_log10(minor_breaks=10**(1:10/2)) + scale_y_continuous(minor_breaks=1:20/20)
34
35 top_1_percentile = quantile(x=dt$n.editors,probs=(1:99)/100)[99]
36 ## lets take all with > 100. This is very close to the top 1%, but it involves nice round numbers :)
37
38 wiki.list <- dt[n.editors >= top_1_percentile]
39
40 wiki.list[is.na(url),':='(url=paste0("http://",wiki,".wikia.com/"))]
41 wiki.list$wiki.type="wikia"
42
43 fwrite(wiki.list,"selected.wikis.csv")
44            

Community Data Science Collective || Want to submit a patch?