public void logStat(statItem item) { statType type = getStatType(item.statTypeName, item.moduleType.ToString()); if (type != null) { type.logStat(item); } else { Roboto.log.log("Tried to log stat " + item.statTypeName + " for " + item.moduleType + " but doesnt exist!", logging.loglevel.high); } }
public void registerStatType(string name, Type moduleType, System.Drawing.Color c, stats.displaymode displayMode = stats.displaymode.line, stats.statmode statMode = statmode.increment) { statType existing = getStatType(name, moduleType.ToString()); if (existing != null) { Roboto.log.log("Registering StatType " + name + " from " + moduleType.ToString() + ": already exists.", logging.loglevel.normal); existing.updateDisplaySettings(c, displayMode, statMode); } else { statType newST = new statType(name, moduleType.ToString(), c, displayMode, statMode); statsList.Add(newST); Roboto.log.log("Registering StatType " + name + " from " + moduleType.ToString() + " added.", logging.loglevel.warn); } }
/// <summary> /// Expecting a list of series names, which are the type and name, split with an ">", or can be a list of regex's /// </summary> /// <param name="series"></param> public Stream generateImage(List <string> series) { DateTime graphStartTime = DateTime.Now; //set up a windows form graph thing try { using (var ch = new Chart()) { ch.Width = 1200; ch.Height = 600; ch.TextAntiAliasingQuality = TextAntiAliasingQuality.High; Title t = new Title(Roboto.Settings.botUserName + " Statistics", Docking.Top, new System.Drawing.Font("Roboto", 14), Color.Black); ch.Titles.Add(t); ChartArea cha = new ChartArea("cha"); cha.BackColor = Color.FromArgb(200, 225, 255); cha.AxisX.Title = "Hours Ago"; //cha.AxisX.TitleFont = new System.Drawing.Font("Calibri", 11, System.Drawing.FontStyle.Bold); cha.AxisX.TitleFont = new System.Drawing.Font("Roboto", 11); cha.AxisX.MajorGrid.Interval = 6; cha.AxisY.Title = "Value / " + granularity.TotalMinutes.ToString() + " mins"; cha.AxisY.TitleFont = new System.Drawing.Font("Roboto", 11); //cha.AxisY.TitleFont = new System.Drawing.Font("Calibri", 11, System.Drawing.FontStyle.Bold); Legend l = new Legend("Legend"); l.DockedToChartArea = "cha"; l.IsDockedInsideChartArea = true; l.Docking = Docking.Right; ch.ChartAreas.Add(cha); ch.Legends.Add(l); //if nothing passed in, assume all stats if (series.Count == 0) { series.Add(".*"); } //gather all matching statTypes List <statType> matches = new List <statType>(); foreach (string s in series) { //populate list of statTypes that match our query. Dont worry about order / dupes - will be ordered later //try exact matches string[] titles = s.Trim().Split(">"[0]); if (titles.Length == 2) { //get the series info statType seriesStats = getStatType(titles[1], titles[0]); if (seriesStats != null) { matches.Add(seriesStats); } } //try regex matches List <statType> matchingTypes = getStatTypes(s); foreach (statType mt in matchingTypes) { matches.Add(mt); } } if (matches.Count == 0) { Roboto.log.log("No chart type matches", logging.loglevel.warn); return(null); } else { matches = matches.Distinct().OrderBy(x => x.moduleType + ">" + x.name).ToList(); foreach (statType seriesStats in matches) { ch.Series.Add(seriesStats.getSeries(graphStartTime)); } //ch.SaveImage(@"C:\temp\chart.jpg", ChartImageFormat.Jpeg); MemoryStream ms = new MemoryStream(); ch.SaveImage(ms, ChartImageFormat.Jpeg); return(ms); } } } catch (Exception e) { Roboto.log.log("Error generating chart. " + e.ToString(), logging.loglevel.critical); } return(null); }