-
-
Notifications
You must be signed in to change notification settings - Fork 76
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 Units at Runtime #268
Add Units at Runtime #268
Conversation
The problem that I see with this, and the reason I never did something like it myself, is that the Units namespace is global to the httpd child process, so any chanced you make to it will be persistent to other problems that are processed by the same child. That means that, after your problem is processed, other problems that use units will have In order to make this work properly, you need to add the units locally to the problem, so they are part of the safe compartment, and will disappear between problems. The current organization of the Units package doesn't make the easy to do. It has been a while since I tested the details of how the packages work, and I didn't test this change specifically, so perhaps things have changed since then. But last time I looked, this would have caused leakage of problem-secific changes to other problems. |
Hmm. You are right, there is leakage to other problems. You need to be able to override the |
Ok, sounds like a plan. |
Ok, so I added code in the Things to test
This should work even under the following conditions:
In particular this should work with a first answer of
The answers are all the same as the ones for the
|
if ($known_units) { | ||
$options->{known_units} = $known_units; | ||
} | ||
my %Units = Units::evaluate_units($units,{fundamental_units => $fundamental_units, known_units => $known_units}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this want to use $options
rather than the explicit hash. It looks like you are setting up $options
for that, but never use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I was adding and removing stuff for testing purposes and likely added the wrong thing back in.
Just FYI, to check for leakage, you probably need to run the second problem several times, since you have to make sure it runs in the same child process as the original problem. Since the children are parceled out in various orders, you probably won't get the same child for the second problem on your first try. I'm sure you know that, but just in case anyone else it doing testing. I haven't had a chance to run tests by hand yet, but just looked through the code by hand. It looks good. I'll see if I can get some time this weekend to give it a try. |
@@ -0,0 +1,60 @@ | |||
#!/usr/bin/perl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to add these ~
files?
Good point. I've made the suggested changes. |
I've cleaned up the unit tests so they work. You can try them out by also checking out the Automated Testing branch (openwebwork/webwork2#681) and getting Selenium set up. Then you can just run
Again this is a bit of a proof of concept to see if these tests are useful. The basic idea is that you can keep a pg file in the testing folder and use the existing utilities to easy make a problem to test. Then you would use the Selenium IDE to generate some tests on the rendered version of the problem. In theory having these tests, and providing them with pull requests will speed things up, but it depends on if people use them and if they are robust enough. |
I've verified that there is no leakage in this code but I have some suggestions before
This is the test code I put in problems to determine which new units were defined:
Change the formula file in the same way. Comments? |
If you make a pull request against my feature branch I will merge it. Cheers
|
…nits or FormulaWithUnits. Simplify the way NumberWithUnits is called -- I don't believe the eval() is necessary. Add accessor so the current value of units can be determined.
OK. That’s done. (It took three tries to submit a clean PR. :-) ) Take care, Mike
|
Create ability to add new units to problem before calling NumberWithU…
This pull requests modifies
NumberWithUnits
so that you can add units at runtime. You can see the documentation in the header portion ofparserNumberWithUnits
(see file changes). The short version is you can add new units, along with conversion info, at runtime.Davide, since I'm mucking about in MathObjects, let me know if I've stepped on anything I shouldn't have or if there is something I should do to improve things. You can use the following problem to test: