Last active
September 25, 2015 08:42
-
-
Save RavuAlHemio/1f8c5996c9c5592a89ea to your computer and use it in GitHub Desktop.
counting print jobs, five minutes at a time (pseudo-C#)
This file contains hidden or 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
DateTime start = new DateTime(2015, 1, 13, 0, 0, 0); | |
DateTime end = start.AddDays(1); | |
List<PrintJob> jobs = GetPrintJobsOnDay(start); | |
List<JobStatisticsEntry> statsEntries = new List<JobStatisticsEntry>(); | |
jobs.Sort(j => j.DateTimePerformed); | |
int jobIndex = 0; | |
// for each five-minute chunk of this day | |
for (DateTime partStart = start; partStart < end; partStart = partStart.AddMinutes(5)) | |
{ | |
DateTime partEnd = partStart.AddMinutes(5); | |
int jobCount = 0; | |
while (jobs[jobIndex].DateTimePerformed >= partStart && jobs[jobIndex].DateTimePerformed < partEnd) | |
{ | |
// the current job was performed within this five-minute chunk | |
++jobCount; | |
// test the next job | |
++jobIndex; | |
} | |
// since the jobs are sorted by date/time, there is no other job in the list within this five-minute chunk | |
// store it | |
var statsEntry = new JobStatisticsEntry(partStart, jobCount); | |
statsEntries.Add(statsEntry); | |
// continue to the next five-minute chunk | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment