コード例 #1
0
        private void UpdateEfficiencyCache(IEnumerable <Shared.Models.Transaction> transactions)
        {
            var end   = DateTime.Today.AddDays(1);
            var start = end.AddDays(-2);

            var liveEfficiencyCache = _efficiencyCacheRepositoryFactory.GetCurrent();

            if (!_initEfficiencyRunner.IsInitialLoad(() => LiveEfficiencyCacheHelper.ComputeAndUpdateCacheForAllSites(
                                                         _transactionCacheRepositoryFactory,
                                                         _timesheetCacheProvider,
                                                         liveEfficiencyCache,
                                                         _liveEfficiencyEngine,
                                                         start, end)))
            {
                var siteEmployeeCodesBySiteCodes = transactions
                                                   .Where(r => !string.IsNullOrWhiteSpace(r.SiteCode) &&
                                                          !string.IsNullOrWhiteSpace(r.SiteEmployeeCode))
                                                   .GroupBy(r => new { r.SiteCode, r.SiteEmployeeCode })
                                                   .Select(r => new SiteEmployeeCode {
                    SiteCode = r.Key.SiteCode, EmployeeCode = r.Key.SiteEmployeeCode
                })
                                                   .GroupBy(r => r.SiteCode)
                                                   .ToDictionary(r => r.Key, r => r.ToArray());

                if (!siteEmployeeCodesBySiteCodes.Any())
                {
                    //historical ingestion events will be ignored
                    return;
                }

                _liveEfficiencyEngine.ComputeForSiteEmployeeCodesAndExecute(siteEmployeeCodesBySiteCodes,
                                                                            start, end, (calculatedEfficiency) => EfficiencyCacheHelper.UpdateLiveEfficiencyCache(calculatedEfficiency, liveEfficiencyCache, start, end, false));
            }
        }
コード例 #2
0
        private void UpdateEfficiencyRecordsCache(TimesheetIngestionEvent @event)
        {
            var eventTimesheets = new List <Timesheet>()
            {
                @event.Value
            };

            var end   = DateTime.Today.AddDays(1);
            var start = end.AddDays(-2);

            var liveEfficiencyCache = _efficiencyCacheRepositoryFactory.GetCurrent();

            if (!_initEfficiencyRunner.IsInitialLoad(() => LiveEfficiencyCacheHelper.ComputeAndUpdateCacheForAllSites(
                                                         _transactionCacheRepositoryFactory,
                                                         _timesheetCacheProvider,
                                                         liveEfficiencyCache,
                                                         _liveEfficiencyEngine,
                                                         start, end)))
            {
                var tnaEmployeeCodesBySiteCodes = eventTimesheets
                                                  .Where(r => r.PunchInDateTime < end &&
                                                         (r.PunchOutDateTime ?? start) >= start &&
                                                         !string.IsNullOrWhiteSpace(r.SiteCode) &&
                                                         !string.IsNullOrWhiteSpace(r.EmployeeNumber))
                                                  .GroupBy(r => new { r.SiteCode, r.EmployeeNumber })
                                                  .Select(r => new SiteEmployeeCode {
                    SiteCode = r.Key.SiteCode, EmployeeCode = r.Key.EmployeeNumber
                })
                                                  .GroupBy(r => r.SiteCode)
                                                  .ToDictionary(r => r.Key, r => r.ToArray());

                if (!tnaEmployeeCodesBySiteCodes.Any())
                {
                    //historical ingestion events will be ignored
                    return;
                }

                _liveEfficiencyEngine.ComputeForTnaEmployeeCodesAndExecute(tnaEmployeeCodesBySiteCodes, start, end,
                                                                           (calculatedEfficiency) => EfficiencyCacheHelper.UpdateLiveEfficiencyCache(calculatedEfficiency, liveEfficiencyCache, start, end, false));
            }
        }