示例#1
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);
        }
示例#2
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
            });
        }