-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fetching data from Space-Track, fixing some bugs, adding cron tasks for updating database with tool functions * Orbital chart done, using backend data without refetching from the backend server * Clean code of orbitalDataGraph, restore strapi files, adding cronTask to the 3rd of each month. * Adding package*.json files * ESLint fixed * Updating strapi env * Reseting frontend/package.json * Prettier checked * Updating for ESlint check
- Loading branch information
Graulitard
authored and
GitHub
committed
Jul 18, 2024
1 parent
70fa07d
commit c443439
Showing
19 changed files
with
1,423 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // backend/config/functions/cronTask.js | ||
| /* | ||
| * Function to fetch data from Space-Track such as Eccentricy, SMA, Inclination every month | ||
| * and update the database with the new data | ||
| */ | ||
| 'use strict'; | ||
|
|
||
| const { fetchOrbitalData } = require('./satelliteUtils'); | ||
|
|
||
| module.exports = { | ||
| updateAllSatellitesData: { | ||
| task: async ({ strapi }) => { | ||
| try { | ||
| // Fetching all satellites | ||
| const satellites = await strapi.entityService.findMany('api::satellite.satellite'); | ||
|
|
||
| // Waiting for all promises to be resolved | ||
| await Promise.all( | ||
| satellites.map(async satellite => { | ||
| try { | ||
| setTimeout(async () => { | ||
| await fetchOrbitalData(strapi, satellite.id); | ||
| }, 10000); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }) | ||
| ); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }, | ||
| options: { | ||
| rule: "0 0 0 3 * *", // Every month on the 3rd at midnight | ||
| }, | ||
| }, | ||
| }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // backend/utils/satelliteUtils.js | ||
| const axios = require('axios'); | ||
|
|
||
| async function fetchOrbitalData(strapi, contextId) { | ||
| try { | ||
| // Fetching the satellite | ||
| const satellite = await strapi.entityService.findOne('api::satellite.satellite', contextId); | ||
| const noradId = satellite.catalogNumberNORAD; | ||
|
|
||
| // Authentication to Space-Track | ||
| const authResponse = await axios.post('https://www.space-track.org/ajaxauth/login', { | ||
| identity: 'floridg@stud.ntnu.no', | ||
| password: 'Vm5JxTtD3-hYBdq' | ||
| }); | ||
|
|
||
| if (authResponse.status === 200) { | ||
| // Fetching data from Space-Track | ||
| const satelliteResponse = await axios.get(`https://www.space-track.org/basicspacedata/query/class/gp_history/NORAD_CAT_ID/${noradId}/orderby/TLE_LINE1%20ASC/EPOCH/1950-07-02--2024-07-02/format/json`, { | ||
| headers: { | ||
| Cookie: authResponse.headers['set-cookie'] | ||
| } | ||
| }); | ||
|
|
||
| if (satelliteResponse.status === 200) { | ||
| // Collecting data | ||
| const satelliteData = satelliteResponse.data; | ||
| const historicalOrbitalData = satelliteData.map(data => ({ | ||
| epoch: data.EPOCH, | ||
| inclination: data.INCLINATION, | ||
| eccentricity: data.ECCENTRICITY, | ||
| semiMajorAxis: data.SEMIMAJOR_AXIS | ||
| })); | ||
|
|
||
| // Updating the satellite with the new data | ||
| const updatedSatellite = await strapi.entityService.update('api::satellite.satellite', contextId, { | ||
| data: { | ||
| historicalOrbitalData: historicalOrbitalData, | ||
| }, | ||
| }); | ||
| return updatedSatellite; | ||
| } else { | ||
| throw new Error('Error while fetching data from Space-Track'); | ||
| } | ||
| } else { | ||
| throw new Error('Authentication failed'); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error while fetching data to Space-Track: ', error); | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| fetchOrbitalData, | ||
| }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,9 @@ | |
| }, | ||
| "massKg": { | ||
| "type": "float" | ||
| }, | ||
| "historicalOrbitalData": { | ||
| "type": "json" | ||
| } | ||
| } | ||
| } | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.