Example #1
0
		public void Calculate() {
			Lessees = new Dictionary<Lessee, ResultInfo>();
			Vacancy = new ResultInfo();
			Landlord = new ResultInfo();
			if ( Project == Project.Empty ) return;

			foreach ( var fac in Project.Assignments ) {
				foreach ( var fa in fac ) {
					if ( !Lessees.ContainsKey(fa.Lessee) ) Lessees[fa.Lessee] = new ResultInfo();
					Lessees[fa.Lessee].Lessee = fa.Lessee;
					if ( fa.Start < Lessees[fa.Lessee].StartDate ) Lessees[fa.Lessee].StartDate = fa.Start;
					if ( fa.End > Lessees[fa.Lessee].EndDate ) Lessees[fa.Lessee].EndDate = fa.End;
					Lessees[fa.Lessee].Durations.Add(new Interval(fa.StartIntervalIndex, fa.EndIntervalIndex));
					Lessees[fa.Lessee].Members = fa.Lessee.Members;
					Lessees[fa.Lessee].FlatSize += fac.Flat.Size * fa.Duration;
				}
				Vacancy.Members += fac.VacantDuration;
				Vacancy.FlatSize += fac.Flat.Size * fac.VacantDuration;
			}

			foreach ( var result in Lessees.Values ) {
				result.AdvancePayment = TimeInterval.Within(result.StartDate, result.EndDate).Sum(
					i => result.Lessee.Payments.Get(i.Start) / 2.0);
                result.Members *= result.Duration;
			}

			foreach ( var cost in Project.Costs ) {
				if ( !Landlord.Costs.ContainsKey(cost) ) Landlord.Costs[cost] = 0;
				var devisor = CalculateDevisor(cost, Lessees, Vacancy);
				foreach ( var lessee in Lessees.Keys ) {
					var option = cost.Options.FirstOrDefault(o => o.Lessee == lessee); 
					if ( option == null || (!option.Affected && !option.Exempt) ) continue;
					if ( option.Exempt ) Landlord.Costs[cost] += CalculateAmount(cost, Lessees[lessee], devisor);
					else Lessees[lessee].Costs[cost] = CalculateAmount(cost, Lessees[lessee], devisor);
				}
				if ( cost.AffectsVacancy ) Vacancy.Costs[cost] = CalculateAmount(cost, Vacancy, devisor);
			}

			Error = new ResultInfo();
			foreach ( var cost in Project.Costs ) {
				Error.Costs[cost] = Math.Abs(Lessees.Sum(i => i.Value.Costs.ContainsKey(cost) ? i.Value.Costs[cost] : 0)
					+ (Vacancy.Costs.ContainsKey(cost) ? Vacancy.Costs[cost] : 0)
					+ (Landlord.Costs.ContainsKey(cost) ? Landlord.Costs[cost] : 0 )
					- cost.Amount);
			}
			
			NotifyPropertyChanged("Result");
		}
Example #2
0
		public double CalculateAmount(Cost cost, ResultInfo info, double devisor) {
			switch ( cost.Mode ) {
				case CostMode.Lessee: return cost.Amount * info.Duration / devisor;
				case CostMode.Member: return cost.Amount * info.Members / devisor;
				case CostMode.Flat: return cost.Amount * info.FlatSize / devisor;
				case CostMode.External: 
                    if (info.Lessee != null)
					    return cost.Options.First(o => o.Lessee == info.Lessee).Amount;
                    else if (info == Vacancy)
                        return cost.VacancyAmount;
                    else return 0;
			}
			return 0;
		}
Example #3
0
		public double CalculateDevisor(Cost cost, Dictionary<Lessee, ResultInfo> result, ResultInfo vacancy) {
			switch ( cost.Mode ) {
				case CostMode.Lessee: 
					return cost.Options.Sum(o => o.Affected || o.Exempt ? result[o.Lessee].Duration : 0) 
						+ (cost.AffectsVacancy ? vacancy.Members : 0);
				case CostMode.Member:
					return cost.Options.Sum(o => o.Affected || o.Exempt ? result[o.Lessee].Members : 0) 
						+ (cost.AffectsVacancy ?  vacancy.Members : 0);
				case CostMode.Flat:
					return cost.Options.Sum(o => o.Affected || o.Exempt ? result[o.Lessee].FlatSize : 0) 
						+ (cost.AffectsVacancy ? vacancy.FlatSize : 0);
			}
			return 1;
		}