Beispiel #1
0
        public async Task <JObject> AggregateCalculations()
        {
            Task <string> FileContentsTask     = FileOperations.ReadfileAsync(CSVPath);
            Task <string> JSONMapTask          = FileOperations.ReadfileAsync(CountryContinentMapPath);
            string        FileContentsComplete = await FileContentsTask;

            string[] FileContents = FileContentsComplete.Split('\n');
            string   headerText   = FileContents[0];

            string[] headers = headerText.Replace("\"", "").Split(',');

            int IndexOfCountry    = Array.IndexOf(headers, "Country Name");;
            int IndexOfPopulation = Array.IndexOf(headers, "Population (Millions) 2012");
            int IndexOfGDP        = Array.IndexOf(headers, "GDP Billions (USD) 2012");

            string CountryContinentJSONFileContents = await JSONMapTask;

            var CountryContinentMap = JSONOperations.DeSerializeString(CountryContinentJSONFileContents);

            for (int i = 1; i < FileContents.Length - 1; i++)
            {
                List <string> RowOfData  = FileContents[i].Split(',').ToList();
                string        Country    = RowOfData[IndexOfCountry].Trim('\"');
                float         Population = float.Parse(RowOfData[IndexOfPopulation].Trim('\"'));
                float         Gdp        = float.Parse(RowOfData[IndexOfGDP].Trim('\"'));
                try
                {
                    string Continent = CountryContinentMap.GetValue(RowOfData[IndexOfCountry].Trim('\"')).ToString();
                    AggregatedData.AddOrUpdateAggGDPPopulation(Continent, Gdp, Population);
                }
                catch (Exception) { }
            }
            var JSONOutput     = JSONOperations.SerializeJObject(AggregatedData.AggGDPPopulation);
            var AggregatedJSON = JSONOperations.DeSerializeString(JSONOutput);

            FileOperations.WriteFileAsync(OutputPath, JSONOutput);
            return(AggregatedJSON);
        }