content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
""" Simple example set holiday dates (c) 2016 EKM Metering. """ import random from ekmmeters import * #port setup my_port_name = "COM3" my_meter_address = "300001162" #log to console ekm_set_log(ekm_print_log) # init port and meter port = SerialPort(my_port_name) if (port.initPort() == True): my_meter = V4Meter(my_meter_address) my_meter.attachPort(port) else: print "Cannot open port" exit() # input over range(Extents.Holidays) for holiday in range(Extents.Holidays): day = random.randint(1,28) mon = random.randint(1,12) my_meter.assignHolidayDate(holiday, mon, day) my_meter.setHolidayDates() # input directly param_buf = OrderedDict() param_buf["Holiday_1_Month"] = 1 param_buf["Holiday_1_Day"] = 1 param_buf["Holiday_2_Month"] = 2 param_buf["Holiday_2_Day"] = 3 param_buf["Holiday_3_Month"] = 4 param_buf["Holiday_3_Day"] = 4 param_buf["Holiday_4_Month"] = 4 param_buf["Holiday_4_Day"] = 5 param_buf["Holiday_5_Month"] = 5 param_buf["Holiday_5_Day"] = 4 param_buf["Holiday_6_Month"] = 0 param_buf["Holiday_6_Day"] = 0 param_buf["Holiday_7_Month"] = 0 param_buf["Holiday_7_Day"] = 0 param_buf["Holiday_8_Month"] = 0 param_buf["Holiday_8_Day"] = 0 param_buf["Holiday_9_Month"] = 0 param_buf["Holiday_9_Day"] = 0 param_buf["Holiday_10_Month"] = 0 param_buf["Holiday_10_Day"] = 0 param_buf["Holiday_11_Month"] = 0 param_buf["Holiday_11_Day"] = 0 param_buf["Holiday_12_Month"] = 0 param_buf["Holiday_12_Day"] = 0 param_buf["Holiday_13_Month"] = 0 param_buf["Holiday_13_Day"] = 0 param_buf["Holiday_14_Month"] = 0 param_buf["Holiday_14_Day"] = 0 param_buf["Holiday_15_Month"] = 0 param_buf["Holiday_15_Day"] = 0 param_buf["Holiday_16_Month"] = 0 param_buf["Holiday_16_Day"] = 0 param_buf["Holiday_17_Month"] = 0 param_buf["Holiday_17_Day"] = 0 param_buf["Holiday_18_Month"] = 0 param_buf["Holiday_18_Day"] = 0 param_buf["Holiday_19_Month"] = 0 param_buf["Holiday_19_Day"] = 0 param_buf["Holiday_20_Month"] = 1 param_buf["Holiday_20_Day"] = 9 if my_meter.setHolidayDates(param_buf): print "Set holiday dates success." port.closePort()
[ 37811, 17427, 1672, 900, 9912, 9667, 198, 7, 66, 8, 1584, 412, 42, 44, 3395, 1586, 13, 198, 37811, 198, 11748, 4738, 198, 6738, 304, 74, 3020, 7307, 1330, 1635, 198, 198, 2, 634, 9058, 198, 1820, 62, 634, 62, 3672, 796, 366, 9858,...
2.411628
860
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Sun Oct 30 20:11:19 2016 @author: stephen """ from __future__ import print_function from keras.models import Model from keras.utils import np_utils import numpy as np import os from keras.callbacks import ModelCheckpoint import pandas as pd import sys import keras from keras.callbacks import ReduceLROnPlateau nb_epochs = 300 #flist = ['Adiac', 'Beef', 'CBF', 'ChlorineConcentration', 'CinC_ECG_torso', 'Coffee', 'Cricket_X', 'Cricket_Y', 'Cricket_Z', #'DiatomSizeReduction', 'ECGFiveDays', 'FaceAll', 'FaceFour', 'FacesUCR', '50words', 'FISH', 'Gun_Point', 'Haptics', #'InlineSkate', 'ItalyPowerDemand', 'Lighting2', 'Lighting7', 'MALLAT', 'MedicalImages', 'MoteStrain', 'NonInvasiveFatalECG_Thorax1', #'NonInvasiveFatalECG_Thorax2', 'OliveOil', 'OSULeaf', 'SonyAIBORobotSurface', 'SonyAIBORobotSurfaceII', 'StarLightCurves', 'SwedishLeaf', 'Symbols', #'synthetic_control', 'Trace', 'TwoLeadECG', 'Two_Patterns', 'uWaveGestureLibrary_X', 'uWaveGestureLibrary_Y', 'uWaveGestureLibrary_Z', 'wafer', 'WordsSynonyms', 'yoga'] flist = [ sys.argv[1] ] for each in flist: fname = each x_train, y_train = readucr(fname+'/'+fname+'_TRAIN') x_test, y_test = readucr(fname+'/'+fname+'_TEST') nb_classes = len(np.unique(y_test)) batch_size = int(min(x_train.shape[0]/10, 16)) y_train = (y_train - y_train.min())/(y_train.max()-y_train.min())*(nb_classes-1) y_test = (y_test - y_test.min())/(y_test.max()-y_test.min())*(nb_classes-1) Y_train = np_utils.to_categorical(y_train, nb_classes) Y_test = np_utils.to_categorical(y_test, nb_classes) x_train_mean = x_train.mean() x_train_std = x_train.std() x_train = (x_train - x_train_mean)/(x_train_std) x_test = (x_test - x_train_mean)/(x_train_std) x_train = x_train.reshape(x_train.shape + (1,)) x_test = x_test.reshape(x_test.shape + (1,)) print ("class:"+each+", number of classes: "+str(nb_classes)) x = keras.layers.Input(x_train.shape[1:]) # drop_out = Dropout(0.2)(x) conv1 = keras.layers.Conv1D(filters=32, kernel_size=8, strides=1, activation='relu', input_shape=(32,1))(x) conv1 = keras.layers.normalization.BatchNormalization()(conv1) conv1 = keras.layers.Activation('relu')(conv1) # drop_out = Dropout(0.2)(conv1) conv2 = keras.layers.Conv1D(filters=64, kernel_size=5, border_mode='same')(conv1) conv2 = keras.layers.normalization.BatchNormalization()(conv2) conv2 = keras.layers.Activation('relu')(conv2) # drop_out = Dropout(0.2)(conv2) conv3 = keras.layers.Conv1D(filters=32, kernel_size=3, border_mode='same')(conv2) conv3 = keras.layers.normalization.BatchNormalization()(conv3) conv3 = keras.layers.Activation('relu')(conv3) full = keras.layers.pooling.GlobalAveragePooling1D()(conv3) out = keras.layers.Dense(nb_classes, activation='softmax')(full) model = Model(input=x, output=out) optimizer = keras.optimizers.Adam() model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy']) reduce_lr = ReduceLROnPlateau(monitor = 'loss', factor=0.5, patience=50, min_lr=0.0001) # if os.path.isfile(fname+"_best.hdf5"): # model.load_weights(fname+'_best.hdf5') # model.load_weights(fname+'_shapelet_best.hdf5') checkpointer = ModelCheckpoint(filepath=fname+"_best.hdf5", monitor = 'val_accuracy', verbose=2, save_best_only=True) # hist = model.fit(x_train, Y_train, batch_size=batch_size, epochs=nb_epochs, # verbose=1, callbacks=[reduce_lr], validation_data=(x_test, Y_test)) hist = model.fit(x_train, Y_train, batch_size=batch_size, epochs=nb_epochs, verbose=1, callbacks=[checkpointer,reduce_lr], validation_data=(x_test, Y_test)) #Print the testing results which has the lowest training loss. log = pd.DataFrame(hist.history) print (log.loc[log['loss'].idxmin]['loss'], log.loc[log['loss'].idxmin])
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 17, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 3825, 2556, 1542, 1160, 25, 1157, 25, 1129, 1584, 198, 198, 31, 9800, 25, 2239, 831, 198,...
2.203753
1,865
import os indentSize=1 #size of the indent
[ 11748, 28686, 198, 198, 521, 298, 10699, 28, 16, 1303, 7857, 286, 262, 33793 ]
3.071429
14
#!/usr/bin/env python from __future__ import division """MODULE_DESCRIPTION""" __author__ = "Nick Sweet" __copyright__ = "Copyright 2015, Cohrint" __credits__ = ["Nick Sweet", "Nisar Ahmed"] __license__ = "GPL" __version__ = "1.0.0" __maintainer__ = "Nick Sweet" __email__ = "nick.sweet@colorado.edu" __status__ = "Development" import logging from copy import deepcopy import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 6738, 11593, 37443, 834, 1330, 7297, 198, 37811, 33365, 24212, 62, 30910, 40165, 37811, 198, 198, 834, 9800, 834, 796, 366, 23609, 15335, 1, 198, 834, 22163, 4766, 834, 796, 366, 15269, ...
2.862275
167
from django.contrib.auth.models import User, Group from django.utils import timezone from django.conf import settings from django.urls import reverse_lazy from apps.projects.models import Project, Client, ProjectContributor from ddf import G from guardian.shortcuts import assign_perm
[ 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 11787, 11, 4912, 198, 6738, 42625, 14208, 13, 26791, 1330, 640, 11340, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 6371, 82, 1330, 9575, 62,...
3.776316
76
# -*- coding: utf-8 -*- import numpy as np from torch import load as Tload from torch import tensor from dataloader import read_data,DataLoader,load_init from cdkt import CDKT if 'model' not in dir(): model = CDKT() model.load_state_dict(Tload('model.pkl')) # inits = load_init() data = """0 506123310064654031030450460312100605 0 506123310064654031230450460312100605 0 506123310064654031231450460312100605 0 506123310064654031231456460312100605 0 506123310064654031231456460312100645 0 506123310564654031231456460312100645 0 506123310564654231231456460312100645 0 506123310564654231231456460312100605 0 506123310564654231231456460312100645 0 506123312564654231231456460312100645 0 546123312564654231231456460312100645 0 546123312564654231231456465312100645 0 546123312564654231231456465312120645 0 546123312564654231231456465312123645 1 002163163050030425245001316542000000 1 002163163054030425245001316542000000 1 002163163054030425245001316542000006""" # 1 002163163054030425245001316542030006 # 1 002163163054030425245001316542000006 # 1 002163163054031425245001316542000006 # 1 002163163054631425245001316542000006 # 1 002163163254631425245001316542000006 # 1 002163163254631425245601316542000006 # 1 002163163254631425245631316542000006 # 1 052163163254631425245631316542000006 # 1 452163163254631425245631316542000006 # 1 452163163254631425245631316542000016 # 1 452163163254631425245631316542000316 # 1 452163163254631425245631316542003316 # 1 452163163254631425245631316542000316 # 1 452163163254631425245631316542500316 # 1 452163163254631425245631316542520316 # 1 452163163254631425245631316542524316""" data = [d.strip().split() for d in data.split('\n')] states = [list(map(int,s)) for i,s in data] states = tensor([states]) out = model.predicts(states) prds = np.argmax(out[0],axis=2).flatten()*np.array(inits[2])
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 201, 198, 201, 198, 11748, 299, 32152, 355, 45941, 201, 198, 201, 198, 6738, 28034, 1330, 3440, 355, 309, 2220, 201, 198, 6738, 28034, 1330, 11192, 273, 201, 198, 6738, 4818,...
2.170626
926
# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: hello.proto import sys _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor.FileDescriptor( name='hello.proto', package='hello', syntax='proto3', serialized_options=None, serialized_pb=_b('\n\x0bhello.proto\x12\x05hello\"\x18\n\x08HelloReq\x12\x0c\n\x04Name\x18\x01 \x01(\t\"\x1b\n\tHelloResp\x12\x0e\n\x06Result\x18\x01 \x01(\t2v\n\x0cHelloService\x12/\n\x08SayHello\x12\x0f.hello.HelloReq\x1a\x10.hello.HelloResp\"\x00\x12\x35\n\x0eSayHelloStrict\x12\x0f.hello.HelloReq\x1a\x10.hello.HelloResp\"\x00\x62\x06proto3') ) _HELLOREQ = _descriptor.Descriptor( name='HelloReq', full_name='hello.HelloReq', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='Name', full_name='hello.HelloReq.Name', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], nested_types=[], enum_types=[ ], serialized_options=None, is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], serialized_start=22, serialized_end=46, ) _HELLORESP = _descriptor.Descriptor( name='HelloResp', full_name='hello.HelloResp', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='Result', full_name='hello.HelloResp.Result', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], nested_types=[], enum_types=[ ], serialized_options=None, is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], serialized_start=48, serialized_end=75, ) DESCRIPTOR.message_types_by_name['HelloReq'] = _HELLOREQ DESCRIPTOR.message_types_by_name['HelloResp'] = _HELLORESP _sym_db.RegisterFileDescriptor(DESCRIPTOR) HelloReq = _reflection.GeneratedProtocolMessageType('HelloReq', (_message.Message,), { 'DESCRIPTOR' : _HELLOREQ, '__module__' : 'hello_pb2' # @@protoc_insertion_point(class_scope:hello.HelloReq) }) _sym_db.RegisterMessage(HelloReq) HelloResp = _reflection.GeneratedProtocolMessageType('HelloResp', (_message.Message,), { 'DESCRIPTOR' : _HELLORESP, '__module__' : 'hello_pb2' # @@protoc_insertion_point(class_scope:hello.HelloResp) }) _sym_db.RegisterMessage(HelloResp) _HELLOSERVICE = _descriptor.ServiceDescriptor( name='HelloService', full_name='hello.HelloService', file=DESCRIPTOR, index=0, serialized_options=None, serialized_start=77, serialized_end=195, methods=[ _descriptor.MethodDescriptor( name='SayHello', full_name='hello.HelloService.SayHello', index=0, containing_service=None, input_type=_HELLOREQ, output_type=_HELLORESP, serialized_options=None, ), _descriptor.MethodDescriptor( name='SayHelloStrict', full_name='hello.HelloService.SayHelloStrict', index=1, containing_service=None, input_type=_HELLOREQ, output_type=_HELLORESP, serialized_options=None, ), ]) _sym_db.RegisterServiceDescriptor(_HELLOSERVICE) DESCRIPTOR.services_by_name['HelloService'] = _HELLOSERVICE # @@protoc_insertion_point(module_scope)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 262, 8435, 11876, 17050, 13, 220, 8410, 5626, 48483, 0, 198, 2, 2723, 25, 23748, 13, 1676, 1462, 198, 198, 11748, 25064, 198, 62, 65, 28, 17597, 1...
2.440197
1,622
''' Sitemap plugin for CKAN ''' from ckan.plugins import implements, SingletonPlugin from ckan.plugins import IRoutes
[ 7061, 6, 198, 50, 9186, 499, 13877, 329, 45233, 1565, 198, 7061, 6, 198, 198, 6738, 269, 27541, 13, 37390, 1330, 23986, 11, 5573, 10565, 37233, 198, 6738, 269, 27541, 13, 37390, 1330, 14826, 448, 274, 198, 220, 220, 220, 220, 220, 2...
2.782609
46
from typing import Any, Dict, List class Controller: """Provides a template for the functionality required from a controller class to interface with the experiment wrappper functionality. A controller class must implement the following methods: - __call__: takes in the current state and time and returns the control (note: a function object can be used, e.g.: def nominal_policy(x, t): return L @ x with L the LQR controller matrix""" from experiment_wrapper.experiment import Experiment, ScenarioList, Controllers from experiment_wrapper.rollout_trajectory import ( RolloutTrajectory, TimeSeriesExperiment, StateSpaceExperiment, ) from experiment_wrapper.experiment_suite import ExperimentSuite __version__ = "1.0.1"
[ 6738, 19720, 1330, 4377, 11, 360, 713, 11, 7343, 628, 198, 198, 4871, 22741, 25, 198, 220, 220, 220, 37227, 15946, 1460, 257, 11055, 329, 262, 11244, 2672, 422, 257, 10444, 1398, 284, 7071, 351, 262, 6306, 198, 220, 220, 220, 7917, ...
3.457399
223
#!/usr/bin/python # programmer : Bo # usage: Count_Reads_bin.py file_list import sys import re import random import string import time if __name__=="__main__": tS = time.time() bin = 50000 BL = Read_blacklist() #(B_site,B_name,C_reads,tt) = Read_data(sys.argv[1]) OP = main(sys.argv[1]) for each in OP: (B_site,B_name,B_reads,B_score,tt) = Read_data() data = main(each[:-1]) n = 0 m = 0 out = file('M50K_'+'_'+each[:-1],'w') #out.write(tt) for each in data: n += 1 if n == 1000000: m += 1 n = 0 print m,'million reads' te = each.split('\t') start = int(te[1]) end = int(te[2]) if te[0] not in B_site.keys(): continue if te[0] in BL.keys(): for ebi in range(len(BL[te[0]])): if start < BL[te[0]][ebi][1] and end > BL[te[0]][ebi][0]: continue ss = int(0.5+(start/50000))*50000 s = str(ss) w =int( len(s)/2) tag = s[:w+1] try : y = B_site[te[0]][tag][s] except: continue B_reads[y] += 1 B_score[y] += float(te[-1]) for i in range(len(B_name)): if B_reads[i] == 0: out.write(B_name[i]+'\t0\t0\n') else: out.write(B_name[i]+'\t'+str(B_reads[i])+'\t'+str(B_score[i]/B_reads[i])+'\n') out.close() tE = time.time() print 'Cost ',(tE-tS),' sec'
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 24292, 1058, 3248, 198, 2, 8748, 25, 2764, 62, 5569, 82, 62, 8800, 13, 9078, 2393, 62, 4868, 220, 220, 198, 198, 11748, 25064, 198, 11748, 302, 198, 11748, 4738, 198, 11748, 4731, 198, ...
1.618861
1,018
from collections import deque from copy import deepcopy from slm_lab.agent.memory.base import Memory from slm_lab.lib import logger, math_util, util from slm_lab.lib.decorator import lab_api import numpy as np import pydash as ps logger = logger.get_logger(__name__) def sample_next_states(head, max_size, ns_idx_offset, batch_idxs, states, ns_buffer): '''Method to sample next_states from states, with proper guard for next_state idx being out of bound''' # idxs for next state is state idxs with offset, modded ns_batch_idxs = (batch_idxs + ns_idx_offset) % max_size # if head < ns_idx <= head + ns_idx_offset, ns is stored in ns_buffer ns_batch_idxs = ns_batch_idxs % max_size buffer_ns_locs = np.argwhere( (head < ns_batch_idxs) & (ns_batch_idxs <= head + ns_idx_offset)).flatten() # find if there is any idxs to get from buffer to_replace = buffer_ns_locs.size != 0 if to_replace: # extract the buffer_idxs first for replacement later # given head < ns_idx <= head + offset, and valid buffer idx is [0, offset) # get 0 < ns_idx - head <= offset, or equiv. # get -1 < ns_idx - head - 1 <= offset - 1, i.e. # get 0 <= ns_idx - head - 1 < offset, hence: buffer_idxs = ns_batch_idxs[buffer_ns_locs] - head - 1 # set them to 0 first to allow sampling, then replace later with buffer ns_batch_idxs[buffer_ns_locs] = 0 # guard all against overrun idxs from offset ns_batch_idxs = ns_batch_idxs % max_size next_states = util.batch_get(states, ns_batch_idxs) if to_replace: # now replace using buffer_idxs and ns_buffer buffer_ns = util.batch_get(ns_buffer, buffer_idxs) next_states[buffer_ns_locs] = buffer_ns return next_states
[ 6738, 17268, 1330, 390, 4188, 198, 6738, 4866, 1330, 2769, 30073, 198, 6738, 1017, 76, 62, 23912, 13, 25781, 13, 31673, 13, 8692, 1330, 14059, 198, 6738, 1017, 76, 62, 23912, 13, 8019, 1330, 49706, 11, 10688, 62, 22602, 11, 7736, 198,...
2.553009
698
import yaml import sys Head = "# Dockerfile derived from easy::jit's .travis.yml" From = "ubuntu:latest" Manteiner = "Juan Manuel Martinez Caamao jmartinezcaamao@gmail.com" base_packages = ['build-essential', 'python', 'python-pip', 'git', 'wget', 'unzip', 'cmake'] travis = yaml.load(open(sys.argv[1])) travis_sources = travis['addons']['apt']['sources'] travis_packages = travis['addons']['apt']['packages'] before_install = travis['before_install'] script = travis['script'] # I could not get a better way to do this AddSourceCmd = { "llvm-toolchain-trusty-6.0" : "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main | tee -a /etc/apt/sources.list > /dev/null", "ubuntu-toolchain-r-test" : "apt-add-repository -y \"ppa:ubuntu-toolchain-r/test\"" } Sources = ["RUN {cmd} \n".format(cmd=AddSourceCmd[source]) for source in travis_sources] Apt = """# add sources RUN apt-get update RUN apt-get install -y software-properties-common {AddSources} # install apt packages, base first, then travis RUN apt-get update RUN apt-get upgrade -y RUN apt-get install -y {base_packages} && \\ apt-get install -y {travis_packages} """.format(AddSources = "".join(Sources), base_packages = " ".join(base_packages), travis_packages=" ".join(travis_packages)) Checkout = "RUN git clone --depth=50 --branch=${branch} https://github.com/jmmartinez/easy-just-in-time.git easy-just-in-time && cd easy-just-in-time\n" BeforeInstall = "".join(["RUN cd /easy-just-in-time && {0} \n".format(cmd) for cmd in before_install]) Run = "RUN cd easy-just-in-time && \\\n" + "".join([" {cmd} && \\ \n".format(cmd=cmd) for cmd in script]) + " echo ok!" Template = """{Head} FROM {From} LABEL manteiner {Manteiner} ARG branch=master {Apt} # checkout {Checkout} # install other deps {BeforeInstall} # compile and test! {Run}""" print(Template.format(Head=Head, From=From, Manteiner=Manteiner, Apt=Apt, BeforeInstall=BeforeInstall, Checkout=Checkout, Run=Run))
[ 11748, 331, 43695, 198, 11748, 25064, 198, 198, 13847, 796, 25113, 25716, 7753, 10944, 422, 2562, 3712, 45051, 338, 764, 83, 16956, 13, 88, 4029, 1, 198, 4863, 796, 366, 32230, 25, 42861, 1, 198, 44, 12427, 7274, 796, 366, 41, 7258, ...
2.69931
725
from api import models from api.twitter_tools.tweet_seeker import TweetSeeker
[ 6738, 40391, 1330, 4981, 198, 6738, 40391, 13, 6956, 62, 31391, 13, 83, 7277, 62, 325, 28233, 1330, 18752, 4653, 28233, 628 ]
3.590909
22
from twisted.internet import task from twisted.names import dns task.react(main)
[ 6738, 19074, 13, 37675, 1330, 4876, 198, 6738, 19074, 13, 14933, 1330, 288, 5907, 198, 198, 35943, 13, 45018, 7, 12417, 8, 198 ]
3.565217
23
from __future__ import print_function import numpy as np import pandas as pd from sklearn import metrics def get_substitute_cate(sample, target_index, opts): field_i = opts.fields_index_inverse.get(sample[target_index]) if field_i is None: field_i = np.random.choice(opts.fields_index.keys(),1)[0] field_cates = opts.fields_index[field_i] rst = np.random.choice(field_cates,1)[0] if len(field_cates) == 1: rst = np.random.randint(opts.vocabulary_size) return rst def generate_fake_sample(temp, opts): temp_sequence_length = len(temp) temp = temp[0:opts.sequence_length] if len(temp) < opts.sequence_length: gap = opts.sequence_length - len(temp) temp = np.array(temp + [0] * gap) else: temp_sequence_length = opts.sequence_length assert len(temp) == opts.sequence_length targets_to_avoid = set(temp) indices_to_avoid = set() substitute_index = np.random.randint(temp_sequence_length) substitute_target = get_substitute_cate(temp, substitute_index, opts) for _ in range(opts.substitute_num): while substitute_index in indices_to_avoid: substitute_index = np.random.randint(temp_sequence_length) indices_to_avoid.add(substitute_index) count = 0 while substitute_target in targets_to_avoid: if count > 5: break substitute_target = get_substitute_cate(temp, substitute_index, opts) count += 1 targets_to_avoid.add(substitute_target) temp[substitute_index] = substitute_target return temp
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 6738, 1341, 35720, 1330, 20731, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 198, 4299, ...
2.182741
788
try: from setuptools import setup except ImportError: from distutils.core import setup import versioneer def read(path): """ Read the contents of a file. """ with open(path) as f: return f.read() setup( classifiers=[ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], name='crochet', version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), description="Use Twisted anywhere!", install_requires=[ "Twisted>=15.0", "wrapt", ], keywords="twisted threading", license="MIT", packages=["crochet", "crochet.tests"], url="https://github.com/itamarst/crochet", maintainer='Itamar Turner-Trauring', maintainer_email='itamar@itamarst.org', long_description=read('README.rst') + '\n' + read('docs/news.rst'), )
[ 28311, 25, 198, 220, 220, 220, 422, 900, 37623, 10141, 1330, 9058, 198, 16341, 17267, 12331, 25, 198, 220, 220, 220, 422, 1233, 26791, 13, 7295, 1330, 9058, 198, 198, 11748, 2196, 28153, 628, 198, 4299, 1100, 7, 6978, 2599, 198, 220, ...
2.614141
495
from __future__ import division from __future__ import print_function from builtins import range from past.utils import old_div from pypusu.polling import PuSuClient from time import sleep, time if __name__ == "__main__": print("Connecting") c = PuSuClient("ws://127.0.0.1:55000") count = 0 print("Authorizing") c.authorize("foo") print("Subscribing") c.subscribe("channel.1", listener) print("Waiting") target = 500 start = time() for i in range(1, target + 1): c.publish("channel.1", {"foo": "bar"}) end = time() elapsed = end - start print("Sent {} messages in {:.3f}s, {:.2f}msg/s".format( target, elapsed, old_div(target, elapsed) )) sleep(1) print("So far got {} messages, polling...".format(count)) c.poll() print("After poll got {} messages, waiting for more...".format(count)) for i in range(0, 60): sleep(1) c.poll() print("Got {} messages".format(count))
[ 6738, 11593, 37443, 834, 1330, 7297, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 6738, 3170, 1040, 1330, 2837, 198, 6738, 1613, 13, 26791, 1330, 1468, 62, 7146, 198, 6738, 279, 4464, 385, 84, 13, 30393, 278, 1330, 11634, ...
2.498759
403
# Import libnacl libs import libnacl import libnacl.utils # Import python libs import unittest t = TestPublic() t.test_box_seal()
[ 2, 17267, 9195, 77, 37779, 9195, 82, 198, 11748, 9195, 77, 37779, 198, 11748, 9195, 77, 37779, 13, 26791, 198, 198, 2, 17267, 21015, 9195, 82, 198, 11748, 555, 715, 395, 628, 198, 83, 796, 6208, 15202, 3419, 198, 83, 13, 9288, 62, ...
2.75
48
from tkinter import Tk, Frame, Scrollbar, Label, Text, Button, Entry, StringVar, IntVar, TclError from tkinter.messagebox import showerror, showwarning from client import Client from threading import Thread from socket import error as socket_error destroy = False login = Tk() login.title("Login") host = StringVar() port = IntVar() Label(login, text="Host & port:").pack() login_f = Frame(login) login_f.pack() Entry(login_f, textvariable=host, width=14).grid(row=0, column=0) Entry(login_f, textvariable=port, width=4).grid(row=0, column=1) Button(login, text="Submit", command=start).pack() login.mainloop() tchat = Tk() tchat.title("PyTchat") tchat.protocol("WM_DELETE_WINDOW", on_closing) chat = Frame(tchat) chat.pack() scrollbar = Scrollbar(chat) scrollbar.pack(side="right", fill="y") chat_message = Text(chat, height=15, width=50, yscrollcommand=scrollbar.set, state="disable") chat_message.pack(side="left", fill="both") receive_thread = Thread(target=receive) receive_thread.start() entry = Frame(tchat) entry.pack() message = StringVar() field = Entry(entry, textvariable=message) field.bind("<Return>", send) field.grid(row=0, column=0) Button(entry, text="Send", command=send).grid(row=0, column=1) tchat.mainloop()
[ 6738, 256, 74, 3849, 1330, 309, 74, 11, 25184, 11, 17428, 5657, 11, 36052, 11, 8255, 11, 20969, 11, 21617, 11, 10903, 19852, 11, 2558, 19852, 11, 309, 565, 12331, 198, 6738, 256, 74, 3849, 13, 20500, 3524, 1330, 14643, 1472, 11, 905...
2.890443
429
"""Django urlpatterns declaration for nautobot_secrets_providers plugin.""" from django.urls import path from nautobot_secrets_providers import views app_name = "nautobot_secrets_providers" urlpatterns = [ path("", views.SecretsProvidersHomeView.as_view(), name="home"), ]
[ 37811, 35, 73, 14208, 19016, 33279, 82, 14305, 329, 299, 2306, 672, 313, 62, 2363, 8004, 62, 15234, 4157, 13877, 526, 15931, 198, 6738, 42625, 14208, 13, 6371, 82, 1330, 3108, 198, 198, 6738, 299, 2306, 672, 313, 62, 2363, 8004, 62, ...
2.867347
98
from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404, redirect, render from .forms import QuizForm from .models import Quiz
[ 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 12501, 273, 2024, 1330, 17594, 62, 35827, 198, 6738, 42625, 14208, 13, 7295, 13, 1069, 11755, 1330, 2448, 3411, 21306, 798, 198, 6738, 42625, 14208, 13, 19509, 23779, 1330, 651, 62, 1525...
3.405797
69
import discord from discord.ext import commands import asyncio import time from enum import Enum def setup(bot): bot.add_cog(Vote(bot))
[ 11748, 36446, 198, 6738, 36446, 13, 2302, 1330, 9729, 198, 198, 11748, 30351, 952, 198, 11748, 640, 198, 6738, 33829, 1330, 2039, 388, 198, 198, 4299, 9058, 7, 13645, 2599, 198, 220, 220, 220, 10214, 13, 2860, 62, 66, 519, 7, 37394, ...
3.086957
46
import inspect import threading import time from six.moves import urllib from ..errors import ConfigurationError from ..util import get_dependency from .base import Storage
[ 11748, 10104, 198, 11748, 4704, 278, 198, 11748, 640, 198, 198, 6738, 2237, 13, 76, 5241, 1330, 2956, 297, 571, 198, 198, 6738, 11485, 48277, 1330, 28373, 12331, 198, 6738, 11485, 22602, 1330, 651, 62, 45841, 1387, 198, 6738, 764, 8692,...
4
44
#!/usr/bin/python # -*- coding: utf-8 -*- import os from django.http import HttpResponse, HttpResponseForbidden from django.shortcuts import render_to_response from django.contrib.auth.decorators import login_required from caracole import settings from .decorators import nw_admin_required from .getters import get_delivery, get_subgroup from . import latex from .spreadsheet import spreadsheet from .delivery_description import delivery_description MIME_TYPE = { 'pdf': "application/pdf", 'xlsx': "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"} def non_html_response(name_bits, name_extension, content): """Common helper to serve PDF and Excel content.""" filename = ("_".join(name_bits) + "." + name_extension).replace(" ", "_") mime_type = MIME_TYPE[name_extension] response = HttpResponse(content_type=mime_type) response['Content-Disposition'] = 'attachment; filename="%s"' % filename response.write(content) return response
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 11748, 28686, 198, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 31077, 11, 367, 29281, 31077, 1890, 37978, 198, 6...
3.070769
325
import requests charset = "abcdefghijklmnopqrstuvwxyz0123456789_{}" password = "HackToday{" url = "http://sawah.ittoday.web.id:40137/" while(password[-1]!="}"): for i in charset: r = requests.get(url) payload = {'password': password+i, 'submit': 'Submit+Query'} r = requests.post(url, data=payload) if r.status_code==302: password+=i print password
[ 11748, 7007, 198, 198, 354, 945, 316, 796, 366, 39305, 4299, 456, 2926, 41582, 10295, 404, 80, 81, 301, 14795, 86, 5431, 89, 486, 1954, 2231, 3134, 4531, 23330, 36786, 198, 28712, 796, 366, 32833, 8888, 4895, 198, 6371, 796, 366, 4023...
2.163158
190
from __future__ import unicode_literals <<<<<<< HEAD __title__ = 'Mayan EDMS' __version__ = '2.7.3' __build__ = 0x020703 ======= __title__ = 'IITH DVC' __version__ = '2.7.2' __build__ = 0x020702 >>>>>>> 4cedd41ab6b9750abaebc35d1970556408d83cf5 __author__ = 'Roberto Rosario' __author_email__ = 'roberto.rosario@mayan-edms.com' __description__ = 'Free Open Source Electronic Document Management System' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2011-2016 Roberto Rosario'
[ 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, 198, 16791, 16791, 16791, 27, 39837, 198, 834, 7839, 834, 796, 705, 6747, 272, 8392, 5653, 6, 198, 834, 9641, 834, 796, 705, 17, 13, 22, 13, 18, 6, 198, 834, 11249, ...
2.644809
183
from __future__ import division import pandas as pd import numpy as np import calendar import os.path as op import sys from datetime import datetime from dateutil.relativedelta import relativedelta from scipy.stats import percentileofscore from scipy.stats import scoreatpercentile, pearsonr from math import * import time from BCSD_stats_functions import * import xarray as xr import os, errno
[ 6738, 11593, 37443, 834, 1330, 7297, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 11845, 198, 11748, 28686, 13, 6978, 355, 1034, 198, 11748, 25064, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 6...
3.482456
114
from bz2 import BZ2File from pathlib import Path from queue import Queue from threading import Thread from typing import Any, Callable, Dict, Iterator, List, Tuple from xmltodict import parse as xmltodict_parse
[ 6738, 275, 89, 17, 1330, 347, 57, 17, 8979, 198, 6738, 3108, 8019, 1330, 10644, 198, 6738, 16834, 1330, 4670, 518, 198, 6738, 4704, 278, 1330, 14122, 198, 6738, 19720, 1330, 4377, 11, 4889, 540, 11, 360, 713, 11, 40806, 1352, 11, 73...
3.242424
66
import cv2 import sys,json,numpy as np import glob,os import face_recognition import datetime from pathlib import Path from pymongo import MongoClient from flask_mongoengine import MongoEngine from bson.objectid import ObjectId face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') client = MongoClient(port=27017) db=client.GetMeThrough; home = str(os.path.dirname(os.path.abspath(__file__))) + "/../../" known_encodings_file_path = home + "/data/known_encodings_file.csv" people_file_path = home + "/data/people_file.csv" known_encodings_file = Path(known_encodings_file_path) if known_encodings_file.is_file(): known_encodings = np.genfromtxt(known_encodings_file, delimiter=',') else: known_encodings = [] people_file = Path(people_file_path) if people_file.is_file(): people = np.genfromtxt(people_file, dtype='U',delimiter=',') else: people = []
[ 11748, 269, 85, 17, 198, 11748, 25064, 11, 17752, 11, 77, 32152, 355, 45941, 198, 11748, 15095, 11, 418, 198, 11748, 1986, 62, 26243, 653, 198, 11748, 4818, 8079, 198, 6738, 3108, 8019, 1330, 10644, 198, 6738, 279, 4948, 25162, 1330, ...
2.740741
324
################################### # Created on 22:20, Nov. 16th, 2020 # Author: fassial # Filename: utils.py ################################### # dep import os import pandas as pd import scanpy as sp from collections import defaultdict # local dep # macro # def get_data_lm func # def get_data_csv func # def UTILS_GET_DATA_FUNC dict UTILS_GET_DATA_FUNC = defaultdict(lambda : get_data_csv, { ".loom": get_data_lm, ".csv": get_data_csv }) # def get_data func
[ 29113, 21017, 198, 2, 15622, 319, 2534, 25, 1238, 11, 5267, 13, 1467, 400, 11, 12131, 198, 2, 6434, 25, 277, 562, 498, 198, 2, 7066, 12453, 25, 3384, 4487, 13, 9078, 198, 29113, 21017, 198, 2, 1207, 198, 11748, 28686, 198, 11748, ...
2.902439
164
#! /usr/bin/env python # -*- coding: utf-8 -*- """ Created on Mon Jul 10 16:26:41 CEST 2017 @author: BMMN """ import gc # garbage collector import nacl.signing import nacl.encoding if __name__ == "__main__": # This in an example. In production, you would want to read the key from an # external file or the command line. The key must be 32 bytes long. # DON'T DO THIS IN PRODUCTION! signing_key, verify_key = key_gen() message = 'This is my message.' print("message : " + message) # signing signed = sign(signing_key, message) verify_key_hex = verify_key.encode(encoder=nacl.encoding.HexEncoder) print("signed: " + signed) print("verify_key_hex: " + verify_key_hex) # verification verify_key = nacl.signing.VerifyKey(verify_key_hex, encoder=nacl.encoding.HexEncoder) print() print("verification positive:") print(verify_key.verify(signed)) print() print("verification negative:") print(verify_key.verify("0"*len(signed))) # make sure all memory is flushed after operations del signing_key del signed del message del verify_key del verify_key_hex gc.collect()
[ 2, 0, 1220, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 2892, 5979, 838, 1467, 25, 2075, 25, 3901, 327, 6465, 2177, 198, 198, 31, 9800, 25, 347, ...
2.634921
441
# -*- coding: utf-8 -*- # Copyright (c) 2016 Osmo Salomaa # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import base64 import bs4 import cairosvg import contextlib import dotenv import flask import functools import imghdr import io import json import os import pickle import PIL.Image import random import re import requests import traceback import tweepy import unicodedata import urllib.parse import xml.etree.ElementTree as ET dotenv.load_dotenv() FALLBACK_PNG = open("letter-icons/x.png", "rb").read() LINK_REL_PATTERNS = [ re.compile("^apple-touch-icon$"), re.compile("^apple-touch-icon-precomposed$"), re.compile("^icon$"), re.compile("^shortcut icon$"), ] app = flask.Flask(__name__) blacklist = set() if app.config["ENV"] == "production": import redis cache = redis.from_url(os.environ["REDISCLOUD_URL"]) else: import redislite cache = redislite.Redis() # Cache HTTP connections for better performance. # https://urllib3.readthedocs.io/en/latest/advanced-usage.html#customizing-pool-behavior adapter = requests.adapters.HTTPAdapter(pool_connections=10, pool_maxsize=100, max_retries=0, pool_block=False) rs = requests.Session() rs.headers = {"User-Agent": "Mozilla/5.0"} rs.mount("http://", adapter) rs.mount("https://", adapter) def find_icons(url): """Yield icon entries specified in the HTML HEAD of `url`.""" url, page = get_page(url) soup = bs4.BeautifulSoup(page, "html.parser") for pattern in LINK_REL_PATTERNS: for tag in soup.find_all("link", dict(rel=pattern)): href = urllib.parse.urljoin(url, tag.attrs["href"]) size = tag.attrs.get("sizes", "0x0") if size == "any": size = "1000x1000" yield dict(url=href, size=int(size.split("x")[0])) # Fall back on looking for icons at the server root. join = lambda x: urllib.parse.urljoin(url, x) yield dict(url=join("/apple-touch-icon.png"), fallback=True) yield dict(url=join("/apple-touch-icon-precomposed.png"), fallback=True) def get_cache_control(max_age): """Return a Cache-Control header for `max_age`.""" return "public, max-age={:d}".format(max_age) def get_from_cache(key): """Return value, ttl for `key` from cache.""" return cache.get(key), cache.ttl(key) def get_letter(url): """Return letter to represent `url`.""" if "://" not in url: url = "http://{}".format(url) url = urllib.parse.urlparse(url).netloc url = url.split(".") url = url[-2] if len(url) > 1 else url[0] return url[0].lower() if url else "x" def get_page(url, timeout=15): """Return evaluated `url`, HTML page as text.""" if "://" in url: response = rs.get(url, timeout=timeout) response.raise_for_status() return response.url, response.text for scheme in ("https", "http"): with silent(Exception): return get_page("{}://{}".format(scheme, url)) raise Exception("Failed to get page") def is_svg(image): return (isinstance(image, str) and image.lstrip().startswith("<svg")) def make_response(data, format, max_age=None): """Return response 200 for `data` as `format`.""" if format == "base64": text = base64.b64encode(data) max_age = max_age or random.randint(1, 3) * 86400 return flask.Response(text, 200, { "Access-Control-Allow-Origin": "*", "Content-Type": "text/plain", "Content-Encoding": "UTF-8", "Content-Length": str(len(text)), "Cache-Control": get_cache_control(max_age), }) if format == "json": text = json.dumps(data, ensure_ascii=False) max_age = max_age or 3600 return flask.Response(text, 200, { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json", "Content-Encoding": "UTF-8", "Content-Length": str(len(text)), "Cache-Control": get_cache_control(max_age), }) if format == "png": max_age = max_age or random.randint(1, 3) * 86400 return flask.Response(data, 200, { "Access-Control-Allow-Origin": "*", "Content-Type": "image/png", "Content-Length": str(len(data)), "Cache-Control": get_cache_control(max_age), }) def request_image(url, max_size=1, timeout=15): """Request and return image at `url` at most `max_size` MB.""" # Avoid getting caught reading insanely large files. # http://docs.python-requests.org/en/master/user/advanced/#body-content-workflow if url in blacklist: raise ValueError("URL blacklisted") max_size = max_size * 1024 * 1024 with contextlib.closing(rs.get( url, timeout=timeout, stream=True)) as response: response.raise_for_status() if ("content-length" in response.headers and response.headers["content-length"].isdigit() and int(response.headers["content-length"]) > max_size): raise ValueError("Too large") content_type = response.headers.get("content-type", "").lower() if url.endswith(".svg") or content_type == "image/svg+xml": # SVG, return as string. image = response.text if len(image) > max_size: blacklist.add(url) raise ValueError("Too large") return image # Raster, return as bytes. image = response.raw.read(max_size+1, decode_content=True) if len(image) > max_size: blacklist.add(url) raise ValueError("Too large") return image def resize_image(image, size): """Resize `image` to `size` and return PNG bytes.""" if is_svg(image): image = cairosvg.svg2png(bytestring=image.encode("utf-8"), output_width=size, output_height=size) with PIL.Image.open(io.BytesIO(image)) as pi: if pi.mode not in ("RGB", "RGBA"): pi = pi.convert("RGBA") pi.thumbnail((size, size), PIL.Image.BICUBIC) if pi.width != pi.height: # Add transparent margins to make a square image. bg = PIL.Image.new("RGBA", (size, size), (255, 255, 255, 0)) bg.paste(pi, ((size - pi.width) // 2, (size - pi.height) // 2)) pi = bg out = io.BytesIO() pi.save(out, "PNG") return out.getvalue() def rex(a, b): """Return a random amount of seconds between a and b days.""" return random.randint(int(a*86400), int(b*86400))
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 2, 15069, 357, 66, 8, 1584, 440, 5796, 78, 4849, 6086, 64, 198, 2, 198, 2, 2448, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597, 1048, 16727, 257, ...
2.365502
3,264
# Generated by Django 1.10.6 on 2017-03-13 04:46 # Modified by Ral Negrn on 2019-06-22 16:48 import django.db.models.deletion import django.utils.timezone from django.conf import settings from django.db import migrations, models import apps.core.models
[ 2, 2980, 515, 416, 37770, 352, 13, 940, 13, 21, 319, 2177, 12, 3070, 12, 1485, 8702, 25, 3510, 198, 2, 40499, 416, 371, 282, 13496, 35906, 319, 13130, 12, 3312, 12, 1828, 1467, 25, 2780, 198, 198, 11748, 42625, 14208, 13, 9945, 13...
2.976744
86
# -*- coding: utf-8 -*- """ obspy.io.nied.knet - K-NET/KiK-net read support for ObsPy ========================================================= Reading of the K-NET and KiK-net ASCII format as defined on http://www.kyoshin.bosai.go.jp. """ from __future__ import (absolute_import, division, print_function, unicode_literals) from future.builtins import * # NOQA @UnusedWildImport import re import numpy as np from obspy import UTCDateTime, Stream, Trace from obspy.core.trace import Stats def _buffer_proxy(filename_or_buf, function, reset_fp=True, file_mode="rb", *args, **kwargs): """ Calls a function with an open file or file-like object as the first argument. If the file originally was a filename, the file will be opened, otherwise it will just be passed to the underlying function. :param filename_or_buf: File to pass. :type filename_or_buf: str, open file, or file-like object. :param function: The function to call. :param reset_fp: If True, the file pointer will be set to the initial position after the function has been called. :type reset_fp: bool :param file_mode: Mode to open file in if necessary. """ try: position = filename_or_buf.tell() is_buffer = True except AttributeError: is_buffer = False if is_buffer is True: ret_val = function(filename_or_buf, *args, **kwargs) if reset_fp: filename_or_buf.seek(position, 0) return ret_val else: with open(filename_or_buf, file_mode) as fh: return function(fh, *args, **kwargs) def _is_knet_ascii(filename_or_buf): """ Checks if the file is a valid K-NET/KiK-net ASCII file. :param filename_or_buf: File to test. :type filename_or_buf: str or file-like object. """ try: return _buffer_proxy(filename_or_buf, _internal_is_knet_ascii, reset_fp=True) # Happens for example when passing the data as a string which would be # interpreted as a filename. except (OSError, UnicodeDecodeError): return False def _internal_is_knet_ascii(buf): """ Checks if the file is a valid K-NET/KiK-net ASCII file. :param buf: File to read. :type buf: Open file or open file like object. """ first_string = buf.read(11).decode() # File has less than 11 characters if len(first_string) != 11: return False if first_string == 'Origin Time': return True return False def _prep_hdr_line(name, line): """ Helper function to check the contents of a header line and split it. :param name: String that the line should start with. :type name: str :param line: Line to check and split. :type line: str """ if not line.startswith(name): raise KNETException("Expected line to start with %s but got %s " % (name, line)) else: return line.split() def _read_knet_hdr(hdrlines, convert_stnm=False, **kwargs): """ Read the header values into a dictionary. :param hdrlines: List of the header lines of a a K-NET/KiK-net ASCII file :type hdrlines: list :param convert_stnm: For station names with 6 letters write the last two letters of the station code to the 'location' field :type convert_stnm: bool """ hdrdict = {'knet': {}} hdrnames = ['Origin Time', 'Lat.', 'Long.', 'Depth. (km)', 'Mag.', 'Station Code', 'Station Lat.', 'Station Long.', 'Station Height(m)', 'Record Time', 'Sampling Freq(Hz)', 'Duration Time(s)', 'Dir.', 'Scale Factor', 'Max. Acc. (gal)', 'Last Correction', 'Memo.'] _i = 0 # Event information flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) dt = flds[2] + ' ' + flds[3] dt = UTCDateTime.strptime(dt, '%Y/%m/%d %H:%M:%S') # All times are in Japanese standard time which is 9 hours ahead of UTC dt -= 9 * 3600. hdrdict['knet']['evot'] = dt _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) lat = float(flds[1]) hdrdict['knet']['evla'] = lat _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) lon = float(flds[1]) hdrdict['knet']['evlo'] = lon _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) dp = float(flds[2]) hdrdict['knet']['evdp'] = dp _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) mag = float(flds[1]) hdrdict['knet']['mag'] = mag # Station information _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) # K-NET and KiK-Net station names can be more than 5 characters long # which will cause the station name to be truncated when writing the # the trace as miniSEED; if convert_stnm is enabled, the last two # letters of the station code are written to the 'location' field stnm = flds[2] location = '' if convert_stnm and len(stnm) > 5: location = stnm[-2:] stnm = stnm[:-2] if len(stnm) > 7: raise KNETException( "Station name can't be more than 7 characters long!") hdrdict['station'] = stnm hdrdict['location'] = location _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) hdrdict['knet']['stla'] = float(flds[2]) _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) hdrdict['knet']['stlo'] = float(flds[2]) _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) hdrdict['knet']['stel'] = float(flds[2]) # Data information _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) dt = flds[2] + ' ' + flds[3] # A 15 s delay is added to the record time by the # the K-NET and KiK-Net data logger dt = UTCDateTime.strptime(dt, '%Y/%m/%d %H:%M:%S') - 15.0 # All times are in Japanese standard time which is 9 hours ahead of UTC dt -= 9 * 3600. hdrdict['starttime'] = dt _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) freqstr = flds[2] m = re.search('[0-9]*', freqstr) freq = int(m.group()) hdrdict['sampling_rate'] = freq _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) hdrdict['knet']['duration'] = float(flds[2]) _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) channel = flds[1].replace('-', '') kiknetcomps = {'1': 'NS1', '2': 'EW1', '3': 'UD1', '4': 'NS2', '5': 'EW2', '6': 'UD2'} if channel.strip() in kiknetcomps.keys(): # kiknet directions are 1-6 channel = kiknetcomps[channel.strip()] hdrdict['channel'] = channel _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) eqn = flds[2] num, denom = eqn.split('/') num = float(re.search('[0-9]*', num).group()) denom = float(denom) # convert the calibration from gal to m/s^2 hdrdict['calib'] = 0.01 * num / denom _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) acc = float(flds[3]) hdrdict['knet']['accmax'] = acc _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) dt = flds[2] + ' ' + flds[3] dt = UTCDateTime.strptime(dt, '%Y/%m/%d %H:%M:%S') # All times are in Japanese standard time which is 9 hours ahead of UTC dt -= 9 * 3600. hdrdict['knet']['last correction'] = dt # The comment ('Memo') field is optional _i += 1 flds = _prep_hdr_line(hdrnames[_i], hdrlines[_i]) if len(flds) > 1: hdrdict['knet']['comment'] = ' '.join(flds[1:]) if len(hdrlines) != _i + 1: raise KNETException("Expected %d header lines but got %d" % (_i + 1, len(hdrlines))) return hdrdict def _read_knet_ascii(filename_or_buf, **kwargs): """ Reads a K-NET/KiK-net ASCII file and returns an ObsPy Stream object. .. warning:: This function should NOT be called directly, it registers via the ObsPy :func:`~obspy.core.stream.read` function, call this instead. :param filename: K-NET/KiK-net ASCII file to be read. :type filename: str or file-like object. """ return _buffer_proxy(filename_or_buf, _internal_read_knet_ascii, **kwargs) def _internal_read_knet_ascii(buf, **kwargs): """ Reads a K-NET/KiK-net ASCII file and returns an ObsPy Stream object. .. warning:: This function should NOT be called directly, it registers via the ObsPy :func:`~obspy.core.stream.read` function, call this instead. :param buf: File to read. :type buf: Open file or open file like object. """ data = [] hdrdict = {} cur_pos = buf.tell() buf.seek(0, 2) size = buf.tell() buf.seek(cur_pos, 0) # First read the headerlines headerlines = [] while buf.tell() < size: line = buf.readline().decode() headerlines.append(line) if line.startswith('Memo'): hdrdict = _read_knet_hdr(headerlines, **kwargs) break while buf.tell() < size: line = buf.readline() parts = line.strip().split() data += [float(p) for p in parts] hdrdict['npts'] = len(data) # The FDSN network code for the National Research Institute for Earth # Science and Disaster Prevention (NEID JAPAN) is BO (Bosai-Ken Network) hdrdict['network'] = 'BO' data = np.array(data) stats = Stats(hdrdict) trace = Trace(data, header=stats) return Stream([trace]) if __name__ == '__main__': import doctest doctest.testmod(exclude_empty=True)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 672, 2777, 88, 13, 952, 13, 77, 798, 13, 74, 3262, 532, 509, 12, 12884, 14, 42, 72, 42, 12, 3262, 1100, 1104, 329, 11086, 20519, 198, 10052, 4770, 2559, ...
2.273051
4,208
from .base import Dataset from .pandas_dataset import MetaPandasDataset, PandasDataset from .sqlalchemy_dataset import MetaSqlAlchemyDataset, SqlAlchemyDataset
[ 6738, 764, 8692, 1330, 16092, 292, 316, 198, 6738, 764, 79, 392, 292, 62, 19608, 292, 316, 1330, 30277, 47206, 292, 27354, 292, 316, 11, 16492, 292, 27354, 292, 316, 198, 6738, 764, 25410, 282, 26599, 62, 19608, 292, 316, 1330, 30277,...
2.789474
57
from flask import Blueprint, jsonify, request, redirect, abort, url_for, render_template main = Blueprint('main', __name__) # routes
[ 6738, 42903, 1330, 39932, 11, 33918, 1958, 11, 2581, 11, 18941, 11, 15614, 11, 19016, 62, 1640, 11, 8543, 62, 28243, 198, 12417, 796, 39932, 10786, 12417, 3256, 11593, 3672, 834, 8, 198, 2, 11926, 198 ]
3.694444
36
# *************************************************************** # Copyright (c) 2020 Jittor. Authors: Dun Liang <randonlang@gmail.com>. All Rights Reserved. # This file is subject to the terms and conditions defined in # file 'LICENSE.txt', which is part of this source code package. # *************************************************************** import unittest import jittor as jt import numpy as np from .test_core import expect_error if __name__ == "__main__": unittest.main()
[ 2, 41906, 8412, 46068, 8162, 198, 2, 15069, 357, 66, 8, 12131, 449, 715, 273, 13, 46665, 25, 5648, 43322, 1279, 81, 5063, 17204, 31, 14816, 13, 785, 28401, 1439, 6923, 33876, 13, 198, 2, 770, 2393, 318, 2426, 284, 262, 2846, 290, ...
3.99187
123
from typing import Union from mre.Regex import Regex
[ 6738, 19720, 1330, 4479, 198, 198, 6738, 285, 260, 13, 3041, 25636, 1330, 797, 25636, 628 ]
3.4375
16
# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. import sys import tvm from tvm.ir.module import IRModule from tvm.script import tir as T from tvm.tir.function import PrimFunc if __name__ == "__main__": test_matmul()
[ 2, 49962, 284, 262, 24843, 10442, 5693, 357, 1921, 37, 8, 739, 530, 198, 2, 393, 517, 18920, 5964, 11704, 13, 220, 4091, 262, 28536, 2393, 198, 2, 9387, 351, 428, 670, 329, 3224, 1321, 198, 2, 5115, 6634, 9238, 13, 220, 383, 7054,...
3.743191
257
from Artist import Artist
[ 6738, 18902, 1330, 18902, 198 ]
5.2
5
#!/usr/bin/env python from collections import defaultdict from itertools import product import json import random import sys from annoy import AnnoyIndex from Bio import SeqIO import numpy as np
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 6738, 17268, 1330, 4277, 11600, 198, 6738, 340, 861, 10141, 1330, 1720, 198, 11748, 33918, 198, 11748, 4738, 198, 11748, 25064, 198, 198, 6738, 10072, 1330, 5506, 726, 15732, 198, 1...
3.636364
55
# tf.transformations alternative is not yet available in tf2 from tf.transformations import quaternion_from_euler if __name__ == '__main__': # RPY to convert: 90deg, 0, -90deg q = quaternion_from_euler(1.5707, 0, -1.5707) print "The quaternion representation is %s %s %s %s." % (q[0], q[1], q[2], q[3])
[ 2, 48700, 13, 35636, 602, 5559, 318, 407, 1865, 1695, 287, 48700, 17, 198, 6738, 48700, 13, 35636, 602, 1330, 627, 9205, 295, 62, 6738, 62, 68, 18173, 198, 220, 220, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 628...
2.57377
122
import datetime from django.contrib.auth.models import User, Group from django.utils import timezone from rest_framework.test import APITestCase import fvh_courier.models.base from fvh_courier import models
[ 11748, 4818, 8079, 198, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 11787, 11, 4912, 198, 6738, 42625, 14208, 13, 26791, 1330, 640, 11340, 198, 6738, 1334, 62, 30604, 13, 9288, 1330, 3486, 2043, 395, 20448, 198, ...
3.181818
66
""" Binder classes perform two functions through their format method - given a query template with %(somevar)s python substition class MyClass(object): pass arg1 = MyClass() arg1.customer = 101 default = MyClass() default.customer = 201 arg2.country = "CAN" qry, sub = format(" select * from customer where country = %(country)s and custid = %(customer)s", arg1, default) means that we will be fetching for country=CAN, custid=101 - the query template itself is transformed to a format that fits the underlying database's bind variable scheme which protects against sql injection attacks. For example, assuming an Oracle database (paramstyle="named") qry: "select * from customer where country = :country and custid = :customer" sub: {"country":"CAN", "customer" : 101} Postgres (paramstyle=""): qry: "select * from customer where country = :country and custid = :customer" sub: {"country":"CAN", "customer" : 101} a positional database (paramstyle="numeric") (NotImplementedError) would instead return qry: "select * from customer where country = :1 and custid = :2" sub: ["CAN", 101] """ import re PARAMSTYLE_QMARK = PARAMSTYLE_SQLITE = PARAMSTYLE_SQLSERVER = "qmark" ExperimentalBinderNamed = BinderNamed # This is what decides how the Binder # will process incoming template substitutions Binder._di_paramstyle["pyformat"] = Binder_pyformat Binder._di_paramstyle["named"] = BinderNamed Binder._di_paramstyle[PARAMSTYLE_QMARK] = BinderQmark Binder._di_paramstyle["format"] = BinderFormat Binder._di_paramstyle["experimentalnamed"] = ExperimentalBinderNamed # and these are not done yet Binder._di_paramstyle["numeric"] = Binder_NotImplementedError
[ 37811, 198, 33, 5540, 6097, 1620, 734, 5499, 832, 511, 5794, 2446, 198, 198, 12, 1813, 257, 12405, 11055, 351, 4064, 7, 11246, 7785, 8, 82, 21015, 3293, 653, 628, 198, 220, 220, 220, 1398, 2011, 9487, 7, 15252, 2599, 198, 220, 220, ...
2.918006
622
# -*- coding: utf-8 -*- # # parselglossy -- Generic input parsing library, speaking in tongues # Copyright (C) 2020 Roberto Di Remigio, Radovan Bast, and contributors. # # This file is part of parselglossy. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # For information on the complete list of contributors to the # parselglossy library, see: <http://parselglossy.readthedocs.io/> # """Documentation generation.""" from typing import List # noqa: F401 from .utils import JSONDict def documentation_generator( template: JSONDict, *, header: str = "Input parameters" ) -> str: """Generates documentation from a valid template. Parameters ---------- template : JSONDict The template to generate documentation from. We assume that the template is valid. Returns ------- documentation : str """ comment = ( ".. raw:: html\n\n" # noqa: F541 " <style> .red {color:#aa0060; font-weight:bold; font-size:18px} </style>\n\n" # noqa: E501 ".. role:: red\n\n" f".. This documentation was autogenerated using parselglossy." " Editing by hand is not recommended.\n" ) header = ( f"{comment:s}\n{'=' * len(header):s}\n{header:s}\n{'=' * len(header):s}\n\n" "- Keywords without a default value are **required**.\n" "- Default values are either explicit or computed from the value of other keywords in the input.\n" # noqa: E501 "- Sections where all keywords have a default value can be omitted.\n" "- Predicates, if present, are the functions run to validate user input.\n" ) docs = _rec_documentation_generator(template=template) documentation = header + docs return documentation def _rec_documentation_generator(template, *, level: int = 0) -> str: """Generates documentation from a valid template. Parameters ---------- template : JSONDict level : int Returns ------- docs : str """ docs = [] # type: List[str] keywords = template["keywords"] if "keywords" in template.keys() else [] if keywords: docs.append(_indent("\n:red:`Keywords`", level)) for k in keywords: doc = _document_keyword(k) docs.extend(_indent(doc, level)) sections = template["sections"] if "sections" in template.keys() else [] if sections: docs.append(_indent("\n:red:`Sections`", level)) for s in sections: docstring = s["docstring"].replace("\n", " ") doc = f"\n :{s['name']:s}: {docstring:s}\n" doc += _rec_documentation_generator(s, level=level + 1) docs.extend(_indent(doc, level)) return "".join(docs)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 198, 2, 1582, 741, 4743, 793, 88, 1377, 42044, 5128, 32096, 5888, 11, 5486, 287, 39413, 198, 2, 15069, 357, 34, 8, 12131, 32076, 6031, 3982, 328, 952, 11, 5325, 2...
2.880124
1,293
import numpy as np
[ 11748, 299, 32152, 355, 45941, 198 ]
3.166667
6
# -*- coding: utf-8 -*- import glob import os import json from collections import OrderedDict import itertools import re from datetime import datetime import six from six import iteritems from flask.ext.sqlalchemy import SQLAlchemy from sqlalchemy import or_ from .. import field_names, localization from ..models import AccidentMarker, Involved, Vehicle from .. import models from ..utilities import ItmToWGS84, init_flask, CsvReader, time_delta, decode_hebrew,ImporterUI,truncate_tables from functools import partial import logging failed_dirs = OrderedDict() CONTENT_ENCODING = 'cp1255' ACCIDENT_TYPE_REGEX = re.compile(r"Accidents Type (?P<type>\d)") ACCIDENTS = 'accidents' CITIES = 'cities' STREETS = 'streets' ROADS = "roads" URBAN_INTERSECTION = 'urban_intersection' NON_URBAN_INTERSECTION = 'non_urban_intersection' DICTIONARY = "dictionary" INVOLVED = "involved" VEHICLES = "vehicles" cbs_files = { ACCIDENTS: "AccData.csv", URBAN_INTERSECTION: "IntersectUrban.csv", NON_URBAN_INTERSECTION: "IntersectNonUrban.csv", STREETS: "DicStreets.csv", DICTIONARY: "Dictionary.csv", INVOLVED: "InvData.csv", VEHICLES: "VehData.csv" } coordinates_converter = ItmToWGS84() app = init_flask() db = SQLAlchemy(app) json_dumps = partial(json.dumps, encoding=models.db_encoding) if six.PY2 else json.dumps def get_street(settlement_sign, street_sign, streets): """ extracts the street name using the settlement id and street id """ if settlement_sign not in streets: # Changed to return blank string instead of None for correct presentation (Omer) return u"" street_name = [decode_hebrew(x[field_names.street_name]) for x in streets[settlement_sign] if x[field_names.street_sign] == street_sign] # there should be only one street name, or none if it wasn't found. return street_name[0] if len(street_name) == 1 else u"" def get_address(accident, streets): """ extracts the address of the main street. tries to build the full address: <street_name> <street_number>, <settlement>, but might return a partial one if unsuccessful. """ street = get_street(accident[field_names.settlement_sign], accident[field_names.street1], streets) if not street: return u"" # the home field is invalid if it's empty or if it contains 9999 home = accident[field_names.home] if accident[field_names.home] != 9999 else None settlement = localization.get_city_name(accident[field_names.settlement_sign]) if not home and not settlement: return street if not home and settlement: return u"{}, {}".format(street, settlement) if home and not settlement: return u"{} {}".format(street, home) return u"{} {}, {}".format(street, home, settlement) def get_streets(accident, streets): """ extracts the streets the accident occurred in. every accident has a main street and a secondary street. :return: a tuple containing both streets. """ main_street = get_address(accident, streets) secondary_street = get_street(accident[field_names.settlement_sign], accident[field_names.street2], streets) return main_street, secondary_street def get_junction(accident, roads): """ extracts the junction from an accident omerxx: added "km" parameter to the calculation to only show the right junction, every non-urban accident shows nearest junction with distance and direction :return: returns the junction or None if it wasn't found """ if accident["KM"] is not None and accident[field_names.non_urban_intersection] is None: min_dist = 100000 key = (), () junc_km = 0 for option in roads: if accident[field_names.road1] == option[0] and abs(accident["KM"]-option[2]) < min_dist: min_dist = abs(accident["KM"]-option[2]) key = accident[field_names.road1], option[1], option[2] junc_km = option[2] junction = roads.get(key, None) if junction: if accident["KM"] - junc_km > 0: direction = u"" if accident[field_names.road1] % 2 == 0 else u"" else: direction = u"" if accident[field_names.road1] % 2 == 0 else u"" if abs(float(accident["KM"] - junc_km)/10) >= 1: string = str(abs(float(accident["KM"])-junc_km)/10) + u" " + direction + u" " + \ decode_hebrew(junction) elif 0 < abs(float(accident["KM"] - junc_km)/10) < 1: string = str(int((abs(float(accident["KM"])-junc_km)/10)*1000)) + u" " + direction + u" " + \ decode_hebrew(junction) else: string = decode_hebrew(junction) return string else: return u"" elif accident[field_names.non_urban_intersection] is not None: key = accident[field_names.road1], accident[field_names.road2], accident["KM"] junction = roads.get(key, None) return decode_hebrew(junction) if junction else u"" else: return u"" def parse_date(accident): """ parses an accident's date """ year = accident[field_names.accident_year] month = accident[field_names.accident_month] day = accident[field_names.accident_day] ''' hours calculation explanation - The value of the hours is between 1 to 96. These values represent 15 minutes each that start at 00:00: 1 equals 00:00, 2 equals 00:15, 3 equals 00:30 and so on. ''' minutes = accident[field_names.accident_hour] * 15 - 15 hours = int(minutes // 60) minutes %= 60 accident_date = datetime(year, month, day, hours, minutes, 0) return accident_date def load_extra_data(accident, streets, roads): """ loads more data about the accident :return: a dictionary containing all the extra fields and their values :rtype: dict """ extra_fields = {} # if the accident occurred in an urban setting if bool(accident[field_names.urban_intersection]): main_street, secondary_street = get_streets(accident, streets) if main_street: extra_fields[field_names.street1] = main_street if secondary_street: extra_fields[field_names.street2] = secondary_street # if the accident occurred in a non urban setting (highway, etc') if bool(accident[field_names.non_urban_intersection]): junction = get_junction(accident, roads) if junction: extra_fields[field_names.junction_name] = junction # localize static accident values for field in localization.get_supported_tables(): # if we have a localized field for that particular field, save the field value # it will be fetched we deserialized if accident[field] and localization.get_field(field, accident[field]): extra_fields[field] = accident[field] return extra_fields def get_data_value(value): """ :returns: value for parameters which are not mandatory in an accident data OR -1 if the parameter value does not exist """ return int(value) if value else -1 def import_to_datastore(directory, provider_code, batch_size): """ goes through all the files in a given directory, parses and commits them """ try: xrange except NameError: xrange = range try: assert batch_size > 0 files_from_cbs = dict(get_files(directory)) if len(files_from_cbs) == 0: return 0 logging.info("Importing '{}'".format(directory)) started = datetime.now() new_items = 0 all_existing_accidents_ids = set(map(lambda x: x[0], db.session.query(AccidentMarker.id).all())) accidents = import_accidents(provider_code=provider_code, **files_from_cbs) accidents = [accident for accident in accidents if accident['id'] not in all_existing_accidents_ids] new_items += len(accidents) for accidents_chunk in chunks(accidents, batch_size, xrange): db.session.bulk_insert_mappings(AccidentMarker, accidents_chunk) all_involved_accident_ids = set(map(lambda x: x[0], db.session.query(Involved.accident_id).all())) involved = import_involved(provider_code=provider_code, **files_from_cbs) involved = [x for x in involved if x['accident_id'] not in all_involved_accident_ids] for involved_chunk in chunks(involved, batch_size, xrange): db.session.bulk_insert_mappings(Involved, involved_chunk) new_items += len(involved) all_vehicles_accident_ids = set(map(lambda x: x[0], db.session.query(Vehicle.accident_id).all())) vehicles = import_vehicles(provider_code=provider_code, **files_from_cbs) vehicles = [x for x in vehicles if x['accident_id'] not in all_vehicles_accident_ids] for vehicles_chunk in chunks(vehicles, batch_size, xrange): db.session.bulk_insert_mappings(Vehicle, vehicles_chunk) new_items += len(vehicles) logging.info("\t{0} items in {1}".format(new_items, time_delta(started))) return new_items except ValueError as e: failed_dirs[directory] = str(e) return 0 def delete_invalid_entries(): """ deletes all markers in the database with null latitude or longitude first deletes from tables Involved and Vehicle, then from table AccidentMarker """ marker_ids_to_delete = db.session.query(AccidentMarker.id).filter(or_((AccidentMarker.longitude == None), (AccidentMarker.latitude == None))).all() marker_ids_to_delete = [acc_id[0] for acc_id in marker_ids_to_delete] q = db.session.query(Involved).filter(Involved.accident_id.in_(marker_ids_to_delete)) if q.all(): print('deleting invalid entries from Involved') q.delete(synchronize_session='fetch') q = db.session.query(Vehicle).filter(Vehicle.accident_id.in_(marker_ids_to_delete)) if q.all(): print('deleting invalid entries from Vehicle') q.delete(synchronize_session='fetch') q = db.session.query(AccidentMarker).filter(AccidentMarker.id.in_(marker_ids_to_delete)) if q.all(): print('deleting invalid entries from AccidentMarker') q.delete(synchronize_session='fetch') db.session.commit()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 15095, 198, 11748, 28686, 198, 11748, 33918, 198, 6738, 17268, 1330, 14230, 1068, 35, 713, 198, 11748, 340, 861, 10141, 198, 11748, 302, 198, 6738, 4818, 8079, 1330...
2.555255
4,072
# -*- coding: utf-8 -*- """ (c) 2020 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon <pingou@pingoured.fr> """ from __future__ import unicode_literals, absolute_import import datetime import json import unittest import shutil import sys import tempfile import os import pygit2 from celery.result import EagerResult from mock import patch, Mock sys.path.insert( 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") ) import pagure.api import pagure.flask_app import pagure.lib.query import tests from pagure.lib.repo import PagureRepo
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 37811, 198, 357, 66, 8, 12131, 532, 15069, 2297, 10983, 3457, 628, 46665, 25, 198, 220, 220, 21204, 12, 56, 1158, 609, 571, 261, 1279, 13886, 280, 31, 13886, 8167...
2.802956
203
# Copyright 2020 Google LLC. 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. # NOTE: this is adapted from the official TFX taxi pipeline sample # You can find it here: https://github.com/tensorflow/tfx/tree/master/tfx/examples/chicago_taxi_pipeline import os # pylint: disable=unused-import # Pipeline name will be used to identify this pipeline PIPELINE_NAME = 'my_pipeline' # TODO: replace with your Google Cloud project GOOGLE_CLOUD_PROJECT='your-cloud-project' # TODO: replace with the GCS bucket where you'd like to store model artifacts # Only include the bucket name here, without the 'gs://' GCS_BUCKET_NAME = 'your-gcs-bucket' # TODO: set your Google Cloud region below (or use us-central1) GOOGLE_CLOUD_REGION = 'us-central1' RUN_FN = 'pipeline.model.run_fn' TRAIN_NUM_STEPS = 100 EVAL_NUM_STEPS = 100 BIG_QUERY_WITH_DIRECT_RUNNER_BEAM_PIPELINE_ARGS = [ '--project=' + GOOGLE_CLOUD_PROJECT, '--temp_location=' + os.path.join('gs://', GCS_BUCKET_NAME, 'tmp'), ] # The rate at which to sample rows from the Chicago Taxi dataset using BigQuery. # The full taxi dataset is > 120M record. In the interest of resource # savings and time, we've set the default for this example to be much smaller. # Feel free to crank it up and process the full dataset! _query_sample_rate = 0.0001 # Generate a 0.01% random sample. # The query that extracts the examples from BigQuery. This sample uses # a BigQuery public dataset from NOAA BIG_QUERY_QUERY = """ SELECT usa_wind, usa_sshs FROM `bigquery-public-data.noaa_hurricanes.hurricanes` WHERE latitude > 19.5 AND latitude < 64.85 AND longitude > -161.755 AND longitude < -68.01 AND usa_wind IS NOT NULL AND longitude IS NOT NULL AND latitude IS NOT NULL AND usa_sshs IS NOT NULL AND usa_sshs > 0 """ # A dict which contains the training job parameters to be passed to Google # Cloud AI Platform. For the full set of parameters supported by Google Cloud AI # Platform, refer to # https://cloud.google.com/ml-engine/reference/rest/v1/projects.jobs#Job GCP_AI_PLATFORM_TRAINING_ARGS = { 'project': GOOGLE_CLOUD_PROJECT, 'region': 'us-central1', # Starting from TFX 0.14, training on AI Platform uses custom containers: # https://cloud.google.com/ml-engine/docs/containers-overview # You can specify a custom container here. If not specified, TFX will use # a public container image matching the installed version of TFX. # Set your container name below. 'masterConfig': { 'imageUri': 'gcr.io/' + GOOGLE_CLOUD_PROJECT + '/tfx-pipeline' }, # Note that if you do specify a custom container, ensure the entrypoint # calls into TFX's run_executor script (tfx/scripts/run_executor.py) } # A dict which contains the serving job parameters to be passed to Google # Cloud AI Platform. For the full set of parameters supported by Google Cloud AI # Platform, refer to # https://cloud.google.com/ml-engine/reference/rest/v1/projects.models GCP_AI_PLATFORM_SERVING_ARGS = { 'model_name': PIPELINE_NAME, 'project_id': GOOGLE_CLOUD_PROJECT, # The region to use when serving the model. See available regions here: # https://cloud.google.com/ml-engine/docs/regions 'regions': [GOOGLE_CLOUD_REGION], }
[ 2, 15069, 12131, 3012, 11419, 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, 13789, ...
2.932567
1,305
import unittest import sys import os import py_compile from vatools import vcf_info_annotator import tempfile from filecmp import cmp
[ 11748, 555, 715, 395, 198, 11748, 25064, 198, 11748, 28686, 198, 11748, 12972, 62, 5589, 576, 198, 6738, 410, 265, 10141, 1330, 410, 12993, 62, 10951, 62, 34574, 1352, 198, 11748, 20218, 7753, 198, 6738, 2393, 48991, 1330, 269, 3149, 19...
3.268293
41
# Generated by the protocol buffer compiler. DO NOT EDIT! # source: peer/admin.proto import sys _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database from google.protobuf import descriptor_pb2 # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 DESCRIPTOR = _descriptor.FileDescriptor( name='peer/admin.proto', package='protos', syntax='proto3', serialized_pb=_b('\n\x10peer/admin.proto\x12\x06protos\x1a\x1bgoogle/protobuf/empty.proto\"\x9a\x01\n\x0cServerStatus\x12/\n\x06status\x18\x01 \x01(\x0e\x32\x1f.protos.ServerStatus.StatusCode\"Y\n\nStatusCode\x12\r\n\tUNDEFINED\x10\x00\x12\x0b\n\x07STARTED\x10\x01\x12\x0b\n\x07STOPPED\x10\x02\x12\n\n\x06PAUSED\x10\x03\x12\t\n\x05\x45RROR\x10\x04\x12\x0b\n\x07UNKNOWN\x10\x05\"8\n\x0fLogLevelRequest\x12\x12\n\nlog_module\x18\x01 \x01(\t\x12\x11\n\tlog_level\x18\x02 \x01(\t\"9\n\x10LogLevelResponse\x12\x12\n\nlog_module\x18\x01 \x01(\t\x12\x11\n\tlog_level\x18\x02 \x01(\t2\xd5\x02\n\x05\x41\x64min\x12;\n\tGetStatus\x12\x16.google.protobuf.Empty\x1a\x14.protos.ServerStatus\"\x00\x12=\n\x0bStartServer\x12\x16.google.protobuf.Empty\x1a\x14.protos.ServerStatus\"\x00\x12<\n\nStopServer\x12\x16.google.protobuf.Empty\x1a\x14.protos.ServerStatus\"\x00\x12H\n\x11GetModuleLogLevel\x12\x17.protos.LogLevelRequest\x1a\x18.protos.LogLevelResponse\"\x00\x12H\n\x11SetModuleLogLevel\x12\x17.protos.LogLevelRequest\x1a\x18.protos.LogLevelResponse\"\x00\x42+Z)github.com/hyperledger/fabric/protos/peerb\x06proto3') , dependencies=[google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,]) _sym_db.RegisterFileDescriptor(DESCRIPTOR) _SERVERSTATUS_STATUSCODE = _descriptor.EnumDescriptor( name='StatusCode', full_name='protos.ServerStatus.StatusCode', filename=None, file=DESCRIPTOR, values=[ _descriptor.EnumValueDescriptor( name='UNDEFINED', index=0, number=0, options=None, type=None), _descriptor.EnumValueDescriptor( name='STARTED', index=1, number=1, options=None, type=None), _descriptor.EnumValueDescriptor( name='STOPPED', index=2, number=2, options=None, type=None), _descriptor.EnumValueDescriptor( name='PAUSED', index=3, number=3, options=None, type=None), _descriptor.EnumValueDescriptor( name='ERROR', index=4, number=4, options=None, type=None), _descriptor.EnumValueDescriptor( name='UNKNOWN', index=5, number=5, options=None, type=None), ], containing_type=None, options=None, serialized_start=123, serialized_end=212, ) _sym_db.RegisterEnumDescriptor(_SERVERSTATUS_STATUSCODE) _SERVERSTATUS = _descriptor.Descriptor( name='ServerStatus', full_name='protos.ServerStatus', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='status', full_name='protos.ServerStatus.status', index=0, number=1, type=14, cpp_type=8, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ _SERVERSTATUS_STATUSCODE, ], options=None, is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], serialized_start=58, serialized_end=212, ) _LOGLEVELREQUEST = _descriptor.Descriptor( name='LogLevelRequest', full_name='protos.LogLevelRequest', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='log_module', full_name='protos.LogLevelRequest.log_module', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='log_level', full_name='protos.LogLevelRequest.log_level', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], serialized_start=214, serialized_end=270, ) _LOGLEVELRESPONSE = _descriptor.Descriptor( name='LogLevelResponse', full_name='protos.LogLevelResponse', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='log_module', full_name='protos.LogLevelResponse.log_module', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='log_level', full_name='protos.LogLevelResponse.log_level', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], serialized_start=272, serialized_end=329, ) _SERVERSTATUS.fields_by_name['status'].enum_type = _SERVERSTATUS_STATUSCODE _SERVERSTATUS_STATUSCODE.containing_type = _SERVERSTATUS DESCRIPTOR.message_types_by_name['ServerStatus'] = _SERVERSTATUS DESCRIPTOR.message_types_by_name['LogLevelRequest'] = _LOGLEVELREQUEST DESCRIPTOR.message_types_by_name['LogLevelResponse'] = _LOGLEVELRESPONSE ServerStatus = _reflection.GeneratedProtocolMessageType('ServerStatus', (_message.Message,), dict( DESCRIPTOR = _SERVERSTATUS, __module__ = 'peer.admin_pb2' # @@protoc_insertion_point(class_scope:protos.ServerStatus) )) _sym_db.RegisterMessage(ServerStatus) LogLevelRequest = _reflection.GeneratedProtocolMessageType('LogLevelRequest', (_message.Message,), dict( DESCRIPTOR = _LOGLEVELREQUEST, __module__ = 'peer.admin_pb2' # @@protoc_insertion_point(class_scope:protos.LogLevelRequest) )) _sym_db.RegisterMessage(LogLevelRequest) LogLevelResponse = _reflection.GeneratedProtocolMessageType('LogLevelResponse', (_message.Message,), dict( DESCRIPTOR = _LOGLEVELRESPONSE, __module__ = 'peer.admin_pb2' # @@protoc_insertion_point(class_scope:protos.LogLevelResponse) )) _sym_db.RegisterMessage(LogLevelResponse) DESCRIPTOR.has_options = True DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('Z)github.com/hyperledger/fabric/protos/peer')) try: # THESE ELEMENTS WILL BE DEPRECATED. # Please use the generated *_pb2_grpc.py files instead. import grpc from grpc.framework.common import cardinality from grpc.framework.interfaces.face import utilities as face_utilities from grpc.beta import implementations as beta_implementations from grpc.beta import interfaces as beta_interfaces def add_AdminServicer_to_server(servicer, server): rpc_method_handlers = { 'GetStatus': grpc.unary_unary_rpc_method_handler( servicer.GetStatus, request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, response_serializer=ServerStatus.SerializeToString, ), 'StartServer': grpc.unary_unary_rpc_method_handler( servicer.StartServer, request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, response_serializer=ServerStatus.SerializeToString, ), 'StopServer': grpc.unary_unary_rpc_method_handler( servicer.StopServer, request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, response_serializer=ServerStatus.SerializeToString, ), 'GetModuleLogLevel': grpc.unary_unary_rpc_method_handler( servicer.GetModuleLogLevel, request_deserializer=LogLevelRequest.FromString, response_serializer=LogLevelResponse.SerializeToString, ), 'SetModuleLogLevel': grpc.unary_unary_rpc_method_handler( servicer.SetModuleLogLevel, request_deserializer=LogLevelRequest.FromString, response_serializer=LogLevelResponse.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( 'protos.Admin', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) def beta_create_Admin_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): """The Beta API is deprecated for 0.15.0 and later. It is recommended to use the GA API (classes and functions in this file not marked beta) for all further purposes. This function was generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" request_deserializers = { ('protos.Admin', 'GetModuleLogLevel'): LogLevelRequest.FromString, ('protos.Admin', 'GetStatus'): google_dot_protobuf_dot_empty__pb2.Empty.FromString, ('protos.Admin', 'SetModuleLogLevel'): LogLevelRequest.FromString, ('protos.Admin', 'StartServer'): google_dot_protobuf_dot_empty__pb2.Empty.FromString, ('protos.Admin', 'StopServer'): google_dot_protobuf_dot_empty__pb2.Empty.FromString, } response_serializers = { ('protos.Admin', 'GetModuleLogLevel'): LogLevelResponse.SerializeToString, ('protos.Admin', 'GetStatus'): ServerStatus.SerializeToString, ('protos.Admin', 'SetModuleLogLevel'): LogLevelResponse.SerializeToString, ('protos.Admin', 'StartServer'): ServerStatus.SerializeToString, ('protos.Admin', 'StopServer'): ServerStatus.SerializeToString, } method_implementations = { ('protos.Admin', 'GetModuleLogLevel'): face_utilities.unary_unary_inline(servicer.GetModuleLogLevel), ('protos.Admin', 'GetStatus'): face_utilities.unary_unary_inline(servicer.GetStatus), ('protos.Admin', 'SetModuleLogLevel'): face_utilities.unary_unary_inline(servicer.SetModuleLogLevel), ('protos.Admin', 'StartServer'): face_utilities.unary_unary_inline(servicer.StartServer), ('protos.Admin', 'StopServer'): face_utilities.unary_unary_inline(servicer.StopServer), } server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) return beta_implementations.server(method_implementations, options=server_options) def beta_create_Admin_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): """The Beta API is deprecated for 0.15.0 and later. It is recommended to use the GA API (classes and functions in this file not marked beta) for all further purposes. This function was generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" request_serializers = { ('protos.Admin', 'GetModuleLogLevel'): LogLevelRequest.SerializeToString, ('protos.Admin', 'GetStatus'): google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, ('protos.Admin', 'SetModuleLogLevel'): LogLevelRequest.SerializeToString, ('protos.Admin', 'StartServer'): google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, ('protos.Admin', 'StopServer'): google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, } response_deserializers = { ('protos.Admin', 'GetModuleLogLevel'): LogLevelResponse.FromString, ('protos.Admin', 'GetStatus'): ServerStatus.FromString, ('protos.Admin', 'SetModuleLogLevel'): LogLevelResponse.FromString, ('protos.Admin', 'StartServer'): ServerStatus.FromString, ('protos.Admin', 'StopServer'): ServerStatus.FromString, } cardinalities = { 'GetModuleLogLevel': cardinality.Cardinality.UNARY_UNARY, 'GetStatus': cardinality.Cardinality.UNARY_UNARY, 'SetModuleLogLevel': cardinality.Cardinality.UNARY_UNARY, 'StartServer': cardinality.Cardinality.UNARY_UNARY, 'StopServer': cardinality.Cardinality.UNARY_UNARY, } stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) return beta_implementations.dynamic_stub(channel, 'protos.Admin', cardinalities, options=stub_options) except ImportError: pass # @@protoc_insertion_point(module_scope)
[ 2, 2980, 515, 416, 262, 8435, 11876, 17050, 13, 220, 8410, 5626, 48483, 0, 198, 2, 2723, 25, 12720, 14, 28482, 13, 1676, 1462, 198, 198, 11748, 25064, 198, 62, 65, 28, 17597, 13, 9641, 62, 10951, 58, 15, 60, 27, 18, 290, 357, 50...
2.51322
5,257
from pathlib import Path from tempfile import mkdtemp from nose.tools import eq_ from anycache import AnyCache from anycache import get_defaultcache from anycache import anycache def test_basic(): """Basic functionality.""" myfunc.callcount = 0 eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) eq_(myfunc(4, 2), 6) eq_(myfunc.callcount, 2) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 2) assert get_defaultcache().size > 0 def test_cleanup(): """Cleanup.""" ac = AnyCache() cachedir = ac.cachedir myfunc.callcount = 0 # first use eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) eq_(myfunc(4, 2), 6) eq_(myfunc.callcount, 2) eq_(myfunc(4, 2), 6) eq_(myfunc.callcount, 2) assert ac.size > 0 # clear ac.clear() eq_(ac.size, 0) eq_(tuple(cachedir.glob("*")), tuple()) # second use eq_(myfunc(4, 4), 8) eq_(myfunc.callcount, 3) assert ac.size > 0 # clear twice ac.clear() eq_(ac.size, 0) ac.clear() eq_(ac.size, 0) def test_size(): """Size.""" ac = AnyCache() eq_(ac.size, 0) eq_(len(tuple(ac.cachedir.glob("*.cache"))), 0) eq_(myfunc(4, 5), 9) eq_(len(tuple(ac.cachedir.glob("*.cache"))), 1) size1 = ac.size eq_(myfunc(4, 2), 6) eq_(ac.size, 2 * size1) eq_(len(tuple(ac.cachedir.glob("*.cache"))), 2) def test_corrupt_cache(): """Corrupted Cache.""" cachedir = Path(mkdtemp()) ac = AnyCache(cachedir=cachedir) myfunc.callcount = 0 eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) # corrupt cache cachefilepath = list(cachedir.glob("*.cache"))[0] with open(str(cachefilepath), "w") as cachefile: cachefile.write("foo") # repair eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 2) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 2) # corrupt dep depfilepath = list(cachedir.glob("*.dep"))[0] with open(str(depfilepath), "w") as depfile: depfile.write("foo") # repair eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 3) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 3) ac.clear() def test_cachedir(): """Corrupted Cache.""" cachedir = Path(mkdtemp()) myfunc.callcount = 0 eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 1) myfunc.callcount = 0 eq_(myfunc(4, 5), 9) eq_(myfunc.callcount, 0)
[ 6738, 3108, 8019, 1330, 10644, 198, 6738, 20218, 7753, 1330, 33480, 67, 29510, 198, 198, 6738, 9686, 13, 31391, 1330, 37430, 62, 198, 198, 6738, 597, 23870, 1330, 4377, 30562, 198, 6738, 597, 23870, 1330, 651, 62, 12286, 23870, 198, 673...
2.135843
1,222
"""A run_fn method called by the TFX Trainer component.""" import os import logging from tfx import v1 as tfx from tfx_taxifare_tips.model_training import defaults from tfx_taxifare_tips.model_training import model_trainer from tfx_taxifare_tips.model_training import model_exporter # TFX Trainer will call this function. def run_fn(fn_args: tfx.components.FnArgs): """Train the model based on given args. Args: fn_args: Holds args used to train the model as name/value pairs. See https://www.tensorflow.org/tfx/api_docs/python/tfx/v1/components/FnArgs. """ logging.info("Model Runner started...") logging.info("fn_args: %s", fn_args) logging.info("") try: log_dir = fn_args.model_run_dir except KeyError: log_dir = os.path.join(os.path.dirname(fn_args.serving_model_dir), "logs") hyperparameters = fn_args.hyperparameters if not hyperparameters: hyperparameters = {} hyperparameters = defaults.update_hyperparameters(hyperparameters) logging.info("Hyperparameter:") logging.info(hyperparameters) logging.info("") logging.info("Model Runner executing model trainer...") classifier = model_trainer.train( data_accessor=fn_args.data_accessor, train_data_dir=fn_args.train_files, eval_data_dir=fn_args.eval_files, tft_output_dir=fn_args.transform_output, log_dir=log_dir, hyperparameters=hyperparameters, ) logging.info("Model Runner executing model evaluation...") classifier = model_trainer.evaluate( classifier=classifier, data_accessor=fn_args.data_accessor, eval_data_dir=fn_args.eval_files, tft_output_dir=fn_args.transform_output, hyperparameters=hyperparameters, ) logging.info("Model Runner executing exporter...") model_exporter.export_serving_model( classifier=classifier, serving_model_dir=fn_args.serving_model_dir, raw_schema_location=fn_args.schema_path, tft_output_dir=fn_args.transform_output, ) logging.info("Model Runner completed.")
[ 37811, 32, 1057, 62, 22184, 2446, 1444, 416, 262, 309, 17213, 31924, 7515, 526, 15931, 201, 198, 201, 198, 11748, 28686, 201, 198, 11748, 18931, 201, 198, 6738, 256, 21373, 1330, 410, 16, 355, 256, 21373, 201, 198, 6738, 256, 21373, 6...
2.414444
900
import random, os, string, subprocess, shutil, requests from discord import Webhook, RequestsWebhookAdapter, Embed from dotenv import dotenv_values import argparse, colorama from colorama import Fore if __name__ == "__main__": colorama.init(autoreset=True) parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", help="Display errors in console.", action="store_true", default=False) args = parser.parse_args() CONFIG = Settings() app = App(CONFIG) try: app.run() except Exception as e: if args.verbose: print(e) exit(f'{Fore.RED}An Error occured program will exit.')
[ 11748, 4738, 11, 28686, 11, 4731, 11, 850, 14681, 11, 4423, 346, 11, 7007, 198, 6738, 36446, 1330, 5313, 25480, 11, 9394, 3558, 13908, 25480, 47307, 11, 13302, 276, 198, 6738, 16605, 24330, 1330, 16605, 24330, 62, 27160, 198, 11748, 182...
2.72314
242
from .board import Board from .slide import slide_action from .corner import corner_action from .control import control_action from .penalty import penalty_action from .throwin import throwin_action from .kickoff import kickoff_action from .goalkick import goalkick_action from .freekick import freekick_action from .without_ball import without_ball_action
[ 6738, 764, 3526, 1330, 5926, 198, 6738, 764, 6649, 485, 1330, 10649, 62, 2673, 198, 6738, 764, 10215, 1008, 1330, 5228, 62, 2673, 198, 6738, 764, 13716, 1330, 1630, 62, 2673, 198, 6738, 764, 3617, 6017, 1330, 7389, 62, 2673, 198, 6738...
3.797872
94
"""Bin Testing""" # standard library from importlib.machinery import SourceFileLoader from importlib.util import module_from_spec, spec_from_loader from typing import List # third-party from typer.testing import CliRunner # dynamically load bin/tcex file spec = spec_from_loader('app', SourceFileLoader('app', 'bin/tcex')) tcex_cli = module_from_spec(spec) spec.loader.exec_module(tcex_cli) # get app from bin/tcex CLI script app = tcex_cli.app # get instance of typer CliRunner for test case runner = CliRunner()
[ 37811, 33, 259, 23983, 37811, 198, 2, 3210, 5888, 198, 6738, 1330, 8019, 13, 76, 620, 15451, 1330, 8090, 8979, 17401, 198, 6738, 1330, 8019, 13, 22602, 1330, 8265, 62, 6738, 62, 16684, 11, 1020, 62, 6738, 62, 29356, 198, 6738, 19720, ...
3.035088
171
# 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, _tables from . import outputs from ._inputs import * __all__ = ['ManagedPrefixListArgs', 'ManagedPrefixList'] def _internal_init(__self__, resource_name: str, opts: Optional[pulumi.ResourceOptions] = None, address_family: Optional[pulumi.Input[str]] = None, entries: Optional[pulumi.Input[Sequence[pulumi.Input[pulumi.InputType['ManagedPrefixListEntryArgs']]]]] = None, max_entries: Optional[pulumi.Input[int]] = None, name: Optional[pulumi.Input[str]] = None, tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None, __props__=None, __name__=None, __opts__=None): if __name__ is not None: warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning) resource_name = __name__ if __opts__ is not None: warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning) opts = __opts__ if opts is None: opts = pulumi.ResourceOptions() if not isinstance(opts, pulumi.ResourceOptions): raise TypeError('Expected resource options to be a ResourceOptions instance') if opts.version is None: opts.version = _utilities.get_version() if opts.id is None: if __props__ is not None: raise TypeError('__props__ is only valid when passed in combination with a valid opts.id to get an existing resource') __props__ = dict() if address_family is None and not opts.urn: raise TypeError("Missing required property 'address_family'") __props__['address_family'] = address_family __props__['entries'] = entries if max_entries is None and not opts.urn: raise TypeError("Missing required property 'max_entries'") __props__['max_entries'] = max_entries __props__['name'] = name __props__['tags'] = tags __props__['arn'] = None __props__['owner_id'] = None __props__['version'] = None super(ManagedPrefixList, __self__).__init__( 'aws:ec2/managedPrefixList:ManagedPrefixList', resource_name, __props__, opts) def translate_output_property(self, prop): return _tables.CAMEL_TO_SNAKE_CASE_TABLE.get(prop) or prop def translate_input_property(self, prop): return _tables.SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop
[ 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.241301
1,322
# coding=utf-8 """LeNet for MNIST""" import os from keras.datasets import mnist from keras.models import Sequential from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D from keras.utils import np_utils from keras.callbacks import ModelCheckpoint, TensorBoard from snntoolbox.parsing.utils import \ get_quantized_activation_function_from_string from snntoolbox.utils.utils import ClampedReLU (X_train, y_train), (X_test, y_test) = mnist.load_data() X_train = X_train.reshape(X_train.shape[0], 1, 28, 28).astype('float32') / 255. X_test = X_test.reshape(X_test.shape[0], 1, 28, 28).astype('float32') / 255. Y_train = np_utils.to_categorical(y_train, 10) Y_test = np_utils.to_categorical(y_test, 10) # nonlinearity = get_quantized_activation_function_from_string('relu_Q1.4') # nonlinearity = ClampedReLU nonlinearity = 'relu' model = Sequential() model.add(Conv2D(6, (5, 5), input_shape=(1, 28, 28), activation=nonlinearity)) model.add(MaxPooling2D()) model.add(Conv2D(16, (5, 5), activation=nonlinearity)) model.add(MaxPooling2D()) model.add(Dropout(0.5)) model.add(Conv2D(120, (5, 5), padding='same', activation=nonlinearity)) model.add(Flatten()) model.add(Dense(84, activation=nonlinearity)) model.add(Dense(10, activation='softmax')) model.compile('adam', 'categorical_crossentropy', metrics=['accuracy']) path = '/home/rbodo/.snntoolbox/data/mnist/cnn/lenet5/keras/gradients' checkpoint = ModelCheckpoint('weights.{epoch:02d}-{val_acc:.2f}.h5', 'val_acc') gradients = TensorBoard(os.path.join(path, 'logs'), 2, write_grads=True) model.fit(X_train, Y_train, validation_data=(X_test, Y_test), callbacks=[checkpoint, gradients]) score = model.evaluate(X_test, Y_test) print('Test score:', score[0]) print('Test accuracy:', score[1]) model.save(os.path.join(path, '{:2.2f}.h5'.format(score[1]*100)))
[ 2, 19617, 28, 40477, 12, 23, 198, 198, 37811, 3123, 7934, 329, 29060, 8808, 37811, 198, 198, 11748, 28686, 198, 6738, 41927, 292, 13, 19608, 292, 1039, 1330, 285, 77, 396, 198, 6738, 41927, 292, 13, 27530, 1330, 24604, 1843, 198, 6738...
2.516349
734
import numpy as np x = 1.0 #define a float y = 2.0 #define another float #trigonometry print(f"np.sin({x}) = {np.sin(x)}") #sin(x) print(f"np.cos({x}) = {np.cos(x)}") #cos(x) print(f"np.tan({x}) = {np.tan(x)}") #tan(x) print(f"np.arcsin({x}) = {np.arcsin(x)}") #arcsin(x) print(f"np.arccos({x}) = {np.arccos(x)}") #arccos(x) print(f"np.arctan({x}) = {np.arctan(x)}") #arctan(x) print(f"np.arctan2({x}) = {np.arctan2(x,y)}") #arctan(x/y) print(f"np.rad2deg({x}) = {np.rad2deg(x)}") #convert rad to degree #hyperbolic functions print(f"np.sinh({x}) = {np.sinh(x)}") #sinh(x) print(f"np.cosh({x}) = {np.cosh(x)}") #cosh(x) print(f"np.tanh({x}) = {np.tanh(x)}") #tanh(x) print(f"np.arcsinh({x}) = {np.arcsinh(x)}") #arcsinh(x) print(f"np.arccosh({x}) = {np.arccosh(x)}") #arccosh(x) print(f"np.arctanh({x}) = {np.arctanh(x)}") #arctanh(x)
[ 11748, 299, 32152, 355, 45941, 201, 198, 87, 796, 352, 13, 15, 1303, 13086, 257, 12178, 201, 198, 88, 796, 362, 13, 15, 1303, 13086, 1194, 12178, 201, 198, 201, 198, 2, 2213, 37107, 15748, 201, 198, 4798, 7, 69, 1, 37659, 13, 3136...
1.821277
470
# Generated by Django 2.1.2 on 2018-10-27 15:50 from django.conf import settings from django.db import migrations, models import django.db.models.deletion import django_countries.fields
[ 2, 2980, 515, 416, 37770, 362, 13, 16, 13, 17, 319, 2864, 12, 940, 12, 1983, 1315, 25, 1120, 198, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 198, 11748, 42625, 1420...
3.081967
61
import argparse from mahjong.shanten import Shanten from multiprocessing import Pool import os import sys from log_parser.discard_prediction_parser import parse_discard_prediction SHANTEN = Shanten() INPUT_DATA_FOLDER = "data/raw" OUTPUT_DATA_DIR = "data/single_hand_efficiency" if __name__ == '__main__': parser = argparse.ArgumentParser(fromfile_prefix_chars='@') parser.add_argument('--start_date', default='') parser.add_argument('--end_date', default='') known_args, _ = parser.parse_known_args(sys.argv) date_to_process = [] for date in os.listdir(INPUT_DATA_FOLDER): if date >= known_args.start_date and date <= known_args.end_date: date_to_process.append(date) print date_to_process generate_data(date_to_process[0]) # multithread generate training data #p = Pool(NUM_THREADS) #p.map(generate_data, date_to_process)
[ 11748, 1822, 29572, 198, 6738, 42768, 32428, 13, 1477, 415, 268, 1330, 49892, 268, 198, 6738, 18540, 305, 919, 278, 1330, 19850, 198, 11748, 28686, 198, 11748, 25064, 198, 198, 6738, 2604, 62, 48610, 13, 15410, 446, 62, 28764, 2867, 62,...
2.594203
345
from JumpScale import j
[ 6738, 15903, 29990, 1330, 474, 628 ]
4.166667
6
# This file is only used to generate documentation # VM class # PyQBDI module functions def alignedAlloc(size, align): """Allocate a block of memory of a specified sized with an aligned base address. :param size: Allocation size in bytes. :param align: Base address alignement in bytes. :returns: Pointer to the allocated memory (as a long) or NULL in case an error was encountered. """ pass def alignedFree(): """ """ pass def allocateVirtualStack(ctx, stackSize): """Allocate a new stack and setup the GPRState accordingly. The allocated stack needs to be freed with alignedFree(). :param ctx: GPRState which will be setup to use the new stack. :param stackSize: Size of the stack to be allocated. :returns: A tuple (bool, stack) where 'bool' is true if stack allocation was successfull. And 'stack' the newly allocated stack pointer. """ pass def simulateCall(ctx, returnAddress, args): """Simulate a call by modifying the stack and registers accordingly. :param ctx: GPRState where the simulated call will be setup. The state needs to point to a valid stack for example setup with allocateVirtualStack(). :param returnAddress: Return address of the call to simulate. :param args: A list of arguments. """ pass def getModuleNames(): """ Get a list of all the module names loaded in the process memory. :returns: A list of strings, each one containing the name of a loaded module. """ pass def getCurrentProcessMaps(): """ Get a list of all the memory maps (regions) of the current process. :returns: A list of :py:class:`MemoryMap` object. """ pass def readMemory(address, size): """Read a memory content from a base address. :param address: Base address :param size: Read size :returns: Bytes of content. .. warning:: This API is hazardous as the whole process memory can be read. """ pass def writeMemory(address, bytes): """Write a memory content to a base address. :param address: Base address :param bytes: Memory content .. warning:: This API is hazardous as the whole process memory can be written. """ pass def decodeFloat(val): """ Decode a float stored as a long. :param val: Long value. """ pass def encodeFloat(val): """Encode a float as a long. :param val: Float value """ pass # Various objects GPRState = None """ GPRState object, a binding to :cpp:type:`QBDI::GPRState` """ FPRState = None """ FPRState object, a binding to :cpp:type:`QBDI::FPRState` """
[ 2, 770, 2393, 318, 691, 973, 284, 7716, 10314, 198, 198, 2, 16990, 1398, 628, 198, 2, 9485, 48, 14529, 40, 8265, 5499, 198, 4299, 19874, 3237, 420, 7, 7857, 11, 10548, 2599, 198, 220, 220, 220, 37227, 3237, 13369, 257, 2512, 286, ...
2.951299
924
# -*- coding: utf-8 -*- """Scrapy settings.""" BOT_NAME = 'krkbipscraper' SPIDER_MODULES = ['krkbipscraper.spiders'] NEWSPIDER_MODULE = 'krkbipscraper.spiders' ITEM_PIPELINES = ['krkbipscraper.pipelines.JsonWriterPipeline']
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 3351, 2416, 88, 6460, 526, 15931, 198, 198, 33, 2394, 62, 20608, 796, 705, 38584, 32812, 541, 1416, 38545, 6, 198, 198, 4303, 41237, 62, 33365, 6239, 1546, 796, ...
2.22549
102
# Importao da biblioteca. # Certifique-se de ter a biblioteca instalada. import pyhdb # Essa funo traz/chama outro arquivo que contm a senha, visando no deixar exposta na aplicao. # Caso no queira utilizar esse mtodo e inserir diretamente a senha na conexo, exclua esse bloco e insira a senha diretamente no bloco (def connect) em (passoword). # Realiza a conexo com o Sap Hana. # Executa a query no Sap Hana. if __name__ == '__main__': connect() # Execuo a funo de conexo. resultado = query_exec() # Executa a funo de execuo da query. print (resultado) # Imprimi o resultado no terminal.
[ 2, 17267, 5488, 12379, 275, 29142, 313, 31047, 13, 220, 198, 2, 14965, 361, 2350, 12, 325, 390, 1059, 257, 275, 29142, 313, 31047, 916, 282, 4763, 13, 198, 11748, 12972, 71, 9945, 198, 198, 2, 11985, 64, 1257, 78, 1291, 89, 14, 35...
2.611111
234
# Copyright 2019 Ondrej Skopek. # # 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 pytest import torch from mt.mvae import utils from mt.mvae.distributions.von_mises_fisher import VonMisesFisher dims = [2, 3, 4] scales = [1e9, 1e5, 1e1, 1e0, 1e-5, 1e-15] # This does not depend on the mean (loc), just it's dimensionality. # This does not depend on the mean (loc), just it's dimensionality.
[ 2, 15069, 13130, 440, 358, 260, 73, 3661, 404, 988, 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,...
3.48227
282
""" Download CellO's resources files. These files include CellO's pre-trained models, gene ID-to-symbol mappings, and training sets for training CellO's models on new gene sets. Authors: Matthew Bernstein <mbernstein@morgridge.org> """ import subprocess from os.path import join from shutil import which
[ 37811, 198, 10002, 12440, 46, 338, 4133, 3696, 13, 2312, 3696, 2291, 12440, 46, 338, 662, 12, 35311, 198, 27530, 11, 9779, 4522, 12, 1462, 12, 1837, 23650, 285, 39242, 11, 290, 3047, 5621, 329, 3047, 12440, 46, 338, 198, 27530, 319, ...
3.611765
85
from abc import ABCMeta, abstractmethod import torch import torch.nn.functional as F from addict import Dict from mmtrack.models import TRACKERS
[ 6738, 450, 66, 1330, 9738, 48526, 11, 12531, 24396, 198, 198, 11748, 28034, 198, 11748, 28034, 13, 20471, 13, 45124, 355, 376, 198, 6738, 19678, 1330, 360, 713, 198, 198, 6738, 8085, 11659, 13, 27530, 1330, 7579, 8120, 4877, 628 ]
3.7
40
# Copyright 2019-2022 The University of Manchester, UK # Copyright 2020-2022 Vlaams Instituut voor Biotechnologie (VIB), BE # Copyright 2020-2022 Barcelona Supercomputing Center (BSC), ES # Copyright 2020-2022 Center for Advanced Studies, Research and Development in Sardinia (CRS4), IT # Copyright 2022 cole Polytechnique Fdrale de Lausanne, CH # # 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 json import pathlib import shutil import pytest from rocrate.utils import get_norm_value THIS_DIR = pathlib.Path(__file__).absolute().parent TEST_DATA_NAME = 'test-data' BASE_URL = 'https://w3id.org/ro/crate' VERSION = '1.1' LEGACY_VERSION = '1.0' # pytest's default tmpdir returns a py.path object
[ 2, 15069, 13130, 12, 1238, 1828, 383, 2059, 286, 9502, 11, 3482, 198, 2, 15069, 12131, 12, 1238, 1828, 569, 5031, 4105, 2262, 34272, 315, 410, 2675, 8436, 1258, 1349, 928, 494, 357, 53, 9865, 828, 9348, 198, 2, 15069, 12131, 12, 123...
3.417614
352
#!/usr/bin/python from __future__ import print_function import unittest import json import os import sys import requests sys.path.insert(0, os.path.abspath(os.path.join( os.path.dirname(os.path.realpath(__file__)), os.pardir, "cli"))) from cli.marathon import Marathon from cli.appconfig import AppConfig from mockito import mock, when # Test basic functionalities of MarathonValidator class if __name__ == '__main__': unittest.main()
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 11748, 555, 715, 395, 198, 11748, 33918, 198, 11748, 28686, 198, 11748, 25064, 198, 11748, 7007, 198, 17597, 13, 6978, 13, 28463, 7, 1...
2.98
150
numbers = list(map(int, input().split(','))) print(len(numbers))
[ 77, 17024, 796, 1351, 7, 8899, 7, 600, 11, 5128, 22446, 35312, 7, 41707, 22305, 198, 4798, 7, 11925, 7, 77, 17024, 4008, 198 ]
2.708333
24
from flask import Flask, request import json app = Flask(__name__) if __name__ == '__main__': app.run()
[ 6738, 42903, 1330, 46947, 11, 2581, 198, 11748, 33918, 198, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 598, 13, 5143, 3419 ]
2.842105
38
import pytest import nlp from nlp4e import Rules, Lexicon, Grammar, ProbRules, ProbLexicon, ProbGrammar, E0 from nlp4e import Chart, CYK_parse, subspan, astar_search_parsing, beam_search_parsing # Clumsy imports because we want to access certain nlp.py globals explicitly, because # they are accessed by functions within nlp.py if __name__ == '__main__': pytest.main()
[ 11748, 12972, 9288, 201, 198, 11748, 299, 34431, 201, 198, 201, 198, 6738, 299, 34431, 19, 68, 1330, 14252, 11, 17210, 4749, 11, 20159, 3876, 11, 30873, 37766, 11, 30873, 45117, 4749, 11, 30873, 38, 859, 3876, 11, 412, 15, 201, 198, ...
2.56875
160
#!/usr/bin/python3 import binascii import random import cosim
[ 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 198, 11748, 9874, 292, 979, 72, 198, 11748, 4738, 198, 11748, 8615, 320, 628 ]
2.782609
23
""" Module for common target stage stack configurations. """ import logging import numpy as np from datetime import datetime import os from ophyd.device import Device import json import jsonschema import yaml from itertools import chain from pcdsdevices.epics_motor import _GetMotorClass from .interface import tweak_base logger = logging.getLogger(__name__) def StageStack(mdict, name): """ Conveniencefunction for generating a stage stack device. Intended for bundling various motors into a single object. The function takes a dictionary of PVs and/or previously instantiated motor objects and bundles them together. If given a PV, The factory function attempts to determine the appropriate motor class from the given base PV; if this fails then it will attempt to create an EpicsMotor. Axes are given the same name as they are assigned in the provided dictionary. See examples below. Parameters ---------- mdict : dictionary Dictionary of motor objects and or base PVs. name : str Name for the stack. Used to make a class name. No whitespace. Examples -------- # Make a classic XYZ stack with two PVs and one motor object d = {'x': 'TST:MMS:01', 'y': 'TST:MMS:02', 'z': z_motor} xyz = StageStack(d, 'my_xyz') """ cpts = {} for mname, mitem in mdict.items(): # Check if this is a PV or motor object if issubclass(type(mitem), Device): # Motor object cpts[mname] = mitem elif isinstance(mitem, (str)): # PV mcls = _GetMotorClass(mitem) cpt = mcls(prefix=mitem, name=mname) cpts[mname] = cpt else: # Something is wrong logger.warning("Unrecognized input {}. " "Skipping axis {}.".format(mitem, mname)) cls_name = name + '_StageStack' cls = type(cls_name, (object,), cpts) dev = cls() return dev # Internal class def set_presets(self): """ Save four preset coordinate points. These are the coordinates from the four corners of the wanted/defined grid. The points for these coordinates shuld be taken from the middle of the four targets that are encasing the grid. The user will be asked to define the coordinates using the `tweak` method. Examples -------- # Press q when ready to save the coordinates >>> xy.set_presets() Setting coordinates for (0, 0) top left corner: 0.0000, : 0.0000, scale: 0.1 Setting coordinates for (0, M) top right corner: 10.0000, : 0.0000, scale: 0.1 Setting coordinates for (N, M) bottom right corner: 10.0000, : -10.0000, scale: 0.1 Setting coordinates for (N, 0) bottom left corner: -0.0000, : -10.0000, scale: 0.1 """ # check to see the the presets are setup if not hasattr(self.x.presets, 'add_hutch'): raise AttributeError('No folder setup for motor presets. ' 'Please add a location to save the positions ' 'to, using setup_preset_paths from ' 'pcdsdevices.interface to save the position.') print('\nSetting coordinates for (0, 0) top left corner: \n') self.tweak() pos = [self.x.position, self.y.position] print('\nSetting coordinates for (0, M) top right corner: \n') self.tweak() pos.extend([self.x.position, self.y.position]) print('\nSetting coordinates for (N, M) bottom right corner: \n') self.tweak() pos.extend([self.x.position, self.y.position]) print('\nSetting coordinates for (N, 0) bottom left corner: \n') self.tweak() pos.extend([self.x.position, self.y.position]) # create presets # corner (0, 0) self.x.presets.add_hutch(value=pos[0], name="x_top_left") self.y.presets.add_hutch(value=pos[1], name="y_top_left") # corner (0, M) self.x.presets.add_hutch(value=pos[2], name="x_top_right") self.y.presets.add_hutch(value=pos[3], name="y_top_right") # corner (M, N) self.x.presets.add_hutch(value=pos[4], name="x_bottom_right") self.y.presets.add_hutch(value=pos[5], name="y_bottom_right") # corner (N, 0) self.x.presets.add_hutch(value=pos[6], name="x_bottom_left") self.y.presets.add_hutch(value=pos[7], name="y_bottom_left") def get_presets(self): """ Get the saved presets if any. Examples -------- >>> xy.get_presets() ((0, 0), (9.99999999999998, 0), (9.99999999999998, -9.99999999999998), (-6.38378239159465e-16, -9.99999999999998)) Returns ------- coord : tuple Four coordinate positions. (top_left, top_right, bottom_right, bottom_left) """ try: top_left = (self.x.presets.positions.x_top_left.pos, self.y.presets.positions.y_top_left.pos) # corner (0, M) top_right = (self.x.presets.positions.x_top_right.pos, self.y.presets.positions.y_top_right.pos) # corner (M, N) bottom_right = (self.x.presets.positions.x_bottom_right.pos, self.y.presets.positions.y_bottom_right.pos) # corner (N, 0) bottom_left = (self.x.presets.positions.x_bottom_left.pos, self.y.presets.positions.y_bottom_left.pos) return top_left, top_right, bottom_right, bottom_left except Exception: logger.warning('Could not get presets, try to set_presets.') def get_samples(self, path=None): """ Get all the available sample grids names that are currently saved. Returns ------- samples : list List of strings of all the sample names available. """ samples = [] path = path or self._path with os.scandir(path) as entries: for entry in entries: if entry.is_file(): samples.append(entry.name.split('.yml')[0]) return samples def load(self, sample_name, path=None): """ Get the sample information and populate these parameters. This function displays the parameters for the sample just loaded, but also populates them, in the sense that it sets the current `coefficients` and current `m, n` values. Parameters ---------- sample_name : str Name of the sample to load. path : str, optional Path where the samples yaml file exists. """ path = path or self._path entry = os.path.join(path, sample_name + '.yml') m_points, n_points, coeffs = self.get_sample_map_info( str(sample_name), path=entry) self.m_n_points = m_points, n_points self.coefficients = coeffs # make this sample the current one self.current_sample = str(sample_name) def get_sample_data(self, sample_name, path=None): """ Get the information for a saved sample. Parameters ---------- sample_name : str The sample name that we want the grid for. To see current available samples call `mapped_grids` path : str, optional Path to the `.yml` file. Defaults to the path defined when creating this object. Returns ------- data : dictionary Dictionary of all the information for a saved sample, or empty dictionary if troubles getting the sample. Examples -------- >>> get_sample('sample1') {'time_created': '2021-01-06 11:43:40.701095', 'top_left': [0, 0], 'top_right': [4.0, -1.0], 'bottom_right': [4.4, -3.5], 'bottom_left': [1.0, -3.0], 'M': 10, 'N': 10, 'coefficients': [1.1686746987951824, -0.3855421686746996, -9.730859023513261e-15, -0.29216867469879476, 1.1566265060240974, 6.281563288265657e-16, 0.042168674698794054, -0.05220883534136586], xx: ... yy: ...} """ path = path or os.path.join(self._path, sample_name + '.yml') data = None with open(path) as sample_file: try: data = yaml.safe_load(sample_file) except yaml.YAMLError as err: logger.error('Error when loading the samples yaml file: %s', err) raise err if data is None: logger.warning('The file is empty, no sample grid yet. ' 'Please use `save_presets` to insert grids ' 'in the file.') return {} try: return data[str(sample_name)] except Exception: logger.error('The sample %s might not exist in the file.', sample_name) return {} def get_sample_map_info(self, sample_name, path=None): """ Given a sample name, get the m and n points, as well as the coeffs. Parameters ---------- sample_name : str The name of the sample to get the mapped points from. To see the available mapped samples call the `mapped_samples()` method. path : str, optional Path to the samples yaml file. """ path = path or os.path.join(self._path, sample_name + '.yml') sample = self.get_sample_data(str(sample_name), path=path) coeffs = [] m_points, n_points = 0, 0 if sample: try: coeffs = sample["coefficients"] m_points = sample['M'] n_points = sample['N'] except Exception as ex: logger.error('Something went wrong when getting the ' 'information for sample %s. %s', sample_name, ex) raise ex else: err_msg = ('This sample probably does not exist. Please call' ' mapped_samples() to see which ones are available.') logger.error(err_msg) raise Exception(err_msg) return m_points, n_points, coeffs def save_grid(self, sample_name, path=None): """ Save a grid file of mapped points for a sample. This will save the date it was created, along with the sample name, the m and n points, the coordinates for the four corners, and the coefficients that will help get the x and y position on the grid. If an existing name for a sample is saved again, it will override the information for that samplefile keeping the status of the targets. When overriding a sample, this is assuming that a re-calibration was needed for that sample, so in case we have already shot targets from that sample - we want to keep track of that. Parameters ---------- sample_name : str A name to identify the sample grid, should be snake_case style. path : str, optional Path to the sample folder where this sample will be saved. Defaults to the path defined when creating this object. Examples -------- >>> save_grid('sample_1') """ path = path or self._path entry = os.path.join(path, sample_name + '.yml') now = str(datetime.now()) top_left, top_right, bottom_right, bottom_left = [], [], [], [] if self.get_presets(): top_left, top_right, bottom_right, bottom_left = self.get_presets() xx, yy = self.positions_x, self.positions_y flat_xx, flat_yy = [], [] if xx and yy: flat_xx = [float(x) for x in xx] flat_yy = [float(y) for y in yy] # add False to each target to indicate they # have not been shot yet flat_xx = [{"pos": x, "status": False} for x in flat_xx] flat_yy = [{"pos": y, "status": False} for y in flat_yy] m_points, n_points = self.m_n_points coefficients = self.coefficients data = {sample_name: {"time_created": now, "top_left": list(top_left), "top_right": list(top_right), "bottom_right": list(bottom_right), "bottom_left": list(bottom_left), "M": m_points, # number of rows "N": n_points, # number of columns "coefficients": coefficients, "xx": flat_xx, "yy": flat_yy}} try: jsonschema.validate(data[sample_name], self.sample_schema) except jsonschema.exceptions.ValidationError as err: logger.warning('Invalid input: %s', err) raise err # entry = os.path.join(path, sample_name + '.yml') # if this is an existing file, overrite the info but keep the statuses if os.path.isfile(entry): with open(entry) as sample_file: yaml_dict = yaml.safe_load(sample_file) sample = yaml_dict[sample_name] # when overriding the same sample, this is assuming that a # re-calibration was done - so keep the previous statuses. temp_xx = sample['xx'] temp_yy = sample['yy'] temp_x_status = [i['status'] for i in temp_xx] temp_y_status = [i['status'] for i in temp_yy] # update the current data statuses with previous ones for xd, status in zip(data[sample_name]['xx'], temp_x_status): xd.update((k, status) for k, v in xd.items() if k == 'status') for yd, status in zip(data[sample_name]['yy'], temp_y_status): yd.update((k, status) for k, v in yd.items() if k == 'status') yaml_dict.update(data) with open(entry, 'w') as sample_file: yaml.safe_dump(data, sample_file, sort_keys=False, default_flow_style=False) else: # create a new file with open(entry, 'w') as sample_file: yaml.safe_dump(data, sample_file, sort_keys=False, default_flow_style=False) def reset_statuses(self, sample_name, path=None): """ Reset the statuses to `False` for the sample targets. Parameters ---------- sample_name : str A name to identify the sample grid, should be snake_case style. path : str, optional Path to the `.yml` file. Defaults to the path defined when creating this object. """ path = path or os.path.join(self._path, sample_name + '.yml') with open(path) as sample_file: yaml_dict = yaml.safe_load(sample_file) or {} sample = yaml_dict.get(sample_name) if sample: for xd in sample.get('xx'): xd.update((k, False) for k, v in xd.items() if k == 'status') for yd in sample.get('yy'): yd.update((k, False) for k, v in yd.items() if k == 'status') yaml_dict[sample_name].update(sample) else: raise ValueError('Could not find this sample name in the file:' f' {sample}') with open(path, 'w') as sample_file: yaml.safe_dump(yaml_dict, sample_file, sort_keys=False, default_flow_style=False) def map_points(self, snake_like=True, top_left=None, top_right=None, bottom_right=None, bottom_left=None, m_rows=None, n_columns=None): """ Map the points of a quadrilateral. Given the 4 corners coordinates of a grid, and the numbers of rows and columns, map all the sample positions in 2-d coordinates. Parameters ---------- snake_like : bool Indicates if the points should be saved in a snake_like pattern. top_left : tuple, optional (x, y) coordinates of the top left corner top_right : tuple, optional (x, y) coordinates of the top right corner bottom_right : tuple, optional (x, y) coordinates of the bottom right corner bottom_left : tuple, optional (x, y) coordinates of the bottom left corner m_rows : int, optional Number of rows the grid has. n_columns : int, optional Number of columns the grid has. Returns ------- xx, yy : tuple Tuple of two lists with all mapped points for x and y positions in the grid. """ top_left = top_left or self.get_presets()[0] top_right = top_right or self.get_presets()[1] bottom_right = bottom_right or self.get_presets()[2] bottom_left = bottom_left or self.get_presets()[3] if any(v is None for v in [top_left, top_right, bottom_right, bottom_left]): raise ValueError('Could not get presets, make sure you set presets' ' first using the `set_presets` method.') rows = m_rows or self.m_n_points[0] columns = n_columns or self.m_n_points[1] a_coeffs, b_coeffs = mesh_interpolation(top_left, top_right, bottom_right, bottom_left) self.coefficients = a_coeffs.tolist() + b_coeffs.tolist() x_points, y_points = [], [] xx, yy = get_unit_meshgrid(m_rows=rows, n_columns=columns) # return x_points, y_points for rowx, rowy in zip(xx, yy): for x, y in zip(rowx, rowy): i, j = convert_to_physical(a_coeffs=a_coeffs, b_coeffs=b_coeffs, logic_x=x, logic_y=y) x_points.append(i) y_points.append(j) if snake_like: x_points = snake_grid_list( np.array(x_points).reshape(rows, columns)) y_points = snake_grid_list( np.array(y_points).reshape(rows, columns)) self.positions_x = x_points self.positions_y = y_points return x_points, y_points def is_target_shot(self, m, n, sample=None, path=None): """ Check to see if the target position at MxN is shot. Parameters ---------- sample_name : str, optional The name of the sample to get the mapped points from. To see the available mapped samples call the `mapped_samples()` method. m_point : int Represents the row value of the point we want the position for. n_point : int Represents the column value of the point we want the position for. path : str, optional Sample path. Returns ------- is_shot : bool Indicates is target is shot or not. """ sample = sample or self.current_sample path = path or self.current_sample_path x, y = self.compute_mapped_point(m_row=m, n_column=n, sample_name=sample, path=path) data = self.get_sample_data(sample) xx = data.get('xx') x_status = None # one value should be enough # TODO: this is assuming that none of the points will be the unique. if xx is not None: x_status = next((item['status'] for item in xx if item['pos'] == x), None) return x_status def compute_mapped_point(self, m_row, n_column, sample_name=None, path=None, compute_all=False): """ For a given sample, compute the x, y position for M and N respecively. Parameters ---------- sample_name : str The name of the sample to get the mapped points from. To see the available mapped samples call the `mapped_samples()` method. m_point : int Represents the row value of the point we want the position for. n_point : int Represents the column value of the point we want the position for. compute_all : boolean, optional If `True` all the point positions will be computed for this sample. path : str, optional Path to the samples yaml file. Returns ------- x, y : tuple The x, y position for m n location. """ path = path or self._path sample_name = sample_name or self.current_sample if sample_name is None or sample_name == '': raise ValueError( 'Please make sure you provide a sample name or use load()') # if we have a current loaded sample, use the current M, N values and # current coefficients if self.current_sample != '': m_points, n_points = self.m_n_points coeffs = self.coefficients else: # try to get them from the sample_name file entry = os.path.join(path, sample_name + '.yml') m_points, n_points, coeffs = self.get_sample_map_info( str(sample_name), path=entry) if any(v is None for v in [m_points, n_points, coeffs]): raise ValueError('Some values are empty, please check the sample ' f'{sample_name} in the has the M and N values as ' 'well as coefficients saved') if (m_row > m_points) or (n_column > n_points): raise IndexError('Index out of range, make sure the m and n values' f' are between ({m_points, n_points})') if (m_row or n_column) == 0: raise IndexError('Please start at 1, 1, as the initial points.') xx_origin, yy_origin = get_unit_meshgrid(m_rows=m_points, n_columns=n_points) a_coeffs = coeffs[:4] b_coeffs = coeffs[4:] if not compute_all: logic_x = xx_origin[m_row - 1][n_column - 1] logic_y = yy_origin[m_row - 1][n_column - 1] x, y = convert_to_physical(a_coeffs, b_coeffs, logic_x, logic_y) return x, y else: # compute all points x_points, y_points = [], [] for rowx, rowy in zip(xx_origin, yy_origin): for x, y in zip(rowx, rowy): i, j = convert_to_physical(a_coeffs=a_coeffs, b_coeffs=b_coeffs, logic_x=x, logic_y=y) x_points.append(i) y_points.append(j) return x_points, y_points def move_to_sample(self, m, n): """ Move x,y motors to the computed positions of n, m of current sample. Given m (row) and n (column), compute the positions for x and y based on the current sample's parameters. See `current_sample` and move the x and y motor to those positions. Parameters ---------- m : int Indicates the row on the grid. n : int Indicates the column on the grid. """ sample_name = self.current_sample if sample_name: n, m = self.compute_mapped_point(m_row=m, n_column=n) self.x.mv(n) self.y.mv(m) def move_to(self, sample, m, n): """ Move x,y motors to the computed positions of n, m of given sample. Given m (row) and n (column), compute the positions for x and y based on the current sample's parameters. See `current_sample` Parameters ---------- m : int Indicates the row on the grid. n : int Indicates the column on the grid. """ entry = os.path.join(self._path, sample + '.yml') n, m = self.compute_mapped_point(m_row=m, n_column=n, sample_name=sample, path=entry) self.x.mv(n) self.y.mv(m) def set_status(self, m, n, status=False, sample_name=None, path=None): """ TODO not working properly yet Set the status for a specific m and n point. Parametrs: --------- m : int Indicates the row number starting at 1. n : int Indicates the column number starting at 1. status : bool, optional `False` to indicate that is has been shot, and `True` for available. """ assert isinstance(status, bool) sample_name = sample_name or self.current_sample path = path or os.path.join(self._path, sample_name + '.yml') m_points, n_points = self.m_n_points if (m > m_points) or (n > n_points): raise IndexError('Index out of range, make sure the m and n values' f' are between ({m_points, n_points})') if (m or n) == 0: raise IndexError('Please start at 1, 1, as the initial points.') with open(path) as sample_file: yaml_dict = yaml.safe_load(sample_file) or {} sample = yaml_dict.get(sample_name) if sample: xx = sample['xx'] yy = sample['yy'] n_pos = next(d['pos'] for (index, d) in enumerate(xx) if index == n - 1) m_pos = next(d['pos'] for (index, d) in enumerate(yy) if index == m - 1) for xd in sample.get('xx'): for k, v in xd.items(): if k == 'pos' and v == n_pos: xd.update((st, status) for st, vv in xd.items() if st == 'status') for yd in sample.get('yy'): for k, v in yd.items(): if k == 'pos' and v == m_pos: yd.update((st, status) for st, vv in xd.items() if st == 'status') yaml_dict[sample_name].update(sample) else: raise ValueError('Could not find this sample name in the file:' f' {sample}') with open(path, 'w') as sample_file: yaml.safe_dump(yaml_dict, sample_file, sort_keys=False, default_flow_style=False) def mesh_interpolation(top_left, top_right, bottom_right, bottom_left): """ Mapping functions for an arbitrary quadrilateral. Reference: https://www.particleincell.com/2012/quad-interpolation/ In order to perform the interpolation on an arbitrary quad, we need to obtain a mapping function. Our goal is to come up with a function such as (x, y) = f(l, m) where l = [0, 1] and m = [0, 1] describes the entire point space enclosed by the quadrilateral. In addition, we want f(0, 0) = (x1, y1), f(1, 0) = (x2, y2) and so on to correspond to the polygon vertices. This function forms a map that allows us to transform the quad from the physical coordinates set to a logical coordinate space. In the logical coordinates, the polygon morphs into a square, regardless of its physical form. Once the logical coordinates are obtained, we perform the scatter and find the physical x, y values. To find the map, we assume a bilinear mapping function given by: x = alpha_1 + alpha_2*l + alpha_3*m + alpha_4 * l _ m y = beta_1 + beta_2 * l + beta_3 * m + beta_4 * l * m Next we use these experessions to solve for the 4 coefficients: x1 1 0 0 0 alpha_1 x2 1 1 0 0 alpha_2 x3 1 1 1 1 alpha_3 x4 1 0 1 0 alpha_4 We do the same for the beta coefficients. Parameters ---------- top_left : tuple (x, y) coordinates of the top left corner top_right : tuple (x, y) coordinates of the top right corner bottom_right : tuple (x, y) coordinates of the bottom right corner bottom_left : tuple (x, y) coordinates of the bottom left corner Returns ------- a_coeffs, b_coeffs : tuple List of tuples with the alpha and beta coefficients for projective transformation. They are used to find x and y. """ # describes the entire point space enclosed by the quadrilateral unit_grid = np.array([[1, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 1], [1, 0, 1, 0]]) # x value coordinates for current grid (4 corners) px = np.array([top_left[0], top_right[0], bottom_right[0], bottom_left[0]]) # y value coordinates for current grid (4 corners) py = np.array([top_left[1], top_right[1], bottom_right[1], bottom_left[1]]) a_coeffs = np.linalg.solve(unit_grid, px) b_coeffs = np.linalg.solve(unit_grid, py) return a_coeffs, b_coeffs def get_unit_meshgrid(m_rows, n_columns): """ Based on the 4 coordinates and m and n points, find the meshgrid. Regardless of the physical form of our polygon, we first need to morph it into a unit square. Parameters ---------- m_rows : int Number of rows our grid has. n_columns : int Number of columns our grid has. """ px = [0, 1, 1, 0] py = [0, 0, 1, 1] x0 = min(px) lx = max(px) - min(px) y0 = min(py) ly = max(py) - min(py) ni = n_columns nj = m_rows dx = lx / (ni - 1) dy = ly / (nj - 1) xx = [x0 + (i - 1) * dx for i in range(1, ni + 1)] yy = [y0 + (j - 1) * dy for j in range(1, nj + 1)] return np.meshgrid(xx, yy) def convert_to_physical(a_coeffs, b_coeffs, logic_x, logic_y): """ Convert to physical coordinates from logical coordinates. Parameters ---------- a_coeffs : array Perspective transformation coefficients for alpha. b_coeffs : array Perspective transformation coefficients for beta. logic_x : float Logical point in the x direction. logic_y : float Logical point in the y direction. Returns ------- x, y : tuple The x and y physical values on the specified grid. """ # x = a(1) + a(2)*l + a(3)*m + a(4)*l*m x = (a_coeffs[0] + a_coeffs[1] * logic_x + a_coeffs[2] * logic_y + a_coeffs[3] * logic_x * logic_y) # y = b(1) + b(2)*l + b(3)*m + b(4)*l*m y = (b_coeffs[0] + b_coeffs[1] * logic_x + b_coeffs[2] * logic_y + b_coeffs[3] * logic_x * logic_y) return x, y def snake_grid_list(points): """ Flatten them into lists with snake_like pattern coordinate points. [[1, 2], [3, 4]] => [1, 2, 4, 3] Parameters ---------- points : array Array containing the grid points for an axis with shape MxN. Returns ------- flat_points : list List of all the grid points folowing a snake-like pattern. """ temp_points = [] for i in range(points.shape[0]): if i % 2 == 0: temp_points.append(points[i]) else: t = points[i] tt = t[::-1] temp_points.append(tt) flat_points = list(chain.from_iterable(temp_points)) # convert the numpy.float64 to normal float to be able to easily # save them in the yaml file flat_points = [float(v) for v in flat_points] return flat_points
[ 37811, 198, 26796, 329, 2219, 2496, 3800, 8931, 25412, 13, 198, 37811, 198, 11748, 18931, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 11748, 28686, 198, 198, 6738, 267, 746, 5173, 13, 25202, 1330, 1...
2.075303
15,670
#!/usr/bin/env python # # time # # Copyright Jelmer Vernooij 2010 <jelmer@samba.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import samba.getopt as options import common from samba.net import Net from samba.netcmd import ( Command, )
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 198, 2, 640, 198, 2, 198, 2, 15069, 449, 417, 647, 23092, 2238, 2926, 3050, 1279, 73, 417, 647, 31, 82, 31842, 13, 2398, 29, 198, 2, 198, 2, 770, 1430, 318, 1479, 3788, 26, ...
3.465021
243
import unittest import redis import socket import pytest from bokchoy.conductors.dummy import DummyConductor from bokchoy.results.redis import RedisResult from bokchoy.serializers.json import JSONSerializer from exam import fixture from .base import JobTests requires_redis = pytest.mark.skipif( not redis_is_available(), reason="requires redis search server running")
[ 11748, 555, 715, 395, 198, 11748, 2266, 271, 198, 11748, 17802, 198, 11748, 12972, 9288, 198, 198, 6738, 275, 482, 354, 726, 13, 36495, 669, 13, 67, 13513, 1330, 360, 13513, 25559, 33029, 198, 6738, 275, 482, 354, 726, 13, 43420, 13, ...
3.218487
119
# Copyright (c) 2020 # Author: xiaoweixiang """Contains purely network-related utilities. """
[ 2, 220, 15069, 357, 66, 8, 12131, 198, 2, 220, 6434, 25, 2124, 544, 47097, 844, 15483, 198, 198, 37811, 4264, 1299, 14177, 3127, 12, 5363, 20081, 13, 198, 37811, 198 ]
3.129032
31
DEFAULT_KUBE_VERSION=1.14 KUBE_VERSION="kubeVersion" USER_ID="userId" DEFAULT_USER_ID=1 CLUSTER_NAME="clusterName" CLUSTER_MASTER_IP="masterHostIP" CLUSTER_WORKER_IP_LIST="workerIPList" FRAMEWORK_TYPE= "frameworkType" FRAMEWORK_VERSION="frameworkVersion" FRAMEWORK_RESOURCES="frameworkResources" FRAMEWORK_VOLUME_SIZE= "storageVolumeSizegb" FRAMEWORK_ASSIGN_DPU_TYPE= "dpuType" FRAMEWORK_ASSIGN_DPU_COUNT= "count" FRAMEWORK_INSTANCE_COUNT="instanceCount" FRAMEWORK_SPEC="spec" FRAMEWORK_IMAGE_NAME="imageName" FRAMEWORK_DPU_ID="dpuId" FRAMEWORK_DPU_COUNT="count" CLUSTER_ID="clusterId" FRAMEWORK_DEFAULT_PVC="/home/user/" DEFAULT_FRAMEWORK_TYPE="POLYAXON" DEFAULT_FRAMEWORK_VERSION="0.4.4" POLYAXON_TEMPLATE="templates/polyaxon_config" POLYAXON_CONFIG_FILE="/home/user/polyaxonConfig.yaml" POLYAXON_DEFAULT_NAMESPACE="polyaxon" TENSORFLOW_TEMPLATE="templates/tensorflow-gpu" DEFAULT_PATH="/home/user/" ##########Cluster Info#################### POD_IP="podIp" POD_STATUS="podStatus" POD_HOST_IP="hostIp" ##########End Of Cluster Info#################### PVC_MAX_ITERATIONS=50 SLEEP_TIME=5 GLUSTER_DEFAULT_MOUNT_PATH="/volume" CONTAINER_VOLUME_PREFIX="volume" MAX_RETRY_FOR_CLUSTER_FORM=10 ##############Cluster Related ####################33 CLUSTER_NODE_READY_COUNT=60 CLUSTER_NODE_READY_SLEEP=6 CLUSTER_NODE_NAME_PREFIX="worker" NO_OF_GPUS_IN_GK210_K80=2 POLYAXON_NODE_PORT_RANGE_START=30000 POLYAXON_NODE_PORT_RANGE_END=32767 DEFAULT_CIDR="10.244.0.0/16" GFS_STORAGE_CLASS="glusterfs" GFS_STORAGE_REPLICATION="replicate:2" HEKETI_REST_URL="http://10.138.0.2:8080" DEFAULT_VOLUME_MOUNT_PATH="/volume" GLUSTER_DEFAULT_REP_FACTOR=2 POLYAXON_DEFAULT_HTTP_PORT=80 POLYAXON_DEFAULT_WS_PORT=1337 SUCCESS_MESSAGE_STATUS="SUCCESS" ERROR_MESSAGE_STATUS="SUCCESS" ROLE="role" IP_ADDRESS="ipAddress" INTERNAL_IP_ADDRESS="internalIpAddress" ADD_NODE_USER_ID="hostUserId" ADD_NODE_PASSWORD="password" ####Polyaxon GetClusterInfo### QUOTA_NAME="quotaName" QUOTA_USED="used" QUOTA_LIMIT="limit" DEFAULT_QUOTA="default" VOLUME_NAME="volumeName" MOUNT_PATH_IN_POD="volumePodMountPath" VOLUME_TOTAL_SIZE="totalSize" VOLUME_FREE="free" NVIDIA_GPU_RESOURCE_NAME="requests.nvidia.com/gpu" EXECUTOR="executor" MASTER_IP="masterIP" GPU_COUNT="gpuCount" NAME="name" KUBE_CLUSTER_INFO="kubeClusterInfo" ML_CLUSTER_INFO="mlClusterInfo" POLYAXON_DEFAULT_USER_ID="root" POLYAXON_DEFAULT_PASSWORD="rootpassword" POLYAXON_USER_ID="polyaxonUserId" POLYAXON_PASSWORD="polyaxonPassword" DEFAULT_DATASET_VOLUME_NAME="vol_f37253d9f0f35868f8e3a1d63e5b1915" DEFAULT_DATASET_MOUNT_PATH="/home/user/dataset" DEFAULT_CLUSTER_VOLUME_MOUNT_PATH="/home/user/volume" DEFAULT_GLUSTER_SERVER="10.138.0.2" DEFAULT_DATASET_VOLUME_SIZE="10Gi" CLUSTER_VOLUME_MOUNT_PATH="volumeHostMountPath" DATASET_VOLUME_MOUNT_POINT="dataSetVolumemountPointOnHost" DATASET_VOLUME_MOUNT_PATH_IN_POD_REST= "volumeDataSetPodMountPoint" DATASET_VOLUME_MOUNT_PATH_IN_POD="/dataset" DYNAMIC_GLUSTERFS_ENDPOINT_STARTS_WITH="glusterfs-dynamic-"
[ 7206, 38865, 62, 42, 10526, 36, 62, 43717, 28, 16, 13, 1415, 198, 42, 10526, 36, 62, 43717, 2625, 74, 3266, 14815, 1, 198, 198, 29904, 62, 2389, 2625, 7220, 7390, 1, 198, 7206, 38865, 62, 29904, 62, 2389, 28, 16, 198, 5097, 7759, ...
2.228487
1,348
# -*- coding: utf-8 -*- from django.conf.urls import url from django.views.generic.base import RedirectView from mpcontribs.portal import views app_name = "mpcontribs_portal" urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^healthcheck/?$", views.healthcheck, name="healthcheck"), url( r"^notebooks/(?P<nb>[A-Za-z0-9_\/]{3,}).html$", views.notebooks, name="notebooks", ), url(r"^(?P<cid>[a-f\d]{24})/?$", views.contribution, name="contribution"), # downloads url( r"^component/(?P<oid>[a-f\d]{24})$", views.download_component, name="download_component", ), url( r"^(?P<cid>[a-f\d]{24}).json.gz$", views.download_contribution, name="download_contribution", ), # TODO .(?P<fmt>[a-z]{3}) url( r"^(?P<project>[a-zA-Z0-9_]{3,}).json.gz$", views.download_project, name="download_project", ), # redirects url(r"^fe-co-v/?$", RedirectView.as_view(url="/swf/", permanent=False)), url(r"^fe-co-v/dataset-01/?$", RedirectView.as_view(url="/swf/", permanent=False)), url( r"^boltztrap/?$", RedirectView.as_view(url="/carrier_transport/", permanent=True), ), url( r"^Screeninginorganicpv/?$", RedirectView.as_view(url="/screening_inorganic_pv/", permanent=False), ), url( r"^ScreeningInorganicPV/?$", RedirectView.as_view(url="/screening_inorganic_pv/", permanent=False), ), # default view url(r"^[a-zA-Z0-9_]{3,}/?$", views.landingpage), ]
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 6738, 42625, 14208, 13, 10414, 13, 6371, 82, 1330, 19016, 198, 6738, 42625, 14208, 13, 33571, 13, 41357, 13, 8692, 1330, 2297, 1060, 7680, 198, 6738, 29034, 3642, 822, 8...
2.015287
785
from typing import List, Optional, Tuple from collections import defaultdict from mp_api.core.client import BaseRester, MPRestError import warnings
[ 6738, 19720, 1330, 7343, 11, 32233, 11, 309, 29291, 198, 6738, 17268, 1330, 4277, 11600, 198, 198, 6738, 29034, 62, 15042, 13, 7295, 13, 16366, 1330, 7308, 4965, 353, 11, 337, 4805, 395, 12331, 198, 198, 11748, 14601, 628 ]
3.871795
39
from wtforms import TextField, IntegerField, PasswordField from wtforms.ext.sqlalchemy.fields import ( QuerySelectField, QuerySelectMultipleField) from wtforms.validators import Required from pynuts.view import BaseForm import database from application import nuts
[ 6738, 266, 83, 23914, 1330, 8255, 15878, 11, 34142, 15878, 11, 30275, 15878, 198, 6738, 266, 83, 23914, 13, 2302, 13, 25410, 282, 26599, 13, 25747, 1330, 357, 198, 220, 220, 220, 43301, 17563, 15878, 11, 43301, 17563, 31217, 15878, 8, ...
3.777778
72
#!/usr/bin/env python3 import sys from Bio import SeqIO import os genome = sys.argv[1] in_aa = f'hits/{genome}.hits' in_up = f'fa/{genome}.upstream' hits = SeqIO.to_dict(SeqIO.parse(in_aa, 'fasta')) raes = SeqIO.to_dict(SeqIO.parse(in_up, 'fasta')) for k in hits.keys(): i = k.split('|')[1] print(raes[i].format('fasta'))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 11748, 25064, 198, 6738, 16024, 1330, 1001, 80, 9399, 198, 11748, 28686, 198, 198, 5235, 462, 796, 25064, 13, 853, 85, 58, 16, 60, 198, 198, 259, 62, 7252, 796, 277, 6, 71...
2.037037
162
"""AirTouch 4 component to control of AirTouch 4 Climate Devices.""" from __future__ import annotations import logging from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( FAN_AUTO, FAN_DIFFUSE, FAN_FOCUS, FAN_HIGH, FAN_LOW, FAN_MEDIUM, HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, HVAC_MODE_OFF, SUPPORT_FAN_MODE, SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE AT_TO_HA_STATE = { "Heat": HVAC_MODE_HEAT, "Cool": HVAC_MODE_COOL, "AutoHeat": HVAC_MODE_AUTO, # airtouch reports either autoheat or autocool "AutoCool": HVAC_MODE_AUTO, "Auto": HVAC_MODE_AUTO, "Dry": HVAC_MODE_DRY, "Fan": HVAC_MODE_FAN_ONLY, } HA_STATE_TO_AT = { HVAC_MODE_HEAT: "Heat", HVAC_MODE_COOL: "Cool", HVAC_MODE_AUTO: "Auto", HVAC_MODE_DRY: "Dry", HVAC_MODE_FAN_ONLY: "Fan", HVAC_MODE_OFF: "Off", } AT_TO_HA_FAN_SPEED = { "Quiet": FAN_DIFFUSE, "Low": FAN_LOW, "Medium": FAN_MEDIUM, "High": FAN_HIGH, "Powerful": FAN_FOCUS, "Auto": FAN_AUTO, "Turbo": "turbo", } AT_GROUP_MODES = [HVAC_MODE_OFF, HVAC_MODE_FAN_ONLY] HA_FAN_SPEED_TO_AT = {value: key for key, value in AT_TO_HA_FAN_SPEED.items()} _LOGGER = logging.getLogger(__name__)
[ 37811, 16170, 35211, 604, 7515, 284, 1630, 286, 3701, 35211, 604, 13963, 29362, 526, 15931, 198, 6738, 11593, 37443, 834, 1330, 37647, 198, 198, 11748, 18931, 198, 198, 6738, 1363, 562, 10167, 13, 5589, 3906, 13, 42570, 1330, 13963, 32398...
2.23
800
import json import requests
[ 11748, 33918, 198, 11748, 7007, 628 ]
4.833333
6
#MenuTitle: Delete Duplicate Components # -*- coding: utf-8 -*- from __future__ import division, print_function, unicode_literals __doc__=""" Looks for duplicate components (same component, same x/y values) and keeps only one of them. """ Font = Glyphs.font selectedLayers = Font.selectedLayers Font.disableUpdateInterface() for thisLayer in selectedLayers: print "Components deleted in %s:" % thisLayer.parent.name, process( thisLayer ) Font.enableUpdateInterface()
[ 2, 23381, 19160, 25, 23520, 49821, 5344, 36109, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 6738, 11593, 37443, 834, 1330, 7297, 11, 3601, 62, 8818, 11, 28000, 1098, 62, 17201, 874, 198, 834, 15390, 834, 2625...
3.352113
142
""" Error classes, when needed for exceptions. """ from _ast import AST from dataclasses import dataclass, field from typing import Optional, Union from src.compiler.Util import Util
[ 37811, 198, 12331, 6097, 11, 618, 2622, 329, 13269, 13, 198, 37811, 198, 6738, 4808, 459, 1330, 29273, 198, 6738, 4818, 330, 28958, 1330, 4818, 330, 31172, 11, 2214, 198, 6738, 19720, 1330, 32233, 11, 4479, 198, 198, 6738, 12351, 13, ...
3.584906
53
# -*- coding: utf-8 -*- import argparse from github.accounts.github_account import GithubAccount from github.domain.github import GithubUser from github.recorders.github.common import get_result from zvdata.api import get_entities from zvdata.domain import get_db_session from zvdata.recorder import TimeSeriesDataRecorder from zvdata.utils.time_utils import day_offset_today, now_pd_timestamp if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--start', help='start_timestamp', default='2015-01-01') parser.add_argument('--end', help='end_timestamp', default='2015-12-31') args = parser.parse_args() start = args.start end = args.end recorder = GithubUserInfoRecorder(start_timestamp=start, end_timestamp=end) recorder.run()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 1822, 29572, 198, 198, 6738, 33084, 13, 23317, 82, 13, 12567, 62, 23317, 1330, 38994, 30116, 198, 6738, 33084, 13, 27830, 13, 12567, 1330, 38994, 12982, 198, 6738, ...
3.007547
265
from pyTooling.Decorators import export __version__ = "0.1.0"
[ 198, 6738, 12972, 25391, 278, 13, 10707, 273, 2024, 1330, 10784, 198, 198, 834, 9641, 834, 796, 366, 15, 13, 16, 13, 15, 1, 628 ]
2.6
25
# Importing needed libraries import uuid from decouple import config from dotenv import load_dotenv from flask import Flask, render_template, request, jsonify from sklearn.externals import joblib import traceback import pandas as pd import numpy as np from flask_sqlalchemy import SQLAlchemy # Saving DB var DB = SQLAlchemy() # Reads key value pair from .env load_dotenv() # Running function to create the app def create_app(): ''' Used to initiate the app ''' # saving flask(__name__) to var app app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = config('DATABASE_URL') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False DB.init_app(app) if __name__ == '__main__': try: port = int(sys.argv[1]) # This is for a command-line input except: port = 12345 # If you don't provide any port the port will be set to 12345 lr = joblib.load("model.pkl") # Load "model.pkl" print ('Model loaded') model_columns = joblib.load("model_columns.pkl") # Load "model_columns.pkl" print ('Model columns loaded') app.run(port=port, debug=True)
[ 2, 17267, 278, 2622, 12782, 198, 11748, 334, 27112, 198, 6738, 875, 43846, 1330, 4566, 198, 6738, 16605, 24330, 1330, 3440, 62, 26518, 24330, 198, 6738, 42903, 1330, 46947, 11, 8543, 62, 28243, 11, 2581, 11, 33918, 1958, 198, 6738, 1341...
2.581292
449
import pandas as pd import os from sklearn.svm import SVC from sklearn.preprocessing import StandardScaler from sklearn.metrics import classification_report, confusion_matrix from sklearn.model_selection import train_test_split import pickle BASE_PATH = os.path.join(os.getcwd() , "dataset") df = None i = 0 for file_name in os.listdir(BASE_PATH): file_path = os.path.join(BASE_PATH , file_name) print(file_path) data_frame = pd.read_csv(file_path , header=None) data_frame.pop(178) data_frame.pop(0) dat = pd.DataFrame({'result': [i for k in range(data_frame.shape[1])]}) data_frame = data_frame.join(dat) if not df is None : df = df.append(data_frame , ignore_index=True) else: df = data_frame i += 1 scaler = StandardScaler() y = df.pop("result") scalled_data = scaler.fit_transform(df) X_train, X_test, y_train, y_test = train_test_split(scalled_data , y, test_size = 0.20) svclassifier = SVC(kernel='linear') svclassifier.fit(X_train, y_train) y_pred = svclassifier.predict(X_test) print(confusion_matrix(y_test,y_pred)) print(classification_report(y_test,y_pred)) pickle.dump(svclassifier , open("classifier.pkl" , 'wb')) pickle.dump(scaler , open("scaler.pkl" , 'wb'))
[ 11748, 19798, 292, 355, 279, 67, 198, 11748, 28686, 198, 6738, 1341, 35720, 13, 82, 14761, 1330, 311, 15922, 198, 6738, 1341, 35720, 13, 3866, 36948, 1330, 8997, 3351, 36213, 198, 6738, 1341, 35720, 13, 4164, 10466, 1330, 17923, 62, 131...
2.493952
496
# -*- coding: utf-8 -*- """ Created on Mon Aug 14 20:21:23 2017 @author: DKIM """ import pandas as pd import numpy as np # required libraries loaded import pandas as pd import numpy as np import matplotlib matplotlib.style.use('ggplot') import matplotlib.pyplot as plt seednumber = 319 data = pd.read_csv('Data.csv') # Initial dataset print('Initial dataset dimensions') print(data.shape) target_year = 2017 print('Filter to only the training data') orig_data = data[data['season'] <= target_year] # Data Preprocessing # replace any null values with 0 data = data.fillna(0) # use one-hot coding to replace the favorite and underdog categorical variables fav_team = pd.get_dummies(data['favorite']) und_team = pd.get_dummies(data['underdog']) # use a prefix to distinguish the two categorical variables fav_team = fav_team.add_prefix('fav_') und_team = und_team.add_prefix('und_') # remove the original fields data = data.drop('favorite', axis = 1) data = data.drop('underdog', axis = 1) # add the one-hot coded fields data = pd.concat([data, fav_team], axis = 1) data = pd.concat([data, und_team], axis = 1) #print data.head(5) #print(data.describe()) # split the dataset into training and testing datasets data = data[data['season'] <= target_year] data.reset_index() print('Final dataset dimensions') print(data.shape) #statistics = data.describe() #statistics.to_csv('stats.csv') print('Review the distribution of the target variable') print('Target variable is evenly distributed and is not skewed') spread_by_year = data.groupby(['season'])['spreadflag'].mean() print(spread_by_year) corr_data = data.corr(method = 'pearson') print('Review the correlation between the variables and the target variable') print('Top 10 correlated variables') print(corr_data['spreadflag'].sort_values(ascending=False).head(11)) print('Top 10 negatively correlated variables') print(corr_data['spreadflag'].sort_values(ascending=True).head(10)) years = [2010,2011,2012,2013,2014,2015,2016,2017] for x in years: year_data = data[data['season'] == x] year_data_corr = year_data.corr(method = 'pearson') print('Top 10 correlated variables for the target variable, spreadflag, for the year ' + str(x)) print(year_data_corr['spreadflag'].sort_values(ascending=False).head(11)) print('') print('Top 10 negatively correlated variables for the target variable, spreadflag, for the year ' + str(x)) print(year_data_corr['spreadflag'].sort_values(ascending=True).head(10)) print('') # Plot favorite win % over spread spread_agg = data.groupby(['spread'])['spreadflag'].mean() spread_count = data.groupby(['spread'])['spreadflag'].count() / data.shape[0] fig, axes = plt.subplots(2,1) spread_agg_ax = spread_agg.plot(ax = axes[0]) spread_agg_ax.set_ylabel('favorite win %') spread_agg_ax.set_title('Figure 1 - Spread') spread_agg_figure = spread_agg_ax.get_figure() spread_count_ax = spread_count.plot(kind = 'line',ax = axes[1]) spread_count_ax.set_ylabel('spread %') spread_count_figure = spread_count_ax.get_figure() plt.show() #plt.savefig('2b - fig 1 - spread_vis.png') # Plot the favorite win % over total total_agg = data.groupby(['total'])['spreadflag'].mean() total_count = data.groupby(['total'])['spreadflag'].count() / data.shape[0] fig, axes = plt.subplots(2,1) total_agg_ax = total_agg.plot(ax = axes[0]) total_agg_ax.set_ylabel('favorite win %') total_agg_ax.set_title('Figure 2 - Total') total_agg_figure = total_agg_ax.get_figure() total_count_ax = total_count.plot(kind = 'line',ax = axes[1]) total_count_ax.set_ylabel('total %') total_count_figure = total_count_ax.get_figure() plt.show() #plt.savefig('2b - fig 2 - total_vis.png') # Check the Team over winning % favorite_win_percent = orig_data.groupby(['favorite'])['spreadflag'].mean() underdog_win_percent = 1 - orig_data.groupby(['underdog'])['spreadflag'].mean() print('Top 10 Favorites by ATS percent') print(favorite_win_percent.sort_values(ascending=False).head(10)) print('') print('Top 10 Underdogs by ATS percent') print(underdog_win_percent.sort_values(ascending=False).head(10)) print('') # Plot the favorite win % over favorite's win record over last 5 and 10 games fav_last_5_percent_vis_agg = data.groupby(['fav_last_5_percent'])['spreadflag'].mean() fav_last_10_percent_vis_agg = data.groupby(['fav_last_10_percent'])['spreadflag'].mean() fig, axes = plt.subplots(2,1) fav_last_5_percent_vis_agg_ax = fav_last_5_percent_vis_agg.plot(ax = axes[0]) fav_last_5_percent_vis_agg_ax.set_ylabel('favorite win %') fav_last_5_percent_vis_agg_ax.set_title('Figure 3a - Favorite Win % Last 5 Games') fav_last_5_percent_vis_agg_figure = fav_last_5_percent_vis_agg_ax.get_figure() fav_last_5_percent_vis_agg_figure.subplots_adjust(hspace=0.75) fav_last_10_percent_vis_agg_ax = fav_last_10_percent_vis_agg.plot(kind = 'line',ax = axes[1]) fav_last_10_percent_vis_agg_ax.set_ylabel('favorite win %') fav_last_10_percent_vis_agg_ax.set_title('Figure 3b - Favorite Win % Last 10 Games') fav_last_10_percent_vis_count_figure = fav_last_10_percent_vis_agg_ax.get_figure() plt.show() #plt.savefig('2b - fig 3 - fav_last_5_percent.png') # Plot the favorite win % over underdog's win record over last 5 and 10 games undlast_5_percent_vis_agg = data.groupby(['und_last_5_percent'])['spreadflag'].mean()#.sum()/ data.groupby(['spread'])['spreadflag'].count() und_last_10_percent_vis_agg = data.groupby(['und_last_10_percent'])['spreadflag'].mean() fig, axes = plt.subplots(2,1) und_last_5_percent_vis_agg_ax = undlast_5_percent_vis_agg.plot(ax = axes[0]) und_last_5_percent_vis_agg_ax.set_ylabel('underdog win %') und_last_5_percent_vis_agg_ax.set_title('Figure 4a - Underdog Win % Last 5 Games') und_last_5_percent_vis_agg_figure = und_last_5_percent_vis_agg_ax.get_figure() und_last_5_percent_vis_agg_figure.subplots_adjust(hspace=0.75) und_last_10_percent_vis_agg_ax = und_last_10_percent_vis_agg.plot(kind = 'line',ax = axes[1]) und_last_10_percent_vis_agg_ax.set_ylabel('underdog win %') und_last_10_percent_vis_agg_ax.set_title('Figure 4b - Underdog Win % Last 10 Games') und_last_10_percent_vis_agg_figure = und_last_10_percent_vis_agg_ax.get_figure() plt.show() #plt.savefig('2b - fig 4 - und_last_5_percent.png')
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 2892, 2447, 1478, 1160, 25, 2481, 25, 1954, 2177, 198, 198, 31, 9800, 25, 32975, 3955, 198, 37811, 198, 198, 11748, 19798, 292, 355, 279, 67, 1...
2.699698
2,321
#!/usr/bin/env python """Testplan that is expected to time out.""" import sys import threading import testplan from testplan.testing import multitest if __name__ == '__main__': sys.exit(main().exit_code)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 37811, 14402, 11578, 326, 318, 2938, 284, 640, 503, 526, 15931, 198, 11748, 25064, 198, 11748, 4704, 278, 198, 198, 11748, 1332, 11578, 198, 6738, 1332, 11578, 13, 33407, 1330, 41785, 39...
3.101449
69
# Python3
[ 2, 11361, 18, 198 ]
2.5
4
# ! /usr/bin/python # -*- coding: utf-8 -*- # import funkc z jinho adrese # import sys import os.path path_to_script = os.path.dirname(os.path.abspath(__file__)) # sys.path.append(os.path.join(path_to_script, "../extern/pyseg_base/src/")) # sys.path.append(os.path.join(path_to_script, "../extern/sed3/")) # sys.path.append(os.path.join(path_to_script, "../src/")) import unittest import numpy as np import lisa.classification if __name__ == "__main__": unittest.main()
[ 2, 5145, 1220, 14629, 14, 8800, 14, 29412, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 1330, 46212, 66, 1976, 474, 20327, 512, 260, 325, 198, 2, 1330, 25064, 198, 11748, 28686, 13, 6978, 198, 198, 6978, ...
2.395
200
from flask import Flask # import pyodbc app = Flask(__name__)
[ 6738, 42903, 1330, 46947, 198, 2, 1330, 12972, 375, 15630, 220, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 198 ]
3
21
from sweeps.sweepFunctions import * import numpy as np
[ 6738, 46778, 13, 46280, 538, 24629, 2733, 1330, 1635, 198, 11748, 299, 32152, 355, 45941, 198 ]
3.4375
16
from __future__ import unicode_literals import pytest # noqa import sys pytestmark = pytest.mark.skipif(sys.version_info[0] < 3, reason="pyecore is not Python 2 compatible") # noqa pyecore = pytest.importorskip("pyecore") # noqa import textx from textx.metamodel import metamodel_from_str pytestmark = pytest.mark.usefixtures("enable_pyecore_support") def test_issue_34_resolving(): """An issue in resolving a list of objects of different types. In the grammar below, attribute `values` in `FormulaExp` collect STRING instances which leads textX to deduce the type of this attribute to be list of STRING objects. Thus, object reference resolving does not consider the `values` list. In the new version textX will deduce type OBJECT if different types are used in multiple assignments. """ grammar = """ Expression: atts+=Attribute[','] 'formula' form=Formula ; Formula: value=FormulaExp ; FormulaExp: values=Cond | ( values='(' values=Formula values=')' ) ; Cond: attribute = [Attribute|attr_id] '<' values=STRING ; attr_id: /attr_[a-f0-9]+/ ; Attribute: name = attr_id ; """ meta_model = metamodel_from_str(grammar) model = meta_model.model_from_str( "attr_123, attr_444 formula attr_123 < 'aa'") assert type(model.form.value.values[0].attribute).__name__ == 'Attribute' assert model.form.value.values[0].attribute.name == 'attr_123'
[ 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, 11748, 12972, 9288, 220, 1303, 645, 20402, 198, 11748, 25064, 198, 9078, 9288, 4102, 796, 12972, 9288, 13, 4102, 13, 48267, 361, 7, 17597, 13, 9641, 62, 10951, 58, 15, 6...
2.521104
616
# -*- coding: utf-8 -*- import boto3 from botocore.exceptions import ClientError import attr from attrs_mate import AttrsClass import weakref
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 11748, 275, 2069, 18, 198, 6738, 10214, 420, 382, 13, 1069, 11755, 1330, 20985, 12331, 198, 11748, 708, 81, 198, 6738, 708, 3808, 62, 9830, 1330, 3460, 3808, 9487, ...
2.9
50
from android.runnable import run_on_ui_thread from jnius import autoclass, cast mActivity = autoclass("org.kivy.android.PythonActivity").mActivity Toast = autoclass("android.widget.Toast") CharSequence = autoclass("java.lang.CharSequence") String = autoclass("java.lang.String")
[ 198, 6738, 19286, 13, 5143, 77, 540, 1330, 1057, 62, 261, 62, 9019, 62, 16663, 198, 6738, 474, 77, 3754, 1330, 1960, 420, 31172, 11, 3350, 198, 198, 76, 16516, 796, 1960, 420, 31172, 7203, 2398, 13, 74, 452, 88, 13, 19411, 13, 379...
3
94