-
-
Save anonymous/a32c775adc2c0a0c3c5d60df9d12ba35 to your computer and use it in GitHub Desktop.
Make a .txt File from CSTimer Session times, and this will automatically create an Excel Graph for you.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################## | |
#NOTE:#################################################### | |
#The File has to be in the same folder as this file,###### | |
#and the File is only one session, so just copy the whole# | |
#time list for the session.############################### | |
########################################################## | |
#Check to see if the Computer contains xlsxwriter. | |
try: | |
import xlsxwriter as Excel_Writer | |
except ImportError: | |
print('xlsxwriter is not installed.') | |
print(ImportError) | |
import math | |
#Open Time List. | |
def Open_Time_List(): | |
try: | |
return open('Time_List.txt', 'r') | |
except FileNotFoundError: | |
Times_File = input('Standard File Name not found. \n' | |
'Type in the file name of the Time List: ') | |
return open(Times_File, 'r') | |
#Creates a new file for space efficiency. | |
def New_File(Times): | |
Count = 0 | |
Start_Point = 0 | |
Lines = [] | |
for Current_Line in Times: | |
Count += 1 | |
Lines.append(Current_Line) | |
if 'Time List:' in Current_Line: Start_Point = Count - 1 | |
Times.close() | |
#Create a new File, then allow the program to Write in it and Read. | |
Altered_Time_List = open("New_Time_List.txt", "w") | |
Test_Array = [] | |
for Lines_To_Copy in range(Start_Point, len(Lines)): | |
Test_Array.append(Lines[Lines_To_Copy]) | |
#Altered_Time_List.write(Lines[Lines_To_Copy]) | |
Altered_Time_List.close() | |
return Test_Array | |
#Delete Comments to save even more space. | |
def Remove_Comments(Transfer_Array): | |
Time_File = open("New_Time_List.txt", "r+") | |
Time_List = Transfer_Array | |
Time_Array = [] | |
for Current_Line in Time_List: | |
Time_Array.append(Current_Line) | |
for Current_Line in Time_Array: | |
Line_Index = Time_Array.index(Current_Line) | |
if '[' and ']' in Current_Line: | |
Start_Index = Current_Line.index('[') | |
End_Index = Current_Line.index(']') + 1 | |
New_Line = ('%s %s') % (Current_Line[0:Start_Index], | |
Current_Line[End_Index +1:]) | |
Time_Array[Line_Index] = New_Line | |
Time_File.writelines(Time_Array) | |
Time_File.close() | |
return Time_Array | |
def Excel_Transfer(Final_Array): | |
Time_Array = [] | |
for Current_Line in Final_Array: | |
Line_Index = Final_Array.index(Current_Line) | |
Extra = 0 | |
#Should be every Solve Line. | |
if '. ' and ' ' in Current_Line: | |
if '+' in Current_Line: | |
Extra = 1 | |
Start_Index = Current_Line.index('. ') + 2 | |
End_Index = Current_Line.index(' ') - Extra | |
Time_Array.append(float(Current_Line[Start_Index:End_Index])) | |
#Write the Excel File with the Solve Data. | |
Excel_File = Excel_Writer.Workbook('Times_To_Excel.xlsx') | |
Excel_Worksheet = Excel_File.add_worksheet() | |
#Write the Single Solves | |
Excel_Worksheet.write('A1', 'Single Solves') | |
Excel_Worksheet.write_column('A2', Time_Array) | |
#Write the Average of 5 | |
Average_Of_Five = Find_Average_Of(5, Excel_Worksheet, Time_Array) | |
Excel_Worksheet.write('B1', 'Average of 5') | |
Excel_Worksheet.write_column('B6', Average_Of_Five) | |
#Write the Average of 12 | |
Average_Of_Twelve = Find_Average_Of(12, Excel_Worksheet, Time_Array) | |
Excel_Worksheet.write('C1', 'Average of 12') | |
Excel_Worksheet.write_column('C13', Average_Of_Twelve) | |
#Build the Chart | |
Chart_Sheet = Excel_File.add_chartsheet() | |
Chart = Excel_File.add_chart({'type': 'line'}) | |
Chart.add_series({ | |
'values': '=Sheet1!$A$2:$A{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$A$1', | |
'line' : {'color': 'gray'}, | |
}) | |
Chart.add_series({ | |
'values': '=Sheet1!$B$6:$B{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$B$1', | |
'line' : {'color': 'red'}, | |
}) | |
Chart.add_series({ | |
'values': '=Sheet1!$C$13:$C{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$C$1', | |
'line' : {'color': 'blue'}, | |
}) | |
Chart_Sheet.set_chart(Chart) | |
Excel_File.close() | |
def Find_Average_Of(Average_Number, Excel_Worksheet, Time_Array): | |
#Get the Averages and Append them to an Array | |
Average_Array = [] | |
for Time_Index in range(Average_Number, len(Time_Array) + 1): | |
Average = 0 | |
Smallest_Number = 0 | |
Highest_Number = 0 | |
Start = True | |
for Added_Values in range(1, Average_Number + 1): | |
Current_Number = float(Time_Array[Time_Index - Added_Values]) | |
if Start: | |
Smallest_Number = Current_Number | |
Start = False | |
if Current_Number < Smallest_Number: | |
Smallest_Number = Current_Number | |
if Current_Number > Highest_Number: | |
Highest_Number = Current_Number | |
Average += Current_Number | |
Average -= (Smallest_Number + Highest_Number) | |
Average = math.floor((Average/(Average_Number - 2)) * 100)/100.0 | |
Average_Array.append(Average) | |
return Average_Array | |
if __name__ == '__main__': | |
#Functions to Setup Solve Information. | |
Times = Open_Time_List() | |
Array_File = New_File(Times) | |
Finalized_Array = Remove_Comments(Array_File) | |
Excel_Transfer(Finalized_Array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment