helpers.py 947 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 19:32:50 2020

@author: luna
"""

class ParticleBinSorter(object):
    def __init__(self):
        super(ParticleBinSorter, self).__init__()
        self.bins = [5, 10, 20, 50, 100, 200, 500]
        
    def sort_particles_into_bins(self, particleList):
        particlesInBins = self._get_empty_bins()
        
        for particle in particleList:
            binIndex = self._get_binIndex_of_particle(particle)
            particlesInBins[binIndex].append(particle)
        return particlesInBins
    
    def _get_empty_bins(self):
        return [[] for i in range(len(self.bins)+1)]
    
    def _get_binIndex_of_particle(self, particle):
        size = particle.getParticleSize()
        binIndex = 0
        for upperLimit in self.bins:
            if size <= upperLimit:
                break
            else:
                binIndex += 1
        return binIndex