Skip to content

Commit

Permalink
Adjusted ingest endpoint to be more dynamic
Browse files Browse the repository at this point in the history
Forget the separator correction
  • Loading branch information
sellnat77 committed Dec 10, 2019
1 parent 801093a commit 4ee73ea
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MarkupSafe==1.1.1
multidict==4.5.2
numpy==1.17.4
pandas==0.25.3
psycopg2==2.8.4
python-dateutil==2.8.1
pytz==2019.3
requests==2.22.0
Expand Down
13 changes: 11 additions & 2 deletions server/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ async def sample_route(request):
return json(sample_dataset)


@app.route('/ingest')
@app.route('/ingest', methods=["POST"])
async def ingest(request):
'''Accept POST requests with a list of datasets to import\
based on the YearMapping. Body parameter format is \
{"sets": ["YearMappingKey","YearMappingKey","YearMappingKey"]}'''

ingress_worker = ingress_service(config=app.config['Settings'])
return_data = ingress_worker.ingest()
return_data = {'response':'ingest ok'}

for dataSet in request.json.get("sets", None):
target_data = app.config["Settings"]["YearMapping"][dataSet]
return_data = await ingress_worker.ingest(from_dataset=target_data)

return json(return_data)


Expand Down
8 changes: 4 additions & 4 deletions server/src/services/ingress_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from sqlIngest import DataHandler
from .sqlIngest import DataHandler

class ingress_service(object):
def __init__(self, config=None):
self.config = config


def ingest(self):
async def ingest(self, from_dataset=None):
loader = DataHandler(config=self.config)
loader.loadData()
loader.loadData(fileName=from_dataset)
loader.cleanData()
loader.ingestData()
return {'response':'ingest ok'}
Expand All @@ -24,6 +24,6 @@ def hello_world(self):
if __name__ == "__main__":
from configparser import ConfigParser
config = ConfigParser()
config.read(configFilePath)
config.read('../settings.cfg')
worker = ingress_service(config = config)
worker.ingest()
14 changes: 6 additions & 8 deletions server/src/services/sqlIngest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def loadData(self, fileName="311data"):
self.filePath = os.path.join(self.config['Database']['DATA_DIRECTORY'], dataFile )
print('Loading dataset %s' % self.filePath)
self.data = pd.read_table(self.filePath,
sep=',',
sep=self.separator,
na_values=['nan'],
dtype={
'SRNumber':str,
Expand Down Expand Up @@ -156,10 +156,8 @@ def ingestData(self):
'closedcreatedd':DateTime})

if __name__ == "__main__":
def do_stuff():
loader = DataHandler()
loader.loadConfig('../settings.cfg')
loader.loadData()
loader.cleanData()
loader.ingestData()
do_stuff()
loader = DataHandler()
loader.loadConfig('../settings.cfg')
loader.loadData()
loader.cleanData()
loader.ingestData()
4 changes: 4 additions & 0 deletions server/src/settings.example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ DATA_DIRECTORY = .

[Api]
REDACTED = REDACTED

[YearMapping]
2018_MINI = 2018_mini
2018_FULL = 311data
File renamed without changes.
3 changes: 3 additions & 0 deletions server/src/static/2018_mini.csv
Git LFS file not shown

0 comments on commit 4ee73ea

Please sign in to comment.