fix: Save in /build and use stating archmaester

This commit is contained in:
2025-06-25 16:07:55 +02:00
parent df9bdef3ed
commit d7c5e413d2
3 changed files with 47 additions and 44 deletions

1
.gitignore vendored
View File

@@ -26,3 +26,4 @@ NuGet.Config
.direnv/
result
result-*
.env

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2020 Serit Tromsø AS
Copyright (c) 2025 Oceanbox AS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -120,14 +120,26 @@ type PlumeJob =
timeIdx: int
}
let dirname = Path.GetDirectoryName("./build")
let createPlume (next: HttpFunc) (ctx: HttpContext) =
task {
let! plume = ctx.BindJsonAsync<PlumeJob>()
Log.Information $"Archmaester URL: %s{Archive.archmaester.url}"
Log.Information $"Archive GUID: %A{plume.aid}"
let name = Archive.readName plume.aid
Log.Information $"Archive %s{name}"
let outCsv = $"plume_%A{plume.aid}.csv"
let outNc = $"plume_%s{name}.nc"
Log.Information $"Archive Name: %s{name}"
let path = Archive.readPath plume.aid
Log.Information $"Archive path: %s{path}"
let projection = Archive.readCoordinateProjection plume.aid
Log.Information $"Coordinate projection: %s{Archive.archmaester.url}"
let fvgrid = Archive.readGrid plume.aid
// Grid stuff
@@ -172,9 +184,9 @@ let createPlume (next: HttpFunc) (ctx: HttpContext) =
let z0 =
// if timeArgs.Contains TimeArgs.Dob then
// let dob = timeArgs.GetResult(TimeArgs.Dob)
// -h + dob
-h + plume.depth
// else
-plume.depth
// -plume.depth
let U = plume.transport
let R0 = plume.radius
let theta0 = plume.theta
@@ -301,52 +313,42 @@ let createPlume (next: HttpFunc) (ctx: HttpContext) =
let r, z, d, _ = rz
$"{timestamp s.time}, {plume.pos.lon}, {plume.pos.lat}, {r}, {z}, {d}")
let dilution = calcDilutionAll solution
let out = dirname + outNc
IO.File.WriteAllLines(out, results)
let results =
solution
|> Array.mapi (fun i s ->
let Ta, Sa =
ambientWmass ambientarray[i].z ambientarray[i].temp ambientarray[i].salt z0
let rz = innlagring s dilution[i]
let r, z, d, _ = rz
$"{timestamp s.time}, {plume.pos.lon}, {plume.pos.lat}, {r}, {z}, {d}")
let file = "Plume.nc"
IO.File.WriteAllLines(file, results)
let datafile = "PlumeData"
Log.Information $"Write ambient data to {datafile}"
writeAmbientFile ambientarray datafile solution dilution
let plume_fname = datafile.Split('.')[0] + "_plume.nc"
writeFullPlume2NetCDF plume_fname solution dilution
let out = dirname + outCsv
writeAmbientFile ambientarray out solution dilution
writeFullPlume2NetCDF out solution dilution
|> ignore
return! Successful.OK plume next ctx
return! Successful.CREATED plume next ctx
}
/// Redirects to the swagger interface from the root of the site.
let swaggerRedirectHandler: HttpHandler = redirectTo true "swagger/index.html"
let healthCheck (next: HttpFunc) (ctx: HttpContext) =
task { return! Successful.OK "Healthy" next ctx }
let endpoints = [
route "/" swaggerRedirectHandler
POST [
route "/api/v1/plume" createPlume
|> configureEndpoint _.WithTags("Plume")
|> configureEndpoint _.WithSummary("Runs a PlumeJob")
|> configureEndpoint _.WithDescription("Will return the sim-results in the inbox.")
|> addOpenApi (
OpenApiConfig(
requestBody = RequestBody(typeof<PlumeJob>),
responseBodies = [| ResponseBody(typeof<PlumeJob>) |],
configureOperation =
(fun o ->
o.OperationId <- "PostPlume"
o)
)
)
]
]
/// Redirects to the swagger interface from the root of the site.
let swaggerRedirectHandler: HttpHandler =
redirectTo true "swagger/index.html"
let endpoints =
[ route "/healthz" healthCheck
route "/" swaggerRedirectHandler
POST
[ route "/api/v1/plume" createPlume
|> configureEndpoint _.WithTags("Plume")
|> configureEndpoint _.WithSummary("Runs a PlumeJob")
|> configureEndpoint _.WithDescription("Will return the sim-results in the inbox.")
|> addOpenApi (
OpenApiConfig(
requestBody = RequestBody(typeof<PlumeJob>),
responseBodies = [| ResponseBody(typeof<PlumeJob>) |],
configureOperation =
(fun o ->
o.OperationId <- "PostPlume"
o)
)
) ] ]
let configureSerilog level =
let n =