Commit 3bc4f82b authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

tests

parent d8c5a76d
{
"setting": {
"forecastMethod": "NEMO",
"outletType": "AREA",
"forwardCalculation": "true",
"start": "STARTDATE",
"end": "ENDDATE",
"calculationType": "Oil classes",
"substance": "Medium oils (100-1000 cSt)",
"fresh": "true",
"winddrag": "0.00",
"outletPoints": "1",
"depth": "0",
"instantaneous": "true",
"amount": "100",
"amountUnit": "m3",
"duration": "24",
"durationUnit": "hours",
"uncertainty": "false",
"calculationMode": "Normal"
},
"coordinate": [
{
"latitude": 58.335270633241244,
"longitude": 11.390247344970703
}
],
"timeperiod": 24
}
\ No newline at end of file
{
"setting": {
"forecastMethod": "NEMO",
"outletType": "AREA",
"forwardCalculation": "true",
"start": "STARTDATE",
"end": "ENDDATE",
"calculationType": "Oil classes",
"substance": "Medium oils (100-1000 cSt)",
"fresh": "true",
"winddrag": "0.00",
"outletPoints": "3",
"depth": "0",
"instantaneous": "true",
"amount": "100",
"amountUnit": "m3",
"duration": "24",
"durationUnit": "hours",
"uncertainty": "false",
"calculationMode": "Normal"
},
"coordinate": [
{
"latitude": 60.356127978060933,
"longitude": 26.961650443838113
},
{
"latitude": 60.348048724559071,
"longitude": 26.934164170849897
},
{
"latitude": 60.357731733846322,
"longitude": 26.935840154054311
},
{
"latitude": 60.362457652517769,
"longitude": 26.958385167216541
}
],
"timeperiod": 24
}
\ No newline at end of file
{
"setting": {
"start": "STARTDATE",
"stop": "ENDDATE",
"mode": "Normal",
"forecastMethod": "NEMO",
"forwardCalculation": "true",
"amount": "100.0",
"amountUnit": "m3",
"oilclass": "Floating object \/ Algae",
"substance": "Floating object, file",
"fresh": "false",
"instantaneous": "true",
"uncertainty": "false",
"winddrag": "1",
"depth": "0",
"duration": "",
"durationUnit": ""
},
"coordinate": [
{
"latitude": 56.41390137600676,
"longitude": 18.0615234375
}
],
"timeperiod": 24
}
\ No newline at end of file
{
"setting": {
"forecastMethod": "HIRLAM",
"forecastMethod": "NEMO",
"outletType": "AREA",
"forwardCalculation": "true",
"start": "STARTDATE",
......@@ -19,18 +19,11 @@
"uncertainty": "false",
"calculationMode": "Normal"
},
"coordinate": [{
"latitude": 60.356127978060933,
"longitude": 26.961650443838113
}, {
"latitude": 60.348048724559071,
"longitude": 26.934164170849897
}, {
"latitude": 60.357731733846322,
"longitude": 26.935840154054311
}, {
"latitude": 60.362457652517769,
"longitude": 26.958385167216541
}],
"coordinate": [
{
"latitude": 59.08009382655441,
"longitude": 13.6724853515625
}
],
"timeperiod": 24
}
\ No newline at end of file
1
\ No newline at end of file
1
\ No newline at end of file
......@@ -4,27 +4,11 @@
import json
import requests
from requests.auth import HTTPBasicAuth
from time import gmtime, strftime
from time import time, strftime, sleep
from datetime import datetime, timedelta
from pprint import pprint
from ConfigParser import SafeConfigParser
# class RegexValidator(object):
# def __call__(self, value):
# # validation logic
# class URLValidator(RegexValidator):
# def __call__(self, value):
# super(URLValidator, self).__call__(value)
# #additional logic
# class EmailValidator(RegexValidator):
# # some logic
# for v in [custom_validator, EmailValidator()]:
# v(value) # <-----
class Runner(object):
def __init__(self):
settings = SafeConfigParser()
......@@ -33,39 +17,72 @@ class Runner(object):
self.usr = settings.get('misc', 'usr');
self.pwd = settings.get('misc', 'pwd');
def __call__(self, json):
# print json
# # create
# rCreate = requests.post('/'.join([self.url, "workarea", "v2"]), data=None, json = None, auth=HTTPBasicAuth(self.usr, self.pwd))
# wid = rCreate.headers['Location'].split('/')[-1]
# # domain
# rDomain = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "domain"]), data=None, json = {"domain": "HELCOM_NEMO"}, auth=HTTPBasicAuth(self.usr, self.pwd))
# # setting
# setting = json['setting']
# setting['start'] = datetime.utcnow().strftime("%Y-%m-%d %H:%M")+':00'
# end = datetime.utcnow()
# end += timedelta(hours=json['timeperiod'])
# setting['end'] = end.strftime("%Y-%m-%d %H:%M")+':00'
# rSetting = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "setting"]), data=None, json = json['setting'], auth=HTTPBasicAuth(self.usr, self.pwd))
# # coordinates
# rCoords = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "coordinates"]), data=None, json = {"coordinate": json['coordinate']}, auth=HTTPBasicAuth(self.usr, self.pwd))
def __call__(self, jdata, name, domain):
# create
rCreate = requests.post('/'.join([self.url, "workarea", "v2"]), data=None, json = None, auth=HTTPBasicAuth(self.usr, self.pwd))
wid = rCreate.headers['Location'].split('/')[-1]
# domain
rDomain = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "domain"]), data=None, json = {"domain": domain}, auth=HTTPBasicAuth(self.usr, self.pwd))
# setting
setting = jdata['setting']
setting['start'] = datetime.utcnow().strftime("%Y-%m-%d %H:%M")+':00'
end = datetime.utcnow()
end += timedelta(hours=jdata['timeperiod'])
setting['end'] = end.strftime("%Y-%m-%d %H:%M")+':00'
rSetting = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "setting"]), data=None, json = jdata['setting'], auth=HTTPBasicAuth(self.usr, self.pwd))
# coordinates
rCoords = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "coordinates"]), data=None, json = {"coordinate": jdata['coordinate']}, auth=HTTPBasicAuth(self.usr, self.pwd))
# run
# rRun = requests.post('/'.join([self.url, "runner", "v2"]), data='workareaId='+wid, json=None, auth=HTTPBasicAuth(self.usr, self.pwd))
wid = 'b1814927-20de-41e1-8d24-9edf6451cba2'
status = requests.get('/'.join([self.url, "runner", "v2", wid, "progress"])).content
print status
rRun = requests.post('/'.join([self.url, "runner", "v2"]), data='workareaId='+wid, json=None, auth=HTTPBasicAuth(self.usr, self.pwd))
progress = json.loads(requests.get('/'.join([self.url, "runner", "v2", wid, "progress"])).content)
start = time()
end = time()
while ((progress['status'] != 'COMPLETE') and (end-start < 30)):
sleep(3)
progress = json.loads(requests.get('/'.join([self.url, "runner", "v2", wid, "progress"])).content)
end = time()
# done
with open('run/output/'+name+'.txt', 'w') as outputfile:
if (progress['status'] == 'COMPLETE'):
outputfile.write('1')
else:
outputfile.write('0')
with open('run/output/'+name+datetime.utcnow().strftime("%Y%m%d%H%M")+'.txt', 'w') as errorfile:
errorfile.write(wid)
class HELCOM_NEMO(Runner):
def __init__(self):
def __init__(self, value):
super(HELCOM_NEMO, self).__init__()
with open('run/helcom_nemo_1.json') as helcom_nemo_1_file:
self.helcom_nemo_1 = json.load(helcom_nemo_1_file)
self.name = 'helcom_nemo_'+str(value)
with open('run/input/'+self.name+'.json') as file:
self.jdata = json.load(file)
def __call__(self):
super(HELCOM_NEMO, self).__call__(self.helcom_nemo_1)
super(HELCOM_NEMO, self).__call__(self.jdata, self.name, "HELCOM_NEMO")
class BF_NEMO(Runner):
def __init__(self, value):
super(BF_NEMO, self).__init__()
self.name = 'bf_nemo_'+str(value)
with open('run/input/'+self.name+'.json') as file:
self.jdata = json.load(file)
def __call__(self):
super(BF_NEMO, self).__call__(self.jdata, self.name, "BF_NEMO")
class VN_NEMO(Runner):
def __init__(self, value):
super(VN_NEMO, self).__init__()
self.name = 'vn_nemo_'+str(value)
with open('run/input/'+self.name+'.json') as file:
self.jdata = json.load(file)
def __call__(self):
super(VN_NEMO, self).__call__(self.jdata, self.name, "VN_NEMO")
def main():
for v in [HELCOM_NEMO()]:
# for v in [HELCOM_NEMO(1), HELCOM_NEMO(2), VN_NEMO(1), BF_NEMO(1)]:
for v in [VN_NEMO(1)]:
v() # <-----
print "ok"
print "done"
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment