Esempio n. 1
0
        private static void insertMeasurementTest()
        {
            DBConnect db = new DBConnect();
            Measurement m = new Measurement();

            db.SaveMeasurement(m, db.getNewTrainingSessionId(1), 1);
        }
Esempio n. 2
0
        public override Measurement RecieveData()
        {
            TimeSpan runningTime = DateTime.Now.Subtract(_startTime); 

            Measurement m = new Measurement();
            m.DISTANCE = new Random().Next(0, 100);
            m.ENERGY = 25;
            m.POWER = 25;
            m.PULSE = 0;
            m.RPM = new Random().Next(24, 80);
            m.SPEED = new Random().Next(12, 50);
            m.TIME = String.Format("{0:00}:{1:00}", runningTime.Minutes, runningTime.Seconds);
            m.DATE = DateTime.Now;
            return m;
        }
Esempio n. 3
0
        protected Measurement ProtocolToMeasurement(String protocolData)
        {
            String[] values = protocolData.Split('\t');

            Measurement measurement = new Measurement();

            if (values.Length == 8)
            {
                int pulse = -1;
                int rpm = -1;
                int speed = -1;
                int distance = -1;
                int despwr = -1;
                int energy = -1;
                int actpwer = -1;

                Int32.TryParse(values[0], out pulse);
                Int32.TryParse(values[1], out rpm);
                Int32.TryParse(values[2], out speed);
                Int32.TryParse(values[3], out distance);
                Int32.TryParse(values[4], out actpwer);
                Int32.TryParse(values[5], out energy);
                String time = values[6];
                Int32.TryParse(values[7], out despwr);

                measurement.PULSE = pulse;
                measurement.RPM = rpm;
                measurement.SPEED = speed;
                measurement.DISTANCE = distance;
                measurement.POWER = despwr;
                measurement.ACT_POWER = actpwer;
                measurement.ENERGY = energy;
                measurement.TIME = time;

            }
            else
            {
                throw new ArgumentException("Invalid protocoldata given, Expected 8 parameters instead of "+values.Length);
            }
            return measurement;
        }
 public void SetMeasurement(Measurement m)
 {
     _data.Add(m);
     OnUpdatedList(new MeasurementEventArgs(m));
 }
 public MeasurementEventArgs(Measurement m)
 {
     Measurement = m;
 }
Esempio n. 6
0
 public void copy(Measurement m)
 {
     this.PULSE = m.PULSE;
     this.RPM = m.RPM;
     this.SPEED = m.SPEED;
     this.DISTANCE = m.DISTANCE;
     this.POWER = m.POWER;
     this.POWERPCT = m.POWERPCT;
     this.ACT_POWER = m.ACT_POWER;
     this.ENERGY = m.ENERGY;
     this.TIME = m.TIME;
     this.DATE = m.DATE;
 }
Esempio n. 7
0
 public void setMeasurement(Measurement m)
 {
     this.m = m;
 }
Esempio n. 8
0
        public List<Measurement> getMeasurementsOfUser(String username, string sessionID)
        {
            OpenConnection();
            List<Measurement> measurements = new List<Measurement>();

            string query;
            query = String.Format("select RPM, speed, distance, power, energy, pulse, user_id, datetime, time from {0}.measurement ", _database);

            int userID= -1;
            Boolean check = Int32.TryParse(username, out userID);
            if (check && userID > -1)
            {
                query += String.Format("WHERE user_id = {0} ",username);
            }
            else {
                query += String.Format(" LEFT JOIN users on users.id = measurement.user_id WHERE username = '******' ", username);
            }
            int ID;
            Int32.TryParse(sessionID,out ID);
            query += String.Format("AND session_id = {0} ", ID);

            _selectCommand = new MySqlCommand(query, Connection);
            _reader = _selectCommand.ExecuteReader();

            try
            {
                while (_reader.Read())
                {
                    Measurement m = new Measurement();

                    m.RPM = _reader.GetInt32(0);
                    m.SPEED = _reader.GetInt32(1);
                    m.DISTANCE = _reader.GetInt32(2);
                    m.ACT_POWER = _reader.GetInt32(3);
                    m.POWER = _reader.GetInt32(3);
                    m.ENERGY = _reader.GetInt32(4);
                    m.PULSE = _reader.GetInt32(5);
                    m.DATE = _reader.GetDateTime(7);
                    string dt = _reader.GetString(8);
                    m.TIME = dt;
                    measurements.Add(m);
                }

            }
            catch (MySqlException e)
            {
                Console.WriteLine("Could not validate user. " + e.Message);
            }
            finally
            {
                Connection.Close();
            }

            return measurements;
        }
Esempio n. 9
0
        public Measurement getMeasurement(JToken userId, JToken username, JToken measurementID, JToken measurmentStart)
        {
            OpenConnection();
            Measurement m = new Measurement();
            try
            {

                string query;

                if (userId != null)
                {
                    query = String.Format("select measurement.RPM, speed, distance, power, energy, pulse, user_id, datetime, time from `{1}`.`measurments` where id ='{0}' ", userId, _database);
                }
                else
                {
                    query = String.Format("SELECT measurement RPM, speed, distance, power, energy, pulse, user_id, datetime, time FROM `{1}`.`measurement` LEFT JOIN users on `measurement`.`id` = `users`.`id` WHERE `username` = '{0}' ", username, _database);
                }

                if (measurmentStart == null)
                {
                    query += String.Format(" AND `measurement`.`id`= '{0}'", measurementID);
                }
                else
                {
                    query += String.Format(" AND `measurement`.`` = '{0}'", measurmentStart);
                    throw new InvalidOperationException("niet gesupport");
                }

                _selectCommand = new MySqlCommand(query,Connection);
                _reader = _selectCommand.ExecuteReader();
                

                while (_reader.Read())
                {

                    m.RPM = _reader.GetInt32(0);
                    m.SPEED = _reader.GetInt32(1);
                    m.DISTANCE = _reader.GetInt32(2);
                    m.ACT_POWER = _reader.GetInt32(3);
                    m.POWER = _reader.GetInt32(3);
                    m.ENERGY = _reader.GetInt32(4);
                    m.PULSE = _reader.GetInt32(5);
                    m.DATE = _reader.GetDateTime(7);
                }

            }
            catch (MySqlException e)
            {
                Console.WriteLine("Could not validate user. " + e.Message);
            }
            finally
            {
                Connection.Close();
            }



            return m;
        }
Esempio n. 10
0
        public bool SaveMeasurement(Measurement m, int sessionId, int userId) 
        {
            var measurementQuery = String.Format("INSERT INTO {0}.measurement(session_id, RPM, speed, distance, power, energy, pulse, user_id, datetime, time) VALUES('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}', '{9}', '{10}')",
                _database, sessionId, m.RPM, m.SPEED, m.DISTANCE, m.POWER, m.ENERGY,  m.PULSE, userId, m.DATE.ToString("yyyy-MM-dd HH:mm:ss.fff"),  ":00" + m.TIME);
            OpenConnection();
            _selectCommand = new MySqlCommand(measurementQuery, Connection);

            try
            {
                _reader = _selectCommand.ExecuteReader();
                _reader.Close();
                return true;
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Exception: DBConnect.saveClient(): " + ex.Message);
                throw;
            }
            finally
            {
                Connection.Close();
            }
        }