Skip to content
Snippets Groups Projects
Commit b21e77b0 authored by Olivier Maury's avatar Olivier Maury
Browse files

feat: :sparkles: Pouvoir calculer les valeurs de chaque date

Utiliser season-1.4.0, modifier le script de lancement

refs agroclim/agrometinfo/AgroMetInfo_2.0#35
parent 572eea6a
No related branches found
No related tags found
1 merge request!27Pouvoir calculer les indicateurs à tous les jours
Pipeline #230738 failed
......@@ -42,7 +42,7 @@
<lombok.version>1.18.34</lombok.version>
<mockito.version>5.12.0</mockito.version>
<picoli.version>4.7.6</picoli.version>
<season.version>1.3.1</season.version>
<season.version>1.4.0-SNAPSHOT</season.version>
<!-- Maven environment values -->
<build.date>${maven.build.timestamp}</build.date>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
......
#!/bin/bash
set -e
function usage {
echo "USAGE"
echo " $0 [OPTIONS]"
echo ""
echo " Environment variables AGROMETINFO_ACTIVEMQ_USER and AGROMETINFO_ACTIVEMQ_PASSWORD must be set."
echo "OPTIONS"
echo " -h show usage"
echo " -c compute each date"
echo " -l <DATE> send to localhost"
echo " -p <DATE> send to pre-production"
}
if [[ -z "$AGROMETINFO_ACTIVEMQ_USER" ]]; then
echo "Missing AGROMETINFO_ACTIVEMQ_USER"
exit 1
......@@ -9,11 +21,43 @@ if [[ -z "$AGROMETINFO_ACTIVEMQ_PASSWORD" ]]; then
echo "Missing AGROMETINFO_ACTIVEMQ_PASSWORD"
exit 1
fi
if [[ -z "$1" ]]; then
DATE=$(date +%Y-%m-%d)
else
DATE=$1
while getopts ":chl:p:" option
do
case "${option}" in
c)
COMPUTE_EACH_DATE='true'
;;
h)
usage
exit 0
;;
l)
URL='http://localhost:8161/console/jolokia/'
DATE=$OPTARG
;;
p)
URL='http://agrometinfo-preprod:8161/console/jolokia/'
DATE=$OPTARG
;;
:)
echo "Option -$OPTARG requires an argument."
usage
exit 1
;;
\?)
echo "Invalid option: -$OPTARG"
usage
exit 1
;;
esac
done
if [[ -z "$DATE" ]]; then
usage
exit 1
fi
BASE64=$(printf '%s:%s' "$AGROMETINFO_ACTIVEMQ_USER" "$AGROMETINFO_ACTIVEMQ_PASSWORD" | base64)
JSON='{
......@@ -21,7 +65,7 @@ JSON='{
"mbean":"org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"agrometinfo-new-safran-data\"",
"operation":"sendMessage(java.util.Map, int, java.lang.String, boolean, java.lang.String, java.lang.String, boolean)",
"arguments":[
{},
{"compute_each_date": "'$COMPUTE_EACH_DATE'"},
3,
"'$DATE'",
true,
......@@ -30,6 +74,5 @@ JSON='{
false
]
}'
URL='http://localhost:8161/console/jolokia/'
curl --verbose $URL -H "Content-Type: text/json" -H "Authorization: Basic $BASE64" --data-raw "$JSON"
echo
......@@ -9,7 +9,7 @@ BEGIN
sql := format(
$$
INSERT INTO agrometinfo.dailyvalue ("indicator", cell, date, computedvalue, comparedvalue)
SELECT
SELECT DISTINCT
i.id AS "indicator",
s.cell,
s.enddate AS date,
......
......@@ -119,10 +119,17 @@ public final class SafranReceiver implements MessageListener, Runnable {
if (message instanceof final ActiveMQMessage msg) {
try {
final String body = msg.getBody(String.class);
final String property = SimulationProperties.Property.COMPUTE_EACH_DATE.name().toLowerCase();
final boolean computeEachDate;
if (msg.propertyExists(property)) {
computeEachDate = msg.getBooleanProperty(property);
} else {
computeEachDate = false;
}
LOGGER.info("Body from received message: {}", body);
lastDate = LocalDate.parse(body);
updateLastDateInTable();
sendEvaluations();
sendEvaluations(computeEachDate);
msg.acknowledge();
} catch (final IndicatorsException | JMSException ex) {
LOGGER.fatal(ex);
......@@ -139,6 +146,7 @@ public final class SafranReceiver implements MessageListener, Runnable {
Objects.requireNonNull(launcher);
Objects.requireNonNull(varietyParameterDao);
consumer.setMessageListener(this);
fitter.setVarietyParameterDao(varietyParameterDao);
}
/**
......@@ -162,10 +170,11 @@ public final class SafranReceiver implements MessageListener, Runnable {
}
/**
* @param computeEachDate If evaluation computation is launched with {@link Evaluation#computeEachDate()}
* @throws IndicatorsException should not occur at this point: error while getting XML from evaluation
*/
private void sendEvaluations() throws IndicatorsException {
LOGGER.traceEntry("Loop on each evaluation");
private void sendEvaluations(final boolean computeEachDate) throws IndicatorsException {
LOGGER.traceEntry("Loop on each evaluation, compute each date : {}", computeEachDate);
final Optional<String> res = config.init();
if (!res.isEmpty()) {
LOGGER.error("Configuration error: " + res.get());
......@@ -176,6 +185,7 @@ public final class SafranReceiver implements MessageListener, Runnable {
LOGGER.trace("SimulationProperties: {}", config.getSimulationProperties());
for (int i = 0; i < config.getEvaluations().size(); i++) {
final SimulationProperties props = config.getSimulationProperties().get(i);
props.set(SimulationProperties.Property.COMPUTE_EACH_DATE, computeEachDate);
final Evaluation evaluation = config.getEvaluations().get(i);
sendEvaluation(evaluation, props);
}
......
......@@ -4,10 +4,11 @@ climatic_model = safran
climatic_scenario = SAFRAN
start_year = 1980
end_year = 2015
compute_each_date = false
species = bl\u00e9
variety = soissons
# cell ids are provided in another file.
cells = ./cells-good.json
phenological_model = linear
# stages
stages = s0: 274, s1: 307, s2: 366, s8: 730
\ No newline at end of file
stages = s0: 274, s1: 307, s2: 366, s8: 730
......@@ -4,6 +4,7 @@ climatic_model = safran
climatic_scenario = SAFRAN
start_year = 1980
end_year = 2015
compute_each_date = false
species = bl\u00e9
variety = soissons
# cell ids are provided in another file.
......@@ -11,4 +12,4 @@ cells = ./cells-good.json
# phenological model
phenological_model = linear
# If computed soil data must be stored. default: false.
store_soil_data = true
\ No newline at end of file
store_soil_data = true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment