Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fs/jquinn (Sourcery refactored) #42

Closed
wants to merge 1 commit into from
Closed

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Dec 31, 2022

Pull Request #41 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the fs/jquinn branch, then run:

git fetch origin sourcery/fs/jquinn
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from fsargent December 31, 2022 19:17
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 31, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.32%.

Quality metrics Before After Change
Complexity 26.79 😞 25.57 😞 -1.22 👍
Method Length 85.75 🙂 85.29 🙂 -0.46 👍
Working memory 10.84 😞 10.81 😞 -0.03 👍
Quality 51.43% 🙂 51.75% 🙂 0.32% 👍
Other metrics Before After Change
Lines 3586 3551 -35
Changed files Quality Before Quality After Quality Change
dataClasses.py 77.39% ⭐ 77.44% ⭐ 0.05% 👍
methods.py 43.57% 😞 44.18% 😞 0.61% 👍
stratFunctions.py 88.25% ⭐ 90.12% ⭐ 1.87% 👍
voterModels.py 75.19% ⭐ 75.19% ⭐ 0.00%
vse.py 25.94% 😞 25.87% 😞 -0.07% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
methods.py V321.stratBallotFor 52 ⛔ 469 ⛔ 5.23% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
vse.py threeRoundResults 39 ⛔ 1126 ⛔ 34 ⛔ 6.32% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
methods.py makeSTARMethod 157 ⛔ 1284 ⛔ 16 ⛔ 7.41% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
methods.py makeScoreMethod 54 ⛔ 829 ⛔ 15 😞 11.06% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
methods.py V321.results 11 🙂 342 ⛔ 16 ⛔ 32.45% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@sourcery-ai sourcery-ai bot force-pushed the sourcery/fs/jquinn branch from 5b9b687 to d8b1513 Compare December 31, 2022 19:22
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

for i in range(niter):
for _ in range(niter):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function stratStats refactored with the following changes:

pollErrors = [random.gauss(0, pollingError/2) for i in range(numCands)]
pollErrors = [random.gauss(0, pollingError/2) for _ in range(numCands)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function influentialBlocs refactored with the following changes:

self.mNames = [m[0].__name__ + ':' + m[1].__name__ + str(m[2]) for m in ms]
self.mNames = [f'{m[0].__name__}:{m[1].__name__}{str(m[2])}' for m in ms]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CID.__init__ refactored with the following changes:

Comment on lines -236 to +239
incentFracts = {re.match(".*(?=:)", name).group(0): data for name, data in incentFracts.items()}
incentFracts = {
re.match(".*(?=:)", name)[0]: data
for name, data in incentFracts.items()
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CID.chart refactored with the following changes:

Comment on lines -261 to +274
myFile = open(baseName + (str(i) if newFile else "") + ".csv", "w")
dw = csv.DictWriter(myFile, fields, restval="data missing")
dw.writeheader()
for outcome, index in resultTypeIndices.items():
for name, results in self.summarize()[index].items():
row = {'name': name, 'baseResult': outcome}
row.update({i: result for i, result in enumerate(results)})
row.update(universalInfo)
dw.writerow(row)
myFile.close()
with open(baseName + (str(i) if newFile else "") + ".csv", "w") as myFile:
dw = csv.DictWriter(myFile, fields, restval="data missing")
dw.writeheader()
for outcome, index in resultTypeIndices.items():
for name, results in self.summarize()[index].items():
row = (
{'name': name, 'baseResult': outcome}
| enumerate(results)
| universalInfo
)
dw.writerow(row)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CID.saveFile refactored with the following changes:

Comment on lines -366 to +488
results = {c: kw.get(c, None) for c in resultColumns}
results.update(kw)
return results
return {c: kw.get(c, None) for c in resultColumns} | kw
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeResults refactored with the following changes:

Comment on lines -533 to +705
if False and len(polls) < 6:
return tieFor2Probs(polls, uncertainty)
else:
return tieFor2Estimate(tuple(pollsToProbs(polls, uncertainty)))
return tieFor2Estimate(tuple(pollsToProbs(polls, uncertainty)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function adaptiveTieFor2 refactored with the following changes:

dataClasses.py Outdated
Comment on lines 554 to 723
print("# " + str(globalComment),
#dict(
#media=self.media.__name__,
# version=self.repo_version,
# seed=self.seed,
## model=self.model,
# methods=self.methods,
# nvot=self.nvot,
# ncand=self.ncand,
# niter=self.niter)),
file=myFile)
print(f"# {str(globalComment)}", file=myFile)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function appendResults refactored with the following changes:

This removes the following comments ( why? ):

#media=self.media.__name__,
#              niter=self.niter)),
#dict(
##              model=self.model,
#              nvot=self.nvot,
#              version=self.repo_version,
#              seed=self.seed,
#              methods=self.methods,
#              ncand=self.ncand,

Comment on lines -263 to +312
Top2Version.__name__ = noRunoffMethod.__name__ + "Top2"
Top2Version.__name__ = f"{noRunoffMethod.__name__}Top2"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function top2 refactored with the following changes:

methods.py Outdated
Comment on lines 294 to 350



Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeScoreMethod refactored with the following changes:

methods.py Outdated
Comment on lines 524 to 647
expectedUtility = sum(u for u in utils)/len(utils)
expectedUtility = sum(utils) / len(utils)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Approval.zeroInfoBallot refactored with the following changes:

methods.py Outdated
Comment on lines 653 to 812
#minF, maxF = min(winner, runnerUp), max(winner, runnerUp)
#thirdProbs = pollsToProbs(
#electabilities[:minF] + electabilities[minF+1:maxF] + electabilities[maxF+1:], pollingUncertainty)
for third in range(nCands):
if third == winner or third == runnerUp:
if third in [winner, runnerUp]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getCoefficients refactored with the following changes:

This removes the following comments ( why? ):

#thirdProbs = pollsToProbs(
#electabilities[:minF] + electabilities[minF+1:maxF] + electabilities[maxF+1:], pollingUncertainty)
#minF, maxF = min(winner, runnerUp), max(winner, runnerUp)

Comment on lines 680 to +860


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeSTARMethod refactored with the following changes:

Comment on lines -1000 to +1209
def candScore(self, scores):
def candScore(cls, scores):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Mav.candScore refactored with the following changes:

methods.py Outdated
Comment on lines 1076 to 1066
((frontId,frontResult), (targId, targResult)) = places[0:2]
((frontId,frontResult), (targId, targResult)) = places[:2]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Mav.stratBallot refactored with the following changes:

Comment on lines -2035 to +2391
matchupWins = [sum(1 for marg in row if marg > 0) for row in cmat]
matchupWins = [sum(marg > 0 for marg in row) for row in cmat]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RankedRobin.results refactored with the following changes:

Comment on lines -2192 to +2593
for i, b in enumerate(ballots):
for b in ballots:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ITRV.results refactored with the following changes:

@@ -2,6 +2,7 @@
from methods import *

def makeBlock(method):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeBlock refactored with the following changes:

Comment on lines -102 to +105
scoreSupport = 0
for ballot in ballots:
if ballot[winner] == score:
scoreSupport += ballot.weight
scoreSupport = sum(
ballot.weight for ballot in ballots if ballot[winner] == score
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AllocatedScore.reweight refactored with the following changes:

if upset > 0:
return runnerUp
else: return top
return runnerUp if upset > 0 else top
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ASFinalRunoff.pickWinner refactored with the following changes:

Comment on lines -278 to +276
if upset > 0:
return runnerUp
else: return top
return runnerUp if upset > 0 else top
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ASRunoffs.pickWinner refactored with the following changes:

Comment on lines -322 to +319
else:
scores = [sum(ballot[c]*ballot.weight for ballot in ballots) if c in bestCands else -1 for c in range(ncand)]
return scores.index(max(scores))
scores = [sum(ballot[c]*ballot.weight for ballot in ballots) if c in bestCands else -1 for c in range(ncand)]
return scores.index(max(scores))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SequentialMonroe.pickWinner refactored with the following changes:

Comment on lines -355 to +354
scoreSupport = 0
for ballot in ballots:
if ballot[winner] == score:
scoreSupport += score*ballot.weight
scoreSupport = sum(
score * ballot.weight
for ballot in ballots
if ballot[winner] == score
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function S5H.reweight refactored with the following changes:

Comment on lines -443 to +444
piles = [[] for i in range(nCands)]
piles = [[] for _ in range(nCands)]
while len(winners) + len(candsLeft) > numWinners:
cls.resort(ballotsToSort, candsLeft, piles)
newWinners = [c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota]
if newWinners:
if newWinners := [
c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota
]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function STV.winnerSet refactored with the following changes:

Comment on lines -484 to +485
piles = [[] for i in range(nCands)]
piles = [[] for _ in range(nCands)]
while len(winners) < numWinners - 1 and len(winners) + len(candsLeft) > numWinners - 1:
cls.resort(ballotsToSort, candsLeft, piles)
newWinners = [c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota][:max(0, numWinners-len(winners)-1)]
if newWinners:
if newWinners := [
c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota
][: max(0, numWinners - len(winners) - 1)]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MinimaxSTV.winnerSet refactored with the following changes:

Comment on lines -64 to +65
if callable(biaser):
bias = biaser(standings)
else:
bias = biaser
result= (standings[0:2] +
[(standing - bias + numerator * (bias / max(i+2, 1)))
for i, standing in enumerate(standings[2:])])
bias = biaser(standings) if callable(biaser) else biaser
result = standings[:2] + [
(standing - bias + numerator * (bias / max(i + 2, 1)))
for i, standing in enumerate(standings[2:])
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function biasedMediaFor refactored with the following changes:

Comment on lines -82 to +77
if callable(biaser):
bias = biaser(standings)
else:
bias = biaser
bias = biaser(standings) if callable(biaser) else biaser
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function skewedMediaFor refactored with the following changes:

if caring==None:
if caring is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DimVoter.fromDims refactored with the following changes:

Comment on lines -367 to +372
subclusterMeans.append([random.gauss(0,sqrt(cares)) for i in range(self.dimsPerView[c])])
subclusterMeans.append(
[
random.gauss(0, sqrt(cares))
for _ in range(self.dimsPerView[c])
]
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function KSElectorate.chooseClusters refactored with the following changes:

Comment on lines +77 to +78
fgHelped = []
fgHarmed = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function threeRoundResults refactored with the following changes:

This removes the following comments ( why? ):

#If not I should be quitting earlier than this but easier to just fake it.
#zero-sized foreground

@sourcery-ai sourcery-ai bot force-pushed the sourcery/fs/jquinn branch from d8b1513 to 278cea6 Compare December 31, 2022 23:19
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

for i in range(niter):
for _ in range(niter):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function stratStats refactored with the following changes:

pollErrors = [random.gauss(0, pollingError/2) for i in range(numCands)]
pollErrors = [random.gauss(0, pollingError/2) for _ in range(numCands)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function influentialBlocs refactored with the following changes:

self.mNames = [m[0].__name__ + ':' + m[1].__name__ + str(m[2]) for m in ms]
self.mNames = [f'{m[0].__name__}:{m[1].__name__}{str(m[2])}' for m in ms]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CID.__init__ refactored with the following changes:

Comment on lines -236 to +239
incentFracts = {re.match(".*(?=:)", name).group(0): data for name, data in incentFracts.items()}
incentFracts = {
re.match(".*(?=:)", name)[0]: data
for name, data in incentFracts.items()
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CID.chart refactored with the following changes:

Comment on lines -261 to +274
myFile = open(baseName + (str(i) if newFile else "") + ".csv", "w")
dw = csv.DictWriter(myFile, fields, restval="data missing")
dw.writeheader()
for outcome, index in resultTypeIndices.items():
for name, results in self.summarize()[index].items():
row = {'name': name, 'baseResult': outcome}
row.update({i: result for i, result in enumerate(results)})
row.update(universalInfo)
dw.writerow(row)
myFile.close()
with open(baseName + (str(i) if newFile else "") + ".csv", "w") as myFile:
dw = csv.DictWriter(myFile, fields, restval="data missing")
dw.writeheader()
for outcome, index in resultTypeIndices.items():
for name, results in self.summarize()[index].items():
row = (
{'name': name, 'baseResult': outcome}
| enumerate(results)
| universalInfo
)
dw.writerow(row)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CID.saveFile refactored with the following changes:

Comment on lines -487 to +488
results = {c: kw.get(c, None) for c in resultColumns}
results.update(kw)
return results
return {c: kw.get(c, None) for c in resultColumns} | kw
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeResults refactored with the following changes:

Comment on lines -706 to +705
if False and len(polls) < 6:
return tieFor2Probs(polls, uncertainty)
else:
return tieFor2Estimate(tuple(pollsToProbs(polls, uncertainty)))
return tieFor2Estimate(tuple(pollsToProbs(polls, uncertainty)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function adaptiveTieFor2 refactored with the following changes:

Comment on lines -727 to +723
print(
"# " + str(globalComment),
# dict(
# media=self.media.__name__,
# version=self.repo_version,
# seed=self.seed,
## model=self.model,
# methods=self.methods,
# nvot=self.nvot,
# ncand=self.ncand,
# niter=self.niter)),
file=myFile,
)
print(f"# {str(globalComment)}", file=myFile)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function appendResults refactored with the following changes:

This removes the following comments ( why? ):

#              version=self.repo_version,
#              seed=self.seed,
# media=self.media.__name__,
#              niter=self.niter)),
# dict(
#              nvot=self.nvot,
#              ncand=self.ncand,
#              methods=self.methods,
##              model=self.model,

Top2Version.__name__ = noRunoffMethod.__name__ + "Top2"
Top2Version.__name__ = f"{noRunoffMethod.__name__}Top2"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function top2 refactored with the following changes:

Comment on lines +349 to +351



Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeScoreMethod refactored with the following changes:

Comment on lines -643 to +647
expectedUtility = sum(u for u in utils) / len(utils)
expectedUtility = sum(utils) / len(utils)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Approval.zeroInfoBallot refactored with the following changes:

Comment on lines -808 to +812
if third == winner or third == runnerUp:
if third in [winner, runnerUp]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getCoefficients refactored with the following changes:

Comment on lines 859 to +860


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeSTARMethod refactored with the following changes:

Comment on lines -1216 to +1209
def candScore(self, scores):
def candScore(cls, scores):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Mav.candScore refactored with the following changes:

Comment on lines -1304 to +1297
((frontId, frontResult), (targId, targResult)) = places[0:2]
((frontId, frontResult), (targId, targResult)) = places[:2]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Mav.stratBallot refactored with the following changes:

Comment on lines -2404 to +2391
matchupWins = [sum(1 for marg in row if marg > 0) for row in cmat]
matchupWins = [sum(marg > 0 for marg in row) for row in cmat]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RankedRobin.results refactored with the following changes:

Comment on lines -2606 to +2593
for i, b in enumerate(ballots):
for b in ballots:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ITRV.results refactored with the following changes:

@@ -2,6 +2,7 @@
from methods import *

def makeBlock(method):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeBlock refactored with the following changes:

Comment on lines -102 to +105
scoreSupport = 0
for ballot in ballots:
if ballot[winner] == score:
scoreSupport += ballot.weight
scoreSupport = sum(
ballot.weight for ballot in ballots if ballot[winner] == score
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AllocatedScore.reweight refactored with the following changes:

if upset > 0:
return runnerUp
else: return top
return runnerUp if upset > 0 else top
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ASFinalRunoff.pickWinner refactored with the following changes:

Comment on lines -278 to +276
if upset > 0:
return runnerUp
else: return top
return runnerUp if upset > 0 else top
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ASRunoffs.pickWinner refactored with the following changes:

Comment on lines -322 to +319
else:
scores = [sum(ballot[c]*ballot.weight for ballot in ballots) if c in bestCands else -1 for c in range(ncand)]
return scores.index(max(scores))
scores = [sum(ballot[c]*ballot.weight for ballot in ballots) if c in bestCands else -1 for c in range(ncand)]
return scores.index(max(scores))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SequentialMonroe.pickWinner refactored with the following changes:

Comment on lines -355 to +354
scoreSupport = 0
for ballot in ballots:
if ballot[winner] == score:
scoreSupport += score*ballot.weight
scoreSupport = sum(
score * ballot.weight
for ballot in ballots
if ballot[winner] == score
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function S5H.reweight refactored with the following changes:

Comment on lines -443 to +444
piles = [[] for i in range(nCands)]
piles = [[] for _ in range(nCands)]
while len(winners) + len(candsLeft) > numWinners:
cls.resort(ballotsToSort, candsLeft, piles)
newWinners = [c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota]
if newWinners:
if newWinners := [
c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota
]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function STV.winnerSet refactored with the following changes:

Comment on lines -484 to +485
piles = [[] for i in range(nCands)]
piles = [[] for _ in range(nCands)]
while len(winners) < numWinners - 1 and len(winners) + len(candsLeft) > numWinners - 1:
cls.resort(ballotsToSort, candsLeft, piles)
newWinners = [c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota][:max(0, numWinners-len(winners)-1)]
if newWinners:
if newWinners := [
c for c in candsLeft if sum(b.weight for b in piles[c]) >= quota
][: max(0, numWinners - len(winners) - 1)]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MinimaxSTV.winnerSet refactored with the following changes:

Comment on lines -64 to +65
if callable(biaser):
bias = biaser(standings)
else:
bias = biaser
result= (standings[0:2] +
[(standing - bias + numerator * (bias / max(i+2, 1)))
for i, standing in enumerate(standings[2:])])
bias = biaser(standings) if callable(biaser) else biaser
result = standings[:2] + [
(standing - bias + numerator * (bias / max(i + 2, 1)))
for i, standing in enumerate(standings[2:])
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function biasedMediaFor refactored with the following changes:

Comment on lines -82 to +77
if callable(biaser):
bias = biaser(standings)
else:
bias = biaser
bias = biaser(standings) if callable(biaser) else biaser
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function skewedMediaFor refactored with the following changes:

if caring==None:
if caring is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DimVoter.fromDims refactored with the following changes:

Comment on lines -367 to +372
subclusterMeans.append([random.gauss(0,sqrt(cares)) for i in range(self.dimsPerView[c])])
subclusterMeans.append(
[
random.gauss(0, sqrt(cares))
for _ in range(self.dimsPerView[c])
]
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function KSElectorate.chooseClusters refactored with the following changes:

Comment on lines +77 to +78
fgHelped = []
fgHarmed = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function threeRoundResults refactored with the following changes:

This removes the following comments ( why? ):

#If not I should be quitting earlier than this but easier to just fake it.
#zero-sized foreground

@fsargent fsargent closed this Dec 31, 2022
@sourcery-ai sourcery-ai bot deleted the sourcery/fs/jquinn branch December 31, 2022 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant