Skip to content

Commit

Permalink
Merge pull request #5 from brewerwall/feature/calculate
Browse files Browse the repository at this point in the history
Feature/calculate
  • Loading branch information
griffithben authored Sep 8, 2023
2 parents faca0cb + 67c0c40 commit c06a5af
Show file tree
Hide file tree
Showing 16 changed files with 1,012 additions and 205 deletions.
241 changes: 239 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![example workflow](https://github.com/brewerwall/unitz/actions/workflows/main.yml/badge.svg)

### Introduction
## Introduction

Unitz is a way to address easy conversions among various brewing/fermentation units. A utility
that helps convert a unit to all types and agnostic to what type of unit it is.
Expand Down Expand Up @@ -142,4 +142,241 @@ method that all units share.
$weight = new Weight(kilogram: 7.5629145);

$kilogram = $weight->getKilogram(3); // $kilogram = 7.563
```
```

## Calculate

A library of calculations that can be used with various Unitz classes.

### Beer

This class will calculate Beer related calculations.
___

#### Alcohol By Volume (ABV)

Alcohol By Volume (ABV) is the percent of alcohol content in the beer based on the original gravity, final gravity and
formula version. Source of equation is
at [Brewer's Friend](https://www.brewersfriend.com/2011/06/16/alcohol-by-volume-calculator-updated/).

```php
Beer::alcoholByVolume(Gravity $originalGravity, Gravity $finalGravity, string $formulaVersion = Beer::ABV_ALTERNATE_FORMULA): float
```

##### Arguments

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer
- `string $formulaVersion` - Formula ABV calculation: `Beer::ABV_STANDARD_FORMULA`
or `Beer::ABV_ALTERNATE_FORMULA`

##### Returns

- `float` - Alcohol By Volume (ABV) Value

---

#### Alcohol By Weight (ABW)

Alcohol By Weight (ABW) is weighing the amount of alcohol in a fixed volume of liquid and comparing it to the weight of
pure water based on the original gravity and final gravity.

```php
Beer::alcoholByWeight(Gravity $originalGravity, Gravity $finalGravity): float
```

##### Arguments

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer

##### Returns

- `float` - Alcohol By Weight (ABW) Value

---

#### Standard Reference Method (SRM)

Standard Reference Method (Srm) is the method for color assessment of wort or beer as published in the recommended
methods of the American Society of Brewing Chemists

```php
Beer::standardReferenceMethod(Weight $weight, Color $color, Volume $volume): Color
```

##### Arguments

- `Weight $weight` - Weight of the grain
- `Color $color` - Color of the grain
- `Volume $volume` - Volume of the water

##### Returns

- `Unitz/Color` - Color (Color) Value

---

#### Malt Color Unit (MCU)

Malt Color Unit (MCU) is an equation that helps determine what color a beer would be.

```php
Beer::maltColorUnit(Weight $weight, Color $color, Volume $volume): float
```

##### Arguments

- `Weight $weight` - Weight of the grain
- `Color $color` - Color of the grain
- `Volume $volume` - Volume of the water

##### Returns

- `float` - Malt Color Unit (MCU) Value

---

#### International Bitterness Units (IBU)

International Bitterness Units (IBU) is the bitterness of the beer based on the alpha acid of the
hops, weight of the hops, time in the boil, gravity of the wort, and volume of the wort.

Based off Palmer's Calculation

```php
Beer::internationalBitternessUnits(float $alphaAcid, Weight $weight, Time $time, Gravity $gravity, Volume $volume)
```

##### Arguments

- `float $alphaAcid` - Alpha Acid of the hops
- `Weight $weight` - Weight of the hops
- `Time $time` - Time in the boil
- `Gravity $gravity` - Gravity of the wort
- `Volume $volume` - Volume of the wort

##### Returns

- `float` - International Bitterness Units (IBU) Value

---

#### Alpha Acid Units (AAU)

Alpha Acid Units (AAU) is the potential bitterness of the hops based on the alpha acid and weight.

```php
Beer::alphaAcidUnit(float $alphaAcid, Weight $weight): float
```

##### Arguments

- `float $alphaAcid` - Alpha Acid of the hops
- `Weight $weight` - Weight of the hops

##### Returns

- `float` - Alpha Acid Units (AAU) Value

---

#### Hop Utilization

This is a hop utilization factor based on the Tinseth formula derived
by [Glenn Tinseth](https://beersmith.com/blog/2011/02/10/beer-bitterness-and-ibus-with-glenn-tinseth-bshb-podcast-9/]).

```php
Beer::hopUtilization(Time $time, Gravity $gravity)
```

##### Arguments

- `Time $time` - Time in the boil
- `Gravity $gravity` - Gravity of the wort

##### Returns

- `float` - Hop Utilization Value

---

#### Calories

Determines the number of calories in a finished beer based on the original gravity, final gravity and the volume of the
beer consumed.

```php
Beer::calories(Gravity $originalGravity, Gravity $finalGravity, Volume $volume)
```

##### Arguments

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer
- `Volume $volume` - Volume of the beer consumed

##### Returns

- `float` - Calories

---

#### Real Extract

Real Extract (RE) is a precise calculation concerning the gravity of beer.
Source of equation is [Craft Beer & Brewing](https://beerandbrewing.com/dictionary/ewOeMFnY4x/)

```php
Beer::realExtract(Gravity $originalGravity, Gravity $finalGravity)
```

##### Arguments

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer

##### Returns

- `float` - Real Extract

---

#### Apparent Degree of Fermentation

Apparent Degree of Fermentation (ADF) is a measure of the amount of sugar that has been converted to alcohol and carbon
dioxide by yeast during fermentation

```php
Beer::apparentDegreeOfFermentation(Gravity $originalGravity, Gravity $finalGravity)
```

##### Arguments

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer

##### Returns

- `float` - Apparent Degree of Fermentation

---

#### Gravity Correction

Gravity Correction based on Temperature of Sample and Hydrometer Calibration.
Source [Brewers Friend](https://www.brewersfriend.com/hydrometer-temp/)

```php
Beer::gravityCorrection(Gravity $gravity, Temperature $temperature, Temperature $calibrationTemperature)
```

##### Arguments

- `Gravity $gravity` - Gravity of the Sample
- `Temperature $temperature` - Temperature of the sample
- `Temperature $calibrationTemperature` - Temperature hydrometer is calibrated to

##### Returns

- `Gravity` - Corrected Gravity of Sample
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": "^8.0"
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^10.2"
Expand Down
Loading

0 comments on commit c06a5af

Please sign in to comment.