cannawen / metric_units_reddit_bot

Reddit bot converting imperial units to metric units
https://www.reddit.com/user/metric_units
GNU General Public License v3.0
78 stars 34 forks source link

Bushel conversion should depend on keyword. #53

Closed cannawen closed 6 years ago

cannawen commented 6 years ago

metric_units is a sassy reddit bot that finds imperial units, and replies with a metric conversion.

Current behaviour: The bot converts bushels to ~32 lbs Enhancement request: The unit "bushel" should change depending on the commodity.

metric_units bot should search for keywords to figure out what kind of bushel it is translating, based on this link For example:

See this file to get started. Hint: it may help to have a "preprocess" step that searches for the unit "bushel" and replaces it with "bushel60" or "bushel32" depending on what kind of bushel it is.

Recommended skills: Javascript & regular expressions Estimated time: 1-2 hours

Comment below if you would like to take on this task!

MFogleman commented 6 years ago

I created this beast.

The problem with the 'Bushel' is that it is completely not defined. A bushel of oats is a different weight than a bushel of wheat. The weight of a bushel of wheat is also going to vary depending on where you are. I found This site, which has some state standards that recognize some federal standards.

You also have to consider that the bushels weight assumes a specific moisture and other states of the product in certain products.

From https://www.thebalance.com/how-much-is-a-bushel-1389308

A bushel of tomatoes, for example, is supposed to weigh 56 pounds, as is a bushel of shelled corn. But if the corn is still in ears, a bushel is supposed to weigh a whopping 70 pounds. Leaves and greens take up more space with less weight, so a bushel of spinach need only be 20 pounds.

So you are looking at close to 100 usage cases for a bushel. This list would still be inaccurate in certain scenarios due to variances of the definition of a bushel of that product, and also not inclusive of all use cases.

Other options include

a measure of capacity equal to 64 US pints (equivalent to 35.2 liters), used for dry goods. and convert it to kilograms. Or pick a common agricultural bushel, and add a disclaimer (maybe links to other bushel definitions).

I think no matter what, a disclaimer of how vague a 'bushel' is, should probably be included.

cannawen commented 6 years ago

Yeah... I didn't realize how many kinds of bushels there were until all the farmers were upset in my reddit feedback thread, haha! I asked them if a volumetric conversion would be better, and they said no.

I feel like some simple keyword matching would help a lot, like if a post said "1 bushel of tomatoes" then we would use tomato-bushels.

Code-wise it might not be so bad if we made a object like

[
  {
    regex: /tomato(?:es)?/,
    lbs: 56
  },
  {
    regex: /spinach/,
    lbs: 20
  },
  {
    regex: function(inputString) {
      return inputString.match("ear") && inputString.match("corn");
    },
    lbs: 70
  }
  ...
]

But yes, it might be a fair bit of work to take into account ALL the bushel types... hmm. Maybe we can just start with a few, and then expand our bushel-recognition slowly? Is this a task you would like to continue, or are you sick of dealing with bushels? :o)

MFogleman commented 6 years ago

I'd like to give it a shot, but don't know how much time I'll have to devote to it. If anyone else wants to as well (It is hacktoberfest), I won't be offended. I think there is enough work and edge cases to keep multiple contributors busy.

cannawen commented 6 years ago

@MFogleman Maybe you can do 2-3 bushel numbers to get the ball rolling, and I can make issues afterwards for other people to add more bushel types? If you get too busy just give me a shout here and I can try to find someone else to do it. Thank you!! :)

cannawen commented 6 years ago

Hey @MFogleman, we have just added a CONTRIBUTING.md doc, please check it out when you have time! Sections "Etiquette", "Work on an issue" and "Make a PR" are most important

cannawen commented 6 years ago

I'm going to temporarily remove bushels from all conversions to solve this issue for now, an issue can be opened later on to fix it "properly," taking into account keywords :)