PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/traveldashboard/server/data/MetroGeneralCrowdGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 53 lines | 30 code | 19 blank | 4 comment | 5 complexity | c2064c2bfd4c2015cc7feb5c0df2a5e1 MD5 | raw file
  1. package traveldashboard.server.data;
  2. import java.util.TimeZone;
  3. import org.ibicoop.sdp.config.NetworkMessage;
  4. import com.google.gson.Gson;
  5. public class MetroGeneralCrowdGetterUtils extends ResponseUtils {
  6. private static final String TAG = "GeneralCrowdGetterUtils";
  7. public static NetworkMessage getMetroGeneralCrowdMessage(NetworkMessage req) {
  8. String methodTag = "getMetroGeneralCrowdMessage";
  9. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "Getting metro general crowd message...");
  10. NetworkMessage resp = prepareMsgReturn(req);
  11. String city = req.getPayload(DataConstants.PARAM_KEY_CITY_TYPE);
  12. String stopId = req.getPayload(DataConstants.PARAM_KEY_STOP_ID);
  13. String routeId = req.getPayload(DataConstants.PARAM_KEY_ROUTE_ID);
  14. long timestamp = Long.parseLong(req.getPayload(DataConstants.PARAM_KEY_TIMESTAMP));
  15. long interval = Long.parseLong(req.getPayload(DataConstants.PARAM_KEY_INTERVAL));
  16. String timeZone = "";
  17. if (city.equals(DataConstants.PARIS)) {
  18. timeZone = "Europe/Paris";
  19. } else if (city.equals(DataConstants.LONDON)) {
  20. timeZone = "Europe/London";
  21. }
  22. //Set to local timestamp
  23. timestamp = timestamp - TimeZone.getDefault().getRawOffset() +
  24. TimeZone.getTimeZone(timeZone).getRawOffset();
  25. Gson gson = new Gson();
  26. //Get crowd data until interval ago
  27. //String json = gson.toJson(MongoDbManager.getMetroGeneralCrowd(city, stopId, routeId, timestamp, interval));
  28. //Get crowd data until 6 times interval ago
  29. String json = gson.toJson(MongoDbManager.getMetroGeneralCrowdCollection(city, stopId, routeId, timestamp, interval));
  30. resp.addPayload(DataConstants.METRO_GENERAL_CROWD_MESSAGE, json);
  31. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "End get crowdedness message : " + new String(resp.encode()));
  32. return resp;
  33. }
  34. }