Exemplo n.º 1
0
        public List<List<Point>> PrepareData(Speciality speciality, short polinom)
        {
            var topMonthPayments = GetMonthPayments((int)speciality.TopPrice);
            var middleMonthPayments = GetMonthPayments((int)speciality.MiddlePrice);
            var lowMonthPayments = GetMonthPayments((int)speciality.LowPrice);
            var topSummaryPayments = GetSummaryPayments((int)speciality.TopPrice);
            var middleSummaryPayments = GetSummaryPayments((int)speciality.MiddlePrice);
            var lowSummaryPayments = GetSummaryPayments((int)speciality.LowPrice);

            result.Add(Point.InitList(topMonthPayments));
            result.Add(Point.InitList(middleMonthPayments));
            result.Add(Point.InitList(lowMonthPayments));
            result.Add(Point.InitList(1));
            result.Add(Point.InitList(1));
            result.Add(Point.InitList(1));
            result.Add(new List<Point>(yearsOfStudying)); //salaries per month
            result.Add(new List<Point>(yearsOfStudying)); //salaries summary

            Point point = new Point(speciality.StartOfWorking);
            result[monthSalaryIndex].Add(point);
            result[summarySalaryIndex].Add(point);

            InitPointsOnPayments(0, 3);
            InitPointsOnPayments(1, 4);
            InitPointsOnPayments(2, 5);

            InitSalaries(speciality, polinom);

            return result;
        }
Exemplo n.º 2
0
        public NodeModel()
        {
            Region = new Region();

            City = new City();

            University = new University();

            Faculty = new Faculty();

            Speciality = new Speciality();

            FacultyToSpeciality = new FacultyToSpeciality();
        }
Exemplo n.º 3
0
 public bool TrySave(Speciality editedModel)
 {
     bool result;
     try
     {
         provider.Update(editedModel);
         result = true;
     }
     catch
     {
         result = false;
     }
     return result;
 }
Exemplo n.º 4
0
 public void Create(Speciality model)
 {
     ClearCache();
     provider.Create(model);
 }
Exemplo n.º 5
0
        public List<NodeModel> Parse()
        {
            if (!OpenDataFile(filePath))
                return null;

            var results = new List<NodeModel>();

            foreach(XElement region in document.Root.Elements())
            {
                if (String.IsNullOrEmpty(region.Attribute("name").Value) || regionList.Contains(region.Attribute("name").Value))
                    continue;

                var regionModel = new Region();

                regionList.Add(region.Attribute("name").Value);

                regionModel.Name = region.Attribute("name").Value;

                regionModel.Fields.Add(GetKey(), translator.Translate(regionModel.Name, Translator.Languages.Uk, Translator.Languages.En));

                foreach(XElement city in region.Elements())
                {
                    if (String.IsNullOrEmpty(city.Attribute("name").Value) || cityList.Contains(city.Attribute("name").Value))
                        continue;

                    var cityModel = new City();

                    cityList.Add(city.Attribute("name").Value);

                    cityModel.Name = city.Attribute("name").Value;

                    cityModel.Region = regionModel;

                    cityModel.Fields.Add(GetKey(), translator.Translate(cityModel.Name, Translator.Languages.Uk, Translator.Languages.En));

                    foreach (XElement university in city.Elements())
                    {
                        if (String.IsNullOrEmpty(university.Attribute("name").Value) || universityList.Contains(university.Attribute("name").Value))
                            continue;

                        var universityModel = new University();

                        universityList.Add(university.Attribute("name").Value);

                        universityModel.Name = university.Attribute("name").Value;

                        universityModel.City = cityModel;

                        universityModel.Fields.Add(GetKey(), translator.Translate(universityModel.Name, Translator.Languages.Uk, Translator.Languages.En));

                        foreach (XElement faculty in university.Elements())
                        {
                            if (String.IsNullOrEmpty(faculty.Attribute("name").Value))
                                continue;

                            var facultyModel = new Faculty();

                            facultyModel.University = universityModel;

                            facultyModel.Name = faculty.Attribute("name").Value;

                            facultyModel.Fields.Add(GetKey(), translator.Translate(facultyModel.Name, Translator.Languages.Uk, Translator.Languages.En));

                            foreach(XElement speciality in faculty.Elements())
                            {

                                if (String.IsNullOrEmpty(speciality.Attribute("name").Value))
                                    continue;

                                var specialityModel = new Speciality();

                                var facultyToSpecialityModel = new FacultyToSpeciality();

                                specialityModel.Name = speciality.Attribute("name").Value;

                                specialityModel.Fields.Add(GetKey(), translator.Translate(specialityModel.Name, Translator.Languages.Uk, Translator.Languages.En));

                                facultyToSpecialityModel.Speciality = specialityModel;

                                facultyToSpecialityModel.Faculty = facultyModel;

                                var node = new NodeModel
                                {
                                    Region = regionModel,
                                    City = cityModel,
                                    University = universityModel,
                                    Faculty = facultyModel,
                                    Speciality = specialityModel,
                                    FacultyToSpeciality = facultyToSpecialityModel
                                };

                                results.Add(node);
                            }
                        }
                    }
                }
            }

            return results;
        }
Exemplo n.º 6
0
        private IApproximator InitAproximator(Speciality speciality, short polinom)
        {
            var x = new List<int>();
            var y = new List<int>();

            var tmp = speciality.Salaries.SkipWhile(pair => pair.Value == null).ToList();

            foreach (var item in speciality.Salaries)
            {
                int value = item.Value ?? -1;

                if (value >= 0)
                {
                    y.Add(value);
                    x.Add(item.Key);
                }
                else
                {
                    if (item.Key < speciality.Salaries.First(pair => pair.Value > -1).Key)
                    {
                        x.Add(item.Key);
                        y.Add(tmp.First().Value ?? -1);
                    }
                }
            }
            if (polinom + 1 >= x.Count)
                polinom = (short)(x.Count - 1);

            return new Approximation.Approximator(x, y, speciality.StartOfWorking);
        }
Exemplo n.º 7
0
        private void InitSalaries(Speciality speciality, short polinom)
        {
            var aproximator = InitAproximator(speciality, polinom);

            var isFirstNonZeroValueReached = false;

            for (var i = speciality.StartOfWorking; (result[monthPriceIndex].Count > i ||
                result[summarySalaryIndex][i - 1 - speciality.StartOfWorking].y <= result[summaryPriceIndex][result[summaryPriceIndex].Count - 1].y) && i < maxYears; i++)
            {
                var value = aproximator.CalcY(i);
                if (value < 0)
                    value = 0;

                var newPoint = new Point(i, value);
                if (result[monthPriceIndex].Count > i)
                {
                    if (!isFirstNonZeroValueReached && value > 0)
                        result[monthSalaryIndex].Add(new Point(i, 0));
                    result[monthSalaryIndex].Add(newPoint);
                }
                else if (result[monthPriceIndex].Count == i && result[monthPriceIndex].Last().y >= value)
                {
                    if (!isFirstNonZeroValueReached && value > 0)
                        result[monthSalaryIndex].Add(new Point(i, 0));
                    result[monthSalaryIndex].Add(newPoint);
                }

                result[summarySalaryIndex].Add(new Point(i, result[summarySalaryIndex].Last().y + 12 * value));

                if (value > 0)
                    isFirstNonZeroValueReached = true;
            }
        }