public double getPeak(Sensor sensor) { String sensorName = sensor.getSensorName(); if (session.hasStream(sensorName)) { return session.getStream(sensorName).getPeak(); } else { return 0; } }
public List<Measurement> getMeasurements(Sensor sensor) { String name = sensor.getSensorName(); if (session.hasStream(name)) { MeasurementStream stream = session.getStream(name); return stream.getMeasurements(); } else { return newArrayList(); } }
private MeasurementStream prepareStream(SensorEvent event) { String sensorName = event.getSensorName(); if (!session.hasStream(sensorName)) { MeasurementStream stream = event.stream(); tracker.addStream(stream); } MeasurementStream stream = session.getStream(sensorName); if (stream.isVisible()) { stream.markAs(MeasurementStream.Visibility.VISIBLE_RECONNECTED); } return stream; }
@Before public void setup() { sessionManager.sessionRepository = mock(SessionRepository.class); sessionManager.session = new Session(); sessionManager.session.add(new SoundMeasurement()); session = new Session(); session.setTitle("New title"); }
void deleteSensorStream(String sensorName) { MeasurementStream stream = getMeasurementStream(sensorName); if (stream == null) { Logger.w("No stream for sensor [" + sensorName + "]"); return; } sessionRepository.deleteStream(session, stream); session.removeStream(stream); }
private Location getLocation() { Location location = locationHelper.getLastLocation(); if (session.isLocationless()) { location = new Location("fake"); location.setLatitude(TOTALLY_FAKE_COORDINATE); location.setLongitude(TOTALLY_FAKE_COORDINATE); } return location; }
private int getOffset(Session session) { List<MeasurementStream> streams = session.getActiveMeasurementStreams(); for (MeasurementStream stream : streams) { List<Measurement> measurements = stream.getMeasurements(); for (Measurement measurement : measurements) { return measurement.getTimeZoneOffsetMinutes(); } } return 0; }
public void fromUTCtoLocal(Session session) { if (needsTimeFix(session)) { fixStartEndTimeFromMeasurements(session); } int minutes = getOffset(session); int offset = minutes * 60 * 1000; Date start = session.getStart(); Date end = session.getEnd(); session.setStart(new Date(start.getTime() + offset)); session.setEnd(new Date(end.getTime() + offset)); List<MeasurementStream> streams = session.getActiveMeasurementStreams(); for (MeasurementStream stream : streams) { List<Measurement> measurements = stream.getMeasurements(); for (Measurement measurement : measurements) { measurement.setTime(new Date(measurement.getTime().getTime() + offset)); } } }
void fixStartEndTimeFromMeasurements(Session session) { Date start = session.getStart(); Date end = session.getEnd(); for (MeasurementStream stream : session.getMeasurementStreams()) { List<Measurement> measurements = stream.getMeasurements(); if (measurements.isEmpty()) { continue; } Measurement first = measurements.get(0); Measurement last = measurements.get(measurements.size() - 1); if (start == null) { start = first.getTime(); } else { start = start.before(first.getTime()) ? start : first.getTime(); } if (end == null) { end = last.getTime(); } else { end = end.before(last.getTime()) ? last.getTime() : end; } } if (start == null || end == null) { String message = "Session [" + session.getId() + "] has incorrect start/end date [" + start + "/" + end + "]"; throw new SessionSyncException(message); } session.setStart(new Date(start.getTime())); session.setEnd(new Date(end.getTime())); }
boolean needsTimeFix(Session session) { return session.getStart() == null || session.getEnd() == null; }
public void updateHeader(Session session) { this.title = session.getTitle(); this.tags = session.getTags(); this.description = session.getDescription(); }
public boolean isLocationless() { return session.isLocationless(); }
public void updateSession(Session from) { Preconditions.checkNotNull(from.getId(), "Unsaved session?"); setTitleTagsDescription(from.getId(), from.getTitle(), from.getTags(), from.getDescription()); }
public void deleteSession() { Long sessionId = session.getId(); sessionRepository.markSessionForRemoval(sessionId); discardSession(sessionId); }
public MeasurementStream getMeasurementStream(String sensorName) { return session.getStream(sensorName); }
public Collection<MeasurementStream> getMeasurementStreams() { return newArrayList(session.getActiveMeasurementStreams()); }
public int getNoteCount() { return session.getNotes().size(); }
public Note getNote(int i) { return session.getNotes().get(i); }