def execute(self, goal):
        temp_start_time = rospy.Time.now()
        curr_date = datetime.datetime.fromtimestamp(rospy.Time.now().secs)
        # curr_date = datetime.datetime(2016, 3, 10, 0, 50)
        if curr_date.hour >= 0 and curr_date.hour < 8:
            curr_date = curr_date - datetime.timedelta(hours=24)
        curr_date = datetime.datetime(curr_date.year, curr_date.month, curr_date.day, 0, 0)
        prev_date = curr_date - datetime.timedelta(hours=24)
        self.rotm.calculate_region_observation_duration([prev_date, curr_date], self.minute_interval)
        self.rotm.store_to_mongo()
        if self._as.is_preempt_requested():
            self._as.set_preempted()
            return

        curr_traj_est = self.tre.estimate_trajectories_daily([curr_date.day], curr_date.month, curr_date.year)
        curr_traj_est = trajectory_estimate_for_date(curr_traj_est, curr_date)
        prev_traj_est = self.tre.estimate_trajectories_daily([prev_date.day], prev_date.month, prev_date.year)
        prev_traj_est = trajectory_estimate_for_date(prev_traj_est, prev_date)
        if self._as.is_preempt_requested():
            self._as.set_preempted()
            return

        self.tof.update_tof_daily(curr_traj_est, prev_traj_est, curr_date)
        self.tof.store_tof()
        self.rotm.reinit()
        self.tof.reinit()
        temp_end_time = rospy.Time.now()
        rospy.loginfo("Time needed to complete this is %d" % (temp_end_time - temp_start_time).secs)
        self._as.set_succeeded(OccurrenceRateLearningResult())
    def execute(self, goal):
        temp_start_time = rospy.Time.now()
        curr_date = datetime.datetime.fromtimestamp(rospy.Time.now().secs)
        # curr_date = datetime.datetime(2016, 3, 10, 0, 50)
        if curr_date.hour >= 0 and curr_date.hour < 8:
            curr_date = curr_date - datetime.timedelta(hours=24)
        curr_date = datetime.datetime(curr_date.year, curr_date.month,
                                      curr_date.day, 0, 0)
        prev_date = curr_date - datetime.timedelta(hours=24)
        self.rotm.calculate_region_observation_duration([prev_date, curr_date],
                                                        self.minute_interval)
        self.rotm.store_to_mongo()
        if self._as.is_preempt_requested():
            self._as.set_preempted()
            return

        curr_traj_est = self.tre.estimate_trajectories_daily([curr_date.day],
                                                             curr_date.month,
                                                             curr_date.year)
        curr_traj_est = trajectory_estimate_for_date(curr_traj_est, curr_date)
        prev_traj_est = self.tre.estimate_trajectories_daily([prev_date.day],
                                                             prev_date.month,
                                                             prev_date.year)
        prev_traj_est = trajectory_estimate_for_date(prev_traj_est, prev_date)
        if self._as.is_preempt_requested():
            self._as.set_preempted()
            return

        self.tof.update_tof_daily(curr_traj_est, prev_traj_est, curr_date)
        self.tof.store_tof()
        self.rotm.reinit()
        self.tof.reinit()
        temp_end_time = rospy.Time.now()
        rospy.loginfo("Time needed to complete this is %d" %
                      (temp_end_time - temp_start_time).secs)
        self._as.set_succeeded(OccurrenceRateLearningResult())
    if len(sys.argv) < 4:
        rospy.logerr("usage: synthetic minute_interval window_interval store(0)/test(1)")
        sys.exit(2)

    interval = int(sys.argv[1])
    window = int(sys.argv[2])

    sw = SyntheticWave(interval)
    if not int(sys.argv[3]):
        waves = sw.get_one_month_synthetic_wave(True)
        tof = TOF("synthetic", "synthetic_config", interval, window)
        tof.load_tof()
        for i in range(4, 31+1):
            prev_traj_est = trajectory_estimate_for_date(
                waves, datetime.date(2015, 5, i-1)
            )
            curr_traj_est = trajectory_estimate_for_date(
                waves, datetime.date(2015, 5, i)
            )
            tof.update_tof_daily(
                curr_traj_est, prev_traj_est, datetime.date(2015, 5, i)
            )
        tof.store_tof()
    else:
        waves = sw.get_one_week_synthetic_wave(True)
        tp = TrajectoryPeriodicity("synthetic", "synthetic_config", interval, window)
        inp = raw_input("MSE(0) or Prediction MSE(1): ")
        if int(inp) == 0:
            rospy.loginfo("Start model selection...")
            tp.model_selection(waves, 5, 2015, True)
        rospy.logerr(
            "usage: synthetic minute_interval window_interval store(0)/test(1)"
        )
        sys.exit(2)

    interval = int(sys.argv[1])
    window = int(sys.argv[2])

    sw = SyntheticWave(interval)
    if not int(sys.argv[3]):
        waves = sw.get_one_month_synthetic_wave(True)
        # waves = sw.get_one_month_synthetic_wave(False)  # no noise
        tof = TOF("synthetic", "synthetic_config", interval, window)
        tof.load_tof()
        for i in range(4, 31 + 1):
            prev_traj_est = trajectory_estimate_for_date(
                waves, datetime.date(2015, 5, i - 1))
            curr_traj_est = trajectory_estimate_for_date(
                waves, datetime.date(2015, 5, i))
            tof.update_tof_daily(curr_traj_est, prev_traj_est,
                                 datetime.date(2015, 5, i))
        tof.store_tof()
    else:
        waves = sw.get_one_week_synthetic_wave(True)
        tp = TrajectoryPeriodicity("synthetic", "synthetic_config", interval,
                                   window)
        # comment from here if just want the plot
        inp = raw_input("MSE(0) or Prediction MSE(1): ")
        if int(inp) == 0:
            rospy.loginfo("Start model selection...")
            tp.model_selection(waves, 5, 2015, True)
            rospy.loginfo("End model selection...")
    tof = TrajectoryOccurrenceFrequencies(sys.argv[1],
                                          sys.argv[2],
                                          minute_interval=interval,
                                          window_interval=window)
    tof.load_tof()
    for i in range(start_date, end_date + 1):
        if i == 1:
            prev_month = month - 1
            prev_year = year
            if prev_month == 0:
                prev_month = 12
                prev_year -= 1
            prev_traj_est = tre.estimate_trajectories_daily(
                [calendar.monthrange(prev_year, prev_month)[1]], prev_month,
                prev_year)
            prev_traj_est = trajectory_estimate_for_date(
                prev_traj_est,
                datetime.date(prev_year, prev_month,
                              calendar.monthrange(prev_year, prev_month)[1]))
        else:
            prev_traj_est = trajectory_estimate_for_date(
                trajectory_estimate, datetime.date(year, month, i - 1))
        curr_traj_est = trajectory_estimate_for_date(
            trajectory_estimate, datetime.date(year, month, i))
        tof.update_tof_daily(curr_traj_est, prev_traj_est,
                             datetime.date(year, month, i))
    tof.store_tof()
    temp_end_time = rospy.Time.now()
    rospy.loginfo("Time needed to complete this %d" %
                  (temp_end_time - temp_start_time).secs)
 )
 tof.load_tof()
 for i in range(start_date, end_date+1):
     if i == 1:
         prev_month = month - 1
         prev_year = year
         if prev_month == 0:
             prev_month = 12
             prev_year -= 1
         prev_traj_est = tre.estimate_trajectories_daily(
             [calendar.monthrange(prev_year, prev_month)[1]],
             prev_month, prev_year
         )
         prev_traj_est = trajectory_estimate_for_date(
             prev_traj_est, datetime.date(
                 prev_year, prev_month,
                 calendar.monthrange(prev_year, prev_month)[1]
             )
         )
     else:
         prev_traj_est = trajectory_estimate_for_date(
             trajectory_estimate, datetime.date(year, month, i-1)
         )
     curr_traj_est = trajectory_estimate_for_date(
         trajectory_estimate, datetime.date(year, month, i)
     )
     tof.update_tof_daily(
         curr_traj_est, prev_traj_est, datetime.date(year, month, i)
     )
 tof.store_tof()
 temp_end_time = rospy.Time.now()
 rospy.loginfo("Time needed to complete this %d" % (temp_end_time - temp_start_time).secs)