Skip to content

Commit 442aaf9

Browse files
authored
Merge pull request #28 from zazuko/fix-ci
Improve CI
2 parents 0cc9467 + 389563e commit 442aaf9

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

.github/workflows/ci.yaml

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build HTML version
33
on:
44
push:
55
branches:
6-
- master
6+
- "**"
77

88
jobs:
99
docker:
@@ -15,14 +15,22 @@ jobs:
1515

1616
steps:
1717
- name: Checkout
18-
uses: actions/checkout@v2
18+
uses: actions/checkout@v3
1919

20-
- uses: actions/setup-python@v1
20+
- uses: actions/setup-python@v4
2121
with:
2222
python-version: 3.9
2323

24+
- name: Install and configure Poetry
25+
uses: snok/install-poetry@v1
26+
with:
27+
version: 1.5.1
28+
virtualenvs-create: false
29+
virtualenvs-in-project: false
30+
installer-parallel: true
31+
2432
- name: Install dependencies
25-
run: pip install -r requirements.txt
33+
run: poetry install
2634

2735
- name: Install Jupyter
2836
run: pip install jupyterlab sparqlkernel
@@ -36,10 +44,13 @@ jobs:
3644
- name: Build HTML version of the notebook
3745
run: ./run.sh
3846

47+
# Only deploy on GitHub Pages if we are on the "master" branch
3948
- name: Configure CNAME
49+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
4050
run: echo jupyter.zazuko.com > html/CNAME
4151

4252
- name: Deploy to GitHub Pages
53+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
4354
uses: JamesIves/[email protected]
4455
with:
4556
branch: gh-pages

notebooks/zefix/addresses.json

+29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22
"type": "FeatureCollection",
33
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
44
"features": [
5+
{ "type": "Feature", "properties": { "address": "Industriestrasse, 6055 Alpnach Dorf, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.277393652963429, 46.94092995 ] } },
6+
{ "type": "Feature", "properties": { "address": "Seeburgstrasse, 6006 Luzern, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.3389154, 47.0530533 ] } },
7+
{ "type": "Feature", "properties": { "address": "Via Giovan Battista Pioda, 6900 Lugano, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.9542748, 46.0075449 ] } },
8+
{ "type": "Feature", "properties": { "address": "Via Carlo Maderno, 6900 Lugano, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.9549544, 46.0093445 ] } },
9+
{ "type": "Feature", "properties": { "address": "Rue du Pas de l'Ours, 3963 Crans VS, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 7.467844, 46.3074497 ] } },
10+
{ "type": "Feature", "properties": { "address": "Poststrasse, 9000 St. Gallen, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 9.3740105, 47.4250466 ] } },
11+
{ "type": "Feature", "properties": { "address": "Rue de la Rôtisserie, 1204 Genève, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.1471323, 46.2026403 ] } },
12+
{ "type": "Feature", "properties": { "address": "Rue de la Corraterie, 1204 Genève, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.143915, 46.2014168 ] } },
13+
{ "type": "Feature", "properties": { "address": "Ueberlandstrasse, 8600 Dübendorf, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.6187628, 47.4002515 ] } },
14+
{ "type": "Feature", "properties": { "address": "Selnaustrasse, 8001 Zürich, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.5329915, 47.3700265 ] } },
15+
{ "type": "Feature", "properties": { "address": "Route de l'Aéroport, 1950 Sion, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 7.3477037, 46.2236772 ] } },
16+
{ "type": "Feature", "properties": { "address": "Brandschenkestrasse, 8001 Zürich, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.5331798, 47.369396 ] } },
17+
{ "type": "Feature", "properties": { "address": "Avenue de Tivoli, 1007 Lausanne, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.616784, 46.5209716 ] } },
18+
{ "type": "Feature", "properties": { "address": "Haselstrasse, 5400 Baden, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.310141, 47.4780467 ] } },
19+
{ "type": "Feature", "properties": { "address": "Rue des Pâquis, 1201 Genève, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.1480865, 46.2098051 ] } },
20+
{ "type": "Feature", "properties": { "address": "Laupenstrasse, 3008 Bern, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 7.4301286, 46.9476323 ] } },
21+
{ "type": "Feature", "properties": { "address": "Ankerstrasse, 8004 Zürich, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.5249697, 47.3741796 ] } },
22+
{ "type": "Feature", "properties": { "address": "Hauptstrasse, 4147 Aesch BL, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 7.5970561, 47.4689821 ] } },
23+
{ "type": "Feature", "properties": { "address": "Klausstrasse, 8008 Zürich, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.551488, 47.3591733 ] } },
24+
{ "type": "Feature", "properties": { "address": "Huobstrasse, 8808 Pfäffikon SZ, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.7809236, 47.2005643 ] } },
25+
{ "type": "Feature", "properties": { "address": "Luzernerstrasse, 6014 Luzern, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.2614142, 47.0491612 ] } },
26+
{ "type": "Feature", "properties": { "address": "Rue de Genève, 1225 Chêne-Bourg, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.1938107, 46.1947594 ] } },
27+
{ "type": "Feature", "properties": { "address": "Route Aloys-Fauquez, 1018 Lausanne, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.6334145, 46.5341791 ] } },
28+
{ "type": "Feature", "properties": { "address": "Zürcherstrasse, 8953 Dietikon, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.4029967, 47.4044452 ] } },
29+
{ "type": "Feature", "properties": { "address": "Wassergrabe, 6210 Sursee, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.1094776, 47.1833104 ] } },
30+
{ "type": "Feature", "properties": { "address": "Espace des Remparts, 1950 Sion, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 7.359018660370566, 46.23214475 ] } },
31+
{ "type": "Feature", "properties": { "address": "Avenue du Grey, 1004 Lausanne, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.6187142, 46.5327985 ] } },
32+
{ "type": "Feature", "properties": { "address": "Soodstrasse, 8134 Adliswil, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.5260873, 47.3134104 ] } },
33+
{ "type": "Feature", "properties": { "address": "Römerstrasse, 8404 Winterthur, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.7563255, 47.508088 ] } },
534
{ "type": "Feature", "properties": { "address": "Altgasse, 6340 Baar, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 8.521283, 47.1923375 ] } },
635
{ "type": "Feature", "properties": { "address": "Güterstrasse, 4053 Basel, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 7.5911933, 47.5440842 ] } },
736
{ "type": "Feature", "properties": { "address": "Chemin du Chêne, 1020 Renens VD, Switzerland" }, "geometry": { "type": "Point", "coordinates": [ 6.5932191, 46.5290259 ] } },

notebooks/zefix/zefix.ipynb

+17-5
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@
8585
"import folium\n",
8686
"import mapclassify\n",
8787
"import matplotlib as mpl\n",
88-
"import matplotlib.pyplot as plt\n",
8988
"import pandas as pd\n",
9089
"import geopandas as gpd\n",
9190
"import plotly.express as px\n",
9291
"import plotly.graph_objects as go\n",
93-
"from plotly.subplots import make_subplots\n",
9492
"\n",
9593
"from graphly.api_client import SparqlClient\n",
94+
"from geopy.extra.rate_limiter import RateLimiter\n",
95+
"from geopy.geocoders import Nominatim\n",
96+
"from shapely.geometry import Point\n",
9697
"\n",
9798
"%matplotlib inline"
9899
]
@@ -501,6 +502,9 @@
501502
"metadata": {},
502503
"outputs": [],
503504
"source": [
505+
"geolocator = Nominatim(user_agent=\"zefix\")\n",
506+
"find_location = RateLimiter(geolocator.geocode, min_delay_seconds=1)\n",
507+
"\n",
504508
"def geocode(df: pd.DataFrame, cache_file: str=\"addresses.json\"):\n",
505509
"\n",
506510
" if os.path.isfile(cache_file): \n",
@@ -513,8 +517,16 @@
513517
" is_new_address = ~df.address.isin(cached_addresses)\n",
514518
"\n",
515519
" if any(is_new_address):\n",
516-
" new_locations = gpd.tools.geocode(df.address[is_new_address], user_agent=\"zazuko\", provider=\"nominatim\")\n",
517-
" new_locations[\"address\"] = df.address[is_new_address]\n",
520+
" \n",
521+
" coordinates = []\n",
522+
" addresses = []\n",
523+
" for address in df.address[is_new_address]:\n",
524+
" location = find_location(address)\n",
525+
" if coordinates:\n",
526+
" coordinates.append(Point(location))\n",
527+
" addresses.append(address)\n",
528+
"\n",
529+
" new_locations = gpd.GeoDataFrame.from_dict({\"address\": addresses, \"geometry\": coordinates})\n",
518530
" new_locations = new_locations.set_crs(epsg=4326)\n",
519531
" new_locations = new_locations[~new_locations.geometry.is_empty]\n",
520532
" all_locations = gpd.GeoDataFrame(pd.concat([new_locations, cached_locations], ignore_index=True), crs=new_locations.crs)\n",
@@ -609,7 +621,7 @@
609621
"name": "python",
610622
"nbconvert_exporter": "python",
611623
"pygments_lexer": "ipython3",
612-
"version": "3.9.0"
624+
"version": "3.9.12"
613625
},
614626
"title": "Central Business Name Index - Zefix"
615627
},

0 commit comments

Comments
 (0)