Amehiny
Amehiny

Reputation: 135

How to Calculate the distance passed by a car for a day, and for entire month

So I have three classes such as :

internal class Checkpoint
{
    public int Id { get; set; }
    public string Coordinates { get; set; }
}

internal class Log
{
    public DateTime TimeStamp { get; set; }
    public int CheckpointId { get; set; }

}

internal class User
{
    public int Id { get; set; }
    public string Coordinate { get; set; }
    public string Name { get; set; }

}

And I want to calculate the distcane the Car travels per day according to the registration points. If the user is registered at point A only, I get the coordinates of his home and calculate the distance between his home, the checking point A and back to his home. If he is registered in Point A and B , I take the coordinates from Home to A to B and then Back to Home.

So my program is as follows :

static void Main(string[] args)
    {


        var listOfUsers = new List<User>(); //get users from db
        var listOfCheckpoints = new List<Checkpoint>(); //get checkpoints from db
        StringBuilder sb = new StringBuilder();
        foreach (var user in listOfUsers)
        {
            string address = user.Coordinate;

            DateTime currentDate = new DateTime(2014, 8, 1);
            var dictionary = new Dictionary<string, double>();

            while (currentDate <= DateTime.Now)
            {
                double dayUserDistance = 0.00;
                var listOfUserLogs = new List<Log>(); //Get logs where day == currentDate from db
                var previousCoordinate = address;
                foreach (var log in listOfUserLogs)
                {

                    Checkpoint checkpoint = listOfCheckpoints.FirstOrDefault(x => x.Id == log.CheckpointId);


                    dayUserDistance += DistanceCalculator.GetDistance(previousCoordinate, checkpoint.Coordinates);
                    previousCoordinate = checkpoint.Coordinates;

                }
                dayUserDistance += DistanceCalculator.GetDistance(previousCoordinate, address);

                dictionary.Add(currentDate.ToString("yyyy-MM-dd"), dayUserDistance);

                currentDate = currentDate.AddDays(1);
            }

            sb.Append(user.Name + " ; ");
            foreach (KeyValuePair<string, double> keyValuePair in dictionary)
            {
                sb.Append(keyValuePair.Value + ";");
            }
            sb.AppendLine();
        }
        Console.WriteLine();
        Console.ReadLine();
    }
}

But when I run it I don't get anything printed in the Console. The console is blank.

Can you please let me know what I am missing. I have connected the database to the console app, since I have all the data needed in the database.

Upvotes: 0

Views: 141

Answers (2)

DrKoch
DrKoch

Reputation: 9782

From writing a line like

 var listOfUsers = new List<User>(); //get users from db

you just have an empty list. No data is read from the database. You have to add some code which reads records from the database and populates your listOfUsers.

And so on...

Upvotes: 2

Willz
Willz

Reputation: 78

You are not writing anything on the screen. Your code is reaching the Console.WriteLine and writing a blank line, and then on ReadLine it's waiting for text input.

Console.WriteLine(//what you want printed here);

Upvotes: 1

Related Questions