Skip to content

Commit

Permalink
Merge pull request #15 from Cambio-Project/add_remote_time_refinement
Browse files Browse the repository at this point in the history
101 - added remote time refinement
  • Loading branch information
julianbrott authored Mar 18, 2024
2 parents fbaa3dc + 9a0d624 commit 7e5b69e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
.angular
.idea
.vscode
dist

.git
.editorconfig
/.vscode/*
/node_modules
/proxy/node_modules
/e2e
/docs
.gitignore
Expand Down
46 changes: 28 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ version: "1"
name: "transient-behavior-requirement-optimizer"

services:
dashboard:
image: ghcr.io/cambio-project/transient-behavior-requirement-refiner:latest
ports:
- 8080:80

proxy:
build:
context: ./proxy
dockerfile: Dockerfile
network: host
ports:
- 3000:3000
networks:
- dashboardNetwork
depends_on:
- dashboard
extra_hosts:
- host.docker.internal:host-gateway
tbverifier:
image: ghcr.io/cambio-project/transient-behavior-verifier:latest
ports:
- 8083:5000
networks:
- dashboardNetwork

tqproprefiner:
image: ghcr.io/cambio-project/transient-behavior-requirement-refiner:latest
ports:
- 8080:80
networks:
- dashboardNetwork

proxy:
build:
context: ./proxy
dockerfile: Dockerfile
network: host
ports:
- 8070:8070
networks:
- dashboardNetwork
depends_on:
- tqproprefiner
extra_hosts:
- host.docker.internal:host-gateway

networks:
dashboardNetwork:
dashboardNetwork:
2 changes: 1 addition & 1 deletion proxy/prometheus.proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const axios = require('axios');
const cors = require('cors');
const stream = require("stream");
const app = express();
const port = 3000;
const port = 8070;

// handle arguments
const showHelp = () => {
Expand Down
58 changes: 47 additions & 11 deletions src/app/core/services/validation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { Absence } from 'src/app/shared/psp/sel/patterns/occurence/absence';
import { Universality } from 'src/app/shared/psp/sel/patterns/occurence/universality';
import { TimeBound } from 'src/app/shared/psp/constraints/time-bound';

//const VERIFIER_URL = "http://localhost:5000/monitor";
const VERIFIER_URL = "https://transient-behavior-verifier-abngcvp24a-uc.a.run.app/monitor";
// const VERIFIER_URL = "http://localhost:5000"; // local
const VERIFIER_URL = "http://localhost:8083"; // docker

@Injectable({
providedIn: 'root'
Expand All @@ -35,9 +35,12 @@ export class ValidationService {
predicate.predicateInfo
],
"measurement_source": "csv",
"measurement_points": dataset.measurementPoints
"measurement_points": dataset.measurementPoints,
"options": {
"create_plots": false
}
});
return this.sendRequest(request, predicate, dataset.file);
return this.sendRequest("monitor", request, predicate, dataset.file);
}

async validateProperty(dataset: Dataset, property: Property) {
Expand All @@ -53,13 +56,41 @@ export class ValidationService {
"specification_type": "psp",
"predicates_info": property.predicateInfos,
"measurement_source": "csv",
"measurement_points": dataset.measurementPoints
"measurement_points": dataset.measurementPoints,
"options": {
"create_plots": false
}
});
return this.sendRequest(request, property, dataset.file).then(validationResponse => {
return this.sendRequest("monitor", request, property, dataset.file).then(validationResponse => {
return validationResponse;
});
}

async refineTimeboundRemote(dataset: Dataset, property: Property): Promise<TimeBound | null> {

if (!property.propertySpecification || !property.predicateInfos) {
throw new Error('Invalid Property');
}

const request = JSON.stringify({
"behavior_description": "description",
"specification": property.propertySpecification,
"specification_type": "psp",
"predicates_info": property.predicateInfos,
"measurement_source": "csv",
"measurement_points": dataset.measurementPoints,
});

return this.sendRequest("refine_timebound", request, property, dataset.file)
.then(refinementResponse => {
if(refinementResponse.result === true) {
return refinementResponse.timebound;
}
return null;
});

}

async refineTimebound(dataset: Dataset, property: Property): Promise<TimeBound | null> {
const pattern = property.getPattern();

Expand All @@ -76,7 +107,10 @@ export class ValidationService {
while (lowerTimebound <= end && upperTimebound <= end) {
const propertyCandidate = Object.assign(Object.create(Object.getPrototypeOf(property)), property);
const patternCandidate = Object.assign(Object.create(Object.getPrototypeOf(pattern)), pattern);
const evaluatedTimebound = new Interval(new Event('Candidate' + lowerTimebound + ' to ' + upperTimebound), lowerTimebound, upperTimebound, 'time units');
const evaluatedTimebound = new Interval(
new Event('Candidate' + lowerTimebound + ' to ' + upperTimebound),
lowerTimebound, upperTimebound, 'time units'
);
patternCandidate.setSTimeBound(evaluatedTimebound);
propertyCandidate.setPattern(patternCandidate);
const validationResponse = await this.validateProperty(dataset, propertyCandidate);
Expand All @@ -87,7 +121,9 @@ export class ValidationService {
lowerTimebound++;
} else if (refinedInterval) {
refinedlowerTimebound = lowerTimebound = upperTimebound = refinedInterval.getLowerLimit();
}
} else {
lowerTimebound++;
}
} else if (refinedUpperTimebound === -1) {
if (validationResponse.result === true) {
refinedUpperTimebound = upperTimebound;
Expand Down Expand Up @@ -157,8 +193,7 @@ export class ValidationService {
return Promise.all(promises);
}

private sendRequest(request: string, validatedItem: Property | Event, file: File): Promise<ValidationResponse> {
console.log(request);
private sendRequest(endpoint: string, request: string, validatedItem: Property | Event, file: File): Promise<ValidationResponse> {
return new Promise((resolve, reject) => {
var formdata = new FormData();
formdata.append("formula_json", request);
Expand All @@ -170,7 +205,8 @@ export class ValidationService {
redirect: 'follow'
};

fetch(VERIFIER_URL, requestOptions)
let url = VERIFIER_URL + "/" + endpoint;
fetch(url, requestOptions)
.then(response => response.text())
.then(result => {
const response = JSON.parse(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class TimeboundConstraintRefinementComponent implements OnInit {

async refineTimeboundConstraint() {
this.isLoading = true;
this.refinedTimebound = await this.validationSvc.refineTimebound(this.dataset, this.property);
this.refinedTimebound = await this.validationSvc.refineTimeboundRemote(this.dataset, this.property);
this.isLoading = false;
this.plot(this.refinedTimebound);
}
Expand Down
18 changes: 17 additions & 1 deletion src/app/shared/models/validation-response.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Event } from "../psp/sel/event";
import { Property } from "../psp/sel/property";
import {TimeBound} from "../psp/constraints/time-bound";
import {UpperTimeBound} from "../psp/constraints/upper-time-bound";
import {Interval} from "../psp/constraints/interval";

export class ValidationResponse {

result: boolean;
intervals: { start: number, end: number, result: boolean }[];
timebound: TimeBound | null;

constructor(response: any, public validatedItem: Property | Event) {
console.log(response)
this.result = (new String(response.result)).toLowerCase() === 'true';
this.intervals = response.intervals.map((interval: any[]) => {
return {
Expand All @@ -15,6 +20,17 @@ export class ValidationResponse {
result: interval[2],
}
});
}

this.timebound = this.determineTimeBound(response);
}

private determineTimeBound(response: any): TimeBound | null {
const {lower_bound, upper_bound} = response;
if (lower_bound && upper_bound) {
return new Interval(new Event(`Candidate ${lower_bound} to ${upper_bound}`), lower_bound, upper_bound, 'time units');
} else if (upper_bound) {
return new UpperTimeBound(new Event(`Candidate ${upper_bound}`), upper_bound, 'time units');
}
return null;
}
}

0 comments on commit 7e5b69e

Please sign in to comment.