/
YakuninAV
/
Convertors
Обзор
Документация
Войти
/
YakuninAV
/
Convertors
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Estimate/EstCoefficientFormulas.pas
99 строк
4 KB
YakuninAV
begin with gitflick
31 июл 2026, 15:21
31 июл 2026, 15:21
1dc0fc6
Код
Авторство
О чём код?
unit EstCoefficientFormulas; interface uses SynCommons, DBDStrUtils, EstTypes, EstIntfs; type /// Вычислитель итогового значения коэффициента TEstCoefficientCalcV1 = record private FCoefs: TEstCoefficients; FFormula: string; FNames: string; FValue: Double; FTarget: TEstimateValueTarget; public property Names: string read FNames; property Value: Double read FValue; property Formula: string read FFormula; property Target: TEstimateValueTarget read FTarget; constructor Create(Coefs: TEstCoefficients); function Calc(const Trg: TEstimateValueTarget): Boolean; end; /// Функция формирует формулу расчёта поправочного коэффициента на основании массива поправок // num ToNum Val op // каждый Num в массиве уникален и больше 0 // для любого ToNum>0 должен существовать Num=ToNum // может быть несколько записей с одинаковым ToNum // значения коэфов обозначаются Nnum // значения коэфов, имеющих одинаковый ToNum объединяются с Nnum в виде: // (Nnum Oi Ni Oj Nj ... Ok Nk) // где O сперация для значения коэфов N (i,j,k) function ComputeCoefficientsValueV1(const Target: TEstimateValueTarget; Coefficients: TEstCoefficients; out Value: Double; out Formula: string): Boolean; /// Функция выполняет операцию над операндами и возвращает результат function ExecValueOperation(const D1, D2: Double; const Op: TEstimateOperationType): Double; implementation function ExecValueOperation(const D1, D2: Double; const Op: TEstimateOperationType): Double; begin case Op of eopMul: Result:=D1*D2; eopSum: Result:=D1+D2; eopSub: Result:=D1-D2; eopDiv: Result:=D1/D2; end; end; function ComputeCoefficientsValueV1(const Target: TEstimateValueTarget; Coefficients: TEstCoefficients; out Value: Double; out Formula: string): Boolean; var i,j: Integer; coef: IEstCoefficient; v: TEstimateCoefValue; s: string; d: Double; c: Char; begin s := ''; Value:=1; for i := Low(Coefficients) to High(Coefficients) do begin coef := Coefficients[i]; j := coef.IndexOfValueTarget(Target); if j>=0 then begin v:=coef.Values[j]; if (s='') and (v.Operation=eopMul) then s := EstDoubleToString(v.Value, EstimateValuePrecision) else if (s='') then s := '1' + EstimateOperationTypeToChar(v.Operation) + EstDoubleToString(v.Value, EstimateValuePrecision) else s := s + EstimateOperationTypeToChar(v.Operation) + EstDoubleToString(v.Value, EstimateValuePrecision); Value := ExecValueOperation(Value,v.Value, v.Operation); end; end; result := True; Formula:= DBDTrimChar(s,'*'); end; { TEstCoefficientCalcV1 } function TEstCoefficientCalcV1.Calc(const Trg: TEstimateValueTarget): Boolean; begin if (FCoefs = nil) or (Length(FCoefs)=0) then Result := False else if Trg=FTarget then Result := True else begin FTarget := Trg; Result := ComputeCoefficientsValueV1(Trg, FCoefs, FValue, FFormula); end; end; constructor TEstCoefficientCalcV1.Create(Coefs: TEstCoefficients); var i: Integer; begin FCoefs:=Coefs; FTarget := evtNone; FNames := ''; FValue := 0; FFormula := ''; if FCoefs=nil then Exit; for i := Low(FCoefs) to High(FCoefs) do begin FNames := FNames + '#' + FCoefs[i].Name + '||' + FCoefs[i].Reason; end; FNames := DBDTrimChar(FNames,'#'); end; end.