Beispiel #1
0
        private void InitialiseBlobContainer()
        {
            var storageAccount = CloudStorageAccount.Parse(options.StorageConnectionString);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            container = blobClient.GetContainerReference(ContainerName);

            // Create the container if it doesn't already exist.
            container.CreateIfNotExists();

            // Get a reference to the JSON file.
            blockBlob = container.GetBlockBlobReference(SummaryEntityBlobName);

            if (blockBlob.Exists())
            {
                return;
            }
            // Create a new, empty weekday summary as the json blob does not exist.
            var summary = new WeekSummary();

            WriteSummary(summary);
        }
        private string SummariseDayHappinessRatings(WeekSummary summary)
        {
            var dayTotals = new Dictionary <DayOfWeek, int>();

            foreach (var day in summary)
            {
                if (day.HappinessScores.Count == 0)
                {
                    continue;
                }
                double runningTotal = 0;
                int    faceCount    = day.HappinessScores.Sum(h => h.Value);

                foreach (var happinessValue in day.HappinessScores)
                {
                    runningTotal += (happinessValue.Key + 1) * happinessValue.Value;
                }

                dayTotals.Add(day.DayOfWeek, (int)(runningTotal / faceCount));
            }
            if (dayTotals.Count == 0)
            {
                return("We don't have enough data to show which days are happiest, is the Azure blob storage connection string set?");
            }
            return(string.Join(",", dayTotals.OrderBy(t => t.Value).Select(t => $"{t.Key}: {t.Value}")));
        }
        private string[][] GetGrid(WeekSummary model)
        {
            if (model.Events.Display)
            {
                if (!model.Pluralsight.Display && !model.Blogs.Display)
                {
                    return(new string[][]
                    {
                        new string[] { "focus", "skills" },
                        new string[] { "title", "title" },
                        new string[] { "events", "events" },
                        new string[] { "footer", "footer" },
                        new string[] { "podcasts", "books" }
                    });
                }

                return(new string[][]
                {
                    new string[] { "focus", "skills", "books" },
                    new string[] { "title", "title", "title" },
                    new string[] { "events", "events", "events" },
                    new string[] { "footer", "footer", "footer" },
                    new string[] { "podcasts", "pluralsight", "pluralsight" },
                    new string[] { "podcasts", "blogs", "blogs" },
                });
            }

            if (!model.Pluralsight.Display && !model.Blogs.Display)
            {
                return(new string[][]
                {
                    new string[] { "focus", "skills" },
                    new string[] { "title", "title" },
                    new string[] { "podcasts", "books" },
                    new string[] { "footer", "footer" }
                });
            }

            return(new string[][]
            {
                new string[] { "focus", "skills", "books" },
                new string[] { "title", "title", "title" },
                new string[] { "podcasts", "pluralsight", "pluralsight" },
                new string[] { "podcasts", "blogs", "blogs" },
                new string[] { "footer", "footer", "footer" }
            });
        }
Beispiel #4
0
        private static void SetData(ListLogicalView weekView, MonthPlan plan)
        {
            var weekIndex = TimeHelper.CurrentWeekIndex;

            var weekSummaryList = new WeekSummaryList();

            weekSummaryList.AutoTreeIndexEnabled = false;

            //把 plan.TaskOrCategoryList 中的数据复制到 WeekSummaryList 中。
            foreach (TaskOrCategory category in plan.TaskOrCategoryList)
            {
                var categoryWeek = new WeekSummary();
                categoryWeek.IsCategory = true;
                categoryWeek.TreeIndex  = category.TreeIndex;
                categoryWeek.Name       = category.Name;
                categoryWeek.Content    = category.Content;
                categoryWeek.Id         = category.Id;
                categoryWeek.TreePId    = category.TreePId;
                weekSummaryList.Add(categoryWeek);

                foreach (TaskOrCategory task in category.TreeChildren)
                {
                    var taskWeek = new WeekSummary();
                    taskWeek.IsTask            = true;
                    taskWeek.TreeIndex         = task.TreeIndex;
                    taskWeek.Name              = task.Name;
                    taskWeek.Content           = task.Content;
                    taskWeek.ObjectiveName     = task.ObjectiveName;
                    taskWeek.Id                = task.Id;
                    taskWeek.TreePId           = task.TreePId;
                    taskWeek.MonthObjectiveNum = task.ObjectiveNum;
                    taskWeek.MonthCompletedNum = task.SumCompletedRO;

                    var weekCompletion = task.WeekCompletionList[weekIndex] as WeekCompletion;
                    taskWeek.WeekCompletion  = weekCompletion;
                    taskWeek.ObjectiveNum    = weekCompletion.ObjectiveNum;
                    taskWeek.NumCompleted    = weekCompletion.NumCompleted;
                    taskWeek.WeekSummaryNote = weekCompletion.Note;

                    categoryWeek.TreeChildren.Add(taskWeek);
                    weekSummaryList.Add(taskWeek);
                }
            }

            weekView.Data = weekSummaryList;
        }
    public WeekSummarySerialized(WeekSummary ws)
    {
        this.Asserts           = ws.Asserts;
        this.AssertsPercentage = ws.AssertsPercentage;
        this.Etapa             = ws.Etapa;
        this.EtapaChallenge    = ws.EtapaChallenge;
        this.Minigame          = ws.Minigame;
        this.TimesPlayed       = ws.TimesPlayed;
        this.TotalTime         = ws.TotalTime;
        this.Week = ws.Week;

        if (ws.School != null)
        {
            SchoolSerialized ss = new SchoolSerializedDAO().LoadByObjectId(ws.School.ObjectId);
            if (ss != null)
            {
                this.SchoolSerialized = ss;
            }
            else
            {
                //Debug.Log ("Serialized: There is no relationship saved");
            }
        }

        if (ws.Student != null)
        {
            StudentSerialized ss = new StudentSerializedDAO().LoadByObjectId(ws.Student.ObjectId);
            if (ss != null)
            {
                this.StudentSerialized = ss;
            }
            else
            {
                //Debug.Log ("Serialized: There is no relationship saved");
            }
        }
    }
Beispiel #6
0
        public List <WeekSummary> GetWeekSummaries(int week)
        {
            var summaries = new List <WeekSummary>();
            var users     = _mapper.Map <IEnumerable <User> >(_userRepository.GetAll().ToList());

            foreach (var user in users)
            {
                var  summary    = new WeekSummary(user, week);
                var  picks      = _gamePickRepository.GetByUserAndWeek(user.Id, week);
                bool madePick   = false;
                bool missedPick = false;

                foreach (var pick in picks)
                {
                    if (CorrectPick(pick.Pick, pick.Game))
                    {
                        summary.Score += pick.Wager;
                        summary.CorrectPicks++;
                    }

                    missedPick = pick.Pick == GameResult.NotPlayed ? true : missedPick;
                    madePick   = pick.Pick == GameResult.NotPlayed ? madePick : true;
                }

                summary.PickStatus = (madePick) ? (missedPick ? WeekPickStatus.PartiallyPicked :
                                                   WeekPickStatus.FullyPicked)
                                : WeekPickStatus.NotPicked;

                summaries.Add(summary);
            }

            HandleMissedWeek(summaries, week);

            SetBaseSummaryPlaces(summaries);

            return(summaries);
        }
        public IActionResult Weekly([FromServices] IActivityRepository repository, string year, string weekNumber)
        {
            var raw = repository.Weekly(year, weekNumber);

            var viewModel = new WeekSummary
            {
                Year        = raw.Year,
                WeekNumber  = raw.WeekNumber,
                Start       = raw.Start,
                End         = raw.End,
                PodCasts    = new ActivityLayout <Models.Activity.PodCastActivity>(raw.PodCasts, "podcasts", x => x != null && x.Categories != null && x.Categories.Count > 0),
                Skills      = new ActivityLayout <Models.Activity.SkillsActivity>(raw.Skills, "skills", x => x != null && x.Skills != null && x.Skills.Count > 0),
                Pluralsight = new ActivityLayout <Models.Activity.PluralsightActivity>(raw.Pluralsight, "pluralsight", x => x != null && x.Courses != null && x.Courses.Count > 0),
                Focus       = new ActivityLayout <Models.Activity.FocusActivity>(raw.Focus, "focus", x => x != null && x.Focus != null && x.Focus.Count > 0),
                //Clients = new ActivityLayout<Models.Activity.ClientActivity>(raw.Clients, "clients", x => x != null && x.Clients != null && x.Clients.Count > 0),
                Blogs  = new ActivityLayout <Models.Activity.BlogActivity>(raw.Blogs, "blogs", x => x != null && x.Blogs != null && x.Blogs.Count > 0),
                Events = new ActivityLayout <Models.Activity.EventActivity>(raw.Events, "events", x => x != null && x.Events != null && x.Events.Count > 0),
                Books  = new ActivityLayout <Models.Activity.BookActivity>(raw.Books, "books", x => x != null && x.Books != null && x.Books.Count > 0)
            };

            viewModel.Layout = GetGrid(viewModel);

            return(View("Weekly", viewModel));
        }
Beispiel #8
0
 private void WriteSummary(WeekSummary summary)
 {
     blockBlob.Properties.ContentType = "application/json";
     blockBlob.UploadText(JsonConvert.SerializeObject(summary));
 }
Beispiel #9
0
 public int IndexOf(WeekSummary entity)
 {
     return base.IndexOf(entity);
 }
Beispiel #10
0
 public void Add(WeekSummary entity)
 {
     base.Add(entity);
 }
Beispiel #11
0
 public bool Remove(WeekSummary entity)
 {
     return base.Remove(entity);
 }
Beispiel #12
0
 public void Insert(int index, WeekSummary entity)
 {
     base.Insert(index, entity);
 }
Beispiel #13
0
        private static void SetData(ListLogicalView weekView, MonthPlan plan)
        {
            var weekIndex = TimeHelper.CurrentWeekIndex;

            var weekSummaryList = new WeekSummaryList();
            weekSummaryList.AutoTreeIndexEnabled = false;

            //把 plan.TaskOrCategoryList 中的数据复制到 WeekSummaryList 中。
            foreach (TaskOrCategory category in plan.TaskOrCategoryList)
            {
                var categoryWeek = new WeekSummary();
                categoryWeek.IsCategory = true;
                categoryWeek.TreeIndex = category.TreeIndex;
                categoryWeek.Name = category.Name;
                categoryWeek.Content = category.Content;
                categoryWeek.Id = category.Id;
                categoryWeek.TreePId = category.TreePId;
                weekSummaryList.Add(categoryWeek);

                foreach (TaskOrCategory task in category.TreeChildren)
                {
                    var taskWeek = new WeekSummary();
                    taskWeek.IsTask = true;
                    taskWeek.TreeIndex = task.TreeIndex;
                    taskWeek.Name = task.Name;
                    taskWeek.Content = task.Content;
                    taskWeek.ObjectiveName = task.ObjectiveName;
                    taskWeek.Id = task.Id;
                    taskWeek.TreePId = task.TreePId;
                    taskWeek.MonthObjectiveNum = task.ObjectiveNum;
                    taskWeek.MonthCompletedNum = task.SumCompletedRO;

                    var weekCompletion = task.WeekCompletionList[weekIndex] as WeekCompletion;
                    taskWeek.WeekCompletion = weekCompletion;
                    taskWeek.ObjectiveNum = weekCompletion.ObjectiveNum;
                    taskWeek.NumCompleted = weekCompletion.NumCompleted;
                    taskWeek.WeekSummaryNote = weekCompletion.Note;

                    categoryWeek.TreeChildren.Add(taskWeek);
                    weekSummaryList.Add(taskWeek);
                }
            }

            weekView.Data = weekSummaryList;
        }
Beispiel #14
0
 private bool CanShow(WeekSummary entity)
 {
     return !entity.IsCompletedRO;
 }
Beispiel #15
0
        public HttpResponseMessage Get(string apiToken, string regularWorkingHoursString, string startDateString, string endDateString)
        {
            double   regularWorkingHours;
            DateTime startDate;
            DateTime endDate;

            try
            {
                regularWorkingHours = double.Parse(regularWorkingHoursString);
                startDate           = DateTime.ParseExact(startDateString, WebApiConfig.DateFormat, CultureInfo.InvariantCulture);
                endDate             = DateTime.ParseExact(endDateString, WebApiConfig.DateFormat, CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.PreconditionFailed,
                                                   "At least one of the passed parameters was not in the correct format!"));
            }

            Dictionary <DateTime, List <TimeEntry> > workTimeByDays;

            try
            {
                var timeService = new TimeEntryService(apiToken);
                workTimeByDays = timeService.List(new TimeEntryParams {
                    StartDate = startDate, EndDate = endDate.AddDays(1)
                })
                                 .GroupBy(h => DateTime.Parse(h.Start).Date)
                                 .OrderBy(d => d.Key)
                                 .ToDictionary(timeEntriesByDay => timeEntriesByDay.Key,
                                               timeEntriesByDay => timeEntriesByDay.ToList());
            }
            catch (WebException webEx)
            {
                var httpWebResponse = ((HttpWebResponse)webEx.Response);
                return(Request.CreateErrorResponse(HttpStatusCode.PreconditionFailed,
                                                   $"The toggl server (toggl.com) threw an exception ({(int) httpWebResponse.StatusCode}:" +
                                                   $" {httpWebResponse.StatusDescription}) - either your API token is wrong or the servers are down."));
            }

            double regularWorkDayInSeconds = (regularWorkingHours / 5.0 * 3600);
            var    togglTimeSummary        = new TogglTimeSummary();

            foreach (var daysByWeek in workTimeByDays.GroupBy(timeEntriesByDay => GetWeekGroupKey(timeEntriesByDay.Key),
                                                              timeEntriesByDay => new { Day = timeEntriesByDay.Key, TimeEntries = timeEntriesByDay.Value }))
            {
                var weekSummary = new WeekSummary(daysByWeek.Key, regularWorkDayInSeconds);

                foreach (var timeEntriesByDay in daysByWeek)
                {
                    var daySummary = new DaySummary(timeEntriesByDay.Day, weekSummary.IsRegularWorkDayLimitReached ? 0 : regularWorkDayInSeconds);

                    foreach (long timeEntry in timeEntriesByDay.TimeEntries
                             .Where(t => t.Duration.HasValue && t.Duration > 0)
                             .Select(t => (long)t.Duration))
                    {
                        daySummary.AddTimeEntry(timeEntry);
                    }

                    weekSummary.AddDay(daySummary);
                }

                togglTimeSummary.AddWeek(weekSummary);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, togglTimeSummary));
        }
Beispiel #16
0
 public bool Contains(WeekSummary entity)
 {
     return base.Contains(entity);
 }
Beispiel #17
0
 private bool CanShow(WeekSummary entity)
 {
     return(!entity.IsCompletedRO);
 }