Skip to content

Instantly share code, notes, and snippets.

@kamanazan
Created March 8, 2018 10:56
Show Gist options
  • Save kamanazan/25de4a028b9bb1916a8944952144aa30 to your computer and use it in GitHub Desktop.
Save kamanazan/25de4a028b9bb1916a8944952144aa30 to your computer and use it in GitHub Desktop.
image abstraction
from pathlib2 import PurePath
img_root = Path('AAT_images')
class AatImage():
def __init__(curr_path):
"""
get list of image in current directory
curr_path: PosixPAth object parent dir of the images, starts with push* / pull*
"""
self.action = 'Push' if curr_path.name.count('Push') else 'Pull'
self.category = curr_path.parents[0].name
# since glob is generator we use next() to get the first item and resolve() to get the full path
self.phases = {
0: str(curr_path.glob('*medium.jpg').next().resolve()),
1: str(curr_path.glob('*1.jpg').next().resolve()),
2: str(curr_path.glob('*2.jpg').next().resolve()),
3: str(curr_path.glob('*2.jpg').next().resolve()),
}
self.wrong_image = str(curr_path.glob('*SALAH.jpg').next().resolve()),
def image_on_phase(phase):
return self.phases[phase]
def wrong_image():
return self.wrong_image
def __str__():
return '%s - %s' % (self.category, self.action)
def __repr__():
return __str__()
class ImageSet():
'''
abstract the image set creation
'''
def __init__(path):
"""
Generate image set
path: expected value: ('Block A'|'Block B'|'Block C'|'Latihan')
"""
img_path = '*%s*/*/*' % path
path_to_image = list(img_root.glob(img_path))
self.images = []
for x in xrange(12):
# image must be repeated 12 times
self.images.extend([AatImage(folder) for folder in path_to_image]) # something like that
assert len(self.images)==168 # otherwise there is missing images
# ..and then randomize the image list
self.limit = len(self.images)
def next():
self.images.pop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment