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); }
/// ----------------------------------------------------------------------------- /// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <remarks> /// </remarks> /// <history> /// </history> /// ----------------------------------------------------------------------------- protected void Page_Load(System.Object sender, System.EventArgs e) { base.Page_Load(sender, e); try { ServiceReference service = new ServiceReference("~/DesktopModules/ATI_Base/resources/services/StreamService.asmx"); service.InlineScript = true; ScriptManager.GetCurrent(Page).Services.Add(service); imgAd.Src = ResolveUrl("/portals/0/images/adTastyPaleo.jpg"); imgCheck.ImageUrl = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/iCheck.png"); if (!Page.IsPostBack && !Page.IsCallback) { baseUrl = ResolveUrl("~/"); long wId = 0; if (HttpContext.Current.Items["w"] != null) { wId = Convert.ToInt64(HttpContext.Current.Items["w"]); } else if (Request["w"] != null) { wId = Convert.ToInt64(Request["w"]); } // Are we viewing a specific workout ? if (wId > 0) { divMainLinks.Visible = true; atiProfile.Visible = false; hiddenWorkoutKey.Value = "" + wId; aqufitEntities entities = new aqufitEntities(); WOD wod = entities.WODs.Include("WODType").Include("WODSets").Include("WODSets.WODExercises").Include("WODSets.WODExercises.Exercise").FirstOrDefault(w => w.Id == wId); if( base.UserSettings != null && wod.Standard == 0){ User2WODFav fav = entities.User2WODFav.FirstOrDefault(mr => mr.WOD.Id == wod.Id && mr.UserSetting.Id == UserSettings.Id); bAddWorkout.Visible = fav == null; bRemoveWorkout.Visible = fav != null; } lWorkoutTitle.Text = wod.Name; // lWorkoutDescription.Text = wod.Description; // constructWorkoutInfo(wod); lWorkoutInfo.Text = wod.Description; if (wod.Standard > 0) { imgCrossFit.Visible = true; imgCrossFit.Src = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/xfit.png"); atiProfileImg.Visible = false; } else { atiProfileImg.Settings = entities.UserSettings.FirstOrDefault(us => us.Id == wod.UserSettingsKey); } atiWorkoutPanel.Visible = false; atiWorkoutViewer.Visible = true; // Get the leader board IQueryable<Workout> stream = entities.UserStreamSet.OfType<Workout>().Where(w => w.WOD.Id == wId); long typeId = entities.WODs.Where(w => w.Id == wId).Select(w => w.WODType.Id).FirstOrDefault(); switch (typeId) { case (long)Affine.Utils.WorkoutUtil.WodType.AMRAP: case (long)Affine.Utils.WorkoutUtil.WodType.SCORE: atiScoreRangePanel.Visible = true; stream = stream.OrderByDescending(w => w.Score); break; case (long)Affine.Utils.WorkoutUtil.WodType.MAX_WEIGHT: atiMaxRangePanel.Visible = true; atiMaxWeightUnitsFirst.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS); atiMaxWeightUnitsFirst.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_KG); atiMaxWeightUnitsFirst.Selected = WeightUnits; atiMaxWeightUnitsLast.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS); atiMaxWeightUnitsLast.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_KG); atiMaxWeightUnitsLast.Selected = WeightUnits; stream = stream.OrderByDescending(w => w.Max); break; case (long)Affine.Utils.WorkoutUtil.WodType.TIMED: atiTimeSpanePanel.Visible = true; stream = stream.OrderBy(w => w.Duration); break; default: stream = stream.OrderByDescending(w => w.TimeStamp); break; } string js = string.Empty; atiShareLink.ShareLink = "http://" + Request.Url.Host + "/workout/" + wod.Id; atiShareLink.ShareTitle = "FlexFWD.com crossfit WOD " + wod.Name; workoutTabTitle.Text = " " + (string.IsNullOrWhiteSpace(wod.Name) ? "Untitled" : wod.Name) + " "; Affine.WebService.StreamService ss = new WebService.StreamService(); string jsonEveryone = ss.getStreamDataForWOD(wod.Id, -1, 0, 15, true, true, -1, -1, -1); string jsonYou = string.Empty; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".fromStreamData('" + jsonEveryone + "'); "; if (base.UserSettings != null) { hlLogWorkout.HRef = baseUrl + UserSettings.UserName + "?w=" + wId; hlWorkouts.HRef = baseUrl + UserSettings.UserName + "/workout-history"; jsonYou = ss.getStreamDataForWOD(wod.Id, base.UserSettings.Id, 0, 10, true, true, -1, -1, -1); js += "Aqufit.Page.atiYouStreamScript.generateStreamDom('" + jsonYou + "');"; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".fromYourStreamData('" + jsonYou + "'); "; // TODO: this could be improved on... Workout thisWod = entities.UserStreamSet.OfType<Workout>().FirstOrDefault(w => w.UserSetting.Id == UserSettings.Id && w.WOD.Id == wId); if (thisWod != null) { // graphs of this wod hlGraph.HRef = ResolveUrl("~/") + UserSettings.UserName + "/workout/" + thisWod.Id; } else { // just grab any workout then.. Workout any = entities.UserStreamSet.OfType<Workout>().OrderByDescending( w => w.Id ).FirstOrDefault(w => w.UserSetting.Id == UserSettings.Id); if (any != null) { hlGraph.HRef = ResolveUrl("~/") + UserSettings.UserName + "/workout/" + any.Id; } else { // no workouts ??? say what.. slack man :) hide graph hlGraph.Visible = false; } } } else { hlGraph.HRef = ResolveUrl("~/Login"); hlLogWorkout.HRef = hlGraph.HRef; hlWorkouts.HRef = hlGraph.HRef; atiPanelYourProgress.Visible = false; } hlCreateWOD.HRef = baseUrl + "Profile/WorkoutBuilder"; hlMyWorkouts.HRef = baseUrl + "Profile/MyWorkouts"; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".drawChart(); "; ScriptManager.RegisterStartupScript(this, Page.GetType(), "SimilarRouteList", "$(function(){ " + js + " Aqufit.Page.atiEveryoneStreamScript.generateStreamDom('" + jsonEveryone + "'); });", true); YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); //order results by the number of views (most viewed first) query.OrderBy = "viewCount"; query.NumberToRetrieve = 3; query.SafeSearch = YouTubeQuery.SafeSearchValues.Moderate; YouTubeRequestSettings settings = new YouTubeRequestSettings(ConfigurationManager.AppSettings["youtubeApp"], ConfigurationManager.AppSettings["youtubeKey"]); YouTubeRequest request = new YouTubeRequest(settings); const int NUM_ENTRIES = 50; IList<Video> videos = new List<Video>(); IList<Video> groupVideo = new List<Video>(); // first try to find videos with regard to users group Feed<Video> videoFeed = null; if (this.UserSettings != null) { long[] groupIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == UserSettings.Id || f.DestUserSettingKey == UserSettings.Id) && f.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(f => f.SrcUserSettingKey == UserSettings.Id ? f.DestUserSettingKey : f.SrcUserSettingKey).ToArray(); Group business = entities.UserSettings.OfType<Group>().Where(Utils.Linq.LinqUtils.BuildContainsExpression<Group, long>(us => us.Id, groupIds)).FirstOrDefault(g => g.GroupType.Id == 1); if (business != null) { // TODO: need the business name... query.Query = business.UserName; } else { UserSettings creator = entities.UserSettings.FirstOrDefault(u => u.Id == wod.UserSettingsKey); if (creator is Group ) { // TODO: need the business name... query.Query = creator.UserFirstName + " " + creator.UserLastName; } else { query.Query = UserSettings.UserFirstName + " " + UserSettings.UserLastName; } } videoFeed = request.Get<Video>(query); foreach (Video v in videoFeed.Entries) { groupVideo.Add(v); } } if (videos.Count < NUM_ENTRIES) { // now try the crossfit WOD name query.NumberToRetrieve = NUM_ENTRIES - videos.Count; query.Query = "crossfit wod " + wod.Name; videoFeed = request.Get<Video>(query); foreach (Video v in videoFeed.Entries) { videos.Add(v); } if (videos.Count < NUM_ENTRIES) { // this is last resort .. just get videos about crossfit... query.NumberToRetrieve = NUM_ENTRIES - videos.Count; query.Query = "crossfit wod"; videoFeed = request.Get<Video>(query); foreach (Video v in videoFeed.Entries) { videos.Add(v); } } } const int TAKE = 3; if (videos.Count > TAKE) { Random random = new Random((int)DateTime.Now.Ticks); int rand = random.Next(videos.Count - TAKE); videos = videos.Skip(rand).Take(TAKE).ToList(); if( groupVideo.Count > 0 ){ // always replace one of the main videos with a gorup one.. (if possible) rand = random.Next(groupVideo.Count - 1); videos[0] = groupVideo[rand]; } atiYoutubeThumbList.VideoFeed = videos; } else { atiVideoPanel.Visible = false; } } else { atiVideoPanel.Visible = false; atiPanelQuickView.Visible = false; hlGraph.Visible = false; aqufitEntities entities = new aqufitEntities(); var exerciseArray = entities.Exercises.OrderBy( x => x.Name ).Select( x => new{ Text = x.Name, Value = x.Id } ).ToArray(); RadListBoxExcerciseSource.DataSource = exerciseArray; RadListBoxExcerciseSource.DataBind(); string order = orderDate.Checked ? "date" : "popular"; if (Settings["Configure"] != null && Convert.ToString(Settings["Configure"]).Equals("ConfigureMyWorkouts")) { this.IsMyWorkouts = true; atiProfile.ProfileSettings = base.UserSettings; atiProfile.IsOwner = true; atiProfile.IsSmall = true; atiWorkoutPanel.Visible = true; workoutTabTitle.Text = "My Workouts"; liMyWorkouts.Visible = false; liFindWorkout.Visible = true; WebService.StreamService streamService = new WebService.StreamService(); string json = streamService.GetWorkouts(base.UserSettings.Id, 0, 30, order, null); ScriptManager.RegisterStartupScript(this, Page.GetType(), "WorkoutList", "$(function(){ Aqufit.Page.atiWorkoutListScript.isMyRoutes = true; Aqufit.Page.atiWorkoutListScript.generateStreamDom('" + json + "'); });", true); } else { this.IsMyWorkouts = false; atiProfile.Visible = false; workoutTabTitle.Text = "Workouts"; atiWorkoutPanel.Visible = true; atiWorkoutViewer.Visible = false; WebService.StreamService streamService = new WebService.StreamService(); string json = streamService.GetWorkouts(-1, 0, 30, order, null); ScriptManager.RegisterStartupScript(this, Page.GetType(), "WorkoutList2", "$(function(){ Aqufit.Page.atiWorkoutListScript.generateStreamDom('" + json + "'); });", true); } } } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
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); }
/// ----------------------------------------------------------------------------- /// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <remarks> /// </remarks> /// <history> /// </history> /// ----------------------------------------------------------------------------- protected void Page_Load(System.Object sender, System.EventArgs e) { base.Page_Load(sender, e); try { ServiceReference service = new ServiceReference("~/DesktopModules/ATI_Base/resources/services/StreamService.asmx"); service.InlineScript = true; ScriptManager.GetCurrent(Page).Services.Add(service); imgAd.Src = ResolveUrl("/portals/0/images/adTastyPaleo.jpg"); imgCheck.ImageUrl = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/iCheck.png"); if (!Page.IsPostBack && !Page.IsCallback) { baseUrl = ResolveUrl("~/"); long wId = 0; if (HttpContext.Current.Items["w"] != null) { wId = Convert.ToInt64(HttpContext.Current.Items["w"]); } else if (Request["w"] != null) { wId = Convert.ToInt64(Request["w"]); } // Are we viewing a specific workout ? if (wId > 0) { divMainLinks.Visible = true; atiProfile.Visible = false; hiddenWorkoutKey.Value = "" + wId; aqufitEntities entities = new aqufitEntities(); WOD wod = entities.WODs.Include("WODType").Include("WODSets").Include("WODSets.WODExercises").Include("WODSets.WODExercises.Exercise").FirstOrDefault(w => w.Id == wId); if (base.UserSettings != null && wod.Standard == 0) { User2WODFav fav = entities.User2WODFav.FirstOrDefault(mr => mr.WOD.Id == wod.Id && mr.UserSetting.Id == UserSettings.Id); bAddWorkout.Visible = fav == null; bRemoveWorkout.Visible = fav != null; } lWorkoutTitle.Text = wod.Name; // lWorkoutDescription.Text = wod.Description; // constructWorkoutInfo(wod); lWorkoutInfo.Text = wod.Description; if (wod.Standard > 0) { imgCrossFit.Visible = true; imgCrossFit.Src = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/xfit.png"); atiProfileImg.Visible = false; } else { atiProfileImg.Settings = entities.UserSettings.FirstOrDefault(us => us.Id == wod.UserSettingsKey); } atiWorkoutPanel.Visible = false; atiWorkoutViewer.Visible = true; // Get the leader board IQueryable <Workout> stream = entities.UserStreamSet.OfType <Workout>().Where(w => w.WOD.Id == wId); long typeId = entities.WODs.Where(w => w.Id == wId).Select(w => w.WODType.Id).FirstOrDefault(); switch (typeId) { case (long)Affine.Utils.WorkoutUtil.WodType.AMRAP: case (long)Affine.Utils.WorkoutUtil.WodType.SCORE: atiScoreRangePanel.Visible = true; stream = stream.OrderByDescending(w => w.Score); break; case (long)Affine.Utils.WorkoutUtil.WodType.MAX_WEIGHT: atiMaxRangePanel.Visible = true; atiMaxWeightUnitsFirst.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS); atiMaxWeightUnitsFirst.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_KG); atiMaxWeightUnitsFirst.Selected = WeightUnits; atiMaxWeightUnitsLast.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_LBS); atiMaxWeightUnitsLast.UnitList.Add(Affine.Utils.UnitsUtil.MeasureUnit.UNIT_KG); atiMaxWeightUnitsLast.Selected = WeightUnits; stream = stream.OrderByDescending(w => w.Max); break; case (long)Affine.Utils.WorkoutUtil.WodType.TIMED: atiTimeSpanePanel.Visible = true; stream = stream.OrderBy(w => w.Duration); break; default: stream = stream.OrderByDescending(w => w.TimeStamp); break; } string js = string.Empty; atiShareLink.ShareLink = "http://" + Request.Url.Host + "/workout/" + wod.Id; atiShareLink.ShareTitle = "FlexFWD.com crossfit WOD " + wod.Name; workoutTabTitle.Text = " " + (string.IsNullOrWhiteSpace(wod.Name) ? "Untitled" : wod.Name) + " "; Affine.WebService.StreamService ss = new WebService.StreamService(); string jsonEveryone = ss.getStreamDataForWOD(wod.Id, -1, 0, 15, true, true, -1, -1, -1); string jsonYou = string.Empty; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".fromStreamData('" + jsonEveryone + "'); "; if (base.UserSettings != null) { hlLogWorkout.HRef = baseUrl + UserSettings.UserName + "?w=" + wId; hlWorkouts.HRef = baseUrl + UserSettings.UserName + "/workout-history"; jsonYou = ss.getStreamDataForWOD(wod.Id, base.UserSettings.Id, 0, 10, true, true, -1, -1, -1); js += "Aqufit.Page.atiYouStreamScript.generateStreamDom('" + jsonYou + "');"; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".fromYourStreamData('" + jsonYou + "'); "; // TODO: this could be improved on... Workout thisWod = entities.UserStreamSet.OfType <Workout>().FirstOrDefault(w => w.UserSetting.Id == UserSettings.Id && w.WOD.Id == wId); if (thisWod != null) { // graphs of this wod hlGraph.HRef = ResolveUrl("~/") + UserSettings.UserName + "/workout/" + thisWod.Id; } else { // just grab any workout then.. Workout any = entities.UserStreamSet.OfType <Workout>().OrderByDescending(w => w.Id).FirstOrDefault(w => w.UserSetting.Id == UserSettings.Id); if (any != null) { hlGraph.HRef = ResolveUrl("~/") + UserSettings.UserName + "/workout/" + any.Id; } else { // no workouts ??? say what.. slack man :) hide graph hlGraph.Visible = false; } } } else { hlGraph.HRef = ResolveUrl("~/Login"); hlLogWorkout.HRef = hlGraph.HRef; hlWorkouts.HRef = hlGraph.HRef; atiPanelYourProgress.Visible = false; } hlCreateWOD.HRef = baseUrl + "Profile/WorkoutBuilder"; hlMyWorkouts.HRef = baseUrl + "Profile/MyWorkouts"; js += " Aqufit.Page." + atiWorkoutHighChart.ID + ".drawChart(); "; ScriptManager.RegisterStartupScript(this, Page.GetType(), "SimilarRouteList", "$(function(){ " + js + " Aqufit.Page.atiEveryoneStreamScript.generateStreamDom('" + jsonEveryone + "'); });", true); YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); //order results by the number of views (most viewed first) query.OrderBy = "viewCount"; query.NumberToRetrieve = 3; query.SafeSearch = YouTubeQuery.SafeSearchValues.Moderate; YouTubeRequestSettings settings = new YouTubeRequestSettings(ConfigurationManager.AppSettings["youtubeApp"], ConfigurationManager.AppSettings["youtubeKey"]); YouTubeRequest request = new YouTubeRequest(settings); const int NUM_ENTRIES = 50; IList <Video> videos = new List <Video>(); IList <Video> groupVideo = new List <Video>(); // first try to find videos with regard to users group Feed <Video> videoFeed = null; if (this.UserSettings != null) { long[] groupIds = entities.UserFriends.Where(f => (f.SrcUserSettingKey == UserSettings.Id || f.DestUserSettingKey == UserSettings.Id) && f.Relationship >= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER).Select(f => f.SrcUserSettingKey == UserSettings.Id ? f.DestUserSettingKey : f.SrcUserSettingKey).ToArray(); Group business = entities.UserSettings.OfType <Group>().Where(Utils.Linq.LinqUtils.BuildContainsExpression <Group, long>(us => us.Id, groupIds)).FirstOrDefault(g => g.GroupType.Id == 1); if (business != null) { // TODO: need the business name... query.Query = business.UserName; } else { UserSettings creator = entities.UserSettings.FirstOrDefault(u => u.Id == wod.UserSettingsKey); if (creator is Group) { // TODO: need the business name... query.Query = creator.UserFirstName + " " + creator.UserLastName; } else { query.Query = UserSettings.UserFirstName + " " + UserSettings.UserLastName; } } videoFeed = request.Get <Video>(query); foreach (Video v in videoFeed.Entries) { groupVideo.Add(v); } } if (videos.Count < NUM_ENTRIES) { // now try the crossfit WOD name query.NumberToRetrieve = NUM_ENTRIES - videos.Count; query.Query = "crossfit wod " + wod.Name; videoFeed = request.Get <Video>(query); foreach (Video v in videoFeed.Entries) { videos.Add(v); } if (videos.Count < NUM_ENTRIES) { // this is last resort .. just get videos about crossfit... query.NumberToRetrieve = NUM_ENTRIES - videos.Count; query.Query = "crossfit wod"; videoFeed = request.Get <Video>(query); foreach (Video v in videoFeed.Entries) { videos.Add(v); } } } const int TAKE = 3; if (videos.Count > TAKE) { Random random = new Random((int)DateTime.Now.Ticks); int rand = random.Next(videos.Count - TAKE); videos = videos.Skip(rand).Take(TAKE).ToList(); if (groupVideo.Count > 0) { // always replace one of the main videos with a gorup one.. (if possible) rand = random.Next(groupVideo.Count - 1); videos[0] = groupVideo[rand]; } atiYoutubeThumbList.VideoFeed = videos; } else { atiVideoPanel.Visible = false; } } else { atiVideoPanel.Visible = false; atiPanelQuickView.Visible = false; hlGraph.Visible = false; aqufitEntities entities = new aqufitEntities(); var exerciseArray = entities.Exercises.OrderBy(x => x.Name).Select(x => new{ Text = x.Name, Value = x.Id }).ToArray(); RadListBoxExcerciseSource.DataSource = exerciseArray; RadListBoxExcerciseSource.DataBind(); string order = orderDate.Checked ? "date" : "popular"; if (Settings["Configure"] != null && Convert.ToString(Settings["Configure"]).Equals("ConfigureMyWorkouts")) { this.IsMyWorkouts = true; atiProfile.ProfileSettings = base.UserSettings; atiProfile.IsOwner = true; atiProfile.IsSmall = true; atiWorkoutPanel.Visible = true; workoutTabTitle.Text = "My Workouts"; liMyWorkouts.Visible = false; liFindWorkout.Visible = true; WebService.StreamService streamService = new WebService.StreamService(); string json = streamService.GetWorkouts(base.UserSettings.Id, 0, 30, order, null); ScriptManager.RegisterStartupScript(this, Page.GetType(), "WorkoutList", "$(function(){ Aqufit.Page.atiWorkoutListScript.isMyRoutes = true; Aqufit.Page.atiWorkoutListScript.generateStreamDom('" + json + "'); });", true); } else { this.IsMyWorkouts = false; atiProfile.Visible = false; workoutTabTitle.Text = "Workouts"; atiWorkoutPanel.Visible = true; atiWorkoutViewer.Visible = false; WebService.StreamService streamService = new WebService.StreamService(); string json = streamService.GetWorkouts(-1, 0, 30, order, null); ScriptManager.RegisterStartupScript(this, Page.GetType(), "WorkoutList2", "$(function(){ Aqufit.Page.atiWorkoutListScript.generateStreamDom('" + json + "'); });", true); } } } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }