Exemplo n.º 1
0
 public static FileInfo FindSolution(string path)
 {
     var solutions =  new DirectoryInfo(path).GetFiles("*.sln", SearchOption.AllDirectories);
     if (solutions.Length == 0)
         throw new Exception("No solution found");
     if (solutions.Length == 1)
         return solutions.First();
     // candidates.Length > 1
     var candidatesByDepth = solutions.GroupBy(x => x.FullName.Count(ch => ch == '/')).ToList();
     var minKey2 = candidatesByDepth.Min(x => x.Key);
     var topLevelCandidates = candidatesByDepth.First(x => x.Key == minKey2);
     if (topLevelCandidates.Count() == 1)
         return topLevelCandidates.First();
     //TopLevelCandidates > 1
     var dirName = Path.GetFileName(path);
     var matchesName = solutions.Where(x => x.Name == dirName).ToList();
     if (matchesName.Count == 1)
         return matchesName.First();
     throw new Exception("Could not find solution");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Convert LEAN data to custom data
        /// </summary>
        /// <param name="OutputResolution">Output resoltution for intraday cases (hour/minute/second)</param>
        /// <returns></returns>
        private static async Task Convert2CustomCSV(string OutputResolution)
        {
            var symbols = new DirectoryInfo(_settings.OutputFolder + @"/" + _settings.SecurityType + @"/bra/" + OutputResolution + @"/")
                .GetDirectories().ToList();

            if (_settings.InstrumentList.Length > 0) symbols.RemoveAll(s => !_settings.InstrumentList.Contains(s.Name.ToUpper()));

            if (symbols.Count == 0)
            {

            }

            var sum = 0.0;
            var total = 0.0;
            symbols.ForEach(d => total += d.GetFiles().Sum(f => f.Length));
            
            var roottime = DateTime.Now;
            Console.WriteLine("\r" + symbols.Count + " symbol directories to read (" + (total / 1024 / 1024).ToString("000.00") + " MB).\t" + roottime);

            foreach (var symbol in symbols)
            {
                var starttime = DateTime.Now;
                var factors = GetTickerFactors(symbol.Name);
                var zipfiles = symbol.GetFiles("*.zip").ToList();
                var csvFile = new FileInfo(symbol.Name.ToUpper() + "_" + _settings.OutputResolution + ".csv");
                if (csvFile.Exists) csvFile.Delete();

                foreach (var zipfile in zipfiles)
                {
                    var date = zipfile.Name.ToDateTime();
                    var factor = factors.FirstOrDefault(kvp => kvp.Key >= date);

                    File.AppendAllLines(csvFile.FullName, (await ReadAsyncZipFile(zipfile)).Select(l =>
                    {
                        var data = l.Split(',');

                        return symbol.Name.ToUpper() + ";" +
                            date.AddMilliseconds(data[0].ToInt64()).ToString(@"dd/MM/yyyy;HH\:mm\:ss") + ";" +
                            Math.Round(data[1].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            Math.Round(data[2].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            Math.Round(data[3].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            Math.Round(data[4].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            (data.Length == 6 ? data[5] : data[6] + ";" + data[5]);

                    }).ToArray());

                    sum += zipfile.Length;
                }

                Console.Write("\r" + (sum / total).ToString("0.00%") + "\t" + symbol.Name.ToUpper() + ": \t" + zipfiles.Count +
                " days were read/written in " + (DateTime.Now - starttime).ToString(@"ss\.ff") + " secs.\t");
            }

            // For options and futures
            var csvFiles = new DirectoryInfo(Environment.CurrentDirectory).GetFiles("*_" + _settings.OutputResolution + ".csv");

            if (csvFiles.Count() > 0)
            {
                sum = 0.0;
                total = csvFiles.Sum(f => f.Length);
                Console.WriteLine("Zipping " + (total / 1024 / 1024).ToString("000.00") + " MB");

                csvFiles.GroupBy(g =>
                {
                    if (_settings.SecurityType == "equity") return g.Name.Replace(".csv", ".zip");
                    if (_settings.SecurityType == "futures") return g.Name.Substring(0, 3).ToUpper() + "FUT" + "_" + _settings.OutputResolution + ".zip";

                    var type = ("ABCDEFGHIJKL".Contains(g.Name[4]) ? "_C" : "_P") + "_" + _settings.OutputResolution + ".zip";
                    return g.Name.Substring(0, 4) + type;
                })
                    //.ToList().ForEach(f =>
                    //{
                    //    var outputfile = new FileInfo(f.Key);
                    //    if (outputfile.Exists) outputfile.Delete();

                    //    Compression.Zip(outputfile.FullName);

                    //    using (var z = new FileStream(outputfile.FullName, FileMode.Create))

                    //    using (var a = new ZipArchive(z, ZipArchiveMode.Create, true))
                    //        f.ToList().ForEach(csvFile =>
                    //        {
                    //            a.CreateEntryFromFile(csvFile.FullName, csvFile.Name, CompressionLevel.Optimal);
                    //            csvFile.Delete();
                    //            sum += csvFile.Length;
                    //            Console.Write("\r" + (sum / total).ToString("0.00%") + "\tLast zippped file:\t" + csvFile.Name.ToUpper());
                    //        });
                    //})
                    ;
            }
            Console.WriteLine("\r\n... exiting routine at " + DateTime.Now);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the languages found in the languages directory.
        /// Sets the default language to english before looking at config file.
        /// Executes the commands specified in the configuration file.
        /// Returns a reference back to this object.
        /// </summary>
        public override ICoreController Execute() {
            var languageDirectories = new DirectoryInfo(Defines.PackagesDirectory.FullName)
                .GetDirectories(Defines.LocalizationDirectoryName, SearchOption.AllDirectories)
                .Union(new [] {
                    new DirectoryInfo(Defines.LocalizationDirectory.FullName)
                })
                .SelectMany(localizationDirectory => localizationDirectory.GetDirectories());

            // Loop over each grouped language
            foreach (var groupedLanguageDirectories in languageDirectories.GroupBy(directory => directory.Name)) {
                // Loop over each directory for this language, appending to the build language file.
                LanguageConfig language = null;

                foreach (var languageDirectory in groupedLanguageDirectories) {
                    if (language == null) {
                        language = new LanguageConfig();
                        language.Load(languageDirectory);
                    }
                    else {
                        language.Config.Union(new Config().Load(languageDirectory));
                    }
                }

                if (language != null && language.LanguageModel.LanguageCode != null) {
                    this.LoadedLanguageFiles.Add(language);
                }
            }

            this.AssignEvents();

            this.Shared.Variables.Variable(CommonVariableNames.LocalizationDefaultLanguageCode).Value = "en-GB";

            this.LoadDefaultLanguage();

            return base.Execute();
        }