public string addTrip(string userID, string tripDate, string startTime,string data)
        {
            List<tripData> li = new List<tripData>();

                dbManager db = new dbManager();
                trip t = new trip();

                t.userID = Convert.ToInt32(userID);
                t.tripDate = tripDate;
                t.startTime = startTime;
                //get an id to link the data to the trip
                int tripID = db.addUserTrip(t);  //saves to database
                //process data string
                StringReader reader = new StringReader(data);
                string line;
                var context = new drivestatsEntities();
                using (var transactionScope = new TransactionScope())
                {
                    context.Configuration.AutoDetectChangesEnabled = false;
                    context.Configuration.ValidateOnSaveEnabled = false;
                    int count = 0;
                    while (reader.Peek() > -1)
                    {
                        count++;
                        tripData d = new tripData();
                        d.tripID = tripID;
                        line = reader.ReadLine();
                        string lat = line.Substring(1, line.IndexOf(',')-1);
                        line = line.Remove(0, lat.Length + 3);
                        string lon = line.Substring(0, line.IndexOf(']'));
                        line = line.Remove(0, lon.Length + 2);
                        string speed = line.Substring(0, line.IndexOf(';'));
                        line = line.Remove(0, speed.Length + 1);
                        string x = line.Substring(0, line.IndexOf(';'));
                        line = line.Remove(0, x.Length + 1);
                        string y = line.Substring(0, line.IndexOf(';'));
                        line = line.Remove(0, y.Length + 1);
                        string z = line.Substring(0, line.IndexOf(';'));
                        d.latitude = lat;
                        d.longitude = lon;
                        d.speed = speed;
                        d.maxXAcelerometer = x;
                        d.maxYAcelerometer = y;
                        d.maxZAcelerometer = z;
                        li.Add(d);
                    }
                    context.BulkInsert(li);
                    context.SaveChanges();
                    transactionScope.Complete();
                    if (userID == "1")//test client
                    {
                        return "5.3";
                    }
                }

            ScoreCalculator score = new ScoreCalculator(li,3);

            return score.getscore().ToString();
        }
示例#2
0
 public void inserTripData(tripData td)
 {
     using (var context = new drivestatsEntities())
     {
         context.tripDatas.Add(td);
         context.SaveChanges();
     }
 }
示例#3
0
 public trip getUserTrip(int id)
 {
     using (var context = new drivestatsEntities())
         {
             var query = context.trips.Where(t => t.ID == id);
             var result = query.First();
             return result;
         }
 }
示例#4
0
 public double getAverageScore()
 {
     double score = 0;
     using (var context = new drivestatsEntities())
     {
         score = (double)context.users.Select(u => u.averageScore).Average();
     }
     return score;
 }
示例#5
0
 public int addUserTrip(trip ut)
 {
     int id = -1;
     using (var context = new drivestatsEntities())
     {
         context.trips.Add(ut);
         context.SaveChanges();
         id = ut.ID;
     }
     return id;
 }
示例#6
0
 private void addUser(string email)
 {
     user newUser = new user();
     newUser.email = email;
     newUser.joinDate = DateTime.Now.ToShortDateString();
     newUser.averageScore = 0;
     using (var context = new drivestatsEntities())
     {
         context.users.Add(newUser);
         context.SaveChanges();
     }
 }
示例#7
0
 public string getUserID(string email)
 {
     string id = "-1";
     using (var context = new drivestatsEntities())
     {
         var query = context.users.Where(s => s.email == email);
         var dbuser = query.FirstOrDefault<user>();
         if (dbuser == null)
         {
             addUser(email);
             var queryNew = context.users.Where(s => s.email == email);
             var dbuserNew = query.FirstOrDefault<user>();
             id = dbuserNew.ID.ToString();
         }
         else
         {
             id = dbuser.ID.ToString();
         }
     }
     return id;
 }