Before start, I want to highlight brief what is point of this project, at first stage , the application should be able to generate random series of numbers, every serie will have 5 numbers, also the application should organize the raw data, and in base of an “awards” structure it should be able to award with more points if the serie generated is fibonacci.
In a second stage, my goal is to implement a learning process that let the application learn that per fibonacci serie created it will get more awards, so in some point the app should be able to generate more fibonacci series in order to gain more awards.
Ok, this is my goal will see if it actually possible, I think so, we will prove it
Continuing with the project, I had different challenges that motivate me to investigate and learn, will see what I have done until now.
File with raw data
The format of the file is .csv and the filename is already set like this:
[datetime]_data.csv
example: 050925232003_data.csv

Data structure
The data structure for every file with raw data is set as below:
Field | Type | Description |
uuid | String | The Universal Unique Identifier, used to identify every serie of numbers |
series | Array | An array with integer numbers generated randomly |
status | String | The series pass through the follow status: – raw – sorted – processed |
created_date | date | Date of creation data file |
example:

The raw data is generated as expected, I ran several tests generate up to 100,000 series successfully.
The Master File of Registers
Part of the solution include keep a register on a master file with every new file of series generated, on that way this master file will be open and close very often.
Function:
# Update Master File that keep register
# of new Files generated
def update_master_register_file():
# Set initial status
file_initial_status = "new"
#open the master file
register_file = open(get_master_register_file(), "a")
#update the master by input new line
register_file.write(filename+","+ set_now_variables().strftime("%d/%m/%Y")+","+ file_initial_status+","+set_start_time()+","+set_end_time()+"\n" )
The structure of the file
field | data type | description |
name of file (csv) | string | Name of data file generated |
date | date | date file created |
status | string | the status are: – new – processed |
start time | time | time of file created |
end time | time | time of file was closed after the series created. |
The result is like that:

Check Register Updated
The next challenge is to open the master file when it is updated, and get the last line added to open the file. For this task I did create a process that scan the master file and once it is updated , the process will be opened and get the last line which is related with the last file created.
Function:
#Check update Master File
def detect_master_file_changes(file_path, interval=1):
last_modified = os.path.getmtime(file_path)
while True:
current_modified = os.path.getmtime(file_path)
# Confirm the file was modified
if current_modified != last_modified:
print("File has changed!")
last_modified = current_modified
# Open the last file created
open_register_file(file_path)
time.sleep(interval)
After several test the components works as expected as per my plan:

The next step is finish the component to read the last file generated and sort out the array of numbers.
Github Repository
FYI , I pushed the first version of this project, up today, feel free to take a look, I’ll appreciate your comments
Comments are closed