File indexing completed on 2024-04-21 03:43:39
0001 /* 0002 SPDX-FileCopyrightText: 2023 Wolfgang Reissenberger <sterne-jaeger@openfuture.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 0008 #pragma once 0009 0010 #include "schedulertypes.h" 0011 #include "ekos/auxiliary/modulelogger.h" 0012 #include "dms.h" 0013 #include "libindi/lilxml.h" 0014 0015 #include <QString> 0016 #include <QUrl> 0017 0018 class SkyPoint; 0019 0020 namespace Ekos { 0021 0022 class SchedulerJob; 0023 class SequenceJob; 0024 0025 class SchedulerUtils 0026 { 0027 public: 0028 SchedulerUtils(); 0029 0030 0031 /** 0032 * @brief createJob Create job from its XML representation 0033 */ 0034 static SchedulerJob *createJob(XMLEle *root); 0035 0036 /** 0037 * @brief setupJob Initialize a job with all fields accessible from the UI. 0038 */ 0039 static void setupJob(SchedulerJob &job, const QString &name, const QString &group, const dms &ra, const dms &dec, 0040 double djd, double rotation, const QUrl &sequenceUrl, const QUrl &fitsUrl, StartupCondition startup, 0041 const QDateTime &startupTime, CompletionCondition completion, const QDateTime &completionTime, int completionRepeats, 0042 double minimumAltitude, double minimumMoonSeparation, bool enforceWeather, bool enforceTwilight, 0043 bool enforceArtificialHorizon, bool track, bool focus, bool align, bool guide); 0044 0045 0046 /** 0047 * @brief Fill the map signature -> frame count so that a single iteration of the scheduled job creates as many frames as possible 0048 * in addition to the already captured ones, but does not the expected amount. 0049 * @param expected map signature -> expected frames count 0050 * @param capturedFramesCount map signature -> already captured frames count 0051 * @param schedJob scheduler job for which these calculations are done 0052 * @param capture_map map signature -> frame count that will be handed over to the capture module to control that a single iteration 0053 * of the scheduler job creates as many frames as possible, but does not exceed the expected ones. 0054 * @param completedIterations How many times has the job completed its capture sequence (for repeated jobs). 0055 * @return total number of captured frames, truncated to the maximal number of frames the scheduler job could produce 0056 */ 0057 static uint16_t fillCapturedFramesMap(const QMap<QString, uint16_t> &expected, const CapturedFramesMap &capturedFramesCount, SchedulerJob &schedJob, 0058 CapturedFramesMap &capture_map, int &completedIterations); 0059 0060 0061 /** 0062 * @brief Update the flag for the given job whether light frames are required 0063 * @param oneJob scheduler job where the flag should be updated 0064 * @param seqjobs list of capture sequences of the job 0065 * @param framesCount map capture signature -> frame count 0066 * @return true iff the job need to capture light frames 0067 */ 0068 static void updateLightFramesRequired(SchedulerJob *oneJob, const QList<SequenceJob *> &seqjobs, const CapturedFramesMap &framesCount); 0069 0070 /** 0071 * @brief processJobInfo a utility used by loadSequenceQueue() to help it read a capture sequence file 0072 * @param root the filename 0073 * @param schedJob the SchedulerJob is modified accoring to the contents of the sequence queue 0074 * @return a capture sequence 0075 */ 0076 static SequenceJob *processSequenceJobInfo(XMLEle *root, SchedulerJob *schedJob); 0077 0078 /** 0079 * @brief loadSequenceQueue Loads what's necessary to estimate job completion time from a capture sequence queue file 0080 * @param fileURL the filename 0081 * @param schedJob the SchedulerJob is modified according to the contents of the sequence queue 0082 * @param jobs the returned values read from the file 0083 * @param hasAutoFocus a return value indicating whether autofocus can be triggered by the sequence. 0084 * @param logger module logging utility 0085 */ 0086 0087 static bool loadSequenceQueue(const QString &fileURL, SchedulerJob *schedJob, QList<SequenceJob *> &jobs, bool &hasAutoFocus, ModuleLogger *logger); 0088 0089 /** 0090 * @brief estimateJobTime Estimates the time the job takes to complete based on the sequence file and what modules to utilize during the observation run. 0091 * @param job target job 0092 * @param capturedFramesCount a map of what's been captured already 0093 * @param logger module logging utility 0094 * @return true if the time could be estimated, false if the corresponding sequence file is invalid 0095 */ 0096 static bool estimateJobTime(SchedulerJob *schedJob, const QMap<QString, uint16_t> &capturedFramesCount, ModuleLogger *logger); 0097 0098 /** 0099 * @brief timeHeuristics Estimates the number of seconds of overhead above and beyond imaging time, used by estimateJobTime. 0100 * @param schedJob the scheduler job. 0101 * @return seconds of overhead. 0102 */ 0103 static int timeHeuristics(const SchedulerJob *schedJob); 0104 0105 /** 0106 * @brief Calculate the map signature -> expected number of captures from the given list of capture sequence jobs, 0107 * i.e. the expected number of captures from a single scheduler job run. 0108 * @param seqJobs list of capture sequence jobs 0109 * @param expected map to be filled 0110 * @return total expected number of captured frames of a single run of all jobs 0111 */ 0112 static uint16_t calculateExpectedCapturesMap(const QList<SequenceJob *> &seqJobs, QMap<QString, uint16_t> &expected); 0113 0114 /** 0115 * @brief findAltitude Find altitude given a specific time 0116 * @param target Target 0117 * @param when date time to find altitude 0118 * @param is_setting whether target is setting at the argument time (optional). 0119 * @param debug outputs calculation to log file (optional). 0120 * @return Altitude of the target at the specific date and time given. 0121 * @warning This function uses the current KStars geolocation. 0122 */ 0123 static double findAltitude(const SkyPoint &target, const QDateTime &when, bool *is_setting = nullptr, bool debug = false); 0124 }; 0125 0126 0127 } // namespace