private static long GetSpeedInBytes(IGrouping <long, KeyValuePair <long, long> > measurements, int useMiliseconds = 0)
    {
        long time            = useMiliseconds == 0 ? measurements.Last().Key - measurements.First().Key : useMiliseconds;
        long downloadedBytes = (measurements.Last().Value - measurements.First().Value);

        return(downloadedBytes / (time / 1000));
    }
    private static double GetSpeedInKBs(IGrouping <long, KeyValuePair <long, long> > measurements, int useMiliseconds = 0)
    {
        long   time          = useMiliseconds == 0 ? measurements.Last().Key - measurements.First().Key : useMiliseconds;
        double downloadedKBs = (measurements.Last().Value - measurements.First().Value) / (double)Constants.Kilobyte;

        return(downloadedKBs / (time / 1000d));
    }
        private ActionDTO SimplifyOperations(IGrouping <int, ActionDTO> g)
        {
            ActionDTO result;

            if (g.Any(a => a.ActionType == ActionType.Delete && g.Key > 0))
            {
                result = new ActionDTO {
                    Id = g.Key, ActionType = ActionType.Delete
                }
            }
            ;
            else if (g.Any(a => a.ActionType == ActionType.Add && g.Key < 0))
            {
                var last = g.LastOrDefault(a => a.ActionType == ActionType.Modify);
                result = new ActionDTO {
                    Id = g.Key, ActionType = ActionType.Add, Text = last?.Text, Date = last?.Date
                };
            }
            else if (g.Key > 0)
            {
                var last = g.Last(a => a.ActionType == ActionType.Modify);
                result = new ActionDTO {
                    Id = g.Key, ActionType = ActionType.Modify, Text = last.Text, Date = last.Date
                };
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            return(result);
        }
示例#4
0
        public static bool IsMessageGroupWhole(IGrouping <string, ClockworkMessageStorage> messageGroup)
        {
            var lastMessage = messageGroup.Last();

            var length = int.Parse(lastMessage.MessageLength) + 1;

            return(messageGroup.Count() == length && lastMessage.RowKey.Equals(lastMessage.MessageLength, StringComparison.InvariantCultureIgnoreCase));
        }
示例#5
0
        private string CompereValues(IGrouping <string, KeyValuePair <string, object> > groupedData)
        {
            var columnName    = groupedData.Key;
            var tableOneValue = groupedData.First().Value.ToString();
            var tableTwoValue = groupedData.Last().Value.ToString();

            if (tableOneValue.Equals(tableTwoValue, StringComparison.InvariantCultureIgnoreCase))
            {
                return(String.Empty);
            }

            return($"{columnName} has changed from {tableOneValue} to {tableTwoValue}");
        }
示例#6
0
 /// <summary>
 /// Decides whether our daily worktime is inconclusive, was done on weekend, was overtime or undertime.
 /// </summary>
 /// <param name="workDayRecords"></param>
 /// <param name="workTime"></param>
 /// <returns></returns>
 public WorkTimeClassifier ClassifyWorkTime(IGrouping <DateTime, InputRecord> workDayRecords, TimeSpan workTime)
 {
     if (workDayRecords.Last().Event)
     {
         return(WorkTimeClassifier.Inconclusive);
     }
     if (workDayRecords.Key.DayOfWeek == DayOfWeek.Saturday || workDayRecords.Key.DayOfWeek == DayOfWeek.Sunday)
     {
         return(WorkTimeClassifier.Weekend);
     }
     if (workTime > _config.GetSection("Overtime").GetValue <TimeSpan>("timespan"))
     {
         return(WorkTimeClassifier.Overtime);
     }
     if (workTime < _config.GetSection("Undertime").GetValue <TimeSpan>("timespan"))
     {
         return(WorkTimeClassifier.Undertime);
     }
     return(WorkTimeClassifier.Normal);
 }
示例#7
0
        public static CoapFlowRecord GetFlow(IGrouping <string, IPacketRecord> arg)
        {
            var first   = arg.First() as CoapPacketRecord;
            var last    = arg.Last();
            var flowKey = FlowKey.Parse(arg.Key);

            return(new CoapFlowRecord
            {
                StartMsec = first.TimeEpoch,
                EndMsec = last.TimeEpoch,
                SrcAddr = flowKey.IpSrc,
                SrcPort = flowKey.SrcPort,
                DstAddr = flowKey.IpDst,
                DstPort = flowKey.DstPort,
                CoapCode = first.CoapCode,
                CoapType = first.CoapType,
                CoapUriPath = first.CoapUriPath,
                FlowOctets = arg.Sum(x => x.PayloadLength),
                FlowPackets = arg.Count()
            });
        }
示例#8
0
 private static double CalculateReturn(IGrouping <string, Price> grouped)
 {
     return(Math.Round(((grouped.Last().Close - grouped.First().Open) / grouped.First().Open) * 100, 2));
 }
示例#9
0
        public EmbedBuilder CreateDetailedCommandInfoEmbed([NotNull] IGrouping <string, CommandInfo> commandGroup)
        {
            var eb = _feedback.CreateEmbedBase();

            var relevantAliases = commandGroup.SelectMany(c => c.Aliases).Distinct()
                                  .Skip(1)
                                  .Where(a => a.StartsWith(commandGroup.First().Module.Aliases.First()))
                                  .ToList();

            var prefix = relevantAliases.Count > 1
                ? "as well as"
                : "or";

            var commandExtraAliases = relevantAliases.Any()
                ? $"({prefix} {relevantAliases.Humanize("or")})"
                : string.Empty;

            eb.WithTitle($"{commandGroup.Key} {commandExtraAliases}");

            eb.WithDescription
            (
                "All the variants of the command are shown below. Text in italics after a variant are parameters, and" +
                " are listed in more detail below the command itself.\n" +
                "\n" +
                "Parameters inside [brackets] are optional, and can be omitted.\n" +
                "\u200b"
            );

            foreach (var variant in commandGroup)
            {
                eb.AddField($"{variant.GetFullCommand()} {BuildParameterList(variant)}", variant.Summary);

                var parameterList = BuildDetailedParameterList(variant).ToList();
                if (parameterList.Any())
                {
                    eb.AddField("Parameters", string.Join(", \n", parameterList));
                }

                var contexts = variant.Preconditions
                               .Where(a => a is RequireContextAttribute)
                               .Cast <RequireContextAttribute>()
                               .SingleOrDefault()?.Contexts;

                if (!(contexts is null))
                {
                    var separateContexts = contexts.ToString().Split(',');
                    separateContexts = separateContexts.Select(c => c.Pluralize()).ToArray();

                    var restrictions = $"*Can only be used in {separateContexts.Humanize()}.*"
                                       .Transform(To.SentenceCase);

                    eb.AddField("Restrictions", restrictions);
                }

                if (variant != commandGroup.Last())
                {
                    var previousField = eb.Fields.Last();

                    // Add a spacer
                    previousField.WithValue($"{previousField.Value}\n\u200b");
                }
            }

            return(eb);
        }
示例#10
0
 /// <summary>
 /// Calculates daily work time.
 /// </summary>
 /// <param name="workDayRecords"></param>
 /// <returns></returns>
 public TimeSpan CalculateWorkTime(IGrouping <DateTime, InputRecord> workDayRecords)
 {
     return(workDayRecords.Last().Date - workDayRecords.First().Date);
 }
示例#11
0
 private static RequestsPatchRequestDailyData AuthoritativeValue(
     IGrouping <LocalDate, RequestsPatchRequestDailyData> dailyRequests) => dailyRequests.Last();
 public static double CalculateProfitPercentage(this IGrouping <string, Price> groupedPrice) =>
 Math.Round(((groupedPrice.Last().Close - groupedPrice.First().Open) / groupedPrice.First().Open) * 100, 2);
示例#13
0
        public static ChatThreadViewModel FromDb(IGrouping <int, Chat> thread, string userId, int studentId)
        {
            ChatThreadViewModel model = new ChatThreadViewModel()
            {
                Id      = thread.Last().Id,
                Title   = thread.Last().Title,
                AddedAt = thread.Last().AddedAt.ToString("dd.MM.yyyy HH:mm:ss")
            };

            if (!string.IsNullOrEmpty(userId))
            {
                model.IsRead = thread.Any(t => t.ReceiverUserId == userId) ? thread.OrderBy(t => t.AddedAt).Last(t => t.ReceiverUserId == userId).IsRead : true;

                if (thread.Last().SenderUserId == userId)
                {
                    model.Author = thread.Last().ReceiverUser != null?thread.Last().ReceiverUser.FirstName + " " + thread.Last().ReceiverUser.LastName : thread.Last().ReceiverStudent.FirstName + " " + thread.Last().ReceiverStudent.LastName;
                }
                else if (thread.Last().ReceiverUserId == userId)
                {
                    model.Author = thread.Last().SenderUser != null?thread.Last().SenderUser.FirstName + " " + thread.Last().SenderUser.LastName : thread.Last().SenderStudent.FirstName + " " + thread.Last().SenderStudent.LastName;
                }
            }

            if (studentId != 0)
            {
                model.IsRead = thread.Any(t => t.ReceiverStudentId == studentId) ? thread.OrderBy(t => t.AddedAt).Last(t => t.ReceiverStudentId == studentId).IsRead : true;

                if (thread.Last().SenderStudentId == studentId)
                {
                    model.Author = thread.Last().ReceiverStudent != null?thread.Last().ReceiverStudent.FirstName + " " + thread.Last().ReceiverStudent.LastName : thread.Last().ReceiverUser.FirstName + " " + thread.Last().ReceiverUser.LastName;
                }
                else if (thread.Last().ReceiverStudentId == studentId)
                {
                    model.Author = thread.Last().SenderStudent != null?thread.Last().SenderStudent.FirstName + " " + thread.Last().SenderStudent.LastName : thread.Last().SenderUser.FirstName + " " + thread.Last().SenderUser.LastName;
                }
            }

            return(model);
        }