forked from MapComplete/MapComplete
Full code cleanup
This commit is contained in:
parent
3a4a2a2016
commit
fa971ffbbf
300 changed files with 16352 additions and 19284 deletions
|
@ -3,7 +3,7 @@ import {OH} from "../UI/OpeningHours/OpeningHours";
|
|||
|
||||
|
||||
function extractValue(vs: { __value }[]) {
|
||||
if(vs === undefined){
|
||||
if (vs === undefined) {
|
||||
return undefined
|
||||
}
|
||||
for (const v of vs) {
|
||||
|
@ -16,33 +16,34 @@ function extractValue(vs: { __value }[]) {
|
|||
}
|
||||
|
||||
|
||||
function extract_oh_block (days) : string{
|
||||
function extract_oh_block(days): string {
|
||||
const oh = []
|
||||
for (const day of days.day) {
|
||||
const abbr = day.name.substr(0,2)
|
||||
const abbr = day.name.substr(0, 2)
|
||||
const block = day.time_block[0]
|
||||
const from = block.time_from.substr(0,5)
|
||||
const to = block.time_until.substr(0,5)
|
||||
const from = block.time_from.substr(0, 5)
|
||||
const to = block.time_until.substr(0, 5)
|
||||
const by_appointment = block.by_appointment ? " \"by appointment\"" : ""
|
||||
oh.push(`${abbr} ${from}-${to}${by_appointment}`)
|
||||
}
|
||||
return oh.join("; ")
|
||||
}
|
||||
function extract_oh(opening_periods){
|
||||
|
||||
function extract_oh(opening_periods) {
|
||||
const rules = []
|
||||
if(opening_periods === undefined){
|
||||
if (opening_periods === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
for (const openingPeriod of opening_periods.opening_period ?? []) {
|
||||
let rule = extract_oh_block(openingPeriod.days)
|
||||
if(openingPeriod.name.toLowerCase().indexOf("schoolvakantie") >= 0){
|
||||
rule = "SH "+rule
|
||||
if (openingPeriod.name.toLowerCase().indexOf("schoolvakantie") >= 0) {
|
||||
rule = "SH " + rule
|
||||
}
|
||||
rules.push(rule)
|
||||
}
|
||||
return OH.simplify( rules.join(";"))
|
||||
return OH.simplify(rules.join(";"))
|
||||
}
|
||||
|
||||
|
||||
function rewrite(obj, key) {
|
||||
if (obj[key] === undefined) {
|
||||
return
|
||||
|
@ -109,12 +110,12 @@ for (const item of data) {
|
|||
metadata["addr:housenumber"] = addr.number
|
||||
metadata["phone"] = item.contact_info["telephone"] ?? item.contact_info["mobile"]
|
||||
metadata["email"] = item.contact_info["email_address"]
|
||||
|
||||
|
||||
const links = item.links?.link?.map(l => l.url) ?? []
|
||||
metadata["website"] = item.contact_info["website"] ?? links[0]
|
||||
|
||||
delete item["links"]
|
||||
|
||||
|
||||
delete item.location_info
|
||||
delete item.contact_info
|
||||
delete item.promotional_info
|
||||
|
@ -136,25 +137,25 @@ for (const item of data) {
|
|||
metadata.fee = "yes"
|
||||
metadata.charge = extractValue(item.price_info?.extra_information?.value)
|
||||
const methods = item.price_info?.payment_methods?.payment_method
|
||||
if(methods !== undefined){
|
||||
if (methods !== undefined) {
|
||||
methods.map(v => extractValue(v.value)).forEach(method => {
|
||||
metadata["payment:" + method.toLowerCase()] = "yes"
|
||||
})
|
||||
}
|
||||
delete item.price_info
|
||||
}else if(item.price_info?.prices?.length === 0){
|
||||
} else if (item.price_info?.prices?.length === 0) {
|
||||
delete item.price_info
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
|
||||
if(item.labels_info?.labels_own?.label[0]?.code === "Billenkar"){
|
||||
metadata.rental = "quadricycle"
|
||||
delete item.labels_info
|
||||
}
|
||||
}catch(e){
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
if (item.labels_info?.labels_own?.label[0]?.code === "Billenkar") {
|
||||
metadata.rental = "quadricycle"
|
||||
delete item.labels_info
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
delete item["publishing_channels"]
|
||||
|
||||
|
@ -166,22 +167,20 @@ for (const item of data) {
|
|||
}
|
||||
delete item.media
|
||||
|
||||
|
||||
|
||||
const time_info = item.time_info?.time_info_regular
|
||||
if(time_info?.permantly_open === true){
|
||||
if (time_info?.permantly_open === true) {
|
||||
metadata.opening_hours = "24/7"
|
||||
}else{
|
||||
} else {
|
||||
metadata.opening_hours = extract_oh(time_info?.opening_periods)
|
||||
}
|
||||
delete item.time_info
|
||||
|
||||
|
||||
|
||||
const properties = {}
|
||||
for (const key in metadata) {
|
||||
const v = metadata[key]
|
||||
if(v === null || v === undefined || v === ""){
|
||||
if (v === null || v === undefined || v === "") {
|
||||
delete metadata[key]
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue