Example #1
0
    def test_stations(self, repository: Repository):
        """Checks that a list of stations is returned properly."""
        station_entries = repository.read_stations()
        station_statistics = repository.read_stations_statistics()
        self.assertEqual(len(station_entries), 2)
        self.assertEqual(len(station_statistics), 2)
        s1, s2 = zip(station_entries, station_statistics)

        self.check_station1(*s1)
        self.check_station2(*s2)

        # Now limit number of returned stations to just one. There should be only station-id 1.
        station_entries = repository.read_stations(limit=1)
        station_statistics = repository.read_stations_statistics(limit=1)
        self.assertEqual(len(station_entries), 1)
        self.assertEqual(len(station_statistics), 1)
        self.check_station1(station_entries[0], station_statistics[0]
                            )  # This should return values for station-id 1

        # Now skip the first station. Only station 2 should be returned.
        station_entries = repository.read_stations(offset=1)
        station_statistics = repository.read_stations_statistics(offset=1)
        self.assertEqual(len(station_entries), 1)
        self.assertEqual(len(station_statistics), 1)
        self.check_station2(station_entries[0], station_statistics[0]
                            )  # This should return values for station-id 2
Example #2
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)
Example #3
0
def stations(limit_and_offset):
    '''This function retrieves list of all registered ground stations.'''
    repository = Repository()
    stations = repository.read_stations(**limit_and_offset)
    statistics = repository.read_stations_statistics(**limit_and_offset)
    station_count = repository.count_stations()
    # Now convert the data to a list of objects that we can pass to the template.
    stationlist = []

    for station, stat in zip(stations, statistics):
        x = {}
        x['station_id'] = station['station_id']
        x['name'] = station['name']
        x['coords'] = utils.coords(station['lon'], station['lat'])
        x['descr'] = station['descr']
        x['config'] = station['config']
        x['registered'] = station['registered']
        x['lastobs'] = stat["last_los"]
        x['cnt'] = stat["observation_count"]

        stationlist.append(x)

    return 'stations.html', dict(stations=stationlist,
                                 item_count=station_count)