コード例 #1
0
 void GetStats(System.Collections.Generic.List <float> input, out float mean, out float median, out float min, out float max)
 {
     mean   = input.Average();
     min    = input.Min();
     max    = input.Max();
     median = input.OrderBy(sample => sample).ToList().ElementAt(input.Count / 2);
 }
コード例 #2
0
        }// end Reconnect code segment.

        private void axTws1_tickPrice(object sender, AxTWSLib._DTwsEvents_tickPriceEvent e)
        {
            // If the price is the Last Price, add it to the list of prices
            if (e.tickType == 4)
            {
                listOfPrices.Add(e.price);

                /* Not this is currently just adding the price from connection to the chart, we might need
                 * more data for functions */
                OurChart.ChartAreas[0].AxisY.Maximum = listOfPrices.Max() + .05;
                OurChart.ChartAreas[0].AxisY.Minimum = listOfPrices.Min() - .05;
                OurChart.Series["Price"].Points.AddY(e.price);
                if (listOfPrices.Count() > 19)
                {
                    OurChart.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "20", "Price", "SMA-20 D");
                    OurChart.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, "20", "Price", "EMA-20 D");
                }
            }
        }// end TWS tick price event handler
コード例 #3
0
        }         // end btnSubmit_Click

        private void axTws1_historicalData(object sender, AxTWSLib._DTwsEvents_historicalDataEvent e)
        {
            // Handle the incoming historical data records.
            // Object e contains:
            // e.date      Date (and time) of the historical data bar
            // e.open      The opening price of the bar/interval
            // e.high      The high price for the bar/interval
            // e.low       The low price for the bar/interval
            // e.close     The closing price of the bar/interval
            // e.volume    The volume (number of shares/contract) for the bar/interval
            // e.wAP       The average price during the bar/interval



            // Add data points to the chart
            if (e.close > 0.0)
            {
                histCloses.Add(e.close);

                chtStocks.Series["Closing Prices"].Points.AddXY(e.date, e.close);
                chtStocks.ChartAreas[0].AxisY.Minimum = histCloses.Min() - .5;
            } //end  axTws1_historicalData
        }
コード例 #4
0
        public void TestPerfData()
        {
            // Trace.TraceInformation("Starting TestPerfData");
            Trace.TraceInformation("Starting TestPerfData", "Information");
            try
            {
                var      account = Microsoft.WindowsAzure.CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
                var      context = new PerformanceDataContext(account.TableEndpoint.ToString(), account.Credentials);
                var      data    = context.PerfData;
                DateTime dtnow   = DateTime.UtcNow.AddMinutes(-30);
                DateTime dtnow2  = DateTime.UtcNow.AddMinutes(-20);
                System.Collections.Generic.List <PerformanceData> selectedData = (from d in data
                                                                                  where d.CounterName == @"\Processor(_Total)\% Processor Time" &&
                                                                                  d.EventTickCount >=
                                                                                  dtnow.Ticks && d.EventTickCount <=
                                                                                  dtnow2.Ticks &&
                                                                                  d.Role == "ProjectCS218"
                                                                                  select d).ToList <PerformanceData>();


                Trace.TraceInformation(selectedData.Count.ToString() + "  " + dtnow.Ticks + "  " + dtnow2.Ticks);;

                double AvgCPU = selectedData.Where(p => p.CounterName == @"\Processor(_Total)\% Processor Time").DefaultIfEmpty().Average(p => p == null ? 0 : p.CounterValue);

                /* double AvgCPU = (from d in selectedData
                 *                where d.CounterName == @"\Processor(_Total)\% Processor Time"
                 *                   select d.CounterValue).Average();*/

                //Trace.WriteLine("Average CPU == " + AvgCPU.ToString());
                Trace.TraceInformation("Average CPU == " + AvgCPU.ToString(), "Information Role Name");
                Trace.TraceInformation("Max Time Stamp CPU == " + selectedData.Max(item => item.Timestamp).ToString(), "Information");
                Trace.TraceInformation("Min Time Stamp CPU == " + selectedData.Min(item => item.Timestamp).ToString(), "Information");
                //test threshold
                if (AvgCPU >= 1)
                {
                    Trace.TraceInformation("Increase the instance by adding one more role" + AvgCPU.ToString(), "Information");
                    // Trace.TraceInformation(selectedData.Max(item => item.Timestamp).ToString(), "Information");
                    //Trace.TraceInformation(selectedData.Min(item => item.Timestamp).ToString(), "Information");
                    //increase instances

                    string deploymentInfo = AzureRESTMgmtHelper.GetDeploymentInfo();
                    string svcconfig      = AzureRESTMgmtHelper.GetServiceConfig(deploymentInfo);
                    int    InstanceCount  = System.Convert.ToInt32(AzureRESTMgmtHelper.GetInstanceCount(svcconfig, "ProjectCS218"));
                    if (InstanceCount == 1)
                    {
                        InstanceCount++;
                        Trace.TraceInformation("Average CPU == " + AvgCPU.ToString(), "Information" + " Instance Count increased by 1");
                        string UpdatedSvcConfig = AzureRESTMgmtHelper.ChangeInstanceCount(svcconfig, "ProjectCS218", InstanceCount.ToString());

                        AzureRESTMgmtHelper.ChangeConfigFile(UpdatedSvcConfig);
                    }
                }
                else if (AvgCPU < 1) //50
                {
                    Trace.TraceInformation("in the AvgCPU < 5 test.");

                    string deploymentInfo = AzureRESTMgmtHelper.GetDeploymentInfo();
                    string svcconfig      = AzureRESTMgmtHelper.GetServiceConfig(deploymentInfo);
                    int    InstanceCount  = System.Convert.ToInt32(AzureRESTMgmtHelper.GetInstanceCount(svcconfig, "ProjectCS218"));

                    if (InstanceCount > 1)
                    {
                        InstanceCount--;
                        string UpdatedSvcConfig = AzureRESTMgmtHelper.ChangeInstanceCount(svcconfig, "ProjectCS218", InstanceCount.ToString());

                        AzureRESTMgmtHelper.ChangeConfigFile(UpdatedSvcConfig);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Trace.TraceInformation(ex.StackTrace, "Information");
                Trace.WriteLine("Worker Role Error: " + ex.Message);
            }
        }