/FlashCard/WindowsFormsApplication1/Tabs/Stats.cs
C# | 280 lines | 218 code | 62 blank | 0 comment | 9 complexity | 441e8e3a928014653bbbf5743177bfbd MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using ZedGraph;
-
- namespace FlashCard
- {
- public partial class Stats : UserControl
- {
- private Deck<Word> wordDeck;
- private Deck<KanjiCharacter> kanjiDeck;
-
- public Stats()
- {
- InitializeComponent();
- }
-
- public void LoadDeck(Deck<Word> wordDeck, Deck<KanjiCharacter> kanjiDeck)
- {
- this.wordDeck = wordDeck;
- this.kanjiDeck = kanjiDeck;
-
- graphTypeBox.SelectedIndex = 1;
- }
-
- public void UpdateGraph()
- {
- switch (graphTypeBox.SelectedIndex)
- {
- case 0:
- UpdateHistoryGraph();
- break;
- case 1:
- UpdatePointGraph();
- break;
- case 2:
- UpdateMultiplierGraph();
- break;
- case 3:
- UpdateAverageGraph();
- break;
- default:
- break;
- }
- }
-
- private void graph_ZoomEvent(ZedGraphControl graph, ZoomState oldState, ZoomState newState)
- {
- GraphPane pane = graph.GraphPane;
- CurveItem curve = pane.CurveList.First();
-
- double max = 20;
-
- if (curve.Points.Count > 0)
- {
- max = curve.Points[curve.Points.Count - 1].X;
- }
-
- Scale scale = pane.XAxis.Scale;
-
- double difference = 5.0 - (scale.Max - scale.Min);
- if (difference > 0)
- {
- scale.Max += difference / 2.0;
- scale.Min -= difference / 2.0;
- }
-
- scale.Min = Math.Max(scale.Min, 1);
- scale.Max = Math.Min(scale.Max, max);
- }
-
- private void graphTypeBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- UpdateGraph();
- }
-
- private void bucketSizeControl_ValueChanged(object sender, EventArgs e)
- {
- UpdateGraph();
- }
-
- private void UpdateHistoryGraph()
- {
- GraphPane pane = graphControl.GraphPane;
- IList<int> pointHistory = wordDeck.CurrentCard.Stats.PointHistory;
-
- pane.CurveList.Clear();
- pane.Title.Text = wordDeck.CurrentCard.EnglishWord + " (" + wordDeck.CurrentCard.KanaWord + ") History";
-
- pane.XAxis.Title.Text = "Time";
- pane.XAxis.Scale.Min = Math.Max(1, pointHistory.Count - 20 + 1);
- pane.XAxis.Scale.Max = Math.Max(20, pointHistory.Count);
- pane.XAxis.Scale.MajorStep = 2;
- pane.XAxis.Scale.MinorStep = 1;
-
- pane.YAxis.Title.Text = "Points";
- pane.YAxis.Scale.Min = 0;
- pane.YAxis.Scale.Max = wordDeck.MaxPoints;
- pane.YAxis.Scale.MajorStep = 20;
- pane.YAxis.Scale.MinorStep = 10;
-
- graphControl.ScrollMinX = 1;
- graphControl.ScrollMaxX = pane.XAxis.Scale.Max;
-
- PointPairList list = new PointPairList();
- for (int i = 0; i < pointHistory.Count; i++)
- {
- list.Add(i + 1, pointHistory[i]);
- }
-
- LineItem curve = pane.AddCurve(string.Empty, list, Color.Blue, SymbolType.Circle);
-
- curve.Line.Width = 2.0f;
- curve.Symbol.Size = 8.0f;
- curve.Symbol.Fill = new Fill(Color.White);
- curve.Line.Fill = new Fill(Color.White, Color.Blue, 45.0f);
-
- graphControl.Refresh();
-
- graphControl.IsEnableHZoom = true;
- }
-
- private void UpdatePointGraph()
- {
- GraphPane pane = graphControl.GraphPane;
-
- pane.CurveList.Clear();
- pane.Title.Text = "Point Distribution";
-
- int bucketSize = (int)bucketSizeControl.Value;
-
- int minX = wordDeck.MaxPoints / 2;
- int[] points = new int[minX / bucketSize + 1];
-
- foreach (Word word in wordDeck.EnabledCards)
- {
- if (word.Stats.Points > minX)
- {
- points[(word.Stats.Points - minX) / bucketSize]++;
- }
- }
-
- double maxY = points.Max() * 1.1;
-
- pane.XAxis.Title.Text = "Points";
- pane.XAxis.Scale.Min = minX;
- pane.XAxis.Scale.Max = wordDeck.MaxPoints;
- pane.XAxis.Scale.MajorStep = 10;
- pane.XAxis.Scale.MinorStep = 5;
-
- pane.YAxis.Title.Text = "Number of Words";
- pane.YAxis.Scale.Min = 0;
- pane.YAxis.Scale.Max = maxY;
- pane.YAxis.Scale.MajorStep = Math.Floor(maxY / 10);
- pane.YAxis.Scale.MinorStep = double.MaxValue;
-
- graphControl.ScrollMinX = minX;
- graphControl.ScrollMaxX = wordDeck.MaxPoints;
-
- PointPairList list = new PointPairList();
- for (int i = 0; i < points.Length; i++)
- {
- list.Add(minX + i * bucketSize, points[i]);
- }
-
- LineItem curve = pane.AddCurve(string.Empty, list, Color.Green, SymbolType.Circle);
-
- curve.Line.Width = 2.0f;
- curve.Symbol.Size = 3.0f;
- curve.Symbol.Fill = new Fill(Color.Green);
- curve.Line.Fill = new Fill(Color.White, Color.Green, 45.0f);
-
- graphControl.Refresh();
-
- graphControl.IsEnableHZoom = false;
- }
-
- private void UpdateAverageGraph()
- {
- GraphPane pane = graphControl.GraphPane;
- IList<double> pointHistory = wordDeck.PointAverageHistory;
-
- pane.CurveList.Clear();
- pane.Title.Text = "Point Average History";
-
- pane.XAxis.Title.Text = "Time";
- pane.XAxis.Scale.Min = Math.Max(1, pointHistory.Count - 20 + 1);
- pane.XAxis.Scale.Max = Math.Max(20, pointHistory.Count);
- pane.XAxis.Scale.MajorStep = 2;
- pane.XAxis.Scale.MinorStep = 1;
-
- pane.YAxis.Title.Text = "Points";
- pane.YAxis.Scale.Min = wordDeck.PointCutOff;
- pane.YAxis.Scale.Max = wordDeck.MaxPoints;
- pane.YAxis.Scale.MajorStep = 10;
- pane.YAxis.Scale.MinorStep = 5;
-
- graphControl.ScrollMinX = 1;
- graphControl.ScrollMaxX = pane.XAxis.Scale.Max;
-
- PointPairList list = new PointPairList();
- for (int i = 0; i < pointHistory.Count; i++)
- {
- list.Add(i + 1, pointHistory[i]);
- }
-
- LineItem curve = pane.AddCurve(string.Empty, list, Color.Red, SymbolType.Circle);
-
- curve.Line.Width = 2.0f;
- curve.Symbol.Size = 8.0f;
- curve.Symbol.Fill = new Fill(Color.White);
- curve.Line.Fill = new Fill(Color.White, Color.Red, 45.0f);
-
- graphControl.Refresh();
-
- graphControl.IsEnableHZoom = true;
- }
-
- private void UpdateMultiplierGraph()
- {
- GraphPane pane = graphControl.GraphPane;
-
- pane.CurveList.Clear();
- pane.Title.Text = "Multiplier Distribution";
-
- double bucketSize = (double)(bucketSizeControl.Value / 10);
-
- double maxX = wordDeck.EnabledCards.Max(w => w.Stats.Multiplier);
-
- double[] multipliers = new double[(int)(maxX / bucketSize) + 1];
-
- foreach (Word word in wordDeck.EnabledCards)
- {
- if (word.Stats.Multiplier >= 0)
- {
- multipliers[(int)(word.Stats.Multiplier / bucketSize)]++;
- }
- }
-
- double maxY = multipliers.Max() * 1.1;
-
- pane.XAxis.Title.Text = "Multipliers";
- pane.XAxis.Scale.Min = 0;
- pane.XAxis.Scale.Max = maxX;
- pane.XAxis.Scale.MajorStep = maxX / 10;
- pane.XAxis.Scale.MinorStep = maxX / 20;
-
- pane.YAxis.Title.Text = "Number of Words";
- pane.YAxis.Scale.Min = 0;
- pane.YAxis.Scale.Max = maxY;
- pane.YAxis.Scale.MajorStep = Math.Floor(maxY / 10);
- pane.YAxis.Scale.MinorStep = double.MaxValue;
-
- graphControl.ScrollMinX = 0;
- graphControl.ScrollMaxX = maxX;
-
- PointPairList list = new PointPairList();
- for (int i = 0; i < multipliers.Length; i++)
- {
- list.Add(i * bucketSize, multipliers[i]);
- }
-
- LineItem curve = pane.AddCurve(string.Empty, list, Color.Black, SymbolType.Circle);
-
- curve.Line.Width = 2.0f;
- curve.Symbol.Size = 3.0f;
- curve.Symbol.Fill = new Fill(Color.Black);
- curve.Line.Fill = new Fill(Color.White, Color.Black, 45.0f);
-
- graphControl.Refresh();
-
- graphControl.IsEnableHZoom = false;
- }
- }
- }