public ActionResult Index() { XmlSerializer serializer = new XmlSerializer(typeof(Task)); string path = "http://91.232.241.66:92/api/v1/study/89b4effb-40f8-44d9-ba25-c9cbe7602a95/measurements/tasks/3ba2733b-6274-4bee-93ac-6af4eab90e72/?authorization=Basic%20dGVzdF92YWNhbnRpb246dGVzdF92YWNhbnRpb24="; XmlTextReader reader = new XmlTextReader(path); var task = serializer.Deserialize(reader) as Task; if (task != null) { for (int i = 0; i < task.Groups.Length; i++) { for (int j = 0; j < task.Groups[i].Sessions.Length; j++) { AverageViewModel model = new AverageViewModel(); model.GroupName = task.Groups[i].Name; model.CurrentDate = task.Groups[i].Sessions[j].SessionDate; double sum = 0; int count; for (count = 0; count < task.Groups[i].Sessions[j].Animals.Length; count++) { for (int z = 0; z < task.Groups[i].Sessions[j].Animals[count].Data.Length; z++) { sum += task.Groups[i].Sessions[j].Animals[count].Data[z].Value; } } model.Average = sum / count; model.Id = Guid.NewGuid(); modelAverageList.Add(model); } } } return(View(modelAverageList)); }
private async void calculateAverageButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(startNumberText.Text)) { errorMessageStartLabel.Text = "El Inicio es requerido."; return; } if (startNumberText.Text == "0") { errorMessageStartLabel.Text = "El Inicio debe ser mayor a 0."; return; } if (string.IsNullOrWhiteSpace(endNumberText.Text)) { errorMessageEndLabel.Text = "El Fin es requerido."; return; } if (endNumberText.Text == "0") { errorMessageEndLabel.Text = "El Fin debe ser mayor a 0."; return; } errorMessageStartLabel.Text = string.Empty; errorMessageEndLabel.Text = string.Empty; var entidad = new AverageViewModel { End = Convert.ToInt32(endNumberText.Text), Start = Convert.ToInt32(startNumberText.Text), }; calculateAverageButton.Enabled = false; resultAverageLabel.Text = "Procesando datos..."; var result = await averageService.Request(entidad); calculateAverageButton.Enabled = true; resultAverageLabel.Text = $"El resultado es: {result}"; }
public AveragePage(string userId) { InitializeComponent(); Model = new AverageViewModel(userId); BindingContext = Model; }
/*Function to create AverageViewModels: each criteria with a specific average asking price calculated * Calculate average for each district and property type * Each will be a AverageViewModel e.g. [Condominium, 1503.15] * Then display all AverageViewModels in a page with a table */ private AverageViewModel getAveragePrices() { //TODO Logic //Declare empty list Stopwatch myStopWatch = Stopwatch.StartNew(); List <Average> typeCriteria = new List <Average>(); List <Average> districtCriteria = new List <Average>(); IEnumerable <Property> propertiesByCriteria; //To later load list of properties for each different criteria //Get list of all properties first IEnumerable <Property> fullList = propertyMapper.SelectAll(); //Get all property types IEnumerable <string> allPropertyTypes = propertyMapper.GetAllPropertyTypes(); //Get all district names IEnumerable <string> allDistricts = propertyMapper.GetAllDistrictName(); //filter the full list by each property type, and then find its average and add as new AverageViewModel foreach (string type in allPropertyTypes) { propertiesByCriteria = fullList.Where(p => p.PropertyType.Equals(type)); //If there are properties for this criteria if (propertiesByCriteria.Any()) { double totalSum = 0; int count = 0; //Nested For-loop to get total sum of all properties for this criteria foreach (Property ppt in propertiesByCriteria) { totalSum = totalSum + ppt.AskingPrice; count++; } //Add the criteria and its average as a new AverageViewModel Average avg = new Average(); avg.criteriaAverage = totalSum / count; avg.criteriaName = type; typeCriteria.Add(avg); //System.Diagnostics.Debug.WriteLine(avm.criteriaAverage + " - " + avm.criteriaName); } } //foreach district, find its average and add as new AverageViewModel foreach (string district in allDistricts) { propertiesByCriteria = fullList.Where(p => p.DistrictID.Equals(propertyMapper.GetDistrictIdByDistrictName(district).First())); if (propertiesByCriteria.Any()) { double totalSum = 0; int count = 0; //Nested For-loop to get total sum of all properties for this criteria foreach (Property ppt in propertiesByCriteria) { totalSum = totalSum + ppt.AskingPrice; count++; } //Add the criteria and its average as a new AverageViewModel Average avg = new Average(); avg.criteriaAverage = totalSum / count; avg.criteriaName = district; districtCriteria.Add(avg); //System.Diagnostics.Debug.Write(avm.criteriaAverage + " - " + avm.criteriaName); } } if (districtCriteria.Any() && typeCriteria.Any()) { //Put the two loaded lists from above into a AverageViewModel for display AverageViewModel avm = new AverageViewModel(); avm.districtAverages = districtCriteria; avm.propertyTypesAverages = typeCriteria; System.Diagnostics.Debug.WriteLine("Time taken (ms) : " + myStopWatch.ElapsedMilliseconds); return(avm); } return(null); }