-
-
Save anonymous/b221eee608a517e1cc0f1bd9c3835e42 to your computer and use it in GitHub Desktop.
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 | |
class Create_Excel_Graph(): | |
def __init__(self): | |
self.Times = self.Open_Time_List() | |
self.Array_File = self.New_File(self.Times) | |
self.Finalized_Array = self.Remove_Comments(self.Array_File) | |
self.Excel_Transfer(self.Finalized_Array) | |
def Open_Time_List(self): | |
#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(self, 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.close() | |
return Test_Array | |
#Delete Comments to save even more space. | |
def Remove_Comments(self, 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(self, 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 | |
try: | |
Time_Array.append(float(Current_Line[Start_Index:End_Index])) | |
except: Time_Array.append(float(max(Time_Array))) | |
#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 | |
if len(Time_Array) >= 5: | |
Average_Of_Five = self.Find_Average_Of(5, Time_Array) | |
Excel_Worksheet.write('B1', 'Average of 5') | |
Excel_Worksheet.write_column('B6', Average_Of_Five) | |
#Write the Average of 12 | |
if len(Time_Array) >= 12: | |
Average_Of_Twelve = self.Find_Average_Of(12, Time_Array) | |
Excel_Worksheet.write('C1', 'Average of 12') | |
Excel_Worksheet.write_column('C13', Average_Of_Twelve) | |
#Write the Average of 50 | |
if len(Time_Array) >= 50: | |
Average_Of_Fifty = self.Find_Average_Of(50, Time_Array, 3) | |
Excel_Worksheet.write('D1', 'Average of 50') | |
Excel_Worksheet.write_column('D51', Average_Of_Fifty) | |
#Write the Average of 100 | |
if len(Time_Array) >= 100: | |
Average_Of_Hundred = self.Find_Average_Of(100, Time_Array, 5) | |
Excel_Worksheet.write('E1', 'Average of 100') | |
Excel_Worksheet.write_column('E101', Average_Of_Hundred) | |
#Write the Average of 1000 | |
if len(Time_Array) >= 1000: | |
Average_Of_Thousand = self.Find_Average_Of(1000, Time_Array, 50) | |
Excel_Worksheet.write('F1', 'Average of 1000') | |
Excel_Worksheet.write_column('F1001', Average_Of_Thousand) | |
#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' : {'none': True}, | |
'marker' : {'type': 'circle', | |
'size': 3}, | |
'trendline': {'type': 'linear', | |
'name': 'Single Solve Trend', | |
'line': { | |
'color': 'black', | |
'width': 3, | |
} | |
}, | |
}) | |
if len(Time_Array) >= 5: | |
Chart.add_series({ | |
'values': '=Sheet1!$B$6:$B{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$B$1', | |
'line' : {'color': 'red'}, | |
}) | |
if len(Time_Array) >= 12: | |
Chart.add_series({ | |
'values': '=Sheet1!$C$13:$C{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$C$1', | |
'line' : {'color': 'blue'}, | |
}) | |
if len(Time_Array) >= 50: | |
Chart.add_series({ | |
'values': '=Sheet1!$D$51:$D{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$D$1', | |
'line' : {'color': 'purple'}, | |
}) | |
if len(Time_Array) >= 100: | |
Chart.add_series({ | |
'values': '=Sheet1!$E$101:$E{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$E$1', | |
'line' : {'color': 'green'}, | |
}) | |
if len(Time_Array) >= 1000: | |
Chart.add_series({ | |
'values': '=Sheet1!$F$1001:$F{}'.format(len(Time_Array) + 1), | |
'name' : '=Sheet1!$F$1', | |
'line' : {'color': 'orange'}, | |
}) | |
Chart_Sheet.set_chart(Chart) | |
Excel_File.close() | |
def Find_Average_Of(self, Average_Number, Time_Array, Times_To_Cancel = 1): | |
#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_Array = [] | |
Highest_Number_Array = [0 for Fillers in range(Times_To_Cancel)] | |
Start = True | |
for Added_Values in range(1, Average_Number + 1): | |
Current_Number = float(Time_Array[Time_Index - Added_Values]) | |
if Start: | |
Smallest_Number_Array.append(Current_Number) | |
if len(Smallest_Number_Array) >= Times_To_Cancel: | |
Start = False | |
for Times in range(len(Smallest_Number_Array)): | |
if Current_Number < Smallest_Number_Array[Times]: | |
High_Index = Smallest_Number_Array.index(max(Smallest_Number_Array)) | |
Smallest_Number_Array[High_Index] = Current_Number | |
break | |
for Times in range(len(Highest_Number_Array)): | |
if Current_Number > Highest_Number_Array[Times]: | |
Lowest_Index = Highest_Number_Array.index(min(Highest_Number_Array)) | |
Highest_Number_Array[Lowest_Index] = Current_Number | |
break | |
Average += Current_Number | |
Small_Total = sum(Smallest_Number_Array) | |
High_Total = sum(Highest_Number_Array) | |
Average -= (Small_Total + High_Total) | |
Average = math.floor((Average/(Average_Number - | |
(Times_To_Cancel * 2))) * 100)/100.0 | |
Average_Array.append(Average) | |
return Average_Array | |
if __name__ == '__main__': | |
Create_Excel_Graph() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment