Counter to track success/failure rates [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am iterating over folders and files trying to fix the lines. After each folder or file, I'd like to print how many times the code fixed/failed/skipped the lines inside.
Here is a working solution:
from collections import Counter
class AttemptCounter:
def __init__(self):
self.fixed, self.failed, self.skipped = Counter(), Counter(), Counter()
def fixed(self, items):
self.fixed.update(items)
def failed(self, items):
self.failed.update(items)
def skipped(self, items):
self.skipped.update(items)
def show(self, name):
return f'self.fixed[name] fixed, '
f'self.failed[name] failed, '
f'self.skipped[name] skipped.'
After each line I call one of the fixed/failed/skipped methods with argument [file_name, folder_name]
and afterwards I call either show(file_name)
or show(folder_name)
.
I feel that there has to be a cleaner solution for this. Could you help?
python python-3.x
closed as off-topic by jonrsharpe, t3chb0t, Stephen Rauch, Dannnno, Daniel Jun 10 at 16:44
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â jonrsharpe, t3chb0t, Dannnno, Daniel
 |Â
show 1 more comment
up vote
1
down vote
favorite
I am iterating over folders and files trying to fix the lines. After each folder or file, I'd like to print how many times the code fixed/failed/skipped the lines inside.
Here is a working solution:
from collections import Counter
class AttemptCounter:
def __init__(self):
self.fixed, self.failed, self.skipped = Counter(), Counter(), Counter()
def fixed(self, items):
self.fixed.update(items)
def failed(self, items):
self.failed.update(items)
def skipped(self, items):
self.skipped.update(items)
def show(self, name):
return f'self.fixed[name] fixed, '
f'self.failed[name] failed, '
f'self.skipped[name] skipped.'
After each line I call one of the fixed/failed/skipped methods with argument [file_name, folder_name]
and afterwards I call either show(file_name)
or show(folder_name)
.
I feel that there has to be a cleaner solution for this. Could you help?
python python-3.x
closed as off-topic by jonrsharpe, t3chb0t, Stephen Rauch, Dannnno, Daniel Jun 10 at 16:44
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â jonrsharpe, t3chb0t, Dannnno, Daniel
Is that your actual code? Because you seem to have attributes with the same name as methods, so I'd expectTypeError: 'Counter' object is not callable
.
â jonrsharpe
Jun 9 at 12:06
@jonrsharpe I get no error when running it?
â esote
Jun 9 at 13:54
@esote it will run just fine, until you instantiate the class and try to call a method that just got shadowed with a Counter in__init__
.
â jonrsharpe
Jun 9 at 14:03
@jonrsharpe Thanks for clarifying.
â esote
Jun 9 at 14:16
1
We're not here to review ideas of code, but actual implementations. Please review to ensure the code actually does what you say then edit accordingly. Also: what concerns you about the current code, how do you think it could be "cleaner"?
â jonrsharpe
Jun 9 at 20:30
 |Â
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am iterating over folders and files trying to fix the lines. After each folder or file, I'd like to print how many times the code fixed/failed/skipped the lines inside.
Here is a working solution:
from collections import Counter
class AttemptCounter:
def __init__(self):
self.fixed, self.failed, self.skipped = Counter(), Counter(), Counter()
def fixed(self, items):
self.fixed.update(items)
def failed(self, items):
self.failed.update(items)
def skipped(self, items):
self.skipped.update(items)
def show(self, name):
return f'self.fixed[name] fixed, '
f'self.failed[name] failed, '
f'self.skipped[name] skipped.'
After each line I call one of the fixed/failed/skipped methods with argument [file_name, folder_name]
and afterwards I call either show(file_name)
or show(folder_name)
.
I feel that there has to be a cleaner solution for this. Could you help?
python python-3.x
I am iterating over folders and files trying to fix the lines. After each folder or file, I'd like to print how many times the code fixed/failed/skipped the lines inside.
Here is a working solution:
from collections import Counter
class AttemptCounter:
def __init__(self):
self.fixed, self.failed, self.skipped = Counter(), Counter(), Counter()
def fixed(self, items):
self.fixed.update(items)
def failed(self, items):
self.failed.update(items)
def skipped(self, items):
self.skipped.update(items)
def show(self, name):
return f'self.fixed[name] fixed, '
f'self.failed[name] failed, '
f'self.skipped[name] skipped.'
After each line I call one of the fixed/failed/skipped methods with argument [file_name, folder_name]
and afterwards I call either show(file_name)
or show(folder_name)
.
I feel that there has to be a cleaner solution for this. Could you help?
python python-3.x
edited Jun 9 at 12:06
jonrsharpe
12.8k12554
12.8k12554
asked Jun 9 at 9:29
Pranasas
1092
1092
closed as off-topic by jonrsharpe, t3chb0t, Stephen Rauch, Dannnno, Daniel Jun 10 at 16:44
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â jonrsharpe, t3chb0t, Dannnno, Daniel
closed as off-topic by jonrsharpe, t3chb0t, Stephen Rauch, Dannnno, Daniel Jun 10 at 16:44
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â jonrsharpe, t3chb0t, Dannnno, Daniel
Is that your actual code? Because you seem to have attributes with the same name as methods, so I'd expectTypeError: 'Counter' object is not callable
.
â jonrsharpe
Jun 9 at 12:06
@jonrsharpe I get no error when running it?
â esote
Jun 9 at 13:54
@esote it will run just fine, until you instantiate the class and try to call a method that just got shadowed with a Counter in__init__
.
â jonrsharpe
Jun 9 at 14:03
@jonrsharpe Thanks for clarifying.
â esote
Jun 9 at 14:16
1
We're not here to review ideas of code, but actual implementations. Please review to ensure the code actually does what you say then edit accordingly. Also: what concerns you about the current code, how do you think it could be "cleaner"?
â jonrsharpe
Jun 9 at 20:30
 |Â
show 1 more comment
Is that your actual code? Because you seem to have attributes with the same name as methods, so I'd expectTypeError: 'Counter' object is not callable
.
â jonrsharpe
Jun 9 at 12:06
@jonrsharpe I get no error when running it?
â esote
Jun 9 at 13:54
@esote it will run just fine, until you instantiate the class and try to call a method that just got shadowed with a Counter in__init__
.
â jonrsharpe
Jun 9 at 14:03
@jonrsharpe Thanks for clarifying.
â esote
Jun 9 at 14:16
1
We're not here to review ideas of code, but actual implementations. Please review to ensure the code actually does what you say then edit accordingly. Also: what concerns you about the current code, how do you think it could be "cleaner"?
â jonrsharpe
Jun 9 at 20:30
Is that your actual code? Because you seem to have attributes with the same name as methods, so I'd expect
TypeError: 'Counter' object is not callable
.â jonrsharpe
Jun 9 at 12:06
Is that your actual code? Because you seem to have attributes with the same name as methods, so I'd expect
TypeError: 'Counter' object is not callable
.â jonrsharpe
Jun 9 at 12:06
@jonrsharpe I get no error when running it?
â esote
Jun 9 at 13:54
@jonrsharpe I get no error when running it?
â esote
Jun 9 at 13:54
@esote it will run just fine, until you instantiate the class and try to call a method that just got shadowed with a Counter in
__init__
.â jonrsharpe
Jun 9 at 14:03
@esote it will run just fine, until you instantiate the class and try to call a method that just got shadowed with a Counter in
__init__
.â jonrsharpe
Jun 9 at 14:03
@jonrsharpe Thanks for clarifying.
â esote
Jun 9 at 14:16
@jonrsharpe Thanks for clarifying.
â esote
Jun 9 at 14:16
1
1
We're not here to review ideas of code, but actual implementations. Please review to ensure the code actually does what you say then edit accordingly. Also: what concerns you about the current code, how do you think it could be "cleaner"?
â jonrsharpe
Jun 9 at 20:30
We're not here to review ideas of code, but actual implementations. Please review to ensure the code actually does what you say then edit accordingly. Also: what concerns you about the current code, how do you think it could be "cleaner"?
â jonrsharpe
Jun 9 at 20:30
 |Â
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is that your actual code? Because you seem to have attributes with the same name as methods, so I'd expect
TypeError: 'Counter' object is not callable
.â jonrsharpe
Jun 9 at 12:06
@jonrsharpe I get no error when running it?
â esote
Jun 9 at 13:54
@esote it will run just fine, until you instantiate the class and try to call a method that just got shadowed with a Counter in
__init__
.â jonrsharpe
Jun 9 at 14:03
@jonrsharpe Thanks for clarifying.
â esote
Jun 9 at 14:16
1
We're not here to review ideas of code, but actual implementations. Please review to ensure the code actually does what you say then edit accordingly. Also: what concerns you about the current code, how do you think it could be "cleaner"?
â jonrsharpe
Jun 9 at 20:30