/// <summary>
        ///
        /// </summary>
        /// <param name="objDataAnalysisHelper"></param>
        /// <returns></returns>
        public List <Person> GetPersonListFromFile(DataAnalysisHelper dataAnalysisHelper)
        {
            Error = string.Empty;
            List <Person> persons = new List <Person>();

            try
            {
                string currentDirectory = dataAnalysisHelper.GetCurrentDirectory();
                if (dataAnalysisHelper.Error == string.Empty)
                {
                    string filePath = System.IO.Path.Combine(currentDirectory, "CSVFiles", "dataOct-17-2018.csv");
                    persons = File.ReadAllLines(filePath)
                              .Skip(1)
                              .Select(v => this.ReadFromCsv(v, new Person()))
                              .ToList();
                }
                else
                {
                    Error = dataAnalysisHelper.Error;
                }
            }
            catch (Exception ex)
            {
                Error = string.Format("An unknown error occurred while reading Person List From File. Exception Details:::{0}", ex.InnerException);
            }
            return(persons);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            PrintHelper printHelper = new PrintHelper();

            printHelper.PrintText("Start Data Analysis.");
            printHelper.PrintText("::::::::::::::::::::");
            printHelper.PrintText("");
            try
            {
                DataAnalysisService dataAnalysisService = new DataAnalysisService();
                DataAnalysisHelper  dataAnalysisHelper  = new DataAnalysisHelper();

                /*
                 * Reading a text file and Binding to Person List,
                 *      This functionality will be changed if retrieved from database
                 *      Entity Framework/ADO.NET Can be used to retrive data from DB and Bind As a PersonList
                 */
                List <Person> personList = dataAnalysisService.GetPersonListFromFile(dataAnalysisHelper);

                if (dataAnalysisService.Error != string.Empty)
                {
                    printHelper.PrintText(dataAnalysisService.Error);
                }
                else
                {
                    //1) Distance of the people relating to -37.954, 144.615
                    List <PersonInformation> personInformationList = dataAnalysisService.GetPersonInformationList(personList, dataAnalysisHelper);

                    if (dataAnalysisService.Error == string.Empty)
                    {
                        //2) People within 1000 m of reference point
                        List <PersonInformation> personInfomationRelativeDistanceLessThanThousandMeters
                            = dataAnalysisService.GetPersonInfomationListRelativeDistanceLessThanThousandMeters
                                  (personInformationList, dataAnalysisHelper);

                        printHelper.PrintText(string.Format("People within 1000m of the reference point Lat {0} Long {1}.",
                                                            RelativePoint.LATTITUDE.ToString(),
                                                            RelativePoint.LONGITUDE.ToString()));

                        if (dataAnalysisService.Error != "")
                        {
                            printHelper.PrintText(dataAnalysisService.Error);
                        }
                        else
                        {
                            printHelper.PrintText(string.Format("No of People {0}", personInfomationRelativeDistanceLessThanThousandMeters.Count()));
                        }

                        //Break Point
                        printHelper.PrintText("");

                        //3) Top 10 people closest to reference point.
                        printHelper.PrintText(string.Format("Top 10 people closest to reference point Lat {0} Long {1}.", RelativePoint.LATTITUDE.ToString(), RelativePoint.LONGITUDE.ToString()));

                        List <PersonInformation> topTenPersonInfomationToRelativeDistance = dataAnalysisService.GettopTenPersonInfomationToRelativeDistance(personInformationList);
                        if (dataAnalysisService.Error != "")
                        {
                            printHelper.PrintText(dataAnalysisService.Error);
                        }
                        else
                        {
                            printHelper.PrintPersonInformation(topTenPersonInfomationToRelativeDistance);
                        }

                        //Break Point
                        printHelper.PrintText("");

                        //4) People with Attribute = 1
                        printHelper.PrintText(string.Format("People with Attribute 1.", RelativePoint.LATTITUDE.ToString(), RelativePoint.LONGITUDE.ToString()));

                        List <PersonInformation> personInfomationWithAttributeOne = dataAnalysisService.GetPersonInfomationWithAttributeOne(personInformationList);
                        if (dataAnalysisService.Error != "")
                        {
                            printHelper.PrintText(dataAnalysisService.Error);
                        }
                        else
                        {
                            printHelper.PrintPersonInformation(personInfomationWithAttributeOne);
                        }
                    }
                    else
                    {
                        printHelper.PrintText(dataAnalysisService.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                printHelper.PrintText(string.Format("Data Analysis Unexcepted Error Occured{0}", ex.StackTrace));
            }
            printHelper.PrintText("");
            printHelper.PrintText("::::::::::::::::::::");
            printHelper.PrintText("Stop Data Analysis");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="persons"></param>
        /// <param name="dataAnalysisHelper"></param>
        /// <returns></returns>
        public List <PersonInformation> GetPersonInformationList(List <Person> persons, DataAnalysisHelper dataAnalysisHelper)
        {
            Error = string.Empty;
            List <PersonInformation> personInformationList = new List <PersonInformation>();

            try
            {
                personInformationList = persons.Select(e =>
                                                       new PersonInformation
                {
                    LastName  = e.LastName,
                    FirstName = e.FirstName,
                    Attribute = e.Attribute,
                    Suburb    = e.Suburb,
                    PostCode  = e.PostCode,
                    Lat       = e.Lat,
                    Lon       = e.Lon,
                    RelativeDistance
                        =
                            dataAnalysisHelper.GetDistanceBetweenCoordinates(e.Lat, e.Lon, RelativePoint.LATTITUDE, RelativePoint.LONGITUDE)
                }
                                                       ).ToList();
            }
            catch (Exception ex)
            {
                Error = string.Format("An unknown error occurred while generating Person Information List. Exception Details:::{0}", ex.InnerException);
            }
            return(personInformationList);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="personInformationList"></param>
 /// <param name="dataAnalysisHelper"></param>
 /// <returns></returns>
 public List <PersonInformation> GetPersonInfomationListRelativeDistanceLessThanThousandMeters(List <PersonInformation> personInformationList, DataAnalysisHelper dataAnalysisHelper)
 {
     Error = string.Empty;
     return(personInformationList.Where(e => e.RelativeDistance <= 1).ToList());
 }