async def get_dyn(uid, last_time, browser, default_name, config, file_list): api = BiliAPI() dynamics = (api.get_dynamic(uid)).get('cards', []) if len(dynamics) == 0: # 没有发过动态或者动态全删的直接结束 return if uid not in last_time: # 没有爬取过这位主播就把最新一条动态时间为 last_time dynamic = Dynamic(dynamics[0], default_name, config['data_path']) if dynamic.time > datetime.now().timestamp() - timedelta( days=1).total_seconds(): if dynamic.type not in config['exclude_types']: if not config['enable_filter'] or ( config['enable_filter'] and content_filter( dynamic.content, config['content_filter'])): await dynamic.get_screenshot(browser) file_list.append(dynamic.img_path) last_time[uid] = dynamic.time else: last_time[uid] = int(datetime.now().timestamp()) return for dynamic in dynamics[::-1]: # 从旧到新取最近5条动态 dynamic = Dynamic(dynamic, default_name, config['data_path']) if dynamic.time > last_time[uid]: if dynamic.type not in config['exclude_types']: if not config['enable_filter'] or ( config['enable_filter'] and content_filter( dynamic.content, config['content_filter'])): await dynamic.get_screenshot(browser) file_list.append(dynamic.img_path) last_time[uid] = dynamic.time
def __init__(self, track, comp_location, duration, volume): """Create a dynamic to adjust the volume of a track in a composition. Any segments in the composition that include the ``track`` between ``comp_location`` and ``comp_location + duration`` will be adjust to the given ``volume``. Here, ``volume`` is a constant multiplier (0.0 for zero volume, 1.0 for normal volume). You can use a range of volumes, but obviously if volume is much greater than 1.0, there will likely be clipping in the final composition. :param track: Track whose volume to adjust :type track: :py:class:`radiotool.composer.Track` :param float comp_location: Location to begin volume adjustment in composition (in seconds) :param float duration: Duration of volume adjustment (in seconds) :param float volume: Volume throughout the duration of the adjustment (1.0: normal, to 0.0: muted) """ Dynamic.__init__(self, track, comp_location, duration) self.volume = volume
def __init__(self, track, comp_location, duration, in_volume, out_volume, fade_type="linear"): """A fade is a :py:class:`radiotool.composer.Dynamic` that represents a fade in a track (either in or out). Currently supported fade types are ``linear`` and ``exponential``. The exponential fades are probably a bit quirky, but they work for me for some use cases. :param track: Track to fade :type track: :py:class:`radiotool.composer.Track` :param float comp_location: Location in composition to start fade (in seconds) :param float duration: Duration of fade (in seconds) :param float in_volume: Initial volume multiplier :param float out_volume: Ending volume multiplier :param string fade_type: Type of fade (``linear`` or ``exponential``) """ Dynamic.__init__(self, track, comp_location, duration) self.in_volume = in_volume self.out_volume = out_volume self.fade_type = fade_type
def __init__(self, h5n): self._h5n = h5n # type: H5Nastran self.constraint = Constraint(self._h5n, self) # self.contact = Contact(self.h5n, self) self.coordinate_system = CoordinateSystem(self._h5n, self) self.design = Design(self._h5n, self) # self.domains = None self.dynamic = Dynamic(self._h5n, self) self.element = Element(self._h5n, self) # self.fatigue = None self.load = Load(self._h5n, self) self.material = Material(self._h5n, self) # self.matrix = None # self.modules = None self.node = Node(self._h5n, self) self.parameter = Parameter(self._h5n, self) # self.partition = None self.property = Property(self._h5n, self) self.table = Table(self._h5n, self)
def test_integration_interaction(self): parameters = { "tp": 200, "tp2": 20, "Ef": 3000, "Np": 4, "g1": 0.2, "g2": 0.64, "g3": 0.0, "Temperature": 100 } IQ = Quasi1dIntegrableSystem().set_all( **parameters ) # input(IQ.Neq) # IQ.initialize() integrator = Dynamic( rel_tol=1e-3).get_integrator(IQ) lf = 0.1 li = 0 integrator.initialize() integrator.next_value(l_ini=li, l_next=lf)
H = min(int((y + h) * 1.0), frame.shape[0]) return X, W, Y, H def compute_face_vector(self, face_image): d = dlib.rectangle(0, 0, face_image.shape[0], face_image.shape[1]) shape = self.dynamic.sp(face_image, d) face_descriptor = self.dynamic.facerec.compute_face_descriptor( face_image, shape) return np.array(face_descriptor) def draw_pic(self, frame, x, y, w, h, name, pr): if pr <= self.threshold: return X, W, Y, H = self.get_pos(frame, x, y, w, h) cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) font = cv2.FONT_HERSHEY_DUPLEX cv2.putText(frame, name, (X + 6, H + 16), font, 0.7, (0, 0, 255), 1) cv2.putText(frame, "PR: {}".format(pr), (x + 3, y - 5), font, 0.5, (0, 0, 255), 1) def run(self): for f_name in glob.glob( os.path.join(self.dynamic.video_src, self.dynamic.video_type)): f.check(f_name) if __name__ == '__main__': d = Dynamic("Thrones") f = Facedec(d) f.check("video/Thrones/02/S02E07.mkv")
def get_dynamic(): return Dynamic()
def get_dynamic(card: dict): _dynamic = Dynamic(card) return _dynamic
from dynamic import Dynamic vector = Dynamic("vector", types = [ ("int", "int"), ("uint", "unsigned int"), ("long", "long"), ("ulong", "unsigned long"), ("float", "float"), ("double", "double"), ("bool", "bool") ]) vector.preCompile() hashmap = Dynamic("hashmap", types = [ ("byte", "char"), ("int", "int"), ("uint", "unsigned int"), ("long", "long"), ("ulong", "unsigned long"), ("float", "float"), ("double", "double"), ("bool", "bool") ]) hashmap.preCompile()
def main(): #For argument passing fileargs = argparse.ArgumentParser() fileargs.add_argument('file', help="file number to run", type=int) args = fileargs.parse_args() #Initialize Knapsack Objects for tasks weights = [] values = [] valueIndices = [] #Copy of the original order of values heapWeights = [] heapValues = [] #Concate checks and balances if args.file < 10: c_file = "./KnapsackTestData/p0" + str(args.file) + "_c.txt" w_file = "./KnapsackTestData/p0" + str(args.file) + "_w.txt" v_file = "./KnapsackTestData/p0" + str(args.file) + "_v.txt" else: c_file = "./KnapsackTestData/p" + str(args.file) + "_c.txt" w_file = "./KnapsackTestData/p" + str(args.file) + "_w.txt" v_file = "./KnapsackTestData/p" + str(args.file) + "_v.txt" print("File containing the capacity, weights, and values are:", c_file[19:] + ", " + w_file[19:] + ", " + v_file[19:]) print() #Read in from files file = open(c_file) #Max weight maxCapacity = int(file.readline()) file.close() #Weights file = open(w_file) for line in file: weights.append(int(line)) heapWeights.append(int(line)) file.close() #Values file = open(v_file) for line in file: valueIndices.append(int(line)) values.append(int(line)) heapValues.append(int(line)) file.close() totalWeights = len(weights) totalValues = len(values) print("Knapsack capacity =", maxCapacity, ". Total number of items =", totalWeights) print() #Dynamic Programming dynamicClass = Dynamic() dpTable = [[0 for x in range(maxCapacity + 1)] for x in range(totalWeights + 1)] begin = time.time() dpResult = dynamicClass.dynamicApproach(weights, values, maxCapacity, totalWeights, dpTable) dpOptimal = dynamicClass.dynamicOptimal(weights, maxCapacity, totalWeights, dpTable) dpTime = time.time() - begin print("Traditional Dynamic Programming Optimal value:", dpResult) print("Traditional Dynamic Programming Optimal subset:", dpOptimal) print("Traditional Dynamic Programming Time Taken:", dpTime) print() #Greedy approach using in-built sorting greedyOptSubset = [] greedyOptValues = [] greedyClass = Greedy() greedyClass.quickSort(0, totalValues - 1, values, weights) greedyResult = greedyClass.greedyApproach(values, maxCapacity, weights, greedyOptValues) greedyOptSubset = optimalSubset(valueIndices, greedyOptValues) print("Greedy Approach Optimal value:", greedyResult) print("Greedy Approach Optimal subset:", greedyOptSubset) print("Greedy Approach Number of Operations:", greedyClass.greedyOperations) print() #Greedy approach using a max-heap heapOptSubset = [] heapOptValues = [] totalHeapValues = len(heapValues) heapClass = Heap() heapClass.heapSort(heapValues, heapWeights, totalHeapValues) heapOptValue = heapClass.heapApproach(heapValues, heapWeights, maxCapacity, heapOptValues) heapOptSubset = optimalSubset(valueIndices, heapOptValues) print("Heap-based Greedy Approach Optimal value:", heapOptValue) print("Heap-based Greedy Approach Optimal subset:", heapOptSubset) print("Heap-based Approach Number of Operations:", heapClass.heapOperations) print() graphMaker()