Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. package logic;
  2.  
  3. import be.kdg.se3legacy.proxy.UserCallbackListener;
  4. import interfaces.Controle;
  5. import interfaces.Response;
  6. import model.CameraResponse;
  7. import model.LicensePlate;
  8. import model.Message;
  9. import model.Offense;
  10.  
  11. import java.util.Date;
  12. import java.util.HashMap;
  13. import java.util.Map;
  14.  
  15. /**
  16. * Created by Steven on 1-11-2014.
  17. */
  18. public class SegmentControlenew implements UserCallbackListener {
  19. private Map<CameraResponse, Message> messages = new HashMap<CameraResponse, Message>();
  20.  
  21. private Message latestMessage;
  22. private Response latestReponse;
  23. private CameraResponse response;
  24. private double speed;
  25. boolean found = false;
  26.  
  27. public void addMessageAndResponse(Message m, Response r) {
  28. latestMessage = m;
  29. latestReponse = r;
  30. messages.put((CameraResponse) latestReponse, latestMessage);
  31. }
  32.  
  33. public void checkIfIlligal(Message message){
  34. for (Map.Entry<CameraResponse, Message> entry : messages.entrySet()) {
  35. response = entry.getKey();
  36. Message firstMessage = entry.getValue();
  37.  
  38. if(response.segment.connectedCamera == message.getCameraId() && firstMessage.getLicensePlate().equals(message.getLicensePlate()) ){
  39. calcSpeed(response.segment.distance,firstMessage.getTimeStamp(),message.getTimeStamp(),response.segment.speedLimit,message.getLicensePlate());
  40. messages.remove(response,firstMessage);
  41. }
  42. }
  43. }
  44.  
  45. public void calcSpeed(int distance, Date beginTime, Date endTime, int limit, String plate) {
  46. double speed = 0.00;
  47. double diff = endTime.getTime() - beginTime.getTime();
  48. double diffHour = diff / (60 * 60 * 1000) % 60;
  49. speed = distance / diffHour;
  50. System.out.println("speed: " + speed);
  51. if (speed > limit) {
  52. this.speed = speed;
  53. new UserService(plate, this);
  54. }
  55. }
  56.  
  57. @Override
  58. public void onUserInfo(String s) {
  59. Offense offense = new Offense();
  60. offense.setCarType(latestMessage.getCarType());
  61. LicensePlate plate = new LicensePlate();
  62. plate.setPlate(latestMessage.getLicensePlate());
  63. offense.setLicensePlate(plate);
  64. offense.setOwner(s);
  65. offense.setTimeOffense(new Date());
  66. offense.setSpeed(speed);
  67. double[] location = response.getLocation();
  68. offense.setLocation(Double.toString(location[0]) + "-" + Double.toString(location[1]));
  69.  
  70. System.out.println("License plate: " + latestMessage.getLicensePlate() + " gave result: " + s);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement