Exemple #1
0
 def buildCategories(self):
     multiclass_exp = self.buildMulticlassClassifier()
     train = self.multiclass_model.datasets.train_instances
     test  = self.multiclass_model.datasets.test_instances
     all_instances = copy.deepcopy(test)
     all_instances.union(train)
     if test.numInstances() > 0:
         predicted_families = self.multiclass_model.testing_monitoring.getPredictedLabels()
         all_families       = list(predicted_families) + train.families
         predicted_proba    = self.multiclass_model.testing_monitoring.getAllPredictedProba()
         for family in train.families:
             probas = [int(family == s) for s in self.multiclass_model.class_labels]
             predicted_proba = np.vstack((predicted_proba, np.array(probas)))
     else:
         all_families    = self.annotated_instances.families
         predicted_proba = None
         for family in self.annotated_instances.families:
             probas = [int(family == s) for s in self.multiclass_model.class_labels]
             if predicted_proba is None:
                 predicted_proba = np.array(probas)
             else:
                 predicted_proba = np.vstack((predicted_proba, np.array(probas)))
     labels_values = list(self.multiclass_model.class_labels)
     assigned_categories = [labels_values.index(x) for x in all_families]
     self.categories = Categories(multiclass_exp,
                                  all_instances,
                                  assigned_categories,
                                  predicted_proba,
                                  self.label,
                                  self.multiclass_model.class_labels)
	def get_category_by_id(self, cat_id):
		if cat_id == None:
			return None
		Category = Categories(self.db)
		category = Category.find_by_id(cat_id)
		if not category:
			return None
		return category
def remove_category():
    '''Function used to remove a category from the txt database'''

    # read the input and create a new python object
    categoryToRemove = Category(input('What category you want to remove?\n'))

    # remove the category
    Categories.remove_category(categoryToRemove)

    print("The category was removed.")
    input(READ_ENTER_KEY)
def add_category():
    '''Function used to display the jewlery menu in the console'''

    # read the input and create a new python object
    newCategory = Category(input('What category you want to add?\n'))

    # load the new category in the txt database
    Categories.add_category(newCategory)

    print( str(newCategory) + ' added successfully')
    input("\nPress enter key in order to continue\n")
	def get_or_create_category_by_name(self, cat_name, gender=None, parent=None):
		if cat_name == None:
			return None
		if gender != None:
			gender = gender["id"]
		if parent != None:
			parent = parent["id"]
		Category = Categories(self.db)
		category = Category.find_by_name_and_gender(cat_name.strip(), gender)
		if not category:
			category = Category.save(cat_name.strip(), gender=gender, category=parent)
		if not category:
			return None
		return category
 def setCategories(self, all_instances, assigned_categories, predicted_proba):
     self.categories = Categories(self.iteration,
                                  all_instances,
                                  assigned_categories,
                                  predicted_proba,
                                  self.label,
                                  self.multiclass_model.class_labels)
Exemple #7
0
 def __init__(self, nTrial, nStim):
     self.nTrial = nTrial
     self.nStim = nStim
     self.categs = Categories(nTrial, nStim)
     self.stims = self.categs.encDF
     #        self.trials = data.TrialHandler(self.stims,
     #                                        1,
     #                                        method='sequential')
     self.poslist = []
Exemple #8
0
 def uploader(self, updown):
     while True:
         images = updown.q.get()
         if(images):
             for image in images:
                 cat = Categories(image[2])
                 cat = cat.find_category()
                 desc = str(image[8]) + ", " + str(image[9])
                 url = self.base_url + image[1]
                 date = image[4]
                 lat = image[5]
                 lon = image[6]
                 description = Description(desc, url, date, cat, lat, lon)
                 print description.get_desc()
                 up = Upload(description=description, file_name=image[13])
                 up.perform()
                 self.db.update_image_uploaded(image[3])
         time.sleep(120)
Exemple #9
0
    def __init__(self,nTrial,nStim):
        '''
        Parameters
        ----------
        
        nTrial: number of runs for a subject
        
        nStim: number of new images used in each phase in a trial
        
        '''
        
        self.log = logging.LogFile(f='imTaskLogFile')
        self.nTrial = nTrial
        self.nStim = nStim
        self.categs = Categories(nTrial,nStim)
        self.encDict = self.categs.encDF.to_dict(orient="index")
        self.recDict = self.categs.recDF.to_dict(orient="index")

        self.stimpos = {'0':(-250.0, 250.0),
                        '1':(250.0, 250.0),
                        '2':(250.0, -250.0),
                        '3':(-250.0, -250.0)}
        self.outputlist = []
        
        self.encInstStartText = '''\
            Memorize the following images and
            their location on screen.
            Press space to start.\
                                '''.format()
        
        self.recInstStartText = '''\
            A series of {x} images will appear.
            Indicate if shown image corresponds to a previously seen image
            and in which quadrant it has appeared earlier.
            Press SPACE to start\
                             '''.format(x=self.nStim+1)
        
        self.recInstText1 = '''\
            Have you seen this picture before?
            If yes, press "y". If not, press "n".\
                         '''.format()
        
        self.recInstText2 = '''\
            Where have you seen it? 
            Press 0, 1, 2 or 3 to answer\
                         '''.format()
                         
        self.recInstPosText = '''\
            Where have you seen it?
            0 = upper-left, 1 = upper-right
            2 = lower-left, 3 = lower-right\
                           '''.format()
        
        self.ansSaveText = 'Answer saved!'
        
        self.endText = 'Thank you for your time, goodbye!'
def display_categories():
    print('The categories available in the jewlery shop are: \n')

    # Get a list with the categories
    categoriesList = Categories.load_categories()

    # Display the categories retrieved in the list
    for category in categoriesList:
        print(category)

    input(READ_ENTER_KEY)
Exemple #11
0
    def __init__(self, whichTrial, nTrial, nStim):
        self.whichTrial = whichTrial
        self.nTrial = nTrial
        self.nStim = nStim
        self.categs = Categories(nTrial, nStim)
        self.encDict = self.categs.encDF.to_dict(orient="index")
        self.thisEncTrial = self.encDict[self.whichTrial]
        self.recDict = self.categs.recDF.to_dict(orient="index")
        self.thisRecTrial = self.recDict[self.whichTrial]
        self.thisTrialTarg = self.categs.Targs[self.whichTrial]
        self.encStimlist = []
        self.answerlist = []
        self.stimpos = {
            '0': (-250.0, 250.0),
            '1': (250.0, 250.0),
            '2': (250.0, -250.0),
            '3': (-250.0, -250.0)
        }

        self.targetPos = self.getTargPos()

        self.encInstStartText = '''\
            Memorize the following images and
            their location on screen.
            Press space to start.\
                                '''.format()

        self.recInstStartText = '''\
            A series of {x} images will appear.
            Indicate if shown image corresponds to a previously seen image
            and in which quadrant it has appeared earlier.
            Press SPACE to start\
                             '''.format(x=self.nStim + 1)

        self.recInstText1 = '''\
            Have you seen this picture before?
            If yes, press "y". If not, press "n".\
                         '''.format()

        self.recInstText2 = '''\
            Where have you seen it? 
            Press 0, 1, 2 or 3 to answer\
                         '''.format()

        self.recInstPosText = '''\
            Where have you seen it?
            0 = upper-left, 1 = upper-right
            2 = lower-left, 3 = lower-right\
                           '''.format()

        self.ansSaveText = 'Answer saved!'

        self.endText = 'Thank you for your time, goodbye!'
Exemple #12
0
def adminMenu():
    print("                   ~~ Administration MAIN MENUE ~~\n\n")
    print("                       1- Manage Categories")
    print("                       2- Manage Products")
    print("                       3- Manage Customers\n")
    manageGRP = input("Please choose your option [1-3] >>")
    # admin select manage categories
    if manageGRP[:1] == '1':
        clear()
        Category = Categories()
        Category.main()
        # admin select manage Products
    elif manageGRP[:1] == '2':
        clear()
        product = Products()
        product.main()
        # admin select manage Customers
    elif manageGRP[:1] == '3':
        clear()
        # Category = Categories()
        # Category.main()
    else:
        print("Invalid Option")
Exemple #13
0
def search_categories(categories, combobox):
    """
    * Parameter: categories  (etree element -Tag- 'Categories)
    * Parameter: combobox (Qt Combobox object)
    * Create Categories object -Note- Pass opt parameter Scan as True
    * Iterate over category (etree element tag 'Category) in categories
    * Get name of category (attrib 'Name')
    * Execute add_category method for each category (Category Object)
    """

    categories_object = Categories.add(categories.getparent(), combobox, True)
    for category in categories:
        name = category.attrib["Name"]
        categories_object.add_category(name, True)
Exemple #14
0
    def check_categories(self):
        """
        * Check if the categories checkbox is selected
        * Add Categories object if it is checked
        * Delete Categories object if it is not checked
        * Update category fields
        * Display error message if AttributeError occurs
        """

        try:
            status = self.categoryCheckbox.isChecked()
            if status:
                root = self.tree.getroot()
                self.categories = Categories.add(root, self.category_box, False)
            else:
                self.categories.delete()
                self.categories = None
            set_software_tags(self)
            update_category_fields(self, status)
        except AttributeError:
            self.statusBar().showMessage('No file selected.', 1500)
 def __init__(self,nTrial,nStim):
     self.nTrial = nTrial
     self.nStim = nStim
     self.categs = Categories(nTrial,nStim)
     self.encResults = pd.read_csv(os.getcwd()+'\\stimDF.csv')
     self.stims = self.categs.recDF
     self.TargStims = self.categs.Targs
     
     self.stimpos = {'0':np.array((-250.0, 250.0)),
                     '1':np.array((250.0, 250.0)),
                     '2':np.array((250.0, -250.0)),
                     '3':np.array((-250.0, -250.0))}
     
     self.instStartText = '''\
     ... A series of {x} images will appear.
     ... Indicate if shown image corresponds to a previously seen image
     ... and in which quadrant it has appeared earlier.
     ... Press SPACE to start\
                          '''.format(x=len(self.stims)+1)
     
     self.inst1Text = '''\
     ... Have you seen this picture before?
     ... If yes, press "y". If not, press "n".\
                      '''.format()
     
     self.inst2Text = '''\
     ... Where have you seen it? 
     ... Press 0, 1, 2 or 3 to answer\
                      '''.format()
                      
     self.instPosText = '''\
     ... Where have you seen it?
     ... 0 = upper-left, 1 = upper-right
     ... 2 = lower-left, 3 = lower-right\
                        '''.format()
     
     self.ansSaveText = 'Answer saved!'
Exemple #16
0
  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    action=self.request.get('action')
    output='error'

    if action == "login":
         user = users.get_current_user()

         if user:
            output=self.createResponseXML('true')
         else:
            output=self.createResponseXML('false') 
    if action == "regtemp":
         self.redirect(users.create_login_url("/loggedin.html"))

         output = 'redirected'
    if action =="remove":
         user = users.get_current_user()
         if user:
            id=self.request.get('id')
            deleteSession(id)
            output=self.createResponseXML('true')
         else:
            output=self.createResponseXML('false')   
    if action == "save":
         doc = xml.dom.minidom.parseString(self.request.get('urls'))
         doc = doc.childNodes[0]
         user = users.get_current_user()
         if user:
            output=self.createResponseXML('true')
            name=doc.getAttribute("name")
            categories_all = db.GqlQuery("SELECT * FROM Categories order by id desc limit 1")
            curid=0
            for cat in categories_all:
               curid=cat.id+1;
            for e in doc.childNodes:
                category= Categories()
                category.user=user.nickname()
                category.name=name
                category.id=curid
                category.url=e.getAttribute('link')
                category.put()  

         else:
            output=self.createResponseXML('false')   
    if action == "load":
         doc = xml.dom.minidom.Document()
         urlsChild = doc.createElement("urls")
         doc.appendChild(urlsChild)
         urlsChild=doc.childNodes[0]
         user = users.get_current_user()
         if user:
            id=self.request.get("id")
            categories_all = db.GqlQuery("SELECT * FROM Categories where id="+id)
            for cat in categories_all:
               urlsChild.setAttribute('name',cat.name)
               linkChild=doc.createElement("url")
               linkChild.setAttribute('link',cat.url)
               urlsChild.appendChild(linkChild)
            output=doc.toxml()
    
         else:
            output=self.createResponseXML('false')
    if action == "list":
         doc = xml.dom.minidom.Document()
         urlsChild = doc.createElement("categories")
         doc.appendChild(urlsChild)
         urlsChild=doc.childNodes[0]
         user = users.get_current_user()
         if user:
            categories_all = db.GqlQuery("SELECT * FROM Categories where user='******'")
            unique_results = []
            for cat in categories_all:
               if cat.id not in unique_results:
                  linkChild=doc.createElement("cat")
                  linkChild.setAttribute('name',cat.name)
                  linkChild.setAttribute('id',str(cat.id))
                  urlsChild.appendChild(linkChild)
                  unique_results.append(cat.id)
            output=doc.toxml()

         else:
            output=self.createResponseXML('false') 
    if output == "error":
       self.redirect('/tabinfo.html')
    self.response.out.write(output)
Exemple #17
0
class RareCategoryDetectionAnnotationQueries(AnnotationQueries):

    def __init__(self, iteration, label, proba_min, proba_max,
            multiclass_model = None,
            multiclass_exp = None):
        AnnotationQueries.__init__(self, iteration, label)
        self.proba_min = proba_min
        self.proba_max = proba_max
        self.rare_category_detection_conf = self.iteration.experiment.conf.rare_category_detection_conf
        self.multiclass_model = multiclass_model
        self.multiclass_exp = multiclass_exp

    def run(self, already_queried = None):
        self.runModels(already_queried = already_queried)
        start_time = time.time()
        self.generateAnnotationQueries()
        self.generate_queries_time = time.time() - start_time
        self.exportAnnotationQueries()
        self.generateClusteringVisualization()

    def runModels(self, already_queried = None):
        df = matrix_tools.extractRowsWithThresholds(self.predictions,
                self.proba_min, self.proba_max, 'predicted_proba')
        if already_queried is not None:
            self.predicted_ids = list(set(df.index).difference(set(already_queried)))
        else:
            self.predicted_ids = list(df.index)
        datasets = self.iteration.datasets
        self.annotated_instances = datasets.getAnnotatedInstances(label = self.label)
        self.families_analysis   = self.familiesAnalysis()
        if self.families_analysis:
            self.annotations_type = 'families'
            start_time = time.time()
            self.buildCategories()
            self.analysis_time = time.time() - start_time
            self.categories.setLikelihood(self.iteration.iteration_number)
        else:
            self.annotations_type = 'individual'
            self.categories       = None
            self.analysis_time    = 0

    def generateAnnotationQueries(self):
        num_annotations = self.rare_category_detection_conf.num_annotations
        if not self.families_analysis:
            selected_instances = self.predicted_ids
            if len(selected_instances) > num_annotations:
                selected_instances = random.sample(selected_instances, num_annotations)
            self.annotation_queries = []
            for instance_id in selected_instances:
                predicted_proba = self.predictions.loc[instance_id]['predicted_proba']
                query = AnnotationQuery(instance_id, predicted_proba, self.label, None)
                self.annotation_queries.append(query)
        else:
            self.categories.generateAnnotationQueries(self.rare_category_detection_conf)

    def exportAnnotationQueries(self):
        if not self.families_analysis:
            AnnotationQueries.exportAnnotationQueries(self)
        else:
            filename  = self.iteration.output_directory
            filename += 'toannotate_' + self.label + '.json'
            self.categories.exportAnnotationQueries(filename)

    def annotateAuto(self):
        if not self.families_analysis:
            AnnotationQueries.annotateAuto(self)
        else:
            self.categories.annotateAuto(self.iteration)

    def getManualAnnotations(self):
        if not self.families_analysis:
            AnnotationQueries.getManualAnnotations(self)
        else:
            self.categories.getManualAnnotations(self.iteration)

    def checkAnnotationQueriesAnswered(self):
        if not self.families_analysis:
            return AnnotationQueries.checkAnnotationQueriesAnswered(self)
        else:
            return self.categories.checkAnnotationQueriesAnswered(self.iteration)

    #######################
    ### Private methods ###
    #######################

    def createMulticlassExperiment(self):
        conf = self.rare_category_detection_conf.classification_conf
        exp  = self.iteration.experiment
        name = '-'.join(['AL' + str(exp.experiment_id),
                         'Iter' + str(self.iteration.iteration_number),
                         self.label,
                         'analysis'])
        multiclass_exp = ClassificationExperiment(exp.project, exp.dataset, exp.session,
                                                  experiment_name = name,
                                                  labels_id = exp.labels_id,
                                                  parent = exp.experiment_id)
        multiclass_exp.setFeaturesFilenames(exp.features_filenames)
        multiclass_exp.setClassifierConf(conf)
        multiclass_exp.createExperiment()
        multiclass_exp.export()
        return multiclass_exp

    def buildCategories(self):
        multiclass_exp = self.buildMulticlassClassifier()
        train = self.multiclass_model.datasets.train_instances
        test  = self.multiclass_model.datasets.test_instances
        all_instances = copy.deepcopy(test)
        all_instances.union(train)
        if test.numInstances() > 0:
            predicted_families = self.multiclass_model.testing_monitoring.getPredictedLabels()
            all_families       = list(predicted_families) + train.families
            predicted_proba    = self.multiclass_model.testing_monitoring.getAllPredictedProba()
            for family in train.families:
                probas = [int(family == s) for s in self.multiclass_model.class_labels]
                predicted_proba = np.vstack((predicted_proba, np.array(probas)))
        else:
            all_families    = self.annotated_instances.families
            predicted_proba = None
            for family in self.annotated_instances.families:
                probas = [int(family == s) for s in self.multiclass_model.class_labels]
                if predicted_proba is None:
                    predicted_proba = np.array(probas)
                else:
                    predicted_proba = np.vstack((predicted_proba, np.array(probas)))
        labels_values = list(self.multiclass_model.class_labels)
        assigned_categories = [labels_values.index(x) for x in all_families]
        self.categories = Categories(multiclass_exp,
                                     all_instances,
                                     assigned_categories,
                                     predicted_proba,
                                     self.label,
                                     self.multiclass_model.class_labels)

    def buildMulticlassClassifier(self):
        if self.multiclass_model is not None:
            return self.multiclass_exp
        multiclass_exp = self.createMulticlassExperiment()
        datasets = self.iteration.datasets
        predicted_instances = datasets.getInstancesFromIds(self.predicted_ids)
        multiclass_datasets = ClassifierDatasets(multiclass_exp.classification_conf)
        multiclass_datasets.train_instances = self.annotated_instances
        multiclass_datasets.test_instances  = predicted_instances
        multiclass_datasets.setSampleWeights()
        self.multiclass_model = multiclass_exp.classification_conf.model_class(
                multiclass_exp.classification_conf,
                multiclass_datasets,
                cv_monitoring = True)
        self.multiclass_model.run(multiclass_exp.getOutputDirectory(),
                                  multiclass_exp)
        return multiclass_exp

    # A multi class supervised model is learned from the annotated instances if:
    #       - there are at most 2 families
    #       - the second most represented family has at least 2 instances
    def familiesAnalysis(self):
        num_families = len(self.annotated_instances.getFamiliesValues())
        if num_families < 2:
            return False
        families_counts = self.annotated_instances.getFamiliesCount()
        families_counts = [(k, x) for k, x in families_counts.iteritems()]
        families_counts.sort(key=lambda tup: tup[1], reverse = True)
        if families_counts[1][1] < 2:
            return False
        return True

    def createClusteringExperiment(self):
        conf = ClusteringConfiguration(self.categories.numCategories())
        exp  = self.iteration.experiment
        name = '-'.join(['AL' + str(exp.experiment_id),
                         'Iter' + str(self.iteration.iteration_number),
                         self.label,
                         'clustering'])
        clustering_exp = ClusteringExperiment(exp.project, exp.dataset, exp.session,
                                              conf,
                                              labels_id = exp.labels_id,
                                              experiment_name = name,
                                              parent = exp.experiment_id)
        clustering_exp.setFeaturesFilenames(exp.features_filenames)
        clustering_exp.createExperiment()
        clustering_exp.export()
        return clustering_exp

    def generateClusteringVisualization(self):
        if self.families_analysis:
            self.clustering_exp = self.createClusteringExperiment()
            clustering = Clustering(self.categories.instances,
                                    self.categories.assigned_categories)
            clustering.generateClustering(self.clustering_exp.getOutputDirectory(),
                                          None, None)
        else:
            self.clustering_exp = None
Exemple #18
0
 def __init__(self, parent_exp, iteration, instances, assigned_categories,
              assignment_proba, label, category_labels):
     Categories.__init__(self, iteration, instances, assigned_categories, assignment_proba,
                         label, category_labels)
     self.experiment = parent_exp
Exemple #19
0
    def get(self):
        self.response.headers["Content-Type"] = "text/html"

        user = users.get_current_user()

        if user:
            htmlUtils = HtmlUtils()

            output = htmlUtils.generateStart("TabSender: My account")
            output += htmlUtils.generateDefaultMenu()
            output += htmlUtils.generateMenuEnd()

            newShares = getNewShares(user.nickname())

            type = self.request.get("type")

            if not type or type == "browse":
                output += '<h1><span class="colouredText">' + user.nickname() + "</span>'s shares on server:</h1><ul>"
                if newShares == 0:
                    output += 'No new shares.<br />Return to <a href="/tabinfo.html">your account</a>.'
                else:
                    output += "<ul>\n"
                    sharesForUser = db.GqlQuery("SELECT * FROM Share WHERE user='******'")
                    for share in sharesForUser:
                        output += (
                            '<li><a href="/share.html?type=details&id='
                            + str(share.id)
                            + '">'
                            + getNameForID(share.sessionid)
                            + '</a> by <span class="colouredText">'
                            + share.creator
                            + '</span><br /><span class="colouredText">Message</span>: '
                            + share.message
                            + "<br />\n"
                        )
                        output += (
                            '<a href="/share.html?type=accept&id='
                            + str(share.id)
                            + '"><img class="imageURL" src="/html/images/add.png" />Accept</a>\n'
                        )
                        output += (
                            '<a href="/share.html?type=cancel&id='
                            + str(share.id)
                            + '"><img class="imageURL" src="/html/images/cancel.png" />Cancel</a>\n'
                        )
                        output += "</li>\n"
                    output += "</ul>\n"
            #        if type == 'browsedb':
            #            sharesTable = db.GqlQuery("SELECT * FROM Share")
            #            for share in sharesTable:
            #                output += str(share.user) + ' ' + str(share.sessionid) + ' ' + str(share.message) + ' ' + str(share.creator) + '<br />'
            elif type == "cancel":
                id = self.request.get("id")
                shareToCancel = db.GqlQuery("SELECT * FROM Share WHERE id=:1", int(id))
                for share in shareToCancel:
                    share.delete()
                self.redirect("/share.html")
            elif type == "accept":
                id = self.request.get("id")

                sessionid = -1
                shareToAccept = db.GqlQuery("SELECT * FROM Share WHERE id=:1", int(id))
                for share in shareToAccept:
                    sessionid = share.sessionid
                    break

                sessionToCopy = db.GqlQuery("SELECT * FROM Categories WHERE id=:1", sessionid)

                categories_all = db.GqlQuery("SELECT * FROM Categories ORDER BY id DESC LIMIT 1")
                curid = 0
                for cat in categories_all:
                    curid = cat.id + 1

                copiedSession = []
                for sess in sessionToCopy:
                    copiedPart = Categories()
                    copiedPart.id = curid
                    copiedPart.name = sess.name
                    copiedPart.url = sess.url
                    copiedPart.user = user.nickname()
                    copiedPart.put()

                for share in shareToAccept:
                    share.delete()
                self.redirect("/tabinfo.html")

            output += htmlUtils.generateMainPartEnd()

            #        if newShares == 0:
            #            output += 'You have no new shares.'
            #        else:
            #            output += 'TO FIX!!!'

            output += htmlUtils.generateEnd()

            self.response.out.write(output)
        else:
            self.redirect(users.create_login_url("/share.html"))
Exemple #20
0
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 22 00:37:31 2019

@author: Francois
"""

from psychopy import core
from psychopy import data
from psychopy import event
from psychopy import visual
from Categories import Categories
from randSign import randSign

trials = data.TrialHandler(Categories(2, 8).trialslist, 1, method='sequential')


def runtask(trials):
    win = visual.Window(size=(1000, 1000), color=(0, 0, 0), units='pix')
    eachTrial = 0
    while eachTrial <= len(trials.trialList) - 1:

        def encodingphase(
                win
        ):  # Shows stimuli in each trial list in "trials"(also list)

            #stimpos = [(250.0, 250.0),(-250.0, -250.0),(250.0, -250.0),(-250.0, -250.0)] #Possibly replacing randSign()
            instructionStart = visual.TextStim(
                win,
                text=
                'Memorize the following images and their location on screen. Press space to start.'
Exemple #21
0
 def __init__(self):
     self.trials = data.TrialHandler(Categories(2, 5).trialslist,
                                     1,
                                     method='sequential')
    def main(self):
        product = Products()
        self.clear()
        print("                    ***** Manage Products *****\n\n")
        print("                       1- Add a new product")
        print("                       2- Edit existing product")
        print("                       3- Remove existing product\n")
        productOperation = input("Please choose your option [1-3] >>")

        if productOperation[:1] == '1':
            category = Categories()
            self.clear()
            # Retrive real state data from database
            print("Options:")
            print(
                "\n\n1- Choose a category from the existing categories to add your product to")
            print("\n2- Add a new category to connect your product to")

            option = input("\nPlease make a selection [1-2] >>")
            if category.ValidateUserInputAsNumber(option):
                option = int(option)
                if(option == 1 or option == 2):
                    if(option == 1):
                        self.clear()

                        SQLStatment = category.selectStatment(
                            "*", "categories", "")
                        cursor = self.executeSQLStatment(SQLStatment)
                        rows = cursor.fetchall()
                        cursor.close()
                        print(
                            "-------------------------------------------------------------:")

                        print(

                            "---------------------- Categories List ----------------------")
                        #ProductCategory = Category()
                        if(rows):

                            counter = 0
                            for row in rows:

                                print(f"{counter+1} - {row[1]} ")
                                counter += 1
                        categoryNo = input(
                            "\n\nPlease enter a valid category from the list above>>")
                        if category.ValidateUserInputAsNumber(categoryNo):
                            categoryNo = int(categoryNo)
                            if(categoryNo > 0 and categoryNo <= counter and categoryNo is not None):
                                rowIndex = int(categoryNo)-1
                                category_id = int(rows[rowIndex][0])
                                print("\n\n ***New Product Information:***")
                                productName = input(
                                    "Please enter the product name >> ")
                                productDescription = input(
                                    "Please enter the product description >> ")
                                productPrice = input(
                                    "Please enter the product price >> ")
                                self.addNewProduct(
                                    category_id, productName, productDescription, productPrice)

                    else:
                        categoryName = input(
                            "Please enter the Category name that you want to add >>")
                        rows = category.addNewCategory(categoryName)
                        category_id = rows.fetchone()[0]
                        print("\n\n ***New Product Information:***")
                        productName = input(
                            "Please enter the product name >> ")
                        productDescription = input(
                            "Please enter the product description >> ")
                        productPrice = input(
                            "Please enter the product price >> ")
                        self.addNewProduct(
                            category_id, productName, productDescription, productPrice)

                else:
                    print("invalid option")

        elif productOperation[:1] == '2':
            # self.EditProduct("Edit")
            # self.editExistingProduct(

            print("\n\n- Search Products by Name -")
            productName = input(
                "Please enter a keyword to search for Product Name >> ")
            whereStatment = f"LOWER(product_name) like '%{productName}%' "
            self.editExistingProduct(whereStatment)
        elif productOperation[:1] == '3':
            self.searchMainMenu("Delete")

        else:

            print("Invalid entry\n")