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

Backend/feature/measurement without event #321

Merged
merged 3 commits into from
Apr 9, 2020

Conversation

VentusXu09
Copy link
Contributor

Take the first event as the active event for end to end demo

@VentusXu09 VentusXu09 requested a review from alldne April 8, 2020 22:56
}

for d in dic:
if json_data.get(dic[d]) is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: name suggestion for readability

key_map = {                           
    "timestamp": "date",              
    "sensor_id": "sensor_id",         
    "value": "values",                
}                                     
                                      
for key, json_key in key_map.items(): 
    if json_key not in json_data:     
        return Response(...)          
    res[key] = json_data[json_key]    

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion! I have updated the code.

@@ -12,12 +12,42 @@ def build_error(str):
return json.dumps({"error": str})


def add_measurement(request, event):
json_data = request.data
if isinstance(json_data, str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if json_data is not str?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be a JSON dict. The only case that the json_data is a string is that it is transferred through radio script since the native request module can only accept the string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Later it would be great to add assert for the input type (i.e either a JSON dict or a stringified json, otherwise fail loudly). But looks good to me at this point.

Copy link
Contributor

@alldne alldne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alldne alldne merged commit 4618901 into backend/develop Apr 9, 2020
@alldne alldne deleted the backend/feature/measurement_without_event branch April 9, 2020 13:57
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

Successfully merging this pull request may close these issues.

Tech story : Modify the existing API and data sender simulator to work without using event_id.
2 participants