def get_all_games(): # Load template clips.Clear() clips.Load("clips/templates.clp") clips.Load("clips/games.clp") clips.Reset() # Run clips clips.Run() # load game from facts games = [] facts = clips.FactList() for fact in facts: if fact.Relation != 'game': continue game = { 'id': int(fact.Slots['id']), 'name': fact.Slots['name'], 'description': fact.Slots['description'], 'genre': list(fact.Slots['genre']), 'platform': list(fact.Slots['platform']), 'age-range': fact.Slots['age-range'], 'game-mode': fact.Slots['game-mode'], 'release-date': fact.Slots['release-date'], 'length': fact.Slots['length'], 'difficulty': fact.Slots['difficulty'], 'image': fact.Slots['image'] } games.append(game) # print fact.Slots['id'], list(fact.Slots['genre']) return games
def updatePeopleLocation(self): for r in self.rooms: r.emptyRoom() disponibles = [] facts = clips.FactList() for f in facts: vector = f.PPForm().replace("(", "").replace(")", "").split() if vector[1] == "URJ6": # (Situacion_actual ?pers ?hab) print(vector) id = vector[2] habitacion = vector[3] room = self.getRoom(habitacion) if room != None: type = "Usuario" if "usuario" in id else "Empleado" if type == "Usuario": tramite = "TG" if "TG" in id else "TE" id = id.replace("usuario", "u") id = id.replace('"', '') else: if "Director" in id or "Recepcionista" in id: tramite = "" elif "G" in id: tramite = "TG" elif "E" in id: tramite = "TE" room.addPerson(Person(id, type, tramite, room.getId())) if vector[1] == "Disponible": disponibles.append(vector[2]) if vector[1] == "Luz": habitacion = vector[2] status = vector[3] room = self.getRoom(habitacion) if room != None: room.switch(status.upper()) if vector[1] == "ciclo": self.ciclo = vector[2] if vector[1] == "hora_actual": self.hora = vector[2] if vector[1] == "minutos_actual": self.minutos = vector[2] if vector[1] == "segundos_actual": self.segundos = vector[2] for r in self.rooms: for p in r.getPeople(): if p.getId() in disponibles: p.disp = True else: p.disp = False
def changePanel(frame, id): if id == 1: frame.panelOne.Destroy() frame.panelTwo = Panel_choose(frame) frame.panelTwo.m_choice1.SetItems(selections[0]) frame.panelTwo.m_staticText1.SetLabel(questions[step]) elif id == 2: frame.panelOne.Destroy() frame.panelThree = Panel_pic(frame) elif id == 3: frame.panelThree.Destroy() frame.panelTwo = Panel_choose(frame) frame.panelTwo.m_choice1.SetItems(selections[0]) frame.panelTwo.m_staticText1.SetLabel(questions[step]) elif id == 4: frame.panelTwo.Destroy() frame.panelFour = Panel_compare(frame) elif id == 5: frame.panelFour.Destroy() frame.panelOne = Panel_YESorNO(frame) frame.panelOne.m_staticText1.SetLabel(questions[step]) elif id == 6: facts = clips.FactList() # print t # t = clips.StdoutStream.Read() #clips.SaveFacts('./fact.txt') c, s = readFactsFile(facts) frame.panelOne.Destroy() info = getMoreInfo("Tourist Attraction Description.xlsx", s) print len(info) frame.panelFive = Panel_result(frame, c, info)
def resultados(user): cuestiones = [(k[6:], v) for k, v in request.form.items() if k.startswith('hecho_')] for hecho, respuesta in cuestiones: if respuesta == "Si": clips.Assert("(%s (id %s))" % (hecho, user)) elif respuesta == "ingles": clips.Assert("(%s (id %s) (idioma %s))" % (hecho, user, respuesta)) elif respuesta == "frances": clips.Assert("(%s (id %s) (idioma %s))" % (hecho, user, respuesta)) clips.Run() context = {} hechos = clips.FactList()[1:] for h in hechos: if h.Slots['id'] == user: if h.Relation == "alumnoInfantil": context[u'Lengua y cultura inglesas'] = h.Slots['ingles'] context[u'Educación Física'] = h.Slots['efisica'] context[u'Necesidades educativas especiales'] = h.Slots['nde'] context[u'Religión'] = h.Slots['religion'] elif h.Relation == "alumnoPrimaria": context[u'Lengua extranjera: Inglés'] = h.Slots['ingles'] context[u'Lengua extranjera: Francés'] = h.Slots['frances'] context[u'Música'] = h.Slots['musica'] context[u'Educación Física'] = h.Slots['efisica'] context[u'Pedagogía Terapéutica'] = h.Slots['apt'] context[u'Audición y Lenguaje'] = h.Slots['al'] context[u'Religión'] = h.Slots['religion'] h.Retract() break print context lista = u"" for idx, (mencion, puntos) in enumerate( sorted(context.items(), key=lambda x: x[1], reverse=True)): lista += u'<li class="list-group-item"><span class="badge">{3}/5</span><h{0}>{1}.- {2}</h{0}></li>'.format( 6 - puntos, idx + 1, mencion, puntos) return render_template("resultados.html", lista=lista, idx=2)
def OnOpen(self, event): dlg = wx.FileDialog(self, "Selecciona archivo", self.dirname, "", "*.clp", wx.FD_OPEN) if dlg.ShowModal() == wx.ID_OK: self.filename = dlg.GetFilename() self.dirname = dlg.GetDirectory() if (self.filename != ""): os.chdir(self.dirname) self.clipsFile = os.path.join(self.dirname, self.filename) self.simClipsFile = os.path.join(self.dirname, 'CicloControlado2.clp') self.timeClipsFile = os.path.join(self.dirname, 'simulacionoficinaalumnos.clp') clips.Clear() clips.BatchStar(self.simClipsFile) clips.BatchStar(self.clipsFile) clips.BatchStar(self.timeClipsFile) clips.Reset() clips.Run() # Modo de ejecucion for f in clips.FactList(): if "Preguntando" in f.PPForm(): self.nuevoCicloItem.Enable(True) break self.SetStatusText(self.clipsFile) self.office.updatePeopleLocation() self.Refresh() self.OutputFrame.box.Clear() self.OutputFrame.appendText("-> Iniciar simulacion " + time.strftime("%c")) dlg.Destroy()
def printFacts(self): for f in clips.FactList(): print f.PPForm()
def __startGame(self): """Intialize rules and facts of the main environment. This function loads differents modules and create an environment that provides the proper context where a game can be played. """ clips.Eval('(clear)') clips.EngineConfig.Strategy = clips.RANDOM_STRATEGY random.seed() clips.Eval("(seed " + str(random.randint(0, 9999)) + ")") try: # Se cargan una serie de funciones de utilidad, como "minimo" o "mov-valido" funciones.LoadFunctions(clips) # Se inicializan las opciones de juego (deffacts) f1.init_world(clips, self.number_turns) # Se cargan las plantillas ficha-r, ficha, mueve y obstaculo # además de las reglas para el control de los turnos f1.LoadFunctions(clips) mover.LoadFunctions(clips) texto.LoadFunctions(clips) traducirF.LoadFunctions(clips) traducirM.LoadFunctions(clips) nombreFicheroObstaculos = parsear_fichero_obstaculos.generar_reglas_obstaculos( ) if nombreFicheroObstaculos: clips.Load(nombreFicheroObstaculos) os.unlink(nombreFicheroObstaculos) except clips.ClipsError as e: logging.error("####################") logging.error("ERROR de clips: %s", e) logging.error("Mensaje: ") logging.error(clips.ErrorStream.Read()) logging.error("####################") raise FileError("W===============TTTT") logging.info("Parseando ficheros de formación...") temp_form_A = parsear_fichero_formacion.parsear_fichero_formacion( self.teamA[1], "A") temp_form_B = parsear_fichero_formacion.parsear_fichero_formacion( self.teamB[1], "B") self.teamA = (self.teamA[0], temp_form_A) self.teamB = (self.teamB[0], temp_form_B) temp_team = mirroring.mirroring_team(self.teamB[1]) logging.info('Cargando %s', self.teamA[1]) #create a temporally file that mirror the formation of B team, #because it's written thinking in A team try: clips.Load(self.teamA[1]) except clips.ClipsError as e: logging.error("####################") logging.error("ERROR de clips: %s", e) logging.error("Mensaje: ") logging.error(clips.ErrorStream.Read()) logging.error("####################") raise FileError( _('Error parsing the file ') + self.teamA[1] + "\n" + e) logging.info('Cargando %s', self.teamB[1]) try: clips.Load(temp_team) except clips.ClipsError as e: logging.error("####################") logging.error("ERROR de clips: %s", e) logging.error("Mensaje: ") logging.error(clips.ErrorStream.Read()) logging.error("####################") os.remove(temp_team) raise FileError(_('Error parsing the file ') + self.teamB[1]) os.remove(temp_team) os.remove(temp_form_A) os.remove(temp_form_B) try: fA.LoadFunctions(clips) logging.info('Cargando %s', self.teamA[0]) clips.Load(self.teamA[0]) except clips.ClipsError as e: logging.error("####################") logging.error("ERROR de clips: %s", e) logging.error("Mensaje: ") logging.error(clips.ErrorStream.Read()) logging.error("####################") raise FileError(_('Error parsing the file ') + self.teamA[0]) temp_rules = mirroring.mirroring_rules(self.teamB[0]) #same thing that for the formation, but this time using the rules try: fB.LoadFunctions(clips) logging.info('Cargando %s', self.teamB[0]) clips.Load(temp_rules) except clips.ClipsError as e: os.remove(temp_rules) logging.error("####################") logging.error("ERROR de clips: %s", e) logging.error("Mensaje: ") logging.error(clips.ErrorStream.Read()) logging.error("####################") raise FileError( _('Error parsing the file ') + self.teamB[0] + "\n") os.remove(temp_rules) clips.Reset() #restart the environment clips.Run() #start the simulation t = clips.StdoutStream.Read() #print the output clipsOutputFile = open("clipsOutputFile", "w") clipsOutputFile.write(t) clipsOutputFile.close() f = clips.FactList() last_fact = f[len(f) - 1].PPForm() prev_last_fact = f[len(f) - 2].PPForm() winner = self.__define_winner(last_fact, prev_last_fact) return winner