Beispiel #1
0
def search_city():
	city = request.args['city']
	with cursor() as cur:
		cur.execute("""SELECT DISTINCT city FROM msa WHERE city ~~* '%{}%' """.format(city))
		results = cur.fetchall()
	for r in results:
		r['inputPhrase'] = city
	return jsonify({'results': results})
Beispiel #2
0
def search_state():
	with cursor() as cur:
		state = request.args['state']
		cur.execute("""SELECT DISTINCT state FROM msa WHERE state ~~* '{}%' """.format(state))
		results = cur.fetchall()
		for r in results:
			r['inputPhrase'] = state
		return jsonify({'results': results})
Beispiel #3
0
def search_city():
    city = request.args['city']
    with cursor() as cur:
        cur.execute(
            """SELECT DISTINCT city FROM msa WHERE city ~~* '%{}%' """.format(
                city))
        results = cur.fetchall()
    for r in results:
        r['inputPhrase'] = city
    return jsonify({'results': results})
Beispiel #4
0
def search_state():
    with cursor() as cur:
        state = request.args['state']
        cur.execute(
            """SELECT DISTINCT state FROM msa WHERE state ~~* '{}%' """.format(
                state))
        results = cur.fetchall()
        for r in results:
            r['inputPhrase'] = state
        return jsonify({'results': results})
Beispiel #5
0
def load_states():
	analyzer =  NgramAnalyzer(1,2)
	state_schema = Schema(state=ID(stored=True,analyzer=analyzer))
	with cursor() as cur:
		print('Loading states...')
		cur.execute('SELECT DISTINCT state FROM msa');
		state_index = storage.create_index(state_schema)
		writer = state_index.writer()
		for s in cur.fetchall():
			writer.add_document(state=s[u'state'])
		writer.commit()
	return state_index
Beispiel #6
0
def search_occ():
	query = request.args['occ_title']
	# results = search.find_occ(query)
	# for r in results:
	# 	r['inputPhrase'] = query
	# return jsonify({'results': results})
	with cursor() as cur:
		cur.execute("""SELECT DISTINCT occ_title, occ_code FROM msa WHERE occ_title ~~* '%{}%' """.format(query))
		results = cur.fetchall()
	for r in results:
		r['inputPhrase'] = query
	return jsonify({'results': results})
Beispiel #7
0
def load_states():
    analyzer = NgramAnalyzer(1, 2)
    state_schema = Schema(state=ID(stored=True, analyzer=analyzer))
    with cursor() as cur:
        print('Loading states...')
        cur.execute('SELECT DISTINCT state FROM msa')
        state_index = storage.create_index(state_schema)
        writer = state_index.writer()
        for s in cur.fetchall():
            writer.add_document(state=s[u'state'])
        writer.commit()
    return state_index
Beispiel #8
0
def load_cities():
    analyzer = NgramAnalyzer(1)
    city_schema = Schema(state=ID(stored=True),
                         city=ID(stored=True, analyzer=analyzer))
    with cursor() as cur:
        print('Loading cities...')
        cur.execute('SELECT DISTINCT state, city FROM msa')
        city_index = storage.create_index(city_schema)
        writer = city_index.writer()
        for s in cur.fetchall():
            writer.add_document(state=s[u'state'], city=s[u'city'])
        writer.commit()
    return city_index
Beispiel #9
0
def a_median_by_state():
	with cursor() as cur:
		# pdb.set_trace()
		sql="""SELECT occ_code,
					  state,
					  SUM(a_mean*tot_emp)/SUM(tot_emp) AS a_mean
			     FROM msa
			     WHERE occ_code = '{occ_code}'
			     GROUP BY 1,2""".format(**request.args)

		cur.execute(sql)
		print(sql)
		return jsonify({'data':cur.fetchall()})
Beispiel #10
0
def load_occs():
	analyzer =  NgramAnalyzer(3)
	occ_schema = Schema(occ_title=TEXT(stored=True,analyzer=analyzer),
		occ_code=ID(stored=True))
	with cursor() as cur:
		print('Loading occs...')
		cur.execute('SELECT DISTINCT occ_code, occ_title FROM msa');
		occ_index = storage.create_index(occ_schema)
		writer = occ_index.writer()
		for s in cur.fetchall():
			writer.add_document(occ_title=s[u'occ_title'],occ_code=s[u'occ_code'])
		writer.commit()
	return occ_index
Beispiel #11
0
def load_cities():
	analyzer =  NgramAnalyzer(1)
	city_schema = Schema(state=ID(stored=True),
		city=ID(stored=True,analyzer=analyzer))
	with cursor() as cur:
		print('Loading cities...')
		cur.execute('SELECT DISTINCT state, city FROM msa');
		city_index = storage.create_index(city_schema)
		writer = city_index.writer()
		for s in cur.fetchall():
			writer.add_document(state=s[u'state'],city=s[u'city'])
		writer.commit()
	return city_index
Beispiel #12
0
def a_median_by_state():
    with cursor() as cur:
        # pdb.set_trace()
        sql = """SELECT occ_code,
					  state,
					  SUM(a_mean*tot_emp)/SUM(tot_emp) AS a_mean
			     FROM msa
			     WHERE occ_code = '{occ_code}'
			     GROUP BY 1,2""".format(**request.args)

        cur.execute(sql)
        print(sql)
        return jsonify({'data': cur.fetchall()})
Beispiel #13
0
def load_occs():
    analyzer = NgramAnalyzer(3)
    occ_schema = Schema(occ_title=TEXT(stored=True, analyzer=analyzer),
                        occ_code=ID(stored=True))
    with cursor() as cur:
        print('Loading occs...')
        cur.execute('SELECT DISTINCT occ_code, occ_title FROM msa')
        occ_index = storage.create_index(occ_schema)
        writer = occ_index.writer()
        for s in cur.fetchall():
            writer.add_document(occ_title=s[u'occ_title'],
                                occ_code=s[u'occ_code'])
        writer.commit()
    return occ_index
Beispiel #14
0
def top_salaries_in_state_by_city():
	
	sql = """SELECT occ_code,
					state,
					city,
	                a_mean
		       FROM msa 
			   WHERE occ_code ='{occ_code}' AND state = '{state}'
			   ORDER BY a_mean DESC
			   LIMIT 10""".format(**request.args)
	with cursor() as cur:
		print(sql)
		cur.execute(sql)
		return jsonify({'data':cur.fetchall()})
Beispiel #15
0
def search_occ():
    query = request.args['occ_title']
    # results = search.find_occ(query)
    # for r in results:
    # 	r['inputPhrase'] = query
    # return jsonify({'results': results})
    with cursor() as cur:
        cur.execute(
            """SELECT DISTINCT occ_title, occ_code FROM msa WHERE occ_title ~~* '%{}%' """
            .format(query))
        results = cur.fetchall()
    for r in results:
        r['inputPhrase'] = query
    return jsonify({'results': results})
Beispiel #16
0
def top_salaries_in_state_by_city():

    sql = """SELECT occ_code,
					state,
					city,
	                a_mean
		       FROM msa 
			   WHERE occ_code ='{occ_code}' AND state = '{state}'
			   ORDER BY a_mean DESC
			   LIMIT 10""".format(**request.args)
    with cursor() as cur:
        print(sql)
        cur.execute(sql)
        return jsonify({'data': cur.fetchall()})
Beispiel #17
0
def stats_by_state_city_occ():
	with cursor() as cur:
		# pdb.set_trace()
		sql="""SELECT state,
					  city,
					  occ_title,
					  occ_code,
					  tot_emp,
					  jobs_1000,
					  h_mean,
					  a_mean,
					  h_median,
					  a_median
				FROM msa
			   WHERE state ~~* '{state}'
			     	 AND city ~~* '{city}'
			     	 AND occ_code = '{occ_code}'""".format(**request.args)

		cur.execute(sql)
		print(sql)
		return jsonify({'data':cur.fetchall()})
Beispiel #18
0
def stats_by_state_city_occ():
    with cursor() as cur:
        # pdb.set_trace()
        sql = """SELECT state,
					  city,
					  occ_title,
					  occ_code,
					  tot_emp,
					  jobs_1000,
					  h_mean,
					  a_mean,
					  h_median,
					  a_median
				FROM msa
			   WHERE state ~~* '{state}'
			     	 AND city ~~* '{city}'
			     	 AND occ_code = '{occ_code}'""".format(**request.args)

        cur.execute(sql)
        print(sql)
        return jsonify({'data': cur.fetchall()})