Skip to content

Commit 60752bd

Browse files
Update SatPass.py
1 parent d094fb4 commit 60752bd

File tree

1 file changed

+69
-50
lines changed

1 file changed

+69
-50
lines changed

src/SatPass.py

+69-50
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import requests
22
import json
3+
import datetime
4+
import time
35
import sqlite3;
4-
import pandas as pd
5-
import ephem # USE THIS in terminal TO IMPORT EPHEM python -m pip install ephem
66
import csv
7+
import math
78

89
class Station (object):
910

@@ -27,61 +28,87 @@ def __init__(self, ID, AOSt, LOSt, AOSd, TCAd, LOSd, Sperc):
2728

2829
# Functions
2930
def Schedule(List, StartT, EndT): #function to schedule the given Pass List in the allowed time period
31+
print('Creating Schedule From ', StartT, 'to ', EndT)
3032
SchedList = []
31-
SchedNum = 1
33+
SchedNum = 0
3234
numconsidered = 0
33-
CurrSat = List[0]
34-
LST = '0' #Last Scheduled Time
35-
35+
StartT = string_time_to_unix_time(StartT)
36+
EndT = string_time_to_unix_time(EndT)
37+
LST = StartT #Last Scheduled Time
38+
PrevSatID = []
39+
PrevSatDesc = []
40+
List.sort()
3641

3742
for x in range(1,len(List)): #Goes through every pass in List
43+
MatchID = 0
3844
CompSat = List[x] #CompSat = relevent pass
39-
if StartT <= CompSat[0]: #only enters if start of pass is after the specified start time frame
40-
if EndT >= CompSat[1]: #only enters if the end of pass is before the specified end time frame
41-
numconsidered = numconsidered+1 #this code runs whenever a sat is being considered
42-
if LST < CompSat[0]: #if the last considered time is before the start time
43-
###########################################################################
44-
##THIS IS WHERE THE SPECIFIC STATION PREFERENCES ARE ADDED
45-
##there have been a few provided examples of what priorities can be added
46-
###########################################################################
47-
# this example checks if the sattelite is to the WEST of the ground station
48-
# (can be used if there is a physical restriction making sats to the east unreadable)
49-
#
50-
#
51-
# this example checks if the duration of the pass is over 600 seconds long
52-
# (can be used if short passes do not want to be considered)
53-
#
54-
#
55-
# this example only considers sattelites that are below limit_elevation height
56-
# (can be used if the ground station can not accurately read sats above a certain elevation)
57-
#
58-
#
59-
###########################################################################
60-
61-
#this scedules the currently considered sattelite (currently sceduling if it fits within schedule)
62-
SchedList.append(CompSat)
63-
SchedNum = SchedNum+1
64-
LST = CompSat[1]
45+
compsat_0_unix_time = string_time_to_unix_time(CompSat[0])
46+
if StartT <= compsat_0_unix_time: #only enters if start of pass is after the specified start time frame
47+
if EndT >= string_time_to_unix_time(CompSat[1]): #only enters if the end of pass is before the specified end time frame
48+
if CompSat[2] > 600: #only enters if the time of a pass is more than 15 sec
49+
for y in range(0,len(PrevSatID)):
50+
if CompSat[8] == PrevSatID[y]:
51+
MatchID = 1
52+
if MatchID == 0: #disqualifies same sat ID from being scheduled twice
53+
if PrevSatDesc != CompSat[7]:
54+
numconsidered = numconsidered+1 #this code runs whenever a sat is being considered
55+
Score = SigScore(CompSat,LST)
56+
if Score > 0.5: #if the sigmoid score of the sattelite is greater than 0.5 (CHANGE THIS currently x > 0 in the sig function to be scheduled)
57+
58+
#this scedules the currently considered sattelite (currently sceduling if it fits within schedule)
59+
print('Scheduling Sattelite with starting time ',CompSat[0], 'New Last Scheduled Time is ',CompSat[1])
60+
SchedList.append(CompSat)
61+
SchedNum = SchedNum+1
62+
LST = string_time_to_unix_time(CompSat[1])
63+
PrevSatID.append(CompSat[8])
64+
PrevSatDesc = CompSat[7]
6565

6666

6767

6868

6969
print('After considering', numconsidered, 'sattelites, scheduling pass readings of', len(SchedList), 'sattelites in the allocated time period')
70-
#print('After considering', len(List), 'sattelites, scheduling pass of sattelite ID(s): ', CurrSat.ID)
71-
#print('After considering', len(List), 'sattelites, scheduling pass of sattelite ID(s): ', len(SchedList))
7270
return SchedList
7371

74-
def GetPasses(Station, StartT, EndT, minimum_altitude, min_pass_duration):
75-
a = 0
76-
return
72+
def SigScore(Pass,LST):
73+
x = -10
74+
###########################################################################
75+
##THIS IS WHERE THE SPECIFIC STATION PREFERENCES ARE ADDED
76+
##there have been a few provided examples of what priorities can be added
77+
###########################################################################
78+
# this example checks if the sattelite is to the WEST of the ground station
79+
# (can be used if there is a physical restriction making sats to the east unreadable)
80+
# if Pass[3] < 180:
81+
# if Pass[4] < 180:
82+
#
83+
# this example checks if the duration of the pass is over 600 seconds long
84+
# (can be used if short passes do not want to be considered)
85+
# if Pass[2] > 600:
86+
#
87+
# this example only considers sattelites that are below limit_elevation height
88+
# (can be used if the ground station can not accurately read sats above a certain elevation)
89+
# if Pass[6] < limit_elevation:
90+
#
91+
# The X value directly changes what the score will be, negasive values will always be below a 0.5
92+
# while pos values increase the score exponentially, You should add to x based on how important the
93+
# preference is, and then increase the value that the score must be over in the schedule function to
94+
# prioritise based on those scores
95+
###########################################################################
96+
satstart = string_time_to_unix_time(Pass[0])
97+
#print(LST)
98+
if LST < satstart: #if the last scheduled time is before the start time
99+
x = x+11
100+
score = 1/(1 + math.exp(-x))
101+
return score
102+
103+
77104

78105
def string_time_to_unix_time(input_str):
79106
ymd_s, hms_s = tuple(input_str.split(" "))
80107
year, month, day = tuple(ymd_s.split('-'))
81108
hms_s = hms_s.split(".")[0]
82109
hour, minute, second = tuple(hms_s.split(':'))
83110
date_time = datetime.datetime(int(year), int(month), int(day), int(hour), int(minute), int(second))
84-
return ("unix_timestamp => ",(time.mktime(date_time.timetuple())))
111+
return (time.mktime(date_time.timetuple()))
85112

86113

87114
################
@@ -91,28 +118,20 @@ def string_time_to_unix_time(input_str):
91118
#Set up Stations and Passes
92119

93120

94-
sats = sqlite3.connect("C:\\Users\\Yogif\\OneDrive\\Desktop\\Homework\\CS 358\\satdata\\passes.sqlite\\passes.sqlite")
121+
sats = sqlite3.connect("C:\\Users\\Yogif\\OneDrive\\Desktop\\Homework\\CS 358\\satdata\\passes.sqlite\\passes.sqlite") #input file path to SAT PASS LIST sqlite file
95122

96123
sc = sats.cursor()
97-
#print(sc.execute('SELECT name FROM sqlite_schema WHERE type=\'table\' AND name NOT LIKE \'sqlite_%\';'))
98124
PassList = []
99125
for row in sc.execute('SELECT * FROM passes;'): #fills in the PassList array with all of the 4.8M individual passes
100126
PassList.append(row)
101127

102-
for pass_ in PassList:
103-
start, end, duration, rizeaz, setaz, tca, max_el, gs, norad = pass_
104-
105128
#INFO READ IN IS FORMATTED AS: start, end, duration, riseaz, setaz, tca, max el, gs, norad (TCA IRRELEVENT)
106129

107-
InStartTime = '2018-09-12 07:22:40.080409'
108-
InEndTime = '2018-09-13 21:51:21.865953'
130+
InStartTime = '2018-08-01 00:00:00.000000'
131+
InEndTime = '2018-08-01 20:00:00.000000' #currently makes schedule over 20 hour time period on August 1st 2018
109132
FinSc = Schedule(PassList, InStartTime, InEndTime)
110133

111-
#Testing
112-
#for y in range(len(FinSc)):
113-
# print(FinSc[y])
114-
115-
#Write to CSV
134+
#Write Schedule to CSV
116135
file = open('schedule.csv', 'w') #Opens file in write mode
117136
writer = csv.writer(file)
118137
for y in range(len(FinSc)):

0 commit comments

Comments
 (0)