public static void CreateCovidChart(CovidParser.Country country, CovidChartTypes type) { CovidParser.Country[] countries = new CovidParser.Country[1]; countries[0] = country; CreateCovidChart(countries, type); }
public static CovidParser.Country.Data GetWorldOnDate(CovidParser.Country world, DateTime date) { if (date == DateTime.MinValue) { return(world.data[world.data.Count - 1]); } string dt = DateToStr(date); for (int i = 0; i < world.data.Count; i++) { if (world.data[i].date == dt) { return(world.data[i]); } } Debug.LogError("Cannot find world data on " + dt); return(new CovidParser.Country.Data()); }
public void Execute(List <CovidParser.Country> data, CovidParser.Country world) { CovidParser.Country _country = null; CovidParser.Country.Data countryData = new CovidParser.Country.Data(); CovidParser.Country.Data prevCountryData = new CovidParser.Country.Data(); CovidParser.Country[] cTc = new CovidParser.Country[countriesToCompare.Length]; if (country == "world") { _country = world; countryData = GetWorldOnDate(world, date); if (date == DateTime.MinValue) { if (world.data.Count > 1) { prevCountryData = world.data[world.data.Count - 2]; } } else { DateTime prevDate = date.AddDays(-1); prevCountryData = GetWorldOnDate(world, prevDate); } } else { for (int i = 0; i < data.Count; i++) { if (data[i].name == country) { if (date == DateTime.MinValue) { _country = data[i]; countryData = data[i].data[data[i].data.Count - 1]; if (data[i].data.Count > 1) { prevCountryData = data[i].data[data[i].data.Count - 2]; } } else { string toFind = date.Year.ToString() + "-" + date.Month.ToString() + "-" + date.Day.ToString(); foreach (CovidParser.Country.Data country in data[i].data) { if (country.date == toFind) { _country = data[i]; countryData = country; break; } prevCountryData = country; } } //break; } for (int j = 0; j < countriesToCompare.Length; j++) { if (data[i].name == countriesToCompare[j]) { if (date == DateTime.MinValue) { cTc[j] = data[i]; } else { string toFind = DateToStr(date); foreach (CovidParser.Country.Data country in data[i].data) { if (country.date == toFind) { cTc[j] = data[i]; break; } } } } } } } if (_country == null) { RespondToCommand("Country ``" + country + "`` not found", channel); return; } if (param.info) { RespondToCommand(ParseData(countryData, prevCountryData, GetWorldOnDate(world, date), country), channel); } if (param.chart) { CovidParser.Country[] countries = new CovidParser.Country[countriesToCompare.Length + 1]; countries[0] = _country; for (int i = 0; i < cTc.Length; i++) { if (cTc[i] == null) { RespondToCommand("Cannot find country: " + countriesToCompare[i], channel); Debug.LogError("Cannot find country: " + countriesToCompare[i]); return; } countries[i + 1] = cTc[i]; } int start = 0; int end = 2147483647; if (startDate != DateTime.MinValue) { start = (startDate - StrToDate(world.data[0].date)).Days; Debug.Log("Start: " + start); } if (date != DateTime.MinValue) // end date { end = (date - StrToDate(world.data[0].date)).Days; Debug.Log("End: " + end); } CreateCovidChart(countries, CovidChartTypes.all, start, end); channel.Channel.SendFileAsync("covid.png"); } }