Skip to content

Commit 5245aa3

Browse files
committed
input help
1 parent 036d249 commit 5245aa3

3 files changed

Lines changed: 70 additions & 32 deletions

File tree

geosupport/function_info.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,19 @@ def list_functions():
7878
) for function in FUNCTIONS.values()
7979
])
8080
s = ["List of functions (and alternate names):"] + s
81-
s.append("\nUse Geosupport.help(<function>) to read about specific function.")
81+
s.append(
82+
"\nCall a function using the function code or alternate name using "
83+
"Geosupport.<function>() or Geosupport['<function>']()."
84+
"\n\nExample usage:\n"
85+
" from geosupport import Geosupport\n"
86+
" g = Geosupport()\n"
87+
" # Call address using the alternate name.\n"
88+
" g.address(house_number=125, street_name='Worth St', borough_code='Mn')\n"
89+
" # Call function 3 using the function code.\n"
90+
" g['3']({'borough_code': 'MN', 'on': '1 Av', 'from': '1 st', 'to': '2 st'})\n"
91+
"\nUse Geosupport.help(<function>) or Geosupport.<function>.help() "
92+
"to read about specific function."
93+
)
8294
return '\n'.join(s)
8395

8496
def function_help(function):
@@ -106,19 +118,40 @@ def function_help(function):
106118
""
107119
]
108120

109-
#for i in function['inputs']:
110-
# s.append("%s - %s" % (i['name'], i['comment']))
111-
112-
#s.append()
113-
114121
s = "\n".join(s)
115122

116123
return s
117124

125+
def input_help():
126+
#for i in INPUT:
127+
# s.append()
128+
129+
s = [
130+
"\nThe following is a full list of inputs for Geosupport. "
131+
"It has the full name (followed by alternate names.)",
132+
"To use the full names, pass a dictionary of values to the "
133+
"Geosupport functions. Many of the inputs also have alternate names "
134+
"in parantheses, which can be passed as keyword arguments as well.",
135+
"\nInputs",
136+
"="*40,
137+
]
138+
''' + [
139+
"%s (%s)" % (i['name'], ', '.join(i['alt_names'])) for i in INPUT
140+
]'''
141+
142+
for i in INPUT:
143+
s.append("%s (%s)" % (i['name'], ', '.join(i['alt_names'])))
144+
s.append("-"*40)
145+
s.append("Functions: %s" % i['functions'])
146+
s.append("Expected Values: %s\n" % i['value'])
147+
148+
return '\n'.join(s)
149+
118150
FUNCTIONS = load_function_info()
119151

120152
def load_work_area_layouts():
121153
WORK_AREA_LAYOUTS = {}
154+
INPUT = []
122155

123156
for csv in glob.glob(path.join(WORK_AREA_LAYOUTS_PATH, '*', '*.csv')):
124157
directory = path.basename(path.dirname(csv))
@@ -139,10 +172,6 @@ def load_work_area_layouts():
139172
for function in functions:
140173
WORK_AREA_LAYOUTS[directory][function + mode] = layout
141174

142-
'''df = pd.read_csv(
143-
csv, encoding='latin-1', dtype={'from': int, 'to': int, 'formatter': str}
144-
).fillna('')'''
145-
146175
with open(csv) as f:
147176
rows = DictReader(f)
148177

@@ -159,7 +188,6 @@ def load_work_area_layouts():
159188

160189
v = {
161190
'i': (int(row['from']) - 1, int(row['to'])),
162-
#'formatter': get_formatter(row['formatter'])
163191
'formatter': row['formatter']
164192
}
165193

@@ -173,6 +201,14 @@ def load_work_area_layouts():
173201
layout[n.upper()] = v
174202
layout[n.lower()] = v
175203

176-
return WORK_AREA_LAYOUTS
204+
if directory == 'input':
205+
INPUT.append({
206+
'name': name,
207+
'alt_names': alt_names,
208+
'functions': row['functions'],
209+
'value': row['value']
210+
})
211+
212+
return WORK_AREA_LAYOUTS, INPUT
177213

178-
WORK_AREA_LAYOUTS = load_work_area_layouts()
214+
WORK_AREA_LAYOUTS, INPUT = load_work_area_layouts()

geosupport/function_info/work_area_layouts/input/WA1.csv

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ House Number - Sort Format,11,19,29,"1, 1A, 1B, 1E, AP, D*",,,,
55
Low House Number - Display Format,16,30,45,Internal Use,,,,
66
Low House Number - Sort Format,11,46,56,"D*, Internal Use",,,,
77
"B10SC-1 (includes Borough Code 1, B5SC-1 and B7SC-1):",11,57,67,See next 2 entries,,"borough, borough_1,b5sc,b5sc_1,b7sc,b7sc_1,b10sc,b10sc_1",borough,
8-
Borough Code-1,1,57,57,"Required for All Functions but BL, BN. Ignored if Fn 2 has Node Number input",,"borough_code, borough_code_1",borough,"‘1’=Manhattan, ‘2’=Bronx, ‘3’=Brooklyn, ‘4’=Queens, ‘5’=Staten Island"
8+
Borough Code-1,1,57,57,"Required for All Functions but BL, BN. Ignored if Fn 2 has Node Number input",,"borough_code, borough_code_1",borough,"'1'=Manhattan, '2'=Bronx, '3'=Brooklyn, '4'=Queens, '5'=Staten Island"
99
10SC-1,10,58,67,"All but 1N, B*",,"street_code, street_code_1",,
1010
Street Name-1,32,68,99,"All but BL, BN, D*",,"street_name, street, street_name_1, on",,
1111
"B10SC-2 (includes Borough Code 2, B5SC-2 and B7SC-2):",11,100,110,"2, 3*, D*",,"borough_2,b5sc_2,b7sc_2,b10sc_2",borough,
12-
Borough Code-2,1,100,100,"2, 3*, D*",,borough_code_2,borough,"‘1’=Manhattan, ‘2’=Bronx, ‘3’=Brooklyn, ‘4’=Queens, ‘5’=Staten Island"
12+
Borough Code-2,1,100,100,"2, 3*, D*",,borough_code_2,borough,"'1'=Manhattan, '2'=Bronx, '3'=Brooklyn, '4'=Queens, '5'=Staten Island"
1313
10SC-2,10,101,110,"2, 3*, D*",,street_code_2,,
1414
Street Name-2,32,111,142,"2, 3*",,"street_name_2, from",,
1515
"B10SC-3 (includes Borough Code 3, B5SC-3 and B7SC-3):",11,143,153,"3*, D*",,"borough_3,b5sc_3,b7sc_3,b10sc_3",borough,
16-
Borough Code-3,1,143,143,"3*, D*",,borough_code_3,borough,"‘1’=Manhattan, ‘2’=Bronx, ‘3’=Brooklyn, ‘4’=Queens, ‘5’=Staten Island"
16+
Borough Code-3,1,143,143,"3*, D*",,borough_code_3,borough,"'1'=Manhattan, '2'=Bronx, '3'=Brooklyn, '4'=Queens, '5'=Staten Island"
1717
10SC-3,10,144,153,"3*, D*",,street_code_3,,
1818
Street Name-3,32,154,185,3*,,"street_name_3, to",,
1919
BOROUGH BLOCK LOT (BBL),10,186,195,BL,,bbl,,
@@ -22,36 +22,36 @@ Tax Block,5,187,191,BL,,bbl_block,,
2222
Tax Lot,4,192,195,BL,,bbl_lot,,
2323
Filler for Tax Lot Version Number,1,196,196,Not Implemented,,,,
2424
Building Identification Number (BIN),7,197,203,BN,,bin,,
25-
Compass Direction,1,204,204,"2, 3C, 3S",,"compass_direction_1, compass_direction",,"‘N’, ‘S’, ‘E’ or ‘W’"
26-
Compass Direction for 2nd Intersection,1,205,205,3S,,compass_direction_2,,"‘N’, ‘S’, ‘E’ or ‘W’"
25+
Compass Direction,1,204,204,"2, 3C, 3S",,"compass_direction_1, compass_direction",,"'N', 'S', 'E' or 'W'"
26+
Compass Direction for 2nd Intersection,1,205,205,3S,,compass_direction_2,,"'N', 'S', 'E' or 'W'"
2727
Node Number,7,206,212,"2, 2W",,"node, node_number",,Seven-digit number
28-
Work Area Format Indicator,1,213,213,All,,work_area_format,,"‘C’ = COW format
28+
Work Area Format Indicator,1,213,213,All,,work_area_format,,"'C' = COW format
2929
Blank = MSW format"
3030
ZIP Code Input,5,214,218,"1*, AP",,"zip, zip_code",,
3131
Unit Input,14,219,232,1*,,,,
3232
Filler,82,233,314,,,,,
33-
Long Work Area 2 Flag,1,315,315,"1A, BL",,long_work_area_2,long_work_area_2,"‘L’ = Long WA2,
33+
Long Work Area 2 Flag,1,315,315,"1A, BL",,long_work_area_2,long_work_area_2,"'L' = Long WA2,
3434
Blank = regular WA2"
3535
House Number Justification Flag,1,316,316,Not Implemented,,,,
3636
House Number Normalization Length,2,317,318,Not Implemented,,,,
3737
House Number Normalization Override Flag,1,319,319,Internal Use,,,,
3838
Street Name Normalization Length Limit (SNL),2,320,321,All but B*,,snl,,A number between 4 and 32
39-
Street Name Normalization Format Flag,1,322,322,All but B*,,street_name_normalization,street_name_normalization,"‘C’ = compact format,
39+
Street Name Normalization Format Flag,1,322,322,All but B*,,street_name_normalization,street_name_normalization,"'C' = compact format,
4040
Blank = sort format"
41-
Cross Street Names Flag a.k.a. Expanded Format Flag,1,323,323,"1, 1A, 1B, 1E, 2, 3, 3C",,cross_street_names,cross_street_names,"‘E’ = return names
41+
Cross Street Names Flag a.k.a. Expanded Format Flag,1,323,323,"1, 1A, 1B, 1E, 2, 3, 3C",,cross_street_names,cross_street_names,"'E' = return names
4242
Blank = do not return names"
43-
Roadbed Request Switch,1,324,324,"1, 1B, 1E, 3S (Limited)",,roadbed_request_switch,roadbed_request_switch,"‘R’ = Roadbed info requested
43+
Roadbed Request Switch,1,324,324,"1, 1B, 1E, 3S (Limited)",,roadbed_request_switch,roadbed_request_switch,"'R' = Roadbed info requested
4444
Blank = Generic info requested"
4545
Reserved for Internal Use,1,325,325,Internal GRC Flag,,,,
46-
Auxiliary Segment Switch,1,326,326,"3, 3C",,"auxseg, segaux, auxiliary_segment_switch",auxseg,"‘Y’ = return all segment IDs
47-
‘N’ or Blank = regular WA2"
48-
Browse Flag,1,327,327,"1*, 2, 3, 3C, BB, BF",,,,"‘P’ = primary street name / code
49-
‘F’ = principal street name / code
50-
‘R’ = DCP preferred street name
46+
Auxiliary Segment Switch,1,326,326,"3, 3C",,"auxseg, segaux, auxiliary_segment_switch",auxseg,"'Y' = return all segment IDs
47+
'N' or Blank = regular WA2"
48+
Browse Flag,1,327,327,"1*, 2, 3, 3C, BB, BF",,,,"'P' = primary street name / code
49+
'F' = principal street name / code
50+
'R' = DCP preferred street name
5151
Blank = input street name / code"
5252
Real Streets Only Flag,1,328,328,3S,,real_streets_only,real_streets_only,
53-
TPAD Switch,1,329,329,"1A, 1B, BL, BN",,tpad,tpad,"‘Y’ = TPAD information requested
54-
Blank or ‘N’ = TPAD not requested"
55-
Mode Switch,1,330,330,"1, 1E, 1A, 3, 3C, AP",,mode_switch,mode_switch,"‘X’ = Extended Mode Work Area 2
53+
TPAD Switch,1,329,329,"1A, 1B, BL, BN",,tpad,tpad,"'Y' = TPAD information requested
54+
Blank or 'N' = TPAD not requested"
55+
Mode Switch,1,330,330,"1, 1E, 1A, 3, 3C, AP",,mode_switch,mode_switch,"'X' = Extended Mode Work Area 2
5656
Blank = normal mode"
5757
WTO Switch,1,331,331,All,,,,

geosupport/geosupport.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
from geosupport.error import GeosupportError
5-
from geosupport.function_info import FUNCTIONS, function_help, list_functions
5+
from geosupport.function_info import FUNCTIONS, function_help, list_functions, input_help
66
from geosupport.io import format_input, parse_output, set_mode
77

88
class Geosupport(object):
@@ -95,6 +95,8 @@ def __getitem__(self, name):
9595

9696
def help(self, name=None):
9797
if name:
98+
if name.upper() == 'INPUT':
99+
return input_help()
98100
try:
99101
return function_help(name)
100102
except KeyError:

0 commit comments

Comments
 (0)