示例#1
0
def insee_code_unit(id):
    config = Config('./config/config.yml')
    factory = DocFactory(config.get('mongodb'))
    collection = factory.insee_collection()
    obj = collection.find_one({'code': id})
    return render_template('admin/other/unit.html', data=obj)
示例#2
0
wiki.create_index([('code', 1)])
wiki.create_index([('name', 1)])
wiki.create_index([('admin_hierarchy', 1)])


gmaps = factory.gmaps_collection()

gmaps.drop_indexes()

gmaps.create_index([('_id', 1)])
gmaps.create_index([('code', 1)])
gmaps.create_index([('name', 1)])
gmaps.create_index([('admin_hierarchy', 1)])


insee = factory.insee_collection()

insee.drop_indexes()

insee.create_index([('_id', 1)])
insee.create_index([('code', 1)])
insee.create_index([('name', 1)])

istat = factory.istat_collection()

istat.drop_indexes()

insee.create_index([('_id', 1)])
insee.create_index([('code', 1)])
insee.create_index([('name', 1)])
示例#3
0
def matching_france_js(region):
    region = unquote_plus(region)
    #mode = request.args.get('mode', 'none')
    config = Config('./config/config.yml')

    factory = DocFactory(config.get('mongodb'))
    internal = factory.internal_collection()
    wiki = factory.wiki_collection()
    gmap = factory.gmaps_collection()
    insee = factory.insee_collection()
    objects = internal.find({
        'name': {
            '$exists': True,
            '$not': {
                '$size': 0
            }
        },
        '$and': [{
            'admin_hierarchy.ADMIN_LEVEL_1.name': 'France'
        }, {
            'admin_hierarchy.ADMIN_LEVEL_2.name': region
        }],
    })
    result = []
    for item in objects:
        dic = {'internal': item}

        wiki_res = {}
        if item.get('source', {}).get('wiki'):
            wiki_res = wiki.find_one(
                {'code': item.get('source', {}).get('wiki')})

        dic.update(wiki=wiki_res)

        gmap_res = {}
        if item.get('source', {}).get('gmap'):
            gmap_res = gmap.find_one(
                {'code': item.get('source', {}).get('gmap')})

        dic.update(gmap=gmap_res)

        insee_res = {}
        if item.get('source', {}).get('insee'):
            insee_res = insee.find_one(
                {'code': item.get('source', {}).get('insee')})

        dic.update(insee=insee_res)

        compare_res = {}
        compare_res.update({
            'insee_code!=wiki_code':
            1 if not (insee_res.get('InseeXls_CodeCommune')
                      == wiki_res.get('commune_codes')) else 0
        })
        compare_res.update({
            'insee_name!=wiki_name':
            1 if
            not (insee_res.get('InseeXls_NameCommune') == wiki_res.get('name'))
            else 0
        })
        compare_res.update({
            'wiki_name!=gmaps_name':
            1
            if not (wiki_res.get('true_name', wiki_res.get('name'))
                    == gmap_res.get('true_name', gmap_res.get('name'))) else 0
        })
        compare_res.update({
            'wiki_post!=gmaps_post':
            1 if not (str(wiki_res.get('postal_codes')) == str(
                gmap_res.get('postal_code'))) else 0
        })
        compare_res.update({
            'wiki_admin!=gmaps_admin':
            1 if not (str(wiki_res.get('admin_hierarchy')) == str(
                gmap_res.get('admin_hierarchy'))) else 0
        })
        try:
            max_meters_in_distance = 5000
            compare_res.update({
                'wiki_posinion>gmaps_position':
                1 if Comparison.by_distance(wiki_res.get('center'),
                                            gmap_res.get('center')) >
                max_meters_in_distance else 0
            })
        except:
            compare_res.update({'wiki_posinion>gmaps_position': 1})
        dic.update(compare=compare_res)

        #        if mode != 'none':
        #            if mode == 'wiki_adapte':
        #                if dic.get('wiki', {}).get('name', '').lower() != dic.get('insee', {}).get('name', '').lower():
        #                    result.append(dic)
        #            elif mode == 'gmap_adapte':
        #                if dic.get('gmap', {}).get('name', '').lower() != dic.get('insee', {}).get('name', '').lower():
        #                    result.append(dic)
        #        else:
        #            result.append(dic)

        result.append(dic)

    return render_template('admin/matching-france/list.js',
                           e=escape,
                           items=result)