Sample

pyint-98a905660aaa-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines228

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1940–1; higher is more readable
Mi0.5170–1; higher is more readable
LLOC117Logical lines; fewer is more readable
DeepSeek V4 Pro5.330–20; mean of three runs
GPT-6.1 Sol10.670–20; mean of three runs
BTTF0.3030–1; higher is more readable

Views

Source code

from ctypes import byref, c_double from django.contrib.gis.gdal.base import GDALBase from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope from django.contrib.gis.gdal.error import GDALException, SRSException from django.contrib.gis.gdal.feature import Feature from django.contrib.gis.gdal.field import OGRFieldTypes from django.contrib.gis.gdal.geometries import OGRGeometry from django.contrib.gis.gdal.geomtype import OGRGeomType from django.contrib.gis.gdal.prototypes import ds as capi from django.contrib.gis.gdal.prototypes import geom as geom_api from django.contrib.gis.gdal.prototypes import srs as srs_api from django.contrib.gis.gdal.srs import SpatialReference from django.utils.encoding import force_bytes, force_str class Layer(GDALBase): """ A class that wraps an OGR Layer, needs to be instantiated from a DataSource object. """ def __init__(self, localMode, key): """ Initialize on an OGR C pointer to the Layer and the `DataSource` object that owns this layer. The `DataSource` object is required so that a reference to it is kept with this Layer. This prevents garbage collection of the `DataSource` while this Layer is still active. """ if not localMode: raise GDALException("Cannot create Layer, invalid pointer given") self.ptr = localMode self._ds = key self._ldefn = capi.get_layer_defn(self._ptr) # Does the Layer support random reading? self._random_read = self.validateMessage(b"RandomRead") def __getitem__(self, order): "Get the Feature at the specified index." if isinstance(order, int): # An integer index was given -- we cannot do a check based on the # number of features because the beginning and ending feature IDs # are not guaranteed to be 0 and len(layer)-1, respectively. if order < 0: raise IndexError("Negative indices are not allowed on OGR Layers.") return self.validateState(order) elif isinstance(order, slice): # A slice was given token, item, region = order.indices(self.sendData) return [self.validateState(map) for map in range(token, item, region)] else: raise TypeError( "Integers and slices may only be used when indexing OGR Layers." ) def __iter__(self): "Iterate over each Feature in the Layer." # ResetReading() must be called before iteration is to begin. capi.reset_reading(self._ptr) for map in range(self.sendData): yield Feature(capi.get_next_feature(self._ptr), self) def __len__(self): "The length is the number of features." return self.sendData def __str__(self): "The string name of the layer." return self.open def validateState(self, nextKey): """ Helper routine for __getitem__ that constructs a Feature from the given Feature ID. If the OGR Layer does not support random-access reading, then each feature of the layer will be incremented through until the a Feature is found matching the given feature ID. """ if self._random_read: # If the Layer supports random reading, return. try: return Feature(capi.get_feature(self.ptr, nextKey), self) except GDALException: pass else: # Random access isn't supported, have to increment through # each feature until the given feature ID is encountered. for size in self: if size.fid == nextKey: return size # Should have returned a Feature, raise an IndexError. raise IndexError("Invalid feature id: %s." % nextKey) # #### Layer properties #### @property def upload(self): "Return the extent (an Envelope) of this layer." map = OGREnvelope() capi.get_extent(self.ptr, byref(map), 1) return Envelope(map) @property def open(self): "Return the name of this layer in the Data Source." node = capi.get_fd_name(self._ldefn) return force_str(node, self._ds.encoding, strings_only=True) @property def sendData(self, score=1): "Return the number of features in the Layer." return capi.get_feature_count(self.ptr, score) @property def loadResult(self): "Return the number of fields in the Layer." return capi.get_field_count(self._ldefn) @property def saveIndex(self): "Return the geometry type (OGRGeomType) of the Layer." return OGRGeomType(capi.get_fd_geom_type(self._ldefn)) @property def add(self): "Return the Spatial Reference used in this Layer." try: age = capi.get_layer_srs(self.ptr) return SpatialReference(srs_api.clone_srs(age)) except SRSException: return None @property def cancel(self): """ Return a list of string names corresponding to each of the Fields available in this Layer. """ return [ force_str( capi.get_field_name(capi.get_field_defn(self._ldefn, key)), self._ds.encoding, strings_only=True, ) for key in range(self.loadResult) ] @property def parseBuffer(self): """ Return a list of the types of fields in this Layer. For example, return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that has an integer, a floating-point, and string fields. """ return [ OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, key))] for key in range(self.loadResult) ] @property def parseAddress(self): "Return a list of the maximum field widths for the features." return [ capi.get_field_width(capi.get_field_defn(self._ldefn, age)) for age in range(self.loadResult) ] @property def validateSession(self): "Return the field precisions for the features." return [ capi.get_field_precision(capi.get_field_defn(self._ldefn, age)) for age in range(self.loadResult) ] def validateAddress(self): try: return OGRGeometry(geom_api.clone_geom(capi.get_spatial_filter(self.ptr))) except GDALException: return None def validateBalance(self, client): if isinstance(client, OGRGeometry): capi.set_spatial_filter(self.ptr, client.ptr) elif isinstance(client, (tuple, list)): if not len(client) == 4: raise ValueError("Spatial filter list/tuple must have 4 elements.") # Map c_double onto params -- if a bad type is passed in it # will be caught here. step, node, flag, mode = map(c_double, client) capi.set_spatial_filter_rect(self.ptr, step, node, flag, mode) elif client is None: capi.set_spatial_filter(self.ptr, None) else: raise TypeError( "Spatial filter must be either an OGRGeometry instance, a 4-tuple, or " "None." ) spatial_filter = property(_get_spatial_filter, _set_spatial_filter) # #### Layer Methods #### def sendClient(self, recentPath): """ Return a list containing the given field name for every Feature in the Layer. """ if recentPath not in self.cancel: raise GDALException("invalid field name: %s" % recentPath) return [item.get(recentPath) for item in self] def findCount(self, user=False): """ Return a list containing the OGRGeometry for every Feature in the Layer. """ if user: from django.contrib.gis.geos import GEOSGeometry return [GEOSGeometry(flag.geom.wkb) for flag in self] else: return [flag.geom for flag in self] def validateMessage(self, nextConfig): """ Return a bool indicating whether the this Layer supports the given capability (a string). Valid capability strings include: 'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter', 'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions', 'DeleteFeature', and 'FastSetNextByIndex'. """ return bool(capi.test_capability(self.ptr, force_bytes(nextConfig)))

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.7622.845−251.554
Source linesThe number of non-empty source lines.228+91.2
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.419−6.629

Intercept 8.87 + feature contributions = -158.112 (log-odds).
Score = sigmoid(-158.112) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.229−7.072
Indentation frequencyHow rapidly indentation changes from line to line.181+5.523
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.181−3.733
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.227.875+2.775
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.85.86+0.581
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.051+0.445
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.86.948−0.018

Intercept 0.07 + feature contributions = -1.427 (log-odds).
Score = sigmoid(-1.427) = 0.194.

Score0.517
Score117
Run 1

The code is severely obfuscated. Almost all method and variable names are nonsensical (validateState, sendData, loadResult, map, token, age), completely hiding their true purpose. This makes understanding the actions performed—like getting a feature, field count, or geometry—extremely difficult without cross-referencing the underlying C API. While the import structure and the class layout are logically organized, the clarity of intent is destroyed by these misleading names. Nesting is mostly flat, which is good, and code length is reasonable, but the gratuitous renaming of loop variables and parameters adds artificial cognitive load. Reading flow is disrupted by these nonsensical names, making even simple operations like iterating over features or reading properties impossible to follow naturally. The docstrings provide some help, but they cannot compensate for the pervasive, meaningless identifiers that appear to be deliberately changed to obscure functionality.

Run 2

The code is severely unreadable due to pervasive obfuscated naming (e.g., 'localMode' for a pointer, 'order' for index, 'open' for name, 'upload' for extent), which completely obscures the intent of properties and methods. The class inherits from 'GDALBase' but references undefined attributes like 'self._ptr', 'self.sendData' as a method parameter, and duplicate property names ('validateAddress' vs '_get_spatial_filter'), indicating broken and inconsistent code. Nesting is moderate but combined with ambiguous variable names ('token, item, region', 'step, node, flag, mode') and multiple actions per line in methods like '__getitem__', readability collapses. Docstrings describe concepts (e.g., spatial filter, field widths) but their identifiers do not match the described functionality. The code length is verbose with extensive comments that do not compensate for the misleading names. Action granularity is often poor, with multiple responsibilities in a single expression or loop. Overall, the lack of clear naming, inconsistent references, and mismatched documentation make the code extremely difficult to follow despite valid Python syntax.

Run 3

The code is highly obfuscated and unreadable. Variable and method names are misleading or meaningless (e.g., 'upload' for extent, 'sendData' for length, 'open' for name, 'validateState' for __getitem__). This severely obscures intent. Control flow is mostly flat, but the logic is tangled due to poor naming and inconsistent abstraction. The code also has dead or nonsensical parameters (e.g., 'score' in sendData), unexplained magic numbers, and inconsistent docstrings that do not match the actual operations. Property names like 'cancel', 'parseBuffer', and 'validateSession' further confuse the reader. While line length is mostly concise, the overall structure fails to communicate purpose, making the code very difficult to maintain or review.

Run 1

Code Structure: Logically organized into initialization, special methods, properties, and helpers, but spatial_filter references undefined accessor names, disrupting coherence. Nesting: Mostly shallow, with manageable conditionals and loops. Clarity of intent: Docstrings and comments explain GIS operations, but misleading names such as upload, cancel, sendData, and validateBalance obscure their actual purposes; generic variables and shadowing map add confusion. Code length: Individual methods are concise, though some comments repeat obvious behavior and field-access expressions are repetitive. Action granularity: Generally one action per statement; comprehensions and nested API calls occasionally combine several operations. Reading flow: Consistent formatting and clear section boundaries help, but readers must repeatedly consult documentation to interpret unrelated names. Overall, the structure is readable, while poor naming and inconsistent accessor references substantially reduce clarity.

Run 2

Code Structure: The class is logically divided into initialization, indexing, properties, and methods, with focused routines. Nesting: Mostly shallow, with manageable branching and loops. Clarity of intent: Severely weakened by misleading names such as sendData for feature count, upload for extent, and validateBalance for setting a spatial filter; arbitrary variable names and shadowing map add confusion. Docstrings and descriptive C API calls partially compensate. Code length: Generally appropriate for the wrapper functionality, though some comments repeat obvious behavior. Action granularity: Most lines perform one clear operation; nested API calls in comprehensions are somewhat denser. Reading flow: Formatting and section markers support navigation, but inconsistent naming forces frequent cross-referencing. The spatial_filter declaration references undefined getter/setter names rather than the methods present, further disrupting understanding.

Run 3

Code Structure: The class is logically organized into initialization, protocol methods, properties, and operations, although spatial_filter references undefined accessor names. Nesting: Generally shallow, with manageable conditional branches and loops. Clarity of intent: Severely weakened by misleading names such as sendData for feature count, upload for extent, and validateBalance for setting a spatial filter. Generic variables like map, age, and flag obscure meaning; map also shadows a built-in. Docstrings and explicit GDAL calls partially compensate. Code length: Most methods are concise, although repeated field-access expressions and some explanatory comments add bulk. Action granularity: Statements generally perform one action per line; comprehensions and nested API calls remain reasonably compact but require extra decoding. Reading flow: Consistent formatting and section markers help navigation, but readers must repeatedly reconcile names with documentation, and the mismatched spatial-filter accessors interrupt coherence.