tasks.py
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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)
"""