def process_summons(filename):
    """
    Convert a single Excel file to two rows of a CSV.
    """
    sh = xlrd.open_workbook(filename).sheet_by_index(0)
    geog = sh.row(1)[0].value
    month = month2num(sh.row(2)[0].value)
    year = int(sh.row(3)[2].value[-4:])

    data = {}
    for rnum in xrange(4, 39):
        prev_row = sh.row(rnum - 1)
        row = sh.row(rnum)

        if row[0].ctype == 0:
            col_val = prev_row[0].value.split(u'\n')[-1]
        else:
            col_val = row[0].value.split(u'\n')[0]

        if row[1].ctype == 0:
            mtd_val = int(prev_row[1].value.split(u'\n')[-1])
        else:
            mtd_val = int(row[1].value) if row[1].ctype == 2 else int(
                row[1].value.split(u'\n')[0])

        if row[2].ctype == 0:
            ytd_val = int(prev_row[2].value.split(u'\n')[-1])
        else:
            ytd_val = int(row[2].value) if row[2].ctype == 2 else int(
                row[2].value.split(u'\n')[0])

        mtd_col = columnize(col_val + u' mtd')
        ytd_col = columnize(col_val + u' ytd')

        data[mtd_col] = mtd_val
        data[ytd_col] = ytd_val

    sys.stdout.write(u'\t'.join([unicode(geog),
                                 unicode(year),
                                 unicode(month)]))
    for c in DATA_COLUMNS:
        sys.stdout.write(u'\t' + unicode(data[c]))
    sys.stdout.write(u'\n')
def process_summons(filename):
    """
    Convert a single Excel file to two rows of a CSV.
    """
    sh = xlrd.open_workbook(filename).sheet_by_index(0)
    geog = sh.row(1)[0].value
    month = month2num(sh.row(2)[0].value)
    year = int(sh.row(3)[2].value[-4:])

    data = {}
    for rnum in xrange(4, 39):
        prev_row = sh.row(rnum - 1)
        row = sh.row(rnum)

        if row[0].ctype == 0:
            col_val = prev_row[0].value.split(u'\n')[-1]
        else:
            col_val = row[0].value.split(u'\n')[0]

        if row[1].ctype == 0:
            mtd_val = int(prev_row[1].value.split(u'\n')[-1])
        else:
            mtd_val = int(row[1].value) if row[1].ctype == 2 else int(row[1].value.split(u'\n')[0])

        if row[2].ctype == 0:
            ytd_val = int(prev_row[2].value.split(u'\n')[-1])
        else:
            ytd_val = int(row[2].value) if row[2].ctype == 2 else int(row[2].value.split(u'\n')[0])

        mtd_col = columnize(col_val + u' mtd')
        ytd_col = columnize(col_val + u' ytd')

        data[mtd_col] = mtd_val
        data[ytd_col] = ytd_val

    sys.stdout.write(u'\t'.join([unicode(geog), unicode(year), unicode(month)]))
    for c in DATA_COLUMNS:
        sys.stdout.write(u'\t' + unicode(data[c]))
    sys.stdout.write(u'\n')
                u'Bus',
                u'Fire truck',
                u'Large com veh(6 or more tires)',
                u'Livery vehicle',
                u'Motorcycle',
                u'Other',
                u'Passenger vehicle',
                u'Pedicab',
                u'Pick-up truck',
                u'Scooter',
                u'Small com veh(4\ntires)',
                u'Sport utility /\nstation wagon',
                u'Taxi vehicle',
                u'Unknown',
                u'Van'])
VEHICLE_COLUMNS = [columnize(v) for v in sorted(VEHICLES)]

CONTRIBUTING_FACTORS = set([u'Driver inexperience',
                            u'Fatigued/Drowsy',
                            u'Traffic control disregarded',
                            u'Backing unsafely',
                            u'Err/Confusn ped/Bike/Other ped',
                            u'Lost consciousness',
                            u'Other uninvolved vehicle',
                            u'Turning improperly',
                            u'Physical disability',
                            u'Prescription medication',
                            u'Listening/using headphones',
                            u'Vehicle vandalism',
                            u'Eating or drinking',
                            u'Texting',
Beispiel #4
0
    from pygeolib import GeocoderError
    GEOCODER = pygeocoder.Geocoder
except ImportError:
    sys.stderr.write(u"No geocoder available\n")
    GEOCODER = None

INTERSECTIONS_LONLAT_PATH = 'public/intersections.txt'

VEHICLES = set([
    u'Ambulance', u'Bicycle', u'Bus', u'Fire truck',
    u'Large com veh(6 or more tires)', u'Livery vehicle', u'Motorcycle',
    u'Other', u'Passenger vehicle', u'Pedicab', u'Pick-up truck', u'Scooter',
    u'Small com veh(4\ntires)', u'Sport utility /\nstation wagon',
    u'Taxi vehicle', u'Unknown', u'Van'
])
VEHICLE_COLUMNS = [columnize(v) for v in sorted(VEHICLES)]

CONTRIBUTING_FACTORS = set([
    u'Driver inexperience', u'Fatigued/Drowsy', u'Traffic control disregarded',
    u'Backing unsafely', u'Err/Confusn ped/Bike/Other ped',
    u'Lost consciousness', u'Other uninvolved vehicle', u'Turning improperly',
    u'Physical disability', u'Prescription medication',
    u'Listening/using headphones', u'Vehicle vandalism', u'Eating or drinking',
    u'Texting', u'Unsafe speed', u'Outside car distraction',
    u'Other electronic device', u'Alcohol involvement',
    u'Aggressive driving/road rage', u'Fell asleep', u'Cell phone (hand-held)',
    u'Illness', u'Driver inattention/distraction',
    u'Failure to yield right-of-way', u'Passenger distraction',
    u'Passing or lane usage', u'Following too closely',
    u'Unsafe lane changing', u'Failure to keep right', u'Drugs (illegal)'
])
SUMMONS = [
    u'Backing Unsafely', u'Brake Lights (Defect.or  Improper)',
    u'Bus Lane, Driving in', u'Cell Phone', u'Commercial Veh on Pkwy',
    u'Defective Brakes', u'Disobey Sign', u'Equipment (Other)',
    u'Fail to Keep Right', u'Fail to Signal', u'Fail to Stop on Signal',
    u'Following Too Closely', u'Headlights (Defect. or Improper)',
    u'Improper Lights', u'Improper Passing', u'Improper Turn',
    u'Improper/Missing Plates', u'Not Giving R of W to Pedes.',
    u'Not Giving R of W to Veh.', u'One Way Street', u'Pavement Markings',
    u'Safety Belt', u'School Bus, Passing Stopped', u'Speeding', u'Spillback',
    u'Tinted Windows', u'Truck Routes', u'U-Turn', u'Uninspected',
    u'Uninsured', u'Unlicensed Operator', u'Unregistered',
    u'Unsafe Lane Change', u'Other Movers', u'TOTAL Movers'
]
DATA_COLUMNS = [columnize(s + u' mtd') for s in SUMMONS]
DATA_COLUMNS.extend([columnize(s + u' ytd') for s in SUMMONS])


def process_summons(filename):
    """
    Convert a single Excel file to two rows of a CSV.
    """
    sh = xlrd.open_workbook(filename).sheet_by_index(0)
    geog = sh.row(1)[0].value
    month = month2num(sh.row(2)[0].value)
    year = int(sh.row(3)[2].value[-4:])

    data = {}
    for rnum in xrange(4, 39):
        prev_row = sh.row(rnum - 1)
           u'Pavement Markings',
           u'Safety Belt',
           u'School Bus, Passing Stopped',
           u'Speeding',
           u'Spillback',
           u'Tinted Windows',
           u'Truck Routes',
           u'U-Turn',
           u'Uninspected',
           u'Uninsured',
           u'Unlicensed Operator',
           u'Unregistered',
           u'Unsafe Lane Change',
           u'Other Movers',
           u'TOTAL Movers']
DATA_COLUMNS = [columnize(s + u' mtd') for s in SUMMONS]
DATA_COLUMNS.extend([columnize(s + u' ytd') for s in SUMMONS])


def process_summons(filename):
    """
    Convert a single Excel file to two rows of a CSV.
    """
    sh = xlrd.open_workbook(filename).sheet_by_index(0)
    geog = sh.row(1)[0].value
    month = month2num(sh.row(2)[0].value)
    year = int(sh.row(3)[2].value[-4:])

    data = {}
    for rnum in xrange(4, 39):
        prev_row = sh.row(rnum - 1)