Guest User

Untitled

a guest
Mar 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. from pathlib2 import PurePath
  2. img_root = Path('AAT_images')
  3. class AatImage():
  4. def __init__(curr_path):
  5. """
  6. get list of image in current directory
  7. curr_path: PosixPAth object parent dir of the images, starts with push* / pull*
  8. """
  9.  
  10. self.action = 'Push' if curr_path.name.count('Push') else 'Pull'
  11. self.category = curr_path.parents[0].name
  12. # since glob is generator we use next() to get the first item and resolve() to get the full path
  13. self.phases = {
  14. 0: str(curr_path.glob('*medium.jpg').next().resolve()),
  15. 1: str(curr_path.glob('*1.jpg').next().resolve()),
  16. 2: str(curr_path.glob('*2.jpg').next().resolve()),
  17. 3: str(curr_path.glob('*2.jpg').next().resolve()),
  18. }
  19. self.wrong_image = str(curr_path.glob('*SALAH.jpg').next().resolve()),
  20.  
  21. def image_on_phase(phase):
  22. return self.phases[phase]
  23.  
  24. def wrong_image():
  25. return self.wrong_image
  26.  
  27. def __str__():
  28. return '%s - %s' % (self.category, self.action)
  29.  
  30. def __repr__():
  31. return __str__()
  32.  
  33. class ImageSet():
  34. '''
  35. abstract the image set creation
  36. '''
  37. def __init__(path):
  38. """
  39. Generate image set
  40. path: expected value: ('Block A'|'Block B'|'Block C'|'Latihan')
  41. """
  42. img_path = '*%s*/*/*' % path
  43. path_to_image = list(img_root.glob(img_path))
  44. self.images = []
  45. for x in xrange(12):
  46. # image must be repeated 12 times
  47. self.images.extend([AatImage(folder) for folder in path_to_image]) # something like that
  48. assert len(self.images)==168 # otherwise there is missing images
  49. # ..and then randomize the image list
  50. self.limit = len(self.images)
  51.  
  52. def next():
  53. self.images.pop()
Add Comment
Please, Sign In to add comment