Пример #1
0
  public void readDumpedPersons(String file) {
    try {
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
      String curr_line;
      while ((curr_line = br.readLine()) != null) {
        String[] entrs = curr_line.split(";", -1);
        Id<Person> userId = Id.create(entrs[0].trim().substring(4, 8), Person.class);

        EstimationPerson person = new EstimationPerson(userId);
        this.population.put(userId, person);

        person.setAge(Math.max(0, Integer.parseInt(entrs[1].trim())));

        if (entrs[2].trim().equals("w")) {
          person.setSex("f");
        } else if (entrs[2].trim().equals("m")) {
          person.setSex("m");
        } else {
          person.setSex("-99");
        }

        person.setWeight(1.0);
        // TODO: hh income -99 = AHV
        if (!entrs[3].trim().equals("")) {
          person.setHhIncome(Integer.parseInt(entrs[3].trim()));
        } else {
          person.setHhIncome(-1);
        }
        person.setHhSize(Integer.parseInt(entrs[4].trim()));
        person.setNbrPersonShoppingTripsMonth(Integer.parseInt(entrs[5].trim()));
        person.setNbrShoppingTripsMonth(entrs[6].trim());

        Location hlocation = new Location(Id.create(-1, Location.class));
        person.setHomeLocation(hlocation);
        hlocation.setCity(entrs[10].trim());

        CoordImpl hcoords =
            new CoordImpl(
                Double.parseDouble(entrs[12].trim()), Double.parseDouble(entrs[11].trim()));

        hlocation.setCoord(this.trafo.transform(hcoords)); // TODO: prüfen bei NULL

        person.setModesForShopping(
            SurveyControler.modes.indexOf("car"),
            SurveyControler.frequency.indexOf(entrs[13].trim().replaceAll("car", "")));
        person.setModesForShopping(
            SurveyControler.modes.indexOf("pt"),
            SurveyControler.frequency.indexOf(entrs[14].trim().replaceAll("pt", "")));
        person.setModesForShopping(
            SurveyControler.modes.indexOf("bike"),
            SurveyControler.frequency.indexOf(entrs[15].trim().substring(1)));
        person.setModesForShopping(
            SurveyControler.modes.indexOf("walk"),
            SurveyControler.frequency.indexOf(entrs[16].trim().substring(1)));

        boolean hasJob = entrs[17].trim().equals("yes");

        if (hasJob) {
          Location wlocation = new Location(Id.create(-2, Location.class));
          person.setEmployed(hasJob);
          person.setWorkLocation(wlocation);
          wlocation.setCity(entrs[21].trim());
          wlocation.setCoord(
              this.trafo.transform(
                  new CoordImpl(
                      Double.parseDouble(entrs[22].trim()), Double.parseDouble(entrs[23].trim()))));

          if (entrs[25].trim().contains("car"))
            person.setModeForWorking(SurveyControler.modes.indexOf("car"), true);
          if (entrs[25].trim().contains("pt"))
            person.setModeForWorking(SurveyControler.modes.indexOf("pt"), true);
          if (entrs[25].trim().contains("bike"))
            person.setModeForWorking(SurveyControler.modes.indexOf("bike"), true);
          if (entrs[25].trim().contains("walk"))
            person.setModeForWorking(SurveyControler.modes.indexOf("walk"), true);

          person.setAreaToShop(
              0, SurveyControler.frequency.indexOf(entrs[26].trim().replaceAll("home", "")));
          person.setAreaToShop(
              1, SurveyControler.frequency.indexOf(entrs[27].trim().replaceAll("work", "")));
          person.setAreaToShop(
              2, SurveyControler.frequency.indexOf(entrs[28].trim().replaceAll("inter", "")));
          person.setAreaToShop(
              3, SurveyControler.frequency.indexOf(entrs[29].trim().replaceAll("other", "")));
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  public void readDumpedPersonShops(String file) {
    try {
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
      String curr_line;
      Id<Person> prevId = Id.create(-99, Person.class);
      int countAware = 0;
      int countVisited = 0;
      while ((curr_line = br.readLine()) != null) {
        String[] entrs = curr_line.split(";", -1);
        Id<Location> shopId = Id.create(entrs[1].trim(), Location.class);
        Id<Person> userId = Id.create(entrs[2].trim().substring(4, 8), Person.class);

        EstimationPerson person = this.population.get(userId);
        ShopLocation store = new ShopLocation(shopId);
        int aware = 0;
        int visited = 0;
        boolean nullStore = false;

        if (entrs[5].trim().equals("yes")) {
          aware = 1;
          countAware++;
        } else if (entrs[5].trim().equals("no")) {
          aware = -1;
          store.setVisitFrequency("never");
        } else if (entrs[5].trim().equals("NULL")) {
          nullStore = true;
        }

        if (entrs[3].trim().equals("yes")) {
          visited = 1;
          store.setVisitFrequency(entrs[6].trim());
          countVisited++;
        } else if (entrs[3].trim().equals("no")) {
          visited = -1;
          store.setVisitFrequency(entrs[6].trim());
        } else if (entrs[3].trim().equals("NULL")) {
          nullStore = true;
        }
        if (person == null) {
          log.error("person null for user " + userId);
          System.exit(1);
        } else {
          if (nullStore) {
            person.addNullStore(store);
          } else {
            person.addStore(store, aware, visited);
          }
        }
        if (prevId.compareTo(userId) != 0 && prevId.compareTo(Id.create(-99, Person.class)) != 0) {
          log.info(
              "parsed user: "******" "
                  + countAware
                  + " aware stores "
                  + countVisited
                  + " visited stores");
          countAware = 0;
          countVisited = 0;
        }
        prevId = Id.create(entrs[2].trim().substring(4, 8), Person.class);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }