Ejemplo n.º 1
0
    def getDevsInstance(self):
        """ Returns the DEVS instance built from YAML file
        """
        from Container import Diagram

        if self.filename_is_valid != True: return False

        try :
            return Diagram.makeDEVSInstance(self.diagram)
        except:
            self.report['devs_instance'] = None
            self.report['success'] = False
            self.report['info'] = traceback.format_exc()
            print(json.dumps(self.report))
            return False
	def __set_properties(self):
		# begin wxGlade: ActivityReport.__set_properties

		self.SetTitle(self._title)

		data = []

		### get user configuration ofr static or dynamic execution
		diagram = self.parent.master.getBlockModel()

		if hasattr(diagram, 'activity_flags'):
			self.static_user_flag, self.dynamic_user_flag = diagram.activity_flags
		else:
			self.static_user_flag = self.dynamic_user_flag = True

		### after simulation, we can display the static and dynamic activity informations
		if self._master and self.dynamic_user_flag:

			L = GetFlatDEVSList(self._master, [])

			### if model have texec attribute, then its selected in the properties panel
			model_list = filter(lambda a: hasattr(a, 'texec'), L)

			### if at least one model has been selected in Activity configuration dialogue
			if len(model_list) != 0:

				d = ActivityData(model_list)

				### A=(Aint+Aext)/H
				H=self._master.timeLast if self._master.timeLast <= self._master.FINAL_TIME else self._master.FINAL_TIME

				Ddata, DrowLabels, DcolLabels = d.getDynamicData(H)

				if self.static_user_flag:
					Sdata, SrowLabels, ScolLabels = d.getStaticData()

					### update data ([1:] to delete the label of the model in case of dynamic data with static data)
					ScolLabels.extend(DcolLabels[1:])

					for i in range(len(Sdata)):
						### ([1:] to delete the label of the model in case of dynamic data with static data)
						Sdata[i].extend(Ddata[i][1:])

					###
					data = Sdata
					colLabels = ScolLabels
				else:
					data = Ddata
					colLabels = DcolLabels

				rowLabels = map(lambda a: str(a), range(len(map(lambda b: b[0], data))))

				d.EndProgressBar()

			### no models are selected from activity plug-in properties panel
			else:
				self.ReportGrid.Show(False)
				wx.MessageBox(_('Please select at least one model in activity configuration panel.'), _('Info'), wx.OK|wx.ICON_INFORMATION)

		### static data
		elif self.static_user_flag:

			### get DEVS model form diagram
			diagram.Clean()
			self._master = Diagram.makeDEVSInstance(diagram)

			### for static infrmations, all model are considered
			L = GetFlatDEVSList(self._master, [])

			model_list = filter(lambda a: hasattr(a.getBlockModel(), 'activity'), L)

			if len(model_list) != 0:
				d = ActivityData(model_list)
				data, rowLabels, colLabels = d.getStaticData()
				d.EndProgressBar()
			else:
				self.ReportGrid.Show(False)
				wx.MessageBox(_('Please select at least one model in activity configuration panel.'), _('Info'), wx.OK|wx.ICON_INFORMATION)

		### populate the grid from data
		if len(data) != 0:

			tableBase = GenericTable(data, rowLabels, colLabels)

			self.ReportGrid.CreateGrid(10, len(colLabels))
			for i in range(len(colLabels)):
				self.ReportGrid.SetColLabelValue(i, colLabels[i])

			self.ReportGrid.SetTable(tableBase)
			self.ReportGrid.EnableEditing(0)
			self.ReportGrid.SetColLabelSize(60)
			self.ReportGrid.SetLabelTextColour('#0000ff') # Blue
			self.ReportGrid.AutoSize()
Ejemplo n.º 3
0
def makeSimulation(filename, T, json_trace=False):
    """
	"""

    from Container import Diagram

    if not json_trace:
        sys.stdout.write(
            _("\nSimulation in batch mode with %s\n") %
            __builtin__.__dict__['DEFAULT_DEVS_DIRNAME'])

    a = Diagram()

    if not json_trace:
        sys.stdout.write(
            _("\nLoading %s file...\n") % (os.path.basename(filename)))
    else:
        json = {'date': time.strftime("%c")}
    json['mode'] = 'no-gui'

    if a.LoadFile(filename):

        if not json_trace:
            sys.stdout.write(_("%s loaded!\n") % (os.path.basename(filename)))
        else:
            json['file'] = filename

        try:
            if not json_trace:
                sys.stdout.write(_("\nMaking DEVS instance...\n"))
            master = Diagram.makeDEVSInstance(a)
        except:
            if not json_trace:
                return False
            else:
                json['devs_instance'] = None
                json['success'] = False
                sys.stdout.write(str(json))
        else:
            if not json_trace:
                sys.stdout.write(_("DEVS instance created!\n"))
            else:
                json['devs_instance'] = str(master)

            if not json_trace:
                sys.stdout.write(_("\nPerforming DEVS simulation...\n"))

            sim = runSimulation(master, T)
            thread = sim.Run()

            first_time = time.time()
            while (thread.isAlive()):
                new_time = time.time()
                output = new_time - first_time
                if not json_trace: Printer(output)

            if not json_trace:
                sys.stdout.write(_("\nDEVS simulation completed!\n"))

        if json_trace:
            json['time'] = output
            json['output'] = []

        ### inform that data file has been generated
        for m in filter(lambda a: hasattr(a, 'fileName'), master.componentSet):
            for i in range(len(m.IPorts)):
                fn = '%s%s.dat' % (m.fileName, str(i))
                if os.path.exists(fn):
                    if not json_trace:
                        sys.stdout.write(
                            _("\nData file %s has been generated!\n") % (fn))
                    else:
                        json['output'].append({
                            'name': os.path.basename(fn),
                            'path': fn
                        })
    else:
        if json_trace:
            json['file'] = None
        json['success'] = True
        sys.stdout.write(str(json))
Ejemplo n.º 4
0
def makeSimulation(filename, T, json_trace=False):
	"""
	"""

	from Container import Diagram

	if not json_trace: sys.stdout.write(_("\nSimulation in batch mode with %s\n")%__builtin__.__dict__['DEFAULT_DEVS_DIRNAME'])

	a = Diagram()

	if not json_trace:
		sys.stdout.write(_("\nLoading %s file...\n")%(os.path.basename(filename)))
	else:
		json = {'date':time.strftime("%c")}
        json['mode']='no-gui'

	if a.LoadFile(filename):

		if not json_trace:
			sys.stdout.write(_("%s loaded!\n")%(os.path.basename(filename)))
		else:
			json['file'] = filename

		try:
			if not json_trace: sys.stdout.write(_("\nMaking DEVS instance...\n"))
			master = Diagram.makeDEVSInstance(a)
		except :
			if not json_trace:
				return False
			else:
				json['devs_instance'] = None
				json['success'] = False
				sys.stdout.write(str(json))
		else:
			if not json_trace:
				sys.stdout.write(_("DEVS instance created!\n"))
			else:
				json['devs_instance'] = str(master)

			if not json_trace: sys.stdout.write(_("\nPerforming DEVS simulation...\n"))

			sim = runSimulation(master, T)
			thread = sim.Run()

			first_time = time.time()
			while(thread.isAlive()):
				new_time = time.time()
				output = new_time - first_time
				if not json_trace: Printer(output)

			if not json_trace: sys.stdout.write(_("\nDEVS simulation completed!\n"))

		if json_trace:
			json['time'] = output
			json['output'] = []

		### inform that data file has been generated
		for m in filter(lambda a: hasattr(a, 'fileName'), master.componentSet):
			for i in range(len(m.IPorts)):
				fn ='%s%s.dat'%(m.fileName,str(i))
				if os.path.exists(fn):
					if not json_trace:
						sys.stdout.write(_("\nData file %s has been generated!\n")%(fn))
					else:
						json['output'].append({'name':os.path.basename(fn), 'path':fn})
	else:
		if json_trace:
			json['file'] = None
        	json['success'] = True
         	sys.stdout.write(str(json))