Asap 171 make document import more flexible - #235
Conversation
| @@ -1,11 +1,54 @@ | |||
| class Document < ApplicationRecord | |||
| DEFAULT_DECISION = "Needs Decision".freeze | |||
There was a problem hiding this comment.
I moved constants to the top of the model classes. I think this is a fairly standard pattern.
|
|
||
| has_many :document_inferences | ||
|
|
||
| before_save :set_complexity |
There was a problem hiding this comment.
Before the model is saved, we will now calculate complexity. This means if the underlying field values change, the calculation does as well. I think that is ok.
| location: "San Rafael, CA", | ||
| primary_url: "https://www.cityofsanrafael.org/" | ||
| ) | ||
| puts "Created site: #{san_rafael.name}" |
There was a problem hiding this comment.
Since these sites are already created in production, I wasn't sure if we needed this anymore. It would be nice not to have to maintain a list of sites and/or mapping to files. If we think keeping all the current sites we load into our development environment is useful, I can bring them back.
| (document.number_of_images == 0)) ? Document::SIMPLE_STATUS : Document::COMPLEX_STATUS | ||
| document.complexity = complexity | ||
| document.save | ||
| PaperTrail.request(enabled: false) do |
There was a problem hiding this comment.
I simplified this rake task, which could still be useful.
There was a problem hiding this comment.
I'm not sure what this rake task does anymore? Logically, it seems to be looping over documents where complexity isn't assigned, and then if information on number of tables or images is available, we save the document without any changes?
There was a problem hiding this comment.
Complexity calculation happens every time a document is saved as of this PR. In essence this rake task should be calculating complexity for any documents that are missing it by saving them.
allisonmorgan
left a comment
There was a problem hiding this comment.
The new rake task worked perfectly for me! Had two clarifying questions, but nothing is blocking.
I didn't do a super deep dive on how many simple / complex documents there are before and after this change, but looking at the SLC sample on this branch and the full SLC database on production it looks consistent. Great job!
| (document.number_of_images == 0)) ? Document::SIMPLE_STATUS : Document::COMPLEX_STATUS | ||
| document.complexity = complexity | ||
| document.save | ||
| PaperTrail.request(enabled: false) do |
There was a problem hiding this comment.
I'm not sure what this rake task does anymore? Logically, it seems to be looping over documents where complexity isn't assigned, and then if information on number of tables or images is available, we save the document without any changes?
| self.complexity = calculate_complexity | ||
| end | ||
|
|
||
| def calculate_complexity |
There was a problem hiding this comment.
Just of a question: what's the benefit of having two separate functions set_complexity & calculate_complexity vs one that does both? Not a blocker.
There was a problem hiding this comment.
Great call out. I think I must have not noticed how duplicative they became. I changed it to one simpler function in 24f1178. Thanks!
As we get ready to onboard more stakeholders, they will need to be able to import their own documents. Ideally our import process would be more flexible and not directly coupled to site creation.
This PR simplifies the document bootstrap command and adds a new
document_importcommand. This command requires a site id and allows files in a zip archive or elsewhere. I also cleaned up the models to make them more consistent and added the complexity calculation to the document model. This makes one less rake task for stakeholders to run.Do a
rails db:drop ; rails db:migrate; rails db:setupand make sure bootstrap still works for you. Create a fresh empty site and run a few variants of the document_import command.The rake commands and complexity calculation.
No