-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add postprocessing_info to device #180
Conversation
@oscgonfer could you review this? Maybe you could post an example payload to verify it works |
Hey, I was testing this now with the following:
Without success, even with the 200:
Am I doing anything wrong? |
@oscgonfer this has not been merged yet - still a work in progress. We need a bit more context / examples on what info we need to save in the database, and how we want to structure it. For example if we want to create a few new columns (how many, what they should be called) in a table that we can sort/index on - or if we just "dump" a long string into a single column. If we talk about the requirements in #179 we can figure out what makes sense. |
@oscgonfer I think what @viktorsmari needs to know is simply: A. We want to store a single level json That is easier to integrate in to the Rails flow and we can easily filter properties inside or via the REST interface with a bit of configuration on Ransak. (more info on Ransak integration) i.e.
B. We want to store a full json object That is easy to integrate if we consider it an string, no search or filter available, at least by default. We can always implement a custom filter or mapping for a specific property i.e.
@viktorsmari I'm explaining that to @oscgonfer as the purpose of using JSON is we don't know yet how the model might grow. However, I don't think option B is bad for now, the same I think option A can perfectly support the model @oscgonfer has in mind. |
Hi, Right now, what I am aiming at is option A. Actually, it would be a single level json with a multiple properties, that will lately be mapped to the IDs here: https://github.com/fablabbcn/smartcitizen-data/blob/master/hardware/hardware.json As @pral2a says, I am not sure atm how the data model will grow, but I rather have the largest amount of information on the framework side, since it's the one that ultimately will make the numbers. Nevertheless, If you think that hardware.json could be or should be fully stored in the postprocessing_info, option B would be best, as this will evolve and should be adaptable to multiple sensor blueprints (2x, 4x, 6x, ... sensors) |
With option B we need to be sure that when updating only Every time we want to update Imagine we do a POST with This would be the perfect use case for a 'nosql' database like Mongodb, where you don't care about the schema and just put in whatever you want. Maybe it's easier to talk on a call to sync faster? |
@viktorsmari I think option A is perfectly fine as @oscgonfer already stated. The {
"updated_at": "2020-10-29T04:35:23Z",
"template_url": "https://github.com/fablabbcn/smartcitizen-data/blob/master/hardware/hardware.json",
"template_version_hash": "434a1d245c3f115e99988a4ae3ed6751bb9f31c3",
"latest_postprocessing": "2020-10-29T08:35:23Z"
} Also, we always plan to update all the properties at once. The application reads the The only time we might need to access the properties individually will be from rails inside. Imagine the case we want to add a |
Fully agree with @pral2a latest comment. Option A it is. |
Closes #179
postprocessing_info
to the db as ajsonb
postprocessing_info
in the controllerJSON.parse
on the controller or will rails handle it?In
mqtt_messages_handler.rb
we do this:device.update hardware_info: JSON.parse(message)
Example PATCH via curl
As a string:
curl -i -X PATCH <url> -d "postprocessing_info=some data here"
Or a JSON:
curl -i -X PATCH <url> -H "Content-Type: application/json" -d '{"postprocessing_info":"bbbca"}'
Nested JSON:
'{"postprocessing_info":{"some":"data2", "other":"data"}}'
Using the data
In rails console, this is stored as:
Allowing nested objects
In order to allow posting nested objects, we need to specify each object on the
device_controller
postprocessing_info: [:some, :other]
https://stackoverflow.com/questions/16549382/how-to-permit-an-array-with-strong-parameters