<commit_before>from appfd.models import FeaturePlace, Order
from geojson import Feature as gFeature
from geojson import dumps, FeatureCollection, MultiPolygon, Point, Polygon, GeometryCollection
from os import mkdir
from os.path import isdir

def run(key):
    print "starting create_geojson with key " + key

    from django.db import connection
    connection.close()

    features = []
    for fp in FeaturePlace.objects.filter(feature__order__token=key, correct=True).order_by("-place__admin_level"):

            properties = {}

            feature = fp.feature

            if feature.end:
                properties['end_time'] = feature.end.strftime('%y-%m-%d')

            if feature.start:
                properties['start_time'] = feature.start.strftime('%y-%m-%d')

            properties['confidence'] = float(fp.confidence)
            place = fp.place
            properties['admin1_code'] = place.admin1_code
            properties['country_code'] = place.country_code
            properties['name'] = place.name
            properties['geonameid'] = place.geonameid
            properties['pcode'] = place.pcode
            properties['timezone'] = place.timezone
            point = Point((place.point.x, place.point.y))
            geometries = [point]
            if place.mpoly:
                coords = place.mpoly.coords
                length_of_coords = len(coords)
                if length_of_coords == 1:
                    geometries.append(Polygon(coords[0]))
                elif length_of_coords > 1:
                    geometries.append(MultiPolygon(coords))
            gc = GeometryCollection(geometries)
            features.append(gFeature(geometry=gc, properties=properties))
    featureCollection = FeatureCollection(features)

    directory = "/home/usrfd/maps/" + key + "/"
    if not isdir(directory):
        mkdir(directory)

    serialized = dumps(featureCollection, sort_keys=True)
    with open(directory + key + ".geojson", "wb") as f:
        f.write(serialized)<commit_msg>added importance to final geojson<commit_after>from appfd.models import FeaturePlace, Order
from geojson import Feature as gFeature
from geojson import dumps, FeatureCollection, MultiPolygon, Point, Polygon, GeometryCollection
from os import mkdir
from os.path import isdir

def run(key):
    print "starting create_geojson.run with key " + key

    from django.db import connection
    connection.close()

    features = []
    for fp in FeaturePlace.objects.filter(feature__order__token=key, correct=True).order_by("-place__admin_level"):

            properties = {}

            feature = fp.feature

            if feature.end:
                properties['end_time'] = feature.end.strftime('%y-%m-%d')

            if feature.start:
                properties['start_time'] = feature.start.strftime('%y-%m-%d')

            properties['confidence'] = float(fp.confidence)
            place = fp.place
            properties['admin_level'] = place.admin_level
            properties['admin1_code'] = place.admin1_code
            properties['country_code'] = place.country_code
            try:
                importance = place.wikipedia.importance
            except:
                importance = 0
            properties['importance'] = importance
            properties['name'] = place.name
            properties['geonameid'] = place.geonameid
            properties['pcode'] = place.pcode
            properties['timezone'] = place.timezone
            point = Point((place.point.x, place.point.y))
            geometries = [point]
            if place.mpoly:
                coords = place.mpoly.coords
                length_of_coords = len(coords)
                if length_of_coords == 1:
                    geometries.append(Polygon(coords[0]))
                elif length_of_coords > 1:
                    geometries.append(MultiPolygon(coords))
            gc = GeometryCollection(geometries)
            features.append(gFeature(geometry=gc, properties=properties))
    featureCollection = FeatureCollection(features)

    directory = "/home/usrfd/maps/" + key + "/"
    if not isdir(directory):
        mkdir(directory)

    serialized = dumps(featureCollection, sort_keys=True)
    with open(directory + key + ".geojson", "wb") as f:
        f.write(serialized)
{'fraction_non_alphanumeric': 0.10296846011131726, 'fraction_numerical': 0.002551020408163265, 'mean_word_length': 2.3202463433410316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2388', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1134, 'n_words': 247}