Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding calibration end point to hmi-server #1022

Merged
merged 1 commit into from
Apr 24, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@/utils/logger';
import API from '@/api/api';
import { Simulation, SimulationParams } from '@/types/Types';
import { Simulation, SimulationParams, CalibrationParams } from '@/types/Types';

export async function makeForecast(simulationParam: SimulationParams) {
try {
Expand Down Expand Up @@ -91,3 +91,14 @@ export async function deleteAnnotation(id: Simulation['id']) {
return null;
}
}

export async function makeCalibrateJob(calibrationParams: CalibrationParams) {
try {
const resp = await API.post('simulation/calibrate', calibrationParams);
const output = resp.data;
return output;
} catch (err) {
logger.error(err);
return null;
}
}
66 changes: 66 additions & 0 deletions packages/client/hmi-client/src/temp/TA2Playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { defineComponent, ref } from 'vue';
import { fetchStratificationResult } from '@/services/models/stratification-service';
import { runDagreLayout, D3SelectionINode, D3SelectionIEdge } from '@/services/graph';
import API from '@/api/api';
import { CalibrationParams } from '@/types/Types';
import { makeCalibrateJob } from '@/services/models/simulation-service';

enum NodeType {
Species = 'S',
Expand Down Expand Up @@ -763,13 +765,77 @@ export default defineComponent({
resultGraph.height = 500;
await renderer?.setData(resultGraph);
await renderer?.render();
},
async testCalibration() {
console.log('Testing Calibration:');
let calibrationParam: CalibrationParams = {
petri: JSON.stringify({
T: [{ tname: 'exp' }, { tname: 'conv' }, { tname: 'rec' }, { tname: 'death' }],
S: [{ sname: 'S' }, { sname: 'E' }, { sname: 'I' }, { sname: 'R' }, { sname: 'D' }],
I: [
{ it: 1, is: 1 },
{ it: 1, is: 3 },
{ it: 2, is: 2 },
{ it: 3, is: 3 },
{ it: 4, is: 3 }
],
O: [
{ ot: 1, os: 2 },
{ ot: 1, os: 3 },
{ ot: 2, os: 3 },
{ ot: 3, os: 4 },
{ ot: 4, os: 5 }
]
}),
initials: {
S: 0.49457800495224524,
E: 0.26745259325403603,
I: 0.4497387877393193,
R: 0.32807705995998604,
D: 0.8545934885162726
},
t: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
data: {
S: [
0.8457800495224524, 0.7989147588862952, 0.7717574792075946, 0.7555359186659574,
0.7456920016554676, 0.7396688112881398
],
E: [
0.21745259325403604, 0.1404833532397162, 0.088632010007611, 0.05529630617740498,
0.03431001255438966, 0.021230743198302895
],
I: [
0.4497387877393193, 0.27034535589195036, 0.1653910436709313, 0.10194987107919627,
0.06301885280976183, 0.03898091182580745
],
R: [
0.8545934885162726, 0.575704439041781, 0.7259355031548465, 0.8182142842907686,
0.8751839322495475, 0.9104140088945406
],
D: [
0.3545934885162726, 0.41019407193232343, 0.44392594295108295, 0.4646455987787392,
0.47743717972289984, 0.48534750378527575
]
},
params: {
exp: 0.16207166221196045,
conv: 0.7009195813964052,
rec: 0.7040317196117394,
death: 0.15807853921067516
}
};
console.log('Calibration Params setup done');
const results = await makeCalibrateJob(calibrationParam);
console.log('Done');
console.log(results);
}
}
});
</script>
<template>
<section class="playground">
<p>A playground for testing TA2 API integrations.</p>
<button type="button" @click="testCalibration">Test Calibration</button>
<button type="button" @click="addPlace">Add place</button>
<button type="button" @click="addTransition">Add transition</button>
&nbsp;
Expand Down
8 changes: 8 additions & 0 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export interface Simulation {
modelId: number;
}

export interface CalibrationParams {
petri: string;
initials: { [index: string]: number };
t: number[];
params: { [index: string]: number };
data: { [index: string]: number[] };
}

export interface SimulationParams {
petri: string;
initials: { [index: string]: number };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package software.uncharted.terarium.hmiserver.models.simulationservice;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import software.uncharted.terarium.hmiserver.annotations.TSModel;


@Data
@Accessors(chain = true)
@TSModel
public class CalibrationParams implements Serializable {
private String petri;
private Map<String, Double> initials;
private List<Double> t;
private Map<String, Double> params;
private Map<String, List<Double>> data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import software.uncharted.terarium.hmiserver.models.simulationservice.SimulationParams;
import software.uncharted.terarium.hmiserver.models.simulationservice.CalibrationParams;


@RegisterRestClient(configKey = "simulation-service")
Expand All @@ -31,4 +32,11 @@ Response getRunStatus(
Response getRunResult(
@PathParam("runId") String runId
);

@POST
@Path("/calls/calibrate")
@Consumes(MediaType.APPLICATION_JSON)
Response makeCalibrateJob(
CalibrationParams calibrationParams
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import software.uncharted.terarium.hmiserver.models.dataservice.Simulation;
import software.uncharted.terarium.hmiserver.models.simulationservice.SimulationParams;
import software.uncharted.terarium.hmiserver.models.simulationservice.CalibrationParams;
import software.uncharted.terarium.hmiserver.proxies.dataservice.SimulationProxy;
import software.uncharted.terarium.hmiserver.proxies.simulationservice.SimulationServiceProxy;

Expand Down Expand Up @@ -79,4 +80,15 @@ public Response getRunResult(
) {
return simulationServiceProxy.getRunResult(runId);
}

@POST
@Path("/calibrate")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Tag(name = "Create calibrate job")
public Response makeCalibrateJob(
final CalibrationParams calibrationParams
) {
return simulationServiceProxy.makeCalibrateJob(calibrationParams);
}
}