Skip to content

Commit ad88e69

Browse files
author
Donald Szeto
committed
Merge branch 'hotfix-0.6.2'
2 parents 7979fc3 + 54a4496 commit ad88e69

File tree

61 files changed

+1010
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1010
-149
lines changed

bin/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# This script should be sourced with $BASE set to the base of the repository
44

5-
VERSION=0.6.1
5+
VERSION=0.6.2
66

77
# Play framework related
88
PLAY_OPTS=

commons/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "PredictionIO Commons"
22

3-
version := "0.6.1"
3+
version := "0.6.2"
44

55
organization := "io.prediction"
66

commons/src/main/scala/io/prediction/commons/appdata/Items.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ trait Items {
4141
/** Find all items by App ID. */
4242
def getByAppid(appid: Int): Iterator[Item]
4343

44+
/** Find items by App ID sorted by geolocation distance. */
45+
def getByAppidAndLatlng(appid: Int, latlng: Tuple2[Double, Double], within: Option[Double], unit: Option[String]): Iterator[Item]
46+
4447
/** Get items by IDs. */
4548
def getByIds(appid: Int, ids: Seq[String]): Seq[Item]
4649

commons/src/main/scala/io/prediction/commons/appdata/mongodb/MongoItems.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class MongoItems(db: MongoDB) extends Items {
1414

1515
/** Indices and hints. */
1616
val starttimeIndex = MongoDBObject("starttime" -> -1)
17+
val lnglatIndex = MongoDBObject("lnglat" -> "2d")
1718
itemColl.ensureIndex(starttimeIndex)
19+
itemColl.ensureIndex(lnglatIndex)
1820

1921
RegisterJodaTimeConversionHelpers()
2022

@@ -41,6 +43,22 @@ class MongoItems(db: MongoDB) extends Items {
4143

4244
def getByAppid(appid: Int) = new MongoItemsIterator(itemColl.find(MongoDBObject("appid" -> appid)))
4345

46+
def getByAppidAndLatlng(appid: Int, latlng: Tuple2[Double, Double], within: Option[Double], unit: Option[String]) = {
47+
val earthRadiusInKm = 6371
48+
val earthRadiusInMiles = 3959
49+
50+
val nearSphereObj = MongoDBObject("$nearSphere" -> MongoDBList(latlng._2, latlng._1))
51+
val maxDistObj = within map { maxDist =>
52+
unit match {
53+
case Some("km") => MongoDBObject("$maxDistance" -> maxDist / earthRadiusInKm)
54+
case Some("mi") => MongoDBObject("$maxDistance" -> maxDist / earthRadiusInMiles)
55+
case _ => MongoDBObject("$maxDistance" -> maxDist / earthRadiusInKm)
56+
}
57+
} getOrElse emptyObj
58+
59+
new MongoItemsIterator(itemColl.find(MongoDBObject("appid" -> appid, "lnglat" -> (nearSphereObj ++ maxDistObj))))
60+
}
61+
4462
def getByIds(appid: Int, ids: Seq[String]) = {
4563
itemColl.find(MongoDBObject("_id" -> MongoDBObject("$in" -> ids.map(idWithAppid(appid, _))))).toList map { dbObjToItem(_) }
4664
}

commons/src/test/scala/io/prediction/commons/appdata/ItemsSpec.scala

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ItemsSpec extends Specification { def is =
1919

2020
def items(items: Items) = { t ^
2121
"inserting and getting an item" ! insert(items) ^
22+
"getting items by App ID and geo data" ! getByAppidAndLatlng(items) ^
2223
"getting items by IDs" ! getByIds(items) ^
2324
"getting items by IDs sorted by start time" ! getRecentByIds(items) ^
2425
"updating an item" ! update(items) ^
@@ -67,6 +68,65 @@ class ItemsSpec extends Specification { def is =
6768
(items.get(appid, id2) must beSome(item2))
6869
}
6970

71+
def getByAppidAndLatlng(items: Items) = {
72+
val id = "getByAppidAndLatlng"
73+
val appid = 5
74+
val dac = Item(
75+
id = id + "dac",
76+
appid = appid,
77+
ct = DateTime.now,
78+
itypes = List("fresh", "meat"),
79+
starttime = Some(DateTime.now.hour(14).minute(13)),
80+
endtime = None,
81+
price = Some(49.394),
82+
profit = None,
83+
latlng = Some((37.3197611, -122.0466141)),
84+
inactive = None,
85+
attributes = Some(Map("foo" -> "bar", "foo2" -> "bar2")))
86+
val hsh = Item(
87+
id = id + "hsh",
88+
appid = appid,
89+
ct = DateTime.now,
90+
itypes = List("fresh", "meat"),
91+
starttime = Some(DateTime.now.hour(23).minute(13)),
92+
endtime = None,
93+
price = Some(49.394),
94+
profit = None,
95+
latlng = Some((37.3370801, -122.0493201)),
96+
inactive = None,
97+
attributes = None)
98+
val mvh = Item(
99+
id = id + "mvh",
100+
appid = appid,
101+
ct = DateTime.now,
102+
itypes = List("fresh", "meat"),
103+
starttime = Some(DateTime.now.hour(17).minute(13)),
104+
endtime = None,
105+
price = Some(49.394),
106+
profit = None,
107+
latlng = Some((37.3154153, -122.0566829)),
108+
inactive = None,
109+
attributes = Some(Map("foo3" -> "bar3")))
110+
val lbh = Item(
111+
id = id + "lbh",
112+
appid = appid,
113+
ct = DateTime.now,
114+
itypes = List("fresh", "meat"),
115+
starttime = Some(DateTime.now.hour(3).minute(13)),
116+
endtime = None,
117+
price = Some(49.394),
118+
profit = None,
119+
latlng = Some((37.2997029, -122.0034684)),
120+
inactive = None,
121+
attributes = Some(Map("foo4" -> "bar4", "foo5" -> "bar5")))
122+
val allItems = Seq(dac, hsh, lbh, mvh)
123+
allItems foreach { items.insert(_) }
124+
(items.getByAppidAndLatlng(appid, (37.336402, -122.040467), None, None).toSeq must beEqualTo(Seq(hsh, dac, mvh, lbh))) and
125+
(items.getByAppidAndLatlng(appid, (37.3229978, -122.0321823), None, None).toSeq must beEqualTo(Seq(dac, hsh, mvh, lbh))) and
126+
(items.getByAppidAndLatlng(appid, (37.3229978, -122.0321823), Some(2.2), None).toSeq must beEqualTo(Seq(dac, hsh))) and
127+
(items.getByAppidAndLatlng(appid, (37.3229978, -122.0321823), Some(2.2), Some("mi")).toSeq must beEqualTo(Seq(dac, hsh, mvh)))
128+
}
129+
70130
def getByIds(items: Items) = {
71131
val id = "getByIds"
72132
val appid = 4

dist/bin/backup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ JARS="${JARS}:${PROG_HOME}/lib/minlog-1.2.jar"
145145
JARS="${JARS}:${PROG_HOME}/lib/mongo-java-driver-2.11.2.jar"
146146
JARS="${JARS}:${PROG_HOME}/lib/nscala-time_2.10-0.4.2.jar"
147147
JARS="${JARS}:${PROG_HOME}/lib/objenesis-1.2.jar"
148-
JARS="${JARS}:${PROG_HOME}/lib/predictionio-commons_2.10-0.6.1.jar"
149-
JARS="${JARS}:${PROG_HOME}/lib/predictionio-software-manager_2.10-0.6.1.jar"
148+
JARS="${JARS}:${PROG_HOME}/lib/predictionio-commons_2.10-0.6.2.jar"
149+
JARS="${JARS}:${PROG_HOME}/lib/predictionio-software-manager_2.10-0.6.2.jar"
150150
JARS="${JARS}:${PROG_HOME}/lib/reflectasm-1.07.jar"
151151
JARS="${JARS}:${PROG_HOME}/lib/scala-library-2.10.2.jar"
152152
JARS="${JARS}:${PROG_HOME}/lib/scopt_2.10-3.1.0.jar"

dist/bin/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# This script should be sourced with $BASE set to the base of the repository
44

5-
VERSION=0.6.1
5+
VERSION=0.6.2
66

77
# Play framework related
88
PLAY_OPTS=""

dist/bin/conncheck

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ JARS="${JARS}:${PROG_HOME}/lib/minlog-1.2.jar"
144144
JARS="${JARS}:${PROG_HOME}/lib/mongo-java-driver-2.11.2.jar"
145145
JARS="${JARS}:${PROG_HOME}/lib/nscala-time_2.10-0.4.2.jar"
146146
JARS="${JARS}:${PROG_HOME}/lib/objenesis-1.2.jar"
147-
JARS="${JARS}:${PROG_HOME}/lib/predictionio-commons_2.10-0.6.1.jar"
148-
JARS="${JARS}:${PROG_HOME}/lib/predictionio-connection-check-tool_2.10-0.6.1.jar"
147+
JARS="${JARS}:${PROG_HOME}/lib/predictionio-commons_2.10-0.6.2.jar"
148+
JARS="${JARS}:${PROG_HOME}/lib/predictionio-connection-check-tool_2.10-0.6.2.jar"
149149
JARS="${JARS}:${PROG_HOME}/lib/reflectasm-1.07.jar"
150150
JARS="${JARS}:${PROG_HOME}/lib/scala-library-2.10.2.jar"
151151
JARS="${JARS}:${PROG_HOME}/lib/slf4j-api-1.6.0.jar"

dist/bin/migration/appdata

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ JARS="${JARS}:${PROG_HOME}/../lib/minlog-1.2.jar"
144144
JARS="${JARS}:${PROG_HOME}/../lib/mongo-java-driver-2.11.2.jar"
145145
JARS="${JARS}:${PROG_HOME}/../lib/nscala-time_2.10-0.2.0.jar"
146146
JARS="${JARS}:${PROG_HOME}/../lib/objenesis-1.2.jar"
147-
JARS="${JARS}:${PROG_HOME}/../lib/predictionio-0.4-to-0.5-appdata-migration_2.10-0.6.1.jar"
148-
JARS="${JARS}:${PROG_HOME}/../lib/predictionio-commons_2.10-0.6.1.jar"
147+
JARS="${JARS}:${PROG_HOME}/../lib/predictionio-0.4-to-0.5-appdata-migration_2.10-0.6.2.jar"
148+
JARS="${JARS}:${PROG_HOME}/../lib/predictionio-commons_2.10-0.6.2.jar"
149149
JARS="${JARS}:${PROG_HOME}/../lib/reflectasm-1.07.jar"
150150
JARS="${JARS}:${PROG_HOME}/../lib/scala-library-2.10.2.jar"
151151
JARS="${JARS}:${PROG_HOME}/../lib/slf4j-api-1.6.0.jar"

dist/bin/restore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ JARS="${JARS}:${PROG_HOME}/lib/minlog-1.2.jar"
145145
JARS="${JARS}:${PROG_HOME}/lib/mongo-java-driver-2.11.2.jar"
146146
JARS="${JARS}:${PROG_HOME}/lib/nscala-time_2.10-0.4.2.jar"
147147
JARS="${JARS}:${PROG_HOME}/lib/objenesis-1.2.jar"
148-
JARS="${JARS}:${PROG_HOME}/lib/predictionio-commons_2.10-0.6.1.jar"
149-
JARS="${JARS}:${PROG_HOME}/lib/predictionio-software-manager_2.10-0.6.1.jar"
148+
JARS="${JARS}:${PROG_HOME}/lib/predictionio-commons_2.10-0.6.2.jar"
149+
JARS="${JARS}:${PROG_HOME}/lib/predictionio-software-manager_2.10-0.6.2.jar"
150150
JARS="${JARS}:${PROG_HOME}/lib/reflectasm-1.07.jar"
151151
JARS="${JARS}:${PROG_HOME}/lib/scala-library-2.10.2.jar"
152152
JARS="${JARS}:${PROG_HOME}/lib/scopt_2.10-3.1.0.jar"

0 commit comments

Comments
 (0)