Overpowered

by gapty

GeodeScanner.py

Previous ChapterNext Chapter

Author's Note

Please be aware that this chapter may have weird formatting on mobile view.


GeodeScanner.py

``` 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")

```

Next Chapter