Exemple #1
0
    //  Cuando el jugador muere
    public void playerDied(string playerTag)
    {
        //buscamos el objeto stats
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        //y llamamos el metodo LostLife
        stats.LostLife(playerTag);

        if (stats.getLives(playerTag) > 0)
        {
            if (playerTag == "Player1")//lo reaparecemos
            {
                GameObject.FindWithTag(playerTag).GetComponent <PlayerController>().Respawn();
            }
            else if (playerTag == "Player2")//lo reaparecemos
            {
                GameObject.FindWithTag(playerTag).GetComponent <PlayerController1>().Respawn();
            }
        }
        else if (stats.singlePlayer)
        {
            LoadLevel("Lose");
        }
        else
        {
            LoadLevel("Win");
        }
    }
Exemple #2
0
        public void SimpleTest()
        {
            var statCounter = new StatCounter();
            var average     = statCounter.GetAverage(new[]
            {
                new Individual(0, null)
                {
                    Color = new ColorGene {
                        Value = 0x102030
                    },
                    Aggression = new Gene(0, 10000)
                    {
                        Value = 200
                    },
                },
                new Individual(0, null)
                {
                    Color = new ColorGene {
                        Value = 0x306050
                    },
                    Aggression = new Gene(0, 10000)
                    {
                        Value = 400
                    },
                },
            });

            Assert.AreEqual(300, average.Aggression);
            Assert.AreEqual(0x204040, average.Color);
        }
Exemple #3
0
            public HourlyStats(BinaryReader bR)
            {
                if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "HS") //format
                {
                    throw new InvalidDataException("HourlyStats format is invalid.");
                }

                byte version = bR.ReadByte();

                switch (version)
                {
                case 1:
                    _hourStat = new StatCounter();
                    _hourStat.Lock();

                    for (int i = 0; i < _minuteStats.Length; i++)
                    {
                        _minuteStats[i] = new StatCounter(bR);
                        _hourStat.Merge(_minuteStats[i]);
                    }

                    break;

                default:
                    throw new InvalidDataException("HourlyStats version not supported.");
                }
            }
Exemple #4
0
            public void Merge(StatCounter statCounter)
            {
                if (!_locked || !statCounter._locked)
                {
                    throw new DnsServerException("StatCounter must be locked.");
                }

                _totalQueries       += statCounter._totalQueries;
                _totalNoError       += statCounter._totalNoError;
                _totalServerFailure += statCounter._totalServerFailure;
                _totalNameError     += statCounter._totalNameError;
                _totalRefused       += statCounter._totalRefused;
                _totalBlocked       += statCounter._totalBlocked;

                foreach (KeyValuePair <string, Counter> queryDomain in statCounter._queryDomains)
                {
                    _queryDomains.GetOrAdd(queryDomain.Key, new Counter()).Merge(queryDomain.Value);
                }

                foreach (KeyValuePair <string, Counter> queryBlockedDomain in statCounter._queryBlockedDomains)
                {
                    _queryBlockedDomains.GetOrAdd(queryBlockedDomain.Key, new Counter()).Merge(queryBlockedDomain.Value);
                }

                foreach (KeyValuePair <DnsResourceRecordType, Counter> queryType in statCounter._queryTypes)
                {
                    _queryTypes.GetOrAdd(queryType.Key, new Counter()).Merge(queryType.Value);
                }

                foreach (KeyValuePair <IPAddress, Counter> clientIpAddress in statCounter._clientIpAddresses)
                {
                    _clientIpAddresses.GetOrAdd(clientIpAddress.Key, new Counter()).Merge(clientIpAddress.Value);
                }
            }
Exemple #5
0
 public World(Random random, Coord size)
 {
     Random        = random;
     Size          = size;
     Mutator       = new Mutator(this);
     Navigator     = new Navigator(this);
     DecisionMaker = new DecisionMaker(this);
     StatCounter   = new StatCounter();
     Tuners        = new Dictionary <string, LimitedInt>
     {
         { nameof(MaxFoodItems), MaxFoodItems },
         { nameof(MaxFoodItemsPerTick), MaxFoodItemsPerTick },
         { nameof(MaxEnergyPerFoodItem), MaxEnergyPerFoodItem },
         { nameof(MutationProbability), MutationProbability },
         { nameof(MutationMaxDelta), MutationMaxDelta },
         { nameof(EnergyDrainModifier), EnergyDrainModifier },
         { nameof(BirthEnergyShare), BirthEnergyShare },
         { nameof(EatDecisionModifier), EatDecisionModifier },
         { nameof(SexDecisionModifier), SexDecisionModifier },
         { nameof(KillDecisionModifier), KillDecisionModifier },
         { nameof(PoisonEffectiveness), PoisonEffectiveness },
         { nameof(PoisonResistEnergyDrain), PoisonResistEnergyDrain },
         { nameof(AttackerDamageModifier), AttackerDamageModifier },
     };
 }
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            DestroyImmediate(this);
        }

        zaps             = 0;  //
        time             = 0f; //
        resets           = 0;  //
        deaths           = 0;  //
        refuels          = 0;  //
        spikings         = 0;
        strandings       = 0;  //
        collisions       = 0;  //
        fuelBurned       = 0f; //
        damageTaken      = 0f; //
        distanceDragged  = 0f;
        distanceConveyed = 0f;


        scoreMenu.SetActive(false);
    }
Exemple #7
0
    //  We added these functions from our previous LevelManager script.
    public void LoadNextLevel()
    {
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        stats.passedLevel();
        Debug.Log("load next level");
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
        public BroadcastWorker(TelegramBotClient bot, ILogger <BroadcastWorker> logger, IServiceProvider provider)
        {
            Bot = bot;

            _logger   = logger;
            _provider = provider;
            Counter   = provider.GetService <StatCounter>();
        }
Exemple #9
0
 // Use this for initialization
 void Start()
 {
     //Busca el objeto stats que contiene el score y highscore
     stats = GameObject.Find("Stats").GetComponent <StatCounter>();
     //Y lo muestra en pantalla usando labels
     ScoreLabel.text     = "Score: " + stats.score;
     HighScoreLabel.text = "HighScore: " + stats.HighScore;
 }
Exemple #10
0
 // Use this for initialization
 void Start()
 {
     updates = 0;
     //asignamos a floor la altura del jugador
     floor = player.transform.position.y;
     //buscamos los objetos ceiling y stats para usarlos despues
     ceiling = GameObject.Find("Ceiling");
     stats   = GameObject.Find("Stats").GetComponent <StatCounter>();
 }
Exemple #11
0
            public void UpdateStat(DateTime dateTime, StatCounter minuteStat)
            {
                if (!minuteStat.IsLocked)
                {
                    throw new DnsServerException("StatCounter must be locked.");
                }

                _hourStat.Merge(minuteStat);
                _minuteStats[dateTime.Minute] = minuteStat;
            }
Exemple #12
0
        public void GetEuclideanDistanceTest()
        {
            var statCounter = new StatCounter();
            var individual1 = new Individual(0, null);
            var individual2 = new Individual(0, null);

            individual2.Fertility.Value = individual2.Fertility + 1;

            Assert.AreEqual(1, statCounter.GetEuclideanDistance(individual1, individual2));
        }
Exemple #13
0
        public void GetEuclideanDistanceWithColorTest()
        {
            var statCounter = new StatCounter();
            var individual1 = new Individual(0, null);
            var individual2 = new Individual(0, null);

            individual2.Color.Value = individual2.Color + 0x100;

            Assert.AreEqual(1, statCounter.GetEuclideanDistance(individual1, individual2));
        }
Exemple #14
0
    //cuando el jugador llega a la cima
    public void playerReachedTop()
    {
        //buscamos el objeto stats
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        //lamamos el metodo reachedTop
        stats.reachedTop();
        //y cargamos la escena de ganar
        LoadLevel("Win");
    }
Exemple #15
0
    //cuando el jugador llega a una puerta
    public void playerReachedDoor()
    {
        //buscamos el objeto stats
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        //llamamos el metodo reachedDoor
        stats.reachedDoor();
        //y cargamos el siguiente nivel
        LoadNextLevel();
    }
Exemple #16
0
    //cuando el jugador ya no quiere continuar o quiere salir
    public void returnToMenu()
    {
        //buscamos el objeto stats
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        //lamamos el metodo restart
        stats.restart();
        //y cargamos la escena Start
        LoadLevel("Menu");
    }
Exemple #17
0
    void Update()
    {
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        if (SceneManager.GetActiveScene().name.Contains("SP"))
        {
            stats.singlePlayer = true;
        }
        else
        {
            stats.singlePlayer = false;
        }
    }
Exemple #18
0
    private void Start()
    {
        cm = CheckpointManager.instance;
        sc = StatCounter.instance;
        rb = GetComponent <Rigidbody2D>();
        rb.centerOfMass = Vector2.zero;
        fuel            = GetComponent <ShipFuel>();
        health          = GetComponent <ShipHealth>();

        goText.enabled = false;
        paused         = false;
        pausedText.gameObject.SetActive(paused);

        StartCoroutine(ShowText());
    }
Exemple #19
0
    void ReloadDeck()
    {
        tempDeck.AddRange(pile);
        pile.Clear();
        StatCounter.IncrementTotalDeckReload();

        AddBlankToDeck();

        //Fire Spread code - move to another script if necessary

        GameObject[] fires = GameObject.FindGameObjectsWithTag("Fire");
        for (int i = 0; i < fires.Length; i++)
        {
            fires [i].GetComponent <FireController> ().SpreadWarning();
        }
    }
Exemple #20
0
            public void WriteTo(BinaryWriter bW)
            {
                bW.Write(Encoding.ASCII.GetBytes("HS")); //format
                bW.Write((byte)1);                       //version

                for (int i = 0; i < _minuteStats.Length; i++)
                {
                    if (_minuteStats[i] == null)
                    {
                        _minuteStats[i] = new StatCounter();
                        _minuteStats[i].Lock();
                    }

                    _minuteStats[i].WriteTo(bW);
                }
            }
Exemple #21
0
    //  Cuando el jugador muere
    public void playerDied()
    {
        //buscamos el objeto stats
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        //y llamamos el metodo LostLife
        stats.LostLife();
        //si el jugador aun tiene vidas
        if (stats.lives > 0)
        {
            //recargamos el nivel
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
        else //si ya no tiene vidas restantes
        {
            //cargamos la escena de perdida
            LoadLevel("lose");
        }
    }
Exemple #22
0
        public void TestDoubleRddStats()
        {
            StatCounter stats = doubles.Stats();

            Assert.AreEqual(9, stats.Count);
            Assert.AreEqual(201, stats.Sum);
            Assert.AreEqual(23, stats.Max);
            Assert.AreEqual(22, stats.Min);
            Assert.AreEqual(22.333333333333332, stats.Mean);
            Assert.AreEqual(0.22222222222222213, stats.Variance);
            Assert.AreEqual(0.24999999999999989, stats.SampleVariance);
            Assert.AreEqual(0.47140452079103157, stats.Stdev);
            Assert.AreEqual(0.49999999999999989, stats.SampleStdev);

            Assert.AreEqual(doubles.Mean(), stats.Mean);
            Assert.AreEqual(doubles.Variance(), stats.Variance);
            Assert.AreEqual(doubles.SampleVariance(), stats.SampleVariance);
            Assert.AreEqual(doubles.Stdev(), stats.Stdev);
            Assert.AreEqual(doubles.SampleStdev(), stats.SampleStdev);
        }
Exemple #23
0
    //cuando el jugador recoge un item
    public void pickedUpItem(string playerTag)
    {
        StatCounter stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        stats.gotItem(playerTag);
        //si ya no hay items
        if (Item.itemCount <= 0)
        {
            Debug.Log(stats.singlePlayer);
            if (stats.singlePlayer)
            {
                //Si es singleplayer se carga el siguiente nivel
                LoadNextLevel();
            }
            else
            {
                LoadLevel("Win");
            }
            //si es multijugador se carga win
        }
    }
Exemple #24
0
        private void DoMaintenance()
        {
            //load new stats counter 5 min ahead of current time
            DateTime currentDateTime = DateTime.UtcNow;

            for (int i = 0; i < 5; i++)
            {
                int minute = currentDateTime.AddMinutes(i).Minute;

                StatCounter statCounter = _lastHourStatCounters[minute];
                if ((statCounter == null) || statCounter.IsLocked)
                {
                    _lastHourStatCounters[minute] = new StatCounter();
                }
            }

            //save data upto last 5 mins
            DateTime last5MinDateTime = currentDateTime.AddMinutes(-5);

            for (int i = 0; i < 5; i++)
            {
                DateTime lastDateTime = last5MinDateTime.AddMinutes(i);

                StatCounter lastStatCounter = _lastHourStatCounters[lastDateTime.Minute];
                if ((lastStatCounter != null) && !lastStatCounter.IsLocked)
                {
                    //load hourly stats data
                    HourlyStats hourlyStats = LoadHourlyStats(lastDateTime);

                    //update hourly stats file
                    lastStatCounter.Lock();
                    hourlyStats.UpdateStat(lastDateTime, lastStatCounter);

                    //save hourly stats
                    SaveHourlyStats(lastDateTime, hourlyStats);
                }
            }
        }
Exemple #25
0
    // Use this for initialization
    void Start()
    {
        stats = GameObject.Find("Stats").GetComponent <StatCounter>();

        if (stats.singlePlayer)
        {
            ScoreLabel.text = "You Won! \n Score: " + stats.P1score;
        }
        else
        {
            if (stats.P1lives == 0)
            {
                winner = "Player 2 Won!\n";
            }
            else if (stats.P2lives == 0)
            {
                winner = "Player 1 Won!\n";
            }
            else if (stats.P1score > stats.P2score)
            {
                winner = "Player 1 Won!\n";
            }
            else
            {
                winner = "Player 2 Won!\n";
            }
            ScoreLabel.text = winner + "Score Player 1: " + stats.P1score + "\nScore Player 2: " + stats.P2score;
        }

        /*
         * //Busca el objeto stats que contiene el score y highscore
         * stats = GameObject.Find("Stats").GetComponent<StatCounter>();
         * //Y lo muestra en pantalla usando labels
         * ScoreLabel.text = "Score: " +stats.score;
         * HighScoreLabel.text = "HighScore: " + stats.HighScore;
         */
    }
Exemple #26
0
    public void init(int ageRange, Transform destination, StatCounter statCounter)
    {
        this.ageRange = ageRange;
        this.viewObject.GetComponent <Renderer>().material = ageRangeMats[ageRange];
        this.destination = destination;
        this.GetComponent <AIDestinationSetter>().target = destination;

        switch (ageRange)
        {
        case 0: { break; }

        case 1: { viewObject.transform.position += new Vector3(0, 0.06f, 0); break; }

        case 2: { viewObject.transform.position += new Vector3(0, 0.12f, 0); break; }

        case 3: { viewObject.transform.position += new Vector3(0, 0.18f, 0); break; }

        case 4: { viewObject.transform.position += new Vector3(0, -0.06f, 0); break; }

        case 5: { viewObject.transform.position += new Vector3(0, -0.12f, 0); break; }
        }

        statCounter.addAgent(ageRange);
    }
Exemple #27
0
        void ICmpRenderer.Draw(IDrawDevice device)
        {
            Profile.BeginMeasure(@"ProfileRenderer");
            Canvas canvas = new Canvas(device);

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White, null));

            bool anyTextReport = this.textReportPerf || this.textReportStat;
            bool anyGraph      = this.drawGraphs && this.counterGraphs.Count > 0;

            // Determine geometry
            int areaWidth = (int)device.TargetSize.X - 20;

            if (anyGraph && anyTextReport)
            {
                areaWidth = (areaWidth - 10) / 2;
            }
            Rect textReportRect = new Rect(
                10,
                10,
                anyTextReport ? areaWidth : 0,
                (int)device.TargetSize.Y - 20);
            Rect graphRect = new Rect(
                anyTextReport ? (textReportRect.MaximumX + 10) : 10,
                10,
                anyGraph ? areaWidth : 0,
                (int)device.TargetSize.Y - 20);

            // Text Reports
            if (anyTextReport)
            {
                // Update Report
                IEnumerable <ProfileCounter> counters = Profile.GetUsedCounters();
                if (!this.textReportPerf)
                {
                    counters = counters.Where(c => !(c is TimeCounter));
                }
                if (!this.textReportStat)
                {
                    counters = counters.Where(c => !(c is StatCounter));
                }
                if (this.textReport == null || (Time.MainTimer - this.textReportLast).TotalMilliseconds > this.updateInterval)
                {
                    string report = Profile.GetTextReport(counters, this.textReportOptions | ProfileReportOptions.FormattedText);

                    if (this.textReport == null)
                    {
                        this.textReport       = new FormattedText();
                        this.textReport.Fonts = new[] { Font.GenericMonospace8 };
                    }
                    this.textReport.MaxWidth   = (int)textReportRect.W;
                    this.textReport.SourceText = report;
                    this.textReportLast        = Time.MainTimer;
                }

                // Draw Report
                canvas.DrawText(textReport, ref textReportTextVert, ref textReportIconVert, textReportRect.X, textReportRect.Y, drawBackground: true);
            }

            // Counter Graphs
            if (anyGraph)
            {
                // Mark graph cache as unused
                foreach (GraphCacheEntry entry in this.graphCache.Values)
                {
                    entry.WasUsed = false;
                }

                int space  = 5;
                int graphY = (int)graphRect.Y;
                int graphH = MathF.Min((int)(graphRect.H / this.counterGraphs.Count) - space, (int)graphRect.W / 2);
                foreach (string counterName in this.counterGraphs)
                {
                    ProfileCounter counter = Profile.GetCounter <ProfileCounter>(counterName);
                    if (counter == null)
                    {
                        return;
                    }

                    // Create or retrieve graph cache entry
                    GraphCacheEntry cache = null;
                    if (!this.graphCache.TryGetValue(counterName, out cache))
                    {
                        cache                        = new GraphCacheEntry();
                        cache.GraphValues            = new float[ProfileCounter.ValueHistoryLen];
                        cache.GraphColors            = new ColorRgba[ProfileCounter.ValueHistoryLen];
                        this.graphCache[counterName] = cache;
                    }
                    cache.WasUsed = true;

                    float cursorRatio = 0.0f;
                    if (counter is TimeCounter)
                    {
                        TimeCounter timeCounter = counter as TimeCounter;
                        for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
                        {
                            float factor = timeCounter.ValueGraph[i] / Time.MsPFMult;
                            cache.GraphValues[i] = factor * 0.75f;
                            cache.GraphColors[i] = ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, factor);
                        }
                        canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
                        canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH);
                        canvas.State.ColorTint = ColorRgba.White;
                        this.DrawHorizontalGraph(canvas, cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH);
                        cursorRatio = (float)timeCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen;
                    }
                    else if (counter is StatCounter)
                    {
                        StatCounter statCounter = counter as StatCounter;
                        for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
                        {
                            cache.GraphValues[i] = (float)(statCounter.ValueGraph[i] - statCounter.MinValue) / statCounter.MaxValue;
                            cache.GraphColors[i] = ColorRgba.White;
                        }
                        canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
                        canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH);
                        canvas.State.ColorTint = ColorRgba.White;
                        this.DrawHorizontalGraph(canvas, cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH);
                        cursorRatio = (float)statCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen;
                    }

                    canvas.DrawText(new string[] { counter.FullName }, ref cache.VertText, graphRect.X, graphY);
                    canvas.DrawLine(graphRect.X + graphRect.W * cursorRatio, graphY, graphRect.X + graphRect.W * cursorRatio, graphY + graphH);

                    graphY += graphH + space;
                }

                // Remove unused graph cache entries
                foreach (var pair in this.graphCache.ToArray())
                {
                    if (!pair.Value.WasUsed)
                    {
                        pair.Value.GraphColors = null;
                        pair.Value.GraphValues = null;
                        pair.Value.VertGraph   = null;
                        pair.Value.VertText    = null;
                        this.graphCache.Remove(pair.Key);
                    }
                }
            }

            Profile.EndMeasure(@"ProfileRenderer");
        }
Exemple #28
0
 public HourlyStats()
 {
     _hourStat = new StatCounter();
     _hourStat.Lock();
 }
Exemple #29
0
        public Dictionary <string, List <KeyValuePair <string, int> > > GetLastYearStats()
        {
            StatCounter totalStatCounter = new StatCounter();

            totalStatCounter.Lock();

            List <KeyValuePair <string, int> > totalQueriesPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNoErrorPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalServerFailurePerInterval = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNameErrorPerInterval     = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalRefusedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalBlockedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalClientsPerInterval       = new List <KeyValuePair <string, int> >();

            DateTime lastYearDateTime = DateTime.UtcNow.AddMonths(-12);

            lastYearDateTime = new DateTime(lastYearDateTime.Year, lastYearDateTime.Month, 1, 0, 0, 0, DateTimeKind.Utc);

            for (int month = 0; month < 12; month++) //months
            {
                StatCounter monthlyStatCounter = new StatCounter();
                monthlyStatCounter.Lock();

                DateTime lastMonthDateTime = lastYearDateTime.AddMonths(month);
                string   label             = lastMonthDateTime.ToLocalTime().ToString("MM/yyyy");

                int days = DateTime.DaysInMonth(lastMonthDateTime.Year, lastMonthDateTime.Month);

                for (int day = 0; day < days; day++) //days
                {
                    DateTime lastDayDateTime = lastMonthDateTime.AddDays(day);

                    for (int hour = 0; hour < 24; hour++) //hours
                    {
                        DateTime    lastDateTime = lastDayDateTime.AddHours(hour);
                        HourlyStats hourlyStats  = LoadHourlyStats(lastDateTime);

                        monthlyStatCounter.Merge(hourlyStats.HourStat);
                    }
                }

                totalStatCounter.Merge(monthlyStatCounter);

                totalQueriesPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalQueries));
                totalNoErrorPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalNoError));
                totalServerFailurePerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalServerFailure));
                totalNameErrorPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalNameError));
                totalRefusedPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalRefused));
                totalBlockedPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalBlocked));
                totalClientsPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalClients));
            }

            Dictionary <string, List <KeyValuePair <string, int> > > data = new Dictionary <string, List <KeyValuePair <string, int> > >();

            {
                List <KeyValuePair <string, int> > stats = new List <KeyValuePair <string, int> >(6);

                stats.Add(new KeyValuePair <string, int>("totalQueries", totalStatCounter.TotalQueries));
                stats.Add(new KeyValuePair <string, int>("totalNoError", totalStatCounter.TotalNoError));
                stats.Add(new KeyValuePair <string, int>("totalServerFailure", totalStatCounter.TotalServerFailure));
                stats.Add(new KeyValuePair <string, int>("totalNameError", totalStatCounter.TotalNameError));
                stats.Add(new KeyValuePair <string, int>("totalRefused", totalStatCounter.TotalRefused));
                stats.Add(new KeyValuePair <string, int>("totalBlocked", totalStatCounter.TotalBlocked));
                stats.Add(new KeyValuePair <string, int>("totalClients", totalStatCounter.TotalClients));

                data.Add("stats", stats);
            }

            data.Add("totalQueriesPerInterval", totalQueriesPerInterval);
            data.Add("totalNoErrorPerInterval", totalNoErrorPerInterval);
            data.Add("totalServerFailurePerInterval", totalServerFailurePerInterval);
            data.Add("totalNameErrorPerInterval", totalNameErrorPerInterval);
            data.Add("totalRefusedPerInterval", totalRefusedPerInterval);
            data.Add("totalBlockedPerInterval", totalBlockedPerInterval);
            data.Add("totalClientsPerInterval", totalClientsPerInterval);

            data.Add("topDomains", totalStatCounter.GetTopDomains());
            data.Add("topBlockedDomains", totalStatCounter.GetTopBlockedDomains());
            data.Add("topClients", totalStatCounter.GetTopClients());
            data.Add("queryTypes", totalStatCounter.GetTopQueryTypes());

            return(data);
        }
Exemple #30
0
        public Dictionary <string, List <KeyValuePair <string, int> > > GetLastDayStats()
        {
            StatCounter totalStatCounter = new StatCounter();

            totalStatCounter.Lock();

            List <KeyValuePair <string, int> > totalQueriesPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNoErrorPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalServerFailurePerInterval = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNameErrorPerInterval     = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalRefusedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalBlockedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalClientsPerInterval       = new List <KeyValuePair <string, int> >();

            DateTime lastDayDateTime = DateTime.UtcNow.AddHours(-24);

            lastDayDateTime = new DateTime(lastDayDateTime.Year, lastDayDateTime.Month, lastDayDateTime.Day, lastDayDateTime.Hour, 0, 0, DateTimeKind.Utc);

            for (int hour = 0; hour < 24; hour++)
            {
                DateTime lastDateTime = lastDayDateTime.AddHours(hour);
                string   label        = lastDateTime.ToLocalTime().ToString("MM/dd HH") + ":00";

                HourlyStats hourlyStats       = LoadHourlyStats(lastDateTime);
                StatCounter hourlyStatCounter = hourlyStats.HourStat;

                totalStatCounter.Merge(hourlyStatCounter);

                totalQueriesPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalQueries));
                totalNoErrorPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalNoError));
                totalServerFailurePerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalServerFailure));
                totalNameErrorPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalNameError));
                totalRefusedPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalRefused));
                totalBlockedPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalBlocked));
                totalClientsPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalClients));
            }

            Dictionary <string, List <KeyValuePair <string, int> > > data = new Dictionary <string, List <KeyValuePair <string, int> > >();

            {
                List <KeyValuePair <string, int> > stats = new List <KeyValuePair <string, int> >(6);

                stats.Add(new KeyValuePair <string, int>("totalQueries", totalStatCounter.TotalQueries));
                stats.Add(new KeyValuePair <string, int>("totalNoError", totalStatCounter.TotalNoError));
                stats.Add(new KeyValuePair <string, int>("totalServerFailure", totalStatCounter.TotalServerFailure));
                stats.Add(new KeyValuePair <string, int>("totalNameError", totalStatCounter.TotalNameError));
                stats.Add(new KeyValuePair <string, int>("totalRefused", totalStatCounter.TotalRefused));
                stats.Add(new KeyValuePair <string, int>("totalBlocked", totalStatCounter.TotalBlocked));
                stats.Add(new KeyValuePair <string, int>("totalClients", totalStatCounter.TotalClients));

                data.Add("stats", stats);
            }

            data.Add("totalQueriesPerInterval", totalQueriesPerInterval);
            data.Add("totalNoErrorPerInterval", totalNoErrorPerInterval);
            data.Add("totalServerFailurePerInterval", totalServerFailurePerInterval);
            data.Add("totalNameErrorPerInterval", totalNameErrorPerInterval);
            data.Add("totalRefusedPerInterval", totalRefusedPerInterval);
            data.Add("totalBlockedPerInterval", totalBlockedPerInterval);
            data.Add("totalClientsPerInterval", totalClientsPerInterval);

            data.Add("topDomains", totalStatCounter.GetTopDomains());
            data.Add("topBlockedDomains", totalStatCounter.GetTopBlockedDomains());
            data.Add("topClients", totalStatCounter.GetTopClients());
            data.Add("queryTypes", totalStatCounter.GetTopQueryTypes());

            return(data);
        }