Skip to content

Instantly share code, notes, and snippets.

View gordonje's full-sized avatar

James Gordon gordonje

View GitHub Profile
@gordonje
gordonje / F501_2016.sql
Last active August 24, 2016 12:46
Form 501 filed by month
select
date_part('month', a."RPT_DATE") as month,
date_part('year', a."RPT_DATE") as year,
COUNT(*) as the_count
from "F501_502_CD" a
join "FILER_FILINGS_CD" b
on a."FILING_ID" = b."FILING_ID"
where a."YR_OF_ELEC" = 2016
and a."FORM_TYPE" = 'F501'
group by 1, 2
@gordonje
gordonje / part4_filings.sql
Created May 1, 2016 02:29
F460 part4 vs part5
SELECT date_part('year', "DEADLINE") as deadline_year, COUNT(*)
FROM "FILER_FILINGS_CD" as a
JOIN "FILING_PERIOD_CD" as b
ON a."PERIOD_ID" = b."PERIOD_ID"
WHERE "FILING_ID" in (
SELECT "FILING_ID"
FROM "CVR2_CAMPAIGN_DISCLOSURE_CD"
WHERE upper("F460_PART") in ('4A', '4B')
)
GROUP BY 1
@gordonje
gordonje / __init__.py
Last active February 7, 2016 06:37
for checking tsv lines while cleaning.
# django-calaccess-raw-data/calaccess_raw/__init__.py
def get_model_from_file_name(file_name):
"""
Returns a calaccess_raw model to which the given .CSV or .TSV file maps
"""
from django.apps import apps
import re
model_name = re.sub(r'\.\w+', '', file_name).title().replace('_', '')
return apps.get_app_config("calaccess_raw").get_model(model_name)
@gordonje
gordonje / .sql
Created October 22, 2015 21:37
max lottery wins by a person at each store
-- what we want our distinct stores and the max number of wins for a person that played there
SELECT "AGENT NAME", max(count_person_wins), max(sum_person_winnings)
FROM (
-- gets us the number of wins per person for each store
SELECT
"AGENT NAME"
, "FIRSTNAME"
, "LASTNAME"
, "CITY"
, "STATE"