moodle-qtype_formulas icon indicating copy to clipboard operation
moodle-qtype_formulas copied to clipboard

Update All SI Units

Open tkuschel opened this issue 2 years ago • 4 comments

I have been annoyed for a very long time that you can't just use all the units with the SI prefixes. For the electronics lectures at the university of applied sciences I asked students to use the scientific notation for the time being. Then I moved on to using conversion formulas. Long story short: I implemented a third choice at the "Unit Settings "+"Basic conversion rules" called "All SI units". With this setting, for any unit, the possibility to enter all SI prefixes is given. Example: Unit "µA" given. As a result from a question you have to enter e.g. "22 µA". Now, with this "All SI units" - setting, all these answers are correct:

  • 22 µA
  • 0.022 mA
  • 22e-6 A
  • 22000 pA
  • 22 uA

Additionally this functionality works with any unit e.g. kΩ, VA, kmol, mol, cd, ...

  • new feature: possiblity to enter µ (mu, and greek letter) in addition to u
  • new feature: conversion rules: add fullsiunit beside of commonsiunit and none.
  • removed: not used function get_unit_mapping(), and get_dimension_list()

tkuschel avatar Apr 06 '23 02:04 tkuschel

Thank you very much for this nice contribution. I will have a closer look at it soon. You chose a good time, because I am currently rewriting the whole parsing/evaluation engine and was thinking about ways to improve the unit stuff.

PhilippImhof avatar Apr 06 '23 08:04 PhilippImhof

If there are more then one Units given in the field "Unit" e.g. "mΩ = mohm = mm^2 kg s^-3 A^-2"

This did not work any more. Also I think the "mm^2 kg s^-3 A^-2" did not work in the past, that could be also implemented to use prefixes for such a unit. Several testcases at http://159.69.109.101/course/view.php?id=2``

It looks like that a refactoring of the whole prefix calculation would be fine. For instance the following feature would be great:

  • prefix handling with m^2 or m^3
  • very complex handling of this->mapping and additonal_rules; could be more flexible and easier data structures

I updated my solution, still room for improvements...

Thomas

tkuschel avatar Apr 06 '23 20:04 tkuschel

Thanks! The whole unit thing suffers from a huge lack of unit and, to a lesser extent, acceptance testing. I think now is a good moment to add some tests. Don't worry, I will try to find some time to write them :)

I also agree with your remarks about prefix calculation. That code is very old and comes with some limitations, especially w.r.t. maintainability. My ultimate goal is to rewrite that part, but that can only be done once the new parsing/evaluation engine is ready.

PhilippImhof avatar Apr 07 '23 07:04 PhilippImhof

I have added a very basic test for the "common SI unit" conversion rules and took the liberty to merge this into your PR. We will be able to extend that test for the stuff you added.

PhilippImhof avatar Apr 12 '23 12:04 PhilippImhof