Пример #1
0
        private Calculation Resolve(Defaults defaults, string defaultLocation, Processor processor, CalculationConfig calculationConfig)
        {
            var samplingTimeSeries = FindTimeSeries(
                nameof(calculationConfig.SamplingSeries),
                calculationConfig.SamplingSeries,
                defaultLocation,
                defaults.SamplingLabel);

            var samplingIdentifier = TimeSeriesIdentifierParser.ParseIdentifier(samplingTimeSeries.Identifier);

            var totalLoadingIdentifier = !string.IsNullOrEmpty(calculationConfig.TotalLoadingSeries)
                ? calculationConfig.TotalLoadingSeries
                : $"{defaults.TotalLoadingPrefix}{samplingIdentifier.Parameter}";

            var totalLoadingTimeSeries = FindOrCreateTimeSeries(
                nameof(calculationConfig.TotalLoadingSeries),
                totalLoadingIdentifier,
                defaultLocation,
                defaults.EventLabel,
                identifier => CreateTotalLoadingTimeSeries(defaults, calculationConfig, processor, samplingTimeSeries, identifier));

            return(new Calculation
            {
                SamplingTimeSeries = samplingTimeSeries,
                EventTimeSeries = processor.EventTimeSeries,
                TotalLoadingTimeSeries = totalLoadingTimeSeries
            });
        }
Пример #2
0
        private TimeSeries CreateDischargeTotalTimeSeries(
            Defaults defaults,
            ProcessorConfig processorConfig,
            string identifier)
        {
            var timeSeriesIdentifier = TimeSeriesIdentifierParser.ParseIdentifier(identifier);

            Log.Info($"Creating '{identifier}' ...");

            var parameter = FindExistingParameterByIdentifier(timeSeriesIdentifier.Parameter);
            var unit      = ResolveParameterUnit(defaults.DischargeTotalUnit, processorConfig.DischargeTotalUnit, parameter);
            var location  = FindExistingLocation(timeSeriesIdentifier.Location);

            var response = Client.Provisioning.Post(
                new Aquarius.TimeSeries.Client.ServiceModels.Provisioning.PostReflectedTimeSeries
            {
                LocationUniqueId  = location.UniqueId,
                Parameter         = parameter.ParameterId,
                Unit              = unit,
                Label             = timeSeriesIdentifier.Label,
                InterpolationType = InterpolationType.SucceedingConstant,
                GapTolerance      = DurationExtensions.MaxGapDuration,
                UtcOffset         = location.UtcOffset,
                Method            = DefaultMethodCode,
                Comment           = $"Created automatically by {ExeHelper.ExeNameAndVersion}"
            });

            Log.Info($"Created '{response.Identifier}' ({response.Unit})");

            AddNewTimeSeries(response);

            return(response);
        }
Пример #3
0
        private TimeSeries CreateTotalLoadingTimeSeries(
            Defaults defaults,
            CalculationConfig calculationConfig,
            Processor processor,
            TimeSeries sourceTimeSeries,
            string identifier)
        {
            var timeSeriesIdentifier = TimeSeriesIdentifierParser.ParseIdentifier(identifier);

            Log.Info($"Creating '{identifier}' ...");

            var parameter = FindExistingParameterByIdentifier(timeSeriesIdentifier.Parameter);
            var unit      = ResolveParameterUnit(defaults.TotalLoadingUnit, calculationConfig.TotalLoadingUnit, parameter);
            var location  = FindExistingLocation(timeSeriesIdentifier.Location);

            var(sourceMassUnit, sourceVolumeUnit) = DecomposeIntegrationUnits(MassUnitGroup, VolumeUnitGroup, sourceTimeSeries);
            var totalDischargeVolumeUnit = GetUnit(VolumeUnitGroup, processor.DischargeTotalTimeSeries.Unit);
            var loadingMassUnit          = GetUnit(MassUnitGroup, parameter.UnitIdentifier);

            var comments = new List <string>();
            var scalars  = new List <string>();

            if (sourceMassUnit != loadingMassUnit)
            {
                BuildUnitConversion(scalars, comments, sourceMassUnit, loadingMassUnit);
            }

            if (sourceVolumeUnit != totalDischargeVolumeUnit)
            {
                BuildUnitConversion(scalars, comments, totalDischargeVolumeUnit, sourceVolumeUnit);
            }

            var formula = !scalars.Any()
                ? $"y = x1 * x2; // No unit conversion required"
                : $"y = x1 * x2 * {string.Join(" * ", scalars)}; // Convert {string.Join(", then ", comments)}";

            var response = Client.Provisioning.Post(new PostCalculatedDerivedTimeSeries
            {
                LocationUniqueId    = location.UniqueId,
                Parameter           = parameter.ParameterId,
                Unit                = unit,
                Label               = timeSeriesIdentifier.Label,
                InterpolationType   = GetTimeSeriesInterpolationType(sourceTimeSeries.UniqueId),
                UtcOffset           = location.UtcOffset,
                Method              = DefaultMethodCode,
                Comment             = $"Created automatically by {ExeHelper.ExeNameAndVersion}",
                TimeSeriesUniqueIds = new List <Guid> {
                    sourceTimeSeries.UniqueId, processor.DischargeTotalTimeSeries.UniqueId
                },
                Formula = formula,
                ExtendedAttributeValues = CreateRequiredExtendedAttributes()
            });

            Log.Info($"Created '{response.Identifier}' ({response.Unit}) with formula: {formula}");

            AddNewTimeSeries(response);

            return(response);
        }