comeetie 2022-11-09 17:53:39 +01:00
rodzic 491c24aa68
commit d55cfaf1d1
9 zmienionych plików z 11 dodań i 178 usunięć

Wyświetl plik

@ -1,2 +1,4 @@
~%2FProjets%2Fmap-stodon%2FscrData.R="7448EAAE"
~%2FProjets%2Fmap-stodon%2FscrPlot.R="12A0E261"
~%2FProjets%2Fmapstodon%2FscrData.R="E46C5F41"
~%2FProjets%2Fmapstodon%2FscrPlot.R="21CE1D26"

Wyświetl plik

@ -1,27 +0,0 @@
{
"id": "632B0BBB",
"path": "~/Projets/mapstodon/scrData.R",
"project_path": "scrData.R",
"type": "r_source",
"hash": "0",
"contents": "",
"dirty": true,
"created": 1667917274243.0,
"source_on_save": false,
"relative_order": 1,
"properties": {
"tempName": "Untitled1",
"source_window_id": "",
"Source": "Source",
"cursorPosition": "77,13",
"scrollLine": "57"
},
"folds": "",
"lastKnownWriteTime": 1668007721,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1668008010790,
"read_only": false,
"read_only_alternatives": []
}

Wyświetl plik

@ -1,91 +0,0 @@
library(httr)
library(dplyr)
library(stringr)
peers = jsonlite:::fromJSON("https://mapstodon.space/api/v1/instance/peers")
peers= c(peers,"mapstodon.space")
Links=list()
Lang=list()
for(peer in peers){
ur <- paste0("https://",peer,"/api/v1/timelines/public?limit=25")
next_url = ur;
instances = c();
languages = c();
for(pages in 1:20){
try({
response = GET(next_url)
link = headers(response)$link
min_id = link |> str_extract("max_id=[0123456789]+") |> str_remove("max_id=")
next_url = paste0(ur,"&max_id=",min_id)
print(next_url)
jsonRespText <- content(response, "text")
toots <- jsonlite::fromJSON(jsonRespText)
instances = c(instances,toots$account$url |> str_remove("/@.*") |> str_remove("https://"))
languages = c(languages,toots$language)
})
Sys.sleep(0.2)
}
try({
peers_links=table(instances)
Links[[peer]]=data.frame(instance=peer,from=names(peers_links),nb_toots=as.numeric(peers_links))
peers_langs=table(languages)
Lang[[peer]]=data.frame(instance=peer,from=names(peers_langs),nb_toots=as.numeric(peers_langs))
})
}
seems_ok=sapply(Links,\(df){sum(df$nb_toots)})>400
sum(seems_ok)/length(peers)
Links_clean=Links[seems_ok]
Lang_clean=Lang[seems_ok]
Links.df = do.call(rbind,Links_clean)
Lang.df = do.call(rbind,Lang_clean)
library(readr)
write_csv(Links.df,"Links_raw.csv")
write_csv(Lang.df,"Langs_raw.csv")
# some cleaning
instances = unique(Links.df$instance)
Links.cl = Links.df |> mutate(from=str_remove(from,"/.*")) |>
group_by(instance,from)|>
summarise(nb_toots=sum(nb_toots)) |>
filter(from %in% instances) |>
ungroup()
Links.probs= Links.cl |>
add_count(instance,wt = nb_toots) |>
mutate(p=nb_toots/n) |>
arrange(desc(p))
# get instances average prob
Nblink = sum(Links.cl$nb_toots)
Links.probs.average = Links.cl |>
count(from,wt=nb_toots,name="nb_toots_total") |>
mutate(paverage=nb_toots_total/Nblink) |>
arrange(desc(paverage))
# some filtering + biner
Links.filtered = Links.probs |> left_join(Links.probs.average,by="from") |>
mutate(logratio=log(p/paverage)) |>
filter(logratio>log(5),nb_toots>10)
write_csv(Links.filtered,"Links_filtered.csv")
# individuals
library(rtoot)
token = auth_setup("mapstodon.space", "user")
directory = get_instance_directory("mapstodon.space",local = TRUE,limit=500)
attr(directory,"headers")
folowers = get_account_followers("109302019656613226",token=token,limit=200)
attr(folowers,"headers")
folowing = get_account_following("109302019656613226",token=token,limit=200)

Wyświetl plik

@ -1,27 +0,0 @@
{
"id": "8D711DAA",
"path": "~/Projets/mapstodon/scrPlot.R",
"project_path": "scrPlot.R",
"type": "r_source",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1668002263018.0,
"source_on_save": false,
"relative_order": 2,
"properties": {
"tempName": "Untitled1",
"source_window_id": "",
"Source": "Source",
"cursorPosition": "25,83",
"scrollLine": "0"
},
"folds": "",
"lastKnownWriteTime": 1668007729,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1668007729854,
"read_only": false,
"read_only_alternatives": []
}

Wyświetl plik

@ -1,33 +0,0 @@
graph=jsonlite::fromJSON("graph.json")
class(graph$nodes)
library(ggplot2)
ggplot(graph$nodes)+geom_point(aes(x=attributes$x,y=attributes$y,size=attributes$`nansi-indegree`,color=factor(attributes$`nansi-louvain`)))+
scale_size_area("",guide="none",max_size = 3)+
scale_color_brewer(palette="Set3",guide="none")+
theme_void()
library(dplyr)
graph$nodes |> group_by(attributes$`nansi-louvain`) |> top_n(3,attributes$`nansi-indegree`) |>
transmute(indeg=attributes$`nansi-indegree`,com=attributes$`nansi-louvain`,lab= attributes$`label`) |> arrange(com) |> View()
mapstodon = graph$nodes |> filter(attributes$label=="mapstodon.space")
labels = graph$nodes |>
transmute(label=attributes$label,x=attributes$x,y=attributes$y,indeg=attributes$`nansi-indegree`) |>
arrange(desc(indeg)) |>
filter(indeg>=20,!is.na(label))
ggplot(graph$nodes)+geom_point(aes(x=attributes$x,y=attributes$y,size=attributes$`nansi-indegree`,color=factor(attributes$`nansi-louvain`)))+
geom_point(data=mapstodon,aes(x=attributes$x,y=attributes$y,size=5*attributes$`nansi-indegree`),shape=1,color="red")+
geom_text(data=labels,aes(x=x,y=y,label=label),size=1.5)+
scale_size_area("",guide="none",max_size = 3)+
scale_color_brewer(palette="Set3",guide="none")+
theme_void()

4
.gitignore vendored 100644
Wyświetl plik

@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata

Wyświetl plik

@ -77,8 +77,13 @@ write_csv(Links.filtered,"Links_filtered.csv")
# individuals
library(rtoot)
token = auth_setup("mapstodon.space", "user")
directory = get_instance_directory("mapstodon.space",local = TRUE,limit=500)
attr(directory,"headers")
folowers = get_account_followers("109302019656613226",token=token,limit=200)
attr(folowers,"headers")