<commit_before>from framework.log import log

# deprecated ?
def getLocationDictionary(db):
    locations = {}

    try:
        # TODO
        # this is temporary until actual scoring is determined
        sql = """select l.location_id, l.name, l.lat, l.lon, t.score from location l
                left join temp_scores t on t.location_id = l.location_id
                order by l.location_id""";
        data = list(db.query(sql))
        
        for item in data:
            locations[item.name] = {'location_id':item.location_id, 'lat':str(item.lat), 'lon':str(item.lon), 'score': (item.score if item.score else 0)}
    except Exception, e:
        log.info("*** couldn't get or write locations")
        log.error(e)

    return locations
  
def getLocationsWithScoring(db):
    data = []
    
    log.info("*** hit locations")

    try:
        # TODO
        # this is temporary until actual scoring is determined
        sql = """
select l.location_id
    ,l.name
    ,l.lat
    ,l.lon
    ,(select count(*) from project p where p.location_id = l.location_id) as num_projects
    ,(select count(*) from idea i where i.location_id = l.location_id) as num_ideas
    ,(select count(*) from project_resource r where r.location_id = l.location_id) as num_project_resources
from location l""";
        data = list(db.query(sql))
    except Exception, e:
        log.info("*** couldn't get locations")
        log.error(e)

    return data 
        
def getLocations(db):
    data = []

    try:
        sql = """select l.location_id, l.name, l.lat, l.lon from location l
                order by l.location_id""";
        data = list(db.query(sql))
    except Exception, e:
        log.info("*** couldn't get locations")
        log.error(e)

    return data 

def getLocationInfo(db, locationId):
    info = {}
    
    try:
        sql = """select 'n_projects' as key_name, count(*) as num from project where location_id = $id
union
select 'n_ideas' as key_name, count(*) as num from idea where location_id = $id
union
select 'n_resources' as key_name, count(*) as num from project_resource where location_id = $id;"""
        data = list(db.query(sql, {'id':locationId}))

        for item in data:<commit_msg>omitting citywide from neighborhood/borough location data<commit_after>from framework.log import log

# deprecated ?
def getLocationDictionary(db):
    locations = {}

    try:
        # TODO
        # this is temporary until actual scoring is determined
        sql = """select l.location_id, l.name, l.lat, l.lon, t.score from location l
                left join temp_scores t on t.location_id = l.location_id
                order by l.location_id""";
        data = list(db.query(sql))
        
        for item in data:
            locations[item.name] = {'location_id':item.location_id, 'lat':str(item.lat), 'lon':str(item.lon), 'score': (item.score if item.score else 0)}
    except Exception, e:
        log.info("*** couldn't get or write locations")
        log.error(e)

    return locations
  
def getLocationsWithScoring(db):
    data = []
    
    log.info("*** hit locations")

    try:
        # TODO
        # this is temporary until actual scoring is determined
        sql = """
select l.location_id
    ,l.name
    ,l.lat
    ,l.lon
    ,(select count(*) from project p where p.location_id = l.location_id) as num_projects
    ,(select count(*) from idea i where i.location_id = l.location_id) as num_ideas
    ,(select count(*) from project_resource r where r.location_id = l.location_id) as num_project_resources
from location l where l.location_id > 0""";
        data = list(db.query(sql))
    except Exception, e:
        log.info("*** couldn't get locations")
        log.error(e)

    return data 
        
def getLocations(db):
    data = []

    try:
        sql = """select l.location_id, l.name, l.lat, l.lon from location l where l.location_id > 0
                order by l.location_id""";
        data = list(db.query(sql))
    except Exception, e:
        log.info("*** couldn't get locations")
        log.error(e)

    return data 

def getLocationInfo(db, locationId):
    info = {}
    
    try:
        sql = """select 'n_projects' as key_name, count(*) as num from project where location_id = $id
union
select 'n_ideas' as key_name, count(*) as num from idea where location_id = $id
union
select 'n_resources' as key_name, count(*) as num from project_resource where location_id = $id;"""
        data = list(db.query(sql, {'id':locationId}))

        for item in data:
{'fraction_non_alphanumeric': 0.11766004415011037, 'fraction_numerical': 0.0008830022075055188, 'mean_word_length': 2.5537254901960784, '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': '7195444', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1365, 'n_words': 434}