Skip to content

[membership_map] JSON schema based on Hacktoberfest 2023 Microsoft Office Form #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ["--maxkb=7168"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ assets/js/index.js
_layouts/default.html
_layouts/index.html
_includes/header.html
_membership/membership-map.html
_includes/social.html
_includes/social-item.html
_includes/svg_symbol.html
10 changes: 10 additions & 0 deletions _articles/es/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ title: Sobre Nosotros

## ¿Qué es Black Python Devs?

---

Black Python Devs es una comunidad [online-first](https://github.com/BlackPythonDevs/blackpythondevs.github.io/issues/9#why-online-first) para desarrolladores de Python de todos los niveles de habilidad que se identifican como negros.

Nuestro objetivo es:
Expand All @@ -16,6 +18,14 @@ Nuestro objetivo es:

## ¿Por qué en línea primero?

---

Esperamos a largo plazo crear muchos grupos de usuarios y eventos en persona, pero tenemos que entender dónde podemos tener los mayores impactos.

Para hacer esto, esperamos reunir a personas de todo el mundo y ver dónde están nuestras audiencias más grandes.

## Mapa de Membresía

---

{% include membership-map.html %}
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ exclude:
- .venv
- requirements*.txt
- pytest.ini
- _membership/schema.json
- _membership/users.json
# timezone: America/Toronto

permalink: "/:path/"
Expand All @@ -84,6 +86,9 @@ collections:
articles:
output: true
permalink: "/:path/"
membership:
output: false
permalink: "/:path/"

defaults:
# - scope:
Expand Down
2 changes: 1 addition & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% assign t = site.data.locales[page.lang][page.lang] %}
<header class="site-header" role="banner">
<h1 class="site-title"><a class="logo-text" href="/index.html">BPDev</a></h1>
<h1 class="site-title"><a class="logo-text" href="/index.html">BPDevs</a></h1>
<nav class="site-navigation">
<div class="site-navigation-wrap">
<ul class="menu" role="menu">
Expand Down
1 change: 1 addition & 0 deletions _includes/membership-map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe src="/membership-map.html" height="720" width="100%" style="border: none" title="{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %} - Membership Map"></iframe>
100 changes: 100 additions & 0 deletions _membership/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# https://en.wikipedia.org/wiki/GeoJSON
# https://realpython.com/python-folium-web-maps-from-data/#create-a-choropleth-map-with-your-data
# https://geopandas.org/en/stable/gallery/polygon_plotting_with_folium.html
import functools
import json
import random
from pathlib import Path

import faker
import folium
import geopy
import pandas as pd

fake = faker.Faker()

continents = ["Africa", "Asia", "Australia", "Europe", "North America", "South America"]
# Based on Discord members
num_users = 165
users = []
users_path = Path(__file__).parent / "users.json"
membership_path = Path(__file__).parent / "membership-map.html"

print("[Faker] Generating fake users...")

for _ in range(num_users):
user = {"full_name": fake.name()}
user["discord_username"] = f"{fake.user_name()}#{random.randint(1000, 9999)}"
user["continent_location"] = random.choices(
continents, weights=[0.15, 0.15, 0.3, 0.5, 0.7, 0.25], k=1
)[0]
users.append(user)

users_json = json.dumps(users, indent=2)

with users_path.open("w") as f:
f.write(users_json)

print("Saved to users.json")

users_df = pd.read_json(users_path)
geolocator = geopy.Nominatim(user_agent="blackpythondevs.github.io")


# @lru_cache decorator with a maxsize of 6 (the number of continents)
@functools.lru_cache(maxsize=6)
def get_continent_coords(continent):
location = geolocator.geocode(continent)
return (location.latitude, location.longitude)


print("[geopy] Getting coordinates of continents...")

users_df["continent_coords"] = users_df["continent_location"].apply(
get_continent_coords
)
# Group the DataFrame by continent location and count the number of users
# Also keep the first value of the continent coordinates for each group
users_by_continent = users_df.groupby("continent_location").agg(
user_count=("full_name", "count"),
continent_coords=("continent_location", lambda x: get_continent_coords(x.iloc[0])),
)

print("Members per continent:")
print(f"{users_by_continent}\n")
# Null Island
m = folium.Map(location=(0, 0), zoom_start=2)
# GeoJSON Countries Layer
geo_data_url = "https://geojson.xyz/naturalearth-3.3.0/ne_50m_admin_0_countries.geojson"

for index, row in users_by_continent.iterrows():
continent = index
user_count = row["user_count"]
coords = row["continent_coords"]
# Marker with the coordinates and a popup text
marker = folium.Marker(
location=coords,
popup=f"{continent}: {user_count} members",
icon=folium.Icon(color="blue"),
)
marker.add_to(m)

users_by_continent = users_by_continent.reset_index(names=["continent"])

folium.Choropleth(
geo_data=geo_data_url,
name="choropleth",
data=users_by_continent,
columns=["continent", "user_count"],
key_on="feature.properties.continent", # by name
fill_color="YlOrRd", # ‘YlGn’, ‘YlOrRd’, ‘BuPu’
nan_fill_color="white",
fill_opacity=0.8,
line_opacity=0.3,
legend_name="Number of members by continent",
).add_to(m)

folium.LayerControl().add_to(m)

m.save(membership_path)
print(f"{membership_path} saved.")
Loading