コード例 #1
0
  public void getRate() {
    RouteId id = new RouteId();
    HubEntity hub = hubsRegistry.findHubByName(selectedHub);
    CoefficientsInfo coef = hubsRegistry.getCoefficientsForHub(selectedHub);
    id.setDestName(Parser.getCity(destination));
    id.setDestState(Parser.getState(destination));
    id.setHubName(hub.getCity());
    id.setHubState(hub.getState());
    RouteEntity route = repo.findRoute(id);

    if (route == null) {
      try {
        route =
            GoogleHandler.createRouteEntity(
                id.getHubName(), id.getHubState(), id.getDestName(), id.getDestState());
        route = repo.saveRoute(route, id);
      } catch (GoogleServiceParamException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    float interceptX = coef.getIntercept().getX();
    float rate = 0;
    if (route.getDistanceInMiles() < interceptX) {
      rate = route.getDistanceInMiles() * coef.getCoef1().getBeta() + coef.getCoef1().getAlpha();
    } else {
      rate = route.getDistanceInMiles() * coef.getCoef2().getBeta() + coef.getCoef2().getAlpha();
    }

    Messanger.show(
        "Got rate ",
        route.getDestName() + " : " + route.getDistanceInMiles() + "mi, rate: " + rate);
  }
コード例 #2
0
  public void generateReport() {
    if (destinationsTA.isEmpty()) return;
    List<String> lines = Parser.getLines(destinationsTA);
    Map<String, Set<String>> existingRoutesByDestMap = new HashMap<String, Set<String>>();
    Map<String, Set<String>> to = new HashMap<String, Set<String>>();
    Map<String, Set<String>> from = new HashMap<String, Set<String>>();
    Report report = new Report();
    List<String> errors = new ArrayList<String>();
    String destCity = "", destState = "";
    State destStateEnm, hubStateEnm;
    for (String line : lines) {
      System.out.println(line);
      destCity = Parser.getCity(line);
      destState = Parser.getState(line);
      try {
        destStateEnm = State.valueOf(destState);
      } catch (IllegalArgumentException e) {
        continue;
      }
      for (String hubName : hubsRegistry.getHubsNames()) {
        String hubCity = Parser.getCity(hubName);
        String hubState = Parser.getState(hubName);
        try {
          hubStateEnm = State.valueOf(hubState);
        } catch (IllegalArgumentException e) {
          continue;
        }
        if (destStateEnm != hubStateEnm
            & !catchment.getDestinations().get(destStateEnm).contains(hubStateEnm)) continue;
        RouteId id = new RouteId();
        id.setHubName(hubCity);
        id.setHubState(hubState);
        id.setDestName(destCity);
        id.setDestState(destState);
        RouteEntity route = repo.findRoute(id);
        System.out.println("Found route: " + route);
        // add to request
        if (route == null) {
          System.out.println("Adding to request");
          if (to.containsKey(destState)) to.get(destState).add(destCity);
          else {
            Set<String> dCities = new HashSet<String>();
            dCities.add(destCity);
            to.put(destState, dCities);
          }
          if (from.containsKey(hubState)) from.get(hubState).add(hubCity);
          else {
            Set<String> hCities = new HashSet<String>();
            hCities.add(hubCity);
            from.put(hubState, hCities);
          }
          System.out.println("REquest : " + to + " / " + from);
        }
        // add to report
        else {
          // for(HubServiceEntity service :
          // hubsRegistry.getServicesForHub(hub.getShortName())){
          try {
            report.add(
                route,
                hubsRegistry.getServicesForHub(hubName),
                hubsRegistry.getCoefficientsForHub(hubName));
            if (existingRoutesByDestMap.containsKey(destCity + "," + destState))
              existingRoutesByDestMap.get(destCity + "," + destState).add(hubName);
            else {
              Set<String> hubsList = new HashSet<String>();
              hubsList.add(hubName);
              existingRoutesByDestMap.put(destCity + "," + destState, hubsList);
            }

          } catch (ReportEntryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }
    List<RouteInfo> routeInfoList = getRouteInfoForDestinations(from, to, errors);
    List<RouteEntity> savedRoutes = repo.saveRoutes(routeInfoList);
    for (RouteEntity route : savedRoutes) {
      try {
        report.add(
            route,
            hubsRegistry.getServicesForHub(route.getHubName() + "," + route.getHubState()),
            hubsRegistry.getCoefficientsForHub(route.getHubName() + "," + route.getHubState()));
      } catch (ReportEntryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    System.out.println(routeInfoList);
    System.out.println(report);
    ReportRow row;

    for (Entry<String, ArrayList<ReportEntry>> next : report.entrySet()) {
      row = new ReportRow();
      row.setDestInfo(next.getKey());
      ArrayList<ReportEntry> list = next.getValue();
      Collections.sort(list);
      row.setEntries(list);
      entries.add(row);
    }
    // }
    Messanger.show("Got rate ", report.size() + "/");
  }