-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PI extraction calculation (#107)
* Add: new PI extraction calculation documentation and implementation in C# and Python * Fix: correct a typo in the README regarding language definition for new snippets * Add: enhance PI extraction calculation documentation and include it in the navigation * Fix: formatting for pi-extraction.cs * Chore: refactor pi-extraction.py --------- Co-authored-by: Steven Noorbergen <91969936+steven-noorbergen@users.noreply.github.com>
- Loading branch information
1 parent
251d757
commit d856895
Showing
6 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# PI | ||
|
||
## Extraction calculation | ||
To calculate the amount extracted from the ESI PI endpoint is more complex then just pulling from the ESI and using the values, snippets below walk through calculating each stage with its variations. | ||
<h3>Example</h3> | ||
|
||
--8<-- "snippets/formulae/pi-extraction.md" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
int[] CalculateExtractorValues() { | ||
|
||
//Inputs - these are set from the API results. | ||
//Note that all times are in seconds. | ||
int duration = 171000; //1d 23h 30m; from API expiryTime-installTime | ||
int cycleTime = 30 * 60; //30 minutes, value from API cycleTime * 60 | ||
int quantityPerCycle = 6965; | ||
|
||
//These constants are the defaults in dgmAttributeTypes. They may change. | ||
const float decayFactor = 0.012f; //Dogma attribute 1683 for this pin typeID | ||
const float noiseFactor = 0.8f; //Dogma attribute 1687 for this pin typeID | ||
|
||
int numIterations = duration / cycleTime; | ||
float barWidth = cycleTime / 900f; | ||
int[] values = new int[numIterations]; | ||
|
||
for (int i = 0; i < numIterations; i++) { | ||
float t = (i + 0.5f)*barWidth; | ||
float decayValue = quantityPerCycle/(1 + t * decayFactor); | ||
double phaseShift = Math.Pow(quantityPerCycle, 0.7f); | ||
|
||
double sinA = Math.Cos(phaseShift + t * (1/12f)); | ||
double sinB = Math.Cos(phaseShift / 2 + t * 0.2f); | ||
double sinC = Math.Cos(t * 0.5f); | ||
|
||
double sinStuff = Math.Max((sinA + sinB + sinC) / 3, 0); | ||
|
||
double barHeight = decayValue * (1 + noiseFactor * sinStuff); | ||
values[i] = (int) (barWidth * barHeight); | ||
} | ||
return values; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import math | ||
|
||
# These constants are the defaults in dgmAttributeTypes. They may change. | ||
decay_factor = 0.012 # Dogma attribute 1683 for this pin typeID | ||
noise_factor = 0.8 # Dogma attribute 1687 for this pin typeID | ||
|
||
def calculateExtractorValues(total_cycles = 30, cycle_time = 30 * 60, qty_per_cycle = 6965): | ||
""" | ||
:param int total_cycles: End time in seconds - start time in seconds / cycle_time | ||
:param int cycle_time: Cycle time, in seconds | ||
:returns Generator[int]: A generaotr that iterates over all values | ||
""" | ||
bar_width = float(cycle_time) / 900.0 | ||
|
||
for cycle in range(0, total_cycles): | ||
t = (cycle + 0.5) * bar_width | ||
decay_value = qty_per_cycle / (1 + t * decay_factor) | ||
phase_shift = pow(qty_per_cycle, 0.7) | ||
|
||
sin_a = math.cos(phase_shift + t * (1 / 12)) | ||
sin_b = math.cos(phase_shift / 2 + t * 0.2) | ||
sin_c = math.cos(t * 0.5) | ||
|
||
sin_stuff = max((sin_a + sin_b + sin_c) / 3, 0) | ||
|
||
bar_height = decay_value * (1 + noise_factor * sin_stuff) | ||
|
||
yield bar_width * bar_height |