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