Fix handling of multiple INSEE on same postal code
This commit is contained in:
parent
4d11726332
commit
67da9a055e
@ -1,77 +1,88 @@
|
||||
import { findFlatGPS, costFilter } from '../tools'
|
||||
|
||||
export default {
|
||||
allFlats: state => state.flats,
|
||||
allFlats: (state) => state.flats,
|
||||
|
||||
flat: (state, getters) => id => state.flats.find(flat => flat.id === id),
|
||||
flat: (state, getters) => (id) =>
|
||||
state.flats.find((flat) => flat.id === id),
|
||||
|
||||
isLoading: state => state.loading > 0,
|
||||
isLoading: (state) => state.loading > 0,
|
||||
|
||||
postalCodesFlatsBuckets: (state, getters) => filter => {
|
||||
const postalCodeBuckets = {}
|
||||
inseeCodesFlatsBuckets: (state, getters) => (filter) => {
|
||||
const buckets = {};
|
||||
|
||||
state.flats.forEach(flat => {
|
||||
state.flats.forEach((flat) => {
|
||||
if (!filter || filter(flat)) {
|
||||
const postalCode = flat.flatisfy_postal_code.postal_code
|
||||
if (!postalCodeBuckets[postalCode]) {
|
||||
postalCodeBuckets[postalCode] = {
|
||||
'name': flat.flatisfy_postal_code.name,
|
||||
'flats': []
|
||||
const insee = flat.flatisfy_postal_code.insee_code;
|
||||
if (!buckets[insee]) {
|
||||
buckets[insee] = {
|
||||
name: flat.flatisfy_postal_code.name,
|
||||
flats: [],
|
||||
};
|
||||
}
|
||||
buckets[insee].flats.push(flat);
|
||||
}
|
||||
postalCodeBuckets[postalCode].flats.push(flat)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return postalCodeBuckets
|
||||
return buckets;
|
||||
},
|
||||
|
||||
flatsMarkers: (state, getters) => (router, filter) => {
|
||||
const markers = []
|
||||
state.flats.forEach(flat => {
|
||||
const markers = [];
|
||||
state.flats.forEach((flat) => {
|
||||
if (filter && filter(flat)) {
|
||||
const gps = findFlatGPS(flat)
|
||||
const gps = findFlatGPS(flat);
|
||||
|
||||
if (gps) {
|
||||
const previousMarker = markers.find(
|
||||
marker => marker.gps[0] === gps[0] && marker.gps[1] === gps[1]
|
||||
)
|
||||
(marker) =>
|
||||
marker.gps[0] === gps[0] && marker.gps[1] === gps[1]
|
||||
);
|
||||
if (previousMarker) {
|
||||
// randomize position a bit
|
||||
// gps[0] += (Math.random() - 0.5) / 500
|
||||
// gps[1] += (Math.random() - 0.5) / 500
|
||||
}
|
||||
const href = router.resolve({ name: 'details', params: { id: flat.id }}).href
|
||||
const href = router.resolve({
|
||||
name: "details",
|
||||
params: { id: flat.id },
|
||||
}).href;
|
||||
const cost = flat.cost
|
||||
? costFilter(flat.cost, flat.currency)
|
||||
: ''
|
||||
: "";
|
||||
markers.push({
|
||||
'title': '',
|
||||
'content': '<a href="' + href + '">' + flat.title + '</a>' + cost,
|
||||
'gps': gps,
|
||||
'flat_id': flat.id
|
||||
})
|
||||
title: "",
|
||||
content:
|
||||
'<a href="' +
|
||||
href +
|
||||
'">' +
|
||||
flat.title +
|
||||
"</a>" +
|
||||
cost,
|
||||
gps: gps,
|
||||
flat_id: flat.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return markers
|
||||
return markers;
|
||||
},
|
||||
|
||||
allTimeToPlaces: state => {
|
||||
const places = {}
|
||||
Object.keys(state.timeToPlaces).forEach(constraint => {
|
||||
const constraintTimeToPlaces = state.timeToPlaces[constraint]
|
||||
Object.keys(constraintTimeToPlaces).forEach(name => {
|
||||
places[name] = constraintTimeToPlaces[name]
|
||||
})
|
||||
})
|
||||
return places
|
||||
allTimeToPlaces: (state) => {
|
||||
const places = {};
|
||||
Object.keys(state.timeToPlaces).forEach((constraint) => {
|
||||
const constraintTimeToPlaces = state.timeToPlaces[constraint];
|
||||
Object.keys(constraintTimeToPlaces).forEach((name) => {
|
||||
places[name] = constraintTimeToPlaces[name];
|
||||
});
|
||||
});
|
||||
return places;
|
||||
},
|
||||
|
||||
timeToPlaces: (state, getters) => (constraintName) => {
|
||||
return state.timeToPlaces[constraintName]
|
||||
return state.timeToPlaces[constraintName];
|
||||
},
|
||||
|
||||
metadata: state => state.metadata
|
||||
}
|
||||
metadata: (state) => state.metadata,
|
||||
};
|
||||
|
@ -15,16 +15,16 @@
|
||||
</label>
|
||||
</h2>
|
||||
|
||||
<template v-if="Object.keys(postalCodesFlatsBuckets).length > 0">
|
||||
<template v-for="(postal_code_data, postal_code) in postalCodesFlatsBuckets">
|
||||
<template v-if="Object.keys(inseeCodesFlatsBuckets).length > 0">
|
||||
<template v-for="(insee_code_data, insee_code) in inseeCodesFlatsBuckets">
|
||||
<h3>
|
||||
{{ postal_code_data.name || $t('common.Unknown') }}
|
||||
<span v-if="postal_code !== 'undefined'">
|
||||
({{ postal_code }})
|
||||
{{ insee_code_data.name || $t('common.Unknown') }}
|
||||
<span v-if="insee_code !== 'undefined'">
|
||||
({{ insee_code }})
|
||||
</span>
|
||||
- {{ postal_code_data.flats.length }} {{ $tc("common.flats", postal_code_data.flats.length) }}
|
||||
- {{ insee_code_data.flats.length }} {{ $tc("common.flats", insee_code_data.flats.length) }}
|
||||
</h3>
|
||||
<FlatsTable :flats="postal_code_data.flats" :key="postal_code"></FlatsTable>
|
||||
<FlatsTable :flats="insee_code_data.flats" :key="insee_code"></FlatsTable>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="isLoading">
|
||||
@ -83,8 +83,8 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
postalCodesFlatsBuckets () {
|
||||
return this.$store.getters.postalCodesFlatsBuckets(flat =>
|
||||
inseeCodesFlatsBuckets () {
|
||||
return this.$store.getters.inseeCodesFlatsBuckets(flat =>
|
||||
flat.status === 'new' &&
|
||||
(this.showExpiredFlats || !flat.is_expired)
|
||||
)
|
||||
|
@ -12,10 +12,10 @@
|
||||
<template v-if="isLoading">
|
||||
<p>{{ $t("common.loading") }}</p>
|
||||
</template>
|
||||
<template v-else-if="Object.keys(postalCodesFlatsBuckets).length > 0">
|
||||
<template v-for="(postal_code_data, postal_code) in postalCodesFlatsBuckets">
|
||||
<h3>{{ postal_code_data.name }} ({{ postal_code }}) - {{ postal_code_data.flats.length }} {{ $tc("common.flats", postal_code_data.flats.length) }}</h3>
|
||||
<FlatsTable :flats="postal_code_data.flats"></FlatsTable>
|
||||
<template v-else-if="Object.keys(inseeCodesFlatsBuckets).length > 0">
|
||||
<template v-for="(insee_code_data, insee_code) in inseeCodesFlatsBuckets">
|
||||
<h3>{{ insee_code_data.name }} ({{ insee_code }}) - {{ insee_code_data.flats.length }} {{ $tc("common.flats", insee_code_data.flats.length) }}</h3>
|
||||
<FlatsTable :flats="insee_code_data.flats"></FlatsTable>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>
|
||||
@ -51,12 +51,12 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
postalCodesFlatsBuckets () {
|
||||
inseeCodesFlatsBuckets () {
|
||||
if (!this.$route.query.query || this.loading) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return this.$store.getters.postalCodesFlatsBuckets(
|
||||
return this.$store.getters.inseeCodesFlatsBuckets(
|
||||
flat => flat.status !== 'duplicate' && flat.status !== 'ignored' && flat.status !== 'user_deleted'
|
||||
)
|
||||
},
|
||||
|
@ -17,11 +17,11 @@
|
||||
<template v-if="isLoading">
|
||||
<p>{{ $t("common.loading") }}</p>
|
||||
</template>
|
||||
<template v-else-if="Object.keys(postalCodesFlatsBuckets).length">
|
||||
<template v-for="(postal_code_data, postal_code) in postalCodesFlatsBuckets">
|
||||
<h3>{{ postal_code_data.name }} ({{ postal_code }}) - {{ postal_code_data.flats.length }} {{ $tc("common.flats", postal_code_data.flats.length) }}</h3>
|
||||
<template v-else-if="Object.keys(inseeCodesFlatsBuckets).length">
|
||||
<template v-for="(insee_code_data, insee_code) in inseeCodesFlatsBuckets">
|
||||
<h3>{{ insee_code_data.name }} ({{ insee_code }}) - {{ insee_code_data.flats.length }} {{ $tc("common.flats", insee_code_data.flats.length) }}</h3>
|
||||
<FlatsTable
|
||||
:flats="postal_code_data.flats"
|
||||
:flats="insee_code_data.flats"
|
||||
:showNotationColumn="$route.params.status === 'followed'"
|
||||
:showNotes="$route.params.status === 'followed'"
|
||||
:initialSortBy="$route.params.status === 'followed' ? 'notation' : undefined"
|
||||
@ -81,8 +81,8 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
postalCodesFlatsBuckets () {
|
||||
return this.$store.getters.postalCodesFlatsBuckets(flat => flat.status === this.$route.params.status)
|
||||
inseeCodesFlatsBuckets () {
|
||||
return this.$store.getters.inseeCodesFlatsBuckets(flat => flat.status === this.$route.params.status)
|
||||
},
|
||||
title () {
|
||||
return 'Flatisfy - ' + capitalize(this.$t('status.' + this.$route.params.status))
|
||||
|
@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
import datetime
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import os
|
||||
|
||||
@ -15,6 +16,7 @@ import vobject
|
||||
|
||||
import flatisfy.data
|
||||
from flatisfy.models import flat as flat_model
|
||||
from flatisfy.models import postal_code
|
||||
from flatisfy.models.postal_code import PostalCode
|
||||
from flatisfy import cmds
|
||||
|
||||
@ -106,15 +108,17 @@ def _serialize_flat(flat, config):
|
||||
postal_codes[constraint_name] = flatisfy.data.load_data(PostalCode, constraint, config)
|
||||
|
||||
try:
|
||||
assert flat["flatisfy_postal_code"]
|
||||
assert flat["flatisfy_position"]
|
||||
|
||||
lat = flat["flatisfy_position"]["lat"]
|
||||
lng = flat["flatisfy_position"]["lng"]
|
||||
postal_code_data = next(
|
||||
x
|
||||
for x in postal_codes.get(flat["flatisfy_constraint"], [])
|
||||
if x.postal_code == flat["flatisfy_postal_code"]
|
||||
x for x in postal_codes.get(flat["flatisfy_constraint"], []) if x.lat == lat and x.lng == lng
|
||||
)
|
||||
logging.warn(f"{postal_code_data.name}, {lat}, {lng}")
|
||||
flat["flatisfy_postal_code"] = {
|
||||
"postal_code": flat["flatisfy_postal_code"],
|
||||
"postal_code": postal_code_data.postal_code,
|
||||
"insee_code": postal_code_data.insee_code,
|
||||
"name": postal_code_data.name,
|
||||
"gps": (postal_code_data.lat, postal_code_data.lng),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user