[kstars] kstars: Junion Job: Investigate NEOs is fixed!

Jasem Mutlaq null at kde.org
Tue Mar 21 10:25:58 UTC 2017


Git commit a180b383e50e671c25c0b5cbd5dbe4447ac65e05 by Jasem Mutlaq, on behalf of Valentin Boettcher.
Committed on 21/03/2017 at 10:24.
Pushed by mutlaqja into branch 'master'.

Junion Job: Investigate NEOs is fixed!

I've constructed a request to JPL myself and got out a csv of several hundred megabytes, which is certainly not suitable for KStars.
Looking at the differences between my query and the one in KStars, I found some extra parameters, which had not been included in my one: c1_item=Ai and c1_op=%3C and c1_value=12.
That basicly means, that JPL filters the asteroids for the ones which have an parameter 'H' (absolute magnitude) smaller than 12, which means that they are 'visible'.

Added "Waiting for Server Response" to filedownloder class to improve usability.

CCMAIL:kstars-devel at kde.org

M  +14   -4    kstars/auxiliary/filedownloader.cpp
M  +24   -0    kstars/auxiliary/ksutils.cpp
M  +16   -0    kstars/auxiliary/ksutils.h
M  +5    -0    kstars/kstars.kcfg
M  +13   -0    kstars/options/opssolarsystem.cpp
M  +1    -1    kstars/options/opssolarsystem.h
M  +72   -23   kstars/options/opssolarsystem.ui
M  +3    -8    kstars/skycomponents/asteroidscomponent.cpp
M  +2    -0    kstars/skycomponents/asteroidscomponent.h
M  +2    -11   kstars/skycomponents/cometscomponent.cpp

https://commits.kde.org/kstars/a180b383e50e671c25c0b5cbd5dbe4447ac65e05

diff --git a/kstars/auxiliary/filedownloader.cpp b/kstars/auxiliary/filedownloader.cpp
index 815a827d5..f7a0a9855 100644
--- a/kstars/auxiliary/filedownloader.cpp
+++ b/kstars/auxiliary/filedownloader.cpp
@@ -41,6 +41,8 @@ void FileDownloader::get(const QUrl & fileUrl)
     connect(m_Reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));
     connect(m_Reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(setDownloadProgress(qint64,qint64)));
     connect(m_Reply, SIGNAL(readyRead()), this, SLOT(dataReady()));
+
+    setDownloadProgress(0,0);
 }
 
 void FileDownloader::post(const QUrl &fileUrl, QByteArray & data)
@@ -54,6 +56,8 @@ void FileDownloader::post(const QUrl &fileUrl, QByteArray & data)
     connect(m_Reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));
     connect(m_Reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(setDownloadProgress(qint64,qint64)));
     connect(m_Reply, SIGNAL(readyRead()), this, SLOT(dataReady()));    
+
+    setDownloadProgress(0,0);
 }
 
 void FileDownloader::post(const QUrl & fileUrl, QHttpMultiPart *parts)
@@ -67,6 +71,8 @@ void FileDownloader::post(const QUrl & fileUrl, QHttpMultiPart *parts)
     connect(m_Reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));
     connect(m_Reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(setDownloadProgress(qint64,qint64)));
     connect(m_Reply, SIGNAL(readyRead()), this, SLOT(dataReady()));
+
+    setDownloadProgress(0,0);
 }
 
 void FileDownloader::dataReady()
@@ -120,7 +126,7 @@ void FileDownloader::setProgressDialogEnabled(bool ShowProgressDialog, const QSt
         title = textTitle;
 
     if (textLabel.isEmpty())
-       label = i18n("Downloading Data...");
+        label = i18n("Downloading Data...");
     else
         label = textLabel;
 }
@@ -159,7 +165,7 @@ void FileDownloader::setDownloadProgress(qint64 bytesReceived, qint64 bytesTotal
             isCancelled = false;
             progressDialog = new QProgressDialog(KStars::Instance());
             progressDialog->setWindowTitle(title);
-            progressDialog->setLabelText(label);
+            progressDialog->setLabelText(i18n("Awaiting response from server..."));
             connect(progressDialog, SIGNAL(canceled()), this, SIGNAL(canceled()));
             connect(progressDialog, &QProgressDialog::canceled, this, [&]() { isCancelled = true; m_Reply->abort(); progressDialog->close(); });
             progressDialog->setMinimum(0);
@@ -168,12 +174,16 @@ void FileDownloader::setDownloadProgress(qint64 bytesReceived, qint64 bytesTotal
             progressDialog->raise();
         }
 
+        if (bytesReceived > 0)
+        {
+            progressDialog->setLabelText(label);
+        }
+
         if (bytesTotal > 0)
         {
             progressDialog->setMaximum(bytesTotal);
             progressDialog->setValue(bytesReceived);
-        }
-        else
+        } else
         {
             progressDialog->setMaximum(0);
         }
diff --git a/kstars/auxiliary/ksutils.cpp b/kstars/auxiliary/ksutils.cpp
index 3e4d7ce5c..06654df9c 100644
--- a/kstars/auxiliary/ksutils.cpp
+++ b/kstars/auxiliary/ksutils.cpp
@@ -818,4 +818,28 @@ bool copyRecursively(QString sourceFolder, QString destFolder)
 }
 #endif
 
+QByteArray getJPLQueryString(const QByteArray &kind, const QByteArray &dataFields, const QVector<JPLFilter> &filters) {
+    QByteArray query("obj_group=all&obj_kind=" + kind + "&obj_numbered=num&OBJ_field=0&ORB_field=0");
+
+    // Apply filters:
+    for(int i = 0; i < filters.length(); i++) {
+        QString f = QString::number(i+1);
+        query += "&c" + f + "_group=OBJ&c1_item=" + filters[i].item
+               + "&c" + f + "_op=" + filters[i].op
+               + "&c" + f + "_value=" + filters[i].value;
+    }
+
+    // Apply query data fields...
+    query += "&c_fields=" + dataFields;
+
+    query +=
+    "&table_format=CSV&max_rows=10&format_option=full&query=Generate%20Table&."
+    "cgifields=format_option&.cgifields=field_list&.cgifields=obj_kind&.cgifie"
+    "lds=obj_group&.cgifields=obj_numbered&.cgifields=combine_mode&.cgifields="
+    "ast_orbit_class&.cgifields=table_format&.cgifields=ORB_field_set&.cgifiel"
+    "ds=OBJ_field_set&.cgifields=preset_field_set&.cgifields=com_orbit_class";
+
+    return query;
+}
+
 }
diff --git a/kstars/auxiliary/ksutils.h b/kstars/auxiliary/ksutils.h
index 9b3c845e7..611493f0d 100644
--- a/kstars/auxiliary/ksutils.h
+++ b/kstars/auxiliary/ksutils.h
@@ -232,6 +232,22 @@ namespace KSUtils {
     bool copyRecursively(QString sourceFolder, QString destFolder);
     #endif
 
+    struct JPLFilter {
+        QByteArray item;
+        QByteArray op;
+        QByteArray value;
+    };
+
+    // TODO: Implement Datatypes//Maps for kind, datafields, filters...
+
+    /**
+     *@short Generate a query string for downloading comet/asteroid data from JPL.
+     *@param kind The kind of object we want: ast, com.
+     *@param dataFields The collumns we want to download.
+     *@param filters Filters for the Data.
+     *@return The query string.
+     */
+    QByteArray getJPLQueryString(const QByteArray &kind, const QByteArray &dataFields, const QVector<JPLFilter> &filters);
 }
 
 #endif
diff --git a/kstars/kstars.kcfg b/kstars/kstars.kcfg
index f27a27c35..ec5ced90b 100644
--- a/kstars/kstars.kcfg
+++ b/kstars/kstars.kcfg
@@ -672,6 +672,11 @@
          <whatsthis>The faint magnitude limit for drawing asteroids.</whatsthis>
          <default>15.0</default>
       </entry>
+      <entry name="MagLimitAsteroidDownload" type="Double">
+         <label>Maximum magnitude for asteroids to be downloaded from JPL.</label>
+         <whatsthis>The maximum magnitude (visibility) to filter the asteroid data download from JPL.</whatsthis>
+         <default>12.000</default>
+      </entry>
       <entry name="AsteroidLabelDensity" type="Double">
          <label>Label density for asteroid names</label>
          <whatsthis>Controls the relative number of asteroid name labels drawn in the map.</whatsthis>
diff --git a/kstars/options/opssolarsystem.cpp b/kstars/options/opssolarsystem.cpp
index 9ab2eb88e..5982ced4b 100644
--- a/kstars/options/opssolarsystem.cpp
+++ b/kstars/options/opssolarsystem.cpp
@@ -30,13 +30,19 @@ OpsSolarSystem::OpsSolarSystem()
 
     connect( kcfg_ShowSolarSystem, SIGNAL( toggled(bool) ), SLOT( slotAllWidgets(bool) ) );
     connect( kcfg_ShowAsteroids, SIGNAL( toggled(bool) ), SLOT( slotAsteroidWidgets(bool) ) );
+    connect( kcfg_MagLimitAsteroidDownload, SIGNAL( valueChanged( double ) ), this, SLOT( slotChangeMagDownload( double ) ) );
     connect( kcfg_ShowComets, SIGNAL( toggled(bool) ), SLOT( slotCometWidgets(bool) ) );
     connect( ClearAllTrails, SIGNAL( clicked() ), KStars::Instance(), SLOT( slotClearAllTrails() ) );
     connect( showAllPlanets, SIGNAL( clicked() ), this, SLOT( slotSelectPlanets() ) );
     connect( showNonePlanets, SIGNAL( clicked() ), this, SLOT( slotSelectPlanets() ) );
 
+    MagLimitAsteroidDownloadWarning->setVisible( false );
+
+    kcfg_MagLimitAsteroid->setMinimum( 0.0 );
     kcfg_MagLimitAsteroid->setMaximum( 30.0 );
     kcfg_MaxRadCometName->setMaximum( 100.0 );
+    kcfg_MagLimitAsteroidDownload->setMinimum( 0.0 );
+    kcfg_MagLimitAsteroidDownload->setMaximum( 30.0 );
 
     slotAsteroidWidgets( kcfg_ShowAsteroids->isChecked() );
     slotCometWidgets( kcfg_ShowComets->isChecked() );
@@ -55,6 +61,13 @@ OpsSolarSystem::~OpsSolarSystem()
 {
 }
 
+void OpsSolarSystem::slotChangeMagDownload( double mag ) {
+    if( mag > 12 )
+        MagLimitAsteroidDownloadWarning->setVisible( true );
+    else
+        MagLimitAsteroidDownloadWarning->setVisible( false );
+}
+
 void OpsSolarSystem::slotAllWidgets( bool on ) {
     MajorBodiesBox->setEnabled( on );
     MinorBodiesBox->setEnabled( on );
diff --git a/kstars/options/opssolarsystem.h b/kstars/options/opssolarsystem.h
index 2566b55e2..47bfe7c48 100644
--- a/kstars/options/opssolarsystem.h
+++ b/kstars/options/opssolarsystem.h
@@ -38,11 +38,11 @@ public:
     ~OpsSolarSystem();
 
 private slots:
+    void slotChangeMagDownload( double mag );
     void slotAllWidgets(bool on);
     void slotAsteroidWidgets(bool on);
     void slotCometWidgets(bool on);
     void slotSelectPlanets();
-
     void slotApply();
 
 private:
diff --git a/kstars/options/opssolarsystem.ui b/kstars/options/opssolarsystem.ui
index 3915ffc36..06e446097 100644
--- a/kstars/options/opssolarsystem.ui
+++ b/kstars/options/opssolarsystem.ui
@@ -6,11 +6,26 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>506</width>
-    <height>593</height>
+    <width>438</width>
+    <height>516</height>
    </rect>
   </property>
   <layout class="QVBoxLayout">
+   <property name="spacing">
+    <number>3</number>
+   </property>
+   <property name="leftMargin">
+    <number>3</number>
+   </property>
+   <property name="topMargin">
+    <number>3</number>
+   </property>
+   <property name="rightMargin">
+    <number>3</number>
+   </property>
+   <property name="bottomMargin">
+    <number>3</number>
+   </property>
    <item>
     <widget class="QCheckBox" name="kcfg_ShowSolarSystem">
      <property name="text">
@@ -270,6 +285,36 @@
      <layout class="QVBoxLayout">
       <item>
        <layout class="QGridLayout">
+        <item row="3" column="0">
+         <spacer>
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeType">
+           <enum>QSizePolicy::Fixed</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>16</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item row="1" column="2">
+         <layout class="QHBoxLayout" name="horizontalLayout">
+          <item>
+           <widget class="QDoubleSpinBox" name="kcfg_MagLimitAsteroidDownload"/>
+          </item>
+          <item>
+           <widget class="QLabel" name="label_2">
+            <property name="text">
+             <string>mag</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
         <item row="0" column="0">
          <widget class="QCheckBox" name="kcfg_ShowAsteroids">
           <property name="toolTip">
@@ -323,23 +368,7 @@
           </item>
          </layout>
         </item>
-        <item row="1" column="0">
-         <spacer>
-          <property name="orientation">
-           <enum>Qt::Vertical</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Fixed</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>20</width>
-            <height>16</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-        <item row="1" column="1">
+        <item row="3" column="1">
          <layout class="QHBoxLayout">
           <item>
            <widget class="QCheckBox" name="kcfg_ShowAsteroidNames">
@@ -382,7 +411,7 @@
           </item>
          </layout>
         </item>
-        <item row="1" column="2">
+        <item row="3" column="2">
          <widget class="QSlider" name="kcfg_AsteroidLabelDensity">
           <property name="maximum">
            <number>20</number>
@@ -392,7 +421,7 @@
           </property>
          </widget>
         </item>
-        <item row="2" column="0">
+        <item row="4" column="0">
          <widget class="QCheckBox" name="kcfg_ShowComets">
           <property name="toolTip">
            <string>Draw comets?</string>
@@ -408,7 +437,7 @@
           </attribute>
          </widget>
         </item>
-        <item row="2" column="1">
+        <item row="4" column="1">
          <widget class="QCheckBox" name="kcfg_ShowCometNames">
           <property name="toolTip">
            <string>Show names of comets near the Sun</string>
@@ -424,7 +453,7 @@
           </attribute>
          </widget>
         </item>
-        <item row="2" column="2">
+        <item row="4" column="2">
          <layout class="QHBoxLayout">
           <item>
            <widget class="QDoubleSpinBox" name="kcfg_MaxRadCometName">
@@ -451,6 +480,26 @@
           </item>
          </layout>
         </item>
+        <item row="1" column="1">
+         <widget class="QLabel" name="label_3">
+          <property name="text">
+           <string>Download astroids brighter than</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0" colspan="3">
+         <widget class="QLabel" name="MagLimitAsteroidDownloadWarning">
+          <property name="styleSheet">
+           <string notr="true">color:red; font-weight:bold;</string>
+          </property>
+          <property name="text">
+           <string>This value might result in a big data file and reduced performance!</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignCenter</set>
+          </property>
+         </widget>
+        </item>
        </layout>
       </item>
       <item>
diff --git a/kstars/skycomponents/asteroidscomponent.cpp b/kstars/skycomponents/asteroidscomponent.cpp
index d561048c5..d56e4248e 100644
--- a/kstars/skycomponents/asteroidscomponent.cpp
+++ b/kstars/skycomponents/asteroidscomponent.cpp
@@ -267,14 +267,9 @@ void AsteroidsComponent::updateDataFile()
     QObject::connect(downloadJob, SIGNAL(error(QString)), this, SLOT(downloadError(QString)));
 
     QUrl url = QUrl( "http://ssd.jpl.nasa.gov/sbdb_query.cgi" );
-    QByteArray post_data = QByteArray( "obj_group=all&obj_kind=ast&obj_numbere"
-    "d=num&OBJ_field=0&ORB_field=0&c1_group=OBJ&c1_item=Ai&c1_op=%3C&c1_value="
-    "12&c_fields=AcBdBiBhBgBjBlBkBmBqBbAiAjAgAkAlApAqArAsBsBtCh&table_format=C"
-    "SV&max_rows=10&format_option=full&query=Generate%20Table&.cgifields=forma"
-    "t_option&.cgifields=field_list&.cgifields=obj_kind&.cgifields=obj_group&."
-    "cgifields=obj_numbered&.cgifields=combine_mode&.cgifields=ast_orbit_class"
-    "&.cgifields=table_format&.cgifields=ORB_field_set&.cgifields=OBJ_field_se"
-    "t&.cgifields=preset_field_set&.cgifields=com_orbit_class" );    
+
+    QByteArray mag = QString::number(Options::magLimitAsteroidDownload()).toUtf8();
+    QByteArray post_data = KSUtils::getJPLQueryString("ast", "AcBdBiBhBgBjBlBkBmBqBbAiAjAgAkAlApAqArAsBsBtCh", QVector<KSUtils::JPLFilter> {{"Ai", "<", mag}});
 
     downloadJob->post(url, post_data);
 }
diff --git a/kstars/skycomponents/asteroidscomponent.h b/kstars/skycomponents/asteroidscomponent.h
index 40e31b518..b83675695 100644
--- a/kstars/skycomponents/asteroidscomponent.h
+++ b/kstars/skycomponents/asteroidscomponent.h
@@ -47,7 +47,9 @@ public:
     virtual void draw( SkyPainter *skyp );
     virtual bool selected();
     virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+
     void updateDataFile();
+
     QString ans();
 
 protected slots:
diff --git a/kstars/skycomponents/cometscomponent.cpp b/kstars/skycomponents/cometscomponent.cpp
index cc303f3f7..b4577ac50 100644
--- a/kstars/skycomponents/cometscomponent.cpp
+++ b/kstars/skycomponents/cometscomponent.cpp
@@ -41,6 +41,7 @@
 #include "projections/projector.h"
 #include "auxiliary/filedownloader.h"
 #include "kspaths.h"
+#include "ksutils.h"
 
 CometsComponent::CometsComponent( SolarSystemComposite *parent )
         : SolarSystemListComponent( parent ) {
@@ -224,19 +225,9 @@ void CometsComponent::updateDataFile()
     connect(downloadJob, SIGNAL(error(QString)), this, SLOT(downloadError(QString)));
 
     QUrl url = QUrl( "http://ssd.jpl.nasa.gov/sbdb_query.cgi" );
-    QByteArray post_data = QByteArray( "obj_group=all&obj_kind=com&obj_numbere"
-    "d=all&OBJ_field=0&OBJ_op=0&OBJ_value=&ORB_field=0&ORB_op=0&ORB_value=&com"
-    "bine_mode=AND&c1_group=OBJ&c1_item=Af&c1_op=!%3D&c1_value=D&c2_group=OBJ&"
-    "c2_item=Ae&c2_op=!%3D&c2_value=SOHO&c_fields=AcBdBiBgBjBlBkBqBbAgAkAlApAq"
-    "ArAsBsBtChAmAn&table_format=CSV&max_rows=10&format_option=full&query=Gene"
-    "rate%20Table&.cgifields=format_option&.cgifields=field_list&.cgifields=ob"
-    "j_kind&.cgifields=obj_group&.cgifields=obj_numbered&.cgifields=combine_mo"
-    "de&.cgifields=ast_orbit_class&.cgifields=table_format&.cgifields=ORB_fiel"
-    "d_set&.cgifields=OBJ_field_set&.cgifields=preset_field_set&.cgifields=com"
-    "_orbit_class" );    
+    QByteArray post_data = KSUtils::getJPLQueryString("com", "AcBdBiBgBjBlBkBqBbAgAkAlApAqArAsBsBtChAmAn",  QVector<KSUtils::JPLFilter> {{"Af", "!=", "D"}});
 
     downloadJob->post(url, post_data);
-
 }
 
 void CometsComponent::downloadReady()


More information about the Kstars-devel mailing list