Ejemplo n.º 1
0
void Flight::Reduce(const BrokenDateTime start, const BrokenDateTime end,
                    const unsigned num_levels, const unsigned zoom_factor,
                    const double threshold, const bool force_endpoints,
                    const unsigned max_delta_time, const unsigned max_points) {
  // we need the whole flight, so read it now...
  if (!keep_flight) {
    ReadFlight();
    keep_flight = true;
  }

  DouglasPeuckerMod dp(num_levels, zoom_factor, threshold,
    force_endpoints, max_delta_time, max_points);

  unsigned start_index = 0,
           end_index = 0;

  int64_t start_time = start.ToUnixTimeUTC(),
          end_time = end.ToUnixTimeUTC();

  for (auto fix : *fixes) {
    if (BrokenDateTime(fix.date, fix.time).ToUnixTimeUTC() < start_time)
      start_index++;

    if (BrokenDateTime(fix.date, fix.time).ToUnixTimeUTC() < end_time)
      end_index++;
    else
      break;
  }

  end_index = std::min(end_index, unsigned(fixes->size()));
  start_index = std::min(start_index, end_index);

  dp.Encode(*fixes, start_index, end_index);
}
Ejemplo n.º 2
0
int FlightInfo::Duration() const {
  if (!date.IsPlausible() ||
      !start_time.IsPlausible() || !end_time.IsPlausible())
    return -1;

  int secs = BrokenDateTime(date, end_time) - BrokenDateTime(date, start_time);

  // adjust for possible date advance between start and end (add one day)
  if (secs < 0)
    secs += 24 * 60 * 60;

  // if still not a plausible duration return invalid duration
  if (secs < 0 || secs > 14 * 60 * 60)
    return -1;

  return secs;
}
BrokenDateTime Python::PyToBrokenDateTime(PyObject *py_datetime) {
  return BrokenDateTime(
    PyDateTime_GET_YEAR(py_datetime),
    PyDateTime_GET_MONTH(py_datetime),
    PyDateTime_GET_DAY(py_datetime),
    PyDateTime_DATE_GET_HOUR(py_datetime),
    PyDateTime_DATE_GET_MINUTE(py_datetime),
    PyDateTime_DATE_GET_SECOND(py_datetime));
};
Ejemplo n.º 4
0
BrokenDateTime
NMEAInfo::GetDateTimeAt(double other_time) const
{
  if (negative(other_time))
    return BrokenDateTime::Invalid();

  if (!time_available || !date_time_utc.IsDatePlausible())
    return BrokenDateTime(BrokenDate::Invalid(),
                          BrokenTime::FromSecondOfDayChecked(int(other_time)));

  return date_time_utc + int(other_time - time);
}
Ejemplo n.º 5
0
static void
TestDateTime()
{
  ok1(BrokenDateTime(2010, 1, 2).year == 2010);
  ok1(BrokenDateTime(2010, 1, 2).month == 1);
  ok1(BrokenDateTime(2010, 1, 2).day == 2);
  ok1(BrokenDateTime(2010, 1, 2).hour == 0);
  ok1(BrokenDateTime(2010, 1, 2).minute == 0);
  ok1(BrokenDateTime(2010, 1, 2).second == 0);

  ok1(BrokenDateTime(2010, 1, 2, 12, 15).year == 2010);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15).month == 1);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15).day == 2);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15).hour == 12);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15).minute == 15);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15).second == 0);

  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).year == 2010);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).month == 1);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).day == 2);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).hour == 12);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).minute == 15);
  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).second == 30);

  ok1(BrokenDateTime(2010, 2, 28, 23, 0, 0) == BrokenDateTime(2010, 2, 28, 23, 0, 0));
  ok1(BrokenDateTime(2010, 2, 28, 23, 0, 0) + 3600 == BrokenDateTime(2010, 3, 1));
  ok1(BrokenDateTime(2010, 2, 28, 23, 59, 59) + 1 == BrokenDateTime(2010, 3, 1));
  ok1(BrokenDateTime(2010, 2, 28, 23, 59, 59) + 2 == BrokenDateTime(2010, 3, 1, 0, 0, 1));
  ok1(BrokenDateTime(2010, 12, 31, 23, 59, 59) + 1 == BrokenDateTime(2011, 1, 1));

  ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).ToUnixTimeUTC() == 1262434530);

  ok1(BrokenDateTime(2010, 1, 1, 0, 0 ,1) -
      BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 1);
  ok1(BrokenDateTime(2010, 1, 1, 0, 1 ,0) -
      BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 60);
  ok1(BrokenDateTime(2010, 1, 1, 1, 0 ,0) -
      BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 60 * 60);
  ok1(BrokenDateTime(2010, 1, 2, 0, 0 ,0) -
      BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 60 * 60 * 24);
}
Ejemplo n.º 6
0
/**
 * Is called by the CalculationThread and processes the received GPS data in Basic()
 */
bool
GlideComputer::ProcessGPS(bool force)
{
  const MoreData &basic = Basic();
  DerivedInfo &calculated = SetCalculated();
  const ComputerSettings &settings = GetComputerSettings();

  const bool last_flying = calculated.flight.flying;

  if (basic.time_available) {
    /* use UTC offset to calculate local time */
    const int utc_offset_s = settings.utc_offset.AsSeconds();

    calculated.date_time_local = basic.date_time_utc.IsDatePlausible()
      /* known date: apply UTC offset to BrokenDateTime, which may
         increment/decrement date */
      ? basic.date_time_utc + utc_offset_s
      /* unknown date: apply UTC offset only to BrokenTime, leave the
         BrokenDate part invalid as it was */
      : BrokenDateTime(BrokenDate::Invalid(),
                       ((const BrokenTime &)basic.date_time_utc) + utc_offset_s);
  } else
    calculated.date_time_local = BrokenDateTime::Invalid();

  calculated.Expire(basic.clock);

  // Process basic information
  air_data_computer.ProcessBasic(Basic(), SetCalculated(),
                                 GetComputerSettings());

  // Process basic task information
  const bool last_finished = calculated.ordered_task_stats.task_finished;

  task_computer.ProcessBasicTask(basic,
                                 calculated,
                                 GetComputerSettings(),
                                 force);
  task_computer.ProcessMoreTask(basic, calculated, GetComputerSettings());

  if (!last_finished && calculated.ordered_task_stats.task_finished)
    OnFinishTask();

  // Check if everything is okay with the gps time and process it
  air_data_computer.FlightTimes(Basic(), SetCalculated(),
                                GetComputerSettings());

  TakeoffLanding(last_flying);

  task_computer.ProcessAutoTask(basic, calculated);

  // Process extended information
  air_data_computer.ProcessVertical(Basic(),
                                    SetCalculated(),
                                    GetComputerSettings());

  stats_computer.ProcessClimbEvents(calculated);

  // Calculate the team code
  CalculateOwnTeamCode();

  // Calculate the bearing and range of the teammate
  CalculateTeammateBearingRange();

  vegavoice.Update(basic, Calculated(), GetComputerSettings().voice);

  // update basic trace history
  if (basic.time_available) {
    const auto dt = trace_history_time.Update(basic.time, 0.5, 30);
    if (dt > 0)
      calculated.trace_history.append(basic);
    else if (dt < 0)
      /* time warp */
      calculated.trace_history.clear();
  }

  // Update the ConditionMonitors
  ConditionMonitorsUpdate(Basic(), Calculated(), settings);

  return idle_clock.CheckUpdate(500);
}
PyObject* Python::IGCFixEnhancedToPyTuple(const IGCFixEnhanced &fix) {
  PyObject *py_enl,
           *py_trt,
           *py_gsp,
           *py_tas,
           *py_ias,
           *py_siu,
           *py_elevation;

  if (fix.enl > -1) {
    py_enl = PyInt_FromLong(fix.enl);
  } else {
    py_enl = Py_None;
    Py_INCREF(Py_None);
  }

  if (fix.trt > -1) {
    py_trt = PyInt_FromLong(fix.trt);
  } else {
    py_trt = Py_None;
    Py_INCREF(Py_None);
  }

  if (fix.gsp > -1) {
    py_gsp = PyInt_FromLong(fix.gsp);
  } else {
    py_gsp = Py_None;
    Py_INCREF(Py_None);
  }

  if (fix.tas > -1) {
    py_tas = PyInt_FromLong(fix.tas);
  } else {
    py_tas = Py_None;
    Py_INCREF(Py_None);
  }

  if (fix.ias > -1) {
    py_ias = PyInt_FromLong(fix.ias);
  } else {
    py_ias = Py_None;
    Py_INCREF(Py_None);
  }

  if (fix.siu > -1) {
    py_siu = PyInt_FromLong(fix.siu);
  } else {
    py_siu = Py_None;
    Py_INCREF(Py_None);
  }

  if (fix.elevation > -999) {
    py_elevation = PyInt_FromLong(fix.elevation);
  } else {
    py_elevation = Py_None;
    Py_INCREF(Py_None);
  }

  return Py_BuildValue("(NiNiiNNNNNNNi)",
    BrokenDateTimeToPy(BrokenDateTime(fix.date, fix.time)),
    fix.clock,
    WriteLonLat(fix.location),
    fix.gps_altitude,
    fix.pressure_altitude,
    py_enl,
    py_trt,
    py_gsp,
    py_tas,
    py_ias,
    py_siu,
    py_elevation,
    fix.level);
}