Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (var db = new BioImisEntities())
- {
- var start = new DateTime(2017, 1, 1);
- var end = new DateTime(2017, 12, 31, 23, 59, 59);
- decimal totMeasures = 0;
- decimal totWeight = 0;
- var dataPerCustomer = db.CustomersPADailyDatas.Where(x => x.jrn_State == 0 && x.Date >= start && x.Date <= end).GroupBy(x => x.CustomerId);
- int a = 0;
- foreach (var customer in dataPerCustomer)
- {
- var firstMeasures = customer.OrderBy(x => x.Date);
- var lastMeasures = customer.OrderByDescending(x => x.Date);
- decimal sum = 0;
- decimal sumWeight = 0;
- if (firstMeasures.Any(x => x.Hips != 0))
- {
- var i = firstMeasures.SkipWhile(x => x.Hips == 0).FirstOrDefault().Hips;
- var f = lastMeasures.SkipWhile(x => x.Hips == 0).FirstOrDefault().Hips;
- sum += (i - f);
- }
- if (firstMeasures.Any(x => x.Knee != 0))
- {
- sum += firstMeasures.SkipWhile(x => x.Knee == 0).FirstOrDefault().Knee - lastMeasures.SkipWhile(x => x.Knee == 0).FirstOrDefault().Knee;
- }
- if (firstMeasures.Any(x => x.Neck != 0))
- {
- sum += firstMeasures.SkipWhile(x => x.Neck == 0).FirstOrDefault().Neck - lastMeasures.SkipWhile(x => x.Neck == 0).FirstOrDefault().Neck;
- }
- if (firstMeasures.Any(x => x.Thigh != 0))
- {
- sum += firstMeasures.SkipWhile(x => x.Thigh == 0).FirstOrDefault().Thigh - lastMeasures.SkipWhile(x => x.Thigh == 0).FirstOrDefault().Thigh;
- }
- if (firstMeasures.Any(x => x.Waistline != 0))
- {
- sum += firstMeasures.SkipWhile(x => x.Waistline == 0).FirstOrDefault().Waistline - lastMeasures.SkipWhile(x => x.Waistline == 0).FirstOrDefault().Waistline;
- }
- sumWeight += firstMeasures.SkipWhile(x => x.Weight == 0).FirstOrDefault().Weight - lastMeasures.SkipWhile(x => x.Weight == 0).FirstOrDefault().Weight;
- totMeasures += sum;
- totWeight += sumWeight;
- Console.WriteLine($"{++a}/{dataPerCustomer.Count()} done...");
- }
- Console.WriteLine($"CM persi nel 2017: {totMeasures}");
- Console.WriteLine($"KG persi nel 2017: {totWeight}");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement