Beispiel #1
0
 public void Merge(PreCalculatedFeatures newPcs)
 {
     foreach (KeyValuePair <DateTime, Dictionary <string, double?> > bar in newPcs.Data)
     {
         if (!Data.ContainsKey(bar.Key))
         {
             Data.Add(bar.Key, bar.Value);
         }
         else
         {
             Data[bar.Key] = bar.Value;
         }
     }
 }
        public static void LoadExternalFeatureBinary(Asset asset, ExternalFeatureData externalFeature, MessageDelegate messageDelegate)
        {
            //Read the results into the bars from the binary file that python has written over
            PreCalculatedFeatures pcFeatures = new PreCalculatedFeatures();

            //[ASSET] is used as a placeholder so insert the assetname here
            string filename = externalFeature.BinaryFilepath.Replace("[ASSET]", asset.Name);

            byte[] bytes = File.ReadAllBytes(filename);

            //Traverse the byte array to add in the values to the Data attribute of the corresponding bar
            int i = 0;

            while (i < bytes.Length)
            {
                //Read the required data from the byte array and increment the index
                long timestamp = BitConverter.ToInt64(bytes, i);
                i += 8;
                //convert from python to .net date
                DateTime dt = DateTime.FromBinary(timestamp / 100).AddYears(1969);

                //Add a new bar
                Dictionary <string, double?> barData = new Dictionary <string, double?>();
                pcFeatures.Data.Add(dt, barData);

                foreach (string field in externalFeature.FieldNames)
                {
                    double val = BitConverter.ToDouble(bytes, i);
                    barData.Add(field, val);
                    i += 8;
                }
            }

            //add this data to the asset (or overwrite if exists)
            if (!asset.Data.ContainsKey(externalFeature.Timeframe))
            {
                asset.Data.Add(externalFeature.Timeframe, pcFeatures);
            }
            else
            {
                asset.Data[externalFeature.Timeframe] = pcFeatures;
            }
        }