Weather
So, according to the Biblical principle of 'Search and you shall find' here's a loop that searches for a 'sunny day with 20 degrees' (i hope its celsius.....) for 60 seconds. Let's see what kinda weather we get today.
import time
class WeatherFSM:
def __init__(self):
self.target = ["a", "sunny", "day", "of", "20", "degrees"]
self.index = 0
self.matches_found = 0
def process(self, word):
if word.lower() == self.target[self.index]:
self.index += 1
if self.index == len(self.target):
self.matches_found += 1
self.index = 0 # Reset to look for the next occurrence
return True
else:
self.index = 0
return False
# --- Timing Wrapper ---
def run_timed_search(duration_seconds):
fsm = WeatherFSM()
start_time = time.time()
end_time = start_time + duration_seconds
print(f"FSM Search Started... will run for {duration_seconds} seconds.")
# Simulating a stream of data (e.g., from a weather log or social feed)
mock_stream = ["It", "is", "a", "sunny", "day", "of", "20", "degrees", "today"]
stream_index = 0
while time.time() < end_time:
# Get next word from our simulated stream
word = mock_stream[stream_index % len(mock_stream)]
stream_index += 1
# Process through FSM
if fsm.process(word):
print(f"[{time.strftime('%H:%M:%S')}] Pattern Detected!")
# Small sleep to prevent 100% CPU usage during simulation
time.sleep(0.5)
print(f"\nTime's up! Total occurrences found: {fsm.matches_found}")
# Run for 60 seconds
run_timed_search(60)
So have some faith. "Search and you shall find" is what Jesus said. So replace to text string to say "500,-" or whatever else you wish. I suggest a Google wish search page for the compute.
ReplyDeleteAnd search for a $1 token.
Delete