Beispiel #1
0
 def extract(self):
     try:
         median = float(med(self.flux_data))
     except:
         self.ex_error(
             "EXCEPT in medianextractor() most likely flux_data=[]")
     return (median)
Beispiel #2
0
	def rescale_vertices(self, scale, rescaling_type=RescalingTypeMin):
		'''
		Rescales the vertex coordinates so that the minimum dimension (X, Y, Z) is exactly min_scale

		Params:
		scale: (float) scale of the ,esj
                rescaling_type: (int) which dimension to scale along; if not absolute then the min,med,max dim is scaled to be exactly scale
		Returns:
		Nothing. Modified the mesh in place (for now)
		'''
		vertex_array = np.array(self.mesh_.vertices())
		min_vertex_coords = np.min(self.mesh_.vertices(), axis=0)
		max_vertex_coords = np.max(self.mesh_.vertices(), axis=0)
		vertex_extent = max_vertex_coords - min_vertex_coords

		# find minimal dimension
		if rescaling_type == MeshCleaner.RescalingTypeMin:
			dim = np.where(vertex_extent == np.min(vertex_extent))[0][0]
                        relative_scale = vertex_extent[dim]
		elif rescaling_type == MeshCleaner.RescalingTypeMed:
			dim = np.where(vertex_extent == np.med(vertex_extent))[0][0]
                        relative_scale = vertex_extent[dim]
		elif rescaling_type == MeshCleaner.RescalingTypeMax:
			dim = np.where(vertex_extent == np.max(vertex_extent))[0][0]
                        relative_scale = vertex_extent[dim]
		elif rescaling_type == MeshCleaner.RescalingTypeAbsolute:
                        relative_scale = 1.0

		# compute scale factor and rescale vertices
		scale_factor = scale / relative_scale 
		vertex_array = scale_factor * vertex_array
		self.mesh_.vertices_ = vertex_array.tolist()
 def __init__(self, data=[0]):
     self.data    = data
     self.highest = max(data)
     self.lowest  = min(data)
     self.median  = med(data)
     self.average = mean(data)
     for i in self.__dict__:
         call = self.__dict__[i]
         try:   
             self.__setattr__(i, round(float(call), 1))
         except TypeError: 
             self.__setattr__(i, list(map(lambda x: round(x,1), call)))
Beispiel #4
0
    def _rescale_vertices(self, scale, rescaling_type=RescalingTypeMin):
        """
        Rescales the vertex coordinates so that the minimum dimension (X, Y, Z) is exactly min_scale
        
        Params:
        scale: (float) scale of the mesh
        rescaling_type: (int) which dimension to scale along; if not absolute then the min,med,max dim is scaled to be exactly scale
        Returns:
        Nothing. Modified the mesh in place (for now)
        """
        vertex_array = np.array(self.mesh_.vertices())
        min_vertex_coords = np.min(self.mesh_.vertices(), axis=0)
        max_vertex_coords = np.max(self.mesh_.vertices(), axis=0)
        vertex_extent = max_vertex_coords - min_vertex_coords

        # find minimal dimension
        if rescaling_type == MeshProcessor.RescalingTypeMin:
            dim = np.where(vertex_extent == np.min(vertex_extent))[0][0]
            relative_scale = vertex_extent[dim]
        elif rescaling_type == MeshProcessor.RescalingTypeMed:
            dim = np.where(vertex_extent == np.med(vertex_extent))[0][0]
            relative_scale = vertex_extent[dim]
        elif rescaling_type == MeshProcessor.RescalingTypeMax:
            dim = np.where(vertex_extent == np.max(vertex_extent))[0][0]
            relative_scale = vertex_extent[dim]
        elif rescaling_type == MeshProcessor.RescalingTypeRelative:
            relative_scale = 1.0
        elif rescaling_type == MeshProcessor.RescalingTypeDiag:
            diag = np.linalg.norm(vertex_extent)
            relative_scale = diag / 3.0 # make the gripper size exactly one third of the diagonal

        # compute scale factor and rescale vertices
        scale_factor = scale / relative_scale 
        vertex_array = scale_factor * vertex_array
        self.mesh_.vertices_ = vertex_array.tolist()
        self.mesh_._compute_bb_center()
        self.mesh_._compute_centroid()
        self.mesh_.set_center_of_mass(self.mesh_.bb_center_)
Beispiel #5
0
def medfilt(ipt):
    med_len = 31
    output = []
    for i in range(0, len(ipt)):
        #get the values you want the median of
        tmp = []
        for x in range(i - med_len / 2, i + med_len / 2):
            if x < 0:  #out of bounds
                if ipt[0] < 0:
                    tmp.append(.5)
                else:
                    tmp.append(ipt[0])
            elif x >= len(ipt):
                if ipt[len(ipt) - 1] < 0:
                    tmp.append(.5)
                else:
                    tmp.append(ipt[len(ipt) - 1])
            else:
                if ipt[x] < 0:
                    tmp.append(.5)
                else:
                    tmp.append(ipt[x])
        output.append(med(tmp))
    return output
 def extract(self):
     try:
         median = float(med(self.flux_data))
     except:
         self.ex_error("EXCEPT in medianextractor() most likely flux_data=[]")
     return(median)
Beispiel #7
0
def experiment(request, experiment_id):
    exp = Experiment.objects.get(id=experiment_id)
    tasks = Task.objects.filter(Task_user=exp)
    count_g = 0 # посдсчет решенных
    count_b = 0 # подсчет не решенных
    count_nb = 0 # подсчет  счастливых но не ближайших
    full = 0
    times = []
    time_of_task = []
    time_of_task_avg = []
    diff_of_time = [0]
    if exp.Strategy in (1,2,3):
        i = 1
        for t in tasks:
            count = 0
            tm = 0.0
            for v in Variant.objects.filter(Variant_task = t):
                full += 1
                count += 1
                times.append(v.Time)
                tm += v.Time
                if v.Check == 'Решено':
                    count_g += 1
                elif v.Check == 'Счастливый, но не ближайший':
                    count_nb += 1
                else:
                    count_b += 1
            time_of_task.append(tm/count)
            if len(time_of_task) > 1:
                diff_of_time.append(abs(time_of_task[i]-time_of_task[i-1]))
                t.Diff = abs(time_of_task[i]-time_of_task[i-1])
                i += 1
            t.Time = tm
            t.save()
    elif exp.Strategy in (4,5,7,8):
        i = 1
        for t in tasks:
            count = 0
            tm = 0.0
            for v in Variant.objects.filter(Variant_task=t):
                full += 1
                count += 1
                times.append(v.Time)
                tm += v.Time
                if v.Check == 'Решено':
                    count_g += 1
                elif v.Check == 'Счастливый, но не ближайший':
                    count_nb += 1
                else:
                    count_b += 1
            if exp.Strategy == 7 and count != 0:
                time_of_task.append(tm/count)
                t.Time = tm/count
            elif exp.Strategy == 7 and count == 0:
                time_of_task.append(0.0)
            else:
                time_of_task.append(tm)
                t.Time = tm
            if len(time_of_task) > 1:
                diff_of_time.append(abs(time_of_task[i]-time_of_task[i-1]))
                t.Diff = abs(time_of_task[i] - time_of_task[i-1])
                i += 1

            t.save()
    Define_lev(t.id)
    g_pct = count_g/full * 100
    b_pct = count_b/full * 100
    nb_pct = count_nb/full * 100
    median_all = med(times)
    args = {}
    args['tasks'] = tasks
    args['experiment'] = Experiment.objects.get(id=experiment_id)
    args['g_pct'] = g_pct
    args['b_pct'] = b_pct
    args['nb_pct'] = nb_pct
    args['avg_task_time'] = avg(time_of_task)
    args['median_all'] = median_all #медиана времени ответа
    args['avg_of_diff'] = sum(diff_of_time)/(len(diff_of_time)-1)
    args['median_of_diff'] = med(diff_of_time)

    return render_to_response('tasks/experiment.html', args)