solr.deleteByQuery("*:*");
solr.commit();
String prevIp = null;
String dbfile = ConfigurationManager.getProperty("usage-statistics", "dbfile");
LookupService cl = new LookupService(dbfile,
LookupService.GEOIP_STANDARD);
int countryErrors = 0;
for (int i = 0; i < nrLogs; i++) {
String ip = "";
Date time;
String continent;
String countryCode;
float longitude;
float latitude;
String city;
// 1. Generate an ip for our user
StringBuilder ipBuilder = new StringBuilder();
for (int j = 0; j < 4; j++) {
ipBuilder.append(getRandomNumberInRange(0, 254));
if (j != 3)
{
ipBuilder.append(".");
}
}
ip = ipBuilder.toString();
// 2 Depending on our ip get all the location info
Location location;
try {
location = cl.getLocation(ip);
} catch (Exception e) {
location = null;
}
if (location == null) {
// If we haven't got a prev ip this is pretty useless so move on
// to the next one
if (prevIp == null)
{
continue;
}
ip = prevIp;
location = cl.getLocation(ip);
}
city = location.city;
countryCode = location.countryCode;
longitude = location.longitude;