static void Main(string[] args) { DataSourceManager dataSerieManager = new DataSourceManager(); // http://www.agmercados.com/dexx/strategies/exchanges/splits/splits.asp?opcion=dividendos //String symbol = "010060BBVA.MC"; String symbol = "010060TEF.MC"; DateTime initDate = new DateTime(2010, 1, 1); DateTime endDate = new DateTime(2011, 1, 1); DataSerie dataSerie = dataSerieManager.getSerie(symbol, enumCompressionType.Days, 1, initDate, endDate); Console.WriteLine("dataSerie.Size = " + dataSerie.Size); Console.WriteLine("initDate = " + dataSerie.InitDateTime); Console.WriteLine("endDate = " + dataSerie.EndDateTime); Console.WriteLine("Name = " + dataSerie.SymbolCode); foreach (BarValue bv in dataSerie) { Console.WriteLine(bv.ToString()); } ; }
public void LoadCompleted(DataSerie serie, ref List <pointXY> liveData, List <pointXY> dataLoggerData) { if (dataLoggerData.Count <= 0) { return; } if (liveData.Count > 0) { double lastTimeStamp = dataLoggerData[dataLoggerData.Count - 1].x; int n = 0; while ((n < liveData.Count) && (lastTimeStamp >= liveData[n].x)) { n++; } if (n > 0) { liveData.RemoveRange(0, n); } } liveData = (List <pointXY>)dataLoggerData.Concat(liveData).ToList(); MonitorGraph.DisableRedraw(); serie.clear(); serie.InsertPoints(liveData.ToArray()); MonitorGraph.AllowRedraw(); }
// GET: api/Serie public DataSerie[] Get() { DataSerie[] dataSeries = new DataSerie[] { }; try { string url = "https://www.banxico.org.mx/SieAPIRest/service/v1/series/SP74665/datos/"; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Accept = "application/json"; string bmxtoken = ConfigurationManager.AppSettings["BmxToken"].ToString().Trim(); request.Headers["Bmx-Token"] = bmxtoken; //"7129bfea1f989fca2990db9941007a1798de3b0d2cc6b508626aeb151700832c"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; if (response.StatusCode != HttpStatusCode.OK) { throw new Exception(String.Format("Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); } DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); Response jsonResponse = objResponse as Response; dataSeries = jsonResponse.seriesResponse.series[0].Data; return(dataSeries); } catch (Exception e) { Console.WriteLine(e.Message); } return(dataSeries); }
public void SetData(string serieName, DateTime date, decimal value) { using (var db = new DomoContext()) { DataSerie serie = db.DataSerie.FirstOrDefault(e => e.Name.Equals(serieName)); if (serie == null) { return; } db.Sample.Add(new Sample { Date = date, Value = value, SerieId = serie.Id }); db.SaveChanges(); } }
public bool CrossedUnder(DataSerie b, int lookback = 3) { lookback = Math.Abs(lookback); if (b.Count < lookback) { return(false); } decimal[] valuesB = new decimal[lookback]; for (int i = 0; i < lookback; i++) { valuesB[i] = b[i]; } return(CrossedUnder(valuesB, lookback)); }
private ExcelChart AddBarChart(ExcelWorksheet ws, string NameChart, eChartType type, List <DataSerie> ListSeries) { ExcelBarChart chart = ws.Drawings.AddChart(NameChart, eChartType.ColumnClustered) as ExcelBarChart; chart.Title.Font.Size = 18; chart.Title.Font.Bold = true; chart.Legend.Remove(); chart.YAxis.Border.Fill.Style = eFillStyle.NoFill; chart.YAxis.Font.Size = 9; chart.XAxis.MajorTickMark = eAxisTickMark.None; chart.XAxis.MinorTickMark = eAxisTickMark.None; chart.YAxis.MajorTickMark = eAxisTickMark.None; chart.YAxis.MinorTickMark = eAxisTickMark.None; for (int i = 0; i < ListSeries.Count; i++) { DataSerie dat = ListSeries[i]; ExcelBarChartSerie ser = (ExcelBarChartSerie)(chart.Series.Add(dat.Series, dat.xSeries)); ser.DataLabel.ShowValue = true; ser.DataLabel.Position = eLabelPosition.OutEnd; ser.Header = dat.name; if (dat.name == "Move") { ser.DataLabel.Border.Fill.Color = Color.Red; ser.DataLabel.Border.LineStyle = eLineStyle.Solid; } } chart.YAxis.Format = string.Format("{0};{1}", "#,##0", "(#,##0)"); return(chart); }
private string GenerateLineChart() { //Serie Collection List <DataSerie> series = new List <DataSerie>(); DataSerie Lula = new DataSerie() { SerieLabel = "Lula" }; List <DataPoint> LulaVotes = new List <DataPoint>() { new DataPoint() { ValueY = 30 }, //Each position corresponds to respective position in Categories (month in this case) array new DataPoint() { ValueY = 35 }, new DataPoint() { ValueY = 32 }, new DataPoint() { ValueY = 28 }, new DataPoint() { ValueY = 25 }, new DataPoint() { ValueY = 30 }, new DataPoint() { ValueY = 40 }, new DataPoint() { ValueY = 35 }, new DataPoint() { ValueY = 30 }, new DataPoint() { ValueY = 28 }, new DataPoint() { ValueY = 27 }, new DataPoint() { ValueY = 26 }, }; Lula.Points = LulaVotes.ToArray(); series.Add(Lula); DataSerie Bolsonaro = new DataSerie() { SerieLabel = "Bolsie" }; List <DataPoint> BolsonaroVotes = new List <DataPoint>() { new DataPoint() { ValueY = 20 }, new DataPoint() { ValueY = 25 }, new DataPoint() { ValueY = 12 }, new DataPoint() { ValueY = 18 }, new DataPoint() { ValueY = 15 }, new DataPoint() { ValueY = 20 }, new DataPoint() { ValueY = 30 }, new DataPoint() { ValueY = 25 }, new DataPoint() { ValueY = 20 }, new DataPoint() { ValueY = 18 }, new DataPoint() { ValueY = 17 }, new DataPoint() { ValueY = 16 }, }; Bolsonaro.Points = BolsonaroVotes.ToArray(); series.Add(Bolsonaro); //This serie have 10 points (other series have 12 points). Chart generation automatically fill last positions (10 values / 12 categories) with ValueY = 0 DataSerie Alckmin = new DataSerie() { SerieLabel = "Picolé de Chuchu" }; List <DataPoint> AlckminVotes = new List <DataPoint>() { new DataPoint() { ValueY = 0 }, //January value (category index 0) new DataPoint() { ValueY = 5 }, new DataPoint() { ValueY = 2 }, new DataPoint() { ValueY = 8 }, new DataPoint() { ValueY = 5 }, new DataPoint() { ValueY = 0 }, new DataPoint() { ValueY = 0 }, new DataPoint() { ValueY = 5 }, new DataPoint() { ValueY = 0 }, new DataPoint() { ValueY = 8 }, //October value (category index 9) //November value = 0 (auto fill) //December value = 0 (auto fill) }; Alckmin.Points = AlckminVotes.ToArray(); series.Add(Alckmin); //Categories Collection string[] months = { "Jan", "Fev", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; return(ChartHelper.Instance.GenerateLineChart("Voting intentions for 2018 Presidential Brazilian Elections", "Candidate", "% of votes", series.ToArray(), months, "2500 pepole sample", "votingChartContainer")); }
private string GenerateBarChart() { string[] requestTypes = { "Hardware", "Systems", "Network", "External" }; List <DataSerie> requests = new List <DataSerie>(); DataSerie opened = new DataSerie(); opened.SerieLabel = "Opened"; List <DataPoint> openedRequests = new List <DataPoint>() { new DataPoint() { ValueY = 102 }, //# of Opened Hardware requests new DataPoint() { ValueY = 50 }, //# of Opened System requests new DataPoint() { ValueY = 425 }, //# of Opened Network requests new DataPoint() { ValueY = 20 } //# of Opened External requests }; opened.Points = openedRequests.ToArray(); requests.Add(opened); DataSerie pending = new DataSerie(); pending.SerieLabel = "Pending"; List <DataPoint> pendingRequests = new List <DataPoint>() { new DataPoint() { ValueY = 50 }, //# of Pending Hardware requests new DataPoint() { ValueY = 40 }, //# of Pending System requests new DataPoint() { ValueY = 152 }, //# of Pending Network requests new DataPoint() { ValueY = 10 } //# of Pending External requests }; pending.Points = pendingRequests.ToArray(); requests.Add(pending); DataSerie solved = new DataSerie(); solved.SerieLabel = "Solved"; List <DataPoint> solvedRequests = new List <DataPoint>() { new DataPoint() { ValueY = 200 }, //# of Solved Hardware requests new DataPoint() { ValueY = 350 }, //# of Solved System requests new DataPoint() { ValueY = 400 }, //# of Solved Network requests new DataPoint() { ValueY = 15 } //# of Solved External requests }; solved.Points = solvedRequests.ToArray(); requests.Add(solved); return(ChartHelper.Instance.GenerateBarChart("Requests x State", "Request type", "nº of requests", requests.ToArray(), requestTypes, "", "requestChartContainer")); }
public void MonitorPanelDrawPanel() { int tabIndex = 0; SuspendLayout(); // // WarningResetMessage1 // if (MonitorMessage1 == null) { MonitorMessage1 = new System.Windows.Forms.Label(); } MonitorMessage1.Name = "MonitorMessage1"; MonitorMessage1.AutoSize = false; MonitorMessage1.TabIndex = tabIndex++; MonitorMessage1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); MonitorMessage1.Text = "Your device is gathering data at 0.1Hz, let the process run for several days to make sure that day/night temperature cycles are captured, then use this utility to analyze it and compute Temperature compensation. " + (RadioBtMonitor.Checked? " Once datalogger is loaded, you can export data at any time. ":"") + "Click on next to go back to the welcome page. You can also close this application, the capture process will still run in background."; MonitorMessage1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); Controls.Add(MonitorMessage1); if (MonitorGraphContainer == null) { MonitorGraphContainer = new PictureBox(); } MonitorGraphContainer.Name = "MonitorGraphContainer"; MonitorGraphContainer.TabIndex = tabIndex++; Controls.Add(MonitorGraphContainer); // // Export button // if (ExportButton == null) { ExportButton = new Button(); } this.ExportButton.Name = "ExportButton"; this.ExportButton.AutoSize = false; this.ExportButton.Size = new Size(75, 23); this.ExportButton.TabIndex = tabIndex++; this.ExportButton.Text = "Export.."; this.ExportButton.UseVisualStyleBackColor = true; this.ExportButton.Click += ExportButton_Click; ExportButton.Enabled = false; Controls.Add(ExportButton); ResumeLayout(false); NextButton.Visible = true; NextButton.Enabled = true; PrevButton.Visible = false; PrevButton.TabIndex = tabIndex++; NextButton.TabIndex = tabIndex++; MonitorPanelResize(); MonitorGraph = new YGraph(MonitorGraphContainer, null); MonitorGraph.DisableRedraw(); YAxis wAxis = MonitorGraph.addYAxis(); wAxis.showGrid = true; wAxis.visible = true; wAxis.legend.title = "Weight (" + ChoosedWeighScale.sensor.get_unit() + ")"; wAxis.highlightZero = true; YAxis tAxis = MonitorGraph.addYAxis(); tAxis.visible = true; tAxis.legend.title = "Temperature (" + ChoosedWeighScale.tsensor.get_unit() + ")"; tAxis.position = YAxis.HrzPosition.RIGHT; MonitorGraph.navigator.enabled = true; MonitorGraph.navigator.relativeheight = 12; MonitorGraph.xAxis.showGrid = true; monitor_wData = MonitorGraph.addSerie(); monitor_wData.yAxisIndex = wAxis.index; monitor_wData.color = Color.DarkBlue; wAxis.legend.font.color = monitor_wData.color; monitor_tData = MonitorGraph.addSerie(); monitor_tData.yAxisIndex = tAxis.index; monitor_tData.color = Color.DarkRed; tAxis.legend.font.color = monitor_tData.color; progressPanel = MonitorGraph.addDataPanel(); progressPanel.horizontalPosition = DataPanel.HorizontalPosition.RIGHTBORDER; progressPanel.verticalPosition = DataPanel.VerticalPosition.TOPBORDER; progressPanel.horizontalMargin = 5; progressPanel.verticalMargin = 5; progressPanel.panelHrzAlign = DataPanel.HorizontalAlign.LEFTOF; progressPanel.panelVrtAlign = DataPanel.VerticalAlign.BELOW; progressPanel.borderColor = Color.Black; progressPanel.borderthickness = 1; progressPanel.enabled = true; MonitorGraph.AllowRedraw(); WeightData = new List <pointXY>(); TempData = new List <pointXY>(); ChoosedWeighScale.genericSensor.registerTimedReportCallback(newGenericSensorData); ChoosedWeighScale.tsensor.registerTimedReportCallback(newTempSensorData); //MonitorLoadProgress(0); ChoosedWeighScale.LoadDataLogger(MonitorLoadCompleted, MonitorLoadProgress, true); }
public List <Models.DataSerie> ReadSerieINEGI(string SerieID, string fechainicio, string fechafin) { DataSerie resBan = new DataSerie(); List <Models.DataSerie> oresultado = new List <Models.DataSerie>(); List <Models.DataSerie> Resultado = new List <Models.DataSerie>(); string Token = "d33048f2-1ff9-089d-d7d5-eb5a00dbf702"; try { string responseText = string.Empty; try { string url = "https://www.inegi.org.mx"; string _url = url; string _token = Token; var client = new RestClient(string.Format("{0}/app/api/indicadores/desarrolladores/jsonxml/INDICATOR/" + SerieID + "/es/00/false/BIE/2.0/" + _token, _url)); //client.AddDefaultHeader("Authorization", _token); var request = new RestRequest(Method.GET); request.RequestFormat = DataFormat.Json; IRestResponse response = client.Execute(request); Newtonsoft.Json.Linq.JToken data = Newtonsoft.Json.Linq.JToken.Parse(response.Content); List <Models.DataSerie> resultado = new List <Models.DataSerie>(); Models.DataSerie dato = new DataSerie(); if (data.Last.Values().Count() > 0) { if (data.Last.Values().ToList().Count() > 0) { if (data.Last.Values().ToList()[0].Last.ToList().Count() > 0) { foreach (var d in data.Last.Values().ToList()[0].Last.ToList()[0].ToList()) { var datos = JObject.Parse(d.ToString()); var uno = datos.Values(); dato = new DataSerie(); dato.Date = uno.ToList()[0].ToString(); dato.Data = uno.ToList()[1].ToString(); resultado.Add(dato); } } } } DateTime dtfechaIni = Convert.ToDateTime(fechainicio); DateTime dtfechaIniFormato = Convert.ToDateTime(dtfechaIni.Year + "/" + dtfechaIni.Month + "/" + dtfechaIni.Day + " 00:00"); DateTime dtfechafin = Convert.ToDateTime(fechafin); DateTime dtfechaFinFormato = Convert.ToDateTime(dtfechafin.Year + "/" + dtfechafin.Month + "/" + dtfechafin.Day + " 23:59"); oresultado = resultado.Where(n => Convert.ToDateTime(n.Date) >= dtfechaIniFormato && Convert.ToDateTime(n.Date) <= dtfechaFinFormato).ToList(); Resultado = (from n in oresultado orderby n.Date ascending select n).ToList(); } catch (WebException wex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("ERROR:" + wex.Message + ". STATUS: " + wex.Status.ToString()); if (wex.Status == WebExceptionStatus.ProtocolError) { var response = ((HttpWebResponse)wex.Response); sb.AppendLine(string.Format("Status Code : {0}", response.StatusCode)); sb.AppendLine(string.Format("Status Description : {0}", response.StatusDescription)); try { StreamReader reader = new StreamReader(response.GetResponseStream()); sb.AppendLine(reader.ReadToEnd()); } catch (WebException ex) { throw; } } throw new Exception(sb.ToString(), wex); } catch (Exception ex) { throw; } //string url = "https://www.inegi.org.mx/app/api/indicadores/desarrolladores/jsonxml/INDICATOR/" + "493621" + "/es/00/false/BIE/2.0/" + Token + "?type=json"; //WebRequest request = WebRequest.Create(url); //WebResponse ws = request.GetResponse(); //JsonSerializer jsonSerializer = new JsonSerializer(typeof(DataListInegi)); //PanoramioData photos = (PanoramioData)jsonSerializer.Deserialize(ws.GetResponseStream()); /*HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; * * HttpWebResponse response = request.GetResponse() as HttpWebResponse; * if (response.StatusCode != HttpStatusCode.OK) * throw new Exception(String.Format( * "Server error (HTTP {0}: {1}).", * response.StatusCode, * response.StatusDescription)); * * //De esta forma se obtiene el JSON de la respuesta en una cadena. Esta cadena puede ser mapeada a objetos de la siguiente forma: */ //DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(DataListInegi)); //object c = jsonSerializer.ReadObject(ws.GetResponseStream()); /* * resBan = (DataListInegi)c; * * Respuesta.Add(resBan);*/ } catch (Exception e) { Console.WriteLine(e.Message); } return(Resultado); }
public void loadFile(string fname) { FileInfo fileInfo = new FileInfo(fname); DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); CultureInfo culture = CultureInfo.InvariantCulture; count = 0; using (var reader = new StreamReader(fname)) { while (!reader.EndOfStream && count < maxPoints) { var line = reader.ReadLine(); var values = line.Split(';'); if (values.Length < 3) { break; } if (values[0].Contains("stamp")) { continue; } stamp[count] = (DateTime.ParseExact(values[0], "yyyy.MM.dd HH:mm:ss.ff", culture) - epoch).TotalSeconds; temp[count] = float.Parse(values[1], culture); rawW[count] = float.Parse(values[2], culture); count++; } } if (count < 100) { count = 0; disable_textChangeEvents = true; dialogTitle.Text = "Invalid file"; errorMessage.Text = "CSV file with at least 100 lines and 3 columns expected"; errorMessage.Visible = true; progressBar.Visible = false; dialogButton.Text = "Close"; dialogPanel.Visible = true; return; } fileName.Text = fileInfo.Name; count -= 24; learnCount = 3 * count / 4; disable_textChangeEvents = false; chart.DisableRedraw(); tempData = chart.addSerie(); avgTempData = chart.addSerie(); deltaTempData = chart.addSerie(); rawWData = chart.addSerie(); predData = chart.addSerie(); errorData = chart.addSerie(); for (int i = 0; i < count; i++) { tempData.AddPoint(new pointXY() { x = stamp[i], y = temp[i] }); rawWData.AddPoint(new pointXY() { x = stamp[i], y = rawW[i] }); } chart.xAxis.min = stamp[count * 3 / 4]; chart.xAxis.max = stamp[count - 1]; tempData.legend = "Temperature"; tempData.color = Color.DarkRed; tempData.disabled = !showTemp.Checked; avgTempData.legend = "Avg.Temp."; avgTempData.color = Color.Red; avgTempData.disabled = !showAvg.Checked; deltaTempData.legend = "Delta.Temp."; deltaTempData.color = Color.DarkOrange; deltaTempData.disabled = !showDelta.Checked; rawWData.legend = "Zero Drift"; rawWData.color = Color.DarkBlue; rawWData.yAxisIndex = 1; rawWData.disabled = !showRawW.Checked; predData.legend = "Pred.Drift"; predData.color = Color.Blue; predData.yAxisIndex = 1; predData.disabled = !showPrediction.Checked; errorData.legend = "Residual Error"; errorData.color = Color.Black; errorData.yAxisIndex = 1; errorData.disabled = !showError.Checked; chart.AllowRedraw(); this.optimizeDeltaRate(); }