def get(self, estimate=True): current = ProcessCpuLoadValue(self.pid) previous = self.searchLast(current) self.datas.append(current) tics = current.tics if previous: time = current.timestamp - previous.timestamp tics -= previous.tics else: if not estimate: return None time = current.timestamp - self.start time = timedeltaSeconds(time) load = tics / (HERTZ * time) return minmax(0.0, load, 1.0)
def writeGraphData(self, session_index, score): self.last_session_index = session_index if CREATE_GRAPH_DAT and not self.graph_data: filename = self.project().createFilename('aggressivity.dat') self.graph_data = open(filename, 'w') print >>self.graph_data, "# Aggressivity data" print >>self.graph_data, "# Started at %s" % datetime.now() print >>self.graph_data, "#" print >>self.graph_data, "# session_index score aggressivity" if self.project().success_score <= score: score = 1.0 else: score = minmax(-1.0, score, 1.0) if self.graph_data: print >>self.graph_data, "%u\t%.3f\t%.3f" % ( self.last_session_index, score, self.aggressivity) self.graph_data.flush()
def writeGraphData(self, session_index, score): self.last_session_index = session_index if CREATE_GRAPH_DAT and not self.graph_data: filename = self.project().createFilename('aggressivity.dat') self.graph_data = open(filename, 'w') print >> self.graph_data, "# Aggressivity data" print >> self.graph_data, "# Started at %s" % datetime.now() print >> self.graph_data, "#" print >> self.graph_data, "# session_index score aggressivity" if self.project().success_score <= score: score = 1.0 else: score = minmax(-1.0, score, 1.0) if self.graph_data: print >> self.graph_data, "%u\t%.3f\t%.3f" % ( self.last_session_index, score, self.aggressivity) self.graph_data.flush()
def setupConf(self, data): operations = ["bit"] size_factor = 0.30 if 0.25 <= self.aggressivity: operations.extend(("replace", "special_value")) if 0.50 <= self.aggressivity: operations.extend(("insert_bytes", "delete_bytes")) size_factor = 0.20 self.config.operations = operations # Display config count = len(data) * size_factor * self.fixed_size_factor count = minmax(self.hard_min_op, count, self.hard_max_op) count = int(count * self.aggressivity) self.config.max_op = max(count, self.hard_min_op) self.config.min_op = max(int(self.config.max_op * 0.80), self.hard_min_op) self.warning("operation#:%s..%s operations=%s" % (self.config.min_op, self.config.max_op, self.config.operations))
def setValue(self, value): value = round(value, 2) value = minmax(self.aggressivity_min, value, self.aggressivity_max) self.aggressivity = value
def __call__(self, data): offset = self.offset // 8 data[offset] = minmax(0, data[offset] + self.incr, 255)
def normalizeScore(score): score = minmax(-1.0, score, 1.0) return round(score, 2)
def mangle_increment(self): incr = randint(1, self.config.max_incr) if randint(0, 1) == 1: incr = -incr offset = self.offset() self.data[offset] = minmax(0, self.data[offset] + incr, 255)