Skip to content

Commit

Permalink
various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
couteau committed Jan 28, 2025
1 parent 4c42d85 commit b603701
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion redistricting/services/basebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def removePopField(self, field) -> Self:
self._popFields.remove(field)
return self

def setDataFields(self, dataFields: list[RdsDataField]):
def setDataFields(self, dataFields: list[RdsDataField]) -> Self:
l = []
for f in dataFields:
if not self._checkNotDuplicate(f, l):
Expand Down
2 changes: 1 addition & 1 deletion redistricting/services/district.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, parent: Optional[QObject] = None):

def updateDistrictData(self, plan: "RdsPlan", data: Union[pd.DataFrame, gpd.GeoDataFrame]):
for district, row in data.to_dict(orient="index").items():
plan.districts[district].update(row)
plan.districts[f"{district:04}"].update(row)

def updateMetrics(self, plan: "RdsPlan", totalPopulation: int, cutEdges: int, splitsData: dict[str, pd.DataFrame]):
plan.updateMetrics(totalPopulation, cutEdges, splitsData)
Expand Down
7 changes: 4 additions & 3 deletions redistricting/services/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,15 @@ def createLabels(self):
self._labeling = QgsVectorLayerSimpleLabeling(layerSettings)

def createRenderers(self, numDistricts):
self._numDistricts = max(self._numDistricts, numDistricts)
if self._ramp:
self._ramp.setCount(numDistricts+1)
if self._numDistricts >= self._ramp.count():
self._ramp.setCount(self._numDistricts+1)
else:
self._ramp = QgsLimitedRandomColorRamp(count=numDistricts+1, satMin=50, satMax=100)
self._ramp = QgsLimitedRandomColorRamp(count=self._numDistricts+1, satMin=50, satMax=100)

self.createAssignmentRenderer(numDistricts)
self.createDistrictRenderer(numDistricts)
self._numDistricts = numDistricts

def createAssignmentRenderer(self, numDistricts: int):
symbol: QgsFillSymbol = QgsSymbol.defaultSymbol(DISTRICT_GEOMETRY_TYPE)
Expand Down
2 changes: 1 addition & 1 deletion redistricting/services/tasks/updatepending.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def checkCanceled():
new = pd.DataFrame(0, index=data.index.difference(dist.index), columns=dist.columns)
if len(new) > 0:
dist = pd.concat([dist, new])
members = [self.districts[d].members for d in dist.index]
members = [self.districts[f"{d:04}"].members for d in dist.index]
dist["members"] = members

data[f"new_{DistrictColumns.POPULATION}"] = dist[DistrictColumns.POPULATION] + \
Expand Down

0 comments on commit b603701

Please sign in to comment.