Permalink
Browse files

Added "basic" history screen + several bugfixes

  • Loading branch information...
1 parent e02a090 commit 04f1da01f48de6042c1a9f4752a764da09bd4dc2 @KBomba committed Mar 23, 2015
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Globalization;
+using System.Security.Cryptography;
+using System.Text;
namespace MinerControl
{
@@ -51,7 +54,7 @@ public static decimal ExtractDecimal(this object raw)
if (intValue.HasValue) return intValue.Value;
decimal parseValue;
- const NumberStyles style = NumberStyles.AllowDecimalPoint;
+ const NumberStyles style = NumberStyles.Any;
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
if (decimal.TryParse(raw.ToString(), style, culture, out parseValue)) return parseValue;
@@ -70,5 +73,75 @@ public static string GetString(this IDictionary<string, object> data, string key
if (!data.ContainsKey(key)) return null;
return data[key] is int ? (int) data[key] : 0;
}
+
+ private static double[] GetDecimalRepresentation(this string s)
+ {
+ byte[] bytes = Encoding.UTF8.GetBytes(s);
+ SHA256Managed sha256 = new SHA256Managed();
+ // We all love SHA256, don't we *cough*
+ byte[] hash = sha256.ComputeHash(bytes);
+ int average = 0;
+ byte xor1 = 170;
+ byte xor2 = 85;
+ byte xor3 = 127;
+ foreach (byte b in hash)
+ {
+ average += b;
+ xor1 ^= b;
+ xor2 ^= b;
+ xor3 ^= b;
+ }
+
+ return new []{(xor1^(average/32)) / 255.0, xor2/1275.0, xor3/1275.0 };
+ }
+
+ private static Color GetColorRepresentation(this double[] d)
+ {
+ // Decimal number to Color by using HSL, HSL to RGB taken from:
+ // http://www.codeproject.com/Articles/19045/Manipulating-colors-in-NET-Part
+ double hk = d[0];
+ double l = 0.4 + d[1];
+ double s = 0.8 + d[2];
+
+ double q = (l < 0.5) ? (l * (1.0 + s)) : (l + s - (l * s));
+ double p = (2.0 * l) - q;
+
+ double[] T = new double[3];
+ T[0] = hk + (1.0 / 3.0); // Tr
+ T[1] = hk; // Tb
+ T[2] = hk - (1.0 / 3.0); // Tg
+
+ for (int i = 0; i < 3; i++)
+ {
+ if (T[i] < 0) T[i] += 1.0;
+ if (T[i] > 1) T[i] -= 1.0;
+
+ if ((T[i] * 6) < 1)
+ {
+ T[i] = p + ((q - p) * 6.0 * T[i]);
+ }
+ else if ((T[i] * 2.0) < 1)
+ {
+ T[i] = q;
+ }
+ else if ((T[i] * 3.0) < 2)
+ {
+ T[i] = p + (q - p) * ((2.0 / 3.0) - T[i]) * 6.0;
+ }
+ else T[i] = p;
+ }
+
+ return Color.FromArgb((int)(T[0] * 255.0), (int)(T[2] * 255.0), (int)(T[1] * 255.0));
+ }
+
+ public static Color GetColorRepresentation(this string s)
+ {
+ return s.GetDecimalRepresentation().GetColorRepresentation();
+ }
+
+ public static string Remove(this string s, string removal)
+ {
+ return s.Replace(removal, String.Empty).Trim();
+ }
}
}
@@ -0,0 +1,106 @@
+namespace MinerControl.History
+{
+ partial class HistoryChart
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+ System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
+ System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
+ this.chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
+ ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
+ this.SuspendLayout();
+ //
+ // chart
+ //
+ chartArea1.AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
+ chartArea1.AxisX.IsMarginVisible = false;
+ chartArea1.AxisX.IsStartedFromZero = false;
+ chartArea1.AxisX.LabelStyle.Format = "HH:mm:ss";
+ chartArea1.AxisY.IsLabelAutoFit = false;
+ chartArea1.AxisY.IsStartedFromZero = false;
+ chartArea1.AxisY.ScaleBreakStyle.BreakLineStyle = System.Windows.Forms.DataVisualization.Charting.BreakLineStyle.Wave;
+ chartArea1.AxisY.ScaleBreakStyle.CollapsibleSpaceThreshold = 50;
+ chartArea1.AxisY.ScaleBreakStyle.Enabled = true;
+ chartArea1.AxisY.ScaleBreakStyle.MaxNumberOfBreaks = 1;
+ chartArea1.CursorX.AutoScroll = false;
+ chartArea1.CursorX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
+ chartArea1.CursorX.IsUserEnabled = true;
+ chartArea1.CursorX.IsUserSelectionEnabled = true;
+ chartArea1.CursorY.AutoScroll = false;
+ chartArea1.CursorY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
+ chartArea1.Name = "ChartArea";
+ this.chart.ChartAreas.Add(chartArea1);
+ this.chart.Cursor = System.Windows.Forms.Cursors.Default;
+ this.chart.Dock = System.Windows.Forms.DockStyle.Fill;
+ legend1.InterlacedRows = true;
+ legend1.InterlacedRowsColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
+ legend1.LegendStyle = System.Windows.Forms.DataVisualization.Charting.LegendStyle.Column;
+ legend1.Name = "Legend";
+ this.chart.Legends.Add(legend1);
+ this.chart.Location = new System.Drawing.Point(0, 0);
+ this.chart.Name = "chart";
+ series1.BackSecondaryColor = System.Drawing.Color.Black;
+ series1.BorderColor = System.Drawing.Color.Black;
+ series1.BorderWidth = 10;
+ series1.ChartArea = "ChartArea";
+ series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
+ series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
+ series1.Legend = "Legend";
+ series1.MarkerBorderColor = System.Drawing.Color.Black;
+ series1.MarkerBorderWidth = 10;
+ series1.MarkerColor = System.Drawing.Color.Black;
+ series1.MarkerImageTransparentColor = System.Drawing.Color.Black;
+ series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Square;
+ series1.Name = "Series1";
+ series1.ShadowColor = System.Drawing.Color.Black;
+ series1.ShadowOffset = 10;
+ series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
+ this.chart.Series.Add(series1);
+ this.chart.Size = new System.Drawing.Size(903, 367);
+ this.chart.TabIndex = 0;
+ this.chart.Text = "chart";
+ this.chart.TextAntiAliasingQuality = System.Windows.Forms.DataVisualization.Charting.TextAntiAliasingQuality.SystemDefault;
+ this.chart.MouseClick += new System.Windows.Forms.MouseEventHandler(this.chart_MouseClick);
+ //
+ // HistoryChart
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.chart);
+ this.Name = "HistoryChart";
+ this.Size = new System.Drawing.Size(903, 367);
+ ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.DataVisualization.Charting.Chart chart;
+ }
+}
Oops, something went wrong.

0 comments on commit 04f1da0

Please sign in to comment.