Beispiel #1
0
        public AllTablesResult LoadAllTables(int stepPrecision)
        {
            var result = new AllTablesResult();

            var tablesCsv = HydroModel.GetExpandedRatingTables(stepPrecision, CsvMetaHeader, CsvMetadata);

            if (string.IsNullOrEmpty(tablesCsv))
            {
                return(result);
            }

            var csvRatings = AQCSV.Load(tablesCsv, true, new[] { "NumTables", "NumPeriods", "NumPoints" });

            var tableNumber = CSVUtil.ToDouble(csvRatings.dataSet[0].datas, 0);
            var tableName   = CSVUtil.ToString(csvRatings.dataSet[0].datas, 1);
            var numPeriods  = CSVUtil.ToDouble(csvRatings.dataSet[0].datas, 2);
            var numPoints   = CSVUtil.ToDouble(csvRatings.dataSet[0].datas, 3);

            for (var i = 0; i < tableNumber.Length; ++i)
            {
                result.Tables.Add(new Table
                {
                    TableNumber = tableNumber[i],
                    TableName   = tableName[i],
                    NumPeriods  = numPeriods[i],
                    NumPoints   = numPoints[i]
                });
            }

            var tableNumber2 = CSVUtil.ToDouble(csvRatings.dataSet[1].datas, 0);
            var startDate    = CSVUtil.ToString(csvRatings.dataSet[1].datas, 1);
            var endDate      = CSVUtil.ToString(csvRatings.dataSet[1].datas, 2);

            for (var i = 0; i < tableNumber2.Length; ++i)
            {
                result.TableDates.Add(new TableDate
                {
                    TableNumber = tableNumber2[i],
                    StartDate   = DateTimeParser.Parse(LocationData, startDate[i]),
                    EndDate     = string.IsNullOrEmpty(endDate[i]) ? DateTimeOffset.MaxValue : DateTimeParser.Parse(LocationData, endDate[i])
                });
            }

            var tableNumber3 = CSVUtil.ToDouble(csvRatings.dataSet[2].datas, 0);
            var input        = CSVUtil.ToDouble(csvRatings.dataSet[2].datas, 1);
            var output       = CSVUtil.ToDouble(csvRatings.dataSet[2].datas, 2);

            for (var i = 0; i < tableNumber3.Length; ++i)
            {
                result.TableValues.Add(new TableValue
                {
                    TableNumber = tableNumber3[i],
                    Input       = input[i],
                    Output      = output[i]
                });
            }

            return(result);
        }
        public AllTablesResult LoadAllTables(RatingModelDescription ratingModelDescription, RatingCurveListServiceResponse ratingCurves, double stepSize)
        {
            var result = new AllTablesResult();

            var validTableNumbers = new HashSet <double>(
                ratingCurves
                .RatingCurves
                .Select(c => double.TryParse(c.Id, out var number) ? (double?)number : null)
                .Where(d => d.HasValue)
                .Select(d => d.Value));

            for (var i = 0; i < ratingCurves.RatingCurves.Count; ++i)
            {
                var ratingCurve = ratingCurves.RatingCurves[i];

                if (!double.TryParse(ratingCurve.Id, out var tableNumber))
                {
                    tableNumber = 1.0 + i;

                    while (validTableNumbers.Contains(tableNumber))
                    {
                        tableNumber += ratingCurves.RatingCurves.Count;
                    }
                }

                result.Tables.Add(new Table
                {
                    TableNumber = tableNumber,
                    TableName   = ratingCurve.Id,
                    NumPeriods  = ratingCurve.PeriodsOfApplicability.Count,
                    NumPoints   = ratingCurve.BaseRatingTable.Count
                });

                result.TableDates.AddRange(ratingCurve.PeriodsOfApplicability.Select(p => new TableDate
                {
                    TableNumber = tableNumber,
                    StartDate   = p.StartTime,
                    EndDate     = p.EndTime
                }));

                result.TableValues.AddRange(ratingCurve.BaseRatingTable.Select(p => new TableValue
                {
                    TableNumber = tableNumber,
                    Input       = p.InputValue ?? double.NaN,
                    Output      = p.OutputValue ?? double.NaN
                }));
            }

            return(result);
        }