123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using Application.ATG_Classic_App.Model;
- namespace Application.ATG_Classic_App
- {
- public class HeightToVolumeCaculator
- {
- public enum Mode
- {
-
-
-
- PreferNearest = 1,
-
-
-
- PreferCeiling = 2,
-
-
-
- PreferFloor = 4,
- }
- public Mode EstimateMode { get; set; }
- private IOrderedEnumerable<TankProfileData> tankProfiles_by_Ascending;
-
-
-
-
- public HeightToVolumeCaculator(IEnumerable<TankProfileData> tankProfiles)
- {
- if (tankProfiles == null || !tankProfiles.Any()) throw new ArgumentNullException(nameof(tankProfiles));
- this.EstimateMode = Mode.PreferNearest | Mode.PreferCeiling;
- this.tankProfiles_by_Ascending = tankProfiles.OrderBy(p => p.Height);
- }
- public double GetVolume(double height)
- {
- var find = this.tankProfiles_by_Ascending.FirstOrDefault(p => p.Height == height);
- if (find != null) return find.Volume;
- TankProfileData estimation;
- if (this.EstimateMode.HasFlag(Mode.PreferNearest))
- {
- var next = this.tankProfiles_by_Ascending.FirstOrDefault(p => p.Height > height);
- if (next == null) return this.tankProfiles_by_Ascending.Last().Volume;
- var prior = this.tankProfiles_by_Ascending.LastOrDefault(p => p.Height < height);
- if (prior == null) return this.tankProfiles_by_Ascending.First().Volume;
- var offsetToNext = next.Height - height;
- var offsetToPrior = Math.Abs(prior.Height - height);
- if (offsetToNext < offsetToPrior)
- estimation = this.tankProfiles_by_Ascending.FirstOrDefault(p => p.Height == next.Height);
- else if (offsetToNext > offsetToPrior)
- estimation = this.tankProfiles_by_Ascending.FirstOrDefault(p => p.Height == prior.Height);
- else
- {
- if (this.EstimateMode.HasFlag(Mode.PreferCeiling))
- estimation = next;
- else
- estimation = prior;
- }
- }
- else if (this.EstimateMode == Mode.PreferCeiling)
- {
-
- estimation = this.tankProfiles_by_Ascending.FirstOrDefault(p => p.Height > height);
- if (estimation == null) return this.tankProfiles_by_Ascending.Last().Volume;
- }
- else if (this.EstimateMode == Mode.PreferFloor)
- {
-
- estimation = this.tankProfiles_by_Ascending.LastOrDefault(p => p.Height < height);
- if (estimation == null) return this.tankProfiles_by_Ascending.First().Volume;
- }
- else return 0;
- return estimation.Volume;
- }
-
-
-
-
- }
- public class TemperatureCompensationCaculator
- {
- private double coeff;
-
-
-
-
- public TemperatureCompensationCaculator(double expansionCoefficient)
- {
- if (expansionCoefficient > 1 || expansionCoefficient < 0) throw new ArgumentException("invalid expansionCoefficient");
- this.coeff = expansionCoefficient;
- }
-
-
-
-
-
-
-
- public double CaculateCompensatedVolume(double standardTemp, double currentVol, double currentTemp)
- {
- var volDiffPerLiter = 1 - this.coeff * (currentTemp - standardTemp);
- return volDiffPerLiter * currentVol;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
|