Kstars

schedulerutils.h
1/*
2 SPDX-FileCopyrightText: 2023 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7
8#pragma once
9
10#include "schedulertypes.h"
11#include "ekos/capture/capturetypes.h"
12#include "ekos/auxiliary/modulelogger.h"
13#include "dms.h"
14#include <lilxml.h>
15
16#include <QString>
17#include <QUrl>
18#include <QDateTime>
19
20class SkyPoint;
21class GeoLocation;
22
23namespace Ekos
24{
25
26class SchedulerJob;
27class SequenceJob;
28
29class SchedulerUtils
30{
31 public:
32 SchedulerUtils();
33
34
35 /**
36 * @brief createJob Create job from its XML representation
37 * @param root XML description of the job to be created
38 * @param leadJob candidate for lead (only necessary if the new job's type is follower)
39 */
40 static SchedulerJob *createJob(XMLEle *root, SchedulerJob *leadJob);
41
42 /**
43 * @brief setupJob Initialize a job with all fields accessible from the UI.
44 */
45 static void setupJob(SchedulerJob &job, const QString &name, bool isLead, const QString &group, const QString &train,
46 const dms &ra, const dms &dec,
47 double djd, double rotation, const QUrl &sequenceUrl, const QUrl &fitsUrl, StartupCondition startup,
48 const QDateTime &startupTime, CompletionCondition completion, const QDateTime &completionTime, int completionRepeats,
49 double minimumAltitude, double minimumMoonSeparation, double maxMoonAltitude, bool enforceTwilight,
50 bool enforceArtificialHorizon, bool track, bool focus, bool align, bool guide);
51
52
53 /**
54 * @brief Fill the map signature -> frame count so that a single iteration of the scheduled job creates as many frames as possible
55 * in addition to the already captured ones, but does not the expected amount.
56 * @param expected map signature -> expected frames count
57 * @param capturedFramesCount map signature -> already captured frames count
58 * @param schedJob scheduler job for which these calculations are done
59 * @param capture_map map signature -> frame count that will be handed over to the capture module to control that a single iteration
60 * of the scheduler job creates as many frames as possible, but does not exceed the expected ones.
61 * @param completedIterations How many times has the job completed its capture sequence (for repeated jobs).
62 * @return total number of captured frames, truncated to the maximal number of frames the scheduler job could produce
63 */
64 static uint16_t fillCapturedFramesMap(const CapturedFramesMap &expected, const CapturedFramesMap &capturedFramesCount,
65 SchedulerJob &schedJob,
66 CapturedFramesMap &capture_map, int &completedIterations);
67
68
69 /**
70 * @brief Update the flag for the given job whether light frames are required
71 * @param oneJob scheduler job where the flag should be updated
72 * @param seqjobs list of capture sequences of the job
73 * @param framesCount map capture signature -> frame count
74 * @return true iff the job need to capture light frames
75 */
76 static void updateLightFramesRequired(SchedulerJob *oneJob, const QList<QSharedPointer<SequenceJob> > &seqjobs,
77 const CapturedFramesMap &framesCount);
78
79 /**
80 * @brief processJobInfo a utility used by loadSequenceQueue() to help it read a capture sequence file
81 * @param root the filename
82 * @param schedJob the SchedulerJob is modified accoring to the contents of the sequence queue
83 * @return a capture sequence
84 */
85 static QSharedPointer<SequenceJob> processSequenceJobInfo(XMLEle *root, SchedulerJob *schedJob);
86
87 /**
88 * @brief loadSequenceQueue Loads what's necessary to estimate job completion time from a capture sequence queue file
89 * @param fileURL the filename
90 * @param schedJob the SchedulerJob is modified according to the contents of the sequence queue
91 * @param jobs the returned values read from the file
92 * @param hasAutoFocus a return value indicating whether autofocus can be triggered by the sequence.
93 * @param logger module logging utility
94 */
95
96 static bool loadSequenceQueue(const QString &fileURL, SchedulerJob *schedJob, QList<QSharedPointer<SequenceJob> > &jobs,
97 bool &hasAutoFocus, ModuleLogger *logger);
98
99 /**
100 * @brief estimateJobTime Estimates the time the job takes to complete based on the sequence file and what modules to utilize during the observation run.
101 * @param job target job
102 * @param capturedFramesCount a map of what's been captured already
103 * @param logger module logging utility
104 * @return true if the time could be estimated, false if the corresponding sequence file is invalid
105 */
106 static bool estimateJobTime(SchedulerJob *schedJob, const CapturedFramesMap &capturedFramesCount, ModuleLogger *logger);
107
108 /**
109 * @brief timeHeuristics Estimates the number of seconds of overhead above and beyond imaging time, used by estimateJobTime.
110 * @param schedJob the scheduler job.
111 * @return seconds of overhead.
112 */
113 static int timeHeuristics(const SchedulerJob *schedJob);
114
115 /**
116 * @brief Calculate the map signature -> expected number of captures from the given list of capture sequence jobs,
117 * i.e. the expected number of captures from a single scheduler job run.
118 * @param seqJobs list of capture sequence jobs
119 * @param expected map to be filled
120 * @return total expected number of captured frames of a single run of all jobs
121 */
122 static uint16_t calculateExpectedCapturesMap(const QList<QSharedPointer<SequenceJob> > &seqJobs,
123 CapturedFramesMap &expected);
124
125 /**
126 * @brief findAltitude Find altitude given a specific time
127 * @param target Target
128 * @param when date time to find altitude
129 * @param is_setting whether target is setting at the argument time (optional).
130 * @param debug outputs calculation to log file (optional).
131 * @return Altitude of the target at the specific date and time given.
132 * @warning This function uses the current KStars geolocation.
133 */
134 static double findAltitude(const SkyPoint &target, const QDateTime &when, bool *is_setting = nullptr,
135 GeoLocation *geo = nullptr, bool debug = false);
136
137 /**
138 * @brief create a new list with only the master jobs from the input
139 */
140 static QList<SchedulerJob *> filterLeadJobs(const QList<SchedulerJob *> &jobs);
141};
142
143
144} // namespace
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
The sky coordinates of a point in the sky.
Definition skypoint.h:45
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
StartupCondition
Conditions under which a SchedulerJob may start.
QMap< QString, uint16_t > CapturedFramesMap
mapping signature --> frames count
CompletionCondition
Conditions under which a SchedulerJob may complete.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:57:24 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.