Clean up algorithm
<p>I've made an C# application which connects to my webcam and reads the images at the speed the webcam delivers them. I'm parsing the stream, in a way that I have a few jpeg's per seconds.</p>

<p>I don't want to write all the webcam data to the disk, I want to store images in memory. Also the application will act as a webserver which I can supply a datetime in the querystring. And the webserver must server the image closest to that time which it still has in memory.</p>

<p>In my code I have this: </p>

<pre><code>Dictionary&lt;DateTime, byte[]&gt; cameraImages;
</code></pre>

<p>of which DateTime is the timestamp of the received image and the bytearray is the jpeg.
All of that works; also handling the webrequest works. Basically I want to clean up that dictionary by keep images according to their age.</p>

<p>Now I need an algorithm for it, in that it cleans up older images.</p>

<p>I can't really figure out an algorithm for it, one reason for it is that the datetimes aren't exactly on a specific moment, and I can't be sure that an image always arrives. (Sometimes the image stream is aborted for serveral minutes). But what I want to do is:</p>

<ul>
<li>Keep all images for the first minute.</li>
<li>Keep 2 images per second for the first half hour.</li>
<li>Keep only one image per second if it's older than 30 minutes.</li>
<li>Keep only one image per 30 seconds if it's older than 2 hours.</li>
<li>Keep only one image per minute if it's older than 12 hours.</li>
<li>Keep only one image per hour if it's older than 24 hours.</li>
<li>Keep only one image per day if it's older than two days.</li>
<li>Remove all images older than 1 weeks.</li>
</ul>

<p>The above intervals are just an example.</p>

<p>Any suggestions? :P</p>
