Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r "System.Windows.Forms"
- using System.Windows.Forms;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Drawing2D;
- using System.Net;
- using System.Web;
- HttpWebRequest hwr = HttpWebRequest.CreateHttp("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv");
- class Stat
- {
- public DateTime Date { get; set; }
- public String State { get; set; }
- public int Fips { get; set; }
- public int Cases { get; set; }
- public int Deaths { get; set; }
- }
- List<Stat> stats = new List<Stat>();
- using (var r = hwr.GetResponse())
- using (var srs = r.GetResponseStream())
- using (var sr = new StreamReader(srs))
- {
- sr.ReadLine();
- String line = "";
- while ((line = sr.ReadLine()) != null)
- {
- var parts = line.Split(',');
- stats.Add(new Stat
- {
- Date = DateTime.Parse(parts[0]),
- State = parts[1],
- Fips = int.Parse(parts[2]),
- Cases = int.Parse(parts[3]),
- Deaths = int.Parse(parts[4])
- });
- }
- }
- int lastCases = 0;
- var info = stats.Where(x => x.State == "Washington")
- .Select(x => {
- var ret = new
- {
- Date = x.Date,
- Cases = x.Cases,
- Delta = x.Cases - lastCases,
- Deaths = x.Deaths
- };
- lastCases = x.Cases;
- return ret;
- })
- .ToList();
- Form x = (new Form()
- {
- Width = 1000,
- Height = 800,
- BackColor = Color.White
- });
- x.Paint += (s, e) => {
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- int offX = 10;
- float increment = (800 - 20) / (float)info.Count;
- float scaleCases = (600 - 40) / (float)info.Max(x => x.Cases);
- float scaleDeltas = (600 - 40) / (float)info.Max(x => x.Delta);
- int item = 0;
- e.Graphics.DrawLines(Pens.Blue, info.Select(x => new PointF(
- offX + (item++) * increment,
- 600 - 20 - scaleCases * x.Cases
- )).ToArray());
- item = 0;
- e.Graphics.DrawLines(Pens.Orange, info.Select(x => new PointF(
- offX + (item++) * increment,
- 600 - 20 - scaleCases * x.Delta
- )).ToArray());
- item = 0;
- e.Graphics.DrawLines(Pens.Red, info.Select(x => new PointF(
- offX + (item++) * increment,
- 600 - 20 - scaleCases * x.Deaths
- )).ToArray());
- for (int i = 0; i < info.Count; ++i)
- {
- e.Graphics.FillEllipse(Brushes.LightBlue, offX + i * increment - 2, 600 - 20 - scaleCases * info[i].Cases - 2, 4, 4);
- e.Graphics.FillEllipse(Brushes.Yellow, offX + i * increment - 2, 600 - 20 - scaleCases * info[i].Delta - 2, 4, 4);
- e.Graphics.FillEllipse(Brushes.Pink, offX + i * increment - 2, 600 - 20 - scaleCases * info[i].Deaths - 2, 4, 4);
- e.Graphics.DrawString(info[i].Cases.ToString() + "(" + (info[i].Deaths / (float)info[i].Cases * 100).ToString("0.00") + "%)", new Font("Segoe UI", 8), Brushes.Blue, offX + (i) * increment + 10, 600 - 20 - scaleCases * info[i].Cases);
- e.Graphics.DrawString(info[i].Delta.ToString(), new Font("Segoe UI", 8), Brushes.Orange, offX + (i) * increment + 10, 600 - 20 - scaleCases * info[i].Delta);
- e.Graphics.DrawString(info[i].Deaths.ToString(), new Font("Segoe UI", 8), Brushes.Red, offX + (i) * increment + 10, 600 - 20 - scaleCases * info[i].Deaths);
- }
- };
- x.Show();
- x.Invalidate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement