forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyser_merge_restaurant_FR_cg71.py
84 lines (75 loc) · 4.38 KB
/
analyser_merge_restaurant_FR_cg71.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frédéric Rodrigo 2015-2016 ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###########################################################################
from .Analyser_Merge import Analyser_Merge, Source, CSV, Load, Mapping, Select, Generate
import re
class Analyser_Merge_Restaurant_FR_cg71(Analyser_Merge):
def __init__(self, config, logger = None):
Analyser_Merge.__init__(self, config, logger)
self.missing_official = self.def_class(item = 8240, id = 11, level = 3, tags = ['merge', 'amenity'],
title = T_('Restaurant not integrated'))
start_restaurant = re.compile("^(hôtel-)?restaurant ", flags=re.IGNORECASE)
final_name = re.compile("/.*$")
self.init(
u"https://www.data.gouv.fr/fr/datasets/restaurants-od71",
u"Les restaurants en Saône-et-Loire - CG71",
CSV(Source(attribution = u"Département de Saône-et-Loire", millesime = "03/2013",
fileUrl = u"https://www.data.gouv.fr/s/resources/restaurants-od71/20180207-141445/CG71Restaurants.csv", encoding = "ISO-8859-15"),
separator = u";"),
Load("LONGITUDE", "LATITUDE",
xFunction = self.float_comma,
yFunction = self.float_comma),
Mapping(
select = Select(
types = ["nodes", "ways"],
tags = {"amenity": "restaurant"}),
conflationDistance = 100,
generate = Generate(
static1 = {"amenity": "restaurant"},
static2 = {"source": self.source},
mapping1 = {
"amenity": lambda fields: self.amenity_type.get(fields["CATEGORIE"]) or "restaurant",
"name": lambda fields: final_name.sub('', start_restaurant.sub('', fields["NOM"])),
"tourism": lambda fields: "hotel" if fields["TYPE_RESTAURATION"] == u"Hotel-restaurant" else None,
"cuisine": lambda fields: self.cuisine(fields),
"website": "SITE_WEB",
"stars": lambda fields: len(fields["note_Guide_Rouge_Michelin"]) if fields["note_Guide_Rouge_Michelin"] else None},
text = lambda tags, fields: {"en": ', '.join(filter(lambda x: x, [fields["NOM"], fields["TYPE_RESTAURATION"], fields["CATEGORIE"], fields["ADRESSE1"], fields["ADRESSE2"], fields["ADRESSE3"], fields["VILLE"]]))} )))
amenity_type = {
u"Cafétéria": "restaurant",
u"Crêperie": "restaurant",
u"Bistrot": "bar",
u"Grill": "restaurant",
u"Restauration rapide": "fast_food",
u"Restauration à thème": "restaurant",
u"Brasserie": "restaurant",
u"Cuisine traditionnelle": "restaurant",
}
cuisine_categorie = {
u"Crêperie": "crepe",
u"Grill": "steak_house",
u"Pizzeria": "pizza",
}
def cuisine(self, fields):
categorie = fields["CATEGORIE"]
if self.amenity_type.get(categorie) == "restaurant":
if fields["CATEGORIE"] in self.cuisine_categorie:
return self.cuisine_categorie[categorie]
return None