Skip to content

Commit

Permalink
Add calculation time metric to PointSamplingResponse in surface query…
Browse files Browse the repository at this point in the history
… service
  • Loading branch information
sigurdp committed Nov 22, 2024
1 parent e75a0ed commit f60972d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend_go/surface_query/handlers/handle_sample_in_points.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ type RealizationSampleResult struct {
}

type PointSamplingResponse struct {
SampleResultArr []RealizationSampleResult `json:"sampleResultArr" binding:"required"`
UndefLimit float32 `json:"undefLimit" binding:"required"`
SampleResultArr []RealizationSampleResult `json:"sampleResultArr" binding:"required"`
UndefLimit float32 `json:"undefLimit" binding:"required"`
CalculationTime_ms int `json:"calculationTime_ms" binding:"required"`
}

func HandleSampleInPoints(c *gin.Context) {
Expand Down Expand Up @@ -66,14 +67,16 @@ func HandleSampleInPoints(c *gin.Context) {
// TO-DISCUSS:
// Must check this out in relation to the xtgeo code
// Undef value and limit seem to be misaligned!!!
duration_ms := (time.Now().Sub(startTime)) / time.Millisecond
retResultArr := make([]RealizationSampleResult, len(perRealSamplesArr))
for i := range retResultArr {
retResultArr[i] = RealizationSampleResult(perRealSamplesArr[i])
}

responseBody := PointSamplingResponse{
SampleResultArr: retResultArr,
UndefLimit: 0.99e30,
SampleResultArr: retResultArr,
UndefLimit: 0.99e30,
CalculationTime_ms: int(duration_ms),
}
c.JSON(http.StatusOK, responseBody)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _PointSamplingRequestBody(BaseModel):
class _PointSamplingResponseBody(BaseModel):
sampleResultArr: List[RealizationSampleResult]
undefLimit: float
calculationTime_ms: int


# URL of the Go server endpoint
Expand Down Expand Up @@ -96,6 +97,9 @@ async def batch_sample_surface_in_points_async(
json_data: bytes = response.content
response_body = _PointSamplingResponseBody.model_validate_json(json_data)

perf_metrics.set_metric("inner-go-call", response_body.calculationTime_ms)


# Replace values above the undefLimit with np.nan
for res in response_body.sampleResultArr:
values_np = np.asarray(res.sampledValues)
Expand Down

0 comments on commit f60972d

Please sign in to comment.