diff --git a/apps/cgs/models.py b/apps/cgs/models.py index ba2e952..2350e18 100644 --- a/apps/cgs/models.py +++ b/apps/cgs/models.py @@ -71,7 +71,7 @@ class CGSConfiguration(Configuration): route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" try: - r = requests.get(route,timeout=1) + r = requests.get(route,timeout=0.5) except: self.device.status = 0 self.device.save() @@ -110,7 +110,7 @@ class CGSConfiguration(Configuration): route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" try: - frequencies = requests.get(route,timeout=1) + frequencies = requests.get(route,timeout=0.5) except: self.message = "Could not read CGS parameters from this device" @@ -148,7 +148,7 @@ class CGSConfiguration(Configuration): route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" try: - r = requests.post(route, post_data, timeout=1) + r = requests.post(route, post_data, timeout=0.5) except: self.message = "Could not write CGS parameters" return None diff --git a/apps/main/views.py b/apps/main/views.py index ae27307..acfc699 100644 --- a/apps/main/views.py +++ b/apps/main/views.py @@ -963,15 +963,49 @@ def operation_search(request, id_camp=None): def radar_play(request, id_camp, id_radar): campaign = get_object_or_404(Campaign, pk = id_camp) radar = get_object_or_404(Location, pk = id_radar) - experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) - current_time = datetime.today() - #exp = RunningExperiment( - # radar = purchase_request.user_id, - # running_experiment = purchase_request, - # status = , - # ) - #new_pos.append(exp) - #exp.save() + today = datetime.today() + now = today.time() + + #--If campaign datetime is ok: + if today >= campaign.start_date and today <= campaign.end_date: + experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) + for exp in experiments: + #--If experiment time is ok: + if now >= exp.start_time and now <= exp.end_time: + configurations = Configuration.objects.filter(experiment = exp) + for conf in configurations: + if 'cgs' in conf.device.device_type.name: + conf.status_device() + else: + answer = conf.start_device() + conf.status_device() + #--Running Experiment + r_e = RunningExperiment.objects.filter(radar=radar) + #--If RunningExperiment element exists + if r_e: + r_e = r_e[0] + r_e.running_experiment = exp + r_e.status = 3 + r_e.save() + else: + running_experiment = RunningExperiment( + radar = radar, + running_experiment = exp, + status = 3, + ) + running_experiment.save() + + if answer: + messages.success(request, conf.message) + exp.status=2 + exp.save() + else: + messages.error(request, conf.message) + else: + if exp.status == 1 or exp.status == 3: + exp.status=3 + exp.save() + route = request.META['HTTP_REFERER'] route = str(route)