/// <summary> /// Method to read the record state census csv file and check the file type,file path, delimeter and header . /// </summary> /// <param name="stateCensusFilePath"></param> /// <param name="delimeter"></param> /// <param name="header"></param> /// <returns></returns> public static object CsvStateCensusReadRecord(string stateCensusFilePath, char delimeter, string[] header) { CensusAnalyser stateCensusPathObject = new CensusAnalyser(stateCensusFilePath); object returnObject = stateCensusPathObject.ReadRecordCsvFile(stateCensusFilePath, delimeter, header); return(returnObject); }
static void Main(string[] args) { CensusAnalyser CensusAnalyse = new CensusAnalyser(); CensusAnalyse.ReadRecordCsvFile(filePath1, in_delimeter1, in_header1); CensusAnalyse.CountRecordsUSingMap(record); SortingJsonBasedOnKey(jsonFilePath1, key1); RetriveFirstDataOnKey(jsonPath1, key1); RetriveLastDataOnKey(jsonPath1, key1); }
/// <summary> /// Method to sorting the area of small area value /// </summary> /// <param name="filePath"></param> /// <param name="jsonFilepath"></param> /// <param name="key"></param> /// <returns></returns> public static string ReturnDataNumberOfStatesFirstDataSortCSVFileAndWriteInJson(string filePath, string jsonFilepath, string key) { string readFile = File.ReadAllText(filePath); StringBuilder stringbuilder = new StringBuilder(); using (var loadText = ChoCSVReader.LoadText(readFile) .WithFirstLineHeader()) { using (var writer = new ChoJSONWriter(stringbuilder)) writer.Write(loadText); } File.WriteAllText(jsonFilepath, stringbuilder.ToString()); JArray array = CensusAnalyser.SortJsonBasedOnKeyAndValueIsNumber(jsonFilepath, key); var jsonArray = JsonConvert.SerializeObject(array, Formatting.Indented); File.WriteAllText(jsonFilepath, jsonArray); return(CensusAnalyser.RetriveFirstDataOnKey(jsonFilepath, key)); }
/// <summary> /// Method to write the last state data using json /// </summary> /// <param name="filePath"></param> /// <param name="jsonFilepath"></param> /// <param name="key"></param> /// <returns></returns> public static string ReturnLastDataAfterSortingCsvFileWriteInJson(string filePath, string jsonFilepath, string key) { string readFile = File.ReadAllText(filePath); StringBuilder stringbuilder = new StringBuilder(); using (var loadText = ChoCSVReader.LoadText(readFile) .WithFirstLineHeader()) { using (var writer = new ChoJSONWriter(stringbuilder)) writer.Write(loadText); } File.WriteAllText(jsonFilepath, stringbuilder.ToString()); JArray array = CensusAnalyser.SortingJsonBasedOnKey(jsonFilepath, key); // serialize JSON to a string and then write string to a file var jsonArray = JsonConvert.SerializeObject(array, Formatting.Indented); File.WriteAllText(jsonFilepath, jsonArray); return(CensusAnalyser.RetriveLastDataOnKey(jsonFilepath, key)); }