Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply DateToUnitCircleTransformer logic in raw feature transformations. #130

Merged
merged 18 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add time zone + move out dataframe from function
  • Loading branch information
marcovivero committed Sep 13, 2018
commit bc39bfe123323a0efe2e4d586695f97c3fc3bd21
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ object DateToUnitCircle {
}.getOrElse(Array(0.0, 0.0))

private def getPeriodWithSize(timestamp: Long, timePeriod: TimePeriod): (Double, Int) = {
val dt = new JDateTime(timestamp)
val dt = new JDateTime(timestamp).withZone(DateTimeZone.UTC)
timePeriod match {
case TimePeriod.DayOfMonth => (dt.dayOfMonth.get.toDouble - 1, 31)
case TimePeriod.DayOfWeek => (dt.dayOfWeek.get.toDouble - 1, 7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class PreparedFeaturesTest extends FlatSpec with PassengerSparkFixtureTest {
val allPredictorKeys1 = Array(predictorKey1, predictorKey2A, predictorKey2B)
val allPredictorKeys2 = Array(predictorKey1)

val dateMap =
FeatureBuilder.DateMap[Passenger].extract(p => Map("DTMap" -> p.getBoarded.toLong).toDateMap).asPredictor
val dateFeatures: Array[OPFeature] = Array(boarded, boardedTime, boardedTimeAsDateTime, dateMap)
lazy val dateDataFrame: DataFrame = dataReader.generateDataFrame(dateFeatures)

Spec[PreparedFeatures] should "produce correct summaries" in {
val (responseSummaries1, predictorSummaries1) = preparedFeatures1.summaries
val (responseSummaries2, predictorSummaries2) = preparedFeatures2.summaries
Expand Down Expand Up @@ -197,18 +202,13 @@ class PreparedFeaturesTest extends FlatSpec with PassengerSparkFixtureTest {
expected3: Double,
expected4: Double,
expected5: Double): Unit = {
val dateMap =
FeatureBuilder.DateMap[Passenger].extract(p => Map("DTMap" -> p.getBoarded.toLong).toDateMap).asPredictor
val dateFeatures: Array[OPFeature] = Array(boarded, boardedTime, boardedTimeAsDateTime, dateMap)
val df: DataFrame = dataReader.generateDataFrame(dateFeatures)

def createExpectedDateMap(d: Double, aggregates: Int): Map[FeatureKey, ProcessedSeq] = Map(
(boarded.name, None) -> Right((0 until aggregates).map(_ => d).toList),
(boardedTime.name, None) -> Right(List(d)),
(boardedTimeAsDateTime.name, None) -> Right(List(d)),
(dateMap.name, Option("DTMap")) -> Right(List(d)))

val ppRDD: RDD[Map[FeatureKey, ProcessedSeq]] = df.rdd
val ppRDD: RDD[Map[FeatureKey, ProcessedSeq]] = dateDataFrame.rdd
.map(PreparedFeatures(
_, Array.empty[TransientFeature], dateFeatures.map(TransientFeature(_)), Option(period)))
.map(_.predictors.mapValues(_.right.map(_.toList)))
Expand Down