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

Refactor everything #42

Closed
okitec opened this issue Dec 23, 2017 · 10 comments
Closed

Refactor everything #42

okitec opened this issue Dec 23, 2017 · 10 comments

Comments

@okitec
Copy link
Contributor

okitec commented Dec 23, 2017

Name Definition
Recipe Array of Ingredients
Recipe.mass() Sum of the alcohol masses of the ingredients
Ingredient (name, alcohol content, quantity [ml])
Ingredient.mass() Returns the mass A [gram] of the alcohol as defined by A = quantity [ml] * alcohol content * density of alcohol (0.8 g/ml).
Drink A consumed Recipe with the constructor new Drink(Recipe r);
Drink (name, recipe, consumption time, remaining factor)
Drink.mass() Returns the remaining unprocessed mass of the drink's alcohol after exponential decline: remaining mass = remaining factor * recipe.mass().
Drink.dec() Decreases the remaining factor by the average decline rate 0.00015 and returns the new remaining factor. This is the only call that modifies anything. Call it once every hour for the first drink in every User's list. If the result is <= 0, remove the drink; also, if it is < 0, call dec(abs(result)) for the next drink in the list, and so on. This way, all of the processing capacity of the liver is accounted for. Else, we'd remove only one drink where we should remove more.
User (name, sex, age, height, mass, drinks)
User.waterQuantity() (private) Returns the total volume of the water in the body (GKW on Wikipedia (BAK/Watson-Formel)).
User.reductionFactor() Returns the percentage of the body reached by the alcohol as defined by r = blood density (1.055g/ml) * waterQuantity() / 0.8 * mass.
User.alcoholMass() Returns the mass of the remaining alcohol in the blood defined as the sum of drink[i].mass().
User.bac() Returns the BAC of the user as defined by Widmark: bac = alcoholMass() / mass * reductionFactor().
@dieechtenilente
Copy link
Collaborator

Recipe, Ingredient added with 4e87491

@dieechtenilente dieechtenilente added this to the Working version milestone Dec 26, 2017
@dieechtenilente
Copy link
Collaborator

-> #40, #41

@okitec
Copy link
Contributor Author

okitec commented Dec 26, 2017

Maximum nitpick mode engaged, I hope you don't mind me criticising every little bit. I only care for code quality. Make it the best app (die BWESTE)!

@dieechtenilente
Copy link
Collaborator

It's okay. THIS WILL BE THE BEST APP!!!!11 SCHAUNS HER!

@okitec
Copy link
Contributor Author

okitec commented Dec 27, 2017

I'm concerned the remaining factor/dec logic might be wrong. Each tick, we want to decrement the first drink's alcohol mass by 0.00015 times the total alcohol mass, not times the first alcohol mass only. But we use the remaining factor here, so I don't know if it is what we want. Maths!

@dieechtenilente
Copy link
Collaborator

dieechtenilente commented Dec 27, 2017

I think, my original logic is correct. Say you drank a drink (lol) at a time point A and it has alcohol mass M in it, so you use M * 3600000 to deplete ~0,1 ‰ per hour [like in line 236: expireTime = takingTime + Math.round(bac * 36000000)]. where bac is from this methode:

public static double getBac(Mixture mixture, User user) {
  if (user.isMale()) {
    double R = 2.447 - 0.09516 * user.getAge() + 0.1074 * user.getHeight() + 0.3362 * user.getWeight();
  } else {
    double R = -2.097 + 0.1069 * user.getHeight() + 0.2466 * user.getWeight();
  }

  r = (1.055 * R) / (0.8 * user.getWeight());
  return (mixture.getAmount() * mixture.getPercentage() * 0.8) / (user.getWeight() * r);
}

So you need only a factor so you can get the remaining alcohol mass from this drink at a given point in time.

@okitec
Copy link
Contributor Author

okitec commented Dec 27, 2017

Why would the mass decrease when you multiply it with a huge value?

My logic would be fine if we stored a remaining alcohol mass in Drink, instead of a remainingFactor. I suggest we use the new system and revert if it turns out to be wrong.

@dieechtenilente
Copy link
Collaborator

Why store something in the drink anyway? We have a taking time and the alc-mass. Everything could be calculated on the fly.

@okitec
Copy link
Contributor Author

okitec commented Dec 27, 2017

You drink a drink with 50mg alcohol at time 0h.
You drink a drink with 20mg alcohol at time 1h.
How much grams of alcohol are there at time 2h?

Well, you are probably right, since there's the distributive law, I derped the night I wrote the proposal.

reduced alc mass at time t [hours] = t * 0.00015 * total alc mass
    = t * 0.00015 * alc mass 1 + t * 0.00015 * alc mass 2 + ...

For this to work, we need to set a time epoch t = 0. We mustn't consider any taking times except the one of the first drink. That's probably why I thought this wouldn't work.

@dieechtenilente
Copy link
Collaborator

Pretty much closed/done with #43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants