Commit c26e3c75 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

refactor

parent e96b0657
{
"setting": {
"forecastMethod": "NEMO",
"outletType": "POINT",
"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
}
],
"starthour": 3,
"startdaysadjustment": 1,
"timeperiod": 12,
"maxperiod" : 47,
"domain" : "BF_NEMO"
}
\ No newline at end of file
{
"setting": {
"start": "STARTDATE",
"end": "ENDDATE",
"calculationMode": "Normal",
"outletType": "MULTIPOINT",
"forecastMethod": "NEMO",
"forwardCalculation": "true",
"amount": "100.0",
"amountUnit": "m3",
"calculationType": "Floating object \/ Algae",
"substance": "Floating object, file",
"fresh": "false",
"instantaneous": "true",
"outletPoints": "1",
"uncertainty": "false",
"winddrag": "1",
"depth": "0",
"duration": "",
"durationUnit": ""
},
"coordinate": [
{
"latitude": 56.41390137600676,
"longitude": 18.0615234375
}
],
"starthour": 0,
"startdaysadjustment": 0,
"timeperiod": 3,
"maxperiod" : 200,
"domain" : "HELCOM_NEMO"
}
\ 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
}
],
"starthour": 0,
"startdaysadjustment": 1,
"timeperiod": 3,
"maxperiod" : 200,
"domain" : "HELCOM_NEMO"
}
\ No newline at end of file
{
"setting": {
"forecastMethod": "NEMO",
"outletType": "POINT",
"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": 59.08009382655441,
"longitude": 13.6724853515625
}
],
"starthour": 0,
"startdaysadjustment": 0,
"timeperiod": 3,
"maxperiod" : 59,
"domain" : "VN_NEMO"
}
\ No newline at end of file
......@@ -11,6 +11,13 @@ def main():
v = Models()()
r = random.choice(v)
r();
if (r.error == 1):
r = random.choice(v)
r();
if (r.error == 1):
r = random.choice(v)
r();
r.clean();
sys.exit(0)
except Exception as error:
......
......@@ -17,6 +17,7 @@ class Runner(object):
self.url = settings.get('padmws', 'url');
self.usr = settings.get('padmws', 'usr');
self.pwd = settings.get('padmws', 'pwd');
self.error = 0;
def onError(error, errarea):
raise ValueError(error, errarea)
......@@ -74,6 +75,7 @@ class Runner(object):
if (output == 'run'):
with open('output/run/run.txt', 'w') as outputfile:
if (status != 'COMPLETE') or hasError:
self.error = 1;
outputfile.write('0')
with open('output/run/'+name+'_'+datetime.utcnow().strftime("%Y%m%d%H%M")+'.txt', 'w') as errorfile:
errorfile.write(wid)
......@@ -88,25 +90,28 @@ class Runner(object):
else:
with open('output/validate/statistics.txt', 'a') as statisticsfile:
statisticsfile.write(datetime.utcnow().strftime("%Y%m%d%H%M")+' '+wid+' '+name+'\n')
return 1
class Model(Runner):
def __init__(self, inputfile):
super(Model, self).__init__()
self.name,suffix = inputfile.split('.')
with open('input/'+inputfile) as file:
inputsplit = inputfile.split('/')
self.name,suffix = inputsplit[2].split('.')
with open(inputfile) as file:
self.jdata = json.load(file)
def __call__(self, timeperiod = None, output = 'run', timeout = 60):
def __call__(self, timeperiod = None, output = 'run', timeout = 90):
super(Model, self).__call__(self.jdata, self.name, timeperiod, output, timeout)
def clean(self):
super(Model,self).clean();
class Models(object):
def __init__(self):
def __init__(self, input = 'run'):
inputFolder = 'input/'+input
self.inputs = []
for (dirpath, dirnames, filenames) in walk('input'):
self.inputs.extend(filenames)
break
for (dirpath, dirnames, filenames) in walk(inputFolder):
for filename in filenames:
self.inputs.append(dirpath+'/'+filename)
def __call__(self):
models = []
......
No preview for this file type
......@@ -8,7 +8,7 @@ from runner.model import Models
def main(method):
try:
mlist = Models()()
mlist = Models('validate')()
if method == 'all':
for m in mlist:
m(None, 'validate', 300);
......
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