示例#1
0
def surface_search(search_params: list, db=False) -> list:
    if db:
        current_url, pagesnr, database = search_url(search_params, db)
    else:
        current_url, pagesnr = search_url(search_params, db)

    data = []
    for i in range(pagesnr):
        for item in surface_data(current_url):
            data.append(item)
        current_url = next_page(current_url, i + 1)

    assert data != []

    data = scalg.score_columns(data, [2, 3, 4], [0, 1, 0])
    data.sort(key=lambda d: d[-1])

    undup = []
    undup_indexes = []
    for i, d in enumerate(data):
        if d[-1] in undup:
            undup_indexes.append(i)
        else:
            undup.append(d[-1])
    for i in sorted(undup_indexes, reverse=True):
        del data[i]

    return (data, database) if db else data
示例#2
0
    def test_score_columns(self, ):
        req_result = [[2016, 21999, 62000, 181, 1.4911330049261085],
                      [2013, 21540, 89000, 223, 0.5665024630541872],
                      [2015, 18900, 100000, 223, 1.6666666666666665],
                      [2013, 24200, 115527, 223, 0.12972085385878485],
                      [2016, 24990, 47300, 223, 1.0]]

        result = scalg.score_columns(DATA, [0, 1], WEIGHTS)
        assert result == req_result
示例#3
0
 def get_pollution(self, location: str) -> list:
     if type(location) == str:
         user_coords = self._user_location(location)
     else:
         user_coords = location
     item = self.kmz_obj.coords_item(user_coords)
     edges, image = self.kmz_obj.load_images(item[1],
                                             single=True,
                                             neighbours=True)
     closest_unique_spots = find_pollution_coords(user_coords, edges, image)
     for i, spot in enumerate(closest_unique_spots):
         elevation = self.gmaps.elevation(spot)[0]['elevation']
         weather = self._coords_weather(spot)
         distance = geodesic(user_coords, spot).km
         closest_unique_spots[i] = [spot, distance, elevation] + weather
     scored = scalg.score_columns(closest_unique_spots, [1, 2, 4],
                                  [0, 1, 0])
     return user_coords, sorted(scored, key=lambda x: x[-1])[-1]
示例#4
0
def surface_search(search_params: list, db=False) -> list:
    if db:
        current_url, pagesnr, database = search_url(search_params, db)
    else:
        current_url, pagesnr = search_url(search_params, db)

    data = []
    for i in range(pagesnr):
        for item in surface_data(current_url + "&lang=en"):
            data.append(item)
        current_url = next_page(current_url, i + 1)

    assert data != []

    data = scalg.score_columns(data, [2, 3, 4], [0, 1, 0])

    if db:
        return data, database
    else:
        return data
示例#5
0
def search(search_params: list, db=False) -> list:
    if db:
        current_url, pagesnr, database = search_url(search_params, db)
    else:
        current_url, pagesnr = search_url(search_params, db)

    # get links
    car_links = []
    for i in range(pagesnr):
        for link in get_page_listings(current_url + "&lang=en"):
            car_links.append(link)
        current_url = next_page(current_url, i + 1)

    assert len(car_links) != 0

    data = [get_car_data(link + "&lang=en") for link in car_links]
    data = scalg.score_columns(data, [2, 3, 4], [0, 1, 0])

    if db:
        return database, data
    else:
        return data
示例#6
0
import os, sys, inspect

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

import scalg

DATA = [
    [2016, 21999, 62000, 181],
    [2013, 21540, 89000, 223],
    [2015, 18900, 100000, 223],
    [2013, 24200, 115527, 223],
    [2016, 24990, 47300, 223],
]

if __name__ == "__main__":
    print(scalg.score_columns(DATA, [0, 1], [1, 0, 0, 1]))