private static List <EventDate> GetEvents(string country, CalendariumConfiguration calculated, int year, CalendarEnum calendar = CalendarEnum.Default) { var dates = calculated.GetDates(year, country, calendar); List <EventDate> _events = new List <EventDate>(); foreach (var _date in dates) { foreach (var _event in _date.Value.Events) { _events.Add(_event); } } return(_events.OrderBy(c => c.Date.OriginalDate).ThenByDescending(c => c.Name).ToList()); }
private static bool Check(string country, System.Collections.Generic.List <Referential> referential, CalendariumConfiguration cal, string region, List <string> listErrors) { if (country != "Algeria") { return(true); } if (!cal.GetKeys(country).Any()) { return(false); } Trace.WriteLine($"Starting {country.ToString()}"); var calendar = cal.GetConfigurationByCountry(country)[0].Calendar.GetCalendar(); foreach (var item in referential) { item.Date2 = GetExpectedDate(item, calendar); if (item.ObservedDate != null) { item.ObservedDate.Date2 = GetExpectedDate(item.ObservedDate, calendar); } } foreach (var item in referential.Where(c => c.Reconstitued && c.Date2 == c.ObservedDate.Date2).ToList()) { var it = referential.Where(c => c.DayName == item.DayName && !c.Reconstitued).ToList(); if (it.Count == 0) { } else { var it2 = it.Where(c => c.DayName == item.DayName && !c.Reconstitued).Select(c => ($"{c.Date2.Month}-{c.Date2.Day}")).Distinct().ToList(); if (it2.Count == 1) { item.Date2 = new DateTime(item.Date2.Year, it[0].Date2.Month, it[0].Date2.Day); //not specify calendar is wrong only if the calendar is not gregorian. } else { } } } var _l2 = referential.OrderBy(c => c.Date2).ToList(); foreach (var item in _l2) { var year = item.Date2.Year; List <EventDate> dates1 = GetEvents(country, cal, year, CalendarEnum.Default); // flat list List <EventDate> dates = GetEvents(dates1, item.DayName); if (dates.Count == 0) { listErrors.Add($"failed on '{item.DayName.Mark(Mark.Bold)}' expected : {item.Date2.ToString("D")} missing day\r\n"); } else { var date = dates.FirstOrDefault(c => c.Date == item.Date2); if (date == null) { if (CountryDebugger.CheckStop(country, item.DayName, item.Date2.Year)) { System.Diagnostics.Debugger.Break(); } if (dates.Count == 1) { listErrors.Add($"failed on '{item.DayName}' expected : {item.Date2.ToString("D")} and computed : {dates[0].Date.ToString("D")}\r\n"); } else { } } else { var date1 = dates[0]; if (item.ObservedDate != null) { if (date1.Observed.OriginalDate.Date != item.ObservedDate.Date2.Date) { listErrors.Add($"failed match observed date on '{item.DayName}' expected : {item.ObservedDate.Date2.ToString("D")} and computed : {date1.Observed.ToString("D")}\r\n"); } } else if (date1.Observed != null && date1.Observed.OriginalDate.Date.Date != date1.Date.OriginalDate.Date) { listErrors.Add($"missing observed date in expected referential on '{item.DayName}' computed : {date1.Observed.ToString("D")}\r\n"); } } } } return(true); }
public void GenerateReligiousTags() { var _items = GetDaysWithTags(); List <CountryConfiguration> _countries = GetCountriesFromSolution(); var dateCountries = CalendariumConfiguration.GetCalendarium(_countries.ToArray()); foreach (var item in _items) { foreach (var item2 in item.Value) { foreach (var item3 in item2.Value.Dates) { dateCountries.GetDate(item3, item.Key); } } } foreach (var country in _countries) { var trads = _items[country.Country]; foreach (var period in country.Periods) { var day = trads[period.Name] ?? trads[Helper.GetA(period.Name)]; if (day == null) { foreach (var item in trads) { if (item.Value.IsFix) { var dte = dateCountries.GetDate(item.Value.Dates.First(), country.Country, null); } } } } } //foreach (var country in _c) //{ // //var _country = _items[country.Value.Country]; // foreach (var item in country.Value.Periods) // _h.Add(item.Name); //} //foreach (var item in _h.OrderBy(c => c)) // Debug.WriteLine($"case \"{item}\":"); //_h.Clear(); //foreach (var item1 in _items) // foreach (var item2 in item1.Value) // foreach (var item3 in item2.Value.Translations.Where(c => c.Key == Language.English)) // _h.Add(item3.Value.Name.Trim('"').Trim()); //foreach (var item in _h.OrderBy(c => c)) // Debug.WriteLine($"return \"{item}\";"); //StringBuilder sb = new StringBuilder(); //List<religious> religious = new List<religious>(); //foreach (var item1 in _items.Values) // foreach (var item2 in item1) // { // StringBuilder sb2 = new StringBuilder(); // foreach (var item in item2.Value.Translations) // { // sb2.Append(item.Key.ToString()); // sb2.Append("="); // sb2.Append(item.Value.Name); // int c = 0; // do // { // c = sb2.Length; // var ch = sb2[sb2.Length - 1]; // if (char.IsNumber(ch) || char.IsWhiteSpace(ch) || ch == '#') // sb2.Remove(sb2.Length - 1, 1); // } while (sb2.Length != c); // sb2.Append(","); // } // sb2.Append(";"); // sb2.Append(string.Join(',', item2.Value.Tags)); // sb2.Append(";"); // if (item2.Value.IsFix) // { // var dt = item2.Value.Dates.First(); // sb2.Append($"{dt.Month}-{dt.Day};"); // } // else // { // foreach (var item3 in item2.Value.Dates) // { // sb2.Append(item3.ToString("d")); // sb2.Append(","); // } // } // sb2.Append(";"); // if (_h.Add(sb2.ToString())) // sb.AppendLine(sb2.ToString()); // sb2.Clear(); // } //var fileReligious = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Output", "religious.csv"); //if (File.Exists(fileReligious)) // File.Delete(fileReligious); //File.AppendAllText(fileReligious, sb.ToString()); //var txt = JsonConvert.SerializeObject(religious, Formatting.Indented); //File.AppendAllText(fileReligious, txt); }
public void TestChecked() { var dir = new System.IO.DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "Black.Beard.Calendarium", "Countries")); var loader = new ConfigurationLoader(dir).Load(); //.Where(c => c.Country == "Algeria").ToArray(); var result = new System.IO.FileInfo(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "..", "result.md")); //CountryDebugger.AutoStop.Rule = RuleEnum.Observed; //CountryDebugger.AutoStop.Country = "Algeria"; //CountryDebugger.AutoStop.DayName = "Hijri New Year"; //CountryDebugger.AutoStop.Year = 2013; var cal = CalendariumConfiguration.GetCalendarium ( loader ); List <string> listErrors = new List <string>(); StringBuilder sb = new StringBuilder(); sb.Mark(Mark.H1, "Check configuration result"); foreach (var item in loader.OfType <CountryConfiguration>()) { sb.Mark(Mark.H2, item.Country); sb.AppendLine(); listErrors.Clear(); var referential = Helper.Referential[item.Country] .OrderBy(c => c.DayName).ToList(); if (Check(item.Country, referential, cal, string.Empty, listErrors)) { if (listErrors.Any()) { foreach (var error in listErrors) { sb.AppendLine(error); } } else { sb.AppendLine("all tests are OK"); } } else { sb.Mark(Mark.Bold, "not implemented"); } sb.MarkHorizontalRule(); } if (result.Exists) { result.Delete(); } File.AppendAllText(result.FullName, sb.ToString()); }
public static CommandLineApplication CommandCompute(this CommandLineApplication app) { var cmd = app.Command("compute", (Action <CommandLineApplication>)(config1 => { config1.Description = "compute country"; config1.HelpOption(HelpFlag); var validator = new GroupArgument(config1, false); var outputName = validator.Argument("outputName", "name of the output csv file" , ValidatorExtension.EvaluateRequired ); var countYear = validator.Argument("CountYears", "count of years must be computed. (this argument is required)" , ValidatorExtension.EvaluateShort ); var countryName = validator.Argument("CountryName", "name of the country must be computed. (if this argument is missing all config will be computed)" , ValidatorExtension.EvaluateCountryName ); countryName.MultipleValues = true; //var countYear = validator.Option("", // "count of years must be computed. (1 year by default)" // , Va config1.OnExecute((Func <int>)(() => { if (validator.Evaluate() > 0) { return(2); } // Resolve arguments var Namecountries = countryName.Values.Select(c => c.ToLower()).ToList(); string file = outputName.Value; var d = Path.Combine(Directory.GetCurrentDirectory(), outputName.Value); short cYear = 1; if (short.TryParse((string)countYear.Value.ToString(), out short cc)) { cYear = cc; } // Initialisation parameters var loader = new ConfigurationLoader(Constants.RootPathConfig); List <CountryParameter> countriesToCompute = BuildListOfCountriesMustBeComputed(Namecountries); List <DefaultCountryConfiguration> _list = LoadConfigurations(countriesToCompute, loader); var _countries = CalendariumConfiguration.GetCalendarium(_list.ToArray()); // Init file if (File.Exists(d)) { File.Delete(d); } var t = "Name;StartDate;EndDate;ObservedDate;Country;Culture;Free;Calendar"; File.AppendAllLines(d, new string[] { t }); List <EventDate> dates = new List <EventDate>(); foreach (var countryToCompute in countriesToCompute) { if (countryToCompute.OnlineVersion != countryToCompute.LocalVersion) { Output.WriteLine($"{countryToCompute.Name} is not up to date"); } var items = _countries.GetNextDates(DateTime.Now, countryToCompute.Name, cYear * 365); foreach (var item in items) { foreach (var item2 in item.Value.Events) { dates.Add(item2); var dateEnd = item2.DateEnd?.ToString() ?? string.Empty; var dateObserved = item2.Observed?.ToString() ?? string.Empty; var y = $"{item2.Name};{item.Value.Date};{dateEnd};{dateObserved};{item2.Country};{item2.Culture};{item2.Free.ToString().ToLower()};{item2.CalendarUsedToBuild.ToString().Split('.')[2].Replace("Calendar", "")}"; File.AppendAllLines(d, new string[] { y }); } } } dates.ConvertList( "computed dates" , c => c.Name , c => c.Country , c => c.Culture , c => c.Date , c => c.DateEnd , c => c.Observed , c => c.Free , c => c.Region ) .PrintList() ; return(0); })); })); return(app); }