コード例 #1
0
    def setUp(self):
        engine = create_engine('sqlite:///test_points.sqlite')

        # Creates all the tables
        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        self.points_mgr = PointManager('test_points.sqlite')

        self.logPoint()
コード例 #2
0
 def setUp(self):
     engine = create_engine('sqlite:///test_points.sqlite')
     # Creates all the tables
     Base.metadata.create_all(engine)
     Base.metadata.bind = engine
     points_api.point_mgr = PointManager('test_points.sqlite')
     points_api.app.testing = True
     self.app = points_api.app.test_client()
     self.logPoint()
コード例 #3
0
class TestPointManager(unittest.TestCase):
    """ Tests PointManager Class """
    def setUp(self):
        engine = create_engine('sqlite:///test_points.sqlite')

        # Creates all the tables
        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        self.points_mgr = PointManager('test_points.sqlite')

        self.logPoint()

    def tearDown(self):
        os.remove('test_points.sqlite')
        self.logPoint()

    def logPoint(self):
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))

    def test_add_point(self):
        point = Point(5, 5)
        self.points_mgr.add_point(point)

        all_points = self.points_mgr.get_all_points()
        self.assertEqual(len(all_points), 1)

    def test_add_point_invalid(self):
        self.assertRaisesRegex(ValueError, "Invalid Point Object",
                               self.points_mgr.add_point, None)
        self.assertRaisesRegex(ValueError, "Invalid Point Object",
                               self.points_mgr.add_point, [])

    def test_update_point(self):
        point1 = Point(5, 5)
        point1_id = self.points_mgr.add_point(point1)

        retrieved_point = self.points_mgr.get_point(point1_id)
        self.assertEqual(retrieved_point.x, 5)
        self.assertEqual(retrieved_point.y, 5)

        retrieved_point.x = 6
        retrieved_point.y = 7
        self.points_mgr.update_point(retrieved_point)

        retrieved_updated_point = self.points_mgr.get_point(point1_id)
        self.assertEqual(retrieved_updated_point.x, 6)
        self.assertEqual(retrieved_updated_point.y, 7)

    def test_update_point_invalid(self):
        self.assertRaisesRegex(ValueError, "Invalid Point Object",
                               self.points_mgr.update_point, None)
        self.assertRaisesRegex(ValueError, "Invalid Point Object",
                               self.points_mgr.update_point, [])

    def test_delete_point(self):
        point1 = Point(5, 5)
        point1_id = self.points_mgr.add_point(point1)

        retreived_point1 = self.points_mgr.get_point(point1_id)
        self.assertIsNotNone(retreived_point1)

        self.points_mgr.delete_point(point1_id)

        retreived_point1 = self.points_mgr.get_point(point1_id)
        self.assertIsNone(retreived_point1)

    def test_delete_point_invalid(self):
        self.assertRaisesRegex(ValueError, "Invalid Point ID",
                               self.points_mgr.delete_point, None)
        self.assertRaisesRegex(ValueError, "Invalid Point ID",
                               self.points_mgr.delete_point, "1")

    def test_get_point(self):
        point1 = Point(5, 5)
        point2 = Point(6, 6)

        point1_id = self.points_mgr.add_point(point1)
        point2_id = self.points_mgr.add_point(point2)

        retrieved_point1 = self.points_mgr.get_point(point1_id)
        self.assertIsNotNone(retrieved_point1)
        self.assertEqual(retrieved_point1.x, 5)
        self.assertEqual(retrieved_point1.y, 5)

        retrieved_point2 = self.points_mgr.get_point(point2_id)
        self.assertIsNotNone(retrieved_point2)
        self.assertEqual(retrieved_point2.x, 6)
        self.assertEqual(retrieved_point2.y, 6)

    def test_get_point_invalid(self):
        self.assertRaisesRegex(ValueError, "Invalid Point ID",
                               self.points_mgr.get_point, None)
        self.assertRaisesRegex(ValueError, "Invalid Point ID",
                               self.points_mgr.get_point, "1")

    def test_get_all(self):
        all_points = self.points_mgr.get_all_points()
        self.assertEqual(len(all_points), 0)

        point1 = Point(5, 5)
        point2 = Point(6, 6)

        point1_id = self.points_mgr.add_point(point1)
        point2_id = self.points_mgr.add_point(point2)

        all_points = self.points_mgr.get_all_points()
        self.assertEqual(len(all_points), 2)
コード例 #4
0
import json, os, sys

import requests

import const
from point_manager import PointManager

assert len(sys.argv) == 2
response = requests.get(const.URL.format(sys.argv[1]))

game_json = json.loads(response.text)
players = [game_json["player1"], game_json["player2"]]
output = ["{},{},ラリー本数".format(*players)]

pmger = PointManager()
for p, cnt in zip(game_json["getPointPlayer"], game_json["rallyCnt"]):
    pmger.add_point(p)
    score = pmger.get_score()
    output.append("{},{},{}".format(score["p1p"], score["p2p"], cnt))

with open("output/normal.csv", "w") as f:
    f.write("\n".join(output))

with open("output/memo.txt", "w") as f:
    f.write(game_json["memo"])

#  ラリー内容 2シート目
output = []
pmger = PointManager()
for i, p in enumerate(game_json["getPointPlayer"]):
    pmger.add_point(p)
コード例 #5
0
]

tree_points_arr = possible_tree_points_arr[feasible_tree_indeces]
tree_basins_arr = possible_tree_basin_arr[feasible_tree_indeces]
tree_weights_arr = possible_tree_weights_arr[feasible_tree_indeces]
tree_points_kdtree = KDTree(tree_points_arr)

for j in range(num_trials):
    print("TRIAL {}".format(j))
    trial_uuid = str(uuid.uuid4())

    bucket_dirname = os.path.join("output", algorithm_name, heuristic_type,
                                  tile_name, trial_uuid)
    os.makedirs(bucket_dirname)

    landing_point_manager = PointManager(set(()), set(road_points))

    initial_cuts = Cuts(tree_points_arr, tree_points_kdtree, tree_weights_arr,
                        tree_basins_arr, landing_point_manager)
    initial_landings = Landings(landing_point_manager)

    landing_point_manager.subscribe_active_changes(
        initial_cuts.update_landings)

    for i in range(40):
        initial_landings.add_random_landing()

    initial_solution = Solution()
    initial_solution.add_component(initial_landings)
    initial_solution.add_component(initial_cuts)
コード例 #6
0
from flask import Flask, request
from point_manager import PointManager
from point import Point
import json

app = Flask(__name__)

POINTS_DB = 'points.sqlite'

point_mgr = PointManager(POINTS_DB)


@app.route('/points', methods=['POST'])
def add_point():
    """ Adds a point to the Grid """
    content = request.json

    try:
        point = Point(content['x'], content['y'])
        point_id = point_mgr.add_point(point)

        response = app.response_class(response=str(point_id), status=200)
    except ValueError as e:
        response = app.response_class(response=str(e), status=400)

    return response


@app.route('/points/<int:point_id>', methods=['PUT'])
def update_point(point_id):
    """ Updates an existing point in the Point Manager """