I’ve got ten years worth of hourly processed email data stored in invisible yearly data files.
I’m trying to strip out varying data from the files, but they are not always in sequence. When testing, dates have been altered by day, or even month, resulting in daily stored sections that can be multiple in number for a given day, and out of chronological sequence.
I’ve written the following code to ensure data is accumulated despite daily sections being in multiples, and out of sequence, but it’s taking over 4 minutes to run.
As I have little experience in ObjC (or C++ for that matter), I don’t know where to start, so would appreciate any pointers, or advice.
I need the returned data to stay the way it is, please.
I’ve also got a handler that creates a filled data file, but including it makes this message too large.
set theYear to 2000
set t to current date
set {theEssentialList, daysOFF, daysExtra, totalOfYearsProcessedEmails, totalOfYearsProcessedPrinted, totalOfYearsExtraPrinted, maximumHourlyCount, maximumHourlyExtraCount, maximumDailyCount} to my arrangeDetailedData(theYear) as list
on arrangeDetailedData(theYear)
tell application "Finder"
set YearsTally to read file ((path to desktop) & "Mail Manager Folder:.Detailed Yearly Tally " & theYear as text) using delimiter ","
end tell
set theEssentialList to {}
set daysOFF to 0
set daysExtra to 0
# c will vary by adding a day on each loop
set c to current date
set month of c to 1
set day of c to 1
set time of c to 0
set year of c to theYear
set daysOFFFlag to true
set totalOfYearsProcessedPrinted to 0
set totalOfYearsProcessedEmails to 0
set totalOfYearsExtraPrinted to 0
set maximumHourlyCount to 0
set maximumHourlyExtraCount to 0
set maximumDailyCount to 0
repeat with eachDay from 1 to 366
if year of c ≠ theYear then exit repeat
set totalOfHoursProcessedPrinted to 0
set totalOfHoursProcessedEmails to 0
set totalOfDaysExtraPrinted to 0
set foundMatchingDay to 0
repeat with x from 1 to ((count of YearsTally) div 52)
set theDateInfo to item ((x * 52) - 51) of YearsTally & " " & item ((x * 52) - 50) of YearsTally & " " & item ((x * 52) - 1) of YearsTally
if month of c as text = word 1 of theDateInfo as text then
if day of c as integer = word 2 of theDateInfo as integer then
set foundMatchingDay to foundMatchingDay + 1
repeat with y from ((x * 52) - 49) to ((x * 52) - 3) by 2
set temp to (item y of YearsTally) as integer
set totalOfHoursProcessedPrinted to totalOfHoursProcessedPrinted + temp
if temp > maximumHourlyExtraCount then set maximumHourlyExtraCount to temp
set temp to (item (y + 1) of YearsTally) as integer
set totalOfHoursProcessedEmails to totalOfHoursProcessedEmails + temp
if temp > maximumHourlyCount then set maximumHourlyCount to temp
end repeat
set totalOfYearsProcessedPrinted to totalOfYearsProcessedPrinted + totalOfHoursProcessedPrinted
set totalOfYearsProcessedEmails to totalOfYearsProcessedEmails + totalOfHoursProcessedEmails
set totalOfDaysExtraPrinted to totalOfDaysExtraPrinted + (word 3 of theDateInfo)
set totalOfYearsExtraPrinted to totalOfYearsExtraPrinted + totalOfDaysExtraPrinted
end if
end if
end repeat
if (current date) as date < c as date then set daysOFFFlag to false
if daysOFFFlag and (word 3 of theDateInfo) = 0 then set daysOFF to daysOFF + 1
if (word 3 of theDateInfo) > maximumDailyCount then set maximumDailyCount to (word 3 of theDateInfo)
if foundMatchingDay > daysExtra then set daysExtra to foundMatchingDay
set daysEssentialTally to (month of c as text) & ", " & day of c & ", " & totalOfHoursProcessedPrinted & ", " & totalOfHoursProcessedEmails & ", " & totalOfDaysExtraPrinted & ", " & foundMatchingDay as text
set end of theEssentialList to daysEssentialTally & return
set c to c + days
end repeat
return {theEssentialList, daysOFF, daysExtra, totalOfYearsProcessedEmails, totalOfYearsProcessedPrinted, totalOfYearsExtraPrinted, maximumHourlyCount, maximumHourlyExtraCount, maximumDailyCount}
end arrangeDetailedData
tell application "System Events" to display dialog "Days off is " & daysOFF & ", days extra is " & daysExtra & return & return & " totalOfYearsProcessedEmails = " & totalOfYearsProcessedEmails & return & " totalOfYearsProcessedPrinted = " & totalOfYearsProcessedPrinted & return & " totalOfYearsExtraPrinted = " & totalOfYearsExtraPrinted & return & "maximumHourlyCount = " & maximumHourlyCount & return & "maximumHourlyExtraCount = " & maximumHourlyExtraCount & return & "maximumDailyCount = " & maximumDailyCount & return & "Time elapsed is " & (current date) - t & " seconds" as text