diff --git a/public/simulation/README.md b/public/simulation/README.md new file mode 100644 index 0000000..900e497 --- /dev/null +++ b/public/simulation/README.md @@ -0,0 +1,3 @@ +The data.json file represent the parameters of the simulator class + +The datas will be loaded if you call SimulatorRoutines.loadJson diff --git a/public/simulation/data.json b/public/simulation/data.json new file mode 100644 index 0000000..f4ff86e --- /dev/null +++ b/public/simulation/data.json @@ -0,0 +1,13 @@ +{ + "SCIENTIFIC_PROGRAMS" : {"quantity" : -1, "content" : [{"id" : 5, "name" : "Sim1", "desc" : "Sim1", "quota": 20, "priority" : 3}, {"id" : 6, "name" : "Sim2", "quota" : 20, priority : 4}]}, + "USER_LEVELS" : {"quantity" : 5, "content" : []}, + "PYROS_USERS" : {"quantity": 5, "content" : []}, + "AUTH_USERS" : {"quantity": 5, "content" : []}, + "REQUESTS" : {"quantity" : 10, "content" : []}, + "SEQUENCES" : {"quantity" : [1, 2, 3], "content" : []}, + "ALBUMS" : {"quantity" : [1, 2], "content" : [{"sequence" : 1}]}, + "PLANS" : {"quantity" : [1, 2, 3, 4], "content" : []}, + "DETECTORS" : {"quantity" : -1, "existing" : true, "id" : [1, 2], "content" : []}, + "TELESCOPES" : {"quantity" : -1, "existing" : true, "id" : [1], "content" : []}, + "DEVICES" : {"quantity" : 0, "existing" : false, "content" : []} +} diff --git a/src/misc/fixtures/simulation/simulation.json b/src/misc/fixtures/simulation/simulation.json new file mode 100644 index 0000000..f19b59a --- /dev/null +++ b/src/misc/fixtures/simulation/simulation.json @@ -0,0 +1,5 @@ +[ +{ + +} +] diff --git a/src/misc/fixtures/simulation/simulation1.json b/src/misc/fixtures/simulation/simulation1.json new file mode 100644 index 0000000..77e906f --- /dev/null +++ b/src/misc/fixtures/simulation/simulation1.json @@ -0,0 +1,543 @@ +[ +{ + "model": "common.country", + "pk": 1, + "fields": { + "name": "France", + "desc": "", + "quota": null + } +}, +{ + "model": "common.detector", + "pk": 1, + "fields": { + "device": 1, + "telescope": 1, + "status": "", + "nb_photo_x": null, + "nb_photo_y": null, + "photo_size_x": null, + "photo_size_y": null, + "has_shutter": false, + "equivalent_foc_len": "", + "acq_start": null, + "acq_stop": null, + "check_temp": null, + "gain": null, + "readout_noise": null, + "readout_time": null, + "idcam_readout_mode": null + } +}, +{ + "model": "common.detector", + "pk": 2, + "fields": { + "device": 7, + "telescope": 1, + "status": "", + "nb_photo_x": null, + "nb_photo_y": null, + "photo_size_x": null, + "photo_size_y": null, + "has_shutter": false, + "equivalent_foc_len": "", + "acq_start": null, + "acq_stop": null, + "check_temp": null, + "gain": null, + "readout_noise": null, + "readout_time": null, + "idcam_readout_mode": null + } +}, +{ + "model": "common.device", + "pk": 1, + "fields": { + "name": "Cagire", + "desc": "", + "created": "2016-05-13T11:49:49Z", + "updated": "2016-05-13T11:49:49Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 2, + "fields": { + "name": "First infrared filter", + "desc": "", + "created": "2016-05-13T11:49:56Z", + "updated": "2016-05-13T11:49:56Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 3, + "fields": { + "name": "First visible filter", + "desc": "", + "created": "2016-05-13T11:50:02Z", + "updated": "2016-05-13T11:50:02Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 4, + "fields": { + "name": "Second infrared filter", + "desc": "", + "created": "2016-05-13T11:50:07Z", + "updated": "2016-05-13T11:50:07Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 5, + "fields": { + "name": "Second visible filter", + "desc": "", + "created": "2016-05-13T11:50:11Z", + "updated": "2016-05-13T11:50:11Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 6, + "fields": { + "name": "Telescope", + "desc": "", + "created": "2016-05-13T11:50:14Z", + "updated": "2016-05-13T11:50:14Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 7, + "fields": { + "name": "Visible camera", + "desc": "", + "created": "2016-05-13T11:50:17Z", + "updated": "2016-05-13T11:50:17Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 8, + "fields": { + "name": "Cagire FW", + "desc": "", + "created": "2016-06-28T13:28:28Z", + "updated": "2016-06-28T13:28:28Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.device", + "pk": 9, + "fields": { + "name": "Visible Camera FW", + "desc": "", + "created": "2016-06-28T13:28:46Z", + "updated": "2016-06-28T13:28:46Z", + "is_online": false, + "status": "", + "maintenance_date": null + } +}, +{ + "model": "common.filter", + "pk": 1, + "fields": { + "device": 2, + "filter_wheel": 2, + "category": "", + "transmission_curve_doc": "" + } +}, +{ + "model": "common.filter", + "pk": 2, + "fields": { + "device": 4, + "filter_wheel": 2, + "category": "", + "transmission_curve_doc": "" + } +}, +{ + "model": "common.filter", + "pk": 3, + "fields": { + "device": 3, + "filter_wheel": 2, + "category": "", + "transmission_curve_doc": "" + } +}, +{ + "model": "common.filter", + "pk": 4, + "fields": { + "device": 5, + "filter_wheel": 2, + "category": "", + "transmission_curve_doc": "" + } +}, +{ + "model": "common.filterwheel", + "pk": 1, + "fields": { + "device": 8, + "detector": 1 + } +}, +{ + "model": "common.filterwheel", + "pk": 2, + "fields": { + "device": 9, + "detector": 2 + } +}, +{ + "model": "common.scientificprogram", + "pk": 1, + "fields": { + "name": "GRB", + "desc": "", + "quota": 9999.0, + "priority": 0, + "pyros_users": [ + 5 + ] + } +}, +{ + "model": "common.strategyobs", + "pk": 1, + "fields": { + "name": "strat1", + "desc": "", + "xml_file": "strat1.xml", + "is_default": false + } +}, +{ + "model": "common.strategyobs", + "pk": 2, + "fields": { + "name": "strat2", + "desc": "", + "xml_file": "strat2.xml", + "is_default": false + } +}, +{ + "model": "common.strategyobs", + "pk": 3, + "fields": { + "name": "strat_unittest", + "desc": "", + "xml_file": "strat_unittest.xml", + "is_default": true + } +}, +{ + "model": "common.telescope", + "pk": 1, + "fields": { + "device": 6, + "mount_type": "", + "diameter": null, + "status": "", + "latitude": null, + "longitude": null, + "sens": "", + "altitude": null, + "readout_time": null, + "slew_time": null, + "slew_dead": null, + "slew_rate_max": null, + "horizon_type": "", + "horizon_def": null, + "lim_dec_max": null, + "lim_dec_min": null, + "lim_ha_rise": null, + "lim_ha_set": null, + "address": "", + "night_elev_sun": null, + "mpc_code": "" + } +}, +{ + "model": "common.userlevel", + "pk": 1, + "fields": { + "name": "Developer", + "desc": "", + "priority": 0, + "quota": 9999.0 + } +}, +{ + "model": "common.version", + "pk": 1, + "fields": { + "module_name": "Scheduler", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 2, + "fields": { + "module_name": "Dashboard", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 3, + "fields": { + "module_name": "Observation Manager", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 4, + "fields": { + "module_name": "Routine Manager", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 5, + "fields": { + "module_name": "Alert Manager", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 6, + "fields": { + "module_name": "Monitoring", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 7, + "fields": { + "module_name": "User Manager", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 8, + "fields": { + "module_name": "Analyzer", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 9, + "fields": { + "module_name": "Majordome", + "version": "0.1", + "created": "2016-06-23T14:04:48Z", + "updated": "2016-06-23T14:04:48Z" + } +}, +{ + "model": "common.version", + "pk": 10, + "fields": { + "module_name": "Majordome", + "version": "0.2", + "created": "2016-06-28T10:50:32Z", + "updated": "2016-06-28T10:50:32Z" + } +}, +{ + "model": "common.version", + "pk": 11, + "fields": { + "module_name": "Majordome", + "version": "0.1.4", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 12, + "fields": { + "module_name": "Alert Manager", + "version": "0.2.3", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 13, + "fields": { + "module_name": "Dashboard", + "version": "0.1.1", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 14, + "fields": { + "module_name": "Observation Manager", + "version": "0.1.3", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 15, + "fields": { + "module_name": "Routine Manager", + "version": "0.1.2", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 16, + "fields": { + "module_name": "Monitoring", + "version": "0.1.3", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 17, + "fields": { + "module_name": "Scheduler", + "version": "0.1.2", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 18, + "fields": { + "module_name": "User Manager", + "version": "0.1.1", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "common.version", + "pk": 19, + "fields": { + "module_name": "Analyzer", + "version": "0.1.2", + "created": "2016-07-20T13:44:29Z", + "updated": "2016-07-20T13:44:29Z" + } +}, +{ + "model": "auth.user", + "pk": 9, + "fields": { + "password": "pbkdf2_sha256$24000$HRial3QUfrlz$bVuEzQaXthOd9GZVXd2449LDEF8EMQure69nA/Hu7qQ=", + "last_login": "2016-08-10T15:16:42.327Z", + "is_superuser": true, + "username": "pyros", + "first_name": "", + "last_name": "", + "email": "admin@example.com", + "is_staff": true, + "is_active": true, + "date_joined": "2016-08-10T15:15:58.481Z", + "groups": [], + "user_permissions": [] + } +}, +{ + "model": "common.pyrosuser", + "pk": 5, + "fields": { + "user": 9, + "country": 1, + "user_level": 1, + "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": 1000.0, + "quota_rea": null, + "u_priority": 1, + "p_priority": 1, + "dir_level": null, + "can_del_void_req": false + } +} +] diff --git a/src/misc/fixtures/simulation/simulation2.json b/src/misc/fixtures/simulation/simulation2.json new file mode 100644 index 0000000..d957fa8 --- /dev/null +++ b/src/misc/fixtures/simulation/simulation2.json @@ -0,0 +1,4 @@ +[ +{ +} +] diff --git a/src/pyros/__init__.py b/src/pyros/__init__.py index c7fb05a..7cfaeb1 100644 --- a/src/pyros/__init__.py +++ b/src/pyros/__init__.py @@ -9,11 +9,11 @@ from django.conf import settings @worker_ready.connect def start_permanent_tasks(signal, sender): import monitoring.tasks - import simulator.tasks + import simulator.userSimulator.tasks print(sender.hostname) if sender.hostname == "pyros@simulator": - simulator.tasks.simulator.delay() + simulator.userSimulator.tasks.simulator.delay() if sender.hostname == "pyros@monitoring": monitoring.tasks.monitoring.delay() diff --git a/src/pyros/settings.py b/src/pyros/settings.py index 4aeb02b..2e6bfa2 100644 --- a/src/pyros/settings.py +++ b/src/pyros/settings.py @@ -242,7 +242,7 @@ CELERY_IMPORTS = ( "monitoring.tasks", "observation_manager.tasks", "scheduler.tasks", - "simulator.tasks", + "simulator.userSimulator.tasks", ) # This config allows only 1 process / queue. We replace it by the -c option at celery workers creation. @@ -278,7 +278,7 @@ CELERY_ROUTES = { "observation_manager.tasks.execute_plan_nir": {"queue": "execute_plan_nir_q"}, "observation_manager.tasks.create_calibrations": {"queue": "create_calibrations_q"}, "scheduler.tasks.scheduling": {"queue": "scheduling_q"}, - "simulator.tasks.simulator": {"queue": "simulator_q"}, + "simulator.userSimulator.tasks.simulator": {"queue": "simulator_q"}, } ''' Removes pickle warning ''' diff --git a/src/scripts/kill_simulation.sh b/src/scripts/kill_simulation.sh index bd49745..dbf7c9c 100755 --- a/src/scripts/kill_simulation.sh +++ b/src/scripts/kill_simulation.sh @@ -5,6 +5,7 @@ cd $SCRIPT_PATH/.. #Reseting sed -i -e "s/CELERY_TEST = True/CELERY_TEST = False/g" pyros/settings.py +sed -i -e "s/.*SIMULATOR_VALUE = .*/SIMULATOR_VALUE = None/g" simulator/userSimulator/tasks.py #Kill web server fuser -k 8000/tcp diff --git a/src/scripts/simulator_launch.sh b/src/scripts/simulator_launch.sh index 35021ba..06464d8 100755 --- a/src/scripts/simulator_launch.sh +++ b/src/scripts/simulator_launch.sh @@ -4,27 +4,73 @@ SCRIPT_PATH=${SCRIPT_PATH%/*} cd $SCRIPT_PATH/.. +echo -n "Existing simulations : " +ls misc/fixtures/simulation/ +echo -n "Enter which simulation you want to launch : " +read -r line + +if [ ! -f misc/fixtures/simulation/"$line" ]; then + echo "This simulation doesn't exist" + exit +fi + +sed -i -e "s/SIMULATOR_VALUE = None/SIMULATOR_VALUE = '$line'/g" simulator/userSimulator/tasks.py sed -i -e "s/CELERY_TEST = False/CELERY_TEST = True/g" pyros/settings.py +trap ctrl_c INT + +function ctrl_c() { + ./../pyrosrun.sh kill_simulation + killall ALERTsimulator.py + killall PLCsimulator.py + echo "Ctrl-c catched, all process launched have been killed" + exit +} + + rm -f testdb.sqlite3 python manage.py migrate python manage.py loaddata misc/fixtures/initial_fixture.json -echo "----------------WEB SERVER----------------" +python manage.py loaddata misc/fixtures/simulation/"$line" + +echo "----------------LAUNCHING WEB SERVER----------------" python manage.py runserver & sleep 2 -echo "----------------WEB SERVER----------------" +echo "----------------WEB SERVER LAUNCHED-----------------" -#launch simulator workers -./scripts/start_simulator_worker.sh 2>&1 /dev/null - -echo "----------------------------SUMMARY-------------------------------------" -echo "The simulator has been successfully launched" +echo "----------------------------------------SUMMARY---------------------------------------------" +echo "The simulator has been successfully initialised" echo "The simulator run on a temp database : src/testdb.sqlite3" echo "The simulation will be ended by the task 'simulator herself'" echo "If you want to shutdown the simulation, please run :" -echo "./pyrosrun.sh kill_simulation" +echo "CTRL-C or ./pyrosrun.sh kill_simulation" echo "If the simulation isn't correctly killed, please switch the variable" echo "CELERY_TEST in src/pyros/settings.py to false" -echo "----------------------------SUMMARY-------------------------------------" +echo "" +echo "----------------------------------------SUMMARY---------------------------------------------" +echo "" +read -n1 -r -p "Press any key to continue..." key + +#launch simulator workers +./scripts/start_simulator_worker.sh 2>&1 /dev/null + +#launch simulators binaries +python simulator/alertSimulator/ALERTsimulator.py "$line" & +ALERTPID=$! +python simulator/plcSimulator/PLCsimulator.py "$line" & +PLCPID=$! + +echo "" +echo "Waiting for ALERTsimulator to finish" +wait "$ALERTPID" +echo "Alersimulator finished" +echo "" +echo "Waiting for PLCsimulator to finish" +wait "$PLCPID" +echo "PLCsimulator finished" +echo "" +echo "Killing all processes" + +./../pyrosrun.sh kill_simulation diff --git a/src/scripts/start_simulator_worker.sh b/src/scripts/start_simulator_worker.sh index 7efc43a..58b515c 100755 --- a/src/scripts/start_simulator_worker.sh +++ b/src/scripts/start_simulator_worker.sh @@ -9,7 +9,6 @@ source ../private/venv_py3_pyros/bin/activate ./scripts/kill_celery_workers.sh - celery worker -A pyros -Q monitoring_q -n pyros@monitoring -c 1 & celery worker -A pyros -Q alert_listener_q -n pyros@alert_listener -c 1 & celery worker -A pyros -Q simulator_q -n pyros@simulator -c 1 & diff --git a/src/simulator/__init__.py b/src/simulator/__init__.py index d81ec95..e69de29 100644 --- a/src/simulator/__init__.py +++ b/src/simulator/__init__.py @@ -1,2 +0,0 @@ -default_app_config = 'simulator.apps.SimulatorConfig' - diff --git a/src/simulator/admin.py b/src/simulator/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/src/simulator/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/src/simulator/alertSimulator/ALERTsimulator.py b/src/simulator/alertSimulator/ALERTsimulator.py new file mode 100644 index 0000000..0b7d200 --- /dev/null +++ b/src/simulator/alertSimulator/ALERTsimulator.py @@ -0,0 +1,17 @@ +import sys +import time + +class AlertSimulator(): + def __init__(self, argv): + if (len(argv) > 1): + self.path = argv[1] + pass + + def run(self): + print("Alert Simulator %s"%self.path) + time.sleep(2) + pass + +if __name__ == "__main__": + sim = AlertSimulator(sys.argv) + sim.run() diff --git a/src/simulator/alertSimulator/__init__.py b/src/simulator/alertSimulator/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/simulator/alertSimulator/__init__.py diff --git a/src/simulator/apps.py b/src/simulator/apps.py deleted file mode 100644 index e91a69c..0000000 --- a/src/simulator/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class SimulatorConfig(AppConfig): - name = 'simulator' diff --git a/src/simulator/migrations/__init__.py b/src/simulator/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/simulator/migrations/__init__.py +++ /dev/null diff --git a/src/simulator/models.py b/src/simulator/models.py deleted file mode 100644 index 71a8362..0000000 --- a/src/simulator/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/src/simulator/plcSimulator/PLCsimulator.py b/src/simulator/plcSimulator/PLCsimulator.py new file mode 100644 index 0000000..c4be8a5 --- /dev/null +++ b/src/simulator/plcSimulator/PLCsimulator.py @@ -0,0 +1,15 @@ +import sys +import time + +class PLCSimulator(): + def __init__(self, argv): + pass + + def run(self): + print("PLC simulator running") + time.sleep(4) + pass + +if __name__ == "__main__": + sim = PLCSimulator(sys.argv) + sim.run() diff --git a/src/simulator/plcSimulator/__init__.py b/src/simulator/plcSimulator/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/simulator/plcSimulator/__init__.py diff --git a/src/simulator/tasks.py b/src/simulator/tasks.py deleted file mode 100644 index 2bc1e13..0000000 --- a/src/simulator/tasks.py +++ /dev/null @@ -1,69 +0,0 @@ -from __future__ import absolute_import -from django.conf import settings -from common.models import * -from celery.task import Task - -import logger.config as l -import sys -import os -import time - -log = l.setupLogger("simulator", "simulator") - -class SimulatorRoutines(): - def __init__(self, quantity, dtime): - self.quantity = quantity - self.dtime = dtime - log.info("SimulatorRoutines class instantiated with %d routines to be executed with an interval of time %d"%(quantity,dtime)) - - # First create some scientific programs - def createScientificPrograms(self): - pass - - # create some user levels with diferent priorities - def createUserLevels(self): - pass - - # create some pyros users - def createPyrosUsers(self, country, user_id, user_level_id): - pass - - # create auth users - def createAuthUsers(self): - - # You can now create Requests - def createRequest(self, pyros_user_id, scientific_program_id): - pass - - # requests must have sequences - def createSequences(self, request): - pass - - # Sequences must have albums - def createAlbums(self, sequence): - pass - - # albums must have plans - def createPlans(self, album): - pass - - def process(self): - pass - - -class simulator(Task): - shouldClean = False - - def run(self): - simu = SimulatorRoutines(100, 2) - # for schedule in py_schedules: - - - # 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) - sim.shouldClean = False - sim.run() diff --git a/src/simulator/tests.py b/src/simulator/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/src/simulator/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/simulator/urls.py b/src/simulator/urls.py deleted file mode 100644 index 18537c7..0000000 --- a/src/simulator/urls.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.conf.urls import url -from . import views - -urlpatterns = [ - ] diff --git a/src/simulator/userSimulator/__init__.py b/src/simulator/userSimulator/__init__.py new file mode 100644 index 0000000..d81ec95 --- /dev/null +++ b/src/simulator/userSimulator/__init__.py @@ -0,0 +1,2 @@ +default_app_config = 'simulator.apps.SimulatorConfig' + diff --git a/src/simulator/userSimulator/admin.py b/src/simulator/userSimulator/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/simulator/userSimulator/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/simulator/userSimulator/apps.py b/src/simulator/userSimulator/apps.py new file mode 100644 index 0000000..e91a69c --- /dev/null +++ b/src/simulator/userSimulator/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SimulatorConfig(AppConfig): + name = 'simulator' diff --git a/src/simulator/userSimulator/migrations/__init__.py b/src/simulator/userSimulator/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/simulator/userSimulator/migrations/__init__.py diff --git a/src/simulator/userSimulator/models.py b/src/simulator/userSimulator/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/simulator/userSimulator/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/simulator/userSimulator/tasks.py b/src/simulator/userSimulator/tasks.py new file mode 100644 index 0000000..5ba250a --- /dev/null +++ b/src/simulator/userSimulator/tasks.py @@ -0,0 +1,174 @@ +from __future__ import absolute_import +from django.conf import settings +from common.models import * +from celery.task import Task + +import logger.config as l +import sys +import os +import time +import json + +log = l.setupLogger("simulator", "simulator") + +SIMULATOR_VALUE = None + +class simulator(Task): + shouldClean = False + + def loadJson(self, path): + json_data = open(path, 'r') + # if (not json_data.is_open()): + + def run(self): + print('-------------------------------') + print(SIMULATOR_VALUE) + + # 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) + sim.shouldClean = False + sim.run() + + +""" +class SimulatorRoutines(): + def __init__(self, dtime): + self.dtime = dtime + self.dicto = { + "SCIENTIFIC_PROGRAMS" : self.createScientificPrograms, + "USER_LEVELS" : self.createUserLevels, + "PYROS_USERS" : self.createPyrosUsers, + "AUTH_USERS" : self.createAuthUsers, + "REQUESTS" : self.createRequest, + "ALBUMS" : self.createAlbums, + "PLANS" : self.createPlans, + "DETECTORS" : self.createDetector, + "TELESCOPES" : self.createTelescope, + "DEVICES" : self.createDev + } + + USER PART + # First create some scientific programs + def createScientificPrograms(self, params, default=False): + sc = [] + i = 0 + # for (value in self.data["SCIENTIFIC_PROGRAMS"]): + + if (quantity == -1): + return (sc) + while (quantity > i): + sc[i] = ScientificProgram(name="Sc_test-%d"%quantity, desc="Simulation", quota=(100 / quantity), priority=i) + sc[i].save + i += 1 + return (sc) + + # create some user levels with diferent priorities + def createUserLevels(self, params, default=False): + pass + + # create some pyros users -> country, user_id, user_level_id + def createPyrosUsers(self, params, default=False): + pass + + # create auth users + def createAuthUsers(self, params, default=False): + pass + + + + + DEVICE PART + # if you want to create an album you must have a detector + # device, telescope + def createDetector(self, params, default=False): + pass + + # detector must have a telescope + # device + def createTelescope(self, params, default=False): + pass + + # detector AND telescope must have a device + def createDevice(self, params, default=False): + dc = [] + i = 0 + + if (quantity == -1): + # TODO create from class array loaded by loadJson + return (dc) + while (quantity > i): + dc[i] = Device(name="testdevice-%d"%i, desc="Simulator", + create=datetime.datetime.now(), updated=datetime.datetime.now(), + is_online="1", status="Online") + i += 1 + return (dc) + + + + ROUTINE PART + # You can now create Requests + # pyros_user_id, scientific_program_id + def createRequest(self, params, default=False): + pass + + # requests must have sequences + # Request + def createSequences(self, params, default=False): + pass + + # Sequences must have albums and albums must have a detector + # sequence, detector + def createAlbums(self, params, default=False): + pass + + # albums must have plans + # album id, plan id + def createPlans(self, params, default=False): + pass + + SIMULATOR PART + def prepareDatabase(self): + for (key, value in self.data): + for (name, func in self.dicto): + if (name == key): + ret = func(value) + if (not ret): + return (False) + return (True) + + def loadJson(self, path): + json_data = open(path, 'r') + if (not json_data.is_open()): + return (False) + self.init = True + data1 = json.load(json_data) + self.data = data1 + json_data.close() + return (True) + + def process(self): + + for (key, value in dicto): + array_object = value() + for (value in array_object): + value.save() + pass +class simulator(Task): + shouldClean = False + + def run(self): + simu = SimulatorRoutines(100, 2) + simu.loadJson("%s/../public/simulation/data.json"%settings.BASE_DIR) + simu.prepareDatabase() + simu.create + simu.process() + + # END OF EXECTUION (KILLING WEB SERVER AN PROCESS) + if (self.shouldClean == True): + os.system("%s/../pyrosrun.sh kill_simulation"%settings.BASE_DIR) + +""" diff --git a/src/simulator/userSimulator/tests.py b/src/simulator/userSimulator/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/simulator/userSimulator/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/simulator/userSimulator/urls.py b/src/simulator/userSimulator/urls.py new file mode 100644 index 0000000..18537c7 --- /dev/null +++ b/src/simulator/userSimulator/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + ] diff --git a/src/simulator/userSimulator/views.py b/src/simulator/userSimulator/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/src/simulator/userSimulator/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/src/simulator/views.py b/src/simulator/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/src/simulator/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. -- libgit2 0.21.2