Skip to content

Commit

Permalink
load schedule for each device separately
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Apr 3, 2024
1 parent 66a3543 commit 1721529
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ru/r2cloud/R2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import ru.r2cloud.web.api.device.DeviceConfigList;
import ru.r2cloud.web.api.device.DeviceConfigLoad;
import ru.r2cloud.web.api.device.DeviceConfigSave;
import ru.r2cloud.web.api.device.DeviceSchedule;
import ru.r2cloud.web.api.observation.ObservationList;
import ru.r2cloud.web.api.observation.ObservationLoad;
import ru.r2cloud.web.api.observation.ObservationLoadPresentation;
Expand Down Expand Up @@ -260,6 +261,7 @@ public R2Cloud(Configuration props, Clock clock) {
index(new DeviceConfigList(deviceManager));
index(new DeviceConfigDelete(props, deviceManager));
index(new Restart());
index(new DeviceSchedule(deviceManager, satelliteDao));
webServer = new WebServer(props, controllers, auth, signed);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ru/r2cloud/satellite/ObservationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ObservationFactory {

private static final Logger LOG = LoggerFactory.getLogger(ObservationFactory.class);
private static final long MAX_OBSERVATION_MILLIS = 15 * 60 * 1000;
private static final long MIN_OBSERVATION_MILLIS = 4 * 60 * 1000;

private final PredictOreKit predict;

Expand Down Expand Up @@ -55,6 +56,9 @@ public List<ObservationRequest> createSchedule(AntennaConfiguration antenna, Dat
result.add(convert(transmitter, transmitter.getTle(), startMillis, startMillis + MAX_OBSERVATION_MILLIS));
startMillis += MAX_OBSERVATION_MILLIS;
}
if (endMillis - startMillis < MIN_OBSERVATION_MILLIS) {
continue;
}
result.add(convert(transmitter, transmitter.getTle(), startMillis, endMillis));
}
return result;
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/ru/r2cloud/web/api/device/DeviceSchedule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ru.r2cloud.web.api.device;

import java.util.Collections;
import java.util.List;

import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;

import fi.iki.elonen.NanoHTTPD.IHTTPSession;
import ru.r2cloud.device.Device;
import ru.r2cloud.device.DeviceManager;
import ru.r2cloud.model.ObservationRequest;
import ru.r2cloud.model.Satellite;
import ru.r2cloud.satellite.ObservationRequestComparator;
import ru.r2cloud.satellite.SatelliteDao;
import ru.r2cloud.web.AbstractHttpController;
import ru.r2cloud.web.ModelAndView;
import ru.r2cloud.web.NotFound;
import ru.r2cloud.web.WebServer;

public class DeviceSchedule extends AbstractHttpController {

private final DeviceManager deviceManager;
private final SatelliteDao satelliteDao;

public DeviceSchedule(DeviceManager deviceManager, SatelliteDao satelliteDao) {
this.deviceManager = deviceManager;
this.satelliteDao = satelliteDao;
}

@Override
public ModelAndView doGet(IHTTPSession session) {
String id = WebServer.getParameter(session, "id");
Device device = deviceManager.findDeviceById(id);
if (device == null) {
return new NotFound();
}
JsonArray result = new JsonArray();
List<ObservationRequest> request = device.findScheduledObservations();
Collections.sort(request, ObservationRequestComparator.INSTANCE);
for (ObservationRequest cur : request) {
Satellite satellite = satelliteDao.findById(cur.getSatelliteId());
if (satellite == null) {
continue;
}
JsonObject curRequest = new JsonObject();
curRequest.set("id", cur.getId());
curRequest.set("start", cur.getStartTimeMillis());
curRequest.set("end", cur.getEndTimeMillis());
curRequest.set("satelliteId", cur.getSatelliteId());
curRequest.set("name", satellite.getName());
result.add(curRequest);
}
ModelAndView model = new ModelAndView();
model.setData(result);
return model;
}

@Override
public String getRequestMappingURL() {
return "/api/v1/admin/device/schedule";
}

}
46 changes: 23 additions & 23 deletions src/main/java/ru/r2cloud/web/api/schedule/ScheduleFull.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@

public class ScheduleFull extends AbstractHttpController {

private final DeviceManager deviceManager;
private final DeviceManager deviceManager;

public ScheduleFull(DeviceManager deviceManager) {
this.deviceManager = deviceManager;
}
public ScheduleFull(DeviceManager deviceManager) {
this.deviceManager = deviceManager;
}

@Override
public ModelAndView doGet(IHTTPSession session) {
JsonArray entity = new JsonArray();
for (ObservationRequest cur : deviceManager.findScheduledObservations()) {
JsonObject curRequest = new JsonObject();
curRequest.add("id", cur.getId());
curRequest.add("satelliteId", cur.getSatelliteId());
curRequest.add("start", cur.getStartTimeMillis());
curRequest.add("end", cur.getEndTimeMillis());
entity.add(curRequest);
}
ModelAndView result = new ModelAndView();
result.setData(entity);
return result;
}
@Override
public ModelAndView doGet(IHTTPSession session) {
JsonArray entity = new JsonArray();
for (ObservationRequest cur : deviceManager.findScheduledObservations()) {
JsonObject curRequest = new JsonObject();
curRequest.add("id", cur.getId());
curRequest.add("satelliteId", cur.getSatelliteId());
curRequest.add("start", cur.getStartTimeMillis());
curRequest.add("end", cur.getEndTimeMillis());
entity.add(curRequest);
}
ModelAndView result = new ModelAndView();
result.setData(entity);
return result;
}

@Override
public String getRequestMappingURL() {
return "/api/v1/admin/schedule/full";
}
@Override
public String getRequestMappingURL() {
return "/api/v1/admin/schedule/full";
}
}

0 comments on commit 1721529

Please sign in to comment.