Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSCore-Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSCore-Python
Commits
eb858c85
Commit
eb858c85
authored
2 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
First commit (prototype for APPLESCABM)
parent
08cc70e5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
endpoint_tests/run_REFERENCEM.py
+81
-0
81 additions, 0 deletions
endpoint_tests/run_REFERENCEM.py
with
81 additions
and
0 deletions
endpoint_tests/run_REFERENCEM.py
0 → 100755
+
81
−
0
View file @
eb858c85
#!/usr/bin/python3
"""
Naïve script demonstrating how to run a model from a client in the simplest way. Assumes that the
VIPS-Python reference model is deployed on the running instance of VIPSCore-Python
Please note that this script does NOT require/utilize VIPSCore-Common-Python, which contains
data classes and utils for weather data, result objects etc.
Copyright (C) 2023 NIBIO <tor-einar.skog@nibio.no>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import
requests
import
json
from
datetime
import
datetime
from
dateutil
import
parser
# Which weather data source to connect to
weather_data_source_name
=
"
LMT
"
weather_data_source_uri
=
"
https://lmt.nibio.no/services/rest/vips/getdata/forecastfallback?weatherStationId=%s&%s
"
weather_param_string
=
"
elementMeasurementTypes[]=TM&elementMeasurementTypes[]=RR&elementMeasurementTypes[]=BT&logInterval=1h&startDate=2016-03-01&startTime=00&endDate=2016-09-30&endTime=00&timeZone=Europe/Oslo
"
# Which VIPSCore system to connect to
core_server_uri
=
"
https://coremanager.testvips.nibio.no
"
# The unique identificator for the Apple Scab model
model_id
=
"
APPLESCABM
"
print
(
"
Downloading weather data from %s, please wait...
"
%
weather_data_source_name
)
weather_data_request
=
requests
.
get
(
weather_data_source_uri
%
(
"
5
"
,
weather_param_string
))
#print weather_data_request.text
# Convert the text to Python JSON representation
#print(weather_data_request.text)
weather_data
=
weather_data_request
.
json
()
print
(
"
Sending request to VIPS, waiting for calculation results, please wait...
"
)
# Building the request with config values and weather data to send to VIPS
model_config
=
{
"
loginInfo
"
:
{
"
username
"
:
"
testuser
"
,
"
password
"
:
"
testpass
"
},
"
modelId
"
:
"
APPLESCABM
"
,
"
configParameters
"
:
{
"
timeZone
"
:
"
Europe/Oslo
"
,
"
startDateAscosporeMaturity
"
:
"
2016-03-10
"
,
# APPLESCABM Specific configuration value
"
observations
"
:
weather_data
}
}
# Posting the request to VIPSLogic
r2
=
requests
.
post
(
"
%s/models/%s/run
"
%
(
core_server_uri
,
model_id
),
json
=
model_config
)
#print r2.text
results
=
r2
.
json
()
for
result
in
results
:
# Create a Python timestamp from the JSON timestamp string
timestamp
=
parser
.
parse
(
result
[
"
validTimeStart
"
])
# Printing selected result parameters to stdout
allValues
=
json
.
loads
(
result
[
"
allValues
"
])
print
(
"
%s: Ascospore maturation = %s, Accumulated Mills = %s, Warning status = %s
"
%
(
datetime
.
strftime
(
timestamp
,
'
%Y-%m-%dT%H:%M %Z
'
),
allValues
[
"
APPLESCABM.ASCMAT
"
],
allValues
[
"
APPLESCABM.ACCMILLS
"
],
result
[
"
warningStatus
"
]
)
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment