Exemple #1
0
    public void InsertingSensorReading()
    {
        DBInstance dbInstance = new DBInstance("sensor_readings");

        dbInstance.InitialiseSQLiteConnection();

        string newTableName = "testTable";

        dbInstance.ExecuteNonQuery(SensorReadingTableDetails.CreateTableSQLString(newTableName));

        int numberOfRowsBeforeAddition = dbInstance.GetNumberOfRowsInTable(newTableName);

        Debug.Log("Number of rows in table before addition: " + numberOfRowsBeforeAddition);

        BaseSensorReading newSensorReading = new BaseSensorReading
        {
            sensorName = " ",
            sensorType = Sensor.Type.Interaction,
            areaName   = " "
        };

        newSensorReading.SetDateTime(1, 1, 1, 1, 1, 1);

        string insertSensorReadingString = SensorReadingTableDetails.InsertSensorReadingSQLString(newSensorReading, "testBookmark", 0, newTableName);

        Debug.Log(insertSensorReadingString);
        dbInstance.ExecuteNonQuery(insertSensorReadingString);

        int numberOfRowsAfterAddition = dbInstance.GetNumberOfRowsInTable(newTableName);

        Debug.Log("Number of rows in table after addition: " + numberOfRowsAfterAddition);

        dbInstance.ExecuteNonQuery(SensorReadingTableDetails.DropTableSQLString(newTableName));
        dbInstance.CloseSQLiteConnection();

        if (numberOfRowsBeforeAddition == numberOfRowsAfterAddition - 1)
        {
            Assert.Pass();
        }
        else
        {
            Assert.Fail();
        }
    }
Exemple #2
0
    /// <summary>
    /// Helper method which creates a base sensor reading object using the specified sensor
    /// reading data. Used to construct sensor reading objects from database data.
    /// </summary>
    /// <param name="sensorArea">Area of where sensor reading was generated.</param>
    /// <param name="sensorName">Unique identifier of sensor which generated the sensor reading.</param>
    /// <param name="year">Year (Date) of when sensor reading was generated.</param>
    /// <param name="month">Month (Date) of when sensor reading was generated.</param>
    /// <param name="day">Day (Date) of when sensor reading was generated.</param>
    /// <param name="hours">Hours (Time) of when sensor reading was generated.</param>
    /// <param name="minutes">Minutes (Time) of when sensor reading was generated.</param>
    /// <param name="seconds">Seconds (Time) of when sensor reading was generated.</param>
    /// <param name="sensorValue">Value associated with the sensor reading.</param>
    /// <param name="sensorType">Sensor type which generated the sensor reading.</param>
    /// <returns></returns>
    private BaseSensorReading ConstructSensorReading(string sensorArea, string sensorName,
                                                     int year, int month, int day, int hours, int minutes, int seconds, float sensorValue,
                                                     Sensor.Type sensorType)
    {
        BaseSensorReading newSensorReading;

        switch (sensorType)
        {
        // Float sensor reading format for light, temperature.
        case Sensor.Type.Light:
        case Sensor.Type.Temperature:
            newSensorReading = new FloatSensorReading
            {
                sensorValue = sensorValue,
            };
            break;

        // Boolean sensor reading format for presence, toggle
        case Sensor.Type.Presence:
        case Sensor.Type.Toggle:
            newSensorReading = new BoolSensorReading
            {
                sensorValue = Convert.ToBoolean(sensorValue)
            };
            break;

        // Base sensor reading format for interaction
        default:
            newSensorReading = new BaseSensorReading();
            break;
        }

        // Set the base attributes for the sensor reading
        newSensorReading.areaName   = sensorArea;
        newSensorReading.sensorName = sensorName;
        newSensorReading.sensorType = sensorType;
        newSensorReading.SetDateTime(year, month, day, hours, minutes, seconds);

        return(newSensorReading);
    }