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

ICF Off-model calculator - Refactor 1-3, Feature 1-3 #74

Closed

Conversation

caroarriaga
Copy link

@caroarriaga caroarriaga commented Jul 17, 2024

Summary

This PR refactors the architecture of the script processing the copying and updating off-model calculator files.
Additionally, it includes the first part of Feature 1 applied to the bike share calculator.

Details

Refactor 1: rearranged methods into calculator classes and subclasses.
Refactor 2: added user type (mtc, external) to point to specific directory paths.
Refactor 3: the calculator updates SB375 data into all calculators.

Feature 1: all calculator variables and corresponding cell location in Excel are centralized.
Feature 2: automatically open and close excel to update formulas.
Feature 3: log in the corresponding calculators the outputs.

@caroarriaga caroarriaga marked this pull request as ready for review July 17, 2024 00:32
@caroarriaga caroarriaga marked this pull request as draft July 17, 2024 00:33
@caroarriaga caroarriaga marked this pull request as ready for review July 17, 2024 00:37
@caroarriaga caroarriaga marked this pull request as draft July 17, 2024 00:41
@caroarriaga caroarriaga marked this pull request as draft July 17, 2024 00:41
@yuqiww yuqiww requested review from yuqiww and lmz July 17, 2024 05:14
@lmz
Copy link
Member

lmz commented Jul 19, 2024

Hello - Thanks for making this PR! Appreciate it! I'll drop some initial comments (nothing huge) as comments.

Copy link
Member

Choose a reason for hiding this comment

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

I think these files should live on Box rather than in GitHub. It's likely our workflow will include a number of iterations on model runs and there's no need to repeatedly commit data files to GitHub since they don't serve any purpose here, and Box keeps versions/timestamps.

Copy link
Author

Choose a reason for hiding this comment

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

@lmz I agree, the purpose of these files (at least having a couple of them as samples) is to give flexibility to people who don't have access to BOX to run the whole script as a demo. This is helpful for me or people on our team. In this way, anyone can demo the script and provide improvements later. The end goal is that for all MTC team, they'll automatically use the paths in the mtc.py file which point directly to BOX. Additionally, it's a way to clearly state as a sample the shape in which we are expecting to receive the inputs.

Copy link
Member

Choose a reason for hiding this comment

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

It's trivial to give other folks access to Box; please request if you need others to have access. We generally keep data files on Box and not on GitHub, and I'd prefer to keep it that way; having it both ways adds confusion.

Copy link
Member

Choose a reason for hiding this comment

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

This folder (templates) has three files which makes you click around and the paths could just be done using an if statement without this kind of complexity. A simple if would make it clear what variables need to be defined for each environment and this structure is more error prone. Suggest deprecating this, and just inlining this logic somewhere else that's logical.

Also, please use pathlib for paths rather than strings with replace("\\","/"). pathlib handles forward versus backward slashes, etc and it is much more readable.

Copy link
Author

Choose a reason for hiding this comment

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

@lmz Thanks for the suggestion, I will keep them together instead in multiple locations and propose a new location for this logic.

Copy link
Member

Choose a reason for hiding this comment

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

Please rename this to be something more descriptive; suggest "OffModelCalculator" rather than "Calc". Also, please add documentation for the class variables and methods.

Copy link
Member

Choose a reason for hiding this comment

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

Also, let's just make the args that are passed into the constructor explicit, rather than hiding them in "args" -- there's only two...

Copy link
Author

Choose a reason for hiding this comment

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

@lmz sounds good. I've integrated this change in a new commit.

Copy link
Member

Choose a reason for hiding this comment

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

What does "mons" mean?

If these methods are for the Calc class, can they just be static methods of the class? Ditto for methods in runs.py

Copy link
Author

Choose a reason for hiding this comment

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

@lmz "mons" was a shorter name for commons. I will rename the file as commons.py. Here I want to add helper methods that are common between multiple calculators were transformations are needed.

I can definitely keep the methods in "commons" and "runs" in the same file. However, I wanted to have the OffModelCalculator class to include only the methods that are necessary in the high-level process. In this way, I can follow the update process in a more clear-cut way. Would that be okay with you?

Copy link
Member

Choose a reason for hiding this comment

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

The terminology is confusing here... what a "NewRun"? Internally, we think of model runs being Travel Model Runs, but we wouldn't be creating a new run here. Suggest some clarity -- if not in the method naming, through method documentation.

Copy link
Author

Choose a reason for hiding this comment

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

@lmz sounds good! I've added the method documentation.

Copy link
Member

Choose a reason for hiding this comment

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

Similarly -- what is this? I would think this should go on Box?

Copy link
Author

Choose a reason for hiding this comment

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

@lmz the IPA_TM2 folder saved in the inputs is the folder we received as an example of what the R script created (previous step). I am not touching this folder design because I'm not updating the R script. I'm only using it as the expected input sample folder.

Once we complete all the updates and run a demo, we can remove all the files that are unnecessary in the process, if applicable. My understanding is that we only need the files in IPA_TM2/ModelData. Ideally, we'd like the R script to reflect that.

Copy link
Member

Choose a reason for hiding this comment

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

What is this? Does it need to be excel? It makes it hard to see diffs, so if it could be a CSV instead, that would be preferrable.

Copy link
Author

Choose a reason for hiding this comment

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

@lmz this file was created with the intention that the Off Model Calculator manager could update the Calculators in the folder "models" and then, update the Variable_locations Excel file with the added/updated cell locations. We're using excel as a UI to make it easier to update. The end goal is for the manager to update the calculators and be able to run the script even when cells have changed location in the individual calculators.

Now, the Off Model Calculators latest version will be in the folder "models" to be used as the source of truth. Those files will keep a log of the runs that have been executed.

Copy link
Member

@lmz lmz Jul 19, 2024

Choose a reason for hiding this comment

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

Rather than commenting out a bunch of code, go ahead and just remove it, since it's still viewable in the git history...

Copy link
Author

Choose a reason for hiding this comment

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

@lmz absolutely! I am still in the process of converting the missing calculators, so I wanted to see each update process. Once I complete this step, I will delete all the commented code and keep it clean.

@caroarriaga
Copy link
Author

@lmz Thanks a lot for all the feedback. I will start working on this and respond/add new commits. I appreciate all the detailed responses.

@caroarriaga caroarriaga changed the title ICF Off-model calculator - Refactor 1, 2. Feature 1 ICF Off-model calculator - Refactor 1, 2, 3. Feature 1 Aug 6, 2024
@lmz lmz mentioned this pull request Sep 17, 2024
@lmz
Copy link
Member

lmz commented Sep 17, 2024

Hi @caroarriaga & @yuqiww -
I've created a new branch For ICF & MTC to collaborate on this work: https://github.com/BayAreaMetro/travel-model-one/tree/icfOffmodelExcelCalc

The branch is current master plus the commits from https://github.com/caroarriaga/travel-model-one/tree/icfOffmodelExcelCalc merged in.

You can see the diffs with master in this PR: #76

@yuqiww: It's cloned to X:\travel-model-one-icfOffmodelExcelCalc
@caroarriaga: I think you need to rebase your branch to this one, and then update this PR -- although I'm not sure if that's possible; you may need to close your PR and open a new one to merge into icfOffmodelExcelCalc

Let me know if you have issues!

@caroarriaga
Copy link
Author

Hi @lmz , I've sync'd the upstream repo and my forked version. I also went over the new branch you created to collaborate.
I tried to update this PR to the new icfOffmodelExcelCalc branch but is not possible. So, I will close it given the new icfOffmodelExcelCalc you created has all the commits now.

I will create another PR to the new branch you created (to push there instead of master). Let me know if you'd prefer I handle future collaboration differently.

@lmz
Copy link
Member

lmz commented Oct 16, 2024

Sounds good, @caroarriaga ! Thank you!

@lmz lmz closed this Oct 16, 2024
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.

4 participants