///<inheritdoc cref="ITemperatureRepo.AddTemperatureAsync(InputTemperature)"/> public async Task <Temperature> AddTemperatureAsync(InputTemperature inputTemperature) { await using var dbConnection = await CreateOpenConnectionAsync().ConfigureAwait(false); var temperature = new Temperature(inputTemperature); temperature.created_date = temperature.last_updated_date = TruncateTo6DigitFractional(DateTime.UtcNow); await dbConnection.InsertAsync(temperature).ConfigureAwait(false); return(temperature); }
public async Task <IActionResult> PutByJson([BindRequired] InputTemperature inputTemperature) { try { return(await PutAsync(inputTemperature).ConfigureAwait(false)); } catch (Exception e) { log.LogError(e, $"Exception caught in {nameof(PutByJson)}"); return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError)); } }
private async Task <IActionResult> PutAsync(InputTemperature inputTemperature) { try { var temperature = await temperatureRepo.UpdateTemperatureAsync(inputTemperature).ConfigureAwait(false); return(Ok(temperature)); } catch (KeyNotFoundException) { return(await PostAsync(inputTemperature).ConfigureAwait(false)); } }
private async Task <IActionResult> PostAsync(InputTemperature inputTemperature) { try { var newTemperature = await temperatureRepo.AddTemperatureAsync(inputTemperature).ConfigureAwait(false); return(CreatedAtAction(nameof(GetById), new { newTemperature.id }, newTemperature)); } catch (MySqlException e) when(e.Number == 1062) { return(Problem($"An existing record with the id '{inputTemperature.id}' was already found.", statusCode: StatusCodes.Status409Conflict)); } }
///<inheritdoc cref="ITemperatureRepo.UpdateTemperatureAsync(InputTemperature)"/> public async Task <Temperature> UpdateTemperatureAsync(InputTemperature inputTemperature) { await using var dbConnection = await CreateOpenConnectionAsync().ConfigureAwait(false); var temperature = await GetTemperatureAsync(dbConnection, inputTemperature.id).ConfigureAwait(false); temperature.value = inputTemperature.value; temperature.unit = inputTemperature.unit; temperature.last_updated_date = TruncateTo6DigitFractional(DateTime.UtcNow); await dbConnection.UpdateAsync(temperature).ConfigureAwait(false); return(temperature); }
private void Configurate() { numberOfTimesteps = (int)(SimulationEndTime.ToOADate() - SimulationStartTime.ToOADate() - 0.5); precipitation = new TimestampSeries("Precipitation", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); potentialEvaporation = new TimestampSeries("PotentialEvaportion", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); temperature = new TimestampSeries("Temperature", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.Centigrade); int numberOfObservedRunoffValues = 0; if (inputObservedRunoff is TimespanSeries) { numberOfObservedRunoffValues = ((TimespanSeries)inputObservedRunoff).Items.Count; } else if (inputObservedRunoff is TimestampSeries) { numberOfObservedRunoffValues = ((TimestampSeries)inputObservedRunoff).Items.Count; } else { throw new Exception("Unexpected exception"); } observedSpecificRunoff = new TimestampSeries("Observed specific runoff", simulationStartTime, numberOfObservedRunoffValues, 1, TimestepUnit.Days, 0, Units.MmPrDay); observedRunoff = new TimestampSeries("Observed Runoff", simulationStartTime, numberOfObservedRunoffValues, 1, TimestepUnit.Days, 0, Units.M3PrSec); for (int i = 0; i < numberOfTimesteps; i++) { DateTime fromTime = SimulationStartTime.AddDays(i); DateTime toTime = SimulationStartTime.AddDays(i + 1); precipitation.Items[i].Value = InputPrecipitation.GetValue(fromTime, toTime, precipitation.Unit); potentialEvaporation.Items[i].Value = InputPotentialEvaporation.GetValue(fromTime, toTime, potentialEvaporation.Unit); temperature.Items[i].Value = InputTemperature.GetValue(fromTime, toTime, temperature.Unit); } for (int i = 0; i < numberOfObservedRunoffValues; i++) { DateTime fromTime = SimulationStartTime.AddDays(i); DateTime toTime = SimulationStartTime.AddDays(i + 1); observedSpecificRunoff.Items[i].Value = InputObservedRunoff.GetValue(fromTime, toTime, observedSpecificRunoff.Unit) * (1000.0 * 3600 * 24 / CatchmentArea); observedRunoff.Items[i].Value = InputObservedRunoff.GetValue(fromTime, toTime, observedRunoff.Unit); } surfaceEvaporation = new TimestampSeries("SurfaceEvaporation", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); rootZoneEvaporation = new TimestampSeries("RootZoneEvaporation", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); rainfall = new TimestampSeries("Rainfall", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); snowfall = new TimestampSeries("Snowfall", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); snowMelt = new TimestampSeries("Snowmelt", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); snowStorage = new TimestampSeries("Snow storage", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.Millimiters); surfaceStorage = new TimestampSeries("Surface storage", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.Millimiters); rootZoneStorage = new TimestampSeries("Root zone storage", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.Millimiters); overlandflow = new TimestampSeries("Overlandflow", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); routedOverlandflow = new TimestampSeries("Routed overlandflow", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); interflow = new TimestampSeries("Inteflow", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); routedInterflow = new TimestampSeries("Routed interflow", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); baseflow = new TimestampSeries("Baseflow", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); routedBaseflow = new TimestampSeries("Routed baseflow", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); specificRunoff = new TimestampSeries("Specific runoff", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.MmPrDay); runoff = new TimestampSeries("Runoff", simulationStartTime, numberOfTimesteps, 1, TimestepUnit.Days, 0, Units.M3PrSec); OutputTimeSeries.Items.Clear(); OutputTimeSeries.Items.Add(precipitation); OutputTimeSeries.Items.Add(potentialEvaporation); OutputTimeSeries.Items.Add(temperature); OutputTimeSeries.Items.Add(observedSpecificRunoff); OutputTimeSeries.Items.Add(observedRunoff); OutputTimeSeries.Items.Add(surfaceEvaporation); OutputTimeSeries.Items.Add(rootZoneEvaporation); OutputTimeSeries.Items.Add(rainfall); OutputTimeSeries.Items.Add(snowfall); OutputTimeSeries.Items.Add(snowMelt); OutputTimeSeries.Items.Add(snowStorage); OutputTimeSeries.Items.Add(surfaceStorage); OutputTimeSeries.Items.Add(rootZoneStorage); OutputTimeSeries.Items.Add(overlandflow); OutputTimeSeries.Items.Add(routedOverlandflow); OutputTimeSeries.Items.Add(interflow); OutputTimeSeries.Items.Add(routedInterflow); OutputTimeSeries.Items.Add(baseflow); OutputTimeSeries.Items.Add(routedBaseflow); OutputTimeSeries.Items.Add(specificRunoff); OutputTimeSeries.Items.Add(runoff); foreach (TimestampSeries ts in OutputTimeSeries.Items) { ts.IsVisible = false; } observedRunoff.IsVisible = true; runoff.IsVisible = true; isConfigurated = true; }