Ejemplo n.º 1
0
def obslist(limit_and_offset, **filters):
    '''This function retrieves observations list from a local database and
        displays it.'''
    aos_before_org = filters.get("aos_before")
    if aos_before_org is not None:
        # Repository uses datetime.datetime structure to bound dates and it is
        # exact date.
        # User provides datetime.date (which not include hour) and it means that
        # list should contain observations from @los_after day 00:00:00 hour to
        # @aos_before day 23:59:59.999 hour. For handle it we add 1 day to
        # @aos_before day before send to repository.
        filters["aos_before"] = aos_before_org + timedelta(days=1)

    repository = Repository()
    obslist = repository.read_observations(filters, **limit_and_offset)
    satellites_list = repository.read_satellites()
    observation_count = repository.count_observations(filters)
    stations_list = repository.read_stations()

    satellites_dict = {
        sat["sat_id"]: sat["sat_name"]
        for sat in satellites_list
    }
    stations_dict = {s["station_id"]: s["name"] for s in stations_list}
    for obs in obslist:
        obs["sat_name"] = satellites_dict[obs["sat_id"]]
        obs["station_name"] = stations_dict[obs["station_id"]]

    if aos_before_org is not None:
        # We send back to user the same date as user provide.
        filters["aos_before"] = aos_before_org

    # When database will contain many satellites and stations then we need
    # refactor this code to lazy, async read satellites and stations.
    return 'obslist.html', dict(obslist=obslist,
                                item_count=observation_count,
                                satellites=satellites_list,
                                stations=stations_list,
                                filters=filters)
Ejemplo n.º 2
0
# This script generates fly-over charts for observations that have TLE
# information recorded.

from typing import Dict
from app.controllers.receive import make_charts
from app.repository import Repository, Station, StationId

if __name__ == '__main__':
    stations: Dict[StationId, Station] = { }

    repository = Repository()
    observation_count = repository.count_observations()

    print("There are a total of %d observations" % observation_count)

    STEP = 100
    limit = STEP
    offset = 0
    index = 0

    while offset < observation_count:
        # ToDo: Add filtration when MR with filtration will be merged.
        observations = repository.read_observations(limit=limit, offset=offset)

        print("Processing batch of %d observations" % len(observations))

        for observation in observations:
            if observation['tle'] is None:
                print("No TLE info for observation %d, skipping." % observation['obs_id'])
                continue
            station_id = observation["station_id"]
Ejemplo n.º 3
0
 def test_observations_count(self, repository: Repository):
     count = repository.count_observations()
     self.assertEqual(count, 4)