Skip to content

Instantly share code, notes, and snippets.

View bschoenfeld's full-sized avatar

Ben Schoenfeld bschoenfeld

  • Port Solution Integrators
  • Portsmouth, VA
View GitHub Profile
Locality 9 10 11 12 13 14 Average
Buena Vista -0.4 2.2 5.8 4.7 6.2 6.3 4.1
Bristol 3.2 6.0 1.4 0.7 1.6 3.9 2.8
Emporia -0.4 5.7 3.6 3.2 2.0 1.3 2.6
Hampton -0.2 0.8 5.6 3.3 2.3 1.5 2.2
Colonial Heights -0.4 1.1 2.6 2.1 4.0 3.7 2.2
Franklin -0.2 1.0 1.6 4.6 2.1 3.1 2.1
Chesapeake -0.3 2.0 3.1 2.4 2.1 1.1 1.7
Alexandria 5.5 1.4 0.7 0.5 0.9 1.0 1.7
Bath County 0.0 2.8 2.3 2.1 0.8 0.2 1.4
# Graph miles driven per ticket by locality
data = []
# For each locality, create a tuple with the name of the locality
# and the miles driven per ticket
for court in traffic_by_court:
# Remove Manassas because it makes the locality name too long
localities = [l for l in court['locality'] if 'Manassas' not in l]
locality = ' / '.join(localities)
data.append((locality, court['all'] * 365 / court['chargeCount']))
data.sort(key=lambda x: x[1], reverse=True)
SPEEDING_CODE_SECTIONS = [
'18.2-456',
'22-395',
'22-396',
'46.2-0000',
'46.2-830',
'46.2-848',
'46.2-852',
'46.2-861',
'46.2-862',
[
{
"locality": ["Newport News"],
"fips": [701, 702, 703],
"all": 4365476,
"chargeCount": 100000
},
...
]
def load_traffic_data():
traffic = {}
with open('data/traffic_daily_vehicle_miles_traveled_2015.csv') as f:
reader = csv.DictReader(f)
for row in reader:
if row['District Court FIPS Codes'] == '':
continue
if row['District Court FIPS Codes'] not in traffic:
# Some district courts are represented in the traffic data
# by mulitple localities. So instead of just loading the traffic
import urllib2
from bs4 import BeautifulSoup
# get the web page
url = "http://healthspace.com/Clients/VDH/NewRiver/web.nsf/module_facilities.xsp?module=Food"
web_page = urllib2.urlopen(url)
web_page_html = web_page.read()
# write the web page to a file
# google "python write to file"
@bschoenfeld
bschoenfeld / courts.py
Created November 14, 2014 20:37
VA Circuit Court Search
from bs4 import BeautifulSoup
import scraperwiki
import cookielib, urllib, urllib2
import sys
def getNames(html, name):
for row in html.find(class_="nameList").find_all('tr'):
cols = row.find_all('td')
if len(cols) > 4:
if name not in cols[1].string:
@bschoenfeld
bschoenfeld / data.json
Created November 14, 2014 17:39
Health Inspection Data for Heatmap
This file has been truncated, but you can view the full file.
[{"lat": 36.77721, "count": 100, "lng": -77.87301}, {"lat": 36.80509, "count": 99, "lng": -78.94802}, {"lat": 36.99772, "count": 100, "lng": -79.04197}, {"lat": 36.67743, "count": 97, "lng": -78.9196}, {"lat": 36.735, "count": 86, "lng": -78.91515}, {"lat": 36.76143, "count": 100, "lng": -78.76973}, {"lat": 36.69857, "count": 100, "lng": -78.92031}, {"lat": 36.70611, "count": 95, "lng": -78.94777}, {"lat": 36.67466, "count": 90, "lng": -78.92763}, {"lat": 36.735, "count": 95, "lng": -78.91515}, {"lat": 36.70478, "count": 94, "lng": -78.89878}, {"lat": 36.56512, "count": 100, "lng": -79.1404}, {"lat": 36.68801, "count": 100, "lng": -78.8965}, {"lat": 36.73745, "count": 98, "lng": -78.91978}, {"lat": 36.69708, "count": 91, "lng": -78.90118}, {"lat": 36.94173, "count": 94, "lng": -78.75275}, {"lat": 36.72836, "count": 96, "lng": -79.13531}, {"lat": 36.73383, "count": 100, "lng": -78.88802}, {"lat": 36.71382, "count": 100, "lng": -78.91707}, {"lat": 37.03008, "count": 78, "lng": -78.95301}, {"lat": 36.70086, "cou
--- C:/Users/BSCHOE~1/AppData/Local/Temp/underscore.js-revBASE.svn000.tmp.js Tue Mar 5 11:30:16 2013
+++ C:/bschoenfeld/OPs_Service_Bus/VIT.NIT.OPS.HatchChecker/WebServer/Scripts/underscore.js Tue Mar 5 11:48:58 2013
@@ -238,7 +238,7 @@
// Convenience version of a common use case of `filter`: selecting only objects
// containing specific `key:value` pairs.
_.where = function(obj, attrs, first) {
- if (_.isEmpty(attrs)) return first ? void 0 : [];
+ if (_.isEmpty(attrs)) return first ? null : [];
return _[first ? 'find' : 'filter'](obj, function(value) {
for (var key in attrs) {
from datetime import datetime, timedelta
from pymongo import Connection, GEO2D
class HRTDatabase:
def __init__(self, uri):
self.client = Connection(uri)
self.database = self.client.hrt
def insertStops(self, data, date):
collectionName = self.genCollectionName('stops_', date)