Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Nov 14, 2023
1 parent c6d7145 commit 7667c06
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions backend/src/backend/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from typing import List, Union, Optional

import asyncio
from fastapi import APIRouter, Depends, HTTPException, Query, Response

from src.services.sumo_access.surface_access import SurfaceAccess
Expand Down Expand Up @@ -184,6 +184,23 @@ async def get_realization_surface_data_as_png(
return surf_data_response


class AsyncRange:
def __init__(self, start, end):
self.current = start
self.end = end

def __aiter__(self):
return self

async def __anext__(self):
if self.current < self.end:
number = self.current
self.current += 1
return number
else:
raise StopAsyncIteration


@router.get("/statistical_surface_data_as_png/")
async def get_statistical_surface_data_as_png(
response: Response,
Expand All @@ -210,13 +227,21 @@ async def get_statistical_surface_data_as_png(
)
if service_stat_func_to_compute is None:
raise HTTPException(status_code=404, detail="Invalid statistic requested")

xtgeo_surf = await access.get_statistical_surface_data_async(
statistic_function=service_stat_func_to_compute,
name=name,
attribute=attribute,
time_or_interval_str=time_or_interval,
)
xtg_arr = []
print("before loop", flush=True)
for i in range(0, 100):
print(i, flush=True)
xtg_arr.append(
access.get_statistical_surface_data_async(
statistic_function=service_stat_func_to_compute,
name=name,
attribute=attribute,
time_or_interval_str=time_or_interval,
)
)
print("before await", flush=True)
await asyncio.gather(*xtg_arr)
print("after await", flush=True)
perf_metrics.record_lap("sumo-calc")

if not xtgeo_surf:
Expand Down

0 comments on commit 7667c06

Please sign in to comment.