Skip to content

Commit

Permalink
Chore: refactor pi-extraction.py
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-noorbergen authored Jan 25, 2025
1 parent 6e5ce41 commit ddc61b5
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions snippets/formulae/pi-extraction.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
import math

# Inputs - these are set from the API results.
# Note that all times are in seconds.
planet_dict = {}
planet_dict["total_cycles"] = (
30 # End time in seconds - start time in seconds / cycle time
)
planet_dict["cycle_time"] = 30 * 60 # 30 minutes, value from API cycleTime * 60
planet_dict["qty_per_cycle"] = 6965

# These constants are the defaults in dgmAttributeTypes. They may change.
decay_factor = 0.012 # Dogma attribute 1683 for this pin typeID
noiseFactor = 0.8 # Dogma attribute 1687 for this pin typeID

# Populated by data from the PI ESI Endpoint

cycle_time = planet_dict["cycle_time"]
planet_dict["total_qty"] = 0
quantityPerCycle = planet_dict["qty_per_cycle"]
barWidth = cycle_time / 900
total_cycles = planet_dict["total_cycles"]
for cycle in range(0, int(total_cycles)):
t = (cycle + 0.5) * barWidth
decay_value = quantityPerCycle / (1 + t * decay_factor)
phaseShift = pow(quantityPerCycle, 0.7)

sinA = math.cos(phaseShift + t * (1 / 12))
sinB = math.cos(phaseShift / 2 + t * 0.2)
sinC = math.cos(t * 0.5)

sinStuff = (sinA + sinB + sinC) / 3
sinStuff = max(sinStuff, 0)

barHeight = decay_value * (1 + noiseFactor * sinStuff)

planet_dict["total_qty"] += barWidth * barHeight

planet_dict["average_qty"] = planet_dict["total_qty"] / planet_dict["total_cycles"]
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

0 comments on commit ddc61b5

Please sign in to comment.