I have a base for fanfic that imports data and chapters via Airtables Webclipper. Some fanfics have 100+ chapters, so my base is set up to accomodate up to 125 chapters, one per field.
After a fanfic is imported I want to tagg it for the characters in it that have not yet been tagged and disregard the ones that are mentioned in passing, but aren’t “physically present” in the fic.
As is the code to find A (as in one) character looks like this:
It may be that the problem is not the formula; rather the data model design. If you have to add fields to accommodate a new chapter, that’s not ideal.
When I see a massive number of fields that act as classifiers, it’s almost a sure sign that the data model can be optimized, and such optimizations will lead to far easier filtering and conditional processing without formulaic delirium. :winking_face:
Any idea for a better model?
The reason for the many, many fields are that stories almost always, and sometimes even chapters, excedes maximum number of caracters a cell can hold and the easiest way to ensure this doesn’t happen is to split it to multiple fields. A story can be anything from 1K+ to 500K+ words.
I’m normally a fan of no more fields than neccessary, but here it’s fields-gallore. Only because it adresses the issue (but creates a formula-giant instead).
If there is a better way to go about it I would be ever so thankful for a hint, or an entire map :winking_face: , of shortest road to greatness.
That makes all kinds of sense. Unfortunately scripts are entierly foreign to me and my brain is not working at ideal capacity right now due to illness, so learning a new language (Java?) is out of my ability at the moment, but very tempting for the future.
This base is just a base that I tinker with for something to entertain my brain with (within limits) while recovering. I will definitely mark your answer for later investigation and tinkering.
You could move chapters to a linked table, with one chapter per record. Then each chapter could be responsible for checking for its own characters.
However, if you are using a free workspace, you may have trouble with the record limits.
Moving chapters to attachments could free up space, but formulas cannot search inside attachments. Getting a script to search inside an attachment is doable, but not an easy task for someone new to coding.
This base is just for fun and learning, and to keep track of what I’ve read and and not. With the current setup I get it to easily import warnings, different tags and other data together with the story in it’s entierty with 3 clicks.
The base is in a PRO workspace, so record limit isn’t an issue.
The clunkyness of the formula isn’t an issue either, for now at least.
My question about condensing it has more to do with learning and elegance than functionality to be honest. I see these elegant solutions to various problems in the forum and I wanted input on if this could be condensed in any way, and if so a hint or two as to how.
I’m really greatful for the ideas for different approaches I’ve gotten. It informs my future learning and projects.
Learning how to write an elegant function is a combination of art and part logic. It requires knowing all the vocabulary available to you: both the functions you can use, and the arguments they can take. It also requires understanding the underlying logic of what you are trying to accomplish. Here are just a few things to consider:
Can a different function call simplify a longer pattern, such as converting nested IFs to a SWITCH?
Can the logic be simplified by looking for the opposite condition?
Does the logic contain redundant parts that can be removed?
Of the different functions and operators that will accomplish the same result, which will be the most clear?
Writing an elegant function also requires recognizing that there are many ways to accomplish something in code, and thus many possible working solution. One method of improving your code is to practice refactoring–rewriting the code so that it does the same thing, but in a different way.
Finally, the best solution is the one you understand and can maintain.
Thank you @kuovonne!
That is great advice and nicely breaks down what I can try to improve.
I’m dealing with a temporary setback in what my brain can process due to illness, so scripts look so intresting, but I know it’s a too big a project right now, but a nice carrot for the future.
Your advice is a great road map for what I can do for now to become better, within something that is within my current ability. So truly, thank you!