/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1507 by torben, Wed Jun 8 16:11:27 2011 UTC revision 1569 by torben, Sat Jul 9 07:31:01 2011 UTC
# Line 124  public class StationDAO { Line 124  public class StationDAO {
124                    
125                    
126          public StationBean getByNameFuzzy(final String name) throws SQLException {          public StationBean getByNameFuzzy(final String name) throws SQLException {
127                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0, " +                  String SQL = "SELECT * FROM (" +
128                  "levenshtein(lower(name),lower(?) ) as leven " +                                           "    SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0, " +
129                  "FROM trainstations " +                                           "    levenshtein(lower(name),lower(?) ) as leven " +
130                  "WHERE (levenshtein(lower(name),lower(?) ) <= 3) AND enabled = true " +                                           "    FROM trainstations " +
131                  "AND  enabled = true " +                                           "    WHERE  enabled = true ) as lev2 " +
132                  "ORDER BY leven " +                                           "WHERE (leven <= 3) " +                
133                  "LIMIT 1";                                           "ORDER BY leven " +
134                                             "LIMIT 1";
135    
136                  class NameSetter implements StatementParamSetter {                  class NameSetter implements StatementParamSetter {
137                          @Override                          @Override
138                          public void setParams(PreparedStatement stmt) throws SQLException {                          public void setParams(PreparedStatement stmt) throws SQLException {
139                                  stmt.setString(1, name );                                  stmt.setString(1, name );
                                 stmt.setString(2, name );  
140                          }                                                }                      
141                  }                  }
142                                    
# Line 145  public class StationDAO { Line 145  public class StationDAO {
145                  return stations;                  return stations;
146          }          }
147                    
148          public StationBean getByName(final String name) throws SQLException {          private String removeSuffix(String str, String suffix) {
149                    if (str.endsWith(suffix)) {
150                            return str.substring(0, str.length() - suffix.length() );
151                    } else {
152                            return str;
153                    }
154            }
155            
156            public StationBean getByName(String name) throws SQLException {
157                    name = removeSuffix(name, " st.");
158                    name = removeSuffix(name, " st");
159                    name = removeSuffix(name, " station");
160                    
161                  StationBean stations = getByNameNormal(name);                  StationBean stations = getByNameNormal(name);
162                                    
163                  if (stations.entries.size() == 0) {                  if (stations.entries.size() == 0) {
                         logger.info("getByName failover: " + name);  
164                          stations = getByNameFuzzy(name);                          stations = getByNameFuzzy(name);
165    
166                            logger.info("getByName failover: " + name + "(" + (stations.entries.size() >0) + ")" );
167                  }                  }
168                  return stations;                  return stations;
169          }          }
# Line 160  public class StationDAO { Line 173  public class StationDAO {
173          //Latitude (horizonal), longitude(vertical) so          //Latitude (horizonal), longitude(vertical) so
174          // 1 degree latitude is ~ 111320 meters, since the distance between the horizonal lines is always the same          // 1 degree latitude is ~ 111320 meters, since the distance between the horizonal lines is always the same
175          // 1 degree longitude is ~111320 meters at equator but gets shorter as we get closer to the poles.          // 1 degree longitude is ~111320 meters at equator but gets shorter as we get closer to the poles.
176          // the "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains,          // so 1 degree longitude is 64.5 km at denmarks southern point (gedser=54.55,11.95)
177            // and is 59.4km at northern point (skagen = 57.75,10.65)
178            // The "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains,
179          // in denmark 0.4dg latitude ~ 44km, 0.75dg longitude ~ 47km          // in denmark 0.4dg latitude ~ 44km, 0.75dg longitude ~ 47km
180    
181          // the ultra fast method  (and only slightly inaccurate as long as we only cover a limited geographically area)          // the ultra fast method  (and only slightly inaccurate as long as we only cover a limited geographically area)
# Line 243  public class StationDAO { Line 258  public class StationDAO {
258          }          }
259                    
260          //used to create full dump in order to populate Google Appengine DB          //used to create full dump in order to populate Google Appengine DB
261          @Deprecated          //after 1.1.0 also used to populate client-side station list
262          public StationBean dumpAll() throws SQLException {          public StationBean dumpAll() throws SQLException {
263                                    
264                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0,aliases " +                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0,aliases " +

Legend:
Removed from v.1507  
changed lines
  Added in v.1569

  ViewVC Help
Powered by ViewVC 1.1.20