content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
import datetime import xml.dom.minidom import logging from PyQt5 import QtCore, QtWidgets from functions.button_functions import add_read NAMESPACE_URI = 'http://www.eufar.net/ASMM'
[ 11748, 4818, 8079, 198, 11748, 35555, 13, 3438, 13, 1084, 312, 296, 198, 11748, 18931, 198, 6738, 9485, 48, 83, 20, 1330, 33734, 14055, 11, 33734, 54, 312, 11407, 198, 6738, 5499, 13, 16539, 62, 12543, 2733, 1330, 751, 62, 961, 628, ...
2.347826
92
from django.db import models # Create your models here.
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 198, 2, 13610, 534, 4981, 994, 13, 628, 198 ]
3.470588
17
#!/usr/bin/python # # Copyright (C) 2004 British Broadcasting Corporation and Kamaelia Contributors(1) # All Rights Reserved. # # You may only modify and redistribute this under the terms of any of the # following licenses(2): Mozilla Public License, V1.1, GNU General # Public License, V2.0, GNU Lesser General Public License, V2.1 # # (1) Kamaelia Contributors are listed in the AUTHORS file and at # http://kamaelia.sourceforge.net/AUTHORS - please extend this file, # not this notice. # (2) Reproduced in the COPYING file, and at: # http://kamaelia.sourceforge.net/COPYING # Under section 3.5 of the MPL, we are using this text since we deem the MPL # notice inappropriate for this file. As per MPL/GPL/LGPL removal of this # notice is prohibited. # # Please contact us via: kamaelia-list-owner@lists.sourceforge.net # to discuss alternative licensing. # ------------------------------------------------------------------------- """\ ==================== Unique ID generation ==================== The methods of the idGen class are used to generate unique IDs in various forms (numbers, strings, etc) which are used to give microprocesses and other Axon objects a unique identifier and name. * Every Axon.Microprocess.microprocess gets a unique ID * Axon.ThreadedComponent.threadedcomponent uses unique IDs to identify threads Generating a new unique ID -------------------------- Do not use the idGen class defined in this module directly. Instead, use any of these module methods to obtain a unique ID: * **Axon.idGen.newId(thing)** - returns a unique identifier as a string based on the class name of the object provided * **Axon.idGen.strId(thing)** - returns a unique identifier as a string based on the class name of the object provided * **Axon.idGen.numId()** - returns a unique identifier as a number * **Axon.idGen.tupleId(thing)** - returns both the numeric and string versions of a new unique id as a tuple (where the string version is based on the class name of the object provided) Calling tupleId(thing) is *not* equivalent to calling numId() then strId(thing) because doing that would return two different id values! Examples:: >>> x=Component.component() >>> idGen.newId(x) 'Component.component_4' >>> idGen.strId(x) 'Component.component_5' >>> idGen.numId() 6 >>> idGen.tupleId(x) (7, 'Component.component_7') """ import debug; debugger = debug.debug() debugger.useConfig() Debug = debugger.debug # idGen - A class to provide Unique Identifiers # # Ids can provide be provided as numerical, string or a tuple. # # numerical ids are integers allocated on a "next integer" basis. # eg object 1, apple 2, orange 3. (Not object 1, apple 2, orange 3) # # string ids consist of the '__str__' of the object, with the numerical # id tacked on the end. # # tuple ids consists : '(the numerical id, the string id)' # newId = idGen().strId strId=idGen().strId numId=idGen().numId tupleId=idGen().tupleId if __name__ == '__main__': print newId(foo()) print newId(bar()) print newId(bibble())
[ 2, 48443, 14629, 14, 8800, 14, 29412, 201, 198, 2, 201, 198, 2, 15069, 357, 34, 8, 5472, 3517, 32250, 10501, 290, 509, 1689, 25418, 25767, 669, 7, 16, 8, 201, 198, 2, 220, 220, 220, 220, 1439, 6923, 33876, 13, 201, 198, 2, 201, ...
3.088008
1,034
""" flux related class and functions """ from scipy.integrate import quad import pandas as pd from .helper import LinearInterp, polar_to_cartesian, lorentz_boost, lorentz_matrix from .oscillation import survival_solar from .parameters import *
[ 37811, 198, 69, 22564, 3519, 1398, 290, 5499, 198, 37811, 198, 198, 6738, 629, 541, 88, 13, 18908, 4873, 1330, 15094, 198, 11748, 19798, 292, 355, 279, 67, 198, 198, 6738, 764, 2978, 525, 1330, 44800, 9492, 79, 11, 13559, 62, 1462, ...
3.117647
85
# Author : Pavel Vitis "blackdaemon" # Email : blackdaemon@seznam.cz # # Copyright (c) 2010, Pavel Vitis <blackdaemon@seznam.cz> # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of Enso nor the names of its contributors may # be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ---------------------------------------------------------------------------- # # enso.contrib.minimessages # # ---------------------------------------------------------------------------- """ An Enso plugin that makes all mini-messages related commands available. Commands: hide mini messages """ # ---------------------------------------------------------------------------- # Imports # ---------------------------------------------------------------------------- from xml.sax.saxutils import escape as xml_escape import enso.messages from enso.commands import CommandManager, CommandObject from enso.commands.factories import ArbitraryPostfixFactory from enso.contrib.scriptotron.ensoapi import EnsoApi from enso.contrib.scriptotron.tracebacks import safetyNetted from enso.messages import MessageManager, TimedMiniMessage ensoapi = EnsoApi() # ---------------------------------------------------------------------------- # The 'hide mini messages' command # --------------------------------------------------------------------------- # ---------------------------------------------------------------------------- # The 'show mini message' testing command # --------------------------------------------------------------------------- # ---------------------------------------------------------------------------- # Plugin initialization # --------------------------------------------------------------------------- def load(): cmdMan = CommandManager.get() cmdMan.registerCommand( HideMiniMessagesCommand.NAME, HideMiniMessagesCommand() ) cmdMan.registerCommand( ShowMiniMessageFactory.NAME, ShowMiniMessageFactory() ) cmdMan.registerCommand( ShowRecentMessageCommand.NAME, ShowRecentMessageCommand() ) # vim:set tabstop=4 shiftwidth=4 expandtab:
[ 2, 6434, 1058, 49612, 569, 11815, 366, 13424, 6814, 7966, 1, 198, 2, 9570, 220, 1058, 2042, 6814, 7966, 31, 325, 89, 7402, 13, 26691, 198, 2, 198, 2, 15069, 357, 66, 8, 3050, 11, 49612, 569, 11815, 1279, 13424, 6814, 7966, 31, 325...
3.881757
888
import unittest from unittest.mock import Mock import json from processor import scrape_article import main
[ 11748, 555, 715, 395, 198, 6738, 555, 715, 395, 13, 76, 735, 1330, 44123, 198, 11748, 33918, 198, 198, 6738, 12649, 1330, 42778, 62, 20205, 198, 11748, 1388, 628 ]
3.793103
29
import unittest if __name__ == '__main__': unittest.main()
[ 11748, 555, 715, 395, 628, 628, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 555, 715, 395, 13, 12417, 3419, 198 ]
2.392857
28
# -*- coding: utf-8 -*- import platiagro import pandas as pd from werkzeug.exceptions import NotFound from pipelines.database import db_session from pipelines.models import Operator from pipelines.models.utils import raise_if_experiment_does_not_exist def get_dataset_name(experiment_id, operator_id,): """Retrieves a dataset name from experiment. Args: experiment_id(str): the experiment uuid operator_id(str): the operator uuid Returns: Dataset name """ raise_if_experiment_does_not_exist(experiment_id) operator = Operator.query.get(operator_id) if operator is None: raise NotFound("The specified operator does not exist") # get dataset name dataset = operator.parameters.get('dataset') if dataset is None: # try to find dataset name in other operators operators = db_session.query(Operator) \ .filter_by(experiment_id=experiment_id) \ .filter(Operator.uuid != operator_id) \ .all() for operator in operators: dataset = operator.parameters.get('dataset') if dataset: break if dataset is None: raise NotFound() return dataset def get_dataset_pagination(application_csv, name, operator_id, page, page_size, run_id): """Retrieves a dataset. Args: application_csv(bool): if is to return dataset as csv name(str): the dataset name operator_id(str): the operator uuid page_size(int) : record numbers page(int): page number run_id (str): the run id. Returns: Dataset """ try: metadata = platiagro.stat_dataset(name=name, operator_id=operator_id) if "run_id" not in metadata: raise FileNotFoundError() dataset = platiagro.load_dataset(name=name, operator_id=operator_id, run_id=run_id) except FileNotFoundError as e: raise NotFound(str(e)) if page_size == -1: if application_csv: return dataset.to_csv(index=False) dataset = dataset.to_dict(orient="split") del dataset["index"] return dataset else: dataset = dataset.to_dict(orient="split") del dataset["index"] pdataset = pagination_datasets(page=page, page_size=page_size, dataset=dataset) if application_csv: df = pd.DataFrame(columns=pdataset['columns'], data=pdataset['data']) return df.to_csv(index=False) return pdataset def pagination_datasets(page, page_size, dataset): """pagination of datasets. Args: page_size(int) : record numbers page(int): page number dataset(json): data to be paged Returns: Paged dataset """ try: count = 0 new_datasets = [] total_elements = len(dataset['data']) page = (page * page_size) - page_size for i in range(page, total_elements): new_datasets.append(dataset['data'][i]) count += 1 if page_size == count: response = { 'columns': dataset['columns'], 'data': new_datasets, 'total': len(dataset['data']) } return response if len(new_datasets) == 0: raise NotFound("The informed page does not contain records") else: response = { 'columns': dataset['columns'], 'data': new_datasets, 'total': len(dataset['data']) } return response except RuntimeError: raise NotFound("The specified page does not exist")
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 458, 7246, 363, 305, 198, 198, 11748, 19798, 292, 355, 279, 67, 198, 6738, 266, 9587, 2736, 1018, 13, 1069, 11755, 1330, 1892, 21077, 198, 198, 6738, 31108, 13, ...
2.109642
1,815
import pytest from flask_mailing.schemas import Message, MultipartSubtypeEnum from flask_mailing.msg import MailMsg import os CONTENT = "file test content"
[ 11748, 12972, 9288, 198, 6738, 42903, 62, 4529, 278, 13, 1416, 4411, 292, 1330, 16000, 11, 7854, 541, 433, 7004, 4906, 4834, 388, 198, 6738, 42903, 62, 4529, 278, 13, 19662, 1330, 11099, 50108, 198, 11748, 28686, 198, 198, 37815, 3525, ...
3.109091
55
import discord
[ 11748, 36446, 198 ]
5
3
"""Rigbits eye rigger tool""" import json import traceback from functools import partial import mgear.core.pyqt as gqt import pymel.core as pm from maya.app.general.mayaMixin import MayaQWidgetDockableMixin from mgear.core import meshNavigation, curve, applyop, node, primitive, icon from mgear.core import transform, utils, attribute, skin, string from mgear.vendor.Qt import QtCore, QtWidgets from pymel.core import datatypes from mgear import rigbits ########################################################## # Eye rig constructor ########################################################## def eyeRig(eyeMesh, edgeLoop, blinkH, namePrefix, offset, rigidLoops, falloffLoops, headJnt, doSkin, parent=None, ctlName="ctl", sideRange=False, customCorner=False, intCorner=None, extCorner=None, ctlGrp=None, defGrp=None): """Create eyelid and eye rig Args: eyeMesh (TYPE): Description edgeLoop (TYPE): Description blinkH (TYPE): Description namePrefix (TYPE): Description offset (TYPE): Description rigidLoops (TYPE): Description falloffLoops (TYPE): Description headJnt (TYPE): Description doSkin (TYPE): Description parent (None, optional): Description ctlName (str, optional): Description sideRange (bool, optional): Description customCorner (bool, optional): Description intCorner (None, optional): Description extCorner (None, optional): Description ctlGrp (None, optional): Description defGrp (None, optional): Description Returns: TYPE: Description """ # Checkers if edgeLoop: edgeLoopList = [pm.PyNode(e) for e in edgeLoop.split(",")] else: pm.displayWarning("Please set the edge loop first") return if eyeMesh: try: eyeMesh = pm.PyNode(eyeMesh) except pm.MayaNodeError: pm.displayWarning("The object %s can not be found in the " "scene" % (eyeMesh)) return else: pm.displayWarning("Please set the eye mesh first") if doSkin: if not headJnt: pm.displayWarning("Please set the Head Jnt or unCheck " "Compute Topological Autoskin") return # Initial Data bboxCenter = meshNavigation.bboxCenter(eyeMesh) extr_v = meshNavigation.getExtremeVertexFromLoop(edgeLoopList, sideRange) upPos = extr_v[0] lowPos = extr_v[1] inPos = extr_v[2] outPos = extr_v[3] edgeList = extr_v[4] vertexList = extr_v[5] # Detect the side L or R from the x value if inPos.getPosition(space='world')[0] < 0.0: side = "R" inPos = extr_v[3] outPos = extr_v[2] normalPos = outPos npw = normalPos.getPosition(space='world') normalVec = npw - bboxCenter else: side = "L" normalPos = outPos npw = normalPos.getPosition(space='world') normalVec = bboxCenter - npw # Manual Vertex corners if customCorner: if intCorner: try: if side == "R": inPos = pm.PyNode(extCorner) else: inPos = pm.PyNode(intCorner) except pm.MayaNodeError: pm.displayWarning("%s can not be found" % intCorner) return else: pm.displayWarning("Please set the internal eyelid corner") return if extCorner: try: normalPos = pm.PyNode(extCorner) npw = normalPos.getPosition(space='world') if side == "R": outPos = pm.PyNode(intCorner) normalVec = npw - bboxCenter else: outPos = pm.PyNode(extCorner) normalVec = bboxCenter - npw except pm.MayaNodeError: pm.displayWarning("%s can not be found" % extCorner) return else: pm.displayWarning("Please set the external eyelid corner") return # Check if we have prefix: if namePrefix: namePrefix = string.removeInvalidCharacter(namePrefix) else: pm.displayWarning("Prefix is needed") return if pm.ls(setName("root")): pm.displayWarning("The object %s already exist in the scene. Please " "choose another name prefix" % setName("root")) return # Eye root eye_root = primitive.addTransform(None, setName("root")) eyeCrv_root = primitive.addTransform(eye_root, setName("crvs")) # Eyelid Main crvs try: upEyelid = meshNavigation.edgeRangeInLoopFromMid( edgeList, upPos, inPos, outPos) upCrv = curve.createCurveFromOrderedEdges( upEyelid, inPos, setName("upperEyelid"), parent=eyeCrv_root) upCrv_ctl = curve.createCurveFromOrderedEdges( upEyelid, inPos, setName("upCtl_crv"), parent=eyeCrv_root) pm.rebuildCurve(upCrv_ctl, s=2, rt=0, rpo=True, ch=False) lowEyelid = meshNavigation.edgeRangeInLoopFromMid( edgeList, lowPos, inPos, outPos) lowCrv = curve.createCurveFromOrderedEdges( lowEyelid, inPos, setName("lowerEyelid"), parent=eyeCrv_root) lowCrv_ctl = curve.createCurveFromOrderedEdges( lowEyelid, inPos, setName("lowCtl_crv"), parent=eyeCrv_root) pm.rebuildCurve(lowCrv_ctl, s=2, rt=0, rpo=True, ch=False) except UnboundLocalError: if customCorner: pm.displayWarning("This error is maybe caused because the custom " "Corner vertex is not part of the edge loop") pm.displayError(traceback.format_exc()) return upBlink = curve.createCurveFromCurve( upCrv, setName("upblink_crv"), nbPoints=30, parent=eyeCrv_root) lowBlink = curve.createCurveFromCurve( lowCrv, setName("lowBlink_crv"), nbPoints=30, parent=eyeCrv_root) upTarget = curve.createCurveFromCurve( upCrv, setName("upblink_target"), nbPoints=30, parent=eyeCrv_root) lowTarget = curve.createCurveFromCurve( lowCrv, setName("lowBlink_target"), nbPoints=30, parent=eyeCrv_root) midTarget = curve.createCurveFromCurve( lowCrv, setName("midBlink_target"), nbPoints=30, parent=eyeCrv_root) rigCrvs = [upCrv, lowCrv, upCrv_ctl, lowCrv_ctl, upBlink, lowBlink, upTarget, lowTarget, midTarget] for crv in rigCrvs: crv.attr("visibility").set(False) # localBBOX localBBox = eyeMesh.getBoundingBox(invisible=True, space='world') wRadius = abs((localBBox[0][0] - localBBox[1][0])) dRadius = abs((localBBox[0][1] - localBBox[1][1]) / 1.7) # Groups if not ctlGrp: ctlGrp = "rig_controllers_grp" try: ctlSet = pm.PyNode(ctlGrp) except pm.MayaNodeError: pm.sets(n=ctlGrp, em=True) ctlSet = pm.PyNode(ctlGrp) if not defGrp: defGrp = "rig_deformers_grp" try: defset = pm.PyNode(defGrp) except pm.MayaNodeError: pm.sets(n=defGrp, em=True) defset = pm.PyNode(defGrp) # Calculate center looking at averagePosition = ((upPos.getPosition(space='world') + lowPos.getPosition(space='world') + inPos.getPosition(space='world') + outPos.getPosition(space='world')) / 4) if side == "R": negate = False offset = offset over_offset = dRadius else: negate = False over_offset = dRadius if side == "R" and sideRange or side == "R" and customCorner: axis = "z-x" # axis = "zx" else: axis = "z-x" t = transform.getTransformLookingAt( bboxCenter, averagePosition, normalVec, axis=axis, negate=negate) over_npo = primitive.addTransform( eye_root, setName("center_lookatRoot"), t) over_ctl = icon.create(over_npo, setName("over_%s" % ctlName), t, icon="square", w=wRadius, d=dRadius, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, over_offset), color=4) node.add_controller_tag(over_ctl) attribute.add_mirror_config_channels(over_ctl) attribute.setKeyableAttributes( over_ctl, params=["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"]) if side == "R": over_npo.attr("rx").set(over_npo.attr("rx").get() * -1) over_npo.attr("ry").set(over_npo.attr("ry").get() + 180) over_npo.attr("sz").set(-1) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=over_ctl) center_lookat = primitive.addTransform( over_ctl, setName("center_lookat"), t) # Tracking # Eye aim control t_arrow = transform.getTransformLookingAt(bboxCenter, averagePosition, upPos.getPosition(space='world'), axis="zy", negate=False) radius = abs((localBBox[0][0] - localBBox[1][0]) / 1.7) arrow_npo = primitive.addTransform(eye_root, setName("aim_npo"), t_arrow) arrow_ctl = icon.create(arrow_npo, setName("aim_%s" % ctlName), t_arrow, icon="arrow", w=1, po=datatypes.Vector(0, 0, radius), color=4) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=arrow_ctl) attribute.setKeyableAttributes(arrow_ctl, params=["rx", "ry", "rz"]) # tracking custom trigger if side == "R": tt = t_arrow else: tt = t aimTrigger_root = primitive.addTransform( center_lookat, setName("aimTrigger_root"), tt) aimTrigger_lvl = primitive.addTransform( aimTrigger_root, setName("aimTrigger_lvl"), tt) aimTrigger_lvl.attr("tz").set(1.0) aimTrigger_ref = primitive.addTransform( aimTrigger_lvl, setName("aimTrigger_ref"), tt) aimTrigger_ref.attr("tz").set(0.0) # connect trigger with arrow_ctl pm.parentConstraint(arrow_ctl, aimTrigger_ref, mo=True) # Controls lists upControls = [] trackLvl = [] # upper eyelid controls upperCtlNames = ["inCorner", "upInMid", "upMid", "upOutMid", "outCorner"] cvs = upCrv_ctl.getCVs(space="world") if side == "R" and not sideRange: # if side == "R": cvs = [cv for cv in reversed(cvs)] for i, cv in enumerate(cvs): if utils.is_odd(i): color = 14 wd = .5 icon_shape = "circle" params = ["tx", "ty", "tz"] else: color = 4 wd = .7 icon_shape = "square" params = ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"] t = transform.setMatrixPosition(t, cvs[i]) npo = primitive.addTransform(center_lookat, setName("%s_npo" % upperCtlNames[i]), t) npoBase = npo if i == 2: # we add an extra level to input the tracking ofset values npo = primitive.addTransform(npo, setName("%s_trk" % upperCtlNames[i]), t) trackLvl.append(npo) ctl = icon.create(npo, setName("%s_%s" % (upperCtlNames[i], ctlName)), t, icon=icon_shape, w=wd, d=wd, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, offset), color=color) attribute.add_mirror_config_channels(ctl) node.add_controller_tag(ctl, over_ctl) upControls.append(ctl) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=ctl) attribute.setKeyableAttributes(ctl, params) if side == "R": npoBase.attr("ry").set(180) npoBase.attr("sz").set(-1) # adding parent average contrains to odd controls for i, ctl in enumerate(upControls): if utils.is_odd(i): pm.parentConstraint(upControls[i - 1], upControls[i + 1], ctl.getParent(), mo=True) # lower eyelid controls lowControls = [upControls[0]] lowerCtlNames = ["inCorner", "lowInMid", "lowMid", "lowOutMid", "outCorner"] cvs = lowCrv_ctl.getCVs(space="world") if side == "R" and not sideRange: cvs = [cv for cv in reversed(cvs)] for i, cv in enumerate(cvs): # we skip the first and last point since is already in the uper eyelid if i in [0, 4]: continue if utils.is_odd(i): color = 14 wd = .5 icon_shape = "circle" params = ["tx", "ty", "tz"] else: color = 4 wd = .7 icon_shape = "square" params = ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"] t = transform.setMatrixPosition(t, cvs[i]) npo = primitive.addTransform(center_lookat, setName("%s_npo" % lowerCtlNames[i]), t) npoBase = npo if i == 2: # we add an extra level to input the tracking ofset values npo = primitive.addTransform(npo, setName("%s_trk" % lowerCtlNames[i]), t) trackLvl.append(npo) ctl = icon.create(npo, setName("%s_%s" % (lowerCtlNames[i], ctlName)), t, icon=icon_shape, w=wd, d=wd, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, offset), color=color) attribute.add_mirror_config_channels(ctl) lowControls.append(ctl) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=ctl) attribute.setKeyableAttributes(ctl, params) # mirror behaviout on R side controls if side == "R": npoBase.attr("ry").set(180) npoBase.attr("sz").set(-1) for lctl in reversed(lowControls[1:]): node.add_controller_tag(lctl, over_ctl) lowControls.append(upControls[-1]) # adding parent average contrains to odd controls for i, ctl in enumerate(lowControls): if utils.is_odd(i): pm.parentConstraint(lowControls[i - 1], lowControls[i + 1], ctl.getParent(), mo=True) # Connecting control crvs with controls applyop.gear_curvecns_op(upCrv_ctl, upControls) applyop.gear_curvecns_op(lowCrv_ctl, lowControls) # adding wires w1 = pm.wire(upCrv, w=upBlink)[0] w2 = pm.wire(lowCrv, w=lowBlink)[0] w3 = pm.wire(upTarget, w=upCrv_ctl)[0] w4 = pm.wire(lowTarget, w=lowCrv_ctl)[0] # adding blendshapes bs_upBlink = pm.blendShape(upTarget, midTarget, upBlink, n="blendShapeUpBlink") bs_lowBlink = pm.blendShape(lowTarget, midTarget, lowBlink, n="blendShapeLowBlink") bs_mid = pm.blendShape(lowTarget, upTarget, midTarget, n="blendShapeLowBlink") # setting blendshape reverse connections rev_node = pm.createNode("reverse") pm.connectAttr(bs_upBlink[0].attr(midTarget.name()), rev_node + ".inputX") pm.connectAttr(rev_node + ".outputX", bs_upBlink[0].attr(upTarget.name())) rev_node = pm.createNode("reverse") pm.connectAttr(bs_lowBlink[0].attr(midTarget.name()), rev_node + ".inputX") pm.connectAttr(rev_node + ".outputX", bs_lowBlink[0].attr(lowTarget.name())) rev_node = pm.createNode("reverse") pm.connectAttr(bs_mid[0].attr(upTarget.name()), rev_node + ".inputX") pm.connectAttr(rev_node + ".outputX", bs_mid[0].attr(lowTarget.name())) # setting default values bs_mid[0].attr(upTarget.name()).set(blinkH) # joints root jnt_root = primitive.addTransformFromPos( eye_root, setName("joints"), pos=bboxCenter) # head joint if headJnt: try: headJnt = pm.PyNode(headJnt) jnt_base = headJnt except pm.MayaNodeError: pm.displayWarning( "Aborted can not find %s " % headJnt) return else: # Eye root jnt_base = jnt_root eyeTargets_root = primitive.addTransform(eye_root, setName("targets")) eyeCenter_jnt = rigbits.addJnt(arrow_ctl, jnt_base, grp=defset, jntName=setName("center_jnt")) # Upper Eyelid joints ################################################## cvs = upCrv.getCVs(space="world") upCrv_info = node.createCurveInfoNode(upCrv) # aim constrain targets and joints upperEyelid_aimTargets = [] upperEyelid_jnt = [] upperEyelid_jntRoot = [] for i, cv in enumerate(cvs): # aim targets trn = primitive.addTransformFromPos(eyeTargets_root, setName("upEyelid_aimTarget", i), pos=cv) upperEyelid_aimTargets.append(trn) # connecting positions with crv pm.connectAttr(upCrv_info + ".controlPoints[%s]" % str(i), trn.attr("translate")) # joints jntRoot = primitive.addJointFromPos(jnt_root, setName("upEyelid_jnt_base", i), pos=bboxCenter) jntRoot.attr("radius").set(.08) jntRoot.attr("visibility").set(False) upperEyelid_jntRoot.append(jntRoot) applyop.aimCns(jntRoot, trn, axis="zy", wupObject=jnt_root) jnt_ref = primitive.addJointFromPos(jntRoot, setName("upEyelid_jnt_ref", i), pos=cv) jnt_ref.attr("radius").set(.08) jnt_ref.attr("visibility").set(False) jnt = rigbits.addJnt(jnt_ref, jnt_base, grp=defset, jntName=setName("upEyelid_jnt", i)) upperEyelid_jnt.append(jnt) # Lower Eyelid joints ################################################## cvs = lowCrv.getCVs(space="world") lowCrv_info = node.createCurveInfoNode(lowCrv) # aim constrain targets and joints lowerEyelid_aimTargets = [] lowerEyelid_jnt = [] lowerEyelid_jntRoot = [] for i, cv in enumerate(cvs): if i in [0, len(cvs) - 1]: continue # aim targets trn = primitive.addTransformFromPos(eyeTargets_root, setName("lowEyelid_aimTarget", i), pos=cv) lowerEyelid_aimTargets.append(trn) # connecting positions with crv pm.connectAttr(lowCrv_info + ".controlPoints[%s]" % str(i), trn.attr("translate")) # joints jntRoot = primitive.addJointFromPos(jnt_root, setName("lowEyelid_base", i), pos=bboxCenter) jntRoot.attr("radius").set(.08) jntRoot.attr("visibility").set(False) lowerEyelid_jntRoot.append(jntRoot) applyop.aimCns(jntRoot, trn, axis="zy", wupObject=jnt_root) jnt_ref = primitive.addJointFromPos(jntRoot, setName("lowEyelid_jnt_ref", i), pos=cv) jnt_ref.attr("radius").set(.08) jnt_ref.attr("visibility").set(False) jnt = rigbits.addJnt(jnt_ref, jnt_base, grp=defset, jntName=setName("lowEyelid_jnt", i)) lowerEyelid_jnt.append(jnt) # Channels # Adding and connecting attributes for the blink up_ctl = upControls[2] blink_att = attribute.addAttribute( over_ctl, "blink", "float", 0, minValue=0, maxValue=1) blinkMult_att = attribute.addAttribute( over_ctl, "blinkMult", "float", 1, minValue=1, maxValue=2) midBlinkH_att = attribute.addAttribute( over_ctl, "blinkHeight", "float", blinkH, minValue=0, maxValue=1) mult_node = node.createMulNode(blink_att, blinkMult_att) pm.connectAttr(mult_node + ".outputX", bs_upBlink[0].attr(midTarget.name())) pm.connectAttr(mult_node + ".outputX", bs_lowBlink[0].attr(midTarget.name())) pm.connectAttr(midBlinkH_att, bs_mid[0].attr(upTarget.name())) low_ctl = lowControls[2] # Adding channels for eye tracking upVTracking_att = attribute.addAttribute(up_ctl, "vTracking", "float", .02, minValue=0, maxValue=1, keyable=False, channelBox=True) upHTracking_att = attribute.addAttribute(up_ctl, "hTracking", "float", .01, minValue=0, maxValue=1, keyable=False, channelBox=True) lowVTracking_att = attribute.addAttribute(low_ctl, "vTracking", "float", .01, minValue=0, maxValue=1, keyable=False, channelBox=True) lowHTracking_att = attribute.addAttribute(low_ctl, "hTracking", "float", .01, minValue=0, maxValue=1, keyable=False, channelBox=True) mult_node = node.createMulNode(upVTracking_att, aimTrigger_ref.attr("ty")) pm.connectAttr(mult_node + ".outputX", trackLvl[0].attr("ty")) mult_node = node.createMulNode(upHTracking_att, aimTrigger_ref.attr("tx")) pm.connectAttr(mult_node + ".outputX", trackLvl[0].attr("tx")) mult_node = node.createMulNode(lowVTracking_att, aimTrigger_ref.attr("ty")) pm.connectAttr(mult_node + ".outputX", trackLvl[1].attr("ty")) mult_node = node.createMulNode(lowHTracking_att, aimTrigger_ref.attr("tx")) pm.connectAttr(mult_node + ".outputX", trackLvl[1].attr("tx")) # Tension on blink node.createReverseNode(blink_att, w1.scale[0]) node.createReverseNode(blink_att, w3.scale[0]) node.createReverseNode(blink_att, w2.scale[0]) node.createReverseNode(blink_att, w4.scale[0]) ########################################### # Reparenting ########################################### if parent: try: if isinstance(parent, basestring): parent = pm.PyNode(parent) parent.addChild(eye_root) except pm.MayaNodeError: pm.displayWarning("The eye rig can not be parent to: %s. Maybe " "this object doesn't exist." % parent) ########################################### # Auto Skinning ########################################### if doSkin: # eyelid vertex rows totalLoops = rigidLoops + falloffLoops vertexLoopList = meshNavigation.getConcentricVertexLoop(vertexList, totalLoops) vertexRowList = meshNavigation.getVertexRowsFromLoops(vertexLoopList) # we set the first value 100% for the first initial loop skinPercList = [1.0] # we expect to have a regular grid topology for r in range(rigidLoops): for rr in range(2): skinPercList.append(1.0) increment = 1.0 / float(falloffLoops) # we invert to smooth out from 100 to 0 inv = 1.0 - increment for r in range(falloffLoops): for rr in range(2): if inv < 0.0: inv = 0.0 skinPercList.append(inv) inv -= increment # this loop add an extra 0.0 indices to avoid errors for r in range(10): for rr in range(2): skinPercList.append(0.0) # base skin geo = pm.listRelatives(edgeLoopList[0], parent=True)[0] # Check if the object has a skinCluster objName = pm.listRelatives(geo, parent=True)[0] skinCluster = skin.getSkinCluster(objName) if not skinCluster: skinCluster = pm.skinCluster(headJnt, geo, tsb=True, nw=2, n='skinClsEyelid') eyelidJoints = upperEyelid_jnt + lowerEyelid_jnt pm.progressWindow(title='Auto skinning process', progress=0, max=len(eyelidJoints)) firstBoundary = False for jnt in eyelidJoints: pm.progressWindow(e=True, step=1, status='\nSkinning %s' % jnt) skinCluster.addInfluence(jnt, weight=0) v = meshNavigation.getClosestVertexFromTransform(geo, jnt) for row in vertexRowList: if v in row: it = 0 # iterator inc = 1 # increment for i, rv in enumerate(row): try: perc = skinPercList[it] t_val = [(jnt, perc), (headJnt, 1.0 - perc)] pm.skinPercent(skinCluster, rv, transformValue=t_val) if rv.isOnBoundary(): # we need to compare with the first boundary # to check if the row have inverted direction # and offset the value if not firstBoundary: firstBoundary = True firstBoundaryValue = it else: if it < firstBoundaryValue: it -= 1 elif it > firstBoundaryValue: it += 1 inc = 2 except IndexError: continue it = it + inc pm.progressWindow(e=True, endProgress=True) # Eye Mesh skinning skinCluster = skin.getSkinCluster(eyeMesh) if not skinCluster: skinCluster = pm.skinCluster(eyeCenter_jnt, eyeMesh, tsb=True, nw=1, n='skinClsEye') ########################################################## # Eye Rig UI ########################################################## # build lips from json file: def eyesFromfile(path): buildDict = json.load(open(path)) eyeRig(*buildDict["eye"]) def showEyeRigUI(*args): gqt.showDialog(eyeRigUI) if __name__ == "__main__": showEyeRigUI() # path = "C:\\Users\\miquel\\Desktop\\eye_L.eyes" # eyesFromfile(path) # path = "C:\\Users\\miquel\\Desktop\\eye_R.eyes" # eyesFromfile(path)
[ 37811, 49, 328, 9895, 4151, 7805, 1362, 2891, 37811, 198, 198, 11748, 33918, 198, 11748, 12854, 1891, 198, 6738, 1257, 310, 10141, 1330, 13027, 198, 198, 11748, 10527, 451, 13, 7295, 13, 9078, 39568, 355, 308, 39568, 198, 11748, 279, 49...
1.78729
17,042
#!/usr/bin/env python3 import os import shutil import sys import pathlib import logging # I will NEVER EVER use subproccess again # At least not for something like Popen try: from sh import wget except Exception: print('[!] Just install sh right now!(pip install --user sh)') sys.exit(0) # Dumb Python2 support if sys.version_info[0] == 2: input = raw_input # Path where this python script is located when it's run curr_dir = pathlib.Path(os.path.dirname(os.path.abspath(__file__))) # The URL url = input('[$] Url(none for ema.perfact.de): ') url = url if url else 'ema.perfact.de' print('[*] Url: {}\n'.format(url)) # Get name of the directory where the whole page should be saved dir_name = input('[$] Directory name for the page(none for "1337"): ') dir_name = dir_name if dir_name else '1337' page_dir = curr_dir / dir_name if page_dir.is_dir(): print('[!] {} is already a directory and will be overwritten!'.format(page_dir)) choice = input('[!] Continue?(y/n):').lower() if choice != 'y': sys.exit(0) print('[*] Directory to save the page: {}\n'.format(dir_name)) # Get name of directory where the files will be saved we actually want to save save_name = input('[$] Directory name to save findings(none for "saved"): ') save_name = save_name if save_name else 'saved' save_dir = curr_dir / save_name if save_dir.is_dir(): print('[!] {} is already a directory!'.format(save_dir)) choice = input('[!] Delete it?(y/n): '.format(save_dir)).lower() if choice == 'y': shutil.rmtree(save_dir.absolute().as_posix()) else: sys.exit(0) os.makedirs(save_dir.absolute().as_posix()) print('[*] Directory to save findings: {}\n'.format(save_name)) # The searchterm (which files we want to copy) print('[*] Everything with the following substring will be copied') search_term = input('[$] Files to copy to that directory(none for ".png"): ') search_term = search_term if search_term else '.png' print('[*] Searchterm: {}\n'.format(search_term)) input('\n[$] Press any key to continue...') # We will give these exit_codes to the wget call later # to disabled every exit/error message (will look horribly else) exit_codes = (i for i in range(0, 9)) # Sets off the wget -m <url> -P <directory> commande # It's written so weird, so we can see the output of the program try: for line in wget('-m', url, '-P', dir_name, _iter=True, _err_to_out=True, _out_bufsize=1, _ok_code=exit_codes): print(line) except Exception: pass # Copying the files we want to save try: # Get every file with the correct searchterm from the folder where the webpage is saved files = list(page_dir.glob("**/*{}".format(search_term))) if not files: print("[!] No matching files found") else: print("[*] Copying {} *{} files...".format(len(files), search_term)) for f in files: shutil.copy(f.absolute().as_posix(), save_dir.absolute().as_posix()) except Exception as e: print('[!] Something went wrong while copying data') print(e) # Deleting the saved webpage, cause we don't need it anymore print('\n[*] Cleaning up...\n') if page_dir.is_dir(): shutil.rmtree(page_dir.absolute().as_posix()) print('[*] All done!')
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 11748, 28686, 198, 11748, 4423, 346, 198, 11748, 25064, 198, 11748, 3108, 8019, 198, 11748, 18931, 198, 198, 2, 314, 481, 33602, 20498, 779, 850, 1676, 1591, 757, 198, 2, 1629, 155...
2.725753
1,196
import ase from ase import Atoms from ase.atom import Atom import sys from ase.visualize import view import pickle f = open(sys.argv[1],'r') #The .amc file p = pickle.load(f) positions = p['atomspositions'] atms = Atoms() for p0 in positions: a = Atom('Au',position=p0) atms.append(a) atms.center(vacuum=2) view(atms)
[ 11748, 257, 325, 198, 6738, 257, 325, 1330, 1629, 3150, 198, 6738, 257, 325, 13, 37696, 1330, 33102, 198, 11748, 25064, 198, 6738, 257, 325, 13, 41464, 1096, 1330, 1570, 198, 11748, 2298, 293, 198, 69, 796, 1280, 7, 17597, 13, 853, ...
2.392593
135
# dev TELEGRAM_TOKEN = "..." RELATIVE_CHAT_IDS = [ "...", '...'] TEXT = { "bot_info": (', , .\n\n' ' , '), "get_link": " ", "new_room": " \n%s", "nothing_to_change": " " }
[ 2, 220, 1614, 220, 198, 198, 9328, 2538, 10761, 2390, 62, 10468, 43959, 796, 366, 9313, 198, 16448, 37045, 62, 31542, 62, 14255, 796, 685, 366, 9313, 11, 705, 986, 20520, 198, 198, 32541, 796, 1391, 198, 220, 220, 220, 366, 13645, 6...
1.691729
133
######################################################################## # test/xslt/sm20000304.py # Example from Steve Muench <smuench@us.oracle.com> # to Jon Smirl <jonsmirl@mediaone.net> # on 4 March 2000 """ From: "Steve Muench" <smuench@us.oracle.com> To: <xsl-list@mulberrytech.com> Subject: Re: SVG charts and graphs from XML input Date: Sat, 4 Mar 2000 18:02:53 -0800 (19:02 MST) This is by no means a bullet-proof, one-size-fits all charting stylesheet, but it *was* my first foray into SVG from XSLT. Given XML results of an Oracle XSQL Page like: <xsql:query xmlns:xsql="urn:oracle-xsql" connection="demo"> select ename, sal from dept </xsql:query> Which under the covers produces a dynamic XML doc like: [SNIP source] The following "salchart.xsl" XSLT stylesheet renders a dynamic bar chart with "cool colors" for the employees in the department. You may have to modify the namespace of the Java extension functions to get it to work in XT or Saxon or other XSLT engines. [SNIP stylesheet] """ import os import cStringIO import unittest from amara.lib import treecompare from amara.test import test_main from amara.test.xslt import xslt_test, filesource, stringsource ### dalke - added to make the imports work #Extensions ORACLE_JAVA_NS = 'http://www.oracle.com/XSL/Transform/java' JAVA_COLOR_NS = ORACLE_JAVA_NS + '/java.awt.Color' JAVA_INTEGER_NS = ORACLE_JAVA_NS + '/java.lang.Integer' ExtFunctions = { (JAVA_COLOR_NS, 'getHSBColor') : Java_Color_GetHSBColor, (JAVA_COLOR_NS, 'getRed') : Java_Color_GetRed, (JAVA_COLOR_NS, 'getGreen') : Java_Color_GetGreen, (JAVA_COLOR_NS, 'getBlue') : Java_Color_GetBlue, (JAVA_INTEGER_NS, 'toHexString') : Java_Integer_ToHexString, } # Hide the test framework from nose del xslt_test if __name__ == '__main__': test_main()
[ 29113, 29113, 7804, 198, 2, 1332, 14, 34223, 2528, 14, 5796, 2167, 405, 21288, 13, 9078, 198, 2, 17934, 422, 6542, 8252, 24421, 1279, 5796, 84, 24421, 31, 385, 13, 273, 6008, 13, 785, 29, 198, 2, 284, 5966, 2439, 1901, 1279, 73, 6...
2.71365
674
import json
[ 11748, 33918, 198, 220, 220, 220, 220 ]
2.285714
7
"""go.""" import warnings from typing import List, Optional from pathlib import Path from pmfp.utils.run_command_utils import run def build_pb_go(serv_file: str, includes: List[str], to: str, source_relative: bool, cwd: Path, files: Optional[List[str]] = None, **kwargs: str) -> None: """grpcprotobuffergo. Args: serv_file (str): grpc serviceproto includes (List[str]): protobuffer to (str): source_relative (bool): ,go cwd (Path): . files (Optional[List[str]]): protobuffer """ includes_str = " ".join([f"-I {include}" for include in includes]) target_str = serv_file if files: target_str += " " + " ".join(files) flag_str = "" if source_relative: flag_str += " --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative" if kwargs: if flag_str: flag_str += " " flag_str += " ".join([f"{k}={v}" for k, v in kwargs.items()]) _build_grpc(includes_str, flag_str, to, target_str, cwd)
[ 37811, 2188, 526, 15931, 198, 11748, 14601, 198, 6738, 19720, 1330, 7343, 11, 32233, 198, 6738, 3108, 8019, 1330, 10644, 198, 6738, 9114, 46428, 13, 26791, 13, 5143, 62, 21812, 62, 26791, 1330, 1057, 628, 198, 198, 4299, 1382, 62, 40842...
2.299559
454
# Generated by Django 2.2.1 on 2019-05-22 00:07 from django.db import migrations
[ 2, 2980, 515, 416, 37770, 362, 13, 17, 13, 16, 319, 13130, 12, 2713, 12, 1828, 3571, 25, 2998, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 628 ]
2.766667
30
import json import logging from flask import jsonify, make_response, request from flask_jwt_extended import jwt_required from flask_restful import Resource from http import HTTPStatus from marshmallow import ValidationError, Schema from werkzeug.security import generate_password_hash from app.models import db from app.models.user import User, user_schema from app.api.utils import get_url from app.utils.exceptions import ApiException logger = logging.getLogger(__name__)
[ 11748, 33918, 198, 11748, 18931, 198, 198, 6738, 42903, 1330, 33918, 1958, 11, 787, 62, 26209, 11, 2581, 198, 6738, 42903, 62, 73, 46569, 62, 2302, 1631, 1330, 474, 46569, 62, 35827, 198, 6738, 42903, 62, 2118, 913, 1330, 20857, 198, ...
3.589552
134
from main import readData, getTrueLabels, binariseLabels, removePacketsAfterChange label_data = list() label_data.append(readData("..\\data\\test5_targets_1.csv")) label_data.append(readData("..\\data\\test5_targets_2.csv")) label_data.append(readData("..\\data\\test5_targets_3.csv")) labels = [getTrueLabels(label) for label in label_data] binarised_labels = dict() binarised_labels[1] = [binariseLabels(label, 1) for label in labels] binarised_labels[2] = [binariseLabels(label, 2) for label in labels] binarised_labels[3] = [binariseLabels(label, 3) for label in labels] for target in [1,2,3]: for dataset in [0,1,2]: _, binarised_labels[target][dataset] =\ removePacketsAfterChange(binarised_labels[target][dataset], binarised_labels[target][dataset], label_data[dataset], 256) for target in [1,2,3]: for dataset in [0,1,2]: print "Dataset:", str(dataset+1), "Target:", str(target), "Count:", str(sum(binarised_labels[target][dataset]))
[ 6738, 1388, 1330, 1100, 6601, 11, 651, 17821, 17822, 1424, 11, 9874, 283, 786, 17822, 1424, 11, 4781, 11869, 1039, 3260, 19400, 628, 198, 18242, 62, 7890, 796, 1351, 3419, 198, 18242, 62, 7890, 13, 33295, 7, 961, 6601, 7203, 492, 6852...
2.447761
402
import numpy as np from mpi4py import MPI from src.imagine.goal_generator.simple_sentence_generator import SentenceGeneratorHeuristic from src import logger
[ 11748, 299, 32152, 355, 45941, 198, 6738, 285, 14415, 19, 9078, 1330, 4904, 40, 198, 6738, 12351, 13, 320, 12756, 13, 35231, 62, 8612, 1352, 13, 36439, 62, 34086, 594, 62, 8612, 1352, 1330, 11352, 594, 8645, 1352, 1544, 27915, 198, 67...
3.434783
46
#!/usr/bin/env python #This is different from AIY Kit's actions #Copying and Pasting AIY Kit's actions commands will not work from googleapiclient.discovery import build from googleapiclient.errors import HttpError from gmusicapi import Mobileclient from googletrans import Translator from gtts import gTTS import requests import os import os.path import RPi.GPIO as GPIO import time import re import subprocess import json import urllib.request import pafy #API Key for YouTube and KS Search Engine google_cloud_api_key='ENTER-YOUR-GOOGLE-CLOUD-API-KEY-HERE' #YouTube API Constants DEVELOPER_KEY = google_cloud_api_key YOUTUBE_API_SERVICE_NAME = 'youtube' YOUTUBE_API_VERSION = 'v3' playshell = None
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 2, 1212, 318, 1180, 422, 9552, 56, 10897, 338, 4028, 198, 2, 13379, 1112, 290, 350, 9222, 9552, 56, 10897, 338, 4028, 9729, 481, 407, 670, 628, 198, 6738, 23645, 499, 291, 75, ...
3.025532
235
from Qt import QtWidgets, QtGui from .categories import ( CategoryState, SystemWidget, ProjectWidget ) from .widgets import ShadowWidget from .. import style
[ 6738, 33734, 1330, 33734, 54, 312, 11407, 11, 33734, 8205, 72, 198, 6738, 764, 66, 26129, 1330, 357, 198, 220, 220, 220, 21743, 9012, 11, 198, 220, 220, 220, 4482, 38300, 11, 198, 220, 220, 220, 4935, 38300, 198, 8, 198, 6738, 764, ...
3.166667
54
import lambda_handler from unittest import TestCase from mock import call, patch, Mock from datetime import datetime import boto3 import json from botocore.stub import Stubber import urllib3 mock_s3_client = boto3.client('s3') s3_stubber = Stubber(mock_s3_client) list_objects_response = { 'IsTruncated': False, 'Contents': [ { 'Key': 'return1.zip', 'LastModified': datetime(2015, 1, 1), 'ETag': 'string', 'Size': 123, 'StorageClass': 'STANDARD', 'Owner': { 'DisplayName': 'string', 'ID': 'string' } }, { 'Key': 'do_not_return.txt', 'LastModified': datetime(2015, 1, 1), 'ETag': 'string', 'Size': 123, 'StorageClass': 'STANDARD', 'Owner': { 'DisplayName': 'string', 'ID': 'string' } }, { 'Key': 'return2.zip', 'LastModified': datetime(2015, 1, 1), 'ETag': 'string', 'Size': 123, 'StorageClass': 'STANDARD', 'Owner': { 'DisplayName': 'string', 'ID': 'string' } }, ], 'Name': 'string', 'EncodingType': 'url', 'KeyCount': 123, 'ContinuationToken': 'string' } s3_stubber.add_response('list_objects_v2', list_objects_response) s3_stubber.activate() mock_sm_client = boto3.client('secretsmanager') sm_stubber = Stubber(mock_sm_client) mock_secret_value_response = { 'ARN': 'arn:aws:secretsmanager:eu-west-7:123456789012:secret:tutorials/MyFirstSecret-jiObOV', 'Name': 'string', 'VersionId': 'EXAMPLE1-90ab-cdef-fedc-ba987EXAMPLE', 'SecretBinary': b'{"azkaban_username": "test_user", "azkaban_password": "pw123"}', 'CreatedDate': datetime(2015, 1, 1) } sm_stubber.add_response('get_secret_value', mock_secret_value_response) sm_stubber.add_response('get_secret_value', mock_secret_value_response) sm_stubber.activate() data_non_fail = json.dumps({ "status" : "error", "message" : "Project already exists.", }).encode('utf-8') http_non_fail_error= Mock() http_non_fail_error.data = data_non_fail data_fail = json.dumps({ "error" : "error", "message" : "Other message.", }).encode('utf-8') http_raise_error = Mock() http_raise_error.data = data_fail http_status_error = Mock() http_status_error.data = "non JSON error response".encode('utf-8') http_status_error.status = 418 session_data = json.dumps({ "status" : "success", "session.id" : "test-session-id-12345432" }).encode('utf-8') http_session = Mock() http_session.data = session_data http_session.status = 200
[ 11748, 37456, 62, 30281, 198, 6738, 555, 715, 395, 1330, 6208, 20448, 198, 6738, 15290, 1330, 869, 11, 8529, 11, 44123, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 11748, 275, 2069, 18, 198, 11748, 33918, 198, 6738, 10214, 420, 382, ...
2.101382
1,302
import uuid from mongoengine import Document, StringField, ListField, UUIDField from django.conf import settings from cripts.core.cripts_mongoengine import CriptsBaseAttributes, CriptsSourceDocument from cripts.core.cripts_mongoengine import CriptsActionsDocument
[ 11748, 334, 27112, 198, 198, 6738, 285, 25162, 18392, 1330, 16854, 11, 10903, 15878, 11, 7343, 15878, 11, 471, 27586, 15878, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 198, 6738, 269, 1968, 82, 13, 7295, 13, 6519, 82, 62, 76...
3.25
84
import pytest import operator as op from sweetpea import fully_cross_block from sweetpea.primitives import Factor, DerivedLevel, WithinTrial, Transition, Window from sweetpea.encoding_diagram import __generate_encoding_diagram color = Factor("color", ["red", "blue"]) text = Factor("text", ["red", "blue"]) con_level = DerivedLevel("con", WithinTrial(op.eq, [color, text])) inc_level = DerivedLevel("inc", WithinTrial(op.ne, [color, text])) con_factor = Factor("congruent?", [con_level, inc_level]) color_repeats_factor = Factor("color repeats?", [ DerivedLevel("yes", Transition(lambda colors: colors[0] == colors[1], [color])), DerivedLevel("no", Transition(lambda colors: colors[0] != colors[1], [color])) ]) text_repeats_factor = Factor("text repeats?", [ DerivedLevel("yes", Transition(lambda colors: colors[0] == colors[1], [text])), DerivedLevel("no", Transition(lambda colors: colors[0] != colors[1], [text])) ]) design = [color, text, con_factor] crossing = [color, text] blk = fully_cross_block(design, crossing, [])
[ 11748, 12972, 9288, 198, 11748, 10088, 355, 1034, 198, 198, 6738, 6029, 431, 64, 1330, 3938, 62, 19692, 62, 9967, 198, 6738, 6029, 431, 64, 13, 19795, 20288, 1330, 27929, 11, 9626, 1572, 4971, 11, 12511, 51, 4454, 11, 40658, 11, 26580...
2.977591
357
import json from labinstrument.SS.CMW500.CMW500_WIFI.CMW500_WIFI import * if __name__ == '__main__': new_config_name='emm' new_config=CMW_WIFI(17).get_parameters() config=json.load(open('config.txt')) config[new_config_name]=new_config json.dump(config,open('config.txt','w'))
[ 11748, 33918, 198, 6738, 2248, 259, 43872, 13, 5432, 13, 34, 14326, 4059, 13, 34, 14326, 4059, 62, 54, 5064, 40, 13, 34, 14326, 4059, 62, 54, 5064, 40, 1330, 1635, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, ...
2.302326
129
import yaml import os import time import datetime from pycti.utils.constants import StixCyberObservableTypes from weasyprint import HTML from pycti import OpenCTIConnectorHelper, get_config_variable from jinja2 import Environment, FileSystemLoader if __name__ == "__main__": try: connector_export_report_pdf = ExportReportPdf() connector_export_report_pdf.start() except Exception as e: print(e) time.sleep(10) exit(0)
[ 11748, 331, 43695, 198, 11748, 28686, 198, 11748, 640, 198, 11748, 4818, 8079, 198, 6738, 12972, 310, 72, 13, 26791, 13, 9979, 1187, 1330, 520, 844, 20418, 527, 31310, 712, 540, 31431, 198, 6738, 356, 4107, 4798, 1330, 11532, 198, 6738,...
2.670455
176
from django.urls import path from .views import initiate_payment, callback urlpatterns = [ path('', initiate_payment, name='pay'), path('callback/', callback, name='callback'), ]
[ 6738, 42625, 14208, 13, 6371, 82, 1330, 3108, 198, 6738, 764, 33571, 1330, 22118, 62, 37301, 11, 23838, 198, 198, 6371, 33279, 82, 796, 685, 198, 220, 220, 220, 3108, 10786, 3256, 22118, 62, 37301, 11, 1438, 11639, 15577, 33809, 198, ...
3.258621
58
def get(isamAppliance, check_mode=False, force=False): """ Retrieve an overview of updates and licensing information """ return isamAppliance.invoke_get("Retrieve an overview of updates and licensing information", "/updates/overview") def get_licensing_info(isamAppliance, check_mode=False, force=False): """ Retrieve the licensing information """ return isamAppliance.invoke_get("Retrieve the licensing information", "/lum/is_licensed")
[ 4299, 651, 7, 271, 321, 4677, 75, 3610, 11, 2198, 62, 14171, 28, 25101, 11, 2700, 28, 25101, 2599, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 4990, 30227, 281, 16700, 286, 5992, 290, 15665, 1321, 198, 220, 220, 220, 37227, 198, ...
2.461538
221
# -*- coding: utf-8 -*- __author__ = "Paul Schifferer <dm@sweetrpg.com>" """ config.py - settings for the flask application object """ import os import redis from sweetrpg_library_api.application import constants
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 834, 9800, 834, 796, 366, 12041, 41665, 11882, 1279, 36020, 31, 34751, 81, 6024, 13, 785, 24618, 198, 37811, 198, 11250, 13, 9078, 198, 12, 6460, 329, 262, 42903, 3586, ...
3.070423
71
import pandas as pd from group import Group
[ 11748, 19798, 292, 355, 279, 67, 201, 198, 6738, 1448, 1330, 4912, 201, 198, 201, 198, 201, 198, 201, 198 ]
2.6
20
# Copyright (c) 2018 Mycroft AI, Inc. # # This file is part of Mycroft Skills Manager # (see https://github.com/MatthewScholefield/mycroft-light). # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. """Install, remove, update and track the skills on a device MSM can be used on the command line but is also used by Mycroft core daemons. """ import time import logging import shutil from functools import wraps from glob import glob from multiprocessing.pool import ThreadPool from os import path from typing import Dict, List from xdg import BaseDirectory from msm import GitException from msm.exceptions import ( AlreadyInstalled, AlreadyRemoved, MsmException, MultipleSkillMatches, RemoveException, SkillNotFound ) from msm.skill_entry import SkillEntry from msm.skill_repo import SkillRepo from msm.skill_state import ( initialize_skill_state, get_skill_state, write_device_skill_state, load_device_skill_state, device_skill_state_hash ) from msm.util import cached_property, MsmProcessLock LOG = logging.getLogger(__name__) CURRENT_SKILLS_DATA_VERSION = 2 ONE_DAY = 86400 def save_device_skill_state(func): """Decorator to overwrite the skills.json file when skill state changes. The methods decorated with this function are executed in threads. So, this contains some funky logic to keep the threads from stepping on one another. """ return func_wrapper def _init_skills_data(self): """Initial load of the skill state that occurs upon instantiation. If the skills state was upgraded after it was loaded, write the updated skills state to disk. """ try: del(self.device_skill_state['upgraded']) except KeyError: self.device_skill_state_hash = device_skill_state_hash( self.device_skill_state ) else: self.write_device_skill_state() def _upgrade_skills_data(self): """Upgrade the contents of the device skills state if needed.""" if self._device_skill_state.get('version', 0) == 0: self._upgrade_to_v1() if self._device_skill_state['version'] == 1: self._upgrade_to_v2() def _upgrade_to_v1(self): """Upgrade the device skills state to version one.""" self._device_skill_state.update(blacklist=[], version=1, skills=[]) for skill in self.local_skills.values(): skill_data = self._device_skill_state.get(skill.name, {}) try: origin = skill_data['origin'] except KeyError: origin = self._determine_skill_origin(skill) beta = skill_data.get('beta', False) skill_state = initialize_skill_state( skill.name, origin, beta, skill.skill_gid ) skill_state['installed'] = skill_data.get('installed', 0) if isinstance(skill_state['installed'], bool): skill_state['installed'] = 0 skill_state['updated'] = skill_data.get('updated', 0) self._device_skill_state['skills'].append(skill_state) self._device_skill_state.update(upgraded=True) def _upgrade_to_v2(self): """Upgrade the device skills state to version 2. This adds the skill_gid field to skill entries. """ self._update_skill_gid() self._device_skill_state.update(version=2, upgraded=True) def _sync_device_skill_state(self): """Sync device's skill state with with actual skills on disk.""" self._add_skills_to_state() self._remove_skills_from_state() self._update_skill_gid() def _add_skills_to_state(self): """Add local skill to state if it is not already there.""" skill_names = [s['name'] for s in self._device_skill_state['skills']] for skill in self.local_skills.values(): if skill.name not in skill_names: origin = self._determine_skill_origin(skill) skill_state = initialize_skill_state( skill.name, origin, False, skill.skill_gid ) self._device_skill_state['skills'].append(skill_state) def _remove_skills_from_state(self): """Remove skills from state that no longer exist in the filesystem.""" skills_to_remove = [] for skill in self._device_skill_state['skills']: is_not_local = skill['name'] not in self.local_skills is_installed_state = skill['installation'] == 'installed' if is_not_local and is_installed_state: skills_to_remove.append(skill) for skill in skills_to_remove: self._device_skill_state['skills'].remove(skill) def write_device_skill_state(self, data=None): """Write device's skill state to disk if it has been modified.""" data = data or self.device_skill_state if device_skill_state_hash(data) != self.device_skill_state_hash: write_device_skill_state(data) self.device_skill_state_hash = device_skill_state_hash(data) def update_all(self): return self.apply(update_skill, self.local_skills.values()) def _invalidate_skills_cache(self, new_value=None): """Reset the cached skill lists in case something changed. The cached_property decorator builds a _cache instance attribute storing a dictionary of cached values. Deleting from this attribute invalidates the cache. """ LOG.info('invalidating skills cache') if hasattr(self, '_cache') and 'all_skills' in self._cache: del self._cache['all_skills'] self._all_skills = None if new_value is None else new_value self._local_skills = None self._default_skills = None def find_skill(self, param, author=None, skills=None): # type: (str, str, List[SkillEntry]) -> SkillEntry """Find skill by name or url""" if param.startswith('https://') or param.startswith('http://'): repo_id = SkillEntry.extract_repo_id(param) for skill in self.all_skills: if skill.id == repo_id: return skill name = SkillEntry.extract_repo_name(param) skill_directory = SkillEntry.create_path(self.skills_dir, param) return SkillEntry(name, skill_directory, param, msm=self) else: skill_confs = { skill: skill.match(param, author) for skill in skills or self.all_skills } best_skill, score = max(skill_confs.items(), key=lambda x: x[1]) LOG.info('Best match ({}): {} by {}'.format( round(score, 2), best_skill.name, best_skill.author) ) if score < 0.3: raise SkillNotFound(param) low_bound = (score * 0.7) if score != 1.0 else 1.0 close_skills = [ skill for skill, conf in skill_confs.items() if conf >= low_bound and skill != best_skill ] if close_skills: raise MultipleSkillMatches([best_skill] + close_skills) return best_skill
[ 2, 15069, 357, 66, 8, 2864, 2011, 36714, 9552, 11, 3457, 13, 198, 2, 198, 2, 770, 2393, 318, 636, 286, 2011, 36714, 20389, 9142, 198, 2, 357, 3826, 3740, 1378, 12567, 13, 785, 14, 25372, 14874, 2305, 3245, 14, 1820, 36714, 12, 297...
2.418931
3,349
# Autogenerated by the mkresources management command 2014-11-13 05:39 from tastypie.resources import ModelResource from tastypie.fields import CharField from tastypie.constants import ALL from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from ietf import api from ietf.utils.models import DumpInfo api.utils.register(DumpInfoResource())
[ 2, 5231, 519, 877, 515, 416, 262, 33480, 37540, 4542, 3141, 1946, 12, 1157, 12, 1485, 8870, 25, 2670, 198, 6738, 14854, 4464, 494, 13, 37540, 1330, 9104, 26198, 198, 6738, 14854, 4464, 494, 13, 25747, 1330, 3178, 15878, 198, 6738, 148...
3.517857
112
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. import bisect import numpy as np from torch.utils.data.dataset import ConcatDataset as _ConcatDataset
[ 2, 15069, 357, 66, 8, 3203, 11, 3457, 13, 290, 663, 29116, 13, 1439, 6923, 33876, 13, 198, 11748, 47457, 478, 198, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 28034, 13, 26791, 13, 7890, 13, 19608, 292, 316, 1330, 1482, 9246, 273...
3.320755
53
# 153. Find Minimum in Rotated Sorted Array # # Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. # # (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). # # Find the minimum element. # # You may assume no duplicate exists in the array. if __name__ == '__main__': print Solution().findMin([4, 5, 6, 7, 0, 1, 2])
[ 2, 24652, 13, 9938, 26265, 287, 18481, 515, 311, 9741, 15690, 198, 2, 198, 2, 39200, 281, 7177, 23243, 287, 41988, 1502, 318, 38375, 379, 617, 30355, 6439, 284, 345, 27091, 13, 198, 2, 198, 2, 357, 72, 13, 68, 1539, 657, 352, 362,...
3.042017
119
import pytest from brownie import ( accounts, interface, MockVault, BadgerBridgeAdapter, CurveSwapStrategy, CurveTokenWrapper, ) from helpers.constants import AddressZero from helpers.registry import registry from config.badger_config import badger_config from scripts.systems.badger_system import connect_badger from scripts.systems.bridge_system import connect_bridge from scripts.systems.swap_system import connect_swap # Curve lp tokens RENBTC = "0x49849C98ae39Fff122806C06791Fa73784FB3675" TBTC = "0x64eda51d3Ad40D56b9dFc5554E06F94e1Dd786Fd" SBTC = "0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3" # Bridge mock vaults for testing. # Schema is (in token addr, vault name, vault symbol, vault token addr) BRIDGE_VAULTS = [ # TODO: When bridge adapter addr is approved, can test # directly against badger sett contracts. { "inToken": registry.tokens.renbtc, "outToken": registry.tokens.renbtc, "id": "native.renCrv", "symbol": "bcrvrenBTC", "token": RENBTC, "address": "0x6dEf55d2e18486B9dDfaA075bc4e4EE0B28c1545", "upgrade": True, }, { "inToken": registry.tokens.renbtc, "outToken": registry.tokens.renbtc, "id": "native.tbtcCrv", "symbol": "bcrvtBTC", "token": TBTC, "address": "0xb9D076fDe463dbc9f915E5392F807315Bf940334", "upgrade": True, }, { "inToken": registry.tokens.renbtc, "outToken": registry.tokens.renbtc, "id": "native.sbtcCrv", "symbol": "bcrvsBTC", "token": SBTC, "address": "0xd04c48A53c111300aD41190D63681ed3dAd998eC", "upgrade": True, }, { "inToken": registry.tokens.wbtc, "outToken": registry.tokens.wbtc, "id": "yearn.wbtc", "symbol": "byvwBTC", "token": registry.tokens.wbtc, "address": "0x4b92d19c11435614cd49af1b589001b7c08cd4d5", "upgrade": False, }, ] # Tests mint/burn to/from crv sett. # We create a mock vault for each pool token. # Tests swap router failures and wbtc mint/burn. def test_bridge_basic_swap_fail(): renbtc = registry.tokens.renbtc wbtc = registry.tokens.wbtc badger = connect_badger(badger_config.prod_json) bridge = connect_bridge(badger, badger_config.prod_json) swap = connect_swap(badger_config.prod_json) bridge.add_existing_swap(swap) _upgrade_bridge(badger, bridge) _deploy_bridge_mocks(badger, bridge) # NB: If true, fails during router opimizeSwap() call, otherwise the underlying strategy fails. for router_fail in [True, False]: _deploy_swap_mocks(badger, bridge, swap, router_fail=router_fail) # .1% slippage slippage = 0.001 amount = 1 * 10 ** 8 for accIdx in range(10, 12): account = accounts[accIdx] for i in range(0, 2): balanceBefore = interface.IERC20(renbtc).balanceOf(account) # Test mints bridge.adapter.mint( wbtc, slippage * 10 ** 4, account.address, AddressZero, # No vault. amount, # Darknode args hash/sig optional since gateway is mocked. "", "", {"from": account}, ) assert interface.IERC20(renbtc).balanceOf(account) > balanceBefore # NB: User should not receive any wbtc but rather renbtc as part # of the fallback mechanism. assert interface.IERC20(wbtc).balanceOf(account) == 0 # Tests swap router and wbtc mint/burn.
[ 11748, 12972, 9288, 198, 6738, 7586, 494, 1330, 357, 198, 220, 220, 220, 5504, 11, 198, 220, 220, 220, 7071, 11, 198, 220, 220, 220, 44123, 53, 1721, 11, 198, 220, 220, 220, 7772, 1362, 37385, 47307, 11, 198, 220, 220, 220, 46300, ...
2.056478
1,806
import os
[ 11748, 28686, 628 ]
3.666667
3
"""Top-level package for etherscan-py.""" __author__ = """Julian Koh""" __email__ = 'juliankohtx@gmail.com' __version__ = '0.1.0'
[ 37811, 9126, 12, 5715, 5301, 329, 28475, 35836, 12, 9078, 526, 15931, 198, 198, 834, 9800, 834, 796, 37227, 16980, 666, 24754, 37811, 198, 834, 12888, 834, 796, 705, 73, 377, 666, 74, 1219, 17602, 31, 14816, 13, 785, 6, 198, 834, 96...
2.471698
53
from subprocess import Popen, PIPE if __name__ == "__main__": run_command("ping google.com")
[ 6738, 850, 14681, 1330, 8099, 268, 11, 350, 4061, 36, 628, 198, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, 198, 220, 220, 220, 1057, 62, 21812, 7203, 13886, 23645, 13, 785, 4943, 198 ]
2.702703
37
from db_connection import db
[ 6738, 20613, 62, 38659, 1330, 20613, 198 ]
4.142857
7
"""Database models""" from sqlalchemy import orm import sqlalchemy from .db_session import SqlAlchemyBase # Task database model # User database model
[ 37811, 38105, 4981, 37811, 198, 198, 6738, 44161, 282, 26599, 1330, 393, 76, 198, 11748, 44161, 282, 26599, 198, 6738, 764, 9945, 62, 29891, 1330, 311, 13976, 2348, 26599, 14881, 628, 198, 2, 15941, 6831, 2746, 628, 198, 2, 11787, 6831,...
3.604651
43
# Generated by Django 3.0 on 2019-12-18 21:09 import ckeditor.fields from django.db import migrations
[ 2, 2980, 515, 416, 37770, 513, 13, 15, 319, 13130, 12, 1065, 12, 1507, 2310, 25, 2931, 198, 198, 11748, 269, 9091, 2072, 13, 25747, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 628 ]
2.971429
35
#!/usr/bin/env python """Unit tests for M2Crypto.m2 obj_* functions. """ from M2Crypto import ASN1, BIO, Rand, X509, m2, six from tests import unittest """ These functions must be cleaned up and moved to some python module Taken from CA managment code """ if __name__ == '__main__': Rand.load_file('randpool.dat', -1) unittest.TextTestRunner().run(suite()) Rand.save_file('randpool.dat')
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 37811, 26453, 5254, 329, 337, 17, 23919, 78, 13, 76, 17, 26181, 62, 9, 5499, 13, 198, 37811, 198, 6738, 337, 17, 23919, 78, 1330, 7054, 45, 16, 11, 347, 9399, 11, 8790, 11, ...
2.738255
149
#!/bin/python # -*- coding: utf-8 -*- # Droplet Name: ubuntu-512mb-sfo2-01 # IP Address: 138.68.252.152 # Username: root # Password: fbe29a96430704766b5054c4d9 # New Password: Rowing525 # https://medium.com/@hoppy/how-to-test-or-scrape-javascript-rendered-websites-with-python-selenium-a-beginner-step-by-c137892216aa from time import sleep from random import randint from selenium import webdriver from pyvirtualdisplay import Display # Run spider RealTassa = RealTassaSpider() items_list = RealTassa.parse() # Do something with the data touched for item in items_list: print item
[ 2, 48443, 8800, 14, 29412, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 2, 21045, 37069, 6530, 25, 20967, 11157, 12, 25836, 2022, 12, 82, 6513, 17, 12, 486, 198, 2, 6101, 17917, 25, 21503, 13, 3104, 1...
2.744186
215
from gdsfactory.simulation.gmeep.add_monitors import add_monitors from gdsfactory.simulation.gmeep.get_simulation import get_simulation from gdsfactory.simulation.gmeep.get_transmission_2ports import ( get_transmission_2ports, plot2D, plot3D, ) from gdsfactory.simulation.gmeep.plot_xsection import plot_xsection __all__ = [ "add_monitors", "get_simulation", "get_sparameters1x2", "get_transmission_2ports", "plot2D", "plot3D", "plot_xsection", "plot_eigenmode", ] __version__ = "0.0.2"
[ 6738, 308, 9310, 69, 9548, 13, 14323, 1741, 13, 70, 1326, 538, 13, 2860, 62, 2144, 6742, 1330, 751, 62, 2144, 6742, 198, 6738, 308, 9310, 69, 9548, 13, 14323, 1741, 13, 70, 1326, 538, 13, 1136, 62, 14323, 1741, 1330, 651, 62, 1432...
2.323144
229
#!/usr/bin/python3 import boto3 import botocore import fedora_messaging import fedora_messaging.api import hashlib import json import logging import os import subprocess import sys import tarfile import tempfile import traceback # Set local logging logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) FEDORA_MESSAGING_TOPIC_LISTEN = ( "org.fedoraproject.prod.coreos.build.request.ostree-import" ) FEDORA_MESSAGING_TOPIC_RESPOND = FEDORA_MESSAGING_TOPIC_LISTEN + ".finished" # We are processing the org.fedoraproject.prod.coreos.build.request.ostree-import topic # https://apps.fedoraproject.org/datagrepper/raw?topic=org.fedoraproject.prod.coreos.build.request.ostree-import&delta=100000 # The schema was originally designed in: # https://github.com/coreos/fedora-coreos-tracker/issues/198#issuecomment-513944390 EXAMPLE_MESSAGE_BODY = json.loads(""" { "build_id": "30.20190905.0", "stream": "testing", "basearch": "x86_64", "commit": "s3://fcos-builds/prod/streams/testing/builds/30.20190905.0/x86_64/ostree-commit.tar", "checksum": "sha256:d01db6939e7387afa2492ac8e2591c53697fc21cf16785585f7f1ac0de692863", "ostree_ref": "fedora/x86_64/coreos/testing", "ostree_checksum": "b4beca154dab3696fd04f32ddab818102caa9247ec3192403adb9aaecc991bd9", "target_repo": "prod" } """ ) KNOWN_OSTREE_REPOS = { "prod": "/mnt/koji/ostree/repo", "compose": "/mnt/koji/compose/ostree/repo", } # Given a repo (and thus an input JSON) analyze existing koji tag set # and tag in any missing packages # https://stackoverflow.com/a/55542529 # The code in this file is expected to be run through fedora messaging # However, you can run the script directly for testing purposes. The # below code allows us to do that and also fake feeding data to the # call by updating the json text below. if __name__ == "__main__": sh = logging.StreamHandler() sh.setFormatter( logging.Formatter("%(asctime)s %(levelname)s %(name)s - %(message)s") ) logger.addHandler(sh) m = fedora_messaging.api.Message( topic="org.fedoraproject.prod.coreos.build.request.ostree-import", body=EXAMPLE_MESSAGE_BODY, ) c = Consumer() c.__call__(m)
[ 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 198, 11748, 275, 2069, 18, 198, 11748, 10214, 420, 382, 198, 11748, 11672, 5799, 62, 37348, 3039, 198, 11748, 11672, 5799, 62, 37348, 3039, 13, 15042, 198, 11748, 12234, 8019, 198, 11748, ...
2.450549
910
from torch.utils.data.dataset import Dataset import numpy as np import pandas as pd import os import nibabel as nib from nilearn.image import resample_img import torch
[ 6738, 28034, 13, 26791, 13, 7890, 13, 19608, 292, 316, 1330, 16092, 292, 316, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 28686, 198, 11748, 33272, 9608, 355, 33272, 198, 6738, 299, 576, 1501, ...
3.230769
52
# Copyright (C) 2021 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions # and limitations under the License. import copy import numpy as np from mmdet.datasets.builder import PIPELINES from ..datasets import get_annotation_mmdet_format
[ 2, 15069, 357, 34, 8, 33448, 8180, 10501, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198, 2, ...
3.699482
193
from typing import List print(Solution().luckyNumbers([[3,7,8],[9,11,13],[15,16,17]])) print(Solution().luckyNumbers([[1,10,4,2],[9,3,8,7],[15,16,17,12]])) print(Solution().luckyNumbers([[7,8],[1,2]]))
[ 6738, 19720, 1330, 7343, 198, 198, 4798, 7, 46344, 22446, 75, 5309, 49601, 26933, 58, 18, 11, 22, 11, 23, 38430, 24, 11, 1157, 11, 1485, 38430, 1314, 11, 1433, 11, 1558, 11907, 4008, 198, 4798, 7, 46344, 22446, 75, 5309, 49601, 2693...
2.295455
88
# UC10 - Evaluate price # # User U exists and has valid account # We create two Users, User1_UC10, User2_UC10 and one new gasStation GasStationUC10 # # Registered on a 1920x1080p, Google Chrome 100% zoom ### SETUP #User1 click("1590678880209.png") click("1590678953637.png") wait(2) type("1590829373120.png", "User1_UC10" + Key.TAB + "user1uc10@polito.it" + Key.TAB + "user1") click("1590679157604.png") click("1590788841790.png") wait(2) # User2 click("1590678880209.png") wait(2) click("1590678953637.png") wait(2) type("1590829373120.png", "User2_UC10" + Key.TAB + "user2uc10@polito.it" + Key.TAB + "user2") click("1590679157604.png") click("1590788841790.png") # Admin creates a new GasStation click("1590678880209-1.png") wait(3) type("1590829943940.png", "admin@ezgas.com" + Key.TAB + "admin" ) click("1590784293656.png") wait(2) click("1590784369122.png") wait(2) wheel(WHEEL_DOWN, 6) wait(2) type("1590830169812.png", "GasStation_UC10" + Key.TAB + "Torino, corso duca") wait( "add_UC10.png" , 20) type(Key.DOWN + Key.ENTER) type("1590830389386.png", Key.DOWN + Key.DOWN + Key.ENTER) click("1590830256446.png") click("1590830265272.png") wait(2) click("1590785166092.png") wait(3) type(Key.HOME) click("1590788397797.png") wait(2) click("1590828906996.png") wait(2) click("1590788458524.png") # User1 searches the gasStation click("1590678880209.png") wait(3) type("1590829943940.png", "user1uc10@polito.it" + Key.TAB + "user1" ) click("1590784293656.png") wait(2) wheel(WHEEL_DOWN, 6) type("1590931278631.png" , "Torino, corso duca" ) wait( "add_UC10.png" , 20) type(Key.DOWN + Key.ENTER) wait(2) click("1590922172004.png") wait(2) wheel(WHEEL_DOWN, 4) wait(2) click(Pattern("1590922374562.png").targetOffset(543,-4)) wheel(WHEEL_DOWN, 4) wait(2) click(Pattern("1590930530512.png").targetOffset(73,1)) type("1.5") click(Pattern("1590930568512.png").targetOffset(73,0)) type("1.4") click("1590834482526.png") wait(3) type(Key.HOME) wait(3) click("1590788458524.png") # User2 login and evaluate prices wait(2) click("1590678880209.png") wait(3) type("1590829943940.png", "user2uc10@polito.it" + Key.TAB + "user2" ) click("1590784293656.png") wait(2) wheel(WHEEL_DOWN, 4) wait(2) type("1590918242822-1.png" , "Torino, corso duca" ) wait( "add_UC10.png" , 20) type(Key.DOWN + Key.ENTER) wait(2) click("1590918499196.png") wheel(WHEEL_DOWN, 3) click(Pattern("1591638408351.png").targetOffset(1068,-3)) # User2 clicks on the green button if the price is correct, otherwise clicks on the red button # If User clicks the green button, the User1 trustlevel increases +1, otherwise it decreases -1 # wait(3) type(Key.HOME) click("1590788458524.png") wait(2) # Admin deletes users and gasStation click("1590678880209-1.png") wait(3) type("1590829943940.png", "admin@ezgas.com" + Key.TAB + "admin" ) click("1590784293656.png") wait(2) click("1590784369122.png") wait(2) wheel(WHEEL_DOWN, 10) wait(2) click(Pattern("1590931822851.png").targetOffset(905,-27)) wait(2) wheel(WHEEL_UP, 15) wait(2) click(Pattern("1590931876805.png").targetOffset(560,-4)) wait(2) click(Pattern("1590931914901.png").targetOffset(556,-10)) wait(2) click("1590788397797.png") wait(2) click("1590828906996.png") wait(2) click("1590788458524.png") wait(2)
[ 2, 220, 220, 220, 14417, 940, 532, 26439, 4985, 2756, 198, 2, 198, 2, 220, 220, 220, 11787, 471, 7160, 220, 290, 468, 4938, 1848, 198, 198, 2, 220, 220, 220, 220, 775, 2251, 734, 18987, 11, 11787, 16, 62, 9598, 940, 11, 11787, 1...
2.283925
1,437
# -*- coding: utf-8 -*- # Generated by Django 1.11.3 on 2017-07-27 16:14 from __future__ import unicode_literals from django.db import migrations, models
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 37770, 352, 13, 1157, 13, 18, 319, 2177, 12, 2998, 12, 1983, 1467, 25, 1415, 198, 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, ...
2.736842
57
# -------------------------------------------------------- # Pytorch Multi-GPU Faster R-CNN # Licensed under The MIT License [see LICENSE for details] # Written by Jiasen Lu, Jianwei Yang, based on code from Ross Girshick # -------------------------------------------------------- from __future__ import absolute_import from __future__ import division from __future__ import print_function import _init_paths import os import sys import numpy as np import argparse import pprint import pdb import time import cv2 import torch from torch.autograd import Variable import torch.nn as nn import torch.optim as optim import pickle from roi_data_layer.roidb import combined_roidb from roi_data_layer.roibatchLoader import roibatchLoader from model.utils.config import cfg, cfg_from_file, cfg_from_list, get_output_dir from model.rpn.bbox_transform import clip_boxes # from model.nms.nms_wrapper import nms from model.roi_layers import nms from model.rpn.bbox_transform import bbox_transform_inv from model.utils.net_utils import save_net, load_net, vis_detections from model.faster_rcnn.vgg16 import vgg16 from model.faster_rcnn.resnet import resnet from PIL import Image from torchvision.utils import save_image import cv2 from torch.utils.data import DataLoader from srgan_datasets import * from srgan import * import torch.nn.functional as F from datasets.voc_eval import parse_rec try: xrange # Python 2 except NameError: xrange = range # Python 3 classes = ('__background__', # always index 0 'A.bes(H)','A.bes(T)','A.bes','A.bic(H)','A.bic(T)','A.bic', 'A.fuj(H)','A.fuj(T)','A.fuj','B.xyl(H)','B.xyl(T)','B.xyl', 'C.ele(H)','C.ele(T)','C.ele','M.ent(H)','M.ent(T)','M.ent', 'M.gra(H)','M.gra(T)','M.gra','M.inc(H)','M.inc(T)','M.inc', 'P.cof(H)','P.cof(T)','P.cof','P.vul(H)','P.vul(T)','P.vul', 'P.spe(H)','P.spe(T)','P.spe','H.sp(H)','H.sp(T)','H.sp', 'M.ams(H)' ,'M.ams(T)','M.ams' )################### def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Train a Fast R-CNN network') parser.add_argument('--dataset', dest='dataset', help='training dataset', default='pascal_voc', type=str) parser.add_argument('--cfg', dest='cfg_file', help='optional config file', default='cfgs/res101.yml', type=str) parser.add_argument('--net', dest='net', help='vgg16, res50, res101, res152', default='res101', type=str) parser.add_argument('--set', dest='set_cfgs', help='set config keys', default=None, nargs=argparse.REMAINDER) parser.add_argument('--load_dir', dest='load_dir', help='directory to load models', default="models", type=str) parser.add_argument('--cuda', dest='cuda', help='whether use CUDA', action='store_true') parser.add_argument('--ls', dest='large_scale', help='whether use large imag scale', action='store_true') parser.add_argument('--mGPUs', dest='mGPUs', help='whether use multiple GPUs', action='store_true') parser.add_argument('--cag', dest='class_agnostic', help='whether perform class_agnostic bbox regression', action='store_true') parser.add_argument('--parallel_type', dest='parallel_type', help='which part of model to parallel, 0: all, 1: model before roi pooling', default=0, type=int) parser.add_argument('--checksession', dest='checksession', help='checksession to load model', default=1, type=int) parser.add_argument('--checkepoch', dest='checkepoch', help='checkepoch to load network', default=1, type=int) parser.add_argument('--checkpoint', dest='checkpoint', help='checkpoint to load network', default=10021, type=int) parser.add_argument('--vis', dest='vis', help='visualization mode', action='store_true') args = parser.parse_args() return args lr = cfg.TRAIN.LEARNING_RATE momentum = cfg.TRAIN.MOMENTUM weight_decay = cfg.TRAIN.WEIGHT_DECAY def iou(bb1, bb2):######################### """ check if overlap""" #assert bb1[0] < bb1[2] #assert bb1[1] < bb1[3] #assert bb2[0] < bb2[2] #assert bb2[1] < bb2[3] # determine the coordinates of the intersection rectangle #print(bb1[0], bb2[0]) x_left = max(bb1[0], bb2[0]) y_top = max(bb1[1], bb2[1]) x_right = min(bb1[2], bb2[2]) y_bottom = min(bb1[3], bb2[3]) iw = x_right - x_left ih = y_bottom - y_top inters = iw * ih # union uni = ((bb1[2]-bb1[0])*(bb1[3]-bb1[1]) + (bb2[2]-bb2[0])*(bb2[3]-bb2[1]) - inters) overlaps = inters / uni return overlaps if __name__ == '__main__': args = parse_args() args_sr = parse_args_for_srgan() print('Called with args:') print(args) if torch.cuda.is_available() and not args.cuda: print("WARNING: You have a CUDA device, so you should probably run with --cuda") np.random.seed(cfg.RNG_SEED) if args.dataset == "pascal_voc": args.imdb_name = "voc_2007_trainval" args.imdbval_name = "voc_2007_test" args.set_cfgs = ['ANCHOR_SCALES', '[8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] elif args.dataset == "pascal_voc_0712": args.imdb_name = "voc_2007_trainval+voc_2012_trainval" args.imdbval_name = "voc_2007_test" args.set_cfgs = ['ANCHOR_SCALES', '[8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] elif args.dataset == "coco": args.imdb_name = "coco_2014_train+coco_2014_valminusminival" args.imdbval_name = "coco_2014_minival" args.set_cfgs = ['ANCHOR_SCALES', '[4, 8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] elif args.dataset == "imagenet": args.imdb_name = "imagenet_train" args.imdbval_name = "imagenet_val" args.set_cfgs = ['ANCHOR_SCALES', '[8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] elif args.dataset == "vg": args.imdb_name = "vg_150-50-50_minitrain" args.imdbval_name = "vg_150-50-50_minival" args.set_cfgs = ['ANCHOR_SCALES', '[4, 8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] args.cfg_file = "cfgs/{}_ls.yml".format(args.net) if args.large_scale else "cfgs/{}.yml".format(args.net) if args.cfg_file is not None: cfg_from_file(args.cfg_file) if args.set_cfgs is not None: cfg_from_list(args.set_cfgs) print('Using config:') pprint.pprint(cfg) cfg.TRAIN.USE_FLIPPED = False imdb, roidb, ratio_list, ratio_index = combined_roidb(args.imdbval_name, False) imdb.competition_mode(on=True) print('{:d} roidb entries'.format(len(roidb))) input_dir = args.load_dir + "/" + args.net + "/" + args.dataset if not os.path.exists(input_dir): raise Exception('There is no input directory for loading network from ' + input_dir) load_name = os.path.join(input_dir, 'faster_rcnn_{}_{}_{}.pth'.format(args.checksession, args.checkepoch, args.checkpoint)) # initilize the network here. if args.net == 'vgg16': fasterRCNN = vgg16(imdb.classes, pretrained=False, class_agnostic=args.class_agnostic) elif args.net == 'res101': fasterRCNN = resnet(imdb.classes, 101, pretrained=False, class_agnostic=args.class_agnostic) elif args.net == 'res50': fasterRCNN = resnet(imdb.classes, 50, pretrained=False, class_agnostic=args.class_agnostic) elif args.net == 'res152': fasterRCNN = resnet(imdb.classes, 152, pretrained=False, class_agnostic=args.class_agnostic) else: print("network is not defined") pdb.set_trace() fasterRCNN.create_architecture() print("load checkpoint %s" % (load_name)) checkpoint = torch.load(load_name) fasterRCNN.load_state_dict(checkpoint['model']) if 'pooling_mode' in checkpoint.keys(): cfg.POOLING_MODE = checkpoint['pooling_mode'] print('load model successfully!') # initilize the tensor holder here. im_data = torch.FloatTensor(1) im_info = torch.FloatTensor(1) num_boxes = torch.LongTensor(1) gt_boxes = torch.FloatTensor(1) # ship to cuda if args.cuda: im_data = im_data.cuda() im_info = im_info.cuda() num_boxes = num_boxes.cuda() gt_boxes = gt_boxes.cuda() # make variable im_data = Variable(im_data) im_info = Variable(im_info) num_boxes = Variable(num_boxes) gt_boxes = Variable(gt_boxes) if args.cuda: cfg.CUDA = True if args.cuda: fasterRCNN.cuda() start = time.time() max_per_image = 100 vis = args.vis if vis: thresh = 0.0 else: thresh = 0.0 save_name = 'faster_rcnn_10' num_images = len(imdb.image_index) all_boxes = [[[] for _ in range(num_images)] for _ in range(imdb.num_classes)] output_dir = get_output_dir(imdb, save_name) dataset = roibatchLoader(roidb, ratio_list, ratio_index, 1, \ imdb.num_classes, training=False, normalize = False) dataloader = torch.utils.data.DataLoader(dataset, batch_size=1, shuffle=False, num_workers=0, pin_memory=True) data_iter = iter(dataloader) _t = {'im_detect': time.time(), 'misc': time.time()} det_file = os.path.join(output_dir, 'detections.pkl') fasterRCNN.eval() empty_array = np.transpose(np.array([[],[],[],[],[]]), (1,0)) for i in range(num_images): data = next(data_iter) with torch.no_grad(): im_data.resize_(data[0].size()).copy_(data[0]) im_info.resize_(data[1].size()).copy_(data[1]) gt_boxes.resize_(data[2].size()).copy_(data[2]) num_boxes.resize_(data[3].size()).copy_(data[3]) #print(im_data.shape) #print(im_info.shape) #print(gt_boxes) #print(num_boxes) det_tic = time.time() rois, cls_prob, bbox_pred, \ rpn_loss_cls, rpn_loss_box, \ RCNN_loss_cls, RCNN_loss_bbox, \ rois_label = fasterRCNN(im_data, im_info, gt_boxes, num_boxes) scores = cls_prob.data boxes = rois.data[:, :, 1:5] if cfg.TEST.BBOX_REG: # Apply bounding-box regression deltas box_deltas = bbox_pred.data if cfg.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED: # Optionally normalize targets by a precomputed mean and stdev if args.class_agnostic: box_deltas = box_deltas.view(-1, 4) * torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_STDS).cuda() \ + torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_MEANS).cuda() box_deltas = box_deltas.view(1, -1, 4) else: box_deltas = box_deltas.view(-1, 4) * torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_STDS).cuda() \ + torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_MEANS).cuda() box_deltas = box_deltas.view(1, -1, 4 * len(imdb.classes)) pred_boxes = bbox_transform_inv(boxes, box_deltas, 1) pred_boxes = clip_boxes(pred_boxes, im_info.data, 1) else: # Simply repeat the boxes, once for each class pred_boxes = np.tile(boxes, (1, scores.shape[1])) pred_boxes /= data[1][0][2].item() scores = scores.squeeze() pred_boxes = pred_boxes.squeeze() det_toc = time.time() detect_time = det_toc - det_tic misc_tic = time.time() #print(scores[:,1:3].shape) #print(pred_boxes[:,4:12].shape) ############################## decline head-tail overlapping new_pred_boxes = torch.cuda.FloatTensor(300, 160).zero_() new_scores = torch.cuda.FloatTensor(300,40).zero_() for k in range(13): b = torch.cat((pred_boxes[:,12*k+4:12*k+8],pred_boxes[:,12*k+8:12*k+12]),0) s = torch.cat((scores[:,3*k+1],scores[:,3*k+2]),0) keep = nms(b, s, 0.2) #new head class idx = [g for g in range(len(keep)) if keep[g] <300] new_pred_boxes[:len(keep[idx]),12*k+4:12*k+8] = b[keep[idx]] new_scores[:len(keep[idx]),3*k+1] = s[keep[idx]] #new tail class idx = [g for g in range(len(keep)) if keep[g] >=300] new_pred_boxes[:len(keep[idx]),12*k+8:12*k+12] = b[keep[idx]] new_scores[:len(keep[idx]),3*k+2] = s[keep[idx]] #new full length class = original new_pred_boxes[:,12*k+12:12*k+16] = pred_boxes[:,12*k+12:12*k+16] new_scores[:,3*k+3] = scores[:,3*k+3] if vis: im = cv2.imread(imdb.image_path_at(i)) im2show = np.copy(im) for j in range(1, imdb.num_classes): inds = torch.nonzero(new_scores[:,j]>thresh).view(-1) # if there is det if inds.numel() > 0: cls_scores = new_scores[:,j][inds] _, order = torch.sort(cls_scores, 0, True) if args.class_agnostic: cls_boxes = new_pred_boxes[inds, :] else: cls_boxes = new_pred_boxes[inds][:, j * 4:(j + 1) * 4] #print(cls_boxes.shape) #print(cls_scores.unsqueeze(1).shape) cls_dets = torch.cat((cls_boxes, cls_scores.unsqueeze(1)), 1) # cls_dets = torch.cat((cls_boxes, cls_scores), 1) cls_dets = cls_dets[order] keep = nms(cls_boxes[order, :], cls_scores[order], cfg.TEST.NMS) cls_dets = cls_dets[keep.view(-1).long()] if vis: im2show = vis_detections(im2show, imdb.classes[j], cls_dets.cpu().numpy(), 0.3) all_boxes[j][i] = cls_dets.cpu().numpy() else: all_boxes[j][i] = empty_array #print(exist_classes) #for k, j in enumerate(exist_classes): # all_boxes[j][i] = exist_dets[k] #print(all_boxes) # Limit to max_per_image detections *over all classes* if max_per_image > 0: #print(all_boxes[3][i][:,-1]) image_scores = np.hstack([all_boxes[j][i][:,-1] for j in range(1, imdb.num_classes)]) if len(image_scores) > max_per_image: image_thresh = np.sort(image_scores)[-max_per_image] for j in xrange(1, imdb.num_classes): keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0] all_boxes[j][i] = all_boxes[j][i][keep, :] misc_toc = time.time() nms_time = misc_toc - misc_tic sys.stdout.write('im_detect: {:d}/{:d} {:.3f}s {:.3f}s \r' \ .format(i + 1, num_images, detect_time, nms_time)) sys.stdout.flush() if vis: cv2.imwrite('result.png', im2show) pdb.set_trace() #cv2.imshow('test', im2show) #cv2.waitKey(0) #print(all_boxes[1][0][0]) print(torch.cuda.current_device()) with torch.cuda.device(torch.cuda.current_device()): torch.cuda.empty_cache() #################################### filter imgs need to do SRGAN-preprocessing annopath = '/home/jason/faster-rcnn.pytorch-1.0/data/VOCdevkit2007/VOC2007/Annotations/{:s}.xml' imagesetfile = '/home/jason/faster-rcnn.pytorch-1.0/data/VOCdevkit2007/VOC2007/ImageSets/Main/test.txt' cachedir = '/home/jason/faster-rcnn.pytorch-1.0/data/VOCdevkit2007/annotations_cache' image_file = '/home/jason/faster-rcnn.pytorch-1.0/data/VOCdevkit2007/VOC2007/JPEGImages' f = open(imagesetfile) new_indexes = [] img_ids = [] new_gt_boxes = [] for line in f: img_ids.append(line.splitlines()) img_ids = np.squeeze(img_ids) for i in range(num_images): for j in range(1, imdb.num_classes): gt_boxes_1 = load_gt_box(annopath,imagesetfile,classes[j],cachedir) if not np.any(all_boxes[j][i]): continue if len(gt_boxes_1[img_ids[i]]['bbox']) == 0: continue else:# 1 GT box in single image for a single class gt_b = gt_boxes_1[img_ids[i]]['bbox'] #print(gt_b) z = 0 for m in range(len(all_boxes[j][i])): for n in range(len(gt_b)): det_b = [int(l) for l in all_boxes[j][i][m][:4]] #print(all_boxes[j][i][m][4], iou(det_b, gt_b[n]), imdb.image_index[j]) if all_boxes[j][i][m][4] > 0.5 and all_boxes[j][i][m][4] < 0.8 \ and iou(det_b, gt_b[n]) > 0.5 and classes[j][-1]==")": print("srgan beginning......") new_indexes.append(img_ids[i]+"_"+classes[j]+"_"+str(z)) print(len(new_indexes))#, all_boxes[j][i][m][4], iou(det_b, gt_b[n])) img_path = os.path.join(image_file, img_ids[i]+".JPG") img = Image.open(img_path) img = np.asarray(img) quaterx = int(img.shape[1]*1/4) quatery = int(img.shape[0]*1/4) x1_padding = 0 y1_padding = 0 x2_padding = 0 y2_padding = 0 print(img.shape) if Area(det_b) >= Area(gt_b[n]): x1, y1, x2, y2 = det_b print("det_b: " + str(det_b)) if x1 > quaterx: x1-=quaterx x1_padding = quaterx else: x1 = 0 x1_padding = x1 if x2 < img.shape[0]-quaterx: x2+= quaterx x2_padding = quaterx else: x2 = img.shape[0]-1 x2_padding = img.shape[0] - x2-1 if y1 > quatery: y1 -=quatery y1_padding = quatery else: y1 = 0 y1_padding = y1 if y2 < img.shape[1]-quatery: y2+=quatery y2_padding = quatery else: y2= img.shape[1]-1 y2_padding = img.shape[1] - y2-1 else: x1, y1, x2, y2 = gt_b[n] print("gt_b: "+str(gt_b)) if x1 > quaterx: x1-=quaterx x1_padding = quaterx else: x1 = 0 x1_padding = x1 if x2 < img.shape[0]-quaterx: x2+= quaterx x2_padding = quaterx else: x2 = img.shape[0]-1 x2_padding = img.shape[0] - x2-1 if y1 > quatery: y1 -=quatery y1_padding = quatery else: y1 = 0 y1_padding = y1 if y2 < img.shape[1]-quatery: y2+=quatery y2_padding = quatery else: y2= img.shape[1]-1 y2_padding = img.shape[1] - y2-1 x1, y1, x2, y2= int(x1),int(y1),int(x2), int(y2) new_gt_boxes.append([x1_padding, y1_padding, x2-x1-x1_padding-x2_padding, \ y2-y1-y1_padding-y2_padding])# whole photo srgan_in = img[y1:y2 ,x1:x2 ,:] srgan_in = srgan_in[...,::-1]#rgb->bgr print(x1,y1,x2,y2,srgan_in.shape) cv2.imwrite(os.path.join("srgan/srgan_input", img_ids[i]+"_"+classes[j]+"_"+str(z)+".JPG"), srgan_in) print("save input: %s" %(img_ids[i]+"_"+classes[j]+"_"+str(z))) z+=1 all_boxes[j][i][m] = np.append(gt_b[n], 1.0)# turn original pred box to gt box with torch.cuda.device(torch.cuda.current_device()): torch.cuda.empty_cache() dataloader = DataLoader( ImageDataset("srgan/srgan_input", hr_shape=(1024,1024)), batch_size=1, shuffle=True, num_workers=0, ) #gan_output = srgan(args_sr, dataloader) srgan(args_sr, dataloader) #print("length of data: %d"%len(gan_output)) print("srgan finish......") with torch.cuda.device(torch.cuda.current_device()): torch.cuda.empty_cache() # re-test srgan output dataloader1 = DataLoader( ImageDataset("srgan/srgan_output", hr_shape=(1024,1024)), batch_size=1, shuffle=True, num_workers=0, ) all_boxes_1 = [[[] for _ in range(len(dataloader1))] for _ in range(imdb.num_classes)] for i, gan_img in enumerate(dataloader1): #for i in range(len(dataloader1)): #gan_img = gan_output[i] #print(gan_img) arr = np.append(gan_img["origin_size"][0][0].numpy(), gan_img["origin_size"][1][0].numpy()) gan_img_os = F.interpolate(gan_img['hr'], size=(arr[0],arr[1]), mode='bilinear') r = 600 / gan_img_os.shape[2] gan_info = np.array([[gan_img_os.shape[2], gan_img_os.shape[3], r]]) with torch.no_grad(): gan_img_600 = F.interpolate(gan_img_os, scale_factor=r, mode="bilinear").cuda() gan_info = torch.from_numpy(gan_info).cuda() gt_boxes num_boxes #print(gan_img.shape) #print(gan_info.shape) #print(gt_boxes) #print(num_boxes) det_tic = time.time() rois_1, cls_prob_1, bbox_pred_1, \ rpn_loss_cls_1, rpn_loss_box_1, \ RCNN_loss_cls_1, RCNN_loss_bbox_1, \ rois_label_1 = fasterRCNN(gan_img_600, gan_info, gt_boxes, num_boxes) scores_1 = cls_prob_1.data boxes_1 = rois_1.data[:, :, 1:5] #print(data) if cfg.TEST.BBOX_REG: # Apply bounding-box regression deltas box_deltas = bbox_pred_1.data if cfg.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED: # Optionally normalize targets by a precomputed mean and stdev if args.class_agnostic: box_deltas_1 = box_deltas.view(-1, 4) * torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_STDS).cuda() \ + torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_MEANS).cuda() box_deltas_1 = box_deltas.view(1, -1, 4) else: box_deltas_1 = box_deltas.view(-1, 4) * torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_STDS).cuda() \ + torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_MEANS).cuda() box_deltas_1 = box_deltas.view(1, -1, 4 * len(imdb.classes)) pred_boxes_1 = bbox_transform_inv(boxes, box_deltas_1, 1) pred_boxes_1 = clip_boxes(pred_boxes_1, gan_info.data, 1) else: # Simply repeat the boxes, once for each class pred_boxes_1 = np.tile(boxes_1, (1, scores.shape[1])) pred_boxes_1 /= data[1][0][2].item() scores_1 = scores_1.squeeze() pred_boxes_1 = pred_boxes_1.squeeze() det_toc = time.time() detect_time = det_toc - det_tic misc_tic = time.time() ############################## decline head-tail overlapping new_pred_boxes = torch.cuda.FloatTensor(300, 160).zero_() new_scores = torch.cuda.FloatTensor(300,40).zero_() for k in range(13): b = torch.cat((pred_boxes_1[:,12*k+4:12*k+8],pred_boxes_1[:,12*k+8:12*k+12]),0) s = torch.cat((scores_1[:,3*k+1],scores_1[:,3*k+2]),0) keep = nms(b, s, 0.2) #new head class idx = [g for g in range(len(keep)) if keep[g] <300] new_pred_boxes[:len(keep[idx]),12*k+4:12*k+8] = b[keep[idx]] new_scores[:len(keep[idx]),3*k+1] = s[keep[idx]] #new tail class idx = [g for g in range(len(keep)) if keep[g] >=300] new_pred_boxes[:len(keep[idx]),12*k+8:12*k+12] = b[keep[idx]] new_scores[:len(keep[idx]),3*k+2] = s[keep[idx]] #new full length class = original new_pred_boxes[:,12*k+12:12*k+16] = pred_boxes[:,12*k+12:12*k+16] new_scores[:,3*k+3] = scores[:,3*k+3] if vis: im = cv2.imread(imdb.image_path_at(i)) im2show = np.copy(im) for j in range(1, imdb.num_classes): inds = torch.nonzero(new_scores[:,j]>thresh).view(-1) # if there is det if inds.numel() > 0: cls_scores_1 = new_scores[:,j][inds] _, order = torch.sort(cls_scores_1, 0, True) if args.class_agnostic: cls_boxes_1 = new_pred_boxes[inds, :] else: cls_boxes_1 = new_pred_boxes[inds][:, j * 4:(j + 1) * 4] cls_dets_1 = torch.cat((cls_boxes_1, cls_scores_1.unsqueeze(1)), 1) cls_dets_1 = cls_dets_1[order] keep = nms(cls_boxes_1[order, :], cls_scores_1[order], cfg.TEST.NMS) cls_dets_1 = cls_dets_1[keep.view(-1).long()] if vis: im2show = vis_detections(im2show, imdb.classes[j], cls_dets.cpu().numpy(), 0.3) all_boxes_1[j][i] = cls_dets.cpu().numpy() else: all_boxes_1[j][i] = empty_array # Limit to max_per_image detections *over all classes* if max_per_image > 0: #print(all_boxes[3][i][:,-1]) image_scores = np.hstack([all_boxes_1[j][i][:,-1] for j in range(1, imdb.num_classes)]) if len(image_scores) > max_per_image: image_thresh = np.sort(image_scores)[-max_per_image] for j in range(1, imdb.num_classes): keep = np.where(all_boxes_1[j][i][:, -1] >= image_thresh)[0] all_boxes_1[j][i] = all_boxes_1[j][i][keep, :] misc_toc = time.time() nms_time = misc_toc - misc_tic sys.stdout.write('im_detect: {:d}/{:d} {:.3f}s {:.3f}s \r' \ .format(i + 1, len(dataloader1), detect_time, nms_time)) sys.stdout.flush() torch.cuda.empty_cache() with open(det_file, 'wb') as f: pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL) print('Evaluating detections') end = time.time() #print(len(all_boxes)) #print(len(all_boxes_1[0])) for a in range(len(all_boxes)): all_boxes[a].extend(all_boxes_1[a]) print(len(all_boxes[a])) print(new_indexes) #print(new_gt_boxes) imdb.evaluate_detections(all_boxes, output_dir, new_indexes, new_gt_boxes) print("test time: %0.4fs" % (end - start))
[ 2, 20368, 22369, 198, 2, 9485, 13165, 354, 15237, 12, 33346, 38996, 371, 12, 18474, 198, 2, 49962, 739, 383, 17168, 13789, 685, 3826, 38559, 24290, 329, 3307, 60, 198, 2, 22503, 416, 449, 4448, 268, 6026, 11, 40922, 42990, 10998, 11, ...
1.92046
13,578
from flask import Flask, render_template, request, redirect, url_for, Markup import app_helper as apHelp app = Flask(__name__) # click convetBtn. get HttpParam. # click homeBtn from header. # click aboutBtn from header. # click historyBtn from header. if __name__ == '__main__': app.run(debug=True)
[ 6738, 42903, 1330, 46947, 11, 8543, 62, 28243, 11, 2581, 11, 18941, 11, 19016, 62, 1640, 11, 2940, 929, 198, 11748, 598, 62, 2978, 525, 355, 2471, 22087, 198, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 198, 198, 2, 3904, 369, 16...
2.90566
106
""" Makes subdirectories with slices of seismic time or depth images. For example, the directory with name "s3_84" contains a constant-i3 slice, where i3 = 84. """ from tputils import * #setupForSubset("subz_401_4_600") setupForSubset("subt_251_4_500") seismicDir = getSeismicDir() ############################################################################# ############################################################################# run(main)
[ 37811, 198, 44, 1124, 850, 12942, 1749, 351, 24314, 286, 37463, 640, 393, 6795, 4263, 13, 198, 1890, 1672, 11, 262, 8619, 351, 1438, 366, 82, 18, 62, 5705, 1, 4909, 257, 6937, 12, 72, 18, 198, 48369, 11, 810, 1312, 18, 796, 9508, ...
3.846154
117
""" LLDB AppKit formatters part of The LLVM Compiler Infrastructure This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. """ # summary provider for class NSException import lldb.runtime.objc.objc_runtime import lldb.formatters.metrics import CFString import lldb import lldb.formatters.Logger statistics = lldb.formatters.metrics.Metrics() statistics.add_metric('invalid_isa') statistics.add_metric('invalid_pointer') statistics.add_metric('unknown_class') statistics.add_metric('code_notrun') def GetSummary_Impl(valobj): logger = lldb.formatters.Logger.Logger() global statistics class_data, wrapper = lldb.runtime.objc.objc_runtime.Utilities.prepare_class_detection( valobj, statistics) if wrapper: return wrapper name_string = class_data.class_name() logger >> "class name is: " + str(name_string) if name_string == 'NSException': wrapper = NSKnownException_SummaryProvider( valobj, class_data.sys_params) statistics.metric_hit('code_notrun', valobj) else: wrapper = NSUnknownException_SummaryProvider( valobj, class_data.sys_params) statistics.metric_hit( 'unknown_class', valobj.GetName() + " seen as " + name_string) return wrapper def NSException_SummaryProvider(valobj, dict): logger = lldb.formatters.Logger.Logger() provider = GetSummary_Impl(valobj) if provider is not None: if isinstance( provider, lldb.runtime.objc.objc_runtime.SpecialSituation_Description): return provider.message() try: summary = provider.description() except: summary = None logger >> "got summary " + str(summary) if summary is None: summary = '<variable is not NSException>' return str(summary) return 'Summary Unavailable' def __lldb_init_module(debugger, dict): debugger.HandleCommand( "type summary add -F NSException.NSException_SummaryProvider NSException")
[ 37811, 198, 3069, 11012, 2034, 20827, 5794, 1010, 198, 198, 3911, 286, 383, 27140, 15996, 3082, 5329, 33709, 198, 1212, 2393, 318, 9387, 739, 262, 2059, 286, 9486, 4946, 8090, 198, 34156, 13, 4091, 38559, 24290, 13, 51, 25010, 329, 3307...
2.557023
833
self.description = "Install a package ('any' architecture)" p = pmpkg("dummy") p.files = ["bin/dummy", "usr/man/man1/dummy.1"] p.arch = 'any' self.addpkg(p) self.option["Architecture"] = ['auto'] self.args = "-U %s" % p.filename() self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=dummy") for f in p.files: self.addrule("FILE_EXIST=%s" % f)
[ 944, 13, 11213, 796, 366, 15798, 257, 5301, 19203, 1092, 6, 10959, 16725, 198, 198, 79, 796, 279, 3149, 10025, 7203, 67, 13513, 4943, 198, 79, 13, 16624, 796, 14631, 8800, 14, 67, 13513, 1600, 198, 220, 220, 220, 220, 220, 220, 220,...
2.233129
163
from simple_network.tcp_app_server import * import httptools """ Module Docstring Docstrings: http://www.python.org/dev/peps/pep-0257/ """ __author__ = 'ButenkoMS <gtalk@butenkoms.space>' # ====================================================================== # ===================GLOBAL SETTINGS FOR ALL TESTS====================== # SERVER_KEYWORD = b'http server inline' SERVER_ADDRESS = ('localhost', 25000) BSC__USE_READ_WITH_FIXED_BUFFER = True # "Optimized for speed". Good for Named Clients. # BSC__USE_READ_WITH_FIXED_BUFFER = False # "Optimized for memory". Good for big amount of Unknown Clients (raw, # http, etc.) if you have small server. BSC__SOCKET_READ_FIXED_BUFFER_SIZE = 1024 ** 2 BSC__USE_NODELAY_INET = True BSC__REUSE_GATE_ADDR = True BSC__REUSE_GATE_PORT = True LINE_TRACE_ALLOWED = True # # ===================GLOBAL SETTINGS FOR ALL TESTS====================== # ====================================================================== # ============================================================================================================== # !!!!! IMPORTANT !!!!! # NEXT CODE SHOULD BE EQUIVALENT TO ASYNCIO HTTP SERVER'S CODE FROM "https://github.com/MagicStack/vmbench" PROJECT # (BENCHMARKING TOOL FROM 'UVLOOP' DEVELOPERS) FOR FAIR COMPARISON, SO IT'S SO DIRTY. # (IT'S ALMOST EQUIVALENT: IT DOES NOT HAVE FEW CRITICAL vmbench's BUGS) _RESP_CACHE = {} if __name__ == '__main__': run_http_server()
[ 6738, 2829, 62, 27349, 13, 83, 13155, 62, 1324, 62, 15388, 1330, 1635, 198, 11748, 1841, 457, 10141, 198, 198, 37811, 198, 26796, 14432, 8841, 198, 23579, 37336, 25, 2638, 1378, 2503, 13, 29412, 13, 2398, 14, 7959, 14, 431, 862, 14, ...
2.925926
513
from os import path from launch import LaunchDescription from ament_index_python.packages import get_package_share_directory from launch_ros.actions import Node from launch.actions import DeclareLaunchArgument from launch.substitutions import Command, LaunchConfiguration
[ 6738, 28686, 1330, 3108, 198, 6738, 4219, 1330, 21225, 11828, 198, 6738, 257, 434, 62, 9630, 62, 29412, 13, 43789, 1330, 651, 62, 26495, 62, 20077, 62, 34945, 198, 6738, 4219, 62, 4951, 13, 4658, 1330, 19081, 198, 6738, 4219, 13, 4658...
4.387097
62
from pyformance.meters import Event, EventPoint from tests import TimedTestCase
[ 6738, 12972, 10367, 13, 4164, 364, 1330, 8558, 11, 8558, 12727, 198, 6738, 5254, 1330, 5045, 276, 14402, 20448, 628 ]
4.05
20
""" Good morning! Here's your coding interview problem for today. This problem was asked by Amazon. Implement a stack that has the following methods: push(val), which pushes an element onto the stack pop(), which pops off and returns the topmost element of the stack. If there are no elements in the stack, then it should throw an error or return null. max(), which returns the maximum value in the stack currently. If there are no elements in the stack, then it should throw an error or return null. Each method should run in constant time. https://www.geeksforgeeks.org/design-a-stack-that-supports-getmin-in-o1-time-and-o1-extra-space/ https://www.geeksforgeeks.org/design-and-implement-special-stack-data-structure/ """ # Class to make a Node stack = Stack() stack.push(3) stack.push(5) stack.getMin() stack.getMax() stack.push(2) stack.push(1) stack.getMin() stack.getMax() stack.pop() stack.getMin() stack.getMax() stack.pop()
[ 37811, 198, 10248, 3329, 0, 3423, 338, 534, 19617, 2720, 1917, 329, 1909, 13, 198, 198, 1212, 1917, 373, 1965, 416, 6186, 13, 198, 198, 3546, 26908, 257, 8931, 326, 468, 262, 1708, 5050, 25, 198, 198, 14689, 7, 2100, 828, 543, 20070...
3.285714
287
""" Link extractor based on lxml.html """ import lxml.html from scrapy.link import Link from scrapy.utils.python import unique as unique_list
[ 37811, 198, 11280, 7925, 273, 1912, 319, 300, 19875, 13, 6494, 198, 37811, 198, 198, 11748, 300, 19875, 13, 6494, 198, 198, 6738, 15881, 88, 13, 8726, 1330, 7502, 198, 6738, 15881, 88, 13, 26791, 13, 29412, 1330, 3748, 355, 3748, 62, ...
3.244444
45
from django.contrib import admin from .models import Meeting admin.site.register(Meeting)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 201, 198, 201, 198, 6738, 764, 27530, 1330, 22244, 201, 198, 201, 198, 28482, 13, 15654, 13, 30238, 7, 5308, 13629, 8, 201, 198 ]
3.03125
32
from flask import Flask, url_for import os app = Flask(__name__) app.config['DEBUG'] = True app.config['SECRET_KEY'] = 'SECRET_KEY_CH1ng3me' # Determines the destination of the build. Only usefull if you're using Frozen-Flask app.config['FREEZER_DESTINATION'] = os.path.dirname(os.path.abspath(__file__))+'/../build' # Function to easily find your assets # In your template use <link rel=stylesheet href="{{ static('filename') }}"> <%= appName %>.jinja_env.globals['static'] = ( lambda filename: url_for('static', filename = filename) ) from <%= appName %> import views
[ 6738, 42903, 1330, 46947, 11, 19016, 62, 1640, 198, 11748, 28686, 198, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 198, 1324, 13, 11250, 17816, 30531, 20520, 796, 6407, 198, 1324, 13, 11250, 17816, 23683, 26087, 62, 20373, 20520, 796, ...
2.919192
198
import numpy as np import argparse from sklearn.svm import LinearSVR from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler from sklearn.datasets import make_regression parser = argparse.ArgumentParser() parser.add_argument('-x', '--datapath', type=str, required=True) parser.add_argument('-y', '--labels', type=str, required=True) parser.add_argument('-v', '--verbose', type=bool, default=False) parser.add_argument('-o', '--outputpath', type=str, required=True) args = parser.parse_args() X = np.load(args.datapath, allow_pickle=True) y = np.load(args.labels, allow_pickle=True) # http://scikit-learn.sourceforge.net/stable/modules/generated/sklearn.svm.LinearSVC.html#sklearn.svm.LinearSVC regr = make_pipeline(StandardScaler(), LinearSVR(verbose=args.verbose, tol = 1e-5, max_iter = 30)) regr.fit(X,y) np.savetxt(args.outputpath, regr.named_steps['linearsvr'].coef_, delimiter=",")
[ 198, 11748, 299, 32152, 355, 45941, 198, 11748, 1822, 29572, 198, 6738, 1341, 35720, 13, 82, 14761, 1330, 44800, 50, 13024, 198, 6738, 1341, 35720, 13, 79, 541, 4470, 1330, 787, 62, 79, 541, 4470, 198, 6738, 1341, 35720, 13, 3866, 369...
2.697406
347
#!/usr/bin/env python # MIT License # # Copyright (c) 2020 Rik Baehnemann, ASL, ETH Zurich, Switzerland # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import rospy import rospkg import pandas as pd import pymap3d as pm import os import numpy as np from matplotlib import cm from matplotlib import colors from sensor_msgs.msg import NavSatFix from visualization_msgs.msg import Marker, MarkerArray # Load target list from CSV, receive home point from ROS msgs and publish target points to RVIZ.
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 2, 17168, 13789, 198, 2, 198, 2, 15069, 357, 66, 8, 12131, 50067, 347, 3609, 21116, 368, 1236, 11, 7054, 43, 11, 35920, 43412, 11, 14679, 198, 2, 198, 2, 2448, 3411, 318, 2937...
3.660194
412
"""Google Cloud Hierarchical Firewall Generator. Hierarchical Firewalls (HF) are represented in a SecurityPolicy GCP resouce. """ import copy import re from typing import Dict, Any from absl import logging from capirca.lib import gcp from capirca.lib import nacaddr def GetRuleTupleCount(dict_term: Dict[str, Any], api_version): """Calculate the tuple count of a rule in its dictionary form. Quota is charged based on how complex the rules are rather than simply limiting the number of rules. The cost of a rule is the number of distinct protocol:port combinations plus the number of IP addresses plus the number of targets. Note: The goal of this function is not to determine if a rule is valid, but to calculate its tuple count regardless of correctness. Args: dict_term: A dict object. api_version: A string indicating the api version. Returns: int: The tuple count of the rule. """ layer4_count = 0 layer_4_config = ApiVersionSyntaxMap.SYNTAX_MAP[api_version]['layer_4_config'] dest_ip_range = ApiVersionSyntaxMap.SYNTAX_MAP[api_version]['dest_ip_range'] src_ip_range = ApiVersionSyntaxMap.SYNTAX_MAP[api_version]['src_ip_range'] targets_count = len(dict_term.get('targetResources', [])) if api_version == 'ga': config = dict_term.get('match', {}) else: config = dict_term.get('match', {}).get('config', {}) addresses_count = len( config.get(dest_ip_range, []) + config.get(src_ip_range, [])) for l4config in config.get(layer_4_config, []): for _ in l4config.get('ports', []): layer4_count += 1 if l4config.get('ipProtocol'): layer4_count += +1 return addresses_count + layer4_count + targets_count
[ 37811, 11708, 10130, 36496, 998, 605, 3764, 11930, 35986, 13, 198, 198, 39, 959, 998, 605, 3764, 86, 5691, 357, 29567, 8, 389, 7997, 287, 257, 4765, 36727, 402, 8697, 581, 280, 344, 13, 198, 37811, 198, 198, 11748, 4866, 198, 11748, ...
2.977391
575
"""Kits class defines the available Toolboxes.""" from enum import Enum
[ 37811, 42, 896, 1398, 15738, 262, 1695, 16984, 29305, 526, 15931, 198, 6738, 33829, 1330, 2039, 388, 628 ]
4.055556
18
#!/bin/python3 # https://www.hackerrank.com/challenges/time-conversion import sys s = input().strip() result = timeConversion(s) print(result)
[ 2, 48443, 8800, 14, 29412, 18, 201, 198, 201, 198, 2, 3740, 1378, 2503, 13, 31153, 8056, 962, 13, 785, 14, 36747, 34120, 14, 2435, 12, 1102, 9641, 201, 198, 11748, 25064, 201, 198, 220, 220, 220, 220, 220, 201, 198, 82, 796, 5128,...
2.47619
63
from decimal import Decimal, getcontext, ROUND_HALF_UP from supplychainpy.demand import analyse_uncertain_demand from supplychainpy.demand.eoq import minimum_variable_cost, economic_order_quantity
[ 6738, 32465, 1330, 4280, 4402, 11, 651, 22866, 11, 371, 15919, 62, 39, 1847, 37, 62, 8577, 198, 6738, 5127, 7983, 9078, 13, 28550, 1330, 39552, 62, 19524, 1425, 62, 28550, 198, 6738, 5127, 7983, 9078, 13, 28550, 13, 68, 78, 80, 1330...
3.535714
56
from __future__ import division import mmcv import numpy as np import pytest
[ 6738, 11593, 37443, 834, 1330, 7297, 198, 198, 11748, 8085, 33967, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 9288, 628, 628 ]
3.521739
23
#!/usr/bin/env python """ Author: Joo Ribeiro """ import argparse import numpy as np from model import FeedForwardNetwork from utils import load_ocr_dataset, plot if __name__ == '__main__': parser = argparse.ArgumentParser() # Hyperparams parser.add_argument('-epochs', default=20, type=int, help="Number of training epochs.") parser.add_argument('-num_layers', default=2, type=int, help="Number of hidden layers.") parser.add_argument('-hidden_size', default=64, type=int, help="Number of units per hidden layer.") parser.add_argument('-activation', default="relu", type=str, help="Activation function for the hidden layers.") parser.add_argument('-learning_rate', default=0.1, type=float, help="Learning rate for SGD optimizer.") parser.add_argument('-l2_penalty', default=0.0, type=float, help="L2 penalty for SGD optimizer.") parser.add_argument('-batch_size', default=32, type=int, help="Number of datapoints per SGD step.") # Misc. parser.add_argument('-data', default='ocr_dataset/letter.data', help="Path to letter.data OCR dataset.") parser.add_argument('-save_plot', action="store_true", help="Whether or not to save the generated accuracies plot.") opt = parser.parse_args() # ############ # # Load Dataset # # ############ # print("Loading OCR Dataset", end="", flush=True) data = load_ocr_dataset(opt.data) X_train, y_train = data["train"] X_val, y_val = data["dev"] X_test, y_test = data["test"] num_features = X_train.shape[1] num_classes = np.unique(y_train).size print(" [Done]", flush=True) # ########### # # Setup Model # # ########### # print("Deploying model", end="", flush=True) model = FeedForwardNetwork( num_features, num_classes, opt.num_layers, opt.hidden_size, opt.activation, opt.learning_rate, opt.l2_penalty, opt.batch_size ) print(" [Done]", flush=True) # ################ # # Train & Evaluate # # ################ # print("Training model", flush=True) validation_accuracies, final_test_accuracy = model.fit(X_train, y_train, X_val, y_val, X_test, y_test, opt.epochs) # #### # # Plot # # #### # print("Plotting", end="", flush=True) plot(opt.epochs, validation_accuracies, opt.save_plot) print(" [Done]\nGoodbye.", flush=True)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 37811, 198, 13838, 25, 449, 2238, 23133, 68, 7058, 198, 37811, 198, 198, 11748, 1822, 29572, 198, 198, 11748, 299, 32152, 355, 45941, 198, 198, 6738, 2746, 1330, 18272, 39746, 26245...
2.671171
888
from guardian.shortcuts import get_objects_for_user from django.http import Http404, HttpResponseRedirect from django.db.models import Count from django.core.urlresolvers import reverse from django.shortcuts import render, get_object_or_404 from vdw.samples.models import Sample, Project, Batch, Cohort from .forms import CohortForm
[ 6738, 21688, 13, 19509, 23779, 1330, 651, 62, 48205, 62, 1640, 62, 7220, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 26429, 11, 367, 29281, 31077, 7738, 1060, 198, 6738, 42625, 14208, 13, 9945, 13, 27530, 1330, 2764, 198, 6738,...
3.356436
101
import sys from pprint import pprint import os #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# #--------------------------------------------------------------------------#
[ 11748, 25064, 198, 6738, 279, 4798, 1330, 279, 4798, 198, 11748, 28686, 198, 2, 10097, 35937, 2, 198, 220, 220, 220, 220, 198, 2, 10097, 35937, 2, 198, 2, 10097, 35937, 2 ]
8.8125
32
#!/usr/bin/env python3 # coding: utf-8 # Adapted from: https://github.com/zpincus/celltool/blob/master/celltool/numerics/image_warp.py from scipy import ndimage import numpy as np from probreg import bcpd import tifffile import matplotlib.pyplot as plt import napari from magicgui import magic_factory, widgets from napari.types import PointsData, ImageData from typing_extensions import Annotated
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 19617, 25, 3384, 69, 12, 23, 198, 2, 30019, 276, 422, 25, 3740, 1378, 12567, 13, 785, 14, 89, 79, 1939, 385, 14, 3846, 25981, 14, 2436, 672, 14, 9866, 14, 3846, 25981, 14,...
2.977612
134
from django.test import TestCase, RequestFactory import vcr from django.conf import settings from django.core.management import call_command from open_humans.models import OpenHumansMember from main.celery import read_reference, clean_raw_23andme from main.celery_helper import vcf_header import os import tempfile import requests import requests_mock from main.celery import process_file
[ 6738, 42625, 14208, 13, 9288, 1330, 6208, 20448, 11, 19390, 22810, 198, 11748, 410, 6098, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 7295, 13, 27604, 1330, 869, 62, 21812, 198, 6738, 1280, 62, 40205, 13...
3.679245
106
from django.contrib import admin from .models import LogCategory, BudgetLog # Register your models here. admin.site.register(LogCategory) admin.site.register(BudgetLog)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 6738, 764, 27530, 1330, 5972, 27313, 11, 15401, 11187, 198, 2, 17296, 534, 4981, 994, 13, 198, 28482, 13, 15654, 13, 30238, 7, 11187, 27313, 8, 198, 28482, 13, 15654, 13, 30238, 7, ...
3.652174
46
# -*- coding: UTF-8 -*- #!/usr/bin/python3 """ Embedding Layer """ #************************************************************ # Imported Libraries #************************************************************ import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from gensim.models import KeyedVectors import pdb
[ 2, 532, 9, 12, 19617, 25, 41002, 12, 23, 532, 9, 12, 198, 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 37811, 198, 31567, 6048, 278, 34398, 198, 37811, 198, 198, 2, 17174, 8412, 46068, 198, 2, 1846, 9213, 46267, 198, 2, 17174, ...
3.826087
92
import abc import socket import logging import asyncio import warnings import h2.config import h2.exceptions from .utils import DeadlineWrapper from .const import Status from .stream import send_message, recv_message from .stream import StreamIterator from .metadata import Metadata, Deadline from .protocol import H2Protocol, AbstractHandler from .exceptions import GRPCError, ProtocolError from .encoding.base import GRPC_CONTENT_TYPE from .encoding.proto import ProtoCodec log = logging.getLogger(__name__) class Handler(_GC, AbstractHandler): __gc_interval__ = 10 closing = False class Server(_GC, asyncio.AbstractServer): """ HTTP/2 server, which uses gRPC service handlers to handle requests. Handler is a subclass of the abstract base class, which was generated from .proto file: .. code-block:: python class CoffeeMachine(cafe_grpc.CoffeeMachineBase): async def MakeLatte(self, stream): task: cafe_pb2.LatteOrder = await stream.recv_message() ... await stream.send_message(empty_pb2.Empty()) server = Server([CoffeeMachine()], loop=loop) """ __gc_interval__ = 10 def __init__(self, handlers, *, loop, codec=None): """ :param handlers: list of handlers :param loop: asyncio-compatible event loop """ mapping = {} for handler in handlers: mapping.update(handler.__mapping__()) self._mapping = mapping self._loop = loop self._codec = codec or ProtoCodec() self._config = h2.config.H2Configuration( client_side=False, header_encoding='utf-8', ) self._tcp_server = None self._handlers = set() def close(self): """Stops accepting new connections, cancels all currently running requests. Request handlers are able to handle `CancelledError` and exit properly. """ if self._tcp_server is None: raise RuntimeError('Server is not started') self._tcp_server.close() for handler in self._handlers: handler.close()
[ 11748, 450, 66, 198, 11748, 17802, 198, 11748, 18931, 198, 11748, 30351, 952, 198, 11748, 14601, 198, 198, 11748, 289, 17, 13, 11250, 198, 11748, 289, 17, 13, 1069, 11755, 198, 198, 6738, 764, 26791, 1330, 35954, 36918, 2848, 198, 6738,...
2.581451
841
#!/usr/bin/env python import argparse from eva import EvaProgram, Input, Output from eva.ckks import CKKSCompiler from eva.seal import generate_keys import numpy as np import time from eva.std.numeric import horizontal_sum def generate_vector_dot_naive(size): """Vector dot product with vector size of 1""" fhe_dot = EvaProgram("fhe_dot", vec_size=1) with fhe_dot: a = np.array([Input(f"x_{n}") for n in range(size)]).reshape(1, size) b = np.array([Input(f"w_{k}") for k in range(size)]).reshape(size, 1) out = dot(a, b) Output("y", out[0][0]) fhe_dot.set_input_scales(32) fhe_dot.set_output_ranges(32) return fhe_dot def generate_vector_dot(size): """Vector dot product with CKKS vector size equal to the size""" fhe_dot = EvaProgram("fhe_dot", vec_size=size) with fhe_dot: a = np.array([Input("x")]) b = np.array([Input(f"w")]) out = dot(a, b) Output("y", horizontal_sum(out)) fhe_dot.set_input_scales(32) fhe_dot.set_output_ranges(32) return fhe_dot if __name__ == "__main__": parser = argparse.ArgumentParser(description="Run a dot product program") parser.add_argument( "--mode", default="SIMD", choices=["SIMD", "naive"], ) args = parser.parse_args() results_cipher = dict() results_plain = dict() if args.mode == "SIMD": print("Generating code in SIMD style") else: print("Generating code in naive style") for size in [4, 8, 16, 32, 64, 128, 256, 512, 1024]: time_cipher, time_plain = benchmark_vector_dot(size, args.mode) results_cipher[f"{size}"] = time_cipher results_plain[f"{size}"] = time_plain print(f"Done vector size {size}, CKKS time: {time_cipher}") print("Done") print("CKKS times:", results_cipher) print("Plain text times:", results_plain)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 11748, 1822, 29572, 198, 6738, 819, 64, 1330, 32355, 15167, 11, 23412, 11, 25235, 198, 6738, 819, 64, 13, 694, 591, 1330, 327, 16601, 6173, 3361, 5329, 198, 6738, 819, 64, 13, 325, 2...
2.327649
821
from __future__ import division from __future__ import print_function # -*- coding: utf-8 -*- # Copyright 2020 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License") # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ This module manages a distributed RAM cache as a global python dictionary in each AppEngine instance. AppEngine can spin up new instances or kill old ones at any time. Each instance's RAM cache is independent and might not have the same entries as found in the RAM caches of other instances. Each instance will do the work needed to compute a given RAM cache entry itself. The values computed in a given instance will speed up future requests made to that instance only. When the user edits something in the app, the updated entity is stored in datastore. Also, the singleton SharedInvalidate entity is updated with the timestamp of the change. Every request handler must start processing a request by first calling SharedInvalidate.check_for_distributed_invalidation() which checks for any needed invalidations and clears RAM cache entries in that instance if needed. For now, there is only a single RAM cache per instance and when anything is invalidated, that entire RAM cache is completely cleared. In the future, invalidations could be compartmentalized by RAM cache type, or even specific entity IDs. Monorail uses that approach, but existing ChromeStatus code does not need it. Calling code must not mutate any value that is passed into set() or returned from get(). If calling code needs to mutate such objects, it should call copy.copy() or copy.deepcopy() to avoid unintentional cumulative mutations. Unlike memcache, this RAM cache has no concept of expiration time. So, whenever a cached value would become invalid, it must be invalidated. """ import logging import time as time_module from google.appengine.ext import db global_cache = {} expires = {} # Whenever the cache would have more than this many items, some # random item is dropped, or the entire cache is cleared. # If our instances are killed by appengine for exceeding memory limits, # we can configure larger instances and/or reduce this value. MAX_CACHE_SIZE = 10000 def set(key, value, time=None): """Emulate the memcache.set() method using a RAM cache.""" if len(global_cache) + 1 > MAX_CACHE_SIZE: popped_item = global_cache.popitem() if popped_item[0] in expires: del expires[popped_item[0]] global_cache[key] = value if time: expires[key] = int(time_module.time()) + time def get(key): """Emulate the memcache.get() method using a RAM cache.""" _check_expired([key]) verb = 'hit' if key in global_cache else 'miss' logging.info('cache %s for %r', verb, key) return global_cache.get(key) def get_multi(keys): """Emulate the memcache.get_multi() method using a RAM cache.""" _check_expired(keys) return { key: global_cache[key] for key in keys if key in global_cache } def set_multi(entries): """Emulate the memcache.set_multi() method using a RAM cache.""" if len(global_cache) + len(entries) > MAX_CACHE_SIZE: global_cache.clear() expires.clear() global_cache.update(entries) def delete(key): """Emulate the memcache.delete() method using a RAM cache.""" if key in global_cache: del global_cache[key] flush_all() # Note: this is wasteful but infrequent in our app. def flush_all(): """Emulate the memcache.flush_all() method using a RAM cache. This does not clear the RAM cache in this instance. That happens at the start of the next request when the request handler calls SharedInvalidate.check_for_distributed_invalidation(). """ SharedInvalidate.invalidate() def check_for_distributed_invalidation(): """Just a shorthand way to call the class method.""" SharedInvalidate.check_for_distributed_invalidation()
[ 6738, 11593, 37443, 834, 1330, 7297, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 15069, 12131, 3012, 3457, 13, 198, 2, 198, 2, 49962, 739, 262, 24...
3.516287
1,228
# Generated by Django 2.2 on 2019-10-25 10:58 from django.db import migrations, models
[ 2, 2980, 515, 416, 37770, 362, 13, 17, 319, 13130, 12, 940, 12, 1495, 838, 25, 3365, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 628 ]
2.966667
30
""" UI for controlling how api classes and mel commands are combined into pymel classes. This UI modifies factories.apiToMelData which is pickled out to apiMelBridge. It controls: which mel methods correspond to api methods disabling of api methods preference for overloaded methods (since currently only one overloaded method is supported) renaming of apiMethod """ import inspect, re, os import pymel.core as pm import pymel.internal.factories as factories import logging logger = logging.getLogger(__name__) if logger.level == logging.NOTSET: logger.setLevel(logging.INFO) FRAME_WIDTH = 800 VERBOSE = True def _getClass(className): for module in [pm.nodetypes, pm.datatypes, pm.general]: try: pymelClass = getattr(module, className) return pymelClass except AttributeError: pass def fixSpace(): "fix the Space enumerator" enum = pm.util.getCascadingDictItem( factories.apiClassInfo, ('MSpace', 'pymelEnums', 'Space') ) keys = enum._keys.copy() #print keys val = keys.pop('postTransform', None) if val is not None: keys['object'] = val newEnum = pm.util.Enum( 'Space', keys ) pm.util.setCascadingDictItem( factories.apiClassOverrides, ('MSpace', 'pymelEnums', 'Space'), newEnum ) else: logger.warning( "could not fix Space") # def doCacheResults(): # print "---" # print "adding manual defaults" # setManualDefaults() # print "merging dictionaries" # # update apiClasIfno with the sparse data stored in apiClassOverrides # factories.mergeApiClassOverrides() # print "saving api cache" # factories.saveApiCache() # print "saving bridge" # factories.saveApiMelBridgeCache() # print "---"
[ 37811, 198, 10080, 329, 12755, 703, 40391, 6097, 290, 7758, 9729, 389, 5929, 656, 279, 4948, 417, 6097, 13, 198, 198, 1212, 12454, 953, 6945, 17590, 13, 15042, 2514, 21102, 6601, 543, 318, 2298, 992, 503, 284, 40391, 21102, 37385, 13, ...
2.691843
662
x:[int] = None x = [] print(x[0])
[ 87, 33250, 600, 60, 796, 6045, 198, 198, 87, 796, 17635, 198, 4798, 7, 87, 58, 15, 12962, 198 ]
1.842105
19
from .model import VQVCModel from .pl_model import VQVCModule
[ 6738, 764, 19849, 1330, 569, 48, 15922, 17633, 198, 6738, 764, 489, 62, 19849, 1330, 569, 48, 15922, 26796, 198 ]
3.1
20
from typing import Union, TypeVar from enum import Enum import torch pi = torch.tensor(3.14159265358979323846) T = TypeVar('T', bound='Resample') U = TypeVar('U', bound='BorderType')
[ 6738, 19720, 1330, 4479, 11, 5994, 19852, 198, 6738, 33829, 1330, 2039, 388, 198, 198, 11748, 28034, 198, 198, 14415, 796, 28034, 13, 83, 22854, 7, 18, 13, 1415, 19707, 22980, 2327, 4531, 44750, 23721, 3510, 8, 198, 51, 796, 5994, 198...
2.876923
65
import intrepyd from intrepyd.iec611312py.plcopen import parse_plc_open_file from intrepyd.iec611312py.stmtprinter import StmtPrinter import unittest from . import from_fixture_path if __name__ == "__main__": unittest.main()
[ 11748, 493, 7856, 5173, 198, 6738, 493, 7856, 5173, 13, 494, 66, 21, 16616, 1065, 9078, 13, 489, 66, 9654, 1330, 21136, 62, 489, 66, 62, 9654, 62, 7753, 198, 6738, 493, 7856, 5173, 13, 494, 66, 21, 16616, 1065, 9078, 13, 301, 1676...
2.58427
89
__author__ = 'Georgios Rizos (georgerizos@iti.gr)' import numpy as np import scipy.sparse as sparse from reveal_graph_embedding.common import get_file_row_generator def read_adjacency_matrix(file_path, separator): """ Reads an edge list in csv format and returns the adjacency matrix in SciPy Sparse COOrdinate format. Inputs: - file_path: The path where the adjacency matrix is stored. - separator: The delimiter among values (e.g. ",", "\t", " ") Outputs: - adjacency_matrix: The adjacency matrix in SciPy Sparse COOrdinate format. """ # Open file file_row_generator = get_file_row_generator(file_path, separator) # Initialize lists for row and column sparse matrix arguments row = list() col = list() append_row = row.append append_col = col.append # Read all file rows for file_row in file_row_generator: source_node = np.int64(file_row[0]) target_node = np.int64(file_row[1]) # Add edge append_row(source_node) append_col(target_node) # Since this is an undirected network also add the reciprocal edge append_row(target_node) append_col(source_node) row = np.array(row, dtype=np.int64) col = np.array(col, dtype=np.int64) data = np.ones_like(row, dtype=np.float64) number_of_nodes = np.max(row) # I assume that there are no missing nodes at the end. # Array count should start from 0. row -= 1 col -= 1 # Form sparse adjacency matrix adjacency_matrix = sparse.coo_matrix((data, (row, col)), shape=(number_of_nodes, number_of_nodes)) return adjacency_matrix def read_node_label_matrix(file_path, separator, number_of_nodes): """ Reads node-label pairs in csv format and returns a list of tuples and a node-label matrix. Inputs: - file_path: The path where the node-label matrix is stored. - separator: The delimiter among values (e.g. ",", "\t", " ") - number_of_nodes: The number of nodes of the full graph. It is possible that not all nodes are labelled. Outputs: - node_label_matrix: The node-label associations in a NumPy array of tuples format. - number_of_categories: The number of categories/classes the nodes may belong to. - labelled_node_indices: A NumPy array containing the labelled node indices. """ # Open file file_row_generator = get_file_row_generator(file_path, separator) # Initialize lists for row and column sparse matrix arguments row = list() col = list() append_row = row.append append_col = col.append # Populate the arrays for file_row in file_row_generator: node = np.int64(file_row[0]) label = np.int64(file_row[1]) # Add label append_row(node) append_col(label) number_of_categories = len(set(col)) # I assume that there are no missing labels. There may be missing nodes. labelled_node_indices = np.array(list(set(row))) row = np.array(row, dtype=np.int64) col = np.array(col, dtype=np.int64) data = np.ones_like(row, dtype=np.float64) # Array count should start from 0. row -= 1 col -= 1 labelled_node_indices -= 1 # Form sparse adjacency matrix node_label_matrix = sparse.coo_matrix((data, (row, col)), shape=(number_of_nodes, number_of_categories)) node_label_matrix = node_label_matrix.tocsr() return node_label_matrix, number_of_categories, labelled_node_indices
[ 834, 9800, 834, 796, 705, 33428, 4267, 371, 528, 418, 357, 469, 273, 1362, 528, 418, 31, 8846, 13, 2164, 33047, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 629, 541, 88, 13, 82, 29572, 355, 29877, 198, 198, 6738, 7766, 62, ...
2.591279
1,353
# create_tweet_classes.py # this assumes the existence of a get_class(day, hour, ticker) function # that returns the class (0, 1, or -1) for a given hour and ticker import collections import json import random refined_tweets = collections.defaultdict(list) #returns label for company and time #parses individual json file if __name__=='__main__': main()
[ 2, 2251, 62, 83, 7277, 62, 37724, 13, 9078, 198, 2, 428, 18533, 262, 6224, 286, 257, 651, 62, 4871, 7, 820, 11, 1711, 11, 4378, 263, 8, 2163, 198, 2, 326, 5860, 262, 1398, 357, 15, 11, 352, 11, 393, 532, 16, 8, 329, 257, 181...
3.185841
113
from unittest import TestCase import json from helpers import * from pytezos import ContractInterface, pytezos, MichelsonRuntimeError from pytezos.context.mixin import ExecutionContext token_a = "KT1AxaBxkFLCUi3f8rdDAAxBKHfzY8LfKDRA" token_b = "KT1PgHxzUXruWG5XAahQzJAjkk4c2sPcM3Ca" token_c = "KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton" token_d = "KT1Wz32jY2WEwWq8ZaA2C6cYFHGchFYVVczC" pair_ab = { "token_a_type" : { "fa2": { "token_address": token_a, "token_id": 0 } }, "token_b_type": { "fa2": { "token_address": token_b, "token_id": 1 } }, } pair_bc = { "token_a_type": { "fa2": { "token_address": token_b, "token_id": 1 } }, "token_b_type" : { "fa2": { "token_address": token_c, "token_id": 2 } } } pair_ac = { "token_a_type" : { "fa2": { "token_address": token_a, "token_id": 0 } }, "token_b_type" : { "fa2": { "token_address": token_c, "token_id": 2 } } } pair_cd = { "token_a_type" : { "fa2": { "token_address": token_c, "token_id": 2 } }, "token_b_type" : { "fa2": { "token_address": token_d, "token_id": 3 } } }
[ 6738, 555, 715, 395, 1330, 6208, 20448, 198, 198, 11748, 33918, 198, 6738, 49385, 1330, 1635, 198, 198, 6738, 12972, 660, 37925, 1330, 17453, 39317, 11, 12972, 660, 37925, 11, 12386, 1559, 41006, 12331, 198, 6738, 12972, 660, 37925, 13, ...
1.646784
855
import datetime from datetime import timedelta import pprint from config import * from helper import * import time import logging from logging.handlers import RotatingFileHandler logger = logging.getLogger('Twitch Relay Monitor') logger.setLevel(logging.DEBUG) handler = RotatingFileHandler('/home/pi/twitch_relay_monitor/logs/app.log', maxBytes=200000, backupCount=2) handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) #First, start by getting token to access Twitch api r=get_token(client_id,client_secret,grant_type,scope) if r == False: # if there is a problem, end the program logger.error("Can't Auth user") exit(1) # since streamer username is given we need to get its broadcaster id for other requests broadcaster=get_broadcaster_id(client_id,username) if broadcaster==False: # if there is a problem, end the program logger.error("Can not get broadcster id") exit(1) if "access_token" not in r: # if there is a problem, end the program logger.error("Access token is missing " + str(r)) exit(1) access_token=r['access_token']; expires_in=r['expires_in'] # Fresh token interval will keep track of the time we need to validate the token fresh_token_interval=token_validate_interval skip_count=0 while True: wait_time=online_user_wait_time # refresh token if expired if fresh_token_interval <30: #confirm the token is valid if is_valid_token(access_token) ==False: r=get_token(client_id,client_secret,grant_type,scope) if r ==False: skip_count=skip_count+1 logger.info("Fresh Token Skip get token , skip:" + str(skip_count)) time.sleep(skip_wait_time) continue access_token=r['access_token']; expires_in=r['expires_in'] fresh_token_interval=token_validate_interval if is_user_live(client_id,access_token,username): print_verbose("User ["+username+"] online") set_stream(1) user_streaming_flag=1 else: print_verbose("User ["+username+"] offline") set_hypetrain(0) set_follow(0) set_stream(0) user_streaming_flag=0 wait_time=user_offline_wait_time last_hype_train_action=get_last_hype_train_action(client_id,access_token,broadcaster["_id"]) if last_hype_train_action ==False: skip_count=skip_count+1 logger.info("Hype Train Skip get token , skip:" + str(skip_count)) time.sleep(skip_wait_time) continue #retrieve most recent follow event last_follow_action=get_last_follow_action(client_id,access_token,broadcaster["_id"]) if last_follow_action ==False: skip_count=skip_count+1 logger.info("Follow Skip get token , skip:" + str(skip_count)) time.sleep(skip_wait_time) continue #mark follow if last follow event is < event notification time from current time if user_streaming_flag==1: subscribe_time=last_follow_action["data"][0]["followed_at"] subscribe_time=datetime.datetime.strptime(subscribe_time,'%Y-%m-%dT%H:%M:%SZ') if datetime.datetime.utcnow() < subscribe_time + timedelta(seconds=event_notification_delay): print_verbose("Relay Function - Follow Event Active") set_follow(1) else: set_follow(0) #set hype train state if(is_train_active(last_hype_train_action["data"])): print_verbose("Train Active at level " + str(last_hype_train_action["data"][0]["event_data"]['level'])) level=last_hype_train_action["data"][0]["event_data"]['level'] if 1 <= level <= 5: if user_streaming_flag==1: logger.info("Relay Function - Hype Train Event") set_hypetrain(level) wait_time=5 # active hype train wait time in seconds else: print_verbose("Train not active") set_hypetrain(0) wait_time=online_user_wait_time fresh_token_interval=fresh_token_interval-wait_time if skip_count == max_skip_count: logger.error("Skip count limit reached") exit(1) time.sleep(wait_time) #reset skip_count if one request execute without issue within max_skip_count skip_count=0
[ 11748, 4818, 8079, 198, 6738, 4818, 8079, 1330, 28805, 12514, 198, 11748, 279, 4798, 198, 6738, 4566, 1330, 1635, 198, 6738, 31904, 1330, 1635, 198, 11748, 640, 198, 11748, 18931, 198, 6738, 18931, 13, 4993, 8116, 1330, 18481, 803, 8979, ...
2.710014
1,438
import os from collections import defaultdict from rbc.omnisci_backend import Array from rbc.errors import OmnisciServerError from numba import types as nb_types import pytest rbc_omnisci = pytest.importorskip('rbc.omniscidb') available_version, reason = rbc_omnisci.is_available() pytestmark = pytest.mark.skipif(not available_version, reason=reason) def test_len_i32(omnisci): omnisci.reset() desrc, result = omnisci.sql_execute( f'select i4, array_sz_int32(i4) from {omnisci.table_name}') for a, sz in result: assert len(a) == sz inps = [('int32', 'i4', 'trunc'), ('int32', 'i4', 'sext'), ('int32', 'i4', 'zext'), ('float', 'f4', 'fptrunc'), ('double', 'f8', 'fpext')]
[ 11748, 28686, 198, 6738, 17268, 1330, 4277, 11600, 198, 6738, 374, 15630, 13, 296, 21361, 979, 62, 1891, 437, 1330, 15690, 198, 6738, 374, 15630, 13, 48277, 1330, 31816, 271, 979, 10697, 12331, 198, 6738, 997, 7012, 1330, 3858, 355, 299...
2.359873
314
data = ( 'Lun ', # 0x00 'Kua ', # 0x01 'Ling ', # 0x02 'Bei ', # 0x03 'Lu ', # 0x04 'Li ', # 0x05 'Qiang ', # 0x06 'Pou ', # 0x07 'Juan ', # 0x08 'Min ', # 0x09 'Zui ', # 0x0a 'Peng ', # 0x0b 'An ', # 0x0c 'Pi ', # 0x0d 'Xian ', # 0x0e 'Ya ', # 0x0f 'Zhui ', # 0x10 'Lei ', # 0x11 'A ', # 0x12 'Kong ', # 0x13 'Ta ', # 0x14 'Kun ', # 0x15 'Du ', # 0x16 'Wei ', # 0x17 'Chui ', # 0x18 'Zi ', # 0x19 'Zheng ', # 0x1a 'Ben ', # 0x1b 'Nie ', # 0x1c 'Cong ', # 0x1d 'Qun ', # 0x1e 'Tan ', # 0x1f 'Ding ', # 0x20 'Qi ', # 0x21 'Qian ', # 0x22 'Zhuo ', # 0x23 'Qi ', # 0x24 'Yu ', # 0x25 'Jin ', # 0x26 'Guan ', # 0x27 'Mao ', # 0x28 'Chang ', # 0x29 'Tian ', # 0x2a 'Xi ', # 0x2b 'Lian ', # 0x2c 'Tao ', # 0x2d 'Gu ', # 0x2e 'Cuo ', # 0x2f 'Shu ', # 0x30 'Zhen ', # 0x31 'Lu ', # 0x32 'Meng ', # 0x33 'Lu ', # 0x34 'Hua ', # 0x35 'Biao ', # 0x36 'Ga ', # 0x37 'Lai ', # 0x38 'Ken ', # 0x39 'Kazari ', # 0x3a 'Bu ', # 0x3b 'Nai ', # 0x3c 'Wan ', # 0x3d 'Zan ', # 0x3e '[?] ', # 0x3f 'De ', # 0x40 'Xian ', # 0x41 '[?] ', # 0x42 'Huo ', # 0x43 'Liang ', # 0x44 '[?] ', # 0x45 'Men ', # 0x46 'Kai ', # 0x47 'Ying ', # 0x48 'Di ', # 0x49 'Lian ', # 0x4a 'Guo ', # 0x4b 'Xian ', # 0x4c 'Du ', # 0x4d 'Tu ', # 0x4e 'Wei ', # 0x4f 'Cong ', # 0x50 'Fu ', # 0x51 'Rou ', # 0x52 'Ji ', # 0x53 'E ', # 0x54 'Rou ', # 0x55 'Chen ', # 0x56 'Ti ', # 0x57 'Zha ', # 0x58 'Hong ', # 0x59 'Yang ', # 0x5a 'Duan ', # 0x5b 'Xia ', # 0x5c 'Yu ', # 0x5d 'Keng ', # 0x5e 'Xing ', # 0x5f 'Huang ', # 0x60 'Wei ', # 0x61 'Fu ', # 0x62 'Zhao ', # 0x63 'Cha ', # 0x64 'Qie ', # 0x65 'She ', # 0x66 'Hong ', # 0x67 'Kui ', # 0x68 'Tian ', # 0x69 'Mou ', # 0x6a 'Qiao ', # 0x6b 'Qiao ', # 0x6c 'Hou ', # 0x6d 'Tou ', # 0x6e 'Cong ', # 0x6f 'Huan ', # 0x70 'Ye ', # 0x71 'Min ', # 0x72 'Jian ', # 0x73 'Duan ', # 0x74 'Jian ', # 0x75 'Song ', # 0x76 'Kui ', # 0x77 'Hu ', # 0x78 'Xuan ', # 0x79 'Duo ', # 0x7a 'Jie ', # 0x7b 'Zhen ', # 0x7c 'Bian ', # 0x7d 'Zhong ', # 0x7e 'Zi ', # 0x7f 'Xiu ', # 0x80 'Ye ', # 0x81 'Mei ', # 0x82 'Pai ', # 0x83 'Ai ', # 0x84 'Jie ', # 0x85 '[?] ', # 0x86 'Mei ', # 0x87 'Chuo ', # 0x88 'Ta ', # 0x89 'Bang ', # 0x8a 'Xia ', # 0x8b 'Lian ', # 0x8c 'Suo ', # 0x8d 'Xi ', # 0x8e 'Liu ', # 0x8f 'Zu ', # 0x90 'Ye ', # 0x91 'Nou ', # 0x92 'Weng ', # 0x93 'Rong ', # 0x94 'Tang ', # 0x95 'Suo ', # 0x96 'Qiang ', # 0x97 'Ge ', # 0x98 'Shuo ', # 0x99 'Chui ', # 0x9a 'Bo ', # 0x9b 'Pan ', # 0x9c 'Sa ', # 0x9d 'Bi ', # 0x9e 'Sang ', # 0x9f 'Gang ', # 0xa0 'Zi ', # 0xa1 'Wu ', # 0xa2 'Ying ', # 0xa3 'Huang ', # 0xa4 'Tiao ', # 0xa5 'Liu ', # 0xa6 'Kai ', # 0xa7 'Sun ', # 0xa8 'Sha ', # 0xa9 'Sou ', # 0xaa 'Wan ', # 0xab 'Hao ', # 0xac 'Zhen ', # 0xad 'Zhen ', # 0xae 'Luo ', # 0xaf 'Yi ', # 0xb0 'Yuan ', # 0xb1 'Tang ', # 0xb2 'Nie ', # 0xb3 'Xi ', # 0xb4 'Jia ', # 0xb5 'Ge ', # 0xb6 'Ma ', # 0xb7 'Juan ', # 0xb8 'Kasugai ', # 0xb9 'Habaki ', # 0xba 'Suo ', # 0xbb '[?] ', # 0xbc '[?] ', # 0xbd '[?] ', # 0xbe 'Na ', # 0xbf 'Lu ', # 0xc0 'Suo ', # 0xc1 'Ou ', # 0xc2 'Zu ', # 0xc3 'Tuan ', # 0xc4 'Xiu ', # 0xc5 'Guan ', # 0xc6 'Xuan ', # 0xc7 'Lian ', # 0xc8 'Shou ', # 0xc9 'Ao ', # 0xca 'Man ', # 0xcb 'Mo ', # 0xcc 'Luo ', # 0xcd 'Bi ', # 0xce 'Wei ', # 0xcf 'Liu ', # 0xd0 'Di ', # 0xd1 'Qiao ', # 0xd2 'Cong ', # 0xd3 'Yi ', # 0xd4 'Lu ', # 0xd5 'Ao ', # 0xd6 'Keng ', # 0xd7 'Qiang ', # 0xd8 'Cui ', # 0xd9 'Qi ', # 0xda 'Chang ', # 0xdb 'Tang ', # 0xdc 'Man ', # 0xdd 'Yong ', # 0xde 'Chan ', # 0xdf 'Feng ', # 0xe0 'Jing ', # 0xe1 'Biao ', # 0xe2 'Shu ', # 0xe3 'Lou ', # 0xe4 'Xiu ', # 0xe5 'Cong ', # 0xe6 'Long ', # 0xe7 'Zan ', # 0xe8 'Jian ', # 0xe9 'Cao ', # 0xea 'Li ', # 0xeb 'Xia ', # 0xec 'Xi ', # 0xed 'Kang ', # 0xee '[?] ', # 0xef 'Beng ', # 0xf0 '[?] ', # 0xf1 '[?] ', # 0xf2 'Zheng ', # 0xf3 'Lu ', # 0xf4 'Hua ', # 0xf5 'Ji ', # 0xf6 'Pu ', # 0xf7 'Hui ', # 0xf8 'Qiang ', # 0xf9 'Po ', # 0xfa 'Lin ', # 0xfb 'Suo ', # 0xfc 'Xiu ', # 0xfd 'San ', # 0xfe 'Cheng ', # 0xff )
[ 7890, 796, 357, 198, 6, 43, 403, 46083, 220, 220, 220, 1303, 657, 87, 405, 198, 6, 42, 6413, 46083, 220, 220, 220, 1303, 657, 87, 486, 198, 6, 43, 278, 46083, 220, 220, 220, 1303, 657, 87, 2999, 198, 6, 3856, 72, 46083, 220, 2...
1.521356
3,067
from dataclasses import dataclass import re from tokenize import group from core.constructs.resource import ResourceModel from core.constructs.workspace import Workspace RUUID = "cdev::simple::bucket" remote_name_regex = "bucket://([a-z,_]+).([a-z,_]+)/?(\S+)?" compiled_regex = re.compile(remote_name_regex)
[ 6738, 4818, 330, 28958, 1330, 4818, 330, 31172, 198, 11748, 302, 198, 6738, 11241, 1096, 1330, 1448, 198, 198, 6738, 4755, 13, 41571, 82, 13, 31092, 1330, 20857, 17633, 198, 6738, 4755, 13, 41571, 82, 13, 5225, 10223, 1330, 10933, 10223...
2.839286
112
from greens_thm_form import greens_form_line, greens_form_shape from numpy import arange, linspace, float64, indices, zeros_like, ones_like, pi, sin, complex128, array, exp, newaxis, cumsum, sum, cos, sin, log, log10 from osrefl.theory.DWBAGISANS import dwbaWavefunction # alternating SLD wavelength = 1.24 # x-ray wavelength, Angstroms spacing = 600.0 # distance between cylinder centers radius = 200.0 # Angstroms, radius of cylinders thickness = 300.0 # Angstrom, thickness of cylinder layer sublayer_thickness = 200.0 # Angstrom, full layer of matrix below cylinders matrix_sld = pi/(wavelength**2) * 2.0 * 1.0e-6 # substrate matrix_sldi = pi/(wavelength**2) * 2.0 * 1.0e-7 # absorption in substrate cyl_sld = 0.0 cyl_sldi = 0.0 # cylinders are holes in matrix unit_dx = 2.0 * spacing unit_dy = 1.0 * spacing matrix = rectangle(0,0, 3000, 3000, matrix_sld, matrix_sldi) cylinders = [] centers = [] for i in range(3): for j in range(6): x0 = i * 2.0 * spacing y0 = j * spacing x1 = x0 + spacing # basis y1 = y0 + spacing/2.0 cylinders.append(arc(radius, 0.0, 360.0, x0, y0, sld=cyl_sld, sldi=cyl_sldi)) cylinders.append(arc(radius, 0.0, 360.0, x1, y1, sld=cyl_sld, sldi=cyl_sldi)) cyl_area = 0.0 for cyl in cylinders: cyl_area += cyl.area clipped_cylinders = [limit_cyl(cyl, xmin=0.0, xmax=3000.0, ymin=0.0, ymax=3000.0) for cyl in cylinders] clipped_cyl_area = 0.0 for cyl in clipped_cylinders: clipped_cyl_area += cyl.area print "clipped_cyl_area / matrix.area = ", clipped_cyl_area / matrix.area print "ratio should be 0.3491 for FCT planar array with a/b = 2 and r = a/6" avg_sld = (matrix.area * matrix_sld + clipped_cyl_area * cyl_sld) / matrix.area avg_sldi = (matrix.area * matrix_sldi + clipped_cyl_area * cyl_sldi) / matrix.area front_sld = 0.0 # air back_sld = pi/(wavelength**2) * 2.0 * 5.0e-6 # substrate back_sldi = pi/(wavelength**2) * 2.0 * 7.0e-8 # absorption in substrate qz = linspace(0.01, 0.21, 501) qy = linspace(-0.1, 0.1, 500) qx = ones_like(qy, dtype=complex128) * 1e-8 SLDArray = [ [0,0,0], # air [avg_sld, thickness, avg_sldi], # sample [matrix_sld, sublayer_thickness, matrix_sldi], # full matrix layer under cylinders [back_sld, 0, back_sldi] ] FT = zeros_like(qx, dtype=complex128) for cyl in clipped_cylinders: FT += greens_form_shape(cyl.points, qx, qy) * (cyl.sld) FT += greens_form_shape(matrix.points, qx, qy) * (matrix.sld) FT += greens_form_shape(matrix.points, qx, qy) * (-avg_sld) SLDArray = array(SLDArray)
[ 6738, 30966, 62, 400, 76, 62, 687, 1330, 30966, 62, 687, 62, 1370, 11, 30966, 62, 687, 62, 43358, 198, 6738, 299, 32152, 1330, 610, 858, 11, 300, 1040, 10223, 11, 12178, 2414, 11, 36525, 11, 1976, 27498, 62, 2339, 11, 3392, 62, 23...
2.322262
1,114
# -*- coding: utf-8 -*- # Demo: MACD strategy # src: ./test_backtest/MACD_JCSC.py # jupyter: ./test_backtest/QUANTAXIS.ipynb # paper: ./test_backtest/QUANTAXIS.md import QUANTAXIS as QA import numpy as np import pandas as pd import datetime st1=datetime.datetime.now() # define the MACD strategy def MACD_JCSC(dataframe, SHORT=12, LONG=26, M=9): """ 1.DIFDEA 2.DIFDEA """ CLOSE = dataframe.close DIFF = QA.EMA(CLOSE, SHORT) - QA.EMA(CLOSE, LONG) DEA = QA.EMA(DIFF, M) MACD = 2*(DIFF-DEA) CROSS_JC = QA.CROSS(DIFF, DEA) CROSS_SC = QA.CROSS(DEA, DIFF) ZERO = 0 return pd.DataFrame({'DIFF': DIFF, 'DEA': DEA, 'MACD': MACD, 'CROSS_JC': CROSS_JC, 'CROSS_SC': CROSS_SC, 'ZERO': ZERO}) # create account Account = QA.QA_Account() Broker = QA.QA_BacktestBroker() Account.reset_assets(1000000) Account.account_cookie = 'macd_stock' QA.QA_SU_save_strategy('MACD_JCSC','Indicator',Account.account_cookie) # get data from mongodb data = QA.QA_fetch_stock_day_adv( ['000001', '000002', '000004', '600000'], '2017-09-01', '2018-05-20') data = data.to_qfq() # add indicator ind = data.add_func(MACD_JCSC) # ind.xs('000001',level=1)['2018-01'].plot() data_forbacktest=data.select_time('2018-01-01','2018-05-01') for items in data_forbacktest.panel_gen: for item in items.security_gen: daily_ind=ind.loc[item.index] if daily_ind.CROSS_JC.iloc[0]>0: order=Account.send_order( code=item.code[0], time=item.date[0], amount=1000, towards=QA.ORDER_DIRECTION.BUY, price=0, order_model=QA.ORDER_MODEL.CLOSE, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT ) #print(item.to_json()[0]) Broker.receive_order(QA.QA_Event(order=order,market_data=item)) trade_mes=Broker.query_orders(Account.account_cookie,'filled') res=trade_mes.loc[order.account_cookie,order.realorder_id] order.trade(res.trade_id,res.trade_price,res.trade_amount,res.trade_time) elif daily_ind.CROSS_SC.iloc[0]>0: #print(item.code) if Account.sell_available.get(item.code[0], 0)>0: order=Account.send_order( code=item.code[0], time=item.date[0], amount=Account.sell_available.get(item.code[0], 0), towards=QA.ORDER_DIRECTION.SELL, price=0, order_model=QA.ORDER_MODEL.MARKET, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT ) #print Broker.receive_order(QA.QA_Event(order=order,market_data=item)) trade_mes=Broker.query_orders(Account.account_cookie,'filled') res=trade_mes.loc[order.account_cookie,order.realorder_id] order.trade(res.trade_id,res.trade_price,res.trade_amount,res.trade_time) Account.settle() print('TIME -- {}'.format(datetime.datetime.now()-st1)) print(Account.history) print(Account.history_table) print(Account.daily_hold) # create Risk analysis Risk = QA.QA_Risk(Account) Account.save() Risk.save() # print(Risk.message) # print(Risk.assets) # Risk.plot_assets_curve() # plt=Risk.plot_dailyhold() # plt.show() # plt1=Risk.plot_signal() # plt.show() # performance=QA.QA_Performance(Account) # plt=performance.plot_pnlmoney(performance.pnl_fifo) # plt.show() # Risk.assets.plot() # Risk.benchmark_assets.plot() # save result #account_info = QA.QA_fetch_account({'account_cookie': 'user_admin_macd'}) #account = QA.QA_Account().from_message(account_info[0]) #print(account)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 34588, 25, 20582, 35, 4811, 198, 2, 12351, 25, 24457, 9288, 62, 1891, 9288, 14, 44721, 35, 62, 34382, 6173, 13, 9078, 198, 2, 474, 929, 88, 353, 25, 24457, 9288, ...
1.987138
1,866
from zquantum.core.interfaces.ansatz_test import AnsatzTests from zquantum.core.circuits import Circuit, H, RX, RZ from zquantum.core.utils import compare_unitary from zquantum.core.openfermion import change_operator_type from zquantum.qaoa.ansatzes.farhi_ansatz import ( QAOAFarhiAnsatz, create_farhi_qaoa_circuits, create_all_x_mixer_hamiltonian, ) from openfermion import QubitOperator, IsingOperator import pytest import numpy as np import sympy def test_create_farhi_qaoa_circuits(): # Given hamiltonians = [ QubitOperator("Z0 Z1"), QubitOperator("Z0") + QubitOperator("Z1"), ] number_of_layers = 2 # When circuits = create_farhi_qaoa_circuits(hamiltonians, number_of_layers) # Then assert len(circuits) == len(hamiltonians) for circuit in circuits: assert isinstance(circuit, Circuit)
[ 6738, 1976, 40972, 388, 13, 7295, 13, 3849, 32186, 13, 504, 27906, 62, 9288, 1330, 28038, 27906, 51, 3558, 198, 6738, 1976, 40972, 388, 13, 7295, 13, 21170, 15379, 1330, 13588, 11, 367, 11, 24202, 11, 371, 57, 198, 6738, 1976, 40972, ...
2.470255
353
from html.parser import HTMLParser
[ 6738, 27711, 13, 48610, 1330, 11532, 46677, 628 ]
4.5
8
"""Wrapper for pygame, which exports the PSP Python API on non-PSP systems.""" __author__ = "Per Olofsson, <MagerValp@cling.gu.se>" import pygame pygame.init() _vol_music = 255 _vol_sound = 255
[ 37811, 36918, 2848, 329, 12972, 6057, 11, 543, 15319, 262, 48651, 11361, 7824, 319, 1729, 12, 3705, 47, 3341, 526, 15931, 198, 198, 834, 9800, 834, 796, 366, 5990, 6544, 1659, 16528, 11, 1279, 44, 3536, 7762, 79, 31, 8493, 13, 5162, ...
2.743243
74
import os import csv import ast # used to generate folder-seperated corpus from CMUMovie dataset # just type python utility_parseCMUMovie.py in a terminal and the data will be downloaded and split to subfolders in the moviePlots/ path os.system("wget http://www.cs.cmu.edu/~ark/personas/data/MovieSummaries.tar.gz") os.system("tar -xvzf MovieSummaries.tar.gz") minRevenue = 20000000 movieMetadata = {} with open('MovieSummaries/movie.metadata.tsv', 'rb') as csvfile: reader = csv.reader(csvfile, delimiter='\t', quotechar='|') for row in reader: rev = 0 if len(row[4])>1: rev = int(row[4]) if (minRevenue < 0) or ( (minRevenue > 0) and (rev>minRevenue) ): movieMetadata[row[0]] = {} movieMetadata[row[0]]['title'] = row[2] movieMetadata[row[0]]['genres'] = ast.literal_eval(row[8]).values() print len(movieMetadata) with open("MovieSummaries/plot_summaries.txt") as f: content = f.readlines() for c in content: d = c.split("\t") id = d[0] plot = d[1] if id in movieMetadata: print id, movieMetadata[id]['title'] for g in movieMetadata[id]['genres']: if not os.path.exists("moviePlots" + os.sep + g.replace("/","-")): os.makedirs("moviePlots" + os.sep + g.replace("/","-")) f = open("moviePlots" + os.sep + g.replace("/","-") + os.sep + id + "_" + movieMetadata[id]["title"].replace("/","-"), 'w') f.write(plot) f.close()
[ 11748, 28686, 198, 11748, 269, 21370, 198, 11748, 6468, 198, 198, 2, 973, 284, 7716, 9483, 12, 325, 525, 515, 35789, 422, 16477, 5883, 10739, 27039, 220, 198, 2, 655, 2099, 21015, 10361, 62, 29572, 24187, 5883, 10739, 13, 9078, 287, 2...
2.178218
707