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);
 }
        }// 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
        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);
            }
        }
Exemple #4
0
 private void MakeLCModels(string SMCFile)
 {
     System.Collections.Generic.List <float> source1    = new System.Collections.Generic.List <float>();
     System.Collections.Generic.List <float> source2    = new System.Collections.Generic.List <float>();
     System.Collections.Generic.List <float> source3    = new System.Collections.Generic.List <float>();
     System.Collections.Generic.List <float> floatList1 = new System.Collections.Generic.List <float>();
     System.Collections.Generic.List <float> floatList2 = new System.Collections.Generic.List <float>();
     System.Collections.Generic.List <float> floatList3 = new System.Collections.Generic.List <float>();
     _Models = new System.Collections.Generic.List <tMesh>();
     try
     {
         System.Collections.Generic.List <smcMesh> source4 = SMCReader.ReadFile(SMCFile);
         for (int index1 = 0; index1 < source4.Count(); ++index1)
         {
             if (LCMeshReader.ReadFile(source4[index1].FileName))
             {
                 tMeshContainer pMesh = LCMeshReader.pMesh;
                 source1.Add((pMesh.Vertices).Max((p => p.X)));
                 source2.Add((pMesh.Vertices).Max((p => p.Y)));
                 source3.Add((pMesh.Vertices).Max((p => p.Z)));
                 floatList1.Add((pMesh.Vertices).Min((p => p.X)));
                 floatList2.Add((pMesh.Vertices).Min((p => p.Y)));
                 floatList3.Add((pMesh.Vertices).Min(p => p.Z));
                 for (int index2 = 0; index2 < (pMesh.Objects).Count(); ++index2)
                 {
                     int     toVert    = (int)pMesh.Objects[index2].ToVert;
                     int     faceCount = (int)pMesh.Objects[index2].FaceCount;
                     short[] faces     = pMesh.Objects[index2].GetFaces();
                     CustomVertex.PositionNormalTextured[] data = new CustomVertex.PositionNormalTextured[toVert];
                     int fromVert = (int)pMesh.Objects[index2].FromVert;
                     for (int index3 = 0; index3 < pMesh.Objects[index2].ToVert; ++index3)
                     {
                         data[index3].Position = new Vector3(pMesh.Vertices[fromVert].X, pMesh.Vertices[fromVert].Y, pMesh.Vertices[fromVert].Z);
                         data[index3].Normal   = new Vector3(pMesh.Normals[fromVert].X, pMesh.Normals[fromVert].Y, pMesh.Normals[fromVert].Z);
                         try
                         {
                             data[index3].Texture = new Vector2(pMesh.UVMaps[0].Coords[fromVert].U, pMesh.UVMaps[0].Coords[fromVert].V);
                         }
                         catch
                         {
                             data[index3].Texture = new Vector2(0.0f, 0.0f);
                         }
                         ++fromVert;
                     }
                     VertexBuffer vertexBuffer = new VertexBuffer(_Device, (data).Count() * 32, Usage.None, VertexFormat.PositionNormal | VertexFormat.Texture1, Pool.Default);
                     Mesh         mesh         = new Mesh(_Device, (faces).Count() / 3, (data).Count(), MeshFlags.Managed, VertexFormat.PositionNormal | VertexFormat.Texture1);
                     DataStream   dataStream1;
                     using (dataStream1 = mesh.VertexBuffer.Lock(0, (data).Count() * 32, LockFlags.None))
                     {
                         dataStream1.WriteRange(data);
                         mesh.VertexBuffer.Unlock();
                     }
                     DataStream dataStream2;
                     using (dataStream2 = mesh.IndexBuffer.Lock(0, (faces).Count() * 2, LockFlags.None))
                     {
                         dataStream2.WriteRange(faces);
                         mesh.IndexBuffer.Unlock();
                     }
                     if ((uint)(pMesh.Weights).Count() > 0U)
                     {
                         string[] strArray = new string[(pMesh.Weights).Count()];
                         System.Collections.Generic.List <int>[]   intListArray   = new System.Collections.Generic.List <int> [(pMesh.Weights).Count()];
                         System.Collections.Generic.List <float>[] floatListArray = new System.Collections.Generic.List <float> [(pMesh.Weights).Count()];
                         for (int index3 = 0; index3 < (pMesh.Weights).Count(); ++index3)
                         {
                             strArray[index3]       = _Enc.GetString(pMesh.Weights[index3].JointName);
                             intListArray[index3]   = new System.Collections.Generic.List <int>();
                             floatListArray[index3] = new System.Collections.Generic.List <float>();
                             for (int index4 = 0; index4 < (pMesh.Weights[index3].WeightsMap).Count(); ++index4)
                             {
                                 intListArray[index3].Add(pMesh.Weights[index3].WeightsMap[index4].Index);
                                 floatListArray[index3].Add(pMesh.Weights[index3].WeightsMap[index4].Weight);
                             }
                         }
                         mesh.SkinInfo = new SkinInfo((data).Count(), VertexFormat.PositionNormal | VertexFormat.Texture1, (int)pMesh.HeaderInfo.JointCount);
                         for (int bone = 0; bone < (intListArray).Count(); ++bone)
                         {
                             mesh.SkinInfo.SetBoneName(bone, strArray[bone]);
                             mesh.SkinInfo.SetBoneInfluence(bone, intListArray[bone].ToArray(), floatListArray[bone].ToArray());
                         }
                     }
                     mesh.GenerateAdjacency(0.5f);
                     mesh.ComputeNormals();
                     Texture texture = null;
                     string  objName = _Enc.GetString(pMesh.Objects[index2].Textures[0].InternalName);
                     int     index5  = source4[index1].Object.FindIndex(x => x.Name.Equals(objName));
                     if (index5 != -1)
                     {
                         texture = GetTextureFromFile(source4[index1].Object[index5].Texture);
                     }
                     _Models.Add(new tMesh(mesh, texture));
                 }
             }
         }
     }
     catch
     {
     }
     try
     {
         _Zoom = (new float[3]
         {
             source1.Max(),
             source2.Max(),
             source3.Max()
         }).Max() * 3f;
     }
     catch
     {
     }
     slideZoom.Value = (int)_Zoom * 100;
 }