Esempio n. 1
0
 private static List<CollegeScore> readCollegScores(String f)
     throws FileNotFoundException, IOException {
   List<CollegeScore> scores = new Vector<CollegeScore>();
   BufferedReader br = new BufferedReader(new FileReader(f));
   String line = null;
   while ((line = br.readLine()) != null) {
     String[] splits = line.split(",");
     CollegeScore cs = new CollegeScore();
     cs.setSchool(splits[0].trim());
     cs.setName(splits[1].trim());
     cs.setStu2011(Integer.parseInt(splits[2].trim()));
     cs.setStu2012(Integer.parseInt(splits[3].trim()));
     cs.setStu2013(Integer.parseInt(splits[4].trim()));
     cs.setScore2011(Integer.parseInt(splits[5].trim()));
     cs.setScore2012(Integer.parseInt(splits[6].trim()));
     cs.setScore2013(Integer.parseInt(splits[7].trim()));
     scores.add(cs);
   }
   br.close();
   return scores;
 }
Esempio n. 2
0
  public static void main(String[] args) throws Exception {
    Map<Integer, Map<String, School>> snameMap = SchoolReader.readSchool();
    Map<Integer, Map<Long, Departments>> dMap = SchoolReader.readDepartment();

    Map<String, Integer> schoolLevel = new HashMap<String, Integer>();
    schoolLevel.put("scores/art1-fix.csv", 1);
    schoolLevel.put("scores/art2-fix.csv", 2);
    schoolLevel.put("scores/sci1-fix.csv", 1);
    schoolLevel.put("scores/sci2-fix.csv", 2);
    Map<String, Integer> departLevel = new HashMap<String, Integer>();
    departLevel.put("scores/art1-fix.csv", 1);
    departLevel.put("scores/sci1-fix.csv", 2);
    departLevel.put("scores/art2-fix.csv", 3);
    departLevel.put("scores/sci2-fix.csv", 4);

    //		String file = "scores/art1-fix.csv";
    int count = 0;
    Set<String> noSchools = new HashSet<String>();
    Set<String> noData = new HashSet<String>();
    List<SchoolScore> listss = new Vector<SchoolScore>();
    List<SchoolDepartment> listsd = new Vector<SchoolDepartment>();
    List<DepartmentScore> matched = new Vector<DepartmentScore>();
    List<SchoolDepartment> noMatched = new Vector<SchoolDepartment>();
    for (String file : schoolLevel.keySet()) {
      List<CollegeScore> scores = readCollegScores(file);
      Map<String, School> sm = snameMap.get(schoolLevel.get(file));
      Map<Long, Departments> dm = dMap.get(departLevel.get(file));
      for (CollegeScore cs : scores) {
        if (sm.get(cs.getSchool()) == null) {
          noSchools.add(cs.getSchool());
          System.out.println("school not exists ? " + cs.getSchool() + " " + file);
        } else {
          if (!cs.getsData().hasData()) {
            noData.add(cs.getName());
            continue;
          }

          School s = sm.get(cs.getSchool());
          if (cs.getName().equals(cs.getSchool())) {
            SchoolScore ss = new SchoolScore();
            listss.add(ss);
            ss.setId(s.getId());
            ss.setName(cs.getName());
            ss.setsData(cs.getsData());
            ss.setType(departLevel.get(file));
          } else {
            Departments departments = dm.get(s.getId());
            if (departments == null) {
              SchoolDepartment sd = new SchoolDepartment();
              listsd.add(sd);
              sd.setId(s.getId());
              sd.setName(s.getName());
              sd.setType(departLevel.get(file));
              sd.setDepartment(cs.getName());
              sd.setsData(cs.getsData());
            } else {
              Map<String, Department> m = departments.getMap();
              if (m.get(cs.getName()) != null) {
                DepartmentScore ds = new DepartmentScore();
                ds.setId(m.get(cs.getName()).getId());
                ds.setSchoolId(s.getId());
                ds.setsData(cs.getsData());
                matched.add(ds);
              } else {
                SchoolDepartment sd = new SchoolDepartment();
                noMatched.add(sd);
                sd.setId(s.getId());
                sd.setName(s.getName());
                sd.setDepartment(cs.getName());
                sd.setType(departLevel.get(file));
                sd.setsData(cs.getsData());
                sd.setComparedData(departments.toDepartment());
              }
            }
          }
        }
      }
    }
    writeToFile("scores/school.csv", listss);
    writeToFile("scores/added.csv", listsd);
    writeToFile("scores/department.csv", matched);
    writeToFile("scores/compared.csv", noMatched);

    writeToSql("scores/altschool.sql", listss);
    writeToSql("scores/altdepartment.sql", matched);

    System.out.println("total no data : " + noData.size());
    //		for(String s : noData)
    //		{
    //			System.out.println("no data ? " + s);
    //		}
    System.out.println("total no department : " + count);
    for (String s : noSchools) {
      System.out.println("noSchool ? " + s);
    }
    System.out.println("total no school : " + noSchools.size());
  }