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

Prevent hash / scalar manipulation #209

Open
ChHaeni opened this issue Oct 7, 2020 · 5 comments
Open

Prevent hash / scalar manipulation #209

ChHaeni opened this issue Oct 7, 2020 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@ChHaeni
Copy link
Collaborator

ChHaeni commented Oct 7, 2020

Add error vor hash operators (P+ etc) for use with scalars, e.g. following code added in File Application.nhd:

+should_fail
  print = check
  ++units  
    en = kg TAN/year
    de = kg TAN/Jahr
    fr = kg TAN/an
  ++formula
    scalar( Out(tan_into_application_solid) ) P-
    Out(nh3_napplication_solid) P-
    Out(n2_napplication_solid)  P-
    Out(no_napplication_solid)  P-
    Out(n2o_napplication_solid);
@zaucker
Copy link
Contributor

zaucker commented Oct 9, 2020

This as intentionally "allowed" to ease the conversion of the model .nhd files. The resulting hash will have an additional key "no filter" that contains the scalar value.
Once we are sure that all model .nhd files are adapted, we could add such a warning/failure.

@jnthn
Copy link
Collaborator

jnthn commented Oct 9, 2020

Indeed; scalar values are automatically upgraded to a filter group collection where the value is under the empty key. This was done to allow piecemeal transition of existing code to have a breakdown of the values. So effectively the final result consists of the same total, with a breakdown of some of the value, and the rest of it considered uncategorized. I'm not especially attached to that, but given it has well-defined semantics and doesn't hurt the final total it seemed like a useful relaxation.

Unlike when it was initially implemented, these days there is a way to tighten this up and still have the freedom in development: one can call filterGroup to explicitly construct a group when an empty key (passing {}). It's a lot more verbose, is all.

@ChHaeni
Copy link
Collaborator Author

ChHaeni commented Oct 12, 2020

So effectively the final result consists of the same total, with a breakdown of some of the value, and the rest of it considered uncategorized.

The Problem with that is, that printing the output of the hash is rather confusing, since the entry for the 'uncategorized' key is not showing up:

Application
    should_fail = 152.57097233606217 kg TAN/Jahr
      * Livestock::SmallRuminants::Excretion::animalcategory=milksheep            0 kg TAN/Jahr
      * Livestock::Poultry::Excretion::animalcategory=turkeys                     -4.04888129781 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=heifers_2nd_yr          -7.57477206244849 kg TAN/Jahr
      * Livestock::Poultry::Excretion::animalcategory=growers                     -0.356882431068 kg TAN/Jahr
      * Livestock::DairyCow::Excretion::animalcategory=dairy_cow                  -59.109790326174156 kg TAN/Jahr
      * Livestock::Poultry::Excretion::animalcategory=broilers                    -2.0822818103 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=fattening_calves        -28.64271810438 kg TAN/Jahr
      * Livestock::Equides::Excretion::animalcategory=horses_younger_than_3yr     -7.60664205 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=heifers_3rd_yr          -11.65059698347027 kg TAN/Jahr
      * Livestock::Equides::Excretion::animalcategory=ponies_and_asses            -2.8977684 kg TAN/Jahr
      * Livestock::SmallRuminants::Excretion::animalcategory=goats                -6.2895444 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=calves_suckling_cows    -13.484133557918055 kg TAN/Jahr
      * Livestock::Poultry::Excretion::animalcategory=layers                      -0.63445765523 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=suckling_cows           -60.500825212625137 kg TAN/Jahr
      * Livestock::Pig::Excretion::animalcategory=boars                           0 kg TAN/Jahr
      * Livestock::Pig::Excretion::animalcategory=weaned_piglets_up_to_25kg       0 kg TAN/Jahr
      * Livestock::SmallRuminants::Excretion::animalcategory=fattening_sheep      -11.099196 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=beef_cattle             -16.05502038358 kg TAN/Jahr
      * Livestock::Equides::Excretion::animalcategory=horses_older_than_3yr       -11.15640834 kg TAN/Jahr
      * Livestock::FatteningPigs::Excretion::animalcategory=fattening_pigs        -6.16710342387 kg TAN/Jahr
      * Livestock::Poultry::Excretion::animalcategory=other_poultry               0 kg TAN/Jahr
      * Livestock::Pig::Excretion::animalcategory=dry_sows                        -4.555164676504 kg TAN/Jahr
      * Livestock::Pig::Excretion::animalcategory=nursing_sows                    0 kg TAN/Jahr
      * Livestock::OtherCattle::Excretion::animalcategory=heifers_1st_yr          -4.4131049179812 kg TAN/Jahr

jnthn added a commit that referenced this issue Oct 12, 2020
Only done for the text output. In response to #209.
@jnthn
Copy link
Collaborator

jnthn commented Oct 12, 2020

@ChHaeni Ah yes, that's less than helpful. Submitted #216 to include it in the text output; @zaucker not sure if you want to look into how it handles it on the GUI.

@zaucker
Copy link
Contributor

zaucker commented Oct 12, 2020

@zaucker Extend GUI Formatter.

@zaucker zaucker self-assigned this Dec 29, 2020
@zaucker zaucker added the bug Something isn't working label Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants