From 743e9c6e00c43c989eea6811ceafef5f86883c00 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 18 Nov 2016 19:16:41 +0100 Subject: [PATCH] Update user simulator --- simulators/config/s1.json | 3 --- simulators/config/user/conf.json | 14 ++++++++++++++ simulators/config/user/conf1.json | 0 simulators/config/user/conf2.json | 0 simulators/fixtures/simulation.json | 435 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- simulators/scripts/simulator_launch.sh | 11 ++++++++--- src/userSimulator/tasks.py | 30 ++++++++++++++++++++---------- 7 files changed, 475 insertions(+), 18 deletions(-) delete mode 100644 simulators/config/s1.json create mode 100644 simulators/config/user/conf.json create mode 100644 simulators/config/user/conf1.json create mode 100644 simulators/config/user/conf2.json diff --git a/simulators/config/s1.json b/simulators/config/s1.json deleted file mode 100644 index e06e08b..0000000 --- a/simulators/config/s1.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Request" : {"id" : 1, "time" : 4} -} diff --git a/simulators/config/user/conf.json b/simulators/config/user/conf.json new file mode 100644 index 0000000..fffd632 --- /dev/null +++ b/simulators/config/user/conf.json @@ -0,0 +1,14 @@ +[ + { + "id" : 1, + "time": 4 + }, + { + "id" : 2, + "time": 4 + }, + { + "id" : 3, + "time": 4 + } +] diff --git a/simulators/config/user/conf1.json b/simulators/config/user/conf1.json new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/simulators/config/user/conf1.json diff --git a/simulators/config/user/conf2.json b/simulators/config/user/conf2.json new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/simulators/config/user/conf2.json diff --git a/simulators/fixtures/simulation.json b/simulators/fixtures/simulation.json index f19b59a..ac0bfe1 100644 --- a/simulators/fixtures/simulation.json +++ b/simulators/fixtures/simulation.json @@ -1,5 +1,436 @@ [ -{ + { + "model": "common.userlevel", + "pk": 42, + "fields": { + "name": "Simulation", + "desc": "", + "priority": 0, + "quota": 9999.0 + } + }, + { + "model": "auth.user", + "pk": 42, + "fields": { + "password": "pbkdf2_sha256$24000$HRial3QUfrlz$bVuEzQaXthOd9GZVXd2449LDEF8EMQure69nA/Hu7qQ=", + "last_login": "2016-08-10T15:16:42.327Z", + "is_superuser": true, + "username": "simulator", + "first_name": "", + "last_name": "", + "email": "simulator@example.com", + "is_staff": true, + "is_active": true, + "date_joined": "2016-08-10T15:15:58.481Z", + "groups": [], + "user_permissions": [] + } + }, + { + "model": "common.pyrosuser", + "pk": 42, + "fields": { + "user": 42, + "country": 1, + "user_level": 42, + "desc": "", + "created": "2016-08-11T07:54:05.627Z", + "updated": "2016-08-11T07:54:05.627Z", + "tel": "", + "address": "", + "laboratory": "IRAP", + "last_connect": null, + "cur_connect": null, + "putvalid_beg": null, + "putvalid_end": null, + "acqvalid_beg": "", + "acqvalid_end": "", + "quota": 9999.0, + "quota_rea": null, + "u_priority": 1, + "p_priority": 1, + "dir_level": null, + "can_del_void_req": false + } + }, + { + "model": "common.scientificprogram", + "pk": 42, + "fields": { + "name": "SIMULATION", + "desc": "", + "quota": 9999.0, + "priority": 0, + "pyros_users": [ + 42 + ] + } + }, -} + { + "model": "common.request", + "pk":1, + "fields" : { + "name" : "Request Simulation 1", + "desc" : "Request description 1", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "target_type" : "test", + "status" : "test", + "autodeposit" : 0, + "checkpoint" : "test", + "flag" : "test", + "complete" : 0, + "submitted" : 0, + "pyros_user_id" : 42, + "scientific_program_id" : 42 + } + }, + { + "model": "common.request", + "pk":2, + "fields" : { + "name" : "Request Simulation 2", + "desc" : "Request description 2", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "target_type" : "test", + "status" : "test", + "autodeposit" : 0, + "checkpoint" : "test", + "flag" : "test", + "complete" : 0, + "submitted" : 0, + "pyros_user_id" : 42, + "scientific_program_id" : 42 + } + }, + { + "model": "common.request", + "pk":3, + "fields" : { + "name" : "Request Simulation 3", + "desc" : "Request description 3", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "target_type" : "test", + "status" : "test", + "autodeposit" : 0, + "checkpoint" : "test", + "flag" : "test", + "complete" : 0, + "submitted" : 0, + "pyros_user_id" : 42, + "scientific_program_id" : 42 + } + }, + { + "model": "common.sequence", + "pk": 1, + "fields": { + "name" : "Sequence 1", + "desc" : "Sequence 1", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "status" : "Sequence 1", + "target_coords" : "100,100", + "with_drift" : 0, + "priority" : 1, + "analysis_method" : "DARK", + "moon_min" : 0, + "alt_min" : 0, + "type" : "test", + "img_current" : 0, + "img_total" : 5, + "not_obs" : 0, + "obsolete" : 0, + "processing" : 0, + "flag" : "flag", + "jd1" : 5.1, + "jd2" : 10.2, + "t_prefered" : 5.1, + "duration" : 5.1, + "overhead" : 0, + "ra" : 56, + "dec" : 34, + "request_id" : 1 + } + }, + { + "model": "common.sequence", + "pk": 2, + "fields": { + "name" : "Sequence 2", + "desc" : "Sequence 2", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "status" : "Sequence 2", + "target_coords" : "200,200", + "with_drift" : 0, + "priority" : 1, + "analysis_method" : "DARK", + "moon_min" : 0, + "alt_min" : 0, + "type" : "test", + "img_current" : 0, + "img_total" : 2, + "not_obs" : 0, + "obsolete" : 0, + "processing" : 0, + "flag" : "flag", + "jd1" : 13.1, + "jd2" : 18.2, + "t_prefered" : 13.1, + "duration" : 5.1, + "overhead" : 0, + "ra" : 56, + "dec" : 34, + "request_id" : 1 + } + }, + { + "model": "common.sequence", + "pk": 3, + "fields": { + "name" : "Sequence 3", + "desc" : "Sequence 3", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "status" : "Sequence 3", + "target_coords" : "200,200", + "with_drift" : 0, + "priority" : 1, + "analysis_method" : "DARK", + "moon_min" : 0, + "alt_min" : 0, + "type" : "test", + "img_current" : 0, + "img_total" : 2, + "not_obs" : 0, + "obsolete" : 0, + "processing" : 0, + "flag" : "flag", + "jd1" : 13.1, + "jd2" : 18.2, + "t_prefered" : 13.1, + "duration" : 5.1, + "overhead" : 0, + "ra" : 56, + "dec" : 34, + "request_id" : 2 + } + }, + { + "model": "common.sequence", + "pk": 4, + "fields": { + "name" : "Sequence 4", + "desc" : "Sequence 4", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "is_alert" : 0, + "status" : "Sequence 4", + "target_coords" : "200,200", + "with_drift" : 0, + "priority" : 1, + "analysis_method" : "DARK", + "moon_min" : 0, + "alt_min" : 0, + "type" : "test", + "img_current" : 0, + "img_total" : 2, + "not_obs" : 0, + "obsolete" : 0, + "processing" : 0, + "flag" : "flag", + "jd1" : 13.1, + "jd2" : 18.2, + "t_prefered" : 13.1, + "duration" : 5.1, + "overhead" : 0, + "ra" : 56, + "dec" : 34, + "request_id" : 3 + } + }, + { + "model" : "common.album", + "pk": 1, + "fields": { + "name": "album 1", + "desc" : "album 1", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "complete" : 0, + "detector_id" : 1, + "sequence_id" : 1 + } + }, + { + "model" : "common.album", + "pk": 2, + "fields": { + "name": "album 2", + "desc" : "album 2", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "complete" : 0, + "detector_id" : 1, + "sequence_id" : 2 + } + }, + { + "model" : "common.album", + "pk": 3, + "fields": { + "name": "album 3", + "desc" : "album 3", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "complete" : 0, + "detector_id" : 2, + "sequence_id" : 2 + } + }, + { + "model" : "common.album", + "pk": 4, + "fields": { + "name": "album 4", + "desc" : "album 4", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "complete" : 0, + "detector_id" : 1, + "sequence_id" : 3 + } + }, + { + "model" : "common.album", + "pk": 5, + "fields": { + "name": "album 5", + "desc" : "album 5", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "complete" : 0, + "detector_id" : 1, + "sequence_id" : 4 + } + }, + { + "model" : "common.plan", + "pk" : 1, + "fields": { + "name" : "plan 1", + "desc" : "plan 1", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "duration" : 10, + "position" : "100,100", + "exposure_time" : 10, + "nb_images" : 5, + "dithering" : 0, + "complete" : 0, + "album_id" : 1, + "filter_id" : 1 + } + }, + { + "model" : "common.plan", + "pk" : 2, + "fields": { + "name" : "plan 2", + "desc" : "plan 2", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "duration" : 10, + "position" : "200,200", + "exposure_time" : 10, + "nb_images" : 5, + "dithering" : 0, + "complete" : 0, + "album_id" : 1, + "filter_id" : 2 + } + }, + { + "model" : "common.plan", + "pk" : 3, + "fields": { + "name" : "plan 1", + "desc" : "plan 1", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "duration" : 10, + "position" : "200,200", + "exposure_time" : 10, + "nb_images" : 5, + "dithering" : 0, + "complete" : 0, + "album_id" : 2, + "filter_id" : 3 + } + }, + { + "model" : "common.plan", + "pk" : 4, + "fields": { + "name" : "plan 4", + "desc" : "plan 4", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "duration" : 10, + "position" : "100,100", + "exposure_time" : 10, + "nb_images" : 5, + "dithering" : 0, + "complete" : 0, + "album_id" : 3, + "filter_id" : 1 + } + }, + { + "model" : "common.plan", + "pk" : 5, + "fields": { + "name" : "plan 5", + "desc" : "plan 5", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "duration" : 10, + "position" : "200,200", + "exposure_time" : 10, + "nb_images" : 5, + "dithering" : 0, + "complete" : 0, + "album_id" : 4, + "filter_id" : 2 + } + }, + { + "model" : "common.plan", + "pk" : 6, + "fields": { + "name" : "plan 6", + "desc" : "plan 6", + "created" : "2016-11-18T16:44:30Z", + "updated" : "2016-11-18T16:44:30Z", + "duration" : 10, + "position" : "200,200", + "exposure_time" : 10, + "nb_images" : 5, + "dithering" : 0, + "complete" : 0, + "album_id" : 5, + "filter_id" : 1 + } + } ] diff --git a/simulators/scripts/simulator_launch.sh b/simulators/scripts/simulator_launch.sh index cda9e2d..6847c91 100755 --- a/simulators/scripts/simulator_launch.sh +++ b/simulators/scripts/simulator_launch.sh @@ -3,10 +3,15 @@ SIM_FIXTURES="../simulators/fixtures/" SIM_PATH="../simulators/" +cd "$SIM_PATH"fixtures/ echo -n "Existing simulations : " -ls "$SIM_FIXTURES" -echo -n "Enter which simulation you want to launch : " -read -r line +ls +read -e -p "Enter which simulation you want to launch : " line +cd - > /dev/null + +if [[ $line != *[!\ ]* ]]; then + line="simulation.json" +fi if [ ! -f "$SIM_FIXTURES"/"$line" ]; then echo "This simulation doesn't exist" diff --git a/src/userSimulator/tasks.py b/src/userSimulator/tasks.py index 5ba250a..6c38b5e 100644 --- a/src/userSimulator/tasks.py +++ b/src/userSimulator/tasks.py @@ -12,21 +12,31 @@ import json log = l.setupLogger("simulator", "simulator") SIMULATOR_VALUE = None +CONF_PATH = "%s/../simulators/config/user/"%settings.BASE_DIR class simulator(Task): - shouldClean = False - - def loadJson(self, path): - json_data = open(path, 'r') - # if (not json_data.is_open()): + shouldClean = True + conf_file = CONF_PATH + SIMULATOR_VALUE + array_requests = [] + + def loadJson(self): + self.conf_file = self.conf_file.replace("simulation", "conf") + try: + json_data = open(self.conf_file, 'r') + except IOError: + log.error("File %s does not exist"%("SIMULATOR_VALUE".replace("simulation", "conf"))) + return (1) + self.json_data = json.loads(json_data.read()) + return (0) def run(self): - print('-------------------------------') - print(SIMULATOR_VALUE) + if (self.loadJson()): + return (0) + for dic in self.json_data: + self.array_requests.append(Request.objects.get(pk=dic["id"])) + for req in self.array_requests: + print(req.name) - # END OF EXECTUION (KILLING WEB SERVER AN PROCESS) - if (self.shouldClean == True): - os.system("%s/../pyrosrun.sh kill_simulation"%settings.BASE_DIR) if __name__ == "__main__": sim = simulator(Task) -- libgit2 0.21.2