content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
#!/usr/bin/env python3 """ The Coin Change Problem :author: Dela Anthonio :hackerrank: https://hackerrank.com/delaanthonio :problem: https://www.hackerrank.com/challenges/coin-change/problem """ from typing import List def count_ways(amount: int, coins: List[int]) -> int: """Return the number of ways we can count to ``amount`` with values ``coins``.""" ways = [1] + [0] * amount for coin in coins: for val in range(coin, amount + 1): ways[val] += ways[val - coin] return ways[-1] if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 37811, 198, 464, 16312, 9794, 20647, 198, 198, 25, 9800, 25, 4216, 64, 8451, 261, 952, 198, 25, 31153, 8056, 962, 25, 3740, 1378, 31153, 8056, 962, 13, 785, 14, 67, 10304, 29313,...
2.618605
215
from django.contrib import admin #from .models import * from . import models # Register your models here. admin.site.register(models.ClimbModel)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 198, 2, 6738, 764, 27530, 1330, 1635, 198, 6738, 764, 1330, 4981, 198, 198, 2, 17296, 534, 4981, 994, 13, 198, 28482, 13, 15654, 13, 30238, 7, 27530, 13, 34, 2475, 65, 17633, 8, ...
3.340909
44
# coding: utf-8 from runpy import run_path from setuptools import setup # Get the version from the relevant file d = run_path('skaero/version.py') __version__ = d['__version__'] setup( name="scikit-aero", version=__version__, description="Aeronautical engineering calculations in Python.", author="Juan Luis Cano", author_email="juanlu001@gmail.com", url="https://github.com/Juanlu001/scikit-aero", license="BSD", keywords=[ "aero", "aeronautical", "aerospace", "engineering", "atmosphere", "gas" ], requires=["numpy", "scipy"], packages=[ "skaero", "skaero.atmosphere", "skaero.gasdynamics", "skaero.util" ], classifiers=[ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Education", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Physics" ], long_description=open('README.rst').read() )
[ 2, 19617, 25, 3384, 69, 12, 23, 198, 6738, 1057, 9078, 1330, 1057, 62, 6978, 198, 6738, 900, 37623, 10141, 1330, 9058, 198, 198, 2, 3497, 262, 2196, 422, 262, 5981, 2393, 198, 67, 796, 1057, 62, 6978, 10786, 82, 4914, 3529, 14, 96...
2.538153
498
""" 8 """ n=int(input("n:")) queens = [0]*(n+1) # col_flags=[0]*(n+1) # diag_flags = [0]*(2*n) # diag2_flags = [0] * (2*n) count = 0 queen(n) print(f"{count}\n")
[ 37811, 198, 23, 628, 198, 198, 37811, 628, 198, 77, 28, 600, 7, 15414, 7203, 77, 11097, 4008, 198, 4188, 641, 796, 685, 15, 60, 9, 7, 77, 10, 16, 8, 198, 2, 220, 198, 4033, 62, 33152, 41888, 15, 60, 9, 7, 77, 10, 16, 8, 19...
1.616822
107
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: CC-BY-4.0 import os import cv2 from collections import namedtuple import imageio from PIL import Image from random import randrange import numpy as np from sklearn.decomposition import PCA from scipy.spatial.distance import pdist, squareform import torch import matplotlib matplotlib.use('Agg') # Required for gif animations import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.image as image import matplotlib.patches as patches from multimodal_affinities.visualization.vis_handler import VisHandler from multimodal_affinities.visualization.image_utils import resize_image from multimodal_affinities.visualization.colors_util import rgb_hex_to_tuple
[ 2, 15069, 6186, 13, 785, 11, 3457, 13, 393, 663, 29116, 13, 1439, 6923, 33876, 13, 198, 2, 30628, 55, 12, 34156, 12, 33234, 7483, 25, 12624, 12, 17513, 12, 19, 13, 15, 198, 198, 11748, 28686, 198, 11748, 269, 85, 17, 198, 6738, ...
3.420354
226
import re import lxml.html from openstates.utils import LXMLMixin from billy.scrape.legislators import LegislatorScraper, Legislator
[ 11748, 302, 198, 11748, 300, 19875, 13, 6494, 198, 6738, 1280, 27219, 13, 26791, 1330, 44988, 5805, 35608, 259, 198, 198, 6738, 2855, 88, 13, 1416, 13484, 13, 1455, 3044, 2024, 1330, 12288, 1352, 3351, 38545, 11, 12288, 1352, 628, 198 ]
3.317073
41
from header import * from .utils import * from .util_func import * '''Only for Testing'''
[ 6738, 13639, 1330, 1635, 198, 6738, 764, 26791, 1330, 1635, 198, 6738, 764, 22602, 62, 20786, 1330, 1635, 198, 198, 7061, 6, 10049, 329, 23983, 7061, 6, 628, 198 ]
3.206897
29
# # PySNMP MIB module DABING-MIB (http://snmplabs.com/pysmi) # ASN.1 source file://..\DABING-MIB.mib # Produced by pysmi-0.3.4 at Tue Mar 22 12:53:47 2022 # On host ? platform ? version ? by user ? # Using Python version 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] # OctetString, ObjectIdentifier, Integer = mibBuilder.importSymbols("ASN1", "OctetString", "ObjectIdentifier", "Integer") NamedValues, = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues") ConstraintsIntersection, ConstraintsUnion, ValueRangeConstraint, SingleValueConstraint, ValueSizeConstraint = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsIntersection", "ConstraintsUnion", "ValueRangeConstraint", "SingleValueConstraint", "ValueSizeConstraint") NotificationGroup, ModuleCompliance = mibBuilder.importSymbols("SNMPv2-CONF", "NotificationGroup", "ModuleCompliance") MibScalar, MibTable, MibTableRow, MibTableColumn, Gauge32, ModuleIdentity, IpAddress, ObjectIdentity, iso, Counter32, Unsigned32, Bits, NotificationType, TimeTicks, Counter64, enterprises, MibIdentifier, Integer32 = mibBuilder.importSymbols("SNMPv2-SMI", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "Gauge32", "ModuleIdentity", "IpAddress", "ObjectIdentity", "iso", "Counter32", "Unsigned32", "Bits", "NotificationType", "TimeTicks", "Counter64", "enterprises", "MibIdentifier", "Integer32") DisplayString, TextualConvention = mibBuilder.importSymbols("SNMPv2-TC", "DisplayString", "TextualConvention") dabing = ModuleIdentity((1, 3, 6, 1, 4, 1, 55532)) dabing.setRevisions(('2022-03-17 00:00',)) if mibBuilder.loadTexts: dabing.setLastUpdated('202203170000Z') if mibBuilder.loadTexts: dabing.setOrganization('www.stuba.sk') Parameters = MibIdentifier((1, 3, 6, 1, 4, 1, 55532, 1)) Agent = MibIdentifier((1, 3, 6, 1, 4, 1, 55532, 2)) Manager = MibIdentifier((1, 3, 6, 1, 4, 1, 55532, 3)) Notifications = MibIdentifier((1, 3, 6, 1, 4, 1, 55532, 4)) NotificationPrefix = MibIdentifier((1, 3, 6, 1, 4, 1, 55532, 4, 1)) NotificationObjects = MibIdentifier((1, 3, 6, 1, 4, 1, 55532, 4, 2)) channel = MibScalar((1, 3, 6, 1, 4, 1, 55532, 1, 1), OctetString().clone('12C')).setMaxAccess("readonly") if mibBuilder.loadTexts: channel.setStatus('current') interval = MibScalar((1, 3, 6, 1, 4, 1, 55532, 1, 2), Integer32().clone(960)).setMaxAccess("readonly") if mibBuilder.loadTexts: interval.setStatus('current') trapEnabled = MibScalar((1, 3, 6, 1, 4, 1, 55532, 1, 3), Integer32()).setMaxAccess("readonly") if mibBuilder.loadTexts: trapEnabled.setStatus('current') agentIdentifier = MibScalar((1, 3, 6, 1, 4, 1, 55532, 2, 1), Integer32()).setMaxAccess("readwrite") if mibBuilder.loadTexts: agentIdentifier.setStatus('current') agentLabel = MibScalar((1, 3, 6, 1, 4, 1, 55532, 2, 2), OctetString()).setMaxAccess("readwrite") if mibBuilder.loadTexts: agentLabel.setStatus('current') agentStatus = MibScalar((1, 3, 6, 1, 4, 1, 55532, 2, 3), Integer32()).setMaxAccess("readonly") if mibBuilder.loadTexts: agentStatus.setStatus('current') managerHostname = MibScalar((1, 3, 6, 1, 4, 1, 55532, 3, 1), OctetString()).setMaxAccess("readonly") if mibBuilder.loadTexts: managerHostname.setStatus('current') managerPort = MibScalar((1, 3, 6, 1, 4, 1, 55532, 3, 2), Integer32().clone(162)).setMaxAccess("readonly") if mibBuilder.loadTexts: managerPort.setStatus('current') genericPayload = MibScalar((1, 3, 6, 1, 4, 1, 55532, 4, 2, 1), OctetString()).setMaxAccess("accessiblefornotify") if mibBuilder.loadTexts: genericPayload.setStatus('current') malfunctionTrap = NotificationType((1, 3, 6, 1, 4, 1, 55532, 4, 1, 1)).setObjects(("DABING-MIB", "genericPayload")) if mibBuilder.loadTexts: malfunctionTrap.setStatus('current') testTrap = NotificationType((1, 3, 6, 1, 4, 1, 55532, 4, 1, 2)).setObjects(("DABING-MIB", "genericPayload")) if mibBuilder.loadTexts: testTrap.setStatus('current') mibBuilder.exportSymbols("DABING-MIB", Notifications=Notifications, channel=channel, PYSNMP_MODULE_ID=dabing, testTrap=testTrap, malfunctionTrap=malfunctionTrap, Parameters=Parameters, agentLabel=agentLabel, managerPort=managerPort, trapEnabled=trapEnabled, managerHostname=managerHostname, Manager=Manager, NotificationPrefix=NotificationPrefix, Agent=Agent, genericPayload=genericPayload, NotificationObjects=NotificationObjects, agentIdentifier=agentIdentifier, dabing=dabing, agentStatus=agentStatus, interval=interval)
[ 2, 198, 2, 9485, 15571, 7378, 337, 9865, 8265, 360, 6242, 2751, 12, 8895, 33, 357, 4023, 1378, 16184, 76, 489, 8937, 13, 785, 14, 79, 893, 11632, 8, 198, 2, 7054, 45, 13, 16, 2723, 2393, 1378, 492, 59, 5631, 33, 2751, 12, 8895, ...
2.735532
1,607
import os import numpy as np save_stem='extra_vis_friday_harbor' data_dir='../../data/sdk_new_100' resolution=100 cre=False source_acronyms=['VISal','VISam','VISl','VISp','VISpl','VISpm', 'VISli','VISpor','VISrl','VISa'] lambda_list = np.logspace(3,12,10) scale_lambda=True min_vox=0 # save_file_name='visual_output.hdf5' #source_coverage=0.90 source_coverage=0.95 #source_shell = 1 source_shell=None save_dir=os.path.join('../../data/connectivities',save_stem) experiments_fn=None target_acronyms=source_acronyms solver=os.path.abspath('../smoothness_c/solve') cmdfile=os.path.join(save_dir,'model_fitting_cmds') selected_fit_cmds=os.path.join(save_dir,'model_fitting_after_selection_cmds') save_mtx=True cross_val_matrices=True cross_val=5 fit_gaussian=False select_one_lambda=False if select_one_lambda: lambda_fn='lambda_opt' else: lambda_fn='lambda_ipsi_contra_opt' laplacian='free' shuffle_seed=666 max_injection_volume=0.7
[ 11748, 28686, 198, 11748, 299, 32152, 355, 45941, 198, 198, 21928, 62, 927, 11639, 26086, 62, 4703, 62, 8310, 2567, 62, 9869, 2865, 6, 198, 7890, 62, 15908, 11639, 40720, 40720, 7890, 14, 21282, 74, 62, 3605, 62, 3064, 6, 198, 29268, ...
2.372208
403
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Nov 20 09:42:39 2020 @author: niklas """ from mossepy.mosse_tracker import MOSSE # choose position of object in first frame # that should be done by mouse click objPos = [256, 256] # choose tracker type tracker = MOSSE() # initialize object position in first frame tracker.setObjPos(objPos) # start tracking tracker.trackImg()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 19480, 5267, 1160, 7769, 25, 3682, 25, 2670, 12131, 198, 198, 31, 9800, 25, 299, 1134, 21...
2.911765
136
def solve(polynomial): """ input is polynomial if more than one variable, returns 'too many variables' looks for formula to apply to coefficients returns solution or 'I cannot solve yet...' """ if len(polynomial.term_matrix[0]) > 2: return 'too many variables' elif len(polynomial.term_matrix[0]) == 1: return polynomial.term_matrix[1][0] elif len(polynomial.term_matrix[0]) == 2: degree = polynomial.term_matrix[1][1] if degree == 1: if len(polynomial.term_matrix) == 2: return 0 else: return -polynomial.term_matrix[2][0]/polynomial.term_matrix[1][0] if degree == 2: ans = quadratic_formula(polynomial) return ans if degree > 2: return Durand_Kerner(polynomial) def quadratic_formula(polynomial): """ input is single-variable polynomial of degree 2 returns zeros """ if len(polynomial.term_matrix) == 3: if polynomial.term_matrix[2][1] == 1: a, b = polynomial.term_matrix[1][0], polynomial.term_matrix[2][0] return 0, -b/a a, c = polynomial.term_matrix[1][0], polynomial.term_matrix[2][0] return (-c/a)**.5, -(-c/a)**.5 if len(polynomial.term_matrix) == 2: a, b, c, = polynomial.term_matrix[1][0], 0, 0 elif len(polynomial.term_matrix) == 3: a, b, c = polynomial.term_matrix[1][0], polynomial.term_matrix[2][0], 0 else: a, b, c = polynomial.term_matrix[1][0], polynomial.term_matrix[2][0], polynomial.term_matrix[3][0] ans1 = (-b + (b**2 - 4*a*c)**.5)/2*a ans2 = (-b - (b**2 - 4*a*c)**.5)/2*a if ans1 == ans2: return ans1 return ans1, ans2 def isclose(a, b, rel_tol=1e-09, abs_tol=0.0001): """ returns boolean whether abs(a-b) is less than abs_total or rel_total*max(a, b) """ return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) def Durand_Kerner(f): """ input polynomial returns numerical approximation of all complex roots """ roots = [] for i in range(f.degree()): roots.append((0.4 + 0.9j)**i) diff = 1 diff_temp = 0 while diff > .00000001 and not isclose(diff_temp, diff): iterate() for i in range(len(roots)): if isclose(roots[i].real, round(roots[i].real)): temp = round(roots[i].real) roots[i] -= roots[i].real roots[i] += temp if isclose(roots[i].imag, round(roots[i].imag)): temp = round(roots[i].imag) roots[i] -= roots[i].imag*1j roots[i] += temp*1j return roots if __name__ == '__main__': pass
[ 4299, 8494, 7, 35428, 26601, 498, 2599, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 5128, 318, 745, 6213, 49070, 198, 220, 220, 220, 611, 517, 621, 530, 7885, 11, 5860, 705, 18820, 867, 9633, 6, 198, 220, 220, 220, 3073, 329, 1...
2.030827
1,330
"""Utility functions for parsing SVG styles.""" __all__ = ["cascade_element_style", "parse_style", "parse_color_string"] from xml.dom.minidom import Element as MinidomElement from colour import web2hex from ...utils.color import rgb_to_hex from typing import Dict, List CASCADING_STYLING_ATTRIBUTES: List[str] = [ "fill", "stroke", "fill-opacity", "stroke-opacity", ] # The default styling specifications for SVG images, # according to https://www.w3.org/TR/SVG/painting.html # (ctrl-F for "initial") SVG_DEFAULT_ATTRIBUTES: Dict[str, str] = { "fill": "black", "fill-opacity": "1", "stroke": "none", "stroke-opacity": "1", } def cascade_element_style( element: MinidomElement, inherited: Dict[str, str] ) -> Dict[str, str]: """Collect the element's style attributes based upon both its inheritance and its own attributes. SVG uses cascading element styles. A closer ancestor's style takes precedence over a more distant ancestor's style. In order to correctly calculate the styles, the attributes are passed down through the inheritance tree, updating where necessary. Note that this method only copies the values and does not parse them. See :meth:`parse_color_string` for converting from SVG attributes to manim keyword arguments. Parameters ---------- element : :class:`MinidomElement` Element of the SVG parse tree inherited : :class:`dict` Dictionary of SVG attributes inherited from the parent element. Returns ------- :class:`dict` Dictionary mapping svg attributes to values with `element`'s values overriding inherited values. """ style = inherited.copy() # cascade the regular elements. for attr in CASCADING_STYLING_ATTRIBUTES: entry = element.getAttribute(attr) if entry: style[attr] = entry # the style attribute should be handled separately in order to # break it up nicely. furthermore, style takes priority over other # attributes in the same element. style_specs = element.getAttribute("style") if style_specs: for style_spec in style_specs.split(";"): try: key, value = style_spec.split(":") except ValueError as e: if not style_spec.strip(): # there was just a stray semicolon at the end, producing an emptystring pass else: raise e else: style[key.strip()] = value.strip() return style def parse_color_string(color_spec: str) -> str: """Handle the SVG-specific color strings and convert them to HTML #rrggbb format. Parameters ---------- color_spec : :class:`str` String in any web-compatible format Returns ------- :class:`str` Hexadecimal color string in the format `#rrggbb` """ if color_spec[0:3] == "rgb": # these are only in integer form, but the Colour module wants them in floats. splits = color_spec[4:-1].split(",") if splits[0][-1] == "%": # if the last character of the first number is a percentage, # then interpret the number as a percentage parsed_rgbs = [float(i[:-1]) / 100.0 for i in splits] else: parsed_rgbs = [int(i) / 255.0 for i in splits] hex_color = rgb_to_hex(parsed_rgbs) elif color_spec[0] == "#": # its OK, parse as hex color standard. hex_color = color_spec else: # attempt to convert color names like "red" to hex color hex_color = web2hex(color_spec, force_long=True) return hex_color def fill_default_values(svg_style: Dict) -> None: """ Fill in the default values for properties of SVG elements, if they are not currently set in the style dictionary. Parameters ---------- svg_style : :class:`dict` Style dictionary with SVG property names. Some may be missing. Returns ------- :class:`dict` Style attributes; none are missing. """ for key in SVG_DEFAULT_ATTRIBUTES: if key not in svg_style: svg_style[key] = SVG_DEFAULT_ATTRIBUTES[key] def parse_style(svg_style: Dict[str, str]) -> Dict: """Convert a dictionary of SVG attributes to Manim VMobject keyword arguments. Parameters ---------- svg_style : :class:`dict` Style attributes as a string-to-string dictionary. Keys are valid SVG element attributes (fill, stroke, etc) Returns ------- :class:`dict` Style attributes, but in manim kwargs form, e.g., keys are fill_color, stroke_color """ manim_style = {} fill_default_values(svg_style) if "fill-opacity" in svg_style: manim_style["fill_opacity"] = float(svg_style["fill-opacity"]) if "stroke-opacity" in svg_style: manim_style["stroke_opacity"] = float(svg_style["stroke-opacity"]) # nones need to be handled specially if "fill" in svg_style: if svg_style["fill"] == "none": manim_style["fill_opacity"] = 0 else: manim_style["fill_color"] = parse_color_string(svg_style["fill"]) if "stroke" in svg_style: if svg_style["stroke"] == "none": # In order to not break animations.creation.Write, # we interpret no stroke as stroke-width of zero and # color the same as the fill color, if it exists. manim_style["stroke_width"] = 0 if "fill_color" in manim_style: manim_style["stroke_color"] = manim_style["fill_color"] else: manim_style["stroke_color"] = parse_color_string(svg_style["stroke"]) return manim_style
[ 37811, 18274, 879, 5499, 329, 32096, 45809, 12186, 526, 15931, 628, 198, 834, 439, 834, 796, 14631, 66, 28966, 62, 30854, 62, 7635, 1600, 366, 29572, 62, 7635, 1600, 366, 29572, 62, 8043, 62, 8841, 8973, 198, 198, 6738, 35555, 13, 343...
2.544611
2,264
#!/usr/bin/env python #coding:utf-8 import os import RPi.GPIO as GPIO # import json from time import sleep # from twython import Twython f=open("tw_config.json",'r') config=json.load(f) f.close() CONSUMER_KEY =config['consumer_key'] CONSUMER_SECRET =config['consumer_secret'] ACCESS_TOKEN =config['access_token'] ACCESS_SECRET =config['access_secret'] dist=config['dist'] api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN,ACCESS_SECRET) trigger_input=21 GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.OUT) GPIO.setup(trigger_input, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(trigger_input, GPIO.RISING, callback=on_positive_edge, bouncetime=1000) ledstate = GPIO.LOW try: while True: sleep(0.01) except KeyboardInterrupt: # pass GPIO.cleanup() #
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 66, 7656, 25, 40477, 12, 23, 198, 198, 11748, 28686, 198, 11748, 25812, 72, 13, 16960, 9399, 355, 50143, 1303, 198, 11748, 33918, 198, 6738, 640, 1330, 3993, 1303, 198, 6738, 665, ...
2.415902
327
""" Unit tests for ``wheezy.templates.utils``. """ import unittest
[ 198, 37811, 11801, 5254, 329, 7559, 12491, 68, 7357, 13, 11498, 17041, 13, 26791, 15506, 13, 198, 37811, 198, 198, 11748, 555, 715, 395, 628, 198 ]
2.730769
26
# -*- coding:utf-8 -*- # /usr/bin/env python """ Date: 2019/10/21 12:08 Desc: --- """ import json import time import pandas as pd import requests from tqdm import tqdm from akshare.economic.cons import ( JS_CONS_GOLD_ETF_URL, JS_CONS_SLIVER_ETF_URL, JS_CONS_OPEC_URL, ) def macro_cons_gold_volume(): """ ETFSPDR Gold Trust, 20041118- :return: pandas.Series 2004-11-18 8.09 2004-11-19 57.85 2004-11-22 87.09 2004-11-23 87.09 2004-11-24 96.42 ... 2019-10-20 924.64 2019-10-21 924.64 2019-10-22 919.66 2019-10-23 918.48 2019-10-24 918.48 """ t = time.time() res = requests.get( JS_CONS_GOLD_ETF_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] value_list = [item["datas"][""] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df["()"] url = "https://datacenter-api.jin10.com/reports/list_v2" params = { "max_date": "", "category": "etf", "attr_id": "1", "_": str(int(round(t * 1000))), } headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } r = requests.get(url, params=params, headers=headers) temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, :2] temp_se.index = pd.to_datetime(temp_se.iloc[:, 0]) temp_se = temp_se.iloc[:, 1] temp_df = temp_df.append(temp_se) temp_df.dropna(inplace=True) temp_df.sort_index(inplace=True) temp_df = temp_df.reset_index() temp_df.drop_duplicates(subset="index", keep="last", inplace=True) temp_df.set_index("index", inplace=True) temp_df = temp_df.squeeze() temp_df.index.name = None temp_df.name = "gold_volume" temp_df = temp_df.astype(float) return temp_df def macro_cons_gold_change(): """ ETFSPDR Gold Trust, 20041118- :return: pandas.Series 2004-11-18 0 2004-11-19 49.76 2004-11-22 29.24 2004-11-23 0.00 2004-11-24 9.33 ... 2019-10-20 0.00 2019-10-21 0.00 2019-10-22 -4.98 2019-10-23 -1.18 2019-10-24 0.00 """ t = time.time() res = requests.get( JS_CONS_GOLD_ETF_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] value_list = [item["datas"][""] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df["/()"] url = "https://datacenter-api.jin10.com/reports/list_v2" params = { "max_date": "", "category": "etf", "attr_id": "1", "_": str(int(round(t * 1000))), } headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } r = requests.get(url, params=params, headers=headers) temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, [0, 2]] temp_se.index = pd.to_datetime(temp_se.iloc[:, 0]) temp_se = temp_se.iloc[:, 1] temp_df = temp_df.append(temp_se) temp_df.dropna(inplace=True) temp_df.sort_index(inplace=True) temp_df = temp_df.reset_index() temp_df.drop_duplicates(subset="index", keep="last", inplace=True) temp_df.set_index("index", inplace=True) temp_df = temp_df.squeeze() temp_df.index.name = None temp_df.name = "gold_change" temp_df = temp_df.astype(float) return temp_df def macro_cons_gold_amount(): """ ETFSPDR Gold Trust, 20041118- :return: pandas.Series 2004-11-18 114920000.00 2004-11-19 828806907.20 2004-11-22 1253785205.50 2004-11-23 1254751438.19 2004-11-24 1390568824.08 ... 2019-10-20 44286078486.23 2019-10-21 44333677232.68 2019-10-22 43907962483.56 2019-10-23 44120217405.82 2019-10-24 44120217405.82 """ t = time.time() res = requests.get( JS_CONS_GOLD_ETF_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] value_list = [item["datas"][""] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df["()"] url = "https://datacenter-api.jin10.com/reports/list_v2" params = { "max_date": "", "category": "etf", "attr_id": "1", "_": str(int(round(t * 1000))), } headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } r = requests.get(url, params=params, headers=headers) temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, [0, 3]] temp_se.index = pd.to_datetime(temp_se.iloc[:, 0]) temp_se = temp_se.iloc[:, 1] temp_df = temp_df.append(temp_se) temp_df.dropna(inplace=True) temp_df.sort_index(inplace=True) temp_df = temp_df.reset_index() temp_df.drop_duplicates(subset="index", keep="last", inplace=True) temp_df.set_index("index", inplace=True) temp_df = temp_df.squeeze() temp_df.index.name = None temp_df.name = "gold_amount" temp_df = temp_df.astype(float) return temp_df def macro_cons_silver_volume(): """ ETF--iShares Silver Trust, 20060429- :return: pandas.Series 2006-04-29 653.17 2006-05-02 653.17 2006-05-03 995.28 2006-05-04 1197.43 2006-05-05 1306.29 ... 2019-10-17 11847.91 2019-10-18 11847.91 2019-10-21 11813.02 2019-10-22 11751.96 2019-10-23 11751.96 """ t = time.time() res = requests.get( JS_CONS_SLIVER_ETF_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] value_list = [item["datas"][""] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df["()"] url = "https://datacenter-api.jin10.com/reports/list_v2" params = { "max_date": "", "category": "etf", "attr_id": "2", "_": str(int(round(t * 1000))), } headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } r = requests.get(url, params=params, headers=headers) temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, [0, 1]] temp_se.index = pd.to_datetime(temp_se.iloc[:, 0]) temp_se = temp_se.iloc[:, 1] temp_df = temp_df.append(temp_se) temp_df.dropna(inplace=True) temp_df.sort_index(inplace=True) temp_df = temp_df.reset_index() temp_df.drop_duplicates(subset="index", keep="last", inplace=True) temp_df.set_index("index", inplace=True) temp_df = temp_df.squeeze() temp_df.index.name = None temp_df.name = "silver_volume" url = "https://cdn.jin10.com/data_center/reports/etf_2.json" r = requests.get(url) data_json = r.json() append_temp_df = pd.DataFrame(data_json["values"]).T append_temp_df.columns = [item["name"] for item in data_json["keys"]] temp_append_df = append_temp_df[""] temp_append_df.name = "silver_volume" temp_df = temp_df.reset_index() temp_df["index"] = temp_df["index"].astype(str) temp_df = temp_df.append(temp_append_df.reset_index()) temp_df.drop_duplicates(subset=["index"], keep="last", inplace=True) temp_df.index = pd.to_datetime(temp_df["index"]) del temp_df["index"] temp_df = temp_df[temp_df != 'Show All'] temp_df.sort_index(inplace=True) temp_df = temp_df.astype(float) return temp_df def macro_cons_silver_change(): """ ETF--iShares Silver Trust, 20060429- :return: pandas.Series 2006-04-29 0 2006-05-02 0.00 2006-05-03 342.11 2006-05-04 202.15 2006-05-05 108.86 ... 2019-10-17 -58.16 2019-10-18 0.00 2019-10-21 -34.89 2019-10-22 -61.06 2019-10-23 0.00 """ t = time.time() res = requests.get( JS_CONS_SLIVER_ETF_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] value_list = [item["datas"][""] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df["/()"] temp_df.name = "silver_change" url = "https://datacenter-api.jin10.com/reports/list_v2" params = { "max_date": "", "category": "etf", "attr_id": "2", "_": str(int(round(t * 1000))), } headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } r = requests.get(url, params=params, headers=headers) temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, [0, 2]] temp_se.index = pd.to_datetime(temp_se.iloc[:, 0]) temp_se = temp_se.iloc[:, 1] temp_df = temp_df.append(temp_se) temp_df.dropna(inplace=True) temp_df.sort_index(inplace=True) temp_df = temp_df.reset_index() temp_df.drop_duplicates(subset="index", keep="last", inplace=True) temp_df.set_index("index", inplace=True) temp_df = temp_df.squeeze() temp_df.index.name = None temp_df.name = "silver_change" url = "https://cdn.jin10.com/data_center/reports/etf_2.json" r = requests.get(url) data_json = r.json() append_temp_df = pd.DataFrame(data_json["values"]).T append_temp_df.columns = [item["name"] for item in data_json["keys"]] temp_append_df = append_temp_df["/"] temp_append_df.name = "silver_change" temp_df = temp_df.reset_index() temp_df["index"] = temp_df["index"].astype(str) temp_df = temp_df.append(temp_append_df.reset_index()) temp_df.drop_duplicates(subset=["index"], keep="last", inplace=True) temp_df.index = pd.to_datetime(temp_df["index"]) del temp_df["index"] temp_df = temp_df[temp_df != 'Show All'] temp_df.sort_index(inplace=True) temp_df = temp_df.astype(float) return temp_df def macro_cons_silver_amount(): """ ETF--iShares Silver Trust, 20060429- :return: pandas.Series 2006-04-29 263651152 2006-05-02 263651152 2006-05-03 445408550 2006-05-04 555123947 2006-05-05 574713264 ... 2019-10-17 Show All 2019-10-18 Show All 2019-10-21 Show All 2019-10-22 Show All 2019-10-23 Show All """ t = time.time() res = requests.get( JS_CONS_SLIVER_ETF_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] value_list = [item["datas"][""] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df["()"] url = "https://datacenter-api.jin10.com/reports/list_v2" params = { "max_date": "", "category": "etf", "attr_id": "2", "_": str(int(round(t * 1000))), } headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } r = requests.get(url, params=params, headers=headers) temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, [0, 3]] temp_se.index = pd.to_datetime(temp_se.iloc[:, 0]) temp_se = temp_se.iloc[:, 1] temp_df = temp_df.append(temp_se) temp_df.dropna(inplace=True) temp_df.sort_index(inplace=True) temp_df = temp_df.reset_index() temp_df.drop_duplicates(subset="index", keep="last", inplace=True) temp_df.set_index("index", inplace=True) temp_df = temp_df.squeeze() temp_df.index.name = None temp_df.name = "silver_amount" url = "https://cdn.jin10.com/data_center/reports/etf_2.json" r = requests.get(url) data_json = r.json() append_temp_df = pd.DataFrame(data_json["values"]).T append_temp_df.columns = [item["name"] for item in data_json["keys"]] temp_append_df = append_temp_df[""] temp_append_df.name = "silver_amount" temp_df = temp_df.reset_index() temp_df["index"] = temp_df["index"].astype(str) temp_df = temp_df.append(temp_append_df.reset_index()) temp_df.drop_duplicates(subset=["index"], keep="last", inplace=True) temp_df.index = pd.to_datetime(temp_df["index"]) del temp_df["index"] temp_df = temp_df[temp_df != 'Show All'] temp_df.sort_index(inplace=True) temp_df = temp_df.astype(float) return temp_df def macro_cons_opec_near_change(): """ -, 20170118- :return: pandas.Series \ 2017-01-18 -0.87 3.56 -0.25 -0.87 0.95 4.26 0.20 3.13 -11.35 2017-02-13 -4.17 -2.32 -1.67 -1.00 5.02 -16.57 -14.12 6.47 10.18 2017-03-14 -0.02 -1.82 -0.44 -0.69 3.61 -6.20 -0.93 -1.11 5.80 2017-04-12 0.45 -1.87 -0.28 0.19 -2.87 -0.85 -0.95 -6.08 -2.98 2017-05-11 -0.75 9.71 -0.06 0.88 -3.47 -3.91 0.03 -6.16 5.08 2017-06-13 0.96 -5.42 0.22 -0.13 0.45 4.44 0.00 17.82 17.42 2017-07-12 -0.09 6.60 -0.21 -0.77 1.67 6.06 -0.02 12.70 9.67 2017-08-10 -0.10 -1.93 0.85 0.71 0.69 -3.31 -0.74 15.43 3.43 2017-09-12 0.41 0.83 -0.03 -3.23 -0.23 -2.31 0.01 -11.23 13.83 2017-10-11 -0.85 -0.29 -0.05 1.44 0.09 3.16 -0.17 5.39 5.08 2017-11-13 -3.84 6.98 0.71 0.18 -1.13 -13.10 -0.37 4.23 -5.44 2017-12-13 1.41 -10.87 -0.51 -0.47 -0.22 0.10 -0.53 0.61 9.58 2018-01-18 3.03 4.48 -0.72 -0.01 1.32 0.79 -0.25 -0.70 7.57 2018-04-12 -4.95 -8.17 0.26 -0.91 0.33 -1.31 0.23 -3.72 1.82 2018-05-14 1.77 -0.78 0.31 -0.93 1.00 -0.07 0.08 0.69 -0.83 2018-06-12 3.90 1.40 0.06 0.18 0.56 2.77 -0.57 -2.43 -5.35 2018-07-11 0.46 -8.83 -0.09 0.35 -2.27 7.15 2.73 -25.43 2.78 2018-08-13 1.38 1.17 0.42 -0.34 -5.63 2.41 7.85 -5.67 7.05 2018-09-12 -1.40 -0.80 0.40 18.80 -15.00 9.00 0.80 25.60 7.40 2018-10-11 -0.80 5.70 53.10 -0.10 -15.00 0.80 0.60 10.30 2.60 2018-11-13 -0.40 2.20 -0.30 0.30 -15.60 465.30 -3.30 6.00 -1.70 2018-12-12 -0.50 0.30 0.10 -1.10 -38.00 -2.30 4.50 -1.10 -3.00 2019-03-14 0.20 2.20 0.50 0.70 1.20 -7.00 -1.40 2.30 1.00 2019-04-10 -0.70 0.70 52.40 0.90 -2.80 -12.60 -0.10 19.60 1.10 2019-06-13 0.60 7.40 -0.10 2.30 -22.70 9.40 1.30 -0.30 -9.20 2017-01-18 -14.93 -0.63 -4.52 -22.09 2017-02-13 -49.62 -15.93 -3.05 -89.02 2017-03-14 -6.81 -3.69 -1.60 -13.95 2017-04-12 4.16 -3.27 -2.59 -15.27 2017-05-11 4.92 -6.23 -2.60 -1.82 2017-06-13 0.23 -1.80 -0.77 33.61 2017-07-12 5.13 -0.07 -1.36 39.35 2017-08-10 3.18 -0.67 -1.58 17.26 2017-09-12 -1.03 -2.02 -3.19 -7.91 2017-10-11 -0.07 -0.84 -5.19 8.85 2017-11-13 1.69 -0.60 -4.36 -15.09 2017-12-13 -4.54 -3.55 -4.16 -13.35 2018-01-18 -1.09 -0.70 -8.22 4.24 2018-04-12 -4.69 4.49 -5.53 -20.14 2018-05-14 4.65 0.61 -4.17 1.21 2018-06-12 8.55 -0.63 -4.25 3.54 2018-07-11 40.54 3.51 -4.75 17.34 2018-08-13 -5.28 6.92 -4.77 4.07 2018-09-12 3.80 1.20 -3.60 27.80 2018-10-11 10.80 3.00 -4.20 13.20 2018-11-13 12.70 14.20 -4.00 12.70 2018-12-12 37.70 7.10 -5.20 -1.10 2019-03-14 -8.60 -0.40 -14.20 -22.10 2019-04-10 -32.40 -0.90 -28.90 -53.40 2019-06-13 -7.60 0.30 -3.50 -23.60 """ t = time.time() big_df = pd.DataFrame() headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_opec_report", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } res = requests.get(f"https://datacenter-api.jin10.com/reports/dates?category=opec&_={str(int(round(t * 1000)))}", headers=headers) # all_date_list = res.json()["data"] bar = tqdm(reversed(all_date_list[:-1])) for item in bar: bar.set_description(f"Please wait for a moment, now downing {item}'s data") res = requests.get( f"https://datacenter-api.jin10.com/reports/list?category=opec&date={item}&_={str(int(round(t * 1000)))}", headers=headers) temp_df = pd.DataFrame(res.json()["data"]["values"], columns=pd.DataFrame(res.json()["data"]["keys"])["name"].tolist()).T temp_df.columns = temp_df.iloc[0, :] temp_df = temp_df.iloc[1:, :] try: temp_df = temp_df[['', '', '', '', '', '', '', '', '', '', '', '']].iloc[-1, :] except: temp_df = temp_df[['', '', '', '', '', '', '', '', '', '', '', '']].iloc[-1, :] big_df[temp_df.name] = temp_df big_df = big_df.T big_df.columns.name = "" big_df = big_df.astype(float) return big_df def _macro_cons_opec_month(): """ -, 20170118- , , :return: pandas.Series \ 2017-01-18 108.0 172.4 54.5 21.3 372.0 463.2 281.2 60.8 154.2 2017-02-13 104.5 165.1 52.7 19.9 377.5 447.6 271.8 67.5 157.6 2017-03-14 105.3 164.1 52.6 19.4 381.4 441.4 270.9 66.9 160.8 2017-04-12 105.6 161.4 52.6 19.8 379.0 440.2 270.2 62.2 154.5 2017-05-11 104.7 169.2 52.4 20.6 375.9 437.3 270.2 55.0 150.8 2017-06-13 105.9 161.3 52.8 20.4 379.5 442.4 270.5 73.0 168.0 2017-07-12 106.0 166.8 52.7 19.7 379.0 450.2 270.9 85.2 173.3 2017-08-10 105.9 164.6 53.6 20.5 382.4 446.8 270.3 100.1 174.8 2017-09-12 106.5 164.6 53.7 17.3 382.8 444.8 270.2 89.0 186.1 2017-10-11 104.6 164.1 53.6 20.1 382.7 449.4 270.0 92.3 185.5 2017-11-13 101.2 171.1 54.1 20.3 382.3 438.3 270.8 96.2 173.8 2017-12-13 101.3 158.1 53.3 19.7 381.8 439.6 270.3 97.3 179.0 2018-01-18 103.7 163.3 52.6 19.7 382.9 440.5 270.0 96.2 186.1 2018-04-12 98.4 152.4 51.8 18.3 381.4 442.6 270.4 96.8 181.0 2018-05-14 99.7 151.5 52.0 18.3 382.3 442.9 270.5 98.2 179.1 2018-06-12 103.1 152.5 51.9 18.9 382.9 445.5 270.1 95.5 171.1 2018-07-11 103.9 143.1 51.9 19.0 379.9 453.3 273.1 70.8 166.0 2018-08-13 106.2 145.6 52.5 18.8 373.7 455.6 279.1 66.4 166.7 2018-09-12 104.5 144.8 52.9 18.7 358.4 464.9 280.2 92.6 172.5 2018-10-11 104.9 151.9 53.1 18.7 344.7 465.0 281.2 105.3 174.8 2018-11-13 105.4 153.3 52.5 18.6 329.6 465.4 276.4 111.4 175.1 2018-12-12 105.2 152.1 52.5 17.6 295.4 463.1 280.9 110.4 173.6 2019-03-14 102.6 145.7 52.2 20.3 274.3 463.3 270.9 90.6 174.1 2019-04-10 101.8 145.4 52.4 21.4 269.8 452.2 270.9 109.8 173.3 2019-06-13 102.9 147.1 52.9 21.1 237.0 472.4 271.0 117.4 173.3 2017-01-18 1047.4 307.1 202.1 3308.5 2017-02-13 994.6 293.1 200.4 3213.9 2017-03-14 979.7 292.5 198.7 3195.8 2017-04-12 999.4 289.5 197.2 3192.8 2017-05-11 995.4 284.2 195.6 3173.2 2017-06-13 994.0 288.5 196.3 3213.9 2017-07-12 995.0 289.8 193.8 3261.1 2017-08-10 1006.7 290.5 193.2 3286.9 2017-09-12 1002.2 290.1 191.8 3275.5 2017-10-11 997.5 290.5 189.0 3274.8 2017-11-13 1000.0 291.1 186.3 3258.9 2017-12-13 999.6 288.3 183.4 3244.8 2018-01-18 991.8 287.8 174.5 3241.6 2018-04-12 993.4 286.4 148.8 3195.8 2018-05-14 995.9 287.2 143.6 3193.0 2018-06-12 998.7 286.5 139.2 3186.9 2018-07-11 1042.0 289.7 134.0 3232.7 2018-08-13 1038.7 295.9 127.8 3232.3 2018-09-12 1040.1 297.2 123.5 3256.5 2018-10-11 1051.2 300.4 119.7 3276.1 2018-11-13 1063.0 316.0 117.1 3290.0 2018-12-12 1101.6 324.6 113.7 3296.5 2019-03-14 1008.7 307.2 100.8 3054.9 2019-04-10 979.4 305.9 73.2 3002.2 2019-06-13 969.0 306.1 74.1 2987.6 """ t = time.time() res = requests.get( JS_CONS_OPEC_URL.format( str(int(round(t * 1000))), str(int(round(t * 1000)) + 90) ) ) json_data = json.loads(res.text[res.text.find("{"): res.text.rfind("}") + 1]) date_list = [item["date"] for item in json_data["list"]] big_df = pd.DataFrame() for country in [item["datas"] for item in json_data["list"]][0].keys(): try: value_list = [item["datas"][country] for item in json_data["list"]] value_df = pd.DataFrame(value_list) value_df.columns = json_data["kinds"] value_df.index = pd.to_datetime(date_list) temp_df = value_df[""] temp_df.name = country big_df = big_df.append(temp_df) except: continue headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_opec_report", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } res = requests.get(f"https://datacenter-api.jin10.com/reports/dates?category=opec&_={str(int(round(t * 1000)))}", headers=headers) # all_date_list = res.json()["data"] need_date_list = [item for item in all_date_list if item.split("-")[0] + item.split("-")[1] + item.split("-")[2] not in date_list] for item in reversed(need_date_list): res = requests.get( f"https://datacenter-api.jin10.com/reports/list?category=opec&date={item}&_={str(int(round(t * 1000)))}", headers=headers) temp_df = pd.DataFrame(res.json()["data"]["values"], columns=pd.DataFrame(res.json()["data"]["keys"])["name"].tolist()).T temp_df.columns = temp_df.iloc[0, :] temp_df = temp_df[['', '', '', '', '', '', '', '', '', '', '', '', '']].iloc[-2, :] big_df[item] = temp_df return big_df.T def macro_cons_opec_month(): """ -, 20170118- , 20200312:fix: https://datacenter.jin10.com/reportType/dc_opec_report :return: pandas.Series \ 2017-01-18 108.0 172.4 54.5 21.3 372.0 463.2 281.2 60.8 154.2 2017-02-13 104.5 165.1 52.7 19.9 377.5 447.6 271.8 67.5 157.6 2017-03-14 105.3 164.1 52.6 19.4 381.4 441.4 270.9 66.9 160.8 2017-04-12 105.6 161.4 52.6 19.8 379.0 440.2 270.2 62.2 154.5 2017-05-11 104.7 169.2 52.4 20.6 375.9 437.3 270.2 55.0 150.8 2017-06-13 105.9 161.3 52.8 20.4 379.5 442.4 270.5 73.0 168.0 2017-07-12 106.0 166.8 52.7 19.7 379.0 450.2 270.9 85.2 173.3 2017-08-10 105.9 164.6 53.6 20.5 382.4 446.8 270.3 100.1 174.8 2017-09-12 106.5 164.6 53.7 17.3 382.8 444.8 270.2 89.0 186.1 2017-10-11 104.6 164.1 53.6 20.1 382.7 449.4 270.0 92.3 185.5 2017-11-13 101.2 171.1 54.1 20.3 382.3 438.3 270.8 96.2 173.8 2017-12-13 101.3 158.1 53.3 19.7 381.8 439.6 270.3 97.3 179.0 2018-01-18 103.7 163.3 52.6 19.7 382.9 440.5 270.0 96.2 186.1 2018-04-12 98.4 152.4 51.8 18.3 381.4 442.6 270.4 96.8 181.0 2018-05-14 99.7 151.5 52.0 18.3 382.3 442.9 270.5 98.2 179.1 2018-06-12 103.1 152.5 51.9 18.9 382.9 445.5 270.1 95.5 171.1 2018-07-11 103.9 143.1 51.9 19.0 379.9 453.3 273.1 70.8 166.0 2018-08-13 106.2 145.6 52.5 18.8 373.7 455.6 279.1 66.4 166.7 2018-09-12 104.5 144.8 52.9 18.7 358.4 464.9 280.2 92.6 172.5 2018-10-11 104.9 151.9 53.1 18.7 344.7 465.0 281.2 105.3 174.8 2018-11-13 105.4 153.3 52.5 18.6 329.6 465.4 276.4 111.4 175.1 2018-12-12 105.2 152.1 52.5 17.6 295.4 463.1 280.9 110.4 173.6 2019-03-14 102.6 145.7 52.2 20.3 274.3 463.3 270.9 90.6 174.1 2019-04-10 101.8 145.4 52.4 21.4 269.8 452.2 270.9 109.8 173.3 2019-06-13 102.9 147.1 52.9 21.1 237.0 472.4 271.0 117.4 173.3 2017-01-18 1047.4 307.1 202.1 3308.5 2017-02-13 994.6 293.1 200.4 3213.9 2017-03-14 979.7 292.5 198.7 3195.8 2017-04-12 999.4 289.5 197.2 3192.8 2017-05-11 995.4 284.2 195.6 3173.2 2017-06-13 994.0 288.5 196.3 3213.9 2017-07-12 995.0 289.8 193.8 3261.1 2017-08-10 1006.7 290.5 193.2 3286.9 2017-09-12 1002.2 290.1 191.8 3275.5 2017-10-11 997.5 290.5 189.0 3274.8 2017-11-13 1000.0 291.1 186.3 3258.9 2017-12-13 999.6 288.3 183.4 3244.8 2018-01-18 991.8 287.8 174.5 3241.6 2018-04-12 993.4 286.4 148.8 3195.8 2018-05-14 995.9 287.2 143.6 3193.0 2018-06-12 998.7 286.5 139.2 3186.9 2018-07-11 1042.0 289.7 134.0 3232.7 2018-08-13 1038.7 295.9 127.8 3232.3 2018-09-12 1040.1 297.2 123.5 3256.5 2018-10-11 1051.2 300.4 119.7 3276.1 2018-11-13 1063.0 316.0 117.1 3290.0 2018-12-12 1101.6 324.6 113.7 3296.5 2019-03-14 1008.7 307.2 100.8 3054.9 2019-04-10 979.4 305.9 73.2 3002.2 2019-06-13 969.0 306.1 74.1 2987.6 """ t = time.time() big_df = pd.DataFrame() headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "cache-control": "no-cache", "origin": "https://datacenter.jin10.com", "pragma": "no-cache", "referer": "https://datacenter.jin10.com/reportType/dc_opec_report", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36", "x-app-id": "rU6QIu7JHe2gOUeR", "x-csrf-token": "", "x-version": "1.0.0", } res = requests.get(f"https://datacenter-api.jin10.com/reports/dates?category=opec&_={str(int(round(t * 1000)))}", headers=headers) # all_date_list = res.json()["data"] bar = tqdm(reversed(all_date_list)) for item in bar: bar.set_description(f"Please wait for a moment, now downing {item}'s data") res = requests.get( f"https://datacenter-api.jin10.com/reports/list?category=opec&date={item}&_={str(int(round(t * 1000)))}", headers=headers) temp_df = pd.DataFrame(res.json()["data"]["values"], columns=pd.DataFrame(res.json()["data"]["keys"])["name"].tolist()).T temp_df.columns = temp_df.iloc[0, :] temp_df = temp_df.iloc[1:, :] try: temp_df = temp_df[['', '', '', '', '', '', '', '', '', '', '', '']].iloc[-2, :] except: temp_df = temp_df[['', '', '', '', '', '', '', '', '', '', '', '']].iloc[-1, :] big_df[temp_df.name] = temp_df big_df = big_df.T big_df.columns.name = "" big_df = big_df.astype(float) return big_df if __name__ == "__main__": macro_cons_gold_volume_df = macro_cons_gold_volume() print(macro_cons_gold_volume_df) macro_cons_gold_change_df = macro_cons_gold_change() print(macro_cons_gold_change_df) macro_cons_gold_amount_df = macro_cons_gold_amount() print(macro_cons_gold_amount_df) print(pd.concat([macro_cons_gold_volume_df, macro_cons_gold_change_df, macro_cons_gold_amount_df], axis=1)) macro_cons_silver_volume_df = macro_cons_silver_volume() print(macro_cons_silver_volume_df) macro_cons_silver_change_df = macro_cons_silver_change() print(macro_cons_silver_change_df) macro_cons_silver_amount_df = macro_cons_silver_amount() print(macro_cons_silver_amount_df) print(pd.concat([macro_cons_silver_volume_df, macro_cons_silver_change_df, macro_cons_silver_amount_df], axis=1)) macro_cons_opec_near_change_df = macro_cons_opec_near_change() print(macro_cons_opec_near_change_df) macro_cons_opec_month_df = macro_cons_opec_month() print(macro_cons_opec_month_df)
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 2, 1220, 14629, 14, 8800, 14, 24330, 21015, 198, 37811, 198, 10430, 25, 13130, 14, 940, 14, 2481, 1105, 25, 2919, 198, 24564, 25, 11420, 198, 198, 37811, 198, 11748, 33918,...
1.855357
18,480
############################################################################## # Written by: Cachen Chen <cachen@novell.com> # Date: 08/06/2008 # Description: Application wrapper for scrollbar.py # Used by the scrollbar-*.py tests ##############################################################################$ 'Application wrapper for scrollbar' from strongwind import * from os.path import exists from sys import path def launchScrollBar(exe=None): 'Launch ScrollBar with accessibility enabled and return a scrollbar object. Log an error and return None if something goes wrong' if exe is None: # make sure we can find the sample application harness_dir = path[0] i = harness_dir.rfind("/") j = harness_dir[:i].rfind("/") uiaqa_path = harness_dir[:j] if uiaqa_path is None: raise IOError, "When launching an application you must provide the "\ "full path or set the\nUIAQA_HOME environment "\ "variable." exe = '%s/samples/winforms/scrollbar.py' % uiaqa_path if not os.path.exists(exe): raise IOError, "%s does not exist" % exe args = [exe] (app, subproc) = cache.launchApplication(args=args, name='ipy', wait=config.LONG_DELAY) scrollbar = ScrollBar(app, subproc) cache.addApplication(scrollbar) scrollbar.scrollBarFrame.app = scrollbar return scrollbar # class to represent the application
[ 198, 29113, 29113, 7804, 4242, 2235, 198, 2, 22503, 416, 25, 220, 327, 330, 831, 12555, 1279, 66, 330, 831, 31, 77, 659, 297, 13, 785, 29, 198, 2, 7536, 25, 220, 220, 220, 220, 220, 220, 220, 8487, 14, 3312, 14, 11528, 198, 2, ...
2.738095
546
import json from os import path from tweepy import OAuthHandler, Stream from tweepy.streaming import StreamListener from sqlalchemy.orm.exc import NoResultFound from database import session, Tweet, Hashtag, User consumer_key = "0qFf4T2xPWVIycLmAwk3rDQ55" consumer_secret = "LcHpujASn4fIIrQ8sikbCTQ3oyU6T6opchFVWBBqwICahzSE64" access_token = "4271002872-XLo7TNnE3qvYevqLmT1RBuiJ5CJ3o0DCr3WReAT" acces_token_secret = "ulZ3dA25zuC6BGJgaFowCSTIm6gKVtOa4x9y7tO0IUDIx" auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, acces_token_secret)
[ 11748, 33918, 198, 6738, 28686, 1330, 3108, 198, 198, 6738, 4184, 538, 88, 1330, 440, 30515, 25060, 11, 13860, 198, 6738, 4184, 538, 88, 13, 5532, 278, 1330, 13860, 33252, 198, 198, 6738, 44161, 282, 26599, 13, 579, 13, 41194, 1330, 1...
2.257813
256
from flask import render_template, jsonify from app import app import random
[ 6738, 42903, 1330, 8543, 62, 28243, 11, 33918, 1958, 198, 6738, 598, 1330, 598, 198, 11748, 4738, 628, 628, 628 ]
4.1
20
# encoding: utf-8 ''' @author: yangsen @license: @contact: @software: @file: numpy_mat.py @time: 18-8-25 9:56 @desc: ''' import numpy as np a = np.arange(9).reshape(3,3) # a[1] a[[1,2]] a[np.array([1,2])] # a[:,1] a[:,[1,2]] a[:,np.array([1,2])]
[ 2, 21004, 25, 3384, 69, 12, 23, 198, 7061, 6, 198, 31, 9800, 25, 331, 648, 6248, 198, 31, 43085, 25, 198, 31, 32057, 25, 198, 31, 43776, 25, 198, 31, 7753, 25, 299, 32152, 62, 6759, 13, 9078, 198, 31, 2435, 25, 1248, 12, 23, ...
1.77305
141
import copy from typing import Callable, Dict, List, Optional import torch import torch.nn as nn import torch.optim as optim from ai_traineree import DEVICE from ai_traineree.agents import AgentBase from ai_traineree.agents.agent_utils import soft_update from ai_traineree.buffers import NStepBuffer, PERBuffer from ai_traineree.buffers.buffer_factory import BufferFactory from ai_traineree.loggers import DataLogger from ai_traineree.networks.heads import RainbowNet from ai_traineree.types import ActionType, AgentState, BufferState, DoneType, NetworkState, ObsType, RewardType from ai_traineree.types.dataspace import DataSpace from ai_traineree.utils import to_numbers_seq, to_tensor def act(self, obs: ObsType, eps: float = 0.) -> int: """ Returns actions for given state as per current policy. Parameters: state: Current available state from the environment. epislon: Epsilon value in the epislon-greedy policy. """ # Epsilon-greedy action selection if self._rng.random() < eps: # TODO: Update with action_space.sample() once implemented assert len(self.action_space.shape) == 1, "Only 1D is supported right now" return self._rng.randint(self.action_space.low, self.action_space.high) t_obs = to_tensor(self.state_transform(obs)).float().unsqueeze(0).to(self.device) self.dist_probs = self.net.act(t_obs) q_values = (self.dist_probs * self.z_atoms).sum(-1) return int(q_values.argmax(-1)) # Action maximizes state-action value Q(s, a) def learn(self, experiences: Dict[str, List]) -> None: """ Parameters: experiences: Contains all experiences for the agent. Typically sampled from the memory buffer. Five keys are expected, i.e. `state`, `action`, `reward`, `next_state`, `done`. Each key contains a array and all arrays have to have the same length. """ rewards = to_tensor(experiences['reward']).float().to(self.device) dones = to_tensor(experiences['done']).type(torch.int).to(self.device) states = to_tensor(experiences['state']).float().to(self.device) next_states = to_tensor(experiences['next_state']).float().to(self.device) actions = to_tensor(experiences['action']).type(torch.long).to(self.device) assert rewards.shape == dones.shape == (self.batch_size, 1) assert states.shape == next_states.shape == (self.batch_size,) + self.obs_space.shape assert actions.shape == (self.batch_size, 1) # Discrete domain with torch.no_grad(): prob_next = self.target_net.act(next_states) q_next = (prob_next * self.z_atoms).sum(-1) * self.z_delta if self.using_double_q: duel_prob_next = self.net.act(next_states) a_next = torch.argmax((duel_prob_next * self.z_atoms).sum(-1), dim=-1) else: a_next = torch.argmax(q_next, dim=-1) prob_next = prob_next[self.__batch_indices, a_next, :] m = self.net.dist_projection(rewards, 1 - dones, self.gamma ** self.n_steps, prob_next) assert m.shape == (self.batch_size, self.num_atoms) log_prob = self.net(states, log_prob=True) assert log_prob.shape == (self.batch_size,) + self.action_size + (self.num_atoms,) log_prob = log_prob[self.__batch_indices, actions.squeeze(), :] assert log_prob.shape == m.shape == (self.batch_size, self.num_atoms) # Cross-entropy loss error and the loss is batch mean error = -torch.sum(m * log_prob, 1) assert error.shape == (self.batch_size,) loss = error.mean() assert loss >= 0 self.optimizer.zero_grad() loss.backward() nn.utils.clip_grad_norm_(self.net.parameters(), self.max_grad_norm) self.optimizer.step() self._loss = float(loss.item()) if hasattr(self.buffer, 'priority_update'): assert (~torch.isnan(error)).any() self.buffer.priority_update(experiences['index'], error.detach().cpu().numpy()) # Update networks - sync local & target soft_update(self.target_net, self.net, self.tau) def state_dict(self) -> Dict[str, dict]: """Returns agent's state dictionary. Returns: State dicrionary for internal networks. """ return {"net": self.net.state_dict(), "target_net": self.target_net.state_dict()} def get_state(self) -> AgentState: """Provides agent's internal state.""" return AgentState( model=self.model, obs_space=self.obs_space, action_space=self.action_space, config=self._config, buffer=copy.deepcopy(self.buffer.get_state()), network=copy.deepcopy(self.get_network_state()), ) def save_state(self, path: str) -> None: """Saves agent's state into a file. Parameters: path: String path where to write the state. """ agent_state = self.get_state() torch.save(agent_state, path) def load_state(self, path: str) -> None: """Loads state from a file under provided path. Parameters: path: String path indicating where the state is stored. """ agent_state = torch.load(path) self._config = agent_state.get('config', {}) self.__dict__.update(**self._config) self.net.load_state_dict(agent_state['net']) self.target_net.load_state_dict(agent_state['target_net']) def save_buffer(self, path: str) -> None: """Saves data from the buffer into a file under provided path. Parameters: path: String path where to write the buffer. """ import json dump = self.buffer.dump_buffer(serialize=True) with open(path, 'w') as f: json.dump(dump, f) def load_buffer(self, path: str) -> None: """Loads data into the buffer from provided file path. Parameters: path: String path indicating where the buffer is stored. """ import json with open(path, 'r') as f: buffer_dump = json.load(f) self.buffer.load_buffer(buffer_dump)
[ 11748, 4866, 198, 6738, 19720, 1330, 4889, 540, 11, 360, 713, 11, 7343, 11, 32233, 198, 198, 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 11748, 28034, 13, 40085, 355, 6436, 198, 198, 6738, 257, 72, 62, 27432, 45316,...
2.359911
2,684
from pycu.nvvm import (get_libdevice, ir_version, version, add_module_to_program, compile_program, create_program, destroy_program, get_compiled_result, get_compiled_result_size, get_program_log, get_program_log_size, lazy_add_module_to_program, verify_program) import os import sys from ctypes import c_char_p import weakref
[ 6738, 12972, 27399, 13, 48005, 14761, 1330, 357, 1136, 62, 8019, 25202, 11, 4173, 62, 9641, 11, 2196, 11, 751, 62, 21412, 62, 1462, 62, 23065, 11, 17632, 62, 23065, 11, 198, 197, 197, 197, 197, 197, 220, 220, 2251, 62, 23065, 11, ...
2.834711
121
# Copyright (c) 2022, itsdve GmbH and Contributors # See license.txt # import frappe import unittest
[ 2, 15069, 357, 66, 8, 33160, 11, 663, 67, 303, 402, 2022, 39, 290, 25767, 669, 198, 2, 4091, 5964, 13, 14116, 198, 198, 2, 1330, 5306, 27768, 198, 11748, 555, 715, 395, 198 ]
3
34
# -*- coding: utf-8 -*- """ Created on Sun Nov 21 14:51:01 2021 @author: 75638 """ import pandas as pd import numpy as np pd.set_option('display.max_columns', None) pd.set_option('display.width', 10000) def process_data(path1,path2): ''' 1.path1: file path of different factor 2.path2:file path of SP500members 3.remove anomalies 4.normalized data 5.fill NaN with 0 ''' #read factor.xlsx factor=pd.read_excel(path1,index_col=0) #remove anomalies which is greater than median+5*std or less than median-s*std for date in factor: median=factor[date].quantile(0.5) std=factor[date].std() min=median-5*std max=median+5*std factor[date]=factor[date].clip(min,max) #normalize data for date in factor: mean=factor[date].mean() std=factor[date].std() factor[date]=(factor[date]-mean)/std # fill NAN for date in factor: median=factor[date].quantile(0.5) factor.fillna(median,inplace=True) #read SP500 member datas member=pd.read_excel(path2,index_col=0) #merge industry data factor=pd.merge(member,factor,left_index=True,right_index=True) # save processed data factor.to_csv('C:\\Users\\75638\\OneDrive - UW\\Desktop\\703project\\data\\volatility.csv') return factor if __name__ == '__main__': path1='C:\\Users\\75638\\OneDrive - UW\\Desktop\\703project\\original_data\\volatility.xlsx' path2='C:\\Users\\75638\\OneDrive - UW\\Desktop\\703project\\SP500\\SP500members.xlsx' data=process_data(path1,path2)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 201, 198, 37811, 201, 198, 41972, 319, 3825, 5267, 2310, 1478, 25, 4349, 25, 486, 33448, 201, 198, 201, 198, 31, 9800, 25, 767, 3980, 2548, 201, 198, 37811, 201, 198, 11748...
2.276536
716
import pytest from pathlib import Path from blendtorch import btt BLENDDIR = Path(__file__).parent/'blender'
[ 11748, 12972, 9288, 198, 6738, 3108, 8019, 1330, 10644, 198, 6738, 13516, 13165, 354, 1330, 275, 926, 198, 198, 9148, 10619, 34720, 796, 10644, 7, 834, 7753, 834, 737, 8000, 14, 6, 2436, 2194, 6, 628, 628, 198 ]
3
38
VERSION = (0, 9, 5)
[ 43717, 796, 357, 15, 11, 860, 11, 642, 8, 198 ]
2
10
# Copyright 2020 Google LLC. # # 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 the copyright holder 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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. r"""Create a visual report of make_examples runtime by region. Use this script to visualize the runtime-by-region data generated by running make_examples with --runtime_by_region. """ from typing import Dict, Sequence, List, Tuple, Text, Any, Union from absl import app from absl import flags import altair as alt import pandas as pd import tensorflow as tf from third_party.nucleus.io import sharded_file_utils # Altair uses a lot of method chaining, such as # chart.mark_bar().encode(...).properties(...), so using backslash # continuation to break this into separate lines makes the code more readable. # pylint: disable=g-backslash-continuation VEGA_URL = 'https://storage.googleapis.com/deepvariant/lib/vega' FLAGS = flags.FLAGS flags.DEFINE_string( 'input', None, 'TSV file that was produced when running make_examples ' 'with --runtime_by_region. Can be sharded, e.g. /path/runtime@64.tsv.') flags.DEFINE_string( 'title', None, 'Title will be shown at the top of the report and will ' 'be used as a prefix for downloaded image files.') flags.DEFINE_string('output', 'runtime_by_region_report.html', 'Path for the output report, which will be an html file.') RUNTIME_COLUMNS = [ 'get reads', 'find candidates', 'make pileup images', 'write outputs' ] COUNT_COLUMNS = ['num reads', 'num candidates', 'num examples'] CSS_STYLES = """ <style> body { font-family: sans-serif; } .chart-container { padding: 30px; } </style> """ def read_sharded_runtime_tsvs(path_string: str) -> pd.DataFrame: """Imports data from a single or sharded path into a pandas dataframe. Args: path_string: The path to the input file, which may be sharded. Returns: A dataframe matching the TSV file(s) but with added Task column. """ if sharded_file_utils.is_sharded_file_spec(path_string): paths = sharded_file_utils.generate_sharded_filenames(path_string) else: paths = [path_string] list_of_dataframes = [] for i, path in enumerate(paths): if path.startswith('gs://'): # Once pandas is updated to 0.24+, pd.read_csv will work for gs:// # without this workaround. with tf.io.gfile.GFile(path) as f: d = pd.read_csv(f, sep='\t') else: d = pd.read_csv(path, sep='\t') d['Task'] = i list_of_dataframes.append(d) return pd.concat(list_of_dataframes, axis=0, ignore_index=True) def format_runtime_string(raw_seconds: float) -> str: """Creates a nice format string from a potentially large number of seconds. Args: raw_seconds: A number of seconds. Returns: The seconds divided into hours, minutes, and remaining seconds, formatted nicely. For example, 2h3m5.012s. """ minutes, seconds = divmod(raw_seconds, 60) hours, minutes = divmod(minutes, 60) seconds = round(seconds, 3) output = '' if hours > 0: output += f'{int(hours)}h' if minutes > 0: output += f'{int(minutes)}m' if seconds > 0 or not output: output += f'{seconds}s' return output def calculate_totals(df: pd.DataFrame) -> pd.DataFrame: """Calculates total runtime, formats it nicely, and sorts by it. Args: df: A dataframe of runtime profiling numbers. Returns: The same dataframe with some additional summary columns. """ # 'total runtime' is a simple sum of the runtime columns. df['total runtime'] = df[RUNTIME_COLUMNS].sum(axis=1) # Create a formatted runtime string for tooltips. df['Runtime'] = df['total runtime'].apply(format_runtime_string) # Sort by descending total region runtime. df.sort_values(by='total runtime', inplace=True, ascending=False) return df def summarize_by_task(df: pd.DataFrame) -> pd.DataFrame: """Groups regions to get the total runtime for each task. Args: df: A dataframe of runtime profiling numbers. Returns: The dataframe grouped by task. """ by_task = df.groupby(by=['Task']).sum() return by_task.reset_index() def stage_histogram(d: pd.DataFrame, title: str = '') -> alt.Chart: """Plots a histogram of runtimes stacked by stage. Args: d: A dataframe of runtimes, either by region or by task. title: A title for the plot. Returns: An altair chart. """ columns_used = RUNTIME_COLUMNS d = d[columns_used] return alt.Chart(d).transform_fold( RUNTIME_COLUMNS, as_=['Stage', 'runtime_by_stage']) \ .mark_bar(opacity=0.3) \ .encode( x=alt.X('runtime_by_stage:Q', bin=alt.Bin(maxbins=100), title='Runtime (seconds)'), y=alt.Y('count()', title='Count of regions', stack=None), color=alt.Color('Stage:N', sort=None) ).properties(title=title) def correlation_scatter_charts(d: pd.DataFrame, title: str = '') -> alt.Chart: """Produces a grid of scatter plots of runtimes of stages versus covariates. Args: d: A pandas dataframe of runtime by regions. title: A title for the plot. Returns: An altair chart """ columns_used = ['region', 'total runtime'] + RUNTIME_COLUMNS + COUNT_COLUMNS d = d[columns_used] return alt.Chart(d).mark_circle(opacity=0.1).encode( x=alt.X(alt.repeat('column'), type='quantitative', axis=alt.Axis(labelExpr="datum.value + 's'")), y=alt.Y(alt.repeat('row'), type='quantitative'), tooltip='region' ).properties(width=100, height=100) \ .repeat( column=['total runtime'] + RUNTIME_COLUMNS, row=COUNT_COLUMNS, ).properties(title=title) def totals_by_stage(d: pd.DataFrame) -> alt.Chart: """Plots total runtimes for each stage. Args: d: A dataframe of runtimes. Returns: An altair chart. """ stage_totals_series = d.sum()[RUNTIME_COLUMNS] stage_totals = pd.DataFrame( stage_totals_series, columns=['Runtime (seconds)']) stage_totals.reset_index(inplace=True) stage_totals = stage_totals.rename(columns={'index': 'Stage'}) stage_totals['Runtime'] = stage_totals['Runtime (seconds)'].apply( format_runtime_string) return alt.Chart(stage_totals).mark_bar().encode( x='Runtime (seconds)', y=alt.Y('Stage', sort=None), tooltip=['Runtime'], fill=alt.Fill('Stage', sort=None)).properties(title='Overall runtime by stage') def pareto_by_task_tooltip(row: pd.Series) -> str: """For one row of a dataframe, computes a tooltip description. Args: row: A Pandas Series, one row of a dataframe containing some specific cumulative sum columns. Returns: A string to show as the tooltip for a pareto curve. """ return (f"{row['task cumsum order'] * 100:.2f}% of regions " f"account for {row['task cumsum fraction'] * 100:.2f}% of " f"the runtime in task {row['Task']}") def calculate_pareto_metrics(df_subset: pd.DataFrame) -> pd.DataFrame: """Calculates cumulative sums for a subset of a dataframe. Args: df_subset: A dataframe subset of one task. Returns: The same dataframe subset with some additional columns. """ # These are the same for all regions in the same task, for the scatter plot: df_subset['task total runtime'] = df_subset['total runtime'].sum() df_subset['Runtime for task'] = df_subset['task total runtime'].apply( format_runtime_string) df_subset['task num examples'] = df_subset['num examples'].sum() # These are cumulative sums for the pareto curves: df_subset['task cumsum fraction'] = df_subset['total runtime'].cumsum( ) / df_subset['total runtime'].sum() n = len(df_subset) df_subset['task cumsum order'] = list(map(lambda x: x / n, range(0, n))) df_subset['tooltip'] = df_subset.apply(pareto_by_task_tooltip, axis=1) return df_subset def pareto_and_runtimes_by_task(df: pd.DataFrame) -> alt.Chart: """Creates an interactive Pareto curve and scatter plot of task runtimes. Tracing each curve shows to what extent a small proportion of long-running regions contribute disproportionately to the overall runtime. That is, "The longest-running X% of regions account for Y% of the total runtime." There is a curve for each task. Args: df: A dataframe of all regions. Returns: An altair chart. """ grouped = df.groupby(df['Task'], sort=False) df = grouped.apply(calculate_pareto_metrics) # Sample along the Pareto curve, ensuring the longest regions are shown. if len(df) > 5000: x = 1000 df = pd.concat([df.nlargest(x, 'total runtime'), df.sample(5000 - x)]) # Limit columns to greatly reduce the size of the html report. columns_used = [ 'task cumsum order', 'task cumsum fraction', 'tooltip', 'Task', 'task total runtime', 'task num examples', 'Runtime for task' ] df = df[columns_used] # Brushing on the task_scatter plot highlights the same tasks in the Pareto # curve. brush = alt.selection_interval() pareto_by_task = alt.Chart(df).mark_line(size=2).encode( x=alt.X( 'task cumsum order', title='The longest-runtime X% of regions', axis=alt.Axis(format='%')), y=alt.Y( 'task cumsum fraction', title='Account for Y% of the total runtime', axis=alt.Axis(format='%')), tooltip='tooltip', color=alt.condition(brush, 'Task:N', alt.value('lightgray'))).properties( title='Pareto curve for each task').interactive() # This chart needs to use the same dataframe as the first chart to enable the # brushing on one to affect the other. Using max(task) for 'text' is a # trick that causes bundling by task to avoid showing multiple overlapping # points which otherwise make the text look funky. task_scatter = alt.Chart(df).mark_point(size=10).encode( x=alt.X('max(task total runtime)', title='Runtime (seconds)'), y=alt.Y('task num examples:Q', title='Number of examples'), color=alt.condition(brush, 'Task:N', alt.value('lightgray')), tooltip=['Task', 'Runtime for task'] ) \ .properties(title='Total runtime for each task (drag to highlight)') \ .add_selection(brush) return pareto_by_task | task_scatter def individual_region_bars(small_df: pd.DataFrame, title: Union[str, Dict[str, str]] = '') -> alt.Chart: """Makes a stacked bar chart with runtime of each stage for individual regions. Args: small_df: A dataframe of regions, each of which will be shown as a bar. title: A title for the plot. If a dict, it should contain 'title' and/or 'subtitle'. Returns: An altair chart. """ columns_used = ['region', 'Runtime'] + RUNTIME_COLUMNS d = small_df[columns_used] return alt.Chart(d).transform_fold( RUNTIME_COLUMNS, as_=['Stage', 'runtime_by_stage']) \ .mark_bar().encode( x=alt.X('region:N', sort=None), y=alt.Y('runtime_by_stage:Q', scale=alt.Scale(type='linear'), title='Runtime (seconds)'), fill=alt.Fill('Stage:N', sort=None), tooltip='Runtime:N' ).properties(title=title) def selected_longest_and_median_regions(df: pd.DataFrame) -> alt.Chart: """Creates a stacked bar charts of the top 20 and median 20 regions. Args: df: A dataframe of all regions. Returns: An altair chart. """ num_rows = len(df) mid = round(num_rows / 2) return individual_region_bars(df.iloc[0:20], 'Top runtime regions') \ | individual_region_bars(df.iloc[mid-10:mid+11], 'Median runtime regions') def top_regions_producing_zero_examples(df: pd.DataFrame) -> alt.Chart: """Creates a chart of the top regions that produced zero examples. Args: df: A dataframe of all regions. Returns: An altair chart. """ regions_with_zero_examples = df[df['num examples'] == 0] runtime_of_zeros = regions_with_zero_examples['total runtime'].sum() / 3600 total_runtime = df['total runtime'].sum() / 3600 subtitle = ( f'Spent {runtime_of_zeros:.2f} hours processing the ' f'{len(regions_with_zero_examples)} regions that produced no examples, ' f'which is {runtime_of_zeros / total_runtime * 100:.2f}% of the total ' f'runtime of {total_runtime:.2f} hours.') return individual_region_bars( regions_with_zero_examples.nlargest(50, 'total runtime'), title={ 'text': 'The longest-running regions that produced no examples', 'subtitle': subtitle }) def write_to_html_report(charts: List[Dict[Text, alt.Chart]], title: str, subtitle: str, html_output: Any) -> None: """Makes the html report with all the charts inserted. Args: charts: A list of altair chart objects. title: The title to show at the top of the report. subtitle: The subtitle to show just below the title on the report. html_output: a writable file object. Returns: None. Writes into the html_output file object. """ # Start the HTML document. html_output.write('<!DOCTYPE html>\n<html>\n<head>') # Add dependencies vega and vega-lite, which render the altair charts. html_output.write('<script type="text/javascript" src="{}/vega@5"></script>' '\n'.format(VEGA_URL)) html_output.write( '<script type="text/javascript" src="{}/vega-lite@4.8.1"></script>' '\n'.format(VEGA_URL)) html_output.write( '<script type="text/javascript" src="{}/vega-embed@6"></script>' '\n'.format(VEGA_URL)) # Add styles (CSS). html_output.write(CSS_STYLES) html_output.write('</head>\n<body>') html_output.write('<h1>{}</h1>\n'.format(title)) html_output.write('<h2>{}</h2>\n'.format(subtitle)) # Make a div containing all the charts. html_output.write('<div>') for chart in charts: html_output.write( '<div class="chart-container" id="vis_{}"></div>\n'.format(chart['id'])) html_output.write('</div>') # Add JSON vega specs and hook them up to the divs with VegaEmbed. html_output.write('<script>\n') for chart in charts: html_output.write('var spec_{} = {};\n'.format(chart['id'], chart['chart'].to_json())) download_filename = '{}_{}'.format(title.replace(' ', '_'), chart['id']) embed_options = {'mode': 'vega-lite', 'downloadFileName': download_filename} html_output.write('vegaEmbed("#vis_{}", spec_{}, {})\n'.format( chart['id'], chart['id'], embed_options)) html_output.write('</script>\n') # Close HTML document. html_output.write('</body></html>') def read_data_and_make_dataframes( input_path: str) -> Tuple[pd.DataFrame, pd.DataFrame]: """Loads data from a file into one dataframe as-is and one by task. Args: input_path: str, path of the input TSV file (may be sharded). Returns: df: A dataframe with one row per region. by_task: A dataframe with one row per task. """ df = read_sharded_runtime_tsvs(input_path) df = calculate_totals(df) by_task = summarize_by_task(df) return df, by_task def make_all_charts( df: pd.DataFrame, by_task: pd.DataFrame) -> List[Dict[Text, Union[str, alt.Chart]]]: """Creates charts and puts them in a list with their ID names. Args: df: A dataframe with one row per region. by_task: A dataframe with one row per task. Returns: list of dicts, each containing a chart and a descriptive ID. """ charts = [{ 'id': 'total_by_stage', 'chart': totals_by_stage(by_task) }, { 'id': 'pareto_and_runtimes_by_task', 'chart': pareto_and_runtimes_by_task(df) }, { 'id': 'histogram_by_task', 'chart': stage_histogram(by_task, title='Stage runtimes for each task') }, { 'id': 'selected_longest_and_median_regions', 'chart': selected_longest_and_median_regions(df) }, { 'id': 'zero_examples', 'chart': top_regions_producing_zero_examples(df) }] # Altair shows a max of 5000 data points. if len(df) <= 5000: # With up to 5000 points, just show them all. charts.extend([{ 'id': 'histogram', 'chart': stage_histogram(df, title='Runtime by stage for all regions') }, { 'id': 'scatter_grid', 'chart': correlation_scatter_charts(df, title='Trends for all regions') }]) else: # With too many points, make different subsets to show trends better. top_100 = df.nlargest(100, 'total runtime') top_5000 = df.nlargest(5000, 'total runtime') # Sample the bottom 99% to avoid outliers that obscure general trends. bottom_99_percent = df.nsmallest(int(len(df) * .99), 'total runtime') if len(bottom_99_percent) > 5000: bottom_99_percent = bottom_99_percent.sample(5000) charts.extend([{ 'id': 'histogram_bottom_99_percent', 'chart': stage_histogram( bottom_99_percent, title='Runtime by stage for regions in the bottom 99%') }, { 'id': 'histogram_top_100', 'chart': stage_histogram( top_100, title='Runtime by stage for regions in the top 100') }, { 'id': 'scatter_grid_top_5000', 'chart': correlation_scatter_charts( top_5000, title='Trends for regions in the top 5000') }, { 'id': 'scatter_grid_bottom_99_percent', 'chart': correlation_scatter_charts( bottom_99_percent, title='Trends for regions in the bottom 99%') }]) return charts def make_report(input_path: str, title: str, html_output: tf.io.gfile.GFile) -> None: """Reads data, creates charts, and composes the charts into an HTML report. Args: input_path: Path of the input TSV file (or sharded files). title: Title to put at the top of the report. html_output: Writable file object where output will be written. """ # Load data into pandas dataframes and add summary columns. df, by_task = read_data_and_make_dataframes(input_path) # Build all the charts. charts = make_all_charts(df, by_task) # Write a subtitle with some top-level stats. subtitle = (f'Runtime profiling for make_examples on {len(df)} regions ' f'across {len(by_task)} task{"(s)" if len(by_task) > 1 else ""}') # Write the HTML report with all the charts. write_to_html_report( charts=charts, title=title, subtitle=subtitle, html_output=html_output) if __name__ == '__main__': flags.mark_flags_as_required(['input', 'title']) app.run(main)
[ 2, 15069, 12131, 3012, 11419, 13, 198, 2, 198, 2, 2297, 396, 3890, 290, 779, 287, 2723, 290, 13934, 5107, 11, 351, 393, 1231, 198, 2, 17613, 11, 389, 10431, 2810, 326, 262, 1708, 3403, 198, 2, 389, 1138, 25, 198, 2, 198, 2, 352,...
2.6643
7,465
import sys import unittest from dynd import nd, ndt """ class TestFields(unittest.TestCase): def test_simple(self): a = nd.array([ (1, 2, 'a', 'b'), (3, 4, 'ab', 'cd'), (5, 6, 'def', 'ghi')], type='3 * {x: int32, y: int32, z: string, w: string}') # Selecting a single field b = nd.fields(a, 'x') self.assertEqual(nd.dtype_of(b), ndt.make_struct( [ndt.int32], ['x'])) self.assertEqual(nd.as_py(b.x), nd.as_py(a.x)) # Selecting two fields b = nd.fields(a, 'z', 'y') self.assertEqual(nd.dtype_of(b), ndt.make_struct( [ndt.string, ndt.int32], ['z', 'y'])) self.assertEqual(nd.as_py(b.z), nd.as_py(a.z)) self.assertEqual(nd.as_py(b.y), nd.as_py(a.y)) # Selecting three fields b = nd.fields(a, 'w', 'y', 'z') self.assertEqual(nd.dtype_of(b), ndt.make_struct( [ndt.string, ndt.int32, ndt.string], ['w', 'y', 'z'])) self.assertEqual(nd.as_py(b.w), nd.as_py(a.w)) self.assertEqual(nd.as_py(b.y), nd.as_py(a.y)) self.assertEqual(nd.as_py(b.z), nd.as_py(a.z)) # Reordering all four fields b = nd.fields(a, 'w', 'y', 'x', 'z') self.assertEqual(nd.dtype_of(b), ndt.make_struct( [ndt.string, ndt.int32, ndt.int32, ndt.string], ['w', 'y', 'x', 'z'])) self.assertEqual(nd.as_py(b.w), nd.as_py(a.w)) self.assertEqual(nd.as_py(b.y), nd.as_py(a.y)) self.assertEqual(nd.as_py(b.x), nd.as_py(a.x)) self.assertEqual(nd.as_py(b.z), nd.as_py(a.z)) def test_fixed_var(self): a = nd.array([ [(1, 2, 'a', 'b'), (3, 4, 'ab', 'cd')], [(5, 6, 'def', 'ghi')], [(7, 8, 'alpha', 'beta'), (9, 10, 'X', 'Y'), (11, 12, 'the', 'end')]], type='3 * var * {x: int32, y: int32, z: string, w: string}') # Selecting a single field b = nd.fields(a, 'x') self.assertEqual(nd.type_of(b), ndt.make_fixed_dim(3, ndt.make_var_dim(ndt.make_struct( [ndt.int32], ['x'])))) self.assertEqual(nd.as_py(b.x), nd.as_py(a.x)) # Selecting two fields b = nd.fields(a, 'z', 'y') self.assertEqual(nd.type_of(b), ndt.make_fixed_dim(3, ndt.make_var_dim(ndt.make_struct( [ndt.string, ndt.int32], ['z', 'y'])))) self.assertEqual(nd.as_py(b.z), nd.as_py(a.z)) self.assertEqual(nd.as_py(b.y), nd.as_py(a.y)) # Selecting three fields b = nd.fields(a, 'w', 'y', 'z') self.assertEqual(nd.type_of(b), ndt.make_fixed_dim(3, ndt.make_var_dim(ndt.make_struct( [ndt.string, ndt.int32, ndt.string], ['w', 'y', 'z'])))) self.assertEqual(nd.as_py(b.w), nd.as_py(a.w)) self.assertEqual(nd.as_py(b.y), nd.as_py(a.y)) self.assertEqual(nd.as_py(b.z), nd.as_py(a.z)) # Reordering all four fields b = nd.fields(a, 'w', 'y', 'x', 'z') self.assertEqual(nd.type_of(b), ndt.make_fixed_dim(3, ndt.make_var_dim(ndt.make_struct( [ndt.string, ndt.int32, ndt.int32, ndt.string], ['w', 'y', 'x', 'z'])))) self.assertEqual(nd.as_py(b.w), nd.as_py(a.w)) self.assertEqual(nd.as_py(b.y), nd.as_py(a.y)) self.assertEqual(nd.as_py(b.x), nd.as_py(a.x)) self.assertEqual(nd.as_py(b.z), nd.as_py(a.z)) def test_bad_field_name(self): a = nd.array([ (1, 2, 'a', 'b'), (3, 4, 'ab', 'cd'), (5, 6, 'def', 'ghi')], type='3 * {x: int32, y: int32, z: string, w: string}') self.assertRaises(RuntimeError, nd.fields, a, 'y', 'v') """ if __name__ == '__main__': unittest.main()
[ 11748, 25064, 198, 11748, 555, 715, 395, 198, 6738, 20268, 358, 1330, 299, 67, 11, 299, 28664, 198, 198, 37811, 198, 4871, 6208, 15878, 82, 7, 403, 715, 395, 13, 14402, 20448, 2599, 198, 220, 220, 220, 825, 1332, 62, 36439, 7, 944, ...
1.590841
2,664
from typing import Union, Iterable, List import numpy as np import pandas as pd from ..models._transformer import _ArrayTransformer, _MultiArrayTransformer
[ 6738, 19720, 1330, 4479, 11, 40806, 540, 11, 7343, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 198, 6738, 11485, 27530, 13557, 7645, 16354, 1330, 4808, 19182, 8291, 16354, 11, 4808, 29800, 19182, 8291, ...
3.697674
43
import os import sys import lipd # import pythonAdapter, assumes in ../python-adapter/ tests_dir = os.path.dirname(os.path.realpath(__file__)) fc_dir = os.path.dirname(tests_dir) python_adapter_dir = os.path.join(fc_dir, "python-adapter") sys.path.append(python_adapter_dir) import adapter # have to call adapter in the adapter.py file as adapter.adapter adapter = adapter.global_adapter adapter.register(fake_model) adapter.start_server()
[ 11748, 28686, 198, 11748, 25064, 198, 11748, 10645, 67, 198, 198, 2, 1330, 21015, 47307, 11, 18533, 287, 11485, 14, 29412, 12, 324, 3429, 14, 198, 41989, 62, 15908, 796, 28686, 13, 6978, 13, 15908, 3672, 7, 418, 13, 6978, 13, 5305, ...
2.88961
154
from PIL import Image from PIL import ImageTk import tkinter as tki from tkinter import Toplevel, Scale import threading import datetime import cv2 import os import time import platform
[ 6738, 350, 4146, 1330, 7412, 198, 6738, 350, 4146, 1330, 7412, 51, 74, 198, 11748, 256, 74, 3849, 355, 256, 4106, 198, 6738, 256, 74, 3849, 1330, 309, 643, 626, 11, 21589, 198, 11748, 4704, 278, 198, 11748, 4818, 8079, 198, 11748, 2...
3.4
55
import compas import compas_rhino from compas.datastructures import Mesh mesh = Mesh.from_ply(compas.get('stanford_dragon.ply')) compas_rhino.mesh_draw(mesh)
[ 11748, 552, 292, 198, 11748, 552, 292, 62, 17179, 2879, 198, 6738, 552, 292, 13, 19608, 459, 1356, 942, 1330, 47529, 198, 198, 76, 5069, 796, 47529, 13, 6738, 62, 2145, 7, 5589, 292, 13, 1136, 10786, 14192, 3841, 62, 14844, 13, 2145...
2.580645
62
# Neural Networks Demystified # Part 1: Data + Architecture # # Supporting code for short YouTube series on artificial neural networks. # # Stephen Welch # @stephencwelch import numpy as np # X = (hours sleeping, hours studying), y = Score on test X = np.array(([3,5], [5,1], [10,2]), dtype=float) y = np.array(([75], [82], [93]), dtype=float) # Normalize X = X/np.amax(X, axis=0) y = y/100 #Max test score is 100
[ 2, 47986, 27862, 1897, 88, 301, 1431, 198, 2, 2142, 352, 25, 6060, 1343, 29778, 198, 2, 198, 2, 44188, 2438, 329, 1790, 7444, 2168, 319, 11666, 17019, 7686, 13, 198, 2, 198, 2, 7970, 41524, 198, 2, 2488, 9662, 831, 66, 86, 417, ...
2.773333
150
import json import logging import os import pathlib import re import textwrap import warnings from typing import List, Optional import jinja2 import pandas import requests import requests_cache import yaml from manubot.util import read_serialized_data, read_serialized_dict from manubot.process.bibliography import load_manual_references from manubot.process.ci import get_continuous_integration_parameters from manubot.process.metadata import ( get_header_includes, get_thumbnail_url, get_manuscript_urls, get_software_versions, ) from manubot.process.manuscript import ( datetime_now, get_manuscript_stats, get_text, ) from manubot.cite.citekey import ( citekey_to_csl_item, shorten_citekey, is_valid_citekey, standardize_citekey, ) def check_collisions(citekeys_df): """ Check for short_citekey hash collisions """ collision_df = citekeys_df[["standard_citekey", "short_citekey"]].drop_duplicates() collision_df = collision_df[collision_df.short_citekey.duplicated(keep=False)] if not collision_df.empty: logging.error(f"OMF! Hash collision. Congratulations.\n{collision_df}") return collision_df def check_multiple_citation_strings(citekeys_df): """ Identify different citation strings referring the the same reference. """ message = textwrap.dedent( f"""\ {len(citekeys_df)} unique citations strings extracted from text {citekeys_df.standard_citekey.nunique()} unique standard citations\ """ ) logging.info(message) multi_df = citekeys_df[citekeys_df.standard_citekey.duplicated(keep=False)] if not multi_df.empty: table = multi_df.to_string( index=False, columns=["standard_citekey", "manuscript_citekey"] ) logging.warning(f"Multiple citekeys detected for the same reference:\n{table}") return multi_df def read_variable_files(paths: List[str], variables: Optional[dict] = None) -> dict: """ Read multiple serialized data files into a user_variables dictionary. Provide `paths` (a list of URLs or local file paths). Paths can optionally have a namespace prepended. For example: ```python paths = [ 'https://git.io/vbkqm', # update the dictionary's top-level 'namespace_1=https://git.io/vbkqm', # store under 'namespace_1' key 'namespace_2=some_local_path.json', # store under 'namespace_2' key ] ``` If a namespace is not provided, the JSON must contain a dictionary as its top level. Namespaces should consist only of ASCII alphanumeric characters (includes underscores, first character cannot be numeric). Pass a dictionary to `variables` to update an existing dictionary rather than create a new dictionary. """ if variables is None: variables = {} for path in paths: logging.info(f"Reading user-provided templating variables at {path!r}") # Match only namespaces that are valid jinja2 variable names # http://jinja.pocoo.org/docs/2.10/api/#identifier-naming match = re.match(r"([a-zA-Z_][a-zA-Z0-9_]*)=(.+)", path) if match: namespace, path = match.groups() logging.info( f"Using the {namespace!r} namespace for template variables from {path!r}" ) try: if match: obj = {namespace: read_serialized_data(path)} else: obj = read_serialized_dict(path) except Exception: logging.exception(f"Error reading template variables from {path!r}") continue assert isinstance(obj, dict) conflicts = variables.keys() & obj.keys() if conflicts: logging.warning( f"Template variables in {path!r} overwrite existing " "values for the following keys:\n" + "\n".join(conflicts) ) variables.update(obj) logging.debug( f"Reading user-provided templating variables complete:\n" f"{json.dumps(variables, indent=2, ensure_ascii=False)}" ) return variables def add_author_affiliations(variables: dict) -> dict: """ Edit variables to contain numbered author affiliations. Specifically, add a list of affiliation_numbers for each author and add a list of affiliations to the top-level of variables. If no authors have any affiliations, variables is left unmodified. """ rows = list() for author in variables["authors"]: if "affiliations" not in author: continue if not isinstance(author["affiliations"], list): warnings.warn( f"Expected list for {author['name']}'s affiliations. " f"Assuming multiple affiliations are `; ` separated. " f"Please switch affiliations to a list.", category=DeprecationWarning, ) author["affiliations"] = author["affiliations"].split("; ") for affiliation in author["affiliations"]: rows.append((author["name"], affiliation)) if not rows: return variables affil_map_df = pandas.DataFrame(rows, columns=["name", "affiliation"]) affiliation_df = affil_map_df[["affiliation"]].drop_duplicates() affiliation_df["affiliation_number"] = range(1, 1 + len(affiliation_df)) affil_map_df = affil_map_df.merge(affiliation_df) name_to_numbers = { name: sorted(df.affiliation_number) for name, df in affil_map_df.groupby("name") } for author in variables["authors"]: author["affiliation_numbers"] = name_to_numbers.get(author["name"], []) variables["affiliations"] = affiliation_df.to_dict(orient="records") return variables def load_variables(args) -> dict: """ Read `metadata.yaml` and files specified by `--template-variables-path` to generate manuscript variables available for jinja2 templating. Returns a dictionary, refered to as `variables`, with the following keys: - `pandoc`: a dictionary for passing options to Pandoc via the `yaml_metadata_block`. Fields in `pandoc` are either generated by Manubot or hard-coded by the user if `metadata.yaml` includes a `pandoc` dictionary. - `manubot`: a dictionary for manubot-related information and metadata. Fields in `manubot` are either generated by Manubot or hard-coded by the user if `metadata.yaml` includes a `manubot` dictionary. - All fields from a manuscript's `metadata.yaml` that are not interpreted by Manubot are copied to `variables`. Interpreted fields include `pandoc`, `manubot`, `title`, `keywords`, `authors` (formerly `author_info`, now deprecated), `lang`, and `thumbnail`. - User-specified fields inserted according to the `--template-variables-path` option. User-specified variables take highest precedence and can overwrite values for existing keys like `pandoc` or `manubot` (dangerous). """ # Generated manuscript variables variables = {"pandoc": {}, "manubot": {}} # Read metadata which contains pandoc_yaml_metadata # as well as authors information. if args.meta_yaml_path.is_file(): metadata = read_serialized_dict(args.meta_yaml_path) else: metadata = {} logging.warning( f"missing {args.meta_yaml_path} file with yaml_metadata_block for pandoc" ) # Interpreted keys that are intended for pandoc move_to_pandoc = "title", "keywords", "lang" for key in move_to_pandoc: if key in metadata: variables["pandoc"][key] = metadata.pop(key) # Add date to metadata now = datetime_now() logging.info( f"Using {now:%Z} timezone.\n" f"Dating manuscript with the current datetime: {now.isoformat()}" ) variables["pandoc"]["date-meta"] = now.date().isoformat() variables["manubot"]["date"] = f"{now:%B} {now.day}, {now.year}" # Process authors metadata if "author_info" in metadata: authors = metadata.pop("author_info", []) warnings.warn( "metadata.yaml: 'author_info' is deprecated. Use 'authors' instead.", category=DeprecationWarning, ) else: authors = metadata.pop("authors", []) if authors is None: authors = [] variables["pandoc"]["author-meta"] = [author["name"] for author in authors] variables["manubot"]["authors"] = authors add_author_affiliations(variables["manubot"]) # Set repository version metadata for CI builds ci_params = get_continuous_integration_parameters() if ci_params: variables["manubot"]["ci_source"] = ci_params # Add manuscript URLs variables["manubot"].update(get_manuscript_urls(metadata.pop("html_url", None))) # Add software versions variables["manubot"].update(get_software_versions()) # Add thumbnail URL if present thumbnail_url = get_thumbnail_url(metadata.pop("thumbnail", None)) if thumbnail_url: variables["manubot"]["thumbnail_url"] = thumbnail_url # Update variables with metadata.yaml pandoc/manubot dicts for key in "pandoc", "manubot": dict_ = metadata.pop(key, {}) if not isinstance(dict_, dict): logging.warning( f"load_variables expected metadata.yaml field {key!r} to be a dict." f"Received a {dict_.__class__.__name__!r} instead." ) continue variables[key].update(dict_) # Update variables with uninterpreted metadata.yaml fields variables.update(metadata) # Update variables with user-provided variables here variables = read_variable_files(args.template_variables_path, variables) # Add header-includes metadata with <meta> information for the HTML output's <head> variables["pandoc"]["header-includes"] = get_header_includes(variables) assert args.skip_citations # Extend Pandoc's metadata.bibliography field with manual references paths bibliographies = variables["pandoc"].get("bibliography", []) if isinstance(bibliographies, str): bibliographies = [bibliographies] assert isinstance(bibliographies, list) bibliographies.extend(args.manual_references_paths) bibliographies = list(map(os.fspath, bibliographies)) variables["pandoc"]["bibliography"] = bibliographies # enable pandoc-manubot-cite option to write bibliography to a file variables["pandoc"]["manubot-output-bibliography"] = os.fspath(args.references_path) variables["pandoc"]["manubot-output-citekeys"] = os.fspath(args.citations_path) variables["pandoc"]["manubot-requests-cache-path"] = os.fspath( args.requests_cache_path ) variables["pandoc"]["manubot-clear-requests-cache"] = args.clear_requests_cache return variables def get_citekeys_df(citekeys: list, citekey_aliases: dict = {}): """ Generate and return citekeys_df. citekeys_df is a pandas.DataFrame with the following columns: - manuscript_citekey: citation keys extracted from the manuscript content files. - detagged_citekey: manuscript_citekey but with tag citekeys dereferenced - standard_citekey: detagged_citekey standardized - short_citekey: standard_citekey hashed to create a shortened citekey """ citekeys_df = pandas.DataFrame( {"manuscript_citekey": list(citekeys)} ).drop_duplicates() citekeys_df["detagged_citekey"] = citekeys_df.manuscript_citekey.map( lambda citekey: citekey_aliases.get(citekey, citekey) ) for citation in citekeys_df.detagged_citekey: is_valid_citekey(citation, allow_raw=True) citekeys_df["standard_citekey"] = citekeys_df.detagged_citekey.map( standardize_citekey ) citekeys_df["short_citekey"] = citekeys_df.standard_citekey.map(shorten_citekey) citekeys_df = citekeys_df.sort_values(["standard_citekey", "detagged_citekey"]) check_collisions(citekeys_df) check_multiple_citation_strings(citekeys_df) return citekeys_df def read_citations_tsv(path) -> dict: """ Read citekey aliases from a citation-tags.tsv file. """ if not path.is_file(): logging.info( f"no citation tags file at {path} " "Not reading citekey_aliases from citation-tags.tsv." ) return {} tag_df = pandas.read_csv(path, sep="\t") na_rows_df = tag_df[tag_df.isnull().any(axis="columns")] if not na_rows_df.empty: logging.error( f"{path} contains rows with missing values:\n" f"{na_rows_df}\n" "This error can be caused by using spaces rather than tabs to delimit fields.\n" "Proceeding to reread TSV with delim_whitespace=True." ) tag_df = pandas.read_csv(path, delim_whitespace=True) tag_df["manuscript_citekey"] = "tag:" + tag_df.tag tag_df = tag_df.rename(columns={"citation": "detagged_citekey"}) citekey_aliases = dict( zip(tag_df["manuscript_citekey"], tag_df["detagged_citekey"]) ) return citekey_aliases def _citation_tags_to_reference_links(args) -> str: """ Convert citation-tags.tsv to markdown reference link syntax """ citekey_aliases = read_citations_tsv(args.citation_tags_path) if not citekey_aliases: return "" text = "\n\n" for key, value in citekey_aliases.items(): text += f"[@{key}]: {value}\n" logging.warning( "citation-tags.tsv is deprecated. " f"Consider deleting citation-tags.tsv and inserting the following paragraph into your Markdown content:{text}" ) return text def generate_csl_items( citekeys: list, manual_refs: dict = {}, requests_cache_path: Optional[str] = None, clear_requests_cache: Optional[bool] = False, ) -> list: """ General CSL (citeproc) items for standard_citekeys in citekeys_df. Parameters: - citekeys: list of standard_citekeys - manual_refs: mapping from standard_citekey to csl_item for manual references - requests_cache_path: path for the requests cache database. Passed as cache_name to `requests_cache.install_cache`. requests_cache may append an extension to this path, so it is not always the exact path to the cache. If None, do not use requests_cache. - clear_requests_cache: If True, clear the requests cache before generating citekey metadata. """ # Deduplicate citations citekeys = list(dict.fromkeys(citekeys)) # Install cache if requests_cache_path is not None: requests # require `import requests` in case this is essential for monkey patching by requests_cache. requests_cache.install_cache(requests_cache_path, include_get_headers=True) cache = requests_cache.get_cache() if clear_requests_cache: logging.info("Clearing requests-cache") requests_cache.clear() logging.info( f"requests-cache starting with {len(cache.responses)} cached responses" ) csl_items = list() failures = list() for standard_citekey in citekeys: if standard_citekey in manual_refs: csl_items.append(manual_refs[standard_citekey]) continue elif standard_citekey.startswith("raw:"): logging.error( f"CSL JSON Data with a standard_citekey of {standard_citekey!r} not found in manual-references.json. " "Metadata must be provided for raw citekeys." ) failures.append(standard_citekey) try: csl_item = citekey_to_csl_item(standard_citekey) csl_items.append(csl_item) except Exception: logging.exception(f"Citeproc retrieval failure for {standard_citekey!r}") failures.append(standard_citekey) # Uninstall cache if requests_cache_path is not None: logging.info( f"requests-cache finished with {len(cache.responses)} cached responses" ) requests_cache.uninstall_cache() if failures: message = "CSL JSON Data retrieval failed for the following standardized citation keys:\n{}".format( "\n".join(failures) ) logging.error(message) return csl_items def _generate_csl_items(args, citekeys_df): """ General CSL (citeproc) items for standard_citekeys in citekeys_df. Writes references.json to disk and logs warnings for potential problems. """ # Read manual references (overrides) in JSON CSL manual_refs = load_manual_references(args.manual_references_paths) # Retrieve CSL Items csl_items = generate_csl_items( citekeys=citekeys_df.standard_citekey.unique(), manual_refs=manual_refs, requests_cache_path=args.requests_cache_path, clear_requests_cache=args.clear_requests_cache, ) # Write CSL JSON bibliography for Pandoc. write_csl_json(csl_items, args.references_path) return csl_items def write_csl_json(csl_items, path): """ Write CSL Items to a JSON file at `path`. If `path` evaluates as False, do nothing. """ if not path: return path = pathlib.Path(path) with path.open("w", encoding="utf-8") as write_file: json.dump(csl_items, write_file, indent=2, ensure_ascii=False) write_file.write("\n") def template_with_jinja2(text, variables): """ Template using jinja2 with the variables dictionary unpacked as keyword arguments. """ jinja_environment = jinja2.Environment( loader=jinja2.BaseLoader(), undefined=jinja2.make_logging_undefined(logging.getLogger()), autoescape=False, comment_start_string="{##", comment_end_string="##}", extensions=["jinja2.ext.do", "jinja2.ext.loopcontrols"], ) template = jinja_environment.from_string(text) return template.render(**variables) def prepare_manuscript(args): """ Compile manuscript, creating manuscript.md and references.json as inputs for pandoc. """ text = get_text(args.content_directory) assert args.skip_citations text += _citation_tags_to_reference_links(args) variables = load_variables(args) variables["manubot"]["manuscript_stats"] = get_manuscript_stats(text) with args.variables_path.open("w", encoding="utf-8") as write_file: json.dump(variables, write_file, ensure_ascii=False, indent=2) write_file.write("\n") text = template_with_jinja2(text, variables) # Write manuscript for pandoc with args.manuscript_path.open("w", encoding="utf-8") as write_file: yaml.dump( variables["pandoc"], write_file, default_flow_style=False, explicit_start=True, explicit_end=True, width=float("inf"), ) write_file.write("\n") write_file.write(text)
[ 11748, 33918, 198, 11748, 18931, 198, 11748, 28686, 198, 11748, 3108, 8019, 198, 11748, 302, 198, 11748, 2420, 37150, 198, 11748, 14601, 198, 6738, 19720, 1330, 7343, 11, 32233, 198, 198, 11748, 474, 259, 6592, 17, 198, 11748, 19798, 292,...
2.533815
7,467
#! /usr/bin/env python # scrape the IBA pages for cocktail lists import sys import xml.etree.ElementTree as ET from lxml import html import requests from pprint import pprint from collections import OrderedDict import json url = 'http://iba-world.com/new-era-drinks/' jsonfile = 'IBA_new_era_drinks.json' url = 'http://iba-world.com/iba-cocktails/' jsonfile = 'IBA_unforgettables.json' url = 'http://iba-world.com/contemporary-classics/' jsonfile = 'IBA_contemporary_classics.json' jsonfile = 'IBA_.json' recipes = OrderedDict() page = requests.get(url) tree = html.fromstring(page.content) items = tree.findall(".//div[@class='blog_list_item_lists']") for item in items: name = item.find(".//h3").text name = ' '.join([word.capitalize() for word in name.split()]) body = item.find(".//div[@class='blog_text']") recipes[name] = {'unit': 'cL'} print name children = [c for c in body.iterchildren()] n = 0 if children[1].tag == 'ul': n = -1 style = children[n+1].text if style is None: try: style = children[n+1].find('span').text except: pass recipes[name]['style'] = style recipes[name]['ingredients'] = OrderedDict() if not children[n+2].tag == 'ul': print "adapting <p> ingredients:", children[n+2].text ing_list = ET.tostring(children[n+2]).lstrip('<p>').rstrip('</p>\n').split('<br />\n') else: ing_list = [i.text for i in children[n+2].iterchildren()] for ingredient in ing_list: if len(ingredient.split()) == 1: recipes[name]['ingredients'][ingredient.lower()] = '' continue unit = ingredient.split()[1].lower() if unit == 'cl': recipes[name]['ingredients'][' '.join([w.lower() for w in ingredient.split()[2:]])] = float(ingredient.split()[0]) elif unit == 'bar' or unit == 'to': # bar spoon recipes[name]['ingredients'][' '.join([w.lower() for w in ingredient.split()[3:]])] = ' '.join(ingredient.split()[:3]) elif unit == 'dashes' or unit == 'drops' or unit == 'with': recipes[name]['ingredients'][' '.join([w.lower() for w in ingredient.split()[2:]])] = ' '.join(ingredient.split()[:2]) elif unit == 'dash': recipes[name]['ingredients'][' '.join([w.lower() for w in ingredient.split()[2:]])] = 'dash' else: print "using literal: ", ingredient literal = {'1': 'one', '2': 'two', 'A': 'one'} try: recipes[name]['ingredients'][' '.join([w.lower() for w in ingredient.split()[1:]])] = literal[ingredient.split()[0]] except: recipes[name]['ingredients'][ingredient.lower()] = '' # Get full description from the link ref_url = item.find(".//a[@class='top_hover_image']").attrib.get('href') detail_page = requests.get(ref_url) detail_tree = html.fromstring(detail_page.content) use_next = False for child in detail_tree.find(".//div[@class='col-sm-9']").iterchildren(): if use_next and child.tag == 'p': recipes[name]['IBA_description'] = child.text break if child.tag =='ul': use_next = True with open(jsonfile, 'w') as fp: json.dump(recipes, fp, indent=4, separators=(',', ': ')) print "Wrote out as {}".format(jsonfile) sys.exit(0) raw = sys.argv[1] with open(raw) as fp: for line in fp.readlines(): if line.lstrip().startswith(r'<h3>'): print line.lstrip() # super hax if line.startswith(r'<p>'): print line if line.startswith(r'<li>'): print line if not line.lstrip().startswith('<'): print line
[ 2, 0, 1220, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 2, 42778, 262, 314, 4339, 5468, 329, 24554, 8341, 198, 198, 11748, 25064, 198, 11748, 35555, 13, 316, 631, 13, 20180, 27660, 355, 12152, 198, 6738, 300, 19875, 1330, 27711, 198,...
2.25861
1,655
api_key = "9N7hvPP9yFrjBnELpBdthluBjiOWzJZw" mongo_url = 'mongodb://localhost:27017' mongo_db = 'CarPopularity' mongo_collections = ['CarSalesByYear', 'PopularCarsByRegion'] years_data = ['2019', '2018', '2017', '2016', '2015'] test_mode = True
[ 15042, 62, 2539, 796, 366, 24, 45, 22, 71, 85, 10246, 24, 88, 6732, 73, 33, 77, 3698, 79, 33, 67, 400, 2290, 33, 7285, 3913, 89, 41, 57, 86, 1, 198, 76, 25162, 62, 6371, 796, 705, 31059, 375, 65, 1378, 36750, 25, 1983, 29326, ...
2.32381
105
import imp import torch import torch.nn as nn import numpy as np import torch.nn.functional as F from pytorch_ares.attack_torch.utils import loss_adv
[ 11748, 848, 198, 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 28034, 13, 20471, 13, 45124, 355, 376, 198, 6738, 12972, 13165, 354, 62, 3565, 13, 20358, 62, 13165, 354, 13, 2...
3.191489
47
from django import template register = template.Library()
[ 6738, 42625, 14208, 1330, 11055, 198, 198, 30238, 796, 11055, 13, 23377, 3419, 628 ]
4.285714
14
from django.test import TestCase from django.contrib.auth.models import User from wiki.models import Page from django.utils.text import slugify # Create your tests here. ''' Steps to writing a test 1. Set up your test data 2. Make a request (GET, POST) 3a. Check if response matches what we expect 3b. Check if database matches what we expect '''
[ 6738, 42625, 14208, 13, 9288, 1330, 6208, 20448, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 11787, 198, 6738, 22719, 13, 27530, 1330, 7873, 198, 6738, 42625, 14208, 13, 26791, 13, 5239, 1330, 31065, 1958, 198, 1...
3.212389
113
__author__ = 'Mitja Pagon <mitja@inueni.com>' __version__ = '0.2'
[ 834, 9800, 834, 796, 705, 43339, 6592, 350, 1840, 1279, 2781, 6592, 31, 259, 84, 43850, 13, 785, 29, 6, 198, 834, 9641, 834, 796, 705, 15, 13, 17, 6, 198 ]
2.129032
31
''' The randomization defense method, which applies random . ''' import tensorflow as tf from ares.defense.input_transformation import input_transformation def randomize(xs, scale_min=0.875, pad_value=0.0): ''' Apply random rescaling and padding to xs. :param xs: A batch of inputs for some classifier. :param scale_min: The random rescaling rate would be chosen between ``scale_min`` and 1.0. :param pad_value: ``constant_values`` parameter for the ``tf.pad`` method. :return: A new tensor with same shape and dtype as xs. ''' ratio = tf.random.uniform((), minval=scale_min, maxval=1.0) height, width = tf.cast(xs.shape[1].value * ratio, tf.int32), tf.cast(xs.shape[2].value * ratio, tf.int32) xs_rescaled = tf.image.resize(xs, (height, width), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR, align_corners=True, preserve_aspect_ratio=False) height_rem, width_rem = xs.shape[1].value - height, xs.shape[2].value - width pad_left = tf.random_uniform((), 0, width_rem, dtype=tf.int32) pad_right = width_rem - pad_left pad_top = tf.random_uniform((), 0, height_rem, dtype=tf.int32) pad_bottom = height_rem - pad_top xs_padded = tf.pad(xs_rescaled, [[0, 0], [pad_top, pad_bottom], [pad_left, pad_right], [0, 0]], constant_values=pad_value) xs_padded.set_shape(xs.shape) return xs_padded def randomization(scale_min=0.875, pad_value=0.0): ''' A decorator to apply randomize rescaling and padding to input of the classifier. :param scale_min: The random rescaling rate would be chosen between ``scale_min`` and 1.0. :param pad_value: ``constant_values`` parameter for the ``tf.pad`` method. ''' return lambda rs_class: input_transformation(rs_class, randomize, args_fn, kwargs_fn)
[ 7061, 6, 383, 4738, 1634, 3761, 2446, 11, 543, 8991, 4738, 764, 705, 7061, 198, 198, 11748, 11192, 273, 11125, 355, 48700, 198, 198, 6738, 389, 82, 13, 19774, 13, 15414, 62, 7645, 1161, 1330, 5128, 62, 7645, 1161, 628, 198, 4299, 47...
2.543811
719
from django.contrib import admin from annotate.backend.models import Image, Annotation admin.site.register(Image) admin.site.register(Annotation)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 6738, 24708, 378, 13, 1891, 437, 13, 27530, 1330, 7412, 11, 1052, 38983, 198, 198, 28482, 13, 15654, 13, 30238, 7, 5159, 8, 198, 28482, 13, 15654, 13, 30238, 7, 2025, 38983, 8, 19...
3.418605
43
data = open('./original').readlines() alphabet = { "<":"lt", ">":"gt", "=":"=", "-":'-', "+":"+", "-":"-", "~":"~", "!":"ex", "%":"%", "^":"^", "&":"&", "*":"*", "(":"(", ")":"right_paran", "[":"[", "]":"]", "{":"{", "}":"}", "[":"[", "]":"]", "|":"|", ";":";", ":":":", ",":",", ".":".", "?":"?", "/":"/", } start = 0 current = "" space = "<space>" declared = [] referenced = [] for x in data: x = x.strip() if x == "": continue if '%%' == x: start = 1 continue elif start != 1: continue if x == "test": break; x = x.split(' ') if len(x) == 1:#item declaration or end if x[0] == ';': current = "" else: current = x[0] declared.append(item(x[0])) print "" else: x = x[1:] tmp = item(current)+'\t=\t' for y in range(len(x)): referenced.append(item(x[y])) tmp += item(x[y]) if y != len(x)-1 and "'" not in x[y+1] and "'" not in x[y]: tmp+=space print tmp referenced = set(referenced) final = [] for x in referenced: if x not in declared: final.append(x) print "" for x in final: tmp = x+'\t=\t' x = x[1:-1] print tmp + x.lower()
[ 7890, 796, 1280, 7, 4458, 14, 14986, 27691, 961, 6615, 3419, 628, 198, 17307, 8380, 796, 1391, 198, 220, 220, 220, 220, 220, 220, 220, 33490, 2404, 2528, 1600, 198, 220, 220, 220, 220, 220, 220, 220, 366, 29, 2404, 13655, 1600, 198,...
1.676923
910
#!/usr/bin/env python # # Copyright 2007 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. # """ Non-stub version of the memcache API, keeping all data in memcached. Uses the python-memcached library to interface with memcached. """ import base64 import cPickle import logging import memcache import os import time from google.appengine.api import apiproxy_stub from google.appengine.api.memcache import memcache_service_pb from google.appengine.runtime import apiproxy_errors MemcacheSetResponse = memcache_service_pb.MemcacheSetResponse MemcacheSetRequest = memcache_service_pb.MemcacheSetRequest MemcacheIncrementRequest = memcache_service_pb.MemcacheIncrementRequest MemcacheIncrementResponse = memcache_service_pb.MemcacheIncrementResponse MemcacheDeleteResponse = memcache_service_pb.MemcacheDeleteResponse from google.appengine.api.memcache import TYPE_INT from google.appengine.api.memcache import TYPE_LONG
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 198, 2, 15069, 4343, 3012, 3457, 13, 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, ...
3.61519
395
from struct import pack from .vector import * from .formatdecimal import decimal from numbers import Number import os import sys try: basestring except: basestring = str def toSCADModule(polys, moduleName, digitsAfterDecimal=9, colorOverride=None): """ INPUT: polys: list of (color,polyhedra) pairs (counterclockwise triangles), or a list of (color,triangle) pairs (TODO: currently uses first color for all in latter case) moduleName: OpenSCAD module name OUTPUT: string with OpenSCAD code implementing the polys """ polys = toPolyhedra(polys) scad = [] scad.append("module " +moduleName+ "() {") for rgb,poly in polys: if colorOverride != "" and (colorOverride or rgb): line = " color(%s) " % describeColor(colorOverride if colorOverride else tuple(min(max(c,0.),1.0) for c in rgb)) else: line = " " pointsDict = {} i = 0 line += "polyhedron(points=[" points = [] for face in poly: for v in reversed(face): if tuple(v) not in pointsDict: pointsDict[tuple(v)] = i points.append( ("[%s,%s,%s]") % tuple(decimal(x,digitsAfterDecimal) for x in v) ) i += 1 line += ",".join(points) line += "], faces=[" line += ",".join( "[" + ",".join(str(pointsDict[tuple(v)]) for v in reversed(face)) + "]" for face in poly ) + "]" line += ");" scad.append(line) scad.append("}\n") return "\n".join(scad) def saveSCAD(filename, polys, moduleName="object1", quiet=False): """ filename: filename to write OpenSCAD file polys: list of (color,polyhedra) pairs (counterclockwise triangles) moduleName: OpenSCAD module name quiet: give no status message if set """ if not quiet: sys.stderr.write("Saving %s\n" % filename) if filename: with open(filename, "w") as f: f.write(toSCADModule(polys, moduleName)) f.write("\n" + moduleName + "();\n") else: sys.stdout.write(toSCADModule(polys, moduleName)) sys.stdout.write("\n" + moduleName + "();\n") def saveSTL(filename, mesh, swapYZ=False, quiet=False): """ filename: filename to save STL file mesh: list of (color,triangle) pairs (counterclockwise) swapYZ: should Y/Z axes be swapped? quiet: give no status message if set """ mesh = toMesh(mesh) if not quiet: sys.stderr.write("Saving %s\n" % filename) minY = float("inf") minVector = Vector(float("inf"),float("inf"),float("inf")) numTriangles = 0 if swapYZ: matrix = Matrix( (1,0,0), (0,0,-1), (0,1,0) ) else: matrix = Matrix.identity(3) mono = True for rgb,triangle in mesh: if rgb is not None: mono = False numTriangles += 1 for vertex in triangle: vertex = matrix*vertex minVector = Vector(min(minVector[i], vertex[i]) for i in range(3)) minVector -= Vector(0.001,0.001,0.001) # make sure all STL coordinates are strictly positive as per Wikipedia if filename: with open(filename, "wb") as f: writeSTL(f.write) else: if sys.platform == "win32": import msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) writeSTL(lambda data : os.write(sys.stdout.fileno(), data))
[ 6738, 2878, 1330, 2353, 198, 6738, 764, 31364, 1330, 1635, 198, 6738, 764, 18982, 12501, 4402, 1330, 32465, 198, 6738, 3146, 1330, 7913, 220, 198, 11748, 28686, 198, 11748, 25064, 198, 198, 28311, 25, 198, 220, 220, 220, 1615, 395, 1806...
2.249837
1,537
import numpy as np from PIL import Image import matplotlib.pyplot as plt import histogram_module import dist_module # model_images - list of file names of model images # query_images - list of file names of query images # # dist_type - string which specifies distance type: 'chi2', 'l2', 'intersect' # hist_type - string which specifies histogram type: 'grayvalue', 'dxdy', 'rgb', 'rg' # # note: use functions 'get_dist_by_name', 'get_hist_by_name' and 'is_grayvalue_hist' to obtain # handles to distance and histogram functions, and to find out whether histogram function # expects grayvalue or color image # For each image file from 'query_images' find and visualize the 5 nearest images from 'model_image'. # # Note: use the previously implemented function 'find_best_match' # Note: use subplot command to show all the images in the same Python figure, one row per query image
[ 11748, 299, 32152, 355, 45941, 198, 6738, 350, 4146, 1330, 7412, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 198, 11748, 1554, 21857, 62, 21412, 198, 11748, 1233, 62, 21412, 628, 198, 198, 2, 2746, 62, 17566, 53...
3.424242
264
import argparse import logging import sys from .dycco import document if __name__ == '__main__': arg_parser = argparse.ArgumentParser(prog='dycco', description='Literate-style documentation generator.') arg_parser.add_argument('source_file', nargs='+', default=sys.stdin, help='Source files to document') arg_parser.add_argument('-o', '--output-dir', default='docs', help='Output directory (will be created if necessary)') arg_parser.add_argument('-a', '--asciidoc3', action='store_true', default=False, dest='use_ascii', help='Process with asciidoc3 instead of markdown (you will have to install asciidoc3, of course)') arg_parser.add_argument('-e', '--escape-html', action='store_true', default=False, dest='escape_html', help='Run the documentation through html.escape() before markdown or asciidoc3') arg_parser.add_argument('-f', '--single-file', action='store_true', default=False, dest='single_file', help='Just produce a .md or .adoc file in single-column to be processed externally') args = arg_parser.parse_args() sys.exit(main(args.source_file, args.output_dir, args.use_ascii, args.escape_html, args.single_file))
[ 11748, 1822, 29572, 198, 11748, 18931, 198, 11748, 25064, 198, 198, 6738, 764, 9892, 535, 78, 1330, 3188, 628, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 1822, 62, 48610, 796, 1822, 29572, ...
2.9601
401
################################################################################ # Copyright (c) 2015-2018 Skymind, Inc. # # This program and the accompanying materials are made available under the # terms of the Apache License, Version 2.0 which is available at # https://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. # # SPDX-License-Identifier: Apache-2.0 ################################################################################ from .java_classes import * import numpy as np import ctypes import warnings native_ops = NativeOpsHolder.getInstance().getDeviceNativeOps() # DATA TYPE MANAGEMENT DOUBLE = DataType.DOUBLE FLOAT = DataType.FLOAT HALF = DataType.HALF LONG = DataType.LONG INT = DataType.INT SHORT = DataType.SHORT UBYTE = DataType.UBYTE BYTE = DataType.BYTE BOOL = DataType.BOOL UTF8 = DataType.UTF8 COMPRESSED = DataType.COMPRESSED UNKNOWN = DataType.UNKNOWN SUPPORTED_JAVA_DTYPES = [ DOUBLE, FLOAT, HALF, LONG, INT, SHORT, BOOL #UTF8 ] SUPPORTED_PYTHON_DTYPES = [ np.float64, np.float32, np.float16, np.int64, np.int32, np.int16, np.bool_ #np.str_ ] _PY2J = {SUPPORTED_PYTHON_DTYPES[i] : SUPPORTED_JAVA_DTYPES[i] for i in range(len(SUPPORTED_JAVA_DTYPES))} _J2PY = {SUPPORTED_JAVA_DTYPES[i] : SUPPORTED_PYTHON_DTYPES[i] for i in range(len(SUPPORTED_JAVA_DTYPES))} def set_context_dtype(dtype): ''' Sets the dtype for nd4j # Arguments dtype: 'float' or 'double' ''' dtype_map = { 'float32': 'float', 'float64': 'double' } dtype = dtype_map.get(dtype, dtype) if dtype not in ['float', 'double']: raise ValueError("Invalid dtype '{}'. Available dtypes are 'float' and 'double'.".format(dtype)) dtype_ = DataTypeUtil.getDtypeFromContext(dtype) DataTypeUtil.setDTypeForContext(dtype_) if get_context_dtype() != dtype: warnings.warn("Can not set context dtype now. Set it at the beginning of your program.") def get_context_dtype(): ''' Returns the nd4j dtype ''' dtype = DataTypeUtil.getDtypeFromContext() return DataTypeUtil.getDTypeForName(dtype) _refs = [] def _from_numpy(np_array): ''' Convert numpy array to nd4j array ''' pointer_address, _ = np_array.__array_interface__['data'] _refs.append(np_array) pointer = native_ops.pointerForAddress(pointer_address) size = np_array.size pointer.limit(size) jdtype = _dtype_py2j(np_array.dtype) ''' mapping = { DOUBLE: DoublePointer, FLOAT: FloatPointer, HALF: HalfPointer, LONG: LongPointer, INT: IntPointer, SHORT: ShortPointer, BOOL: BoolPointer } pc = mapping[jdtype] #pointer = pc(pointer) ''' buff = Nd4j.createBuffer(pointer, size, jdtype) assert buff.address() == pointer_address _refs.append(buff) elem_size = buff.getElementSize() assert elem_size == np_array.dtype.itemsize strides = np_array.strides strides = [dim / elem_size for dim in strides] shape = np_array.shape nd4j_array = Nd4j.create(buff, shape, strides, 0) assert buff.address() == nd4j_array.data().address() return nd4j_array def _to_numpy(nd4j_array): ''' Convert nd4j array to numpy array ''' buff = nd4j_array.data() address = buff.pointer().address() dtype = nd4j_array.dataType().toString() mapping = { 'DOUBLE': ctypes.c_double, 'FLOAT': ctypes.c_float, 'HALF': ctypes.c_short, 'LONG': ctypes.c_long, 'INT': ctypes.c_int, 'SHORT': ctypes.c_short, 'BOOL': ctypes.c_bool } Pointer = ctypes.POINTER(mapping[dtype]) pointer = ctypes.cast(address, Pointer) np_array = np.ctypeslib.as_array(pointer, tuple(nd4j_array.shape())) return np_array
[ 29113, 29113, 14468, 198, 2, 15069, 357, 66, 8, 1853, 12, 7908, 5274, 10155, 11, 3457, 13, 198, 2, 198, 2, 770, 1430, 290, 262, 19249, 5696, 389, 925, 1695, 739, 262, 198, 2, 2846, 286, 262, 24843, 13789, 11, 10628, 362, 13, 15, ...
2.392652
1,742
import serial ser = serial.Serial('/dev/tty.usbmodem7071', 115200, timeout=10) ser.write("\xb1\xa3\xb5\xb5") #set usec mode 177,163,181,181 ser.flush() ser.flushInput() obs = ser.read(8) if len(obs) != 8: print('Error: no buttons presses detected') print 'Observed data (as hex): '+ obs.encode('hex') obsBin = [ord(c) for c in obs] usec = (obsBin[3] << 24)+ (obsBin[4] << 16)+ (obsBin[5] << 8)+obsBin[6] keys = (obsBin[1] << 8)+obsBin[2] print 'keys pressed %d at %d usec' % (keys, usec) ser.write("\xb1\xa3\xa9\xa9") #turn off oscilloscope: set keyboard mode 177,163,169,169 ser.close()
[ 11748, 11389, 198, 2655, 796, 11389, 13, 32634, 10786, 14, 7959, 14, 42852, 13, 43319, 4666, 368, 2154, 4869, 3256, 12279, 2167, 11, 26827, 28, 940, 8, 198, 2655, 13, 13564, 7203, 59, 30894, 16, 59, 27865, 18, 59, 30894, 20, 59, 308...
2.349206
252
import os from typing import Tuple import torchaudio from torch import Tensor from torch.utils.data import Dataset from torchaudio.datasets.utils import ( download_url, extract_archive, walk_files, ) URL = "train-clean-100" FOLDER_IN_ARCHIVE = "LibriTTS" _CHECKSUMS = { "http://www.openslr.org/60/dev-clean.tar.gz": "0c3076c1e5245bb3f0af7d82087ee207", "http://www.openslr.org/60/dev-other.tar.gz": "815555d8d75995782ac3ccd7f047213d", "http://www.openslr.org/60/test-clean.tar.gz": "7bed3bdb047c4c197f1ad3bc412db59f", "http://www.openslr.org/60/test-other.tar.gz": "ae3258249472a13b5abef2a816f733e4", "http://www.openslr.org/60/train-clean-100.tar.gz": "4a8c202b78fe1bc0c47916a98f3a2ea8", "http://www.openslr.org/60/train-clean-360.tar.gz": "a84ef10ddade5fd25df69596a2767b2d", "http://www.openslr.org/60/train-other-500.tar.gz": "7b181dd5ace343a5f38427999684aa6f", }
[ 11748, 28686, 198, 6738, 19720, 1330, 309, 29291, 198, 198, 11748, 28034, 24051, 198, 6738, 28034, 1330, 309, 22854, 198, 6738, 28034, 13, 26791, 13, 7890, 1330, 16092, 292, 316, 198, 6738, 28034, 24051, 13, 19608, 292, 1039, 13, 26791, ...
2.131148
427
# coding: utf-8 ######################################################################### # : <a href="http://www.crazyit.org">Java</a> # # author yeeku.H.lee kongyeeku@163.com # # # # version 1.0 # # # # Copyright (C), 2001-2018, yeeku.H.Lee # # # # This program is protected by copyright laws. # # # # Program Name: # # # # <br>Date: # ######################################################################### import matplotlib.pyplot as plt import numpy as np # x_data = ['2011', '2012', '2013', '2014', '2015', '2016', '2017'] y_data = [58000, 60200, 63000, 71000, 84000, 90500, 107000] y_data2 = [52000, 54200, 51500,58300, 56800, 59500, 62700] bar_width=0.3 # Yrange(len(x_data), 012... plt.barh(y=range(len(x_data)), width=y_data, label='Java', color='steelblue', alpha=0.8, height=bar_width) # Ynp.arange(len(x_data))+bar_width, # bar_width1+bar_width2+bar_width... plt.barh(y=np.arange(len(x_data))+bar_width, width=y_data2, label='Android', color='indianred', alpha=0.8, height=bar_width) # , ha, va for y, x in enumerate(y_data): plt.text(x+5000, y-bar_width/2, '%s' % x, ha='center', va='bottom') for y, x in enumerate(y_data2): plt.text(x+5000, y+bar_width/2, '%s' % x, ha='center', va='bottom') # Y plt.yticks(np.arange(len(x_data))+bar_width/2, x_data) # plt.title("JavaAndroid") # plt.xlabel("") plt.ylabel("") # plt.legend() plt.show()
[ 2, 19617, 25, 3384, 69, 12, 23, 201, 198, 29113, 29113, 7804, 2, 201, 198, 2, 1058, 1279, 64, 13291, 2625, 4023, 1378, 2503, 13, 50112, 270, 13, 2398, 5320, 29584, 3556, 64, 29, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, ...
1.63506
1,255
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Dec 18 20:13:57 2018 @author: allen """ import random, os, json, datetime, time from flask import Flask, Response from pymongo import MongoClient from bson import json_util app = Flask(__name__) MONGO_URI = "mongodb://mongodb:27017" # "mongodb:<container_name>:27017" mongdb_client= MongoClient(MONGO_URI) random_numbers = mongdb_client.demo.random_numbers time.sleep(5) # hack for the mongoDb database to get running ###################### ## ########################## from pymodm.connection import connect from pymongo.write_concern import WriteConcern from pymodm import MongoModel, fields # Connect to MongoDB and call the connection "my-app". connect("mongodb://mongodb:27017/myDatabase", alias="my-app") if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.config['DEBUG'] = True app.run(host='0.0.0.0', port=port)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 30030, 4280, 1248, 1160, 25, 1485, 25, 3553, 2864, 198, 198, 31, 9800, 25, 477, 268, 198,...
2.833333
330
#! /usr/bin/Python from gensim.models.keyedvectors import KeyedVectors from scipy import spatial from numpy import linalg import argparse import sys vector_file = sys.argv[1] if len(sys.argv) != 6: print('arguments wrong!') print(len(sys.argv)) exit() else: words = [sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]] print(words) wvs = KeyedVectors.load_word2vec_format(vector_file, binary=True) print('WVs loaded.') for w in words: if w not in wvs.vocab: print('out of vocab!') exit() #print(wvs.most_similar(positive=[words[1], words[2]], negative=[words[0]], topn=3)) w1 = wvs[words[0]] w2 = wvs[words[1]] w3 = wvs[words[2]] w4 = wvs[words[3]] m1 = w1 / linalg.norm(w1) m2 = w2 / linalg.norm(w2) m3 = w3 / linalg.norm(w3) m4 = w4 / linalg.norm(w4) diff1 = w1 - w2 diff2 = w3 - w4 miff1 = m1 - m2 miff2 = m3 - m4 print('-------Word Space---------') print('to word-4: ', 1-spatial.distance.cosine(m2+m3-m1, m4)) print('to word-3: ', 1-spatial.distance.cosine(m1+m4-m2, m3)) print('to word-2: ', 1-spatial.distance.cosine(m4+m1-m3, m2)) print('to word-1: ', 1-spatial.distance.cosine(m2+m3-m4, m1)) print('------Analogy Space-------') print(' cosine: ', 1-spatial.distance.cosine(diff1, diff2)) print(' Euclidean: ', 1-linalg.norm(diff1-diff2)/(linalg.norm(diff1)+linalg.norm(diff2))) print(' M-cosine: ', 1-spatial.distance.cosine(miff1, miff2)) print('M-Euclidean: ', 1-linalg.norm(miff1-miff2)/(linalg.norm(miff1)+linalg.norm(miff2)))
[ 2, 0, 1220, 14629, 14, 8800, 14, 37906, 201, 198, 201, 198, 6738, 308, 641, 320, 13, 27530, 13, 2539, 276, 303, 5217, 1330, 7383, 276, 53, 478, 669, 201, 198, 6738, 629, 541, 88, 1330, 21739, 201, 198, 6738, 299, 32152, 1330, 300,...
2.058108
740
import numpy as np import scipy as sp import scipy.sparse.linalg as splinalg def eig2_nL(g, tol_eigs = 1.0e-6, normalize:bool = True, dim:int=1): """ DESCRIPTION ----------- Computes the eigenvector that corresponds to the second smallest eigenvalue of the normalized Laplacian matrix then it uses sweep cut to round the solution. PARAMETERS (mandatory) ---------------------- g: graph object PARAMETERS (optional) --------------------- dim: positive, int default == 1 The number of eigenvectors or dimensions to compute. tol_eigs: positive float, double default == 1.0e-6 Tolerance for computation of the eigenvector that corresponds to the second smallest eigenvalue of the normalized Laplacian matrix. normalize: bool, default == True True if we should return the eigenvectors of the generalized eigenvalue problem associated with the normalized Laplacian. This should be on unless you know what you are doing. RETURNS ------ p: Eigenvector or Eigenvector matrixthat corresponds to the second smallest eigenvalue of the normalized Laplacian matrix and larger eigenvectors if dim >= 0. """ n = g.adjacency_matrix.shape[0] D_sqrt_neg = sp.sparse.spdiags(g.dn_sqrt.transpose(), 0, n, n) L = sp.sparse.identity(n) - D_sqrt_neg.dot((g.adjacency_matrix.dot(D_sqrt_neg))) emb_eig_val, p = splinalg.eigsh(L, which='SM', k=1+dim, tol = tol_eigs) F = np.real(p[:,1:]) if normalize: F *= g.dn_sqrt[:,np.newaxis] return F, emb_eig_val """ Random walks and local cuts in graphs, Chung, LAA 2007 We just form the sub-matrix of the Laplacian and use the eigenvector there. """
[ 11748, 299, 32152, 355, 45941, 198, 11748, 629, 541, 88, 355, 599, 198, 11748, 629, 541, 88, 13, 82, 29572, 13, 75, 1292, 70, 355, 4328, 1292, 70, 628, 198, 4299, 304, 328, 17, 62, 77, 43, 7, 70, 11, 284, 75, 62, 68, 9235, 796...
2.326456
824
""" ******************************************************************************* * Ledger Blue * (c) 2016 Ledger * * 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. ******************************************************************************** """ from ledgerblue.hexParser import IntelHexParser import argparse parser = argparse.ArgumentParser() parser.add_argument("--hex", help="Hex file to be converted as a C array") args = parser.parse_args() if args.hex == None: raise Exception("Missing hex filename to sign") parser = IntelHexParser(args.hex) for a in parser.getAreas(): if (len(a.data) > 0x10000): raise BaseException("data must be splitted in chunks of 64k") print "0x" + hexU8(a.start >> 24) + ", 0x" + hexU8(a.start >> 16) + ", 0x" + hexU8(a.start >> 8) + ", 0x" + hexU8(a.start) + ", " print "0x" + hexU8(len(a.data) >> 24) + ", 0x" + hexU8(len(a.data) >> 16) + ", 0x" + hexU8(len(a.data) >> 8) + ", 0x" + hexU8(len(a.data)) + ", " # low @ to high @ offset = 0 while offset < len(a.data): string = "" for i in range(8): if offset+i < len(a.data): string += " 0x" + hexU8(a.data[offset+i]) + "," print string offset+=8
[ 37811, 198, 17174, 17174, 46068, 8162, 198, 9, 220, 220, 22964, 1362, 4518, 198, 9, 220, 220, 357, 66, 8, 1584, 22964, 1362, 198, 9, 198, 9, 220, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, ...
3.010753
558
# Copyright 2020 XAMES3. All Rights Reserved. # # 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. # # ====================================================================== """ vdoXA is an open-source python package for trimming the videos. It is built as a subsystem for < XXXXX Not to be named XXXXX > project. Originally inspired by my colleague's work, I thought of improving the concept and build a tool to simplify the process. I hope it comes with strong support for continuous updates, reliable functions and overall ease of use. Read complete documentation at: <https://github.com/xames3/vdoxa>. """ from setuptools import find_packages, setup from vdoxa.vars import dev doclines = __doc__.split('\n') def use_readme() -> str: """Use `README.md` for parsing long description.""" with open('README.md') as file: return file.read() with open('requirements.txt', 'r') as requirements: required_packages = [package.rstrip() for package in requirements] setup( name=dev.PROJECT_NAME, version=dev.PROJECT_VERSION, url=dev.PROJECT_LINK, download_url=dev.PROJECT_LINK, author=dev.AUTHOR, author_email=dev.AUTHOR_EMAIL, maintainer=dev.AUTHOR, maintainer_email=dev.AUTHOR_EMAIL, classifiers=[ 'Intended Audience :: Developers', 'Intended Audience :: End Users/Desktop', 'Intended Audience :: Information Technology', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: Apache Software License', 'Natural Language :: English', ], license=dev.PROJECT_LICENSE, description=f'{doclines[1]}', long_description=use_readme(), long_description_content_type='text/markdown', keywords='opencv2 cv2 moviepy', zip_safe=False, install_requires=required_packages, python_requires='~=3.6', include_package_data=True, packages=find_packages(), entry_points={ 'console_scripts': [ 'vdoxa = vdoxa.parser:main', ], } )
[ 2, 15069, 12131, 1395, 29559, 18, 13, 1439, 6923, 33876, 13, 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, 1...
3.224
750
from django.contrib import messages from django.contrib.auth import login, authenticate from django.shortcuts import render, redirect from django.urls import reverse from django.views import View from application.forms import AuthenticateForm from application.views import get_navbar, Page
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 6218, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 1330, 17594, 11, 8323, 5344, 198, 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 11, 18941, 198, 6738, 42625, 14208, 13, 6371, 82, 1330...
4
73
# Copyright 2017 Mycroft AI 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. # import inspect import logging import sys
[ 2, 15069, 2177, 2011, 36714, 9552, 3457, 13, 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.863354
161
#!/usr/bin/env python # -*- coding: utf-8 -*- import json from alipay.aop.api.response.AlipayResponse import AlipayResponse
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 33918, 198, 198, 6738, 435, 541, 323, 13, 64, 404, 13, 15042, 13, 26209, 13, 2348, 541, 323, 31077, 1330, 978,...
2.571429
49
import os from PyQt5 import QtCore from PyQt5.QtCore import QRect, QPoint from PyQt5.QtGui import QMovie, QCloseEvent, QShowEvent from PyQt5.QtWidgets import QDialog, QLabel, QVBoxLayout, QApplication, QWidget
[ 11748, 28686, 198, 198, 6738, 9485, 48, 83, 20, 1330, 33734, 14055, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 14055, 1330, 42137, 478, 11, 1195, 12727, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 8205, 72, 1330, 1195, 25097, 11, 1195,...
2.65
80
# # PySNMP MIB module MWORKS-MIB (http://snmplabs.com/pysmi) # ASN.1 source file:///Users/davwang4/Dev/mibs.snmplabs.com/asn1/MWORKS-MIB # Produced by pysmi-0.3.4 at Wed May 1 14:16:04 2019 # On host DAVWANG4-M-1475 platform Darwin version 18.5.0 by user davwang4 # Using Python version 3.7.3 (default, Mar 27 2019, 09:23:15) # ObjectIdentifier, OctetString, Integer = mibBuilder.importSymbols("ASN1", "ObjectIdentifier", "OctetString", "Integer") NamedValues, = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues") ValueRangeConstraint, SingleValueConstraint, ConstraintsUnion, ValueSizeConstraint, ConstraintsIntersection = mibBuilder.importSymbols("ASN1-REFINEMENT", "ValueRangeConstraint", "SingleValueConstraint", "ConstraintsUnion", "ValueSizeConstraint", "ConstraintsIntersection") ModuleCompliance, NotificationGroup = mibBuilder.importSymbols("SNMPv2-CONF", "ModuleCompliance", "NotificationGroup") Gauge32, Unsigned32, ObjectIdentity, IpAddress, Bits, MibIdentifier, Integer32, enterprises, ModuleIdentity, TimeTicks, Counter32, NotificationType, iso, Counter64, MibScalar, MibTable, MibTableRow, MibTableColumn = mibBuilder.importSymbols("SNMPv2-SMI", "Gauge32", "Unsigned32", "ObjectIdentity", "IpAddress", "Bits", "MibIdentifier", "Integer32", "enterprises", "ModuleIdentity", "TimeTicks", "Counter32", "NotificationType", "iso", "Counter64", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn") TextualConvention, DisplayString = mibBuilder.importSymbols("SNMPv2-TC", "TextualConvention", "DisplayString") tecElite = MibIdentifier((1, 3, 6, 1, 4, 1, 217)) meterWorks = MibIdentifier((1, 3, 6, 1, 4, 1, 217, 16)) mw501 = MibIdentifier((1, 3, 6, 1, 4, 1, 217, 16, 1)) mwMem = MibIdentifier((1, 3, 6, 1, 4, 1, 217, 16, 1, 1)) mwHeap = MibIdentifier((1, 3, 6, 1, 4, 1, 217, 16, 1, 2)) mwMemCeiling = MibScalar((1, 3, 6, 1, 4, 1, 217, 16, 1, 1, 1), Counter32()).setMaxAccess("readonly") if mibBuilder.loadTexts: mwMemCeiling.setStatus('mandatory') if mibBuilder.loadTexts: mwMemCeiling.setDescription('bytes of memory the agent memory manager will allow the agent to use.') mwMemUsed = MibScalar((1, 3, 6, 1, 4, 1, 217, 16, 1, 1, 2), Counter32()).setMaxAccess("readonly") if mibBuilder.loadTexts: mwMemUsed.setStatus('mandatory') if mibBuilder.loadTexts: mwMemUsed.setDescription("bytes of memory that meterworks has malloc'ed. some of this may be in free pools.") mwHeapTotal = MibScalar((1, 3, 6, 1, 4, 1, 217, 16, 1, 2, 1), Counter32()).setMaxAccess("readonly") if mibBuilder.loadTexts: mwHeapTotal.setStatus('mandatory') if mibBuilder.loadTexts: mwHeapTotal.setDescription('bytes of memory given to the heap manager.') mwHeapUsed = MibScalar((1, 3, 6, 1, 4, 1, 217, 16, 1, 2, 2), Counter32()).setMaxAccess("readonly") if mibBuilder.loadTexts: mwHeapUsed.setStatus('mandatory') if mibBuilder.loadTexts: mwHeapUsed.setDescription('bytes of available memory in the heap.') mibBuilder.exportSymbols("MWORKS-MIB", mwHeap=mwHeap, mwHeapUsed=mwHeapUsed, mwMemCeiling=mwMemCeiling, meterWorks=meterWorks, tecElite=tecElite, mwMem=mwMem, mw501=mw501, mwHeapTotal=mwHeapTotal, mwMemUsed=mwMemUsed)
[ 2, 198, 2, 9485, 15571, 7378, 337, 9865, 8265, 29961, 14670, 50, 12, 8895, 33, 357, 4023, 1378, 16184, 76, 489, 8937, 13, 785, 14, 79, 893, 11632, 8, 198, 2, 7054, 45, 13, 16, 2723, 2393, 1378, 14, 14490, 14, 67, 615, 47562, 19,...
2.624263
1,187
#!/usr/bin/env python import sys import re from subprocess import Popen, PIPE import argparse from pbxproj import XcodeProject, TreeType from pbxproj import FileOptions if __name__ == "__main__": main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 11748, 25064, 198, 11748, 302, 198, 6738, 850, 14681, 1330, 8099, 268, 11, 350, 4061, 36, 198, 11748, 1822, 29572, 198, 198, 6738, 279, 65, 87, 1676, 73, 1330, 1395, 8189, 16775, ...
2.837838
74
# == 1 == bar = [1, 2] print(foo(bar)) # == 2 == bar = [1, 2] print(foo(bar)) # == 3 == bar = [1, 2] print(foo()) # == 4 == bar = [1, 2] print(foo(bar), bar) # == 5 == bar = [1, 2] print(foo(bar), bar) # == 6 == try: bar = 1 / 0 print(bar) except ZeroDivisionError as bar: print(bar) print(bar) # == 7 == bar = [1, 2] print(list(bar for bar in bar)) print(bar) # == 8 == bar = [1, 2] f = lambda: sum(bar) print(f()) bar = [1, 2, 3, ] print(f()) # == 9 == bar = [1, 2] f = foo(bar) print(f()) bar = [1, 2, 3, ] print(f()) # == 10 == bar = [1, 2] foo = [] for i in bar: foo.append(lambda: i) print([f() for f in foo]) # == 11 == bar = [1, 2] foo = [ lambda: i for i in bar ] print(list(f() for f in foo)) # == 12 == bar = [1, 2] foo = [ lambda: i for i in bar ] print(list(f() for f in foo)) bar = [1, 2, 3, ] print(list(f() for f in foo)) bar[:] = [1, 2, 3, ] print(list(f() for f in foo)) # == 13 == bar = [1, 2] foo = [ lambda i=i: i for i in bar ] print(list(f() for f in foo))
[ 2, 6624, 220, 352, 220, 6624, 198, 5657, 796, 685, 16, 11, 362, 60, 198, 4798, 7, 21943, 7, 5657, 4008, 628, 198, 2, 6624, 220, 362, 220, 6624, 198, 5657, 796, 685, 16, 11, 362, 60, 198, 4798, 7, 21943, 7, 5657, 4008, 628, 198...
1.987085
542
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Author: Chmouel Boudjnah <chmouel@chmouel.com> # # 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. # See README.md for documentation import typing import argparse import base64 import hashlib import hmac import json import os import subprocess import sys import time import requests import ghapp_token NAMESPACE = "pipelines-as-code" SECRET_NAME = "pipelines-as-code-secret" ELNAME = "pipelines-as-code" EXPIRE_MINUTES_AS_SECONDS = ( int(os.environ.get("GITHUBAPP_TOKEN_EXPIRATION_MINUTES", 10)) * 60 ) if __name__ == "__main__": main(parse_args())
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 6434, 25, 609, 76, 280, 417, 347, 2778, 73, 40909, 1279, 354, 76, 280, 417, 31, 354, 76, 280, 417, 13, 785...
3.008065
372
from .algolia import search_by_nsuid from .algolia import search_by_platform from .algolia import search_by_query
[ 6738, 764, 14016, 22703, 1330, 2989, 62, 1525, 62, 77, 2385, 312, 198, 6738, 764, 14016, 22703, 1330, 2989, 62, 1525, 62, 24254, 198, 6738, 764, 14016, 22703, 1330, 2989, 62, 1525, 62, 22766, 198 ]
3.257143
35
# Other solution # V2 # Time: O(|S|+|T|) # Space:O(|S|+|T|) # Refer from: # https://leetcode.com/problems/minimum-window-substring/solution/ # Sliding Window # We start with two pointers, leftleft and rightright initially pointing to the first element of the string S. # We use the rightright pointer to expand the window until we get a desirable window i.e. a window that contains all of the characters of T. # Once we have a window with all the characters, we can move the left pointer ahead one by one. If the window is still a desirable one we keep on updating the minimum window size. # If the window is not desirable any more, we repeat step 2 onwards. # The current window is s[i:j] and the result window is s[I:J]. In need[c] I store how many times I # need character c (can be negative) and missing tells how many characters are still missing. # In the loop, first add the new character to the window. Then, if nothing is missing, # remove as much as possible from the window start and then update the result. # Time: O(|S|+|T|) # Space:O(|S|+|T|) # Optimized Sliding Window # A small improvement to the above approach can reduce the time complexity of the algorithm to O(2*filtered_S+S+T), # where filtered(S) is the string formed from S by removing all the elements not present in T
[ 198, 2, 3819, 4610, 198, 2, 569, 17, 198, 198, 2, 3862, 25, 440, 7, 91, 50, 91, 10, 91, 51, 91, 8, 198, 2, 4687, 25, 46, 7, 91, 50, 91, 10, 91, 51, 91, 8, 198, 198, 2, 33973, 422, 25, 198, 2, 3740, 1378, 293, 316, 8189...
3.451444
381
# -*- coding: utf-8 -*- # Generated by Django 1.11.5 on 2017-10-17 04:12 from __future__ import unicode_literals from django.db import migrations import wagtail.core.blocks import wagtail.core.fields
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 37770, 352, 13, 1157, 13, 20, 319, 2177, 12, 940, 12, 1558, 8702, 25, 1065, 198, 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, ...
2.767123
73
import torch import torch.nn as nn import torch.nn.functional as F
[ 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 11748, 28034, 13, 20471, 13, 45124, 355, 376, 628, 198 ]
3.285714
21
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import unittest from unittest.mock import patch, MagicMock from typing import List, Tuple from .. import Storage # Module import to ensure we get plugins
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 15069, 357, 66, 8, 3203, 11, 3457, 13, 290, 663, 29116, 13, 198, 2, 198, 2, 770, 2723, 2438, 318, 11971, 739, 262, 17168, 5964, 1043, 287, 262, 198, 2, 38559, 24290, 2393, ...
3.663265
98
# coding=utf-8 # *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** # *** Do not edit by hand unless you're certain you know what you are doing! *** import warnings import pulumi import pulumi.runtime from typing import Any, Mapping, Optional, Sequence, Union, overload from .. import _utilities from . import outputs __all__ = [ 'GetKMSCryptoKeyVersionResult', 'AwaitableGetKMSCryptoKeyVersionResult', 'get_kms_crypto_key_version', 'get_kms_crypto_key_version_output', ] def get_kms_crypto_key_version(crypto_key: Optional[str] = None, version: Optional[int] = None, opts: Optional[pulumi.InvokeOptions] = None) -> AwaitableGetKMSCryptoKeyVersionResult: """ Provides access to a Google Cloud Platform KMS CryptoKeyVersion. For more information see [the official documentation](https://cloud.google.com/kms/docs/object-hierarchy#key_version) and [API](https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.cryptoKeys.cryptoKeyVersions). A CryptoKeyVersion represents an individual cryptographic key, and the associated key material. ## Example Usage ```python import pulumi import pulumi_gcp as gcp my_key_ring = gcp.kms.get_kms_key_ring(name="my-key-ring", location="us-central1") my_crypto_key = gcp.kms.get_kms_crypto_key(name="my-crypto-key", key_ring=my_key_ring.id) my_crypto_key_version = gcp.kms.get_kms_crypto_key_version(crypto_key=data["google_kms_key"]["my_key"]["id"]) ``` :param str crypto_key: The `self_link` of the Google Cloud Platform CryptoKey to which the key version belongs. This is also the `id` field of the `kms.CryptoKey` resource/datasource. :param int version: The version number for this CryptoKeyVersion. Defaults to `1`. """ __args__ = dict() __args__['cryptoKey'] = crypto_key __args__['version'] = version if opts is None: opts = pulumi.InvokeOptions() if opts.version is None: opts.version = _utilities.get_version() __ret__ = pulumi.runtime.invoke('gcp:kms/getKMSCryptoKeyVersion:getKMSCryptoKeyVersion', __args__, opts=opts, typ=GetKMSCryptoKeyVersionResult).value return AwaitableGetKMSCryptoKeyVersionResult( algorithm=__ret__.algorithm, crypto_key=__ret__.crypto_key, id=__ret__.id, name=__ret__.name, protection_level=__ret__.protection_level, public_keys=__ret__.public_keys, state=__ret__.state, version=__ret__.version)
[ 2, 19617, 28, 40477, 12, 23, 198, 2, 17202, 39410, 25, 428, 2393, 373, 7560, 416, 262, 21624, 12994, 24118, 687, 10290, 357, 27110, 5235, 8, 16984, 13, 17202, 198, 2, 17202, 2141, 407, 4370, 416, 1021, 4556, 345, 821, 1728, 345, 760...
2.524085
1,038
#!/usr/bin/env python3 import itertools # Constants NUMBERS = range(0, 10) # Main Execution if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 11748, 340, 861, 10141, 198, 198, 2, 4757, 1187, 198, 198, 41359, 33, 4877, 796, 2837, 7, 15, 11, 838, 8, 198, 198, 2, 8774, 37497, 198, 198, 361, 11593, 3672, 834, 6624, ...
2.410714
56
# Copyright (C) 2015-2021 Regents of the University of California # # 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 enum import logging import os import shutil from abc import ABC, abstractmethod from argparse import ArgumentParser, _ArgumentGroup from contextlib import contextmanager from typing import (Any, Callable, ContextManager, Dict, Iterator, List, Optional, Tuple, Type, TypeVar, Union, NamedTuple) from toil.common import Toil, cacheDirName, Config from toil.deferred import DeferredFunctionManager from toil.fileStores.abstractFileStore import AbstractFileStore from toil.job import JobDescription from toil.resource import Resource logger = logging.getLogger(__name__) # Value to use as exitStatus in UpdatedBatchJobInfo.exitStatus when status is not available. EXIT_STATUS_UNAVAILABLE_VALUE = 255 # Information required for worker cleanup on shutdown of the batch system. # FIXME: Return value should be a set (then also fix the tests) def getSchedulingStatusMessage(self) -> Optional[str]: """ Get a log message fragment for the user about anything that might be going wrong in the batch system, if available. If no useful message is available, return None. This can be used to report what resource is the limiting factor when scheduling jobs, for example. If the leader thinks the workflow is stuck, the message can be displayed to the user to help them diagnose why it might be stuck. :return: User-directed message about scheduling state. """ # Default implementation returns None. # Override to provide scheduling status information. return None def setEnv(self, name: str, value: Optional[str] = None) -> None: """ Set an environment variable for the worker process before it is launched. The worker process will typically inherit the environment of the machine it is running on but this method makes it possible to override specific variables in that inherited environment before the worker is launched. Note that this mechanism is different to the one used by the worker internally to set up the environment of a job. A call to this method affects all jobs issued after this method returns. Note to implementors: This means that you would typically need to copy the variables before enqueuing a job. If no value is provided it will be looked up from the current environment. """ raise NotImplementedError() OptionType = TypeVar('OptionType') def getWorkerContexts(self) -> List[ContextManager[Any]]: """ Get a list of picklable context manager objects to wrap worker work in, in order. Can be used to ask the Toil worker to do things in-process (such as configuring environment variables, hot-deploying user scripts, or cleaning up a node) that would otherwise require a wrapping "executor" process. """ return [] class BatchSystemSupport(AbstractBatchSystem): """ Partial implementation of AbstractBatchSystem, support methods. """ def __init__(self, config: Config, maxCores: float, maxMemory: int, maxDisk: int) -> None: """ Initializes initial state of the object :param toil.common.Config config: object is setup by the toilSetup script and has configuration parameters for the jobtree. You can add code to that script to get parameters for your batch system. :param float maxCores: the maximum number of cores the batch system can request for any one job :param int maxMemory: the maximum amount of memory the batch system can request for any one job, in bytes :param int maxDisk: the maximum amount of disk space the batch system can request for any one job, in bytes """ super().__init__() self.config = config self.maxCores = maxCores self.maxMemory = maxMemory self.maxDisk = maxDisk self.environment: Dict[str, str] = {} self.workerCleanupInfo = WorkerCleanupInfo(workDir=self.config.workDir, workflowID=self.config.workflowID, cleanWorkDir=self.config.cleanWorkDir) def checkResourceRequest(self, memory: int, cores: float, disk: int, job_name: str = '', detail: str = '') -> None: """ Check resource request is not greater than that available or allowed. :param int memory: amount of memory being requested, in bytes :param float cores: number of cores being requested :param int disk: amount of disk space being requested, in bytes :param str job_name: Name of the job being checked, for generating a useful error report. :param str detail: Batch-system-specific message to include in the error. :raise InsufficientSystemResources: raised when a resource is requested in an amount greater than allowed """ batch_system = self.__class__.__name__ or 'this batch system' for resource, requested, available in [('cores', cores, self.maxCores), ('memory', memory, self.maxMemory), ('disk', disk, self.maxDisk)]: assert requested is not None if requested > available: unit = 'bytes of ' if resource in ('disk', 'memory') else '' R = f'The job {job_name} is r' if job_name else 'R' if resource == 'disk': msg = (f'{R}equesting {requested} {unit}{resource} for temporary space, ' f'more than the maximum of {available} {unit}{resource} of free space on ' f'{self.config.workDir} that {batch_system} was configured with, or enforced ' f'by --max{resource.capitalize()}. Try setting/changing the toil option ' f'"--workDir" or changing the base temporary directory by setting TMPDIR.') else: msg = (f'{R}equesting {requested} {unit}{resource}, more than the maximum of ' f'{available} {unit}{resource} that {batch_system} was configured with, ' f'or enforced by --max{resource.capitalize()}.') if detail: msg += detail raise InsufficientSystemResources(msg) def setEnv(self, name: str, value: Optional[str] = None) -> None: """ Set an environment variable for the worker process before it is launched. The worker process will typically inherit the environment of the machine it is running on but this method makes it possible to override specific variables in that inherited environment before the worker is launched. Note that this mechanism is different to the one used by the worker internally to set up the environment of a job. A call to this method affects all jobs issued after this method returns. Note to implementors: This means that you would typically need to copy the variables before enqueuing a job. If no value is provided it will be looked up from the current environment. :param str name: the environment variable to be set on the worker. :param str value: if given, the environment variable given by name will be set to this value. if None, the variable's current value will be used as the value on the worker :raise RuntimeError: if value is None and the name cannot be found in the environment """ if value is None: try: value = os.environ[name] except KeyError: raise RuntimeError(f"{name} does not exist in current environment") self.environment[name] = value def formatStdOutErrPath(self, toil_job_id: int, cluster_job_id: str, std: str) -> str: """ Format path for batch system standard output/error and other files generated by the batch system itself. Files will be written to the Toil work directory (which may be on a shared file system) with names containing both the Toil and batch system job IDs, for ease of debugging job failures. :param: int toil_job_id : The unique id that Toil gives a job. :param: cluster_job_id : What the cluster, for example, GridEngine, uses as its internal job id. :param: string std : The provenance of the stream (for example: 'err' for 'stderr' or 'out' for 'stdout') :rtype: string : Formatted filename; however if self.config.noStdOutErr is true, returns '/dev/null' or equivalent. """ if self.config.noStdOutErr: return os.devnull fileName: str = f'toil_{self.config.workflowID}.{toil_job_id}.{cluster_job_id}.{std}.log' workDir: str = Toil.getToilWorkDir(self.config.workDir) return os.path.join(workDir, fileName)
[ 2, 15069, 357, 34, 8, 1853, 12, 1238, 2481, 3310, 658, 286, 262, 2059, 286, 3442, 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, ...
2.67331
3,713
# -*- coding: utf-8 -*- from lite_tools import get_md5, get_sha, get_sha3, get_b64e, get_b64d # about hashlib ==> get_md5, get_sha, get_sha3 || default mode=256 s = "test_information" # print(get_md5(s)) # 5414ffd88fcb58417e64ecec51bb3a6b print(get_md5(s, upper=True)) # 5414FFD88FCB58417E64ECEC51BB3A6B print(get_md5(s, to_bin=True)) # b'T\x14\xff\xd8\x8f\xcbXA~d\xec\xecQ\xbb:k' # print(get_sha(s)) # d09869fdf901465c8566f0e2debfa3f6a3d878a8157e199c7c4c6dd755617f33 print(get_sha(s, to_bin=True)) # b'\xd0\x98i\xfd\xf9\x01F\\\x85f\xf0\xe2\xde\xbf\xa3\xf6\xa3\xd8x\xa8\x15~\x19\x9c|Lm\xd7Ua\x7f3' print(get_sha(s, mode=1)) # ada5dfdf0c9a76a84958310b838a70b6fd6d01f6 # default mode=256 // mode: 1 224 256 384 512 print(get_sha3(s)) # 9c539ca35c6719f546e67837ff37fe7791e53fe40715cd4da0167c78c9adc2e8 print(get_sha3(s, to_bin=True)) # b'\x9cS\x9c\xa3\\g\x19\xf5F\xe6x7\xff7\xfew\x91\xe5?\xe4\x07\x15\xcdM\xa0\x16|x\xc9\xad\xc2\xe8' print(get_sha3(s, mode=1)) # return "" // SUPPORT: sha3_224 sha3_256 sha3_384 sha3_512// only need inputting: 224 256 384 512 # default mode=256 // mode: 224 256 384 512 print(get_sha3(s, mode=384)) # 95c09e20a139843eae877a64cd95d6a629b3c9ff383b5460557aab2612682d4228d05fe41606a79acf5ae1c4de35160c # about base64 ==> get_b64e, get_b64d res_b64_encode = get_b64e(s) print(res_b64_encode) # dGVzdF9pbmZvcm1hdGlvbg== res_b64_bin = get_b64e(s, to_bin=True) print(res_b64_bin) # b'dGVzdF9pbmZvcm1hdGlvbg==' res_b32_encode = get_b64e(s, mode=32) # default mode=64 // mode: 16 32 64 85 print(res_b32_encode) # ORSXG5C7NFXGM33SNVQXI2LPNY====== res_b64_decode = get_b64d(res_b64_encode) print(res_b64_decode) # test_information res_b32_decode = get_b64d(res_b32_encode, mode=32) # default mode=64 // mode: 16 32 64 85 print(res_b32_decode) # test_information
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 6738, 300, 578, 62, 31391, 1330, 651, 62, 9132, 20, 11, 651, 62, 26270, 11, 651, 62, 26270, 18, 11, 651, 62, 65, 2414, 68, 11, 651, 62, 65, 2414, 67, 628, 198, 2...
1.755194
1,107
__all__ = ["mock_pv_info", "test_pv_tracking"]
[ 834, 439, 834, 796, 14631, 76, 735, 62, 79, 85, 62, 10951, 1600, 366, 9288, 62, 79, 85, 62, 36280, 8973, 198 ]
2.136364
22
import carmcmc as cm from gatspy.periodic import LombScargleFast import matplotlib.pyplot as plt import numpy as np
[ 11748, 1097, 76, 11215, 66, 355, 12067, 198, 6738, 308, 1381, 9078, 13, 41007, 291, 1330, 28503, 3351, 853, 293, 22968, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 11748, 299, 32152, 355, 45941, 628 ]
3
39
# Fast large file synchronization inspired by rsync. # # Author: Peter Odding <peter@peterodding.com> # Last Change: March 6, 2020 # URL: https://pdiffcopy.readthedocs.io """Parallel hashing of files using :mod:`multiprocessing` and :mod:`pdiffcopy.mp`.""" # Standard library modules. import functools import hashlib import os # External dependencies. from six.moves import range # Modules included in our package. from pdiffcopy.mp import WorkerPool # Public identifiers that require documentation. __all__ = ("compute_hashes", "hash_worker") def hash_worker(offset, block_size, filename, method): """Worker function to be run in child processes.""" with open(filename, "rb") as handle: handle.seek(offset) context = hashlib.new(method) context.update(handle.read(block_size)) return offset, context.hexdigest()
[ 2, 12549, 1588, 2393, 42133, 7867, 416, 374, 27261, 13, 198, 2, 198, 2, 6434, 25, 5613, 20664, 278, 1279, 79, 2357, 31, 79, 2357, 5088, 278, 13, 785, 29, 198, 2, 4586, 9794, 25, 2805, 718, 11, 12131, 198, 2, 10289, 25, 3740, 137...
3.021053
285
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved. # # 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. from __future__ import print_function import unittest from pyscf.nao.m_siesta_utils import get_siesta_command, get_pseudo if __name__ == "__main__": unittest.main()
[ 2, 15069, 1946, 12, 7908, 383, 9485, 6173, 37, 34152, 13, 1439, 6923, 33876, 13, 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...
3.568807
218
import pytest from moz_library.rental_books import RentalBooks
[ 11748, 12972, 9288, 198, 6738, 6941, 89, 62, 32016, 13, 1156, 282, 62, 12106, 1330, 371, 2470, 30650, 628 ]
3.368421
19
import aspose.pydrawing as drawing import aspose.slides as slides
[ 11748, 355, 3455, 13, 79, 5173, 1831, 278, 355, 8263, 198, 11748, 355, 3455, 13, 6649, 1460, 355, 19392 ]
3.421053
19
from django import forms from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.utils.translation import gettext as _ from dcim.models import DeviceRole, DeviceType, Platform, Region, Site, SiteGroup from extras.choices import * from extras.models import * from extras.utils import FeatureQuery from netbox.forms.base import NetBoxModelFilterSetForm from tenancy.models import Tenant, TenantGroup from utilities.forms import ( add_blank_choice, APISelectMultiple, BOOLEAN_WITH_BLANK_CHOICES, ContentTypeChoiceField, ContentTypeMultipleChoiceField, DateTimePicker, DynamicModelMultipleChoiceField, FilterForm, MultipleChoiceField, StaticSelect, TagFilterField, ) from virtualization.models import Cluster, ClusterGroup, ClusterType __all__ = ( 'ConfigContextFilterForm', 'CustomFieldFilterForm', 'CustomLinkFilterForm', 'ExportTemplateFilterForm', 'JournalEntryFilterForm', 'LocalConfigContextFilterForm', 'ObjectChangeFilterForm', 'TagFilterForm', 'WebhookFilterForm', )
[ 6738, 42625, 14208, 1330, 5107, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 11787, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 11299, 19199, 13, 27530, 1330, 14041, 6030, 198, 6738, 42625, 14208, 13, 26791, 13, 4...
3.427673
318
#!/usr/bin/python3 ## write2cly.py - reads json (generated by sml_reader.py) from stdin ## - writes values to Corlysis time series InfluxDB ## ## Writes data from smart meter to time series database (InfluxDB) ## at Corlysis.com [1]. You need to configure your database and token ## in the config section. ## ## [1] https://corlysis.com/ ##==== license section ======== ## This code is under MIT License: Copyright (C) 2019 Bernd Knnen ## License details see https://choosealicense.com/licenses/mit/ ##==== config section ======== # define corlysis settings here - set db and token at least cly_base_url = 'https://corlysis.com:8086/write' cly_parameters = { "db": "energy", "u" : "token", "p" : "placeyourtokenhere", "precision": "ms"} # assign readable field names config = { "1.8.0": "Bezug", "2.8.0": "Einspeisung", "16.7.0": "Wirkleistung" } ##==== code section ==== no need to change lines below ==== ##-- import libraries import json, sys, requests import requests import time # load json from stdin try: myjson = json.load(sys.stdin) except: sys.stderr.write('!! error loading json') exit(1) # decode json try: line = "meter_data " # add each meter value to line for obis in myjson['data']: key = config[obis] # set human readable field name value = myjson['data'][obis] # get value from smart meter line += key + '=' + str(value) + ',' # add key=value to insert line # cut off last comma line = line[:-1] # add timestamp as unix timestamp in ms line += ' ' + str(int(time.time()*1000)) #+ '\n' # post data into time series database; http response should be 204 r = requests.post(cly_base_url, params=cly_parameters, data=line) if r.status_code != 204 : sys.stderr.write(r.status_code) sys.stderr.write(r.content) # catch if input is no valid json except: sys.stderr.write('!!error: no data block in json') exit(2)
[ 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 198, 2235, 3551, 17, 66, 306, 13, 9078, 220, 220, 532, 9743, 33918, 357, 27568, 416, 895, 75, 62, 46862, 13, 9078, 8, 422, 14367, 259, 198, 2235, 220, 220, 220, 220, 220, 220, 220, ...
2.762108
702
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, # provided that the above copyright notice and this permission notice # appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """Class ANY (generic) rdata type classes.""" __all__ = [ 'AFSDB', 'AMTRELAY', 'AVC', 'CAA', 'CDNSKEY', 'CDS', 'CERT', 'CNAME', 'CSYNC', 'DLV', 'DNAME', 'DNSKEY', 'DS', 'EUI48', 'EUI64', 'GPOS', 'HINFO', 'HIP', 'ISDN', 'LOC', 'MX', 'NINFO', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', 'OPENPGPKEY', 'OPT', 'PTR', 'RP', 'RRSIG', 'RT', 'SMIMEA', 'SOA', 'SPF', 'SSHFP', 'TKEY', 'TLSA', 'TSIG', 'TXT', 'URI', 'X25', ]
[ 2, 15069, 357, 34, 8, 360, 77, 2777, 7535, 25767, 669, 11, 766, 38559, 24290, 329, 2420, 286, 3180, 34, 5964, 198, 198, 2, 15069, 357, 34, 8, 5816, 12, 12726, 11, 3717, 12, 9804, 399, 6351, 388, 11, 3457, 13, 198, 2, 198, 2, 2...
2.318841
621
""" @file 01_test.py @brief Script for test @author Toshiki Nakamura, Yuki Nikaido, and Yohei Kawaguchi (Hitachi Ltd.) Copyright (C) 2020 Hitachi, Ltd. All right reserved. """ ######################################################################## # import default python-library ######################################################################## import os import glob import csv import re import itertools import sys ######################################################################## ######################################################################## # import additional python-library ######################################################################## import numpy # from import from tqdm import tqdm from sklearn import metrics # original lib import common as com import keras_model ######################################################################## ######################################################################## # load parameter.yaml ######################################################################## param = com.yaml_load() ####################################################################### ######################################################################## # def ######################################################################## def get_machine_id_list_for_test(target_dir, dir_name="test", ext="json"): """ target_dir : str base directory path of "dev_data" or "eval_data" test_dir_name : str (default="test") directory containing test data ext : str (default="wav) file extension of audio files return : machine_id_list : list [ str ] list of machine IDs extracted from the names of test files """ # create test files dir_path = os.path.abspath("{dir}/{dir_name}/*.{ext}".format(dir=target_dir, dir_name=dir_name, ext=ext)) file_paths = sorted(glob.glob(dir_path)) # extract id machine_id_list = sorted(list(set(itertools.chain.from_iterable( [re.findall('id_[0-9][0-9]', ext_id) for ext_id in file_paths])))) return machine_id_list def test_file_list_generator(target_dir, id_name, dir_name="test", prefix_normal="normal", prefix_anomaly="anomaly", ext="json"): """ target_dir : str base directory path of the dev_data or eval_data id_name : str id of wav file in <<test_dir_name>> directory dir_name : str (default="test") directory containing test data prefix_normal : str (default="normal") normal directory name prefix_anomaly : str (default="anomaly") anomaly directory name ext : str (default="wav") file extension of audio files return : if the mode is "development": test_files : list [ str ] file list for test test_labels : list [ boolean ] label info. list for test * normal/anomaly = 0/1 if the mode is "evaluation": test_files : list [ str ] file list for test """ com.logger.info("target_dir : {}".format(target_dir+"_"+id_name)) # development if mode: normal_files = sorted( glob.glob("{dir}/{dir_name}/{prefix_normal}_{id_name}*.{ext}".format(dir=target_dir, dir_name=dir_name, prefix_normal=prefix_normal, id_name=id_name, ext=ext))) normal_labels = numpy.zeros(len(normal_files)) anomaly_files = sorted( glob.glob("{dir}/{dir_name}/{prefix_anomaly}_{id_name}*.{ext}".format(dir=target_dir, dir_name=dir_name, prefix_anomaly=prefix_anomaly, id_name=id_name, ext=ext))) anomaly_labels = numpy.ones(len(anomaly_files)) files = numpy.concatenate((normal_files, anomaly_files), axis=0) labels = numpy.concatenate((normal_labels, anomaly_labels), axis=0) com.logger.info("test_file num : {num}".format(num=len(files))) if len(files) == 0: com.logger.exception("no_wav_file!!") print("\n========================================") # evaluation else: files = sorted( glob.glob("{dir}/{dir_name}/*{id_name}*.{ext}".format(dir=target_dir, dir_name=dir_name, id_name=id_name, ext=ext))) labels = None com.logger.info("test_file num : {num}".format(num=len(files))) if len(files) == 0: com.logger.exception("no_wav_file!!") print("\n=========================================") return files, labels ######################################################################## ######################################################################## # main 01_test.py ######################################################################## if __name__ == "__main__": # check mode # "development": mode == True # "evaluation": mode == False mode = com.command_line_chk() if mode is None: sys.exit(-1) # make output result directory os.makedirs(param["result_directory"], exist_ok=True) # load base directory dirs = com.select_dirs(param=param, mode=mode) # initialize lines in csv for AUC and pAUC csv_lines = [] # loop of the base directory for idx, target_dir in enumerate(dirs): print("\n===========================") print("[{idx}/{total}] {dirname}".format(dirname=target_dir, idx=idx+1, total=len(dirs))) machine_type = os.path.split(target_dir)[1] print("============== MODEL LOAD ==============") # set model path model_file = "{model}/model_{machine_type}.hdf5".format(model=param["model_directory"], machine_type=machine_type) # load model file if not os.path.exists(model_file): com.logger.error("{} model not found ".format(machine_type)) sys.exit(-1) model = keras_model.load_model(model_file) model.summary() if mode: # results by type csv_lines.append([machine_type]) csv_lines.append(["id", "AUC", "pAUC"]) performance = [] machine_id_list = get_machine_id_list_for_test(target_dir) print(machine_id_list) for id_str in machine_id_list: # load test file test_files, y_true = test_file_list_generator(target_dir, id_str) # setup anomaly score file path anomaly_score_csv = "{result}/anomaly_score_{machine_type}_{id_str}.csv".format( result=param["result_directory"], machine_type=machine_type, id_str=id_str) anomaly_score_list = [] print("\n============== BEGIN TEST FOR A MACHINE ID ==============") y_pred = [0. for k in test_files] for file_idx, file_path in tqdm(enumerate(test_files), total=len(test_files)): try: data = com.file_to_vector_array(file_path, n_mels=param["feature"]["n_mels"], frames=param["feature"]["frames"], n_fft=param["feature"]["n_fft"], hop_length=param["feature"]["hop_length"], power=param["feature"]["power"]) errors = numpy.mean(numpy.square(data - model.predict(data)), axis=1) y_pred[file_idx] = numpy.mean(errors) anomaly_score_list.append([os.path.basename(file_path), y_pred[file_idx]]) except: com.logger.error("file broken!!: {}".format(file_path)) # save anomaly score save_csv(save_file_path=anomaly_score_csv, save_data=anomaly_score_list) com.logger.info("anomaly score result -> {}".format(anomaly_score_csv)) if mode: # append AUC and pAUC to lists auc = metrics.roc_auc_score(y_true, y_pred) p_auc = metrics.roc_auc_score(y_true, y_pred, max_fpr=param["max_fpr"]) csv_lines.append([id_str.split("_", 1)[1], auc, p_auc]) performance.append([auc, p_auc]) com.logger.info("AUC : {}".format(auc)) com.logger.info("pAUC : {}".format(p_auc)) print("\n============ END OF TEST FOR A MACHINE ID ============") if mode: # calculate averages for AUCs and pAUCs averaged_performance = numpy.mean(numpy.array(performance, dtype=float), axis=0) csv_lines.append(["Average"] + list(averaged_performance)) csv_lines.append([]) if mode: # output results result_path = "{result}/{file_name}".format(result=param["result_directory"], file_name=param["result_file"]) com.logger.info("AUC and pAUC results -> {}".format(result_path)) save_csv(save_file_path=result_path, save_data=csv_lines)
[ 37811, 198, 2488, 7753, 220, 220, 5534, 62, 9288, 13, 9078, 198, 2488, 65, 3796, 220, 12327, 329, 1332, 198, 2488, 9800, 47922, 5580, 22255, 37324, 11, 575, 11308, 11271, 44354, 11, 290, 25455, 27392, 23043, 363, 22200, 357, 17889, 1429...
2.037096
5,068
import argparse import os parser = argparse.ArgumentParser(description="a simple parser") parser.add_argument("filename", type=str) parser.add_argument("lineno", nargs="+", type=int) parser.add_argument("--same_length", action=argparse.BooleanOptionalAction)
[ 11748, 1822, 29572, 198, 11748, 28686, 198, 198, 48610, 796, 1822, 29572, 13, 28100, 1713, 46677, 7, 11213, 2625, 64, 2829, 30751, 4943, 198, 198, 48610, 13, 2860, 62, 49140, 7203, 34345, 1600, 2099, 28, 2536, 8, 198, 48610, 13, 2860, ...
3.316456
79
from __future__ import absolute_import import six import string import warnings import pytz from collections import OrderedDict from dateutil.parser import parse as parse_date from django.db import models from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from hashlib import md5 from semaphore.processing import StoreNormalizer from sentry import eventtypes from sentry.db.models import ( BoundedBigIntegerField, BoundedIntegerField, Model, NodeData, NodeField, sane_repr, ) from sentry.db.models.manager import EventManager from sentry.interfaces.base import get_interfaces from sentry.utils import json from sentry.utils.cache import memoize from sentry.utils.canonical import CanonicalKeyDict, CanonicalKeyView from sentry.utils.safe import get_path from sentry.utils.strings import truncatechars def get_interface(self, name): return self.interfaces.get(name) def get_legacy_message(self): # TODO(mitsuhiko): remove this code once it's unused. It's still # being used by plugin code and once the message rename is through # plugins should instead swithc to the actual message attribute or # this method could return what currently is real_message. return ( get_path(self.data, "logentry", "formatted") or get_path(self.data, "logentry", "message") or self.message ) def get_event_type(self): """ Return the type of this event. See ``sentry.eventtypes``. """ return self.data.get("type", "default") def get_event_metadata(self): """ Return the metadata of this event. See ``sentry.eventtypes``. """ # For some inexplicable reason we have some cases where the data # is completely empty. In that case we want to hobble along # further. return self.data.get("metadata") or {} def get_grouping_config(self): """Returns the event grouping config.""" from sentry.grouping.api import get_grouping_config_dict_for_event_data return get_grouping_config_dict_for_event_data(self.data, self.project) def get_hashes(self, force_config=None): """ Returns the calculated hashes for the event. This uses the stored information if available. Grouping hashes will take into account fingerprinting and checksums. """ # If we have hashes stored in the data we use them, otherwise we # fall back to generating new ones from the data. We can only use # this if we do not force a different config. if force_config is None: hashes = self.data.get("hashes") if hashes is not None: return hashes return filter( None, [x.get_hash() for x in self.get_grouping_variants(force_config).values()] ) def get_grouping_variants(self, force_config=None, normalize_stacktraces=False): """ This is similar to `get_hashes` but will instead return the grouping components for each variant in a dictionary. If `normalize_stacktraces` is set to `True` then the event data will be modified for `in_app` in addition to event variants being created. This means that after calling that function the event data has been modified in place. """ from sentry.grouping.api import get_grouping_variants_for_event, load_grouping_config from sentry.stacktraces.processing import normalize_stacktraces_for_grouping # Forcing configs has two separate modes. One is where just the # config ID is given in which case it's merged with the stored or # default config dictionary if force_config is not None: if isinstance(force_config, six.string_types): stored_config = self.get_grouping_config() config = dict(stored_config) config["id"] = force_config else: config = force_config # Otherwise we just use the same grouping config as stored. if # this is None the `get_grouping_variants_for_event` will fill in # the default. else: config = self.data.get("grouping_config") config = load_grouping_config(config) if normalize_stacktraces: normalize_stacktraces_for_grouping(self.data, config) return get_grouping_variants_for_event(self, config) def get_primary_hash(self): # TODO: This *might* need to be protected from an IndexError? return self.get_hashes()[0] # For compatibility, still used by plugins. def get_tags(self): return self.tags def get_tag(self, key): for t, v in self.get_tags(): if t == key: return v return None def get_raw_data(self): """Returns the internal raw event data dict.""" return dict(self.data.items()) def get_email_subject(self): template = self.project.get_option("mail:subject_template") if template: template = EventSubjectTemplate(template) else: template = DEFAULT_SUBJECT_TEMPLATE return truncatechars(template.safe_substitute(EventSubjectTemplateData(self)), 128).encode( "utf-8" ) def get_environment(self): from sentry.models import Environment if not hasattr(self, "_environment_cache"): self._environment_cache = Environment.objects.get( organization_id=self.project.organization_id, name=Environment.get_name_or_default(self.get_tag("environment")), ) return self._environment_cache def get_minimal_user(self): """ A minimal 'User' interface object that gives us enough information to render a user badge. """ return self.get_interface("user") def as_dict(self): """Returns the data in normalized form for external consumers.""" # We use a OrderedDict to keep elements ordered for a potential JSON serializer data = OrderedDict() data["event_id"] = self.event_id data["project"] = self.project_id data["release"] = self.release data["dist"] = self.dist data["platform"] = self.platform data["message"] = self.real_message data["datetime"] = self.datetime data["time_spent"] = self.time_spent data["tags"] = [(k.split("sentry:", 1)[-1], v) for (k, v) in self.tags] for k, v in sorted(six.iteritems(self.data)): if k in data: continue if k == "sdk": v = {v_k: v_v for v_k, v_v in six.iteritems(v) if v_k != "client_ip"} data[k] = v # for a long time culprit was not persisted. In those cases put # the culprit in from the group. if data.get("culprit") is None and self.group_id: data["culprit"] = self.group.culprit # Override title and location with dynamically generated data data["title"] = self.title data["location"] = self.location return data # ============================================ # DEPRECATED # ============================================ # deprecated accessors def error(self): # TODO why is this not a property? warnings.warn("Event.error is deprecated, use Event.title", DeprecationWarning) return self.title error.short_description = _("error") class Event(EventCommon, Model): """ An event backed by data stored in postgres. """ __core__ = False group_id = BoundedBigIntegerField(blank=True, null=True) event_id = models.CharField(max_length=32, null=True, db_column="message_id") project_id = BoundedBigIntegerField(blank=True, null=True) message = models.TextField() platform = models.CharField(max_length=64, null=True) datetime = models.DateTimeField(default=timezone.now, db_index=True) time_spent = BoundedIntegerField(null=True) data = NodeField( blank=True, null=True, ref_func=lambda x: x.project_id or x.project.id, ref_version=2, wrapper=EventDict, ) objects = EventManager() __repr__ = sane_repr("project_id", "group_id") class EventSubjectTemplate(string.Template): idpattern = r"(tag:)?[_a-z][_a-z0-9]*" class EventSubjectTemplateData(object): tag_aliases = {"release": "sentry:release", "dist": "sentry:dist", "user": "sentry:user"} DEFAULT_SUBJECT_TEMPLATE = EventSubjectTemplate("$shortID - $title")
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 198, 11748, 2237, 198, 11748, 4731, 198, 11748, 14601, 198, 11748, 12972, 22877, 198, 198, 6738, 17268, 1330, 14230, 1068, 35, 713, 198, 6738, 3128, 22602, 13, 48610, 1330, 21136, 355, ...
2.534418
3,443
""" Makes training and test dataset for nowcasting model using SEVIR """ # -*- coding: utf-8 -*- import argparse import logging import os import h5py os.environ["HDF5_USE_FILE_LOCKING"]='FALSE' import sys import numpy as np import tensorflow as tf from nowcast_generator import get_nowcast_test_generator # parser = argparse.ArgumentParser(description='Make nowcast training & test datasets using SEVIR') # parser.add_argument('--sevir_data', type=str, help='location of SEVIR dataset',default='../../data/sevir') # parser.add_argument('--sevir_catalog', type=str, help='location of SEVIR dataset',default='../../data/CATALOG.csv') # parser.add_argument('--output_location', type=str, help='location of SEVIR dataset',default='../../data/interim') # parser.add_argument('--n_chunks', type=int, help='Number of chucks to use (increase if memory limited)',default=10) #args = parser.parse_args() def generate_data(sevir_location,sevir_catalog,output_location,n_chunks=10): """ Runs data processing scripts to extract training set from SEVIR """ logger = logging.getLogger(__name__) logger.info('making final data set from raw data') #trn_generator = get_nowcast_train_generator(sevir_catalog=args.sevir_catalog,sevir_location=args.sevir_data) tst_generator = get_nowcast_test_generator(sevir_catalog,sevir_location) #ogger.info('Reading/writing training data to %s' % ('%s/nowcast_training.h5' % args.output_location)) #read_write_chunks('%s/nowcast_training.h5' % args.output_location,trn_generator,args.n_chunks) logger.info('Reading/writing testing data to ' + output_location+'/nowcast_testing.h5') read_write_chunks(output_location+'/nowcast_testing.h5',tst_generator,n_chunks)
[ 37811, 198, 44, 1124, 3047, 290, 1332, 27039, 329, 783, 19913, 2746, 1262, 7946, 53, 4663, 198, 37811, 198, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 1822, 29572, 198, 11748, 18931, 198, 198, 11748, ...
2.851064
611
# The Original importer was created by Nick # Copyright (c) 2020 Nick import bpy import bmesh import os import array import math from mathutils import * from bpy_extras.image_utils import load_image from .cast import Cast, Model, Animation, Curve, NotificationTrack, Mesh, Skeleton, Bone, Material, File
[ 198, 2, 383, 13745, 848, 4337, 373, 2727, 416, 8047, 198, 2, 15069, 357, 66, 8, 12131, 8047, 198, 198, 11748, 275, 9078, 198, 11748, 275, 76, 5069, 198, 11748, 28686, 198, 11748, 7177, 198, 11748, 10688, 198, 6738, 10688, 26791, 1330,...
3.556818
88
# https://luma-oled.readthedocs.io/en/latest/software.html import os import sys import time import threading import usb4vc_oled from luma.core.render import canvas import RPi.GPIO as GPIO import usb4vc_usb_scan import usb4vc_shared import usb4vc_show_ev import usb4vc_check_update import json import subprocess from subprocess import Popen, PIPE from usb4vc_shared import this_app_dir_path from usb4vc_shared import config_dir_path from usb4vc_shared import firmware_dir_path from usb4vc_shared import temp_dir_path from usb4vc_shared import ensure_dir from usb4vc_shared import i2c_bootloader_pbid from usb4vc_shared import usb_bootloader_pbid config_file_path = os.path.join(config_dir_path, 'config.json') ensure_dir(this_app_dir_path) ensure_dir(config_dir_path) ensure_dir(firmware_dir_path) ensure_dir(temp_dir_path) PLUS_BUTTON_PIN = 27 MINUS_BUTTON_PIN = 19 ENTER_BUTTON_PIN = 22 SHUTDOWN_BUTTON_PIN = 21 PBOARD_RESET_PIN = 25 PBOARD_BOOT0_PIN = 12 SLEEP_LED_PIN = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(PBOARD_RESET_PIN, GPIO.IN) GPIO.setup(PBOARD_BOOT0_PIN, GPIO.IN) GPIO.setup(SLEEP_LED_PIN, GPIO.OUT) GPIO.output(SLEEP_LED_PIN, GPIO.LOW) SPI_MOSI_MAGIC = 0xde SPI_MOSI_MSG_TYPE_SET_PROTOCOL = 2 set_protocl_spi_msg_template = [SPI_MOSI_MAGIC, 0, SPI_MOSI_MSG_TYPE_SET_PROTOCOL] + [0]*29 PBOARD_ID_UNKNOWN = 0 PBOARD_ID_IBMPC = 1 PBOARD_ID_ADB = 2 pboard_info_spi_msg = [0] * 32 this_pboard_id = PBOARD_ID_UNKNOWN USBGP_BTN_SOUTH = 0x130 USBGP_BTN_EAST = 0x131 USBGP_BTN_C = 0x132 USBGP_BTN_NORTH = 0x133 USBGP_BTN_WEST = 0x134 USBGP_BTN_Z = 0x135 USBGP_BTN_TL = 0x136 USBGP_BTN_TR = 0x137 USBGP_BTN_TL2 = 0x138 USBGP_BTN_TR2 = 0x139 USBGP_BTN_SELECT = 0x13a USBGP_BTN_START = 0x13b USBGP_BTN_MODE = 0x13c USBGP_BTN_THUMBL = 0x13d USBGP_BTN_THUMBR = 0x13e USBGP_BTN_A = USBGP_BTN_SOUTH USBGP_BTN_B = USBGP_BTN_EAST USBGP_BTN_X = USBGP_BTN_NORTH USBGP_BTN_Y = USBGP_BTN_WEST USBGP_ABS_X = 0x00 # left stick X USBGP_ABS_Y = 0x01 # left stick Y USBGP_ABS_Z = 0x02 # left analog trigger USBGP_ABS_RX = 0x03 # right stick X USBGP_ABS_RY = 0x04 # right stick Y USBGP_ABS_RZ = 0x05 # right analog trigger USBGP_ABS_HAT0X = 0x10 # D-pad X USBGP_ABS_HAT0Y = 0x11 # D-pad Y GENERIC_USB_GAMEPAD_TO_MOUSE_KB_DEAULT_MAPPING = { "MAPPING_TYPE": "DEFAULT_MOUSE_KB", 'BTN_TL': {'code': 'BTN_LEFT'}, 'BTN_TR': {'code': 'BTN_RIGHT'}, 'BTN_TL2': {'code': 'BTN_LEFT'}, 'BTN_TR2': {'code': 'BTN_RIGHT'}, 'ABS_X': {'code': 'REL_X'}, 'ABS_Y': {'code': 'REL_Y'}, 'ABS_HAT0X': {'code': 'KEY_RIGHT', 'code_neg': 'KEY_LEFT'}, 'ABS_HAT0Y': {'code': 'KEY_DOWN', 'code_neg': 'KEY_UP'} } IBM_GENERIC_USB_GAMEPAD_TO_15PIN_GAMEPORT_GAMEPAD_DEAULT_MAPPING = { "MAPPING_TYPE": "DEFAULT_15PIN", # buttons to buttons 'BTN_SOUTH': {'code':'IBM_GGP_BTN_1'}, 'BTN_NORTH': {'code':'IBM_GGP_BTN_2'}, 'BTN_EAST': {'code':'IBM_GGP_BTN_3'}, 'BTN_WEST': {'code':'IBM_GGP_BTN_4'}, 'BTN_TL': {'code':'IBM_GGP_BTN_1'}, 'BTN_TR': {'code':'IBM_GGP_BTN_2'}, 'BTN_Z': {'code':'IBM_GGP_BTN_3'}, 'BTN_C': {'code':'IBM_GGP_BTN_4'}, 'BTN_TL2': {'code':'IBM_GGP_BTN_1'}, 'BTN_TR2': {'code':'IBM_GGP_BTN_2'}, # analog axes to analog axes 'ABS_X': {'code':'IBM_GGP_JS1_X'}, 'ABS_Y': {'code':'IBM_GGP_JS1_Y'}, 'ABS_HAT0X': {'code':'IBM_GGP_JS1_X'}, 'ABS_HAT0Y': {'code':'IBM_GGP_JS1_Y'}, 'ABS_RX': {'code':'IBM_GGP_JS2_X'}, 'ABS_RY': {'code':'IBM_GGP_JS2_Y'}, } PROTOCOL_OFF = {'pid':0, 'display_name':"OFF"} PROTOCOL_AT_PS2_KB = {'pid':1, 'display_name':"AT/PS2"} PROTOCOL_XT_KB = {'pid':2, 'display_name':"PC XT"} PROTOCOL_ADB_KB = {'pid':3, 'display_name':"ADB"} PROTOCOL_PS2_MOUSE_NORMAL = {'pid':4, 'display_name':"PS/2"} PROTOCOL_MICROSOFT_SERIAL_MOUSE = {'pid':5, 'display_name':"Microsft Serial"} PROTOCOL_ADB_MOUSE = {'pid':6, 'display_name':"ADB"} PROTOCOL_15PIN_GAMEPORT_GAMEPAD = {'pid':7, 'display_name':"Generic 15-Pin", 'mapping':IBM_GENERIC_USB_GAMEPAD_TO_15PIN_GAMEPORT_GAMEPAD_DEAULT_MAPPING} PROTOCOL_MOUSESYSTEMS_SERIAL_MOUSE = {'pid':8, 'display_name':"MouseSys Serial"} PROTOCOL_USB_GP_TO_MOUSE_KB = {'pid':0, 'display_name':'Mouse & KB', 'mapping':GENERIC_USB_GAMEPAD_TO_MOUSE_KB_DEAULT_MAPPING} PROTOCOL_RAW_KEYBOARD = {'pid':125, 'display_name':"Raw data"} PROTOCOL_RAW_MOUSE = {'pid':126, 'display_name':"Raw data"} PROTOCOL_RAW_GAMEPAD = {'pid':127, 'display_name':"Raw data"} custom_profile_list = [] try: onlyfiles = [f for f in os.listdir(config_dir_path) if os.path.isfile(os.path.join(config_dir_path, f))] json_map_files = [os.path.join(config_dir_path, x) for x in onlyfiles if x.lower().startswith('usb4vc_map') and x.lower().endswith(".json")] for item in json_map_files: print('loading json file:', item) with open(item) as json_file: custom_profile_list.append(json.load(json_file)) except Exception as e: print('exception json load:', e) ibmpc_keyboard_protocols = [PROTOCOL_OFF, PROTOCOL_AT_PS2_KB, PROTOCOL_XT_KB] ibmpc_mouse_protocols = [PROTOCOL_OFF, PROTOCOL_PS2_MOUSE_NORMAL, PROTOCOL_MICROSOFT_SERIAL_MOUSE, PROTOCOL_MOUSESYSTEMS_SERIAL_MOUSE] ibmpc_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_15PIN_GAMEPORT_GAMEPAD, PROTOCOL_USB_GP_TO_MOUSE_KB] adb_keyboard_protocols = [PROTOCOL_OFF, PROTOCOL_ADB_KB] adb_mouse_protocols = [PROTOCOL_OFF, PROTOCOL_ADB_MOUSE] adb_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_USB_GP_TO_MOUSE_KB] raw_keyboard_protocols = [PROTOCOL_OFF, PROTOCOL_RAW_KEYBOARD] raw_mouse_protocols = [PROTOCOL_OFF, PROTOCOL_RAW_MOUSE] raw_gamepad_protocols = [PROTOCOL_OFF, PROTOCOL_RAW_GAMEPAD] mouse_sensitivity_list = [1, 1.25, 1.5, 1.75, 0.25, 0.5, 0.75] """ key is protocol card ID conf_dict[pbid]: hw revision current keyboard protocol current mouse protocol current gamepad procotol mouse sensitivity """ configuration_dict = {} LINUX_EXIT_CODE_TIMEOUT = 124 curve_vertial_axis_x_pos = 80 curve_horizontal_axis_width = 32 curve_linear = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, 17: 17, 18: 18, 19: 19, 20: 20, 21: 21, 22: 22, 23: 23, 24: 24, 25: 25, 26: 26, 27: 27, 28: 28, 29: 29, 30: 30, 31: 31, 32: 32, 33: 33, 34: 34, 35: 35, 36: 36, 37: 37, 38: 38, 39: 39, 40: 40, 41: 41, 42: 42, 43: 43, 44: 44, 45: 45, 46: 46, 47: 47, 48: 48, 49: 49, 50: 50, 51: 51, 52: 52, 53: 53, 54: 54, 55: 55, 56: 56, 57: 57, 58: 58, 59: 59, 60: 60, 61: 61, 62: 62, 63: 63, 64: 64, 65: 65, 66: 66, 67: 67, 68: 68, 69: 69, 70: 70, 71: 71, 72: 72, 73: 73, 74: 74, 75: 75, 76: 76, 77: 77, 78: 78, 79: 79, 80: 80, 81: 81, 82: 82, 83: 83, 84: 84, 85: 85, 86: 86, 87: 87, 88: 88, 89: 89, 90: 90, 91: 91, 92: 92, 93: 93, 94: 94, 95: 95, 96: 96, 97: 97, 98: 98, 99: 99, 100: 100, 101: 101, 102: 102, 103: 103, 104: 104, 105: 105, 106: 106, 107: 107, 108: 108, 109: 109, 110: 110, 111: 111, 112: 112, 113: 113, 114: 114, 115: 115, 116: 116, 117: 117, 118: 118, 119: 119, 120: 120, 121: 121, 122: 122, 123: 123, 124: 124, 125: 125, 126: 126, 127: 127} curve1 = {0: 1, 1: 1, 2: 2, 3: 2, 4: 3, 5: 4, 6: 4, 7: 5, 8: 5, 9: 6, 10: 6, 11: 7, 12: 7, 13: 8, 14: 8, 15: 9, 16: 9, 17: 10, 18: 11, 19: 11, 20: 12, 21: 12, 22: 13, 23: 13, 24: 14, 25: 15, 26: 15, 27: 16, 28: 16, 29: 17, 30: 18, 31: 18, 32: 19, 33: 19, 34: 20, 35: 21, 36: 21, 37: 22, 38: 22, 39: 23, 40: 24, 41: 24, 42: 25, 43: 26, 44: 26, 45: 27, 46: 28, 47: 28, 48: 29, 49: 30, 50: 30, 51: 31, 52: 32, 53: 33, 54: 33, 55: 34, 56: 35, 57: 36, 58: 36, 59: 37, 60: 38, 61: 39, 62: 39, 63: 40, 64: 41, 65: 42, 66: 43, 67: 44, 68: 45, 69: 46, 70: 46, 71: 47, 72: 48, 73: 49, 74: 50, 75: 51, 76: 52, 77: 53, 78: 55, 79: 56, 80: 57, 81: 58, 82: 59, 83: 60, 84: 61, 85: 62, 86: 63, 87: 65, 88: 66, 89: 67, 90: 68, 91: 70, 92: 71, 93: 72, 94: 73, 95: 75, 96: 76, 97: 77, 98: 79, 99: 80, 100: 81, 101: 83, 102: 84, 103: 86, 104: 87, 105: 89, 106: 90, 107: 92, 108: 93, 109: 95, 110: 96, 111: 98, 112: 100, 113: 101, 114: 103, 115: 105, 116: 106, 117: 108, 118: 110, 119: 112, 120: 113, 121: 115, 122: 117, 123: 119, 124: 121, 125: 123, 126: 125, 127: 127} curve2 = {0: 1, 1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 2, 8: 2, 9: 3, 10: 3, 11: 3, 12: 3, 13: 4, 14: 4, 15: 4, 16: 4, 17: 5, 18: 5, 19: 5, 20: 5, 21: 6, 22: 6, 23: 6, 24: 7, 25: 7, 26: 7, 27: 8, 28: 8, 29: 8, 30: 8, 31: 9, 32: 9, 33: 9, 34: 10, 35: 10, 36: 10, 37: 11, 38: 11, 39: 12, 40: 12, 41: 12, 42: 13, 43: 13, 44: 13, 45: 14, 46: 14, 47: 15, 48: 15, 49: 15, 50: 16, 51: 16, 52: 17, 53: 17, 54: 18, 55: 18, 56: 19, 57: 19, 58: 20, 59: 20, 60: 21, 61: 21, 62: 22, 63: 22, 64: 23, 65: 23, 66: 24, 67: 24, 68: 25, 69: 26, 70: 26, 71: 27, 72: 28, 73: 28, 74: 29, 75: 30, 76: 30, 77: 31, 78: 32, 79: 33, 80: 34, 81: 35, 82: 36, 83: 37, 84: 38, 85: 39, 86: 40, 87: 41, 88: 42, 89: 43, 90: 44, 91: 45, 92: 47, 93: 48, 94: 49, 95: 51, 96: 52, 97: 53, 98: 55, 99: 56, 100: 58, 101: 59, 102: 61, 103: 63, 104: 64, 105: 66, 106: 68, 107: 70, 108: 71, 109: 73, 110: 75, 111: 78, 112: 80, 113: 82, 114: 84, 115: 86, 116: 89, 117: 92, 118: 94, 119: 96, 120: 100, 121: 102, 122: 106, 123: 110, 124: 112, 125: 116, 126: 120, 127: 125} curve3 = {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1, 13: 1, 14: 1, 15: 1, 16: 1, 17: 1, 18: 1, 19: 1, 20: 1, 21: 2, 22: 2, 23: 2, 24: 2, 25: 2, 26: 2, 27: 2, 28: 2, 29: 2, 30: 2, 31: 3, 32: 3, 33: 3, 34: 3, 35: 3, 36: 3, 37: 3, 38: 4, 39: 4, 40: 4, 41: 4, 42: 4, 43: 4, 44: 5, 45: 5, 46: 5, 47: 5, 48: 5, 49: 6, 50: 6, 51: 6, 52: 6, 53: 7, 54: 7, 55: 7, 56: 7, 57: 8, 58: 8, 59: 8, 60: 8, 61: 9, 62: 9, 63: 9, 64: 10, 65: 10, 66: 10, 67: 11, 68: 11, 69: 11, 70: 12, 71: 12, 72: 12, 73: 13, 74: 13, 75: 14, 76: 14, 77: 15, 78: 15, 79: 16, 80: 16, 81: 17, 82: 17, 83: 18, 84: 19, 85: 19, 86: 20, 87: 21, 88: 21, 89: 22, 90: 23, 91: 24, 92: 25, 93: 26, 94: 27, 95: 28, 96: 29, 97: 30, 98: 32, 99: 33, 100: 34, 101: 35, 102: 37, 103: 38, 104: 40, 105: 41, 106: 43, 107: 45, 108: 46, 109: 48, 110: 50, 111: 52, 112: 54, 113: 56, 114: 59, 115: 61, 116: 64, 117: 66, 118: 69, 119: 72, 120: 76, 121: 79, 122: 83, 123: 87, 124: 92, 125: 99, 126: 104, 127: 118} joystick_curve_list = [curve_linear, curve1, curve2, curve3] pboard_database = { PBOARD_ID_UNKNOWN:{'author':'Unknown', 'fw_ver':(0,0,0), 'full_name':'Unknown', 'hw_rev':0, 'protocol_list_keyboard':raw_keyboard_protocols, 'protocol_list_mouse':raw_mouse_protocols, 'protocol_list_gamepad':raw_gamepad_protocols}, PBOARD_ID_IBMPC:{'author':'dekuNukem', 'fw_ver':(0,0,0), 'full_name':'IBM PC Compatible', 'hw_rev':0, 'protocol_list_keyboard':ibmpc_keyboard_protocols, 'protocol_list_mouse':ibmpc_mouse_protocols, 'protocol_list_gamepad':ibmpc_gamepad_protocols}, PBOARD_ID_ADB:{'author':'dekuNukem', 'fw_ver':(0,0,0), 'full_name':'Apple Desktop Bus', 'hw_rev':0, 'protocol_list_keyboard':adb_keyboard_protocols, 'protocol_list_mouse':adb_mouse_protocols, 'protocol_list_gamepad':adb_gamepad_protocols}, } plus_button = my_button(PLUS_BUTTON_PIN) minus_button = my_button(MINUS_BUTTON_PIN) enter_button = my_button(ENTER_BUTTON_PIN) shutdown_button = my_button(SHUTDOWN_BUTTON_PIN) my_oled = oled_sleep_control() my_menu = None ui_thread = threading.Thread(target=ui_worker, daemon=True)
[ 2, 3740, 1378, 75, 7487, 12, 45342, 13, 961, 83, 704, 420, 82, 13, 952, 14, 268, 14, 42861, 14, 43776, 13, 6494, 198, 198, 11748, 28686, 198, 11748, 25064, 198, 11748, 640, 198, 11748, 4704, 278, 198, 11748, 38551, 19, 28435, 62, ...
2.037536
5,488
# Generated by Django 3.0.2 on 2020-02-24 23:16 from django.db import migrations, models
[ 2, 2980, 515, 416, 37770, 513, 13, 15, 13, 17, 319, 12131, 12, 2999, 12, 1731, 2242, 25, 1433, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 628 ]
2.84375
32
# -*- coding: utf-8 -*- ### # (C) Copyright [2019] Hewlett Packard Enterprise Development LP # # 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 io import unittest import mock from mock import call from tests.test_utils import mock_builtin from hpOneView.connection import connection from hpOneView import exceptions from hpOneView.resources.resource import (ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method) def test_build_uri_with_uri_should_work(self): input = "/rest/testuri/09USE7335NW3" expected_output = "/rest/testuri/09USE7335NW3" result = self.resource_client._helper.build_uri(input) self.assertEqual(expected_output, result) def test_build_uri_with_none_should_raise_exception(self): try: self.resource_client._helper.build_uri(None) except ValueError as exception: self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0]) else: self.fail("Expected Exception was not raised") def test_build_uri_with_empty_str_should_raise_exception(self): try: self.resource_client._helper.build_uri('') except ValueError as exception: self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0]) else: self.fail("Expected Exception was not raised") class FakeResource(object): class ResourceClientTest(unittest.TestCase): URI = "/rest/testuri" TYPE_V200 = 'typeV200' TYPE_V300 = 'typeV300' DEFAULT_VALUES = { '200': {'type': TYPE_V200}, '300': {'type': TYPE_V300} } def test_delete_dict_invalid_uri(self): dict_to_delete = {"task": "task", "uri": ""} try: self.resource_client.delete(dict_to_delete, False, -1) except exceptions.HPOneViewUnknownType as e: self.assertEqual("Unknown object type", e.args[0]) else: self.fail() def test_delete_with_none(self): try: self.resource_client.delete(None) except ValueError as e: self.assertTrue("Resource" in e.args[0]) else: self.fail() def test_get_utilization_with_empty(self): try: self.resource_client.get_utilization('') except ValueError as exception: self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0]) else: self.fail("Expected Exception was not raised") def test_merge_api_default_values(self): resource = {'name': 'resource1'} default_values = { '200': {"type": "EnclosureGroupV200"}, '300': {"type": "EnclosureGroupV300"} } expected = {'name': 'resource1', "type": "EnclosureGroupV300"} resource_client = ResourceClient(self.connection, self.URI) result = resource_client.merge_default_values(resource, default_values) self.assertEqual(result, expected) def test_transform_list_to_dict(self): list = ['one', 'two', {'tree': 3}, 'four', 5] dict_transformed = transform_list_to_dict(list=list) self.assertEqual(dict_transformed, {'5': True, 'four': True, 'one': True, 'tree': 3, 'two': True})
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 21017, 198, 2, 357, 34, 8, 15069, 685, 23344, 60, 30446, 15503, 6400, 446, 14973, 7712, 18470, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, ...
2.214428
2,010
# -*- coding: utf-8 -*- from __future__ import (absolute_import, division, print_function, unicode_literals) from .core import UnitedStates
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 6738, 11593, 37443, 834, 1330, 357, 48546, 62, 11748, 11, 7297, 11, 3601, 62, 8818, 11, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 22...
2.405797
69
#!/usr/bin/env python # -*- coding: utf-8 -*- import random import numpy as np # Generic data augmentation ########## # Images # ########## def horizontal_flip(p=0.5): return fc def vertical_flip(p=0.5): return fc def gaussian_noise(p=0.5, mean=0, sigma=0.02): return fc def black_vstripe(p=0.5, size=10): return fc def black_hstripe(p=0.5, size=10): return fc def default_augmenter(p=0.5, strip_size=3, mean=0, sigma=0.02): """Default data augmentation with horizontal flip, vertical flip, gaussian noise, black hstripe, and black vstripe. Returns: Augmenter object. Use as: aug.augment(img) """ print("Using default image augmenter") return Augmenter([ horizontal_flip(p), gaussian_noise(p, mean, sigma), black_hstripe(p, size=strip_size), black_vstripe(p, size=strip_size) ]) ########## # Videos # ########## def default_augmenter_vid(p=0.5, strip_size=3, mean=0, sigma=0.02): """Default data augmentation with horizontal flip, gaussian noise, black hstripe, and black vstripe. Returns: Augmenter object. Use as: aug.augment(img) """ return Augmenter([ horizontal_flip_vid(p), gaussian_noise(p, mean, sigma), black_hstripe_vid(p, size=strip_size), black_vstripe_vid(p, size=strip_size) ])
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 11748, 4738, 198, 11748, 299, 32152, 355, 45941, 628, 198, 2, 42044, 1366, 16339, 14374, 198, 198, 7804, 2235, 198...
2.454373
526
from django.contrib import admin from django.contrib.gis import geos from leaflet.admin import LeafletGeoAdmin, LeafletGeoAdminMixin from .models import Lau1 from .models import Nuts3 from .models import Airport from .models import Road from .models import PublicTransportStop from .models import RailwayStation from django.urls import reverse from django.utils.translation import ugettext_lazy as _ import nested_admin import uuid import json # Register your models here. admin.site.register(Lau1, LAU1Admin) admin.site.register(Nuts3, NUTS3Admin) admin.site.register(Road, RoadAdmin) admin.site.register(PublicTransportStop, PublicTransportStopAdmin) admin.site.register(RailwayStation, RailwayStationAdmin) admin.site.register(Airport, AirportAdmin)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 70, 271, 1330, 4903, 418, 198, 6738, 12835, 1616, 13, 28482, 1330, 14697, 1616, 10082, 78, 46787, 11, 14697, 1616, 10082, 78, 46787, 35608, 259,...
3.371681
226
import logging import json import asyncio from google.protobuf import json_format from umbra.common.protobuf.umbra_grpc import MonitorBase from umbra.common.protobuf.umbra_pb2 import Instruction, Snapshot from umbra.monitor.tools import Tools logger = logging.getLogger(__name__) logging.getLogger("hpack").setLevel(logging.WARNING)
[ 11748, 18931, 198, 11748, 33918, 198, 11748, 30351, 952, 198, 198, 6738, 23645, 13, 11235, 672, 3046, 1330, 33918, 62, 18982, 198, 198, 6738, 20810, 430, 13, 11321, 13, 11235, 672, 3046, 13, 2178, 430, 62, 2164, 14751, 1330, 18289, 1488...
3.12963
108
"""https://www.dndbeyond.com/spells/hunters-mark""" from unittest.mock import patch import dice from pycs.constant import ActionCategory from pycs.constant import SpellType from pycs.creature import Creature from pycs.effect import Effect from pycs.gear import Shortbow from pycs.spell import SpellAction from pycs.spells.spelltest import SpellTest ############################################################################## ############################################################################## ############################################################################## ############################################################################## ############################################################################## ############################################################################## ############################################################################## ############################################################################## ############################################################################## # EOF
[ 37811, 5450, 1378, 2503, 13, 67, 358, 1350, 3243, 13, 785, 14, 46143, 82, 14, 20088, 1010, 12, 4102, 37811, 198, 198, 6738, 555, 715, 395, 13, 76, 735, 1330, 8529, 198, 11748, 17963, 198, 6738, 12972, 6359, 13, 9979, 415, 1330, 7561...
6.515152
165
import numpy as np
[ 11748, 299, 32152, 355, 45941, 628, 198 ]
3
7
from .gripper_model import GripperModel from .gripper_factory import gripper_factory from .gripper_tester import GripperTester from .panda_gripper import PandaGripper from .rethink_gripper import RethinkGripper from .robotiq_85_gripper import Robotiq85Gripper from .robotiq_three_finger_gripper import RobotiqThreeFingerGripper, RobotiqThreeFingerDexterousGripper from .panda_gripper import PandaGripper from .jaco_three_finger_gripper import JacoThreeFingerGripper, JacoThreeFingerDexterousGripper from .robotiq_140_gripper import Robotiq140Gripper from .wiping_gripper import WipingGripper from .null_gripper import NullGripper GRIPPER_MAPPING = { "RethinkGripper": RethinkGripper, "PandaGripper": PandaGripper, "JacoThreeFingerGripper": JacoThreeFingerGripper, "JacoThreeFingerDexterousGripper": JacoThreeFingerDexterousGripper, "WipingGripper": WipingGripper, "Robotiq85Gripper": Robotiq85Gripper, "Robotiq140Gripper": Robotiq140Gripper, "RobotiqThreeFingerGripper": RobotiqThreeFingerGripper, "RobotiqThreeFingerDexterousGripper": RobotiqThreeFingerDexterousGripper, None: NullGripper, } ALL_GRIPPERS = GRIPPER_MAPPING.keys()
[ 6738, 764, 70, 380, 2848, 62, 19849, 1330, 20914, 2848, 17633, 198, 6738, 764, 70, 380, 2848, 62, 69, 9548, 1330, 11120, 2848, 62, 69, 9548, 198, 6738, 764, 70, 380, 2848, 62, 4879, 353, 1330, 20914, 2848, 51, 7834, 198, 198, 6738, ...
2.50533
469
import logging logger = logging.getLogger(__name__) import random import chainercv import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D # NOQA from pose.hand_dataset.geometry_utils import normalize_joint_zyx from pose.hand_dataset.image_utils import normalize_depth # Decimal Code (R,G,B) BASE_COLOR = { "RED": (255, 0, 0), "GREEN": (0, 255, 0), "BLUE": (0, 0, 255), "YELLOW": (255, 255, 0), "CYAN": (0, 255, 255), "MAGENTA": (255, 0, 255), } def vis_image(img, ax=None): """ extend chainercv.visualizations.vis_image """ C, H, W = img.shape if C == 1: if ax is None: fig = plt.figure() ax = fig.add_subplot(1, 1, 1) # remove channnel dimension ax.imshow(img.squeeze()) else: ax = chainercv.visualizations.vis_image(img, ax) return ax def vis_point(point, img=None, color=None, ax=None): """ Visualize points in an image, customized to our purpose. Base implementation is taken from chainercv.visualizations.vis_image """ point, ax, H, W = preprocess(point, ax, img) n_inst = len(point) c = np.asarray(color) / 255. if color is not None else None for i in range(n_inst): # note that the shape of `point[i]` is (K,N) and the format of one is (y, x), (z,y,x). # (K, N) -> (N, K) pts = point[i].transpose() # (K,N) -> (N,K) # resort coordinate order : yx -> xy or zyx -> xyz pts = pts[::-1] ax.scatter(*pts, c=c) if W is not None: ax.set_xlim(left=0, right=W) if H is not None: ax.set_ylim(bottom=H - 1, top=0) return ax def vis_edge(point, indices, img=None, color=None, ax=None): """ Visualize edges in an image """ point, ax, H, W = preprocess(point, ax, img) n_inst = len(point) if color is not None: color = np.asarray(color) / 255. else: color = [None] * len(indices) for i in range(n_inst): # note that the shape of `point[i]` is (K,N) and the format of one is (y, x) or (z,y,x). pts = point[i] for ((s, t), c) in zip(indices, color): # Select point which consists edge. It is a pair or point (start, target). # Note that [::-1] does resort coordinate order: yx -> xy or zyx -> xyz edge = pts[[s, t]].transpose() edge = edge[::-1] ax.plot(*edge, c=c) if W is not None: ax.set_xlim(left=0, right=W) if H is not None: ax.set_ylim(bottom=H - 1, top=0) return ax
[ 11748, 18931, 198, 198, 6404, 1362, 796, 18931, 13, 1136, 11187, 1362, 7, 834, 3672, 834, 8, 198, 198, 11748, 4738, 198, 198, 11748, 6333, 2798, 85, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 2603, 29487, 8019, 1330, 12972, 29487, ...
2.146986
1,211
#!/usr/bin/env python3 from flask import Flask app = Flask(__name__) if __name__ == "__main__": app.run()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 6738, 42903, 1330, 46947, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 628, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, 198, 220, 220, 220, 598, 13, 5143, ...
2.511111
45
import os import skimage.io from torch.nn import Module import torch.nn from torchvision.models import resnet18 from nn.speaker_dataset import Dataset # @UnusedImport os.environ['TORCH_MODEL_ZOO'] = '../data/' VIDTIMIT_PATH = '../data/vidtimit/' skimage.io.use_plugin('pil')
[ 11748, 28686, 198, 198, 11748, 1341, 9060, 13, 952, 198, 6738, 28034, 13, 20471, 1330, 19937, 198, 11748, 28034, 13, 20471, 198, 6738, 28034, 10178, 13, 27530, 1330, 581, 3262, 1507, 198, 6738, 299, 77, 13, 4125, 3110, 62, 19608, 292, ...
2.62037
108
# Copyright 2018 Google LLC # # 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 # # https://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. """Simple tests for util.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import tensorflow as tf from tensorflow_model_analysis import util if __name__ == '__main__': tf.test.main()
[ 2, 15069, 2864, 3012, 11419, 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, 921, 743, 7330...
3.734234
222