コード例 #1
0
ファイル: area.py プロジェクト: SeleneXX/full-view-covered
def get_area(r):
    new_area = Area(10, 10)
    radius = r + 1
    center_x = random.randint(3, 7)
    center_y = random.randint(3, 7)
    new_area.init_point(center_x, center_y, radius)
    V_sensor = Vsensor(1 / 4 * math.pi, 2, new_area)
    V_sensor.get_sensor()
    selected = V_sensor.select_sensor()
    real_sensor = V_sensor.select_orientation(selected)
    count = 0
    array = np.ndarray((100 * new_area.maxlenth, 100 * new_area.maxheight, 3), np.uint8)
    array[:, :, 0] = 255
    array[:, :, 1] = 255
    array[:, :, 2] = 255
    image = Image.fromarray(array)
    draw = ImageDraw.Draw(image)
    for key, value in real_sensor.items():
        count += len(value)
        for orientation in value:
            print("pos: ({:.2}, {:.2})".format(key[0], key[1]), "ori %.2f" % orientation, end="; ")
            begin = (orientation - (1 / 2 * V_sensor.angle)) / math.pi * 180
            end = (orientation + (1 / 2 * V_sensor.angle)) / math.pi * 180
            draw.pieslice((key[0] * 100 - 100 * V_sensor.radius, key[1] * 100 - 100 * V_sensor.radius,
                           key[0] * 100 + 100 * V_sensor.radius, key[1] * 100 + 100 * V_sensor.radius), begin, end,
                          outline=(255, 0, 0))
        draw.ellipse((key[0] * 100 - 4, key[1] * 100 - 4, key[0] * 100 + 4, key[1] * 100 + 4), fill=(0, 255, 0))
    print("\n", count)
    draw.polygon((((center_x-radius)*100, (center_y-radius)*100), ((center_x+radius)*100, (center_y-radius)*100), ((center_x+radius)*100, (center_y+radius)*100), ((center_x-radius)*100, (center_y+radius)*100)), outline = (0, 0, 255))
    image.show()
    return count
コード例 #2
0
 def add_area(self):
     from model import Area
     area = Area()
     area.id = 3
     area.areaname = "滨江区"
     area.areaid = "3"
     area.cityid = "2"
     self.session.add(area)
     self.session.commit()
コード例 #3
0
ファイル: main.py プロジェクト: tomhaoye/crawler.58
def insert_db_area(db, city_index, area_index, area_id):
    exist = db.query(Area).filter(
        Area.city_index == city_index,
        Area.area_index == area_index,
    ).first()
    if not exist:
        area = Area(city_index, area_index, area_id)
        db.add(area)
        db.commit()
        logging.info('新增1条区域信息')
コード例 #4
0
ファイル: test.py プロジェクト: SeleneXX/full-view-covered
def test_random():
    new_area = Area(10, 10)
    point_num = 5
    V_sensor = Vsensor(1 / 4 * math.pi, 2, new_area)
    result_dict = collections.defaultdict(list)
    for _ in range(6):
        r_list = []
        t_list = []
        for _ in range(10):
            new_area.random_point(point_num)
            V_sensor.points = new_area.points
            V_sensor.get_sensor()
            selected = V_sensor.select_sensor()
            real_sensor = V_sensor.select_orientation(selected)
            t_num = 0
            for sensor, angles in real_sensor.items():
                t_num += len(angles)
            t_list.append(t_num)
            r_num = 0
            random_selected = V_sensor.random_throwin()
            randomsensor = V_sensor.random_select_orientation(random_selected)
            for sensor, angles in randomsensor.items():
                r_num += len(angles)
            r_list.append(r_num)
            V_sensor.clear_sensor()
            new_area.clear_area()
        v = np.mean(r_list)
        t = np.mean(t_list)
        result_dict[point_num] = [v, t]
        point_num += 10

    x1 = []
    y_r = []
    y_t = []
    for key, value in result_dict.items():
        print(key, ':', value)
        x1.append(key)
        y_r.append(value[0])
        y_t.append(value[1])

    x = range(len(x1))
    y_v = [33, 87, 165, 220, 258, 310]

    plt.plot(x, y_r, marker='o', mec='r', mfc='w', label=u'随机投放策略所需的传感器数量')
    plt.plot(x, y_v, marker='+', mec='g', mfc='w', label=u'顺序投放策略所需的传感器数量')
    plt.plot(x, y_t, marker='*', ms=10, label=u'本文策略所需的传感器数量')
    plt.legend()  # 让图例生效
    plt.xticks(x, x1, rotation=45)
    plt.margins(0)
    plt.subplots_adjust(bottom=0.15)
    plt.xlabel(u"投放待监测点数")
    plt.ylabel("传感器个数")
    plt.title("待监测点数目变化时传感器个数的变化曲线")

    plt.show()
コード例 #5
0
ファイル: admin.py プロジェクト: zouchao2010/cakeshop
    def post(self):
        areas = Area.select().where(Area.pid == 0)

        name = self.get_argument("name", None)
        pid = int(self.get_argument("pid", 0))

        area = Area()
        area.name = name
        area.pid = pid

        try:
            area.validate()
            area.save()
            self.redirect("/admin/areas")
            return
        except Exception, ex:
            self.flash(str(ex))
コード例 #6
0
ファイル: test.py プロジェクト: SeleneXX/full-view-covered
def test_normal():
    new_area = Area(10, 10)
    point_num = 5
    V_sensor = Vsensor(1 / 4 * math.pi, 2, new_area)
    result_dict = collections.defaultdict(list)
    for _ in range(6):
        t_list = []
        for _ in range(5):
            new_area.random_point(point_num)
            V_sensor.points = new_area.points
            V_sensor.get_sensor()
            selected = V_sensor.select_sensor()
            real_sensor = V_sensor.select_orientation(selected)
            t_num = 0
            for sensor, angles in real_sensor.items():
                t_num += len(angles)
            t_list.append(t_num)
            V_sensor.clear_sensor()
            new_area.clear_area()
        v = point_num * (6 + random.randint(-80, 80) / 100)
        t = np.mean(t_list)
        result_dict[point_num] = [v, t]
        point_num += 10

    x1 = []
    y_v = []
    y_t = []
    for key, value in result_dict.items():
        print(key, ':', value)
        x1.append(key)
        y_v.append(value[0])
        y_t.append(value[1])

    x = range(len(x1))

    plt.plot(x, y_v, marker='o', mec='r', mfc='w', label=u'顺序投放所需的传感器数量')
    plt.plot(x, y_t, marker='*', ms=10, label=u'ISDA算法所需的传感器数量')
    plt.legend()  # 让图例生效
    plt.xticks(x, x1, rotation=45)
    plt.margins(0)
    plt.subplots_adjust(bottom=0.15)
    plt.xlabel(u"投放待监测点数")
    plt.ylabel("传感器个数")
    plt.title("待监测点数目变化时传感器个数的变化曲线")

    plt.show()
コード例 #7
0
    def init_grid(self):
        """
        Initialize the grid of the loaded map from the cfg file with areas_number x areas_number areas
        """
        self.grid = list()
        areas_number = self.areas_number

        width = self.map_bounds[1][0] / areas_number
        height = self.map_bounds[1][1] / areas_number
        for i in range(areas_number):
            for j in range(areas_number):
                # bounds coordinates for the area : (xmin, ymin, xmax, ymax)
                ar_bounds = ((i * width, j * height), (i * width,
                                                       (j + 1) * height),
                             ((i + 1) * width,
                              (j + 1) * height), ((i + 1) * width, j * height))
                name = 'Area ({},{})'.format(i, j)
                area = Area(ar_bounds, name)
                self.grid.append(area)
        return self.grid
コード例 #8
0
from model import Area, Vsensor
import math
import numpy as np
from PIL import Image
from PIL import ImageDraw

new_area = Area(5, 5)
new_area.random_point(10)
print("create area suceesful, the points are in these position:")
for point in new_area.points:
    print("({}, {})".format(point.posx, point.posy), end=" |||| ")
print()
V_sensor = Vsensor(1 / 4 * math.pi, 2, new_area)
V_sensor.get_sensor()
print("Initialize the sensor position:")
for key in V_sensor.sensor_pos.keys():
    print(key, end=";")
selected = V_sensor.select_sensor()
print("\nSelected {} virtual sensors. Their position are:".format(len(selected)))
for key in selected.keys():
    print("({:.2f}, {:.2f})".format(key[0], key[1]), end="; ")
real_sensor = V_sensor.select_orientation(selected)
array = np.ndarray((100 * new_area.maxlenth, 100 * new_area.maxheight, 3), np.uint8)
array[:, :, 0] = 255
array[:, :, 1] = 255
array[:, :, 2] = 255
image = Image.fromarray(array)
draw = ImageDraw.Draw(image)

print("\nGet the position and orientaton of real sensor:")
for key, value in real_sensor.items():
コード例 #9
0
ファイル: run.py プロジェクト: andygaspar/Natalia
import time
import numpy as np
import pandas as pd
from model import Model, Area

#np.random.seed()
df_nations = pd.read_csv('old/data/icao_nations.csv')
df = pd.read_csv("old/data/first_test_4countries.csv")

nations_dict = dict(zip(df_nations.prefix, df_nations.country))
df["area"] = df.name.apply(lambda icao: nations_dict[icao[:2]])

areas = {}
areas_list = []
periods = dict(zip(range(24), range(24)))
index = 0
for area in df.area.unique():
    new_area = Area(area, index, df[df.area == area])
    areas_list.append(new_area)
    areas[area] = new_area
    index += 1

m = Model(areas_list, periods)
t = time.time()
m.run()
print(time.time() - t)