コード例 #1
0
        public static void getPopularGraph(HttpListenerContext request)
        {
            DateTime timestamp = DateTime.Now.ToUniversalTime();
            Dictionary <string, List <int> > graphvalues = new Dictionary <string, List <int> >();
            List <string> labels  = new List <string>();
            int           highest = 10;
            int           days    = 10;
            List <Script> scripts = new List <Script>();

            foreach (KeyValuePair <Script, int> scriptvalue in Program.getpopular(10))
            {
                scripts.Add(scriptvalue.Key);
            }
            for (int i = days - 1; i >= 0; i--)
            {
                YAMLConfiguration file = Program.getlog(Program.GetFileIDForTimestamp(timestamp.AddDays(i * -1)));
                labels.Add(timestamp.AddDays(i * -1).Day + "/" + timestamp.AddDays(i * -1).Month);
                for (int y = 0; y < 24; y++)
                {
                    foreach (Script script in scripts)
                    {
                        int amount = file.GetKeys(y + "." + script.ID).Count;
                        if (!graphvalues.ContainsKey(script.Name))
                        {
                            graphvalues.Add(script.Name, new List <int>());
                        }
                        graphvalues[script.Name].Add(amount);
                        if (highest < amount)
                        {
                            highest = amount;
                        }
                    }
                }
            }
            byte[] output = GraphRenderer.MultiLineGraph("popular", graphvalues, highest + 10, Math.Ceiling(highest / 10.0), days, 24, labels);
            request.Response.OutputStream.Write(output, 0, output.Length);
        }
コード例 #2
0
        public static byte[] GetGraph(Script script, int days, string data, string datavalue, ModeEnum mode)
        {
            data      = data.ToLowerFast();
            datavalue = datavalue?.ToLowerFast();
            DateTime timestamp = DateTime.Now.ToUniversalTime();

            switch (mode)
            {
            case ModeEnum.ADD:
            case ModeEnum.COUNT:
            case ModeEnum.AVERAGE:

            {
                List <double> graphvalues = new List <double>();
                List <string> labels      = new List <string>();
                int           highest     = 10;
                for (int i = days - 1; i >= 0; i--)
                {
                    YAMLConfiguration file = Program.getlog(Program.GetFileIDForTimestamp(timestamp.AddDays(i * -1)));
                    labels.Add(timestamp.AddDays(i * -1).Day + "/" + timestamp.AddDays(i * -1).Month);
                    for (int y = 0; y < 24; y++)
                    {
                        if (data == "servers")
                        {
                            int amount = file.GetKeys(y + "." + script.ID).Count;
                            graphvalues.Add(amount);
                            if (highest < amount)
                            {
                                highest = amount;
                            }
                        }
                        else
                        {
                            switch (mode)
                            {
                            case ModeEnum.ADD:
                                double count = 0;
                                foreach (string server in file.GetKeys(y + "." + script.ID))
                                {
                                    count += file.ReadDouble(y + "." + script.ID + "." + server + "." + data, 0);
                                }
                                if (highest < count)
                                {
                                    highest = Convert.ToInt32(Math.Ceiling(count));
                                }
                                graphvalues.Add(count);
                                break;

                            case ModeEnum.COUNT:
                                int count2 = 0;
                                foreach (string server in file.GetKeys(y + "." + script.ID))
                                {
                                    if (file.ReadString(y + "." + script.ID + "." + server + "." + data, "").ToLowerFast() == datavalue)
                                    {
                                        count2++;
                                    }
                                }
                                if (highest < count2)
                                {
                                    highest = count2;
                                }
                                graphvalues.Add(count2);
                                break;

                            case ModeEnum.AVERAGE:
                                double        count3 = 0;
                                List <string> keys   = file.GetKeys(y + "." + script.ID);
                                foreach (string server in keys)
                                {
                                    count3 += file.ReadDouble(y + "." + script.ID + "." + server + "." + data, 0);
                                }
                                int keycount = keys.Count;
                                if (keycount < 1)
                                {
                                    keycount = 1;
                                }
                                count3 /= keycount;
                                if (highest < count3)
                                {
                                    highest = Convert.ToInt32(Math.Ceiling(count3));
                                }
                                graphvalues.Add(count3);
                                break;
                            }
                        }
                    }
                }
                return(GraphRenderer.BasicLineGraph(script.Name, graphvalues, highest, Math.Ceiling(highest / 10.0), days, 24, labels));
            }

            case (ModeEnum.MULTICOUNT):
            {
                Dictionary <string, List <int> > graphvalues = new Dictionary <string, List <int> >();
                List <string> labels    = new List <string>();
                int           highest   = 10;
                int           countsize = 0;
                for (int i = days - 1; i >= 0; i--)
                {
                    YAMLConfiguration file = Program.getlog(Program.GetFileIDForTimestamp(timestamp.AddDays(i * -1)));
                    labels.Add(timestamp.AddDays(i * -1).Day + "/" + timestamp.AddDays(i * -1).Month);
                    for (int y = 0; y < 24; y++)
                    {
                        Dictionary <string, int> loopvaluecount = new Dictionary <string, int>();
                        foreach (string server in file.GetKeys(y + "." + script.ID))
                        {
                            string currentvalue = file.ReadString(y + "." + script.ID + "." + server + "." + data, "").ToLowerFast();
                            int    count;
                            if (!string.IsNullOrWhiteSpace(currentvalue))
                            {
                                count = 1;
                            }
                            else
                            {
                                count = 0;
                            }
                            if (!loopvaluecount.ContainsKey(currentvalue))
                            {
                                loopvaluecount.Add(currentvalue, 0);
                            }
                            loopvaluecount[currentvalue] = loopvaluecount[currentvalue] + count;
                            if (!graphvalues.ContainsKey(currentvalue) && graphvalues.Keys.Count < 15 && !string.IsNullOrWhiteSpace(currentvalue))
                            {
                                graphvalues.Add(currentvalue, new List <int>());
                                for (int z = 0; z < countsize; z++)
                                {
                                    graphvalues[currentvalue].Add(0);
                                }
                            }
                        }
                        foreach (KeyValuePair <string, List <int> > currentvalue in graphvalues)
                        {
                            if (loopvaluecount.ContainsKey(currentvalue.Key))
                            {
                                graphvalues[currentvalue.Key].Add(loopvaluecount[currentvalue.Key]);
                                if (loopvaluecount[currentvalue.Key] > highest)
                                {
                                    highest = loopvaluecount[currentvalue.Key];
                                }
                            }
                            else
                            {
                                graphvalues[currentvalue.Key].Add(0);
                            }
                        }
                        countsize++;
                    }
                }
                return(GraphRenderer.MultiLineGraph(script.Name, graphvalues, highest, Math.Ceiling(highest / 10.0), days, 24, labels));
            }
            }
            return(null);
        }