Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying client routes for data validation #44

Closed
im-prakher opened this issue Jun 11, 2020 · 3 comments
Closed

Modifying client routes for data validation #44

im-prakher opened this issue Jun 11, 2020 · 3 comments
Assignees

Comments

@im-prakher
Copy link
Contributor

im-prakher commented Jun 11, 2020

The goal of this issue is to implement data validation for shapefiles, spreadsheets before API data ingestion by modifying existing API routes functionality.

BETYdb-YABA/app/Meta.py

Lines 52 to 72 in 64b540e

try:
user_id=fetch_id(username, table='users')
if not user_id:
return 401
#Reading the CSV file into DataFrame
data = pd.read_csv(fileName,delimiter = ',')
#Checking necessary columns are there.
columns=data.columns.values.tolist()
accepted_columns=['name','start_date','end_date','description','design']
if(all(x in accepted_columns for x in columns)):
data['user_id']=user_id
data['design'].fillna('some text', inplace=True)
insert_table(table='experiments',data=data)
msg = {'Message' : 'Successfully inserted',
'Table Affected' : 'Experiments',
'Lines Inserted': data.shape[0]}
return make_response(jsonify(msg), 201)
#

Like, the code in this function responds to /yaba/v1/experiments (for inserting experiments in the BETY database), we can modify this, by accepting one more parameter as status(which can be true or false), if false then return a valid response after validating data otherwise continue with data insertion. In this example, we can check the status after line 64, if true we can return a response from there only and stop further execution otherwise continue with data insertion.

if(all(x in accepted_columns for x in columns)):
>> if(status == false)
>>>> msg = {'Message' : true }
>>>> return make_response(jsonify(msg), 200)

So, what do you say?
@dlebauer @KristinaRiemer @saurabh1969 @Chris-Schnaufer

@saurabh1969
Copy link
Contributor

Can you elaborate about status parameter?

@im-prakher
Copy link
Contributor Author

It will be a Boolean. A false value indicates that data should be only validated and a response should be returned accordingly, while a true value tells us that data should also be inserted.

@im-prakher
Copy link
Contributor Author

Done in #69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants