Public
Edited
Jan 29, 2024
Insert cell
Insert cell
bertin = require("bertin@1.8")
Insert cell
wifi = d3.json(
"https://opendata.paris.fr/api/explore/v2.1/catalog/datasets/paris-wi-fi-utilisation-des-hotspots-paris-wi-fi/records?select=code_site%2C%20device_constructor_name%2C%20count(datetime)%20as%20nb%2C%20envelope(geo_shape)%20as%20geo&where=code_site%20is%20not%20null&group_by=code_site%2C%20device_constructor_name&order_by=code_site%20ASC&exclude=code_site%3A%23N%2FA"
)
Insert cell
points_wifi = FileAttachment("sites-disposant-du-service-paris-wi-fi.geojson").json()
Insert cell
paris = FileAttachment("arrondissements.geojson").json()
Insert cell
data_geojson= wifi.results.map(function(r){return {type:"Feature",geometry: {type: r.geo.type,coordinates:r.geo.coordinates} ,properties:{code:r.code_site, brand:r.device_constructor_name, nb:r.nb}}})
Insert cell
data_merged_loc = bertin.merge(points_wifi,"idpw",wifi.results.filter(d=>d.device_constructor_name=="Samsung"),"code_site")
Insert cell
cleanMap = bertin.draw({
params: { background: "#bdeff0", margin: 10 },
layers: [
{
type: "bubble",
geojson: data_merged_loc,
values:"nb"
}
]
})
Insert cell
Insert cell
turf= require("@turf/turf@6")
Insert cell
data_centroid = data_geojson.map( function(d){let res = turf.centroid(d);res.properties = d.properties; return res})
Insert cell
data_centroid[0]
Insert cell
data_nb = data_centroid.map(d=> d.properties.nb)
Insert cell
epsg2154 = "+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs"
Insert cell
centroidMap = bertin.draw({
params: { background: "#bde1f0", margin: 10, projection:epsg2154 },
layers: [
{
type: "mushroom",
geojson: champigons,
bottom_values:"apple",
top_values:"other"
},
{
type: "layer",
geojson: paris,
fill: "#f7da48",
stroke: "#6eb5e0",
strokeWidth: 1
}
]
})
Insert cell
data_centroid.filter(d=>d.properties.brand=="Apple").sort((a,b) => b.properties.nb-a.properties.nb)
Insert cell
map_site = d3.group(wifi.results,d=>d.code_site)
Insert cell
data_merged_loc_allbrands = points_wifi.features.map(function(d){
let res = map_site.get(d.properties.idpw);
if(res){
let apple = res.filter(d=>d.device_constructor_name=="Apple").length>0?res.filter(d=>d.device_constructor_name=="Apple")[0].nb:0;
let other = res.filter(d=>d.device_constructor_name!="Apple").map(cv=>cv.nb).reduce((val,cval)=>cval+val)
return {code:d.properties.idpw,apple:apple,other:other}
}
return {code:d.properties.idpw,apple:0,other:0}
})
Insert cell
champigons = bertin.merge(points_wifi,"idpw",data_merged_loc_allbrands.filter(d=>d.code),"code")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more