예제 #1
0
        public void FixTo()
        {
            var ex = new TimeExpression("time < 1455376521s");

            ex.From.Should().Be(null);
            ex.To.Should().Be(new DateTime(2016, 2, 13, 16, 15, 21, DateTimeKind.Local).ToUniversalTime());
        }
예제 #2
0
        public void FixFrom()
        {
            var ex = new TimeExpression("time > 1455354920s");

            ex.From.Should().Be(new DateTime(2016, 2, 13, 10, 15, 20, DateTimeKind.Local).ToUniversalTime());
            ex.To.Should().Be(null);
        }
예제 #3
0
 public IQuerySerie <T> GetDataPoints <T>(string timeExpression) where T : struct
 {
     if (timeExpression != null)
     {
         var expression = new TimeExpression(timeExpression);
         return(GetDataPoints <T>(expression.From, expression.To));
     }
     return(GetDataPoints <T>());
 }
예제 #4
0
        public void RelativeTo()
        {
            var ex = new TimeExpression("time < now() - 6h");

            var shouldTime = DateTime.UtcNow - TimeSpan.FromHours(6);

            var diff = shouldTime - ex.To.Value;

            Math.Abs(diff.TotalMinutes).Should().BeLessThan(1);
        }
예제 #5
0
    /// <summary>
    /// 生成刷新配置
    /// </summary>
    protected override void generateRefresh()
    {
        startTimeT = new TimeExpression(startTime);

        endTimeT = new TimeExpression(endTime);

        resetTimeT = new TimeExpression(resetTime);

        canSeeTimeT = new TimeExpression(canSeeTime);

        cantSeeTimeT = new TimeExpression(cantSeeTime);
    }
예제 #6
0
    /// <summary>
    /// 生成刷新配置
    /// </summary>
    protected override void generateRefresh()
    {
        if (_name == null)
        {
            _name = name;
        }
        name = LanguageConfig.getText(_name);

        if (_explain == null)
        {
            _explain = explain;
        }
        explain = LanguageConfig.getText(_explain);

        enableTimeT = new TimeExpression(enableTime);

        iconT = LoadControl.getResourceIDByName(icon);
    }
예제 #7
0
    /// <summary>
    /// 生成刷新配置
    /// </summary>
    protected override void generateRefresh()
    {
        if (_name == null)
        {
            _name = name;
        }
        name = LanguageConfig.getText(_name);

        if (_explain == null)
        {
            _explain = explain;
        }
        explain = LanguageConfig.getText(_explain);

        cycleTimeT = new TimeExpression(cycleTime);

        failTimeT = new TimeExpression(failTime);
    }
예제 #8
0
        internal List <Result> Calculate(IEnumerable <Camp> camps, IncomingResources incomingResourcesObject)
        {
            // Calculate total skills needed
            DateTime start = DateTime.Now;
            SortedDictionary <string, SkillWithCount> skills = new SortedDictionary <string, SkillWithCount>();

            foreach (Camp camp in camps)
            {
                foreach (SkillWithCount campSkillWithCount in camp.Skills)
                {
                    SkillWithCount skillWithCount = null;
                    if (skills.TryGetValue(campSkillWithCount.Skill.Id, out skillWithCount))
                    {
                        skillWithCount.Count += campSkillWithCount.Count;
                    }
                    else
                    {
                        skillWithCount = new SkillWithCount(campSkillWithCount.Skill, campSkillWithCount.Count);
                        skills.Add(skillWithCount.Skill.Id, skillWithCount);
                    }
                }
            }

            int[] skillCount = new int[skills.Count];
            List <SkillWithCount>        skillsWithCount   = new List <SkillWithCount>(skills.Values);
            IDictionary <string, double> incomingResources = incomingResourcesObject.GetResources();

            int MAX_RESULTS = 10;
            List <InternalResult> internalResults = new List <InternalResult>(MAX_RESULTS);

            SortedDictionary <string, BuffCountExpression>         buffExpressions             = PrepareBuffExpressions(skillsWithCount);
            SortedDictionary <string, ResourceCountExpression>     resourceExpression          = PrepareResourceExpressions(buffExpressions);
            SortedDictionary <string, ResourceInStorageExpression> resourceInStorageExpression = PrepareResourceInStorageExpressions(buffExpressions, incomingResources);
            TimeExpression timeExpression = new TimeExpression();

            foreach (KeyValuePair <string, ResourceCountExpression> pair in resourceExpression)
            {
                timeExpression.Add(incomingResources[pair.Key], pair.Value);
            }

            TimeExpression timeStorageCostExpression = new TimeExpression();

            foreach (KeyValuePair <string, ResourceInStorageExpression> pair in resourceInStorageExpression)
            {
                timeStorageCostExpression.Add(incomingResources[pair.Key], pair.Value);
            }

            double totalVariantCount = 1;

            foreach (SkillWithCount skill in skillsWithCount)
            {
                totalVariantCount *= skill.Count + 1;
            }
            int inc = 1;

            if (totalVariantCount > 10000000)
            {
                inc = 2;
            }
            if (totalVariantCount > 15000000)
            {
                inc = 3;
            }

            while (Inc(skillCount, skillsWithCount, inc))
            {
                double time = timeExpression.Calculate(skillCount);

                if (internalResults.Count < MAX_RESULTS)
                {
                    InternalResult newResult = new InternalResult(time, (int[])skillCount.Clone(), timeStorageCostExpression);
                    AddResult(internalResults, newResult);
                }
                else if (time < internalResults[MAX_RESULTS - 1].Time)
                {
                    internalResults.RemoveAt(MAX_RESULTS - 1);
                    InternalResult newResult = new InternalResult(time, (int[])skillCount.Clone(), timeStorageCostExpression);
                    AddResult(internalResults, newResult);
                }
            }

            if (inc > 1)
            {
                AdjastSolutions(skillsWithCount, internalResults, timeExpression);
            }

            return(PrepareResults(camps, skillsWithCount, internalResults, buffExpressions, resourceInStorageExpression));
        }
예제 #9
0
        private static void AdjastSolutions(List <SkillWithCount> skillsWithCount, List <InternalResult> results, TimeExpression timeExpression)
        {
            for (int i = 0; i < results.Count; i++)
            {
                double bestTime   = results[i].Time;
                int[]  bestResult = results[i].Solution;
                bool   flag       = true;
                while (flag)
                {
                    flag = false;
                    NextSteps nextSteps = new NextSteps(bestResult, skillsWithCount);
                    foreach (int[] tmp in nextSteps.GetSteps())
                    {
                        double time = timeExpression.Calculate(tmp);
                        if (time < bestTime)
                        {
                            bestResult = (int[])tmp.Clone();
                            bestTime   = time;
                            flag       = true;
                        }
                    }

                    if (flag)
                    {
                        results[i].Time     = bestTime;
                        results[i].Solution = bestResult;
                    }
                }
            }

            results.Sort();
        }
예제 #10
0
 internal InternalResult(double time, int[] result, TimeExpression timeStorageCostExpression)
 {
     m_time   = time;
     m_result = result;
     m_timeStorageCostExpression = timeStorageCostExpression;
 }