fix large response handler

main
Cizz22 4 months ago
parent 5a51ac99bf
commit 3ca41d4a47

@ -12,7 +12,6 @@ class AerosSimulation(Base, DefaultMixin):
started_at = Column(DateTime, nullable=True)
completed_at = Column(DateTime, nullable=True)
input = Column(JSON, nullable=True)
result = Column(JSON, nullable=True)
error = Column(JSON, nullable=True)
simulation_name = Column(String, nullable=False)
schematic_name = Column(String, nullable=False)

@ -1,10 +1,12 @@
import json
def calculate_eaf(
available_hours: float,
period_hours: float,
actual_production: float,
ideal_production: float,
downtime_hours,
plot_data
):
"""
Calculate EAF using the time-based method from PLN document
@ -24,7 +26,7 @@ def calculate_eaf(
try:
# Calculate lost production
lost_production = ideal_production - actual_production
max_capacity = plot_data.max_flow_rate
max_capacity = 660
# Calculate total equivalent derate and outage hours
total_equivalent_derate_and_outage_hours = lost_production / max_capacity if max_capacity > 0 else 0
total_equivalent_derate = total_equivalent_derate_and_outage_hours - downtime_hours
@ -87,3 +89,43 @@ def calculate_derating(data_list, max_flow_rate: float = 660) -> float:
print(f"Derating hours: {time_interval:.2f}")
return total_time_below_max
def stream_large_array(filepath, key):
with open(filepath, "r") as f:
buffer = ""
depth = 0
inside_string = False
in_target_array = False
while True:
chunk = f.read(8192)
if not chunk:
break
for char in chunk:
buffer += char
if not in_target_array and f'"{key}": [' in buffer:
in_target_array = True
buffer = ""
continue
if in_target_array:
if char == '"' and (len(buffer) < 2 or buffer[-2] != '\\'):
inside_string = not inside_string
if not inside_string:
if char == '{':
depth += 1
elif char == '}':
depth -= 1
if depth == 0:
try:
obj = json.loads(buffer)
yield obj
except Exception:
pass
buffer = ""
if char == ']' and depth == 0:
return
Loading…
Cancel
Save