//$response[] = array($i, $name, null, '<img src="images/'. $filename . (file_exists('images/' . $filename . '.jpg') ? '.jpg' : '.png') .'" /> ' . $name); protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; IList <object> json = new List <object>(); json.Add(new { Id = 0, Name = "", Type = 1 }); try { if (!string.IsNullOrWhiteSpace(Request.Form["u"])) { aqufitEntities entities = new aqufitEntities(); long uid = Convert.ToInt64(Request.Form["u"]); Guid token = Guid.Parse(Request.Form["t"]); User user = entities.UserSettings.OfType <User>().FirstOrDefault(u => u.Id == uid && u.Guid == token); DateTime date = Convert.ToDateTime(Request.Form["d"]); string search = Request.Form["s"]; if (string.IsNullOrWhiteSpace(search) && user.MainGroupKey.HasValue) { WODSchedule schedule = entities.WODSchedules.Include("WOD").Include("WOD.WODType").FirstOrDefault(s => s.UserSetting.Id == user.MainGroupKey.Value && s.Date == date); if (schedule != null) { json.RemoveAt(0); json.Add(new { Id = schedule.WOD.Id, Name = schedule.WOD.Name, Type = schedule.WOD.WODType.Id }); } } else { search = search.ToLower(); IQueryable <WOD> wods = entities.User2WODFav.Where(w => w.UserSetting.Id == user.Id).Select(w => w.WOD); wods = wods.Union <WOD>(entities.WODs.Where(w => w.Standard > 0)); wods.Select(w => w.WODType).ToArray(); // hydrate WODTypes wods = wods.Where(w => w.Name.ToLower().Contains(search)).OrderBy(w => w.Name).Take(10); json = wods.Select(w => new { Id = w.Id, Name = w.Name, Type = w.WODType.Id }).ToArray(); } } } catch (Exception ex) { json.RemoveAt(0); json.Add(new { WorkoutId = 0, Name = ex.Message }); } Response.Write(serializer.Serialize(json)); Response.Flush(); Response.End(); }
private void LoadChartData() { System.Web.Script.Serialization.JavaScriptSerializer jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); // need a list of people in the group aqufitEntities entities = new aqufitEntities(); long[] memberIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == GroupSettings.Id || f.DestUserSettingKey == GroupSettings.Id) && f.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER ).Select(f => f.SrcUserSettingKey == GroupSettings.Id ? f.DestUserSettingKey : f.SrcUserSettingKey).ToArray(); // How many members are there in the group.. this will determin how far back in time we will look for workouts int numMembers = memberIds.Length; // For now we will always look over the last 7 days.. DateTime today = DateTime.Today; DateTime past = today.AddDays(-7); IQueryable<UserStream> streamSet = entities.UserStreamSet .Include("UserSetting").Include("WOD") .Where(w => w.Date.CompareTo(past) > 0) .Where(LinqUtils.BuildContainsExpression<UserStream, long>(w => w.UserSetting.Id, memberIds)); // TODO: we need to get a better idea of who is going to need hydrating before we do it. streamSet.Select(w => w.UserSetting).ToArray(); // THIS IS BAD.. Hydrating a lot of users profiles.. IQueryable<IGrouping<long?, Workout>> groupWorkouts = streamSet.OfType<Workout>().GroupBy(w => w.WorkoutTypeKey); // Lets find out what this group is all about ... IE what type of workouts dominate long ukey = -1; long key = -1; int usize = 0; int size = 0; foreach (IGrouping<long?, Workout> g in groupWorkouts) { UserSettings us = g.Select(w => w.UserSetting).First(); // first see if we can find anything that the current user is in if (UserSettings != null && g.FirstOrDefault(w => (long)w.UserSettingReference.EntityKey.EntityKeyValues[0].Value == UserSettings.Id) != null) { int c = g.Count(); if ( c > size) { ukey = g.Key.Value; usize = c; } }else{ int c = g.Count(); if ( c > size) { key = g.Key.Value; size = c; } } } if( ukey > 0 ){ // we found something that this user is in key = ukey; size = usize; } IGrouping<long?, Workout> workouts = groupWorkouts.Where(g => g.Key == key).FirstOrDefault(); Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance; Affine.Data.json.LeaderBoardWOD[] leaderBoard = dataMan.CalculatCrossFitLeaderBoard(base.GroupSettings.Id); atiLeaderBoard.Visible = true; WODSchedule scheduled = entities.WODSchedules.Include("WOD").Where(w => w.UserSetting.Id == GroupSettings.Id).OrderByDescending(w => w.Id).FirstOrDefault(); litTodaysWOD.Text = "<h3>Last Scheduled Workout:"; if (scheduled != null) { WOD wod = scheduled.WOD; litTodaysWOD.Text += " <a style=\"font-size: 16px; color: #0095cd; font-weight: bold;\" href=\"/workouts/" + wod.Id + "\">" + wod.Name + "</a></h3>"; Affine.WebService.StreamService ss = new WebService.StreamService(); string jsonEveryone = ss.getStreamDataForWOD(wod.Id, -1, 0, 25, true, true, -1, -1, -1); string jsonYou = string.Empty; string js = string.Empty; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".fromStreamData('" + jsonEveryone + "'); "; if (base.UserSettings != null) { jsonYou = ss.getStreamDataForWOD(wod.Id, base.UserSettings.Id, 0, 10, true, true, -1, -1, -1); js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".fromYourStreamData('" + jsonYou + "'); "; } js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".drawChart(); "; RadAjaxManager1.ResponseScripts.Add(" $(function(){ Aqufit.Page." + atiLeaderBoard.ID + ".loadLeaderBoardFromJson('" + jsSerializer.Serialize(leaderBoard) + "'); " + js + " });"); } else { litTodaysWOD.Text += " <em>Unavailble</em></h3>"; atiWorkoutHighChart.Visible = false; } // so now KEY is the most (type) of workout // There are now a couple special cases... (crossfit workouts) /* if (key == (int)Utils.WorkoutUtil.WorkoutType.CROSSFIT) { Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance; Affine.Data.json.LeaderBoardWOD[] females = dataMan.CalculatCrossFitLeaderBoard(base.GroupSettings.Id, "F"); Affine.Data.json.LeaderBoardWOD[] males = dataMan.CalculatCrossFitLeaderBoard(base.GroupSettings.Id, "M"); atiLeaderBoardMale.Visible = true; atiLeaderBoardMale.LeaderWODList = males; atiLeaderBoardFemale.Visible = true; atiLeaderBoardFemale.LeaderWODList = females; } else { if (workouts != null) { // TODO: now for some reason we can not hydrate the "UserSettings" so we need to get them now long[] ids = workouts.Select(w => (long)w.UserSettingReference.EntityKey.EntityKeyValues[0].Value).ToArray(); // for now the other types of workout are just a quick grab... } } */ // ScriptManager.RegisterStartupScript(this, Page.GetType(), "wt", "alert('" + jsSerializer.Serialize( title ) + "');", true); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack && !Page.IsCallback && this.ProfileSettings != null) { atiProfileImage.Settings = ProfileSettings; atiProfileImage.Small = this.IsSmall; urlBase = ResolveUrl("~/"); hlUserStats.HRef = urlBase + ProfileSettings.UserName + "/achievements"; divAddTo.Visible = true; atiProfileLinks.ProfileSettings = this.ProfileSettings; atiProfileLinks.IsOwner = this.IsOwner; atiProfileLinks.IsFriend = this.IsFriend; atiProfileLinks.Mode = this.Mode; atiProfileSuggest.ProfileSettings = this.ProfileSettings; if (this.IsOwner) { bCompareTo.Visible = false; atiProfileImage.IsOwner = true; atiWebLinksList.IsOwner = true; divAddTo.Visible = false; atiFriendsPhotos.FriendListLink = ResolveUrl("~/" + ProfileSettings.UserName + "/Friends"); } else { atiProfileImage.IsOwner = false; atiFriendsPhotos.FriendListLink = "javascript: Aqufit.Windows.WatchList.open();"; aCompareTo.HRef = urlBase + "compare/" + ProfileSettings.UserName; bCompareTo.Visible = ShowCompareButton; } litAchievements.Text = "Achievements"; // TODO: take this out of the control.. ( prolly put it in the pagebase .. have a setup ) aqufitEntities entities = new aqufitEntities(); if (this.Mode == Affine.Utils.ConstsUtil.ProfileMode.NORMAL) { long[] friendIds = null; if (this.MainGroup != null) { litMainGroup.Text = "<a style=\"display: block; padding-top: 10px; font-weight:bold; font-size: 13px;\" href=\"/group/" + this.MainGroup.UserName + "\">" + this.MainGroup.UserName + "</a>"; } else { litMainGroup.Visible = false; } // settup the users web links atiWebLinksList.ProfileSettings = ProfileSettings; if (this.ProfileSettings is Group) { bCompareTo.Visible = false; litMainGroup.Visible = false; divAddTo.Visible = false; hlUserStats.HRef = ResolveUrl("~/") + ProfileSettings.UserName + "/achievements"; lAthleteTerm.Text = "<span>Members</span>"; atiFriendsPhotos.FriendTerm = "Member"; atiFriendsPhotos.FriendTermPlural = "Members"; atiFriendsPhotos.FriendListLink = "javascript: Aqufit.Windows.WatchList.open();"; // TODO: cache this grabbing of the friend ids from the stream service friendIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == ProfileSettings.Id || f.DestUserSettingKey == ProfileSettings.Id) && (f.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER)).Select(f => (f.SrcUserSettingKey == this.ProfileSettings.Id ? f.DestUserSettingKey : f.SrcUserSettingKey)).ToArray(); // TODO: we only want the best times / scores ect.. ( Take this out of the control as well ) WODSchedule lastWOD = entities.WODSchedules.Include("WOD").Include("WOD.WODType").Where(w => w.Date.CompareTo(DateTime.Now) < 0).OrderByDescending(w => w.Date).FirstOrDefault(); if (lastWOD != null) { litAchievements.Text = lastWOD.WOD.Name; IQueryable <Workout> crossfitWorkouts = entities.UserStreamSet.Include("UserSetting").Include("WOD").OfType <Workout>().Where(w => w.WOD.Id == lastWOD.WOD.Id); int numDistinct = crossfitWorkouts.Count(); const int MAX_DISPLAY = 15; IQueryable <Workout> wodsToDisplay = null; if (numDistinct > MAX_DISPLAY) { Random rand = new Random((int)DateTime.Now.Millisecond); int skip = rand.Next(numDistinct - MAX_DISPLAY); wodsToDisplay = crossfitWorkouts.OrderByDescending(w => w.Id).Skip(skip).Take(MAX_DISPLAY); } else { wodsToDisplay = crossfitWorkouts.OrderByDescending(w => w.Id).Take(MAX_DISPLAY); } Workout[] workoutArray = wodsToDisplay.ToArray(); IList <DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem> cfTotals = new List <DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem>(); // links are like "workout/187" string baseUrl = ResolveUrl("~"); if (lastWOD.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.TIMED) { cfTotals = workoutArray.Select(w => new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = w.UserSetting.UserName, Total = Affine.Utils.UnitsUtil.durationToTimeString(Convert.ToInt64(w.Duration)), Link = baseUrl + w.UserSetting.UserName }).ToList(); } else if (lastWOD.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.SCORE || lastWOD.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.AMRAP) { cfTotals = workoutArray.Select(w => new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = w.UserSetting.UserName, Total = Convert.ToString(w.Score), Link = baseUrl + w.UserSetting.UserName }).ToList(); } else if (lastWOD.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.MAX_WEIGHT) { cfTotals = workoutArray.Select(w => new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = w.UserSetting.UserName, Total = "" + Affine.Utils.UnitsUtil.systemDefaultToUnits(w.Max.Value, Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS), Link = baseUrl + w.UserSetting.UserName }).ToList(); } // TODO: we need the link (?? are we going to goto stats page.. or to the workout stream view) nvgCrossfit.Totals = cfTotals; } } else { string baseUrl = ResolveUrl("~") + "workout/"; // TODO: cache this grabbing of the friend ids from the stream service friendIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == ProfileSettings.Id || f.DestUserSettingKey == ProfileSettings.Id) && (f.Relationship == (int)Affine.Utils.ConstsUtil.Relationships.FRIEND)).Select(f => (f.SrcUserSettingKey == this.ProfileSettings.Id ? f.DestUserSettingKey : f.SrcUserSettingKey)).ToArray(); lAthleteTerm.Text = "<span>Athletes</span>"; // TODO: we only want the best times / scores ect.. ( Take this out of the control as well ) IQueryable <Workout> crossfitWorkouts = entities.UserStreamSet.OfType <Workout>().Include("WOD").Where(w => w.UserSetting.Id == ProfileSettings.Id && w.WorkoutTypeKey == (int)Affine.Utils.WorkoutUtil.WorkoutType.CROSSFIT && w.IsBest == true); int numDistinct = crossfitWorkouts.Select(w => w.WOD).Count(); const int MAX_DISPLAY = 10; IQueryable <Workout> wodsToDisplay = null; if (numDistinct > MAX_DISPLAY) { Random rand = new Random((int)DateTime.Now.Millisecond); int skip = rand.Next(numDistinct - MAX_DISPLAY); wodsToDisplay = crossfitWorkouts.OrderByDescending(w => w.Id).Skip(skip).Take(MAX_DISPLAY); } else { wodsToDisplay = crossfitWorkouts.OrderByDescending(w => w.Id).Take(MAX_DISPLAY); } // We need to split up into WOD types now... Workout[] timedWods = wodsToDisplay.Where(w => w.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.TIMED).ToArray(); IList <DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem> cfTotals = timedWods.Select(w => new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = w.Title, Total = Affine.Utils.UnitsUtil.durationToTimeString(Convert.ToInt64(w.Duration)), Link = baseUrl + w.WOD.Id }).ToList(); // Now all the scored ones... Workout[] scoredWods = wodsToDisplay.Where(w => w.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.SCORE).ToArray(); cfTotals = cfTotals.Concat(scoredWods.Select(w => new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = w.Title, Total = Convert.ToString(w.Score), Link = baseUrl + w.WOD.Id }).ToList()).ToList(); // Now all the max ones... Workout[] maxWods = wodsToDisplay.Where(w => w.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.MAX_WEIGHT).ToArray(); cfTotals = cfTotals.Concat(maxWods.Select(w => new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = w.Title, Total = Affine.Utils.UnitsUtil.systemDefaultToUnits(w.Max.Value, Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS) + " " + Affine.Utils.UnitsUtil.unitToStringName(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS), Link = baseUrl + w.WOD.Id }).ToList()).ToList(); // TODO: we need the link (?? are we going to goto stats page.. or to the workout stream view) nvgCrossfit.Totals = cfTotals; } IQueryable <Affine.Data.User> friends = entities.UserSettings.OfType <User>().Where(Affine.Utils.Linq.LinqUtils.BuildContainsExpression <User, long>(s => s.Id, friendIds)).OrderBy(s => s.Id); int fcount = friends.Count(); UserSettings[] firendSettings = null; if (fcount > 6) { Random rand = new Random((int)DateTime.Now.Millisecond); int skip = rand.Next(fcount - 6); firendSettings = friends.Skip(skip).Take(6).ToArray(); } else { firendSettings = friends.Take(6).ToArray(); } atiFriendsPhotos.FriendKeyList = firendSettings; atiFriendsPhotos.User = ProfileSettings; atiFriendsPhotos.FriendCount = fcount; // atiSendMessage.UserSettings = firendSettings; } else if (this.Mode == Affine.Utils.ConstsUtil.ProfileMode.BIO) { pAchievements.Visible = false; pWebLinks.Visible = false; pFriends.Visible = false; bCompareTo.Visible = false; if (this.IsOwner) { pAchievements.Visible = false; } pBodyComp.Visible = true; pTrainingHistory.Visible = true; BodyComposition bc = entities.BodyComposition.FirstOrDefault(b => b.UserSetting.Id == ProfileSettings.Id); pBio.Visible = true; litBio.Text = "<p>No Info</p>"; litTrainingHistory.Text = "<p>No Info</p>"; string height = "Unknown"; string weight = "Unknown"; if (bc != null) { litBio.Text = "<p>" + bc.Bio + "</p>"; litTrainingHistory.Text = "<p>" + bc.Description + "</p>"; if (bc.Height.HasValue) { double inches = Affine.Utils.UnitsUtil.systemDefaultToUnits(bc.Height.Value, Affine.Utils.UnitsUtil.MeasureUnit.UNIT_INCHES); double feet = Math.Floor(inches / 12); inches = Math.Floor(inches % 12); height = feet + " feet " + inches + " inches"; } if (bc.Weight.HasValue) { double lbs = Affine.Utils.UnitsUtil.systemDefaultToUnits(bc.Weight.Value, Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS); weight = lbs + " " + Affine.Utils.UnitsUtil.unitToStringName(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS); } } IList <DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem> cfHeightWeight = new List <DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem>(); cfHeightWeight.Add(new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = "Height", Total = height }); cfHeightWeight.Add(new DesktopModules_ATI_Base_controls_ATI_NameValueGrid.TotalItem() { Name = "Weight", Total = weight }); nvgBodyComp.Totals = cfHeightWeight; } if (this.IsFriend) // You are viewing a friends profile... so should the "Send Message Button"; { divAddTo.Visible = false; } else { if (this.IsFollowing) { // We need to change the "following link" to a smaller "Send Friend Request" bAddTo.Visible = false; hlSendFriendRequest.Visible = true; } } } }