Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Geo Tools
Commits
6cd9012d
Commit
6cd9012d
authored
May 31, 2016
by
Matija Obreza
Browse files
Use DECLONGITUDE, DECLATITUDE as input columns
parent
a9533459
Pipeline
#37
skipped
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys/geotools/cli/CountryCLI.java
View file @
6cd9012d
...
...
@@ -35,6 +35,7 @@ import java.util.regex.Matcher;
import
java.util.regex.Pattern
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.time.StopWatch
;
import
org.genesys.geotools.service.HeaderUtils
;
import
org.genesys.geotools.service.impl.CountryOfOriginServiceImpl
;
...
...
@@ -50,8 +51,10 @@ public class CountryCLI implements GeoTool {
// 2000 meters
private
static
final
int
ALLOWED_DISTANCE_MARGIN
=
2000
;
private
static
final
String
HEADER_LONGITUDE
=
"LONGITUDE"
;
private
static
final
String
HEADER_LATITUDE
=
"LATITUDE"
;
private
static
final
String
CHECK_PASSED
=
"OK"
;
private
static
final
String
HEADER_LONGITUDE
=
"DECLONGITUDE"
;
private
static
final
String
HEADER_LATITUDE
=
"DECLATITUDE"
;
private
static
final
String
HEADER_ORIGCTY
=
"ORIGCTY"
;
private
static
final
String
HEADER_ORIGCTY_CHECK
=
"ORIGCTY_check"
;
...
...
@@ -103,15 +106,22 @@ public class CountryCLI implements GeoTool {
HeaderUtils
.
throwIfHeaderNotFound
(
headers
,
new
String
[]
{
HEADER_LONGITUDE
,
HEADER_LATITUDE
});
List
<
String
>
outputHeaders
=
new
ArrayList
<>(
Arrays
.
asList
(
headers
));
List
<
Integer
>
outputMapping
=
HeaderUtils
.
mapHeaderPositions
(
headers
);
List
<
Integer
>
outputMapping
=
HeaderUtils
.
mapHeaderPositions
(
headers
);
LOG
.
debug
(
"Source mapping indexes: {}"
,
outputMapping
);
LOG
.
debug
(
"Initial output headers: {}"
,
outputHeaders
);
Map
<
String
,
Integer
>
sourceMapping
=
HeaderUtils
.
makeSourceMapping
(
headers
,
new
String
[]
{
HEADER_LONGITUDE
,
HEADER_LATITUDE
,
HEADER_ORIGCTY
});
outputHeaders
.
add
(
Math
.
max
(
outputHeaders
.
indexOf
(
HEADER_ORIGCTY
),
outputHeaders
.
indexOf
(
HEADER_LATITUDE
))
+
1
,
HEADER_ORIGCTY_CHECK
);
if
(
outputHeaders
.
indexOf
(
HEADER_ORIGCTY
)
>=
0
)
{
outputHeaders
.
add
(
outputHeaders
.
indexOf
(
HEADER_ORIGCTY
)
+
1
,
HEADER_ORIGCTY_CHECK
);
outputMapping
.
add
(
outputHeaders
.
indexOf
(
HEADER_ORIGCTY
)
+
1
,
null
);
}
else
{
int
pos
=
Math
.
max
(
outputHeaders
.
indexOf
(
HEADER_LONGITUDE
),
outputHeaders
.
indexOf
(
HEADER_LATITUDE
));
outputHeaders
.
add
(
pos
+
1
,
HEADER_ORIGCTY_CHECK
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
LOG
.
info
(
"Output headers: {}"
,
outputHeaders
);
LOG
.
info
(
"Source mapping indexes: {}"
,
outputMapping
);
...
...
@@ -179,26 +189,33 @@ public class CountryCLI implements GeoTool {
// if ("101346".equals(nextLine[0])) {
// LOG.info("!!! Got what we're looking for");
// }
try
{
String
origCty
=
nextLine
[
sourceMapping
.
get
(
HEADER_ORIGCTY
)].
trim
();
float
longitude
=
Float
.
parseFloat
(
nextLine
[
sourceMapping
.
get
(
HEADER_LONGITUDE
)].
trim
());
float
latitude
=
Float
.
parseFloat
(
nextLine
[
sourceMapping
.
get
(
HEADER_LATITUDE
)].
trim
());
String
declongitude
=
nextLine
[
sourceMapping
.
get
(
HEADER_LONGITUDE
)].
trim
();
String
declatitude
=
nextLine
[
sourceMapping
.
get
(
HEADER_LATITUDE
)].
trim
();
String
origCty
=
nextLine
[
sourceMapping
.
get
(
HEADER_ORIGCTY
)].
trim
();
if
(
StringUtils
.
isNotBlank
(
declatitude
)
&&
StringUtils
.
isNotBlank
(
declongitude
))
{
try
{
result
=
countryOfOriginService
.
getCountries
(
longitude
,
latitude
,
origCty
,
ALLOWED_DISTANCE_MARGIN
);
}
catch
(
Exception
e
)
{
result
=
e
.
getMessage
();
float
longitude
=
Float
.
parseFloat
(
declongitude
);
float
latitude
=
Float
.
parseFloat
(
declatitude
);
try
{
result
=
countryOfOriginService
.
getCountries
(
longitude
,
latitude
,
origCty
,
ALLOWED_DISTANCE_MARGIN
);
}
catch
(
Exception
e
)
{
result
=
e
.
getMessage
();
}
}
catch
(
NumberFormatException
e
)
{
result
=
"Unparseable lat/lon"
;
}
catch
(
Throwable
e
)
{
result
=
"ERROR: "
+
e
.
getMessage
();
}
}
catch
(
Throwable
e
)
{
result
=
"ERROR: "
+
e
.
getMessage
();
}
outputLine
[
outputHeaders
.
indexOf
(
HEADER_ORIGCTY_CHECK
)]
=
result
;
outputLine
[
outputHeaders
.
indexOf
(
HEADER_ORIGCTY_CHECK
)]
=
StringUtils
.
equals
(
origCty
,
result
)
?
CHECK_PASSED
:
result
;
writer
.
writeNext
(
outputLine
);
//
if ("101346".equals(nextLine[0])) {
//
LOG.info("Written what we're looking for");
//
}
//
if ("101346".equals(nextLine[0])) {
//
LOG.info("Written what we're looking for");
//
}
}
// LOG.info("Done " + cpuId);
...
...
src/main/java/org/genesys/geotools/cli/LandOrSeaCLI.java
View file @
6cd9012d
...
...
@@ -29,6 +29,8 @@ import java.util.Map;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.genesys.geotools.service.HeaderUtils
;
import
org.genesys.geotools.service.impl.LandOrSeaServiceImpl
;
import
org.slf4j.Logger
;
...
...
@@ -42,9 +44,9 @@ public class LandOrSeaCLI implements GeoTool {
// 2000 meters
private
static
final
int
ALLOWED_DISTANCE_MARGIN
=
2000
;
private
static
final
String
HEADER_LATITUDE
=
"LATITUDE"
;
private
static
final
String
HEADER_LONGITUDE
=
"LONGITUDE"
;
private
static
final
String
HEADER_LA
TLON
_CHECK
=
"LA
TLON
_check"
;
private
static
final
String
HEADER_LATITUDE
=
"
DEC
LATITUDE"
;
private
static
final
String
HEADER_LONGITUDE
=
"
DEC
LONGITUDE"
;
private
static
final
String
HEADER_LA
NDORSEA
_CHECK
=
"LA
NDorSEA
_check"
;
public
static
void
main
(
String
arg
[])
throws
Exception
{
...
...
@@ -90,7 +92,7 @@ public class LandOrSeaCLI implements GeoTool {
String
[]
headers
=
reader
.
readNext
();
LOG
.
debug
(
"Input CSV headers: {}"
,
Arrays
.
toString
(
headers
));
HeaderUtils
.
throwIfHeaderFound
(
headers
,
new
String
[]
{
HEADER_LA
TLON
_CHECK
});
HeaderUtils
.
throwIfHeaderFound
(
headers
,
new
String
[]
{
HEADER_LA
NDORSEA
_CHECK
});
HeaderUtils
.
throwIfHeaderNotFound
(
headers
,
new
String
[]
{
HEADER_LONGITUDE
,
HEADER_LATITUDE
});
List
<
String
>
outputHeaders
=
new
ArrayList
<>(
Arrays
.
asList
(
headers
));
...
...
@@ -102,10 +104,19 @@ public class LandOrSeaCLI implements GeoTool {
Map
<
String
,
Integer
>
sourceMapping
=
HeaderUtils
.
makeSourceMapping
(
headers
,
new
String
[]
{
HEADER_LONGITUDE
,
HEADER_LATITUDE
});
// Add extra header
outputHeaders
.
add
(
outputHeaders
.
indexOf
(
HEADER_LATITUDE
)
+
1
,
HEADER_LATLON_CHECK
);
{
int
pos
=
Math
.
max
(
outputHeaders
.
indexOf
(
HEADER_LONGITUDE
),
outputHeaders
.
indexOf
(
HEADER_LATITUDE
));
outputHeaders
.
add
(
pos
+
1
,
HEADER_LANDORSEA_CHECK
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
LOG
.
info
(
"Output headers: {}"
,
outputHeaders
);
LOG
.
info
(
"Source mapping indexes: {}"
,
outputMapping
);
try
(
CSVWriter
writer
=
new
CSVWriter
(
new
OutputStreamWriter
(
output
),
','
,
'"'
,
'\\'
,
"\n"
))
{
writer
.
writeNext
(
outputHeaders
.
toArray
(
ArrayUtils
.
EMPTY_STRING_ARRAY
));
LandOrSeaServiceImpl
landOrSeaService
=
new
LandOrSeaServiceImpl
();
landOrSeaService
.
afterPropertiesSet
();
...
...
@@ -120,19 +131,27 @@ public class LandOrSeaCLI implements GeoTool {
String
[]
outputLine
=
HeaderUtils
.
toOutputLine
(
nextLine
,
outputHeaders
,
outputMapping
);
try
{
float
longitude
=
Float
.
parseFloat
(
nextLine
[
sourceMapping
.
get
(
HEADER_LONGITUDE
)].
trim
());
float
latitude
=
Float
.
parseFloat
(
nextLine
[
sourceMapping
.
get
(
HEADER_LATITUDE
)].
trim
());
String
declongitude
=
nextLine
[
sourceMapping
.
get
(
HEADER_LONGITUDE
)].
trim
();
String
declatitude
=
nextLine
[
sourceMapping
.
get
(
HEADER_LATITUDE
)].
trim
();
String
result
=
null
;
if
(
StringUtils
.
isNotBlank
(
declatitude
)
&&
StringUtils
.
isNotBlank
(
declongitude
))
{
try
{
outputLine
[
outputHeaders
.
indexOf
(
HEADER_LATLON_CHECK
)]
=
landOrSeaService
.
classifyLocation
(
longitude
,
latitude
,
ALLOWED_DISTANCE_MARGIN
);
float
longitude
=
Float
.
parseFloat
(
declongitude
);
float
latitude
=
Float
.
parseFloat
(
declatitude
);
result
=
landOrSeaService
.
classifyLocation
(
longitude
,
latitude
,
ALLOWED_DISTANCE_MARGIN
);
}
catch
(
Exception
e
)
{
outputLine
[
outputHeaders
.
indexOf
(
HEADER_LATLON_CHECK
)]
=
e
.
getMessage
();
if
(
e
.
getCause
()
!=
null
)
result
=
"ERROR: "
+
e
.
getCause
().
getMessage
();
else
result
=
"ERROR: "
+
e
.
getMessage
();
}
}
catch
(
Throwable
e
)
{
outputLine
[
outputHeaders
.
indexOf
(
HEADER_LATLON_CHECK
)]
=
"ERROR: "
+
e
.
getMessage
();
}
outputLine
[
outputHeaders
.
indexOf
(
HEADER_LANDORSEA_CHECK
)]
=
result
;
writer
.
writeNext
(
outputLine
);
}
}
...
...
src/main/resources/log4j.properties
View file @
6cd9012d
...
...
@@ -25,5 +25,5 @@ log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %t %5p %c{1}:%L - %m
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger
=
error, stdout
log4j.category.org.genesys
.geotools
=
info
log4j.category.org.genesys.geotools.cli
=
warn
log4j.category.org.genesys
=
warn
log4j.category.org.genesys.geotools.cli
=
info
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment