Beispiel #1
0
 public TextLog(string _content)
 {
     logType         = LogEnum.Error;
     timeGranularity = TimeGranularity.Daily;
     content         = _content;
     lastWriteTime   = DateTime.Now;
 }
Beispiel #2
0
        private PeriodCardsStatus generatePeriods(DateTime start, ref DateTime end, TimeGranularity granularity,
                                                  bool analysisExists, out PeriodCardsStatus lastPeriod, out Dictionary <DateTime, PeriodCardsStatus> result)
        {
            PeriodCardsStatus firstPeriod;
            PeriodCardsStatus period;

            if (analysisExists)
            {
                firstPeriod = _boardAnalysis.Periods.First();
                period      = _boardAnalysis.Periods.Last();
            }
            else
            {
                firstPeriod = new PeriodCardsStatus(_boardAnalysis, start, granularity);
                period      = firstPeriod;
            }
            result = new Dictionary <DateTime, PeriodCardsStatus> {
                { firstPeriod.Start, firstPeriod }
            };
            while (true)
            {
                period = (PeriodCardsStatus)period.Next();
                _boardAnalysis.Periods.Add(period);
                result.Add(period.Start, period);
                if (period.End < end)
                {
                    continue;
                }

                lastPeriod = period;
                end        = lastPeriod.End;
                break;
            }
            return(firstPeriod);
        }
Beispiel #3
0
 public TextLog(LogEnum _logType, TimeGranularity _timeGranularity, string _content)
 {
     logType         = _logType;
     timeGranularity = _timeGranularity;
     content         = _content;
     lastWriteTime   = DateTime.Now;
 }
        public Task <BetfairServerResponse <List <TimeRangeResult> > > ListTimeRanges(MarketFilter marketFilter, TimeGranularity timeGranularity)
        {
            var args = new Dictionary <string, object>();

            args[FILTER]      = marketFilter;
            args[GRANULARITY] = timeGranularity;
            return(networkClient.Invoke <List <TimeRangeResult> >(Endpoint.Betting, LIST_TIME_RANGES, args));
        }
Beispiel #5
0
 public RecencyBoostingQuery(LuceneQuery subQuery, string fieldName, TimeGranularity granularity, double alpha, double halfDecay)
     : base(subQuery)
 {
     _fieldName   = fieldName;
     _granularity = granularity;
     _alpha       = alpha;
     _halfDecay   = halfDecay;
 }
 public BoardAnalysisResult(string boardId, DateTime start, DateTime end, TimeGranularity timeGranularity)
 {
     Timestamp   = DateTime.Now;
     Start       = start;
     End         = end;
     Granularity = timeGranularity;
     BoardId     = boardId;
 }
Beispiel #7
0
 /// <summary>
 /// 自定义业务日志
 /// </summary>
 /// <param name="biz">业务标识,如:登录-Login</param>
 /// <param name="_content">内容</param>
 /// <param name="_timeGranularity">时间粒度</param>
 public TextLog(string biz, string _content, TimeGranularity _timeGranularity)
 {
     this.logType         = LogEnum.Customize;
     this.bizSign         = biz;
     this.timeGranularity = _timeGranularity;
     this.content         = _content;
     this.lastWriteTime   = DateTime.Now;
 }
Beispiel #8
0
 public RecencyScoreProvider(IndexReader indexReader, string fieldName, TimeGranularity granularity, double alpha, double halfDecay)
     : base(indexReader)
 {
     _alpha          = alpha;
     _halfDecay      = halfDecay;
     _lastUpdatedDay = FieldCache.__Fields.DEFAULT.getInts(indexReader, fieldName);
     _today          = DateTime.Now.ToFieldValue(granularity);
 }
Beispiel #9
0
 private static void statusOut(BoardAnalysisResult result, TimeGranularity gran)
 {
     Console.WriteLine($"{(gran != TimeGranularity.Month ? $"{gran};\t" : "")}Period;\tDoing;\tDone;\tOther;Still ongoing;");
     foreach (var p in result.Periods)
     {
         var w = gran != TimeGranularity.Month ? p.WeekNumber.ToString() : "";
         Console.WriteLine($"{(gran != TimeGranularity.Month ? $"{w};\t" : "")}{p.Start:yy-MM-dd};\t{p.Doing.Count};\t{p.Done.Count};\t{p.Other.Count};\t{p.StillOngoing.Count()}");
     }
 }
Beispiel #10
0
        public ChangePointDetectRequest(IEnumerable <TimeSeriesPoint> series, TimeGranularity granularity)
        {
            if (series == null)
            {
                throw new ArgumentNullException(nameof(series));
            }

            Series      = series.ToList();
            Granularity = granularity;
        }
        public static IQueryable <WorkLogGraphData> GroupWorkLogsByGranularity(this IQueryable <WorkLog> workLogs,
                                                                               TimeGranularity timeGranularity)
        {
            switch (timeGranularity)
            {
            case TimeGranularity.Day:
                return(workLogs.Select(wl => new
                {
                    CreatedDay = wl.CreatedDate.Date.Day,
                    CreatedMonth = wl.CreatedDate.Date.Month,
                    CreatedYear = wl.CreatedDate.Date.Year,
                    wl.Duration,
                    wl.Status
                }).GroupBy(wl => new { wl.CreatedYear, wl.CreatedMonth, wl.CreatedDay })
                       .Select(workLogGroup => new WorkLogGraphData
                {
                    Date = $"{workLogGroup.Key.CreatedYear:D4}" +
                           $"-{workLogGroup.Key.CreatedMonth:D2}" +
                           $"-{workLogGroup.Key.CreatedDay:D2}",
                    TotalHours = workLogGroup.Sum(wl => wl.Duration),
                    TotalApproved =
                        workLogGroup.Sum(wl => wl.Status == WorkLogStatus.Approved ? wl.Duration : 0),
                    TotalRejected =
                        workLogGroup.Sum(wl => wl.Status == WorkLogStatus.Rejected ? wl.Duration : 0),
                    TotalPending = workLogGroup.Sum(wl =>
                                                    wl.Status == WorkLogStatus.PendingApproval ? wl.Duration : 0)
                }));

            case TimeGranularity.Month:
                return(workLogs.Select(wl => new
                {
                    CreatedMonth = wl.CreatedDate.Date.Month,
                    CreatedYear = wl.CreatedDate.Date.Year,
                    wl.Duration,
                    wl.Status
                }).GroupBy(wl => new { wl.CreatedYear, wl.CreatedMonth })
                       .Select(workLogGroup => new WorkLogGraphData
                {
                    Date = $"{workLogGroup.Key.CreatedYear:D4}" +
                           $"-{workLogGroup.Key.CreatedMonth:D2}",
                    TotalHours = workLogGroup.Sum(wl => wl.Duration),
                    TotalApproved =
                        workLogGroup.Sum(wl => wl.Status == WorkLogStatus.Approved ? wl.Duration : 0),
                    TotalRejected =
                        workLogGroup.Sum(wl => wl.Status == WorkLogStatus.Rejected ? wl.Duration : 0),
                    TotalPending = workLogGroup.Sum(wl =>
                                                    wl.Status == WorkLogStatus.PendingApproval ? wl.Duration : 0)
                }));

            default:
                throw new ArgumentException("Wrong time granularity specified!");
            }
        }
Beispiel #12
0
        public static int ToFieldValue(this DateTime dateTime, TimeGranularity timeGranularity)
        {
            // Convert to number of <timegranularity> since 1 Jan 0001, 00:00:00

            switch (timeGranularity)
            {
            case TimeGranularity.Day:
                return((int)(dateTime.Ticks / 10000000 / 3600 / 24));

            case TimeGranularity.Hour:
                return((int)(dateTime.Ticks / 10000000 / 3600));

            case TimeGranularity.Minute:
                return((int)(dateTime.Ticks / 10000000 / 60));
            }

            throw new NotImplementedException();
        }
Beispiel #13
0
        public Period(DateTime start, TimeGranularity granularity)
        {
            Start = start;
            switch (granularity)
            {
            case TimeGranularity.Day:
                day(start);
                break;

            case TimeGranularity.Week:
                week(start);
                break;

            case TimeGranularity.Month:
                month(start);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(granularity), granularity, null);
            }
        }
Beispiel #14
0
        private bool tryLoadLastBoardAnalysis(string boardId, DateTime start, TimeGranularity granularity,
                                              out BoardAnalysisResult analysisResult)
        {
            analysisResult = null;
            var dir = new DirectoryInfo(RootFolder);

            if (!dir.Exists)
            {
                return(false);
            }

            var files = dir.GetFiles(getFilePattern(boardId, start, granularity)).ToList();

            if (files.Count == 0)
            {
                return(false);
            }

            files.Sort((f1, f2) => string.CompareOrdinal(f1.Name, f2.Name));
            var path = Path.Combine(RootFolder, files.Last().Name);

            return(tryLoadAndDeserializeBoardAnalysis(path, out analysisResult));
        }
Beispiel #15
0
 private string getFilePattern(string boardId, DateTime start, TimeGranularity granularity)
 {
     return($"{boardId}_{start:yy-MM-dd}_*_{granularity}.json");
 }
Beispiel #16
0
 private string getPath(string boardId, DateTime start, DateTime end, TimeGranularity granularity)
 {
     return(Path.Combine(RootFolder, $"{boardId}_{start:yy-MM-dd}_{end:yy-MM-dd}_{granularity}.json"));
 }
Beispiel #17
0
        public bool TryLoadBoardAnalysis(string boardId, DateTime start, DateTime end, TimeGranularity granularity,
                                         out BoardAnalysisResult analysisResult)
        {
            var path = getPath(boardId, start, end, granularity);

            return(File.Exists(path)
                ? tryLoadAndDeserializeBoardAnalysis(path, out analysisResult)
                : tryLoadLastBoardAnalysis(boardId, start, granularity, out analysisResult));
        }
 public LeadTimesResult(TimeGranularity granularity)
 {
     Granularity = granularity;
 }
Beispiel #19
0
 protected LuceneQuery GetRecencyBoostingQuery(LuceneQuery query, string fieldName, TimeGranularity granularity, double?alpha, double?halfDecay)
 {
     return((alpha == null || halfDecay == null)
         ? query
         : new RecencyBoostingQuery(query, fieldName, granularity, alpha.Value, halfDecay.Value));
 }
Beispiel #20
0
        public LeadTimesResult GetLeadTimes(DateTime?start = null, DateTime?end = null, TimeGranularity granularity = TimeGranularity.Week)
        {
            try
            {
                AnalyzePeriod(start, end, granularity);
                var totalCount           = 0;
                var accumulatedLeadTimes = TimeSpan.Zero;
                var result = new LeadTimesResult(granularity);
                foreach (var period in _boardAnalysis.Periods)
                {
                    var periodCount = 0;
                    var periodAccumulatedLeadTimes = TimeSpan.Zero;
                    foreach (var card in period.Done)
                    {
                        var leadTime = card.LeadTime;
                        if (card.LeadTime == TimeSpan.Zero)
                        {
                            continue;
                        }

                        accumulatedLeadTimes       += leadTime;
                        periodAccumulatedLeadTimes += leadTime;
                        ++totalCount;
                        ++periodCount;
                    }
                    if (periodCount == 0)
                    {
                        continue;
                    }
                    var periodLeadTimes = TimeSpan.FromSeconds(periodAccumulatedLeadTimes.TotalSeconds / periodCount);
                    result.AddPeriod(new LeadTimesResultPeriod(period, periodLeadTimes));
                }
                var overallLeadTimes = TimeSpan.FromSeconds(accumulatedLeadTimes.TotalSeconds / totalCount);
                result.LeadTimes = overallLeadTimes;
                return(result);
            }
            catch (Exception nisse)
            {
                throw;
            }
        }
 public static string ToSerialString(this TimeGranularity value) => value switch
 {
 public BetfairServerResponse<List<TimeRangeResult>> ListTimeRanges(MarketFilter marketFilter, TimeGranularity timeGranularity)
 {
     return client.ListTimeRanges(marketFilter, timeGranularity).Result;
 }
Beispiel #23
0
 protected virtual Period OnMakeNext(DateTime start, TimeGranularity granularity)
 {
     return(new Period(start, granularity));
 }
Beispiel #24
0
        public BoardAnalysisResult AnalyzePeriod(DateTime?start = null, DateTime?end = null, TimeGranularity granularity = TimeGranularity.Week)
        {
            const string DataFolder = ".\\data";

            ensureBoardIsSelected();
            ensureProgressListsAreSpecified();
            var startDate = start.HasValue && start.Value != default(DateTime) ? start.Value : projectStartTime();
            var endDate   = end.HasValue && end.Value != default(DateTime) ? end.Value : DateTime.Today.AddDays(1).Subtract(TimeSpan.FromSeconds(1));

            if (_boardAnalysis?.Equals(startDate, endDate, granularity) ?? false)
            {
                return(_boardAnalysis);
            }

            var db = new ApiDatastore(DataFolder);
            BoardAnalysisResult boardAnalysis;
            var    analysisExists = false;
            ISince since          = new SinceDate(startDate);

            if (db.TryLoadBoardAnalysis(Board.Id, startDate, endDate, granularity, out boardAnalysis))
            {
                _boardAnalysis = boardAnalysis;
                since          = new SinceDate(boardAnalysis.Timestamp);
                analysisExists = true;
            }
            UI?.Write("Reads cards from Trello ... ");
            var allCards = _trello.Cards.ForBoard(Board).ToList();

            UI?.WriteLine($"DONE (board '{Board.Name}' contains {allCards.Count} cards)");
            UI?.WriteLine("Analysing card actions ...");
            UI?.ShowBusy(maxValue: allCards.Count);
            try
            {
                Func <CreateCardAction, CardStatus> createStatus = action =>
                {
                    if (_doingListsIds.Any(id => id == action.Data.List.Id))
                    {
                        return(CardStatus.Doing);
                    }
                    return(_doneListsIds.Any(id => id == action.Data.List.Id) ? CardStatus.Done : CardStatus.Other);
                };
                Func <MoveCardAction, CardStatus> moveStatus = action =>
                {
                    if (_doingListsIds.Any(id => id == action.ListAfter.Id))
                    {
                        return(CardStatus.Doing);
                    }
                    return(_doneListsIds.Any(id => id == action.ListAfter.Id) ? CardStatus.Done : CardStatus.Other);
                };

                if (!analysisExists)
                {
                    _boardAnalysis = new BoardAnalysisResult(Board.Id, startDate, endDate, granularity);
                }

                // generate all periods ...
                PeriodCardsStatus lastPeriod;
                Dictionary <DateTime, PeriodCardsStatus> result;
                var firstPeriod = generatePeriods(startDate, ref endDate, granularity, analysisExists, out lastPeriod, out result);
                var progress    = 0;
                ICardActionsProvider cardActionsProvider;
                if (!analysisExists || !tryQuickAnalyzePeriodThroughActions(out cardActionsProvider))
                {
                    cardActionsProvider = new CardActionsReader(_trello, since, endDate);
                }

                var analysisWasUpdated = false;
                foreach (var card in allCards)
                {
                    UI?.UpdateBusy(progress, $" | Card: '{card.Name}'");
                    var allActions = cardActionsProvider.GetCardActions(card);
                    if (allActions.Count == 0)
                    {
                        UI?.UpdateBusy(++progress);
                        continue;
                    }
                    var createActions = allActions.OfType <CreateCardAction>().Where(a => a.Date <= endDate).ToList();
                    var trelloCard    = _boardAnalysis.Cards.FirstOrDefault(c => c.Id == card.Id);
                    PeriodCardsStatus period;
                    foreach (var createAction in createActions)
                    {
#if DEBUG
                        if (trelloCard != null)
                        {
                            throw new Exception("Huh?");
                        }
#endif
                        analysisWasUpdated = true;
                        var date = createAction.Date;
                        if (date < firstPeriod.Start)
                        {
                            period = firstPeriod;
                        }
                        else if (date > lastPeriod.End)
                        {
                            period = lastPeriod;
                        }
                        else
                        {
                            period = result[new Period(date, granularity).Start];
                        }
                        var cardStatus = createStatus(createAction);
                        trelloCard = new TrelloCard {
                            Id = card.Id, Name = card.Name
                        };
                        if (cardStatus == CardStatus.Doing)
                        {
                            trelloCard.DateCommitted = createAction.Date;
                        }
                        period.Set(trelloCard, cardStatus, true);
                    }
                    var moveActions =
                        allActions.OfType <UpdateCardMoveAction>()
                        .Where(a => a.Date <= endDate)
                        .Select(a => new MoveCardAction(a))
                        .ToList();
                    moveActions.Sort((a1, a2) => a1.Date <a2.Date ? -1 : a1.Date> a2.Date ? 1 : 0);
                    foreach (var moveAction in moveActions)
                    {
                        analysisWasUpdated = true;
                        var date = moveAction.Date;
                        if (date < firstPeriod.Start)
                        {
                            period = firstPeriod;
                        }
                        else if (date > lastPeriod.End)
                        {
                            period = lastPeriod;
                        }
                        else
                        {
                            period = result[new Period(moveAction.Date, granularity).Start];
                        }
                        var cardStatus = moveStatus(moveAction);
                        trelloCard = trelloCard ?? new TrelloCard(moveAction.MoveAction.Data.Card);
                        switch (cardStatus)
                        {
                        case CardStatus.Doing:
                            if (!trelloCard.IsCommitted)
                            {
                                trelloCard.DateCommitted = moveAction.Date;
                            }
                            break;

                        case CardStatus.Done:
                            if (!trelloCard.IsDone)
                            {
                                trelloCard.DateDone = moveAction.Date;
                            }
                            break;
                        }
                        period.Set(trelloCard, cardStatus, true);
                    }
                    UI?.UpdateBusy(++progress);
                }
                if (!analysisExists || analysisWasUpdated)
                {
                    db.SaveBoardAnalysis(_boardAnalysis);
                }
                return(_boardAnalysis);
            }
            finally
            {
                UI?.HideBusy();
            }
        }
 public BoardAnalysisResult(TimeGranularity granularity)
 {
     Granularity = granularity;
 }
 public BetfairServerResponse <List <TimeRangeResult> > ListTimeRanges(MarketFilter marketFilter, TimeGranularity timeGranularity)
 {
     return(client.ListTimeRanges(marketFilter, timeGranularity).Result);
 }
 public PeriodCardsStatus(BoardAnalysisResult boardAnalysis, DateTime start, TimeGranularity granularity)
     : base(start, granularity)
 {
     BoardAnalysis = boardAnalysis;
 }
 protected override Period OnMakeNext(DateTime start, TimeGranularity granularity)
 {
     return(new PeriodCardsStatus(BoardAnalysis, start, granularity));
 }
 public bool Equals(DateTime start, DateTime end, TimeGranularity granularity)
 {
     return(Start.Equals(start) && End.Equals(end) && Granularity == granularity);
 }
Beispiel #30
0
 protected TimestampFieldHandler(string fieldName, TimeGranularity timeGranularity, IBooster booster)
 {
     _fieldName       = fieldName;
     _timeGranularity = timeGranularity;
     _booster         = booster;
 }
Beispiel #31
0
 public Period(DateTime start, DateTime end, TimeGranularity granularity)
 {
     Start       = start;
     End         = end;
     Granularity = granularity;
 }