The testbench is used for performance benchmarking of the Semantic API of the SemanticBMS middleware layer.

The Powershell scripts available in this toolset can be used for generating the sample data, loading them to the triple store
and running the performance benchmarks.

The generated data represent mock-up facility of an organization.
They consist of several sites and buildings. Each building is equipped with an PLC, an energy meter and two data points representing energy consumption - overall and last month.
Each room is equipped with a temperature sensor, a humidity sensor, a motion sensor and a PLC that publishes following data points:
 - Air temeprature
 - Air humidity
 - Setpoint temperature
 - Occupancy  

For each of the data points, there are two trends defined - one in the PLC iself, the other in the archive historian database.

Usage:

1)  [Optional] Run the script Generate-CSVs.ps1
    The script generates CSV files into the CSV-Data folder.
    Optional parameters:
        -Sites  [Default: 5] - number of sites in the dataset
        -Buildings [Default: 5] - number of buildings in each site
        -Floors [Default: 3] - number of floors in each building 
        -Rooms [Default: 10] - number of rooms in each floor 
    
    Pre-generated CSV files for the default configuration are available in the CSV-Data folder.

2)  [Optional] Run the script Generate-Triples.ps1
    The script generates an N-Triples file into the NT-Data folder, based on the CSV files located in the .\CSV-Data folder.

    Pre-generated NT file for the default test mock-up is available in the NT-Data folder.

    The process of Triples generation is universal and can be performed with existing CSV when using real facility data 
    instead of a generated mock-up created by Generate-CSVs script.

3)  Run the script Create-TDB.ps1
    The script will create the TDB triplestore using the Apache Jena framework.
    Optional parameters (no need to set them if they not differ from the defaults):
        -TDBPath [Default: .\NT-Data\tdb] - location of the resulting TDB directory
        -NTPath [Default: .\NT-Data\data.nt] - Path to the source NT file
        -JenaRoot [Default: C:\apache-jena-3.2.0] - Path to the directory with the Apache Jena distribution

4)  Set up the SemanticAPI to use the created TDB
    Update the tdb.path property in the semantics.properties file
    Check the ont-policy.rdf file and update paths to the local ontology definitions if needed

5)  Deploy the Semantic API into the Apache Tomcat
    To deploy the application:
        - Build the SemanticAPI project using maven:
            mvn install
            mvn war:exploded
        - Create a directory named sbms in the webapps folder of your tomcat installation (e.g. C:\apache-tomcat-9.0.0.M19\webapps)
        - Copy the resulting build (located in <Your git repositoty>\semanticBMS\SemanticAPI\target\SemanticAPI-1.0) 
            into the new directory directory (e.g. C:\apache-tomcat-9.0.0.M19\webapps\sbms) - the WEB-INF amnd META-INF folders 
            are meant to be placed directly in the sbms directory

6)  [Optional] Run the Apache Tomcat
    Execute the bin\startup.bat script
    This step is recommended if you plan to run several rounds of benchmarks, as the Tomcat container is not started each time
    the tests are executed

7)  Run the script Performance-Test.ps1
    The srcipt will start the performance benchmark and outputs the result to standard output 
    (Use .\Performance-Test.ps1 | OutFile results.txt to redirect it to a file)
    
    If you did not start the Apache Tomcat in the previous step, use the -ManageTomcat switch. You can also set the path to 
    the Apache Tomcat installation directory by the -TomcatHome param (Default is C:\apache-tomcat-9.0.0.M19)

8)  [Optional] Stop the Apache Tomcat
    Execute the bin\shutdown.bat script if you did not use the -ManageTomcat option and started the server manually in the step 6) 
 

