MadsKirkFoged / EngineeringUnits

Working with units made easy with automatic unit-check and converting between units
MIT License
41 stars 10 forks source link

Adding Cost/Currency/Price #39

Open MadsKirkFoged opened 8 months ago

MadsKirkFoged commented 8 months ago

Creating a Issue based in @mschmitz2's excellent suggestion in #19 to add cost. It has been on my list for some time now so lets give it a go!

I have added following (still subject to change..)

Cost f1 = new Cost(10, CostUnit.USDollar); //10 $
Energy e1 = new Energy(10, EnergyUnit.KilowattHour); //10 kWh

EnergyCost test = f1 / e1; //1 $/kWh

Any other name we should consider for the unit representing $£€? Price Cost Currency

Name when combining it with other units: EnergyCost CostOfEnergy EnergySpecificCost EnergyPrice

What do you guys think?

Also, we need to figure out how to convert between the different Currencies.

mschmitz2 commented 8 months ago

Any other name we should consider for the unit representing $£€? Price Cost Currency

Personally, I think Cost is enough, but maybe there are applications where people might prefer one of the other so adding an alias might be OK.

We should just keep in mind that, unlike with aliases of combined units, having an alias for a base unit might add either

Name when combining it with other units: EnergyCost CostOfEnergy EnergySpecificCost EnergyPrice

I think I chose EnergySpecificCost because we already have units like SpecificEnergy etc. but I don't necessarily think it's the best.

I do like your suggestion of EnergyCost, mostly because it's the shortest. I also like CostOfEnergy as it would nicely group all "CostOf" units together in alphabetic order.

Also, we need to figure out how to convert between the different Currencies.

  1. Have a hardcoded conversion that will (automatic) be updated with each build.
  2. Have a way you can override the hardcoded conversions with your own
  3. an option to Connect to a public Currency exchange API that will give you the current currencies

This is probably the trickiest point.

MadsKirkFoged commented 8 months ago

I also like Cost and EnergyCost even thought some of the unit might end up sounding a bit funny; LengthCost, VolumeCost, AreaCost. But I think most people will understand the intent. I agree with not creating aliases for this, it will mean making too many new units. I think will create option 1 and 2. This way uses that just want ballpark currency conversions can use the build-in rates while others can input their own

MadsKirkFoged commented 8 months ago

@mschmitz2 I have added all the Cost units that you were using.

Feel free to make a pull request where you add more unit quantities: image

mschmitz2 commented 8 months ago

Thanks. I added a few units quantities and also fixed an issue where the namespace of the new units (*Enum.cs files) was EngineeringUnits instead of EngineeringUnits.Units like in the older units. This resulted in the getters and setters not being generated for the new classes.

I wanted to open a pull request for this but I'm having trouble publishing my branch... image

I am assuming the issue is on my side, but just in case, could you check if there might be any repo setting preventing me from doing this? Thanks

MadsKirkFoged commented 7 months ago

I think you need to:

  1. fork a new version.
  2. Clone that version to visual studio
  3. Create the changes
  4. Push to your forked version which you have access to.
  5. Go to github.com -> your fork -> Create pull request

Then I can accept your pull request if im happy with it ;-D

mschmitz2 commented 7 months ago

Oh I see.. I was attempting this without forking (cloned, made my own branch, then tried to push that, which I don't have permission to do). With forking this works fine, as you can see in the pull request above