示例#1
0
def test_add_network_type_parameter():
    db = StatsDatabase(testing=True)
    db.load_data_castalia(castalia_output_file())

    # column name
    c_name = Column("name")
    # column SUM(data) AS data
    c_data = ColumnExpr("data", Operator(SUM, [ConstantExpr("data")]))
    # filter --> name = "Consumed Energy"
    f = Operator(EQ, [
        ColumnRef(DATA_TABLE.col["name"]),
        ConstantExpr("\"Consumed Energy\"")
    ])
    # create derived table containing the SUM of all "Consumed Energy"
    dt = DerivedTable("dt", [c_name, c_data], [DATA_TABLE], f,
                      [DATA_TABLE.col["name"]])

    # generate a view based on the above derived table
    create_view_for_derived(db, dt)

    # network parameter
    pm_node = PlotModel("parameter",
                        "network",
                        dt,
                        None, (dt.col["data"], ),
                        title="Total Consumed Energy")

    # create JsonOutput object
    jo = JsonOutput("simulation_results", "46345634563456")

    # fetch stats from db
    stats = db.execute("SELECT data FROM dt")

    # add parameter to jsonOutput object
    add_network_type_parameter(jo, pm_node, stats)

    correct_json = """{
  "node_parameter_results": [],
  "node_plot_results": [],
  "node_2_node_results": [],
  "network_parameter_results": [
    {
      "value": 19.371669999999998,
      "unit": "",
      "name": "Total Consumed Energy"
    }
  ],
  "type": "simulation_results",
  "network_plot_results": [],
  "simulation_id": "46345634563456"
}"""

    assert json.loads(correct_json) == json.loads(jo.get_json_string())
示例#2
0
def test_readCSV():
    data_list = [('foo', 'plan1', '12345'),
                 ('bar', 'plan2', '54321')]
    table = nsdTable("csvTable", [Column("name"), Column("node"), Column("data")], csv_data_file(), "csv", ["node"])
    d = StatsDatabase(testing=True)
    create_table(d, table)
    d.load_data_csv(table, node_mapping_file())
    dt = d.execute("SELECT * FROM csvTable")

    for i in data_list:
        assert(i in dt)

    d.conn.close()
示例#3
0
def test_execute():
    db = StatsDatabase(testing=True)
    db.load_data_castalia(castalia_output_file())

    assert db.execute("SELECT node,data FROM dataTable WHERE name = 'Consumed Energy'") == [(0, 6.79813), (1, 6.28785), (2, 6.28569)]
示例#4
0
def test_add_node2node_type_parameter():
    db = StatsDatabase(testing=True)
    db.load_data_castalia(castalia_output_file())

    # DerivedTable for node2node parameter
    q = Operator(EQ, [
        ColumnRef(DATA_TABLE.col["name"]),
        ConstantExpr("\"Packets received per node\"")
    ])
    dt = DerivedTable(
        "testn2n",
        [Column("node"), Column("n_index"),
         Column("data")], [DATA_TABLE], q)

    # node2node parameter
    pm_node = PlotModel("parameter",
                        "node2node",
                        dt, (dt.col["node"], dt.col["n_index"]),
                        (dt.col["data"], ),
                        title="Packets received per node")

    # generate a view based on the above derived table
    create_view_for_derived(db, dt)

    # create JsonOutput object
    jo = JsonOutput("simulation_results", "5678657421")

    # fetch stats from db
    stats = db.execute("SELECT node,n_index,data FROM testn2n")

    # add parameter to jsonOutput object
    add_node2node_type_parameter(jo, pm_node, stats)

    correct_json = """{
  "network_parameter_results": [],
  "node_plot_results": [],
  "network_plot_results": [],
  "simulation_id": "5678657421",
  "type": "simulation_results",
  "node_parameter_results": [],
  "node_2_node_results": [
    {
      "plots": [],
      "node2_id": 1,
      "node1_id": 0,
      "parameters": [
        {
          "name": "Packets received per node",
          "value": 60.0,
          "unit": ""
        }
      ]
    },
    {
      "plots": [],
      "node2_id": 2,
      "node1_id": 0,
      "parameters": [
        {
          "name": "Packets received per node",
          "value": 71.0,
          "unit": ""
        }
      ]
    }
  ]
}"""

    assert json.loads(correct_json) == json.loads(jo.get_json_string())
示例#5
0
def test_add_node_type_parameter():
    db = StatsDatabase(testing=True)
    db.load_data_castalia(castalia_output_file())

    # node parameter
    q = Operator(EQ, [
        ColumnRef(DATA_TABLE.col["name"]),
        ConstantExpr("\"Consumed Energy\"")
    ])
    rel = DerivedTable("test", [Column("node"), Column("data")], [DATA_TABLE],
                       q)
    create_view_for_derived(db, rel)
    pm_node = PlotModel("parameter",
                        "node",
                        rel, (rel.col["node"], ), (rel.col["data"], ),
                        select={"name": "Consumed Energy"},
                        title="Consumed Energy")

    # create JsonOutput object
    jo = JsonOutput("simulation_results", "243241234143141")

    # fetch stats from db
    stats = db.execute(
        "SELECT node, data FROM dataTable WHERE name = \"Consumed Energy\"")

    # add parameters to jsonOutput object
    add_node_type_parameter(jo, pm_node, stats)

    correct_json = """{
  "node_2_node_results": [],
  "node_parameter_results": [
    {
      "results": [
        {
          "name": "Consumed Energy",
          "unit": "",
          "value": 6.79813
        }
      ],
      "node_id": "0"
    },
    {
      "results": [
        {
          "name": "Consumed Energy",
          "unit": "",
          "value": 6.28785
        }
      ],
      "node_id": "1"
    },
    {
      "results": [
        {
          "name": "Consumed Energy",
          "unit": "",
          "value": 6.28569
        }
      ],
      "node_id": "2"
    }
  ],
  "simulation_id": "243241234143141",
  "node_plot_results": [],
  "type": "simulation_results",
  "network_plot_results": [],
  "network_parameter_results": []
}"""

    assert json.loads(correct_json) == json.loads(jo.get_json_string())