Repository: incubator-s2graph Updated Branches: refs/heads/master 75c30bb31 -> 320c36cf0
[S2GRAPH-34] Provide option to select which field in edge's properties to run timeDecay function. provide options on query to specify property for timeDecay calculations. JIRA: [S2GRAPH-34] https://issues.apache.org/jira/browse/S2GRAPH-34 Pull Request: Closes #17 Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/320c36cf Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/320c36cf Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/320c36cf Branch: refs/heads/master Commit: 320c36cf0046461dcbb02dbba67a13b7bc454d1b Parents: 75c30bb Author: DO YUNG YOON <steams...@apache.org> Authored: Tue Feb 23 16:17:29 2016 +0900 Committer: DO YUNG YOON <steams...@apache.org> Committed: Tue Feb 23 16:17:29 2016 +0900 ---------------------------------------------------------------------- CHANGES | 2 ++ .../scala/com/kakao/s2graph/core/Graph.scala | 23 +++++++++++++++++++- .../com/kakao/s2graph/core/QueryParam.scala | 5 ++++- .../kakao/s2graph/core/rest/RequestParser.scala | 4 +++- 4 files changed, 31 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/320c36cf/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 9d9b103..620ca62 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ Release 0.12.1 - unreleased NEW FEATURES + + S2GRAPH-34: Provide option to select which field in edge's properties to run timeDecay function (Committed by DOYUNG YOON). IMPROVEMENT http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/320c36cf/s2core/src/main/scala/com/kakao/s2graph/core/Graph.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/com/kakao/s2graph/core/Graph.scala b/s2core/src/main/scala/com/kakao/s2graph/core/Graph.scala index 111f3df..58953e2 100644 --- a/s2core/src/main/scala/com/kakao/s2graph/core/Graph.scala +++ b/s2core/src/main/scala/com/kakao/s2graph/core/Graph.scala @@ -85,7 +85,28 @@ object Graph { val tsVal = queryParam.timeDecay match { case None => 1.0 case Some(timeDecay) => - val timeDiff = queryParam.timestamp - edge.ts + val tsVal = try { + val labelMeta = edge.label.metaPropsMap(timeDecay.labelMetaSeq) + val innerValWithTsOpt = edge.propsWithTs.get(timeDecay.labelMetaSeq) + innerValWithTsOpt.map { innerValWithTs => + val innerVal = innerValWithTs.innerVal + labelMeta.dataType match { + case InnerVal.LONG => innerVal.value match { + case n: BigDecimal => n.bigDecimal.longValue() + case _ => innerVal.toString().toLong + } + case _ => innerVal.toString().toLong + } + } getOrElse(edge.ts) + // val innerVal = edge.propsWithTs(timeDecay.labelMetaSeq).innerVal + // + // edge.propsWithTs.get(timeDecay.labelMetaSeq).map(_.toString.toLong).getOrElse(edge.ts) + } catch { + case e: Exception => + logger.error(s"processTimeDecay error. ${edge.toLogString}", e) + edge.ts + } + val timeDiff = queryParam.timestamp - tsVal timeDecay.decay(timeDiff) } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/320c36cf/s2core/src/main/scala/com/kakao/s2graph/core/QueryParam.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/com/kakao/s2graph/core/QueryParam.scala b/s2core/src/main/scala/com/kakao/s2graph/core/QueryParam.scala index 449764b..7f52e1a 100644 --- a/s2core/src/main/scala/com/kakao/s2graph/core/QueryParam.scala +++ b/s2core/src/main/scala/com/kakao/s2graph/core/QueryParam.scala @@ -517,7 +517,10 @@ case class QueryParam(labelWithDir: LabelWithDirection, timestamp: Long = System // } } -case class TimeDecay(initial: Double = 1.0, lambda: Double = 0.1, timeUnit: Double = 60 * 60 * 24) { +case class TimeDecay(initial: Double = 1.0, + lambda: Double = 0.1, + timeUnit: Double = 60 * 60 * 24, + labelMetaSeq: Byte = LabelMeta.timeStampSeq) { def decay(diff: Double): Double = { //FIXME val ret = initial * Math.pow(1.0 - lambda, diff / timeUnit) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/320c36cf/s2core/src/main/scala/com/kakao/s2graph/core/rest/RequestParser.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/com/kakao/s2graph/core/rest/RequestParser.scala b/s2core/src/main/scala/com/kakao/s2graph/core/rest/RequestParser.scala index 260e213..beaa151 100644 --- a/s2core/src/main/scala/com/kakao/s2graph/core/rest/RequestParser.scala +++ b/s2core/src/main/scala/com/kakao/s2graph/core/rest/RequestParser.scala @@ -282,11 +282,13 @@ class RequestParser(config: Config) extends JSONParser { } val cacheTTL = (labelGroup \ "cacheTTL").asOpt[Long].getOrElse(-1L) val timeDecayFactor = (labelGroup \ "timeDecay").asOpt[JsObject].map { jsVal => + val propName = (jsVal \ "propName").asOpt[String].getOrElse(LabelMeta.timestamp.name) + val propNameSeq = label.metaPropsInvMap.get(propName).map(_.seq).getOrElse(LabelMeta.timeStampSeq) val initial = (jsVal \ "initial").asOpt[Double].getOrElse(1.0) val decayRate = (jsVal \ "decayRate").asOpt[Double].getOrElse(0.1) if (decayRate >= 1.0 || decayRate <= 0.0) throw new BadQueryException("decay rate should be 0.0 ~ 1.0") val timeUnit = (jsVal \ "timeUnit").asOpt[Double].getOrElse(60 * 60 * 24.0) - TimeDecay(initial, decayRate, timeUnit) + TimeDecay(initial, decayRate, timeUnit, propNameSeq) } val threshold = (labelGroup \ "threshold").asOpt[Double].getOrElse(QueryParam.DefaultThreshold) // TODO: refactor this. dirty