private async Task CalculaPoinsFitness(SqlConnection connection1, string iduser, DateTime dateIni, List <Activity> activities) { if (activities.Count() > 0) { ActivityFitness actFitness = new ActivityFitness(); int count = 0; while (count < activities.Count) { Activity act = activities[count]; DateTime endTime = act.start.AddSeconds(act.duration); count++; while (count < activities.Count) { if (activities[count].start > endTime) { break; } else if (activities[count].calories > act.calories) { act = activities[count]; endTime = act.start.AddSeconds(act.duration); } count++; } LeonAPICalculations.ValidicCategoryPoints categoryPoints = new LeonAPICalculations.ValidicCategoryPoints(); string name = GetActivityNameFitness(act.activity); var distance = act.distance * 0.000621371; var duration = act.duration / 60; var points = categoryPoints.GetFitnesPoints(name, duration, distance, act.calories); FillDataFitness(actFitness, name, act, points); } await UpdateFitness(connection1, iduser, dateIni, actFitness); await UpdateFitnessPoints(connection1, iduser, dateIni, actFitness); } }
private async Task UpdateFitnessPoints(SqlConnection connection1, string iduser, DateTime dateIni, ActivityFitness actFitness) { string strcommand = "UPDATE DailyDataPoints set running = @runningpoints, " + "weight = @weightpoints, cycling = @cyclingpoints, " + "swimming = @swimmingpoints, sport = @sportpoints, " + "yoga = @yogapoints, classes = @classespoints, " + "downhilski = @downhilskipoints, otherfitness = @fitnessotherOthersPoints " + "WHERE iduser = @iduser and datedone = @dateIni"; SqlCommand command1 = new SqlCommand(strcommand, connection1); SqlParameter parameter = new SqlParameter("@iduser", SqlDbType.VarChar); parameter.Value = iduser; command1.Parameters.Add(parameter); parameter = new SqlParameter("@dateIni", SqlDbType.Date); parameter.Value = dateIni.Year + "-" + dateIni.Month + "-" + dateIni.Day; command1.Parameters.Add(parameter); parameter = new SqlParameter("@runningpoints", SqlDbType.Decimal); parameter.Value = actFitness.runningpoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@weightpoints", SqlDbType.Decimal); parameter.Value = actFitness.weightpoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@cyclingpoints", SqlDbType.Decimal); parameter.Value = actFitness.cyclingpoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@swimmingpoints", SqlDbType.Decimal); parameter.Value = actFitness.swimmingpoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@sportpoints", SqlDbType.Decimal); parameter.Value = actFitness.sportpoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@yogapoints", SqlDbType.Decimal); parameter.Value = actFitness.yogapoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@classespoints", SqlDbType.Decimal); parameter.Value = actFitness.classespoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@downhilskipoints", SqlDbType.Decimal); parameter.Value = actFitness.downhilskipoints; command1.Parameters.Add(parameter); parameter = new SqlParameter("@fitnessotherOthersPoints", SqlDbType.Decimal); parameter.Value = actFitness.fitnessotherOthersPoints; command1.Parameters.Add(parameter); await command1.ExecuteNonQueryAsync(); }
private async Task UpdateFitness(SqlConnection connection1, string iduser, DateTime dateIni, ActivityFitness actFitness) { string strcommand = "UPDATE DailyData set " + "runningdistance = @runningdistance, runningduration = @runningduration, runningcalories = @runningcalories, " + "weightdistance = @weightdistance, weightduration = @weightduration, weightcalories = @weightcalories, " + "cyclingdistance = @cyclingdistance, cyclingduration = @cyclingduration, cyclingcalories = @cyclingcalories, " + "swimmingdistance = @swimmingdistance, swimmingduration = @swimmingduration, swimmingcalories = @swimmingcalories, " + "sportdistance = @sportdistance, sportduration = @sportduration, sportcalories = @sportcalories, " + "yogadistance = @yogadistance, yogaduration = @yogaduration, yogacalories = @yogacalories, " + "classesdistance = @classesdistance, classesduration = @classesduration, classescalories = @classescalories, " + "downhilskidistance = @downhilskidistance, downhilskiduration = @downhilskiduration, downhilskicalories = @downhilskicalories, " + "fitnessotherdistance = @fitnessotherdistance, fitnessotherduration = @fitnessotherduration, fitnessothercalories = @fitnessothercalories " + "WHERE iduser = @iduser and datedone = @dateIni"; SqlCommand command1 = new SqlCommand(strcommand, connection1); SqlParameter parameter = new SqlParameter("@iduser", SqlDbType.VarChar); parameter.Value = iduser; command1.Parameters.Add(parameter); parameter = new SqlParameter("@dateIni", SqlDbType.Date); parameter.Value = dateIni.Year + "-" + dateIni.Month + "-" + dateIni.Day; command1.Parameters.Add(parameter); parameter = new SqlParameter("@runningdistance", SqlDbType.Decimal); parameter.Value = actFitness.runningdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@runningduration", SqlDbType.Decimal); parameter.Value = actFitness.runningduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@runningcalories", SqlDbType.Decimal); parameter.Value = actFitness.runningcalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@weightdistance", SqlDbType.Decimal); parameter.Value = actFitness.weightdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@weightduration", SqlDbType.Decimal); parameter.Value = actFitness.weightduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@weightcalories", SqlDbType.Decimal); parameter.Value = actFitness.weightcalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@cyclingdistance", SqlDbType.Decimal); parameter.Value = actFitness.cyclingdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@cyclingduration", SqlDbType.Decimal); parameter.Value = actFitness.cyclingduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@cyclingcalories", SqlDbType.Decimal); parameter.Value = actFitness.cyclingcalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@swimmingdistance", SqlDbType.Decimal); parameter.Value = actFitness.swimmingdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@swimmingduration", SqlDbType.Decimal); parameter.Value = actFitness.swimmingduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@swimmingcalories", SqlDbType.Decimal); parameter.Value = actFitness.swimmingcalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@sportdistance", SqlDbType.Decimal); parameter.Value = actFitness.sportdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@sportduration", SqlDbType.Decimal); parameter.Value = actFitness.sportduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@sportcalories", SqlDbType.Decimal); parameter.Value = actFitness.sportcalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@yogadistance", SqlDbType.Decimal); parameter.Value = actFitness.yogadistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@yogaduration", SqlDbType.Decimal); parameter.Value = actFitness.yogaduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@yogacalories", SqlDbType.Decimal); parameter.Value = actFitness.yogacalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@classesdistance", SqlDbType.Decimal); parameter.Value = actFitness.classesdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@classesduration", SqlDbType.Decimal); parameter.Value = actFitness.classesduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@classescalories", SqlDbType.Decimal); parameter.Value = actFitness.classescalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@downhilskidistance", SqlDbType.Decimal); parameter.Value = actFitness.downhilskidistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@downhilskiduration", SqlDbType.Decimal); parameter.Value = actFitness.swimmingduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@downhilskicalories", SqlDbType.Decimal); parameter.Value = actFitness.downhilskicalories; command1.Parameters.Add(parameter); parameter = new SqlParameter("@fitnessotherdistance", SqlDbType.Decimal); parameter.Value = actFitness.fitnessotherdistance; command1.Parameters.Add(parameter); parameter = new SqlParameter("@fitnessotherduration", SqlDbType.Decimal); parameter.Value = actFitness.fitnessotherduration; command1.Parameters.Add(parameter); parameter = new SqlParameter("@fitnessothercalories", SqlDbType.Decimal); parameter.Value = actFitness.fitnessothercalories; command1.Parameters.Add(parameter); await command1.ExecuteNonQueryAsync(); }
private string FillDataFitness(ActivityFitness actFitness, string activity, Activity act, int points) { if (activity.Contains("running")) { actFitness.runningdistance += act.distance; actFitness.runningduration += act.duration; actFitness.runningcalories += act.calories; actFitness.runningpoints += points; } else if (activity.Contains("weight")) { actFitness.weightdistance += act.distance; actFitness.weightduration += act.duration; actFitness.weightcalories += act.calories; actFitness.weightpoints += points; } else if (activity.Contains("cycling")) { actFitness.cyclingdistance += act.distance; actFitness.cyclingduration += act.duration; actFitness.cyclingcalories += act.calories; actFitness.cyclingpoints += points; } else if (activity.Contains("swimming")) { actFitness.swimmingdistance += act.distance; actFitness.swimmingduration += act.duration; actFitness.swimmingcalories += act.calories; actFitness.swimmingpoints += points; } else if (activity.Contains("sport")) { actFitness.sportdistance += act.distance; actFitness.sportduration += act.duration; actFitness.sportcalories += act.calories; actFitness.sportpoints += points; } else if (activity.Contains("yoga") || activity.ToLower().Contains("pilates")) { actFitness.yogadistance += act.distance; actFitness.yogaduration += act.duration; actFitness.yogacalories += act.calories; actFitness.yogapoints += points; } else if (activity.Contains("classes") || activity.ToLower().Contains("pt training")) { actFitness.classesdistance += act.distance; actFitness.classesduration += act.duration; actFitness.classescalories += act.calories; actFitness.classespoints += points; } else if (activity.Contains("downhill ski")) { actFitness.downhilskidistance += act.distance; actFitness.downhilskiduration += act.duration; actFitness.downhilskicalories += act.calories; actFitness.downhilskipoints += points; } else { actFitness.fitnessotherdistance += act.distance; actFitness.fitnessotherduration += act.duration; actFitness.fitnessothercalories += act.calories; actFitness.fitnessotherOthersPoints += points; } return(activity); }