Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1.   using (var db = new BioImisEntities())
  2.             {
  3.                 var start = new DateTime(2017, 1, 1);
  4.  
  5.                 var end = new DateTime(2017, 12, 31, 23, 59, 59);
  6.                 decimal totMeasures = 0;
  7.                 decimal totWeight = 0;
  8.                 var dataPerCustomer = db.CustomersPADailyDatas.Where(x => x.jrn_State == 0 && x.Date >= start && x.Date <= end).GroupBy(x => x.CustomerId);
  9.                 int a = 0;
  10.                 foreach (var customer in dataPerCustomer)
  11.                 {
  12.                     var firstMeasures = customer.OrderBy(x => x.Date);
  13.                     var lastMeasures = customer.OrderByDescending(x => x.Date);
  14.                     decimal sum = 0;
  15.                     decimal sumWeight = 0;
  16.                     if (firstMeasures.Any(x => x.Hips != 0))
  17.                     {
  18.                         var i = firstMeasures.SkipWhile(x => x.Hips == 0).FirstOrDefault().Hips;
  19.                         var f = lastMeasures.SkipWhile(x => x.Hips == 0).FirstOrDefault().Hips;
  20.                         sum += (i - f);
  21.                     }
  22.                     if (firstMeasures.Any(x => x.Knee != 0))
  23.                     {
  24.                         sum += firstMeasures.SkipWhile(x => x.Knee == 0).FirstOrDefault().Knee - lastMeasures.SkipWhile(x => x.Knee == 0).FirstOrDefault().Knee;
  25.                     }
  26.                     if (firstMeasures.Any(x => x.Neck != 0))
  27.                     {
  28.                         sum += firstMeasures.SkipWhile(x => x.Neck == 0).FirstOrDefault().Neck - lastMeasures.SkipWhile(x => x.Neck == 0).FirstOrDefault().Neck;
  29.                     }
  30.                     if (firstMeasures.Any(x => x.Thigh != 0))
  31.                     {
  32.                         sum += firstMeasures.SkipWhile(x => x.Thigh == 0).FirstOrDefault().Thigh - lastMeasures.SkipWhile(x => x.Thigh == 0).FirstOrDefault().Thigh;
  33.                     }
  34.                     if (firstMeasures.Any(x => x.Waistline != 0))
  35.                     {
  36.                         sum += firstMeasures.SkipWhile(x => x.Waistline == 0).FirstOrDefault().Waistline - lastMeasures.SkipWhile(x => x.Waistline == 0).FirstOrDefault().Waistline;
  37.                     }
  38.                     sumWeight += firstMeasures.SkipWhile(x => x.Weight == 0).FirstOrDefault().Weight - lastMeasures.SkipWhile(x => x.Weight == 0).FirstOrDefault().Weight;
  39.  
  40.                     totMeasures += sum;
  41.                     totWeight += sumWeight;
  42.                     Console.WriteLine($"{++a}/{dataPerCustomer.Count()} done...");
  43.                 }
  44.                 Console.WriteLine($"CM persi nel 2017: {totMeasures}");
  45.                 Console.WriteLine($"KG persi nel 2017: {totWeight}");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement