Beispiel #1
0
 def clear(self):
     """
     Removes all elements from the mapping of this Bundle.
     """
     self._keys = []
     self._format = ''
     self._itemsize = []
     self._parcel = Parcel()
     pass
Beispiel #2
0
    def test___add__2(self):
        """Check adding multiple parcels to the drone."""

        self.assertEqual(self.drone0.parcels, [])

        self.drone0 += [Parcel(0, Pos(10, 10), 5), Parcel(1, Pos(20, 20), 15)]

        self.assertEqual(len(self.drone0.parcels), 2)
        self.assertIsInstance(self.drone0.parcels[0], Parcel)
        self.assertIsInstance(self.drone0.parcels[1], Parcel)
        self.assertEqual(len(self.drone0.path), 4)
        self.assertEqual(self.drone0.path_length, 56.568542494923804)
Beispiel #3
0
    def setUp(self):
        """Prepare environment for testing."""

        self.drone0 = Drone(0, max_capacity=50, max_speed=10)  # Empty drone
        self.drone1 = Drone(1, max_capacity=140,
                            max_speed=8)  # Drone with parcels

        self.parcel1 = Parcel(1, Pos(1, 1), 10)
        self.parcel2 = Parcel(2, Pos(-20, -1), 5)

        self.drone1 += self.parcel1
        self.drone1 += self.parcel2
Beispiel #4
0
    def setUp(self):
        """Prepare environment for testing."""

        self.city = City(position=Pos(0, 0), wind=(1, 2), metric='simple')

        self.drone0 = Drone(0, max_capacity=50, max_speed=10)  # Empty drone
        self.drone1 = Drone(1, max_capacity=140,
                            max_speed=8)  # Drone with parcels

        self.parcel1 = Parcel(1, Pos(1, 1), 10)
        self.parcel2 = Parcel(2, Pos(-20, -1), 5)

        self.drone1 += self.parcel1
        self.drone1 += self.parcel2
    def test_deliver_parcel(self):
        handler = ParcelsHandler(Parcel.simple_builder())
        assert handler.claim_parcel("a-team", 142) is True
        assert len(handler.on_the_road_parcels) == 1

        assert handler.delivered("a-team", 142) is True
        assert len(handler.on_the_road_parcels) == 0
        assert len(handler.delivered_parcels) == 1
Beispiel #6
0
    def test_deliver_parcel(self):
        handler = ParcelsHandler(Parcel.simple_builder())
        assert handler.claim_parcel("a-team", 142) is True
        assert len(handler.on_the_road_parcels) == 1

        assert handler.delivered("a-team", 142) is True
        assert len(handler.on_the_road_parcels) == 0
        assert len(handler.delivered_parcels) == 1
Beispiel #7
0
    def test___add__(self):
        """Check adding a parcel to the drone."""

        self.assertEqual(self.drone0.parcels, [])

        self.drone0 += Parcel(0, Pos(10, 10), 50)

        self.assertEqual(len(self.drone0.parcels), 1)
        self.assertIsInstance(self.drone0.parcels[0], Parcel)
        self.assertEqual(len(self.drone0.path), 3)
        self.assertEqual(self.drone0.path_length, 28.284271247461902)
Beispiel #8
0
 def rload(self, raw_file_name):
     """Loads performance testing data from .txt file in raw format (used in test_tsp only)."""
     with open(os.path.join("test_TSP", "raw_test",
                            raw_file_name)) as raw_file:
         data = raw_file.read().strip('\n')
     self.solution = int(data.split('\n')[0])
     self.parcels = []
     for line in data.split('\n')[1:]:
         parcel_number, pos_x, pos_y = line.split(' ')
         self += Parcel(int(parcel_number), Pos(float(pos_x), float(pos_y)))
         self.position = Pos(float(pos_x),
                             float(pos_y))  # Base overlaps with last point.
Beispiel #9
0
 def cload(self, coord_file_name):
     """Loads data from GPS coordinates. The solutions are approximate due to conversion to
         xy coordinates (used in test_tsp only)."""
     with open(os.path.join("test_TSP", "coord_test",
                            coord_file_name)) as coord_file:
         data = coord_file.read().strip('\n')
     self.solution = int(data.split('\n')[0])
     self.parcels = []
     th0 = mean(float(line.split(' ')[1]) for line in data.split('\n')[1:])
     for line in data.split('\n')[1:]:
         parcel_number, pos_x, pos_y = self.convert(line, th0)
         self += Parcel(parcel_number, Pos(pos_x, pos_y))
         self.position = Pos(pos_x, pos_y)  # Base overlaps with last point.
Beispiel #10
0
 def jload(self, json_file_name):
     """Loads data from json .txt file stored in "test_json" folder."""
     # TODO Add full drone spec.
     with open(os.path.join("json_test", json_file_name)) as json_file:
         data = json.load(json_file)
     self.wind = tuple(data['wind'])
     self.position = Pos(data['position'][0], data['position'][1])
     self.parcels = []
     self.drones = []
     for parcel in data['parcels']:
         self += Parcel(parcel['number'], Pos(parcel['x'], parcel['y']),
                        parcel['weight'])
     for drone in data['drones']:
         self += Drone(drone['number'], drone['max_capacity'],
                       drone['max_speed'])
Beispiel #11
0
def parcelLister(fileName):
    """
    Based on the input file, compiles a list of Parcel objects complete with the corresponding attributes for each parcel
    Requires: input file is a text file in established format and fileName is a string with the name of the file.
    Ensures: returnal of a list with Parcel objects corresponding to the parcels found in the input files
    """
    inFile = open(fileName, "r")
    fileContent = inFile.readlines()
    fileContent = fileContent[7:]

    parcelList = []

    for line in fileContent:

        parcelDetails = line.strip().split(", ")
        parcelObject = Parcel(parcelDetails[0], parcelDetails[1],
                              parcelDetails[2], parcelDetails[3],
                              parcelDetails[4], parcelDetails[5],
                              parcelDetails[6])
        parcelList.append(parcelObject)

    return parcelList
Beispiel #12
0
 def test_Parcel_JSON(self):
     handler = ParcelsHandler(Parcel.simple_builder())
     json = handler.toJSON()
     assert '{"on_the_road_parcels": [], "delivered_parcels": [], "available_parcels": [[142, 1, 2], [145, 2, 3]]}' == json
Beispiel #13
0
import flask
from flask import jsonify, request, Response
from jsonpickle import json
from PenMap import PenMap
from Team import Team
from Parcel import Parcel, ParcelsHandler

app = flask.Flask(__name__)

#
# Model
#
teams = {}
robots_map = PenMap.simple_builder()
parcels_handler = ParcelsHandler(Parcel.simple_builder())
# end Model

@app.route("/")
def root():
    return Response(status=200)


@app.route("/robots/<team_id>", methods=['POST'])
def register_team(team_id):
    print "team_id %s" %team_id


    if teams.has_key(team_id):
        return "SORRY already registered!"
    else:
        # data = request.get_json(force=True)
Beispiel #14
0
 def test_Parcel_Builder(self):
     parcels = Parcel.simple_builder()
     assert len(parcels) == 2
Beispiel #15
0
PARCEL = {'amount': (50, 50), 'position': (-18_000, 18_000), 'weight': (0, 0)}

city = City(position=Pos(*CITY['position']), wind=CITY['wind'])

for drone_number in range(randint(*DRONE['amount'])):
    city += Drone(drone_number + 1,
                  base=city.position,
                  wind=CITY['wind'],
                  drone_mass=randint(*DRONE['mass']),
                  max_capacity=randint(*DRONE['capacity']),
                  max_speed=randint(*DRONE['speed']),
                  max_fuel=randint(*DRONE['fuel']),
                  base_fuel_consumption=uniform(*DRONE['consumption']),
                  altitude=randint(*DRONE['altitude']),
                  factor=uniform(*DRONE['factor']),
                  waiting_at_base=randint(*DRONE['waiting_at_base']),
                  waiting_at_client=randint(*DRONE['waiting_at_client']))

for parcel_number in range(randint(*PARCEL['amount'])):
    city += Parcel(
        parcel_number + 1,
        Pos(randint(*PARCEL['position']), randint(*PARCEL['position'])),
        uniform(*PARCEL['weight']))

# Testing?
city.full_simulated_annealing(iterations=10000,
                              initial_temperature=10,
                              final_temperature=0.0000001,
                              show_solution=False)
Beispiel #16
0
 def test_claim_parcel(self):
     handler = ParcelsHandler(Parcel.simple_builder())
     assert handler.claim_parcel("a-team", 142) is True
     assert handler.claim_parcel("a-team", 142) is False
     assert handler.claim_parcel("b-team", 142) is False
Beispiel #17
0
 def test_claim_parcel(self):
     handler = ParcelsHandler(Parcel.simple_builder())
     assert handler.claim_parcel("a-team", 142) is True
     assert handler.claim_parcel("a-team", 142) is False
     assert handler.claim_parcel("b-team", 142) is False
    arcpy.AddMessage("Adding Error Fields")
    arcpy.AddField_management(output_fc_temp, "GeneralElementErrors", "TEXT",
                              "", "", 1000)
    arcpy.AddField_management(output_fc_temp, "AddressElementErrors", "TEXT",
                              "", "", 1000)
    arcpy.AddField_management(output_fc_temp, "TaxrollElementErrors", "TEXT",
                              "", "", 1000)
    arcpy.AddField_management(output_fc_temp, "GeometricElementErrors", "TEXT",
                              "", "", 1000)

    #Create update cursor then use it to iterate through records in feature class
    arcpy.AddMessage("Testing the data for various attribute error types.")
    with arcpy.da.UpdateCursor(output_fc_temp, fieldNames) as cursor:
        for row in cursor:
            #Construct the Parcel object for the row
            currParcel = Parcel(row, fieldNames)

            #Execute in-cursor error tests
            totError, currParcel = Error.checkGeometricQuality(
                totError, currParcel, pinSkips)

            totError, currParcel = Error.checkNumericTextValue(
                totError, currParcel, "addnum", "address", True)
            totError, currParcel = Error.checkNumericTextValue(
                totError, currParcel, "parcelfips", "general", False)
            totError, currParcel = Error.checkNumericTextValue(
                totError, currParcel, "zipcode", "address", True)
            totError, currParcel = Error.checkNumericTextValue(
                totError, currParcel, "zip4", "address", True)
            totError, currParcel = Error.checkNumericTextValue(
                totError, currParcel, "cntassdvalue", "tax", True)
Beispiel #19
0
class BaseBundle(Android.Object):
    """
    A mapping from String keys to values of various types. In most cases, you 
    should work directly with either the Bundle or PersistableBundle subclass.
    """
    _fsuffixmap = {
        'b': 'Byte',
        '1': 'BooleanArray',
        'd': 'Double',
        '2': 'DoubleArray',
        'i': 'Int',
        '3': 'IntArray',
        'l': 'Long',
        '4': 'LongArray',
        's': 'String',
        '5': 'StringArray',
        'n': '',
    }

    def __init__(self, *args):
        super(BaseBundle, self).__init__(*args)
        self._keys = []
        self._format = ''
        self._itemsize = []
        self._parcel = Parcel()

    def _readtype(self, key, dtype, defaulvalue=None):
        try:
            npos = self._keys.index(key)
        except:
            pass
        else:
            vtype = self._format[npos]
            if dtype is None or vtype == dtype:
                fname = 'read' + self._fsuffixmap[vtype]
                func = getattr(self._parcel, fname)
                offset = sum(self._itemsize[:npos])
                self._parcel.setDataPosition(offset)
                if vtype == 'p':
                    return func(None)
                return func()
        return defaulvalue

    def _writetype(self, key, dtype, *value):
        if key is None: return
        self.remove(key)
        offset = self._parcel.dataSize()
        if value is None and dtype != 'p':
            if dtype.isdigit():
                dtype = 'n'
            else:
                raise Exception('None type not allowed')
        else:
            fname = 'write' + self._fsuffixmap[dtype]
            func = getattr(self._parcel, fname)
            self._parcel.setDataPosition(offset)
            func(*value)
        self._keys.append(key)
        self._itemsize.append(self._parcel.dataSize() - offset)
        self._format += dtype

    def clear(self):
        """
        Removes all elements from the mapping of this Bundle.
        """
        self._keys = []
        self._format = ''
        self._itemsize = []
        self._parcel = Parcel()
        pass

    def containsKey(self, key):
        """
        Returns true if the given key is contained in the mapping of this
        Bundle.
        :param key: String: a String key
        :return: boolean. true if the key is part of the mapping, false
        otherwise
        """
        return key in self._keys

    def get(self, key):
        """
        Returns the entry with the given key as an object.
        :param key: String: a String key
        :return: Object. an Object, or null
        """
        return self._readtype(key, None)

    def getBoolean(self, key, defaultValue=False):
        """
        Returns the value associated with the given key, or defaultValue if no
        mapping of the desired type exists for the given key.
        :param key: String: a String
        :param defaultValue: boolean: Value to return if key does not exist
        :return: boolean. a boolean value
        """
        return bool(self._readtype(key, 'b', defaultValue))

    def getBooleanArray(self, key):
        """
        Returns the value associated with the given key, or null if no mapping
        of the desired type exists for the given key or a null value is
        explicitly associated with the key.
        :param key: String: a String, or null
        :return: boolean[]. a boolean[] value, or null
        """
        return self._readtype(key, '1')

    def getDouble(self, key, defaultValue=0.0):
        """
        Returns the value associated with the given key, or defaultValue if no
        mapping of the desired type exists for the given key.
        :param key: String: a String
        :param defaultValue: double: Value to return if key does not exist
        :return: double. a double value
        """
        return self._readtype(key, 'd', defaultValue)

    def getDoubleArray(self, key):
        """
        Returns the value associated with the given key, or null if no mapping
        of the desired type exists for the given key or a null value is
        explicitly associated with the key.
        :param key: String: a String, or null
        :return: double[]. a double[] value, or null
        """
        return self._readtype(key, '2')

    def getInt(self, key, defaultValue=0):
        """
        Returns the value associated with the given key, or defaultValue if no
        mapping of the desired type exists for the given key.
        :param key: String: a String
        :param defaultValue: int: Value to return if key does not exist
        :return: int. an int value
        """
        return self._readtype(key, 'i', defaultValue)

    def getIntArray(self, key):
        """
        Returns the value associated with the given key, or null if no mapping
        of the desired type exists for the given key or a null value is
        explicitly associated with the key.
        :param key: String: a String, or null
        :return: int[]. an int[] value, or null
        """
        return self._readtype(key, '3')

    def getLong(self, key, defaultValue=0L):
        """
        Returns the value associated with the given key, or defaultValue if no
        mapping of the desired type exists for the given key.
        :param key: String: a String
        :param defaultValue: long: Value to return if key does not exist
        :return: long. a long value
        """
        return self._readtype(key, 'l', defaultValue)

    def getLongArray(self, key):
        """
        Returns the value associated with the given key, or null if no mapping
        of the desired type exists for the given key or a null value is
        explicitly associated with the key.
        :param key: String: a String, or null
        :return: long[]. a long[] value, or null
        """
        return self._readtype(key, '4')

    def getString(self, key, defaultValue=None):
        """
        Returns the value associated with the given key, or defaultValue if no
        mapping of the desired type exists for the given key or if a null
        value is explicitly associated with the given key.
        :param key: String: a String, or null
        :param defaultValue: String: Value to return if key does not exist or
        if a null value is associated with the given key.
        :return: String. the String value associated with the given key, or
        defaultValue if no valid String object is currently mapped to that key.
        """
        return self._readtype(key, 's', defaultValue)

    def getStringArray(self, key):
        """
        Returns the value associated with the given key, or null if no mapping
        of the desired type exists for the given key or a null value is
        explicitly associated with the key.
        :param key: String: a String, or null
        :return: String[]. a String[] value, or null
        """
        return self._readtype(key, '5')

    def isEmpty(self):
        """
        Returns true if the mapping of this Bundle is empty, false otherwise.
        :return: boolean.
        """
        return not bool(self.size())

    def keySet(self):
        """
        Returns a Set containing the Strings used as keys in this Bundle.
        :return: Set<String>. a Set of String keys
        """
        return set(self._keys)

    def putAll(self, bundle):
        """
        Inserts all mappings from the given PersistableBundle into this
        BaseBundle.
        :param bundle: PersistableBundle: a PersistableBundle
        """
        for k, key in enumerate(bundle._keys):
            self._writetype(key, bundle._format[k], bundle.get(key))

    def putBoolean(self, key, value):
        """
        Inserts a Boolean value into the mapping of this Bundle, replacing any
        existing value for the given key.  Either key or value may be null.
        :param key: String: a String, or null
        :param value: boolean: a boolean
        """
        self._writetype(key, 'b', value)

    def putBooleanArray(self, key, value):
        """
        Inserts a boolean array value into the mapping of this Bundle,
        replacing any existing value for the given key.  Either key or value
        may be null.
        :param key: String: a String, or null
        :param value: boolean: a boolean array object, or null
        """
        self._writetype(key, '1', value)

    def putDouble(self, key, value):
        """
        Inserts a double value into the mapping of this Bundle, replacing any
        existing value for the given key.
        :param key: String: a String, or null
        :param value: double: a double
        """
        self._writetype(key, 'd', value)

    def putDoubleArray(self, key, value):
        """
        Inserts a double array value into the mapping of this Bundle,
        replacing any existing value for the given key.  Either key or value
        may be null.
        :param key: String: a String, or null
        :param value: double: a double array object, or null
        """
        self._writetype(key, '2', value)

    def putInt(self, key, value):
        """
        Inserts an int value into the mapping of this Bundle, replacing any
        existing value for the given key.
        :param key: String: a String, or null
        :param value: int: an int
        """
        self._writetype(key, 'i', value)

    def putIntArray(self, key, value):
        """
        Inserts an int array value into the mapping of this Bundle, replacing
        any existing value for the given key.  Either key or value may be null.
        :param key: String: a String, or null
        :param value: int: an int array object, or null
        """
        self._writetype(key, '3', value)

    def putLong(self, key, value):
        """
        Inserts a long value into the mapping of this Bundle, replacing any
        existing value for the given key.
        :param key: String: a String, or null
        :param value: long: a long
        """
        self._writetype(key, 'l', value)

    def putLongArray(self, key, value):
        """
        Inserts a long array value into the mapping of this Bundle, replacing
        any existing value for the given key.  Either key or value may be null.
        :param key: String: a String, or null
        :param value: long: a long array object, or null
        """
        self._writetype(key, '4', value)

    def putString(self, key, value):
        """
        Inserts a String value into the mapping of this Bundle, replacing any
        existing value for the given key.  Either key or value may be null.
        :param key: String: a String, or null
        :param value: String: a String, or null
        """
        self._writetype(key, 's', value)

    def putStringArray(self, key, value):
        """
        Inserts a String array value into the mapping of this Bundle,
        replacing any existing value for the given key.  Either key or value
        may be null.
        :param key: String: a String, or null
        :param value: String: a String array object, or null
        """
        self._writetype(key, '5', value)

    def remove(self, key):
        """
        Removes any entry with the given key from the mapping of this Bundle.
        :param key: String: a String key
        """
        if not self.containsKey(key): return
        npos = self._keys.index(key)
        buffer = self._parcel.marshall()
        offset = sum(self._itemsize[:npos])
        size = self._itemsize[npos]
        length = self._parcel.dataSize() - offset - size
        self._parcel.setDataPosition(offset)
        self._parcel.appendFrom(self._parcel, offset + size, length)
        self._format = self._format[:npos] + self._format[npos + 1:]
        self._keys = self._keys[:npos] + self._keys[npos + 1:]
        self._itemsize = self._itemsize[:npos] + self._itemsize[npos + 1:]

    def size(self):
        """
        Returns the number of mappings contained in this Bundle.
        :return: int. the number of mappings as an int.
        """
        return len(self._keys)

    def equals(self, obj):
        npos = self._parcel.dataSize()
        return self._keys == obj._keys and \
               self._format == obj._format and \
               self._itemsize == obj._itemsize and \
               self._parcel._buffer[:npos] == obj._parcel._buffer[:npos]
Beispiel #20
0
 def test_Parcel_Builder(self):
     parcels = Parcel.simple_builder()
     assert len(parcels) == 2
Beispiel #21
0
 def __init__(self, *args):
     super(BaseBundle, self).__init__(*args)
     self._keys = []
     self._format = ''
     self._itemsize = []
     self._parcel = Parcel()
Beispiel #22
0
import flask
from flask import jsonify, request, Response
from jsonpickle import json
from PenMap import PenMap
from Team import Team
from Parcel import Parcel, ParcelsHandler

app = flask.Flask(__name__)

#
# Model
#
teams = {}
robots_map = PenMap.simple_builder()
parcels_handler = ParcelsHandler(Parcel.simple_builder())
# end Model

@app.route("/")
def root():
    return Response(status=200)


@app.route("/robots/<team_id>", methods=['POST'])
def register_team(team_id):
    print "team_id %s" %team_id


    if teams.has_key(team_id):
        return "SORRY already registered!"
    else:
        # data = request.get_json(force=True)
Beispiel #23
0
 def test_Parcel_JSON(self):
     handler = ParcelsHandler(Parcel.simple_builder())
     json = handler.toJSON()
     assert '{"on_the_road_parcels": [], "delivered_parcels": [], "available_parcels": [[142, 1, 2], [145, 2, 3]]}' == json
def runStatsOn(countyName):

    #dictionary for V3 completeness collection
    v3CompDict = {
        'STATEID': 0,
        'PARCELID': 0,
        'TAXPARCELID': 0,
        'PARCELDATE': 0,
        'TAXROLLYEAR': 0,
        'OWNERNME1': 0,
        'OWNERNME2': 0,
        'PSTLADRESS': 0,
        'SITEADRESS': 0,
        'ADDNUMPREFIX': 0,
        'ADDNUM': 0,
        'ADDNUMSUFFIX': 0,
        'PREFIX': 0,
        'STREETNAME': 0,
        'STREETTYPE': 0,
        'SUFFIX': 0,
        'LANDMARKNAME': 0,
        'UNITTYPE': 0,
        'UNITID': 0,
        'PLACENAME': 0,
        'ZIPCODE': 0,
        'ZIP4': 0,
        'STATE': 0,
        'SCHOOLDIST': 0,
        'SCHOOLDISTNO': 0,
        'IMPROVED': 0,
        'CNTASSDVALUE': 0,
        'LNDVALUE': 0,
        'IMPVALUE': 0,
        'FORESTVALUE': 0,
        'ESTFMKVALUE': 0,
        'NETPRPTA': 0,
        'GRSPRPTA': 0,
        'PROPCLASS': 0,
        'AUXCLASS': 0,
        'ASSDACRES': 0,
        'DEEDACRES': 0,
        'GISACRES': 0,
        'CONAME': 0,
        'LOADDATE': 0,
        'PARCELFIPS': 0,
        'PARCELSRC': 0,
    }

    #Copy feature class, add new fields for error reporting
    arcpy.AddMessage("Writing to memory using the following parameters:")
    output_fc_temp = os.path.join("in_memory", "WORKING")
    arcpy.AddMessage("Output path: " + output_fc_temp)
    arcpy.Delete_management("in_memory")
    dynamic_workspace = "in_memory"
    expression = "CONAME = '" + countyName + "'"
    arcpy.AddMessage("Query expression: " + expression)
    # Execute FeatureClassToFeatureClass
    arcpy.FeatureClassToFeatureClass_conversion(in_fc, dynamic_workspace,
                                                "WORKING", expression)

    #Run primary checks
    totError = Error(output_fc_temp, countyName)

    # Fields that we do not need to collect summary stats on
    fieldListPass = [
        "OID", "OID@", "SHAPE", "SHAPE@", "SHAPE_LENGTH", "SHAPE_AREA",
        "SHAPE_XY", "SHAPE@LENGTH", "SHAPE@AREA", "SHAPE@XY",
        "GENERALELEMENTERRORS", "ADDRESSELEMENTERRORS", "TAXROLLELEMENTERRORS",
        "GEOMETRICELEMENTERRORS"
    ]

    #Adding new fields for error reporting.  We can change names, lenght, etc... (need to keep these, BUT SETTING THEIR LENGTH TO 1)
    arcpy.AddMessage("Adding Error Fields")
    arcpy.AddField_management(output_fc_temp, "GeneralElementErrors", "TEXT",
                              "", "", 1)
    arcpy.AddField_management(output_fc_temp, "AddressElementErrors", "TEXT",
                              "", "", 1)
    arcpy.AddField_management(output_fc_temp, "TaxrollElementErrors", "TEXT",
                              "", "", 1)
    arcpy.AddField_management(output_fc_temp, "GeometricElementErrors", "TEXT",
                              "", "", 1)

    #Create update cursor then use it to iterate through records in feature class
    arcpy.AddMessage("Testing the data for field completeness (" + countyName +
                     " COUNTY)")
    with arcpy.da.UpdateCursor(output_fc_temp, fieldNames) as cursor:
        for row in cursor:
            #Construct the Parcel object for the row
            currParcel = Parcel(row, fieldNames)
            #compile completeness stats via the Error class function
            totError, currParcel = Error.fieldCompleteness(
                totError, currParcel, fieldNames, fieldListPass, v3CompDict)
            #End of loop, clear parcel
            currParcel = None
    # Create a .csv and then write the dictionary to it
    fd = open(os.path.join(outDirTxt, outName + ".py"), 'a')
    statString = (
        (countyName.replace(" ", "_")) + "LegacyDict = ") + str(v3CompDict)
    fd.write(statString + '\n')
    fd.close()
    # testing code for validation tool (converting string back into usable dict):
    '''statArray = statString.split("|")
	reincarnatedString = (statArray[1].replace("'",'"'))
	reincarnatedCounty = (statArray[0])
	reincarnatedDict = json.loads(reincarnatedString) # REQUIRES import json
	for value in reincarnatedDict:
			arcpy.AddMessage(reincarnatedCounty )
			arcpy.AddMessage(value)
			arcpy.AddMessage(reincarnatedDict[value])'''
    # Clear memory to free up space for other county processing
    arcpy.Delete_management("in_memory")
Beispiel #25
0
"""Testing purposes."""

from random import shuffle

from City import City
from common import Position as Pos
from Drone import Drone
from Parcel import Parcel

# City creation
city = City(position=Pos(0, 0), wind=(1, 2))

city += Drone(1, 24000, 10)

parcels = []

n = 1
for i in range(-40, 50, 10):
    for j in range(-40, 50, 10):
        if i != 0 or j != 0:
            parcels.append(Parcel(n, 10, Pos(i, j)))
            n += 1

shuffle(parcels)

city += parcels

city.store("grid.txt")