<commit_before>from __future__ import division
from direct.gui.OnscreenImage import OnscreenImage
from direct.showbase.MessengerGlobal import messenger
from panda3d.core import LineSegs, BitMask32
import os
from time import time


class Photos():

    def __init__(self, base, config=None, logging=None):
        # photo location
        self.base = base
        self.config = config
        self.logging = logging

        self.photo_names = []
        self.photo_set = []
        # this variable will change, and then be re-set with the configuration
        self.fixation_timer = config['PHOTO_TIMER']
        self.flag_timer = False  # starts out assuming fixated
        self.imageObject = None
        self.photo_gen = None
        # tells calibration routine when it should care about fixation for photos
        self.check_eye = False  # true means check fixation, false means stop checking
        self.photo_window = []  # where we will store the fixation window for photos
        self.time_stash = 0  # used to keep track of timing
        # this will change when finished with all sets
        self.cal_pts_per_photo = config['CAL_PTS_PER_PHOTO']
        total_cal_points = config['POINT_REPEAT'] * config['X_POINTS'] * config['Y_POINTS']
        num_photos_in_set = config['NUM_PHOTOS_IN_SET']
        num_poss_photos = total_cal_points // self.cal_pts_per_photo
        num_sets = num_poss_photos // num_photos_in_set
        #print num_sets
        # show each set twice, so just need half that many
        num_sets //= 2
        num_sets = 1
        #print num_sets
        try:
            last_index = config['LAST_PHOTO_INDEX']
        except KeyError:
            last_index = 0
        self.index_list = create_index_list(num_photos_in_set, num_sets, last_index)
        #print('index list', self.index_list)
        self.end_index = 0
        #photo_size = [1280, 800]
        # ratio of photo is approximately the same as the screen (3:4), which means
        # about same number of pixels in x and y to get same ratio. Not really intuitive.
        photo_size = [600, 600]
        #photo_size = [1000, 800]
        self.tolerance = tuple([x/2 for x in photo_size])
        #print('photo tolerance', self.tolerance)

    def load_all_photos(self):
        #print 'load all photos'
        for file_name in os.listdir(self.config['PHOTO_PATH']):
            #print file_name
            if file_name.endswith('.bmp'):
                self.photo_names.append(os.path.join(self.config['PHOTO_PATH'], file_name))
        if self.index_list[-1] > len(self.photo_names):
            raise Exception("Not enough Photos in this directory")
        test = self.load_photo_set()
        #print test

    def load_photo_set(self):
        #print 'load photo set'
        try:
            start_ind = self.index_list.pop(0)
            end_ind = self.index_list.pop(0)
            self.end_index = end_ind
        except IndexError:
            #print 'end of index!'
            return False
        self.photo_set = self.photo_names[start_ind:end_ind]
        #print self.photo_set
        self.photo_gen = self.get_photo()
        return True

    def get_photo(self):
        for photo in self.photo_set:
            yield photo

    def show_photo(self):
        #print 'show photo and tolerance'
        try:<commit_msg>photos now presented in random order<commit_after>from __future__ import division
from direct.gui.OnscreenImage import OnscreenImage
from direct.showbase.MessengerGlobal import messenger
from panda3d.core import LineSegs, BitMask32
import os
from random import shuffle
from time import time


class Photos():

    def __init__(self, base, config=None, logging=None):
        # photo location
        self.base = base
        self.config = config
        self.logging = logging

        self.photo_names = []
        self.photo_set = []
        # this variable will change, and then be re-set with the configuration
        self.fixation_timer = config['PHOTO_TIMER']
        self.flag_timer = False  # starts out assuming fixated
        self.imageObject = None
        self.photo_gen = None
        # tells calibration routine when it should care about fixation for photos
        self.check_eye = False  # true means check fixation, false means stop checking
        self.photo_window = []  # where we will store the fixation window for photos
        self.time_stash = 0  # used to keep track of timing
        # this will change when finished with all sets
        self.cal_pts_per_photo = config['CAL_PTS_PER_PHOTO']
        total_cal_points = config['POINT_REPEAT'] * config['X_POINTS'] * config['Y_POINTS']
        num_photos_in_set = config['NUM_PHOTOS_IN_SET']
        num_poss_photos = total_cal_points // self.cal_pts_per_photo
        num_sets = num_poss_photos // num_photos_in_set
        #print num_sets
        # show each set twice, so just need half that many
        num_sets //= 2
        num_sets = 1
        #print num_sets
        try:
            last_index = config['LAST_PHOTO_INDEX']
        except KeyError:
            last_index = 0
        self.index_list = create_index_list(num_photos_in_set, num_sets, last_index)
        #print('index list', self.index_list)
        self.end_index = 0
        #photo_size = [1280, 800]
        # ratio of photo is approximately the same as the screen (3:4), which means
        # about same number of pixels in x and y to get same ratio. Not really intuitive.
        photo_size = [600, 600]
        #photo_size = [1000, 800]
        self.tolerance = tuple([x/2 for x in photo_size])
        #print('photo tolerance', self.tolerance)

    def load_all_photos(self):
        #print 'load all photos'
        for file_name in os.listdir(self.config['PHOTO_PATH']):
            #print file_name
            if file_name.endswith('.bmp'):
                self.photo_names.append(os.path.join(self.config['PHOTO_PATH'], file_name))
        if self.index_list[-1] > len(self.photo_names):
            raise Exception("Not enough Photos in this directory")
        test = self.load_photo_set()
        #print test

    def load_photo_set(self):
        #print 'load photo set'
        try:
            start_ind = self.index_list.pop(0)
            end_ind = self.index_list.pop(0)
            self.end_index = end_ind
        except IndexError:
            #print 'end of index!'
            return False
        # want photos presented in different order second time,
        # so shuffle list.
        self.photo_set = shuffle(self.photo_names[start_ind:end_ind])
        #print self.photo_set
        self.photo_gen = self.get_photo()
        return True

    def get_photo(self):
        for photo in self.photo_set:
            yield photo

    def show_photo(self):
        #print 'show photo and tolerance'
        try:
{'fraction_non_alphanumeric': 0.07967193907439953, 'fraction_numerical': 0.00995899238429994, 'mean_word_length': 2.370681145113524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2902516', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1955, 'n_words': 579}