public List <ProductBuyClientModel> GetProductBuyClientAndFeedback(int id) { List <FeedbackModel> feedbacks = _controller.GetFeedbackModels(); List <ProductBuyClientModel> productByClients = _controller.GetProductsBuyClientModels(id); for (int i = 0; i < productByClients.Count; ++i) { List <int> rate = new List <int>(); for (int j = 0; j < feedbacks.Count; ++j) { if (productByClients[i].ProductId == feedbacks[j].ProductId && id == feedbacks[j].ClientId) { if (feedbacks[j].Rate > 0) { rate.Add(feedbacks[j].Rate); } } } productByClients[i].AVGRate = rate.Count > 0 ? Convert.ToString(Queryable.Average(rate.AsQueryable())) : "нет оценки"; } return(productByClients); }
static void Main(string[] args) { var values = new int[] { 5, 10, 20, 24 }; //we can convert an int array to IQuerable. //and then we can pass it to Querable and methods like Average. double result = Queryable.Average(values.AsQueryable()); Console.WriteLine(result); /* ----------Another Example------------ */ //List and Array can be converted to IQuerable. List <int> list = new List <int>(); list.Add(0); list.Add(1); list.Add(2); list.Add(3); int[] array = new int[4]; array[0] = 4; array[0] = 5; array[0] = 6; array[0] = 7; //We can use IQuerable to treat collection as one type. Test(list.AsQueryable()); Test(array.AsQueryable()); Console.ReadLine(); }
public char Calculate() { double avg = Queryable.Average(testScores.AsQueryable()); if (avg >= 90 && avg <= 100) { return('O'); } else if (avg >= 80 && avg < 90) { return('E'); } else if (avg >= 70 && avg < 80) { return('A'); } else if (avg >= 55 && avg < 70) { return('P'); } else if (avg >= 40 && avg < 55) { return('D'); } else { return('T'); } }
private void OnTextChanged(object sender, EventArgs e) { var output = App.ProductDatabase.SelectProduct(barCode.Text); if (output.Any()) { DateTime ExpDate; string productName = output[0].productName; productNameText.Text = productName; openFunctions1(); var averages = App.ExpiratonDateDatabase.GetAverage(barCode.Text); int[] average = new int[output.Count()]; int c = 0; foreach (var current in averages) { int k = (current.ExpDate - current.StartDate).Days; average[c] = k; c++; } double avg = Queryable.Average(average.AsQueryable()); ExpDate = DateTime.Now.AddDays(avg); expDate.Date = ExpDate; } else { productNameText.Text = "No such product found"; closeFunctions1(); } }
static void Main() { var arr = new int[] { 10, 17, 25, 30, 40, 55, 60, 70 }; double avg = Queryable.Average(arr.AsQueryable()); Console.WriteLine("Average = " + avg); }
public decimal GetAverage(List <decimal> list) { var arr = list.ToArray <decimal>(); decimal avg = Queryable.Average(arr.AsQueryable()); return(avg); }
public void Init() { var output = App.ListsDatabase.GetListsPerUser(); compartmentPicker.Items.Clear(); if (output.Any()) { for (int i = 0; i < output.Count; i++) { compartmentPicker.Items.Add(output[i].ListName); } } string barCode = this.productId.ToString(); var product = App.ProductDatabase.SelectProductWBwithId(barCode); DateTime ExpDate; var averages = App.ExpiratonDateDatabase.GetAverage(product[0].productName); int[] average = new int[output.Count()]; int c = 0; foreach (var current in averages) { int k = (current.ExpDate - current.StartDate).Days; average[c] = k; c++; } double avg = Queryable.Average(average.AsQueryable()); ExpDate = DateTime.Now.AddDays(avg); expDate.Date = ExpDate; }
public string LecturaMedidor() { var v = _lecturas.FindAll(p => p.Voltage > 0); var c = (_lecturas.FindAll(p => p.Current > 0)); var aP = _lecturas.FindAll(p => p.ActivePower > 0); double avg_v = v.Count > 0 ? Queryable.Average((IQueryable <double>)v.Select(o => o.Voltage).AsQueryable()) : 0; double avg_c = c.Count > 0 ? Queryable.Average((IQueryable <double>)c.Select(o => o.Current).AsQueryable()) : 0; double avg_aP = aP.Count > 0 ? Queryable.Average((IQueryable <int>)aP.Select(o => o.ActivePower).AsQueryable()) : 0; var fecha = DateTime.Now; if (!(fecha.Hour == 23 && fecha.Minute == 59)) { fecha = DateTime.Now.AddSeconds(1); } var s = string.Format("{0};{1:0.00};{2:0.00};{3:0.00}", fecha.ToString("yyyyMMddHHmm"), avg_v, avg_c, avg_aP ); _lecturas.Clear(); return(s); { } }
public async Task <dynamic> GetJoke() { reacted = false; GetUserData(); double avg = Queryable.Average((IQueryable <int>)jokeCategories.AsQueryable()); int index; if (avg == 0) { index = new Random().Next(jokeCategories.Count); } else { index = jokeCategories.FindIndex(a => a >= avg); } currentCategory = stringCategories[index]; string path = "https://jokesapi.gottacatchemall.repl.co/jokes/" + stringCategories[index]; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { dynamic jsonJoke = await response.Content.ReadAsStringAsync(); Console.WriteLine(jsonJoke); return(JsonConvert.DeserializeObject <Joke>(jsonJoke)); } return(null); }
public static void GetAverage(int[] numbers) { // Write a function that takes an integer array and prints the AVERAGE of the values in the array. // For example, with an array [2, 10, 3], your program should write 5 to the console. double avg = Queryable.Average(numbers.AsQueryable()); Console.WriteLine(avg); }
private static object DynamicAverage(this IQueryable source, dynamic selector) { ParameterExpression newParamter = Expression.Parameter(source.ElementType, "x"); var newBody = new StatisVisitor(newParamter).Visit(selector.Body); dynamic dynSelector = Expression.Lambda(newBody, newParamter); dynamic dynSource = source; return(Queryable.Average(dynSource, dynSelector)); }
public virtual object Avg(IQueryable query, string elementSelector) { if (!string.IsNullOrWhiteSpace(elementSelector)) { query = query.Select(elementSelector); } return(Queryable.Average((dynamic)query)); }
static string AverageTenScores() { double a, b, c, d, e, f, g, h, i, j; Console.WriteLine("Please enter the value of 1st Test Score:"); a = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 2nd Test Score:"); b = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 3rd Test Score:"); c = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 4th Test Score:"); d = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 5th Test Score:"); e = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 6th Test Score:"); f = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 7th Test Score:"); g = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 8th Test Score:"); h = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 9th Test Score:"); i = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the value of 10th Test Score:"); j = double.Parse(Console.ReadLine()); var arr = new double[] { a, b, c, d, e, f, g, h, i, j }; double avg = Queryable.Average(arr.AsQueryable()); if (avg == 100 || avg >= 90) { Console.WriteLine($"The Average score is: A ({avg})"); Console.ReadKey(); } else if (avg <= 89 || avg >= 80) { Console.WriteLine($"The Average score is: B ({avg})"); Console.ReadKey(); } else if (avg <= 79 || avg >= 70) { Console.WriteLine($"The Average score is: C ({avg})"); Console.ReadKey(); } else if (avg <= 69 || avg >= 60) { Console.WriteLine($"The Average score is: D ({avg})"); Console.ReadKey();; } else if (avg <= 59) { Console.WriteLine($"The Average score is: F ({avg})"); Console.ReadKey();; } return(Console.ReadLine()); }
static void Main(string[] args) { var values = new int[] { 5, 10, 20 }; // We can convert an int array to IQueryable. // ... And then we can pass it to Queryable and methods like Average. double result = Queryable.Average(values.AsQueryable()); Console.WriteLine(result); Console.ReadLine(); }
public static float GetPackAvgOP(AvaliPack pack, Pawn pawn) { List <float> opinions = new List <float>(); foreach (Pawn packmember in pack.pawns) { opinions.Add(packmember.relations.OpinionOf(pawn)); } return(Queryable.Average(opinions.AsQueryable())); }
static void Evaluate(int[] results) { int highestmark = results.Max(); int lowestmark = results.Min(); double averagemark = Queryable.Average(results.AsQueryable()); Console.WriteLine("Evaluating score"); Console.WriteLine("Highest mark is: {0}", highestmark); Console.WriteLine("Lowest mark is: {0}", lowestmark); Console.WriteLine("Average mark is: {0}", averagemark); }
static void Main(string[] args) { Action <int[]> PrintAverageofArray = (arry) => { double avgNum = Queryable.Average(arry.AsQueryable()); Console.WriteLine($"The average of the array is {avgNum}"); }; int[] myArry4 = { 2, -30, -4, 56, -19, 67 }; PrintAverageofArray(myArry4); }
public void FindAvg() { double TempAvg = Queryable.Average(WeeklyTemp.AsQueryable()); double OxgenAvg = Queryable.Average(WeeklyOxygen.AsQueryable()); double WaterHeightAvg = Queryable.Average(WeeklyWaterLevel.AsQueryable()); Console.WriteLine($"\n\n\n Average Weekly Temp {TempAvg}\n"); Console.WriteLine($"\n\n Average Weekly Oxygen Levels {OxgenAvg}"); Console.WriteLine($"\n\n Average Weekly Water Levels {WaterHeightAvg}"); }
public static void MonteCarlo_Variation() { int n = 20000; //n is the number of simulations double l_three_d = 0; //length of a line double[] distancesThreeD = new double[n]; // here the distance is stored in an array for each iteration of n BoxMullerNormal b = new BoxMullerNormal(); //repeat the experiment n (20k) times for (int i = 0; i < n; i++) { //get a point (x1,x2,y1,y2) at random double x1 = b.GetRandom(); double x2 = b.GetRandom(); double y1 = b.GetRandom(); double y2 = b.GetRandom(); double z1 = b.GetRandom(); double z2 = b.GetRandom(); //3D double result2 = ThreeD(x1, x2, y1, y2, z1, z2); l_three_d = result2; //get length of a 3d line distancesThreeD[i] = l_three_d; } #region average double averageOfLineThreeD = Queryable.Average(distancesThreeD.AsQueryable()); #endregion #region standard dev double sum = distancesThreeD.Sum(d => Math.Pow(d - averageOfLineThreeD, 2)); double sd_3d = Math.Sqrt((sum) / (distancesThreeD.Count() - 1)); #endregion #region confidence interval double marginOfError_3d = 2.58 * (sd_3d / Math.Sqrt(n)); double lowerEndOfInterval_3d = averageOfLineThreeD - marginOfError_3d; //lower end of the interval is average - margin of error double UpperEndOfInterval_3d = averageOfLineThreeD + marginOfError_3d; //and upper end is average + margin of error #endregion #region display results Console.WriteLine("3D Results: \n"); Console.WriteLine("Average of 3d: " + averageOfLineThreeD); Console.WriteLine("Standard Deviation 3d: " + sd_3d); Console.WriteLine("μ: " + averageOfLineThreeD + " ± " + marginOfError_3d); Console.WriteLine("lower end of interval = " + lowerEndOfInterval_3d); Console.WriteLine("upper end of interval = " + UpperEndOfInterval_3d); Console.WriteLine("You can be 99% confident that the population mean (μ) falls between " + lowerEndOfInterval_3d + " and " + UpperEndOfInterval_3d); #endregion Console.WriteLine("\nPress any key to continue..... \n"); }
//public string full_address; public Student(string First_name, string Last_name, string Student_number, int Age, int[] Scores) { first_name = First_name; last_name = Last_name; student_number = Student_number; age = Age; //full_address = Full_Address; scores = Scores; full_name = First_name + " " + Last_name; average_scores = Queryable.Average(Scores.AsQueryable()); }
static void Main(string[] args) { Action <int[]> PrintMaxMinAverageArrayValues = (arry) => { int maxNum = arry.Max(); int minNum = arry.Min(); double avgNum = Queryable.Average(arry.AsQueryable()); Console.Write($"The Max Number in the Array is {maxNum}\n The Min Number in the array is {minNum}\n The Averag of the Array is {avgNum}"); }; int[] myArry1 = { 2, 30, 4, 56, 19 }; PrintMaxMinAverageArrayValues(myArry1); }
public void GetSupportedMethods() { Assert.That( AverageExpressionNode.GetSupportedMethods(), Is.EquivalentTo( new[] { GetGenericMethodDefinition(() => Queryable.Average((IQueryable <decimal>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <decimal?>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <double>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <double?>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <int>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <int?>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <long>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <long?>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <float>)null)), GetGenericMethodDefinition(() => Queryable.Average((IQueryable <float?>)null)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (decimal)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (decimal?)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (double)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (double?)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (int)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (int?)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (long)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (long?)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (float)0)), GetGenericMethodDefinition(() => Queryable.Average <object> (null, o => (float?)0)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <decimal>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <decimal?>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <double>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <double?>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <int>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <int?>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <long>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <long?>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <float>)null)), GetGenericMethodDefinition(() => Enumerable.Average((IEnumerable <float?>)null)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (decimal)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (decimal?)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (double)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (double?)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (int)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (int?)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (long)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (long?)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (float)0)), GetGenericMethodDefinition(() => Enumerable.Average <object> (null, o => (float?)0)) })); }
public void myMethod1(float[] param1f, float[] param2f) { float oj = 43f; foreach (float i in param1f) { if (oj == 4) { Console.WriteLine(oj); Console.WriteLine("huhhh"); } else { Console.WriteLine("no se"); } } float jo = 12f; foreach (float i in param2f) { if (jo == 5) { Console.WriteLine(jo); Console.WriteLine("huhhh"); Console.ReadKey(); } else { Console.WriteLine("seee"); } } int forr = 3; if (forr == 4) { var avg = Queryable.Average(param1f.AsQueryable()); Console.WriteLine("Average = " + avg); Console.ReadKey(); } int orr = 43; if (orr == 43) { double avg = Queryable.Average(param2f.AsQueryable()); Console.WriteLine("Average = " + avg); Console.ReadKey(); } Console.ReadKey(); }
public static void MinMaxAverage(int[] numbers) { // Given an integer array, say [1, 5, 10, -2], create a function that prints the maximum number in the array, // the minimum value in the array, and the average of the values in the array. int minValue = numbers.Min(); Console.WriteLine($"Min: {minValue}"); int maxValue = numbers.Max(); Console.WriteLine($"Max: {maxValue}"); double avg = Queryable.Average(numbers.AsQueryable()); Console.WriteLine($"Avg: {avg}"); }
public override string ToString() { var v = _lecturas.FindAll(p => p.Voltage > 0); var c = (_lecturas.FindAll(p => p.Current > 0)); var aP = _lecturas.FindAll(p => p.ActivePower > 0); var pcW = _lecturas.FindAll(p => p.Pv_watt > 0); var kw = _lecturas.LastOrDefault(p => p.Kw_day > 0) != null?_lecturas.LastOrDefault(p => p.Kw_day > 0).Kw_day : 0; var im = _lecturas.LastOrDefault(p => p.Import > 0) != null?_lecturas.LastOrDefault(p => p.Import > 0).Import : 0; var ex = _lecturas.LastOrDefault(p => p.Export > 0) != null?_lecturas.LastOrDefault(p => p.Export > 0).Export : 0; var tim = _lecturas.LastOrDefault(p => p.TotalImport > 0) != null?_lecturas.LastOrDefault(p => p.TotalImport > 0).TotalImport : 0; var tex = _lecturas.LastOrDefault(p => p.TotalExport > 0) != null?_lecturas.LastOrDefault(p => p.TotalExport > 0).TotalExport : 0; double avg_v = v.Count > 0 ? Queryable.Average((IQueryable <double>)v.Select(o => o.Voltage).AsQueryable()) : 0; double avg_c = c.Count > 0 ? Queryable.Average((IQueryable <double>)c.Select(o => o.Current).AsQueryable()) : 0; double avg_aP = aP.Count > 0 ? Queryable.Average((IQueryable <int>)aP.Select(o => o.ActivePower).AsQueryable()) : 0; double avg_pcW = pcW.Count > 0 ? Queryable.Average((IQueryable <double>)pcW.Select(o => o.Pv_watt).AsQueryable()) : 0; var fecha = DateTime.Now; if (!(fecha.Hour == 23 && fecha.Minute == 59)) { fecha = DateTime.Now.AddSeconds(1); } var s = string.Format("{0};{1:0.00};{2:0.00};{3:0.00};{4:0.00};{5:0.00};{6:0.00};{7:0.00};{8:0.00};{9:0.00}", fecha.ToString("yyyyMMdd"), avg_v, avg_c, avg_aP, avg_pcW, kw, im, ex, tim, tex); return(s); { } }
public List <Movie> JoinLists(HttpResponseMessage movies, HttpResponseMessage moviesDetailed) { var movieList = JsonSerializer.Deserialize <List <Movie> >(new StreamReader(movies.Content.ReadAsStream()).ReadToEnd()); var movieListDetailed = JsonSerializer.Deserialize <List <DetailedMovie> >(new StreamReader(moviesDetailed.Content.ReadAsStream()).ReadToEnd()); List <Movie> detailedMovieAvgCounted = new List <Movie>(); foreach (var movie in movieListDetailed) { double avg = Queryable.Average(movie.ratings.AsQueryable()); detailedMovieAvgCounted.Add(new Movie { title = movie.title, id = movie.id, rated = avg.ToString() }); } var joinedMovieList = movieList.Union(detailedMovieAvgCounted).ToList(); return(joinedMovieList); }
static int breakVigenereKeysize(byte[] ciphertext) { Dictionary <int, double> likelyKeys = new Dictionary <int, double>(); KeyValuePair <int, double> result = new KeyValuePair <int, double>(0, 100); // Try keysizes from 4 - 40 for (int keysize = 4; keysize < 41; keysize++) { int blocksInText = ciphertext.Length / keysize; double[] hammings = new double[blocksInText]; // Calculate hamming distance between every pair of blocks in the file // Then get the overall average. // More data = more accuracy. for (int index = 0; index < blocksInText - 1; index += 2) { byte[] block1 = new byte[keysize], block2 = new byte[keysize]; Array.Copy(ciphertext, index * keysize, block1, 0, keysize); Array.Copy(ciphertext, (index + 1) * keysize, block2, 0, keysize); hammings[index] = hammingDistance(block1, block2) / keysize; } double averageHamming = Queryable.Average(hammings.AsQueryable()); likelyKeys.Add(keysize, averageHamming); } // For debugging - gives an ordered list of keys var ordered = likelyKeys.OrderBy(x => x.Value); foreach (KeyValuePair <int, double> item in likelyKeys) { if (item.Value < result.Value) { result = item; } } Console.WriteLine("Guessed keysize: {0}", result); return(result.Key); }
public static double?CalculateFinalGrade(ICollection <GradedItem> gradedItems) { var gradedItemsList = gradedItems.ToList(); if (gradedItemsList.Count == 0) { return(null); } var grades = new double[gradedItems.Count]; for (int i = 0; i < gradedItemsList.Count; i++) { var gradedItem = gradedItemsList[i]; grades[i] = gradedItem.Grade; } return(Queryable.Average(grades.AsQueryable())); }
private double calcRecommendScore(List <bool> recommends) { List <int> recommendPool = new List <int>(); double recommendScore = 0.0; foreach (bool rating in recommends) { if (rating == true) { recommendPool.Add(1); } else { recommendPool.Add(0); } } recommendScore = Queryable.Average(recommendPool.ToArray().AsQueryable()); return(recommendScore); }
static void Main() { int idadeDani = 28; int idadePaulo = 29; int idadeJesus = 33; int[] arrayIdade = { idadeDani, idadePaulo, idadeJesus }; int mediaIdade = Media(arrayIdade); Console.WriteLine("Median by Function " + mediaIdade); mediaIdade = (int)Queryable.Average(arrayIdade.AsQueryable()); Console.WriteLine("Median by Linq " + mediaIdade); /* ERRO int pi = 3.14; */ double pi = 3.14; int piQuebrado = (int)pi; Console.WriteLine("piQuebrado = " + piQuebrado); }