public string goalSetting(string userid) { GenericAzureStorageTableEntity <stepData> step = new GenericAzureStorageTableEntity <stepData>("stepTable"); //Find this week data List <stepData> thisweek = getWeeklyEntitiesByUserID(userid); if (thisweek.Count > 0) { //Update entity foreach (stepData data in thisweek) { try { var entity = new DynamicTableEntity(data.PartitionKey, data.RowKey); entity.ETag = "*"; entity.Properties.Add("calorieGoal", new EntityProperty(400)); entity.Properties.Add("stepsGoal", new EntityProperty(10000)); var mergeOperation = TableOperation.Merge(entity); step.cloudtable.Execute(mergeOperation); } catch (Exception e) { return(e.Message); } } } return("OK"); }
//GetWeeklyCalories //Search by user ID => MacAddress public double[] GetWeeklyCalories() { GenericAzureStorageTableEntity <stepData> step = new GenericAzureStorageTableEntity <stepData>("stepTable"); try { //List<stepData> datas = step.ReadAll(macAddress); //GetTheWeekConstraint DateTime current = DateTime.Now; int dayofweek = (int)current.DayOfWeek; DateTime startTime = current.AddDays(-7).AddDays(dayofweek); List <stepData> datas = step.ReadWeeklyData(macAddress, startTime); double[] calories = new double[datas.Count]; string timezone = datas[0].timezone; //source data timezone int count = 0; foreach (stepData data in datas) { calories[count] = data.calories; count++; } return(calories); } catch (Exception e) { double[] exception = new double[1]; exception[0] = 10.01; return(exception); } }
public string goalsetting(string goalobj) { GenericAzureStorageTableEntity <stepData> step = new GenericAzureStorageTableEntity <stepData>("stepTable"); Dictionary <string, string> goalentity = JsonConvert.DeserializeObject <Dictionary <string, string> >(goalobj); string userid = goalentity.Where(x => x.Key == "userid").First().Value; int stepsgoal = int.Parse(goalentity.Where(x => x.Key == "stepsgoal").First().Value); int calgoal = int.Parse(goalentity.Where(x => x.Key == "calgoals").First().Value); List <stepData> thisweek = getWeeklyEntitiesByUserID(userid); if (thisweek.Count > 0) { //Update entity foreach (stepData data in thisweek) { try { var entity = new DynamicTableEntity(data.PartitionKey, data.RowKey); entity.ETag = "*"; entity.Properties.Add("calorieGoal", new EntityProperty(calgoal)); entity.Properties.Add("stepsGoal", new EntityProperty(stepsgoal)); var mergeOperation = TableOperation.Merge(entity); step.cloudtable.Execute(mergeOperation); } catch (Exception e) { return(e.Message); } } return("ok"); } else { return(string.Empty); } }
public List <stepData> getWeeklyEntitiesByUserID(string userid) { GenericAzureStorageTableEntity <stepData> step = new GenericAzureStorageTableEntity <stepData>("stepTable"); Dictionary <string, DateTime> startdate = rctrl.getStartDateUTC(userid); DateTime nowUTC = DateTime.UtcNow; TimeSpan timespan = nowUTC.Subtract(startdate.Where(x => x.Key == "UTC").First().Value); int weeks = timespan.Days / 7; DateTime localdate = startdate.Where(x => x.Key == "Local").First().Value; List <stepData> entities = step.ReadAll(macAddress); List <stepData> thisweek = new List <stepData>(); foreach (stepData data in entities) { String[] rowkeys = data.RowKey.ToString().Split('-'); //userid-week-number-time //int week = int.Parse(rowkeys[1]); string userID = rowkeys[0].ToString(); TimeSpan tspan = data.timestamp.Subtract(localdate); int week = tspan.Days / 7; if (userid == userID) { if (week == weeks) { thisweek.Add(data); } } } return(thisweek); }