Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Middleware/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
Expand Down
76 changes: 39 additions & 37 deletions Middleware/docs/examples/code/CalibrationExampleWithCITYdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
# USER CONFIGURATION
# ==========================
# Configuration
BASE_URL = "https://ngci.encs.concordia.ca/citydata"
USERNAME = username # Production username created by CITYdata team
PASSWORD = password # Production password created by CITYdata team
# BASE_URL = "http://localhost:8080/citydata"
# USERNAME = username # Local username created with the script (cf. README)
# PASSWORD = password # Local password created with the script (cf. README)
#BASE_URL = "https://ngci.encs.concordia.ca/citydata"
#USERNAME = "workshop" # Production username
#PASSWORD = "workshop2026" # Production password
BASE_URL = "http://localhost:8080"
USERNAME = "temp" # Local username
PASSWORD = "temp" # Local password



Expand All @@ -33,7 +33,7 @@ def print_result(response):
raw_data = response.get("result", "")
raw_data = raw_data.strip("[]")

parts = raw_data.split(", ")
parts =raw_data.split(", ")

print("\nResults:\n")
for i in range(0, len(parts), 3):
Expand All @@ -55,37 +55,39 @@ def fetch_consumption(base_url, token):
"Authorization": f"Bearer {token}"
}

# json_input = {
# "use": "ca.concordia.encs.citydata.producers.CalibrationProducer",
# "withParams": [
# { "name": "filePath", "value": "src/test/resources/OMHM_natural_gas.csv" }
# ],
# "apply": [
# {
# "name": "ca.concordia.encs.citydata.operations.CSVFilterOperation",
# "withParams": [
# { "name": "addressFilter", "value": "H1W3J9" },
# { "name": "dateFilter", "value": "2022-04-30" }
# ]
# }
# ]
# }

json_input = {
"use": "ca.concordia.encs.citydata.producers.CalibrationProducer",
"withParams": [
{ "name": "filePath", "value": "src/test/resources/OMHM_electricity.csv" }
],
"apply": [
{
"name": "ca.concordia.encs.citydata.operations.CSVFilterOperation",
"withParams": [
{ "name": "addressFilter", "value": "H1Z 0B3" },
{ "name": "dateFilter", "value": "2022-02-28" }
]
}
]
}
"use": "ca.concordia.encs.citydata.producers.CalibrationProducer",
"withParams": [
{ "name": "filePath", "value": "src/test/resources/OMHM_natural_gas.csv" }
],
"apply": [
{
"name": "ca.concordia.encs.citydata.operations.CSVFilterOperation",
"withParams": [
{ "name": "addressFilter", "value": "8431 Allée Léo-Bricault Montréal H1Z 0B3;8441 Allée Léo-Bricault Montréal H1Z 0B3;8425 Avenue 25e Montréal H1Z 4A9" },
{ "name": "startDateFilter", "value": "2022-01-31" },
{ "name": "endDateFilter", "value": "2022-12-31" }
]
}
]
}

# json_input = {
# "use": "ca.concordia.encs.citydata.producers.CalibrationProducer",
# "withParams": [
# { "name": "filePath", "value": "src/test/resources/OMHM_electricity.csv" }
# ],
# "apply": [
# {
# "name": "ca.concordia.encs.citydata.operations.CSVFilterOperation",
# "withParams": [
# { "name": "addressFilter", "value": "8431 Allée Léo-Bricault Montréal H1Z 0B3;8441 Allée Léo-Bricault Montréal H1Z 0B3;8425 Avenue 25e Montréal H1Z 4A9" },
# { "name": "startDateFilter", "value": "2022-01-31" },
# { "name": "endDateFilter", "value": "2022-12-31" }
# ]
# }
# ]
# }

response = requests.post(sync_url, headers=headers, data=json.dumps(json_input))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# USER CONFIGURATION
# ==========================
# Configuration
B ASE_URL = "https://ngci.encs.concordia.ca/citydata"
BASE_URL = "https://ngci.encs.concordia.ca/citydata"
USERNAME = "workshop" # Production username
PASSWORD = "workshop2026" # Production password
#BASE_URL = "http://localhost:8080/citydata"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
{
"use": "ca.concordia.encs.citydata.producers.PortfolioManagerProducer",
"use": "ca.concordia.encs.citydata.core.implementations.PortfolioManagerProducer",
"withParams": [
{
"name": "meterId",
"value": "299278275"
}
{ "name": "meterId", "value": meter_id }
],
"apply": [
{
"use": "ca.concordia.encs.citydata.producers.PortfolioManagerProducer",
"withParams": [
{ "name": "meterId", "value": "299278275" }
],
"apply": [
{
"name": "ca.concordia.encs.citydata.operations.XmlToJsonFilterOperation",
"withParams": [
{ "name": "filterKey", "value": "startDate" },
{ "name": "from", "value": "2024-11-01" },
{ "name": "to", "value": "2024-12-31" }
]
}
]
}
{
"name": "ca.concordia.encs.citydata.operations.XmlToJsonFilterOperation",
"withParams": [
{ "name": "filterKey", "value": "startDate" },
{ "name": "from", "value": "2020-11-01" },
{ "name": "to", "value": "2023-12-31" }
]
}
]
}
38 changes: 0 additions & 38 deletions Middleware/docs/examples/queries/mergeRandomNumberProducers.json

This file was deleted.

20 changes: 0 additions & 20 deletions Middleware/docs/examples/queries/randomNumberProducerFloor.json

This file was deleted.

10 changes: 0 additions & 10 deletions Middleware/docs/examples/queries/stringProducerRandom.json

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
* @since 2025-05-27
*/

public sealed abstract class AbstractProducer<E> extends AbstractEntity implements IProducer<E> permits JSONProducer,
CSVProducer, ExceptionProducer, FirebaseProducer, PortfolioManagerProducer, PortfolioManagerMetadataProducer {
public sealed abstract class AbstractProducer<E> extends AbstractEntity implements IProducer<E>
permits JSONProducer, CSVProducer, ExceptionProducer, FirebaseProducer, PortfolioManagerProducer,
PortfolioManagerMetadataProducer, JsonArrayProducer {
private String filePath;
private RequestOptions fileOptions;
private IOperation<E> operation;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ca.concordia.encs.citydata.core.implementations;

import java.io.OutputStream;
import java.util.ArrayList;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import ca.concordia.encs.citydata.core.contracts.IProducer;
import ca.concordia.encs.citydata.core.utils.RequestOptions;

/**
*This acts as a base producer for EnergyConsuimption Producer and any other producer that needs to return a JSON array.
*
* @author Sikandar Ejaz
* @since 2026-05-13
*/

public non-sealed class JsonArrayProducer extends AbstractProducer<JsonArray> implements IProducer<JsonArray> {

public JsonArrayProducer(final String filePath) {
super(filePath);
}

public JsonArrayProducer(final String filePath, final RequestOptions fileOptions) {
super(filePath, fileOptions);
}

@Override
public void fetch() {
final ArrayList<JsonObject> jsonOutput = new ArrayList<>();

// Use ByteArrayOutputStream to fetch data

OutputStream outputStream = this.fetchFromPath();
String inputJson = outputStream.toString();

// Convert JSON string to object
final JsonElement inputJsonElement = JsonParser.parseString(inputJson);

JsonObject outputJsonObject = new JsonObject();
if (inputJsonElement.isJsonArray()) {
outputJsonObject.add("result", inputJsonElement);
} else {
outputJsonObject = inputJsonElement.getAsJsonObject();
}

jsonOutput.add(outputJsonObject);
this.setResult(jsonOutput);
this.applyOperation();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public non-sealed class PortfolioManagerMetadataProducer extends AbstractProduce
private IOperation<JsonObject> operation;
private IRunner runnerObserver;

public PortfolioManagerMetadataProducer() {
super();
}

public PortfolioManagerMetadataProducer(String filePath, RequestOptions fileOptions) {
super(filePath, fileOptions);
}

public void setAccountId(String accountId) {
this.accountId = accountId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@
public non-sealed class PortfolioManagerProducer extends AbstractProducer<JsonObject> implements IProducer<JsonObject> {
private String meterId;
private final ArrayList<JsonObject> intermediateResult = new ArrayList<>();

public void setMeterId(String meterId) {
this.meterId = meterId;
}


public PortfolioManagerProducer() {
super();
}

public PortfolioManagerProducer(String filePath, RequestOptions fileOptions) {
super(filePath, fileOptions);
}

public void setMeterId(String meterId) {
System.out.println(">>> setMeterId called with: " + meterId);
this.meterId = meterId;
}

@SuppressWarnings("unchecked")
private ArrayList<JsonObject> getMeterMetadata(SingleStepRunner runner) {
final InMemoryDataStore store = InMemoryDataStore.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ArrayList<JsonArray> apply(ArrayList<JsonArray> inputs) {

// compute the average
for (JsonArray list : inputs) {
floatAverage = 0.0f;
for (JsonElement element : list) {
floatAverage += element.getAsJsonObject().get(keyName).getAsFloat();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import ca.concordia.encs.citydata.core.exceptions.MiddlewareException;
import ca.concordia.encs.citydata.core.implementations.CSVProducer;
import ca.concordia.encs.citydata.core.utils.RequestOptions;

/**
* This Producer outputs metadata about a building, such as floors, zones and sensors.
Expand All @@ -19,6 +20,10 @@ public CalibrationProducer(String filePath) {
super(filePath);
}

public CalibrationProducer(String filePath, RequestOptions fileOptions) {
super(filePath, fileOptions);
}

@Override
public void fetch() {
System.out.println("Fetching file from path: " + this.getFilePath());
Expand Down
Loading
Loading