コード例 #1
0
        public List <UsageBlock> UsageListForGivenTimeFrame(DateTime startTime, DateTime endTime)
        {
            List <UsageModel> filteredUsages = ComposeListOfUsages(startTime, endTime);

            List <UsageBlock> blockList = new List <UsageBlock>();
            UsageBlock        block     = new UsageBlock();

            foreach (UsageModel usage in filteredUsages)
            {
                if (block.StartTime == default && block.EndTime == default)
                {
                    block.StartTime = usage.StartTime;
                    block.EndTime   = usage.EndTime;
                }

                if ((usage.StartTime - block.EndTime) <= TimeSpan.FromMilliseconds((int)Res))
                {
                    block.EndTime = usage.EndTime;
                }
                else
                {
                    blockList.Add(block);
                    block = new UsageBlock(usage.StartTime, usage.EndTime);
                }
            }

            if (!blockList.Any(sm => sm.Id == block.Id))
            {
                blockList.Add(block);
            }

            return(blockList);
        }
コード例 #2
0
        public List <UsageBlock> NotUsageListForGivenTimeFrame(DateTime startTime, DateTime endTime)
        {
            List <UsageBlock> usageList = UsageListForGivenTimeFrame(startTime, endTime);

            List <UsageBlock> notUsageList  = new List <UsageBlock>();
            UsageBlock        notUsageBlock = new UsageBlock();
            bool isValueWrittenInRound;

            foreach (UsageBlock block in usageList)
            {
                isValueWrittenInRound = false;

                if (notUsageBlock.StartTime == default && notUsageBlock.EndTime == default &&
                    !isValueWrittenInRound)
                {
                    notUsageBlock.StartTime = block.EndTime;
                    isValueWrittenInRound   = true;
                }

                if (notUsageBlock.EndTime == default && notUsageBlock.StartTime != default &&
                    !isValueWrittenInRound)
                {
                    notUsageBlock.EndTime = block.StartTime;
                    isValueWrittenInRound = true;
                }

                if (notUsageBlock.StartTime != default && notUsageBlock.EndTime != default &&
                    isValueWrittenInRound)
                {
                    notUsageList.Add(notUsageBlock);
                    notUsageBlock = new UsageBlock
                    {
                        StartTime = block.EndTime
                    };
                }
            }

            return(notUsageList);
        }