from Sensors import sensors
from Messenger import send_notification
class GeodeScanner:
"""
A class for scanning and measuring the power levels of the different elements and their respective geodes.
Attributes:
- ELEMENTS: A list of the different elements to be scanned.
- sensors: A dictionary containing lists of sensors for each element.
- current_element: A string representing the currently scanned element.
- current_value: A list representing each of the current sensor values.
- geode_power: An integer representing the power level of the geode.
"""
ELEMENTS = ['Honesty', 'Kindness', 'Laughter', 'Generosity', 'Loyalty', 'Empathy', 'Magic']
def __init__(self):
self.sensors = {}
self.current_element = ""
self.current_value = {element: 0 for element in self.ELEMENTS}
self.geode_power = 0
self.start_scan = False
# Initialize sensors for each element
for element in self.ELEMENTS:
self.sensors[element] = Sensors(element)
def stop_scanning(self):
# Stops start_scanning
self.start_scan = False
def start_scanning(self):
# Continuously scans geode elements for changes in power levels until stopped
self.start_scan = True
while self.start_scan:
for element in self.ELEMENTS:
value = self.sensors[element].get_value()
if value != self.current_value[element]:
self.current_value[element] = value
self.current_element = element
self.measure_power()
def measure_power(self):
# Measures geode power level and calls function log_data()
self.geode_power = self.sensors[self.current_element].get_value()
self.log_data()
def log_data(self):
# Logs timestamp and geode’s power level to file. Sends notification to Element bearer
log_file = open("Element_logs/" + self.current_element + ".txt", "a")
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
log_file.write(timestamp + " Power: " + str(self.geode_power) + "\n")
log_file.close()
send_notification(self.current_element, "Your geode’s power level is now " + str(self.geode_power))
send_notification(self.current_element, "Please log your current action for analysis")
Trying so hard not to code review this XD I love it!
The most impressive part of this is that she documented her code.
This is Twilight Sparkle we're talking about. I'd be surprised if the code wasn't documented.
11528532
First critique: why is the log data not CSV? 😇
Also also: the notification framework does not glom responses into matching events? Also also also...... 😘
magic strings? boooooo!
using this instead of with open? boooooo!
(in all seriousness, love that you actually are using code in a fic, it is quite a trip to read as someone who does both)
I’m actually liking how this is written. Sure it’s confusing but it actually fits with the story.