hexsha stringlengths 40 40 | size int64 10 1.01M | ext stringclasses 8 values | lang stringclasses 1 value | max_stars_repo_path stringlengths 4 237 | max_stars_repo_name stringlengths 5 113 | max_stars_repo_head_hexsha stringlengths 40 41 | max_stars_repo_licenses list | max_stars_count int64 1 95.2k ⌀ | max_stars_repo_stars_event_min_datetime stringlengths 24 24 ⌀ | max_stars_repo_stars_event_max_datetime stringlengths 24 24 ⌀ | max_issues_repo_path stringlengths 4 237 | max_issues_repo_name stringlengths 5 113 | max_issues_repo_head_hexsha stringlengths 40 41 | max_issues_repo_licenses list | max_issues_count int64 1 67k ⌀ | max_issues_repo_issues_event_min_datetime stringlengths 24 24 ⌀ | max_issues_repo_issues_event_max_datetime stringlengths 24 24 ⌀ | max_forks_repo_path stringlengths 4 237 | max_forks_repo_name stringlengths 5 113 | max_forks_repo_head_hexsha stringlengths 40 41 | max_forks_repo_licenses list | max_forks_count int64 1 33.1k ⌀ | max_forks_repo_forks_event_min_datetime stringlengths 24 24 ⌀ | max_forks_repo_forks_event_max_datetime stringlengths 24 24 ⌀ | content stringlengths 10 1.01M | avg_line_length float64 2.26 46k | max_line_length int64 3 990k | alphanum_fraction float64 0.1 1 | label int64 0 2 | cost float64 0 5.77 | embedding list |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8a23e2e394242f4eca447da628bb8ac3e7fe2807 | 6,323 | py | Python | tools/aerial_detection.py | gfjiangly/AerialDetection | ee8a945c67c8e9ddef725900ac300d2d5a785e08 | [
"Apache-2.0"
] | null | null | null | tools/aerial_detection.py | gfjiangly/AerialDetection | ee8a945c67c8e9ddef725900ac300d2d5a785e08 | [
"Apache-2.0"
] | 1 | 2021-08-28T15:48:14.000Z | 2021-08-28T15:48:14.000Z | tools/aerial_detection.py | gfjiangly/AerialDetection | ee8a945c67c8e9ddef725900ac300d2d5a785e08 | [
"Apache-2.0"
] | null | null | null | # -*- encoding:utf-8 -*-
# @Time : 2021/1/3 15:15
# @Author : gfjiang
import os.path as osp
import mmcv
import numpy as np
import cvtools
import matplotlib.pyplot as plt
import cv2.cv2 as cv
from functools import partial
import torch
import math
from cvtools.utils.path import add_prefix_filename_suffix
from mmdet.ops import nms
from mmdet.apis import init_detector, inference_detector
def draw_features(module, input, output, work_dir='./'):
x = output.cpu().numpy()
out_channels = list(output.shape)[1]
height = int(math.sqrt(out_channels))
width = height
if list(output.shape)[2] < 128:
return
fig = plt.figure(figsize=(32, 32))
fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95, wspace=0.05, hspace=0.05)
for i in range(height * width):
plt.subplot(height, width, i + 1)
plt.axis('off')
img = x[0, i, :, :]
pmin = np.min(img)
pmax = np.max(img)
img = ((img - pmin) / (pmax - pmin + 0.000001))*255 # float在[0,1]之间,转换成0-255
img = img.astype(np.uint8) # 转成unit8
img = cv.applyColorMap(img, cv.COLORMAP_JET) # 生成heat map
img = img[:, :, ::-1] # 注意cv2(BGR)和matplotlib(RGB)通道是相反的
plt.imshow(img)
# print("{}/{}".format(i,width*height))
savename = get_image_name_for_hook(module, work_dir)
fig.savefig(savename, dpi=100)
fig.clf()
plt.close()
def get_image_name_for_hook(module, work_dir='./'):
"""
Generate image filename for hook function
Parameters:
-----------
module: module of neural network
"""
# os.makedirs(work_dir, exist_ok=True)
module_name = str(module)
base_name = module_name.split('(')[0]
index = 0
image_name = '.' # '.' is surely exist, to make first loop condition True
while osp.exists(image_name):
index += 1
image_name = osp.join(
work_dir, 'feats', '%s_%d.png' % (base_name, index))
return image_name
class AerialDetectionOBB(object):
def __init__(self, config, pth):
self.imgs = []
self.cfg = mmcv.Config.fromfile(config)
self.pth = pth
print('loading model {} ...'.format(pth))
self.model = init_detector(self.cfg, self.pth, device='cuda:0')
self.results = []
self.img_detected = []
# self.vis_feats((torch.nn.Conv2d, torch.nn.MaxPool2d))
def __call__(self,
imgs_or_path,
det_thrs=0.5,
vis=False,
vis_thr=0.5,
save_root=''):
if isinstance(imgs_or_path, str):
self.imgs += cvtools.get_files_list(imgs_or_path)
else:
self.imgs += imgs_or_path
prog_bar = mmcv.ProgressBar(len(self.imgs))
for _, img in enumerate(self.imgs):
self.detect(img, det_thrs=det_thrs, vis=vis,
vis_thr=vis_thr, save_root=save_root)
prog_bar.update()
def detect(self,
img,
det_thrs=0.5,
vis=False,
vis_thr=0.5,
save_root=''):
result = inference_detector(self.model, img)
# result = self.nms(result)
if isinstance(det_thrs, float):
det_thrs = [det_thrs] * len(result)
if vis:
to_file = osp.join(save_root, osp.basename(img))
to_file = add_prefix_filename_suffix(to_file, suffix='_obb')
self.vis(img, result, vis_thr=vis_thr, to_file=to_file)
result = [det[det[..., -1] > det_thr] for det, det_thr
in zip(result, det_thrs)]
if len(result) == 0:
print('detect: image {} has no object.'.format(img))
self.img_detected.append(img)
self.results.append(result)
return result
def nms(self, result, nms_th=0.3):
dets_num = [len(det_cls) for det_cls in result]
result = np.vstack(result)
_, ids = nms(result, nms_th)
total_num = 0
nms_result = []
for num in dets_num:
ids_cls = ids[np.where((total_num <= ids) & (ids < num))[0]]
nms_result.append(result[ids_cls])
total_num += num
return nms_result
def vis(self, img, bbox_result, vis_thr=0.5,
to_file='vis.jpg'):
bboxes = np.vstack(bbox_result)
labels = [
np.full(bbox.shape[0], i, dtype=np.int32)
for i, bbox in enumerate(bbox_result)
]
labels = np.concatenate(labels)
inds = np.where(bboxes[:, -1] > vis_thr)[0]
bboxes = bboxes[inds]
labels = labels[inds]
texts = [self.model.CLASSES[index]+'|'+str(round(bbox[-1], 2))
for index, bbox in zip(labels, bboxes)]
img = cvtools.draw_boxes_texts(
img, bboxes[:, :-1], box_format='polygon', line_width=2)
cvtools.imwrite(img, to_file)
def vis_feats(self, modules_for_plot):
h, w = self.cfg.data.train.img_scale
for name, module in self.model.named_modules():
if isinstance(module, modules_for_plot):
draw_features_func = partial(
draw_features, work_dir=self.cfg.work_dir)
module.register_forward_hook(draw_features_func)
def save_results(self, save):
str_results = ''
for i, img in enumerate(self.img_detected):
result = self.results[i]
img = osp.basename(img)
for cls_index, dets in enumerate(result):
cls = self.model.CLASSES[cls_index]
for box in dets:
bbox_str = ','.join(map(str, map(int, box[:4])))
str_results += ' '.join([img, cls, bbox_str]) + '\n'
with open(save, 'w') as f:
f.write(str_results)
if __name__ == '__main__':
config_file = 'configs/DOTA/faster_rcnn_RoITrans_r50_fpn_1x_dota_1gpus_mdanet2.py'
pth_file = 'work_dirs/faster_rcnn_RoITrans_r50_fpn_1x_dota_1gpus_mdanet2/epoch_12.pth'
detector = AerialDetectionOBB(config_file, pth_file)
detector('/media/data/DOTA/crop/P2701_2926_1597_3949_2620.png', vis=True,
save_root='work_dirs/attention_vis/')
detector.save_results('work_dirs/faster_rcnn_RoITrans_r50_fpn_1x_dota_1gpus_mdanet2/detect_result.txt')
| 36.33908 | 107 | 0.591966 | 0 | 0 | [
-0.017472390085458755,
0.04579763486981392,
0.02514750510454178,
0.03635174781084061,
-0.005926261655986309,
0.01118503324687481,
-0.034757982939481735,
-0.004132633097469807,
-0.013774197548627853,
0.00919195357710123,
-0.01915372908115387,
-0.013794319704174995,
0.0302580576390028,
-0.008928476832807064,
-0.03608906269073486,
-0.0022830627858638763,
0.12816594541072845,
0.004480906296521425,
-0.03582095727324486,
-0.0133689409121871,
0.0016002303455024958,
-0.00581635907292366,
-0.02465728297829628,
0.01562157366424799,
0.0052181268110871315,
0.012990817427635193,
0.047780055552721024,
-0.007468649186193943,
0.02343808114528656,
-0.003505063708871603,
0.011000322178006172,
-0.013328210450708866,
-0.024417074397206306,
0.061808668076992035,
0.006641402840614319,
-0.02081107534468174,
0.005264997482299805,
-0.01393542904406786,
0.0032961745746433735,
-0.00677249813452363,
0.023781629279255867,
-0.006924854591488838,
0.0024763005785644054,
-0.03064591810107231,
-0.01712084375321865,
-0.009928114712238312,
-0.0004330634546931833,
-0.0034338587429374456,
-0.020519709214568138,
0.00953016709536314,
0.003868397790938616,
0.024251829832792282,
0.02180563472211361,
-0.05429472029209137,
-0.014928244054317474,
-0.023595336824655533,
0.02065279148519039,
0.006299234926700592,
-0.024917319416999817,
0.006027079187333584,
-0.01158585213124752,
-0.034219324588775635,
0.0059157018549740314,
-0.021208064630627632,
0.028261233121156693,
-0.0006850226782262325,
-0.0262297336012125,
-0.01221510861068964,
-0.05901067703962326,
0.027158569544553757,
-0.026911847293376923,
-0.0040313443168997765,
0.012128778733313084,
0.04621770605444908,
0.0008440124220214784,
-0.005484552588313818,
-0.00295362900942564,
-0.010247650556266308,
-0.028785262256860733,
0.02312675304710865,
-0.0197535902261734,
0.028828982263803482,
0.031128747388720512,
0.013428224250674248,
-0.01703314483165741,
0.05583026260137558,
0.042091723531484604,
-0.006094982381910086,
0.02717115357518196,
0.018013615161180496,
-0.04804213345050812,
0.028461096808314323,
-0.004839382134377956,
-0.02002808079123497,
0.004413984715938568,
-0.03381267562508583,
0.016014382243156433,
0.01127139013260603,
-0.0013989988947287202,
0.034415729343891144,
0.0012350708711892366,
-0.06340669095516205,
0.0014175409451127052,
-0.025934983044862747,
0.0028387466445565224,
-0.00019663211423903704,
-0.051844462752342224,
0.009891359135508537,
0.019225412979722023,
-0.046502385288476944,
-0.054781168699264526,
0.010831018909811974,
0.03348211199045181,
-0.02427602745592594,
-0.017918191850185394,
0.0016705762827768922,
0.009919792413711548,
-0.010313824750483036,
0.009566446766257286,
0.07302693277597427,
0.0006961370236240327,
-0.033535316586494446,
0.019920676946640015,
-0.00831474456936121,
-0.024995941668748856,
0.047348834574222565,
0.021541107445955276,
-0.0061069573275744915,
-0.011949124746024609,
-0.003711994271725416,
0.004602508619427681,
0.02382180094718933,
-0.005013240966945887,
-0.003129576798528433,
-0.022899212315678596,
-0.01352095976471901,
0.01681634783744812,
0.03264344111084938,
-0.016545018181204796,
-0.001915625063702464,
0.0011772150173783302,
-0.04642719775438309,
0.002792002633213997,
0.0027824710123240948,
0.019924277439713478,
-0.06654645502567291,
-0.03475534915924072,
0.007607762701809406,
-0.017927542328834534,
-0.022649116814136505,
0.0064055356197059155,
0.010241663083434105,
-0.0293743759393692,
0.04223627597093582,
0.017351645976305008,
0.013178129680454731,
-0.013585393317043781,
-0.03474317491054535,
-0.025352371856570244,
-0.008674980141222477,
-0.014558951370418072,
0.010724258609116077,
-0.022831328213214874,
0.020205248147249222,
0.012443168088793755,
0.01591714657843113,
-0.022912073880434036,
0.021112574264407158,
-0.002083847764879465,
-0.00807616114616394,
0.02001321129500866,
-0.01124420203268528,
-0.011555825360119343,
0.009143328294157982,
-0.021042177453637123,
0.026303770020604134,
0.04128799960017204,
0.01293950341641903,
0.006563992705196142,
-0.025303103029727936,
0.009477902203798294,
-0.014801998622715473,
0.010232373140752316,
0.045532893389463425,
0.012308994308114052,
-0.020963087677955627,
-0.04297156631946564,
-0.018863728269934654,
0.013587829656898975,
-0.025731470435857773,
-0.031891319900751114,
0.04390851408243179,
-0.031168945133686066,
-0.027742542326450348,
0.007787779439240694,
0.01947564072906971,
-0.014571111649274826,
0.023298082873225212,
-0.038811929523944855,
0.024581240490078926,
0.015124435536563396,
-0.024670792743563652,
-0.01076432317495346,
-0.028579793870449066,
-0.009009069763123989,
-0.009518810547888279,
-0.7372397780418396,
0.018715428188443184,
-0.006953341420739889,
-0.01738491654396057,
0.0037121488712728024,
0.046158675104379654,
-0.03835686668753624,
0.003119643311947584,
-0.06730638444423676,
-0.027913402765989304,
0.0019669265020638704,
-0.009958207607269287,
-0.016932232305407524,
0.020990127697587013,
0.040955375880002975,
0.0014821771765127778,
0.04424113407731056,
-0.006790452171117067,
-0.02299521118402481,
0.008538078516721725,
0.015995068475604057,
-0.054922789335250854,
-0.03266259282827377,
0.017752397805452347,
0.017488883808255196,
0.01353614591062069,
-0.01181008480489254,
-0.021825658157467842,
0.006706440821290016,
-0.0380450040102005,
0.005962704308331013,
-0.010317952372133732,
0.012323887087404728,
-0.04151095822453499,
-0.003388847690075636,
-0.006320062093436718,
0.002321043983101845,
0.002195879351347685,
-0.04694180563092232,
-0.023325400426983833,
0.00044466997496783733,
-0.020535843446850777,
-0.0005350909195840359,
-0.042920295149087906,
-0.05375019833445549,
0.0030181300826370716,
0.003375621512532234,
-0.025844426825642586,
0.019947418943047523,
0.04083424434065819,
-0.014478613622486591,
0.01952171139419079,
0.03845426067709923,
-0.005472234915941954,
0.031643345952034,
-0.0032596371602267027,
-0.02218625880777836,
-0.030532117933034897,
-0.02781490609049797,
0.006846151780337095,
0.009327494539320469,
0.012310219928622246,
-0.006356523837894201,
0.021596692502498627,
-0.044165872037410736,
0.016795305535197258,
0.02773258462548256,
-0.04556722939014435,
-0.015441137365996838,
0.020135030150413513,
0.0028157217893749475,
0.0024774568155407906,
-0.026504885405302048,
0.12335166335105896,
-0.02771637588739395,
-0.018478190526366234,
-0.004099360667169094,
0.024646177887916565,
0.026792215183377266,
-0.01817978546023369,
0.0022002803161740303,
-0.007594630587846041,
-0.0017803363734856248,
0.02058733068406582,
-0.06169814616441727,
0.007778273895382881,
0.006844049785286188,
0.006352304946631193,
0.006256606429815292,
0.02183089777827263,
-0.00023373146541416645,
0.044893622398376465,
0.005015712231397629,
-0.01709102652966976,
0.010463656857609749,
0.004528517369180918,
0.01062699407339096,
0.06056922674179077,
0.0028809136711061,
0.004508763551712036,
-0.0311660785228014,
0.016852963715791702,
0.005118789616972208,
-0.01813514530658722,
0.0051935529336333275,
0.0007964605465531349,
-0.018038693815469742,
0.0020299896132200956,
0.033182691782712936,
-0.058368779718875885,
-0.023450255393981934,
-0.011710884980857372,
-0.03532935678958893,
0.02715945616364479,
-0.024565991014242172,
-0.013487077318131924,
0.012396035715937614,
-0.04732409119606018,
-0.0007135113701224327,
-0.03334096074104309,
0.000660308578517288,
0.03839012235403061,
-0.009083221666514874,
0.0022946172393858433,
-0.0033373539336025715,
-0.01875988394021988,
-0.04055405780673027,
-0.005737823899835348,
0.017284099012613297,
0.02431025542318821,
-0.012377948500216007,
0.01755014806985855,
-0.024983836337924004,
0.011418777517974377,
-0.0115911103785038,
-0.010060682892799377,
0.011622918769717216,
-0.018666552379727364,
0.001168390386737883,
0.010796582326292992,
-0.0009306810097768903,
-0.029059017077088356,
-0.0011146378237754107,
-0.028022658079862595,
0.014684510417282581,
-0.020368030294775963,
-0.0034869180526584387,
0.005688543897122145,
0.03401010110974312,
0.022601235657930374,
-0.0020842610392719507,
0.05210825428366661,
0.0014308078680187464,
0.03248024359345436,
-0.0174607764929533,
0.004539528861641884,
-0.02370159700512886,
0.004415930714458227,
0.04125737398862839,
-0.004638648591935635,
0.015754682943224907,
-0.028773192316293716,
-0.02007182501256466,
0.03560490906238556,
0.008487291634082794,
-0.010725878179073334,
-0.0185902900993824,
0.06459940969944,
-0.0020805075764656067,
0.05996252968907356,
0.006919985171407461,
-0.021330242976546288,
-0.0022012912668287754,
0.004084596876055002,
-0.02403949201107025,
0.004873837810009718,
0.001075775595381856,
-0.0010187478037551045,
0.0037376314867287874,
0.004923794884234667,
-0.004990387707948685,
-0.005890120752155781,
-0.01831265352666378,
-0.027313746511936188,
0.01582997664809227,
-0.01314055547118187,
-0.03024095483124256,
0.015339845791459084,
0.01546106580644846,
-0.013533641584217548,
0.036560431122779846,
-0.011416326276957989,
-0.01531316339969635,
0.01227527391165495,
-0.007333132438361645,
0.0014088413445279002,
0.010886390693485737,
0.0059665497392416,
0.004561310168355703,
-0.014749279245734215,
-0.018613576889038086,
0.004762872122228146,
-0.007834509015083313,
-0.02903500758111477,
0.0022401486057788134,
0.03896138817071915,
0.013003220781683922,
-0.01818256638944149,
-0.0033113316167145967,
-0.009131682105362415,
-0.0006960990722291172,
-0.03577804937958717,
0.009837677702307701,
-0.005282154772430658,
-0.029373973608016968,
0.018692687153816223,
-0.041290830820798874,
-0.03273840993642807,
-0.003942579496651888,
-0.050592295825481415,
-0.01592540554702282,
-0.015917925164103508,
0.03981829434633255,
0.01462743990123272,
-0.02748061902821064,
-0.009268229827284813,
-0.03846883401274681,
0.017422690987586975,
-0.01578063890337944,
-0.007075136061757803,
0.0022782066371291876,
0.033180560916662216,
-0.0022421900648623705,
-0.01411872636526823,
-0.0006092262337915599,
0.013404362834990025,
-0.04630326107144356,
-0.02047756314277649,
-0.029790308326482773,
0.003845763858407736,
0.02848917990922928,
-0.03533249720931053,
-0.028505025431513786,
0.042183224111795425,
0.02919471636414528,
0.02973116561770439,
0.015057651326060295,
-0.010537529364228249,
-0.04915941134095192,
0.02542189508676529,
-0.006378009915351868,
0.039993517100811005,
0.008586358278989792,
0.010947049595415592,
0.004846303723752499,
-0.0058769830502569675,
-0.006191774737089872,
-0.005379237700253725,
0.0029042079113423824,
0.005255952011793852,
-0.005234048701822758,
-0.01166182104498148,
-0.01195003092288971,
0.007098671514540911,
0.037890300154685974,
-0.012229866348206997,
0.01583670638501644,
0.02621723897755146,
0.006572581361979246,
0.007093523629009724,
0.007406618911772966,
-0.053658291697502136,
-0.003032640554010868,
0.00028213701443746686,
0.004829352721571922,
-0.007359760347753763,
0.02913622185587883,
-0.02233656868338585,
0.0009278536890633404,
0.036484792828559875,
-0.0023043197579681873,
0.012582228519022465,
0.03447273373603821,
0.020432664081454277,
-0.00054114282829687,
0.028215108439326286,
0.045074161142110825,
-0.017234642058610916,
-0.026848748326301575,
0.012958988547325134,
-0.0008250814280472696,
-0.035050809383392334,
-0.010035174898803234,
0.043486401438713074,
-0.013383794575929642,
0.03044542483985424,
-0.014964022673666477,
0.032693613320589066,
0.05524075776338577,
0.022425131872296333,
0.023754559457302094,
-0.0012973729753866792,
0.02108602039515972,
-0.006418555974960327,
-0.010987920686602592,
-0.02324092946946621,
0.040305305272340775,
0.007455955259501934,
0.028472494333982468,
0.009578663855791092,
0.0186696145683527,
0.020626641809940338,
0.016297420486807823,
-0.029039621353149414,
0.021178174763917923,
-0.006172120571136475,
0.06542898714542389,
-0.01422801986336708,
0.017690587788820267,
-0.005213157273828983,
0.011716018430888653,
0.017356671392917633,
0.011080910451710224,
0.00940010417252779,
-0.007047699298709631,
0.004513992462307215,
-0.005408172495663166,
-0.016189999878406525,
0.010340866632759571,
0.004842014517635107,
-0.03027195669710636,
-0.0067308335565030575,
0.009040032513439655,
-0.009149035438895226,
-0.005225272383540869,
-0.013501661829650402,
0.013746208511292934,
0.03239952027797699,
0.022098490968346596,
0.00648179417476058,
0.022382313385605812,
0.016725823283195496,
-0.021589932963252068,
-0.01313125528395176,
0.024441324174404144,
0.024601753801107407,
0.022458797320723534,
0.05407941713929176,
0.019158529117703438,
0.020707180723547935,
0.023641198873519897,
-0.014605702832341194,
0.0018701462540775537,
0.03711964562535286,
-0.003788026049733162,
-0.008128587156534195,
0.0007092661689966917,
0.029431426897644997,
-0.0015420395648106933,
-0.011746950447559357,
-0.00549470167607069,
0.01717374473810196,
-0.00995252188295126,
-0.008340083993971348,
0.027756376191973686,
-0.017559869214892387,
0.05224781855940819,
-0.004362096544355154,
-0.02924983948469162,
-0.006557735614478588,
-0.021953605115413666,
0.00038447583210654557,
-0.006828161422163248,
0.013295660726726055,
0.0036161926109343767,
0.03501845523715019,
0.03286134824156761,
0.034518882632255554,
-0.017412932589650154,
-0.01584201119840145,
-0.014221545308828354,
0.011298244819045067,
0.037172045558691025,
-0.04964935779571533,
0.04006992280483246,
-0.028265194967389107,
0.03629303351044655,
0.000054966265452094376,
-0.020163580775260925,
-0.013693142682313919,
-0.0035333987325429916,
0.012785608880221844,
0.03451906517148018,
0.017797106876969337,
-0.007961832918226719,
0.012216765433549881,
-0.046158358454704285,
-0.022949371486902237,
0.020040705800056458,
0.018557153642177582,
-0.010877343825995922,
0.014015047810971737,
-0.00972500629723072,
-0.018743226304650307,
-0.027739329263567924,
-0.008258364163339138,
0.04110795259475708,
-0.013949948363006115,
0.0005873015616089106,
-0.025516806170344353,
0.016122860834002495,
0.03719073906540871,
-0.018315263092517853,
-0.029851436614990234,
0.005704957526177168,
-0.013654991053044796,
-0.046666067093610764,
0.014695289544761181,
-0.005261234473437071,
-0.02468918450176716,
-0.04047524929046631,
-0.022807985544204712,
0.0052947537042200565,
0.003148511052131653,
0.011409441940486431,
-0.0004565901181194931,
0.006160651333630085,
0.005158587358891964,
0.00017981590644922107,
0.05050111562013626,
-0.015133647248148918,
-0.005211365409195423,
-0.029728060588240623,
0.021799683570861816,
0.00341043365187943,
-0.022221682593226433,
-0.008283167146146297,
-0.0122103625908494,
-0.013250666670501232,
0.010219334624707699,
0.01807825267314911,
-0.007738849148154259,
0.011091497726738453,
0.006025393959134817,
0.003783075837418437,
-0.034376706928014755,
0.02774304337799549,
-0.017802605405449867,
0.020994925871491432,
0.02850392647087574,
0.03556908294558525,
-0.0024817148223519325,
-0.007653164677321911,
0.011299841105937958,
-0.003451667260378599,
-0.017315559089183807,
0.021704290062189102,
0.03801113739609718,
0.0009830007329583168,
0.010061643086373806,
0.006262408569455147,
-0.002658241195604205,
-0.014061084017157555,
0.04010371118783951,
-0.0018336789216846228,
0.0275679100304842,
0.02386472560465336,
-0.031498540192842484,
0.00343488622456789,
-0.027947740629315376,
0.015832217410206795,
-0.0013825034257024527,
-0.010255762375891209,
-0.01149330846965313,
0.003560112090781331,
0.010274720378220081,
-0.008875695988535881,
0.019229266792535782,
0.005036312621086836,
0.010577280074357986,
-0.04286019504070282,
0.008537843823432922,
0.015571676194667816,
0.0192835945636034,
-0.0013860352337360382,
-0.005912996828556061,
0.005324685946106911,
0.04262004792690277,
0.01225721463561058,
0.01592189632356167,
-0.029750047251582146,
-0.01954234018921852,
-0.01176474429666996,
0.03507959842681885,
-0.0021552653051912785,
-0.027123918756842613,
0.03225809335708618,
-0.002171962521970272,
0.04077344760298729,
-0.0055554648861289024,
-0.015021927654743195,
-0.023554693907499313,
0.006297960877418518,
-0.05794288590550423,
0.02493046224117279,
0.00956854410469532,
0.07707051932811737,
0.003543928498402238,
-0.016453789547085762,
-0.03011627309024334,
-0.017109407112002373,
-0.010525261983275414,
-0.035368263721466064,
0.016621273010969162,
0.00733184115961194,
0.02544637769460678,
0.004835187923163176,
-0.029626091942191124,
0.022035522386431694,
0.009477630257606506,
0.0006657622870989144,
0.0077162194065749645,
-0.04471805319190025,
-0.043804820626974106,
-0.015649808570742607,
0.004458718933165073,
-0.04241862893104553,
-0.013218170031905174,
-0.01680699735879898,
0.010425061918795109,
-0.0365794338285923,
-0.020107831805944443,
-0.016001654788851738,
0.015829548239707947,
0.04105280712246895,
-0.017750076949596405,
-0.007866881787776947,
0.06152127683162689,
-0.028627676889300346,
-0.04053746163845062,
0.02578595094382763,
0.008570183999836445,
-0.008527818135917187,
-0.0179857537150383,
-0.02404620498418808,
-0.03976398706436157,
-0.0004122157988604158,
0.014889254234731197,
0.02627585269510746,
0.03979601338505745,
-0.024081362411379814,
0.004973947536200285,
-0.013673894107341766,
-0.022336728870868683,
-0.011335092596709728,
-0.02944011427462101,
-0.005707339849323034,
-0.0019769116770476103,
0.009721723385155201,
-0.05209486186504364,
-0.006963090971112251,
0.006754907313734293
] |
8a248f7412b4e5841bfb0f9c54b8c6e82ae3813b | 19,715 | py | Python | tradingAPI/low_level.py | federico123579/Trading212-API | 0fab20b71a2348e72bbe76071b81f3692128851f | [
"MIT"
] | 44 | 2017-10-23T19:17:20.000Z | 2021-09-06T17:01:49.000Z | tradingAPI/low_level.py | federico123579/Trading212-API | 0fab20b71a2348e72bbe76071b81f3692128851f | [
"MIT"
] | 7 | 2017-09-05T09:51:16.000Z | 2020-05-17T11:23:27.000Z | tradingAPI/low_level.py | federico123579/Trading212-API | 0fab20b71a2348e72bbe76071b81f3692128851f | [
"MIT"
] | 18 | 2017-11-18T11:55:58.000Z | 2021-04-11T14:23:12.000Z | # -*- coding: utf-8 -*-
"""
tradingAPI.low_level
~~~~~~~~~~~~~~
This module provides the low level functions with the service.
"""
import time
import re
from datetime import datetime
from pyvirtualdisplay import Display
from bs4 import BeautifulSoup
from splinter import Browser
from .glob import Glob
from .links import path
from .utils import num, expect, get_pip
# exceptions
from tradingAPI import exceptions
import selenium.common.exceptions
# logging
import logging
logger = logging.getLogger('tradingAPI.low_level')
class Stock(object):
"""base class for stocks"""
def __init__(self, product):
self.product = product
self.market = True
self.records = []
def new_rec(self, rec):
"""add a record"""
self.records.append(rec)
return self.records
class Movement(object):
"""class-storing movement"""
def __init__(self, product, quantity, mode, price):
self.product = product
self.quantity = quantity
self.mode = mode
self.price = price
class PurePosition(object):
"""class-storing position"""
def __init__(self, product, quantity, mode, price):
self.product = product
self.quantity = quantity
self.mode = mode
self.price = price
def __repr__(self):
return ' - '.join([str(self.product), str(self.quantity),
str(self.mode), str(self.price)])
class LowLevelAPI(object):
"""low level api to interface with the service"""
def __init__(self, brow="firefox"):
self.brow_name = brow
self.positions = []
self.movements = []
self.stocks = []
# init globals
Glob()
def launch(self):
"""launch browser and virtual display, first of all to be launched"""
try:
# init virtual Display
self.vbro = Display()
self.vbro.start()
logger.debug("virtual display launched")
except Exception:
raise exceptions.VBroException()
try:
self.browser = Browser(self.brow_name)
logger.debug(f"browser {self.brow_name} launched")
except Exception:
raise exceptions.BrowserException(
self.brow_name, "failed to launch")
return True
def css(self, css_path, dom=None):
"""css find function abbreviation"""
if dom is None:
dom = self.browser
return expect(dom.find_by_css, args=[css_path])
def css1(self, css_path, dom=None):
"""return the first value of self.css"""
if dom is None:
dom = self.browser
def _css1(path, domm):
"""virtual local func"""
return self.css(path, domm)[0]
return expect(_css1, args=[css_path, dom])
def search_name(self, name, dom=None):
"""name find function abbreviation"""
if dom is None:
dom = self.browser
return expect(dom.find_by_name, args=[name])
def xpath(self, xpath, dom=None):
"""xpath find function abbreviation"""
if dom is None:
dom = self.browser
return expect(dom.find_by_xpath, args=[xpath])
def elCss(self, css_path, dom=None):
"""check if element is present by css"""
if dom is None:
dom = self.browser
return expect(dom.is_element_present_by_css, args=[css_path])
def elXpath(self, xpath, dom=None):
"""check if element is present by css"""
if dom is None:
dom = self.browser
return expect(dom.is_element_present_by_xpath, args=[xpath])
def login(self, username, password, mode="demo"):
"""login function"""
url = "https://trading212.com/it/login"
try:
logger.debug(f"visiting %s" % url)
self.browser.visit(url)
logger.debug(f"connected to %s" % url)
except selenium.common.exceptions.WebDriverException:
logger.critical("connection timed out")
raise
try:
self.search_name("login[username]").fill(username)
self.search_name("login[password]").fill(password)
self.css1(path['log']).click()
# define a timeout for logging in
timeout = time.time() + 30
while not self.elCss(path['logo']):
if time.time() > timeout:
logger.critical("login failed")
raise CredentialsException(username)
time.sleep(1)
logger.info(f"logged in as {username}")
# check if it's a weekend
if mode == "demo" and datetime.now().isoweekday() in range(5, 8):
timeout = time.time() + 10
while not self.elCss(path['alert-box']):
if time.time() > timeout:
logger.warning("weekend trading alert-box not closed")
break
if self.elCss(path['alert-box']):
self.css1(path['alert-box']).click()
logger.debug("weekend trading alert-box closed")
except Exception as e:
logger.critical("login failed")
raise exceptions.BaseExc(e)
return True
def logout(self):
"""logout func (quit browser)"""
try:
self.browser.quit()
except Exception:
raise exceptions.BrowserException(self.brow_name, "not started")
return False
self.vbro.stop()
logger.info("logged out")
return True
def get_bottom_info(self, info):
accepted_values = {
'free_funds': 'equity-free',
'account_value': 'equity-total',
'live_result': 'equity-ppl',
'used_margin': 'equity-margin'}
try:
info_label = accepted_values[info]
val = self.css1("div#%s span.equity-item-value" % info_label).text
return num(val)
except KeyError as e:
raise exceptions.BaseExc(e)
def get_price(self, name):
soup = BeautifulSoup(
self.css1("div.scrollable-area-content").html, "html.parser")
for product in soup.select("div.tradebox"):
fullname = product.select("span.instrument-name")[0].text.lower()
if name.lower() in fullname:
mark_closed_list = [x for x in product.select(
"div.quantity-list-input-wrapper") if x.select(
"div.placeholder")[0].text.lower().find("close") != -1]
if mark_closed_list:
sell_price = product.select("div.tradebox-price-sell")[0]\
.text
return float(sell_price)
else:
return False
class MovementWindow(object):
"""add movement window"""
def __init__(self, api, product):
self.api = api
self.product = product
self.state = 'initialized'
self.insfu = False
def open(self, name_counter=None):
"""open the window"""
if self.api.css1(path['add-mov']).visible:
self.api.css1(path['add-mov']).click()
else:
self.api.css1('span.dataTable-no-data-action').click()
logger.debug("opened window")
self.api.css1(path['search-box']).fill(self.product)
if self.get_result(0) is None:
self.api.css1(path['close']).click()
raise exceptions.ProductNotFound(self.product)
result, product = self.search_res(self.product, name_counter)
result.click()
if self.api.elCss("div.widget_message"):
self.decode(self.api.css1("div.widget_message"))
self.product = product
self.state = 'open'
def _check_open(self):
if self.state == 'open':
return True
else:
raise exceptions.WindowException()
def close(self):
"""close a movement"""
self._check_open()
self.api.css1(path['close']).click()
self.state = 'closed'
logger.debug("closed window")
def confirm(self):
"""confirm the movement"""
self._check_open()
self.get_price()
self.api.css1(path['confirm-btn']).click()
widg = self.api.css("div.widget_message")
if widg:
self.decode(widg[0])
raise exceptions.WidgetException(widg)
if all(x for x in ['quantity', 'mode'] if hasattr(self, x)):
self.api.movements.append(Movement(
self.product, self.quantity, self.mode, self.price))
logger.debug("%s movement appended to the list" % self.product)
self.state = 'conclused'
logger.debug("confirmed movement")
def search_res(self, res, check_counter=None):
"""search for a res"""
logger.debug("searching result")
result = self.get_result(0)
name = self.get_research_name(result)
x = 0
while not self.check_name(res, name, counter=check_counter):
name = self.get_research_name(self.get_result(x))
if name is None:
self.api.css1(path['close']).click()
raise exceptions.ProductNotFound(res)
logger.debug(name)
if self.check_name(res, name, counter=check_counter):
return self.get_result(x)
x += 1
logger.debug("found product at position %d" % (x + 1))
return result, name
def check_name(self, name, string, counter=None):
"""if both in string return False"""
name = name.lower()
string = string.lower()
if counter is None:
if name in string:
return True
else:
return False
counter = counter.lower()
if name in string and counter in string:
logger.debug("check_name: counter found in string")
return False
elif name in string and counter not in string:
return True
else:
return False
def get_research_name(self, res):
"""return result name"""
if res is None:
return None
return self.api.css1("span.instrument-name", res).text
def get_result(self, pos):
"""get pos result, where 0 is first"""
evalxpath = path['res'] + f"[{pos + 1}]"
try:
res = self.api.xpath(evalxpath)[0]
return res
except Exception:
return None
def set_limit(self, category, mode, value):
"""set limit in movement window"""
self._check_open()
if (mode not in ["unit", "value"] or category
not in ["gain", "loss", "both"]):
raise ValueError()
if not hasattr(self, 'stop_limit'):
self.stop_limit = {'gain': {}, 'loss': {}}
logger.debug("initialized stop_limit")
if category == 'gain':
self.api.xpath(
path['limit-gain-%s' % mode])[0].fill(str(value))
elif category == 'loss':
self.api.xpath(
path['limit-loss-%s' % mode])[0].fill(str(value))
if category != 'both':
self.stop_limit[category]['mode'] = mode
self.stop_limit[category]['value'] = value
elif category == 'both':
self.api.xpath(
path['limit-gain-%s' % mode])[0].fill(str(value))
self.api.xpath(
path['limit-loss-%s' % mode])[0].fill(str(value))
for cat in ['gain', 'loss']:
self.stop_limit[cat]['mode'] = mode
self.stop_limit[cat]['value'] = value
logger.debug("set limit")
def decode(self, message):
"""decode text pop-up"""
title = self.api.css1("div.title", message).text
text = self.api.css1("div.text", message).text
if title == "Insufficient Funds":
self.insfu = True
elif title == "Maximum Quantity Limit":
raise exceptions.MaxQuantLimit(num(text))
elif title == "Minimum Quantity Limit":
raise exceptions.MinQuantLimit(num(text))
logger.debug("decoded message")
def decode_update(self, message, value, mult=0.1):
"""decode and update the value"""
try:
msg_text = self.api.css1("div.text", message).text
return num(msg_text)
except Exception:
if msg_text.lower().find("higher") != -1:
value += value * mult
return value
else:
self.decode(message)
return None
def get_mov_margin(self):
"""get the margin of the movement"""
self._check_open()
return num(self.api.css1("span.cfd-order-info-item-value").text)
def set_mode(self, mode):
"""set mode (buy or sell)"""
self._check_open()
if mode not in ["buy", "sell"]:
raise ValueError()
self.api.css1(path[mode + '-btn']).click()
self.mode = mode
logger.debug("mode set")
def get_quantity(self):
"""gte current quantity"""
self._check_open()
quant = int(num(self.api.css1(path['quantity']).value))
self.quantity = quant
return quant
def set_quantity(self, quant):
"""set quantity"""
self._check_open()
self.api.css1(path['quantity']).fill(str(int(quant)))
self.quantity = quant
logger.debug("quantity set")
def get_price(self, mode='buy'):
"""get current price"""
if mode not in ['buy', 'sell']:
raise ValueError()
self._check_open()
price = num(self.api.css1(
"div.orderdialog div.tradebox-price-%s" % mode).text)
self.price = price
return price
def get_unit_value(self):
"""get unit value of stock based on margin, memoized"""
# find in the collection
try:
unit_value = Glob().theCollector.collection['unit_value']
unit_value_res = unit_value[self.product]
logger.debug("unit_value found in the collection")
return unit_value_res
except KeyError:
logger.debug("unit_value not found in the collection")
pip = get_pip(mov=self)
quant = 1 / pip
if hasattr(self, 'quantity'):
old_quant == self.quantity
self.set_quantity(quant)
# update the site
time.sleep(0.5)
margin = self.get_mov_margin()
logger.debug(f"quant: {quant} - pip: {pip} - margin: {margin}")
if 'old_quant' in locals():
self.set_quantity(old_quant)
unit_val = margin / quant
self.unit_value = unit_val
Glob().unit_valueHandler.add_val({self.product: unit_val})
return unit_val
def new_mov(self, name):
"""factory method pattern"""
return self.MovementWindow(self, name)
class Position(PurePosition):
"""position object"""
def __init__(self, api, html_div):
"""initialized from div"""
self.api = api
if isinstance(html_div, type('')):
self.soup_data = BeautifulSoup(html_div, 'html.parser')
else:
self.soup_data = html_div
self.product = self.soup_data.select("td.name")[0].text
self.quantity = num(self.soup_data.select("td.quantity")[0].text)
if ("direction-label-buy" in
self.soup_data.select("td.direction")[0].span['class']):
self.mode = 'buy'
else:
self.mode = 'sell'
self.price = num(self.soup_data.select("td.averagePrice")[0].text)
self.margin = num(self.soup_data.select("td.margin")[0].text)
self.id = self.find_id()
def update(self, soup):
"""update the soup"""
self.soup_data = soup
return soup
def find_id(self):
"""find pos ID with with given data"""
pos_id = self.soup_data['id']
self.id = pos_id
return pos_id
@property
def close_tag(self):
"""obtain close tag"""
return f"#{self.id} div.close-icon"
def close(self):
"""close position via tag"""
self.api.css1(self.close_tag).click()
try:
self.api.xpath(path['ok_but'])[0].click()
except selenium.common.exceptions.ElementNotInteractableException:
if (self.api.css1('.widget_message div.title').text ==
'Market Closed'):
logger.error("market closed, position can't be closed")
raise exceptions.MarketClosed()
raise exceptions.WidgetException(
self.api.css1('.widget_message div.text').text)
# wait until it's been closed
# set a timeout
timeout = time.time() + 10
while self.api.elCss(self.close_tag):
time.sleep(0.1)
if time.time() > timeout:
raise TimeoutError("failed to close pos %s" % self.id)
logger.debug("closed pos %s" % self.id)
def get_gain(self):
"""get current profit"""
gain = num(self.soup_data.select("td.ppl")[0].text)
self.gain = gain
return gain
def bind_mov(self):
"""bind the corresponding movement"""
logger = logging.getLogger("tradingAPI.low_level.bind_mov")
mov_list = [x for x in self.api.movements
if x.product == self.product and
x.quantity == self.quantity and
x.mode == self.mode]
if not mov_list:
logger.debug("fail: mov not found")
return None
else:
logger.debug("success: found movement")
for x in mov_list:
# find approximate price
max_roof = self.price + self.price * 0.01
min_roof = self.price - self.price * 0.01
if min_roof < x.price < max_roof:
logger.debug("success: price corresponding")
# bind mov
self.mov = x
return x
else:
logger.debug("fail: price %f not corresponding to %f" %
(self.price, x.price))
continue
# if nothing, return None
return None
def new_pos(self, html_div):
"""factory method pattern"""
pos = self.Position(self, html_div)
pos.bind_mov()
self.positions.append(pos)
return pos
| 37.058271 | 79 | 0.526401 | 1 | 1.9371 | [
-0.04403216391801834,
0.033958982676267624,
0.03588360920548439,
-0.0068239010870456696,
-0.0123117845505476,
-0.0024192803539335728,
-0.02549063041806221,
-0.010205814614892006,
-0.01639142818748951,
-0.0034437738358974457,
-0.003396413754671812,
-0.005665982142090797,
-0.002476758323609829,
-0.005052241496741772,
-0.009049118496477604,
-0.0077611906453967094,
0.04399476200342178,
-0.02487456612288952,
-0.021303415298461914,
0.015274319797754288,
0.01873650774359703,
-0.009968147613108158,
-0.008173196576535702,
0.011404823511838913,
0.004567028023302555,
0.036373887211084366,
0.06092017889022827,
0.016820287331938744,
0.033150944858789444,
-0.008699559606611729,
0.008001560345292091,
-0.019123293459415436,
-0.014780535362660885,
-0.034801777452230453,
-0.007811670657247305,
-0.01750251092016697,
0.019687645137310028,
0.03246006742119789,
0.023850075900554657,
0.014533094130456448,
-0.01095584686845541,
-0.053010329604148865,
-0.041249215602874756,
-0.020992513746023178,
0.030189502984285355,
0.03790612146258354,
-0.0167440976947546,
-0.029343988746404648,
0.0027944869361817837,
0.02099096029996872,
0.0044839754700660706,
0.026869310066103935,
-0.02270364575088024,
-0.009212612174451351,
0.003499711863696575,
-0.022595219314098358,
0.03607575222849846,
0.002439056523144245,
-0.06439019739627838,
-0.001840942190028727,
-0.017818370833992958,
-0.0012147933011874557,
-0.016605516895651817,
0.010180888697504997,
-0.02631709724664688,
-0.013788405805826187,
0.01055754255503416,
0.009733186103403568,
-0.014659455977380276,
0.03544791042804718,
-0.0030842525884509087,
-0.04137587174773216,
0.025928309187293053,
0.009407774545252323,
0.0036243745125830173,
-0.017614910379052162,
-0.012735462747514248,
-0.03429090231657028,
-0.009648796170949936,
0.01133677177131176,
-0.00983500573784113,
0.05885758623480797,
0.001131263910792768,
-0.01392847578972578,
-0.022216683253645897,
0.01854030415415764,
0.0042724148370325565,
-0.030976425856351852,
0.019290270283818245,
0.009086084552109241,
-0.03271223604679108,
-0.0037085791118443012,
0.02839859575033188,
0.026688560843467712,
-0.03259100764989853,
0.00011862130486406386,
0.022900469601154327,
-0.020242393016815186,
0.029696818441152573,
0.012432546354830265,
0.018637387081980705,
0.016139637678861618,
-0.008018859662115574,
-0.026768336072564125,
-0.01570710353553295,
0.023863976821303368,
-0.031906694173812866,
-0.03438855707645416,
0.0164827611297369,
-0.04153384640812874,
0.008273977786302567,
0.0402383916079998,
-0.0010764416074380279,
0.002332719974219799,
-0.015242142602801323,
-0.009249569848179817,
0.005424387287348509,
-0.02026314288377762,
0.0057782442308962345,
-0.052002497017383575,
0.006694659125059843,
0.0017762314528226852,
0.014291114173829556,
-0.020099733024835587,
-0.017109621316194534,
0.042629778385162354,
-0.039912644773721695,
0.05788567662239075,
0.004269174765795469,
-0.0036587012000381947,
-0.01087011769413948,
-0.0016373314429074526,
0.004535256884992123,
-0.013453059829771519,
0.03848031535744667,
0.012984721921384335,
-0.010911732912063599,
0.01851844973862171,
-0.009780066087841988,
0.00021761978860013187,
-0.03737576678395271,
-0.011773080565035343,
0.0056954738683998585,
0.003935354761779308,
-0.023795029148459435,
-0.023381229490041733,
-0.0019377315184101462,
-0.00906174723058939,
-0.020779013633728027,
-0.01536602433770895,
0.023030856624245644,
0.002182604745030403,
-0.026345737278461456,
0.055461812764406204,
-0.041119225323200226,
0.009163787588477135,
0.034927740693092346,
0.01482369378209114,
0.031927600502967834,
0.0052956813015043736,
-0.02320200763642788,
0.040692154318094254,
-0.021401040256023407,
0.014661233872175217,
-0.0047256615944206715,
0.004955313168466091,
-0.020859353244304657,
0.022967325523495674,
-0.01912619359791279,
0.05509233847260475,
0.0030255746096372604,
0.013270054012537003,
0.000030252938813646324,
0.00008130287460517138,
0.03212695196270943,
0.006266098003834486,
0.010312548838555813,
-0.0020030145533382893,
0.013148339465260506,
-0.05547315627336502,
-0.00033107699709944427,
-0.03855731338262558,
0.023177627474069595,
0.0368209108710289,
-0.028277220204472542,
-0.022704731673002243,
-0.002977369586005807,
0.03622542321681976,
-0.007589633110910654,
0.0017014439217746258,
0.005720687564462423,
0.021028321236371994,
0.028233475983142853,
0.006576169282197952,
0.03233780711889267,
-0.016703398898243904,
0.04952303692698479,
-0.03642294555902481,
0.024219723418354988,
0.015055152587592602,
-0.024096129462122917,
-0.019443748518824577,
-0.029956310987472534,
0.03645007684826851,
-0.005535578355193138,
-0.0045747291296720505,
-0.6977757811546326,
0.03341245651245117,
-0.0054242596961557865,
0.028446439653635025,
0.013467017561197281,
0.00277518923394382,
0.0009468959760852158,
0.0015645726816728711,
0.02149733528494835,
-0.04431053251028061,
0.0008955532102845609,
0.00627830671146512,
-0.06373392045497894,
0.017398806288838387,
0.018896590918302536,
-0.009473981335759163,
-0.0037364878226071596,
0.007000258658081293,
-0.014247546903789043,
-0.019030943512916565,
0.012335052713751793,
-0.046053797006607056,
-0.0071242693811655045,
0.018894042819738388,
0.0464649572968483,
0.012058554217219353,
-0.0068324897438287735,
0.032329656183719635,
-0.0029770354740321636,
-0.008195530623197556,
-0.0169615987688303,
-0.004919837694615126,
-0.021942561492323875,
0.0258017610758543,
0.019931193441152573,
0.05032043904066086,
0.03000200167298317,
-0.029084589332342148,
-0.006390691269189119,
-0.01631993055343628,
0.014421707019209862,
-0.020160013809800148,
-0.01437300257384777,
-0.04598364233970642,
-0.04096655175089836,
0.04409189149737358,
-0.019544532522559166,
0.052702538669109344,
0.0398566871881485,
0.030836030840873718,
-0.07616829872131348,
-0.009755928069353104,
0.040966689586639404,
-0.031247487291693687,
-0.025769120082259178,
0.0019633383490145206,
0.002137104282155633,
-0.015264736488461494,
0.00880187563598156,
-0.026856601238250732,
-0.03173787519335747,
0.010097279213368893,
-0.020441312342882156,
-0.03293057903647423,
0.0009905498009175062,
-0.005468236748129129,
-0.0025411059614270926,
-0.007600684650242329,
0.009030286222696304,
0.002549179596826434,
-0.07384771853685379,
-0.015519410371780396,
-0.062464311718940735,
0.028410568833351135,
0.013193044811487198,
0.036367110908031464,
-0.025879500433802605,
0.010140087455511093,
0.0912022814154625,
-0.034985531121492386,
-0.004828934092074633,
0.018401749432086945,
-0.018468940630555153,
0.01599285937845707,
-0.0005341179203242064,
0.0004617303784471005,
0.005317733623087406,
0.004306384362280369,
-0.035399675369262695,
-0.015036235563457012,
0.024759558960795403,
-0.004422117955982685,
0.015607105568051338,
-0.005077412351965904,
0.012776010669767857,
-0.01467552687972784,
0.002580781001597643,
0.05551113560795784,
-0.006920041050761938,
0.005302761681377888,
-0.016484742984175682,
0.0003370415361132473,
-0.015145237557590008,
-0.008478383533656597,
0.020091809332370758,
-0.028435036540031433,
-0.0707559660077095,
-0.017942512407898903,
0.06423254311084747,
-0.037811119109392166,
0.038375042378902435,
0.02100997045636177,
-0.0008715995354577899,
0.02260861173272133,
0.013023738749325275,
0.007329331245273352,
-0.0014181291917338967,
-0.007817975245416164,
0.019891640171408653,
-0.0017185099422931671,
-0.017004838213324547,
-0.003343045711517334,
-0.06531686335802078,
-0.04582769796252251,
-0.008358549326658249,
0.018956659361720085,
0.0054526724852621555,
-0.03585051745176315,
0.030073968693614006,
-0.02027101069688797,
0.014292214997112751,
0.02231704629957676,
0.007853000424802303,
0.035606831312179565,
-0.013003123924136162,
0.00910899043083191,
-0.006887114141136408,
-0.043304443359375,
0.05249661207199097,
-0.011776143684983253,
-0.00551309110596776,
-0.002981573576107621,
0.008990166708827019,
-0.03377983346581459,
0.030668506398797035,
-0.005680907052010298,
-0.023414598777890205,
0.003829499939456582,
-0.005341596435755491,
0.0027151673566550016,
-0.00860292837023735,
0.004429308231920004,
-0.03059815801680088,
-0.004088934976607561,
-0.030776962637901306,
-0.007152838632464409,
-0.012068451382219791,
0.01792740449309349,
0.01476022694259882,
0.025234801694750786,
-0.029045432806015015,
0.026127440854907036,
0.011001142673194408,
-0.03518475964665413,
0.02717999368906021,
-0.0026676126290112734,
-0.012319984845817089,
0.02151610143482685,
-0.017172561958432198,
0.008063170127570629,
0.022931162267923355,
-0.021594857797026634,
-0.010873876512050629,
-0.010024342685937881,
-0.01238715648651123,
0.0560881644487381,
-0.04441643878817558,
0.012992899864912033,
-0.017529498785734177,
-0.010701341554522514,
0.030948400497436523,
0.01050772424787283,
-0.02550286240875721,
0.00540720671415329,
-0.004198376554995775,
0.005311888642609119,
0.010930608958005905,
0.00822075642645359,
0.0027253020089119673,
-0.002448934130370617,
0.04198342189192772,
0.018380681052803993,
-0.036639902740716934,
-0.025874337181448936,
-0.04507751390337944,
-0.008254829794168472,
0.004594157449901104,
-0.018245797604322433,
0.028433706611394882,
-0.019775215536355972,
-0.024450957775115967,
0.001926539815030992,
0.0008985656313598156,
-0.023289041593670845,
-0.012668367475271225,
0.0487840473651886,
0.003337438218295574,
-0.02022511698305607,
0.027204187586903572,
-0.0008925332804210484,
-0.011213717050850391,
-0.039001647382974625,
0.036426763981580734,
-0.007563825696706772,
-0.019122662022709846,
0.024709902703762054,
-0.020781174302101135,
-0.052159685641527176,
0.03060556948184967,
-0.003034176304936409,
0.02660166472196579,
-0.03987953066825867,
0.023083671927452087,
-0.009732596576213837,
-0.0351012721657753,
0.018309807404875755,
0.059372540563344955,
0.007237518671900034,
-0.024167079478502274,
-0.023677656427025795,
0.011352385394275188,
0.013083540834486485,
-0.004548734053969383,
0.0037132329307496548,
-0.04760901257395744,
0.025645289570093155,
0.004602470900863409,
-0.031147658824920654,
0.030456596985459328,
0.001484802458435297,
0.005078075919300318,
-0.03331964462995529,
0.013396743685007095,
0.003588575404137373,
0.0031394818797707558,
0.02053046226501465,
-0.007905515842139721,
0.008551589213311672,
-0.020180966705083847,
-0.01740603893995285,
-0.006592936348170042,
0.0310185756534338,
0.03295038640499115,
-0.0079848887398839,
0.007680532988160849,
0.020084263756871223,
-0.017333386465907097,
0.011109297163784504,
0.011674364097416401,
0.010234721004962921,
-0.02657659351825714,
-0.03911915048956871,
0.012983803637325764,
0.024064894765615463,
0.04436938464641571,
-0.017228100448846817,
-0.006032012403011322,
-0.02066318690776825,
-0.02224341593682766,
0.0006544457282871008,
-0.004543863236904144,
0.006488600745797157,
-0.04220064729452133,
-0.015427024103701115,
0.01632961630821228,
0.02466350607573986,
0.015688475221395493,
-0.026494760066270828,
0.0031708329916000366,
0.06455115973949432,
-0.048630718141794205,
0.0067034256644546986,
0.023277217522263527,
0.015834227204322815,
0.004110181238502264,
-0.03575259447097778,
0.049138449132442474,
-0.02996230311691761,
-0.004042181186378002,
0.011209135875105858,
-0.008145119994878769,
-0.006547577679157257,
0.027911316603422165,
0.00543654290959239,
-0.022290175780653954,
0.008175111375749111,
0.006946152076125145,
0.013324390165507793,
0.042186129838228226,
0.013246948830783367,
0.0009582430357113481,
0.0019451035186648369,
0.011722722090780735,
-0.011785232461988926,
-0.008376244455575943,
0.011515297926962376,
0.013387132436037064,
0.006311919540166855,
0.02668950706720352,
0.0235469751060009,
0.005738814827054739,
0.010484167374670506,
-0.024719955399632454,
-0.015684086829423904,
0.018325410783290863,
-0.047363027930259705,
0.03458014130592346,
-0.04055992141366005,
0.041358061134815216,
-0.01571393571794033,
0.004288888536393642,
0.0007522074738517404,
0.013000891543924809,
-0.012315401807427406,
0.020803377032279968,
-0.000458307535154745,
-0.04382120072841644,
-0.0070109376683831215,
0.05728286877274513,
-0.030512284487485886,
0.0001205318549182266,
-0.03599025681614876,
-0.01287914253771305,
-0.013645438477396965,
0.04000391438603401,
0.0137960035353899,
0.0033579999580979347,
0.02612447738647461,
0.03764070197939873,
-0.031983330845832825,
0.005389215890318155,
0.024062523618340492,
-0.05117366462945938,
-0.02153150364756584,
0.010750725865364075,
0.0035643468145281076,
0.018241925165057182,
-0.001960475230589509,
-0.00958988443017006,
-0.004971143323928118,
-0.04755472391843796,
-0.00400035735219717,
0.01656782627105713,
-0.008758198469877243,
-0.027876168489456177,
0.02830204926431179,
0.017789112403988838,
-0.019900444895029068,
-0.0005185767076909542,
-0.0007565986597910523,
-0.008943385444581509,
0.004785776603966951,
0.010234690271317959,
0.04482553154230118,
0.010649258270859718,
0.0013287389883771539,
0.03234567865729332,
-0.03414469584822655,
-0.03312171623110771,
-0.0252247117459774,
-0.019473254680633545,
-0.014136857353150845,
-0.004352867137640715,
-0.014603974297642708,
0.021665122359991074,
-0.01971156895160675,
-0.013666508719325066,
-0.00762427132576704,
-0.013666143640875816,
-0.01603984646499157,
0.001233446761034429,
-0.004691815469413996,
0.02632375992834568,
0.024288251996040344,
0.0071286652237176895,
0.0003584174846764654,
0.02988312393426895,
0.008245421573519707,
-0.007991241291165352,
-0.01705135591328144,
-0.04120931029319763,
0.03705945611000061,
0.008362445048987865,
-0.0008263032650575042,
-0.008465870283544064,
0.01922811195254326,
-0.03162217140197754,
-0.011641505174338818,
0.006250441074371338,
-0.006097030360251665,
0.03140183910727501,
0.04078883305191994,
-0.01940104551613331,
-0.026844900101423264,
-0.04227606579661369,
-0.03862319514155388,
0.04555725306272507,
0.040113549679517746,
-0.01050244178622961,
-0.06061840429902077,
-0.0198112390935421,
0.01834985986351967,
-0.03908156976103783,
0.01489653903990984,
0.014223420061171055,
0.03206999599933624,
-0.016325192525982857,
0.016338583081960678,
-0.009959224611520767,
0.048516228795051575,
0.010554707609117031,
0.00534306513145566,
-0.0419890433549881,
0.012866674922406673,
-0.012544078752398491,
-0.009293916635215282,
-0.011363497003912926,
-0.0034498160239309072,
-0.00024765392299741507,
0.00806287582963705,
0.017538391053676605,
-0.013309929519891739,
-0.04922788217663765,
-0.008815924637019634,
-0.00613174494355917,
-0.035587605088949203,
-0.007859042845666409,
-0.03591010719537735,
-0.016276082023978233,
0.047717805951833725,
-0.047045521438121796,
-0.02112852782011032,
0.054397474974393845,
0.006418608594685793,
0.032859236001968384,
-0.1723727434873581,
0.020099569112062454,
0.0144657576456666,
-0.006763951387256384,
-0.011617681011557579,
0.017650026828050613,
0.014587147161364555,
-0.01660357229411602,
0.04088413715362549,
0.027247440069913864,
-0.009955060668289661,
-0.02773331291973591,
-0.030623847618699074,
-0.010960351675748825,
0.018742557615041733,
0.022224467247724533,
-0.004878861363977194,
0.018733572214841843,
-0.01309562474489212,
0.019135326147079468,
0.030306948348879814,
-0.0055708265863358974,
-0.04016050323843956,
-0.006791295949369669,
0.005450685508549213,
0.008970189839601517,
0.022711029276251793,
-0.010768134146928787,
0.04495268315076828,
-0.011734397150576115,
0.014946779236197472,
0.026102760806679726,
-0.03978540375828743,
-0.002482041483744979,
-0.009495877660810947,
-0.04713781923055649,
0.039008285850286484,
-0.01451819483190775,
0.028467239812016487,
0.010419121012091637,
0.03011753037571907,
0.01570776477456093,
0.0368526466190815,
-0.013508740812540054,
-0.025571409612894058,
-0.037905555218458176,
-0.019816892221570015,
0.018383413553237915,
-0.02079373225569725,
0.006070013158023357,
-0.019273217767477036,
-0.006633439101278782,
-0.014263479970395565,
0.049416497349739075,
-0.01628079265356064,
0.0376569926738739,
-0.03760078549385071,
0.006462799850851297,
0.0023555736988782883,
0.024518955498933792,
-0.005536566022783518,
0.08563796430826187,
-0.0004566420102491975,
-0.031505465507507324,
0.016938166692852974,
-0.016586147248744965,
0.005306008271872997,
0.005118468776345253,
-0.006807484198361635,
0.048189856112003326,
0.02568157948553562,
0.008843904361128807,
-0.023362070322036743,
-0.012000023387372494,
-0.017655575647950172,
0.001962267095223069,
-0.004304719157516956,
0.0021204431541264057,
-0.06788495182991028,
0.03002694807946682,
-0.005356502719223499,
0.0066522895358502865,
0.040518347173929214,
0.035001061856746674,
0.0198169257491827,
0.011102749034762383,
-0.02541419491171837,
-0.015536484308540821,
-0.012222785502672195,
0.006740128621459007,
-0.06855085492134094,
0.0223336573690176,
0.06176731735467911,
-0.014642526395618916,
0.03211479261517525,
0.013578318990767002,
0.0024683456867933273,
0.031084517017006874,
-0.017398810014128685,
-0.016576223075389862,
-0.022492213174700737,
0.010112850926816463,
0.009473797865211964,
0.005898944567888975,
0.0027701721992343664,
-0.02389110065996647,
0.02793039195239544,
0.06824769824743271,
0.007194106467068195,
0.015489683486521244,
-0.03518866375088692,
0.0123113002628088,
0.03653320297598839,
-0.007637370843440294,
-0.017850767821073532,
-0.041036464273929596,
-0.007844226434826851
] |
8a2561d549e0edb64456facf130fd386d46356d5 | 96,782 | py | Python | .infra/setup/playbooks/roles/ansible.kubernetes-modules/library/openshift_v1_build_config_list.py | cvicens/lab-knative | ef98aa111e566c6d33fd72c61f9c0d93a2c05b2f | [
"Apache-2.0"
] | null | null | null | .infra/setup/playbooks/roles/ansible.kubernetes-modules/library/openshift_v1_build_config_list.py | cvicens/lab-knative | ef98aa111e566c6d33fd72c61f9c0d93a2c05b2f | [
"Apache-2.0"
] | null | null | null | .infra/setup/playbooks/roles/ansible.kubernetes-modules/library/openshift_v1_build_config_list.py | cvicens/lab-knative | ef98aa111e566c6d33fd72c61f9c0d93a2c05b2f | [
"Apache-2.0"
] | null | null | null | #!/usr/bin/python
# -*- coding: utf-8 -*-
from ansible.module_utils.openshift_common import OpenShiftAnsibleModule, OpenShiftAnsibleException
DOCUMENTATION = '''
module: openshift_v1_build_config_list
short_description: OpenShift BuildConfigList
description:
- Retrieve a list of build_configs. List operations provide a snapshot read of the
underlying objects, returning a resource_version representing a consistent version
of the listed objects.
version_added: 2.3.0
author: OpenShift (@openshift)
options:
api_key:
description:
- Token used to connect to the API.
cert_file:
description:
- Path to a certificate used to authenticate with the API.
type: path
context:
description:
- The name of a context found in the Kubernetes config file.
debug:
description:
- Enable debug output from the OpenShift helper. Logging info is written to KubeObjHelper.log
default: false
type: bool
force:
description:
- If set to C(True), and I(state) is C(present), an existing object will updated,
and lists will be replaced, rather than merged.
default: false
type: bool
host:
description:
- Provide a URL for acessing the Kubernetes API.
key_file:
description:
- Path to a key file used to authenticate with the API.
type: path
kubeconfig:
description:
- Path to an existing Kubernetes config file. If not provided, and no other connection
options are provided, the openshift client will attempt to load the default
configuration file from I(~/.kube/config.json).
type: path
password:
description:
- Provide a password for connecting to the API. Use in conjunction with I(username).
resource_definition:
description:
- Provide the YAML definition for the object, bypassing any modules parameters
intended to define object attributes.
type: dict
src:
description:
- Provide a path to a file containing the YAML definition of the object. Mutually
exclusive with I(resource_definition).
type: path
ssl_ca_cert:
description:
- Path to a CA certificate used to authenticate with the API.
type: path
state:
description:
- Determines if an object should be created, patched, or deleted. When set to
C(present), the object will be created, if it does not exist, or patched, if
parameter values differ from the existing object's attributes, and deleted,
if set to C(absent). A patch operation results in merging lists and updating
dictionaries, with lists being merged into a unique set of values. If a list
contains a dictionary with a I(name) or I(type) attribute, a strategic merge
is performed, where individual elements with a matching I(name_) or I(type)
are merged. To force the replacement of lists, set the I(force) option to C(True).
default: present
choices:
- present
- absent
username:
description:
- Provide a username for connecting to the API.
verify_ssl:
description:
- Whether or not to verify the API server's SSL certificates.
type: bool
requirements:
- openshift == 0.3.3
'''
EXAMPLES = '''
'''
RETURN = '''
api_version:
type: string
description: Requested API version
build_config_list:
type: complex
returned: when I(state) = C(present)
contains:
api_version:
description:
- APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
type: str
items:
description:
- items is a list of build configs
type: list
contains:
api_version:
description:
- APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value,
and may reject unrecognized values.
type: str
kind:
description:
- Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated. In CamelCase.
type: str
metadata:
description:
- metadata for BuildConfig.
type: complex
contains:
annotations:
description:
- Annotations is an unstructured key value map stored with a resource
that may be set by external tools to store and retrieve arbitrary
metadata. They are not queryable and should be preserved when modifying
objects.
type: complex
contains: str, str
cluster_name:
description:
- The name of the cluster which the object belongs to. This is used
to distinguish resources with same name and namespace in different
clusters. This field is not set anywhere right now and apiserver is
going to ignore it if set in create or update request.
type: str
creation_timestamp:
description:
- CreationTimestamp is a timestamp representing the server time when
this object was created. It is not guaranteed to be set in happens-before
order across separate operations. Clients may not set this value.
It is represented in RFC3339 form and is in UTC. Populated by the
system. Read-only. Null for lists.
type: complex
contains: {}
deletion_grace_period_seconds:
description:
- Number of seconds allowed for this object to gracefully terminate
before it will be removed from the system. Only set when deletionTimestamp
is also set. May only be shortened. Read-only.
type: int
deletion_timestamp:
description:
- DeletionTimestamp is RFC 3339 date and time at which this resource
will be deleted. This field is set by the server when a graceful deletion
is requested by the user, and is not directly settable by a client.
The resource is expected to be deleted (no longer visible from resource
lists, and not reachable by name) after the time in this field. Once
set, this value may not be unset or be set further into the future,
although it may be shortened or the resource may be deleted prior
to this time. For example, a user may request that a pod is deleted
in 30 seconds. The Kubelet will react by sending a graceful termination
signal to the containers in the pod. After that 30 seconds, the Kubelet
will send a hard termination signal (SIGKILL) to the container and
after cleanup, remove the pod from the API. In the presence of network
partitions, this object may still exist after this timestamp, until
an administrator or automated process can determine the resource is
fully terminated. If not set, graceful deletion of the object has
not been requested. Populated by the system when a graceful deletion
is requested. Read-only.
type: complex
contains: {}
finalizers:
description:
- Must be empty before the object is deleted from the registry. Each
entry is an identifier for the responsible component that will remove
the entry from the list. If the deletionTimestamp of the object is
non-nil, entries in this list can only be removed.
type: list
contains: str
generate_name:
description:
- GenerateName is an optional prefix, used by the server, to generate
a unique name ONLY IF the Name field has not been provided. If this
field is used, the name returned to the client will be different than
the name passed. This value will also be combined with a unique suffix.
The provided value has the same validation rules as the Name field,
and may be truncated by the length of the suffix required to make
the value unique on the server. If this field is specified and the
generated name exists, the server will NOT return a 409 - instead,
it will either return 201 Created or 500 with Reason ServerTimeout
indicating a unique name could not be found in the time allotted,
and the client should retry (optionally after the time indicated in
the Retry-After header). Applied only if Name is not specified.
type: str
generation:
description:
- A sequence number representing a specific generation of the desired
state. Populated by the system. Read-only.
type: int
initializers:
description:
- An initializer is a controller which enforces some system invariant
at object creation time. This field is a list of initializers that
have not yet acted on this object. If nil or empty, this object has
been completely initialized. Otherwise, the object is considered uninitialized
and is hidden (in list/watch and get calls) from clients that haven't
explicitly asked to observe uninitialized objects. When an object
is created, the system will populate this list with the current set
of initializers. Only privileged users may set or modify this list.
Once it is empty, it may not be modified further by any user.
type: complex
contains:
pending:
description:
- Pending is a list of initializers that must execute in order before
this object is visible. When the last pending initializer is removed,
and no failing result is set, the initializers struct will be
set to nil and the object is considered as initialized and visible
to all clients.
type: list
contains:
name:
description:
- name of the process that is responsible for initializing this
object.
type: str
result:
description:
- If result is set with the Failure field, the object will be persisted
to storage and then deleted, ensuring that other clients can observe
the deletion.
type: complex
contains:
api_version:
description:
- APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to
the latest internal value, and may reject unrecognized values.
type: str
code:
description:
- Suggested HTTP return code for this status, 0 if not set.
type: int
details:
description:
- Extended data associated with the reason. Each reason may
define its own extended details. This field is optional and
the data returned is not guaranteed to conform to any schema
except that defined by the reason type.
type: complex
contains:
causes:
description:
- The Causes array includes more details associated with
the StatusReason failure. Not all StatusReasons may provide
detailed causes.
type: list
contains:
field:
description:
- 'The field of the resource that has caused this error,
as named by its JSON serialization. May include dot
and postfix notation for nested attributes. Arrays
are zero-indexed. Fields may appear more than once
in an array of causes due to fields having multiple
errors. Optional. Examples: "name" - the field "name"
on the current resource "items[0].name" - the field
"name" on the first array entry in "items"'
type: str
message:
description:
- A human-readable description of the cause of the error.
This field may be presented as-is to a reader.
type: str
reason:
description:
- A machine-readable description of the cause of the
error. If this value is empty there is no information
available.
type: str
group:
description:
- The group attribute of the resource associated with the
status StatusReason.
type: str
kind:
description:
- The kind attribute of the resource associated with the
status StatusReason. On some operations may differ from
the requested resource Kind.
type: str
name:
description:
- The name attribute of the resource associated with the
status StatusReason (when there is a single name which
can be described).
type: str
retry_after_seconds:
description:
- If specified, the time in seconds before the operation
should be retried.
type: int
uid:
description:
- UID of the resource. (when there is a single resource
which can be described).
type: str
kind:
description:
- Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint
the client submits requests to. Cannot be updated. In CamelCase.
type: str
message:
description:
- A human-readable description of the status of this operation.
type: str
metadata:
description:
- Standard list metadata.
type: complex
contains:
resource_version:
description:
- String that identifies the server's internal version of
this object that can be used by clients to determine when
objects have changed. Value must be treated as opaque
by clients and passed unmodified back to the server. Populated
by the system. Read-only.
type: str
self_link:
description:
- SelfLink is a URL representing this object. Populated
by the system. Read-only.
type: str
reason:
description:
- A machine-readable description of why this operation is in
the "Failure" status. If this value is empty there is no information
available. A Reason clarifies an HTTP status code but does
not override it.
type: str
status:
description:
- 'Status of the operation. One of: "Success" or "Failure".'
type: str
labels:
description:
- Map of string keys and values that can be used to organize and categorize
(scope and select) objects. May match selectors of replication controllers
and services.
type: complex
contains: str, str
name:
description:
- Name must be unique within a namespace. Is required when creating
resources, although some resources may allow a client to request the
generation of an appropriate name automatically. Name is primarily
intended for creation idempotence and configuration definition. Cannot
be updated.
type: str
namespace:
description:
- Namespace defines the space within each name must be unique. An empty
namespace is equivalent to the "default" namespace, but "default"
is the canonical representation. Not all objects are required to be
scoped to a namespace - the value of this field for those objects
will be empty. Must be a DNS_LABEL. Cannot be updated.
type: str
owner_references:
description:
- List of objects depended by this object. If ALL objects in the list
have been deleted, this object will be garbage collected. If this
object is managed by a controller, then an entry in this list will
point to this controller, with the controller field set to true. There
cannot be more than one managing controller.
type: list
contains:
api_version:
description:
- API version of the referent.
type: str
block_owner_deletion:
description:
- If true, AND if the owner has the "foregroundDeletion" finalizer,
then the owner cannot be deleted from the key-value store until
this reference is removed. Defaults to false. To set this field,
a user needs "delete" permission of the owner, otherwise 422 (Unprocessable
Entity) will be returned.
type: bool
controller:
description:
- If true, this reference points to the managing controller.
type: bool
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
uid:
description:
- UID of the referent.
type: str
resource_version:
description:
- An opaque value that represents the internal version of this object
that can be used by clients to determine when objects have changed.
May be used for optimistic concurrency, change detection, and the
watch operation on a resource or set of resources. Clients must treat
these values as opaque and passed unmodified back to the server. They
may only be valid for a particular resource or set of resources. Populated
by the system. Read-only. Value must be treated as opaque by clients
and .
type: str
self_link:
description:
- SelfLink is a URL representing this object. Populated by the system.
Read-only.
type: str
uid:
description:
- UID is the unique in time and space value for this object. It is typically
generated by the server on successful creation of a resource and is
not allowed to change on PUT operations. Populated by the system.
Read-only.
type: str
spec:
description:
- spec holds all the input necessary to produce a new build, and the conditions
when to trigger them.
type: complex
contains:
completion_deadline_seconds:
description:
- completionDeadlineSeconds is an optional duration in seconds, counted
from the time when a build pod gets scheduled in the system, that
the build may be active on a node before the system actively tries
to terminate the build; value must be positive integer
type: int
failed_builds_history_limit:
description:
- failedBuildsHistoryLimit is the number of old failed builds to retain.
If not specified, all failed builds are retained.
type: int
node_selector:
description:
- nodeSelector is a selector which must be true for the build pod to
fit on a node If nil, it can be overridden by default build nodeselector
values for the cluster. If set to an empty map or a map with any values,
default build nodeselector values are ignored.
type: complex
contains: str, str
output:
description:
- output describes the Docker image the Strategy should produce.
type: complex
contains:
image_labels:
description:
- imageLabels define a list of labels that are applied to the resulting
image. If there are multiple labels with the same name then the
last one in the list is used.
type: list
contains:
name:
description:
- name defines the name of the label. It must have non-zero
length.
type: str
value:
description:
- value defines the literal value of the label.
type: str
push_secret:
description:
- PushSecret is the name of a Secret that would be used for setting
up the authentication for executing the Docker push to authentication
enabled Docker Registry (or Docker Hub).
type: complex
contains:
name:
description:
- Name of the referent.
type: str
to:
description:
- to defines an optional location to push the output of this build
to. Kind must be one of 'ImageStreamTag' or 'DockerImage'. This
value will be used to look up a Docker image repository to push
to. In the case of an ImageStreamTag, the ImageStreamTag will
be looked for in the namespace of the build unless Namespace is
specified.
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field access
statement, such as desiredState.manifest.containers[2]. For
example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part of
an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
post_commit:
description:
- postCommit is a build hook executed after the build output image is
committed, before it is pushed to a registry.
type: complex
contains:
args:
description:
- args is a list of arguments that are provided to either Command,
Script or the Docker image's default entrypoint. The arguments
are placed immediately after the command to be run.
type: list
contains: str
command:
description:
- command is the command to run. It may not be specified with Script.
This might be needed if the image doesn't have `/bin/sh`, or if
you do not want to use a shell. In all other cases, using Script
might be more convenient.
type: list
contains: str
script:
description:
- script is a shell script to be run with `/bin/sh -ic`. It may
not be specified with Command. Use Script when a shell script
is appropriate to execute the post build hook, for example for
running unit tests with `rake test`. If you need control over
the image entrypoint, or if the image does not have `/bin/sh`,
use Command and/or Args. The `-i` flag is needed to support CentOS
and RHEL images that use Software Collections (SCL), in order
to have the appropriate collections enabled in the shell. E.g.,
in the Ruby image, this is necessary to make `ruby`, `bundle`
and other binaries available in the PATH.
type: str
resources:
description:
- resources computes resource requirements to execute the build.
type: complex
contains:
limits:
description:
- Limits describes the maximum amount of compute resources allowed.
type: complex
contains: str, str
requests:
description:
- Requests describes the minimum amount of compute resources required.
If Requests is omitted for a container, it defaults to Limits
if that is explicitly specified, otherwise to an implementation-defined
value.
type: complex
contains: str, str
revision:
description:
- revision is the information from the source for a specific repo snapshot.
This is optional.
type: complex
contains:
git:
description:
- Git contains information about git-based build source
type: complex
contains:
author:
description:
- author is the author of a specific commit
type: complex
contains:
email:
description:
- email of the source control user
type: str
name:
description:
- name of the source control user
type: str
commit:
description:
- commit is the commit hash identifying a specific commit
type: str
committer:
description:
- committer is the committer of a specific commit
type: complex
contains:
email:
description:
- email of the source control user
type: str
name:
description:
- name of the source control user
type: str
message:
description:
- message is the description of a specific commit
type: str
type:
description:
- type of the build source, may be one of 'Source', 'Dockerfile',
'Binary', or 'Images'
type: str
run_policy:
description:
- RunPolicy describes how the new build created from this build configuration
will be scheduled for execution. This is optional, if not specified
we default to "Serial".
type: str
service_account:
description:
- serviceAccount is the name of the ServiceAccount to use to run the
pod created by this build. The pod will be allowed to use secrets
referenced by the ServiceAccount
type: str
source:
description:
- source describes the SCM in use.
type: complex
contains:
binary:
description:
- binary builds accept a binary as their input. The binary is generally
assumed to be a tar, gzipped tar, or zip file depending on the
strategy. For Docker builds, this is the build context and an
optional Dockerfile may be specified to override any Dockerfile
in the build context. For Source builds, this is assumed to be
an archive as described above. For Source and Docker builds, if
binary.asFile is set the build will receive a directory with a
single file. contextDir may be used when an archive is provided.
Custom builds will receive this binary as input on STDIN.
type: complex
contains:
as_file:
description:
- asFile indicates that the provided binary input should be
considered a single file within the build input. For example,
specifying "webapp.war" would place the provided binary as
`/webapp.war` for the builder. If left empty, the Docker and
Source build strategies assume this file is a zip, tar, or
tar.gz file and extract it as the source. The custom strategy
receives this binary as standard input. This filename may
not contain slashes or be '..' or '.'.
type: str
context_dir:
description:
- contextDir specifies the sub-directory where the source code for
the application exists. This allows to have buildable sources
in directory other than root of repository.
type: str
dockerfile:
description:
- dockerfile is the raw contents of a Dockerfile which should be
built. When this option is specified, the FROM may be modified
based on your strategy base image and additional ENV stanzas from
your strategy environment will be added after the FROM, but before
the rest of your Dockerfile stanzas. The Dockerfile source type
may be used with other options like git - in those cases the Git
repo will have any innate Dockerfile replaced in the context dir.
type: str
git:
description:
- git contains optional information about git build source
type: complex
contains:
http_proxy:
description:
- httpProxy is a proxy used to reach the git repository over
http
type: str
https_proxy:
description:
- httpsProxy is a proxy used to reach the git repository over
https
type: str
no_proxy:
description:
- noProxy is the list of domains for which the proxy should
not be used
type: str
ref:
description:
- ref is the branch/tag/ref to build.
type: str
uri:
description:
- uri points to the source that will be built. The structure
of the source will depend on the type of build to run
type: str
images:
description:
- images describes a set of images to be used to provide source
for the build
type: list
contains:
_from:
description:
- from is a reference to an ImageStreamTag, ImageStreamImage,
or DockerImage to copy source from.
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
paths:
description:
- paths is a list of source and destination paths to copy from
the image.
type: list
contains:
destination_dir:
description:
- destinationDir is the relative directory within the build
directory where files copied from the image are placed.
type: str
source_path:
description:
- sourcePath is the absolute path of the file or directory
inside the image to copy to the build directory. If the
source path ends in /. then the content of the directory
will be copied, but the directory itself will not be created
at the destination.
type: str
pull_secret:
description:
- pullSecret is a reference to a secret to be used to pull the
image from a registry If the image is pulled from the OpenShift
registry, this field does not need to be set.
type: complex
contains:
name:
description:
- Name of the referent.
type: str
secrets:
description:
- secrets represents a list of secrets and their destinations that
will be used only for the build.
type: list
contains:
destination_dir:
description:
- destinationDir is the directory where the files from the secret
should be available for the build time. For the Source build
strategy, these will be injected into a container where the
assemble script runs. Later, when the script finishes, all
files injected will be truncated to zero length. For the Docker
build strategy, these will be copied into the build directory,
where the Dockerfile is located, so users can ADD or COPY
them during docker build.
type: str
secret:
description:
- secret is a reference to an existing secret that you want
to use in your build.
type: complex
contains:
name:
description:
- Name of the referent.
type: str
source_secret:
description:
- "sourceSecret is the name of a Secret that would be used for setting\
\ up the authentication for cloning private repository. The secret\
\ contains valid credentials for remote repository, where the\
\ data's key represent the authentication method to be used and\
\ value is the base64 encoded credentials. Supported auth methods\
\ are: ssh-privatekey."
type: complex
contains:
name:
description:
- Name of the referent.
type: str
type:
description:
- type of build input to accept
type: str
strategy:
description:
- strategy defines how to perform a build.
type: complex
contains:
custom_strategy:
description:
- customStrategy holds the parameters to the Custom build strategy
type: complex
contains:
_from:
description:
- from is reference to an DockerImage, ImageStreamTag, or ImageStreamImage
from which the docker image should be pulled
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
build_api_version:
description:
- buildAPIVersion is the requested API version for the Build
object serialized and passed to the custom builder
type: str
env:
description:
- env contains additional environment variables you want to
pass into a builder container.
type: list
contains:
name:
description:
- Name of the environment variable. Must be a C_IDENTIFIER.
type: str
value:
description:
- 'Variable references $(VAR_NAME) are expanded using the
previous defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be
unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will
never be expanded, regardless of whether the variable
exists or not. Defaults to "".'
type: str
value_from:
description:
- Source for the environment variable's value. Cannot be
used if value is not empty.
type: complex
contains:
config_map_key_ref:
description:
- Selects a key of a ConfigMap.
type: complex
contains:
key:
description:
- The key to select.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the ConfigMap or it's key must
be defined
type: bool
field_ref:
description:
- 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP.'
type: complex
contains:
api_version:
description:
- Version of the schema the FieldPath is written
in terms of, defaults to "v1".
type: str
field_path:
description:
- Path of the field to select in the specified API
version.
type: str
resource_field_ref:
description:
- 'Selects a resource of the container: only resources
limits and requests (limits.cpu, limits.memory, requests.cpu
and requests.memory) are currently supported.'
type: complex
contains:
container_name:
description:
- 'Container name: required for volumes, optional
for env vars'
type: str
divisor:
description:
- Specifies the output format of the exposed resources,
defaults to "1"
type: str
resource:
description:
- 'Required: resource to select'
type: str
secret_key_ref:
description:
- Selects a key of a secret in the pod's namespace
type: complex
contains:
key:
description:
- The key of the secret to select from. Must be
a valid secret key.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the Secret or it's key must be
defined
type: bool
expose_docker_socket:
description:
- exposeDockerSocket will allow running Docker commands (and
build Docker images) from inside the Docker container.
type: bool
force_pull:
description:
- forcePull describes if the controller should configure the
build pod to always pull the images for the builder or only
pull if it is not present locally
type: bool
pull_secret:
description:
- pullSecret is the name of a Secret that would be used for
setting up the authentication for pulling the Docker images
from the private Docker registries
type: complex
contains:
name:
description:
- Name of the referent.
type: str
secrets:
description:
- secrets is a list of additional secrets that will be included
in the build pod
type: list
contains:
mount_path:
description:
- mountPath is the path at which to mount the secret
type: str
secret_source:
description:
- secretSource is a reference to the secret
type: complex
contains:
name:
description:
- Name of the referent.
type: str
docker_strategy:
description:
- dockerStrategy holds the parameters to the Docker build strategy.
type: complex
contains:
_from:
description:
- from is reference to an DockerImage, ImageStreamTag, or ImageStreamImage
from which the docker image should be pulled the resulting
image will be used in the FROM line of the Dockerfile for
this build.
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
build_args:
description:
- buildArgs contains build arguments that will be resolved in
the Dockerfile. See
type: list
contains:
name:
description:
- Name of the environment variable. Must be a C_IDENTIFIER.
type: str
value:
description:
- 'Variable references $(VAR_NAME) are expanded using the
previous defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be
unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will
never be expanded, regardless of whether the variable
exists or not. Defaults to "".'
type: str
value_from:
description:
- Source for the environment variable's value. Cannot be
used if value is not empty.
type: complex
contains:
config_map_key_ref:
description:
- Selects a key of a ConfigMap.
type: complex
contains:
key:
description:
- The key to select.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the ConfigMap or it's key must
be defined
type: bool
field_ref:
description:
- 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP.'
type: complex
contains:
api_version:
description:
- Version of the schema the FieldPath is written
in terms of, defaults to "v1".
type: str
field_path:
description:
- Path of the field to select in the specified API
version.
type: str
resource_field_ref:
description:
- 'Selects a resource of the container: only resources
limits and requests (limits.cpu, limits.memory, requests.cpu
and requests.memory) are currently supported.'
type: complex
contains:
container_name:
description:
- 'Container name: required for volumes, optional
for env vars'
type: str
divisor:
description:
- Specifies the output format of the exposed resources,
defaults to "1"
type: str
resource:
description:
- 'Required: resource to select'
type: str
secret_key_ref:
description:
- Selects a key of a secret in the pod's namespace
type: complex
contains:
key:
description:
- The key of the secret to select from. Must be
a valid secret key.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the Secret or it's key must be
defined
type: bool
dockerfile_path:
description:
- dockerfilePath is the path of the Dockerfile that will be
used to build the Docker image, relative to the root of the
context (contextDir).
type: str
env:
description:
- env contains additional environment variables you want to
pass into a builder container.
type: list
contains:
name:
description:
- Name of the environment variable. Must be a C_IDENTIFIER.
type: str
value:
description:
- 'Variable references $(VAR_NAME) are expanded using the
previous defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be
unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will
never be expanded, regardless of whether the variable
exists or not. Defaults to "".'
type: str
value_from:
description:
- Source for the environment variable's value. Cannot be
used if value is not empty.
type: complex
contains:
config_map_key_ref:
description:
- Selects a key of a ConfigMap.
type: complex
contains:
key:
description:
- The key to select.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the ConfigMap or it's key must
be defined
type: bool
field_ref:
description:
- 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP.'
type: complex
contains:
api_version:
description:
- Version of the schema the FieldPath is written
in terms of, defaults to "v1".
type: str
field_path:
description:
- Path of the field to select in the specified API
version.
type: str
resource_field_ref:
description:
- 'Selects a resource of the container: only resources
limits and requests (limits.cpu, limits.memory, requests.cpu
and requests.memory) are currently supported.'
type: complex
contains:
container_name:
description:
- 'Container name: required for volumes, optional
for env vars'
type: str
divisor:
description:
- Specifies the output format of the exposed resources,
defaults to "1"
type: str
resource:
description:
- 'Required: resource to select'
type: str
secret_key_ref:
description:
- Selects a key of a secret in the pod's namespace
type: complex
contains:
key:
description:
- The key of the secret to select from. Must be
a valid secret key.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the Secret or it's key must be
defined
type: bool
force_pull:
description:
- forcePull describes if the builder should pull the images
from registry prior to building.
type: bool
image_optimization_policy:
description:
- imageOptimizationPolicy describes what optimizations the system
can use when building images to reduce the final size or time
spent building the image. The default policy is 'None' which
means the final build image will be equivalent to an image
created by the Docker build API. The experimental policy 'SkipLayers'
will avoid commiting new layers in between each image step,
and will fail if the Dockerfile cannot provide compatibility
with the 'None' policy. An additional experimental policy
'SkipLayersAndWarn' is the same as 'SkipLayers' but simply
warns if compatibility cannot be preserved.
type: str
no_cache:
description:
- noCache if set to true indicates that the docker build must
be executed with the --no-cache=true flag
type: bool
pull_secret:
description:
- pullSecret is the name of a Secret that would be used for
setting up the authentication for pulling the Docker images
from the private Docker registries
type: complex
contains:
name:
description:
- Name of the referent.
type: str
jenkins_pipeline_strategy:
description:
- JenkinsPipelineStrategy holds the parameters to the Jenkins Pipeline
build strategy. This strategy is in tech preview.
type: complex
contains:
env:
description:
- env contains additional environment variables you want to
pass into a build pipeline.
type: list
contains:
name:
description:
- Name of the environment variable. Must be a C_IDENTIFIER.
type: str
value:
description:
- 'Variable references $(VAR_NAME) are expanded using the
previous defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be
unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will
never be expanded, regardless of whether the variable
exists or not. Defaults to "".'
type: str
value_from:
description:
- Source for the environment variable's value. Cannot be
used if value is not empty.
type: complex
contains:
config_map_key_ref:
description:
- Selects a key of a ConfigMap.
type: complex
contains:
key:
description:
- The key to select.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the ConfigMap or it's key must
be defined
type: bool
field_ref:
description:
- 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP.'
type: complex
contains:
api_version:
description:
- Version of the schema the FieldPath is written
in terms of, defaults to "v1".
type: str
field_path:
description:
- Path of the field to select in the specified API
version.
type: str
resource_field_ref:
description:
- 'Selects a resource of the container: only resources
limits and requests (limits.cpu, limits.memory, requests.cpu
and requests.memory) are currently supported.'
type: complex
contains:
container_name:
description:
- 'Container name: required for volumes, optional
for env vars'
type: str
divisor:
description:
- Specifies the output format of the exposed resources,
defaults to "1"
type: str
resource:
description:
- 'Required: resource to select'
type: str
secret_key_ref:
description:
- Selects a key of a secret in the pod's namespace
type: complex
contains:
key:
description:
- The key of the secret to select from. Must be
a valid secret key.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the Secret or it's key must be
defined
type: bool
jenkinsfile:
description:
- Jenkinsfile defines the optional raw contents of a Jenkinsfile
which defines a Jenkins pipeline build.
type: str
jenkinsfile_path:
description:
- JenkinsfilePath is the optional path of the Jenkinsfile that
will be used to configure the pipeline relative to the root
of the context (contextDir). If both JenkinsfilePath & Jenkinsfile
are both not specified, this defaults to Jenkinsfile in the
root of the specified contextDir.
type: str
source_strategy:
description:
- sourceStrategy holds the parameters to the Source build strategy.
type: complex
contains:
_from:
description:
- from is reference to an DockerImage, ImageStreamTag, or ImageStreamImage
from which the docker image should be pulled
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
env:
description:
- env contains additional environment variables you want to
pass into a builder container.
type: list
contains:
name:
description:
- Name of the environment variable. Must be a C_IDENTIFIER.
type: str
value:
description:
- 'Variable references $(VAR_NAME) are expanded using the
previous defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be
unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will
never be expanded, regardless of whether the variable
exists or not. Defaults to "".'
type: str
value_from:
description:
- Source for the environment variable's value. Cannot be
used if value is not empty.
type: complex
contains:
config_map_key_ref:
description:
- Selects a key of a ConfigMap.
type: complex
contains:
key:
description:
- The key to select.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the ConfigMap or it's key must
be defined
type: bool
field_ref:
description:
- 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP.'
type: complex
contains:
api_version:
description:
- Version of the schema the FieldPath is written
in terms of, defaults to "v1".
type: str
field_path:
description:
- Path of the field to select in the specified API
version.
type: str
resource_field_ref:
description:
- 'Selects a resource of the container: only resources
limits and requests (limits.cpu, limits.memory, requests.cpu
and requests.memory) are currently supported.'
type: complex
contains:
container_name:
description:
- 'Container name: required for volumes, optional
for env vars'
type: str
divisor:
description:
- Specifies the output format of the exposed resources,
defaults to "1"
type: str
resource:
description:
- 'Required: resource to select'
type: str
secret_key_ref:
description:
- Selects a key of a secret in the pod's namespace
type: complex
contains:
key:
description:
- The key of the secret to select from. Must be
a valid secret key.
type: str
name:
description:
- Name of the referent.
type: str
optional:
description:
- Specify whether the Secret or it's key must be
defined
type: bool
force_pull:
description:
- forcePull describes if the builder should pull the images
from registry prior to building.
type: bool
incremental:
description:
- incremental flag forces the Source build to do incremental
builds if true.
type: bool
pull_secret:
description:
- pullSecret is the name of a Secret that would be used for
setting up the authentication for pulling the Docker images
from the private Docker registries
type: complex
contains:
name:
description:
- Name of the referent.
type: str
runtime_artifacts:
description:
- 'runtimeArtifacts specifies a list of source/destination pairs
that will be copied from the builder to the runtime image.
sourcePath can be a file or directory. destinationDir must
be a directory. destinationDir can also be empty or equal
to ".", in this case it just refers to the root of WORKDIR.
Deprecated: This feature will be removed in a future release.
Use ImageSource to copy binary artifacts created from one
build into a separate runtime image.'
type: list
contains:
destination_dir:
description:
- destinationDir is the relative directory within the build
directory where files copied from the image are placed.
type: str
source_path:
description:
- sourcePath is the absolute path of the file or directory
inside the image to copy to the build directory. If the
source path ends in /. then the content of the directory
will be copied, but the directory itself will not be created
at the destination.
type: str
runtime_image:
description:
- 'runtimeImage is an optional image that is used to run an
application without unneeded dependencies installed. The building
of the application is still done in the builder image but,
post build, you can copy the needed artifacts in the runtime
image for use. Deprecated: This feature will be removed in
a future release. Use ImageSource to copy binary artifacts
created from one build into a separate runtime image.'
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
scripts:
description:
- scripts is the location of Source scripts
type: str
type:
description:
- type is the kind of build strategy.
type: str
successful_builds_history_limit:
description:
- successfulBuildsHistoryLimit is the number of old successful builds
to retain. If not specified, all successful builds are retained.
type: int
triggers:
description:
- triggers determine how new Builds can be launched from a BuildConfig.
If no triggers are defined, a new build can only occur as a result
of an explicit client build creation.
type: list
contains:
bitbucket:
description:
- BitbucketWebHook contains the parameters for a Bitbucket webhook
type of trigger
type: complex
contains:
allow_env:
description:
- allowEnv determines whether the webhook can set environment
variables; can only be set to true for GenericWebHook.
type: bool
secret:
description:
- secret used to validate requests.
type: str
generic:
description:
- generic contains the parameters for a Generic webhook type of
trigger
type: complex
contains:
allow_env:
description:
- allowEnv determines whether the webhook can set environment
variables; can only be set to true for GenericWebHook.
type: bool
secret:
description:
- secret used to validate requests.
type: str
github:
description:
- github contains the parameters for a GitHub webhook type of trigger
type: complex
contains:
allow_env:
description:
- allowEnv determines whether the webhook can set environment
variables; can only be set to true for GenericWebHook.
type: bool
secret:
description:
- secret used to validate requests.
type: str
gitlab:
description:
- GitLabWebHook contains the parameters for a GitLab webhook type
of trigger
type: complex
contains:
allow_env:
description:
- allowEnv determines whether the webhook can set environment
variables; can only be set to true for GenericWebHook.
type: bool
secret:
description:
- secret used to validate requests.
type: str
image_change:
description:
- imageChange contains parameters for an ImageChange type of trigger
type: complex
contains:
_from:
description:
- from is a reference to an ImageStreamTag that will trigger
a build when updated It is optional. If no From is specified,
the From image from the build strategy will be used. Only
one ImageChangeTrigger with an empty From reference is allowed
in a build configuration.
type: complex
contains:
api_version:
description:
- API version of the referent.
type: str
field_path:
description:
- 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object.'
type: str
kind:
description:
- Kind of the referent.
type: str
name:
description:
- Name of the referent.
type: str
namespace:
description:
- Namespace of the referent.
type: str
resource_version:
description:
- Specific resourceVersion to which this reference is made,
if any.
type: str
uid:
description:
- UID of the referent.
type: str
last_triggered_image_id:
description:
- lastTriggeredImageID is used internally by the ImageChangeController
to save last used image ID for build
type: str
type:
description:
- type is the type of build trigger
type: str
status:
description:
- status holds any relevant information about a build config
type: complex
contains:
last_version:
description:
- lastVersion is used to inform about number of last triggered build.
type: int
kind:
description:
- Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to. Cannot
be updated. In CamelCase.
type: str
metadata:
description:
- metadata for BuildConfigList.
type: complex
contains:
resource_version:
description:
- String that identifies the server's internal version of this object that
can be used by clients to determine when objects have changed. Value must
be treated as opaque by clients and passed unmodified back to the server.
Populated by the system. Read-only.
type: str
self_link:
description:
- SelfLink is a URL representing this object. Populated by the system. Read-only.
type: str
'''
def main():
try:
module = OpenShiftAnsibleModule('build_config_list', 'v1')
except OpenShiftAnsibleException as exc:
# The helper failed to init, so there is no module object. All we can do is raise the error.
raise Exception(exc.message)
try:
module.execute_module()
except OpenShiftAnsibleException as exc:
module.fail_json(msg="Module failed!", error=str(exc))
if __name__ == '__main__':
main()
| 50.486176 | 100 | 0.443027 | 1 | 1.9701 | [
-0.03478948771953583,
0.02437642216682434,
-0.0025258739478886127,
0.02221267856657505,
-0.02704777754843235,
0.009184516966342926,
-0.0182780958712101,
-0.0027659477200359106,
-0.0029378298204392195,
0.007461563218384981,
0.006383741274476051,
-0.0025061059277504683,
0.009868916124105453,
0.029453935101628304,
0.0242103710770607,
-0.045886486768722534,
0.3058486580848694,
-0.0041408296674489975,
-0.014426364563405514,
-0.01452590525150299,
-0.005930830258876085,
0.02140742726624012,
0.034374769777059555,
0.008930631913244724,
-0.005314369685947895,
0.05080907419323921,
0.05606444552540779,
0.010911396704614162,
0.010229947976768017,
-0.014205222018063068,
-0.017368774861097336,
-0.0018658587941899896,
-0.030329659581184387,
0.004396299831569195,
-0.0018900542054325342,
-0.0034461847972124815,
0.0021878951229155064,
-0.06619562208652496,
0.005174992606043816,
-0.007524001412093639,
0.004755065310746431,
-0.02663738653063774,
-0.01330094039440155,
0.01643288880586624,
0.025386644527316093,
0.04008764401078224,
-0.007095590699464083,
0.03433556482195854,
0.0027262612711638212,
-0.03282080218195915,
-0.020864184945821762,
-0.030008533969521523,
-0.03833765536546707,
-0.01323673315346241,
0.009221448563039303,
-0.013561319559812546,
0.01018708385527134,
-0.013003796339035034,
-0.010012536309659481,
-0.011662124656140804,
-0.02488032728433609,
-0.001080531277693808,
-0.01347044575959444,
-0.01650269143283367,
-0.028411109000444412,
-0.001988990930840373,
0.009554843418300152,
0.009062090888619423,
-0.025837402790784836,
-0.015306525863707066,
-0.013519550673663616,
0.003780247876420617,
0.0162039864808321,
0.0059061297215521336,
0.007189492229372263,
0.009385558776557446,
-0.016469299793243408,
-0.001097413944080472,
-0.036474891006946564,
-0.012382670305669308,
-0.017933614552021027,
0.038527436554431915,
0.03838541731238365,
-0.01088251918554306,
-0.004589362535625696,
0.016796762123703957,
0.059312280267477036,
-0.007810847833752632,
0.058142028748989105,
-0.018499186262488365,
-0.015825165435671806,
-0.0008054187637753785,
-0.02502983622252941,
0.009174412116408348,
0.0007933902670629323,
0.0022919727489352226,
0.002268440555781126,
0.004405715502798557,
0.00793162826448679,
-0.0051049781031906605,
0.021525336429476738,
-0.00213152845390141,
-0.02297711744904518,
-0.0038464274257421494,
0.006671437527984381,
-0.018749725073575974,
0.002630753442645073,
-0.007612314075231552,
-0.020737815648317337,
0.00013722518633585423,
-0.07757412642240524,
0.003369374666363001,
-0.020151598379015923,
-0.004380751866847277,
-0.0063694375567138195,
-0.006043989211320877,
0.0025850983802229166,
-0.0005605496116913855,
-0.006567622069269419,
0.00952427089214325,
-0.01579982601106167,
0.010948820039629936,
0.011042873375117779,
-0.027424165979027748,
-0.010241052135825157,
-0.012213285081088543,
0.02598685584962368,
0.013103559613227844,
-0.008352525532245636,
0.013875805772840977,
-0.005550932604819536,
-0.01764802262187004,
-0.012334276922047138,
-0.03355207294225693,
-0.008406592532992363,
-0.062407173216342926,
0.0021920332219451666,
0.00004613217242876999,
-0.035515155643224716,
0.04155774042010307,
-0.011806233786046505,
0.026240460574626923,
-0.009546120651066303,
0.02049938775599003,
-0.010972249321639538,
-0.030825695022940636,
0.010916884057223797,
0.018518175929784775,
-0.03008185513317585,
-0.0017006659181788564,
0.015048321336507797,
-0.013607440516352654,
-0.018663499504327774,
-0.0014890480088070035,
-0.021414173766970634,
-0.00923201348632574,
0.005085140001028776,
-0.005177252925932407,
0.028466811403632164,
0.015810858458280563,
-0.004127849359065294,
0.025831228122115135,
0.0020072737243026495,
-0.046434227377176285,
-0.017612941563129425,
0.04470191150903702,
0.001714769983664155,
-0.0009443628950975835,
-0.005937325302511454,
-0.0014613219536840916,
0.024490097537636757,
-0.023928556591272354,
-0.009966550394892693,
0.024172624573111534,
0.005757712293416262,
-0.0036764361429959536,
-0.004582731984555721,
0.008834319189190865,
-0.0007445676019415259,
-0.03099292330443859,
-0.006170762237161398,
-0.013396707363426685,
0.04788793623447418,
0.014985869638621807,
0.004228922538459301,
-0.01865500584244728,
0.004328597337007523,
-0.03228307142853737,
0.014568469487130642,
-0.012243172153830528,
-0.00039007648592814803,
0.012353921309113503,
0.03107205592095852,
0.004499819595366716,
0.0037628391291946173,
-0.012497566640377045,
0.022277027368545532,
0.014975160360336304,
-0.0050933947786688805,
-0.001335968729108572,
-0.004521030467003584,
-0.024730484932661057,
0.020728902891278267,
-0.005647727288305759,
-0.0040641119703650475,
-0.01417542714625597,
-0.7787197828292847,
0.013270078226923943,
0.0013702596770599484,
-0.006876589264720678,
0.007708759978413582,
0.01207725703716278,
0.02163456752896309,
-0.008229444734752178,
-0.03095969930291176,
-0.01589045114815235,
0.0017720223404467106,
-0.03509507700800896,
-0.00920911505818367,
0.00914917141199112,
-0.004685339517891407,
0.00028649839805439115,
-0.017733324319124222,
-0.005736575461924076,
0.01944703981280327,
-0.017248522490262985,
0.03325643390417099,
-0.03887294977903366,
-0.015932749956846237,
0.0013299654237926006,
0.002742954296991229,
-0.0026533191557973623,
0.01791541278362274,
0.006953428033739328,
-0.0008309842087328434,
0.005461953580379486,
-0.013825574889779091,
-0.019376788288354874,
0.03898106515407562,
0.003806810127571225,
0.0052567338570952415,
-0.012674227356910706,
-0.009332005865871906,
0.002790560480207205,
0.045139130204916,
0.014990167692303658,
-0.01937355287373066,
-0.024016575887799263,
-0.0231283251196146,
-0.037865523248910904,
0.0072909193113446236,
0.017051275819540024,
0.04223787784576416,
-0.01751347817480564,
-0.034529250115156174,
-0.018472421914339066,
0.002254434861242771,
-0.006970681250095367,
-0.0044402144849300385,
-0.017776712775230408,
0.03435773029923439,
-0.030058547854423523,
-0.008731318637728691,
-0.009358000010251999,
0.00024357496295124292,
0.025116590782999992,
0.00719462288543582,
0.021003026515245438,
-0.02275562472641468,
0.02574058435857296,
-0.019770756363868713,
0.009744209237396717,
0.010054907761514187,
-0.01813981868326664,
-0.025930270552635193,
0.006843069102615118,
0.017796466127038002,
-0.01592024601995945,
-0.023290948942303658,
0.002689965534955263,
-0.033333275467157364,
0.038833409547805786,
0.010047810152173042,
0.009490463882684708,
-0.003830050816759467,
-0.004441154655069113,
0.0052490499801933765,
0.010938397608697414,
-0.03443928435444832,
-0.010228005237877369,
-0.009778915904462337,
0.0013822931796312332,
-0.013190386816859245,
0.01042724959552288,
0.032488979399204254,
0.011303465813398361,
-0.024818269535899162,
-0.008078602142632008,
0.02053985185921192,
-0.013034123927354813,
0.021675392985343933,
0.022511065006256104,
0.008488054387271404,
0.05693432316184044,
0.030524948611855507,
-0.003905759658664465,
-0.028060797601938248,
0.0038543986156582832,
0.0055239275097846985,
0.0652712807059288,
-0.01698947511613369,
-0.0045563168823719025,
-0.014664550311863422,
-0.007687490899115801,
0.030210666358470917,
-0.057327285408973694,
0.020767806097865105,
-0.01256698090583086,
-0.03792890906333923,
0.005757532548159361,
0.032733526080846786,
-0.02106393687427044,
0.016807833686470985,
-0.01306797843426466,
0.010953898541629314,
0.005722780246287584,
0.012502355501055717,
0.021339667961001396,
0.033461183309555054,
0.0013476612512022257,
-0.02852964960038662,
-0.026098981499671936,
-0.02870493195950985,
-0.014652278274297714,
0.03235822916030884,
0.0006169494008645415,
0.0009045965853147209,
0.000931981427129358,
-0.007759463507682085,
-0.006690520793199539,
0.0018302805256098509,
-0.011030533351004124,
-0.017468921840190887,
-0.0029350018594413996,
0.026837287470698357,
-0.03668678179383278,
0.0007075220928527415,
0.0042229145765304565,
-0.016797613352537155,
0.00321896537207067,
0.011274205520749092,
0.021908780559897423,
-0.015612086281180382,
-0.009165321476757526,
-0.0386703684926033,
-0.004877864848822355,
0.005842205137014389,
0.007326532155275345,
-0.003730620024725795,
0.013041702099144459,
-0.00021314113109838217,
0.025609470903873444,
-0.00500399898737669,
-0.007897639647126198,
0.03150113672018051,
-0.006248805206269026,
-0.007569304667413235,
0.009468715637922287,
-0.01162498164921999,
-0.016631411388516426,
-0.013284172862768173,
-0.01170668937265873,
-0.01207974087446928,
0.012845136225223541,
0.015708046033978462,
0.019632695242762566,
0.035907529294490814,
0.017568815499544144,
-0.03661676123738289,
0.017057448625564575,
0.013541514985263348,
0.008426050655543804,
-0.02073071338236332,
-0.03981120139360428,
0.003847688902169466,
0.02421651966869831,
0.013442721217870712,
0.02414797432720661,
-0.017633726820349693,
-0.00129196816124022,
0.014424331486225128,
-0.029225923120975494,
-0.01819511502981186,
0.004258718807250261,
0.009793863631784916,
-0.001846998929977417,
0.02816125750541687,
-0.004717707168310881,
-0.007064108271151781,
0.02337322011590004,
0.016955936327576637,
-0.03629622980952263,
-0.010368277318775654,
0.01625213399529457,
0.012385637499392033,
-0.01905546337366104,
-0.02230428159236908,
-0.025008657947182655,
0.0043859719298779964,
-0.0426778718829155,
-0.016108598560094833,
0.054156046360731125,
0.02310306392610073,
0.011929920874536037,
-0.0033250206615775824,
0.0058356719091534615,
0.02111941948533058,
-0.016994550824165344,
-0.00793027225881815,
-0.030047912150621414,
-0.01886482909321785,
0.010549231432378292,
-0.030435403808951378,
-0.005116379354149103,
-0.0030007967725396156,
-0.013014737516641617,
-0.0229457076638937,
0.0020642520394176245,
0.010443540289998055,
-0.017975255846977234,
-0.00532116461545229,
0.006436469964683056,
0.011228703893721104,
0.010528885759413242,
-0.009105239994823933,
-0.0037111262790858746,
0.006751918233931065,
-0.005279960576444864,
-0.015850622206926346,
-0.0036323205567896366,
-0.001349318423308432,
0.004030478186905384,
-0.025901203975081444,
-0.0077458396553993225,
-0.01636066660284996,
-0.0005360550130717456,
0.009226430207490921,
-0.028887493535876274,
0.011851412244141102,
0.006193510256707668,
0.006969667039811611,
0.01396389864385128,
0.01982787810266018,
-0.00849196221679449,
0.00845321360975504,
-0.004928122274577618,
-0.0143375713378191,
-0.01623457297682762,
-0.002771303988993168,
0.007086068857461214,
-0.006562159396708012,
0.008962183259427547,
0.0066426643170416355,
-0.006105553824454546,
0.03925621882081032,
-0.019376832991838455,
-0.011128530837595463,
0.013853898271918297,
0.002551091369241476,
0.017968731001019478,
-0.0024097254499793053,
-0.007382078096270561,
-0.03226422145962715,
-0.029826657846570015,
-0.010014234110713005,
0.03487050533294678,
-0.009400464594364166,
0.054025012999773026,
0.0010828281519934535,
-0.025946004316210747,
-0.011325772851705551,
0.005311326589435339,
-0.015205181203782558,
-0.0025925084482878447,
0.003026938997209072,
0.01294801663607359,
-0.006791997235268354,
-0.012821142561733723,
0.00012662814697250724,
-0.0073129259981215,
-0.009326519444584846,
0.01844993606209755,
-0.05082114785909653,
0.009247452020645142,
-0.028309639543294907,
0.0030064040329307318,
-0.008010946214199066,
-0.018413793295621872,
-0.010500255972146988,
0.03838718682527542,
-0.0035608140751719475,
-0.013400266878306866,
0.0026762960478663445,
-0.00012739650264848024,
-0.00256354664452374,
-0.008462175726890564,
-0.0012864432064816356,
-0.006920382380485535,
-0.025995658710598946,
-0.05010654032230377,
0.02570343017578125,
-0.026759633794426918,
0.02536141127347946,
0.01996365562081337,
0.010405950248241425,
0.010268373414874077,
0.023249607533216476,
0.028063565492630005,
-0.008820570074021816,
0.015140854753553867,
0.015799392014741898,
0.018052252009510994,
0.00818005483597517,
0.0078755933791399,
-0.002435831120237708,
-0.010236259549856186,
-0.022286633029580116,
-0.03892848268151283,
-0.024949243292212486,
-0.005545887164771557,
0.0014623525785282254,
0.013676806353032589,
0.0006419381825253367,
0.01443490944802761,
-0.0013684863224625587,
-0.004648935049772263,
0.019685573875904083,
0.022205594927072525,
0.013963202014565468,
0.011945800855755806,
0.025619424879550934,
-0.0017936988733708858,
-0.012626959942281246,
0.029089266434311867,
0.04986928775906563,
-0.00686182314530015,
0.008628392592072487,
0.016413016244769096,
-0.016443515196442604,
0.0042232321575284,
0.016962364315986633,
-0.025175705552101135,
0.004337606020271778,
0.008778992109000683,
0.024445153772830963,
-0.003153246594592929,
-0.0033546611666679382,
-0.012038389220833778,
-0.0437476709485054,
-0.02116728574037552,
-0.01783238723874092,
-0.005199573002755642,
0.00425472529605031,
0.0020677826832979918,
0.02474804036319256,
-0.0186520554125309,
0.00589508144184947,
0.0010027840035036206,
0.010387971065938473,
0.004354474134743214,
-0.01499346736818552,
0.003492858959361911,
0.0214419923722744,
-0.024341944605112076,
0.017816396430134773,
-0.0007968067657202482,
0.018339134752750397,
-0.003477180376648903,
-0.007327638100832701,
0.006265087053179741,
0.015149329788982868,
0.021174628287553787,
0.008091256953775883,
0.040374595671892166,
-0.044660426676273346,
0.030368657782673836,
-0.0212958212941885,
-0.012336552143096924,
0.002881837310269475,
-0.020163260400295258,
0.023715386167168617,
-0.0022317885886877775,
0.011263648979365826,
0.011431431397795677,
0.0015566111542284489,
0.003722055582329631,
-0.015504402108490467,
0.014079390093684196,
-0.009353280998766422,
-0.0025610034354031086,
-0.006332673132419586,
0.017895087599754333,
0.010347357951104641,
0.008181005716323853,
0.008511088788509369,
-0.03135564550757408,
0.0021915812976658344,
-0.0013077018084004521,
-0.020295847207307816,
-0.05839405581355095,
0.010778860189020634,
-0.003640251699835062,
0.04040920361876488,
-0.011329918168485165,
-0.005424754228442907,
0.0022185822017490864,
-0.002929029520601034,
0.01364901289343834,
-0.005357577931135893,
0.009881800040602684,
0.0011139785638079047,
0.007987718097865582,
-0.022722626104950905,
0.024847935885190964,
-0.003805499989539385,
0.022934963926672935,
-0.004539806861430407,
-0.008911527693271637,
-0.0077394768595695496,
0.019318297505378723,
-0.008531888946890831,
-0.0050878021866083145,
-0.015879150480031967,
-0.013111806474626064,
-0.015150787308812141,
0.0011820533545687795,
-0.00921823550015688,
-0.024249015375971794,
-0.01957119256258011,
-0.009061440825462341,
0.005590973421931267,
-0.013692276552319527,
-0.004974930081516504,
0.0030446399468928576,
-0.009725012816488743,
0.0038442325312644243,
-0.020154641941189766,
-0.015475950203835964,
0.01164847332984209,
0.004908865317702293,
0.02131367102265358,
-0.007282488513737917,
-0.003141608787700534,
-0.0002882826665882021,
0.002675734693184495,
0.023224949836730957,
-0.05122758448123932,
0.011732236482203007,
-0.01685958169400692,
-0.005367038305848837,
0.017677266150712967,
0.0075306068174541,
0.03210068121552467,
-0.01574545167386532,
0.05666132643818855,
0.015496250241994858,
-0.03350239619612694,
0.014043631963431835,
-0.01330263540148735,
0.009490648284554482,
0.03133629634976387,
0.008609861135482788,
0.0326240174472332,
0.00384370144456625,
0.017731457948684692,
-0.0065612089820206165,
0.02270984649658203,
-0.0014008873840793967,
0.001945983967743814,
-0.01712251454591751,
0.019035903736948967,
0.02847222238779068,
-0.029702698811888695,
0.001937167253345251,
0.021272683516144753,
0.00215652072802186,
-0.008537568151950836,
0.014528275467455387,
-0.004638359881937504,
-0.001567855360917747,
-0.03383719176054001,
0.030389655381441116,
0.0033583396580070257,
-0.016042735427618027,
-0.011452390812337399,
0.016040222719311714,
0.0044136508367955685,
-0.002715551760047674,
0.008463315665721893,
0.024042343720793724,
0.007666788529604673,
0.019021041691303253,
0.007567938417196274,
-0.0472085066139698,
0.0029072919860482216,
-0.022805748507380486,
-0.009412117302417755,
0.01975945197045803,
0.018742403015494347,
0.0004573224578052759,
0.042877014726400375,
0.003213561838492751,
0.04274033010005951,
0.02276219055056572,
-0.018035154789686203,
-0.010103224776685238,
-0.01144106313586235,
0.017269192263484,
0.01212848350405693,
-0.014448151923716068,
0.0143289091065526,
-0.004347191192209721,
0.0375937819480896,
-0.04313474893569946,
0.00913371704518795,
-0.03328561410307884,
-0.0032295577693730593,
0.019037436693906784,
0.01707562804222107,
-0.05458947271108627,
-0.012982746586203575,
0.0015062650199979544,
0.004595462698489428,
-0.02654838189482689,
-0.003985904622823,
0.02022746577858925,
0.01792188175022602,
-0.017072416841983795,
0.0025601480156183243,
-0.017359448596835136,
-0.0163070410490036,
-0.023151811212301254,
0.020325016230344772,
0.02165132202208042,
-0.013444392010569572,
-0.005585528910160065,
0.011346438899636269,
0.022228065878152847,
-0.00527608348056674,
0.011363483034074306,
-0.028824588283896446,
-0.00023099589452613145,
0.015833916142582893,
-0.008317271247506142,
0.01097641047090292,
0.029668807983398438,
-0.007950715720653534,
0.0010407187510281801,
0.01600688137114048,
-0.0075800116173923016,
-0.017416292801499367,
-0.050069887191057205,
0.021362118422985077,
0.034945160150527954,
-0.009500875137746334,
0.024604013189673424,
0.0008898665546439588,
0.01932246796786785
] |
8a258262e455109304caf1e67879b046459ff1bf | 5,066 | py | Python | aws-regions.py | groorj/cloud-regions | f085491c71440d99000ad29a885e6090dfc9332a | [
"MIT"
] | null | null | null | aws-regions.py | groorj/cloud-regions | f085491c71440d99000ad29a885e6090dfc9332a | [
"MIT"
] | 1 | 2021-07-22T01:25:14.000Z | 2021-07-22T17:29:09.000Z | aws-regions.py | groorj/cloud-regions | f085491c71440d99000ad29a885e6090dfc9332a | [
"MIT"
] | null | null | null | import json
import logging
import os
import inspect
import urllib
import urllib.request
from urllib.error import HTTPError
# logger
logger = logging.getLogger()
logger_level = logging.getLevelName(os.environ['LOGGER_LEVEL'])
logger.setLevel(logger_level)
# validate access
def validate_access(event, context):
logger.debug("Inside function: [%s]", inspect.currentframe().f_code.co_name)
logger.debug("RESTRICTED_ACCESS_ENABLED: [%s]", os.environ['RESTRICTED_ACCESS_ENABLED'])
error_message = "You are not allowed, get out!"
if os.environ['RESTRICTED_ACCESS_ENABLED'] == 'true':
logger.info("Restricted access is enabled")
logger.info("Value for header [%s] is: [%s]", os.environ['RESTRICTED_ACCESS_HTTP_HEADER'], event["headers"][os.environ['RESTRICTED_ACCESS_HTTP_HEADER']])
if event["headers"][os.environ['RESTRICTED_ACCESS_HTTP_HEADER']] != os.environ['RESTRICTED_ACCESS_SECRET']:
logger.info("Key provided is not valid")
logger.debug("Error: [%s]", error_message)
http_code = 403
raise ValueError(http_code, error_message)
else:
logger.info("Key provided is valid")
else:
logger.info("Restricted access is NOT enabled")
# create response
def create_response_new(status_code, message_body):
logger.debug("Inside function: [%s]", inspect.currentframe().f_code.co_name)
return {
'statusCode': str(status_code),
'body': json.dumps(message_body),
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
# download json file
def get_json():
logger.debug("Inside function: [%s]", inspect.currentframe().f_code.co_name)
try:
response = urllib.request.urlopen(os.environ['AWS_REGIONS_JSON_URL'])
except HTTPError as err:
# catch HTTP error
logger.debug("HTTP error: [%s]", err)
raise
json_data = json.loads(response.read())
return json_data
# entry point -> return region info
def get_region_info(event, context):
logger.debug("Inside function: [%s]", inspect.currentframe().f_code.co_name)
return_info_final = {}
# validate the access to this resource
try:
validate_access(event, context)
except ValueError as err:
return_info_final['request'] = { "request_status": "Fail", "error_message": err.args[1], "http_error_code": err.args[0] }
return create_response_new(err.args[0], return_info_final)
# get region info
region_code = event['pathParameters']['region_code']
logger.debug("region_code: [%s]", region_code)
try:
json_data = get_json()
except HTTPError as err:
# http_code = err.code
http_code = 500
return_info_final['request'] = { "request_status": "Fail", "error_message": "Error getting Regions information.", "http_error_code": err.code }
return create_response_new(http_code, return_info_final)
# logger.debug("json_data: [%s]", json_data)
# logger.debug("type(json_data): [%s]", type(json_data))
for element in json_data['data']:
# logger.debug("code: [%s] && region_code: [%s]", element['code'], region_code)
if element['code'] == region_code:
logger.info("region_code found")
http_code = 200
return_info_final['request'] = { "request_status": "Success" }
return_info_final['info'] = json_data['info']
return_info_final['data'] = element
break
else:
logger.info("region_code NOT found")
return_info = "Region code NOT found."
http_code = 404
return_info_final['request'] = { "request_status": "Fail", "error_message": "Region code NOT found.", "http_error_code": http_code }
return create_response_new(http_code, return_info_final)
# entry point -> return region info
def get_all_regions_info(event, context):
logger.debug("Inside function: [%s]", inspect.currentframe().f_code.co_name)
return_info_final = {}
# validate the access to this resource
try:
validate_access(event, context)
except ValueError as err:
return_info_final['request'] = { "request_status": "Fail", "error_message": err.args[1], "http_error_code": err.args[0] }
return create_response_new(err.args[0], return_info_final)
# get regions info
try:
json_data = get_json()
except HTTPError as err:
# http_code = err.code
http_code = 500
return_info_final['request'] = { "request_status": "Fail", "error_message": "Error getting Regions information.", "http_error_code": err.code }
return create_response_new(http_code, return_info_final)
logger.debug("json_data: [%s]", json_data)
http_code = 200
return_info_final['request'] = { "request_status": "Success" }
return_info_final['info'] = json_data['info']
return_info_final['data'] = json_data['data']
return create_response_new(http_code, return_info_final)
# End; | 41.867769 | 161 | 0.66443 | 1 | 1.9911 | [
-0.05630538612604141,
0.04793161153793335,
-0.004440839868038893,
-0.005217285361140966,
-0.0018268667627125978,
0.019526783376932144,
-0.08700791001319885,
-0.020323054865002632,
-0.018681911751627922,
0.03709304332733154,
-0.005490723066031933,
-0.03706176578998566,
0.01122251059859991,
-0.02427821420133114,
0.022338369861245155,
-0.020721085369586945,
0.15459784865379333,
-0.040295958518981934,
-0.01951991394162178,
0.020673906430602074,
0.03782865032553673,
0.02532658912241459,
0.007073407992720604,
0.006427114363759756,
0.022671140730381012,
0.03320297598838806,
0.04062199592590332,
-0.041389916092157364,
0.0013351888628676534,
-0.04354241490364075,
0.011559825390577316,
0.04800620675086975,
-0.05862068757414818,
0.00047273520613089204,
-0.022032177075743675,
0.02686896361410618,
0.006720215082168579,
-0.06330835819244385,
0.03168034553527832,
0.011331276036798954,
-0.07717903703451157,
-0.014071248471736908,
-0.02109934575855732,
0.055279191583395004,
0.03339041396975517,
0.005543261766433716,
-0.03899369016289711,
0.03514225780963898,
-0.05091121420264244,
0.0014202144229784608,
0.005514085292816162,
-0.005232825409621,
-0.00009370871703140438,
-0.037309687584638596,
-0.030242588371038437,
-0.023992151021957397,
0.04285559803247452,
0.045454517006874084,
-0.03878346085548401,
0.04592333734035492,
-0.02000816911458969,
0.006220971699804068,
0.0413285531103611,
0.025899210944771767,
0.010391900315880775,
0.017613183706998825,
-0.0016230784822255373,
0.004030874464660883,
0.023275794461369514,
-0.020486749708652496,
-0.016715126112103462,
-0.030230730772018433,
-0.04190906509757042,
-0.0007708842749707401,
0.04638966545462608,
-0.035898927599191666,
0.004746731836348772,
-0.0418170690536499,
-0.03966124355792999,
0.0024269381538033485,
-0.027120256796479225,
0.07955748587846756,
0.004252052400261164,
-0.020182961598038673,
0.005507196765393019,
0.03773900121450424,
0.07019249349832535,
-0.07130756974220276,
0.028899459168314934,
0.03676718473434448,
-0.043637964874506,
0.015959346666932106,
-0.03192855045199394,
-0.029153669252991676,
-0.014753632247447968,
-0.06129416823387146,
0.007111675105988979,
0.01596147008240223,
0.013607585802674294,
0.038697775453329086,
0.00859682448208332,
-0.004614726640284061,
-0.021080972626805305,
0.017244424670934677,
-0.020157739520072937,
0.015760527923703194,
-0.09285681694746017,
-0.04398530349135399,
-0.015713417902588844,
-0.04436016455292702,
0.0016762872692197561,
0.03501085937023163,
-0.01246207021176815,
-0.012450373731553555,
0.0018929257057607174,
-0.0273138340562582,
0.017467649653553963,
0.04991917312145233,
-0.0033939052373170853,
-0.006066824775189161,
-0.0029974968638271093,
0.040404062718153,
-0.0009087045327760279,
-0.05623143911361694,
-0.013912925496697426,
0.08291450142860413,
-0.016245050355792046,
0.035255156457424164,
0.03871249407529831,
-0.009190218523144722,
0.008435036055743694,
0.010070365853607655,
-0.020665479823946953,
0.02095007337629795,
0.038636017590761185,
0.0015304620610550046,
0.01257250178605318,
0.009104459546506405,
-0.01966068148612976,
0.03538765385746956,
-0.01924624852836132,
-0.013658738695085049,
0.003167640883475542,
-0.03737085685133934,
0.012018098495900631,
-0.04053156450390816,
0.041887667030096054,
-0.03725463151931763,
0.010711219161748886,
-0.018455779179930687,
0.008051752112805843,
0.0230381079018116,
-0.008475977927446365,
0.03541441261768341,
-0.06754352897405624,
-0.004312995821237564,
-0.02245139516890049,
-0.014580262824892998,
0.003114912658929825,
0.02827109582722187,
-0.06739194691181183,
0.03497370332479477,
0.0005530661437660456,
0.04440920799970627,
0.010375011712312698,
0.0026601350400596857,
-0.023548712953925133,
0.03900193050503731,
0.03101813979446888,
0.03969704359769821,
-0.035762302577495575,
-0.027738317847251892,
-0.0580219030380249,
0.022051965817809105,
-0.0020927097648382187,
0.0039035682566463947,
0.03856981545686722,
0.000006369461061694892,
-0.010111710987985134,
-0.03570479527115822,
0.011342557147145271,
-0.05899603292346001,
-0.03096422180533409,
-0.019589336588978767,
0.007359342183917761,
-0.02356712333858013,
-0.0650184229016304,
-0.0037437283899635077,
0.012236971408128738,
0.006694352719932795,
0.01744394563138485,
0.005744201131165028,
-0.02094905450940132,
-0.04342234507203102,
-0.007881006225943565,
0.002162664895877242,
0.005997025407850742,
-0.007061529438942671,
-0.0001163699125754647,
-0.05318368226289749,
-0.024765461683273315,
0.018645083531737328,
-0.04897639527916908,
-0.013950994238257408,
0.010305927135050297,
0.012720389291644096,
-0.5085656046867371,
0.04768096283078194,
-0.04547172039747238,
-0.006704846862703562,
0.02059830166399479,
0.01577325351536274,
0.00038295076228678226,
0.031870488077402115,
-0.04050351306796074,
0.0004279838176444173,
0.006903357803821564,
0.0037280390970408916,
0.0022193784825503826,
-0.022695258259773254,
0.02944285050034523,
-0.011340266093611717,
0.008081638254225254,
-0.026385528966784477,
-0.05314581096172333,
0.0005549059133045375,
0.01621607318520546,
-0.08985787630081177,
-0.010605933144688606,
0.0072075072675943375,
0.039434030652046204,
-0.00035205090534873307,
0.05397218093276024,
0.01098018791526556,
-0.06078650429844856,
-0.01149214617908001,
-0.0384480319917202,
0.021298782899975777,
0.024638911709189415,
0.014033363200724125,
-0.02933673746883869,
0.016115644946694374,
0.016877109184861183,
-0.0519125871360302,
-0.06911899149417877,
0.0004922990337945521,
-0.028996439650654793,
-0.002517229411751032,
0.030624831095337868,
-0.04627951607108116,
-0.04007820039987564,
-0.006553167011588812,
0.02410108782351017,
0.03700121492147446,
0.004281608387827873,
0.049949608743190765,
-0.03630676493048668,
-0.022490162402391434,
0.05108644813299179,
-0.037057314068078995,
-0.033693477511405945,
-0.004704848863184452,
-0.026003306731581688,
0.005496767349541187,
-0.03542123734951019,
-0.0010893859434872866,
0.004682477563619614,
-0.022443728521466255,
-0.05372573435306549,
-0.01271053683012724,
0.07134436070919037,
-0.004843130707740784,
0.04808743670582771,
-0.02715982124209404,
-0.02047679014503956,
0.0742887631058693,
-0.046875592321157455,
0.04805106297135353,
-0.05260752514004707,
0.04006213694810867,
-0.018449019640684128,
0.053797222673892975,
-0.021671319380402565,
-0.002737172180786729,
-0.09307438135147095,
-0.0070456406101584435,
-0.0342705175280571,
-0.01791858859360218,
0.0012248590355738997,
-0.006187354680150747,
-0.007523012347519398,
-0.01669074036180973,
-0.025066299363970757,
-0.0164363831281662,
-0.006060317624360323,
0.024652743712067604,
-0.000014381595065060537,
0.03514508530497551,
-0.02460538037121296,
0.02712792344391346,
0.030580246821045876,
0.034609194844961166,
-0.00337805668823421,
0.03463905304670334,
0.019180726259946823,
0.005584722384810448,
-0.07208916544914246,
-0.02691725268959999,
0.01527461875230074,
0.019825290888547897,
0.005890220403671265,
-0.00997235719114542,
-0.04895421862602234,
0.0033485088497400284,
0.02904263511300087,
-0.045142341405153275,
-0.023175429552793503,
0.0034506581723690033,
-0.014279406517744064,
0.04329119250178337,
-0.01728181540966034,
0.01773461140692234,
-0.039110422134399414,
-0.01903010532259941,
0.035716596990823746,
-0.023032506927847862,
0.004158218391239643,
0.0376054085791111,
0.05337764695286751,
-0.0263394545763731,
0.014982826076447964,
-0.02738426998257637,
-0.023012440651655197,
-0.0017552475910633802,
0.02071305923163891,
-0.01654120348393917,
-0.035404812544584274,
-0.014774664305150509,
0.03327716141939163,
0.05228105187416077,
-0.015631387010216713,
0.014069316908717155,
-0.02591349184513092,
-0.04313197359442711,
0.005354938097298145,
-0.018923120573163033,
-0.011272550560534,
-0.007292426191270351,
0.01047807652503252,
-0.030087588354945183,
0.032908711582422256,
0.05082213133573532,
-0.025774134323000908,
-0.02606048248708248,
-0.012524323537945747,
-0.08870051056146622,
-0.03352588415145874,
0.06147901341319084,
-0.002797568216919899,
-0.037923771888017654,
-0.027295351028442383,
-0.022936508059501648,
0.013904605060815811,
0.043129414319992065,
0.014602391049265862,
-0.038098402321338654,
0.00014886971621308476,
-0.021713081747293472,
0.020832551643252373,
-0.0028218103107064962,
0.02022564969956875,
-0.02013062685728073,
-0.01432021614164114,
-0.03819311782717705,
-0.01214868575334549,
0.045533064752817154,
0.021473076194524765,
0.024982333183288574,
0.03736349940299988,
0.006553974933922291,
0.025677451863884926,
0.016375204548239708,
-0.0001373170962324366,
-0.08781826496124268,
0.01888246089220047,
0.0003709920565597713,
-0.00042606002534739673,
0.0336381271481514,
0.006877042353153229,
0.040534790605306625,
-0.005910233594477177,
-0.010518328286707401,
-0.029870692640542984,
-0.000526600459124893,
0.02050301991403103,
0.002032878343015909,
0.024554364383220673,
0.06313759833574295,
0.00991516187787056,
-0.005435632076114416,
-0.002724807010963559,
-0.035787224769592285,
0.046380724757909775,
-0.05773470178246498,
-0.015738900750875473,
-0.031956758350133896,
0.016173072159290314,
-0.00179687247145921,
0.006536731030791998,
-0.01665106974542141,
0.01654691994190216,
0.006454695947468281,
0.02375737577676773,
0.026438966393470764,
0.0003519527381286025,
-0.03366725891828537,
0.0301615372300148,
-0.0142900999635458,
0.04271147400140762,
0.04730375111103058,
-0.014786536805331707,
0.04693242534995079,
-0.07012084871530533,
-0.04383312538266182,
0.02184479311108589,
-0.0036452366039156914,
-0.028494570404291153,
-0.04613417014479637,
-0.005272285547107458,
0.02702387608587742,
-0.03692487254738808,
-0.02920280396938324,
-0.006102483253926039,
0.0019079920602962375,
-0.0371234193444252,
0.0070195067673921585,
0.03111501783132553,
0.016485532745718956,
-0.021251922473311424,
-0.013452533632516861,
-0.005171215161681175,
0.016123091802001,
-0.03251223266124725,
-0.034671600908041,
0.009016021154820919,
0.03077494353055954,
-0.002522475551813841,
-0.03243108093738556,
0.024679405614733696,
0.0021801094990223646,
0.029057800769805908,
-0.02666153386235237,
-0.0027408197056502104,
-0.06006573885679245,
-0.011255715973675251,
0.02129357121884823,
-0.005939783062785864,
-0.00029952736804261804,
0.03515966609120369,
-0.03532392531633377,
0.02442021667957306,
-0.0023027234710752964,
-0.008143508806824684,
0.04885910823941231,
-0.019162151962518692,
-0.01990051381289959,
-0.022804124280810356,
-0.0016500470228493214,
0.03720269724726677,
0.0433213897049427,
-0.04999752342700958,
0.014372787438333035,
0.024992600083351135,
0.0026508315932005644,
-0.02288561873137951,
0.02593608945608139,
-0.007270888425409794,
-0.010214021429419518,
-0.025866758078336716,
0.016408054158091545,
0.05305871367454529,
0.017465107142925262,
-0.014901441521942616,
0.012649321928620338,
0.0108217503875494,
-0.0032028567511588335,
0.00537238921970129,
-0.018195252865552902,
0.0500190295279026,
0.03645970672369003,
-0.004900265019387007,
-0.0014493491034954786,
0.05152517557144165,
0.020129328593611717,
-0.05330485850572586,
-0.024191834032535553,
-0.008404921740293503,
-0.031214484944939613,
0.08786122500896454,
-0.010357405059039593,
0.008344539441168308,
0.016353482380509377,
0.016943493857979774,
-0.03690919652581215,
-0.012241534888744354,
-0.055843111127614975,
0.004696195479482412,
-0.011583731509745121,
-0.013960764743387699,
0.0074112191796302795,
0.033600762486457825,
0.0032887556590139866,
0.06772914528846741,
-0.0018854918889701366,
0.022335318848490715,
-0.011509643867611885,
0.04621472209692001,
0.022257020696997643,
-0.007898141629993916,
-0.016049131751060486,
0.05821637809276581,
0.029117994010448456,
0.04949624463915825,
-0.04401405528187752,
0.01075007300823927,
0.0106632886454463,
-0.030265819281339645,
-0.0032158109825104475,
-0.015404636040329933,
0.0007585205603390932,
0.015528980642557144,
0.010618293657898903,
-0.027723517268896103,
-0.014301631599664688,
-0.02425270713865757,
0.052817318588495255,
-0.008606732822954655,
-0.05084319785237312,
-0.0021035841200500727,
0.0045670634135603905,
-0.002662412356585264,
-0.034434814006090164,
-0.004419916309416294,
-0.01603400893509388,
-0.029715832322835922,
0.057901300489902496,
-0.01763872057199478,
0.0032996106892824173,
0.0016174742486327887,
-0.07082047313451767,
0.01170235127210617,
0.013911102898418903,
0.06802146881818771,
-0.047449883073568344,
0.017186013981699944,
0.0028685959987342358,
0.01076342724263668,
-0.018444376066327095,
0.022082587704062462,
-0.008331804536283016,
-0.0059013040736317635,
-0.017901191487908363,
-0.014383065514266491,
-0.0035529800225049257,
-0.002064324449747801,
-0.0048323203809559345,
-0.03701985254883766,
0.023683367297053337,
-0.008070753887295723,
0.0033348905853927135,
-0.014934341423213482,
-0.007200553081929684,
0.018093915656208992,
0.0006887079798616469,
0.000807720236480236,
0.009991577826440334,
-0.007232086267322302,
0.002189930295571685,
0.06156475841999054,
0.036692921072244644,
-0.011275086551904678,
0.019737452268600464,
0.008990337140858173,
0.002842121059074998,
-0.03173160180449486,
-0.012464141473174095,
-0.08446217328310013,
-0.04567230865359306,
0.0077523947693407536,
-0.035883959382772446,
0.0006465312326326966,
-0.015472711995244026,
-0.03232160583138466,
0.06979010999202728,
-0.036915481090545654,
-0.01907125860452652,
0.0405745767056942,
0.0024752644822001457,
-0.0327179990708828,
0.022690538316965103,
-0.028881417587399483,
0.003467512084171176,
-0.057396288961172104,
-0.023489659652113914,
-0.015487205237150192,
0.029841288924217224,
-0.02455296739935875,
0.002733405912294984,
0.05434760823845863,
-0.02967844530940056,
0.02363891713321209,
-0.05116039514541626,
-0.003448519157245755,
-0.010669143870472908,
-0.025116268545389175,
-0.014927337877452374,
0.0031138851772993803,
0.005951831117272377,
-0.013182674534618855,
0.0012977744918316603,
0.03052380494773388,
0.008215821348130703,
-0.040131375193595886,
0.015261988155543804,
-0.014416990801692009,
0.05244175344705582,
-0.04900074005126953,
0.037985943257808685,
0.010162505321204662,
0.012015446089208126,
0.010147918947041035,
-0.008312657475471497,
0.011712124571204185,
0.03652533143758774,
0.007480837404727936,
0.02025969699025154,
-0.0007455961895175278,
0.04471477121114731,
0.023153100162744522,
0.08150281012058258,
0.005103417206555605,
-0.009787816554307938,
-0.03157865256071091,
0.03976784646511078,
0.027706027030944824,
-0.011993596330285072,
0.016837552189826965,
0.0145353302359581,
-0.010052687488496304,
0.017449958249926567,
0.011428765021264553,
-0.04431023821234703,
0.018020445480942726,
-0.026256071403622627,
-0.00944366492331028,
-0.013465456664562225,
-0.008477196097373962,
0.005925722885876894,
0.011592989787459373,
0.036708537489175797,
0.00970614142715931,
0.014640910550951958,
0.001947632059454918,
0.001944140181876719,
0.02707485854625702,
-0.0037258241791278124,
0.05248231068253517,
0.0017983532743528485,
0.025539878755807877,
0.05402970686554909,
0.011412916705012321,
0.016588615253567696,
0.012687025591731071,
-0.016554994508624077,
-0.012738540768623352,
0.034452732652425766,
0.008440941572189331,
0.012458723038434982,
0.0029730447567999363,
0.007847587577998638,
-0.016656268388032913,
0.013842710293829441,
-0.0016536914044991136,
-0.03793341666460037,
0.07102224975824356,
0.011280432343482971,
0.04520169645547867,
-0.0034940149635076523,
0.003493952564895153,
0.04512782394886017,
0.015071253292262554,
0.01725698448717594,
0.005284951534122229,
0.033969391137361526,
0.0007321674493141472,
0.024947024881839752,
-0.06242351606488228,
-0.031531915068626404,
-0.026143494993448257,
0.026136819273233414,
-0.016127662733197212,
-0.02207234501838684,
0.028349850326776505,
0.02242850326001644,
0.07106413692235947,
-0.021377522498369217,
0.03642445430159569,
0.007602265570312738,
0.012642341665923595,
-0.00844910740852356,
0.0444062203168869,
0.02136852964758873,
0.04344206675887108,
-0.00945587083697319,
0.002090837573632598,
-0.025028381496667862,
-0.028392750769853592,
0.02083299122750759,
0.00880797952413559,
0.06157862767577171,
0.04378092288970947,
0.015839194878935814,
0.06813213974237442,
-0.011988997459411621,
0.004120623227208853,
-0.03837525099515915,
0.029035232961177826,
-0.01826579123735428,
-0.00272272527217865,
-0.00469761248677969,
-0.015479600988328457,
0.019204994663596153,
-0.07350371778011322,
-0.026106545701622963,
-0.04278562590479851,
-0.018713712692260742,
0.002283150563016534,
0.03042357601225376,
-0.02095063030719757,
-0.001272437279112637,
-0.0010694266529753804,
-0.027597501873970032,
0.009742173366248608,
0.04648521915078163,
-0.004389793146401644,
-0.04820062220096588,
0.034153662621974945,
0.017660802230238914,
-0.009484919719398022,
-0.016300465911626816,
-0.023689331486821175,
0.023422131314873695,
0.008390171453356743,
-0.047679461538791656,
0.02962173894047737,
-0.03479459509253502,
0.026235321536660194,
-0.0008613349637016654,
0.01787736266851425,
-0.0011935526272282004,
-0.03426468372344971,
-0.056891486048698425,
-0.00550801120698452,
0.07770729809999466,
-0.02129543386399746,
-0.055038806051015854,
-0.03364419564604759,
0.023318760097026825
] |
8a267a4563f9753a8ce7cda07a22ac19aca67d1a | 10,157 | py | Python | src/models/encoder.py | guowenying111/SEKE | a913a19090eb690c3188036795559210a5262f2b | [
"Apache-2.0"
] | null | null | null | src/models/encoder.py | guowenying111/SEKE | a913a19090eb690c3188036795559210a5262f2b | [
"Apache-2.0"
] | null | null | null | src/models/encoder.py | guowenying111/SEKE | a913a19090eb690c3188036795559210a5262f2b | [
"Apache-2.0"
] | null | null | null | import math
import torch
import torch.nn as nn
from models.neural import MultiHeadedAttention, PositionwiseFeedForward
from models.rnn import LayerNormLSTM
class Classifier(nn.Module):
def __init__(self, hidden_size):
super(Classifier, self).__init__()
self.linear1 = nn.Linear(hidden_size, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x, mask_cls):
h = self.linear1(x).squeeze(-1)
sent_scores = self.sigmoid(h) * mask_cls.float()
return sent_scores
class PositionalEncoding(nn.Module):
def __init__(self, dropout, dim, max_len=5000):
pe = torch.zeros(max_len, dim)
position = torch.arange(0, max_len).unsqueeze(1)
div_term = torch.exp((torch.arange(0, dim, 2, dtype=torch.float) *
-(math.log(10000.0) / dim)))
pe[:, 0::2] = torch.sin(position.float() * div_term)
pe[:, 1::2] = torch.cos(position.float() * div_term)
pe = pe.unsqueeze(0)
super(PositionalEncoding, self).__init__()
self.register_buffer('pe', pe)
self.dropout = nn.Dropout(p=dropout)
self.dim = dim
def forward(self, emb, step=None):
emb = emb * math.sqrt(self.dim)
if (step):
emb = emb + self.pe[:, step][:, None, :]
else:
emb = emb + self.pe[:, :emb.size(1)]
emb = self.dropout(emb)
return emb
def get_emb(self, emb):
return self.pe[:, :emb.size(1)]
class TransformerEncoderLayer(nn.Module):
def __init__(self, d_model, heads, d_ff, dropout):
super(TransformerEncoderLayer, self).__init__()
self.self_attn = MultiHeadedAttention(
heads, d_model, dropout=dropout)
self.feed_forward = PositionwiseFeedForward(d_model, d_ff, dropout)
self.layer_norm = nn.LayerNorm(d_model, eps=1e-6)
self.dropout = nn.Dropout(dropout)
def forward(self, iter, query, inputs, mask):
if (iter != 0):
input_norm = self.layer_norm(inputs)
else:
input_norm = inputs
mask = mask.unsqueeze(1)
context = self.self_attn(input_norm, input_norm, input_norm,
mask=mask)
out = self.dropout(context) + inputs
return self.feed_forward(out)
class TransformerInterEncoder(nn.Module):
def __init__(self, d_model, d_ff, heads, dropout, num_inter_layers=0):
super(TransformerInterEncoder, self).__init__()
self.d_model = d_model
self.num_inter_layers = num_inter_layers
self.pos_emb = PositionalEncoding(dropout, d_model)
self.transformer_inter = nn.ModuleList(
[TransformerEncoderLayer(d_model, heads, d_ff, dropout)
for _ in range(num_inter_layers)])
self.dropout = nn.Dropout(dropout)
self.layer_norm = nn.LayerNorm(d_model, eps=1e-6)
self.wo = nn.Linear(d_model, 1, bias=True)
self.sigmoid = nn.Sigmoid()
def forward(self, top_vecs, mask):
""" See :obj:`EncoderBase.forward()`"""
batch_size, n_sents = top_vecs.size(0), top_vecs.size(1)
pos_emb = self.pos_emb.pe[:, :n_sents]
x = top_vecs * mask[:, :, None].float()
x = x + pos_emb
for i in range(self.num_inter_layers):
x = self.transformer_inter[i](i, x, x, ~mask) # all_sents * max_tokens * dim
x = self.layer_norm(x)
sent_scores = self.sigmoid(self.wo(x))
sent_scores = sent_scores.squeeze(-1) * mask.float()
return sent_scores
class GRUEncoder_attn(nn.Module):
def __init__(self,bidirectional, num_layers, input_size, hidden_size,dropout=0.0):
super(GRUEncoder_attn,self).__init__()
class RNNEncoder_attn(nn.Module):
def __init__(self, bidirectional, num_layers, input_size,
hidden_size, dropout=0.0):
super(RNNEncoder_attn, self).__init__()
num_directions = 2 if bidirectional else 1
assert hidden_size % num_directions == 0
hidden_size = hidden_size // num_directions
self.relu = nn.ReLU()
self.rnn = LayerNormLSTM(
input_size=input_size,
hidden_size=hidden_size,
num_layers=num_layers,
bidirectional=bidirectional)
self.wo = nn.Linear(num_directions * hidden_size, 1, bias=True)
self.dropout = nn.Dropout(dropout)
self.softmax = nn.Softmax()
print('this is dropout',dropout)
def forward(self, x, mask):
"""See :func:`EncoderBase.forward()`"""
batch, layer, seq, hidden = x.size()
x1=x.contiguous().view(batch * layer, -1, hidden)
x1 = torch.transpose(x1, 1, 0)
memory_bank, _ = self.rnn(x1)
memory_bank = self.dropout(memory_bank) + x1
memory_bank = torch.transpose(memory_bank, 1, 0)
# sent_scores = self.softmax(self.relu(self.wo(memory_bank)).squeeze(dim=-1)).unsqueeze(-1)
sent_scores = self.softmax(self.relu(self.wo(memory_bank[:,-1,:])).squeeze(dim=-1).view(-1,layer)).unsqueeze(-1)
x=x.transpose(1,2)
sent_vec = torch.matmul(sent_scores.transpose(1,2).unsqueeze(dim = 1).expand(batch,seq,1,layer),x)
return sent_vec.squeeze(dim = 2)
class TransformerDecoderLayer(nn.Module):
def __init__(self, d_model, heads, d_ff, dropout):
super(TransformerDecoderLayer, self).__init__()
self.self_attn = MultiHeadedAttention(
heads, d_model, dropout=dropout)
self.feed_forward = PositionwiseFeedForward(d_model, d_ff, dropout)
self.layer_norm = nn.LayerNorm(d_model, eps=1e-6)
def forward(self, iter, ent_enc, inputs, self_attn_mask=None,context_attn_mask=None):
context = self.self_attn(inputs, inputs, inputs,
mask=self_attn_mask)
dec_output = self.self_attn(
ent_enc, ent_enc, context, mask=context_attn_mask)
dec_output = self.feed_forward(dec_output)
return dec_output
class TransformerInterDecoder(nn.Module):
def __init__(self, d_model, d_ff, heads, dropout, d_hidden, num_inter_layers=0):
super(TransformerInterDecoder, self).__init__()
self.d_model = d_model
self.num_inter_layers = num_inter_layers
self.pos_emb = PositionalEncoding(dropout, d_model)
self.transformer_inter = nn.ModuleList(
[TransformerDecoderLayer(d_model, heads, d_ff, dropout)
for _ in range(num_inter_layers)])
self.dropout = nn.Dropout(dropout)
self.layer_norm = nn.LayerNorm(d_model, eps=1e-6)
self.wo = nn.Linear(d_model, d_hidden , bias=True)
self.wi = nn.Linear(d_model, d_hidden, bias=True)
self.v = nn.Linear(d_hidden, 1, bias=True)
self.LR = nn.LeakyReLU()
self.softmax = nn.Softmax(dim=-1)
def forward(self, top_vecs, inputs, mask, label_mask=None):
""" See :obj:`EncoderBase.forward()`"""
n_out = inputs.size(1)
pos_emb = self.pos_emb.pe[:, :n_out]
seq_mask=subsequent_mask(inputs)
self_attn_mask = torch.gt((~label_mask.unsqueeze(1).expand(-1, n_out, -1) + seq_mask), 0)
inputs=inputs+pos_emb
for i in range(self.num_inter_layers):
inputs = self.transformer_inter[i](i, top_vecs, inputs,self_attn_mask,~ mask.unsqueeze(1).expand(-1, n_out,-1))
scores=self.v(self.LR(
self.wo(inputs.unsqueeze(2)).expand(-1, -1, top_vecs.size(1), -1) + self.wi(top_vecs).unsqueeze(
1))).squeeze(-1)
sent_scores = self.softmax(scores)
return sent_scores
class RNNEncoder(nn.Module):
def __init__(self, bidirectional, num_layers, input_size,
hidden_size, dropout=0.0):
super(RNNEncoder, self).__init__()
num_directions = 2 if bidirectional else 1
assert hidden_size % num_directions == 0
hidden_size = hidden_size // num_directions
self.rnn = LayerNormLSTM(
input_size=input_size,
hidden_size=hidden_size,
num_layers=num_layers,
bidirectional=bidirectional)
self.wo = nn.Linear(num_directions * hidden_size, 1, bias=True)
self.dropout = nn.Dropout(dropout)
self.sigmoid = nn.Sigmoid()
def forward(self, x, mask):
"""See :func:`EncoderBase.forward()`"""
x = torch.transpose(x, 1, 0)
memory_bank, _ = self.rnn(x)
memory_bank = self.dropout(memory_bank) + x
memory_bank = torch.transpose(memory_bank, 1, 0)
sent_scores = self.sigmoid(self.wo(memory_bank))
sent_scores = sent_scores.squeeze(-1) * mask.float()
return sent_scores
class GCN(nn.Module):
def __init__(self,in_channel,out_channel,hidden_dim,drop):
super(GCN, self).__init__()
self.in_channel=in_channel
self.out_channel=out_channel
self.hidden_dim=hidden_dim
self.dropout = nn.Dropout(p=drop)
self.gcn_x_11=GCNConv(self.in_channel,self.hidden_dim)
self.gcn_x_12=GCNConv(self.hidden_dim,self.out_channel)#No.1-*2*2
# self.gcn_x_21=GCNConv(self.in_channel,self.hidden_dim)
# self.gcn_x_22=GCNConv(self.hidden_dim,self.out_channel)#No.2-*2
# self.gcn_mix=GCNConv(self.hidden_dim*2,self.hidden_dim)#No.2-*2
self.relu=nn.ReLU(inplace=True)
def forward(self, x_1, edge_index_1, edge_index_2=None,edge_weight_1=None,edge_weight_2=None):
syn=self.gcn_x_11(x_1, edge_index_1, edge_weight_1)
syn=self.relu(syn)
syn=self.dropout(syn)
syn = self.gcn_x_12(syn, edge_index_1, edge_weight_1)
syn = self.relu(syn)
syn = self.dropout(syn)
# x2 = self.gcn_x_21(x_1, edge_index_2, edge_weight_2)
# x2 = self.relu(x2)
# x2 = self.dropout(x2)
# mix = self.gcn_mix(torch.cat((syn,x2),-1), edge_index_2, edge_weight_2)
# x2 = self.gcn_x_22(mix, edge_index_2, edge_weight_2)
# syn=self.gcn_x_12(mix, edge_index_1, edge_weight_1)
# syn=self.relu(syn)
# syn=self.dropout(syn)
# x2 = self.relu(x2)
# x2 = self.dropout(x2)
return syn
| 39.065385 | 123 | 0.632962 | 1 | 2.1381 | [
0.00006681236845906824,
0.03159094229340553,
0.016702251508831978,
0.04110461473464966,
0.014041335321962833,
-0.04047567769885063,
0.0028538936749100685,
0.0027998406440019608,
-0.017725523561239243,
-0.0016530592693015933,
0.006294186692684889,
-0.005667092744261026,
0.005538384895771742,
-0.005214706528931856,
0.0006705416599288583,
-0.022110944613814354,
0.12524503469467163,
0.022366901859641075,
-0.0033358230721205473,
0.020621025934815407,
0.012878342531621456,
0.012925988994538784,
-0.009532595984637737,
0.00024289602879434824,
-0.01986696757376194,
0.0007870179833844304,
0.04845191538333893,
0.009890318848192692,
0.006833609193563461,
-0.004032410215586424,
0.006600226275622845,
0.04558481648564339,
0.02256125956773758,
0.014936087653040886,
-0.0205124169588089,
0.023905141279101372,
0.001344221062026918,
-0.0014165756292641163,
0.002023002365604043,
-0.010348213836550713,
0.001783542102202773,
-0.02939748950302601,
-0.0030216085724532604,
-0.03947853296995163,
-0.004812609404325485,
0.008558488450944424,
-0.0010677276877686381,
0.06469392031431198,
-0.03361383453011513,
0.010023316368460655,
0.01375307235866785,
0.07750772684812546,
0.019072361290454865,
0.013438330963253975,
0.020497022196650505,
-0.025236818939447403,
-0.005491189658641815,
0.007824726402759552,
-0.03047640435397625,
-0.010021290741860867,
-0.05049235373735428,
0.000052817482355749235,
0.0028772475197911263,
-0.012238465249538422,
-0.010743344202637672,
-0.018500691279768944,
-0.04091659188270569,
0.01915503852069378,
-0.028104143217206,
0.013815921731293201,
0.017188386991620064,
0.015181516297161579,
0.051921237260103226,
0.046478450298309326,
-0.001722014625556767,
0.011898699216544628,
-0.014984959736466408,
0.0021398526150733232,
-0.001013319124467671,
0.021327555179595947,
-0.039226431399583817,
0.059966497123241425,
0.010946227237582207,
0.01178224291652441,
0.011566744185984135,
-0.018893906846642494,
0.014254595153033733,
-0.013703473843634129,
0.014570103026926517,
0.012077600695192814,
-0.03976806253194809,
0.02179582603275776,
-0.052921414375305176,
0.01838727854192257,
-0.04484473541378975,
-0.06602615118026733,
0.0010758114513009787,
-0.026392897590994835,
0.010361917316913605,
0.017694827169179916,
0.0009198629413731396,
-0.015307959169149399,
0.061435066163539886,
0.002755430294200778,
0.018800660967826843,
0.01138908788561821,
-0.02621084451675415,
0.009927605278789997,
0.009229263290762901,
0.0021493034437298775,
-0.03687267377972603,
-0.00769460666924715,
0.10400552302598953,
-0.041171737015247345,
-0.02964671142399311,
-0.009580884128808975,
-0.019266633316874504,
0.0020365144591778517,
0.0009705168195068836,
0.052013952285051346,
0.021769313141703606,
-0.014950431883335114,
0.0054682171903550625,
-0.013445251621305943,
-0.014336037449538708,
0.03933815285563469,
-0.009636247530579567,
-0.004723350051790476,
0.0096170948818326,
-0.03191685676574707,
0.002063764026388526,
-0.0013248891336843371,
0.0067497738637030125,
0.007735563442111015,
-0.0005093681393191218,
-0.0319293849170208,
-0.016229428350925446,
0.007155789528042078,
-0.05395747721195221,
0.0023727649822831154,
-0.004596528131514788,
-0.03027033619582653,
0.008683696389198303,
0.0008147589978761971,
0.012191107496619225,
-0.06464570015668869,
-0.0013709294144064188,
0.0019980508368462324,
-0.02665436640381813,
-0.022501444444060326,
0.01653035543859005,
0.06821531057357788,
-0.017014911398291588,
0.011501350440084934,
-0.010069441981613636,
0.003506175009533763,
0.02081332914531231,
-0.050475820899009705,
0.00191931810695678,
0.004354643635451794,
0.0005336444010026753,
0.017079558223485947,
0.02782941609621048,
0.01499874796718359,
-0.0156190050765872,
0.013522774912416935,
0.01122236717492342,
-0.014455543830990791,
-0.009900425560772419,
0.0011048967717215419,
0.01063185092061758,
-0.0015915997792035341,
-0.02425149828195572,
0.0003570013795979321,
0.005318390671163797,
-0.01881531998515129,
0.020187178626656532,
0.027430040761828423,
-0.014378324151039124,
-0.032010458409786224,
0.01828075759112835,
-0.027296843007206917,
0.07451806217432022,
0.045446429401636124,
0.003063847543671727,
-0.02173779159784317,
-0.03877352550625801,
-0.01850799471139908,
-0.00853443332016468,
0.005160260945558548,
-0.015444383956491947,
-0.018419578671455383,
0.01729615405201912,
-0.04564071074128151,
0.013117269612848759,
-0.029822679236531258,
-0.017015326768159866,
0.02497127838432789,
0.000031726929591968656,
-0.03808923438191414,
-0.011405383236706257,
-0.0004242905415594578,
0.003268896834924817,
0.010056596249341965,
-0.017722995951771736,
0.007280468475073576,
-0.7169284224510193,
0.005687881261110306,
-0.0019661225378513336,
-0.009065228514373302,
-0.052047327160835266,
0.01785774528980255,
-0.02133854478597641,
0.012117752805352211,
-0.019655920565128326,
-0.03311195224523544,
-0.007523467764258385,
-0.0001517035998404026,
0.004412961658090353,
-0.004223878029733896,
-0.0059993816539645195,
0.00691572017967701,
0.01699935272336006,
-0.0074598281644284725,
-0.005055057350546122,
0.0345628522336483,
-0.018671486526727676,
0.0075814444571733475,
-0.0003093346022069454,
0.026470229029655457,
0.006917103659361601,
-0.01611214503645897,
0.010283038020133972,
0.001180063234642148,
-0.007755879312753677,
0.0014402820961549878,
-0.01869240403175354,
0.023874003440141678,
-0.008970729075372219,
-0.013696215115487576,
0.03765387833118439,
-0.011661017313599586,
0.025820398703217506,
-0.023978492245078087,
-0.010252321138978004,
-0.031357958912849426,
0.012229823507368565,
-0.015279622748494148,
0.00032800319604575634,
-0.01348874345421791,
-0.056010372936725616,
-0.006402839440852404,
0.03073107637465,
-0.0250861756503582,
0.0026368757244199514,
0.005287501495331526,
-0.027933716773986816,
0.029289761558175087,
0.03246241435408592,
-0.009255815297365189,
0.003183221910148859,
-0.0024476516991853714,
0.004379871301352978,
-0.032462939620018005,
-0.014310481958091259,
-0.0063331411220133305,
-0.016182642430067062,
-0.05725240334868431,
-0.012787168845534325,
-0.010860796086490154,
-0.04326678812503815,
0.01054175291210413,
0.016406122595071793,
-0.024205947294831276,
-0.015707889571785927,
0.028073253110051155,
-0.0010930524440482259,
-0.01012041699141264,
-0.05211486667394638,
0.044232118874788284,
0.023920219391584396,
-0.01856563612818718,
-0.028527606278657913,
-0.00029508682200685143,
0.025490902364253998,
-0.02196371927857399,
0.012152742594480515,
0.019294898957014084,
0.0304801594465971,
0.001616840367205441,
-0.03323249891400337,
-0.005281141493469477,
-0.017676126211881638,
0.009923776611685753,
0.008377802558243275,
0.028600560501217842,
0.004128661938011646,
0.08430127054452896,
0.013677585870027542,
0.012546869926154613,
0.02291158214211464,
0.026720596477389336,
0.019703108817338943,
0.007238640449941158,
0.0029271887615323067,
-0.01522846333682537,
-0.020479805767536163,
0.07133928686380386,
0.017784008756279945,
-0.01058202888816595,
-0.03536520525813103,
-0.00402348255738616,
0.0045674811117351055,
-0.01719437912106514,
-0.036507584154605865,
-0.037436313927173615,
0.024858511984348297,
0.0009620337514206767,
-0.024008652195334435,
0.04043837636709213,
0.04277753829956055,
-0.007036938797682524,
-0.01396208256483078,
-0.009042834863066673,
0.008061593398451805,
-0.015999309718608856,
-0.004750736989080906,
0.009923858568072319,
-0.0024605814833194017,
-0.008288263343274593,
0.01209777407348156,
0.012477681040763855,
-0.03559716418385506,
-0.011186225339770317,
0.013934280723333359,
-0.016333842650055885,
-0.032397471368312836,
0.023447996005415916,
-0.011537011712789536,
-0.0011900811223313212,
-0.0005848441505804658,
0.0013560244115069509,
0.013615869916975498,
-0.025917330756783485,
0.01659887656569481,
0.00027580317691899836,
-0.023453569039702415,
-0.025824524462223053,
0.013090427033603191,
-0.01926903985440731,
0.005755844991654158,
-0.012160172685980797,
0.005381355062127113,
0.01309630274772644,
-0.07983627915382385,
-0.02604086510837078,
0.009855207987129688,
-0.025178279727697372,
0.034237511456012726,
0.03105498105287552,
0.031026309356093407,
-0.021161401644349098,
-0.011523517780005932,
0.04839898273348808,
0.044979799538850784,
0.024740949273109436,
-0.0014115992235019803,
-0.028320342302322388,
0.012262911535799503,
0.005086240824311972,
0.010908259078860283,
-0.007261825725436211,
-0.004221437964588404,
0.036806538701057434,
-0.001689961994998157,
0.04420201852917671,
0.00474191689863801,
-0.03456674516201019,
0.014946897514164448,
0.019061971455812454,
0.03670884296298027,
0.004133397713303566,
0.005066633690148592,
-0.045806992799043655,
0.009312770329415798,
0.015828698873519897,
-0.02048327587544918,
-0.002738758223131299,
-0.018764613196253777,
0.020037155598402023,
0.01144933421164751,
0.045907143503427505,
-0.014493469148874283,
-0.013917017728090286,
-0.0011037043295800686,
-0.03189112991094589,
0.03636014088988304,
-0.02667705900967121,
-0.0217568501830101,
-0.02010694518685341,
-0.023614395409822464,
-0.0023114054929465055,
-0.02022136189043522,
0.00006466470949817449,
-0.0016952811274677515,
-0.0062911310233175755,
-0.022277789190411568,
0.04747448489069939,
0.01718916743993759,
-0.004505738150328398,
-0.02105819433927536,
0.03904621675610542,
0.027165569365024567,
-0.01868937537074089,
-0.004044875968247652,
0.0004630586481653154,
-0.028449883684515953,
-0.017782872542738914,
-0.0013005535583943129,
0.02361469902098179,
-0.013213898986577988,
-0.016918545588850975,
-0.023462550714612007,
-0.05497666075825691,
-0.02729499712586403,
-0.035756297409534454,
0.014535837806761265,
0.0034121950156986713,
0.017753683030605316,
0.015359778888523579,
-0.02046852372586727,
0.008566971868276596,
-0.00847414880990982,
0.011464736424386501,
-0.02720266580581665,
-0.0005210861563682556,
0.004175419453531504,
0.0037535245064646006,
-0.026511266827583313,
-0.014604097232222557,
-0.0010555345797911286,
0.03080659918487072,
-0.011463826522231102,
-0.027899686247110367,
0.009230447933077812,
-0.0008434882038272917,
0.02014765329658985,
-0.029297344386577606,
0.0013289081398397684,
0.022380074486136436,
-0.004969160072505474,
-0.0351540744304657,
-0.03367481753230095,
-0.020807355642318726,
-0.056532543152570724,
-0.04377195984125137,
-0.0063410233706235886,
-0.011425554752349854,
0.019689755514264107,
-0.0051081255078315735,
-0.04755440354347229,
-0.009642291814088821,
-0.03649963438510895,
-0.0074928621761500835,
0.0290896724909544,
0.023198025301098824,
-0.0014618230052292347,
-0.030423462390899658,
0.006101518403738737,
0.0023517722729593515,
-0.014127451926469803,
-0.005423724185675383,
-0.040219832211732864,
0.00823372881859541,
0.038673628121614456,
0.006414317525923252,
0.03223441541194916,
-0.03344709798693657,
0.01842588745057583,
-0.007208844646811485,
0.03129933029413223,
-0.055089615285396576,
-0.023253271356225014,
-0.0021863861475139856,
-0.048919860273599625,
0.05006781220436096,
-0.03713574633002281,
0.005145038478076458,
0.03609565272927284,
0.009323210455477238,
0.016626641154289246,
-0.0035665149334818125,
-0.05986765772104263,
0.030894452705979347,
0.005772060249000788,
-0.003607250517234206,
0.017012501135468483,
-0.03024853579699993,
0.028011610731482506,
0.02759276144206524,
0.003164793597534299,
-0.006059322506189346,
-0.01693178527057171,
-0.03029785305261612,
0.003165473463013768,
-0.020770834758877754,
0.04757039248943329,
-0.0016129132127389312,
-0.002936034230515361,
0.012091978453099728,
-0.024978257715702057,
-0.01537772361189127,
0.0009495074627920985,
0.01267800759524107,
0.027811946347355843,
0.045377783477306366,
0.009090910665690899,
-0.02421334944665432,
0.021509626880288124,
0.02091037854552269,
-0.020388072356581688,
0.008632752113044262,
0.04834837093949318,
-0.03790924325585365,
0.03362421318888664,
0.018000565469264984,
-0.019797461107373238,
-0.007449903059750795,
-0.02541682869195938,
-0.013117076829075813,
0.009403104893863201,
-0.038308218121528625,
-0.02061649225652218,
0.0037449451629072428,
0.034122101962566376,
0.026286905631422997,
0.013812562450766563,
0.02934686653316021,
0.006544785108417273,
-0.008657551370561123,
0.002042800420895219,
0.03129960596561432,
0.03297778218984604,
0.04483337700366974,
0.050926852971315384,
-0.013500367291271687,
0.03621840476989746,
-0.0068677994422614574,
-0.033126045018434525,
-0.012618208304047585,
-0.00250066164880991,
-0.028440887108445168,
-0.01701618917286396,
0.040981970727443695,
0.026044528931379318,
0.020245499908924103,
-0.04248439520597458,
-0.006405671127140522,
0.0310526005923748,
0.022541910409927368,
-0.002213074592873454,
-0.0027371563483029604,
0.04031132161617279,
0.02071565017104149,
0.04020014405250549,
0.022640785202383995,
0.009649910032749176,
0.0075207059271633625,
-0.027486568316817284,
-0.05096183717250824,
0.01701224036514759,
-0.018104087561368942,
0.006946592126041651,
0.017489848658442497,
-0.008697736077010632,
-0.022003231570124626,
-0.0009338085656054318,
-0.0380089096724987,
-0.018759610131382942,
0.009724964387714863,
0.02332695759832859,
0.025963520631194115,
0.04827870801091194,
-0.005556010641157627,
-0.017994489520788193,
-0.040097400546073914,
-0.028761139139533043,
0.010623116977512836,
0.03103967197239399,
0.0036951065994799137,
0.014002214185893536,
-0.033988937735557556,
0.004123518243432045,
0.02161068096756935,
-0.056400954723358154,
-0.034446872770786285,
0.013613528572022915,
0.021234717220067978,
0.012777778320014477,
-0.01909436471760273,
-0.03786332532763481,
0.029553202912211418,
-0.02191179245710373,
-0.014750243164598942,
0.020937785506248474,
-0.04469647631049156,
0.057785507291555405,
0.013008367270231247,
0.0015895153628662229,
0.00793923158198595,
-0.02469196356832981,
-0.020848793908953667,
0.04907120019197464,
-0.0006670301081612706,
0.021975215524435043,
0.026115840300917625,
-0.019843237474560738,
0.03544703498482704,
-0.01996874250471592,
-0.029160555452108383,
0.05188235267996788,
0.0003161603235639632,
-0.04499462991952896,
-0.0005196411511860788,
-0.002977237571030855,
0.039441581815481186,
-0.03288166597485542,
0.002565067959949374,
0.006748511455953121,
-0.019359363242983818,
0.000316267745802179,
-0.036357637494802475,
-0.011673933826386929,
-0.0030540425796061754,
0.017411094158887863,
0.024275045841932297,
-0.05197404697537422,
-0.055340759456157684,
-0.006401177030056715,
0.017650358378887177,
0.04338882118463516,
0.01099881250411272,
0.022794468328356743,
-0.00107050861697644,
-0.003991424571722746,
-0.014177478849887848,
0.027660179883241653,
-0.005966567434370518,
-0.00015341346443165094,
0.029256174340844154,
0.011269970797002316,
-0.11662399768829346,
0.014058810658752918,
0.02640097215771675,
0.004227699711918831,
-0.010675458237528801,
0.009015132673084736,
-0.03176804259419441,
0.0058739264495670795,
0.0025118140038102865,
0.021947521716356277,
-0.01710316352546215,
0.021519312635064125,
0.0541599802672863,
-0.007323524449020624,
0.023466475307941437,
0.006028180941939354,
0.04924069717526436,
0.007996388711035252,
-0.004272251855581999,
0.020474746823310852,
0.0191655270755291,
0.012031740508973598,
-0.019596360623836517,
0.022723902016878128,
-0.04419955983757973,
0.003822721540927887,
0.0028966516256332397,
-0.014978853054344654,
0.021511944010853767,
0.0010354368714615703,
-0.005062231328338385,
-0.004070351831614971,
0.012616571970283985,
-0.025989970192313194,
0.0036427995655685663,
0.016786474734544754,
0.0020680436864495277,
0.013718289323151112,
-0.014566363766789436,
-0.0031229103915393353,
-0.012167442589998245,
0.007223517633974552,
0.007942676544189453,
0.002593172015622258,
0.020983291789889336,
-0.021282978355884552,
-0.03208639845252037,
-0.018613282591104507,
-0.010138414800167084,
0.029083263128995895,
-0.020638225600123405,
0.019355962052941322,
-0.037063077092170715,
0.0085908779874444,
-0.014593004249036312,
-0.017904307693243027,
0.01058612298220396,
0.037512268871068954,
-0.03474266082048416,
-0.00490950234234333,
0.012598322704434395,
0.006132406648248434,
-0.0021401483099907637,
-0.02189989760518074,
-0.037189219146966934,
-0.011286182329058647,
-0.035664841532707214,
-0.010914779268205166,
-0.018526306375861168,
0.024767588824033737,
0.01116203237324953,
-0.003620767965912819,
0.029705189168453217,
0.002987751504406333,
-0.025675643235445023,
0.001061831833794713,
0.015553801320493221,
-0.053180500864982605,
0.023910602554678917,
0.011176536791026592,
-0.0018143642228096724,
0.0061188144609332085,
0.021760333329439163,
0.018435675650835037,
0.004829034674912691,
0.017733050510287285,
0.009105606004595757,
-0.020287146791815758,
-0.022484419867396355,
0.00936485268175602,
-0.0021517889108508825,
0.01775580830872059,
0.04148479923605919,
-0.04317175969481468,
-0.041805729269981384,
0.03721801936626434,
0.013820819556713104,
0.003792321076616645,
-0.0010777604766190052,
-0.018575947731733322,
0.00016355380648747087,
-0.019253065809607506,
0.012322669848799706,
0.007875790819525719,
0.015562545508146286,
-0.01563790999352932,
-0.02144247107207775,
-0.04546164348721504,
0.011851352639496326,
0.029567386955022812,
0.00575208617374301,
-0.0017115232767537236,
-0.005551570560783148,
0.0029035217594355345,
-0.03306064382195473,
-0.02917555905878544,
-0.008165808394551277
] |
8a27086b8164b7eb22322aad33d91e3b2ba51e9e | 974 | py | Python | djangox/lib/python3.8/site-packages/allauth/socialaccount/providers/dropbox/views.py | DemarcusL/django_wiki_lab | 3b7cf18af7e0f89c94d10eb953ca018a150a2f55 | [
"MIT"
] | 6,342 | 2015-01-01T07:40:30.000Z | 2022-03-31T04:18:30.000Z | djangox/lib/python3.8/site-packages/allauth/socialaccount/providers/dropbox/views.py | DemarcusL/django_wiki_lab | 3b7cf18af7e0f89c94d10eb953ca018a150a2f55 | [
"MIT"
] | 2,198 | 2015-01-02T15:17:45.000Z | 2022-03-28T10:20:43.000Z | djangox/lib/python3.8/site-packages/allauth/socialaccount/providers/dropbox/views.py | DemarcusL/django_wiki_lab | 3b7cf18af7e0f89c94d10eb953ca018a150a2f55 | [
"MIT"
] | 2,928 | 2015-01-01T10:44:13.000Z | 2022-03-31T03:20:16.000Z | import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import DropboxOAuth2Provider
class DropboxOAuth2Adapter(OAuth2Adapter):
provider_id = DropboxOAuth2Provider.id
access_token_url = "https://api.dropbox.com/oauth2/token"
authorize_url = "https://www.dropbox.com/oauth2/authorize"
profile_url = "https://api.dropbox.com/2/users/get_current_account"
redirect_uri_protocol = "https"
def complete_login(self, request, app, token, **kwargs):
response = requests.post(
self.profile_url,
headers={"Authorization": "Bearer %s" % (token.token,)},
)
response.raise_for_status()
return self.get_provider().sociallogin_from_response(request, response.json())
oauth_login = OAuth2LoginView.adapter_view(DropboxOAuth2Adapter)
oauth_callback = OAuth2CallbackView.adapter_view(DropboxOAuth2Adapter)
| 32.466667 | 86 | 0.737166 | 1 | 0.9441 | [
0.0027482493314892054,
0.02354171685874462,
0.009897438809275627,
0.002963519422337413,
0.0037991348654031754,
-0.0027908156625926495,
-0.009544968605041504,
0.002930247690528631,
-0.006730847992002964,
0.0030413109343498945,
0.00237730098888278,
0.003528473898768425,
0.007601513061672449,
-0.017124619334936142,
-0.0003886848280671984,
0.015448905527591705,
-0.05126300826668739,
0.0016351320082321763,
-0.006053378339856863,
0.002419056138023734,
-0.007382107432931662,
0.007792149670422077,
0.00873690564185381,
0.006003945134580135,
0.006521651986986399,
-0.0008747662650421262,
0.009993338026106358,
0.0018951297970488667,
-0.00818610843271017,
-0.005888523533940315,
-0.0010309917852282524,
-0.003958974964916706,
-0.006765699479728937,
-0.0059379287995398045,
0.00766519270837307,
-0.00321791204623878,
0.002002387773245573,
-0.018069492653012276,
0.012759700417518616,
-0.0055052717216312885,
-0.007408143021166325,
-0.018973391503095627,
-0.00259264069609344,
0.003044349141418934,
-0.009368228726089,
0.0013011391274631023,
-0.0037411926314234734,
0.004114887211471796,
-0.01515396311879158,
0.004108963999897242,
-0.0101667745038867,
0.007034094538539648,
0.012161508202552795,
0.0022177754435688257,
-0.0059547726996243,
-0.008928065188229084,
0.012937693856656551,
-0.000387331674573943,
-0.012576460838317871,
0.001839907024987042,
-0.0037974126171320677,
-0.0020214447285979986,
0.004895769990980625,
0.0031219222582876682,
-0.015844887122511864,
-0.0046754744835197926,
-0.003486651461571455,
0.0031786030158400536,
0.0018430048367008567,
0.005610211752355099,
-0.0005306393723003566,
-0.0029275573324412107,
0.006592756602913141,
0.003771465737372637,
0.006896608509123325,
-0.003347226185724139,
0.0006303836707957089,
0.00010418985038995743,
0.009781483560800552,
0.002135792514309287,
0.005640983581542969,
-0.007697654888033867,
0.0070505766198039055,
0.009939929470419884,
0.014762087725102901,
0.00835007056593895,
0.020143859088420868,
-0.014275561086833477,
0.048219677060842514,
0.008913728408515453,
-0.010236530564725399,
0.0003295310598332435,
-0.009812537580728531,
-0.002596860285848379,
-0.004624488297849894,
-0.025129443034529686,
0.0003447819035500288,
-0.005900326184928417,
0.0033160627353936434,
0.0034193384926766157,
-0.001810666173696518,
0.006304016802459955,
-0.004348540212959051,
-0.0036017459351569414,
-0.006525231990963221,
0.014336486347019672,
-0.008253502659499645,
-0.002372145187109709,
0.008924216032028198,
0.001415287726558745,
-0.011494485661387444,
-0.0013650415930896997,
0.007171471603214741,
-0.013156075961887836,
0.0036113064270466566,
0.001958552049472928,
-0.0063639190047979355,
0.05597181245684624,
0.0022082349751144648,
0.0020086069125682116,
-0.004653305280953646,
-0.0013671184424310923,
-0.0006082026520743966,
0.007074242457747459,
0.006776315625756979,
-0.002084193052724004,
0.00995984859764576,
0.0076452153734862804,
0.002690317342057824,
0.00840042345225811,
-0.0013846319634467363,
0.009784327819943428,
-0.004703337326645851,
-0.0035889502614736557,
0.00198091147467494,
-0.008713548071682453,
0.005624042823910713,
-0.003033578395843506,
-0.008151741698384285,
0.0003368408652022481,
0.0009009919012896717,
-0.0140586132183671,
0.0018026649486273527,
-0.0014387009432539344,
0.00007159543019952253,
-0.01328305434435606,
-0.004972192458808422,
-0.0054191481322050095,
-0.006472409702837467,
0.004999393597245216,
0.0078537967056036,
0.004172897431999445,
0.0033796473871916533,
-0.004741821903735399,
-0.009113650768995285,
-0.0004710101638920605,
-0.004612669348716736,
0.00349827716127038,
0.007917028851807117,
0.0022406394127756357,
-0.00921493861824274,
0.0015231129946187139,
0.004796087276190519,
0.0022567668929696083,
-0.001062546158209443,
-0.000499086338095367,
-0.00869213230907917,
0.0057516261003911495,
0.00022824241023045033,
0.005793423857539892,
0.011564294807612896,
-0.005076543893665075,
-0.003146563423797488,
-0.0021744377445429564,
0.0028070686385035515,
-0.000646440195851028,
0.004645626526325941,
0.014811970293521881,
-0.0029149355832487345,
-0.005972000304609537,
0.004641176667064428,
0.006937659345567226,
0.007765706162899733,
0.007751779165118933,
-0.0024002380669116974,
0.0013383133336901665,
-0.003702125744894147,
-0.0010766295017674565,
0.0033673287834972143,
-0.004802377428859472,
0.004694708622992039,
0.0046501848846673965,
-0.015351586975157261,
-0.008391756564378738,
0.00380987161770463,
-0.008862610906362534,
0.0015184760559350252,
0.014537766575813293,
0.00917052198201418,
-0.0025937322061508894,
0.004565953742712736,
-0.0083150090649724,
-0.0009480940061621368,
0.00408363388851285,
0.0009006914333440363,
-0.015498927794396877,
-0.9572540521621704,
0.0047577363438904285,
0.004136478528380394,
-0.000010366404239903204,
0.005178708583116531,
0.004113493021577597,
0.000029853621526854113,
0.003752497024834156,
0.01509058102965355,
-0.013126498088240623,
-0.005622069351375103,
-0.011926716193556786,
-0.0102922972291708,
-0.0016266480088233948,
-0.0065700397826731205,
-0.006109283771365881,
-0.004603216424584389,
-0.006575595587491989,
-0.0033189491368830204,
-0.0036916572134941816,
-0.005025407299399376,
0.010537998750805855,
-0.0008985800668597221,
0.005433353595435619,
0.0039057377725839615,
0.00351165933534503,
-0.00254073110409081,
-0.0005806171684525907,
-0.0012588670942932367,
0.00010203816782450303,
-0.008838308975100517,
-0.015143521130084991,
-0.005766885820776224,
-0.001164751360192895,
0.01011969055980444,
-0.0004995957715436816,
0.009917744435369968,
-0.0016424729255959392,
0.002759006340056658,
-0.006419488228857517,
0.005779453087598085,
0.00035991374170407653,
0.0023583583533763885,
-0.029398664832115173,
0.0014134158845990896,
-0.0023407211992889643,
-0.009869481436908245,
0.008524704724550247,
0.0004441365890670568,
-0.0017825847025960684,
-0.0026903103571385145,
-0.0033766368869692087,
0.012190337292850018,
-0.007754686754196882,
0.0034276838414371014,
-0.004540230613201857,
-0.0056694732047617435,
-0.002960284473374486,
-0.010215988382697105,
0.0004037152393721044,
0.0036779637448489666,
-0.003836204530671239,
-0.0046694716438651085,
0.00011657548748189583,
0.0018714094767346978,
0.0017111041815951467,
-0.0013570677256211638,
-0.016529954969882965,
-0.007953432388603687,
-0.001136355334892869,
-0.001225053332746029,
-0.005772754084318876,
-0.003579517360776663,
0.005999105982482433,
-0.00966562144458294,
0.005739459302276373,
0.0018309045117348433,
0.0019340686267241836,
-0.013985825702548027,
-0.0004466043901629746,
-0.007573956158012152,
-0.009007522836327553,
0.0011689219390973449,
-0.00889250822365284,
-0.005308005027472973,
0.0007282336009666324,
0.0003024617617484182,
0.008234724402427673,
-0.003586332779377699,
0.0054476005025208,
0.01379293855279684,
-0.0027084951288998127,
-0.006755380891263485,
0.007581673562526703,
0.0050822654739022255,
-0.0007235922385007143,
-0.0041299681179225445,
0.0007892193971201777,
0.0091451620683074,
0.00674884207546711,
0.001761418185196817,
0.004575675819069147,
-0.0004304329922888428,
0.009717249311506748,
0.0000054542160796700045,
0.0007048689876683056,
-0.004064406733959913,
-0.0006481426535174251,
-0.005038101226091385,
-0.0009902212768793106,
-0.0032651855144649744,
-0.002029578434303403,
-0.015123958699405193,
-0.007717616856098175,
-0.0019312461372464895,
0.0006830109632574022,
0.001110542449168861,
-0.0024861530400812626,
-0.00032031015143729746,
0.00357645726762712,
0.007993355393409729,
0.001290566986426711,
-0.0018935807747766376,
0.0015940479934215546,
0.0033080708235502243,
-0.008686242625117302,
0.015047322027385235,
-0.012799673713743687,
0.006671612150967121,
-0.0025898057501763105,
-0.01668631285429001,
0.008091786876320839,
0.007811109069734812,
-0.00955367274582386,
0.0018187285168096423,
0.005715071223676205,
0.005428755655884743,
-0.0010151923634111881,
-0.0058517297729849815,
-0.0018829616019502282,
-0.012535317800939083,
-0.0009285168489441276,
0.01761072315275669,
0.0013009574031457305,
0.011076492257416248,
0.011459484696388245,
-0.0021938649006187916,
0.0028347212355583906,
0.005128923803567886,
0.001000191317871213,
0.011209814809262753,
-0.01009825337678194,
-0.002614183584228158,
0.0012174522271379828,
-0.005218182224780321,
-0.00041049878927879035,
0.006464631296694279,
0.005168350413441658,
-0.0037703081034123898,
0.003427576506510377,
-0.007724476978182793,
-0.004215354565531015,
-0.018879976123571396,
-0.0030619571916759014,
0.007790702860802412,
-0.004600589629262686,
0.0052236816845834255,
-0.011066394858062267,
0.007012024521827698,
0.009654099121689796,
-0.0004756120906677097,
0.001685761846601963,
-0.0022838725708425045,
0.008327263407409191,
0.011022999882698059,
-0.006255366373807192,
0.0029782007914036512,
0.0027720050420612097,
-0.0007197428494691849,
0.0008175509283319116,
0.00894615612924099,
-0.007656675763428211,
-0.006181144621223211,
0.003020207630470395,
0.004260766785591841,
-0.002536744112148881,
-0.00640864297747612,
-0.009116066619753838,
-0.004615025594830513,
0.002694362075999379,
-0.0025311303324997425,
0.005437392741441727,
0.0010315217077732086,
0.0037178811617195606,
-0.006823851726949215,
-0.00008225697092711926,
-0.001957619795575738,
-0.013275894336402416,
0.010528466664254665,
-0.002300004009157419,
0.003038495546206832,
0.011512485332787037,
0.003989656455814838,
-0.014032631181180477,
0.006622761953622103,
0.007963216863572598,
-0.004624333698302507,
0.003921738360077143,
0.004773369990289211,
-0.008220971561968327,
-0.024312708526849747,
-0.003944843541830778,
-0.015114448964595795,
0.009333744645118713,
-0.002045684726908803,
0.005620304495096207,
-0.005902511533349752,
0.0064652045257389545,
0.004436060320585966,
-0.013752717524766922,
-0.00565923098474741,
-0.00789384264498949,
0.010546544566750526,
0.0013434133725240827,
0.00001657919528952334,
-0.0032229528296738863,
0.0021130540408194065,
-0.00426316075026989,
-0.003762856824323535,
-0.0009963213233277202,
0.005660108756273985,
0.004092749673873186,
-0.002243713941425085,
0.0031517273746430874,
-0.005373889580368996,
0.0011461027897894382,
-0.0005258446326479316,
-0.01077140960842371,
0.002446478232741356,
0.007337093818932772,
-0.0037035872228443623,
-0.009596649557352066,
0.002228939440101385,
-0.0010386164067313075,
-0.007385007105767727,
-0.010157214477658272,
-0.003832574002444744,
-0.003779113758355379,
-0.003651389153674245,
-0.011490711942315102,
-0.00446626590564847,
-0.008204283192753792,
0.006164207588881254,
-0.007833637297153473,
0.010891959071159363,
0.004788490477949381,
-0.006617309525609016,
0.006542800460010767,
-0.004095419310033321,
0.004990671761333942,
0.004098725970834494,
0.005859812721610069,
-0.00019283212895970792,
-0.004103690851479769,
-0.009643602184951305,
0.011429157108068466,
-0.008974067866802216,
-0.0013009656686335802,
0.012837757356464863,
0.0058483523316681385,
0.00928413774818182,
0.0006399358389899135,
-0.0008071883930824697,
0.004524730611592531,
0.008065194822847843,
-0.01286759041249752,
0.0025715616066008806,
-0.002522202907130122,
0.002175160450860858,
0.0064830482006073,
-0.004245213232934475,
0.00694111967459321,
0.0069704726338386536,
0.002792958403006196,
-0.009439988993108273,
-0.0035950560122728348,
0.002588133327662945,
0.00553872250020504,
-0.012787754647433758,
0.0004998601507395506,
-0.0067999656312167645,
-0.004425357095897198,
-0.0045249853283166885,
-0.004114949610084295,
-0.0013576785568147898,
0.007758821826428175,
-0.0017530523473396897,
0.005821488332003355,
0.0008025881252251565,
-0.0010620862012729049,
0.015124646946787834,
-0.005546743981540203,
-0.002302342327311635,
0.0020990604534745216,
0.002604326233267784,
0.0006241040537133813,
-0.007289136294275522,
-0.002602536929771304,
0.002511776750907302,
0.004386476241052151,
-0.0012884646421298385,
-0.006850851699709892,
-0.0026251845993101597,
-0.0016360972076654434,
-0.008220274932682514,
0.0008252204861491919,
0.009962066076695919,
-0.0010113038588315248,
0.005866330582648516,
-0.0022686852607876062,
-0.005890813190490007,
-0.013487138785421848,
0.05498625710606575,
-0.001826890162192285,
0.005900578107684851,
0.0075591676868498325,
-0.006414317525923252,
0.0014901574468240142,
-0.004700807388871908,
0.003955761436372995,
-0.006844054441899061,
-0.0091660525649786,
0.00823229644447565,
-0.0024653468281030655,
0.004200217314064503,
0.004195531364530325,
-0.002090317429974675,
0.016848359256982803,
-0.005385459866374731,
-0.01414894312620163,
-0.01777869462966919,
0.007643414661288261,
-0.006308060605078936,
-0.009459438733756542,
0.01129484549164772,
-0.0026532127521932125,
-0.00633852556347847,
0.0009465264156460762,
0.0044863526709377766,
0.0032867526169866323,
-0.0004858781467191875,
-0.005483969114720821,
-0.0013541168300434947,
-0.0004204120486974716,
0.003621343057602644,
0.00498393177986145,
0.007691439241170883,
-0.0052895802073180676,
0.005068259779363871,
-0.004957281984388828,
-0.003637748071923852,
0.0017549750627949834,
0.006551856640726328,
0.009132943116128445,
0.0003148991381749511,
-0.0002116579853463918,
0.005957843270152807,
0.002922330517321825,
0.0006585927912965417,
0.008260713890194893,
0.0033866295125335455,
-0.00400692131370306,
0.009426667355000973,
0.00579604459926486,
0.0009638477931730449,
0.007006138563156128,
-0.002802632749080658,
0.004969161935150623,
0.0019118657801300287,
-0.006226531229913235,
-0.014526411890983582,
-0.0042782798409461975,
0.006448852363973856,
0.0073088244535028934,
0.0014046323485672474,
0.0025447686202824116,
-0.002032320247963071,
-0.002162112621590495,
-0.0063626025803387165,
-0.004475979134440422,
-0.003186518792062998,
0.00027157695149071515,
0.004251888487488031,
0.07063789665699005,
-0.007193498779088259,
-0.0011716202134266496,
-0.006842853967100382,
-0.00006692025635857135,
-0.0012198251206427813,
-0.0011429847218096256,
-0.0001505279215052724,
-0.004276585299521685,
0.0009311122121289372,
0.0034554910380393267,
-0.005949704442173243,
-0.011826013214886189,
0.0029928223229944706,
0.0012495059054344893,
-0.0019419727614149451,
0.0042680054903030396,
0.003731301287189126,
-0.009698843583464622,
0.003418720094487071,
-0.011511077173054218,
-0.00683178473263979,
-0.0034071356058120728,
-0.008577302098274231,
-0.0021718183998018503,
-0.00036790946614928544,
0.003329738276079297,
0.0022743854206055403,
0.0036969496868550777,
-0.002220593160018325,
0.007109272293746471,
-0.003611857770010829,
-0.0014534618239849806,
-0.003893307177349925,
-0.002848495962098241,
-0.004368389956653118,
0.004614753648638725,
-0.00024055055109784007,
-0.00783858448266983,
-0.003585630562156439,
-0.00098668341524899,
-0.0021325405687093735,
-0.0051856813952326775,
0.004596275743097067,
-0.0010958361672237515,
0.005195088218897581,
-0.0029845144599676132,
-0.0009980666218325496,
-0.006076411809772253,
0.0036557912826538086,
-0.015455673448741436,
0.0012825020821765065,
-0.17512676119804382,
0.011284724809229374,
0.004388708155602217,
-0.0046384152956306934,
-0.004682645667344332,
-0.015365146100521088,
-0.00390452123247087,
0.006042925175279379,
0.011243337765336037,
0.0023319609463214874,
-0.0010872094426304102,
-0.00036020632251165807,
0.0034982573706656694,
0.0029188150074332952,
-0.00415903190150857,
-0.005355909466743469,
0.0025474941357970238,
-0.0035743811167776585,
0.0027836565859615803,
0.006272347178310156,
0.004816602449864149,
0.008511122316122055,
0.00004038216138724238,
0.0024339284282177687,
-0.0031326983589679003,
-0.005050307139754295,
0.006969543173909187,
-0.0009777016239240766,
0.0036183595657348633,
-0.010511782951653004,
-0.005125307012349367,
-0.0019555003382265568,
-0.005071528255939484,
0.0034280051477253437,
0.00519421324133873,
-0.0017434806795790792,
0.011098632588982582,
0.004835586994886398,
-0.005448600742965937,
0.006534353364259005,
-0.009257340803742409,
0.029833829030394554,
0.009147506207227707,
0.00777975469827652,
0.00032583545544184744,
-0.005883755162358284,
-0.005962662398815155,
0.009321226738393307,
0.005149580538272858,
0.012468850240111351,
-0.008512846194207668,
-0.003209889866411686,
0.003839515382423997,
0.01906215399503708,
-0.004995344206690788,
-0.006320187821984291,
-0.006380911450833082,
-0.0027236228343099356,
0.0043153041042387486,
0.008741054683923721,
0.011353868059813976,
-0.0018533073598518968,
0.011196501553058624,
-0.004227627534419298,
-0.02072393149137497,
0.0024194326251745224,
-0.002767358673736453,
-0.009296543896198273,
0.004157021176069975,
0.004855727776885033,
0.013509443961083889,
-0.0016761714359745383,
0.0008741129422560334,
-0.001937378547154367,
0.0058532520197331905,
0.0005644875927828252,
0.004760381765663624,
-0.0004180275136604905,
0.006919569335877895,
-0.00912594236433506,
0.009660989977419376,
-0.009972366504371166,
-0.002305420348420739,
0.0021440747659653425,
-0.003438935847952962,
0.01115607563406229,
0.004209761507809162,
-0.0012640554923564196,
0.002529722172766924,
-0.008328954689204693,
-0.004447535146027803,
0.00044702726881951094,
0.0018001823918893933,
-0.008897032588720322,
0.004793152213096619,
-0.000418813549913466,
0.005085981450974941,
0.00838937982916832,
-0.008069543167948723,
0.007943679578602314,
0.0029319035820662975,
-0.005688819568604231,
0.000562921748496592,
-0.005866711493581533,
0.0010767363710328937,
0.0017937499796971679,
-0.006489858962595463,
-0.0074554807506501675,
0.003323242999613285,
-0.008150107227265835,
-0.005094141233712435,
0.005095190368592739,
-0.00958841759711504,
-0.009338785894215107,
0.00002862463952624239,
-0.01044616661965847,
0.0004330836236476898
] |
8a27be0083c13f36f7583420125751ea6216ec63 | 1,599 | py | Python | source/conf.py | Tatsh/upkeep | 7fa99ff54104e3dec15d611eb174910337cf1870 | [
"MIT"
] | 3 | 2019-04-24T10:17:00.000Z | 2020-03-11T06:18:42.000Z | source/conf.py | Tatsh/pezu | d5264b61a7113783ea29388180c16126cf185bdd | [
"MIT"
] | 4 | 2020-04-27T19:56:29.000Z | 2021-02-11T05:44:22.000Z | source/conf.py | Tatsh/pezu | d5264b61a7113783ea29388180c16126cf185bdd | [
"MIT"
] | null | null | null | # SPDX-License-Identifier: MIT
# pylint: disable=redefined-builtin,invalid-name
"""See https://www.sphinx-doc.org/en/master/usage/configuration.html"""
from typing import Sequence
import os
import sys
# region Path setup
sys.path.insert(0, os.path.abspath('..'))
# endregion
# region Project information
project = 'Upkeep'
copyright = '2020, Andrew Udvare'
author = 'Andrew Udvare'
# The short X.Y version
version = '1.2.7'
# The full version, including alpha/beta/rc tags
release = f'v{version}'
# endregion
# region General configuration
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns: Sequence[str] = []
master_doc = 'index'
# endregion
# region Options for HTML output
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# endregion
# region Extension configuration
# endregion
| 33.3125 | 77 | 0.760475 | 1 | 1.1871 | [
0.00014135174569673836,
0.025193938985466957,
0.008268387988209724,
-0.00003304989149910398,
0.004564194008708,
-0.0018842598656192422,
-0.009315144270658493,
0.0022660738322883844,
-0.00801901426166296,
0.0029660596046596766,
0.0027588317170739174,
0.0048061213456094265,
0.00531976530328393,
-0.017192712053656578,
0.00306027103215456,
0.017344217747449875,
-0.05274517461657524,
0.0023334003053605556,
-0.00261146342381835,
0.0014194761170074344,
-0.007987221702933311,
0.009497001767158508,
0.00872101355344057,
0.0061107720248401165,
0.00663982518017292,
0.001967889256775379,
0.008750834502279758,
0.00388268637470901,
-0.006164367310702801,
-0.004740355536341667,
-0.0028003763873130083,
-0.0014963282737880945,
-0.005286809988319874,
-0.009502197615802288,
0.006429366767406464,
-0.0011448299046605825,
-0.0012292948085814714,
-0.021403828635811806,
0.010611852630972862,
-0.0036978169810026884,
-0.007098824251443148,
-0.018101684749126434,
0.001158030703663826,
0.004240258596837521,
-0.013151668012142181,
-0.00030832039192318916,
-0.0009064322803169489,
0.005521285347640514,
-0.01181587390601635,
0.009206417948007584,
-0.008071738295257092,
0.00800220388919115,
0.015576524659991264,
0.002873628167435527,
-0.004044879227876663,
-0.006235981825739145,
0.013610441237688065,
0.0006331689073704183,
-0.012127249501645565,
-0.00014194326649885625,
-0.003019592259079218,
-0.0035039365757256746,
0.004282296635210514,
0.006050588097423315,
-0.017239859327673912,
-0.006560345645993948,
-0.003981652669608593,
0.003286033170297742,
0.002187824808061123,
0.005244017578661442,
0.002374465810135007,
-0.00276488671079278,
0.009998110122978687,
0.0017666690982878208,
0.0060442062094807625,
-0.002141673816367984,
-0.0003078861627727747,
0.0014271168038249016,
0.007457192055881023,
0.0028585498221218586,
0.0027736297342926264,
-0.006134766153991222,
0.006911067292094231,
0.01284797489643097,
0.013694182969629765,
0.007217236328870058,
0.01972055435180664,
-0.011172709986567497,
0.045261263847351074,
0.006678183563053608,
-0.008750204928219318,
0.00029396015452221036,
-0.0061112092807888985,
-0.001756313256919384,
-0.0022714852821081877,
-0.029097270220518112,
0.0012164138024672866,
-0.004060272593051195,
-0.001588931423611939,
0.0033672493882477283,
-0.002398696495220065,
0.003461780957877636,
0.00014499780081678182,
-0.0007752428646199405,
-0.009565497748553753,
0.012380470521748066,
-0.0072351908311247826,
-0.003124688984826207,
0.005513391457498074,
0.0023367167450487614,
-0.012646181508898735,
-0.0006293707410804927,
0.0021428100299090147,
-0.012181559577584267,
0.005532474722713232,
0.002372300485149026,
-0.005240422673523426,
0.053130172193050385,
-0.004489195998758078,
0.004046477843075991,
-0.0035486281849443913,
0.0014450647868216038,
0.0016956741455942392,
0.006173237692564726,
0.008061624132096767,
-0.0026081549003720284,
0.00932201836258173,
0.007495232857763767,
0.002278260188177228,
0.0098396772518754,
-0.00042891420889645815,
0.005575533490628004,
-0.0022850227542221546,
-0.003907271195203066,
0.00043605000246316195,
-0.008872978389263153,
0.00777653232216835,
-0.0014379289932549,
-0.008259396068751812,
0.00037381640868261456,
-0.0014308546669781208,
-0.010784853249788284,
0.0005399631336331367,
-0.0052392687648534775,
0.0012973619159311056,
-0.011145850643515587,
-0.0053115710616111755,
-0.0018955045379698277,
-0.004465618170797825,
0.0016357488930225372,
0.011003873310983181,
0.004080366343259811,
0.0034540602937340736,
-0.004905588459223509,
-0.009308308362960815,
0.00021282045054249465,
-0.0036602190230041742,
0.003064800752326846,
0.008426490239799023,
0.004717804957181215,
-0.009384888224303722,
-0.002095452742651105,
0.0027205694932490587,
0.0037169810384511948,
-0.0010897144675254822,
0.0035544803831726313,
-0.007580915465950966,
0.007743719033896923,
0.0006633246666751802,
0.005913976579904556,
0.011301390826702118,
-0.0029311450198292732,
0.00034446013160049915,
0.00026965411962009966,
0.0009497719584032893,
-0.00029260109295137227,
0.006811597850173712,
0.01071527972817421,
-0.002430445747449994,
-0.0025699667166918516,
0.0026486809365451336,
0.003579301992431283,
0.008735853247344494,
0.007858941331505775,
-0.002279086271300912,
0.0017778227338567376,
-0.0029456710908561945,
-0.0018144134664908051,
0.004670863039791584,
-0.004194607958197594,
0.004539168905466795,
0.004722833167761564,
-0.012102530337870121,
-0.00911360327154398,
-0.0022530497517436743,
-0.006630126852542162,
-0.0004137574869673699,
0.015271930024027824,
0.010330644436180592,
-0.0037531538400799036,
0.004560921806842089,
-0.009994657710194588,
0.0011785731185227633,
0.008759552612900734,
0.0007796247373335063,
-0.01335642859339714,
-0.9574173092842102,
0.0025826673954725266,
0.0014956683153286576,
-0.0005397549248300493,
0.004033831879496574,
0.000748041900806129,
0.0031434560660272837,
0.0031835015397518873,
0.014527060091495514,
-0.005798023659735918,
-0.006487215403467417,
-0.008557776920497417,
-0.010809468105435371,
-0.0021520827431231737,
-0.008118347264826298,
-0.00376528175547719,
-0.0060819778591394424,
-0.00680201780050993,
-0.0014359747292473912,
-0.003135871607810259,
-0.0020513790659606457,
0.011527196504175663,
0.00042212236439809203,
0.004308001603931189,
0.001927327481098473,
0.0035513429902493954,
-0.0017177230911329389,
0.0017827970441430807,
-0.0012917394051328301,
-0.0044468543492257595,
-0.005632949993014336,
-0.016253022477030754,
-0.0035820065531879663,
-0.0013776891864836216,
0.01066392008215189,
0.0016721542924642563,
0.006605501286685467,
-0.00123502966016531,
-0.0020047889556735754,
-0.008167396299540997,
0.003926792647689581,
0.0017594479722902179,
-0.00022201906540431082,
-0.03075762465596199,
0.00018606502271723002,
-0.0016320336144417524,
-0.007348537910729647,
0.010840273462235928,
0.0004989541484974325,
-0.0007786796777509153,
-0.0037975257728248835,
-0.004916390869766474,
0.010794537141919136,
-0.008909308351576328,
0.005642369389533997,
-0.005309279076755047,
-0.006085595116019249,
-0.003296529408544302,
-0.012288817204535007,
0.0009465729235671461,
0.006145214196294546,
-0.0021736572962254286,
-0.004480960313230753,
-0.005621396470814943,
0.0019170428859069943,
0.002278453204780817,
-0.0006190689164213836,
-0.01754477247595787,
-0.006366142071783543,
-0.0028055142611265182,
0.0025911934208124876,
-0.004425702150911093,
-0.002976649673655629,
0.005554445553570986,
-0.009394927881658077,
0.008212441578507423,
0.0025370903313159943,
0.0009130428079515696,
-0.009541974402964115,
0.0032529672607779503,
-0.006111083086580038,
-0.007295006420463324,
-0.0005333471926860511,
-0.0037351716309785843,
-0.005415226332843304,
0.0009314650087617338,
0.0005083814030513167,
0.005933451931923628,
-0.002965029329061508,
0.004814401268959045,
0.014096965081989765,
-0.004625848960131407,
-0.007874233648180962,
0.007134094834327698,
0.004906405229121447,
-0.0007863729260861874,
-0.0024647475220263004,
0.0012416014214977622,
0.010894042439758778,
0.007004698272794485,
0.002517367945984006,
0.005186426918953657,
-0.0007843251805752516,
0.009485333226621151,
0.0012677180347964168,
0.002329053357243538,
-0.0014727289089933038,
-0.0032478400971740484,
-0.0047906143590807915,
0.0009001939324662089,
-0.006017469335347414,
-0.0032228385098278522,
-0.011483822017908096,
-0.009837895631790161,
-0.0019392461981624365,
-0.000036194836866343394,
0.001198001322336495,
-0.0016522775404155254,
0.0020376117900013924,
0.0032292858231812716,
0.007935413159430027,
-0.0003377609536983073,
-0.0019576482009142637,
0.0002541871217545122,
0.003970192279666662,
-0.006842141039669514,
0.014312581159174442,
-0.011496301740407944,
0.004767283331602812,
-0.00010960215149680153,
-0.016685359179973602,
0.006145355757325888,
0.00858281273394823,
-0.007982096634805202,
0.0025876322761178017,
0.003153041936457157,
0.0030325944535434246,
0.0014876615023240447,
-0.005528294015675783,
-0.0038481999654322863,
-0.013879337348043919,
-0.0005330641288310289,
0.019023941829800606,
0.0019106996478512883,
0.008988087065517902,
0.01325194537639618,
-0.003134709782898426,
0.00010049077536677942,
0.005412770435214043,
0.0012252145679667592,
0.01468262542039156,
-0.007391795981675386,
0.00003449306677794084,
-0.00020135413797106594,
-0.006350171752274036,
-0.001414662692695856,
0.005667085759341717,
0.006435984279960394,
-0.001950194826349616,
0.0032791371922940016,
-0.005533372983336449,
-0.00586130702868104,
-0.017106402665376663,
-0.005153211299329996,
0.005753535311669111,
-0.006011689081788063,
0.004817778244614601,
-0.014100301079452038,
0.004489908926188946,
0.008109884336590767,
0.004499826580286026,
-0.00004494961831369437,
-0.002575059188529849,
0.007084340322762728,
0.014159482903778553,
-0.005563015583902597,
0.0009306547581218183,
-0.00025009980890899897,
-0.0024059140123426914,
0.0012849306222051382,
0.009419630281627178,
-0.008059605956077576,
-0.004389864858239889,
0.001155142206698656,
0.005659264978021383,
0.00007134428597055376,
-0.004099777899682522,
-0.01006920076906681,
-0.004637134727090597,
0.003888614010065794,
-0.008111700415611267,
0.004220266360789537,
0.00004415256262291223,
0.002106913598254323,
-0.007019828073680401,
-0.0006940870080143213,
-0.003983241505920887,
-0.011297045275568962,
0.011899413540959358,
-0.0021253013983368874,
0.004706609062850475,
0.01496396865695715,
0.005258678924292326,
-0.012938117608428001,
0.007188651245087385,
0.008514417335391045,
-0.004120801109820604,
0.0030454755760729313,
0.00563478609547019,
-0.0042967526242136955,
-0.02357923984527588,
-0.000508644909132272,
-0.013537868857383728,
0.006440930534154177,
-0.0012185589876025915,
0.00432102894410491,
-0.007046787533909082,
0.0059790597297251225,
0.006919923238456249,
-0.01597009412944317,
-0.006010584067553282,
-0.011778153479099274,
0.00975209753960371,
-0.0017696631839498878,
-0.0016200232785195112,
-0.003494855249300599,
-0.0037397188134491444,
-0.00010240321716992185,
-0.0025144952815026045,
-0.0032077794894576073,
0.003989203833043575,
0.0016419183230027556,
-0.005740259308367968,
0.002330687129870057,
-0.003993679769337177,
-0.0013435690198093653,
0.002788859186694026,
-0.01107035018503666,
0.0034160881768912077,
0.00666861142963171,
-0.002689854009076953,
-0.0036514168605208397,
0.0005681458860635757,
-0.0022997381165623665,
-0.005865724757313728,
-0.011436945758759975,
-0.0035133420024067163,
-0.004624456167221069,
-0.0024849525652825832,
-0.010837653651833534,
-0.000006839975412731292,
-0.00808666367083788,
0.006403131876140833,
-0.005732415243983269,
0.009141367860138416,
0.006355090532451868,
-0.002712491201236844,
0.0030808793380856514,
-0.002477561589330435,
0.0028336630202829838,
0.006889311596751213,
0.006218852940946817,
0.00017742265481501818,
-0.007106931880116463,
-0.012068877927958965,
0.01180589571595192,
-0.009331871755421162,
0.0005118153057992458,
0.015675783157348633,
0.00388415833003819,
0.009764304384589195,
-0.0007773848483338952,
-0.0012600915506482124,
0.004829190205782652,
0.007402712944895029,
-0.014702517539262772,
0.002312887692824006,
-0.002332986332476139,
0.0001942621893249452,
0.006372478324919939,
-0.0031976201571524143,
0.0031103058718144894,
0.01124050933867693,
0.0028361522126942873,
-0.006742194294929504,
-0.0012946112547069788,
0.002501684008166194,
0.004066343419253826,
-0.012067367322742939,
-0.0005062089185230434,
-0.0025158787611871958,
-0.00334359984844923,
-0.0036914313677698374,
-0.002281792461872101,
-0.00027862106799148023,
0.006172717548906803,
-0.0027212875429540873,
0.004047711845487356,
0.0010995249031111598,
-0.0034039916936308146,
0.013223422691226006,
-0.006305020768195391,
-0.008739474229514599,
0.0010538360802456737,
0.002141085220500827,
-0.00211304216645658,
-0.006794211454689503,
-0.002436953131109476,
0.0018756359349936247,
0.0063634286634624004,
-0.003980590496212244,
-0.006045624613761902,
-0.0009587940876372159,
0.002999380696564913,
-0.006847369484603405,
0.00016458389291074127,
0.013682547025382519,
-0.0008835605694912374,
0.005759282968938351,
-0.00235613901168108,
-0.006638840772211552,
-0.015423203818500042,
0.05414833500981331,
0.001555187744088471,
0.002928681904450059,
0.002973004709929228,
-0.009344875812530518,
0.00030885287560522556,
-0.004255198873579502,
0.007504316046833992,
-0.008036626502871513,
-0.004127053543925285,
0.007950613275170326,
-0.002645957749336958,
0.0026550102047622204,
0.0007193809142336249,
-0.00024024219601415098,
0.012654128484427929,
-0.003416457213461399,
-0.017420120537281036,
-0.01821812242269516,
0.010347822681069374,
-0.0018083024770021439,
-0.007761381100863218,
0.007071389351040125,
-0.003454729449003935,
-0.004360342863947153,
0.000794783525634557,
0.005008072126656771,
0.000672491267323494,
0.00025083281798288226,
-0.002361206104978919,
-0.0032834128942340612,
0.001704470720142126,
0.0032552636694163084,
0.007761274930089712,
0.0074986950494349,
-0.0031468449160456657,
0.006259361747652292,
-0.00459063146263361,
-0.001775652403011918,
-0.00162160350009799,
0.003890939988195896,
0.006230513099581003,
-0.0009840454440563917,
-0.0011842279927805066,
0.004338840488344431,
0.005064310040324926,
0.0035485478583723307,
0.0102652283385396,
-0.0015400039264932275,
-0.003321695141494274,
0.009463298134505749,
0.006991571746766567,
-0.0025130268186330795,
0.006334800738841295,
-0.0040173036977648735,
0.0049629416316747665,
0.00019485490338411182,
-0.007744207512587309,
-0.014619816094636917,
-0.0016233862843364477,
0.003632232081145048,
0.006792227737605572,
0.00126708357129246,
0.00011443228868301958,
-0.0024792389012873173,
-0.002626658882945776,
-0.00839199312031269,
-0.009178489446640015,
-0.004370963666588068,
0.0010589980520308018,
0.0016876970184966922,
0.07038356363773346,
-0.0033451213967055082,
-0.00240600504912436,
-0.008315390907227993,
-0.00005672900442732498,
-0.00048324919771403074,
-0.0026767016388475895,
0.0005614056717604399,
-0.0027534798718988895,
0.001179695944301784,
0.004520012531429529,
-0.007013645023107529,
-0.010869652032852173,
0.001584633719176054,
0.0008346112444996834,
-0.0010854311985895038,
0.0017707516672089696,
0.006670497823506594,
-0.0077468655072152615,
0.0002717683673836291,
-0.011744477786123753,
-0.0010345856426283717,
-0.0028931349515914917,
-0.006838086526840925,
-0.0021053124219179153,
-0.0019540104549378157,
0.0037416843697428703,
0.0016615968197584152,
0.005916570778936148,
-0.003584787482395768,
0.007307539228349924,
-0.002753934357315302,
-0.0014299183385446668,
-0.003007511841133237,
-0.001407594420015812,
-0.006402251776307821,
0.007652245927602053,
-0.0002444126002956182,
-0.01033157017081976,
-0.006767855025827885,
-0.00274010025896132,
0.0009698353242129087,
-0.0042016105726361275,
0.006012211088091135,
0.000737424532417208,
0.006354550831019878,
-0.0025541852228343487,
0.001112699625082314,
-0.005860036239027977,
-0.0006742805708199739,
-0.011565212160348892,
0.003682008944451809,
-0.17911940813064575,
0.010387002490460873,
0.0030111130326986313,
-0.0035691638477146626,
-0.00423775427043438,
-0.013565598987042904,
-0.007149234879761934,
0.003908909857273102,
0.009167862124741077,
0.0021262220107018948,
-0.0003582114586606622,
-0.0012238993076607585,
0.004564269445836544,
0.004723581951111555,
-0.0009402769501321018,
-0.005228480789810419,
0.003947102930396795,
-0.005525111686438322,
0.0007003453793004155,
0.003747635753825307,
0.00682554766535759,
0.007640230469405651,
0.002723878715187311,
-0.0004280029097571969,
-0.0025180322118103504,
-0.0061970860697329044,
0.005762288812547922,
-0.0029150641057640314,
0.006847303360700607,
-0.013384704478085041,
-0.0021733734756708145,
-0.0025273731444031,
-0.006354179698973894,
0.0009566874359734356,
0.004796934314072132,
-0.0032540401443839073,
0.007175780367106199,
0.0018413282232359052,
-0.009686865843832493,
0.005603889003396034,
-0.010251362808048725,
0.027432633563876152,
0.00855150818824768,
0.006310918368399143,
-0.0005198068683966994,
-0.006184905767440796,
-0.0034524209331721067,
0.009827816858887672,
0.0021154440473765135,
0.013318068347871304,
-0.012541503645479679,
-0.0042876387014985085,
0.003867214545607567,
0.018225686624646187,
-0.005423618946224451,
-0.008125935681164265,
-0.005719179753214121,
-0.005433849990367889,
0.002145636361092329,
0.008230569772422314,
0.009641669690608978,
-0.0020414614118635654,
0.008045834489166737,
-0.0032844331581145525,
-0.02168271690607071,
0.002436763374134898,
-0.004363480489701033,
-0.005509168840944767,
0.0033041115384548903,
0.00612524664029479,
0.010168244130909443,
-0.0008073814096860588,
0.0030142981559038162,
-0.001019264804199338,
0.0024664041120558977,
-0.0015331180766224861,
0.006688195746392012,
-0.002025487832725048,
0.004519192036241293,
-0.008694867603480816,
0.008926628157496452,
-0.008363492786884308,
-0.001418719650246203,
0.0026998892426490784,
-0.002778862603008747,
0.012195123359560966,
0.005125139374285936,
-0.002063733758404851,
-0.0019415216520428658,
-0.010993804782629013,
-0.0034515259321779013,
0.002081562066450715,
0.0015667799161747098,
-0.008094143122434616,
0.0032198827248066664,
0.000736111425794661,
0.004597783088684082,
0.007029613945633173,
-0.006957434583455324,
0.005240727681666613,
0.003843732178211212,
-0.006080367136746645,
0.0015775642823427916,
-0.005428998731076717,
0.0017462031682953238,
0.0046647391282022,
-0.0076785217970609665,
-0.005986467003822327,
0.0020948618184775114,
-0.0066474126651883125,
-0.006292190868407488,
0.006592958699911833,
-0.011323550716042519,
-0.006829367950558662,
-0.0008271722472272813,
-0.010548959486186504,
-0.0009732395992614329
] |
8a29601d340f52437bc81f042a9b4102018cde77 | 19,710 | py | Python | generators/generate_pybind11_bindings.py | sweptlaser/pclpy | ab84da7ed264b5bc918af0d858e6d4063275aab9 | [
"MIT"
] | null | null | null | generators/generate_pybind11_bindings.py | sweptlaser/pclpy | ab84da7ed264b5bc918af0d858e6d4063275aab9 | [
"MIT"
] | null | null | null | generators/generate_pybind11_bindings.py | sweptlaser/pclpy | ab84da7ed264b5bc918af0d858e6d4063275aab9 | [
"MIT"
] | null | null | null | import os
import platform
import shutil
import sys
from collections import Counter
from collections import defaultdict, OrderedDict
from os.path import join
from typing import List, Dict, Set
from CppHeaderParser import CppHeaderParser
from CppHeaderParser.CppHeaderParser import CppMethod
import generators.dependency_tree
from generators.config import common_includes, PCL_BASE, PATH_LOADER, PATH_MODULES, MODULES_TO_BUILD, \
HEADERS_TO_SKIP, ATTRIBUTES_TO_SKIP, CLASSES_TO_IGNORE, METHODS_TO_SKIP, SUBMODULES_TO_SKIP, EXPLICIT_INCLUDES, \
SPECIALIZED_TEMPLATED_TYPES_TO_SKIP
from generators.definitions.function import generate_function_definitions, get_methods_defined_outside
from generators.definitions.method import split_methods_by_type
from generators.definitions.submodule_loader import generate_loader
from generators.definitions.templated_class import ClassDefinition
from generators.instantiations import Instantiations
from generators.point_types_utils import unpack_yaml_point_types
from generators.utils import make_header_include_name, sort_headers_by_dependencies, \
generate_main_loader, make_namespace_class, read_header_file
def filter_methods_for_parser_errors(methods):
return [m for m in methods if not m["name"] in ("void", "bool")]
def filter_methods_to_skip(methods):
filtered_methods = []
for m in methods:
if (m["parent"]["name"], m["name"]) in METHODS_TO_SKIP:
continue
if "Callback" in m["name"]:
single_argument = len(m["parameters"]) == 1
boost_function = single_argument and m["parameters"][0]["type"].startswith("boost::function")
if not boost_function:
continue
filtered_methods.append(m)
return filtered_methods
def same_parameters(p1: Dict, p2: Dict) -> bool:
fields = ["constant", "name", "raw_type", "reference", "static"]
return all(p1[f] == p2[f] for f in fields)
def same_methods(m1: CppMethod, m2: CppMethod) -> bool:
if m1["name"] != m2["name"]:
return False
# bug in CppHeaderParser
# in "void ImageGrabber<PointT>::publish", "void ImageGrabber<PointT>::" is the return type
path = m1.get("path", m2.get("path"))
path = path[path.rfind(":") + 1:]
if not any(path in type_ for type_ in [m1["rtnType"], m2["rtnType"]]):
return False
# same parameters
for p1 in m1["parameters"]:
for p2 in m2["parameters"]:
if m1["name"] == m2["name"] and same_parameters(p1, p2):
break
else:
return False
return len(m1["parameters"]) == len(m2["parameters"])
def private_methods_defined_outside(private_methods: List[CppMethod],
methods_declared_outside: List[CppMethod]) -> List[CppMethod]:
private_defined_outside = []
for m_private in private_methods:
for m_outside in methods_declared_outside:
if same_methods(m_private, m_outside):
private_defined_outside.append(m_private)
break
return private_defined_outside
def generate_class_definitions(main_classes,
module,
header_name,
path,
needs_overloading: List[str],
methods_defined_outside: List[CppMethod]) -> str:
text = []
a = text.append
a(common_includes)
a(EXPLICIT_INCLUDES.get((module, header_name), ""))
a(make_header_include_name(module, header_name, path))
a("")
namespaces = set([c["namespace"] for c in main_classes])
for namespace in namespaces:
if not namespace == "pcl":
a("using namespace %s;" % namespace)
a("\n")
for class_ in main_classes:
methods = class_["methods"]["public"]
methods = filter_methods_for_parser_errors(methods)
methods = filter_methods_to_skip(methods)
private_and_protected = class_["methods"]["private"] + class_["methods"]["protected"]
methods += private_methods_defined_outside(private_and_protected, methods_defined_outside)
class_properties = [p for p in class_["properties"]["public"]
if not "using" in p["type"]
and not "union" in p["type"]]
union_properties = [p for nested_class in class_["nested_classes"]
for p in nested_class["properties"]["public"]
if "union" in nested_class["name"]]
class_properties += union_properties
class_properties = filter_class_properties(module, header_name, class_["name"], class_properties)
constructors, variables, others = split_methods_by_type(methods, class_properties,
needs_overloading)
if not class_["can_be_instantiated"]:
constructors = []
class_def = ClassDefinition(class_, constructors, variables, others, module)
a(class_def.to_class_function_definition())
a("")
return "\n".join(text)
def filter_class_properties(module, header, class_name, properties):
key = (module, header, class_name)
# ignore properties without a name
properties = [p for p in properties if p["name"]]
if key in ATTRIBUTES_TO_SKIP:
to_ignore = ATTRIBUTES_TO_SKIP[key]
filtered_properties = []
for p in properties:
if p["name"] in to_ignore:
continue
filtered_properties.append(p)
properties = filtered_properties
return properties
def get_main_classes(header, module, header_name):
# header = read_headers(base_path, header_name, module)
main_classes = [c for c in header.classes.values() if c["namespace"] in ("pcl", "pcl::" + module)]
filtered_main_classes = []
for class_ in main_classes:
specialized_template = class_.get("template") and "<" in class_["name"]
if specialized_template:
to_skip = any(("<%s>" % type_) in class_["name"] for type_ in SPECIALIZED_TEMPLATED_TYPES_TO_SKIP)
if not to_skip:
message = "Warning: Template class specialization not implemented for class %s in %s"
print(message % (class_["name"], header_name))
elif (module, header_name, class_["name"]) in CLASSES_TO_IGNORE:
pass
else:
filtered_main_classes.append(class_)
filtered_main_classes = sorted(filtered_main_classes, key=lambda c: c["name"])
return filtered_main_classes
def get_functions(header, module):
functions = [f for f in header.functions if f["namespace"] in ("pcl",
"pcl::",
"pcl::%s" % module,
"pcl::%s::" % module)]
functions = sorted(functions, key=lambda f: f["name"])
filtered = filter_module_level_functions(functions)
return filtered
def filter_module_level_functions(functions: List[CppMethod]):
filtered = []
for f in functions:
keep = True
if f.get("returns_const"):
keep = False
for param in f["parameters"]:
for type_ in SPECIALIZED_TEMPLATED_TYPES_TO_SKIP:
if type_ in param["type"]:
keep = False
if keep:
filtered.append(f)
return filtered
def get_variables(header):
variables = [v for v in header.variables if v.get("defaultValue") and 'using' != v.get('type')]
variables = sorted(variables, key=lambda v: v["name"])
return variables
def get_enums(header):
enums = [e for e in header.enums if e.get("name")] # skip nameless enums
enums = sorted(enums, key=lambda v: v["name"])
return enums
def read_header(header_path, skip_macros=None):
# I tried to do this in multiple threads but it seems like CppHeaderParser is not thread safe...
if skip_macros is None:
skip_macros = []
header_file_str = read_header_file(header_path, skip_macros)
parser = CppHeaderParser
parser.debug = False
header = parser.CppHeader(header_file_str, argType="string")
return header
def clean():
try:
os.remove(PATH_LOADER)
except FileNotFoundError:
pass
if os.path.exists(PATH_MODULES):
shutil.rmtree(PATH_MODULES)
def check_if_needs_overloading(main_classes):
needs_overloading = {}
classes_by_module = defaultdict(list)
for (module, _), class_ in main_classes.items():
classes_by_module[module] += class_
for module, classes in classes_by_module.items():
needs = []
for class_ in classes:
count = Counter(m["name"] for methods in class_["methods"].values() for m in methods)
for name, count in count.items():
if count >= 2:
needs.append(name)
needs_overloading[module] = needs
return needs_overloading
def get_headers(modules=None, skip_modules=None):
def listmod(module):
found_modules = []
for base, folders, files in os.walk(join(PCL_BASE, module)):
if any(base.endswith(m) for m in SUBMODULES_TO_SKIP):
continue
relative_base = os.path.abspath(base).replace(PCL_BASE, "")[1:]
for f in files:
if f.endswith(".h"):
found_modules.append([f, join(relative_base, f)])
return found_modules
if modules is None:
modules = MODULES_TO_BUILD
if skip_modules is not None:
modules = [m for m in modules if m not in skip_modules]
headers_to_generate = [(module, header_name, path) for module in modules
for header_name, path in listmod(module)]
base_headers = [("", f, f) for f in os.listdir(PCL_BASE) if f.endswith(".h")]
headers_to_generate += base_headers
headers_to_generate_temp = []
for module, header_name, path in headers_to_generate:
if (module, header_name) in HEADERS_TO_SKIP:
continue
headers_to_generate_temp.append(tuple([module, header_name, path]))
return headers_to_generate_temp
def get_pure_virtual_methods(class_: CppHeaderParser.CppClass) -> Set[str]:
access = "private protected public".split()
return set([m["name"] for a in access for m in class_["methods"][a] if m["pure_virtual"]])
def get_all_class_methods_not_pure_virtual(class_: CppHeaderParser.CppClass) -> Set[str]:
access = "private protected public".split()
return set([m["name"] for a in access for m in class_["methods"][a] if not m["pure_virtual"]])
def flag_instantiatable_class(dependency_tree, main_classes):
"""determine if the class can be instantiated"""
main_classes_by_name_namespace = {make_namespace_class(c["namespace"], c["name"]): c
for classes in main_classes.values() for c in classes}
for module, header_name in main_classes:
for class_ in main_classes[(module, header_name)]:
can_be_instantiated = True
if class_["abstract"]:
can_be_instantiated = False
else:
# check if any pure virtual method is not implemented
all_implemented_inherited_methods = get_all_class_methods_not_pure_virtual(class_)
namespace_class = make_namespace_class(class_["namespace"], class_["name"])
for base_name_nsp in dependency_tree.breadth_first_iterator(namespace_class):
base_class = main_classes_by_name_namespace.get(base_name_nsp)
if base_class:
base_class_methods = get_all_class_methods_not_pure_virtual(base_class)
all_implemented_inherited_methods.update(base_class_methods)
for base_name_nsp in dependency_tree.breadth_first_iterator(namespace_class):
base_class = main_classes_by_name_namespace.get(base_name_nsp)
if base_class and base_class["abstract"]:
base_pure_virtual_methods = get_pure_virtual_methods(base_class)
if base_pure_virtual_methods - all_implemented_inherited_methods:
can_be_instantiated = False
class_["can_be_instantiated"] = can_be_instantiated
def load_yaml_point_types(not_every_point_type):
classes_point_types = unpack_yaml_point_types("point_types_generated.yml", not_every_point_type)
extra_point_types = unpack_yaml_point_types("point_types_extra.yml")
for k, v in extra_point_types.items():
if k in classes_point_types:
classes_point_types[k].append(v)
else:
classes_point_types[k] = v
return classes_point_types
def make_module_dirs(modules):
for module in modules:
module_dir = join(PATH_MODULES, module)
if not os.path.exists(module_dir):
os.makedirs(module_dir)
def is_file_different(path, text):
v = open(path).read()
if v != text:
print("File is different: %s" % os.path.split(path)[1])
return True
# print("File is the same: %s" % os.path.split(path)[1])
return False
def write_if_different(files_to_write, delete_others):
written = []
for base, folder, files in os.walk(PATH_MODULES):
for f in files:
path = join(base, f)
if path in files_to_write:
if is_file_different(path, files_to_write[path]):
open(path, "w").write(files_to_write[path])
written.append(path)
elif delete_others:
os.remove(path)
print("Deleted: " + path)
# write new files
for path, text in files_to_write.items():
if path not in written:
open(path, "w").write(files_to_write[path])
def delete_other_dirs(modules):
for f in os.listdir(PATH_MODULES):
folder = join(PATH_MODULES, f)
if f not in modules and os.path.isdir(folder):
shutil.rmtree(folder, ignore_errors=True)
def write_stuff_if_needed(generated_headers: OrderedDict, delete_others=True):
modules = set(module for module, _ in generated_headers.keys())
make_module_dirs(modules)
# hpp
files_to_write = {}
for (module, header_name), text in generated_headers.items():
if text:
output_path = join(PATH_MODULES, module, header_name + "pp")
files_to_write[output_path] = text
# loaders
loader_modules = defaultdict(list)
for (module, header_name), text in generated_headers.items():
if text:
loader_modules[module or "base"].append(header_name)
for module, headers in loader_modules.items():
path_loader = join(PATH_MODULES, "_%s_loader.cpp" % module)
files_to_write[path_loader] = generate_loader(module, headers)
files_to_write[PATH_LOADER] = generate_main_loader(loader_modules)
write_if_different(files_to_write, delete_others)
if delete_others:
delete_other_dirs(modules)
def generate(headers_to_generate, skip_macros, not_every_point_type=False) -> OrderedDict:
"""
:return: OrderedDict
"""
main_classes, module_functions, module_variables, module_enums = {}, {}, {}, {}
for module, header_name, path in headers_to_generate[:]:
header_full_path = join(PCL_BASE, path) if path else join(PCL_BASE, module, header_name)
header = read_header(header_full_path, skip_macros)
main_classes[(module, header_name)] = get_main_classes(header, module, header_name)
module_functions[(module, header_name)] = get_functions(header, module)
module_variables[(module, header_name)] = get_variables(header)
module_enums[(module, header_name)] = get_enums(header)
classes = [c for module, header, path in headers_to_generate
for c in main_classes[(module, header)]]
dependency_tree = generators.dependency_tree.DependencyTree(classes)
loaded_point_types = load_yaml_point_types(not_every_point_type)
classes_point_types: OrderedDict = dependency_tree.get_point_types_with_dependencies(loaded_point_types)
classes_sorted_base_first = list(dependency_tree.leaf_iterator())
def index_for_class(class_):
return classes_sorted_base_first.index(make_namespace_class(class_["namespace"], class_["name"]))
# sort classes inside modules based on inheritance
for module, header in main_classes:
main_classes[(module, header)] = list(sorted(main_classes[(module, header)], key=index_for_class))
headers_to_generate = sort_headers_by_dependencies(headers_to_generate, skip_macros=skip_macros)
methods_need_overloading = check_if_needs_overloading(main_classes)
flag_instantiatable_class(dependency_tree, main_classes)
def generate_header(module, header, path, keep_if_no_instantiation) -> str:
header_functions = module_functions[(module, header)]
header_classes = main_classes[(module, header)]
methods_defined_outside = get_methods_defined_outside(header_functions)
class_definitions = generate_class_definitions(header_classes,
module,
header,
path,
methods_need_overloading.get(module),
methods_defined_outside)
function_definitions = generate_function_definitions(header_functions,
module,
header,
not_every_point_type=not_every_point_type)
instantiations = Instantiations(header_classes,
module,
header,
classes_point_types,
module_variables[(module, header)],
module_enums[(module, header)],
)
instantiation_function = instantiations.generate_instantiation_function(has_functions=bool(header_functions))
something_instantiated = len(instantiation_function.split("\n")) > 2
text = []
if something_instantiated or keep_if_no_instantiation:
text = [class_definitions, function_definitions, instantiation_function]
return "\n".join(text)
generated_headers = OrderedDict()
for module, header, path in headers_to_generate:
generated_headers[(module, header)] = generate_header(module, header, path, keep_if_no_instantiation=False)
return generated_headers
def main():
import time
t = time.time()
windows = platform.system() == "Windows"
skip_macros = []
skip_modules = []
if not windows:
skip_macros = ["_MSC_VER"]
#skip_modules = ["visualization"]
skip_modules = []
all_headers = get_headers(skip_modules=skip_modules)
not_every_point_type = "--not-every-point-type" in sys.argv
generated_headers = generate(all_headers, skip_macros, not_every_point_type)
write_stuff_if_needed(generated_headers, delete_others=True)
print("generated in %.2f s" % (time.time() - t,))
if __name__ == '__main__':
main()
| 40.22449 | 117 | 0.640589 | 1 | 1.9836 | [
-0.06181016564369202,
0.014262111857533455,
-0.02182135544717312,
0.06732065230607986,
0.015137813985347748,
0.026492908596992493,
-0.04459414258599281,
0.01183068286627531,
-0.030758921056985855,
0.010837427340447903,
0.02257605455815792,
0.01225785817950964,
-0.005704379640519619,
0.005319088231772184,
-0.015413070097565651,
0.007811019662767649,
0.13792400062084198,
0.015094124712049961,
-0.02178076282143593,
0.0016984182875603437,
0.005965324584394693,
0.0112720662727952,
-0.03974180296063423,
0.01395399495959282,
0.025079907849431038,
0.028832318261265755,
0.04011157527565956,
0.004768583457916975,
0.007119053043425083,
-0.015355868265032768,
-0.01881360448896885,
0.0010940672364085913,
0.004277590196579695,
0.008096115663647652,
-0.057625092566013336,
0.022859647870063782,
0.0069281067699193954,
0.0014287985395640135,
0.014416221529245377,
0.01193904411047697,
0.011125626973807812,
-0.0014513181522488594,
-0.027003703638911247,
-0.025572622194886208,
0.013740342110395432,
-0.011073957197368145,
0.013528809882700443,
-0.025081833824515343,
-0.07505860924720764,
-0.01068242359906435,
0.0041351318359375,
0.04847823083400726,
-0.027276238426566124,
0.017079545184969902,
-0.014052296057343483,
-0.03657005354762077,
0.014773032627999783,
-0.006653792690485716,
-0.02464897930622101,
-0.03026723489165306,
0.005974892992526293,
0.027675434947013855,
0.011327001266181469,
-0.022011516615748405,
0.026661016047000885,
-0.0273966733366251,
-0.011960047297179699,
-0.01909147948026657,
0.013290773145854473,
-0.035366885364055634,
-0.030264927074313164,
-0.006613488774746656,
0.028624964877963066,
0.058249473571777344,
0.03560587018728256,
-0.0038833003491163254,
-0.04094323515892029,
0.0037450711242854595,
-0.032865289598703384,
0.016489464789628983,
-0.03125578910112381,
0.05724915489554405,
-0.028878653421998024,
-0.014669043011963367,
-0.0070229219272732735,
0.0003375274536665529,
0.06513886898756027,
-0.05042743310332298,
0.026779253035783768,
0.03689249977469444,
-0.04865729808807373,
-0.013191286474466324,
-0.025808585807681084,
0.009075385518372059,
-0.0037541487254202366,
-0.020493242889642715,
0.01963297463953495,
0.004575767088681459,
0.020755209028720856,
-0.0038211510982364416,
0.012958158738911152,
-0.0356840156018734,
0.036136072129011154,
-0.03648902103304863,
0.011129564605653286,
0.0196627639234066,
-0.0393262654542923,
-0.014239706099033356,
-0.004110009875148535,
0.0070548937655985355,
-0.06459423154592514,
-0.005183094181120396,
0.040663447231054306,
0.0004607715818565339,
-0.007146039977669716,
-0.019461028277873993,
0.0009529482340440154,
0.01634398102760315,
0.037702467292547226,
0.05646660923957825,
-0.011889220215380192,
0.0033951452933251858,
-0.0013323461171239614,
-0.009664339013397694,
-0.013064486905932426,
0.0638337954878807,
0.03919368237257004,
-0.03507108613848686,
0.04305587708950043,
-0.005619403440505266,
0.004456826485693455,
0.01398013997823,
0.008343499153852463,
-0.037035949528217316,
0.018249142915010452,
-0.0007930897991172969,
-0.009576153010129929,
0.009487351402640343,
-0.06642325967550278,
0.045526616275310516,
0.00574952969327569,
0.016337839886546135,
-0.007214730605483055,
-0.022182077169418335,
0.005480063613504171,
-0.06476423144340515,
0.007901676930487156,
-0.033689457923173904,
0.03341379389166832,
-0.02221929468214512,
0.011511677876114845,
0.034392133355140686,
-0.008864590898156166,
0.01772763766348362,
-0.0007123093819245696,
-0.0340227447450161,
-0.009979899041354656,
-0.08945353329181671,
-0.0022368410136550665,
0.01620388962328434,
-0.02115936391055584,
-0.008257553912699223,
0.003687704913318157,
-0.010054642334580421,
0.022393610328435898,
0.03903478756546974,
-0.05203874781727791,
0.016405215486884117,
-0.011359569616615772,
-0.014825649559497833,
-0.0015407797181978822,
-0.022691253572702408,
-0.06198348104953766,
0.02400181256234646,
-0.008501371368765831,
-0.021083993837237358,
-0.011902989819645882,
0.005497741512954235,
0.042251087725162506,
0.006816398352384567,
0.03911558538675308,
0.006226419471204281,
0.004810177255421877,
0.06066044047474861,
0.009218787774443626,
0.03986617177724838,
-0.049256451427936554,
-0.041698236018419266,
0.008543252013623714,
-0.013394230045378208,
-0.011534101329743862,
0.015510190278291702,
0.01299781072884798,
-0.015122000128030777,
0.02609775774180889,
-0.0018282881937921047,
-0.008313761092722416,
-0.012891136109828949,
-0.00831420999020338,
0.0063852532766759396,
-0.009242112748324871,
-0.011983613483607769,
-0.03779257461428642,
-0.025344010442495346,
0.007933189161121845,
0.008260619826614857,
-0.6353575587272644,
0.036318179219961166,
0.01530715823173523,
0.004153215792030096,
0.0030523925088346004,
0.021632499992847443,
0.0089982058852911,
-0.0011190352961421013,
0.015799930319190025,
0.01921697147190571,
-0.01030068937689066,
-0.03173746541142464,
-0.010819349437952042,
0.0020702776964753866,
-0.013030657544732094,
0.004871940240263939,
0.02086961455643177,
-0.016346629709005356,
-0.012883567251265049,
0.000028322530852165073,
-0.003407174488529563,
-0.035693369805812836,
0.009031135588884354,
0.03474272042512894,
-0.00412775669246912,
-0.01952134072780609,
-0.010795087553560734,
0.0013001597253605723,
0.004608931485563517,
0.029121480882167816,
-0.006789505016058683,
0.036000244319438934,
0.02375931479036808,
-0.0068058958277106285,
0.04060611501336098,
-0.0068418895825743675,
0.05982838198542595,
-0.028523972257971764,
-0.025860682129859924,
-0.018936801701784134,
-0.02490144781768322,
-0.021615788340568542,
-0.011635408736765385,
-0.05249156430363655,
-0.02305561676621437,
-0.04204000160098076,
0.012943903915584087,
0.01942511275410652,
0.00672039482742548,
0.024627910926938057,
0.00761419115588069,
0.05026585981249809,
0.04394301027059555,
-0.013768517412245274,
-0.02409840188920498,
0.011871526017785072,
-0.008593803271651268,
-0.003575726877897978,
-0.038617368787527084,
-0.019414590671658516,
-0.010540781542658806,
-0.04641050100326538,
-0.0077054258435964584,
0.04383851960301399,
-0.002243775175884366,
-0.0029064470436424017,
-0.004751505795866251,
-0.035379961133003235,
-0.0087223956361413,
0.034154750406742096,
0.026348482817411423,
-0.002065458567813039,
-0.00921670626848936,
0.020303018391132355,
-0.0008544835727661848,
0.007234633434563875,
-0.049974873661994934,
0.025315962731838226,
-0.019159991294145584,
-0.033319856971502304,
0.030177036300301552,
-0.017209630459547043,
-0.030484501272439957,
-0.02177469991147518,
-0.029168425127863884,
-0.02836764045059681,
-0.008324779570102692,
-0.03045608103275299,
-0.00844652857631445,
0.04744868725538254,
0.047235000878572464,
0.020383106544613838,
0.0031425943598151207,
-0.000404945807531476,
0.007449097465723753,
-0.02394734136760235,
0.03771614655852318,
0.054101355373859406,
0.02301020920276642,
0.01799890771508217,
-0.0146474689245224,
0.043682683259248734,
0.018086282536387444,
-0.0022352454252541065,
-0.026130003854632378,
0.008278993889689445,
-0.03476617485284805,
-0.01520658377557993,
0.029935957863926888,
-0.047817353159189224,
0.0049160136841237545,
0.00719334464520216,
-0.031804561614990234,
0.03487144038081169,
0.04631771519780159,
-0.03479059040546417,
-0.03697860613465309,
0.0011460956884548068,
0.006339992396533489,
0.0019407450454309583,
-0.002094392431899905,
0.0015345829306170344,
-0.048490259796381,
0.0316179059445858,
0.018424667418003082,
0.01722429320216179,
-0.006989005021750927,
0.010144652798771858,
-0.0014902726979926229,
-0.0007188777672126889,
-0.04901505261659622,
-0.002624091925099492,
-0.043244753032922745,
-0.024884961545467377,
-0.0012500244192779064,
-0.042356301099061966,
-0.002449627732858062,
-0.018835393711924553,
0.012482541613280773,
0.0009105685167014599,
-0.015225371345877647,
0.014367982745170593,
0.03123987838625908,
-0.015298615209758282,
0.012702091597020626,
-0.000899498991202563,
0.006148835644125938,
0.006946685258299112,
0.015444738790392876,
0.011590221896767616,
0.0012972350232303143,
0.06866397708654404,
0.004575876519083977,
-0.0015240192878991365,
-0.015766343101859093,
-0.012288518249988556,
-0.025121046230196953,
0.03183053806424141,
0.034729085862636566,
0.0034255057107657194,
-0.014613247476518154,
-0.010965253226459026,
0.01850549504160881,
0.02602645382285118,
0.019954999908804893,
-0.011669541709125042,
0.00897469837218523,
0.0843975841999054,
0.017153099179267883,
0.035113755613565445,
0.040839556604623795,
-0.04065866023302078,
-0.0052370536141097546,
0.061218440532684326,
-0.009399902075529099,
0.025285590440034866,
0.001264201127924025,
-0.05804457888007164,
-0.010106857866048813,
-0.012027912773191929,
0.005758519284427166,
-0.021092580631375313,
0.004429839085787535,
-0.02318587340414524,
-0.00672672875225544,
0.006246846169233322,
-0.00586106488481164,
0.012947703711688519,
0.04669773206114769,
-0.006754000671207905,
0.05018480867147446,
-0.020381992682814598,
0.0008476703660562634,
-0.037519704550504684,
-0.051028911024332047,
0.009332469664514065,
0.004218478687107563,
-0.020092884078621864,
-0.0028458968736231327,
-0.010402307845652103,
-0.041347187012434006,
0.06498107314109802,
-0.011963853612542152,
-0.02150971069931984,
0.029840121045708656,
0.050478655844926834,
0.012786380015313625,
-0.0046454682014882565,
-0.006915454752743244,
0.03882676362991333,
-0.02040785364806652,
-0.024828676134347916,
-0.017000341787934303,
-0.016963696107268333,
-0.03248440846800804,
0.032629624009132385,
-0.0725770890712738,
-0.007867386564612389,
0.011440977454185486,
-0.04435050114989281,
0.01755312830209732,
-0.020068366080522537,
0.005844664294272661,
0.008098652586340904,
0.012409830465912819,
0.01321263425052166,
-0.0479302741587162,
-0.0034964492078870535,
0.0010430736001580954,
-0.010375936515629292,
0.025439854711294174,
0.010128903202712536,
0.0016360225854441524,
-0.016343561932444572,
-0.025257736444473267,
0.010959829203784466,
-0.031970568001270294,
-0.05272381007671356,
-0.011487066745758057,
-0.016574788838624954,
0.05207821726799011,
0.0052278293296694756,
-0.012285321950912476,
-0.01618431881070137,
0.01155158318579197,
-0.01613740622997284,
0.012853854335844517,
-0.015440627932548523,
-0.024669861420989037,
-0.021677913144230843,
-0.08063225448131561,
0.07924923300743103,
0.007551823742687702,
0.027020785957574844,
-0.0033024807926267385,
0.006510613020509481,
0.007598387077450752,
-0.007994867861270905,
-0.020310232415795326,
-0.029757067561149597,
-0.006316467188298702,
-0.02852325327694416,
0.05805283039808273,
0.010628941468894482,
-0.009556774981319904,
0.04261237755417824,
0.039963070303201675,
-0.020444011315703392,
0.029970357194542885,
0.04207669198513031,
-0.0034486798103898764,
-0.0018154619028791785,
0.011770332232117653,
0.0383593775331974,
0.03731721267104149,
-0.004730351734906435,
-0.004103329498320818,
-0.0064459596760571,
-0.02145150862634182,
0.054980047047138214,
-0.02493421919643879,
0.03866179287433624,
0.024713508784770966,
0.03446335718035698,
0.016490841284394264,
0.040992751717567444,
-0.038775425404310226,
-0.019194668158888817,
-0.008331172168254852,
0.016634264960885048,
0.018420960754156113,
-0.04916456714272499,
0.058685339987277985,
0.06345196068286896,
0.0156503077596426,
-0.026099462062120438,
-0.019462797790765762,
0.011583198793232441,
-0.012775004841387272,
0.03205963596701622,
0.03355017304420471,
-0.012292004190385342,
-0.021564416587352753,
0.03844898194074631,
-0.03346865996718407,
-0.03278510645031929,
0.008642436005175114,
-0.004414360038936138,
0.026148267090320587,
0.022383352741599083,
0.015946421772241592,
0.010971598327159882,
-0.02660820074379444,
0.04099857062101364,
0.030375925824046135,
0.02081988751888275,
0.05100912228226662,
0.008431557565927505,
0.0031778065022081137,
0.016870304942131042,
-0.029716501012444496,
0.012071959674358368,
-0.02101142518222332,
-0.021273158490657806,
0.03156106919050217,
-0.013117052614688873,
-0.008088544942438602,
-0.010831034742295742,
-0.014599285088479519,
-0.010571548715233803,
-0.04227554053068161,
-0.0047471108846366405,
0.009355596266686916,
0.007802911102771759,
0.01382480375468731,
0.01135808601975441,
0.02808728814125061,
0.016812728717923164,
-0.0038366124499589205,
0.03143821656703949,
0.0036754768807440996,
0.01269889809191227,
0.011070970445871353,
0.007498602848500013,
-0.010125942528247833,
-0.04642505571246147,
-0.07717867940664291,
0.044777072966098785,
0.03445941209793091,
-0.016015419736504555,
0.017247729003429413,
-0.02134687267243862,
-0.014109721407294273,
0.01385126356035471,
-0.01808868534862995,
-0.006333285942673683,
0.007872524671256542,
0.004469431936740875,
-0.01382324006408453,
0.056561365723609924,
-0.00012498920841608196,
0.01955406926572323,
0.016833290457725525,
-0.009803485125303268,
-0.02883797325193882,
-0.03277931362390518,
0.029698431491851807,
0.0033203898929059505,
0.005197638180106878,
-0.021842069923877716,
-0.005273905582726002,
-0.00902055948972702,
-0.03614671155810356,
0.015275822021067142,
0.015892980620265007,
0.03894197568297386,
0.017627688124775887,
-0.01281958818435669,
-0.016402840614318848,
-0.0629895031452179,
-0.005432736128568649,
-0.03781542927026749,
0.04586424306035042,
0.007972550578415394,
0.03658127412199974,
-0.07716703414916992,
-0.011203904636204243,
0.03340285271406174,
-0.057868365198373795,
-0.03774527087807655,
-0.022156113758683205,
-0.040759652853012085,
-0.0016330803046002984,
0.043508920818567276,
0.013528184033930302,
-0.020146265625953674,
-0.0055622318759560585,
-0.00646832725033164,
0.014104378409683704,
0.0034037563018500805,
0.0020737459417432547,
-0.04520409554243088,
-0.009019268676638603,
-0.018858764320611954,
0.029013359919190407,
-0.000031629399018129334,
0.0019859063904732466,
-0.024245712906122208,
-0.0017250303644686937,
0.016764210537075996,
-0.0006044212495908141,
0.034497614949941635,
-0.006077034864574671,
-0.04340861737728119,
-0.00280136545188725,
-0.00804371852427721,
-0.027348948642611504,
-0.033064041286706924,
-0.0010831382824108005,
-0.0030328831635415554,
-0.03155400976538658,
-0.035529833287000656,
0.006113743409514427,
-0.010158918797969818,
-0.02710334025323391,
-0.04353849217295647,
-0.033857718110084534,
0.0005404074909165502,
-0.03803623095154762,
0.003916371613740921,
0.0032542922999709845,
-0.07105644792318344,
0.0011002998799085617,
0.007537561468780041,
0.020408106967806816,
0.00575303053483367,
-0.019793961197137833,
-0.03811105713248253,
0.05291105434298515,
0.0050145708955824375,
0.02904585190117359,
-0.010465901345014572,
-0.058957166969776154,
0.025797318667173386,
-0.02520323172211647,
-0.07602330297231674,
0.022645609453320503,
0.00016612261242698878,
0.018961835652589798,
0.012101434171199799,
0.009456734172999859,
-0.01813054457306862,
-0.02664344571530819,
0.00879497267305851,
0.015721134841442108,
0.016459403559565544,
0.05419100448489189,
0.01882306858897209,
0.05011206865310669,
0.03587239608168602,
-0.02085363306105137,
0.02910950593650341,
0.03496050462126732,
0.03111848421394825,
0.01985819824039936,
0.03665472939610481,
-0.005397012922912836,
-0.0155936349183321,
0.01830979250371456,
0.001787147601135075,
-0.029695609584450722,
0.032436393201351166,
0.0139351487159729,
0.03711475431919098,
0.014644050039350986,
0.011089948937296867,
-0.008423102088272572,
-0.027220340445637703,
0.06946734338998795,
0.012490815483033657,
-0.014565592631697655,
0.020147809758782387,
0.02462962456047535,
-0.003309220541268587,
0.030729759484529495,
0.04911999776959419,
-0.018949754536151886,
-0.00927394162863493,
-0.01692420244216919,
0.04975187033414841,
-0.022166425362229347,
0.0022504115477204323,
-0.02922600694000721,
0.0011563812149688601,
0.0077964020892977715,
-0.036978282034397125,
0.022368820384144783,
-0.028068339452147484,
0.00260388245806098,
-0.030645882710814476,
-0.0019823270849883556,
-0.016625171527266502,
0.038716528564691544,
-0.04036845266819,
0.017573386430740356,
-0.021196501329541206,
0.014775121584534645,
0.0296370517462492,
-0.006039564032107592,
-0.035647839307785034,
-0.004935144446790218,
0.016548212617635727,
0.0007888792897574604,
-0.05995453521609306,
0.011297052726149559,
0.024494556710124016,
0.052065636962652206,
-0.003568225773051381,
-0.027579428628087044,
-0.05598435178399086,
0.019595924764871597,
0.022996507585048676,
0.018282923847436905,
-0.012562033720314503,
0.014142556115984917,
0.006114481016993523,
-0.05938015133142471,
0.0329049788415432,
0.007600495591759682,
0.01048379298299551,
-0.01236247643828392,
0.0023937432561069727,
-0.04226066544651985,
0.012817109003663063,
-0.021309437230229378,
-0.035933904349803925,
0.005886481609195471,
0.012952202931046486,
-0.021765973418951035,
-0.034010205417871475,
0.03128403425216675,
-0.007593868300318718,
0.0006590598495677114,
0.02659822441637516,
-0.04463711753487587,
-0.004533916246145964,
0.021274197846651077,
0.05652708187699318,
0.016562489792704582,
-0.009046520106494427,
0.0028079405892640352,
0.009027589112520218,
-0.07458445429801941,
-0.014025299809873104,
0.001473071752116084,
-0.031046874821186066,
-0.004890057723969221,
0.04049272835254669,
-0.00917370431125164,
-0.047869306057691574,
-0.005772612057626247,
0.01832912117242813
] |
8a29eefe067ae42942e4915562e64419af3d1cde | 950 | py | Python | scripts_python3/exchange/deleteExchange.py | bcvsolutions/winrm-ad-connector | 9b45dae78d3ba24fe6b00e090f8763d3162e1570 | [
"Apache-2.0"
] | null | null | null | scripts_python3/exchange/deleteExchange.py | bcvsolutions/winrm-ad-connector | 9b45dae78d3ba24fe6b00e090f8763d3162e1570 | [
"Apache-2.0"
] | 2 | 2020-05-27T07:15:28.000Z | 2020-12-17T05:22:54.000Z | scripts_python3/exchange/deleteExchange.py | bcvsolutions/winrm-ad-connector | 9b45dae78d3ba24fe6b00e090f8763d3162e1570 | [
"Apache-2.0"
] | null | null | null | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# All params from IdM is stored in environment and you can get them by os.environ["paramName"]
import sys, os
# this is needed for importing file winrm_wrapper from parent dir
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import winrm_wrapper
import codecs
uid = os.environ["__UID__"]
winrm_wrapper.writeLog("Delete start for " + uid)
# Load PS script from file and replace params
winrm_wrapper.writeLog("loading script")
f = codecs.open(os.environ["script"], encoding='utf-8', mode='r')
command = f.read()
command = command.replace("$uid", uid)
# Call wrapper
winrm_wrapper.executeScript(os.environ["endpoint"], os.environ["authentication"], os.environ["user"],
os.environ["password"], os.environ["caTrustPath"], os.environ["ignoreCaValidation"], command, uid)
winrm_wrapper.writeLog("Delete end for " + uid)
print("__UID__=" + uid)
sys.exit()
| 35.185185 | 134 | 0.705263 | 1 | 0.9561 | [
0.0021406710147857666,
0.02469176985323429,
0.008136658929288387,
-0.0010332155507057905,
0.004615438636392355,
-0.0016985140973702073,
-0.010866932570934296,
0.002525113755837083,
-0.006600199732929468,
0.003176832804456353,
0.0022113407030701637,
0.005732772871851921,
0.007942295633256435,
-0.017147311940789223,
0.0009995109867304564,
0.01602800562977791,
-0.05411114916205406,
-0.0005099520203657448,
-0.003610488958656788,
0.0011674542911350727,
-0.009285845793783665,
0.00952202919870615,
0.008956462144851685,
0.006454613525420427,
0.005863063503056765,
-0.0004489248094614595,
0.0097423754632473,
0.0031920422334223986,
-0.007433151826262474,
-0.006055241916328669,
-0.00008657056605443358,
-0.0005922787240706384,
-0.004804986994713545,
-0.008871220983564854,
0.005347065627574921,
-0.0038714176043868065,
-0.00012763601262122393,
-0.021123483777046204,
0.012697926722466946,
-0.005381283350288868,
-0.009085753001272678,
-0.015285123139619827,
-0.00045979837886989117,
0.0071695405058562756,
-0.00930668693035841,
0.001035712193697691,
-0.004581382963806391,
-0.0004561316454783082,
-0.010301551781594753,
0.005343167576938868,
-0.009673206135630608,
0.004377210047096014,
0.013367380015552044,
0.0043275984935462475,
-0.0056186276488006115,
-0.006569653749465942,
0.01373498048633337,
-0.0003841567668132484,
-0.01194895152002573,
-0.002360123908147216,
-0.004166410304605961,
-0.003473437624052167,
0.005928010679781437,
0.0029848527628928423,
-0.015141245909035206,
-0.008197045885026455,
-0.004924677778035402,
0.0024244750384241343,
-0.0021424072328954935,
0.006445153150707483,
0.0017034775810316205,
-0.0005771918804384768,
0.006422682199627161,
0.004484401550143957,
0.00650703115388751,
-0.002390194684267044,
-0.0026087008882313967,
0.0011691403342410922,
0.008568761870265007,
0.0019982648082077503,
0.0038912566378712654,
-0.008102433755993843,
0.0076689510606229305,
0.009474671445786953,
0.015864698216319084,
0.006794758141040802,
0.01614738442003727,
-0.011447872966527939,
0.04551500827074051,
0.007783119101077318,
-0.010350791737437248,
0.001727455761283636,
-0.008820004761219025,
-0.002768405247479677,
-0.004114612936973572,
-0.028357800096273422,
0.00012298631190788,
-0.004075675271451473,
-0.0008236262365244329,
0.004000098444521427,
0.00047229768824763596,
0.006965193897485733,
-0.0012860242277383804,
-0.003939933143556118,
-0.009161580353975296,
0.011957881040871143,
-0.009756394661962986,
-0.0037483416963368654,
0.004003510344773531,
0.003244773019105196,
-0.011001772247254848,
-0.0012521484168246388,
0.001457319245673716,
-0.01186759676784277,
0.002409374574199319,
0.0032471816521137953,
-0.004671098664402962,
0.0553162507712841,
-0.0008978775586001575,
0.004611489828675985,
-0.004439701791852713,
0.00042914689402095973,
-0.0010065868264064193,
0.00651821494102478,
0.010675692930817604,
-0.004387335851788521,
0.011056981980800629,
0.00592262065038085,
0.001718380255624652,
0.00709361769258976,
-0.002835006918758154,
0.006445078179240227,
-0.0038862950168550014,
-0.0008032125770114362,
0.0004030222771689296,
-0.008626035414636135,
0.007091624196618795,
-0.0018457149853929877,
-0.006032791920006275,
-0.00005317616887623444,
-0.0007632033666595817,
-0.009958235546946526,
0.00333703332580626,
-0.001370221027173102,
0.0057342322543263435,
-0.01008254662156105,
-0.005568282678723335,
-0.003386639291420579,
-0.004861640743911266,
0.0013378411531448364,
0.010291803628206253,
0.0047406298108398914,
0.004299154505133629,
-0.004363496787846088,
-0.007929974235594273,
0.00044472594163380563,
-0.004812963772565126,
0.0024502465967088938,
0.005581958685070276,
0.003501256462186575,
-0.01049656793475151,
-0.001216324046254158,
0.0025942877400666475,
0.0020707373041659594,
0.000014577881302102469,
0.002276657847687602,
-0.009403507225215435,
0.007513146847486496,
-0.0005759093910455704,
0.004552608821541071,
0.011771502904593945,
-0.004621316213160753,
-0.0012050041696056724,
0.00038442673394456506,
0.004449447151273489,
-0.000278207182418555,
0.0049738516099750996,
0.010532042942941189,
-0.004203720949590206,
-0.0040642693638801575,
0.005319868680089712,
0.003579977434128523,
0.007650999817997217,
0.0066757299937307835,
-0.0049365367740392685,
0.00233735260553658,
-0.005193235818296671,
-0.001007113722153008,
0.006459799129515886,
-0.003906539641320705,
0.007501591462641954,
0.003462487831711769,
-0.01513050589710474,
-0.00783392321318388,
-0.0001592556800460443,
-0.007618258241564035,
0.000578136183321476,
0.015213195234537125,
0.011400857008993626,
-0.0038720283191651106,
0.0033223696518689394,
-0.010260592214763165,
-0.000595906691160053,
0.00793147087097168,
0.0009505900088697672,
-0.012685433961451054,
-0.9584183096885681,
0.007237785495817661,
0.00359416869468987,
-0.0027850219048559666,
0.005575564689934254,
0.0028770167846232653,
0.005693127401173115,
0.004357474856078625,
0.01441448274999857,
-0.010806814767420292,
-0.00579058937728405,
-0.011317233555018902,
-0.009804664179682732,
-0.0008656723657622933,
-0.00793854333460331,
-0.0043509844690561295,
-0.0067921290174126625,
-0.006318334955722094,
-0.002011307282373309,
-0.002419104101136327,
-0.0012634588638320565,
0.007719329092651606,
-0.0001290698128286749,
0.005243042949587107,
0.002467092126607895,
0.0034016547724604607,
-0.0054976437240839005,
-0.0025970968417823315,
-0.0002985578612424433,
-0.0013811754761263728,
-0.005449903663247824,
-0.015078959055244923,
-0.004178536590188742,
-0.0005914206267334521,
0.011782941408455372,
0.000875515746884048,
0.008916663005948067,
-0.0030532842501997948,
0.0036039359401911497,
-0.009062342345714569,
0.0048017604276537895,
0.001739294151775539,
0.0029453702736645937,
-0.028991499915719032,
0.0014075437793508172,
0.0007056228932924569,
-0.007802610285580158,
0.0077017019502818584,
0.0016687167808413506,
-0.0014272574335336685,
-0.00237315078265965,
-0.005050498526543379,
0.008436774834990501,
-0.006460052914917469,
0.004523549694567919,
-0.005715972278267145,
-0.007146838586777449,
-0.002452410524711013,
-0.00889248214662075,
0.0007849829853512347,
0.0037785805761814117,
-0.004544641822576523,
-0.005169230978935957,
-0.004291035234928131,
0.0038570882752537727,
0.001746296533383429,
0.0013786808121949434,
-0.01703265868127346,
-0.004308778792619705,
-0.0018462508451193571,
0.002598700812086463,
-0.002180466428399086,
-0.002724036807194352,
0.0035953549668192863,
-0.008631461299955845,
0.006020886357873678,
0.0027761561796069145,
0.0020140206906944513,
-0.01079841423779726,
-0.00007080973591655493,
-0.00913279503583908,
-0.00727637205272913,
0.0014745908556506038,
-0.0038351535331457853,
-0.005175883881747723,
0.0006640880019403994,
0.0013861069455742836,
0.008734369650483131,
-0.0047870809212327,
0.0018396144732832909,
0.008925213478505611,
-0.002914420096203685,
-0.009251492097973824,
0.005237481091171503,
0.006197017151862383,
0.000879014958627522,
-0.0024270324502140284,
0.004986973945051432,
0.007742168847471476,
0.008583089336752892,
0.003195876022800803,
0.005063994787633419,
0.000898051424883306,
0.009208411909639835,
-0.0003586459788493812,
0.00208780774846673,
-0.0019178049406036735,
-0.0015643255319446325,
-0.005093709100037813,
-0.0006902303430251777,
-0.004455702845007181,
-0.002038531471043825,
-0.013011772185564041,
-0.008978880941867828,
-0.003384556155651808,
0.0010553328320384026,
0.0021263789385557175,
-0.005520841106772423,
-0.0008141470025293529,
0.002968899207189679,
0.009192640893161297,
0.0004417721356730908,
-0.0033069609198719263,
-0.0013951704604551196,
0.002044202294200659,
-0.007840186357498169,
0.015540082938969135,
-0.011723400093615055,
0.007674963213503361,
-0.001163395936600864,
-0.016624128445982933,
0.007969850674271584,
0.010215726681053638,
-0.009032981470227242,
0.003222886472940445,
0.002264553913846612,
0.004395605064928532,
0.0011754459701478481,
-0.0049125119112432,
-0.003866060171276331,
-0.0170394629240036,
-0.0007079108036123216,
0.020846066996455193,
0.0007640752010047436,
0.010114963166415691,
0.011271323077380657,
-0.0023397861514240503,
0.003157811239361763,
0.004971316549926996,
0.0003751747135538608,
0.012603161856532097,
-0.007858606055378914,
-0.0017663257895037532,
0.0019060216145589948,
-0.004846677649766207,
0.0014923660783097148,
0.005452691577374935,
0.006223936565220356,
-0.002950945869088173,
0.00254259305074811,
-0.005766039714217186,
-0.005602301098406315,
-0.01826195977628231,
-0.003335110144689679,
0.005697569809854031,
-0.004670400172472,
0.0030730392318218946,
-0.014031447470188141,
0.0035531159956008196,
0.005250775255262852,
0.00303467083722353,
-0.0014377018669620156,
0.001831841771490872,
0.005743052810430527,
0.012997974641621113,
-0.00644262321293354,
0.002647670917212963,
0.0022497873287647963,
-0.0016410787357017398,
-0.0002870979660656303,
0.0069549367763102055,
-0.006498102564364672,
-0.004680129233747721,
0.002646204549819231,
0.005952638573944569,
-0.0009689285070635378,
-0.004622597713023424,
-0.008569108322262764,
-0.0034648075234144926,
0.0030270011629909277,
-0.005518364254385233,
0.0024840510450303555,
-0.002130605513229966,
0.004213620442897081,
-0.00762353278696537,
-0.00012182469799881801,
-0.0034281532280147076,
-0.011534910649061203,
0.009304231032729149,
-0.0033822099212557077,
0.002793980995193124,
0.014636230655014515,
0.005165926646441221,
-0.012929069809615612,
0.005246467422693968,
0.0070847561582922935,
-0.005603478290140629,
0.004884060006588697,
0.006182731129229069,
-0.004694524221122265,
-0.020842187106609344,
-0.0027957831043750048,
-0.01437373086810112,
0.005651234183460474,
-0.0019180148374289274,
0.00269786617718637,
-0.008083746768534184,
0.00812146719545126,
0.0072488607838749886,
-0.014320828020572662,
-0.004029939416795969,
-0.007924813777208328,
0.008774235844612122,
0.0016976316692307591,
-0.0008959406986832619,
-0.0029915429186075926,
-0.0017204458126798272,
-0.0026904146652668715,
-0.0023594005033373833,
-0.0005766341928392649,
0.004592136479914188,
0.00021157613082323223,
-0.004655415657907724,
0.000757618632633239,
-0.004717965144664049,
0.001356953289359808,
0.0024904641322791576,
-0.009524848312139511,
0.0026982235722243786,
0.005003988742828369,
-0.0038699540309607983,
-0.002179468749091029,
0.003122918773442507,
-0.00006335852958727628,
-0.004579974804073572,
-0.010643761605024338,
-0.0013961527729406953,
-0.004216971341520548,
-0.0027249236591160297,
-0.01074445154517889,
-0.0029452056623995304,
-0.008970048278570175,
0.006061263382434845,
-0.007639972493052483,
0.008333610370755196,
0.006447473540902138,
-0.007192409597337246,
0.007822606712579727,
-0.002765340730547905,
0.0019992198795080185,
0.002242976799607277,
0.003067306475713849,
0.0008625721093267202,
-0.006941577885299921,
-0.00974823534488678,
0.012092068791389465,
-0.009134175255894661,
0.0016738163540139794,
0.013764194212853909,
0.004313726909458637,
0.009623163379728794,
0.0023670466616749763,
-0.00020781320927198976,
0.0029369518160820007,
0.007482366170734167,
-0.012270077131688595,
0.0034704413264989853,
-0.004264453426003456,
-0.00006851560465293005,
0.004754481837153435,
-0.003308463841676712,
0.002952585695311427,
0.007257661782205105,
0.0018853930523619056,
-0.006806353572756052,
0.0009419807465746999,
0.0022144014947116375,
0.005268822889775038,
-0.012481343001127243,
0.0006061132880859077,
-0.003706585615873337,
-0.004814367275685072,
-0.005528812296688557,
-0.0019492169376462698,
0.0005516723613254726,
0.005757121369242668,
-0.0016925932141020894,
0.006367881316691637,
0.0028568734414875507,
-0.0031888079829514027,
0.014844533987343311,
-0.006078260950744152,
-0.004362080246210098,
0.0011811831500381231,
0.0009370428742840886,
-0.00028582540107890964,
-0.007028820458799601,
-0.0005134192178957164,
0.00345224910415709,
0.006890513468533754,
-0.0028659063391387463,
-0.004360220395028591,
0.0001444926456315443,
0.003021396230906248,
-0.00846271775662899,
0.0010648532770574093,
0.012402566149830818,
-0.003710952354595065,
0.004838384687900543,
-0.002601759508252144,
-0.008141224272549152,
-0.013780154287815094,
0.05333719775080681,
-0.0000544922731933184,
0.004321121610701084,
0.005958146881312132,
-0.004973515868186951,
-0.002051077550277114,
-0.0011330555425956845,
0.008105490356683731,
-0.005912193097174168,
-0.007898136973381042,
0.007886222563683987,
-0.0033151619136333466,
0.0020724465139210224,
-0.00013332148955669254,
-0.0013708006590604782,
0.015120967291295528,
-0.004440415184944868,
-0.015758175402879715,
-0.017325755208730698,
0.008472065441310406,
-0.004778637085109949,
-0.007248600944876671,
0.008033414371311665,
-0.004140760749578476,
-0.0037503375206142664,
0.0016869218088686466,
0.005245980806648731,
0.00019885259098373353,
0.0007200607215054333,
-0.0027939830906689167,
-0.0012039291905239224,
-0.0009735628846101463,
0.003255642717704177,
0.004484735894948244,
0.009484157897531986,
-0.002112667541950941,
0.005064001306891441,
0.00020992675854358822,
-0.0007428113603964448,
-0.0026109223254024982,
0.003846060950309038,
0.007463657297194004,
-0.001509463065303862,
-0.003765156725421548,
0.0057444325648248196,
0.006392032373696566,
0.0015783541603013873,
0.012002627365291119,
-0.0007163234404288232,
-0.006162118166685104,
0.00906981248408556,
0.007576253265142441,
0.000365293089998886,
0.008241942152380943,
-0.002773970365524292,
0.006073268596082926,
0.0011389434803277254,
-0.007413377985358238,
-0.015510165132582188,
-0.0026068524457514286,
0.005941809620708227,
0.00763965817168355,
-0.002667786320671439,
0.0024705114774405956,
-0.0005929450853727758,
-0.0023147594183683395,
-0.006677714642137289,
-0.008793345652520657,
-0.0026789004914462566,
0.0009894231334328651,
0.00400403281673789,
0.06871554255485535,
-0.00604050699621439,
-0.0003185642708558589,
-0.006918163038790226,
0.0004201224073767662,
-0.0018054017564281821,
-0.0007463855436071754,
0.00008177702693501487,
-0.0021468487102538347,
0.0011151742655783892,
0.0024743631947785616,
-0.00889862421900034,
-0.010437929071485996,
0.0012312993640080094,
0.0006114377174526453,
-0.004612771328538656,
0.0037968356627970934,
0.007281277794390917,
-0.008930684998631477,
0.004152553156018257,
-0.009499691426753998,
-0.001960113411769271,
-0.0027426457963883877,
-0.01046337652951479,
-0.003744203830137849,
-0.004995919298380613,
0.0037343695294111967,
0.003531343536451459,
0.005740822292864323,
-0.0019112734589725733,
0.0064235650934278965,
-0.0014307732926681638,
0.0006926523055881262,
-0.004657099489122629,
0.0019250820623710752,
-0.006803057622164488,
0.0069609517231583595,
0.004801176954060793,
-0.011643359437584877,
-0.004257568623870611,
-0.0006231970037333667,
-0.0003841436409857124,
-0.0057291253469884396,
0.0032206426840275526,
0.0004934394964948297,
0.004478043410927057,
-0.0014407633570954204,
0.0015202534850686789,
-0.006509425584226847,
0.0013668376486748457,
-0.014209670946002007,
0.0038662184961140156,
-0.1754271388053894,
0.009386231191456318,
0.003448051866143942,
-0.005253415089100599,
-0.004783194046467543,
-0.014589755795896053,
-0.0060490877367556095,
0.0033572549000382423,
0.011552087962627411,
0.003337013302370906,
-0.0019934249576181173,
-0.00005554710151045583,
0.003615276189520955,
0.0027182186022400856,
-0.0009867582703009248,
-0.00537863839417696,
0.002387512009590864,
-0.0033574539702385664,
0.0002134467358700931,
0.0034597411286085844,
0.004052670672535896,
0.009230300784111023,
0.0008692750125192106,
0.0002681178448256105,
-0.0007439468754455447,
-0.004321865737438202,
0.006235494278371334,
-0.0019797272980213165,
0.005342411808669567,
-0.012845421209931374,
-0.0037326952442526817,
-0.003332725027576089,
-0.0038638943806290627,
0.0016109030693769455,
0.0055237626656889915,
-0.000989760272204876,
0.009238915517926216,
0.003297146875411272,
-0.007218486163765192,
0.007694489788264036,
-0.007919891737401485,
0.02869940921664238,
0.00479706609621644,
0.007801021449267864,
0.002086398657411337,
-0.005596252158284187,
-0.004415404982864857,
0.009431208483874798,
0.002729673171415925,
0.01298905536532402,
-0.01195924635976553,
-0.0038120781537145376,
0.0012553714914247394,
0.01791554130613804,
-0.004431546200066805,
-0.010587780736386776,
-0.008396160788834095,
-0.005114096682518721,
0.0035108798183500767,
0.006211451720446348,
0.008613922633230686,
-0.0029204227030277252,
0.008753882721066475,
-0.0030998222064226866,
-0.020918147638440132,
0.0028584052342921495,
-0.003740158397704363,
-0.005121680907905102,
0.002179631032049656,
0.006411210633814335,
0.010472188703715801,
-0.0013904973166063428,
0.0020938385277986526,
-0.0015545538626611233,
0.003481521736830473,
0.001058594905771315,
0.00590267451480031,
-0.0007485190290026367,
0.004504816606640816,
-0.010311211459338665,
0.009299781173467636,
-0.009419158101081848,
-0.0016730681527405977,
0.001126362127251923,
-0.0056551252491772175,
0.012303237803280354,
0.004847790114581585,
-0.0009993492858484387,
-0.001223180559463799,
-0.009677816182374954,
-0.004031635355204344,
0.002635064534842968,
0.0009399749105796218,
-0.009582597762346268,
0.003127770032733679,
0.00002640423917910084,
0.004201726987957954,
0.0036502843722701073,
-0.00992758758366108,
0.006207265891134739,
0.004634230397641659,
-0.003803280182182789,
0.0018468743655830622,
-0.006776756606996059,
0.003697032108902931,
0.003724772483110428,
-0.005167481489479542,
-0.007452770136296749,
0.0027320843655616045,
-0.004683893173933029,
-0.00534619577229023,
0.005397962871938944,
-0.010167253203690052,
-0.008764764294028282,
-0.0030558896251022816,
-0.012183137238025665,
0.0003707829746417701
] |
8a2ac410faa6645af8d41c21c8f5834684cf1a20 | 2,152 | py | Python | tests/registry_test.py | Walon1998/dace | 95ddfd3e9a5c654f0f0d66d026e0b64ec0f028a0 | [
"BSD-3-Clause"
] | 1 | 2022-03-11T13:36:34.000Z | 2022-03-11T13:36:34.000Z | tests/registry_test.py | Walon1998/dace | 95ddfd3e9a5c654f0f0d66d026e0b64ec0f028a0 | [
"BSD-3-Clause"
] | null | null | null | tests/registry_test.py | Walon1998/dace | 95ddfd3e9a5c654f0f0d66d026e0b64ec0f028a0 | [
"BSD-3-Clause"
] | null | null | null | # Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved.
import unittest
from aenum import Enum, auto
from dace import registry
@registry.make_registry
class ExtensibleClass(object):
pass
class Extension(ExtensibleClass):
pass
@registry.extensible_enum
class ExtensibleEnumeration(Enum):
a = auto()
b = auto()
class RegistryTests(unittest.TestCase):
def test_class_registry(self):
ExtensibleClass.register(Extension)
self.assertTrue(Extension in ExtensibleClass.extensions())
ExtensibleClass.unregister(Extension)
self.assertTrue(Extension not in ExtensibleClass.extensions())
def test_autoregister(self):
@registry.autoregister
class Extension2(ExtensibleClass):
pass
self.assertTrue(Extension2 in ExtensibleClass.extensions())
def test_class_registry_args(self):
ExtensibleClass.register(Extension, a=True, b=1, c=2)
self.assertTrue(Extension in ExtensibleClass.extensions())
self.assertEqual(ExtensibleClass.extensions()[Extension], dict(a=True, b=1, c=2))
ExtensibleClass.unregister(Extension)
self.assertTrue(Extension not in ExtensibleClass.extensions())
def test_autoregister_args(self):
@registry.autoregister_params(a=False, b=0)
class Extension3(ExtensibleClass):
pass
self.assertTrue(Extension3 in ExtensibleClass.extensions())
self.assertEqual(ExtensibleClass.extensions()[Extension3], dict(a=False, b=0))
def test_autoregister_fail(self):
with self.assertRaises(TypeError):
@registry.autoregister
class Extension4(object):
pass
def test_enum_registry(self):
ExtensibleEnumeration.register('c')
self.assertTrue(ExtensibleEnumeration.c in ExtensibleEnumeration)
self.assertEqual(ExtensibleEnumeration.c.value, 3)
def test_enum_registry_fail(self):
with self.assertRaises(TypeError):
@registry.extensible_enum
class NotAnEnum(object):
pass
if __name__ == '__main__':
unittest.main()
| 29.479452 | 89 | 0.697955 | 1 | 1.2846 | [
0.0014822558732703328,
0.024114662781357765,
0.007126349490135908,
0.0007639052346348763,
0.00428076833486557,
-0.0011012853356078267,
-0.009807419963181019,
0.0031918506138026714,
-0.004942592699080706,
0.002934741321951151,
0.0054910690523684025,
0.005853188689798117,
0.0057111685164272785,
-0.015978096053004265,
0.0009170224657282233,
0.017492711544036865,
-0.05107671394944191,
0.0001738710852805525,
-0.0038427221588790417,
0.002662008861079812,
-0.005574733018875122,
0.008240138180553913,
0.009610814973711967,
0.008173173293471336,
0.007030913140624762,
-0.00015449295460712165,
0.00945946667343378,
0.0037103809881955385,
-0.006754600442945957,
-0.007102172821760178,
-0.0001461544306948781,
-0.0018879491835832596,
-0.007019178941845894,
-0.007681264542043209,
0.006354647688567638,
-0.0027753484901040792,
-0.00011215167614864185,
-0.017677735537290573,
0.00991508923470974,
-0.0049931020475924015,
-0.007714942563325167,
-0.015497052110731602,
-0.0006098502199165523,
0.003538405755534768,
-0.009590797126293182,
0.0018713690806180239,
-0.004573709797114134,
0.0021895738318562508,
-0.011009437032043934,
0.007252988871186972,
-0.009549232199788094,
0.006508316844701767,
0.012666379101574421,
0.0024052595254033804,
-0.008384539745748043,
-0.007135404273867607,
0.011202044785022736,
-0.0000263270121649839,
-0.010036886669695377,
0.0012437804834917188,
-0.003670450998470187,
-0.002628530841320753,
0.005423381458967924,
0.0034915090072900057,
-0.014861813746392727,
-0.006643869914114475,
-0.00362536683678627,
0.0030275071039795876,
-0.0013218795647844672,
0.005313535686582327,
-0.0008842474198900163,
-0.0019836940336972475,
0.0072773415595293045,
0.005520383827388287,
0.005653941072523594,
-0.002523435279726982,
-0.000576494843699038,
-0.0001927803532453254,
0.009044559672474861,
0.0034366415347903967,
0.0026306351646780968,
-0.006232454441487789,
0.00571592990309,
0.007344875019043684,
0.015588883310556412,
0.0084009924903512,
0.020591694861650467,
-0.010043738409876823,
0.0476904921233654,
0.007418626453727484,
-0.008613018319010735,
0.002490577520802617,
-0.00917610339820385,
-0.001450329669751227,
-0.003728763898834586,
-0.02516573667526245,
0.0010921854991465807,
-0.004075747448951006,
-0.0021271780133247375,
0.003673217259347439,
-0.00046328137977980077,
0.006325608119368553,
-0.0009914023103192449,
-0.0007708638440817595,
-0.010257918387651443,
0.009718157351016998,
-0.009188880212605,
-0.0034136816393584013,
0.005584285594522953,
0.0017867295537143946,
-0.009355003945529461,
-0.0016413370613008738,
0.001114293118007481,
-0.011648289859294891,
0.002216482535004616,
0.0026839221827685833,
-0.007917488925158978,
0.053505152463912964,
-0.0000695835697115399,
0.0032576839439570904,
-0.005285380873829126,
0.00033832414192147553,
-0.000598010839894414,
0.004049837589263916,
0.008605895563960075,
-0.002057339996099472,
0.009663556702435017,
0.007379527203738689,
0.004137061070650816,
0.009195341728627682,
-0.0030121731106191874,
0.007999712601304054,
-0.0054473248310387135,
-0.001961532048881054,
0.0001035905079334043,
-0.007962128147482872,
0.006057157181203365,
-0.000598966667894274,
-0.006610061042010784,
-0.0010200104443356395,
-0.001814170740544796,
-0.00894960481673479,
0.0012754485942423344,
-0.005811652634292841,
0.004365437664091587,
-0.011706489138305187,
-0.003152158111333847,
-0.0028087992686778307,
-0.00220066518522799,
0.0014783742371946573,
0.009159091860055923,
0.004687752574682236,
0.0031822926830500364,
-0.0040150475688278675,
-0.010101796127855778,
0.0003889498475473374,
-0.0036677776370197535,
0.0012821871787309647,
0.005346375051885843,
0.004985691048204899,
-0.009352670051157475,
-0.0010670138290151954,
0.0013157704379409552,
0.0027534158434718847,
-0.0007588506559841335,
0.0026232004165649414,
-0.008545536547899246,
0.005563960410654545,
-0.0002868955780286342,
0.003479784121736884,
0.011475796811282635,
-0.004457900300621986,
-0.000870312622282654,
0.0008560193236917257,
0.0021418749820441008,
0.0004732315137516707,
0.004566487856209278,
0.009747917763888836,
-0.0017527589807286859,
-0.004578928463160992,
0.0025700926780700684,
0.0061944941990077496,
0.0102230841293931,
0.008558779023587704,
-0.0035932823084294796,
0.0018590199761092663,
-0.005132922437041998,
-0.0016554957255721092,
0.005609579849988222,
-0.005446279887109995,
0.006497744470834732,
0.0035983731504529715,
-0.011707625351846218,
-0.007798055186867714,
-0.0007631765329279006,
-0.008964146487414837,
0.0009563990752212703,
0.013499927707016468,
0.012119668535888195,
-0.0052200560458004475,
0.0021021559368819,
-0.009065897203981876,
0.001653428771533072,
0.006557192653417587,
0.0025472405832260847,
-0.011669745668768883,
-0.9582826495170593,
0.005230247508734465,
0.002765428740531206,
-0.0014092979254201055,
0.0065858145244419575,
0.0016940349014475942,
0.003182719461619854,
0.00397135317325592,
0.013540035113692284,
-0.0091626588255167,
-0.007235752884298563,
-0.00875941850244999,
-0.012068481184542179,
-0.0014139646664261818,
-0.008301762863993645,
-0.002137682633474469,
-0.004949635826051235,
-0.007081180810928345,
-0.003385258838534355,
-0.0027857476379722357,
-0.0014539083931595087,
0.007632529363036156,
0.000005309723292157287,
0.005750297103077173,
0.004390852991491556,
0.003323337296023965,
-0.004714999347925186,
0.0002965151215903461,
-0.002347910311073065,
-0.0018541425233706832,
-0.007761342916637659,
-0.015289540402591228,
-0.004664367064833641,
-0.0013865921646356583,
0.010511434637010098,
0.00015272636665031314,
0.007991105318069458,
-0.0020678769797086716,
0.002385766012594104,
-0.007792939897626638,
0.00368141639046371,
0.00002656920514709782,
0.0044988649897277355,
-0.031751833856105804,
-0.000029418679332593456,
-0.0015309599693864584,
-0.011475659906864166,
0.0070449174381792545,
0.0002712660643737763,
-0.0002325625973753631,
-0.0034048871602863073,
-0.005954714026302099,
0.011081274598836899,
-0.007872004993259907,
0.005130913574248552,
-0.0029976582154631615,
-0.0077468473464250565,
-0.0025371259544044733,
-0.00842699222266674,
0.0020416209008544683,
0.006785294972360134,
-0.002642753068357706,
-0.006137278862297535,
-0.0030980578158050776,
0.002569366479292512,
0.00332443555817008,
0.0025587433483451605,
-0.01828102394938469,
-0.008681119419634342,
-0.0020988075993955135,
0.00022071468993090093,
-0.0037326079327613115,
-0.004711955785751343,
0.007036895956844091,
-0.008283432573080063,
0.00744354072958231,
0.002543842187151313,
0.0015947167994454503,
-0.010353119112551212,
0.0014233255060389638,
-0.009778412990272045,
-0.007173959165811539,
0.0014002255629748106,
-0.0058227949775755405,
-0.004676514305174351,
-0.0008391496958211064,
0.0030539417639374733,
0.005773616023361683,
-0.0053132520988583565,
0.005898157600313425,
0.011209165677428246,
-0.004576480481773615,
-0.007492506876587868,
0.008273432962596416,
0.007492390461266041,
-0.0011596116237342358,
-0.0019152144668623805,
0.0031173620373010635,
0.008365681394934654,
0.0091029591858387,
0.003561184508726001,
0.006756770424544811,
-0.0001416767481714487,
0.007630504202097654,
-0.0002223938936367631,
0.002211090177297592,
-0.0015446246834471822,
-0.0008571729995310307,
-0.002887501148506999,
-0.002884427085518837,
-0.0043618869967758656,
-0.002867552451789379,
-0.012545336969196796,
-0.007819208316504955,
-0.0019445113139227033,
-0.00014073231432121247,
0.003217305988073349,
-0.002811207203194499,
-0.00034776912070810795,
0.0028475953731685877,
0.0087265120819211,
-0.0007850017282180488,
-0.0030962415039539337,
0.0012763958657160401,
0.005558502394706011,
-0.006871827412396669,
0.014792104251682758,
-0.012003551237285137,
0.0062724086456000805,
0.0012647921685129404,
-0.01539673376828432,
0.006145484745502472,
0.008752100169658661,
-0.010091711767017841,
0.003533744253218174,
0.003064416814595461,
0.0014708128292113543,
-0.0018133894773200154,
-0.0034617988858371973,
-0.0032329645473510027,
-0.017121480777859688,
0.00008891624747775495,
0.021098114550113678,
-0.0011893053306266665,
0.009565037675201893,
0.012398803606629372,
-0.0019148585852235556,
0.002987861866131425,
0.002785713877528906,
-0.00028643058612942696,
0.012346943840384483,
-0.006689582020044327,
-0.0011165388859808445,
0.002219429239630699,
-0.006042340770363808,
0.001963638933375478,
0.006546935997903347,
0.007224102504551411,
-0.0018722291570156813,
0.0034455040004104376,
-0.006706607528030872,
-0.003467637114226818,
-0.0181893240660429,
-0.0013753226958215237,
0.009418522007763386,
-0.0030426885932683945,
0.005798063240945339,
-0.012829283252358437,
0.005960616283118725,
0.008420740254223347,
0.0029115001671016216,
-0.0014737064484506845,
0.0008411317830905318,
0.005116460844874382,
0.01198072824627161,
-0.006158722564578056,
0.0014990826603025198,
0.0030383896082639694,
0.00035834283335134387,
-0.0025369999930262566,
0.008261723443865776,
-0.006990212015807629,
-0.005669091362506151,
0.00025300594279542565,
0.003562044817954302,
0.000732294749468565,
-0.005094203632324934,
-0.01020056288689375,
-0.003499982412904501,
0.005563855636864901,
-0.005969862919300795,
0.0039428845047950745,
0.0021297147031873465,
0.003528945380821824,
-0.007236090954393148,
0.0009569910471327603,
-0.0034833443351089954,
-0.011348365806043148,
0.012112048454582691,
-0.0033523954916745424,
0.0036156277637928724,
0.013006779365241528,
0.005455878563225269,
-0.013868791982531548,
0.006906366441398859,
0.008621719665825367,
-0.004240493755787611,
0.005008166190236807,
0.004418949596583843,
-0.005472103599458933,
-0.02233625203371048,
-0.0022968584671616554,
-0.012480096891522408,
0.007956929504871368,
-0.0021562022157013416,
0.0056302547454833984,
-0.007276272401213646,
0.0065138135105371475,
0.005299990996718407,
-0.014578007161617279,
-0.004226129502058029,
-0.009399705566465855,
0.008374245837330818,
-0.00011196470586583018,
-0.0009994539432227612,
-0.004034069832414389,
-0.0034707202576100826,
-0.00327027915045619,
-0.0024799732491374016,
-0.0008782904478721321,
0.006838897708803415,
0.002291648183017969,
-0.004093949217349291,
0.00196763570420444,
-0.006063684355467558,
0.0019521249923855066,
0.0019363310420885682,
-0.00958831887692213,
0.0037283366546034813,
0.0031466700602322817,
-0.001653070212341845,
-0.002988602267578244,
0.0007818695739842951,
-0.0016253364738076925,
-0.006057241000235081,
-0.010638967156410217,
-0.0030535180121660233,
-0.003626787569373846,
-0.0021553379483520985,
-0.011854151263833046,
-0.0012874657986685634,
-0.010111638344824314,
0.004510817583650351,
-0.007847596891224384,
0.00792336743324995,
0.0070800515823066235,
-0.0058308993466198444,
0.007383850868791342,
-0.0010251320200040936,
0.0026402731891721487,
0.0035593085922300816,
0.004990736488252878,
-0.0007398601737804711,
-0.00653934758156538,
-0.008382040075957775,
0.013009230606257915,
-0.0097060427069664,
0.00011219143925700337,
0.012212550267577171,
0.006076924502849579,
0.009965597651898861,
0.00009519032028038055,
0.0005436971550807357,
0.0039765797555446625,
0.007889867760241032,
-0.013002235442399979,
0.00325400591827929,
-0.0019398697186261415,
-0.000029653601814061403,
0.0072356900200247765,
-0.002894911216571927,
0.0014789729611948133,
0.008963389322161674,
0.00033301766961812973,
-0.006224999204277992,
-0.002170391846448183,
0.002549150725826621,
0.004546170588582754,
-0.012892038561403751,
0.0016462967032566667,
-0.004767637699842453,
-0.005544774234294891,
-0.002026577480137348,
-0.0023141279816627502,
-0.0007470642449334264,
0.004843680653721094,
-0.003054166678339243,
0.00585605064406991,
0.0004967347485944629,
-0.0033633746206760406,
0.01370521541684866,
-0.006077704485505819,
-0.007175725884735584,
0.0004036095051560551,
0.0029000607319176197,
-0.00266407267190516,
-0.006950775161385536,
-0.003485799301415682,
0.0031923751812428236,
0.0060315425507724285,
-0.00217396579682827,
-0.00549182016402483,
-0.0015150799881666899,
0.0016709683695808053,
-0.008513839915394783,
0.002751582767814398,
0.012327516451478004,
-0.002680908888578415,
0.007381151895970106,
-0.0010685005690902472,
-0.007269650232046843,
-0.014849656261503696,
0.053865332156419754,
-0.0027956480626016855,
0.004985496401786804,
0.0030882549472153187,
-0.006977265700697899,
-0.0009136240114457905,
-0.00200322805903852,
0.007154989056289196,
-0.008064072579145432,
-0.008420052006840706,
0.00845502782613039,
-0.0021881628781557083,
0.00443292036652565,
0.0015129413222894073,
-0.001118700485676527,
0.015527330338954926,
-0.00376186054199934,
-0.01774515211582184,
-0.014776629395782948,
0.009153652936220169,
-0.0031658965162932873,
-0.0078431386500597,
0.009261679835617542,
-0.0012231898726895452,
-0.003999766893684864,
0.0007445317460224032,
0.007427483797073364,
0.0013285360764712095,
0.0024673165753483772,
-0.0033693043515086174,
-0.004348618909716606,
-0.00008569424971938133,
0.0019966792315244675,
0.007515421602874994,
0.007368423044681549,
-0.004485017620027065,
0.003955795429646969,
-0.0034942009951919317,
-0.0009079394512809813,
-0.0024097515270113945,
0.003832597518339753,
0.007453047204762697,
-0.0019475669832900167,
-0.0020883390679955482,
0.004297967068850994,
0.004709933884441853,
0.00306476978585124,
0.010661877691745758,
-0.000502870767377317,
-0.005646476987749338,
0.006970232352614403,
0.00675669452175498,
-0.0010714060626924038,
0.008379945531487465,
-0.0013614604249596596,
0.005993320140987635,
0.0007450320990756154,
-0.007175154518336058,
-0.016230039298534393,
-0.0029193046502768993,
0.004295286722481251,
0.005578924901783466,
-0.000620691804215312,
0.004025384318083525,
-0.0019178963266313076,
0.0005674951244145632,
-0.0062615759670734406,
-0.008648430928587914,
-0.004632403142750263,
0.001513489754870534,
0.0037799859419465065,
0.0684678927063942,
-0.005719820037484169,
-0.002323952503502369,
-0.0080718994140625,
-0.0006489267107099295,
-0.001963213086128235,
-0.0013464861549437046,
-0.0015560714527964592,
-0.0035669272765517235,
0.0023604310117661953,
0.0008749100961722434,
-0.00581762008368969,
-0.011111797764897346,
0.0016683803405612707,
-0.0006724307895638049,
-0.0035183134023100138,
0.005815092474222183,
0.00826312880963087,
-0.009361005388200283,
0.0020809276029467583,
-0.013178350403904915,
-0.0013971696607768536,
-0.005235202144831419,
-0.01091218926012516,
-0.0052835470996797085,
-0.004410140216350555,
0.005598460789769888,
0.00409867987036705,
0.005697254091501236,
-0.004170126281678677,
0.0059196241199970245,
-0.002198232803493738,
-0.0005213395925238729,
-0.004059791564941406,
-0.0006608504918403924,
-0.007157238200306892,
0.00518146762624383,
0.0024182996712625027,
-0.010207433253526688,
-0.0035066367127001286,
-0.001909419777803123,
0.0007263555307872593,
-0.005191260017454624,
0.003641546471044421,
0.00041203995351679623,
0.007380447816103697,
-0.001832660287618637,
-0.000377982942154631,
-0.00721888430416584,
0.0031702511478215456,
-0.011927305720746517,
0.00565804960206151,
-0.17700490355491638,
0.009378761984407902,
0.005001241806894541,
-0.004918984603136778,
-0.004651847295463085,
-0.0152092594653368,
-0.006842802278697491,
0.003989074844866991,
0.01147024892270565,
-0.0002932903589680791,
-0.0003003262390848249,
-0.00339168100617826,
0.004850964993238449,
0.00542585551738739,
0.0003692636382766068,
-0.007190391421318054,
0.003730562049895525,
-0.004373401403427124,
0.0002049532631644979,
0.0040694959461688995,
0.005622770171612501,
0.009693775326013565,
0.0014688102528452873,
-0.0004081670194864273,
-0.0020234771072864532,
-0.0038310601375997066,
0.00841430202126503,
-0.0027880610432475805,
0.006169605068862438,
-0.010955740697681904,
-0.003936268389225006,
-0.00626030471175909,
-0.00550456065684557,
0.0014619968133047223,
0.004790683276951313,
0.0002894313947763294,
0.007520942948758602,
0.0030628119129687548,
-0.008150659501552582,
0.007049462292343378,
-0.007761665154248476,
0.026243196800351143,
0.004916441161185503,
0.007815555669367313,
0.001120245549827814,
-0.004881572909653187,
-0.004559924826025963,
0.008893713355064392,
0.0014277311274781823,
0.011027035303413868,
-0.013866569846868515,
-0.0009694172185845673,
0.002651150105521083,
0.018086645752191544,
-0.00443651806563139,
-0.01057487539947033,
-0.007649387698620558,
-0.0034155871253460646,
0.002664014929905534,
0.008585049770772457,
0.010552316904067993,
-0.0030525908805429935,
0.006939285434782505,
-0.0037622509989887476,
-0.02117771841585636,
0.0033560246229171753,
-0.004935151431709528,
-0.0068430607207119465,
0.0004949214053340256,
0.007051798980683088,
0.009764482267200947,
-0.0006994584109634161,
0.0004335528064984828,
-0.0012328983284533024,
0.006967736873775721,
0.0005222340696491301,
0.006252466235309839,
-0.0008660235325805843,
0.0039046064484864473,
-0.010622676461935043,
0.0063631571829319,
-0.010324645787477493,
-0.003175221849232912,
0.0014756489545106888,
-0.005292178597301245,
0.012101525440812111,
0.004247085191309452,
-0.0008594611426815391,
-0.0028170165605843067,
-0.009060190059244633,
-0.0050486186519265175,
0.002489804057404399,
-0.0006035798578523099,
-0.008641188964247704,
0.002749999286606908,
0.0010555761400610209,
0.006422887556254864,
0.005262019578367472,
-0.006653785705566406,
0.005586924962699413,
0.005253561306744814,
-0.005726987030357122,
0.001598781207576394,
-0.005951581988483667,
0.0010801804019138217,
0.0031165529508143663,
-0.007357072085142136,
-0.0039826990105211735,
0.003547155996784568,
-0.007897338829934597,
-0.0060136811807751656,
0.007423941045999527,
-0.009706555865705013,
-0.010721164755523205,
-0.0035740891471505165,
-0.013124214485287666,
0.0015279100043699145
] |
8a2b2a493d7950b9f9a43469d730e06de8f5d85d | 2,372 | py | Python | tests/conftest.py | aviramha/aiologstash2 | 08c5127bf77e3b66ddcb2e8acff82368dbc58af7 | [
"MIT"
] | 1 | 2022-02-01T10:10:05.000Z | 2022-02-01T10:10:05.000Z | tests/conftest.py | aviramha/aiologstash2 | 08c5127bf77e3b66ddcb2e8acff82368dbc58af7 | [
"MIT"
] | null | null | null | tests/conftest.py | aviramha/aiologstash2 | 08c5127bf77e3b66ddcb2e8acff82368dbc58af7 | [
"MIT"
] | null | null | null | import asyncio
import logging
from json import loads
import pytest
from aiologstash2 import create_tcp_handler
logging.getLogger().setLevel(logging.DEBUG)
class FakeTcpServer:
def __init__(self):
self.data = bytearray()
self.server = None
self.futs = set()
async def start(self):
self.server = await asyncio.start_server(self.on_connect, host="127.0.0.1")
@property
def port(self):
return self.server.sockets[0].getsockname()[1]
@property
def jsons(self):
s = self.data.decode("utf8")
return [loads(i) for i in s.split("\n") if i]
async def close(self):
if self.server is None:
return
self.server.close()
await self.server.wait_closed()
self.server = None
async def on_connect(self, reader, writer):
while True:
data = await reader.read(1024)
if not data:
break
self.data.extend(data)
for fut in self.futs:
if not fut.done():
fut.set_result(None)
async def wait(self):
fut = asyncio.get_event_loop().create_future()
self.futs.add(fut)
await fut
self.futs.remove(fut)
@pytest.fixture
async def make_tcp_server():
servers = []
async def go():
server = FakeTcpServer()
await server.start()
servers.append(server)
return server
yield go
async def finalize():
for server in servers:
await server.close()
await finalize()
@pytest.fixture
async def make_tcp_handler(make_tcp_server):
handlers = []
async def go(*args, level=logging.DEBUG, **kwargs):
server = await make_tcp_server()
handler = await create_tcp_handler("127.0.0.1", server.port, **kwargs)
handlers.append(handler)
return handler, server
yield go
async def finalize():
for handler in handlers:
handler.close()
await handler.wait_closed()
await finalize()
@pytest.fixture
async def setup_logger(make_tcp_handler):
async def go(*args, **kwargs):
handler, server = await make_tcp_handler(*args, **kwargs)
logger = logging.getLogger("aiologstash_test")
logger.addHandler(handler)
return logger, handler, server
yield go
| 23.029126 | 83 | 0.605818 | 1 | 1.3836 | [
0.0015688887797296047,
0.023890815675258636,
0.008664872497320175,
0.00029156601522117853,
0.003835038747638464,
-0.0008774808957241476,
-0.007797758560627699,
0.0025160405784845352,
-0.00591633515432477,
0.0018810003530234098,
0.0017565868329256773,
0.008105697110295296,
0.006221713963896036,
-0.01807853765785694,
0.00036443956196308136,
0.015465209260582924,
-0.050942759960889816,
-0.0002580696309451014,
-0.0029785342048853636,
0.0026273143012076616,
-0.007223719265311956,
0.008786053396761417,
0.009413770399987698,
0.005070948973298073,
0.008133893832564354,
0.0003532914270181209,
0.008504936471581459,
0.0018112105317413807,
-0.009266193956136703,
-0.00778011092916131,
-0.00030989013612270355,
-0.0005507058231160045,
-0.007652232889086008,
-0.008064174093306065,
0.00656337384134531,
-0.00376428896561265,
-0.0011757464380934834,
-0.017583347856998444,
0.013473737053573132,
-0.0035225916653871536,
-0.006784849800169468,
-0.014038549736142159,
0.0019709812477231026,
0.0027848444879055023,
-0.008618157356977463,
0.00038274217513389885,
-0.003533873939886689,
0.0037970836274325848,
-0.013182541355490685,
0.005404687952250242,
-0.009114873595535755,
0.007171839941293001,
0.014245961792767048,
0.0012522663455456495,
-0.005300563294440508,
-0.007157876156270504,
0.01119556650519371,
0.00033429806353524327,
-0.009724230505526066,
0.00010943503730231896,
-0.003933056257665157,
-0.003489203518256545,
0.007505686022341251,
0.00384308653883636,
-0.01493818312883377,
-0.006900510750710964,
-0.004023643210530281,
0.0033000600524246693,
-0.00020404579117894173,
0.006570304278284311,
-0.00013227293675299734,
-0.002984911436215043,
0.008497902192175388,
0.007369381841272116,
0.006190027110278606,
-0.0038659542333334684,
-0.0023317208979278803,
-0.00025877024745568633,
0.009810122661292553,
0.002929166192188859,
0.004690141417086124,
-0.007115073502063751,
0.00573398731648922,
0.009182686917483807,
0.017650311812758446,
0.011192921549081802,
0.021228335797786713,
-0.011601242236793041,
0.048656292259693146,
0.007527181413024664,
-0.007710526697337627,
0.002250585937872529,
-0.009917175397276878,
-0.0011071423068642616,
-0.004226831719279289,
-0.027309780940413475,
0.0018649729900062084,
-0.0037018531002104282,
0.00023628913913853467,
0.003360261907801032,
-0.0019127510022372007,
0.005974522791802883,
-0.0003002360463142395,
-0.0017329738475382328,
-0.00559884961694479,
0.009661068208515644,
-0.008286302909255028,
-0.0031524773221462965,
0.006090619135648012,
0.0012398672988638282,
-0.00903597567230463,
-0.0022121586371213198,
0.0016733637312427163,
-0.012408758513629436,
0.003057562280446291,
0.0027701514773070812,
-0.004505751188844442,
0.05301325023174286,
0.0010549940634518862,
0.004633400123566389,
-0.005309742409735918,
0.0008476647781208158,
0.001049956539645791,
0.0039032537024468184,
0.009150244295597076,
-0.0014149328926578164,
0.01161895040422678,
0.007854481227695942,
0.0022005923092365265,
0.010681464336812496,
-0.0019324899185448885,
0.006935262121260166,
-0.003870959160849452,
-0.0019497860921546817,
0.0015194533625617623,
-0.00713105034083128,
0.00539141520857811,
-0.001516356016509235,
-0.008570722304284573,
-0.0025758370757102966,
-0.0002806818811222911,
-0.00803963840007782,
0.0014310237020254135,
-0.007206162437796593,
0.005669757723808289,
-0.010511217638850212,
-0.0026969171594828367,
-0.004294955171644688,
-0.003877649549394846,
0.0013393564149737358,
0.010205771774053574,
0.004093437921255827,
0.003351360559463501,
-0.005233652424067259,
-0.009744775481522083,
-0.0011537699028849602,
-0.00520669249817729,
0.0015659808414056897,
0.008319745771586895,
0.004377605393528938,
-0.009131699800491333,
-0.0010191579349339008,
0.00044991003233008087,
0.0013260385021567345,
0.000813906139228493,
0.003745855763554573,
-0.008456496521830559,
0.004412154667079449,
-0.0018922742456197739,
0.004134660586714745,
0.010228144936263561,
-0.003676960477605462,
0.000186066550668329,
0.0008365410612896085,
0.00098502729088068,
-0.0011327456450089812,
0.004057029727846384,
0.010299543850123882,
-0.004233244340866804,
-0.0050148796290159225,
0.004955857060849667,
0.00451103737577796,
0.010396751575171947,
0.005016145296394825,
-0.0036305186804383993,
0.0005322934011928737,
-0.0023543983697891235,
-0.0017377069452777505,
0.006062768399715424,
-0.004094529896974564,
0.0064788744784891605,
0.0038430870044976473,
-0.01334290485829115,
-0.008743830025196075,
0.002754938555881381,
-0.007634900044649839,
0.002309399889782071,
0.013168261386454105,
0.013074325397610664,
-0.0032614178489893675,
0.0010773173999041319,
-0.008060546591877937,
0.000978022813796997,
0.008929124101996422,
0.0028874354902654886,
-0.013095445930957794,
-0.9591580033302307,
0.006889613810926676,
0.002179836854338646,
-0.003651292761787772,
0.004819316323846579,
0.0015262081287801266,
0.0031332895159721375,
0.004613702185451984,
0.015082870610058308,
-0.00960449781268835,
-0.006241689436137676,
-0.01038834173232317,
-0.010877445340156555,
-0.0016994259785860777,
-0.008284817449748516,
-0.0034928976092487574,
-0.007038378156721592,
-0.005417071282863617,
-0.003703176276758313,
-0.0031504235230386257,
-0.0018965587951242924,
0.007250330876559019,
0.0016309728380292654,
0.0033107867930084467,
0.003622995689511299,
0.0036057026591151953,
-0.006381198763847351,
-0.0013314090901985765,
-0.0037276449147611856,
-0.0007380562019534409,
-0.008079769089818,
-0.01661704108119011,
-0.0019203521078452468,
-0.005281574558466673,
0.011419872753322124,
-0.0006029389915056527,
0.007726472802460194,
-0.002479271963238716,
0.002720865420997143,
-0.006528651341795921,
0.004800284747034311,
-0.0014341716887429357,
0.0038692078087478876,
-0.03203412517905235,
-0.00017884219414554536,
-0.002212798921391368,
-0.010975644923746586,
0.007094315253198147,
-0.0014795521274209023,
-0.0006135767907835543,
-0.003043432254344225,
-0.006658703088760376,
0.009947918355464935,
-0.0079965153709054,
0.004821788519620895,
-0.0032177495304495096,
-0.00682499073445797,
-0.003490098984912038,
-0.008235255256295204,
0.000978665193542838,
0.005739463958889246,
-0.003123494330793619,
-0.004664590582251549,
-0.003191370517015457,
0.002534836530685425,
0.002100190380588174,
0.0012154382420703769,
-0.01889876089990139,
-0.00568111427128315,
0.0005237612058408558,
-0.00023877837520558387,
-0.004928826820105314,
-0.003703694324940443,
0.007330906577408314,
-0.0088396817445755,
0.005424194969236851,
0.0017726169899106026,
-0.0008886136347427964,
-0.010592393577098846,
0.00044747881474904716,
-0.008924187161028385,
-0.00842959899455309,
0.002411685883998871,
-0.003956850618124008,
-0.004730772692710161,
0.0010601870017126203,
0.001997455023229122,
0.007359410170465708,
-0.004559899680316448,
0.003761494066566229,
0.01112627238035202,
-0.005008567124605179,
-0.007355122826993465,
0.006766289472579956,
0.006323474459350109,
-0.0006185057573020458,
-0.002386450069025159,
0.004531380720436573,
0.007062326651066542,
0.006947295740246773,
0.003005947219207883,
0.004744001664221287,
0.0006225574761629105,
0.007345634512603283,
-0.0002117421681759879,
0.0016656764782965183,
-0.0018415130907669663,
-0.00043769265175797045,
-0.0035389719996601343,
0.0021440580021589994,
-0.0032533968333154917,
-0.0017778961919248104,
-0.012841540388762951,
-0.008096108213067055,
-0.0031343363225460052,
-0.0008566871401853859,
0.0028431774117052555,
-0.004058435559272766,
-0.002184045035392046,
0.0022153742611408234,
0.008618798106908798,
0.001355441752821207,
-0.0034115174785256386,
0.0031393375247716904,
0.004794594831764698,
-0.007312195375561714,
0.014475773088634014,
-0.013081586919724941,
0.004659077152609825,
-0.00034289469476789236,
-0.014788703992962837,
0.006768205668777227,
0.008319267071783543,
-0.010926676914095879,
0.0037034188862890005,
0.004923681728541851,
0.003810828784480691,
-0.00021234409359749407,
-0.003336006309837103,
-0.002657724544405937,
-0.0165364108979702,
-0.0008538762340322137,
0.019015870988368988,
0.001751118921674788,
0.010702164843678474,
0.011867290362715721,
-0.002612160984426737,
0.0026861592195928097,
0.004291985649615526,
0.0008215786074288189,
0.013253270648419857,
-0.009574691765010357,
-0.00028380448929965496,
0.003217130433768034,
-0.0063667697831988335,
0.0008638334111310542,
0.00432001706212759,
0.005883428268134594,
-0.004909985698759556,
0.0036722668446600437,
-0.005673953332006931,
-0.0038863089866936207,
-0.014653634279966354,
-0.0019522091606631875,
0.0074097453616559505,
-0.004166348837316036,
0.007453850004822016,
-0.0127078453078866,
0.006113935727626085,
0.005985939875245094,
0.0022450934629887342,
-0.0008910770993679762,
0.0016118506900966167,
0.0032295044511556625,
0.01255106832832098,
-0.0040494948625564575,
0.0012264363467693329,
0.0009376479429192841,
-0.0017278211889788508,
-0.00001289531519432785,
0.006432201713323593,
-0.00786746945232153,
-0.007515890523791313,
0.002470289822667837,
0.005021121818572283,
0.00020955265790689737,
-0.004150992259383202,
-0.006445007864385843,
-0.0022260488476604223,
0.0038800076581537724,
-0.0049271718598902225,
0.003298211842775345,
0.0011663048062473536,
0.0025053962599486113,
-0.007162276655435562,
-0.0006697819917462766,
-0.0021256976760923862,
-0.0135605214163661,
0.010382909327745438,
-0.004876593593508005,
0.003332768799737096,
0.013437733985483646,
0.005790503695607185,
-0.011998743750154972,
0.00464250985532999,
0.007385957520455122,
-0.0030847268644720316,
0.006433443631976843,
0.003592465305700898,
-0.007267846260219812,
-0.022623561322689056,
-0.0029371401760727167,
-0.013995487242937088,
0.007829711772501469,
-0.0035643631126731634,
0.005344173405319452,
-0.007020908407866955,
0.007300617638975382,
0.006998009048402309,
-0.012556499801576138,
-0.005755731835961342,
-0.008790913037955761,
0.00989396870136261,
-0.0002546247560530901,
0.0012266137637197971,
-0.003383633913472295,
-0.00043917138827964664,
-0.002130639972165227,
-0.004063671920448542,
-0.002525489777326584,
0.006790586747229099,
0.0018497301498427987,
-0.003346168203279376,
0.003339797956869006,
-0.006216960493475199,
-0.0000388792650483083,
0.0008849482983350754,
-0.010020125657320023,
0.00295524625107646,
0.002868121489882469,
-0.0029299554880708456,
-0.0037866244092583656,
0.0031389426440000534,
-0.0024156218860298395,
-0.0037617746274918318,
-0.011942708864808083,
-0.002019420498982072,
-0.004921901971101761,
-0.0009005094179883599,
-0.011432260274887085,
-0.003089906880632043,
-0.005890790838748217,
0.006099443417042494,
-0.007734229322522879,
0.006741811521351337,
0.0042806267738342285,
-0.0028207709547132254,
0.006464632228016853,
-0.0019060228951275349,
0.004652802832424641,
0.0026430082507431507,
0.004669965710490942,
0.0034433186519891024,
-0.006559385452419519,
-0.011370238848030567,
0.010053531266748905,
-0.007623640354722738,
-0.0023519888054579496,
0.012488747015595436,
0.006669966969639063,
0.009511846117675304,
-0.0009108085068874061,
0.00003627277692430653,
0.0019096829928457737,
0.007871832698583603,
-0.011918184347450733,
0.00339512643404305,
-0.00395369715988636,
0.001362971612252295,
0.002518345834687352,
-0.003323968267068267,
0.0017911375034600496,
0.009180816821753979,
0.00025527720572426915,
-0.00627754395827651,
-0.002718735486268997,
0.002439874690026045,
0.005344934295862913,
-0.011483854614198208,
0.0006582700880244374,
-0.003901176853105426,
-0.0040490897372365,
-0.0029464473482221365,
-0.002031772630289197,
-0.0008093287469819188,
0.005622695665806532,
-0.002683716593310237,
0.005481349304318428,
0.001623124466277659,
-0.0045600878074765205,
0.014483850449323654,
-0.006000092718750238,
-0.003990821540355682,
0.0011596739059314132,
0.004027204122394323,
-0.002274882048368454,
-0.006726558320224285,
-0.0019551818259060383,
0.003826020983979106,
0.004780245013535023,
-0.002387767657637596,
-0.003914868924766779,
0.00011339101183693856,
0.001289176638238132,
-0.009786128997802734,
0.0011875741183757782,
0.012750741094350815,
-0.005243587773293257,
0.007025987841188908,
-0.001679152948781848,
-0.006780928932130337,
-0.012538042850792408,
0.04988761618733406,
-0.00230677449144423,
0.0015545593341812491,
0.0034670254681259394,
-0.00881439633667469,
-0.00013527074770536274,
-0.0027219129260629416,
0.008946326561272144,
-0.007058172021061182,
-0.006077914964407682,
0.007999978959560394,
-0.005087042693048716,
0.003463692031800747,
0.0031746814493089914,
-0.0014036362990736961,
0.016592197120189667,
-0.0032352893613278866,
-0.016146257519721985,
-0.018117932602763176,
0.006934982258826494,
-0.0050744046457111835,
-0.005915394518524408,
0.009198116138577461,
-0.0015781210968270898,
-0.005914981942623854,
0.002980486722663045,
0.007790363393723965,
0.0012411813950166106,
0.0010481105418875813,
-0.003844722406938672,
-0.003828207030892372,
-0.0005668114754371345,
0.001449840608984232,
0.006350984331220388,
0.007894963957369328,
-0.0025454184506088495,
0.003428635187447071,
-0.002364909974858165,
-0.0010174332419410348,
-0.0020460491068661213,
0.0017814477905631065,
0.009103518910706043,
-0.0012009936617687345,
-0.0009197825565934181,
0.006115358788520098,
0.006116746924817562,
0.002471036510542035,
0.010142837651073933,
0.0003051879466511309,
-0.007155911531299353,
0.008395056240260601,
0.007408399134874344,
0.0009830903727561235,
0.00892955157905817,
-0.001921368413604796,
0.0052285450510680676,
0.0009377674432471395,
-0.007797649595886469,
-0.016388384625315666,
-0.005478942766785622,
0.007258276455104351,
0.009635671973228455,
-0.0014343956718221307,
0.0024979496374726295,
-0.004563096445053816,
-0.0008165569161064923,
-0.0068111601285636425,
-0.006959714461117983,
-0.0029459220822900534,
0.0017122200224548578,
0.0031785659957677126,
0.06912735849618912,
-0.007276258897036314,
-0.0009072510874830186,
-0.01013864204287529,
-0.0020404732786118984,
-0.003111208789050579,
-0.0021266983821988106,
0.0019891855772584677,
-0.0029743346385657787,
0.0016604538541287184,
0.00033783511025831103,
-0.0077333394438028336,
-0.011517392471432686,
0.0028002287726849318,
0.0011824284447357059,
-0.002607319736853242,
0.00557438749819994,
0.005125898867845535,
-0.009916050359606743,
0.0007270384230650961,
-0.011472159065306187,
-0.0022375581320375204,
-0.003465010318905115,
-0.010949691757559776,
-0.0061828442849218845,
-0.003821778343990445,
0.0045659225434064865,
0.001532820868305862,
0.005363191943615675,
-0.003782885381951928,
0.004918000660836697,
-0.003967645578086376,
0.0005817290511913598,
-0.00551984366029501,
-0.0016684719594195485,
-0.0062026334926486015,
0.00801883451640606,
0.003855708986520767,
-0.010655907914042473,
-0.004350011702626944,
-0.0004155808419454843,
-0.0007019617478363216,
-0.004304126836359501,
0.006053709425032139,
-0.00041849302942864597,
0.003949018195271492,
-0.0019935162272304296,
-0.0005130128702148795,
-0.006774434819817543,
0.0009495036792941391,
-0.011767097748816013,
0.004292457364499569,
-0.17262329161167145,
0.008817099034786224,
0.005246540065854788,
-0.005288304761052132,
-0.005343563389033079,
-0.014562549069523811,
-0.0030132217798382044,
0.004903129767626524,
0.009929096326231956,
0.0010403840569779277,
-0.0024566887877881527,
-0.002785799326375127,
0.00725738937035203,
0.004669336602091789,
-0.0006956939469091594,
-0.0050451853312551975,
0.002781611168757081,
-0.0023869997821748257,
0.00018048041965812445,
0.0026582421269267797,
0.003722633933648467,
0.011049633845686913,
-0.001595512148924172,
0.002089459914714098,
-0.0019584153778851032,
-0.005594038870185614,
0.006718284450471401,
-0.0037342244759202003,
0.007662046235054731,
-0.011496521532535553,
-0.0011954164365306497,
-0.0035701384767889977,
-0.006740477867424488,
0.0010956026380881667,
0.005617886781692505,
-0.0033700778149068356,
0.009375989437103271,
0.003604328725486994,
-0.0072294059209525585,
0.006988455541431904,
-0.01094353012740612,
0.028291039168834686,
0.0037097178865224123,
0.0074167498387396336,
-0.00021216254390310496,
-0.007355029229074717,
-0.005607795435935259,
0.008508260361850262,
0.0011643560137599707,
0.010113662108778954,
-0.013585563749074936,
-0.0002202617033617571,
0.002726862207055092,
0.01877645216882229,
-0.004803378134965897,
-0.01042560487985611,
-0.007160595152527094,
-0.0006742329569533467,
0.0018730009905993938,
0.006837164983153343,
0.012649567797780037,
-0.002299097366631031,
0.006394121330231428,
-0.003606690326705575,
-0.022711336612701416,
0.0036710381973534822,
-0.005220050457865,
-0.007028015796095133,
0.0025816240813583136,
0.006859969813376665,
0.00912618450820446,
0.0006305179558694363,
0.0001798479352146387,
0.0009124058997258544,
0.005281262565404177,
-0.0004996240604668856,
0.006274695508182049,
-0.0006912939716130495,
0.0028702516574412584,
-0.009153639897704124,
0.00727356132119894,
-0.009686381556093693,
-0.0011127652833238244,
0.0020519327372312546,
-0.0036421394906938076,
0.011796747334301472,
0.0040720123797655106,
-0.002326402347534895,
-0.0025041692424565554,
-0.008731231093406677,
-0.002499002730473876,
0.003504448104649782,
0.00008131882350426167,
-0.01126873679459095,
0.0028049233369529247,
0.00070103321922943,
0.005258208606392145,
0.004902539774775505,
-0.007765683811157942,
0.005869985558092594,
0.006193644367158413,
-0.005206788424402475,
0.0014084057183936238,
-0.0043491218239068985,
0.0027394802309572697,
0.0037139321211725473,
-0.006223746109753847,
-0.0053016385063529015,
0.003084474941715598,
-0.007919546216726303,
-0.004175801761448383,
0.008357533253729343,
-0.008073423057794571,
-0.008208127692341805,
-0.002451582346111536,
-0.011988887563347816,
0.0021304285619407892
] |
8a2b9f3633d27fae8143c30667678e54429c7aa8 | 19,973 | py | Python | tcex/playbooks/playbooks_base.py | RichieB2B/tcex | eba20a67d4b8e3596c895b7c45325716267d7c85 | [
"Apache-2.0"
] | null | null | null | tcex/playbooks/playbooks_base.py | RichieB2B/tcex | eba20a67d4b8e3596c895b7c45325716267d7c85 | [
"Apache-2.0"
] | null | null | null | tcex/playbooks/playbooks_base.py | RichieB2B/tcex | eba20a67d4b8e3596c895b7c45325716267d7c85 | [
"Apache-2.0"
] | null | null | null | """TcEx Framework Playbook module"""
# standard library
import base64
import json
import re
from collections import OrderedDict
from collections.abc import Iterable
class PlaybooksBase:
"""TcEx Playbook Module Base Class
Args:
tcex (TcEx): Instance of TcEx class.
context (str): The Redis context (hash).
output_variables (list): The requested output variables.
"""
def __init__(self, tcex, context, output_variables):
"""Initialize the Class properties."""
self.tcex = tcex
self._context = context
self._output_variables = output_variables or []
# properties
self._output_variables_by_name = None
self._output_variables_by_type = None
self.log = tcex.log
# match full variable
self._variable_match = re.compile(fr'^{self._variable_pattern}$')
# capture variable parts (exactly a variable)
self._variable_parse = re.compile(self._variable_pattern)
# match embedded variables without quotes (#App:7979:variable_name!StringArray)
self._vars_keyvalue_embedded = re.compile(fr'(?:\"\:\s?)[^\"]?{self._variable_pattern}')
def _coerce_string_value(self, value):
"""Return a string value from an bool or int."""
# coerce bool before int as python says a bool is an int
if isinstance(value, bool):
# coerce bool to str type
self.log.warning(f'Coercing bool value ({value}) to a string ("{str(value).lower()}").')
value = str(value).lower()
# coerce int to str type
if isinstance(value, (float, int)):
self.log.warning(f'Coercing float/int value ({value}) to a string ("{str(value)}").')
value = str(value)
return value
def _create(self, key, value, validate=True):
"""Create the value in Redis if applicable."""
if key is None or value is None:
self.log.warning('The key or value field is None.')
return None
# get variable type from variable value
variable_type = self.variable_type(key)
if variable_type == 'Binary':
# if not isinstance(value, bytes):
# value = value.encode('utf-8')
if validate and not isinstance(value, bytes):
raise RuntimeError('Invalid data provided for Binary.')
value = base64.b64encode(value).decode('utf-8')
elif variable_type == 'KeyValue':
if validate and (not isinstance(value, dict) or not self._is_key_value(value)):
raise RuntimeError('Invalid data provided for KeyValue.')
elif variable_type == 'String':
# coerce string values
value = self._coerce_string_value(value)
if validate and not isinstance(value, str):
raise RuntimeError('Invalid data provided for String.')
elif variable_type == 'TCEntity':
if validate and (not isinstance(value, dict) or not self._is_tc_entity(value)):
raise RuntimeError('Invalid data provided for TcEntity.')
# self.log.trace(f'pb create - context: {self._context}, key: {key}, value: {value}')
try:
value = json.dumps(value)
except ValueError as e: # pragma: no cover
raise RuntimeError(f'Failed to serialize value ({e}).')
try:
return self.tcex.key_value_store.create(self._context, key.strip(), value)
except RuntimeError as e:
self.log.error(e)
return None
def _create_array(self, key, value, validate=True):
"""Create the value in Redis if applicable."""
if key is None or value is None:
self.log.warning('The key or value field is None.')
return None
# get variable type from variable value
variable_type = self.variable_type(key)
# Enhanced entity array is the wild-wild west, don't validate it
if variable_type != 'TCEnhancedEntityArray':
if validate and (not isinstance(value, Iterable) or isinstance(value, (str, dict))):
raise RuntimeError(f'Invalid data provided for {variable_type}.')
value = [
*value
] # spread the value so that we know it's a list (as opposed to an iterable)
if variable_type == 'BinaryArray':
value_encoded = []
for v in value:
if v is not None:
if validate and not isinstance(v, bytes):
raise RuntimeError('Invalid data provided for Binary.')
# if not isinstance(v, bytes):
# v = v.encode('utf-8')
v = base64.b64encode(v).decode('utf-8')
value_encoded.append(v)
value = value_encoded
elif variable_type == 'KeyValueArray':
if validate and not self._is_key_value_array(value):
raise RuntimeError('Invalid data provided for KeyValueArray.')
elif variable_type == 'StringArray':
value_coerced = []
for v in value:
# coerce string values
v = self._coerce_string_value(v)
if validate and not isinstance(v, (type(None), str)):
raise RuntimeError('Invalid data provided for StringArray.')
value_coerced.append(v)
value = value_coerced
elif variable_type == 'TCEntityArray':
if validate and not self._is_tc_entity_array(value):
raise RuntimeError('Invalid data provided for TcEntityArray.')
# self.log.trace(f'pb create - context: {self._context}, key: {key}, value: {value}')
try:
value = json.dumps(value)
except ValueError as e: # pragma: no cover
raise RuntimeError(f'Failed to serialize value ({e}).')
try:
return self.tcex.key_value_store.create(self._context, key.strip(), value)
except RuntimeError as e:
self.log.error(e)
return None
@staticmethod
def _decode_binary(data):
"""Return decoded bytes data handling data written by java apps."""
try:
data = data.decode('utf-8')
except UnicodeDecodeError: # pragma: no cover
# for data written an upstream java App
data = data.decode('latin-1')
return data
@staticmethod
def _is_key_value(data):
"""Return True if provided data has proper structure for Key Value."""
if data is None:
return False
return all(x in data for x in ['key', 'value'])
def _is_key_value_array(self, data):
"""Return True if provided data has proper structure for Key Value Array."""
for d in data:
if not self._is_key_value(d):
return False
return True
@staticmethod
def _is_tc_entity(data):
"""Return True if provided data has proper structure for TC Entity."""
if data is None:
return False
return all(x in data for x in ['id', 'value', 'type'])
def _is_tc_entity_array(self, data):
"""Return True if provided data has proper structure for TC Entity Array."""
for d in data:
if not self._is_tc_entity(d):
return False
return True
@staticmethod
def _load_value(value):
"""Return the loaded JSON value or raise an error.
Args:
value (str): The data from key/value store.
Raises:
RuntimeError: Raise error when data can't be loaded as JSON data.
Returns:
any: The de-serialized value from the key/value store.
"""
try:
return json.loads(value, object_pairs_hook=OrderedDict)
except ValueError as e: # pragma: no cover
raise RuntimeError(f'Failed to JSON load data "{value}" ({e}).')
def _parse_output_variables(self):
"""Parse the output variables provided to Playbook Class.
**Example Variable Format**::
['#App:1234:status!String', '#App:1234:status_code!String']
"""
self._output_variables_by_name = {}
self._output_variables_by_type = {}
for ov in self._output_variables:
# parse the variable to get individual parts
parsed_variable = self.parse_variable(ov)
variable_name = parsed_variable.get('name')
variable_type = parsed_variable.get('type')
# store the variables in dict by name (e.g. "status_code")
self._output_variables_by_name[variable_name] = {'variable': ov}
# store the variables in dict by name-type (e.g. "status_code-String")
self._output_variables_by_type[f'{variable_name}-{variable_type}'] = {'variable': ov}
def _read(self, key, embedded=True, b64decode=True, decode=False):
"""Create the value in Redis if applicable."""
if key is None:
self.log.warning('The key is None.')
return None
# get variable type from variable value
variable_type = self.variable_type(key)
try:
value = self.tcex.key_value_store.read(self._context, key.strip())
except RuntimeError as e:
self.log.error(e)
return None
if value is None:
return value
if variable_type == 'Binary':
value = self._load_value(value)
if b64decode:
value = base64.b64decode(value)
if decode:
value = self._decode_binary(value)
elif variable_type == 'KeyValue':
# embedded variable can be unquoted, which breaks JSON.
value = self._wrap_embedded_keyvalue(value)
if embedded:
value = self._read_embedded(value)
value = self._load_value(value)
elif variable_type == 'String':
if embedded:
value = self._read_embedded(value)
# coerce string values
value = self._coerce_string_value(self._load_value(value))
elif variable_type == 'TCEntity':
value = self._load_value(value)
return value
def _read_array(self, key, embedded=True, b64decode=True, decode=False):
"""Create the value in Redis if applicable."""
if key is None: # pragma: no cover
self.log.warning('The null value for key was provided.')
return None
# get variable type from variable value
variable_type = self.variable_type(key)
try:
value = self.tcex.key_value_store.read(self._context, key.strip())
except RuntimeError as e:
self.log.error(e)
return None
if value is None:
return value
if variable_type == 'BinaryArray':
value = json.loads(value, object_pairs_hook=OrderedDict)
values = []
for v in value:
if v is not None and b64decode:
v = base64.b64decode(v)
if decode:
v = self._decode_binary(v)
values.append(v)
value = values
elif variable_type == 'KeyValueArray':
# embedded variable can be unquoted, which breaks JSON.
value = self._wrap_embedded_keyvalue(value)
if embedded:
value = self._read_embedded(value)
try:
value = json.loads(value, object_pairs_hook=OrderedDict)
except ValueError as e: # pragma: no cover
raise RuntimeError(f'Failed loading JSON data ({value}). Error: ({e})')
elif variable_type == 'StringArray':
if embedded:
value = self._read_embedded(value)
# convert int to str
value_coerced = []
for v in self._load_value(value):
# coerce string values
value_coerced.append(self._coerce_string_value(v))
value = value_coerced
elif variable_type in ['TCEntityArray', 'TCEnhancedEntity', 'TCEnhancedEntityArray']:
value = self._load_value(value)
# self.log.trace(f'pb create - context: {self._context}, key: {key}, value: {value}')
return value
def _read_embedded(self, value):
"""Read method for "embedded" variables.
.. Note:: The ``read()`` method will automatically determine if the input is a variable or
needs to be searched for embedded variables.
Embedded variable rules:
* Only user input can have embedded variables.
* Only String and KeyValueArray variables can have embedded variables.
* Variables can only be embedded one level deep.
This method will automatically covert variables embedded in a string with value retrieved
from DB. If there are no keys/variables the raw string will be returned.
Examples::
DB Values
#App:7979:variable_name!String:
"embedded \\"variable\\""
#App:7979:two!String:
"two"
#App:7979:variable_name!StringArray:
["one", "two", "three"]
Examples 1:
Input: "This input has a embedded #App:7979:variable_name!String"
Examples 2:
Input: ["one", #App:7979:two!String, "three"]
Examples 3:
Input: [{
"key": "embedded string",
"value": "This input has a embedded #App:7979:variable_name!String"
}, {
"key": "string array",
"value": #App:7979:variable_name!StringArray
}, {
"key": "string",
"value": #App:7979:variable_name!String
}]
Args:
value (str): The value to parsed and updated from the DB.
Returns:
(str): Results retrieved from DB
"""
if value is None: # pragma: no cover
return value
for variable in (v.group(0) for v in re.finditer(self._variable_parse, str(value))):
v = self.read(variable)
self.log.trace(f'embedded variable: {variable}, value: {v}')
if isinstance(v, (dict, list)):
v = json.dumps(v)
# for KeyValueArray with nested dict/list type replace the
# quoted value to ensure the resulting data is loadable JSON
value = re.sub(f'"{variable}"', v, value)
if v is not None:
# only replace variable if a non-null value is returned from kv store
# APP-1030 need to revisit this to handle variable references in kv/kvarrays that
# are None. Would like to be able to say if value is just the variable reference,
# sub None value, else insert '' in string. That would require a kv-specific
# version of this method that gets the entire list/dict instead of just the string.
value = re.sub(variable, v, value)
return value
@property
def _variable_pattern(self):
"""Regex pattern to match and parse a playbook variable."""
variable_pattern = r'#([A-Za-z]+)' # match literal (#App,#Trigger) at beginning of String
variable_pattern += r':([\d]+)' # app id (:7979)
variable_pattern += r':([A-Za-z0-9_\.\-\[\]]+)' # variable name (:variable_name)
variable_pattern += r'!(StringArray|BinaryArray|KeyValueArray' # variable type (array)
variable_pattern += r'|TCEntityArray|TCEnhancedEntityArray' # variable type (array)
variable_pattern += r'|String|Binary|KeyValue|TCEntity|TCEnhancedEntity' # variable type
variable_pattern += r'|(?:(?!String)(?!Binary)(?!KeyValue)' # non matching for custom
variable_pattern += r'(?!TCEntity)(?!TCEnhancedEntity)' # non matching for custom
variable_pattern += r'[A-Za-z0-9_-]+))' # variable type (custom)
return variable_pattern
@property
def _variable_array_types(self):
"""Return list of standard playbook array variable types."""
return [
'BinaryArray',
'KeyValueArray',
'StringArray',
'TCEntityArray',
'TCEnhancedEntityArray',
]
@property
def _variable_single_types(self):
"""Return list of standard playbook single variable types."""
return [
'Binary',
'KeyValue',
'String',
'TCEntity',
'TCEnhancedEntity',
]
@property
def _variable_types(self):
"""Return list of standard playbook variable typesd."""
return self._variable_single_types + self._variable_array_types
def _wrap_embedded_keyvalue(self, data):
"""Wrap keyvalue embedded variable in double quotes.
Args:
data (str): The data with embedded variables.
Returns:
(str): Results retrieved from DB
"""
# TODO: need to verify if core still sends improper JSON for KeyValueArrays
if data is not None: # pragma: no cover
variables = []
for v in re.finditer(self._vars_keyvalue_embedded, data):
variables.append(v.group(0))
for var in set(variables): # recursion over set to handle duplicates
# pull (#App:1441:embedded_string!String) from (": #App:1441:embedded_string!String)
variable_string = re.search(self._variable_parse, var).group(0)
# reformat to replace the correct instance only, handling the case where a variable
# is embedded multiple times in the same key value array.
data = data.replace(var, f'": "{variable_string}"')
return data
def create_raw(self, key, value):
"""Create method of CRUD operation for raw data.
..important:: Raw data can only be a byte, str or int. Other data structures
(dict, list, etc) must be serialized.
Args:
key (str): The variable to write to the DB.
value (bytes|int|string): The data to write to the DB.
Returns:
(str): Result of DB write.
"""
data = None
if key is not None and value is not None:
try:
data = self.tcex.key_value_store.create(self._context, key.strip(), value)
except RuntimeError as e:
self.log.error(e)
else:
self.log.warning('The key or value field was None.')
return data
def read_raw(self, key):
"""Read method of CRUD operation for raw data.
..important:: Bytes input will be returned a as string as there is
no way to determine data from redis originated as bytes or string.
Args:
key (str): The variable to read from the DB.
Returns:
(str): Results retrieved from DB.
"""
value = None
if key is not None:
value = self.tcex.key_value_store.read(self._context, key.strip())
else:
self.log.warning('The key field was None.')
return value
def parse_variable(self, variable): # pragma: no cover
"""Set placeholder for child method."""
raise NotImplementedError('Implemented in child class')
def read(self, key, array=False, embedded=True): # pragma: no cover
"""Set placeholder for child method."""
raise NotImplementedError('Implemented in child class')
def variable_type(self, variable): # pragma: no cover
"""Set placeholder for child method."""
raise NotImplementedError('Implemented in child class')
| 38.857977 | 100 | 0.586191 | 1 | 1.9326 | [
-0.026492483913898468,
0.033126749098300934,
0.00426010275259614,
0.0017070999601855874,
0.005240694619715214,
0.0034254956990480423,
-0.011714420281350613,
0.012999075464904308,
-0.01174459420144558,
0.03916159272193909,
0.010079408995807171,
-0.008627869188785553,
-0.015836067497730255,
-0.044850338250398636,
-0.022752925753593445,
-0.013925675302743912,
0.1696067601442337,
0.028576230630278587,
-0.036002688109874725,
0.01570728048682213,
0.016622813418507576,
0.003982889000326395,
0.00644230842590332,
0.02747221849858761,
0.04500996321439743,
0.011776246130466461,
0.06355433911085129,
0.01225624606013298,
0.005771801806986332,
-0.0097120963037014,
-0.01758056879043579,
0.039320286363363266,
0.011386334896087646,
0.01767229661345482,
-0.019174158573150635,
-0.006898036226630211,
0.032086435705423355,
-0.041646815836429596,
0.03383750468492508,
0.034777648746967316,
-0.052055906504392624,
0.011548301205039024,
-0.0013732978841289878,
-0.01863742619752884,
0.0043607489205896854,
0.004285389557480812,
-0.02191740646958351,
0.01790933683514595,
-0.028411690145730972,
-0.010173160582780838,
0.015568865463137627,
0.056705281138420105,
-0.033368758857250214,
-0.028271235525608063,
-0.0007649745675735176,
-0.05059148743748665,
0.03027356043457985,
-0.03687756881117821,
-0.0374002680182457,
0.01803303137421608,
-0.03754021227359772,
-0.014752065762877464,
0.012289067730307579,
-0.02997719869017601,
0.02967418171465397,
0.020339470356702805,
0.010222711600363255,
0.010902836918830872,
0.0022154569160193205,
-0.002429526997730136,
-0.06202147528529167,
-0.021849291399121284,
-0.03189372271299362,
0.06843594461679459,
0.07204132527112961,
-0.0021636509336531162,
-0.005311979912221432,
-0.03888899087905884,
-0.021124521270394325,
0.025733353570103645,
-0.0019209198653697968,
0.040178027004003525,
-0.013331054709851742,
-0.006847398355603218,
-0.011126859113574028,
0.05313250422477722,
0.05726390704512596,
-0.038787491619586945,
0.02865559607744217,
-0.004754392430186272,
0.005136546213179827,
0.039431359618902206,
-0.036015190184116364,
-0.021653179079294205,
-0.03370659798383713,
-0.0483219288289547,
0.007783009670674801,
0.03222101181745529,
0.01135403010994196,
0.053107552230358124,
0.007484058849513531,
-0.04657525196671486,
0.04810279607772827,
0.004538304638117552,
0.011853566393256187,
0.02394128032028675,
-0.03104514442384243,
0.012033366598188877,
-0.026235481724143028,
-0.0371343195438385,
-0.06079358235001564,
-0.0002601943851914257,
0.0365382619202137,
0.005726653151214123,
0.007969140075147152,
-0.0013270076597109437,
0.0378769114613533,
0.009539674036204815,
0.0558539517223835,
0.04941967502236366,
0.008258037269115448,
0.009479153901338577,
0.019569924101233482,
-0.0013524325331673026,
-0.025831859558820724,
0.08417046815156937,
-0.0020870210137218237,
-0.04426855593919754,
0.033636707812547684,
-0.02636181004345417,
-0.00746498117223382,
0.018161876127123833,
0.008941163308918476,
0.01993991807103157,
0.02375951036810875,
-0.024888822808861732,
-0.011920358054339886,
-0.012307650409638882,
-0.03166421502828598,
-0.008905822411179543,
-0.023052606731653214,
-0.013128257356584072,
0.011822269298136234,
0.02258196845650673,
0.0011571384966373444,
-0.08279396593570709,
-0.0101341987028718,
-0.020998788997530937,
-0.010233177803456783,
-0.02413392998278141,
0.05685370787978172,
0.019813476130366325,
-0.009195896796882153,
-0.022064320743083954,
0.008588852360844612,
-0.026589209213852882,
-0.004210966639220715,
-0.0673920065164566,
-0.027820715680718422,
0.005441715940833092,
-0.04385765269398689,
0.014743498526513577,
0.03845147788524628,
0.007128526456654072,
0.0019071842543780804,
0.03195706754922867,
-0.07316602021455765,
0.014898259192705154,
0.041284311562776566,
-0.019378354772925377,
-0.016074873507022858,
0.018388107419013977,
-0.007140032947063446,
-0.0010453733848407865,
0.02133764512836933,
0.05133211240172386,
0.03466039523482323,
0.008565948344767094,
-0.027111053466796875,
-0.021370278671383858,
0.03603935241699219,
0.026136506348848343,
0.04061616212129593,
0.03650018945336342,
-0.006544990465044975,
-0.016958866268396378,
-0.030529120936989784,
-0.04103085398674011,
-0.03810778632760048,
-0.01042165420949459,
0.00045033555943518877,
0.042506515979766846,
0.04766244441270828,
-0.01632143184542656,
-0.003046590369194746,
0.030280541628599167,
0.01861724629998207,
-0.008141177706420422,
0.0009159751934930682,
0.006484923884272575,
0.020785242319107056,
-0.002816095482558012,
-0.013172551989555359,
0.0016536397160962224,
-0.015922503545880318,
-0.0029042595997452736,
-0.642687201499939,
0.04402593895792961,
0.012329530902206898,
0.006162720732390881,
0.03238821029663086,
0.020780380815267563,
0.01835699751973152,
0.023067746311426163,
0.0316927544772625,
-0.005418826825916767,
-0.026788994669914246,
-0.0019250430632382631,
-0.000584147812332958,
-0.03196932002902031,
0.030388275161385536,
0.008508609607815742,
-0.02846677415072918,
0.00026044604601338506,
-0.058024778962135315,
0.01721515879034996,
-0.0139430807903409,
-0.10065814852714539,
-0.02721395529806614,
-0.0020304073113948107,
-0.002053829375654459,
0.02271198481321335,
-0.031128183007240295,
0.011206170544028282,
0.0021406770683825016,
0.017537251114845276,
-0.02381589449942112,
0.00203520804643631,
0.021480342373251915,
-0.03567471727728844,
0.020342731848359108,
0.0007233057403936982,
0.012645957991480827,
-0.02357730269432068,
-0.030951108783483505,
0.014912514016032219,
-0.044739123433828354,
-0.013482600450515747,
0.014172577299177647,
-0.04603785276412964,
-0.0397598035633564,
-0.023624571040272713,
0.022268664091825485,
0.010039678774774075,
0.010514572262763977,
0.01714971847832203,
-0.0024341545067727566,
0.0145419891923666,
0.020156966522336006,
-0.04721059277653694,
-0.0009244359098374844,
-0.023445716127753258,
-0.059073176234960556,
0.020979249849915504,
-0.03318186476826668,
0.04339056834578514,
-0.010434106923639774,
-0.018786031752824783,
-0.024663664400577545,
0.036297790706157684,
-0.03622858226299286,
-0.01489007193595171,
0.031164169311523438,
-0.030794013291597366,
0.0082374457269907,
0.016094572842121124,
0.007662446238100529,
0.008500959724187851,
-0.03884540870785713,
0.023307066410779953,
-0.006925503257662058,
0.003033536020666361,
-0.04687619209289551,
-0.009570993483066559,
-0.061877280473709106,
-0.006457380950450897,
-0.01863466389477253,
-0.030595069751143456,
-0.031005945056676865,
0.006941657047718763,
-0.012447851710021496,
0.02207823470234871,
-0.005605329293757677,
0.02094416320323944,
-0.012230084277689457,
0.03146529570221901,
-0.013204580172896385,
0.039171457290649414,
0.019212709739804268,
0.0033914304804056883,
0.018546508625149727,
-0.008265946991741657,
0.028404971584677696,
0.03157088905572891,
-0.03556611388921738,
-0.015182740986347198,
-0.0165728572756052,
-0.011340633034706116,
-0.0021601456683129072,
0.023307709023356438,
-0.016120806336402893,
-0.0003571975394152105,
-0.04601306840777397,
-0.008017754182219505,
0.05490870401263237,
-0.06429142504930496,
-0.002397282049059868,
-0.007293604779988527,
-0.07199389487504959,
0.023716086521744728,
-0.004755090456455946,
0.023014061152935028,
0.000010212036613665987,
-0.041986268013715744,
0.00603594072163105,
0.004024825990200043,
-0.0017520861001685262,
-0.018202707171440125,
-0.0305788516998291,
0.042189694941043854,
0.023433424532413483,
0.012017501518130302,
0.007250754628330469,
0.019320117309689522,
0.023838194087147713,
0.08116158843040466,
-0.029433095827698708,
-0.02459203638136387,
-0.017472321167588234,
-0.019861966371536255,
-0.007351816166192293,
-0.00043791081407107413,
-0.011797216720879078,
-0.0337735116481781,
0.042166538536548615,
-0.005410502199083567,
-0.007234770338982344,
-0.011439045891165733,
0.03664674982428551,
-0.03902972489595413,
-0.0040283482521772385,
0.01533075887709856,
-0.026288913562893867,
0.02373647689819336,
-0.004149720538407564,
-0.006074852775782347,
0.0253804512321949,
0.016995249316096306,
0.003651935374364257,
-0.02547488920390606,
-0.03353385254740715,
-0.001789588131941855,
-0.007036226335912943,
0.024105355143547058,
-0.0056359120644629,
0.007130087353289127,
-0.019048254936933517,
-0.027070200070738792,
0.01613793708384037,
-0.01726192981004715,
0.015361735597252846,
-0.0007050487329252064,
-0.01975555159151554,
-0.0049615781754255295,
0.008701225742697716,
0.053307052701711655,
0.01847962848842144,
-0.04772711545228958,
-0.027055086567997932,
0.029320046305656433,
-0.00807702075690031,
0.04445592314004898,
0.020124001428484917,
-0.059761643409729004,
0.02683677338063717,
-0.010449941270053387,
0.053023505955934525,
0.02868669666349888,
-0.011956684291362762,
-0.009828814305365086,
-0.0035646024625748396,
0.003409111639484763,
-0.023016517981886864,
0.01682153530418873,
0.039667386561632156,
-0.013684827834367752,
0.014226937666535378,
0.020089300349354744,
0.04953847452998161,
-0.017189757898449898,
0.010173613205552101,
-0.03125299885869026,
-0.020656157284975052,
-0.03909223899245262,
-0.026077307760715485,
-0.010008484125137329,
-0.017399758100509644,
0.0031784879975020885,
-0.0680774450302124,
-0.01174899935722351,
-0.0019138603238388896,
0.013496934436261654,
0.014982580207288265,
0.0012486027553677559,
-0.004802849143743515,
-0.02392924576997757,
-0.005026002414524555,
-0.010004829615354538,
0.02286403998732567,
-0.053730759769678116,
0.02410120889544487,
0.0363895408809185,
-0.05957110971212387,
0.02109611965715885,
0.02368444949388504,
-0.05659520998597145,
-0.0037987749092280865,
-0.046653419733047485,
0.005596024449914694,
0.005146278999745846,
-0.022470343858003616,
-0.011688916012644768,
0.01007405947893858,
0.018541771918535233,
0.006360533181577921,
-0.03658744692802429,
0.029706060886383057,
-0.005487562157213688,
0.016310911625623703,
-0.02571854367852211,
-0.07455063611268997,
0.005809797905385494,
-0.04166221618652344,
-0.0350237675011158,
-0.0023393998853862286,
-0.0204019695520401,
0.04790131002664566,
-0.016597751528024673,
-0.011788536794483662,
0.005434851627796888,
-0.045154113322496414,
-0.021219369024038315,
0.004522162023931742,
-0.04585002362728119,
-0.04870498180389404,
-0.009271848946809769,
-0.028179055079817772,
0.02361936867237091,
0.025081738829612732,
-0.0019756348337978125,
0.005528111942112446,
0.047704048454761505,
-0.01371914055198431,
-0.01801132783293724,
0.013987748883664608,
-0.00650338688865304,
0.027743183076381683,
0.002147229388356209,
0.04003719985485077,
0.022641843184828758,
-0.02338455617427826,
0.0006874655955471098,
0.026561226695775986,
0.006763397250324488,
0.012033728882670403,
-0.011090710759162903,
0.03529167175292969,
-0.01184875052422285,
-0.006503406446427107,
0.006320430897176266,
0.016162022948265076,
0.031486984342336655,
0.02924882248044014,
-0.0026124559808522463,
-0.0102060716599226,
0.05812367424368858,
-0.009265008382499218,
0.0211701188236475,
0.04204760119318962,
0.010466303676366806,
0.037050485610961914,
-0.015241492539644241,
0.034923769533634186,
-0.06361866742372513,
-0.01809895969927311,
0.019622299820184708,
-0.010427077300846577,
-0.04694438353180885,
-0.007326016202569008,
0.02699834108352661,
0.0011028717271983624,
-0.03317767381668091,
-0.00990062952041626,
0.017598368227481842,
0.028182974085211754,
-0.0006408480112440884,
0.0504254549741745,
0.012263965792953968,
0.008512777276337147,
0.005365447606891394,
-0.02658180706202984,
-0.010978375561535358,
0.024613048881292343,
-0.023987796157598495,
0.014237669296562672,
0.03982022777199745,
0.003448805306106806,
0.03056768700480461,
-0.044160179793834686,
-0.037880949676036835,
0.022333895787596703,
0.03385079279541969,
0.06810111552476883,
-0.004469740204513073,
0.03468757122755051,
-0.0035762384068220854,
-0.014947627671062946,
-0.020196231082081795,
0.004451255314052105,
-0.004327440168708563,
0.015755360946059227,
-0.025855515152215958,
-0.019993608817458153,
-0.028366221114993095,
-0.04571126773953438,
0.0205271877348423,
-0.011136160232126713,
-0.003182831918820739,
-0.0011034851195290685,
-0.010466408915817738,
0.05528881773352623,
-0.03601424768567085,
0.020642932504415512,
0.015761014074087143,
0.035714611411094666,
0.005183093249797821,
-0.001968592405319214,
0.03531483933329582,
-0.024750489741563797,
-0.02635687217116356,
0.025851670652627945,
-0.04366673156619072,
-0.05550682917237282,
0.003664343850687146,
0.023315170779824257,
-0.014445364475250244,
-0.02533208765089512,
-0.01750774495303631,
0.010182707570493221,
0.007390250917524099,
-0.02371188811957836,
0.004419032949954271,
-0.023642417043447495,
0.00012361408153083175,
0.036081381142139435,
0.013292103074491024,
0.032708801329135895,
-0.016387900337576866,
-0.0007920719217509031,
-0.0038196623791009188,
0.001962080830708146,
-0.02492344006896019,
0.018428528681397438,
0.005978578235954046,
-0.01997273601591587,
0.04578286036849022,
0.00712496368214488,
-0.017842106521129608,
0.027035702019929886,
0.013121851719915867,
0.011254661716520786,
-0.007067596539855003,
0.0364958755671978,
0.010174429975450039,
-0.04827333986759186,
0.012317044660449028,
-0.03143290430307388,
-0.039982326328754425,
-0.00033074902603402734,
0.035188939422369,
0.01759805716574192,
-0.04287387803196907,
-0.026815373450517654,
0.06011173874139786,
-0.025822320953011513,
-0.02307899296283722,
0.0022641203831881285,
0.005860496778041124,
-0.019355857744812965,
0.02805674448609352,
0.010656219907104969,
0.012144994921982288,
-0.026584750041365623,
0.004836041014641523,
-0.004822170827537775,
-0.02146129496395588,
-0.012373319827020168,
-0.009140915237367153,
-0.019826730713248253,
-0.012168346904218197,
0.004987312946468592,
-0.031088419258594513,
0.0029010027647018433,
0.02727031521499157,
0.013070045039057732,
0.010786650702357292,
0.016392845660448074,
0.03894192725419998,
-0.04295520484447479,
-0.059205759316682816,
-0.01325114443898201,
-0.018419645726680756,
-0.045083776116371155,
-0.009243309497833252,
0.028792627155780792,
0.06095708906650543,
-0.018678423017263412,
-0.004675453994423151,
-0.023340221494436264,
-0.0029433355666697025,
-0.005688748322427273,
-0.029728533700108528,
0.03617510572075844,
0.02363872155547142,
-0.003322990145534277,
0.016704728826880455,
-0.04488459229469299,
-0.06486351042985916,
0.03320835158228874,
0.03231997415423393,
-0.006487877573817968,
-0.018292613327503204,
-0.00005247407534625381,
-0.013543793000280857,
0.021171072497963905,
-0.009776473976671696,
0.0460486114025116,
0.005711766425520182,
-0.020315734669566154,
0.032648053020238876,
-0.014667567797005177,
-0.06124655529856682,
0.025926737114787102,
-0.0217930655926466,
0.019240686669945717,
0.00809568166732788,
-0.028418811038136482,
0.008320922963321209,
0.027187395840883255,
-0.004176152404397726,
0.045421939343214035,
0.01563798263669014,
0.0031888459343463182,
-0.013015138916671276,
0.022980881854891777,
0.02214132994413376,
-0.0001073306193575263,
0.04759149253368378,
0.025393439456820488,
0.011835265904664993,
0.0072622341103851795,
0.007407600525766611,
-0.007195113226771355,
-0.029767295345664024,
0.011666964739561081,
-0.0035748162772506475,
-0.014281869865953922,
0.007277327124029398,
0.0018680798821151257,
-0.014849529601633549,
-0.003122401423752308,
0.006040812470018864,
-0.01921810209751129,
-0.014837668277323246,
-0.02259856089949608,
0.026980867609381676,
0.017294026911258698,
-0.012327756732702255,
-0.0036069119814783335,
0.01895749568939209,
-0.017924953252077103,
0.0016560301883146167,
-0.02543359249830246,
-0.018360162153840065,
0.038288503885269165,
0.015944404527544975,
-0.008342066779732704,
-0.00014416287012863904,
-0.033574074506759644,
-0.007010042201727629,
0.000007790011295583099,
-0.020362455397844315,
-0.0014631613157689571,
0.0051956153474748135,
-0.0008748386171646416,
0.009568491019308567,
0.012186767533421516,
-0.0016633286140859127,
0.014955924823880196,
0.0074206870049238205,
0.04984631761908531,
0.01777457818388939,
0.006476610898971558,
0.021139858290553093,
-0.019782422110438347,
-0.04674748331308365,
-0.026242347434163094,
-0.008185682818293571,
-0.00991168525069952,
0.00709886010736227,
0.019007110968232155,
0.016727304086089134,
0.014245698228478432,
-0.039423875510692596,
0.03269137069582939,
-0.015988124534487724,
0.011863659135997295,
0.0051209512166678905,
-0.0028800007421523333,
-0.02166619338095188,
-0.011339136399328709,
-0.007884695194661617,
-0.029442040249705315,
0.04015427082777023,
-0.017220089212059975,
0.020541511476039886,
0.007680207025259733,
0.04370177909731865,
0.0037622787058353424,
-0.01352083683013916,
0.018431425094604492,
-0.04186876118183136,
-0.01712593249976635,
0.04403126612305641,
-0.003719293512403965,
-0.02111225202679634,
0.02953142300248146,
-0.005388463847339153,
-0.0054641966708004475,
-0.011521418578922749,
0.004244828596711159,
0.020887210965156555,
0.060160353779792786,
0.03459089621901512,
-0.014835593290627003,
0.007902887649834156,
-0.009966223500669003,
-0.004434766713529825,
-0.04344494268298149,
-0.010469908826053143,
-0.00032608743640594184,
-0.026439310982823372,
0.006850610487163067,
0.04036600515246391,
-0.03647525608539581,
-0.009395691566169262,
-0.02202596701681614,
0.004118338692933321
] |
8a2c1d2751e3ec16040b8d54e21b7960cfed3c22 | 31,780 | py | Python | DeepLearningExamples/TensorFlow/LanguageModeling/BERT/run_classifier.py | puririshi98/benchmark | 79f554f1e1cf36f62994c78e0e6e5b360f554022 | [
"BSD-3-Clause"
] | null | null | null | DeepLearningExamples/TensorFlow/LanguageModeling/BERT/run_classifier.py | puririshi98/benchmark | 79f554f1e1cf36f62994c78e0e6e5b360f554022 | [
"BSD-3-Clause"
] | null | null | null | DeepLearningExamples/TensorFlow/LanguageModeling/BERT/run_classifier.py | puririshi98/benchmark | 79f554f1e1cf36f62994c78e0e6e5b360f554022 | [
"BSD-3-Clause"
] | null | null | null | # coding=utf-8
# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved.
# Copyright 2018 The Google AI Language Team Authors.
#
# 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.
"""BERT finetuning runner."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import collections
import csv
import os
import modeling
import optimization
import tokenization
import tensorflow as tf
import horovod.tensorflow as hvd
import time
from utils.utils import LogEvalRunHook, LogTrainRunHook, setup_xla_flags
from utils.gpu_affinity import set_affinity
import utils.dllogger_class
from dllogger import Verbosity
from utils.create_glue_data import *
import numpy as np
import tf_metrics
flags = tf.flags
FLAGS = flags.FLAGS
## Required parameters
flags.DEFINE_string(
"data_dir", None,
"The input data dir. Should contain the .tsv files (or other data files) "
"for the task.")
flags.DEFINE_string(
"bert_config_file", None,
"The config json file corresponding to the pre-trained BERT model. "
"This specifies the model architecture.")
flags.DEFINE_string("task_name", None, "The name of the task to train.")
flags.DEFINE_string("vocab_file", None,
"The vocabulary file that the BERT model was trained on.")
flags.DEFINE_string(
"output_dir", None,
"The output directory where the model checkpoints will be written.")
## Other parameters
flags.DEFINE_string(
"dllog_path", "/results/bert_dllog.json",
"filename where dllogger writes to")
flags.DEFINE_string(
"optimizer_type", "lamb",
"Optimizer type : adam or lamb")
flags.DEFINE_string(
"init_checkpoint", None,
"Initial checkpoint (usually from a pre-trained BERT model).")
flags.DEFINE_bool(
"do_lower_case", True,
"Whether to lower case the input text. Should be True for uncased "
"models and False for cased models.")
flags.DEFINE_integer(
"max_seq_length", 128,
"The maximum total input sequence length after WordPiece tokenization. "
"Sequences longer than this will be truncated, and sequences shorter "
"than this will be padded.")
flags.DEFINE_bool("do_train", False, "Whether to run training.")
flags.DEFINE_bool("do_eval", False, "Whether to run eval on the dev set.")
flags.DEFINE_bool(
"do_predict", False,
"Whether to run the model in inference mode on the test set.")
flags.DEFINE_integer("train_batch_size", 32, "Total batch size for training.")
flags.DEFINE_integer("eval_batch_size", 8, "Total batch size for eval.")
flags.DEFINE_integer("predict_batch_size", 8, "Total batch size for predict.")
flags.DEFINE_float("learning_rate", 5e-5, "The initial learning rate for Adam.")
flags.DEFINE_bool("use_trt", False, "Whether to use TF-TRT")
flags.DEFINE_float("num_train_epochs", 3.0,
"Total number of training epochs to perform.")
flags.DEFINE_float(
"warmup_proportion", 0.1,
"Proportion of training to perform linear learning rate warmup for. "
"E.g., 0.1 = 10% of training.")
flags.DEFINE_integer("save_checkpoints_steps", 1000,
"How often to save the model checkpoint.")
flags.DEFINE_integer("display_loss_steps", 10,
"How often to print loss from estimator")
flags.DEFINE_integer("iterations_per_loop", 1000,
"How many steps to make in each estimator call.")
flags.DEFINE_integer("num_accumulation_steps", 1,
"Number of accumulation steps before gradient update"
"Global batch size = num_accumulation_steps * train_batch_size")
flags.DEFINE_bool("amp", True, "Whether to enable AMP ops. When false, uses TF32 on A100 and FP32 on V100 GPUS.")
flags.DEFINE_bool("use_xla", True, "Whether to enable XLA JIT compilation.")
flags.DEFINE_bool("horovod", False, "Whether to use Horovod for multi-gpu runs")
flags.DEFINE_bool(
"verbose_logging", False,
"If true, all of the warnings related to data processing will be printed. "
"A number of warnings are expected for a normal SQuAD evaluation.")
def file_based_input_fn_builder(input_file, batch_size, seq_length, is_training,
drop_remainder, hvd=None):
"""Creates an `input_fn` closure to be passed to Estimator."""
name_to_features = {
"input_ids": tf.io.FixedLenFeature([seq_length], tf.int64),
"input_mask": tf.io.FixedLenFeature([seq_length], tf.int64),
"segment_ids": tf.io.FixedLenFeature([seq_length], tf.int64),
"label_ids": tf.io.FixedLenFeature([], tf.int64),
}
def _decode_record(record, name_to_features):
"""Decodes a record to a TensorFlow example."""
example = tf.parse_single_example(record, name_to_features)
# tf.Example only supports tf.int64, but the TPU only supports tf.int32.
# So cast all int64 to int32.
for name in list(example.keys()):
t = example[name]
if t.dtype == tf.int64:
t = tf.to_int32(t)
example[name] = t
return example
def input_fn():
"""The actual input function."""
# For training, we want a lot of parallel reading and shuffling.
# For eval, we want no shuffling and parallel reading doesn't matter.
d = tf.data.TFRecordDataset(input_file)
if is_training:
if hvd is not None: d = d.shard(hvd.size(), hvd.rank())
d = d.repeat()
d = d.shuffle(buffer_size=100)
d = d.apply(
tf.contrib.data.map_and_batch(
lambda record: _decode_record(record, name_to_features),
batch_size=batch_size,
drop_remainder=drop_remainder))
return d
return input_fn
def create_model(bert_config, is_training, input_ids, input_mask, segment_ids,
labels, num_labels, use_one_hot_embeddings):
"""Creates a classification model."""
model = modeling.BertModel(
config=bert_config,
is_training=is_training,
input_ids=input_ids,
input_mask=input_mask,
token_type_ids=segment_ids,
use_one_hot_embeddings=use_one_hot_embeddings,
compute_type=tf.float32)
# In the demo, we are doing a simple classification task on the entire
# segment.
#
# If you want to use the token-level output, use model.get_sequence_output()
# instead.
output_layer = model.get_pooled_output()
hidden_size = output_layer.shape[-1].value
output_weights = tf.get_variable(
"output_weights", [num_labels, hidden_size],
initializer=tf.truncated_normal_initializer(stddev=0.02))
output_bias = tf.get_variable(
"output_bias", [num_labels], initializer=tf.zeros_initializer())
with tf.variable_scope("loss"):
if is_training:
# I.e., 0.1 dropout
output_layer = tf.nn.dropout(output_layer, keep_prob=0.9)
logits = tf.matmul(output_layer, output_weights, transpose_b=True)
logits = tf.nn.bias_add(logits, output_bias, name='cls_logits')
probabilities = tf.nn.softmax(logits, axis=-1, name='cls_probabilities')
log_probs = tf.nn.log_softmax(logits, axis=-1)
one_hot_labels = tf.one_hot(labels, depth=num_labels, dtype=tf.float32)
per_example_loss = -tf.reduce_sum(one_hot_labels * log_probs, axis=-1, name='cls_per_example_loss')
loss = tf.reduce_mean(per_example_loss, name='cls_loss')
return (loss, per_example_loss, logits, probabilities)
def get_frozen_tftrt_model(bert_config, shape, num_labels, use_one_hot_embeddings, init_checkpoint):
tf_config = tf.compat.v1.ConfigProto()
tf_config.gpu_options.allow_growth = True
output_node_names = ['loss/cls_loss', 'loss/cls_per_example_loss', 'loss/cls_logits', 'loss/cls_probabilities']
with tf.Session(config=tf_config) as tf_sess:
input_ids = tf.placeholder(tf.int32, shape, 'input_ids')
input_mask = tf.placeholder(tf.int32, shape, 'input_mask')
segment_ids = tf.placeholder(tf.int32, shape, 'segment_ids')
label_ids = tf.placeholder(tf.int32, (None), 'label_ids')
create_model(bert_config, False, input_ids, input_mask, segment_ids, label_ids,
num_labels, use_one_hot_embeddings)
tvars = tf.trainable_variables()
(assignment_map, initialized_variable_names) = modeling.get_assignment_map_from_checkpoint(tvars, init_checkpoint)
tf.train.init_from_checkpoint(init_checkpoint, assignment_map)
tf_sess.run(tf.global_variables_initializer())
print("LOADED!")
tf.compat.v1.logging.info("**** Trainable Variables ****")
for var in tvars:
init_string = ""
if var.name in initialized_variable_names:
init_string = ", *INIT_FROM_CKPT*"
else:
init_string = ", *NOTTTTTTTTTTTTTTTTTTTTT"
tf.compat.v1.logging.info(" name = %s, shape = %s%s", var.name, var.shape, init_string)
frozen_graph = tf.graph_util.convert_variables_to_constants(tf_sess,
tf_sess.graph.as_graph_def(), output_node_names)
num_nodes = len(frozen_graph.node)
print('Converting graph using TensorFlow-TensorRT...')
from tensorflow.python.compiler.tensorrt import trt_convert as trt
converter = trt.TrtGraphConverter(
input_graph_def=frozen_graph,
nodes_blacklist=output_node_names,
max_workspace_size_bytes=(4096 << 20) - 1000,
precision_mode = "FP16" if FLAGS.amp else "FP32",
minimum_segment_size=4,
is_dynamic_op=True,
maximum_cached_engines=1000
)
frozen_graph = converter.convert()
print('Total node count before and after TF-TRT conversion:',
num_nodes, '->', len(frozen_graph.node))
print('TRT node count:',
len([1 for n in frozen_graph.node if str(n.op) == 'TRTEngineOp']))
with tf.io.gfile.GFile("frozen_modelTRT.pb", "wb") as f:
f.write(frozen_graph.SerializeToString())
return frozen_graph
def model_fn_builder(task_name, bert_config, num_labels, init_checkpoint, learning_rate,
num_train_steps, num_warmup_steps,
use_one_hot_embeddings, hvd=None):
"""Returns `model_fn` closure for Estimator."""
def model_fn(features, labels, mode, params): # pylint: disable=unused-argument
"""The `model_fn` for Estimator."""
def metric_fn(per_example_loss, label_ids, logits):
predictions = tf.argmax(logits, axis=-1, output_type=tf.int32)
if task_name == "cola":
FN, FN_op = tf.metrics.false_negatives(labels=label_ids, predictions=predictions)
FP, FP_op = tf.metrics.false_positives(labels=label_ids, predictions=predictions)
TP, TP_op = tf.metrics.true_positives(labels=label_ids, predictions=predictions)
TN, TN_op = tf.metrics.true_negatives(labels=label_ids, predictions=predictions)
MCC = (TP * TN - FP * FN) / ((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)) ** 0.5
MCC_op = tf.group(FN_op, TN_op, TP_op, FP_op, tf.identity(MCC, name="MCC"))
return {"MCC": (MCC, MCC_op)}
elif task_name == "mrpc":
accuracy = tf.metrics.accuracy(
labels=label_ids, predictions=predictions)
loss = tf.metrics.mean(values=per_example_loss)
f1 = tf_metrics.f1(labels=label_ids, predictions=predictions, num_classes=2, pos_indices=[1])
return {
"eval_accuracy": accuracy,
"eval_f1": f1,
"eval_loss": loss,
}
else:
accuracy = tf.metrics.accuracy(
labels=label_ids, predictions=predictions)
loss = tf.metrics.mean(values=per_example_loss)
return {
"eval_accuracy": accuracy,
"eval_loss": loss,
}
tf.compat.v1.logging.info("*** Features ***")
tf.compat.v1.logging.info("*** Features ***")
for name in sorted(features.keys()):
tf.compat.v1.logging.info(" name = %s, shape = %s" % (name, features[name].shape))
input_ids = features["input_ids"]
input_mask = features["input_mask"]
segment_ids = features["segment_ids"]
label_ids = features["label_ids"]
is_training = (mode == tf.estimator.ModeKeys.TRAIN)
if not is_training and FLAGS.use_trt:
trt_graph = get_frozen_tftrt_model(bert_config, input_ids.shape, num_labels, use_one_hot_embeddings, init_checkpoint)
(total_loss, per_example_loss, logits, probabilities) = tf.import_graph_def(trt_graph,
input_map={'input_ids':input_ids, 'input_mask':input_mask, 'segment_ids':segment_ids, 'label_ids':label_ids},
return_elements=['loss/cls_loss:0', 'loss/cls_per_example_loss:0', 'loss/cls_logits:0', 'loss/cls_probabilities:0'],
name='')
if mode == tf.estimator.ModeKeys.PREDICT:
predictions = {"probabilities": probabilities}
output_spec = tf.estimator.EstimatorSpec(
mode=mode, predictions=predictions)
elif mode == tf.estimator.ModeKeys.EVAL:
eval_metric_ops = metric_fn(per_example_loss, label_ids, logits)
output_spec = tf.estimator.EstimatorSpec(
mode=mode,
loss=total_loss,
eval_metric_ops=eval_metric_ops)
return output_spec
(total_loss, per_example_loss, logits, probabilities) = create_model(
bert_config, is_training, input_ids, input_mask, segment_ids, label_ids,
num_labels, use_one_hot_embeddings)
tvars = tf.trainable_variables()
initialized_variable_names = {}
if init_checkpoint and (hvd is None or hvd.rank() == 0):
(assignment_map, initialized_variable_names
) = modeling.get_assignment_map_from_checkpoint(tvars, init_checkpoint)
tf.train.init_from_checkpoint(init_checkpoint, assignment_map)
if FLAGS.verbose_logging:
tf.compat.v1.logging.info("**** Trainable Variables ****")
for var in tvars:
init_string = ""
if var.name in initialized_variable_names:
init_string = ", *INIT_FROM_CKPT*"
tf.compat.v1.logging.info(" name = %s, shape = %s%s", var.name, var.shape,
init_string)
output_spec = None
if mode == tf.estimator.ModeKeys.TRAIN:
train_op = optimization.create_optimizer(
total_loss, learning_rate, num_train_steps, num_warmup_steps,
hvd, False, FLAGS.amp, FLAGS.num_accumulation_steps, FLAGS.optimizer_type)
output_spec = tf.estimator.EstimatorSpec(
mode=mode,
loss=total_loss,
train_op=train_op)
elif mode == tf.estimator.ModeKeys.EVAL:
dummy_op = tf.no_op()
# Need to call mixed precision graph rewrite if fp16 to enable graph rewrite
if FLAGS.amp:
loss_scaler = tf.train.experimental.FixedLossScale(1)
dummy_op = tf.train.experimental.enable_mixed_precision_graph_rewrite(
optimization.LAMBOptimizer(learning_rate=0.0), loss_scaler)
eval_metric_ops = metric_fn(per_example_loss, label_ids, logits)
output_spec = tf.estimator.EstimatorSpec(
mode=mode,
loss=total_loss,
eval_metric_ops=eval_metric_ops)
else:
dummy_op = tf.no_op()
# Need to call mixed precision graph rewrite if fp16 to enable graph rewrite
if FLAGS.amp:
dummy_op = tf.train.experimental.enable_mixed_precision_graph_rewrite(
optimization.LAMBOptimizer(learning_rate=0.0))
output_spec = tf.estimator.EstimatorSpec(
mode=mode, predictions=probabilities)
return output_spec
return model_fn
# This function is not used by this file but is still used by the Colab and
# people who depend on it.
def input_fn_builder(features, batch_size, seq_length, is_training, drop_remainder, hvd=None):
"""Creates an `input_fn` closure to be passed to Estimator."""
all_input_ids = []
all_input_mask = []
all_segment_ids = []
all_label_ids = []
for feature in features:
all_input_ids.append(feature.input_ids)
all_input_mask.append(feature.input_mask)
all_segment_ids.append(feature.segment_ids)
all_label_ids.append(feature.label_id)
def input_fn():
"""The actual input function."""
num_examples = len(features)
# This is for demo purposes and does NOT scale to large data sets. We do
# not use Dataset.from_generator() because that uses tf.py_func which is
# not TPU compatible. The right way to load data is with TFRecordReader.
d = tf.data.Dataset.from_tensor_slices({
"input_ids":
tf.constant(
all_input_ids, shape=[num_examples, seq_length],
dtype=tf.int32),
"input_mask":
tf.constant(
all_input_mask,
shape=[num_examples, seq_length],
dtype=tf.int32),
"segment_ids":
tf.constant(
all_segment_ids,
shape=[num_examples, seq_length],
dtype=tf.int32),
"label_ids":
tf.constant(all_label_ids, shape=[num_examples], dtype=tf.int32),
})
if is_training:
if hvd is not None: d = d.shard(hvd.size(), hvd.rank())
d = d.repeat()
d = d.shuffle(buffer_size=100)
d = d.batch(batch_size=batch_size, drop_remainder=drop_remainder)
return d
return input_fn
def main(_):
setup_xla_flags()
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.INFO)
dllogging = utils.dllogger_class.dllogger_class(FLAGS.dllog_path)
if FLAGS.horovod:
hvd.init()
processors = {
"cola": ColaProcessor,
"mnli": MnliProcessor,
"mrpc": MrpcProcessor,
"xnli": XnliProcessor,
}
if not FLAGS.do_train and not FLAGS.do_eval and not FLAGS.do_predict:
raise ValueError(
"At least one of `do_train`, `do_eval` or `do_predict' must be True.")
bert_config = modeling.BertConfig.from_json_file(FLAGS.bert_config_file)
if FLAGS.max_seq_length > bert_config.max_position_embeddings:
raise ValueError(
"Cannot use sequence length %d because the BERT model "
"was only trained up to sequence length %d" %
(FLAGS.max_seq_length, bert_config.max_position_embeddings))
tf.io.gfile.makedirs(FLAGS.output_dir)
task_name = FLAGS.task_name.lower()
if task_name not in processors:
raise ValueError("Task not found: %s" % (task_name))
processor = processors[task_name]()
label_list = processor.get_labels()
tokenizer = tokenization.FullTokenizer(
vocab_file=FLAGS.vocab_file, do_lower_case=FLAGS.do_lower_case)
master_process = True
training_hooks = []
global_batch_size = FLAGS.train_batch_size * FLAGS.num_accumulation_steps
hvd_rank = 0
config = tf.compat.v1.ConfigProto()
if FLAGS.horovod:
tf.compat.v1.logging.info("Multi-GPU training with TF Horovod")
tf.compat.v1.logging.info("hvd.size() = %d hvd.rank() = %d", hvd.size(), hvd.rank())
global_batch_size = FLAGS.train_batch_size * FLAGS.num_accumulation_steps * hvd.size()
master_process = (hvd.rank() == 0)
hvd_rank = hvd.rank()
config.gpu_options.visible_device_list = str(hvd.local_rank())
set_affinity(hvd.local_rank())
if hvd.size() > 1:
training_hooks.append(hvd.BroadcastGlobalVariablesHook(0))
if FLAGS.use_xla:
config.graph_options.optimizer_options.global_jit_level = tf.compat.v1.OptimizerOptions.ON_1
if FLAGS.amp:
tf.enable_resource_variables()
run_config = tf.estimator.RunConfig(
model_dir=FLAGS.output_dir if master_process else None,
session_config=config,
save_checkpoints_steps=FLAGS.save_checkpoints_steps if master_process else None,
save_summary_steps=FLAGS.save_checkpoints_steps if master_process else None,
log_step_count_steps=FLAGS.display_loss_steps,
keep_checkpoint_max=1)
if master_process:
tf.compat.v1.logging.info("***** Configuaration *****")
for key in FLAGS.__flags.keys():
tf.compat.v1.logging.info(' {}: {}'.format(key, getattr(FLAGS, key)))
tf.compat.v1.logging.info("**************************")
train_examples = None
num_train_steps = None
num_warmup_steps = None
training_hooks.append(LogTrainRunHook(global_batch_size, hvd_rank, FLAGS.save_checkpoints_steps, num_steps_ignore_xla=25))
if FLAGS.do_train:
train_examples = processor.get_train_examples(FLAGS.data_dir)
num_train_steps = int(
len(train_examples) / global_batch_size * FLAGS.num_train_epochs)
num_warmup_steps = int(num_train_steps * FLAGS.warmup_proportion)
start_index = 0
end_index = len(train_examples)
tmp_filenames = [os.path.join(FLAGS.output_dir, "train.tf_record")]
if FLAGS.horovod:
tmp_filenames = [os.path.join(FLAGS.output_dir, "train.tf_record{}".format(i)) for i in range(hvd.size())]
num_examples_per_rank = len(train_examples) // hvd.size()
remainder = len(train_examples) % hvd.size()
if hvd.rank() < remainder:
start_index = hvd.rank() * (num_examples_per_rank+1)
end_index = start_index + num_examples_per_rank + 1
else:
start_index = hvd.rank() * num_examples_per_rank + remainder
end_index = start_index + (num_examples_per_rank)
model_fn = model_fn_builder(
task_name=task_name,
bert_config=bert_config,
num_labels=len(label_list),
init_checkpoint=FLAGS.init_checkpoint,
learning_rate=FLAGS.learning_rate if not FLAGS.horovod else FLAGS.learning_rate * hvd.size(),
num_train_steps=num_train_steps,
num_warmup_steps=num_warmup_steps,
use_one_hot_embeddings=False,
hvd=None if not FLAGS.horovod else hvd)
estimator = tf.estimator.Estimator(
model_fn=model_fn,
config=run_config)
if FLAGS.do_train:
file_based_convert_examples_to_features(
train_examples[start_index:end_index], label_list, FLAGS.max_seq_length, tokenizer, tmp_filenames[hvd_rank])
tf.compat.v1.logging.info("***** Running training *****")
tf.compat.v1.logging.info(" Num examples = %d", len(train_examples))
tf.compat.v1.logging.info(" Batch size = %d", FLAGS.train_batch_size)
tf.compat.v1.logging.info(" Num steps = %d", num_train_steps)
train_input_fn = file_based_input_fn_builder(
input_file=tmp_filenames,
batch_size=FLAGS.train_batch_size,
seq_length=FLAGS.max_seq_length,
is_training=True,
drop_remainder=True,
hvd=None if not FLAGS.horovod else hvd)
train_start_time = time.time()
estimator.train(input_fn=train_input_fn, max_steps=num_train_steps, hooks=training_hooks)
train_time_elapsed = time.time() - train_start_time
train_time_wo_overhead = training_hooks[-1].total_time
avg_sentences_per_second = num_train_steps * global_batch_size * 1.0 / train_time_elapsed
ss_sentences_per_second = (training_hooks[-1].count - training_hooks[-1].skipped) * global_batch_size * 1.0 / train_time_wo_overhead
if master_process:
tf.compat.v1.logging.info("-----------------------------")
tf.compat.v1.logging.info("Total Training Time = %0.2f for Sentences = %d", train_time_elapsed,
num_train_steps * global_batch_size)
tf.compat.v1.logging.info("Total Training Time W/O Overhead = %0.2f for Sentences = %d", train_time_wo_overhead,
(training_hooks[-1].count - training_hooks[-1].skipped) * global_batch_size)
tf.compat.v1.logging.info("Throughput Average (sentences/sec) with overhead = %0.2f", avg_sentences_per_second)
tf.compat.v1.logging.info("Throughput Average (sentences/sec) = %0.2f", ss_sentences_per_second)
tf.compat.v1.logging.info("-----------------------------")
if FLAGS.do_eval and master_process:
eval_examples = processor.get_dev_examples(FLAGS.data_dir)
eval_file = os.path.join(FLAGS.output_dir, "eval.tf_record")
file_based_convert_examples_to_features(
eval_examples, label_list, FLAGS.max_seq_length, tokenizer, eval_file)
tf.compat.v1.logging.info("***** Running evaluation *****")
tf.compat.v1.logging.info(" Num examples = %d", len(eval_examples))
tf.compat.v1.logging.info(" Batch size = %d", FLAGS.eval_batch_size)
eval_drop_remainder = False
eval_input_fn = file_based_input_fn_builder(
input_file=eval_file,
batch_size=FLAGS.eval_batch_size,
seq_length=FLAGS.max_seq_length,
is_training=False,
drop_remainder=eval_drop_remainder)
eval_hooks = [LogEvalRunHook(FLAGS.eval_batch_size)]
eval_start_time = time.time()
result = estimator.evaluate(input_fn=eval_input_fn, hooks=eval_hooks)
eval_time_elapsed = time.time() - eval_start_time
time_list = eval_hooks[-1].time_list
time_list.sort()
# Removing outliers (init/warmup) in throughput computation.
eval_time_wo_overhead = sum(time_list[:int(len(time_list) * 0.8)])
num_sentences = (int(len(time_list) * 0.8)) * FLAGS.eval_batch_size
avg = np.mean(time_list)
cf_50 = max(time_list[:int(len(time_list) * 0.50)])
cf_90 = max(time_list[:int(len(time_list) * 0.90)])
cf_95 = max(time_list[:int(len(time_list) * 0.95)])
cf_99 = max(time_list[:int(len(time_list) * 0.99)])
cf_100 = max(time_list[:int(len(time_list) * 1)])
ss_sentences_per_second = num_sentences * 1.0 / eval_time_wo_overhead
tf.compat.v1.logging.info("-----------------------------")
tf.compat.v1.logging.info("Total Inference Time = %0.2f for Sentences = %d", eval_time_elapsed,
eval_hooks[-1].count * FLAGS.eval_batch_size)
tf.compat.v1.logging.info("Total Inference Time W/O Overhead = %0.2f for Sentences = %d", eval_time_wo_overhead,
num_sentences)
tf.compat.v1.logging.info("Summary Inference Statistics on EVAL set")
tf.compat.v1.logging.info("Batch size = %d", FLAGS.eval_batch_size)
tf.compat.v1.logging.info("Sequence Length = %d", FLAGS.max_seq_length)
tf.compat.v1.logging.info("Precision = %s", "fp16" if FLAGS.amp else "fp32")
tf.compat.v1.logging.info("Latency Confidence Level 50 (ms) = %0.2f", cf_50 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 90 (ms) = %0.2f", cf_90 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 95 (ms) = %0.2f", cf_95 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 99 (ms) = %0.2f", cf_99 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 100 (ms) = %0.2f", cf_100 * 1000)
tf.compat.v1.logging.info("Latency Average (ms) = %0.2f", avg * 1000)
tf.compat.v1.logging.info("Throughput Average (sentences/sec) = %0.2f", ss_sentences_per_second)
dllogging.logger.log(step=(), data={"throughput_val": ss_sentences_per_second}, verbosity=Verbosity.DEFAULT)
tf.compat.v1.logging.info("-----------------------------")
output_eval_file = os.path.join(FLAGS.output_dir, "eval_results.txt")
with tf.io.gfile.GFile(output_eval_file, "w") as writer:
tf.compat.v1.logging.info("***** Eval results *****")
for key in sorted(result.keys()):
dllogging.logger.log(step=(), data={key: float(result[key])}, verbosity=Verbosity.DEFAULT)
tf.compat.v1.logging.info(" %s = %s", key, str(result[key]))
writer.write("%s = %s\n" % (key, str(result[key])))
if FLAGS.do_predict and master_process:
predict_examples = processor.get_test_examples(FLAGS.data_dir)
predict_file = os.path.join(FLAGS.output_dir, "predict.tf_record")
file_based_convert_examples_to_features(predict_examples, label_list,
FLAGS.max_seq_length, tokenizer,
predict_file)
tf.compat.v1.logging.info("***** Running prediction*****")
tf.compat.v1.logging.info(" Num examples = %d", len(predict_examples))
tf.compat.v1.logging.info(" Batch size = %d", FLAGS.predict_batch_size)
predict_drop_remainder = False
predict_input_fn = file_based_input_fn_builder(
input_file=predict_file,
batch_size=FLAGS.predict_batch_size,
seq_length=FLAGS.max_seq_length,
is_training=False,
drop_remainder=predict_drop_remainder)
predict_hooks = [LogEvalRunHook(FLAGS.predict_batch_size)]
predict_start_time = time.time()
output_predict_file = os.path.join(FLAGS.output_dir, "test_results.tsv")
with tf.io.gfile.GFile(output_predict_file, "w") as writer:
tf.compat.v1.logging.info("***** Predict results *****")
for prediction in estimator.predict(input_fn=predict_input_fn, hooks=predict_hooks,
yield_single_examples=False):
output_line = "\t".join(
str(class_probability) for class_probability in prediction) + "\n"
writer.write(output_line)
predict_time_elapsed = time.time() - predict_start_time
time_list = predict_hooks[-1].time_list
time_list.sort()
# Removing outliers (init/warmup) in throughput computation.
predict_time_wo_overhead = sum(time_list[:int(len(time_list) * 0.8)])
num_sentences = (int(len(time_list) * 0.8)) * FLAGS.predict_batch_size
avg = np.mean(time_list)
cf_50 = max(time_list[:int(len(time_list) * 0.50)])
cf_90 = max(time_list[:int(len(time_list) * 0.90)])
cf_95 = max(time_list[:int(len(time_list) * 0.95)])
cf_99 = max(time_list[:int(len(time_list) * 0.99)])
cf_100 = max(time_list[:int(len(time_list) * 1)])
ss_sentences_per_second = num_sentences * 1.0 / predict_time_wo_overhead
tf.compat.v1.logging.info("-----------------------------")
tf.compat.v1.logging.info("Total Inference Time = %0.2f for Sentences = %d", predict_time_elapsed,
predict_hooks[-1].count * FLAGS.predict_batch_size)
tf.compat.v1.logging.info("Total Inference Time W/O Overhead = %0.2f for Sentences = %d", predict_time_wo_overhead,
num_sentences)
tf.compat.v1.logging.info("Summary Inference Statistics on TEST SET")
tf.compat.v1.logging.info("Batch size = %d", FLAGS.predict_batch_size)
tf.compat.v1.logging.info("Sequence Length = %d", FLAGS.max_seq_length)
tf.compat.v1.logging.info("Precision = %s", "fp16" if FLAGS.amp else "fp32")
tf.compat.v1.logging.info("Latency Confidence Level 50 (ms) = %0.2f", cf_50 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 90 (ms) = %0.2f", cf_90 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 95 (ms) = %0.2f", cf_95 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 99 (ms) = %0.2f", cf_99 * 1000)
tf.compat.v1.logging.info("Latency Confidence Level 100 (ms) = %0.2f", cf_100 * 1000)
tf.compat.v1.logging.info("Latency Average (ms) = %0.2f", avg * 1000)
tf.compat.v1.logging.info("Throughput Average (sentences/sec) = %0.2f", ss_sentences_per_second)
dllogging.logger.log(step=(), data={"throughput_val": ss_sentences_per_second}, verbosity=Verbosity.DEFAULT)
tf.compat.v1.logging.info("-----------------------------")
if __name__ == "__main__":
flags.mark_flag_as_required("data_dir")
flags.mark_flag_as_required("task_name")
flags.mark_flag_as_required("vocab_file")
flags.mark_flag_as_required("bert_config_file")
flags.mark_flag_as_required("output_dir")
tf.compat.v1.app.run()
| 42.204515 | 136 | 0.685809 | 1 | 2.0136 | [
-0.002947216620668769,
0.016682403162121773,
-0.006420179735869169,
0.0197619516402483,
-0.03945139795541763,
-0.006731863133609295,
0.005278726574033499,
-0.01668604277074337,
-0.01906329020857811,
-0.0003540908801369369,
-0.01696663908660412,
0.0015876991674304008,
0.021306052803993225,
-0.005857231095433235,
-0.01751698926091194,
-0.03143807128071785,
0.0374271385371685,
0.007769100368022919,
-0.0155259370803833,
0.0013579941587522626,
-0.003944348078221083,
0.005016036797314882,
0.003343232674524188,
0.009133748710155487,
0.03931528702378273,
0.025294791907072067,
-0.028443848714232445,
0.010058308951556683,
-0.009480984881520271,
-0.010003183037042618,
-0.008857093751430511,
0.030817031860351562,
-0.02908991649746895,
-0.00632080202922225,
0.008003133349120617,
0.0021358984522521496,
0.021072911098599434,
-0.05274912342429161,
0.03624993562698364,
0.021035924553871155,
0.004721712786704302,
-0.012089400552213192,
0.009871994145214558,
-0.02473057247698307,
0.029232731088995934,
0.013065924867987633,
0.03396984189748764,
0.02517426386475563,
-0.010161558166146278,
0.018096670508384705,
-0.013278836384415627,
0.009010374546051025,
0.023129453882575035,
-0.010056243278086185,
0.0001751936797518283,
-0.03622300550341606,
-0.010251428000628948,
0.04472006484866142,
-0.015200208872556686,
-0.020070921629667282,
-0.026870209723711014,
-0.007291138172149658,
0.0019470518454909325,
0.00877856183797121,
0.018594685941934586,
0.01677650585770607,
-0.01819654181599617,
-0.005537829827517271,
-0.08338145911693573,
0.019381200894713402,
-0.009971764869987965,
-0.0038012813311070204,
0.009008840657770634,
0.018412549048662186,
0.026103680953383446,
0.022459955886006355,
-0.018196871504187584,
0.006121332757174969,
-0.04350269213318825,
0.03080235980451107,
-0.03654244542121887,
0.06707760691642761,
0.024636009708046913,
-0.01006567943841219,
0.008307844400405884,
0.030041422694921494,
0.04390375688672066,
0.007954377681016922,
0.014912298880517483,
0.0008234138949774206,
0.0022407302167266607,
0.026925506070256233,
-0.0363076813519001,
0.0032941559329628944,
-0.015019740909337997,
-0.026482878252863884,
-0.00022648392769042403,
0.02229534462094307,
0.0066448841243982315,
-0.0049882675521075726,
-0.0012407057220116258,
-0.008772398345172405,
-0.013575340621173382,
0.0006405993481166661,
0.0037686326541006565,
-0.043589379638433456,
-0.020428145304322243,
-0.019736604765057564,
-0.0010994202457368374,
0.0004046456015203148,
-0.08105304092168808,
0.005449909716844559,
0.02477351762354374,
-0.012892954051494598,
-0.005315706133842468,
0.005012598354369402,
-0.004618898034095764,
-0.021740207448601723,
0.005885475315153599,
0.07983545958995819,
0.007160461973398924,
-0.008666195906698704,
0.032202400267124176,
-0.023502694442868233,
-0.03643116354942322,
0.024848049506545067,
0.02640087902545929,
-0.013314451090991497,
0.009614769369363785,
-0.0046539329923689365,
-0.0029535270296037197,
0.006661823019385338,
0.01861935295164585,
0.01858585514128208,
-0.001751934178173542,
-0.025497952476143837,
0.02330676279962063,
-0.0016574615146964788,
-0.046610720455646515,
0.022704003378748894,
-0.0014837529743090272,
-0.027149436995387077,
-0.0031692523043602705,
-0.013426455669105053,
0.011830349452793598,
-0.0036838396918028593,
-0.029013585299253464,
0.004601906519383192,
-0.005930592771619558,
0.001658529625274241,
0.009375403635203838,
-0.029866328462958336,
0.030198993161320686,
-0.005354509688913822,
-0.012686769478023052,
0.024935929104685783,
-0.01547236181795597,
-0.037463173270225525,
0.000018494692994863726,
-0.004002398811280727,
0.00923185795545578,
0.03738461434841156,
-0.013385659083724022,
-0.013764576986432076,
0.017939481884241104,
-0.009399600327014923,
-0.01640995778143406,
0.0015196900349110365,
-0.010971708223223686,
0.008037742227315903,
0.008137517608702183,
0.008965613320469856,
0.027634600177407265,
0.010149653069674969,
-0.048760998994112015,
0.019551360979676247,
0.020091243088245392,
0.006606874521821737,
-0.015871917828917503,
0.0074380687437951565,
-0.028793003410100937,
-0.04039544239640236,
0.003053630469366908,
0.029347501695156097,
-0.0008731727139092982,
-0.01537370216101408,
-0.051913488656282425,
-0.022107809782028198,
0.023913364857435226,
-0.016798682510852814,
-0.007769854739308357,
-0.02855110354721546,
-0.03430360555648804,
0.011011211201548576,
0.014391563832759857,
-0.001661341404542327,
0.026942558586597443,
-0.014558070339262486,
-0.021849997341632843,
0.0033758075442165136,
-0.001701844041235745,
-0.012072691693902016,
-0.012155778706073761,
0.04965120181441307,
0.009352164342999458,
0.023838529363274574,
-0.794701099395752,
0.006253967992961407,
-0.016255952417850494,
-0.005293336696922779,
0.015360302291810513,
0.0191476009786129,
-0.02859865128993988,
-0.016606079414486885,
-0.00351641490124166,
0.02147498168051243,
-0.012025024741888046,
0.024036545306444168,
0.009014386683702469,
0.04298000782728195,
0.009221070446074009,
-0.007284111343324184,
0.0168662928044796,
0.012743162922561169,
0.0022229833994060755,
-0.012277087196707726,
-0.02155730314552784,
-0.026364684104919434,
-0.0036857575178146362,
0.029280556365847588,
0.030578099191188812,
-0.0009354971698485315,
0.03983500972390175,
-0.009278965182602406,
-0.0373770035803318,
-0.03578348457813263,
0.029544446617364883,
-0.036542557179927826,
0.008526021614670753,
0.0004835568543057889,
0.012605417519807816,
0.0348275825381279,
0.030560776591300964,
-0.018482094630599022,
-0.03127036616206169,
0.000717253249604255,
0.028393980115652084,
-0.028759978711605072,
-0.043836068361997604,
-0.04597095027565956,
-0.04526578634977341,
0.0215167123824358,
-0.05740724503993988,
-0.03278655186295509,
0.031074315309524536,
0.02069086581468582,
-0.02106412500143051,
0.025611240416765213,
0.04009734466671944,
-0.010944858193397522,
-0.02018396370112896,
-0.008235122077167034,
-0.022923115640878677,
-0.023126671090722084,
0.009142089635133743,
-0.0026796753518283367,
0.0037086580414325,
-0.011601106263697147,
-0.010187160223722458,
0.000907180190552026,
-0.02877628616988659,
-0.005040271673351526,
0.028024964034557343,
-0.011250379495322704,
-0.015755509957671165,
-0.005228093825280666,
-0.04147905483841896,
0.02154942974448204,
-0.03236543387174606,
0.041886959224939346,
0.02138429321348667,
-0.008447960019111633,
-0.04824383184313774,
0.000054670315876137465,
-0.04482145607471466,
0.003197016892954707,
-0.009242570027709007,
-0.003045526100322604,
0.004779820796102285,
0.0019507705001160502,
-0.022559262812137604,
-0.014846117235720158,
0.009198997169733047,
-0.000003821793598035583,
0.000583177839871496,
0.02565189264714718,
0.014790158718824387,
0.025353310629725456,
0.021010302007198334,
-0.014015301130712032,
0.007344167213886976,
0.05787253379821777,
0.0079622408375144,
0.07459329813718796,
-0.0006622273358516395,
-0.011907234787940979,
-0.02475075237452984,
0.02280563674867153,
-0.011406714096665382,
0.06748493760824203,
-0.0389830619096756,
-0.007753150071948767,
-0.015621649101376534,
-0.024920469149947166,
0.027586981654167175,
-0.02078813873231411,
0.021517086774110794,
-0.01540055125951767,
-0.01944810338318348,
0.0061058164574205875,
0.02863665297627449,
-0.014745538122951984,
-0.00012197225441923365,
-0.023427149280905724,
0.014398192055523396,
0.0060706608928740025,
-0.009203100576996803,
-0.007340595126152039,
-0.016201883554458618,
0.0034754048101603985,
-0.006769250612705946,
0.010623535141348839,
-0.05926310271024704,
-0.006008444353938103,
-0.008612951263785362,
0.00865182001143694,
0.03250398859381676,
-0.011858189478516579,
0.027104085311293602,
0.0052808355540037155,
-0.014647950418293476,
-0.0005563016748055816,
-0.02185957133769989,
-0.02849290706217289,
-0.010191692970693111,
-0.02734610065817833,
0.0027434127405285835,
-0.0034662499092519283,
-0.019101237878203392,
-0.048795200884342194,
-0.008181403391063213,
-0.01760217361152172,
0.020171618089079857,
-0.01759749837219715,
0.013107867911458015,
-0.02048240229487419,
0.004018752835690975,
0.027842888608574867,
0.007095827255398035,
0.01309061236679554,
0.0011331544956192374,
-0.0028833297546952963,
-0.020547697320580482,
0.005158503074198961,
0.016050856560468674,
-0.015231783501803875,
-0.018161823973059654,
-0.0061326464638113976,
-0.025560878217220306,
-0.0075115724466741085,
0.004073874093592167,
0.010428149253129959,
-0.03676612302660942,
0.035502802580595016,
-0.0033283252269029617,
-0.007804549764841795,
0.006855575833469629,
-0.006545009557157755,
0.012619083747267723,
0.030612770467996597,
-0.0011664193589240313,
0.012624467723071575,
-0.003894613590091467,
-0.048367489129304886,
0.022654026746749878,
0.0209156796336174,
-0.020584892481565475,
-0.015128636732697487,
-0.0041832393035292625,
-0.014750644564628601,
0.004207989666610956,
0.018250321969389915,
-0.016407418996095657,
0.04324573278427124,
0.029778437688946724,
-0.03253864124417305,
-0.03040018491446972,
-0.010256234556436539,
-0.019649168476462364,
-0.006332073826342821,
-0.010806878097355366,
-0.018157698214054108,
0.00657039787620306,
0.020114487037062645,
-0.020259317010641098,
0.00039920161361806095,
-0.025301171466708183,
0.048600934445858,
0.029947983101010323,
0.014345286414027214,
0.001785079832188785,
-0.015286985784769058,
-0.006698885466903448,
-0.004983612336218357,
-0.01390098500996828,
-0.0560523197054863,
0.0356733500957489,
-0.032234929502010345,
0.04188947752118111,
0.017248231917619705,
0.01585501804947853,
0.010779179632663727,
-0.02707982435822487,
-0.003147354582324624,
-0.023365836590528488,
-0.003796763950958848,
-0.013777755200862885,
-0.03982110694050789,
-0.0011273460695520043,
-0.0006547135999426246,
-0.01292197685688734,
0.011461326852440834,
-0.01609077677130699,
-0.00044652854558080435,
-0.030667785555124283,
-0.013674386776983738,
0.0006734537309966981,
0.021572185680270195,
0.0000510171776113566,
-0.002221267204731703,
-0.007047081366181374,
-0.0013052676804363728,
-0.01811458356678486,
-0.013630974106490612,
-0.004135798662900925,
-0.021958328783512115,
-0.002743442775681615,
-0.023858794942498207,
-0.00820176675915718,
0.04448252171278,
0.027085378766059875,
-0.021879080682992935,
0.010041875764727592,
-0.022615626454353333,
-0.03298976644873619,
-0.01339390967041254,
-0.032361891120672226,
0.03372485563158989,
0.02527235820889473,
-0.00426953099668026,
-0.005431755445897579,
0.021357335150241852,
-0.015157836489379406,
0.004300085362046957,
0.02071615308523178,
0.0028237293008714914,
0.006676009856164455,
0.007784679532051086,
-0.004072709009051323,
0.012845278717577457,
-0.03238736093044281,
-0.027606120333075523,
-0.017593465745449066,
-0.012570224702358246,
-0.0266860481351614,
0.01744825951755047,
0.027489975094795227,
0.006032903678715229,
0.030881507322192192,
0.00965341366827488,
-0.021039748564362526,
0.010482458397746086,
-0.004382702521979809,
-0.0034863236360251904,
0.01853114366531372,
0.006016080267727375,
-0.022647781297564507,
0.00196464778855443,
0.032828617841005325,
0.019725920632481575,
0.027606891468167305,
0.012541752308607101,
-0.0033154338598251343,
0.015593933872878551,
-0.02441314421594143,
0.0066497307270765305,
0.032240137457847595,
-0.02329964190721512,
0.02145458199083805,
0.0364915132522583,
-0.000011157369954162277,
-0.002817779313772917,
-0.002105697290971875,
0.019400151446461678,
0.043496813625097275,
-0.003613426350057125,
0.028109246864914894,
-0.01573892869055271,
-0.02223796769976616,
0.01589454524219036,
0.002240631962195039,
-0.00798793975263834,
0.0014299058821052313,
0.006566394120454788,
0.022421278059482574,
0.01627829670906067,
0.014402893371880054,
0.025285251438617706,
-0.00767239835113287,
-0.01310554426163435,
0.009795618243515491,
-0.003140144981443882,
0.03431234136223793,
0.02422845922410488,
0.0010861690388992429,
0.013903777115046978,
-0.012739299796521664,
0.033318255096673965,
-0.01420346274971962,
-0.026315981522202492,
-0.02671945095062256,
-0.013115769252181053,
-0.01955750584602356,
-0.002391660353168845,
0.01935301162302494,
0.03416495770215988,
-0.00037365860771387815,
-0.010042442008852959,
0.02992088906466961,
-0.021509967744350433,
-0.00425242492929101,
0.003189483191817999,
-0.017474453896284103,
0.009149950928986073,
0.026760734617710114,
-0.025876514613628387,
-0.013041227124631405,
0.00632834155112505,
-0.002820739522576332,
-0.0011630286462605,
0.03549858182668686,
0.0069208331406116486,
0.04356350749731064,
0.04303641989827156,
0.0012751099420711398,
0.043948132544755936,
-0.025978457182645798,
-0.015953168272972107,
-0.01302051916718483,
0.017180882394313812,
0.003964497707784176,
0.02369101718068123,
0.027303915470838547,
0.03957308828830719,
0.03746496140956879,
-0.0009048112551681697,
0.004486815072596073,
-0.016177715733647346,
-0.012858105823397636,
-0.020717324689030647,
0.0036480394192039967,
-0.022558921948075294,
0.019292378798127174,
-0.02008461393415928,
-0.03196841478347778,
0.021381745114922523,
-0.027067672461271286,
-0.006707887630909681,
0.021035348996520042,
-0.019439563155174255,
0.04332118481397629,
0.006049339193850756,
-0.0007679772679693997,
0.02604224905371666,
0.01150712464004755,
-0.029877372086048126,
-0.0223686546087265,
-0.005183756817132235,
0.0326554998755455,
0.0072210789658129215,
0.034696467220783234,
-0.014062256552278996,
0.008651274256408215,
-0.02472727932035923,
0.00947793573141098,
-0.010886071249842644,
-0.022108180448412895,
0.005129591096192598,
0.053488075733184814,
0.028479767963290215,
-0.025491831824183464,
0.007716290187090635,
0.00783053319901228,
-0.014505618251860142,
-0.0032703012693673372,
-0.012891310267150402,
-0.003970636986196041,
-0.03812453895807266,
-0.004200809635221958,
-0.01701710745692253,
-0.002936513861641288,
-0.02103862352669239,
0.02016737125813961,
-0.0018361331894993782,
0.01310652680695057,
-0.015975113958120346,
0.0028073983266949654,
0.032602351158857346,
-0.02591395378112793,
0.005833918694406748,
0.014209741726517677,
0.01837391033768654,
-0.009037052281200886,
-0.0007490336429327726,
0.005414361134171486,
0.026634221896529198,
-0.009634513407945633,
-0.005098007153719664,
-0.01849050261080265,
-0.009483246132731438,
-0.02605135552585125,
-0.008279792033135891,
0.03108838200569153,
-0.021958837285637856,
0.010626887902617455,
0.019223513081669807,
-0.015068164095282555,
-0.023388002067804337,
-0.012610560283064842,
0.03555518016219139,
0.03939332440495491,
0.0005378577625378966,
-0.009849680587649345,
0.024129653349518776,
-0.04740724340081215,
-0.02626756951212883,
0.0173915047198534,
-0.0033702002838253975,
0.009000335820019245,
-0.0006988528184592724,
0.022404545918107033,
0.03944845125079155,
0.005167416762560606,
-0.0003060519229620695,
-0.00005871858957107179,
0.012440276332199574,
-0.02755863405764103,
-0.028466498479247093,
0.016980933025479317,
-0.013491742312908173,
-0.009237602353096008,
0.010706905275583267,
0.02960469201207161,
0.05092287063598633,
0.018137605860829353,
0.0032280171290040016,
-0.001637224922887981,
-0.008537182584404945,
-0.003728426992893219,
-0.04300963506102562,
0.027671923860907555,
0.01397177018225193,
0.0014831370208412409,
0.004594906698912382,
0.00868225283920765,
-0.00520575325936079,
-0.009738950990140438,
-0.0019096897449344397,
-0.019316302612423897,
0.0031046830117702484,
-0.011974194087088108,
0.009103687480092049,
0.019593769684433937,
0.030452193692326546,
0.007374058477580547,
0.023315822705626488,
-0.005721745081245899,
0.01600096933543682,
0.00420096330344677,
0.01675371825695038,
-0.0020929970778524876,
0.0268506221473217,
0.00584767060354352,
-0.006001331843435764,
-0.0029982211999595165,
0.006821555085480213,
-0.03409402072429657,
-0.013654536567628384,
-0.02695239707827568,
0.019336767494678497,
-0.004208935424685478,
-0.006360240280628204,
0.01712380163371563,
-0.0255555659532547,
0.0324002280831337,
0.002006499795243144,
0.007558232638984919,
-0.017116013914346695,
-0.01054498739540577,
0.004034169018268585,
0.03261436149477959,
0.005372947547584772,
0.031025124713778496,
0.037749677896499634,
-0.013263228349387646,
0.04194152355194092,
0.00415785564109683,
-0.019694896414875984,
-0.018723133951425552,
-0.021061096340417862,
-0.01157693937420845,
0.03333129361271858,
-0.017920227721333504,
-0.048660241067409515,
0.009521400555968285,
0.027848005294799805,
0.023008935153484344,
0.0375225730240345,
0.00869584921747446,
-0.019645359367132187,
-0.013077052310109138,
0.002839996013790369,
-0.0017194830579683185,
-0.02018784172832966,
-0.024027664214372635,
0.027442770078778267,
-0.014690150506794453,
0.011622818186879158,
-0.029926884919404984,
-0.028823228552937508,
0.009702090173959732,
-0.0011727464152500033,
0.002084781415760517,
0.03865485265851021,
-0.0137198930606246,
-0.016498319804668427,
0.016013288870453835,
-0.008577177301049232,
-0.004956879653036594,
0.016433343291282654,
-0.026288196444511414,
0.014981904998421669,
-0.005737653002142906,
-0.024851584807038307,
0.005361054092645645,
-0.013435223139822483,
-0.0020217006094753742,
-0.0180569626390934,
-0.006052653305232525,
0.0012821165146306157,
-0.03116791322827339,
0.004707601852715015,
0.03012113645672798,
-0.004122462589293718,
0.008659460581839085,
-0.03229484334588051,
-0.01561526395380497,
-0.03061734139919281
] |
8a2c56df110778d23c3bb4671a208f95d1915011 | 69,038 | py | Python | FusionIIIT/applications/academic_information/views.py | 29rj/Fusion | bc2941a67532e183adeb0bc4042df0b182b9e3aa | [
"bzip2-1.0.6"
] | 29 | 2019-02-20T15:35:33.000Z | 2022-03-22T11:10:57.000Z | FusionIIIT/applications/academic_information/views.py | 29rj/Fusion | bc2941a67532e183adeb0bc4042df0b182b9e3aa | [
"bzip2-1.0.6"
] | 409 | 2019-01-17T19:30:51.000Z | 2022-03-31T16:28:45.000Z | FusionIIIT/applications/academic_information/views.py | 29rj/Fusion | bc2941a67532e183adeb0bc4042df0b182b9e3aa | [
"bzip2-1.0.6"
] | 456 | 2019-01-12T11:01:13.000Z | 2022-03-30T17:06:52.000Z | import datetime
import json
import os
import xlrd
import logging
from io import BytesIO
from xlsxwriter.workbook import Workbook
from xhtml2pdf import pisa
from itertools import chain
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404, render
from django.template.loader import get_template
from django.views.decorators.csrf import csrf_exempt
from django.template.loader import render_to_string
from django.contrib.auth.decorators import login_required
from applications.academic_procedures.models import MinimumCredits, Register, InitialRegistration, course_registration, AssistantshipClaim,Assistantship_status
from applications.globals.models import (Designation, ExtraInfo,
HoldsDesignation, DepartmentInfo)
from .forms import AcademicTimetableForm, ExamTimetableForm, MinuteForm
from .models import (Calendar, Course, Exam_timetable, Grades, Curriculum_Instructor,Constants,
Meeting, Student, Student_attendance, Timetable,Curriculum)
from applications.programme_curriculum.models import (CourseSlot, Course as Courses, Batch, Semester, Programme, Discipline)
from applications.academic_procedures.views import acad_proced_global_context
from applications.programme_curriculum.models import Batch
@login_required
def user_check(request):
"""
This function is used to check the type of user.
It checkes the authentication of the user.
@param:
request - contains metadata about the requested page
@variables:
current_user - get user from request
user_details - extract details of user from database
desig_id - check for designation
acadadmin - designation for Acadadmin
final_user - final designation of request user
"""
try:
current_user = get_object_or_404(User, username=request.user.username)
user_details = ExtraInfo.objects.all().select_related('user','department').filter(user=current_user).first()
desig_id = Designation.objects.all().filter(name='Upper Division Clerk')
temp = HoldsDesignation.objects.all().select_related().filter(designation = desig_id).first()
acadadmin = temp.working
k = str(user_details).split()
final_user = k[2]
except Exception as e:
acadadmin=""
final_user=""
pass
if (str(acadadmin) != str(final_user)):
return True
else:
return False
def get_context(request):
"""
This function gets basic gata from database to send to template
@param:
request - contains metadata about the requested page
@variables:
acadTtForm - the form to add academic calender
examTtForm - the form required to add exam timetable
exam_t - all the exam timetable objects
timetable - all the academic timetable objects
calendar - all the academic calender objects
context - the datas to be displayed in the webpage
this_sem_course - tha data of thsi semester courses
next_sem_courses - the data of next semester courses
courses - all the courses in curriculum
course_type - list the type of courses
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
course_list = sem_for_generate_sheet()
if(course_list[0]==1):
course_list_2 = [2, 4, 6, 8]
else:
course_list_2 = [1, 3, 5, 7]
# examTtForm = ExamTimetableForm()
# acadTtForm = AcademicTimetableForm()
# calendar = Calendar.objects.all()
# this_sem_courses = Curriculum.objects.all().filter(sem__in=course_list).filter(floated=True)
# next_sem_courses = Curriculum.objects.all().filter(sem__in=course_list).filter(floated=True)
# courses = Course.objects.all()
# course_type = Constants.COURSE_TYPE
# timetable = Timetable.objects.all()
# exam_t = Exam_timetable.objects.all()
procedures_context = acad_proced_global_context()
try:
examTtForm = ExamTimetableForm()
acadTtForm = AcademicTimetableForm()
calendar = Calendar.objects.all()
this_sem_courses = Curriculum.objects.all().select_related().filter(sem__in=course_list).filter(floated=True)
next_sem_courses = Curriculum.objects.all().select_related().filter(sem__in=course_list_2).filter(floated=True)
courses = Course.objects.all()
courses_list = Courses.objects.all()
course_type = Constants.COURSE_TYPE
timetable = Timetable.objects.all()
exam_t = Exam_timetable.objects.all()
pgstudent = Student.objects.filter(programme = "M.Tech") | Student.objects.filter(programme = "PhD")
assistant_list = AssistantshipClaim.objects.filter(ta_supervisor_remark = True).filter(thesis_supervisor_remark = True).filter(hod_approval =True).filter(acad_approval = False)
assistant_approve_list = AssistantshipClaim.objects.filter(ta_supervisor_remark = True).filter(thesis_supervisor_remark = True).filter(hod_approval =True).filter(hod_approval = True)
assistant_list_length = len(assistant_list.filter(acad_approval = False))
assis_stat = Assistantship_status.objects.all()
for obj in assis_stat:
assistant_flag = obj.student_status
hod_flag = obj.hod_status
account_flag = obj.account_status
except Exception as e:
examTtForm = ""
acadTtForm = ""
calendar = ""
this_sem_courses = ""
next_sem_courses = ""
courses = ""
course_type = ""
timetable = ""
exam_t = ""
pass
context = {
'acadTtForm': acadTtForm,
'examTtForm': examTtForm,
'courses': courses,
'courses_list': courses_list,
'course_type': course_type,
'exam': exam_t,
'timetable': timetable,
'academic_calendar': calendar,
'next_sem_course': next_sem_courses,
'this_sem_course': this_sem_courses,
'curriculum': curriculum,
'pgstudent' : pgstudent,
'assistant_list' : assistant_list,
'assistant_approve_list' : assistant_approve_list,
'assistant_list_length' : assistant_list_length,
'tab_id': ['1','1'],
'context': procedures_context['context'],
'lists': procedures_context['lists'],
'date': procedures_context['date'],
'query_option1': procedures_context['query_option1'],
'query_option2': procedures_context['query_option2'],
'course_verification_date' : procedures_context['course_verification_date'],
'submitted_course_list' : procedures_context['submitted_course_list'],
'result_year' : procedures_context['result_year'],
'batch_grade_data' : procedures_context['batch_grade_data'],
'batch_branch_data' : procedures_context['batch_branch_data'],
'assistant_flag' : assistant_flag,
'hod_flag' : hod_flag,
'account_flag' : account_flag
}
return context
@login_required
def homepage(request):
"""
This function is used to set up the homepage of the application.
It checkes the authentication of the user and also fetches the available
data from the databases to display it on the page.
@param:
request - contains metadata about the requested page
@variables:
senates - the extraInfo objects that holds the designation as a senator
students - all the objects in the Student class
Convenor - the extraInfo objects that holds the designation as a convenor
CoConvenor - the extraInfo objects that holds the designation as a coconvenor
meetings - the all meeting objects held in senator meetings
minuteForm - the form to add a senate meeting minutes
acadTtForm - the form to add academic calender
examTtForm - the form required to add exam timetable
Dean - the extraInfo objects that holds the designation as a dean
student - the students as a senator
extra - all the extraInfor objects
exam_t - all the exam timetable objects
timetable - all the academic timetable objects
calendar - all the academic calender objects
department - all the departments in the college
attendance - all the attendance objects of the students
context - the datas to be displayed in the webpage
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context = get_context(request)
return render(request, "ais/ais.html", context)
# ####################################
# # curriculum #
# ####################################
@login_required
def curriculum(request):
"""
This function is used to see curriculum and edit entries in a curriculum.
It checkes the authentication of the user and also fetches the available
data from the databases to display it on the page.
@param:
request - contains metadata about the requested page
@variables:
request_batch - Batch from form
request_branch - Branch from form
request_programme - Programme from form
request_sem - Semester from form
curriculum - Get data about curriculum from database
courses - get courses from database
courses_type - get course types from database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context = get_context(request)
context['tab_id'][0]='6'
if request.method == 'POST':
try:
request_batch = request.POST['batch']
request_branch = request.POST['branch']
request_programme = request.POST['programme']
request_sem = request.POST['sem']
except Exception as e:
request_batch = ""
request_branch = ""
request_programme = ""
request_sem = ""
#for checking if the user has searched for any particular curriculum
if request_batch == "" and request_branch == "" and request_programme=="" and request_sem=="":
curriculum = None #Curriculum.objects.all()
else:
if int(request_sem) == 0:
curriculum = Curriculum.objects.select_related().filter(branch = request_branch).filter(batch = request_batch).filter(programme= request_programme).order_by('sem')
else:
curriculum = Curriculum.objects.select_related().filter(branch = request_branch).filter(batch = request_batch).filter(programme= request_programme).filter(sem= request_sem)
# context={
# 'courses' : courses,
# 'course_type' : course_type,
# 'curriculum' : curriculum,
# 'tab_id' :['3','1']
# }
courses = Course.objects.all()
course_type = Constants.COURSE_TYPE
html = render_to_string('ais/curr_list.html',{'curriculum':curriculum,'courses':courses,'course_type':course_type},request)
obj = json.dumps({'html':html})
#return render(request, "ais/ais.html", context)
return HttpResponse(obj,content_type='application/json')
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
@login_required
def add_curriculum(request):
"""
This function is used to add new curriculum in database
It checkes the authentication of the user and also fetches the available
data from the databases to display it on the page.
@param:
request - contains metadata about the requested page
@variables:
programme - programme from form.REQUEST
batch - batch from form.REQUEST
branch - branch from form.REQUEST
sem - semester from form.REQUEST
course_code - course_code from form.REQUEST
course_name - course-name from form.REQUEST
course_id - course_id from database
credits - credits from form.REQUEST
optional - optional from form.REQUEST
course_type - course_type from form.REQUEST
ins - data is stored in database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context={
'tab_id' :['3','2']
}
if request.method == 'POST':
i=0
new_curr=[]
while True:
if "semester_"+str(i) in request.POST:
try:
programme=request.POST['AddProgramme']
batch=request.POST['AddBatch']
branch=request.POST['AddBranch']
sem=request.POST["semester_"+str(i)]
course_code=request.POST["course_code_"+str(i)]
course_name=request.POST["course_name_"+str(i)]
course_id=Course.objects.get(course_name=course_name)
credits=request.POST["credits_"+str(i)]
if "optional_"+str(i) in request.POST:
optional=True
else:
optional=False
course_type=request.POST["course_type_"+str(i)]
except Exception as e:
programme=""
batch=""
branch=""
sem=""
course_code=""
course_name=""
course_id=""
credits=""
optional=""
course_type=""
pass
ins=Curriculum(
programme=programme,
batch=batch,
branch=branch,
sem=sem,
course_code=course_code,
course_id=course_id,
credits=credits,
optional=optional,
course_type=course_type,
)
new_curr.append(ins)
else:
break
i+=1
Curriculum.objects.bulk_create(new_curr)
curriculum = Curriculum.objects.select_related().filter(branch = branch).filter(batch = batch).filter(programme= programme)
courses = Course.objects.all()
course_type = Constants.COURSE_TYPE
context= {
'courses': courses,
'course_type': course_type,
'curriculum': curriculum,
'tab_id' :['3','2']
}
return render(request, "ais/ais.html", context)
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
@login_required
def edit_curriculum(request):
"""
This function is used to edit curriculum in database
It checkes the authentication of the user and also fetches the available
data from the databases to display it on the page.
@param:
request - contains metadata about the requested page
@variables:
programme - programme from form.REQUEST
batch - batch from form.REQUEST
branch - branch from form.REQUEST
sem - semester from form.REQUEST
course_code - course_code from form.REQUEST
course_name - course-name from form.REQUEST
course_id - course_id from database
credits - credits from form.REQUEST
optional - optional from form.REQUEST
course_type - course_type from form.REQUEST
ins - data is stored in database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context={
'tab_id' :['3','1']
}
if request.method == 'POST':
try:
id=request.POST['id']
programme=request.POST['programme']
batch=request.POST['batch']
branch=request.POST['branch']
sem=request.POST["sem"]
course_code=request.POST["course_code"]
course_name=request.POST["course_id"]
course_id=Course.objects.get(course_name=course_name)
credits=request.POST["credits"]
if request.POST['optional'] == "on":
optional=True
else:
optional=False
course_type=request.POST["course_type"]
except Exception as e:
id=""
programme=""
batch=""
branch=""
sem=""
course_code=""
course_name=""
course_id=""
credits=""
optional=""
course_type=""
pass
entry=Curriculum.objects.all().select_related().filter(curriculum_id=id).first()
entry.programme=programme
entry.batch=batch
entry.branch=branch
entry.sem=sem
entry.course_code=course_code
entry.course_id=course_id
entry.credits=credits
entry.optional=optional
entry.course_type=course_type
entry.save()
curriculum = Curriculum.objects.select_related().filter(branch = branch).filter(batch = batch).filter(programme= programme)
courses = Course.objects.all()
course_type = Constants.COURSE_TYPE
context= {
'courses': courses,
'course_type': course_type,
'curriculum': curriculum,
'tab_id' :['3','1']
}
return render(request, "ais/ais.html", context)
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
@login_required
def delete_curriculum(request):
"""
This function is used to delete curriculum entry in database
It checkes the authentication of the user and also fetches the available
data from the databases to display it on the page.
@param:
request - contains metadata about the requested page
@variables:
dele - data being deleted from database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context={
'tab_id' :['3','1']
}
if request.method == "POST":
dele = Curriculum.objects.select_related().filter(curriculum_id=request.POST['id'])
dele.delete()
curriculum = Curriculum.objects.select_related().filter(branch = request.POST['branch']).filter(batch = request.POST['batch']).filter(programme= request.POST['programme'])
courses = Course.objects.all()
course_type = Constants.COURSE_TYPE
context= {
'courses': courses,
'course_type': course_type,
'curriculum': curriculum,
'tab_id' :['3','1']
}
return render(request, "ais/ais.html", context)
return render(request, 'ais/ais.html', context)
@login_required
def next_curriculum(request):
"""
This function is used to decide curriculum for new batch.
It checkes the authentication of the user and also fetches the available
data from the databases to display it on the page.
@param:
request - contains metadata about the requested page
@variables:
programme - programme from form.REQUEST
now - current date from system
year - current year
batch - batch form form
curriculum - curriculum details form database
ins - Inster data in database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
if request.method == 'POST':
programme = request.POST['programme']
now = datetime.datetime.now()
year = int(now.year)
batch = year-1
curriculum = Curriculum.objects.all().select_related().filter(batch = batch).filter(programme = programme)
if request.POST['option'] == '1':
new_curriculum=[]
for i in curriculum:
ins=Curriculum(
programme=i.programme,
batch=i.batch+1,
branch=i.branch,
sem=i.sem,
course_code=i.course_code,
course_id=i.course_id,
credits=i.credits,
optional=i.optional,
course_type=i.course_type,
)
new_curriculum.append(ins)
Curriculum.objects.bulk_create(new_curriculum)
elif request.POST['option'] == '2':
new_curriculum=[]
for i in curriculum:
ins=Curriculum(
programme=i.programme,
batch=i.batch+1,
branch=i.branch,
sem=i.sem,
course_code=i.course_code,
course_id=i.course_id,
credits=i.credits,
optional=i.optional,
course_type=i.course_type,
)
new_curriculum.append(ins)
Curriculum.objects.bulk_create(new_curriculum)
batch=batch+1
curriculum = Curriculum.objects.all().select_related().filter(batch = batch).filter(programme = programme)
context= {
'curriculumm' :curriculum,
'tab_id' :['3','3']
}
return render(request, "ais/ais.html", context)
else:
context= {
'tab_id' :['3','2']
}
return render(request, "ais/ais.html", context)
context= {
'tab_id' :['3','1']
}
return render(request, "ais/ais.html", context)
@login_required
def add_timetable(request):
"""
acad-admin can upload the time table(any type of) of the semester.
@param:
request - contains metadata about the requested page.
@variables:
acadTtForm - data of delete dictionary in post request
timetable - all timetable from database
exam_t - all exam timetable from database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
timetable = Timetable.objects.all()
exam_t = Exam_timetable.objects.all()
context= {
'exam': exam_t,
'timetable': timetable,
'tab_id' :['10','1']
}
acadTtForm = AcademicTimetableForm()
if request.method == 'POST' and request.FILES:
acadTtForm = AcademicTimetableForm(request.POST, request.FILES)
if acadTtForm.is_valid():
acadTtForm.save()
return render(request, "ais/ais.html", context)
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
@login_required
def add_exam_timetable(request):
"""
acad-admin can upload the exam timtable of the ongoing semester.
@param:
request - contains metadata about the requested page.
@variables:
examTtForm - data of delete dictionary in post request
timetable - all timetable from database
exam_t - all exam timetable from database
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
timetable = Timetable.objects.all()
exam_t = Exam_timetable.objects.all()
context= {
'exam': exam_t,
'timetable': timetable,
'tab_id' :['10','2']
}
examTtForm = ExamTimetableForm()
if request.method == 'POST' and request.FILES:
examTtForm = ExamTimetableForm(request.POST, request.FILES)
if examTtForm.is_valid():
examTtForm.save()
return render(request, "ais/ais.html", context)
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
@login_required
def delete_timetable(request):
"""
acad-admin can delete the outdated timetable from the server.
@param:
request - contains metadata about the requested page.
@variables:
data - data of delete dictionary in post request
t - Object of time table to be deleted
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
if request.method == "POST":
data = request.POST['delete']
t = Timetable.objects.get(time_table=data)
t.delete()
return HttpResponse("TimeTable Deleted")
@login_required
def delete_exam_timetable(request):
"""
acad-admin can delete the outdated exam timetable.
@param:
request - contains metadata about the requested page.
@variables:
data - data of delete dictionary in post request
t - Object of Exam time table to be deleted
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
if request.method == "POST":
data = request.POST['delete']
t = Exam_timetable.objects.get(exam_time_table=data)
t.delete()
return HttpResponse("TimeTable Deleted")
@login_required
def add_calendar(request):
"""
to add an entry to the academic calendar to be uploaded
@param:
request - contains metadata about the requested page.
@variables:
from_date - The starting date for the academic calendar event.
to_date - The ending date for the academic caldendar event.
desc - Description for the academic calendar event.
c = object to save new event to the academic calendar.
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
calendar = Calendar.objects.all()
context= {
'academic_calendar' :calendar,
'tab_id' :['4','1']
}
if request.method == "POST":
try:
from_date = request.POST.getlist('from_date')
to_date = request.POST.getlist('to_date')
desc = request.POST.getlist('description')[0]
from_date = from_date[0].split('-')
from_date = [int(i) for i in from_date]
from_date = datetime.datetime(*from_date).date()
to_date = to_date[0].split('-')
to_date = [int(i) for i in to_date]
to_date = datetime.datetime(*to_date).date()
except Exception as e:
from_date=""
to_date=""
desc=""
pass
c = Calendar(
from_date=from_date,
to_date=to_date,
description=desc)
c.save()
HttpResponse("Calendar Added")
return render(request, "ais/ais.html", context)
@login_required
def update_calendar(request):
"""
to update an entry to the academic calendar to be updated.
@param:
request - contains metadata about the requested page.
@variables:
from_date - The starting date for the academic calendar event.
to_date - The ending date for the academic caldendar event.
desc - Description for the academic calendar event.
prev_desc - Description for the previous event which is to be updated.
get_calendar_details = Get the object of the calendar instance from the database for the previous Description.
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
calendar = Calendar.objects.all()
context= {
'academic_calendar' :calendar,
'tab_id' :['4','1']
}
if request.method == "POST":
try:
from_date = request.POST.getlist('from_date')
to_date = request.POST.getlist('to_date')
desc = request.POST.getlist('description')[0]
prev_desc = request.POST.getlist('prev_desc')[0]
from_date = from_date[0].split('-')
from_date = [int(i) for i in from_date]
from_date = datetime.datetime(*from_date).date()
to_date = to_date[0].split('-')
to_date = [int(i) for i in to_date]
to_date = datetime.datetime(*to_date).date()
get_calendar_details = Calendar.objects.all().filter(description=prev_desc).first()
get_calendar_details.description = desc
get_calendar_details.from_date = from_date
get_calendar_details.to_date = to_date
get_calendar_details.save()
except Exception as e:
from_date=""
to_date=""
desc=""
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
#Generate Attendance Sheet
def sem_for_generate_sheet():
"""
This function generates semester grade sheet
@variables:
now - current datetime
month - current month
"""
now = datetime.datetime.now()
month = int(now.month)
if month >= 7 and month <= 12:
return [1, 3, 5, 7]
else:
return [2, 4, 6, 8]
@login_required
def generatexlsheet(request):
"""
to generate Course List of Registered Students
@param:
request - contains metadata about the requested page
@variables:
batch - gets the batch
course - gets the course
curr_key - gets the curriculum from database
obj - get stdents data from database
ans - Formatted Array to be converted to xlsx
k -temporary array to add data to formatted array/variable
output - io Bytes object to write to xlsx file
book - workbook of xlsx file
title - formatting variable of title the workbook
subtitle - formatting variable of subtitle the workbook
normaltext - formatting variable for normal text
sheet - xlsx sheet to be rendered
titletext - formatting variable of title text
dep - temporary variables
z - temporary variables for final output
b - temporary variables for final output
c - temporary variables for final output
st - temporary variables for final output
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
try:
batch = request.POST['batch']
course = Courses.objects.get(id = request.POST['course'])
obj = course_registration.objects.all().filter(course_id = course)
except Exception as e:
batch=""
course=""
curr_key=""
obj=""
registered_courses = []
for i in obj:
if i.student_id.batch_id.year == int(batch):
registered_courses.append(i)
ans = []
for i in registered_courses:
k = []
k.append(i.student_id.id.id)
k.append(i.student_id.id.user.first_name)
k.append(i.student_id.id.user.last_name)
k.append(i.student_id.id.department)
ans.append(k)
ans.sort()
output = BytesIO()
book = Workbook(output,{'in_memory':True})
title = book.add_format({'bold': True,
'font_size': 22,
'align': 'center',
'valign': 'vcenter'})
subtitle = book.add_format({'bold': True,
'font_size': 15,
'align': 'center',
'valign': 'vcenter'})
normaltext = book.add_format({'bold': False,
'font_size': 15,
'align': 'center',
'valign': 'vcenter'})
sheet = book.add_worksheet()
title_text = ((str(course.name)+" : "+str(str(batch))))
sheet.set_default_row(25)
sheet.merge_range('A2:E2', title_text, title)
sheet.write_string('A3',"Sl. No",subtitle)
sheet.write_string('B3',"Roll No",subtitle)
sheet.write_string('C3',"Name",subtitle)
sheet.write_string('D3',"Discipline",subtitle)
sheet.write_string('E3','Signature',subtitle)
sheet.set_column('A:A',20)
sheet.set_column('B:B',20)
sheet.set_column('C:C',60)
sheet.set_column('D:D',15)
sheet.set_column('E:E',30)
k = 4
num = 1
for i in ans:
sheet.write_number('A'+str(k),num,normaltext)
num+=1
z,b,c = str(i[0]),i[1],i[2]
name = str(b)+" "+str(c)
temp = str(i[3]).split()
dep = str(temp[len(temp)-1])
sheet.write_string('B'+str(k),z,normaltext)
sheet.write_string('C'+str(k),name,normaltext)
sheet.write_string('D'+str(k),dep,normaltext)
k+=1
book.close()
output.seek(0)
response = HttpResponse(output.read(),content_type = 'application/vnd.ms-excel')
st = 'attachment; filename = ' + course.code + '.xlsx'
response['Content-Disposition'] = st
return response
@login_required
def generate_preregistration_report(request):
"""
to generate preresgistration report after pre-registration
@param:
request - contains metadata about the requested page
@variables:
sem - get current semester from current time
now - get current time
year - getcurrent year
batch - gets the batch from form
sem - stores the next semester
obj - All the registration details appended into one
data - Formated data for context
m - counter for Sl. No (in formated data)
z - temporary array to add data to variable data
k -temporary array to add data to formatted array/variable
output - io Bytes object to write to xlsx file
book - workbook of xlsx file
title - formatting variable of title the workbook
subtitle - formatting variable of subtitle the workbook
normaltext - formatting variable for normal text
sheet - xlsx sheet to be rendered
titletext - formatting variable of title text
dep - temporary variables
z - temporary variables for final output
b - temporary variables for final output
c - temporary variables for final output
st - temporary variables for final output
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
if request.method == "POST":
sem = request.POST.get('semester_no')
batch_id=request.POST.get('batch_branch')
batch = Batch.objects.filter(id = batch_id).first()
obj = InitialRegistration.objects.filter(student_id__batch_id=batch_id, semester_id__semester_no=sem)
registered_students = set()
unregistered_students = set()
for stu in obj:
registered_students.add(stu.student_id)
students = Student.objects.filter(batch_id = batch_id)
for stu in students:
if stu not in registered_students:
unregistered_students.add(stu)
data = []
m = 1
for i in unregistered_students:
z = []
z.append(m)
m += 1
z.append(i.id.user.username)
z.append(str(i.id.user.first_name)+" "+str(i.id.user.last_name))
z.append(i.id.department.name)
z.append('not registered')
data.append(z)
for i in registered_students:
z = []
z.append(m)
m += 1
z.append(i.id.user.username)
z.append(str(i.id.user.first_name)+" "+str(i.id.user.last_name))
z.append(i.id.department.name)
z.append('registered')
data.append(z)
output = BytesIO()
book = Workbook(output,{'in_memory':True})
title = book.add_format({'bold': True,
'font_size': 22,
'align': 'center',
'valign': 'vcenter'})
subtitle = book.add_format({'bold': True,
'font_size': 15,
'align': 'center',
'valign': 'vcenter'})
normaltext = book.add_format({'bold': False,
'font_size': 15,
'align': 'center',
'valign': 'vcenter'})
sheet = book.add_worksheet()
title_text = ("Pre-registeration : "+ batch.name + str(" ") + batch.discipline.acronym + str(" ") + str(batch.year))
sheet.set_default_row(25)
sheet.merge_range('A2:E2', title_text, title)
sheet.write_string('A3',"Sl. No",subtitle)
sheet.write_string('B3',"Roll No",subtitle)
sheet.write_string('C3',"Name",subtitle)
sheet.write_string('D3',"Discipline",subtitle)
sheet.write_string('E3','Status',subtitle)
sheet.set_column('A:A',20)
sheet.set_column('B:B',20)
sheet.set_column('C:C',50)
sheet.set_column('D:D',15)
sheet.set_column('E:E',15)
k = 4
num = 1
for i in data:
sheet.write_number('A'+str(k),num,normaltext)
num+=1
z,b,c = str(i[0]),i[1],i[2]
a,b,c,d,e = str(i[0]),str(i[1]),str(i[2]),str(i[3]),str(i[4])
temp = str(i[3]).split()
sheet.write_string('B'+str(k),b,normaltext)
sheet.write_string('C'+str(k),c,normaltext)
sheet.write_string('D'+str(k),d,normaltext)
sheet.write_string('E'+str(k),e,normaltext)
k+=1
book.close()
output.seek(0)
response = HttpResponse(output.read(),content_type = 'application/vnd.ms-excel')
st = 'attachment; filename = ' + batch.name + batch.discipline.acronym + str(batch.year) + '-preresgistration.xlsx'
response['Content-Disposition'] = st
return response
@login_required
def add_new_profile (request):
"""
To add details of new upcoming students in the database.User must be logged in and must be acadadmin
@param:
request - contains metadata about the requested page.
@variables:
profiles - gets the excel file having data
excel - excel file
sheet - sheet no in excel file
roll_no - details of student from file
first_name - details of student from file
last_name - details of student from file
email - details of student from file
sex - details of student from file
title - details of student from file
dob - details of student from file
fathers_name - details of student from file
mothers_name - details of student from file
category - details of student from file
phone_no - details of student from file
address - details of student from file
department - details of student from file
specialization - details of student from file
hall_no - details of student from file
programme - details of student from file
batch - details of student from file
user - new user created in database
einfo - new extrainfo object created in database
stud_data - new student object created in database
desig - get designation object of student
holds_desig - get hold_desig object of student
currs - get curriculum details
reg - create registeration object in registeration table
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context= {
'tab_id' :['2','1']
}
if request.method == 'POST' and request.FILES:
profiles=request.FILES['profiles']
excel = xlrd.open_workbook(file_contents=profiles.read())
sheet=excel.sheet_by_index(0)
for i in range(sheet.nrows):
roll_no=int(sheet.cell(i,0).value)
first_name=str(sheet.cell(i,1).value)
last_name=str(sheet.cell(i,2).value)
email=str(sheet.cell(i,3).value)
sex=str(sheet.cell(i,4).value)
if sex == 'F':
title='Ms.'
else:
title='Mr.'
dob_tmp=sheet.cell(i,5).value
dob_tmp=sheet.cell_value(rowx=i,colx=5)
dob=datetime.datetime(*xlrd.xldate_as_tuple(dob_tmp,excel.datemode))
fathers_name=str(sheet.cell(i,6).value)
mothers_name=str(sheet.cell(i,7).value)
category=str(sheet.cell(i,8).value)
phone_no=int(sheet.cell(i,9).value)
address=str(sheet.cell(i,10).value)
dept=str(sheet.cell(i,11).value)
specialization=str(sheet.cell(i,12).value)
hall_no=sheet.cell(i,13 ).value
department=DepartmentInfo.objects.all().filter(name=dept).first()
if specialization == "":
specialization="None"
if hall_no == None:
hall_no=3
else:
hall_no=int(hall_no)
programme_name=request.POST['Programme']
batch_year=request.POST['Batch']
batch = Batch.objects.all().filter(name = programme_name, discipline__acronym = dept, year = batch_year).first()
user = User.objects.create_user(
username=roll_no,
password='hello123',
first_name=first_name,
last_name=last_name,
email=email,
)
einfo = ExtraInfo.objects.create(
id=roll_no,
user=user,
title=title,
sex=sex,
date_of_birth=dob,
address=address,
phone_no=phone_no,
user_type='student',
department=department,
)
sem=1
stud_data = Student.objects.create(
id=einfo,
programme = programme_name,
batch=batch_year,
batch_id = batch,
father_name = fathers_name,
mother_name = mothers_name,
cpi = 0,
category = category,
hall_no = hall_no,
specialization = specialization,
curr_semester_no=sem,
)
desig = Designation.objects.get(name='student')
hold_des = HoldsDesignation.objects.create(
user=user,
working=user,
designation=desig,
)
sem_id = Semester.objects.get(curriculum = batch.curriculum, semester_no = sem)
course_slots = CourseSlot.objects.all().filter(semester = sem_id)
courses = []
for course_slot in course_slots:
courses += course_slot.courses.all()
new_reg=[]
for c in courses:
reg=course_registration(
course_id = c,
semester_id=sem_id,
student_id=stud_data
)
new_reg.append(reg)
course_registration.objects.bulk_create(new_reg)
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
def get_faculty_list():
"""
to get faculty list from database
@param:
request - contains metadata about the requested page.
@variables:
f1,f2,f3 - temporary varibles
faculty - details of faculty of data
faculty_list - list of faculty
"""
try:
f1 = HoldsDesignation.objects.select_related().filter(designation=Designation.objects.get(name = "Assistant Professor"))
f2 = HoldsDesignation.objects.select_related().filter(designation=Designation.objects.get(name = "Professor"))
f3 = HoldsDesignation.objects.select_related().filter(designation=Designation.objects.get(name = "Associate Professor"))
except Exception as e:
f1=f2=f3=""
pass
faculty = list(chain(f1,f2,f3))
faculty_list = []
for i in faculty:
faculty_list.append(i)
return faculty_list
@login_required
def float_course(request):
"""
to float courses for the next sem and store data in databsae.
User must be logged in and must be acadadmin
@param:
request - contains metadata about the requested page.
@variables:
request_batch - Batch from form
request_branch - Branch from form
request_programme - Programme from form
request_sem - Semester from form
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context= {
'tab_id' :['5','1']
}
if request.method == 'POST':
try:
request_batch = request.POST['batch']
request_branch = request.POST['branch']
request_programme = request.POST['programme']
except Exception as e:
request_batch = ""
request_branch = ""
request_programme = ""
if request_batch == "" and request_branch == "" and request_programme=="":
curriculum = None #Curriculum.objects.all()
else:
sem = sem_for_generate_sheet()
now = datetime.datetime.now()
year = int(now.year)
if sem[0] == 2:
sem = sem[year-int(request_batch)-1]
else:
sem = sem[year-int(request_batch)]
sem+=1
curriculum = Curriculum.objects.select_related().filter(branch = request_branch).filter(batch = request_batch).filter(programme= request_programme).filter(sem=sem).order_by('course_code')
faculty_list = get_faculty_list()
courses = Course.objects.all()
course_type = Constants.COURSE_TYPE
context= {
'courses': courses,
'course_type': course_type,
'curriculum': curriculum,
'faculty_list': faculty_list,
'tab_id' :['5','1']
}
return render(request, "ais/ais.html", context)
else:
return render(request, "ais/ais.html", context)
return render(request, "ais/ais.html", context)
@login_required
def float_course_submit(request):
"""
to float courses for the next sem and store data in databsae.
User must be logged in and must be acadadmin
@param:
request - contains metadata about the requested page.
@variables:
request_batch - Batch from form
request_branch - Branch from form
request_programme - Programme from form
request_sem - Semester from form
"""
if user_check(request):
return HttpResponseRedirect('/academic-procedures/')
context= {
'tab_id' :['5','1']
}
if request.method == "POST":
i=1
while True:
if str(i)+"_ccode" in request.POST:
if str(i)+"_fac" in request.POST:
if request.POST[str(i)+"_fac"] == "" :
logging.warning("No faculty")
else:
flot = Curriculum.objects.select_related().get(curriculum_id=request.POST[str(i)+"_ccode"])
flot.floated = True
flot.save()
new_curr_inst=[]
for c,i in enumerate(request.POST.getlist(str(i)+'_fac')):
inst = get_object_or_404(User, username = i)
inst = ExtraInfo.objects.select_related('user','department').get(user=inst)
if c==0:
ins=Curriculum_Instructor(
curriculum_id=flot,
instructor_id=inst,
chief_inst=True,
)
new_curr_inst.append(ins)
else:
ins=Curriculum_Instructor(
curriculum_id=flot,
instructor_id=inst,
chief_inst=False,
)
new_curr_inst.append(ins)
Curriculum_Instructor.objects.bulk_create(new_curr_inst)
else:
break
i+=1
return render(request, "ais/ais.html", context)
# # ---------------------senator------------------
# @csrf_exempt
def senator(request):
# """
# to add a new student senator
# @param:
# request - contains metadata about the requested page
# @variables:
# current_user - gets the data of current user.
# user_details - gets the details of the required user.
# desig_id - used to check the designation ID.
# extraInfo - extraInfo object of the student with that rollno
# s - designation object of senator
# hDes - holdsDesignation object to store that the particualr student is holding the senator designation
# student - the student object of the new senator
# data - data of the student to be displayed in teh webpage
# """
# current_user = get_object_or_404(User, username=request.user.username)
# user_details = ExtraInfo.objects.all().filter(user=current_user).first()
# desig_id = Designation.objects.all().filter(name='Upper Division Clerk')
temp = HoldsDesignation.objects.all().select_related().filter(designation = desig_id).first()
#print (temp)
# print (current_user)
# acadadmin = temp.working
# k = str(user_details).split()
# print(k)
# final_user = k[2]
# if (str(acadadmin) != str(final_user)):
# return HttpResponseRedirect('/academic-procedures/')
# if request.method == 'POST':
# print(request.POST, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
# rollno = request.POST.getlist('Roll Number')[0]
# # print(request.POST.get('rollno'))
# extraInfo = ExtraInfo.objects.get(id=rollno)
# s = Designation.objects.get(name='Senator')
# hDes = HoldsDesignation()
# hDes.user = extraInfo.user
# hDes.working = extraInfo.user
# hDes.designation = s
# hDes.save()
# student = Student.objects.get(id=extraInfo)
# data = {
# 'name': extraInfo.user.username,
# 'rollno': extraInfo.id,
# 'programme': student.programme,
# 'branch': extraInfo.department.name
# }
# return HttpResponseRedirect('/aims/')
# # return JsonResponse(data)
# else:
# return HttpResponseRedirect('/aims/')
# @csrf_exempt
def deleteSenator(request, pk):
# """
# to remove a senator from the position
# @param:
# request - contains metadata about the requested page
# @variables:
# s - the designation object that contains senator
# student - the list students that is a senator
# hDes - the holdDesignation object that stores the
# information that the particular student is a senator
# """
pass
# if request.POST:
# s = get_object_or_404(Designation, name="Senator")
# student = get_object_or_404(ExtraInfo, id=request.POST.getlist("senate_id")[0])
# hDes = get_object_or_404( HoldsDesignation, user = student.user)
# hDes.delete()
# return HttpResponseRedirect('/aims/')
# else:
# return HttpResponseRedirect('/aims/')# ####################################################
# # ##########covenors and coconvenors##################
# @csrf_exempt
def add_convenor(request):
# """
# to add a new student convenor/coconvenor
# @param:
# request - contains metadata about the requested page
# @variables:
# rollno - rollno of the student to become the convenor/coconvenor
# extraInfo - extraInfo object of the student with that rollno
# s - designation object of Convenor
# p - designation object of Co Convenor
# result - the data that contains where the student will become
# convenor or coconvenor
# hDes - holdsDesignation object to store that the particualr student is
# holding the convenor/coconvenor designation
# student - the student object of the new convenor/coconvenor
# data - data of the student to be displayed in the webpage
# """
s = Designation.objects.get(name='Convenor')
# p = Designation.objects.get(name='Co Convenor')
# if request.method == 'POST':
# rollno = request.POST.get('rollno_convenor')
# extraInfo = ExtraInfo.objects.get(id=rollno)
# s = Designation.objects.get(name='Convenor')
# p = Designation.objects.get(name='Co Convenor')
# result = request.POST.get('designation')
# hDes = HoldsDesignation()
# hDes.user = extraInfo.user
# hDes.working = extraInfo.user
# if result == "Convenor":
# hDes.designation = s
# else:
# hDes.designation = p
# hDes.save()
# data = {
# 'name': extraInfo.user.username,
# 'rollno_convenor': extraInfo.id,
# 'designation': hDes.designation.name,
# }
# return JsonResponse(data)
# else:
# data = {}
# return JsonResponse(data)
# @csrf_exempt
def deleteConvenor(request, pk):
# """
# to remove a convenor/coconvenor from the position
# @param:
# request - contains metadata about the requested page
# pk - the primary key of that particular student field
# @variables:
# s - the designation object that contains convenor
# c - the designation object that contains co convenor
# student - the student object with the given pk
# hDes - the holdDesignation object that stores the
# information that the particular student is a convenor/coconvenor to be deleted
# data - data of the student to be hidden in the webpage
# """
# s = get_object_or_404(Designation, name="Convenor")
c = get_object_or_404(Designation, name="Co Convenor")
# student = get_object_or_404(ExtraInfo, id=pk)
# hDes = HoldsDesignation.objects.filter(user = student.user)
# designation = []
# for des in hDes:
# if des.designation == s or des.designation == c:
# designation = des.designation.name
# des.delete()
# data = {
# 'id': pk,
# 'designation': designation,
# }
# return JsonResponse(data)# ######################################################
# # ##########Senate meeting Minute##################
# @csrf_exempt
def addMinute(request):
# """
# to add a new senate meeting minute object to the database.
# @param:
# request - contains metadata about the requested page
# @variables:
# current_user - details of the current user.
# desig_id - to check the designation of the user.
# user_details - to get the details of the required user.
# """
# current_user = get_object_or_404(User, username=request.user.username)
# user_details = ExtraInfo.objects.all().filter(user=current_user).first()
# desig_id = Designation.objects.all().filter(name='Upper Division Clerk')
temp = HoldsDesignation.objects.all().select_related().filter(designation = desig_id).first()
# print (temp)
# print (current_user)
# acadadmin = temp.working
# k = str(user_details).split()
# print(k)
# final_user = k[2]
# if (str(acadadmin) != str(final_user)):
# return HttpResponseRedirect('/academic-procedures/')
# if request.method == 'POST' and request.FILES:
# form = MinuteForm(request.POST, request.FILES)
# if form.is_valid():
# form.save()
# return HttpResponse('sucess')
# else:
# return HttpResponse('not uploaded')
# return render(request, "ais/ais.html", {})
def deleteMinute(request):
# """
# to delete an existing senate meeting minute object from the database.
# @param:
# request - contains metadata about the requested page
# @variables:
# data - the id of the minute object to be deleted
# t - the minute object received from id to be deleted
# """
# if request.method == "POST":
# data = request.POST['delete']
# t = Meeting.objects.get(id=data)
# t.delete()
return HttpResponseRedirect('/aims/')
# # ######################################################
# # ##########Student basic profile##################
# @csrf_exempt
def add_basic_profile(request):
# """
# It adds the basic profile information like username,password, name,
# rollno, etc of a student
# @param:
# request - contains metadata about the requested page
# @variables:
# name - the name of the student
# roll - the rollno of the student
# batch - the current batch of the student
# programme - the programme the student is enrolled in
# ph - the phone number of the student
# """
if request.method == "POST":
name = request.POST.get('name')
# roll = ExtraInfo.objects.get(id=request.POST.get('rollno'))
# programme = request.POST.get('programme')
# batch = request.POST.get('batch')
# ph = request.POST.get('phoneno')
# if not Student.objects.filter(id=roll).exists():
# db = Student()
# st = ExtraInfo.objects.get(id=roll.id)
# db.name = name.upper()
# db.id = roll
# db.batch = batch
# db.programme = programme
# st.phone_no = ph
# db.save()
# st.save()
# data = {
# 'name': name,
# 'rollno': roll.id,
# 'programme': programme,
# 'phoneno': ph,
# 'batch': batch
# }
# print(data)
# return JsonResponse(data)
# else:
# data = {}
# return JsonResponse(data)
# else:
# data = {}
# return JsonResponse(data)
# @csrf_exempt
def delete_basic_profile(request, pk):
# """
# Deletes the student from the database
# @param:
# request - contains metadata about the requested page
# pk - the primary key of the student's record in the database table
# @variables:
# e - the extraInfo objects of the student
# user - the User object of the student
# s - the student object of the student
# """
e = get_object_or_404(ExtraInfo, id=pk)
# user = get_object_or_404(User, username = e.user.username)
# s = get_object_or_404(Student, id=e)
# data = {
# 'rollno': pk,
# }
# s.delete()
# e.delete()
# u.delete()
# return JsonResponse(data)# #########################################################
# '''
# # view to add attendance data to database
# def curriculum(request):
# '''
def delete_advanced_profile(request):
# """
# to delete the advance information of the student
# @param:
# request - contains metadata about the requested page
# @variables:
# current_user - the username of the logged in user
# user_details - the details of the current user
# desig_id - checking the designation of the current user
# acadadmin - deatils of the acad admin
# s - the student object from the requested rollno
# """
current_user = get_object_or_404(User, username=request.user.username)
# user_details = ExtraInfo.objects.all().filter(user=current_user).first()
# desig_id = Designation.objects.all().filter(name='Upper Division Clerk')
# temp = HoldsDesignation.objects.all().filter(designation = desig_id).first()
# print (temp)
# print (current_user)
# acadadmin = temp.working
# k = str(user_details).split()
# print(k)
# final_user = k[2]
# if (str(acadadmin) != str(final_user)):
# return HttpResponseRedirect('/academic-procedures/')
# if request.method == "POST":
# st = request.POST['delete']
# arr = st.split("-")
# stu = arr[0]
# if Student.objects.get(id=stu):
# s = Student.objects.get(id=stu)
# s.father_name = ""
# s.mother_name = ""
# s.hall_no = 1
# s.room_no = ""
# s.save()
# else:
# return HttpResponse("Data Does Not Exist")
# return HttpResponse("Data Deleted Successfully")
def add_advanced_profile(request):
# """
# It adds the advance profile information like hall no, room no,
# profile picture, about me etc of a student
# @param:
# request - contains metadata about the requested page
# @variables:
# current_user - the username of the logged in user
# user_details - the details of the current user
# desig_id - checking the designation of the current user
# acadadmin - deatils of the acad admin
# father - father's name of the student
# rollno - the rollno of the student required to check if the student is available
# mother - mother's name of the student
# add - student's address
# cpi - student's cpi
# hall - hall no of where the student stays
# room no - hostel room no
# """
current_user = get_object_or_404(User, username=request.user.username)
# user_details = ExtraInfo.objects.all().filter(user=current_user).first()
# desig_id = Designation.objects.all().filter(name='Upper Division Clerk')
# temp = HoldsDesignation.objects.all().filter(designation = desig_id).first()
# print (temp)
# print (current_user)
# acadadmin = temp.working
# k = str(user_details).split()
# print(k)
# final_user = k[2]
# if (str(acadadmin) != str(final_user)):
# return HttpResponseRedirect('/academic-procedures/')
# if request.method == "POST":
# print(request.POST)
# rollno=request.POST.get('roll')
# print(rollno)
# student = ExtraInfo.objects.get(id=rollno)
# print(student.address)
# if not student:
# data = {}
# return JsonResponse(data)
# else:
# father = request.POST.get('father')
# mother = request.POST.get('mother')
# add = request.POST.get('address')
# hall = request.POST.get('hall')
# room = request.POST.get('room')
# cpi = request.POST.get('cpi')
# student.address = str(hall) + " " + str(room)
# student.save()
# s = Student.objects.get(id=student)
# s.father_name=father
# s.mother_name=mother
# s.hall_no = hall
# s.room_no = room
# s.save()
# return HttpResponseRedirect('/academic-procedures/')
# return HttpResponseRedirect('/academic-procedures/')
def add_optional(request):
# """
# acadmic admin to update the additional courses
# @param:
# request - contains metadata about the requested page.
# @variables:
# choices - selected addtional courses by the academic person.
# course - Course details which is selected by the academic admin.
# """
if request.method == "POST":
pass
# print(request.POST)
# choices = request.POST.getlist('choice')
# for i in choices:
# course = Course.objects.all().filter(course_id=i).first()
# course.acad_selection = True
# course.save()
# courses = Course.objects.all()
# for i in courses:
# if i.course_id not in choices:
# i.acad_selection = False
# i.save()
# return HttpResponseRedirect('/academic-procedures/')
def min_cred(request):
# """
# to set minimum credit for a current semester that a student must take
# @param:
# request - contains metadata about the requested page.
# @variables:
# sem_cred = Get credit details from forms and the append it to an array.
# sem - Get the object for the minimum credits from the database and the update it.
# """
if request.method=="POST":
sem_cred = []
# sem_cred.append(0)
# for i in range(1, 10):
# sem = "sem_"+"1"
# sem_cred.append(request.POST.getlist(sem)[0])
# for i in range(1, 9):
# sem = MinimumCredits.objects.all().filter(semester=i).first()
# sem.credits = sem_cred[i+1]
# sem.save()
# return HttpResponse("Worked")
def view_course(request):
# if request.method == "POST":
# programme=request.POST['programme']
# batch=request.POST['batch']
# branch=request.POST['branch']
# sem=request.POST['sem']
# curriculum_courses = Curriculum.objects.filter(branch = branch).filter(batch = batch).filter(programme= programme).filter(sem = sem)
# print(curriculum_courses)
# courses = Course.objects.all()
# course_type = Constants.COURSE_TYPE
# context= {
# 'courses': courses,
# 'course_type': course_type,
# 'curriculum_course': curriculum_courses,
# }
# return render(request, "ais/ais.html", context)
# else:
# return render(request, "ais/ais.html")
return render(request, "ais/ais.html")
def delete_grade(request):
# """
# It deletes the grade of the student
# @param:
# request - contains metadata about the requested page
# @variables:
# current_user - father's name of the student
# user_details - the rollno of the student required to check if the student is available
# desig_id - mother 's name of the student
# acadadmin - student's address
# final_user - details of the user
# sem - current semester of the student
# data - tag whether to delete it or not
# course - get the course details
# """
# current_user = get_object_or_404(User, username=request.user.username)
# user_details = ExtraInfo.objects.all().filter(user=current_user).first()
# desig_id = Designation.objects.all().filter(name='Upper Division Clerk')
# temp = HoldsDesignation.objects.all().filter(designation = desig_id).first()
# print (temp)
# print (current_user)
# acadadmin = temp.working
# k = str(user_details).split()
# print(k)
# final_user = k[2]
# if (str(acadadmin) != str(final_user)):
# return HttpResponseRedirect('/academic-procedures/')
# print(request.POST['delete'])
# data = request.POST['delete']
# d = data.split("-")
# id = d[0]
# course = d[2]
# sem = int(d[3])
# if request.method == "POST":
# if(Grades.objects.filter(student_id=id, sem=sem)):
# s = Grades.objects.filter(student_id=id, sem=sem)
# for p in s:
# if (str(p.course_id) == course):
# print(p.course_id)
# p.delete()
# else:
# return HttpResponse("Unable to delete data")
return HttpResponse("Data Deleted SuccessFully")
@login_required
def verify_grade(request):
"""
It verify the grades of the student
@param:
request - contains metadata about the requested page
@variables:
current_user - father's name of the student
user_details - the rollno of the student required to check if the student is available
desig_id - mother's name of the student
acadadmin - student's address
subject - subject of which the grade has to be added
sem - semester of the student
grade - grade to be added in the student
course - course ofwhich the grade is added
"""
# if user_check(request):
# return HttpResponseRedirect('/academic-procedures/')
# if request.method == "POST":
# curr_id=request.POST['course']
# print(curr_id)
# curr_course = Curriculum.objects.filter(curriculum_id=curr_id)
# grades = Grades.objects.filter(curriculum_id=curr_course)
# context= {
# 'grades': grades,
# 'tab_id' :"2"
# }
# return render(request,"ais/ais.html", context)
# else:
# return HttpResponseRedirect('/aims/')
return HttpResponseRedirect('/aims/')
def confirm_grades(request):
# if user_check(request):
# return HttpResponseRedirect('/academic-procedures/')
# if request.method == "POST":
# print("confirm hone wala hai")
# print(request.POST)
return HttpResponseRedirect('/aims/')
| 35.826674 | 199 | 0.591761 | 1 | 1.9131 | [
0.008102104999125004,
0.06065990775823593,
-0.007816297002136707,
-0.022749904543161392,
0.007599957752972841,
-0.009392470121383667,
-0.016642559319734573,
-0.016821393743157387,
-0.02771913632750511,
0.030436653643846512,
0.019448596984148026,
0.013773654587566853,
-0.006775946822017431,
-0.013120751827955246,
-0.01743839494884014,
0.031819041818380356,
0.08846904337406158,
0.0028618481010198593,
-0.02297222428023815,
0.021266648545861244,
-0.02141578495502472,
-0.0060972594656050205,
-0.010722920298576355,
-0.002055968390777707,
0.003672069637104869,
0.017739787697792053,
0.039643339812755585,
-0.018079813569784164,
-0.0023577238898724318,
-0.017898568883538246,
0.000015831710697966628,
-0.002902248175814748,
-0.010067413561046124,
-0.011158376932144165,
-0.009307324886322021,
-0.02672344073653221,
0.027988841757178307,
-0.031441833823919296,
0.04851778596639633,
0.0024685789830982685,
0.01201046071946621,
-0.025776784867048264,
0.009616831317543983,
-0.032805364578962326,
-0.007810086011886597,
-0.0064651863649487495,
-0.014296263456344604,
-0.024386141449213028,
0.041507307440042496,
-0.03583003208041191,
0.00047871333663351834,
0.0010800622403621674,
-0.023821095004677773,
-0.00008378664642805234,
0.0029349406249821186,
-0.04871835559606552,
0.03390389680862427,
-0.047954387962818146,
-0.0200062058866024,
0.040095601230859756,
-0.0027749883010983467,
0.003190744901075959,
0.03548865020275116,
-0.022300375625491142,
-0.047707002609968185,
0.00106348330155015,
-0.016660263761878014,
-0.021772710606455803,
0.032211821526288986,
0.02881576679646969,
-0.010846667923033237,
0.014987208880484104,
0.08005871623754501,
0.05878829583525658,
-0.061086688190698624,
0.012013295665383339,
-0.011758286505937576,
-0.023079685866832733,
-0.03640612214803696,
-0.004012524150311947,
-0.0223994180560112,
-0.003810948459431529,
-0.007930130697786808,
-0.006448720581829548,
-0.0028653638437390327,
0.029701240360736847,
0.017593616619706154,
-0.015312779694795609,
0.024561317637562752,
-0.00613653939217329,
0.006697570905089378,
0.02840934321284294,
-0.0454951710999012,
-0.01391740795224905,
-0.024795426055788994,
-0.07091959565877914,
0.005267983768135309,
-0.01019201334565878,
-0.02332943305373192,
0.013853377662599087,
0.06257568299770355,
0.0058441199362277985,
0.07825933396816254,
-0.0024624469224363565,
0.011073963716626167,
0.008699293248355389,
-0.020798148587346077,
0.004652044735848904,
0.006886952091008425,
-0.0020462730899453163,
-0.07209056615829468,
-0.009659483097493649,
0.013807306066155434,
-0.023947935551404953,
-0.0697316825389862,
0.01298049371689558,
0.013050219975411892,
0.020057380199432373,
0.0072632175870239735,
0.12826578319072723,
-0.02497650869190693,
0.05031731352210045,
0.0017502153059467673,
0.03385656327009201,
-0.004215009976178408,
0.07618547230958939,
0.017393069341778755,
-0.05050329864025116,
0.003694565501064062,
0.02487240545451641,
0.003653408493846655,
0.036250825971364975,
-0.00549663882702589,
0.05241822451353073,
0.011119579896330833,
0.007520714774727821,
-0.018073828890919685,
-0.02104974165558815,
-0.06940782070159912,
-0.01491247396916151,
-0.0064743803814053535,
0.0039220512844622135,
-0.0035972592886537313,
-0.02879367582499981,
0.03316961228847504,
-0.04271459951996803,
-0.014914385043084621,
-0.02668791450560093,
-0.005218305625021458,
-0.04313065856695175,
0.020605036988854408,
0.06464291363954544,
0.016143856570124626,
-0.0023924214765429497,
-0.0029198345728218555,
-0.00883669126778841,
-0.02144709974527359,
-0.08131981641054153,
0.03412644937634468,
0.011739615350961685,
0.005985199939459562,
0.012332383543252945,
-0.02081792987883091,
0.0069209919311106205,
0.047405123710632324,
-0.01964464969933033,
-0.00011270713002886623,
0.01245423685759306,
0.007802458014339209,
-0.00555895920842886,
0.0053290133364498615,
0.011735060252249241,
-0.028150735422968864,
0.008861750364303589,
-0.06564351171255112,
-0.000049850983486976475,
0.001822604681365192,
-0.040800534188747406,
0.03244026005268097,
-0.02946428768336773,
-0.003358915913850069,
-0.026243288069963455,
0.03634721785783768,
0.04211690276861191,
0.012566243298351765,
0.03581913188099861,
-0.11125709116458893,
-0.06622212380170822,
0.03149896487593651,
-0.010026865638792515,
-0.01375486422330141,
0.004982717800885439,
-0.010199092328548431,
0.011476723477244377,
-0.008694381453096867,
0.01884574070572853,
-0.0193364005535841,
-0.002722108503803611,
-0.0036869614850729704,
-0.017858808860182762,
-0.016244707629084587,
-0.03853264078497887,
0.009924955666065216,
-0.018253143876791,
-0.013023394159972668,
0.00007998330693226308,
-0.5856534242630005,
0.003274110145866871,
-0.02235683985054493,
0.010896389372646809,
0.0632324293255806,
0.016268927603960037,
-0.023692503571510315,
0.01146770641207695,
-0.012655578553676605,
0.014788134023547173,
-0.005482809152454138,
-0.022669784724712372,
0.037292368710041046,
-0.006283975671976805,
-0.01340229157358408,
0.005547527223825455,
0.01818837970495224,
-0.006265511270612478,
-0.035078197717666626,
0.006920913700014353,
-0.0026624989695847034,
-0.024007627740502357,
-0.03544829785823822,
-0.005345011129975319,
0.017394430935382843,
-0.04984090477228165,
-0.02358926646411419,
0.009486245922744274,
-0.03987985476851463,
-0.004637944977730513,
-0.031340327113866806,
-0.01307886466383934,
0.03218825161457062,
-0.006886085029691458,
0.024810675531625748,
0.029349807649850845,
0.03940713033080101,
-0.002509355079382658,
-0.01319741178303957,
-0.05807936564087868,
-0.03563740849494934,
-0.03610970079898834,
-0.006594826001673937,
-0.08164907991886139,
-0.012259777635335922,
0.009887263178825378,
0.05137591063976288,
0.009360401891171932,
-0.03605073690414429,
0.05604665353894234,
-0.05786226689815521,
-0.00543410237878561,
0.04517338424921036,
-0.003198104677721858,
-0.02193344011902809,
0.017109908163547516,
0.0038356014993041754,
0.008690586313605309,
-0.004332607612013817,
-0.007104906253516674,
-0.003474301192909479,
0.004503481090068817,
-0.013421664945781231,
-0.01624993048608303,
-0.0681726410984993,
-0.009088512510061264,
0.013749206438660622,
-0.05937179923057556,
-0.0035771604161709547,
0.024262309074401855,
-0.017102714627981186,
-0.03934966027736664,
-0.05739258602261543,
-0.0331181138753891,
-0.022617999464273453,
0.005187236703932285,
-0.02393067441880703,
0.02341987006366253,
0.013373173773288727,
0.008787175640463829,
0.027649741619825363,
0.004618873819708824,
0.007190394215285778,
0.004108997527509928,
0.010634555481374264,
0.0016195677453652024,
0.035208068788051605,
-0.0036800119560211897,
0.022332102060317993,
0.01551826298236847,
0.06698499619960785,
0.0011627577478066087,
0.009413516148924828,
0.022210590541362762,
0.01132277026772499,
-0.06499451398849487,
0.011414802633225918,
0.06460723280906677,
0.034075625240802765,
0.055159952491521835,
-0.014720591716468334,
0.013061584904789925,
0.002374701201915741,
-0.01806405372917652,
0.006581692490726709,
-0.03802884742617607,
-0.009586740285158157,
0.0068291425704956055,
0.026237696409225464,
-0.06735967844724655,
-0.04225582629442215,
-0.01073375903069973,
-0.046175532042980194,
-0.04283049702644348,
-0.03317459300160408,
-0.03729495406150818,
0.016575245186686516,
-0.0012355346698313951,
-0.01833416521549225,
-0.006774464622139931,
-0.010646667331457138,
-0.012887170538306236,
0.00759098632261157,
0.007109441794455051,
0.016295338049530983,
-0.007304023951292038,
-0.0022050270345062017,
0.011632651090621948,
-0.016765737906098366,
0.041973382234573364,
-0.02645631693303585,
-0.028017381206154823,
-0.00009524551569484174,
-0.0006200909847393632,
-0.01893373765051365,
0.015617751516401768,
0.006809438578784466,
-0.015746543183922768,
0.009965631179511547,
0.012200498022139072,
-0.08054771274328232,
0.024476779624819756,
0.011026537977159023,
-0.04149436950683594,
-0.00860164500772953,
0.019086552783846855,
0.01073321234434843,
-0.01782776415348053,
-0.01067692507058382,
-0.01814524084329605,
-0.030029596760869026,
-0.009041565470397472,
0.022751756012439728,
-0.020205562934279442,
0.03317265212535858,
-0.01769564300775528,
-0.02738940715789795,
0.009540224447846413,
-0.011828078888356686,
0.023511456325650215,
0.02054717391729355,
-0.03179167956113815,
-0.01880641095340252,
-0.007994643412530422,
0.051812794059515,
-0.0038894223980605602,
-0.0008204316254705191,
0.05396156385540962,
-0.00893970113247633,
-0.025018014013767242,
0.028835829347372055,
-0.024853726848959923,
-0.015632132068276405,
-0.01028662919998169,
-0.07049147039651871,
0.002332964912056923,
0.004508511628955603,
0.009781270287930965,
-0.040514614433050156,
-0.0478670597076416,
0.03642326593399048,
0.01379594299942255,
0.011213375255465508,
-0.031787026673555374,
-0.011106260120868683,
0.027390822768211365,
-0.00514951441437006,
-0.04976154863834381,
0.004853696562349796,
-0.029521964490413666,
0.01300258282572031,
0.04137856140732765,
-0.04991855472326279,
0.018573815003037453,
-0.044471461325883865,
0.011327037587761879,
0.02521372213959694,
-0.08711309731006622,
-0.018671870231628418,
-0.03931756317615509,
-0.01306847296655178,
0.017289288341999054,
-0.008413296192884445,
-0.007738948799669743,
0.0024743780959397554,
0.02154611609876156,
-0.01076316088438034,
-0.006599658168852329,
0.0019527255790308118,
0.036677323281764984,
-0.025117753073573112,
0.017922252416610718,
0.03674706071615219,
-0.016350936144590378,
0.005852946080267429,
0.009817424230277538,
-0.019800648093223572,
-0.0043146186508238316,
-0.015680549666285515,
-0.03891444206237793,
0.07742775976657867,
-0.042440611869096756,
0.0006431702640838921,
-0.005797194316983223,
-0.014250503852963448,
-0.002844104776158929,
-0.022324591875076294,
0.07037924230098724,
-0.025376085191965103,
-0.046507351100444794,
-0.003977085463702679,
0.04061543568968773,
-0.01213411707431078,
-0.01669544167816639,
0.010246212594211102,
0.06057443842291832,
0.020186826586723328,
0.030173739418387413,
0.018689416348934174,
-0.017738206312060356,
0.05252322554588318,
0.03235428035259247,
0.013579828664660454,
0.010617949068546295,
-0.025065071880817413,
-0.01042867824435234,
0.002220824360847473,
-0.03177407756447792,
0.004824256524443626,
-0.011975605972111225,
-0.018029822036623955,
0.014154616743326187,
0.013837125152349472,
0.013984490185976028,
0.010030295699834824,
0.03522457927465439,
-0.012766765430569649,
-0.02175712026655674,
0.00045722280628979206,
-0.01557185035198927,
0.023045334964990616,
-0.04260272905230522,
-0.0085536427795887,
-0.010168611072003841,
0.000020191064322716556,
0.037465836852788925,
-0.0075249578803777695,
-0.025124143809080124,
0.05662405863404274,
0.00389090902172029,
0.03467549383640289,
-0.020619554445147514,
-0.017481308430433273,
-0.02110070176422596,
0.026502573862671852,
0.006151233334094286,
-0.0038865013048052788,
-0.019661705940961838,
0.028269128873944283,
0.03304728865623474,
-0.010097047314047813,
0.024602381512522697,
0.03630290552973747,
0.011514785699546337,
-0.005543065257370472,
0.003711189143359661,
-0.024841025471687317,
-0.020650876685976982,
-0.05039660260081291,
0.004315858241170645,
-0.02801627852022648,
-0.013614242896437645,
0.022059116512537003,
0.050211101770401,
-0.00420593423768878,
-0.026030564680695534,
-0.01752323843538761,
0.01602514088153839,
-0.010080289095640182,
-0.006124172359704971,
0.021416014060378075,
-0.008709129877388477,
-0.026826346293091774,
-0.043932653963565826,
0.025010976940393448,
-0.008430656976997852,
0.01620718091726303,
-0.030347421765327454,
0.018235476687550545,
0.016572659835219383,
-0.003663918934762478,
0.041528139263391495,
0.01224240567535162,
0.03177222982048988,
0.023352431133389473,
0.0015351311303675175,
0.061567939817905426,
0.03937375172972679,
0.008538452908396721,
-0.010664587840437889,
0.005218508653342724,
0.0284271202981472,
0.029586713761091232,
0.022443430498242378,
0.020328961312770844,
-0.005990119650959969,
-0.025715844705700874,
-0.016670694574713707,
0.014495348557829857,
0.0488235168159008,
-0.013716032728552818,
-0.0019872940611094236,
-0.0323188342154026,
-0.020448125898838043,
0.034662239253520966,
0.05801358446478844,
0.033533092588186264,
0.0807565376162529,
0.014870029874145985,
-0.00890580378472805,
-0.038051337003707886,
-0.01107143983244896,
-0.03165615722537041,
-0.00936879776418209,
-0.021570025011897087,
-0.043905600905418396,
-0.06111365184187889,
-0.0030335120391100645,
0.02715355157852173,
-0.04779353365302086,
0.001915722619742155,
-0.008961481973528862,
0.032573141157627106,
0.0021614960860460997,
-0.029161756858229637,
-0.01766183413565159,
0.04485240951180458,
-0.00042845422285608947,
0.0020805061794817448,
0.022078771144151688,
0.0032364800572395325,
0.008273459039628506,
0.00803298968821764,
-0.023050135001540184,
0.018251102417707443,
0.005625838879495859,
0.025822220370173454,
-0.03591565787792206,
-0.009845311753451824,
-0.02191421203315258,
-0.011467712000012398,
-0.012657100334763527,
0.00498293386772275,
0.027874616906046867,
-0.01806090958416462,
0.03428616002202034,
0.008643515408039093,
-0.021269522607326508,
-0.017185339704155922,
-0.03254706785082817,
-0.004928907845169306,
-0.003168908879160881,
0.03958418592810631,
0.03019748255610466,
-0.01150650717318058,
0.05298770219087601,
0.00744074210524559,
-0.004997430369257927,
-0.028156310319900513,
-0.04283099249005318,
0.009966529905796051,
-0.03814222291111946,
0.029669830575585365,
0.04386238008737564,
-0.013185485266149044,
-0.0028337519615888596,
-0.041908085346221924,
0.005366370547562838,
0.013784252107143402,
-0.0022321485448628664,
0.013172527775168419,
0.014172122813761234,
-0.011833741329610348,
-0.01553049311041832,
0.05229879915714264,
-0.04921623691916466,
0.0029325149953365326,
0.007321689277887344,
0.012846885249018669,
0.09988047182559967,
0.03965727612376213,
0.04930558428168297,
-0.06958126276731491,
-0.013419142924249172,
0.033306073397397995,
0.0028486864175647497,
-0.0429963544011116,
0.004507908131927252,
0.01602019928395748,
0.01125339511781931,
0.044267844408750534,
-0.030021950602531433,
0.02500658482313156,
-0.02084224484860897,
-0.0031488300301134586,
-0.047110773622989655,
0.015096331015229225,
-0.0021973364055156708,
-0.0173319261521101,
0.008803345263004303,
0.020946433767676353,
-0.03367914631962776,
0.003014440881088376,
-0.017230363562703133,
-0.0050535197369754314,
0.010395183227956295,
-0.015547886490821838,
-0.06076941266655922,
-0.007726091425865889,
-0.004296971019357443,
0.015878504142165184,
0.009195871651172638,
0.011969680897891521,
0.014087752439081669,
0.00284009613096714,
-0.1362561136484146,
0.012334459461271763,
0.012465630657970905,
-0.008480830118060112,
-0.020261287689208984,
0.03250765800476074,
-0.007541050668805838,
-0.0005364252137951553,
0.05361141264438629,
0.05087917670607567,
0.035979997366666794,
0.020609935745596886,
0.018405597656965256,
0.038605064153671265,
0.016541874036192894,
0.013158541172742844,
0.046906083822250366,
-0.01998654007911682,
0.0019401076715439558,
-0.02555304393172264,
0.03963341936469078,
-0.010289091616868973,
-0.02359328232705593,
-0.04603711888194084,
-0.011764503084123135,
-0.030701804906129837,
0.041767433285713196,
0.03132712468504906,
0.040109045803546906,
-0.01828913204371929,
0.02014806866645813,
-0.033928461372852325,
-0.009607832878828049,
0.049320898950099945,
0.0019472832791507244,
-0.024418365210294724,
0.008739516139030457,
0.03137258067727089,
-0.015799492597579956,
0.018173180520534515,
-0.018472278490662575,
-0.011607254855334759,
0.01192130520939827,
-0.010211999528110027,
0.01965520903468132,
0.01996549963951111,
0.0126359136775136,
0.041180312633514404,
-0.0033979250583797693,
0.03723672032356262,
-0.03153398260474205,
-0.0011214811820536852,
0.0746413990855217,
0.04470067098736763,
0.008672810159623623,
-0.006689421832561493,
-0.07736290991306305,
0.011415809392929077,
-0.03905155509710312,
-0.006502588279545307,
0.032752253115177155,
0.007388124708086252,
0.043635398149490356,
0.01717871055006981,
-0.05407792702317238,
-0.020482512190937996,
-0.006588147021830082,
0.009251239709556103,
0.024397145956754684,
-0.009464791044592857,
0.05671790614724159,
0.03006706014275551,
0.06339062750339508,
0.011005700565874577,
-0.017789918929338455,
0.010696932673454285,
-0.010205622762441635,
0.0031235539354383945,
0.04468340426683426,
-0.011098633520305157,
-0.01958432048559189,
-0.02421974390745163,
0.01973685435950756,
0.008460450917482376,
-0.006274566985666752,
0.018282124772667885,
-0.014616083353757858,
-0.016954438760876656,
-0.044768501073122025,
0.019258949905633926,
-0.0225386880338192,
-0.01232121977955103,
0.01575229875743389,
-0.025417914614081383,
0.0247814878821373,
0.027649832889437675,
0.008617067709565163,
-0.0560283325612545,
-0.025543909519910812,
0.0033050240017473698,
0.022508110851049423,
-0.0169370137155056,
0.033580511808395386,
0.030380479991436005,
0.003171155694872141,
0.012168897315859795,
-0.05543651804327965,
0.0014118595281615853,
0.00035858855699189007,
-0.0037937993183732033,
-0.02130354940891266,
0.00858313124626875,
0.052813321352005005,
-0.016193117946386337,
0.001398567808791995,
0.01871694065630436,
0.008279928006231785
] |
8a2c8b21ea65c7fbe7c24c113fc96385ffdf77cb | 1,245 | py | Python | subject/tests/functional/test_glance_replicator.py | laoyigrace/subject | e6ed989fdc250917a19788112b22322b73b3550f | [
"Apache-2.0"
] | null | null | null | subject/tests/functional/test_glance_replicator.py | laoyigrace/subject | e6ed989fdc250917a19788112b22322b73b3550f | [
"Apache-2.0"
] | null | null | null | subject/tests/functional/test_glance_replicator.py | laoyigrace/subject | e6ed989fdc250917a19788112b22322b73b3550f | [
"Apache-2.0"
] | null | null | null | # 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.
"""Functional test cases for subject-replicator"""
import sys
from subject.tests import functional
from subject.tests.utils import execute
class TestGlanceReplicator(functional.FunctionalTest):
"""Functional tests for subject-replicator"""
def test_compare(self):
# Test for issue: https://bugs.launchpad.net/glance/+bug/1598928
cmd = ('%s -m subject.cmd.replicator '
'compare az1:9292 az2:9292 --debug' %
(sys.executable,))
exitcode, out, err = execute(cmd, raise_error=False)
self.assertIn(
'Request: GET http://az1:9292/v1/subjects/detail?is_public=None',
err
)
| 36.617647 | 78 | 0.683534 | 1 | 1.0581 | [
0.0033107809722423553,
0.02088257297873497,
0.009680991061031818,
0.003725009737536311,
0.005532607901841402,
-0.0027475766837596893,
-0.00540525559335947,
0.0014599713031202555,
-0.005420392379164696,
0.0021168680395931005,
0.003124465001747012,
0.005032933782786131,
0.0051378305070102215,
-0.014028542675077915,
-0.0008240382885560393,
0.017499597743153572,
-0.05078037455677986,
0.0020701384637504816,
-0.004001435358077288,
0.004543901886790991,
-0.008726353757083416,
0.008654885925352573,
0.009713158011436462,
0.005764342844486237,
0.00464260159060359,
-0.0012848946498706937,
0.007937257178127766,
0.0005098265246488154,
-0.004470036365091801,
-0.008115946315228939,
-0.00001514137056801701,
-0.0033164636697620153,
-0.008557891473174095,
-0.005726188886910677,
0.00436582462862134,
-0.005422131158411503,
-0.0006258298526518047,
-0.017310824245214462,
0.010844302363693714,
-0.002536711050197482,
-0.005564898252487183,
-0.01640143059194088,
-0.0019072683062404394,
0.0023170390632003546,
-0.00867488607764244,
0.004173828288912773,
-0.004981216974556446,
0.0034796542022377253,
-0.012458521872758865,
0.008663313463330269,
-0.008993349969387054,
0.004569164011627436,
0.01589851640164852,
0.0020076839718967676,
-0.004681102465838194,
-0.008628333918750286,
0.013952286913990974,
-0.0003907854843419045,
-0.009075319394469261,
0.0013690053019672632,
-0.004692337475717068,
-0.0024155888240784407,
0.004869935568422079,
0.0019654138013720512,
-0.014139089733362198,
-0.005953872110694647,
-0.005317767150700092,
0.0030941942241042852,
-0.0015774259809404612,
0.007380031980574131,
0.00025987124536186457,
-0.003519871039316058,
0.006717133801430464,
0.0042869034223258495,
0.0018836983945220709,
-0.006145332008600235,
-0.001322297495789826,
-0.002725442172959447,
0.008068084716796875,
0.004383454564958811,
0.004760425072163343,
-0.006566048599779606,
0.005835289601236582,
0.007193538825958967,
0.012413806281983852,
0.010678977705538273,
0.02153829112648964,
-0.00911641214042902,
0.04471660405397415,
0.007469507399946451,
-0.007546931505203247,
0.0010413187555968761,
-0.004436776973307133,
-0.002517290646210313,
-0.005870402790606022,
-0.02703569456934929,
-0.0010175923816859722,
-0.0018710974836722016,
-0.0031029940582811832,
0.005175922065973282,
-0.0007544383406639099,
0.006238619331270456,
-0.0005463366978801787,
-0.0007865966181270778,
-0.010914675891399384,
0.009472152218222618,
-0.00861396361142397,
-0.0016344148898497224,
0.0049720648676157,
0.0010616967920213938,
-0.013491412624716759,
-0.0023026939015835524,
0.000572569202631712,
-0.01262796949595213,
0.0018756387289613485,
0.0013761218870058656,
-0.007210141513496637,
0.04764357954263687,
-0.0011645401827991009,
0.0018153706332668662,
-0.00355221307836473,
0.004049261100590229,
0.0003855490358546376,
0.0035969598684459925,
0.009282698854804039,
-0.0029415066819638014,
0.013818242587149143,
0.009631638415157795,
0.002886693924665451,
0.008586117997765541,
-0.0018381114350631833,
0.009103463031351566,
-0.0050812531262636185,
-0.004717555362731218,
0.0013306657783687115,
-0.005761351436376572,
0.007482432294636965,
0.00011607841588556767,
-0.009071542881429195,
0.0025723332073539495,
-0.0008366017136722803,
-0.008086021989583969,
0.0010734000243246555,
-0.0037959774490445852,
0.009124300442636013,
-0.007419432047754526,
-0.006735146511346102,
-0.006162141915410757,
-0.004028646741062403,
0.0030298528727144003,
0.010588089004158974,
0.002841412555426359,
0.002487429417669773,
-0.0053372555412352085,
-0.0066511621698737144,
0.001253877766430378,
-0.0005543407751247287,
0.0014873159816488624,
0.005972276441752911,
0.004435277543962002,
-0.011890181340277195,
-0.0008587689371779561,
0.003741618013009429,
0.00394774042069912,
-0.0015700883232057095,
0.005641614552587271,
-0.009281900711357594,
0.006865983363240957,
0.0005271267727948725,
0.004711988382041454,
0.011084478348493576,
-0.004946808330714703,
0.0005275532021187246,
-0.0014628650387749076,
0.004313158802688122,
-0.0005707753589376807,
0.005805542692542076,
0.010738658718764782,
-0.001220740843564272,
-0.004717962350696325,
0.0031854072585701942,
0.00370219349861145,
0.01038331724703312,
0.007422498892992735,
-0.0024467152543365955,
-0.0005572687950916588,
-0.003700841451063752,
-0.0022432859987020493,
0.006058740429580212,
-0.004433746449649334,
0.007027752697467804,
0.004966395907104015,
-0.011837447062134743,
-0.0085677495226264,
0.002461126772686839,
-0.010321231558918953,
0.00402992544695735,
0.013485225848853588,
0.01371261291205883,
-0.00298152188770473,
0.0034863653127104044,
-0.008603142574429512,
0.002052499447017908,
0.009893682785332203,
0.002686975058168173,
-0.012637127190828323,
-0.9614425897598267,
0.007987461052834988,
0.0027073302771896124,
-0.0000787357275839895,
0.00580277806147933,
0.003050013678148389,
0.0021742903627455235,
0.0050274948589503765,
0.014747560024261475,
-0.005405510775744915,
-0.0054806605912745,
-0.010079069063067436,
-0.008802816271781921,
-0.0015534773701801896,
-0.006313820835202932,
-0.0023932892363518476,
-0.007740054279565811,
-0.002641007537022233,
-0.004309794865548611,
-0.0024848363827914,
-0.0011398046044632792,
0.005943178199231625,
-0.0010779715375974774,
0.003899344941601157,
0.0014452609466388822,
0.00398112740367651,
-0.0053274682722985744,
-0.0014072484336793423,
-0.0028506831731647253,
-0.0020540563855320215,
-0.0070441304706037045,
-0.01287643238902092,
-0.002260473556816578,
-0.002844698028638959,
0.009459778666496277,
0.00015240279026329517,
0.008154790848493576,
-0.0024724125396460295,
0.0021296502090990543,
-0.0072783008217811584,
0.0065844436176121235,
-0.00222063809633255,
0.004061576444655657,
-0.029933365061879158,
-0.001702532754279673,
-0.0007939196075312793,
-0.00841220747679472,
0.008117081597447395,
-0.0013847025111317635,
0.00022732488287147135,
-0.0038949456065893173,
-0.007184306625276804,
0.00920867919921875,
-0.006583067122846842,
0.0008986791362985969,
-0.001175065292045474,
-0.00899503007531166,
-0.0026008388958871365,
-0.007604279555380344,
0.0019623807165771723,
0.005812441930174828,
-0.0031974499579519033,
-0.0029002337250858545,
-0.0036161192692816257,
0.0032342765480279922,
0.001313652959652245,
0.0021061047445982695,
-0.017225749790668488,
-0.008700399659574032,
-0.0012825536541640759,
0.00044040847569704056,
-0.003978209104388952,
-0.0020002254750579596,
0.0026597098913043737,
-0.008475890383124352,
0.006476154550909996,
0.0013301309663802385,
-0.0023278496228158474,
-0.008354013785719872,
-0.0013489248231053352,
-0.009604311548173428,
-0.007004554383456707,
0.0015565087087452412,
-0.007371724117547274,
-0.004501347430050373,
-0.0025873437989503145,
-0.001005868543870747,
0.006954571697860956,
-0.0033607417717576027,
0.0053968485444784164,
0.011097826063632965,
-0.0030896032694727182,
-0.007320881355553865,
0.0048731304705142975,
0.007406671531498432,
-0.0013207073789089918,
-0.001854207250289619,
-0.00013117492198944092,
0.007787417154759169,
0.005449466407299042,
0.0017667956417426467,
0.006371495313942432,
-0.0004708054184447974,
0.008202320896089077,
-0.0012803839053958654,
-0.0011592519003897905,
-0.005284999497234821,
0.0002358276688028127,
-0.0040760044939816,
-0.0001862475328380242,
-0.003615063149482012,
-0.0024835732765495777,
-0.01207983773201704,
-0.006353738717734814,
-0.002820482710376382,
-0.0016316313995048404,
0.004416084848344326,
-0.0026675856206566095,
0.0010648607276380062,
0.001752279233187437,
0.006703454069793224,
-0.00113702064845711,
-0.002740333089604974,
0.001259582000784576,
0.0028646658174693584,
-0.004151748027652502,
0.0138117466121912,
-0.010371416807174683,
0.007213928271085024,
-0.0016360982554033399,
-0.014438197948038578,
0.007142497692257166,
0.00964996125549078,
-0.007710786536335945,
0.0016946963733062148,
0.003357808105647564,
0.00264564692042768,
-0.0015560773899778724,
-0.004647789988666773,
-0.002677839482203126,
-0.01664816029369831,
0.0012789092725142837,
0.01801014505326748,
-0.00019037968013435602,
0.010222910903394222,
0.010432674549520016,
-0.0025296222884207964,
0.0013765848707407713,
0.005889597348868847,
0.0007859292672947049,
0.011844394728541374,
-0.007205771282315254,
-0.0011986989993602037,
0.00319352513179183,
-0.006650297436863184,
0.0010186623549088836,
0.004977608099579811,
0.0027685058303177357,
-0.002514737658202648,
0.0037774010561406612,
-0.007839233614504337,
-0.005800034385174513,
-0.020204519852995872,
-0.002465920289978385,
0.009120889008045197,
-0.002749945968389511,
0.00809474103152752,
-0.012955442070960999,
0.0037166005931794643,
0.003916197456419468,
0.004602942615747452,
-0.001009065774269402,
-0.0002327787078684196,
0.006064550019800663,
0.008498960174620152,
-0.005055159796029329,
0.0047723823226988316,
0.0032054479233920574,
-0.00179776712320745,
0.0003010363725479692,
0.008038460277020931,
-0.00549565302208066,
-0.007077051792293787,
0.0027562142349779606,
0.002529046032577753,
0.000745357247069478,
-0.003472220152616501,
-0.006725677754729986,
-0.0017654432449489832,
0.0026596561074256897,
-0.003500536782667041,
0.004937655758112669,
0.002292670775204897,
0.004258488770574331,
-0.005866969469934702,
0.0009919039439409971,
-0.004974663723260164,
-0.01181115210056305,
0.010824869386851788,
-0.0017542393179610372,
-0.0001541866222396493,
0.014365751296281815,
0.0018052818486467004,
-0.011875982396304607,
0.004101058002561331,
0.008672292344272137,
-0.002834407612681389,
0.003526127664372325,
0.006152071058750153,
-0.005296017043292522,
-0.021581945940852165,
-0.004416184965521097,
-0.014080852270126343,
0.006711140740662813,
-0.0022499109618365765,
0.0032439169008284807,
-0.006311843637377024,
0.008386938832700253,
0.004749933257699013,
-0.014773806557059288,
-0.005294107366353273,
-0.008171380497515202,
0.008456164039671421,
-0.0006292176549322903,
-0.00041124585550278425,
-0.004434033762663603,
-0.0008246447541750968,
-0.0019991190638393164,
-0.0031742851715534925,
-0.002156228059902787,
0.004283754155039787,
0.001813444891013205,
-0.0019245032453909516,
0.0039989841170609,
-0.006068146321922541,
0.0004301615117583424,
-0.00012205378152430058,
-0.011109648272395134,
0.0017016351921483874,
0.0017960728146135807,
-0.0014249255182221532,
-0.00337905902415514,
-0.0008245745557360351,
-0.001108594355173409,
-0.00800852756947279,
-0.01245263684540987,
-0.0045625315979123116,
-0.002320979256182909,
-0.0028465755749493837,
-0.011246600188314915,
-0.003156127640977502,
-0.006702435202896595,
0.0048538376577198505,
-0.006863343995064497,
0.005635790526866913,
0.005008609965443611,
-0.004972273483872414,
0.0063943020068109035,
0.0008497977978549898,
0.0029941857792437077,
0.004741947166621685,
0.004269437398761511,
0.0015027528861537576,
-0.0052874889224767685,
-0.012711860239505768,
0.010186734609305859,
-0.007745243608951569,
0.001839607721194625,
0.012913770042359829,
0.004569548647850752,
0.008846539072692394,
-0.0014034447958692908,
-0.0020130376797169447,
-0.00044690206414088607,
0.008372819982469082,
-0.014204774051904678,
0.0038435948081314564,
-0.00274498644284904,
-0.0007904345402494073,
0.0037063895724713802,
-0.002626926638185978,
0.0011197127168998122,
0.009207506664097309,
0.0034381358418613672,
-0.0068843974731862545,
-0.005153974052518606,
0.0037469430826604366,
0.004109641537070274,
-0.011502280831336975,
0.0010173323098570108,
-0.0036292155273258686,
-0.004869022406637669,
-0.0033071059733629227,
-0.002441745949909091,
-0.00006276948988670483,
0.002842671237885952,
-0.0010047514224424958,
0.007049465086311102,
0.003076913533732295,
-0.006005162838846445,
0.014408085495233536,
-0.006440929602831602,
-0.004100284073501825,
0.003089688252657652,
0.0025703059509396553,
-0.0027637924067676067,
-0.005488389637321234,
-0.003705679439008236,
0.0036350018344819546,
0.0072312806732952595,
-0.0012969182571396232,
-0.004741414915770292,
0.00006858963024569675,
-0.0008198483265005052,
-0.009848264046013355,
0.0005576745024882257,
0.010538074187934399,
-0.0021983084734529257,
0.005408076569437981,
-0.0030770523007959127,
-0.00845758430659771,
-0.014027511700987816,
0.05394360050559044,
0.00033714273013174534,
0.005150794051587582,
0.0035534847993403673,
-0.006559265311807394,
-0.0016785062616690993,
-0.0009747006115503609,
0.00862102024257183,
-0.0064767394214868546,
-0.005749073810875416,
0.009928138926625252,
-0.0010196032235398889,
0.005533400923013687,
0.004926055669784546,
-0.0011554340599104762,
0.016098206862807274,
-0.0013954380992799997,
-0.015485565178096294,
-0.015812905505299568,
0.008120052516460419,
-0.0057144309394061565,
-0.008242077194154263,
0.008654182776808739,
-0.005106352269649506,
-0.007180159445852041,
0.001174268894828856,
0.0049661933444440365,
0.002333851531147957,
-0.0013843827182427049,
-0.002304877620190382,
-0.002486552344635129,
-0.0005244974745437503,
0.0018738798098638654,
0.006624225992709398,
0.008226413279771805,
-0.003461194923147559,
0.004722755867987871,
-0.002495907014235854,
-0.0021897447295486927,
-0.0000887629939825274,
0.0034902947954833508,
0.006486896891146898,
-0.0016326240729540586,
-0.003444811562076211,
0.00599413039162755,
0.005066418554633856,
-0.0003099253517575562,
0.007174360565841198,
-0.001020405674353242,
-0.0075570871122181416,
0.005826864391565323,
0.007399249356240034,
-0.0013490081764757633,
0.009151805192232132,
-0.00029630865901708603,
0.003734684782102704,
0.003388111013919115,
-0.0075232707895338535,
-0.018669629469513893,
-0.004693220369517803,
0.005724335089325905,
0.008245863951742649,
-0.0010375474812462926,
0.002901714527979493,
-0.0016628277953714132,
-0.004155914764851332,
-0.007746596354991198,
-0.006099338177591562,
-0.004827252589166164,
0.0021034865640103817,
0.004977109842002392,
0.0687013566493988,
-0.00880676694214344,
-0.0016377524007111788,
-0.005844459403306246,
-0.0005024529527872801,
-0.001417428022250533,
0.0005178411956876516,
0.0008267554803751409,
-0.0025482550263404846,
0.002837956650182605,
-0.0035006278194487095,
-0.007369239814579487,
-0.010986843146383762,
-0.0016384086338803172,
0.0024852524511516094,
-0.004219201393425465,
0.0031255886424332857,
0.0048016333021223545,
-0.01048951968550682,
-0.0013335937401279807,
-0.013407931663095951,
-0.004101606085896492,
-0.0006691248272545636,
-0.009228618815541267,
-0.003802174935117364,
-0.0025303864385932684,
0.003739079460501671,
0.005129939876496792,
0.006140599027276039,
-0.0032156037632375956,
0.006743870675563812,
-0.0004735634720418602,
-0.0013805025955662131,
-0.007265686988830566,
-0.0011563764419406652,
-0.0025015883147716522,
0.007451178971678019,
0.0016027254750952125,
-0.010841887444257736,
-0.006601732689887285,
-0.00307224178686738,
0.0025793113745748997,
-0.0065498012118041515,
0.004332915414124727,
0.00011600270227063447,
0.00453738309442997,
-0.0021476398687809706,
-0.003363450989127159,
-0.0073797269724309444,
0.0031828037463128567,
-0.009184139780700207,
0.008431656286120415,
-0.1657164990901947,
0.007960397750139236,
0.00613704277202487,
-0.003605840727686882,
-0.002167552476748824,
-0.018443698063492775,
-0.0036907666362822056,
0.0028954569716006517,
0.009614036418497562,
0.0003244686231482774,
-0.0023466323036700487,
-0.0023464795667678118,
0.005836064461618662,
0.004053500946611166,
-0.003167659044265747,
-0.004882334731519222,
0.002279347972944379,
-0.0036103399470448494,
0.00003871087028528564,
0.004407139029353857,
0.004052179399877787,
0.010123636573553085,
0.001977616688236594,
0.0030121426098048687,
-0.002136758528649807,
-0.0056533110328018665,
0.006326555740088224,
-0.00215781107544899,
0.0035536193754523993,
-0.012240544892847538,
-0.0035676700063049793,
-0.002383969258517027,
-0.004544862546026707,
-0.0005985759198665619,
0.005966757889837027,
0.0002439417876303196,
0.011161704547703266,
0.005299003329128027,
-0.006499673239886761,
0.00726059265434742,
-0.009345663711428642,
0.02519465610384941,
0.005690467543900013,
0.005486240144819021,
-0.0012273663887754083,
-0.004510118160396814,
-0.00594572676345706,
0.008120475336909294,
0.0005256119766272604,
0.010443545877933502,
-0.012196865864098072,
0.00015557989536318928,
0.003933408297598362,
0.016909964382648468,
-0.005288145504891872,
-0.009757491759955883,
-0.005832782480865717,
-0.0012665545800700784,
0.00007352219836320728,
0.006598242558538914,
0.009756905026733875,
-0.003756569465622306,
0.007585618644952774,
-0.0032142384443432093,
-0.01852688565850258,
0.0033611657563596964,
-0.005106768570840359,
-0.008875272236764431,
0.002409272827208042,
0.007232889998704195,
0.010022376663982868,
0.0016437784070149064,
0.0038199308328330517,
-0.002184963785111904,
0.008272649720311165,
0.0003299992240499705,
0.007441319990903139,
-0.0008872028556652367,
0.00602882681414485,
-0.009038159623742104,
0.007144401781260967,
-0.010877939872443676,
-0.002662553684785962,
0.0014008086873218417,
-0.0031802747398614883,
0.01292248722165823,
0.00243384693749249,
-0.0019148529972881079,
-0.0002272766432724893,
-0.00936486478894949,
-0.002062988467514515,
0.002706181723624468,
0.0014570151688531041,
-0.008035295642912388,
0.0035558207891881466,
-0.00013783641043119133,
0.007756711915135384,
0.0075982301495969296,
-0.010410105809569359,
0.007815548218786716,
0.006219176109880209,
-0.0036610595416277647,
0.001013597589917481,
-0.005857020616531372,
0.002872296143323183,
0.002407429041340947,
-0.003300304990261793,
-0.0044281198643147945,
0.005075834691524506,
-0.004940972197800875,
-0.002532358281314373,
0.006287454627454281,
-0.009922497905790806,
-0.008367781527340412,
-0.003542277729138732,
-0.010065545327961445,
-0.001874555367976427
] |
8a2d310413da9e85779ff39fa32f7bd2c4075553 | 8,648 | py | Python | test/countries/test_united_states.py | OmoMicheal/marketanalysis | ddc2476ec918a28658e64574e89d8944cee75617 | [
"MIT"
] | 2 | 2021-06-29T21:56:15.000Z | 2022-02-17T22:10:55.000Z | test/countries/test_united_states.py | OmoMicheal/marketanalysis | ddc2476ec918a28658e64574e89d8944cee75617 | [
"MIT"
] | null | null | null | test/countries/test_united_states.py | OmoMicheal/marketanalysis | ddc2476ec918a28658e64574e89d8944cee75617 | [
"MIT"
] | null | null | null | # -*- coding: utf-8 -*-
# marketanalysis
# ----------------
# A fast, efficient Python library for generating country, province and state
# specific sets of marketmarketholidayss on the fly. It aims to make determining whether a
# specific date is a holiday as fast and flexible as possible.
#
# Author: MichealOmojola <momojola@aust.edu.ng>
# Website: https://github.com/OmoMicheal/trading_days
# License: MIT (see LICENSE file)
# Version: 0.1 (April 7, 2021)
import unittest
from datetime import date
from dateutil.relativedelta import relativedelta
# import sys
# sys.path.insert(0, 'C:/Users/momojola/projects/marketanalysis/marketanalysis/')
from marketanalysis import marketholidays
from marketanalysis import markettradingdays
class TestUS(unittest.TestCase):
def setUp(self):
self.marketholidayss = marketholidays.USA(observed=False)
self.markettradingdayss = markettradingdays.USA()
def test_new_years(self):
self.assertNotIn(date(2010, 12, 31), self.marketholidayss)
self.assertNotIn(date(2017, 1, 2), self.marketholidayss)
self.marketholidayss.observed = True
self.assertIn(date(2010, 12, 31), self.marketholidayss)
self.assertIn(date(2017, 1, 2), self.marketholidayss)
self.marketholidayss.observed = False
for year in range(1900, 2100):
dt = date(year, 1, 1)
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
def test_martin_luther(self):
for dt in [
date(1986, 1, 20),
date(1999, 1, 18),
date(2000, 1, 17),
date(2012, 1, 16),
date(2013, 1, 21),
date(2014, 1, 20),
date(2015, 1, 19),
date(2016, 1, 18),
date(2020, 1, 20),
]:
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
def test_washingtons_birthday(self):
de_marketholidayss = marketholidays.US()
for dt in [
date(1969, 2, 22),
date(1970, 2, 22),
date(1971, 2, 15),
date(1997, 2, 17),
date(1999, 2, 15),
date(2000, 2, 21),
date(2012, 2, 20),
date(2013, 2, 18),
date(2014, 2, 17),
date(2015, 2, 16),
date(2016, 2, 15),
date(2020, 2, 17),
]:
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
self.assertIn(dt, de_marketholidayss)
self.assertEqual(marketholidays.US().get("2015-02-16"), "Presidents' Day")
def test_good_friday(self):
marketholidayss_US = marketholidays.US()
for dt in [
date(1900, 4, 13),
date(1901, 4, 5),
date(1902, 3, 28),
date(1999, 4, 2),
date(2000, 4, 21),
date(2010, 4, 2),
date(2018, 3, 30),
date(2019, 4, 19),
date(2020, 4, 10),
]:
self.assertIn(dt, self.marketholidayss)
self.assertIn(dt, marketholidayss_US)
def test_memorial_day(self):
for dt in [
date(1969, 5, 30),
date(1970, 5, 30),
date(1971, 5, 31),
date(1997, 5, 26),
date(1999, 5, 31),
date(2000, 5, 29),
date(2012, 5, 28),
date(2013, 5, 27),
date(2014, 5, 26),
date(2015, 5, 25),
date(2016, 5, 30),
date(2020, 5, 25),
]:
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
def test_independence_day(self):
for year in range(1900, 2100):
dt = date(year, 7, 4)
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
self.assertNotIn(date(2010, 7, 5), self.marketholidayss)
self.assertNotIn(date(2020, 7, 3), self.marketholidayss)
self.marketholidayss.observed = True
self.assertIn(date(2010, 7, 5), self.marketholidayss)
self.assertIn(date(2020, 7, 3), self.marketholidayss)
def test_labor_day(self):
for dt in [
date(1997, 9, 1),
date(1999, 9, 6),
date(2000, 9, 4),
date(2012, 9, 3),
date(2013, 9, 2),
date(2014, 9, 1),
date(2015, 9, 7),
date(2016, 9, 5),
date(2020, 9, 7),
]:
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
def test_thanksgiving_day(self):
for dt in [
date(1997, 11, 27),
date(1999, 11, 25),
date(2000, 11, 23),
date(2012, 11, 22),
date(2013, 11, 28),
date(2014, 11, 27),
date(2015, 11, 26),
date(2016, 11, 24),
date(2020, 11, 26),
]:
self.assertNotIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
def test_christmas_eve(self):
as_marketholidayss = marketholidays.US()
self.marketholidayss.observed = False
for year in range(1900, 2050):
self.assertNotIn(date(year, 12, 24), self.marketholidayss)
# self.assertIn(date(year, 12, 24), as_marketholidayss)
self.assertNotIn(date(2016, 12, 23), as_marketholidayss)
self.assertNotIn(
"Christmas Eve (Observed)",
as_marketholidayss.get_list(date(2017, 12, 22)),
)
def test_christmas_day(self):
for year in range(1900, 2100):
dt = date(year, 12, 25)
self.assertIn(dt, self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=-1), self.marketholidayss)
self.assertNotIn(dt + relativedelta(days=+1), self.marketholidayss)
self.assertNotIn(date(2010, 12, 24), self.marketholidayss)
self.assertNotIn(date(2016, 12, 26), self.marketholidayss)
self.marketholidayss.observed = True
self.assertIn(date(2010, 12, 24), self.marketholidayss)
self.assertIn(date(2016, 12, 26), self.marketholidayss)
def test_day_after_christmas(self):
nc_marketholidayss = marketholidays.US(observed=False)
self.assertNotIn(date(2015, 12, 28), nc_marketholidayss)
self.assertNotIn(date(2016, 12, 27), nc_marketholidayss)
nc_marketholidayss.observed = True
def test_new_years_eve(self):
ky_marketholidayss = marketholidays.US()
self.assertNotIn(date(2012, 12, 31), ky_marketholidayss)
for dt in [date(2013, 12, 31), date(2016, 12, 30)]:
self.assertNotIn(dt, self.marketholidayss)
self.assertNotIn(dt, ky_marketholidayss)
def test_future_list(self):
current_date = '2021-04-13'
lookup_step = 10
self.assertIn(date(2021, 4, 16), self.markettradingdayss.future_list(current_date, lookup_step))
self.assertNotIn(date(2021, 4, 18), self.markettradingdayss.future_list(current_date, lookup_step))
def test_prevDays(self):
current_date = '2021-04-13'
lookback_step = 4
self.assertIn(date(2021, 4, 9), self.markettradingdayss.prevDays(current_date, lookback_step))
self.assertNotIn(date(2021, 4, 11), self.markettradingdayss.prevDays(current_date, lookback_step))
def test_BtwDates(self):
current_date = '2021-04-13'
future_date = '2021-04-20'
self.assertIn(date(2021, 4, 15), self.markettradingdayss.BtwDates(current_date, future_date))
self.assertNotIn(date(2021, 4, 18), self.markettradingdayss.BtwDates(current_date, future_date))
# if __name__ == "__main__":
# unittest.main() | 38.096916 | 107 | 0.591929 | 1 | 2.4441 | [
-0.037612564861774445,
0.020635949447751045,
0.05966561287641525,
-0.005943977274000645,
0.04428081214427948,
0.03831864893436432,
-0.03666774556040764,
0.010701456107199192,
-0.05286489799618721,
0.02301681414246559,
0.013417521491646767,
0.005602313205599785,
-0.013793090358376503,
0.024708976969122887,
-0.00869471114128828,
-0.011818940751254559,
0.04356750473380089,
-0.03155437856912613,
-0.02236791141331196,
-0.01236829161643982,
-0.009802787564694881,
-0.039221711456775665,
0.019561108201742172,
-0.03154049441218376,
-0.02947569265961647,
0.034725625067949295,
0.03971431404352188,
-0.00910454522818327,
-0.004507986828684807,
-0.003487261477857828,
-0.011547498404979706,
-0.008306162431836128,
0.0031967086251825094,
0.01113579049706459,
-0.016876326873898506,
0.02126811444759369,
0.006428440101444721,
0.01435366552323103,
0.008610296063125134,
0.018623732030391693,
0.006325494963675737,
-0.01013993564993143,
0.01953030377626419,
-0.0340268574655056,
-0.01723329909145832,
-0.015112452208995819,
0.017360148951411247,
-0.031238915398716927,
-0.02420366369187832,
-0.004995923954993486,
-0.07402044534683228,
-0.04381224140524864,
0.020663978531956673,
-0.010031912475824356,
-0.00802706927061081,
-0.015097223222255707,
0.010396318510174751,
0.068683922290802,
0.004738315474241972,
0.03249245882034302,
-0.009759177453815937,
0.016554031521081924,
0.02965293452143669,
-0.00837129820138216,
0.025061411783099174,
-0.01813356764614582,
-0.030855368822813034,
-0.01230502501130104,
0.019009536132216454,
0.03837067633867264,
0.009586811065673828,
0.006286739371716976,
0.045692600309848785,
0.006251902785152197,
0.018770890310406685,
0.0002885714056901634,
-0.015670480206608772,
-0.005760851316154003,
-0.026463039219379425,
0.02157409116625786,
-0.03757689893245697,
0.0027836605440825224,
0.023283565416932106,
-0.010208376683294773,
-0.023774508386850357,
0.031818605959415436,
0.04667279124259949,
-0.02598641626536846,
0.03378206118941307,
-0.017940079793334007,
-0.030708100646734238,
-0.013834139332175255,
-0.005369703285396099,
-0.018175747245550156,
-0.023250173777341843,
-0.033998746424913406,
0.008317781612277031,
0.022770801559090614,
-0.024311073124408722,
0.0319642573595047,
0.014313851483166218,
-0.014028550125658512,
0.006103808525949717,
-0.02074563130736351,
-0.030414627864956856,
-0.029855914413928986,
0.006897741463035345,
-0.004162286873906851,
-0.01718546636402607,
-0.034085385501384735,
-0.007599147502332926,
-0.021463358774781227,
-0.006563358940184116,
-0.0428779162466526,
0.0231323204934597,
-0.020807679742574692,
0.02691563032567501,
-0.010318223387002945,
0.010371142067015171,
0.026199331507086754,
0.04698396101593971,
-0.01591588743031025,
-0.001797105767764151,
-0.04462871700525284,
-0.012236095033586025,
0.06991958618164062,
-0.0446426086127758,
0.014238467440009117,
0.003486637258902192,
-0.00677106250077486,
-0.014397213235497475,
0.03154272586107254,
-0.006597819272428751,
-0.014088005758821964,
0.02706136181950569,
0.0024035393726080656,
0.01314540021121502,
0.00018968306540045887,
-0.022126594558358192,
-0.0013028623070567846,
-0.006418900564312935,
-0.010084806010127068,
0.025572851300239563,
-0.019746435806155205,
-0.004321192391216755,
-0.020641492679715157,
-0.018682777881622314,
0.0009645149693824351,
-0.0016592239262536168,
-0.023491229861974716,
-0.00801684521138668,
-0.000438413058873266,
-0.007520067039877176,
0.03614523261785507,
0.019987598061561584,
0.017917277291417122,
-0.006703126709908247,
0.02844717912375927,
0.02715357020497322,
0.005960321053862572,
-0.016305528581142426,
0.004453996662050486,
0.021224141120910645,
-0.008510415442287922,
-0.04593391343951225,
0.035966627299785614,
0.01031122449785471,
0.05315199866890907,
-0.007728068623691797,
-0.012481778860092163,
0.019249580800533295,
-0.0161537304520607,
0.009100111201405525,
0.014886630699038506,
-0.07318403571844101,
0.035318128764629364,
0.016307614743709564,
0.02124929614365101,
0.01119630504399538,
-0.0013811786193400621,
0.009748932905495167,
-0.015670953318476677,
0.01329532079398632,
0.057655807584524155,
-0.002338293706998229,
-0.0325867123901844,
-0.04550771415233612,
-0.02162347361445427,
-0.017327511683106422,
-0.017798619344830513,
0.026888327673077583,
0.025735948234796524,
0.05386151745915413,
-0.011477096937596798,
0.023412588983774185,
-0.013528973795473576,
0.032780032604932785,
0.024582793936133385,
-0.027435382828116417,
-0.010628779418766499,
-0.019882380962371826,
-0.005715861916542053,
-0.029628373682498932,
0.03014911711215973,
-0.017922259867191315,
0.0055463179014623165,
-0.6889033317565918,
-0.0088889691978693,
0.009252380579710007,
0.01629267819225788,
0.026593992486596107,
0.019655967131257057,
-0.03207230567932129,
-0.0008545016753487289,
-0.0003788615285884589,
-0.006915985140949488,
-0.008365226909518242,
0.013015126809477806,
0.010852012783288956,
0.012683128006756306,
0.011468745768070221,
-0.00025515773450024426,
0.056016940623521805,
0.006280809640884399,
-0.039597637951374054,
0.0035233518574386835,
0.012838119640946388,
-0.07865819334983826,
-0.006036592647433281,
0.014949020929634571,
-0.06075633317232132,
0.025523781776428223,
0.01375711988657713,
-0.057318415492773056,
0.027213549241423607,
0.00013812094402965158,
-0.009087824262678623,
-0.012727852910757065,
0.01776360347867012,
0.011108401231467724,
-0.016048237681388855,
0.027033334597945213,
0.0023131207562983036,
-0.023370739072561264,
-0.004177169408649206,
0.007099757436662912,
0.009224294684827328,
-0.02856295183300972,
0.03483167290687561,
-0.04330884665250778,
-0.023217815905809402,
-0.027132004499435425,
0.04041518270969391,
0.02408609353005886,
-0.0004273315134923905,
-0.022691288962960243,
-0.0047333743423223495,
0.03878636658191681,
-0.009555499069392681,
-0.0008250034297816455,
0.02030465193092823,
-0.0071325176395475864,
0.045577552169561386,
0.014393891207873821,
0.010054798796772957,
-0.033752016723155975,
0.04091351479291916,
0.0025643431581556797,
-0.013484712690114975,
-0.032562654465436935,
-0.06062604859471321,
-0.0035707519855350256,
-0.01868431828916073,
-0.015364227816462517,
-0.03861561417579651,
0.002401163801550865,
-0.0025858483277261257,
-0.01857413910329342,
-0.040558602660894394,
0.009638339281082153,
-0.04004441574215889,
0.010502214543521404,
-0.016553353518247604,
-0.004889811854809523,
0.02123761735856533,
-0.02152198925614357,
-0.010751500725746155,
-0.004629123955965042,
0.021884769201278687,
-0.0236075259745121,
0.01900629885494709,
-0.014968344941735268,
-0.0038207864854484797,
-0.0022268882021307945,
-0.009418733417987823,
0.016492271795868874,
0.05704030767083168,
0.00536639429628849,
0.018243471160531044,
0.02690359205007553,
-0.001473903888836503,
0.002761643845587969,
-0.03149014711380005,
0.03023763932287693,
0.024471843615174294,
-0.002152110682800412,
0.03496694937348366,
-0.008345723152160645,
-0.03458814695477486,
-0.01905898191034794,
-0.04426610842347145,
-0.0014366509858518839,
-0.03302490711212158,
-0.027786314487457275,
0.0026703260373324156,
-0.04479963332414627,
-0.0003846338076982647,
-0.024000659584999084,
-0.033021267503499985,
0.04868679121136665,
0.0018676483305171132,
-0.030987927690148354,
0.029177531599998474,
0.010731385089457035,
0.02271835319697857,
0.006760747637599707,
-0.020985955372452736,
-0.01624361425638199,
-0.03188952058553696,
0.03836725279688835,
-0.03530952334403992,
-0.027339698746800423,
-0.05276554077863693,
-0.020420808345079422,
0.020929107442498207,
0.03763943165540695,
-0.008838217705488205,
0.010745108127593994,
-0.007814801298081875,
0.007360693067312241,
0.02129867859184742,
-0.022316528484225273,
-0.015046216547489166,
-0.016394497826695442,
0.04094728082418442,
-0.0026448597200214863,
0.021898100152611732,
0.025852935388684273,
0.025178777053952217,
-0.03941633924841881,
0.012734479270875454,
-0.009034257382154465,
0.03365349769592285,
0.0275165606290102,
0.0784815102815628,
-0.009896633215248585,
-0.0002797932247631252,
0.05897993966937065,
0.015210030600428581,
0.014283137395977974,
-0.0034383463207632303,
0.006570726167410612,
-0.007829387672245502,
-0.009175929240882397,
0.022386567667126656,
0.04015357792377472,
0.008462515659630299,
-0.006660705432295799,
-0.022239437326788902,
-0.009992252103984356,
0.01643412560224533,
0.007169224787503481,
-0.017083793878555298,
0.025795642286539078,
-0.011882425285875797,
0.002640634309500456,
0.05936632305383682,
-0.0008301619091071188,
-0.003353437874466181,
0.003956211265176535,
-0.007397940848022699,
-0.021354490891098976,
-0.010928099974989891,
0.022193675860762596,
-0.06684788316488266,
-0.011724619194865227,
0.06441059708595276,
0.01393168419599533,
0.04712986573576927,
-0.006200606003403664,
0.0006286613061092794,
0.04159141331911087,
0.009520909748971462,
0.0061653791926801205,
0.005337798036634922,
0.0005616754060611129,
-0.009665161371231079,
0.0056934654712677,
-0.05091796815395355,
0.027433067560195923,
-0.05192215368151665,
0.0038383908104151487,
-0.04670865833759308,
0.05083582550287247,
0.04139824956655502,
0.009251432493329048,
-0.038087040185928345,
-0.032741911709308624,
0.012924594804644585,
-0.008908797986805439,
-0.022561581805348396,
0.10040581971406937,
0.015845436602830887,
0.018355360254645348,
0.02139904722571373,
-0.00476418249309063,
-0.01076264213770628,
-0.047452639788389206,
0.010883886367082596,
0.00757202785462141,
-0.04376065731048584,
0.022448033094406128,
0.009871034882962704,
0.028766803443431854,
-0.04892323538661003,
-0.01566954515874386,
0.004456132184714079,
-0.027291901409626007,
-0.018841790035367012,
-0.01466323807835579,
-0.012369022704660892,
0.005219888407737017,
-0.0010356658603996038,
0.008966578170657158,
-0.012711772695183754,
0.012236128561198711,
-0.02902333438396454,
-0.0022543359082192183,
0.019843243062496185,
-0.008634882979094982,
-0.01566212624311447,
0.03379801660776138,
-0.006017378997057676,
-0.007044777274131775,
-0.028765397146344185,
0.031691376119852066,
-0.012633927166461945,
-0.031097376719117165,
-0.03352507948875427,
-0.0031299516558647156,
0.0028338655829429626,
0.028156429529190063,
0.002343149157240987,
-0.00737581355497241,
-0.01283184438943863,
0.01069045253098011,
0.027881942689418793,
0.0323621891438961,
-0.0027541439048945904,
0.007998512126505375,
0.0017212630482390523,
0.08237351477146149,
0.004529597703367472,
0.01383636798709631,
0.00834388006478548,
-0.026814887300133705,
0.021473083645105362,
-0.0016903807409107685,
-0.03389301896095276,
-0.02269533835351467,
-0.011136144399642944,
-0.02620035596191883,
0.0046315607614815235,
-0.08579327911138535,
0.0060500819236040115,
0.03988683223724365,
0.0025162934325635433,
-0.012819784693419933,
-0.03964687138795853,
-0.01781611517071724,
0.025444986298680305,
-0.004815511405467987,
0.00546760018914938,
0.007984312251210213,
-0.018541187047958374,
-0.008554641157388687,
-0.043180160224437714,
-0.010182834230363369,
0.009731900878250599,
0.030632158741354942,
-0.009533995762467384,
0.002478370675817132,
0.016386745497584343,
-0.009849168360233307,
-0.03370847553014755,
-0.010822589509189129,
0.010489024221897125,
-0.020815594121813774,
0.018344027921557426,
0.04024885594844818,
0.007514470256865025,
-0.014406375586986542,
-0.0033634069841355085,
0.033058010041713715,
0.02490062080323696,
0.019579976797103882,
-0.0007304701139219105,
-0.04350801184773445,
0.003684306750074029,
-0.05905647948384285,
0.0032669950742274523,
0.020970676094293594,
0.01874709129333496,
-0.010629995726048946,
0.023865075781941414,
-0.007977484725415707,
0.015703978016972542,
0.008458154276013374,
0.009506325237452984,
0.05655227228999138,
-0.004768294282257557,
0.03921277076005936,
0.004554725717753172,
0.016836419701576233,
0.033601317554712296,
-0.00109260028693825,
0.004462042357772589,
0.032401613891124725,
-0.005473368335515261,
0.01064358837902546,
0.006618426647037268,
-0.023482518270611763,
0.005129537545144558,
-0.017491109669208527,
0.03353416919708252,
-0.028679508715867996,
-0.013909053057432175,
-0.004814818501472473,
0.005736844148486853,
0.0022801505401730537,
0.033229053020477295,
-0.03655030205845833,
-0.024914871901273727,
0.03527862951159477,
0.03899858519434929,
0.01739121787250042,
0.017884962260723114,
0.01296269055455923,
-0.02690763771533966,
0.005381574388593435,
-0.025052456185221672,
0.017216073349118233,
-0.0066172340884804726,
0.03290235996246338,
0.022943740710616112,
-0.018607739359140396,
0.012560040690004826,
-0.035827722400426865,
-0.04099152982234955,
0.0066698151640594006,
-0.023016640916466713,
-0.012333383783698082,
-0.0005631818203255534,
-0.008508500643074512,
0.04679267480969429,
-0.04128080978989601,
0.00037401486770249903,
0.007977241650223732,
-0.053128037601709366,
0.003204196924343705,
0.021778292953968048,
-0.006630467250943184,
0.011641704477369785,
-0.05238856375217438,
0.0024769490119069815,
-0.020977739244699478,
-0.016407638788223267,
0.00194443145301193,
-0.022813603281974792,
0.015192393213510513,
0.008444029837846756,
-0.009045124053955078,
-0.0175075214356184,
-0.00023601482098456472,
0.006600863765925169,
-0.004188333638012409,
0.010944261215627193,
-0.03254201263189316,
-0.010895024985074997,
-0.006625339388847351,
0.0029268963262438774,
-0.01645905338227749,
0.029450563713908195,
-0.008156020194292068,
0.02082451619207859,
0.022360052913427353,
0.005473449360579252,
-0.006961762439459562,
0.0008890649187378585,
0.04430403932929039,
-0.002637732308357954,
0.004798367619514465,
0.001591096050105989,
-0.005115414038300514,
0.012896006926894188,
-0.0008720387704670429,
-0.02287532575428486,
0.032473307102918625,
0.0175626277923584,
-0.002337508136406541,
-0.027207253500819206,
-0.042558468878269196,
0.04831356182694435,
0.029654715210199356,
-0.0005366661353036761,
-0.008718547411262989,
-0.02807522751390934,
0.0019476672168821096,
-0.06574127078056335,
-0.023334883153438568,
0.03318819776177406,
0.020934350788593292,
-0.011274811811745167,
0.017803139984607697,
-0.009619579650461674,
0.02134620025753975,
0.019602680578827858,
0.032760921865701675,
-0.021672019734978676,
0.025594163686037064,
-0.026541491970419884,
-0.009347014129161835,
0.0024796256329864264,
-0.007298228330910206,
-0.003392858197912574,
-0.020728962495923042,
0.011372755281627178,
-0.024896666407585144,
-0.043599046766757965,
-0.011609419248998165,
0.029179181903600693,
0.006407076958566904,
-0.011543616652488708,
-0.031012438237667084,
-0.014335586689412594,
0.0026712839026004076,
-0.051734451204538345,
-0.019977478310465813,
-0.003956046886742115,
0.03150864690542221,
-0.04220433905720711,
-0.12417639046907425,
0.012031146325170994,
0.016988106071949005,
-0.011861142702400684,
0.007195251528173685,
-0.0370209626853466,
-0.000008255040484073106,
0.010029943659901619,
0.026787472888827324,
0.010502759367227554,
-0.024683227762579918,
0.016545379534363747,
0.03610642999410629,
0.058315277099609375,
-0.01347661018371582,
-0.024678820744156837,
-0.03580912575125694,
0.0026634125970304012,
0.01019227597862482,
-0.0006452666711993515,
0.039903413504362106,
0.015800002962350845,
-0.024993102997541428,
-0.0009991622064262629,
-0.014773670583963394,
-0.06280435621738434,
0.000803325092419982,
-0.022797882556915283,
-0.0027124204207211733,
-0.047599319368600845,
-0.008714048191905022,
0.0023332792334258556,
0.056345902383327484,
-0.016309719532728195,
0.01131454762071371,
-0.00938404630869627,
0.01869916170835495,
0.02554514817893505,
-0.02405250445008278,
-0.029489783570170403,
-0.02802702784538269,
-0.030586136505007744,
0.04622289910912514,
-0.01365440059453249,
-0.0092645063996315,
-0.023919684812426567,
-0.00004695640382124111,
0.00985008291900158,
-0.031832870095968246,
-0.006092576775699854,
-0.07422001659870148,
0.03580315783619881,
0.020596005022525787,
0.0518912710249424,
0.004700453951954842,
0.042985908687114716,
0.001968497410416603,
-0.002761684823781252,
-0.06683478504419327,
0.013813992962241173,
0.035884078592061996,
0.025093497708439827,
0.017465664073824883,
-0.013330858200788498,
-0.01612144336104393,
-0.0032536506187170744,
-0.022555900737643242,
-0.04667338728904724,
0.04113530367612839,
0.019076576456427574,
0.022977614775300026,
0.03511793911457062,
0.02427077107131481,
-0.006310812197625637,
-0.02688126266002655,
0.0025234129279851913,
0.023765364661812782,
0.013090983033180237,
0.003009956795722246,
-0.011166795156896114,
0.045637913048267365,
-0.03328540548682213,
0.011428182013332844,
0.00395567249506712,
0.034380652010440826,
0.01566016860306263,
-0.025510836392641068,
-0.022522317245602608,
0.009625914506614208,
0.05177758261561394,
-0.07243276387453079,
-0.00714649586006999,
0.03029673919081688,
-0.0014999982668086886,
-0.015200626105070114,
0.01941646821796894,
0.013517250306904316,
0.011724363081157207,
-0.00644342415034771,
-0.024098621681332588,
-0.020563917234539986,
0.037426866590976715,
-0.003166726091876626,
0.013249163515865803,
0.05509006977081299,
-0.03229590877890587,
-0.044512126594781876,
0.0052567701786756516,
-0.005961569491773844,
-0.03530304133892059,
-0.025046331807971,
-0.00175414455588907,
0.0437455028295517,
-0.0018457400146871805,
-0.0003832248621620238,
0.007236950099468231,
0.01641288958489895
] |
8a2e82e1a97d54e2d6df29004c910ab7dc7dda4f | 344 | py | Python | src/ros_comm/rosmsg/setup.py | jungleni/ros_code_reading | 499e98c0b0d309da78060b19b55c420c22110d65 | [
"Apache-2.0"
] | 742 | 2017-07-05T02:49:36.000Z | 2022-03-30T12:55:43.000Z | src/ros_comm/rosmsg/setup.py | jungleni/ros_code_reading | 499e98c0b0d309da78060b19b55c420c22110d65 | [
"Apache-2.0"
] | 73 | 2017-07-06T12:50:51.000Z | 2022-03-07T08:07:07.000Z | src/ros_comm/rosmsg/setup.py | jungleni/ros_code_reading | 499e98c0b0d309da78060b19b55c420c22110d65 | [
"Apache-2.0"
] | 425 | 2017-07-04T22:03:29.000Z | 2022-03-29T06:59:06.000Z | #!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['rosmsg'],
package_dir={'': 'src'},
scripts=['scripts/rosmsg', 'scripts/rosmsg-proto', 'scripts/rossrv'],
requires=['genmsg', 'rosbag', 'roslib', 'rospkg']
)
setup(**d)
| 24.571429 | 73 | 0.700581 | 1 | 0.7551 | [
-0.0013547491980716586,
0.0218539759516716,
0.006544872187077999,
0.0006323120323941112,
0.0030466734897345304,
-0.002212462481111288,
-0.008718176744878292,
0.0013209378812462091,
-0.009337007999420166,
-0.0021149630192667246,
0.0027124485932290554,
0.004936779383569956,
0.008073508739471436,
-0.01891809143126011,
0.0028462756890803576,
0.0168338343501091,
-0.05914955213665962,
0.0014301217161118984,
-0.000057504621508996934,
0.0034710364416241646,
-0.00913488119840622,
0.010825357399880886,
0.006540869362652302,
0.009614525362849236,
0.005648225080221891,
0.0018693736055865884,
0.00826283823698759,
0.00421220064163208,
-0.010913927108049393,
-0.0084394421428442,
0.0007442454807460308,
-0.000015574496501358226,
-0.0059370663948357105,
-0.009356984868645668,
0.0044643268920481205,
-0.0035982539411634207,
-0.0014452224131673574,
-0.01943395286798477,
0.01341476384550333,
-0.005684410687536001,
-0.007622813805937767,
-0.01919878087937832,
0.0030968147329986095,
0.007105976343154907,
-0.012219898402690887,
0.0018449184717610478,
-0.003289927262812853,
0.005573438014835119,
-0.008251376450061798,
0.008782971650362015,
-0.0091664157807827,
0.006718936841934919,
0.015333336777985096,
0.0037321129348129034,
-0.007465635426342487,
-0.006530305370688438,
0.010317577980458736,
0.00102634122595191,
-0.010997919365763664,
0.001918797381222248,
-0.0034113784786313772,
0.00043301386176608503,
0.003686601063236594,
0.006760053336620331,
-0.01722905784845352,
-0.004910026676952839,
-0.004151697736233473,
-0.0012536925496533513,
-0.0026897608768194914,
0.005158879328519106,
-0.0008763761725276709,
-0.0009496918064542115,
0.005699541885405779,
-0.00023695909476373345,
0.005601052660495043,
-0.0027753759641200304,
-0.0007622086559422314,
0.0020120565313845873,
0.00803340319544077,
0.002504257019609213,
0.0052483766339719296,
-0.007846645079553127,
0.0038552009500563145,
0.013319774530827999,
0.015248574316501617,
0.009396146051585674,
0.015906546264886856,
-0.010044940747320652,
0.042687706649303436,
0.004687024280428886,
-0.011277670040726662,
-0.002094494178891182,
-0.008349938318133354,
-0.004028647672384977,
-0.0031750930938869715,
-0.029877351596951485,
-0.00037529386463575065,
-0.004652251489460468,
-0.0008972554351203144,
0.003671441925689578,
0.0006040525040589273,
0.004278426058590412,
-0.003491166513413191,
-0.0018994081765413284,
-0.012081668712198734,
0.015208026394248009,
-0.008567954413592815,
0.0004653866053558886,
0.007238425314426422,
0.002238326473161578,
-0.0121666444465518,
-0.0005954995285719633,
0.0027496367692947388,
-0.012217842042446136,
0.002289040479809046,
0.0012140352046117187,
-0.011001874692738056,
0.05554971843957901,
0.0014061228139325976,
0.004415661562234163,
-0.0027459466364234686,
-0.00007696859393035993,
-0.0012685179244726896,
0.009369940496981144,
0.012280093505978584,
-0.0047987536527216434,
0.010166042484343052,
0.007461412809789181,
0.0019248815951868892,
0.007319158408790827,
-0.0012379181571304798,
0.006774570792913437,
-0.0020904431585222483,
-0.0022898432798683643,
0.0011017053620889783,
-0.006328556686639786,
0.00955275259912014,
-0.0020320452749729156,
-0.00872940756380558,
0.0013378889998421073,
-0.0031548289116472006,
-0.010747438296675682,
0.0028165520634502172,
-0.0026984172873198986,
0.004164926707744598,
-0.011723237112164497,
-0.004803288262337446,
-0.000818891276139766,
-0.0016057002358138561,
0.0007668799953535199,
0.007246905006468296,
0.005143911577761173,
0.002950838068500161,
-0.006089275237172842,
-0.00565836438909173,
-0.0033375939819961786,
-0.002171618165448308,
0.004423338919878006,
0.009888299740850925,
0.0033752024173736572,
-0.008765988983213902,
-0.0040296753868460655,
0.0073293233290314674,
0.006257154513150454,
-0.0035133427008986473,
0.0030398524831980467,
-0.005251014139503241,
0.009146703407168388,
0.00323378574103117,
0.0019163131946697831,
0.012929188087582588,
-0.002100803889334202,
-0.0025292213540524244,
0.002235202118754387,
0.005859283730387688,
0.0020432190503925085,
0.005533409304916859,
0.0091831274330616,
-0.001875378075055778,
-0.004001291934400797,
0.004318753723055124,
0.005578945390880108,
0.0080146174877882,
0.012237640097737312,
-0.0037445456255227327,
0.0030068845953792334,
0.0002540075802244246,
-0.0010300553403794765,
0.005802018102258444,
-0.005927256774157286,
0.006775607354938984,
0.006093316711485386,
-0.017431342974305153,
-0.00709069799631834,
0.00010210015898337588,
-0.011131037957966328,
0.0015541744651272893,
0.01386647392064333,
0.010798330418765545,
-0.0012218257179483771,
0.0026245680637657642,
-0.006911327131092548,
-0.00034782636794261634,
0.009862970560789108,
-0.002747670281678438,
-0.01192599069327116,
-0.9561434388160706,
0.004390307702124119,
0.001872338354587555,
-0.0024674648884683847,
0.004194455221295357,
0.0019014985300600529,
0.0046689617447555065,
0.002916682045906782,
0.011791606433689594,
-0.007499036379158497,
-0.006822647992521524,
-0.005677787587046623,
-0.011348998174071312,
-0.00020758734899573028,
-0.006339071784168482,
-0.004923599306493998,
-0.008734434843063354,
-0.008599424734711647,
-0.0004455654707271606,
-0.003627956612035632,
-0.00222723837941885,
0.012135512195527554,
0.00016057526227086782,
0.004079703241586685,
0.0007546826382167637,
0.006036732345819473,
-0.007144454400986433,
0.002213145140558481,
0.0014215682167559862,
-0.0025345822796225548,
-0.003991283476352692,
-0.016341455280780792,
-0.00611724890768528,
-0.0021302939858287573,
0.010387769900262356,
-0.0006800912087783217,
0.010489590466022491,
-0.0014942471170797944,
0.001598678412847221,
-0.007215296383947134,
0.004618045408278704,
0.005482769105583429,
0.0023521201219409704,
-0.029792357236146927,
-0.00029910524608567357,
-0.00028970171115361154,
-0.007033949717879295,
0.005541811231523752,
0.0006332698394544423,
-0.0012876996770501137,
-0.0005070082261227071,
-0.005746791604906321,
0.008803809992969036,
-0.008488482795655727,
0.0034959865733981133,
-0.0016432501142844558,
-0.003897866467013955,
-0.0044827233068645,
-0.011746053583920002,
0.003211567411199212,
0.003746581496670842,
-0.005110825411975384,
-0.002926965244114399,
-0.002856340492144227,
0.001967544201761484,
0.002212644787505269,
0.001999163767322898,
-0.02119475044310093,
-0.0023242183960974216,
-0.003450860269367695,
0.008546981029212475,
-0.0013896853197366,
-0.0041772122494876385,
0.005991706158965826,
-0.007316709961742163,
0.0049717482179403305,
0.002841315930709243,
-0.001857010298408568,
-0.009096170775592327,
0.003094856161624193,
-0.00816052034497261,
-0.006323011592030525,
0.003527378663420677,
-0.003899852279573679,
-0.00450843945145607,
-0.001697098952718079,
0.0011906567960977554,
0.007104923482984304,
-0.002979902783408761,
0.00249875639565289,
0.00975741259753704,
-0.0038402974605560303,
-0.007777655031532049,
0.005821763537824154,
0.006023013032972813,
0.002147189574316144,
-0.0008743990329094231,
0.0005799062782898545,
0.00971386581659317,
0.005549349822103977,
0.003513344330713153,
0.004619070328772068,
0.0012791450135409832,
0.011960878036916256,
0.00138756912201643,
0.0037363634910434484,
-0.0036093394737690687,
-0.0017714856658130884,
-0.005420501343905926,
0.00040980245103128254,
-0.0029639883432537317,
-0.0004970910376869142,
-0.009256209246814251,
-0.00953278411179781,
-0.0021429206244647503,
0.0012887699995189905,
0.000650676665827632,
-0.0037652445025742054,
0.0007705817115493119,
0.003007328836247325,
0.010381735861301422,
-0.003072996623814106,
-0.003682744922116399,
0.00030950590735301375,
0.004613070748746395,
-0.005878996569663286,
0.011076029390096664,
-0.011671236716210842,
0.006086441688239574,
-0.002495399909093976,
-0.015011767856776714,
0.005493813659995794,
0.006421480793505907,
-0.005157141946256161,
0.00067240180214867,
0.0016694562509655952,
0.0017915895441547036,
-0.001484301988966763,
-0.005898536182940006,
-0.0017940184334293008,
-0.013602645136415958,
-0.001998098334297538,
0.021754341199994087,
0.0010090090800076723,
0.009151277132332325,
0.01076488010585308,
-0.002244488336145878,
0.0008461184916086495,
0.0047291237860918045,
0.0014509896282106638,
0.014249465428292751,
-0.007293604779988527,
0.00019037794845644385,
-0.00020742998458445072,
-0.005246575456112623,
0.0005194933619350195,
0.00600628275424242,
0.005689073819667101,
-0.0018698843196034431,
-0.00024800316896289587,
-0.0064768120646476746,
-0.009484002366662025,
-0.016053656116127968,
0.00006593080615857616,
0.004179895389825106,
-0.006336437072604895,
0.004568125586956739,
-0.010784766636788845,
0.0019362623570486903,
0.00435565784573555,
0.006628720089793205,
-0.0029557128436863422,
0.0008091451018117368,
0.006418989505618811,
0.011671553365886211,
-0.006606654264032841,
0.0027016266249120235,
0.0019656457006931305,
-0.003090076381340623,
0.0019729500636458397,
0.0046394746750593185,
-0.005894421134144068,
-0.004692911170423031,
0.003707668511196971,
0.003796546021476388,
0.0021666092798113823,
-0.002431419212371111,
-0.010055182501673698,
-0.004540417809039354,
0.0014009905280545354,
-0.00855699647217989,
0.005177455488592386,
0.0005834397743456066,
0.005194384604692459,
-0.008444310165941715,
0.0006153632421046495,
-0.004649430979043245,
-0.009983842261135578,
0.010849256068468094,
-0.005679181776940823,
0.00044546095887199044,
0.011830930598080158,
0.002988232532516122,
-0.015424196608364582,
0.005687760189175606,
0.007978041656315327,
-0.0017073031049221754,
0.0025049149990081787,
0.006354842334985733,
-0.0027970431838184595,
-0.02106710523366928,
-0.002453866880387068,
-0.016748955473303795,
0.006441489327698946,
-0.0000286628110188758,
0.0024720029905438423,
-0.007998468354344368,
0.009035071358084679,
0.006100536324083805,
-0.012771237641572952,
-0.0036461087875068188,
-0.00970826018601656,
0.00469391793012619,
-0.0014084521681070328,
-0.0017526731826364994,
-0.003092072671279311,
-0.003955029416829348,
-0.002657950157299638,
0.0006285301642492414,
-0.002048937836661935,
0.008116111159324646,
0.0025820317678153515,
-0.003490515286102891,
0.00295925117097795,
-0.0003828013432212174,
-0.00013200505054555833,
-0.0005845424602739513,
-0.010296240448951721,
0.00008734886068850756,
0.008773977868258953,
-0.002002839930355549,
-0.001612912048585713,
-0.0012767717707902193,
-0.0037992706056684256,
-0.0014084787108004093,
-0.011120022274553776,
-0.0014279326424002647,
-0.0021933410316705704,
-0.0026338379830121994,
-0.010702383704483509,
-0.0031422439496964216,
-0.011154469102621078,
0.010776177980005741,
-0.005289075430482626,
0.00870490726083517,
0.00015512239770032465,
-0.004397126380354166,
0.006606199312955141,
0.0007125865668058395,
0.005772836040705442,
0.0010029366239905357,
0.0036393310874700546,
0.0039752875454723835,
-0.009271624498069286,
-0.012692422606050968,
0.010599951259791851,
-0.010561973787844181,
0.002710761735215783,
0.013573851436376572,
0.004117130301892757,
0.009046765975654125,
-0.0001970361772691831,
0.0003622628573793918,
0.00736974785104394,
0.010360568761825562,
-0.012365887872874737,
0.006048628129065037,
-0.0024186079390347004,
0.0008837117347866297,
0.0022046586964279413,
-0.0034679865930229425,
0.005009437445551157,
0.010128381662070751,
0.0034995402675122023,
-0.005131901707500219,
-0.001146830734796822,
-0.0004540054651442915,
0.003599252551794052,
-0.009976084344089031,
-0.0010572524042800069,
-0.0026674005202949047,
-0.0031394052784889936,
-0.005600249394774437,
-0.0012332883197814226,
-0.001060745446011424,
0.005474593956023455,
-0.0025497539900243282,
0.008469419553875923,
-0.0023789333645254374,
-0.007042437791824341,
0.014529157429933548,
-0.007082946132868528,
-0.0060870288871228695,
0.0028688448946923018,
-0.0002269791002618149,
0.0019046872621402144,
-0.004547033924609423,
-0.002904352033510804,
0.0019463786156848073,
0.003963130991905928,
-0.0042277248576283455,
-0.0078549450263381,
-0.0013631421606987715,
-0.0003077674482483417,
-0.010537665337324142,
0.0026789680123329163,
0.013145306147634983,
-0.0008252493571490049,
0.004102789796888828,
0.0006023559253662825,
-0.008046042174100876,
-0.015452849678695202,
0.05446692183613777,
-0.0017192610539495945,
0.004050589632242918,
0.004367750138044357,
-0.008868638426065445,
-0.003950190264731646,
-0.003929354716092348,
0.007493636105209589,
-0.006161335855722427,
-0.007264795247465372,
0.009090238250792027,
-0.002484098309651017,
0.0009911754168570042,
-0.0013686709571629763,
-0.0006004945607855916,
0.012112878262996674,
-0.0037618789356201887,
-0.01611904613673687,
-0.015567903406918049,
0.007474102079868317,
-0.0013444137293845415,
-0.00796708557754755,
0.006122995633631945,
-0.0010714016389101744,
-0.0024998034350574017,
-0.00017721232143230736,
0.003846983890980482,
0.0004425248771440238,
0.0025377722922712564,
-0.005351997911930084,
-0.002481314819306135,
-0.0018256620969623327,
0.0038773007690906525,
0.0065020001493394375,
0.010098973289132118,
-0.0029546725563704967,
0.0067188008688390255,
-0.001844005542807281,
-0.0007899559568613768,
-0.0026837806217372417,
0.004001006484031677,
0.004442707635462284,
-0.004299148451536894,
-0.004171145148575306,
0.002484573284164071,
0.003616522066295147,
0.0003517100412864238,
0.009767248295247555,
-0.0017323227366432548,
-0.003679663874208927,
0.009607583284378052,
0.0053852275013923645,
-0.002649742877110839,
0.005588640924543142,
-0.0022316561080515385,
0.006466072518378496,
0.0015597953461110592,
-0.009397393092513084,
-0.01687803491950035,
-0.0009645160171203315,
0.004826386459171772,
0.006906070280820131,
-0.0018128521041944623,
0.00016255213995464146,
0.0015319172525778413,
-0.005586490035057068,
-0.007903769612312317,
-0.009608898311853409,
-0.0015708747087046504,
-0.0032801292836666107,
0.0019583574030548334,
0.07274401932954788,
-0.004398631863296032,
0.0017816280014812946,
-0.008761952631175518,
0.0009300900856032968,
-0.0024606750812381506,
-0.0009443002636544406,
-0.0020129389595240355,
-0.0028324597515165806,
0.0034711796324700117,
0.0024860582780092955,
-0.006480820942670107,
-0.011964562349021435,
0.003329483326524496,
0.0005185719346627593,
-0.0050574117340147495,
0.0009347725426778197,
0.009497634135186672,
-0.0055047255009412766,
0.004690183326601982,
-0.01188776083290577,
-0.0001475040044169873,
-0.003736085956916213,
-0.00826206710189581,
-0.004706250503659248,
-0.002349727787077427,
0.003541064215824008,
0.0023128052707761526,
0.004868278279900551,
-0.0033732764422893524,
0.002609656425192952,
0.0017279908061027527,
0.0032942125108093023,
-0.0016330828657373786,
0.0012509016087278724,
-0.005105597898364067,
0.006586660631000996,
0.0036504343152046204,
-0.012593348510563374,
-0.005365919787436724,
-0.0010572233004495502,
-0.0006952570984140038,
-0.0027418839745223522,
0.0059356982819736,
-0.001346257864497602,
0.006528038997203112,
-0.004754052963107824,
0.0011848739814013243,
-0.005991831421852112,
-0.0032991990447044373,
-0.011328833177685738,
0.00928682554513216,
-0.1820622682571411,
0.007669657468795776,
0.005872114561498165,
-0.0019449664978310466,
-0.0035440477076917887,
-0.016867181286215782,
-0.008968407288193703,
0.004460776690393686,
0.010969446040689945,
0.0021477178670465946,
0.0008626632625237107,
-0.0019581804517656565,
0.005467062816023827,
0.0031363789457827806,
-0.000508334778714925,
-0.008180573582649231,
0.005279661156237125,
-0.00680686067789793,
-0.0007962612435221672,
0.0012198506155982614,
0.004394835326820612,
0.008899731561541557,
0.00313952867873013,
0.004080492537468672,
-0.002254899824038148,
-0.001203260151669383,
0.003649067599326372,
-0.001721035223454237,
0.007874949835240841,
-0.013852372765541077,
-0.0015959630254656076,
-0.003597961040213704,
-0.003981349524110556,
0.00034986648824997246,
0.002806349890306592,
-0.00463550491258502,
0.00839086715131998,
0.0036388495936989784,
-0.00552555313333869,
0.010455934330821037,
-0.009597581811249256,
0.029270173981785774,
0.0027651183772832155,
0.010089816525578499,
0.0013006400549784303,
-0.0026035383343696594,
-0.005080564878880978,
0.008720177225768566,
0.0010678754188120365,
0.012028913013637066,
-0.013251247815787792,
-0.0034402552992105484,
0.0036944930907338858,
0.016032453626394272,
-0.004543195012956858,
-0.007877836935222149,
-0.008744166232645512,
-0.008631506003439426,
0.002433622954413295,
0.010577249340713024,
0.005915889982134104,
-0.004147726111114025,
0.008801094256341457,
-0.0034855976700782776,
-0.01697021909058094,
0.001861478085629642,
-0.004300207365304232,
-0.010303782299160957,
0.005206186790019274,
0.00631609046831727,
0.00988876260817051,
0.000512919679749757,
0.004149305168539286,
-0.0013600217644125223,
0.0034522206988185644,
-0.0023911765310913324,
0.007434590253978968,
-0.0007834596908651292,
0.00534195126965642,
-0.005280263721942902,
0.008463278412818909,
-0.01009835209697485,
-0.005625947378575802,
0.002305343048647046,
-0.004950938746333122,
0.00930771604180336,
0.004878572188317776,
-0.004079067148268223,
0.00030864085420034826,
-0.012352424673736095,
-0.003854589769616723,
0.004648846108466387,
0.0014720768667757511,
-0.008777455426752567,
0.0020752965938299894,
-0.003426741808652878,
0.006732618436217308,
0.009776183404028416,
-0.005681408103555441,
0.004286781884729862,
0.00443076528608799,
-0.004436353221535683,
0.0011129096383228898,
-0.0050860983319580555,
0.0021574627608060837,
0.004000829998403788,
-0.007709641475230455,
-0.008637028746306896,
0.006884542293846607,
-0.0064151291735470295,
-0.008240073919296265,
0.001298957853578031,
-0.013417436741292477,
-0.005299053620547056,
-0.0022360284347087145,
-0.010865829885005951,
-0.0014429049333557487
] |
8a2eae99a5174fb4958d90cc6f7e9618fa70f6e1 | 2,414 | py | Python | unsorted/linked_list.py | AlgoArt/algoart | 7a7a28f099351a6b6c1b360c794f697881c7e429 | [
"Unlicense"
] | 1 | 2015-09-20T06:35:58.000Z | 2015-09-20T06:35:58.000Z | unsorted/linked_list.py | algoart/algoart | 7a7a28f099351a6b6c1b360c794f697881c7e429 | [
"Unlicense"
] | null | null | null | unsorted/linked_list.py | algoart/algoart | 7a7a28f099351a6b6c1b360c794f697881c7e429 | [
"Unlicense"
] | null | null | null | #!/usr/bin/env python
# linked_list.py - Linked list implementation in Python by Sergey 2015
"""
Linked list implementation in Python
"""
# Standard modules
import unittest
import sys
import os
import argparse
import re
import random
import subprocess
import getpass
import shutil
# Additional modules
###############################################################################
# Linked_list Class
###############################################################################
class Node:
def __init__(self, value, tail):
self.value = value
self.next = tail
class Linked_list:
""" Linked_list representation """
def __init__(self):
""" Default constructor """
self.list = None
def insert(self, value):
self.list = Node(value, self.list)
def start_iter(self):
return self.list
def next_iter(self, iter):
if iter is not None:
return iter.next
else:
return iter
def tolist(self):
result = []
iter = self.start_iter()
while True:
result.append(iter.value)
iter = self.next_iter(iter)
if not iter:
break
return result
def run(self, test=False):
""" Main execution function """
if test:
return
###############################################################################
# Executable code
###############################################################################
def main():
# Sandbox
sb = Linked_list(" ".join(sys.argv[1:]))
sb.run()
###############################################################################
# Unit Tests
###############################################################################
class unitTests(unittest.TestCase):
def test_Linked_list_class__basic_functionality(self):
""" Linked_list class basic testing """
d = Linked_list()
self.assertEqual(d.list, None)
d.insert(1)
self.assertEqual(d.list.value, 1)
d.insert(2)
self.assertEqual(d.list.next.value, 1)
iter = d.start_iter()
self.assertEqual(iter.value, 2)
iter = d.next_iter(iter)
self.assertEqual(iter.value, 1)
self.assertEqual(d.tolist(), [2, 1])
if __name__ == "__main__":
if sys.argv[-1] == "-ut":
unittest.main(argv=[" "])
main()
| 22.773585 | 79 | 0.474731 | 1 | 1.2816 | [
0.00048230469110421836,
0.02480439841747284,
0.008311997167766094,
-0.0011339621851220727,
0.004624395165592432,
-0.002212591003626585,
-0.009635813534259796,
0.0032173795625567436,
-0.005451629403978586,
0.0014846479753032327,
0.0012197480536997318,
0.006402576807886362,
0.0066308253444731236,
-0.016481392085552216,
0.0007785275229252875,
0.01715538091957569,
-0.0523531511425972,
0.0003096369036938995,
-0.0033503693994134665,
0.0022670363541692495,
-0.008056172169744968,
0.009466232731938362,
0.008459430187940598,
0.006865024100989103,
0.006784683559089899,
0.00023445874103344977,
0.009605932980775833,
0.0026450951118022203,
-0.0076277232728898525,
-0.007266105618327856,
-0.0007764162146486342,
-0.0018403674475848675,
-0.006942305248230696,
-0.008863242343068123,
0.006019358057528734,
-0.0031048657838255167,
-0.000991040375083685,
-0.01842324621975422,
0.012635366059839725,
-0.003801467828452587,
-0.005474022589623928,
-0.01452054176479578,
0.00023502369003836066,
0.004441379103809595,
-0.00853679794818163,
0.0021805500146001577,
-0.003981861285865307,
0.0017531138146296144,
-0.012004709802567959,
0.005689232610166073,
-0.009783538058400154,
0.005534106399863958,
0.013323601335287094,
0.0032606208696961403,
-0.005991868209093809,
-0.0061245509423315525,
0.01200529932975769,
0.00012208415137138218,
-0.009763957932591438,
-0.0010974232573062181,
-0.0033220716286450624,
-0.0035291602835059166,
0.004812921397387981,
0.0028165332041680813,
-0.014928477816283703,
-0.007643766701221466,
-0.004273782949894667,
0.002960625570267439,
-0.0006450724904425442,
0.005882371217012405,
0.0008027507574297488,
0.0006565024959854782,
0.007307454943656921,
0.004676081705838442,
0.003595635062083602,
-0.002495948923751712,
-0.0017686983337625861,
-0.00008115926175378263,
0.007177424151450396,
0.0038877646438777447,
0.0039007465820759535,
-0.0061564091593027115,
0.005807693116366863,
0.00887159164994955,
0.013178369961678982,
0.0069318003952503204,
0.01798159070312977,
-0.011478983797132969,
0.04688073322176933,
0.008613904938101768,
-0.008310521021485329,
0.0014946245355531573,
-0.008954009972512722,
-0.001223118626512587,
-0.004464627709239721,
-0.027392419055104256,
0.00029749321402050555,
-0.004273553378880024,
-0.0008570493664592505,
0.0038548132870346308,
0.00039426522562280297,
0.006424956955015659,
-0.0012104539200663567,
-0.0018119243904948235,
-0.00763336569070816,
0.010066408663988113,
-0.008036063052713871,
-0.002695683389902115,
0.0060487063601613045,
0.002559512387961149,
-0.010801858268678188,
-0.00231130956672132,
0.0010367388604208827,
-0.012336396612226963,
0.002889081835746765,
0.00147646211553365,
-0.005282157100737095,
0.053717419505119324,
-0.0004088104469701648,
0.003750056028366089,
-0.004174877889454365,
0.0024833595380187035,
0.0014831955777481198,
0.004646784625947475,
0.011267662048339844,
-0.0034793205559253693,
0.010510527528822422,
0.0067945304326713085,
0.0021408062893897295,
0.009865060448646545,
-0.0011493550846353173,
0.006718281656503677,
-0.004661940038204193,
-0.0020059417001903057,
0.0011047294829040766,
-0.006540580652654171,
0.007137454580515623,
-0.0016017642337828875,
-0.007035587448626757,
0.0011485263239592314,
-0.0013547091512009501,
-0.010453234426677227,
0.0017132977955043316,
-0.004070692230015993,
0.005315068643540144,
-0.009966309182345867,
-0.003109429031610489,
-0.003935671411454678,
-0.004112923517823219,
0.00246889004483819,
0.010365467518568039,
0.00410142308101058,
0.0033908365294337273,
-0.00594360614195466,
-0.008469837717711926,
-0.0010932199656963348,
-0.0035845490638166666,
0.0020142393186688423,
0.008055921643972397,
0.004940276499837637,
-0.010242476128041744,
-0.002149252686649561,
0.0012022566515952349,
0.0012194423470646143,
-0.000568331335671246,
0.004121583886444569,
-0.009546082466840744,
0.006738234777003527,
-0.0003478471771813929,
0.00432260986417532,
0.011913912370800972,
-0.0043664597906172276,
0.00025085872039198875,
-0.00024720642250031233,
0.0029425823595374823,
-0.0000575284066144377,
0.003569783875718713,
0.010391350835561752,
-0.002531352685764432,
-0.004507876932621002,
0.004092664923518896,
0.00429336866363883,
0.009277916513383389,
0.004515197593718767,
-0.003765188390389085,
0.0016939264023676515,
-0.004371752496808767,
-0.001969690900295973,
0.006792907603085041,
-0.004852308426052332,
0.006729979999363422,
0.004526647739112377,
-0.014198827557265759,
-0.00978867243975401,
-0.00004140711098443717,
-0.008708995766937733,
0.00027462627622298896,
0.01370561495423317,
0.011001829989254475,
-0.0034285718575119972,
0.002941899001598358,
-0.009947691112756729,
0.0007745198090560734,
0.009140417911112309,
0.0027250421699136496,
-0.012743504717946053,
-0.9591524004936218,
0.006109160371124744,
0.0036352653987705708,
-0.0012125435750931501,
0.006235586013644934,
0.002797974506393075,
0.0038790092803537846,
0.004437788389623165,
0.015125845558941364,
-0.009386830031871796,
-0.006619620602577925,
-0.009540969505906105,
-0.011111161671578884,
-0.0022597615607082844,
-0.007422574795782566,
-0.002437713323161006,
-0.007346100173890591,
-0.006794885266572237,
-0.0035665235482156277,
-0.0025926181115210056,
-0.0017198616405948997,
0.008288029581308365,
-0.0008555249660275877,
0.004815146792680025,
0.0020613183733075857,
0.0037069704849272966,
-0.007108304183930159,
-0.0012977177975699306,
-0.0029068172443658113,
-0.0020512943156063557,
-0.00641306908801198,
-0.013597244396805763,
-0.0029239915311336517,
-0.000910089467652142,
0.010022447444498539,
0.0011057257652282715,
0.008709735237061977,
-0.0030137186404317617,
0.0013166979188099504,
-0.006980679929256439,
0.005147651769220829,
0.0010122647508978844,
0.003508777590468526,
-0.03052227944135666,
-0.0007227514288388193,
-0.00042188219958916306,
-0.00895711500197649,
0.008750924840569496,
0.00020381726790219545,
-0.0016521289944648743,
-0.0033671665005385876,
-0.005796059034764767,
0.008091664873063564,
-0.006991072557866573,
0.004160963464528322,
-0.0026476120110601187,
-0.0074574751779437065,
-0.00190115871373564,
-0.009115287102758884,
0.0015357555821537971,
0.0037087881937623024,
-0.0031711820047348738,
-0.005085257813334465,
-0.0031597719062119722,
0.00348131125792861,
0.0023568749893456697,
0.001987486844882369,
-0.017761915922164917,
-0.005606756079941988,
0.0003831578651443124,
0.0001724813919281587,
-0.0031144258100539446,
-0.0033739269711077213,
0.005651134066283703,
-0.008669610135257244,
0.0054231807589530945,
0.002714666770771146,
-0.001500253682024777,
-0.011582529172301292,
-0.0006171665736474097,
-0.009029214270412922,
-0.007372109219431877,
0.0010940036736428738,
-0.004296252503991127,
-0.004229340702295303,
0.0004488001868594438,
0.001618550973944366,
0.006032437551766634,
-0.0037090512923896313,
0.0032384733203798532,
0.011865495704114437,
-0.0043288469314575195,
-0.008978613652288914,
0.006149287801235914,
0.006160249002277851,
0.00040387449553236365,
-0.0026119451504200697,
0.003060760907828808,
0.007607055362313986,
0.008407031185925007,
0.0023662641178816557,
0.006136443931609392,
0.00016272280481643975,
0.007361882831901312,
-0.00007853059651097283,
0.0006738297524861991,
-0.002646423876285553,
-0.0002097319083986804,
-0.0029468433931469917,
-0.0007773726829327643,
-0.004064792767167091,
-0.0026576118543744087,
-0.011437973938882351,
-0.009425988420844078,
-0.0037369453348219395,
-0.0000663424507365562,
0.002811378799378872,
-0.004601729102432728,
-0.0008567678742110729,
0.001867871731519699,
0.008911174722015858,
0.0008070837357081473,
-0.0038494097534567118,
0.0006815522210672498,
0.0034141738433390856,
-0.004665604792535305,
0.01443474367260933,
-0.011099846102297306,
0.007375629618763924,
0.00008961415005614981,
-0.016158027574419975,
0.007120936643332243,
0.009740708395838737,
-0.009926868602633476,
0.001753555261529982,
0.002247992204502225,
0.003451382974162698,
-0.000570473843254149,
-0.004628283437341452,
-0.003368489909917116,
-0.01653401367366314,
0.0007455055019818246,
0.019526813179254532,
0.0011640838347375393,
0.009522989392280579,
0.011680473573505878,
-0.0037873350083827972,
0.002068806905299425,
0.005409544333815575,
0.0009640696807764471,
0.012848972342908382,
-0.007739654742181301,
0.00036254097358323634,
0.00337532302364707,
-0.006563667207956314,
0.0007656632224097848,
0.006727207917720079,
0.006550701335072517,
-0.004980902187526226,
0.0033205528743565083,
-0.006297701969742775,
-0.005384583491832018,
-0.01761285774409771,
-0.004730622749775648,
0.005418808199465275,
-0.0043694148771464825,
0.005502728279680014,
-0.012545423582196236,
0.004395990166813135,
0.006671347189694643,
0.0036953696981072426,
-0.0012161487247794867,
0.0002082935388898477,
0.004899746272712946,
0.011257406324148178,
-0.005274351220577955,
0.001096704974770546,
0.004288811236619949,
-0.001422902219928801,
-0.00023387675173580647,
0.006441683974117041,
-0.006295247469097376,
-0.005462648347020149,
0.0028182542882859707,
0.0037406941410154104,
-0.0008142993901856244,
-0.0032878797501325607,
-0.008208625949919224,
-0.004134052433073521,
0.0036762701347470284,
-0.006679106969386339,
0.003117010463029146,
-0.0007924923556856811,
0.004699372220784426,
-0.006612252444028854,
-0.0013019124744459987,
-0.0028659484814852476,
-0.013708695769309998,
0.010671809315681458,
-0.002317855367437005,
0.002339103491976857,
0.012925545684993267,
0.0029624062590301037,
-0.012273162603378296,
0.0046330587938427925,
0.008862988092005253,
-0.003962675575166941,
0.004345555789768696,
0.005123163107782602,
-0.00564476428553462,
-0.02098633535206318,
-0.00256324908696115,
-0.012959986925125122,
0.006081993225961924,
-0.0011229772353544831,
0.004364679101854563,
-0.009132461622357368,
0.007763887755572796,
0.007939400151371956,
-0.01293924730271101,
-0.006346329115331173,
-0.008401959203183651,
0.008367576636373997,
0.00012369673640932888,
-0.0009217453189194202,
-0.0038019041530787945,
-0.0019834227859973907,
-0.000604495289735496,
-0.002723335986956954,
-0.0021237675100564957,
0.006017299368977547,
0.0019022703636437654,
-0.002784355077892542,
0.002976000774651766,
-0.0031354583334177732,
0.00005092726132716052,
0.00043544231448322535,
-0.010232610628008842,
0.0018732177559286356,
0.0038869152776896954,
-0.003146299859508872,
-0.0020499485544860363,
0.0007876322488300502,
-0.0023347772657871246,
-0.006358967162668705,
-0.011943068355321884,
-0.003941280301660299,
-0.004384159576147795,
-0.00313762784935534,
-0.01226032990962267,
-0.002366089029237628,
-0.007376627065241337,
0.008123870939016342,
-0.006939890328794718,
0.008006869815289974,
0.006642439402639866,
-0.005045237950980663,
0.005578276235610247,
-0.0014147423207759857,
0.004402343183755875,
0.0025697420351207256,
0.005356699228286743,
0.001800771919079125,
-0.0062046661041677,
-0.009762531146407127,
0.012706827372312546,
-0.008520467206835747,
0.0009810671908780932,
0.013844895176589489,
0.006622691638767719,
0.009997755289077759,
0.0005051263142377138,
-0.0002508364850655198,
0.0019335933029651642,
0.007820110768079758,
-0.012403860688209534,
0.005956775508821011,
-0.004208933096379042,
-0.0012353966012597084,
0.0053627751767635345,
-0.0026170772034674883,
0.0025139949284493923,
0.008000900037586689,
0.0010394301498308778,
-0.006490155588835478,
-0.0018602482741698623,
0.003282609162852168,
0.003139867214486003,
-0.011591888032853603,
0.0013999607181176543,
-0.0023304808419197798,
-0.006217856891453266,
-0.001712855533696711,
-0.001981364330276847,
-0.00032764647039584816,
0.00238973880186677,
-0.0006149923428893089,
0.005706707946956158,
0.003707575611770153,
-0.0055097793228924274,
0.014251073822379112,
-0.003543248400092125,
-0.0038960478268563747,
0.0028183776885271072,
0.0023150029592216015,
-0.0027952089440077543,
-0.005698539316654205,
-0.0023913749027997255,
0.0021456165704876184,
0.007358156144618988,
-0.002780304988846183,
-0.0039552804082632065,
-0.0019547499250620604,
0.0008278097957372665,
-0.010209030471742153,
0.0007651169435121119,
0.012524659745395184,
-0.005969081539660692,
0.0063783046789467335,
-0.0017470530001446605,
-0.0069364034570753574,
-0.012947327457368374,
0.053415633738040924,
0.0005835369229316711,
0.0034016950521618128,
0.0033835021313279867,
-0.007854310795664787,
-0.00032179211848415434,
-0.0015392298810184002,
0.00788742583245039,
-0.007702113129198551,
-0.008007338270545006,
0.008724519982933998,
-0.003392175305634737,
0.004438035190105438,
0.002532325452193618,
-0.0013846654910594225,
0.015530426055192947,
-0.0030419561080634594,
-0.01767393946647644,
-0.016529373824596405,
0.008073187433183193,
-0.0035881258081644773,
-0.0071287150494754314,
0.009150341153144836,
-0.004022630862891674,
-0.0031351163052022457,
0.0001539028889965266,
0.00457781832665205,
0.000017707079678075388,
0.0006218302296474576,
-0.002662170911207795,
-0.002640807069838047,
-0.0004730797663796693,
0.0035683854948729277,
0.00552327698096633,
0.007051283959299326,
-0.0027412292547523975,
0.005434791557490826,
-0.00086594169260934,
-0.001277526025660336,
-0.0023374976590275764,
0.003308317856863141,
0.008584714494645596,
-0.0028243937995284796,
-0.0016183749539777637,
0.006513466127216816,
0.004810009151697159,
0.003446676069870591,
0.010979712009429932,
-0.0006717209471389651,
-0.005919903516769409,
0.008550330065190792,
0.006912621669471264,
-0.0005256444565020502,
0.010022459551692009,
-0.0006290534511208534,
0.005801339168101549,
0.0013681186828762293,
-0.0083461320027709,
-0.014949290081858635,
-0.0036752130836248398,
0.006626824848353863,
0.008475764654576778,
-0.0017325300723314285,
0.0005106294993311167,
-0.0013252554927021265,
-0.001752060023136437,
-0.006538009271025658,
-0.007943478412926197,
-0.0029620372224599123,
0.001677151769399643,
0.0037607222329825163,
0.06965143233537674,
-0.005740783177316189,
-0.0008231487590819597,
-0.008510858751833439,
-0.0007377368747256696,
-0.0017861822852864861,
-0.001582069438882172,
-0.0008416927303187549,
-0.0019018420716747642,
0.0011755501618608832,
0.0004295784456189722,
-0.008487405255436897,
-0.01027104165405035,
0.0005115150706842542,
0.001794316223822534,
-0.0021104393526911736,
0.005063756834715605,
0.006235509645193815,
-0.007547026965767145,
0.001005016383714974,
-0.012139399535953999,
-0.002112912479788065,
-0.0022037653252482414,
-0.010746639221906662,
-0.004646672401577234,
-0.003007884370163083,
0.005175780039280653,
0.0032150212209671736,
0.005303830374032259,
-0.003386933356523514,
0.0056947688572108746,
-0.0020777611061930656,
-0.0011814397294074297,
-0.0052273948676884174,
0.00041272019734606147,
-0.006212806794792414,
0.007597771938890219,
0.001460621366277337,
-0.011515035293996334,
-0.004197537433356047,
-0.00014135277888271958,
-0.00027561126626096666,
-0.00537008186802268,
0.004276065621525049,
-0.0011510117910802364,
0.004580977372825146,
-0.0021244168747216463,
-0.00006321739056147635,
-0.006543609779328108,
0.0027646173257380724,
-0.013046047650277615,
0.004179026000201702,
-0.17404529452323914,
0.010155917145311832,
0.0035389866679906845,
-0.004022159613668919,
-0.00446538720279932,
-0.015778275206685066,
-0.004331775009632111,
0.003040905110538006,
0.009721453301608562,
0.0012355804210528731,
-0.0013524459209293127,
-0.001956619555130601,
0.004553032107651234,
0.004800192080438137,
-0.0014102548593655229,
-0.005367810372263193,
0.0047536748461425304,
-0.004088977351784706,
0.0016923522343859076,
0.002988936146721244,
0.004480603151023388,
0.010708270594477654,
0.0016468868125230074,
0.002041323808953166,
-0.0014877569628879428,
-0.004707877058535814,
0.00635308213531971,
-0.0012870834907516837,
0.005859456490725279,
-0.011261948384344578,
-0.0026819873601198196,
-0.004057896323502064,
-0.005897982511669397,
0.0006484155892394483,
0.006181881297379732,
-0.0007654044893570244,
0.00827821996062994,
0.003301476826891303,
-0.007776067592203617,
0.007032069377601147,
-0.007858294993638992,
0.02823036164045334,
0.0037582896184176207,
0.0073754857294261456,
-0.00006384195148712024,
-0.0050733950920403,
-0.004859919659793377,
0.008797407150268555,
0.0011492656776681542,
0.011419989168643951,
-0.014139724895358086,
-0.0015847731847316027,
0.0026036652270704508,
0.01775030605494976,
-0.004712976980954409,
-0.010797669179737568,
-0.007018002215772867,
-0.002791171194985509,
0.0005509501206688583,
0.007684547454118729,
0.011450626887381077,
-0.0034878479782491922,
0.00787539966404438,
-0.0026285010389983654,
-0.022555643692612648,
0.002685542916879058,
-0.005137132480740547,
-0.007223736960440874,
0.0013576344354078174,
0.007274633273482323,
0.010748717933893204,
-0.001551081077195704,
0.0018248235573992133,
-0.0008872595499269664,
0.0030187254305928946,
-0.0007752875098958611,
0.005129576660692692,
-0.001447584480047226,
0.004584149923175573,
-0.010722479782998562,
0.00691549526527524,
-0.008581901900470257,
-0.0032667932100594044,
0.0007654845830984414,
-0.005019091069698334,
0.012221891433000565,
0.00518158171325922,
-0.001478175981901586,
-0.002911986783146858,
-0.008918758481740952,
-0.0021551379468292,
0.0015990067040547729,
0.0023312733974307775,
-0.009504709392786026,
0.002761705545708537,
-0.0004619936225935817,
0.0051053110510110855,
0.005783111788332462,
-0.009116758592426777,
0.0056370822712779045,
0.004685549531131983,
-0.0035384800285100937,
0.00228393217548728,
-0.004202235955744982,
0.002484602387994528,
0.004767321050167084,
-0.005699935369193554,
-0.005963537376374006,
0.0038333514239639044,
-0.007441013120114803,
-0.005038686562329531,
0.0070067946799099445,
-0.008169579319655895,
-0.008155877701938152,
-0.0030357514042407274,
-0.012222780846059322,
0.0007987079443410039
] |
8a2f2c6d37a1cc224033909e079c7c6469595c55 | 8,555 | py | Python | examples/seismic/viscoacoustic/wavesolver.py | speglich/devito | b636f7694eb6a1e19b0f2c48f44ff63613029a7b | [
"MIT"
] | 1 | 2020-01-31T10:35:49.000Z | 2020-01-31T10:35:49.000Z | examples/seismic/viscoacoustic/wavesolver.py | speglich/devito | b636f7694eb6a1e19b0f2c48f44ff63613029a7b | [
"MIT"
] | 52 | 2020-10-12T19:29:09.000Z | 2022-03-10T14:05:22.000Z | examples/seismic/viscoacoustic/wavesolver.py | alisiahkoohi/devito | f535a44dff12de2837eb6e3217a65ffb2d371cb8 | [
"MIT"
] | 1 | 2020-06-02T03:31:11.000Z | 2020-06-02T03:31:11.000Z | from devito import VectorTimeFunction, TimeFunction, NODE
from devito.tools import memoized_meth
from examples.seismic import PointSource
from examples.seismic.viscoacoustic.operators import (ForwardOperator, AdjointOperator)
class ViscoacousticWaveSolver(object):
"""
Solver object that provides operators for seismic inversion problems
and encapsulates the time and space discretization for a given problem
setup.
Parameters
----------
model : Model
Physical model with domain parameters.
geometry : AcquisitionGeometry
Geometry object that contains the source (SparseTimeFunction) and
receivers (SparseTimeFunction) and their position.
space_order : int, optional
Order of the spatial stencil discretisation. Defaults to 4.
kernel : selects a visco-acoustic equation from the options below:
'sls' (Standard Linear Solid) :
1st order - Blanch and Symes (1995) / Dutta and Schuster (2014)
viscoacoustic equation
2nd order - Bai et al. (2014) viscoacoustic equation
'ren' - Ren et al. (2014) viscoacoustic equation
'deng_mcmechan' - Deng and McMechan (2007) viscoacoustic equation
Defaults to 'sls' 2nd order.
"""
def __init__(self, model, geometry, space_order=4, kernel='sls', time_order=2,
**kwargs):
self.model = model
self.model._initialize_bcs(bcs="mask")
self.geometry = geometry
self.space_order = space_order
self.kernel = kernel
self.time_order = time_order
self._kwargs = kwargs
@property
def dt(self):
return self.model.critical_dt
@memoized_meth
def op_fwd(self, save=None):
"""Cached operator for forward runs with buffered wavefield"""
return ForwardOperator(self.model, save=save, geometry=self.geometry,
space_order=self.space_order, kernel=self.kernel,
time_order=self.time_order, **self._kwargs)
@memoized_meth
def op_adj(self):
"""Cached operator for adjoint runs"""
return AdjointOperator(self.model, save=None, geometry=self.geometry,
space_order=self.space_order, kernel=self.kernel,
time_order=self.time_order, **self._kwargs)
def forward(self, src=None, rec=None, v=None, r=None, p=None, qp=None, b=None,
vp=None, save=None, **kwargs):
"""
Forward modelling function that creates the necessary
data objects for running a forward modelling operator.
Parameters
----------
src : SparseTimeFunction or array_like, optional
Time series data for the injected source term.
rec : SparseTimeFunction or array_like, optional
The interpolated receiver data.
v : VectorTimeFunction, optional
The computed particle velocity.
r : TimeFunction, optional
The computed memory variable.
p : TimeFunction, optional
Stores the computed wavefield.
qp : Function, optional
The P-wave quality factor.
b : Function, optional
The time-constant inverse density.
vp : Function or float, optional
The time-constant velocity.
save : bool, optional
Whether or not to save the entire (unrolled) wavefield.
Returns
-------
Receiver, wavefield and performance summary
"""
# Source term is read-only, so re-use the default
src = src or self.geometry.src
# Create a new receiver object to store the result
rec = rec or self.geometry.rec
# Create all the fields v, p, r
save_t = src.nt if save else None
if self.time_order == 1:
v = v or VectorTimeFunction(name="v", grid=self.model.grid, save=save_t,
time_order=self.time_order,
space_order=self.space_order)
kwargs.update({k.name: k for k in v})
# Create the forward wavefield if not provided
p = p or TimeFunction(name="p", grid=self.model.grid, save=save_t,
time_order=self.time_order, space_order=self.space_order,
staggered=NODE)
# Memory variable:
r = r or TimeFunction(name="r", grid=self.model.grid, save=save_t,
time_order=self.time_order, space_order=self.space_order,
staggered=NODE)
# Pick physical parameters from model unless explicitly provided
b = b or self.model.b
qp = qp or self.model.qp
# Pick vp from model unless explicitly provided
vp = vp or self.model.vp
if self.kernel == 'sls':
# Execute operator and return wavefield and receiver data
# With Memory variable
summary = self.op_fwd(save).apply(src=src, rec=rec, qp=qp, r=r,
p=p, b=b, vp=vp,
dt=kwargs.pop('dt', self.dt), **kwargs)
else:
# Execute operator and return wavefield and receiver data
# Without Memory variable
summary = self.op_fwd(save).apply(src=src, rec=rec, qp=qp, p=p,
b=b, vp=vp,
dt=kwargs.pop('dt', self.dt), **kwargs)
return rec, p, v, summary
def adjoint(self, rec, srca=None, va=None, pa=None, vp=None, qp=None, b=None, r=None,
**kwargs):
"""
Adjoint modelling function that creates the necessary
data objects for running an adjoint modelling operator.
Parameters
----------
rec : SparseTimeFunction or array-like
The receiver data. Please note that
these act as the source term in the adjoint run.
srca : SparseTimeFunction or array-like
The resulting data for the interpolated at the
original source location.
va : VectorTimeFunction, optional
The computed particle velocity.
pa : TimeFunction, optional
Stores the computed wavefield.
vp : Function or float, optional
The time-constant velocity.
qp : Function, optional
The P-wave quality factor.
b : Function, optional
The time-constant inverse density.
r : TimeFunction, optional
The computed memory variable.
Returns
-------
Adjoint source, wavefield and performance summary.
"""
# Create a new adjoint source and receiver symbol
srca = srca or PointSource(name='srca', grid=self.model.grid,
time_range=self.geometry.time_axis,
coordinates=self.geometry.src_positions)
if self.time_order == 1:
va = va or VectorTimeFunction(name="va", grid=self.model.grid,
time_order=self.time_order,
space_order=self.space_order)
kwargs.update({k.name: k for k in va})
pa = pa or TimeFunction(name="pa", grid=self.model.grid,
time_order=self.time_order, space_order=self.space_order,
staggered=NODE)
# Memory variable:
r = r or TimeFunction(name="r", grid=self.model.grid, time_order=self.time_order,
space_order=self.space_order, staggered=NODE)
b = b or self.model.b
qp = qp or self.model.qp
# Pick vp from model unless explicitly provided
vp = vp or self.model.vp
# Execute operator and return wavefield and receiver data
if self.kernel == 'sls':
# Execute operator and return wavefield and receiver data
# With Memory variable
summary = self.op_adj().apply(src=srca, rec=rec, pa=pa, r=r, b=b, vp=vp,
qp=qp, dt=kwargs.pop('dt', self.dt), **kwargs)
else:
summary = self.op_adj().apply(src=srca, rec=rec, pa=pa, vp=vp, b=b, qp=qp,
dt=kwargs.pop('dt', self.dt), **kwargs)
return srca, pa, va, summary
| 42.142857 | 89 | 0.575453 | 1 | 1.9026 | [
-0.02174144983291626,
0.0039507984183728695,
0.025528308004140854,
0.0011607815977185965,
-0.029106970876455307,
0.021687684580683708,
-0.010629900731146336,
-0.008738407865166664,
0.012002861127257347,
0.00586122740060091,
-0.004871029872447252,
0.014061550609767437,
0.03035246953368187,
0.001775476266629994,
-0.011617216281592846,
-0.0029243468306958675,
0.09023592621088028,
-0.02646397054195404,
-0.019148603081703186,
0.03052797168493271,
0.01865670271217823,
0.020240649580955505,
0.014483303762972355,
0.02492010034620762,
-0.005546804517507553,
0.010368476621806622,
-0.0034775049425661564,
-0.015034395270049572,
0.022568577900528908,
0.007924439385533333,
0.009824490174651146,
-0.011679067276418209,
-0.014868969097733498,
-0.031169909983873367,
-0.016001883894205093,
0.014850780367851257,
-0.003160994267091155,
0.03635181114077568,
-0.00918069388717413,
0.022987622767686844,
0.03608470782637596,
0.03125283122062683,
-0.0006975555443204939,
-0.011059085838496685,
-0.008213615976274014,
-0.007490586489439011,
-0.005146755371242762,
0.02308768965303898,
-0.008973198011517525,
0.02048901841044426,
0.019517844542860985,
0.027553407475352287,
0.01831258460879326,
-0.014675305224955082,
0.03730931505560875,
-0.038870397955179214,
0.007910857908427715,
-0.021766716614365578,
-0.015512854792177677,
-0.03593899682164192,
0.0024900103453546762,
-0.03193417936563492,
0.0030262689106166363,
-0.05795314162969589,
0.03992575779557228,
-0.01566253788769245,
-0.009435098618268967,
-0.014783523976802826,
0.009385878220200539,
0.022087104618549347,
-0.012919866479933262,
0.00830030720680952,
0.06008788198232651,
0.05444468557834625,
-0.05421777814626694,
0.010074056684970856,
0.01137901097536087,
-0.01533438265323639,
-0.0037609052378684282,
-0.006333473138511181,
-0.0191554743796587,
0.024715060368180275,
-0.004821381065994501,
-0.01360352523624897,
-0.00850785430520773,
0.06588227301836014,
0.008126117289066315,
-0.01957227848470211,
0.01756250113248825,
0.02074120007455349,
-0.0013489883858710527,
0.022670626640319824,
-0.040114663541316986,
-0.006411902140825987,
0.024014931172132492,
-0.06635066866874695,
-0.005305591505020857,
-0.023638950660824776,
0.035560060292482376,
0.03306661173701286,
0.011929119937121868,
0.006101551465690136,
-0.00458722747862339,
0.02730068378150463,
0.019495606422424316,
-0.02071020007133484,
-0.033335134387016296,
0.007960357703268528,
0.035603683441877365,
-0.013982303440570831,
-0.08870644867420197,
-0.028561806306242943,
-0.005603226367384195,
-0.041342634707689285,
-0.022094612941145897,
-0.025688275694847107,
0.001776119228452444,
0.006933947559446096,
-0.009734755381941795,
0.021765021607279778,
-0.000525097653735429,
-0.012710781767964363,
0.001595002831891179,
0.005327114835381508,
-0.04141392931342125,
-0.002978062257170677,
-0.014489000663161278,
0.017344152554869652,
0.0038575183134526014,
-0.014786000363528728,
0.003931322135031223,
-0.024419531226158142,
0.014833093620836735,
0.0071198102086782455,
-0.016816558316349983,
-0.007433339487761259,
0.00442508514970541,
-0.027953889220952988,
-0.04362797737121582,
0.012199551798403263,
-0.001562977791763842,
-0.029928993433713913,
0.00008573066588724032,
-0.002711100038141012,
0.010177478194236755,
-0.024694299325346947,
0.006868036463856697,
-0.0007825398351997137,
0.011119901202619076,
-0.011212038807570934,
0.029253900051116943,
-0.0020665829069912434,
-0.023984935134649277,
0.04960677772760391,
-0.01637861877679825,
0.007117790170013905,
0.03303596377372742,
-0.06427547335624695,
-0.011823954991996288,
0.014056266285479069,
0.0024034972302615643,
0.008687702938914299,
0.013014261610805988,
0.03459750488400459,
-0.010265364311635494,
-0.027205076068639755,
-0.012097013182938099,
-0.017842380329966545,
0.002604942535981536,
-0.020813127979636192,
0.000837034429423511,
0.004485854413360357,
-0.013253730721771717,
0.006093481555581093,
-0.032539378851652145,
0.017625153064727783,
0.0026457365602254868,
0.019892457872629166,
0.016199126839637756,
-0.030776290223002434,
0.003187333233654499,
0.0034792982041835785,
0.0057525113224983215,
-0.0001761803578119725,
-0.0237321425229311,
-0.015944059938192368,
-0.0021640872582793236,
-0.0037490238901227713,
0.008141937665641308,
-0.002378530567511916,
-0.0009272616007365286,
0.018026869744062424,
-0.019683266058564186,
0.015113514848053455,
-0.022292092442512512,
0.0026240607257932425,
-0.010031130164861679,
-0.018807027488946915,
-0.010562616400420666,
0.006443618331104517,
0.03639030084013939,
-0.04530428722500801,
-0.009468347765505314,
-0.004488144535571337,
-0.017490392550826073,
-0.008247206918895245,
-0.7763111591339111,
0.04404300078749657,
0.006509383209049702,
0.004865484777837992,
-0.0463443361222744,
0.02225811965763569,
-0.008672735653817654,
0.00833575613796711,
-0.05298202857375145,
-0.001737441518343985,
-0.01684219017624855,
-0.003716712584719062,
-0.049696024507284164,
0.022421924397349358,
0.03033318743109703,
-0.00014402512169908732,
-0.055472567677497864,
0.015710027888417244,
0.028055598959326744,
-0.017741449177265167,
0.002286570379510522,
0.026609811931848526,
-0.000841524510178715,
-0.00018622689822223037,
-0.0011897345539182425,
-0.03439982235431671,
0.04720064997673035,
-0.02516406960785389,
0.01627884991466999,
0.026823025196790695,
-0.014977166429162025,
-0.010568245314061642,
-0.018739691004157066,
0.011125992052257061,
-0.002979890676215291,
0.005756641738116741,
0.006371740717440844,
-0.01090080663561821,
-0.10380906611680984,
-0.006325688678771257,
-0.019092293456196785,
-0.010893495753407478,
-0.0150294853374362,
-0.007810171227902174,
-0.06810831278562546,
0.06684613227844238,
-0.04733336344361305,
-0.04631916061043739,
-0.0034786409232765436,
0.014019360765814781,
-0.014015833847224712,
0.007789754308760166,
0.01248537003993988,
-0.019212918356060982,
-0.004753149580210447,
0.0044608996249735355,
-0.007130876649171114,
-0.0023756243754178286,
-0.026494445279240608,
0.007796906400471926,
0.039545100182294846,
-0.00781702809035778,
0.02309057116508484,
-0.0051395222544670105,
-0.006553349085152149,
-0.028347797691822052,
-0.028603406623005867,
0.006507823243737221,
0.0006894582184031606,
0.03341233730316162,
0.011000492610037327,
0.03867427259683609,
-0.007575868628919125,
0.0520579069852829,
0.0045525976456701756,
0.00024012548965401947,
0.003734351135790348,
-0.005693839397281408,
0.052669502794742584,
-0.026059042662382126,
-0.003377431770786643,
0.022360507398843765,
-0.008715366013348103,
0.012533368542790413,
-0.03663981333374977,
0.033158425241708755,
-0.01910918578505516,
0.014202004298567772,
0.02443668432533741,
-0.0013251736527308822,
0.042005755007267,
0.038809891790151596,
0.012732616625726223,
0.011906095780432224,
-0.007165161427110434,
0.0387384258210659,
-0.020573394373059273,
0.01160952914506197,
0.0009080879390239716,
0.005681741517037153,
-0.016197659075260162,
-0.013153733685612679,
0.008087796159088612,
0.057818084955215454,
-0.0005547243054024875,
-0.011317615397274494,
-0.05725903809070587,
-0.012584209442138672,
0.017877694219350815,
-0.05628964677453041,
0.025880545377731323,
0.0013371121603995562,
-0.013793198391795158,
-0.011543935164809227,
0.019846497103571892,
0.014909910038113594,
0.00027713552117347717,
-0.017436670139431953,
0.014757290482521057,
-0.0015007344773039222,
0.00892813690006733,
-0.019747082144021988,
0.007153231650590897,
0.01875137910246849,
-0.01393563486635685,
0.013503318652510643,
-0.06705473363399506,
-0.02025078795850277,
-0.014320124872028828,
0.05935884267091751,
-0.03137454763054848,
0.020026391372084618,
-0.03137501701712608,
0.022101929411292076,
0.017001817002892494,
-0.0341729074716568,
-0.025886990129947662,
-0.0004872052522841841,
0.012493181973695755,
-0.026421943679451942,
-0.0012980521423742175,
-0.03573061525821686,
0.02779974415898323,
-0.03205077722668648,
-0.0019757160916924477,
-0.006146158091723919,
0.04490746185183525,
-0.0008520893752574921,
0.0072050378657877445,
-0.006557974498718977,
-0.007179632317274809,
-0.011086603626608849,
-0.01676769182085991,
0.014411022886633873,
-0.020249616354703903,
0.023158635944128036,
-0.01387341320514679,
0.021839413791894913,
0.00044985770364291966,
0.001778280595317483,
-0.017973996698856354,
-0.00802120566368103,
-0.016455966979265213,
-0.0004600220709107816,
-0.007188974414020777,
0.020786965265870094,
0.009120023809373379,
0.047454413026571274,
-0.017296670004725456,
-0.022144468501210213,
0.0005826413980685174,
0.00882416870445013,
-0.0013719936832785606,
0.0427403561770916,
0.016373740509152412,
0.02121138572692871,
-0.01756262592971325,
-0.018190985545516014,
0.016403278335928917,
0.026316868141293526,
0.005000369157642126,
0.021007083356380463,
-0.018755458295345306,
-0.0080410810187459,
-0.001950106001459062,
-0.007736079394817352,
0.013306764885783195,
0.009984595701098442,
0.008068838156759739,
-0.005623344797641039,
0.0025955992750823498,
-0.0013701192801818252,
-0.03316904604434967,
-0.015464697033166885,
-0.0159462783485651,
-0.03579315170645714,
-0.040532611310482025,
-0.0198715440928936,
-0.020998673513531685,
-0.013847757130861282,
0.0008699498139321804,
0.052207961678504944,
0.014285007491707802,
-0.014885147102177143,
0.015187565237283707,
0.036749377846717834,
-0.016420183703303337,
-0.009688088670372963,
-0.0043611545115709305,
-0.013338549062609673,
0.007872921414673328,
0.02047421783208847,
0.016631584614515305,
0.027373159304261208,
0.0032161870039999485,
-0.008497629314661026,
-0.04333361238241196,
-0.018505359068512917,
0.015248381532728672,
-0.014153499156236649,
-0.03471985086798668,
-0.010479510761797428,
0.013911816291511059,
-0.000026682382667786442,
-0.02759970724582672,
0.003696934087201953,
0.016990019008517265,
-0.045839760452508926,
0.025034276768565178,
-0.02170279435813427,
0.004045445472002029,
-0.025381391867995262,
-0.0356217585504055,
-0.01445812452584505,
0.00014905341959092766,
-0.007646182551980019,
-0.018812749534845352,
-0.026881685480475426,
0.008756337687373161,
-0.014034843072295189,
0.03702692314982414,
-0.025474563241004944,
-0.017600717023015022,
0.025021154433488846,
0.023385001346468925,
0.0037346130702644587,
0.043101966381073,
-0.036396224051713943,
0.00324269849807024,
0.006583331618458033,
-0.02638714574277401,
0.04636852443218231,
0.01911255158483982,
-0.0015007291221991181,
-0.004642276093363762,
-0.002750416286289692,
0.0011974001536145806,
0.023027943447232246,
0.013618097640573978,
0.0030414811335504055,
-0.00779792619869113,
-0.02341313287615776,
-0.004908418282866478,
0.002966509200632572,
-0.00754596758633852,
0.003922172822058201,
-0.01727396994829178,
0.027661170810461044,
-0.009505514055490494,
-0.010098753497004509,
-0.0019478934118524194,
-0.009578052908182144,
-0.01541581004858017,
-0.02673978917300701,
0.016257770359516144,
0.01036140602082014,
0.02163093350827694,
-0.027775460854172707,
-0.0025604369584470987,
0.052374083548784256,
-0.0256026741117239,
-0.004573679529130459,
-0.0041113439947366714,
0.02501397393643856,
0.0061418600380420685,
-0.015658266842365265,
-0.01891004852950573,
-0.02301621064543724,
-0.01311563327908516,
-0.013360634446144104,
0.0028277109377086163,
-0.012100646272301674,
-0.00916796550154686,
0.06817952543497086,
0.016783488914370537,
-0.0009450207580812275,
-0.008441684767603874,
-0.027344468981027603,
-0.021187083795666695,
0.024605141952633858,
0.030611397698521614,
-0.0016193159390240908,
0.00387119734659791,
0.01586073450744152,
0.000471445731818676,
0.022728174924850464,
0.003675818210467696,
0.017884546890854836,
0.012521623633801937,
0.014183328486979008,
0.01790761947631836,
0.03272275626659393,
-0.025551434606313705,
-0.04330725967884064,
0.02173484116792679,
0.019380973652005196,
0.0037321830168366432,
0.05069437250494957,
0.01095265056937933,
-0.021148281171917915,
0.0030029122717678547,
0.023834338411688805,
-0.018478067591786385,
-0.015739114955067635,
-0.009391657076776028,
-0.02439574897289276,
-0.007721679750829935,
-0.015556219033896923,
-0.009741092100739479,
-0.017293307930231094,
-0.016816558316349983,
0.03978772461414337,
0.03903057426214218,
0.0026441607624292374,
0.008436060510575771,
-0.007442360278218985,
-0.0030784374102950096,
0.002183787990361452,
-0.006685423199087381,
-0.02528945729136467,
0.006220594514161348,
-0.011223320849239826,
-0.018492581322789192,
0.0077896276488900185,
-0.0004970881855115294,
0.009071954526007175,
-0.03206611052155495,
0.04668741673231125,
0.008098996244370937,
0.05911357328295708,
-0.0073441555723547935,
0.001136569888330996,
0.008384021930396557,
-0.032561518251895905,
0.003593981033191085,
-0.04543045908212662,
0.03231998533010483,
-0.016310369595885277,
0.013060824014246464,
0.00950910896062851,
-0.00041595069342292845,
-0.013773170299828053,
-0.004481544252485037,
0.00011369853746145964,
0.036889899522066116,
-0.026368042454123497,
0.012953214347362518,
-0.0236043818295002,
0.007858886383473873,
0.0304199680685997,
-0.020170997828245163,
0.008810192346572876,
-0.020117804408073425,
-0.011617916636168957,
0.004270994570106268,
0.014287371188402176,
0.034630075097084045,
0.002358474303036928,
0.0010847141966223717,
-0.011637422256171703,
-0.001968679716810584,
-0.019383622333407402,
0.006475647445768118,
-0.007012183777987957,
0.013042699545621872,
-0.03587092459201813,
0.049712203443050385,
-0.006069269962608814,
0.01844373159110546,
-0.006773254834115505,
-0.008927241899073124,
0.01912764087319374,
0.00274268863722682,
0.0012258769711479545,
-0.004489448852837086,
-0.0038157240487635136,
-0.0034681600518524647,
0.0020154868252575397,
0.010498753748834133,
-0.012157827615737915,
0.0006160018383525312,
-0.016780056059360504,
-0.005262505263090134,
-0.0299066249281168,
0.022114338353276253,
-0.017637105658650398,
-0.004759891889989376,
0.0029604851733893156,
0.011693252250552177,
-0.02210979163646698,
0.030051900073885918,
0.022699669003486633,
-0.018326476216316223,
-0.009036310948431492,
0.03365151584148407,
0.008344488218426704,
-0.008703532628715038,
-0.002705206396058202,
0.043062545359134674,
0.003484868910163641,
-0.0353795625269413,
0.0357370525598526,
-0.0027415116783231497,
0.005438555963337421,
0.0012057049898430705,
-0.001299899653531611,
0.022986795753240585,
-0.0005428427830338478,
0.023964304476976395,
0.046784304082393646,
0.019528383389115334,
-0.06454885005950928,
-0.0024151999969035387,
0.0025629668962210417,
-0.0024538750294595957,
0.04693099111318588,
0.018368739634752274,
0.017545728012919426,
-0.019369563087821007,
0.0012937133433297276,
0.012009982950985432,
0.02064203843474388,
0.018448002636432648,
0.024211930111050606,
0.02942638471722603,
-0.04233518987894058,
0.029790937900543213,
0.015224114060401917,
0.005675209686160088,
-0.0026440571527928114,
-0.031038230285048485,
-0.00665343226864934,
0.02071196213364601,
0.0030341718811541796,
-0.002178556751459837,
0.02406153455376625,
-0.03852451965212822,
0.01498174387961626,
-0.01630351133644581,
0.04527571052312851,
0.007538112811744213,
0.0019756865222007036,
0.015120427124202251,
0.015229016542434692,
-0.038214072585105896,
0.0043589090928435326,
0.006432459689676762,
0.003578770440071821,
-0.011083251796662807,
0.010251869447529316,
0.013919517397880554,
-0.025381730869412422,
0.02755535952746868,
-0.00009005974425235763,
-0.004893869627267122,
0.016449907794594765,
-0.00125147495418787,
0.012476600706577301,
0.003924857825040817,
-0.05187445878982544,
-0.03532030060887337,
0.02237146720290184,
0.00004746740160044283,
-0.005026861559599638,
-0.0065239593386650085,
0.015553006902337074,
-0.0134934913367033,
-0.00996252242475748,
-0.018610980361700058,
0.013942522928118706,
-0.0018692841986194253,
-0.026954397559165955,
0.0008781187934800982,
0.02036825753748417,
0.011295516975224018,
-0.031723830848932266,
0.013119002804160118,
-0.000946069834753871,
0.02928951196372509,
-0.045032914727926254,
-0.0007966561825014651,
0.028239533305168152,
0.003406805917620659,
-0.0019578293431550264,
0.025495275855064392,
0.021396834403276443,
0.05376393347978592,
-0.00020351374405436218,
0.012379636988043785,
0.012133241631090641,
-0.01869140937924385,
-0.004624329507350922,
-0.016341915354132652,
-0.016901366412639618,
-0.0031774190720170736,
0.012055437080562115,
0.03190983086824417,
0.05978589132428169,
-0.020137399435043335,
-0.01982192136347294,
-0.008814849890768528,
-0.0008147498592734337,
-0.004951964598149061,
0.00391103932633996,
-0.029383225366473198,
-0.018328696489334106,
0.005946049466729164,
0.02528778277337551,
-0.0065433862619102,
0.026868591085076332,
-0.003769992385059595,
-0.008727523498237133,
-0.012072734534740448,
-0.007729539182037115,
0.005354680586606264,
-0.01100875437259674,
-0.024779625236988068,
0.019610924646258354,
-0.008010676130652428,
-0.03667061775922775,
0.03332553803920746,
0.03159751743078232,
0.003622695105150342,
0.0024321251548826694,
-0.0024771741591393948,
0.004946601111441851,
-0.014219202101230621,
0.014963081106543541,
-0.01016030739992857,
0.01790814846754074,
-0.02110571600496769,
0.004321757238358259,
-0.00843200646340847,
0.002311968244612217,
-0.04586513713002205,
0.000005289355613058433,
-0.004240365698933601,
-0.007815244607627392,
-0.0006786849116906524,
-0.008005437441170216,
0.0029889261350035667,
-0.009647449478507042
] |
8a2f3c798c33272d514bf543343fc4f88d9112f6 | 1,483 | py | Python | StaticProcess/apriori.py | NIL-zhuang/NJU-Data-Integration | 78315d33cda6b69dd16a4704fa8e0dfc6fc359b6 | [
"MIT"
] | null | null | null | StaticProcess/apriori.py | NIL-zhuang/NJU-Data-Integration | 78315d33cda6b69dd16a4704fa8e0dfc6fc359b6 | [
"MIT"
] | null | null | null | StaticProcess/apriori.py | NIL-zhuang/NJU-Data-Integration | 78315d33cda6b69dd16a4704fa8e0dfc6fc359b6 | [
"MIT"
] | null | null | null | import pandas as pd
import os
from tqdm import tqdm
from collections import defaultdict
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
dataPath = "data/static"
itemSetList = []
def loadDataSet():
with open(os.path.join(dataPath, "aprioriData.csv"), 'r') as f:
for line in f.readlines():
line = line.replace('\n', '')
cates = line.split(' ')
itemSetList.append(list(map(int, cates)))
def myApriori():
te = TransactionEncoder()
te_ary = te.fit(itemSetList).transform(itemSetList)
df = pd.DataFrame(te_ary, columns=te.columns_)
return df
def dataInit():
if os.path.exists(os.path.join(dataPath, "aprioriData.csv")):
return
df = pd.read_csv("data/static/static.csv")
user_category = defaultdict(set)
for idx, row in tqdm(df.iterrows(), total=df.shape[0], desc="category data generate"):
user_category[row['USER_ID']].add(row['CATEGORY_ID'])
with open(os.path.join(dataPath, "aprioriData.csv"), 'w+') as f:
for k, v in tqdm(user_category.items()):
f.write(' '.join(sorted(list(map(str, v))))+'\n')
if __name__ == '__main__':
dataInit()
loadDataSet()
df = myApriori()
frequent_itemsets = apriori(df, min_support=0.0035, use_colnames=True)
frequent_itemsets['length'] = frequent_itemsets['itemsets'].apply(lambda x: len(x))
print(frequent_itemsets[(frequent_itemsets['length'] >= 2)])
| 32.23913 | 90 | 0.666891 | 1 | 1.1826 | [
0.0004520108923316002,
0.02412262186408043,
0.007391582243144512,
0.0013099205680191517,
0.004972564056515694,
-0.003025258192792535,
-0.008808974176645279,
0.00429911632090807,
-0.009077848866581917,
0.002487115329131484,
0.0033149716909974813,
0.00445846701040864,
0.008256439119577408,
-0.017237486317753792,
-0.0004538146604318172,
0.01656237244606018,
-0.0527908131480217,
0.0020192854572087526,
-0.00414316076785326,
0.0019329318311065435,
-0.008922663517296314,
0.009069828316569328,
0.009049715474247932,
0.006721057463437319,
0.004732227418571711,
-0.0018522664904594421,
0.011912751942873001,
0.000941637612413615,
-0.008133509196341038,
-0.005100545473396778,
-0.0014958365354686975,
-0.0010821294272318482,
-0.006604508496820927,
-0.007737740408629179,
0.00626777671277523,
-0.0028829893562942743,
-0.00043405548785813153,
-0.019455432891845703,
0.012201446108520031,
-0.005646109580993652,
-0.006465781945735216,
-0.014712212607264519,
0.0011668610386550426,
0.004958685953170061,
-0.010058420710265636,
0.0034563508816063404,
-0.004094853065907955,
0.00215084757655859,
-0.01178588904440403,
0.004707596264779568,
-0.009605019353330135,
0.005057790782302618,
0.013048000633716583,
0.004382193088531494,
-0.004963613115251064,
-0.00612412067130208,
0.011995558626949787,
0.0013081656070426106,
-0.011786183342337608,
-0.0012979068560525775,
-0.005289363209158182,
-0.0018487994093447924,
0.004771302454173565,
0.0031664357520639896,
-0.017017867416143417,
-0.007096696645021439,
-0.005951185245066881,
0.0027035842649638653,
-0.00014232586545404047,
0.005626959260553122,
0.0027056278195232153,
0.000414675974752754,
0.0068059759214520454,
0.002800437156111002,
0.004096484277397394,
-0.004134686663746834,
-0.0018085925839841366,
0.0020429869182407856,
0.0085567282512784,
0.0037695998325943947,
0.00430859811604023,
-0.007313382811844349,
0.00558131281286478,
0.012330654077231884,
0.0141446553170681,
0.007259323727339506,
0.019216395914554596,
-0.010735814459621906,
0.0444907583296299,
0.006949310190975666,
-0.010102618485689163,
0.0019781705923378468,
-0.011205533519387245,
-0.002599861240014434,
-0.0033895617816597223,
-0.028714681044220924,
0.0004988368018530309,
-0.004208071157336235,
-0.0011857354547828436,
0.003035098547115922,
0.0005659321905113757,
0.0072528100572526455,
-0.0008027244475670159,
-0.0036100430879741907,
-0.009222861379384995,
0.011135251261293888,
-0.006925233174115419,
-0.0037281904369592667,
0.006357935722917318,
0.0034021197352558374,
-0.012768990360200405,
-0.00007650600309716538,
0.0011727657401934266,
-0.013141537085175514,
0.006141266785562038,
0.003221542341634631,
-0.005046581383794546,
0.05608456954360008,
-0.0023373730946332216,
0.003108976176008582,
-0.005348291713744402,
0.0007900148630142212,
0.003546525491401553,
0.006581603083759546,
0.009844818152487278,
-0.004269907716661692,
0.013790900819003582,
0.006482425611466169,
0.004845489282160997,
0.00904775783419609,
-0.0009118412272073328,
0.008287436328828335,
-0.004862751346081495,
-0.0014347134856507182,
0.0015166858211159706,
-0.008669358678162098,
0.00876622274518013,
-0.00047394869034178555,
-0.006442715879529715,
0.0005091209313832223,
-0.0005356566980481148,
-0.011286969296634197,
0.0019852754194289446,
-0.0032072842586785555,
0.0021749280858784914,
-0.011736762709915638,
-0.0027448527980595827,
-0.002210986567661166,
-0.0059975190088152885,
0.0032045303378254175,
0.008117709308862686,
0.003355990396812558,
0.003485636319965124,
-0.005183826200664043,
-0.00899038091301918,
-0.0006874390528537333,
-0.003809469984844327,
0.0028945286758244038,
0.0066760629415512085,
0.0032266948837786913,
-0.010617685504257679,
-0.0006875905091874301,
0.003248142311349511,
0.004537475295364857,
-0.0018851084169000387,
0.0023711479734629393,
-0.008917833678424358,
0.008749114349484444,
0.0003854758688248694,
0.004003901034593582,
0.01102906558662653,
-0.002860975218936801,
0.000021363306586863473,
0.00003147529059788212,
0.002033487195149064,
-0.0009195805760100484,
0.0050444104708731174,
0.01000863965600729,
-0.003865000559017062,
-0.005840794648975134,
0.0038772979751229286,
0.004951660521328449,
0.008127777837216854,
0.006017063744366169,
-0.0022040412295609713,
0.0034831250086426735,
-0.005268378648906946,
-0.0007141470559872687,
0.00687938928604126,
-0.0038756881840527058,
0.005252141039818525,
0.003442947054281831,
-0.015183228999376297,
-0.006830293219536543,
-0.0007893978036008775,
-0.008441997691988945,
0.0017649850342422724,
0.014368560165166855,
0.009520151652395725,
-0.00016395430429838598,
0.001901155454106629,
-0.01081604603677988,
-0.0013852296397089958,
0.006025363691151142,
0.002795261098071933,
-0.014089127071201801,
-0.9579700827598572,
0.005520999897271395,
0.005147630348801613,
-0.0016084244707599282,
0.005395861808210611,
0.002879868960008025,
0.0032994456123560667,
0.003957987762987614,
0.013765355572104454,
-0.010512799955904484,
-0.0068997666239738464,
-0.009092742577195168,
-0.010393345728516579,
-0.0019551559817045927,
-0.006872339639812708,
-0.0018984628841280937,
-0.005848251283168793,
-0.006761044729501009,
-0.0014186609769240022,
-0.004728787578642368,
-0.0017737785819917917,
0.00937023013830185,
-0.0026852453593164682,
0.005766698624938726,
0.0027161564212292433,
0.0019922929350286722,
-0.004896341357380152,
-0.0030347954016178846,
-0.002505760407075286,
-0.002208380028605461,
-0.005908159539103508,
-0.014671135693788528,
-0.004004540853202343,
0.000164612996741198,
0.010220453143119812,
0.0011846405686810613,
0.009581208229064941,
-0.002061634324491024,
0.0013537011109292507,
-0.009469360113143921,
0.006138054188340902,
-0.000039371847378788516,
0.003007636871188879,
-0.028694849461317062,
0.0003998861648142338,
-0.0013723594602197409,
-0.008248627185821533,
0.007933178916573524,
0.000671412970405072,
0.0002319230407010764,
-0.003958015702664852,
-0.006661543156951666,
0.009151913225650787,
-0.007456224411725998,
0.005422957707196474,
-0.006586219184100628,
-0.008506313897669315,
-0.00196325546130538,
-0.006797126494348049,
0.00020353548461571336,
0.0029099388048052788,
-0.004362012725323439,
-0.004927838686853647,
-0.004531079437583685,
0.003238290548324585,
0.0031222477555274963,
0.00215688394382596,
-0.018678026273846626,
-0.006539172492921352,
-0.002313330303877592,
0.002122275298461318,
-0.003529869019985199,
-0.0032500815577805042,
0.004219803027808666,
-0.009146135300397873,
0.006227409467101097,
0.00187883956823498,
0.00035922465031035244,
-0.010217070579528809,
-0.00031354950624518096,
-0.009283047169446945,
-0.00885329581797123,
0.0023801238276064396,
-0.0046187108382582664,
-0.005159099120646715,
-0.0012768100714311004,
0.0033072528894990683,
0.007999740540981293,
-0.004128248430788517,
0.0033663271460682154,
0.010956031270325184,
-0.004310785327106714,
-0.009502350352704525,
0.006589045282453299,
0.006054711062461138,
0.0017882304964587092,
-0.0040442682802677155,
0.003112049540504813,
0.00756762595847249,
0.008184830658137798,
0.0021019766572862864,
0.005327623337507248,
-0.0007150286692194641,
0.009231584146618843,
-0.0009438086999580264,
0.0014053802005946636,
-0.002297177677974105,
-0.0007427983800880611,
-0.003458557650446892,
-0.0016427735099568963,
-0.0040253219194710255,
-0.003342270152643323,
-0.011516721919178963,
-0.009749426506459713,
-0.0033030109480023384,
0.0004808950761798769,
0.0018886184552684426,
-0.004735924303531647,
0.0011903338599950075,
0.0021142633631825447,
0.010593665763735771,
0.0009139559115283191,
-0.003895378904417157,
-0.001274860231205821,
0.0009385170415043831,
-0.005990305915474892,
0.01610722206532955,
-0.010660788044333458,
0.005735810846090317,
-0.0018568886443972588,
-0.01476028747856617,
0.007934273220598698,
0.009770583361387253,
-0.009609661996364594,
0.0011254447745159268,
0.0014728299574926496,
0.0037153069861233234,
-0.00005180450898478739,
-0.005439913831651211,
-0.002927009016275406,
-0.01824394054710865,
-0.0009331972687505186,
0.018899722024798393,
0.0012798155657947063,
0.012171117588877678,
0.013448689132928848,
-0.0023114229552447796,
0.0006603988003917038,
0.00879786815494299,
-0.00017975068476516753,
0.013181653805077076,
-0.009527712129056454,
0.00010851011029444635,
0.0019835534039884806,
-0.006158697418868542,
0.0007557161152362823,
0.00590323144569993,
0.005570251494646072,
-0.0034385358449071646,
0.0016868137754499912,
-0.00663302605971694,
-0.004062967840582132,
-0.018192827701568604,
-0.0034363935701549053,
0.005631767679005861,
-0.004795072600245476,
0.004498152527958155,
-0.011837156489491463,
0.0035428060218691826,
0.005888169165700674,
0.004816785920411348,
-0.00009251214942196384,
0.0014053232735022902,
0.006646156311035156,
0.012342496775090694,
-0.005742018576711416,
0.002927901688963175,
0.0031483410857617855,
-0.002504489617422223,
0.002600481268018484,
0.007040947210043669,
-0.007956190966069698,
-0.005421245936304331,
0.0034916969016194344,
0.0038924962282180786,
0.00029609957709908485,
-0.00295978132635355,
-0.0077145714312791824,
-0.002689145738258958,
0.0015834226505830884,
-0.006659744307398796,
0.003072333987802267,
0.0014278822345659137,
0.003198182675987482,
-0.006546882446855307,
-0.0005138596170581877,
-0.0015842620050534606,
-0.011146245524287224,
0.009990203194320202,
-0.003371261991560459,
0.002342208754271269,
0.012767353095114231,
0.003855641931295395,
-0.013217584230005741,
0.006886166054755449,
0.00893914233893156,
-0.0035691268276423216,
0.004202600568532944,
0.007228297647088766,
-0.005714762955904007,
-0.02170400880277157,
-0.003048500744625926,
-0.014741907827556133,
0.006415016017854214,
-0.0034468802623450756,
0.0017744676442816854,
-0.007900191470980644,
0.007231683470308781,
0.00650528259575367,
-0.014405754394829273,
-0.004964890424162149,
-0.008751866407692432,
0.008768334984779358,
-0.0007650203770026565,
-0.0003564991056919098,
-0.0032936129719018936,
-0.001819478697143495,
-0.002792192855849862,
-0.002210275735706091,
-0.0013072279980406165,
0.005105022341012955,
0.0011508280877023935,
-0.00256038224324584,
0.0024409694597125053,
-0.001539345714263618,
0.0011963354190811515,
0.00019852173863910139,
-0.010697170160710812,
0.001253749243915081,
0.004237288609147072,
-0.0034542432986199856,
-0.002797710010781884,
0.002143068937584758,
-0.002212364226579666,
-0.008906724862754345,
-0.01219046302139759,
-0.005532344337552786,
-0.004903028719127178,
-0.00312229641713202,
-0.011694984510540962,
-0.0026284842751920223,
-0.009042714722454548,
0.007414735853672028,
-0.006252492778003216,
0.008751040324568748,
0.005009418819099665,
-0.005399174988269806,
0.005401420872658491,
-0.0023833056911826134,
0.005661064758896828,
0.002919968916103244,
0.005515799392014742,
-0.000013029096407990437,
-0.004878852516412735,
-0.0083853118121624,
0.011119692586362362,
-0.008868965320289135,
0.0017942239064723253,
0.013588152825832367,
0.00405504833906889,
0.009233229793608189,
-0.0014633394312113523,
-0.00000285033229374676,
0.002877809340134263,
0.007874717004597187,
-0.01363938394933939,
0.0038100213278084993,
-0.0035800288897007704,
0.00010362482134951279,
0.004708988592028618,
-0.0053094825707376,
0.001057166256941855,
0.007941163145005703,
0.0015121730975806713,
-0.006061255931854248,
-0.0008936108206398785,
0.002257182262837887,
0.0029303969349712133,
-0.012311541475355625,
0.0007121132803149521,
-0.0013751714723184705,
-0.0035026073455810547,
-0.0019178219372406602,
-0.0022247133310884237,
-0.000938720942940563,
0.0037438676226884127,
-0.0011344464728608727,
0.006276669446378946,
0.0035559204407036304,
-0.005519474856555462,
0.014316754415631294,
-0.0036303368397057056,
-0.0037859012372791767,
0.004565226845443249,
0.002092404756695032,
-0.0036816734354943037,
-0.007592079229652882,
-0.0016846543876454234,
0.0012262918753549457,
0.005656881723552942,
-0.0028351577930152416,
-0.004070847295224667,
-0.002065913286060095,
0.0023391807917505503,
-0.00887874886393547,
0.0002739769115578383,
0.010923396795988083,
-0.005026142578572035,
0.006650460418313742,
-0.00045145678450353444,
-0.007561547216027975,
-0.012985940091311932,
0.05409915745258331,
-0.0010161296231672168,
0.0023989230394363403,
0.005475277081131935,
-0.006476113107055426,
-0.0010779028525575995,
-0.0023514507338404655,
0.00832394789904356,
-0.008182176388800144,
-0.00732406135648489,
0.008479862473905087,
-0.004071209114044905,
0.003131352597847581,
0.003378460416570306,
-0.0025082863867282867,
0.017284542322158813,
-0.004581271670758724,
-0.018135376274585724,
-0.01602640561759472,
0.006029680836945772,
-0.002486494602635503,
-0.007056320086121559,
0.0082364771515131,
-0.003249326255172491,
-0.002620645333081484,
0.0013525593094527721,
0.0054517146199941635,
-0.000017019752704072744,
-0.002568615833297372,
-0.001047739409841597,
-0.00036300139618106186,
0.0005042481352575123,
0.003294908907264471,
0.007054958026856184,
0.009020314551889896,
-0.0014499404933303595,
0.003993517253547907,
-0.0017785545205697417,
-0.0011233631521463394,
-0.001054273103363812,
0.004890779964625835,
0.005774278659373522,
-0.0010022009955719113,
-0.0021694772876799107,
0.0051600756123661995,
0.003761402564123273,
0.0012366536539047956,
0.01189384050667286,
-0.0004535690532065928,
-0.0048521836288273335,
0.008373207412660122,
0.0077075962908566,
-0.0006889785872772336,
0.006823516450822353,
-0.0016095283208414912,
0.006085571367293596,
0.0016434782883152366,
-0.009802214801311493,
-0.013996483758091927,
-0.0018231758149340749,
0.008001690730452538,
0.00808787066489458,
-0.0013998025096952915,
0.0011617119889706373,
-0.00039752275915816426,
-0.0033035764936357737,
-0.007423738017678261,
-0.006163771729916334,
-0.002664069877937436,
0.0011737847235053778,
0.004462321288883686,
0.07013464719057083,
-0.007103271782398224,
-0.003592201042920351,
-0.008547411300241947,
-0.001901833456940949,
-0.002928755711764097,
-0.001213633338920772,
-0.00023982692800927907,
-0.0009794019861146808,
0.0012730266898870468,
0.0030288200359791517,
-0.008263207972049713,
-0.010847754776477814,
0.00168487592600286,
0.003077833214774728,
-0.0022000938188284636,
0.0035419745836406946,
0.005988325923681259,
-0.009049036540091038,
0.0010635326616466045,
-0.011437577195465565,
-0.0011981540592387319,
-0.00275903707370162,
-0.009476478211581707,
-0.00436596293002367,
-0.0031942715868353844,
0.003674606792628765,
0.00393964909017086,
0.004447695333510637,
-0.002542598405852914,
0.0070701465010643005,
-0.0021549698431044817,
0.00012222495570313185,
-0.0038141049444675446,
-0.00016819431039039046,
-0.0058348472230136395,
0.00920061394572258,
0.0006523107877001166,
-0.0106351962313056,
-0.004873865749686956,
0.00009753265476319939,
-0.0012378058163449168,
-0.006744726561009884,
0.004399600904434919,
-0.001176122110337019,
0.004144754260778427,
-0.002723871497437358,
0.00273212231695652,
-0.005486749112606049,
0.0013163648545742035,
-0.014110851101577282,
0.006010012701153755,
-0.17632758617401123,
0.011308311484754086,
0.002211976796388626,
-0.005132577382028103,
-0.004431172739714384,
-0.014081581495702267,
-0.007239992264658213,
0.004386805929243565,
0.009381982497870922,
0.002810235135257244,
-0.0017848293064162135,
-0.000859578256495297,
0.0049660904332995415,
0.003510627429932356,
-0.0025039659813046455,
-0.0035514694172888994,
0.003557685064151883,
-0.00513949990272522,
0.0021263521630316973,
0.004731347318738699,
0.0047392514534294605,
0.009097479283809662,
0.002421309007331729,
0.0026036929339170456,
-0.001350080012343824,
-0.004430316388607025,
0.004374102223664522,
-0.002445582766085863,
0.006705767009407282,
-0.010257892310619354,
-0.003518626093864441,
-0.0051644290797412395,
-0.002700574230402708,
-0.0005544650484807789,
0.0033187514636665583,
-0.00044392357813194394,
0.008665735833346844,
0.00046120924525894225,
-0.0086857033893466,
0.007822416722774506,
-0.007146414835005999,
0.029558727517724037,
0.005369875580072403,
0.005929231643676758,
0.0004887718241661787,
-0.0057142917066812515,
-0.003351295832544565,
0.008732651360332966,
0.003083466086536646,
0.012923886068165302,
-0.014323785901069641,
-0.001768512069247663,
0.0035119818057864904,
0.018579542636871338,
-0.004846541676670313,
-0.011518070474267006,
-0.007196440827101469,
-0.002336106961593032,
0.0036639547906816006,
0.007869595661759377,
0.011331906542181969,
-0.004193761385977268,
0.008624134585261345,
-0.003080526366829872,
-0.021627867594361305,
0.004823634400963783,
-0.004900800064206123,
-0.006228799931704998,
0.0007127732969820499,
0.008262512274086475,
0.009289868175983429,
-0.0028038539458066225,
0.0032734288834035397,
-0.0027740327641367912,
0.004827942233532667,
-0.00042698628385551274,
0.006409334018826485,
-0.003489445662125945,
0.004828782752156258,
-0.009363320656120777,
0.010389224626123905,
-0.007384248543530703,
-0.0003182139771524817,
0.00289196171797812,
-0.0038683218881487846,
0.010344003327190876,
0.004671774338930845,
-0.003025980433449149,
-0.0018761300016194582,
-0.009206167422235012,
-0.003051991108804941,
0.0019013757118955255,
0.003998851869255304,
-0.008964546956121922,
0.003605310106649995,
-0.00024750520242378116,
0.005124141462147236,
0.00821546372026205,
-0.009096193127334118,
0.005821232683956623,
0.004894118290394545,
-0.006956818979233503,
-0.0017823161324486136,
-0.003100163070484996,
0.0034154646564275026,
0.004207325167953968,
-0.00553881237283349,
-0.006492774933576584,
0.0038491247687488794,
-0.007158762309700251,
-0.005988438613712788,
0.005215329118072987,
-0.009743248112499714,
-0.006785253528505564,
-0.0015923456521704793,
-0.010126929730176926,
0.0012688158312812448
] |
8a2f400a7655554fbc57b5f622cd3afad8069e45 | 427 | py | Python | gcp-python-fn/main.py | FuriKuri/faas-playground | 52618e21064e327d2874d2b73cfe5fb247d3dd6e | [
"MIT"
] | 1 | 2019-05-07T13:15:16.000Z | 2019-05-07T13:15:16.000Z | gcp-python-fn/main.py | FuriKuri/faas-playground | 52618e21064e327d2874d2b73cfe5fb247d3dd6e | [
"MIT"
] | null | null | null | gcp-python-fn/main.py | FuriKuri/faas-playground | 52618e21064e327d2874d2b73cfe5fb247d3dd6e | [
"MIT"
] | null | null | null | def hello_world(request):
request_json = request.get_json()
name = 'World'
if request_json and 'name' in request_json:
name = request_json['name']
headers = {
'Access-Control-Allow-Origin': 'https://furikuri.net',
'Access-Control-Allow-Methods': 'GET, POST',
'Access-Control-Allow-Headers': 'Content-Type'
}
return ('Hello ' + name + '! From GCP + Python', 200, headers)
| 35.583333 | 66 | 0.620609 | 1 | 0.7746 | [
0.0002000003441935405,
0.028296101838350296,
0.006251232698559761,
0.002441384131088853,
0.00449927756562829,
-0.004892830736935139,
-0.01250616367906332,
0.005400561727583408,
-0.011103810742497444,
-0.0009742275578901172,
0.0010623307898640633,
0.0032137816306203604,
0.007941046729683876,
-0.01647818274796009,
0.0009641564101912081,
0.01735093630850315,
-0.05645628273487091,
0.0017184786265715957,
-0.004307070281356573,
0.0023966776207089424,
-0.011644050478935242,
0.011685122735798359,
0.007998012937605381,
0.01014726608991623,
0.007336081005632877,
0.0026287774089723825,
0.010616790503263474,
0.005026920698583126,
-0.009344391524791718,
-0.002262961817905307,
0.0024892513174563646,
-0.002977984491735697,
0.0018917409470304847,
-0.006630425341427326,
0.008359658531844616,
-0.0013660283293575048,
-0.000568235875107348,
-0.018504483625292778,
0.015201379545032978,
-0.011153727769851685,
-0.011186830699443817,
-0.020224811509251595,
-0.0009324377169832587,
0.0059822844341397285,
-0.013507356867194176,
0.001052105100825429,
-0.006876540370285511,
-0.00015063270984683186,
-0.009449794888496399,
0.007679769769310951,
-0.007828368805348873,
0.006565701216459274,
0.011086384765803814,
0.0023584903683513403,
-0.006554995197802782,
-0.008597827516496181,
0.008813511580228806,
-0.0009309680899605155,
-0.014362757094204426,
-0.0013277198886498809,
-0.004882813431322575,
-0.0030326158739626408,
0.004800124559551477,
0.005547903012484312,
-0.020922759547829628,
-0.0031306713353842497,
-0.004575940314680338,
-0.0010806858772411942,
-0.001845601131208241,
0.0037956046871840954,
0.0017898260848596692,
-0.002111824695020914,
0.0059581659734249115,
0.0053436956368386745,
0.008696473203599453,
-0.0003182959044352174,
-0.0015082816826179624,
0.005137328524142504,
0.006663600914180279,
0.0050557334907352924,
0.006199833005666733,
-0.013870778493583202,
0.0077697886154055595,
0.01782529056072235,
0.011985408142209053,
0.004442035686224699,
0.017276592552661896,
-0.01394957210868597,
0.041857462376356125,
0.007463538553565741,
-0.011400185525417328,
0.004280771128833294,
-0.008592613972723484,
-0.0011716359294950962,
-0.0014145405730232596,
-0.03233055770397186,
0.0005550758796744049,
-0.008788727223873138,
0.0009537372970953584,
0.005003176163882017,
0.00040869886288419366,
0.0011029478628188372,
-0.0023322596680372953,
-0.003086016746237874,
-0.014051114208996296,
0.021918872371315956,
-0.012336897663772106,
-0.0005853317561559379,
0.007553453557193279,
0.002719118958339095,
-0.013942703604698181,
-0.00036705585080198944,
0.004135860595852137,
-0.014077889733016491,
-0.00009718347428133711,
-0.00042738037882372737,
-0.004397680517286062,
0.05978933349251747,
0.0032286597415804863,
0.005982654169201851,
-0.004915566649287939,
-0.0071216546930372715,
-0.0012525903293862939,
0.007607950828969479,
0.008980323560535908,
-0.005803395994007587,
0.012165538035333157,
0.006583790760487318,
0.004125046078115702,
0.006302311085164547,
0.0015169244725257158,
0.008459802716970444,
-0.006696321535855532,
0.0010437197051942348,
-0.0007708024349994957,
-0.0049499101005494595,
0.008173806592822075,
-0.00015506529598496854,
-0.001709797652438283,
0.001770555041730404,
-0.0014013806357979774,
-0.01655471883714199,
0.00334198959171772,
-0.0007317211711779237,
-0.003262554993852973,
-0.015060357749462128,
-0.006441646721214056,
-0.005386927630752325,
-0.007695306558161974,
0.0034562647342681885,
0.00881567969918251,
0.003164128167554736,
0.0005885158316232264,
-0.0066245971247553825,
-0.005212803371250629,
-0.005056816153228283,
-0.005794009193778038,
0.003363389056175947,
0.006822607479989529,
-0.0015855253441259265,
-0.007864267565310001,
-0.005506779067218304,
0.006957009434700012,
0.003759053535759449,
-0.0024433527141809464,
0.0017787818796932697,
-0.004981087986379862,
0.009366136975586414,
0.002689535031095147,
0.003285143058747053,
0.014581505209207535,
-0.00726967491209507,
-0.003064027288928628,
0.0002476412046235055,
0.0004896334139630198,
0.0001610070321476087,
0.004741516895592213,
0.004629859700798988,
-0.010050761513411999,
-0.002872372977435589,
0.008981450460851192,
0.003090876853093505,
0.0077231163159012794,
0.010835666209459305,
0.0007795843994244933,
0.0022370812948793173,
-0.004906726535409689,
-0.0002807760611176491,
0.0027714476455003023,
-0.004737961106002331,
0.009421694092452526,
0.005309131927788258,
-0.016944611445069313,
-0.005913627799600363,
0.0029164000879973173,
-0.013283513486385345,
-0.0003702407702803612,
0.014959167689085007,
0.008717783726751804,
0.0017941942205652595,
0.0047568571753799915,
-0.012800115160644054,
0.0005896143265999854,
0.004197543486952782,
-0.0004011586424894631,
-0.013758275657892227,
-0.9507500529289246,
0.002413505222648382,
0.004341564606875181,
0.002908302703872323,
0.0029727534856647253,
-0.00136643520090729,
0.0001494290045229718,
0.004463035613298416,
0.009949746541678905,
-0.015507673844695091,
-0.0038988948799669743,
-0.013711684383451939,
-0.011399137787520885,
-0.0003114262653980404,
-0.008417799137532711,
-0.0039031291380524635,
-0.006494887638837099,
-0.011912950314581394,
-0.0016461808700114489,
-0.003866806859150529,
-0.004459400661289692,
0.008398620411753654,
-0.001995066413655877,
0.00750482315197587,
0.0033304940443485975,
0.00047715604887343943,
-0.006578716915100813,
-0.0006870845681987703,
0.007406584918498993,
-0.0004992061294615269,
-0.002006102818995714,
-0.018100814893841743,
-0.005440295208245516,
0.00030581903411075473,
0.012490988709032536,
-0.0012844097800552845,
0.007930666208267212,
-0.0034747039899230003,
0.0001897645415738225,
-0.01131673064082861,
0.005764168221503496,
0.00363962072879076,
0.0007295503164641559,
-0.02876480668783188,
0.004256381653249264,
-0.003631862113252282,
-0.009384384378790855,
0.012588860467076302,
0.002076486125588417,
-0.0013589153531938791,
0.0016774162650108337,
-0.002220663707703352,
0.013203054666519165,
-0.005230465903878212,
0.002453778637573123,
-0.003045983612537384,
-0.0019631695467978716,
-0.0037127258256077766,
-0.008296830579638481,
0.002248024335131049,
0.0029709674417972565,
-0.005422794725745916,
-0.0032734910491853952,
-0.00461365794762969,
0.0009434079984202981,
-0.001523321378044784,
0.0038287672214210033,
-0.018939176574349403,
-0.004878218751400709,
-0.0038826095405966043,
0.004009416326880455,
-0.005014694295823574,
-0.004517241846770048,
0.0015121042961254716,
-0.011374318972229958,
0.0047043124213814735,
0.0012705352855846286,
0.006542006507515907,
-0.012938877567648888,
0.0033282884396612644,
-0.005489726085215807,
-0.012669905088841915,
0.0022031348198652267,
-0.002635324141010642,
-0.007354536093771458,
0.004338264465332031,
0.007340793032199144,
0.0073456671088933945,
-0.004036448430269957,
-0.0021991028916090727,
0.009289714507758617,
-0.0045395405031740665,
-0.00787874311208725,
0.008892065845429897,
0.004449412226676941,
0.0003679415676742792,
0.00019636056094896048,
0.00612348597496748,
0.009644794277846813,
0.008929080329835415,
0.00031819718424230814,
0.0019644417334347963,
0.00030216906452551484,
0.015242638997733593,
0.0006642849184572697,
-0.00007491257565561682,
0.0030123551841825247,
-0.0014637337299063802,
-0.0008165483013726771,
0.001126762363128364,
-0.00271994830109179,
-0.0008144709863699973,
-0.011717628687620163,
-0.01065992284566164,
-0.004745601210743189,
0.0027481920551508665,
-0.0017058511730283499,
-0.005343096796423197,
-0.0005287380772642791,
0.0029850027058273554,
0.011931614018976688,
0.0007939384668134153,
-0.009296385571360588,
0.0008480324177071452,
0.002885030582547188,
-0.01097829733043909,
0.016544651240110397,
-0.00933306198567152,
0.004716417286545038,
-0.0037435225676745176,
-0.018109451979398727,
0.009124146774411201,
0.010070501826703548,
-0.008866116404533386,
0.005322722718119621,
0.004822500981390476,
0.00409485399723053,
-0.0025022123008966446,
-0.004645343404263258,
-0.004993998445570469,
-0.019510800018906593,
-0.0045066531747579575,
0.02275559864938259,
0.005928865168243647,
0.013116659596562386,
0.013302628882229328,
-0.002012234413996339,
-0.0016672138590365648,
0.009006171487271786,
0.002035311656072736,
0.016901474446058273,
-0.007907356135547161,
-0.0009462250745855272,
-0.0010541791561990976,
-0.00317586911842227,
0.0004714364476967603,
-0.0003469426592346281,
0.005200028419494629,
0.002484539756551385,
0.0009091514511965215,
-0.007135122083127499,
-0.006751473527401686,
-0.01415336038917303,
0.0024848480243235826,
0.005139172077178955,
-0.003124419366940856,
0.00077117356704548,
-0.007979613728821278,
0.007055428810417652,
0.00469279196113348,
0.0038282533641904593,
0.001500369980931282,
0.002413082169368863,
0.010574311949312687,
0.011594620533287525,
-0.005511816591024399,
0.0064089312218129635,
0.0005081493873149157,
0.00015856206300668418,
0.006054816767573357,
0.009669283404946327,
-0.009647292084991932,
-0.006544886156916618,
0.00547699723392725,
0.0017321028281003237,
0.00022132373123895377,
-0.004242595750838518,
-0.007084858603775501,
-0.00242109433747828,
0.0030359262600541115,
-0.002932819304987788,
0.002904708730056882,
0.0017537962412461638,
0.002047664951533079,
-0.012319942004978657,
-0.000012187428183096927,
-0.0027063116431236267,
-0.007536689750850201,
0.007975533604621887,
-0.004245180636644363,
0.004251211415976286,
0.011396865360438824,
0.0013317835982888937,
-0.014263407327234745,
0.006183233577758074,
0.004620909225195646,
-0.008631069213151932,
0.0033658554311841726,
0.011562656611204147,
-0.0054156421683728695,
-0.020840484648942947,
0.002365649212151766,
-0.01730353944003582,
0.006535071413964033,
-0.00015291957242880017,
0.007023483980447054,
-0.00833613146096468,
0.011037696152925491,
0.006773425731807947,
-0.013991213403642178,
-0.0006096342694945633,
-0.009184001944959164,
0.010981409810483456,
-0.000975881761405617,
-0.0020614604000002146,
-0.004235352389514446,
-0.0011964354198426008,
-0.006232403684407473,
-0.0002704361395444721,
0.003053028369322419,
0.005083361174911261,
0.003332228399813175,
-0.0022161819506436586,
0.0032667925115674734,
-0.0011208700016140938,
-0.0016988381976261735,
0.004820683971047401,
-0.009548896923661232,
-0.0002613393880892545,
0.008796034380793571,
-0.003874319838359952,
-0.005923496559262276,
-0.00015341989637818187,
0.0014156103134155273,
-0.008530410006642342,
-0.011301863938570023,
0.0013924967497587204,
-0.00359390489757061,
-0.004141401965171099,
-0.00833207555115223,
-0.0007489583804272115,
-0.008105991408228874,
0.010301696136593819,
-0.008561544120311737,
0.010573156177997589,
0.006851212587207556,
-0.007083562668412924,
0.008194712921977043,
-0.0009247342240996659,
0.003878368530422449,
0.001219605328515172,
0.006502262782305479,
0.002573037054389715,
-0.005728856194764376,
-0.011756709776818752,
0.012554016895592213,
-0.010706617496907711,
-0.0003016000846400857,
0.01255180686712265,
0.00788398738950491,
0.010292085818946362,
-0.00022379824076779187,
-0.002036117482930422,
0.007940246723592281,
0.008084965869784355,
-0.01435963623225689,
0.001741628861054778,
-0.002058043610304594,
0.0022643343545496464,
0.006075010169297457,
-0.009703870862722397,
0.007476736791431904,
0.005590716376900673,
0.003373719984665513,
-0.006422322243452072,
0.0011325152590870857,
-0.002598128980025649,
0.006270853336900473,
-0.011724279262125492,
0.0011261197505518794,
-0.008224408142268658,
-0.0043929885141551495,
-0.006852211430668831,
-0.0040128580294549465,
0.0006222052616067231,
0.00553426519036293,
-0.005064094439148903,
0.004026342649012804,
-0.001333441468887031,
-0.001083443989045918,
0.01850930228829384,
-0.004978266544640064,
-0.004839136730879545,
0.004557004198431969,
0.0023884382098913193,
0.0011880591046065092,
-0.007892372086644173,
-0.005424988456070423,
0.0007488718838430941,
0.0035608122125267982,
-0.0002977160911541432,
-0.011750838719308376,
-0.0002320025087101385,
-0.0030803184490650892,
-0.003445176873356104,
-0.00033815682400017977,
0.010243847966194153,
0.0012552269035950303,
0.004901725333184004,
-0.0015418841503560543,
-0.006115213502198458,
-0.017114384099841118,
0.05571461468935013,
-0.001569475862197578,
0.005901957396417856,
0.006866406183689833,
-0.007139682304114103,
-0.002370328875258565,
-0.0010633931960910559,
0.004401741083711386,
-0.005449594464153051,
-0.009440002031624317,
0.009210117161273956,
0.0009014561073854566,
0.0026288817171007395,
-0.0023672122042626143,
-0.0027328399010002613,
0.013982357457280159,
-0.00941881537437439,
-0.013871142640709877,
-0.013281469233334064,
0.008781015872955322,
-0.006939453538507223,
-0.008873283863067627,
0.006830735132098198,
-0.003120572306215763,
-0.0005114556406624615,
-0.0004962343955412507,
0.0076675680465996265,
-0.00017450397717766464,
-0.0017681305762380362,
-0.0029270523227751255,
0.0006250090664252639,
0.00228738971054554,
0.004442332778126001,
0.00391308031976223,
0.011360608972609043,
-0.0028963920194655657,
0.007565631065517664,
-0.001440766267478466,
0.00008346542745130137,
-0.002367662498727441,
0.008322921581566334,
0.007850507274270058,
-0.001960662892088294,
-0.0030996818095445633,
0.003877645591273904,
0.0037761065177619457,
-0.0023297732695937157,
0.012233556248247623,
0.003439672291278839,
-0.0032516915816813707,
0.008457007817924023,
0.009885622188448906,
-0.0042251106351614,
0.005518386140465736,
-0.0041253953240811825,
0.0036056372337043285,
0.00225213379599154,
-0.004584734793752432,
-0.018030349165201187,
-0.0035946439020335674,
0.005351838655769825,
0.008797317743301392,
-0.0018916917033493519,
-0.000004705806986748939,
-0.0013724882155656815,
-0.0035117354709655046,
-0.007388943340629339,
-0.005344389472156763,
-0.001069873571395874,
-0.003049459308385849,
0.004283074289560318,
0.07557240128517151,
-0.010658517479896545,
-0.0010954852914437652,
-0.010351997800171375,
0.0034697228111326694,
0.00012683038949035108,
-0.003372190287336707,
-0.0012693837052211165,
0.0032281577587127686,
0.0003571278939489275,
0.004796699620783329,
-0.009196523576974869,
-0.007107133977115154,
0.002255399711430073,
0.0025001182220876217,
-0.002297048456966877,
0.002728587482124567,
0.009084464982151985,
-0.00844574999064207,
0.006187986582517624,
-0.011203695088624954,
-0.0013127477141097188,
-0.004661177285015583,
-0.008405213244259357,
-0.003674177685752511,
-0.0070446631871163845,
0.003679303452372551,
0.005460277199745178,
0.007111314218491316,
-0.005315092857927084,
0.004614405333995819,
-0.0022329441271722317,
0.0052987998351454735,
-0.0036873153876513243,
-0.0013369746739044785,
-0.0025858189910650253,
0.005922497250139713,
0.0042298175394535065,
-0.01128213107585907,
-0.003513682633638382,
-0.000589066999964416,
-0.0010326943593099713,
-0.0123377600684762,
0.007499131374061108,
-0.004297914914786816,
0.013054515235126019,
-0.0031061829067766666,
0.0009442994487471879,
-0.0036573491524904966,
0.003576789516955614,
-0.016060683876276016,
0.005627347156405449,
-0.1891089379787445,
0.013365991413593292,
-0.0020215120166540146,
-0.004316509701311588,
-0.0058694821782410145,
-0.01569334976375103,
-0.01233672071248293,
0.0039537749253213406,
0.008301010355353355,
0.0019616640638560057,
-0.00029961278778500855,
-0.004314024932682514,
0.00760563975200057,
0.002160507021471858,
0.0014274334535002708,
-0.0032743553165346384,
0.0012702117674052715,
-0.0020727182272821665,
-0.00302333221770823,
0.006028997711837292,
0.003248548833653331,
0.008245587348937988,
0.0015850004274398088,
0.003627131227403879,
-0.00013384601334109902,
-0.0022692878264933825,
0.0029361287597566843,
-0.004072628915309906,
0.0015437473775818944,
-0.01224597729742527,
-0.0026671222876757383,
-0.007218790706247091,
-0.007558511570096016,
0.002961877267807722,
0.007059240713715553,
-0.005953753832727671,
0.008819619193673134,
0.00404746737331152,
-0.004990574438124895,
0.005368749611079693,
-0.008895531296730042,
0.027216380462050438,
0.006358799058943987,
0.01328741479665041,
0.003377682762220502,
-0.0040428959764540195,
-0.007088406942784786,
0.011008554138243198,
0.0025008399970829487,
0.015222224406898022,
-0.011022957973182201,
-0.00887919683009386,
-0.002773676533252001,
0.020991330966353416,
-0.005884366109967232,
-0.011164572089910507,
-0.00845672283321619,
-0.009113670326769352,
0.0069612557999789715,
0.013744805939495564,
0.009197426028549671,
0.00014136306708678603,
0.006534998305141926,
-0.0025372952222824097,
-0.021951286122202873,
0.0037086985539644957,
-0.00261581689119339,
-0.006152306217700243,
-0.00018956309941131622,
0.0037611224688589573,
0.013673338107764721,
-0.00528982887044549,
0.007193022407591343,
0.002463298151269555,
0.00021773544722236693,
-0.0022392156533896923,
0.00708227651193738,
-0.007235451601445675,
0.006884644739329815,
-0.006076878402382135,
0.015024621970951557,
-0.011818530037999153,
-0.0013663993449881673,
0.001839522970840335,
-0.005699133966118097,
0.012970196083188057,
0.005903798155486584,
-0.00231464602984488,
0.005475188139826059,
-0.012818067334592342,
-0.005935785360634327,
-0.002113637514412403,
0.005304393358528614,
-0.007874610833823681,
0.002743765013292432,
-0.002192984102293849,
0.0013552696909755468,
0.008448917418718338,
-0.007428143173456192,
0.006662084721028805,
0.005524976644665003,
-0.008105291053652763,
-0.0007159391534514725,
-0.0050929393619298935,
0.003870793618261814,
0.0018523642793297768,
-0.01066083274781704,
-0.012682992033660412,
0.005148258525878191,
-0.003154268255457282,
-0.005546413362026215,
-0.0022333660162985325,
-0.011024216189980507,
-0.005411874502897263,
-0.0026712464168667793,
-0.009709233418107033,
-0.000347861583577469
] |
8a3098e50d11c10c71215d547da0dfbd833ce050 | 1,205 | py | Python | tonclient/test/helpers.py | move-ton/ton-client-py | a9393a0e03b5da9bf5369a44c6873a3e720af229 | [
"Apache-2.0"
] | 28 | 2020-10-29T06:57:32.000Z | 2022-03-20T12:26:14.000Z | tonclient/test/helpers.py | move-ton/ton-client-py | a9393a0e03b5da9bf5369a44c6873a3e720af229 | [
"Apache-2.0"
] | 1 | 2021-03-30T18:18:17.000Z | 2021-04-04T15:35:10.000Z | tonclient/test/helpers.py | move-ton/ton-client-py | a9393a0e03b5da9bf5369a44c6873a3e720af229 | [
"Apache-2.0"
] | 8 | 2020-10-28T20:11:52.000Z | 2022-01-12T12:28:02.000Z | import os
from tonclient.client import TonClient
from tonclient.types import Abi, CallSet, Signer, ClientConfig, \
ParamsOfEncodeMessage, ParamsOfProcessMessage
BASE_DIR = os.path.dirname(__file__)
SAMPLES_DIR = os.path.join(BASE_DIR, 'samples')
GIVER_ADDRESS = '0:f5c2510bfe407363cb1db6b9d7bc1184a05f8b343aeaa828189c580e8569ee23'
client_config = ClientConfig()
client_config.network.endpoints = ['https://tonos.freeton.surf']
async_core_client = TonClient(config=client_config)
sync_core_client = TonClient(config=client_config, is_core_async=False)
def send_grams(address: str):
giver_abi = Abi.from_path(
path=os.path.join(SAMPLES_DIR, 'Giver.abi.json'))
call_set = CallSet(
function_name='grant', input={'dest': address})
encode_params = ParamsOfEncodeMessage(
abi=giver_abi, signer=Signer.NoSigner(), address=GIVER_ADDRESS,
call_set=call_set)
process_params = ParamsOfProcessMessage(
message_encode_params=encode_params, send_events=False)
async_core_client.processing.process_message(params=process_params)
def tonos_punch():
send_grams(
address='0:b5e9240fc2d2f1ff8cbb1d1dee7fb7cae155e5f6320e585fcc685698994a19a5')
| 36.515152 | 85 | 0.778423 | 1 | 1.1226 | [
0.0026200059801340103,
0.025710346177220345,
0.011272653937339783,
0.0007387378718703985,
0.0054959747940301895,
-0.0017712271073833108,
-0.007988751865923405,
0.002918776823207736,
-0.00535848131403327,
0.0036628858651965857,
0.003478562692180276,
0.006593924015760422,
0.007421385496854782,
-0.017975065857172012,
-0.0006448892527259886,
0.016787955537438393,
-0.052128903567790985,
0.0007299303542822599,
-0.005342934746295214,
0.004013375379145145,
-0.007246149238198996,
0.008536174893379211,
0.010087494738399982,
0.006284573581069708,
0.005303399171680212,
-0.00021552667021751404,
0.008954405784606934,
0.002598564838990569,
-0.007464941591024399,
-0.007242539431899786,
0.000983154634013772,
-0.0024211120326071978,
-0.00784100592136383,
-0.005919784307479858,
0.005375041160732508,
-0.003275769529864192,
0.001979970606043935,
-0.01758154295384884,
0.013742775656282902,
-0.006327702198177576,
-0.006911050528287888,
-0.017697421833872795,
0.0018490634392946959,
0.004202434793114662,
-0.009913135319948196,
0.0010611193720251322,
-0.00414632773026824,
0.0022206855937838554,
-0.010959198698401451,
0.005628046113997698,
-0.009734179824590683,
0.00656880484893918,
0.014128407463431358,
0.0028134931344538927,
-0.004798342939466238,
-0.009082737378776073,
0.012737493962049484,
-0.00018400269618723541,
-0.013042241334915161,
0.00016685971058905125,
-0.0035209907218813896,
-0.0015086057828739285,
0.005177319515496492,
0.003837642725557089,
-0.016555605456233025,
-0.007091239560395479,
-0.004911105614155531,
0.0024249095004051924,
-0.003002156736329198,
0.005396828521043062,
0.0011064170394092798,
-0.0025977143086493015,
0.005358505994081497,
0.003602840704843402,
0.003563525853678584,
-0.003411297919228673,
-0.0020855830516666174,
0.00007573562470497563,
0.008219027891755104,
0.002193290740251541,
0.006312227342277765,
-0.0067562987096607685,
0.004338375758379698,
0.010273761115968227,
0.016427649185061455,
0.009822595864534378,
0.01955527812242508,
-0.011491680517792702,
0.045868728309869766,
0.009423961862921715,
-0.00925805326551199,
0.002434259280562401,
-0.007702135480940342,
-0.0030064003076404333,
-0.0025754363741725683,
-0.02780204266309738,
-0.00012460534344427288,
-0.0032862750813364983,
-0.00003119526809314266,
0.003115559695288539,
-0.0012838814873248339,
0.007878481410443783,
-0.0028043733909726143,
-0.003306556260213256,
-0.007864964194595814,
0.011932200752198696,
-0.009326054714620113,
-0.0035921891685575247,
0.006715612486004829,
-0.00034959494951181114,
-0.009624747559428215,
-0.0016885417280718684,
0.004664498381316662,
-0.0138905243948102,
0.002122624311596155,
0.0029953750781714916,
-0.007584684994071722,
0.054320573806762695,
0.00033591638202778995,
0.0025269004981964827,
-0.004195353947579861,
-0.0014187560882419348,
0.002316566649824381,
0.006366581190377474,
0.009567853063344955,
-0.004404732491821051,
0.013185949996113777,
0.010852617211639881,
0.0023179769050329924,
0.007692195940762758,
-0.0025178370997309685,
0.008592342026531696,
-0.0033950270153582096,
-0.0021310271695256233,
0.00316567812114954,
-0.007110239937901497,
0.008340527303516865,
-0.0028320825658738613,
-0.008785170502960682,
0.0005074492655694485,
-0.0009814024670049548,
-0.011191505938768387,
0.0024418262764811516,
-0.003678828477859497,
0.004366591572761536,
-0.011742625385522842,
-0.004226610530167818,
-0.005558931268751621,
-0.005120818968862295,
0.0024256519973278046,
0.009184964932501316,
0.004162131808698177,
0.004173640627413988,
-0.004025685600936413,
-0.0070540569722652435,
-0.0022186371497809887,
-0.0033797009382396936,
0.0029276248533278704,
0.008440416306257248,
0.002109266584739089,
-0.009070740081369877,
-0.002240478526800871,
0.003126550232991576,
0.0037095332518219948,
-0.0022159195505082607,
0.00041961052920669317,
-0.009136688895523548,
0.006614683661609888,
0.00003444042886258103,
0.004594020079821348,
0.010635830461978912,
-0.002977442927658558,
0.000546193914487958,
-0.0001064280659193173,
0.00023307839001063257,
-0.00014652597019448876,
0.0035121918190270662,
0.010967256501317024,
-0.002509794430807233,
-0.0052731335163116455,
0.004044420551508665,
0.006218569818884134,
0.010316134430468082,
0.007284423802047968,
-0.0025325471069663763,
0.0019445496145635843,
-0.0038762192707508802,
-0.0008880487293936312,
0.005775184370577335,
-0.00392856216058135,
0.005787753965705633,
0.0043213278986513615,
-0.01506809238344431,
-0.00926766637712717,
0.002159773837774992,
-0.010132996365427971,
0.003280641743913293,
0.015586531721055508,
0.010289720259606838,
-0.003416758496314287,
0.0013086798135191202,
-0.008262686431407928,
0.0013290934730321169,
0.007596277631819248,
0.0016959953354671597,
-0.012156366370618343,
-0.9579689502716064,
0.005775914527475834,
0.002677558222785592,
-0.002409257460385561,
0.0037954619619995356,
0.0032190526835620403,
0.0024438987020403147,
0.0037171777803450823,
0.013997106812894344,
-0.009313869290053844,
-0.005465396214276552,
-0.010289695113897324,
-0.010248398408293724,
-0.0018678033957257867,
-0.008065175265073776,
-0.004640929400920868,
-0.005383776035159826,
-0.006067938171327114,
-0.0018259843345731497,
-0.0027484390884637833,
-0.002514489693567157,
0.008165169507265091,
0.0021570713724941015,
0.004882300738245249,
0.002602853812277317,
0.0030491237994283438,
-0.0044760084711015224,
0.00007981155795278028,
-0.00303327152505517,
-0.002507624216377735,
-0.00443196902051568,
-0.014554768800735474,
-0.004785888362675905,
-0.0022905059158802032,
0.012030784040689468,
-0.0010313065722584724,
0.009250904433429241,
-0.002259142231196165,
0.0037649318110197783,
-0.008394838310778141,
0.0058687306009233,
-0.0017047019209712744,
0.0021557698491960764,
-0.030211692675948143,
0.0010295403189957142,
-0.0016065641539171338,
-0.010072855278849602,
0.0060034445486962795,
-0.0004250258789397776,
0.00006937492435099557,
-0.003443322377279401,
-0.005135590676218271,
0.009852255694568157,
-0.0070498306304216385,
0.003985059447586536,
-0.0039320881478488445,
-0.005722056608647108,
-0.002403135411441326,
-0.008984854444861412,
0.0005117790424264967,
0.004101456142961979,
-0.005789537914097309,
-0.0046453033573925495,
-0.0016095711616799235,
0.0021115047857165337,
0.0024775839410722256,
0.0020547215826809406,
-0.01861816830933094,
-0.005413570441305637,
-0.00045080058043822646,
0.002232123166322708,
-0.002716752700507641,
-0.00201797136105597,
0.004701998550444841,
-0.009124300442636013,
0.005798900034278631,
0.0009327714215032756,
-0.0018676245817914605,
-0.010659364052116871,
0.00042121612932533026,
-0.008711900562047958,
-0.008972556330263615,
0.002979041775688529,
-0.004983787890523672,
-0.004553996492177248,
-0.00048297079047188163,
0.002456432208418846,
0.0077657136134803295,
-0.0049143764190375805,
0.0048159705474972725,
0.011047696694731712,
-0.004186015576124191,
-0.009406739845871925,
0.007309055421501398,
0.004754486493766308,
-0.0015148780075833201,
-0.0017717996379360557,
0.002383986720815301,
0.00660373829305172,
0.0053083146922290325,
0.0007206368027254939,
0.004997937940061092,
-0.0016034250147640705,
0.011068460531532764,
-0.0009181058849208057,
0.00247581978328526,
-0.0027765370905399323,
-0.0014603330055251718,
-0.0061869933269917965,
-0.0002458376984577626,
-0.0029294558335095644,
0.00001120214983529877,
-0.012829530984163284,
-0.008315473794937134,
-0.0018377258675172925,
0.0007185256108641624,
0.0020139191765338182,
-0.004820159636437893,
-0.000055547636293340474,
0.0012086955830454826,
0.0077744778245687485,
-0.0005728433607146144,
-0.006115050986409187,
0.0010891647543758154,
0.0016676281811669469,
-0.007285859901458025,
0.01566794142127037,
-0.011166010051965714,
0.0055412836372852325,
-0.0008552883518859744,
-0.016629740595817566,
0.007945893332362175,
0.01033969409763813,
-0.008971909992396832,
0.0028226280119270086,
0.003186482237651944,
0.0055476827546954155,
-0.0005861234967596829,
-0.004546483512967825,
-0.002895812038332224,
-0.016915282234549522,
0.0007340061711147428,
0.019398972392082214,
0.0028687305748462677,
0.011079867370426655,
0.011376455426216125,
-0.0022378817666321993,
0.002657165750861168,
0.005014430731534958,
0.0011188015341758728,
0.011779162101447582,
-0.008212979882955551,
0.00007220944098662585,
0.001916756620630622,
-0.00450775446370244,
0.0006376925739459693,
0.004658410791307688,
0.007468036375939846,
-0.0018257434712722898,
0.0027225168887525797,
-0.007371407933533192,
-0.005434681195765734,
-0.01795126125216484,
-0.0008744687656871974,
0.0071274032816290855,
-0.0038528109434992075,
0.005445359740406275,
-0.012448595836758614,
0.005825549364089966,
0.005382825620472431,
0.0023400236386805773,
0.0005944112199358642,
0.00031886494252830744,
0.006127438507974148,
0.012362050823867321,
-0.006933759432286024,
0.004009566269814968,
-0.0015761886024847627,
-0.002072220668196678,
0.0009882196318358183,
0.008609870448708534,
-0.007149385288357735,
-0.006730404682457447,
0.0027158826123923063,
0.004868196323513985,
0.0005177780985832214,
-0.004765007644891739,
-0.007832459174096584,
-0.0029073988553136587,
0.004020150285214186,
-0.005089783109724522,
0.005129221361130476,
0.002639660844579339,
0.002423821249976754,
-0.008822997100651264,
0.0015197681495919824,
-0.006619961932301521,
-0.011866818182170391,
0.009902670979499817,
-0.00257197511382401,
0.0041098338551819324,
0.01195069681853056,
0.0024304355029016733,
-0.013635947369039059,
0.0035018566995859146,
0.00851612538099289,
-0.003765437752008438,
0.004434846807271242,
0.004383783787488937,
-0.006629438139498234,
-0.02216392382979393,
-0.004138727206736803,
-0.014306853525340557,
0.008794109337031841,
-0.002693510614335537,
0.00443706288933754,
-0.007126207463443279,
0.008567975834012032,
0.004773530177772045,
-0.014144730754196644,
-0.0048591746017336845,
-0.007581876590847969,
0.009325937367975712,
-0.0018073795363307,
-0.00044037276529707015,
-0.0032842555083334446,
0.00011286912922514603,
-0.002625050488859415,
-0.003823264501988888,
-0.0009582245838828385,
0.0037799132987856865,
0.0008305024239234626,
-0.002343909116461873,
0.0017441119998693466,
-0.005831265356391668,
0.0008034995407797396,
0.0008892355835996568,
-0.011768786236643791,
0.0012871529906988144,
0.005738785490393639,
-0.001949381548911333,
-0.006048845127224922,
0.0010364826302975416,
-0.0018913841340690851,
-0.0046740369871258736,
-0.011189169250428677,
-0.003299746196717024,
-0.003726484952494502,
-0.0030754851177334785,
-0.01239587552845478,
-0.0023195731919258833,
-0.008667121641337872,
0.006019027438014746,
-0.006251305341720581,
0.008925640024244785,
0.0054303621873259544,
-0.004905376583337784,
0.007226295303553343,
-0.0017697967123240232,
0.005944537464529276,
0.0013402466429397464,
0.004662076942622662,
0.0013301174622029066,
-0.007011265028268099,
-0.012766161933541298,
0.009592045098543167,
-0.007630906067788601,
-0.001615484245121479,
0.013102339580655098,
0.005688761826604605,
0.008186099119484425,
-0.0006613832083530724,
-0.000535836792550981,
0.002082386752590537,
0.008123242296278477,
-0.013755801133811474,
0.002324503380805254,
-0.0037373166996985674,
0.0011188669595867395,
0.0038990317843854427,
-0.00439944863319397,
0.003194598015397787,
0.007663264404982328,
0.001788847497664392,
-0.007519772741943598,
-0.0022810823284089565,
0.001747372793033719,
0.005362294614315033,
-0.012436700984835625,
0.00034288474125787616,
-0.006316369865089655,
-0.0038783568888902664,
-0.00365517963655293,
-0.0009899033466354012,
-0.0016691430937498808,
0.004025291185826063,
-0.005477110855281353,
0.006315548438578844,
0.003954239655286074,
-0.005092265084385872,
0.015400486998260021,
-0.007584357168525457,
-0.003975292202085257,
0.002986906562000513,
0.0029215055983513594,
-0.0009238608763553202,
-0.008279266767203808,
-0.0009648712002672255,
0.0003069829836022109,
0.0047471062280237675,
-0.0016178153455257416,
-0.006340979598462582,
-0.0022923548240214586,
-0.0011755081359297037,
-0.008810777217149734,
0.0029784305952489376,
0.009676248766481876,
-0.0019161583622917533,
0.005413287319242954,
-0.0015200308989733458,
-0.0063020274974405766,
-0.014424391090869904,
0.055093519389629364,
-0.002292879158630967,
0.005201761145144701,
0.005305339582264423,
-0.007886048406362534,
-0.0011064698919653893,
-0.0030984384939074516,
0.0068376753479242325,
-0.006793081294745207,
-0.008386921137571335,
0.007821413688361645,
-0.003006167709827423,
0.0021578918676823378,
0.0021662020590156317,
-0.0023081712424755096,
0.016709165647625923,
-0.003215634962543845,
-0.016146689653396606,
-0.015656765550374985,
0.005719924811273813,
-0.004819639027118683,
-0.007915450260043144,
0.007949987426400185,
-0.0038249145727604628,
-0.0031649938318878412,
0.0022181053645908833,
0.007669204380363226,
-0.00015540288586635143,
0.00016205500287469476,
-0.0027759503573179245,
-0.0014283083146438003,
0.0005195601843297482,
0.003195015247911215,
0.0062364982441067696,
0.008530177175998688,
-0.004612203687429428,
0.0050676073879003525,
-0.0025524618104100227,
0.00008025904389796779,
-0.0024727866984903812,
0.006544674281030893,
0.008448520675301552,
-0.0014947402523830533,
0.0005078216781839728,
0.006106780841946602,
0.005413179751485586,
0.0017105364240705967,
0.012496106326580048,
0.0011555448872968554,
-0.006511223502457142,
0.008872092701494694,
0.008478601463139057,
0.0011134849628433585,
0.009503768756985664,
-0.0013586794957518578,
0.00379738537594676,
-0.0004620864347089082,
-0.007217687088996172,
-0.01624598726630211,
-0.0017177833942696452,
0.007025040220469236,
0.008565257303416729,
-0.001764887128956616,
0.003183948341757059,
-0.0025067573878914118,
-0.002207524608820677,
-0.00684215035289526,
-0.006366130895912647,
0.0005820454098284245,
0.001232827897183597,
0.00521704088896513,
0.07014108449220657,
-0.008280135691165924,
-0.0017878328217193484,
-0.00643742922693491,
-0.000648343819193542,
-0.0027133910916745663,
-0.0013569348957389593,
-0.00004253751831129193,
-0.0012161555932834744,
0.0024508750066161156,
0.00003373151776031591,
-0.006108559668064117,
-0.011215945705771446,
0.0018993276171386242,
0.001830716384574771,
-0.002543052891269326,
0.00394323980435729,
0.00625893659889698,
-0.009524245746433735,
0.0022842339240014553,
-0.012439142912626266,
-0.0025276716332882643,
-0.003748740069568157,
-0.009962627664208412,
-0.005566984415054321,
-0.0030289001297205687,
0.004214276559650898,
0.0030794672202318907,
0.006406098138540983,
-0.004769922699779272,
0.0053983572870492935,
-0.0028851793613284826,
0.0011900040553882718,
-0.005883437115699053,
-0.0008499622927047312,
-0.004044341389089823,
0.007236749865114689,
0.002141533885151148,
-0.010385189205408096,
-0.0057275849394500256,
0.0003204421082045883,
-0.0007215584046207368,
-0.006449610460549593,
0.006129678804427385,
-0.0003842027217615396,
0.0068267094902694225,
-0.002773894462734461,
-0.0004096238117199391,
-0.0067526292987167835,
0.002776257460936904,
-0.011533998884260654,
0.005027311388403177,
-0.1746838241815567,
0.010136702097952366,
0.004281727131456137,
-0.0048843626864254475,
-0.004458912648260593,
-0.01652699150145054,
-0.005133660044521093,
0.00475036446005106,
0.011754374951124191,
0.0024237714242190123,
-0.0011470994213595986,
-0.003953634295612574,
0.005604395177215338,
0.0033645830117166042,
-0.0007892512367106974,
-0.003812182694673538,
0.0031034734565764666,
-0.0018948304932564497,
0.00015317180077545345,
0.006229601334780455,
0.005179323721677065,
0.00752319535240531,
0.0010532219894230366,
0.0017371921567246318,
-0.0030016337987035513,
-0.004262666217982769,
0.003763995599001646,
-0.003368342760950327,
0.006694458890706301,
-0.01179713848978281,
-0.0017170929349958897,
-0.003709842450916767,
-0.004428875166922808,
-0.0008580388384871185,
0.006752542685717344,
-0.0009812373900786042,
0.009658467955887318,
0.002089536050334573,
-0.007021111901849508,
0.004940246697515249,
-0.007582059595733881,
0.029852069914340973,
0.004918363876640797,
0.006773459259420633,
-0.00026886462001129985,
-0.004972490947693586,
-0.0052925823256373405,
0.009656524285674095,
0.0035227304324507713,
0.010251644067466259,
-0.011575608514249325,
-0.002242187038064003,
0.002981797559186816,
0.016620643436908722,
-0.0035686111077666283,
-0.008237131871283054,
-0.006646839436143637,
-0.0032740808092057705,
0.0035768907982856035,
0.009665886871516705,
0.010017779655754566,
-0.006081895437091589,
0.008038817904889584,
-0.003023287747055292,
-0.022234421223402023,
0.004254087805747986,
-0.005393539555370808,
-0.009084073826670647,
0.0014627695782110095,
0.007279837038367987,
0.010868546552956104,
-0.0005501285195350647,
0.0035106982104480267,
0.0000036451610867516138,
0.00568762281909585,
0.00011383778473827988,
0.008510901592671871,
-0.0010783668840304017,
0.0062928167171776295,
-0.01022008154541254,
0.00933434721082449,
-0.009167371317744255,
-0.0037522956263273954,
0.0016679218970239162,
-0.004235256928950548,
0.011613471433520317,
0.00393882067874074,
-0.0014814591268077493,
-0.000179881535586901,
-0.010641275905072689,
-0.004702392965555191,
0.0033742061350494623,
0.0010932603618130088,
-0.010650105774402618,
0.0029539894312620163,
0.000824491202365607,
0.005048877093940973,
0.005295807961374521,
-0.010560465045273304,
0.005584029480814934,
0.0066202725283801556,
-0.004570203833281994,
0.0003000532742589712,
-0.004945801571011543,
0.001615250832401216,
0.0032370660919696093,
-0.005519344005733728,
-0.008100360631942749,
0.003970257937908173,
-0.005889942869544029,
-0.002914687618613243,
0.006366863381117582,
-0.010110837407410145,
-0.00699628097936511,
-0.0011635409900918603,
-0.010998226702213287,
0.0010143331019207835
] |
8a30c3ee79ce2efcb14fdc2c9e26c3ab71e499c1 | 671 | py | Python | tests/test_i18n.py | vthriller/flask-kajiki | eadaa0aa45d23507066758b9e74091bddbc943c4 | [
"BSD-3-Clause"
] | null | null | null | tests/test_i18n.py | vthriller/flask-kajiki | eadaa0aa45d23507066758b9e74091bddbc943c4 | [
"BSD-3-Clause"
] | null | null | null | tests/test_i18n.py | vthriller/flask-kajiki | eadaa0aa45d23507066758b9e74091bddbc943c4 | [
"BSD-3-Clause"
] | null | null | null | from kajiki import i18n
from flask import request
from flask_kajiki import render_template
# N. B. settting i18n.gettext would affect tests from all modules,
# so we test for request path that only functions from this module could set
def gettext(s):
if request.path == '/test_i18n':
return s.upper()
return s
i18n.gettext = gettext
def test_does_translations(app):
"""Callback interface is able to inject Translator filter"""
with app.test_request_context(path='/test_i18n'):
rendered = render_template('i18n.html')
# TODO DOCTYPE; see also render_args
expected = '<p>HELLO!</p>'
assert rendered == expected
| 27.958333 | 76 | 0.704918 | 1 | 0.8631 | [
0.0018686701077967882,
0.022481262683868408,
0.01110015343874693,
0.0014598253183066845,
0.006847179960459471,
-0.004239426925778389,
-0.010827550664544106,
0.0026397905312478542,
-0.008420336991548538,
-0.00005471163967740722,
0.002714278409257531,
0.0023836202453821898,
0.005055917892605066,
-0.016810724511742592,
0.0017568801995366812,
0.014920871704816818,
-0.05538102611899376,
0.006183340679854155,
-0.0034565329551696777,
0.005872888956218958,
-0.007762649096548557,
0.008933746255934238,
0.007213463541120291,
0.004270039498806,
0.005079037044197321,
0.0011691483668982983,
0.009899760596454144,
0.0025973129086196423,
-0.007005095947533846,
-0.00580915343016386,
0.0012439351994544268,
-0.00207635760307312,
-0.0061934879049658775,
-0.005518184043467045,
0.006657230667769909,
-0.0011143883457407355,
0.0014285990037024021,
-0.020940497517585754,
0.010675610974431038,
-0.004034886136651039,
-0.007987990975379944,
-0.018753821030259132,
-0.001067424425855279,
0.0045042745769023895,
-0.014454849064350128,
0.0019627143628895283,
-0.005507158115506172,
0.0058861905708909035,
-0.01335885375738144,
0.007368993479758501,
-0.008807539939880371,
0.004215648863464594,
0.015851354226469994,
0.0021331736352294683,
-0.006199262570589781,
-0.010032666847109795,
0.010687884874641895,
0.0004498489433899522,
-0.010633975267410278,
0.002740634372457862,
-0.005372239276766777,
-0.004412184935063124,
0.0026425670366734266,
0.00224792561493814,
-0.01779523491859436,
-0.002972482703626156,
-0.0037307317834347486,
0.0030041150748729706,
-0.001968615921214223,
0.006227543111890554,
-0.0007623638957738876,
-0.00223417766392231,
0.008237875998020172,
0.003055887995287776,
0.004280427936464548,
-0.004724737722426653,
-0.00065615278435871,
0.0003720558888744563,
0.006269758101552725,
0.004198478069156408,
0.00755873741582036,
-0.0076779210940003395,
0.007058161310851574,
0.009285504929721355,
0.01357274316251278,
0.009052569046616554,
0.019252842292189598,
-0.010051662102341652,
0.04673837870359421,
0.007843591272830963,
-0.007626377511769533,
0.0005525431479327381,
-0.00399280060082674,
-0.0007684127194806933,
-0.003088290337473154,
-0.029821787029504776,
0.0010096309706568718,
-0.006039535626769066,
0.0037037499714642763,
0.004856817424297333,
0.00010302042937837541,
0.004942761268466711,
-0.002334351185709238,
0.00009254530596081167,
-0.011217210441827774,
0.010989423841238022,
-0.009630474261939526,
-0.0022572032175958157,
0.008175603114068508,
0.0025581764057278633,
-0.014080326072871685,
-0.0009321135585196316,
0.002011097501963377,
-0.011256908997893333,
0.005981439258903265,
-0.0002655286225490272,
-0.004209069535136223,
0.05643557012081146,
-0.0010704523883759975,
0.0031813851092010736,
-0.005496966186910868,
-0.000828790944069624,
0.0007209785399027169,
0.00441322848200798,
0.008675159886479378,
-0.0041147321462631226,
0.012118963524699211,
0.005607683211565018,
0.005611774045974016,
0.008587483316659927,
0.0017330334521830082,
0.008791483938694,
-0.004445970058441162,
-0.0035740442108362913,
0.0009628591942600906,
-0.00710629764944315,
0.007656414993107319,
-0.0004339622100815177,
-0.006900150794535875,
0.0031871257815510035,
-0.0016497998731210828,
-0.011894692666828632,
0.0024070420768111944,
-0.003694063751026988,
0.005653226748108864,
-0.01074421126395464,
-0.007235828321427107,
-0.007778058294206858,
-0.003309904830530286,
0.0026459088549017906,
0.007323595695197582,
0.0038970275782048702,
0.003274934832006693,
-0.004768225830048323,
-0.008805379271507263,
-0.0024921223521232605,
-0.004378245212137699,
0.0005620383890345693,
0.00862677302211523,
0.0037577275652438402,
-0.008867877535521984,
-0.0021468806080520153,
0.003359857015311718,
0.0025972884614020586,
-0.0019937483593821526,
0.0012317843502387404,
-0.008538723923265934,
0.005734575912356377,
0.000824709131848067,
0.005791261326521635,
0.009975860826671124,
-0.004850252065807581,
-9.79789888333471e-7,
0.0003572067362256348,
0.004733574111014605,
-0.00021136843133717775,
0.0047983210533857346,
0.011300315149128437,
-0.006777412258088589,
-0.005126417614519596,
0.006031940225511789,
0.00480937073007226,
0.011091272346675396,
0.010585244745016098,
-0.00125616486184299,
0.0011147826444357634,
-0.0017913462361320853,
0.000009961538125935476,
0.007036169059574604,
-0.0025763525627553463,
0.007093734107911587,
0.0032280730083584785,
-0.012218688614666462,
-0.007589472457766533,
0.0028502715285867453,
-0.009710648097097874,
0.0018363731214776635,
0.01571771502494812,
0.012884911149740219,
-0.003181896638125181,
0.004304346162825823,
-0.011006910353899002,
0.0001272349909413606,
0.00764805544167757,
0.0028699911199510098,
-0.01355365477502346,
-0.9563581347465515,
0.002574016572907567,
0.0019498374313116074,
-0.002142987446859479,
0.002623330568894744,
0.0033532993402332067,
0.005132606718689203,
0.006011204794049263,
0.013102706521749496,
-0.006448685657233,
-0.0056604305282235146,
-0.009061054326593876,
-0.009746678173542023,
-0.001592103624716401,
-0.0067853787913918495,
-0.0035194812808185816,
-0.009120260365307331,
-0.007347491569817066,
-0.00435076467692852,
-0.0034564912784844637,
-0.0024239292833954096,
0.007075775880366564,
-0.0004856215382460505,
0.004777533933520317,
0.0011498181847855449,
0.004944818094372749,
-0.006226813420653343,
0.00306649855338037,
0.00027449330082163215,
-0.0022778103593736887,
-0.004513115156441927,
-0.01584624871611595,
-0.006478604860603809,
0.00043789923074655235,
0.01196780614554882,
0.000015133612578210887,
0.00862827617675066,
-0.0038572156336158514,
0.00045007324661128223,
-0.010658062994480133,
0.004746241960674524,
0.0016596534987911582,
0.0035181718412786722,
-0.029923539608716965,
0.0003851159999612719,
-0.0001851262932177633,
-0.005006454885005951,
0.010996786877512932,
-0.0025526857934892178,
0.0008854051120579243,
-0.0007403597119264305,
-0.0022033420391380787,
0.009170646779239178,
-0.007353638298809528,
0.003223299514502287,
-0.003947573248296976,
-0.00599473575130105,
-0.00361877609975636,
-0.009722343645989895,
0.0002409204898867756,
0.005519942846149206,
-0.004025076981633902,
-0.003500852733850479,
-0.004680885002017021,
0.0018952368991449475,
-0.00015818381507415324,
0.0021007421892136335,
-0.016684655100107193,
-0.005007016938179731,
-0.002235163701698184,
0.00014135910896584392,
-0.004357106518000364,
-0.004316899459809065,
0.0022544246166944504,
-0.010448023676872253,
0.0068812379613518715,
0.0007978285429999232,
-0.00012928724754601717,
-0.008321035653352737,
0.0017411670414730906,
-0.008476941846311092,
-0.010415233671665192,
0.00232801609672606,
-0.007490314543247223,
-0.00488966703414917,
0.0008556484244763851,
0.0037908307276666164,
0.007834939286112785,
-0.0038111323956400156,
0.004054924473166466,
0.011489525437355042,
-0.004129573702812195,
-0.006985486950725317,
0.006999286822974682,
0.006624313537031412,
-0.001076479791663587,
0.00023585124290548265,
0.0004285720642656088,
0.008327366784214973,
0.007860190235078335,
0.0008071137126535177,
0.004867312498390675,
0.00037702228291891515,
0.009655749425292015,
0.001218132907524705,
-0.0022108673583716154,
-0.0015723146498203278,
-0.00241004372946918,
-0.0028305561281740665,
-0.0008330101263709366,
-0.005553368013352156,
0.00021353951888158917,
-0.01224608439952135,
-0.008765109814703465,
-0.0016521824290975928,
-0.000430132495239377,
0.0036620134487748146,
-0.003022884950041771,
0.0016067528631538153,
0.002533293329179287,
0.01079475600272417,
0.0018187593668699265,
-0.0016715218080207705,
0.00045187646173872054,
0.005076458211988211,
-0.005055225919932127,
0.014373216778039932,
-0.009210862219333649,
0.003893393324688077,
-0.004535953979939222,
-0.017206018790602684,
0.009042062796652317,
0.01299191266298294,
-0.007013662252575159,
0.0023689698427915573,
0.005466056987643242,
0.002201579976826906,
-0.0007746812771074474,
-0.008304549381136894,
-0.005801004823297262,
-0.01783442124724388,
0.00017962275887839496,
0.019347216933965683,
0.0015576236182823777,
0.011433235369622707,
0.0113595025613904,
-0.0021687871776521206,
0.0004455829912330955,
0.006939028389751911,
0.0002160963194910437,
0.011475096456706524,
-0.009489551186561584,
-0.0023165163584053516,
0.0011083054123446345,
-0.005472224671393633,
0.0011736893793568015,
0.0015499736182391644,
0.004966220818459988,
-0.00014991986972745508,
0.002649355446919799,
-0.007920444943010807,
-0.005744260735809803,
-0.021338198333978653,
-0.0033841195981949568,
0.008004209026694298,
-0.00244629243388772,
0.005227264482527971,
-0.01225966028869152,
0.004541453439742327,
0.00660783750936389,
0.0033555689733475447,
0.0006779294926673174,
0.00334853189997375,
0.004773884546011686,
0.011798955500125885,
-0.007004315033555031,
0.005007707513868809,
0.002566251903772354,
-0.0023901076056063175,
0.0031166241969913244,
0.008864175528287888,
-0.008584248833358288,
-0.008763019926846027,
0.003314368659630418,
0.0035917614586651325,
0.0007401702459901571,
-0.0031956075690686703,
-0.008241528645157814,
-0.005001707933843136,
0.004365187603980303,
-0.0045853895135223866,
0.002466463716700673,
0.00286476849578321,
0.002611882518976927,
-0.00912918709218502,
-0.00027489932836033404,
-0.005702830385416746,
-0.011126022785902023,
0.01019334513694048,
-0.0018500563455745578,
0.0010094576282426715,
0.011885342188179493,
0.004692095331847668,
-0.011143138632178307,
0.00760989123955369,
0.008087416179478168,
-0.005343955010175705,
0.004161285236477852,
0.008543254807591438,
-0.00449323421344161,
-0.02422179840505123,
0.0006875515100546181,
-0.01536793913692236,
0.008079510182142258,
-0.0011243884218856692,
0.004817618057131767,
-0.008283902890980244,
0.006525359582155943,
0.004914071876555681,
-0.012989700771868229,
-0.004462118726223707,
-0.01021010521799326,
0.010065536946058273,
-0.0016529138665646315,
-0.0017830418655648828,
-0.003686043666675687,
0.0009276688215322793,
-0.001905249897390604,
-0.0034552584402263165,
0.00009552630945108831,
0.00477942219004035,
0.002111122477799654,
-0.0018794165225699544,
0.004163602367043495,
-0.004673017654567957,
0.0016311536310240626,
0.004253363236784935,
-0.011670872569084167,
-0.001382702961564064,
0.005042026750743389,
-0.0009743458358570933,
-0.003576258895918727,
-0.001636974629946053,
0.001154094934463501,
-0.006224243901669979,
-0.010823705233633518,
-0.003008986823260784,
-0.003077559173107147,
-0.003094219136983156,
-0.010312235914170742,
-0.0003102261107414961,
-0.005372774321585894,
0.006446551531553268,
-0.007714398205280304,
0.008033564314246178,
0.008855190128087997,
-0.006097341887652874,
0.008326108567416668,
-0.0022979560308158398,
0.004265001974999905,
0.0027343800757080317,
0.006038242019712925,
0.002597083104774356,
-0.005927966441959143,
-0.014079305343329906,
0.012144726701080799,
-0.008455491624772549,
-0.001070341793820262,
0.011680412106215954,
0.006982328370213509,
0.009442683309316635,
0.001294472604058683,
-0.0030295185279101133,
0.00248800334520638,
0.008257947862148285,
-0.016690650954842567,
0.00044285107287578285,
0.0004533881729003042,
-0.0017184597672894597,
0.004652929492294788,
-0.0016317632980644703,
0.002299906685948372,
0.007780736777931452,
0.0021977205760776997,
-0.006671549752354622,
-0.003336061257869005,
0.0036215847358107567,
0.005921036005020142,
-0.012691106647253036,
-0.0003472996177151799,
-0.003804572159424424,
-0.0047086020931601524,
-0.004484411329030991,
-0.0047953468747437,
-0.0003727236471604556,
0.0050897542387247086,
-0.0018617993919178843,
0.0034681824035942554,
0.0033284970559179783,
-0.006652391515672207,
0.01705324649810791,
-0.005274983122944832,
-0.005129851400852203,
0.002092830603942275,
0.0023567727766931057,
-0.00008084563160082325,
-0.00834968313574791,
-0.003137404564768076,
0.0030360990203917027,
0.006209082901477814,
0.000874664110597223,
-0.008081423118710518,
-0.0011418242938816547,
-0.0013630028115585446,
-0.007932146079838276,
0.0025624227710068226,
0.008683332242071629,
-0.002491418272256851,
0.0058928970247507095,
-0.0003647998964879662,
-0.008038747124373913,
-0.014677698723971844,
0.05653810873627663,
-0.0015847409376874566,
0.0034022636245936155,
0.0037598598282784224,
-0.007931915111839771,
-0.0017061540856957436,
-0.00374101335182786,
0.006364027503877878,
-0.00762640405446291,
-0.00880787055939436,
0.008407548069953918,
-0.0005844365805387497,
0.0032502389512956142,
0.002448172075673938,
-0.0024051375221461058,
0.015923215076327324,
-0.002878729021176696,
-0.014785482548177242,
-0.01697435788810253,
0.008114047348499298,
-0.007246324792504311,
-0.009133320301771164,
0.005851182620972395,
-0.0035969701129943132,
-0.008385829627513885,
0.0005671424441970885,
0.007271875161677599,
0.002288806950673461,
-0.0007059219060465693,
-0.002047443063929677,
-0.00357242114841938,
0.000535429862793535,
0.0029129793401807547,
0.008226542733609676,
0.005862616002559662,
-0.002178221708163619,
0.004039335530251265,
-0.0026959595270454884,
-0.002597179263830185,
0.0007320432341657579,
0.002498912625014782,
0.006997144781053066,
-0.0025420652236789465,
-0.004098972305655479,
0.0052410513162612915,
0.005677873268723488,
-0.0004149618907831609,
0.008016637526452541,
0.002752348082140088,
-0.0072334883734583855,
0.01013278029859066,
0.009772724471986294,
-0.0026309366803616285,
0.006442512851208448,
-0.00476765725761652,
0.0045655472204089165,
0.0014748191460967064,
-0.007903139106929302,
-0.019404036924242973,
-0.0025171968154609203,
0.005258429795503616,
0.009461678564548492,
0.0005419452791102231,
0.004041631706058979,
-0.00022689094475936145,
-0.002170765306800604,
-0.010422127321362495,
-0.00466440012678504,
-0.0014338478213176131,
-0.0024913642555475235,
0.0010087754344567657,
0.07146592438220978,
-0.011586260981857777,
-0.00041707628406584263,
-0.009194493293762207,
-0.00018451323558110744,
0.0006003163289278746,
0.0006910421070642769,
0.001214345800690353,
-0.0010432666167616844,
0.003340552793815732,
0.002659013494849205,
-0.0071530635468661785,
-0.009275504387915134,
0.0009232196025550365,
0.006922248750925064,
-0.002274111146107316,
0.002989853033795953,
0.008680771104991436,
-0.014065838418900967,
0.0012982016196474433,
-0.00991988554596901,
-0.0013930952409282327,
-0.002628864487633109,
-0.008804031647741795,
-0.003870806423947215,
-0.003401512047275901,
0.0017348758410662413,
0.004265366122126579,
0.006697065196931362,
-0.001726027112454176,
0.006139334291219711,
-0.0005873363115824759,
0.0018357166554778814,
-0.00593129126355052,
-0.0021555530838668346,
-0.003521876409649849,
0.005836773198097944,
0.0012697152560576797,
-0.010880761779844761,
-0.00445574289187789,
-0.003299369476735592,
0.00022414737031795084,
-0.0076507506892085075,
0.006324272137135267,
0.001585508114658296,
0.007009681314229965,
-0.003570825792849064,
0.0019449280807748437,
-0.0059919836930930614,
0.0007514137541875243,
-0.014331752434372902,
0.007337960414588451,
-0.17663158476352692,
0.010544465854763985,
0.0024077650159597397,
-0.003397855209186673,
-0.007379421964287758,
-0.016596389934420586,
-0.0073074959218502045,
0.004910018760710955,
0.012356058694422245,
-0.0003656242333818227,
-0.0016700790729373693,
-0.002099700504913926,
0.004903449676930904,
0.0007776159909553826,
-0.001968286233022809,
-0.008306493982672691,
0.0005762950167991221,
-0.0022329548373818398,
-0.0003362944698892534,
0.0058836801908910275,
0.004745026119053364,
0.010916166007518768,
0.003081586444750428,
0.0008639637380838394,
-0.0026343860663473606,
-0.005236336495727301,
0.0053734141401946545,
-0.0032865849789232016,
0.003222155151888728,
-0.011864150874316692,
-0.003438445972278714,
-0.0031076143495738506,
-0.004760623909533024,
0.001667073112912476,
0.004088067449629307,
-0.0013905541272833943,
0.008403371088206768,
0.004646056331694126,
-0.007794083561748266,
0.00788191519677639,
-0.005453381221741438,
0.02916071005165577,
0.004445429891347885,
0.006316932383924723,
-0.00017134494555648416,
-0.005157158710062504,
-0.004965703934431076,
0.01057066023349762,
-0.00007818181620677933,
0.012015522457659245,
-0.009840256534516811,
-0.002008028794080019,
0.003169644856825471,
0.017552722245454788,
-0.005797217600047588,
-0.010191180743277073,
-0.009452015161514282,
-0.004044361412525177,
0.0030919136479496956,
0.012979390099644661,
0.009801933541893959,
-0.004417965654283762,
0.008080942556262016,
-0.0028545958921313286,
-0.01934514194726944,
0.002417061710730195,
-0.005232961382716894,
-0.008318389765918255,
0.0002189545048167929,
0.004152568522840738,
0.011962051503360271,
-0.001966153969988227,
0.004313487093895674,
-0.001720872358419001,
0.004360174760222435,
-0.0006369574111886322,
0.007661844603717327,
-0.007569297216832638,
0.00763672823086381,
-0.006561290938407183,
0.010312655009329319,
-0.010780923999845982,
-0.0003691578167490661,
0.0007357439608313143,
-0.0033501002471894026,
0.012477234937250614,
0.003735489910468459,
-0.00386572303250432,
-0.00018993036064784974,
-0.009691736660897732,
-0.0037209701258689165,
0.0001546769926790148,
0.004377476871013641,
-0.007864133454859257,
0.0047725047916173935,
-0.0030408173333853483,
0.008000724948942661,
0.006715334486216307,
-0.008087494410574436,
0.003943296615034342,
0.005943820346146822,
-0.009793243370950222,
0.0033624572679400444,
-0.004307217430323362,
0.0035521371755748987,
0.0036332441959530115,
-0.005811033770442009,
-0.00838229525834322,
0.003467462956905365,
-0.0061887335032224655,
-0.004422659985721111,
0.0034171834122389555,
-0.010865078307688236,
-0.00918473582714796,
-0.0013691320782527328,
-0.012235756032168865,
-0.000542772701010108
] |
8a3176dcac3313f88ab52ef3d929182aaaba205a | 12,423 | py | Python | mmdet/models/roi_heads/mask_heads/fcn_mask_head.py | jstzwjr/mmdetection | 1c2878eb4f4da2978dcd9a05f9d0247726680213 | [
"Apache-2.0"
] | 1 | 2020-09-21T12:13:48.000Z | 2020-09-21T12:13:48.000Z | mmdet/models/roi_heads/mask_heads/fcn_mask_head.py | xiaojianying/mmdetection | a10d24d686e8714f42a9022da89124d04c0389ad | [
"Apache-2.0"
] | null | null | null | mmdet/models/roi_heads/mask_heads/fcn_mask_head.py | xiaojianying/mmdetection | a10d24d686e8714f42a9022da89124d04c0389ad | [
"Apache-2.0"
] | null | null | null | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule, build_upsample_layer
from mmcv.ops import Conv2d
from mmcv.ops.carafe import CARAFEPack
from mmcv.runner import auto_fp16, force_fp32
from torch.nn.modules.utils import _pair
from mmdet.core import mask_target
from mmdet.models.builder import HEADS, build_loss
BYTES_PER_FLOAT = 4
# TODO: This memory limit may be too much or too little. It would be better to
# determine it based on available resources.
GPU_MEM_LIMIT = 1024**3 # 1 GB memory limit
@HEADS.register_module()
class FCNMaskHead(nn.Module):
def __init__(self,
num_convs=4,
roi_feat_size=14,
in_channels=256,
conv_kernel_size=3,
conv_out_channels=256,
num_classes=80,
class_agnostic=False,
upsample_cfg=dict(type='deconv', scale_factor=2),
conv_cfg=None,
norm_cfg=None,
loss_mask=dict(
type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)):
super(FCNMaskHead, self).__init__()
self.upsample_cfg = upsample_cfg.copy()
if self.upsample_cfg['type'] not in [
None, 'deconv', 'nearest', 'bilinear', 'carafe'
]:
raise ValueError(
f'Invalid upsample method {self.upsample_cfg["type"]}, '
'accepted methods are "deconv", "nearest", "bilinear", '
'"carafe"')
self.num_convs = num_convs
# WARN: roi_feat_size is reserved and not used
self.roi_feat_size = _pair(roi_feat_size)
self.in_channels = in_channels
self.conv_kernel_size = conv_kernel_size
self.conv_out_channels = conv_out_channels
self.upsample_method = self.upsample_cfg.get('type')
self.scale_factor = self.upsample_cfg.pop('scale_factor', None)
self.num_classes = num_classes
self.class_agnostic = class_agnostic
self.conv_cfg = conv_cfg
self.norm_cfg = norm_cfg
self.fp16_enabled = False
self.loss_mask = build_loss(loss_mask)
self.convs = nn.ModuleList()
for i in range(self.num_convs):
in_channels = (
self.in_channels if i == 0 else self.conv_out_channels)
padding = (self.conv_kernel_size - 1) // 2
self.convs.append(
ConvModule(
in_channels,
self.conv_out_channels,
self.conv_kernel_size,
padding=padding,
conv_cfg=conv_cfg,
norm_cfg=norm_cfg))
upsample_in_channels = (
self.conv_out_channels if self.num_convs > 0 else in_channels)
upsample_cfg_ = self.upsample_cfg.copy()
if self.upsample_method is None:
self.upsample = None
elif self.upsample_method == 'deconv':
upsample_cfg_.update(
in_channels=upsample_in_channels,
out_channels=self.conv_out_channels,
kernel_size=self.scale_factor,
stride=self.scale_factor)
self.upsample = build_upsample_layer(upsample_cfg_)
elif self.upsample_method == 'carafe':
upsample_cfg_.update(
channels=upsample_in_channels, scale_factor=self.scale_factor)
self.upsample = build_upsample_layer(upsample_cfg_)
else:
# suppress warnings
align_corners = (None
if self.upsample_method == 'nearest' else False)
upsample_cfg_.update(
scale_factor=self.scale_factor,
mode=self.upsample_method,
align_corners=align_corners)
self.upsample = build_upsample_layer(upsample_cfg_)
out_channels = 1 if self.class_agnostic else self.num_classes
logits_in_channel = (
self.conv_out_channels
if self.upsample_method == 'deconv' else upsample_in_channels)
self.conv_logits = Conv2d(logits_in_channel, out_channels, 1)
self.relu = nn.ReLU(inplace=True)
self.debug_imgs = None
def init_weights(self):
for m in [self.upsample, self.conv_logits]:
if m is None:
continue
elif isinstance(m, CARAFEPack):
m.init_weights()
else:
nn.init.kaiming_normal_(
m.weight, mode='fan_out', nonlinearity='relu')
nn.init.constant_(m.bias, 0)
@auto_fp16()
def forward(self, x):
for conv in self.convs:
x = conv(x)
if self.upsample is not None:
x = self.upsample(x)
if self.upsample_method == 'deconv':
x = self.relu(x)
mask_pred = self.conv_logits(x)
return mask_pred
def get_targets(self, sampling_results, gt_masks, rcnn_train_cfg):
pos_proposals = [res.pos_bboxes for res in sampling_results]
pos_assigned_gt_inds = [
res.pos_assigned_gt_inds for res in sampling_results
]
mask_targets = mask_target(pos_proposals, pos_assigned_gt_inds,
gt_masks, rcnn_train_cfg)
return mask_targets
@force_fp32(apply_to=('mask_pred', ))
def loss(self, mask_pred, mask_targets, labels):
loss = dict()
if mask_pred.size(0) == 0:
loss_mask = mask_pred.sum() * 0
else:
if self.class_agnostic:
loss_mask = self.loss_mask(mask_pred, mask_targets,
torch.zeros_like(labels))
else:
loss_mask = self.loss_mask(mask_pred, mask_targets, labels)
loss['loss_mask'] = loss_mask
return loss
def get_seg_masks(self, mask_pred, det_bboxes, det_labels, rcnn_test_cfg,
ori_shape, scale_factor, rescale):
"""Get segmentation masks from mask_pred and bboxes.
Args:
mask_pred (Tensor or ndarray): shape (n, #class, h, w).
For single-scale testing, mask_pred is the direct output of
model, whose type is Tensor, while for multi-scale testing,
it will be converted to numpy array outside of this method.
det_bboxes (Tensor): shape (n, 4/5)
det_labels (Tensor): shape (n, )
img_shape (Tensor): shape (3, )
rcnn_test_cfg (dict): rcnn testing config
ori_shape: original image size
Returns:
list[list]: encoded masks
"""
if isinstance(mask_pred, torch.Tensor):
mask_pred = mask_pred.sigmoid()
else:
mask_pred = det_bboxes.new_tensor(mask_pred)
device = mask_pred.device
cls_segms = [[] for _ in range(self.num_classes)
] # BG is not included in num_classes
bboxes = det_bboxes[:, :4]
labels = det_labels
if rescale:
img_h, img_w = ori_shape[:2]
else:
if isinstance(scale_factor, float):
img_h = np.round(ori_shape[0] * scale_factor).astype(np.int32)
img_w = np.round(ori_shape[1] * scale_factor).astype(np.int32)
else:
w_scale, h_scale = scale_factor[0], scale_factor[1]
img_h = np.round(ori_shape[0] * h_scale.item()).astype(
np.int32)
img_w = np.round(ori_shape[1] * w_scale.item()).astype(
np.int32)
scale_factor = 1.0
if not isinstance(scale_factor, (float, torch.Tensor)):
scale_factor = bboxes.new_tensor(scale_factor)
bboxes = bboxes / scale_factor
N = len(mask_pred)
# The actual implementation split the input into chunks,
# and paste them chunk by chunk.
if device.type == 'cpu':
# CPU is most efficient when they are pasted one by one with
# skip_empty=True, so that it performs minimal number of
# operations.
num_chunks = N
else:
# GPU benefits from parallelism for larger chunks,
# but may have memory issue
num_chunks = int(
np.ceil(N * img_h * img_w * BYTES_PER_FLOAT / GPU_MEM_LIMIT))
assert (num_chunks <=
N), 'Default GPU_MEM_LIMIT is too small; try increasing it'
chunks = torch.chunk(torch.arange(N, device=device), num_chunks)
threshold = rcnn_test_cfg.mask_thr_binary
im_mask = torch.zeros(
N,
img_h,
img_w,
device=device,
dtype=torch.bool if threshold >= 0 else torch.uint8)
if not self.class_agnostic:
mask_pred = mask_pred[range(N), labels][:, None]
for inds in chunks:
masks_chunk, spatial_inds = _do_paste_mask(
mask_pred[inds],
bboxes[inds],
img_h,
img_w,
skip_empty=device.type == 'cpu')
if threshold >= 0:
masks_chunk = (masks_chunk >= threshold).to(dtype=torch.bool)
else:
# for visualization and debugging
masks_chunk = (masks_chunk * 255).to(dtype=torch.uint8)
im_mask[(inds, ) + spatial_inds] = masks_chunk
for i in range(N):
cls_segms[labels[i]].append(im_mask[i].cpu().numpy())
return cls_segms
def _do_paste_mask(masks, boxes, img_h, img_w, skip_empty=True):
"""Paste instance masks acoording to boxes.
This implementation is modified from
https://github.com/facebookresearch/detectron2/
Args:
masks (Tensor): N, 1, H, W
boxes (Tensor): N, 4
img_h (int): Height of the image to be pasted.
img_w (int): Width of the image to be pasted.
skip_empty (bool): Only paste masks within the region that
tightly bound all boxes, and returns the results this region only.
An important optimization for CPU.
Returns:
tuple: (Tensor, tuple). The first item is mask tensor, the second one
is the slice object.
If skip_empty == False, the whole image will be pasted. It will
return a mask of shape (N, img_h, img_w) and an empty tuple.
If skip_empty == True, only area around the mask will be pasted.
A mask of shape (N, h', w') and its start and end coordinates
in the original image will be returned.
"""
# On GPU, paste all masks together (up to chunk size)
# by using the entire image to sample the masks
# Compared to pasting them one by one,
# this has more operations but is faster on COCO-scale dataset.
device = masks.device
if skip_empty:
x0_int, y0_int = torch.clamp(
boxes.min(dim=0).values.floor()[:2] - 1,
min=0).to(dtype=torch.int32)
x1_int = torch.clamp(
boxes[:, 2].max().ceil() + 1, max=img_w).to(dtype=torch.int32)
y1_int = torch.clamp(
boxes[:, 3].max().ceil() + 1, max=img_h).to(dtype=torch.int32)
else:
x0_int, y0_int = 0, 0
x1_int, y1_int = img_w, img_h
x0, y0, x1, y1 = torch.split(boxes, 1, dim=1) # each is Nx1
N = masks.shape[0]
img_y = torch.arange(
y0_int, y1_int, device=device, dtype=torch.float32) + 0.5
img_x = torch.arange(
x0_int, x1_int, device=device, dtype=torch.float32) + 0.5
img_y = (img_y - y0) / (y1 - y0) * 2 - 1
img_x = (img_x - x0) / (x1 - x0) * 2 - 1
# img_x, img_y have shapes (N, w), (N, h)
if torch.isinf(img_x).any():
inds = torch.where(torch.isinf(img_x))
img_x[inds] = 0
if torch.isinf(img_y).any():
inds = torch.where(torch.isinf(img_y))
img_y[inds] = 0
gx = img_x[:, None, :].expand(N, img_y.size(1), img_x.size(1))
gy = img_y[:, :, None].expand(N, img_y.size(1), img_x.size(1))
grid = torch.stack([gx, gy], dim=3)
img_masks = F.grid_sample(
masks.to(dtype=torch.float32), grid, align_corners=False)
if skip_empty:
return img_masks[:, 0], (slice(y0_int, y1_int), slice(x0_int, x1_int))
else:
return img_masks[:, 0], ()
| 39.189274 | 79 | 0.583353 | 1 | 1.9761 | [
-0.04716212674975395,
0.05823003500699997,
0.02189871296286583,
-0.013217030093073845,
-0.014337878674268723,
-0.011249384842813015,
0.000608209811616689,
-0.00973590649664402,
-0.037598345428705215,
0.01016240008175373,
-0.0006782686687074602,
0.02781134843826294,
0.01443622075021267,
-0.03450429067015648,
-0.0445549339056015,
-0.018824007362127304,
0.06391270458698273,
0.05060192197561264,
-0.02798089198768139,
0.014696500264108181,
-0.00952121801674366,
-0.0026168478652834892,
-0.02188274636864662,
-0.012632790952920914,
0.016484994441270828,
0.02119043655693531,
-0.0022585534024983644,
0.03782600909471512,
0.039411380887031555,
-0.019417578354477882,
-0.018531810492277145,
-0.006030767224729061,
0.020570887252688408,
-0.00525883212685585,
0.01695200428366661,
0.000734281144104898,
0.050661321729421616,
-0.017028307542204857,
-0.02043454721570015,
0.017124420031905174,
-0.01924799755215645,
-0.003780222265049815,
0.00020971515914425254,
0.03134538233280182,
-0.004820556379854679,
-0.012318005785346031,
0.003757857484742999,
0.024329960346221924,
-0.045039400458335876,
0.023574048653244972,
-0.013076964765787125,
-0.014066927134990692,
0.023518385365605354,
-0.02381536178290844,
0.010462574660778046,
-0.04525575786828995,
0.022951764985919,
0.05979042500257492,
-0.04234161227941513,
0.012193216942250729,
0.020792579278349876,
-0.02297211065888405,
0.001041856943629682,
-0.00052652508020401,
0.050288714468479156,
0.006194509100168943,
0.021204551681876183,
-0.004896452184766531,
-0.0470881424844265,
-0.0038309264928102493,
0.0018264035461470485,
-0.023620883002877235,
-0.000010034274964709766,
0.017585504800081253,
0.05237501114606857,
0.008047014474868774,
-0.024293668568134308,
-0.022902455180883408,
0.0008517078240402043,
0.030033566057682037,
-0.013709168881177902,
0.08197666704654694,
0.0007903728983364999,
0.026200149208307266,
0.010776830837130547,
0.03271641582250595,
0.05322533845901489,
-0.06061606854200363,
0.03145245090126991,
0.025294607505202293,
-0.02392248436808586,
0.0007541344384662807,
-0.023715339601039886,
-0.00894608162343502,
0.0173187293112278,
-0.05005478486418724,
0.02880011685192585,
0.012610284611582756,
0.007850957103073597,
0.007805096451193094,
0.00640222430229187,
-0.01999404840171337,
-0.03874688223004341,
0.008007674477994442,
0.011192845180630684,
-0.0017029710579663515,
-0.019628558307886124,
-0.016701461747288704,
0.011514957062900066,
-0.03148818388581276,
0.011434534564614296,
-0.003593405708670616,
-0.0008470055181533098,
-0.04151157662272453,
0.01933937706053257,
-0.017439616844058037,
0.027914967387914658,
0.012634698301553726,
0.006494208704680204,
-0.0473802350461483,
0.010961444117128849,
-0.016582170501351357,
0.03755908086895943,
-0.02085268497467041,
0.0032788212411105633,
0.06687944382429123,
-0.036522332578897476,
0.05284620448946953,
0.017267417162656784,
-0.002182119758799672,
-0.01063865702599287,
0.006382203660905361,
0.01752414181828499,
-0.020018838346004486,
0.03930654749274254,
0.006360579282045364,
0.025550026446580887,
0.029274942353367805,
-0.05065986141562462,
0.0006344231660477817,
0.011321273632347584,
-0.04548470675945282,
-0.004954318981617689,
0.00693994527682662,
-0.021059546619653702,
-0.04981452599167824,
-0.018103010952472687,
-0.012916812673211098,
-0.010657651349902153,
0.006508723367005587,
-0.008161479607224464,
-0.027234934270381927,
0.010085147805511951,
0.015798242762684822,
-0.023637568578124046,
0.01574062928557396,
-0.0031345419120043516,
-0.03147999942302704,
0.0003018977295141667,
-0.0018790164031088352,
-0.04327703267335892,
0.0018641430651769042,
-0.020867381244897842,
-0.01284906454384327,
0.026193983852863312,
0.02928326651453972,
-0.03632098808884621,
0.033108849078416824,
-0.03811749815940857,
0.00237881182692945,
-0.004029812756925821,
0.006676194723695517,
-0.021995794028043747,
-0.016653871163725853,
-0.04799995571374893,
0.02280440367758274,
0.02261844277381897,
0.001925034448504448,
0.0020557690877467394,
-0.02530663087964058,
0.0018958094296976924,
0.024032996967434883,
0.02350100316107273,
0.002089444315060973,
0.0069763618521392345,
-0.03298585116863251,
-0.06962541490793228,
-0.006309194955974817,
0.010158740915358067,
0.006483947858214378,
-0.01054058875888586,
-0.020899426192045212,
-0.013846010901033878,
-0.02917529083788395,
0.026653246954083443,
0.04293779656291008,
0.038481276482343674,
-0.0028792168013751507,
-0.002422035438939929,
0.008762212470173836,
0.0038075284101068974,
0.01494604256004095,
-0.03008827567100525,
0.03710901737213135,
0.028333492577075958,
-0.0012389767216518521,
-0.6929624080657959,
0.035172250121831894,
0.01208492275327444,
-0.026227502152323723,
0.002523580798879266,
0.02524755336344242,
-0.007253683637827635,
0.02060355804860592,
-0.04791951924562454,
0.009409752674400806,
-0.004609071649610996,
-0.00413023866713047,
-0.03775909170508385,
0.021725790575146675,
-0.02639947272837162,
-0.023003162816166878,
0.014261238276958466,
-0.005641870200634003,
0.0029724424239248037,
0.02003060095012188,
0.020489659160375595,
-0.016091207042336464,
-0.007652702275663614,
-0.011145452037453651,
-0.005179600324481726,
0.025688741356134415,
0.015916211530566216,
0.002124431310221553,
-0.04540122300386429,
-0.05676747113466263,
-0.004313196986913681,
-0.0355093888938427,
-0.0009483676985837519,
-0.019985906779766083,
0.01957879588007927,
0.02713717892765999,
0.003008256433531642,
0.005377190187573433,
-0.02458188869059086,
0.003773552132770419,
-0.011236583814024925,
-0.01047557033598423,
-0.04563653841614723,
-0.04155726358294487,
-0.02310257963836193,
-0.014074764214456081,
-0.03931913897395134,
-0.04760650917887688,
0.03573247045278549,
0.023123182356357574,
-0.01351548545062542,
0.050555210560560226,
0.054372482001781464,
-0.036342643201351166,
0.019981713965535164,
0.01865505799651146,
-0.011934787966310978,
-0.004545415285974741,
-0.028438931331038475,
0.030113326385617256,
0.018425723537802696,
0.013593404553830624,
-0.0035323661286383867,
0.01414353959262371,
-0.00678920466452837,
0.028237953782081604,
0.05380815267562866,
0.02249807119369507,
-0.03323023021221161,
-0.013292415998876095,
-0.09401261061429977,
0.012210680171847343,
-0.03507084399461746,
0.11777618527412415,
0.011108365841209888,
0.027371812611818314,
-0.018849268555641174,
0.004977610427886248,
-0.025079093873500824,
0.007637332659214735,
-0.015658322721719742,
-0.022190812975168228,
-0.03373246639966965,
-0.00012412246724124998,
-0.027964746579527855,
-0.000854726240504533,
-0.012251838110387325,
0.02527748793363571,
-0.0009375740773975849,
0.011052712798118591,
0.02449045702815056,
0.011115525849163532,
0.035344019532203674,
-0.01714029349386692,
0.003039681352674961,
0.03293563798069954,
-0.01025958452373743,
0.10702765733003616,
-0.00025186006678268313,
0.03820713236927986,
-0.02895495295524597,
0.005489252507686615,
-0.02139303833246231,
0.06184103339910507,
-0.03902142122387886,
-0.012132043950259686,
-0.03333093971014023,
-0.02821945771574974,
0.042356155812740326,
-0.03174769505858421,
-0.003382972441613674,
0.01031101681292057,
-0.004578522872179747,
0.0009042033343575895,
-0.021416686475276947,
-0.017417244613170624,
0.013851595111191273,
-0.02416953444480896,
0.01882731355726719,
-0.021502340212464333,
-0.03523322939872742,
-0.0038129575550556183,
0.007480683270841837,
0.013620969839394093,
-0.0018994917627424002,
-0.0024303249083459377,
-0.05108259618282318,
0.007133739069104195,
0.00025570570142008364,
-0.005661731120198965,
0.01844809763133526,
-0.001565849524922669,
-0.04492069035768509,
-0.0023620089050382376,
-0.0019322253065183759,
0.014983062632381916,
-0.020901961252093315,
-0.05387961491942406,
-0.02114223688840866,
-0.015109889209270477,
0.03477443754673004,
-0.03351001441478729,
-0.03772681578993797,
-0.06298980116844177,
0.03751782700419426,
-0.0037187847774475813,
0.010838696733117104,
0.01434003934264183,
0.020997200161218643,
-0.018601378425955772,
-0.01424904353916645,
0.021807562559843063,
-0.009105149656534195,
0.0005773513694293797,
0.01154632493853569,
0.03337177261710167,
-0.023946573957800865,
-0.012716609984636307,
0.03269556909799576,
-0.011154655367136002,
-0.020024344325065613,
0.011015474796295166,
-0.015050305053591728,
0.009346971288323402,
-0.015367838554084301,
-0.008218093775212765,
-0.0068687195889651775,
-0.011572819203138351,
-0.015780799090862274,
0.022005032747983932,
-0.0038506737910211086,
-0.0447920560836792,
0.0398157499730587,
-0.014756834134459496,
0.007492093835026026,
0.016879094764590263,
-0.010931720957159996,
-0.034728944301605225,
0.02160104177892208,
-0.01862465776503086,
0.021365389227867126,
-0.023230137303471565,
0.0043280464597046375,
-0.04655018821358681,
0.008642355911433697,
-0.004130394198000431,
-0.0038388906978070736,
0.046741750091314316,
0.010880084708333015,
-0.016131650656461716,
0.005015665665268898,
0.023069577291607857,
-0.03536766767501831,
0.01660885289311409,
-0.052539024502038956,
-0.021669361740350723,
-0.021242519840598106,
-0.000006614614449063083,
0.008305096067488194,
0.004182897973805666,
0.024294504895806313,
-0.005470335017889738,
0.0223896075040102,
-0.01618429645895958,
0.0065120370127260685,
0.010180499404668808,
0.01738344319164753,
-0.018418986350297928,
0.03861021623015404,
-0.04160809889435768,
0.01810789667069912,
-0.0030520630534738302,
0.0371176116168499,
0.006142436061054468,
-0.017147282138466835,
0.03859076276421547,
-0.02451907843351364,
-0.0451246052980423,
-0.0072674378752708435,
-0.025091862305998802,
-0.058346591889858246,
0.0020053526386618614,
0.029304668307304382,
-0.01773214153945446,
0.019690752029418945,
0.004438284784555435,
-0.029911955818533897,
-0.008345609530806541,
-0.02041730284690857,
-0.0374889113008976,
0.028498651459813118,
-0.009656287729740143,
0.042885757982730865,
-0.021211789920926094,
-0.010201744735240936,
0.04018544405698776,
-0.04111377149820328,
-0.012142292223870754,
-0.016449524089694023,
0.0013040598714724183,
0.0024077726993709803,
-0.012399525381624699,
-0.008349083364009857,
0.026203034445643425,
0.024913854897022247,
-0.004444774240255356,
0.004075446631759405,
-0.013157844543457031,
-0.035899750888347626,
0.0037689399905502796,
-0.029746875166893005,
0.015998855233192444,
-0.004779433365911245,
0.0313207283616066,
0.010634309612214565,
0.04492775350809097,
-0.04144545644521713,
0.020628459751605988,
0.01922762766480446,
0.012258634902536869,
0.038866158574819565,
-0.01590609923005104,
0.002518091816455126,
-0.03020683489739895,
0.04213162511587143,
0.0023810509592294693,
0.000679156044498086,
0.03487110882997513,
-0.02872738242149353,
0.02341882884502411,
0.00507673155516386,
-0.02579995058476925,
-0.0154956616461277,
-0.004169898573309183,
0.0029191041830927134,
0.016707926988601685,
0.02250232920050621,
-0.03866124525666237,
0.011635464616119862,
0.005315251648426056,
-0.029881440103054047,
0.018829604610800743,
0.03228549659252167,
0.04664649814367294,
0.029945356771349907,
-0.010342331603169441,
0.035842590034008026,
0.02502177096903324,
-0.050244759768247604,
0.007141470909118652,
0.01782338321208954,
-0.017953377217054367,
-0.0016292232321575284,
-0.008594824001193047,
-0.071163609623909,
-0.007103069685399532,
-0.02916734479367733,
-0.0031445955391973257,
0.032848846167325974,
0.0328863225877285,
-0.018393002450466156,
0.022909704595804214,
0.0007904679514467716,
-0.04208747670054436,
0.008009159937500954,
0.01393143180757761,
-0.0019486621022224426,
0.006124239880591631,
0.03792114555835724,
0.018429173156619072,
-0.004977789707481861,
0.0401439405977726,
0.007019472774118185,
-0.012906529940664768,
0.029369035735726357,
-0.0008630835800431669,
0.04015560448169708,
-0.005218402948230505,
0.003873767564073205,
-0.008132178336381912,
0.010285332798957825,
-0.0011927415616810322,
-0.028508873656392097,
-0.008994908072054386,
-0.030102161690592766,
-0.008455123752355576,
-0.0300860945135355,
0.023904697969555855,
0.011772981844842434,
0.023551272228360176,
-0.022072775289416313,
-0.0006091681425459683,
0.021481545642018318,
0.004487157333642244,
0.006857855711132288,
-0.023297399282455444,
0.02140234410762787,
0.02474397048354149,
0.03025021404027939,
-0.019413433969020844,
0.001708226976916194,
0.04446559026837349,
0.013142457231879234,
0.018282003700733185,
0.026234781369566917,
0.02525530755519867,
0.06431015580892563,
0.04185226932168007,
0.03471556305885315,
0.020602568984031677,
0.034769732505083084,
0.007615907117724419,
0.030635345727205276,
0.05628155544400215,
0.005648383405059576,
0.011248467490077019,
-0.05282542109489441,
0.014544324018061161,
0.05281916260719299,
-0.011469575576484203,
0.0035319665912538767,
0.005373434629291296,
-0.016637645661830902,
-0.013391717337071896,
-0.006719372700899839,
-0.0030983982142060995,
0.06359005719423294,
-0.011366203427314758,
-0.020308898761868477,
0.0002512006903998554,
-0.041426241397857666,
0.0041863080114126205,
0.00006754745845682919,
-0.011873428709805012,
0.018542230129241943,
0.0044383998028934,
0.02625421993434429,
0.025120055302977562,
0.010293823666870594,
0.00728524150326848,
0.010989947244524956,
-0.03047548606991768,
0.014689217321574688,
-0.03821941092610359,
0.028309253975749016,
-0.04340078681707382,
-0.019172610715031624,
-0.004325283225625753,
-0.009438186883926392,
0.005683466326445341,
-0.018820835277438164,
-0.007969739846885204,
0.020317452028393745,
0.021650584414601326,
-0.02878655679523945,
0.013584044761955738,
-0.026661528274416924,
0.00472608394920826,
0.03386612609028816,
-0.02063051424920559,
0.005304273217916489,
-0.0022495046723634005,
-0.007637886330485344,
-0.03856143355369568,
-0.006138883531093597,
-0.011908473446965218,
0.03817697614431381,
0.022394225001335144,
0.032895587384700775,
-0.014556830748915672,
0.023244399577379227,
-0.00674638943746686,
-0.03407943621277809,
-0.004094755742698908,
-0.06336461007595062,
0.016214145347476006,
-0.026365268975496292,
0.03247646987438202,
-0.018326958641409874,
0.06186813488602638,
-0.016772909089922905,
-0.01604771614074707,
-0.003410866018384695,
0.0062216706573963165,
-0.038242239505052567,
-0.03490997478365898,
-0.003813734045252204,
-0.0057663870975375175,
0.01758904755115509,
0.019571343436837196,
-0.0099728899076581,
-0.010373955592513084,
-0.021008111536502838,
0.003307440783828497,
0.03260720521211624,
0.016751637682318687,
-0.053216297179460526,
-0.03221205249428749,
-0.03411088511347771,
0.009290536865592003,
-0.002420677337795496,
-0.029325807467103004,
0.011981803923845291,
0.023051373660564423,
0.00933238584548235,
-0.015331423841416836,
-0.009305278770625591,
0.02219388261437416,
0.0040830885991454124,
-0.020773103460669518,
0.009016542695462704,
0.0026693607214838266,
0.017380516976118088,
0.01668064296245575,
0.03395908698439598,
-0.018545780330896378,
0.0043463148176670074,
0.0247220229357481,
-0.018541431054472923,
-0.006185752805322409,
-0.026595963165163994,
0.02127019688487053,
-0.045505959540605545,
-0.009917814284563065,
0.03595429286360741,
0.0420982725918293,
0.01633133552968502,
0.013607474975287914,
-0.006081621628254652,
-0.009389860555529594,
-0.0040281242690980434,
-0.02763456106185913,
-0.019682586193084717,
-0.0009757301886565983,
-0.002700228476896882,
0.009748517535626888,
0.020043684169650078,
0.012175658717751503,
-0.02155921421945095,
0.014798020012676716,
-0.010008218698203564,
0.0105645302683115,
0.011832506395876408,
-0.024234352633357048,
-0.00900937058031559,
-0.001345268334262073,
-0.01536659523844719,
0.023496394976973534,
-0.028103189542889595,
-0.00495843356475234,
-0.027763742953538895,
0.0009745034039951861,
-0.04168587550520897,
0.022939277812838554,
0.00663232384249568,
0.02030867151916027,
0.009531557559967041,
-0.026498856022953987,
0.0723932608962059,
0.003195488126948476,
-0.01328484620898962,
-0.0265228021889925,
-0.03230472654104233,
-0.013757877983152866,
0.03477456048130989,
0.028791973367333412,
0.05224672704935074,
0.051103394478559494,
-0.005472814664244652,
0.02086586318910122,
-0.007699279114603996,
-0.02558310516178608,
-0.033091869205236435,
0.010707039386034012,
-0.0023994590155780315,
0.0022224218118935823,
0.005968334618955851,
-0.04588952288031578,
-0.003765254747122526,
0.0022429099772125483,
0.013621470890939236,
0.023099642246961594,
0.014928937889635563,
-0.016943011432886124,
-0.0217868834733963,
0.009678138419985771,
-0.04278826341032982,
-0.03721662610769272,
0.007490447722375393,
0.023302193731069565,
0.007616820745170116,
-0.028001464903354645,
-0.040224120020866394,
-0.015811851248145103,
0.011119460687041283,
-0.046527083963155746,
-0.012581897899508476,
0.027855630964040756,
-0.021254729479551315,
-0.016270702704787254,
0.05873780697584152,
0.0020402022637426853,
-0.020569629967212677,
0.003767261514440179,
-0.0675138309597969,
-0.0009403324802406132,
0.018353676423430443,
-0.006527597084641457,
-0.01431744173169136,
0.03683875501155853,
-0.03137216344475746,
0.0038424646481871605,
0.014826761558651924,
0.006282627582550049,
-0.0512019544839859,
-0.026138046756386757,
0.0026038759388029575,
0.022857895120978355,
-0.018179064616560936,
-0.030034154653549194,
-0.004076972138136625,
-0.020881811156868935
] |
8a3245f4587a32c402e78f398ab94bc52ef0cf9a | 780 | py | Python | PaddleOCR/deploy/hubserving/ocr_det/params.py | TangJiamin/Ultra_light_OCR_No.23 | 594aa286dc2f88614141838ce45c164647226cdb | [
"Apache-2.0"
] | null | null | null | PaddleOCR/deploy/hubserving/ocr_det/params.py | TangJiamin/Ultra_light_OCR_No.23 | 594aa286dc2f88614141838ce45c164647226cdb | [
"Apache-2.0"
] | null | null | null | PaddleOCR/deploy/hubserving/ocr_det/params.py | TangJiamin/Ultra_light_OCR_No.23 | 594aa286dc2f88614141838ce45c164647226cdb | [
"Apache-2.0"
] | null | null | null | # -*- coding:utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
class Config(object):
pass
def read_params():
cfg = Config()
#params for text detector
cfg.det_algorithm = "DB"
cfg.det_model_dir = "./inference/ch_ppocr_mobile_v2.0_det_infer/"
cfg.det_limit_side_len = 960
cfg.det_limit_type = 'max'
#DB parmas
cfg.det_db_thresh = 0.3
cfg.det_db_box_thresh = 0.5
cfg.det_db_unclip_ratio = 1.6
cfg.use_dilation = False
# #EAST parmas
# cfg.det_east_score_thresh = 0.8
# cfg.det_east_cover_thresh = 0.1
# cfg.det_east_nms_thresh = 0.2
cfg.use_pdserving = False
cfg.use_tensorrt = False
return cfg
| 22.285714 | 70 | 0.661538 | 1 | 0.9561 | [
0.002016077982261777,
0.023200197145342827,
0.008600419387221336,
0.001198548823595047,
0.0028250347822904587,
-0.007046186365187168,
-0.006283713039010763,
0.0037947078235447407,
-0.008682931773364544,
-0.0005052239284850657,
0.002083053346723318,
0.003626555670052767,
0.009583551436662674,
-0.014914105646312237,
0.0011978752445429564,
0.01813618466258049,
-0.054764434695243835,
0.0005102720460854471,
-0.004074730444699526,
0.001459195977076888,
-0.010078204795718193,
0.009047207422554493,
0.008737267926335335,
0.005703100003302097,
0.003985452000051737,
-0.0027907988987863064,
0.012579568661749363,
-0.00008938941027736291,
-0.006566953845322132,
-0.007824000902473927,
-0.002306466456502676,
0.0004635079822037369,
-0.009547479450702667,
-0.007282447535544634,
0.005578529089689255,
-0.004545591771602631,
0.000573459139559418,
-0.020078498870134354,
0.011426197364926338,
-0.004001187160611153,
-0.004827477037906647,
-0.015458496287465096,
0.0008645047782920301,
0.0043013435788452625,
-0.008492756634950638,
0.0016562058590352535,
-0.004241114482283592,
0.003304059384390712,
-0.010300605557858944,
0.005686991382390261,
-0.012293745763599873,
0.006646261550486088,
0.013355065137147903,
0.004375604446977377,
-0.0059583294205367565,
-0.006394579075276852,
0.010910638608038425,
-0.0013018354075029492,
-0.012010336853563786,
0.0003232849412597716,
-0.005848247092217207,
-0.0003100918547715992,
0.005126520525664091,
0.005046038888394833,
-0.018009714782238007,
-0.00613590981811285,
-0.004424353130161762,
0.003046027384698391,
-0.0012078603031113744,
0.005489605013281107,
0.0037338712718337774,
-0.001888334285467863,
0.008072183467447758,
0.002049308968707919,
0.005144366528838873,
-0.005746903829276562,
-0.00028433132683858275,
-0.0004950531874783337,
0.007831448689103127,
0.0011067017912864685,
0.007019716314971447,
-0.005868369713425636,
0.005401114467531443,
0.009522768668830395,
0.013524465262889862,
0.01025854330509901,
0.019759416580200195,
-0.010021229274570942,
0.04699932783842087,
0.00827015470713377,
-0.010372884571552277,
0.0003618282498791814,
-0.00949177611619234,
-0.00409890990704298,
-0.004449131898581982,
-0.028690503910183907,
-0.001248308108188212,
-0.0032401257194578648,
0.001948280376382172,
0.004146177787333727,
0.0011201385641470551,
0.009330586530268192,
-0.001685084542259574,
-0.007287187036126852,
-0.007338279392570257,
0.01062192302197218,
-0.010700838640332222,
-0.002650122158229351,
0.008218614384531975,
0.0033882688730955124,
-0.013960284180939198,
-0.00009344991849502549,
0.0007095569162629545,
-0.014450335875153542,
0.005613842513412237,
0.001459795399568975,
-0.005605860613286495,
0.05304323881864548,
-0.0025039156898856163,
0.0033889934420585632,
-0.007394679356366396,
0.00006488758663181216,
0.0017610571812838316,
0.009385315701365471,
0.008006277494132519,
-0.002068420173600316,
0.011600395664572716,
0.007226626388728619,
0.00538049777969718,
0.007531080394983292,
-0.0005704811192117631,
0.007962821051478386,
0.00005696190055459738,
-0.0038175128865987062,
0.0020193683449178934,
-0.007146691903471947,
0.008449858985841274,
-0.0002893796772696078,
-0.010472838766872883,
0.006713511887937784,
-0.00008314850128954276,
-0.010872912593185902,
-0.001000858610495925,
-0.002274527447298169,
0.0038131976034492254,
-0.008576036430895329,
-0.004416678100824356,
-0.003606904298067093,
-0.004547181539237499,
0.002627674024552107,
0.010938452556729317,
0.006014987360686064,
0.005188856273889542,
-0.0054812016896903515,
-0.008621552027761936,
-0.00010916483734035864,
-0.004274012520909309,
0.00188149802852422,
0.0066251084208488464,
0.004291627090424299,
-0.00977026391774416,
-0.0011904705315828323,
0.0027845187578350306,
0.004369808826595545,
0.00009017426054924726,
0.0007275749230757356,
-0.008306512609124184,
0.009165010415017605,
0.0003072984400205314,
0.004737693350762129,
0.009698807261884212,
-0.0025245684664696455,
0.00041760221938602626,
-0.00001526460619061254,
0.0027980641461908817,
-0.004025513306260109,
0.005825161933898926,
0.01067869458347559,
-0.0040105851367115974,
-0.005691634491086006,
0.006537894252687693,
0.0027911942452192307,
0.005004644859582186,
0.008246884681284428,
-0.0032913191244006157,
0.0021990349050611258,
-0.0044687469489872456,
-0.0010142619721591473,
0.00821379479020834,
-0.0051945894956588745,
0.005435090512037277,
0.002111425157636404,
-0.012542277574539185,
-0.007385685108602047,
0.0018667252734303474,
-0.006678575649857521,
0.002231125719845295,
0.014554853551089764,
0.013883653096854687,
-0.0012290121521800756,
0.005166005343198776,
-0.008807116188108921,
0.001016465830616653,
0.00492520909756422,
0.0021523423492908478,
-0.011334920302033424,
-0.957963228225708,
0.009288135915994644,
0.0022608954459428787,
-0.0034789564087986946,
0.0032540487591177225,
0.0030991248786449432,
0.003144648391753435,
0.003699925262480974,
0.015307307243347168,
-0.006030034739524126,
-0.006634455174207687,
-0.009000618942081928,
-0.011959596537053585,
-0.0012805652804672718,
-0.006603637710213661,
-0.0034632678143680096,
-0.006880404427647591,
-0.0043474044650793076,
-0.0008164981845766306,
-0.004301438108086586,
-0.0029054756741970778,
0.012323680333793163,
-0.0013194987550377846,
0.0051659513264894485,
0.005291525274515152,
0.0030462362337857485,
-0.003661407856270671,
-0.0009825367014855146,
-0.0013517828192561865,
-0.001136074191890657,
-0.004900388419628143,
-0.014934631995856762,
-0.006290201563388109,
-0.001496514887548983,
0.012801761738955975,
0.0007973746978677809,
0.009239028207957745,
-0.0014446998247876763,
0.0038970967289060354,
-0.010513469576835632,
0.006854741834104061,
0.0012463681632652879,
0.005229939240962267,
-0.029477272182703018,
-0.00030532522941939533,
-0.0014594385866075754,
-0.006439324002712965,
0.008496432565152645,
0.0010216885711997747,
-0.002450512954965234,
-0.0035719077568501234,
-0.00655730627477169,
0.007607071194797754,
-0.008221914991736412,
0.0027676657773554325,
-0.004970257170498371,
-0.008647233247756958,
-0.004467597231268883,
-0.010252058506011963,
-0.00034810759825631976,
0.004406954161822796,
-0.005258341785520315,
-0.001739923725835979,
-0.005212598945945501,
0.0043485420756042,
0.003821337828412652,
-0.002341030864045024,
-0.019754914566874504,
-0.004434528294950724,
0.0005287247477099299,
0.0007638491806574166,
-0.000864283530972898,
-0.002799615729600191,
0.0023329593241214752,
-0.009923616424202919,
0.004830279387533665,
0.003212285926565528,
-0.0011150118662044406,
-0.013393066823482513,
-0.0008536739624105394,
-0.012228509411215782,
-0.006182459183037281,
0.0011209722142666578,
-0.005924798082560301,
-0.006001003086566925,
-0.001067881123162806,
0.00035162968561053276,
0.008240734227001667,
-0.004979421850293875,
0.005917280912399292,
0.012226903811097145,
0.0012800493277609348,
-0.008186555467545986,
0.007053270470350981,
0.008484702557325363,
0.0040099420584738255,
-0.0030193510465323925,
0.00000515739247930469,
0.007448590360581875,
0.009094424545764923,
0.003396435175091028,
0.0054692476987838745,
0.003337272210046649,
0.008105581626296043,
-0.002200683346018195,
0.0007398398010991514,
-0.006112625356763601,
-0.0009603278012946248,
-0.002018676372244954,
-0.0013799825683236122,
-0.0017202565213665366,
-0.0026754809077829123,
-0.013240142725408077,
-0.0075046890415251255,
-0.006386622786521912,
-0.0028712076600641012,
0.0022156122140586376,
-0.003978283144533634,
0.0014073484344407916,
0.0012275183107703924,
0.008196759037673473,
0.001938598812557757,
-0.0016970692668110132,
-0.0008873085025697947,
0.0023578135296702385,
-0.002137100789695978,
0.014458922669291496,
-0.013108848594129086,
0.00816805474460125,
-0.0030034054070711136,
-0.01432771235704422,
0.0055759623646736145,
0.009918839670717716,
-0.007011726964265108,
0.00004253052975400351,
0.0023166381288319826,
-0.0005728365504182875,
0.00012809137115254998,
-0.006538099143654108,
-0.002657349919900298,
-0.01750544086098671,
0.0013026570668444037,
0.01758831925690174,
0.002308355178683996,
0.010653713718056679,
0.011736895889043808,
-0.004914760589599609,
0.0015842535067349672,
0.006549444980919361,
0.0034951837733387947,
0.014645973220467567,
-0.008678657002747059,
0.0009364847792312503,
0.0010565599659457803,
-0.005182361695915461,
0.0010080421343445778,
0.006561273243278265,
0.002101598074659705,
-0.002637845929712057,
0.00026251765666529536,
-0.008869627490639687,
-0.009171062149107456,
-0.01948745734989643,
-0.004662257619202137,
0.006306916009634733,
-0.005619194824248552,
0.007165768649429083,
-0.009120234288275242,
0.0026497533544898033,
0.00487220473587513,
0.004376458004117012,
-0.001626718556508422,
0.0008056124206632376,
0.006223437376320362,
0.011746744625270367,
-0.007008570246398449,
0.005046694073826075,
0.002339709782972932,
-0.003789511974900961,
0.001921323360875249,
0.01221614982932806,
-0.006217433139681816,
-0.0061907111667096615,
0.005668123252689838,
0.0026763349305838346,
0.0019825375638902187,
-0.0035067452117800713,
-0.007095823064446449,
-0.006403518840670586,
0.0022518550977110863,
-0.004965034779161215,
0.0009936414426192641,
0.002130338456481695,
0.0014494220959022641,
-0.007739702705293894,
0.001647160155698657,
-0.0032706039492040873,
-0.0099039226770401,
0.01050295028835535,
-0.0018010296626016498,
0.001228980254381895,
0.014863239601254463,
0.004141556099057198,
-0.013305566273629665,
0.008390986360609531,
0.006807265803217888,
-0.003903650213032961,
0.005224461201578379,
0.006898379418998957,
-0.006312111858278513,
-0.022136887535452843,
-0.002439823467284441,
-0.016332533210515976,
0.0040700845420360565,
-0.0013218466192483902,
0.001680975779891014,
-0.009059811010956764,
0.012900280766189098,
0.005308730062097311,
-0.012746752239763737,
-0.003880132921040058,
-0.01038651168346405,
0.009998681023716927,
0.0016102440422400832,
0.0006573147256858647,
-0.0033600926399230957,
-0.001519245794042945,
-0.0034883087500929832,
-0.002935168333351612,
-0.0028346714098006487,
0.0028804903849959373,
0.0021553728729486465,
-0.001773990341462195,
0.003638082416728139,
-0.0022337129339575768,
0.000545626797247678,
0.0010837471345439553,
-0.010787908919155598,
-0.0012653082376345992,
0.004460148047655821,
-0.0005547492764890194,
-0.0036250753328204155,
0.0005906880833208561,
-0.00111743516754359,
-0.004359083715826273,
-0.011384524405002594,
-0.004363849759101868,
-0.0011650968808680773,
-0.0012876975815743208,
-0.010582546703517437,
-0.0026575264055281878,
-0.011327139101922512,
0.009158524684607983,
-0.005777293350547552,
0.007775138132274151,
0.0027217131573706865,
-0.005367862526327372,
0.007371342275291681,
-0.0018229675479233265,
0.0014178656274452806,
0.0031783117447048426,
0.005468548275530338,
0.0012210557470098138,
-0.009516117163002491,
-0.010252853855490685,
0.01230293046683073,
-0.009876983240246773,
0.005007505416870117,
0.01286834105849266,
0.002651385497301817,
0.00936540775001049,
-0.002807328710332513,
0.0014021772658452392,
0.004635513760149479,
0.008315728977322578,
-0.013593630865216255,
0.0021120591554790735,
-0.00291692023165524,
-0.0018342030234634876,
0.0049127247184515,
-0.0020167597103863955,
0.0026902053505182266,
0.010145812295377254,
0.002536691725254059,
-0.006258001085370779,
-0.0034853038378059864,
-0.00040336066740565,
0.000004489517323236214,
-0.012484974227845669,
0.00003047362588404212,
-0.0014253876870498061,
-0.0041096946224570274,
-0.0007451883866451681,
-0.0008327807881869376,
0.00006500989547930658,
0.005919335409998894,
-0.0009410659549757838,
0.0058552976697683334,
0.0034712632186710835,
-0.006419399753212929,
0.01691618748009205,
-0.00465611694380641,
-0.005688278004527092,
0.0034818288404494524,
0.00045113515807315707,
-0.0003303606645204127,
-0.008578168228268623,
-0.0015144454082474113,
0.0019686250016093254,
0.0042290398851037025,
-0.0020968392491340637,
-0.002856501145288348,
-0.0026415858883410692,
0.0015769234159961343,
-0.013433882966637611,
0.0023673889227211475,
0.01338495034724474,
-0.004175166133791208,
0.0034850898664444685,
-0.0018869648920372128,
-0.008997805416584015,
-0.012003927491605282,
0.05422598496079445,
-0.0010269727790728211,
0.0025622518733143806,
0.005879085045307875,
-0.006723269820213318,
-0.0015062764286994934,
-0.0032859425991773605,
0.007824278436601162,
-0.00497015193104744,
-0.007994502782821655,
0.007740796077996492,
-0.0032151155173778534,
0.002991116140037775,
0.008499110117554665,
-0.001874836627393961,
0.01665431819856167,
-0.004897665698081255,
-0.01504976861178875,
-0.01896083727478981,
0.004915246739983559,
-0.006420152727514505,
-0.006960127968341112,
0.009185229428112507,
-0.003709909738972783,
-0.005918171722441912,
0.0015292303869500756,
0.005570997949689627,
0.0003222004452254623,
-0.0012889609206467867,
-0.003907279577106237,
-0.0016226035077124834,
0.0005013751797378063,
0.0005103211151435971,
0.007125399075448513,
0.006963639985769987,
-0.002544776536524296,
0.002961871214210987,
0.002138538518920541,
-0.0031642713584005833,
0.0014406944392248988,
0.004796127323061228,
0.005440734326839447,
-0.0019497396424412727,
-0.0016376323765143752,
0.005156172905117273,
0.005629122722893953,
0.0008536498062312603,
0.008973206393420696,
-0.0020652383100241423,
-0.006406230386346579,
0.005337842274457216,
0.006368407513946295,
0.0008532216306775808,
0.0053553273901343346,
-0.003146644914522767,
0.005900898482650518,
0.003095118561759591,
-0.010126406326889992,
-0.01572059653699398,
0.0011471983743831515,
0.006987081374973059,
0.010110002011060715,
0.0036955566611140966,
0.003297875402495265,
-0.0007962472154758871,
-0.0027384792920202017,
-0.011421608738601208,
-0.005435698200017214,
-0.0011282972991466522,
0.002077527577057481,
0.0022043895442038774,
0.069587841629982,
-0.006962492596358061,
-0.0005427960422821343,
-0.008450918830931187,
-0.0005549679044634104,
-0.0003262439277023077,
-0.0006689260480925441,
-0.001828947220928967,
-0.0034959865733981133,
0.004042453598231077,
0.0010921942302957177,
-0.00913495197892189,
-0.012452120892703533,
0.0002542087167967111,
0.004024271387606859,
-0.005120917223393917,
0.0028453439008444548,
0.004378918092697859,
-0.010908053256571293,
0.00406228844076395,
-0.014906736090779305,
-0.0012773871421813965,
0.0019660599064081907,
-0.007590248249471188,
-0.0049330005422234535,
-0.001560202450491488,
0.004342628642916679,
0.003658812725916505,
0.003538023680448532,
-0.004035160876810551,
0.003576449351385236,
-0.004622325301170349,
-0.0010314487153664231,
-0.0034309234470129013,
-0.00016422501357737929,
-0.005382672417908907,
0.006745236925780773,
0.0005759502528235316,
-0.011167552322149277,
-0.006703232415020466,
-0.0010900466004386544,
0.0006380678387358785,
-0.0038918093778192997,
0.003159034764394164,
0.0012078495929017663,
0.002974455477669835,
-0.003753961995244026,
0.004023460205644369,
-0.004332000855356455,
0.0004448760882951319,
-0.012493031099438667,
0.007764419075101614,
-0.17108656466007233,
0.009746845811605453,
0.003336834255605936,
-0.0067993029952049255,
-0.003976717125624418,
-0.015308981761336327,
-0.00890055950731039,
0.0034042862243950367,
0.0095301428809762,
0.004459535237401724,
-0.0011819594074040651,
0.0034447561483830214,
0.00333806243725121,
0.0004502693482208997,
-0.004691438749432564,
-0.002363010076805949,
0.0035481788218021393,
-0.0054216161370277405,
0.0016536259790882468,
0.0069811721332371235,
0.004138682968914509,
0.009062418714165688,
0.0007613189518451691,
0.004405182786285877,
-0.0005336767062544823,
-0.006272803992033005,
0.004374682437628508,
-0.0009065251215361059,
0.006704145111143589,
-0.012740455567836761,
-0.006963287014514208,
-0.0006861885194666684,
-0.0035098346415907145,
0.00010306303011020645,
0.0018401825800538063,
-0.0013828673399984837,
0.009965670295059681,
0.0012340877437964082,
-0.006975570227950811,
0.007771939504891634,
-0.0070785945281386375,
0.03090357966721058,
0.007107049226760864,
0.003710404271259904,
-0.0016606452409178019,
-0.00564300362020731,
-0.004446520935744047,
0.00900061521679163,
0.0036037941463291645,
0.011395210400223732,
-0.01042091567069292,
0.00003257951175328344,
0.0024026576429605484,
0.01964384689927101,
-0.006497879512608051,
-0.008725536987185478,
-0.007437543943524361,
-0.0030024980660527945,
0.001383211463689804,
0.0090912114828825,
0.01045154593884945,
-0.0005971320206299424,
0.009115399792790413,
-0.004039738327264786,
-0.021031247451901436,
0.004662643652409315,
-0.002876362530514598,
-0.007886436767876148,
0.003062601201236248,
0.006927047856152058,
0.010527949780225754,
-0.002931560855358839,
0.004196974448859692,
-0.0037129924166947603,
0.006434753071516752,
0.000831926241517067,
0.005424586124718189,
-0.003989853896200657,
0.0066519081592559814,
-0.007667894475162029,
0.008501295000314713,
-0.010144928470253944,
-0.003257380798459053,
0.003577358089387417,
-0.00617853831499815,
0.008174055255949497,
0.0061186207458376884,
-0.0028712861239910126,
-0.0009436610853299499,
-0.010910311713814735,
-0.002319648629054427,
-0.000257070962106809,
0.002672183094546199,
-0.009738819673657417,
0.004744520876556635,
-0.00018967072537634522,
0.005820312071591616,
0.009741712361574173,
-0.008278865367174149,
0.008637242950499058,
0.0031235460191965103,
-0.0073159304447472095,
-0.0016600439557805657,
-0.003703352529555559,
0.004135705064982176,
0.0037960547488182783,
-0.006842378061264753,
-0.005665504839271307,
0.004716745112091303,
-0.008833716623485088,
-0.003545373911038041,
0.006743717938661575,
-0.011556289158761501,
-0.012501846067607403,
-0.00015813067147973925,
-0.011024427600204945,
-0.00016155334014911205
] |
8a328b7be397a48ed8f6202385b17e0dbf81357c | 12,156 | py | Python | networks/larflow/models/larflow_uresnet.py | LArbys/ublarcvserver | 02381c937f49a2eab2f754017ab431c3f6fa70d7 | [
"Apache-2.0"
] | 2 | 2020-07-09T19:34:03.000Z | 2021-06-21T23:09:23.000Z | networks/larflow/models/larflow_uresnet.py | LArbys/ublarcvserver | 02381c937f49a2eab2f754017ab431c3f6fa70d7 | [
"Apache-2.0"
] | null | null | null | networks/larflow/models/larflow_uresnet.py | LArbys/ublarcvserver | 02381c937f49a2eab2f754017ab431c3f6fa70d7 | [
"Apache-2.0"
] | null | null | null | import torch.nn as nn
import torch as torch
import math
import torch.utils.model_zoo as model_zoo
###########################################################
#
# U-ResNet
# U-net witih ResNet modules
#
# Semantic segmentation network used by MicroBooNE
# to label track/shower pixels
#
# resnet implementation from pytorch.torchvision module
# U-net from (cite)
#
# meant to be copy of caffe version
#
###########################################################
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,padding=1, bias=False)
class BasicBlock(nn.Module):
expansion = 1
def __init__(self, inplanes, planes, stride=1):
super(BasicBlock, self).__init__()
self.conv1 = conv3x3(inplanes, planes, stride)
self.bn1 = nn.BatchNorm2d(planes)
self.relu1 = nn.ReLU(inplace=True)
self.conv2 = conv3x3(planes, planes)
self.bn2 = nn.BatchNorm2d(planes)
self.stride = stride
self.bypass = None
if inplanes!=planes or stride>1:
self.bypass = nn.Conv2d(inplanes, planes, kernel_size=1, stride=stride, padding=0, bias=False)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
out = self.conv1(x)
out = self.bn1(out)
out = self.relu1(out)
out = self.conv2(out)
out = self.bn2(out)
if self.bypass is not None:
outbp = self.bypass(x)
out += outbp
else:
out += x
out = self.relu(out)
return out
class Bottleneck(nn.Module):
def __init__(self, inplanes, planes, stride=1 ):
super(Bottleneck, self).__init__()
# residual path
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(planes)
self.conv3 = nn.Conv2d(planes, planes, kernel_size=1, bias=False)
self.bn3 = nn.BatchNorm2d(planes)
self.relu = nn.ReLU(inplace=True)
self.stride = stride
# if stride >1, then we need to subsamble the input
if stride>1:
self.shortcut = nn.Conv2d(inplanes,planes,kernel_size=1,stride=stride,bias=False)
else:
self.shortcut = None
def forward(self, x):
if self.shortcut is None:
bypass = x
else:
bypass = self.shortcut(x)
residual = self.conv1(x)
residual = self.bn1(residual)
residual = self.relu(residual)
residual = self.conv2(residual)
residual = self.bn2(residual)
residual = self.relu(residual)
residual = self.conv3(residual)
residual = self.bn3(residual)
out = bypass+residual
out = self.relu(out)
return out
class PreactivationBlock(nn.Module):
def __init__(self, inplanes, planes, stride=1 ):
super(Preactivation, self).__init__()
# residual path
self.bn1 = nn.BatchNorm2d(inplanes)
self.relu1 = nn.ReLU(inplace=True)
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, bias=False)
self.bn2 = nn.BatchNorm2d(planes)
self.relu2 = nn.ReLU(inplace=True)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
# if stride >1, then we need to subsamble the input
if stride>1:
self.shortcut = nn.Conv2d(inplanes,planes,kernel_size=1,stride=stride,bias=False)
else:
self.shortcut = None
def forward(self, x):
if self.shortcut is None:
bypass = x
else:
bypass = self.shortcut(x)
class DoubleResNet(nn.Module):
def __init__(self,Block,inplanes,planes,stride=1):
super(DoubleResNet,self).__init__()
self.res1 = Block(inplanes,planes,stride)
self.res2 = Block( planes,planes, 1)
def forward(self, x):
out = self.res1(x)
out = self.res2(out)
return out
class ConvTransposeLayer(nn.Module):
def __init__(self,deconv_inplanes,skip_inplanes,deconv_outplanes,res_outplanes):
super(ConvTransposeLayer,self).__init__()
self.deconv = nn.ConvTranspose2d( deconv_inplanes, deconv_outplanes, kernel_size=4, stride=2, padding=1, bias=False )
self.res = DoubleResNet(BasicBlock,deconv_outplanes+skip_inplanes,res_outplanes,stride=1)
def forward(self,x,skip_x):
out = self.deconv(x,output_size=skip_x.size())
# concat skip connections
out = torch.cat( [out,skip_x], 1 )
out = self.res(out)
return out
class LArFlowUResNet(nn.Module):
def __init__(self, num_classes=3, input_channels=3, inplanes=16, showsizes=False, use_visi=True):
self.inplanes =inplanes
super(LArFlowUResNet, self).__init__()
self._showsizes = showsizes # print size at each layer
self.use_visi = use_visi
# Encoder
# stem
# one big stem
self.conv1 = nn.Conv2d(input_channels, self.inplanes, kernel_size=7, stride=1, padding=3, bias=True) # initial conv layer
self.bn1 = nn.BatchNorm2d(self.inplanes)
self.relu1 = nn.ReLU(inplace=True)
self.pool1 = nn.MaxPool2d( 3, stride=2, padding=1 )
self.enc_layer1 = self._make_encoding_layer( self.inplanes*1, self.inplanes*2, stride=1) # 16->32
self.enc_layer2 = self._make_encoding_layer( self.inplanes*2, self.inplanes*4, stride=2) # 32->64
self.enc_layer3 = self._make_encoding_layer( self.inplanes*4, self.inplanes*8, stride=2) # 64->128
self.enc_layer4 = self._make_encoding_layer( self.inplanes*8, self.inplanes*16, stride=2) # 128->256
self.enc_layer5 = self._make_encoding_layer( self.inplanes*16, self.inplanes*32, stride=2) # 256->512
# decoding flow
#self.num_final_flow_features = self.inplanes
self.num_final_flow_features = self.inplanes
self.flow_dec_layer5 = self._make_decoding_layer( self.inplanes*32*2, self.inplanes*16, self.inplanes*16, self.inplanes*16 ) # 512->256
self.flow_dec_layer4 = self._make_decoding_layer( self.inplanes*16, self.inplanes*8, self.inplanes*8, self.inplanes*8 ) # 256->128
self.flow_dec_layer3 = self._make_decoding_layer( self.inplanes*8, self.inplanes*4, self.inplanes*4, self.inplanes*4 ) # 128->64
self.flow_dec_layer2 = self._make_decoding_layer( self.inplanes*4, self.inplanes*2, self.inplanes*2, self.inplanes*2 ) # 64->32
#self.flow_dec_layer1 = self._make_decoding_layer( self.inplanes*2, self.inplanes, self.inplanes ) # 32->16
self.flow_dec_layer1 = self._make_decoding_layer( self.inplanes*2, self.inplanes, self.inplanes, self.num_final_flow_features ) # 32->200
# decoding matchability
if self.use_visi:
self.visi_dec_layer5 = self._make_decoding_layer( self.inplanes*32*2, self.inplanes*16, self.inplanes*16, self.inplanes*16 ) # 512->256
self.visi_dec_layer4 = self._make_decoding_layer( self.inplanes*16, self.inplanes*8, self.inplanes*8, self.inplanes*8 ) # 256->128
self.visi_dec_layer3 = self._make_decoding_layer( self.inplanes*8, self.inplanes*4, self.inplanes*4, self.inplanes*4 ) # 128->64
self.visi_dec_layer2 = self._make_decoding_layer( self.inplanes*4, self.inplanes*2, self.inplanes*2, self.inplanes*2 ) # 64->32
self.visi_dec_layer1 = self._make_decoding_layer( self.inplanes*2, self.inplanes, self.inplanes, self.inplanes ) # 32->16
# 1x1 conv for flow
self.flow_conv = nn.Conv2d( self.num_final_flow_features, 1, kernel_size=1, stride=1, padding=0, bias=True )
# 1x1 conv for mathability
if self.use_visi:
self.visi_conv = nn.Conv2d( self.inplanes, 2, kernel_size=1, stride=1, padding=0, bias=True ) # 2 classes, 0=not vis, 1=vis
self.visi_softmax = nn.LogSoftmax(dim=1)
# initialization
for m in self.modules():
if isinstance(m, nn.Conv2d) or isinstance(m,nn.ConvTranspose2d):
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
m.weight.data.normal_(0, math.sqrt(2. / n))
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def _make_encoding_layer(self, inplanes, planes, stride=2):
return DoubleResNet(BasicBlock,inplanes,planes,stride=stride)
def _make_decoding_layer(self, inplanes, skipplanes, deconvplanes, resnetplanes ):
return ConvTransposeLayer( inplanes, skipplanes, deconvplanes, resnetplanes )
def encode(self,x):
# stem
x = self.conv1(x)
x = self.bn1(x)
x0 = self.relu1(x)
x = self.pool1(x0)
x1 = self.enc_layer1(x)
x2 = self.enc_layer2(x1)
x3 = self.enc_layer3(x2)
x4 = self.enc_layer4(x3)
x5 = self.enc_layer5(x4)
if self._showsizes:
print "after encoding: "
print " x1: ",x1.size()
print " x2: ",x2.size()
print " x3: ",x3.size()
print " x4: ",x4.size()
print " x5: ",x5.size()
return x5,x0,x1,x2,x3,x4
def flow(self,merged_encode,x0,x1,x2,x3,x4):
""" decoding to flow prediction """
x = self.flow_dec_layer5(merged_encode,x4)
if self._showsizes:
print "after decoding:"
print " dec5: ",x.size()," iscuda=",x.is_cuda
x = self.flow_dec_layer4(x,x3)
if self._showsizes:
print " dec4: ",x.size()," iscuda=",x.is_cuda
x = self.flow_dec_layer3(x,x2)
if self._showsizes:
print " dec3: ",x.size()," iscuda=",x.is_cuda
x = self.flow_dec_layer2(x,x1)
if self._showsizes:
print " dec2: ",x.size()," iscuda=",x.is_cuda
x = self.flow_dec_layer1(x,x0)
if self._showsizes:
print " dec1: ",x.size()," iscuda=",x.is_cuda
return x
def visibility(self,merged_encode,x0,x1,x2,x3,x4):
""" decoding to flow prediction """
x = self.visi_dec_layer5(merged_encode,x4)
if self._showsizes:
print "after decoding:"
print " dec5: ",x.size()," iscuda=",x.is_cuda
x = self.visi_dec_layer4(x,x3)
if self._showsizes:
print " dec4: ",x.size()," iscuda=",x.is_cuda
x = self.visi_dec_layer3(x,x2)
if self._showsizes:
print " dec3: ",x.size()," iscuda=",x.is_cuda
x = self.visi_dec_layer2(x,x1)
if self._showsizes:
print " dec2: ",x.size()," iscuda=",x.is_cuda
x = self.visi_dec_layer1(x,x0)
if self._showsizes:
print " dec1: ",x.size()," iscuda=",x.is_cuda
return x
def forward(self, src, target):
if self._showsizes:
print "input: ",x.size()," is_cuda=",x.is_cuda
src_encode, s0, s1, s2, s3, s4 = self.encode(src)
target_encode, t0, t1, t2, t3, t4 = self.encode(target)
merged_encode = torch.cat( [target_encode,src_encode], 1 )
flowout = self.flow( merged_encode, s0, s1, s2, s3, s4 )
if self.use_visi:
visiout = self.visibility( merged_encode, t0, t1, t2, t3, t4 )
flow_predict = self.flow_conv( flowout )
if self.use_visi:
visi_predict = self.visi_conv( visiout )
visi_predict = self.visi_softmax(visi_predict)
else:
visi_predict = None
if self._showsizes:
print " softmax: ",x.size()
return flow_predict,visi_predict
| 36.286567 | 152 | 0.599786 | 0 | 0 | [
-0.0854632705450058,
0.024271978065371513,
-0.011135147884488106,
-0.007208495866507292,
0.013388988561928272,
0.030839234590530396,
-0.03195352852344513,
-0.022013811394572258,
0.0015700358198955655,
0.041309550404548645,
0.05631908401846886,
0.003492854768410325,
0.01847619190812111,
0.00839257426559925,
-0.04283446818590164,
-0.008553546853363514,
0.1207304298877716,
-0.007602013181895018,
-0.01873018965125084,
0.013665215112268925,
0.006619905587285757,
0.005201825872063637,
-0.0063003008253872395,
0.015855303034186363,
0.05654410645365715,
-0.04479362070560455,
0.035004857927560806,
-0.013377250172197819,
-0.0025894115678966045,
0.01692279241979122,
0.026194337755441666,
0.0006387339089997113,
-0.010458591394126415,
0.004854097496718168,
0.0022497649770230055,
0.023010844364762306,
0.014239376410841942,
-0.05668370798230171,
0.023907992988824844,
0.02068488672375679,
-0.007667057681828737,
-0.018088368698954582,
-0.03151001036167145,
-0.04213108494877815,
0.02664642408490181,
0.03214412182569504,
-0.01574966497719288,
-0.01562942937016487,
-0.0801127552986145,
0.004657629877328873,
-0.006624886300414801,
-0.004899251740425825,
0.027636324986815453,
-0.05247346684336662,
-0.011237796396017075,
-0.04449253901839256,
-0.0023030717857182026,
0.0313800610601902,
-0.027962354943156242,
-0.04454953223466873,
-0.022535910829901695,
-0.008657244965434074,
0.029074298217892647,
-0.01301389280706644,
0.003074587555602193,
-0.0017390509601682425,
-0.002504962030798197,
-0.0340714193880558,
-0.03256243094801903,
0.0030208975076675415,
0.003611228661611676,
-0.002572743222117424,
0.004621326923370361,
0.03923957422375679,
0.007640097755938768,
-0.019048238173127174,
-0.030403409153223038,
0.001377662061713636,
0.00040556499152444303,
0.04873667657375336,
-0.011463301256299019,
0.0930401012301445,
0.01218328159302473,
0.0259704627096653,
-0.017340976744890213,
0.059758491814136505,
0.016136836260557175,
-0.09104423224925995,
0.04431529343128204,
0.020145181566476822,
-0.029318474233150482,
0.04339810833334923,
-0.038027066737413406,
-0.026843702420592308,
-0.022760996595025063,
-0.04708673432469368,
0.011932378634810448,
-0.013641576282680035,
0.024192189797759056,
0.00643181661143899,
0.009711730293929577,
-0.029421597719192505,
0.04425928741693497,
-0.019051166251301765,
0.011992830783128738,
0.02225111983716488,
-0.03411775454878807,
0.0017723658820614219,
-0.008499528281390667,
0.0019763410091400146,
-0.051068682223558426,
-0.02508184127509594,
0.014280853793025017,
-0.03180069476366043,
0.014816557057201862,
-0.038682468235492706,
0.031296033412218094,
0.012547953985631466,
-0.01093139685690403,
-0.025273103266954422,
0.007878907024860382,
0.014448404312133789,
0.012750337831676006,
-0.0011431454913690686,
-0.044770319014787674,
0.06980231404304504,
0.013885384425520897,
0.0425637848675251,
0.04789460077881813,
-0.03831591457128525,
0.01433775294572115,
0.0337807834148407,
0.00113977724686265,
-0.0059328810311853886,
0.010679474100470543,
-0.010902348905801773,
-0.016793571412563324,
0.014622321352362633,
-0.05150950327515602,
-0.011401932686567307,
-0.02538863755762577,
0.016163038089871407,
-0.024865146726369858,
-0.012763663195073605,
-0.02041834034025669,
-0.058960363268852234,
-0.04805334284901619,
-0.010245191864669323,
-0.013840307481586933,
-0.010669780895113945,
0.047065574675798416,
0.003832484595477581,
0.014352071098983288,
0.02450672537088394,
-0.04004736617207527,
-0.03457968309521675,
0.004697875119745731,
-0.0849410742521286,
-0.01271822303533554,
-0.007049152627587318,
-0.0982654020190239,
0.0006923092296347022,
-0.006526668090373278,
0.017486149445176125,
0.048495225608348846,
0.03816935792565346,
-0.024469800293445587,
-0.020147142931818962,
-0.040558818727731705,
-0.006322364788502455,
0.025161003693938255,
-0.005825664382427931,
-0.01364453136920929,
-0.01094550359994173,
0.016367673873901367,
-0.026995744556188583,
0.06832051277160645,
-0.006667595822364092,
-0.027883153408765793,
0.007001106161624193,
-0.0027158386074006557,
0.008938157930970192,
0.00810362957417965,
0.011511249467730522,
0.004620098974555731,
0.02474907785654068,
-0.06978932023048401,
-0.017371781170368195,
-0.014639703556895256,
0.00011615264520514756,
0.015917254611849785,
0.01135693583637476,
-0.008631547912955284,
-0.042840052396059036,
0.006057275924831629,
0.0163167305290699,
-0.010911171324551105,
0.002896092366427183,
-0.008171431720256805,
0.02576300874352455,
0.01709393411874771,
-0.0020645316690206528,
0.006656320299953222,
0.04358598589897156,
0.0022675534710288048,
0.005333012901246548,
-0.6154541969299316,
0.032508205622434616,
-0.0018600322073325515,
-0.006739354692399502,
0.006923092529177666,
0.034868042916059494,
-0.02866986393928528,
-0.006437255069613457,
-0.029715485870838165,
0.0019672662019729614,
-0.014029149897396564,
-0.006007279735058546,
-0.02130194939672947,
-0.03230191022157669,
-0.013579001650214195,
-0.05239264294505119,
0.004407681990414858,
-0.014677590690553188,
-0.03413010761141777,
0.016199547797441483,
-0.012040875852108002,
-0.017247049137949944,
0.014946330338716507,
0.007331498432904482,
0.0010012454586103559,
0.02249305695295334,
-0.005995647516101599,
-0.0267020370811224,
-0.0004083861131221056,
0.015433648601174355,
0.01575809344649315,
-0.03385341167449951,
0.04225385561585426,
0.019309433177113533,
0.02713468112051487,
0.013483671471476555,
0.029199466109275818,
-0.006714461836963892,
-0.02934827096760273,
-0.004924315959215164,
-0.024751322343945503,
-0.030337752774357796,
-0.017782311886548996,
-0.061051808297634125,
-0.020981058478355408,
-0.025914810597896576,
-0.03572409600019455,
0.009186804294586182,
0.0066043003462255,
-0.01348885428160429,
-0.03917568549513817,
0.05415666103363037,
0.00890014786273241,
-0.023043429479002953,
0.01811978407204151,
0.028380924835801125,
-0.016603097319602966,
0.018838396295905113,
-0.015327146276831627,
0.005194486118853092,
0.013643146492540836,
0.03939802572131157,
-0.013910750858485699,
0.014881548471748829,
-0.047930411994457245,
0.021157676354050636,
0.07571285963058472,
0.006209754850715399,
0.0013454583240672946,
0.044257257133722305,
-0.08193637430667877,
0.024363575503230095,
-0.011751051060855389,
0.14159254729747772,
0.007260489277541637,
0.03782234340906143,
-0.015006721019744873,
0.041305139660835266,
-0.015407274477183819,
0.004213327541947365,
-0.02312595769762993,
-0.0243462435901165,
-0.007307885680347681,
0.019523216411471367,
-0.041946783661842346,
-0.022454166784882545,
-0.03167947381734848,
0.008827016688883305,
0.00013798179861623794,
0.009351769462227821,
0.013192323967814445,
0.06019335240125656,
0.019930267706513405,
-0.018824268132448196,
0.039226632565259933,
0.005678836721926928,
0.0033907212782651186,
0.06747708469629288,
0.006434999406337738,
0.016858594492077827,
0.0031303069554269314,
0.037453919649124146,
-0.000880202918779105,
0.020956050604581833,
0.029737256467342377,
0.04696356877684593,
-0.08690482378005981,
0.0014502210542559624,
0.06958993524312973,
-0.015114884823560715,
-0.02852264977991581,
-0.021435150876641273,
-0.03915275260806084,
0.011008852161467075,
-0.015120473690330982,
-0.008655745536088943,
-0.025717832148075104,
-0.045620281249284744,
-0.019986314699053764,
0.019754886627197266,
0.0021657284814864397,
0.038322556763887405,
0.019528763368725777,
0.03195328265428543,
0.029685672372579575,
0.015804346650838852,
-0.030441658571362495,
0.026074152439832687,
0.030148623511195183,
-0.009001906961202621,
-0.0008617069688625634,
-0.061590567231178284,
-0.015974227339029312,
-0.01911470666527748,
0.020940285176038742,
-0.022655492648482323,
-0.016326719895005226,
-0.052155833691358566,
0.010542169213294983,
0.02696479856967926,
-0.02204832248389721,
0.003520091064274311,
-0.006264760158956051,
-0.05363459512591362,
-0.04006229341030121,
-0.011687908321619034,
-0.008113606832921505,
0.02718200907111168,
0.06045784801244736,
0.0027865569572895765,
-0.024532947689294815,
0.0031932147685438395,
-0.010052920319139957,
0.013630366884171963,
-0.0042380099184811115,
-0.03638971596956253,
0.0006777982343919575,
-0.0018873853841796517,
0.01612255536019802,
0.008199432864785194,
-0.01415933296084404,
0.05517787113785744,
0.0016033663414418697,
-0.015331478789448738,
0.03070892207324505,
0.03404699265956879,
-0.01657801866531372,
-0.007728636730462313,
0.023502735421061516,
0.029707618057727814,
0.026965731754899025,
-0.016253294423222542,
0.008968813344836235,
0.0033519624266773462,
-0.01752854324877262,
-0.017913267016410828,
-0.03711352124810219,
-0.04436028003692627,
0.01222142018377781,
-0.012763235718011856,
-0.0237015001475811,
-0.009095980785787106,
-0.00794832780957222,
-0.00865121465176344,
-0.012935985811054707,
0.0008498922688886523,
0.0005003165570087731,
0.00030352864996530116,
-0.020688965916633606,
0.012508277781307697,
0.03160911425948143,
0.008427029475569725,
0.0037385867908596992,
0.020941367372870445,
-0.02615315653383732,
-0.03560443967580795,
0.03830358758568764,
-0.03893904760479927,
-0.0004781500028911978,
-0.010630985721945763,
0.034996263682842255,
-0.047327920794487,
0.01022823341190815,
0.010611886158585548,
-0.004454079549759626,
0.06444836407899857,
-0.0014287530211731791,
0.04776044934988022,
-0.021512534469366074,
-0.050772927701473236,
0.07267296314239502,
0.01410472672432661,
0.03494662046432495,
-0.005868783686310053,
-0.013468501158058643,
0.04033350944519043,
-0.010757893323898315,
-0.0030262835789471865,
0.0038429261185228825,
-0.05333978310227394,
-0.043245092034339905,
-0.03691728040575981,
0.01647106558084488,
-0.005057791713625193,
-0.019979113712906837,
-0.008227554149925709,
-0.0063949814066290855,
0.01817050203680992,
0.02085437998175621,
-0.037126172333955765,
0.010695083066821098,
-0.025507839396595955,
0.03436632081866264,
-0.06024426594376564,
-0.009656531736254692,
-0.05299263820052147,
-0.029845494776964188,
-0.0034851613454520702,
0.0055795032531023026,
0.0018380095716565847,
-0.0014307867968454957,
-0.006380859762430191,
-0.024217231199145317,
-0.0072215222753584385,
-0.04671177640557289,
-0.03269675374031067,
-0.0046301851980388165,
-0.036868371069431305,
-0.011104084551334381,
-0.011930989101529121,
-0.017077339813113213,
0.06104585528373718,
0.013218095526099205,
-0.020374000072479248,
-0.0022405353374779224,
0.06707420200109482,
-0.05255988985300064,
0.021850205957889557,
0.05573703348636627,
0.021732527762651443,
-0.015013945288956165,
-0.0022690892219543457,
-0.045832134783267975,
0.0005155809340067208,
-0.0558580607175827,
0.02913624234497547,
0.0031767517793923616,
-0.02365826442837715,
0.005158861167728901,
-0.012790928594768047,
0.012256858870387077,
-0.01286934781819582,
-0.03124352917075157,
0.005190916825085878,
0.00830952636897564,
0.003959632012993097,
0.025176361203193665,
-0.009276083670556545,
0.029711822047829628,
0.023039953783154488,
-0.005571953020989895,
-0.016519412398338318,
0.023977745324373245,
0.029139405116438866,
0.025828689336776733,
0.004039714112877846,
0.05187405273318291,
0.028232969343662262,
-0.06238054111599922,
-0.006114115007221699,
-0.017999373376369476,
0.008729137480258942,
0.03141581639647484,
-0.010756274685263634,
0.012990559451282024,
0.009526324458420277,
0.004609810188412666,
-0.015053635463118553,
0.021218840032815933,
0.023455597460269928,
0.025362351909279823,
0.0400097593665123,
0.021798796951770782,
0.014132458716630936,
-0.017613817006349564,
0.00006215048779267818,
-0.010885096155107021,
-0.03843363747000694,
0.03517163172364235,
0.009420652873814106,
0.002669131150469184,
-0.0020195876713842154,
0.010811537504196167,
-0.00026624472229741514,
0.014250501990318298,
-0.02962021715939045,
0.031211046501994133,
0.03334030136466026,
0.009732993319630623,
0.01469617523252964,
0.0022511077113449574,
-0.006280642002820969,
0.047990430146455765,
0.024090122431516647,
-0.035887353122234344,
-0.03796005994081497,
-0.02373669110238552,
-0.005133101716637611,
-0.022633731365203857,
-0.037118732929229736,
0.004348843824118376,
-0.02027030847966671,
0.003001320408657193,
0.013655457645654678,
0.024782752618193626,
-0.04418452829122543,
0.02728993445634842,
0.024764588102698326,
0.040778279304504395,
-0.00891834031790495,
0.02448689565062523,
-0.004097298253327608,
-0.012891588732600212,
0.0056762611493468285,
0.009165804833173752,
-0.0003319120150990784,
0.058153893798589706,
0.06215285509824753,
0.02876274846494198,
0.04098666459321976,
-0.008954220451414585,
-0.004533179569989443,
-0.04492567107081413,
-0.0005815494223497808,
0.0036072381772100925,
-0.04223349317908287,
-0.020013604313135147,
-0.0025295407976955175,
0.028154117986559868,
-0.005581254605203867,
-0.03688082844018936,
-0.03255463391542435,
-0.01226538885384798,
0.027852356433868408,
0.04111086204648018,
0.0017979779513552785,
0.04389980435371399,
-0.013628347776830196,
-0.015633411705493927,
0.0063281916081905365,
-0.02015666663646698,
0.016570940613746643,
-0.006369087845087051,
-0.014314420521259308,
0.024761511012911797,
0.04104580357670784,
0.01078686024993658,
-0.013979336246848106,
-0.03461538255214691,
0.019456682726740837,
0.029416916891932487,
-0.0462779738008976,
0.04925931245088577,
-0.06138705462217331,
0.06360947340726852,
0.022454312071204185,
0.018914291635155678,
0.01115602906793356,
0.04908222705125809,
-0.03560507670044899,
-0.025024479255080223,
-0.005084361881017685,
0.03846601024270058,
0.056122735142707825,
-0.00000989656473393552,
-0.015378172509372234,
-0.05669959634542465,
0.0029934870544821024,
0.02187020517885685,
-0.017980540171265602,
-0.007200903724879026,
0.020535584539175034,
0.007956493645906448,
-0.02566579543054104,
-0.04671390727162361,
-0.004384200554341078,
0.04409485682845116,
-0.025469008833169937,
0.0005116364918649197,
-0.04875949025154114,
0.0041622803546488285,
-0.029444225132465363,
0.001664699288085103,
0.006393612362444401,
0.027431441470980644,
0.004287772346287966,
-0.06584875285625458,
-0.005405010189861059,
-0.017004622146487236,
0.0011421128874644637,
-0.03896225243806839,
0.002912375144660473,
-0.008595620281994343,
0.03786517679691315,
0.012904652394354343,
0.001626932411454618,
0.05433027446269989,
-0.017504410818219185,
-0.0027478153351694345,
-0.004781059455126524,
0.02037317119538784,
0.006017227657139301,
-0.007996505126357079,
-0.004178095608949661,
0.009417286142706871,
-0.0046704537235200405,
-0.006515731103718281,
-0.017975134775042534,
-0.014357045292854309,
0.026118088513612747,
-0.01397201232612133,
0.008870454505085945,
0.026622675359249115,
0.024598857387900352,
-0.01642804779112339,
0.015085692517459393,
0.014907482080161572,
-0.0016651734476909041,
0.04046543687582016,
-0.012523423880338669,
-0.007184018846601248,
-0.0044369869865477085,
0.00820928905159235,
0.002959343371912837,
-0.015157425776124,
-0.011544937267899513,
0.03210195153951645,
0.022279424592852592,
0.016630355268716812,
-0.004605873022228479,
0.013455793261528015,
0.0027809608727693558,
0.03246026486158371,
-0.0029269494116306305,
0.05075965076684952,
0.018324056640267372,
0.023680346086621284,
-0.0053906808607280254,
-0.022285519167780876,
-0.012254977598786354,
-0.014109245501458645,
0.02178044244647026,
0.006171185523271561,
-0.007141490932554007,
0.000756232300773263,
0.00510527566075325,
-0.009651534259319305,
-0.012729775160551071,
0.04976452887058258,
0.014936694875359535,
-0.06682997196912766,
0.000003939102953154361,
0.024047385901212692,
0.03597534820437431,
-0.0014085160801187158,
-0.010876894928514957,
-0.03185298666357994,
-0.012168247252702713,
-0.0015411971835419536,
0.022523723542690277,
-0.008656010031700134,
-0.027175480499863625,
-0.03814122825860977,
0.028760945424437523,
-0.019931212067604065,
-0.01996864564716816,
0.0021059196442365646,
0.013800350949168205,
0.02495702914893627,
0.011651746928691864,
-0.024116871878504753,
-0.022283615544438362,
0.021946702152490616,
-0.02404581941664219,
0.0703091248869896,
0.0312625989317894,
0.013529753312468529,
-0.011303167790174484,
-0.024493969976902008,
-0.0348966047167778,
0.014407310634851456,
0.023087285459041595,
-0.03996242210268974,
-0.014881917275488377,
0.012329340912401676,
-0.007709650322794914,
0.03309943154454231,
0.0008657770231366158,
-0.024271471425890923,
-0.0032976383809000254,
0.018965579569339752,
0.006846127565950155,
0.029248937964439392,
0.012741097249090672,
0.006003867369145155,
-0.036872655153274536,
-0.06776703894138336,
0.010272406972944736,
0.003252856433391571,
-0.013300750404596329,
0.00509023480117321,
-0.018748633563518524,
-0.035058800131082535,
-0.024800900369882584,
0.01454837154597044,
-0.01357071753591299,
-0.018226567655801773,
0.007615085691213608,
-0.001692003570497036,
-0.004333511460572481,
0.04806361719965935,
0.037424832582473755,
-0.00849162694066763,
-0.008972836658358574,
-0.00207285163924098,
0.0152870649471879,
-0.018487781286239624,
0.005360561888664961,
0.057198621332645416,
0.035913966596126556,
-0.0007949595456011593,
-0.0023018340580165386,
-0.014280889183282852,
-0.018176015466451645,
-0.036223165690898895,
-0.01845654658973217,
0.00028549745911732316,
-0.035077162086963654,
-0.016401680186390877,
0.007070682477205992,
-0.022730369120836258,
-0.0033217461314052343
] |
8a3315016cdca312326db456e1d5eabcd1f0d049 | 14,798 | py | Python | examples/machine_reading_comprehension/DuReader-robust/run_du.py | wzzju/PaddleNLP | 1757a4fc2a3cd5a45f75c6482746777752b414d8 | [
"Apache-2.0"
] | 3 | 2021-09-06T11:27:49.000Z | 2021-11-09T08:19:00.000Z | examples/machine_reading_comprehension/DuReader-robust/run_du.py | svs1984/PaddleNLP | 9eb9e23b01d044706c789158ac6cf0d365aea848 | [
"Apache-2.0"
] | null | null | null | examples/machine_reading_comprehension/DuReader-robust/run_du.py | svs1984/PaddleNLP | 9eb9e23b01d044706c789158ac6cf0d365aea848 | [
"Apache-2.0"
] | 4 | 2021-08-23T07:46:06.000Z | 2021-09-23T08:37:03.000Z | # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 The HuggingFace Inc. team.
#
# 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 os
import random
import time
import json
import math
from functools import partial
import numpy as np
import paddle
from paddle.io import DataLoader
from args import parse_args
import paddlenlp as ppnlp
from paddlenlp.data import Pad, Stack, Tuple, Dict
from paddlenlp.transformers import BertForQuestionAnswering, BertTokenizer
from paddlenlp.transformers import ErnieForQuestionAnswering, ErnieTokenizer
from paddlenlp.transformers import ErnieGramForQuestionAnswering, ErnieGramTokenizer
from paddlenlp.transformers import RobertaForQuestionAnswering, RobertaTokenizer
from paddlenlp.transformers import LinearDecayWithWarmup
from paddlenlp.metrics.squad import squad_evaluate, compute_prediction
from paddlenlp.datasets import load_dataset
MODEL_CLASSES = {
"bert": (BertForQuestionAnswering, BertTokenizer),
"ernie": (ErnieForQuestionAnswering, ErnieTokenizer),
"ernie_gram": (ErnieGramForQuestionAnswering, ErnieGramTokenizer),
"roberta": (RobertaForQuestionAnswering, RobertaTokenizer)
}
def set_seed(args):
random.seed(args.seed)
np.random.seed(args.seed)
paddle.seed(args.seed)
@paddle.no_grad()
def evaluate(model, data_loader, args):
model.eval()
all_start_logits = []
all_end_logits = []
tic_eval = time.time()
for batch in data_loader:
input_ids, token_type_ids = batch
start_logits_tensor, end_logits_tensor = model(input_ids,
token_type_ids)
for idx in range(start_logits_tensor.shape[0]):
if len(all_start_logits) % 1000 == 0 and len(all_start_logits):
print("Processing example: %d" % len(all_start_logits))
print('time per 1000:', time.time() - tic_eval)
tic_eval = time.time()
all_start_logits.append(start_logits_tensor.numpy()[idx])
all_end_logits.append(end_logits_tensor.numpy()[idx])
all_predictions, _, _ = compute_prediction(
data_loader.dataset.data, data_loader.dataset.new_data,
(all_start_logits, all_end_logits), False, args.n_best_size,
args.max_answer_length)
# Can also write all_nbest_json and scores_diff_json files if needed
with open('prediction.json', "w", encoding='utf-8') as writer:
writer.write(
json.dumps(
all_predictions, ensure_ascii=False, indent=4) + "\n")
squad_evaluate(
examples=data_loader.dataset.data,
preds=all_predictions,
is_whitespace_splited=False)
model.train()
class CrossEntropyLossForSQuAD(paddle.nn.Layer):
def __init__(self):
super(CrossEntropyLossForSQuAD, self).__init__()
def forward(self, y, label):
start_logits, end_logits = y
start_position, end_position = label
start_position = paddle.unsqueeze(start_position, axis=-1)
end_position = paddle.unsqueeze(end_position, axis=-1)
start_loss = paddle.nn.functional.cross_entropy(
input=start_logits, label=start_position)
end_loss = paddle.nn.functional.cross_entropy(
input=end_logits, label=end_position)
loss = (start_loss + end_loss) / 2
return loss
def run(args):
paddle.set_device(args.device)
if paddle.distributed.get_world_size() > 1:
paddle.distributed.init_parallel_env()
rank = paddle.distributed.get_rank()
task_name = args.task_name.lower()
args.model_type = args.model_type.lower()
model_class, tokenizer_class = MODEL_CLASSES[args.model_type]
tokenizer = tokenizer_class.from_pretrained(args.model_name_or_path)
set_seed(args)
if rank == 0:
if os.path.exists(args.model_name_or_path):
print("init checkpoint from %s" % args.model_name_or_path)
model = model_class.from_pretrained(args.model_name_or_path)
if paddle.distributed.get_world_size() > 1:
model = paddle.DataParallel(model)
def prepare_train_features(examples):
# Tokenize our examples with truncation and maybe padding, but keep the overflows using a stride. This results
# in one example possible giving several features when a context is long, each of those features having a
# context that overlaps a bit the context of the previous feature.
# NOTE: Almost the same functionality as HuggingFace's prepare_train_features function. The main difference is
# that HugggingFace uses ArrowTable as basic data structure, while we use list of dictionary instead.
contexts = [examples[i]['context'] for i in range(len(examples))]
questions = [examples[i]['question'] for i in range(len(examples))]
tokenized_examples = tokenizer(
questions,
contexts,
stride=args.doc_stride,
max_seq_len=args.max_seq_length)
# Let's label those examples!
for i, tokenized_example in enumerate(tokenized_examples):
# We will label impossible answers with the index of the CLS token.
input_ids = tokenized_example["input_ids"]
cls_index = input_ids.index(tokenizer.cls_token_id)
# The offset mappings will give us a map from token to character position in the original context. This will
# help us compute the start_positions and end_positions.
offsets = tokenized_example['offset_mapping']
# Grab the sequence corresponding to that example (to know what is the context and what is the question).
sequence_ids = tokenized_example['token_type_ids']
# One example can give several spans, this is the index of the example containing this span of text.
sample_index = tokenized_example['overflow_to_sample']
answers = examples[sample_index]['answers']
answer_starts = examples[sample_index]['answer_starts']
# Start/end character index of the answer in the text.
start_char = answer_starts[0]
end_char = start_char + len(answers[0])
# Start token index of the current span in the text.
token_start_index = 0
while sequence_ids[token_start_index] != 1:
token_start_index += 1
# End token index of the current span in the text.
token_end_index = len(input_ids) - 1
while sequence_ids[token_end_index] != 1:
token_end_index -= 1
# Minus one more to reach actual text
token_end_index -= 1
# Detect if the answer is out of the span (in which case this feature is labeled with the CLS index).
if not (offsets[token_start_index][0] <= start_char and
offsets[token_end_index][1] >= end_char):
tokenized_examples[i]["start_positions"] = cls_index
tokenized_examples[i]["end_positions"] = cls_index
else:
# Otherwise move the token_start_index and token_end_index to the two ends of the answer.
# Note: we could go after the last offset if the answer is the last word (edge case).
while token_start_index < len(offsets) and offsets[
token_start_index][0] <= start_char:
token_start_index += 1
tokenized_examples[i]["start_positions"] = token_start_index - 1
while offsets[token_end_index][1] >= end_char:
token_end_index -= 1
tokenized_examples[i]["end_positions"] = token_end_index + 1
return tokenized_examples
if args.do_train:
if args.train_file:
train_ds = load_dataset(task_name, data_files=args.train_file)
else:
train_ds = load_dataset(task_name, splits='train')
train_ds.map(prepare_train_features, batched=True)
train_batch_sampler = paddle.io.DistributedBatchSampler(
train_ds, batch_size=args.batch_size, shuffle=True)
train_batchify_fn = lambda samples, fn=Dict({
"input_ids": Pad(axis=0, pad_val=tokenizer.pad_token_id),
"token_type_ids": Pad(axis=0, pad_val=tokenizer.pad_token_type_id),
"start_positions": Stack(dtype="int64"),
"end_positions": Stack(dtype="int64")
}): fn(samples)
train_data_loader = DataLoader(
dataset=train_ds,
batch_sampler=train_batch_sampler,
collate_fn=train_batchify_fn,
return_list=True)
num_training_steps = args.max_steps if args.max_steps > 0 else len(
train_data_loader) * args.num_train_epochs
num_train_epochs = math.ceil(num_training_steps /
len(train_data_loader))
lr_scheduler = LinearDecayWithWarmup(
args.learning_rate, num_training_steps, args.warmup_proportion)
# Generate parameter names needed to perform weight decay.
# All bias and LayerNorm parameters are excluded.
decay_params = [
p.name for n, p in model.named_parameters()
if not any(nd in n for nd in ["bias", "norm"])
]
optimizer = paddle.optimizer.AdamW(
learning_rate=lr_scheduler,
epsilon=args.adam_epsilon,
parameters=model.parameters(),
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_params)
criterion = CrossEntropyLossForSQuAD()
global_step = 0
tic_train = time.time()
for epoch in range(num_train_epochs):
for step, batch in enumerate(train_data_loader):
global_step += 1
input_ids, token_type_ids, start_positions, end_positions = batch
logits = model(
input_ids=input_ids, token_type_ids=token_type_ids)
loss = criterion(logits, (start_positions, end_positions))
if global_step % args.logging_steps == 0:
print(
"global step %d, epoch: %d, batch: %d, loss: %f, speed: %.2f step/s"
% (global_step, epoch + 1, step + 1, loss,
args.logging_steps / (time.time() - tic_train)))
tic_train = time.time()
loss.backward()
optimizer.step()
lr_scheduler.step()
optimizer.clear_grad()
if global_step % args.save_steps == 0 or global_step == num_training_steps:
if rank == 0:
output_dir = os.path.join(args.output_dir,
"model_%d" % global_step)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# need better way to get inner model of DataParallel
model_to_save = model._layers if isinstance(
model, paddle.DataParallel) else model
model_to_save.save_pretrained(output_dir)
tokenizer.save_pretrained(output_dir)
print('Saving checkpoint to:', output_dir)
if global_step == num_training_steps:
break
def prepare_validation_features(examples):
# Tokenize our examples with truncation and maybe padding, but keep the overflows using a stride. This results
# in one example possible giving several features when a context is long, each of those features having a
# context that overlaps a bit the context of the previous feature.
# NOTE: Almost the same functionality as HuggingFace's prepare_train_features function. The main difference is
# that HugggingFace uses ArrowTable as basic data structure, while we use list of dictionary instead.
contexts = [examples[i]['context'] for i in range(len(examples))]
questions = [examples[i]['question'] for i in range(len(examples))]
tokenized_examples = tokenizer(
questions,
contexts,
stride=args.doc_stride,
max_seq_len=args.max_seq_length)
# For validation, there is no need to compute start and end positions
for i, tokenized_example in enumerate(tokenized_examples):
# Grab the sequence corresponding to that example (to know what is the context and what is the question).
sequence_ids = tokenized_example['token_type_ids']
# One example can give several spans, this is the index of the example containing this span of text.
sample_index = tokenized_example['overflow_to_sample']
tokenized_examples[i]["example_id"] = examples[sample_index]['id']
# Set to None the offset_mapping that are not part of the context so it's easy to determine if a token
# position is part of the context or not.
tokenized_examples[i]["offset_mapping"] = [
(o if sequence_ids[k] == 1 else None)
for k, o in enumerate(tokenized_example["offset_mapping"])
]
return tokenized_examples
if args.do_predict and rank == 0:
if args.predict_file:
dev_ds = load_dataset(task_name, data_files=args.predict_file)
else:
dev_ds = load_dataset(task_name, splits='dev')
dev_ds.map(prepare_validation_features, batched=True)
dev_batch_sampler = paddle.io.BatchSampler(
dev_ds, batch_size=args.batch_size, shuffle=False)
dev_batchify_fn = lambda samples, fn=Dict({
"input_ids": Pad(axis=0, pad_val=tokenizer.pad_token_id),
"token_type_ids": Pad(axis=0, pad_val=tokenizer.pad_token_type_id)
}): fn(samples)
dev_data_loader = DataLoader(
dataset=dev_ds,
batch_sampler=dev_batch_sampler,
collate_fn=dev_batchify_fn,
return_list=True)
evaluate(model, dev_data_loader, args)
if __name__ == "__main__":
args = parse_args()
run(args)
| 43.651917 | 120 | 0.648331 | 0 | 0 | [
-0.03822460025548935,
0.02025292068719864,
0.03394338861107826,
0.0252982284873724,
-0.01569686084985733,
0.007806390058249235,
0.03134125843644142,
-0.014753464609384537,
0.0032185858581215143,
0.02255501225590706,
-0.0001201755294459872,
-0.01190030574798584,
0.038932863622903824,
0.028328459709882736,
-0.023385873064398766,
-0.003038192167878151,
0.05815419182181358,
-0.035511597990989685,
0.0015280169900506735,
-0.005030583590269089,
0.018624404445290565,
0.007991394959390163,
-0.010054775513708591,
0.00403177784755826,
0.028319014236330986,
-0.027428491041064262,
0.06858566403388977,
0.018942968919873238,
0.0270988866686821,
-0.018386462703347206,
0.007227581925690174,
-0.039386775344610214,
-0.008588677272200584,
0.019834239035844803,
-0.021519897505640984,
-0.019869545474648476,
0.02374393865466118,
-0.024842984974384308,
0.015168015845119953,
0.016669178381562233,
-0.03909321501851082,
-0.03873434662818909,
-0.026376068592071533,
0.01500618550926447,
0.02261689305305481,
0.008079851046204567,
-0.018924172967672348,
0.03415527567267418,
-0.0597539022564888,
0.010598707012832165,
0.010105776600539684,
0.01772766374051571,
0.0005836007185280323,
-0.04511246830224991,
0.027732111513614655,
-0.022053884342312813,
0.00874192826449871,
0.03413014113903046,
-0.03334460407495499,
0.01589057222008705,
0.00011460268433438614,
-0.012811992317438126,
0.001242447760887444,
-0.030452223494648933,
0.06589286774396896,
-0.005101032555103302,
-0.0003132607089355588,
0.011049383319914341,
-0.036422472447156906,
-0.023656228557229042,
-0.024291859939694405,
0.004449940752238035,
0.006072464864701033,
0.03507360816001892,
0.026834188029170036,
0.00827303808182478,
-0.03223542869091034,
-0.01993025839328766,
-0.0023819480556994677,
0.004219961818307638,
0.00554942199960351,
0.08824525773525238,
0.013557149097323418,
-0.011197544634342194,
0.010700616054236889,
0.03383937105536461,
0.05467236042022705,
-0.0663510113954544,
0.03514601290225983,
0.012639306485652924,
-0.030906619504094124,
0.038109589368104935,
-0.04589630663394928,
-0.006024947389960289,
-0.025218987837433815,
-0.05269637331366539,
0.032444074749946594,
0.0042815906926989555,
0.001005590776912868,
0.0016833118861541152,
0.027822501957416534,
-0.017154989764094353,
0.043538231402635574,
-0.010522383265197277,
0.0009203897207044065,
0.004375683609396219,
-0.05612228810787201,
-0.0029253100510686636,
-0.005891729146242142,
-0.025748800486326218,
-0.027114102616906166,
-0.017999382689595222,
0.0303957499563694,
0.0026534805074334145,
-0.0029388738330453634,
-0.0026293813716620207,
-0.00635599484667182,
-0.006270115729421377,
0.01594051532447338,
-0.010730776935815811,
-0.03132718801498413,
-0.006000195629894733,
0.026875274255871773,
-0.01315535418689251,
-0.004663958679884672,
0.06866790354251862,
0.007653674576431513,
0.04271508380770683,
0.049299806356430054,
-0.005971871316432953,
-0.0038512046448886395,
0.0388377383351326,
0.01955576241016388,
-0.03748411685228348,
0.0035420290660113096,
-0.013850790448486805,
0.010847439058125019,
0.0213372390717268,
-0.031854137778282166,
-0.0038592168129980564,
-0.014696468599140644,
-0.018087290227413177,
-0.004692296031862497,
-0.008221644908189774,
-0.024949155747890472,
-0.047256309539079666,
-0.018790293484926224,
-0.012688569724559784,
-0.009226790629327297,
0.028612861409783363,
0.002441211137920618,
-0.0128098139539361,
-0.016037072986364365,
0.008940900675952435,
-0.03035030886530876,
-0.027175625786185265,
-0.011588123627007008,
-0.07229603826999664,
-0.018289165571331978,
-0.031831055879592896,
-0.03249875456094742,
-0.013829866424202919,
0.007317603100091219,
0.007973897270858288,
-0.00019160498050041497,
0.06075294688344002,
-0.03914259746670723,
0.004586994182318449,
-0.03417889028787613,
0.001240511890500784,
-0.0015420729760080576,
0.005508417263627052,
0.008312014862895012,
-0.02394442819058895,
-0.05856342986226082,
-0.02110346220433712,
-0.0035109673626720905,
0.016532476991415024,
-0.009692979976534843,
-0.004354486241936684,
0.040886856615543365,
-0.0007461771601811051,
0.031336020678281784,
0.013199899345636368,
-0.0050248210318386555,
-0.016809621825814247,
-0.01713523641228676,
-0.011957639828324318,
0.012764444574713707,
0.003644560696557164,
-0.01878977194428444,
0.02365592122077942,
0.009632348082959652,
-0.03904595598578453,
0.027719618752598763,
0.024216381832957268,
0.013157310895621777,
0.008364626206457615,
0.0029762438498437405,
0.0009533057454973459,
0.028416676446795464,
-0.015645241364836693,
0.022229710593819618,
0.0275154709815979,
-0.002203735988587141,
0.01660090684890747,
-0.7090747356414795,
0.06756516546010971,
0.049971047788858414,
-0.018311381340026855,
0.008528532460331917,
0.027480224147439003,
-0.020035389810800552,
0.029080891981720924,
-0.035368919372558594,
0.021672341972589493,
0.010728306137025356,
-0.0035519308876246214,
-0.034615181386470795,
0.021557535976171494,
-0.019373413175344467,
-0.010999473743140697,
0.016104670241475105,
-0.010850297287106514,
-0.01776224747300148,
0.00790674239397049,
0.0008901019464246929,
-0.019672365859150887,
-0.020993022248148918,
0.002058302750810981,
0.007202781271189451,
-0.020701387897133827,
0.0010015735169872642,
-0.013150538317859173,
0.019671982154250145,
-0.006618109531700611,
0.0022959308698773384,
0.0019007851369678974,
0.02870645932853222,
-0.022822421044111252,
-0.016340473666787148,
0.020561357960104942,
-0.030186951160430908,
-0.018233664333820343,
-0.016817107796669006,
0.00032865541288629174,
0.03742076829075813,
-0.004533417522907257,
-0.06314051896333694,
-0.040171168744564056,
-0.02263593301177025,
-0.03532462567090988,
-0.07364822179079056,
-0.03503210097551346,
-0.0016720349667593837,
-0.017695846036076546,
-0.04119007661938667,
0.023310916498303413,
0.027781469747424126,
-0.009225592948496342,
-0.03270355612039566,
0.03212086111307144,
-0.034226637333631516,
-0.01638856902718544,
0.02369164302945137,
-0.015944333747029305,
0.0241971705108881,
0.025049665942788124,
-0.019892413169145584,
0.022092603147029877,
-0.01955811306834221,
0.012848137877881527,
0.08270781487226486,
-0.04834870249032974,
-0.023413076996803284,
0.04676637426018715,
-0.056262675672769547,
0.007120001129806042,
-0.008222490549087524,
0.07466582208871841,
0.021681468933820724,
-0.0012792303459718823,
-0.02195132151246071,
0.005511168856173754,
-0.033311255276203156,
-0.03183280676603317,
-0.019590266048908234,
-0.07043622434139252,
-0.018439915031194687,
0.02339857630431652,
-0.010638178326189518,
0.016661008819937706,
-0.010657091625034809,
-0.009213018231093884,
-0.0015852266224101186,
0.010825681500136852,
0.008804400451481342,
0.02279762551188469,
0.017664287239313126,
0.004600086249411106,
0.006103456486016512,
0.02357381395995617,
0.016346300020813942,
0.05282693728804588,
0.006188482046127319,
0.027504252269864082,
-0.018709251657128334,
0.023235291242599487,
0.013088453561067581,
0.027587633579969406,
0.009613809175789356,
-0.007141051348298788,
-0.031994860619306564,
0.0052619981579482555,
0.034548189491033554,
-0.035049423575401306,
-0.008905882015824318,
0.0025441113393753767,
-0.011670681647956371,
-0.008987823501229286,
0.010478813201189041,
-0.006654750090092421,
-0.006279196590185165,
-0.034486137330532074,
0.0469532385468483,
-0.005543248727917671,
-0.04730989784002304,
0.02489333227276802,
0.030002756044268608,
0.013590858317911625,
-0.00919260736554861,
0.037030454725027084,
0.0022403199691325426,
0.0012738985242322087,
-0.0018424775917083025,
-0.007110644597560167,
-0.008968198671936989,
-0.024325011298060417,
-0.005462257657200098,
0.002263791859149933,
-0.005140210967510939,
-0.01823643408715725,
-0.0054912809282541275,
-0.035743530839681625,
-0.025172224268317223,
0.011318515986204147,
-0.026089662685990334,
-0.022148285061120987,
-0.009826290421187878,
-0.029411867260932922,
0.025909246876835823,
0.015701720491051674,
-0.002367840614169836,
0.017393335700035095,
-0.015167978592216969,
-0.024194618687033653,
-0.017598362639546394,
0.019674625247716904,
0.01908707618713379,
-0.01993712969124317,
-0.034181635826826096,
0.03570112958550453,
0.0046517858281731606,
-0.01812688447535038,
0.05924975126981735,
-0.008042905479669571,
-0.006848475895822048,
-0.00939373392611742,
0.015129255130887032,
0.05821973830461502,
-0.016428813338279724,
-0.007337179500609636,
0.016523543745279312,
0.00985706876963377,
-0.00485171377658844,
0.0035071708261966705,
0.005855218507349491,
-0.02508785016834736,
0.03576632961630821,
-0.001175160170532763,
-0.01362167950719595,
-0.008130911737680435,
-0.02785210683941841,
-0.06588499248027802,
0.023004848510026932,
-0.0446222722530365,
0.0037110394332557917,
0.011157117784023285,
-0.025397615507245064,
0.036140866577625275,
0.004771650768816471,
0.04570780694484711,
0.03450099378824234,
0.027283333241939545,
0.021294189617037773,
0.009230074472725391,
0.029198817908763885,
0.012572243809700012,
-0.015569203533232212,
0.012740494683384895,
0.006244420073926449,
-0.023938914760947227,
-0.021776912733912468,
-0.007247554138302803,
-0.02374085783958435,
-0.04792032763361931,
0.00056890316773206,
0.003330481704324484,
-0.01608673855662346,
-0.02541522867977619,
0.008128237910568714,
0.020073875784873962,
0.007986302487552166,
0.0015692978631705046,
0.007522360887378454,
-0.010804875753819942,
0.005313283763825893,
-0.018177228048443794,
-0.011199582368135452,
0.03208921477198601,
-0.0070943026803433895,
0.018104486167430878,
-0.040950335562229156,
-0.014078212901949883,
0.05374881997704506,
-0.024574924260377884,
-0.03907166048884392,
-0.03947851434350014,
0.007376780267804861,
-0.014200248755514622,
0.018110495060682297,
-0.039850424975156784,
-0.023045290261507034,
0.032073430716991425,
0.0062080142088234425,
-0.011802312918007374,
0.021972840651869774,
0.008577211759984493,
0.01108075026422739,
-0.008441979065537453,
-0.005685998592525721,
0.007904625497758389,
-0.03572671115398407,
-0.027428599074482918,
-0.011921423487365246,
-0.06064876541495323,
0.03603452071547508,
-0.014934569597244263,
0.0192841999232769,
0.002275218954309821,
-0.01191497128456831,
0.012867458164691925,
0.001688272226601839,
-0.0066199335269629955,
-0.04047861695289612,
-0.0219831895083189,
-0.021709328517317772,
0.051340408623218536,
0.02629958651959896,
-0.006217029877007008,
0.027467800304293633,
0.03160000964999199,
-0.019864773377776146,
0.018714526668190956,
0.028014283627271652,
0.025289855897426605,
-0.008592251688241959,
-0.042131006717681885,
0.03503672778606415,
0.014610880054533482,
-0.018293753266334534,
-0.0025265738368034363,
0.004833931103348732,
0.006311951205134392,
-0.00046709825983271003,
0.040717996656894684,
-0.03307599946856499,
-0.015954116359353065,
-0.05358614772558212,
0.005386232398450375,
-0.0032456377521157265,
-0.005176207050681114,
-0.007034594658762217,
-0.05194845423102379,
0.025546634569764137,
0.017970114946365356,
-0.011951317079365253,
0.028868526220321655,
0.002952729118987918,
0.025788450613617897,
-0.00002055853656202089,
0.0020666394848376513,
0.004623481538146734,
-0.0027056161779910326,
-0.017264369875192642,
0.004473906941711903,
-0.01760028302669525,
-0.027024241164326668,
0.0010800703894346952,
0.01439175009727478,
-0.03672027587890625,
0.02265925519168377,
-0.0016687631141394377,
-0.000785892189014703,
0.020274315029382706,
0.011772530153393745,
0.020666085183620453,
-0.02565888874232769,
0.003524328116327524,
-0.02814473770558834,
0.0010682943975552917,
-0.012763621285557747,
0.028347833082079887,
-0.019215133041143417,
0.040132541209459305,
-0.006383263971656561,
-0.020417073741555214,
0.02373688295483589,
0.006573481019586325,
-0.013305344618856907,
0.0023710918612778187,
0.005302533973008394,
0.0358474925160408,
0.03432539850473404,
-0.010791461914777756,
0.010957912541925907,
-0.008117572404444218,
-0.0008601745939813554,
-0.026606500148773193,
-0.02701251581311226,
0.01084328442811966,
0.014165181666612625,
-0.004202497191727161,
0.0115425456315279,
-0.0464215949177742,
-0.02380218915641308,
-0.03152870759367943,
0.008323561400175095,
0.025814970955252647,
0.012940570712089539,
-0.002794926753267646,
0.025578971952199936,
0.020988063886761665,
0.05791298672556877,
-0.0024977177381515503,
0.00042747240513563156,
0.03688279166817665,
0.030183101072907448,
-0.04933588579297066,
0.03653484582901001,
0.031236443668603897,
0.004812255967408419,
0.04759836196899414,
0.03333280608057976,
0.018933752551674843,
0.0034608810674399137,
0.018397416919469833,
-0.023970063775777817,
-0.002661819802597165,
0.005384724121540785,
0.00032947989529930055,
-0.005105325020849705,
-0.03076672926545143,
-0.008417378179728985,
0.015363316051661968,
-0.017486151307821274,
-0.0007601057877764106,
0.004086151719093323,
-0.003566131694242358,
-0.03100143000483513,
0.00891563668847084,
-0.008153245784342289,
0.032862190157175064,
-0.017022915184497833,
-0.008591949939727783,
0.03135572373867035,
-0.010357823222875595,
-0.04536103084683418,
0.023814866319298744,
-0.013424402102828026,
-0.01322524156421423,
0.049267806112766266,
0.10623784363269806,
0.015376784838736057,
-0.020831452682614326,
-0.02652667835354805,
-0.02154506742954254,
-0.04960671812295914,
0.027621323242783546,
-0.029075657948851585,
0.014116667211055756,
-0.04772261157631874,
-0.0036688591353595257,
0.005636051297187805,
-0.012343044392764568,
-0.01672801747918129,
-0.03755369037389755,
-0.02948157675564289,
0.0068788365460932255,
0.023846598342061043,
-0.009888962842524052,
-0.001513159484602511,
-0.04362020641565323,
0.0067117526195943356,
0.008319695480167866,
0.019848806783556938,
0.004582250490784645,
-0.04156568646430969,
0.03141302987933159,
-0.04556236416101456,
-0.023561235517263412,
0.013756416738033295,
-0.00645753787830472,
0.003987849224358797,
0.0056480965577065945,
0.02478502318263054,
0.017183497548103333,
0.018167538568377495,
0.004926955793052912,
-0.006495872046798468,
-0.018811965361237526,
0.008856822736561298,
-0.04064992442727089,
-0.02335496060550213,
-0.017978981137275696,
0.019980616867542267,
-0.03806578367948532,
-0.010762704536318779,
-0.015516119077801704,
0.019140874966979027,
-0.015049532055854797,
-0.0009104622295126319,
0.05445348098874092,
-0.006251122802495956,
0.006624416448175907,
0.03180955722928047,
0.0258462093770504,
-0.025409644469618797,
-0.01796746626496315,
0.01574612222611904,
0.028242692351341248,
0.008501262404024601,
0.011817006394267082,
0.0006826773751527071,
-0.008009430021047592,
0.023238442838191986,
-0.021710382774472237,
0.013744032010436058,
0.03394901379942894,
0.018854578956961632,
-0.04485514760017395,
-0.018976949155330658,
0.04967189580202103,
0.019018538296222687,
-0.0009444202296435833,
-0.006074399687349796,
-0.02106134407222271,
0.03163665533065796,
-0.0002386801061220467,
-0.013149213045835495,
-0.007454158738255501,
-0.004011805634945631,
0.034526389092206955,
0.03589414060115814,
0.025093592703342438,
0.012543217279016972,
0.0010930434800684452,
0.017107265070080757,
-0.0015274380566552281,
0.03407365828752518,
0.023091383278369904,
0.0009389957413077354,
0.018050184473395348,
-0.023873528465628624,
-0.014984870329499245,
-0.027048245072364807,
0.049663983285427094,
0.015487590804696083,
-0.0030908132903277874,
0.0014832521555945277,
0.007235947996377945,
-0.014920994639396667,
-0.00788735132664442,
0.015765853226184845,
0.018122944980859756,
0.012296641245484352,
-0.019137274473905563,
0.011591716669499874,
0.007168267387896776,
-0.004998950287699699,
0.02646166831254959,
0.009031705558300018,
-0.008809118531644344,
0.024951793253421783,
0.002762874122709036,
0.013351939618587494,
0.005229196045547724,
-0.002288524294272065,
-0.031184636056423187,
0.033287692815065384,
0.00848335586488247,
-0.015266363508999348,
0.046776093542575836,
-0.002844264730811119,
0.03704804927110672,
0.0004907699185423553,
-0.031824991106987,
-0.011771037243306637,
-0.0012123897904530168,
-0.005216575227677822,
0.01294814795255661,
0.013359880074858665,
0.07633236050605774,
0.042336851358413696,
-0.012372451834380627,
-0.02736351452767849,
-0.029416143894195557,
-0.0064944010227918625,
-0.02284233085811138,
-0.010637953877449036,
0.006924622692167759,
0.02667599730193615,
0.023768151178956032,
-0.07723996043205261,
0.020530641078948975,
0.0050558410584926605,
0.03448900580406189,
0.02676003985106945,
0.00433397525921464,
-0.0344398096203804,
-0.0009896393166854978,
-0.033577702939510345,
-0.049516912549734116,
-0.03355736285448074,
0.0012365005677565932,
0.0194277111440897,
-0.03473441302776337,
0.01637522503733635,
-0.03987643122673035,
-0.010720651596784592,
-0.012866862118244171,
-0.042974114418029785,
0.03011053241789341,
0.020620061084628105,
-0.0330127477645874,
0.0026713437400758266,
0.030080512166023254,
-0.018303370103240013,
-0.004782409872859716,
0.00010780002776300535,
-0.012877817265689373,
0.002599380910396576,
-0.02261773683130741,
-0.04554547742009163,
0.026515193283557892,
0.03966771811246872,
-0.017900370061397552,
0.007130508776754141,
0.008318793959915638,
-0.0035633661318570375,
-0.03540833294391632,
-0.036410246044397354,
-0.005809461697936058,
0.0030710736755281687,
-0.0016967979026958346,
-0.023596404120326042,
0.017583275213837624,
-0.00961846299469471
] |
8a3543c746387ad12029585c2e306e26ec984737 | 4,324 | py | Python | Deep_Q_Network/DQN_for_FrozenLake_Discrete_Domain.py | quangnguyendang/Reinforcement_Learning | 2551ce95068561c553500838ee6b976f001ba667 | [
"MIT"
] | null | null | null | Deep_Q_Network/DQN_for_FrozenLake_Discrete_Domain.py | quangnguyendang/Reinforcement_Learning | 2551ce95068561c553500838ee6b976f001ba667 | [
"MIT"
] | null | null | null | Deep_Q_Network/DQN_for_FrozenLake_Discrete_Domain.py | quangnguyendang/Reinforcement_Learning | 2551ce95068561c553500838ee6b976f001ba667 | [
"MIT"
] | null | null | null | # Credit to https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part-0-q-learning-with-tables-and-neural-networks-d195264329d0
import gym
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
env = gym.make('FrozenLake-v0')
# NEURAL NETWORK IMPLEMENTATION
tf.reset_default_graph()
# Feature vector for current state representation
input1 = tf.placeholder(shape=[1, env.observation_space.n], dtype=tf.float32)
# tf.Variable(<initial-value>, name=<optional-name>)
# tf.random_uniform(shape, minval=0, maxval=None, dtype=tf.float32, seed=None, name=None)
# Weighting W vector in range 0 - 0.01 (like the way Andrew Ng did with *0.01
W = tf.Variable(tf.random_uniform([env.observation_space.n, env.action_space.n], 0, 0.01))
# Qout with shape [1, env.action_space.n] - Action state value for Q[s, a] with every a available at a state
Qout = tf.matmul(input1, W)
# Greedy action at a state
predict = tf.argmax(Qout, axis=1)
# Feature vector for next state representation
nextQ = tf.placeholder(shape=[1, env.action_space.n], dtype=tf.float32)
# Entropy loss
loss = tf.reduce_sum(tf.square(Qout - nextQ))
trainer = tf.train.GradientDescentOptimizer(learning_rate=0.1)
updateModel = trainer.minimize(loss)
# TRAIN THE NETWORK
init = tf.global_variables_initializer()
# Set learning parameters
y = 0.99
e = 0.1
number_episodes = 2000
# List to store total rewards and steps per episode
jList = []
rList = []
with tf.Session() as sess:
sess.run(init)
for i in range(number_episodes):
print("Episode #{} is running!".format(i))
# First state
s = env.reset()
rAll = 0
d = False
j = 0
# Q network
while j < 200: # or While not d:
j += 1
# Choose action by epsilon (e) greedy
# print("s = ", s," --> Identity s:s+1: ", np.identity(env.observation_space.n)[s:s+1])
# s = 0 --> Identity s: s + 1: [[1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
# s = 1 --> Identity s: s + 1: [[0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
# Identity [s:s+1] is a one-hot vector
# Therefore W is the actual Q value
a, allQ = sess.run([predict, Qout], feed_dict={input1: np.identity(env.observation_space.n)[s:s+1]})
if np.random.rand(1) < e:
a[0] = env.action_space.sample()
s1, r, d, _ = env.step(a[0])
# Obtain next state Q value by feeding the new state throughout the network
Q1 = sess.run(Qout, feed_dict={input1: np.identity(env.observation_space.n)[s1:s1+1]})
maxQ1 = np.max(Q1)
targetQ = allQ
targetQ[0, a[0]] = r + y * maxQ1
# Train our network using target and predicted Q values
_, W1 = sess.run([updateModel, W], feed_dict={input1: np.identity(env.observation_space.n)[s:s+1], nextQ: targetQ})
rAll += r
s = s1
if d:
e = 1./((i/50) + 10)
break
jList.append(j)
rList.append(rAll)
env.close()
plt.figure()
plt.plot(rList, label="Return - Q Learning")
plt.show()
plt.figure()
plt.plot(jList, label="Steps - Q Learning")
plt.show()
# -------------------------------------------------------------------------
# TABULAR IMPLEMENTATION
#
# # Set learning parameters
# lr = 0.8
# y = 0.95
# number_episodes = 20000
#
# # Initial table with all zeros
# Q = np.zeros([env.observation_space.n, env.action_space.n])
#
# # List of reward and steps per episode
# rList = []
# for i in range (number_episodes):
# print("Episode #{} is running!".format(i))
# s = env.reset()
# rAll = 0
# d = False
# j = 0
# while j < 99:
# j += 1
# # Choose an action by greedily (with noise) picking from Q table
# # Because of the noise, it is epsilon-greedy with epsilon decreasing over time
# a = np.argmax(Q[s, :] + np.random.rand(1, env.action_space.n)*(1./(i + 1)))
# s1, r, d, _ = env.step(a)
# # env.render()
#
# # Update Q table with new knowledge
# Q[s, a] = Q[s, a] + lr * (r + y * np.max(Q[s1, :]) - Q[s, a])
# rAll += r
# s = s1
# if d:
# break
# rList.append(rAll)
| 30.666667 | 155 | 0.586725 | 0 | 0 | [
-0.00900201965123415,
0.03866386041045189,
0.019795674830675125,
0.04108386114239693,
0.033451396971940994,
0.01972990855574608,
0.015908721834421158,
0.03469279035925865,
0.004460745491087437,
0.005827091634273529,
-0.006859639193862677,
-0.010790068656206131,
-0.0053227744065225124,
-0.01815071515738964,
0.011274577118456364,
0.042322561144828796,
0.015324153006076813,
-0.04148556664586067,
-0.025823691859841347,
0.03878237307071686,
-0.008202914148569107,
-0.02253066562116146,
-0.08185893297195435,
0.00700484961271286,
0.0020428746938705444,
0.01118613313883543,
0.06158732250332832,
0.017111025750637054,
0.016713283956050873,
0.009014857932925224,
-0.035216763615608215,
0.005699029192328453,
-0.00001013251494441647,
-0.000304884510114789,
-0.04061150923371315,
0.009753398597240448,
0.01680135913193226,
-0.06517370045185089,
-0.006003833841532469,
0.025102216750383377,
-0.03617357462644577,
-0.025109611451625824,
0.039562422782182693,
-0.07949118316173553,
0.06719686090946198,
-0.048582594841718674,
0.002942892722785473,
0.0043885363265872,
-0.0705081969499588,
0.0092281149700284,
-0.05696506053209305,
0.05758703500032425,
-0.04703080281615257,
-0.03622535243630409,
0.00883559975773096,
-0.02860168367624283,
-0.0003959016758017242,
0.04739686846733093,
-0.018343502655625343,
-0.052992597222328186,
0.01410114485770464,
0.03714844211935997,
-0.04867056384682655,
0.003733882447704673,
-0.01311584748327732,
0.029808983206748962,
0.003047769423574209,
-0.003297331975772977,
0.04051165655255318,
0.005693902261555195,
-0.0008618555730208755,
0.03199290484189987,
0.04816790297627449,
0.06868002563714981,
0.008352435193955898,
-0.03215429559350014,
-0.043415866792201996,
-0.01805924065411091,
0.04091636463999748,
0.0074196732603013515,
-0.01612001098692417,
0.0969608947634697,
-0.04847200959920883,
0.017752792686223984,
0.0020427610725164413,
-0.030830081552267075,
0.038230881094932556,
-0.027974804863333702,
0.031896982342004776,
0.022753411903977394,
-0.04949633404612541,
-0.003407424548640847,
-0.07336951047182083,
0.013479419983923435,
-0.08552819490432739,
-0.05763817951083183,
0.01139258686453104,
-0.029295580461621284,
0.011562974192202091,
-0.03667038306593895,
-0.025254741311073303,
0.005297474097460508,
0.053901880979537964,
0.004940989892929792,
0.03828581050038338,
-0.018872013315558434,
-0.04686597362160683,
-0.016627652570605278,
0.047300998121500015,
0.005331134889274836,
-0.05126776918768883,
0.009997234679758549,
0.06647922098636627,
-0.027813421562314034,
-0.006511033046990633,
-0.0699051097035408,
-0.024539534002542496,
0.028259992599487305,
-0.015748176723718643,
0.017248621210455894,
-0.040165286511182785,
-0.009309622459113598,
0.03671056404709816,
-0.02713332511484623,
0.006384560372680426,
0.04340587928891182,
-0.07964273542165756,
-0.008882522583007812,
-0.01281154528260231,
-0.009866771288216114,
0.023546289652585983,
-0.028874803334474564,
0.015491782687604427,
-0.009667972102761269,
0.028378797695040703,
0.034772079437971115,
-0.008426012471318245,
-0.03650915250182152,
-0.04261011257767677,
0.007247653789818287,
-0.01711655966937542,
-0.011952978558838367,
0.0011446309508755803,
0.014890936203300953,
0.045147232711315155,
-0.06025846675038338,
-0.0012356718070805073,
0.011598972603678703,
-0.015104668214917183,
0.0032494126353412867,
-0.011326138861477375,
0.04100107029080391,
0.020836416631937027,
-0.001196759520098567,
0.007413231767714024,
-0.0012744955020025373,
-0.06115952879190445,
0.027918972074985504,
0.014114264398813248,
0.02173812873661518,
0.0019429826643317938,
0.039045725017786026,
0.01252469327300787,
-0.03624154254794121,
-0.050115395337343216,
0.0553603395819664,
-0.034574881196022034,
0.024051403626799583,
0.020059026777744293,
-0.011628306470811367,
0.00926596112549305,
0.003725580405443907,
-0.0031049514655023813,
-0.019398855045437813,
-0.059585582464933395,
-0.01515209674835205,
0.013233899138867855,
0.07015927881002426,
0.020127037540078163,
-0.0062211924232542515,
0.025127334520220757,
-0.019560305401682854,
0.04103007912635803,
0.015134982764720917,
0.027021601796150208,
-0.047519803047180176,
0.03649526089429855,
-0.02999497391283512,
-0.01139310747385025,
0.00360175222158432,
-0.0312839150428772,
0.0425453819334507,
0.034318793565034866,
-0.07035720348358154,
0.05451231077313423,
0.005126374773681164,
-0.03941119462251663,
0.0218631774187088,
-0.014645906165242195,
-0.023847900331020355,
-0.016017872840166092,
-0.03835742548108101,
0.011107961647212505,
0.06859450042247772,
-0.005979103501886129,
0.007759668864309788,
-0.4602803587913513,
0.04057825356721878,
0.0063065723516047,
-0.01592828333377838,
-0.017296424135565758,
0.020867493003606796,
0.01937713287770748,
0.012228839099407196,
0.012734564952552319,
-0.035254690796136856,
-0.002981170080602169,
-0.011553171090781689,
-0.009448560886085033,
-0.020246921107172966,
-0.002991363639011979,
-0.023601306602358818,
-0.017913153395056725,
-0.03259306401014328,
-0.006381439045071602,
0.028825217857956886,
0.03537392616271973,
-0.043976761400699615,
0.0020149201154708862,
-0.02166292630136013,
-0.05343597009778023,
0.0035051133017987013,
0.015934329479932785,
0.02360418438911438,
0.0029353229328989983,
-0.02056417427957058,
-0.023553356528282166,
-0.01356430072337389,
0.022696029394865036,
0.014158498495817184,
-0.0329437293112278,
0.03523451089859009,
0.02807733789086342,
-0.011886143125593662,
0.00028919149190187454,
0.02470404841005802,
-0.009545078501105309,
0.004316096194088459,
0.0034876884892582893,
-0.07286365330219269,
-0.033359281718730927,
-0.010922216810286045,
0.053365569561719894,
-0.020270101726055145,
0.011707955971360207,
0.028573160991072655,
-0.04793625324964523,
0.03718568757176399,
0.07094971835613251,
-0.005298882722854614,
-0.04594940319657326,
-0.008590040728449821,
-0.028099175542593002,
-0.059619128704071045,
-0.004413269460201263,
-0.042798034846782684,
0.024232469499111176,
0.0391576811671257,
-0.08963911235332489,
0.0032350036781281233,
-0.03097664564847946,
0.03301657363772392,
0.026792651042342186,
-0.03809162229299545,
-0.04453849419951439,
-0.0044437493197619915,
-0.05945323035120964,
0.015272228047251701,
-0.047522805631160736,
-0.00003484778426354751,
0.020937319844961166,
0.015044568106532097,
-0.0008030046592466533,
0.024827348068356514,
-0.05072741582989693,
-0.012388045899569988,
-0.0032951878383755684,
-0.02102232538163662,
-0.006147720385342836,
0.03398100659251213,
0.007339501287788153,
-0.04462337866425514,
0.001662899856455624,
0.05187208205461502,
-0.021696368232369423,
-0.012666617520153522,
0.011499643325805664,
0.04676054045557976,
0.013005104847252369,
0.04686170443892479,
0.006924293003976345,
0.024343889206647873,
-0.031535904854536057,
0.03826890140771866,
-0.017805319279432297,
-0.01133754663169384,
-0.016474515199661255,
0.008452721871435642,
-0.012329047545790672,
0.02252298966050148,
-0.022365782409906387,
0.00195746636018157,
-0.013573904521763325,
-0.005776136182248592,
-0.002171690110117197,
0.007393321022391319,
0.002654615556821227,
0.007012426387518644,
0.01703599840402603,
0.03095158375799656,
-0.011635009199380875,
0.019599145278334618,
-0.025969073176383972,
-0.061068326234817505,
0.044761739671230316,
-0.019134782254695892,
-0.006725737359374762,
-0.056169286370277405,
0.00550716882571578,
0.009105795994400978,
-0.021800855174660683,
0.012934689410030842,
-0.04855925589799881,
-0.05950486660003662,
0.036623816937208176,
0.015026213601231575,
-0.0026011487934738398,
0.012575462460517883,
0.020180581137537956,
0.005780057981610298,
-0.006617564242333174,
-0.024797586724162102,
-0.020462635904550552,
-0.03138642758131027,
0.0004922926891595125,
0.028421293944120407,
-0.01072725746780634,
-0.057112108916044235,
0.01505966018885374,
-0.003418128238990903,
0.01925758086144924,
0.01683630608022213,
0.020695915445685387,
0.004943054169416428,
-0.04324118793010712,
0.004437415860593319,
-0.019031977280974388,
0.03513925522565842,
0.043296925723552704,
0.0020687193609774113,
-0.008599300868809223,
-0.02063858136534691,
-0.031953081488609314,
0.004237486980855465,
0.04527578875422478,
0.013847840949892998,
0.019545430317521095,
-0.0192470271140337,
-0.004992629401385784,
0.0599825344979763,
-0.0190474484115839,
-0.036286335438489914,
0.030520055443048477,
0.009166681207716465,
0.00628114165738225,
0.03797345235943794,
-0.02781253680586815,
0.015021661296486855,
0.0008332022116519511,
0.003991113975644112,
0.04334571957588196,
0.0234430730342865,
0.0034930137917399406,
-0.02107473462820053,
-0.02038714848458767,
-0.014378204010426998,
0.019511068239808083,
-0.007918943651020527,
-0.02333492413163185,
0.04203089699149132,
0.054320890456438065,
0.040796466171741486,
-0.020968470722436905,
-0.03231203556060791,
-0.018574267625808716,
-0.07043888419866562,
-0.0070650409907102585,
-0.015467111952602863,
-0.027466537430882454,
0.001643763855099678,
-0.02497045323252678,
-0.0438021682202816,
-0.005074112210422754,
-0.013699592091143131,
0.03811641409993172,
-0.04730275645852089,
-0.06111191213130951,
0.029173508286476135,
0.043453723192214966,
-0.01609247736632824,
-0.012880791909992695,
0.0459667444229126,
0.017530271783471107,
0.003245617263019085,
0.031001605093479156,
0.00359656591899693,
0.03680660203099251,
-0.023781629279255867,
-0.03520488739013672,
-0.006506101693958044,
-0.03829042613506317,
0.08618950098752975,
-0.006448964588344097,
0.005037948954850435,
0.008637248538434505,
0.001038720365613699,
-0.023905230686068535,
-0.06948096305131912,
0.03079715557396412,
0.008868185803294182,
0.03554781153798103,
-0.003620203584432602,
-0.0521099753677845,
0.0012994398130103946,
0.008050450123846531,
0.004416660405695438,
0.017426282167434692,
0.02000868320465088,
0.01870656944811344,
-0.023721104487776756,
0.03610834851861,
0.030263125896453857,
0.0008620562730357051,
-0.01775446906685829,
0.018975362181663513,
-0.033083390444517136,
-0.00317016220651567,
-0.017273830249905586,
-0.030827393755316734,
0.05919310823082924,
0.03205249831080437,
0.032218918204307556,
-0.017085982486605644,
-0.021747993305325508,
-0.018558206036686897,
-0.010625968687236309,
0.026815861463546753,
0.017592592164874077,
0.03047771565616131,
0.011300232261419296,
0.019166376441717148,
-0.019190318882465363,
0.026729105040431023,
0.027279451489448547,
0.03293589875102043,
0.027035776525735855,
-0.03508228436112404,
-0.0687904879450798,
0.055115073919296265,
0.03894268348813057,
0.02956654317677021,
0.011450749821960926,
-0.03394455090165138,
-0.024259071797132492,
0.0213710255920887,
0.016257718205451965,
0.0457235723733902,
-0.07204169034957886,
-0.015435625799000263,
0.007021042052656412,
0.0182158462703228,
-0.0009065994527190924,
0.01436442881822586,
-0.03077165223658085,
0.004856308456510305,
0.035942960530519485,
-0.0039529516361653805,
-0.03172390162944794,
-0.026663510128855705,
0.03125873953104019,
-0.01936335116624832,
-0.007457964587956667,
0.008018513210117817,
0.053730763494968414,
-0.041442058980464935,
-0.0344306044280529,
0.03699449449777603,
-0.02221020497381687,
0.06102726608514786,
0.025965426117181778,
-0.022621195763349533,
0.060550227761268616,
0.00014513765927404165,
0.024173587560653687,
0.052373990416526794,
-0.022928716614842415,
-0.01650536060333252,
0.00598236033692956,
-0.005234162323176861,
-0.006894045043736696,
-0.012916077859699726,
-0.0012031259248033166,
0.06175874546170235,
0.02509206347167492,
0.02816190756857395,
0.017487376928329468,
0.015445703640580177,
-0.004988883156329393,
0.014092330820858479,
0.026838049292564392,
-0.022680513560771942,
0.023692220449447632,
0.0042160688899457455,
-0.007071931380778551,
0.07286219298839569,
-0.008834907785058022,
-0.02770431898534298,
0.021866489201784134,
-0.005003115627914667,
-0.05422364920377731,
-0.0066177998669445515,
-0.07738160341978073,
-0.048166800290346146,
-0.011507703922688961,
0.008310840465128422,
0.02045423537492752,
0.03118468075990677,
-0.010524163022637367,
-0.02874918468296528,
-0.051576606929302216,
-0.004264023154973984,
0.016101039946079254,
0.05340117588639259,
0.04873654246330261,
0.032021913677453995,
0.00982840359210968,
-0.008844575844705105,
-0.028069917112588882,
0.012251385487616062,
-0.04018605127930641,
0.01806720346212387,
-0.01075209304690361,
0.012928941287100315,
-0.002184930257499218,
0.04598667472600937,
0.03454604744911194,
-0.019135458394885063,
-0.011693133041262627,
-0.01838049292564392,
-0.008662776090204716,
0.0022868122905492783,
-0.058850664645433426,
0.015118098817765713,
0.05071598291397095,
-0.007175897713750601,
-0.011326744221150875,
-0.022730939090251923,
0.01881045289337635,
-0.009301994927227497,
-0.020955178886651993,
0.040311794728040695,
-0.040220316499471664,
-0.028399117290973663,
0.013034370727837086,
-0.04554528743028641,
0.06770358979701996,
-0.000244109018240124,
-0.05916881188750267,
0.008022485300898552,
0.03731079399585724,
-0.0026301867328584194,
0.0402965322136879,
0.06991871446371078,
-0.04718530550599098,
0.0009216468315571547,
0.011083981022238731,
0.029189445078372955,
-0.027747703716158867,
0.028541799634695053,
-0.037034276872873306,
0.026665907353162766,
-0.0128103606402874,
0.030962496995925903,
0.05261474475264549,
-0.02969658002257347,
-0.07685092091560364,
-0.01049173902720213,
0.0026452906895428896,
0.03727492317557335,
0.015235311351716518,
-0.021665647625923157,
-0.004258792847394943,
-0.05187144875526428,
-0.038152746856212616,
0.00440191850066185,
0.002343558706343174,
0.03777697682380676,
0.030056679621338844,
0.003406458767130971,
-0.008898505941033363,
0.03909865394234657,
-0.006605558097362518,
0.057128868997097015,
0.019201528280973434,
0.03730543702840805,
0.041946519166231155,
-0.03953138738870621,
-0.0023834998719394207,
-0.011687244288623333,
-0.06852193921804428,
0.05399257317185402,
0.05253874883055687,
-0.019862905144691467,
-0.05314106494188309,
-0.03306069225072861,
-0.000260887696640566,
-0.054803263396024704,
-0.03270254656672478,
0.04438139498233795,
-0.035977400839328766,
-0.013794409111142159,
0.003654231783002615,
0.013188515789806843,
0.00448645418509841,
0.0006244763499125838,
0.03823986276984215,
0.011863663792610168,
0.03193744271993637,
-0.060079287737607956,
0.010191715322434902,
0.043289124965667725,
0.000995417358353734,
0.0006745566497556865,
-0.021042874082922935,
-0.03908344358205795,
-0.030522501096129417,
-0.03633168339729309,
-0.032454341650009155,
0.029701869934797287,
0.029237719252705574,
0.03372244909405708,
-0.08768073469400406,
-0.04149286076426506,
0.00369636295363307,
-0.024289974942803383,
-0.04017135500907898,
-0.01066445279866457,
0.03932521492242813,
0.06298550963401794,
-0.022876303642988205,
0.01222445722669363,
-0.029074562713503838,
0.08594608306884766,
0.02600371465086937,
0.0008523153373971581,
-0.002141988603398204,
-0.027635138481855392,
0.019875722005963326,
-0.06435240805149078,
-0.026091312989592552,
0.0505838617682457,
0.061943888664245605,
0.017458871006965637,
-0.00795540027320385,
0.011309091001749039,
0.009132479317486286,
-0.013449165970087051,
0.02896067686378956,
-0.008267574943602085,
0.06014089286327362,
0.013366017490625381,
-0.020229749381542206,
-0.004670923575758934,
0.008056034334003925,
0.02745004929602146,
0.00599603122100234,
-0.09802623093128204,
0.02207873947918415,
0.01036748941987753,
0.005802980624139309,
0.05444803461432457,
-0.02177303284406662,
0.026795733720064163,
0.014570871368050575,
-0.03147757798433304,
0.04068702086806297,
-0.03249456360936165,
-0.036800213158130646,
0.018589457497000694,
-0.025093892589211464,
0.02607089839875698,
-0.0023554174695163965,
0.03168630599975586,
0.05443336442112923,
0.04938993602991104,
-0.0016484672669321299,
-0.045476775616407394,
-0.03140905871987343,
0.029937898740172386,
-0.0340680293738842,
0.01232590526342392,
0.014595652930438519,
-0.01327507197856903,
0.02859266847372055,
0.012175122275948524,
0.019592123106122017,
0.002630942966789007,
-0.03819679096341133,
-0.01640312559902668,
-0.03704676032066345,
0.016647806391119957,
0.014681178145110607,
0.0071923029609024525,
-0.1333046406507492,
-0.007376788649708033,
-0.02680928073823452,
0.024850670248270035,
-0.0019506494281813502,
-0.022834278643131256,
-0.010938913561403751,
-0.00002955119634862058,
-0.04461653530597687,
-0.04058375954627991,
-0.05090419203042984,
0.01861952431499958,
-0.028311969712376595,
0.015576108358800411,
-0.05730339139699936,
-0.0005126313189975917,
0.00010547621786827222,
-0.02236565761268139,
-0.05025904253125191,
-0.011849399656057358,
0.05390952527523041,
-0.025882462039589882,
-0.01820799894630909,
0.003687486983835697,
0.04677804931998253,
-0.03358088433742523,
-0.02935541234910488,
0.005295533686876297,
-0.021186187863349915,
0.011743198148906231,
0.003207053989171982,
0.021078146994113922,
0.04887353256344795,
0.0016913478029891849,
-0.015706224367022514,
-0.0074282255955040455,
0.007678660564124584,
0.015768978744745255,
-0.008692151866853237,
0.02344873547554016,
0.01179539691656828,
0.011676548048853874,
-0.04036546126008034,
-0.023436641320586205,
0.005630366504192352
] |
8a3651a34d3b1893e6f70ebe64b9db39d329cd63 | 8,496 | py | Python | testing/cross_language/util/supported_key_types.py | chanced/tink | 9cc3a01ac0165b033ed51dc9d0812a98b4b6e305 | [
"Apache-2.0"
] | null | null | null | testing/cross_language/util/supported_key_types.py | chanced/tink | 9cc3a01ac0165b033ed51dc9d0812a98b4b6e305 | [
"Apache-2.0"
] | null | null | null | testing/cross_language/util/supported_key_types.py | chanced/tink | 9cc3a01ac0165b033ed51dc9d0812a98b4b6e305 | [
"Apache-2.0"
] | 1 | 2022-01-02T20:54:04.000Z | 2022-01-02T20:54:04.000Z | # 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.
"""All KeyTypes and which languages support them."""
# Placeholder for import for type annotations
from tink import aead
from tink import daead
from tink import hybrid
from tink import mac
from tink import prf
from tink import signature
from tink import streaming_aead
from tink.proto import tink_pb2
# All languages supported by cross-language tests.
ALL_LANGUAGES = ['cc', 'java', 'go', 'python']
# All KeyTypes (without the prefix 'type.googleapis.com/google.crypto.tink.')
AEAD_KEY_TYPES = [
'AesEaxKey',
'AesGcmKey',
'AesGcmSivKey',
'AesCtrHmacAeadKey',
'ChaCha20Poly1305Key',
'XChaCha20Poly1305Key',
]
DAEAD_KEY_TYPES = ['AesSivKey']
STREAMING_AEAD_KEY_TYPES = [
'AesCtrHmacStreamingKey',
'AesGcmHkdfStreamingKey',
]
HYBRID_PRIVATE_KEY_TYPES = ['EciesAeadHkdfPrivateKey']
MAC_KEY_TYPES = [
'AesCmacKey',
'HmacKey',
]
SIGNATURE_KEY_TYPES = [
'EcdsaPrivateKey',
'Ed25519PrivateKey',
'RsaSsaPkcs1PrivateKey',
'RsaSsaPssPrivateKey',
]
PRF_KEY_TYPES = [
'AesCmacPrfKey',
'HmacPrfKey',
'HkdfPrfKey',
]
ALL_KEY_TYPES = (
AEAD_KEY_TYPES + DAEAD_KEY_TYPES + STREAMING_AEAD_KEY_TYPES +
HYBRID_PRIVATE_KEY_TYPES + MAC_KEY_TYPES + SIGNATURE_KEY_TYPES +
PRF_KEY_TYPES)
# All languages that are supported by a KeyType
SUPPORTED_LANGUAGES = {
'AesEaxKey': ['cc', 'java', 'python'],
'AesGcmKey': ['cc', 'java', 'go', 'python'],
'AesGcmSivKey': ['cc', 'python'],
'AesCtrHmacAeadKey': ['cc', 'java', 'go', 'python'],
'ChaCha20Poly1305Key': ['java', 'go'],
'XChaCha20Poly1305Key': ['cc', 'java', 'go', 'python'],
'AesSivKey': ['cc', 'java', 'go', 'python'],
'AesCtrHmacStreamingKey': ['cc', 'java', 'go', 'python'],
'AesGcmHkdfStreamingKey': ['cc', 'java', 'go', 'python'],
'EciesAeadHkdfPrivateKey': ['cc', 'java', 'go', 'python'],
'AesCmacKey': ['cc', 'java', 'go', 'python'],
'HmacKey': ['cc', 'java', 'go', 'python'],
'EcdsaPrivateKey': ['cc', 'java', 'go', 'python'],
'Ed25519PrivateKey': ['cc', 'java', 'go', 'python'],
'RsaSsaPkcs1PrivateKey': ['cc', 'java', 'python'],
'RsaSsaPssPrivateKey': ['cc', 'java', 'python'],
'AesCmacPrfKey': ['cc', 'java', 'go', 'python'],
'HmacPrfKey': ['cc', 'java', 'go', 'python'],
'HkdfPrfKey': ['cc', 'java', 'go', 'python'],
}
KEY_TYPE_FROM_URL = {
'type.googleapis.com/google.crypto.tink.' + key_type: key_type
for key_type in ALL_KEY_TYPES}
# For each KeyType, a list of all KeyTemplate Names that must be supported.
KEY_TEMPLATE_NAMES = {
'AesEaxKey': ['AES128_EAX', 'AES256_EAX'],
'AesGcmKey': ['AES128_GCM', 'AES256_GCM'],
'AesGcmSivKey': ['AES128_GCM_SIV', 'AES256_GCM_SIV'],
'AesCtrHmacAeadKey': ['AES128_CTR_HMAC_SHA256', 'AES256_CTR_HMAC_SHA256'],
'ChaCha20Poly1305Key': ['CHACHA20_POLY1305'],
'XChaCha20Poly1305Key': ['XCHACHA20_POLY1305'],
'AesSivKey': ['AES256_SIV'],
'AesCtrHmacStreamingKey': [
'AES128_CTR_HMAC_SHA256_4KB',
'AES256_CTR_HMAC_SHA256_4KB',
],
'AesGcmHkdfStreamingKey': [
'AES128_GCM_HKDF_4KB',
'AES256_GCM_HKDF_4KB',
'AES256_GCM_HKDF_1MB',
],
'EciesAeadHkdfPrivateKey': [
'ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM',
'ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256'
],
'AesCmacKey': ['AES_CMAC'],
'HmacKey': [
'HMAC_SHA256_128BITTAG', 'HMAC_SHA256_256BITTAG',
'HMAC_SHA512_256BITTAG', 'HMAC_SHA512_512BITTAG'
],
'EcdsaPrivateKey': [
'ECDSA_P256', 'ECDSA_P384', 'ECDSA_P384_SHA384', 'ECDSA_P521',
'ECDSA_P256_IEEE_P1363', 'ECDSA_P384_IEEE_P1363',
'ECDSA_P384_SHA384_IEEE_P1363', 'ECDSA_P521_IEEE_P1363'
],
'Ed25519PrivateKey': ['ED25519'],
'RsaSsaPkcs1PrivateKey': [
'RSA_SSA_PKCS1_3072_SHA256_F4', 'RSA_SSA_PKCS1_4096_SHA512_F4'
],
'RsaSsaPssPrivateKey': [
'RSA_SSA_PSS_3072_SHA256_SHA256_32_F4',
'RSA_SSA_PSS_4096_SHA512_SHA512_64_F4'
],
'AesCmacPrfKey': ['AES_CMAC_PRF'],
'HmacPrfKey': ['HMAC_PRF_SHA256', 'HMAC_PRF_SHA512'],
'HkdfPrfKey': ['HKDF_PRF_SHA256'],
}
# KeyTemplate (as Protobuf) for each KeyTemplate name.
KEY_TEMPLATE = {
'AES128_EAX':
aead.aead_key_templates.AES128_EAX,
'AES256_EAX':
aead.aead_key_templates.AES256_EAX,
'AES128_GCM':
aead.aead_key_templates.AES128_GCM,
'AES256_GCM':
aead.aead_key_templates.AES256_GCM,
'AES128_GCM_SIV':
aead.aead_key_templates.AES128_GCM_SIV,
'AES256_GCM_SIV':
aead.aead_key_templates.AES256_GCM_SIV,
'AES128_CTR_HMAC_SHA256':
aead.aead_key_templates.AES128_CTR_HMAC_SHA256,
'AES256_CTR_HMAC_SHA256':
aead.aead_key_templates.AES256_CTR_HMAC_SHA256,
'CHACHA20_POLY1305':
tink_pb2.KeyTemplate(
type_url=('type.googleapis.com/google.crypto.tink.' +
'ChaCha20Poly1305Key'),
output_prefix_type=tink_pb2.TINK),
'XCHACHA20_POLY1305':
aead.aead_key_templates.XCHACHA20_POLY1305,
'AES256_SIV':
daead.deterministic_aead_key_templates.AES256_SIV,
'AES128_CTR_HMAC_SHA256_4KB':
streaming_aead.streaming_aead_key_templates.AES128_CTR_HMAC_SHA256_4KB,
'AES256_CTR_HMAC_SHA256_4KB':
streaming_aead.streaming_aead_key_templates.AES256_CTR_HMAC_SHA256_4KB,
'AES128_GCM_HKDF_4KB':
streaming_aead.streaming_aead_key_templates.AES128_GCM_HKDF_4KB,
'AES256_GCM_HKDF_4KB':
streaming_aead.streaming_aead_key_templates.AES256_GCM_HKDF_4KB,
'AES256_GCM_HKDF_1MB':
streaming_aead.streaming_aead_key_templates.AES256_GCM_HKDF_1MB,
'ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM':
hybrid.hybrid_key_templates.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM,
'ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256':
hybrid.hybrid_key_templates
.ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256,
'AES_CMAC':
mac.mac_key_templates.AES_CMAC,
'HMAC_SHA256_128BITTAG':
mac.mac_key_templates.HMAC_SHA256_128BITTAG,
'HMAC_SHA256_256BITTAG':
mac.mac_key_templates.HMAC_SHA256_256BITTAG,
'HMAC_SHA512_256BITTAG':
mac.mac_key_templates.HMAC_SHA512_256BITTAG,
'HMAC_SHA512_512BITTAG':
mac.mac_key_templates.HMAC_SHA512_512BITTAG,
'ECDSA_P256':
signature.signature_key_templates.ECDSA_P256,
'ECDSA_P384':
signature.signature_key_templates.ECDSA_P384,
'ECDSA_P384_SHA384':
signature.signature_key_templates.ECDSA_P384_SHA384,
'ECDSA_P521':
signature.signature_key_templates.ECDSA_P521,
'ECDSA_P256_IEEE_P1363':
signature.signature_key_templates.ECDSA_P256_IEEE_P1363,
'ECDSA_P384_IEEE_P1363':
signature.signature_key_templates.ECDSA_P384_IEEE_P1363,
'ECDSA_P384_SHA384_IEEE_P1363':
signature.signature_key_templates.ECDSA_P384_SHA384_IEEE_P1363,
'ECDSA_P521_IEEE_P1363':
signature.signature_key_templates.ECDSA_P521_IEEE_P1363,
'ED25519':
signature.signature_key_templates.ED25519,
'RSA_SSA_PKCS1_3072_SHA256_F4':
signature.signature_key_templates.RSA_SSA_PKCS1_3072_SHA256_F4,
'RSA_SSA_PKCS1_4096_SHA512_F4':
signature.signature_key_templates.RSA_SSA_PKCS1_4096_SHA512_F4,
'RSA_SSA_PSS_3072_SHA256_SHA256_32_F4':
signature.signature_key_templates.RSA_SSA_PSS_3072_SHA256_SHA256_32_F4,
'RSA_SSA_PSS_4096_SHA512_SHA512_64_F4':
signature.signature_key_templates.RSA_SSA_PSS_4096_SHA512_SHA512_64_F4,
'AES_CMAC_PRF':
prf.prf_key_templates.AES_CMAC,
'HMAC_PRF_SHA256':
prf.prf_key_templates.HMAC_SHA256,
'HMAC_PRF_SHA512':
prf.prf_key_templates.HMAC_SHA512,
'HKDF_PRF_SHA256':
prf.prf_key_templates.HKDF_SHA256,
}
SUPPORTED_LANGUAGES_BY_TEMPLATE_NAME = {
name: SUPPORTED_LANGUAGES[KEY_TYPE_FROM_URL[template.type_url]]
for name, template in KEY_TEMPLATE.items()
}
| 37.263158 | 79 | 0.711982 | 0 | 0 | [
-0.07054749876260757,
0.06580975651741028,
0.01646018587052822,
0.026345012709498405,
-0.0346854068338871,
-0.005210396368056536,
-0.04476875066757202,
0.023764584213495255,
-0.004802241921424866,
0.007953334599733353,
0.03883397579193115,
-0.007098836358636618,
0.03511433303356171,
-0.0026259450241923332,
-0.015508420765399933,
0.0010473342845216393,
0.044212523847818375,
-0.019148515537381172,
0.008695832453668118,
0.009797809645533562,
-0.01513311080634594,
-0.026368968188762665,
-0.019404996186494827,
0.022934142500162125,
0.01656476780772209,
0.021056121215224266,
0.041140880435705185,
0.026845116168260574,
0.021457361057400703,
-0.009630696848034859,
0.00921058189123869,
0.010613802820444107,
-0.023762304335832596,
-0.07846181094646454,
-0.027565134689211845,
0.020429445430636406,
0.0038479240611195564,
-0.004493319429457188,
0.05199982970952988,
-0.0261127557605505,
-0.03477559611201286,
-0.0361328162252903,
-0.0014927115989848971,
-0.01795145496726036,
0.022434955462813377,
-0.00087696936680004,
-0.01003443356603384,
0.02074049785733223,
-0.0771225169301033,
0.030888797715306282,
-0.0006148596876300871,
-0.033283643424510956,
0.010689299553632736,
0.033858492970466614,
-0.004528820980340242,
-0.023306604474782944,
0.007442181929945946,
0.024688707664608955,
-0.0333571583032608,
0.025056714192032814,
0.031088650226593018,
-0.010531282983720303,
0.03965931758284569,
0.021950142458081245,
-0.013033677823841572,
-0.02228662185370922,
0.002384515479207039,
0.019351713359355927,
-0.04864108934998512,
-0.01666019670665264,
0.009128657169640064,
-0.03031717799603939,
-0.0038905281107872725,
0.02867865562438965,
-0.007670227903872728,
-0.014498072676360607,
-0.026701046153903008,
-0.04210759699344635,
0.021322252228856087,
-0.018381113186478615,
-0.007994144223630428,
0.05094088986515999,
0.02128557860851288,
-0.007724777329713106,
0.031460780650377274,
0.06119904667139053,
0.10298392921686172,
-0.0545731745660305,
0.032122015953063965,
0.031220877543091774,
-0.027302175760269165,
0.00031491764821112156,
-0.0026878383941948414,
-0.005464787594974041,
0.013106591068208218,
-0.007224219385534525,
0.030475853011012077,
0.014725944958627224,
0.012390593998134136,
0.0012382835848256946,
0.028614070266485214,
-0.0378754548728466,
0.010623862035572529,
0.017284689471125603,
0.013411066494882107,
-0.005061616655439138,
-0.07686411589384079,
-0.04794994741678238,
0.00019374200201127678,
-0.019480278715491295,
-0.007865927182137966,
0.02821240946650505,
0.0011080974945798516,
-0.029075512662529945,
-0.03647298738360405,
-0.030607201159000397,
0.02172432839870453,
0.017688672989606857,
-0.04090968891978264,
0.015405782498419285,
-0.005835512652993202,
0.012740928679704666,
-0.009675583802163601,
-0.06162676960229874,
-0.023376181721687317,
0.07931406795978546,
-0.022753039374947548,
0.015133466571569443,
-0.002808289835229516,
-0.005750189535319805,
-0.01305761281400919,
0.027081215754151344,
-0.033667970448732376,
-0.019498737528920174,
0.02836097776889801,
0.002290097065269947,
0.03023109957575798,
0.0425398088991642,
-0.05399564281105995,
0.035137973725795746,
-0.035041384398937225,
0.013926499523222446,
0.01458679512143135,
-0.00841523427516222,
-0.011780325323343277,
-0.036201056092977524,
-0.00182875688187778,
-0.008983198553323746,
0.006400033365935087,
0.003973705228418112,
-0.004609215073287487,
-0.0075940522365272045,
0.00479480717331171,
0.04456807300448418,
-0.03615958243608475,
-0.01368329394608736,
-0.019237274304032326,
-0.047404006123542786,
-0.04057259485125542,
0.03655147925019264,
-0.0333806537091732,
0.015066389925777912,
0.009644887410104275,
0.008262785151600838,
-0.009697015397250652,
0.038126278668642044,
-0.02036113478243351,
0.010873849503695965,
-0.022449897602200508,
0.01652330718934536,
0.017313187941908836,
-0.006177917588502169,
-0.049188047647476196,
-0.023848678916692734,
0.021866915747523308,
0.018573768436908722,
0.014070684090256691,
-0.003656972898170352,
0.008891805075109005,
0.016451869159936905,
0.008493442088365555,
-0.03000716120004654,
0.021998047828674316,
0.042424775660037994,
-0.027875496074557304,
0.039133135229349136,
-0.010426689870655537,
0.006864071357995272,
0.007707745302468538,
0.007809587754309177,
0.00782245583832264,
-0.0006550883408635855,
0.025011705234646797,
-0.043956201523542404,
0.019568758085370064,
0.007232898846268654,
-0.019989918917417526,
-0.01044559944421053,
0.0032891929149627686,
0.027255425229668617,
-0.024282235652208328,
-0.035834383219480515,
-0.0038028021808713675,
0.010428374633193016,
0.0009008392808027565,
-0.02346131205558777,
-0.692478358745575,
0.014208708889782429,
-0.0036331492010504007,
-0.027032583951950073,
0.014276760630309582,
-0.02164361998438835,
-0.023595012724399567,
0.023906810209155083,
-0.06074255332350731,
-0.0026544234715402126,
0.012709692120552063,
-0.005533063784241676,
-0.014123912900686264,
0.014800583012402058,
-0.008792410604655743,
0.006530321668833494,
0.028949495404958725,
0.0012242809170857072,
-0.003908088896423578,
-0.02083830162882805,
0.019403185695409775,
-0.02170003205537796,
-0.023020293563604355,
-0.0050245365127921104,
0.014684748835861683,
-0.020249828696250916,
0.031092610210180283,
0.020457815378904343,
-0.009191545657813549,
0.02152392640709877,
-0.04660811647772789,
-0.008858272805809975,
0.017663132399320602,
-0.01765013113617897,
0.004124345723539591,
0.01171873789280653,
0.014843551442027092,
-0.031670425087213516,
0.007465609814971685,
-0.0055877151899039745,
-0.012801718898117542,
-0.024566859006881714,
-0.0089121013879776,
-0.056429799646139145,
-0.021402493119239807,
-0.010586168617010117,
0.031089287251234055,
-0.0056802318431437016,
-0.019069286063313484,
0.0125122694298625,
-0.029670223593711853,
-0.0012292892206460238,
0.01677064038813114,
-0.0331968292593956,
-0.0252394936978817,
-0.011604154482483864,
-0.010248452425003052,
0.010930468328297138,
-0.0031947901006788015,
0.01612692140042782,
-0.0041459002532064915,
-0.007337590679526329,
0.006274507846683264,
0.012424208223819733,
0.005464484915137291,
-0.013757986016571522,
-0.020257985219359398,
-0.025870434939861298,
-0.043260831385850906,
-0.020354636013507843,
-0.00884412694722414,
-0.00441479217261076,
-0.03170744702219963,
0.012135276570916176,
0.022589396685361862,
0.037114594131708145,
-0.018750032410025597,
-0.023395460098981857,
-0.026390673592686653,
-0.02710612304508686,
-0.0320056676864624,
-0.011215467937290668,
-0.01870723068714142,
0.004335562698543072,
-0.017756648361682892,
-0.019986018538475037,
0.024716023355722427,
-0.0037748399190604687,
0.00760982371866703,
-0.01107881497591734,
0.03557317703962326,
0.0005512998905032873,
0.03294483199715614,
0.0063566346652805805,
0.02742442861199379,
0.016644161194562912,
0.024209368973970413,
-0.016638945788145065,
0.000821154797449708,
0.02254381775856018,
-0.037697456777095795,
0.0025040400214493275,
-0.011112327687442303,
0.08318110555410385,
0.032228149473667145,
0.0054809157736599445,
-0.01760394312441349,
-0.012705798260867596,
0.05411134287714958,
-0.04399746656417847,
-0.0027517930138856173,
-0.010432074777781963,
-0.0035055617336183786,
-0.013702510856091976,
-0.03196563944220543,
-0.009196621365845203,
-0.03854820877313614,
-0.029174521565437317,
0.003998207859694958,
-0.0022200532257556915,
-0.027419468387961388,
0.048001978546381,
0.010073050856590271,
0.020013930276036263,
0.0013037880416959524,
0.013090595602989197,
-0.005993261002004147,
0.0051132747903466225,
0.029144849628210068,
-0.0007010800763964653,
-0.02162150666117668,
0.009796686470508575,
0.00371957547031343,
-0.002972388407215476,
-0.0002724131918512285,
0.022886261343955994,
-0.035127654671669006,
-0.024278590455651283,
0.026945559307932854,
0.004614665172994137,
-0.009536166675388813,
-0.01440388709306717,
0.02008868381381035,
-0.012030590325593948,
0.01248142495751381,
0.023237312212586403,
-0.019942238926887512,
0.0016028874088078737,
-0.013378169387578964,
0.004330003634095192,
-0.029175741598010063,
0.01423384714871645,
-0.00319060985930264,
-0.018562695011496544,
-0.010855640284717083,
-0.0019423901103436947,
-0.006663940846920013,
-0.028121523559093475,
0.030010001733899117,
0.0359044075012207,
-0.023005664348602295,
-0.00031357782427221537,
0.035094715654850006,
0.03593175858259201,
-0.017052719369530678,
-0.013032348826527596,
0.01457038801163435,
0.022774873301386833,
-0.01268352847546339,
0.03407972678542137,
0.003522886661812663,
0.026626449078321457,
0.0399446040391922,
0.002276370534673333,
-0.00003504238338791765,
-0.0008201341843232512,
0.010416391305625439,
-0.03158818185329437,
-0.003473001066595316,
-0.02363945171236992,
0.004599743988364935,
0.004238948691636324,
-0.019328517839312553,
-0.0027472367510199547,
-0.0007431728881783783,
0.03656194359064102,
0.024895748123526573,
0.0053309169597923756,
0.04406987875699997,
0.0066588763147592545,
0.04975827410817146,
0.05171022564172745,
-0.01864008978009224,
-0.0028587249107658863,
-0.011961335316300392,
-0.0030738329514861107,
-0.03635919839143753,
-0.010447456501424313,
0.027682770043611526,
-0.0009872453520074487,
0.002819401677697897,
0.01390699204057455,
-0.03430779650807381,
-0.009499358013272285,
0.021109454333782196,
0.03068367950618267,
-0.011988313868641853,
0.0037916088476777077,
0.011848598718643188,
-0.0007760421140119433,
-0.00023543572751805186,
-0.020314564928412437,
-0.006008953787386417,
0.009296910837292671,
-0.01419511903077364,
0.017180591821670532,
-0.050074443221092224,
0.0005673971027135849,
0.03332490101456642,
-0.07232718169689178,
-0.05890360474586487,
-0.017770390957593918,
0.00329192029312253,
0.009149149991571903,
-0.005358852446079254,
0.004674185998737812,
0.013784036971628666,
0.02792743407189846,
-0.024312641471624374,
-0.006082093343138695,
0.022073164582252502,
0.007043214049190283,
0.014134230092167854,
-0.0016355471452698112,
-0.02023007906973362,
0.023939011618494987,
-0.004656205419450998,
-0.04299048334360123,
0.009261195547878742,
0.0038005197420716286,
-0.003883525263518095,
-0.058965668082237244,
-0.01626593805849552,
-0.009380226023495197,
-0.025583039969205856,
-0.006949538830667734,
0.012280203402042389,
-0.043488968163728714,
-0.0071230786852538586,
0.013414840213954449,
0.03515656292438507,
0.007978856563568115,
0.05482100695371628,
0.007412362843751907,
0.02743993140757084,
0.007772438228130341,
-0.007917405106127262,
0.00916906725615263,
0.027721259742975235,
-0.002072056056931615,
-0.021825134754180908,
-0.05359962582588196,
-0.03150801360607147,
0.04786957800388336,
0.016471028327941895,
-0.0015267980052158237,
0.018468985334038734,
-0.039198972284793854,
-0.0349460169672966,
0.02233944460749626,
-0.013170219026505947,
-0.020514264702796936,
-0.02171114645898342,
-0.02414977364242077,
0.030719958245754242,
0.004045970272272825,
-0.0001871723070507869,
-0.0068346597254276276,
-0.002322954125702381,
0.051761362701654434,
-0.013937778770923615,
0.005973071325570345,
0.04101065173745155,
-0.009740541689097881,
0.01518878061324358,
0.028897179290652275,
0.02069590985774994,
-0.0476691834628582,
-0.016818247735500336,
-0.021489880979061127,
-0.019585156813263893,
-0.029891666024923325,
0.05362239480018616,
0.009194283746182919,
0.015606088563799858,
-0.0032387254759669304,
0.028986867517232895,
-0.011825146153569221,
0.03650146350264549,
-0.03214095160365105,
-0.00620735390111804,
-0.02406284399330616,
-0.02333538793027401,
0.03972173482179642,
-0.028373675420880318,
-0.008422954007983208,
-0.001950523816049099,
-0.011136976070702076,
0.013784659095108509,
0.017711011692881584,
0.015706006437540054,
0.043906070291996,
0.002091973088681698,
0.022879604250192642,
0.012515293434262276,
0.008673037402331829,
0.02296646684408188,
0.0032529812306165695,
0.013056454248726368,
0.023216569796204567,
-0.0463937446475029,
0.013131449930369854,
-0.021789085119962692,
-0.025466160848736763,
0.006362184416502714,
-0.018774012103676796,
-0.0549713633954525,
-0.01733597368001938,
0.016171645373106003,
-0.04564448818564415,
-0.014078957028687,
-0.013108582235872746,
-0.02323511429131031,
0.006313396617770195,
-0.0037633238825947046,
0.002862154273316264,
0.008131004869937897,
0.02643563598394394,
0.017171701416373253,
-0.003352745668962598,
-0.015237021259963512,
0.04624411091208458,
0.007886610925197601,
-0.06265582889318466,
0.009007160551846027,
-0.005172383040189743,
0.05950230732560158,
0.059368498623371124,
0.0546887144446373,
0.01043398305773735,
0.015052604489028454,
0.013255130499601364,
-0.0026780676562339067,
0.0062585026025772095,
-0.014005118981003761,
-0.011290175840258598,
-0.03159191459417343,
-0.03650452569127083,
0.024129102006554604,
-0.022433074191212654,
-0.0042637004517018795,
-0.007026126608252525,
-0.02023669332265854,
0.03755227476358414,
0.0014133219374343753,
-0.01044385228306055,
0.020159056410193443,
0.003380924230441451,
0.012370358221232891,
0.022574828937649727,
-0.02447804994881153,
-0.02905973047018051,
0.014693200588226318,
0.030509641394019127,
0.03457000106573105,
-0.005452622193843126,
-0.010105917230248451,
-0.017115022987127304,
0.009048489853739738,
0.007985382340848446,
-0.057263556867837906,
-0.05423334985971451,
-0.004720855969935656,
-0.019143089652061462,
0.024864437058568,
-0.030504997819662094,
-0.022022753953933716,
0.014069735072553158,
-0.01924472488462925,
-0.0534258708357811,
-0.029993221163749695,
0.035403911024332047,
0.011183517053723335,
0.011881382204592228,
0.012357129715383053,
-0.012377392500638962,
-0.029767490923404694,
-0.010528492741286755,
0.010444904677569866,
-0.002584657398983836,
0.0013649952597916126,
0.00697840703651309,
0.051179032772779465,
-0.005896615795791149,
0.006622468587011099,
-0.06645318120718002,
-0.01322648674249649,
0.0005191084928810596,
-0.025651128962635994,
0.024006139487028122,
0.00825771689414978,
0.021468903869390488,
-0.0198187455534935,
-0.04137572646141052,
0.04878539592027664,
0.00019573968893382698,
-0.004938468802720308,
0.01390480250120163,
-0.0016705497400835156,
0.056791987270116806,
0.0034345006570219994,
0.019174709916114807,
-0.0119552630931139,
0.015600197948515415,
0.005264550447463989,
0.008063234388828278,
-0.005213316064327955,
0.001491622650064528,
0.0018946070922538638,
0.00025719613768160343,
-0.00989933218806982,
-0.014493429102003574,
-0.023394333198666573,
0.012104890309274197,
0.04348563402891159,
-0.008322631008923054,
-0.0013299623969942331,
-0.014707687310874462,
0.036643754690885544,
0.016381388530135155,
-0.0121913505718112,
0.006169147323817015,
0.016802269965410233,
0.019089046865701675,
0.007041251286864281,
-0.12471107393503189,
0.015890656039118767,
0.008729016408324242,
-0.02408122643828392,
-0.0022298775147646666,
-0.0456429049372673,
0.02034074068069458,
0.025020303204655647,
0.008198430761694908,
0.012274784967303276,
0.030983831733465195,
0.03391921892762184,
-0.018568601459264755,
0.02026776410639286,
0.000024817056328174658,
0.00693201320245862,
0.04551595076918602,
0.006949427537620068,
0.017203394323587418,
0.035700730979442596,
0.019972365349531174,
0.0013527747942134738,
0.0002708252868615091,
0.000990356900729239,
0.00031370396027341485,
-0.0028883086051791906,
0.02856628969311714,
-0.02588958479464054,
-0.001241360791027546,
0.010933809913694859,
0.011661599390208721,
-0.040623463690280914,
-0.03966331109404564,
0.03801459074020386,
0.009513725526630878,
0.009927102364599705,
0.011936936527490616,
0.02089904248714447,
-0.01243457943201065,
0.014008017256855965,
0.02717476524412632,
-0.008663183078169823,
0.00588607182726264,
-0.016921205446124077,
0.005520686972886324,
-0.03397065028548241,
-0.04681212827563286,
-0.02373911254107952,
0.031347502022981644,
0.0006581498892046511,
-0.023817991837859154,
0.018851449713110924,
-0.02567311003804207,
0.06555330008268356,
-0.012654813006520271,
0.01638558693230152,
-0.01221307273954153,
-0.014449939131736755,
-0.03460971638560295,
0.03456965833902359,
0.024955520406365395,
0.034215863794088364,
0.06805326789617538,
-0.008900363929569721,
0.0033852113410830498,
-0.024709448218345642,
0.00546631496399641,
-0.010491346009075642,
0.008587843738496304,
0.03404999151825905,
0.03829770162701607,
0.0306954775005579,
-0.06318355351686478,
0.014359193854033947,
0.007331070024520159,
0.00676138186827302,
-0.037508975714445114,
-0.0019614973571151495,
-0.02086506225168705,
0.010657145641744137,
0.010663721710443497,
-0.05328512564301491,
-0.006540884729474783,
0.04806939512491226,
0.021177226677536964,
-0.014112841337919235,
0.007166313007473946,
-0.01230197586119175,
-0.0044281696900725365,
-0.02413366734981537,
-0.05932822450995445,
-0.0036255368031561375,
0.077720046043396,
-0.02449961006641388,
0.009107811376452446,
0.022394832223653793,
0.004765130579471588,
-0.008311212994158268,
-0.003658225294202566,
-0.018862871453166008,
-0.010949003510177135,
-0.020722653716802597,
-0.041479162871837616,
0.04863129183650017,
-0.008140483871102333,
-0.0018789742607623339,
0.02045736089348793,
0.038647912442684174,
0.030642449855804443,
-0.03423997014760971,
-0.0639340728521347,
-0.008174587041139603,
0.05471445620059967,
-0.03418085351586342,
-0.029427582398056984,
-0.0071954564191401005,
0.0264218021184206
] |
8a36ee854524bdd692e5d46cc0bfba0c999e570b | 3,625 | py | Python | signer.py | chapeltech/remote-signer | 83d083ed7e8c7123187ba70ee3132b898e8ef02e | [
"MIT"
] | 39 | 2018-07-08T01:01:18.000Z | 2022-01-03T13:48:10.000Z | signer.py | chapeltech/remote-signer | 83d083ed7e8c7123187ba70ee3132b898e8ef02e | [
"MIT"
] | 4 | 2019-10-04T11:15:15.000Z | 2022-02-03T00:17:47.000Z | signer.py | chapeltech/remote-signer | 83d083ed7e8c7123187ba70ee3132b898e8ef02e | [
"MIT"
] | 19 | 2018-09-20T11:52:25.000Z | 2022-02-02T19:21:04.000Z | #!/usr/bin/env python3
#########################################################
# Written by Carl Youngblood, carl@blockscale.net
# Copyright (c) 2018 Blockscale LLC
# released under the MIT license
#########################################################
from flask import Flask, request, Response, json, jsonify
from src.remote_signer import RemoteSigner
from os import path
import logging
logging.basicConfig(filename='./remote-signer.log', format='%(asctime)s %(message)s', level=logging.INFO)
app = Flask(__name__)
# sample config used for testing
config = {
'hsm_username': 'resigner',
'hsm_slot': 1,
'hsm_lib': '/opt/cloudhsm/lib/libcloudhsm_pkcs11.so',
'node_addr': 'http://node.internal:8732',
'keys': {
'tz3aTaJ3d7Rh4yXpereo4yBm21xrs4bnzQvW': {
'public_key': 'p2pk67jx4rEadFpbHdiPhsKxZ4KCoczLWqsEpNarWZ7WQ1SqKMf7JsS',
'private_handle': 7,
'public_handle': 9
}
}
}
logging.info('Opening keys.json')
if path.isfile('keys.json'):
logging.info('Found keys.json')
with open('keys.json', 'r') as myfile:
json_blob = myfile.read().replace('\n', '')
logging.info('Parsed keys.json successfully as JSON')
config = json.loads(json_blob)
logging.info('Config contains: {}'.format(json.dumps(config, indent=2)))
@app.route('/keys/<key_hash>', methods=['POST'])
def sign(key_hash):
response = None
try:
data = request.get_json(force=True)
if key_hash in config['keys']:
logging.info('Found key_hash {} in config'.format(key_hash))
key = config['keys'][key_hash]
logging.info('Attempting to sign {}'.format(data))
rs = RemoteSigner(config, data)
response = jsonify({
'signature': rs.sign(key['private_handle'])
})
logging.info('Response is {}'.format(response))
else:
logging.warning("Couldn't find key {}".format(key_hash))
response = Response('Key not found', status=404)
except Exception as e:
data = {'error': str(e)}
logging.error('Exception thrown during request: {}'.format(str(e)))
response = app.response_class(
response=json.dumps(data),
status=500,
mimetype='application/json'
)
logging.info('Returning flask response {}'.format(response))
return response
@app.route('/keys/<key_hash>', methods=['GET'])
def get_public_key(key_hash):
response = None
try:
if key_hash in config['keys']:
key = config['keys'][key_hash]
response = jsonify({
'public_key': key['public_key']
})
logging.info('Found public key {} for key hash {}'.format(key['public_key'], key_hash))
else:
logging.warning("Couldn't public key for key hash {}".format(key_hash))
response = Response('Key not found', status=404)
except Exception as e:
data = {'error': str(e)}
logging.error('Exception thrown during request: {}'.format(str(e)))
response = app.response_class(
response=json.dumps(data),
status=500,
mimetype='application/json'
)
logging.info('Returning flask response {}'.format(response))
return response
@app.route('/authorized_keys', methods=['GET'])
def authorized_keys():
return app.response_class(
response=json.dumps({}),
status=200,
mimetype='application/json'
)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000, debug=True)
| 33.564815 | 105 | 0.592552 | 1 | 1.8561 | [
0.0015488723292946815,
0.02443292737007141,
0.009182854555547237,
0.0015949684893712401,
0.004335560370236635,
-0.0008108005858957767,
-0.009122143499553204,
0.001458982820622623,
-0.006749831605702639,
0.0020976620726287365,
0.003413280937820673,
0.006176747847348452,
0.006660113111138344,
-0.017115850001573563,
0.000765684642829001,
0.014687782153487206,
-0.050949469208717346,
0.0002235280117020011,
-0.0018858123803511262,
0.0017516881925985217,
-0.007173209451138973,
0.007946142926812172,
0.008987916633486748,
0.004391504917293787,
0.004961592610925436,
-0.0020629020873457193,
0.009543362073600292,
0.0015850894851610065,
-0.007011890411376953,
-0.007485572714358568,
0.0013947709230706096,
-0.0023111500777304173,
-0.006459101103246212,
-0.006026277784258127,
0.004747034050524235,
-0.003962813410907984,
-0.00008876984065864235,
-0.020311320200562477,
0.01479292195290327,
-0.0053887879475951195,
-0.007623953279107809,
-0.014356649480760098,
0.0007691517239436507,
0.0029387681279331446,
-0.008726871572434902,
-0.0003610250714700669,
-0.005822342820465565,
0.002650044858455658,
-0.012098226696252823,
0.006876620464026928,
-0.008881350979208946,
0.006772059015929699,
0.013688734732568264,
0.0030064042657613754,
-0.004702830221503973,
-0.007631135173141956,
0.012953607365489006,
-0.00008524407166987658,
-0.011096128262579441,
-0.0006328923627734184,
-0.003127564210444689,
-0.0015534545527771115,
0.005075404886156321,
0.0047392332926392555,
-0.01641853153705597,
-0.006327743176370859,
-0.0029064600821584463,
0.0015978310257196426,
-0.0028996013570576906,
0.006042367313057184,
0.0005374225438572466,
-0.0008109562913887203,
0.0059270295314490795,
0.003899918170645833,
0.004786061588674784,
-0.004605479072779417,
-0.000940033933147788,
-0.000980642274953425,
0.009985641576349735,
0.003231973387300968,
0.004973631352186203,
-0.0071755507960915565,
0.006019911728799343,
0.009352194145321846,
0.014293180778622627,
0.007551330141723156,
0.019832758232951164,
-0.011273990385234356,
0.04868350178003311,
0.0102600222453475,
-0.008795664645731449,
0.0017960276454687119,
-0.009647096507251263,
-0.0016267704777419567,
-0.003637452144175768,
-0.027415474876761436,
0.0001587222795933485,
-0.004018088337033987,
0.001167159527540207,
0.0029843735974282026,
0.0004252915387041867,
0.006866802461445332,
-0.0015147087397053838,
-0.0027626785449683666,
-0.00734978960826993,
0.009852980263531208,
-0.009595924988389015,
-0.003394653555005789,
0.005254162475466728,
0.0013134751934558153,
-0.011738019995391369,
-0.002415293827652931,
0.0035759909078478813,
-0.01266909297555685,
0.002202380448579788,
0.0020124483853578568,
-0.004420366138219833,
0.05310839042067528,
0.00039837099029682577,
0.004762094933539629,
-0.004084239713847637,
0.0023180346470326185,
0.00010128665599040687,
0.005489974282681942,
0.008657065220177174,
-0.0024170109536498785,
0.012624848634004593,
0.009661929681897163,
0.0035457094199955463,
0.009651166386902332,
-0.0035194538068026304,
0.005240628961473703,
-0.0028411541134119034,
-0.0031588824931532145,
0.0023062052205204964,
-0.005416065454483032,
0.005687509197741747,
-0.00399514427408576,
-0.00912425946444273,
0.0015384923899546266,
0.0013415248831734061,
-0.009359234012663364,
0.0019529247656464577,
-0.004582274239510298,
0.006194500718265772,
-0.010695715434849262,
-0.004355454817414284,
-0.00391957676038146,
-0.005296734627336264,
0.003027403261512518,
0.012003366835415363,
0.003224278101697564,
0.0029689001385122538,
-0.004454939626157284,
-0.009765060618519783,
0.0005862836260348558,
-0.002618824364617467,
0.0021186191588640213,
0.006214706227183342,
0.0034153165761381388,
-0.01020019594579935,
-0.0016863689525052905,
0.0026766385417431593,
0.002592067699879408,
-0.0010288821067661047,
0.0017392464214935899,
-0.00856902077794075,
0.0050097317434847355,
0.0005338994087651372,
0.004265724215656519,
0.011400404386222363,
-0.003895548637956381,
-0.0007642629207111895,
0.001293417066335678,
0.0008516086963936687,
-0.0014073674101382494,
0.00475690420717001,
0.011102384887635708,
-0.0029089192394167185,
-0.004674845840781927,
0.003386082826182246,
0.00594518193975091,
0.00875080842524767,
0.006377592217177153,
-0.003360625822097063,
0.0017824486130848527,
-0.004366259556263685,
-0.0022213479969650507,
0.006291578058153391,
-0.004239588975906372,
0.0047642942517995834,
0.003712018020451069,
-0.01365591585636139,
-0.009141013026237488,
0.0023762143682688475,
-0.007078405469655991,
0.0017708640079945326,
0.013604248873889446,
0.011350304819643497,
-0.004859833046793938,
0.0017725927755236626,
-0.009059335105121136,
0.001068292884156108,
0.0072136190719902515,
0.002097360324114561,
-0.011927507817745209,
-0.9601300358772278,
0.008331526070833206,
0.002494469517841935,
-0.002014941070228815,
0.005474959500133991,
0.0035224773455411196,
0.004041885957121849,
0.003956078551709652,
0.013665243051946163,
-0.00849585235118866,
-0.00644948473200202,
-0.01194979902356863,
-0.008976669050753117,
-0.0024615551810711622,
-0.008349835872650146,
-0.004021264612674713,
-0.0062574842013418674,
-0.005922761745750904,
-0.002751904772594571,
-0.003454504767432809,
-0.003118549706414342,
0.008267544209957123,
0.0008802851079963148,
0.006104602944105864,
0.003788077039644122,
0.0036464750301092863,
-0.005563776474446058,
-0.0016771834343671799,
-0.0024536768905818462,
-0.0032149606849998236,
-0.00472431443631649,
-0.01574205793440342,
-0.0038502283859997988,
-0.001904296106658876,
0.010883951559662819,
0.0008111894712783396,
0.009265704080462456,
-0.0022273806389421225,
0.0026696287095546722,
-0.008279458619654179,
0.006079073995351791,
-0.0008260107133537531,
0.0017797221662476659,
-0.030119342729449272,
0.0001665145537117496,
0.00003422587542445399,
-0.010099421255290508,
0.006511806044727564,
-0.0016456237062811852,
0.0006087417714297771,
-0.002763883676379919,
-0.005068765953183174,
0.009385809302330017,
-0.005782442167401314,
0.0027271511498838663,
-0.0039962283335626125,
-0.009744369424879551,
-0.002189519116654992,
-0.008179840631783009,
0.0011682595359161496,
0.004432058893144131,
-0.003266514278948307,
-0.004921380430459976,
-0.001986410701647401,
0.0014107037568464875,
0.003606654703617096,
0.0022248246241360903,
-0.019284505397081375,
-0.005107056815177202,
-0.00041064037941396236,
0.0007083615055307746,
-0.00463841762393713,
-0.0035312350373715162,
0.004592827055603266,
-0.00809146836400032,
0.006530126091092825,
0.00238784565590322,
-0.0005424830596894026,
-0.01226149033755064,
0.00045040398254059255,
-0.008820045739412308,
-0.007715003099292517,
0.0009107959922403097,
-0.005241244100034237,
-0.004496172536164522,
-0.0002844840637408197,
0.00010188063606619835,
0.007844322361052036,
-0.004185763653367758,
0.003823624225333333,
0.01200756523758173,
-0.0036421034019440413,
-0.00839877687394619,
0.0061281099915504456,
0.0058936066925525665,
-0.00007785428169881925,
-0.0009339886019006371,
0.004590234253555536,
0.006596850231289864,
0.008901744149625301,
0.0023567776661366224,
0.004956190474331379,
0.00036901995190419257,
0.010339543223381042,
-0.0016813167603686452,
0.0019021129701286554,
-0.002599518047645688,
-0.0016488538822159171,
-0.003974449820816517,
-0.00002922577186836861,
-0.0029146093875169754,
-0.0014696617145091295,
-0.013527773320674896,
-0.007969542406499386,
-0.003026542253792286,
-0.001395422383211553,
0.0037789710331708193,
-0.002697105286642909,
-0.001922187744639814,
0.0022796199191361666,
0.0073722610250115395,
0.0009834119118750095,
-0.0020232354290783405,
-0.0009691130835562944,
0.0029708105139434338,
-0.004534222651273012,
0.01370321772992611,
-0.01144680567085743,
0.006922408007085323,
0.0005318544572219253,
-0.01509836781769991,
0.004635313991457224,
0.009928246028721333,
-0.009377636946737766,
0.0027391836047172546,
0.0045002419501543045,
0.004113960545510054,
-0.0019748907070606947,
-0.004286185372620821,
-0.0031106416136026382,
-0.015322161838412285,
-0.0002161518350476399,
0.01959306001663208,
-0.0006675981567241251,
0.009048773907124996,
0.011186518706381321,
-0.001959372078999877,
0.0014500607503578067,
0.00528891384601593,
0.002286957809701562,
0.01130459364503622,
-0.007699241396039724,
-0.001041268347762525,
0.0017560621490702033,
-0.0053946590051054955,
0.00035063340328633785,
0.006443975958973169,
0.006943435873836279,
-0.0024640506599098444,
0.004094528499990702,
-0.007285779342055321,
-0.004604013171046972,
-0.016338659450411797,
-0.0021697627380490303,
0.006264577154070139,
-0.0048379129730165005,
0.0064835031516849995,
-0.012764825485646725,
0.00529253575950861,
0.007035349030047655,
0.004270205739885569,
0.0002876392682082951,
-0.00025912097771652043,
0.006124779582023621,
0.0117971645668149,
-0.006569229532033205,
0.0021899936255067587,
0.00013651445624418557,
-0.0014698707964271307,
-0.00005268997483653948,
0.007295864634215832,
-0.007028625346720219,
-0.006609010510146618,
0.003182613290846348,
0.005122657865285873,
0.0004685552266892046,
-0.004136600997298956,
-0.006912828888744116,
-0.003590855747461319,
0.0029419539496302605,
-0.0056826528161764145,
0.004478366579860449,
0.0029284278862178326,
0.0029778683092445135,
-0.006931779906153679,
0.00045580705045722425,
-0.0033291480503976345,
-0.013019747100770473,
0.0104058301076293,
-0.0034498965833336115,
0.0037533596623688936,
0.011961068958044052,
0.00419437512755394,
-0.011286281980574131,
0.004000071901828051,
0.008399438112974167,
-0.0031198374927043915,
0.004830508027225733,
0.006405288819223642,
-0.005678819492459297,
-0.02052379585802555,
-0.004004797898232937,
-0.013392928056418896,
0.005174289457499981,
-0.0023582493886351585,
0.005497148260474205,
-0.007522622123360634,
0.007484950590878725,
0.007320648059248924,
-0.014016125351190567,
-0.005346539430320263,
-0.00783118512481451,
0.007490275427699089,
0.0002083685394609347,
0.00030857883393764496,
-0.002902219071984291,
0.0004913451848551631,
-0.003098178654909134,
-0.0037988065741956234,
-0.0025969354901462793,
0.004712115041911602,
0.0020630646031349897,
-0.000729924940969795,
0.002663559978827834,
-0.005221547558903694,
-0.00013495379243977368,
0.0007438663160428405,
-0.009853583760559559,
0.0044420757330954075,
0.0032336066942662,
-0.0028684567660093307,
-0.003902068128809333,
0.0013988108839839697,
-0.0004636113881133497,
-0.007195428013801575,
-0.01113990880548954,
-0.0007781613967381418,
-0.0032937293872237206,
-0.0025674921926110983,
-0.011338436044752598,
-0.0016199720557779074,
-0.007630079984664917,
0.005942281801253557,
-0.007443587761372328,
0.008342129178345203,
0.005855889059603214,
-0.006022839806973934,
0.005836475640535355,
-0.0013850554823875427,
0.004307756666094065,
0.002557413885369897,
0.0052604032680392265,
0.0025001857429742813,
-0.005377639550715685,
-0.011172911152243614,
0.011149952188134193,
-0.006561028305441141,
0.00139766710344702,
0.01188358012586832,
0.0062476336024701595,
0.008421024307608604,
-0.0007614032947458327,
-0.0002034391218330711,
0.001638237270526588,
0.00677471561357379,
-0.014069375582039356,
0.0027167820371687412,
-0.003950013779103756,
0.0009482717141509056,
0.0038202395662665367,
-0.004480248782783747,
0.002644583582878113,
0.009938911534845829,
0.0016506382962688804,
-0.007144308649003506,
-0.0016766503686085343,
0.001117934356443584,
0.004099029581993818,
-0.012233458459377289,
0.0018012005602940917,
-0.00412944657728076,
-0.0035246103070676327,
-0.002860300475731492,
-0.0019798874855041504,
0.000496513326652348,
0.003861207515001297,
-0.0021935920231044292,
0.005986478179693222,
0.001861579017713666,
-0.004966625943779945,
0.015105519443750381,
-0.007529224269092083,
-0.0044304728507995605,
0.003236831398680806,
0.0018458548001945019,
-0.0021052772644907236,
-0.006479541305452585,
-0.002240132773295045,
0.0011054091155529022,
0.006408251356333494,
-0.0030024144798517227,
-0.00397566519677639,
-0.00004953744064550847,
0.0022440198808908463,
-0.010467897169291973,
0.0007886972744017839,
0.012182011269032955,
-0.0042915185913443565,
0.006543624680489302,
-0.0017952783964574337,
-0.008189496584236622,
-0.013734694570302963,
0.052239179611206055,
-0.0012034042738378048,
0.0057193259708583355,
0.0038858361076563597,
-0.006611560005694628,
-0.0010836375877261162,
-0.003879187162965536,
0.006708313245326281,
-0.005874364636838436,
-0.007998852990567684,
0.007257768418639898,
-0.002106467727571726,
0.0049302298575639725,
0.0031187294516712427,
-0.0011522478889673948,
0.015472732484340668,
-0.0033701767679303885,
-0.014971333555877209,
-0.017409367486834526,
0.007983241230249405,
-0.004633036907762289,
-0.0074399178847670555,
0.010752935893833637,
-0.00341984280385077,
-0.004562238696962595,
0.0007813729462213814,
0.006119712721556425,
0.000310543313389644,
-0.00019846871146000922,
-0.0033484087325632572,
-0.0022285175509750843,
-0.0005017107469029725,
0.0026779891923069954,
0.00410716375336051,
0.0070969108492136,
-0.0038533711340278387,
0.0028901665937155485,
-0.001333598862402141,
-0.000863218039739877,
-0.0031880447641015053,
0.004647685214877129,
0.00810861587524414,
-0.0014417641796171665,
-0.00231332890689373,
0.005467453505843878,
0.004639304243028164,
0.0016731212381273508,
0.011033512651920319,
0.0012452566297724843,
-0.006588222924619913,
0.00886545516550541,
0.006061703898012638,
0.0011441124370321631,
0.007550325244665146,
-0.0006921695894561708,
0.005407885182648897,
0.0022826283238828182,
-0.008168221451342106,
-0.018949560821056366,
-0.005411314778029919,
0.0070897904224693775,
0.0075584352016448975,
-0.0011061805998906493,
0.0014804101083427668,
-0.002089566085487604,
-0.0017228111391887069,
-0.006186727900058031,
-0.006788135506212711,
-0.0024984851479530334,
0.0022584223188459873,
0.00513937883079052,
0.06917879730463028,
-0.008400010876357555,
-0.0005253729759715497,
-0.007975400425493717,
-0.0008863198454491794,
-0.0022660994436591864,
0.0005127553595229983,
0.0018650875426828861,
-0.0013902841601520777,
0.0013507569674402475,
-0.0009076189598999918,
-0.007561477832496166,
-0.011915109120309353,
0.0004576533392537385,
0.001950779464095831,
-0.00388473947532475,
0.0035850857384502888,
0.0068092611618340015,
-0.010823158547282219,
0.001538519631139934,
-0.01167005579918623,
-0.0031255350913852453,
-0.0024171045515686274,
-0.010387429036200047,
-0.004986164625734091,
-0.0046210032887756824,
0.005934443324804306,
0.0038561311084777117,
0.007569798268377781,
-0.0031993375159800053,
0.005487620830535889,
-0.0031948955729603767,
-0.000334171432768926,
-0.006020831409841776,
0.00003258331344113685,
-0.004416736774146557,
0.008609237149357796,
0.0030749060679227114,
-0.010952328331768513,
-0.004021113272756338,
0.0009264166583307087,
-0.000746380421333015,
-0.005542417522519827,
0.0024949691724032164,
-0.0012646304676309228,
0.004896783735603094,
-0.0034274982754141092,
-0.0010576618369668722,
-0.007664993871003389,
0.002026504371315241,
-0.012948510237038136,
0.007732650265097618,
-0.16863176226615906,
0.010553337633609772,
0.002837764099240303,
-0.0059220134280622005,
-0.0045825461857020855,
-0.016463490203022957,
-0.00540595268830657,
0.003930066246539354,
0.01001172885298729,
0.0024346867576241493,
-0.0015457486733794212,
-0.0007932374137453735,
0.0050162868574261665,
0.0041392166167497635,
-0.001667482778429985,
-0.005061506759375334,
0.0038761552423238754,
-0.0026749372482299805,
0.0010101128136739135,
0.004287974443286657,
0.0037739824037998915,
0.009004006162285805,
-0.0009084457997232676,
0.002439358038827777,
-0.0017368609551340342,
-0.004619863349944353,
0.006368736270815134,
-0.0015489427605643868,
0.004300722386687994,
-0.011165911331772804,
-0.0036222359631210566,
-0.004850657191127539,
-0.00558894220739603,
0.00023522129049524665,
0.007112697698175907,
-0.00009204769594362006,
0.01002516783773899,
0.002228403463959694,
-0.006583012640476227,
0.007300300523638725,
-0.007856134325265884,
0.02790479175746441,
0.0037863177713006735,
0.006032692268490791,
0.00039260491030290723,
-0.00775752030313015,
-0.006385237909853458,
0.009890705347061157,
0.0020049200393259525,
0.011037573218345642,
-0.01209514681249857,
-0.00005783354208688252,
0.003203009255230427,
0.020350029692053795,
-0.003821113845333457,
-0.009081346914172173,
-0.006732264533638954,
-0.0025730410125106573,
-0.000521104026120156,
0.007208922877907753,
0.009256329387426376,
-0.0030286468099802732,
0.007007867097854614,
-0.0023899755906313658,
-0.020666422322392464,
0.0032645794562995434,
-0.005245815962553024,
-0.004660452250391245,
0.0011437976500019431,
0.0065043228678405285,
0.009034759365022182,
-0.00019487671670503914,
-0.001087407348677516,
-0.0010145005071535707,
0.005329866427928209,
0.00038410467095673084,
0.006340859457850456,
-0.0017852875171229243,
0.005914763547480106,
-0.009477343410253525,
0.006261857226490974,
-0.01104648131877184,
-0.0027186465449631214,
0.0023157382383942604,
-0.004791849758476019,
0.01124375406652689,
0.0033675122540444136,
-0.0017789897974580526,
-0.00045245178625918925,
-0.009765855967998505,
-0.0034126436803489923,
0.001023529446683824,
0.0009750701719895005,
-0.008278150111436844,
0.003567451611161232,
0.0023871581070125103,
0.0038341586478054523,
0.005162417888641357,
-0.010796479880809784,
0.006267121527343988,
0.005556284915655851,
-0.005418538115918636,
0.0016996670747175813,
-0.00564111303538084,
0.00020191505609545857,
0.0038085468113422394,
-0.0055702761746943,
-0.0056730471551418304,
0.002861712360754609,
-0.007262181956321001,
-0.004264841787517071,
0.005158514715731144,
-0.008221544325351715,
-0.008654403500258923,
-0.001808507484383881,
-0.00938736367970705,
0.0003037233545910567
] |
8a37a73802d1db18a333fdc568416dbf6367829d | 3,658 | py | Python | unwind.py | 0x1F9F1/binja-msvc | be2577c22c8d37fd1e2e211f80b1c9a920705bd2 | [
"MIT"
] | 9 | 2019-02-08T10:01:39.000Z | 2021-04-29T12:27:34.000Z | unwind.py | DatBrick/binja-msvc | 751ffc1450c569bad23ac67a761d0f1fbd4ca4c4 | [
"MIT"
] | 1 | 2019-07-04T20:09:57.000Z | 2019-07-12T11:10:15.000Z | unwind.py | DatBrick/binja-msvc | 751ffc1450c569bad23ac67a761d0f1fbd4ca4c4 | [
"MIT"
] | 2 | 2019-03-03T13:00:14.000Z | 2020-05-01T05:35:04.000Z | from binaryninja import log
from .utils import BinjaStruct, read_pe_header, split_bits, update_percentage
# https://msdn.microsoft.com/en-us/library/ft9x1kdx.aspx
RUNTIME_FUNCTION_t = BinjaStruct('<III', names = ('BeginAddress', 'EndAddress', 'UnwindData'))
def read_runtime_function(view, address):
runtime_function, address = RUNTIME_FUNCTION_t.read(view, address, 4)
if runtime_function is not None:
runtime_function['BeginAddress'] += view.start
runtime_function['EndAddress'] += view.start
runtime_function['UnwindData'] += view.start
return runtime_function, address
UNWIND_INFO_t = BinjaStruct('<BBBB', names = ('VersionAndFlags', 'SizeOfProlog', 'CountOfCodes', 'FrameRegisterAndOffset'))
UNW_FLAG_NHANDLER = 0x0
UNW_FLAG_EHANDLER = 0x1
UNW_FLAG_UHANDLER = 0x2
UNW_FLAG_FHANDLER = 0x3
UNW_FLAG_CHAININFO = 0x4
def read_unwind_info(view, address):
unwind_info, address = UNWIND_INFO_t.read(view, address)
if unwind_info is not None:
split_bits(unwind_info, 'VersionAndFlags', [
('Version', 0, 3),
('Flags', 3, 5)
])
split_bits(unwind_info, 'FrameRegisterAndOffset', [
('FrameRegister', 0, 4),
('FrameOffset', 4, 4)
])
if unwind_info['Version'] == 1:
unwind_codes = [ ]
for i in range(unwind_info['CountOfCodes']):
unwind_code, address = read_unwind_code(view, address)
unwind_codes.append(unwind_code)
unwind_info['UnwindCodes'] = unwind_codes
if unwind_info['Flags'] & UNW_FLAG_CHAININFO:
unwind_info['FunctionEntry'], address = read_runtime_function(view, address)
return unwind_info, address
UNWIND_CODE_t = BinjaStruct('<BB', names = ('CodeOffset', 'UnwindOpAndInfo'))
def read_unwind_code(view, address):
unwind_code, address = UNWIND_CODE_t.read(view, address)
if unwind_code is not None:
split_bits(unwind_code, 'UnwindOpAndInfo', [
('UnwindOp', 0, 4),
('OpInfo', 4, 4)
])
return unwind_code, address
def parse_unwind_info(thread, view):
base_address = view.start
pe = read_pe_header(view)
unwind_directory = pe.OPTIONAL_HEADER.DATA_DIRECTORY[3]
unwind_entrys = base_address + unwind_directory.VirtualAddress
unwind_entrys_end = unwind_entrys + unwind_directory.Size
funcs = set()
log.log_info('Exception Data @ 0x{0:X} => 0x{1:X}'.format(unwind_entrys, unwind_entrys_end))
for runtime_address in range(unwind_entrys, unwind_entrys_end, 12):
if thread.cancelled:
break
update_percentage(thread, unwind_entrys, unwind_entrys_end, runtime_address, 'Parsing Unwind Info - Found {0} functions'.format(len(funcs)))
runtime_function, _ = read_runtime_function(view, runtime_address)
if runtime_function is None:
continue
start_address = runtime_function['BeginAddress']
if not view.is_offset_executable(start_address):
continue
if view.get_functions_containing(start_address):
continue
info_address = runtime_function['UnwindData']
unwind_info, _ = read_unwind_info(view, info_address)
if unwind_info is None:
continue
if 'FunctionEntry' in unwind_info:
continue
funcs.add(start_address)
if not thread.cancelled:
thread.progress = 'Creating {0} Function'.format(len(funcs))
log.log_info('Found {0} functions'.format(len(funcs)))
for func in funcs:
view.create_user_function(func)
| 31 | 148 | 0.667578 | 1 | 1.9551 | [
-0.0353490374982357,
0.028436999768018723,
0.01276386622339487,
0.0004639436665456742,
0.011570177972316742,
-0.006514573935419321,
-0.04695755988359451,
-0.0049865334294736385,
0.0041400594636797905,
0.020535869523882866,
-0.0026442683301866055,
-0.02134213224053383,
-0.00558666605502367,
-0.024184538051486015,
-0.024461327120661736,
-0.0341314934194088,
0.11242692172527313,
-0.011095462366938591,
-0.032594893127679825,
0.011972460895776749,
0.03164256364107132,
0.04078521579504013,
-0.037293940782547,
0.0031185788102447987,
0.012850696220993996,
-0.013760032132267952,
0.03630499541759491,
-0.016090357676148415,
0.04256516322493553,
0.02957633137702942,
0.04285108670592308,
0.044539857655763626,
-0.020354587584733963,
0.03719526529312134,
-0.03859112784266472,
0.02079869620501995,
0.0013491662684828043,
0.0771874338388443,
0.03537696972489357,
0.01572495698928833,
0.010066401213407516,
0.016324182972311974,
-0.02030002325773239,
-0.009310002438724041,
0.007203448563814163,
-0.044536277651786804,
0.02214628830552101,
0.010326837189495564,
-0.0673585832118988,
0.020805610343813896,
0.05156710743904114,
0.07189106941223145,
-0.010184305720031261,
-0.014684458263218403,
0.044717367738485336,
-0.0017424345714971423,
0.00894766952842474,
-0.07327767461538315,
-0.040289051830768585,
-0.013151000253856182,
-0.027975093573331833,
-0.009554983116686344,
0.032916534692049026,
-0.026204023510217667,
0.04889878258109093,
0.016723357141017914,
-0.02339663729071617,
0.00974319875240326,
0.059544019401073456,
0.015487296506762505,
-0.008706534281373024,
-0.019594283774495125,
-0.014400104060769081,
0.06553980708122253,
0.019985690712928772,
-0.029117681086063385,
-0.0168029572814703,
-0.019112296402454376,
-0.002217754488810897,
-0.04665562883019447,
-0.01166156679391861,
0.022480135783553123,
0.005679481662809849,
-0.004729966167360544,
0.0024886024184525013,
-0.007683298084884882,
0.08374891430139542,
-0.03391367942094803,
0.06563757359981537,
0.023990105837583542,
-0.028333241119980812,
0.010203080251812935,
-0.028924860060214996,
-0.028656940907239914,
-0.03428925946354866,
-0.04445626214146614,
-0.010535953566432,
0.008502103388309479,
-0.021957717835903168,
0.012782154604792595,
0.05017760023474693,
-0.06651923060417175,
0.028519796207547188,
0.0029982554260641336,
-0.0038664317689836025,
0.04503335803747177,
-0.05036315694451332,
-0.025071604177355766,
-0.01070522889494896,
0.0006984322681091726,
-0.02276492863893509,
0.023772364482283592,
0.006963018327951431,
-0.022995131090283394,
-0.01653801091015339,
-0.03282943367958069,
0.02816646918654442,
0.016194194555282593,
-0.0014797229086980224,
-0.01599027030169964,
0.02760804444551468,
0.03783629462122917,
0.011321309953927994,
0.005420241039246321,
-0.03717844560742378,
0.060554955154657364,
0.008397269062697887,
-0.005003911908715963,
0.0023942715488374233,
-0.00839605275541544,
-0.007981011644005775,
0.013127937912940979,
-0.016181349754333496,
-0.000053875293815508485,
0.036274492740631104,
0.0017316165613010526,
0.02952626347541809,
-0.007670952007174492,
-0.05377267673611641,
-0.008296954445540905,
0.008822597563266754,
-0.0050632525235414505,
0.02631140872836113,
-0.005717447027564049,
0.020859768614172935,
-0.012763419188559055,
0.001247402629815042,
0.0037438017316162586,
0.01266375370323658,
-0.01589161716401577,
0.020875032991170883,
0.008359657600522041,
-0.0172872394323349,
0.040284767746925354,
-0.005899316631257534,
0.012020878493785858,
0.03358179330825806,
-0.08954726159572601,
-0.05187787488102913,
0.029004409909248352,
-0.026328429579734802,
0.026844413951039314,
0.0081891855224967,
-0.017563965171575546,
0.035785868763923645,
-0.005039718002080917,
0.005057633388787508,
-0.011782200075685978,
-0.034743908792734146,
0.0025123367086052895,
0.01850942336022854,
-0.007538544479757547,
-0.013788093812763691,
-0.009693342261016369,
0.009059185162186623,
-0.03750694915652275,
-0.019689051434397697,
0.022548962384462357,
0.022486377507448196,
-0.024760855361819267,
0.05708964541554451,
-0.0027514174580574036,
-0.009397465735673904,
-0.010949773713946342,
-0.00028998067136853933,
0.03035535104572773,
-0.029301868751645088,
0.03786845877766609,
0.00597872631624341,
0.022998735308647156,
-0.0024437515530735254,
0.0383274145424366,
-0.012829750776290894,
-0.00025375233963131905,
-0.01048551220446825,
0.005398338660597801,
-0.0010312781669199467,
-0.004483894910663366,
0.011119705624878407,
0.03185097128152847,
-0.03779567405581474,
-0.025517050176858902,
-0.02666660025715828,
0.008507654070854187,
0.0031093736179172993,
-0.01185243297368288,
-0.6229362487792969,
0.08312470465898514,
-0.05004375800490379,
-0.017827965319156647,
-0.030703553929924965,
-0.022810282185673714,
-0.025807056576013565,
0.03841710090637207,
-0.034421760588884354,
-0.013552741147577763,
-0.0028587060514837503,
-0.02819635160267353,
-0.051141466945409775,
-0.0026107158046215773,
0.04387764632701874,
-0.02459479309618473,
-0.01635153591632843,
0.007281073834747076,
-0.01597139798104763,
0.011475348845124245,
0.03183296322822571,
-0.016400177031755447,
0.016130438074469566,
0.0022475237492471933,
0.03557102382183075,
0.01889839768409729,
-0.006232657004147768,
0.00394847895950079,
-0.03762534260749817,
0.06720893830060959,
-0.0371406115591526,
-0.019661670550704002,
0.021955456584692,
-0.007889109663665295,
-0.013366135768592358,
0.005083853844553232,
0.032318733632564545,
-0.054119039326906204,
-0.002792770741507411,
-0.015036162920296192,
-0.043483175337314606,
0.02057793363928795,
0.003581797005608678,
-0.05686059594154358,
-0.027490930631756783,
-0.029330139979720116,
-0.0006402971339412034,
-0.014987939037382603,
-0.0003405245079193264,
0.008799577131867409,
-0.06040998548269272,
-0.021128574386239052,
0.0005747555987909436,
-0.054654210805892944,
0.04555168002843857,
0.03550682216882706,
-0.03326840698719025,
-0.006264847237616777,
0.016133077442646027,
0.008828726597130299,
0.03297720476984978,
-0.003442382672801614,
0.028074081987142563,
-0.02306661382317543,
-0.025609802454710007,
0.0068785659968853,
0.018803775310516357,
-0.0021303200628608465,
-0.018450841307640076,
0.03317690268158913,
0.01715519092977047,
0.047951407730579376,
-0.03966999799013138,
-0.003561844350770116,
0.0016673647332936525,
-0.015043176710605621,
-0.006765308324247599,
-0.023015903308987617,
0.0014810123248025775,
-0.006781552452594042,
0.013861196115612984,
-0.01595098152756691,
-0.010175113566219807,
-0.04363962635397911,
-0.028067180886864662,
-0.005493666511029005,
-0.008658895269036293,
0.035894572734832764,
-0.02726435661315918,
0.025529446080327034,
0.03035249188542366,
0.04297465831041336,
0.012479056604206562,
0.01089923083782196,
0.02718067727982998,
0.036766715347766876,
0.02228587493300438,
0.05296952649950981,
0.005689208395779133,
0.01624494045972824,
-0.029281223192811012,
0.026126625016331673,
0.016906624659895897,
0.025269165635108948,
0.02315790206193924,
-0.0030845394358038902,
-0.061374567449092865,
-0.008831104263663292,
0.06741780787706375,
-0.005576771683990955,
0.020887846127152443,
0.00963657908141613,
0.012943267822265625,
0.0029956481885164976,
0.019789230078458786,
-0.047168388962745667,
-0.01065142173320055,
-0.019111230969429016,
0.04516608640551567,
-0.008888660930097103,
-0.042433690279722214,
0.033459946513175964,
0.0010308623313903809,
-0.011957112699747086,
0.007236004341393709,
-0.02336849272251129,
-0.03768002614378929,
-0.0030582996550947428,
0.0023200474679470062,
0.03190438076853752,
-0.01051455456763506,
-0.038630079478025436,
0.008282437920570374,
-0.01591382548213005,
-0.0024753573816269636,
0.03240947797894478,
-0.02567010372877121,
-0.022112345322966576,
0.017912739887833595,
0.0015429984778165817,
0.010337168350815773,
0.000931723800022155,
0.05380483344197273,
-0.01970970444381237,
0.001021757023409009,
0.040994998067617416,
0.005938299465924501,
0.008702347055077553,
0.004731847904622555,
-0.03578168526291847,
-0.02199343778192997,
0.024212444201111794,
-0.03240855783224106,
0.0165726188570261,
-0.04103199765086174,
-0.015118297189474106,
-0.046870265156030655,
-0.004052149597555399,
0.007440602872520685,
0.018812183290719986,
-0.016210561618208885,
-0.0025689289905130863,
-0.01398610882461071,
-0.0032122815027832985,
0.02191552147269249,
-0.01036218460649252,
-0.0057843150570988655,
0.013899071142077446,
0.02188776433467865,
-0.009719868190586567,
0.004939411301165819,
-0.014715636149048805,
0.011578363366425037,
0.026271754875779152,
0.0008594146929681301,
0.0352795347571373,
0.0023261946626007557,
-0.06441354751586914,
0.0058316923677921295,
-0.010745461098849773,
-0.06817920506000519,
-0.002999851480126381,
-0.005983132869005203,
-0.04397440701723099,
0.02923739328980446,
0.061460692435503006,
-0.03531581535935402,
0.0038472504820674658,
0.008971897885203362,
0.001078508561477065,
0.039672497659921646,
-0.03583697974681854,
0.0007727310294285417,
-0.03402426093816757,
-0.02710885927081108,
-0.0013329817447811365,
-0.0061279297806322575,
-0.0350310318171978,
0.006551598664373159,
-0.016811512410640717,
0.012515038251876831,
0.08792547136545181,
0.022102421149611473,
-0.025763999670743942,
0.006076492834836245,
0.057349711656570435,
0.01655297540128231,
0.0009116727160289884,
-0.04534297063946724,
0.013788482174277306,
-0.006446168292313814,
-0.012939045205712318,
0.027611644938588142,
-0.010497071780264378,
-0.056111954152584076,
-0.013125940226018429,
-0.029728775843977928,
-0.0075612436048686504,
0.02002647891640663,
0.0007033328874967992,
-0.027256542816758156,
0.0067634969018399715,
-0.011616259813308716,
0.0056185428984463215,
-0.006249884143471718,
-0.0002304142981301993,
-0.011732785031199455,
-0.013715352863073349,
-0.005209812894463539,
0.01306279469281435,
0.03391363099217415,
-0.018978746607899666,
-0.05390890687704086,
-0.0183537770062685,
0.0035379992332309484,
-0.006225451827049255,
0.022256838157773018,
-0.06772538274526596,
0.011570191010832787,
-0.020109442993998528,
0.0005689961835741997,
-0.04952726140618324,
0.01585124060511589,
-0.02350744418799877,
-0.024942444637417793,
0.003618272952735424,
0.00020987156312912703,
-0.006541248876601458,
-0.002841806039214134,
-0.016355548053979874,
-0.014853234402835369,
0.08448586612939835,
0.0296782273799181,
0.013934814371168613,
0.02772960066795349,
-0.05722552165389061,
-0.006932885851711035,
0.038775645196437836,
-0.003438025014474988,
-0.02483144961297512,
-0.013756830245256424,
-0.05130702257156372,
0.040954623371362686,
-0.0014405971160158515,
-0.0239435825496912,
0.013035674579441547,
-0.022037323564291,
-0.03243235498666763,
-0.02545815519988537,
0.017254717648029327,
0.010609608143568039,
-0.024330897256731987,
-0.016541017219424248,
-0.019075749441981316,
0.030956529080867767,
0.005612516775727272,
0.007148189935833216,
0.0031116532627493143,
-0.03147410228848457,
0.044322360306978226,
-0.010326179675757885,
0.022340677678585052,
0.010214684531092644,
0.012228405103087425,
0.037049952894449234,
0.035824213176965714,
-0.022316191345453262,
-0.006718610413372517,
-0.012043338268995285,
0.027007902041077614,
-0.010143070481717587,
-0.03986825421452522,
0.04471364989876747,
0.04824018105864525,
0.012713340111076832,
0.017731592059135437,
0.025876643136143684,
0.019067397341132164,
0.010441497899591923,
-0.043815385550260544,
0.0468849316239357,
-0.02409118413925171,
-0.04767780005931854,
0.03930412232875824,
0.0008993863593786955,
-0.011414065025746822,
0.005377264693379402,
-0.02011125534772873,
0.0534215047955513,
0.028345121070742607,
0.03026888146996498,
0.022456225007772446,
0.008759577758610249,
0.010204385034739971,
-0.006267735734581947,
0.0015886061592027545,
0.041193537414073944,
-0.01814148761332035,
0.011064153164625168,
0.009905370883643627,
-0.0503963939845562,
0.013013789430260658,
-0.02452978491783142,
-0.01934259943664074,
0.002919708611443639,
-0.02315196953713894,
-0.031257811933755875,
-0.022153960540890694,
0.056803569197654724,
0.007967229001224041,
0.0291528832167387,
0.02884294092655182,
-0.004083484411239624,
0.004817041102796793,
-0.04013039544224739,
-0.022878658026456833,
0.015584932640194893,
0.008933252654969692,
-0.017856240272521973,
0.0156309362500906,
0.022945886477828026,
0.0013391077518463135,
-0.04668298363685608,
-0.054025501012802124,
-0.007254611235111952,
-0.0017559992847964168,
-0.032803989946842194,
0.05030679702758789,
0.040009863674640656,
0.02327779307961464,
0.007235469296574593,
0.008167760446667671,
-0.006534955929964781,
-0.033871863037347794,
0.019194919615983963,
-0.013980258256196976,
-0.008441186510026455,
-0.014628713950514793,
0.014777076430618763,
0.002774821361526847,
-0.05849232152104378,
-0.0011090671177953482,
-0.047415897250175476,
0.0025796766858547926,
-0.01485116221010685,
-0.04846963286399841,
0.027475504204630852,
0.015750059857964516,
0.0011034655617550015,
0.01280405092984438,
-0.0355987474322319,
-0.018687482923269272,
0.0028845123015344143,
0.028816664591431618,
0.01801150105893612,
0.019159367308020592,
0.0278837401419878,
0.03805021196603775,
0.001896349131129682,
-0.029738854616880417,
-0.010127678513526917,
-0.01261450257152319,
0.04685045778751373,
-0.016103308647871017,
0.005795164033770561,
-0.04879693686962128,
-0.02273808792233467,
0.0238813403993845,
-0.0320650078356266,
-0.055797725915908813,
0.0031355321407318115,
0.05422132834792137,
0.020662821829319,
0.02738315612077713,
0.003935572691261768,
0.02423623763024807,
-0.02770722471177578,
-0.005341593641787767,
0.031282197684049606,
-0.00714422482997179,
0.005456764716655016,
-0.018462976440787315,
-0.005958579946309328,
-0.00010480668424861506,
-0.03286680579185486,
-0.004174009896814823,
0.02689097821712494,
0.008192134089767933,
-0.00693541020154953,
0.025970986112952232,
-0.022106418386101723,
0.025348642840981483,
-0.02815994620323181,
-0.03463144227862358,
0.023169539868831635,
0.026870369911193848,
-0.03656632825732231,
-0.01564445160329342,
-0.008947798982262611,
0.010597891174256802,
0.004359537735581398,
-0.03511856868863106,
-0.025661036372184753,
-0.013204386457800865,
0.003986182622611523,
0.01821998879313469,
-0.009065407328307629,
-0.020600659772753716,
0.030615517869591713,
0.027668306604027748,
-0.02316856198012829,
-0.06912989169359207,
0.020780591294169426,
0.01980324275791645,
0.012665458023548126,
-0.01148297544568777,
0.022224582731723785,
-0.007113320287317038,
0.030942820012569427,
0.003720024833455682,
0.025733888149261475,
-0.017947031185030937,
-0.013896715827286243,
-0.003372691571712494,
0.00467684818431735,
-0.11274520307779312,
0.026660051196813583,
0.015335485339164734,
-0.01645553670823574,
-0.02147052250802517,
-0.020738162100315094,
0.026104554533958435,
0.00693924818187952,
-0.02925609052181244,
-0.0009059287258423865,
0.004635921213775873,
0.09267742186784744,
-0.007945891469717026,
0.04134499654173851,
0.02499447949230671,
-0.01884014718234539,
0.013331272639334202,
-0.0024371242616325617,
-0.018956700339913368,
0.031564176082611084,
0.00947482232004404,
0.01628689654171467,
-0.0009399872506037354,
0.0218614861369133,
0.011648179031908512,
0.00630050478503108,
0.026881245896220207,
-0.07317239046096802,
0.018450764939188957,
-0.0031339582055807114,
-0.02566346526145935,
-0.013477327302098274,
-0.036879319697618484,
-0.024126775562763214,
0.032919034361839294,
-0.018535776063799858,
0.0034602892119437456,
0.05103887990117073,
-0.02735225297510624,
0.02917695790529251,
0.042301155626773834,
-0.003680513007566333,
-0.046959444880485535,
-0.005532548762857914,
0.029402362182736397,
-0.04121095687150955,
-0.011611524038016796,
0.000803144765086472,
0.007161175366491079,
-0.02482706494629383,
-0.04524395987391472,
0.04092729091644287,
-0.020522385835647583,
0.052213381975889206,
-0.023699233308434486,
0.033310651779174805,
-0.0027407645247876644,
0.04975388944149017,
-0.02369595877826214,
0.019285663962364197,
0.015459044836461544,
0.02955528162419796,
0.0008109095506370068,
-0.005159439519047737,
-0.012175553478300571,
0.012201580218970776,
-0.039143312722444534,
0.02059955894947052,
-0.06820318102836609,
0.006984636187553406,
0.002769307466223836,
0.035151414573192596,
-0.02239971235394478,
-0.011456904001533985,
0.0022086896933615208,
0.012509015388786793,
0.02965184487402439,
-0.017311353236436844,
-0.021301619708538055,
-0.01370795164257288,
0.017264558002352715,
-0.06356627494096756,
0.06273820251226425,
0.0167918112128973,
-0.018675656989216805,
-0.026181884109973907,
-0.03445437550544739,
-0.0032964993733912706,
-0.012511810287833214,
-0.02778923697769642,
-0.01602075807750225,
0.0010249154875054955,
0.04807190224528313,
-0.059350330382585526,
0.014126232825219631,
-0.0167891476303339,
0.019229261204600334,
-0.009755721315741539,
-0.0168752521276474,
-0.013168646022677422,
-0.023107532411813736,
-0.013493712991476059,
0.044781338423490524,
-0.006765476427972317,
-0.010914681479334831,
-0.02199913188815117,
0.004801368340849876,
-0.04311255365610123,
0.020483126863837242,
-0.003445238107815385,
0.03322445973753929,
-0.009113483130931854,
-0.013631301932036877,
0.004170328378677368,
-0.04094661772251129,
0.0009021263103932142,
0.017672749236226082
] |
8a37f39c3ffc420ffcb4173ab24c22f5ec606276 | 2,538 | py | Python | pixloc/visualization/viz_3d.py | jmorlana/pixloc | 90f7e968398252e8557b284803ee774cb8d80cd0 | [
"Apache-2.0"
] | 457 | 2021-03-17T00:39:33.000Z | 2022-03-30T02:38:19.000Z | pixloc/visualization/viz_3d.py | jmorlana/pixloc | 90f7e968398252e8557b284803ee774cb8d80cd0 | [
"Apache-2.0"
] | 31 | 2021-03-17T07:35:34.000Z | 2022-03-31T07:07:56.000Z | pixloc/visualization/viz_3d.py | jmorlana/pixloc | 90f7e968398252e8557b284803ee774cb8d80cd0 | [
"Apache-2.0"
] | 56 | 2021-03-17T05:55:09.000Z | 2022-03-15T01:38:35.000Z | """
3D visualization primitives based on Plotly.
We might want to instead use a more powerful library like Open3D.
Plotly however supports animations, buttons and sliders.
1) Initialize a figure with `fig = init_figure()`
2) Plot points, cameras, lines, or create a slider animation.
3) Call `fig.show()` to render the figure.
"""
import plotly.graph_objects as go
import numpy as np
from ..pixlib.geometry.utils import to_homogeneous
def init_figure(height=800):
"""Initialize a 3D figure."""
fig = go.Figure()
fig.update_layout(
height=height,
scene_camera=dict(
eye=dict(x=0., y=-.1, z=-2), up=dict(x=0, y=-1., z=0)),
scene=dict(
xaxis=dict(showbackground=False),
yaxis=dict(showbackground=False),
aspectmode='data', dragmode='orbit'),
margin=dict(l=0, r=0, b=0, t=0, pad=0)) # noqa E741
return fig
def plot_points(fig, pts, color='rgba(255, 0, 0, 1)', ps=2):
"""Plot a set of 3D points."""
x, y, z = pts.T
tr = go.Scatter3d(
x=x, y=y, z=z, mode='markers', marker_size=ps,
marker_color=color, marker_line_width=.2)
fig.add_trace(tr)
def plot_camera(fig, R, t, K, color='rgb(0, 0, 255)'):
"""Plot a camera as a cone with camera frustum."""
x, y, z = t
u, v, w = R @ -np.array([0, 0, 1])
tr = go.Cone(
x=[x], y=[y], z=[z], u=[u], v=[v], w=[w], anchor='tip',
showscale=False, colorscale=[[0, color], [1, color]],
sizemode='absolute')
fig.add_trace(tr)
W, H = K[0, 2]*2, K[1, 2]*2
corners = np.array([[0, 0], [W, 0], [W, H], [0, H], [0, 0]])
corners = to_homogeneous(corners) @ np.linalg.inv(K).T
corners = (corners/2) @ R.T + t
x, y, z = corners.T
tr = go.Scatter3d(
x=x, y=y, z=z, line=dict(color='rgba(0, 0, 0, .5)'),
marker=dict(size=0.0001), showlegend=False)
fig.add_trace(tr)
def create_slider_animation(fig, traces):
"""Create a slider that animates a list of traces (e.g. 3D points)."""
slider = {'steps': []}
frames = []
fig.add_trace(traces[0])
idx = len(fig.data) - 1
for i, tr in enumerate(traces):
frames.append(go.Frame(name=str(i), traces=[idx], data=[tr]))
step = {"args": [
[str(i)],
{"frame": {"redraw": True},
"mode": "immediate"}],
"label": i,
"method": "animate"}
slider['steps'].append(step)
fig.frames = tuple(frames)
fig.layout.sliders = (slider,)
| 32.126582 | 74 | 0.566982 | 1 | 1.7706 | [
0.0025226331781595945,
0.024211755022406578,
0.0073385825380682945,
-0.0009367569000460207,
0.005180307663977146,
-0.0017572779906913638,
-0.007352424785494804,
0.0023576300591230392,
-0.0073997038416564465,
0.0033416668884456158,
0.0033904698211699724,
0.004341313149780035,
0.00874587893486023,
-0.018302828073501587,
-0.001218667021021247,
0.014241308905184269,
-0.04846162348985672,
-0.0002664367202669382,
-0.0032631654758006334,
0.0010727331973612309,
-0.008527477271854877,
0.01059507206082344,
0.009089619852602482,
0.007019991986453533,
0.0064345719292759895,
-0.0017411309527233243,
0.009478730149567127,
0.0010517742484807968,
-0.009091993793845177,
-0.007142156828194857,
-0.0017598924459889531,
-0.001069625373929739,
-0.005560640711337328,
-0.007727570366114378,
0.005508175119757652,
-0.0025484999641776085,
-0.0027566934004426003,
-0.019977284595370293,
0.012320112437009811,
-0.0046296194195747375,
-0.005662050563842058,
-0.014572620391845703,
0.002283587818965316,
0.004346788860857487,
-0.010161013342440128,
0.0009390253690071404,
-0.0038972380571067333,
0.001930523430928588,
-0.01170408632606268,
0.0081015694886446,
-0.009266291745007038,
0.0047626253217458725,
0.0144082335755229,
0.0031160484068095684,
-0.004972259048372507,
-0.00540961092337966,
0.014033668674528599,
0.00024994174600578845,
-0.011673644185066223,
-0.0014869293663650751,
-0.002067280700430274,
-0.0031469380483031273,
0.003775304649025202,
0.00282578868791461,
-0.015031439252197742,
-0.007378563284873962,
-0.005654791835695505,
0.0038602810818701982,
0.0004036759492009878,
0.0059462920762598515,
0.0022094843443483114,
-0.0010791352251544595,
0.007037070579826832,
0.003992212470620871,
0.0052055357955396175,
-0.006387917324900627,
-0.0011581829749047756,
-0.0007739874417893589,
0.008896160870790482,
0.004574227146804333,
0.0034742639400064945,
-0.005637496244162321,
0.004515205044299364,
0.010477966628968716,
0.012206174433231354,
0.008325029164552689,
0.018747298046946526,
-0.01202938798815012,
0.0472986064851284,
0.008240836672484875,
-0.00960531085729599,
0.0014008153229951859,
-0.011392669752240181,
-0.0023185419850051403,
-0.003683227812871337,
-0.026848874986171722,
0.00042373023461550474,
-0.003087757620960474,
0.0007781392778269947,
0.001689335098490119,
-0.0003480639716144651,
0.008052636869251728,
-0.0026152951177209616,
-0.0019075301242992282,
-0.009363282471895218,
0.009075910784304142,
-0.007506575435400009,
-0.0033009073231369257,
0.008679823949933052,
0.0026288137305527925,
-0.009675885550677776,
-0.001615909393876791,
0.0006268772995099425,
-0.014820866286754608,
0.0028692560736089945,
0.0019297872204333544,
-0.007288155145943165,
0.05508476123213768,
-0.0009108901722356677,
0.0018533022375777364,
-0.005145875737071037,
0.0007407823577523232,
0.0024887833278626204,
0.0071351840160787106,
0.009756031446158886,
-0.0022071413695812225,
0.011770404875278473,
0.009679755195975304,
0.005097400862723589,
0.007708429358899593,
-0.002788868732750416,
0.006709784734994173,
-0.004735090769827366,
-0.0027549273800104856,
0.0010166359134018421,
-0.007889576256275177,
0.007360139396041632,
-0.00130196544341743,
-0.008362405933439732,
0.0006805381854064763,
-0.002015904290601611,
-0.010896207764744759,
0.00046611286234110594,
-0.004753627814352512,
0.004024381749331951,
-0.010975453071296215,
-0.0023658846039325,
-0.0037862861063331366,
-0.004014445468783379,
0.0026840369682759047,
0.01065913774073124,
0.0034552819561213255,
0.002366654109209776,
-0.005355100147426128,
-0.009960649535059929,
-0.0010413905838504434,
-0.005881258752197027,
0.0015543163754045963,
0.008116558194160461,
0.0028891100082546473,
-0.011229021474719048,
0.0010781039018183947,
0.0023863953538239002,
0.0029777868185192347,
-0.002265340881422162,
0.0056860437616705894,
-0.007681748364120722,
0.007806338369846344,
0.00010231689520878717,
0.003028937615454197,
0.012888453900814056,
-0.005612100474536419,
-0.000022729513148078695,
-0.0006395545788109303,
0.0013249313924461603,
-0.0005413483595475554,
0.0048902262933552265,
0.010615993291139603,
-0.002097217133268714,
-0.005320281255990267,
0.00513124093413353,
0.0036924094893038273,
0.008485482074320316,
0.004904909059405327,
-0.004675219301134348,
0.002312063006684184,
-0.004697403870522976,
-0.0013498691841959953,
0.008658875711262226,
-0.005004493519663811,
0.0049338084645569324,
0.004345790017396212,
-0.013394910842180252,
-0.01032626535743475,
-0.0020070215687155724,
-0.007246641907840967,
0.0015339963138103485,
0.01609889604151249,
0.010734331794083118,
-0.0025990591384470463,
0.002075167838484049,
-0.010978462174534798,
0.0012724495027214289,
0.00836749654263258,
0.002053536707535386,
-0.012027670629322529,
-0.9580027461051941,
0.005413164850324392,
0.004663319792598486,
-0.002516437554731965,
0.006272377446293831,
0.004524922464042902,
0.0035583865828812122,
0.003543527564033866,
0.013933737762272358,
-0.006519347429275513,
-0.0044531794264912605,
-0.011438257060945034,
-0.010250994004309177,
-0.0008535293745808303,
-0.007932928390800953,
-0.006213207729160786,
-0.006485769059509039,
-0.006095887161791325,
-0.0027043544687330723,
-0.0034638617653399706,
-0.0028265465516597033,
0.009101723320782185,
0.00017471595492679626,
0.0048155407421290874,
0.0037206269335001707,
0.004265910945832729,
-0.004031213466078043,
-0.001074982457794249,
-0.0033687485847622156,
-0.0021740742959082127,
-0.0058754319325089455,
-0.01419578492641449,
-0.0023609488271176815,
-0.002121208468452096,
0.009337089024484158,
0.0004824097268283367,
0.008982493542134762,
-0.0021389795001596212,
0.002681896323338151,
-0.0069322227500379086,
0.004430868662893772,
0.0006443590973503888,
0.0025526550598442554,
-0.030684977769851685,
-0.001648899051360786,
0.0002592274686321616,
-0.010263551026582718,
0.006985552608966827,
0.0009315244387835264,
0.0013001002371311188,
-0.0024484908208251,
-0.005163857247680426,
0.008821559138596058,
-0.006146360654383898,
0.004503389820456505,
-0.004540097899734974,
-0.008208083920180798,
-0.0012458872515708208,
-0.00809963047504425,
0.0024762486573308706,
0.005156735889613628,
-0.005780745297670364,
-0.004487471655011177,
-0.0019555543549358845,
0.004399230238050222,
0.0021563535556197166,
0.0013110741274431348,
-0.021062536165118217,
-0.007612899877130985,
0.0005929233739152551,
0.0020106832962483168,
-0.002732326043769717,
-0.003890065476298332,
0.004253110848367214,
-0.009738358668982983,
0.006733329966664314,
-0.001053789397701621,
0.0013133941683918238,
-0.011789059266448021,
-0.0010061837965622544,
-0.008676051162183285,
-0.007987854070961475,
0.002947897184640169,
-0.003059477312490344,
-0.005255172960460186,
-0.0001705058675725013,
-0.00007639198884135112,
0.009523059241473675,
-0.005518114194273949,
0.0029955559875816107,
0.011562532745301723,
-0.0004990161978639662,
-0.008149296045303345,
0.007423574570566416,
0.005914738401770592,
0.0011999787529930472,
-0.003652942832559347,
0.0020193299278616905,
0.007999562658369541,
0.008823486976325512,
0.0018549924716353416,
0.00514420960098505,
-0.000015128400264075026,
0.011524636298418045,
-0.00008964540757006034,
0.0014457651413977146,
-0.0027797692455351353,
0.00038581376429647207,
-0.004305135924369097,
-0.0027310254517942667,
-0.004931292962282896,
-0.0024375368375331163,
-0.010906203649938107,
-0.00906311720609665,
-0.006031606812030077,
-0.0005719488253816962,
0.0021846683230251074,
-0.005245564039796591,
-0.0006813134532421827,
0.0010095376055687666,
0.009147841483354568,
-0.0010616809595376253,
-0.003100220113992691,
0.0003754429635591805,
0.001845557359047234,
-0.006514159496873617,
0.013650810346007347,
-0.011402348056435585,
0.006493407301604748,
0.00023336861340794712,
-0.016944272443652153,
0.007184409536421299,
0.008344918489456177,
-0.0085159195587039,
0.0021285535767674446,
0.003255601041018963,
0.0018705065594986081,
-0.0005792109877802432,
-0.005877599120140076,
-0.002583930501714349,
-0.015211966820061207,
-0.001288033789023757,
0.018972592428326607,
0.0006676743505522609,
0.010350181721150875,
0.01230703853070736,
-0.0022820637095719576,
0.0019944782834500074,
0.002932982984930277,
0.0006390306516550481,
0.01491454429924488,
-0.008499866351485252,
0.00033327736309729517,
0.0015089369844645262,
-0.006295600440353155,
0.0008587503689341247,
0.005282767117023468,
0.005466124042868614,
-0.003424345515668392,
0.003279665485024452,
-0.007397138513624668,
-0.0063302889466285706,
-0.018984077498316765,
-0.0034172809682786465,
0.006854198407381773,
-0.005146009381860495,
0.005379552021622658,
-0.012475963681936264,
0.005559116136282682,
0.005403413902968168,
0.0037377297412604094,
0.00011171663936693221,
0.0017518738750368357,
0.006315113510936499,
0.012920951470732689,
-0.0043375627137720585,
0.0013312113005667925,
0.003397589083760977,
-0.0025668684393167496,
-0.0006820374401286244,
0.008836888708174229,
-0.00697702169418335,
-0.00585256889462471,
0.001167046488262713,
0.005522443912923336,
0.00002894606404879596,
-0.005222818348556757,
-0.00964769721031189,
-0.003578341333195567,
0.002301697852090001,
-0.007546718697994947,
0.004572388716042042,
0.003284118603914976,
0.003369428450241685,
-0.0042862668633461,
-0.00039034042856656015,
-0.0027711214497685432,
-0.011203328147530556,
0.011440999805927277,
-0.003448508447036147,
0.002752194181084633,
0.012617403641343117,
0.004037701059132814,
-0.013615177012979984,
0.005942361894994974,
0.008094935677945614,
-0.004677133169025183,
0.0056446390226483345,
0.006081053987145424,
-0.006780147552490234,
-0.021500229835510254,
-0.0037889420054852962,
-0.014254522509872913,
0.005857221316546202,
-0.002669677371159196,
0.0036043282598257065,
-0.006687812507152557,
0.005817782133817673,
0.009282196871936321,
-0.014004886150360107,
-0.005614969879388809,
-0.009410526603460312,
0.007759431377053261,
-0.00044924707617610693,
-0.000632450042758137,
-0.0036822063848376274,
-0.0024601793847978115,
-0.0019147132989019156,
-0.004344979766756296,
-0.0023939379025250673,
0.005232836119830608,
0.0013912402791902423,
-0.0015298387734219432,
0.0028119306080043316,
-0.0023837583139538765,
0.0021090523805469275,
-0.0002621047315187752,
-0.00939874816685915,
0.0017069282475858927,
0.0031753936782479286,
-0.003027939237654209,
-0.0017045839922502637,
0.0008575774845667183,
-0.0014370139688253403,
-0.007536714896559715,
-0.011622116900980473,
-0.0037371113430708647,
-0.004970173351466656,
-0.002571520861238241,
-0.012362605892121792,
-0.004075626842677593,
-0.008447130210697651,
0.00839583296328783,
-0.008345619775354862,
0.008816489018499851,
0.005424960982054472,
-0.005779867060482502,
0.007368856109678745,
-0.0008094277000054717,
0.0043218485079705715,
0.002711624838411808,
0.004964705556631088,
0.0018887409241870046,
-0.006860481109470129,
-0.011291340924799442,
0.012079431675374508,
-0.007978147827088833,
0.0018575659487396479,
0.012975174002349377,
0.005552775226533413,
0.010284271091222763,
-0.000305225548800081,
-0.0010005277581512928,
0.0032944215927273035,
0.007522380445152521,
-0.014099271036684513,
0.003915637265890837,
-0.005085572134703398,
-0.0010539129143580794,
0.0038720564916729927,
-0.003907337319105864,
0.0005356594920158386,
0.010511756874620914,
0.0013692397624254227,
-0.006821407936513424,
-0.0020730416290462017,
0.004056402947753668,
0.005198450293391943,
-0.012783507816493511,
-0.0012343180133029819,
-0.003751736367121339,
-0.004080918151885271,
-0.0027831285260617733,
-0.0017143776640295982,
0.00019093953596893698,
0.0055379681289196014,
-0.003589893924072385,
0.00586203346028924,
0.0037338093388825655,
-0.003774437354877591,
0.013627104461193085,
-0.005008911248296499,
-0.005976789630949497,
0.004039707127958536,
0.0034350287169218063,
-0.0031992837321013212,
-0.007205972447991371,
-0.002985453000292182,
0.002012559911236167,
0.0074940943159163,
-0.002392983064055443,
-0.0025129124987870455,
-0.0026825726963579655,
0.0004198960086796433,
-0.008764136582612991,
0.002145855687558651,
0.013571042567491531,
-0.0035308189690113068,
0.006790549028664827,
-0.0006722086109220982,
-0.009330935776233673,
-0.014581303112208843,
0.05160125717520714,
-0.0023146243765950203,
0.0034286081790924072,
0.004390748683363199,
-0.006962287239730358,
0.001121319248341024,
-0.001958634704351425,
0.008309825323522091,
-0.0075475419871509075,
-0.007953522726893425,
0.009370943531394005,
-0.00380414305254817,
0.0032757523003965616,
0.002906105713918805,
-0.0001684662711340934,
0.014585204422473907,
-0.004394758027046919,
-0.017197076231241226,
-0.01779237575829029,
0.006970755290240049,
-0.0025393699761480093,
-0.008045497350394726,
0.00926951039582491,
-0.001774771953932941,
-0.004326922353357077,
0.002847658470273018,
0.008792241103947163,
0.003583040554076433,
0.0017591464566066861,
-0.0027616803999990225,
-0.001918346039019525,
-0.0002817561908159405,
0.00455680675804615,
0.006380909122526646,
0.0068084606900811195,
-0.0023461775854229927,
0.0034735228400677443,
-0.0034113158471882343,
-0.0010833381675183773,
-0.004714810289442539,
0.003586587030440569,
0.006105230189859867,
-0.002506187418475747,
-0.0039081270806491375,
0.0042617893777787685,
0.004061088897287846,
0.003058074740692973,
0.010215474292635918,
0.0006592088611796498,
-0.007181495428085327,
0.010629064403474331,
0.004942395258694887,
-0.000607717433013022,
0.008269361220300198,
-0.0011234526755288243,
0.006753665395081043,
0.0003562655474524945,
-0.007608687039464712,
-0.013554208911955357,
-0.0020618480630218983,
0.008280874229967594,
0.007400829810649157,
-0.0011517602251842618,
0.002008784329518676,
-0.000932383700273931,
-0.0031422022730112076,
-0.007311888504773378,
-0.00849852804094553,
-0.003012255532667041,
0.0019632389303296804,
0.003152756253257394,
0.07178887724876404,
-0.006554960738867521,
-0.0020098986569792032,
-0.010334593243896961,
0.00039012552588246763,
-0.002528072101995349,
-0.001469806069508195,
0.001002114498987794,
-0.0010261127026751637,
0.005583283957093954,
0.0013940054923295975,
-0.00987327191978693,
-0.011524242348968983,
0.0019911101553589106,
0.0026473619509488344,
-0.001299520255997777,
0.0028256941586732864,
0.007619595155119896,
-0.007987519726157188,
0.0010259082773700356,
-0.011185882613062859,
-0.002059826161712408,
-0.0010342993773519993,
-0.009473768062889576,
-0.004165915306657553,
-0.0030383155681192875,
0.004146089311689138,
0.0012080330634489655,
0.004453720524907112,
-0.002988646738231182,
0.005537089891731739,
-0.0039036318194121122,
-0.00009960320312529802,
-0.003139117732644081,
-0.0006669521681033075,
-0.006214634515345097,
0.008383356034755707,
-0.00045073044020682573,
-0.009096182882785797,
-0.00509527325630188,
0.0011344822123646736,
0.0012011752696707845,
-0.005797095596790314,
0.005379787180572748,
-0.0017098254757001996,
0.004533423110842705,
-0.0036252110730856657,
0.0012559087481349707,
-0.006945365574210882,
0.0011844359105452895,
-0.013429899699985981,
0.0054084365256130695,
-0.17497967183589935,
0.010049927048385143,
0.003135127015411854,
-0.006950858980417252,
-0.0015894981333985925,
-0.014623232185840607,
-0.005797381512820721,
0.004806446842849255,
0.010254318825900555,
0.0017655013361945748,
-0.0011757637839764357,
-0.003115014173090458,
0.003506554290652275,
0.005590475630015135,
-0.0021291407756507397,
-0.0043940418399870396,
0.004688546527177095,
-0.004703261889517307,
0.002282916335389018,
0.0031585856340825558,
0.0029216366820037365,
0.010305773466825485,
0.000611491035670042,
0.0014797368785366416,
-0.0014252986293286085,
-0.006113846320658922,
0.007721361238509417,
-0.0036654584109783173,
0.005171750672161579,
-0.012672118842601776,
-0.003119664965197444,
-0.00431055435910821,
-0.004146228078752756,
0.0012111283140257,
0.005184363108128309,
-0.001282185665331781,
0.007569857407361269,
0.0031084478832781315,
-0.008097713813185692,
0.007917352020740509,
-0.006779320538043976,
0.03164456784725189,
0.005356148816645145,
0.005828959867358208,
-0.0011250968091189861,
-0.007032779976725578,
-0.0053550321608781815,
0.00850700680166483,
0.0034320002887398005,
0.013514379039406776,
-0.01354232057929039,
0.00004908110713586211,
0.003991053905338049,
0.01878790371119976,
-0.004640253260731697,
-0.00883544608950615,
-0.005550613161176443,
-0.004093807656317949,
0.0021418666001409292,
0.010062546469271183,
0.011484838090837002,
-0.0032771150581538677,
0.008659101091325283,
-0.0009081876487471163,
-0.021394122391939163,
0.0032849435228854418,
-0.005382673814892769,
-0.007822494022548199,
0.0020024082623422146,
0.0068825711496174335,
0.007628564722836018,
0.0004966474371030927,
0.0008122645667754114,
0.00021298578940331936,
0.0067080240696668625,
-0.00020871392916887999,
0.006400454789400101,
-0.0006677463534288108,
0.004960989113897085,
-0.009591984562575817,
0.008569246158003807,
-0.009104524739086628,
-0.0024006415624171495,
0.0016697628889232874,
-0.0049853636883199215,
0.01075360644608736,
0.0046510109677910805,
-0.0035523383412510157,
-0.00046227657003328204,
-0.009072305634617805,
-0.0034585967659950256,
0.0034505915828049183,
0.0012573772110044956,
-0.008466478437185287,
0.0027293402235955,
0.0019383388571441174,
0.007448793854564428,
0.00686317402869463,
-0.008732160553336143,
0.005420674104243517,
0.005767737980931997,
-0.00711604580283165,
0.002597522921860218,
-0.0036287351977080107,
0.0037490027025341988,
0.004578993655741215,
-0.005255701020359993,
-0.0064148991368710995,
0.002923433668911457,
-0.008095183409750462,
-0.0061301132664084435,
0.004870245698839426,
-0.00834609754383564,
-0.009731338359415531,
-0.001068896264769137,
-0.010473490692675114,
0.00101681228261441
] |
8a37f74b88dcc7ed94cf7a22b08f15fb01357b23 | 1,882 | py | Python | day04/c.py | Net-Mist/advent_of_code2021 | 124d773356bee2794294800de7673d5fac24db0a | [
"MIT"
] | 1 | 2022-01-03T09:21:33.000Z | 2022-01-03T09:21:33.000Z | day04/c.py | Net-Mist/advent_of_code2021 | 124d773356bee2794294800de7673d5fac24db0a | [
"MIT"
] | null | null | null | day04/c.py | Net-Mist/advent_of_code2021 | 124d773356bee2794294800de7673d5fac24db0a | [
"MIT"
] | null | null | null | import numpy as np
GRID_SIZE = 5
def read_bingo_grid(lines: list[str]) -> list[list[int]]:
return [[int(n) for n in line.split()] for line in lines]
def bingo_step(grids: np.ndarray, checked_grids: np.ndarray, number: int) -> None:
checked_grids[np.where(grids == number)] = True
def check_victory(check_grids: np.ndarray) -> set[int]:
"""return empty set if no victory, else set of id of the wining grids"""
return set(np.where(check_grids.sum(axis=1).max(axis=1) == 5)[0]).union(
np.where(check_grids.sum(axis=2).max(axis=1) == 5)[0]
)
def sum_grid(grid: np.ndarray, checked_grid: np.ndarray) -> int:
grid[checked_grid] = 0
return grid.sum()
def main() -> None:
with open("input.txt") as f:
lines = f.readlines()
random_numbers = [int(n) for n in lines[0].split(",")]
grids = np.array([read_bingo_grid(lines[i : i + GRID_SIZE]) for i in range(2, len(lines), 1 + GRID_SIZE)])
checked_grids = np.array([[[False for _ in range(GRID_SIZE)] for _ in range(GRID_SIZE)] for _ in range(len(grids))])
win = False
i = 0
q1_done = False
while not win:
bingo_step(grids, checked_grids, random_numbers[i])
winning_set = check_victory(checked_grids)
if len(winning_set) == 1 and not q1_done:
index = list(winning_set)[0]
s = sum_grid(grids[index], checked_grids[index])
print("part1:", s * random_numbers[i])
q1_done = True
if len(grids) == len(winning_set) + 1:
index_last_to_win = list(set(range(len(grids))).difference(winning_set))[0]
if len(grids) == len(winning_set):
s = sum_grid(grids[index_last_to_win], checked_grids[index_last_to_win])
print("part2:", random_numbers[i], s, random_numbers[i] * s)
return
i += 1
if __name__ == "__main__":
main()
| 34.218182 | 120 | 0.624867 | 1 | 1.4001 | [
0.002584450878202915,
0.024471193552017212,
0.006390625610947609,
0.00001118394902732689,
0.00504136411473155,
-0.0018551596440374851,
-0.010865927673876286,
0.003974570892751217,
-0.006620422471314669,
0.0008460123790428042,
0.0015356322983279824,
0.004789862781763077,
0.0072883740067481995,
-0.018505383282899857,
0.000495444517582655,
0.017028070986270905,
-0.05255160108208656,
-0.0007476825849153101,
-0.0019503794610500336,
0.002771845320239663,
-0.007711473386734724,
0.0080674197524786,
0.008824855089187622,
0.007318045478314161,
0.006073708180338144,
-0.0013779851142317057,
0.010208429768681526,
0.0029766038060188293,
-0.00854100938886404,
-0.004079751670360565,
-0.0007958101923577487,
-0.000724708428606391,
-0.005419434048235416,
-0.00885212142020464,
0.004543459974229336,
-0.0034409125801175833,
-0.0004518352507147938,
-0.019454803317785263,
0.012378588318824768,
-0.005370336584746838,
-0.005509708076715469,
-0.015207181684672832,
-0.002221275819465518,
0.0034218605142086744,
-0.008918077684938908,
0.0030097500421106815,
-0.0028337494004517794,
0.00016668856551405042,
-0.011026783846318722,
0.0055918823927640915,
-0.011100990697741508,
0.006162740755826235,
0.012082270346581936,
0.003931073937565088,
-0.006291683297604322,
-0.006293961312621832,
0.011772911995649338,
0.0004518789064604789,
-0.010464383289217949,
0.00043907956569455564,
-0.0007980528171174228,
-0.003479231847450137,
0.005603289697319269,
0.002862950088456273,
-0.01610093005001545,
-0.008516029454767704,
-0.003398722968995571,
0.0030657488387078047,
-0.00048402842367067933,
0.004523604176938534,
-0.00006837897672085091,
-0.0007368411170318723,
0.006626851856708527,
0.004847439471632242,
0.0053999279625713825,
-0.003050883999094367,
-0.0031530249398201704,
0.0012786301085725427,
0.008770291693508625,
0.004129938781261444,
0.0009301070822402835,
-0.005594484508037567,
0.0070453523658216,
0.00955120474100113,
0.015252767130732536,
0.00821822788566351,
0.017743026837706566,
-0.011103522032499313,
0.04485802724957466,
0.007681515999138355,
-0.008289385586977005,
0.004226727411150932,
-0.012655806727707386,
-0.0009891277877613902,
-0.0035217497497797012,
-0.027991890907287598,
0.003051403444260359,
-0.004557607229799032,
-0.0005477689555846155,
0.0033676158636808395,
-0.0005223547923378646,
0.007020602468401194,
-0.0013066111132502556,
-0.002094071125611663,
-0.009766324423253536,
0.010732640512287617,
-0.008593465201556683,
-0.0026589110493659973,
0.005435023456811905,
0.00182896398473531,
-0.01048757042735815,
-0.0009755191276781261,
0.001784765743650496,
-0.012316269800066948,
0.0022928747348487377,
0.003890450345352292,
-0.0059002903290092945,
0.05395122990012169,
0.00014389016723725945,
0.004191424697637558,
-0.004447117913514376,
-0.0016584619879722595,
0.0015523883048444986,
0.004219501279294491,
0.0108637735247612,
-0.004015689250081778,
0.008298663422465324,
0.00431859353557229,
0.0020705643109977245,
0.00868641771376133,
-0.004007870797067881,
0.006079799961298704,
-0.005157950334250927,
-0.0006952838157303631,
0.000015630161215085536,
-0.008030026219785213,
0.005243534687906504,
-0.001919019385240972,
-0.0037580698262900114,
-0.0004445028898771852,
-0.002686473773792386,
-0.009162518195807934,
0.0022703176364302635,
-0.00488113472238183,
0.00480021582916379,
-0.012292223051190376,
-0.005071418825536966,
-0.002325894543901086,
-0.004255128093063831,
0.00041769922245293856,
0.010092312470078468,
0.003926628269255161,
0.0017806008690968156,
-0.004462475422769785,
-0.008114428259432316,
-0.0007253280491568148,
-0.005533784627914429,
0.0021907154005020857,
0.006304412614554167,
0.004456648603081703,
-0.010900174267590046,
-0.0008492182241752744,
0.00212096213363111,
0.0011692149564623833,
-0.001244031940586865,
0.00438860896974802,
-0.008057220838963985,
0.008356465958058834,
0.00023959667305462062,
0.003599534509703517,
0.011603008955717087,
-0.005465951282531023,
-0.0008941154228523374,
0.0009373595821671188,
0.0019384712213650346,
0.0010238016257062554,
0.0036196589935570955,
0.00983045157045126,
-0.004193473607301712,
-0.005557791329920292,
0.004866127856075764,
0.005448705051094294,
0.009462923742830753,
0.005146737676113844,
-0.003944589290767908,
-0.0002134146634489298,
-0.004331329837441444,
-0.0016234706854447722,
0.008587847463786602,
-0.0054563116282224655,
0.006462828256189823,
0.0038057081401348114,
-0.014067007228732109,
-0.009263722226023674,
-0.0025589196011424065,
-0.007253744639456272,
0.0011785207316279411,
0.012858498841524124,
0.010150305926799774,
-0.0024031626526266336,
0.0019425064092501998,
-0.010648497380316257,
0.0012370360782369971,
0.01030564121901989,
0.0021311913151293993,
-0.012420306913554668,
-0.9580273628234863,
0.005737438332289457,
0.004248660523444414,
-0.0018088937504217029,
0.005047087091952562,
0.0022852616384625435,
0.003970685414969921,
0.00442897342145443,
0.013766682706773281,
-0.01014840416610241,
-0.005383850075304508,
-0.010266839526593685,
-0.011925531551241875,
-0.0016204265411943197,
-0.0064780740067362785,
-0.004415114410221577,
-0.005641249008476734,
-0.007557894103229046,
-0.002441873075440526,
-0.0031060902401804924,
-0.0019310603383928537,
0.009557878598570824,
0.0005331910797394812,
0.004941634833812714,
0.0028287137392908335,
0.005381075199693441,
-0.0024211835116147995,
-0.003100460162386298,
-0.0007821623585186899,
-0.002241101348772645,
-0.007720282766968012,
-0.01577656902372837,
-0.003654308384284377,
-0.00038692724774591625,
0.011772063560783863,
0.0025807588826864958,
0.006146664265543222,
-0.0023418902419507504,
0.001160894287750125,
-0.009131691418588161,
0.0024154919665306807,
-0.0002578541752882302,
0.0046383230946958065,
-0.029801683500409126,
0.0015540699241682887,
-0.00023339441395364702,
-0.00952997151762247,
0.00623641163110733,
0.003725804155692458,
-0.000803839648142457,
-0.0025589410215616226,
-0.006615085527300835,
0.010985798202455044,
-0.006196317728608847,
0.004415720235556364,
-0.003077656961977482,
-0.008147837594151497,
-0.0022304896265268326,
-0.008268577978014946,
0.0026187547482550144,
0.0055059096775949,
-0.00549027556553483,
-0.0032246161717921495,
-0.0049611967988312244,
0.0029710144735872746,
0.0005163769237697124,
0.005850172135978937,
-0.018567072227597237,
-0.007172936573624611,
0.0006684546242468059,
0.001498656114563346,
-0.0030077460687607527,
-0.005594801623374224,
0.006182432174682617,
-0.00828827079385519,
0.005625966936349869,
0.0019350703805685043,
0.001455941703170538,
-0.011604070663452148,
-0.0006243669777177274,
-0.010063525289297104,
-0.006595043931156397,
0.0034703477285802364,
-0.0036415751092135906,
-0.004868322052061558,
-0.00007265366002684459,
0.004667528904974461,
0.0074652135372161865,
-0.004629714880138636,
0.0014628039207309484,
0.00900269951671362,
-0.004126096609979868,
-0.009746997617185116,
0.006666122004389763,
0.005210132338106632,
0.0013362995814532042,
-0.0020233422983437777,
0.005141210276633501,
0.006514588370919228,
0.006938048172742128,
0.001614911830984056,
0.006848322693258524,
0.0020594268571585417,
0.008081480860710144,
0.00003855260001728311,
0.00292590050958097,
-0.00223020208068192,
-0.0006734297494404018,
-0.004431562498211861,
-0.00009564558422425762,
-0.005562218371778727,
-0.0022613685578107834,
-0.013276495039463043,
-0.008671442978084087,
-0.004941349849104881,
0.0006014044629409909,
0.002246629912406206,
-0.004198587033897638,
-0.002386548090726137,
0.002195469569414854,
0.00977617222815752,
-0.0011146031320095062,
-0.005528263282030821,
0.0008746060775592923,
0.0032990225590765476,
-0.0061907460913062096,
0.013562355190515518,
-0.010347524657845497,
0.008296969346702099,
0.0020602447912096977,
-0.015108625404536724,
0.006675854325294495,
0.008345154114067554,
-0.010930116288363934,
0.003974089398980141,
0.002011719858273864,
0.0019307616166770458,
-0.0014460082165896893,
-0.005666959099471569,
-0.0038229390047490597,
-0.015568926930427551,
0.0006302222609519958,
0.02204451709985733,
0.0011819007340818644,
0.01042036060243845,
0.011146264150738716,
-0.003298478201031685,
0.004159582778811455,
0.003235053503885865,
-0.0014947414165362716,
0.013996824622154236,
-0.0068924883380532265,
-0.0008171125664375722,
0.0036461493000388145,
-0.004566307179629803,
0.002673387760296464,
0.006863253656774759,
0.006288611330091953,
-0.002475373214110732,
0.004035060293972492,
-0.0033322745002806187,
-0.0033822108525782824,
-0.015334239229559898,
-0.002513555809855461,
0.008555895648896694,
-0.002785097574815154,
0.00576439592987299,
-0.012237445451319218,
0.005149949342012405,
0.006330535281449556,
0.004708331078290939,
-0.0007855725707486272,
0.003135736333206296,
0.0062806191854178905,
0.011018755845725536,
-0.005908052437007427,
-0.0005928772152401507,
0.0042051756754517555,
-0.0010894957231357694,
-0.0013504920061677694,
0.004658650606870651,
-0.008364643901586533,
-0.005071084946393967,
0.0019177461508661509,
0.004118403419852257,
0.00005605910700978711,
-0.003825852880254388,
-0.008973556570708752,
-0.0033990570809692144,
0.004673290066421032,
-0.007134124170988798,
0.004281992558389902,
0.0011668496299535036,
0.0031933949794620275,
-0.005735836457461119,
0.00021042031585238874,
-0.00016222258273046464,
-0.011758720502257347,
0.010831387713551521,
-0.00477324053645134,
0.003004128346219659,
0.01264269556850195,
0.006268302910029888,
-0.011869307607412338,
0.005567135754972696,
0.010248232632875443,
-0.0038964475970715284,
0.005471421871334314,
0.005900054704397917,
-0.0050371442921459675,
-0.023499978706240654,
-0.0033905182499438524,
-0.012056277133524418,
0.007350211497396231,
-0.0015114168636500835,
0.006429326254874468,
-0.007157446816563606,
0.004777006804943085,
0.008917532861232758,
-0.014923596754670143,
-0.00616413401439786,
-0.009230240248143673,
0.0065390486270189285,
-0.0008169226930476725,
-0.0010946260299533606,
-0.0038121130783110857,
-0.004054700955748558,
-0.0018376886146143079,
-0.0032422528602182865,
-0.002910429146140814,
0.00487897451967001,
0.0026095763314515352,
-0.003925887402147055,
0.002587550552561879,
-0.003576979972422123,
0.0023423093371093273,
0.0004537783097475767,
-0.009228922426700592,
0.005455018486827612,
0.0020501415710896254,
-0.00571313826367259,
-0.0011696041328832507,
0.001517690485343337,
-0.0007674046792089939,
-0.007246079854667187,
-0.010097422637045383,
-0.004206185229122639,
-0.005676516331732273,
-0.005083252210170031,
-0.010985823348164558,
-0.004296252969652414,
-0.006956028752028942,
0.0067488583736121655,
-0.00791253987699747,
0.008125842548906803,
0.007622179109603167,
-0.005563476122915745,
0.007085873279720545,
-0.001839508069679141,
0.003956654109060764,
0.00006152695277705789,
0.005769469775259495,
0.0017851867014542222,
-0.004027529153972864,
-0.006848894525319338,
0.011816941201686859,
-0.009303363040089607,
-0.0008952186326496303,
0.014288157224655151,
0.005493554286658764,
0.010590989142656326,
0.0016012752894312143,
0.00045133676030673087,
0.0031834125984460115,
0.008344579488039017,
-0.01367595512419939,
0.003260263940319419,
-0.003452789504081011,
-0.00006295803905231878,
0.0039520650170743465,
-0.004305872600525618,
0.0003056297719012946,
0.008172176778316498,
0.0008171352674253285,
-0.005981177091598511,
0.0003733289777301252,
0.002558451844379306,
0.0043069543316960335,
-0.011576956138014793,
-0.0008811753941699862,
-0.0041084252297878265,
-0.0055435700342059135,
-0.0023628512863069773,
-0.0021298679057508707,
0.0007476597093045712,
0.00432930700480938,
-0.0032729438971728086,
0.006215078290551901,
0.0018818634562194347,
-0.0038435147143900394,
0.013110862113535404,
-0.003285203129053116,
-0.003197448793798685,
0.002869188319891691,
0.003416588297113776,
-0.0044711981900036335,
-0.004757219459861517,
-0.0030803002882748842,
0.00241580861620605,
0.007252529263496399,
-0.0019499693298712373,
-0.004625564906746149,
-0.0018449475755915046,
0.0007039167103357613,
-0.011656071059405804,
0.000620565377175808,
0.012389905750751495,
-0.0056346566416323185,
0.006141681224107742,
0.0001639346737647429,
-0.006737694144248962,
-0.014034349471330643,
0.05251442268490791,
-0.000850305485073477,
0.001847975654527545,
0.0035105543211102486,
-0.006981757935136557,
-0.0006461163866333663,
0.000081731537648011,
0.008928250521421432,
-0.007548557128757238,
-0.008139440789818764,
0.009500240907073021,
-0.006277556996792555,
0.0029036812484264374,
0.0021384842693805695,
0.0016920703928917646,
0.015300837345421314,
-0.0038112092297524214,
-0.01947825774550438,
-0.015882205218076706,
0.007557146716862917,
-0.0014296328881755471,
-0.005641079042106867,
0.007999948225915432,
-0.002484492026269436,
-0.0005464828573167324,
0.0029266842175275087,
0.007332011125981808,
-0.0007945062825456262,
0.001764435088261962,
-0.0020958317909389734,
-0.0020153720397502184,
0.0015401074197143316,
0.001819792902097106,
0.0061945621855556965,
0.007573167327791452,
-0.0008342236978933215,
0.007090941537171602,
-0.002318795071914792,
-0.00021073120296932757,
-0.0036841833498328924,
0.003252680879086256,
0.0070088207721710205,
-0.0028047796804457903,
-0.0037158073391765356,
0.002734667155891657,
0.004118860233575106,
0.003660177579149604,
0.011743598617613316,
0.00013742358714807779,
-0.007509307470172644,
0.010029054246842861,
0.00479515315964818,
-0.0012106997892260551,
0.008860752917826176,
-0.0034244020935148,
0.007085910998284817,
0.0010036126477643847,
-0.009778150357306004,
-0.015116443857550621,
-0.0017533100908622146,
0.008525511249899864,
0.0075937616638839245,
-0.0019580069929361343,
0.0021371692419052124,
0.00019720752607099712,
-0.0017631901428103447,
-0.005711616948246956,
-0.009151688776910305,
-0.005389050114899874,
0.0009976871078833938,
0.0053712232038378716,
0.06983205676078796,
-0.005072575528174639,
-0.002620123326778412,
-0.008821502327919006,
-0.0006547160446643829,
-0.002491272520273924,
-0.0011054259957745671,
-0.00010982956882799044,
-0.0010004511568695307,
0.003847513347864151,
0.0013833623379468918,
-0.00902931671589613,
-0.009931102395057678,
0.003385604592040181,
-0.001080886460840702,
-0.0025209267623722553,
0.00543064484372735,
0.007103780750185251,
-0.007024968042969704,
0.0010716746328398585,
-0.010699432343244553,
-0.0027623854111880064,
-0.004145549610257149,
-0.010707573965191841,
-0.005136971827596426,
-0.005893931724131107,
0.002831218997016549,
0.0018453706288710237,
0.00437468197196722,
-0.004418708384037018,
0.005494377110153437,
-0.002860563574358821,
0.0027324880938977003,
-0.0033831323962658644,
-0.00054445635760203,
-0.006560508627444506,
0.008470828644931316,
0.002538315486162901,
-0.011955113150179386,
-0.00450483150780201,
-0.0022698871325701475,
-0.00021928770001977682,
-0.006115909665822983,
0.005384805146604776,
-0.004056433215737343,
0.006727661471813917,
-0.0013053478905931115,
0.0009235195466317236,
-0.005612249486148357,
0.004154816269874573,
-0.011863447725772858,
0.003977904561907053,
-0.17802828550338745,
0.00900602899491787,
0.0019587913993746042,
-0.004750652238726616,
-0.003742945147678256,
-0.012956623919308186,
-0.0068355449475348,
0.00483251828700304,
0.010724612511694431,
0.001312451553530991,
-0.0012793048517778516,
-0.0026771635748445988,
0.005732797551900148,
0.0048266020603477955,
0.000538540247362107,
-0.008370121009647846,
0.004697883035987616,
-0.004448899999260902,
-0.001254415838047862,
0.002699210774153471,
0.005406743846833706,
0.010991974733769894,
0.0017143473960459232,
0.0008731756825000048,
-0.0018199211917817593,
-0.0035669824574142694,
0.006715891882777214,
-0.003142864676192403,
0.006994164548814297,
-0.00930181983858347,
-0.002015692414715886,
-0.0064376723021268845,
-0.0037093372084200382,
0.00332439667545259,
0.005375826731324196,
0.00012669422721955925,
0.006963616237044334,
0.0015953094698488712,
-0.008094418793916702,
0.00763016939163208,
-0.008659797720611095,
0.028562581166625023,
0.004007058218121529,
0.008248134516179562,
0.0031880741007626057,
-0.005194739904254675,
-0.004579063504934311,
0.009134355001151562,
0.0010409797541797161,
0.014074326492846012,
-0.01716371439397335,
-0.003082024399191141,
0.001412136945873499,
0.018092447891831398,
-0.0037904167547822,
-0.010773909278213978,
-0.006640664301812649,
-0.004968754481524229,
0.002087192377075553,
0.008344877511262894,
0.010164286941289902,
-0.003943362273275852,
0.006342144217342138,
-0.0028435413260012865,
-0.02241857908666134,
0.0016444664215669036,
-0.004865764640271664,
-0.007822754792869091,
-0.0001731131342239678,
0.007559146266430616,
0.010802241042256355,
-0.0008955614757724106,
0.0028000373858958483,
0.0008385151741094887,
0.003880695439875126,
-0.0012083270121365786,
0.0059769172221422195,
-0.00004397235170472413,
0.0031449398957192898,
-0.009065665304660797,
0.0065653761848807335,
-0.007094834931194782,
-0.0019951490685343742,
0.0002318971964996308,
-0.00374148553237319,
0.01132587157189846,
0.004782901145517826,
-0.0022314805537462234,
-0.002439583884552121,
-0.007382775656878948,
-0.004060662817209959,
0.002852599835023284,
0.00004395504220155999,
-0.009004072286188602,
0.0011837639613077044,
0.0001971432939171791,
0.0031761443242430687,
0.005988942459225655,
-0.008370214141905308,
0.003971791360527277,
0.006733746733516455,
-0.00573253957554698,
0.0010954830795526505,
-0.002513737417757511,
0.003204737789928913,
0.003248718800023198,
-0.005238729529082775,
-0.005614403169602156,
0.002410123124718666,
-0.005913508590310812,
-0.0056936731562018394,
0.0059545510448515415,
-0.008226749487221241,
-0.009731580503284931,
-0.0008927768794819713,
-0.012497317045927048,
0.0014101036358624697
] |
8a3aa16cb3dbe2b4a517472d48c9588e47d4f479 | 1,497 | py | Python | altair/vegalite/v2/examples/us_population_pyramid_over_time.py | hugovk/altair | a3c9f06790f7a8c5c7e2c98278d0f69e4630b5be | [
"BSD-3-Clause"
] | 1 | 2022-03-13T21:42:09.000Z | 2022-03-13T21:42:09.000Z | altair/vegalite/v2/examples/us_population_pyramid_over_time.py | RoyMachineLearning/altair | 74a765b373694776e63d224d99536975cc173810 | [
"BSD-3-Clause"
] | null | null | null | altair/vegalite/v2/examples/us_population_pyramid_over_time.py | RoyMachineLearning/altair | 74a765b373694776e63d224d99536975cc173810 | [
"BSD-3-Clause"
] | null | null | null | '''
US Population Pyramid Over Time
===============================
A population pyramid shows the distribution of age groups within a population.
It uses a slider widget that is bound to the year to visualize the age
distribution over time.
'''
# category: case studies
import altair as alt
from altair.expr import datum, if_
from vega_datasets import data
pop = data.population.url
slider = alt.binding_range(min=1850, max=2000, step=10)
select_year = alt.selection_single(name='year', fields=['year'], bind=slider)
base = alt.Chart(pop).add_selection(
select_year
).transform_filter(
select_year
).transform_calculate(
gender=if_(datum.sex == 1, 'Male', 'Female')
)
title = alt.Axis(title='population')
color_scale = alt.Scale(domain=['Male', 'Female'],
range=['#1f77b4', '#e377c2'])
left = base.transform_filter(
datum.gender == 'Female'
).encode(
y=alt.X('age:O', axis=None),
x=alt.X('sum(people):Q', axis=title, sort=alt.SortOrder('descending')),
color=alt.Color('gender:N', scale=color_scale, legend=None)
).mark_bar().properties(title='Female')
middle = base.encode(
y=alt.X('age:O', axis=None),
text=alt.Text('age:Q'),
).mark_text().properties(width=20)
right = base.transform_filter(
datum.gender == 'Male'
).encode(
y=alt.X('age:O', axis=None),
x=alt.X('sum(people):Q', axis=title),
color=alt.Color('gender:N', scale=color_scale, legend=None)
).mark_bar().properties(title='Male')
left | middle | right | 29.352941 | 78 | 0.674683 | 1 | 1.1931 | [
-0.0017172860680148005,
0.02361295558512211,
0.006478296592831612,
0.006395714357495308,
0.006416714750230312,
-0.0027811825275421143,
-0.0034558498300611973,
-0.0034768227487802505,
-0.006323599256575108,
0.004967327229678631,
0.0006735522183589637,
0.005465258378535509,
0.006225258111953735,
-0.01363504957407713,
-0.0025517093017697334,
0.01493314653635025,
-0.04461795091629028,
0.00006882408342789859,
-0.006466513965278864,
-0.0002652260009199381,
-0.008050046861171722,
0.008940448984503746,
0.007088696118444204,
0.006072353105992079,
-0.001036213361658156,
-0.0020531550981104374,
0.007692332379519939,
0.0032052078749984503,
-0.0039031733758747578,
-0.0022930942941457033,
-0.006388342473655939,
-0.0035149387549608946,
-0.008629580959677696,
-0.006360980682075024,
0.002026608446612954,
-0.007334604859352112,
-0.0015376510564237833,
-0.016686702147126198,
0.013350795023143291,
-0.004338598344475031,
0.00040813189116306603,
-0.007766454014927149,
0.004827290773391724,
0.0035295032430440187,
-0.010480934754014015,
0.003509550355374813,
-0.005618961062282324,
0.000534732942469418,
-0.01212036982178688,
0.005573390517383814,
-0.00269884429872036,
0.007894273847341537,
0.014316987246274948,
0.00034575368044897914,
-0.008350986056029797,
-0.00604159664362669,
0.015165131539106369,
0.0018400577828288078,
-0.009636572562158108,
0.0023496218491345644,
-0.005217636935412884,
-0.0029889969155192375,
0.004309116862714291,
-0.002342264400795102,
-0.010813235305249691,
-0.007315108086913824,
-0.005278774071484804,
0.0021404835861176252,
-0.0069639720022678375,
0.006990781985223293,
0.0009776742663234472,
-0.003160539548844099,
0.003432930214330554,
0.0027298778295516968,
0.001192005118355155,
-0.004402191378176212,
0.0007374333217740059,
0.002319255145266652,
0.009696964174509048,
0.005905610974878073,
0.00410423381254077,
-0.005084219388663769,
0.00045611592940986156,
0.006745207589119673,
0.007745875045657158,
0.012137449346482754,
0.019390670582652092,
-0.011464913375675678,
0.0401785634458065,
0.005066930782049894,
-0.007763458415865898,
0.007145020179450512,
-0.007947942242026329,
-0.004963011480867863,
-0.009355670772492886,
-0.02767840586602688,
-0.0015919532161206007,
-0.0006690342561341822,
0.00022591621382161975,
0.005219935905188322,
0.000276833277894184,
0.006036761682480574,
-0.0007728443015366793,
-0.00035509999725036323,
-0.010900729335844517,
0.005757586564868689,
-0.010400784201920033,
-0.005041193217039108,
0.006729033309966326,
0.0011632496025413275,
-0.010852718725800514,
-0.0019887418020516634,
0.00022542184160556644,
-0.012857169844210148,
0.008887043222784996,
0.005683494731783867,
-0.005774976685643196,
0.04226033017039299,
-0.0028730714693665504,
0.0070818508975207806,
-0.00007768428622512147,
-0.0004467386461328715,
0.0015107443323358893,
0.0030711451545357704,
0.006651538889855146,
-0.00029282865580171347,
0.01604849100112915,
0.006575845647603273,
0.0020817029289901257,
0.009260217659175396,
-0.003496810793876648,
0.005394347477704287,
-0.0013742555165663362,
0.00044077294296585023,
-0.0018811346963047981,
-0.010196427814662457,
0.00553586520254612,
-0.004919080995023251,
-0.008648043498396873,
0.004549362696707249,
-0.0031176747288554907,
-0.009897703304886818,
-0.003166991053149104,
-0.005083360709249973,
0.008281663991510868,
-0.013231325894594193,
-0.000871509313583374,
-0.004344054963439703,
-0.005928519647568464,
0.003914038650691509,
0.006451053079217672,
0.003007499733939767,
0.0024770202580839396,
-0.0025664016138762236,
-0.008970124647021294,
0.0016752260271459818,
-0.0013891450362280011,
-0.000018278324205311947,
0.005109059624373913,
0.0048483978025615215,
-0.009644154459238052,
0.0029387078247964382,
0.0011205539340153337,
0.004953349474817514,
-0.0017096081282943487,
0.006957139354199171,
-0.006272257771342993,
0.00891904067248106,
0.00008794933091849089,
0.0069781458005309105,
0.01462643500417471,
-0.0025529926642775536,
-0.0018216873286291957,
-0.002777174348011613,
0.0004031966673210263,
0.0023746853694319725,
0.009646897204220295,
0.007466610986739397,
-0.0008919753017835319,
-0.004542370326817036,
0.004874684382230043,
0.004390252288430929,
0.008281024172902107,
0.009440727531909943,
-0.00044644021545536816,
-0.002770619234070182,
-0.004246729891747236,
-0.004066580440849066,
0.005039778538048267,
-0.004114216193556786,
0.007410290185362101,
0.0006519911112263799,
-0.010358382947742939,
-0.00803777389228344,
-0.0019278745166957378,
-0.008488754741847515,
0.0019263424910604954,
0.014633351936936378,
0.00972001999616623,
-0.004921529907733202,
0.003166258567944169,
-0.00959588959813118,
-0.0012882031733170152,
0.009086317382752895,
-0.0018119585001841187,
-0.011773870326578617,
-0.9632323980331421,
0.004312383476644754,
0.004391659051179886,
-0.0017549918266013265,
0.004244064446538687,
0.007799130864441395,
-0.00014205170737113804,
0.005998119246214628,
0.009885262697935104,
-0.010247000493109226,
-0.0017211948288604617,
-0.008223515003919601,
-0.006970182992517948,
-0.00000873572480486473,
-0.00916393380612135,
-0.0006776958471164107,
-0.0013173081679269671,
-0.005457061342895031,
-0.006064317189157009,
-0.0011225943453609943,
-0.004504579119384289,
0.002985278842970729,
-0.0024306352715939283,
0.004988750442862511,
0.0021001279819756746,
0.00533292768523097,
-0.0018307362915948033,
-0.0027558014262467623,
-0.0012427346082404256,
-0.005234644748270512,
-0.0063558304682374,
-0.012289238162338734,
-0.004722230136394501,
-0.004309017676860094,
0.008597551845014095,
0.0027893998194485903,
0.010225050151348114,
-0.0015135352732613683,
-0.0034872558899223804,
-0.007354918401688337,
0.005600361619144678,
-0.0025972959119826555,
0.002056731143966317,
-0.02913343720138073,
-0.0027892854996025562,
0.0018962830072268844,
-0.01262892596423626,
0.009696025401353836,
0.0011003128020092845,
0.003929490689188242,
-0.0063265119679272175,
-0.002610395196825266,
0.010650728829205036,
-0.004315860103815794,
0.0069226427003741264,
-0.0029173477087169886,
-0.012901109643280506,
-0.0058072409592568874,
-0.011615362018346786,
0.0032614064402878284,
0.00313113653101027,
0.005863996688276529,
0.0013465899974107742,
-0.005625521764159203,
0.00005141178553458303,
-0.00021823904535267502,
0.005780367646366358,
-0.017449021339416504,
-0.00543462997302413,
0.0012347039300948381,
0.0036236371379345655,
-0.005065742414444685,
-0.0053300014697015285,
0.007660761009901762,
-0.011249201372265816,
0.0031743545550853014,
0.0002630897506605834,
0.002398120006546378,
-0.006343170069158077,
-0.005808308254927397,
-0.00550628500059247,
-0.007038412615656853,
0.0003595116431824863,
-0.005391179583966732,
-0.00590523611754179,
0.00269183237105608,
0.0020005651749670506,
0.007192691788077354,
-0.005922058131545782,
0.0017654800321906805,
0.012101982720196247,
0.00045092430082149804,
-0.007674711756408215,
0.004162182565778494,
0.008531015366315842,
0.001312211505137384,
-0.0019073913572356105,
0.003538089571520686,
0.006886519957333803,
0.007630085106939077,
0.002219557762145996,
0.006677050609141588,
0.0020547553431242704,
0.01670083962380886,
0.0006245221593417227,
-0.004262825008481741,
-0.004690603353083134,
0.00024818137171678245,
-0.002533033024519682,
-0.006535151042044163,
-0.0061154416762292385,
-0.002584919799119234,
-0.012551256455481052,
-0.009409547783434391,
-0.0016775097465142608,
0.0020189243368804455,
0.004646788816899061,
-0.006588238291442394,
-0.0039397794753313065,
-0.001947578159160912,
0.0024004282895475626,
0.0010476893512532115,
-0.004111273679882288,
-0.0017644016770645976,
-0.0015574205899611115,
-0.005430873017758131,
0.018551351502537727,
-0.00821282435208559,
0.007972841151058674,
0.00548135070130229,
-0.013220902532339096,
0.005687188357114792,
0.008958899416029453,
-0.005824700463563204,
0.0010875033913180232,
0.0007647458114661276,
0.003281393088400364,
0.001495508593507111,
-0.0021548697259277105,
0.000261942419456318,
-0.017623813822865486,
0.0006605593371205032,
0.020193811506032944,
-0.0024345468264073133,
0.00838050153106451,
0.007891837507486343,
-0.0019384123152121902,
-0.0004857873427681625,
0.008969196118414402,
-0.000900986953638494,
0.013265608809888363,
-0.004532619845122099,
-0.002304874360561371,
0.005906455684453249,
-0.008320261724293232,
0.004497833549976349,
0.003896510461345315,
0.004397229757159948,
0.000766918936278671,
0.004072822630405426,
-0.006851955782622099,
-0.005130139645189047,
-0.016254005953669548,
-0.004706794861704111,
0.006866552866995335,
-0.0036894080694764853,
0.006706347223371267,
-0.016266144812107086,
0.004190963227301836,
0.0028720248956233263,
0.007775374688208103,
0.00012055470142513514,
0.00001716430051601492,
0.006367970257997513,
0.011158489622175694,
-0.002675459487363696,
-0.00013829866657033563,
0.0012788313906639814,
0.0006998919416218996,
0.003262521233409643,
0.009581184014678001,
-0.00829812791198492,
-0.004299401305615902,
-0.0024077692069113255,
0.004475611262023449,
-0.001060369540937245,
-0.0029335464350879192,
-0.010875437408685684,
0.001507687964476645,
0.004795674234628677,
-0.004683693405240774,
0.00018924086180049926,
0.0031277714297175407,
0.0008913049823604524,
-0.004473777953535318,
-0.001724284258671105,
-0.0028333605732768774,
-0.012188389897346497,
0.010255495086312294,
-0.003215413074940443,
0.0016575485933572054,
0.016353297978639603,
0.007810248993337154,
-0.012348049320280552,
0.007721279747784138,
0.012321255169808865,
-0.005994295701384544,
0.0028459380846470594,
0.005655511748045683,
-0.00734318932518363,
-0.01942606084048748,
-0.0011569078778848052,
-0.0137266730889678,
0.00403559161350131,
-0.0012746209977194667,
0.00532593484967947,
-0.007816320285201073,
0.003363531781360507,
0.009871205314993858,
-0.017116408795118332,
-0.0061424230225384235,
-0.01036891620606184,
0.006458502262830734,
0.0019561105873435736,
0.0009282536339014769,
-0.003494278294965625,
-0.0007508709677495062,
0.001279412186704576,
-0.006624290719628334,
-0.0003373610961716622,
0.005421420559287071,
0.0009499789448454976,
-0.0028574655298143625,
0.0014244456542655826,
-0.0036709459964185953,
0.0009618732728995383,
-0.0007439698674716055,
-0.009420763701200485,
0.0030374499037861824,
0.0015447934856638312,
-0.0012001789873465896,
-0.004303915426135063,
0.0011774643789976835,
-0.00010412294795969501,
-0.010158553719520569,
-0.010004671290516853,
-0.003893244545906782,
-0.0026669600047171116,
-0.005015314556658268,
-0.008084926754236221,
-0.004124565981328487,
-0.005268553737550974,
0.008695447817444801,
-0.009204016998410225,
0.010463451035320759,
0.004545506089925766,
0.00011014950723620132,
0.007300048600882292,
-0.001261981320567429,
0.005140597466379404,
0.0041240244172513485,
0.010366210713982582,
-0.003114426275715232,
-0.002276279032230377,
-0.009343191049993038,
0.009336893446743488,
-0.005377504974603653,
0.00012896703265141696,
0.016699818894267082,
0.004182681441307068,
0.007941022515296936,
-0.0007945875404402614,
-0.0014028297737240791,
0.0018961820751428604,
0.008008367381989956,
-0.01318657211959362,
0.008247705176472664,
-0.003881048643961549,
0.0019142189994454384,
0.007367469370365143,
-0.007224961183965206,
0.0033236390445381403,
0.014543329365551472,
0.0031318641267716885,
-0.005962655879557133,
-0.0031901653856039047,
0.0022239242680370808,
0.0006867005140520632,
-0.013848714530467987,
0.0013064091326668859,
-0.006823609117418528,
-0.0055932276882231236,
-0.0029293608386069536,
-0.0010466360254213214,
0.0003199647180736065,
0.007405558601021767,
-0.004712526220828295,
0.008513743989169598,
0.0009294591145589948,
-0.003319766139611602,
0.01197009440511465,
-0.0053290873765945435,
-0.002979803830385208,
0.004607575945556164,
0.0001248765183845535,
-0.0005439634551294148,
-0.003456923644989729,
-0.0075346617959439754,
0.0025214708875864744,
0.006177413277328014,
-0.00607198616489768,
-0.0053966958075761795,
-0.0013968541752547026,
-0.00309174507856369,
-0.010665715672075748,
0.0008673092816025019,
0.010994372889399529,
-0.0041735474951565266,
0.0042439959943294525,
0.0002365395921515301,
-0.009389408864080906,
-0.013064359314739704,
0.05047207325696945,
0.00036457180976867676,
0.006695192772895098,
0.0006893217214383185,
-0.004698800388723612,
-0.004522285424172878,
0.00033202796475961804,
0.004745257552713156,
-0.008868077769875526,
-0.00878580566495657,
0.007709656376391649,
-0.006742772646248341,
0.00609958590939641,
-0.0016567250713706017,
-0.0018111263634636998,
0.014204246923327446,
-0.0011444560950621963,
-0.011643131263554096,
-0.015998752787709236,
0.0007332012755796313,
-0.003486942034214735,
-0.0057396129705011845,
0.009180943481624126,
-0.004405557177960873,
-0.00363989919424057,
0.00436711311340332,
0.007061454001814127,
-0.000742361240554601,
-0.0018321130191907287,
-0.003183633554726839,
-0.001743571599945426,
0.0003298674710094929,
0.002076739212498069,
0.009516527876257896,
0.007848125882446766,
-0.00577872060239315,
0.00474596256390214,
-0.003665992757305503,
-0.0003665803524199873,
-0.0033080342691391706,
0.004174947738647461,
0.005480792373418808,
-0.0021375103387981653,
-0.00442335894331336,
0.005580201745033264,
0.0046568624675273895,
-0.0009728169534355402,
0.01228182204067707,
-0.0001362171897199005,
-0.002887340961024165,
0.005422560963779688,
0.003771075513213873,
-0.001082009170204401,
0.008976224809885025,
0.006662811152637005,
0.004527644719928503,
0.0024681261274963617,
-0.01145183201879263,
-0.017635704949498177,
-0.0013639298267662525,
0.012412241660058498,
0.003944020252674818,
-0.0024576818104833364,
-0.0009829087648540735,
0.002853075973689556,
0.0015129393432289362,
-0.0067334952764213085,
-0.011302434839308262,
-0.0009222273365594447,
0.0029167826287448406,
0.00833964440971613,
0.06728576123714447,
-0.0051384554244577885,
0.003477157559245825,
-0.007086803205311298,
0.00012430112110450864,
0.0010012147249653935,
-0.0013064795639365911,
0.002585629466921091,
0.0027119701262563467,
0.002737172646448016,
-0.0028724689036607742,
-0.00485602580010891,
-0.016286741942167282,
0.003723457455635071,
0.0006215312168933451,
-0.00231855153106153,
-0.0035554710775613785,
0.008717195130884647,
-0.005596501752734184,
-0.000363241444574669,
-0.011372106149792671,
0.0029172697104513645,
-0.0026509002782404423,
-0.009841126389801502,
-0.0007369235390797257,
-0.00618596700951457,
0.003615371650084853,
0.005462329834699631,
0.0033409628085792065,
-0.0028122004587203264,
0.005607511382550001,
0.000051294358854647726,
-0.00010979792568832636,
-0.0038367335218936205,
-0.0015338447410613298,
-0.0007353969849646091,
0.008234313689172268,
0.0018405853770673275,
-0.012927922420203686,
-0.008376725018024445,
-0.0009374587098136544,
0.0031138325575739145,
-0.009547067806124687,
0.010203422978520393,
0.0003366567543707788,
0.00622898293659091,
-0.005657866597175598,
-0.00389778520911932,
-0.005442025139927864,
0.0014635787811130285,
-0.005580849014222622,
0.003603601362556219,
-0.15482093393802643,
0.010220250114798546,
0.003152458695694804,
-0.002949551912024617,
-0.0011404339456930757,
-0.018927428871393204,
-0.007784699089825153,
0.00007012538117123768,
0.014045567251741886,
0.0010539668146520853,
-0.0013216095976531506,
0.004577556625008583,
0.004690263420343399,
0.0016803430626168847,
-0.0009375209920108318,
-0.006233689840883017,
0.0011659529991447926,
-0.004945777822285891,
0.0029588048346340656,
0.00016215082723647356,
0.008301280438899994,
0.008966256864368916,
-0.00046298952656798065,
0.002926942892372608,
0.000025547511540935375,
-0.005285772494971752,
0.0038165603764355183,
-0.0013755965046584606,
-0.00023570159100927413,
-0.011094897985458374,
-0.008488399907946587,
-0.004067667759954929,
-0.005566672421991825,
0.0016223167767748237,
0.005208139773458242,
-0.0007103472598828375,
0.009720731526613235,
0.002378099597990513,
-0.007656459230929613,
0.0026850863359868526,
-0.005205030553042889,
0.024607498198747635,
0.004467383027076721,
0.007345977704972029,
0.002068674424663186,
-0.009351694025099277,
-0.0067063248716294765,
0.01153042633086443,
0.0031056387815624475,
0.012357414700090885,
-0.016034316271543503,
0.0001620307011762634,
0.007688427343964577,
0.015990588814020157,
-0.0060639288276433945,
-0.01092528086155653,
-0.005834372714161873,
-0.003924504388123751,
-0.0020167457405477762,
0.006191224325448275,
0.010570666752755642,
-0.004706458188593388,
0.010911008343100548,
-0.002284553600475192,
-0.019578298553824425,
0.0039750151336193085,
-0.002578603569418192,
-0.005224121268838644,
-0.0042806328274309635,
0.006147726904600859,
0.007250125985592604,
0.0005997861735522747,
0.006323386915028095,
-0.0017606449546292424,
0.007261424325406551,
-0.0024901535362005234,
0.006808744743466377,
-0.0008272184641100466,
0.008331257849931717,
-0.008494775742292404,
0.00801803357899189,
-0.00792799610644579,
-0.0022372202947735786,
0.0021510112565010786,
-0.00241244793869555,
0.00688240397721529,
0.0050829253159463406,
-0.00014706510410178453,
-0.0016403270419687033,
-0.010003541596233845,
-0.006110810209065676,
0.005596198607236147,
0.0033664037473499775,
-0.008929645642638206,
0.0035010920837521553,
0.0016093722078949213,
0.005160687956959009,
0.008567207492887974,
-0.009184868074953556,
0.005739577580243349,
0.0026227948255836964,
-0.007989395409822464,
-0.0008209503721445799,
-0.0066238343715667725,
0.010998185724020004,
0.002182950731366873,
-0.005424031987786293,
-0.010247888043522835,
0.0006834962987340987,
-0.0019724785815924406,
-0.006489855702966452,
0.004393311683088541,
-0.013614235445857048,
-0.010134465992450714,
-0.0013898586621508002,
-0.006164981052279472,
-0.0024132272228598595
] |
8a3b3f3a85478c2b401e7083ce3f440c82013e30 | 987 | py | Python | mtp_api/apps/core/migrations/0004_token.py | ministryofjustice/mtp-api | b1c34c29e4aa9f48598cb060abe1368ae7686e0b | [
"MIT"
] | 5 | 2016-01-05T12:21:35.000Z | 2020-10-28T17:06:02.000Z | mtp_api/apps/core/migrations/0004_token.py | ministryofjustice/mtp-api | b1c34c29e4aa9f48598cb060abe1368ae7686e0b | [
"MIT"
] | 209 | 2015-06-12T09:39:41.000Z | 2022-03-21T16:01:19.000Z | mtp_api/apps/core/migrations/0004_token.py | ministryofjustice/mtp-api | b1c34c29e4aa9f48598cb060abe1368ae7686e0b | [
"MIT"
] | 1 | 2021-04-11T06:19:23.000Z | 2021-04-11T06:19:23.000Z | from django.db import migrations, models
import django.utils.timezone
import model_utils.fields
class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20180404_1515'),
]
operations = [
migrations.CreateModel(
name='Token',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('name', models.CharField(max_length=20, primary_key=True, serialize=False)),
('token', models.TextField()),
('expires', models.DateTimeField(blank=True, null=True)),
],
options={
'ordering': ('name',),
'permissions': (('view_token', 'Can view token'),),
},
),
]
| 37.961538 | 147 | 0.591692 | 1 | 0.8976 | [
0.002102968282997608,
0.02330811507999897,
0.00778445927426219,
0.0020082369446754456,
0.003640896873548627,
-0.003955533262342215,
-0.010540157556533813,
0.0038010496646165848,
-0.007887757383286953,
0.005826234817504883,
0.004067696165293455,
0.007202783599495888,
0.005251775495707989,
-0.016890546306967735,
0.0018471820512786508,
0.017923397943377495,
-0.053894661366939545,
0.003392779268324375,
-0.0038572698831558228,
0.0016672591445967555,
-0.005735951010137796,
0.0076371775940060616,
0.010771434754133224,
0.006612346041947603,
0.005600981879979372,
-0.002714515198022127,
0.008807685226202011,
0.0015685384860262275,
-0.006732690613716841,
-0.002833872102200985,
-0.0024395177606493235,
-0.002505843061953783,
-0.00562545470893383,
-0.008047773502767086,
0.007719012908637524,
-0.0027350953314453363,
0.0017877673963084817,
-0.02005315199494362,
0.010939115658402443,
-0.0036250376142561436,
-0.008027860894799232,
-0.020644279196858406,
-0.0029812490101903677,
0.001886998419649899,
-0.010100824758410454,
0.0027049584314227104,
-0.005211245268583298,
0.005402562208473682,
-0.013183113187551498,
0.005948080215603113,
-0.010632812976837158,
0.005758284125477076,
0.01315013226121664,
0.005015828646719456,
-0.006540409754961729,
-0.00869261659681797,
0.012902798131108284,
0.002328105503693223,
-0.011121305637061596,
0.0004450111882761121,
-0.002942122519016266,
-0.002173028653487563,
0.006633818615227938,
0.002404186874628067,
-0.019872989505529404,
-0.007167727220803499,
-0.003699505003169179,
0.002299534622579813,
0.00020848213171120733,
0.004572728183120489,
0.0002885462308768183,
-0.003036308800801635,
0.005660959053784609,
0.004305380862206221,
0.005897429771721363,
-0.0017957167001441121,
-0.0013274295488372445,
0.0015762262046337128,
0.009530763141810894,
0.0030417912639677525,
0.004150362219661474,
-0.007290975656360388,
0.006983890198171139,
0.00965078268200159,
0.016019631177186966,
0.007255891803652048,
0.020966513082385063,
-0.013483384624123573,
0.04544173926115036,
0.006292229983955622,
-0.010965874418616295,
0.003028587205335498,
-0.00750458799302578,
-0.000694079149980098,
-0.0026169689372181892,
-0.028447119519114494,
0.0031151268631219864,
-0.004783961921930313,
0.0014167986810207367,
0.002171821892261505,
-0.002002330496907234,
0.006363584194332361,
-0.0026531240437179804,
-0.0023406725376844406,
-0.008822168223559856,
0.013754657469689846,
-0.010707787238061428,
-0.0034416145645081997,
0.007216715253889561,
0.0023789454717189074,
-0.009901967830955982,
0.0012163498904556036,
0.0014396405313163996,
-0.015111559070646763,
0.003981768153607845,
0.00399757968261838,
-0.0044349124655127525,
0.053311411291360855,
0.00020008804858662188,
0.005319074261933565,
-0.0045661949552595615,
0.0005134720122441649,
-0.0014742823550477624,
0.005927564576268196,
0.006934201344847679,
-0.0035810284316539764,
0.010146294720470905,
0.007284084800630808,
0.003272213274613023,
0.007865255698561668,
-0.004513571038842201,
0.0073474375531077385,
-0.004496357403695583,
-0.003874103305861354,
0.0016530290013179183,
-0.008660195395350456,
0.0059218560345470905,
-0.002751632360741496,
-0.006110066547989845,
0.00022619953961111605,
-0.0025099541526287794,
-0.011451972648501396,
0.0007649816107004881,
-0.003971104975789785,
0.003684389404952526,
-0.013521559536457062,
-0.005981798749417067,
-0.0012740170350298285,
-0.00731640262529254,
0.0045837718062102795,
0.008265985175967216,
0.004578507039695978,
0.004065567161887884,
-0.005331514868885279,
-0.008321104571223259,
0.0017352463910356164,
-0.004028909839689732,
0.0014989409828558564,
0.005571268033236265,
0.004456981085240841,
-0.010824865661561489,
0.0004985810373909771,
0.0030608116649091244,
0.0066781239584088326,
-0.002610383788123727,
0.002147599123418331,
-0.009521390311419964,
0.00813403632491827,
0.000465843768324703,
0.0035482351668179035,
0.00870171282440424,
-0.0069809965789318085,
-0.00318884733133018,
0.0005310820997692645,
0.005204733461141586,
0.0008250715909525752,
0.0036099664866924286,
0.011575162410736084,
-0.0033369415905326605,
-0.005310902837663889,
0.0038000240456312895,
0.005744364112615585,
0.008556005544960499,
0.009051439352333546,
-0.0020988688338547945,
0.002445604419335723,
-0.004195011220872402,
-0.0018000046256929636,
0.007217442616820335,
-0.003996734973043203,
0.005742038134485483,
0.0023993821814656258,
-0.015896020457148552,
-0.006035949103534222,
0.0021659377962350845,
-0.009649716317653656,
0.0015081691090017557,
0.016393262892961502,
0.012729872949421406,
-0.0012447908520698547,
0.004507957957684994,
-0.007164905313402414,
0.002259971806779504,
0.006129524204879999,
0.0008312754216603935,
-0.011669105850160122,
-0.9560160636901855,
0.006325516849756241,
0.0030748683493584394,
0.0002560779685154557,
0.00350698153488338,
0.004757566377520561,
0.0011871429160237312,
0.0048234895803034306,
0.013271983712911606,
-0.00762634864076972,
-0.0027663796208798885,
-0.010408218950033188,
-0.011370903812348843,
0.0005598206771537662,
-0.009432168677449226,
-0.004571214318275452,
-0.005316817667335272,
-0.006985460873693228,
-0.0006976762088015676,
-0.005727687384933233,
-0.003277899930253625,
0.00798924919217825,
-0.001576719107106328,
0.005332320462912321,
0.0032990947365760803,
0.006418307311832905,
-0.0013285094173625112,
0.00000427838904215605,
-0.00019137896015308797,
0.0004277427797205746,
-0.010126936249434948,
-0.01564355380833149,
-0.006177063100039959,
-0.00035615978413261473,
0.010684700682759285,
0.0028503744397312403,
0.007748854346573353,
-0.001206821296364069,
0.003025296377018094,
-0.00928773544728756,
0.0035734521225094795,
-0.000843193382024765,
0.003141358494758606,
-0.02673816680908203,
0.004092234652489424,
-0.001109797740355134,
-0.006239685229957104,
0.0077425227500498295,
0.0009632670553401113,
-0.0008919771644286811,
-0.0026910328306257725,
-0.002917738165706396,
0.008813787251710892,
-0.007478602696210146,
0.0059509798884391785,
-0.005846507381647825,
-0.00887665618211031,
-0.0037917951121926308,
-0.010059800930321217,
0.0022731830831617117,
0.004821450915187597,
-0.005597136449068785,
-0.004282579757273197,
-0.0027499361895024776,
0.0005725908558815718,
0.002405438804998994,
0.0012733291368931532,
-0.01862918585538864,
-0.007977492175996304,
-0.0007907121325843036,
0.0026904663536697626,
-0.006721838377416134,
-0.006495233625173569,
0.00655628414824605,
-0.010670339688658714,
0.008202495984733105,
0.0032589680049568415,
0.000489474565256387,
-0.011221927590668201,
0.004303194582462311,
-0.009700515307486057,
-0.008266959339380264,
0.0017245726194232702,
-0.006516048684716225,
-0.00565410265699029,
-0.00027725560357794166,
0.0022294807713478804,
0.008380509912967682,
-0.005091555416584015,
0.005523516330868006,
0.011844736523926258,
-0.002715970855206251,
-0.008438306860625744,
0.008661187253892422,
0.008823010139167309,
0.0009475515689700842,
-0.003785747103393078,
0.0016034959116950631,
0.009880244731903076,
0.006570354104042053,
0.004442218225449324,
0.006054794415831566,
0.001086898846551776,
0.010961556807160378,
-0.0011616589035838842,
0.0013060083147138357,
-0.004461454227566719,
-0.002902318025007844,
-0.004246537573635578,
-0.001013446832075715,
-0.0028790291398763657,
-0.0029961371328681707,
-0.014383437111973763,
-0.008557499386370182,
-0.002988639986142516,
0.001468934235163033,
-0.00026734909624792635,
-0.001464005676098168,
0.0009720053640194237,
0.004261121619492769,
0.00910414382815361,
-0.002398650161921978,
-0.002929429057985544,
0.00088025868171826,
0.001989869400858879,
-0.007454747799783945,
0.016530314460396767,
-0.012777553871273994,
0.005604536738246679,
0.000578048056922853,
-0.015632417052984238,
0.006806252058595419,
0.01154415588825941,
-0.010409497655928135,
0.0025325044989585876,
0.00369482534006238,
0.0034631062299013138,
-0.0005938131362199783,
-0.0048468830063939095,
-0.0027054552920162678,
-0.015727464109659195,
-0.0020351724233478308,
0.020875079557299614,
0.0027626394294202328,
0.010001757182180882,
0.011643552221357822,
-0.004439942538738251,
0.0015435393434017897,
0.003927900921553373,
0.0001055376123986207,
0.013292386196553707,
-0.010510541498661041,
-0.002579358173534274,
0.003380493028089404,
-0.004716996569186449,
0.0004847402742598206,
0.006384799722582102,
0.005409987177699804,
-0.0020126737654209137,
0.0016201274702325463,
-0.006078438833355904,
-0.0040727416053414345,
-0.018359484151005745,
0.000034423559554852545,
0.010727870278060436,
-0.00483426870778203,
0.004256037995219231,
-0.01208510622382164,
0.00826993491500616,
0.004293983802199364,
0.00013269434566609561,
0.00103082787245512,
-0.003168911673128605,
0.00738284969702363,
0.013501630164682865,
-0.0069496347568929195,
0.003277621464803815,
0.0013274203520268202,
0.000285096000880003,
-0.0006545782089233398,
0.009988026693463326,
-0.008986582979559898,
-0.003677493194118142,
0.0018181682098656893,
0.004265167284756899,
-0.0003149723052047193,
-0.0030302058439701796,
-0.00827653519809246,
-0.0020547653548419476,
0.003377632237970829,
-0.0045719207264482975,
0.0061543844640254974,
0.003441873239353299,
0.004319966305047274,
-0.0035508747678250074,
0.0014553666114807129,
-0.005488378461450338,
-0.010980768129229546,
0.011878740042448044,
-0.002773957559838891,
0.0034120904747396708,
0.011409178376197815,
0.0031256310176104307,
-0.013206107541918755,
0.005769109353423119,
0.008160260505974293,
-0.004454236943274736,
0.00441166153177619,
0.007051342166960239,
-0.006175675429403782,
-0.02584368735551834,
-0.0010410905815660954,
-0.013098534196615219,
0.005602549761533737,
-0.001553685637190938,
0.005589441396296024,
-0.005489318631589413,
0.007481891196221113,
0.006055739708244801,
-0.014139649458229542,
-0.006284666247665882,
-0.009327282197773457,
0.010126188397407532,
-0.000141105119837448,
-0.0023413158487528563,
-0.0045227049849927425,
-0.0011981385760009289,
-0.00398631114512682,
-0.0010566763812676072,
-0.0033980929292738438,
0.005370365455746651,
0.0013767280615866184,
-0.006639746483415365,
-0.00011360870121279731,
-0.005157161969691515,
-0.0008354288875125349,
0.004753747954964638,
-0.010544734075665474,
0.003759265411645174,
0.004562923219054937,
-0.004115480929613113,
-0.004825999028980732,
0.00004060426363139413,
0.0009052659734152257,
-0.008452213369309902,
-0.011086499318480492,
-0.0029665427282452583,
-0.003778384765610099,
-0.0043398551642894745,
-0.010493488982319832,
-0.0012158744502812624,
-0.009699324145913124,
0.0025912451092153788,
-0.007484602276235819,
0.006683011073619127,
0.005073780659586191,
-0.005691394209861755,
0.007850905880331993,
-0.0027341421227902174,
0.004108621273189783,
0.00679812952876091,
0.008536196313798428,
-0.0024505627807229757,
-0.005457612220197916,
-0.008118532598018646,
0.010962695814669132,
-0.009309704415500164,
-0.001404790673404932,
0.014786812476813793,
0.004291577730327845,
0.009192741475999355,
0.0013691894710063934,
-0.00025537057081237435,
0.003760972060263157,
0.006829301360994577,
-0.015996403992176056,
0.0017404385143890977,
-0.0020767832174897194,
-0.0012248835992068052,
0.0048474702052772045,
-0.006124147679656744,
0.00212326692417264,
0.008197532035410404,
0.0027427172753959894,
-0.008145150728523731,
-0.0035687105264514685,
0.0007159449742175639,
0.006171086803078651,
-0.011717488057911396,
0.000338333920808509,
-0.004503251053392887,
-0.0038942815735936165,
-0.003554938593879342,
-0.005837509874254465,
-0.0009268525172956288,
0.005083587486296892,
-0.006096189375966787,
0.0063962507992982864,
0.001614433596841991,
-0.005640452262014151,
0.013265136629343033,
-0.00801222026348114,
-0.005854496266692877,
0.00024319229123648256,
-0.0006561898626387119,
-0.0036550024524331093,
-0.008585121482610703,
-0.0058308192528784275,
0.0018627988174557686,
0.002315556164830923,
-0.0018353647319599986,
-0.007458406966179609,
-0.000012214081834827084,
0.0008458594093099236,
-0.010567153804004192,
0.004507214762270451,
0.01138344407081604,
0.00040992311551235616,
0.004343661479651928,
-0.0029683937318623066,
-0.009280648082494736,
-0.015879837796092033,
0.05506717786192894,
-0.0016958963824436069,
0.005819342564791441,
0.004246281459927559,
-0.005872613750398159,
-0.0021863230504095554,
-0.0006266108248382807,
0.007353943772614002,
-0.006054655183106661,
-0.006650824099779129,
0.008921931497752666,
-0.0028149629943072796,
0.0038443533703684807,
-0.0007050042040646076,
-0.0007297230185940862,
0.01514110341668129,
-0.00655512697994709,
-0.016945667564868927,
-0.015428370796144009,
0.008634306490421295,
-0.00303145800717175,
-0.006752200424671173,
0.010885452851653099,
-0.00109804084058851,
-0.0032309298403561115,
0.0025220499373972416,
0.007989072240889072,
0.0026717616710811853,
-0.0008517686510458589,
-0.0034610785078257322,
-0.0007776062120683491,
0.0006182899232953787,
0.0033979546278715134,
0.006443708669394255,
0.00807949248701334,
-0.002257778076454997,
0.006151645909994841,
-0.006881507113575935,
-0.0004356594290584326,
0.0005109946941956878,
0.005762879271060228,
0.006042220629751682,
-0.000823869660962373,
0.000001481731487729121,
0.004478150513023138,
0.004957486409693956,
0.0008123308070935309,
0.011611290276050568,
0.0007487265393137932,
-0.004502003081142902,
0.011464793235063553,
0.007912847213447094,
-0.00026365171652287245,
0.00768075929954648,
-0.0034356822725385427,
0.004565470386296511,
0.0025107937399297953,
-0.007786809001117945,
-0.014280111528933048,
-0.003279984463006258,
0.006924546789377928,
0.005267633590847254,
-0.003024069592356682,
0.0034936864394694567,
-0.002185510704293847,
-0.00253131496720016,
-0.006061420775949955,
-0.004988972097635269,
-0.005422605201601982,
0.000388622866012156,
0.007411816623061895,
0.06929542124271393,
-0.007833926007151604,
-0.0021618972532451153,
-0.007627122104167938,
0.0008565964526496828,
-0.0016845115460455418,
-0.001999752363190055,
0.0024550417438149452,
-0.001110643264837563,
0.0038282510358840227,
0.0012427777983248234,
-0.007133644074201584,
-0.00972809735685587,
0.0023345290683209896,
0.001377480453811586,
-0.002459934912621975,
0.0024950101505964994,
0.004353321623057127,
-0.010200745426118374,
0.0034135410096496344,
-0.011924201622605324,
-0.0060614594258368015,
-0.004197247792035341,
-0.008061569184064865,
-0.002061489736661315,
-0.004715616814792156,
-0.0013048829277977347,
0.002828855300322175,
0.007853320799767971,
-0.003298963885754347,
0.007919196039438248,
-0.00294544012285769,
0.000780827016569674,
-0.0038967328146100044,
0.00010969414870487526,
-0.005568582098931074,
0.007267144974321127,
0.0008356395992450416,
-0.008621832355856895,
-0.0038163773715496063,
-0.004116646479815245,
-0.0016693667275831103,
-0.005883353762328625,
0.002118640346452594,
-0.0007550393929705024,
0.008042283356189728,
-0.0012046289630234241,
0.0020260708406567574,
-0.0024096332490444183,
0.0014611475635319948,
-0.013808779418468475,
0.0057848612777888775,
-0.18197913467884064,
0.007739535067230463,
0.0019440881442278624,
-0.006805815733969212,
-0.004370482638478279,
-0.013985712081193924,
-0.0061790612526237965,
0.006667635403573513,
0.008801746182143688,
0.0024994718842208385,
-0.0033175137359648943,
-0.0016635932261124253,
0.0027411936316639185,
0.004058948252350092,
-0.0027926152106374502,
-0.007529459428042173,
0.0036551642697304487,
-0.005711499135941267,
-0.00006829688209109008,
0.0047167097218334675,
0.004889210220426321,
0.010043090209364891,
0.00015822304703760892,
0.0009949016384780407,
0.0009442486916668713,
-0.005170799791812897,
0.008165069855749607,
-0.004842799156904221,
0.004639464430510998,
-0.009758452884852886,
-0.0045332880690693855,
-0.005524848122149706,
-0.0037386580370366573,
0.0019962280057370663,
0.0035722902975976467,
0.0009929181542247534,
0.008340277709066868,
0.00008141915168380365,
-0.007842916995286942,
0.0072655025869607925,
-0.009199568070471287,
0.02740955911576748,
0.005830479320138693,
0.006446738261729479,
0.002192046493291855,
-0.00495920330286026,
-0.0033920668065547943,
0.007986146956682205,
0.0033515654504299164,
0.012278228998184204,
-0.013593785464763641,
-0.004625242669135332,
0.002439203904941678,
0.019130516797304153,
-0.005107181612402201,
-0.010512205772101879,
-0.007966387085616589,
-0.005968265701085329,
0.000805061194114387,
0.007830223999917507,
0.009071389213204384,
-0.003205002285540104,
0.009254875592887402,
-0.0027079270221292973,
-0.022721905261278152,
0.0029816601891070604,
-0.002947218483313918,
-0.00906799640506506,
0.0039057566318660975,
0.006086684297770262,
0.010515972040593624,
-0.0020353554282337427,
0.003409659257158637,
0.0003570184635464102,
0.003999600186944008,
-0.0002278133761137724,
0.00968034565448761,
0.0013151458697393537,
0.006113727577030659,
-0.007688434328883886,
0.007477885577827692,
-0.006696091033518314,
-0.003253681119531393,
0.0029841712675988674,
-0.002615180565044284,
0.010409035719931126,
0.00376481213606894,
-0.002288977848365903,
-0.00010051089338958263,
-0.008065297268331051,
-0.0017736173467710614,
0.0025396961718797684,
0.0015965632628649473,
-0.007531037554144859,
0.0018062046729028225,
0.001946068019606173,
0.004021432716399431,
0.008120293729007244,
-0.008626886643469334,
0.007621874567121267,
0.003444002941250801,
-0.004920470528304577,
0.00008051482291193679,
-0.005464284215122461,
0.0033934565726667643,
0.0018329217564314604,
-0.005413282196968794,
-0.005583784077316523,
-0.00001588151280884631,
-0.0051232692785561085,
-0.005035096779465675,
0.007510486990213394,
-0.010723982006311417,
-0.010227757506072521,
-0.0009224548703059554,
-0.0096213323995471,
0.0025546960532665253
] |
8a3c0f03126e25cbd17946a5a7c81e22d30b3f4d | 821 | py | Python | palm_tree/coconut_1/models.py | m-hintz-42/a-palm-tree | 57656874335f4dfae13cf720668f2c5391621618 | [
"MIT"
] | null | null | null | palm_tree/coconut_1/models.py | m-hintz-42/a-palm-tree | 57656874335f4dfae13cf720668f2c5391621618 | [
"MIT"
] | null | null | null | palm_tree/coconut_1/models.py | m-hintz-42/a-palm-tree | 57656874335f4dfae13cf720668f2c5391621618 | [
"MIT"
] | null | null | null | from palm_tree import db
class Data(db.Model):
id = db.Column(db.Integer, primary_key=True)
uuid = db.Column(db.Integer)
response = db.Column(db.Text)
datetime = db.Column(db.DateTime)
def __init__(self, uuid, response, datetime):
self.uuid = uuid
self.response = response
self.datetime = datetime
def __repr__(self):
return '<Data %r>' % self.response
#
# class Logs(db.Model):
# id = db.Column(db.Integer, primary_key=True)
# uuid = db.Column(db.Integer)
# payload = db.Column(db.Text)
# datetime = db.Column(db.DateTime)
#
# def __init__(self, uuid, payload, datetime):
# self.uuid = uuid
# self.payload = payload
# self.datetime = datetime
#
# def __repr__(self):
# return '<Data %r>' % self.payload
| 25.65625 | 50 | 0.613886 | 1 | 0.9201 | [
-0.00007380460010608658,
0.023522790521383286,
0.005680890288203955,
0.0015849644551053643,
0.004627750255167484,
-0.0023992813657969236,
-0.009129323065280914,
0.002397495321929455,
-0.006777709815651178,
0.0023655614349991083,
0.0029982535634189844,
0.005941685754805803,
0.0071149119175970554,
-0.013970620930194855,
-0.0006436359253711998,
0.01635715179145336,
-0.05396733805537224,
0.004819127731025219,
-0.004477327689528465,
0.0010908010881394148,
-0.006385703571140766,
0.007356648799031973,
0.0088495509698987,
0.005087024532258511,
0.006506182253360748,
-0.0017503633862361312,
0.010267817415297031,
0.0026205014437437057,
-0.006423654034733772,
-0.004755367524921894,
-0.0013086970429867506,
-0.0008372505544684827,
-0.005499767605215311,
-0.006267664022743702,
0.0071362596936523914,
-0.003893171902745962,
-0.00003261772872065194,
-0.02022378146648407,
0.013212988153100014,
-0.004782568663358688,
-0.005105574615299702,
-0.015039706602692604,
-0.0017304124776273966,
0.0024241080973297358,
-0.009282199665904045,
0.0025283147115260363,
-0.004469119478017092,
0.005825852043926716,
-0.013179213739931583,
0.0046608783304691315,
-0.008892095647752285,
0.006093974225223064,
0.014399930834770203,
0.002225177362561226,
-0.007378654554486275,
-0.007161231711506844,
0.012016910128295422,
0.0025370775256305933,
-0.010758167132735252,
-0.00040630187140777707,
-0.005901386495679617,
-0.0036922835279256105,
0.0050073959864676,
0.0038305921480059624,
-0.014218316413462162,
-0.0066040996462106705,
-0.0028908252716064453,
0.002770101884379983,
-0.0029019294306635857,
0.0063253785483539104,
0.00031777870026417077,
9.83598056336632e-7,
0.004654792137444019,
0.0037931499537080526,
0.004014279693365097,
-0.004965104162693024,
-0.0010856130393221974,
0.0011878273217007518,
0.008691167458891869,
0.004220449365675449,
0.004856131970882416,
-0.00835727620869875,
0.00654458487406373,
0.008765053004026413,
0.014099054969847202,
0.009617457166314125,
0.01813511550426483,
-0.01107551995664835,
0.04625861346721649,
0.009249676018953323,
-0.011240082792937756,
0.0025010176468640566,
-0.010283038951456547,
-0.001812874572351575,
-0.005272758658975363,
-0.029372556135058403,
0.0009684633114375174,
-0.004190199542790651,
-0.0007800464518368244,
0.002169162267819047,
0.0004938549245707691,
0.008073177188634872,
0.0011797077022492886,
-0.002403746824711561,
-0.006754747591912746,
0.00967628788203001,
-0.010708918794989586,
-0.0031283432617783546,
0.005719187669456005,
0.002000638283789158,
-0.011326026171445847,
-0.0011221410240978003,
0.00242359540425241,
-0.012608533725142479,
0.004630133043974638,
0.001660299370996654,
-0.006182962097227573,
0.05503712594509125,
-0.00003138772081001662,
0.004425344988703728,
-0.004200976807624102,
0.00034219244844280183,
0.0006754346541129053,
0.004779635928571224,
0.00899510458111763,
-0.002929533366113901,
0.013633874244987965,
0.007816125638782978,
0.005927616730332375,
0.008435691706836224,
-0.0007861537160351872,
0.006566626485437155,
-0.0021721688099205494,
-0.003124558599665761,
0.0010156441712751985,
-0.008680297993123531,
0.003815557574853301,
-0.002932278672233224,
-0.010277586057782173,
-0.00003933190964744426,
0.0008971862262114882,
-0.010512682609260082,
-0.00010255970119033009,
-0.002941200276836753,
0.0030658200848847628,
-0.011381734162569046,
-0.003002213779836893,
-0.0028141597285866737,
-0.006362162064760923,
0.0022486336529254913,
0.008446416817605495,
0.002500547096133232,
0.004154536873102188,
-0.004266765434294939,
-0.009192024357616901,
-0.00027743823011405766,
-0.004522876348346472,
0.0016126760747283697,
0.008311007171869278,
0.0036211370024830103,
-0.011638857424259186,
-0.002846188610419631,
0.002463920507580042,
0.002636066172271967,
-0.0010596697684377432,
0.003870563581585884,
-0.008019287139177322,
0.007831556722521782,
0.0024863213766366243,
0.0035560019314289093,
0.012240325100719929,
-0.0033934335224330425,
-0.0006029594223946333,
0.00009024313476402313,
0.0035504510160535574,
-0.0015749756712466478,
0.006430961657315493,
0.008061066269874573,
-0.0034147838596254587,
-0.006408691871911287,
0.004441398661583662,
0.006166489794850349,
0.010018967092037201,
0.006447136402130127,
-0.0034395414404571056,
0.0035498447250574827,
-0.004996016155928373,
-0.0046509201638400555,
0.0067404103465378284,
-0.0033716463949531317,
0.007040268275886774,
0.003687787801027298,
-0.010775724425911903,
-0.007908791303634644,
0.0006003822200000286,
-0.007169033866375685,
-0.00007456412276951596,
0.014026830904185772,
0.013065160252153873,
-0.003137263935059309,
0.004888779483735561,
-0.008824847638607025,
0.0006561078480444849,
0.004950668662786484,
0.003782562678679824,
-0.01309246476739645,
-0.9583947062492371,
0.0080278180539608,
0.0034315739758312702,
-0.0006633498123846948,
0.0049421354196965694,
0.00350603717379272,
0.004812592174857855,
0.0022775745019316673,
0.014300341717898846,
-0.00982493907213211,
-0.007523809559643269,
-0.010981505736708641,
-0.010692340321838856,
-0.00016309246711898595,
-0.007344115991145372,
-0.0028891272377222776,
-0.0058798398822546005,
-0.006016718689352274,
-0.002705453196540475,
-0.0037305415607988834,
-0.0039130039513111115,
0.010246116667985916,
-0.0006329260068014264,
0.004660890903323889,
0.0020957901142537594,
0.006265256553888321,
-0.005399065557867289,
-0.0018057671841233969,
-0.0016151985619217157,
-0.0016207852168008685,
-0.005782096181064844,
-0.01447742898017168,
-0.0031484654173254967,
-0.001758694532327354,
0.013082637451589108,
0.0018083922332152724,
0.007575339172035456,
-0.0003239602083340287,
0.0012275571934878826,
-0.009330696426331997,
0.006004981696605682,
-0.0002953168877866119,
0.004160338081419468,
-0.030493784695863724,
0.0009227072005160153,
-0.0024220163468271494,
-0.008448110893368721,
0.009484972804784775,
0.0021390400361269712,
-0.0010304423049092293,
-0.0026326568331569433,
-0.004975518211722374,
0.009075541980564594,
-0.007697064895182848,
0.0051849354058504105,
-0.0046452684327960014,
-0.009056035429239273,
-0.0036410356406122446,
-0.008838539943099022,
0.00044375209836289287,
0.003990669269114733,
-0.0022974321618676186,
-0.004996090196073055,
-0.0025442740879952908,
0.0018456305842846632,
0.0033144790213555098,
0.000002835414534274605,
-0.01891922391951084,
-0.007341113407164812,
-0.0007718245033174753,
0.00033930421341210604,
-0.004716001451015472,
-0.0032920059747993946,
0.003932517021894455,
-0.011456619948148727,
0.007168959826231003,
0.001824650214985013,
-0.0005804301472380757,
-0.011318500153720379,
-0.000447977043222636,
-0.009179717861115932,
-0.00753282243385911,
0.002745578298345208,
-0.006667353678494692,
-0.004411952570080757,
0.0007162545807659626,
0.0020210049115121365,
0.006858489476144314,
-0.003654147731140256,
0.003337038215249777,
0.013530230149626732,
-0.0026349504478275776,
-0.006830725818872452,
0.008147312328219414,
0.007864067330956459,
0.0017100860131904483,
-0.0025526052340865135,
0.002643200568854809,
0.008559752255678177,
0.00847262516617775,
0.0036341268569231033,
0.004866199567914009,
0.001438613748177886,
0.011525738053023815,
-0.0015480471774935722,
0.0008704452775418758,
-0.004405373707413673,
-0.0003260089142713696,
-0.003464719280600548,
-0.00275465939193964,
-0.0035519322846084833,
-0.002302768873050809,
-0.01297784224152565,
-0.008525105193257332,
-0.0037100010085850954,
-0.0008461292018182576,
0.0009869849309325218,
-0.0034907532390207052,
-0.0003026554477401078,
0.0029206189792603254,
0.009237573482096195,
0.003999125212430954,
-0.0004100976511836052,
-0.00019993635942228138,
0.0024479557760059834,
-0.007681421469897032,
0.01418325025588274,
-0.014650051482021809,
0.007889185100793839,
0.00007110121805453673,
-0.015124592930078506,
0.007209794595837593,
0.011771239340305328,
-0.009807789698243141,
0.0026911005843430758,
0.004711919464170933,
0.0016136105405166745,
-0.0016446049557998776,
-0.006691157817840576,
-0.0029575657099485397,
-0.01677943952381611,
-0.0015142366755753756,
0.01936502940952778,
-0.0005514032091014087,
0.010300867259502411,
0.009923196397721767,
-0.004246255848556757,
0.001156786922365427,
0.0070416564121842384,
0.002724689431488514,
0.011947780847549438,
-0.008188212290406227,
-0.0011133785592392087,
0.0026116857770830393,
-0.007451443932950497,
0.0010939404601231217,
0.006436418276280165,
0.0045624696649611,
-0.0017382438527420163,
0.0010991692543029785,
-0.009303080849349499,
-0.005605856887996197,
-0.016902387142181396,
-0.0033855366054922342,
0.008416549302637577,
-0.005331016145646572,
0.005350963212549686,
-0.013077029958367348,
0.005509600508958101,
0.005341905634850264,
0.004381223581731319,
-0.0006546089425683022,
-0.001129521057009697,
0.0056786383502185345,
0.012778069823980331,
-0.007897722534835339,
0.003355539171025157,
0.0012436691904440522,
-0.002995138056576252,
0.0014105497393757105,
0.011270417831838131,
-0.00866708718240261,
-0.00541685102507472,
0.0035909172147512436,
0.0027813557535409927,
0.001974775455892086,
-0.0027576510328799486,
-0.0058334157802164555,
-0.0046607814729213715,
0.0016675661318004131,
-0.006742710713297129,
0.0028401652816683054,
0.0021337938960641623,
0.0025627375580370426,
-0.008004900068044662,
-0.002138732001185417,
-0.00007495584577554837,
-0.012611081823706627,
0.010143388994038105,
-0.0031125328969210386,
0.0023444003891199827,
0.012709759175777435,
0.005891553591936827,
-0.012271068058907986,
0.004729545209556818,
0.010300207883119583,
-0.0020669151563197374,
0.004555121995508671,
0.007271412760019302,
-0.0058685713447630405,
-0.02245810627937317,
-0.0021093448158353567,
-0.015354970470070839,
0.005477902013808489,
-0.003667909884825349,
0.0068647670559585094,
-0.006643660366535187,
0.008650606498122215,
0.006271424703299999,
-0.013310405425727367,
-0.00691103795543313,
-0.008326365612447262,
0.008869243785738945,
-0.0007804272463545203,
0.0002978603297378868,
-0.003666952485218644,
-0.0024989056400954723,
-0.00325214141048491,
-0.0024095114786177874,
-0.0028398374561220407,
0.006889317184686661,
0.001967326970770955,
-0.0036419278476387262,
0.0014181905426084995,
-0.005379630718380213,
0.00045041844714432955,
0.003179164370521903,
-0.011420144699513912,
0.002271544886752963,
0.006275310181081295,
-0.002774936845526099,
-0.0038130339235067368,
0.001352887600660324,
-0.0008824219112284482,
-0.0073957862332463264,
-0.012074282392859459,
-0.0015642663929611444,
-0.002723997924476862,
-0.004393152426928282,
-0.010229279287159443,
-0.0038298077415674925,
-0.0062248241156339645,
0.005123321898281574,
-0.00823275838047266,
0.009340217337012291,
0.005906268488615751,
-0.0028265665750950575,
0.007006813306361437,
-0.0022490574046969414,
0.005141666624695063,
0.004565696697682142,
0.004139404743909836,
0.001174015924334526,
-0.004792137537151575,
-0.009898437187075615,
0.01016294490545988,
-0.00888177752494812,
0.00032487857970409095,
0.013400624506175518,
0.004981540143489838,
0.008440438657999039,
-0.002845434471964836,
-0.0014503911370411515,
0.0022144692484289408,
0.007392894942313433,
-0.014261557720601559,
0.0038980823010206223,
-0.0022981753572821617,
-0.0003313500201329589,
0.004863454960286617,
-0.005907421000301838,
-0.00035229488275945187,
0.009380836971104145,
0.004214059095829725,
-0.009208958595991135,
-0.0031412134412676096,
0.0011842125095427036,
0.0025662591215223074,
-0.010697094723582268,
0.0006277234642766416,
-0.003264141269028187,
-0.005229291971772909,
-0.0014487397857010365,
-0.003962689079344273,
0.00018151789845433086,
0.003975095227360725,
0.0008651076932437718,
0.00515160383656621,
0.0020317109301686287,
-0.004601420368999243,
0.01357379462569952,
-0.004295745398849249,
-0.005564951803535223,
0.0010795361595228314,
0.0007089449209161103,
-0.0035518903750926256,
-0.00887236837297678,
-0.0020960194524377584,
0.0029630307108163834,
0.006581387482583523,
-0.00250016781501472,
-0.005791819654405117,
-0.0006093422416597605,
0.0013595930067822337,
-0.01172576006501913,
0.0031163834501057863,
0.009770667180418968,
-0.0010234080255031586,
0.007403873372823,
-0.0002743455406744033,
-0.009028333239257336,
-0.013105113990604877,
0.05251646786928177,
-0.00225659622810781,
0.002446016762405634,
0.003542638150975108,
-0.005999601446092129,
-0.0024989007506519556,
-0.00326037360355258,
0.007749534677714109,
-0.0063544875010848045,
-0.004807921126484871,
0.00633812602609396,
-0.00388070335611701,
0.004498653579503298,
0.0035854617599397898,
-0.0029509137384593487,
0.014746131375432014,
-0.0038991705514490604,
-0.014565682969987392,
-0.018002592027187347,
0.005466349422931671,
-0.001734859892167151,
-0.0071968743577599525,
0.009216811507940292,
0.0004913712036795914,
-0.004009881988167763,
0.0010497953044250607,
0.006125533953309059,
0.0031426874920725822,
-0.002498957561329007,
-0.001992290373891592,
-0.002237384906038642,
-0.001466094283387065,
0.0035632241051644087,
0.0042564114555716515,
0.008504191413521767,
-0.0029585103038698435,
0.004039174877107143,
-0.003844150109216571,
-0.0014068458694964647,
-0.0006141720223240554,
0.003713404992595315,
0.0056814588606357574,
-0.0005056396475993097,
-0.0021579237654805183,
0.005519886501133442,
0.005172408651560545,
0.001569048617966473,
0.010591820813715458,
0.00016250333283096552,
-0.005653651896864176,
0.008382543921470642,
0.006608209572732449,
0.0009298374061472714,
0.009180683642625809,
-0.002329613082110882,
0.004740030504763126,
0.0023260365705937147,
-0.009288134053349495,
-0.014938673935830593,
-0.003329948987811804,
0.0068757785484194756,
0.007717576343566179,
0.00024274065799545497,
0.0017649512737989426,
0.0015740491217002273,
-0.0017803021473810077,
-0.008303338661789894,
-0.005209135822951794,
-0.006319505162537098,
0.0016134378965944052,
0.004391924943774939,
0.06874265521764755,
-0.006662202998995781,
-0.0021728407591581345,
-0.009929172694683075,
-0.0012568901292979717,
-0.003255425952374935,
-0.001408272422850132,
0.0004377519362606108,
-0.0031381442677229643,
0.0011784512316808105,
-0.00019524832896422595,
-0.008957735262811184,
-0.010752955451607704,
0.0009702611132524908,
0.0018587438389658928,
-0.003656419925391674,
0.002645461354404688,
0.00527232838794589,
-0.008858242072165012,
0.004027379676699638,
-0.013281350024044514,
-0.0026969052851200104,
-0.002128084423020482,
-0.009272433817386627,
-0.003844647668302059,
-0.0033317666966468096,
0.0029246376361697912,
0.004003079608082771,
0.007214440032839775,
-0.004301727749407291,
0.0057617295533418655,
-0.0015346485888585448,
-0.0007399132009595633,
-0.004635580349713564,
-0.0023874707985669374,
-0.006958412937819958,
0.008395488373935223,
-0.00018367079610470682,
-0.01093680877238512,
-0.003155825426802039,
0.0005143911694176495,
-0.002888523740693927,
-0.006988621316850185,
0.004041996318846941,
0.0008048642775975168,
0.004266299773007631,
-0.0018640619236975908,
0.00262117269448936,
-0.005142915993928909,
0.000989300082437694,
-0.013472315855324268,
0.006571024656295776,
-0.1734117716550827,
0.011038427241146564,
0.004705851431936026,
-0.006167971063405275,
-0.004857092164456844,
-0.01679498516023159,
-0.0054921433329582214,
0.006190881133079529,
0.009983555413782597,
0.0025470091495662928,
-0.0027342268731445074,
-0.0007448717369697988,
0.006226345431059599,
0.00285645155236125,
-0.0021291542798280716,
-0.0060783675871789455,
0.0026920936070382595,
-0.004861077293753624,
0.0014519015094265342,
0.005853709764778614,
0.004917911719530821,
0.0097328657284379,
-0.002293994650244713,
0.0030535166151821613,
-0.000006717746600770624,
-0.002424296922981739,
0.006572007667273283,
-0.0006322496919892728,
0.00513231847435236,
-0.01095399260520935,
-0.002849031938239932,
-0.0053148721344769,
-0.005760084837675095,
0.002901047468185425,
0.0023124285507947206,
0.0001585797144798562,
0.010201700031757355,
0.0013182550901547074,
-0.005490388721227646,
0.010343428701162338,
-0.006883630529046059,
0.0284044798463583,
0.006201914045959711,
0.005595274735242128,
-0.0003909042861778289,
-0.006461114622652531,
-0.006054523400962353,
0.007792158983647823,
0.0013993199681863189,
0.012314089573919773,
-0.013547246344387531,
0.00038291438249871135,
0.003574099624529481,
0.018008606508374214,
-0.00574242789298296,
-0.010292001068592072,
-0.006968721281737089,
-0.002751086140051484,
0.002036693971604109,
0.007021763361990452,
0.011007207445800304,
-0.004307302180677652,
0.00919001828879118,
-0.004416629206389189,
-0.022423813119530678,
0.004761979915201664,
-0.0023276566062122583,
-0.005873006768524647,
0.004347323905676603,
0.0044090100564062595,
0.00696219690144062,
-0.0025336171966046095,
0.0035666520707309246,
0.0013267769245430827,
0.005284403916448355,
-0.00023474212503060699,
0.007917099632322788,
-0.0025754438247531652,
0.005223239306360483,
-0.007644686382263899,
0.00856365542858839,
-0.009610186330974102,
-0.00046916352584958076,
0.004667757079005241,
-0.0038562545087188482,
0.01037906575948,
0.004953558556735516,
-0.0011652038665488362,
-0.000999491661787033,
-0.010219271294772625,
-0.0035236990079283714,
0.0017978207906708121,
0.0018946097698062658,
-0.006713309790939093,
0.001799148740246892,
0.0017447584541514516,
0.005932120606303215,
0.007386223878711462,
-0.007167551200836897,
0.006652360316365957,
0.005403673276305199,
-0.005237033125013113,
-0.00012592885468620807,
-0.004919934086501598,
0.005086467135697603,
0.0036249954719096422,
-0.007969792000949383,
-0.006131559144705534,
0.002935780445113778,
-0.006792654749006033,
-0.004699620883911848,
0.00574926333501935,
-0.010507624596357346,
-0.008601372130215168,
-0.002011517295613885,
-0.010579146444797516,
0.002185332588851452
] |
8a3ca54d0e30bc25beb86e00254a401833904b9e | 6,885 | py | Python | network_checker/dhcp_checker/utils.py | Zipfer/fuel-web | c6c4032eb6e29474e2be0318349265bdb566454c | [
"Apache-2.0"
] | null | null | null | network_checker/dhcp_checker/utils.py | Zipfer/fuel-web | c6c4032eb6e29474e2be0318349265bdb566454c | [
"Apache-2.0"
] | null | null | null | network_checker/dhcp_checker/utils.py | Zipfer/fuel-web | c6c4032eb6e29474e2be0318349265bdb566454c | [
"Apache-2.0"
] | null | null | null | # Copyright 2013 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import functools
import re
import subprocess
import sys
from scapy import all as scapy
DHCP_OFFER_COLUMNS = ('iface', 'mac', 'server_ip', 'server_id', 'gateway',
'dport', 'message', 'yiaddr')
def command_util(*command):
"""object with stderr and stdout
"""
return subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
def _check_vconfig():
"""Check vconfig installed or not
"""
return not command_util('which', 'vconfig').stderr.read()
def _iface_state(iface):
"""For a given iface return it's state
returns UP, DOWN, UNKNOWN
"""
state = command_util('ip', 'link', 'show', iface).stdout.read()
search_result = re.search(r'.*<(?P<state>.*)>.*', state)
if search_result:
state_list = search_result.groupdict().get('state', [])
if 'UP' in state_list:
return 'UP'
else:
return 'DOWN'
return 'UNKNOWN'
def check_network_up(iface):
return _iface_state(iface) == 'UP'
def check_iface_exist(iface):
"""Check provided interface exists
"""
return not command_util("ip", "link", "show", iface).stderr.read()
def filtered_ifaces(ifaces):
for iface in ifaces:
if not check_iface_exist(iface):
sys.stderr.write('Iface {0} does not exist.'.format(iface))
else:
if not check_network_up(iface):
sys.stderr.write('Network for iface {0} is down.'.format(
iface))
else:
yield iface
def pick_ip(range_start, range_end):
"""Given start_range, end_range generate list of ips
>>> next(pick_ip('192.168.1.10','192.168.1.13'))
'192.168.1.10'
"""
split_address = lambda ip_address: \
[int(item) for item in ip_address.split('.')]
range_start = split_address(range_start)
range_end = split_address(range_end)
i = 0
# ipv4 subnet cant be longer that 4 items
while i < 4:
# 255 - end of subnet
if not range_start[i] == range_end[i] and range_start[i] < 255:
yield '.'.join([str(item) for item in range_start])
range_start[i] += 1
else:
i += 1
def get_item_properties(item, columns):
"""Get specified in columns properties, with preserved order.
Required for correct cli table generation
:param item: dict
:param columns: list with arbitrary keys
"""
properties = []
for key in columns:
properties.append(item.get(key, ''))
return properties
def format_options(options):
"""Util for serializing dhcp options
@options = [1,2,3]
>>> format_options([1, 2, 3])
'\x01\x02\x03'
"""
return "".join((chr(item) for item in options))
def _dhcp_options(dhcp_options):
"""Dhcp options returned by scapy is not in usable format
[('message-type', 2), ('server_id', '192.168.0.5'),
('name_server', '192.168.0.1', '192.168.0.2'), 'end']
"""
for option in dhcp_options:
if isinstance(option, (tuple, list)):
header = option[0]
if len(option[1:]) > 1:
yield (header, option)
else:
yield (header, option[1])
def format_answer(ans, iface):
dhcp_options = dict(_dhcp_options(ans[scapy.DHCP].options))
results = (
iface, ans[scapy.Ether].src, ans[scapy.IP].src,
dhcp_options['server_id'], ans[scapy.BOOTP].giaddr,
ans[scapy.UDP].sport,
scapy.DHCPTypes[dhcp_options['message-type']],
ans[scapy.BOOTP].yiaddr)
return dict(zip(DHCP_OFFER_COLUMNS, results))
def single_format(func):
"""Manage format of dhcp response
"""
@functools.wraps(func)
def formatter(*args, **kwargs):
iface = args[0]
ans = func(*args, **kwargs)
#scapy stores all sequence of requests
#so ans[0][1] would be response to first request
return [format_answer(response[1], iface) for response in ans]
return formatter
def multiproc_map(func):
# multiproc map could not work with format *args
@functools.wraps(func)
def workaround(*args, **kwargs):
args = args[0] if isinstance(args[0], (tuple, list)) else args
return func(*args, **kwargs)
return workaround
def filter_duplicated_results(func):
# due to network infra on broadcast multiple duplicated results
# returned. This helper filter them out
@functools.wraps(func)
def wrapper(*args, **kwargs):
resp = func(*args, **kwargs)
return (dict(t) for t in set([tuple(d.items()) for d in resp]))
return wrapper
class VlansContext(object):
"""Contains all logic to manage vlans
"""
def __init__(self, config):
"""Initialize VlansContext
@config - list or tuple of (iface, vlan) pairs
"""
self.config = config
def __enter__(self):
for iface, vlans in self.config.iteritems():
vifaces = []
for vlan in vlans:
if vlan > 0:
vifaces.append('{0}.{1}'.format(iface, vlan))
yield str(iface), vifaces
def __exit__(self, type, value, trace):
pass
class IfaceState(object):
"""Context manager to control state of iface when dhcp checker is running
"""
def __init__(self, iface, rollback=True, retry=3):
self.rollback = rollback
self.retry = retry
self.iface = iface
self.pre_iface_state = _iface_state(iface)
self.iface_state = self.pre_iface_state
self.post_iface_state = ''
def iface_up(self):
while self.retry and self.iface_state != 'UP':
command_util('ifconfig', self.iface, 'up')
self.iface_state = _iface_state(self.iface)
self.retry -= 1
if self.iface_state != 'UP':
raise EnvironmentError(
'Tried my best to ifup iface {0}.'.format(self.iface))
def __enter__(self):
self.iface_up()
return self.iface
def __exit__(self, exc_type, exc_val, exc_tb):
if self.pre_iface_state != 'UP' and self.rollback:
command_util('ifconfig', self.iface, 'down')
self.post_iface_state = _iface_state(self.iface)
| 30.464602 | 78 | 0.615832 | 1 | 2.1531 | [
-0.0427827313542366,
0.023124901577830315,
-0.015838103368878365,
-0.0002535321400500834,
0.02226477675139904,
0.014746353961527348,
-0.006138448137789965,
-0.017597287893295288,
-0.007556783966720104,
-0.01648639515042305,
0.0037451395764946938,
0.014546024613082409,
0.0027398334350436926,
-0.009894016198813915,
-0.07518479973077774,
-0.034258417785167694,
0.016372662037611008,
0.008316870778799057,
-0.013458093628287315,
-0.014134439639747143,
-0.04017568752169609,
0.0009515483980067074,
-0.023637210950255394,
0.016832055523991585,
0.021380597725510597,
-0.02651721052825451,
0.015373828820884228,
-0.002353933872655034,
0.021046537905931473,
-0.018417425453662872,
-0.025831496343016624,
0.0017666268395259976,
-0.020151063799858093,
0.02910478226840496,
-0.004057778045535088,
-0.00498105539008975,
0.013200413435697556,
-0.01473582349717617,
0.028894901275634766,
-0.04162120819091797,
-0.01983911730349064,
-0.03841026499867439,
0.04531282186508179,
-0.022275451570749283,
0.019937628880143166,
0.03825226426124573,
-0.02027510479092598,
-0.013347454369068146,
-0.12578222155570984,
-0.017067236825823784,
-0.004975992254912853,
-0.01739068515598774,
0.01890106499195099,
0.02822539396584034,
0.0058335294015705585,
-0.04771013557910919,
-0.0031607686541974545,
0.011529807932674885,
-0.02068944275379181,
0.014063763432204723,
0.0070226495154201984,
-0.0017844723770394921,
0.04531058669090271,
0.016086524352431297,
0.004871130920946598,
0.036331657320261,
0.03581270948052406,
0.008367752656340599,
-0.08360353112220764,
0.013794004917144775,
0.010483471676707268,
0.000686318555381149,
0.017850905656814575,
0.0542060062289238,
-0.0009008602355606854,
0.010576103813946247,
0.017368221655488014,
-0.005533175077289343,
-0.035333532840013504,
-0.01616887003183365,
0.0022809584625065327,
0.07392022758722305,
-0.003757541300728917,
-0.027523508295416832,
-0.006877283565700054,
0.03065500594675541,
-0.011323518119752407,
-0.06429832428693771,
0.05308813229203224,
0.028125718235969543,
-0.05169445648789406,
0.01660287193953991,
-0.027269665151834488,
-0.013667101971805096,
0.031785525381565094,
-0.06781122088432312,
0.000620502105448395,
-0.006412661634385586,
0.018557779490947723,
0.01561410166323185,
0.034976527094841,
0.01222757063806057,
0.06141718849539757,
0.018147852271795273,
0.005835408344864845,
0.008517683483660221,
-0.06380534917116165,
-0.02594524621963501,
-0.028435727581381798,
-0.003343727672472596,
0.025785431265830994,
-0.017644595354795456,
0.04726028069853783,
-0.047039274126291275,
-0.02877620980143547,
0.0021248189732432365,
-0.022013863548636436,
0.01706886477768421,
-0.03650445491075516,
-0.004500680137425661,
0.010514436289668083,
-0.012194345705211163,
-0.006238956935703754,
-0.03145955502986908,
-0.020681820809841156,
0.04979453235864639,
-0.02582390233874321,
0.028440173715353012,
-0.03284009173512459,
-0.0012315456988289952,
-0.006448798347264528,
0.022935839369893074,
0.002138908486813307,
-0.010560487397015095,
0.0041784243658185005,
-0.02140822820365429,
0.0021779960952699184,
0.014947853051126003,
-0.025478338822722435,
0.029619213193655014,
-0.009240147657692432,
0.0060811154544353485,
0.0178532674908638,
0.012163186445832253,
0.019944023340940475,
-0.011510010808706284,
-0.021241096779704094,
-0.014689430594444275,
-0.02934853732585907,
0.010812345892190933,
0.0328017957508564,
0.026095358654856682,
-0.006955931428819895,
-0.05036846920847893,
-0.021708214655518532,
0.016465550288558006,
-0.018456073477864265,
-0.020645447075366974,
-0.041848618537187576,
-0.02133440412580967,
-0.009831213392317295,
-0.029955998063087463,
0.012105132453143597,
-0.029417337849736214,
0.01148601621389389,
-0.0033047052565962076,
-0.005231817718595266,
0.04816693440079689,
0.01612708903849125,
0.05681565776467323,
-0.001819647615775466,
-0.005633241962641478,
0.002332847099751234,
-0.0178083386272192,
-0.0383012481033802,
-0.0032954325433820486,
0.026442090049386024,
-0.03026334010064602,
-0.033056050539016724,
-0.041196104139089584,
0.04103396087884903,
-0.041337136179208755,
0.022385071963071823,
0.00508978171274066,
0.008559977635741234,
-0.0483785942196846,
-0.05476710945367813,
-0.057621654123067856,
-0.01692197658121586,
-0.05863495171070099,
0.026128798723220825,
-0.01111695822328329,
0.051822125911712646,
-0.005278053227812052,
-0.011691861785948277,
0.003025813726708293,
-0.005197249352931976,
-0.030007561668753624,
0.005299209151417017,
-0.0041465796530246735,
0.024937059730291367,
-0.002572571625933051,
0.023942885920405388,
0.015850134193897247,
-0.0014602441806346178,
-0.00011980960698565468,
-0.6159873008728027,
0.013371707871556282,
0.015641534700989723,
-0.003407167736440897,
0.014409099705517292,
0.005486371461302042,
-0.05330897495150566,
0.005161714740097523,
-0.03312065824866295,
-0.05213843658566475,
-0.0016702164430171251,
-0.008455613628029823,
-0.009291634894907475,
-0.035098884254693985,
-0.018229911103844643,
-0.04463759437203407,
-0.01041319314390421,
0.010004728101193905,
-0.0027008496690541506,
0.007498636841773987,
-0.023532798513770103,
-0.0658118724822998,
0.01628875359892845,
-0.028113005682826042,
0.02026122435927391,
-0.041233792901039124,
-0.03547598794102669,
0.0312754362821579,
0.014100140891969204,
-0.006539599504321814,
-0.01753394678235054,
0.007279602810740471,
-0.0028791818767786026,
-0.009249836206436157,
0.012360729277133942,
-0.028360068798065186,
0.08745041489601135,
-0.004883759189397097,
-0.004613193217664957,
0.025268593803048134,
-0.010989491827785969,
-0.04262211546301842,
-0.015189038589596748,
-0.06038857623934746,
-0.031108852475881577,
-0.043397657573223114,
-0.040812063962221146,
-0.04106455296278,
0.006607917137444019,
0.005585200618952513,
-0.009424258023500443,
0.038186319172382355,
-0.0041046058759093285,
0.00023030438751447946,
-0.03874281048774719,
0.011720722541213036,
-0.03660322725772858,
-0.028972160071134567,
0.018497752025723457,
0.012768656015396118,
0.020451830700039864,
-0.0054681068286299706,
0.0027391728945076466,
-0.006069232244044542,
-0.0269416905939579,
0.0135576743632555,
0.05445809289813042,
-0.002234506653621793,
-0.016020892187952995,
-0.038607534021139145,
-0.021101778373122215,
-0.035989392548799515,
-0.023450521752238274,
0.008597448468208313,
0.05074472725391388,
0.031062031164765358,
-0.019645635038614273,
-0.017458295449614525,
-0.04497407004237175,
0.018362674862146378,
-0.013086402788758278,
-0.02324623242020607,
-0.0020988639444112778,
-0.043077774345874786,
-0.019371459260582924,
0.050419896841049194,
0.005475024227052927,
0.026556195691227913,
-0.006529797799885273,
-0.013238178566098213,
0.04661165177822113,
0.05959603935480118,
0.023414958268404007,
-0.007998793385922909,
0.0198043342679739,
0.014390438795089722,
0.03810197860002518,
0.040821440517902374,
-0.039286114275455475,
0.03202197700738907,
0.03145447373390198,
0.02324916608631611,
0.003680300433188677,
0.0748482421040535,
-0.02116200141608715,
-0.022073063999414444,
0.019505858421325684,
0.008643366396427155,
0.07222936302423477,
0.03674193099141121,
0.043619491159915924,
-0.007458764594048262,
-0.00022381440794561058,
0.04281097650527954,
-0.043482307344675064,
-0.023145588114857674,
-0.009997028857469559,
-0.04572082310914993,
0.0518428273499012,
-0.010457048192620277,
0.006721357814967632,
-0.00707126734778285,
-0.045415885746479034,
0.0041058119386434555,
-0.02305203303694725,
0.03009871020913124,
-0.023367788642644882,
0.002202492207288742,
-0.004862787667661905,
0.031208990141749382,
-0.02837201952934265,
-0.017698314040899277,
-0.04073409363627434,
0.035580724477767944,
0.035129401832818985,
0.0001880590571090579,
-0.026658551767468452,
0.00926185306161642,
0.04314417019486427,
-0.010152382776141167,
-0.04036632925271988,
-0.005458617117255926,
0.005288173444569111,
-0.008851700462400913,
-0.010012749582529068,
-0.00011390965664759278,
0.010302120819687843,
-0.0058813318610191345,
-0.022729331627488136,
-0.014453302137553692,
-0.0042083123698830605,
0.058113135397434235,
0.021165302023291588,
-0.008579718880355358,
-0.043919723480939865,
-0.020565366372466087,
-0.0004450201231520623,
-0.01751020736992359,
0.0010955879697576165,
0.04892648011445999,
-0.0008405084372498095,
-0.00892216432839632,
0.007676916196942329,
0.013123451732099056,
0.00029483591788448393,
-0.009667905047535896,
0.0187644362449646,
-0.04328759387135506,
0.007879485376179218,
0.06940516084432602,
0.02770227938890457,
0.042964477092027664,
-0.0029760897159576416,
0.005080805625766516,
0.0019501514034345746,
0.023942677304148674,
-0.0430799163877964,
-0.01188492402434349,
-0.05740714445710182,
0.022333648055791855,
-0.013075996190309525,
-0.018511466681957245,
0.02433181367814541,
-0.00955868698656559,
0.003307142062112689,
0.05973584204912186,
-0.004557715728878975,
0.0056176441721618176,
-0.0015607315581291914,
-0.00009472348028793931,
0.01953849382698536,
0.019222605973482132,
0.01938340626657009,
-0.004545596428215504,
-0.020407821983098984,
-0.011465664952993393,
0.004307233262807131,
0.006266566459089518,
0.0012636941391974688,
-0.035405006259679794,
0.0052747237496078014,
0.018031544983386993,
-0.008100741542875767,
-0.016297264024615288,
0.018159139901399612,
0.04731714352965355,
0.0382939875125885,
-0.006185933947563171,
0.024888858199119568,
-0.047192253172397614,
0.012621181085705757,
0.023783789947628975,
-0.0009212702279910445,
-0.002338273683562875,
-0.02808363549411297,
0.0668497383594513,
-0.0222321730107069,
0.0087697459384799,
-0.004277474712580442,
-0.0140640027821064,
-0.037475138902664185,
-0.012077678926289082,
0.022021785378456116,
0.002350006951019168,
0.019149228930473328,
-0.015803435817360878,
-0.0553133450448513,
0.004398442339152098,
-0.034296806901693344,
0.030112477019429207,
-0.022109705954790115,
-0.0032110100146383047,
0.024124320596456528,
-0.008463077247142792,
0.004058249294757843,
0.029740115627646446,
0.0020836670882999897,
-0.0007217254023998976,
-0.006442494224756956,
0.006699848920106888,
-0.021996784955263138,
-0.0014805631944909692,
-0.04015457630157471,
0.010715331882238388,
-0.045292358845472336,
-0.0012446874752640724,
0.040678687393665314,
-0.00972086563706398,
-0.04642423242330551,
0.034584060311317444,
0.0041426741518080235,
0.05002192407846451,
0.015328533947467804,
0.00788223184645176,
-0.000979577424004674,
0.03521008789539337,
0.008937633596360683,
-0.004470576997846365,
-0.014074197970330715,
0.013616337440907955,
-0.01610361412167549,
0.030905598774552345,
-0.038838621228933334,
-0.025710569694638252,
0.036087505519390106,
0.0019183870172128081,
0.03147222474217415,
0.010106491856276989,
-0.006673085503280163,
-0.0027356252539902925,
0.02880585379898548,
0.040505990386009216,
-0.0385386124253273,
-0.007072543725371361,
0.023709561675786972,
0.02759086899459362,
-0.003238397417590022,
0.018533434718847275,
-0.004736450035125017,
0.0031953814905136824,
0.021304428577423096,
0.004669887945055962,
0.015116007998585701,
-0.024429606273770332,
-0.010357650928199291,
0.010515682399272919,
0.044546909630298615,
-0.003931994084268808,
-0.021320894360542297,
-0.019161969423294067,
-0.0223317202180624,
-0.0693804919719696,
0.039507605135440826,
0.058329686522483826,
0.0012363704154267907,
-0.01892026700079441,
-0.01664748042821884,
0.010809104889631271,
0.01653452403843403,
0.01245403103530407,
0.01809883490204811,
-0.04142315685749054,
-0.00957146193832159,
0.025981470942497253,
-0.014695110730826855,
-0.0034159242641180754,
0.05462492257356644,
-0.046915940940380096,
0.031200194731354713,
0.04019215330481529,
0.008289158344268799,
0.02276841551065445,
0.004417675547301769,
0.06540164351463318,
0.030427461490035057,
-0.0009422007715329528,
0.03260806202888489,
-0.006124280393123627,
0.008354616351425648,
0.005294109228998423,
-0.03184026852250099,
-0.031964633613824844,
-0.006583991460502148,
-0.01304736826568842,
0.01501292735338211,
-0.022937864065170288,
-0.02636902593076229,
0.005023039411753416,
-0.021886682137846947,
0.021482247859239578,
-0.023233819752931595,
0.01695636473596096,
0.032330337911844254,
0.02291921339929104,
0.057534683495759964,
0.011248331516981125,
0.006414921022951603,
0.016654903069138527,
0.014440115541219711,
-0.0020346769597381353,
-0.048351921141147614,
0.0681576132774353,
-0.007331481669098139,
-0.04174158722162247,
0.02846515364944935,
0.014570211991667747,
-0.007271317765116692,
-0.029344996437430382,
-0.007563442457467318,
0.008168530650436878,
0.033739376813173294,
0.012533196248114109,
0.0275303702801466,
-0.005798965226858854,
-0.024092670530080795,
-0.00547176506370306,
0.0284661203622818,
0.020298050716519356,
0.03259509056806564,
-0.02970256470143795,
-0.054021429270505905,
-0.0409972183406353,
0.028483809903264046,
0.01598386839032173,
0.008070671930909157,
-0.06808523833751678,
-0.019977932795882225,
0.007491088937968016,
-0.02413874678313732,
0.027485543861985207,
-0.018184619024395943,
-0.01655540242791176,
0.009991693310439587,
-0.005412699654698372,
-0.014189683832228184,
0.04913865774869919,
0.03054012544453144,
-0.014433180913329124,
0.05593569204211235,
-0.00915486179292202,
-0.018737349659204483,
-0.066297747194767,
-0.02922920323908329,
-0.02787422202527523,
0.024973828345537186,
-0.04284537583589554,
-0.03781656175851822,
0.03808508440852165,
-0.031834982335567474,
-0.012884673662483692,
0.010677904821932316,
-0.03207458555698395,
0.02854023687541485,
-0.005742404609918594,
-0.013610155321657658,
0.030851608142256737,
0.006925590801984072,
-0.05672139301896095,
-0.0056286039762198925,
0.0604042187333107,
-0.050476375967264175,
-0.010419707745313644,
0.0285117719322443,
0.030446205288171768,
0.02971908450126648,
-0.024670829996466637,
0.01447311695665121,
0.03165161609649658,
-0.01848549023270607,
0.02259325608611107,
0.01732819341123104,
0.04929034411907196,
-0.03828921169042587,
-0.010520724579691887,
0.022741807624697685,
0.0013925876701250672,
-0.032921504229307175,
0.012234791181981564,
-0.05947535112500191,
0.01447791326791048,
-0.016106735914945602,
-0.03810363635420799,
-0.01725858822464943,
0.03473569080233574,
-0.00934776570647955,
-0.009367957711219788,
-0.0471336804330349,
0.01230655424296856,
-0.0052106319926679134,
-0.0014087373856455088,
-0.0035495448391884565,
-0.008882771246135235,
0.013313877396285534,
0.03255660831928253,
0.01073535718023777,
-0.040685057640075684,
-0.02343158982694149,
-0.008404317311942577,
-0.05285172164440155,
0.028143150731921196,
-0.013711165636777878,
-0.024432772770524025,
-0.03193417191505432,
0.0542861707508564,
0.023247098550200462,
-0.07844370603561401,
-0.02923525683581829,
-0.0329216793179512,
-0.030615894123911858,
0.006467044353485107,
-0.006224735639989376,
0.03944232687354088,
-0.007657356560230255,
-0.035629019141197205,
-0.008540038019418716,
-0.0025961606297641993,
0.03489389643073082,
0.030540287494659424,
-0.044888388365507126,
0.016109121963381767,
0.02622375264763832,
0.009409444406628609,
-0.028034623712301254,
0.005904385820031166,
-0.03514162451028824,
0.04346910119056702,
-0.015311932191252708,
-0.0170533936470747,
0.026794804260134697,
0.015198914334177971,
0.009885957464575768,
0.05339072272181511,
0.030808765441179276,
-0.014357583597302437,
-0.009092176333069801,
-0.00940622203052044,
-0.005815908778458834,
-0.00835741963237524,
0.037467777729034424,
0.018761692568659782,
-0.03534723445773125,
0.013360016979277134,
0.023540088906884193,
0.03565401956439018,
-0.011489174328744411,
0.022129103541374207,
-0.004617619328200817,
-0.02040281891822815,
-0.014433634467422962,
0.03769616410136223,
0.010160349309444427,
-0.05080730468034744,
0.0032877738121896982,
0.028014151379466057,
0.02470632828772068,
-0.03204184025526047,
-0.009017282165586948,
-0.025747202336788177,
0.016511419788002968,
0.01648854836821556,
-0.04236598312854767,
0.02010047249495983,
0.04223679006099701,
0.009650013409554958,
0.015536804683506489,
0.05109937861561775,
0.007176544517278671,
0.04139992967247963,
-0.024075720459222794,
-0.05013347789645195,
-0.036167360842227936,
0.021124228835105896,
0.015463579446077347,
0.0031689899042248726,
0.014460287988185883,
0.016726136207580566,
0.013240046799182892,
-0.044011879712343216,
0.02664756588637829,
0.012048051692545414,
0.03208864852786064,
-0.037500400096178055,
0.018509794026613235,
-0.01961478218436241,
0.027788611128926277,
-0.009363912045955658,
-0.026151185855269432,
-0.018033940345048904,
0.048544738441705704,
0.019512388855218887,
0.002509185578674078,
0.015698697417974472,
0.018241792917251587,
-0.0011154646053910255,
0.01903524622321129,
-0.042436353862285614,
0.030568541958928108,
0.013850662857294083,
-0.028745509684085846,
-0.08087749034166336,
0.09802514314651489,
0.015421809628605843,
0.0096599031239748,
0.023118652403354645,
-0.04083177074790001,
-0.01105524692684412,
-0.029279768466949463,
-0.03557978942990303,
0.04138675704598427,
0.00871817022562027,
-0.009210406802594662,
0.062004897743463516,
0.012742534279823303,
0.0026995528023689985,
0.005777460988610983,
0.008557864464819431,
-0.02536165714263916,
0.039305757731199265,
0.003325351048260927,
-0.009830406866967678,
-0.030617520213127136,
0.039791952818632126
] |
8a3cab0b0c29dee41665f61e10da5e23f85da48c | 670 | py | Python | paneldata_dash/backend/schemas/johnson_scanner_data.py | clarencejlee/jdp | d3d31db0138ff06f2f5ec592d85317941af4f280 | [
"MIT"
] | null | null | null | paneldata_dash/backend/schemas/johnson_scanner_data.py | clarencejlee/jdp | d3d31db0138ff06f2f5ec592d85317941af4f280 | [
"MIT"
] | null | null | null | paneldata_dash/backend/schemas/johnson_scanner_data.py | clarencejlee/jdp | d3d31db0138ff06f2f5ec592d85317941af4f280 | [
"MIT"
] | null | null | null | from ma import ma
from models.johnson_scanner_data import JohnsonScannerDataModel
from schemas.brand import BrandSchema
from schemas.category import CategorySchema
from schemas.facts_in_data import FactsInDataSchema
from schemas.market import MarketSchema
from schemas.period import PeriodSchema
class JohnsonScannerDataSchema(ma.SQLAlchemySchema):
market = ma.Nested(MarketSchema)
brand = ma.Nested(BrandSchema)
category = ma.Nested(CategorySchema)
period = ma.Nested(PeriodSchema)
facts = ma.Nested(FactsInDataSchema, many=True)
class Meta:
model = JohnsonScannerDataModel
dump_only = ("id",)
# include_fk = False
| 27.916667 | 63 | 0.770149 | 1 | 0.8466 | [
0.0009470265940763056,
0.02372177131474018,
0.006650807801634073,
0.0032399995252490044,
0.005236111581325531,
-0.004765997640788555,
-0.010942826047539711,
0.0052505917847156525,
-0.007835625670850277,
0.002531764330342412,
0.004424646496772766,
0.0038504430558532476,
0.009499707259237766,
-0.01480234507471323,
0.0017256229184567928,
0.01921050436794758,
-0.05553251504898071,
0.002933541312813759,
-0.004579063970595598,
0.0013694324297830462,
-0.00795181468129158,
0.009661322459578514,
0.0100823063403368,
0.006219509989023209,
0.005551663227379322,
-0.0019356370903551579,
0.008912822231650352,
0.004526427481323481,
-0.008420851081609726,
-0.006375533062964678,
-0.0014817791525274515,
-0.0028532238211482763,
-0.005883806850761175,
-0.007901431992650032,
0.007161519955843687,
-0.0026311136316508055,
0.00022014847490936518,
-0.020945698022842407,
0.010471860878169537,
-0.0050280955620110035,
-0.00715657277032733,
-0.016424354165792465,
-0.002024533459916711,
0.004211053252220154,
-0.010844755917787552,
0.001882215728983283,
-0.004152197390794754,
0.0049544041976332664,
-0.010354951955378056,
0.0036565035115927458,
-0.011000478640198708,
0.006004013121128082,
0.012882500886917114,
0.0023217108100652695,
-0.00554340286180377,
-0.006355889607220888,
0.01149632129818201,
0.0009647631668485701,
-0.013358568772673607,
0.0008851026650518179,
-0.0027051842771470547,
-0.003334257984533906,
0.005523665342479944,
0.0034479417372494936,
-0.018784919753670692,
-0.00556886987760663,
-0.004603082779794931,
0.003385248128324747,
-0.0012539115268737078,
0.00544846011325717,
0.0025563151575624943,
0.00006242129893507808,
0.005469096824526787,
0.002598044229671359,
0.002368115121498704,
-0.003630734281614423,
0.0004744213947560638,
0.003895553993061185,
0.007138530258089304,
0.003345572156831622,
0.0057479157112538815,
-0.009755185805261135,
0.006952063646167517,
0.010071628727018833,
0.01172923669219017,
0.007924298755824566,
0.02040930651128292,
-0.011711486615240574,
0.044121213257312775,
0.00640021963045001,
-0.011110357940196991,
0.0013373984256759286,
-0.009319149889051914,
-0.0026342826895415783,
-0.002606180729344487,
-0.03103378228843212,
-0.0003994853759650141,
-0.0036718836054205894,
-0.00006241425580810755,
0.0031764262821525335,
0.000002976725227199495,
0.006686592940241098,
0.0012153929565101862,
-0.0018016461981460452,
-0.008696159347891808,
0.011011413298547268,
-0.010612210258841515,
-0.004062519874423742,
0.009268593974411488,
0.004041524603962898,
-0.014811266213655472,
-0.00031463426421396434,
0.0018149134702980518,
-0.012108724564313889,
0.006846815813332796,
0.0006785892765037715,
-0.007571634370833635,
0.056752149015665054,
-0.0005766045651398599,
0.002688374137505889,
-0.006389623507857323,
-0.0004431963316164911,
0.0014219103613868356,
0.008125493302941322,
0.007767727132886648,
-0.00401753606274724,
0.011470291763544083,
0.007741275709122419,
0.005791337229311466,
0.009024594910442829,
-0.0010191557230427861,
0.00815034843981266,
-0.003891265718266368,
-0.0018336729845032096,
0.0000021087969344080193,
-0.009436901658773422,
0.007015046663582325,
-0.0027459438424557447,
-0.007495369296520948,
0.0005059902905486524,
0.0011083526769652963,
-0.010837646201252937,
0.0002979568380396813,
-0.003759948769584298,
0.00005800552025903016,
-0.012705694884061813,
-0.0026340826880186796,
-0.001734997145831585,
-0.006127449683845043,
0.003894634312018752,
0.007822814397513866,
0.0045295595191419125,
0.0037667567376047373,
-0.007631595246493816,
-0.00938740000128746,
0.0009386602905578911,
-0.0043897912837564945,
0.001973087666556239,
0.008695464581251144,
0.0031550810672342777,
-0.008234350942075253,
-0.0021910355426371098,
0.003560782177373767,
0.006101405713707209,
-0.0024727999698370695,
0.0020618147682398558,
-0.006393927615135908,
0.010458938777446747,
0.000757197558414191,
0.0033417947124689817,
0.010547326877713203,
-0.00453141750767827,
-0.00014472217299044132,
-0.0007562143728137016,
0.00433117663487792,
-0.0015126279322430491,
0.0050146146677434444,
0.010082760825753212,
-0.004409175366163254,
-0.007244504056870937,
0.0036992074456065893,
0.0044774548150599,
0.008100559003651142,
0.008638707920908928,
-0.0030676014721393585,
0.0036020937841385603,
-0.0030956126283854246,
-0.0013239051913842559,
0.0061701214872300625,
-0.004663423635065556,
0.006069717928767204,
0.004428315907716751,
-0.013665597885847092,
-0.005095721688121557,
0.0017161606810986996,
-0.012159598059952259,
0.0023629136849194765,
0.016127899289131165,
0.011201534420251846,
-0.0020234491676092148,
0.004205383360385895,
-0.008404470980167389,
-0.0011440326925367117,
0.005259920377284288,
0.0037477663718163967,
-0.012460030615329742,
-0.9546048641204834,
0.0057283262722194195,
0.003302842378616333,
0.00024892095825634897,
0.0040905894711613655,
0.004195270128548145,
0.002917442237958312,
0.00479916762560606,
0.015845593065023422,
-0.008979624137282372,
-0.008457483723759651,
-0.009614652022719383,
-0.013252472504973412,
-0.001034497981891036,
-0.008410662412643433,
-0.0017262791516259313,
-0.0071128723211586475,
-0.007580428384244442,
0.00006115973519627005,
-0.006205835845321417,
-0.0027866805903613567,
0.010659188963472843,
-0.002864911686629057,
0.004342123866081238,
0.0033756536431610584,
0.004402820952236652,
-0.0045542530715465546,
-0.001583018573001027,
-0.002243202179670334,
-0.0018292313907295465,
-0.008938380517065525,
-0.014957078732550144,
-0.006433379370719194,
-0.001609606435522437,
0.01237571146339178,
-0.0003215269825886935,
0.008977437391877174,
-0.0018681938527151942,
0.002815220970660448,
-0.009934884496033192,
0.005712571088224649,
0.0004779829760082066,
0.004313348792493343,
-0.029646094888448715,
-0.000245256582275033,
-0.002611709525808692,
-0.006818927358835936,
0.010081551969051361,
0.0021355547942221165,
-0.00014518771786242723,
-0.003248266177251935,
-0.004530685488134623,
0.010002230294048786,
-0.009520783089101315,
0.005727928131818771,
-0.007169758901000023,
-0.007892271503806114,
-0.0027710874564945698,
-0.01022638101130724,
0.0006908400100655854,
0.004044678527861834,
-0.0022796725388616323,
-0.004189987201243639,
-0.002028028480708599,
0.003993209917098284,
0.0026919012889266014,
0.0001866705424617976,
-0.01764724962413311,
-0.006603720597922802,
0.0006941580795682967,
0.00285402312874794,
-0.0029946300201117992,
-0.006030465010553598,
0.004013109020888805,
-0.011578641831874847,
0.005509154871106148,
0.0035000774078071117,
0.0012222317745909095,
-0.011291938833892345,
0.0010315871331840754,
-0.010189327411353588,
-0.009766987524926662,
0.0021229293197393417,
-0.0077034845016896725,
-0.003949024248868227,
0.0005759421619586647,
0.0012363105779513717,
0.007673492655158043,
-0.004363467916846275,
0.004454201553016901,
0.012643956579267979,
-0.0032225882168859243,
-0.008582168258726597,
0.010342685505747795,
0.007196115329861641,
0.0035105207934975624,
-0.003154090838506818,
0.00020909160957671702,
0.008497881703078747,
0.008937906473875046,
0.002846037968993187,
0.004781697411090136,
0.0004863360372837633,
0.01202192809432745,
-0.000997513416223228,
0.0031960171181708574,
-0.003505323315039277,
0.0004784702614415437,
-0.005176093894988298,
-0.002911570481956005,
-0.0022720936685800552,
-0.0015307936118915677,
-0.013786545023322105,
-0.010651779361069202,
-0.003243764629587531,
-0.00027268248959444463,
0.001977363135665655,
-0.0031756458338350058,
0.000724497193004936,
0.0015525688650086522,
0.009988471865653992,
0.0034180418588221073,
-0.001049531390890479,
0.0005932777421548963,
0.001976968254894018,
-0.0070136720314621925,
0.014343809336423874,
-0.013044499792158604,
0.006471983157098293,
-0.001296923728659749,
-0.014683082699775696,
0.009201187640428543,
0.012385448440909386,
-0.0067596519365906715,
-0.0009150385740213096,
0.001501757767982781,
0.004722081124782562,
0.0005432293983176351,
-0.004942745435982943,
-0.0027301304508000612,
-0.017218682914972305,
0.000049353249778505415,
0.01994793303310871,
0.002060851315036416,
0.011203655041754246,
0.012436782009899616,
-0.0054057324305176735,
0.0008896240615285933,
0.00895695947110653,
0.003829010296612978,
0.013428131118416786,
-0.010210851207375526,
0.0004652210627682507,
0.0017077097436413169,
-0.005388639867305756,
0.0013217858504503965,
0.006601500324904919,
0.0049748606979846954,
-0.004492444451898336,
0.0008518091053701937,
-0.007891477085649967,
-0.005857811309397221,
-0.01805775798857212,
-0.001881539006717503,
0.00827366765588522,
-0.006562765687704086,
0.006288706324994564,
-0.009963885881006718,
0.00419280119240284,
0.0049761198461055756,
0.0020433394238352776,
0.00007322851161006838,
-0.00236686784774065,
0.006394612602889538,
0.012083178386092186,
-0.006344094406813383,
0.0030031136702746153,
0.0028766761533915997,
-0.002052203519269824,
0.0034231417812407017,
0.01043306477367878,
-0.008063518442213535,
-0.0031519578769803047,
0.0025329545605927706,
0.002214218256995082,
-0.00014002926764078438,
-0.004011997487396002,
-0.00807163491845131,
-0.0041301860474050045,
0.0014514470240101218,
-0.004940812475979328,
0.004029326606541872,
0.0015397685347124934,
0.0036996230483055115,
-0.008975028060376644,
0.000438582879723981,
-0.0013815413694828749,
-0.010817044414579868,
0.01056217122823,
-0.0032691401429474354,
0.0018607740057632327,
0.011330191977322102,
0.004235665779560804,
-0.014545929618179798,
0.006613012403249741,
0.009837138466536999,
-0.003828306682407856,
0.005499481223523617,
0.007156184408813715,
-0.005419571418315172,
-0.024271566420793533,
-0.0002944770094472915,
-0.014877933077514172,
0.00665636220946908,
-0.0031256480142474174,
0.004101024474948645,
-0.00816544983536005,
0.009507070295512676,
0.004569967743009329,
-0.010936270467936993,
-0.00426011485978961,
-0.010083002969622612,
0.009626045823097229,
-0.0009408125770278275,
-0.0028423690237104893,
-0.004233796149492264,
-0.000008466208782920148,
-0.0035943277180194855,
-0.002270056866109371,
-0.0010678169783204794,
0.004927176982164383,
0.0032822745852172375,
-0.004965939559042454,
0.001063716015778482,
-0.0030787880532443523,
0.00031390442745760083,
0.0027228952385485172,
-0.012193946167826653,
0.00008212339889723808,
0.005553788505494595,
-0.0010817846050485969,
-0.004515031818300486,
0.0014676291029900312,
-0.0030144427437335253,
-0.006670973729342222,
-0.010035979561507702,
-0.0026495479978621006,
-0.004577135667204857,
-0.004947943612933159,
-0.010468995198607445,
-0.0027671337593346834,
-0.008925559930503368,
0.006750107277184725,
-0.008570117875933647,
0.0067903888411819935,
0.0032919244840741158,
-0.0034251122269779444,
0.007700607180595398,
-0.002754672896116972,
0.004143637139350176,
0.0053357286378741264,
0.007979857735335827,
-0.0012186685344204307,
-0.005667493212968111,
-0.007314957212656736,
0.011368096806108952,
-0.010186179541051388,
-0.0005352795706130564,
0.014467872679233551,
0.0031175659969449043,
0.009285945445299149,
-0.0004673736111726612,
-0.0005756975733675063,
0.0022690470796078444,
0.00816671084612608,
-0.01524354424327612,
0.003136229235678911,
-0.0038361740298569202,
-0.001728172181174159,
0.007848330773413181,
-0.005642753094434738,
0.0028862343169748783,
0.008443155325949192,
0.003467388218268752,
-0.010061445645987988,
-0.0036614229902625084,
-0.0006353056523948908,
0.0026413395535200834,
-0.012569606304168701,
-0.0014283655909821391,
-0.0030408590100705624,
-0.003933738451451063,
-0.002237583277747035,
-0.0025703259743750095,
-0.0016970749711617827,
0.007602375000715256,
-0.0031562242656946182,
0.006772814784198999,
0.00030725140823051333,
-0.004035735037177801,
0.013453643769025803,
-0.0052688224241137505,
-0.006062757223844528,
0.0026580840349197388,
0.00018041538714896888,
-0.002714368049055338,
-0.00900688674300909,
-0.0039030462503433228,
0.000318670179694891,
0.0039722793735563755,
-0.0016630651662126184,
-0.0067916857078671455,
-0.003948175348341465,
0.0018739954102784395,
-0.00946617592126131,
0.0035971389152109623,
0.008231865242123604,
-0.0010185966966673732,
0.003306677797809243,
-0.0006096643046475947,
-0.006344248075038195,
-0.015027721412479877,
0.056625835597515106,
-0.0017275848658755422,
0.001837517716921866,
0.004938474390655756,
-0.0065703243017196655,
-0.0018913393141701818,
-0.0038371155969798565,
0.007433061022311449,
-0.00597405806183815,
-0.0059988899156451225,
0.008662696927785873,
-0.002856300910934806,
0.003575689857825637,
0.001735094585455954,
-0.0029568944592028856,
0.01829594187438488,
-0.0058982945047318935,
-0.017304280772805214,
-0.016021104529500008,
0.004531382117420435,
-0.003027348080649972,
-0.007054154761135578,
0.009183496236801147,
-0.0014159861020743847,
-0.0034140530042350292,
0.0014543157303705812,
0.006478991825133562,
0.0009784084977582097,
-0.0020088357850909233,
-0.002901033964008093,
-0.0009834092343226075,
-0.00103929010219872,
0.0031256310176104307,
0.005662588868290186,
0.007077271584421396,
-0.0026445656549185514,
0.0042132167145609856,
-0.0024680474307388067,
-0.0010429802350699902,
0.0009027577470988035,
0.00580082181841135,
0.0063587576150894165,
-0.00036646320950239897,
-0.0015206722309812903,
0.004335792735219002,
0.0035812468267977238,
-0.0013476340100169182,
0.012897877022624016,
0.0014276027213782072,
-0.0040823048911988735,
0.0073716542683541775,
0.009700383991003036,
-0.0009264136315323412,
0.0059137726202607155,
-0.0019139901269227266,
0.005176135804504156,
0.0035233930684626102,
-0.008137447759509087,
-0.013363429345190525,
-0.00021546911739278585,
0.007391998078674078,
0.008960504084825516,
-0.001069457270205021,
0.002477581612765789,
-0.0010419434402137995,
-0.0032727110665291548,
-0.008828310295939445,
-0.004559728782624006,
-0.0013961073709651828,
-0.000225413721636869,
0.0045099081471562386,
0.07003172487020493,
-0.00809206161648035,
-0.004493542015552521,
-0.009120327420532703,
-0.0012760480167344213,
-0.001629186444915831,
-0.0007940761861391366,
0.001434248755685985,
-0.0014967876486480236,
0.0014266724465414882,
0.003561480902135372,
-0.008856839500367641,
-0.01149245910346508,
0.0018120174063369632,
0.004554979037493467,
-0.0016338968416675925,
0.005626671481877565,
0.00445639668032527,
-0.008579093031585217,
0.004082011058926582,
-0.013164158910512924,
-0.0020049114245921373,
-0.0026733551640063524,
-0.0073324572294950485,
-0.00312974164262414,
-0.0028147639241069555,
0.002082831459119916,
0.003915862180292606,
0.006122293882071972,
-0.0054978178814053535,
0.005809652619063854,
-0.0024909197818487883,
0.0012351279146969318,
-0.0035865067038685083,
0.0009308248409070075,
-0.004560024011880159,
0.007658713031560183,
-0.00009373124339617789,
-0.010783689096570015,
-0.004578270949423313,
-0.0036355582997202873,
-0.0019371319795027375,
-0.006280495319515467,
0.006090094801038504,
0.0013883468927815557,
0.0066071609035134315,
-0.0023578444961458445,
0.0017981929704546928,
-0.0035133115015923977,
0.0006612142897211015,
-0.013151402585208416,
0.005180800799280405,
-0.18535475432872772,
0.011195115745067596,
0.005232230294495821,
-0.005466772709041834,
-0.004668113309890032,
-0.016275707632303238,
-0.00789668969810009,
0.004941028077155352,
0.01108613982796669,
0.002665638690814376,
0.0003496343269944191,
-0.000271153257926926,
0.003337428206577897,
0.004056212026625872,
-0.0029975809156894684,
-0.00427574198693037,
0.003911988809704781,
-0.005302588455379009,
0.0018399525433778763,
0.0059313406236469746,
0.0052085439674556255,
0.009110236540436745,
0.00218891235999763,
0.0020932669285684824,
-0.00002536149804654997,
-0.0047653354704380035,
0.006653039716184139,
-0.0010244199074804783,
0.004791694227606058,
-0.01097410824149847,
-0.0051379334181547165,
-0.005023249424993992,
-0.0035369687248021364,
0.003710708348080516,
0.0007966967532411218,
0.0010670955525711179,
0.008770331740379333,
-0.00017754641885403544,
-0.007771182339638472,
0.00809002947062254,
-0.007633483037352562,
0.030478617176413536,
0.0058895619586110115,
0.004756713751703501,
-0.0011742640053853393,
-0.004766980651766062,
-0.0051392181776463985,
0.007807292975485325,
0.004265878815203905,
0.014197097159922123,
-0.010090196505188942,
-0.003192909061908722,
0.0026353655848652124,
0.018874287605285645,
-0.006502719596028328,
-0.009692959487438202,
-0.00855730939656496,
-0.003651362145319581,
0.0050108777359128,
0.007346801459789276,
0.011099285446107388,
-0.004967712797224522,
0.009761269204318523,
-0.004004125948995352,
-0.023226182907819748,
0.004797548055648804,
-0.0006117999437265098,
-0.007880100980401039,
0.003346468321979046,
0.004831555299460888,
0.010100297629833221,
-0.004493032116442919,
0.006140262354165316,
-0.0005714103463105857,
0.003418958280235529,
-0.002060876227915287,
0.008161050267517567,
-0.004972955211997032,
0.006925452966243029,
-0.009296360425651073,
0.01011641789227724,
-0.009294061921536922,
-0.00248399144038558,
0.003932718187570572,
-0.003818294731900096,
0.0102852713316679,
0.007054837886244059,
-0.0017518067033961415,
0.0006329940515570343,
-0.010986337438225746,
-0.0012929218355566263,
0.002656635595485568,
0.002424438949674368,
-0.007791253738105297,
0.0024148395750671625,
-0.003164862049743533,
0.00555388955399394,
0.010143956169486046,
-0.007964586839079857,
0.006223965436220169,
0.003921136260032654,
-0.006045003887265921,
-0.0004175851645413786,
-0.0053650736808776855,
0.0018926537595689297,
0.003727046772837639,
-0.00781653355807066,
-0.006902233697474003,
0.004106499720364809,
-0.0061907339841127396,
-0.007565106265246868,
0.0049797301180660725,
-0.01057283952832222,
-0.008801241405308247,
-0.0003999288601335138,
-0.012632213532924652,
0.002422107383608818
] |
8a3cfa083e8e8e57b0bc63b2f6a4954146234e99 | 6,995 | py | Python | Chest X-Ray Multilabel Image classification using CNN - Pytorch/Arch2.py | farzanaaswin0708/CNN-for-Visual-recognition | db65db0a0b60e1ed2a4a418069de61936aaa9e85 | [
"MIT"
] | null | null | null | Chest X-Ray Multilabel Image classification using CNN - Pytorch/Arch2.py | farzanaaswin0708/CNN-for-Visual-recognition | db65db0a0b60e1ed2a4a418069de61936aaa9e85 | [
"MIT"
] | null | null | null | Chest X-Ray Multilabel Image classification using CNN - Pytorch/Arch2.py | farzanaaswin0708/CNN-for-Visual-recognition | db65db0a0b60e1ed2a4a418069de61936aaa9e85 | [
"MIT"
] | null | null | null | #!/usr/bin/env python
# coding: utf-8
# In[ ]:
################################################################################
# CSE 253: Programming Assignment 3
# Winter 2019
# Code author: Jenny Hamer (+ modifications by Tejash Desai)
#
# Filename: baseline_cnn.py
#
# Description:
#
# This file contains the starter code for the baseline architecture you will use
# to get a little practice with PyTorch and compare the results of with your
# improved architecture.
#
# Be sure to fill in the code in the areas marked #TODO.
################################################################################
# PyTorch and neural network imports
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as func
import torch.nn.init as torch_init
import torch.optim as optim
# Data utils and dataloader
import torchvision
from torchvision import transforms, utils
from xray_dataloader_zscored import ChestXrayDataset, create_split_loaders
import matplotlib.pyplot as plt
import numpy as np
import os
class Arch2CNN(nn.Module):
"""
<<<<<<< HEAD
conv1 -> maxpool -> conv2 -> maxpool -> conv3 -> conv4 ->maxpool -> conv5 -> conv6 -> maxpool -> conv7 -> conv8 -> maxpool -> fc1 -> fc2 -> fc3 (outputs)
=======
conv1 -> conv2 -> maxpool -> conv3 -> conv4 -> conv5 -> maxpool -> fc1 -> fc2 -> fc3 (outputs)
>>>>>>> 6652e3cfb72835ac4a7c802c9a703b59d5f63ae6
"""
def __init__(self):
super(Arch2CNN, self).__init__()
# conv1: 1 input channel, 4 output channels, [3x3] kernel size
self.conv1 = nn.Conv2d(in_channels=1, out_channels=4, kernel_size=3)
# Add batch-normalization to the outputs of conv1
self.conv1_normed = nn.BatchNorm2d(4)
# Initialized weights using the Xavier-Normal method
torch_init.xavier_normal_(self.conv1.weight)
self.pool1 = nn.MaxPool2d(kernel_size=3, stride=1)
#TODO: Fill in the remaining initializations replacing each '_' with
# the necessary value based on the provided specs for each layer
#TODO: conv2: 4 input channels, 8 output channels, [3x3] kernel, initialization: xavier
self.conv2 = nn.Conv2d(in_channels=4, out_channels=8, kernel_size=3)
self.conv2_normed = nn.BatchNorm2d(8)
torch_init.xavier_normal_(self.conv2.weight)
#Maxpool
self.pool2 = nn.MaxPool2d(kernel_size=3, stride=1)
#TODO: conv3: X input channels, 12 output channels, [8x8] kernel, initialization: xavier
self.conv3 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3)
self.conv3_normed = nn.BatchNorm2d(16)
torch_init.xavier_normal_(self.conv3.weight)
#TODO: conv4: X input channels, 10 output channels, [6x6] kernel, initialization: xavier
self.conv4 = nn.Conv2d(in_channels=16, out_channels=16, kernel_size=3)
self.conv4_normed = nn.BatchNorm2d(16)
torch_init.xavier_normal_(self.conv4.weight)
self.pool3 = nn.MaxPool2d(kernel_size=3, stride=1)
#TODO: conv5: X input channels, 8 output channels, [5x5] kernel, initialization: xavier
self.conv5 = nn.Conv2d(in_channels=16, out_channels=8, kernel_size=3)
self.conv5_normed = nn.BatchNorm2d(8)
torch_init.xavier_normal_(self.conv5.weight)
self.conv6 = nn.Conv2d(in_channels=8, out_channels=8, kernel_size=3)
self.conv6_normed = nn.BatchNorm2d(8)
torch_init.xavier_normal_(self.conv6.weight)
self.pool4 = nn.MaxPool2d(kernel_size=3, stride=1)
#TODO: Apply max-pooling with a [3x3] kernel using tiling (*NO SLIDING WINDOW*)
self.conv7 = nn.Conv2d(in_channels=8, out_channels=8, kernel_size=3)
self.conv7_normed = nn.BatchNorm2d(8)
torch_init.xavier_normal_(self.conv7.weight)
self.conv8 = nn.Conv2d(in_channels=8, out_channels=8, kernel_size=3)
self.conv8_normed = nn.BatchNorm2d(8)
torch_init.xavier_normal_(self.conv8.weight)
self.pool5 = nn.MaxPool2d(kernel_size=4, stride=4)
# Define 2 fully connected layers:
#TODO: fc1
self.fc1 = nn.Linear(in_features=122*122*8, out_features=512)
self.fc1_normed = nn.BatchNorm1d(512)
torch_init.xavier_normal_(self.fc1.weight)
#TODO: fc2
self.fc2 = nn.Linear(in_features=512, out_features=128)
self.fc2_normed = nn.BatchNorm1d(128)
torch_init.xavier_normal_(self.fc2.weight)
#TODO: fc3
self.fc3 = nn.Linear(in_features=128, out_features=14)
torch_init.xavier_normal_(self.fc3.weight)
#TODO: Output layer: what should out_features be?
self.out_features = 14
def forward(self, batch):
"""Pass the batch of images through each layer of the network, applying
non-linearities after each layer.
Note that this function *needs* to be called "forward" for PyTorch to
automagically perform the forward pass.
Params:
-------
- batch: (Tensor) An input batch of images
Returns:
--------
- logits: (Variable) The output of the network
"""
# Apply first convolution, followed by ReLU non-linearity;
# use batch-normalization on its outputs
batch = func.rrelu(self.conv1_normed(self.conv1(batch)))
batch = self.pool1(batch)
# Apply conv2 and conv3 similarly
batch = func.rrelu(self.conv2_normed(self.conv2(batch)))
batch = self.pool2(batch)
batch = func.rrelu(self.conv3_normed(self.conv3(batch)))
batch = func.rrelu(self.conv4_normed(self.conv4(batch)))
batch = self.pool3(batch)
batch = func.rrelu(self.conv5_normed(self.conv5(batch)))
batch = func.rrelu(self.conv6_normed(self.conv6(batch)))
# Pass the output of conv3 to the pooling layer
batch = self.pool4(batch)
batch = func.rrelu(self.conv7_normed(self.conv7(batch)))
batch = func.rrelu(self.conv8_normed(self.conv8(batch)))
# Pass the output of conv3 to the pooling layer
batch = self.pool5(batch)
# Reshape the output of the conv3 to pass to fully-connected layer
batch = batch.view(-1, self.num_flat_features(batch))
# Connect the reshaped features of the pooled conv3 to fc1
batch = func.rrelu(self.fc1_normed(self.fc1(batch)))
batch = func.rrelu(self.fc2_normed(self.fc2(batch)))
# Connect fc1 to fc2 - this layer is slightly different than the rest (why?)
batch = self.fc3(batch)
# Return the class predictions
#TODO: apply an activition function to 'batch'
#batch = func.sigmoid(batch)
return batch
def num_flat_features(self, inputs):
# Get the dimensions of the layers excluding the inputs
size = inputs.size()[1:]
# Track the number of features
num_features = 1
for s in size:
num_features *= s
return num_features
| 36.623037 | 157 | 0.653324 | 1 | 2.2581 | [
-0.046427976340055466,
0.043275754898786545,
0.027827594429254532,
-0.0007304542814381421,
-0.007697497494518757,
0.008391078561544418,
-0.017215777188539505,
0.014221933670341969,
-0.04704348370432854,
0.0031064904760569334,
0.019785389304161072,
0.02725985087454319,
0.006670027039945126,
-0.03665303438901901,
-0.056521181017160416,
0.004142271354794502,
0.07126660645008087,
0.01587836816906929,
-0.018538549542427063,
0.010417166166007519,
-0.013602428138256073,
-0.01588338240981102,
0.002172695240005851,
0.009548516012728214,
0.00749190803617239,
0.022549763321876526,
0.007253976073116064,
0.01472917478531599,
0.04466191306710243,
-0.006403563544154167,
-0.021245760843157768,
0.0007932346779853106,
0.02168029174208641,
-0.06262896955013275,
0.015485668554902077,
0.005223503336310387,
0.05281256511807442,
-0.040766626596450806,
-0.012288350611925125,
0.014231789857149124,
-0.020897677168250084,
0.002715891459956765,
-0.02290906198322773,
0.016157742589712143,
0.013488668017089367,
-0.04418385028839111,
-0.01974000595510006,
0.007873204536736012,
-0.04593533277511597,
0.03767000883817673,
-0.018669506534934044,
-0.005984765477478504,
0.005995573475956917,
-0.014223647303879261,
0.010540532879531384,
-0.049403611570596695,
0.032644033432006836,
0.04690311476588249,
-0.018834291025996208,
0.02068079635500908,
-0.0003651621227618307,
-0.013982276432216167,
0.015522090718150139,
0.000010386221219960134,
0.04535428434610367,
0.021554363891482353,
0.0409034863114357,
-0.026354046538472176,
-0.038345273584127426,
-0.007349373307079077,
0.00018483531312085688,
-0.006724336184561253,
-0.0034871387761086226,
0.020043784752488136,
0.03296316787600517,
0.014555320143699646,
-0.043445244431495667,
-0.026044005528092384,
0.02420552633702755,
0.047683000564575195,
-0.007260491140186787,
0.06296883523464203,
0.01211550459265709,
0.03372037410736084,
-0.003981591202318668,
0.04860163480043411,
0.04401787370443344,
-0.07537024468183517,
0.026128070428967476,
0.03450232371687889,
-0.015848038718104362,
-0.004296583589166403,
-0.011769557371735573,
-0.004360380582511425,
0.008065681904554367,
-0.05913429334759712,
0.008602785877883434,
0.03323033079504967,
-0.02989451214671135,
0.026324106380343437,
0.00005694993888027966,
-0.02763003297150135,
-0.045797523111104965,
0.013578453101217747,
0.0022854898124933243,
0.01327632274478674,
-0.013363269157707691,
-0.0014767440734431148,
0.009169952012598515,
-0.008922383189201355,
0.024775413796305656,
-0.005739131476730108,
0.01060519553720951,
-0.018253404647111893,
0.01853027008473873,
-0.04166653752326965,
0.014200374484062195,
0.019255131483078003,
-0.008194065652787685,
-0.07104074954986572,
0.021342260763049126,
-0.0006648267735727131,
0.02361045405268669,
-0.037844423204660416,
-0.01690579578280449,
0.05171710625290871,
-0.04547784477472305,
0.014227604493498802,
0.016981204971671104,
0.018063198775053024,
0.012111157178878784,
-0.006500701420009136,
0.002015216974541545,
-0.0032504096161574125,
0.039953090250492096,
-0.01160174235701561,
-0.030805079266428947,
0.011169282719492912,
-0.02974816970527172,
0.016992248594760895,
0.01728031039237976,
-0.03230150416493416,
-0.006384700071066618,
-0.015809951350092888,
-0.024341681972146034,
-0.05500520020723343,
-0.0039164102636277676,
-0.015909405425190926,
-0.027494965121150017,
-0.020026883110404015,
0.0209149569272995,
-0.026875508949160576,
-0.003684390103444457,
0.01737472228705883,
-0.026894371956586838,
0.021121114492416382,
0.004599701147526503,
-0.036196935921907425,
0.0018697637133300304,
0.007930438965559006,
-0.05207885056734085,
0.00815519504249096,
0.01337926834821701,
0.00784105435013771,
-0.005669312551617622,
0.0224801953881979,
-0.050713736563920975,
0.026434870436787605,
-0.04197996109724045,
0.02880278043448925,
-0.008804637007415295,
-0.005285098683089018,
-0.0375836119055748,
-0.017670761793851852,
-0.020628605037927628,
0.010868462733924389,
0.025668829679489136,
0.02929600514471531,
-0.00589016592130065,
0.002715295646339655,
-0.006240237969905138,
0.041807692497968674,
0.02180895023047924,
0.030797509476542473,
0.03182528167963028,
-0.028232837095856667,
-0.05928986519575119,
-0.019761014729738235,
0.014699293300509453,
0.0021223181392997503,
-0.022943230345845222,
-0.00942940078675747,
-0.0354047492146492,
-0.024685751646757126,
0.0035998993553221226,
0.0464068241417408,
0.025050843134522438,
0.009029642678797245,
0.018647262826561928,
0.00030866157612763345,
-0.014788494445383549,
0.03367827832698822,
-0.007036777678877115,
0.010551340878009796,
0.00625269953161478,
0.005915570538491011,
-0.6690659523010254,
0.000046447719796560705,
0.01760798692703247,
0.0022228481248021126,
-0.014149850234389305,
0.0475013330578804,
-0.017422731965780258,
0.05191264674067497,
-0.003661109134554863,
-0.011300560086965561,
-0.014348959550261497,
-0.02750510536134243,
-0.08189529180526733,
0.005090167745947838,
-0.025317922234535217,
-0.025258895009756088,
0.03711867332458496,
-0.018353592604398727,
-0.005529487505555153,
0.03820202499628067,
0.03943710774183273,
0.0167221836745739,
-0.022243037819862366,
0.011443951167166233,
-0.014239187352359295,
0.02170415408909321,
0.015793386846780777,
-0.009705918841063976,
-0.01955660991370678,
-0.034359488636255264,
0.022610487416386604,
-0.010386877693235874,
-0.013717317953705788,
-0.007323299068957567,
0.03003270924091339,
0.015217313542962074,
0.009106671437621117,
-0.012120595201849937,
-0.0156222153455019,
-0.0019955968018621206,
-0.009719839319586754,
-0.0030055458191782236,
-0.03396182879805565,
-0.0681890919804573,
-0.021470265462994576,
-0.017352577298879623,
-0.02012360654771328,
-0.04249289631843567,
0.04172182083129883,
0.021053079515695572,
-0.03035769797861576,
0.04587198793888092,
0.049957916140556335,
-0.020155342295765877,
0.004423095379024744,
0.011981149204075336,
-0.05092661455273628,
-0.01899726502597332,
0.011537066660821438,
0.027189141139388084,
0.009443853050470352,
-0.0034117992036044598,
0.002711260924115777,
0.022646795958280563,
0.021900003775954247,
0.026974301785230637,
0.04510270431637764,
0.01288237888365984,
-0.0392860546708107,
0.043367162346839905,
-0.10248784720897675,
0.006385854911059141,
-0.04083937779068947,
0.13021522760391235,
0.007932801730930805,
0.01585616171360016,
0.015517161227762699,
0.011186279356479645,
-0.008598578162491322,
-0.004220969509333372,
0.0102161830291152,
-0.018271198496222496,
-0.0073910607025027275,
0.005515442695468664,
-0.03278685361146927,
0.027246030047535896,
-0.0418265126645565,
-0.012292117811739445,
-0.0276793260127306,
0.00040528588579036295,
0.039716605097055435,
0.02285405993461609,
0.031523197889328,
-0.004079390782862902,
-0.011054680682718754,
0.04901173338294029,
-0.03298885002732277,
0.10565707087516785,
0.002575293881818652,
0.029267314821481705,
-0.029887232929468155,
-0.011598929762840271,
-0.0018100549932569265,
0.03275632858276367,
-0.028431033715605736,
0.016515012830495834,
-0.052061859518289566,
-0.019379837438464165,
0.03492647036910057,
-0.044858191162347794,
0.015805138275027275,
-0.00549779599532485,
-0.008067399263381958,
0.012764743529260159,
-0.06014861911535263,
-0.011047116480767727,
-0.015358255244791508,
-0.01394432969391346,
0.026781009510159492,
-0.03762717545032501,
-0.03508605808019638,
-0.03940032422542572,
0.023471321910619736,
0.03821302950382233,
0.002146034734323621,
0.003547498257830739,
-0.06366351991891861,
-0.019387826323509216,
-0.004849509801715612,
0.013929981738328934,
0.027815578505396843,
0.007414231076836586,
-0.05641257017850876,
0.002796680899336934,
-0.014211033470928669,
0.013326612301170826,
-0.01838880404829979,
-0.05168549716472626,
-0.026443621143698692,
-0.011252232827246189,
0.06268713623285294,
-0.008333379402756691,
-0.021001406013965607,
-0.03409578651189804,
0.019578341394662857,
0.023821968585252762,
0.037069324404001236,
0.011393762193620205,
-0.014346007257699966,
-0.012869344092905521,
-0.008811036124825478,
0.03191991150379181,
-0.004603952169418335,
-0.02226599119603634,
0.01959512010216713,
0.013505402952432632,
-0.006201085634529591,
-0.03261943534016609,
0.03250230476260185,
0.009713364765048027,
-0.000247981894062832,
-0.0017089572502300143,
-0.007995698601007462,
0.024432307109236717,
-0.011063627898693085,
-0.019699806347489357,
-0.003809007816016674,
-0.018381765112280846,
-0.018619105219841003,
0.024273887276649475,
0.026528550311923027,
-0.05834665521979332,
0.054023757576942444,
-0.015432571060955524,
0.03624459356069565,
0.044328317046165466,
-0.016701623797416687,
-0.01639454998075962,
0.0028247518930584192,
-0.013208147138357162,
0.03514830768108368,
-0.027728307992219925,
-0.0027167394291609526,
-0.02766585350036621,
0.003971130587160587,
-0.009329498745501041,
0.014307991601526737,
0.03170264884829521,
-0.021314652636647224,
-0.023347459733486176,
-0.010120874270796776,
0.024827787652611732,
-0.051872368901968,
0.0065057966858148575,
-0.056762658059597015,
-0.034099891781806946,
-0.0448639877140522,
-0.0062810867093503475,
-0.004603072535246611,
-0.005589624866843224,
0.005626500118523836,
0.018794704228639603,
0.03090270608663559,
-0.014006304554641247,
-0.012507177889347076,
0.019714966416358948,
0.03118121437728405,
-0.0007204920402728021,
0.025790907442569733,
-0.030634647235274315,
0.007391262799501419,
-0.0051411231979727745,
0.025649601593613625,
-0.0027343363035470247,
0.0022414519917219877,
0.0451042540371418,
-0.0057777841575443745,
-0.038228776305913925,
0.007310467306524515,
-0.023898180574178696,
-0.06491833180189133,
0.008804203011095524,
0.024456296116113663,
-0.02236582525074482,
-0.004151038825511932,
0.0031202626414597034,
-0.04020420461893082,
-0.025952758267521858,
0.005916366819292307,
-0.032028649002313614,
0.016957202926278114,
-0.0030081463046371937,
0.029063686728477478,
-0.01416437141597271,
-0.012757686898112297,
0.0642145648598671,
-0.018294982612133026,
-0.022180112078785896,
-0.004875012207776308,
-0.020378312095999718,
-0.0008102216525003314,
-0.00194391212426126,
-0.012190697714686394,
0.02378549613058567,
0.01689409837126732,
0.003204425098374486,
-0.009471091441810131,
-0.0010056847240775824,
-0.04528431594371796,
-0.007621705532073975,
-0.02537388540804386,
0.036310531198978424,
-0.01291905902326107,
0.041557151824235916,
0.0184444859623909,
0.008956928737461567,
-0.01911122351884842,
0.020822668448090553,
0.019837241619825363,
0.028390515595674515,
0.020945724099874496,
-0.035876188427209854,
-0.01251310110092163,
-0.0189835075289011,
0.006666653323918581,
0.03627503663301468,
-0.0225687213242054,
0.014523818157613277,
-0.05204678326845169,
0.02219340391457081,
0.00272757769562304,
-0.015721501782536507,
-0.00567022105678916,
-0.005586960352957249,
0.029914775863289833,
0.02498582750558853,
0.014017220586538315,
-0.04458656534552574,
0.02151326648890972,
0.04595144838094711,
-0.04041288048028946,
-0.015491667203605175,
0.021598631516098976,
0.0300251767039299,
0.017064591869711876,
-0.007925364188849926,
0.03479386493563652,
0.01689150184392929,
-0.04052509367465973,
0.018430637195706367,
0.0009056561975739896,
-0.016842231154441833,
0.0088003845885396,
-0.0009754241909831762,
-0.045653726905584335,
0.020684603601694107,
-0.025497082620859146,
0.0041289865039289,
0.028110621497035027,
0.008763172663748264,
-0.004944172687828541,
-0.0031581707298755646,
-0.024134548380970955,
-0.01591012068092823,
-0.0003766213485505432,
0.0021722500678151846,
-0.00799322035163641,
0.014571735635399818,
0.04542626067996025,
0.007882003672420979,
0.006320062093436718,
-0.00479505117982626,
0.01579992100596428,
-0.01975901611149311,
0.018171394243836403,
0.01710396073758602,
0.03820104897022247,
-0.00019594377954490483,
0.02942604571580887,
-0.0075539047829806805,
0.013573636300861835,
0.008512181229889393,
-0.026690617203712463,
0.006239907816052437,
-0.028374651446938515,
-0.014318890869617462,
-0.03267091512680054,
0.03098788857460022,
-0.012422522529959679,
-0.004741149954497814,
-0.019210632890462875,
0.007055255118757486,
0.016176655888557434,
0.0029960288666188717,
0.034907761961221695,
-0.0390438511967659,
0.01088463980704546,
0.006229519844055176,
0.05334601551294327,
-0.01950760930776596,
-0.01386428251862526,
0.01834741421043873,
0.017959069460630417,
-0.005357992835342884,
0.019520046189427376,
0.044219378381967545,
-0.005377358756959438,
0.045235566794872284,
0.03385799750685692,
0.03291328251361847,
0.006271708756685257,
-0.0029423621017485857,
-0.00019825373601634055,
0.027285436168313026,
0.010020756162703037,
-0.02138681896030903,
-0.03468859940767288,
0.0006589388940483332,
0.044149477034807205,
0.011704760603606701,
0.032137639820575714,
-0.0036358183715492487,
-0.02719234675168991,
-0.011989058926701546,
0.010035409592092037,
-0.023086603730916977,
0.03429755941033363,
-0.01902702823281288,
0.0003613872395362705,
0.01040721870958805,
-0.025008616968989372,
-0.014394160360097885,
-0.0039018094539642334,
-0.021734388545155525,
0.024569982662796974,
0.02155725099146366,
0.024394311010837555,
0.01757514849305153,
0.014792690984904766,
-0.012278231792151928,
0.032455332577228546,
-0.020303206518292427,
0.015759702771902084,
-0.0008989745983853936,
0.046959590166807175,
-0.0234513096511364,
-0.03228476643562317,
-0.015108810737729073,
-0.0023966042790561914,
-0.019576869904994965,
-0.0237641092389822,
-0.01606707088649273,
0.014281895942986012,
0.017545929178595543,
-0.03125543147325516,
0.0001311760861426592,
-0.039111968129873276,
0.004743731580674648,
0.00553593784570694,
-0.04451863095164299,
-0.005487467627972364,
-0.0047517153434455395,
-0.01593467779457569,
-0.018038881942629814,
0.010942686349153519,
-0.01913941092789173,
0.05568340793251991,
0.0027255164459347725,
0.03749530017375946,
0.010160207748413086,
-0.007021524012088776,
-0.01723434589803219,
0.0001410535187460482,
0.02775844931602478,
-0.04839546978473663,
0.03032556176185608,
-0.007337565533816814,
0.029756594449281693,
-0.02622499316930771,
0.04387157782912254,
-0.029053019359707832,
-0.020170601084828377,
-0.011734719388186932,
0.015441743656992912,
-0.04512590542435646,
-0.013567136600613594,
0.024033602327108383,
0.0065739937126636505,
0.00943019986152649,
0.004072059411555529,
0.01835794374346733,
-0.020182544365525246,
0.0008336376049555838,
0.001643321244046092,
0.03528037294745445,
0.027695994824171066,
-0.0269178319722414,
-0.051035795360803604,
-0.005152953322976828,
-0.0038064662367105484,
-0.014796976931393147,
-0.01881600171327591,
-0.007841118611395359,
0.01805666647851467,
0.016463419422507286,
0.019877590239048004,
-0.010328870266675949,
0.020005714148283005,
-0.00641912966966629,
-0.04339837655425072,
0.029899364337325096,
0.007037935312837362,
0.006013959646224976,
0.004394919145852327,
0.05764107406139374,
-0.01398196630179882,
0.04233027994632721,
0.016717370599508286,
-0.022180264815688133,
0.00948241911828518,
0.0006175285670906305,
0.03001907467842102,
-0.048279646784067154,
0.004035144578665495,
0.006538853049278259,
0.05583488196134567,
0.015033528208732605,
-0.019272444769740105,
-0.003727925708517432,
-0.01522020436823368,
0.010357649065554142,
0.0005383600946515799,
-0.02210749313235283,
0.014806070365011692,
0.02463410049676895,
-0.0027854042127728462,
0.009440483525395393,
0.02482888661324978,
0.03162769228219986,
-0.00232079834677279,
-0.05309662967920303,
0.00703579094260931,
0.017706645652651787,
0.018866904079914093,
0.013502231799066067,
-0.011174894869327545,
-0.02678551711142063,
0.01932104490697384,
-0.03320878744125366,
0.020194049924612045,
-0.025186477228999138,
-0.001503947889432311,
-0.041580405086278915,
0.014832445420324802,
0.019020846113562584,
-0.0035384222865104675,
0.030255775898694992,
-0.006819190923124552,
0.08828048408031464,
0.00133746478240937,
-0.0120773296803236,
-0.007885009050369263,
-0.03888799995183945,
-0.03235647454857826,
0.04354336857795715,
0.031612738966941833,
0.031761396676301956,
0.02433202415704727,
-0.003764145541936159,
0.005775377620011568,
-0.004826168064028025,
-0.013760589063167572,
-0.06071561947464943,
-0.027849946171045303,
-0.004115383140742779,
0.02346542850136757,
-0.006008132826536894,
-0.0626097097992897,
0.0031818945426493883,
0.007665153127163649,
-0.021137410774827003,
0.013153962790966034,
0.004514109808951616,
-0.020099233835935593,
-0.016607027500867844,
-0.008720435202121735,
-0.0389796644449234,
-0.04090571403503418,
0.04442031309008598,
0.014335553161799908,
-0.00627402076497674,
-0.01644912362098694,
-0.02544078789651394,
-0.009886623360216618,
-0.010958841070532799,
-0.04191211611032486,
-0.021107109263539314,
0.02638172172009945,
-0.009471763856709003,
-0.0016204663552343845,
0.037978850305080414,
-0.011855700984597206,
-0.0023441524244844913,
0.006473060231655836,
-0.0340462364256382,
-0.00836733914911747,
0.018772603943943977,
-0.012417438440024853,
0.01972450502216816,
0.04569864273071289,
-0.013682813383638859,
-0.0200809333473444,
0.025899821892380714,
-0.00011821864609373733,
-0.03871920332312584,
-0.031043939292430878,
-0.008017499931156635,
0.03454618528485298,
-0.028584983199834824,
-0.06491578370332718,
-0.024684008210897446,
0.006568352226167917
] |
8a3e36ced124cb7dabea478a1f4b328edd22757f | 1,344 | py | Python | news_access.py | HydeJackal/TwitterWeeklyNewsBot | 64fc6b9e7d74bafd26f4dcdfe28e835ece1cee9b | [
"MIT"
] | null | null | null | news_access.py | HydeJackal/TwitterWeeklyNewsBot | 64fc6b9e7d74bafd26f4dcdfe28e835ece1cee9b | [
"MIT"
] | null | null | null | news_access.py | HydeJackal/TwitterWeeklyNewsBot | 64fc6b9e7d74bafd26f4dcdfe28e835ece1cee9b | [
"MIT"
] | null | null | null | import json
import urllib.request
import credentials
from datetime import datetime, timedelta
class NewsAPI:
def __init__(self, nyt_api):
self.nyt_access = nyt_api
def get_nyt_last_week_articles(self, topic, today):
delta = timedelta(weeks = 1)
last_week = today - delta
begin_date = last_week.strftime('%Y%m%d')
url = 'https://api.nytimes.com/svc/search/v2/articlesearch.json?q=' + topic + '&begin_date=' + begin_date + '&sort=best&type_of_material=Article&api-key=' + self.nyt_access
try:
json_url = urllib.request.urlopen(url)
articles = json.loads(json_url.read())
except:
raise RuntimeError('Failed to retrive New York Times data.')
if articles['status'] != 'OK':
num_of_articles = articles['response']['docs'].length()
if num_of_articles > 5:
return articles['response']['docs'][0:4], articles['response']['meta']['hits']
else:
return articles['response']['docs'][0:num_of_articles - 1], articles['response']['meta']['hits']
else:
raise RuntimeError('Failed to find any New York Times articles with query.')
api = NewsAPI(credentials.NYT_API)
date_time_obj = datetime.now()
api.get_nyt_last_week_articles('election', date_time_obj) | 42 | 180 | 0.638393 | 1 | 1.0716 | [
0.0011949569452553988,
0.024570677429437637,
0.008234389126300812,
0.003186840796843171,
0.004027318675071001,
-0.0018879410345107317,
-0.00954557303339243,
0.0019871972035616636,
-0.007510975934565067,
0.005993920844048262,
0.0016496800817549229,
0.006195306312292814,
0.009673033840954304,
-0.013582125306129456,
-0.0002247443189844489,
0.01714957132935524,
-0.05140335112810135,
0.000744369113817811,
-0.00313381920568645,
0.0017295052530243993,
-0.007986892014741898,
0.010597094893455505,
0.008108643814921379,
0.004439550451934338,
0.006287659518420696,
-0.0007958539645187557,
0.008081777952611446,
0.0043875775299966335,
-0.009609246626496315,
-0.0025544625241309404,
-0.0003772666386794299,
-0.0012336702784523368,
-0.001798122888430953,
-0.006348578259348869,
0.006523651536554098,
-0.004089919850230217,
-0.0031620461959391832,
-0.022596685215830803,
0.010643529705703259,
-0.00642341049388051,
-0.005474530626088381,
-0.012410789728164673,
-0.0015158893074840307,
0.004623793996870518,
-0.008916884660720825,
0.0016233131755143404,
-0.00681814830750227,
0.0016265219310298562,
-0.00945972464978695,
0.0051828292198479176,
-0.009782508946955204,
0.004865163471549749,
0.012301050126552582,
0.0017373121809214354,
-0.006460011471062899,
-0.006726759951561689,
0.013561880216002464,
0.000050521317461971194,
-0.010635020211338997,
0.0007721417350694537,
-0.004319849424064159,
-0.0023528430610895157,
0.005450289696455002,
0.003378580790013075,
-0.016514895483851433,
-0.007566236890852451,
-0.004165257327258587,
0.0026845098473131657,
-0.0018090587109327316,
0.004714929964393377,
0.00166959164198488,
-0.00046783211291767657,
0.00820271484553814,
0.005726500879973173,
0.004937352146953344,
-0.0030299602076411247,
0.00019689985492732376,
0.00028887976077385247,
0.00967402569949627,
0.0035461485385894775,
0.004695066250860691,
-0.006242753006517887,
0.007379649206995964,
0.011147281154990196,
0.013205395080149174,
0.010130123235285282,
0.018914733082056046,
-0.012994815595448017,
0.04600030928850174,
0.0067525589838624,
-0.010480420663952827,
0.00444429274648428,
-0.008346980437636375,
-0.0026097320951521397,
-0.007553853560239077,
-0.028713276609778404,
0.0011980001581832767,
-0.005686228629201651,
0.0010035923914983869,
0.003022958757355809,
0.000008464271559205372,
0.0053949132561683655,
-0.0011107217287644744,
-0.004017280880361795,
-0.010090310126543045,
0.012398098595440388,
-0.010550075210630894,
-0.005229917820543051,
0.005420256406068802,
0.002190315630286932,
-0.012259077280759811,
-0.0006691747112199664,
0.0011381680378690362,
-0.014158652164041996,
0.000657104654237628,
0.0036359913647174835,
-0.005585454870015383,
0.05480620637536049,
-0.0017219947185367346,
0.005102807190269232,
-0.006009963341057301,
-0.00012419292761478573,
0.00034471487742848694,
0.0066757723689079285,
0.011330222710967064,
-0.002384816063567996,
0.009453313425183296,
0.0060968948528170586,
0.002240652684122324,
0.009245380759239197,
-0.002814491279423237,
0.006643212866038084,
-0.0038856971077620983,
-0.0007924256497062743,
-0.0015756465727463365,
-0.008011864498257637,
0.007186411879956722,
-0.003334701992571354,
-0.008081984706223011,
0.0033774073235690594,
-0.001087043434381485,
-0.011285618878901005,
0.0033571855165064335,
-0.002124870428815484,
0.0011446007993072271,
-0.013394770212471485,
-0.00329004367813468,
-0.002884841524064541,
-0.005651191342622042,
0.0009175320737995207,
0.008906461298465729,
0.005023500416427851,
0.0012715869816020131,
-0.0036856879014521837,
-0.007332242093980312,
0.00045551644871011376,
-0.004466463346034288,
0.0008399301441386342,
0.00812374334782362,
0.0017198759596794844,
-0.009029116481542587,
0.0011624459875747561,
0.0031874810811132193,
0.0029037073254585266,
-0.0005731312558054924,
0.004538963083177805,
-0.0067895567044615746,
0.009025887586176395,
-0.0008653118857182562,
0.005235342308878899,
0.012508551590144634,
-0.0032252371311187744,
-0.00008545551827410236,
-0.000051845781854353845,
0.001026596873998642,
-0.00041911585140042007,
0.005745991598814726,
0.011385018937289715,
-0.005812707357108593,
-0.005310471635311842,
0.005412607453763485,
0.004701556637883186,
0.008917820639908314,
0.005752609111368656,
-0.001875222777016461,
-0.0008654198027215898,
-0.007912173867225647,
-0.0016743653686717153,
0.006023971829563379,
-0.005371270701289177,
0.008470618166029453,
0.004139651544392109,
-0.013583122752606869,
-0.006942034233361483,
-0.000007702977200096939,
-0.00871205236762762,
0.0023249785881489515,
0.015559004619717598,
0.012263912707567215,
-0.0029105779249221087,
0.0003380716952960938,
-0.010780350305140018,
0.0016438458114862442,
0.007848691195249557,
0.0007300652796402574,
-0.011441746726632118,
-0.9569005370140076,
0.008582851849496365,
0.003325191792100668,
-0.002960790414363146,
0.004518641158938408,
-0.0006730456370860338,
0.004246887750923634,
0.00332782045006752,
0.012633459642529488,
-0.010203676298260689,
-0.005990014411509037,
-0.011909427121281624,
-0.014606357552111149,
-0.002796158893033862,
-0.008759920485317707,
-0.0019463180797174573,
-0.006064844783395529,
-0.009182184934616089,
-0.0032127131707966328,
-0.0024249216075986624,
-0.0016047965036705136,
0.005428314674645662,
-0.0008745588711462915,
0.0050977058708667755,
0.0016228415770456195,
0.00492458650842309,
-0.005974470172077417,
-0.002603949047625065,
0.00041290000081062317,
-0.004178566858172417,
-0.0075379335321486,
-0.013150460086762905,
-0.0042265309020876884,
-0.002405226929113269,
0.010261683724820614,
0.004524562507867813,
0.007891932502388954,
-0.002882700879126787,
0.006087407469749451,
-0.009355749934911728,
0.004812584724277258,
0.002911592600867152,
0.002269830321893096,
-0.029374873265624046,
0.0012958856532350183,
-0.0005789407878182828,
-0.00753055838868022,
0.009541681967675686,
0.001194208045490086,
-0.002406270010396838,
-0.005568584892898798,
-0.0047729345969855785,
0.010169184766709805,
-0.005121180322021246,
0.005787338130176067,
-0.004046103451400995,
-0.00803246721625328,
-0.001724880887195468,
-0.007675199769437313,
0.000044261745642870665,
0.004492179956287146,
-0.002240954665467143,
-0.005296503659337759,
-0.007556229364126921,
0.001435470418073237,
0.0019079121993854642,
0.002509658457711339,
-0.01928602159023285,
-0.007613403256982565,
0.0004339693405199796,
0.0035510456655174494,
-0.0015947043430060148,
-0.0050621540285646915,
0.002721585566177964,
-0.009092799387872219,
0.005564442835748196,
0.004810616839677095,
0.0016323832096531987,
-0.013064367696642876,
-0.00035405915696173906,
-0.009752658195793629,
-0.009349789470434189,
0.0009802072308957577,
-0.005460428539663553,
-0.0041277967393398285,
0.0012627032119780779,
0.005430064629763365,
0.005741158500313759,
-0.0053521436639130116,
0.0027059109415858984,
0.009500439278781414,
-0.004170105326920748,
-0.00832159724086523,
0.006641305051743984,
0.0065047661773860455,
0.002759000286459923,
-0.0007338421419262886,
0.006009730044752359,
0.007495574187487364,
0.008608284406363964,
0.0017084934515878558,
0.007248572073876858,
0.0014604114694520831,
0.013019682839512825,
-0.0019950978457927704,
-0.000029748689485131763,
-0.005857711657881737,
-0.000763936317525804,
-0.004397707991302013,
0.0018210388952866197,
-0.0025792280212044716,
-0.0021254722960293293,
-0.012548860162496567,
-0.010734548792243004,
-0.004512578248977661,
0.0006629612762480974,
0.0025821770541369915,
-0.0058225481770932674,
-0.002968200948089361,
0.0018515706760808825,
0.008890870958566666,
0.001835788250900805,
-0.005338217597454786,
0.0021568641532212496,
0.0030218851752579212,
-0.01033870317041874,
0.015662886202335358,
-0.010312212631106377,
0.006747513078153133,
-0.00012992718257009983,
-0.016259806230664253,
0.00824934896081686,
0.009928418323397636,
-0.007246289402246475,
0.001134276855736971,
0.0035197369288653135,
0.0030647029634565115,
-0.0012834224617108703,
-0.004046294372528791,
-0.004167711362242699,
-0.01975247822701931,
0.0008744027581997216,
0.02353060059249401,
0.0031375689432024956,
0.010933137498795986,
0.010632139630615711,
-0.0028373869135975838,
0.0017842968227341771,
0.006410490721464157,
0.001420406624674797,
0.012461653910577297,
-0.0089796157553792,
0.00047254766104742885,
0.002762495307251811,
-0.006147549953311682,
0.0030135989654809237,
0.0038022955413907766,
0.005866779945790768,
-0.0012405869783833623,
0.0024982423055917025,
-0.006534024141728878,
-0.004356608726084232,
-0.01715523563325405,
-0.0024345451965928078,
0.008971125818789005,
-0.0018086438067257404,
0.004720128607004881,
-0.010088157840073109,
0.005190528463572264,
0.005213424563407898,
0.006666502915322781,
0.0012807468883693218,
0.0014030506135895848,
0.004424088168889284,
0.011937180534005165,
-0.005476509686559439,
0.0014715377474203706,
0.002450227504596114,
-0.0008498665993101895,
0.0007156241335906088,
0.00640515610575676,
-0.007501034997403622,
-0.00493554025888443,
0.0020322815980762243,
0.0031186346895992756,
-0.0019208240555599332,
-0.0028289288748055696,
-0.008690920658409595,
-0.001790099311619997,
0.0039008704479783773,
-0.005559835117310286,
0.004180623684078455,
-0.00030358604271896183,
0.003116419306024909,
-0.010254678316414356,
-0.0011487464653328061,
-0.003749463940039277,
-0.012725851498544216,
0.010698703117668629,
-0.003198439721018076,
0.00303757400251925,
0.014677452854812145,
0.005967062897980213,
-0.012303265742957592,
0.00545486668124795,
0.008266874589025974,
-0.00395266292616725,
0.004096060525625944,
0.005206656642258167,
-0.005814105737954378,
-0.02299969457089901,
-0.00221200636588037,
-0.010679175145924091,
0.004660747479647398,
-0.0031006268691271544,
0.006013472098857164,
-0.007476195227354765,
0.006486035417765379,
0.008551957085728645,
-0.015328475274145603,
-0.003869251348078251,
-0.010296068154275417,
0.0092369569465518,
0.000766382843721658,
0.00008749143307795748,
-0.004946426954120398,
-0.0024854515213519335,
-0.0008633948746137321,
-0.0022977648768574,
-0.0008278207387775183,
0.007366054691374302,
0.001454483950510621,
-0.004308413714170456,
0.001745508168824017,
-0.002550895093008876,
0.0010218840325251222,
0.001968201482668519,
-0.00951733160763979,
0.003395619336515665,
0.003949996083974838,
-0.0038793699350208044,
-0.002838695654645562,
0.002568644005805254,
-0.0025578634813427925,
-0.0073496997356414795,
-0.009876936674118042,
-0.004349150694906712,
-0.0039007780142128468,
-0.004633428994566202,
-0.011201300658285618,
-0.0035193185321986675,
-0.009993426501750946,
0.007669581566005945,
-0.00747373141348362,
0.011430547572672367,
0.006898475810885429,
-0.005971228703856468,
0.006924177519977093,
-0.0019067088142037392,
0.003614878747612238,
0.0032545493450015783,
0.006681107450276613,
0.0004231576749589294,
-0.008498248644173145,
-0.007832301780581474,
0.010548650287091732,
-0.00830891914665699,
-0.0008961315616033971,
0.014573631808161736,
0.004851899575442076,
0.007442797999829054,
-0.0013244232395663857,
-0.0008137421100400388,
-0.000008042625267989933,
0.006442518904805183,
-0.013689029030501842,
0.002941423561424017,
-0.005253066774457693,
-0.0008061449625529349,
0.004441427532583475,
-0.005939878989011049,
0.003426120849326253,
0.008597581647336483,
0.0024171872064471245,
-0.008799068629741669,
0.0012435723328962922,
0.0014438314829021692,
0.004663396161049604,
-0.013153024017810822,
0.0019907623063772917,
-0.0032473590690642595,
-0.004483050666749477,
-0.004628052469342947,
-0.002915098564699292,
0.0009546268847770989,
0.004470540676265955,
-0.002677256241440773,
0.00672533456236124,
0.00004249854100635275,
-0.007275712676346302,
0.01468697004020214,
-0.004906522110104561,
-0.0020107715390622616,
0.002548146527260542,
0.002653403440490365,
-0.004243406001478434,
-0.006095346994698048,
-0.003833787515759468,
0.003575545037165284,
0.00624269712716341,
-0.0033052272628992796,
-0.00566508574411273,
-0.0013648736057803035,
-0.0007856239681132138,
-0.007589737884700298,
0.0011649669613689184,
0.013371406123042107,
-0.003785658162087202,
0.006718772929161787,
-0.0024647533427923918,
-0.008046180941164494,
-0.013302675448358059,
0.05344752222299576,
-0.001007063896395266,
0.003504654625430703,
0.004615429788827896,
-0.007620504125952721,
-0.0022863009944558144,
-0.0022459477186203003,
0.0080692358314991,
-0.0066476562060415745,
-0.007390385027974844,
0.01099978107959032,
-0.003441565204411745,
0.004010670352727175,
0.0030686580576002598,
-0.001467042719013989,
0.01748102903366089,
-0.0023176686372607946,
-0.013003984466195107,
-0.018569257110357285,
0.006467476021498442,
-0.005081886891275644,
-0.007767461705952883,
0.008156591095030308,
-0.003572276094928384,
-0.0033353399485349655,
0.003783479565754533,
0.006826356984674931,
-0.002202032133936882,
0.002540604444220662,
-0.0028082714416086674,
-0.0015026158653199673,
0.0005280600162222981,
0.001596182701177895,
0.005275564733892679,
0.010421463288366795,
-0.0029308937955647707,
0.0037809424102306366,
-0.0013923830119892955,
-0.00107905815821141,
-0.0032088400330394506,
0.006208682432770729,
0.007732846308499575,
0.00003453120734775439,
-0.0013639726676046848,
0.0047101969830691814,
0.0034526707604527473,
-0.0000954240167629905,
0.01255117915570736,
0.0015839355764910579,
-0.005750369746237993,
0.010392515920102596,
0.009306291118264198,
-0.0004030999552924186,
0.00913551077246666,
-0.0010043663205578923,
0.004192193038761616,
0.004579156171530485,
-0.008802917785942554,
-0.013095804490149021,
-0.0029164550360292196,
0.008756930939853191,
0.009075206704437733,
-0.0002562765730544925,
0.0010183390695601702,
-0.001572679728269577,
-0.001404693117365241,
-0.005704886745661497,
-0.006815656553953886,
-0.0028645293787121773,
0.0006577717722393572,
0.006113461218774319,
0.07095149159431458,
-0.007194832433015108,
-0.001011957647278905,
-0.008786153048276901,
0.00005252776463748887,
-0.002819000044837594,
-0.0013001246843487024,
0.000972842623014003,
-0.00028291530907154083,
0.0016677401727065444,
0.0038611204363405704,
-0.00730487983673811,
-0.01061673741787672,
0.0023875334300100803,
0.00045810939627699554,
-0.002915171440690756,
0.003525683656334877,
0.005916993599385023,
-0.007623680867254734,
0.0019996240735054016,
-0.01326619554311037,
-0.0018127417424693704,
-0.0012335748178884387,
-0.010852727107703686,
-0.004604707472026348,
-0.0050032963044941425,
0.007449012249708176,
0.005098928231745958,
0.00502889696508646,
-0.002131036715582013,
0.0050355312414467335,
-0.0007355684065259993,
0.0028938143514096737,
-0.005628027953207493,
-0.00001792429065972101,
-0.005938425660133362,
0.008881180547177792,
0.0027824712451547384,
-0.014323217794299126,
-0.005020104814320803,
-0.0027227476239204407,
-0.0006882310844957829,
-0.007362802512943745,
0.006065569818019867,
-0.0034257376100867987,
0.005895894020795822,
-0.003232079790905118,
0.0035735764540731907,
-0.004936318378895521,
0.00407022750005126,
-0.012560847215354443,
0.004576242528855801,
-0.17621876299381256,
0.010933551006019115,
0.0025144387036561966,
-0.004605559166520834,
-0.004372051917016506,
-0.0131255267187953,
-0.00804871041327715,
0.004739042837172747,
0.008934772573411465,
0.003932654391974211,
-0.001822350430302322,
-0.0013936249306425452,
0.005766616202890873,
0.004356366582214832,
-0.0012881674338132143,
-0.0048587811179459095,
0.004350953735411167,
-0.006044726353138685,
-0.0017313078278675675,
0.004743400029838085,
0.005396186374127865,
0.014119502156972885,
0.0008868431905284524,
0.0011672629043459892,
0.00042190070962533355,
-0.003967741969972849,
0.005046493373811245,
-0.0037781863939017057,
0.004072992596775293,
-0.015105065889656544,
-0.0062136780470609665,
-0.005077724810689688,
-0.006836592685431242,
0.00237978994846344,
0.0057985614985227585,
-0.0020573020447045565,
0.009235723875463009,
0.0004386887012515217,
-0.006973333191126585,
0.006128660403192043,
-0.007870936766266823,
0.029373088851571083,
0.0032917296048253775,
0.0072174882516264915,
0.0006711406167596579,
-0.006723723839968443,
-0.0058161974884569645,
0.008731394074857235,
0.0024665386881679296,
0.014003191143274307,
-0.016830965876579285,
-0.001974139828234911,
0.0032685776241123676,
0.019910795614123344,
-0.0064946566708385944,
-0.009602276608347893,
-0.00719982385635376,
-0.004296517465263605,
0.001305994694121182,
0.00839388556778431,
0.011480662040412426,
-0.0032475001644343138,
0.006566845346242189,
-0.0036568203940987587,
-0.023007037118077278,
0.002946381224319339,
-0.0013090487336739898,
-0.004326031543314457,
-0.0013980705989524722,
0.007250508759170771,
0.007138003595173359,
-0.002247978001832962,
0.002637456636875868,
0.0002908982278313488,
0.002731777261942625,
-0.0010216677328571677,
0.0066505554132163525,
-0.002578319050371647,
0.006950824521481991,
-0.010149271227419376,
0.01103152520954609,
-0.009753614664077759,
-0.0014113712823018432,
0.0018136582802981138,
-0.0053628613241016865,
0.012387830764055252,
0.005102881230413914,
-0.0009616187307983637,
-0.0018132684053853154,
-0.012100926600396633,
-0.002392733236774802,
0.0021796508226543665,
0.0038313763216137886,
-0.007348703686147928,
0.0031761571299284697,
0.0007132854661904275,
0.0017050839960575104,
0.0038253874517977238,
-0.007979132235050201,
0.007609611377120018,
0.00472929747775197,
-0.008537390269339085,
-0.00036797081702388823,
-0.006894593592733145,
0.0029985541477799416,
0.003801560727879405,
-0.006939970888197422,
-0.00932950060814619,
0.0028003843035548925,
-0.005556653253734112,
-0.006193654146045446,
0.002714410424232483,
-0.009638509713113308,
-0.008977367542684078,
-0.003437632927671075,
-0.012360475026071072,
0.000787666067481041
] |
8a3e37aebc3bcbec9a89c90db3f81c339c737670 | 8,847 | py | Python | tests/unit/test_trial_component.py | owen-t/sagemaker-experiments-1 | ef2af4009c3a5c6a63db5cec6b9de6c614dfdd66 | [
"Apache-2.0"
] | null | null | null | tests/unit/test_trial_component.py | owen-t/sagemaker-experiments-1 | ef2af4009c3a5c6a63db5cec6b9de6c614dfdd66 | [
"Apache-2.0"
] | null | null | null | tests/unit/test_trial_component.py | owen-t/sagemaker-experiments-1 | ef2af4009c3a5c6a63db5cec6b9de6c614dfdd66 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Amazon.com, Inc. or its affiliates. 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. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from smexperiments import trial_component, api_types
import datetime
import pytest
import unittest.mock
@pytest.fixture
def sagemaker_boto_client():
return unittest.mock.Mock()
def test_create(sagemaker_boto_client):
sagemaker_boto_client.create_trial_component.return_value = {
"TrialComponentArn": "bazz",
}
obj = trial_component.TrialComponent.create(
trial_component_name="foo", display_name="bar", sagemaker_boto_client=sagemaker_boto_client
)
sagemaker_boto_client.create_trial_component.assert_called_with(TrialComponentName="foo", DisplayName="bar")
assert "foo" == obj.trial_component_name
assert "bar" == obj.display_name
assert "bazz" == obj.trial_component_arn
def test_load(sagemaker_boto_client):
now = datetime.datetime.now(datetime.timezone.utc)
sagemaker_boto_client.describe_trial_component.return_value = {
"TrialComponentArn": "A",
"TrialComponentName": "B",
"DisplayName": "C",
"Status": {"PrimaryStatus": "InProgress", "Message": "D"},
"Parameters": {"E": {"NumberValue": 1.0}, "F": {"StringValue": "G"}},
"InputArtifacts": {"H": {"Value": "s3://foo/bar", "MediaType": "text/plain"}},
"OutputArtifacts": {"I": {"Value": "s3://whizz/bang", "MediaType": "text/plain"}},
"Metrics": [
{
"MetricName": "J",
"Count": 1,
"Min": 1.0,
"Max": 2.0,
"Avg": 3.0,
"StdDev": 4.0,
"SourceArn": "K",
"Timestamp": now,
}
],
}
obj = trial_component.TrialComponent.load(trial_component_name="foo", sagemaker_boto_client=sagemaker_boto_client)
sagemaker_boto_client.describe_trial_component.assert_called_with(TrialComponentName="foo")
assert "A" == obj.trial_component_arn
assert "B" == obj.trial_component_name
assert "C" == obj.display_name
assert api_types.TrialComponentStatus(primary_status="InProgress", message="D") == obj.status
assert {"E": 1.0, "F": "G"} == obj.parameters
assert {"H": api_types.TrialComponentArtifact(value="s3://foo/bar", media_type="text/plain")}
assert {"I": api_types.TrialComponentArtifact(value="s3://whizz/bang", media_type="text/plain")}
assert [
api_types.TrialComponentMetricSummary(
metric_name="J", count=1, min=1.0, max=2.0, avg=3.0, std_dev=4.0, source_arn="K", timestamp=now
)
]
def test_list(sagemaker_boto_client):
start_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)
end_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=2)
creation_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=3)
last_modified_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=4)
sagemaker_boto_client.list_trial_components.side_effect = [
{
"TrialComponentSummaries": [
{
"TrialComponentName": "A" + str(i),
"TrialComponentArn": "B" + str(i),
"DisplayName": "C" + str(i),
"SourceArn": "D" + str(i),
"Status": {"PrimaryStatus": "InProgress", "Message": "E" + str(i)},
"StartTime": start_time + datetime.timedelta(hours=i),
"EndTime": end_time + datetime.timedelta(hours=i),
"CreationTime": creation_time + datetime.timedelta(hours=i),
"LastModifiedTime": last_modified_time + datetime.timedelta(hours=i),
"LastModifiedBy": {},
}
for i in range(10)
],
"NextToken": "100",
},
{
"TrialComponentSummaries": [
{
"TrialComponentName": "A" + str(i),
"TrialComponentArn": "B" + str(i),
"DisplayName": "C" + str(i),
"SourceArn": "D" + str(i),
"Status": {"PrimaryStatus": "InProgress", "Message": "E" + str(i)},
"StartTime": start_time + datetime.timedelta(hours=i),
"EndTime": end_time + datetime.timedelta(hours=i),
"CreationTime": creation_time + datetime.timedelta(hours=i),
"LastModifiedTime": last_modified_time + datetime.timedelta(hours=i),
"LastModifiedBy": {},
}
for i in range(10, 20)
]
},
]
expected = [
api_types.TrialComponentSummary(
trial_component_name="A" + str(i),
trial_component_arn="B" + str(i),
display_name="C" + str(i),
source_arn="D" + str(i),
status=api_types.TrialComponentStatus(primary_status="InProgress", message="E" + str(i)),
start_time=start_time + datetime.timedelta(hours=i),
end_time=end_time + datetime.timedelta(hours=i),
creation_time=creation_time + datetime.timedelta(hours=i),
last_modified_time=last_modified_time + datetime.timedelta(hours=i),
last_modified_by={},
)
for i in range(20)
]
result = list(
trial_component.TrialComponent.list(
sagemaker_boto_client=sagemaker_boto_client,
source_arn="foo",
sort_by="CreationTime",
sort_order="Ascending",
)
)
assert expected == result
expected_calls = [
unittest.mock.call(SortBy="CreationTime", SortOrder="Ascending", SourceArn="foo"),
unittest.mock.call(NextToken="100", SortBy="CreationTime", SortOrder="Ascending", SourceArn="foo"),
]
assert expected_calls == sagemaker_boto_client.list_trial_components.mock_calls
def test_list_empty(sagemaker_boto_client):
sagemaker_boto_client.list_trial_components.return_value = {"TrialComponentSummaries": []}
assert [] == list(trial_component.TrialComponent.list(sagemaker_boto_client=sagemaker_boto_client))
def test_list_trial_components_call_args(sagemaker_boto_client):
created_before = datetime.datetime(1999, 10, 12, 0, 0, 0)
created_after = datetime.datetime(1990, 10, 12, 0, 0, 0)
trial_name = "foo-trial"
experiment_name = "foo-experiment"
next_token = "thetoken"
max_results = 99
sagemaker_boto_client.list_trial_components.return_value = {}
assert [] == list(
trial_component.TrialComponent.list(
sagemaker_boto_client=sagemaker_boto_client,
trial_name=trial_name,
experiment_name=experiment_name,
created_before=created_before,
created_after=created_after,
next_token=next_token,
max_results=max_results,
sort_by="CreationTime",
sort_order="Ascending",
)
)
expected_calls = [
unittest.mock.call(
TrialName="foo-trial",
ExperimentName="foo-experiment",
CreatedBefore=created_before,
CreatedAfter=created_after,
SortBy="CreationTime",
SortOrder="Ascending",
NextToken="thetoken",
MaxResults=99,
)
]
assert expected_calls == sagemaker_boto_client.list_trial_components.mock_calls
def test_save(sagemaker_boto_client):
obj = trial_component.TrialComponent(sagemaker_boto_client, trial_component_name="foo", display_name="bar")
sagemaker_boto_client.update_trial_component.return_value = {}
obj.save()
sagemaker_boto_client.update_trial_component.assert_called_with(TrialComponentName="foo", DisplayName="bar")
def test_delete(sagemaker_boto_client):
obj = trial_component.TrialComponent(sagemaker_boto_client, trial_component_name="foo", display_name="bar")
sagemaker_boto_client.delete_trial_component.return_value = {}
obj.delete()
sagemaker_boto_client.delete_trial_component.assert_called_with(TrialComponentName="foo")
def test_boto_ignore():
obj = trial_component.TrialComponent(sagemaker_boto_client, trial_component_name="foo", display_name="bar")
assert obj._boto_ignore() == ["ResponseMetadata", "CreatedBy"]
| 41.341121 | 118 | 0.635696 | 1 | 2.1006 | [
-0.014799626544117928,
0.019605573266744614,
0.021930504590272903,
0.009358461014926434,
-0.012531237676739693,
0.010230710729956627,
-0.012828192673623562,
-0.04337827116250992,
-0.02418893575668335,
0.008154774084687233,
0.03432246670126915,
0.0077394177205860615,
0.040577422827482224,
-0.05117654427886009,
-0.023582259193062782,
-0.014539883472025394,
0.030532829463481903,
0.05811857804656029,
-0.0546666756272316,
0.0215137992054224,
0.012946520000696182,
0.010823413729667664,
-0.006985577289015055,
0.020093167200684547,
-0.01700545661151409,
-0.0394076406955719,
-0.010858518071472645,
0.0538734570145607,
0.009925168938934803,
-0.04591032490134239,
-0.004981819074600935,
0.007430640514940023,
-0.032300613820552826,
0.016366062685847282,
-0.01567012257874012,
-0.005710152443498373,
0.02057051844894886,
-0.04361216351389885,
-0.02795359492301941,
-0.003765174886211753,
0.0011473617050796747,
0.02946527674794197,
-0.0551547072827816,
-0.00984632596373558,
0.028928376734256744,
-0.005843936000019312,
0.014201793819665909,
-0.013921289704740047,
-0.023910706862807274,
0.022759515792131424,
0.011229309253394604,
0.007307877764105797,
-0.021189434453845024,
-0.019546115770936012,
-0.033800095319747925,
-0.049529366195201874,
-0.0006118734600022435,
0.05134984478354454,
-0.01417854055762291,
-0.019328413531184196,
-0.0302681103348732,
0.004816387314349413,
0.010022412054240704,
0.01514341775327921,
-0.03028728812932968,
-0.01450641080737114,
0.023261750116944313,
0.009978707879781723,
-0.016822703182697296,
-0.029642965644598007,
0.020563477650284767,
-0.021925488486886024,
0.03489109128713608,
0.06495173275470734,
0.030689040198922157,
0.03274611011147499,
-0.03766682371497154,
0.023482711985707283,
0.006187875755131245,
-0.04549271613359451,
-0.031013108789920807,
0.02986852079629898,
-0.04429245367646217,
0.011160480789840221,
0.011359487660229206,
-0.023336105048656464,
0.018953992053866386,
-0.056503280997276306,
0.03041001595556736,
0.05555165559053421,
-0.06104619801044464,
0.03997594118118286,
0.02266104333102703,
0.018279599025845528,
-0.020474771037697792,
-0.04871291294693947,
0.01398223452270031,
0.005560504272580147,
0.03200951963663101,
-0.009090475738048553,
0.0358387716114521,
-0.01404447853565216,
0.0004110090958420187,
-0.009218188934028149,
-0.009510311298072338,
0.016922805458307266,
-0.023267285898327827,
-0.025574322789907455,
0.011396411806344986,
-0.012733976356685162,
-0.007928294129669666,
0.005327987018972635,
0.0003581698110792786,
0.0036123807076364756,
-0.029757168143987656,
-0.03903724253177643,
0.03658203035593033,
0.020771978422999382,
0.00031768152257427573,
-0.022746697068214417,
0.0050531732849776745,
0.03432630002498627,
0.028530938550829887,
0.018089765682816505,
-0.01211859006434679,
0.05533817037940025,
-0.01894284598529339,
0.03673652559518814,
0.014494637958705425,
-0.01216378528624773,
-0.01701592095196247,
0.022398844361305237,
-0.017923036590218544,
0.00015489784709643573,
0.05516336113214493,
-0.04235082119703293,
-0.005979109089821577,
0.0228146780282259,
-0.03772466629743576,
0.044927943497896194,
0.020640509203076363,
-0.05868404358625412,
0.00029754554270766675,
-0.024545744061470032,
0.03373611718416214,
-0.033451713621616364,
-0.03634055331349373,
-0.034004200249910355,
-0.00844758190214634,
0.0009182841749861836,
0.03866768628358841,
-0.009807349182665348,
-0.0013672191416844726,
0.018405044451355934,
-0.03734934329986572,
0.01877785101532936,
0.005444257985800505,
-0.006130201742053032,
-0.003289181273430586,
-0.004721172619611025,
0.0035900988150388002,
0.016831766813993454,
0.011385140009224415,
0.027918972074985504,
0.027280136942863464,
0.03194303438067436,
-0.022024206817150116,
0.05359556898474693,
-0.010295174084603786,
0.0039893100038170815,
-0.01476626843214035,
0.025783725082874298,
0.02287421189248562,
0.020418807864189148,
-0.03799054026603699,
-0.033661458641290665,
-0.011609066277742386,
-0.03734542801976204,
-0.031673721969127655,
-0.034557174891233444,
0.023965494707226753,
0.07622237503528595,
0.03166418895125389,
0.0069991243071854115,
0.017701996490359306,
-0.035294488072395325,
0.0064971065148711205,
-0.025211598724126816,
0.016020789742469788,
-0.0025660123210400343,
-0.034765757620334625,
0.04782753437757492,
-0.023594984784722328,
-0.013328149914741516,
0.041288431733846664,
0.01412773597985506,
0.018913188949227333,
0.007648778613656759,
0.007930353283882141,
-0.0027166344225406647,
0.0455649197101593,
0.02704106643795967,
-0.004775306209921837,
0.039874155074357986,
0.005919097922742367,
-0.009599076583981514,
-0.621609628200531,
0.059939462691545486,
0.0445471815764904,
0.005867037456482649,
-0.013869260437786579,
0.016537945717573166,
-0.03573175147175789,
0.028509169816970825,
-0.04729199409484863,
-0.00616738386452198,
-0.0034315618686378,
-0.021119486540555954,
-0.048673685640096664,
0.013095577247440815,
-0.008912930265069008,
-0.05341034382581711,
0.020476294681429863,
0.015416347421705723,
-0.026719706133008003,
0.04619069769978523,
0.0025402065366506577,
-0.03312944248318672,
-0.03654094040393829,
0.002041066996753216,
0.022179828956723213,
0.021566729992628098,
-0.043545763939619064,
0.04679787904024124,
-0.023342303931713104,
0.02866070531308651,
-0.011545040644705296,
-0.031556446105241776,
-0.008769365027546883,
0.014412989839911461,
-0.009024969302117825,
0.03286615014076233,
0.026751689612865448,
-0.027462176978588104,
-0.04872193932533264,
0.028075240552425385,
-0.030791470780968666,
-0.01946237124502659,
0.020284786820411682,
-0.054281044751405716,
-0.03858265280723572,
-0.04498426988720894,
0.009089238941669464,
-0.005573090631514788,
0.01780986227095127,
-0.004459296353161335,
-0.006841882131993771,
0.03849776089191437,
0.05072500556707382,
-0.04623075947165489,
-0.03665286302566528,
-0.029360992833971977,
-0.006102466490119696,
-0.016070546582341194,
-0.0013354404363781214,
0.010976377874612808,
0.035184070467948914,
0.013809244148433208,
-0.05155729502439499,
0.02587604522705078,
-0.034070003777742386,
0.03158631548285484,
0.09377970546483994,
-0.046745192259550095,
0.01798602193593979,
0.022413469851017,
-0.009594768285751343,
-0.006303197704255581,
-0.04995473474264145,
0.06946448236703873,
-0.02721700631082058,
0.0014938577078282833,
-0.00011341975186951458,
-0.02821970172226429,
-0.030207889154553413,
-0.01806839182972908,
0.00624389573931694,
-0.010057056322693825,
-0.027126837521791458,
0.0017284873174503446,
-0.0111183300614357,
-0.024060359224677086,
0.013047817163169384,
0.0011186532210558653,
0.033857136964797974,
0.04931342229247093,
0.058894652873277664,
0.001295842812396586,
0.008188621141016483,
-0.028896423056721687,
-0.004188891034573317,
-0.009549056179821491,
0.016055922955274582,
0.05003220587968826,
0.006334311328828335,
0.02664189599454403,
-0.01980620063841343,
0.02502978779375553,
-0.009969834238290787,
-0.03144686669111252,
0.02189483493566513,
-0.007867330685257912,
0.022565018385648727,
0.016691599041223526,
0.011087087914347649,
-0.037662357091903687,
-0.02639259584248066,
0.04916296899318695,
-0.027138812467455864,
0.03575903922319412,
-0.00331554445438087,
-0.023548666387796402,
0.02613544464111328,
-0.024440020322799683,
0.003766753477975726,
-0.022004468366503716,
-0.017925461754202843,
0.03255467861890793,
0.0009413892985321581,
-0.010265317745506763,
0.04624953493475914,
-0.0012945221969857812,
0.010474606417119503,
0.021854499354958534,
0.005252748262137175,
0.04927178472280502,
-0.025633955374360085,
-0.042664602398872375,
-0.00788096897304058,
-0.023876240476965904,
0.019151372835040092,
-0.0300491563975811,
0.025559166446328163,
-0.056465908885002136,
-0.01752985082566738,
-0.026596197858452797,
0.016663867980241776,
-0.009468668140470982,
-0.0012708387803286314,
-0.014532633125782013,
0.033225953578948975,
-0.013680982403457165,
0.04139667749404907,
0.006142491474747658,
-0.011869711801409721,
-0.007588859647512436,
-0.006559680216014385,
-0.03061595931649208,
0.008560546673834324,
0.01849088817834854,
0.022384675219655037,
0.02606731653213501,
0.022318420931696892,
0.033234674483537674,
-0.006496231071650982,
0.022860083729028702,
-0.04458335414528847,
-0.000385345978429541,
0.056675780564546585,
0.01968119852244854,
-0.019770924001932144,
-0.032326165586709976,
0.046447668224573135,
0.023795802146196365,
0.01760755479335785,
-0.008871794678270817,
0.025782737880945206,
0.01696179248392582,
0.0335906483232975,
-0.013191256672143936,
-0.03860383480787277,
0.02240026369690895,
-0.00332116661593318,
-0.028914403170347214,
-0.011272095143795013,
-0.0017983510624617338,
-0.032601237297058105,
-0.025863420218229294,
0.013033110648393631,
-0.03802055865526199,
0.03130151703953743,
-0.07990778982639313,
-0.009627565741539001,
0.01836569607257843,
0.029568573459982872,
-0.003628155216574669,
-0.008764372207224369,
0.006798783782869577,
-0.019827615469694138,
-0.0300454031676054,
-0.04169921204447746,
0.015108758583664894,
0.0016063451766967773,
-0.039731379598379135,
-0.024074826389551163,
-0.036746662110090256,
0.041461486369371414,
0.042523887008428574,
0.004354579374194145,
-0.019739320501685143,
0.02327091433107853,
0.06565920263528824,
-0.0024386567529290915,
0.008849773555994034,
0.02603980153799057,
0.01114469114691019,
0.013253564015030861,
0.015119410119950771,
0.02358308620750904,
-0.05730101466178894,
-0.010439385659992695,
0.035620760172605515,
-0.021128978580236435,
-0.025871507823467255,
-0.03318127617239952,
-0.04722711071372032,
0.014615293592214584,
-0.03643111512064934,
0.03728228807449341,
-0.008709280751645565,
0.009099563583731651,
-0.011699403636157513,
-0.03928413987159729,
0.03457821533083916,
-0.025525612756609917,
-0.032984934747219086,
0.03623458370566368,
0.013370843604207039,
0.015473873354494572,
0.00468913558870554,
-0.050344958901405334,
0.04987400025129318,
-0.020501360297203064,
-0.06022067740559578,
0.02192235179245472,
-0.06369387358427048,
-0.019465966150164604,
-0.015011315234005451,
-0.0012508687796071172,
0.05850732699036598,
0.05333152040839195,
0.004220427013933659,
-0.018356353044509888,
-0.037043336778879166,
-0.06520909070968628,
-0.02311367727816105,
-0.02292364463210106,
0.010026163421571255,
0.012734521180391312,
0.0036816243082284927,
0.05292823538184166,
-0.03744994476437569,
-0.017118636518716812,
0.0005255033611319959,
-0.016081003472208977,
0.03261036425828934,
-0.019068602472543716,
-0.022183338180184364,
-0.0038073183968663216,
0.008115733973681927,
-0.007529132068157196,
-0.01382078230381012,
0.025820311158895493,
0.007749646902084351,
-0.048419494181871414,
0.000050296126573812217,
0.027083924040198326,
0.024256791919469833,
-0.019619204103946686,
0.004209333099424839,
-0.0003166870737913996,
0.011563257314264774,
0.004858558997511864,
-0.021395046263933182,
0.039751458913087845,
0.03948705270886421,
-0.04677500203251839,
0.009437485598027706,
0.01924581080675125,
0.030645359307527542,
0.005799564998596907,
0.020253680646419525,
0.004405128303915262,
-0.025809774175286293,
-0.05260057374835014,
-0.048769671469926834,
-0.0003005505132023245,
0.032574594020843506,
0.05759669840335846,
0.03174543008208275,
-0.0048219626769423485,
0.015080717392265797,
0.003829489229246974,
-0.0007363725453615189,
0.008843770250678062,
-0.01322854869067669,
0.04382007569074631,
0.012976332567632198,
-0.013300142250955105,
-0.056351061910390854,
-0.017580440267920494,
-0.0390792191028595,
0.022922340780496597,
-0.026704465970396996,
0.007732141762971878,
0.015644699335098267,
-0.014096557162702084,
0.0697183609008789,
0.00096609111642465,
0.01085451990365982,
-0.007657166570425034,
0.020716719329357147,
0.06276199221611023,
0.022763434797525406,
0.01349386852234602,
0.011576501652598381,
-0.06469869613647461,
0.008313244208693504,
-0.05221386253833771,
-0.010521672666072845,
-0.006628645583987236,
0.024632558226585388,
-0.03631889820098877,
0.004520813003182411,
-0.05700545758008957,
0.02054801769554615,
-0.029646029695868492,
-0.015533087775111198,
-0.013176186010241508,
-0.021244650706648827,
0.02829866111278534,
-0.04558468982577324,
-0.00286288233473897,
0.034437913447618484,
-0.03803325444459915,
0.017761582508683205,
0.02586900256574154,
0.00035294596455059946,
0.005268980748951435,
0.02986454777419567,
0.018906572833657265,
0.03725023567676544,
-0.038099244236946106,
-0.022202467545866966,
0.020632561296224594,
0.004940049722790718,
-0.004701498430222273,
-0.008601958863437176,
-0.014467170462012291,
0.006724416743963957,
0.014702142216265202,
-0.01104662660509348,
-0.02378566935658455,
0.004781069699674845,
-0.010836688801646233,
0.05578229948878288,
0.04532409831881523,
-0.026842067018151283,
-0.006833570543676615,
-0.015768123790621758,
0.0030998317524790764,
-0.033325593918561935,
0.046829547733068466,
-0.008890203200280666,
-0.023926591500639915,
-0.022834042087197304,
-0.019435957074165344,
-0.02134562097489834,
0.034201137721538544,
-0.007720896042883396,
0.026770643889904022,
0.008700086735188961,
-0.01350773312151432,
0.049284327775239944,
0.0031224857084453106,
-0.035062871873378754,
0.012005803175270557,
0.01950991339981556,
0.020383043214678764,
-0.015411202795803547,
-0.0002795563777908683,
0.007158683147281408,
-0.021075597032904625,
-0.02742001600563526,
0.02884179912507534,
-0.026583878323435783,
0.023744264617562294,
-0.01925535872578621,
0.01861034706234932,
0.02057965286076069,
0.002924796659499407,
-0.005444562528282404,
-0.011222376488149166,
-0.000307602109387517,
-0.0036019538529217243,
0.020590411499142647,
0.010670371353626251,
-0.014175291173160076,
-0.01167526375502348,
-0.018225019797682762,
0.00978897511959076,
0.01613468863070011,
-0.007953849621117115,
0.0038340759929269552,
0.021849850192666054,
0.05076132342219353,
-0.003930449951440096,
-0.02306244894862175,
-0.015122623182833195,
-0.019592558965086937,
-0.04106825962662697,
-0.009245024994015694,
-0.028185829520225525,
0.0005397130153141916,
-0.012874331325292587,
0.03707796335220337,
-0.038114797323942184,
0.024263745173811913,
0.008088887669146061,
-0.0035698767751455307,
0.0028363431338220835,
-0.019802918657660484,
0.0023652450181543827,
0.0011999832931905985,
-0.019500570371747017,
0.02576739527285099,
-0.054951608180999756,
-0.029176965355873108,
0.030922792851924896,
0.023604616522789,
0.042093727737665176,
-0.026378704234957695,
-0.02391963265836239,
-0.006362048909068108,
-0.004827436059713364,
-0.009052950888872147,
0.03858092427253723,
0.04058767855167389,
0.014044002629816532,
0.021865926682949066,
0.008173790760338306,
-0.08971066027879715,
-0.02987206168472767,
-0.04529981315135956,
0.012028565630316734,
0.015447588637471199,
-0.0004605664871633053,
0.019543975591659546,
-0.024808209389448166,
-0.031971078366041183,
0.03203321620821953,
0.016566753387451172,
-0.03187641128897667,
0.05083801969885826,
0.019851883873343468,
0.014748313464224339,
0.023259581997990608,
0.01282491348683834,
0.005390924867242575,
-0.010703475214540958,
0.05727405473589897,
-0.006284157279878855,
0.0011099468683823943,
-0.0019606526475399733,
0.03159293904900551,
-0.037395644932985306,
-0.0005710280383937061,
0.028820859268307686,
-0.019466141238808632,
0.009386942721903324,
-0.030469156801700592,
0.04059872031211853,
-0.03524349257349968,
-0.04109273478388786,
-0.014932355843484402,
0.007366674952208996,
-0.07082203775644302,
0.006642709951847792,
-0.007892822846770287,
-0.006344059947878122,
-0.02141936868429184,
-0.04089192673563957,
0.0025400666054338217,
0.051756851375103,
-0.029512211680412292,
-0.0068387361243367195,
-0.010182405821979046,
0.005478133913129568,
-0.009472573176026344,
0.010696659795939922,
-0.03455881029367447,
-0.013359248638153076,
-0.004935897886753082,
0.047165222465991974,
0.027463849633932114,
0.03366551175713539,
-0.02499488927423954,
-0.036398015916347504,
0.026504183188080788,
0.0016338041750714183,
0.03730074688792229,
-0.0104029830545187,
0.051773980259895325,
0.02674252912402153,
0.011546654626727104,
-0.05909699946641922,
-0.03227556496858597,
-0.0032527290750294924,
-0.030938731506466866,
-0.008588808588683605,
0.06288767606019974,
0.026895441114902496,
0.06776390969753265,
-0.041510339826345444,
-0.03617822006344795,
0.0324065238237381,
-0.0070662107318639755,
0.04282505810260773,
-0.022484268993139267,
-0.02179660275578499,
0.009197873994708061,
-0.0237029530107975,
-0.02404560148715973,
0.0279798936098814,
0.019296403974294662,
0.0030401824042201042,
-0.00021899516286794096,
0.02710001729428768,
-0.02917606383562088,
-0.014746090397238731,
0.012883393093943596,
-0.05733949691057205,
-0.0008375984616577625,
0.014782491140067577,
-0.047336652874946594,
-0.0334453210234642,
0.050661101937294006,
-0.026402095332741737,
-0.015467869117856026,
-0.002365784952417016,
-0.006775266490876675,
0.013431241735816002,
0.006096016149967909,
0.011695463210344315,
0.01880939118564129,
0.0329391248524189,
-0.019522052258253098,
0.014690623618662357,
-0.026671165600419044,
-0.0006218421622179449,
0.022141925990581512,
-0.04932737350463867,
-0.04284317418932915,
0.033171311020851135,
-0.01579848676919937,
-0.02537543512880802,
0.004820695146918297,
0.020312195643782616
] |
8a3e99f0293f853274afed91ad78cb5b4d2be8d4 | 8,379 | py | Python | cadnano25/cadnano/part/xovercmds.py | amylittleyang/OtraCAD | 126360719704caf6850d42565fe96be53b66a22d | [
"MIT"
] | null | null | null | cadnano25/cadnano/part/xovercmds.py | amylittleyang/OtraCAD | 126360719704caf6850d42565fe96be53b66a22d | [
"MIT"
] | null | null | null | cadnano25/cadnano/part/xovercmds.py | amylittleyang/OtraCAD | 126360719704caf6850d42565fe96be53b66a22d | [
"MIT"
] | null | null | null | from cadnano.cnproxy import UndoCommand
from cadnano.strand import Strand
from cadnano import getBatch
import cadnano.preferences as prefs
import random
class CreateXoverCommand(UndoCommand):
"""
Creates a Xover from the 3' end of strand5p to the 5' end of strand3p
this needs to
1. preserve the old oligo of strand3p
2. install the crossover
3. apply the strand5p oligo to the strand3p
"""
def __init__(self, part, strand5p, strand5p_idx, strand3p, strand3p_idx, update_oligo=True):
super(CreateXoverCommand, self).__init__("create xover")
self._part = part
self._strand5p = strand5p
self._strand5p_idx = strand5p_idx
self._strand3p = strand3p
self._strand3p_idx = strand3p_idx
self._old_oligo3p = strand3p.oligo()
self._update_oligo = update_oligo
# end def
def redo(self):
part = self._part
strand5p = self._strand5p
strand5p_idx = self._strand5p_idx
strand3p = self._strand3p
strand3p_idx = self._strand3p_idx
olg5p = strand5p.oligo()
old_olg3p = self._old_oligo3p
# 0. Deselect the involved strands
doc = strand5p.document()
doc.removeStrandFromSelection(strand5p)
doc.removeStrandFromSelection(strand3p)
if self._update_oligo:
# Test for Loopiness
if olg5p == strand3p.oligo():
olg5p.setLoop(True)
else:
# 1. update preserved oligo length
olg5p.incrementLength(old_olg3p.length())
# 2. Remove the old oligo and apply the 5' oligo to the 3' strand
old_olg3p.removeFromPart()
for strand in strand3p.generator3pStrand():
# emits strandHasNewOligoSignal
Strand.setOligo(strand, olg5p)
# 3. install the Xover
strand5p.setConnection3p(strand3p)
strand3p.setConnection5p(strand5p)
#print('strand5p = %s, connection3p = %s'%(strand5p._name, strand3p._name))
ss5 = strand5p.strandSet()
vh5p = ss5.virtualHelix()
st5p = ss5.strandType()
ss3 = strand3p.strandSet()
vh3p = ss3.virtualHelix()
st3p = ss3.strandType()
part.partActiveVirtualHelixChangedSignal.emit(part, vh5p)
# strand5p.strandXover5pChangedSignal.emit(strand5p, strand3p)
# if self._update_oligo and not getBatch():
if self._update_oligo:
strand5p.strandUpdateSignal.emit(strand5p)
strand3p.strandUpdateSignal.emit(strand3p)
# end def
def undo(self):
part = self._part
strand5p = self._strand5p
strand5p_idx = self._strand5p_idx
strand3p = self._strand3p
strand3p_idx = self._strand3p_idx
old_olg3p = self._old_oligo3p
olg5p = strand5p.oligo()
# 0. Deselect the involved strands
doc = strand5p.document()
doc.removeStrandFromSelection(strand5p)
doc.removeStrandFromSelection(strand3p)
# 1. uninstall the Xover
strand5p.setConnection3p(None)
strand3p.setConnection5p(None)
if self._update_oligo:
# Test Loopiness
if old_olg3p.isLoop():
old_olg3p.setLoop(False)
else:
# 2. restore the modified oligo length
olg5p.decrementLength(old_olg3p.length())
# 3. apply the old oligo to strand3p
old_olg3p.addToPart(part)
for strand in strand3p.generator3pStrand():
# emits strandHasNewOligoSignal
Strand.setOligo(strand, old_olg3p)
ss5 = strand5p.strandSet()
vh5p = ss5.virtualHelix()
st5p = ss5.strandType()
ss3 = strand3p.strandSet()
vh3p = ss3.virtualHelix()
st3p = ss3.strandType()
part.partActiveVirtualHelixChangedSignal.emit(part, vh5p)
# strand5p.strandXover5pChangedSignal.emit(strand5p, strand3p)
if self._update_oligo:
strand5p.strandUpdateSignal.emit(strand5p)
strand3p.strandUpdateSignal.emit(strand3p)
# end def
# end class
class RemoveXoverCommand(UndoCommand):
"""
Removes a Xover from the 3' end of strand5p to the 5' end of strand3p
this needs to
1. preserve the old oligo of strand3p
2. install the crossover
3. update the oligo length
4. apply the new strand3p oligo to the strand3p
"""
def __init__(self, part, strand5p, strand3p):
super(RemoveXoverCommand, self).__init__("remove xover")
self._part = part
self._strand5p = strand5p
self._strand5p_idx = strand5p.idx3Prime()
self._strand3p = strand3p
self._strand3p_idx = strand3p.idx5Prime()
n_o3p = self._new_oligo3p = strand3p.oligo().shallowCopy()
colorList = prefs.STAP_COLORS if strand5p.strandSet().isStaple() \
else prefs.SCAF_COLORS
n_o3p.setColor(random.choice(colorList).name())
n_o3p.setLength(0)
for strand in strand3p.generator3pStrand():
n_o3p.incrementLength(strand.totalLength())
# end def
n_o3p.setStrand5p(strand3p)
self._isLoop = strand3p.oligo().isLoop()
# end def
def redo(self):
part = self._part
strand5p = self._strand5p
strand5p_idx = self._strand5p_idx
strand3p = self._strand3p
strand3p_idx = self._strand3p_idx
new_olg3p = self._new_oligo3p
olg5p = self._strand5p.oligo()
# 0. Deselect the involved strands
doc = strand5p.document()
doc.removeStrandFromSelection(strand5p)
doc.removeStrandFromSelection(strand3p)
# 1. uninstall the Xover
strand5p.setConnection3p(None)
strand3p.setConnection5p(None)
if self._isLoop:
olg5p.setLoop(False)
olg5p.setStrand5p(strand3p)
else:
# 2. restore the modified oligo length
olg5p.decrementLength(new_olg3p.length())
# 3. apply the old oligo to strand3p
new_olg3p.addToPart(part)
for strand in strand3p.generator3pStrand():
# emits strandHasNewOligoSignal
Strand.setOligo(strand, new_olg3p)
ss5 = strand5p.strandSet()
vh5p = ss5.virtualHelix()
st5p = ss5.strandType()
ss3 = strand3p.strandSet()
vh3p = ss3.virtualHelix()
st3p = ss3.strandType()
part.partActiveVirtualHelixChangedSignal.emit(part, vh5p)
# strand5p.strandXover5pChangedSignal.emit(strand5p, strand3p)
strand5p.strandUpdateSignal.emit(strand5p)
strand3p.strandUpdateSignal.emit(strand3p)
# end def
def undo(self):
part = self._part
strand5p = self._strand5p
strand5p_idx = self._strand5p_idx
strand3p = self._strand3p
strand3p_idx = self._strand3p_idx
olg5p = strand5p.oligo()
new_olg3p = self._new_oligo3p
# 0. Deselect the involved strands
doc = strand5p.document()
doc.removeStrandFromSelection(strand5p)
doc.removeStrandFromSelection(strand3p)
if self._isLoop:
olg5p.setLoop(True)
# No need to restore whatever the old Oligo._strand5p was
else:
# 1. update preserved oligo length
olg5p.incrementLength(new_olg3p.length())
# 2. Remove the old oligo and apply the 5' oligo to the 3' strand
new_olg3p.removeFromPart()
for strand in strand3p.generator3pStrand():
# emits strandHasNewOligoSignal
Strand.setOligo(strand, olg5p)
# end else
# 3. install the Xover
strand5p.setConnection3p(strand3p)
strand3p.setConnection5p(strand5p)
ss5 = strand5p.strandSet()
vh5p = ss5.virtualHelix()
st5p = ss5.strandType()
ss3 = strand3p.strandSet()
vh3p = ss3.virtualHelix()
st3p = ss3.strandType()
part.partActiveVirtualHelixChangedSignal.emit(part, vh5p)
# strand5p.strandXover5pChangedSignal.emit(strand5p, strand3p)
strand5p.strandUpdateSignal.emit(strand5p)
strand3p.strandUpdateSignal.emit(strand3p)
# end def
# end class | 35.807692 | 96 | 0.628118 | 1 | 2.3601 | [
-0.02592843398451805,
0.03481180965900421,
-0.0033981292508542538,
0.07902896404266357,
0.009234065189957619,
0.004090225789695978,
0.04520142078399658,
-0.008363143540918827,
-0.04128432273864746,
-0.02168121188879013,
0.02959890104830265,
0.041356101632118225,
0.039526473730802536,
0.011615386232733727,
-0.00730409100651741,
-0.01557268388569355,
0.2687211036682129,
-0.043955251574516296,
0.016994183883070946,
0.05338258668780327,
-0.018491514027118683,
0.0033501237630844116,
-0.0862177237868309,
-0.003658999688923359,
-0.002810938050970435,
0.03720736876130104,
0.03602417930960655,
-0.029415320605039597,
-0.017796987667679787,
-0.026269150897860527,
0.01614685356616974,
0.0341494120657444,
-0.024902328848838806,
-0.00802510604262352,
-0.03677830100059509,
-0.0003585579397622496,
-0.00709559815004468,
-0.05166719853878021,
0.035216424614191055,
0.000784345087595284,
-0.040583789348602295,
0.028677599504590034,
0.03942107781767845,
-0.05244147405028343,
0.014408138580620289,
0.010394129902124405,
-0.02775350958108902,
-0.07528716325759888,
-0.03513689339160919,
0.03250240162014961,
0.013759512454271317,
0.011894499883055687,
-0.004109041299670935,
-0.06274963915348053,
0.02298375405371189,
-0.024861376732587814,
0.012378726154565811,
-0.017276503145694733,
-0.008632722310721874,
-0.02633744291961193,
-0.06560491025447845,
0.03449927642941475,
0.028883881866931915,
-0.03454391658306122,
-0.008964573964476585,
-0.013413669541478157,
-0.008045799098908901,
0.010538092814385891,
0.06845718622207642,
0.011761151254177094,
0.006293487269431353,
0.0017372964648529887,
-0.022870415821671486,
0.07462269067764282,
-0.045465294271707535,
0.06456170976161957,
-0.0034885979257524014,
-0.02944141998887062,
-0.017859498038887978,
0.02860185131430626,
-0.012506960891187191,
-0.030447034165263176,
-0.03411603718996048,
-0.007187704090029001,
-0.034271489828825,
-0.06345586478710175,
0.010651972144842148,
-0.05423455685377121,
0.02777586318552494,
0.005961321294307709,
-0.02614598535001278,
-0.04288404807448387,
0.04048534110188484,
-0.017086327075958252,
-0.05423933267593384,
-0.04315829649567604,
0.048605334013700485,
0.03617876023054123,
0.02666000835597515,
0.04205756634473801,
0.012233605608344078,
-0.010023299604654312,
0.008839010260999203,
0.024322865530848503,
-0.031852833926677704,
-0.0051186406053602695,
0.007761051412671804,
0.01200008299201727,
-0.004562185145914555,
0.008552290499210358,
0.04519135132431984,
-0.0063404543325304985,
0.005009177140891552,
-0.028160173445940018,
-0.03814302757382393,
-0.016149520874023438,
0.03671826794743538,
0.021552443504333496,
0.011501307599246502,
-0.003353453241288662,
-0.006825907155871391,
0.0443887859582901,
-0.02939867228269577,
-0.05302417650818825,
0.0005749405245296657,
0.06420961022377014,
-0.003366837278008461,
0.020692626014351845,
0.03691606596112251,
-0.04948905482888222,
-0.014867905527353287,
-0.010342293418943882,
-0.05735630542039871,
0.007740277796983719,
-0.01777142845094204,
0.06879335641860962,
-0.0024044131860136986,
-0.010639551095664501,
-0.045782893896102905,
0.022804033011198044,
-0.024790966883301735,
-0.014618857763707638,
-0.015360353514552116,
0.023959418758749962,
0.030522054061293602,
-0.012239775620400906,
-0.024772102013230324,
0.007349261082708836,
-0.03147590532898903,
-0.021615231409668922,
0.05149644985795021,
0.07690605521202087,
0.0417167954146862,
-0.059377722442150116,
0.010762124322354794,
0.0030196921434253454,
0.026286154985427856,
-0.0814204290509224,
0.026597725227475166,
-0.01955287903547287,
-0.02563074417412281,
0.03495998680591583,
0.012654073536396027,
-0.0022348256316035986,
0.06182241439819336,
0.02615637518465519,
-0.014826237224042416,
0.048106078058481216,
0.02825971134006977,
0.042771145701408386,
0.032202139496803284,
0.01421019434928894,
-0.026871515437960625,
-0.04025818780064583,
0.024522803723812103,
-0.01110194344073534,
0.0379011444747448,
0.03901742026209831,
-0.003904656507074833,
-0.046895384788513184,
-0.03964441269636154,
-0.012805091217160225,
0.00902304146438837,
-0.009501957334578037,
-0.04693112149834633,
-0.03820135444402695,
-0.04773921146988869,
-0.017973005771636963,
0.025097114965319633,
0.001846691477112472,
-0.029265692457556725,
0.009541196748614311,
-0.03249290958046913,
0.01326342485845089,
0.003287338884547353,
-0.06121854484081268,
0.03334888443350792,
0.012074382044374943,
0.009625816717743874,
-0.03138177841901779,
-0.0026647786144167185,
-0.0005956526729278266,
0.013111215084791183,
-0.010842718183994293,
0.026358777657151222,
-0.016775144264101982,
-0.4741314947605133,
0.029597248882055283,
-0.010259109549224377,
0.023856233805418015,
0.03373674303293228,
0.0054899659007787704,
0.0010223480639979243,
0.01840069890022278,
0.05430381000041962,
-0.02302117645740509,
-0.016739817336201668,
-0.0113831777125597,
0.024720456451177597,
0.016151249408721924,
0.020716268569231033,
-0.02583790197968483,
-0.0402001217007637,
-0.018753189593553543,
-0.015672478824853897,
-0.017536742612719536,
-0.014466662891209126,
-0.03656673803925514,
0.019689898937940598,
0.019611647352576256,
-0.01618979498744011,
-0.03785482048988342,
-0.04225149378180504,
-0.02879859320819378,
-0.08719365298748016,
0.034988123923540115,
0.0068029360845685005,
-0.010576585307717323,
0.04247665032744408,
-0.013039515353739262,
0.031521763652563095,
0.01603822037577629,
0.027119535952806473,
0.008995821699500084,
-0.02654927596449852,
-0.009013776667416096,
0.02554497681558132,
0.006364651955664158,
-0.0018117056461051106,
-0.015134691260755062,
-0.05835563316941261,
-0.010918271727859974,
0.03014800138771534,
-0.01571197435259819,
-0.00649171881377697,
-0.0035440754145383835,
-0.011213676072657108,
0.05456535145640373,
-0.03127828612923622,
0.029166799038648605,
-0.0024798002559691668,
0.006919179577380419,
-0.02191324532032013,
0.0012289296137169003,
0.012940872460603714,
-0.02015049383044243,
-0.028959397226572037,
0.002130709821358323,
-0.024948876351118088,
0.018536768853664398,
-0.053176987916231155,
-0.008682072162628174,
0.021136276423931122,
-0.009928079321980476,
0.04742826521396637,
-0.0034780078567564487,
-0.025927623733878136,
0.015530128963291645,
-0.003880899865180254,
0.007841121405363083,
0.010686058551073074,
-0.021027110517024994,
0.006174060516059399,
-0.03217975050210953,
-0.03075200878083706,
0.015277000144124031,
0.026449469849467278,
-0.003091463353484869,
-0.001207232242450118,
-0.02917432226240635,
0.008390291593968868,
0.047210175544023514,
0.010340270586311817,
-0.012875898741185665,
0.024110427126288414,
0.0394972562789917,
-0.09080538153648376,
-0.0003408328630030155,
0.0022451411932706833,
0.0006863760645501316,
0.012534774839878082,
0.0344342440366745,
-0.0010648483876138926,
0.001618621521629393,
0.01925717480480671,
0.012864422053098679,
-0.011445454321801662,
-0.019126173108816147,
0.02765258215367794,
-0.026078900322318077,
-0.10348490625619888,
-0.008476330898702145,
0.02996385656297207,
0.006906507536768913,
0.005660739727318287,
-0.03116287849843502,
0.047829873859882355,
-0.004469927866011858,
-0.026992658153176308,
-0.062011923640966415,
-0.07012510299682617,
0.0007084136595949531,
-0.0015336999204009771,
-0.05509067699313164,
-0.04002142325043678,
0.0167116429656744,
0.01351482979953289,
-0.043285828083753586,
-0.04713575541973114,
0.04174613580107689,
-0.022253839299082756,
0.02532392553985119,
-0.03157871216535568,
0.036179810762405396,
-0.013589128851890564,
0.016724642366170883,
0.008051203563809395,
0.014721599407494068,
-0.01977640762925148,
0.0190436989068985,
-0.008588830009102821,
-0.012487481348216534,
-0.019145306199789047,
0.0185654629021883,
0.00907247606664896,
-0.007366418372839689,
0.017129886895418167,
0.03343375027179718,
0.015289979986846447,
-0.013060810044407845,
0.013160349801182747,
0.0369185172021389,
0.015631752088665962,
0.03914683684706688,
0.06625992059707642,
0.001974540064111352,
0.04099391773343086,
-0.018342772498726845,
0.033433131873607635,
0.02826942503452301,
-0.03094027191400528,
0.01773316040635109,
-0.00031272400519810617,
-0.015734495595097542,
-0.01462545432150364,
0.003331491956487298,
0.022136930376291275,
-0.05393929034471512,
-0.01268080435693264,
-0.013663291931152344,
0.010870967991650105,
0.01120991725474596,
0.04192522168159485,
0.017527272924780846,
-0.0005494435899890959,
0.015611193142831326,
0.029773401096463203,
-0.014157268218696117,
-0.04335172101855278,
0.06783691793680191,
0.00619543856009841,
0.041170693933963776,
-0.007894947193562984,
-0.015286171808838844,
-0.018814431503415108,
0.03861807659268379,
0.035515859723091125,
-0.0048756226897239685,
-0.009394490160048008,
0.003749971045181155,
0.02808384783565998,
-0.031975068151950836,
-0.014641196466982365,
-0.021185681223869324,
-0.030412284657359123,
-0.03680649772286415,
0.08047019690275192,
-0.009769323281943798,
-0.019628064706921577,
-0.013848516158759594,
-0.029875455424189568,
-0.01649775728583336,
-0.01274072751402855,
-0.0014032988110557199,
0.03630673512816429,
0.0032589612528681755,
-0.03987886384129524,
0.08318787813186646,
-0.07785664498806,
-0.004185485653579235,
-0.020350398495793343,
0.002185828983783722,
0.0049537429586052895,
0.012559661641716957,
0.016122108325362206,
0.01724235527217388,
0.04114390164613724,
-0.08619850873947144,
0.00897593516856432,
0.02133895829319954,
0.05668949335813522,
-0.00978293176740408,
-0.03321239352226257,
-0.01468687318265438,
0.03692731633782387,
0.018319809809327126,
-0.01445542648434639,
0.019606929272413254,
0.014680532738566399,
-0.009685252793133259,
0.02610417827963829,
0.016286196187138557,
0.04866985231637955,
-0.03935091570019722,
-0.0028275162912905216,
-0.036298636347055435,
0.023345859721302986,
-0.0253905039280653,
0.01131373830139637,
0.0197269506752491,
0.04968757927417755,
0.010242972522974014,
-0.016083642840385437,
-0.02836502343416214,
-0.02442067675292492,
-0.005352532956749201,
0.021710436791181564,
-0.0013880946207791567,
-0.023594466969370842,
-0.020813142880797386,
0.022827597334980965,
-0.018839173018932343,
0.004301913548260927,
-0.009013158269226551,
-0.00710715539753437,
-0.010738740675151348,
-0.01467465702444315,
0.03629064932465553,
-0.019244110211730003,
0.018116218969225883,
-0.03404936194419861,
-0.02016715332865715,
0.009673011489212513,
0.011275849305093288,
-0.005097792483866215,
0.047559838742017746,
0.019392600283026695,
0.01579194888472557,
0.015827417373657227,
-0.003875873051583767,
0.01764686219394207,
0.01198580488562584,
0.0071291313506662846,
0.017177049070596695,
0.05427210032939911,
-0.013162167742848396,
0.036080874502658844,
0.0030961474403738976,
0.020899292081594467,
-0.003549200715497136,
0.021240709349513054,
-0.04292955994606018,
0.019227076321840286,
-0.011836078017950058,
0.013907522894442081,
0.044137436896562576,
-0.020183196291327477,
0.013418350368738174,
-0.004992167931050062,
0.03368354216217995,
-0.014846825040876865,
0.0038623325526714325,
0.025220930576324463,
0.012985284440219402,
-0.06412796676158905,
-0.015267853625118732,
0.008373280055820942,
-0.05782941356301308,
0.04320315271615982,
-0.01682153157889843,
0.01370365358889103,
-0.021864445880055428,
-0.05240781232714653,
0.018001217395067215,
0.040151551365852356,
-0.03895031660795212,
0.035711146891117096,
0.03118877485394478,
0.052828311920166016,
0.00022767843620385975,
-0.01445809192955494,
0.03081311099231243,
0.009914049878716469,
0.03253753110766411,
0.04432501271367073,
0.012028084136545658,
0.008510971441864967,
0.0001214971489389427,
-0.03947412222623825,
0.02213439904153347,
0.027189701795578003,
-0.004425982479006052,
-0.014769986271858215,
0.030786411836743355,
0.023915620520710945,
-0.04993787035346031,
-0.035126373171806335,
-0.04473520442843437,
-0.0431399941444397,
0.037830960005521774,
0.008562647737562656,
0.003166584763675928,
-0.018800491467118263,
-0.0017458326183259487,
-0.0168398879468441,
-0.003178507089614868,
0.026347756385803223,
-0.015674712136387825,
-0.02732378989458084,
-0.012193403206765652,
0.010090000927448273,
0.015163007192313671,
0.017107320949435234,
0.02885916829109192,
-0.011371989734470844,
-0.0061111790128052235,
0.009216696955263615,
0.012226876802742481,
0.04150962457060814,
-0.006715503521263599,
-0.0024007803294807673,
-0.004137811716645956,
-0.01724548079073429,
-0.008022830821573734,
-0.0360536128282547,
0.027404434978961945,
-0.016731299459934235,
0.02004336565732956,
0.009768516756594181,
-0.019599618390202522,
0.0088939955458045,
-0.07567478716373444,
0.03967727720737457,
0.024523627012968063,
0.012111502699553967,
0.02676953189074993,
-0.015456750057637691,
-0.021572692319750786,
-0.03780374303460121,
0.027783092111349106,
-0.012276056222617626,
-0.03793010115623474,
0.0017572473734617233,
0.0012772264890372753,
-0.001056060427799821,
-0.04169156402349472,
0.010482742451131344,
0.005355069413781166,
0.036292050033807755,
0.01320553943514824,
0.005952778272330761,
-0.012521760538220406,
0.013189766556024551,
0.019235488027334213,
0.03876801207661629,
-0.02361229993402958,
0.018560724332928658,
-0.019922420382499695,
0.010464871302247047,
-0.015554258599877357,
0.03218453377485275,
-0.04836590960621834,
0.0043540471233427525,
0.023992063477635384,
-0.03405587747693062,
0.0012043551541864872,
0.03551271930336952,
0.006403635255992413,
0.02784554660320282,
-0.0389413982629776,
0.011246335692703724,
0.011074836365878582,
-0.015175347216427326,
-0.040168412029743195,
-0.022423723712563515,
-0.04008202999830246,
-0.004610630217939615,
-0.03587133809924126,
-0.013493605889379978,
0.009817135520279408,
0.011779028922319412,
-0.058888666331768036,
0.05282608047127724,
0.032676395028829575,
0.015445426106452942,
-0.004248916637152433,
0.015027029439806938,
0.05353425070643425,
-0.005848320666700602,
-0.036334242671728134,
0.0015936075942590833,
0.03975468873977661,
-0.020108474418520927,
-0.018172036856412888,
-0.014344187453389168,
-0.008156392723321915,
-0.02720930427312851,
0.04838778078556061,
0.01888418383896351,
-0.04523104056715965,
0.06676970422267914,
-0.05312935635447502,
0.03776256740093231,
-0.02672724984586239,
-0.017248986288905144,
0.017091818153858185,
-0.009893728420138359,
-0.03377165645360947,
0.00721695413812995,
-0.00717363553121686,
-0.008507193066179752,
-0.005141311790794134,
-0.013910465873777866,
-0.006554482039064169,
0.02752687595784664,
0.024566777050495148,
-0.03557690232992172,
-0.006410674657672644,
-0.010040080174803734,
0.08310369402170181,
-0.03290495276451111,
-0.14508381485939026,
-0.040379565209150314,
0.016423732042312622,
-0.031254030764102936,
-0.016653642058372498,
-0.0680726021528244,
0.011520120315253735,
-0.0064817797392606735,
0.07855632156133652,
0.02351340465247631,
0.01630536839365959,
0.0591011717915535,
0.011809179559350014,
-0.018893444910645485,
-0.0020844517275691032,
-0.0003406017494853586,
0.018913671374320984,
-0.05131503939628601,
0.04000934213399887,
-0.0611271969974041,
0.02109621837735176,
0.019415460526943207,
-0.0019388278014957905,
-0.024576300755143166,
-0.00262024556286633,
0.03586070239543915,
0.021159479394555092,
0.008830293081700802,
-0.00817448366433382,
-0.0019422133918851614,
-0.06005876138806343,
-0.006617127452045679,
0.030610239133238792,
0.03356410190463066,
0.03488782048225403,
-0.0863175019621849,
-0.004441828466951847,
0.03443635627627373,
-0.006682340055704117,
-0.011922517791390419,
0.019461607560515404,
-0.01965445838868618,
0.02076331526041031,
-0.006848275661468506,
-0.03076125681400299,
-0.0408862829208374,
-0.024593500420451164,
0.03803969547152519,
0.0025679601822048426,
0.015397882089018822,
-0.05164426937699318,
0.03979615494608879,
-0.01992947980761528,
-0.013940762728452682,
-0.011146333068609238,
-0.0029930747114121914,
0.026282742619514465,
-0.0033380803652107716,
-0.0009214159217663109,
-0.008993062190711498,
0.03467893972992897,
0.03424052521586418,
-0.017599783837795258,
0.009181837551295757,
0.027141718193888664,
-0.031220192089676857,
-0.00021920038852840662,
-0.012365850619971752,
-0.04104115441441536,
-0.061985671520233154,
-0.05260627344250679,
-0.010594947263598442,
0.04643639922142029,
0.02954617328941822,
-0.04221748933196068,
0.009190346114337444,
-0.02839355543255806,
0.00378102227114141,
-0.010451174341142178,
-0.021525615826249123,
-0.05166551470756531,
0.014046142809092999,
-0.020002588629722595,
0.020662924274802208,
-0.0029994642827659845,
-0.013417525216937065,
-0.02054390124976635,
-0.028091052547097206,
-0.04337102919816971,
-0.003533740062266588,
-0.012503359466791153,
0.007543373852968216,
0.02465934306383133,
0.010077903047204018,
-0.002074694726616144,
0.029297910630702972,
0.027691887691617012,
-0.0020740460604429245,
-0.020642949268221855,
-0.014353180304169655,
-0.030928542837500572,
0.003242025151848793,
-0.05456743761897087,
0.023235026746988297,
-0.05541534349322319,
0.0060619474388659,
-0.007628883700817823,
-0.06212490051984787,
0.024174977093935013,
-0.007825985550880432,
0.007609362713992596,
-0.009798242710530758,
0.04005489498376846,
-0.0035626417957246304,
-0.007187891285866499,
0.02961757965385914,
0.0262617040425539
] |
8a3f2203d02e338bbadd1c557a7d415e6e39dbbc | 379 | py | Python | src/temp2.py | FabBrolMons/frbayart | c2b9dde730cf6d21f1c1492d0da0351c12a4dce9 | [
"MIT"
] | null | null | null | src/temp2.py | FabBrolMons/frbayart | c2b9dde730cf6d21f1c1492d0da0351c12a4dce9 | [
"MIT"
] | null | null | null | src/temp2.py | FabBrolMons/frbayart | c2b9dde730cf6d21f1c1492d0da0351c12a4dce9 | [
"MIT"
] | null | null | null | from w1thermsensor import W1ThermSensor
sensor = W1ThermSensor()
temperature_in_celsius = sensor.get_temperature()
temperature_in_fahrenheit = sensor.get_temperature(W1ThermSensor.DEGREES_F)
temperature_in_all_units = sensor.get_temperatures([W1ThermSensor.DEGREES_C, W1ThermSensor.DEGREES_F, W1ThermSensor.KELVIN])
print("Sensor id:" + sensor.id)
print(temperature_in_celsius)
| 42.111111 | 124 | 0.852243 | 1 | 0.7806 | [
0.0013549438444897532,
0.026400260627269745,
0.008481381461024284,
0.002480000490322709,
0.007334460970014334,
-0.004014730919152498,
-0.01425058115273714,
0.0014084955910220742,
-0.008997387252748013,
0.0005728876567445695,
0.004359276965260506,
0.0057437787763774395,
0.011319664306938648,
-0.014453363604843616,
-0.00022063679352868348,
0.016276929527521133,
-0.05471353977918625,
0.0012320985551923513,
-0.00316738523542881,
0.0027544505428522825,
-0.0072596692480146885,
0.01329294964671135,
0.009558213874697685,
0.005043171811848879,
0.005889111198484898,
-0.0007294247043319046,
0.009132943116128445,
0.0035790528636425734,
-0.009799045510590076,
-0.0032503718975931406,
0.002811236074194312,
-0.0028875565622001886,
-0.0064271921291947365,
-0.00804060883820057,
0.005129185039550066,
-0.003503486281260848,
0.0002400197699898854,
-0.022513944655656815,
0.01361836213618517,
-0.005270932335406542,
-0.010394909419119358,
-0.017161337658762932,
0.00044439639896154404,
0.006485592573881149,
-0.011427544988691807,
0.0004571684112306684,
-0.002655304968357086,
0.002237851731479168,
-0.010632704943418503,
0.002460299525409937,
-0.010520736686885357,
0.0013581556268036366,
0.012775752693414688,
0.0030949837528169155,
-0.008413253352046013,
-0.00945866946130991,
0.011721664108335972,
-0.0017444106051698327,
-0.013012720271945,
-0.000836457998957485,
-0.003406347706913948,
-0.0019551755394786596,
0.002121979370713234,
0.004594134166836739,
-0.018815796822309494,
-0.005867249332368374,
-0.0060795885510742664,
0.002496277680620551,
-0.005306609440594912,
0.004922127816826105,
0.0020151943899691105,
-0.0015927919885143638,
0.008290319703519344,
0.0015145416837185621,
0.0020613926462829113,
-0.003751988522708416,
-0.00173765083309263,
0.0027767519932240248,
0.008888215757906437,
0.0015682829543948174,
0.006436723750084639,
-0.011977544985711575,
0.0053328522481024265,
0.011531674303114414,
0.011639392003417015,
0.009422419592738152,
0.01905745454132557,
-0.01102463249117136,
0.04331173747777939,
0.006612361874431372,
-0.008957711979746819,
0.00033706839894875884,
-0.009057899937033653,
-0.005158109124749899,
-0.005165913607925177,
-0.03236115351319313,
-0.0011822235537692904,
-0.005360979121178389,
-0.0011359271593391895,
0.0021185893565416336,
0.0019240838009864092,
0.0071031455881893635,
-0.0012692292220890522,
-0.0018441654974594712,
-0.01269165612757206,
0.012887326069176197,
-0.010898695327341557,
-0.003974421881139278,
0.00540093332529068,
0.002890360541641712,
-0.015383781865239143,
-0.002086903899908066,
0.0017712642438709736,
-0.01599837653338909,
0.0031032918486744165,
0.002924413653090596,
-0.00730299623683095,
0.0588354617357254,
-0.004984341096132994,
0.0038407170213758945,
-0.003879263298586011,
-0.0036365094128996134,
0.0034944519866257906,
0.008434081450104713,
0.008608512580394745,
-0.004693706054240465,
0.011615940369665623,
0.009529984556138515,
0.004443468060344458,
0.006347058340907097,
-0.0018372765043750405,
0.007479081861674786,
-0.00349015393294394,
0.00028255890356376767,
0.0016836479771882296,
-0.007910525426268578,
0.006439384538680315,
-0.0034468751400709152,
-0.006250126287341118,
-0.00021224208467174321,
-0.0007742652087472379,
-0.013416863046586514,
0.0017834267346188426,
-0.0002096412645187229,
0.0020225318148732185,
-0.012459020130336285,
-0.002598949708044529,
-0.00040126609383150935,
-0.0006756865768693388,
0.0032968372106552124,
0.007956706918776035,
0.004064003936946392,
0.004575014114379883,
-0.005504556465893984,
-0.00943085364997387,
-0.0014039393281564116,
-0.0045113093219697475,
0.0026405761018395424,
0.007754850666970015,
0.004451789893209934,
-0.008793430402874947,
-0.002072575967758894,
0.005561657715588808,
0.005585974548012018,
-0.00015356705989688635,
0.003906853497028351,
-0.008260310627520084,
0.01088250894099474,
-0.0003394695231691003,
0.0018663282971829176,
0.012552116066217422,
-0.0015854533994570374,
0.0011765648378059268,
0.0010572535684332252,
0.005414087790995836,
0.0000016245916185653186,
0.004206715617328882,
0.010290277190506458,
-0.005361435003578663,
-0.003926453180611134,
0.006213188171386719,
0.0025292306672781706,
0.006797888781875372,
0.010579683817923069,
-0.0018258963245898485,
0.0010461894562467933,
-0.004933998454362154,
0.0003888854116667062,
0.0038128665182739496,
-0.00498163141310215,
0.01166878268122673,
0.005175731610506773,
-0.010832946747541428,
-0.006679488345980644,
-0.002559337764978409,
-0.011600503697991371,
0.001192141673527658,
0.01399269700050354,
0.009693163447082043,
-0.001148200943134725,
0.0021523123141378164,
-0.012491918168962002,
0.0015143133932724595,
0.0066520338878035545,
0.00198260135948658,
-0.013811072334647179,
-0.9545519948005676,
0.005283578298985958,
0.0023307877127081156,
0.001059133792296052,
0.004811737220734358,
0.0022847470827400684,
0.005054122768342495,
0.003120388835668564,
0.015739616006612778,
-0.007737905252724886,
-0.007097488269209862,
-0.008286502212285995,
-0.013844874687492847,
-0.0016526927938684821,
-0.008046737872064114,
-0.0020287390798330307,
-0.005421210080385208,
-0.008464379236102104,
-0.000056550394219812006,
-0.005228409077972174,
0.0001925150427268818,
0.006077575962990522,
0.0008063593413680792,
0.006703565828502178,
0.00657583586871624,
0.004437959752976894,
-0.006338409148156643,
-0.0007106995908543468,
0.0005632732063531876,
-0.0033246632665395737,
-0.002285885391756892,
-0.013106531463563442,
-0.005909597966820002,
-0.003871289547532797,
0.010273817926645279,
0.0012716694036498666,
0.010545413009822369,
-0.0010898439213633537,
0.002610032446682453,
-0.009004286490380764,
0.006133866496384144,
0.0050903549417853355,
0.0032458212226629257,
-0.030430974438786507,
0.0009003437589854002,
-0.00022809328220319003,
-0.007488510571420193,
0.005522292573004961,
0.002328739734366536,
-0.0018050021026283503,
-0.0040417383424937725,
-0.004147431347519159,
0.007498634047806263,
-0.008807585574686527,
0.005212475545704365,
-0.006222291849553585,
-0.006690023932605982,
-0.0017483920091763139,
-0.009822210296988487,
0.001322139403782785,
0.0038851096760481596,
-0.0018361345864832401,
-0.002233099890872836,
-0.004768329672515392,
0.003371099941432476,
0.0018060036236420274,
0.0005089587066322565,
-0.018758008256554604,
-0.004803735297173262,
-0.0018395297229290009,
0.002051475690677762,
-0.0012753657065331936,
-0.004428960382938385,
0.0029876811895519495,
-0.009039696305990219,
0.005187732633203268,
-0.0019070106791332364,
0.0023739347234368324,
-0.010483081452548504,
-0.0001535434857942164,
-0.008232451975345612,
-0.009462215937674046,
0.004159330856055021,
-0.004615550395101309,
-0.0027756337076425552,
-0.0002873146440833807,
0.0030631443951278925,
0.007325354497879744,
-0.0025992211885750294,
0.000007537381861766335,
0.011058391071856022,
-0.0033987087663263083,
-0.007831759750843048,
0.005257871001958847,
0.005129611119627953,
-0.00022390924277715385,
-0.0038259420543909073,
0.0034748141188174486,
0.009714694693684578,
0.008972764946520329,
0.000620137492660433,
0.0015078202122822404,
-0.00038438354386016726,
0.007745512295514345,
5.063673711447336e-7,
0.003250399138778448,
-0.0032975736539810896,
-0.003585671540349722,
-0.004041238222271204,
-0.003954142797738314,
-0.004818403627723455,
-0.0004837810411117971,
-0.012764242477715015,
-0.009166118688881397,
-0.005989617668092251,
0.0005462449626065791,
0.0029796313028782606,
-0.007566667161881924,
0.0025517058093100786,
-0.00017437158385291696,
0.010731618851423264,
0.0020241441670805216,
-0.003086748067289591,
0.0011013486655429006,
0.002633321564644575,
-0.005765410605818033,
0.015151715837419033,
-0.012546755373477936,
0.006305762100964785,
-0.001514795352704823,
-0.017858395352959633,
0.012343653477728367,
0.006723333615809679,
-0.006814942229539156,
0.00153066567145288,
0.004219504538923502,
0.002465543569996953,
-0.000145940255606547,
-0.0041601513512432575,
-0.003335477551445365,
-0.018138421699404716,
0.0008601293666288257,
0.023640520870685577,
0.0033605776261538267,
0.008492209948599339,
0.009534950368106365,
0.00011900882236659527,
0.002826858777552843,
0.00990088190883398,
-0.0005536081152968109,
0.01700691320002079,
-0.008313371799886227,
-0.0012882197042927146,
0.0029850383289158344,
-0.006218461319804192,
0.004130062181502581,
0.0016576822381466627,
0.0049267979338765144,
-0.002709061373025179,
0.0012132402043789625,
-0.00813231896609068,
-0.004110878333449364,
-0.01628430001437664,
-0.00015528804215136915,
0.007028322666883469,
-0.00460934778675437,
0.004460942931473255,
-0.014303302392363548,
0.0018570092506706715,
0.008142012171447277,
0.0010588454315438867,
0.000049951253458857536,
0.0038149007596075535,
0.007142836228013039,
0.013549965806305408,
-0.006792640313506126,
0.002555827610194683,
0.0022769183851778507,
-0.001312559237703681,
0.003655023640021682,
0.007916111499071121,
-0.009108864702284336,
-0.00564521923661232,
0.004299207590520382,
0.003618949558585882,
0.003914303611963987,
-0.00292595149949193,
-0.01203469093888998,
-0.004904526751488447,
0.0037624449469149113,
-0.006441796664148569,
0.002262935508042574,
0.001140484819188714,
0.0024814861826598644,
-0.009006544947624207,
-0.0005789579590782523,
-0.003254955168813467,
-0.008712505921721458,
0.009061654098331928,
-0.0032699787989258766,
0.003352057421579957,
0.011294499970972538,
0.008031295612454414,
-0.014009462669491768,
0.006412460468709469,
0.006842353846877813,
-0.004089719150215387,
0.003826345084235072,
0.005548801273107529,
-0.0033682677894830704,
-0.02250739000737667,
-0.0019639558158814907,
-0.013893078081309795,
0.005887525621801615,
-0.002525466261431575,
0.0014016827335581183,
-0.006988441571593285,
0.009037593379616737,
0.005960225127637386,
-0.010411594994366169,
-0.002526372205466032,
-0.012174713425338268,
0.009088276885449886,
-0.003299839561805129,
-0.0023379349149763584,
-0.004281593486666679,
-0.004467224236577749,
-0.0033725672401487827,
-0.0034665041603147984,
-0.0006851825164631009,
0.0049741254188120365,
0.002479261253029108,
-0.0036024535074830055,
0.0038488488644361496,
-0.002798774279654026,
0.00012124838394811377,
0.0008955431985668838,
-0.012536615133285522,
0.00003408907650737092,
0.00640139589086175,
-0.0005492579657584429,
-0.0040998742915689945,
0.0035775210708379745,
-0.0037353101652115583,
-0.007410899735987186,
-0.010505953803658485,
-0.0020402311347424984,
-0.0028389899525791407,
-0.0038817813619971275,
-0.011393211781978607,
-0.004526556935161352,
-0.010032253339886665,
0.011263422667980194,
-0.006654499564319849,
0.0097286282107234,
0.0038571259938180447,
-0.004309102892875671,
0.006301274523139,
-0.0023052471224218607,
0.005032150074839592,
0.00017539896361995488,
0.006879943422973156,
0.00001736373633320909,
-0.006268341559916735,
-0.011341222561895847,
0.011800071224570274,
-0.008247539401054382,
0.0009520500898361206,
0.013913596048951149,
0.004292021971195936,
0.008349258452653885,
-0.000016917880202527158,
-0.0012816579546779394,
0.006543423514813185,
0.009568879380822182,
-0.013254205696284771,
0.0025690444745123386,
-0.0040259817615151405,
-0.001420043408870697,
0.005045353900641203,
-0.004948656540364027,
0.00021240755449980497,
0.009392641484737396,
0.005162583198398352,
-0.008720223791897297,
-0.000011056723451474681,
0.0015677276533097029,
0.004811451304703951,
-0.014594225212931633,
-0.0007927807746455073,
-0.0027179759927093983,
-0.0035333847627043724,
-0.005284184589982033,
-0.002890082774683833,
0.0015908338828012347,
0.006836840882897377,
-0.0014760035555809736,
0.006627104245126247,
-0.0021238240879029036,
-0.004547689110040665,
0.016989270225167274,
-0.0034667043946683407,
-0.005982088390737772,
0.005269140470772982,
0.0028275568038225174,
0.00003158902472932823,
-0.007251121569424868,
-0.0029706608038395643,
-0.00027156720170751214,
0.004246873781085014,
-0.003126207273453474,
-0.006850072648376226,
-0.0019236559746786952,
-0.00041634394438005984,
-0.009620945900678635,
0.0017203077441081405,
0.012303854338824749,
-0.0012613689759746194,
0.007258569356054068,
0.00044968695146963,
-0.006030728109180927,
-0.015379752032458782,
0.05422065407037735,
-0.0020030320156365633,
0.001517744967713952,
0.004286785144358873,
-0.0066347261890769005,
-0.00040319611434824765,
-0.003890808206051588,
0.006975620985031128,
-0.007585032377392054,
-0.00628818990662694,
0.010693731717765331,
-0.0057991002686321735,
0.005685534328222275,
0.00017156192916445434,
-0.0016424712957814336,
0.01772483065724373,
-0.0037441200111061335,
-0.017604079097509384,
-0.015184604562819004,
0.006992491427809,
-0.00808035023510456,
-0.004831591621041298,
0.005686510354280472,
-0.0031338713597506285,
-0.002109667519107461,
0.0011614598333835602,
0.0059884958900511265,
-0.0009165126830339432,
0.0007325188489630818,
-0.0020285279024392366,
-0.002027772134169936,
-0.000328110036207363,
0.002704846439883113,
0.006019366439431906,
0.01267226506024599,
0.0008834644104354084,
0.003343589836731553,
-0.0016303319716826081,
0.00033792981412261724,
-0.005357474088668823,
0.005857229232788086,
0.007364968303591013,
-0.003155497368425131,
-0.004793122410774231,
0.005715459585189819,
0.006203854456543922,
-0.0020602289587259293,
0.012690835632383823,
0.0023734411224722862,
-0.002925427397713065,
0.007977843284606934,
0.009670230560004711,
-0.0025203682016581297,
0.009113583713769913,
-0.0009258220670744777,
0.0029963008128106594,
0.004349254071712494,
-0.006861040368676186,
-0.010356917046010494,
-0.001031361403875053,
0.005084789823740721,
0.006867314223200083,
0.0000366350359399803,
0.001975276507437229,
-0.0006289210286922753,
-0.0030374922789633274,
-0.008541577495634556,
-0.008104715496301651,
-0.002671301132068038,
-0.0007135756313800812,
0.004919025581330061,
0.07197057455778122,
-0.006717620883136988,
-0.0022230735048651695,
-0.008246375247836113,
0.003948091994971037,
-0.001466709072701633,
-0.00016923951625358313,
-0.0038756541907787323,
-0.0028271523769944906,
0.0034527184907346964,
0.0036976682022213936,
-0.01053330022841692,
-0.012480047531425953,
0.001531214453279972,
0.0018040745053440332,
-0.0024132542312145233,
0.003958637360483408,
0.0071272943168878555,
-0.010448462329804897,
0.0019301441498100758,
-0.013897106051445007,
-0.00017025726265273988,
-0.0012808706378564239,
-0.008304259739816189,
-0.006100836675614119,
-0.007500884588807821,
0.002629844704642892,
0.004423579666763544,
0.006683174520730972,
-0.00420933123677969,
0.006059075240045786,
-0.0031579569913446903,
0.0023599942214787006,
-0.004582102410495281,
-0.001336161745712161,
-0.004769148305058479,
0.008463657461106777,
0.0014455184573307633,
-0.014282152988016605,
-0.007344817277044058,
-0.0029453206807374954,
-0.0007032310822978616,
-0.005857375450432301,
0.005426834337413311,
-0.004021610599011183,
0.007480796426534653,
-0.004992991220206022,
0.0034316175151616335,
-0.005742890760302544,
-0.0011458451626822352,
-0.014235459268093109,
0.007621786091476679,
-0.1816355139017105,
0.012255114503204823,
0.002801763592287898,
-0.005526887718588114,
-0.0031455671414732933,
-0.015522335655987263,
-0.010551278479397297,
0.0023171277716755867,
0.012309536337852478,
0.0003606344689615071,
-0.0003376090317033231,
-0.001538543845526874,
0.004780258052051067,
0.0031275846995413303,
-0.0025938129983842373,
-0.0019258150132372975,
0.0041612284258008,
-0.0038816712331026793,
-0.001501237042248249,
0.0023381123319268227,
0.0038292391691356897,
0.007074558176100254,
0.0024047852493822575,
0.0004260360146872699,
0.0007028059335425496,
-0.0021677983459085226,
0.003911206498742104,
-0.0009704219992272556,
0.0057555390521883965,
-0.012848855927586555,
-0.0058943419717252254,
-0.006524418946355581,
-0.0037432690151035786,
0.0013505998067557812,
0.0026398422196507454,
-0.0011975729139521718,
0.009964385069906712,
0.00045504377339966595,
-0.009371011517941952,
0.008301746100187302,
-0.0034024252090603113,
0.029949160292744637,
0.0043646651320159435,
0.00876891054213047,
0.002156037837266922,
-0.003906905185431242,
-0.004635225515812635,
0.010383951477706432,
0.0031159115023911,
0.01246627140790224,
-0.012580586597323418,
-0.002069251611828804,
0.002496493747457862,
0.018941981717944145,
-0.0072126868180930614,
-0.0075774057768285275,
-0.00814890582114458,
-0.003249287838116288,
0.005623277742415667,
0.012483037076890469,
0.01194800902158022,
-0.004712359048426151,
0.009039243683218956,
-0.003857881762087345,
-0.01953163743019104,
0.0036227204836905003,
-0.003297388320788741,
-0.004763020668178797,
-0.0007467356626875699,
0.00802618358284235,
0.008762220852077007,
-0.0033615902066230774,
0.0046950411051511765,
-0.0008602257585152984,
0.003055178327485919,
-0.0003381315909791738,
0.006202891934663057,
-0.0045980531722307205,
0.007959987968206406,
-0.006701495032757521,
0.01226051151752472,
-0.008623236790299416,
-0.0015123557532206178,
0.002516015199944377,
-0.0017579338746145368,
0.012375731952488422,
0.006784368772059679,
-0.0034444148186594248,
-0.0019196973880752921,
-0.011041563004255295,
-0.000568845309317112,
0.0038232305087149143,
0.006393380928784609,
-0.008642535656690598,
0.0015146072255447507,
-7.688272489758674e-7,
0.004439215641468763,
0.00645801005885005,
-0.00871194340288639,
0.0064658839255571365,
0.008086795918643475,
-0.008693316951394081,
0.0013283251319080591,
-0.007206018548458815,
0.0036270839627832174,
0.0023674832191318274,
-0.008021327666938305,
-0.009552122093737125,
0.006063406355679035,
-0.006271156948059797,
-0.005622943863272667,
0.008716623298823833,
-0.012711137533187866,
-0.004758581984788179,
-0.0037587787955999374,
-0.013660211116075516,
0.0004919607890769839
] |
8a3ff7ca606f5ce67c32533b5892e230c75d4eb8 | 413 | py | Python | tables/migrations/0004_auto_20200901_2004.py | jarnoln/exposures | bbae3f79078048d25b77e178db6c0801ffe9f97e | [
"MIT"
] | null | null | null | tables/migrations/0004_auto_20200901_2004.py | jarnoln/exposures | bbae3f79078048d25b77e178db6c0801ffe9f97e | [
"MIT"
] | null | null | null | tables/migrations/0004_auto_20200901_2004.py | jarnoln/exposures | bbae3f79078048d25b77e178db6c0801ffe9f97e | [
"MIT"
] | null | null | null | # Generated by Django 3.1.1 on 2020-09-01 17:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tables', '0003_exposure_category'),
]
operations = [
migrations.AlterField(
model_name='exposure',
name='location',
field=models.CharField(blank=True, default='', max_length=200),
),
]
| 21.736842 | 75 | 0.605327 | 1 | 0.7611 | [
0.002438764087855816,
0.02176401950418949,
0.006805246230214834,
0.004341075196862221,
0.004070241004228592,
-0.004597757942974567,
-0.009086649864912033,
0.004026162438094616,
-0.008120676502585411,
0.005577255971729755,
0.004201265051960945,
0.006943545304238796,
0.00532815046608448,
-0.019139256328344345,
-0.00013571999443229288,
0.020711971446871758,
-0.05576191842556,
0.005793961696326733,
-0.0026622775476425886,
0.0014729708200320601,
-0.0069360267370939255,
0.008249755017459393,
0.008805741555988789,
0.006113398354500532,
0.00530623085796833,
-0.003177990671247244,
0.008411269634962082,
0.00045447953743860126,
-0.004633722826838493,
-0.001729238429106772,
-0.0025157281197607517,
-0.0026153952348977327,
-0.006213312037289143,
-0.00819446612149477,
0.00652550533413887,
-0.0036260727792978287,
-0.0006703762337565422,
-0.019920244812965393,
0.009969370439648628,
-0.0032729392405599356,
-0.008312069810926914,
-0.019225869327783585,
-0.001980970613658428,
0.0025515402667224407,
-0.01108297798782587,
0.0018060168949887156,
-0.004952054005116224,
0.006568606942892075,
-0.013939530588686466,
0.00717637175694108,
-0.009900885634124279,
0.003982907626777887,
0.01307591050863266,
0.004083867650479078,
-0.007035421673208475,
-0.00900246761739254,
0.012958637438714504,
0.0036820140667259693,
-0.010926404036581516,
0.0003569893888197839,
-0.0037596141919493675,
-0.0015121449250727892,
0.005975990556180477,
0.0017427963903173804,
-0.017569411545991898,
-0.004456664435565472,
-0.0031092865392565727,
0.0007564336410723627,
-0.00004944115789839998,
0.0056234970688819885,
0.0019201928516849875,
-0.004539987538009882,
0.006697638891637325,
0.005946736317127943,
0.004181395750492811,
-0.0028002450708299875,
-0.0020870829466730356,
0.0017714474815875292,
0.007926910184323788,
0.002581999870017171,
0.003118978114798665,
-0.007785086520016193,
0.0074591501615941525,
0.008491825312376022,
0.01501916628330946,
0.009077725000679493,
0.020584236830472946,
-0.011742007918655872,
0.040901146829128265,
0.003276276867836714,
-0.011821835301816463,
0.003330957144498825,
-0.006382363848388195,
-0.001252609770745039,
-0.003534351708367467,
-0.02994661219418049,
0.0019323360174894333,
-0.002628463553264737,
-0.002564704744145274,
0.0018150401301681995,
-0.002395183313637972,
0.0060844807885587215,
-0.0027673873119056225,
-0.0014300730545073748,
-0.010507899336516857,
0.0160348042845726,
-0.010810469277203083,
-0.003073539584875107,
0.004911087919026613,
0.0024816878139972687,
-0.010499279014766216,
0.002072864444926381,
-0.0004627396119758487,
-0.015848008915781975,
0.0011568455956876278,
0.0029184992890805006,
-0.004426768980920315,
0.04982365667819977,
-0.00027714346651919186,
0.00559711828827858,
-0.005579897668212652,
0.00268214731477201,
-0.000950666842982173,
0.00423090485855937,
0.007559037301689386,
-0.005600889679044485,
0.009508488699793816,
0.006328861229121685,
0.00283274007961154,
0.005984343588352203,
-0.00472415704280138,
0.008071266114711761,
-0.006422081030905247,
-0.0036053466610610485,
0.0007406905060634017,
-0.007617223542183638,
0.005163820926100016,
-0.0014564725570380688,
-0.003509113099426031,
0.0000728495724615641,
-0.0034956573508679867,
-0.00985448993742466,
0.00007772613753331825,
-0.002605588873848319,
0.0059601180255413055,
-0.011891660280525684,
-0.005243300460278988,
-0.0006155541050247848,
-0.004893972538411617,
0.0035751040559262037,
0.009661072865128517,
0.0031574435997754335,
0.004449740517884493,
-0.006158011499792337,
-0.005958808586001396,
0.0013859199825674295,
-0.0020006655249744654,
0.000009337226401839871,
0.004628800321370363,
0.0032902543898671865,
-0.009897167794406414,
0.0011684757191687822,
0.0026915804482996464,
0.008975561708211899,
-0.00400955555960536,
0.0035315777640789747,
-0.008804496377706528,
0.009398854337632656,
0.0016821569297462702,
0.0024270564317703247,
0.009491444565355778,
-0.007284432649612427,
-0.0022806881461292505,
0.0005250275135040283,
0.006297338753938675,
0.0012900251895189285,
0.003457319689914584,
0.009981904178857803,
-0.002827720483765006,
-0.006861329544335604,
0.002958131255581975,
0.005401771515607834,
0.007889553904533386,
0.007998085580766201,
-0.003203269559890032,
0.003634935710579157,
-0.0055666170082986355,
-0.00028085688245482743,
0.0073144217021763325,
-0.0026709812227636576,
0.006127425003796816,
0.001044193166308105,
-0.015509744174778461,
-0.003813249757513404,
0.002128964988514781,
-0.008688931353390217,
0.001965784700587392,
0.01552828773856163,
0.013118218630552292,
-0.0013397714355960488,
0.005995134357362986,
-0.006852325052022934,
0.002517790999263525,
0.0067192860879004,
0.0005421886453405023,
-0.01107809692621231,
-0.9566808938980103,
0.0057451254688203335,
0.001962704584002495,
0.00010937192564597353,
0.002569360425695777,
0.008471939712762833,
0.0007971745799295604,
0.0035958383232355118,
0.013826827518641949,
-0.006435996852815151,
-0.0037270761094987392,
-0.010286109521985054,
-0.010971032083034515,
0.0021478203125298023,
-0.007127504795789719,
-0.0033881429117172956,
-0.005716899409890175,
-0.006269300356507301,
-0.0009123128256760538,
-0.007559448014944792,
-0.003127636853605509,
0.005858078133314848,
-0.0009133554412983358,
0.007238345220685005,
0.003558641765266657,
0.0058960942551493645,
-0.000939069373998791,
0.0012137785088270903,
-0.0003324740391690284,
0.002984287915751338,
-0.009120369330048561,
-0.015240475535392761,
-0.005104118026793003,
-0.0009912801906466484,
0.008586102165281773,
0.0035193259827792645,
0.0054219732992351055,
-0.0009040358127094805,
0.001242775353603065,
-0.008651216514408588,
0.003309820545837283,
-0.00047310881200246513,
0.0040646884590387344,
-0.02792135626077652,
0.004203197080641985,
-0.0005199491861276329,
-0.007242862600833178,
0.0066684833727777,
0.0010275326203554869,
0.00003510539681883529,
-0.0047396887093782425,
-0.0028344967868179083,
0.009238981641829014,
-0.007857844233512878,
0.00453378539532423,
-0.005933261476457119,
-0.009429818950593472,
-0.00163734401576221,
-0.008725887164473534,
0.0012472986709326506,
0.005640142131596804,
-0.004898719489574432,
-0.002515195170417428,
-0.0031706555746495724,
0.0006321645341813564,
0.001496766461059451,
0.0040545957162976265,
-0.019109997898340225,
-0.009793472476303577,
-0.0005145983886905015,
0.0019063676008954644,
-0.006711329333484173,
-0.005223762709647417,
0.0030731474980711937,
-0.010658914223313332,
0.007228247821331024,
0.0028138686902821064,
0.0007380477036349475,
-0.010181775316596031,
0.004067995119839907,
-0.008937240578234196,
-0.007656433619558811,
0.002689649350941181,
-0.007142407353967428,
-0.005510104354470968,
-0.0003005775506608188,
0.0023920380044728518,
0.00827259011566639,
-0.003394492669031024,
0.005742629989981651,
0.008790967985987663,
-0.0016007381491363049,
-0.008941476233303547,
0.0076804254204034805,
0.008531160652637482,
-0.00012228100968059152,
-0.0026254705153405666,
-0.0004909753915853798,
0.00866580381989479,
0.006099853198975325,
0.003934245556592941,
0.005235154647380114,
0.0013094869209453464,
0.012086715549230576,
-0.001190554816275835,
0.0000506889664393384,
-0.0029809381812810898,
-0.003470338648185134,
-0.003630386432632804,
0.0012372053461149335,
-0.0036342600360512733,
-0.003887742757797241,
-0.012500585988163948,
-0.008134132251143456,
-0.004503821022808552,
0.0011577056720852852,
-0.0005846232525072992,
-0.0009373631328344345,
0.0023935402277857065,
0.004009256139397621,
0.00921767856925726,
-0.001805802108719945,
-0.0032946125138550997,
-0.00011432225437602028,
0.0018150659743696451,
-0.004503391683101654,
0.016293754801154137,
-0.012533538043498993,
0.003700924338772893,
0.0010602545225992799,
-0.014813647605478764,
0.005816509947180748,
0.013242943212389946,
-0.010149303823709488,
0.004663797561079264,
0.002979404991492629,
0.0015420537674799562,
-0.0018071105005219579,
-0.0053007700480520725,
-0.0024925037287175655,
-0.015069730579853058,
-0.00116769562009722,
0.02013390138745308,
0.0016225388972088695,
0.011005806736648083,
0.013041561469435692,
-0.005726420320570469,
0.001989904325455427,
0.005197435151785612,
-0.0012770370813086629,
0.01335762906819582,
-0.00897202454507351,
-0.0029816715978085995,
0.0027752788737416267,
-0.00500076450407505,
-0.001373829203657806,
0.005475559271872044,
0.00494502205401659,
-0.002217385685071349,
0.0020465049892663956,
-0.005056525580585003,
-0.004360651597380638,
-0.019221007823944092,
0.002666028216481209,
0.011740623973309994,
-0.0037297799717634916,
0.004045072477310896,
-0.012772221118211746,
0.008407115004956722,
0.001467019086703658,
0.0008844468975439668,
0.0013274350203573704,
-0.002934847492724657,
0.00783231109380722,
0.012787507846951485,
-0.006281435955315828,
0.0023669784422963858,
0.002596666570752859,
-0.0005730798002332449,
-0.0003600217751227319,
0.008861055597662926,
-0.008568555116653442,
-0.0033191044349223375,
0.0006451410008594394,
0.002527551958337426,
0.001106120296753943,
-0.0017564805457368493,
-0.009388481266796589,
-0.00038009576383046806,
0.003127435687929392,
-0.0035124938003718853,
0.005158748012036085,
0.004668138921260834,
0.0032273917458951473,
-0.0032142610289156437,
0.0028157448396086693,
-0.00430755689740181,
-0.011145509779453278,
0.013466433621942997,
-0.0021929957438260317,
0.0025782743468880653,
0.011769775301218033,
0.0032490980811417103,
-0.012162597849965096,
0.007349322084337473,
0.006356425583362579,
-0.006463734898716211,
0.00483793905004859,
0.007848827168345451,
-0.00721959862858057,
-0.02573608234524727,
-0.0018940449226647615,
-0.013788740150630474,
0.005675484426319599,
-0.00038249199860729277,
0.006053049582988024,
-0.005517955403774977,
0.00784096959978342,
0.006852096877992153,
-0.013903824612498283,
-0.005594990681856871,
-0.00989573635160923,
0.009375871159136295,
-0.0024790510069578886,
-0.002453443594276905,
-0.004760070238262415,
-0.002604067325592041,
-0.004828467033803463,
0.0008740219636820257,
-0.002907975809648633,
0.004796053748577833,
0.0022774296812713146,
-0.008279555477201939,
-0.00014021832612343132,
-0.004105633124709129,
-0.0016030824044719338,
0.00546523742377758,
-0.010446950793266296,
0.003245987230911851,
0.00431595416739583,
-0.004673460498452187,
-0.0036020902916789055,
-0.001054226653650403,
0.0009329852764494717,
-0.009687482379376888,
-0.011195879429578781,
-0.0009073136607185006,
-0.003930103499442339,
-0.00390518456697464,
-0.009724287316203117,
0.0004714190145023167,
-0.008600915782153606,
0.002984865801408887,
-0.00814733561128378,
0.0045210858806967735,
0.005688033066689968,
-0.004753939341753721,
0.011566041968762875,
-0.00018666769028641284,
0.0036004178691655397,
0.004555366933345795,
0.006566890049725771,
-0.0030340347439050674,
-0.005887821316719055,
-0.00992556195706129,
0.008944623172283173,
-0.009632705710828304,
-0.0006067774957045913,
0.01426755078136921,
0.004008240066468716,
0.008362362161278725,
-0.0008399472571909428,
-0.0012480743462219834,
0.0035859132185578346,
0.005533443298190832,
-0.01659615896642208,
0.002848306903615594,
-0.00305716460570693,
0.00023150327615439892,
0.0052031585946679115,
-0.00551395071670413,
-0.0023292796686291695,
0.010101057589054108,
0.003087579971179366,
-0.0056523228995501995,
-0.0031819860450923443,
0.001628309371881187,
0.005430708639323711,
-0.010672125034034252,
-0.0012827088357880712,
-0.005633560474961996,
-0.0027361640240997076,
-0.002931014634668827,
-0.006534193642437458,
0.0012835718225687742,
0.0039600771851837635,
-0.0048529054038226604,
0.004633299075067043,
-0.0011199524160474539,
-0.005344863049685955,
0.012203723192214966,
-0.007863233797252178,
-0.006127471104264259,
0.0005008276784792542,
0.0012488245265558362,
-0.003960565198212862,
-0.009075288660824299,
-0.006567440927028656,
0.0022653983905911446,
0.003567019011825323,
-0.0010817572474479675,
-0.005817101337015629,
0.000040416412957711145,
0.0004270281351637095,
-0.010620919056236744,
0.005072759464383125,
0.010663856752216816,
0.0007935506873764098,
0.004088796675205231,
-0.0018496043048799038,
-0.009878402575850487,
-0.017903700470924377,
0.055982768535614014,
-0.0019169325241819024,
0.003929378464818001,
0.004613988101482391,
-0.00430591544136405,
-0.004727263003587723,
-0.0004212440107949078,
0.008018530905246735,
-0.00651428010314703,
-0.005739916115999222,
0.009932202287018299,
-0.005018339958041906,
0.002709613647311926,
-0.0008336415630765259,
-0.0001241715654032305,
0.013179733417928219,
-0.004612067248672247,
-0.01754927448928356,
-0.01421258132904768,
0.00907214730978012,
-0.0013642929261550307,
-0.007230609189718962,
0.009847602806985378,
-0.000564275891520083,
-0.003349951235577464,
0.0031691109761595726,
0.010673878714442253,
0.0008335650200024247,
-0.002284433925524354,
-0.004658790770918131,
-0.0005042650736868382,
0.0003982319904025644,
0.003592754015699029,
0.007249504793435335,
0.009656320326030254,
-0.0015058692079037428,
0.007095624227076769,
-0.006091139744967222,
-0.0006059596780687571,
-0.0011554277734830976,
0.00494694197550416,
0.005294309463351965,
-0.001959599554538727,
-0.001391163794323802,
0.0037335744127631187,
0.006489922758191824,
0.001301219454035163,
0.010274477303028107,
0.0011408257996663451,
-0.004997122101485729,
0.01066957600414753,
0.008095307275652885,
0.001398127293214202,
0.006981697399169207,
-0.003906410187482834,
0.005746662151068449,
0.004334875848144293,
-0.008280102163553238,
-0.013865060172975063,
-0.003229794092476368,
0.006767203565686941,
0.0028708302415907383,
-0.005212221294641495,
0.003919507842510939,
-0.0019953211303800344,
-0.004009534604847431,
-0.006182188168168068,
-0.0059691607020795345,
-0.007050840184092522,
0.0002680082689039409,
0.008713973686099052,
0.06991636008024216,
-0.009410926140844822,
-0.004176374990493059,
-0.008464466780424118,
0.0018293404718860984,
-0.000446322257630527,
-0.0002237515727756545,
0.0009189114207401872,
-0.0016673518111929297,
0.004672353621572256,
0.0007007309468463063,
-0.007169203832745552,
-0.009831979870796204,
0.0015898377168923616,
0.001756942248903215,
-0.002829157281666994,
0.0031701878178864717,
0.005927221849560738,
-0.010072840377688408,
0.0006163973594084382,
-0.011630410328507423,
-0.005030089523643255,
-0.0037883431650698185,
-0.008195971138775349,
-0.002705127000808716,
-0.005332505330443382,
-0.00005399510700954124,
0.003296695416793227,
0.008734466508030891,
-0.0047882674261927605,
0.007758714724332094,
-0.0005204406916163862,
0.0017548584146425128,
-0.0033127053175121546,
0.00044430900015868247,
-0.004623013082891703,
0.00822755228728056,
0.0018366569420322776,
-0.011491730809211731,
-0.0026094450149685144,
-0.0044476864859461784,
0.0005177863640710711,
-0.006124607287347317,
0.0048135509714484215,
-0.0013201636029407382,
0.008889198303222656,
-0.0016366655472666025,
0.002544064773246646,
-0.0025295279920101166,
0.0013815776910632849,
-0.012060846202075481,
0.007258267607539892,
-0.18118980526924133,
0.008707202970981598,
0.002846482442691922,
-0.00794125348329544,
-0.003221978200599551,
-0.014417869038879871,
-0.008189382962882519,
0.006108345929533243,
0.00960651133209467,
0.003097889944911003,
-0.0026428892742842436,
-0.0026317122392356396,
0.0021590914111584425,
0.0051407101564109325,
-0.0026180455461144447,
-0.006352894473820925,
0.003961853217333555,
-0.007878468371927738,
-0.00157461641356349,
0.003862751414999366,
0.003412958700209856,
0.011104491539299488,
-0.00012537882139440626,
0.000446852995082736,
-0.0005481619155034423,
-0.003172288415953517,
0.007090266793966293,
-0.004478066228330135,
0.0034522805362939835,
-0.010464677587151527,
-0.003933880943804979,
-0.005088133737444878,
-0.004596828017383814,
0.002060581697151065,
0.0030253715813159943,
0.0032935321796685457,
0.007255648262798786,
-0.0007103618117980659,
-0.008332612924277782,
0.00960830319672823,
-0.009236087091267109,
0.02412746287882328,
0.008651488460600376,
0.005976405460387468,
0.0022582816891372204,
-0.005731730721890926,
-0.003349236911162734,
0.008897176943719387,
0.0020179760176688433,
0.011859484948217869,
-0.013450966216623783,
-0.003995918203145266,
0.002702269935980439,
0.01806894689798355,
-0.006291945464909077,
-0.01088577788323164,
-0.008352046832442284,
-0.0062009114772081375,
0.0007720825960859656,
0.008300813846290112,
0.008485650643706322,
-0.0038855320308357477,
0.008349570445716381,
-0.003317302092909813,
-0.020840143784880638,
0.003100345842540264,
-0.0019872563425451517,
-0.009753425605595112,
0.005580169148743153,
0.005724798422306776,
0.008566190488636494,
-0.0014268012018874288,
0.0037241980899125338,
0.0021437720861285925,
0.007049686275422573,
-0.00039865990402176976,
0.009598099626600742,
0.0012225030222907662,
0.006686640437692404,
-0.007076638750731945,
0.00794972013682127,
-0.006178755313158035,
-0.0034179433714598417,
0.004244674928486347,
-0.000986770261079073,
0.009831774048507214,
0.00348831107839942,
-0.0018928545759990811,
-0.0004994663177058101,
-0.007027047220617533,
0.0006741397664882243,
0.0018021219875663519,
-0.00008478277595713735,
-0.005713110323995352,
0.0005454911151900887,
0.0005019162781536579,
0.0042465501464903355,
0.009705228731036186,
-0.006731605622917414,
0.009838809259235859,
0.005368707701563835,
-0.0049291448667645454,
-0.00009864837920758873,
-0.006747295614331961,
0.0054298462346196175,
0.002067343331873417,
-0.005027782171964645,
-0.0037286588922142982,
-0.0002852974575944245,
-0.0033956069964915514,
-0.005825669039040804,
0.007832937873899937,
-0.009414160624146461,
-0.010741508565843105,
-0.00035021849907934666,
-0.008557947352528572,
0.0018049237551167607
] |
8a406525f88287f3d13cd5aee631ef0cc809c7ec | 247 | py | Python | src/reportlab/graphics/charts/__init__.py | kokinomura/reportlab | 18e39b85d7277c2b5e9218b30a7b7b0a644a3c02 | [
"BSD-3-Clause"
] | 52 | 2016-09-30T05:53:45.000Z | 2021-12-26T12:07:48.000Z | src/reportlab/graphics/charts/__init__.py | kokinomura/reportlab | 18e39b85d7277c2b5e9218b30a7b7b0a644a3c02 | [
"BSD-3-Clause"
] | 31 | 2017-01-05T06:07:28.000Z | 2018-05-27T13:13:06.000Z | src/reportlab/graphics/charts/__init__.py | kokinomura/reportlab | 18e39b85d7277c2b5e9218b30a7b7b0a644a3c02 | [
"BSD-3-Clause"
] | 15 | 2016-11-03T08:50:15.000Z | 2022-01-14T07:04:35.000Z | #Copyright ReportLab Europe Ltd. 2000-2016
#see license.txt for license details
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/charts/__init__.py
__version__='3.3.0'
__doc__='''Business charts'''
| 41.166667 | 116 | 0.793522 | 1 | 0.7251 | [
0.0033026770688593388,
0.026837849989533424,
0.007060944568365812,
0.0006848627817817032,
0.004852897021919489,
-0.003920625429600477,
-0.009917095303535461,
0.0030922095756977797,
-0.007825253531336784,
0.0031247176229953766,
0.0019708776380866766,
0.003288824576884508,
0.006912602111697197,
-0.013990897685289383,
0.004723124206066132,
0.017624059692025185,
-0.056215088814496994,
0.0030322785023599863,
-0.005616301205009222,
-0.00019274441001471132,
-0.0076193553395569324,
0.011390428058803082,
0.00912464503198862,
0.00770694762468338,
0.004945091903209686,
0.0018082002643495798,
0.009189313277602196,
0.0028847979847341776,
-0.009830642491579056,
-0.005279237404465675,
-0.0011579745914787054,
-0.0016259774565696716,
-0.00440201535820961,
-0.0065276785753667355,
0.0063491626642644405,
-0.0009302145917899907,
-0.0009485296905040741,
-0.022647008299827576,
0.012408854439854622,
-0.00498426565900445,
-0.008550435304641724,
-0.017523620277643204,
0.0012204095255583525,
0.00570522528141737,
-0.010428182780742645,
0.0033901201095432043,
-0.0027032557409256697,
0.0058847712352871895,
-0.009421231225132942,
0.006012029945850372,
-0.010973566211760044,
0.0027403344865888357,
0.013224891386926174,
0.004260686691850424,
-0.005646473728120327,
-0.006012985482811928,
0.010313360020518303,
0.0021279589273035526,
-0.012298449873924255,
-0.000019940407582907937,
-0.0020894664339721203,
-0.005714634899049997,
0.0030383579432964325,
0.003591307206079364,
-0.01791471801698208,
-0.007494770456105471,
-0.003827521577477455,
0.0009588194661773741,
-0.002096017124131322,
0.004661757964640856,
0.003966465126723051,
0.00027845933800563216,
0.007988695055246353,
0.0006254094187170267,
0.003760986030101776,
-0.0027832542546093464,
-0.0010391034884378314,
0.0042824335396289825,
0.007546908222138882,
0.004540654364973307,
0.006553942337632179,
-0.008745851926505566,
0.006595055107027292,
0.01218633446842432,
0.01141921617090702,
0.00726570887491107,
0.01669873297214508,
-0.013467371463775635,
0.04137035459280014,
0.004540390335023403,
-0.01139036938548088,
0.003181213978677988,
-0.008653342723846436,
-0.0018519462319090962,
-0.00419401191174984,
-0.030209608376026154,
-0.0006463942700065672,
-0.005171257071197033,
0.001211546128615737,
0.0022910102270543575,
-0.0019262846326455474,
0.006939847953617573,
-0.0033740962389856577,
-0.002700598444789648,
-0.010949558578431606,
0.013415358029305935,
-0.009570665657520294,
-0.003157820552587509,
0.008147826418280602,
0.0018890122883021832,
-0.010452590882778168,
-0.002712201327085495,
0.00040426498162560165,
-0.013188186101615429,
0.004541833885014057,
0.001964238937944174,
-0.005167176481336355,
0.0581391416490078,
-0.003153732977807522,
0.0017733304994180799,
-0.005260030273348093,
0.0012232963927090168,
0.0013929978013038635,
0.008854750543832779,
0.011385160498321056,
-0.006401394493877888,
0.011776989325881004,
0.007423955947160721,
0.0007893352885730565,
0.008831695653498173,
0.00027922389563173056,
0.005511838477104902,
-0.005177757702767849,
-0.0027995435521006584,
0.00039755881880410016,
-0.008257506415247917,
0.010841033421456814,
-0.0030719484202563763,
-0.004909459035843611,
0.0032453297171741724,
-0.003984428942203522,
-0.013402107171714306,
0.0014916440704837441,
-0.00010869488323805854,
0.0014020053204149008,
-0.012076259590685368,
-0.0029523433186113834,
-0.0025341652799397707,
-0.004828177858144045,
0.003121025627478957,
0.008117327466607094,
0.003249594010412693,
0.0018942581955343485,
-0.008256921544671059,
-0.009456566534936428,
-0.001343741430900991,
-0.0061357771046459675,
0.0032012274023145437,
0.009529219940304756,
0.00200322805903852,
-0.007940319366753101,
-0.001007902785204351,
0.003959223162382841,
0.004210389219224453,
-0.003012061584740877,
-0.0002173061657231301,
-0.008307863026857376,
0.0101492740213871,
0.001930547528900206,
0.005566338077187538,
0.013292429968714714,
-0.003351665800437331,
-0.0020496174693107605,
0.0016498045297339559,
0.0021882951259613037,
0.0020997708197683096,
0.003945064265280962,
0.008975347504019737,
-0.0033079059794545174,
-0.004432985093444586,
0.003286039922386408,
0.005487850867211819,
0.008954036980867386,
0.009265342727303505,
-0.0023259934969246387,
0.002045707544311881,
-0.00612602336332202,
0.0005354472668841481,
0.004682969767600298,
-0.0036031471099704504,
0.008539890870451927,
0.0036792191676795483,
-0.013906831853091717,
-0.006214067339897156,
-0.0037668340373784304,
-0.010857938788831234,
-0.0007482234505005181,
0.016390424221754074,
0.010424058884382248,
-0.0010535260662436485,
0.004622306674718857,
-0.01319143082946539,
0.001048157922923565,
0.004315872676670551,
0.0006780407857149839,
-0.012411320582032204,
-0.9553771615028381,
0.001571889966726303,
0.002311133546754718,
0.000777986366301775,
0.0054671852849423885,
0.003451772965490818,
-0.0002629552036523819,
0.002290729433298111,
0.014083550311625004,
-0.00962445791810751,
-0.00685432692989707,
-0.01166841946542263,
-0.009312882088124752,
0.001269136555492878,
-0.009983192197978497,
-0.003089822828769684,
-0.0035579320974648,
-0.007235827390104532,
0.000704338017385453,
-0.006272874306887388,
-0.0027274382300674915,
0.009610768407583237,
-0.00018133316189050674,
0.005865879822522402,
0.005297725088894367,
0.00485246442258358,
-0.004438415635377169,
-0.0016380833694711328,
-0.0017800582572817802,
-0.0020223131868988276,
-0.004608610644936562,
-0.016377780586481094,
-0.007131565362215042,
-0.0003884141333401203,
0.01166565716266632,
0.0020864421967417,
0.007432402111589909,
-0.0006045154295861721,
0.0012892504455521703,
-0.009157892316579819,
0.004926625173538923,
0.0027537934947758913,
0.0031924815848469734,
-0.029939662665128708,
0.0027240044437348843,
-0.0006920654559507966,
-0.008775193244218826,
0.00922011211514473,
0.0013221638510003686,
-0.0006079593440517783,
-0.0028240932151675224,
-0.002808342454954982,
0.011641958728432655,
-0.006284289062023163,
0.004141731653362513,
-0.004647519439458847,
-0.005628983024507761,
-0.0011955797672271729,
-0.008063193410634995,
0.002552867867052555,
0.003914158791303635,
-0.0035143839195370674,
-0.003387000411748886,
-0.0056544020771980286,
0.004220267757773399,
0.0004527639248408377,
-0.0012449484784156084,
-0.01828143373131752,
-0.005030833184719086,
-0.003913660068064928,
0.0036371001042425632,
-0.0017957655945792794,
-0.0019001589389517903,
0.002789757214486599,
-0.010466300882399082,
0.00550595298409462,
0.0009025281760841608,
0.0017765051452443004,
-0.009752070531249046,
0.002013623481616378,
-0.008625773712992668,
-0.009311738424003124,
0.0030565187335014343,
-0.005315251648426056,
-0.0020807867404073477,
-0.00011196479317732155,
0.004010064527392387,
0.007505991496145725,
-0.006886782590299845,
0.00028505519730970263,
0.012139839120209217,
-0.004566463176161051,
-0.01091945543885231,
0.00686208950355649,
0.006855018902570009,
0.001431430340744555,
-0.0027007798198610544,
0.001321339514106512,
0.009897943586111069,
0.008985636755824089,
0.001353099592961371,
0.005026638507843018,
-0.0015061915619298816,
0.009680968709290028,
0.0013144022086635232,
0.0018934836843982339,
-0.0032725990749895573,
-0.0015117896255105734,
-0.0002802642702590674,
-0.0029541112016886473,
-0.002128118881955743,
0.0009567845263518393,
-0.011670947074890137,
-0.011260482482612133,
-0.003853654256090522,
0.004507823381572962,
-0.00030951574444770813,
-0.002744322642683983,
0.00164751464035362,
0.0028293957002460957,
0.00828620046377182,
0.001774067641235888,
-0.004685657564550638,
-0.00046709514572285116,
0.001123366761021316,
-0.008620529435575008,
0.016448987647891045,
-0.01184356864541769,
0.0062746573239564896,
0.0011853178730234504,
-0.017116278409957886,
0.009208458475768566,
0.007286394014954567,
-0.0067029716446995735,
0.0034517887979745865,
0.00007760573498671874,
0.002706061117351055,
0.00037789851194247603,
-0.004934261552989483,
-0.003455743659287691,
-0.016265317797660828,
-0.0004244156298227608,
0.021732693538069725,
0.0015858681872487068,
0.01042389776557684,
0.011552873067557812,
-0.0031806649640202522,
0.0021214403677731752,
0.00796080194413662,
0.001332415733486414,
0.013566331937909126,
-0.010836324654519558,
-0.00022383563918992877,
0.0025492876302450895,
-0.005291204433888197,
-0.0002900043036788702,
0.00617864029482007,
0.006482473574578762,
-0.0018758384976536036,
0.0009260182268917561,
-0.0062658460810780525,
-0.003740876680240035,
-0.019914535805583,
-0.0014080167748034,
0.0069837733171880245,
-0.003911386243999004,
0.0024480042047798634,
-0.01604573242366314,
0.005185045767575502,
0.005801851861178875,
0.00216544303111732,
-0.0006282221875153482,
0.00021391501650214195,
0.009037782438099384,
0.01208676677197218,
-0.005434184800833464,
0.0013390956446528435,
0.0006274992483668029,
-0.0013906181557103992,
0.0012402907013893127,
0.008607330732047558,
-0.008520063012838364,
-0.00497405743226409,
0.0025838306173682213,
0.0022998296190053225,
0.00009857983241090551,
-0.004565869458019733,
-0.009097983129322529,
-0.0040433090180158615,
0.004481316544115543,
-0.008995717391371727,
0.005482248030602932,
0.002452249638736248,
0.0029462429229170084,
-0.008500559255480766,
-0.0006208484410308301,
-0.005402556620538235,
-0.009122837334871292,
0.008603048510849476,
-0.001656882232055068,
0.0023785463999956846,
0.012914116494357586,
0.0027916282415390015,
-0.013382707722485065,
0.00624455651268363,
0.0070050437934696674,
-0.00552681740373373,
0.0019787470810115337,
0.008168105967342854,
-0.0035059195943176746,
-0.020930873230099678,
-0.0006390996277332306,
-0.016242332756519318,
0.0077462829649448395,
-0.0037977073807269335,
0.004969694186002016,
-0.008048022165894508,
0.008822275325655937,
0.008842350915074348,
-0.012726218439638615,
-0.003744252026081085,
-0.00830359198153019,
0.007070497609674931,
-0.00426500616595149,
-0.0012409514747560024,
-0.004309839103370905,
-0.0006323628476820886,
-0.004189361352473497,
-0.0015164948999881744,
0.0004432308196555823,
0.0027664839290082455,
0.0014392208540812135,
-0.004090619273483753,
0.0003550920228008181,
-0.0019255687948316336,
-0.00007790113886585459,
0.0031106192618608475,
-0.009244327433407307,
0.003482854925096035,
0.007482833229005337,
-0.0025818203575909138,
-0.0004327232309151441,
0.0009394047083333135,
-0.0016898919129744172,
-0.008978825062513351,
-0.008894887752830982,
-0.0036429166793823242,
-0.0025747709441930056,
-0.002553869504481554,
-0.011117062531411648,
-0.0007743443711660802,
-0.007964760065078735,
0.008699677884578705,
-0.008798099122941494,
0.00621480867266655,
0.004372075200080872,
-0.004939749836921692,
0.00570136122405529,
-0.003673914819955826,
0.003673168597742915,
0.006118351593613625,
0.007806449197232723,
0.0002875650825444609,
-0.006163562647998333,
-0.009475800208747387,
0.011628499254584312,
-0.009626543149352074,
0.0011466984869912267,
0.014282717369496822,
0.0059305052272975445,
0.011313755996525288,
0.0018287653801962733,
-0.0009560268954373896,
0.005360588431358337,
0.006992581766098738,
-0.013090308755636215,
0.0016142966924235225,
-0.0024262862280011177,
-0.0030109016224741936,
0.006516455672681332,
-0.005881716497242451,
0.0032791881822049618,
0.007707101758569479,
0.00021462555741891265,
-0.0071788146160542965,
-0.002366585424169898,
-0.001608378952369094,
0.0027179759927093983,
-0.011094491928815842,
0.0018286316189914942,
-0.004865685943514109,
-0.006010476034134626,
-0.001984665635973215,
0.0006306881550699472,
-0.0016802448080852628,
0.003801995189860463,
-0.0032356141600757837,
0.007508319802582264,
0.0015900848666206002,
-0.0034652771428227425,
0.01396621111780405,
-0.006781830918043852,
-0.005876828450709581,
0.0017010564915835857,
0.0026331886183470488,
-0.001481796964071691,
-0.007918279618024826,
-0.0027988904621452093,
0.0005017415387555957,
0.005721993278712034,
-0.00400617066770792,
-0.006309177726507187,
-0.0006417363183572888,
0.00167566305026412,
-0.007414848543703556,
0.0010595066705718637,
0.010363655164837837,
-0.0008710927795618773,
0.003971658181399107,
0.00016298965783789754,
-0.007685674354434013,
-0.015936050564050674,
0.056668248027563095,
-0.0002384904510108754,
0.0014791060239076614,
0.00569909205660224,
-0.005918273702263832,
0.0004297812411095947,
-0.0012933425605297089,
0.006437921896576881,
-0.008626407943665981,
-0.0054776715114712715,
0.011160635389387608,
-0.0024486915208399296,
0.002165435813367367,
-0.003047002013772726,
-0.001675536041148007,
0.014882893301546574,
-0.006415446288883686,
-0.019618932157754898,
-0.014325814321637154,
0.007184356451034546,
-0.0017390446737408638,
-0.006365655921399593,
0.005276695359498262,
-0.003679357934743166,
-0.004206812009215355,
0.00045588435023091733,
0.004881088621914387,
-0.0023758995812386274,
-0.00010604322596918792,
-0.002029990078881383,
-0.0023813394363969564,
0.0013603746192529798,
0.003476695390418172,
0.008378544822335243,
0.008441631682217121,
0.00020142804714851081,
0.002665336476638913,
-0.005627294536679983,
0.0013361407909542322,
-0.002382084960117936,
0.006145950872451067,
0.006379824131727219,
-0.0038669819477945566,
-0.0001821900368668139,
0.0042237937450408936,
0.004244737792760134,
0.001959787681698799,
0.011311469599604607,
0.0014932093909010291,
-0.002290469827130437,
0.007051004562526941,
0.009367608465254307,
-0.005719876382499933,
0.006754954811185598,
-0.002611936070024967,
0.006284811999648809,
0.002355558332055807,
-0.00968064833432436,
-0.012024435214698315,
-0.0029348863754421473,
0.006056270562112331,
0.004794821608811617,
-0.0017777386819943786,
-0.0005840876256115735,
0.0020444095134735107,
-0.00505795469507575,
-0.009112339466810226,
-0.006712691858410835,
-0.0036580900195986032,
-0.0013838813174515963,
0.003398094093427062,
0.07118840515613556,
-0.005501489154994488,
-0.0007266879547387362,
-0.008696663193404675,
0.000008152523150783964,
-0.0008515322115272284,
-0.0003286860301159322,
-0.0004901228239759803,
0.0005286982050165534,
0.0032397375907748938,
0.0025749686174094677,
-0.009995766915380955,
-0.009543891996145248,
0.0011098028626292944,
0.0010094664758071303,
-0.0032325382344424725,
0.004750204272568226,
0.007369059603661299,
-0.0066222199238836765,
0.0022886530496180058,
-0.012061097659170628,
0.0001816798758227378,
-0.0033719874918460846,
-0.008957800455391407,
-0.0033755269832909107,
-0.004447415936738253,
0.0022396103013306856,
0.006138468626886606,
0.007665375713258982,
-0.0024110348895192146,
0.006045050919055939,
-0.0011225830530747771,
0.0018193458672612906,
-0.00461044954136014,
-0.00037863943725824356,
-0.007452284451574087,
0.007480818312615156,
-0.001667389296926558,
-0.01137624029070139,
-0.008455774746835232,
-0.00576359499245882,
-0.00035224773455411196,
-0.007127388846129179,
0.005412275902926922,
-0.001409853808581829,
0.00729211512953043,
-0.0032955328933894634,
0.0036120060831308365,
-0.0032175532542169094,
-0.0011505677830427885,
-0.011704382486641407,
0.005402383394539356,
-0.18293128907680511,
0.009800502099096775,
0.0017706833314150572,
-0.005063326098024845,
-0.00384000432677567,
-0.010756699368357658,
-0.008285444229841232,
0.0023617353290319443,
0.008582060225307941,
0.0002044205612037331,
0.00007399790774798021,
-0.003000873140990734,
0.0021207882091403008,
0.005804500076919794,
-0.0019519560737535357,
-0.0048124962486326694,
0.004662638064473867,
-0.0058158086612820625,
-0.00019916187738999724,
0.004152245819568634,
0.006828524637967348,
0.008810319937765598,
0.002824040362611413,
0.003129396354779601,
0.0011634028051048517,
-0.006681432947516441,
0.0058433315716683865,
-0.0016800154699012637,
0.007903137244284153,
-0.011854391545057297,
-0.0037746476009488106,
-0.006724384613335133,
-0.0012083902256563306,
-0.0013219036627560854,
0.0025827328208833933,
-0.0002758328046184033,
0.007637636736035347,
0.0010398926679044962,
-0.00758260115981102,
0.007906166836619377,
-0.003251822432503104,
0.0317339226603508,
0.004488429985940456,
0.008915523998439312,
0.0009934190893545747,
-0.0023220109287649393,
-0.005423888564109802,
0.010106927715241909,
0.0031709400936961174,
0.014680570922791958,
-0.012781578116118908,
-0.006078322418034077,
0.0033137386199086905,
0.019848952069878578,
-0.0030003490392118692,
-0.007780428044497967,
-0.007423905190080404,
-0.006182021927088499,
0.004003649111837149,
0.010466856881976128,
0.009442438371479511,
-0.0058259302750229836,
0.007876085117459297,
-0.0031477794982492924,
-0.022609593346714973,
0.004297022242099047,
-0.00034022986073978245,
-0.005378065165132284,
0.0013851637486368418,
0.006434944923967123,
0.00926306564360857,
-0.0035536293871700764,
0.004692997317761183,
-0.0030546102207154036,
0.003575130831450224,
-0.001954279374331236,
0.006221151910722256,
-0.002206799341365695,
0.005734754726290703,
-0.008105677552521229,
0.010728406719863415,
-0.01068875938653946,
-0.0012842619325965643,
0.002987730083987117,
-0.0038862256333231926,
0.01006095577031374,
0.0046556866727769375,
-0.0029079217929393053,
-0.0009089627419598401,
-0.012236672453582287,
-0.0007017249008640647,
0.004458941053599119,
0.003114560153335333,
-0.0042802440002560616,
0.00258745183236897,
0.0003739150706678629,
0.004014814272522926,
0.008163468912243843,
-0.008077085018157959,
0.005207529291510582,
0.00671442411839962,
-0.008308045566082,
0.0009872439550235868,
-0.008280999958515167,
0.0003541531041264534,
0.006618986837565899,
-0.007058090530335903,
-0.009786185808479786,
0.0016021713381633162,
-0.004934045951813459,
-0.006697123404592276,
0.002573983510956168,
-0.008907223120331764,
-0.008917956613004208,
0.0007456767489202321,
-0.010162265971302986,
0.0013387693325057626
] |
8a40f2fa1c9f612802f1a429d750b73c73bf44c3 | 67,147 | py | Python | src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py | AndrewLane/azure-cli | 524491c580fc3c133f2d9859cef1c8251f4192e4 | [
"MIT"
] | null | null | null | src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py | AndrewLane/azure-cli | 524491c580fc3c133f2d9859cef1c8251f4192e4 | [
"MIT"
] | 3 | 2021-03-26T00:25:36.000Z | 2022-03-29T22:03:55.000Z | src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py | david-driscoll/azure-cli | 0dbf5e4ac2f35057bc9b8234b0a59612593552c5 | [
"MIT"
] | null | null | null | # --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint:disable=too-many-lines
import os
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse # pylint: disable=import-error
from knack.log import get_logger
from knack.util import CLIError
from azure.cli.core.commands.validators import (
get_default_location_from_resource_group, validate_file_or_dict, validate_parameter_set, validate_tags)
from azure.cli.core.util import hash_string
from azure.cli.command_modules.vm._vm_utils import check_existence, get_target_network_api, get_storage_blob_uri
from azure.cli.command_modules.vm._template_builder import StorageProfile
import azure.cli.core.keys as keys
from ._client_factory import _compute_client_factory
from ._actions import _get_latest_image_version
logger = get_logger(__name__)
def validate_asg_names_or_ids(cmd, namespace):
from msrestazure.tools import resource_id, is_valid_resource_id
from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.client_factory import get_subscription_id
ApplicationSecurityGroup = cmd.get_models('ApplicationSecurityGroup',
resource_type=ResourceType.MGMT_NETWORK)
resource_group = namespace.resource_group_name
subscription_id = get_subscription_id(cmd.cli_ctx)
names_or_ids = getattr(namespace, 'application_security_groups')
ids = []
if names_or_ids == [""] or not names_or_ids:
return
for val in names_or_ids:
if not is_valid_resource_id(val):
val = resource_id(
subscription=subscription_id,
resource_group=resource_group,
namespace='Microsoft.Network', type='applicationSecurityGroups',
name=val
)
ids.append(ApplicationSecurityGroup(id=val))
setattr(namespace, 'application_security_groups', ids)
def validate_nsg_name(cmd, namespace):
from msrestazure.tools import resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
vm_id = resource_id(name=namespace.vm_name, resource_group=namespace.resource_group_name,
namespace='Microsoft.Compute', type='virtualMachines',
subscription=get_subscription_id(cmd.cli_ctx))
namespace.network_security_group_name = namespace.network_security_group_name \
or '{}_NSG_{}'.format(namespace.vm_name, hash_string(vm_id, length=8))
def validate_keyvault(cmd, namespace):
namespace.keyvault = _get_resource_id(cmd.cli_ctx, namespace.keyvault, namespace.resource_group_name,
'vaults', 'Microsoft.KeyVault')
def process_vm_secret_format(cmd, namespace):
from msrestazure.tools import is_valid_resource_id
keyvault_usage = CLIError('usage error: [--keyvault NAME --resource-group NAME | --keyvault ID]')
kv = namespace.keyvault
rg = namespace.resource_group_name
if rg:
if not kv or is_valid_resource_id(kv):
raise keyvault_usage
validate_keyvault(cmd, namespace)
else:
if kv and not is_valid_resource_id(kv):
raise keyvault_usage
def _get_resource_group_from_vault_name(cli_ctx, vault_name):
"""
Fetch resource group from vault name
:param str vault_name: name of the key vault
:return: resource group name or None
:rtype: str
"""
from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from msrestazure.tools import parse_resource_id
client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_KEYVAULT).vaults
for vault in client.list():
id_comps = parse_resource_id(vault.id)
if id_comps['name'] == vault_name:
return id_comps['resource_group']
return None
def _get_resource_id(cli_ctx, val, resource_group, resource_type, resource_namespace):
from msrestazure.tools import resource_id, is_valid_resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
if is_valid_resource_id(val):
return val
kwargs = {
'name': val,
'resource_group': resource_group,
'namespace': resource_namespace,
'type': resource_type,
'subscription': get_subscription_id(cli_ctx)
}
missing_kwargs = {k: v for k, v in kwargs.items() if not v}
return resource_id(**kwargs) if not missing_kwargs else None
def _get_nic_id(cli_ctx, val, resource_group):
return _get_resource_id(cli_ctx, val, resource_group,
'networkInterfaces', 'Microsoft.Network')
def validate_vm_nic(cmd, namespace):
namespace.nic = _get_nic_id(cmd.cli_ctx, namespace.nic, namespace.resource_group_name)
def validate_vm_nics(cmd, namespace):
rg = namespace.resource_group_name
nic_ids = []
for n in namespace.nics:
nic_ids.append(_get_nic_id(cmd.cli_ctx, n, rg))
namespace.nics = nic_ids
if hasattr(namespace, 'primary_nic') and namespace.primary_nic:
namespace.primary_nic = _get_nic_id(cmd.cli_ctx, namespace.primary_nic, rg)
def _validate_secrets(secrets, os_type):
"""
Validates a parsed JSON array containing secrets for use in VM Creation
Secrets JSON structure
[{
"sourceVault": { "id": "value" },
"vaultCertificates": [{
"certificateUrl": "value",
"certificateStore": "cert store name (only on windows)"
}]
}]
:param dict secrets: Dict fitting the JSON description above
:param string os_type: the type of OS (linux or windows)
:return: errors if any were found
:rtype: list
"""
is_windows = os_type == 'windows'
errors = []
try:
loaded_secret = [validate_file_or_dict(secret) for secret in secrets]
except Exception as err:
raise CLIError('Error decoding secrets: {0}'.format(err))
for idx_arg, narg_secret in enumerate(loaded_secret):
for idx, secret in enumerate(narg_secret):
if 'sourceVault' not in secret:
errors.append(
'Secret is missing sourceVault key at index {0} in arg {1}'.format(
idx, idx_arg))
if 'sourceVault' in secret and 'id' not in secret['sourceVault']:
errors.append(
'Secret is missing sourceVault.id key at index {0} in arg {1}'.format(
idx, idx_arg))
if 'vaultCertificates' not in secret or not secret['vaultCertificates']:
err = 'Secret is missing vaultCertificates array or it is empty at index {0} in ' \
'arg {1} '
errors.append(err.format(idx, idx_arg))
else:
for jdx, cert in enumerate(secret['vaultCertificates']):
message = 'Secret is missing {0} within vaultCertificates array at secret ' \
'index {1} and vaultCertificate index {2} in arg {3}'
if 'certificateUrl' not in cert:
errors.append(message.format('certificateUrl', idx, jdx, idx_arg))
if is_windows and 'certificateStore' not in cert:
errors.append(message.format('certificateStore', idx, jdx, idx_arg))
if errors:
raise CLIError('\n'.join(errors))
# region VM Create Validators
def _parse_image_argument(cmd, namespace):
""" Systematically determines what type is supplied for the --image parameter. Updates the
namespace and returns the type for subsequent processing. """
from msrestazure.tools import is_valid_resource_id
from msrestazure.azure_exceptions import CloudError
import re
# 1 - check if a fully-qualified ID (assumes it is an image ID)
if is_valid_resource_id(namespace.image):
return 'image_id'
# 2 - attempt to match an URN pattern
urn_match = re.match('([^:]*):([^:]*):([^:]*):([^:]*)', namespace.image)
if urn_match:
namespace.os_publisher = urn_match.group(1)
namespace.os_offer = urn_match.group(2)
namespace.os_sku = urn_match.group(3)
namespace.os_version = urn_match.group(4)
if not any([namespace.plan_name, namespace.plan_product, namespace.plan_publisher]):
image_plan = _get_image_plan_info_if_exists(cmd, namespace)
if image_plan:
namespace.plan_name = image_plan.name
namespace.plan_product = image_plan.product
namespace.plan_publisher = image_plan.publisher
return 'urn'
# 3 - unmanaged vhd based images?
if urlparse(namespace.image).scheme:
return 'uri'
# 4 - attempt to match an URN alias (most likely)
from azure.cli.command_modules.vm._actions import load_images_from_aliases_doc
images = load_images_from_aliases_doc(cmd.cli_ctx)
matched = next((x for x in images if x['urnAlias'].lower() == namespace.image.lower()), None)
if matched:
namespace.os_publisher = matched['publisher']
namespace.os_offer = matched['offer']
namespace.os_sku = matched['sku']
namespace.os_version = matched['version']
return 'urn'
# 5 - check if an existing managed disk image resource
compute_client = _compute_client_factory(cmd.cli_ctx)
try:
compute_client.images.get(namespace.resource_group_name, namespace.image)
namespace.image = _get_resource_id(cmd.cli_ctx, namespace.image, namespace.resource_group_name,
'images', 'Microsoft.Compute')
return 'image_id'
except CloudError:
err = 'Invalid image "{}". Use a custom image name, id, or pick one from {}'
raise CLIError(err.format(namespace.image, [x['urnAlias'] for x in images]))
def _get_image_plan_info_if_exists(cmd, namespace):
from msrestazure.azure_exceptions import CloudError
try:
compute_client = _compute_client_factory(cmd.cli_ctx)
if namespace.os_version.lower() == 'latest':
image_version = _get_latest_image_version(cmd.cli_ctx, namespace.location, namespace.os_publisher,
namespace.os_offer, namespace.os_sku)
else:
image_version = namespace.os_version
image = compute_client.virtual_machine_images.get(namespace.location,
namespace.os_publisher,
namespace.os_offer,
namespace.os_sku,
image_version)
# pylint: disable=no-member
return image.plan
except CloudError as ex:
logger.warning("Querying the image of '%s' failed for an error '%s'. Configuring plan settings "
"will be skipped", namespace.image, ex.message)
# pylint: disable=inconsistent-return-statements
def _get_storage_profile_description(profile):
if profile == StorageProfile.SACustomImage:
return 'create unmanaged OS disk created from generalized VHD'
elif profile == StorageProfile.SAPirImage:
return 'create unmanaged OS disk from Azure Marketplace image'
elif profile == StorageProfile.SASpecializedOSDisk:
return 'attach to existing unmanaged OS disk'
elif profile == StorageProfile.ManagedCustomImage:
return 'create managed OS disk from custom image'
elif profile == StorageProfile.ManagedPirImage:
return 'create managed OS disk from Azure Marketplace image'
elif profile == StorageProfile.ManagedSpecializedOSDisk:
return 'attach existing managed OS disk'
def _validate_managed_disk_sku(sku):
allowed_skus = ['Premium_LRS', 'Standard_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS']
if sku and sku.lower() not in [x.lower() for x in allowed_skus]:
raise CLIError("invalid storage SKU '{}': allowed values: '{}'".format(sku, allowed_skus))
def _validate_location(cmd, namespace, zone_info, size_info):
from ._vm_utils import list_sku_info
if not namespace.location:
get_default_location_from_resource_group(cmd, namespace)
if zone_info:
sku_infos = list_sku_info(cmd.cli_ctx, namespace.location)
temp = next((x for x in sku_infos if x.name.lower() == size_info.lower()), None)
# For Stack (compute - 2017-03-30), Resource_sku doesn't implement location_info property
if not hasattr(temp, 'location_info'):
return
if not temp or not [x for x in (temp.location_info or []) if x.zones]:
raise CLIError("{}'s location can't be used to create the VM/VMSS because availablity zone is not yet "
"supported. Please use '--location' to specify a capable one. 'az vm list-skus' can be "
"used to find such locations".format(namespace.resource_group_name))
# pylint: disable=too-many-branches, too-many-statements
def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
from msrestazure.tools import parse_resource_id
# use minimal parameters to resolve the expected storage profile
if getattr(namespace, 'attach_os_disk', None) and not namespace.image:
if namespace.use_unmanaged_disk:
# STORAGE PROFILE #3
namespace.storage_profile = StorageProfile.SASpecializedOSDisk
else:
# STORAGE PROFILE #6
namespace.storage_profile = StorageProfile.ManagedSpecializedOSDisk
elif namespace.image and not getattr(namespace, 'attach_os_disk', None):
image_type = _parse_image_argument(cmd, namespace)
if image_type == 'uri':
# STORAGE PROFILE #2
namespace.storage_profile = StorageProfile.SACustomImage
elif image_type == 'image_id':
# STORAGE PROFILE #5
namespace.storage_profile = StorageProfile.ManagedCustomImage
elif image_type == 'urn':
if namespace.use_unmanaged_disk:
# STORAGE PROFILE #1
namespace.storage_profile = StorageProfile.SAPirImage
else:
# STORAGE PROFILE #4
namespace.storage_profile = StorageProfile.ManagedPirImage
else:
raise CLIError('Unrecognized image type: {}'.format(image_type))
else:
# did not specify image XOR attach-os-disk
raise CLIError('incorrect usage: --image IMAGE | --attach-os-disk DISK')
auth_params = ['admin_password', 'admin_username', 'authentication_type',
'generate_ssh_keys', 'ssh_dest_key_path', 'ssh_key_value']
# perform parameter validation for the specific storage profile
# start with the required/forbidden parameters for VM
if namespace.storage_profile == StorageProfile.ManagedPirImage:
required = ['image']
forbidden = ['os_type', 'attach_os_disk', 'storage_account',
'storage_container_name', 'use_unmanaged_disk']
if for_scale_set:
forbidden.append('os_disk_name')
_validate_managed_disk_sku(namespace.storage_sku)
elif namespace.storage_profile == StorageProfile.ManagedCustomImage:
required = ['image']
forbidden = ['os_type', 'attach_os_disk', 'storage_account',
'storage_container_name', 'use_unmanaged_disk']
if for_scale_set:
forbidden.append('os_disk_name')
_validate_managed_disk_sku(namespace.storage_sku)
elif namespace.storage_profile == StorageProfile.ManagedSpecializedOSDisk:
required = ['os_type', 'attach_os_disk']
forbidden = ['os_disk_name', 'os_caching', 'storage_account',
'storage_container_name', 'use_unmanaged_disk', 'storage_sku'] + auth_params
_validate_managed_disk_sku(namespace.storage_sku)
elif namespace.storage_profile == StorageProfile.SAPirImage:
required = ['image', 'use_unmanaged_disk']
forbidden = ['os_type', 'attach_os_disk', 'data_disk_sizes_gb']
elif namespace.storage_profile == StorageProfile.SACustomImage:
required = ['image', 'os_type', 'use_unmanaged_disk']
forbidden = ['attach_os_disk', 'data_disk_sizes_gb']
elif namespace.storage_profile == StorageProfile.SASpecializedOSDisk:
required = ['os_type', 'attach_os_disk', 'use_unmanaged_disk']
forbidden = ['os_disk_name', 'os_caching', 'image', 'storage_account',
'storage_container_name', 'data_disk_sizes_gb', 'storage_sku'] + auth_params
else:
raise CLIError('Unrecognized storage profile: {}'.format(namespace.storage_profile))
logger.debug("storage profile '%s'", namespace.storage_profile)
if for_scale_set:
# VMSS lacks some parameters, so scrub these out
props_to_remove = ['attach_os_disk', 'storage_account']
for prop in props_to_remove:
if prop in required:
required.remove(prop)
if prop in forbidden:
forbidden.remove(prop)
# set default storage SKU if not provided and using an image based OS
if not namespace.storage_sku and namespace.storage_profile in [StorageProfile.SAPirImage, StorageProfile.SACustomImage]: # pylint: disable=line-too-long
namespace.storage_sku = 'Standard_LRS' if for_scale_set else 'Premium_LRS'
if namespace.storage_sku == 'UltraSSD_LRS' and namespace.ultra_ssd_enabled is None:
namespace.ultra_ssd_enabled = True
# Now verify that the status of required and forbidden parameters
validate_parameter_set(
namespace, required, forbidden,
description='storage profile: {}:'.format(_get_storage_profile_description(namespace.storage_profile)))
image_data_disks_num = 0
if namespace.storage_profile == StorageProfile.ManagedCustomImage:
# extract additional information from a managed custom image
res = parse_resource_id(namespace.image)
compute_client = _compute_client_factory(cmd.cli_ctx, subscription_id=res['subscription'])
if res['type'].lower() == 'images':
image_info = compute_client.images.get(res['resource_group'], res['name'])
namespace.os_type = image_info.storage_profile.os_disk.os_type.value
image_data_disks_num = len(image_info.storage_profile.data_disks or [])
elif res['type'].lower() == 'galleries':
image_info = compute_client.gallery_images.get(resource_group_name=res['resource_group'],
gallery_name=res['name'],
gallery_image_name=res['child_name_1'])
namespace.os_type = image_info.os_type.value
gallery_image_version = res.get('child_name_2', '')
if gallery_image_version.lower() in ['latest', '']:
image_version_infos = compute_client.gallery_image_versions.list_by_gallery_image(
resource_group_name=res['resource_group'], gallery_name=res['name'],
gallery_image_name=res['child_name_1'])
image_version_infos = [x for x in image_version_infos if not x.publishing_profile.exclude_from_latest]
if not image_version_infos:
raise CLIError('There is no latest image version exists for "{}"'.format(namespace.image))
image_version_info = sorted(image_version_infos, key=lambda x: x.publishing_profile.published_date)[-1]
else:
image_version_info = compute_client.gallery_image_versions.get(
resource_group_name=res['resource_group'], gallery_name=res['name'],
gallery_image_name=res['child_name_1'], gallery_image_version_name=res['child_name_2'])
image_data_disks_num = len(image_version_info.storage_profile.data_disk_images or [])
else:
raise CLIError('usage error: unrecognized image informations "{}"'.format(namespace.image))
# pylint: disable=no-member
elif namespace.storage_profile == StorageProfile.ManagedSpecializedOSDisk:
# accept disk name or ID
namespace.attach_os_disk = _get_resource_id(
cmd.cli_ctx, namespace.attach_os_disk, namespace.resource_group_name, 'disks', 'Microsoft.Compute')
if getattr(namespace, 'attach_data_disks', None):
if not namespace.use_unmanaged_disk:
namespace.attach_data_disks = [_get_resource_id(cmd.cli_ctx, d, namespace.resource_group_name, 'disks',
'Microsoft.Compute') for d in namespace.attach_data_disks]
if not namespace.os_type:
namespace.os_type = 'windows' if 'windows' in namespace.os_offer.lower() else 'linux'
from ._vm_utils import normalize_disk_info
# attach_data_disks are not exposed yet for VMSS, so use 'getattr' to avoid crash
namespace.disk_info = normalize_disk_info(image_data_disks_num=image_data_disks_num,
data_disk_sizes_gb=namespace.data_disk_sizes_gb,
attach_data_disks=getattr(namespace, 'attach_data_disks', []),
storage_sku=namespace.storage_sku,
os_disk_caching=namespace.os_caching,
data_disk_cachings=namespace.data_caching)
def _validate_vm_create_storage_account(cmd, namespace):
from msrestazure.tools import parse_resource_id
if namespace.storage_account:
storage_id = parse_resource_id(namespace.storage_account)
rg = storage_id.get('resource_group', namespace.resource_group_name)
if check_existence(cmd.cli_ctx, storage_id['name'], rg, 'Microsoft.Storage', 'storageAccounts'):
# 1 - existing storage account specified
namespace.storage_account_type = 'existing'
logger.debug("using specified existing storage account '%s'", storage_id['name'])
else:
# 2 - params for new storage account specified
namespace.storage_account_type = 'new'
logger.debug("specified storage account '%s' not found and will be created", storage_id['name'])
else:
from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.client_factory import get_mgmt_service_client
storage_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_STORAGE).storage_accounts
# find storage account in target resource group that matches the VM's location
sku_tier = 'Premium' if 'Premium' in namespace.storage_sku else 'Standard'
account = next(
(a for a in storage_client.list_by_resource_group(namespace.resource_group_name)
if a.sku.tier.value == sku_tier and a.location == namespace.location), None)
if account:
# 3 - nothing specified - find viable storage account in target resource group
namespace.storage_account = account.name
namespace.storage_account_type = 'existing'
logger.debug("suitable existing storage account '%s' will be used", account.name)
else:
# 4 - nothing specified - create a new storage account
namespace.storage_account_type = 'new'
logger.debug('no suitable storage account found. One will be created.')
def _validate_vm_create_availability_set(cmd, namespace):
from msrestazure.tools import parse_resource_id, resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
if namespace.availability_set:
as_id = parse_resource_id(namespace.availability_set)
name = as_id['name']
rg = as_id.get('resource_group', namespace.resource_group_name)
if not check_existence(cmd.cli_ctx, name, rg, 'Microsoft.Compute', 'availabilitySets'):
raise CLIError("Availability set '{}' does not exist.".format(name))
namespace.availability_set = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=rg,
namespace='Microsoft.Compute',
type='availabilitySets',
name=name)
logger.debug("adding to specified availability set '%s'", namespace.availability_set)
def _validate_vm_vmss_create_vnet(cmd, namespace, for_scale_set=False):
from msrestazure.tools import is_valid_resource_id
vnet = namespace.vnet_name
subnet = namespace.subnet
rg = namespace.resource_group_name
location = namespace.location
nics = getattr(namespace, 'nics', None)
if not vnet and not subnet and not nics:
logger.debug('no subnet specified. Attempting to find an existing Vnet and subnet...')
# if nothing specified, try to find an existing vnet and subnet in the target resource group
client = get_network_client(cmd.cli_ctx).virtual_networks
# find VNET in target resource group that matches the VM's location with a matching subnet
for vnet_match in (v for v in client.list(rg) if v.location == location and v.subnets):
# 1 - find a suitable existing vnet/subnet
result = None
if not for_scale_set:
result = next((s for s in vnet_match.subnets if s.name.lower() != 'gatewaysubnet'), None)
else:
def _check_subnet(s):
if s.name.lower() == 'gatewaysubnet':
return False
subnet_mask = s.address_prefix.split('/')[-1]
return _subnet_capacity_check(subnet_mask, namespace.instance_count,
not namespace.disable_overprovision)
result = next((s for s in vnet_match.subnets if _check_subnet(s)), None)
if not result:
continue
namespace.subnet = result.name
namespace.vnet_name = vnet_match.name
namespace.vnet_type = 'existing'
logger.debug("existing vnet '%s' and subnet '%s' found", namespace.vnet_name, namespace.subnet)
return
if subnet:
subnet_is_id = is_valid_resource_id(subnet)
if (subnet_is_id and vnet) or (not subnet_is_id and not vnet):
raise CLIError("incorrect '--subnet' usage: --subnet SUBNET_ID | "
"--subnet SUBNET_NAME --vnet-name VNET_NAME")
subnet_exists = \
check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', vnet, 'virtualNetworks')
if subnet_is_id and not subnet_exists:
raise CLIError("Subnet '{}' does not exist.".format(subnet))
elif subnet_exists:
# 2 - user specified existing vnet/subnet
namespace.vnet_type = 'existing'
logger.debug("using specified vnet '%s' and subnet '%s'", namespace.vnet_name, namespace.subnet)
return
# 3 - create a new vnet/subnet
namespace.vnet_type = 'new'
logger.debug('no suitable subnet found. One will be created.')
def _subnet_capacity_check(subnet_mask, vmss_instance_count, over_provision):
mask = int(subnet_mask)
# '2' are the reserved broadcasting addresses
# '*1.5' so we have enough leeway for over-provision
factor = 1.5 if over_provision else 1
return ((1 << (32 - mask)) - 2) > int(vmss_instance_count * factor)
def _validate_vm_vmss_accelerated_networking(cli_ctx, namespace):
if namespace.accelerated_networking is None:
size = getattr(namespace, 'size', None) or getattr(namespace, 'vm_sku', None)
size = size.lower()
# to refresh the list, run 'az vm create --accelerated-networking --size Standard_DS1_v2' and
# get it from the error
aval_sizes = ['Standard_D3_v2', 'Standard_D12_v2', 'Standard_D3_v2_Promo', 'Standard_D12_v2_Promo',
'Standard_DS3_v2', 'Standard_DS12_v2', 'Standard_DS13-4_v2', 'Standard_DS14-4_v2',
'Standard_DS3_v2_Promo', 'Standard_DS12_v2_Promo', 'Standard_DS13-4_v2_Promo',
'Standard_DS14-4_v2_Promo', 'Standard_F4', 'Standard_F4s', 'Standard_D8_v3', 'Standard_D8s_v3',
'Standard_D32-8s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_D3_v2_ABC',
'Standard_D12_v2_ABC', 'Standard_F4_ABC', 'Standard_F8s_v2', 'Standard_D4_v2',
'Standard_D13_v2', 'Standard_D4_v2_Promo', 'Standard_D13_v2_Promo', 'Standard_DS4_v2',
'Standard_DS13_v2', 'Standard_DS14-8_v2', 'Standard_DS4_v2_Promo', 'Standard_DS13_v2_Promo',
'Standard_DS14-8_v2_Promo', 'Standard_F8', 'Standard_F8s', 'Standard_M64-16ms',
'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D32-16s_v3', 'Standard_D64-16s_v3',
'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E32-16s_v3', 'Standard_D4_v2_ABC',
'Standard_D13_v2_ABC', 'Standard_F8_ABC', 'Standard_F16s_v2', 'Standard_D5_v2',
'Standard_D14_v2', 'Standard_D5_v2_Promo', 'Standard_D14_v2_Promo', 'Standard_DS5_v2',
'Standard_DS14_v2', 'Standard_DS5_v2_Promo', 'Standard_DS14_v2_Promo', 'Standard_F16',
'Standard_F16s', 'Standard_M64-32ms', 'Standard_M128-32ms', 'Standard_D32_v3',
'Standard_D32s_v3', 'Standard_D64-32s_v3', 'Standard_E32_v3', 'Standard_E32s_v3',
'Standard_E32-8s_v3', 'Standard_E32-16_v3', 'Standard_D5_v2_ABC', 'Standard_D14_v2_ABC',
'Standard_F16_ABC', 'Standard_F32s_v2', 'Standard_D15_v2', 'Standard_D15_v2_Promo',
'Standard_D15_v2_Nested', 'Standard_DS15_v2', 'Standard_DS15_v2_Promo',
'Standard_DS15_v2_Nested', 'Standard_D40_v3', 'Standard_D40s_v3', 'Standard_D15_v2_ABC',
'Standard_M64ms', 'Standard_M64s', 'Standard_M128-64ms', 'Standard_D64_v3', 'Standard_D64s_v3',
'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3',
'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_M128s', 'Standard_M128ms', 'Standard_L8s_v2',
'Standard_L16s_v2', 'Standard_L32s_v2', 'Standard_L64s_v2', 'Standard_L96s_v2', 'SQLGL',
'SQLGLCore', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D2_v2', 'Standard_DS2_v2',
'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_F2', 'Standard_F2s', 'Standard_F4s_v2',
'Standard_D11_v2', 'Standard_DS11_v2', 'AZAP_Performance_ComputeV17C']
aval_sizes = [x.lower() for x in aval_sizes]
if size not in aval_sizes:
return
new_4core_sizes = ['Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D3_v2_ABC', 'Standard_DS3_v2',
'Standard_DS3_v2_Promo', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D12_v2_ABC',
'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_F8s_v2', 'Standard_F4',
'Standard_F4_ABC', 'Standard_F4s', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_D8_v3',
'Standard_D8s_v3']
new_4core_sizes = [x.lower() for x in new_4core_sizes]
if size not in new_4core_sizes:
compute_client = _compute_client_factory(cli_ctx)
sizes = compute_client.virtual_machine_sizes.list(namespace.location)
size_info = next((s for s in sizes if s.name.lower() == size), None)
if size_info is None or size_info.number_of_cores < 8:
return
# VMs need to be a supported image in the marketplace
# Ubuntu 16.04, SLES 12 SP3, RHEL 7.4, CentOS 7.4, CoreOS Linux, Debian "Stretch" with backports kernel
# Oracle Linux 7.4, Windows Server 2016, Windows Server 2012R2
publisher, offer, sku = namespace.os_publisher, namespace.os_offer, namespace.os_sku
if not publisher:
return
publisher, offer, sku = publisher.lower(), offer.lower(), sku.lower()
distros = [('canonical', 'UbuntuServer', '^16.04'), ('suse', 'sles', '^12-sp3'), ('redhat', 'rhel', '^7.4'),
('openlogic', 'centos', '^7.4'), ('coreos', 'coreos', None), ('credativ', 'debian', '-backports'),
('oracle', 'oracle-linux', '^7.4'), ('MicrosoftWindowsServer', 'WindowsServer', '^2016'),
('MicrosoftWindowsServer', 'WindowsServer', '^2012-R2')]
import re
for p, o, s in distros:
if p.lower() == publisher and (o is None or o.lower() == offer) and (s is None or re.match(s, sku, re.I)):
namespace.accelerated_networking = True
def _validate_vmss_create_subnet(namespace):
if namespace.vnet_type == 'new':
if namespace.subnet_address_prefix is None:
cidr = namespace.vnet_address_prefix.split('/', 1)[0]
i = 0
for i in range(24, 16, -1):
if _subnet_capacity_check(i, namespace.instance_count, not namespace.disable_overprovision):
break
if i < 16:
err = "instance count '{}' is out of range of 2^16 subnet size'"
raise CLIError(err.format(namespace.instance_count))
namespace.subnet_address_prefix = '{}/{}'.format(cidr, i)
if namespace.app_gateway_type and namespace.app_gateway_subnet_address_prefix is None:
namespace.app_gateway_subnet_address_prefix = _get_next_subnet_addr_suffix(
namespace.vnet_address_prefix, namespace.subnet_address_prefix, 24)
def _get_next_subnet_addr_suffix(vnet_cidr, subnet_cidr, new_mask):
def _convert_to_int(address, bit_mask_len):
a, b, c, d = [int(x) for x in address.split('.')]
result = '{0:08b}{1:08b}{2:08b}{3:08b}'.format(a, b, c, d)
return int(result[:-bit_mask_len], 2)
error_msg = "usage error: --subnet-address-prefix value should be a subrange of --vnet-address-prefix's"
# extract vnet information needed to verify the defaults we are coming out
vnet_ip_address, mask = vnet_cidr.split('/')
vnet_bit_mask_len = 32 - int(mask)
vnet_int = _convert_to_int(vnet_ip_address, vnet_bit_mask_len)
subnet_ip_address, mask = subnet_cidr.split('/')
subnet_bit_mask_len = 32 - int(mask)
if vnet_bit_mask_len <= subnet_bit_mask_len:
raise CLIError(error_msg)
candidate_int = _convert_to_int(subnet_ip_address, subnet_bit_mask_len) + 1
if (candidate_int >> (vnet_bit_mask_len - subnet_bit_mask_len)) > vnet_int: # overflows?
candidate_int = candidate_int - 2 # try the other way around
if (candidate_int >> (vnet_bit_mask_len - subnet_bit_mask_len)) > vnet_int:
raise CLIError(error_msg)
# format back to the cidr
candaidate_str = '{0:32b}'.format(candidate_int << subnet_bit_mask_len)
return '{0}.{1}.{2}.{3}/{4}'.format(int(candaidate_str[0:8], 2), int(candaidate_str[8:16], 2),
int(candaidate_str[16:24], 2), int(candaidate_str[24:32], 2),
new_mask)
def _validate_vm_create_nsg(cmd, namespace):
if namespace.nsg:
if check_existence(cmd.cli_ctx, namespace.nsg, namespace.resource_group_name,
'Microsoft.Network', 'networkSecurityGroups'):
namespace.nsg_type = 'existing'
logger.debug("using specified NSG '%s'", namespace.nsg)
else:
namespace.nsg_type = 'new'
logger.debug("specified NSG '%s' not found. It will be created.", namespace.nsg)
elif namespace.nsg == '':
namespace.nsg_type = None
logger.debug('no NSG will be used')
elif namespace.nsg is None:
namespace.nsg_type = 'new'
logger.debug('new NSG will be created')
def _validate_vmss_create_nsg(cmd, namespace):
if namespace.nsg:
namespace.nsg = _get_resource_id(cmd.cli_ctx, namespace.nsg, namespace.resource_group_name,
'networkSecurityGroups', 'Microsoft.Network')
def _validate_vm_vmss_create_public_ip(cmd, namespace):
if namespace.public_ip_address:
if check_existence(cmd.cli_ctx, namespace.public_ip_address, namespace.resource_group_name,
'Microsoft.Network', 'publicIPAddresses'):
namespace.public_ip_address_type = 'existing'
logger.debug("using existing specified public IP '%s'", namespace.public_ip_address)
else:
namespace.public_ip_address_type = 'new'
logger.debug("specified public IP '%s' not found. It will be created.", namespace.public_ip_address)
elif namespace.public_ip_address == '':
namespace.public_ip_address_type = None
logger.debug('no public IP address will be used')
elif namespace.public_ip_address is None:
namespace.public_ip_address_type = 'new'
logger.debug('new public IP address will be created')
# Public-IP SKU is only exposed for VM. VMSS has no such needs so far
if getattr(namespace, 'public_ip_sku', None):
from azure.cli.core.profiles import ResourceType
PublicIPAddressSkuName, IPAllocationMethod = cmd.get_models('PublicIPAddressSkuName', 'IPAllocationMethod',
resource_type=ResourceType.MGMT_NETWORK)
if namespace.public_ip_sku == PublicIPAddressSkuName.standard.value:
if not namespace.public_ip_address_allocation:
namespace.public_ip_address_allocation = IPAllocationMethod.static.value
def _validate_vmss_create_public_ip(cmd, namespace):
if namespace.load_balancer_type is None and namespace.app_gateway_type is None:
if namespace.public_ip_address:
raise CLIError('--public-ip-address can only be used when creating a new load '
'balancer or application gateway frontend.')
namespace.public_ip_address = ''
_validate_vm_vmss_create_public_ip(cmd, namespace)
def _validate_vm_create_nics(cmd, namespace):
from msrestazure.tools import resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
nics_value = namespace.nics
nics = []
if not nics_value:
namespace.nic_type = 'new'
logger.debug('new NIC will be created')
return
if not isinstance(nics_value, list):
nics_value = [nics_value]
for n in nics_value:
nics.append({
'id': n if '/' in n else resource_id(name=n,
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='networkInterfaces',
subscription=get_subscription_id(cmd.cli_ctx)),
'properties': {
'primary': nics_value[0] == n
}
})
namespace.nics = nics
namespace.nic_type = 'existing'
namespace.public_ip_address_type = None
logger.debug('existing NIC(s) will be used')
def _validate_vm_vmss_create_auth(namespace):
if namespace.storage_profile in [StorageProfile.ManagedSpecializedOSDisk,
StorageProfile.SASpecializedOSDisk]:
return
namespace.admin_username = _validate_admin_username(namespace.admin_username, namespace.os_type)
if not namespace.os_type:
raise CLIError("Unable to resolve OS type. Specify '--os-type' argument.")
if not namespace.authentication_type:
# apply default auth type (password for Windows, ssh for Linux) by examining the OS type
namespace.authentication_type = 'password' \
if (namespace.os_type.lower() == 'windows' or namespace.admin_password) else 'ssh'
if namespace.os_type.lower() == 'windows' and namespace.authentication_type == 'ssh':
raise CLIError('SSH not supported for Windows VMs.')
# validate proper arguments supplied based on the authentication type
if namespace.authentication_type == 'password':
if namespace.ssh_key_value or namespace.ssh_dest_key_path:
raise ValueError(
"incorrect usage for authentication-type 'password': "
"[--admin-username USERNAME] --admin-password PASSWORD")
from knack.prompting import prompt_pass, NoTTYException
try:
if not namespace.admin_password:
namespace.admin_password = prompt_pass('Admin Password: ', confirm=True)
except NoTTYException:
raise CLIError('Please specify password in non-interactive mode.')
# validate password
_validate_admin_password(namespace.admin_password,
namespace.os_type)
elif namespace.authentication_type == 'ssh':
if namespace.admin_password:
raise ValueError('Admin password cannot be used with SSH authentication type')
validate_ssh_key(namespace)
if not namespace.ssh_dest_key_path:
namespace.ssh_dest_key_path = \
'/home/{}/.ssh/authorized_keys'.format(namespace.admin_username)
def _validate_admin_username(username, os_type):
import re
if not username:
raise CLIError("admin user name can not be empty")
is_linux = (os_type.lower() == 'linux')
# pylint: disable=line-too-long
pattern = (r'[\\\/"\[\]:|<>+=;,?*@#()!A-Z]+' if is_linux else r'[\\\/"\[\]:|<>+=;,?*@]+')
linux_err = r'admin user name cannot contain upper case character A-Z, special characters \/"[]:|<>+=;,?*@#()! or start with $ or -'
win_err = r'admin user name cannot contain special characters \/"[]:|<>+=;,?*@# or ends with .'
if re.findall(pattern, username):
raise CLIError(linux_err if is_linux else win_err)
if is_linux and re.findall(r'^[$-]+', username):
raise CLIError(linux_err)
if not is_linux and username.endswith('.'):
raise CLIError(win_err)
disallowed_user_names = [
"administrator", "admin", "user", "user1", "test", "user2",
"test1", "user3", "admin1", "1", "123", "a", "actuser", "adm",
"admin2", "aspnet", "backup", "console", "guest",
"owner", "root", "server", "sql", "support", "support_388945a0",
"sys", "test2", "test3", "user4", "user5"]
if username.lower() in disallowed_user_names:
raise CLIError("This user name '{}' meets the general requirements, but is specifically disallowed for this image. Please try a different value.".format(username))
return username
def _validate_admin_password(password, os_type):
import re
is_linux = (os_type.lower() == 'linux')
max_length = 72 if is_linux else 123
min_length = 12
if len(password) not in range(min_length, max_length + 1):
raise CLIError('The password length must be between {} and {}'.format(min_length,
max_length))
contains_lower = re.findall('[a-z]+', password)
contains_upper = re.findall('[A-Z]+', password)
contains_digit = re.findall('[0-9]+', password)
contains_special_char = re.findall(r'[ `~!@#$%^&*()=+_\[\]{}\|;:.\/\'\",<>?]+', password)
count = len([x for x in [contains_lower, contains_upper,
contains_digit, contains_special_char] if x])
# pylint: disable=line-too-long
if count < 3:
raise CLIError('Password must have the 3 of the following: 1 lower case character, 1 upper case character, 1 number and 1 special character')
def validate_ssh_key(namespace):
string_or_file = (namespace.ssh_key_value or
os.path.join(os.path.expanduser('~'), '.ssh', 'id_rsa.pub'))
content = string_or_file
if os.path.exists(string_or_file):
logger.info('Use existing SSH public key file: %s', string_or_file)
with open(string_or_file, 'r') as f:
content = f.read()
elif not keys.is_valid_ssh_rsa_public_key(content):
if namespace.generate_ssh_keys:
# figure out appropriate file names:
# 'base_name'(with private keys), and 'base_name.pub'(with public keys)
public_key_filepath = string_or_file
if public_key_filepath[-4:].lower() == '.pub':
private_key_filepath = public_key_filepath[:-4]
else:
private_key_filepath = public_key_filepath + '.private'
content = keys.generate_ssh_keys(private_key_filepath, public_key_filepath)
logger.warning("SSH key files '%s' and '%s' have been generated under ~/.ssh to "
"allow SSH access to the VM. If using machines without "
"permanent storage, back up your keys to a safe location.",
private_key_filepath, public_key_filepath)
else:
raise CLIError('An RSA key file or key value must be supplied to SSH Key Value. '
'You can use --generate-ssh-keys to let CLI generate one for you')
namespace.ssh_key_value = content
def _validate_vm_vmss_msi(cmd, namespace, from_set_command=False):
if from_set_command or namespace.assign_identity is not None:
identities = namespace.assign_identity or []
from ._vm_utils import MSI_LOCAL_ID
for i, _ in enumerate(identities):
if identities[i] != MSI_LOCAL_ID:
identities[i] = _get_resource_id(cmd.cli_ctx, identities[i], namespace.resource_group_name,
'userAssignedIdentities', 'Microsoft.ManagedIdentity')
if not namespace.identity_scope and getattr(namespace.identity_role, 'is_default', None) is None:
raise CLIError("usage error: '--role {}' is not applicable as the '--scope' is not provided".format(
namespace.identity_role))
user_assigned_identities = [x for x in identities if x != MSI_LOCAL_ID]
if user_assigned_identities and not cmd.supported_api_version(min_api='2017-12-01'):
raise CLIError('usage error: user assigned identity is only available under profile '
'with minimum Compute API version of 2017-12-01')
if namespace.identity_scope:
if identities and MSI_LOCAL_ID not in identities:
raise CLIError("usage error: '--scope'/'--role' is only applicable when assign system identity")
# keep 'identity_role' for output as logical name is more readable
setattr(namespace, 'identity_role_id', _resolve_role_id(cmd.cli_ctx, namespace.identity_role,
namespace.identity_scope))
elif namespace.identity_scope or getattr(namespace.identity_role, 'is_default', None) is None:
raise CLIError('usage error: --assign-identity [--scope SCOPE] [--role ROLE]')
def _resolve_role_id(cli_ctx, role, scope):
import re
import uuid
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType
client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION).role_definitions
role_id = None
if re.match(r'/subscriptions/.+/providers/Microsoft.Authorization/roleDefinitions/',
role, re.I):
role_id = role
else:
try:
uuid.UUID(role)
role_id = '/subscriptions/{}/providers/Microsoft.Authorization/roleDefinitions/{}'.format(
client.config.subscription_id, role)
except ValueError:
pass
if not role_id: # retrieve role id
role_defs = list(client.list(scope, "roleName eq '{}'".format(role)))
if not role_defs:
raise CLIError("Role '{}' doesn't exist.".format(role))
elif len(role_defs) > 1:
ids = [r.id for r in role_defs]
err = "More than one role matches the given name '{}'. Please pick an id from '{}'"
raise CLIError(err.format(role, ids))
role_id = role_defs[0].id
return role_id
def process_vm_create_namespace(cmd, namespace):
validate_tags(namespace)
_validate_location(cmd, namespace, namespace.zone, namespace.size)
validate_asg_names_or_ids(cmd, namespace)
_validate_vm_create_storage_profile(cmd, namespace)
if namespace.storage_profile in [StorageProfile.SACustomImage,
StorageProfile.SAPirImage]:
_validate_vm_create_storage_account(cmd, namespace)
_validate_vm_create_availability_set(cmd, namespace)
_validate_vm_vmss_create_vnet(cmd, namespace)
_validate_vm_create_nsg(cmd, namespace)
_validate_vm_vmss_create_public_ip(cmd, namespace)
_validate_vm_create_nics(cmd, namespace)
_validate_vm_vmss_accelerated_networking(cmd.cli_ctx, namespace)
_validate_vm_vmss_create_auth(namespace)
if namespace.secrets:
_validate_secrets(namespace.secrets, namespace.os_type)
if namespace.license_type and namespace.os_type.lower() != 'windows':
raise CLIError('usage error: --license-type is only applicable on Windows VM')
_validate_vm_vmss_msi(cmd, namespace)
if namespace.boot_diagnostics_storage:
namespace.boot_diagnostics_storage = get_storage_blob_uri(cmd.cli_ctx, namespace.boot_diagnostics_storage)
# endregion
# region VMSS Create Validators
def _get_default_address_pool(cli_ctx, resource_group, balancer_name, balancer_type):
option_name = '--backend-pool-name'
client = getattr(get_network_client(cli_ctx), balancer_type, None)
if not client:
raise CLIError('unrecognized balancer type: {}'.format(balancer_type))
balancer = client.get(resource_group, balancer_name)
values = [x.name for x in balancer.backend_address_pools]
if len(values) > 1:
raise CLIError("Multiple possible values found for '{0}': {1}\nSpecify '{0}' "
"explicitly.".format(option_name, ', '.join(values)))
elif not values:
raise CLIError("No existing values found for '{0}'. Create one first and try "
"again.".format(option_name))
return values[0]
def _validate_vmss_single_placement_group(namespace):
if namespace.platform_fault_domain_count is not None and namespace.zones is None:
raise CLIError('usage error: --platform-fault-domain-count COUNT --zones ZONES')
if namespace.zones or namespace.instance_count > 100:
if namespace.single_placement_group is None:
namespace.single_placement_group = False
elif namespace.single_placement_group:
raise CLIError("usage error: '--single-placement-group' should be turned off for zonal scale-sets or with"
" 100+ instances")
def _validate_vmss_create_load_balancer_or_app_gateway(cmd, namespace):
from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import parse_resource_id
from azure.cli.core.profiles import ResourceType
std_lb_is_available = cmd.supported_api_version(min_api='2017-08-01', resource_type=ResourceType.MGMT_NETWORK)
if namespace.load_balancer and namespace.application_gateway:
raise CLIError('incorrect usage: --load-balancer NAME_OR_ID | '
'--application-gateway NAME_OR_ID')
# Resolve the type of balancer (if any) being used
balancer_type = 'None'
if namespace.load_balancer is None and namespace.application_gateway is None:
if std_lb_is_available:
balancer_type = 'loadBalancer'
else: # needed for Stack profile 2017_03_09
balancer_type = 'loadBalancer' if namespace.single_placement_group is not False else 'applicationGateway'
logger.debug("W/o STD LB, defaulting to '%s' under because single placement group is disabled",
balancer_type)
elif namespace.load_balancer:
balancer_type = 'loadBalancer'
elif namespace.application_gateway:
balancer_type = 'applicationGateway'
if balancer_type == 'applicationGateway':
if namespace.application_gateway:
client = get_network_client(cmd.cli_ctx).application_gateways
try:
rg = parse_resource_id(namespace.application_gateway).get(
'resource_group', namespace.resource_group_name)
ag_name = parse_resource_id(namespace.application_gateway)['name']
client.get(rg, ag_name)
namespace.app_gateway_type = 'existing'
namespace.backend_pool_name = namespace.backend_pool_name or \
_get_default_address_pool(cmd.cli_ctx, rg, ag_name, 'application_gateways')
logger.debug("using specified existing application gateway '%s'", namespace.application_gateway)
except CloudError:
namespace.app_gateway_type = 'new'
logger.debug("application gateway '%s' not found. It will be created.", namespace.application_gateway)
elif namespace.application_gateway == '':
namespace.app_gateway_type = None
logger.debug('no application gateway will be used')
elif namespace.application_gateway is None:
namespace.app_gateway_type = 'new'
logger.debug('new application gateway will be created')
# AppGateway frontend
required = []
if namespace.app_gateway_type == 'new':
required.append('app_gateway_sku')
required.append('app_gateway_capacity')
if namespace.vnet_type != 'new':
required.append('app_gateway_subnet_address_prefix')
elif namespace.app_gateway_type == 'existing':
required.append('backend_pool_name')
forbidden = ['nat_pool_name', 'load_balancer', 'health_probe']
validate_parameter_set(namespace, required, forbidden, description='network balancer: application gateway')
elif balancer_type == 'loadBalancer':
# LoadBalancer frontend
required = []
forbidden = ['app_gateway_subnet_address_prefix', 'application_gateway', 'app_gateway_sku',
'app_gateway_capacity']
validate_parameter_set(namespace, required, forbidden, description='network balancer: load balancer')
if namespace.load_balancer:
rg = parse_resource_id(namespace.load_balancer).get('resource_group', namespace.resource_group_name)
lb_name = parse_resource_id(namespace.load_balancer)['name']
lb = get_network_lb(cmd.cli_ctx, namespace.resource_group_name, lb_name)
if lb:
namespace.load_balancer_type = 'existing'
namespace.backend_pool_name = namespace.backend_pool_name or \
_get_default_address_pool(cmd.cli_ctx, rg, lb_name, 'load_balancers')
if not namespace.nat_pool_name:
if len(lb.inbound_nat_pools) > 1:
raise CLIError("Multiple possible values found for '{0}': {1}\nSpecify '{0}' explicitly.".format( # pylint: disable=line-too-long
'--nat-pool-name', ', '.join([n.name for n in lb.inbound_nat_pools])))
elif not lb.inbound_nat_pools: # Associated scaleset will be missing ssh/rdp, so warn here.
logger.warning("No inbound nat pool was configured on '%s'", namespace.load_balancer)
else:
namespace.nat_pool_name = lb.inbound_nat_pools[0].name
logger.debug("using specified existing load balancer '%s'", namespace.load_balancer)
else:
namespace.load_balancer_type = 'new'
logger.debug("load balancer '%s' not found. It will be created.", namespace.load_balancer)
elif namespace.load_balancer == '':
namespace.load_balancer_type = None
logger.debug('no load balancer will be used')
elif namespace.load_balancer is None:
namespace.load_balancer_type = 'new'
logger.debug('new load balancer will be created')
if namespace.load_balancer_type == 'new' and namespace.single_placement_group is False and std_lb_is_available:
LBSkuName = cmd.get_models('LoadBalancerSkuName', resource_type=ResourceType.MGMT_NETWORK)
if namespace.load_balancer_sku is None:
namespace.load_balancer_sku = LBSkuName.standard.value
logger.debug("use Standard sku as single placement group is turned off")
elif namespace.load_balancer_sku == LBSkuName.basic.value:
if namespace.zones:
err = "'Standard' load balancer is required for zonal scale-sets"
elif namespace.instance_count > 100:
err = "'Standard' load balancer is required for scale-sets with 100+ instances"
else:
err = "'Standard' load balancer is required because 'single placement group' is turned off"
raise CLIError('usage error:{}'.format(err))
def get_network_client(cli_ctx):
from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_NETWORK, api_version=get_target_network_api(cli_ctx))
def get_network_lb(cli_ctx, resource_group_name, lb_name):
from msrestazure.azure_exceptions import CloudError
network_client = get_network_client(cli_ctx)
try:
return network_client.load_balancers.get(resource_group_name, lb_name)
except CloudError:
return None
def process_vmss_create_namespace(cmd, namespace):
validate_tags(namespace)
if namespace.vm_sku is None:
from azure.cli.core.cloud import AZURE_US_GOV_CLOUD
if cmd.cli_ctx.cloud.name != AZURE_US_GOV_CLOUD.name:
namespace.vm_sku = 'Standard_DS1_v2'
else:
namespace.vm_sku = 'Standard_D1_v2'
_validate_location(cmd, namespace, namespace.zones, namespace.vm_sku)
validate_asg_names_or_ids(cmd, namespace)
_validate_vm_create_storage_profile(cmd, namespace, for_scale_set=True)
_validate_vm_vmss_create_vnet(cmd, namespace, for_scale_set=True)
_validate_vmss_single_placement_group(namespace)
_validate_vmss_create_load_balancer_or_app_gateway(cmd, namespace)
_validate_vmss_create_subnet(namespace)
_validate_vmss_create_public_ip(cmd, namespace)
_validate_vmss_create_nsg(cmd, namespace)
_validate_vm_vmss_accelerated_networking(cmd.cli_ctx, namespace)
_validate_vm_vmss_create_auth(namespace)
_validate_vm_vmss_msi(cmd, namespace)
if namespace.license_type and namespace.os_type.lower() != 'windows':
raise CLIError('usage error: --license-type is only applicable on Windows VM scaleset')
if not namespace.public_ip_per_vm and namespace.vm_domain_name:
raise CLIError('Usage error: --vm-domain-name can only be used when --public-ip-per-vm is enabled')
if namespace.eviction_policy and not namespace.priority:
raise CLIError('Usage error: --priority PRIORITY [--eviction-policy POLICY]')
# endregion
# region disk, snapshot, image validators
def validate_vm_disk(cmd, namespace):
namespace.disk = _get_resource_id(cmd.cli_ctx, namespace.disk,
namespace.resource_group_name, 'disks', 'Microsoft.Compute')
def validate_vmss_disk(cmd, namespace):
if namespace.disk:
namespace.disk = _get_resource_id(cmd.cli_ctx, namespace.disk,
namespace.resource_group_name, 'disks', 'Microsoft.Compute')
if bool(namespace.disk) == bool(namespace.size_gb):
raise CLIError('usage error: --disk EXIST_DISK --instance-id ID | --size-gb GB')
elif bool(namespace.disk) != bool(namespace.instance_id):
raise CLIError('usage error: --disk EXIST_DISK --instance-id ID')
def process_disk_or_snapshot_create_namespace(cmd, namespace):
from msrestazure.azure_exceptions import CloudError
validate_tags(namespace)
if namespace.source:
usage_error = 'usage error: --source {SNAPSHOT | DISK} | --source VHD_BLOB_URI [--source-storage-account-id ID]'
try:
namespace.source_blob_uri, namespace.source_disk, namespace.source_snapshot = _figure_out_storage_source(
cmd.cli_ctx, namespace.resource_group_name, namespace.source)
if not namespace.source_blob_uri and namespace.source_storage_account_id:
raise CLIError(usage_error)
except CloudError:
raise CLIError(usage_error)
def process_image_create_namespace(cmd, namespace):
from msrestazure.tools import parse_resource_id
from msrestazure.azure_exceptions import CloudError
validate_tags(namespace)
try:
# try capturing from VM, a most common scenario
res_id = _get_resource_id(cmd.cli_ctx, namespace.source, namespace.resource_group_name,
'virtualMachines', 'Microsoft.Compute')
res = parse_resource_id(res_id)
compute_client = _compute_client_factory(cmd.cli_ctx, subscription_id=res['subscription'])
vm_info = compute_client.virtual_machines.get(res['resource_group'], res['name'])
# pylint: disable=no-member
namespace.os_type = vm_info.storage_profile.os_disk.os_type.value
namespace.source_virtual_machine = res_id
if namespace.data_disk_sources:
raise CLIError("'--data-disk-sources' is not allowed when capturing "
"images from virtual machines")
except CloudError:
namespace.os_blob_uri, namespace.os_disk, namespace.os_snapshot = _figure_out_storage_source(cmd.cli_ctx, namespace.resource_group_name, namespace.source) # pylint: disable=line-too-long
namespace.data_blob_uris = []
namespace.data_disks = []
namespace.data_snapshots = []
if namespace.data_disk_sources:
for data_disk_source in namespace.data_disk_sources:
source_blob_uri, source_disk, source_snapshot = _figure_out_storage_source(
cmd.cli_ctx, namespace.resource_group_name, data_disk_source)
if source_blob_uri:
namespace.data_blob_uris.append(source_blob_uri)
if source_disk:
namespace.data_disks.append(source_disk)
if source_snapshot:
namespace.data_snapshots.append(source_snapshot)
if not namespace.os_type:
raise CLIError("usage error: os type is required to create the image, "
"please specify '--os-type OS_TYPE'")
def _figure_out_storage_source(cli_ctx, resource_group_name, source):
from msrestazure.azure_exceptions import CloudError
source_blob_uri = None
source_disk = None
source_snapshot = None
if urlparse(source).scheme: # a uri?
source_blob_uri = source
elif '/disks/' in source.lower():
source_disk = source
elif '/snapshots/' in source.lower():
source_snapshot = source
else:
compute_client = _compute_client_factory(cli_ctx)
# pylint: disable=no-member
try:
info = compute_client.snapshots.get(resource_group_name, source)
source_snapshot = info.id
except CloudError:
info = compute_client.disks.get(resource_group_name, source)
source_disk = info.id
return (source_blob_uri, source_disk, source_snapshot)
def process_disk_encryption_namespace(cmd, namespace):
namespace.disk_encryption_keyvault = _get_resource_id(cmd.cli_ctx, namespace.disk_encryption_keyvault,
namespace.resource_group_name,
'vaults', 'Microsoft.KeyVault')
if namespace.key_encryption_keyvault:
if not namespace.key_encryption_key:
raise CLIError("Incorrect usage '--key-encryption-keyvault': "
"'--key-encryption-key' is required")
namespace.key_encryption_keyvault = _get_resource_id(cmd.cli_ctx, namespace.key_encryption_keyvault,
namespace.resource_group_name,
'vaults', 'Microsoft.KeyVault')
def process_assign_identity_namespace(cmd, namespace):
_validate_vm_vmss_msi(cmd, namespace, from_set_command=True)
def process_remove_identity_namespace(cmd, namespace):
if namespace.identities:
from ._vm_utils import MSI_LOCAL_ID
for i in range(len(namespace.identities)):
if namespace.identities[i] != MSI_LOCAL_ID:
namespace.identities[i] = _get_resource_id(cmd.cli_ctx, namespace.identities[i],
namespace.resource_group_name,
'userAssignedIdentities',
'Microsoft.ManagedIdentity')
# TODO move to its own command module https://github.com/Azure/azure-cli/issues/5105
def process_msi_namespace(cmd, namespace):
get_default_location_from_resource_group(cmd, namespace)
validate_tags(namespace)
def process_gallery_image_version_namespace(cmd, namespace):
TargetRegion = cmd.get_models('TargetRegion')
if namespace.target_regions:
regions_info = []
for t in namespace.target_regions:
parts = t.split('=', 1)
if len(parts) == 1:
regions_info.append(TargetRegion(name=parts[0]))
else:
try:
replica_count = int(parts[1])
except ValueError:
raise CLIError("usage error: {}'s replica count must be an integer".format(parts[0]))
regions_info.append(TargetRegion(name=parts[0], regional_replica_count=replica_count))
namespace.target_regions = regions_info
# endregion
| 50.486466 | 195 | 0.655949 | 1 | 1.8021 | [
-0.01470201089978218,
0.03191690519452095,
-0.01709648407995701,
0.026368578895926476,
0.0023603562731295824,
0.037751130759716034,
-0.059359822422266006,
0.01716061681509018,
0.020748816430568695,
0.02898680604994297,
0.02308676391839981,
-0.018105398863554,
0.016944557428359985,
-0.027337748557329178,
0.0413944236934185,
0.028965016826987267,
0.0669686570763588,
-0.018912499770522118,
0.020096430554986,
-0.029597442597150803,
-0.002034999430179596,
0.0073470426723361015,
-0.022237975150346756,
-0.0018548968946561217,
0.01960134692490101,
0.013551921583712101,
0.016057686880230904,
-0.006359984166920185,
0.013898693025112152,
-0.0023310482501983643,
-0.03930576518177986,
0.008388357236981392,
0.023461030796170235,
-0.0007877784664742649,
-0.036370377987623215,
0.006476893089711666,
0.005053251516073942,
-0.07209233194589615,
0.026561059057712555,
0.014450403861701488,
-0.02914612740278244,
-0.018764041364192963,
-0.010514896363019943,
0.0055243950337171555,
0.0972275659441948,
0.033618148416280746,
-0.029536936432123184,
-0.01649913378059864,
-0.060422878712415695,
0.00014230709348339587,
-0.07161755859851837,
0.005571885034441948,
0.011904530227184296,
-0.011381993070244789,
-0.010869408957660198,
-0.01957353577017784,
0.013071299530565739,
0.06872895359992981,
-0.04406552389264107,
0.0010599131928756833,
0.0041595324873924255,
-0.007154729682952166,
0.04447754845023155,
0.010611269623041153,
0.011686229147017002,
0.002085495973005891,
0.03587734326720238,
0.003187444992363453,
-0.014041606336832047,
-0.03035550005733967,
-0.008282014168798923,
-0.006435088347643614,
0.042991556227207184,
0.06436184048652649,
0.0030746597331017256,
-0.03237449377775192,
-0.044254738837480545,
-0.01889685168862343,
-0.0287918783724308,
0.00732176098972559,
-0.022158071398735046,
0.08921636641025543,
0.014757086522877216,
-0.03922038897871971,
0.03312688320875168,
0.00338077824562788,
0.042655546218156815,
-0.0903790146112442,
0.02709551341831684,
-0.003985573537647724,
-0.03405759483575821,
-0.02227727323770523,
-0.06635386496782303,
0.02648419700562954,
-0.03192614018917084,
-0.016024895012378693,
0.01940818876028061,
0.0063208467327058315,
0.00035733505501411855,
0.003081581788137555,
-0.02922089211642742,
-0.03320083022117615,
0.01598917506635189,
0.0004829273384530097,
0.03353722393512726,
-0.019404051825404167,
-0.06556807458400726,
-0.028254861012101173,
0.0034679886884987354,
-0.04419625177979469,
-0.0035283442120999098,
0.042551036924123764,
0.0288819782435894,
-0.0501965768635273,
-0.0037021394819021225,
-0.03820883110165596,
-0.000833715486805886,
0.03307010233402252,
-0.01369063463062048,
0.03489246591925621,
0.0073519982397556305,
-0.004984681028872728,
-0.008999848738312721,
-0.01412014476954937,
-0.01142470445483923,
0.09336960315704346,
-0.017259519547224045,
0.0011399849317967892,
-0.010573494248092175,
0.04276643693447113,
0.004378332290798426,
-0.0010223959106951952,
-0.06252841651439667,
0.017185626551508904,
0.025899600237607956,
0.0148816192522645,
0.011175457388162613,
0.012234047055244446,
-0.06585077196359634,
0.009563597850501537,
-0.049443069845438004,
-0.01052824966609478,
0.004340264946222305,
0.006109314039349556,
-0.03393705561757088,
-0.07206845283508301,
0.00014952114725019783,
-0.04602685198187828,
-0.019026707857847214,
-0.019133824855089188,
0.004611104726791382,
-0.00925010908395052,
0.014025725424289703,
-0.017170093953609467,
-0.014682460576295853,
0.010598849505186081,
-0.04193209111690521,
0.014560815878212452,
-0.03454744070768356,
0.03346142917871475,
-0.008584735915064812,
0.02193565107882023,
0.007845396175980568,
0.005054221022874117,
0.01846294477581978,
0.028043407946825027,
-0.033689726144075394,
0.06496108323335648,
-0.001959211425855756,
-0.03431656211614609,
0.0006288995500653982,
0.0008088225731626153,
-0.0031792870722711086,
0.026779282838106155,
-0.04007411748170853,
-0.003714059479534626,
0.05693524330854416,
0.040013886988162994,
-0.0043150149285793304,
-0.04066260904073715,
0.024262020364403725,
-0.044161222875118256,
0.06666408479213715,
0.03310550004243851,
-0.014249460771679878,
-0.03552163392305374,
0.0010416340082883835,
-0.03178783133625984,
0.014526035636663437,
0.006643917877227068,
-0.04313183203339577,
0.0025863328482955694,
-0.0615694485604763,
-0.021754777058959007,
0.02870814874768257,
0.0023235075641423464,
-0.06530211120843887,
0.0076590124517679214,
0.03246486186981201,
0.039938125759363174,
-0.010243690572679043,
-0.023692751303315163,
-0.03249858319759369,
-0.00830167531967163,
0.01406877115368843,
0.0012957016006112099,
-0.5792970657348633,
0.05914581939578056,
0.026646777987480164,
-0.014861224219202995,
0.027233684435486794,
0.027857236564159393,
0.047671083360910416,
0.020744703710079193,
-0.0018723872490227222,
-0.000020050354578415863,
-0.0003731467295438051,
0.009878038428723812,
-0.02438366785645485,
-0.014517616480588913,
-0.005899820011109114,
0.04135840758681297,
0.008009597659111023,
-0.040715016424655914,
-0.02944660559296608,
0.01644301787018776,
0.03196721524000168,
-0.06775964796543121,
-0.02088051848113537,
0.02133205533027649,
-0.003978952299803495,
-0.02624450996518135,
0.016565553843975067,
0.043332409113645554,
-0.022658715024590492,
-0.022381069138646126,
-0.008540804497897625,
-0.04157041758298874,
0.027203360572457314,
-0.024337010458111763,
-0.019888486713171005,
0.03611501306295395,
0.01493009738624096,
-0.042291443794965744,
-0.024259475991129875,
0.020827867090702057,
-0.02511724829673767,
-0.001440137973986566,
-0.010984604246914387,
-0.07239356637001038,
-0.01480160839855671,
0.0071202609688043594,
0.01784140057861805,
-0.003930533770471811,
0.04943491518497467,
0.003505671862512827,
-0.011806982569396496,
0.022333189845085144,
0.02166302315890789,
-0.017480093985795975,
-0.024487389251589775,
-0.01907218247652054,
-0.025115670636296272,
0.013924075290560722,
0.01239099819213152,
-0.0018474322278052568,
-0.030799400061368942,
-0.026405202224850655,
-0.006396854296326637,
0.03174833208322525,
0.021981926634907722,
-0.00826200656592846,
0.06804997473955154,
-0.03146139904856682,
-0.04578571021556854,
0.03032134659588337,
-0.05069498345255852,
-0.006201290991157293,
-0.016898954287171364,
-0.009914224036037922,
0.03146015480160713,
0.0492878258228302,
-0.02980929985642433,
0.003420487279072404,
-0.06535343080759048,
-0.04231429845094681,
0.00993832666426897,
-0.03712911158800125,
0.017766384407877922,
0.005666854791343212,
-0.0044260709546506405,
-0.05316251143813133,
-0.002697573509067297,
-0.005073054693639278,
-0.021783975884318352,
0.025932596996426582,
0.03292834013700485,
0.0075262608006596565,
-0.011912664398550987,
0.038872476667165756,
-0.0003615124151110649,
0.034855421632528305,
-0.012387715280056,
0.03548581898212433,
-0.00716810068115592,
-0.003990244120359421,
-0.012628419324755669,
-0.006668800488114357,
-0.00637404341250658,
0.021633028984069824,
0.0024368183221668005,
-0.022417433559894562,
-0.06385666877031326,
-0.012460200116038322,
0.010834937915205956,
-0.0055629960261285305,
0.02074585109949112,
-0.007603274658322334,
-0.007628079503774643,
0.05644319951534271,
-0.06091595068573952,
-0.0067038824781775475,
-0.0041232299990952015,
-0.04638517275452614,
0.02557213418185711,
-0.011683893389999866,
-0.0003049040969926864,
0.017882399260997772,
-0.02086937054991722,
0.024852462112903595,
-0.006925771478563547,
0.009054053574800491,
-0.005747868213802576,
-0.01616487465798855,
0.018582655116915703,
-0.0422239750623703,
-0.05780375376343727,
-0.0007986471755430102,
0.03581027314066887,
0.013898663222789764,
-0.012838060967624187,
0.0013117800699546933,
-0.028151601552963257,
-0.0034672843758016825,
0.027823537588119507,
0.0002718498872127384,
-0.036782748997211456,
-0.017061607912182808,
0.043152857571840286,
-0.03894759342074394,
0.004111612681299448,
0.03687438741326332,
0.02475736476480961,
-0.0062112160958349705,
-0.03461311757564545,
0.022843588143587112,
0.015942638739943504,
0.0010357688879594207,
-0.008124351501464844,
0.0032169653568416834,
-0.01247526053339243,
0.03108931891620159,
-0.0293210968375206,
0.03827488794922829,
0.018720168620347977,
0.033780504018068314,
0.011014791205525398,
-0.024135634303092957,
0.05053895711898804,
0.00790292490273714,
0.00949978269636631,
0.002786453813314438,
0.0007930477149784565,
0.05732361599802971,
-0.0018836931558325887,
0.02522864006459713,
0.015796339139342308,
-0.00792138371616602,
0.04457603022456169,
0.02947358787059784,
0.0018472610972821712,
0.005002222955226898,
0.015248540788888931,
-0.042689334601163864,
-0.002915148390457034,
-0.03272148221731186,
-0.01261233165860176,
-0.0326090008020401,
0.006152074318379164,
0.01856875792145729,
0.013654529117047787,
-0.02010934427380562,
-0.028360562399029732,
0.008206995204091072,
0.01233628299087286,
-0.052934642881155014,
0.009140792302787304,
0.061251357197761536,
0.0074531263671815395,
-0.03270311281085014,
-0.05260497331619263,
-0.05219411849975586,
0.011008176021277905,
-0.034793078899383545,
0.003296332433819771,
-0.02596011944115162,
0.000608433794695884,
-0.006785560864955187,
-0.009215878322720528,
0.016912072896957397,
0.03405125066637993,
0.06658588349819183,
0.01357630267739296,
0.03175054490566254,
-0.006824306678026915,
0.024433942511677742,
0.002147912047803402,
-0.01665184460580349,
0.013964684680104256,
0.012183665297925472,
-0.0120063666254282,
0.06651461124420166,
-0.02835237607359886,
-0.038525793701410294,
0.01738598756492138,
-0.01604320853948593,
-0.036309268325567245,
-0.03380505368113518,
0.0273850429803133,
0.009398793801665306,
-0.008308002725243568,
-0.0371231809258461,
-0.0490751788020134,
0.04943663999438286,
-0.010268455371260643,
0.021035948768258095,
0.014064626768231392,
0.02053462527692318,
0.042727869004011154,
-0.018460385501384735,
-0.0459514781832695,
0.017636975273489952,
-0.022747626528143883,
-0.03885255008935928,
0.016545765101909637,
0.010730701498687267,
0.024174369871616364,
-0.013052759692072868,
0.018290221691131592,
0.004635573364794254,
-0.03256477415561676,
0.0048344917595386505,
-0.026472635567188263,
-0.058117371052503586,
-0.006383469328284264,
0.01489184983074665,
-0.008615758270025253,
0.03200018033385277,
0.04595078155398369,
-0.041626933962106705,
0.019062910228967667,
-0.024916386231780052,
-0.015267898328602314,
-0.010175877250730991,
0.039290204644203186,
-0.0030383451376110315,
-0.026249991729855537,
-0.06896776705980301,
0.04039081558585167,
0.04003192111849785,
-0.010944263078272343,
0.04467475041747093,
-0.012114692479372025,
-0.04573623090982437,
-0.00819474458694458,
0.017825720831751823,
0.017375636845827103,
-0.003725194139406085,
0.00684365862980485,
0.0469994992017746,
0.04669594392180443,
-0.001802820130251348,
-0.01633431948721409,
-0.049772005528211594,
0.00820592138916254,
0.012076297774910927,
0.010344033129513264,
-0.03159245848655701,
0.04086364433169365,
0.00342586450278759,
0.008274335414171219,
-0.0006871145451441407,
0.029120128601789474,
-0.0017077106749638915,
-0.06375978142023087,
0.001366115058772266,
0.02587234228849411,
-0.010240407660603523,
0.04016412794589996,
0.003772756550461054,
0.011838052421808243,
0.012984635308384895,
-0.014628308825194836,
0.005885779391974211,
0.008071525022387505,
0.014252603985369205,
0.017463982105255127,
0.02558514103293419,
-0.046262726187705994,
0.012363404035568237,
0.0031374767422676086,
0.012046637944877148,
0.011528917588293552,
-0.01040577981621027,
0.033461663872003555,
0.014722897671163082,
-0.011593990959227085,
0.02862951159477234,
0.015014152973890305,
-0.026453876867890358,
-0.036392442882061005,
0.014429453760385513,
0.04846090078353882,
-0.01076576579362154,
0.002570767654106021,
0.015807343646883965,
-0.009847020730376244,
0.01470948290079832,
-0.022854002192616463,
0.0019415634451434016,
-0.009321408346295357,
-0.0325581319630146,
-0.029698826372623444,
-0.03927547112107277,
0.020513398572802544,
0.04508840665221214,
0.03645384684205055,
-0.056855637580156326,
-0.022716643288731575,
-0.022282959893345833,
-0.030383683741092682,
-0.007519099395722151,
0.014209930785000324,
-0.005668674595654011,
0.024359935894608498,
-0.008163383230566978,
-0.02566937729716301,
0.02863982878625393,
-0.03872932866215706,
-0.07713890075683594,
0.038347065448760986,
0.0030486504547297955,
0.04133601486682892,
-0.020403064787387848,
0.07220051437616348,
0.019769418984651566,
0.04332142323255539,
0.017362654209136963,
-0.01108735054731369,
-0.00607173889875412,
0.0042793345637619495,
-0.004877831321209669,
-0.009563766419887543,
0.004700977820903063,
-0.00843772105872631,
0.02638676017522812,
-0.0020598655100911856,
-0.009360872209072113,
0.02478882111608982,
0.01504563819617033,
-0.01499286200851202,
-0.013171317987143993,
0.009330988861620426,
0.017104867845773697,
-0.013863042928278446,
0.007142768241465092,
0.00639792624861002,
-0.02046169340610504,
-0.01588340848684311,
0.0297701396048069,
0.028777630999684334,
0.03966711089015007,
0.0052089998498559,
-0.043759677559137344,
-0.003039444563910365,
0.027151210233569145,
-0.007531374227255583,
-0.011659703217446804,
-0.014150312170386314,
0.015978820621967316,
0.010689440183341503,
-0.005830789916217327,
-0.009920823387801647,
0.020102811977267265,
-0.028126366436481476,
-0.035518158227205276,
0.02041837014257908,
-0.051844969391822815,
0.018073927611112595,
0.02705349214375019,
-0.02418149821460247,
-0.013624309562146664,
-0.012707014568150043,
-0.020693760365247726,
-0.018035193905234337,
-0.008308719843626022,
0.003544539911672473,
0.012934011407196522,
0.0038209157064557076,
-0.0030371921602636576,
0.032055582851171494,
-0.07619836181402206,
0.02562152035534382,
0.008733228780329227,
0.0001693014201009646,
0.06253663450479507,
0.02490098401904106,
-0.02179318107664585,
0.010473567061126232,
-0.04690144956111908,
0.015489661134779453,
0.030154451727867126,
0.00866276677697897,
0.001411527395248413,
-0.025482771918177605,
-0.009114759974181652,
-0.08143913000822067,
-0.017924198880791664,
0.005782661959528923,
-0.004991583526134491,
0.008128141053020954,
0.005029423628002405,
-0.008462488651275635,
0.005155570339411497,
0.032594405114650726,
0.007088428363204002,
0.015169401653110981,
0.006216413341462612,
-0.027223816141486168,
0.0099587831646204,
0.03437560424208641,
-0.017675353214144707,
0.010233422741293907,
0.008587691932916641,
-0.011769919656217098,
-0.03153067082166672,
-0.03948984295129776,
-0.012441324070096016,
-0.013014033436775208,
0.021151460707187653,
0.053670741617679596,
-0.0929998829960823,
0.02101983316242695,
-0.027640020474791527,
-0.021204911172389984,
-0.04817551001906395,
0.00021228253899607807,
0.014630417339503765,
0.06962863355875015,
0.027280496433377266,
0.010509412735700607,
-0.020284611731767654,
0.017616484314203262,
0.026731951162219048,
0.022416967898607254,
0.022766564041376114,
0.04080573096871376,
0.0009114338899962604,
0.009842419996857643,
0.02405649796128273,
0.028741657733917236,
0.02817460708320141,
0.01954738423228264,
-0.023116718977689743,
0.03592055290937424,
0.03486689180135727,
-0.011591272428631783,
0.025916937738656998,
-0.01502373069524765,
-0.007936800830066204,
0.06904440373182297,
0.01569470576941967,
-0.030299993231892586,
-0.004136952105909586,
0.0526442751288414,
0.026268593966960907,
-0.05469324439764023,
-0.008253155276179314,
-0.008973677642643452,
-0.0055212113074958324,
0.034812163561582565,
0.03708147630095482,
0.0032924655824899673,
0.014684037305414677,
0.0022104186937212944,
0.028250664472579956,
-0.028857706114649773,
-0.06191164255142212,
-0.017857791855931282,
-0.03164215758442879,
0.016770048066973686,
-0.019880373030900955,
0.02272391878068447,
-0.013497645035386086,
0.04918654263019562,
-0.04447156935930252,
-0.018788140267133713,
-0.009688942693173885,
0.02913319319486618,
-0.034707169979810715,
0.024294542148709297,
0.03197520598769188,
0.07408227771520615,
0.05061757564544678,
0.017594490200281143,
-0.0006129299872554839,
-0.017554746940732002,
-0.021422695368528366,
-0.021758878603577614,
-0.0036343284882605076,
0.024904532358050346,
0.007145572453737259,
0.06299111992120743,
-0.08546682447195053,
-0.002531131962314248,
-0.013099808245897293,
0.02320263534784317,
-0.024031922221183777,
-0.0027559339068830013,
0.014709943905472755,
-0.007883456535637379,
0.015450803562998772,
-0.03578773885965347,
-0.01753685623407364,
0.03053852915763855,
0.012215061113238335,
0.021597953513264656,
0.009374089539051056,
-0.014189684763550758,
0.026913708075881004,
-0.009515436366200447,
-0.0590890608727932,
0.03313338756561279,
0.029434828087687492,
-0.04454151913523674,
-0.040455859154462814,
0.03826555982232094,
-0.008709843270480633,
-0.01535683311522007,
-0.03793486952781677,
0.0035830093547701836,
-0.006857811938971281,
-0.003972361329942942,
-0.020283358171582222,
0.03512732684612274,
-0.03615985065698624,
-0.045793771743774414,
0.048446252942085266,
0.0010114731267094612,
0.020507875829935074,
-0.05016811564564705,
-0.028089171275496483,
-0.0029692070093005896,
0.05662296339869499,
-0.049173157662153244,
-0.05576470494270325,
-0.04114080220460892,
-0.0030299178324639797
] |
8a41876d28109b10beeda61ce63d0fb68903a3e0 | 4,091 | py | Python | scraping/faqscraper.py | ednihs-yahska/unibrowser | c91aaf7df8b316c707e5a268f82e789615be9fb8 | [
"Apache-2.0"
] | null | null | null | scraping/faqscraper.py | ednihs-yahska/unibrowser | c91aaf7df8b316c707e5a268f82e789615be9fb8 | [
"Apache-2.0"
] | null | null | null | scraping/faqscraper.py | ednihs-yahska/unibrowser | c91aaf7df8b316c707e5a268f82e789615be9fb8 | [
"Apache-2.0"
] | null | null | null | import re
import httplib2
from bs4 import BeautifulSoup
from scraping.faqscrapperutil import stripExtra, removeDuplicates, removeBlackListedQuestions, getBlackListedQuestions, convertToJsonList, saveToMongo
from scraping.Constants import ENABLE_CUSTOM_QUESTIONS_FILTER, FAQ_LINKS, COLLECTION_NAME
def cleanQuestions(questions):
questionList = []
for question in questions:
questionList.append(stripExtra(question.lstrip().rstrip()))
return removeDuplicates(questionList)
def getLastAnswer(question, bodyText):
start = bodyText.index(question) + len(question)
text = bodyText[start : -1].lstrip()
# print(text.lstrip())
whitespaceCount = 0
# print(answerLength)
for i in range(0, len(text)):
# print(answer[i], ' isSpace : ', answer[i].isspace())
if text[i].isspace():
whitespaceCount = whitespaceCount + 1
if whitespaceCount >= 3:
# print(0 + i - 3)
# print(text[0 : 0 + i - 2])
return text[0 : 0 + i - 2]
else :
if whitespaceCount != 0:
whitespaceCount = 0
def cleanAnswer(answer):
answerLength = len(answer)
whitespaceCount = 0
# print(answerLength)
for i in range(0, answerLength):
# print(answer[i], ' isSpace : ', answer[i].isspace())
if answer[i].isspace():
whitespaceCount = whitespaceCount + 1
if whitespaceCount >= 3:
# print(0 + i - 3)
return answer[0 : 0 + i - 2].lstrip()
else :
if whitespaceCount != 0:
whitespaceCount = 0
return answer.rstrip()
def getAnswers(body, questions):
bodyText = body.getText()
# answerTag = getAnswerTag(body, bodyText, questions)
# print(bodyText)
questionCount = len(questions)
answerList = []
for i in range(0, questionCount):
print('Q: ', questions[i])
if i == questionCount - 1:
#Last element
answer = getLastAnswer(questions[i], bodyText)
else :
start = bodyText.index(questions[i]) + len(questions[i])
end = bodyText.index(questions[i + 1], start, -1)
print("Start : ", start , " End : ", end)
soup1 = BeautifulSoup(bodyText[start : end], 'html.parser')
# print(soup1)
answer = soup1.getText().lstrip()
answer = cleanAnswer(answer)
answerList.append(answer)
print('A: ', answer)
return answerList
def processWithCustomQuestions(questions):
# isCustomQuestionsEnabled = checkConfigForFlag(ENABLE_CUSTOM_QUESTIONS_FILTER)
# print("isCustomQuestionsEnabled : ", isCustomQuestionsEnabled)
if ENABLE_CUSTOM_QUESTIONS_FILTER == False:
return
blackListedQuestions = getBlackListedQuestions()
removeBlackListedQuestions(questions, blackListedQuestions)
print(questions)
def getFaqOfLink(link):
# print("LINK : ", link)
http = httplib2.Http()
status, html = http.request(link)
soup = BeautifulSoup(html, 'html.parser')
body = soup.body
questions = cleanQuestions(soup(text=re.compile(r'\s*((?:how|How|Can|can|what|What|where|Where|describe|Describe|Who|who|When|when|Why|why|Should|should|is|Is|I|Do|do|Are|are|Will|will)[^.<>?]*?\s*\?)')))
# print(questions)
processWithCustomQuestions(questions)
answerList = getAnswers(body, questions)
return questions, answerList
# link = "https://transportation.oregonstate.edu/aabc/frequently-asked-questions"
# questions, answerList = getFaqOfLink(link)
if __name__== "__main__":
with open(FAQ_LINKS, 'r') as myfile:
FAQ_LINKS = myfile.read().split('\n')
faqJsonList = []
for i in range(0, len(FAQ_LINKS)):
link = FAQ_LINKS[i]
questions, answerList = getFaqOfLink(link)
jsonList = convertToJsonList(link, questions, answerList)
faqJsonList.extend(jsonList)
# saveJsonToFile(faqJsonList, "output.txt")
saveToMongo(faqJsonList, COLLECTION_NAME) | 36.855856 | 208 | 0.633341 | 1 | 2.1351 | [
-0.014402436092495918,
0.018986403942108154,
0.017861083149909973,
0.050155431032180786,
-0.0229999627918005,
-0.01608320139348507,
-0.006865822244435549,
0.015196283347904682,
-0.01943553239107132,
0.021755751222372055,
-0.016336916014552116,
0.0015698823845013976,
-0.005693504586815834,
-0.02295907773077488,
0.006808870937675238,
0.014545891433954239,
-0.004233228042721748,
0.011141469702124596,
0.02320496179163456,
0.019811296835541725,
0.013462502509355545,
0.012662741355597973,
-0.006661766674369574,
-0.024261148646473885,
-0.007722025271505117,
0.008248582482337952,
-0.037891581654548645,
-0.005325983744114637,
0.0063196392729878426,
-0.01667325384914875,
0.017398348078131676,
-0.05484563857316971,
-0.0050046406686306,
0.032270051538944244,
-0.039042819291353226,
-0.02619200199842453,
-0.009362160228192806,
-0.028062710538506508,
-0.009919015690684319,
0.03438825160264969,
-0.0006827139295637608,
0.016652073711156845,
-0.018392110243439674,
0.002896735677495599,
0.001962689682841301,
0.00481267599388957,
0.002399037592113018,
-0.017137693241238594,
0.017221946269273758,
0.022236870601773262,
0.005916283465921879,
-0.024162981659173965,
-0.00792573019862175,
-0.008662702515721321,
-0.006506392732262611,
0.0037993532605469227,
-0.0329078733921051,
0.023942911997437477,
-0.0007565350388176739,
0.016266310587525368,
-0.0075977398082613945,
-0.026598578318953514,
-0.023973863571882248,
-0.011682288721203804,
0.009769012220203876,
-0.030744411051273346,
0.021251041442155838,
0.011125647462904453,
-0.06741229444742203,
-0.02177722007036209,
0.010954385623335838,
0.0007603724370710552,
-0.008618757128715515,
0.03970525041222572,
-0.011131051927804947,
0.030430084094405174,
-0.010236424393951893,
0.04188254103064537,
-0.020438149571418762,
0.04288516566157341,
0.0206826813519001,
0.012665682472288609,
-0.010480459779500961,
-0.011680064722895622,
-0.010889001190662384,
-0.02142537198960781,
0.026405926793813705,
-0.007400860544294119,
0.01838437281548977,
0.016128085553646088,
-0.014490378089249134,
0.03753138706088066,
-0.011424713768064976,
-0.004235299304127693,
-0.02225830964744091,
-0.08852948993444443,
-0.00950131006538868,
0.0028993291780352592,
0.0327480174601078,
0.028363186866044998,
0.03468978777527809,
-0.0017123441211879253,
-0.03369329497218132,
-0.024916406720876694,
0.029418623074889183,
-0.024388572201132774,
0.03842047601938248,
-0.0052663059905171394,
0.019834956154227257,
0.0074108499102294445,
-0.028664208948612213,
-0.014180866070091724,
0.043215349316596985,
-0.020720064640045166,
-0.039341263473033905,
0.021648315712809563,
-0.019612442702054977,
-0.027795640751719475,
-0.03616159409284592,
0.05811592936515808,
0.0021962353494018316,
-0.013459177687764168,
0.00027567692450247705,
-0.000565810187254101,
0.0037273583002388477,
0.04200218245387077,
0.017239484935998917,
-0.037098221480846405,
-0.0012548428494483232,
-0.008695533499121666,
0.030000975355505943,
-0.06346216797828674,
0.014578740112483501,
-0.017491355538368225,
-0.04014525189995766,
0.02209155634045601,
0.004980166908353567,
-0.002556178718805313,
-0.010512393899261951,
0.013902293518185616,
0.031332727521657944,
0.010700471699237823,
-0.00009989940735977143,
0.0044639827683568,
0.01855730451643467,
-0.02125745825469494,
-0.017188536003232002,
0.0019077165052294731,
-0.022332679480314255,
-0.011094107292592525,
0.019095076248049736,
-0.032572004944086075,
0.005841570906341076,
0.002395970281213522,
0.0027255669701844454,
0.004312103148549795,
-0.005499572027474642,
0.0077076321467757225,
-0.011082523502409458,
-0.0029994905926287174,
-0.011676373891532421,
0.0072910236194729805,
0.005708873271942139,
-0.01775962859392166,
-0.020161665976047516,
-0.037127211689949036,
-0.0056875767186284065,
0.01691153459250927,
-0.018496304750442505,
0.04232952371239662,
0.011328758671879768,
0.0285818949341774,
-0.010747016407549381,
-0.009910929016768932,
-0.058863744139671326,
0.01761113479733467,
0.0037153898738324642,
0.008063464425504208,
-0.019784780219197273,
0.024366319179534912,
-0.00027518553542904556,
-0.008190195076167583,
0.0400177463889122,
-0.007337702438235283,
-0.017283551394939423,
-0.04430072009563446,
-0.015336633659899235,
0.014239405281841755,
0.016109250485897064,
-0.0007782161701470613,
0.004871136508882046,
0.013298322446644306,
0.015504791401326656,
-0.02518429607152939,
0.03183399513363838,
-0.02445661835372448,
-0.057303156703710556,
0.023893725126981735,
-0.016634440049529076,
-0.008052503690123558,
0.0012416536919772625,
-0.020510096102952957,
-0.009476597420871258,
0.06729752570390701,
0.02099747024476528,
0.005258246790617704,
-0.7705079913139343,
0.0190750602632761,
0.00997165497392416,
0.00588478147983551,
0.01475527137517929,
0.027509409934282303,
0.022056205198168755,
0.005014100112020969,
-0.07484692335128784,
-0.05227360129356384,
0.0014209954533725977,
0.005948214326053858,
-0.03337046131491661,
0.01334747951477766,
0.04269573464989662,
0.0014938083477318287,
-0.008826167322695255,
-0.0497441403567791,
0.015805678442120552,
0.002596548292785883,
0.020499614998698235,
-0.014021323062479496,
0.020608646795153618,
-0.0000949492387007922,
-0.011415108107030392,
0.04336733743548393,
0.01465364545583725,
-0.014603085815906525,
-0.016575738787651062,
-0.037764593958854675,
-0.001117012812756002,
0.005063424818217754,
-0.008278066292405128,
0.01047017052769661,
-0.022082023322582245,
-0.00470071192830801,
-0.02623712457716465,
-0.01501084491610527,
-0.008332169614732265,
0.013810625299811363,
0.0012791042681783438,
-0.03132401779294014,
-0.021914556622505188,
-0.009443909861147404,
-0.0366022028028965,
-0.019653216004371643,
-0.04783419147133827,
-0.03685007616877556,
-0.0322532132267952,
0.033566322177648544,
-0.022357862442731857,
0.01741747558116913,
0.004976642783731222,
-0.0045797680504620075,
0.00380185479298234,
0.00952951330691576,
-0.031851332634687424,
-0.0280834399163723,
-0.012805533595383167,
-0.03680838271975517,
-0.02966538444161415,
-0.00965912826359272,
0.011362096294760704,
-0.015308436937630177,
-0.012335014529526234,
-0.0007353523978963494,
0.05147131532430649,
0.02854047529399395,
0.020255940034985542,
0.030435848981142044,
0.018722496926784515,
0.00005296974995872006,
0.014547091908752918,
-0.05319294333457947,
-0.03769326210021973,
0.03479601442813873,
-0.004475719761103392,
-0.01658139005303383,
-0.038325563073158264,
-0.01860865391790867,
0.013251334428787231,
-0.010396916419267654,
-0.004358001984655857,
-0.012714001350104809,
0.006420145742595196,
0.01722676493227482,
-0.01795302890241146,
-0.005766464397311211,
0.016859032213687897,
0.00460868701338768,
0.004177884664386511,
0.03201737254858017,
0.03383644297719002,
-0.0025239759124815464,
-0.012787377461791039,
0.06650730222463608,
0.036047544330358505,
0.038572292774915695,
-0.018489770591259003,
0.005755402147769928,
-0.005517930723726749,
0.015059737488627434,
-0.002776829292997718,
0.024596484377980232,
-0.01383032277226448,
-0.022526316344738007,
-0.011192216537892818,
0.009149781428277493,
0.01802745833992958,
-0.0466519258916378,
-0.02233993634581566,
-0.00855154450982809,
0.011048171669244766,
-0.0026393537409603596,
0.010556229390203953,
-0.006420698948204517,
0.019502989947795868,
-0.023679424077272415,
0.024564184248447418,
0.007440788205713034,
0.001845558057539165,
0.005327313672751188,
-0.013914281502366066,
0.027246646583080292,
-0.033482085913419724,
-0.011332417838275433,
-0.03342220187187195,
-0.0019823703914880753,
0.0020181797444820404,
-0.011961462907493114,
0.01285182498395443,
-0.007362063974142075,
-0.027916740626096725,
0.03794677555561066,
-0.01953345164656639,
-0.005975660402327776,
0.013673597015440464,
0.01323587354272604,
0.008470948785543442,
-0.017123395577073097,
-0.024358244612812996,
-0.0020162579603493214,
0.0016648117452859879,
-0.037472691386938095,
0.01278070267289877,
0.02862749807536602,
-0.031823527067899704,
-0.05895356833934784,
-0.006428795401006937,
0.04876429960131645,
0.0022987709380686283,
-0.0028561593499034643,
0.020728150382637978,
0.00693765701726079,
-0.0040711332112550735,
0.01700582541525364,
-0.04780208691954613,
0.009439930319786072,
0.02013157494366169,
0.029147405177354813,
-0.03642253205180168,
0.0061195529997348785,
0.02422206662595272,
0.024089373648166656,
-0.011224618181586266,
-0.00828179344534874,
0.004878264851868153,
0.0045594340190291405,
0.019560471177101135,
0.018994271755218506,
0.05042272061109543,
0.03259262815117836,
0.014026999473571777,
-0.013686075806617737,
0.004712232854217291,
-0.005797687917947769,
-0.0114215649664402,
-0.03516804054379463,
-0.007331058848649263,
0.019803043454885483,
-0.002531711244955659,
0.02213699370622635,
-0.001398125197738409,
0.01675795577466488,
-0.019898055121302605,
-0.012735302560031414,
-0.010351927019655704,
-0.008922970853745937,
0.02028251625597477,
-0.04101093113422394,
0.026861445978283882,
-0.024726059287786484,
-0.06278468668460846,
0.038966018706560135,
0.004769133869558573,
-0.010739853605628014,
0.005096386186778545,
0.039385441690683365,
0.022880712524056435,
0.003612712025642395,
-0.018584540113806725,
-0.025322452187538147,
0.01745333895087242,
-0.009380131959915161,
-0.016553845256567,
0.001850432250648737,
-0.006989536341279745,
-0.025372793897986412,
-0.0054117594845592976,
-0.02596651390194893,
0.028949281200766563,
0.0043757399544119835,
0.015747331082820892,
0.004337273072451353,
-0.0017383794765919447,
0.015883686020970345,
-0.0007541727973148227,
0.018003853037953377,
0.003539873519912362,
-0.012813773937523365,
0.01221961248666048,
0.010636948049068451,
-0.009280869737267494,
-0.030992645770311356,
0.0034958445467054844,
-0.027724098414182663,
-0.023731285706162453,
0.002253927756100893,
-0.006789566949009895,
0.021328501403331757,
0.03101886808872223,
0.021956849843263626,
-0.00837281346321106,
0.0073175132274627686,
0.005252389702945948,
0.01779891736805439,
-0.026852324604988098,
-0.00974416732788086,
-0.013368767686188221,
0.03464796394109726,
-0.0022972621954977512,
-0.014746609143912792,
-0.02935386821627617,
-0.004417208954691887,
0.022456863895058632,
-0.004086339380592108,
0.02630489319562912,
-0.015133156441152096,
-0.025606831535696983,
0.022917168214917183,
-0.0066328528337180614,
0.04212183505296707,
0.002884984714910388,
-0.030275603756308556,
-0.0037666507996618748,
-0.06645850092172623,
0.04177507758140564,
0.014205287210643291,
0.008249974809587002,
0.014933343976736069,
0.027178125455975533,
-0.04001857340335846,
0.004095019306987524,
0.01994001679122448,
0.0066569349728524685,
-0.00937605369836092,
0.013887619599699974,
-0.018416982144117355,
-0.01042152103036642,
0.025200219824910164,
0.014174441806972027,
-0.014645740389823914,
0.01071484200656414,
0.010212788358330727,
-0.007548476569354534,
-0.006883895955979824,
0.004627044778317213,
-0.01706952415406704,
0.013907955028116703,
0.010410147719085217,
-0.020486675202846527,
0.008198500610888004,
0.0010251642670482397,
-0.010863497853279114,
-0.032347965985536575,
0.026514336466789246,
-0.003734729252755642,
-0.0008351461729034781,
-0.024832524359226227,
0.010949875228106976,
0.003932286519557238,
-0.004006377421319485,
0.035967499017715454,
-0.01600688323378563,
0.0002056873927358538,
-0.000385603605536744,
-0.014673626981675625,
0.04326397553086281,
0.003346080193296075,
0.01916542649269104,
0.008299505338072777,
-0.0058955661952495575,
0.016148611903190613,
-0.004752435255795717,
-0.048642199486494064,
-0.010715555399656296,
0.029748080298304558,
-0.0027368420269340277,
0.025487126782536507,
0.005981696303933859,
0.01455976814031601,
0.05966348946094513,
0.013071640394628048,
0.007429023738950491,
0.0017268280498683453,
0.0035253718961030245,
0.029997484758496284,
0.017892014235258102,
0.010862189345061779,
-0.004611525684595108,
-0.02935096248984337,
0.029572289437055588,
-0.010053006932139397,
0.009177356027066708,
-0.03634341061115265,
-0.01073389034718275,
-0.0116349458694458,
0.0037918288726359606,
0.032128266990184784,
0.018079601228237152,
0.032350219786167145,
0.004084979183971882,
-0.01222322229295969,
0.014020663686096668,
0.011258667334914207,
0.009943928569555283,
-0.020451046526432037,
-0.0016128384741023183,
0.040468230843544006,
0.01767169125378132,
0.03453165665268898,
-0.025909340009093285,
0.015485748648643494,
0.006434646900743246,
0.01621657982468605,
-0.0054760887287557125,
-0.020798923447728157,
0.031369492411613464,
-0.008357984013855457,
-0.002162277465686202,
0.008874626830220222,
0.004613138735294342,
0.012446602806448936,
-0.005928500089794397,
-0.01349730882793665,
-0.08087164163589478,
-0.001108131487853825,
0.0002492062048986554,
-0.007649591192603111,
-0.015006110072135925,
0.005118721630424261,
0.00011059310054406524,
-0.00835060141980648,
0.01439704094082117,
-0.0016994554316625,
-0.03855270519852638,
-0.01072519551962614,
-0.0168507881462574,
-0.023411070927977562,
0.023229394108057022,
0.009811039082705975,
-0.010819754563272,
-0.0071115694008767605,
0.007875533774495125,
0.018431244418025017,
-0.006169668864458799,
0.013638445176184177,
-0.0015278008067980409,
0.03883490338921547,
-0.02893807366490364,
-0.03862898051738739,
0.026558326557278633,
-0.0011680840980261564,
-0.01567074842751026,
0.0035280378069728613,
-0.03570123016834259,
0.03505904972553253,
-0.010448183864355087,
0.0024212368298321962,
0.008959072642028332,
0.007937920279800892,
-0.008656066842377186,
0.0294196754693985,
0.011815130710601807,
-0.025287434458732605,
0.010638277977705002,
-0.024115439504384995,
0.016866127029061317,
0.009726117365062237,
-0.009465543553233147,
0.03205979987978935,
0.029644440859556198,
-0.03931255266070366,
-0.011194798164069653,
0.02984636090695858,
-0.04039936885237694,
0.012461608275771141,
0.011614023707807064,
-0.0019364748150110245,
-0.016014501452445984,
0.0050551556050777435,
0.018932275474071503,
-0.030201859772205353,
0.0015544431516900659,
0.0020516833756119013,
-0.007479366846382618,
-0.001480313017964363,
0.002128582214936614,
-0.01657509058713913,
0.0060840873047709465,
0.0029965676367282867,
0.026378491893410683,
0.004277609288692474,
-0.0005906755686737597,
-0.011396258138120174,
0.016342224553227425,
0.012320974841713905,
-0.02884535863995552,
-0.003980398178100586,
0.021182682365179062,
0.0037395255640149117,
-0.04229147359728813,
-0.010275228880345821,
-0.005117736756801605,
0.006084910128265619,
0.0025871226098388433,
0.03471310809254646,
-0.011449622921645641,
-0.026854537427425385,
0.002897342899814248,
-0.022243402898311615,
0.002305572386831045,
-0.007431869860738516,
0.01017687190324068,
0.018152030184864998,
-0.13615505397319794,
0.004936824087053537,
0.007721839472651482,
0.024086574092507362,
-0.014979925937950611,
-0.03158637136220932,
0.023276083171367645,
-0.007968061603605747,
-0.008667251095175743,
0.010832469910383224,
-0.009629585780203342,
0.07050968706607819,
-0.013730802573263645,
-0.014761371538043022,
-0.00676031643524766,
0.038730550557374954,
0.014331154525279999,
0.0029931380413472652,
0.03553525730967522,
0.007040555588901043,
0.023129940032958984,
-0.0015561000909656286,
-0.03726949542760849,
0.00950700230896473,
-0.020023584365844727,
0.022024914622306824,
-0.025592772290110588,
0.009474190883338451,
0.04816631227731705,
-0.03495382145047188,
-0.015412182547152042,
-0.007502840831875801,
0.03950344771146774,
0.006056524347513914,
0.004565478768199682,
-0.030103584751486778,
-0.009989673271775246,
0.033527474850416183,
0.03373883292078972,
0.0019502766663208604,
-0.001906780176796019,
-0.02277505397796631,
-0.03928842023015022,
0.011492449790239334,
-0.004207565449178219,
-0.016888469457626343,
0.01218303944915533,
-0.002971039852127433,
0.032105859369039536,
0.013140217401087284,
0.0012549626408144832,
0.008821037597954273,
0.007788124494254589,
0.008000185713171959,
0.007558742072433233,
0.052590638399124146,
-0.07591301947832108,
0.0035970713943243027,
0.015328441746532917,
0.00008110552880680189,
0.008638948202133179,
0.03384057432413101,
0.049029815942049026,
-0.037872347980737686,
-0.022643649950623512,
0.005716604180634022,
0.0011796809267252684,
0.013761640526354313,
0.00893650483340025,
-0.025010617449879646,
-0.028637375682592392,
-0.01922580786049366,
0.02188136801123619,
-0.027908939868211746,
-0.03702399507164955,
-0.0036032218486070633,
0.027895400300621986,
-0.03208012506365776,
0.023433499038219452,
0.020226147025823593,
-0.02116677723824978,
-0.020333897322416306,
0.02816431038081646,
-0.003151471959426999,
-0.004151945002377033,
-0.03043506108224392,
-0.027811849489808083,
-0.01279126014560461,
-0.004093261435627937,
-0.005995419342070818,
-0.019717680290341377,
0.020268360152840614,
0.008680586703121662,
0.015400153584778309,
-0.00476092379540205,
0.03117205575108528,
0.011745993047952652,
-0.020323099568486214,
0.0028367829509079456,
-0.016776759177446365,
-0.022536354139447212,
-0.010575669817626476,
0.007349932100623846,
0.023394156247377396,
0.014947788789868355,
-0.00968214962631464,
0.005347337573766708,
0.0023095381911844015,
-0.0024823101703077555,
0.02515496499836445,
-0.0008698842721059918,
0.030917350202798843,
-0.012759266421198845,
0.025082631036639214,
-0.02944157086312771,
-0.009071209467947483,
0.023233547806739807
] |
8a425179166f5e46f9936c55196547277fa5770b | 2,600 | py | Python | messages/term_utils.py | ckousoulis/macos-messages | acf7ac94a81f7d097e2025c6ec7dd429de010795 | [
"MIT"
] | null | null | null | messages/term_utils.py | ckousoulis/macos-messages | acf7ac94a81f7d097e2025c6ec7dd429de010795 | [
"MIT"
] | null | null | null | messages/term_utils.py | ckousoulis/macos-messages | acf7ac94a81f7d097e2025c6ec7dd429de010795 | [
"MIT"
] | null | null | null | """Terminal utilities specific to message archives.
Creates colored text and helps write Messages output.
"""
from contextlib import contextmanager
import itertools
import readline
FG_COLORS = dict(itertools.chain(
zip(("black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
), range(30, 38)),
zip(("bright_black",
"bright_red",
"bright_green",
"bright_yellow",
"bright_blue",
"bright_magenta",
"bright_cyan",
"bright_white",
), range(90, 98))))
BG_COLORS = dict((f"on_{key}", val + 10) for key, val in FG_COLORS.items())
ATTRIBUTES = dict(
zip(("bold",
"faint",
"italic",
"underline",
"slow_blink",
"rapid_blink",
"reverse",
"conceal",
"strikethrough",
), range(1, 10)))
def colored(text, color=None, on_color=None, attrs=None, escape=False):
"""Wraps text with ANSI escape codes to achieve the desired look.
Args:
color: The foreground color.
on_color: The background color.
attrs: A list of effects.
escape: True to escape invisibles (for readline); else False.
Returns:
A string with the original text wrapped by escape codes.
"""
def sgr(*codes):
return "\x1b[%sm" % ";".join(map(str, codes))
def esc(text):
return "\x01%s\x02" % text
codes = []
if color:
codes.append(FG_COLORS[color])
if on_color:
codes.append(BG_COLORS[on_color])
if attrs:
codes.extend(ATTRIBUTES[attr] for attr in attrs)
if not escape:
esc = lambda n: n
return "%s%s%s" % (esc(sgr(*codes)), text, esc(sgr(0)))
@contextmanager
def readline_disabled():
"""Context manager to temporarily disable readline features.
"""
readline.set_auto_history(False)
try:
yield
finally:
readline.set_auto_history(True)
def confirm(text):
"""Presents a yes/no prompt to the user and handles replies.
Args:
text: A message string to present before confirmation.
Returns:
True if the user confirmed the prompt; else False.
"""
replies = {
"yes": True,
"no": False,
}
prompt = "%s (yes/no): " % colored("Are you sure?", "red",
attrs=["bold"], escape=True)
reply = ""
with readline_disabled():
print(text)
while reply not in replies:
try:
reply = input(prompt).casefold()
except (EOFError, KeyboardInterrupt):
reply = "no"
print(reply)
return replies[reply]
| 23.423423 | 75 | 0.589615 | 1 | 1.5666 | [
0.0007304167374968529,
0.025636879727244377,
0.008860120549798012,
-0.0002032502816291526,
0.0045718844048678875,
-0.0020130600314587355,
-0.010614719241857529,
0.0030093032401055098,
-0.0072698937729001045,
0.0025016763247549534,
0.0027055509854108095,
0.0056725721806287766,
0.007010865956544876,
-0.017813820391893387,
0.00007433861173922196,
0.01619889587163925,
-0.0516723170876503,
0.0006244124961085618,
-0.0035427515394985676,
0.0011629954678937793,
-0.007571174297481775,
0.010144778527319431,
0.009254022501409054,
0.006084014195948839,
0.007754459045827389,
-0.000010544472388573922,
0.011389568448066711,
0.002538548083975911,
-0.008590511046350002,
-0.007451750338077545,
0.0004352373944129795,
-0.000809354824014008,
-0.005955058615654707,
-0.008396756835281849,
0.006121061742305756,
-0.0026016621850430965,
-0.0018088407814502716,
-0.01918468251824379,
0.013067305088043213,
-0.004543153103441,
-0.007421734277158976,
-0.015282932668924332,
-0.0001381711772410199,
0.004600176587700844,
-0.008799497038125992,
0.0013656187802553177,
-0.0038856077007949352,
0.003620013128966093,
-0.01180846057832241,
0.006939079146832228,
-0.008028351701796055,
0.005652211140841246,
0.012893450446426868,
0.0029514306224882603,
-0.005493405740708113,
-0.0068787685595452785,
0.012892837636172771,
-0.0004345422494225204,
-0.010892178863286972,
-0.0004955999902449548,
-0.0025678970851004124,
-0.003722880035638809,
0.004679847974330187,
0.0034072597045451403,
-0.01451136264950037,
-0.008168002590537071,
-0.004392290487885475,
0.0039293901063501835,
-0.0008287350065074861,
0.0049919928424060345,
0.0002476844529155642,
0.00011545614688657224,
0.007674731779843569,
0.0036289889831095934,
0.005162772722542286,
-0.0047437832690775394,
-0.00300721381790936,
0.00011881165846716613,
0.007352317217737436,
0.004693072754889727,
0.0021438393741846085,
-0.0058468603529036045,
0.007337468210607767,
0.009807976894080639,
0.014590767212212086,
0.0069252667017281055,
0.018472928553819656,
-0.012453109957277775,
0.047426845878362656,
0.0077233994379639626,
-0.00862881913781166,
0.0023913541808724403,
-0.0090683838352561,
-0.0020418092608451843,
-0.004206160083413124,
-0.02811947464942932,
0.000811201345641166,
-0.0034545210655778646,
0.0011225190246477723,
0.0033448715694248676,
0.0005502256681211293,
0.006915919482707977,
-0.0010618926025927067,
-0.00019934836018364877,
-0.008792138658463955,
0.01130751334130764,
-0.010259700939059258,
-0.004104616120457649,
0.007072064559906721,
0.0021558913867920637,
-0.01066326629370451,
-0.002019511768594384,
0.0014585870085284114,
-0.010914633981883526,
0.004047751426696777,
0.004602709785103798,
-0.0043954188004136086,
0.05669240653514862,
-0.0005965784075669944,
0.00423584645614028,
-0.0055924360640347,
0.0007070935680530965,
0.0032497213687747717,
0.004555346444249153,
0.009872469119727612,
-0.003435219172388315,
0.00985616073012352,
0.007278709206730127,
0.0030338545329868793,
0.008285433053970337,
-0.0014768546679988503,
0.007040147669613361,
-0.00419897073879838,
-0.00031300916452892125,
-0.00017335191660095006,
-0.00950299296528101,
0.007312726229429245,
-0.0005105616291984916,
-0.006696040742099285,
0.0008260288159362972,
-0.000621372542809695,
-0.010995953343808651,
0.002314463257789612,
-0.004807688295841217,
0.002678565913811326,
-0.011284100823104382,
-0.0033422510605305433,
-0.0035792235285043716,
-0.0036614262498915195,
0.0006437044939957559,
0.009111395105719566,
0.005009091459214687,
0.0024301072116941214,
-0.00400411244481802,
-0.009093226864933968,
-0.0007777994615025818,
-0.005027282517403364,
0.002983119571581483,
0.00954678189009428,
0.0038642585277557373,
-0.010724738240242004,
-0.0015191497514024377,
0.0022062540519982576,
0.0012785937869921327,
-0.0004417082527652383,
0.003773106262087822,
-0.009017745964229107,
0.006339909043163061,
0.0001965006667887792,
0.005424898583441973,
0.009919900447130203,
-0.0031382504384964705,
-0.0009869083296507597,
0.001300905947573483,
0.0021833789069205523,
0.00005587877603829838,
0.00517265172675252,
0.0110146040096879,
-0.004036651458591223,
-0.003001812845468521,
0.004158382304012775,
0.005386894568800926,
0.0076909312047064304,
0.0029939631931483746,
-0.0036313384771347046,
-0.00007174315396696329,
-0.0036689836997538805,
-0.0010819685412570834,
0.006810239050537348,
-0.00346419308334589,
0.006922839675098658,
0.004355201497673988,
-0.014642474241554737,
-0.008593585342168808,
0.0009252927266061306,
-0.00777900917455554,
0.0006036887061782181,
0.01370985060930252,
0.010707031935453415,
-0.004510677419602871,
0.0006030885851942003,
-0.010075296275317669,
-0.000567313632927835,
0.009282873943448067,
0.00034803326707333326,
-0.01376432552933693,
-0.9580073952674866,
0.005359884351491928,
0.0021343687549233437,
-0.003004220314323902,
0.0061435094103217125,
0.0031009484082460403,
0.004784911405295134,
0.004070537630468607,
0.014621374197304249,
-0.009594505652785301,
-0.005992294289171696,
-0.010283173061907291,
-0.009972482919692993,
-0.002891000360250473,
-0.007097874768078327,
-0.003849936882033944,
-0.004777762107551098,
-0.008345093578100204,
-0.0029160697013139725,
-0.0034514532890170813,
-0.0023502500262111425,
0.008719096891582012,
0.0006272759637795389,
0.004124727565795183,
0.003108692355453968,
0.004384030122309923,
-0.004853677004575729,
-0.001223124680109322,
-0.0018747628200799227,
-0.0016439247410744429,
-0.006715229246765375,
-0.015639932826161385,
-0.0023826940450817347,
-0.0013875614386051893,
0.011293170042335987,
0.0018555709393694997,
0.009226898662745953,
-0.001779105281457305,
-0.00020780443446710706,
-0.005932674743235111,
0.003731637727469206,
0.0007170763565227389,
0.0021343990229070187,
-0.030562324449419975,
0.0005639820010401309,
-0.0013353410176932812,
-0.00833387766033411,
0.00922352820634842,
0.0007529717986471951,
0.00030803034314885736,
-0.0023740744218230247,
-0.005684203933924437,
0.009617969393730164,
-0.007043399848043919,
0.004525734577327967,
-0.003947469871491194,
-0.008202134631574154,
-0.0025422335602343082,
-0.009675603359937668,
0.00207792641595006,
0.004361449275165796,
-0.005379782058298588,
-0.005489429924637079,
-0.004200724419206381,
0.003594953566789627,
0.0009051525266841054,
0.001946801319718361,
-0.019391024485230446,
-0.005879892967641354,
0.000391805253457278,
0.0006561647751368582,
-0.002360706450417638,
-0.0046276128850877285,
0.005577319301664829,
-0.009055433794856071,
0.006476351525634527,
0.0003318950766697526,
-0.0004954557516612113,
-0.010855428874492645,
0.001982684712857008,
-0.007805564906448126,
-0.008754175156354904,
0.001977170119062066,
-0.0034789196215569973,
-0.005055795423686504,
-0.00012333819177001715,
0.00034585941466502845,
0.005644458811730146,
-0.004037963692098856,
0.002197755267843604,
0.010131539776921272,
-0.0035895048640668392,
-0.009980959817767143,
0.005843734834343195,
0.006575174629688263,
-0.0005109951016493142,
-0.0020847769919782877,
0.002991769928485155,
0.008017055690288544,
0.007433206308633089,
0.0034218542277812958,
0.005736079532653093,
-0.0003085624775849283,
0.010751002468168736,
-0.00010568740253802389,
0.0018591737607493997,
-0.003201093291863799,
-0.00015459659334737808,
-0.003688455792143941,
0.000862554123159498,
-0.004370937589555979,
-0.0010606803698465228,
-0.011791455559432507,
-0.008624931797385216,
-0.003635869361460209,
0.00037469598464667797,
0.002210813108831644,
-0.004487480502575636,
-0.0003191199793945998,
0.001843746518716216,
0.010205420665442944,
0.0001776067219907418,
-0.00321750994771719,
-0.000512083584908396,
0.004328729119151831,
-0.009273390285670757,
0.014850878156721592,
-0.011385771445930004,
0.006522337906062603,
-0.0008080691914074123,
-0.01676258072257042,
0.006948521826416254,
0.009601070545613766,
-0.009258630685508251,
0.002633865224197507,
0.0023622328881174326,
0.004120781552046537,
0.0010736992117017508,
-0.0034636794589459896,
-0.005778562743216753,
-0.015322486869990826,
-0.0007496684556826949,
0.019979918375611305,
0.0010710874339565635,
0.009382830001413822,
0.011205391027033329,
-0.0037030025850981474,
0.0041135395877063274,
0.004057059530168772,
0.0003653319727163762,
0.011653323657810688,
-0.0075746444053947926,
-0.0006124834180809557,
0.0025709993205964565,
-0.006694368552416563,
-0.0006454361719079316,
0.006280137691646814,
0.00620695436373353,
-0.003854505019262433,
0.001267840270884335,
-0.006783215794712305,
-0.005570126697421074,
-0.01749325916171074,
-0.004317502956837416,
0.007100509945303202,
-0.005252736620604992,
0.005586458370089531,
-0.015192024409770966,
0.006782867945730686,
0.007883799262344837,
0.003001144155859947,
-0.001057976740412414,
0.0014649550430476665,
0.0040644253604114056,
0.01256738044321537,
-0.0037284137215465307,
0.001165892113931477,
0.00287242466583848,
0.0009026859770528972,
0.00039880062104202807,
0.0058808173052966595,
-0.006814743857830763,
-0.005581208039075136,
0.0013489859411492944,
0.006135367322713137,
-0.000992863206192851,
-0.004250355064868927,
-0.007842316292226315,
-0.003183238208293915,
0.00407489063218236,
-0.0055947559885680676,
0.003940371796488762,
0.00019600139057729393,
0.003703694324940443,
-0.006158463191241026,
-0.0008166451007127762,
-0.003046897705644369,
-0.01281843800097704,
0.008260478265583515,
-0.00348852202296257,
0.0018568356754258275,
0.012936047278344631,
0.004357960075139999,
-0.012593414634466171,
0.0048724147491157055,
0.007490373682230711,
-0.004974966403096914,
0.004144084639847279,
0.005325320176780224,
-0.006391680333763361,
-0.022439690306782722,
-0.002320881700143218,
-0.014023866504430771,
0.008122839964926243,
-0.0013341864105314016,
0.0027416436932981014,
-0.008207599632441998,
0.005895671434700489,
0.007405129261314869,
-0.013149449601769447,
-0.0042436993680894375,
-0.009533903561532497,
0.008465639315545559,
0.0005695672589354217,
-0.002717870520427823,
-0.0038321171887218952,
-0.001378239830955863,
-0.0007111830054782331,
-0.004159146454185247,
-0.002664657076820731,
0.005886336322873831,
0.0014295788714662194,
-0.004338209982961416,
0.0016663109418004751,
-0.002008266281336546,
0.001193674630485475,
0.0021308965515345335,
-0.010263640433549881,
0.0028879339806735516,
0.003890105290338397,
-0.001805858570151031,
-0.0021664940286427736,
0.002204716671258211,
-0.002248934004455805,
-0.004564165137708187,
-0.011312155053019524,
-0.00261777825653553,
-0.003604194847866893,
-0.002048762980848551,
-0.011863399296998978,
-0.003342140931636095,
-0.009383145719766617,
0.005757856648415327,
-0.00895689707249403,
0.009286446496844292,
0.006248098332434893,
-0.004432604648172855,
0.00672468775883317,
-0.004395585972815752,
0.004069783724844456,
0.0032227174378931522,
0.005117911845445633,
0.00143549800850451,
-0.005805052351206541,
-0.01094128005206585,
0.010429976508021355,
-0.008402825333178043,
0.0012254766188561916,
0.013153841719031334,
0.003505843225866556,
0.008510809391736984,
0.0003628797421697527,
-0.0010021724738180637,
0.004750567954033613,
0.007336577866226435,
-0.01276145689189434,
0.004202031064778566,
-0.0034848712384700775,
-0.0007841052138246596,
0.0043577468022704124,
-0.003523870138451457,
0.0020961749833077192,
0.008032332174479961,
0.0006199135677888989,
-0.006716754287481308,
-0.0014927561860531569,
0.0026201263535767794,
0.0038659072015434504,
-0.012149549089372158,
-0.0006931657553650439,
-0.003291590604931116,
-0.005579938180744648,
-0.004367923364043236,
-0.0014127359027042985,
-0.001606783247552812,
0.004863100592046976,
-0.0021255728788673878,
0.005852871108800173,
0.0034575993195176125,
-0.005981083028018475,
0.01460314355790615,
-0.004589146468788385,
-0.004103301092982292,
0.0026240490842610598,
0.0029086973518133163,
-0.0018781820544973016,
-0.0060755289159715176,
-0.0015378395328298211,
0.0025487556122243404,
0.007039461750537157,
-0.003460416803136468,
-0.0028098211623728275,
-0.002671521622687578,
0.0021878215484321117,
-0.009315459057688713,
0.0005509002367034554,
0.013824459165334702,
-0.0042109135538339615,
0.005017537623643875,
-0.0015287072164937854,
-0.0072041773237288,
-0.01565280370414257,
0.05303485319018364,
-0.000487985962536186,
0.003302551107481122,
0.005582388024777174,
-0.007293563801795244,
0.001349919242784381,
-0.002113654976710677,
0.00837145559489727,
-0.007499636150896549,
-0.008610249496996403,
0.010065067559480667,
-0.004378165118396282,
0.002881008666008711,
0.002257300540804863,
-0.0016519780037924647,
0.015067228116095066,
-0.003015427151694894,
-0.016756199300289154,
-0.016351526603102684,
0.008371998555958271,
-0.0024429643526673317,
-0.008290610276162624,
0.007516274228692055,
-0.0026556311640888453,
-0.004516799468547106,
0.0017854847246780992,
0.007812771946191788,
0.0002649878151714802,
0.0013699143892154098,
-0.003385143354535103,
-0.0031202593818306923,
0.0007099566282704473,
0.003056866582483053,
0.007251854985952377,
0.007606993429362774,
-0.003083114977926016,
0.00305703142657876,
-0.0021428102627396584,
-0.001782541978172958,
-0.0019683109130710363,
0.0037693853955715895,
0.008773094043135643,
-0.0014290829421952367,
-0.002196646062657237,
0.003910599742084742,
0.003819223027676344,
0.0032571402844041586,
0.010250401683151722,
-0.0012366960290819407,
-0.006591132842004299,
0.009647204540669918,
0.0066988347098231316,
-0.0008641844615340233,
0.009134120307862759,
-0.001670534024015069,
0.0064798942767083645,
0.00094085861928761,
-0.007121623493731022,
-0.015051248483359814,
-0.002517256187275052,
0.007227091584354639,
0.010493178851902485,
-0.0013804937480017543,
-0.0007185789290815592,
-0.001596916001290083,
-0.001538449781946838,
-0.007825914770364761,
-0.007141056004911661,
-0.004320704378187656,
0.0009389248443767428,
0.0020503816194832325,
0.07021015882492065,
-0.005755435675382614,
-0.0009115005959756672,
-0.009752730838954449,
-0.0017678523436188698,
-0.0026441889349371195,
-0.0014116530073806643,
0.0006355592631734908,
-0.0016920085763558745,
0.0015773832565173507,
0.0016967598348855972,
-0.009635286405682564,
-0.010498588904738426,
0.0020175736863166094,
0.000983246136456728,
-0.002151170512661338,
0.004086678382009268,
0.007182680536061525,
-0.007178935222327709,
0.002363825449720025,
-0.009966390207409859,
-0.0020951908081769943,
-0.004093138966709375,
-0.01168758049607277,
-0.003035312984138727,
-0.002871224656701088,
0.004386818502098322,
0.002431296743452549,
0.007321877870708704,
-0.0030087153427302837,
0.006865079514682293,
-0.0013906769454479218,
0.0006690307054668665,
-0.00472240149974823,
0.001301524811424315,
-0.007371111307293177,
0.006802307441830635,
0.00245742779225111,
-0.008983277715742588,
-0.005827531684190035,
-0.0006645895773544908,
0.00031964806839823723,
-0.004723689053207636,
0.004458028823137283,
-0.0007635594811290503,
0.0034443894401192665,
-0.0026076340582221746,
0.0008163807797245681,
-0.006810877472162247,
0.003533643437549472,
-0.013170292600989342,
0.0033367127180099487,
-0.17591492831707,
0.011135621927678585,
0.003993798978626728,
-0.006344383116811514,
-0.0019327119225636125,
-0.014260153286159039,
-0.005546780303120613,
0.003261987352743745,
0.011965073645114899,
-0.00048133087693713605,
-0.0010750314686447382,
-0.004023073706775904,
0.004851963371038437,
0.004768291488289833,
-0.00037522471393458545,
-0.005829613655805588,
0.0035040397197008133,
-0.004665412474423647,
0.00035127843148075044,
0.0022404734045267105,
0.004893328528851271,
0.009398747235536575,
0.0012076001148670912,
0.001366618205793202,
-0.0020661037415266037,
-0.005380758550018072,
0.006294510792940855,
-0.001584304845891893,
0.005657515954226255,
-0.012915913946926594,
-0.0019130634609609842,
-0.004857833497226238,
-0.00434806989505887,
0.002103388775140047,
0.005054790992289782,
-0.0009830084163695574,
0.008452667854726315,
0.0039685131050646305,
-0.008860304020345211,
0.007508889771997929,
-0.006795693654567003,
0.030477000400424004,
0.00447998708114028,
0.007526805158704519,
0.0006368568865582347,
-0.0066169858910143375,
-0.003975925501435995,
0.00874114315956831,
0.001628831960260868,
0.012496351264417171,
-0.012885508127510548,
-0.0015511326491832733,
0.001857985625974834,
0.01881277561187744,
-0.0044824713841080666,
-0.009932276792824268,
-0.0061438423581421375,
-0.005286572501063347,
0.0012871321523562074,
0.010558411478996277,
0.011858196929097176,
-0.004880187567323446,
0.008269904181361198,
-0.002893309108912945,
-0.019788172096014023,
0.0027812132611870766,
-0.0043378304690122604,
-0.006526181474328041,
0.0017831438453868032,
0.006222740281373262,
0.01007168646901846,
0.0002045724104391411,
0.0033719781786203384,
-0.0005940268747508526,
0.0043249488808214664,
-0.0007945597753860056,
0.006338566076010466,
-0.0018818371463567019,
0.005359710659831762,
-0.008838330395519733,
0.007425116840749979,
-0.009882219135761261,
-0.0017072901828214526,
0.002448566723614931,
-0.004638317972421646,
0.01150420494377613,
0.0050115459598600864,
-0.0026480862870812416,
-0.0019787021446973085,
-0.011156265623867512,
-0.002559009939432144,
0.002122212667018175,
0.0016398895531892776,
-0.008943538181483746,
0.0034777463879436255,
0.0001041091963998042,
0.003697406966239214,
0.004910450894385576,
-0.008383522741496563,
0.005023071076720953,
0.006476983893662691,
-0.006977559067308903,
0.0014708110829815269,
-0.0036886832676827908,
0.003526798915117979,
0.0036857021041214466,
-0.0066004968248307705,
-0.0070261782966554165,
0.0033213761635124683,
-0.007023196667432785,
-0.004915494471788406,
0.007194949313998222,
-0.008903567679226398,
-0.00719118257984519,
-0.000598268467001617,
-0.012347988784313202,
0.0016588589642196894
] |
8a4336dbd5d1cefd9e382961486ab2a2e96b55c6 | 2,714 | py | Python | tests/test_subpixel_upsample.py | Project-MONAI/MONAI | 2bab12c67c3cc1d54a4847628ce1e879064be11c | [
"Apache-2.0"
] | 2,971 | 2019-10-16T23:53:16.000Z | 2022-03-31T20:58:24.000Z | tests/test_subpixel_upsample.py | Project-MONAI/MONAI | 2bab12c67c3cc1d54a4847628ce1e879064be11c | [
"Apache-2.0"
] | 2,851 | 2020-01-10T16:23:44.000Z | 2022-03-31T22:14:53.000Z | tests/test_subpixel_upsample.py | Project-MONAI/MONAI | 2bab12c67c3cc1d54a4847628ce1e879064be11c | [
"Apache-2.0"
] | 614 | 2020-01-14T19:18:01.000Z | 2022-03-31T14:06:14.000Z | # Copyright 2020 - 2021 MONAI Consortium
# 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 unittest
import torch
import torch.nn as nn
from parameterized import parameterized
from monai.networks import eval_mode
from monai.networks.blocks import SubpixelUpsample
from monai.networks.layers.factories import Conv
TEST_CASE_SUBPIXEL = []
for inch in range(1, 5):
for dim in range(1, 4):
for factor in range(1, 3):
test_case = [
{"dimensions": dim, "in_channels": inch, "scale_factor": factor},
(2, inch, *([8] * dim)),
(2, inch, *([8 * factor] * dim)),
]
TEST_CASE_SUBPIXEL.append(test_case)
TEST_CASE_SUBPIXEL_2D_EXTRA = [
{"dimensions": 2, "in_channels": 2, "scale_factor": 3},
(2, 2, 8, 4), # different size for H and W
(2, 2, 24, 12),
]
TEST_CASE_SUBPIXEL_3D_EXTRA = [
{"dimensions": 3, "in_channels": 1, "scale_factor": 2},
(2, 1, 16, 8, 4), # different size for H, W and D
(2, 1, 32, 16, 8),
]
conv_block = nn.Sequential(
Conv[Conv.CONV, 3](1, 4, kernel_size=1), Conv[Conv.CONV, 3](4, 8, kernel_size=3, stride=1, padding=1)
)
TEST_CASE_SUBPIXEL_CONV_BLOCK_EXTRA = [
{"dimensions": 3, "in_channels": 1, "scale_factor": 2, "conv_block": conv_block},
(2, 1, 16, 8, 4), # different size for H, W and D
(2, 1, 32, 16, 8),
]
TEST_CASE_SUBPIXEL.append(TEST_CASE_SUBPIXEL_2D_EXTRA)
TEST_CASE_SUBPIXEL.append(TEST_CASE_SUBPIXEL_3D_EXTRA)
TEST_CASE_SUBPIXEL.append(TEST_CASE_SUBPIXEL_CONV_BLOCK_EXTRA)
# add every test back with the pad/pool sequential component omitted
for tests in list(TEST_CASE_SUBPIXEL):
args: dict = tests[0] # type: ignore
args = dict(args)
args["apply_pad_pool"] = False
TEST_CASE_SUBPIXEL.append([args, tests[1], tests[2]])
class TestSUBPIXEL(unittest.TestCase):
@parameterized.expand(TEST_CASE_SUBPIXEL)
def test_subpixel_shape(self, input_param, input_shape, expected_shape):
net = SubpixelUpsample(**input_param)
with eval_mode(net):
result = net.forward(torch.randn(input_shape))
self.assertEqual(result.shape, expected_shape)
if __name__ == "__main__":
unittest.main()
| 34.35443 | 105 | 0.687546 | 1 | 1.7721 | [
0.002343697240576148,
0.02426624856889248,
0.010348469018936157,
0.0012815652880817652,
0.0024624052457511425,
-0.0009628379484638572,
-0.006517602596431971,
0.0022324449382722378,
-0.005488698370754719,
0.0005407560383901,
0.0034736257512122393,
0.00463000638410449,
0.007637867238372564,
-0.017173707485198975,
-0.0009997573215514421,
0.0169981736689806,
-0.048977386206388474,
0.0019533419981598854,
-0.003817535936832428,
0.002872090321034193,
-0.0069572762586176395,
0.006203192286193371,
0.010424931533634663,
0.007352446671575308,
0.004115648567676544,
-0.0026698049623519182,
0.011370138265192509,
0.0005466131260618567,
-0.005402348469942808,
-0.008130938746035099,
-0.00039746175752952695,
-0.0030114564578980207,
-0.00748957647010684,
-0.006953665520995855,
0.00523021025583148,
-0.003470322582870722,
0.0004304244357626885,
-0.017356039956212044,
0.011879418045282364,
-0.0047934032045304775,
-0.003685571486130357,
-0.014991753734648228,
0.00022154486214276403,
0.004158325958997011,
-0.00876085925847292,
0.0016018449096009135,
-0.005064257420599461,
0.0013174423947930336,
-0.010814684443175793,
0.007430008612573147,
-0.009925184771418571,
0.007470650132745504,
0.01369559671729803,
0.0020745350047945976,
-0.0061724381521344185,
-0.007223082706332207,
0.011761062778532505,
-0.0016426147194579244,
-0.009604845196008682,
0.0006935968995094299,
-0.004036624915897846,
-0.0008120863931253552,
0.004669340327382088,
0.0029149025212973356,
-0.013775157742202282,
-0.008056411519646645,
-0.003541516372933984,
0.0032208424527198076,
-0.0010394933633506298,
0.006474149413406849,
0.0012349345488473773,
-0.00024524194304831326,
0.00776500441133976,
0.002890428528189659,
0.00540913175791502,
-0.005669658072292805,
-0.0009469034848734736,
-0.0017868222203105688,
0.00803889986127615,
0.0033314747270196676,
0.0027380657847970724,
-0.0037474152632057667,
0.0027658999897539616,
0.007205558475106955,
0.015879029408097267,
0.008983776904642582,
0.0193781778216362,
-0.010048026219010353,
0.04818551242351532,
0.009649408049881458,
-0.008325428701937199,
0.0016090624267235398,
-0.011107663623988628,
-0.0014604413881897926,
-0.003099632915109396,
-0.025654884055256844,
0.0015485297190025449,
-0.0039761564694345,
-0.0008355138706974685,
0.001432263059541583,
0.000166393379913643,
0.008543092757463455,
-0.00041030196007341146,
-0.004498831927776337,
-0.008338053710758686,
0.007944642566144466,
-0.009867989458143711,
-0.0031730926129966974,
0.006891252938657999,
0.0028810608200728893,
-0.011750240810215473,
-0.0028379892464727163,
0.001161004533059895,
-0.012521201744675636,
0.0032972674816846848,
0.004133016336709261,
-0.00670491810888052,
0.05151095241308212,
-0.0012533338740468025,
0.003286483697593212,
-0.005404578987509012,
0.0008994138333946466,
0.0006480006268247962,
0.004593890625983477,
0.010904641821980476,
-0.001819615950807929,
0.010878944769501686,
0.007199170533567667,
0.005469293799251318,
0.009346622042357922,
-0.0039848946034908295,
0.0073826611042022705,
-0.0025295154191553593,
-0.003310190048068762,
0.0014956039376556873,
-0.007618906907737255,
0.008136742748320103,
-0.00040841373265720904,
-0.00928046740591526,
0.0004626031150110066,
-0.000027732388844015077,
-0.008158543147146702,
0.000729994208086282,
-0.004582569934427738,
0.005140981171280146,
-0.01033711712807417,
-0.0038323053158819675,
-0.003978114575147629,
-0.003612157655879855,
0.0028304585721343756,
0.010105193592607975,
0.00403418717905879,
0.0028154044412076473,
-0.004502518568187952,
-0.010795611888170242,
-0.0007955769542604685,
-0.0038265602197498083,
0.001917068613693118,
0.005704972427338362,
0.003562502097338438,
-0.010320113971829414,
-0.0012809220934286714,
0.0015382368583232164,
0.0018869128543883562,
-0.00032190923229791224,
0.0013820246094837785,
-0.00899201724678278,
0.0047979229129850864,
-0.0006448869244195521,
0.004809384699910879,
0.009116382338106632,
-0.004847604315727949,
-0.0005007812869735062,
0.0006451189983636141,
-0.00018548931984696537,
-0.0014600115828216076,
0.004924020264297724,
0.011187765747308731,
-0.0007169935270212591,
-0.005143161863088608,
0.002900514053180814,
0.006929553579539061,
0.01052100583910942,
0.006182716228067875,
-0.004193680360913277,
0.00041754881385713816,
-0.005871756933629513,
-0.0007960934890434146,
0.007494960445910692,
-0.0037666503340005875,
0.0049238442443311214,
0.0029483838006854057,
-0.011272729374468327,
-0.009842080064117908,
-0.0003550316905602813,
-0.007087788078933954,
0.0016918675974011421,
0.013102003373205662,
0.011434357613325119,
-0.003397175809368491,
0.0022647534497082233,
-0.008745306171476841,
0.0005376658518798649,
0.007292089983820915,
0.00412695063278079,
-0.012798791751265526,
-0.9599932432174683,
0.00823205802589655,
0.003950729034841061,
-0.0036381559912115335,
0.006414410192519426,
0.0022118196357041597,
0.0041928221471607685,
0.0037790383212268353,
0.014075237326323986,
-0.009299559518694878,
-0.004651350900530815,
-0.008868802338838577,
-0.009946214966475964,
-0.0022677083034068346,
-0.00697298301383853,
-0.003221557242795825,
-0.005385455209761858,
-0.005142560228705406,
-0.002068047411739826,
-0.0020816645119339228,
-0.0027990650851279497,
0.009016904048621655,
-0.0020965556614100933,
0.005980841349810362,
0.0038537620566785336,
0.0016399993328377604,
-0.005029532127082348,
-0.0014243420446291566,
-0.004408513195812702,
-0.003471373114734888,
-0.006106158252805471,
-0.014780479483306408,
-0.002786684548482299,
-0.0026306831277906895,
0.009466533549129963,
-0.00023466450511477888,
0.009088561870157719,
-0.0033025185111910105,
0.004637959413230419,
-0.007022830191999674,
0.004923471715301275,
-0.0007488583796657622,
0.0048482525162398815,
-0.031648606061935425,
-0.0007315374678000808,
0.00012068565411027521,
-0.009549370035529137,
0.003964452538639307,
-0.0014397158520296216,
-0.0003341570554766804,
-0.0023829464334994555,
-0.00683638034388423,
0.010302950628101826,
-0.007331260945647955,
0.004878324922174215,
-0.00361612974666059,
-0.008728917688131332,
-0.00387918995693326,
-0.00743325799703598,
0.0013901779893785715,
0.006012018769979477,
-0.004959238227456808,
-0.003942741081118584,
-0.002875982318073511,
0.004677934572100639,
0.003991079982370138,
0.001022791606374085,
-0.019692758098244667,
-0.007292806636542082,
-0.0009992828126996756,
-0.0014518597163259983,
-0.00403112918138504,
-0.004728470928966999,
0.006073415279388428,
-0.008132894523441792,
0.006962381303310394,
0.0022400047164410353,
-0.0025456775911152363,
-0.011045781895518303,
-0.001622108626179397,
-0.010092663578689098,
-0.006154157686978579,
0.002354307333007455,
-0.004470029380172491,
-0.0058546168729662895,
-0.0013133048778399825,
0.0008803626406006515,
0.007862703874707222,
-0.00504651851952076,
0.00571830477565527,
0.01151141058653593,
-0.001968825003132224,
-0.008218268863856792,
0.0062608676962554455,
0.0064816102385520935,
0.0017765279626473784,
-0.0030551180243492126,
0.0019374396651983261,
0.007698408793658018,
0.009666569530963898,
0.002470381325110793,
0.007594445254653692,
0.0017872302560135722,
0.006555216386914253,
-0.00014482725237030536,
0.001373617211356759,
-0.002067120047286153,
-0.0005234898999333382,
-0.003464694833382964,
-0.00143555854447186,
-0.00456139026209712,
-0.0037982277572155,
-0.011927510611712933,
-0.006380211561918259,
-0.0065024676732718945,
-0.0011502588167786598,
0.0031527371611446142,
-0.003472324460744858,
-0.00027949121431447566,
0.0009142635972239077,
0.008162657730281353,
-0.0005239503807388246,
-0.0015857191756367683,
0.0011100185802206397,
0.003448296105489135,
-0.004445027094334364,
0.013949569314718246,
-0.012431485578417778,
0.007518233731389046,
0.0008759586489759386,
-0.01517485175281763,
0.006845206953585148,
0.008293929509818554,
-0.010425243526697159,
0.001263533835299313,
0.003815754083916545,
0.0005742734065279365,
-0.0029116577934473753,
-0.006771773565560579,
-0.0010947012342512608,
-0.01727575995028019,
0.00021955602278467268,
0.018217772245407104,
0.0006667885463684797,
0.009718265384435654,
0.011460954323410988,
-0.0006134866271167994,
0.0030476199463009834,
0.0026562565471976995,
-0.0007211897172965109,
0.012123101390898228,
-0.008099918253719807,
-0.0005503133870661259,
0.002891099313274026,
-0.005976385902613401,
0.0006334653589874506,
0.007475884165614843,
0.005128554534167051,
-0.001575300469994545,
0.005750726908445358,
-0.006304359994828701,
-0.004229907412081957,
-0.018941683694720268,
-0.0036134766414761543,
0.0060750944539904594,
-0.0034206050913780928,
0.00788889266550541,
-0.011953582055866718,
0.0032550820615142584,
0.00791686587035656,
0.005847621243447065,
-0.0010619356762617826,
0.001450321520678699,
0.005450391210615635,
0.013026339933276176,
-0.006266098003834486,
0.001067351782694459,
0.0024133429396897554,
-0.0006136056035757065,
-0.0029582201968878508,
0.007706980686634779,
-0.005830252543091774,
-0.005927560850977898,
0.0017471977043896914,
0.005216680467128754,
0.0012407766189426184,
-0.004495925735682249,
-0.007971023209393024,
-0.004568532574921846,
0.00288368109613657,
-0.005489357281476259,
0.003208533627912402,
0.00179453962482512,
0.0028871004469692707,
-0.005490279756486416,
0.0003199987986590713,
-0.0028120006900280714,
-0.011696754954755306,
0.010732293128967285,
-0.0030968862120062113,
0.0023127426393330097,
0.014129581861197948,
0.005215707700699568,
-0.012492133304476738,
0.005125520750880241,
0.011390721425414085,
-0.002701790304854512,
0.006504982244223356,
0.005487070418894291,
-0.0062890551052987576,
-0.02239561825990677,
-0.005112436134368181,
-0.011724106036126614,
0.005672718398272991,
-0.00031161034712567925,
0.004646598361432552,
-0.007435448467731476,
0.005845530889928341,
0.0063892812468111515,
-0.014446423389017582,
-0.008042510598897934,
-0.008502918295562267,
0.007784733083099127,
-0.0008831410086713731,
0.00017725443467497826,
-0.004053256008774042,
-0.0023575061932206154,
-0.002642625942826271,
-0.0025802874006330967,
-0.000946165295317769,
0.00595403416082263,
0.0012610888807103038,
-0.0019073650473728776,
0.001745928660966456,
-0.004778798203915358,
0.0023966070730239153,
-0.00029066181741654873,
-0.009586869738996029,
0.0007350959931500256,
0.0020458714570850134,
-0.000895016361027956,
-0.0018764606211334467,
0.0010319165885448456,
-0.00026220909785479307,
-0.006500343792140484,
-0.012761102989315987,
-0.0053339493460953236,
-0.0038656825199723244,
-0.001310486695729196,
-0.01153678447008133,
-0.0030221673659980297,
-0.0077872369438409805,
0.005769241135567427,
-0.00721545098349452,
0.00788430031388998,
0.00466097192838788,
-0.006680042948573828,
0.005923718214035034,
-0.001609891070984304,
0.002702067606151104,
0.0029650211799889803,
0.004152472596615553,
0.003205415327101946,
-0.00456410413607955,
-0.009858227334916592,
0.011560819111764431,
-0.008247124031186104,
0.002327856607735157,
0.011596182361245155,
0.005949726328253746,
0.008601159788668156,
-0.0017984963487833738,
0.0018047967460006475,
0.0037328004837036133,
0.00800252053886652,
-0.013146212324500084,
0.0023897478822618723,
-0.0031189569272100925,
-0.0003982523630838841,
0.00412718066945672,
-0.002737372647970915,
0.0011089432518929243,
0.009200824424624443,
0.0017613994423300028,
-0.006806351710110903,
-0.001419203937985003,
0.0031927439849823713,
0.0038650594651699066,
-0.012142927385866642,
0.0010072084842249751,
-0.002407741965726018,
-0.004660529550164938,
-0.00044742459431290627,
-0.0011570228962227702,
0.0002872183977160603,
0.0037814027164131403,
-0.0007315546390600502,
0.004968688357621431,
0.002692755311727524,
-0.0056099845096468925,
0.014699284918606281,
-0.0051748864352703094,
-0.005138399079442024,
0.002488604513928294,
0.003047497710213065,
-0.0034711137413978577,
-0.005876814480870962,
-0.001187710091471672,
0.0026765279471874237,
0.007127757649868727,
-0.0027694276068359613,
-0.001615394838154316,
-0.0013478321488946676,
0.0012584353098645806,
-0.012958060950040817,
0.003281503217294812,
0.013033799827098846,
-0.004818079527467489,
0.006795377470552921,
-0.0015538001898676157,
-0.007705819793045521,
-0.011597290635108948,
0.049832042306661606,
-0.001565732411108911,
0.004272365942597389,
0.003141921479254961,
-0.007221773266792297,
-0.0017563822912052274,
-0.0018501805607229471,
0.00912668276578188,
-0.005859911907464266,
-0.009277818724513054,
0.009932834655046463,
-0.003563475329428911,
0.004061260260641575,
0.004558177664875984,
-0.00014017082867212594,
0.016224490478634834,
-0.0019509437261149287,
-0.017222467809915543,
-0.018228644505143166,
0.008506221696734428,
-0.005859189201146364,
-0.00456662941724062,
0.010670077055692673,
-0.0023581483401358128,
-0.006355570629239082,
0.0019326327601447701,
0.007034524343907833,
0.0022135996259748936,
0.0008340707863681018,
-0.0021287486888468266,
-0.0039052446372807026,
0.001169312628917396,
0.0011235106503590941,
0.00704330625012517,
0.006716383621096611,
-0.0031228770967572927,
0.004615209065377712,
0.0010796092683449388,
-0.0026397528126835823,
-0.0013743088347837329,
0.003098401241004467,
0.005876949056982994,
-0.0023725260980427265,
-0.003353741718456149,
0.006457933224737644,
0.004584184382110834,
0.0031867406796664,
0.008767107501626015,
-0.001313813147135079,
-0.006604176480323076,
0.00870673917233944,
0.006141552701592445,
0.0015144567005336285,
0.009505233727395535,
-0.0008411968592554331,
0.0061044469475746155,
0.0006671231240034103,
-0.008865839801728725,
-0.016496656462550163,
-0.002378168748691678,
0.007830416783690453,
0.0075093647465109825,
0.0010967652779072523,
0.002786463126540184,
-0.0008486630977131426,
-0.0010416035074740648,
-0.007573052775114775,
-0.008090054616332054,
-0.004215422086417675,
0.0025541530922055244,
0.0051915571093559265,
0.06734908372163773,
-0.006594968494027853,
-0.0006610324489884079,
-0.006286158226430416,
-0.00132046511862427,
-0.0017742696218192577,
-0.0008686215151101351,
-0.0007439189357683063,
-0.004397280514240265,
0.0032243120949715376,
0.0009954737033694983,
-0.008082635700702667,
-0.011182301677763462,
0.0002387069253018126,
0.0006286452407948673,
-0.002566487994045019,
0.004836063366383314,
0.005229048430919647,
-0.011632578447461128,
-0.0002533318765927106,
-0.012807954102754593,
-0.0036043378058820963,
-0.0028904438950121403,
-0.012136685661971569,
-0.005168501287698746,
-0.002341919345781207,
0.005849653854966164,
0.0017004499677568674,
0.004374571144580841,
-0.0027679000049829483,
0.006838721223175526,
-0.0024251241702586412,
-0.00148151780012995,
-0.005085742566734552,
-0.002897155936807394,
-0.005743963643908501,
0.008591207675635815,
0.0013690146151930094,
-0.01193717960268259,
-0.005115431267768145,
-0.0009537303703837097,
0.0003615085151977837,
-0.004111872054636478,
0.0025823856703937054,
-0.0003313109336886555,
0.005055468529462814,
-0.0019855829887092113,
0.0008401362574659288,
-0.007060305681079626,
0.0014171535149216652,
-0.010372604243457317,
0.005073048174381256,
-0.1702146679162979,
0.01055754255503416,
0.003895200788974762,
-0.005770597141236067,
-0.0032804799266159534,
-0.01335536502301693,
-0.005671606864780188,
0.0035677175037562847,
0.011310815811157227,
0.0017005058471113443,
-0.000759625225327909,
-0.0015013446100056171,
0.005986667703837156,
0.003508135210722685,
-0.0008807284757494926,
-0.0054085589945316315,
0.00411524111405015,
-0.004055562894791365,
0.0016783518949523568,
0.004925731103867292,
0.00388663774356246,
0.010364212095737457,
0.0003761409316211939,
0.003473839722573757,
-0.0025699099060148,
-0.005698974709957838,
0.006056379526853561,
-0.001055859844200313,
0.006339272018522024,
-0.010822868905961514,
-0.003794213058426976,
-0.003748144255951047,
-0.0038159573450684547,
0.0006936622085049748,
0.005722162313759327,
0.0015527268406003714,
0.008536018431186676,
0.002927980152890086,
-0.007426343392580748,
0.008278832770884037,
-0.009502504952251911,
0.028283746913075447,
0.005362191703170538,
0.0058573707938194275,
-0.0006168377003632486,
-0.006280881352722645,
-0.005774113815277815,
0.008642904460430145,
0.0020443119574338198,
0.011001786217093468,
-0.013894162140786648,
0.0015306383138522506,
0.003128503682091832,
0.01753152906894684,
-0.005087672732770443,
-0.011580320075154305,
-0.006467774976044893,
-0.0007502500084228814,
-0.00043624683166854084,
0.007425857242196798,
0.01216349471360445,
-0.002772732637822628,
0.006968389730900526,
-0.003967853728681803,
-0.02158132940530777,
0.004006401170045137,
-0.0077093299478292465,
-0.007376537192612886,
0.001678501139394939,
0.006618420127779245,
0.010976074263453484,
-0.0015430423663929105,
0.0003061551251448691,
-0.0032003477681428194,
0.007009679917246103,
0.0004587868170347065,
0.005878313444554806,
-0.0011199594009667635,
0.0038739205338060856,
-0.009903986006975174,
0.0061647286638617516,
-0.010689707472920418,
-0.004840334411710501,
0.001190840033814311,
-0.004980174358934164,
0.010607943870127201,
0.006025089416652918,
-0.0029871580190956593,
-0.0020895064808428288,
-0.00935607124119997,
-0.0044446587562561035,
0.0007461445056833327,
0.00009435696119908243,
-0.009992056526243687,
0.0037788518238812685,
0.0014607966877520084,
0.006995614618062973,
0.005884923972189426,
-0.009406832978129387,
0.0065101683139801025,
0.007161993067711592,
-0.004230011720210314,
0.000639562145806849,
-0.0024943402968347073,
0.002932873321697116,
0.0013529373100027442,
-0.005347607657313347,
-0.004404802341014147,
0.0031537471804767847,
-0.009889263659715652,
-0.003295884933322668,
0.008557519875466824,
-0.009394564665853977,
-0.011516558937728405,
-0.0025229845196008682,
-0.01184066478163004,
0.0002823508402798325
] |
8a43f4805ca2bfbefacf005fd91befea7f1c3e71 | 492 | py | Python | gen-cfg.py | magetron/secure-flow-prototype | c683939620fec889f882ea095d2b27e3e4bb98fe | [
"Apache-2.0"
] | null | null | null | gen-cfg.py | magetron/secure-flow-prototype | c683939620fec889f882ea095d2b27e3e4bb98fe | [
"Apache-2.0"
] | null | null | null | gen-cfg.py | magetron/secure-flow-prototype | c683939620fec889f882ea095d2b27e3e4bb98fe | [
"Apache-2.0"
] | null | null | null | from staticfg import CFGBuilder
userCfg = CFGBuilder().build_from_file('user.py', './auction/user.py')
bidCfg = CFGBuilder().build_from_file('bid.py', './auction/bid.py')
auctionCfg = CFGBuilder().build_from_file('auction.py','./auction/auction.py')
#auctionEventCfg = CFGBuilder().build_from_file('auction_event.py','./auction/auction_event.py')
bidCfg.build_visual('bidCfg', 'pdf')
auctionCfg.build_visual('auctionCfg', 'pdf')
#auctionEventCfg.build_visual('auctionEventCfg.pdf', 'pdf')
| 41 | 96 | 0.760163 | 1 | 0.8046 | [
0.0027733284514397383,
0.024377694353461266,
0.007135526742786169,
0.0001522550155641511,
0.005806629545986652,
-0.003922770731151104,
-0.008893601596355438,
0.0016274983063340187,
-0.00758705148473382,
0.002034358214586973,
0.004274217877537012,
0.005049391649663448,
0.008086130954325199,
-0.017396844923496246,
0.0013364870101213455,
0.015383923426270485,
-0.054320842027664185,
0.0032608823385089636,
-0.00344522250816226,
0.0008045727736316621,
-0.007255778647959232,
0.010230069980025291,
0.008859802037477493,
0.0069735087454319,
0.0060623581521213055,
0.001917587942443788,
0.008386661298573017,
0.0027668788097798824,
-0.008699764497578144,
-0.007323846686631441,
-0.0013696120586246252,
-0.0010592942126095295,
-0.005246198736131191,
-0.009304771199822426,
0.005157789681106806,
-0.00409914692863822,
0.00023903341207187623,
-0.020842295140028,
0.015061536803841591,
-0.004343701992183924,
-0.004572110250592232,
-0.0157710462808609,
0.005249067675322294,
0.005409026052802801,
-0.011422188021242619,
0.003374975174665451,
-0.004910371731966734,
0.003055620938539505,
-0.01046925038099289,
0.0036258669570088387,
-0.010850340127944946,
0.003543365513905883,
0.014132443815469742,
0.002947589149698615,
-0.004765561781823635,
-0.00635488098487258,
0.01079032476991415,
-0.0009501593303866684,
-0.011979790404438972,
-0.0003068599908147007,
-0.005310609936714172,
-0.0013461756752803922,
0.0029951592441648245,
0.004589146468788385,
-0.019173962995409966,
-0.006686392240226269,
-0.0048613459803164005,
0.0023837273474782705,
-0.001100909081287682,
0.006550313904881477,
0.0014557635877281427,
-0.0010029665427282453,
0.005215300712734461,
0.0013717745896428823,
0.003480489132925868,
-0.0031259492971003056,
-0.0007187120500020683,
0.0031399494037032127,
0.00814609695225954,
0.0020366075914353132,
0.006810585968196392,
-0.006248227786272764,
0.007013183552771807,
0.010541069321334362,
0.014198717661201954,
0.007512873038649559,
0.017467018216848373,
-0.010666687972843647,
0.04352821782231331,
0.006570729892700911,
-0.010248696431517601,
-0.00014159706188365817,
-0.009766807779669762,
-0.004066975321620703,
-0.004167953040450811,
-0.030851352959871292,
-0.0001482781080994755,
-0.0038806325756013393,
0.0010746094631031156,
0.00421949103474617,
-0.00008348082337761298,
0.005221385508775711,
0.0013405034551396966,
-0.005046155769377947,
-0.009557974524796009,
0.013557749800384045,
-0.008468667976558208,
-0.005158779211342335,
0.006142082624137402,
0.0026149272453039885,
-0.010798521339893341,
0.00020982444402761757,
0.0033639739267528057,
-0.012291591614484787,
0.005584280472248793,
0.00236011971719563,
-0.006325422786176205,
0.05650283023715019,
0.00010914325685007498,
0.0012632660800591111,
-0.0040008993819355965,
-0.0001208787871291861,
0.001035742461681366,
0.007986600510776043,
0.010789364576339722,
-0.004285510629415512,
0.010924829170107841,
0.005759445019066334,
0.004481008742004633,
0.007784190122038126,
-0.0008445567800663412,
0.00487419543787837,
-0.0018038819544017315,
-0.0024063228629529476,
0.0018875501118600368,
-0.008084514178335667,
0.010577505454421043,
-0.0031869711820036173,
-0.006668553221970797,
0.0014456723583862185,
-0.0016476453747600317,
-0.011836877092719078,
0.0019207533914595842,
-0.0013800343731418252,
0.0032533640041947365,
-0.010122060775756836,
-0.004016995429992676,
-0.0021828305907547474,
-0.004318018443882465,
0.0016769428038969636,
0.008459500037133694,
0.0041233389638364315,
0.004388577304780483,
-0.005923120304942131,
-0.007288036402314901,
-0.0008619099389761686,
-0.0064984094351530075,
0.0030995383858680725,
0.009454223327338696,
0.003182578133419156,
-0.010486631654202938,
-0.0017022253014147282,
0.002911931136623025,
0.0034972033463418484,
-0.0009653584565967321,
0.000054604468459729105,
-0.008139296434819698,
0.009564409963786602,
-0.000708981417119503,
0.0038379966281354427,
0.01291645597666502,
-0.002630519447848201,
0.0017323448555544019,
-0.0001886054960777983,
0.0017698848387226462,
-0.0018843061989173293,
0.003724254434928298,
0.010708586312830448,
-0.0012641064822673798,
-0.006237884983420372,
0.005286552477627993,
0.005471116863191128,
0.00988734234124422,
0.008217284455895424,
-0.0019863788038492203,
0.0032264215406030416,
-0.004264580085873604,
0.00018888489285018295,
0.006763479206711054,
-0.00403917720541358,
0.007637434173375368,
0.0029923857655376196,
-0.013828752562403679,
-0.007295799907296896,
-0.00043982145143672824,
-0.00801827758550644,
0.0009292318136431277,
0.015356842428445816,
0.010516004636883736,
-0.0003701634705066681,
0.0027285171672701836,
-0.009628965519368649,
0.0011557388352230191,
0.006858117412775755,
0.0019276606617495418,
-0.012890378013253212,
-0.9561929106712341,
0.004396866075694561,
0.0036570474039763212,
-0.001357716042548418,
0.005135558545589447,
0.00399742741137743,
0.001070209196768701,
0.0039887274615466595,
0.01388439629226923,
-0.008551936596632004,
-0.007567973807454109,
-0.00940370000898838,
-0.010983248241245747,
0.0002989491622429341,
-0.0063695902936160564,
-0.0025181106757372618,
-0.004157246556133032,
-0.0052675423212349415,
-0.0002652105176821351,
-0.0038672408554702997,
-0.0033449234906584024,
0.01226821355521679,
-0.0009547906229272485,
0.005304243881255388,
0.0031222300603985786,
0.004348440561443567,
-0.004725600127130747,
-0.00040894380072131753,
-0.0010619701351970434,
-0.0017326929373666644,
-0.004155392292886972,
-0.01532523799687624,
-0.006885212380439043,
0.000025464181817369536,
0.010754890739917755,
0.0005542396102100611,
0.009300800040364265,
-0.0005419508670456707,
0.002759512746706605,
-0.011804265901446342,
0.004630343988537788,
0.0023702436592429876,
0.0002803971292451024,
-0.02932094968855381,
0.0002107721084030345,
-0.0007143609109334648,
-0.004978850483894348,
0.007580892648547888,
-0.0003070081293117255,
-0.00170646992046386,
-0.003821193939074874,
-0.0038659817073494196,
0.008243544027209282,
-0.00870066974312067,
0.007536093704402447,
-0.005024689249694347,
-0.007671093102544546,
-0.002577843377366662,
-0.00994520541280508,
0.00008652467658976093,
0.003665879601612687,
-0.0052435616962611675,
-0.0033867566380649805,
-0.0022256418596953154,
0.003632365260273218,
0.0010263733565807343,
0.0004957002820447087,
-0.019314929842948914,
-0.004435382317751646,
-0.002130097709596157,
0.004056932870298624,
-0.0009134894935414195,
-0.0025211088359355927,
0.0008308750693686306,
-0.008827072568237782,
0.006720295641571283,
0.0005293785943649709,
-0.0000765133008826524,
-0.01140614878386259,
0.0016370377270504832,
-0.009601498022675514,
-0.010477736592292786,
0.003087202087044716,
-0.005277596414089203,
-0.004028737545013428,
-0.0004927896079607308,
0.003027819562703371,
0.008037064224481583,
-0.0043076882138848305,
0.0018006670288741589,
0.012690129689872265,
-0.004026951268315315,
-0.009083629585802555,
0.010195489041507244,
0.007840241305530071,
0.0008775654132477939,
-0.0036960483994334936,
0.0025170783046633005,
0.00795140489935875,
0.008044256828725338,
0.002691407222300768,
0.0052834684029221535,
0.00012107998918509111,
0.011250929906964302,
0.00010190786997554824,
0.0009961709147319198,
-0.0034019937738776207,
-0.0002594463003333658,
-0.001658547786064446,
-0.0003984913055319339,
-0.004546951036900282,
-0.00017525551083963364,
-0.010302405804395676,
-0.009809478186070919,
-0.0020159748382866383,
0.001101933652535081,
0.0010356316342949867,
-0.002755349036306143,
0.0023819992784410715,
0.0023095018696039915,
0.008444312959909439,
0.003371028695255518,
-0.003595024347305298,
-0.0014454409247264266,
0.001980655360966921,
-0.007254248019307852,
0.016381869092583656,
-0.014020675793290138,
0.005368441343307495,
0.0010134440381079912,
-0.015518911182880402,
0.007139034569263458,
0.008242582902312279,
-0.0066394987516105175,
0.0036168096121400595,
0.0014476109063252807,
0.003895388450473547,
0.0010934098390862346,
-0.006176766473799944,
-0.0016658975509926677,
-0.01703067123889923,
0.0011215637205168605,
0.020043566823005676,
0.003023796249181032,
0.010676619596779346,
0.012131395749747753,
-0.004666103981435299,
0.0006209664861671627,
0.009218867868185043,
0.0005627056816592813,
0.014524192549288273,
-0.008791947737336159,
-0.0006178165785968304,
0.0005338270566426218,
-0.006288969423621893,
0.0004878790059592575,
0.003089275909587741,
0.0065331775695085526,
-0.004324717912822962,
0.0037766213063150644,
-0.007814683020114899,
-0.005296426825225353,
-0.019466513767838478,
-0.004343540873378515,
0.006043980363756418,
-0.004217766225337982,
0.0030494260136038065,
-0.013705143705010414,
0.004874936770647764,
0.004459351766854525,
0.0032779579050838947,
-0.0028156146872788668,
-0.0009475750266574323,
0.00665918318554759,
0.012961691245436668,
-0.004944256506860256,
0.003747559618204832,
0.0022618474904447794,
-0.0033855894580483437,
0.001164420391432941,
0.008527342230081558,
-0.007712477818131447,
-0.004328067880123854,
0.0013638923410326242,
0.004571402445435524,
-0.0012503722682595253,
-0.003380714450031519,
-0.009085863828659058,
-0.006586548872292042,
0.001631923601962626,
-0.006479319650679827,
0.002898546401411295,
0.0024824077263474464,
0.003762440988793969,
-0.009107371792197227,
-0.00124846410471946,
-0.004935536999255419,
-0.011376610025763512,
0.011285223066806793,
-0.0017842513043433428,
0.0027199743781238794,
0.01338183879852295,
0.003066819394007325,
-0.014108896255493164,
0.0059484210796654224,
0.009058660827577114,
-0.004918025806546211,
0.0024449906777590513,
0.005651878193020821,
-0.004549519624561071,
-0.023173708468675613,
-0.0011441955575719476,
-0.015904532745480537,
0.006122230086475611,
-0.002048624912276864,
0.0041574095375835896,
-0.007838049903512001,
0.010960218496620655,
0.0029067881405353546,
-0.012842322699725628,
-0.005759560503065586,
-0.009229838848114014,
0.008056648075580597,
-0.0024128323420882225,
-0.002649396425113082,
-0.0034681179095059633,
-0.002165453275665641,
-0.0010448007378727198,
-0.000660765974316746,
-0.002404092578217387,
0.002860254142433405,
0.002032871823757887,
-0.005243813619017601,
-0.0013032543938606977,
-0.003942586947232485,
0.001575540634803474,
0.002781887073069811,
-0.009746828116476536,
0.0006514115375466645,
0.007342129480093718,
-0.0023877141065895557,
-0.003742004046216607,
0.0008592052035965025,
-0.0028274287469685078,
-0.008284898474812508,
-0.010291636921465397,
-0.0024368155281990767,
-0.004276235122233629,
-0.001428052899427712,
-0.011682339012622833,
-0.00303328363224864,
-0.00798717699944973,
0.007590365130454302,
-0.007951727136969566,
0.008487731218338013,
0.0046880790032446384,
-0.005073172971606255,
0.00576396519318223,
-0.002108790213242173,
0.002743043703958392,
0.005354912020266056,
0.005511815659701824,
-0.001155707985162735,
-0.006201096344739199,
-0.010658744722604752,
0.009021435864269733,
-0.00914545264095068,
0.0006865788018330932,
0.016087977215647697,
0.0036957492120563984,
0.00878207292407751,
-0.0004040562780573964,
0.0011383453384041786,
0.003684775438159704,
0.007987472228705883,
-0.014031422324478626,
0.004362333100289106,
-0.0020558058749884367,
-0.0006271192687563598,
0.004594086669385433,
-0.004025295842438936,
0.00433998741209507,
0.007704503834247589,
0.002134022768586874,
-0.005829468835145235,
-0.0012767106527462602,
0.0011547674657776952,
0.0036543572787195444,
-0.013716155663132668,
0.00021680837380699813,
-0.0029505006968975067,
-0.003989147953689098,
-0.0030084731988608837,
-0.0008395204786211252,
-0.0012545535573735833,
0.005464775022119284,
-0.00225950893945992,
0.006607820279896259,
0.003334705252200365,
-0.0022353841923177242,
0.013459591194987297,
-0.005061473231762648,
-0.006271230056881905,
0.0028431748505681753,
0.0012565510114654899,
-0.000008777969924267381,
-0.008541605435311794,
-0.0008682706393301487,
0.0005884638521820307,
0.004419376142323017,
-0.004455943591892719,
-0.006041130982339382,
-0.0026063541881740093,
0.0023027139250189066,
-0.009135820902884007,
0.0007329517393372953,
0.011705132201313972,
-0.0026510388124734163,
0.004361595958471298,
-0.0021504387259483337,
-0.0077700125984847546,
-0.016014181077480316,
0.05482048541307449,
-0.001499578938819468,
0.003517736215144396,
0.006289181765168905,
-0.007064666599035263,
-0.0038129431195557117,
-0.003008541651070118,
0.004367586690932512,
-0.00692311255261302,
-0.008431135676801205,
0.009458702057600021,
-0.003954728599637747,
0.0005457751685753465,
0.0034982068464159966,
-0.0023058566730469465,
0.016465704888105392,
-0.0035912448074668646,
-0.017971636727452278,
-0.019633745774626732,
0.005885421764105558,
-0.004547175019979477,
-0.007244949694722891,
0.007338286377489567,
-0.0037416620180010796,
-0.0024084432516247034,
0.0006651522126048803,
0.006485079415142536,
-0.00016636287909932435,
-0.001819063676521182,
-0.0012979638995602727,
-0.0005538449040614069,
-0.0010776059934869409,
0.0023974592331796885,
0.007787568494677544,
0.008923457004129887,
-0.0028575644828379154,
0.005025222897529602,
-0.00425495533272624,
-0.0019239018438383937,
-0.0012110843090340495,
0.005601666402071714,
0.007033389061689377,
-0.002401718171313405,
-0.004368274938315153,
0.0046724313870072365,
0.005543525330722332,
0.0022085842210799456,
0.011680296622216702,
0.0006978552555665374,
-0.004481927491724491,
0.00903654471039772,
0.008058354258537292,
-0.0006621362408623099,
0.00723664928227663,
-0.0017307116650044918,
0.005968563258647919,
0.0019261601846665144,
-0.009825222194194794,
-0.013986805453896523,
-0.0026079302188009024,
0.008782310411334038,
0.007688518147915602,
-0.0007183909765444696,
0.0032009996939450502,
-0.0018159457249566913,
-0.004085636232048273,
-0.0077980197966098785,
-0.006932826247066259,
-0.0011568970512598753,
0.002660882193595171,
0.004447528626769781,
0.07067443430423737,
-0.006865962408483028,
-0.002015249338001013,
-0.009056255221366882,
-0.0009300239034928381,
-0.001143089379183948,
-0.0019357693381607533,
-0.000013882302482670639,
-0.0010164964478462934,
0.0009308919543400407,
0.0025570255238562822,
-0.0077290781773626804,
-0.012476613745093346,
0.0015728625003248453,
0.0030981963500380516,
-0.004445242695510387,
0.0013011515839025378,
0.007643317338079214,
-0.007037603762000799,
0.002541240071877837,
-0.012183954939246178,
-0.0010085105895996094,
-0.00048616473213769495,
-0.007686703000217676,
-0.0022818176075816154,
-0.0049576424062252045,
0.0034888647496700287,
0.0036171881947666407,
0.0047884853556752205,
-0.005671504884958267,
0.0059196799993515015,
-0.0017069353489205241,
-0.000987922539934516,
-0.003733049612492323,
-0.0015748010482639074,
-0.006190533749759197,
0.006924927234649658,
0.0015931233065202832,
-0.012481903657317162,
-0.006648729555308819,
-0.0012312930775806308,
-0.0017698475858196616,
-0.005935417953878641,
0.005454057827591896,
0.000513823761139065,
0.004311653785407543,
-0.0030320824589580297,
0.00431744335219264,
-0.005082303192466497,
0.0016749432543292642,
-0.013105022720992565,
0.00525966752320528,
-0.18073402345180511,
0.012221545912325382,
0.003950588870793581,
-0.0070815118961036205,
-0.002869674935936928,
-0.015304706990718842,
-0.008406131528317928,
0.0030138222500681877,
0.008785507641732693,
0.0020843849051743746,
-0.0010427274974063039,
0.0002544246963225305,
0.003764994442462921,
0.0035039607901126146,
-0.003588614286854863,
-0.0041600968688726425,
0.005396129097789526,
-0.005130166653543711,
0.001248826738446951,
0.005299738608300686,
0.005031973123550415,
0.008257267065346241,
0.0029720484744757414,
0.001891870517283678,
-0.001075173495337367,
-0.0068593923933804035,
0.005301794968545437,
-0.001081629074178636,
0.0058243656530976295,
-0.0134128388017416,
-0.005463723558932543,
-0.006009895354509354,
-0.001692167017608881,
-0.0011109678307548165,
0.00554078072309494,
-0.0017358064651489258,
0.008215995505452156,
0.002470200415700674,
-0.007556124124675989,
0.009288739413022995,
-0.0074636852368712425,
0.02909471094608307,
0.0074329380877316,
0.0069043999537825584,
-0.0007814618293195963,
-0.002127588726580143,
-0.003515394637361169,
0.011629311367869377,
0.0025803849566727877,
0.012789642438292503,
-0.011886528693139553,
-0.0018779773963615298,
0.0035109638702124357,
0.019287480041384697,
-0.003608524799346924,
-0.00851873867213726,
-0.006378781050443649,
-0.0047801174223423,
0.002485510427504778,
0.00932244025170803,
0.008830574341118336,
-0.005815920419991016,
0.009823196567595005,
-0.002455724636092782,
-0.022680679336190224,
0.003913429100066423,
-0.0019980997312813997,
-0.00739690288901329,
0.002563612535595894,
0.0051902588456869125,
0.010724575258791447,
-0.0029129083268344402,
0.0020937244407832623,
-0.0011814497411251068,
0.002474800916388631,
-0.0028170382138341665,
0.007705360185354948,
-0.00003575931623345241,
0.008315847255289555,
-0.009088407270610332,
0.011026820167899132,
-0.00845929142087698,
-0.002176256850361824,
0.0027923118323087692,
-0.002813746454194188,
0.00853530503809452,
0.005076582543551922,
-0.0027134036645293236,
0.0008332294528372586,
-0.01231606025248766,
-0.003607074497267604,
0.0027842773124575615,
0.002623225562274456,
-0.00926773902028799,
0.003473305841907859,
0.00028872271650470793,
0.005271445028483868,
0.006519452668726444,
-0.008989596739411354,
0.006901691667735577,
0.004427261650562286,
-0.006561066024005413,
-0.0007610167376697063,
-0.005015104543417692,
0.001667429693043232,
0.00322691909968853,
-0.006911861710250378,
-0.009024811908602715,
0.004034694749861956,
-0.005818746518343687,
-0.004308334551751614,
0.005831289570778608,
-0.010269311256706715,
-0.009349941276013851,
0.0010205660946667194,
-0.010283000767230988,
0.002674852730706334
] |
8a44052cfce16663b8820adca1028bccdfa9a1aa | 438 | py | Python | CodeForces/A2OJ Ladder/softuni_problem.py | dimitrov-dimitar/competitive-programming | f2b022377baf6d4beff213fc513907b774c12352 | [
"MIT"
] | null | null | null | CodeForces/A2OJ Ladder/softuni_problem.py | dimitrov-dimitar/competitive-programming | f2b022377baf6d4beff213fc513907b774c12352 | [
"MIT"
] | null | null | null | CodeForces/A2OJ Ladder/softuni_problem.py | dimitrov-dimitar/competitive-programming | f2b022377baf6d4beff213fc513907b774c12352 | [
"MIT"
] | null | null | null | total_budget = 0
while True:
destination = input()
if destination == "End":
break
minimal_budget = float(input())
while True:
command = input()
if command == "End":
break
money = float(command)
total_budget += money
if total_budget >= minimal_budget:
print(f"Going to {destination}!")
total_budget = 0
break
| 24.333333 | 46 | 0.513699 | 1 | 0.7551 | [
0.002584138186648488,
0.0303651113063097,
0.01004650816321373,
-0.002158218063414097,
0.0038848870899528265,
-0.007755898870527744,
-0.01648549549281597,
0.006570159923285246,
-0.008838053792715073,
0.00015310209710150957,
-0.002637491561472416,
0.00318445754237473,
0.012143258936703205,
-0.023485835641622543,
0.0004007804091088474,
0.025416916236281395,
-0.05445843189954758,
-0.001704433117993176,
-0.005510606337338686,
0.004925610963255167,
-0.007688727229833603,
0.013101131655275822,
0.009360458701848984,
0.005786966532468796,
0.010557055473327637,
0.005061544012278318,
0.014636259526014328,
0.005657141096889973,
-0.007266242988407612,
-0.008101577870547771,
-0.004623766057193279,
-0.005422548390924931,
-0.009695791639387608,
-0.011056313291192055,
0.0015946836210787296,
-0.003712027333676815,
0.0013719621347263455,
-0.018221009522676468,
0.017369285225868225,
-0.00859763752669096,
-0.008191515691578388,
-0.024026136845350266,
0.0019428660161793232,
0.01072393637150526,
-0.008937397971749306,
0.00654705660417676,
-0.007597832940518856,
0.0010090055875480175,
-0.010662694461643696,
0.0028043026104569435,
-0.013265692628920078,
0.003728324780240655,
0.012378477491438389,
0.006692587863653898,
-0.0019598351791501045,
-0.010493402369320393,
0.012470211833715439,
-0.0018140885513275862,
-0.015317747369408607,
-0.0014079123502597213,
-0.001221556798554957,
-0.004037207458168268,
0.007604536600410938,
0.0024466668255627155,
-0.02252783253788948,
-0.011016033589839935,
-0.008168058469891548,
0.0064369672909379005,
-0.006880907341837883,
0.0030164166819304228,
0.0016210239846259356,
-0.00130089046433568,
0.008015772327780724,
0.0025741897989064455,
-0.0017184463795274496,
-0.00714476453140378,
-0.010762312449514866,
0.0048988754861056805,
0.008855868130922318,
0.0012797245290130377,
0.007580594625324011,
-0.012425576336681843,
0.00904178898781538,
0.014646880328655243,
0.014758453704416752,
0.009206610731780529,
0.01718074455857277,
-0.013814824633300304,
0.039516061544418335,
0.005591494031250477,
-0.008446910418570042,
0.00388172990642488,
-0.012430522590875626,
-0.004548400640487671,
-0.0005253306590020657,
-0.03835758939385414,
0.0006785436999052763,
-0.005423756316304207,
-0.001360689871944487,
0.0050653512589633465,
0.003234111936762929,
0.007264507468789816,
0.003806804772466421,
-0.002564468886703253,
-0.012483812868595123,
0.01940295100212097,
-0.015453135594725609,
-0.007200927007943392,
0.012758462689816952,
-0.001701062428764999,
-0.02056456357240677,
-0.001514142146334052,
0.009490137919783592,
-0.016330720856785774,
0.00635806517675519,
0.0016566169215366244,
-0.006381591781973839,
0.06617379188537598,
0.002742065116763115,
0.0009291582391597331,
-0.008639661595225334,
0.0020172586664557457,
0.0009284962434321642,
0.008124170824885368,
0.009939135983586311,
-0.009018778800964355,
0.007614567875862122,
0.00838907528668642,
0.0014860500814393163,
0.0023654696997255087,
0.0016251183114945889,
0.003968790639191866,
-0.005538147874176502,
0.003420980181545019,
0.008090692572295666,
-0.008525527082383633,
0.012732032686471939,
-0.0005554364761337638,
-0.000859656254760921,
-0.004635859280824661,
0.001565641607157886,
-0.01755410246551037,
0.008496864698827267,
0.0026713116094470024,
-0.001450293348170817,
-0.015164160169661045,
-0.007106630597263575,
-0.004727437160909176,
-0.007728784345090389,
-0.00048705397057347,
0.01008908823132515,
0.010443390347063541,
0.0000605048771831207,
-0.010277693159878254,
-0.004867592826485634,
-0.005559911951422691,
-0.004526756703853607,
0.004433741327375174,
0.013799702748656273,
0.005982928443700075,
-0.007068634498864412,
-0.009287004359066486,
0.002468904945999384,
0.005425149574875832,
0.003903529839590192,
0.002200140617787838,
-0.009892996400594711,
0.006516043562442064,
0.006667819805443287,
0.0014615734107792377,
0.013733708299696445,
-0.00518434913828969,
-0.006586738396435976,
0.0034480728209018707,
-0.0011405866825953126,
0.005977100692689419,
0.0012772262562066317,
0.010450678877532482,
-0.00810249149799347,
-0.006594415288418531,
0.010486138984560966,
0.0045644622296094894,
0.005702497903257608,
0.0054414658807218075,
-0.0019576402846723795,
-0.00020814535673707724,
-0.0010918680345639586,
0.0030999931041151285,
0.008689049631357193,
-0.009879061952233315,
0.010288748890161514,
0.012104473076760769,
-0.020899321883916855,
-0.0100047392770648,
0.0027963146567344666,
-0.00888042338192463,
0.0016425363719463348,
0.013003421016037464,
0.005978019908070564,
0.0024926583282649517,
-0.005034322384744883,
-0.01753273978829384,
-0.0005699701723642647,
0.011829234659671783,
0.0001092048769351095,
-0.009524200111627579,
-0.9434155225753784,
0.0036797234788537025,
-0.00005295558730722405,
0.0019202925032004714,
0.002446211175993085,
0.005514337681233883,
0.008605423383414745,
0.004588877782225609,
0.018669910728931427,
-0.013891205191612244,
-0.005955023225396872,
-0.012278844602406025,
-0.012382111512124538,
0.0004158603260293603,
-0.00823258887976408,
-0.008081219159066677,
-0.009591749869287014,
-0.010291515849530697,
0.0007400250760838389,
-0.0015541270840913057,
-0.003578235162422061,
0.012315737083554268,
0.008216512389481068,
-0.0008957745740190148,
0.007997626438736916,
0.0008760140044614673,
-0.008821140974760056,
-0.003986007533967495,
0.002807012991979718,
0.00283672078512609,
-0.0012160419719293714,
-0.016394805163145065,
-0.006573464255779982,
0.0010331436060369015,
0.01659940555691719,
0.0006393896765075624,
0.011447029188275337,
-0.000324401626130566,
-0.004875510465353727,
-0.012090343981981277,
0.006843466777354479,
0.0008064875146374106,
0.0004664588486775756,
-0.028563247993588448,
0.005110312718898058,
-0.004950856324285269,
-0.007474950980395079,
0.009865280240774155,
0.0033296444453299046,
0.00046402684529311955,
-0.004011307377368212,
-0.0018283349927514791,
0.0018802942940965295,
-0.013470424339175224,
0.0051791612058877945,
0.000998302479274571,
-0.0034466544166207314,
-0.0003970480465795845,
-0.016937410458922386,
0.0008545921882614493,
0.003264819039031863,
-0.006449177395552397,
-0.0011988779297098517,
-0.002804334508255124,
0.002272888319566846,
-0.006487107370048761,
0.011770754121243954,
-0.01629839837551117,
-0.009050124324858189,
-0.0033768904395401478,
0.002044480526819825,
0.0003962630871683359,
-0.00623741839081049,
-0.002161000156775117,
-0.013230838812887669,
0.005603231955319643,
-0.002383518498390913,
-0.0008515338413417339,
-0.015981964766979218,
0.003382221795618534,
-0.009404991753399372,
-0.012195615097880363,
0.008164688013494015,
-0.007501591462641954,
-0.00499560683965683,
0.000323061685776338,
0.004597915802150965,
0.007918326184153557,
-0.0034410252701491117,
-0.0030944268219172955,
0.008319403044879436,
-0.00005120720015838742,
-0.018111608922481537,
0.007406238932162523,
0.005049164406955242,
-0.0008972518844529986,
0.003990541212260723,
0.004615682177245617,
0.007432150188833475,
0.01004708930850029,
-0.004613108467310667,
0.002176383277401328,
0.0057960981503129005,
0.014978287741541862,
-0.003880827920511365,
0.0039723534137010574,
-0.00523974047973752,
0.0021894546225667,
-0.0029357229359447956,
0.0009446514886803925,
-0.006208783946931362,
0.0018809634493663907,
-0.013255525380373001,
-0.010471131652593613,
-0.010879344306886196,
0.007826858200132847,
-0.0029515190981328487,
-0.007436603307723999,
0.0021551817189902067,
0.0005272986018098891,
0.011138269677758217,
0.0012194063747301698,
-0.005937566049396992,
0.00043516818550415337,
0.0020636036060750484,
-0.007243284489959478,
0.015476390719413757,
-0.012009641155600548,
0.0029249151702970266,
-0.004681564401835203,
-0.019120806828141212,
0.006148087326437235,
0.015279746614396572,
-0.009324107319116592,
0.003506890730932355,
-0.002587768482044339,
0.006670825183391571,
-0.004650361370295286,
0.00019515687017701566,
-0.004321024753153324,
-0.02171359583735466,
0.0031494598370045424,
0.024312440305948257,
0.007504339329898357,
0.011209515854716301,
0.01612337864935398,
-0.004155516624450684,
0.007139948662370443,
0.011824419721961021,
0.0002405608247499913,
0.012649507261812687,
-0.00665438873693347,
-0.002864236244931817,
0.0012840728741139174,
-0.002189171966165304,
0.0053940946236252785,
0.0030809761956334114,
0.001522576087154448,
-0.007474859710782766,
-0.0002957282995339483,
-0.0034835380502045155,
-0.002852929523214698,
-0.017197130247950554,
0.001962437992915511,
0.011258570477366447,
-0.007479763589799404,
0.0023310973774641752,
-0.01811285689473152,
0.011017692275345325,
0.005999682005494833,
0.0004478995979297906,
-0.00046717203804291785,
0.005982821341603994,
0.008498345501720905,
0.013112504966557026,
-0.0056600430980324745,
0.0033736522309482098,
0.0007868400425650179,
0.0004609320021700114,
0.004641831386834383,
0.006505943834781647,
-0.011491190642118454,
-0.00628082687035203,
0.0069584352895617485,
0.0029537449590861797,
0.0009933736873790622,
-0.0037106501404196024,
-0.00792625080794096,
-0.005412050988525152,
0.0026408445555716753,
-0.007989367470145226,
0.005249728448688984,
-0.0012044014874845743,
0.004196339286863804,
-0.010374687612056732,
0.00034148566192016006,
-0.00003704107439261861,
-0.01424316968768835,
0.010531459003686905,
-0.003743570065125823,
0.0009204051457345486,
0.006824124604463577,
0.0039697675965726376,
-0.015886196866631508,
0.0070236301980912685,
0.008369360119104385,
-0.01204998791217804,
-0.00008675269782543182,
0.00811203196644783,
-0.00909291673451662,
-0.025227779522538185,
0.004996068309992552,
-0.015208274126052856,
0.011882425285875797,
-0.008207608014345169,
-0.00420071417465806,
-0.013136006891727448,
0.009023424237966537,
-0.00016961676010396332,
-0.007610740140080452,
-0.0062461793422698975,
-0.009437628090381622,
0.008223281241953373,
-0.008376012556254864,
-0.00760452076792717,
-0.0023570265620946884,
-0.0017623287858441472,
-0.0056447843089699745,
-0.0013609608868137002,
-0.0009638246847316623,
-0.0012801409466192126,
0.005791542585939169,
-0.003685639938339591,
-0.0029338973108679056,
-0.00041686047916300595,
-0.0003680615627672523,
0.004689010791480541,
-0.011037019081413746,
0.000834703678265214,
0.008585265837609768,
0.0030153391417115927,
-0.009871501475572586,
0.0013320889556780457,
-0.003239191137254238,
-0.0047694663517177105,
-0.010800168849527836,
-0.002214409178122878,
-0.001968296244740486,
-0.005916927009820938,
-0.013064615428447723,
-0.0020747289527207613,
-0.007691604550927877,
0.010902250185608864,
-0.009192921221256256,
0.010920383967459202,
0.007879727520048618,
-0.0015060724690556526,
0.014192067086696625,
-0.005063154734671116,
0.004839612171053886,
-0.006066351197659969,
0.007933507673442364,
0.0028563295491039753,
-0.003729727119207382,
-0.012807984836399555,
0.00759804667904973,
-0.012730669230222702,
0.0008933155331760645,
0.01661015674471855,
0.005808393936604261,
0.010178886353969574,
0.0027919893618673086,
-0.0012982962653040886,
0.007128280121833086,
0.008143836632370949,
-0.013074783608317375,
0.004074102267622948,
-0.0018565739737823606,
-0.004591038450598717,
0.003128956537693739,
-0.0020920708775520325,
-0.0010997506324201822,
0.004574843682348728,
0.004140622913837433,
-0.002956006908789277,
-0.004769288469105959,
0.0006325550493784249,
0.002799643436446786,
-0.014189197681844234,
-0.008121859282255173,
-0.007715064100921154,
-0.011483434587717056,
-0.009872833266854286,
0.0013134251348674297,
-0.0033765104599297047,
0.006508172955363989,
-0.004717573057860136,
0.00829850323498249,
0.007334351539611816,
-0.004045718815177679,
0.012924032285809517,
0.00013705019955523312,
-0.00032962780096568167,
0.005921361036598682,
0.0011681171599775553,
0.0003002307494170964,
-0.0013717005494982004,
-0.00034492684062570333,
-0.001536921481601894,
0.00628797709941864,
-0.0001854335714597255,
-0.004506474826484919,
-0.002002118155360222,
-0.0026273096445947886,
-0.012712029740214348,
0.00048390208394266665,
0.005867045372724533,
-0.002746465615928173,
0.0004103283863514662,
0.004407046362757683,
-0.005859664641320705,
-0.022110797464847565,
0.058238010853528976,
0.001623540767468512,
-0.0008580081048421562,
0.010403504595160484,
-0.004591391887515783,
-0.0016627234872430563,
-0.00404764199629426,
0.007303870283067226,
-0.003185083158314228,
-0.007915016263723373,
0.012775047682225704,
-0.0056612263433635235,
-0.0022568716667592525,
-0.001034173765219748,
-0.003196357050910592,
0.02271459624171257,
-0.009846522472798824,
-0.018660861998796463,
-0.011621487326920033,
0.008554374799132347,
-0.001731968019157648,
-0.0020827725529670715,
0.006597152911126614,
-0.0020680283196270466,
0.00654224818572402,
0.0071188523434102535,
0.006746949162334204,
-0.001392293255776167,
-0.00123941944912076,
-0.006414014380425215,
0.0005669518723152578,
0.001107103773392737,
0.0016033760039135814,
0.00267316703684628,
0.010163773782551289,
-0.0020177981350570917,
0.005638593807816505,
0.006905755493789911,
-0.001143291825428605,
0.0004075733304489404,
0.009840917773544788,
0.011466649360954762,
-0.005125921219587326,
-0.0019418378360569477,
0.007332024164497852,
0.006816659588366747,
-0.0005267225787974894,
0.016852041706442833,
-0.004343877546489239,
-0.00893399864435196,
0.011410687118768692,
0.010044625960290432,
-0.006241928786039352,
0.009824548847973347,
0.0005215259152464569,
0.006416411604732275,
-0.00023536046501249075,
-0.010282518342137337,
-0.010448271408677101,
-0.00013176805805414915,
0.00907059945166111,
0.009977200999855995,
-0.002995359478518367,
-0.006477136164903641,
0.0033021161798387766,
-0.00014970912889111787,
-0.017870454117655754,
-0.010531256906688213,
-0.0049458774738013744,
0.0008186250342987478,
0.007763983216136694,
0.08306534588336945,
-0.005649376194924116,
-0.0035316937137395144,
-0.009516622871160507,
0.00433033611625433,
-0.0019436845323070884,
0.0033676240127533674,
-0.002460828982293606,
-0.0015488199423998594,
0.0008495333604514599,
0.0037524893414229155,
-0.008127379231154919,
-0.008895966224372387,
0.0006930021336302161,
0.0061257751658558846,
0.0008011764148250222,
0.006398540455847979,
0.009845152497291565,
-0.007118553854525089,
0.003108867909759283,
-0.012064569629728794,
-0.007144390605390072,
-0.004269225522875786,
-0.008613214828073978,
-0.0025862858165055513,
-0.0028076902963221073,
-0.001437369384802878,
0.001385264447890222,
0.006305169314146042,
-0.01389832329005003,
-0.0002218840381829068,
-0.00017448324069846421,
0.004794029518961906,
-0.0027477594558149576,
0.002690408378839493,
-0.006303488276898861,
0.009676420129835606,
0.00022566752159036696,
-0.010687841102480888,
-0.00972217507660389,
-0.00020524734281934798,
-0.0017448989674448967,
-0.010502290911972523,
0.0069177113473415375,
0.001971072517335415,
0.013402525335550308,
-0.0028083438519388437,
0.0061876545660197735,
-0.004656615201383829,
0.006758618168532848,
-0.01063027698546648,
0.005140773020684719,
-0.1941245049238205,
0.013317305594682693,
-0.0011222203029319644,
-0.004817976616322994,
-0.001499993377365172,
-0.01835373044013977,
-0.009267843328416348,
0.001150212250649929,
0.011615949682891369,
0.00030293213785625994,
0.0025406046770513058,
0.0004543079121503979,
0.012637754902243614,
0.0026889978908002377,
0.0003162685316056013,
-0.0049099489115178585,
0.005953672342002392,
-0.002153267851099372,
0.0005669694510288537,
0.005280205514281988,
0.010607791133224964,
0.004645720589905977,
0.005273997317999601,
0.002530905418097973,
-0.002885259687900543,
-0.00691607128828764,
0.0020769494585692883,
-0.0010448809480294585,
0.006778917275369167,
-0.009215082041919231,
-0.001159909414127469,
-0.008650040253996849,
0.0016009981045499444,
0.0008895504870451987,
0.004347342532128096,
-0.0012945594498887658,
0.009378690272569656,
0.0016284264856949449,
-0.006186254788190126,
0.009904270991683006,
-0.008843507617712021,
0.03071468695998192,
0.0017328779213130474,
0.015386204235255718,
0.005164207424968481,
0.0005299912299960852,
-0.003963741473853588,
0.011095138266682625,
0.0043233116157352924,
0.012026495300233364,
-0.008801820687949657,
-0.007693310268223286,
-0.0008649229421280324,
0.018830610439181328,
-0.005062387324869633,
-0.014771242626011372,
-0.008381037041544914,
-0.004416043404489756,
0.004388194065541029,
0.019045362249016762,
0.007140615489333868,
-0.00987927708774805,
0.009904416278004646,
-0.007753246929496527,
-0.019454924389719963,
0.0038695659022778273,
-0.0017670313827693462,
-0.011323134414851665,
0.000950952060520649,
0.004199171904474497,
0.023227736353874207,
-0.003956293221563101,
0.014826935715973377,
0.0030562656465917826,
-0.0018580334726721048,
-0.006992444861680269,
0.00994837749749422,
-0.007172498852014542,
0.006870642304420471,
-0.009058895520865917,
0.0065491111017763615,
-0.009031830355525017,
0.0007282209116965532,
-0.0012774710776284337,
-0.003119582775980234,
0.010198413394391537,
0.003094671294093132,
0.00013035786105319858,
0.00012937466090079397,
-0.012102597393095493,
-0.0015706304693594575,
0.0009094668203033507,
0.0071918717585504055,
-0.0068693323992192745,
-0.00021858383843209594,
-0.006234734784811735,
0.003615129739046097,
0.008586856536567211,
-0.013743413612246513,
0.0025923792272806168,
0.00972831156104803,
-0.008453610353171825,
0.0004764484183397144,
0.003179343417286873,
0.007340220268815756,
0.004222726449370384,
-0.0085730766877532,
-0.008708302862942219,
0.0029331331606954336,
-0.006297827698290348,
0.00007422511407639831,
0.01028827577829361,
-0.00831433106213808,
0.0008565894095227122,
0.0034761938732117414,
-0.01546703651547432,
-0.00016710461932234466
] |
8a441182ab86ba1e69b301671e3fe079d2030d2e | 406 | py | Python | footmark/ram/regioninfo.py | rockzhu/footmark | af2144e9139a63b475fa2b56c3307ddfd49c43e4 | [
"Apache-2.0"
] | null | null | null | footmark/ram/regioninfo.py | rockzhu/footmark | af2144e9139a63b475fa2b56c3307ddfd49c43e4 | [
"Apache-2.0"
] | null | null | null | footmark/ram/regioninfo.py | rockzhu/footmark | af2144e9139a63b475fa2b56c3307ddfd49c43e4 | [
"Apache-2.0"
] | null | null | null | from footmark.regioninfo import RegionInfo
class RAMRegionInfo(RegionInfo):
"""
Represents an ram Region
"""
def __init__(self, connection=None, name=None, id=None,
connection_cls=None):
from footmark.ram.connection import RAMConnection
super(RAMRegionInfo, self).__init__(connection, name, id,
RAMConnection)
| 29 | 65 | 0.618227 | 1 | 0.7401 | [
-0.0017021262319758534,
0.02391822822391987,
0.006204466335475445,
0.003422098932787776,
0.007462409790605307,
-0.006072914693504572,
-0.012774854898452759,
0.0066989087499678135,
-0.005796240642666817,
0.0008719222969375551,
0.001514800707809627,
0.006560119334608316,
0.009111011400818825,
-0.014428953640162945,
-0.0003735784557648003,
0.020063675940036774,
-0.056699320673942566,
0.00479884585365653,
-0.0066882288083434105,
0.003022504737600684,
-0.009210648015141487,
0.008455331437289715,
0.009162891656160355,
0.01141354814171791,
0.003804134903475642,
-0.0023523506242781878,
0.011255850084125996,
0.0025826902128756046,
-0.0018256952753290534,
-0.005959727801382542,
0.00019165458797942847,
-0.0038763624615967274,
-0.0035198074765503407,
-0.0066826557740569115,
0.007217296864837408,
-0.0017342852661386132,
0.0013084380188956857,
-0.022347571328282356,
0.008717777207493782,
-0.007347884587943554,
-0.008793190121650696,
-0.01887476071715355,
-0.0072814784944057465,
0.007980866357684135,
-0.011693782173097134,
0.002271544886752963,
-0.003995913080871105,
0.00540628656744957,
-0.009565961547195911,
0.0057345484383404255,
-0.011730145663022995,
0.0053068771958351135,
0.011759827844798565,
0.0030652331188321114,
-0.007319612428545952,
-0.009721293114125729,
0.011299791745841503,
-0.0032029543071985245,
-0.012327071279287338,
0.00300167640671134,
0.0013240617699921131,
-0.00469466857612133,
0.004517178982496262,
0.004977216478437185,
-0.018981147557497025,
-0.0073332590982317924,
-0.006318970117717981,
0.004195834510028362,
-0.00040237943176180124,
0.005327286198735237,
-0.0014249174855649471,
-0.00022278516553342342,
0.011446555145084858,
0.003758880775421858,
0.0011882326798513532,
-0.0038792903069406748,
-0.0022273180074989796,
-0.000026668847567634657,
0.007219626568257809,
0.0031201753299683332,
0.00380444573238492,
-0.00940985232591629,
0.0060334582813084126,
0.011231188662350178,
0.013395974412560463,
0.016473213210701942,
0.023435724899172783,
-0.010807370766997337,
0.04338363930583,
0.00934810284525156,
-0.00946750771254301,
0.00503684813156724,
-0.0066832429729402065,
-0.005597063805907965,
-0.000876318197697401,
-0.032437361776828766,
0.002247681375592947,
-0.002018382539972663,
-0.001931172562763095,
0.007974304258823395,
0.0007535848417319357,
0.006782496813684702,
-0.00367743126116693,
-0.0017987674800679088,
-0.011564826592803001,
0.014211691915988922,
-0.011581845581531525,
0.0019116965122520924,
0.008777582086622715,
0.001152919023297727,
-0.014279782772064209,
-0.002299215644598007,
0.0039526959881186485,
-0.013178614899516106,
0.0013344414765015244,
0.0013291443465277553,
-0.0061361342668533325,
0.06051040068268776,
-0.005074258428066969,
0.006819384638220072,
-0.008311844430863857,
-0.003190371673554182,
0.0016405482310801744,
0.006070009432733059,
0.007666361518204212,
-0.003820916870608926,
0.011460267938673496,
0.008197035640478134,
0.002994296606630087,
0.007474653888493776,
0.0011274730786681175,
0.008300130255520344,
-0.004297999199479818,
-0.0018951913807541132,
-0.0014648598153144121,
-0.008905794471502304,
0.004384420812129974,
0.00008711738337296993,
-0.007576919626444578,
-0.0016553798923268914,
0.0018958203727379441,
-0.015996068716049194,
0.00039437945815734565,
-0.0020110299810767174,
0.00143567961640656,
-0.015778815373778343,
-0.0053030820563435555,
-0.003851084504276514,
-0.00467445096001029,
0.0027998341247439384,
0.007891272194683552,
0.003390713594853878,
0.002997289877384901,
-0.00546907028183341,
-0.008188113570213318,
-0.0039191292598843575,
-0.007475258316844702,
0.002620881889015436,
0.00679616816341877,
0.004736857954412699,
-0.009401869028806686,
-0.0022789305076003075,
0.004997354932129383,
0.008514005690813065,
0.00011079413525294513,
-0.0004761643649544567,
-0.007327644154429436,
0.012357020750641823,
0.0016638305969536304,
0.00036289679701440036,
0.014217999763786793,
-0.006914278492331505,
0.002093068091198802,
0.0011522957356646657,
0.0016906553646549582,
0.002413024427369237,
0.005105587188154459,
0.008366026915609837,
-0.005359287839382887,
-0.007296194788068533,
0.0056121028028428555,
0.0028627500869333744,
0.01103093009442091,
0.009750453755259514,
-0.0029056393541395664,
0.0030085300095379353,
-0.003828474786132574,
-0.0017617057310417295,
0.0038399072363972664,
-0.006907842122018337,
0.007460102904587984,
0.005604515317827463,
-0.014590420760214329,
-0.007380262017250061,
0.0014677478466182947,
-0.011341368779540062,
-0.0005925450823269784,
0.01813986711204052,
0.011540361680090427,
-0.0028522873762995005,
0.003918647300451994,
-0.010673539713025093,
0.0026616074610501528,
0.003945875447243452,
0.004111638758331537,
-0.014993567019701004,
-0.9525090456008911,
0.006948975380510092,
0.0038412497378885746,
0.0010704193264245987,
0.002137484960258007,
0.003773457370698452,
0.003355718683451414,
0.0011897132499143481,
0.01699490286409855,
-0.012255233712494373,
-0.007420911453664303,
-0.010009932331740856,
-0.013485347852110863,
0.004226116929203272,
-0.0075132278725504875,
-0.003296044422313571,
-0.0045342640951275826,
-0.009454820305109024,
-0.0016392215620726347,
-0.004850316327065229,
0.0005577839910984039,
0.010044978931546211,
-0.00034083088394254446,
0.005779552273452282,
0.00440107611939311,
0.006396084558218718,
-0.00937158428132534,
-0.0008565834141336381,
0.00015621152124367654,
-0.002635134616866708,
-0.007907065562903881,
-0.014957533217966557,
-0.005406797863543034,
-0.0008303778013214469,
0.012958874925971031,
-0.0010101579828187823,
0.008923501707613468,
0.002149802865460515,
0.004412190988659859,
-0.009321535006165504,
0.007945613004267216,
0.0032473092433065176,
0.0059263515286147594,
-0.03013194352388382,
0.0005992532824166119,
-0.0033569748047739267,
-0.007852781563997269,
0.009125391021370888,
0.006314137950539589,
-0.0027502349112182856,
-0.00040415325202047825,
-0.006491411477327347,
0.010700833052396774,
-0.007007375825196505,
0.002415603259578347,
-0.003282112069427967,
-0.0076353889890015125,
-0.0036985466722398996,
-0.009270044974982738,
0.00399315869435668,
0.006185784470289946,
-0.0019068872788920999,
-0.0015784291317686439,
-0.0027380273677408695,
0.0008406784618273377,
0.003024980193004012,
0.0009872876107692719,
-0.017971709370613098,
-0.008961468003690243,
-0.004919414408504963,
0.004916978068649769,
-0.001612096675671637,
-0.00456572137773037,
0.007355698850005865,
-0.011327407322824001,
0.005083621479570866,
0.0036290856078267097,
0.002709515392780304,
-0.011579088866710663,
0.005297897849231958,
-0.00842398963868618,
-0.007873790338635445,
0.002084438456222415,
-0.006845414638519287,
-0.0033314768224954605,
0.0026658836286514997,
0.000572521414142102,
0.008324716240167618,
-0.0044619617983698845,
0.005069198552519083,
0.01240665465593338,
-0.0038331497926265,
-0.008992468938231468,
0.008973922580480576,
0.009247059002518654,
0.005736388266086578,
-0.00046658600331284106,
-0.0005848173750564456,
0.010126220062375069,
0.007985268719494343,
-0.0003671299200505018,
0.0029605692252516747,
-0.0007212205091491342,
0.013110624626278877,
-0.000227057229494676,
0.0033234115689992905,
-0.0037001557648181915,
-0.0003782915882766247,
-0.007808721158653498,
-0.004309055395424366,
-0.0063565568998456,
0.0015273228054866195,
-0.015686538070440292,
-0.009249437600374222,
-0.0033674139995127916,
0.0007913775625638664,
-0.0009398384718224406,
-0.008443760685622692,
0.0003869820211548358,
0.00104169559199363,
0.010480605997145176,
-0.0007662242278456688,
-0.005908315069973469,
-0.00021604259382002056,
0.006130686029791832,
-0.010222367011010647,
0.012652953155338764,
-0.010499938391149044,
0.005855816416442394,
-0.0019262112909927964,
-0.019112182781100273,
0.009306679479777813,
0.008775942027568817,
-0.006355534307658672,
0.003456495236605406,
-0.00029069912852719426,
0.0035679652355611324,
-0.0011666242498904467,
-0.0012651750585064292,
-0.005561379715800285,
-0.017736168578267097,
0.0006936602294445038,
0.022521432489156723,
-0.0009167550597339869,
0.008810421451926231,
0.007559836842119694,
-0.004783589858561754,
0.0035770535469055176,
0.006191316992044449,
-0.0019112469162791967,
0.010937738232314587,
-0.006813214626163244,
-0.0009420056594535708,
-0.001397056388668716,
-0.006146616768091917,
0.0020180153660476208,
0.0071779037825763226,
0.005650743376463652,
-0.002153614303097129,
0.0008729357505217195,
-0.0073920744471251965,
-0.004784002900123596,
-0.019882580265402794,
0.0010707160690799356,
0.010597830638289452,
-0.0023931381292641163,
0.00638072332367301,
-0.011140436865389347,
0.00497979624196887,
0.006162775214761496,
0.0006410017958842218,
-0.0013169603189453483,
-0.0015888080233708024,
0.006833917461335659,
0.011150123551487923,
-0.006315172649919987,
0.004507762845605612,
0.0008980506681837142,
-0.0033941110596060753,
0.0032329813111573458,
0.005668844096362591,
-0.009492254815995693,
-0.004380210302770138,
0.002264059381559491,
-0.0008993155788630247,
0.003898097900673747,
-0.004238331690430641,
-0.011327959597110748,
-0.003759467275813222,
0.005738146137446165,
-0.005440569017082453,
0.0036901880521327257,
0.00459034088999033,
0.003960483707487583,
-0.01359131932258606,
0.0013662485871464014,
-0.00400179997086525,
-0.009119651280343533,
0.008930898271501064,
-0.003888202365487814,
0.0033204995561391115,
0.012081506662070751,
0.005789485760033131,
-0.016061754897236824,
0.01044829934835434,
0.00696692056953907,
-0.004451462533324957,
0.0026577759999781847,
0.00568746542558074,
-0.00728923175483942,
-0.02402833104133606,
0.00034206712734885514,
-0.01764640025794506,
0.0055772303603589535,
-0.005530421156436205,
0.003968202508985996,
-0.006554367020726204,
0.009286155924201012,
0.00540518993511796,
-0.012715019285678864,
-0.0035294177941977978,
-0.007595025934278965,
0.00776990270242095,
-0.0012744114501401782,
-0.0015972459223121405,
-0.0027276293840259314,
-0.005094435065984726,
-0.004851050674915314,
-0.0027739047072827816,
-0.0015492112142965198,
0.0038338229060173035,
0.00017010734882205725,
-0.0045240637846291065,
0.002037269761785865,
-0.00314435176551342,
0.0010745980544015765,
0.0015398550312966108,
-0.01347532868385315,
-0.0026002973318099976,
0.008336103521287441,
-0.0018270447617396712,
-0.0059461649507284164,
0.000059060475905425847,
-0.0021995173301547766,
-0.005248655565083027,
-0.010248163715004921,
-0.003675015876069665,
-0.0023630906362086535,
-0.004831903614103794,
-0.007953421212732792,
-0.0022668291348963976,
-0.007268378045409918,
0.005609570536762476,
-0.007449779659509659,
0.004022513050585985,
0.004480230156332254,
-0.004573672078549862,
0.010089704766869545,
-0.00014402753731701523,
0.003242750884965062,
0.0025941072963178158,
0.007067275699228048,
-0.0028495541773736477,
-0.009590988978743553,
-0.013576996512711048,
0.01517151016741991,
-0.009108619764447212,
0.0016911496641114354,
0.012810342013835907,
0.003720660228282213,
0.01167998742312193,
-0.0005724610527977347,
-0.00044120123493485153,
0.0042747557163238525,
0.009301664307713509,
-0.013094953261315823,
0.003877227893099189,
-0.003146367147564888,
-0.0038355751894414425,
0.006759081035852432,
-0.0019297718536108732,
-0.0000225122130359523,
0.007123651448637247,
0.003308823797851801,
-0.011297903023660183,
-0.001648441539146006,
0.0014773091534152627,
0.004380109254270792,
-0.01439486164599657,
-0.0026443281676620245,
-0.007074728608131409,
-0.003975868225097656,
-0.004402711987495422,
-0.000011772650395869277,
-0.00048608813085593283,
0.005872487090528011,
-0.0036846078000962734,
0.007655896246433258,
0.0015676062321290374,
-0.0016522143268957734,
0.01562894880771637,
-0.006357482634484768,
-0.005081582348793745,
0.002362369792535901,
0.0001206691304105334,
-0.0023129486944526434,
-0.009064600802958012,
-0.004516839515417814,
0.001284920028410852,
0.0028614536859095097,
-0.00210578553378582,
-0.007482325192540884,
-0.0031300741247832775,
0.0010078843915835023,
-0.012365294620394707,
-0.00003523906343616545,
0.012240538373589516,
0.0011579976417124271,
0.0025024046190083027,
-0.000453271612059325,
-0.006176788825541735,
-0.017582792788743973,
0.058141060173511505,
-0.0018389358883723617,
0.005423723720014095,
0.002394287381321192,
-0.006600916385650635,
-0.000425560399889946,
-0.004639508668333292,
0.010577516630291939,
-0.006879751104861498,
-0.008574041537940502,
0.007738827262073755,
-0.002241129521280527,
0.004360720049589872,
-0.0003890042717102915,
-0.0034890270326286554,
0.018284695222973824,
-0.0037753062788397074,
-0.014877411536872387,
-0.015123681165277958,
0.008425251580774784,
-0.005661940202116966,
-0.007831876166164875,
0.007361023221164942,
-0.0014329840196296573,
-0.004453107714653015,
0.001914075342938304,
0.005123268347233534,
-0.00015639480261597782,
0.002902394160628319,
-0.0036657308228313923,
-0.0020624021999537945,
0.0008568750927224755,
0.005021880380809307,
0.005756431259214878,
0.0065019275061786175,
-0.002616367768496275,
0.002818785607814789,
-0.0011387387057766318,
0.0010171751491725445,
-0.0006445070030167699,
0.004190064966678619,
0.0065726228058338165,
-0.0005645786295644939,
-0.003643242409452796,
0.003733127610757947,
0.005299662705510855,
0.00004891788921668194,
0.010102516040205956,
0.002471636049449444,
-0.005458101164549589,
0.006526146549731493,
0.01126741524785757,
0.000495655694976449,
0.009388177655637264,
-0.0008435555500909686,
0.0030616926960647106,
0.003645256394520402,
-0.006866826210170984,
-0.01603245548903942,
0.0018092950340360403,
0.004426057916134596,
0.005230574868619442,
-0.001449246541596949,
0.005266968160867691,
-0.000885247194673866,
-0.002006844850257039,
-0.01071227714419365,
-0.004979454912245274,
-0.005409634672105312,
-0.0015133466804400086,
0.002190454863011837,
0.07113242894411087,
-0.007699961308389902,
-0.005113936960697174,
-0.0074228462763130665,
0.00044919628999195993,
-0.0013896626187488437,
0.0014095217920839787,
-0.0019850563257932663,
0.00024506228510290384,
0.005706882104277611,
0.0019412775291129947,
-0.007886191830039024,
-0.00713022705167532,
-0.002475682646036148,
0.0017218466382473707,
-0.005612409207969904,
0.009022348560392857,
0.00765343988314271,
-0.008409997448325157,
0.0040236953645944595,
-0.013850446790456772,
-0.002061000792309642,
-0.004837971646338701,
-0.006478564813733101,
-0.0006850155186839402,
-0.002640201710164547,
0.0036318760830909014,
0.004776312969624996,
0.00822143442928791,
-0.004611664451658726,
0.004635853227227926,
-0.0019028063397854567,
0.0031164996325969696,
-0.002006914932280779,
0.0035373989958316088,
-0.009496701881289482,
0.007778908126056194,
0.0012301687384024262,
-0.008917109109461308,
-0.0017954803770408034,
-0.0010330043733119965,
0.0033582805190235376,
-0.006440798286348581,
0.006414411123842001,
0.0022359767463058233,
0.011611505411565304,
-0.0014031531754881144,
-0.0000985244259936735,
-0.00500132841989398,
-0.0020877360366284847,
-0.01426180824637413,
0.003975215367972851,
-0.18319499492645264,
0.007632188964635134,
0.004412929993122816,
-0.007556610740721226,
-0.0030388531740754843,
-0.015688054263591766,
-0.009696059860289097,
0.00606541708111763,
0.009751158766448498,
-0.002027683425694704,
0.0037090296391397715,
-0.00041203046566806734,
0.004845135845243931,
0.0036696738097816706,
-0.001263404730707407,
-0.0057200840674340725,
0.0038623122964054346,
-0.006069623865187168,
-0.0028311931528151035,
0.008695983327925205,
0.006579141598194838,
0.007663229014724493,
0.0030364589765667915,
-0.0020653021056205034,
0.002661632839590311,
-0.00135709042660892,
0.007382398471236229,
-0.001766727538779378,
0.007790621370077133,
-0.010308989323675632,
-0.005290122702717781,
-0.006679927464574575,
-0.00642774673178792,
0.0026801559142768383,
0.005143397953361273,
-0.0010487443068996072,
0.007026194129139185,
0.0010361974127590656,
-0.0072163986042141914,
0.00633330550044775,
-0.004698486533015966,
0.02985074743628502,
0.0030566698405891657,
0.009063276462256908,
-0.0004949393915012479,
-0.001069259480573237,
-0.0024318404030054808,
0.008188610896468163,
0.0022843261249363422,
0.011578904464840889,
-0.011439009569585323,
-0.007181130815297365,
0.0021680935751646757,
0.019469885155558586,
-0.0024954411201179028,
-0.006271829828619957,
-0.006940740160644054,
-0.004563517868518829,
0.005091575440019369,
0.009941465221345425,
0.01290501281619072,
-0.005033543799072504,
0.0065254163928329945,
-0.006826233118772507,
-0.025120539590716362,
0.0034022226464003325,
0.000037038593291072175,
-0.007732708007097244,
0.0027491003274917603,
0.007979707792401314,
0.008768967352807522,
-0.0015015174867585301,
0.009083658456802368,
-0.0012652830919250846,
0.007685927674174309,
0.0015235301107168198,
0.008732674643397331,
-0.0036128333304077387,
0.008265946060419083,
-0.008373888209462166,
0.011438173241913319,
-0.013037614524364471,
-0.004374452400952578,
0.002947880420833826,
-0.005533705931156874,
0.012109087780117989,
0.0056572528555989265,
-0.00391323072835803,
0.0015135849826037884,
-0.012731963768601418,
-0.0020019407384097576,
0.0032014513853937387,
0.0009277455974370241,
-0.00965059082955122,
0.000868917559273541,
-0.004699894227087498,
0.005959650967270136,
0.0074257017113268375,
-0.00521783297881484,
0.008870369754731655,
0.0033114233519881964,
-0.00910449493676424,
0.0009630799177102745,
-0.005802593659609556,
0.0031938154716044664,
0.0034486791118979454,
-0.00716490438207984,
-0.006484370678663254,
0.006850053556263447,
-0.007531469222158194,
-0.0017801020294427872,
0.00240067089907825,
-0.010462686419487,
-0.01306748203933239,
-0.0029734608251601458,
-0.013791012577712536,
0.00379443122074008
] |
8a444601b18de24677a5df5024e0921fdacf4ec7 | 8,983 | py | Python | glue/plugins/export_d3po.py | sergiopasra/glue | c25a217a122a11818382672c99cb21f57a30636f | [
"BSD-3-Clause"
] | 1 | 2019-12-17T07:58:35.000Z | 2019-12-17T07:58:35.000Z | glue/plugins/export_d3po.py | sergiopasra/glue | c25a217a122a11818382672c99cb21f57a30636f | [
"BSD-3-Clause"
] | null | null | null | glue/plugins/export_d3po.py | sergiopasra/glue | c25a217a122a11818382672c99cb21f57a30636f | [
"BSD-3-Clause"
] | 1 | 2019-08-04T14:10:12.000Z | 2019-08-04T14:10:12.000Z | from __future__ import absolute_import, division, print_function
import os
import json
from glue.core import Subset
DISPATCH = {}
def save_page(page, page_number, label, subset):
""" Convert a tab of a glue session into a D3PO page
:param page: Tuple of data viewers to save
:param label: Tab label
"""
result = {}
# layout settings
result['grid'] = {'nRows': 1, 'nColumns': len(page)}
result['name'] = str(label)
result['caption'] = 'Generated by Glue'
# style settings
d = page[0]._data[0]
unselected = dict(opacity=d.style.alpha,
size=d.style.markersize / 2,
color=d.style.color)
result['markerStyle'] = dict(unselected=unselected)
if subset is not None:
s = subset.style
selected = dict(opacity=s.alpha, size=s.markersize / 2, color=s.color)
result['markerStyle']['selected'] = selected
result['selection'] = {'type': 'booleanColumn',
'columnName': 'selection_%i' % page_number}
result['histogramStyle'] = result['markerStyle']
# save each plot
result['plots'] = list(map(save_plot, page, range(len(page))))
return result
def save_plot_base(plot, index):
result = {}
result['gridPosition'] = [0, index]
return result
def save_plot(plot, index):
typ = type(plot)
return DISPATCH[typ](plot, index)
def save_scatter(plot, index):
""" Convert a single glue scatter plot to a D3PO plot
:param plot: Glue scatter plot
:class:`~glue.viewers.scatter.qt.ScatterViewer`
:param index: 1D index of plot on the page
:type index: int
:rtype: json-serializable dict
"""
result = save_plot_base(plot, index)
result['type'] = 'scatter'
result['xAxis'] = dict(columnName=plot.state.x_att.label,
range=[float(plot.state.x_min), float(plot.state.x_max)])
result['yAxis'] = dict(columnName=plot.state.y_att.label,
range=[float(plot.state.y_min), float(plot.state.y_max)])
# XXX log scales
return result
def save_histogram(plot, index):
""" Convert a single histogram to a D3PO plot
:param plot: Glue histogram
:type plot: :class:`~glue.viewers.histogram.qt.HistogramViewer`
:param index: 1D index of plot on the page
:type index: int
:rtype: json-serializable dict
"""
result = save_plot_base(plot, index)
result['type'] = 'histogram'
result['xAxis'] = dict(columnName=plot.state.x_att.label,
bins=int(plot.state.hist_n_bin),
range=[float(plot.state.hist_x_min), float(plot.state.hist_x_max)])
# XXX normed, cumultive, log
return result
def stage_subsets(application):
"""
Return a tuple of the subset to use for each stage/tab,
or None if the tab has no subset
If more than one subset is used per stage/tab, returns None
"""
result = []
for page in application.viewers:
subset = None
for viewer in page:
for layer_artist in viewer.layers:
if not layer_artist.visible:
continue
s = layer_artist.layer
if not isinstance(s, Subset):
continue
if subset is not None and s is not subset:
return None
if subset is None:
subset = s
result.append(subset)
return tuple(result)
def can_save_d3po(application):
"""
Check whether an application can be exported to D3PO.
Raises an exception if not
"""
dc = application.session.data_collection
if len(dc) != 1:
raise ValueError("D3PO Export only supports a single dataset")
for tab in application.viewers:
for viewer in tab:
if not isinstance(viewer, tuple(DISPATCH.keys())):
raise ValueError("D3PO Export only supports scatter "
"and histogram plots")
if sum(len(tab) for tab in application.viewers) == 0:
raise ValueError("D3PO Export requires at least one scatterplot "
"or histogram")
if stage_subsets(application) is None:
raise ValueError("D3PO Export restricted to 0 or 1 subsets visible "
"in each tab")
def make_data_file(data, subsets, path):
"""
Create the data.csv file, given Data and tuple of subsets
"""
from astropy.table import Table, Column
data_path = os.path.join(path, 'data.csv')
t = Table([data[c] for c in data.components],
names=[c.label for c in data.components])
for i, subset in enumerate(subsets):
if subset is None:
continue
c = Column(data=subset.to_mask().astype('i'), name='selection_%i' % i)
t.add_column(c)
t.write(data_path, format='ascii', delimiter=',')
def save_d3po(application, path, launch=True):
"""Save a Glue session to a D3PO bundle.
Currently, this has the following restrictions:
- The Glue session must have only one dataset open, and 0 or 1 subsets
- Only scatter plots or histograms are present
- At least one plot is present
:param application: Glue appication to save
:param path: Path to directory to save in. Will be created if needed
"""
if os.path.exists(path) and not os.path.isdir(path):
os.unlink(path)
if not os.path.exists(path):
os.mkdir(path)
data = application.session.data_collection[0]
subsets = stage_subsets(application)
viewers = application.viewers
# data.csv
make_data_file(data, subsets, path)
# states.json
result = {}
result['filename'] = 'data.csv' # XXX don't think this is needed?
result['title'] = "Glue export of %s" % data.label
result['states'] = list(map(save_page, application.viewers,
range(len(viewers)),
application.tab_names,
subsets))
state_path = os.path.join(path, 'states.json')
with open(state_path, 'w') as outfile:
json.dump(result, outfile, indent=2, sort_keys=True)
# index.html
html_path = os.path.join(path, 'index.html')
with open(html_path, 'w') as outfile:
outfile.write(HTML)
# show the result
if launch:
launch_d3po(path)
def launch_d3po(path):
"""Start a server to view an exported D3PO bundle, and open a browser.
:param path: The TLD of the bundle
"""
from glue.external.six.moves.socketserver import TCPServer
from glue.external.six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler
from random import randrange
from socket import error
import webbrowser
from threading import Thread
os.chdir(path)
while True:
try:
PORT = randrange(8000, 9000)
server = TCPServer(("", PORT), SimpleHTTPRequestHandler, False)
server.allow_reuse_address = True
server.server_bind()
break
except error: # port already taken
pass
print('Serving D3PO on port 0.0.0.0:%i' % PORT)
server.server_activate()
thread = Thread(target=server.serve_forever)
thread.setDaemon(True) # do not prevent shutdown
thread.start()
webbrowser.open('http://0.0.0.0:%i' % PORT)
def setup():
from glue.config import exporters
exporters.add('D3PO', save_d3po, can_save_d3po, outmode='directory')
HTML = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="http://d3po.org/static/css/style.css">
<link rel="stylesheet" type="text/css" href="http://d3po.org/static/css/d3po.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300,400,700' rel='stylesheet' type='text/css'>
<style>
#footer {
position: fixed;
bottom: 0;
right: 0;
}
</style>
<!-- not to be confused with Planet Telex -->
<!-- Javscript dependencies -->
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3po.org/static/js/util.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://d3po.org/static/js/d3po.js"></script>
<script src="http://d3po.org/static/js/d3po.init.js"></script>
</head>
<body>
<div id="svg"><svg></svg></div>
<div id="controls">
<ul class="navigation">
</ul>
</div>
<div id="caption"></div>
<div id="footer">
More information: <a href="http://d3po.org">d3po.org</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
initialize('states.json', 'data.csv');
}
);
</script>
</body>
</html>
"""
try:
from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.histogram.qt import HistogramViewer
except ImportError:
pass
else:
DISPATCH[ScatterViewer] = save_scatter
DISPATCH[HistogramViewer] = save_histogram
| 28.977419 | 121 | 0.627296 | 1 | 2.0466 | [
-0.03257838264107704,
0.053869593888521194,
-0.0239258985966444,
0.06623708456754684,
-0.01721031218767166,
-0.0051480913534760475,
0.0026694941334426403,
-0.0024930660147219896,
-0.05712663382291794,
-0.013185454532504082,
0.04553515836596489,
0.02450898289680481,
0.013531368225812912,
0.00840284675359726,
-0.03154236823320389,
-0.012300114147365093,
0.17303548753261566,
-0.027628008276224136,
-0.03245801851153374,
0.02674650028347969,
0.031481120735406876,
0.019761914387345314,
0.004240268841385841,
-0.003841117722913623,
-0.002141870092600584,
-0.03190376237034798,
-0.01544668897986412,
-0.004797857720404863,
-0.008548077195882797,
-0.0046877069398760796,
0.008765903301537037,
0.005089682526886463,
-0.04865790158510208,
-0.029318321496248245,
-0.005676567554473877,
0.00876004807651043,
-0.013252239674329758,
-0.06166374683380127,
0.0004753011744469404,
-0.019275737926363945,
-0.012718460522592068,
-0.011911201290786266,
-0.01928729936480522,
0.022659791633486748,
0.03314454108476639,
-0.019748026505112648,
-0.03337656334042549,
-0.03354262188076973,
-0.0384429432451725,
0.011401732452213764,
0.010161593556404114,
0.004584563430398703,
0.05340912938117981,
-0.0007025760714896023,
0.005499043967574835,
-0.013093254528939724,
0.038297854363918304,
0.03231420740485191,
-0.03125707432627678,
0.014905963093042374,
0.0006581369671039283,
-0.004511693492531776,
0.030017202720046043,
0.045774973928928375,
-0.02943965047597885,
-0.004998933989554644,
-0.019990423694252968,
0.013071954250335693,
-0.025280948728322983,
0.02420208789408207,
0.010652460157871246,
-0.028463119640946388,
0.07638595253229141,
-0.003498322796076536,
-0.009478621184825897,
-0.002056058496236801,
0.017526529729366302,
-0.029713161289691925,
-0.014806016348302364,
0.0029978451784700155,
-0.0040466575883328915,
0.027386080473661423,
-0.0032795800361782312,
-0.01354850921779871,
0.025316765531897545,
0.03973725438117981,
0.013289694674313068,
-0.06568185985088348,
0.038313694298267365,
0.014275409281253815,
-0.03904687613248825,
0.009874713607132435,
-0.046141188591718674,
0.00024633892462588847,
-0.025987546890974045,
-0.04556484892964363,
0.003656157525256276,
-0.0018292603781446815,
0.03420497104525566,
-0.04827623441815376,
0.05328546091914177,
0.013795418664813042,
0.0036222815979272127,
-0.006451543886214495,
0.02743200771510601,
-0.02681482583284378,
-0.030536117032170296,
0.015202735550701618,
-0.041463397443294525,
-0.004809160716831684,
0.05274903401732445,
0.014751778915524483,
-0.04889736324548721,
-0.0273318812251091,
-0.0859113484621048,
0.008977720513939857,
0.026684779673814774,
0.009241713210940361,
0.030094126239418983,
0.05999894440174103,
0.0031400350853800774,
0.023250320926308632,
0.0014035379281267524,
0.01596374437212944,
0.02073453553020954,
0.030213622376322746,
-0.026553304865956306,
0.005906385835260153,
0.041006967425346375,
0.01786838285624981,
-0.019328920170664787,
0.00047571322647854686,
-0.004640392959117889,
-0.019361993297934532,
0.003914172761142254,
-0.0021309941075742245,
0.040007222443819046,
-0.0026122552808374166,
-0.033600181341171265,
-0.0016879531322047114,
0.02103096805512905,
0.007796474266797304,
0.016207989305257797,
0.0138460174202919,
-0.017984658479690552,
-0.057926665991544724,
0.0025166624691337347,
0.0627073422074318,
-0.017858833074569702,
-0.02636832185089588,
0.04541315510869026,
0.026147808879613876,
-0.009977171197533607,
0.0003052449901588261,
-0.01665673404932022,
-0.016501998528838158,
0.0027009022887796164,
-0.028394727036356926,
0.004315264523029327,
0.025891929864883423,
-0.0568644143640995,
-0.008920847438275814,
0.025147665292024612,
0.010417653247714043,
0.05334107577800751,
0.025249768048524857,
0.01284500677138567,
0.02861727774143219,
0.00857209786772728,
-0.003768814029172063,
-0.0051979380659759045,
-0.032457128167152405,
-0.03987331688404083,
0.021101614460349083,
0.026205189526081085,
0.00039382788236252964,
0.018572160974144936,
-0.05693592503666878,
0.0010193088091909885,
-0.030170582234859467,
0.03265698626637459,
-0.04273143410682678,
-0.0026471749879419804,
0.036514267325401306,
-0.03364823758602142,
0.030995909124612808,
-0.05363241583108902,
-0.027574604377150536,
0.049295827746391296,
-0.009709401056170464,
0.01256372220814228,
-0.007828354835510254,
0.041961055248975754,
-0.009802816435694695,
0.005059062037616968,
-0.052675168961286545,
0.0030054592061787844,
-0.006897601764649153,
-0.00791176874190569,
0.03684885427355766,
0.038233354687690735,
-0.009556477889418602,
-0.031213076785206795,
0.028320562094449997,
0.013505944982171059,
0.031291693449020386,
-0.5914621353149414,
0.02963862195611,
0.011588350869715214,
-0.023087242618203163,
0.012920145876705647,
0.03860948234796524,
-0.03334454447031021,
-0.01254480704665184,
-0.0232204832136631,
-0.0592329241335392,
0.012189938686788082,
0.0025487104430794716,
-0.006674549076706171,
0.006851324811577797,
-0.009016034193336964,
-0.006067140493541956,
0.001724041299894452,
0.008056054823100567,
0.027339283376932144,
0.04534348472952843,
0.014070970006287098,
-0.07006316632032394,
-0.018698226660490036,
0.034130483865737915,
0.0011536598904058337,
-0.009075707755982876,
-0.00594004662707448,
0.03952973335981369,
0.006401825696229935,
0.01563986949622631,
-0.027479112148284912,
0.019236495718359947,
0.0447128601372242,
-0.026092128828167915,
-0.011987720616161823,
0.022881701588630676,
0.01225174218416214,
-0.02254517190158367,
0.0021822534035891294,
-0.04835183173418045,
0.018246904015541077,
0.00837431475520134,
0.03332978114485741,
-0.09825321286916733,
0.0049644880928099155,
-0.012445604428648949,
-0.03726811334490776,
0.03880254551768303,
0.02604725956916809,
0.033050764352083206,
-0.02709612250328064,
-0.01893940195441246,
0.033137623220682144,
0.01933840662240982,
0.010443328879773617,
-0.02033945918083191,
-0.026462629437446594,
-0.0064463247545063496,
-0.01610933616757393,
-0.013516861945390701,
-0.015091681852936745,
0.0015274076722562313,
-0.04728047549724579,
-0.013292284682393074,
0.025128887966275215,
0.010831318795681,
0.050946686416864395,
-0.06370700150728226,
0.008558067493140697,
-0.03205190226435661,
0.010375065729022026,
0.00972672551870346,
-0.05666927620768547,
0.03861439973115921,
0.013780003413558006,
0.000626966473646462,
0.026693392544984818,
-0.014736061915755272,
-0.06598671525716782,
-0.006135627161711454,
0.026927346363663673,
-0.025734825059771538,
0.005032278131693602,
-0.01571517251431942,
-0.01615816541016102,
-0.0507252961397171,
-0.05093073099851608,
0.03469838201999664,
0.02580265700817108,
-0.010292193852365017,
-0.00261593796312809,
0.03380989655852318,
0.010198783129453659,
0.01900130696594715,
0.00302501255646348,
0.09876690059900284,
0.06174089014530182,
0.021275803446769714,
0.002164491219446063,
0.05217650905251503,
0.0164909977465868,
0.01812228187918663,
-0.042076773941516876,
-0.005233997479081154,
-0.0021668560802936554,
-0.01107722893357277,
-0.02187684364616871,
-0.011681229807436466,
-0.00010382961045252159,
0.00705633033066988,
-0.01977241225540638,
-0.0015310707967728376,
-0.015776734799146652,
-0.007521596737205982,
-0.06479882448911667,
-0.008825837634503841,
-0.016635214909911156,
-0.014348620548844337,
0.027669809758663177,
-0.021729281172156334,
0.0021069005597382784,
-0.032439880073070526,
-0.004369496833533049,
-0.03005274198949337,
-0.005819713696837425,
0.013837162405252457,
-0.039334848523139954,
0.0033073797821998596,
-0.01773274689912796,
0.03909074887633324,
-0.06797054409980774,
0.0076314713805913925,
0.0011250198585912585,
-0.05734345689415932,
-0.0008342449436895549,
0.004999302793294191,
-0.029685184359550476,
-0.0034031684044748545,
-0.049709998071193695,
-0.017420222982764244,
-0.00330337043851614,
0.004873054102063179,
0.06254663318395615,
-0.013744725845754147,
-0.01177983544766903,
0.040305234491825104,
-0.004999339580535889,
-0.004069986753165722,
-0.0607769712805748,
0.00065802619792521,
0.0022181151434779167,
0.0051981257274746895,
0.029042312875390053,
-0.015908347442746162,
0.01379404217004776,
-0.021445920690894127,
-0.027308674529194832,
0.05468699336051941,
0.007742040790617466,
0.02755412459373474,
-0.007206707261502743,
-0.06174767017364502,
0.016953473910689354,
-0.017254287376999855,
-0.0021184568759053946,
0.03393169492483139,
-0.007892169058322906,
-0.013528482988476753,
0.010276490822434425,
0.044914111495018005,
0.06452393531799316,
0.015310173854231834,
-0.014252448454499245,
0.04238174855709076,
0.04223722591996193,
-0.02320954203605652,
0.027907025068998337,
-0.06022833660244942,
0.007619660813361406,
0.003905876539647579,
-0.020971285179257393,
0.015490572899580002,
0.0023432227317243814,
0.009791113436222076,
-0.016592858359217644,
0.002912392606958747,
-0.031746525317430496,
-0.0667659267783165,
-0.010361550375819206,
-0.021996118128299713,
-0.010199252516031265,
0.044680312275886536,
-0.04646016284823418,
-0.01261799968779087,
-0.026784654706716537,
0.006572856567800045,
0.00972407590597868,
-0.02968459762632847,
0.013608760200440884,
0.019651617854833603,
-0.014262658543884754,
-0.004936463199555874,
-0.023235395550727844,
0.006677940953522921,
0.049494415521621704,
0.0013655776856467128,
-0.010780737735331059,
0.027810778468847275,
-0.007250381633639336,
-0.0235291738063097,
0.022158782929182053,
0.009966353885829449,
-0.010956747457385063,
0.011175494641065598,
0.06403836607933044,
0.01458290871232748,
-0.005243742372840643,
-0.037710316479206085,
0.08157280832529068,
-0.04161708056926727,
-0.00527989724650979,
-0.027103697881102562,
0.03706257417798042,
-0.02308630757033825,
-0.0006033742683939636,
0.004462189972400665,
-0.029146786779165268,
0.001649078563787043,
-0.0130018824711442,
-0.035209402441978455,
-0.019918173551559448,
0.004396543372422457,
0.004152818117290735,
-0.023566706106066704,
-0.03167970851063728,
0.02396625094115734,
-0.01838703267276287,
-0.019054602831602097,
0.03276102617383003,
-0.019421963021159172,
0.03125852346420288,
-0.024291856214404106,
0.019827408716082573,
0.024174625054001808,
0.007448354735970497,
-0.03614556044340134,
0.029382506385445595,
-0.08093591034412384,
-0.02280707098543644,
0.000017295689758611843,
-0.03103683516383171,
-0.007115873508155346,
0.029140911996364594,
0.010278533212840557,
-0.018261320888996124,
0.018220772966742516,
-0.04605075344443321,
-0.0007643081480637193,
0.009152616374194622,
-0.030692435801029205,
0.019716745242476463,
-0.042155276983976364,
0.03823759779334068,
0.03168409690260887,
-0.044819027185440063,
-0.0020049698650836945,
0.005450807511806488,
0.006764524150639772,
0.00367699540220201,
0.004238984547555447,
-0.0007474080775864422,
-0.011037246324121952,
-0.030369386076927185,
-0.026306027546525,
-0.015376072376966476,
0.03929540514945984,
-0.01675601489841938,
0.008248395286500454,
0.053635258227586746,
0.008130950853228569,
0.025485455989837646,
0.05351702868938446,
-0.003300104755908251,
0.029874876141548157,
-0.00960054062306881,
0.03158111497759819,
0.05028504878282547,
0.02310655638575554,
-0.02502954937517643,
0.0009558811434544623,
-0.010899761691689491,
0.0014515224611386657,
0.021342499181628227,
-0.01567418873310089,
0.027056433260440826,
-0.0004876545863226056,
0.021412627771496773,
-0.008823438547551632,
0.012891549617052078,
-0.02409982867538929,
-0.005164435598999262,
0.0021852145437151194,
0.006450630724430084,
-0.011209542863070965,
-0.017885269597172737,
0.027987807989120483,
0.005075037479400635,
0.010995159856975079,
0.017273716628551483,
0.03828936442732811,
0.024171127006411552,
0.026501134037971497,
0.026772791519761086,
0.034263212233781815,
0.010752080008387566,
0.032137129455804825,
0.015004568733274937,
-0.014294100925326347,
0.01737436279654503,
-0.03602331504225731,
-0.07167971134185791,
-0.01954859308898449,
-0.018409082666039467,
0.03546614199876785,
0.0067041246220469475,
-0.023659197613596916,
-0.023985521867871284,
0.01206720620393753,
0.014071467332541943,
0.03236450254917145,
0.01707911305129528,
-0.055004656314849854,
-0.006605393253266811,
0.010177282616496086,
0.017880894243717194,
-0.02831694670021534,
0.02822883427143097,
0.020569587126374245,
0.021481139585375786,
-0.016364645212888718,
-0.007268549874424934,
0.0046278550289571285,
-0.0448722168803215,
0.0006857500411570072,
0.050261154770851135,
-0.019593264907598495,
0.0029147411696612835,
0.05055186152458191,
-0.022844215855002403,
-0.011813128367066383,
-0.0033878544345498085,
-0.008458606898784637,
0.045045170933008194,
-0.000481202092487365,
0.013243569992482662,
0.021023882552981377,
0.04853375628590584,
-0.01167144812643528,
0.03295358270406723,
0.020903607830405235,
-0.02738240920007229,
-0.03924672305583954,
-0.017153143882751465,
-0.023922055959701538,
-0.052615467458963394,
-0.068217433989048,
0.020578686147928238,
-0.02259969897568226,
0.021401764824986458,
0.0044428096152842045,
-0.023929495364427567,
-0.00889482069760561,
-0.0017054763156920671,
-0.02890084683895111,
0.0021980360615998507,
0.024061493575572968,
0.0056331586092710495,
0.008580472320318222,
0.03539525344967842,
-0.030920639634132385,
-0.055544838309288025,
0.0376964807510376,
-0.04137773811817169,
-0.03547307848930359,
-0.05210871249437332,
0.030596531927585602,
0.048515018075704575,
-0.0028183760587126017,
-0.04457734525203705,
-0.023733632639050484,
-0.0008801185176707804,
-0.032022625207901,
0.008583667688071728,
-0.0015731662278994918,
0.0017022312385961413,
0.005277187097817659,
-0.027095479890704155,
0.011636427603662014,
-0.020551636815071106,
-0.033961743116378784,
0.018997903913259506,
0.0639377161860466,
0.03685452789068222,
0.019510138779878616,
0.018862657248973846,
-0.011617269366979599,
-0.011770175769925117,
-0.0049599590711295605,
0.031765107065439224,
0.01694309338927269,
0.013423236086964607,
0.012670506723225117,
-0.06609568744897842,
0.02103329822421074,
0.023360062390565872,
-0.005449685733765364,
-0.05955173447728157,
0.04183913767337799,
-0.05133539065718651,
-0.021197695285081863,
-0.017246145755052567,
0.002987972227856517,
0.006176700349897146,
0.004907646682113409,
0.007365073077380657,
-0.02241641841828823,
-0.014528981409966946,
-0.013072009198367596,
0.016219209879636765,
0.028942979872226715,
-0.04055783152580261,
-0.010331685654819012,
-0.026770714670419693,
0.004263188224285841,
0.003982146270573139,
-0.016375742852687836,
-0.04744851961731911,
0.009446960873901844,
-0.000044783071643905714,
0.01350521482527256,
-0.02178940735757351,
-0.037091244012117386,
-0.012331253848969936,
0.011020904406905174,
0.0024858410470187664,
-0.09583024680614471,
-0.006421288941055536,
0.00113576534204185,
-0.011925186030566692,
-0.01119372807443142,
-0.0628194808959961,
0.04338410124182701,
-0.028918815776705742,
-0.023760907351970673,
0.03453283756971359,
0.019267452880740166,
-0.0027911877259612083,
0.029412729665637016,
0.010168656706809998,
0.01129826158285141,
0.03620528057217598,
0.018316805362701416,
0.0025481225457042456,
-0.0030572540126740932,
-0.03931639343500137,
-0.008677590638399124,
0.04610147327184677,
-0.0168142132461071,
-0.020921025425195694,
-0.021016618236899376,
-0.08473462611436844,
0.03825874626636505,
0.010689495131373405,
-0.029737340286374092,
0.0076584042981266975,
0.01360285934060812,
0.010992665775120258,
0.01930811256170273,
0.01290004700422287,
-0.0011767683317884803,
0.017571479082107544,
-0.0028023344930261374,
0.05283024162054062,
0.03641887381672859,
0.0030798199586570263,
-0.007665878161787987,
-0.03452411666512489,
-0.024438517168164253,
0.011554885655641556,
-0.003452521748840809,
0.0015105914790183306,
-0.055916983634233475,
-0.0072387149557471275,
0.05128568783402443,
0.0211507435888052,
0.009619253687560558,
0.0030485938768833876,
-0.019519101828336716,
0.018513420596718788,
0.0015000534476712346,
0.04207506775856018,
0.0072897979989647865,
0.0029245056211948395,
0.02215947024524212,
-0.019282124936580658,
0.030139857903122902,
-0.03331161290407181,
0.044136907905340195,
-0.005718905013054609,
-0.030652213841676712,
-0.011484736576676369,
0.02427743747830391,
0.030348757281899452,
0.0222572460770607,
0.06072843074798584,
0.04534614086151123,
0.02031051181256771,
-0.05505514517426491,
-0.042070645838975906,
0.008021811954677105,
0.004110581241548061,
-0.03823678568005562,
-0.005516492296010256,
-0.013820263557136059,
-0.01109843049198389,
0.017562150955200195,
-0.028560664504766464,
-0.02063624933362007,
0.017179831862449646,
0.016801467165350914,
0.009844318963587284,
0.03201116994023323,
-0.013907967135310173,
-0.03396592289209366,
0.05720994621515274,
-0.03946377709507942,
0.008270328864455223,
-0.03001856617629528,
0.007883471436798573,
-0.02698398008942604,
0.03099295310676098,
0.01454774197191,
-0.030467338860034943,
-0.010925982147455215,
0.005388996563851833,
0.019745437428355217,
-0.002933440962806344,
-0.04589305445551872,
-0.0028869931120425463,
0.020229043439030647,
0.038600292056798935,
-0.02817261964082718,
0.03703765571117401,
0.020047759637236595,
-0.01802830584347248,
-0.04331579431891441,
0.03693566471338272,
-0.009882098063826561,
-0.0026779090985655785,
0.008715427480638027,
0.02124933898448944,
0.010178451426327229
] |
8a44b11af8b2eb998e8acb85624cce72fd9e4d1c | 303 | py | Python | exercicios/ex 061 a 070/ex061.py | CarlosWillian/python | f863578245fbf402e5b46f844a247355afed0d62 | [
"MIT"
] | null | null | null | exercicios/ex 061 a 070/ex061.py | CarlosWillian/python | f863578245fbf402e5b46f844a247355afed0d62 | [
"MIT"
] | null | null | null | exercicios/ex 061 a 070/ex061.py | CarlosWillian/python | f863578245fbf402e5b46f844a247355afed0d62 | [
"MIT"
] | null | null | null | print('Crie sua P.A. de 10 termos')
n1 = int(input('Digite o primeiro termo da P.A.: '))
r = int(input('Digite a razão: '))
termo = n1
c = 1
print('A P.A. é (', end='')
while c <= 10:
print('{}'.format(termo), end='')
print(', ' if c < 10 else '', end='')
termo += r
c += 1
print(')')
| 20.2 | 52 | 0.518152 | 1 | 0.7821 | [
0.000012210079148644581,
0.02871941588819027,
0.005804031156003475,
0.0008013300248421729,
0.004045769572257996,
-0.004875029902905226,
-0.013103674165904522,
0.006857303436845541,
-0.006047388538718224,
0.0026839724741876125,
0.001157461549155414,
0.0035851262509822845,
0.005342664197087288,
-0.01605597510933876,
-0.00020192046940792352,
0.017524687573313713,
-0.056728653609752655,
0.002541106194257736,
-0.0025633536279201508,
0.004963456187397242,
-0.008863580413162708,
0.009642725810408592,
0.00902845524251461,
0.007470190990716219,
0.006111896596848965,
0.00040092464769259095,
0.011164174415171146,
0.004454253241419792,
-0.006130436435341835,
-0.00482950359582901,
-0.0003140310291200876,
-0.0021479965653270483,
-0.004357520956546068,
-0.011174970306456089,
0.006855826359242201,
-0.0023910298477858305,
0.0007380081224255264,
-0.018568938598036766,
0.01189984567463398,
-0.004392095375806093,
-0.005974277853965759,
-0.018647948279976845,
-0.0014195661060512066,
0.007371815387159586,
-0.011093593202531338,
0.001351747545413673,
-0.004775374196469784,
0.0015643646474927664,
-0.009729607030749321,
0.004158671945333481,
-0.009978118352591991,
0.0048774234019219875,
0.014070031233131886,
0.00593430595472455,
-0.005111095029860735,
-0.007704632356762886,
0.01151563972234726,
-0.0006582136848010123,
-0.012531748041510582,
-0.002951159607619047,
-0.002887653885409236,
-0.002560911700129509,
0.0039558932185173035,
0.0014414273900911212,
-0.01883261278271675,
-0.007339919451624155,
-0.005822386592626572,
0.000972509675193578,
-0.0022628118749707937,
0.003518781391903758,
0.0031285693403333426,
0.0020078117959201336,
0.006738265510648489,
-0.00011355584865668789,
0.00012949950178153813,
-0.0052799563854932785,
-0.00400164071470499,
0.002643440617248416,
0.005728753283619881,
0.0025032884441316128,
0.0058806962333619595,
-0.009594753384590149,
0.005956410896033049,
0.011708582751452923,
0.0112758819013834,
0.006504628341645002,
0.016266966238617897,
-0.010299142450094223,
0.04293522983789444,
0.009292390197515488,
-0.00857755821198225,
0.0020694441627711058,
-0.006830387748777866,
-0.002992625581100583,
-0.003416674444451928,
-0.029951540753245354,
-0.00005506007437361404,
-0.004968735855072737,
-0.0014762544305995107,
0.002664875239133835,
0.0032239428255707026,
0.007688388228416443,
0.0023639460559934378,
-0.002732404973357916,
-0.008748836815357208,
0.014074021019041538,
-0.010548216290771961,
-0.004720564000308514,
0.009151370264589787,
0.00305654457770288,
-0.011923872865736485,
-0.0002763271040748805,
0.0028122449293732643,
-0.012370344251394272,
0.006940091494470835,
0.0011066743172705173,
-0.004187693819403648,
0.057556044310331345,
-0.0019265408627688885,
0.0004377302248030901,
-0.003936342895030975,
-0.00027002234128303826,
0.00274162576533854,
0.008839545771479607,
0.009883955121040344,
-0.004970341455191374,
0.011624711565673351,
0.010387453250586987,
0.004545609001070261,
0.00827450305223465,
0.00006065229172236286,
0.00835096649825573,
-0.0019926740787923336,
0.00026459674700163305,
0.002662847051396966,
-0.008377728052437305,
0.0099478242918849,
-0.003400156507268548,
-0.004974484443664551,
0.0007452212157659233,
-0.0017137828981503844,
-0.011276157572865486,
0.001805575331673026,
-0.00024513062089681625,
-0.00004896482278127223,
-0.009540863335132599,
-0.0048104277811944485,
-0.004840320907533169,
-0.005146440584212542,
0.001327583217062056,
0.010389515198767185,
0.007323354948312044,
0.0018943795002996922,
-0.007509674411267042,
-0.008094152435660362,
-0.0029079189989715815,
-0.0010156339267268777,
0.0011855373159050941,
0.010249764658510685,
0.003448209725320339,
-0.009051274508237839,
-0.006223650183528662,
0.0027553390245884657,
0.005781505256891251,
-0.0003343540884088725,
0.002963838865980506,
-0.009019176475703716,
0.00996745191514492,
-0.00025177435600198805,
0.005928210448473692,
0.010509093292057514,
-0.003067572833970189,
-0.0009676988702267408,
0.001299483235925436,
0.0038427780382335186,
0.001243252889253199,
0.00436365557834506,
0.009759009815752506,
-0.005790537688881159,
-0.003878871211782098,
0.005016108974814415,
0.005810102913528681,
0.006185680162161589,
0.007165221031755209,
-0.0015296956989914179,
0.0017674207920208573,
-0.003307548351585865,
-0.003527177730575204,
0.006964767351746559,
-0.004776264540851116,
0.009433283470571041,
0.005773840006440878,
-0.01448317151516676,
-0.009824885986745358,
-0.00014568903134204447,
-0.010957416146993637,
0.00041299802251160145,
0.01489910390228033,
0.012430439703166485,
-0.0006030353833921254,
0.002473282627761364,
-0.012569679878652096,
0.001893002656288445,
0.009342804551124573,
0.0015388495521619916,
-0.011122221127152443,
-0.95556640625,
0.005111129954457283,
0.0031931374687701464,
0.0016622073017060757,
0.005569299217313528,
-0.0006816958775743842,
0.003682908834889531,
0.002721626777201891,
0.014742513187229633,
-0.011017539538443089,
-0.006103195250034332,
-0.01059766300022602,
-0.011064966209232807,
0.0010665247682482004,
-0.008065351285040379,
-0.004965478088706732,
-0.008382863365113735,
-0.007437386550009251,
-0.0008491926128044724,
-0.0030040740966796875,
-0.0033425576984882355,
0.009455336257815361,
-0.0015055508119985461,
0.00407213531434536,
0.0056715598329901695,
0.004885414615273476,
-0.0071050203405320644,
-0.002689837943762541,
0.0012545676436275244,
-0.0013411721447482705,
-0.006694256328046322,
-0.014024966396391392,
-0.006297789979726076,
0.000280611653579399,
0.011866885237395763,
0.0015332376351580024,
0.008326072245836258,
-0.002704247832298279,
-0.0009806741727516055,
-0.008098621852695942,
0.006318590138107538,
0.0023329006507992744,
0.0045803324319422245,
-0.027691353112459183,
0.0029009422287344933,
-0.0004962913226336241,
-0.005408181343227625,
0.009115101769566536,
0.0017524710856378078,
-0.0010965187102556229,
-0.003448555013164878,
-0.004908019211143255,
0.006338705308735371,
-0.009095611982047558,
0.004645700100809336,
-0.0031522803474217653,
-0.007929904386401176,
-0.001895030029118061,
-0.011072942055761814,
0.0036753553431481123,
0.0037931932602077723,
-0.004801125265657902,
-0.0035824859514832497,
-0.0047423443756997585,
0.0024013849906623363,
0.0035531348548829556,
0.001457706792280078,
-0.01677590049803257,
-0.0050286115147173405,
-0.0033776210620999336,
0.0023134818766266108,
-0.003782326355576515,
-0.005791774485260248,
0.002340688370168209,
-0.00905073806643486,
0.005353469401597977,
0.002587628783658147,
0.000505959615111351,
-0.01267217192798853,
0.0005343321245163679,
-0.009251897223293781,
-0.010974263772368431,
0.003131049918010831,
-0.004690603818744421,
-0.002786010503768921,
-0.001437319559045136,
0.0025559845380485058,
0.0055982815101742744,
-0.006963758729398251,
0.0006194047164171934,
0.010460887104272842,
-0.0018596351146697998,
-0.011102437973022461,
0.007021781522780657,
0.007379869464784861,
0.0015308698639273643,
-0.0020165976602584124,
0.003821877297013998,
0.00856158696115017,
0.011233043856918812,
-0.00018125934002455324,
0.003443620167672634,
0.00033534079557284713,
0.010270991362631321,
-0.0004954854375682771,
0.002614706987515092,
-0.004031930584460497,
-0.0005536222597584128,
-0.003962566144764423,
-0.0009703462128527462,
-0.0014676727587357163,
0.0012504103360697627,
-0.011488442309200764,
-0.011091758497059345,
-0.004248085897415876,
0.004282190930098295,
0.0005175835685804486,
-0.0023846167605370283,
0.0021311482414603233,
0.0005510107148438692,
0.007997923530638218,
-0.0032770216930657625,
-0.006251666694879532,
0.00032955329515971243,
0.0023719791788607836,
-0.0074865627102553844,
0.01480203215032816,
-0.012053719721734524,
0.00696744117885828,
-0.0019690864719450474,
-0.015009608119726181,
0.006803692784160376,
0.013257579877972603,
-0.008002749644219875,
0.0004870788543485105,
0.000593196542467922,
0.002966229571029544,
0.00039089861093088984,
-0.003889087587594986,
-0.003626316087320447,
-0.01734587922692299,
0.0008668031659908593,
0.020117241889238358,
0.0027109701186418533,
0.009867401793599129,
0.011201400309801102,
-0.00571032240986824,
0.002428542822599411,
0.006695883814245462,
0.00328444829210639,
0.013043065555393696,
-0.008562605828046799,
0.00023372424766421318,
0.002297628205269575,
-0.007097575347870588,
0.0016726651228964329,
0.0039777024649083614,
0.0051651280373334885,
-0.004398250486701727,
0.0006289749871939421,
-0.006328419782221317,
-0.00378968333825469,
-0.018560579046607018,
-0.0010920721106231213,
0.007292373571544886,
-0.004776299931108952,
0.002860730979591608,
-0.013667086139321327,
0.005244057159870863,
0.005354107823222876,
0.002064603613689542,
-0.0019804954063147306,
0.0017264240887016058,
0.006021273322403431,
0.014914869330823421,
-0.006228284910321236,
0.004555199295282364,
0.0034103335347026587,
-0.0035237472038716078,
0.0016136682825163007,
0.010102063417434692,
-0.008733208291232586,
-0.00526286568492651,
0.0029940237291157246,
0.00405858363956213,
0.0009651010041125119,
-0.003460485953837633,
-0.00821860320866108,
-0.003470879979431629,
0.0024304164107888937,
-0.013368240557610989,
0.005596397910267115,
-0.0037667660508304834,
0.002805273048579693,
-0.009028569795191288,
0.0007920254720374942,
-0.0037869021762162447,
-0.011881325393915176,
0.00746900076046586,
-0.003103481838479638,
0.0030741423834115267,
0.011613857001066208,
0.003108375007286668,
-0.014106285758316517,
0.0048744590021669865,
0.010349689051508904,
-0.004739175084978342,
-0.0003126204537693411,
0.00962673220783472,
-0.0054251630790531635,
-0.021942948922514915,
0.0017878367798402905,
-0.014976964332163334,
0.006828039884567261,
-0.004337575752288103,
0.001618540263734758,
-0.010201405733823776,
0.005619753617793322,
0.0054305000230669975,
-0.012937107123434544,
-0.006444540806114674,
-0.008040948770940304,
0.009824724867939949,
-0.0006062826723791659,
-0.0041825417429208755,
-0.003153677564114332,
-0.0016740665305405855,
-0.003433061530813575,
-0.002059305552393198,
-0.0013206236762925982,
0.003987887408584356,
0.0013672622153535485,
-0.001742684980854392,
0.0039020078256726265,
-0.0004883126239292324,
0.000646512140519917,
0.004405423533171415,
-0.009700977243483067,
0.004278859589248896,
0.005065854173153639,
0.0019316932884976268,
-0.0043052672408521175,
0.0003874299582093954,
-0.0036854692734777927,
-0.005761660635471344,
-0.011962328106164932,
-0.001317760907113552,
0.00010483212827239186,
-0.005357407033443451,
-0.011874955147504807,
-0.0013365522027015686,
-0.008988787420094013,
0.007454405073076487,
-0.006116865202784538,
0.007273403462022543,
0.006055407226085663,
-0.005221263039857149,
0.006004013121128082,
-0.005153363104909658,
0.00426523620262742,
0.0003247672284487635,
0.00576954847201705,
0.00007072516018524766,
-0.004783781711012125,
-0.010778041556477547,
0.01234262716025114,
-0.01068907417356968,
0.0034410979133099318,
0.012565555982291698,
0.0059470380656421185,
0.008167554624378681,
0.003193936077877879,
0.00014456367352977395,
0.0022472161799669266,
0.008040553890168667,
-0.012044140137732029,
0.0022408878430724144,
-0.00389131810516119,
-0.0019976296462118626,
0.007349031046032906,
-0.0035500212106853724,
0.0028984970413148403,
0.009065194055438042,
0.001539264339953661,
-0.005631286185234785,
-0.004813135601580143,
-0.00004363325206213631,
0.0021896623075008392,
-0.012990300543606281,
-0.0031285658478736877,
-0.0034337942488491535,
-0.0059588816948235035,
-0.004144192207604647,
0.0003233968745917082,
-0.0007644493598490953,
0.0018969271332025528,
-0.0011726116063073277,
0.007750019896775484,
0.0026026973500847816,
-0.0060830675065517426,
0.014090456068515778,
-0.005414324346929789,
-0.002138167154043913,
0.003709253389388323,
0.0018154538702219725,
-0.0011743496870622039,
-0.004593420773744583,
-0.0048219021409749985,
0.00047538476064801216,
0.005991359241306782,
-0.004651380702853203,
-0.00875102449208498,
-0.0023991502821445465,
0.0002537003601901233,
-0.00921601615846157,
0.0013869003159925342,
0.011208073236048222,
-0.004970584996044636,
0.0032777462620288134,
0.00006435826071538031,
-0.007695158012211323,
-0.014199724420905113,
0.056236788630485535,
0.0011520286789163947,
0.0038966285064816475,
0.007277060300111771,
-0.00740030687302351,
-0.0007284706807695329,
-0.0054175094701349735,
0.005463704001158476,
-0.006426825188100338,
-0.005380306392908096,
0.010014797560870647,
-0.0029574886430054903,
0.0047132885083556175,
0.0002897149825002998,
-0.0028711301274597645,
0.016748860478401184,
-0.007574758492410183,
-0.016176223754882812,
-0.013684759847819805,
0.004839290864765644,
-0.0013541167136281729,
-0.004408979322761297,
0.004076087381690741,
-0.005110616330057383,
-0.002049512229859829,
0.0015124818310141563,
0.0037782287690788507,
-0.0000986073719104752,
-0.0008112285286188126,
-0.0003942050680052489,
-0.0017726693768054247,
0.00028388210921548307,
0.0029675045516341925,
0.005864825565367937,
0.010199344716966152,
-0.00236516073346138,
0.00437275180593133,
-0.0023573567159473896,
-0.00277298828586936,
-0.0011069260071963072,
0.006289408542215824,
0.006270051002502441,
-0.0007283111335709691,
-0.0023688431829214096,
0.005821683444082737,
0.0037921362090855837,
0.0017587743932381272,
0.012030355632305145,
-0.0007537701167166233,
-0.005422024521976709,
0.009460470639169216,
0.01068160030990839,
-0.0031349186319857836,
0.006822157651185989,
-0.0015051070367917418,
0.006403492297977209,
0.0016901412745937705,
-0.010423115454614162,
-0.010257328860461712,
0.0014488600427284837,
0.00488224858418107,
0.00932492595165968,
-0.0019636363722383976,
-0.00013089152344036847,
0.0014426219277083874,
-0.001086505362764001,
-0.012202506884932518,
-0.0062646158039569855,
-0.0011948745232075453,
0.0012135704746469855,
0.006096353754401207,
0.0730777233839035,
-0.005840102676302195,
-0.002237756736576557,
-0.008124619722366333,
0.00009552438859827816,
-0.0023643323220312595,
-0.0012439474230632186,
-0.0017327729146927595,
0.002477603731676936,
0.0037006386555731297,
0.0012791022891178727,
-0.006916363723576069,
-0.008706880733370781,
0.0008823014795780182,
0.003908943384885788,
-0.0024437187239527702,
0.0036007969174534082,
0.006883183028548956,
-0.006827749777585268,
0.0026292428374290466,
-0.012676773592829704,
-0.0025581077206879854,
-0.0013267261674627662,
-0.008676445111632347,
-0.0006208083941601217,
-0.0026480923406779766,
0.0014139637351036072,
0.007172974292188883,
0.00828821212053299,
-0.003462497377768159,
0.00546994199976325,
-0.004058707505464554,
0.00021390662004705518,
-0.005867318715900183,
0.00011471413017716259,
-0.004614530596882105,
0.006418891716748476,
-0.0000724691417417489,
-0.012200520373880863,
-0.00483340909704566,
-0.0018287578132003546,
0.00044673631782643497,
-0.006967656314373016,
0.0025539156049489975,
-0.0010932555887848139,
0.007354407105594873,
-0.0016459986800327897,
0.0014992430806159973,
-0.0048995064571499825,
0.0008007108699530363,
-0.012756715528666973,
0.005771655589342117,
-0.18123652040958405,
0.009411212988197803,
0.00013207801384851336,
-0.004750130698084831,
-0.00266811135224998,
-0.01725662872195244,
-0.007613107096403837,
0.0011209314689040184,
0.008505214937031269,
-0.0009020540164783597,
0.0014721091138198972,
-0.0036466203164309263,
0.008147942833602428,
0.0028791867662221193,
-0.0030558935832232237,
-0.0016182217514142394,
0.004608474671840668,
-0.005290653090924025,
-0.0010305303148925304,
0.0023123042192310095,
0.007354313507676125,
0.007079603616148233,
0.003442681161686778,
0.0016972237499430776,
-0.00048059181426651776,
-0.006471342407166958,
0.0046659065410494804,
-0.0008550363127142191,
0.00455083791166544,
-0.010672668926417828,
-0.005672548431903124,
-0.007290085311979055,
-0.002482590964064002,
0.0020528126042336226,
0.0029017296619713306,
-0.002912171883508563,
0.006605306640267372,
0.0008002306567505002,
-0.007469540927559137,
0.007276785094290972,
-0.006390025839209557,
0.02970024384558201,
0.00329997343942523,
0.009493052028119564,
0.0013380816671997309,
-0.0033693553414195776,
-0.004107311367988586,
0.008712688460946083,
0.0031855066772550344,
0.012910999357700348,
-0.012056279927492142,
-0.002738074865192175,
0.004236418753862381,
0.018469521775841713,
-0.0041093118488788605,
-0.011518062092363834,
-0.005995385814458132,
-0.008038267493247986,
0.0026275464333593845,
0.009976868517696857,
0.009056570008397102,
-0.005869983229786158,
0.008208674378693104,
-0.0037821175064891577,
-0.0203020628541708,
0.004965370986610651,
-0.003010969841852784,
-0.008019822649657726,
-0.0007394212298095226,
0.007056212052702904,
0.011207743547856808,
-0.005118922796100378,
0.00830491166561842,
-0.0008586409967392683,
0.002107046777382493,
-0.0014366511022672057,
0.005231520161032677,
-0.004473657812923193,
0.006087345536798239,
-0.009092098101973534,
0.009015643037855625,
-0.00653704022988677,
-0.002812969731166959,
0.004590957425534725,
-0.0049300179816782475,
0.011770585551857948,
0.006543716881424189,
-0.002965674502775073,
-0.001244878163561225,
-0.013184914365410805,
-0.0019896577578037977,
0.002999908523634076,
0.004145049024373293,
-0.005698569118976593,
0.0020522833801805973,
-0.002229107776656747,
0.0032311337999999523,
0.008968688547611237,
-0.009856924414634705,
0.0058264764957129955,
0.006160784512758255,
-0.007319257128983736,
0.001239984412677586,
-0.003867757972329855,
0.003320631105452776,
0.004151264205574989,
-0.00665888050571084,
-0.009812839329242706,
0.0027006925083696842,
-0.005914104171097279,
-0.0036909969057887793,
0.006530191283673048,
-0.0089053213596344,
-0.006309010554105043,
-0.0032427506521344185,
-0.01024412177503109,
0.0018128766678273678
] |
8a44c4f1bacc53b31ee5cd71ffc633ea07de715c | 5,326 | py | Python | src/pyrqlite/connections.py | zmedico/pyrqlite | 17a22221e4e796a04c28aa578a93821cc3349b41 | [
"MIT"
] | 2 | 2016-04-05T16:16:43.000Z | 2016-05-14T12:58:02.000Z | src/pyrqlite/connections.py | zmedico/pyrqlite | 17a22221e4e796a04c28aa578a93821cc3349b41 | [
"MIT"
] | 1 | 2017-06-04T07:36:45.000Z | 2017-06-04T22:57:05.000Z | src/pyrqlite/connections.py | zmedico/pyrqlite | 17a22221e4e796a04c28aa578a93821cc3349b41 | [
"MIT"
] | 1 | 2016-04-30T20:27:35.000Z | 2016-04-30T20:27:35.000Z |
from __future__ import unicode_literals
import codecs
import logging
try:
from http.client import HTTPConnection, HTTPSConnection
except ImportError:
# pylint: disable=import-error
from httplib import HTTPConnection, HTTPSConnection
try:
from urllib.parse import urlparse
except ImportError:
# pylint: disable=import-error
from urlparse import urlparse
from .constants import (
UNLIMITED_REDIRECTS,
)
from .cursors import Cursor
from ._ephemeral import EphemeralRqlited as _EphemeralRqlited
from .extensions import PARSE_DECLTYPES, PARSE_COLNAMES
class Connection(object):
from .exceptions import (
Warning,
Error,
InterfaceError,
DatabaseError,
DataError,
OperationalError,
IntegrityError,
InternalError,
ProgrammingError,
NotSupportedError,
)
def __init__(self, scheme='http', host='localhost', port=4001,
user=None, password=None, connect_timeout=None,
detect_types=0, max_redirects=UNLIMITED_REDIRECTS):
self.messages = []
self.scheme = scheme
self.host = host
self.port = port
self._headers = {}
if not (user is None or password is None):
self._headers['Authorization'] = 'Basic ' + \
codecs.encode('{}:{}'.format(user, password).encode('utf-8'),
'base64').decode('utf-8').rstrip('\n')
self.connect_timeout = connect_timeout
self.max_redirects = max_redirects
self.detect_types = detect_types
self.parse_decltypes = detect_types & PARSE_DECLTYPES
self.parse_colnames = detect_types & PARSE_COLNAMES
self._ephemeral = None
if scheme == ':memory:':
self._ephemeral = _EphemeralRqlited().__enter__()
self.host, self.port = self._ephemeral.http
self._connection = self._init_connection()
def _init_connection(self):
if self.scheme in ('http', ':memory:'):
cls = HTTPConnection
elif self.scheme == 'https':
cls = HTTPSConnection
else:
raise Connection.ProgrammingError('Unsupported scheme %r' % self.scheme)
return cls(self.host, port=self.port,
timeout=None if self.connect_timeout is None else float(self.connect_timeout))
def _retry_request(self, method, uri, body=None, headers={}):
tries = 10
while tries:
tries -= 1
try:
self._connection.request(method, uri, body=body,
headers=dict(self._headers, **headers))
return self._connection.getresponse()
except Exception:
if not tries:
raise
self._connection.close()
self._connection = self._init_connection()
def _fetch_response(self, method, uri, body=None, headers={}):
"""
Fetch a response, handling redirection.
"""
response = self._retry_request(method, uri, body=body, headers=headers)
redirects = 0
while response.status == 301 and \
response.getheader('Location') is not None and \
(self.max_redirects == UNLIMITED_REDIRECTS or redirects < self.max_redirects):
redirects += 1
uri = response.getheader('Location')
location = urlparse(uri)
logging.getLogger(__name__).debug("status: %s reason: '%s' location: '%s'",
response.status, response.reason, uri)
if self.host != location.hostname or self.port != location.port:
self._connection.close()
self.host = location.hostname
self.port = location.port
self._connection = self._init_connection()
response = self._retry_request(method, uri, body=body, headers=headers)
return response
def close(self):
"""Close the connection now (rather than whenever .__del__() is
called).
The connection will be unusable from this point forward; an
Error (or subclass) exception will be raised if any operation
is attempted with the connection. The same applies to all
cursor objects trying to use the connection. Note that closing
a connection without committing the changes first will cause an
implicit rollback to be performed."""
self._connection.close()
if self._ephemeral is not None:
self._ephemeral.__exit__(None, None, None)
self._ephemeral = None
def __del__(self):
self.close()
def commit(self):
"""Database modules that do not support transactions should
implement this method with void functionality."""
pass
def rollback(self):
"""This method is optional since not all databases provide
transaction support. """
pass
def cursor(self, factory=None):
"""Return a new Cursor Object using the connection."""
if factory:
return factory(self)
else:
return Cursor(self)
def execute(self, *args, **kwargs):
return self.cursor().execute(*args, **kwargs)
| 34.141026 | 97 | 0.608336 | 1 | 1.8756 | [
-0.010205207392573357,
0.06444606930017471,
0.00798284262418747,
0.05503222718834877,
-0.011242828331887722,
0.012261878699064255,
0.027446521446108818,
-0.036207448691129684,
0.03488827124238014,
-0.0011607722844928503,
0.008531351573765278,
-0.0033951110672205687,
0.01974785327911377,
-0.05377563461661339,
-0.0104075837880373,
0.039201878011226654,
0.05916600301861763,
-0.034093793481588364,
-0.055028047412633896,
0.023759333416819572,
0.005855807103216648,
0.006330299191176891,
-0.02340320311486721,
0.0016662628622725606,
0.013811509124934673,
0.022151831537485123,
0.019469527527689934,
-0.022745706140995026,
0.01136489026248455,
-0.05578571557998657,
0.025070276111364365,
0.019808363169431686,
0.05291888862848282,
-0.007825221866369247,
0.014390146359801292,
-0.0509587787091732,
0.027352144941687584,
-0.06026186794042587,
0.060712844133377075,
0.0016433588461950421,
-0.029523281380534172,
-0.01574537344276905,
0.046187322586774826,
0.005908559076488018,
0.0318630151450634,
0.023742539808154106,
0.010504961013793945,
-0.019839122891426086,
-0.03861051797866821,
0.03477420657873154,
-0.02733238786458969,
0.00527277123183012,
-0.03772224485874176,
0.015248754993081093,
-0.0016994657926261425,
-0.03722511604428291,
0.025944232940673828,
0.04069767892360687,
-0.06763806194067001,
-0.0020891763269901276,
-0.00011862849351018667,
-0.004965431522578001,
0.01948765106499195,
0.02450447343289852,
-0.003383354051038623,
-0.03457292541861534,
-0.032383669167757034,
0.026801839470863342,
0.007551759481430054,
0.04820871725678444,
0.016131145879626274,
0.011110109277069569,
0.06486158072948456,
-0.011654451489448547,
-0.02031106688082218,
0.00679597444832325,
-0.02428034134209156,
-0.036374203860759735,
-0.013165317475795746,
-0.045685555785894394,
-0.029384413734078407,
0.06763304024934769,
-0.009448705241084099,
-0.014692354947328568,
0.012634504586458206,
-0.005980575457215309,
0.0594806931912899,
-0.014030774123966694,
0.049728550016880035,
0.031577613204717636,
-0.03841538727283478,
-0.03629651293158531,
0.012512022629380226,
-0.02860039472579956,
-0.007903249934315681,
-0.026132576167583466,
0.021598627790808678,
-0.010498142801225185,
0.028697315603494644,
-0.02197290025651455,
0.04829677939414978,
-0.001117386040277779,
0.06706567108631134,
-0.017386138439178467,
0.0027907269541174173,
-0.020184962078928947,
-0.04771227017045021,
0.006770126521587372,
0.052545420825481415,
-0.03396781533956528,
0.01897016540169716,
0.04236811399459839,
0.03655611723661423,
-0.018371429294347763,
-0.10441984236240387,
-0.014561193063855171,
-0.0017428093124181032,
-0.0002531309728510678,
-0.0022703572176396847,
-0.003722632536664605,
0.002581882756203413,
0.015563617460429668,
-0.025250358507037163,
-0.03255317732691765,
-0.02962304651737213,
0.09549973160028458,
-0.042269960045814514,
0.03650415688753128,
0.007476674392819405,
-0.022067870944738388,
-0.02725352719426155,
-0.002181149320676923,
-0.037131305783987045,
0.036171190440654755,
0.0015843475703150034,
0.048029083758592606,
0.024360748007893562,
0.02466847002506256,
-0.08642898499965668,
0.009802035987377167,
-0.029386969283223152,
-0.00979231484234333,
0.05383676290512085,
0.041530318558216095,
0.02147224359214306,
-0.04727274924516678,
-0.0013243365101516247,
0.018010953441262245,
-0.026588648557662964,
-0.003976440988481045,
-0.0019597054924815893,
0.061601296067237854,
-0.00017127733735833317,
-0.01305015105754137,
-0.01763710007071495,
-0.005919340532273054,
-0.022609403356909752,
-0.015044271014630795,
-0.008304900489747524,
-0.016914093866944313,
0.02015005052089691,
0.03689264506101608,
0.017334384843707085,
0.004104631021618843,
0.0409226231276989,
0.03694533929228783,
-0.011586855165660381,
0.033359408378601074,
0.009129393845796585,
-0.0005117005784995854,
0.008913981728255749,
-0.002931094728410244,
-0.04509742930531502,
-0.035652972757816315,
-0.04184212163090706,
0.0009157168678939342,
0.013271784409880638,
0.02590116858482361,
0.023611286655068398,
-0.021974870935082436,
-0.014479967765510082,
-0.07073311507701874,
0.0063864970579743385,
0.020549768581986427,
0.00033793735201470554,
-0.0019035888835787773,
-0.042679764330387115,
-0.009420061483979225,
-0.011326316744089127,
-0.0033731157891452312,
0.008000223897397518,
-0.025651264935731888,
-0.01800462417304516,
-0.004633999429643154,
0.024182487279176712,
0.014237572439014912,
0.011116794310510159,
-0.020116448402404785,
0.03011821024119854,
0.0038234246894717216,
-0.030511151999235153,
0.024150215089321136,
-0.006882598157972097,
-0.0065759047865867615,
0.035624902695417404,
-0.0213338490575552,
-0.6288783550262451,
0.04595089703798294,
-0.010784843005239964,
-0.03519962355494499,
0.03454222530126572,
0.004020350519567728,
-0.033784445375204086,
-0.004917615558952093,
-0.02758915163576603,
-0.03132542222738266,
0.018874391913414,
-0.007462495006620884,
-0.02091793157160282,
0.0016390277305617929,
-0.046567950397729874,
-0.017503099516034126,
-0.028911320492625237,
0.004972045309841633,
-0.03515484184026718,
-0.008405623957514763,
0.016183089464902878,
-0.006133794318884611,
0.00796427484601736,
0.0022506637033075094,
-0.03545263409614563,
-0.06388594955205917,
-0.00043105825898237526,
-0.006460193078964949,
-0.032067619264125824,
0.018870260566473007,
-0.04925760254263878,
0.02950284443795681,
0.02160440944135189,
-0.028206951916217804,
-0.005024842917919159,
0.031148992478847504,
0.04045959562063217,
-0.01801997609436512,
-0.0037811757065355778,
-0.03608527407050133,
-0.0042953104712069035,
0.011610612273216248,
0.006806870922446251,
-0.06761743128299713,
-0.01999032311141491,
-0.0349065363407135,
0.016206316649913788,
-0.013160446658730507,
-0.01924086920917034,
-0.002690625609830022,
-0.051039837300777435,
0.0014367039548233151,
0.01992197521030903,
0.01231586467474699,
-0.00006307186413323507,
0.0038273411337286234,
-0.011619802564382553,
-0.0014497776282951236,
0.010387380607426167,
0.004493114538490772,
-0.01957015134394169,
0.023894384503364563,
-0.02058304473757744,
0.005490303970873356,
-0.07837264984846115,
0.015425875782966614,
0.016632379963994026,
-0.05722077563405037,
-0.05247512832283974,
0.010645819827914238,
-0.07074595242738724,
0.025761770084500313,
-0.03214758262038231,
0.02335255779325962,
-0.011394395492970943,
0.02054816484451294,
0.019702019169926643,
0.0035926091950386763,
0.0008624338661320508,
0.0013922650832682848,
0.04277488961815834,
-0.027843941003084183,
0.010996145196259022,
0.00018695482867769897,
-0.001982887042686343,
0.011404629796743393,
0.03404824808239937,
-0.019195029512047768,
0.024994168430566788,
0.007235127501189709,
-0.04094390571117401,
0.04811576008796692,
0.03187026455998421,
-0.0008345949463546276,
-0.010182647034525871,
-0.01488285232335329,
0.020489390939474106,
0.038202881813049316,
-0.002708482090383768,
0.019444508478045464,
-0.0379084087908268,
-0.0019490744452923536,
0.01910615898668766,
0.03947785124182701,
-0.0784081444144249,
-0.008862773887813091,
0.0052209882996976376,
0.002355409087613225,
0.03679893910884857,
-0.015401333570480347,
-0.02379482425749302,
0.00914845336228609,
0.008882572874426842,
-0.0008708627428859472,
-0.01233903132379055,
-0.029006047174334526,
-0.0030518698040395975,
-0.03041982837021351,
0.03650478646159172,
0.01258100662380457,
0.019526632502675056,
-0.008380346931517124,
-0.011092337779700756,
0.04477206617593765,
-0.01976754330098629,
-0.0016616982175037265,
-0.006047871429473162,
0.005577264819294214,
0.029025431722402573,
0.016174696385860443,
-0.03905341774225235,
0.017702000215649605,
0.030684033408761024,
-0.015979887917637825,
-0.02758067473769188,
-0.017028337344527245,
0.010538891889154911,
-0.018707916140556335,
0.02984662912786007,
0.013000833801925182,
-0.031065471470355988,
0.00047037837794050574,
-0.004881947301328182,
-0.035761959850788116,
0.02483367547392845,
0.020595325157046318,
-0.006525285542011261,
0.03294169530272484,
-0.03604980930685997,
-0.008159870281815529,
-0.03360215574502945,
0.027170151472091675,
-0.005634416826069355,
-0.02008717693388462,
-0.03166503086686134,
-0.0050718761049211025,
-0.008832699619233608,
-0.02481946162879467,
0.002743188990280032,
0.019601786509156227,
0.013605529442429543,
-0.0245065800845623,
-0.008032901212573051,
0.0578492172062397,
0.030019374564290047,
0.006024177186191082,
0.0027645521331578493,
0.011608488857746124,
0.009415472857654095,
0.03349170461297035,
-0.029444634914398193,
0.02003990299999714,
0.017105353996157646,
0.021277735009789467,
0.014642066322267056,
-0.011544954031705856,
-0.009371289052069187,
-0.0715733990073204,
-0.029743671417236328,
0.022982176393270493,
0.007381081115454435,
0.03526433929800987,
-0.016873018816113472,
0.04280909150838852,
0.022899186238646507,
-0.005287311039865017,
0.014904582872986794,
-0.0035842163488268852,
0.0056592258624732494,
-0.012003821320831776,
0.026816103607416153,
0.04723697155714035,
-0.02784048207104206,
-0.0012047436321154237,
-0.018674783408641815,
-0.015408140607178211,
-0.03015352599322796,
-0.007021717727184296,
0.038209110498428345,
-0.04904557392001152,
-0.012304700911045074,
0.04839697480201721,
-0.04383879154920578,
-0.007795198354870081,
0.012905691750347614,
0.030285317450761795,
-0.01760999672114849,
0.021800005808472633,
0.02967044524848461,
0.01850920170545578,
0.005566812120378017,
-0.030964937061071396,
0.007131664548069239,
0.017024405300617218,
-0.015218825079500675,
0.008485040627419949,
-0.04747899994254112,
-0.039767198264598846,
0.00472106272354722,
-0.061117690056562424,
0.021174399182200432,
0.016109144315123558,
0.014416736550629139,
0.02242334559559822,
0.019616156816482544,
0.010018090717494488,
-0.04405464604496956,
0.0015605997759848833,
0.007497276179492474,
0.003079964080825448,
0.028566865250468254,
-0.05063513293862343,
-0.004230734892189503,
0.0003617933834902942,
-0.013620062731206417,
0.03628713637590408,
0.013180553913116455,
-0.005161625798791647,
-0.0021964318584650755,
-0.004675209056586027,
0.02855309098958969,
0.0014773590955883265,
-0.019768401980400085,
0.01827961951494217,
0.01861800067126751,
-0.025437498465180397,
-0.02109770104289055,
-0.031484853476285934,
0.009982630610466003,
-0.00840039923787117,
0.021728988736867905,
0.032448701560497284,
-0.01204171683639288,
0.023194829002022743,
0.0002103983861161396,
-0.016759976744651794,
0.016112565994262695,
0.037911370396614075,
0.04229253903031349,
-0.00842320453375578,
0.041644252836704254,
-0.013500675559043884,
-0.010379118844866753,
-0.0031303067225962877,
-0.002532062353566289,
0.01472662203013897,
0.004976297728717327,
0.025384938344359398,
0.018631361424922943,
0.024224190041422844,
0.02559051103889942,
-0.03150934725999832,
0.004872471559792757,
-0.018922243267297745,
0.05557461455464363,
-0.006970115005970001,
-0.000462538271676749,
0.007538802921772003,
-0.04154888540506363,
0.030919501557946205,
-0.022143244743347168,
0.005553550086915493,
0.02167954295873642,
0.010306897573173046,
0.00601706700399518,
-0.020151855424046516,
-0.001198877696879208,
0.008728316985070705,
-0.03305074945092201,
-0.02376621402800083,
-0.03856811672449112,
-0.01571490243077278,
0.0357508547604084,
0.01755800098180771,
0.01653054542839527,
0.001660649897530675,
-0.017316043376922607,
-0.005693330895155668,
0.024444997310638428,
-0.0325615368783474,
0.00606985529884696,
-0.02848520688712597,
-0.01890547201037407,
-0.04693272337317467,
0.02344626560807228,
0.011175621300935745,
-0.02283080667257309,
-0.03189992532134056,
0.047545842826366425,
-0.022167488932609558,
0.02598559483885765,
-0.007637090049684048,
-0.010906337760388851,
0.011820562183856964,
-0.025387687608599663,
0.04009434953331947,
0.031193053349852562,
0.015793640166521072,
0.018264619633555412,
-0.04296322166919708,
-0.02972188964486122,
-0.012768846936523914,
-0.010895040817558765,
-0.04537918418645859,
0.03257337585091591,
0.0020422523375600576,
-0.02769034169614315,
-0.025109391659498215,
0.02365938015282154,
0.0011150827631354332,
0.01620487868785858,
-0.030279600992798805,
-0.030225731432437897,
-0.014897970482707024,
-0.006393348332494497,
0.02268708497285843,
-0.008365612477064133,
0.03346781060099602,
0.010343765839934349,
0.010495799593627453,
0.06327895075082779,
0.018771979957818985,
-0.010034718550741673,
-0.03351341560482979,
0.03604918345808983,
0.00304217217490077,
0.04913433641195297,
0.04660733789205551,
0.047360651195049286,
-0.037750598043203354,
0.014985659159719944,
0.001848978572525084,
0.03174101188778877,
-0.011275027878582478,
0.027735285460948944,
-0.05649756267666817,
0.006704206578433514,
-0.029964648187160492,
0.04803960770368576,
0.0311678946018219,
-0.053203035145998,
-0.019661180675029755,
-0.030329374596476555,
-0.000703781726770103,
0.01491275243461132,
-0.015839556232094765,
0.000343997438903898,
-0.025622235611081123,
-0.04080431908369064,
-0.007220566272735596,
0.011678231880068779,
-0.01949969120323658,
0.030368782579898834,
0.01698269322514534,
0.013447477482259274,
0.056747645139694214,
0.0537845641374588,
-0.022875091060996056,
-0.018716944381594658,
0.043349236249923706,
0.01857190579175949,
-0.06704164296388626,
-0.012414217926561832,
-0.03270195797085762,
-0.03350882604718208,
0.028499126434326172,
-0.0015273968456313014,
0.0028569521382451057,
-0.04113520681858063,
-0.005526955705136061,
0.0014891094760969281,
-0.0027790041640400887,
0.055973347276449203,
0.00046115517034195364,
-0.0006326921284198761,
0.00032599197584204376,
-0.01893520914018154,
-0.027913430705666542,
0.027734560891985893,
0.007921688258647919,
0.019379865378141403,
0.012580911628901958,
0.028635116294026375,
0.00047158903907984495,
0.04884364828467369,
-0.0404064804315567,
-0.0021201674826443195,
-0.04235236719250679,
0.00839965045452118,
-0.010814856737852097,
0.03466106578707695,
0.03470543026924133,
-0.011916679330170155,
-0.041613105684518814,
-0.0021156773436814547,
0.044298578053712845,
-0.005205433815717697,
0.01807667501270771,
0.02287841960787773,
0.018462318927049637,
-0.027176126837730408,
-0.0002770465798676014,
-0.014813583344221115,
0.0012396486708894372,
0.013449640944600105,
-0.03871089965105057,
-0.009791793301701546,
0.03122386708855629,
0.002238377695903182,
0.03083113022148609,
0.042576972395181656,
0.05204213038086891,
0.004497119691222906,
0.02495061792433262,
0.0190548375248909,
0.010467051528394222,
-0.0043143900111317635,
-0.020015232264995575,
-0.008306688629090786,
0.0005237680161371827,
-0.06465418636798859,
-0.04939543455839157,
0.007299043238162994,
0.022206410765647888,
-0.04194597899913788,
-0.09326262027025223,
0.005805926397442818,
0.030512303113937378,
-0.02104661427438259,
-0.014294440858066082,
-0.040372636169195175,
0.009110590443015099,
0.025559263303875923,
0.00557325454428792,
0.020221823826432228,
-0.024514617398381233,
0.012276878580451012,
0.07009025663137436,
-0.0194545891135931,
0.02138235978782177,
-0.014231646433472633,
0.03923469036817551,
-0.0395389050245285,
0.010357624851167202,
-0.015454284846782684,
0.04076661169528961,
0.01779096946120262,
-0.00795594323426485,
-0.01894732378423214,
-0.01749725081026554,
0.000790911668445915,
0.020712243393063545,
-0.02365894615650177,
0.0034835422411561012,
0.013997375033795834,
-0.010311787948012352,
-0.02163887396454811,
0.0061065503396093845,
0.026479553431272507,
0.0036397576332092285,
-0.030549421906471252,
0.022006383165717125,
0.04668005183339119,
-0.009597515687346458,
-0.013928401283919811,
-0.009086343459784985,
-0.03325996920466423,
0.04053511470556259,
-0.005050779785960913,
-0.012648506090044975,
-0.01121516339480877,
-0.0321367122232914,
0.000985531136393547,
-0.0035209888592362404,
0.01929163932800293,
-0.02661675214767456,
0.009233321063220501,
0.023740384727716446,
0.03129252791404724,
0.013580271042883396,
0.006067922804504633,
-0.01242379192262888,
0.006340530700981617,
-0.03838488832116127,
-0.00825363490730524,
0.031297944486141205,
0.01926790550351143,
0.016004106029868126,
-0.02430831640958786,
0.011426527053117752,
-0.007192854769527912,
-0.012088827788829803,
-0.04393132030963898,
-0.0085767125710845,
-0.02883438766002655,
0.039097994565963745,
0.048409365117549896,
-0.04736901819705963,
0.027999309822916985,
-0.010549597442150116,
0.030674699693918228,
-0.05253827944397926,
0.0200898889452219,
-0.018469011411070824,
-0.006970861926674843,
-0.025518689304590225,
-0.018845930695533752,
-0.031820375472307205,
0.010026969946920872,
-0.018816767260432243,
0.003497316734865308,
-0.029024608433246613,
-0.003000776981934905,
-0.03504446893930435,
-0.02271576039493084,
-0.03395523503422737,
0.04766567423939705,
-0.009969216771423817,
-0.013856284320354462,
-0.02487974986433983,
0.04337996989488602,
0.02823435515165329,
-0.033795710653066635,
0.0004301313019823283,
0.022494565695524216,
-0.03520631045103073,
-0.025735197588801384,
-0.04670010134577751,
-0.011361638084053993,
-0.05677153542637825,
0.029265159741044044,
-0.009711217135190964,
0.0393233560025692,
-0.01183953508734703,
-0.024027999490499496,
0.004221042152494192,
-0.0013884389773011208,
0.08211962878704071,
0.02042158506810665,
-0.007804337423294783,
-0.033188074827194214,
0.02608686126768589
] |
8a44d6f6124cbf59eb9c835f08ecb56f0d9adf5a | 737 | py | Python | PythonBasics/ConditionalStatements/Exercise/toy_shop.py | achoraev/SoftUni | 0cc7db470a096cc33bbe0ca6bd90060b79120573 | [
"Apache-2.0"
] | null | null | null | PythonBasics/ConditionalStatements/Exercise/toy_shop.py | achoraev/SoftUni | 0cc7db470a096cc33bbe0ca6bd90060b79120573 | [
"Apache-2.0"
] | null | null | null | PythonBasics/ConditionalStatements/Exercise/toy_shop.py | achoraev/SoftUni | 0cc7db470a096cc33bbe0ca6bd90060b79120573 | [
"Apache-2.0"
] | null | null | null | price = float(input())
puzzles = int(input())
dolls = int(input())
bears = int(input())
minions = int(input())
trucks = int(input())
total_toys = puzzles + dolls + bears + minions + trucks
price_puzzles = puzzles * 2.6
price_dolls = dolls * 3
price_bears = bears * 4.1
price_minions = minions * 8.2
price_trucks = trucks * 2
total_price = price_puzzles + price_dolls + price_bears + price_minions + price_trucks
if total_toys >= 50:
total_price = total_price - (total_price * 0.25)
rent = total_price * 0.1
total_price = total_price - rent
if total_price >= price:
print(f"Yes! {(total_price - price):.2f} lv left.")
else:
print(f"Not enough money! {(price - total_price):.2f} lv needed.")
| 25.413793 | 87 | 0.662144 | 1 | 0.9411 | [
0.002541776979342103,
0.022874169051647186,
0.009610539302229881,
0.0014995831297710538,
0.005515483673661947,
-0.006194974295794964,
-0.00972626730799675,
0.0029821337666362524,
-0.007857891730964184,
0.0015923497267067432,
0.001759436447173357,
0.005190670024603605,
0.007461428642272949,
-0.018852781504392624,
0.0011627902276813984,
0.016424592584371567,
-0.05134870111942291,
0.0017293631099164486,
-0.0034829797223210335,
0.004270053002983332,
-0.005756697617471218,
0.010186797939240932,
0.009870560839772224,
0.004758286755532026,
0.007224663160741329,
-0.001063919742591679,
0.010569368489086628,
0.00261563784442842,
-0.006940071936696768,
-0.007654350250959396,
-0.0009333699126727879,
-0.003293050220236182,
-0.006980572827160358,
-0.008775681257247925,
0.004542547278106213,
-0.0038871001452207565,
-0.0009056319831870496,
-0.019898300990462303,
0.013358511961996555,
-0.0034149109851568937,
-0.0067067802883684635,
-0.014190777204930782,
0.0025950579438358545,
0.003587656654417515,
-0.009126867167651653,
0.0011726220836862922,
-0.0047350795939564705,
0.003235596464946866,
-0.009187736548483372,
0.005390707403421402,
-0.010277493856847286,
0.004644733853638172,
0.012987187132239342,
0.003953115548938513,
-0.004460593685507774,
-0.005447394214570522,
0.012075898237526417,
-0.0020996800158172846,
-0.012238648720085621,
-0.0017946005100384355,
-0.004268921911716461,
-0.002514149760827422,
0.0035909838043153286,
0.0013254837831482291,
-0.015841800719499588,
-0.0077393269166350365,
-0.003997019026428461,
0.0031875574495643377,
-0.0010874434374272823,
0.005325132515281439,
0.0014773269649595022,
0.001688786200247705,
0.007584807462990284,
0.0023001222871243954,
0.0014154802775010467,
-0.0031163401436060667,
-0.0020890897139906883,
0.001629384234547615,
0.007718045264482498,
0.0025598646607249975,
0.007894383743405342,
-0.008596046827733517,
0.004972757771611214,
0.010648672468960285,
0.012064105831086636,
0.00823924783617258,
0.018376274034380913,
-0.011797534301877022,
0.04720171168446541,
0.007719527464359999,
-0.007421987596899271,
0.0023372252471745014,
-0.008977399207651615,
-0.002412462839856744,
-0.004251985345035791,
-0.030407678335905075,
-0.002120668301358819,
-0.004570727702230215,
0.00016705674352124333,
0.0033781437668949366,
0.0008366717956960201,
0.008227167651057243,
0.00026880603400059044,
-0.0027260431088507175,
-0.00520031712949276,
0.010249157436192036,
-0.008520752191543579,
-0.0045114438980817795,
0.007804940454661846,
0.0023044561967253685,
-0.013258731923997402,
-0.002150507876649499,
0.0028709794860333204,
-0.011778172105550766,
0.007838212884962559,
0.003444487461820245,
-0.005400936584919691,
0.05563463270664215,
-0.0013754941755905747,
0.001860865973867476,
-0.006797696463763714,
0.0018134764395654202,
0.003237718716263771,
0.008048313669860363,
0.008425639942288399,
-0.0031373894307762384,
0.012950325384736061,
0.008777590468525887,
0.0036225703079253435,
0.008634072728455067,
-0.0004430171975400299,
0.005543629173189402,
-0.0031261546537280083,
-0.0012561959447339177,
0.0035034490283578634,
-0.008963474072515965,
0.01210062950849533,
-0.0023678140714764595,
-0.007703086361289024,
0.0006620345520786941,
-0.0003891145170200616,
-0.010006209835410118,
0.002081198152154684,
-0.0020983766298741102,
0.0022257647942751646,
-0.01065074186772108,
-0.0020003733225166798,
-0.005398772656917572,
-0.00383059773594141,
0.0032991813495755196,
0.010013782419264317,
0.00625432375818491,
0.002817164408043027,
-0.00951619166880846,
-0.010401773266494274,
-0.0001648587640374899,
-0.003299974836409092,
0.003616107627749443,
0.010358041152358055,
0.004664970561861992,
-0.010700213722884655,
-0.00341657642275095,
0.001849451451562345,
0.002768256701529026,
-0.00040046381764113903,
0.0011726404773071408,
-0.008495403453707695,
0.006416275165975094,
0.001362956129014492,
0.00525077898055315,
0.010964815504848957,
-0.003475623205304146,
0.00013345493061933666,
-0.0005338826449587941,
0.001813280745409429,
-0.001291321823373437,
0.005179723724722862,
0.010934594087302685,
-0.0043218135833740234,
-0.004968535620719194,
0.004783161915838718,
0.006495879031717777,
0.009008199907839298,
0.003057671245187521,
-0.002538790926337242,
0.0007401410839520395,
-0.002851372119039297,
-0.0010719506535679102,
0.006444429978728294,
-0.004551853984594345,
0.005318049807101488,
0.004624128807336092,
-0.012981915846467018,
-0.009839747101068497,
0.0009600440389476717,
-0.009311046451330185,
0.0010427696397528052,
0.013766293413937092,
0.009334895759820938,
-0.0034122862853109837,
0.0010681895073503256,
-0.011540953069925308,
0.0008897136431187391,
0.007345190271735191,
0.002697175135836005,
-0.013261550106108189,
-0.9581987857818604,
0.007430338766425848,
0.0015973917907103896,
-0.0013634196948260069,
0.004299077671021223,
0.002343439729884267,
0.004982134327292442,
0.0039206999354064465,
0.01541490200906992,
-0.009126638062298298,
-0.007589746732264757,
-0.009723981842398643,
-0.00982439611107111,
-0.0019649469759315252,
-0.008524328470230103,
-0.0038773759733885527,
-0.007542298641055822,
-0.006659250240772963,
0.0002344197127968073,
-0.003287238534539938,
-0.0018922887975350022,
0.008421673439443111,
-0.0000820424611447379,
0.005593134090304375,
0.0056647369638085365,
0.002712834859266877,
-0.006710296496748924,
-0.0019337702542543411,
-0.004524766001850367,
-0.003381232265383005,
-0.005824888125061989,
-0.013184519484639168,
-0.0065974160097539425,
0.0004571748722810298,
0.010778134688735008,
-0.00039127314812503755,
0.010696085169911385,
-0.0014925042632967234,
0.0016902433708310127,
-0.006228805519640446,
0.006347754970192909,
0.0003101673792116344,
0.002278678584843874,
-0.02876817248761654,
-0.00019475538283586502,
-0.0012301785172894597,
-0.0071814707480371,
0.009500623680651188,
-0.002543774666264653,
-0.0018947216449305415,
-0.003248281078413129,
-0.003287260653451085,
0.005197112914174795,
-0.008944123983383179,
0.0035690676886588335,
-0.0054471613839268684,
-0.0073903221637010574,
-0.002329727169126272,
-0.008948370814323425,
0.00015129528765100986,
0.001569049316458404,
-0.002614495810121298,
-0.0030686534009873867,
-0.0031909672543406487,
0.0041222781874239445,
0.001773050520569086,
0.0017129750922322273,
-0.015230784192681313,
-0.005316118244081736,
0.0022368167992681265,
-0.0012384928995743394,
-0.0028342888690531254,
-0.004124639555811882,
0.0023811301216483116,
-0.010488721542060375,
0.005162111017853022,
0.0008107672911137342,
-0.0014081135159358382,
-0.013521213084459305,
-0.0008497682865709066,
-0.008206244558095932,
-0.011037781834602356,
0.002192038344219327,
-0.00509616220369935,
-0.0038275837432593107,
-0.001039783819578588,
-0.0002604403125587851,
0.007545182481408119,
-0.0045170956291258335,
0.0031021987088024616,
0.010817181318998337,
-0.0027554119005799294,
-0.01036040112376213,
0.007786550559103489,
0.005827694199979305,
0.0013120053336024284,
-0.003967295400798321,
0.003174392506480217,
0.00862910971045494,
0.010560629889369011,
0.00026657787384465337,
0.004362407606095076,
-0.0006318695959635079,
0.01052361261099577,
-0.0012933396501466632,
0.0011417206842452288,
-0.003342675045132637,
0.0002458789385855198,
-0.0025291433557868004,
-0.0010107625275850296,
-0.0034387423656880856,
-0.0014301837654784322,
-0.012514816597104073,
-0.010838160291314125,
-0.004833755549043417,
0.00033248186809942126,
0.00205165334045887,
-0.004597116727381945,
0.0018705473048612475,
0.001241627149283886,
0.007856437936425209,
0.00117846904322505,
-0.0045442176051437855,
-0.0006741753313690424,
0.0018544815247878432,
-0.0052978163585066795,
0.015058456920087337,
-0.01318685244768858,
0.006291630212217569,
-0.0008862202521413565,
-0.013821701519191265,
0.005892694462090731,
0.009754129685461521,
-0.008235407061874866,
-0.00022733031073585153,
0.0022473339922726154,
0.004526256117969751,
0.0007968583959154785,
-0.004852736834436655,
-0.0034597155172377825,
-0.016878893598914146,
0.0005676136934198439,
0.019083857536315918,
0.0038236125838011503,
0.008638573810458183,
0.011467184871435165,
-0.0038378683384507895,
0.0031316678505390882,
0.008954380638897419,
0.0020336760208010674,
0.013142730109393597,
-0.010466806590557098,
0.0015094311675056815,
0.002917889505624771,
-0.007064343895763159,
0.0018887465121224523,
0.006058778613805771,
0.004602945875376463,
-0.005150312557816505,
0.0014560443814843893,
-0.007438880391418934,
-0.004626021720468998,
-0.02060076966881752,
-0.00424120482057333,
0.006151920184493065,
-0.00585616659373045,
0.006403755862265825,
-0.012337897904217243,
0.004937157034873962,
0.004701552912592888,
0.0018395086517557502,
-0.0011948556639254093,
0.0019133372697979212,
0.0054879458621144295,
0.01437635999172926,
-0.005479292944073677,
0.0028639587108045816,
0.0035197362303733826,
-0.0023560160771012306,
0.0030501331202685833,
0.00922368373721838,
-0.00730345631018281,
-0.0065900846384465694,
0.004893979988992214,
0.005914503242820501,
0.0005009775632061064,
-0.004624319728463888,
-0.009355919435620308,
-0.005306765902787447,
0.0023858717177063227,
-0.007646220736205578,
0.004442157689481974,
-0.00009234342724084854,
0.0038040666840970516,
-0.006217609625309706,
-0.001976414816454053,
-0.001668055192567408,
-0.013283733278512955,
0.009253626689314842,
-0.0018806152511388063,
0.00347640598192811,
0.011564490385353565,
0.001749170944094658,
-0.012405583634972572,
0.0054619587026536465,
0.008655313402414322,
-0.004874089267104864,
0.0033452727366238832,
0.006343905348330736,
-0.006235985551029444,
-0.022940395399928093,
-0.0016383419279009104,
-0.014669079333543777,
0.007336854934692383,
-0.002861620858311653,
0.001516740769147873,
-0.008978954516351223,
0.009470355696976185,
0.005753729026764631,
-0.01225150004029274,
-0.004795735236257315,
-0.008424959145486355,
0.008926824666559696,
-0.001279605901800096,
-0.002962360391393304,
-0.0029596243984997272,
-0.00036880766856484115,
-0.0020502214320003986,
-0.0033091355580836535,
-0.002112635411322117,
0.004530145321041346,
0.0017759513575583696,
-0.0035107326693832874,
0.001260102610103786,
-0.001208365662023425,
0.0017413072055205703,
0.0001638699322938919,
-0.010989949107170105,
0.00006587785173906013,
0.0047711217775940895,
-0.00010140529047930613,
-0.0038220512215048075,
0.0026900421362370253,
-0.0016921573551371694,
-0.0074285236187279224,
-0.011212795041501522,
-0.006234383210539818,
-0.002914365381002426,
-0.003249639179557562,
-0.013628040440380573,
-0.0022874099668115377,
-0.00711255194619298,
0.009139405563473701,
-0.004463471006602049,
0.009985977783799171,
0.003490347182378173,
-0.004063127562403679,
0.006733754184097052,
-0.0029507549479603767,
0.004216314293444157,
0.002522153314203024,
0.006236201152205467,
0.0009615172748453915,
-0.003560206387192011,
-0.011536345817148685,
0.010888147167861462,
-0.007134421728551388,
0.0028995443135499954,
0.0153506426140666,
0.00519975321367383,
0.008809616789221764,
0.00007379127782769501,
-0.000036415571230463684,
0.0029615857638418674,
0.0058469208888709545,
-0.011694852262735367,
0.0025661992840468884,
-0.003600720316171646,
-0.0003761737607419491,
0.00406598811969161,
-0.00243328046053648,
0.002025543013587594,
0.008740231394767761,
0.0011389023857191205,
-0.007126804906874895,
-0.0035576410591602325,
0.0020731622353196144,
0.0026865422260016203,
-0.01236378587782383,
-0.0011592762311920524,
-0.002341650892049074,
-0.00444890046492219,
-0.002995687071233988,
-0.0025896653532981873,
-0.002707405248656869,
0.004827655851840973,
-0.0006589008844457567,
0.007794274482876062,
0.0025066398084163666,
-0.005891446489840746,
0.011517735198140144,
-0.0038471112493425608,
-0.002024669898673892,
0.0019440451869741082,
0.0013350840890780091,
-0.0004867741372436285,
-0.006607017479836941,
-0.0024682078510522842,
0.0007223755237646401,
0.006211495958268642,
-0.0036203856579959393,
-0.0038880640640854836,
-0.0034727491438388824,
0.0031733764335513115,
-0.01178699266165495,
0.001423463225364685,
0.010963921435177326,
-0.005118978209793568,
0.004683273378759623,
-0.00282677891664207,
-0.007457812782377005,
-0.011706537567079067,
0.05346182361245155,
-0.001115721301175654,
0.0010688721667975187,
0.003754948964342475,
-0.006475886330008507,
-0.0009063221514225006,
-0.004818014334887266,
0.006444628816097975,
-0.004634309560060501,
-0.006786982528865337,
0.008026259951293468,
-0.003178656566888094,
0.002968697575852275,
0.004267681390047073,
-0.0013270360650494695,
0.01755165122449398,
-0.003627572674304247,
-0.015430904924869537,
-0.01680034212768078,
0.006970168091356754,
-0.004251031205058098,
-0.00530398590490222,
0.00862837117165327,
-0.003534386632964015,
-0.0030335818883031607,
0.00048392152530141175,
0.005806857720017433,
0.000730249856133014,
-0.0018345506396144629,
-0.001334632863290608,
-0.000243933784076944,
-0.002794464584439993,
0.0004314787802286446,
0.004555339924991131,
0.00537169398739934,
-0.0021853591315448284,
0.0013387154322117567,
-0.00015792167687322944,
-0.0020676807034760714,
0.0000758103487896733,
0.005791455507278442,
0.007944597862660885,
-0.0007982985116541386,
0.001830126391723752,
0.006030193064361811,
0.00411334028467536,
0.002216966822743416,
0.011982059106230736,
-0.0009656965848989785,
-0.006804216653108597,
0.008963994681835175,
0.009100176393985748,
-0.0007157636573538184,
0.007237789686769247,
0.0009542196057736874,
0.006314696744084358,
0.002762111835181713,
-0.006665633991360664,
-0.011779551394283772,
-0.0025872986298054457,
0.00930720567703247,
0.007404394447803497,
-0.0009497774299234152,
-0.0006213428569026291,
-0.002363727893680334,
-0.002168836770579219,
-0.007982407696545124,
-0.00581421609967947,
-0.0019322980660945177,
0.0010894837323576212,
0.004113045986741781,
0.06974893063306808,
-0.006527405232191086,
-0.0021181306801736355,
-0.008212785236537457,
-0.0010649199830368161,
-0.002913820557296276,
-0.0021649631671607494,
-0.00015410558262374252,
-0.0027073267847299576,
-0.00013750445214100182,
0.0025950553826987743,
-0.006475716829299927,
-0.01111542247235775,
-0.0012027010088786483,
0.004307262599468231,
-0.0018525636987760663,
0.0060822912491858006,
0.0041283066384494305,
-0.008924378082156181,
0.0021239372435957193,
-0.011823874898254871,
-0.004149403888732195,
-0.00230511836707592,
-0.006590528879314661,
-0.0038439047057181597,
-0.0020133922807872295,
0.0048887659795582294,
0.0029188941698521376,
0.006544977426528931,
-0.005833647213876247,
0.0061165811493992805,
-0.0032122426200658083,
-0.0007303401944227517,
-0.004841634538024664,
-0.0012105655623599887,
-0.005180159118026495,
0.008939826861023903,
-0.0004968312568962574,
-0.010726569220423698,
-0.0056370156817138195,
-0.000463909498648718,
-0.0021601268090307713,
-0.0053638676181435585,
0.00418476527556777,
0.0008218831499107182,
0.006506309844553471,
-0.004115196876227856,
0.0018298678332939744,
-0.005710169207304716,
0.0017012085299938917,
-0.012008675374090672,
0.0033639944158494473,
-0.1753658950328827,
0.011485427618026733,
0.0034186344128102064,
-0.0036827893927693367,
-0.0033669224940240383,
-0.013016512617468834,
-0.005609383340924978,
0.0020800644997507334,
0.009282033890485764,
0.0017853042809292674,
-0.0015707069542258978,
0.001965563278645277,
0.004018954001367092,
0.0030722199007868767,
-0.003811726812273264,
-0.0002881420368794352,
0.0048118713311851025,
-0.003929386381059885,
0.0017567456234246492,
0.0022371411323547363,
0.004975195974111557,
0.007056124974042177,
0.002717624418437481,
0.003943619318306446,
-0.002132511930540204,
-0.005804410669952631,
0.0048683397471904755,
-0.001495657954365015,
0.006192067172378302,
-0.011170431040227413,
-0.0041881464421749115,
-0.003302388358861208,
-0.002714622300118208,
-0.0017885222332552075,
0.003467055270448327,
-0.0008379710488952696,
0.010364629328250885,
0.0025988423731178045,
-0.008813154883682728,
0.00884147360920906,
-0.007922220975160599,
0.028836015611886978,
0.004285513423383236,
0.008159841410815716,
-0.001365257310681045,
-0.0061711398884654045,
-0.00482183089479804,
0.009891549125313759,
0.0022031404078006744,
0.011427267454564571,
-0.01080306340008974,
0.0006528088706545532,
0.0029395988676697016,
0.018819626420736313,
-0.00436816830188036,
-0.010813766159117222,
-0.006481281016021967,
-0.0010533666936680675,
0.0023743349593132734,
0.010237776674330235,
0.010419019497931004,
-0.006442059297114611,
0.010662835091352463,
-0.003309250343590975,
-0.020122621208429337,
0.005154370330274105,
-0.003953148610889912,
-0.007740616798400879,
0.0020857418421655893,
0.006649286951869726,
0.01181717962026596,
-0.0038278813008219004,
0.0021258308552205563,
-0.0031008992809802294,
0.0039829774759709835,
-0.001038517919369042,
0.0052102492190897465,
-0.003304247511550784,
0.006240432150661945,
-0.009747968055307865,
0.006988114677369595,
-0.007478439714759588,
-0.0028122649528086185,
0.0033744836691766977,
-0.0025324197486042976,
0.011804959736764431,
0.005545520223677158,
-0.0007050695130601525,
-0.0003950085665564984,
-0.011149146594107151,
-0.0018929572543129325,
0.0007901947246864438,
0.003163887420669198,
-0.008542196825146675,
0.0035048951394855976,
-0.00041680809226818383,
0.004369948524981737,
0.006633972283452749,
-0.011466658674180508,
0.006190933752804995,
0.005963670089840889,
-0.004070522729307413,
-0.0027365193236619234,
-0.003738566767424345,
0.0008505298756062984,
0.003506491892039776,
-0.005181629676371813,
-0.006977969314903021,
0.005411675665527582,
-0.007192926947027445,
-0.004836253821849823,
0.00967184454202652,
-0.00966719351708889,
-0.0075264908373355865,
0.0005383239476941526,
-0.011660042218863964,
0.00073002849239856
] |
8a45566aab7d64963906b912efac019f5bac9c8e | 2,079 | py | Python | ironic/tests/api/utils.py | citrix-openstack-build/ironic | 4b9eed0aeba44739caa742a48b55d824eae8ec55 | [
"Apache-2.0"
] | null | null | null | ironic/tests/api/utils.py | citrix-openstack-build/ironic | 4b9eed0aeba44739caa742a48b55d824eae8ec55 | [
"Apache-2.0"
] | null | null | null | ironic/tests/api/utils.py | citrix-openstack-build/ironic | 4b9eed0aeba44739caa742a48b55d824eae8ec55 | [
"Apache-2.0"
] | null | null | null | # vim: tabstop=4 shiftwidth=4 softtabstop=4
# -*- encoding: utf-8 -*-
#
# 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.
"""
Utils for testing the API service.
"""
import datetime
import json
ADMIN_TOKEN = '4562138218392831'
MEMBER_TOKEN = '4562138218392832'
class FakeMemcache(object):
"""Fake cache that is used for keystone tokens lookup."""
_cache = {
'tokens/%s' % ADMIN_TOKEN: {
'access': {
'token': {'id': ADMIN_TOKEN},
'user': {'id': 'user_id1',
'name': 'user_name1',
'tenantId': '123i2910',
'tenantName': 'mytenant',
'roles': [{'name': 'admin'}]
},
}
},
'tokens/%s' % MEMBER_TOKEN: {
'access': {
'token': {'id': MEMBER_TOKEN},
'user': {'id': 'user_id2',
'name': 'user-good',
'tenantId': 'project-good',
'tenantName': 'goodies',
'roles': [{'name': 'Member'}]
}
}
}
}
def __init__(self):
self.set_key = None
self.set_value = None
self.token_expiration = None
def get(self, key):
dt = datetime.datetime.now() + datetime.timedelta(minutes=5)
return json.dumps((self._cache.get(key), dt.strftime('%s')))
def set(self, key, value, timeout=None):
self.set_value = value
self.set_key = key
| 31.5 | 78 | 0.534873 | 1 | 1.3386 | [
0.001208532485179603,
0.023185111582279205,
0.009556686505675316,
0.0026351474225521088,
0.004667606204748154,
-0.0026618698611855507,
-0.008220366202294827,
0.0011317713651806116,
-0.005913989152759314,
0.004209920298308134,
0.002252809936180711,
0.005016854964196682,
0.005592263303697109,
-0.014306829310953617,
0.0009482481400482357,
0.014786663465201855,
-0.04993506893515587,
0.001800875528715551,
-0.003892881330102682,
0.0020073186606168747,
-0.007195232901722193,
0.00860538985580206,
0.010531778447329998,
0.005251633003354073,
0.005583724472671747,
-0.00035304742050357163,
0.00883954856544733,
0.0019630431197583675,
-0.006680104415863752,
-0.006469037849456072,
-0.00024695153115317225,
-0.002858429914340377,
-0.005953882820904255,
-0.005187484435737133,
0.006529269274324179,
-0.0037945820949971676,
-0.0001434224541299045,
-0.020120643079280853,
0.011857988312840462,
-0.003048069542273879,
-0.006745032966136932,
-0.015093646012246609,
-0.0017457182984799147,
0.004231776110827923,
-0.008215369656682014,
0.0004996882053092122,
-0.004496465437114239,
0.003918080125004053,
-0.01319701224565506,
0.007314578630030155,
-0.008489360101521015,
0.007377779111266136,
0.014201067388057709,
0.0033483037259429693,
-0.005562224425375462,
-0.008132757619023323,
0.013542652130126953,
0.0006444017053581774,
-0.00965227372944355,
-0.0017772156279534101,
-0.005181183107197285,
-0.004202435724437237,
0.004010199569165707,
0.0016559479990974069,
-0.01773272268474102,
-0.005830308422446251,
-0.003547102212905884,
0.002041628584265709,
-0.0016166312852874398,
0.006674084346741438,
0.0008618894498795271,
-0.0002861797693185508,
0.007715937681496143,
0.004738061688840389,
0.0031133617740124464,
-0.005176810082048178,
-0.00005881559263798408,
-0.001347712823189795,
0.009968764148652554,
0.003284887643530965,
0.005313991568982601,
-0.006324094254523516,
0.004186251200735569,
0.007600612938404083,
0.013084858655929565,
0.00975885707885027,
0.021359378471970558,
-0.010727247223258018,
0.04778874292969704,
0.007588979788124561,
-0.008237510919570923,
0.002386904787272215,
-0.007642244454473257,
-0.0015559695893898606,
-0.004678653087466955,
-0.025836344808340073,
-0.002043703803792596,
-0.0046540070325136185,
0.0011650924570858479,
0.0037642684765160084,
-0.0015523864421993494,
0.007379257585853338,
-0.0030346426647156477,
-0.0016356713604182005,
-0.007476305589079857,
0.009790857322514057,
-0.00782337412238121,
-0.0037670452147722244,
0.006269250065088272,
0.00014462937542703003,
-0.013480826281011105,
-0.002686744090169668,
0.0036414561327546835,
-0.01198670919984579,
0.0037008661311119795,
0.0023375889286398888,
-0.005885270424187183,
0.0514342226088047,
-0.0026888540014624596,
0.0026441412046551704,
-0.0037791847717016935,
0.002451869659125805,
0.0023982971906661987,
0.004667331930249929,
0.008516881614923477,
-0.0014178036944940686,
0.012760818935930729,
0.009175931103527546,
0.0028872631955891848,
0.008829333819448948,
-0.0009532369440421462,
0.009131145663559437,
-0.003844577120617032,
-0.003005607519298792,
0.001922857016324997,
-0.007324904203414917,
0.006931203417479992,
-0.002734649693593383,
-0.009462079964578152,
0.00257681286893785,
-0.0008370942086912692,
-0.010153252631425858,
0.002563809510320425,
-0.004810652229934931,
0.0053834468126297,
-0.010286149568855762,
-0.002307784976437688,
-0.0038156926166266203,
-0.0056494758464396,
0.0030877518001943827,
0.009554151445627213,
0.0037818863056600094,
0.0014777308097109199,
-0.004978731274604797,
-0.00932009331882,
0.0008679465972818434,
-0.003357396461069584,
0.0016093348385766149,
0.00833817571401596,
0.0032669776119291782,
-0.010103571228682995,
-0.00017866560665424913,
0.0038472842425107956,
0.002381897997111082,
-0.002750507788732648,
0.0023545159492641687,
-0.008987769484519958,
0.0057449075393378735,
0.00022855699353385717,
0.004907301161438227,
0.008467412553727627,
-0.004425333812832832,
-0.00010435834701638669,
-0.0004982406389899552,
0.0017977820243686438,
-0.001244387123733759,
0.005181366577744484,
0.011736162938177586,
-0.003724864451214671,
-0.003486131550744176,
0.0027033663354814053,
0.004950257483869791,
0.0095438864082098,
0.007573725655674934,
-0.002356291515752673,
0.0022688787430524826,
-0.0031163711100816727,
-0.001996185863390565,
0.005394428502768278,
-0.0037482038605958223,
0.004558766260743141,
0.004709562752395868,
-0.011951527558267117,
-0.00897350162267685,
0.0025112887378782034,
-0.009182280860841274,
0.0011123636504635215,
0.013990284875035286,
0.010659554973244667,
-0.002522365190088749,
0.003210353432223201,
-0.00872698426246643,
0.0010891602141782641,
0.006941764149814844,
0.0010747205233201385,
-0.013471752405166626,
-0.9606233239173889,
0.007548173423856497,
0.002779164118692279,
-0.0013933806912973523,
0.005282750353217125,
0.002486015670001507,
0.002656087279319763,
0.00416191853582859,
0.015383323654532433,
-0.009260415099561214,
-0.006329791154712439,
-0.009282710961997509,
-0.010076642967760563,
-0.0016916104359552264,
-0.007782117463648319,
-0.003745527472347021,
-0.007068199571222067,
-0.006447345018386841,
-0.0034700511023402214,
-0.0023100003600120544,
-0.0010906850220635533,
0.0073339007794857025,
-0.0006897497223690152,
0.0056634158827364445,
0.002600977197289467,
0.004461953416466713,
-0.005002831574529409,
-0.001778023666702211,
-0.001576066599227488,
-0.001929907943122089,
-0.007856462150812149,
-0.012924306094646454,
-0.005029056221246719,
-0.0017908334266394377,
0.009812571108341217,
-0.00004245851596351713,
0.00824877992272377,
-0.002844335976988077,
0.002758846152573824,
-0.008229811675846577,
0.004138297867029905,
-0.0021103301551193,
0.003679506480693817,
-0.029078267514705658,
0.00024234212469309568,
-0.0001921307557495311,
-0.00874357484281063,
0.009424155578017235,
-0.0012240185169503093,
0.0002608215145301074,
-0.003178253071382642,
-0.004422951955348253,
0.009255120530724525,
-0.007558157667517662,
0.002263822127133608,
-0.005573201924562454,
-0.006877215579152107,
-0.0013656308874487877,
-0.009236657060682774,
0.0004253055958542973,
0.003785202279686928,
-0.0007515304605476558,
-0.0043166386894881725,
-0.00434903334826231,
0.003331871470436454,
0.004370055161416531,
0.002118574222549796,
-0.016622256487607956,
-0.007454050704836845,
-0.00007209499744931236,
0.0001855984010035172,
-0.004567839205265045,
-0.0033703739754855633,
0.004676720127463341,
-0.008678358048200607,
0.006522176321595907,
0.002684188075363636,
-0.000535365252289921,
-0.011898386292159557,
0.00046906922943890095,
-0.00842258706688881,
-0.008587813936173916,
0.000985369668342173,
-0.006071669980883598,
-0.00443696416914463,
-0.0004573764163069427,
0.000857304607052356,
0.007062807213515043,
-0.00362416822463274,
0.006613528355956078,
0.012935297563672066,
-0.001681632362306118,
-0.008893556892871857,
0.00597238028421998,
0.00687211100012064,
-0.0009282208047807217,
-0.002599504776299,
0.0022128175478428602,
0.008115534670650959,
0.006733626127243042,
0.0029444287065416574,
0.00418294919654727,
-0.000562606321182102,
0.008499202318489552,
-0.0004959649522788823,
0.0008887143922038376,
-0.0034393579699099064,
-0.001270890119485557,
-0.0036003836430609226,
-0.0007408797391690314,
-0.0037711947225034237,
-0.00169984286185354,
-0.013739035464823246,
-0.009309091605246067,
-0.0019643402192741632,
-0.0016486968379467726,
0.004648445174098015,
-0.004294474143534899,
0.0010985652916133404,
0.0023067404981702566,
0.006962532177567482,
-0.000658579112496227,
-0.0012783781858161092,
-0.0001882423966890201,
0.0023153393995016813,
-0.005149995442479849,
0.013245956040918827,
-0.012152798473834991,
0.006765184458345175,
0.00034246931318193674,
-0.013916264288127422,
0.007350421976298094,
0.01102194469422102,
-0.008583223447203636,
0.0019965057726949453,
0.0039074900560081005,
0.00369040435180068,
-0.00032091440516524017,
-0.0041117193177342415,
-0.002880404470488429,
-0.017927711829543114,
0.0005727825337089598,
0.019902972504496574,
0.001982524059712887,
0.010624337941408157,
0.011061749421060085,
-0.0017833247547969222,
0.0024110800586640835,
0.0060424902476370335,
0.0027039197739213705,
0.011958417482674122,
-0.009104887023568153,
-0.0009343471028842032,
0.001798892510123551,
-0.005694757681339979,
0.00003010312866535969,
0.005188210401684046,
0.006173200439661741,
-0.0032271682284772396,
0.0027724981773644686,
-0.00667346827685833,
-0.004178618546575308,
-0.018272170796990395,
-0.0021887090988457203,
0.0072429366409778595,
-0.0033163779880851507,
0.006349652074277401,
-0.011585834436118603,
0.005197371821850538,
0.0064513967372477055,
0.003000677330419421,
0.0012164468644186854,
0.0000018039788756141206,
0.00509074330329895,
0.011995547451078892,
-0.006028505973517895,
0.0034286470618098974,
0.0029989953618496656,
-0.0001949122961377725,
0.0019638591911643744,
0.009118183515965939,
-0.007771104108542204,
-0.006813522428274155,
0.00508106267079711,
0.0033887657336890697,
0.0003519923484418541,
-0.004693797789514065,
-0.010201044380664825,
-0.0023145629093050957,
0.002445737598463893,
-0.004578958731144667,
0.004912422504276037,
0.002598386723548174,
0.003927316050976515,
-0.005861775018274784,
-0.001750131486915052,
-0.005637299735099077,
-0.012352969497442245,
0.010568389669060707,
-0.0029139535035938025,
0.003136215265840292,
0.013640280812978745,
0.003916389774531126,
-0.01221699919551611,
0.004492804873734713,
0.010433388873934746,
-0.0034223466645926237,
0.004801128525286913,
0.0061969999223947525,
-0.007883335463702679,
-0.022781720384955406,
-0.004043919034302235,
-0.01375802606344223,
0.005572682712227106,
-0.002509290585294366,
0.002735909540206194,
-0.007950317114591599,
0.00802304595708847,
0.004308965522795916,
-0.014206824824213982,
-0.004140479024499655,
-0.007086277939379215,
0.009732469916343689,
0.0018211296992376447,
-0.0005801303777843714,
-0.0028626793064177036,
0.00004602625995175913,
-0.0029272802639752626,
-0.004361539147794247,
-0.001698582200333476,
0.005381458438932896,
0.002566247945651412,
-0.0021818375680595636,
0.0018148194067180157,
-0.006071941461414099,
0.0014482146361842752,
0.0015184835065156221,
-0.011849767528474331,
0.0018520404119044542,
0.0029714431148022413,
-0.0027947891503572464,
-0.004502497147768736,
-0.0005080321570858359,
-0.002121689496561885,
-0.0058515421114861965,
-0.010783130303025246,
-0.004308621399104595,
-0.004362721461802721,
-0.0029495847411453724,
-0.01170793641358614,
-0.002213137224316597,
-0.00994044914841652,
0.006570401601493359,
-0.005232545081526041,
0.00688491016626358,
0.005116047337651253,
-0.005669429898262024,
0.007479660678654909,
-0.0005943022551946342,
0.0034603308886289597,
0.002411310328170657,
0.004840923007577658,
-0.0007822556071914732,
-0.005749622359871864,
-0.011635315604507923,
0.011299828067421913,
-0.008952160365879536,
0.00004938570418744348,
0.013080413453280926,
0.005914300214499235,
0.00818740576505661,
-0.00045560189755633473,
-0.0011367099359631538,
-0.0004202498239465058,
0.006421200931072235,
-0.014815771020948887,
0.0035510524176061153,
-0.003166679060086608,
-0.00027248726109974086,
0.0030229275580495596,
-0.0024048497434705496,
0.002727906685322523,
0.00820185150951147,
0.0009275184129364789,
-0.006537104491144419,
-0.0035516363568603992,
0.0005528045003302395,
0.003079148940742016,
-0.01145345252007246,
-0.0001376473082927987,
-0.003484222572296858,
-0.004850876983255148,
-0.002905649598687887,
-0.003186270361766219,
-0.0012826870661228895,
0.004616682883352041,
-0.0024978520814329386,
0.004926485009491444,
0.0021909100469201803,
-0.006513433530926704,
0.015245100483298302,
-0.004884508438408375,
-0.003848891006782651,
0.0015399486292153597,
0.0015731132589280605,
-0.0029588034376502037,
-0.007272262591868639,
-0.002912915777415037,
0.002405628329142928,
0.006602265872061253,
-0.0031534426379948854,
-0.004862304776906967,
-0.002313390141353011,
0.001318494905717671,
-0.008440499193966389,
0.001933230203576386,
0.011245322413742542,
-0.00178785459138453,
0.005930126179009676,
-0.00329542881809175,
-0.009340114891529083,
-0.012115592136979103,
0.0538027249276638,
-0.002187171019613743,
0.00481896847486496,
0.0036984900943934917,
-0.007543931249529123,
-0.0009874149691313505,
-0.0027763491962105036,
0.007427811156958342,
-0.004294731188565493,
-0.006778144743293524,
0.008681857958436012,
-0.0023696343414485455,
0.006344866007566452,
0.004582428839057684,
-0.002164610428735614,
0.014841982163488865,
-0.004048079252243042,
-0.015248749405145645,
-0.017158111557364464,
0.0077494350261986256,
-0.0058086044155061245,
-0.008827161975204945,
0.010433446615934372,
-0.004278156906366348,
-0.007114425301551819,
0.000661177618894726,
0.005000531207770109,
0.0013629226014018059,
-0.0005480805411934853,
-0.0030130473896861076,
-0.002717200666666031,
-0.0021040786523371935,
0.0020481594838202,
0.005811169743537903,
0.005785113200545311,
-0.004934891127049923,
0.0029209584463387728,
-0.00316790072247386,
-0.0019379750592634082,
-0.0000065035974330385216,
0.003600803902372718,
0.008254433050751686,
0.0003908496582880616,
-0.0011228419607505202,
0.005582258105278015,
0.004332637879997492,
0.0007422259077429771,
0.011604703962802887,
-0.00008260729373432696,
-0.005332743749022484,
0.007991364225745201,
0.009805743582546711,
0.00036125152837485075,
0.008711161091923714,
-0.0015090021770447493,
0.004565621260553598,
0.0025231146719306707,
-0.004829686600714922,
-0.017095942050218582,
-0.0020891940221190453,
0.006643437780439854,
0.007564019411802292,
-0.0017628829227760434,
0.003089151345193386,
-0.005266429390758276,
-0.0021657426841557026,
-0.004940306302160025,
-0.008149011060595512,
-0.0023696962743997574,
0.0020426746923476458,
0.005215827375650406,
0.06979957222938538,
-0.007721530273556709,
0.00004282047666492872,
-0.008328448981046677,
-0.0011607635533437133,
-0.0016416569706052542,
-0.000570169067941606,
0.0009397268877364695,
-0.0009245004621334374,
0.00120759557466954,
0.0008713770075701177,
-0.007677392102777958,
-0.010896628722548485,
-0.0005352183943614364,
0.0036882837302982807,
-0.002943542553111911,
0.004316641483455896,
0.004773637279868126,
-0.012002740986645222,
0.0012140909675508738,
-0.011849489063024521,
-0.002375661861151457,
-0.003471213625743985,
-0.009576652199029922,
-0.003227134933695197,
-0.0029516813810914755,
0.005209778901189566,
0.00436149537563324,
0.006442483980208635,
-0.002319261897355318,
0.006297429092228413,
-0.0033381409011781216,
-0.002119729295372963,
-0.00612874049693346,
-0.0005184912588447332,
-0.003492659656330943,
0.008134941570460796,
0.0005315321614034474,
-0.008711982518434525,
-0.0058504072949290276,
-0.00283245462924242,
0.0008266381919384003,
-0.004872758407145739,
0.0026446948759257793,
0.00010525780089665204,
0.005187433212995529,
-0.00417310232296586,
-0.0019252195488661528,
-0.006173469591885805,
0.001903267577290535,
-0.01164959091693163,
0.00677887350320816,
-0.16614536941051483,
0.009868888184428215,
0.002832455327734351,
-0.004251930397003889,
-0.0038041709922254086,
-0.01661589741706848,
-0.003292109351605177,
0.0038729989901185036,
0.007987113669514656,
0.0021824808791279793,
-0.0025373969692736864,
-0.002897283062338829,
0.004092840943485498,
0.002750669838860631,
-0.0024433075450360775,
-0.005987393204122782,
0.0016238860553130507,
-0.0032071631867438555,
-0.00013344611215870827,
0.005217542871832848,
0.005427195690572262,
0.009155824780464172,
0.0002546166069805622,
0.0019383035833016038,
-0.001721705193631351,
-0.005145043600350618,
0.005680898204445839,
-0.002959411358460784,
0.004235802683979273,
-0.011703386902809143,
-0.004026619251817465,
-0.0033129777293652296,
-0.004997059237211943,
0.0012166732922196388,
0.00589642534032464,
0.0011645110789686441,
0.0102696493268013,
0.0036562883760780096,
-0.0076151094399392605,
0.005323910620063543,
-0.006577329244464636,
0.02780788391828537,
0.004147526808083057,
0.006174058187752962,
0.00020309945102781057,
-0.006248454097658396,
-0.005854617804288864,
0.008990870788693428,
0.0016529454151168466,
0.011093048378825188,
-0.01211029663681984,
-0.0004410764668136835,
0.003948210272938013,
0.019076451659202576,
-0.005901840049773455,
-0.009779366664588451,
-0.005926633253693581,
-0.000693280715495348,
0.003433921141549945,
0.005711699370294809,
0.011051023378968239,
-0.0024499138817191124,
0.008796448819339275,
-0.003036754671484232,
-0.02046893909573555,
0.0027380785904824734,
-0.005069228820502758,
-0.007412772625684738,
0.002758616814389825,
0.00722478935495019,
0.011708459816873074,
-0.0005309212720021605,
-0.000012470070942072198,
-0.001220500678755343,
0.008271126076579094,
0.0009448167402297258,
0.0067238472402095795,
-0.0004924823297187686,
0.006011385470628738,
-0.007556567434221506,
0.007386747281998396,
-0.009536175057291985,
-0.0014038470108062029,
0.00205322727560997,
-0.0038692199159413576,
0.012659259140491486,
0.0030934985261410475,
-0.0017241198802366853,
-0.0008608949719928205,
-0.009283935651183128,
-0.0019057673634961247,
0.0010197438532486558,
0.001777889672666788,
-0.007299202494323254,
0.00319618359208107,
0.002524192212149501,
0.0048403688706457615,
0.007926360704004765,
-0.012126597575843334,
0.006498077418655157,
0.004077781457453966,
-0.005778237245976925,
-0.0006879484280943871,
-0.005489354487508535,
0.0008331338758580387,
0.00467802444472909,
-0.004760308191180229,
-0.006202255841344595,
0.0043228971771895885,
-0.005627714563161135,
-0.0051000225357711315,
0.006273319013416767,
-0.010666880756616592,
-0.00936760101467371,
-0.0002449049788992852,
-0.008463050238788128,
-0.0006117153097875416
] |
8a455ca53b609476797038c96b21d969bbdf51e3 | 2,234 | py | Python | bookshelf/main/forms.py | thewordisbird/bookshelf | 5166720bdc0dbffedc14b71b0f75ad78dc69b465 | [
"MIT"
] | null | null | null | bookshelf/main/forms.py | thewordisbird/bookshelf | 5166720bdc0dbffedc14b71b0f75ad78dc69b465 | [
"MIT"
] | null | null | null | bookshelf/main/forms.py | thewordisbird/bookshelf | 5166720bdc0dbffedc14b71b0f75ad78dc69b465 | [
"MIT"
] | null | null | null | import datetime
from flask_wtf import FlaskForm
from wtforms import (
StringField,
TextAreaField,
DateTimeField,
HiddenField,
PasswordField,
)
from wtforms.validators import DataRequired, ValidationError, Email, EqualTo
class NullableDateTimeField(DateTimeField):
"""Modify DateField to allow for Null values"""
def process_formdata(self, valuelist):
# Bypasses wtForms validation for blank datetime field.
if valuelist:
date_str = " ".join(valuelist).strip()
if date_str == "":
self.data = None
return
try:
self.data = datetime.datetime.strptime(date_str, self.format)
except ValueError:
self.data = None
raise ValueError(self.gettext("Not a valid date value"))
class SearchForm(FlaskForm):
search = StringField("Search", validators=[DataRequired()])
class ReviewForm(FlaskForm):
rating = HiddenField("Rating", validators=[DataRequired()])
review_title = StringField("Headline")
review_content = TextAreaField("Review")
date_started = NullableDateTimeField("Date Started", format="%m/%d/%Y")
date_finished = NullableDateTimeField("Date Finished", format="%m/%d/%Y")
def validate_date_finished(self, date_finished):
if self.date_started.data and date_finished.data:
if self.date_started.data > date_finished.data:
print("Date finished must be greater than or equal to date started")
raise ValidationError(
"Date finished must be greater than or equal to date started."
)
elif self.date_started.data or date_finished.data:
print("missing date")
raise ValidationError("If setting read dates, both dates are required.")
class EditProfileForm(FlaskForm):
display_name = StringField("Name", validators=[])
email = StringField("Email", validators=[Email(message="Invalid Email Address.")])
password = PasswordField(
"Password",
validators=[EqualTo("confirm_password", message="Passwords must match.")],
)
confirm_password = PasswordField("Confirm Password", validators=[])
| 36.032258 | 86 | 0.658013 | 1 | 1.2771 | [
0.0017877006903290749,
0.020831579342484474,
0.007349253632128239,
0.004266113508492708,
0.0033574430271983147,
-0.0030375588685274124,
-0.0074812257662415504,
0.0013178668450564146,
-0.007675122935324907,
0.004170234315097332,
0.003799309255555272,
0.004594818688929081,
0.006340588442981243,
-0.017521293833851814,
-0.0022517703473567963,
0.013879207894206047,
-0.04823219031095505,
0.0026814730372279882,
-0.004177207592874765,
0.003443086752668023,
-0.0058724782429635525,
0.0076223514042794704,
0.00866070855408907,
0.004739213269203901,
0.004022920969873667,
-0.004367823246866465,
0.010180177167057991,
0.0011296593584120274,
-0.005076932720839977,
-0.004940044600516558,
-0.0020135866943746805,
-0.0031488165259361267,
-0.004093754105269909,
-0.005642096512019634,
0.004553357604891062,
-0.0028171914163976908,
0.00038764983764849603,
-0.018845757469534874,
0.011646464467048645,
-0.002804687013849616,
-0.006981089245527983,
-0.012818006798624992,
-0.0021378695964813232,
0.0018939642468467355,
-0.008776579983532429,
0.0022973644081503153,
-0.006413368508219719,
0.004105236381292343,
-0.012059537693858147,
0.007107296958565712,
-0.006604370195418596,
0.004550683777779341,
0.01467401534318924,
0.005598871968686581,
-0.006521166767925024,
-0.007755752187222242,
0.014124786481261253,
0.0003939548332709819,
-0.01102742925286293,
-0.0004949801368638873,
-0.005334879271686077,
-0.0021157211158424616,
0.003615438239648938,
0.0012114137643948197,
-0.01588035374879837,
-0.005036583170294762,
-0.001378888264298439,
0.0038064431864768267,
0.00021770346211269498,
0.006973084062337875,
0.0007954522734507918,
-0.001470833201892674,
0.0068346173502504826,
0.002915656892582774,
0.0014877268113195896,
-0.005565654020756483,
-0.0005029165768064559,
-0.001789526198990643,
0.008028971962630749,
0.005458362866193056,
0.005477015394717455,
-0.005357768852263689,
0.006341621745377779,
0.006533753592520952,
0.010992076247930527,
0.010334285907447338,
0.022145071998238564,
-0.011360169388353825,
0.04754049703478813,
0.007731201127171516,
-0.008548600599169731,
0.0025138678029179573,
-0.008009131997823715,
-0.0022519065532833338,
-0.00859683845192194,
-0.026949577033519745,
-0.001824249280616641,
-0.00448128767311573,
-0.00025420874590054154,
0.0037177216727286577,
-0.000702366407494992,
0.00832000095397234,
-0.0007077719201333821,
-0.00290633924305439,
-0.007337165996432304,
0.010636821389198303,
-0.008497720584273338,
-0.0032996681984514,
0.005134524777531624,
0.0015632312279194593,
-0.014573580585420132,
-0.0002294825972057879,
0.00318503868766129,
-0.010919153690338135,
0.005557078868150711,
0.0036589880473911762,
-0.0036959429271519184,
0.04938199371099472,
-0.00019492559658829123,
0.002305476227775216,
-0.006784722674638033,
0.004210866056382656,
0.0023951877374202013,
0.006302274763584137,
0.004318234045058489,
-0.00017219060100615025,
0.014157542958855629,
0.010485850274562836,
0.005317824427038431,
0.008544621989130974,
-0.0020833408925682306,
0.005793805234134197,
-0.0030463445000350475,
-0.0034974103327840567,
0.001480925246141851,
-0.008066540583968163,
0.005534579511731863,
-0.003478298895061016,
-0.010645079426467419,
0.005162982270121574,
-0.0003585706581361592,
-0.009602195583283901,
0.00019195200002286583,
-0.0012505409540608525,
0.004882719833403826,
-0.008599977008998394,
-0.0028211295139044523,
-0.007286470849066973,
-0.005997159983962774,
0.004768249578773975,
0.009971882216632366,
0.0034339777193963528,
0.003645482240244746,
-0.007562295068055391,
-0.009674405679106712,
0.0016023671487346292,
-0.0020293272100389004,
0.0018711700104176998,
0.006844706833362579,
0.004342461936175823,
-0.01084041316062212,
-0.00007208761235233396,
0.002411319175735116,
0.0060433982871472836,
-0.004235964268445969,
0.0026070615276694298,
-0.007816632278263569,
0.007689227350056171,
0.00013743805175181478,
0.0031614326871931553,
0.009263293817639351,
-0.005210909992456436,
-0.0029751372057944536,
-0.0019469785038381815,
0.003655142616480589,
-0.0018057201523333788,
0.008063974790275097,
0.012327597476541996,
-0.003162690671160817,
-0.006882428657263517,
0.002049485221505165,
0.00729789212346077,
0.009702036157250404,
0.004638473503291607,
-0.002300513442605734,
0.0010896355379372835,
-0.0034675118513405323,
-0.003470884170383215,
0.00732213631272316,
-0.005454802419990301,
0.005074899177998304,
0.004524161107838154,
-0.009527843445539474,
-0.00737503869459033,
0.0022846516221761703,
-0.006809339392930269,
0.0024755827616900206,
0.012745173647999763,
0.009805170819163322,
-0.0034499892499297857,
0.0040408167988061905,
-0.009096954949200153,
0.0014091263292357326,
0.005439298693090677,
0.002743692370131612,
-0.01245826855301857,
-0.9618839621543884,
0.009296400472521782,
0.005523336585611105,
-0.0003603219520300627,
0.0056867534294724464,
0.004568873904645443,
0.002032162854447961,
0.004418640397489071,
0.013283682987093925,
-0.006674259435385466,
-0.004142384044826031,
-0.01080126129090786,
-0.011723578907549381,
-0.0037674661725759506,
-0.006947587709873915,
-0.0019382290774956346,
-0.0066631995141506195,
-0.006458307150751352,
-0.002991856075823307,
-0.0022846772335469723,
-0.0038029770366847515,
0.010137551464140415,
-0.0027421710547059774,
0.005810367409139872,
0.0010437030578032136,
0.004599676933139563,
-0.0031711459159851074,
-0.0028510242700576782,
-0.003867134917527437,
-0.002817865926772356,
-0.007434115279465914,
-0.012181252241134644,
-0.004635217599570751,
-0.0005760283675044775,
0.009398574940860271,
0.0012664643581956625,
0.0072471583262085915,
-0.0019394404953345656,
0.0005585170001722872,
-0.007745866198092699,
0.0044870213605463505,
-0.003258361713960767,
0.0014940378023311496,
-0.028777314350008965,
0.0006006325711496174,
-0.0013120339717715979,
-0.006862974725663662,
0.008323892951011658,
-0.0008215109119191766,
-0.00046347154420800507,
-0.004964487627148628,
-0.00352384801954031,
0.010549861006438732,
-0.009574084542691708,
0.0035804049111902714,
-0.004360065329819918,
-0.010682969354093075,
-0.0014737469609826803,
-0.008733903989195824,
0.00014509953325614333,
0.00420695636421442,
-0.005111856386065483,
-0.0021568858064711094,
-0.0028646988794207573,
0.0005119684501551092,
0.0027864151634275913,
0.002736584283411503,
-0.018363123759627342,
-0.008944716304540634,
0.002115460578352213,
-0.0033719376660883427,
-0.008825602009892464,
-0.004720678552985191,
0.004366026725620031,
-0.011270342394709587,
0.007550055161118507,
0.003169078379869461,
-0.002339074620977044,
-0.0109377671033144,
-0.0028194033075124025,
-0.009701704606413841,
-0.008443109691143036,
0.0007232873467728496,
-0.009540983475744724,
-0.003980288282036781,
-0.0004627112066373229,
0.0013607648434117436,
0.007791614625602961,
-0.002708003856241703,
0.0051932428032159805,
0.014938435517251492,
-0.000905353925190866,
-0.005955407861620188,
0.007430121302604675,
0.007160182576626539,
-0.00029150405316613615,
-0.002732647815719247,
0.0034456250723451376,
0.007428427692502737,
0.006709672510623932,
0.00021171984553802758,
0.003752135904505849,
0.0012015559477731586,
0.011580795980989933,
-0.0025388887152075768,
-0.00042162087629549205,
-0.005907984916120768,
-0.00007994521729415283,
-0.0018488813657313585,
-0.0013442717026919127,
-0.002428250154480338,
-0.003935869317501783,
-0.013057027012109756,
-0.007821091450750828,
-0.0012479922734200954,
-0.0014610964572057128,
0.0038893341552466154,
-0.0015522692119702697,
0.0025181265082210302,
0.003975709900259972,
0.0072939395904541016,
0.0022947799880057573,
0.0019774052780121565,
-0.001261416357010603,
0.0012943785404786468,
-0.0032272625248879194,
0.013320710510015488,
-0.013374103233218193,
0.005210217088460922,
0.0016401172615587711,
-0.010773470625281334,
0.006826236378401518,
0.010370125994086266,
-0.008114384487271309,
0.00031977699836716056,
0.004633850418031216,
0.0016703559085726738,
-0.003835896262899041,
-0.005003210622817278,
-0.003864405443891883,
-0.01407619472593069,
0.0007209355826489627,
0.0178518146276474,
0.00011049666500184685,
0.009959323331713676,
0.009926937520503998,
-0.005228438414633274,
0.0008848238503560424,
0.007989136502146721,
0.00038846925599500537,
0.01193482056260109,
-0.007449937518686056,
-0.0018257712945342064,
0.0009077166323550045,
-0.0061214701272547245,
-0.000664334453176707,
0.006482526659965515,
0.004537569358944893,
-0.0022120317444205284,
0.002795112319290638,
-0.007894433103501797,
-0.0057875122874975204,
-0.01751084066927433,
-0.0036826138384640217,
0.009498655796051025,
-0.004401755053550005,
0.00601043738424778,
-0.011770063079893589,
0.005498031619936228,
0.006441603414714336,
0.003960850182920694,
0.000740808725822717,
-0.00037795028765685856,
0.005647542420774698,
0.011958585120737553,
-0.003959961701184511,
0.003127522999420762,
0.00463473005220294,
-0.0009115822031162679,
0.00326466909609735,
0.010151444934308529,
-0.0074791619554162025,
-0.005630889441817999,
0.003970417194068432,
0.0036303556989878416,
-0.00007496984471799806,
-0.0035223886370658875,
-0.008581363596022129,
-0.002112459624186158,
0.00213644583709538,
-0.0033507319167256355,
0.004928335081785917,
0.004560956731438637,
0.0023697626311331987,
-0.004886673763394356,
-0.001517400611191988,
-0.0007638564566150308,
-0.015033895149827003,
0.01041927095502615,
-0.002787558827549219,
0.003235482145100832,
0.012543665245175362,
0.002750139683485031,
-0.012393143028020859,
0.00633500749245286,
0.009542024694383144,
-0.0036434191279113293,
0.003354590153321624,
0.005991515703499317,
-0.00656922860071063,
-0.0217373538762331,
-0.004116273485124111,
-0.01413652766495943,
0.005894624162465334,
-0.0027085274923592806,
0.0047124046832323074,
-0.0069952127523720264,
0.005470738746225834,
0.0045397160574793816,
-0.015510698780417442,
-0.005246748216450214,
-0.009228034876286983,
0.009751375764608383,
0.0005519866244867444,
-0.0016223689308390021,
-0.00522619066759944,
0.0014597621047869325,
-0.0013589017326012254,
-0.0033064649906009436,
-0.004411554429680109,
0.005083545111119747,
0.002399606164544821,
-0.0015843880828469992,
0.0032243309542536736,
-0.0063868360593914986,
0.0009687601123005152,
0.0020299917086958885,
-0.012075723148882389,
0.002931148512288928,
0.0029095825739204884,
-0.0016214664792641997,
-0.0024149734526872635,
0.0024944383185356855,
-0.0012756980722770095,
-0.009333977475762367,
-0.010150310583412647,
-0.003854637034237385,
-0.00270086620002985,
-0.002260646317154169,
-0.012935250997543335,
-0.0034267122391611338,
-0.008725456893444061,
0.003807147964835167,
-0.007115422282367945,
0.008387497626245022,
0.004695585463196039,
-0.006847095210105181,
0.00675163185223937,
-0.0012425370514392853,
0.0017541268607601523,
0.0027220684569329023,
0.006255425047129393,
-0.00043776282109320164,
-0.002794913249090314,
-0.013180650770664215,
0.011946816928684711,
-0.007122292649000883,
0.0004978678771294653,
0.01284610852599144,
0.004303399473428726,
0.009503168053925037,
-0.0014422275125980377,
-0.0016396610299125314,
-0.00037120759952813387,
0.0039034842047840357,
-0.01520621869713068,
0.003949617501348257,
-0.004988112952560186,
0.0018797673983499408,
0.0038763009943068027,
-0.002600987209007144,
-0.00013554359611589462,
0.010571182705461979,
0.0013916202588006854,
-0.007467296905815601,
-0.004343797452747822,
-0.000020087220036657527,
0.0005196050042286515,
-0.012976820580661297,
-0.001591658336110413,
-0.004752962850034237,
-0.0031500740442425013,
-0.001921151066198945,
-0.005938956048339605,
-0.0009042431483976543,
0.0073594748973846436,
-0.002597824204713106,
0.003493524855002761,
-0.0008480940596200526,
-0.006169555708765984,
0.012559951283037663,
-0.0043817684054374695,
-0.003564772428944707,
0.002419579541310668,
0.004622968379408121,
-0.003988117910921574,
-0.0074840267188847065,
-0.005027549806982279,
0.002664396073669195,
0.006390050984919071,
-0.0011712954146787524,
-0.004091058857738972,
-0.00016068019613157958,
0.000037860936572542414,
-0.01101615559309721,
-0.0008748055552132428,
0.011580286547541618,
-0.002641957486048341,
0.004705885425209999,
-0.001162962755188346,
-0.01043007057160139,
-0.01133349072188139,
0.05173803120851517,
-0.00002252736703667324,
0.004616871476173401,
0.0051688202656805515,
-0.006545563228428364,
-0.00489514647051692,
-0.0042531173676252365,
0.007126044016331434,
-0.0037187053821980953,
-0.0050468142144382,
0.006453554145991802,
-0.0013786825584247708,
0.005087828263640404,
0.005773719400167465,
-0.0023264121264219284,
0.018193461000919342,
-0.004208294674754143,
-0.014921655878424644,
-0.016612915322184563,
0.007763455621898174,
-0.005492091178894043,
-0.00861208327114582,
0.012102552689611912,
-0.002004830399528146,
-0.009205425158143044,
0.002015636069700122,
0.0059731872752308846,
0.0028324320446699858,
-0.0033860746771097183,
-0.0026944982819259167,
-0.0012018067063763738,
-0.0026949471794068813,
-0.000392474583350122,
0.002761802403256297,
0.006653498858213425,
-0.005189618561416864,
0.002446860773488879,
-0.004933457355946302,
-0.0033028835896402597,
-0.0005689044483006,
0.004684915766119957,
0.006724650505930185,
0.0015018630074337125,
-0.0013149594888091087,
0.0043912362307310104,
0.0021069874055683613,
0.003213883377611637,
0.010847913101315498,
-0.0005782332154922187,
-0.007092378567904234,
0.008800562471151352,
0.007502456661313772,
-0.00006749763269908726,
0.007678100373595953,
-0.001685851952061057,
0.005934601649641991,
0.00359148345887661,
-0.007794673554599285,
-0.01541818305850029,
-0.005216183606535196,
0.007708562072366476,
0.008977466262876987,
-0.0028564275708049536,
0.00015067147614900023,
-0.0026563110295683146,
-0.0015480347210541368,
-0.006090459879487753,
-0.006963816471397877,
-0.003654708620160818,
0.0013369823573157191,
0.006921141408383846,
0.0685872957110405,
-0.009551837109029293,
-0.001568276435136795,
-0.010518457740545273,
-0.000792533450294286,
0.0008284751093015075,
-0.0005298113101162016,
0.004888692870736122,
-0.0038999731186777353,
0.0007054040906950831,
-0.0007795541314408183,
-0.005256241653114557,
-0.012302899733185768,
-0.0029923354741185904,
0.003169200848788023,
-0.0027154863346368074,
0.0030008561443537474,
0.006338413339108229,
-0.012997660785913467,
0.0020676504354923964,
-0.012443523854017258,
-0.0027522926684468985,
-0.0015061527956277132,
-0.008875289000570774,
-0.002501165261492133,
-0.0018725801492109895,
0.0056531475856900215,
0.00820448249578476,
0.003999208100140095,
-0.004558489192277193,
0.006509874016046524,
-0.003838795470073819,
-0.00278049660846591,
-0.006351383402943611,
-0.002952381270006299,
-0.0025314479134976864,
0.006934525445103645,
0.00031458906596526504,
-0.009194622747600079,
-0.002886334201321006,
-0.0016165570123121142,
0.0016740571008995175,
-0.005752024240791798,
0.00231010839343071,
-0.0005331558641046286,
0.0017460689414292574,
-0.003270489163696766,
0.0005598887801170349,
-0.00548686645925045,
0.0032120239920914173,
-0.01165709551423788,
0.01002025231719017,
-0.1599901169538498,
0.010507483966648579,
0.0045784548856318,
-0.0044974638149142265,
-0.0026769237592816353,
-0.0168674997985363,
-0.0035229302011430264,
0.004499352071434259,
0.010401910170912743,
0.003210601396858692,
-0.00354274595156312,
0.00021879411360714585,
0.0025404621846973896,
0.0037603278178721666,
-0.004852205514907837,
-0.003730054944753647,
0.001009216415695846,
-0.0047502098605036736,
-0.001060714479535818,
0.00597840640693903,
0.004418515134602785,
0.007126262877136469,
0.0008019177475944161,
-0.00015086970233824104,
-0.002256670966744423,
-0.005173715762794018,
0.007570846006274223,
-0.001970991725102067,
0.00512212049216032,
-0.008177393116056919,
-0.0033404540736228228,
-0.0020977461244910955,
-0.004731693305075169,
0.0015954439295455813,
0.0031679952517151833,
0.0009098390582948923,
0.010070386342704296,
0.001862497185356915,
-0.007580004632472992,
0.008125602267682552,
-0.00839686207473278,
0.027213789522647858,
0.009464116767048836,
0.003690496552735567,
-0.00044986692955717444,
-0.007845230400562286,
-0.006449232809245586,
0.009528071619570255,
0.0014572776854038239,
0.013270009309053421,
-0.010138723067939281,
0.0023949015885591507,
0.004720461554825306,
0.017886389046907425,
-0.005918561480939388,
-0.010443177074193954,
-0.0060984352603554726,
-0.0018586559453979135,
0.0027156686410307884,
0.0068280259147286415,
0.010475319810211658,
-0.00004792813342646696,
0.012991739436984062,
-0.004294601734727621,
-0.01723947562277317,
0.004153809975832701,
-0.0022705039009451866,
-0.007114975247532129,
0.004455737769603729,
0.006191662512719631,
0.008965753018856049,
0.0006464577745646238,
0.0006526883807964623,
-0.0016005211509764194,
0.008629457093775272,
0.0018029840430244803,
0.009337524883449078,
-0.002098222728818655,
0.005334425717592239,
-0.007937743328511715,
0.0048202392645180225,
-0.008455202914774418,
-0.001013119355775416,
0.0036583023611456156,
-0.001427812036126852,
0.010634087026119232,
0.0042558698914945126,
0.000016518819393240847,
-0.0006936013232916594,
-0.009120140224695206,
-0.0015181603375822306,
0.0009860433638095856,
0.0017592093208804727,
-0.006875122431665659,
0.004234854131937027,
0.00150619400665164,
0.003964946139603853,
0.01073174923658371,
-0.010134512558579445,
0.009048005566000938,
0.002561523811891675,
-0.00452469103038311,
0.0002367746055824682,
-0.004313793033361435,
0.0009875170653685927,
0.0026695975102484226,
-0.005379788111895323,
-0.004217260051518679,
0.004728385712951422,
-0.006240007467567921,
-0.005778786726295948,
0.00857699103653431,
-0.008708079345524311,
-0.009794780053198338,
0.001636641682125628,
-0.00752397021278739,
-0.0009538919548504055
] |
8a458f7c27c0535d07e4b642f5a00528aee12141 | 3,387 | py | Python | main.py | DanielM24/Romanian-sub-dialect-identificator | 78b3e00f8ee768eb0b1e8cf832a2dc0b8504b04d | [
"MIT"
] | null | null | null | main.py | DanielM24/Romanian-sub-dialect-identificator | 78b3e00f8ee768eb0b1e8cf832a2dc0b8504b04d | [
"MIT"
] | null | null | null | main.py | DanielM24/Romanian-sub-dialect-identificator | 78b3e00f8ee768eb0b1e8cf832a2dc0b8504b04d | [
"MIT"
] | null | null | null | # -*- coding: utf-8 -*-
"""Proiect.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1TR1Frf0EX4PtFZkLlVdGtMTINqhoQwRw
"""
# Importarea librariilor
import numpy as np
import pandas as pd # pandas pentru citirea fisierelor
from sklearn import preprocessing
from sklearn import svm # importarea modelului
from sklearn.feature_extraction.text import TfidfVectorizer # modelarea datelor pentru a obtine valori numerice din text
from sklearn.metrics import classification_report, confusion_matrix
# Incarcarea datelor
train_labels = pd.read_csv('train_labels.txt', sep='\t', header=None, engine='python')
train_labels = train_labels.to_numpy() # convertim data frame-ul intr-un vector
train_labels = train_labels[:,1] # pastram doar etichetele
train_samples = pd.read_csv('train_samples.txt', sep='\t', header=None, engine='python')
train_samples = train_samples.to_numpy()
train_samples = train_samples[:,1] # pastram doar cuvintele
validation_samples = pd.read_csv('validation_samples.txt', sep='\t', header=None, engine='python')
validation_samples = validation_samples.to_numpy()
validation_samples = validation_samples[:,1] # salvam cuvintele
validation_labels = pd.read_csv('validation_labels.txt', sep='\t', header=None, engine='python')
validation_labels = validation_labels.to_numpy()
validation_labels = validation_labels[:,1] # pastram doar etichetele
test_samples = pd.read_csv('test_samples.txt', sep='\t', header=None, engine='python')
test_samples = test_samples.to_numpy()
label = test_samples[:,0] # salvam etichetele
test_samples = test_samples[:,1] # salvam cuvintele
def normalize_data(train_data, test_data, type='l2'): # functia care intoarce datele normalizate
#tipul de normalizare este setat implicit la l2
scaler = None
if type == 'standard':
scaler = preprocessing.StandardScaler()
elif type == 'min_max':
scaler = preprocessing.MinMaxScaler()
elif type == 'l1' or type == 'l2':
scaler = preprocessing.Normalizer(norm = type)
if scaler is not None:
scaler.fit(train_data)
scaled_train_data = scaler.transform(train_data)
scaled_test_data = scaler.transform(test_data)
return scaled_train_data, scaled_test_data
else:
return train_data, test_data
# Modelarea datelor
vectorizer = TfidfVectorizer()
training_features = vectorizer.fit_transform(train_samples)
validation_features = vectorizer.transform(validation_samples)
testing_features = vectorizer.transform(test_samples)
# Normalizarea datelor
norm_train, norm_test = normalize_data(training_features, testing_features)
norm_validation, _ = normalize_data(validation_features, validation_features)
# Aplicam modelul SVM
model_svm = svm.SVC(kernel='linear', C=23, gamma=110) # definim modelul
model_svm.fit(norm_train, train_labels) # procesul de invatare
test_predictions = model_svm.predict(norm_test) # predictie pe datele de test
print("Classification report: ")
print(classification_report(validation_labels, model_svm.predict(norm_validation)))
print("Confusion matrix: ")
print(confusion_matrix(validation_labels, model_svm.predict(norm_validation)))
# Exportarea datelor in format CSV
test_export = {'id':label,'label':test_predictions}
data_f = pd.DataFrame(test_export)
data_f.to_csv('test_submission.csv',index=False) | 38.05618 | 120 | 0.775613 | 1 | 1.8231 | [
-0.0008294775034300983,
0.021812057122588158,
0.008749746717512608,
0.003373736049979925,
0.003947226796299219,
-0.0032572492491453886,
-0.00962436106055975,
-0.0005257404409348965,
-0.006748076528310776,
0.0035816251765936613,
0.0025517966132611036,
0.0060999421402812,
0.007582329213619232,
-0.013867385685443878,
-0.0009346685837954283,
0.015321429818868637,
-0.04927651584148407,
0.000005229591351962881,
-0.004226467106491327,
0.0005554656963795424,
-0.00863584317266941,
0.008317386731505394,
0.007136181462556124,
0.003490530652925372,
0.0031375284306705,
-0.0036672204732894897,
0.009195391088724136,
0.0029504247941076756,
-0.008880841545760632,
-0.00486959470435977,
-0.0010531877633184195,
-0.0007147648721002042,
-0.006460557691752911,
-0.0057937647216022015,
0.00454762764275074,
-0.005956834647804499,
0.00035365004441700876,
-0.01954617351293564,
0.013354542665183544,
-0.0025115686003118753,
-0.005250272806733847,
-0.008125387132167816,
0.001146100927144289,
0.005112388636916876,
-0.005650329869240522,
0.003413773374632001,
-0.007195315323770046,
0.001295402180403471,
-0.011279297061264515,
0.005074432585388422,
-0.00733671709895134,
0.005819051060825586,
0.01438397541642189,
0.002892146585509181,
-0.005651310086250305,
-0.005352278705686331,
0.0145384781062603,
0.0008112553623504937,
-0.01043005846440792,
-0.0017319769831374288,
-0.003492477349936962,
-0.0005776204052381217,
0.005845051724463701,
0.0022651220206171274,
-0.014347143471240997,
-0.00545321824029088,
-0.003973679151386023,
0.0022630805615335703,
-0.0020851821172982454,
0.005653284024447203,
0.0034731002524495125,
0.0003090289537794888,
0.006386941764503717,
0.004159652162343264,
0.0015151860425248742,
-0.004250587895512581,
-0.001240147859789431,
-0.0008947276510298252,
0.0077098216861486435,
0.005207268055528402,
0.0050865220837295055,
-0.003982284106314182,
0.003415500046685338,
0.010469027794897556,
0.01187996193766594,
0.00990317203104496,
0.019349511712789536,
-0.013235243037343025,
0.04708314687013626,
0.007034903857856989,
-0.007243681699037552,
0.005155835300683975,
-0.008686419576406479,
-0.0022539838682860136,
-0.008004494942724705,
-0.02638801373541355,
-0.0019891781266778708,
-0.004758141003549099,
0.0017717279260978103,
0.003878365969285369,
0.002014108933508396,
0.008880171924829483,
-0.000833806290756911,
-0.0025947934482246637,
-0.007476653438061476,
0.008132330141961575,
-0.007972974330186844,
-0.0046861432492733,
0.006852888036519289,
0.003257371485233307,
-0.012812357395887375,
-0.000641072285361588,
0.0013340208679437637,
-0.011330093257129192,
0.0013047473039478064,
0.006323027890175581,
-0.005080655217170715,
0.048316024243831635,
-0.0018091915408149362,
0.003360762493684888,
-0.0052937413565814495,
0.0040072728879749775,
0.003907557111233473,
0.004885011352598667,
0.008873655460774899,
-0.00030118078575469553,
0.013988994061946869,
0.008265998214483261,
0.0040187225677073,
0.010831660591065884,
-0.00030287355184555054,
0.004544353112578392,
-0.0019222362898290157,
-0.000604383007157594,
0.0005708103417418897,
-0.008377227000892162,
0.008194349706172943,
-0.003485346445813775,
-0.010797245427966118,
0.005726955831050873,
-0.0009862117003649473,
-0.009794550016522408,
0.00043807338806800544,
-0.003214359050616622,
0.006227768957614899,
-0.01193082146346569,
-0.0028207243885844946,
-0.005886194296181202,
-0.004973927978426218,
0.003587329527363181,
0.008691642433404922,
0.004667205270379782,
0.0011987047037109733,
-0.005563075188547373,
-0.010458320379257202,
0.0024021067656576633,
-0.0012916739797219634,
0.0006775735528208315,
0.006398337427526712,
0.0027512717060744762,
-0.010697086341679096,
-0.0009792133932933211,
0.0016280683921650052,
0.005879524629563093,
-0.0010616079671308398,
0.003452557371929288,
-0.006934917066246271,
0.007042847108095884,
-0.004639581777155399,
0.007855703122913837,
0.00896226242184639,
-0.004156777169555426,
0.0008967795874923468,
-0.0023175072856247425,
0.003937784116715193,
-0.000622850377112627,
0.006479138508439064,
0.009911572560667992,
-0.003914287313818932,
-0.005939497146755457,
0.0035189781337976456,
0.005403408780694008,
0.007223262917250395,
0.004542744718492031,
-0.00020162647706456482,
0.0014909664168953896,
-0.004419591277837753,
-0.0007791597745381296,
0.006521295756101608,
-0.005080985836684704,
0.006630068179219961,
0.0024380984250456095,
-0.013434025458991528,
-0.008028198033571243,
-0.0010125867556780577,
-0.00749222980812192,
0.002201038645580411,
0.011736515909433365,
0.01081377174705267,
-0.0029016307089477777,
0.002357431687414646,
-0.01006193645298481,
0.0012356034712865949,
0.00916541088372469,
0.0010961714433506131,
-0.012934734113514423,
-0.9618905186653137,
0.009266006760299206,
0.0045059011317789555,
-0.001795474672690034,
0.004751155152916908,
0.0032701408490538597,
0.0008009667508304119,
0.00590281980112195,
0.012698175385594368,
-0.0056881229393184185,
-0.005171534605324268,
-0.010577242821455002,
-0.011343805119395256,
-0.004595045465976,
-0.00848905649036169,
-0.002429543063044548,
-0.006172805093228817,
-0.007941145449876785,
-0.003319742623716593,
-0.004649650305509567,
-0.0020374872256070375,
0.0073225852102041245,
-0.003521353006362915,
0.008758028037846088,
0.0034106734674423933,
0.00032073192414827645,
-0.0025030875112861395,
-0.0024009072221815586,
-0.003267195075750351,
-0.003315972164273262,
-0.007671177387237549,
-0.012495419941842556,
-0.0034348159097135067,
-0.003128346987068653,
0.009258303791284561,
0.0014855999033898115,
0.009357191622257233,
-0.0037807368207722902,
0.0024131315294653177,
-0.008190121501684189,
0.005144573748111725,
-0.0005877565126866102,
0.0027463578153401613,
-0.02920438162982464,
-0.0026214986573904753,
-0.0005379898357205093,
-0.008114042691886425,
0.008998709730803967,
-0.0005046448786742985,
0.0008391457377001643,
-0.005510271061211824,
-0.007585929241031408,
0.006225651130080223,
-0.0075797587633132935,
0.0038937313947826624,
-0.005690323188900948,
-0.010429046116769314,
-0.0013275929959490895,
-0.007971308194100857,
0.0016551663866266608,
0.0027101861778646708,
0.0006179857300594449,
-0.0025612018071115017,
-0.0057000163942575455,
0.001921729533933103,
0.003325552912428975,
0.003794103628024459,
-0.018538521602749825,
-0.007470478769391775,
0.0011324298102408648,
-0.001468350295908749,
-0.0031416595447808504,
-0.0036485549062490463,
0.0037057131994515657,
-0.007913659326732159,
0.005662993993610144,
0.0038369125686585903,
-0.00030296825570985675,
-0.010738734155893326,
-0.004917812068015337,
-0.010217121802270412,
-0.006659307982772589,
0.0003615792957134545,
-0.004969446454197168,
-0.004567018244415522,
0.0007675504893995821,
0.0023335502482950687,
0.006163493730127811,
-0.006060549523681402,
0.004360391292721033,
0.010454962030053139,
-0.0038780150935053825,
-0.008945309557020664,
0.003031184896826744,
0.008685184642672539,
0.0008309805416502059,
-0.0011735084699466825,
0.005263388156890869,
0.005918869748711586,
0.00875084102153778,
0.0031252913177013397,
0.005554138217121363,
0.0005858375807292759,
0.013146385550498962,
-0.003117830492556095,
-0.0010540337534621358,
-0.004680291749536991,
0.0011082787532359362,
-0.004439829848706722,
-0.0015525692142546177,
-0.00230226619169116,
-0.004032132215797901,
-0.01236119493842125,
-0.009568699635565281,
-0.0019624861888587475,
-0.0008972327341325581,
0.004546943120658398,
-0.003334084991365671,
-0.0022055695299059153,
0.0004438523028511554,
0.00643240287899971,
-0.0005283507052809,
-0.0041662221774458885,
-0.0012250178260728717,
0.0009104259661398828,
-0.0010997940553352237,
0.015217823907732964,
-0.009351570159196854,
0.0076675983145833015,
0.0006120904581621289,
-0.012362774461507797,
0.006038910709321499,
0.010171199217438698,
-0.0053703938610851765,
-0.0031990157440304756,
0.0021591386757791042,
0.002501957817003131,
-0.0004785071942023933,
-0.0026048379950225353,
-0.0010204403661191463,
-0.01927577331662178,
0.0019836202263832092,
0.017962684854865074,
0.003040148876607418,
0.010649098083376884,
0.01213015429675579,
-0.0031643537804484367,
0.001236885553225875,
0.007896131835877895,
0.0009104190394282341,
0.011722969822585583,
-0.008916698396205902,
0.0014014980988577008,
0.0033629504032433033,
-0.007305985316634178,
0.0009697825298644602,
0.005769905634224415,
0.005150188691914082,
-0.002764924895018339,
0.0008452690672129393,
-0.0064441547729074955,
-0.004121011588722467,
-0.018284553661942482,
-0.004988938104361296,
0.0067884838208556175,
-0.00489956745877862,
0.005060596391558647,
-0.011901061050593853,
0.0035169378388673067,
0.004690314643085003,
0.009053346700966358,
0.001779288169927895,
0.0016222556587308645,
0.005323180463165045,
0.012400156818330288,
-0.005837454926222563,
0.002928684698417783,
0.002407260239124298,
-0.0007672362844459713,
0.0014575053937733173,
0.009033137001097202,
-0.0068604606203734875,
-0.005645040422677994,
0.004445218946784735,
0.0037051786202937365,
-0.00038567237788811326,
-0.003487722482532263,
-0.008135853335261345,
-0.0007805703789927065,
0.0027725282125175,
-0.005265224725008011,
0.0015319070080295205,
-0.00022499109036289155,
0.003521168604493141,
-0.007162421941757202,
-0.0027083938475698233,
-0.0012212353758513927,
-0.013847460970282555,
0.01100174244493246,
-0.0022720282431691885,
0.0036399022210389376,
0.01549787912517786,
0.004598889034241438,
-0.012497218325734138,
0.0053603691048920155,
0.011220126412808895,
-0.0017108023166656494,
0.0036294900346547365,
0.007063026539981365,
-0.006211471743881702,
-0.021503973752260208,
-0.004210601095110178,
-0.010038233362138271,
0.0027307309210300446,
-0.0018766258144751191,
0.001655943924561143,
-0.007546878419816494,
0.005490024574100971,
0.00922210793942213,
-0.014972331002354622,
-0.006853966508060694,
-0.008235208690166473,
0.008868090808391571,
0.0005956033710390329,
0.0013572188327088952,
-0.005221162922680378,
-0.0009138924069702625,
-0.0032903202809393406,
-0.006539138033986092,
-0.0037130238488316536,
0.0050028245896101,
0.0005199936567805707,
-0.00029800544143654406,
0.0034824442118406296,
-0.0032730589155107737,
0.00038656132528558373,
-0.0025988018605858088,
-0.009001667611300945,
0.004423101898282766,
0.00041064940160140395,
-0.0024236170575022697,
-0.0006150173721835017,
0.002325768116861582,
-0.003107843454927206,
-0.006302657071501017,
-0.011314170435070992,
-0.00751066580414772,
-0.002668354893103242,
-0.0037666934076696634,
-0.012648731470108032,
-0.0021390579640865326,
-0.009659705683588982,
0.007202120963484049,
-0.005666347686201334,
0.009074928238987923,
0.003002620767802,
-0.008340415544807911,
0.006213789340108633,
-0.0009551139664836228,
0.003744554938748479,
0.0016075022285804152,
0.006635159254074097,
0.0010998533107340336,
-0.005110543221235275,
-0.01061221119016409,
0.011044429615139961,
-0.0072645219042897224,
0.0025122726801782846,
0.015113717876374722,
0.003906809724867344,
0.009341586381196976,
0.0005078669055365026,
-0.0009434778476133943,
-0.0012392024509608746,
0.006453984882682562,
-0.012349847704172134,
0.0036486913450062275,
-0.006877092178910971,
0.000736474059522152,
0.004793688654899597,
-0.002578732091933489,
0.004382884595543146,
0.009975599125027657,
0.001659355591982603,
-0.007789104711264372,
-0.0010254369117319584,
0.0008092509233392775,
0.0015239546773955226,
-0.010483928956091404,
0.0019149610307067633,
-0.0039175222627818584,
-0.003973182290792465,
-0.003388618817552924,
-0.0007993513136170805,
-0.0000178339487320045,
0.003507838351652026,
-0.002526200609281659,
0.005590767599642277,
0.002439529402181506,
-0.007712189573794603,
0.01259951014071703,
-0.005662829615175724,
-0.0010971864685416222,
0.004438404925167561,
0.0022762964945286512,
-0.004007432144135237,
-0.00426831329241395,
-0.004570885095745325,
0.002904267981648445,
0.00848157238215208,
-0.005288651678711176,
-0.0024649265687912703,
-0.0008072282071225345,
-0.0020981254056096077,
-0.00898311659693718,
-0.0004957978380843997,
0.012864591553807259,
-0.007718953769654036,
0.007093918509781361,
-0.0027728842105716467,
-0.008009683340787888,
-0.010788005776703358,
0.0514005683362484,
-0.00041857073665596545,
0.005119971465319395,
0.0036506368778645992,
-0.005825811065733433,
-0.0014015252236276865,
-0.003218662226572633,
0.007118281442672014,
-0.004165643360465765,
-0.00686353025957942,
0.008765779435634613,
-0.005818977020680904,
0.005680939182639122,
0.0040766578167676926,
-0.0013157431967556477,
0.01769636571407318,
-0.0023020757362246513,
-0.016002511605620384,
-0.016647862270474434,
0.005425824783742428,
-0.004362211097031832,
-0.00817110762000084,
0.009463365189731121,
-0.0066269454546272755,
-0.004956493154168129,
0.0008720601908862591,
0.00459732860326767,
-0.0002776178589556366,
-0.0023534114006906748,
-0.001312243053689599,
-0.002001130022108555,
-0.0031985549721866846,
-0.0010346889030188322,
0.005178122315555811,
0.007735454943031073,
-0.002222552662715316,
0.0048155696131289005,
-0.0018806093139573932,
-0.002754855202510953,
-0.004189345519989729,
0.006142919883131981,
0.007593198213726282,
-0.00022984400857239962,
-0.0013600558741018176,
0.006594586651772261,
0.003080794122070074,
-0.0000328704591083806,
0.011443841271102428,
-0.00006839834532001987,
-0.00444094929844141,
0.008279813453555107,
0.0063110580667853355,
0.00031599393696524203,
0.007446013391017914,
0.000629846123047173,
0.006149617955088615,
0.004075021483004093,
-0.009407834149897099,
-0.017058050259947777,
-0.0021470917854458094,
0.009483135305345058,
0.005569120403379202,
-0.0025253845378756523,
0.0002716108283493668,
0.000575835641939193,
-0.0021302371751517057,
-0.006896114442497492,
-0.008172034285962582,
-0.0009034947725012898,
0.001075646374374628,
0.004506721161305904,
0.06782502681016922,
-0.006103347055613995,
0.0012752590700984001,
-0.008086511865258217,
-0.000551497214473784,
-0.0003790023038163781,
-0.0009181102504953742,
0.002694050082936883,
-0.0012877170229330659,
0.00033046508906409144,
0.00012638152111321688,
-0.009929904714226723,
-0.012310550548136234,
-0.0016799281584098935,
0.003154370002448559,
-0.002272635465487838,
0.003181120613589883,
0.0068360925652086735,
-0.010101218707859516,
0.0006577522726729512,
-0.010797382332384586,
-0.0010921561624854803,
0.0014371996512636542,
-0.010303841903805733,
-0.0047674463130533695,
-0.003496388206258416,
0.006830219645053148,
0.004674641881138086,
0.00256503839045763,
-0.0023364496883004904,
0.006816043518483639,
-0.0015335712814703584,
-0.0011944115394726396,
-0.0035096663050353527,
-0.0007092358428053558,
-0.002933343406766653,
0.010040340013802052,
0.002196243032813072,
-0.012632513418793678,
-0.003680346067994833,
0.0018191436538472772,
-0.0011957959504798055,
-0.004933662712574005,
0.0022892195265740156,
-0.0016399999149143696,
0.003530878573656082,
-0.003672301070764661,
0.0003907416248694062,
-0.0054239267483353615,
0.0027645297814160585,
-0.010384230874478817,
0.0048174671828746796,
-0.16105858981609344,
0.012211344204843044,
0.004438499920070171,
-0.004988047294318676,
-0.004755367059260607,
-0.01690262369811535,
-0.006854241248220205,
0.0007804056513123214,
0.009195821359753609,
0.004328764509409666,
-0.001738611957989633,
-0.0031157222110778093,
0.003984510432928801,
0.004014923702925444,
-0.002583090914413333,
-0.003369996091350913,
0.002357268240302801,
-0.0051652793772518635,
0.002085081534460187,
0.0028268068563193083,
0.004050090443342924,
0.009092425927519798,
0.0009662541560828686,
0.0025834091939032078,
-0.00014660989108961076,
-0.0044107576832175255,
0.0038646028842777014,
-0.0019572351593524218,
0.0017029379960149527,
-0.009870395064353943,
-0.005880835931748152,
-0.0007772903773002326,
-0.0035258892457932234,
0.00025481919874437153,
0.005397418979555368,
0.0013657242525368929,
0.007795304525643587,
0.001774979755282402,
-0.007713151630014181,
0.004089443013072014,
-0.0063879601657390594,
0.02775632217526436,
0.005020978860557079,
0.006064427085220814,
0.00009343673445982859,
-0.008242019452154636,
-0.0071954792365431786,
0.009492256678640842,
0.0028802738524973392,
0.013730309903621674,
-0.014877009205520153,
0.002451494336128235,
0.0037931553088128567,
0.01955651305615902,
-0.004227977246046066,
-0.011684398166835308,
-0.006682479754090309,
-0.0021730810403823853,
0.0015395499067381024,
0.005974367260932922,
0.00993899255990982,
-0.0031926578376442194,
0.009067611768841743,
-0.002128759864717722,
-0.020296301692724228,
0.0042395987547934055,
-0.003275209339335561,
-0.0059852637350559235,
-0.0021068169735372066,
0.008776511065661907,
0.009974606335163116,
0.00027870183112099767,
0.0019554339814931154,
-0.0028490074910223484,
0.007361727301031351,
-0.00032785459188744426,
0.005045265890657902,
-0.0005447593866847456,
0.006478085648268461,
-0.009210396558046341,
0.00695268576964736,
-0.007872658781707287,
-0.0012976247817277908,
0.0006089493399485946,
-0.00471443822607398,
0.010002318769693375,
0.0061896443367004395,
-0.00248255324549973,
-0.0016606580466032028,
-0.010975096374750137,
-0.0007314484100788832,
0.0021228070836514235,
0.0057184877805411816,
-0.009556530974805355,
0.004001378547400236,
0.0028203267138451338,
0.002485272940248251,
0.008488258346915245,
-0.013577581383287907,
0.00718676159158349,
0.003186353947967291,
-0.006026256363838911,
-0.002611500909551978,
-0.0044532050378620625,
0.0036794734187424183,
0.0050244880840182304,
-0.004412396345287561,
-0.005604543723165989,
0.0034601723309606314,
-0.0058974954299628735,
-0.006218340247869492,
0.007698114961385727,
-0.009602162055671215,
-0.00987930130213499,
-0.0024775967467576265,
-0.008812234736979008,
-0.0009154080762527883
] |
8a45f1c6e8e51b93e9ab54060af5d33d536b2abf | 75 | py | Python | logger/__init__.py | remmyzen/nqs-tensorflow2 | 2af5d5ebb108eac4d2daa5082bdef11c8107bd1b | [
"MIT"
] | 4 | 2021-07-29T17:52:54.000Z | 2022-02-15T06:32:15.000Z | logger/__init__.py | remmyzen/nqs-tensorflow2 | 2af5d5ebb108eac4d2daa5082bdef11c8107bd1b | [
"MIT"
] | null | null | null | logger/__init__.py | remmyzen/nqs-tensorflow2 | 2af5d5ebb108eac4d2daa5082bdef11c8107bd1b | [
"MIT"
] | null | null | null | from .logger import Logger
from .logger_supervised import LoggerSupervised
| 25 | 47 | 0.866667 | 1 | 0.6441 | [
0.00010133952309843153,
0.024211985990405083,
0.00840104091912508,
-0.001062778290361166,
0.003954744897782803,
-0.004466807469725609,
-0.010475162416696548,
0.0038202363066375256,
-0.009460799396038055,
-0.0024035251699388027,
0.001903485506772995,
0.003472353098914027,
0.009967059828341007,
-0.015596513636410236,
0.001953986706212163,
0.016970138996839523,
-0.06309191882610321,
0.0048847380094230175,
-0.007818866521120071,
0.0032016111072152853,
-0.00676347129046917,
0.012544220313429832,
0.008582544513046741,
0.008823136799037457,
0.005602804012596607,
0.0018017974216490984,
0.011907466687262058,
0.0013686608290299773,
-0.010498211719095707,
-0.004048439208418131,
0.003734064754098654,
-0.0006055926787666976,
-0.009924729354679585,
-0.008929667994379997,
0.009900790639221668,
-0.0009072414832189679,
0.003474604105576873,
-0.018519414588809013,
0.009608267806470394,
-0.009928158484399319,
-0.006824164185672998,
-0.01967041753232479,
0.0024806750006973743,
0.005087606143206358,
-0.012806414626538754,
0.002242077374830842,
-0.004297845531255007,
0.006999299395829439,
-0.008577780798077583,
0.004706292878836393,
-0.012788733467459679,
0.0029564187861979008,
0.014501631259918213,
0.0022335632238537073,
-0.008637315593659878,
-0.007102360017597675,
0.010093888267874718,
0.0019166694255545735,
-0.012506384402513504,
-0.0005599080468527973,
-0.0040916260331869125,
-0.0019642882980406284,
0.006045504007488489,
0.0074674347415566444,
-0.017718037590384483,
-0.004780888557434082,
-0.0050828224048018456,
0.001231060246936977,
-0.0025252962950617075,
0.007357978727668524,
0.0006128959939815104,
-0.0027230673003941774,
0.01074129343032837,
0.0005569059867411852,
0.00496671674773097,
-0.005087526980787516,
-0.0022549061104655266,
0.004367615096271038,
0.009881648235023022,
-0.0007137088105082512,
0.0073289088904857635,
-0.012319506146013737,
0.006083640735596418,
0.015807019546628,
0.01591649278998375,
0.013041389174759388,
0.019090041518211365,
-0.009616434574127197,
0.04081716760993004,
0.004631790332496166,
-0.011778527870774269,
0.0019612647593021393,
-0.008855280466377735,
-0.0037053090054541826,
0.0018308816943317652,
-0.03344877436757088,
0.003000956727191806,
-0.003972764126956463,
0.0016303900629281998,
0.004715870600193739,
0.0034511848352849483,
0.003545869141817093,
-0.0050384183414280415,
-0.0028565810061991215,
-0.008649570867419243,
0.014045199379324913,
-0.00889043789356947,
-0.0005523422732949257,
0.009135069325566292,
0.0018713435856625438,
-0.00919582974165678,
0.00013514341844711453,
0.0037357094697654247,
-0.014404913410544395,
0.004985387437045574,
0.005305511876940727,
-0.006559802684932947,
0.05652021989226341,
0.00015820225235074759,
0.0015307185240089893,
-0.006899218074977398,
-0.0040214103646576405,
0.00010640716209309176,
0.008779910393059254,
0.01116944383829832,
-0.007429045159369707,
0.012319478206336498,
0.005705216433852911,
0.004024857189506292,
0.005360749550163746,
0.0026366005185991526,
0.008229360915720463,
-0.003830492962151766,
0.000006749313342879759,
-0.00022669733152724802,
-0.007193863391876221,
0.007126739714294672,
-0.001304520876146853,
-0.007158449850976467,
-0.003272242844104767,
-0.0017661049496382475,
-0.014570415019989014,
-0.0034864891786128283,
-0.000650063797365874,
-0.0018394023645669222,
-0.013205783441662788,
-0.00641627749428153,
0.000004446704224392306,
-0.0033465279266238213,
0.001456631114706397,
0.004331683274358511,
0.0058218939229846,
0.001493216841481626,
-0.004966162145137787,
-0.008357313461601734,
-0.004229520447552204,
-0.005242901388555765,
0.004800315480679274,
0.009625710546970367,
0.0038860344793647528,
-0.00688901636749506,
-0.0034305856097489595,
0.002540061017498374,
0.011368674226105213,
0.001274287118576467,
-0.005928562488406897,
-0.008646700531244278,
0.010124871507287025,
0.002055366290733218,
0.0017761042108759284,
0.012747191824018955,
-0.0035486696287989616,
-0.0010492772562429309,
0.004510999657213688,
0.001778442645445466,
-0.0014475990319624543,
0.001401163637638092,
0.010570955462753773,
-0.004014306236058474,
-0.008899902924895287,
0.002892034128308296,
0.0007790503441356122,
0.009134897962212563,
0.012688113376498222,
-0.003014421323314309,
0.007367499638348818,
-0.0010275304084643722,
0.0025611112359911203,
0.003183996072039008,
-0.004824062343686819,
0.007237420417368412,
0.002817695727571845,
-0.01608019880950451,
-0.007508739363402128,
-0.0025363550521433353,
-0.011349508538842201,
0.0003816815442405641,
0.018608126789331436,
0.007352127227932215,
0.002792183542624116,
0.005725126713514328,
-0.010595988482236862,
-0.0021256485488265753,
0.007246049121022224,
0.00007045300299068913,
-0.01433083787560463,
-0.9518380165100098,
0.0014357470208778977,
0.0021956893615424633,
-0.0005896613583900034,
0.0038082546088844538,
0.001954098464921117,
0.0019335267134010792,
-0.0004721539735328406,
0.012269187718629837,
-0.010623416863381863,
-0.010903830640017986,
-0.009618192911148071,
-0.009034727700054646,
0.0019418613519519567,
-0.006588185206055641,
-0.0018518483266234398,
-0.0016931452555581927,
-0.005791329778730869,
0.00008187078492483124,
-0.005893500987440348,
-0.0010515500325709581,
0.009604718536138535,
0.0004717712290585041,
0.0037627716083079576,
0.005034196190536022,
0.006174701265990734,
-0.007059483323246241,
-0.0031466647051274776,
0.0002190369414165616,
-0.001100477995350957,
-0.0035864971578121185,
-0.019210556522011757,
-0.00619212631136179,
-0.004658880177885294,
0.013322390615940094,
-0.0061444188468158245,
0.008073796518146992,
0.0030291639268398285,
0.0027730532456189394,
-0.009207035414874554,
0.006455900147557259,
0.004259237088263035,
0.003969461191445589,
-0.030638625845313072,
0.0005312010180205107,
-0.0018457364058122039,
-0.009679008275270462,
0.010046669282019138,
0.0030462464783340693,
0.0008970918133854866,
-0.0025597952771931887,
-0.0023274910636246204,
0.011394994333386421,
-0.0077042547054588795,
0.007427566219121218,
-0.00897901225835085,
-0.004668461158871651,
-0.0018926516640931368,
-0.007959825918078423,
-0.0003324280260130763,
0.004123254679143429,
-0.004778140224516392,
-0.005371605046093464,
-0.0009759250096976757,
-0.0018764942651614547,
0.0020851034205406904,
-0.006140307988971472,
-0.01798313297331333,
-0.00638194615021348,
-0.007590790744870901,
0.005902688018977642,
0.0013467911630868912,
-0.0005833882605656981,
0.0020983396098017693,
-0.010770202614367008,
0.006593606900423765,
0.0015981075121089816,
0.0012723244726657867,
-0.008165523409843445,
0.002063401974737644,
-0.006119394674897194,
-0.010798660106956959,
0.00928610097616911,
-0.007881813682615757,
-0.001715665915980935,
-0.0017061687540262938,
0.005648637656122446,
0.005105119198560715,
-0.005500942934304476,
0.000503115588799119,
0.011097192764282227,
-0.004435802344232798,
-0.01337704248726368,
0.006197943352162838,
0.00630167918279767,
0.0015440293354913592,
-0.0028433827683329582,
0.0031342897564172745,
0.009591368027031422,
0.008602292276918888,
0.0033320055808871984,
0.003530096961185336,
0.0019528571283444762,
0.011091254651546478,
0.0009961469331756234,
0.0036111921072006226,
0.004188601393252611,
-0.0016323728486895561,
-0.005626958794891834,
-0.0038959383964538574,
-0.004499474074691534,
-0.0006823960575275123,
-0.01258942112326622,
-0.010770575143396854,
-0.0065407417714595795,
0.0026279448065906763,
-0.000777110573835671,
0.0002406900021014735,
0.0013599871890619397,
0.0006821256247349083,
0.015567333437502384,
0.004039237275719643,
-0.0029432871378958225,
0.004967531654983759,
0.004876779858022928,
-0.008436551317572594,
0.015495862811803818,
-0.014682685025036335,
0.0012213721638545394,
-0.0017236970597878098,
-0.015915771946310997,
0.006425455678254366,
0.005750410724431276,
-0.006872197613120079,
0.001711331307888031,
0.003670421661809087,
0.002152404049411416,
-0.0035306010395288467,
-0.006591451354324818,
-0.0024141932372003794,
-0.015314975753426552,
-0.0014258942101150751,
0.02221275120973587,
0.002035995712503791,
0.011550425551831722,
0.012560263276100159,
-0.0025948267430067062,
0.0073907761834561825,
0.009147042408585548,
0.0008149532950483263,
0.01567528396844864,
-0.013635868206620216,
-0.00009343594865640625,
0.0010675762314349413,
-0.004906279966235161,
0.0015745735727250576,
0.0008227243670262396,
0.003547006519511342,
-0.004522183910012245,
-0.0018252113368362188,
-0.0033260846976190805,
-0.006920728366822004,
-0.01764063909649849,
0.00044105021515861154,
0.01141493208706379,
-0.005204718094319105,
0.002392653375864029,
-0.007467193994671106,
0.002850445918738842,
0.004461341071873903,
0.00024576144642196596,
-0.0013876872835680842,
0.0012634790036827326,
0.008892546407878399,
0.016241921111941338,
-0.009811889380216599,
0.006197786424309015,
-0.00011784586968133226,
-0.0009377453825436532,
0.0054363226518034935,
0.011224760673940182,
-0.013166888616979122,
-0.0053356848657131195,
0.002255552913993597,
0.0007291387300938368,
0.0024680907372385263,
-0.004544475581496954,
-0.008714200928807259,
-0.0019670696929097176,
0.002804887481033802,
-0.00972579512745142,
0.004286830313503742,
0.007640449330210686,
-0.00005245268403086811,
-0.011152097955346107,
0.0007413545972667634,
0.0005641182651743293,
-0.007048960775136948,
0.011044560000300407,
-0.006951844319701195,
0.0052872998639941216,
0.010771664790809155,
0.004010231699794531,
-0.015189995057880878,
0.009525175206363201,
0.008147228509187698,
-0.004301859997212887,
0.0032406894024461508,
0.007684542331844568,
-0.004815134685486555,
-0.02216765470802784,
0.0026463039685040712,
-0.015199756249785423,
0.007041564676910639,
-0.008921561762690544,
0.00045930780470371246,
-0.007000443991273642,
0.01426784135401249,
0.0018772125476971269,
-0.010797783732414246,
-0.003618965856730938,
-0.007503769360482693,
0.006321494001895189,
-0.005496914032846689,
-0.0012098286533728242,
-0.0027335956692695618,
-0.003344702534377575,
-0.006463619880378246,
-0.0001613623753655702,
0.0001498249766882509,
0.0033728741109371185,
0.0015164564829319715,
-0.008385718800127506,
0.004667290952056646,
0.0005918302340433002,
-0.0008001899695955217,
-0.00030817935476079583,
-0.010933909565210342,
0.0025848790537565947,
0.01102179940789938,
-0.002527606440708041,
-0.007603451143950224,
0.00010509761341381818,
-0.007062479387968779,
-0.003321340074762702,
-0.013469571247696877,
-0.005342872813344002,
0.00007588480366393924,
-0.005422987509518862,
-0.00863367784768343,
-0.0030785242561250925,
-0.0065591041930019855,
0.005512074567377567,
-0.00600779801607132,
0.004738236777484417,
0.0026427486445754766,
-0.005826602689921856,
0.006574024446308613,
-0.005124800372868776,
0.005975730717182159,
0.003808572655543685,
0.010509922169148922,
-0.0007957837078720331,
-0.007865415886044502,
-0.008091549389064312,
0.010947062633931637,
-0.011779775843024254,
-0.0012806412996724248,
0.015315298922359943,
0.0035922869574278593,
0.009050719439983368,
0.0017012055031955242,
0.002447328995913267,
0.007094000466167927,
0.007837331853806973,
-0.017622044309973717,
0.0034512088168412447,
-0.0005421519745141268,
0.0012892497470602393,
0.005341690964996815,
-0.005741938017308712,
0.007224162109196186,
0.006507650017738342,
0.003969187382608652,
-0.009113617241382599,
-0.0015839779516682029,
-0.0051605417393147945,
0.0032267204951494932,
-0.011771091260015965,
-0.0011085785226896405,
-0.004854715894907713,
-0.004641578998416662,
-0.003980488050729036,
-0.0006446139886975288,
-0.001604931429028511,
0.00802842527627945,
-0.001776083023287356,
0.008934061974287033,
0.0003022097807843238,
-0.00510750524699688,
0.015069358050823212,
-0.005760230589658022,
-0.00907867681235075,
0.0031837918795645237,
0.0007356907590292394,
0.000018117310901288874,
-0.008633972145617008,
0.0010693370131775737,
0.0027202896308153868,
0.000543119153007865,
-0.0037489410024136305,
-0.009069974534213543,
0.0008801419171504676,
0.002062928630039096,
-0.00993138737976551,
0.00047299746074713767,
0.010997247882187366,
0.0041513508185744286,
0.0034321697894483805,
0.0017491200705990195,
-0.005754989106208086,
-0.01443078089505434,
0.053974900394678116,
0.0014269329840317369,
-0.0009823202854022384,
0.007725663483142853,
-0.004266707226634026,
-0.003128606826066971,
-0.00509656174108386,
0.006695113610476255,
-0.009574907831847668,
-0.005695927422493696,
0.009471733123064041,
-0.0050262222066521645,
0.0005457819206640124,
-0.002779107540845871,
-0.0071475026197731495,
0.015531503595411777,
-0.003295284928753972,
-0.015705429017543793,
-0.013682013377547264,
0.005212951917201281,
-0.004418354481458664,
-0.005081568844616413,
0.006058368366211653,
0.0006694522453472018,
-0.0032358956523239613,
0.0020765343215316534,
0.003959240857511759,
0.000899827922694385,
-0.000438020535511896,
-0.004029152449220419,
-0.002598872408270836,
-0.00014417996862903237,
0.007534208707511425,
0.007421243004500866,
0.012725955806672573,
0.0002684126084204763,
0.005719436798244715,
0.001995449187234044,
-0.0016403140034526587,
0.000051856452046195045,
0.005861948244273663,
0.004584657959640026,
-0.0021323992405086756,
-0.003648117184638977,
0.0046327621676027775,
0.0061363824643194675,
-0.0012398016406223178,
0.0112681919708848,
0.0026647215709090233,
-0.0026347972452640533,
0.007352958898991346,
0.010140198282897472,
-0.00322238402441144,
0.007302660960704088,
-0.0008809009450487792,
0.003927495796233416,
0.0009699748479761183,
-0.012104020453989506,
-0.01004707533866167,
-0.0038212970830500126,
0.00442563695833087,
0.0077411155216395855,
-0.00086865050252527,
0.002334282035008073,
0.005178065504878759,
-0.002554134698584676,
-0.015208126045763493,
-0.005860467907041311,
-0.004351774696260691,
-0.004536877386271954,
0.0023354128934442997,
0.07245170325040817,
-0.007284136954694986,
-0.003089549718424678,
-0.010508747771382332,
0.003162842243909836,
-0.001922390190884471,
0.0013312012888491154,
-0.0011953682405874133,
-0.004531687591224909,
0.0029895456973463297,
0.0038436702452600002,
-0.008406591601669788,
-0.011507485993206501,
0.0036204413045197725,
0.0031164817046374083,
-0.0011972490465268493,
0.003076291875913739,
0.009197915904223919,
-0.004129603039473295,
0.002004319801926613,
-0.012957981787621975,
-0.0006752926856279373,
-0.00478480476886034,
-0.004252334591001272,
-0.0006779110990464687,
-0.0020068867597728968,
-0.0029991779010742903,
0.002309683710336685,
0.0036526343319565058,
-0.002764781005680561,
0.0061669498682022095,
0.00018728227587416768,
0.0021757101640105247,
0.001393060083501041,
-0.002154658082872629,
-0.007656542584300041,
0.006259377580136061,
0.001294549205340445,
-0.015177350491285324,
-0.0030277816113084555,
-0.0022355837281793356,
-0.0020984255243092775,
-0.0063722096383571625,
0.006739925593137741,
-0.0005132726510055363,
0.00920792855322361,
-0.002534689847379923,
0.004163328558206558,
-0.00529696187004447,
-0.004623454064130783,
-0.013687469996511936,
0.007004410028457642,
-0.1865878850221634,
0.009900510311126709,
0.0020680942106992006,
-0.007020450662821531,
-0.005651464685797691,
-0.014139318838715553,
-0.014967733062803745,
0.005637898109853268,
0.008536184206604958,
-0.001971028046682477,
0.0012041134759783745,
0.00037148682167753577,
0.009179024957120419,
0.006016635335981846,
-0.0024881050921976566,
-0.007137328386306763,
0.0019919187761843204,
-0.003859021235257387,
0.0005409326986409724,
0.0036169474478811026,
0.0061958287842571735,
0.004622424952685833,
0.0058566187508404255,
6.603721658393624e-7,
-0.0007836755248717964,
-0.0024657442700117826,
0.0015270243166014552,
-0.0027704129461199045,
0.010456917807459831,
-0.0073429131880402565,
-0.0035648311022669077,
-0.004687689710408449,
-0.001699088723398745,
0.006116836331784725,
-0.0003473622491583228,
-0.0004156767681706697,
0.00785567332059145,
0.00087490223813802,
-0.010628423653542995,
0.009226317517459393,
-0.0080453185364604,
0.033604513853788376,
0.004945193417370319,
0.009566542692482471,
-0.0009462219313718379,
-0.0028932092245668173,
-0.0012828996405005455,
0.006200200412422419,
0.003631115425378084,
0.013950948603451252,
-0.013869339600205421,
-0.00642065005376935,
0.0022395101841539145,
0.019815411418676376,
-0.0053258934058249,
-0.008714348077774048,
-0.009497185237705708,
-0.0033225438091903925,
0.006203504279255867,
0.012670079246163368,
0.01018673088401556,
-0.003723365720361471,
0.006018536631017923,
-0.003990806173533201,
-0.020648641511797905,
0.0058756484650075436,
-0.0009131922270171344,
-0.009526362642645836,
0.001023592078126967,
0.007083299104124308,
0.0066930684261024,
-0.003859184682369232,
0.011710980907082558,
-0.0017654873663559556,
0.00450329901650548,
-0.004117392934858799,
0.008445100858807564,
-0.003663289826363325,
0.005907983519136906,
-0.008419850841164589,
0.01608465611934662,
-0.010695495642721653,
-0.0010568705620244145,
0.004563617520034313,
-0.006349078379571438,
0.00825120136141777,
0.006176731549203396,
-0.004531428683549166,
-0.0005094311200082302,
-0.009577428922057152,
-0.00020117351959925145,
0.002214306965470314,
0.0004771049425471574,
-0.007914775982499123,
0.002330512274056673,
-0.00048224409692920744,
0.007561726961284876,
0.010486964136362076,
-0.008185975253582,
0.006992810405790806,
0.0026130753103643656,
-0.011823765933513641,
0.0004930780851282179,
-0.006851491518318653,
0.001259849057532847,
0.0056900037452578545,
-0.00964381918311119,
-0.009785867296159267,
0.008071430958807468,
-0.0065741706639528275,
-0.00522035313770175,
0.002911458257585764,
-0.011216765269637108,
-0.007070127408951521,
-0.000025745157472556457,
-0.01336448173969984,
0.001854495145380497
] |
8a46bd296a626ee6789a10ae8ade0e121655708c | 36,304 | py | Python | flytekit/core/workflow.py | milton0825/flytekit | 7667a154402d7c02e25006bd6cce926917382a1e | [
"Apache-2.0"
] | null | null | null | flytekit/core/workflow.py | milton0825/flytekit | 7667a154402d7c02e25006bd6cce926917382a1e | [
"Apache-2.0"
] | null | null | null | flytekit/core/workflow.py | milton0825/flytekit | 7667a154402d7c02e25006bd6cce926917382a1e | [
"Apache-2.0"
] | null | null | null | from __future__ import annotations
import collections
import inspect
from dataclasses import dataclass
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from flytekit.common import constants as _common_constants
from flytekit.common.exceptions.user import FlyteValidationException, FlyteValueException
from flytekit.core.base_task import PythonTask
from flytekit.core.class_based_resolver import ClassStorageTaskResolver
from flytekit.core.condition import ConditionalSection
from flytekit.core.context_manager import (
BranchEvalMode,
CompilationState,
ExecutionState,
FlyteContext,
FlyteContextManager,
FlyteEntities,
)
from flytekit.core.interface import (
Interface,
transform_inputs_to_parameters,
transform_interface_to_typed_interface,
transform_signature_to_interface,
)
from flytekit.core.launch_plan import LaunchPlan
from flytekit.core.node import Node
from flytekit.core.promise import (
NodeOutput,
Promise,
VoidPromise,
binding_from_python_std,
create_and_link_node,
create_native_named_tuple,
create_task_output,
translate_inputs_to_literals,
)
from flytekit.core.python_auto_container import PythonAutoContainerTask
from flytekit.core.reference_entity import ReferenceEntity, WorkflowReference
from flytekit.core.type_engine import TypeEngine
from flytekit.loggers import logger
from flytekit.models import interface as _interface_models
from flytekit.models import literals as _literal_models
from flytekit.models.core import workflow as _workflow_model
GLOBAL_START_NODE = Node(
id=_common_constants.GLOBAL_INPUT_NODE_ID,
metadata=None,
bindings=[],
upstream_nodes=[],
flyte_entity=None,
)
class WorkflowFailurePolicy(Enum):
FAIL_IMMEDIATELY = _workflow_model.WorkflowMetadata.OnFailurePolicy.FAIL_IMMEDIATELY
FAIL_AFTER_EXECUTABLE_NODES_COMPLETE = (
_workflow_model.WorkflowMetadata.OnFailurePolicy.FAIL_AFTER_EXECUTABLE_NODES_COMPLETE
)
@dataclass
class WorkflowMetadata(object):
on_failure: WorkflowFailurePolicy
def __post_init__(self):
if (
self.on_failure != WorkflowFailurePolicy.FAIL_IMMEDIATELY
and self.on_failure != WorkflowFailurePolicy.FAIL_AFTER_EXECUTABLE_NODES_COMPLETE
):
raise FlyteValidationException(f"Failure policy {self.on_failure} not acceptable")
def to_flyte_model(self):
if self.on_failure == WorkflowFailurePolicy.FAIL_IMMEDIATELY:
on_failure = 0
else:
on_failure = 1
return _workflow_model.WorkflowMetadata(on_failure=on_failure)
@dataclass
class WorkflowMetadataDefaults(object):
"""
This class is similarly named to the one above. Please see the IDL for more information but essentially, this
WorkflowMetadataDefaults class represents the defaults that are handed down to a workflow's tasks, whereas
WorkflowMetadata represents metadata about the workflow itself.
"""
interruptible: bool
def __post_init__(self):
if self.interruptible is not True and self.interruptible is not False:
raise FlyteValidationException(f"Interruptible must be boolean, {self.interruptible} invalid")
def to_flyte_model(self):
return _workflow_model.WorkflowMetadataDefaults(interruptible=self.interruptible)
def construct_input_promises(inputs: List[str]):
return {
input_name: Promise(var=input_name, val=NodeOutput(node=GLOBAL_START_NODE, var=input_name))
for input_name in inputs
}
def get_promise(binding_data: _literal_models.BindingData, outputs_cache: Dict[Node, Dict[str, Promise]]) -> Promise:
"""
This is a helper function that will turn a binding into a Promise object, using a lookup map. Please see
get_promise_map for the rest of the details.
"""
if binding_data.promise is not None:
if not isinstance(binding_data.promise, NodeOutput):
raise FlyteValidationException(
f"Binding data Promises have to be of the NodeOutput type {type(binding_data.promise)} found"
)
# b.var is the name of the input to the task
# binding_data.promise.var is the name of the upstream node's output we want
return outputs_cache[binding_data.promise.node][binding_data.promise.var]
elif binding_data.scalar is not None:
return Promise(var="placeholder", val=_literal_models.Literal(scalar=binding_data.scalar))
elif binding_data.collection is not None:
literals = []
for bd in binding_data.collection.bindings:
p = get_promise(bd, outputs_cache)
literals.append(p.val)
return Promise(
var="placeholder",
val=_literal_models.Literal(collection=_literal_models.LiteralCollection(literals=literals)),
)
elif binding_data.map is not None:
literals = {}
for k, bd in binding_data.map.bindings.items():
p = get_promise(bd, outputs_cache)
literals[k] = p.val
return Promise(
var="placeholder", val=_literal_models.Literal(map=_literal_models.LiteralMap(literals=literals))
)
raise FlyteValidationException("Binding type unrecognized.")
def get_promise_map(
bindings: List[_literal_models.Binding], outputs_cache: Dict[Node, Dict[str, Promise]]
) -> Dict[str, Promise]:
"""
Local execution of imperatively defined workflows is done node by node. This function will fill in the node's
entity's input arguments, which are specified using the bindings list, and a map of nodes to its outputs.
Basically this takes the place of propeller in resolving bindings, pulling in outputs from previously completed
nodes and filling in the necessary inputs.
"""
entity_kwargs = {}
for b in bindings:
entity_kwargs[b.var] = get_promise(b.binding, outputs_cache)
return entity_kwargs
class WorkflowBase(object):
def __init__(
self,
name: str,
workflow_metadata: WorkflowMetadata,
workflow_metadata_defaults: WorkflowMetadataDefaults,
python_interface: Interface,
**kwargs,
):
self._name = name
self._workflow_metadata = workflow_metadata
self._workflow_metadata_defaults = workflow_metadata_defaults
self._python_interface = python_interface
self._interface = transform_interface_to_typed_interface(python_interface)
self._inputs = {}
self._unbound_inputs = set()
self._nodes = []
self._output_bindings: Optional[List[_literal_models.Binding]] = []
FlyteEntities.entities.append(self)
super().__init__(**kwargs)
@property
def name(self) -> str:
return self._name
@property
def short_name(self) -> str:
return self._name.split(".")[-1]
@property
def workflow_metadata(self) -> Optional[WorkflowMetadata]:
return self._workflow_metadata
@property
def workflow_metadata_defaults(self):
return self._workflow_metadata_defaults
@property
def python_interface(self) -> Interface:
return self._python_interface
@property
def interface(self) -> _interface_models.TypedInterface:
return self._interface
@property
def output_bindings(self) -> List[_literal_models.Binding]:
return self._output_bindings
@property
def nodes(self) -> List[Node]:
return self._nodes
def __repr__(self):
return (
f"WorkflowBase - {self._name} && "
f"Inputs ({len(self._python_interface.inputs)}): {self._python_interface.inputs} && "
f"Outputs ({len(self._python_interface.outputs)}): {self._python_interface.outputs} && "
f"Output bindings: {self._output_bindings} && "
)
def __call__(self, *args, **kwargs):
"""
The call pattern for Workflows is close to, but not exactly, the call pattern for Tasks. For local execution,
it goes
__call__ -> _local_execute -> execute
From execute, different things happen for the two Workflow styles. For PythonFunctionWorkflows, the Python
function is run, for the ImperativeWorkflow, each node is run one at a time.
"""
if len(args) > 0:
raise AssertionError("Only Keyword Arguments are supported for Workflow executions")
ctx = FlyteContextManager.current_context()
# Get default agruements and override with kwargs passed in
input_kwargs = self.python_interface.default_inputs_as_kwargs
input_kwargs.update(kwargs)
# The first condition is compilation.
if ctx.compilation_state is not None:
return create_and_link_node(ctx, entity=self, interface=self.python_interface, **input_kwargs)
# This condition is hit when this workflow (self) is being called as part of a parent's workflow local run.
# The context specifying the local workflow execution has already been set.
elif (
ctx.execution_state is not None and ctx.execution_state.mode == ExecutionState.Mode.LOCAL_WORKFLOW_EXECUTION
):
if ctx.execution_state.branch_eval_mode == BranchEvalMode.BRANCH_SKIPPED:
if self.python_interface and self.python_interface.output_tuple_name:
variables = [k for k in self.python_interface.outputs.keys()]
output_tuple = collections.namedtuple(self.python_interface.output_tuple_name, variables)
nones = [None for _ in self.python_interface.outputs.keys()]
return output_tuple(*nones)
else:
return None
# We are already in a local execution, just continue the execution context
return self._local_execute(ctx, **input_kwargs)
# Last is starting a local workflow execution
else:
# Run some sanity checks
# Even though the _local_execute call generally expects inputs to be Promises, we don't have to do the
# conversion here in this loop. The reason is because we don't prevent users from specifying inputs
# as direct scalars, which means there's another Promise-generating loop inside _local_execute too
for k, v in input_kwargs.items():
if k not in self.interface.inputs:
raise ValueError(f"Received unexpected keyword argument {k}")
if isinstance(v, Promise):
raise ValueError(f"Received a promise for a workflow call, when expecting a native value for {k}")
with FlyteContextManager.with_context(
ctx.with_execution_state(
ctx.new_execution_state().with_params(mode=ExecutionState.Mode.LOCAL_WORKFLOW_EXECUTION)
)
) as child_ctx:
result = self._local_execute(child_ctx, **input_kwargs)
expected_outputs = len(self.python_interface.outputs)
if expected_outputs == 0:
if result is None or isinstance(result, VoidPromise):
return None
else:
raise Exception(f"Workflow local execution expected 0 outputs but something received {result}")
if (1 < expected_outputs == len(result)) or (result is not None and expected_outputs == 1):
return create_native_named_tuple(ctx, result, self.python_interface)
raise ValueError("expected outputs and actual outputs do not match")
def execute(self, **kwargs):
raise Exception("Should not be called")
def _local_execute(self, ctx: FlyteContext, **kwargs) -> Union[Tuple[Promise], Promise, VoidPromise]:
# This is done to support the invariant that Workflow local executions always work with Promise objects
# holding Flyte literal values. Even in a wf, a user can call a sub-workflow with a Python native value.
for k, v in kwargs.items():
if not isinstance(v, Promise):
t = self.python_interface.inputs[k]
kwargs[k] = Promise(var=k, val=TypeEngine.to_literal(ctx, v, t, self.interface.inputs[k].type))
# The output of this will always be a combination of Python native values and Promises containing Flyte
# Literals.
function_outputs = self.execute(**kwargs)
# First handle the empty return case.
# A workflow function may return a task that doesn't return anything
# def wf():
# return t1()
# or it may not return at all
# def wf():
# t1()
# In the former case we get the task's VoidPromise, in the latter we get None
if isinstance(function_outputs, VoidPromise) or function_outputs is None:
if len(self.python_interface.outputs) != 0:
raise FlyteValueException(
function_outputs,
f"{function_outputs} received but interface has {len(self.python_interface.outputs)} outputs.",
)
return VoidPromise(self.name)
# Because we should've already returned in the above check, we just raise an error here.
if len(self.python_interface.outputs) == 0:
raise FlyteValueException(
function_outputs, f"{function_outputs} received but should've been VoidPromise or None."
)
expected_output_names = list(self.python_interface.outputs.keys())
if len(expected_output_names) == 1:
# Here we have to handle the fact that the wf could've been declared with a typing.NamedTuple of
# length one. That convention is used for naming outputs - and single-length-NamedTuples are
# particularly troublesome but elegant handling of them is not a high priority
# Again, we're using the output_tuple_name as a proxy.
if self.python_interface.output_tuple_name and isinstance(function_outputs, tuple):
wf_outputs_as_map = {expected_output_names[0]: function_outputs[0]}
else:
wf_outputs_as_map = {expected_output_names[0]: function_outputs}
else:
wf_outputs_as_map = {expected_output_names[i]: function_outputs[i] for i, _ in enumerate(function_outputs)}
# Basically we need to repackage the promises coming from the tasks into Promises that match the workflow's
# interface. We do that by extracting out the literals, and creating new Promises
wf_outputs_as_literal_dict = translate_inputs_to_literals(
ctx,
wf_outputs_as_map,
flyte_interface_types=self.interface.outputs,
native_types=self.python_interface.outputs,
)
# Recreate new promises that use the workflow's output names.
new_promises = [Promise(var, wf_outputs_as_literal_dict[var]) for var in expected_output_names]
return create_task_output(new_promises, self.python_interface)
class ImperativeWorkflow(WorkflowBase):
def __init__(
self,
name: str,
failure_policy: Optional[WorkflowFailurePolicy] = None,
interruptible: Optional[bool] = False,
):
metadata = WorkflowMetadata(on_failure=failure_policy or WorkflowFailurePolicy.FAIL_IMMEDIATELY)
workflow_metadata_defaults = WorkflowMetadataDefaults(interruptible)
self._compilation_state = CompilationState(prefix="")
self._inputs = {}
# This unbound inputs construct is just here to help workflow authors detect issues a bit earlier. It just
# keeps track of workflow inputs that you've declared with add_workflow_input but haven't yet consumed. This
# is an error that Admin would return at compile time anyways, but this allows flytekit to raise
# the error earlier.
self._unbound_inputs = set()
super().__init__(
name=name,
workflow_metadata=metadata,
workflow_metadata_defaults=workflow_metadata_defaults,
python_interface=Interface(),
)
@property
def compilation_state(self) -> CompilationState:
"""
Compilation is done a bit at a time, one task or other entity call at a time. This is why this workflow
class has to keep track of its own compilation state.
"""
return self._compilation_state
@property
def nodes(self) -> List[Node]:
return self._compilation_state.nodes
@property
def inputs(self) -> Dict[str, Promise]:
"""
This holds the input promises to the workflow. The nodes in these Promise objects should always point to
the global start node.
"""
return self._inputs
def __repr__(self):
return super().__repr__() + f"Nodes ({len(self.compilation_state.nodes)}): {self.compilation_state.nodes}"
def execute(self, **kwargs):
"""
Called by _local_execute. This function is how local execution for imperative workflows runs. Because when an
entity is added using the add_entity function, all inputs to that entity should've been already declared, we
can just iterate through the nodes in order and we shouldn't run into any dependency issues. That is, we force
the user to declare entities already in a topological sort. To keep track of outputs, we create a map to
start things off, filled in only with the workflow inputs (if any). As things are run, their outputs are stored
in this map.
After all nodes are run, we fill in workflow level outputs the same way as any other previous node.
"""
if not self.ready():
raise FlyteValidationException(f"Workflow not ready, wf is currently {self}")
# Create a map that holds the outputs of each node.
intermediate_node_outputs = {GLOBAL_START_NODE: {}} # type: Dict[Node, Dict[str, Promise]]
# Start things off with the outputs of the global input node, i.e. the inputs to the workflow.
# _local_execute should've already ensured that all the values in kwargs are Promise objects
for k, v in kwargs.items():
intermediate_node_outputs[GLOBAL_START_NODE][k] = v
# Next iterate through the nodes in order.
for node in self.compilation_state.nodes:
if node not in intermediate_node_outputs.keys():
intermediate_node_outputs[node] = {}
# Retrieve the entity from the node, and call it by looking up the promises the node's bindings require,
# and then fill them in using the node output tracker map we have.
entity = node.flyte_entity
entity_kwargs = get_promise_map(node.bindings, intermediate_node_outputs)
# Handle the calling and outputs of each node's entity
results = entity(**entity_kwargs)
expected_output_names = list(entity.python_interface.outputs.keys())
if isinstance(results, VoidPromise) or results is None:
continue # pragma: no cover # Move along, nothing to assign
# Because we should've already returned in the above check, we just raise an Exception here.
if len(entity.python_interface.outputs) == 0:
raise FlyteValueException(results, f"{results} received but should've been VoidPromise or None.")
# if there's only one output,
if len(expected_output_names) == 1:
if entity.python_interface.output_tuple_name and isinstance(results, tuple):
intermediate_node_outputs[node][expected_output_names[0]] = results[0]
else:
intermediate_node_outputs[node][expected_output_names[0]] = results
else:
if len(results) != len(expected_output_names):
raise FlyteValueException(results, f"Different lengths {results} {expected_output_names}")
for idx, r in enumerate(results):
intermediate_node_outputs[node][expected_output_names[idx]] = r
# The rest of this function looks like the above but now we're doing it for the workflow as a whole rather
# than just one node at a time.
if len(self.python_interface.outputs) == 0:
return VoidPromise(self.name)
# The values that we return below from the output have to be pulled by fulfilling all of the
# workflow's output bindings.
# The return style here has to match what 1) what the workflow would've returned had it been declared
# functionally, and 2) what a user would return in mock function. That is, if it's a tuple, then it
# should be a tuple here, if it's a one element named tuple, then we do a one-element non-named tuple,
# if it's a single element then we return a single element
if len(self.output_bindings) == 1:
# Again use presence of output_tuple_name to understand that we're dealing with a one-element
# named tuple
if self.python_interface.output_tuple_name:
return (get_promise(self.output_bindings[0].binding, intermediate_node_outputs),)
# Just a normal single element
return get_promise(self.output_bindings[0].binding, intermediate_node_outputs)
return tuple([get_promise(b.binding, intermediate_node_outputs) for b in self.output_bindings])
def add_entity(self, entity: Union[PythonTask, LaunchPlan, WorkflowBase], **kwargs) -> Node:
"""
Anytime you add an entity, all the inputs to the entity must be bound.
"""
# circular import
from flytekit.core.node_creation import create_node
ctx = FlyteContext.current_context()
if ctx.compilation_state is not None:
raise Exception("Can't already be compiling")
with FlyteContextManager.with_context(ctx.with_compilation_state(self.compilation_state)) as ctx:
n = create_node(entity=entity, **kwargs)
def get_input_values(input_value):
if isinstance(input_value, list):
input_promises = []
for x in input_value:
input_promises.extend(get_input_values(x))
return input_promises
if isinstance(input_value, dict):
input_promises = []
for _, v in input_value.items():
input_promises.extend(get_input_values(v))
return input_promises
else:
return [input_value]
# Every time an entity is added, mark it as used. The above function though will gather all the input
# values but we're only interested in the ones that are Promises so let's filter for those.
# There's probably a way to clean this up, maybe key off of the name instead of value?
all_input_values = get_input_values(kwargs)
for input_value in filter(lambda x: isinstance(x, Promise), all_input_values):
if input_value in self._unbound_inputs:
self._unbound_inputs.remove(input_value)
return n
def add_workflow_input(self, input_name: str, python_type: Type) -> Interface:
"""
Adds an input to the workflow.
"""
if input_name in self._inputs:
raise FlyteValidationException(f"Input {input_name} has already been specified for wf {self.name}.")
self._python_interface = self._python_interface.with_inputs(extra_inputs={input_name: python_type})
self._interface = transform_interface_to_typed_interface(self._python_interface)
self._inputs[input_name] = Promise(var=input_name, val=NodeOutput(node=GLOBAL_START_NODE, var=input_name))
self._unbound_inputs.add(self._inputs[input_name])
return self._inputs[input_name]
def add_workflow_output(
self, output_name: str, p: Union[Promise, List[Promise], Dict[str, Promise]], python_type: Optional[Type] = None
):
"""
Add an output with the given name from the given node output.
"""
if output_name in self._python_interface.outputs:
raise FlyteValidationException(f"Output {output_name} already exists in workflow {self.name}")
if python_type is None:
if type(p) == list or type(p) == dict:
raise FlyteValidationException(
f"If specifying a list or dict of Promises, you must specify the python_type type for {output_name}"
f" starting with the container type (e.g. List[int]"
)
python_type = p.ref.node.flyte_entity.python_interface.outputs[p.var]
logger.debug(f"Inferring python type for wf output {output_name} from Promise provided {python_type}")
flyte_type = TypeEngine.to_literal_type(python_type=python_type)
ctx = FlyteContext.current_context()
if ctx.compilation_state is not None:
raise Exception("Can't already be compiling")
with FlyteContextManager.with_context(ctx.with_compilation_state(self.compilation_state)) as ctx:
b = binding_from_python_std(
ctx, output_name, expected_literal_type=flyte_type, t_value=p, t_value_type=python_type
)
self._output_bindings.append(b)
self._python_interface = self._python_interface.with_outputs(extra_outputs={output_name: python_type})
self._interface = transform_interface_to_typed_interface(self._python_interface)
def add_task(self, task: PythonTask, **kwargs) -> Node:
return self.add_entity(task, **kwargs)
def add_launch_plan(self, launch_plan: LaunchPlan, **kwargs) -> Node:
return self.add_entity(launch_plan, **kwargs)
def add_subwf(self, sub_wf: WorkflowBase, **kwargs) -> Node:
return self.add_entity(sub_wf, **kwargs)
def ready(self) -> bool:
"""
This function returns whether or not the workflow is in a ready state, which means
* Has at least one node
* All workflow inputs are bound
These conditions assume that all nodes and workflow i/o changes were done with the functions above, which
do additional checking.
"""
if len(self.compilation_state.nodes) == 0:
return False
if len(self._unbound_inputs) > 0:
return False
return True
class PythonFunctionWorkflow(WorkflowBase, ClassStorageTaskResolver):
"""
Please read :std:ref:`flyte:divedeep-workflows` first for a high-level understanding of what workflows are in Flyte.
This Python object represents a workflow defined by a function and decorated with the
:py:func:`@workflow <flytekit.workflow>` decorator. Please see notes on that object for additional information.
"""
def __init__(
self,
workflow_function: Callable,
metadata: Optional[WorkflowMetadata],
default_metadata: Optional[WorkflowMetadataDefaults],
):
name = f"{workflow_function.__module__}.{workflow_function.__name__}"
self._workflow_function = workflow_function
native_interface = transform_signature_to_interface(inspect.signature(workflow_function))
# TODO do we need this - can this not be in launchplan only?
# This can be in launch plan only, but is here only so that we don't have to re-evaluate. Or
# we can re-evaluate.
self._input_parameters = None
super().__init__(
name=name,
workflow_metadata=metadata,
workflow_metadata_defaults=default_metadata,
python_interface=native_interface,
)
@property
def function(self):
return self._workflow_function
def task_name(self, t: PythonAutoContainerTask) -> str:
return f"{self.name}.{t.__module__}.{t.name}"
def compile(self, **kwargs):
"""
Supply static Python native values in the kwargs if you want them to be used in the compilation. This mimics
a 'closure' in the traditional sense of the word.
"""
ctx = FlyteContextManager.current_context()
self._input_parameters = transform_inputs_to_parameters(ctx, self.python_interface)
all_nodes = []
prefix = f"{ctx.compilation_state.prefix}-{self.short_name}-" if ctx.compilation_state is not None else ""
with FlyteContextManager.with_context(
ctx.with_compilation_state(CompilationState(prefix=prefix, task_resolver=self))
) as comp_ctx:
# Construct the default input promise bindings, but then override with the provided inputs, if any
input_kwargs = construct_input_promises([k for k in self.interface.inputs.keys()])
input_kwargs.update(kwargs)
workflow_outputs = self._workflow_function(**input_kwargs)
all_nodes.extend(comp_ctx.compilation_state.nodes)
# This little loop was added as part of the task resolver change. The task resolver interface itself is
# more or less stateless (the future-proofing get_all_tasks function notwithstanding). However the
# implementation of the TaskResolverMixin that this workflow class inherits from (ClassStorageTaskResolver)
# does store state. This loop adds Tasks that are defined within the body of the workflow to the workflow
# object itself.
for n in comp_ctx.compilation_state.nodes:
if isinstance(n.flyte_entity, PythonAutoContainerTask) and n.flyte_entity.task_resolver == self:
logger.debug(f"WF {self.name} saving task {n.flyte_entity.name}")
self.add(n.flyte_entity)
# Iterate through the workflow outputs
bindings = []
output_names = list(self.interface.outputs.keys())
# The reason the length 1 case is separate is because the one output might be a list. We don't want to
# iterate through the list here, instead we should let the binding creation unwrap it and make a binding
# collection/map out of it.
if len(output_names) == 1:
if isinstance(workflow_outputs, tuple):
if len(workflow_outputs) != 1:
raise AssertionError(
f"The Workflow specification indicates only one return value, received {len(workflow_outputs)}"
)
if self.python_interface.output_tuple_name is None:
raise AssertionError(
"Outputs specification for Workflow does not define a tuple, but return value is a tuple"
)
workflow_outputs = workflow_outputs[0]
t = self.python_interface.outputs[output_names[0]]
b = binding_from_python_std(
ctx,
output_names[0],
self.interface.outputs[output_names[0]].type,
workflow_outputs,
t,
)
bindings.append(b)
elif len(output_names) > 1:
if not isinstance(workflow_outputs, tuple):
raise AssertionError("The Workflow specification indicates multiple return values, received only one")
if len(output_names) != len(workflow_outputs):
raise Exception(f"Length mismatch {len(output_names)} vs {len(workflow_outputs)}")
for i, out in enumerate(output_names):
if isinstance(workflow_outputs[i], ConditionalSection):
raise AssertionError("A Conditional block (if-else) should always end with an `else_()` clause")
t = self.python_interface.outputs[out]
b = binding_from_python_std(
ctx,
out,
self.interface.outputs[out].type,
workflow_outputs[i],
t,
)
bindings.append(b)
# Save all the things necessary to create an SdkWorkflow, except for the missing project and domain
self._nodes = all_nodes
self._output_bindings = bindings
if not output_names:
return None
if len(output_names) == 1:
return bindings[0]
return tuple(bindings)
def execute(self, **kwargs):
"""
This function is here only to try to streamline the pattern between workflows and tasks. Since tasks
call execute from dispatch_execute which is in _local_execute, workflows should also call an execute inside
_local_execute. This makes mocking cleaner.
"""
return self._workflow_function(**kwargs)
def workflow(
_workflow_function=None,
failure_policy: Optional[WorkflowFailurePolicy] = None,
interruptible: Optional[bool] = False,
):
"""
This decorator declares a function to be a Flyte workflow. Workflows are declarative entities that construct a DAG
of tasks using the data flow between tasks.
Unlike a task, the function body of a workflow is evaluated at serialization-time (aka compile-time). This is because
while we can determine the entire structure of a task by looking at the function's signature,
workflows need to run through the function itself because the body of the function is what expresses the workflow structure.
It's also important to note that, local execution notwithstanding, it is not evaluated again when the workflow runs on Flyte.
That is, workflows should not call non-Flyte entities since they are only run once (again, this is with respect to
the platform, local runs notwithstanding).
Please see the :std:doc:`cookbook:sphx_glr_auto_core_flyte_basics_basic_workflow.py` for more usage examples.
:param _workflow_function: This argument is implicitly passed and represents the decorated function.
:param failure_policy: Use the options in flytekit.WorkflowFailurePolicy
:param interruptible: Whether or not tasks launched from this workflow are by default interruptible
"""
def wrapper(fn):
workflow_metadata = WorkflowMetadata(on_failure=failure_policy or WorkflowFailurePolicy.FAIL_IMMEDIATELY)
workflow_metadata_defaults = WorkflowMetadataDefaults(interruptible)
workflow_instance = PythonFunctionWorkflow(
fn, metadata=workflow_metadata, default_metadata=workflow_metadata_defaults
)
workflow_instance.compile()
return workflow_instance
if _workflow_function:
return wrapper(_workflow_function)
else:
return wrapper
class ReferenceWorkflow(ReferenceEntity, PythonFunctionWorkflow):
"""
A reference workflow is a pointer to a workflow that already exists on your Flyte installation. This
object will not initiate a network call to Admin, which is why the user is asked to provide the expected interface.
If at registration time the interface provided causes an issue with compilation, an error will be returned.
"""
def __init__(
self, project: str, domain: str, name: str, version: str, inputs: Dict[str, Type], outputs: Dict[str, Type]
):
super().__init__(WorkflowReference(project, domain, name, version), inputs, outputs)
def reference_workflow(
project: str,
domain: str,
name: str,
version: str,
) -> Callable[[Callable[..., Any]], ReferenceWorkflow]:
"""
A reference workflow is a pointer to a workflow that already exists on your Flyte installation. This
object will not initiate a network call to Admin, which is why the user is asked to provide the expected interface.
If at registration time the interface provided causes an issue with compilation, an error will be returned.
"""
def wrapper(fn) -> ReferenceWorkflow:
interface = transform_signature_to_interface(inspect.signature(fn))
return ReferenceWorkflow(project, domain, name, version, interface.inputs, interface.outputs)
return wrapper
| 46.663239 | 129 | 0.675518 | 1 | 1.9131 | [
-0.03312939777970314,
0.0344063937664032,
-0.003140535205602646,
-0.010014411993324757,
-0.02587258443236351,
0.02354920655488968,
-0.04476261883974075,
0.005459308158606291,
0.0017114848596975207,
0.0025206522550433874,
0.017487501725554466,
0.014495790004730225,
0.043772608041763306,
-0.020589403808116913,
-0.022839197888970375,
-0.014543235301971436,
-0.08139481395483017,
0.03911973163485527,
-0.007223848253488541,
-0.01743302121758461,
-0.006648888345807791,
0.01755889505147934,
-0.03437308222055435,
-0.0007982669048942626,
-0.011122025549411774,
0.0018572378903627396,
0.008771603927016258,
0.033706773072481155,
0.00798671692609787,
-0.005119817331433296,
0.011347094550728798,
-0.01870868168771267,
0.030892927199602127,
-0.01718714088201523,
-0.003973493818193674,
0.015809904783964157,
0.0047098430804908276,
0.025046037510037422,
0.017827719449996948,
-0.0006505706696771085,
-0.02846672013401985,
-0.012175790034234524,
-0.018461648374795914,
-0.0006995195872150362,
0.021577589213848114,
0.021020233631134033,
0.023044103756546974,
0.005663328804075718,
-0.02885347418487072,
0.015426757745444775,
-0.009982743300497532,
0.008684777654707432,
0.01717282086610794,
0.008099766448140144,
-0.012952767312526703,
-0.023180047050118446,
0.0004878186446148902,
0.0026195873506367207,
-0.02753910794854164,
-0.017977533861994743,
-0.0035026061814278364,
-0.01671377569437027,
0.03339999169111252,
-0.008555182255804539,
-0.005327149759978056,
-0.030797353014349937,
0.0077514625154435635,
-0.006519651971757412,
-0.044736091047525406,
-0.009580614976584911,
-0.01546557154506445,
-0.008929591625928879,
0.016528042033314705,
0.01169064175337553,
-0.012993993237614632,
0.0012064296752214432,
0.013945215381681919,
-0.021806880831718445,
-0.027316922321915627,
-0.0027592675760388374,
-0.022085677832365036,
0.04636106640100479,
0.006919297389686108,
0.018917134031653404,
0.02862507291138172,
0.03840649500489235,
0.05382704362273216,
-0.04103623330593109,
0.024533594027161598,
0.028802111744880676,
-0.027684692293405533,
-0.004582255147397518,
0.03457313030958176,
-0.005946721415966749,
0.007318753283470869,
-0.011934507638216019,
0.018066884949803352,
0.020935092121362686,
0.04498252645134926,
0.009828056208789349,
0.04391319677233696,
-0.013748226687312126,
0.01120810303837061,
-0.003039703704416752,
-0.023876428604125977,
-0.0071704210713505745,
-0.05839155986905098,
-0.0019653469789773226,
-0.013562108390033245,
-0.022600099444389343,
-0.01679190620779991,
0.016404561698436737,
-0.027791481465101242,
-0.013583223335444927,
0.004280262626707554,
-0.046320728957653046,
0.04890646040439606,
-0.0039740088395774364,
-0.010090751573443413,
-0.003771435935050249,
-0.011839001439511776,
-0.0019519447814673185,
0.018075762316584587,
-0.002106963424012065,
-0.024517059326171875,
0.07119815051555634,
-0.014706194400787354,
0.018877284601330757,
0.000023645985493203625,
0.019885515794157982,
-0.03878101333975792,
-0.005049627274274826,
-0.0142753841355443,
-0.022487729787826538,
0.01679183542728424,
0.00044603386777453125,
-0.020455747842788696,
0.007666673976927996,
-0.03671299293637276,
0.02133321762084961,
0.01968882419168949,
-0.024064674973487854,
0.01955599896609783,
0.014174971729516983,
0.0007636781083419919,
-0.02339954487979412,
-0.0018114305566996336,
0.002613790100440383,
0.0016175395576283336,
-0.024081340059638023,
-0.01423981785774231,
-0.010082755237817764,
-0.0093760434538126,
0.06864647567272186,
-0.021970191970467567,
-0.0029801144264638424,
-0.0072093503549695015,
-0.027035370469093323,
0.003148280084133148,
0.02058691345155239,
-0.02709091082215309,
-0.0007449251133948565,
-0.016237374395132065,
0.025840425863862038,
-0.0013035050360485911,
0.0330132395029068,
-0.021208124235272408,
0.04488936811685562,
-0.05355090647935867,
0.0029044521506875753,
-0.013468586839735508,
-0.0018656429601833224,
-0.02691192366182804,
-0.009065276011824608,
-0.004726001061499119,
0.0017035563942044973,
0.0006664464599452913,
-0.019553592428565025,
0.03263767063617706,
0.0015352123882621527,
-0.004476917441934347,
0.008672622963786125,
0.03871770203113556,
0.03459441661834717,
0.017825031653046608,
0.04401016607880592,
0.005279880482703447,
-0.0312286876142025,
0.027510367333889008,
-0.01638306863605976,
0.01612994074821472,
0.03793548047542572,
0.015474696643650532,
-0.015781080350279808,
-0.025021452456712723,
-0.01917552761733532,
0.0090844901278615,
-0.015718651935458183,
-0.007110422011464834,
0.03931592032313347,
-0.013057481497526169,
-0.015049582347273827,
-0.016330663114786148,
0.027234086766839027,
-0.02173939347267151,
-0.015061574056744576,
-0.7387797236442566,
0.0001676982647040859,
0.017828628420829773,
-0.004823695868253708,
-0.011304451152682304,
0.010281054303050041,
-0.022844232618808746,
0.013858715072274208,
-0.07624268531799316,
-0.005938814487308264,
0.002102377824485302,
-0.013945872895419598,
-0.028582364320755005,
0.013945593498647213,
0.013921993784606457,
-0.018228454515337944,
0.006308333016932011,
0.003983283881098032,
0.0264571625739336,
0.000022909051040187478,
0.03004918247461319,
0.013710033148527145,
-0.002917030593380332,
-0.005775418598204851,
-0.00933134276419878,
-0.03230936825275421,
0.024616772308945656,
-0.05860041454434395,
-0.013203548267483711,
0.05083880573511124,
0.014951126649975777,
-0.0074658202938735485,
0.03638942539691925,
-0.005451449658721685,
-0.011108416132628918,
-0.019883984699845314,
0.016207370907068253,
-0.020882507786154747,
-0.028373798355460167,
-0.0012700955849140882,
-0.03327259048819542,
-0.016071539372205734,
-0.008004974573850632,
-0.02686980552971363,
-0.03321492671966553,
0.01677033118903637,
-0.0020597095135599375,
-0.043104201555252075,
-0.013527682051062584,
0.015835601836442947,
-0.01656513288617134,
-0.02815614454448223,
-0.010348333045840263,
-0.03905494138598442,
-0.0036194236017763615,
0.01467589195817709,
0.05741199851036072,
0.003997039515525103,
0.001288934494368732,
0.039581019431352615,
0.03885640949010849,
0.03897390514612198,
0.010971101000905037,
0.0043529062531888485,
-0.018193822354078293,
-0.0035594592336565256,
-0.04220420867204666,
0.015805689617991447,
-0.01748441532254219,
-0.011075178161263466,
0.01852601394057274,
0.006458447780460119,
0.011835222132503986,
-0.010383141227066517,
0.012787729501724243,
0.004425919149070978,
-0.027128634974360466,
-0.03782190755009651,
-0.026194903999567032,
-0.03352605551481247,
-0.025616763159632683,
0.02552555315196514,
0.02118758298456669,
-0.014154458418488503,
-0.021581541746854782,
-0.023993132635951042,
-0.01852872408926487,
-0.02560834027826786,
0.017901545390486717,
0.02013440802693367,
0.026255270466208458,
-0.031484734266996384,
-0.012659888714551926,
-0.012293958105146885,
0.010848051868379116,
0.006607833318412304,
0.019184432923793793,
0.07295989990234375,
-0.0058402917347848415,
0.015422197058796883,
-0.01139021199196577,
-0.00859164446592331,
0.012733370997011662,
0.04850734770298004,
0.0014902304392307997,
0.01258134562522173,
-0.02196011133491993,
-0.007555575110018253,
0.011118659749627113,
-0.05810465291142464,
0.020710162818431854,
-0.021769501268863678,
-0.024062758311629295,
0.011845218949019909,
0.014018942601978779,
-0.011657873168587685,
-0.008595466613769531,
-0.010950258933007717,
0.02998197264969349,
0.020146813243627548,
-0.025675665587186813,
0.04295383393764496,
-0.01455098669975996,
0.0021171164698898792,
0.01171722263097763,
0.03257788345217705,
0.006949892267584801,
-0.0015356465009972453,
0.00500811031088233,
-0.02349918521940708,
-0.01724891923367977,
0.006879124324768782,
-0.007566182408481836,
-0.027501942589879036,
-0.010831796564161777,
-0.022084064781665802,
-0.017377713695168495,
-0.024055467918515205,
0.012704867869615555,
0.012167440727353096,
0.01904314011335373,
-0.010666219517588615,
-0.04202738776803017,
-0.03955192491412163,
0.01964140310883522,
-0.017075806856155396,
-0.010933621786534786,
-0.0013091572327539325,
0.021413858979940414,
-0.03458366543054581,
-0.019011901691555977,
-0.007256843615323305,
0.01655527576804161,
-0.005087927915155888,
-0.009346232749521732,
0.02006978914141655,
-0.02958177961409092,
-0.004633645992726088,
0.04022003337740898,
0.012653839774429798,
-0.02500566467642784,
-0.01943717524409294,
-0.027656445279717445,
-0.0016547481063753366,
-0.016082998365163803,
0.00526053924113512,
0.01920304074883461,
0.05092360079288483,
-0.013472693040966988,
0.016044937074184418,
-0.012175660580396652,
0.014756021089851856,
0.031323082745075226,
0.03355882689356804,
-0.0168292298913002,
-0.030691055580973625,
0.002923030173406005,
-0.04501347988843918,
-0.025806011632084846,
0.025403587147593498,
0.04559905454516411,
-0.03693205490708351,
-0.003180988598614931,
-0.018731143325567245,
0.007499448023736477,
0.028467316180467606,
0.0023978701792657375,
0.021171435713768005,
0.013241274282336235,
0.017795147374272346,
0.007119783200323582,
0.0326673723757267,
-0.024479353800415993,
-0.012506299652159214,
-0.035873621702194214,
0.02152920886874199,
-0.05573292449116707,
0.008790574967861176,
0.02784891612827778,
0.03358447924256325,
-0.000922161852940917,
-0.007696584798395634,
-0.011255910620093346,
-0.00045219651656225324,
0.013088734820485115,
0.060884710401296616,
0.022782832384109497,
0.006006026640534401,
0.007451004348695278,
0.0033798785880208015,
-0.022215384989976883,
-0.02129044383764267,
0.009286177344620228,
0.030835740268230438,
-0.047358524054288864,
0.03736406937241554,
-0.03134308382868767,
0.0014849533326923847,
-0.011380808427929878,
-0.018681416288018227,
-0.024610430002212524,
-0.014594662003219128,
0.01572386920452118,
-0.005607019178569317,
0.0027105906046926975,
0.028243865817785263,
-0.0012652610894292593,
0.004819118417799473,
-0.029178358614444733,
-0.014460382983088493,
0.01112090703099966,
-0.04752636328339577,
0.020205171778798103,
-0.023343173786997795,
-0.02038467489182949,
-0.005294623784720898,
-0.010858320631086826,
-0.03626251220703125,
0.027454417198896408,
-0.018478499725461006,
0.02714572288095951,
-0.04736335948109627,
-0.04840140789747238,
-0.018358519300818443,
-0.023887092247605324,
0.009092339314520359,
0.02139519527554512,
-0.01639792136847973,
-0.021604590117931366,
0.010586750693619251,
0.0026691455859690905,
0.04062411189079285,
0.0284211877733469,
-0.00946760643273592,
0.015656020492315292,
-0.03200183063745499,
-0.0046195038594305515,
0.005854614544659853,
0.03969603776931763,
0.013313963077962399,
0.0020082644186913967,
-0.05833593010902405,
-0.005469887983053923,
0.04897496849298477,
0.011529069393873215,
-0.021035443991422653,
0.04252643138170242,
-0.02961321547627449,
-0.038375549018383026,
0.041214652359485626,
-0.03921069577336311,
-0.0010260764975100756,
-0.011746437288820744,
-0.022170210257172585,
0.012334904633462429,
0.0085096200928092,
0.03843235224485397,
-0.01691354066133499,
-0.005427511874586344,
0.05085522308945656,
-0.01529647782444954,
0.006518085021525621,
0.017689978703856468,
0.0003503609332256019,
0.021146386861801147,
0.019243363291025162,
-0.004792778752744198,
-0.01737762801349163,
-0.026519175618886948,
-0.0010385912610217929,
-0.0050927395932376385,
0.004009755328297615,
0.03282938897609711,
0.019653944298624992,
-0.004348998889327049,
0.028473371639847755,
0.014567548409104347,
-0.042813532054424286,
0.021432925015687943,
-0.0015314590418711305,
0.01367874350398779,
-0.006529805716127157,
-0.011267057619988918,
0.08250907063484192,
0.02449982427060604,
-0.019407112151384354,
0.004671610426157713,
-0.018855761736631393,
0.013170314021408558,
0.009408059529960155,
0.018231116235256195,
0.07933710515499115,
-0.0011098753893747926,
-0.011724273674190044,
0.004672979936003685,
0.027397286146879196,
0.025737157091498375,
0.005279399920254946,
-0.00117996905464679,
-0.006102667655795813,
-0.01777191273868084,
0.03955422714352608,
-0.022987091913819313,
-0.018318556249141693,
0.00125130673404783,
-0.006532601080834866,
-0.05117875337600708,
0.004364539869129658,
0.007695675361901522,
-0.019515682011842728,
-0.02672610990703106,
-0.04487726092338562,
0.003999054431915283,
0.0005228549125604331,
0.005047100130468607,
-0.007617617957293987,
-0.014952469617128372,
0.003423291025683284,
0.01046418584883213,
0.033262286335229874,
-0.0023012880701571703,
0.026896897703409195,
0.025249972939491272,
-0.016044894233345985,
-0.01089276373386383,
-0.004453515168279409,
0.015031381510198116,
0.08780273050069809,
0.016764845699071884,
0.031158262863755226,
0.004831106401979923,
-0.00753768440335989,
-0.0007115221815183759,
-0.043303970247507095,
0.0005715853767469525,
-0.03740663826465607,
-0.0354301743209362,
0.022174235433340073,
0.007002954371273518,
0.00603925995528698,
-0.02831367217004299,
0.004773039370775223,
0.03130001202225685,
0.03621486946940422,
0.0025442945770919323,
-0.008323133923113346,
-0.004922480788081884,
-0.014268186874687672,
0.01180382538586855,
0.016593944281339645,
-0.0065858568996191025,
0.0018038568086922169,
0.01106326375156641,
0.014153347350656986,
0.030392233282327652,
0.007058761548250914,
0.014622900635004044,
-0.011160919442772865,
-0.0359189510345459,
0.02986825816333294,
-0.027612673118710518,
-0.02092539519071579,
0.012350436300039291,
-0.05196951702237129,
0.02679174765944481,
-0.06337036192417145,
-0.0036499500274658203,
0.017268070951104164,
-0.014091521501541138,
-0.009469755925238132,
-0.021326038986444473,
-0.0224367193877697,
0.03595450147986412,
0.024778705090284348,
-0.01016340684145689,
-0.029960550367832184,
-0.0049034422263503075,
0.00969176460057497,
-0.034418608993291855,
-0.005554644390940666,
-0.0005704562645405531,
0.0025643245317041874,
0.024340461939573288,
-0.0254142377525568,
0.015706809237599373,
-0.03446771204471588,
-0.011680711060762405,
-0.034186139702796936,
0.0036893873475492,
-0.001573439920321107,
0.0019004370551556349,
0.026589039713144302,
0.024205932393670082,
0.0014113351935520768,
0.020851479843258858,
-0.001629756297916174,
-0.00215331744402647,
0.019968761131167412,
-0.01269132737070322,
0.023739928379654884,
0.025730924680829048,
0.0359579361975193,
-0.013234848156571388,
0.003669390454888344,
-0.00013310297799762338,
0.03205221891403198,
0.00891050137579441,
-0.03106057457625866,
-0.0313853845000267,
-0.016018876805901527,
-0.0016350869555026293,
0.030013540759682655,
-0.017148753628134727,
-0.0331442728638649,
0.0492582805454731,
-0.015789585188031197,
-0.01025394443422556,
0.005625471938401461,
-0.010882239788770676,
0.021838610991835594,
-0.009172976948320866,
-0.005018486641347408,
-0.00006765872240066528,
0.00636232690885663,
0.02897290512919426,
-0.08219888806343079,
0.017084194347262383,
-0.0027825762517750263,
-0.021780507639050484,
-0.03143169358372688,
-0.01726669631898403,
0.009956744499504566,
-0.007952236570417881,
0.012298260815441608,
0.0061391787603497505,
0.02166590839624405,
0.031945571303367615,
-0.03184087201952934,
0.02270173281431198,
0.02214939333498478,
0.016780497506260872,
0.008312735706567764,
0.004418073687702417,
0.01039540022611618,
0.044082533568143845,
0.0311726126819849,
-0.02856563590466976,
0.027633702382445335,
-0.004292618483304977,
0.01446566917002201,
-0.01874096691608429,
0.013857975602149963,
0.0004349026130512357,
0.004327334463596344,
0.0038111608009785414,
0.028673658147454262,
-0.022834492847323418,
-0.01203667651861906,
-0.004769669380038977,
-0.02856224961578846,
-0.026667989790439606,
0.021763432770967484,
0.00937693938612938,
-0.006006998009979725,
0.014573578722774982,
0.0018691561417654157,
0.000914685137104243,
0.006939499173313379,
-0.011951619759202003,
0.024412140250205994,
-0.030224738642573357,
-0.02518799714744091,
-0.0325048565864563,
0.021340224891901016,
-0.003216757904738188,
-0.03512975946068764,
-0.019316259771585464,
-0.03794325143098831,
0.03458162769675255,
-0.007968878373503685,
-0.03068874217569828,
0.013471951708197594,
0.002970730420202017,
-0.0180400088429451,
0.007918703369796276,
0.003128655022010207,
0.07317263633012772,
0.018564695492386818,
-0.03188415244221687,
-0.0034825485199689865,
-0.01611359231173992,
0.02235725149512291,
-0.037969328463077545,
-0.004041093401610851,
0.03977511078119278,
0.013655710965394974,
0.001639475580304861,
-0.01812266744673252,
0.009278041310608387,
-0.023166928440332413,
-0.006546929944306612,
0.027560174465179443,
-0.021436329931020737,
-0.019487539306282997,
0.029964113608002663,
0.004153162240982056,
-0.04455409571528435,
-0.011649621650576591,
0.023110512644052505,
0.03298703581094742,
-0.004424707964062691,
-0.004407026804983616,
-0.01505502313375473,
0.0244083683937788,
0.015814492478966713,
-0.06992026418447495,
-0.022502603009343147,
0.08613302558660507,
-0.04165428504347801,
-0.026558972895145416,
0.004745675250887871,
0.028704801574349403,
-0.0016854347195476294,
0.02799951285123825,
-0.033479753881692886,
0.025660095736384392,
-0.0025187700521200895,
0.016065729781985283,
0.036743685603141785,
0.004115922376513481,
0.006539593450725079,
0.033743035048246384,
0.054334063082933426,
0.014460430480539799,
-0.028089646250009537,
-0.05210775136947632,
-0.010746791958808899,
0.029811551794409752,
0.012897813692688942,
-0.030384505167603493,
-0.005898555275052786,
0.020491736009716988
] |
8a47b1a4041d7e6d082433e91d3935c95f8c494b | 12,125 | py | Python | nemo/collections/asr/parts/numba/rnnt_loss/rnnt_numpy.py | madhukarkm/NeMo | 648c97f076147684bee6aaada209f2f20adcaf5d | [
"Apache-2.0"
] | 4,145 | 2019-09-13T08:29:43.000Z | 2022-03-31T18:31:44.000Z | nemo/collections/asr/parts/numba/rnnt_loss/rnnt_numpy.py | madhukarkm/NeMo | 648c97f076147684bee6aaada209f2f20adcaf5d | [
"Apache-2.0"
] | 2,031 | 2019-09-17T16:51:39.000Z | 2022-03-31T23:52:41.000Z | nemo/collections/asr/parts/numba/rnnt_loss/rnnt_numpy.py | madhukarkm/NeMo | 648c97f076147684bee6aaada209f2f20adcaf5d | [
"Apache-2.0"
] | 1,041 | 2019-09-13T10:08:21.000Z | 2022-03-30T06:37:38.000Z | # Copyright (c) 2021, NVIDIA CORPORATION. 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.
#
# Copyright 2018-2019, Mingkun Huang
#
# 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 numpy as np
import torch
from torch.autograd import Function, Variable
from torch.nn import Module
def check_type(var, t, name):
if var.dtype is not t:
raise TypeError("{} must be {}".format(name, t))
def check_contiguous(var, name):
if not var.is_contiguous():
raise ValueError("{} must be contiguous".format(name))
def check_dim(var, dim, name):
if len(var.shape) != dim:
raise ValueError("{} must be {}D".format(name, dim))
def certify_inputs(log_probs, labels, lengths, label_lengths):
# check_type(log_probs, torch.float32, "log_probs")
check_type(labels, torch.int32, "labels")
check_type(label_lengths, torch.int32, "label_lengths")
check_type(lengths, torch.int32, "lengths")
check_contiguous(log_probs, "log_probs")
check_contiguous(labels, "labels")
check_contiguous(label_lengths, "label_lengths")
check_contiguous(lengths, "lengths")
if lengths.shape[0] != log_probs.shape[0]:
raise ValueError(
f"Must have a length per example. "
f"Given lengths dim: {lengths.shape[0]}, "
f"Log probs dim : {log_probs.shape[0]}"
)
if label_lengths.shape[0] != log_probs.shape[0]:
raise ValueError(
"Must have a label length per example. "
f"Given label lengths dim : {label_lengths.shape[0]}, "
f"Log probs dim : {log_probs.shape[0]}"
)
check_dim(log_probs, 4, "log_probs")
check_dim(labels, 2, "labels")
check_dim(lengths, 1, "lenghts")
check_dim(label_lengths, 1, "label_lenghts")
max_T = torch.max(lengths)
max_U = torch.max(label_lengths)
T, U = log_probs.shape[1:3]
if T != max_T:
raise ValueError(f"Input length mismatch! Given T: {T}, Expected max T from input lengths: {max_T}")
if U != max_U + 1:
raise ValueError(f"Output length mismatch! Given U: {U}, Expected max U from target lengths: {max_U} + 1")
def _assert_no_grad(tensor):
assert not tensor.requires_grad, (
"gradients only computed for log_probs - please " "mark other tensors as not requiring gradients"
)
def forward_pass(log_probs, labels, blank):
"""
Computes probability of the forward variable alpha.
Args:
log_probs: Tensor of shape [T, U, V+1]
labels: Labels of shape [B, U]
blank: Index of the blank token.
Returns:
A tuple of the forward variable probabilities - alpha of shape [T, U]
and the log likelihood of this forward step.
"""
T, U, _ = log_probs.shape
alphas = np.zeros((T, U), dtype='f')
for t in range(1, T):
alphas[t, 0] = alphas[t - 1, 0] + log_probs[t - 1, 0, blank]
for u in range(1, U):
alphas[0, u] = alphas[0, u - 1] + log_probs[0, u - 1, labels[u - 1]]
for t in range(1, T):
for u in range(1, U):
no_emit = alphas[t - 1, u] + log_probs[t - 1, u, blank]
emit = alphas[t, u - 1] + log_probs[t, u - 1, labels[u - 1]]
alphas[t, u] = np.logaddexp(emit, no_emit)
loglike = alphas[T - 1, U - 1] + log_probs[T - 1, U - 1, blank]
return alphas, loglike
def backward_pass(log_probs, labels, blank):
"""
Computes probability of the backward variable beta.
Args:
log_probs: Tensor of shape [T, U, V+1]
labels: Labels of shape [B, U]
blank: Index of the blank token.
Returns:
A tuple of the backward variable probabilities - beta of shape [T, U]
and the log likelihood of this backward step.
"""
T, U, _ = log_probs.shape
betas = np.zeros((T, U), dtype='f')
betas[T - 1, U - 1] = log_probs[T - 1, U - 1, blank]
for t in reversed(range(T - 1)):
betas[t, U - 1] = betas[t + 1, U - 1] + log_probs[t, U - 1, blank]
for u in reversed(range(U - 1)):
betas[T - 1, u] = betas[T - 1, u + 1] + log_probs[T - 1, u, labels[u]]
for t in reversed(range(T - 1)):
for u in reversed(range(U - 1)):
no_emit = betas[t + 1, u] + log_probs[t, u, blank]
emit = betas[t, u + 1] + log_probs[t, u, labels[u]]
betas[t, u] = np.logaddexp(emit, no_emit)
return betas, betas[0, 0]
def compute_gradient(log_probs, alphas, betas, labels, blank, fastemit_lambda):
"""
Computes the gradients of the log_probs with respect to the log probability of this step occuring.
Args:
Args:
log_probs: Tensor of shape [T, U, V+1]
alphas: Tensor of shape [T, U] which represents the forward variable.
betas: Tensor of shape [T, U] which represents the backward variable.
labels: Labels of shape [B, U]
blank: Index of the blank token.
Returns:
Gradients of shape [T, U, V+1] with respect to the forward log probability
"""
T, U, _ = log_probs.shape
grads = np.full(log_probs.shape, -float("inf"))
log_like = betas[0, 0] # == alphas[T - 1, U - 1] + betas[T - 1, U - 1]
# // grad to last blank transition
grads[T - 1, U - 1, blank] = alphas[T - 1, U - 1]
grads[: T - 1, :, blank] = alphas[: T - 1, :] + betas[1:, :]
# // grad to label transition
for u, l in enumerate(labels):
grads[:, u, l] = alphas[:, u] + betas[:, u + 1]
grads = -np.exp(grads + log_probs - log_like)
if fastemit_lambda > 0.0:
for u, l in enumerate(labels):
grads[:, u, l] = (1.0 + fastemit_lambda) * grads[:, u, l]
return grads
def fastemit_regularization(log_probs, labels, alphas, betas, blank, fastemit_lambda):
"""
Describes the computation of FastEmit regularization from the paper -
[FastEmit: Low-latency Streaming ASR with Sequence-level Emission Regularization](https://arxiv.org/abs/2010.11148)
Args:
log_probs: Tensor of shape [T, U, V+1]
labels: Unused. Labels of shape [B, U]
alphas: Tensor of shape [T, U] which represents the forward variable.
betas: Unused. Tensor of shape [T, U] which represents the backward variable.
blank: Index of the blank token.
fastemit_lambda: Float scaling factor for FastEmit regularization.
Returns:
The regularized negative log likelihood - lambda * P˜(At, u|x)
"""
# General calculation of the fastemit regularization alignments
T, U, _ = log_probs.shape
# alignment = np.zeros((T, U), dtype='float32')
#
# for t in range(0, T):
# alignment[t, U - 1] = alphas[t, U - 1] + betas[t, U - 1]
#
# for t in range(0, T):
# for u in range(0, U - 1):
# emit = alphas[t, u] + log_probs[t, u, labels[u]] + betas[t, u + 1]
# alignment[t, u] = emit
# reg = fastemit_lambda * (alignment[T - 1, U - 1])
# The above is equivalent to below, without need of computing above
# reg = fastemit_lambda * (alphas[T - 1, U - 1] + betas[T - 1, U - 1])
# The above is also equivalent to below, without need of computing the betas alignment matrix
reg = fastemit_lambda * (alphas[T - 1, U - 1] + log_probs[T - 1, U - 1, blank])
return -reg
def transduce(log_probs, labels, blank=0, fastemit_lambda=0.0):
"""
Args:
log_probs: 3D array with shape
[input len, output len + 1, vocab size]
labels: 1D array with shape [output time steps]
blank: Index of the blank token.
fastemit_lambda: Float scaling factor for FastEmit regularization.
Returns:
float: The negative log-likelihood
3D array: Gradients with respect to the
unnormalized input actications
2d arrays: Alphas matrix (TxU)
2d array: Betas matrix (TxU)
"""
alphas, ll_forward = forward_pass(log_probs, labels, blank)
betas, ll_backward = backward_pass(log_probs, labels, blank)
grads = compute_gradient(log_probs, alphas, betas, labels, blank, fastemit_lambda)
return -ll_forward, grads, alphas, betas
def transduce_batch(log_probs, labels, flen, glen, blank=0, fastemit_lambda=0.0):
"""
Compute the transducer loss of the batch.
Args:
log_probs: [B, T, U, V+1]. Activation matrix normalized with log-softmax.
labels: [B, U+1] - ground truth labels with <SOS> padded as blank token in the beginning.
flen: Length vector of the acoustic sequence.
glen: Length vector of the target sequence.
blank: Id of the blank token.
fastemit_lambda: Float scaling factor for FastEmit regularization.
Returns:
Batch of transducer forward log probabilities (loss) and the gradients of the activation matrix.
"""
grads = np.zeros_like(log_probs)
costs = []
for b in range(log_probs.shape[0]):
t = int(flen[b])
u = int(glen[b]) + 1
ll, g, alphas, betas = transduce(log_probs[b, :t, :u, :], labels[b, : u - 1], blank, fastemit_lambda)
grads[b, :t, :u, :] = g
reg = fastemit_regularization(
log_probs[b, :t, :u, :], labels[b, : u - 1], alphas, betas, blank, fastemit_lambda
)
ll += reg
costs.append(ll)
return costs, grads
class _RNNT(Function):
@staticmethod
def forward(ctx, acts, labels, act_lens, label_lens, blank, fastemit_lambda):
costs, grads = transduce_batch(
acts.detach().cpu().numpy(),
labels.cpu().numpy(),
act_lens.cpu().numpy(),
label_lens.cpu().numpy(),
blank,
fastemit_lambda,
)
costs = torch.FloatTensor([sum(costs)])
grads = torch.Tensor(grads).to(acts)
ctx.grads = grads
return costs
@staticmethod
def backward(ctx, grad_output):
return ctx.grads, None, None, None, None, None
class RNNTLoss(Module):
"""
Parameters:
`blank_label` (int): default 0 - label index of blank token
fastemit_lambda: Float scaling factor for FastEmit regularization.
"""
def __init__(self, blank: int = 0, fastemit_lambda: float = 0.0):
super(RNNTLoss, self).__init__()
self.blank = blank
self.fastemit_lambda = fastemit_lambda
self.rnnt = _RNNT.apply
def forward(self, acts, labels, act_lens, label_lens):
assert len(labels.size()) == 2
_assert_no_grad(labels)
_assert_no_grad(act_lens)
_assert_no_grad(label_lens)
certify_inputs(acts, labels, act_lens, label_lens)
acts = torch.nn.functional.log_softmax(acts, -1)
return self.rnnt(acts, labels, act_lens, label_lens, self.blank, self.fastemit_lambda)
if __name__ == '__main__':
loss = RNNTLoss(fastemit_lambda=0.01)
torch.manual_seed(0)
acts = torch.randn(1, 2, 5, 3)
labels = torch.tensor([[0, 2, 1, 2]], dtype=torch.int32)
act_lens = torch.tensor([2], dtype=torch.int32)
label_lens = torch.tensor([len(labels[0])], dtype=torch.int32)
loss_val = loss(acts, labels, act_lens, label_lens)
| 35.557185 | 119 | 0.628784 | 1 | 2.1861 | [
-0.034597694873809814,
0.06673533469438553,
0.01534244418144226,
0.0025236865039914846,
-0.012278172187507153,
-0.027242522686719894,
-0.006663865875452757,
-0.007174727972596884,
0.005413466598838568,
0.0030163356568664312,
0.005797623656690121,
0.002259036060422659,
-0.003913503140211105,
0.020278096199035645,
-0.0033687890972942114,
-0.006168054416775703,
0.24818524718284607,
-0.05179895460605621,
0.01366520393639803,
0.036166299134492874,
-0.015373569913208485,
0.009031740948557854,
-0.013436229899525642,
0.047014422714710236,
0.0012238292256370187,
-0.027771105989813805,
0.061480846256017685,
0.017940346151590347,
0.0038548442535102367,
-0.00008252223778981715,
-0.0052412692457437515,
0.015652475878596306,
-0.019628453999757767,
-0.004313813988119364,
-0.006378122605383396,
0.02800608240067959,
0.002278123050928116,
-0.09360725432634354,
0.03841322287917137,
0.001886354060843587,
0.0419527068734169,
-0.019271884113550186,
-0.0375090166926384,
-0.05313911288976669,
-0.006611301563680172,
-0.017098359763622284,
-0.0002957422111649066,
0.015912888571619987,
0.04336805269122124,
-0.00725590530782938,
-0.01422848366200924,
0.07768605649471283,
0.014000767841935158,
-0.023173626512289047,
0.009789510630071163,
0.014066907577216625,
-0.02493070811033249,
-0.059719134122133255,
-0.034736815840005875,
-0.010067309252917767,
-0.06594350188970566,
0.012580417096614838,
-0.0070356219075620174,
0.0066328952088952065,
-0.03442201018333435,
0.005064475815743208,
-0.04009983316063881,
0.009612482972443104,
0.05822503939270973,
-0.004675210453569889,
0.01923062652349472,
-0.016610626131296158,
-0.03013327158987522,
0.0473271980881691,
0.0009310233872383833,
-0.02362290397286415,
-0.028696352615952492,
0.0009731592144817114,
0.02647811733186245,
0.013980868272483349,
-0.0026320156175643206,
0.0692766010761261,
-0.023540707305073738,
0.0005545226740650833,
0.01527471374720335,
0.05937056243419647,
-0.005334892310202122,
-0.05231359228491783,
0.04367728903889656,
0.029148070141673088,
-0.02469581924378872,
-0.02477804571390152,
-0.03306557610630989,
0.01774744689464569,
-0.015560353174805641,
-0.061465758830308914,
0.009065883234143257,
-0.012524480000138283,
0.04452952370047569,
0.015137183479964733,
0.00590604217723012,
0.008536551147699356,
-0.04422006756067276,
0.014670888893306255,
-0.029626086354255676,
-0.01660638116300106,
-0.03160529583692551,
0.010928723029792309,
-0.0007152445032261312,
0.004265574738383293,
-0.07792894542217255,
0.005099394824355841,
0.021981969475746155,
-0.02741653472185135,
-0.01650639809668064,
-0.041421666741371155,
0.012101700529456139,
0.016991134732961655,
0.006105139851570129,
0.04560951888561249,
-0.011449236422777176,
0.011767365969717503,
0.003939365968108177,
-0.00547326635569334,
0.001245010644197464,
-0.01903427205979824,
-0.03009170852601528,
-0.03827869892120361,
0.011833193711936474,
0.032795511186122894,
-0.04889186844229698,
0.004624429624527693,
0.013208952732384205,
0.005114416126161814,
0.009219465777277946,
-0.027562228962779045,
0.0031711619812995195,
-0.005887291859835386,
-0.020507613196969032,
-0.010813569650053978,
-0.03157379478216171,
0.005288025364279747,
0.013576439581811428,
-0.0009190310374833643,
0.020158831030130386,
-0.02827955223619938,
-0.022982921451330185,
0.002005929360166192,
-0.003489478724077344,
-0.010077022016048431,
0.007456958759576082,
0.0425516813993454,
-0.029014213010668755,
0.045010026544332504,
-0.008324398659169674,
0.007891182787716389,
0.004803641699254513,
-0.010307525284588337,
-0.012285497970879078,
0.032774679362773895,
-0.01530645415186882,
-0.026254290714859962,
0.009165402501821518,
0.037550188601017,
0.02505061775445938,
-0.03324996307492256,
-0.025451747700572014,
-0.0070318737998604774,
-0.018079377710819244,
-0.006094081327319145,
-0.010465269908308983,
-0.035903118550777435,
-0.028339259326457977,
0.007404420990496874,
0.0010299788555130363,
-0.026249950751662254,
0.06421219557523727,
-0.03400728106498718,
0.00995112955570221,
-0.02392464503645897,
0.0011264649219810963,
-0.0047880662605166435,
0.020814117044210434,
0.031066594645380974,
-0.017096832394599915,
0.04957966133952141,
-0.026894839480519295,
0.017499297857284546,
0.02388860285282135,
-0.005027318838983774,
0.005596772767603397,
0.006268588360399008,
0.003557383781298995,
-0.018319696187973022,
0.015651879832148552,
0.005478281062096357,
-0.002322450280189514,
0.004627490881830454,
-0.02289668284356594,
0.008918995968997478,
0.02090534195303917,
0.023607565090060234,
0.005441599991172552,
0.02419612742960453,
-0.014153813011944294,
0.03250131383538246,
-0.6629864573478699,
0.04722652956843376,
0.010364685207605362,
0.0010024039074778557,
-0.020262550562620163,
0.010788367129862309,
0.01177311223000288,
0.021083330735564232,
-0.00373140093870461,
-0.021523505449295044,
0.0072149839252233505,
-0.005459358915686607,
-0.029700353741645813,
0.022222021594643593,
0.047570616006851196,
-0.06438474357128143,
-0.02556254342198372,
-0.023734409362077713,
-0.058454133570194244,
0.007884489372372627,
0.00216376269236207,
0.02476162649691105,
-0.018732277676463127,
0.025727547705173492,
-0.01303889974951744,
-0.0032161336857825518,
0.027687443420290947,
0.015763243660330772,
0.015507186762988567,
0.004909147042781115,
0.008588231168687344,
0.03959254175424576,
-0.009414711967110634,
-0.006397715304046869,
-0.021416688337922096,
-0.027941308915615082,
0.009480222128331661,
-0.019250495359301567,
0.025493979454040527,
0.030742179602384567,
-0.019677888602018356,
-0.006030557677149773,
0.03326820582151413,
-0.03722052276134491,
-0.041837722063064575,
-0.009579433128237724,
-0.05380668491125107,
-0.027759235352277756,
0.007086799945682287,
-0.006760954391211271,
-0.035929303616285324,
-0.012483049184083939,
0.0028967878315597773,
0.008792064152657986,
-0.02213055081665516,
-0.023122776299715042,
-0.004194405861198902,
-0.0011276683071628213,
-0.023646941408514977,
-0.004387555178254843,
-0.018567699939012527,
-0.04843871295452118,
-0.016971025615930557,
0.00800403393805027,
-0.0037586758844554424,
0.010868929326534271,
0.02647080086171627,
-0.03553127869963646,
0.00718969339504838,
0.024126198142766953,
-0.036496710032224655,
-0.0027096765115857124,
-0.04095902293920517,
-0.00715696020051837,
-0.012957087717950344,
-0.00568403210490942,
0.027112556621432304,
0.014628328382968903,
-0.022199969738721848,
0.0024444228038191795,
0.00648533646017313,
-0.024191532284021378,
0.016955308616161346,
0.002056293888017535,
-0.023379258811473846,
0.005146465264260769,
0.0006341999978758395,
0.027709608897566795,
-0.03442820534110069,
0.019010890275239944,
-0.005628474522382021,
0.022275367751717567,
0.03279517963528633,
-0.030911395326256752,
0.012773782946169376,
0.05126010626554489,
-0.0002810335427056998,
0.05102794989943504,
0.02200426533818245,
-0.006731449160724878,
-0.034342989325523376,
-0.029908986762166023,
0.02400266006588936,
-0.026609793305397034,
-0.02375638298690319,
-0.0017153866356238723,
-0.027685420587658882,
-0.0024962928146123886,
-0.01886925660073757,
-0.02892732247710228,
0.013553694821894169,
-0.00862207356840372,
-0.0271274596452713,
0.022208040580153465,
-0.023047201335430145,
-0.002642399165779352,
-0.017102867364883423,
-0.06025015935301781,
-0.021379932761192322,
-0.004285507835447788,
0.00899412203580141,
-0.05765444412827492,
-0.013556302525103092,
-0.02925492264330387,
-0.02012866735458374,
0.011903523467481136,
-0.07943126559257507,
0.012441554106771946,
0.0147419897839427,
0.06926698982715607,
-0.06753987073898315,
-0.029560832306742668,
-0.0019133139867335558,
-0.020302971825003624,
-0.0014736548764631152,
-0.002118519274517894,
-0.008493345230817795,
-0.016622979193925858,
-0.0007804650813341141,
-0.021776413545012474,
-0.013754542917013168,
-0.0005623858887702227,
0.021144555881619453,
0.0019495696760714054,
0.005797637160867453,
0.0026187850162386894,
0.0067606461234390736,
-0.004043020773679018,
-0.013379202224314213,
-0.024916164577007294,
0.028616854920983315,
0.03381240740418434,
0.02790955826640129,
0.009877191856503487,
0.008126177825033665,
0.008148050867021084,
-0.019941264763474464,
0.014050424098968506,
0.028415851294994354,
0.043274637311697006,
-0.02452775649726391,
-0.054704323410987854,
0.008391992188990116,
0.012386848218739033,
-0.013718167319893837,
-0.0170256607234478,
-0.0038259520661085844,
0.01721188984811306,
-0.020376017317175865,
0.03136337175965309,
-0.022734414786100388,
-0.002921169623732567,
0.018833884969353676,
0.043419305235147476,
0.0025218718219548464,
0.04878649115562439,
-0.01630576141178608,
-0.025990337133407593,
-0.01382577046751976,
0.004503527656197548,
-0.013269547373056412,
0.02489183470606804,
-0.042725663632154465,
0.014749929308891296,
0.028686368837952614,
0.040410544723272324,
-0.027891358360648155,
-0.003373516723513603,
0.016749367117881775,
-0.013729562982916832,
-0.002141372300684452,
0.018474571406841278,
-0.031675875186920166,
-0.015475516207516193,
0.007157274521887302,
-0.011535988189280033,
-0.030734464526176453,
-0.008224421180784702,
-0.028410309925675392,
-0.028481464833021164,
0.0031195529736578465,
0.04891922324895859,
0.053811635822057724,
-0.02479635179042816,
0.025328639894723892,
0.051939625293016434,
-0.03873376175761223,
-0.021517351269721985,
0.020401068031787872,
0.045529723167419434,
0.03974664583802223,
-0.021790342405438423,
0.051834430545568466,
0.007672655396163464,
-0.016712399199604988,
0.01677362620830536,
-0.03716390207409859,
-0.03223937004804611,
0.039964377880096436,
-0.05040452256798744,
-0.053201232105493546,
-0.05307432636618614,
0.002505459124222398,
0.016492638736963272,
-0.01298742275685072,
-0.029200131073594093,
-0.02126225270330906,
-0.02166563831269741,
-0.008259647525846958,
-0.02430380880832672,
-0.007938801310956478,
-0.009677273221313953,
0.0016129984287545085,
-0.0019232694758102298,
0.008059905841946602,
0.015938589349389076,
-0.021554240956902504,
-0.0230662040412426,
-0.0004963284591212869,
-0.028676768764853477,
0.03229983150959015,
0.021011240780353546,
0.0076324897818267345,
0.01982785575091839,
0.03313707932829857,
-0.019893506541848183,
-0.010162526741623878,
-0.06115127354860306,
-0.013640030287206173,
-0.026970142498612404,
-0.0037245559506118298,
0.030782168731093407,
0.020451638847589493,
-0.007633611559867859,
0.03316565603017807,
-0.01487779151648283,
0.004996201954782009,
0.022611841559410095,
0.04013067111372948,
-0.025552984327077866,
-0.01085550244897604,
-0.014674868434667587,
-0.013141641393303871,
0.006635983008891344,
0.023066934198141098,
0.01407717540860176,
-0.006123299244791269,
-0.0028938748873770237,
0.0010655330261215568,
-0.004135497380048037,
-0.03688516467809677,
0.013375860638916492,
0.00544220395386219,
0.017668431624770164,
-0.013316651806235313,
0.010431153699755669,
0.0013728031190112233,
-0.02836710400879383,
0.012373044155538082,
0.08519553393125534,
-0.0027957307174801826,
0.021783120930194855,
0.011722697876393795,
0.02748824842274189,
-0.02036108635365963,
0.016077566891908646,
0.028768198564648628,
-0.003851962275803089,
-0.04692232981324196,
-0.006430010311305523,
0.015322688966989517,
-0.03361772000789642,
0.01567520946264267,
-0.014743111096322536,
0.036668986082077026,
0.0028661524411290884,
-0.01798345521092415,
0.008460445329546928,
0.013885704800486565,
-0.015087186358869076,
0.036450065672397614,
0.016484608873724937,
-0.0088794631883502,
0.031445056200027466,
0.02844025008380413,
0.02706609107553959,
-0.015136678703129292,
0.0030122315511107445,
0.0020642129238694906,
0.024681108072400093,
-0.003164855996146798,
0.04593517258763313,
0.012083814479410648,
0.026371458545327187,
-0.025421997532248497,
0.02800835110247135,
0.024565966799855232,
-0.00557827390730381,
0.04117865860462189,
-0.02430392988026142,
0.0019926028326153755,
0.028078299015760422,
-0.010693809017539024,
-0.014397776685655117,
0.005785718560218811,
-0.016426201909780502,
-0.04259496182203293,
0.0027598950546234846,
-0.040040649473667145,
-0.01693066768348217,
-0.018280645832419395,
-0.03288375213742256,
0.016762549057602882,
-0.024218549951910973,
-0.005068451631814241,
0.042173489928245544,
-0.007936225272715092,
0.021711274981498718,
0.014212018810212612,
0.016232391819357872,
0.038949154317379,
0.008316483348608017,
-0.02253073826432228,
0.008232858031988144,
0.030438782647252083,
-0.02306623011827469,
0.02307368628680706,
0.03388955071568489,
0.02245473302900791,
0.007870183326303959,
-0.0006930626113899052,
-0.014273714274168015,
-0.007159019820392132,
0.005304782185703516,
-0.01618223451077938,
0.008623830042779446,
0.02263106405735016,
-0.0018243290251120925,
0.03399690240621567,
0.0284548569470644,
-0.004764438606798649,
-0.019731571897864342,
-0.008710619062185287,
-0.020561804994940758,
-0.004381876904517412,
-0.027092181146144867,
0.017062200233340263,
-0.024431252852082253,
-0.019686542451381683,
0.04967457056045532,
0.013053905218839645,
-0.03941429778933525,
0.031492941081523895,
-0.014385244809091091,
-0.0028330550994724035,
-0.021215448155999184,
0.031276069581508636,
0.055956825613975525,
0.00696900999173522,
-0.03205264359712601,
-0.0023805771488696337,
0.039385732263326645,
0.027779104188084602,
-0.014786751009523869,
0.00806781742721796,
-0.0025325308088213205,
-0.0021374113857746124,
-0.000819147564470768,
-0.03321046009659767,
-0.03865418583154678,
0.02170727401971817,
-0.014193386770784855,
-0.006590789649635553,
0.03023122251033783,
-0.006406049244105816,
-0.0045798346400260925,
0.0009192905272357166,
-0.016922056674957275,
0.007777535822242498,
-0.023193402215838432,
0.014484518207609653,
0.017178025096654892,
0.03339558467268944,
-0.0281023271381855,
-0.0063317203894257545,
-0.03973940387368202,
0.029139885678887367,
-0.03318997472524643,
0.02297898754477501,
0.01597217656672001,
-0.03424418345093727,
0.007982754148542881,
-0.009174710139632225,
-0.024417564272880554,
-0.002977113239467144,
0.027239173650741577,
-0.02522776462137699,
0.028160756453871727,
-0.004939299542456865,
0.023723559454083443,
-0.018977563828229904,
0.029254579916596413,
-0.014492812566459179,
0.014817844144999981,
-0.012986229732632637,
0.011381273157894611,
0.016512945294380188,
0.011438547633588314,
0.010564400814473629,
0.03676852583885193,
-0.025381077080965042,
-0.009155722334980965,
-0.018803613260388374,
0.0015527872601523995,
0.010682933032512665,
0.0032285861670970917,
-0.03411306440830231,
-0.020886681973934174,
-0.022185085341334343,
-0.013293818570673466,
0.027114953845739365,
-0.005691823083907366,
0.03086763434112072,
0.02789047546684742,
0.02634171023964882,
-0.07792435586452484,
-0.006774482317268848,
0.02531873993575573,
0.006828897166997194,
-0.0034203119575977325,
0.039467401802539825,
-0.0005087220342829823,
0.013164326548576355,
0.014446842484176159,
-0.013236665166914463,
0.017262708395719528,
0.007095540873706341,
-0.0011720045004040003,
0.005515518132597208,
0.0254044309258461,
0.012393460609018803,
0.047390006482601166,
-0.016092360019683838,
-0.03058450296521187,
-0.008480058051645756,
0.011793550103902817,
0.03901718929409981,
-0.03307424113154411,
-0.0035200503189116716,
-0.010716338641941547,
-0.020098987966775894,
0.025752734392881393,
0.0021492294035851955,
0.03741823509335518,
0.030355051159858704,
0.01948622800409794,
0.006988209206610918,
0.004830564372241497,
0.013224104419350624,
-0.007005686406046152,
-0.03216021507978439,
0.025607779622077942,
0.0478709414601326,
0.03900084272027016,
0.013541235588490963,
-0.05082212761044502,
0.012054301798343658,
-0.04449007660150528,
-0.007627994753420353,
0.06000872328877449,
-0.03302501142024994,
-0.029438441619277,
-0.013448749668896198,
-0.011762802489101887,
0.021293438971042633,
-0.05387650430202484,
0.0136955501511693,
-0.04341621324419975,
0.02017705887556076,
-0.01231162529438734,
0.015800252556800842,
0.0016049447003751993,
0.008676765486598015,
-0.012039865367114544,
0.02682516723871231,
0.015062494203448296,
0.03622379153966904,
0.011566982604563236,
0.0022317240945994854,
0.03999505937099457,
-0.015475567430257797,
-0.0019775324035435915,
-0.042158566415309906,
-0.03250809758901596,
0.015023628249764442,
0.019244730472564697,
0.015456918627023697,
-0.030710166320204735,
0.00403735414147377,
0.0023347309324890375,
0.014466571621596813,
0.017003988847136497,
-0.04569451883435249,
-0.023015592247247696,
0.0036273933947086334,
0.002562152221798897,
-0.008316226303577423,
-0.027547167614102364,
0.01605924591422081,
-0.008061833679676056,
0.013913500122725964,
-0.016082746908068657,
0.01822746731340885,
0.022205213084816933,
-0.015183955430984497,
-0.032139308750629425,
0.027024462819099426,
0.07390331476926804,
-0.03021097369492054,
-0.013281941413879395,
0.013393283821642399,
0.0170561783015728,
-0.013996045105159283,
-0.012241877615451813,
-0.007885568775236607,
0.0038416963070631027,
0.002273011952638626,
0.046467479318380356,
0.024920670315623283,
0.0005486455629579723,
-0.02335220016539097,
-0.004614134784787893,
-0.014577734284102917,
-0.009531527757644653,
-0.012903474271297455,
-0.05848361924290657,
-0.0211944617331028,
0.017247913405299187,
0.005753025412559509,
0.0007732437225058675,
-0.008866644464433193,
0.010062211193144321
] |
8a48a06f40aea92943e0a0af216f5992d3ce3e19 | 987 | py | Python | dataset_specifications/swirls.py | joeloskarsson/CGAN-regression | 1cbcced10d28c11df8500373fc625e5df493f21d | [
"MIT"
] | 12 | 2020-05-22T08:02:27.000Z | 2022-03-28T06:14:23.000Z | dataset_specifications/swirls.py | joeloskarsson/CGAN-regression | 1cbcced10d28c11df8500373fc625e5df493f21d | [
"MIT"
] | 3 | 2021-06-08T21:33:24.000Z | 2022-03-11T07:11:06.000Z | dataset_specifications/swirls.py | joeloskarsson/CGAN-regression | 1cbcced10d28c11df8500373fc625e5df493f21d | [
"MIT"
] | null | null | null | import numpy as np
import math
from dataset_specifications.dataset import Dataset
class SwirlsSet(Dataset):
def __init__(self):
super().__init__()
self.name = "swirls"
self.n_samples = {
"train": 2000,
"val": 1000,
"test": 1000,
}
self.y_dim = 2
# 2D heteroskedastic Gaussian mixture model with 2 components
def sample_ys(self, xs):
n = xs.shape[0]
components = np.random.randint(2, size=n) # uniform 0,1
angles = math.pi*components + (math.pi/2.)*xs[:,0] # Angles to centers
means = np.stack((np.cos(angles), np.sin(angles)), axis=1)
noise = np.random.randn(n, 2) # samples form 2d gaussian
std = 0.3 - 0.2*np.abs(xs-1.)
ys = means + std*noise
return ys
def sample(self, n):
xs = np.random.uniform(low=0., high=2., size=(n,1))
ys = self.sample_ys(xs)
return np.concatenate((xs, ys), axis=1)
| 25.307692 | 78 | 0.563323 | 1 | 1.0431 | [
0.0011031274916604161,
0.02483581379055977,
0.008422452956438065,
-0.0006381715065799654,
0.004929491318762302,
-0.006154023576527834,
-0.00936085544526577,
0.004043585155159235,
-0.0068653482012450695,
0.0008697850280441344,
0.005411893129348755,
0.002569695236161351,
0.010652273893356323,
-0.014885332435369492,
0.0012389272451400757,
0.018218761309981346,
-0.052792444825172424,
0.00038862068322487175,
-0.003609827719628811,
0.0038879907224327326,
-0.009527381509542465,
0.010197818279266357,
0.00957533810287714,
0.007981224916875362,
0.003500491613522172,
-0.0030801971442997456,
0.010366617701947689,
0.0033137525897473097,
-0.010121939703822136,
-0.007273566909134388,
-0.0014084060676395893,
-0.0027932191733270884,
-0.008841174654662609,
-0.007355935871601105,
0.0069086020812392235,
-0.005226951092481613,
0.0006964923231862485,
-0.020139755681157112,
0.012004364281892776,
-0.006095205899327993,
-0.005635419860482216,
-0.015273009426891804,
0.0025190021842718124,
0.004938757978379726,
-0.010791519656777382,
0.0005391356535255909,
-0.0021616709418594837,
0.001511147478595376,
-0.008209595456719398,
0.004854957573115826,
-0.010849665850400925,
0.00542432302609086,
0.015659134835004807,
0.004197460133582354,
-0.006276246625930071,
-0.007505292072892189,
0.010188153944909573,
0.000012735702512145508,
-0.011012274771928787,
-0.00027972081443294883,
-0.0036857654340565205,
-0.0026295529678463936,
0.004675639793276787,
0.0022302595898509026,
-0.017735973000526428,
-0.005303667858242989,
-0.007282168138772249,
0.0033893289510160685,
-0.0026397425681352615,
0.005373063031584024,
0.0036556392442435026,
0.0007942876545712352,
0.007232772186398506,
0.0036031242925673723,
0.0021011666394770145,
-0.00612963642925024,
-0.0019984005484730005,
0.001920327777042985,
0.00844231341034174,
0.004146571736782789,
0.005819096229970455,
-0.007838073186576366,
0.0029491689056158066,
0.013541965745389462,
0.013173258863389492,
0.009741011075675488,
0.017640376463532448,
-0.010961759835481644,
0.044779784977436066,
0.009359804913401604,
-0.009792288765311241,
0.0009823762811720371,
-0.011277210898697376,
-0.0009548797970637679,
-0.0005903826095163822,
-0.029778361320495605,
-0.0019542851950973272,
-0.0035805886145681143,
-0.000650105532258749,
0.003426526440307498,
0.0014809360727667809,
0.008476748131215572,
-0.00032878207275643945,
-0.0032882748637348413,
-0.008171508088707924,
0.009810598567128181,
-0.008889496326446533,
-0.004382180981338024,
0.010263052769005299,
0.004134534392505884,
-0.01378889661282301,
-0.0011691839899867773,
0.0006796133820898831,
-0.014325099065899849,
0.005357073619961739,
0.001986955525353551,
-0.009961768984794617,
0.05561031773686409,
-0.0024982502218335867,
-0.0005902079865336418,
-0.005638879723846912,
-0.0018949502846226096,
0.004233799874782562,
0.008062776178121567,
0.009894943796098232,
-0.004721315577626228,
0.012828155420720577,
0.010118898935616016,
0.004950101021677256,
0.01086980290710926,
-0.001518175471574068,
0.01157910656183958,
-0.0032221267465502024,
-0.0019742869772017,
-0.0003511826798785478,
-0.00837570521980524,
0.008099693804979324,
-0.0012428871123120189,
-0.008821302093565464,
0.003909566905349493,
-0.00012094236444681883,
-0.010293934494256973,
-0.0002485404838807881,
-0.0042173354886472225,
0.002594063524156809,
-0.010851497761905193,
-0.00471396092325449,
-0.004638799466192722,
-0.0037843845784664154,
0.004705017898231745,
0.010630900971591473,
0.005330673418939114,
0.003031097585335374,
-0.0054317363537848,
-0.011377369984984398,
-0.0012719708029180765,
-0.006438760086894035,
0.0010438032913953066,
0.009356331080198288,
0.0033486373722553253,
-0.010627270676195621,
-0.0038561741821467876,
0.0037838544230908155,
0.004284774884581566,
-0.003570372937247157,
0.0007953763124532998,
-0.0072492873296141624,
0.00961171556264162,
-0.0010285649914294481,
0.0023608652409166098,
0.011895855888724327,
-0.004546291660517454,
0.0012162190396338701,
0.0005066815647296607,
0.004318553023040295,
-0.0033770117443054914,
0.005816545803099871,
0.010828100144863129,
-0.0039027943275868893,
-0.006510022096335888,
0.007001948542892933,
0.004215037915855646,
0.008386452682316303,
0.00627863546833396,
-0.0033714210148900747,
0.0032666418701410294,
-0.004007259383797646,
0.0010175416246056557,
0.006544014438986778,
-0.003743084380403161,
0.0036301654763519764,
0.0033004481811076403,
-0.01574125327169895,
-0.008798995055258274,
-0.0025262164417654276,
-0.00924001820385456,
0.0015599378384649754,
0.01573881506919861,
0.008759126998484135,
-0.0016122163506224751,
0.0029542874544858932,
-0.010455625131726265,
-0.0019715395756065845,
0.005907563026994467,
0.002618813421577215,
-0.013819086365401745,
-0.9555084705352783,
0.005617958959192038,
0.003523254068568349,
-0.0005287643289193511,
0.006036635488271713,
0.003923957701772451,
0.0030416538938879967,
0.004016839433461428,
0.014820955693721771,
-0.0078013283200562,
-0.007665181532502174,
-0.009482836350798607,
-0.011948135681450367,
-0.0026685118209570646,
-0.006016133353114128,
-0.0029921620152890682,
-0.0068143391981720924,
-0.006977463141083717,
-0.0041681756265461445,
-0.005741985514760017,
-0.003514290088787675,
0.010077870450913906,
-0.0035924117546528578,
0.004430346190929413,
0.003731015371158719,
0.003030159045010805,
-0.0062202271074056625,
-0.0027282629162073135,
-0.002205938333645463,
-0.004555369261652231,
-0.007549201138317585,
-0.015595500357449055,
-0.003145298920571804,
-0.0002193963882746175,
0.00914155226200819,
-0.0020847355481237173,
0.008379723876714706,
-0.0014669029042124748,
0.002775336615741253,
-0.00877978466451168,
0.0058906953781843185,
0.0008306647068820894,
0.002862773137167096,
-0.028157344087958336,
-0.0037207817658782005,
-0.0006199541385285556,
-0.008863640949130058,
0.007429176941514015,
0.00032710767118260264,
0.0011284436332061887,
-0.0035262072924524546,
-0.006460146512836218,
0.011102584190666676,
-0.007653180975466967,
0.003118423279374838,
-0.005848898086696863,
-0.00609236815944314,
-0.0020657579880207777,
-0.00871773436665535,
-0.0011872363975271583,
0.0014638722641393542,
-0.006608554162085056,
-0.0031508016400039196,
-0.003716093488037586,
0.003860795171931386,
0.003048710525035858,
0.0005069259786978364,
-0.018901674076914787,
-0.005501663777977228,
0.003674235427752137,
0.001171499490737915,
-0.0022203354164958,
-0.004005121532827616,
0.0026091737672686577,
-0.009834704920649529,
0.003910302184522152,
0.0025619356893002987,
0.0006589074619114399,
-0.011389598250389099,
-0.0006206847610883415,
-0.011200925335288048,
-0.009882737882435322,
0.005238888785243034,
-0.005688553210347891,
-0.004021899774670601,
-0.000015538844309048727,
-0.00011895458010258153,
0.007021056488156319,
-0.005816304590553045,
0.00551990233361721,
0.01174650527536869,
0.00002764879354799632,
-0.008473558351397514,
0.008093152195215225,
0.007062697783112526,
0.0020634555257856846,
-0.005185623653233051,
0.00044661646825261414,
0.010089162737131119,
0.007361588068306446,
0.0012102354085072875,
0.005111912731081247,
-0.0009484533802606165,
0.008784011006355286,
-0.0005089974729344249,
0.0006909907096996903,
-0.0022301399149000645,
0.00032510142773389816,
-0.006817043758928776,
-0.003499798709526658,
-0.005201573483645916,
-0.0031363291200250387,
-0.012026268057525158,
-0.00909710768610239,
-0.004435527138411999,
-0.0002726319944486022,
0.0018165106885135174,
-0.0050187180750072,
-0.00003917504000128247,
-0.0007756486884318292,
0.007609527558088303,
-0.0030800553504377604,
-0.0047716014087200165,
0.0004977721837349236,
0.00196250481531024,
-0.006917599588632584,
0.014392380602657795,
-0.012326886877417564,
0.0071361795999109745,
-0.0008494866196997464,
-0.017231836915016174,
0.007840113714337349,
0.00907934457063675,
-0.006360447499901056,
-0.0008707448141649365,
-0.00026710907695814967,
0.0040359459817409515,
0.0011250111274421215,
-0.006318752188235521,
-0.0007508029229938984,
-0.018604701384902,
-0.0016884009819477797,
0.01934007555246353,
0.0037280963733792305,
0.01121651940047741,
0.013187593780457973,
-0.005300986114889383,
0.001988673582673073,
0.007231788709759712,
0.0025581251829862595,
0.01550335343927145,
-0.009092272259294987,
0.004017930012196302,
0.00024811559705995023,
-0.004328530747443438,
0.0024960096925497055,
0.00572251807898283,
0.0036451176274567842,
-0.0038868573028594255,
0.0016175492201000452,
-0.007229974493384361,
-0.008182485587894917,
-0.017970431596040726,
-0.0027055174577981234,
0.008219487965106964,
-0.006811932660639286,
0.006156695540994406,
-0.00882164016366005,
0.00343822012655437,
0.004777447786182165,
0.0037244069389998913,
0.0022918516770005226,
0.0006929136579856277,
0.007803070824593306,
0.011616000905632973,
-0.0070223030634224415,
0.0009864125167950988,
0.003657576162368059,
-0.004394194111227989,
0.0011482194531708956,
0.010267464444041252,
-0.007839440368115902,
-0.0050127808935940266,
0.0021934264805167913,
0.0033334011677652597,
0.003767825663089752,
-0.003693662118166685,
-0.009584718383848667,
-0.003987370058894157,
0.0015980091411620378,
-0.007303357589989901,
0.003448653966188431,
-0.0003115520521532744,
0.002207295037806034,
-0.00813260767608881,
0.0009033694514073431,
-0.003837918397039175,
-0.01078472938388586,
0.009837772697210312,
-0.0028618837241083384,
0.002530629513785243,
0.012906364165246487,
0.0027169270906597376,
-0.013273779302835464,
0.005503362510353327,
0.009276008233428001,
-0.004483144264668226,
0.0038836027961224318,
0.008930934593081474,
-0.0034593699965626,
-0.022706981748342514,
-0.001940286485478282,
-0.012927205301821232,
0.006414402276277542,
-0.0014327919343486428,
0.0030266756657510996,
-0.008259071968495846,
0.010549038648605347,
0.006565917283296585,
-0.013050280511379242,
-0.004353862255811691,
-0.008775710128247738,
0.008385940454900265,
-0.0013250912306830287,
0.0008976854151114821,
-0.0036945294123142958,
-0.0036918222904205322,
-0.00297062867321074,
-0.003412656020373106,
-0.0018989074742421508,
0.00240983790718019,
0.001890359097160399,
-0.0019843364134430885,
0.003582812612876296,
-0.0016246124869212508,
0.0010500900680199265,
-0.0014100203989073634,
-0.010699733160436153,
0.0003552958951331675,
0.005572729744017124,
-0.0014650168595835567,
-0.001064741751179099,
0.0010491422144696116,
-0.004420583136379719,
-0.00530067877843976,
-0.010773999616503716,
-0.004737256094813347,
-0.005043849814683199,
-0.001254343194887042,
-0.01139059942215681,
-0.003746426198631525,
-0.010162576101720333,
0.010604136623442173,
-0.007174408063292503,
0.007626679725944996,
0.005948073696345091,
-0.00567858200520277,
0.004567841533571482,
-0.0027894265949726105,
0.003650462022051215,
0.0021389732137322426,
0.005908417049795389,
0.0009610246052034199,
-0.008004150353372097,
-0.009245842695236206,
0.013393023051321507,
-0.007727912627160549,
0.0017013491597026587,
0.015404368750751019,
0.003309442661702633,
0.008977238088846207,
0.00018191114941146225,
0.000055442611483158544,
0.0038060119841247797,
0.00839201733469963,
-0.01459534838795662,
0.0031986767426133156,
-0.004950012546032667,
-0.00011760152847273275,
0.005954458378255367,
-0.0055587319657206535,
0.003597803646698594,
0.01044851541519165,
0.00398275488987565,
-0.005990852601826191,
-0.002017923165112734,
-0.00004130673914914951,
0.0031431487295776606,
-0.012191967107355595,
-0.00026587926549836993,
0.00022590986918658018,
-0.005169265903532505,
-0.0014104938600212336,
-0.0019087912514805794,
0.0001614721113583073,
0.0054009160958230495,
-0.0018378016538918018,
0.0063377320766448975,
0.002898577833548188,
-0.0047086249105632305,
0.016662565991282463,
-0.00482974061742425,
-0.00648836512118578,
0.004585379734635353,
0.0014969827607274055,
-0.002088269218802452,
-0.006020879372954369,
-0.003212379291653633,
0.00036624650238081813,
0.005971421953290701,
-0.0033196222502738237,
-0.005228858906775713,
-0.005024850834161043,
0.0012862433213740587,
-0.008919277228415012,
0.0016569826984778047,
0.012800216674804688,
-0.004247641656547785,
0.004743468016386032,
0.0005863777478225529,
-0.006804513745009899,
-0.012193185277283192,
0.05686604976654053,
-0.001413102145306766,
0.0032081585377454758,
0.007629506289958954,
-0.008093113079667091,
0.00016664985741954297,
-0.0019450319232419133,
0.008471927605569363,
-0.006449978798627853,
-0.008639607578516006,
0.007981989532709122,
-0.003800345351919532,
0.0027498614508658648,
0.004540348891168833,
-0.0014877415960654616,
0.018497589975595474,
-0.003874104470014572,
-0.01645599864423275,
-0.014552569948136806,
0.005000784527510405,
-0.0036924260202795267,
-0.006636139005422592,
0.007821938022971153,
-0.0026524208951741457,
-0.0012043321039527655,
0.0003624055825639516,
0.0073783500120043755,
-0.00028782006120309234,
-0.001264344435185194,
-0.0018432805081829429,
-0.0011340351775288582,
-0.00009011018846649677,
0.003331853076815605,
0.004148466046899557,
0.00910180527716875,
-0.0013798641739413142,
0.0032303077168762684,
0.001758914440870285,
-0.00040745839942246675,
-0.0008560995920561254,
0.007211319636553526,
0.00483036320656538,
-0.0006012286758050323,
-0.0031073917634785175,
0.004893960896879435,
0.003436345374211669,
0.0013983712997287512,
0.012354566715657711,
-0.00032280615414492786,
-0.006475810427218676,
0.008891060017049313,
0.008755714632570744,
-0.001249587396159768,
0.008651434443891048,
0.0009486950584687293,
0.00596589082852006,
0.002618269296362996,
-0.007344834040850401,
-0.011175245977938175,
0.0016134193865582347,
0.008885988965630531,
0.011844023130834103,
0.0004921767977066338,
0.001637516194023192,
0.0008078166283667088,
-0.003914840053766966,
-0.008016250096261501,
-0.008255230262875557,
-0.0012747939908877015,
0.0005404953844845295,
0.004020483698695898,
0.07280268520116806,
-0.008474872447550297,
-0.003620430128648877,
-0.010342627763748169,
0.0008731110719963908,
-0.0019224229035899043,
-0.0018350400496274233,
-0.0021455667447298765,
-0.0007508778944611549,
0.002845116425305605,
0.003425432136282325,
-0.008348469622433186,
-0.010664869099855423,
0.0013478182954713702,
0.004663234110921621,
0.0011044853599742055,
0.003377653192728758,
0.004990814253687859,
-0.004290080163627863,
0.0018818654352799058,
-0.012487736530601978,
-0.0006523541524074972,
-0.0011450701858848333,
-0.00818152166903019,
-0.005239089019596577,
-0.0022886674851179123,
0.0038289157673716545,
0.002518645953387022,
0.005658010020852089,
-0.002470113802701235,
0.0054159751161932945,
-0.0038179485127329826,
-0.0005143581656739116,
-0.00166309776250273,
0.0006267490098252892,
-0.006883606314659119,
0.009467692114412785,
0.0017992497887462378,
-0.012741314247250557,
-0.0060637034475803375,
-0.00006021686567692086,
-0.0005753058358095586,
-0.006618316750973463,
0.006976299919188023,
-0.0011929096654057503,
0.00750684505328536,
-0.0044602081179618835,
0.001471659168601036,
-0.005979079753160477,
0.0012000048300251365,
-0.01570107601583004,
0.00709078973159194,
-0.1799871176481247,
0.009758010506629944,
0.005885965656489134,
-0.0046365284360945225,
-0.0022957574110478163,
-0.014189420267939568,
-0.008647146634757519,
0.0038958340883255005,
0.010247946716845036,
0.003724960843101144,
0.0019071256974712014,
-0.0015241254586726427,
0.0038714774418622255,
0.00332089071162045,
-0.000984927755780518,
-0.004172858782112598,
0.006626950576901436,
-0.005658580455929041,
0.0020944818388670683,
0.0055974326096475124,
0.004559090826660395,
0.007538690697401762,
0.0027953798417001963,
0.0032230857759714127,
0.0007338141440413892,
-0.005356188863515854,
0.004061216488480568,
-0.0003701187379192561,
0.005987354554235935,
-0.01134058553725481,
-0.005742018576711416,
-0.0030612724367529154,
-0.0036575011909008026,
0.001800323254428804,
0.002634599106386304,
-0.0015422279248014092,
0.00892470683902502,
0.001923991134390235,
-0.009113198146224022,
0.005184348672628403,
-0.007319106254726648,
0.0309864841401577,
0.0051680696196854115,
0.005398052744567394,
-0.0006367883761413395,
-0.004121862817555666,
-0.004698548931628466,
0.009842234663665295,
0.004163144621998072,
0.013927197083830833,
-0.012603524141013622,
-0.00013618858065456152,
0.0037834218237549067,
0.018694045022130013,
-0.005168483126908541,
-0.00995673704892397,
-0.006742123048752546,
-0.0051934486255049706,
0.003740333253517747,
0.007917768321931362,
0.011230201460421085,
-0.006376453675329685,
0.009232212789356709,
-0.0020582592114806175,
-0.022415289655327797,
0.0049369544722139835,
-0.003664246294647455,
-0.00806987751275301,
-0.000029496488423319533,
0.00628682179376483,
0.010544147342443466,
-0.0028500077314674854,
0.00398615188896656,
-0.0015667487168684602,
0.004490520339459181,
-0.0007047915132716298,
0.006212302017956972,
-0.004092496354132891,
0.005833249073475599,
-0.008687914349138737,
0.00984961073845625,
-0.009313907474279404,
-0.00373784638941288,
0.0028992476873099804,
-0.005600883159786463,
0.00966824684292078,
0.005754930432885885,
-0.0029467535205185413,
-0.0017905216664075851,
-0.011080436408519745,
-0.00216743815690279,
0.001159610110335052,
0.0006982671329751611,
-0.008085914887487888,
0.0021243994124233723,
-0.000868984789121896,
0.007863735780119896,
0.009887105785310268,
-0.010014473460614681,
0.006475667469203472,
0.0042101857252418995,
-0.00838527549058199,
-0.0012638167245313525,
-0.0011429382720962167,
0.0010115320328623056,
0.0054588308557868,
-0.006790101993829012,
-0.007578684948384762,
0.004705439787358046,
-0.008645640686154366,
-0.005312241148203611,
0.004549859091639519,
-0.011944400146603584,
-0.007375913206487894,
-0.001693576923571527,
-0.011780425906181335,
-0.0003981674090027809
] |
8a490933d8b95e96a7ba4163aae03b0fe0c37be5 | 657 | py | Python | pytorch-frontend/tools/code_coverage/oss_coverage.py | AndreasKaratzas/stonne | 2915fcc46cc94196303d81abbd1d79a56d6dd4a9 | [
"MIT"
] | 40 | 2021-06-01T07:37:59.000Z | 2022-03-25T01:42:09.000Z | pytorch-frontend/tools/code_coverage/oss_coverage.py | AndreasKaratzas/stonne | 2915fcc46cc94196303d81abbd1d79a56d6dd4a9 | [
"MIT"
] | 14 | 2021-06-01T11:52:46.000Z | 2022-03-25T02:13:08.000Z | pytorch-frontend/tools/code_coverage/oss_coverage.py | AndreasKaratzas/stonne | 2915fcc46cc94196303d81abbd1d79a56d6dd4a9 | [
"MIT"
] | 7 | 2021-07-20T19:34:26.000Z | 2022-03-13T21:07:36.000Z | #!/usr/bin/env python
import time
from package.oss.cov_json import get_json_report
from package.oss.init import initialization
from package.tool.summarize_jsons import summarize_jsons
from package.util.setting import TestPlatform
def report_coverage() -> None:
start_time = time.time()
(options, test_list, interested_folders) = initialization()
# run cpp tests
get_json_report(test_list, options)
# collect coverage data from json profiles
if options.need_summary:
summarize_jsons(
test_list, interested_folders, [""], TestPlatform.OSS, start_time
)
if __name__ == "__main__":
report_coverage()
| 27.375 | 77 | 0.73516 | 1 | 0.8376 | [
-0.00027559357113204896,
0.024112513288855553,
0.008138664066791534,
0.003014089772477746,
0.003284794744104147,
-0.0026888460852205753,
-0.006650375667959452,
0.0026271240785717964,
-0.008045891299843788,
-0.0003695121267810464,
0.0012929276563227177,
0.006664424668997526,
0.007125525269657373,
-0.01652885414659977,
-0.0004338279541116208,
0.019525470212101936,
-0.055041346698999405,
0.0014555355301126838,
-0.004953526891767979,
0.005049824248999357,
-0.007634419947862625,
0.010105844587087631,
0.008369228802621365,
0.0058884997852146626,
0.005717260763049126,
0.000223309121793136,
0.009445899166166782,
-0.0010941268410533667,
-0.004354143049567938,
-0.00855546910315752,
0.0019623669795691967,
-0.0029759069439023733,
-0.009072467684745789,
-0.007061960641294718,
0.003096522530540824,
-0.0036332879681140184,
-0.0024094795808196068,
-0.01755416765809059,
0.010378447361290455,
-0.007092151325196028,
-0.007944605313241482,
-0.017523035407066345,
-0.00024823693092912436,
0.007241504732519388,
-0.011157621629536152,
0.0023966797161847353,
-0.002064767060801387,
0.003648453624919057,
-0.01172483991831541,
0.00788828730583191,
-0.011691403575241566,
0.00397416390478611,
0.013965238817036152,
0.0020935568027198315,
-0.004204535391181707,
-0.006467010825872421,
0.010301182977855206,
-0.00024010876950342208,
-0.011766685172915459,
0.0004017241590190679,
-0.006638627965003252,
-0.0021360355895012617,
0.0036064304877072573,
0.0026270353700965643,
-0.013736221939325333,
-0.006215835455805063,
-0.004004866816103458,
0.0013119238428771496,
-0.0008000437519513071,
0.006429403088986874,
-0.00020930581376887858,
-0.0030988859944045544,
0.008698949590325356,
0.004675595555454493,
0.0006419477867893875,
-0.002029804512858391,
-0.0010049630654975772,
0.0022477542515844107,
0.009145361371338367,
0.0014946090523153543,
0.00452992832288146,
-0.007943174801766872,
0.004952976480126381,
0.011228601448237896,
0.012253383174538612,
0.011901916936039925,
0.02072468213737011,
-0.009573085233569145,
0.043444715440273285,
0.007210231851786375,
-0.010585425421595573,
0.0016769535141065717,
-0.008408423513174057,
-0.003561698831617832,
-0.005132653750479221,
-0.03059506230056286,
-0.00107670109719038,
-0.0037314482033252716,
-0.0023764511570334435,
0.003442233894020319,
-0.0007789012743160129,
0.002825245726853609,
-0.002557889325544238,
-0.004005654715001583,
-0.010525255464017391,
0.011372419074177742,
-0.007979086600244045,
-0.001144301611930132,
0.00741180032491684,
0.001485063461586833,
-0.012155161239206791,
-0.0014604309108108282,
0.002736237831413746,
-0.014270022511482239,
0.003621145151555538,
0.0009907353669404984,
-0.006968799978494644,
0.05484788864850998,
-0.0012770878383889794,
0.0035805655643343925,
-0.003916267305612564,
0.0035167373716831207,
-0.0014811006840318441,
0.005189857445657253,
0.009711798280477524,
-0.00438920920714736,
0.010984782129526138,
0.0064560770988464355,
0.0016052306164056063,
0.006567430682480335,
-0.000771014136262238,
0.006285668816417456,
-0.002655311953276396,
-0.00223658699542284,
0.0026815051678568125,
-0.006163469981402159,
0.009154546074569225,
-0.0009835498640313745,
-0.007387716788798571,
-0.0015958162257447839,
-0.002254724269732833,
-0.01083771139383316,
0.0013029597466811538,
-0.004603935405611992,
0.0029323254711925983,
-0.011713431216776371,
-0.0025966118555516005,
-0.0029082715045660734,
-0.0017598879057914019,
0.0006964783533476293,
0.009065554477274418,
0.003650647820904851,
0.004530977923423052,
-0.007284651510417461,
-0.00634004408493638,
-0.002579560736194253,
-0.00591909559443593,
0.0031623276881873608,
0.00666955066844821,
0.004227117169648409,
-0.007393141742795706,
-0.001609790837392211,
0.005942892283201218,
0.0045625907368958,
0.0006088610971346498,
0.0022903713397681713,
-0.009356582537293434,
0.00903062429279089,
0.0024952462408691645,
0.004946507513523102,
0.010401674546301365,
-0.003389030694961548,
-0.00125000043772161,
0.0017414434114471078,
0.002904473803937435,
0.0017246886854991317,
0.005011366214603186,
0.011563032865524292,
-0.0027167259249836206,
-0.004150913562625647,
0.00482430262491107,
0.004360856954008341,
0.0124356085434556,
0.00963258184492588,
-0.003314432455226779,
0.0012048670323565602,
-0.003371724858880043,
-0.00047639652621001005,
0.005845014471560717,
-0.004771793261170387,
0.009491384960711002,
0.005470378790050745,
-0.01507296971976757,
-0.009289774112403393,
0.002616811078041792,
-0.011245240457355976,
0.0017468186561018229,
0.015742728486657143,
0.0113060986623168,
0.00012581578630488366,
0.0006466758204624057,
-0.010858043096959591,
0.0016733022639527917,
0.0078089311718940735,
0.002995510119944811,
-0.012114036828279495,
-0.9563892483711243,
0.005440900102257729,
0.004289221949875355,
-0.0015683096135035157,
0.0028936362359672785,
0.004667550325393677,
0.002169738756492734,
0.0024925631005316973,
0.01697225123643875,
-0.009610716253519058,
-0.00708023551851511,
-0.007594290189445019,
-0.009722062386572361,
0.0023700755555182695,
-0.005825901869684458,
-0.0012991141993552446,
-0.007678285241127014,
-0.0077257477678358555,
-0.003419394139200449,
-0.004048822447657585,
-0.0004924623644910753,
0.0077750543132424355,
0.00009967978985514492,
0.004706734325736761,
0.0026351995766162872,
0.002331990282982588,
-0.005802358966320753,
-0.00155914097558707,
-0.0027006634045392275,
-0.0005993460072204471,
-0.007181745953857899,
-0.017058804631233215,
-0.004187705460935831,
-0.002554959384724498,
0.013165757060050964,
0.0028623000252991915,
0.008770632557570934,
-0.0038395212031900883,
0.004292560275644064,
-0.007581392768770456,
0.005699194502085447,
0.0038156104274094105,
0.0031541942153126,
-0.03239026293158531,
0.00033437146339565516,
-0.0007192089688032866,
-0.00630010012537241,
0.0074883149936795235,
0.0008937109960243106,
0.00043157872278243303,
-0.0019421759061515331,
-0.004948854446411133,
0.00943367462605238,
-0.007977577857673168,
0.002397949807345867,
-0.003182469867169857,
-0.005528518930077553,
-0.0030075404793024063,
-0.009444930590689182,
0.003829492488875985,
0.005361150950193405,
-0.00402865931391716,
-0.0036807560827583075,
-0.004333734977990389,
0.0032580201514065266,
0.0006113579147495329,
0.0015838420949876308,
-0.015929970890283585,
-0.00518740015104413,
-0.002770159626379609,
0.0032097946386784315,
-0.00004785502460435964,
-0.003145163878798485,
0.0052564386278390884,
-0.007983150891959667,
0.006610540207475424,
0.0010169027373194695,
-0.0022366291377693415,
-0.008194928988814354,
0.00021472215303219855,
-0.009298542514443398,
-0.007302949670702219,
0.0018719588406383991,
-0.0043477448634803295,
-0.003073649713769555,
-0.001308842794969678,
0.0033604928757995367,
0.00906327087432146,
-0.0028274646028876305,
0.004489996936172247,
0.013854495249688625,
-0.0051240394823253155,
-0.010208473540842533,
0.006834644824266434,
0.005571360234171152,
0.0005022652912884951,
-0.000461879390059039,
-0.0010828574886545539,
0.007873174734413624,
0.006576783023774624,
-0.0016647276934236288,
0.004497671965509653,
0.0010610331082716584,
0.009305424988269806,
-0.0003010677173733711,
0.0031275663059204817,
-0.003112996928393841,
-0.0033752641174942255,
-0.00229712575674057,
-0.003761890809983015,
-0.00820497889071703,
-0.0010239401599392295,
-0.01082690805196762,
-0.009330818429589272,
-0.00325182662345469,
0.0010502524673938751,
0.0023794113658368587,
-0.005834019277244806,
0.00041154457721859217,
0.0028548415284603834,
0.010888651944696903,
0.0029674225952476263,
-0.003660936141386628,
0.0022760021965950727,
0.004345016088336706,
-0.006905657239258289,
0.015092168003320694,
-0.009078435599803925,
0.003997516818344593,
-0.0015273743774741888,
-0.014381542801856995,
0.008618852123618126,
0.01029124390333891,
-0.007820975966751575,
0.002218111651018262,
0.0015806573210284114,
0.00021956807177048177,
-0.0008249544189311564,
-0.006259830668568611,
-0.005300621967762709,
-0.01740197092294693,
-0.001741661923006177,
0.020211979746818542,
0.001756942947395146,
0.011189891956746578,
0.012335117906332016,
-0.003288041800260544,
0.0019106852123513818,
0.008188375271856785,
0.0037061618641018867,
0.01092715933918953,
-0.009306124411523342,
-0.0005854122573509812,
0.0020383994560688734,
-0.005782621912658215,
0.0016505795065313578,
0.0039361026138067245,
0.005645340774208307,
-0.0017742111813277006,
0.0039276243187487125,
-0.006855464540421963,
-0.007504304405301809,
-0.020131735131144524,
0.00030181038891896605,
0.005564581602811813,
-0.003791024209931493,
0.00761244585737586,
-0.011803355999290943,
0.0016491516726091504,
0.004754677414894104,
0.00340341217815876,
-0.0009809276089072227,
0.003357876557856798,
0.006368615198880434,
0.012853346765041351,
-0.005339862313121557,
0.0037360459100455046,
0.0001025393939926289,
-0.002832186408340931,
-0.00033158916630782187,
0.0033210166729986668,
-0.008304319344460964,
-0.004952380899339914,
0.0037514474242925644,
0.0014677719445899129,
0.001901914132758975,
-0.0016133977333083749,
-0.010900859721004963,
-0.004052510019391775,
0.002096830401569605,
-0.004960554651916027,
0.0021533374674618244,
0.002285389695316553,
0.004494846798479557,
-0.006997021846473217,
0.0033818220254033804,
-0.006907366216182709,
-0.011344300583004951,
0.010561399161815643,
-0.003275310155004263,
0.00042586890049278736,
0.013962775468826294,
0.005375796463340521,
-0.010827498510479927,
0.005745693575590849,
0.007752740290015936,
-0.00284305470995605,
0.0035578706301748753,
0.003272309899330139,
-0.0066158464178442955,
-0.023738576099276543,
-0.0022770906798541546,
-0.016070161014795303,
0.00609838729724288,
-0.002162434859201312,
0.00426347553730011,
-0.007841939106583595,
0.007711227051913738,
0.003934812732040882,
-0.014822898432612419,
-0.0039594778791069984,
-0.008098797872662544,
0.00994099397212267,
-0.0015925621846690774,
-0.0015101220924407244,
-0.004921560641378164,
-0.0025961752980947495,
-0.001458344398997724,
-0.00004892179640592076,
-0.0006040183361619711,
0.006754639558494091,
0.00375666213221848,
-0.004189630039036274,
0.00345869199372828,
-0.0023436695337295532,
-0.0002038375532720238,
0.0010078097693622112,
-0.012154659256339073,
0.0006441902369260788,
0.006182475946843624,
-0.0027134506963193417,
-0.002542058238759637,
0.00032726346398703754,
-0.0016856050351634622,
-0.004089655354619026,
-0.012984038330614567,
-0.002853557001799345,
-0.002412577159702778,
-0.0026431011501699686,
-0.010913228616118431,
-0.0019806548953056335,
-0.005895780399441719,
0.010136883705854416,
-0.00627240352332592,
0.007954279892146587,
0.0042318254709243774,
-0.00596148706972599,
0.008462527766823769,
-0.002630220027640462,
0.002168059814721346,
0.0007374510169029236,
0.00586798507720232,
0.003032405162230134,
-0.008691009134054184,
-0.012458580546081066,
0.011417347006499767,
-0.013255443423986435,
0.0008025551796890795,
0.013923692516982555,
0.006700471043586731,
0.011294623836874962,
-0.000013023245628573932,
0.0012091289972886443,
0.006279595196247101,
0.0089834313839674,
-0.013827582821249962,
0.003770624054595828,
-0.0028239216189831495,
-0.0023839620407670736,
0.003968638833612204,
-0.0036724950186908245,
0.00297369621694088,
0.0060467529110610485,
0.0037055322900414467,
-0.007829488255083561,
-0.0024914450477808714,
0.0009361265110783279,
0.003230333561077714,
-0.011968517675995827,
0.0006642944645136595,
-0.0037761409766972065,
-0.00453219236806035,
-0.003171500051394105,
0.0010631923796609044,
-0.0006780255935154855,
0.003391548991203308,
-0.0032201700378209352,
0.00750361941754818,
0.0005943495780229568,
-0.006083474960178137,
0.015751447528600693,
-0.0051667275838553905,
-0.0030738229397684336,
0.0021008485928177834,
0.0006024760659784079,
-0.001299970899708569,
-0.0043568979017436504,
-0.003475724020972848,
0.0021817870438098907,
0.004541797563433647,
-0.002873858669772744,
-0.005053437780588865,
0.0003189700946677476,
0.0013444145442917943,
-0.009149180725216866,
0.0012502835597842932,
0.011302975937724113,
-0.002122793812304735,
0.005973768420517445,
0.0005338527844287455,
-0.007211518473923206,
-0.013525761663913727,
0.054237984120845795,
-0.0016231772024184465,
0.0031061340123414993,
0.006470012478530407,
-0.00556624261662364,
-0.00347450515255332,
-0.003671599319204688,
0.008896397426724434,
-0.008709374815225601,
-0.0063549792394042015,
0.007972411811351776,
-0.0031091105192899704,
0.004657725803554058,
-0.0007858776953071356,
0.0004164566344115883,
0.017311861738562584,
-0.0037193195894360542,
-0.018788529559969902,
-0.014902593567967415,
0.0076199788600206375,
-0.005522443447262049,
-0.006216403562575579,
0.008546441793441772,
-0.005925904493778944,
-0.003868121188133955,
0.0005798101192340255,
0.0029522820841521025,
0.000273108045803383,
0.0024113901890814304,
-0.002760146977379918,
-0.0014365334063768387,
-0.0008710612310096622,
0.0039933910593390465,
0.00983116589486599,
0.008145533502101898,
-0.003780549857765436,
0.004602331668138504,
0.0013050934066995978,
-0.0019933185540139675,
-0.0017778660403564572,
0.0034462721087038517,
0.006651869975030422,
-0.004033300559967756,
-0.006248116958886385,
0.0061234841123223305,
0.007026575040072203,
-0.0011067783925682306,
0.0087121007964015,
-0.0005709705292247236,
-0.006056285463273525,
0.007010850124061108,
0.008662967942655087,
-0.00016081985086202621,
0.006382944528013468,
-0.0031289071775972843,
0.002872539684176445,
0.0006773280329070985,
-0.008801930584013462,
-0.016517601907253265,
-0.002428926294669509,
0.004337924998253584,
0.007563364692032337,
0.00011762122448999435,
0.003789483802393079,
0.0029126987792551517,
-0.004744814708828926,
-0.007929958403110504,
-0.0066384985111653805,
-0.003305409336462617,
0.0000831705765449442,
0.006356087513267994,
0.07105708867311478,
-0.004570877645164728,
0.0014128899201750755,
-0.008233138360083103,
-0.001386234536767006,
-0.001342814532108605,
0.0018170219846069813,
-0.0015867881011217833,
-0.0025239530950784683,
0.00459803082048893,
0.0016218997770920396,
-0.006470904685556889,
-0.009572996757924557,
0.000025435396310058422,
0.0007223752909339964,
-0.003238741308450699,
0.003538538469001651,
0.009491070173680782,
-0.007188830524682999,
0.001284654950723052,
-0.014320711605250835,
-0.0031785962637513876,
-0.0035906778648495674,
-0.00695001520216465,
-0.0037538213655352592,
-0.004041686188429594,
0.0050170826725661755,
0.0020601118449121714,
0.004074950702488422,
-0.002087785629555583,
0.0032237209379673004,
-0.001133283949457109,
0.0006714516202919185,
-0.004708524793386459,
-0.001367977005429566,
-0.00453066686168313,
0.004899000283330679,
0.001435688929632306,
-0.01028086431324482,
-0.006812032777816057,
-0.004235920496284962,
-0.0006585964583791792,
-0.00480404170230031,
0.005131825339049101,
-0.0018692414741963148,
0.0074315499514341354,
-0.0032937773503363132,
0.0007679163827560842,
-0.004908043425530195,
-0.0038034506142139435,
-0.010515265166759491,
0.004612133372575045,
-0.18038339912891388,
0.009352334775030613,
0.0023219173308461905,
-0.005150183103978634,
-0.004055000375956297,
-0.01563561148941517,
-0.007596986368298531,
0.003016404341906309,
0.008823886513710022,
-0.00035904423566535115,
0.00038390670670196414,
0.002401120262220502,
0.005904495250433683,
0.004372854717075825,
-0.0032877582125365734,
-0.00610005110502243,
0.0022314926609396935,
-0.0038021754007786512,
0.002106689615175128,
0.004860001150518656,
0.0037904398050159216,
0.009953394532203674,
0.002144512953236699,
0.0028977040201425552,
-0.0016012337291613221,
-0.004964329302310944,
0.0060564130544662476,
-0.0025785700418055058,
0.007076088339090347,
-0.01432186458259821,
-0.002762549789622426,
-0.0036259121261537075,
-0.005441156215965748,
-0.0036420742981135845,
0.005959007889032364,
-0.0009690607548691332,
0.008532078936696053,
0.003836912102997303,
-0.006972892209887505,
0.008988332003355026,
-0.007261605467647314,
0.03056037612259388,
0.003988145384937525,
0.007169665303081274,
-0.0003335425863042474,
-0.004145893733948469,
-0.0046072788536548615,
0.007850653491914272,
0.0013958015479147434,
0.011971492320299149,
-0.010263162665069103,
-0.00435505248606205,
0.0030245499219745398,
0.01771393232047558,
-0.005578490439802408,
-0.010810368694365025,
-0.009674874134361744,
-0.0027288927230983973,
0.0012813500361517072,
0.009234189987182617,
0.009413826279342175,
-0.006715800147503614,
0.008825351484119892,
-0.003164245281368494,
-0.020539386197924614,
0.004366158973425627,
-0.006274792831391096,
-0.009366839192807674,
0.0016585183329880238,
0.007444035727530718,
0.011384298093616962,
-0.0018593698041513562,
0.004846531432121992,
-0.0047746398486196995,
0.004240443464368582,
-0.0009014543611556292,
0.0074762930162250996,
-0.0015686099650338292,
0.008150451816618443,
-0.006137478165328503,
0.008614465594291687,
-0.011931639164686203,
-0.0024978057481348515,
0.00309010106138885,
-0.0047729527577757835,
0.011391827836632729,
0.004367837216705084,
-0.002323572523891926,
0.0008032454643398523,
-0.011647902429103851,
0.0009189855773001909,
0.0000796213498688303,
0.001972234109416604,
-0.007943825796246529,
0.0027113009709864855,
-0.00151192513294518,
0.006874391809105873,
0.008549955673515797,
-0.009321042336523533,
0.006623358465731144,
0.0074702040292322636,
-0.00627816142514348,
0.0008939974359236658,
-0.00638113496825099,
0.0017838617786765099,
0.003319006646052003,
-0.005905419588088989,
-0.006204946897923946,
0.0073918686248362064,
-0.00642807874828577,
-0.0033035583328455687,
0.00750774797052145,
-0.011551112867891788,
-0.005863100755959749,
-0.0032622842118144035,
-0.009232986718416214,
-0.0014942610869184136
] |
8a49341d1b3481c67276f3865a9ce768c4be3a18 | 1,068 | py | Python | twitoff/predict.py | dscohen75/twitoff | 62d5702e989a6b5fc54aaf9326e240dd63c9fd06 | [
"MIT"
] | null | null | null | twitoff/predict.py | dscohen75/twitoff | 62d5702e989a6b5fc54aaf9326e240dd63c9fd06 | [
"MIT"
] | null | null | null | twitoff/predict.py | dscohen75/twitoff | 62d5702e989a6b5fc54aaf9326e240dd63c9fd06 | [
"MIT"
] | null | null | null | import numpy as np
from sklearn.linear_model import LogisticRegression
from .models import User
from .twitter import vectorize_tweet
def predict_user(user1_name, user2_name, tweet_text):
"""
Determine and return which user is more likely to say a given Tweet.
Example: predict_user('ausen', 'elonmusk', 'Lambda School Rocks!')
Returns 1 corresponding to 1st user passed in, or 0 for second.
"""
user1 = User.query.filter(User.name == user1_name).one()
user2 = User.query.filter(User.name == user2_name).one()
user1_vect = np.array([tweet.vect for tweet in user1.tweets])
user2_vect = np.array([tweet.vect for tweet in user2.tweets])
vects = np.vstack([user1_vect, user2_vect])
labels = np.concatenate([np.ones(len(user1.tweets)),
np.zeros(len(user2.tweets))])
log_reg = LogisticRegression().fit(vects, labels)
# We've done the model fitting, now to predict...
hypo_tweet_vect = vectorize_tweet(tweet_text)
return log_reg.predict(np.array(hypo_tweet_vect).reshape(1,-1))
| 41.076923 | 72 | 0.699438 | 1 | 1.0176 | [
0.0016620311653241515,
0.02563532441854477,
0.006596450228244066,
0.001576345064677298,
0.005645632278174162,
-0.0055664535611867905,
-0.009975023567676544,
0.0037488145753741264,
-0.007760866545140743,
0.0023594603408128023,
0.0035858042538166046,
0.0036274073645472527,
0.008340619504451752,
-0.015039867721498013,
-0.0026628493797034025,
0.01684759184718132,
-0.05188761651515961,
0.002299171406775713,
-0.003960554488003254,
0.0024819374084472656,
-0.006444263271987438,
0.011171062476933002,
0.007835188880562782,
0.007305404637008905,
0.005708375945687294,
-0.0055329990573227406,
0.011977339163422585,
0.001022574957460165,
-0.010116391815245152,
-0.003995160572230816,
0.00021344554261304438,
-0.0016080542700365186,
-0.005171073600649834,
-0.004382812883704901,
0.005553754046559334,
-0.005395346786826849,
-0.0019964296370744705,
-0.01976204849779606,
0.014450285583734512,
-0.009070026688277721,
-0.007292190566658974,
-0.016406159847974777,
-0.00118629087228328,
0.0054024336859583855,
-0.009149364195764065,
0.005489627830684185,
-0.004100351128727198,
0.0032375336159020662,
-0.010823440738022327,
0.003965246491134167,
-0.010159503668546677,
0.00421912781894207,
0.013296371325850487,
0.0039092861115932465,
-0.006370308343321085,
-0.008520002476871014,
0.012405844405293465,
0.0012771784095093608,
-0.012950131669640541,
-0.000054198677389649674,
-0.0031769522465765476,
-0.0020428206771612167,
0.004518117289990187,
0.002038936596363783,
-0.016461068764328957,
-0.008172758854925632,
-0.005943535827100277,
0.0034645607229322195,
-0.0016538257477805018,
0.005924890283495188,
0.001597888651303947,
-0.0002399980730842799,
0.005283654667437077,
0.00556194456294179,
0.004717240575700998,
-0.0028261500410735607,
-0.002803424373269081,
0.002206186531111598,
0.009330092929303646,
0.004097720608115196,
0.00366861536167562,
-0.00837310217320919,
0.007014414295554161,
0.010691709816455841,
0.014171288348734379,
0.0069067939184606075,
0.018982678651809692,
-0.012925704009830952,
0.04572337493300438,
0.010153869166970253,
-0.010610057041049004,
0.0022063248325139284,
-0.010989971458911896,
-0.003090823767706752,
-0.004095037002116442,
-0.03074147365987301,
0.002132714493200183,
-0.006280646659433842,
-0.0011315057054162025,
0.00128723937086761,
0.0008559547713957727,
0.004021420609205961,
0.00018331105820834637,
-0.0037001606542617083,
-0.00745761813595891,
0.014237341471016407,
-0.009945238009095192,
-0.005058474838733673,
0.007488204166293144,
0.0026477151550352573,
-0.012605506926774979,
0.000483551062643528,
0.0018480945145711303,
-0.014951427467167377,
0.0016220083925873041,
0.0026897541247308254,
-0.006134234834462404,
0.05646588280797005,
-0.0011135116219520569,
0.0024229546543210745,
-0.00777687132358551,
-0.0019669081084430218,
0.001654749154113233,
0.007523693609982729,
0.010112953372299671,
-0.004117409233003855,
0.01167250331491232,
0.00595217477530241,
0.005226755049079657,
0.00831586867570877,
-0.002672194503247738,
0.0074813212268054485,
-0.00445554731413722,
-0.00029566988814622164,
0.00018369493773207068,
-0.006862489040941,
0.006847006734460592,
-0.0016462227795273066,
-0.006474277004599571,
0.002772787120193243,
0.0005023846752010286,
-0.013396899215877056,
0.0009252702002413571,
-0.004027758724987507,
0.001958461944013834,
-0.013634487986564636,
-0.003548023058101535,
-0.0038000543136149645,
-0.0062289913184940815,
0.005214402452111244,
0.009992566891014576,
0.0042960974387824535,
0.0031172088347375393,
-0.0025487630628049374,
-0.008835452608764172,
-0.00024156391737051308,
-0.005211799871176481,
0.002246508374810219,
0.005581642035394907,
0.0035319102462381124,
-0.01271110586822033,
-0.002278316533192992,
0.0032784075010567904,
0.001943530747666955,
-0.0017684707418084145,
0.0012583881616592407,
-0.005806963425129652,
0.010009950958192348,
0.0003213190066162497,
0.004020138178020716,
0.011020085774362087,
-0.0029213358648121357,
-0.0004278545966371894,
-0.0005498923710547388,
0.0005317398463375866,
-0.00024254196614492685,
0.00473151495680213,
0.008302812464535236,
-0.005150994285941124,
-0.005913447588682175,
0.005282620433717966,
0.004316160921007395,
0.009090897627174854,
0.005028960760682821,
-0.0025754952803254128,
0.00284235249273479,
-0.007415384985506535,
0.00035037254565395415,
0.006871250923722982,
-0.004635102581232786,
0.007258533965796232,
0.002327968832105398,
-0.015588672831654549,
-0.00839825626462698,
-0.001876199385151267,
-0.008670895360410213,
0.00033810146851465106,
0.015431979671120644,
0.00853514950722456,
-0.0013354639522731304,
0.0013447123346850276,
-0.012029599398374557,
-0.0005553931114263833,
0.00731752160936594,
0.0026918891817331314,
-0.013448917306959629,
-0.9559284448623657,
0.005951261147856712,
0.002604990964755416,
-0.003945854026824236,
0.0058517055585980415,
0.001061933347955346,
0.0020947358570992947,
0.003606154816225171,
0.012816809117794037,
-0.01051201019436121,
-0.004894162528216839,
-0.012345095165073872,
-0.013097761198878288,
-0.0023439510259777308,
-0.007484822999686003,
-0.002382557839155197,
-0.005327308550477028,
-0.0077491323463618755,
-0.002638779114931822,
-0.0055796061642467976,
-0.002652691677212715,
0.011696286499500275,
-0.0041036284528672695,
0.004665262997150421,
0.0034518237225711346,
0.0020097754895687103,
-0.006582862231880426,
-0.0014020975213497877,
-0.0014235664857551455,
-0.003581817727535963,
-0.007078894414007664,
-0.013983328826725483,
-0.0026147959288209677,
-0.0024803210981190205,
0.01118090096861124,
0.0001879400369944051,
0.011362717486917973,
-0.0020563011057674885,
0.0008261200273409486,
-0.010423664003610611,
0.0037231312599033117,
0.0007671098574064672,
0.003133701626211405,
-0.027910981327295303,
-0.00046028412180021405,
-0.001161258784122765,
-0.007647660560905933,
0.00624242564663291,
0.0032294634729623795,
-0.001569261192344129,
-0.0028042132034897804,
-0.007764970418065786,
0.010463005863130093,
-0.004833144601434469,
0.005959141068160534,
-0.00467665446922183,
-0.0075988504104316235,
-0.0008997177355922759,
-0.005739005748182535,
0.001142422086559236,
0.0027986534405499697,
-0.006873606704175472,
-0.005033348686993122,
-0.003983332309871912,
0.0008388062124140561,
0.0021636129822582006,
0.001960491295903921,
-0.018064232543110847,
-0.006644001696258783,
0.001424733200110495,
0.004316030070185661,
-0.0020759087055921555,
-0.004589972551912069,
0.0023420797660946846,
-0.008578037843108177,
0.005374752450734377,
0.0015433606458827853,
0.0003505380591377616,
-0.010917595587670803,
0.0009361024131067097,
-0.009361929260194302,
-0.008548681624233723,
0.0038989540189504623,
-0.006302278954535723,
-0.005910386331379414,
-0.0016516319010406733,
0.004010346252471209,
0.006455704104155302,
-0.005024875979870558,
0.0016249677864834666,
0.008130834437906742,
-0.0013945986283943057,
-0.009011220186948776,
0.005004932172596455,
0.005922085605561733,
-0.0006209055427461863,
-0.0031909230165183544,
0.0022999029606580734,
0.007697714027017355,
0.007068794220685959,
0.0023813387379050255,
0.004976548720151186,
-0.00006984759238548577,
0.009579719975590706,
-0.002509233308956027,
0.0014067230513319373,
-0.0018445458263158798,
0.000275388709269464,
-0.003198978491127491,
0.0007553066243417561,
-0.003918711096048355,
-0.0053534614853560925,
-0.010974906384944916,
-0.008938418701291084,
-0.0047264788299798965,
0.0002215141721535474,
0.0018565349746495485,
-0.004521195776760578,
0.0004268309858161956,
0.00045992573723196983,
0.011228176765143871,
0.0029871503356844187,
-0.00317660765722394,
-0.0011702683987095952,
0.0027510584332048893,
-0.009405321441590786,
0.016217628493905067,
-0.011446109972894192,
0.007431138772517443,
-0.004467552062124014,
-0.016564490273594856,
0.008415875025093555,
0.007762834429740906,
-0.008732563816010952,
0.0002629278169479221,
0.001965541858226061,
0.004599152598530054,
0.000631654926110059,
-0.00597299262881279,
-0.003568259533494711,
-0.019406484439969063,
-0.0012110190000385046,
0.018822751939296722,
0.003722647437825799,
0.013546979986131191,
0.013908491469919682,
-0.003850871231406927,
0.0015125556383281946,
0.005014452617615461,
-0.000009478109859628603,
0.013796157203614712,
-0.00985176581889391,
0.00042838428635150194,
0.0004932741867378354,
-0.0056396364234387875,
0.00003388564437045716,
0.005064009223133326,
0.003713785670697689,
-0.004144748207181692,
0.0028906643856316805,
-0.005936495028436184,
-0.004162253346294165,
-0.016256248578429222,
-0.0036561209708452225,
0.008646083995699883,
-0.005764400120824575,
0.005178024526685476,
-0.009836990386247635,
0.004891326185315847,
0.007913137786090374,
0.003483148291707039,
-0.000037900514143984765,
0.0008023480186238885,
0.006760205142199993,
0.010271718725562096,
-0.004753604996949434,
0.0024059724528342485,
0.004615302663296461,
-0.0009231262956745923,
0.00022360002913046628,
0.009007100015878677,
-0.007680248934775591,
-0.004143720492720604,
0.003159933490678668,
0.0016047883545979857,
0.00013433376443572342,
-0.003524554893374443,
-0.007671832572668791,
-0.004738452844321728,
0.0038850053679198027,
-0.005170730408281088,
0.003936235327273607,
-0.00005016220165998675,
0.0018880799179896712,
-0.008399555459618568,
-0.0020080271642655134,
-0.0009013375965878367,
-0.01159873977303505,
0.01110760122537613,
-0.002958891214802861,
0.0032734854612499475,
0.011654580011963844,
0.004296420142054558,
-0.012676811777055264,
0.005881391931325197,
0.007899859920144081,
-0.003432131139561534,
0.004809410776942968,
0.005211816634982824,
-0.006124806124716997,
-0.02204429730772972,
-0.0017083791317418218,
-0.012809133157134056,
0.005918263457715511,
-0.001545020379126072,
0.003115149214863777,
-0.006955094635486603,
0.009165382012724876,
0.007302059791982174,
-0.013547145761549473,
-0.005494538228958845,
-0.00945664569735527,
0.009957528673112392,
-0.0007750633521936834,
-0.0006253405590541661,
-0.005202993750572205,
-0.0027919982094317675,
-0.0013959771022200584,
-0.0022252125199884176,
-0.0030104683246463537,
0.006109798327088356,
0.0014774015871807933,
-0.004057207610458136,
0.0033801626414060593,
-0.0011907744919881225,
0.0006631682626903057,
-0.000299199135042727,
-0.010239089839160442,
0.0029549887403845787,
0.006166086997836828,
-0.0034348785411566496,
-0.0046243309043347836,
0.001122103538364172,
-0.0017782236682251096,
-0.008771514520049095,
-0.011784229427576065,
-0.003961424808949232,
-0.004871131852269173,
-0.00411854637786746,
-0.010998344980180264,
-0.004159831907600164,
-0.009327985346317291,
0.009009630419313908,
-0.0075467792339622974,
0.008641182444989681,
0.002788613084703684,
-0.007048792205750942,
0.005963232833892107,
-0.004051925614476204,
0.005553710274398327,
0.001992903184145689,
0.005033064633607864,
0.0022839009761810303,
-0.005171195603907108,
-0.00812060572206974,
0.013163698837161064,
-0.0076392944902181625,
0.00269680330529809,
0.01439442578703165,
0.0036282672081142664,
0.008906546048820019,
-0.0017602263251319528,
0.00021644892694894224,
0.0031784214079380035,
0.005612910725176334,
-0.015595688484609127,
0.0027732402086257935,
-0.004743003752082586,
0.00020749772374983877,
0.0072985864244401455,
-0.006005891598761082,
0.000960736011620611,
0.008418806828558445,
0.004161761607974768,
-0.009658928960561752,
0.00028196172206662595,
0.001326312543824315,
0.004120680969208479,
-0.012569557875394821,
0.0015109740197658539,
0.0002688384265638888,
-0.003786901943385601,
-0.0027486844919621944,
-0.0034258507657796144,
0.0019204327836632729,
0.005031132139265537,
0.0012201860081404448,
0.004035349003970623,
0.0025302383583039045,
-0.00598760973662138,
0.016235852614045143,
-0.004093911498785019,
-0.0031904454808682203,
0.005217102821916342,
0.002602594904601574,
-0.003466782160103321,
-0.006980241276323795,
-0.002221468836069107,
0.002342422492802143,
0.006441736128181219,
-0.0008227925281971693,
-0.003555529983714223,
-0.001652741339057684,
-0.0019460271578282118,
-0.010944228619337082,
0.0008942257263697684,
0.01437250804156065,
-0.005266787484288216,
0.004642297513782978,
-0.0007394566782750189,
-0.005929695442318916,
-0.014635054394602776,
0.05356001853942871,
0.0010807117214426398,
0.003987280186265707,
0.007018237840384245,
-0.006197650451213121,
-0.0020313714630901814,
-0.0011293665738776326,
0.0070350621826946735,
-0.007969492115080357,
-0.00913950614631176,
0.010096095502376556,
-0.0027666613459587097,
0.0029103390406817198,
0.0052711255848407745,
-0.0018528341315686703,
0.018459340557456017,
-0.004983356222510338,
-0.016212306916713715,
-0.012883247807621956,
0.007140552159398794,
-0.005846584215760231,
-0.008133417926728725,
0.009535698220133781,
-0.001788233290426433,
0.00004172686749370769,
0.0013162599643692374,
0.006997116841375828,
-0.001666278694756329,
-0.0008963483269326389,
-0.0026674417313188314,
-0.00182301492895931,
0.0014912596670910716,
0.0029225917533040047,
0.006350814830511808,
0.010818157345056534,
-0.0024851146154105663,
0.004350598435848951,
-0.0006907189381308854,
-0.0006746197468601167,
-0.0017148522892966866,
0.0053256782703101635,
0.005148009397089481,
-0.0018886213656514883,
-0.0007711798534728587,
0.004705464467406273,
0.0023536544758826494,
0.0004834041465073824,
0.011166644282639027,
0.0029750815592706203,
-0.00484681548550725,
0.009988080710172653,
0.0074243126437067986,
-0.0007439047913067043,
0.01014240738004446,
0.0016178397927433252,
0.005538660567253828,
0.0016219825483858585,
-0.007949170656502247,
-0.014667326584458351,
-0.001067617442458868,
0.007850208319723606,
0.010142785497009754,
-0.0011699603637680411,
-0.00024125138588715345,
-0.0004910556017421186,
-0.0031218642834573984,
-0.0072179436683654785,
-0.006076999008655548,
-0.0017848131246864796,
0.0014003237010911107,
0.0035843399818986654,
0.0700373649597168,
-0.007791824638843536,
-0.0035170065239071846,
-0.009773391298949718,
0.0006976925069466233,
-0.0039049277547746897,
-0.000051131406507920474,
-0.001122721703723073,
-0.0010916485916823149,
0.002200894523411989,
0.00198886776342988,
-0.008729657158255577,
-0.013461929745972157,
0.0014734158758074045,
0.0033353420440107584,
-0.0021940714213997126,
0.004195435903966427,
0.0043916963040828705,
-0.004950841423124075,
0.0005821817321702838,
-0.010865920223295689,
0.0005298518226481974,
-0.0013288382906466722,
-0.010504930280148983,
-0.004992572125047445,
-0.004455884452909231,
0.005059948656708002,
0.0033553591929376125,
0.005191560368984938,
-0.0030500898137688637,
0.006071228533983231,
-0.003117179498076439,
-0.0014244512422010303,
-0.003478085156530142,
-0.0012537379516288638,
-0.0061488705687224865,
0.007684556767344475,
0.0020728236995637417,
-0.011565939523279667,
-0.004178580828011036,
0.0006593112484551966,
-0.000824672169983387,
-0.007704583927989006,
0.005095402244478464,
-0.0014936302322894335,
0.006653015501797199,
-0.004784717224538326,
0.00381569960154593,
-0.0031733172945678234,
0.0014634913532063365,
-0.015573889017105103,
0.004964412655681372,
-0.18059058487415314,
0.012289636768400669,
0.001917232759296894,
-0.005485408008098602,
-0.004665962420403957,
-0.013108496554195881,
-0.008489269763231277,
0.004071696661412716,
0.010409756563603878,
0.0038298300933092833,
0.0005742023349739611,
0.00006263570685405284,
0.00478085083886981,
0.004912619944661856,
-0.0019508424447849393,
-0.00336594320833683,
0.004250979050993919,
-0.00525559252128005,
0.0013478206237778068,
0.006587096955627203,
0.003733833320438862,
0.008978626690804958,
0.0018983213230967522,
0.0023644070606678724,
0.00038423595833592117,
-0.003376281587406993,
0.006031931843608618,
-0.000766031676903367,
0.006741947960108519,
-0.011026437394320965,
-0.0028684113640338182,
-0.005507306661456823,
-0.0031569297425448895,
0.002911614952608943,
0.0043757203966379166,
-0.00019063988293055445,
0.008551825769245625,
0.0016657456289976835,
-0.008201404474675655,
0.008647670969367027,
-0.00797292497009039,
0.030817639082670212,
0.005945979151874781,
0.00596581632271409,
0.0021240832284092903,
-0.007434255909174681,
-0.004432473331689835,
0.0076583512127399445,
0.0036304930690675974,
0.01508173905313015,
-0.013118560425937176,
-0.0020972387865185738,
0.0033077422995120287,
0.021412380039691925,
-0.005726127419620752,
-0.010906368494033813,
-0.0076629105024039745,
-0.0030029937624931335,
0.002434046706184745,
0.010196240618824959,
0.010845334269106388,
-0.004699893295764923,
0.008586037904024124,
-0.0002007519215112552,
-0.023650500923395157,
0.003955493215471506,
-0.0035716863349080086,
-0.006465854123234749,
0.0006386529421433806,
0.006653632503002882,
0.011224410496652126,
-0.004211414605379105,
0.003939067479223013,
0.000363588536856696,
0.006509062834084034,
-0.00029468091088347137,
0.006117250770330429,
-0.003989602904766798,
0.007546389475464821,
-0.007468380965292454,
0.010596083477139473,
-0.0071184984408319,
0.0002679025928955525,
0.002753219800069928,
-0.004824110306799412,
0.012169132940471172,
0.007998940534889698,
-0.0016560063231736422,
-0.0010401394683867693,
-0.008213120512664318,
-0.0017659945879131556,
0.0018853450892493129,
0.0028579370118677616,
-0.009030199609696865,
0.004324706736952066,
0.0011556755052879453,
0.0032351608388125896,
0.006985764484852552,
-0.00846464280039072,
0.00924797635525465,
0.004454501438885927,
-0.009175379760563374,
0.0013487209798768163,
-0.0030580274760723114,
0.0037750641349703074,
0.003451312892138958,
-0.005229209549725056,
-0.007951167412102222,
0.003092447528615594,
-0.007653455249965191,
-0.006383643019944429,
0.0032785614021122456,
-0.008795872330665588,
-0.00989167857915163,
-0.0014612195082008839,
-0.011850791051983833,
0.00096432666759938
] |
8a497075ae36fc35a089004f84ef24d85e09ec1c | 401 | py | Python | groupthink/version.py | emanuelfeld/groupthink | d8a6f666080352d396b07096cbd6304391f7c38d | [
"CC0-1.0"
] | 1 | 2017-01-09T17:27:05.000Z | 2017-01-09T17:27:05.000Z | groupthink/version.py | emanuelfeld/groupthink | d8a6f666080352d396b07096cbd6304391f7c38d | [
"CC0-1.0"
] | null | null | null | groupthink/version.py | emanuelfeld/groupthink | d8a6f666080352d396b07096cbd6304391f7c38d | [
"CC0-1.0"
] | null | null | null | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of groupthink.
# https://github.com/emanuelfeld/groupthink
# This project is in the public domain within the United States.
# Additionally, the Government of the District of Columbia waives
# copyright and related rights in the work worldwide through the CC0 1.0
# Universal public domain dedication.
__version__ = '1.0.0' # NOQA
| 28.642857 | 72 | 0.743142 | 1 | 0.7731 | [
0.002238192828372121,
0.023707307875156403,
0.007572941016405821,
0.0009514137636870146,
0.0043075354769825935,
-0.005169113166630268,
-0.009211668744683266,
0.0025784214958548546,
-0.006630641408264637,
0.001026544370688498,
0.0016979635693132877,
0.005041941534727812,
0.005043953191488981,
-0.01761133223772049,
0.004927342291921377,
0.01636103354394436,
-0.057377591729164124,
0.004304598085582256,
-0.003965246491134167,
0.0022733090445399284,
-0.0068899947218596935,
0.010464047081768513,
0.00864185206592083,
0.007145656272768974,
0.006161614321172237,
0.0021546578500419855,
0.00925080943852663,
0.0037730378098785877,
-0.008123557083308697,
-0.006406397093087435,
0.0003703086113091558,
-0.002227766439318657,
-0.006599015556275845,
-0.007953209802508354,
0.006911032367497683,
-0.0033857792150229216,
0.0009106322540901601,
-0.020148996263742447,
0.01095941849052906,
-0.004230543039739132,
-0.0060827541165053844,
-0.016659248620271683,
0.0015063139144331217,
0.006515956949442625,
-0.009051377885043621,
0.0033181533217430115,
-0.003817792749032378,
0.004028772935271263,
-0.008321994915604591,
0.0067326994612813,
-0.010659533552825451,
0.006082004401832819,
0.013955015689134598,
0.0032563440036028624,
-0.005836371798068285,
-0.005769040435552597,
0.011480855755507946,
0.0011077082017436624,
-0.0128666702657938,
0.0015040362486615777,
-0.002739854622632265,
-0.003952625207602978,
0.0029621024150401354,
0.0031896706204861403,
-0.01737130433320999,
-0.005641748663038015,
-0.003423155751079321,
0.003230293048545718,
0.0003259962541051209,
0.007130896672606468,
0.0023760541807860136,
-0.0025948339607566595,
0.006562648806720972,
0.002472223248332739,
0.004429929424077272,
-0.0036883738357573748,
-0.00023684742336627096,
0.0030667490791529417,
0.008429654873907566,
0.0027954643592238426,
0.006424102932214737,
-0.007751151453703642,
0.005994162056595087,
0.011637264862656593,
0.011938784271478653,
0.008124244399368763,
0.016586599871516228,
-0.009323748759925365,
0.04392370581626892,
0.006352824158966541,
-0.009976783767342567,
0.0012627175310626626,
-0.008739444427192211,
-0.0025642728433012962,
-0.0022682189010083675,
-0.02840905450284481,
-0.0016790601657703519,
-0.0047766659408807755,
0.000612378295045346,
0.004368656314909458,
-0.0016039714682847261,
0.0044628931209445,
-0.0009426192264072597,
-0.002869097515940666,
-0.011650076135993004,
0.012590640224516392,
-0.007584657985717058,
-0.0035505990963429213,
0.008447804488241673,
0.0019771126098930836,
-0.013355943374335766,
-0.001663344562985003,
0.0020767308305948973,
-0.010482018813490868,
0.0074110995046794415,
0.002509883837774396,
-0.006623005960136652,
0.05572809651494026,
-0.0019473953871056437,
0.001536344876512885,
-0.0032818487379699945,
0.00028519853367470205,
-0.0007584470440633595,
0.0075866058468818665,
0.008878838270902634,
-0.004489626735448837,
0.012268428690731525,
0.006364112254232168,
0.0021473902743309736,
0.007305849809199572,
-0.000549569318536669,
0.0070209866389632225,
-0.0037793912924826145,
-0.0017005248228088021,
0.0008259843452833593,
-0.0090201236307621,
0.00906845461577177,
-0.0011777888284996152,
-0.005154099781066179,
0.00013709244376514107,
-0.0005163637106306851,
-0.01129258144646883,
0.0019700396806001663,
-0.002651242772117257,
0.0028892087284475565,
-0.011143423616886139,
-0.003700614208355546,
-0.0035824989899992943,
-0.004563948605209589,
0.0019041348714381456,
0.007340181618928909,
0.0029235274996608496,
0.0027003325521945953,
-0.00709004420787096,
-0.008134931325912476,
-0.0018589425599202514,
-0.0025507549289613962,
0.0027868894394487143,
0.008457270450890064,
0.003918748814612627,
-0.00921132043004036,
-0.002265427028760314,
0.00539386598393321,
0.003590910928323865,
-0.0032410440035164356,
0.0010986628476530313,
-0.007547109853476286,
0.007680872920900583,
0.0033109330106526613,
0.004064937122166157,
0.012733761221170425,
-0.004233578220009804,
-0.0006679919897578657,
0.0002298886247444898,
0.003256784053519368,
0.0006925962516106665,
0.004798269830644131,
0.009897073730826378,
-0.0025377003476023674,
-0.004406603053212166,
0.0025029799435287714,
0.003467939794063568,
0.009644391015172005,
0.008052405901253223,
-0.0041230665519833565,
0.0024637714959681034,
-0.002608282258734107,
-0.00010393208503955975,
0.005694839172065258,
-0.0027402983978390694,
0.0056263417936861515,
0.004860979504883289,
-0.012674969621002674,
-0.0071638491936028,
0.0007396569708362222,
-0.01030055433511734,
0.00022175858612172306,
0.014052742160856724,
0.011376339942216873,
-0.0015959127340465784,
0.0036007934249937534,
-0.0096227852627635,
0.0001599570969119668,
0.006903601344674826,
0.0011685171630233526,
-0.013849176466464996,
-0.9569718837738037,
0.0031532030552625656,
0.0009324052953161299,
-0.000745641824323684,
0.00350532541051507,
0.0011133336229249835,
0.0025472657289355993,
0.0034611045848578215,
0.015395192429423332,
-0.008390760980546474,
-0.007572488859295845,
-0.008705433458089828,
-0.011206474155187607,
-0.00064482243033126,
-0.007530239876359701,
-0.0030133076943457127,
-0.005871344357728958,
-0.006319085136055946,
0.0010117106139659882,
-0.0038460323121398687,
-0.00361536699347198,
0.010079383850097656,
-0.00029930335585959256,
0.004114668816328049,
0.00327717000618577,
0.0026054277550429106,
-0.005518309306353331,
-0.000074562500230968,
-0.0011577203404158354,
-0.0030769507866352797,
-0.005360906012356281,
-0.016072595492005348,
-0.005172735080122948,
-0.0004687168402597308,
0.011868447996675968,
0.0003546306979842484,
0.008068687282502651,
-0.0015785255236551166,
0.000329311442328617,
-0.008319539949297905,
0.00450011994689703,
0.001795571413822472,
0.003971554338932037,
-0.029431192204356194,
0.0007981731905601919,
-0.0005169504438526928,
-0.008076819591224194,
0.007636122405529022,
0.0008845633710734546,
0.00011687575897667557,
-0.0019310202915221453,
-0.004751591011881828,
0.00947631150484085,
-0.009381767362356186,
0.005018220283091068,
-0.007044874597340822,
-0.006259884685277939,
-0.0038087801076471806,
-0.010087382048368454,
0.002635752083733678,
0.003340435214340687,
-0.003233421826735139,
-0.004604751244187355,
-0.004367040004581213,
0.003014869522303343,
0.0028929347172379494,
-0.0006028386414982378,
-0.016223477199673653,
-0.0061556501314044,
-0.002422244753688574,
0.003909670282155275,
-0.0034925646614283323,
-0.003357586683705449,
0.003913518041372299,
-0.009459885768592358,
0.005765598267316818,
0.0018265419639647007,
0.0006715001072734594,
-0.010225594975054264,
0.0016326145268976688,
-0.008505035191774368,
-0.008548504672944546,
0.001781551749445498,
-0.0061500282026827335,
-0.0020185576286166906,
-0.00001684918606770225,
0.0024157462175935507,
0.006418542470782995,
-0.004770854953676462,
0.004378849640488625,
0.011992405168712139,
-0.0038846556562930346,
-0.00980691984295845,
0.007446561474353075,
0.00849859043955803,
0.0006278466316871345,
-0.0029662454035133123,
-0.00006473728717537597,
0.010351099073886871,
0.00752678606659174,
0.0016766047338023782,
0.00495103420689702,
-0.0017797925975173712,
0.00993635505437851,
-0.00011147562327096239,
0.003213467774912715,
-0.00173385429661721,
-0.0019153994508087635,
-0.004092141520231962,
-0.000529207696672529,
-0.0053077926859259605,
-0.0019039441831409931,
-0.012910392135381699,
-0.011157930828630924,
-0.0023649195209145546,
0.0012087100185453892,
0.0013453810242936015,
-0.0022558951750397682,
0.0021986167412251234,
0.004483026918023825,
0.00892173033207655,
0.0011500166729092598,
-0.003671353915706277,
0.0012209888081997633,
0.0020532698836177588,
-0.00746892299503088,
0.015383119694888592,
-0.01164075918495655,
0.005592318717390299,
0.000627470959443599,
-0.015035570599138737,
0.007952024228870869,
0.009961222298443317,
-0.0061353277415037155,
0.001548985717818141,
0.0021010173950344324,
0.002404317958280444,
-0.0002458637463860214,
-0.004514945670962334,
-0.004634067416191101,
-0.016837652772665024,
0.0004180383693892509,
0.01921384409070015,
0.0034323290456086397,
0.010630450211465359,
0.011902286671102047,
-0.0032326632644981146,
0.0013829023810103536,
0.007033811882138252,
0.00037358925328589976,
0.013752613216638565,
-0.009883305989205837,
-0.0006677175988443196,
0.000666173524223268,
-0.005603034980595112,
0.0013857620069757104,
0.005506396293640137,
0.00623902166262269,
-0.004288759082555771,
0.0022702186834067106,
-0.0050176591612398624,
-0.003970929887145758,
-0.019225208088755608,
-0.003969359677284956,
0.008668284863233566,
-0.004922662395983934,
0.005278217140585184,
-0.012864982709288597,
0.005283151753246784,
0.004972763359546661,
0.003530974965542555,
-0.0017700622556731105,
-0.000977434916421771,
0.006596849299967289,
0.010221892967820168,
-0.005747651215642691,
0.001879024668596685,
0.0017127146711573005,
-0.0009335001814179122,
0.0012819895055145025,
0.007332905195653439,
-0.008489895612001419,
-0.004556301981210709,
0.0033490322530269623,
0.003670335514470935,
0.00008208087820094079,
-0.0042856778018176556,
-0.009545847773551941,
-0.004933113697916269,
0.0029174606315791607,
-0.004493756219744682,
0.004711795132607222,
0.0019445462385192513,
0.0034507939126342535,
-0.008197838440537453,
0.0017075446667149663,
-0.005278230644762516,
-0.011182020418345928,
0.009927050210535526,
-0.0027776139322668314,
0.0017685526981949806,
0.01260251086205244,
0.002641313709318638,
-0.013747158460319042,
0.005391199141740799,
0.008522401563823223,
-0.004857697989791632,
0.003899067174643278,
0.004776776768267155,
-0.004813716746866703,
-0.02281378023326397,
-0.0004464522935450077,
-0.015446717850863934,
0.008694827556610107,
-0.0018582942429929972,
0.001962136710062623,
-0.00671703927218914,
0.009425858967006207,
0.004262951202690601,
-0.011856181547045708,
-0.004222189076244831,
-0.007845662534236908,
0.006744321435689926,
-0.0027106995694339275,
-0.0028823288157582283,
-0.00259764539077878,
-0.00030617177253589034,
-0.0033763060346245766,
-0.0009243254899047315,
-0.0017151146894320846,
0.004982777405530214,
0.001790625974535942,
-0.004761237185448408,
0.0011626450577750802,
-0.0028055463917553425,
0.0005558046977967024,
0.002978338161483407,
-0.011032884009182453,
0.0007477184990420938,
0.006512101273983717,
-0.0011625356273725629,
-0.0045304629020392895,
7.245972142300161e-7,
-0.002079612109810114,
-0.005844093859195709,
-0.010911073535680771,
-0.0040695443749427795,
-0.0031288438476622105,
-0.0027337356004863977,
-0.009877373464405537,
-0.0011957308743149042,
-0.008074897341430187,
0.006760118063539267,
-0.007598072290420532,
0.007990848273038864,
0.003149721771478653,
-0.005148377735167742,
0.007229638751596212,
-0.001174701377749443,
0.0029336835723370314,
0.005514115560799837,
0.007557598873972893,
0.0006817129324190319,
-0.006613364443182945,
-0.009996186010539532,
0.012007673271000385,
-0.009721990674734116,
0.0007116197375580668,
0.013501700945198536,
0.004697091411799192,
0.011094700545072556,
0.0005472844932228327,
0.001247235108166933,
0.005103058181703091,
0.007893312722444534,
-0.015481740236282349,
0.005067114718258381,
-0.0029091620817780495,
-0.0010290786158293486,
0.005222226493060589,
-0.004207477439194918,
0.004788458812981844,
0.00794579740613699,
0.001286059501580894,
-0.007170034572482109,
-0.0025088635738939047,
0.0001247692562174052,
0.002756442641839385,
-0.010296827182173729,
0.00021605602523777634,
-0.003350315848365426,
-0.004375768359750509,
-0.004311496391892433,
-0.0014946743613108993,
-0.001296455506235361,
0.005299905780702829,
-0.0031337758991867304,
0.006830293219536543,
0.0005808266578242183,
-0.004436727147549391,
0.01418883167207241,
-0.005225006025284529,
-0.007777634542435408,
0.003413980361074209,
0.000361644197255373,
-0.0006899567670188844,
-0.007356319576501846,
-0.002600971842184663,
0.0008219979354180396,
0.0055335694923996925,
-0.003945594187825918,
-0.006654528900980949,
-0.003515740390866995,
0.0011376073816791177,
-0.008792214095592499,
0.0003974800929427147,
0.01220918633043766,
-0.00047963613178581,
0.0037081895861774683,
-0.0023628210183233023,
-0.00623996602371335,
-0.014687992632389069,
0.05557704716920853,
0.000710680556949228,
0.0032185367308557034,
0.004993055481463671,
-0.008153584785759449,
0.0005039096577093005,
-0.0015108061488717794,
0.005369176622480154,
-0.007626238279044628,
-0.009169689379632473,
0.01003408245742321,
-0.0037301299162209034,
0.0037710757460445166,
-0.0018394124926999211,
-0.0021354949567466974,
0.013272044248878956,
-0.004627495538443327,
-0.01855381205677986,
-0.016416342929005623,
0.006875935010612011,
-0.004547697026282549,
-0.00791480578482151,
0.007801375351846218,
-0.004674365743994713,
-0.0043434095568954945,
-0.00008373174932785332,
0.005537213291972876,
0.0005630275700241327,
-0.0002775696339085698,
-0.0027965926565229893,
-0.00160627078730613,
-0.000047664234443800524,
0.003495217068120837,
0.008378620259463787,
0.007966938428580761,
-0.003176330588757992,
0.004577263258397579,
-0.004108664114028215,
-0.0008326328243128955,
-0.0005695853033103049,
0.0050458768382668495,
0.005980202928185463,
-0.00298556056804955,
-0.0015388658503070474,
0.003280988661572337,
0.003602277021855116,
0.0018946538912132382,
0.009983879514038563,
-0.0014418034115806222,
-0.0039050753694027662,
0.007597154472023249,
0.007841067388653755,
-0.0011418339563533664,
0.005785323679447174,
-0.0007232999196276069,
0.005630762316286564,
0.002269137417897582,
-0.007518085651099682,
-0.013925313949584961,
-0.0030579089652746916,
0.0066115581430494785,
0.006122373975813389,
-0.0009108229423873127,
0.00199208315461874,
-0.0019338703714311123,
-0.0048842160031199455,
-0.008285226300358772,
-0.005642451345920563,
-0.004409222397953272,
0.00046635547187179327,
0.0025902381166815758,
0.07178223878145218,
-0.0056967344135046005,
-0.0015265913680195808,
-0.008237934671342373,
-0.0001671409117989242,
-0.001510139089077711,
-0.0020921295508742332,
-0.0010043783113360405,
-0.0007281366852112114,
0.0023748965468257666,
0.003733548801392317,
-0.006791558116674423,
-0.009726504795253277,
0.0011581835569813848,
0.0012807914754375815,
-0.0019128734711557627,
0.004490728490054607,
0.006877021864056587,
-0.007602456957101822,
0.003214239375665784,
-0.011380329728126526,
-0.0014162547886371613,
-0.003620031289756298,
-0.006763482000678778,
-0.0029838678892701864,
-0.003150516888126731,
0.0030688277911394835,
0.0035332716070115566,
0.006532909348607063,
-0.002181804506108165,
0.006680596154183149,
0.0002552505175117403,
-0.0006081026513129473,
-0.0034426888450980186,
-0.00005172854434931651,
-0.004710363689810038,
0.007455391809344292,
0.0005936863017268479,
-0.009868660941720009,
-0.006554088555276394,
-0.0032173211220651865,
0.00008928595343604684,
-0.006129702553153038,
0.007340726908296347,
-0.00012557583977468312,
0.006021567154675722,
-0.0034005765337496996,
0.00023737965966574848,
-0.005260827485471964,
0.0005717966123484075,
-0.012098527513444424,
0.005304261576384306,
-0.1807248443365097,
0.010329577140510082,
0.004175875801593065,
-0.00440242001786828,
-0.0036621028557419777,
-0.014527677558362484,
-0.0074869259260594845,
0.002209756523370743,
0.009324808605015278,
0.00031557719921693206,
0.0007613673224113882,
-0.0010874855797737837,
0.0039194198325276375,
0.004748332314193249,
-0.002141295000910759,
-0.006981429643929005,
0.0027952021919190884,
-0.0055902437306940556,
0.00179536163341254,
0.00412917323410511,
0.006204136647284031,
0.007349115330725908,
0.0027255171444267035,
0.003073019441217184,
-0.0020782696083188057,
-0.005927033256739378,
0.004590229596942663,
-0.0014671719400212169,
0.005863663274794817,
-0.011171712540090084,
-0.003393298014998436,
-0.003719737520441413,
-0.0021563286427408457,
-0.0014930077595636249,
0.00435284897685051,
-0.0017949093598872423,
0.008590486831963062,
0.0026142962742596865,
-0.00862170197069645,
0.006904263515025377,
-0.00728455837816,
0.029049823060631752,
0.004380831960588694,
0.008562766015529633,
-0.00032038171775639057,
-0.0043524764478206635,
-0.004105625208467245,
0.009192008525133133,
0.0012036492116749287,
0.013650979846715927,
-0.008011667057871819,
-0.004774206783622503,
0.0037386813201010227,
0.018852364271879196,
-0.005307836923748255,
-0.009512214921414852,
-0.0072660851292312145,
-0.0048340847715735435,
0.003560057608410716,
0.008823501877486706,
0.00874623004347086,
-0.004035759251564741,
0.009492469020187855,
-0.003620687173679471,
-0.020724451169371605,
0.003813717048615217,
-0.001313541317358613,
-0.008319614455103874,
0.0025975494645535946,
0.007000336889177561,
0.011201569810509682,
-0.0020385412499308586,
0.006936274468898773,
-0.003200576175004244,
0.003219163278117776,
-0.0018306070705875754,
0.006863430142402649,
-0.0021614590659737587,
0.004925525281578302,
-0.009068084880709648,
0.00931516196578741,
-0.009243717417120934,
-0.002745759440585971,
0.002799952868372202,
-0.003975971601903439,
0.009332056157290936,
0.005208601709455252,
-0.0011000391095876694,
-0.0003900632436852902,
-0.011923503130674362,
-0.0012650960125029087,
0.002317058155313134,
0.0024945619516074657,
-0.009214689023792744,
0.004047023598104715,
-0.0019832684192806482,
0.006491071078926325,
0.008799602277576923,
-0.008664611726999283,
0.004942877218127251,
0.004448854364454746,
-0.005824731197208166,
-0.001411809353157878,
-0.0051417541690170765,
0.0001255949609912932,
0.002953885355964303,
-0.007042620796710253,
-0.007463317364454269,
0.005104405339807272,
-0.005240282975137234,
-0.004302798770368099,
0.004824024625122547,
-0.011433456093072891,
-0.008869189769029617,
0.0021464843302965164,
-0.011330155655741692,
0.00004061758954776451
] |
8a49cedf036c8174ae69a9ea00ffa4a94799bd4c | 6,028 | py | Python | feeder/feeder_ucf.py | George-Polya/st-gcn | e3209796d6de160161063e4c93a00c62b35d3591 | [
"BSD-2-Clause"
] | null | null | null | feeder/feeder_ucf.py | George-Polya/st-gcn | e3209796d6de160161063e4c93a00c62b35d3591 | [
"BSD-2-Clause"
] | null | null | null | feeder/feeder_ucf.py | George-Polya/st-gcn | e3209796d6de160161063e4c93a00c62b35d3591 | [
"BSD-2-Clause"
] | null | null | null | # sys
import os
import sys
import numpy as np
import random
import pickle
import json
# torch
import torch
import torch.nn as nn
from torchvision import datasets, transforms
# operation
from . import tools
class Feeder_UCF(torch.utils.data.Dataset):
""" Feeder for skeleton-based action recognition in kinetics-skeleton dataset
Arguments:
data_path: the path to '.npy' data, the shape of data should be (N, C, T, V, M)
label_path: the path to label
random_choose: If true, randomly choose a portion of the input sequence
random_shift: If true, randomly pad zeros at the begining or end of sequence
random_move: If true, perform randomly but continuously changed transformation to input sequence
window_size: The length of the output sequence
pose_matching: If ture, match the pose between two frames
num_person_in: The number of people the feeder can observe in the input sequence
num_person_out: The number of people the feeder in the output sequence
debug: If true, only use the first 100 samples
"""
def __init__(self,
data_path,
label_path,
ignore_empty_sample=True,
random_choose=False,
random_shift=False,
random_move=False,
window_size=-1,
pose_matching=False,
num_person_in=5,
num_person_out=2,
debug=False):
self.debug = debug
self.data_path = data_path
self.label_path = label_path
self.random_choose = random_choose
self.random_shift = random_shift
self.random_move = random_move
self.window_size = window_size
self.num_person_in = num_person_in
self.num_person_out = num_person_out
self.pose_matching = pose_matching
self.ignore_empty_sample = ignore_empty_sample
self.load_data()
def load_data(self):
# load file list
self.sample_name = os.listdir(self.data_path)
if self.debug:
self.sample_name = self.sample_name[0:2]
# load label
label_path = self.label_path
with open(label_path) as f:
label_info = json.load(f)
sample_id = [name.split('.')[0] for name in self.sample_name]
self.label = np.array(
[label_info[id]['label_index'] for id in sample_id])
has_skeleton = np.array(
[label_info[id]['has_skeleton'] for id in sample_id])
# ignore the samples which does not has skeleton sequence
if self.ignore_empty_sample:
self.sample_name = [
s for h, s in zip(has_skeleton, self.sample_name) if h
]
self.label = self.label[has_skeleton]
# output data shape (N, C, T, V, M)
self.N = len(self.sample_name) #sample
self.C = 3 #channel
self.T = 90000 #frame
self.V = 18 #joint
self.M = self.num_person_out #person
def __len__(self):
return len(self.sample_name)
def __iter__(self):
return self
def __getitem__(self, index):
# output shape (C, T, V, M)
# get data
sample_name = self.sample_name[index]
sample_path = os.path.join(self.data_path, sample_name)
with open(sample_path, 'r') as f:
video_info = json.load(f)
# fill data_numpy
data_numpy = np.zeros((self.C, self.T, self.V, self.num_person_in))
count = 0
for frame_info in video_info['data']:
frame_index = frame_info['frame_index']
for m, skeleton_info in enumerate(frame_info["skeleton"]):
if m >= self.num_person_in:
break
pose = skeleton_info['pose']
score = skeleton_info['score']
frame_index = int(frame_index)
# print(frame_index)
data_numpy[0, frame_index, :, m] = pose[0::2]
data_numpy[1, frame_index, :, m] = pose[1::2]
data_numpy[2, frame_index, :, m] = score
# count += 1
# print(" ",count, " ")
# centralization
data_numpy[0:2] = data_numpy[0:2] - 0.5
data_numpy[0][data_numpy[2] == 0] = 0
data_numpy[1][data_numpy[2] == 0] = 0
# get & check label index
label = video_info['label_index']
assert (self.label[index] == label)
# data augmentation
if self.random_shift:
data_numpy = tools.random_shift(data_numpy)
if self.random_choose:
data_numpy = tools.random_choose(data_numpy, self.window_size)
elif self.window_size > 0:
data_numpy = tools.auto_pading(data_numpy, self.window_size)
if self.random_move:
data_numpy = tools.random_move(data_numpy)
# sort by score
sort_index = (-data_numpy[2, :, :, :].sum(axis=1)).argsort(axis=1)
for t, s in enumerate(sort_index):
data_numpy[:, t, :, :] = data_numpy[:, t, :, s].transpose((1, 2,
0))
data_numpy = data_numpy[:, :, :, 0:self.num_person_out]
# match poses between 2 frames
if self.pose_matching:
data_numpy = tools.openpose_match(data_numpy)
return data_numpy, label
def top_k(self, score, top_k):
assert (all(self.label >= 0))
rank = score.argsort()
hit_top_k = [l in rank[i, -top_k:] for i, l in enumerate(self.label)]
return sum(hit_top_k) * 1.0 / len(hit_top_k)
def top_k_by_category(self, score, top_k):
assert (all(self.label >= 0))
return tools.top_k_by_category(self.label, score, top_k)
def calculate_recall_precision(self, score):
assert (all(self.label >= 0))
return tools.calculate_recall_precision(self.label, score)
| 35.251462 | 104 | 0.588421 | 1 | 1.9656 | [
-0.02688375674188137,
0.026769131422042847,
-0.01598040573298931,
-0.01398613303899765,
0.004803820978850126,
-0.015692174434661865,
-0.04424211010336876,
0.002851740689948201,
0.01901642419397831,
-0.004181000869721174,
0.017846116796135902,
-0.011249734088778496,
0.016856998205184937,
0.0207846499979496,
-0.009909416548907757,
0.004521844908595085,
0.09501701593399048,
-0.00019554515893105417,
-0.046117138117551804,
-0.0011345623061060905,
0.0029106743168085814,
0.013702684082090855,
0.011721288785338402,
0.023948892951011658,
-0.004178575240075588,
0.012357550673186779,
-0.012023881077766418,
-0.023482955992221832,
0.03211556375026703,
-0.003426453797146678,
0.015373066067695618,
0.04384478181600571,
0.016240419819951057,
0.04355451837182045,
-0.025387758389115334,
0.006169356871396303,
0.0029874201864004135,
0.02176380157470703,
-0.04010798782110214,
0.014296761713922024,
-0.00046810368075966835,
-0.024643315002322197,
0.0019009750103577971,
-0.004895404446870089,
-0.02033049613237381,
0.010222516022622585,
-0.007669413927942514,
-0.03051084838807583,
-0.021352693438529968,
0.03455420583486557,
-0.02359829843044281,
0.010495039634406567,
0.019865667447447777,
-0.01749434322118759,
0.028409220278263092,
-0.05803719162940979,
0.00028650794411078095,
-0.002732084831222892,
-0.02822241187095642,
-0.011160725727677345,
-0.03540563955903053,
-0.019719386473298073,
0.011246749199926853,
-0.006367926485836506,
0.015034452080726624,
0.004467035178095102,
-0.024239320307970047,
-0.009789238683879375,
0.010359522886574268,
0.002874933648854494,
-0.013630094937980175,
-0.04148455709218979,
0.02839323692023754,
0.008474619127810001,
-0.004625491797924042,
-0.007971695624291897,
-0.043302394449710846,
-0.010918683372437954,
-0.020203717052936554,
-0.0037618710193783045,
-0.01489153690636158,
0.008994894102215767,
0.0019521224312484264,
0.005026475992053747,
0.002282031113281846,
0.029412956908345222,
0.03575124964118004,
0.02085566520690918,
0.0438685417175293,
0.026144806295633316,
-0.013359732925891876,
-0.008822929114103317,
-0.01600668579339981,
-0.014599082060158253,
-0.043040014803409576,
-0.021135617047548294,
0.013548249378800392,
-0.015706926584243774,
0.027937671169638634,
0.02840089611709118,
0.028367405757308006,
-0.029300598427653313,
0.035856943577528,
0.004625337664037943,
-0.01723472774028778,
-0.019910000264644623,
-0.05404248833656311,
0.0318753756582737,
-0.001300246687605977,
-0.01981019414961338,
-0.012264472432434559,
-0.010568481869995594,
0.015816427767276764,
-0.025716548785567284,
0.001678962609730661,
-0.03375764936208725,
-0.004650534596294165,
0.02329343371093273,
0.022742006927728653,
0.06949634850025177,
0.006436608731746674,
0.0027192675042897463,
0.019763808697462082,
-0.002428564475849271,
-0.0068275779485702515,
0.021444611251354218,
-0.00465468131005764,
-0.017788201570510864,
0.009994562715291977,
-0.006479762028902769,
0.009410497732460499,
-0.02057342603802681,
-0.0055939797312021255,
0.03568755462765694,
0.0015946021303534508,
-0.027973905205726624,
-0.04141363874077797,
-0.003931072074919939,
-0.0317656509578228,
-0.03438931703567505,
0.00957007147371769,
-0.034068141132593155,
0.013446526601910591,
0.00603519706055522,
0.007111688610166311,
-0.019363176077604294,
-0.020484860986471176,
0.03069949336349964,
-0.013244233094155788,
-0.013146591372787952,
0.017050383612513542,
0.010985302738845348,
-0.008724799379706383,
0.030542705208063126,
-0.01234061736613512,
0.0031510319095104933,
-0.015257720835506916,
-0.017020439729094505,
-0.01943298615515232,
0.03322818875312805,
-0.01512971892952919,
-0.023984195664525032,
0.019749831408262253,
0.023458819836378098,
-0.015611765906214714,
0.03611554205417633,
0.007007247768342495,
0.016564033925533295,
-0.024589207023382187,
-0.03182310238480568,
0.01327107660472393,
-0.0014522508718073368,
-0.009361650794744492,
0.02737755887210369,
-0.07077043503522873,
-0.0023180749267339706,
0.04774566739797592,
0.016426725313067436,
-0.010438535362482071,
-0.050240494310855865,
-0.004204216413199902,
-0.04452122747898102,
0.04693989083170891,
0.07027625292539597,
-0.006882236804813147,
0.012763207778334618,
0.0009034839458763599,
-0.003923880401998758,
-0.010942740365862846,
-0.029956607148051262,
0.0046073636040091515,
0.02998182736337185,
-0.013048907741904259,
-0.043011438101530075,
0.031109096482396126,
-0.039104923605918884,
0.0028825881890952587,
0.0023029532749205828,
-0.004495021887123585,
0.004496392793953419,
-0.0040277522057294846,
-0.028486870229244232,
-0.024755965918302536,
0.017129911109805107,
-0.029451869428157806,
-0.013014396652579308,
-0.7385902404785156,
0.03915455564856529,
0.03909449651837349,
0.0018418616382405162,
-0.004445191007107496,
0.03482228145003319,
-0.017506107687950134,
0.012526215054094791,
-0.034313030540943146,
-0.03162848949432373,
-0.001234613824635744,
-0.002664057770743966,
-0.01642121933400631,
0.003118974156677723,
0.016561755910515785,
-0.02640494704246521,
-0.0011980247218161821,
0.045565973967313766,
-0.020180733874440193,
0.003377266228199005,
0.013162151910364628,
0.032512594014406204,
0.011084106750786304,
0.010699470527470112,
-0.029790833592414856,
0.0006132503040134907,
-0.006699828896671534,
-0.010458526201546192,
0.05184641852974892,
0.015898210927844048,
-0.0006539368769153953,
0.0027997391298413277,
-0.00631679268553853,
-0.029547329992055893,
0.016043808311223984,
-0.020348280668258667,
0.03354400768876076,
0.01870613731443882,
-0.015895307064056396,
-0.0059595596976578236,
-0.017079394310712814,
0.03771230950951576,
0.008871521800756454,
-0.028798213228583336,
-0.04602489992976189,
-0.02448424883186817,
-0.009239927865564823,
-0.022410385310649872,
0.028779007494449615,
0.004986556246876717,
-0.006095533724874258,
0.04434550926089287,
0.03425993770360947,
-0.020116975530982018,
0.014369492419064045,
-0.01560857892036438,
-0.01835918053984642,
-0.011196170933544636,
0.006114327348768711,
0.004674246534705162,
0.011053125374019146,
0.011256151832640171,
-0.0020643901079893112,
0.01608830690383911,
0.014920847490429878,
-0.0025515188463032246,
-0.006017803214490414,
-0.036908362060785294,
-0.009200389496982098,
-0.0313505083322525,
-0.020549040287733078,
0.016237985342741013,
-0.027976565062999725,
0.01622851938009262,
-0.0029489905573427677,
0.009386799298226833,
-0.026068970561027527,
0.0067295185290277,
0.009600067511200905,
-0.02205991931259632,
-0.0008925964357331395,
0.012643013149499893,
-0.0016417773440480232,
0.01860758662223816,
-0.027453895658254623,
0.011565315537154675,
0.0331021286547184,
0.0015631100395694375,
0.0009638899937272072,
0.01644057221710682,
0.034382354468107224,
0.05452512577176094,
-0.009962683543562889,
-0.049910616129636765,
0.004172937944531441,
0.03416934609413147,
0.024491412565112114,
0.09331930428743362,
0.0020265476778149605,
0.021273087710142136,
-0.025145061314105988,
-0.0013106177793815732,
0.026549343019723892,
0.013477817177772522,
-0.015663662925362587,
0.01992216892540455,
-0.03360806405544281,
0.003050526836887002,
0.02716313861310482,
-0.05762671306729317,
0.023109272122383118,
-0.00020833374583162367,
-0.009238943457603455,
0.022329064086079597,
0.016821363940835,
-0.011579718440771103,
-0.014844835735857487,
-0.015293826349079609,
0.0617012195289135,
-0.01591811329126358,
0.01205084566026926,
-0.011999083682894707,
-0.023488055914640427,
-0.017592038959264755,
0.02016921155154705,
0.020301153883337975,
-0.019664349034428596,
-0.0016540320357307792,
0.01616956852376461,
0.006912760902196169,
-0.010991194285452366,
-0.021235179156064987,
-0.00866368506103754,
-0.015084371902048588,
-0.010844510979950428,
-0.003629544284194708,
-0.024163680151104927,
-0.03663840889930725,
0.004375150892883539,
0.00004103521496290341,
0.015243344940245152,
-0.05472682788968086,
-0.004791453015059233,
-0.04276810213923454,
-0.02605881541967392,
0.01753370277583599,
0.022138291969895363,
0.015710046514868736,
0.042989980429410934,
-0.050117943435907364,
-0.002156353322789073,
0.011475536040961742,
-0.0036969471257179976,
0.010756072588264942,
-0.0340576134622097,
-0.013363070785999298,
-0.0183744877576828,
0.011189131066203117,
0.033973563462495804,
0.010943470522761345,
-0.021483413875102997,
-0.02125656045973301,
-0.038507118821144104,
0.00820106826722622,
0.02590182237327099,
-0.03670037165284157,
-0.029729049652814865,
0.027363330125808716,
-0.011323991231620312,
0.055420152842998505,
0.02425478771328926,
-0.03447013348340988,
0.041402023285627365,
-0.011778353713452816,
0.03330410644412041,
-0.00246229930780828,
-0.008617774583399296,
-0.0362761989235878,
-0.01195439975708723,
0.03870459273457527,
-0.004544381517916918,
-0.02418832667171955,
-0.021677661687135696,
-0.04611266404390335,
0.006479123141616583,
0.03239500895142555,
0.004277801141142845,
0.020063795149326324,
0.006894739810377359,
-0.009913879446685314,
-0.009016671217978,
0.02089807577431202,
-0.030078113079071045,
-0.007146820425987244,
-0.00571442861109972,
-0.021673534065485,
-0.00916952732950449,
0.015436514280736446,
0.01630605012178421,
-0.014767545275390148,
-0.010861178860068321,
-0.0031209327280521393,
0.019143618643283844,
-0.022661445662379265,
0.01995689980685711,
0.06567420810461044,
0.01928393915295601,
-0.015262169763445854,
0.014789547771215439,
0.004561364185065031,
0.00659073144197464,
-0.02036909945309162,
0.02492188662290573,
-0.018278298899531364,
-0.04891307279467583,
0.010108227841556072,
-0.0032713657710701227,
-0.033174578100442886,
-0.01578453555703163,
-0.02247135527431965,
-0.029023105278611183,
-0.03796153888106346,
0.05254343897104263,
0.009308785200119019,
-0.015331936068832874,
0.006886476185172796,
-0.011890960857272148,
-0.005491249728947878,
0.0077765281312167645,
0.020642975345253944,
0.0007861449848860502,
0.011213487945497036,
0.01343574095517397,
-0.013772948645055294,
0.012004050426185131,
0.02329179458320141,
0.001404676935635507,
-0.00417723273858428,
-0.006693069823086262,
0.00015272770542651415,
0.038672465831041336,
-0.050681330263614655,
-0.01771499775350094,
0.035229939967393875,
0.019349418580532074,
0.002110214438289404,
0.009327766485512257,
-0.010325665585696697,
-0.03173404932022095,
0.017633376643061638,
-0.028381124138832092,
0.07731647044420242,
0.007030082400888205,
-0.0021620572078973055,
-0.0062160855159163475,
0.0004285163595341146,
0.021373411640524864,
0.015806663781404495,
0.01434340886771679,
-0.004552960395812988,
-0.022095201537013054,
-0.013900857418775558,
0.0015603970969095826,
0.019306248053908348,
0.03231162577867508,
-0.0044072652235627174,
-0.04422788694500923,
0.003868937725201249,
-0.019574789330363274,
0.01820577122271061,
0.008086070418357849,
-0.032203540205955505,
-0.017612917348742485,
-0.03967030718922615,
0.004229370970278978,
0.02326940931379795,
-0.001473508425988257,
-0.02727791666984558,
-0.02297327294945717,
0.02067970298230648,
0.013031002134084702,
-0.0122169004753232,
0.05444374307990074,
0.01998347043991089,
0.02256661280989647,
-0.008523409254848957,
-0.03559935837984085,
-0.013109070248901844,
-0.03368225693702698,
-0.013273121789097786,
0.005013273563235998,
0.003951135091483593,
0.015349777415394783,
0.062084536999464035,
-0.029537063091993332,
0.002243978437036276,
-0.006123719736933708,
-0.022042298689484596,
0.016849683597683907,
0.032668549567461014,
0.028465576469898224,
0.030729180201888084,
-0.009465503506362438,
-0.031520336866378784,
0.00600733095780015,
-0.03683222830295563,
0.006346519570797682,
0.02885895036160946,
0.017432313412427902,
0.011741695925593376,
0.016720380634069443,
0.026038553565740585,
-0.009550810791552067,
0.004996714182198048,
0.0072245211340487,
-0.001161364489234984,
0.06023797392845154,
-0.001262454898096621,
-0.02475617825984955,
-0.009012365713715553,
0.007293043192476034,
0.06200754642486572,
-0.016525650396943092,
-0.007912999950349331,
0.0005045837024226785,
-0.011379405856132507,
0.008273979648947716,
0.0013043999206274748,
0.009586463682353497,
-0.020714273676276207,
-0.020083094015717506,
-0.01943405531346798,
0.001720393542200327,
-0.008628851734101772,
0.004069081973284483,
0.002806409727782011,
0.02432774007320404,
0.03804396465420723,
0.025745529681444168,
-0.03152924403548241,
0.006298196502029896,
-0.0039843604899942875,
-0.03346392512321472,
-0.011512616649270058,
-0.013684087432920933,
-0.009308042004704475,
-0.04250514507293701,
0.05013834685087204,
0.02063211239874363,
0.03815842792391777,
0.004825842101126909,
0.035128600895404816,
0.004036308266222477,
-0.010364070534706116,
0.02201496623456478,
-0.02402857318520546,
0.00365678989328444,
0.02703612856566906,
0.0141445966437459,
0.011037285439670086,
-0.017837677150964737,
-0.009564608335494995,
0.00977092981338501,
-0.010620154440402985,
0.000027367286747903563,
-0.037892017513513565,
0.0038533606566488743,
-0.024158846586942673,
-0.007390410639345646,
0.014914293773472309,
-0.031414978206157684,
-0.006739060394465923,
0.015074193477630615,
0.0064259604550898075,
0.016727812588214874,
0.03533494845032692,
0.01748429797589779,
0.011908131651580334,
-0.02852250449359417,
-0.07124559581279755,
0.009010492824018002,
-0.012500937096774578,
0.03119305893778801,
-0.04846249520778656,
0.024305807426571846,
-0.03853437304496765,
0.01389643270522356,
0.02858326956629753,
-0.020285475999116898,
-0.015329916961491108,
-0.022294484078884125,
-0.024900661781430244,
0.004018931183964014,
0.014347624965012074,
0.004711488727480173,
-0.01467890478670597,
-0.011758754961192608,
-0.004730727057904005,
0.0018361577531322837,
-0.0035269656218588352,
0.016987113282084465,
0.006170660723000765,
0.0060395896434783936,
0.0014638142893090844,
0.005488652270287275,
-0.011420215480029583,
0.030703749507665634,
-0.013193774968385696,
-0.006539121735841036,
-0.002141498727723956,
0.008780187927186489,
0.04181826114654541,
-0.02714085765182972,
0.00577235734090209,
-0.004372873809188604,
0.007680648472160101,
-0.029106080532073975,
0.040835894644260406,
-0.017167283222079277,
0.020127838477492332,
-0.004586596041917801,
-0.04708300903439522,
-0.01922699250280857,
-0.011491671204566956,
-0.005721615627408028,
-0.038615934550762177,
-0.008042169734835625,
-0.013848149217665195,
0.0004665528831537813,
0.02364734187722206,
-0.03617722913622856,
-0.02108556218445301,
-0.014409788884222507,
0.026622498407959938,
0.024197520688176155,
-0.030739422887563705,
-0.005879411939531565,
0.00215677497908473,
0.007450104225426912,
0.020424215123057365,
0.009138248860836029,
0.013669944368302822,
0.0071886866353452206,
0.05165571719408035,
0.04390744864940643,
-0.1065363883972168,
0.029558656737208366,
0.017867980524897575,
-0.007145271170884371,
-0.025078866630792618,
-0.03014007769525051,
0.004515987820923328,
-0.014151005074381828,
0.035339247435331345,
0.027463627979159355,
0.011023322120308876,
0.041702453047037125,
0.03598489239811897,
-0.024903403595089912,
0.015627700835466385,
0.01822291873395443,
-0.008413625881075859,
0.005060295574367046,
0.005023512989282608,
0.032198864966630936,
0.009045509621500969,
0.008239831775426865,
0.003624961944296956,
0.04956553503870964,
-0.009077707305550575,
0.011460807174444199,
-0.01657969504594803,
-0.014202567748725414,
0.01844487152993679,
-0.017383141443133354,
0.0033175661228597164,
0.015475471504032612,
0.016940928995609283,
0.001460882369428873,
-0.01596892438828945,
-0.036835331469774246,
0.03288641571998596,
0.007690988481044769,
0.005860574543476105,
0.004449869971722364,
-0.0129722123965621,
-0.041601669043302536,
-0.006466230843216181,
-0.006028261501342058,
0.02718289941549301,
-0.00441217515617609,
-0.019946422427892685,
-0.011076346039772034,
0.010022154077887535,
0.012506661005318165,
-0.0156398955732584,
0.017050614580512047,
-0.02543225698173046,
0.03732716664671898,
-0.014553876593708992,
-0.008111830800771713,
-0.004956848453730345,
0.0015642447397112846,
-0.04482409730553627,
0.030550748109817505,
-0.005503708962351084,
0.0857425108551979,
-0.008733076974749565,
-0.026998406276106834,
0.022796090692281723,
-0.0147373853251338,
-0.019437529146671295,
-0.03184209018945694,
0.0036138829309493303,
0.003320324933156371,
0.03195212781429291,
0.010095535777509212,
-0.0002690624096430838,
0.00409069936722517,
-0.011947430670261383,
0.021224698051810265,
0.036720264703035355,
-0.0191494170576334,
-0.05665706470608711,
-0.0018177113961428404,
0.010392776690423489,
-0.042936794459819794,
0.02210390940308571,
0.001549009932205081,
0.0155332675203681,
0.00529275368899107,
0.0056515587493777275,
-0.02265366166830063,
-0.00403630081564188,
0.006300835404545069,
-0.047482576221227646,
0.022591136395931244,
0.06262876093387604,
-0.007943098433315754,
-0.04912051185965538,
0.04484884813427925,
0.010563402436673641,
0.023054594174027443,
-0.010989592410624027,
-0.022176628932356834,
-0.01906622014939785,
0.008204376325011253,
-0.023215560242533684,
-0.0073609002865850925,
0.024756185710430145,
-0.013854959048330784,
-0.035371746867895126,
0.008463523350656033,
-0.015439920127391815,
-0.008546438999474049,
-0.03632712736725807,
0.02168506570160389,
-0.044954098761081696,
0.02326783537864685,
-0.05232151970267296,
-0.009887303225696087,
0.004911365918815136
] |
8a49e6407bf66d6fbb676497c6a102a344eeed6b | 2,533 | py | Python | apps/core/migrations/0001_initial.py | Visualway/Vitary | c7db9a25837fa7390b2177b9db48e73c6f1ab3c8 | [
"BSD-3-Clause"
] | 4 | 2021-12-24T16:07:44.000Z | 2022-03-04T02:30:20.000Z | apps/core/migrations/0001_initial.py | Visualway/Vitary | c7db9a25837fa7390b2177b9db48e73c6f1ab3c8 | [
"BSD-3-Clause"
] | 4 | 2021-12-30T13:32:56.000Z | 2022-03-15T03:58:48.000Z | apps/core/migrations/0001_initial.py | Visualway/Vitary | c7db9a25837fa7390b2177b9db48e73c6f1ab3c8 | [
"BSD-3-Clause"
] | null | null | null | # Generated by Django 4.0.2 on 2022-03-02 03:29
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('vit', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Badge',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('description', models.TextField()),
('color', models.CharField(choices=[('success', 'Green'), ('info', 'Blue'), ('link', 'Purple'), ('primary', 'Turquoise'), ('warning', 'Yellow'), ('danger', 'Red'), ('dark', 'Black'), ('white', 'White')], max_length=50)),
('special', models.BooleanField(default=False)),
],
options={
'ordering': ['name'],
},
),
migrations.CreateModel(
name='Requirments',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('description', models.TextField()),
('badge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.badge')),
],
options={
'ordering': ['name'],
},
),
migrations.CreateModel(
name='Abuse',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('abuse_type', models.CharField(choices=[('ABUSE', 'Abuse'), ('INAPPROPRIATE', 'Inappropriate'), ('SPAM', 'Spam'), ('BULLYING', 'Bullying'), ('SEXUAL_CONTENT', 'Sexual Content'), ('OTHER', 'Other')], max_length=50)),
('description', models.TextField()),
('date', models.DateTimeField(auto_now_add=True)),
('to_vit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vit.vit')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'Abuses',
'ordering': ['-date'],
},
),
]
| 42.932203 | 236 | 0.55073 | 1 | 1.4046 | [
0.0013336852425709367,
0.023791702464222908,
0.00946816522628069,
0.0017550019547343254,
0.004307304508984089,
-0.004891887307167053,
-0.011395485140383244,
0.0029208576306700706,
-0.008449153043329716,
0.0033819875679910183,
0.004310282878577709,
0.005559387616813183,
0.005709102377295494,
-0.017968108877539635,
0.002868441166356206,
0.017356783151626587,
-0.051988448947668076,
0.002774134511128068,
-0.004080167040228844,
0.0013308334164321423,
-0.006666432600468397,
0.009041494689881802,
0.01097107958048582,
0.006253939121961594,
0.006284026429057121,
-0.0024581179022789,
0.008789732120931149,
0.003405278315767646,
-0.00859999842941761,
-0.006101230625063181,
-0.0012743654660880566,
-0.003202863037586212,
-0.006818970199674368,
-0.008566932752728462,
0.005709577351808548,
-0.0027001602575182915,
0.0005079132970422506,
-0.020724643021821976,
0.012443237006664276,
-0.001803096616640687,
-0.008973930031061172,
-0.017976799979805946,
-0.000021296753402566537,
0.0037851447705179453,
-0.01026585791260004,
0.00045417671208269894,
-0.004626523703336716,
0.004086017608642578,
-0.009790055453777313,
0.006532005500048399,
-0.010582960210740566,
0.004690555855631828,
0.013497255742549896,
0.0048864553682506084,
-0.004502611234784126,
-0.006291821599006653,
0.012315414845943451,
0.0007842647028155625,
-0.010791070759296417,
-0.0006736276554875076,
-0.003080984577536583,
-0.0023551119957119226,
0.005838774144649506,
0.0005417099455371499,
-0.017239896580576897,
-0.007088009268045425,
-0.004186740145087242,
0.0036497802939265966,
-0.0003844487655442208,
0.004802154842764139,
0.0005824763211421669,
0.000019851870092679746,
0.006887632887810469,
0.004967980552464724,
0.005505649372935295,
-0.0027630538679659367,
-0.0009746536379680037,
0.0017698521260172129,
0.008619416505098343,
0.003756432794034481,
0.005432815756648779,
-0.006924051325768232,
0.006034604273736477,
0.009207772091031075,
0.013987112790346146,
0.005971737205982208,
0.020957961678504944,
-0.012483618222177029,
0.04677354916930199,
0.007237885147333145,
-0.010804140008985996,
0.0031189871951937675,
-0.008191997185349464,
-0.0007579720113426447,
-0.0021329449955374002,
-0.027280189096927643,
0.000022928641556063667,
-0.004038351587951183,
0.001342164003290236,
0.0005608531064353883,
-0.0003464395413175225,
0.007285669911652803,
-0.0009323660633526742,
-0.0025520138442516327,
-0.007793779019266367,
0.013958653435111046,
-0.008726328611373901,
-0.0038356014993041754,
0.006565820425748825,
0.00292594195343554,
-0.01074210088700056,
-0.0006796286324970424,
0.0014240446034818888,
-0.012624003924429417,
0.004196467809379101,
0.003523393999785185,
-0.005477054510265589,
0.05426960438489914,
-0.000530197168700397,
0.0034805412869900465,
-0.006047347094863653,
0.0016953598242253065,
0.001991851720958948,
0.007227279711514711,
0.006924238987267017,
-0.0040320465341210365,
0.0101895397529006,
0.008128160610795021,
0.0037407090421766043,
0.00851746927946806,
-0.002910326234996319,
0.007374097127467394,
-0.00473908893764019,
-0.0035004953388124704,
0.0010440147016197443,
-0.008381103165447712,
0.008555875159800053,
-0.0021148992236703634,
-0.007593533955514431,
0.0007176347426138818,
-0.0014342860085889697,
-0.010659303516149521,
0.0016609268495813012,
-0.004231876693665981,
0.001884095137938857,
-0.011968850158154964,
-0.0028276729863137007,
-0.0022125921677798033,
-0.0044792043045163155,
0.0042215450666844845,
0.010089228861033916,
0.004534135106950998,
0.003811970818787813,
-0.005983205046504736,
-0.009924410842359066,
0.0016876214649528265,
-0.0034401249140501022,
0.0021345459390431643,
0.006750046741217375,
0.004001587629318237,
-0.009391626343131065,
0.0003366178134456277,
0.0027744716499000788,
0.0037369411438703537,
-0.0012999989558011293,
0.0011212321696802974,
-0.00944547913968563,
0.00851536262780428,
-0.0010804332559928298,
0.004147494211792946,
0.009552338160574436,
-0.006869792938232422,
-0.0015801690751686692,
-0.0004569420125335455,
0.00244042812846601,
-0.0005398275097832084,
0.004548068158328533,
0.010829471051692963,
-0.0031432306859642267,
-0.00453793304041028,
0.003406174946576357,
0.0058256457559764385,
0.00862022116780281,
0.005535541567951441,
-0.0006995403673499823,
0.00206300662830472,
-0.0048663741908967495,
-0.0004844238283112645,
0.004531726241111755,
-0.004279178101569414,
0.004735096357762814,
0.0019272484350949526,
-0.014926750212907791,
-0.007246163208037615,
0.0012692149030044675,
-0.009657174348831177,
0.0022664181888103485,
0.015445184893906116,
0.011197664774954319,
-0.00256923446431756,
0.0034500746987760067,
-0.008961847051978111,
0.0012985026696696877,
0.00491013890132308,
0.002422872930765152,
-0.012961429543793201,
-0.9577170610427856,
0.006750214844942093,
0.002373676747083664,
-0.0010277455439791083,
0.004484059289097786,
0.004407861735671759,
0.0015581385232508183,
0.0040956116281449795,
0.014448021538555622,
-0.00873351376503706,
-0.006791394203901291,
-0.009913885965943336,
-0.009760699234902859,
-0.002219634596258402,
-0.008887901902198792,
-0.003714723279699683,
-0.005290464032441378,
-0.007166325580328703,
-0.0009689969592727721,
-0.005464544054120779,
-0.003434237325564027,
0.008308637887239456,
-0.0011072426568716764,
0.005983924493193626,
0.005667723249644041,
0.003249515313655138,
-0.0036119373980909586,
-0.0002659328165464103,
-0.003711306257173419,
-0.0026239901781082153,
-0.008325474336743355,
-0.014604460448026657,
-0.006238391622900963,
0.00013865047367289662,
0.009951910935342312,
0.0007317141862586141,
0.009153513237833977,
-0.0024290659930557013,
0.001320790615864098,
-0.008076492697000504,
0.004520772956311703,
-0.00021465439931489527,
0.0024827225133776665,
-0.02827497571706772,
0.001629770384170115,
-0.0017238606233149767,
-0.006683084182441235,
0.009171715006232262,
-0.00021365507564041764,
-0.002021799562498927,
-0.004362049046903849,
-0.003970167133957148,
0.007403605151921511,
-0.007247129920870066,
0.004066258203238249,
-0.004985947627574205,
-0.007544077932834625,
-0.0017531594494357705,
-0.008548123762011528,
0.0023074487689882517,
0.0031377228442579508,
-0.0032068677246570587,
-0.004885124042630196,
-0.0036919403355568647,
0.0027795969508588314,
0.0035816419404000044,
0.0025956062600016594,
-0.017496291548013687,
-0.005906866397708654,
0.000560921966098249,
0.0014730861876159906,
-0.0038264128379523754,
-0.005327941849827766,
0.004973262548446655,
-0.00910365954041481,
0.007338826544582844,
0.003524795174598694,
-0.0012082417961210012,
-0.012163848616182804,
0.0019164921250194311,
-0.010575799271464348,
-0.00892407726496458,
0.0016387361101806164,
-0.005627513397485018,
-0.004217194858938456,
-0.0022018649615347385,
0.0004306510672904551,
0.008465582504868507,
-0.005437314044684172,
0.0052238465286791325,
0.010939433239400387,
-0.00389390392228961,
-0.008512957021594048,
0.008490977808833122,
0.007597774267196655,
0.0018937567947432399,
-0.0034602528903633356,
0.0019524323288351297,
0.008873235434293747,
0.007104669697582722,
0.0031533935107290745,
0.0048414673656225204,
-0.0003281450772192329,
0.007914287969470024,
-0.0016755020478740335,
0.001826650113798678,
-0.0037297483067959547,
-0.0012835045345127583,
-0.0030924263410270214,
-0.0009763126727193594,
-0.001217238255776465,
-0.0017275437712669373,
-0.012884257361292839,
-0.01004329975694418,
-0.0028077871538698673,
0.0012703698594123125,
0.0010603107511997223,
-0.0024519325233995914,
0.00027011995553039014,
0.002709802472963929,
0.0075837671756744385,
0.00013850501272827387,
-0.004442277830094099,
0.00002246039002784528,
-0.00030771640012972057,
-0.008017269894480705,
0.015141768380999565,
-0.01311557088047266,
0.005986376665532589,
0.000635027710814029,
-0.015673872083425522,
0.007170018739998341,
0.008874285966157913,
-0.009757405146956444,
0.0004032883152831346,
0.003987165633589029,
0.003557984484359622,
0.001762201078236103,
-0.004375477787107229,
-0.002574857557192445,
-0.015726512297987938,
-0.002245706506073475,
0.01980561763048172,
0.002773297717794776,
0.010407577268779278,
0.013761683367192745,
-0.005690855905413628,
0.002381125232204795,
0.005820190999656916,
0.001840871525928378,
0.012667430564761162,
-0.010643765330314636,
-0.00020193347882013768,
0.003055261680856347,
-0.0051189265213906765,
-0.0005899788229726255,
0.007568833418190479,
0.006718612276017666,
-0.003788834437727928,
0.0016139220679178834,
-0.0072494857013225555,
-0.0045735095627605915,
-0.019189292564988136,
-0.0022185631096363068,
0.007797864731401205,
-0.006547862663865089,
0.006003466434776783,
-0.011195872910320759,
0.007594905328005552,
0.00659537548199296,
-0.00018962181638926268,
0.0004902770160697401,
-0.0014105364680290222,
0.007251971401274204,
0.013665424659848213,
-0.0052637699991464615,
0.0023192954249680042,
0.0023732539266347885,
-0.000986729166470468,
0.0016137018101289868,
0.009742479771375656,
-0.008953467942774296,
-0.0036865572910755873,
0.0022204553242772818,
0.005226546432822943,
0.00010861029295483604,
-0.004130396991968155,
-0.008734093979001045,
-0.0027183489874005318,
0.0022503843065351248,
-0.005246281623840332,
0.005175925325602293,
0.0024757706560194492,
0.004532288294285536,
-0.004619921557605267,
0.00005848539876751602,
-0.0031933498103171587,
-0.010977664962410927,
0.01156217698007822,
-0.002771492348983884,
0.002755039604380727,
0.012946369126439095,
0.0027067442424595356,
-0.013548084534704685,
0.006448382046073675,
0.009677155874669552,
-0.004571316763758659,
0.0035591728519648314,
0.005926334299147129,
-0.006033611949533224,
-0.02405535988509655,
-0.0002653361007105559,
-0.013187088072299957,
0.005109654739499092,
-0.0021085545886307955,
0.0039508286863565445,
-0.0074370973743498325,
0.007212996017187834,
0.006956072058528662,
-0.0133975800126791,
-0.006390030030161142,
-0.008236554451286793,
0.009769282303750515,
-0.0006008266936987638,
-0.0018953087273985147,
-0.0042143031023442745,
-0.0014782382640987635,
-0.0023364024236798286,
-0.0029846683610230684,
-0.0015715878689661622,
0.005167172756046057,
0.0005224435008130968,
-0.004721165169030428,
-0.0004164949059486389,
-0.004452250432223082,
-0.0008537937537766993,
0.0019269066397100687,
-0.010516337119042873,
0.0020428518764674664,
0.004162623547017574,
-0.002442248398438096,
-0.0021923857275396585,
0.002123461803421378,
-0.00178352405782789,
-0.008394674398005009,
-0.011136998422443867,
-0.0036065527237951756,
-0.0053271702490746975,
-0.0023685332853347063,
-0.011767159216105938,
-0.002060864819213748,
-0.008485112339258194,
0.004111193586140871,
-0.006187220569700003,
0.0069464403204619884,
0.00498666288331151,
-0.007431363686919212,
0.00659959577023983,
-0.003518270328640938,
0.0042487857863307,
0.005293303169310093,
0.008015874773263931,
-0.0017999267438426614,
-0.00573962414637208,
-0.009815155528485775,
0.01089757401496172,
-0.008078811690211296,
0.0007090208819136024,
0.014103276655077934,
0.005010249558836222,
0.008212368935346603,
0.0016456132289022207,
0.0009260683436878026,
0.0038339386228471994,
0.005401276051998138,
-0.01401996798813343,
0.001890947693027556,
-0.004160804208368063,
-0.001291331835091114,
0.0053028869442641735,
-0.004836382810026407,
0.0030003227293491364,
0.00928578246384859,
0.0007278592092916369,
-0.007698976434767246,
-0.003558096010237932,
0.0018536776769906282,
0.004866946022957563,
-0.01127686258405447,
0.001370181329548359,
-0.0027738565113395452,
-0.004339361097663641,
-0.001621645293198526,
-0.0030942296143621206,
-0.0004932532319799066,
0.004014860838651657,
-0.004037043545395136,
0.005719230975955725,
0.0022048824466764927,
-0.004464741796255112,
0.014007787220180035,
-0.007787816692143679,
-0.005921189207583666,
0.0017382187070325017,
0.0013311024522408843,
-0.002433021320030093,
-0.006801029667258263,
-0.003333735279738903,
0.0013699709670618176,
0.0051993513479828835,
-0.0026278970763087273,
-0.005623980890959501,
-0.0004959098296239972,
0.0024396004155278206,
-0.007866648025810719,
0.002632533200085163,
0.011950376443564892,
-0.00379168544895947,
0.005333638750016689,
-0.002557918196544051,
-0.008352410048246384,
-0.014649626798927784,
0.05491258576512337,
-0.0019383311737328768,
0.003935794811695814,
0.00443385960534215,
-0.00543671241030097,
-0.0008032476180233061,
-0.001495694974437356,
0.007096700370311737,
-0.005872283596545458,
-0.007115150801837444,
0.008225587196648121,
-0.0036103923339396715,
0.0028611719608306885,
0.001230750698596239,
-0.0014597515109926462,
0.015253318473696709,
-0.0048187351785600185,
-0.01717318780720234,
-0.014763937331736088,
0.007967636920511723,
-0.004062801133841276,
-0.006023995578289032,
0.010232692584395409,
-0.0014296375447884202,
-0.004257386550307274,
0.001122667919844389,
0.007122167386114597,
0.0006941490573808551,
-0.0010691863717511296,
-0.003731650533154607,
-0.0007496350444853306,
-0.0017180840950459242,
0.00287565216422081,
0.005774485878646374,
0.006488015875220299,
-0.0019534591119736433,
0.0049109626561403275,
-0.004292322788387537,
-0.0010853448184207082,
-0.0005947312456555665,
0.006049037910997868,
0.007394420448690653,
-0.00018757488578557968,
0.0013814241392537951,
0.006548677571117878,
0.004117049276828766,
0.0024079643189907074,
0.011366331949830055,
0.00009073373075807467,
-0.00471411133185029,
0.00964324176311493,
0.006813873536884785,
-0.00033773225732147694,
0.006487634498625994,
-0.0009014767711050808,
0.006971477996557951,
0.0029802140779793262,
-0.0056025180965662,
-0.013710136525332928,
-0.00273665483109653,
0.007133234292268753,
0.007127853110432625,
-0.002573934616521001,
0.002378094708546996,
-0.0027537373825907707,
-0.0008766070823185146,
-0.004613226745277643,
-0.006265969946980476,
-0.0022838041186332703,
0.000625249813310802,
0.006380230654031038,
0.06889684498310089,
-0.006783829536288977,
-0.0010682243155315518,
-0.008273140527307987,
-0.0005900040850974619,
-0.0021106312051415443,
-0.002167580183595419,
-0.0002654304844327271,
-0.0013770172372460365,
0.0007943465025164187,
0.0034056336153298616,
-0.0053627388551831245,
-0.010378360748291016,
0.0009161756606772542,
0.002678502118214965,
-0.002044746419414878,
0.005362172611057758,
0.003478479338809848,
-0.008620320819318295,
0.0011095369700342417,
-0.01152045838534832,
-0.002969448221847415,
-0.00283918553031981,
-0.00897141546010971,
-0.002987418556585908,
-0.004403054714202881,
0.0030898586846888065,
0.0010157983051612973,
0.007879247888922691,
-0.0031986639369279146,
0.005806135479360819,
-0.00387183646671474,
-0.0006721809622831643,
-0.003940016496926546,
-0.0009326553554274142,
-0.005896745249629021,
0.008804050274193287,
0.0005375486798584461,
-0.008712355978786945,
-0.004743665922433138,
-0.002183664822950959,
-0.0010448383400216699,
-0.0053184316493570805,
0.0019622957333922386,
0.00021801056573167443,
0.008548825047910213,
-0.0020436744671314955,
0.0023550575133413076,
-0.004015610087662935,
0.0012548565864562988,
-0.013554609380662441,
0.004488843493163586,
-0.178603857755661,
0.009293202310800552,
0.00310907862149179,
-0.0064244051463902,
-0.003090990474447608,
-0.01314834039658308,
-0.006168347783386707,
0.0037574381567537785,
0.008826086297631264,
0.0031508251558989286,
-0.001827163272537291,
-0.0021304741967469454,
0.001961237285286188,
0.003835622686892748,
-0.0028952443972229958,
-0.00414267648011446,
0.004092761315405369,
-0.005798514001071453,
0.0012028667842969298,
0.004309710115194321,
0.0031867544166743755,
0.008542729541659355,
0.001526626292616129,
0.0028125529643148184,
-0.00003737051520147361,
-0.005589745007455349,
0.006402226630598307,
-0.0029707211069762707,
0.005777318496257067,
-0.011700299568474293,
-0.0052498760633170605,
-0.0032721797470003366,
-0.002588627627119422,
0.0009747482254169881,
0.003217503661289811,
-0.0003007013292517513,
0.008007925935089588,
0.0009501053718850017,
-0.009002345614135265,
0.008143702521920204,
-0.0065811132080852985,
0.026143603026866913,
0.006845508236438036,
0.006486496888101101,
0.0005856124917045236,
-0.005530713126063347,
-0.0038882908411324024,
0.009123682975769043,
0.0021847637835890055,
0.012814471498131752,
-0.013081940822303295,
-0.0014395634643733501,
0.0031097426544874907,
0.01956423930823803,
-0.0038390473928302526,
-0.010758675634860992,
-0.00670597655698657,
-0.004759184550493956,
0.002746281214058399,
0.0075288619846105576,
0.008687304332852364,
-0.004312806762754917,
0.008313504047691822,
-0.0023487189318984747,
-0.02424042858183384,
0.00334372092038393,
-0.003907954320311546,
-0.007913481444120407,
0.0037438247818499804,
0.007513056509196758,
0.01001111138612032,
-0.0018087492790073156,
0.000837814062833786,
-0.0013431647093966603,
0.004908647388219833,
0.00030707637779414654,
0.00612664083018899,
-0.0015737711219117045,
0.0058672549203038216,
-0.009189782664179802,
0.006107688415795565,
-0.007248707581311464,
-0.004683168604969978,
0.002633260330185294,
-0.003615131601691246,
0.010190779343247414,
0.004032493103295565,
-0.0034922780469059944,
-0.00044620936387218535,
-0.009357682429254055,
-0.0004040372441522777,
0.001791242160834372,
0.0016572035383433104,
-0.007802130188792944,
0.001949014374986291,
0.001228872686624527,
0.0027145370841026306,
0.007316697854548693,
-0.009576312266290188,
0.006988462060689926,
0.005553658585995436,
-0.0038462600205093622,
-0.00018514676776248962,
-0.0031282808631658554,
0.0021896464750170708,
0.004464506171643734,
-0.004089933820068836,
-0.006474452558904886,
0.00041762233013287187,
-0.006303469650447369,
-0.005890257190912962,
0.007965083234012127,
-0.009224997833371162,
-0.010616944171488285,
-0.0007567696156911552,
-0.01024414412677288,
0.002217296278104186
] |
8a4a2deaf316f920a36e808eb86cd1a1c9c75edd | 2,260 | py | Python | tests/common/schema_registry.py | epiphany-platform/cdl-temporary | daa704f379c05d7b733c382058ff88a2549d33d7 | [
"Apache-2.0"
] | 8 | 2020-11-04T10:32:03.000Z | 2021-09-08T16:46:13.000Z | tests/common/schema_registry.py | epiphany-platform/cdl-temporary | daa704f379c05d7b733c382058ff88a2549d33d7 | [
"Apache-2.0"
] | 418 | 2020-11-05T12:43:26.000Z | 2021-10-19T02:24:43.000Z | tests/common/schema_registry.py | epiphany-platform/cdl-temporary | daa704f379c05d7b733c382058ff88a2549d33d7 | [
"Apache-2.0"
] | 13 | 2020-11-18T12:37:42.000Z | 2021-09-16T07:43:27.000Z | import os
import subprocess
import time
import grpc
import tests.rpc.proto.schema_registry_pb2 as pb2
import tests.rpc.proto.schema_registry_pb2_grpc as pb2_grpc
from tests.common.postgres import PostgresConfig
EXE = os.getenv('SCHEMA_REGISTRY_EXE') or 'schema-registry'
class SchemaRegistry:
def __init__(self,
edge_registry_addr,
kafka_brokers,
postgres_config: PostgresConfig,
kafka_group_id='schema_registry',
input_port='50101',
initial_schema=None):
self.edge_registry_addr = edge_registry_addr
self.kafka_brokers = kafka_brokers
self.kafka_group_id = kafka_group_id
self.input_port = input_port
self.postgres_config = postgres_config
self.initial_schema = initial_schema
self.svc = None
def start(self):
env = {
"SCHEMA_REGISTRY_COMMUNICATION_METHOD": 'kafka',
"SCHEMA_REGISTRY_KAFKA__BROKERS": self.kafka_brokers,
"SCHEMA_REGISTRY_KAFKA__GROUP_ID": self.kafka_group_id,
"SCHEMA_REGISTRY_INPUT_PORT": self.input_port,
"SCHEMA_REGISTRY_MONITORING__OTEL_SERVICE_NAME": 'schema-registry',
"SCHEMA_REGISTRY_MONITORING__STATUS_PORT": '0',
"SCHEMA_REGISTRY_SERVICES__EDGE_REGISTRY_URL": self.edge_registry_addr,
**self.postgres_config.to_dict("SCHEMA_REGISTRY")
}
if self.initial_schema is not None:
env.update(SCHEMA_REGISTRY_IMPORT_FILE=self.initial_schema)
self.svc = subprocess.Popen([EXE], env=env)
time.sleep(3)
return self
def stop(self):
self.svc.kill()
def create_schema(self, name, destination, query, body, schema_type):
with grpc.insecure_channel(f"localhost:{self.input_port}") as channel:
stub = pb2_grpc.SchemaRegistryStub(channel)
resp = stub.AddSchema(
pb2.NewSchema(
definition=bytes(body, 'utf-8'),
name=name,
insert_destination=destination,
query_address=query,
schema_type=pb2.SchemaType(schema_type=schema_type)))
return resp.id
| 35.873016 | 83 | 0.643805 | 1 | 1.3371 | [
0.0002628268557600677,
0.024859387427568436,
0.009074696339666843,
0.0036388931330293417,
0.004211593884974718,
-0.0021740710362792015,
-0.008432946167886257,
0.0024974753614515066,
-0.007181093096733093,
0.00300273927859962,
0.003992299549281597,
0.005560401361435652,
0.006849932484328747,
-0.016942931339144707,
0.0024207637179642916,
0.015249479562044144,
-0.05311162769794464,
0.0011707156663760543,
-0.003127718809992075,
0.00394184747710824,
-0.009061097167432308,
0.008539959788322449,
0.010533846914768219,
0.007020407821983099,
0.006711243651807308,
-0.0016914763255044818,
0.00940550398081541,
0.002829962410032749,
-0.006024916190654039,
-0.008220283314585686,
-0.0003974669089075178,
-0.0016629374586045742,
-0.007283172570168972,
-0.006432110909372568,
0.007500136271119118,
-0.004762933123856783,
0.0010482828365638852,
-0.019677404314279556,
0.012469589710235596,
-0.005226796492934227,
-0.00668326485902071,
-0.01526555884629488,
-0.0008840393275022507,
0.006122339982539415,
-0.009110082872211933,
-0.00013038086763117462,
-0.00439425278455019,
0.003549320390447974,
-0.009153751656413078,
0.005627552513033152,
-0.00977290328592062,
0.005973707884550095,
0.014714675024151802,
0.0016272865468636155,
-0.004220872651785612,
-0.008154602721333504,
0.01169546041637659,
0.00017973693320527673,
-0.011211204342544079,
-0.0014700057217851281,
-0.004330015741288662,
-0.0012447654735296965,
0.007927844300866127,
0.0033938512206077576,
-0.01776205375790596,
-0.0065004765056073666,
-0.003995993640273809,
0.0039054795634001493,
-0.0016973563469946384,
0.005045746918767691,
0.00022446666844189167,
-0.0029111846815794706,
0.006589446682482958,
0.00575372064486146,
0.003207905450835824,
-0.0061882855370640755,
-0.0010310380021110177,
-0.00022130561410449445,
0.0076742470264434814,
0.0036547137424349785,
0.005331475753337145,
-0.0070700859650969505,
0.0038312559481710196,
0.008485477417707443,
0.016655560582876205,
0.010285424068570137,
0.02080528251826763,
-0.011136041954159737,
0.046474456787109375,
0.007930469699203968,
-0.010502045042812824,
0.001212709816172719,
-0.009884913451969624,
-0.0012030600337311625,
-0.0034694154746830463,
-0.027090787887573242,
-0.0018376766238361597,
-0.00205675745382905,
0.00027897345717065036,
0.0018415875965729356,
0.0011955653317272663,
0.006821240298449993,
-0.00006405077874660492,
-0.002728965599089861,
-0.009034340269863605,
0.010048105381429195,
-0.009004967287182808,
-0.002128086518496275,
0.007246032357215881,
0.0025783961173146963,
-0.011197553016245365,
-0.00169344840105623,
0.0018007841426879168,
-0.011928532272577286,
0.0030025974847376347,
0.0010105650871992111,
-0.006756087765097618,
0.054609742015600204,
-0.0006598704494535923,
0.004868792835623026,
-0.005304879974573851,
0.0019244290888309479,
0.0015139593742787838,
0.006937832571566105,
0.007172728888690472,
-0.0030043034348636866,
0.013555374927818775,
0.011900302954018116,
0.002504947129637003,
0.00899389199912548,
-0.0021301291417330503,
0.008754444308578968,
-0.0022451234981417656,
-0.00391170522198081,
0.003492850810289383,
-0.00792132318019867,
0.008554141037166119,
-0.002564836060628295,
-0.009845073334872723,
0.0008401143131777644,
-0.0002856680075637996,
-0.009686616249382496,
0.002817294094711542,
-0.00568745844066143,
0.005999297834932804,
-0.009493468329310417,
-0.0017168298363685608,
-0.0035191872157156467,
-0.004355635493993759,
0.0023844391107559204,
0.011032848618924618,
0.004933954682201147,
0.003350802231580019,
-0.005467593669891357,
-0.00887233205139637,
0.0016434373101219535,
-0.004043286666274071,
0.003142092376947403,
0.007470306474715471,
0.0036387129221111536,
-0.00875595211982727,
-0.0025237377267330885,
0.002060690661892295,
0.005017112009227276,
-0.0005571327055804431,
0.0028971871361136436,
-0.008856305852532387,
0.007379740476608276,
-0.0006847363547421992,
0.003966174088418484,
0.010991137474775314,
-0.005037172231823206,
-0.0006027130293659866,
-0.000051768951379926875,
0.004085084423422813,
-0.001599895884282887,
0.004838760010898113,
0.00886597391217947,
-0.0029174438677728176,
-0.0036856469232589006,
0.003252224298194051,
0.00446319067850709,
0.010196233168244362,
0.006086281500756741,
-0.003608098952099681,
0.0026753710117191076,
-0.003931188955903053,
-0.0019324243767187,
0.006520853377878666,
-0.005012164823710918,
0.005277405492961407,
0.004944433458149433,
-0.013520361855626106,
-0.005107648205012083,
0.0035079033114016056,
-0.01016696635633707,
0.002840643748641014,
0.014867851510643959,
0.011727367527782917,
-0.0015288374852389097,
0.0054930043406784534,
-0.006459593307226896,
0.0006728210137225688,
0.005672961939126253,
0.0024924813769757748,
-0.011896718293428421,
-0.9585554003715515,
0.007045563776046038,
0.003474139841273427,
-0.0021808408200740814,
0.004905546084046364,
0.0007941158255562186,
0.003001668956130743,
0.0048517207615077496,
0.01522160042077303,
-0.008250298909842968,
-0.006686188280582428,
-0.00920520257204771,
-0.010542359203100204,
-0.002091808710247278,
-0.00859125517308712,
-0.0015491597587242723,
-0.007558260578662157,
-0.005433010868728161,
-0.0018787877634167671,
-0.0036853111814707518,
-0.0021331501193344593,
0.008185078389942646,
0.000477658148156479,
0.004023585934191942,
0.00309776165522635,
0.002877485239878297,
-0.006303779780864716,
-0.0009902343153953552,
-0.00255952263250947,
-0.0016372865065932274,
-0.007191753946244717,
-0.015017569065093994,
-0.004035688005387783,
-0.004522864706814289,
0.011708869598805904,
-0.003298825118690729,
0.00984317809343338,
-0.0020663603208959103,
0.003977543208748102,
-0.006669013295322657,
0.006631456781178713,
-0.002540992572903633,
0.004587140399962664,
-0.03082319349050522,
-0.0003480638551991433,
-0.0014078100211918354,
-0.008676180616021156,
0.009007747285068035,
-0.00036914407974109054,
-0.00044148796587251127,
-0.003826320404186845,
-0.005765177309513092,
0.009353055618703365,
-0.009260306134819984,
0.0014217152493074536,
-0.003518779529258609,
-0.006742037367075682,
-0.0036121103912591934,
-0.00810632947832346,
0.0016764362808316946,
0.003386737545952201,
-0.0026438371278345585,
-0.004579036496579647,
-0.002225420670583844,
0.003514899406582117,
0.0019489772384986281,
0.0007318033021874726,
-0.019043948501348495,
-0.0061942520551383495,
-0.002010439522564411,
0.0016476166201755404,
-0.003361643059179187,
-0.002521677641198039,
0.005041144788265228,
-0.008719928562641144,
0.004559900611639023,
0.002240880159661174,
-0.00044553267071023583,
-0.01210996974259615,
0.001375290914438665,
-0.009947321377694607,
-0.007340684067457914,
0.0016793309478089213,
-0.004207643214613199,
-0.003115101484581828,
-0.002175617963075638,
0.0010456365998834372,
0.00912560150027275,
-0.006371458992362022,
0.00429928582161665,
0.012422059662640095,
-0.00451646139845252,
-0.008093444630503654,
0.0060706231743097305,
0.008656181395053864,
0.0000855020189192146,
-0.0025531332939863205,
-0.0001524407125543803,
0.008095868863165379,
0.007035740185528994,
0.0023820390924811363,
0.006327579729259014,
-0.0010111668379977345,
0.010290838778018951,
-0.0009496631100773811,
0.0025738240219652653,
-0.0019963071681559086,
0.0003797353710979223,
-0.004011782817542553,
0.00037332327337935567,
-0.00331161473877728,
-0.001670972676947713,
-0.013111164793372154,
-0.0087638134136796,
-0.004558028187602758,
-0.0004132725007366389,
0.0026601345743983984,
-0.004385987762361765,
-0.0006129195098765194,
0.002478515962138772,
0.008305022493004799,
-0.0012553023407235742,
-0.003710555611178279,
-0.0004852739511989057,
0.0032081801909953356,
-0.005721098743379116,
0.014965943992137909,
-0.013242750428617,
0.005858770105987787,
-0.0005248243105597794,
-0.015227549709379673,
0.007104620337486267,
0.010630258359014988,
-0.00821666233241558,
0.0004959309590049088,
0.0031315204687416553,
0.004668564535677433,
-0.0010669183684512973,
-0.004347504116594791,
-0.002446621423587203,
-0.016528215259313583,
0.0004958759527653456,
0.02025040239095688,
0.00032019338686950505,
0.010786989703774452,
0.012327232398092747,
-0.003215024247765541,
0.0013515421887859702,
0.006089935544878244,
0.0023213846143335104,
0.012176381424069405,
-0.009205725975334644,
0.0007008141838014126,
0.002992267021909356,
-0.006661358289420605,
0.0003892774984706193,
0.005808478686958551,
0.006862419191747904,
-0.0045689912512898445,
0.0027674161829054356,
-0.007848083972930908,
-0.00805619079619646,
-0.016566511243581772,
0.00006323476554825902,
0.008860059082508087,
-0.004931273870170116,
0.009541829116642475,
-0.013474478386342525,
0.004168893210589886,
0.005445442628115416,
0.002809337340295315,
-0.00130928005091846,
-0.0006690201116725802,
0.004010339733213186,
0.011489292606711388,
-0.006651891861110926,
0.0034189277794212103,
0.0004896355094388127,
-0.0008577050757594407,
0.002758231246843934,
0.008068685419857502,
-0.00816645659506321,
-0.00630944361910224,
0.0041816686280071735,
0.004883598070591688,
0.0013454966247081757,
-0.0038845951203256845,
-0.006515210028737783,
-0.002252566395327449,
0.0030065132305026054,
-0.005985267926007509,
0.0036457052920013666,
0.0006697187782265246,
0.002091689733788371,
-0.008106186985969543,
0.0003317045047879219,
-0.003596414113417268,
-0.012671446427702904,
0.00909008365124464,
-0.0042192935943603516,
0.001518658478744328,
0.015895286574959755,
0.0032657363917678595,
-0.012567561119794846,
0.005088331643491983,
0.008832525461912155,
-0.002177248243242502,
0.0037686568684875965,
0.0046610282734036446,
-0.005452316254377365,
-0.023108499124646187,
-0.0014465244021266699,
-0.013378426432609558,
0.007269733585417271,
-0.002762691816315055,
0.0016266214661300182,
-0.007996737025678158,
0.008377197198569775,
0.00514701334759593,
-0.012419350445270538,
-0.003217879682779312,
-0.008151441812515259,
0.01064403634518385,
-0.0005500680999830365,
0.00036490510683506727,
-0.005050619598478079,
-0.0019052898278459907,
-0.003022603690624237,
-0.0038850996643304825,
-0.0024523825850337744,
0.004666464403271675,
0.0008932474884204566,
-0.002813676605001092,
0.0015432380605489016,
-0.005193900316953659,
0.0006691194721497595,
-0.00018636694585438818,
-0.011776351369917393,
0.0014914784114807844,
0.003381336573511362,
0.00015995820285752416,
-0.005332589615136385,
0.0006954293348826468,
-0.0028688888996839523,
-0.005885766353458166,
-0.012093043886125088,
-0.002248569391667843,
-0.00530958641320467,
-0.0008071701740846038,
-0.011620697565376759,
-0.001964413793757558,
-0.006787069141864777,
0.006214396096765995,
-0.0060620391741395,
0.007149385288357735,
0.0033244837541133165,
-0.005018883850425482,
0.005923056043684483,
-0.0023973267525434494,
0.0051020290702581406,
0.003896743757650256,
0.005788574460893869,
0.0013709634076803923,
-0.008339107036590576,
-0.011889279820024967,
0.009623576886951923,
-0.0095768878236413,
0.00007209453906398267,
0.010450784116983414,
0.0036157965660095215,
0.00792513508349657,
-0.0007829933892935514,
-0.0011556486133486032,
0.0014302833005785942,
0.008678795769810677,
-0.012724915519356728,
0.0030656589660793543,
-0.003160304157063365,
0.0007207016460597515,
0.003436719300225377,
-0.0031565173994749784,
0.004159779753535986,
0.007575005292892456,
-0.00005172745659365319,
-0.005273849703371525,
-0.0031152276787906885,
0.0016349211800843477,
0.004572426434606314,
-0.011317232623696327,
-0.0008310008561238647,
-0.0033485223539173603,
-0.002398644806817174,
-0.0019621201790869236,
-0.0010444115614518523,
-0.001001390046440065,
0.004411214962601662,
-0.003432793542742729,
0.006647906266152859,
0.0018358879024162889,
-0.005139893852174282,
0.015806477516889572,
-0.007868596352636814,
-0.006347599904984236,
0.0022096040192991495,
0.002771358471363783,
-0.00005068924656370655,
-0.008244043216109276,
-0.0010910574346780777,
0.000927263405174017,
0.0062721045687794685,
-0.0033920290879905224,
-0.0041974131017923355,
-0.0002994802489411086,
0.002448751125484705,
-0.00786663219332695,
0.0016157047357410192,
0.01150598842650652,
-0.0060814619064331055,
0.004300326108932495,
-0.0026054936461150646,
-0.007071962580084801,
-0.013834454119205475,
0.05411727726459503,
-0.0024105377960950136,
0.0026659551076591015,
0.0048599704168736935,
-0.008846509270370007,
0.00039026435115374625,
-0.0023903963156044483,
0.008475729264318943,
-0.005306520964950323,
-0.005317644216120243,
0.007196239661425352,
-0.003698834218084812,
0.0038216784596443176,
0.003074480453506112,
-0.0029444547835737467,
0.016950249671936035,
-0.003779556369408965,
-0.017981238663196564,
-0.017041951417922974,
0.0046722013503313065,
-0.003762539243325591,
-0.00556557672098279,
0.010293137282133102,
-0.0016479877522215247,
-0.0054582650773227215,
-0.00014079334505368024,
0.0068315439857542515,
0.00008774821617407724,
-0.0011580210411921144,
-0.0034993961453437805,
-0.0028167436830699444,
-0.002713044174015522,
0.0014941808767616749,
0.0071579404175281525,
0.008924918249249458,
-0.003352830419316888,
0.003952592611312866,
-0.0008746983949095011,
-0.0011970502091571689,
-0.0007564824772998691,
0.004578812047839165,
0.0061867740005254745,
0.00026834182790480554,
-0.0011979257687926292,
0.005950384307652712,
0.005272405222058296,
0.0009636646718718112,
0.01076539233326912,
-0.0009579130564816296,
-0.006389521062374115,
0.008228135295212269,
0.007781348656862974,
0.0020925705321133137,
0.007328324485570192,
0.00005081763447378762,
0.006668081972748041,
0.0019567152485251427,
-0.007573896553367376,
-0.0178400669246912,
-0.001756281009875238,
0.0055245691910386086,
0.008130239322781563,
-0.0022677958477288485,
0.0035578387323766947,
-0.00579140055924654,
-0.0028992409352213144,
-0.0075185648165643215,
-0.007757712621241808,
0.0004298763524275273,
0.000835396524053067,
0.004385161679238081,
0.06774729490280151,
-0.007876343093812466,
-0.0008135500829666853,
-0.008863621391355991,
-0.0017700277967378497,
-0.0040688239969313145,
-0.0007064762176014483,
-0.00007946596451802179,
-0.0008857834618538618,
0.003912016749382019,
0.00048234721180051565,
-0.0077245659194886684,
-0.012577551417052746,
0.00011569273920031264,
0.002609220566228032,
-0.0031414348632097244,
0.0067095584236085415,
0.0046626972034573555,
-0.010595092549920082,
0.0017902023391798139,
-0.012923534028232098,
-0.0017983127618208528,
-0.0025836091954261065,
-0.009668886661529541,
-0.005445241462439299,
-0.004270259756594896,
0.0043888455256819725,
0.004030958749353886,
0.008241778239607811,
-0.004190242849290371,
0.00442474102601409,
-0.002670146059244871,
-0.000021920515791862272,
-0.004918324761092663,
-0.0013309011701494455,
-0.004937375895678997,
0.008450294844806194,
0.003449985757470131,
-0.010805520229041576,
-0.006775054149329662,
0.0013686284655705094,
-0.0006465171463787556,
-0.005087212193757296,
0.00416744127869606,
0.0019616074860095978,
0.0050176638178527355,
-0.0024054988753050566,
-0.0017181209987029433,
-0.006621954031288624,
0.002370145870372653,
-0.009895467199385166,
0.00768113462254405,
-0.1720515787601471,
0.006510907784104347,
0.0044422936625778675,
-0.005789428949356079,
-0.004880380351096392,
-0.01744525134563446,
-0.002694518771022558,
0.0028367650229483843,
0.010402941145002842,
0.00307975010946393,
-0.004042684566229582,
-0.004567272495478392,
0.006731793750077486,
0.0035095715429633856,
-0.001115320366807282,
-0.003470893483608961,
0.002110710134729743,
-0.003197752870619297,
-0.0010751570807769895,
0.005317840725183487,
0.005641952622681856,
0.006954506505280733,
-0.0007515487959608436,
0.00309937191195786,
-0.0012971566757187247,
-0.004248444922268391,
0.005925934761762619,
-0.0017854206962510943,
0.006110864225775003,
-0.013081829994916916,
-0.0036761928349733353,
-0.00242672860622406,
-0.005883689969778061,
0.0026799491606652737,
0.004508553072810173,
-0.0003291154862381518,
0.010228417813777924,
0.0022788012865930796,
-0.0073050097562372684,
0.005684523843228817,
-0.00673470925539732,
0.028354469686746597,
0.00768751697614789,
0.006012123543769121,
-0.0016220087418332696,
-0.004346724599599838,
-0.006867668125778437,
0.007501093205064535,
0.0021856860257685184,
0.010374355129897594,
-0.01216404139995575,
0.0006574213039129972,
0.003845175029709935,
0.01805293560028076,
-0.003772500902414322,
-0.00899096392095089,
-0.005988371092826128,
-0.004344648215919733,
0.0025778920389711857,
0.005251653492450714,
0.012139782309532166,
-0.004693593364208937,
0.007576726842671633,
-0.003001454286277294,
-0.02260994352400303,
0.0033205063082277775,
-0.004350419621914625,
-0.0061331577599048615,
0.002609031740576029,
0.008471379056572914,
0.009162873961031437,
0.0024131264071911573,
0.0020383966621011496,
-0.0023105470463633537,
0.005780116189271212,
-0.0008727667736820877,
0.005962374620139599,
-0.0022284630686044693,
0.005119583569467068,
-0.009379835799336433,
0.007874316535890102,
-0.009764470160007477,
-0.003817208344116807,
0.0019520993810147047,
-0.005694492720067501,
0.010779578238725662,
0.0037769079208374023,
-0.002778054680675268,
-0.000557789346203208,
-0.012255702167749405,
-0.0015488136559724808,
0.0030293739400804043,
0.0017131841741502285,
-0.009125596843659878,
0.0023934326600283384,
-0.0019642699044197798,
0.004970851819962263,
0.006884313654154539,
-0.009245019406080246,
0.009601451456546783,
0.007718061562627554,
-0.004671040922403336,
-0.0007320452714338899,
-0.004798627458512783,
0.0015130628598853946,
0.0030984363984316587,
-0.006267568562179804,
-0.006408338434994221,
0.005211069248616695,
-0.008054600097239017,
-0.004438689444214106,
0.007004222832620144,
-0.010342792607843876,
-0.00783885084092617,
-0.0006147528765723109,
-0.011137942783534527,
0.0014639310538768768
] |
8a4a74e407a1faa40bc78d3ab5dcb9c6741e4b2e | 1,743 | py | Python | testsuite/tests/apicast/policy/routing/test_routing_policy_catch_all.py | dlaso99/3scale-tests | b31a3b3596af6d632b393e383c0417ea56bd95ca | [
"Apache-2.0"
] | 5 | 2021-11-04T14:09:24.000Z | 2021-12-23T13:48:36.000Z | testsuite/tests/apicast/policy/routing/test_routing_policy_catch_all.py | dlaso99/3scale-tests | b31a3b3596af6d632b393e383c0417ea56bd95ca | [
"Apache-2.0"
] | 41 | 2021-11-03T14:27:21.000Z | 2022-03-29T14:46:16.000Z | testsuite/tests/apicast/policy/routing/test_routing_policy_catch_all.py | dlaso99/3scale-tests | b31a3b3596af6d632b393e383c0417ea56bd95ca | [
"Apache-2.0"
] | 12 | 2021-11-03T17:28:31.000Z | 2021-11-30T12:28:25.000Z | """
When a routing policy is set with an empty condition, it should be loaded correctly and should route all
the requests to a correct backend.
"""
from urllib.parse import urlparse
import pytest
from packaging.version import Version # noqa # pylint: disable=unused-import
from testsuite import TESTED_VERSION, rawobj # noqa # pylint: disable=unused-import
from testsuite.echoed_request import EchoedRequest
pytestmark = [
pytest.mark.skipif("TESTED_VERSION < Version('2.11')"),
pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-6415")]
@pytest.fixture(scope="module")
def service_proxy_settings(private_base_url):
"""
Asserts, that echo api is used as the default backend
"""
return rawobj.Proxy(private_base_url("echo_api"))
@pytest.fixture(scope="module")
def service(service, private_base_url):
"""
Set the routing policy to route all requests to httpbin.
(Using the logic that an empty condition should act as a catch all rule)
"""
proxy = service.proxy.list()
proxy.policies.insert(0, rawobj.PolicyConfig(
"routing", {
"rules": [
{
"url": private_base_url("httpbin"),
"condition": {},
}]}))
return service
def test_routing_policy_without_header(api_client, private_base_url):
"""
Sends a request and asserts, that the routing policy is active and the
requests is routed to the correct backend (httpbin)
"""
parsed_url = urlparse(private_base_url("httpbin"))
response = api_client().get("/get")
assert response.status_code == 200
echoed_request = EchoedRequest.create(response)
assert echoed_request.headers["Host"] == parsed_url.hostname
| 32.277778 | 104 | 0.693058 | 1 | 1.1886 | [
0.00018278548668604344,
0.023457935079932213,
0.009490106254816055,
0.0022636251524090767,
0.004970739595592022,
-0.0032336069270968437,
-0.009159461595118046,
0.002921435283496976,
-0.007320108823478222,
0.0016269213519990444,
0.0028835865668952465,
0.005001708399504423,
0.007443491369485855,
-0.01585589349269867,
0.0014161687577143312,
0.01405415777117014,
-0.0504293218255043,
0.0006540704052895308,
-0.003562995931133628,
0.0032299847807735205,
-0.007988568395376205,
0.009210579097270966,
0.01008339412510395,
0.0044297887943685055,
0.005955975037068129,
-0.0008393828757107258,
0.009832357056438923,
0.0024730588775128126,
-0.00785143580287695,
-0.007763481233268976,
0.0002768041449598968,
-0.0025676877703517675,
-0.007015012204647064,
-0.0064317453652620316,
0.006009326782077551,
-0.003385839518159628,
-0.00035385022056289017,
-0.018675895407795906,
0.012176322750747204,
-0.004802162759006023,
-0.006835094187408686,
-0.016363713890314102,
-0.0003738789528142661,
0.003924907185137272,
-0.01054127886891365,
0.000598431215621531,
-0.002764039905741811,
0.0041907294653356075,
-0.013063785620033741,
0.0064223697409033775,
-0.01073741726577282,
0.005370781756937504,
0.014419027604162693,
0.0024478917475789785,
-0.005227000452578068,
-0.00828828476369381,
0.011786426417529583,
-0.00033164190244860947,
-0.010027824901044369,
0.0014732180861756206,
-0.004641905892640352,
-0.003541999962180853,
0.003693101927638054,
0.0029907957650721073,
-0.015788240358233452,
-0.005501517094671726,
-0.004051238764077425,
0.0022882367484271526,
-0.0018781429389491677,
0.006683672778308392,
-0.00017090668552555144,
-0.001783286570571363,
0.008424248546361923,
0.005095090717077255,
0.004512614104896784,
-0.005354598164558411,
-0.0007876732852309942,
0.00021693766757380217,
0.008808248676359653,
0.0030045760795474052,
0.005016433075070381,
-0.006901374086737633,
0.0050750430673360825,
0.009041584096848965,
0.013390791602432728,
0.010165642015635967,
0.019906513392925262,
-0.01303020678460598,
0.047718338668346405,
0.007888885214924812,
-0.00871010310947895,
0.001572640030644834,
-0.008389916270971298,
-0.0005348469130694866,
-0.00392387667670846,
-0.028373034670948982,
-0.0008928499883040786,
-0.004386313259601593,
-0.0015600653132423759,
0.0022230027243494987,
-0.0010741495061665773,
0.006218914873898029,
-0.002884697401896119,
-0.0016780438600108027,
-0.008011170662939548,
0.009971953928470612,
-0.009010962210595608,
-0.000511628168169409,
0.006426144391298294,
0.001507980516180396,
-0.011058165691792965,
-0.004215817898511887,
0.0019390088273212314,
-0.011682706885039806,
0.0022023518104106188,
0.0011448394507169724,
-0.006416591815650463,
0.05363956466317177,
-0.0005646234494633973,
0.001959523418918252,
-0.005801850464195013,
0.0010908005060628057,
0.0010277447290718555,
0.005327058956027031,
0.00949734915047884,
-0.003018313320353627,
0.011639430187642574,
0.00768371531739831,
0.0028968730475753546,
0.009805315174162388,
-0.0010514858877286315,
0.00932335201650858,
-0.005589889362454414,
-0.0037194008473306894,
0.0023139086551964283,
-0.007382290903478861,
0.00860963761806488,
-0.0015490148216485977,
-0.009530848823487759,
-0.0005322875804267824,
-0.0014276125002652407,
-0.008842471987009048,
0.0021912690717726946,
-0.005339082330465317,
0.006330123636871576,
-0.010304425843060017,
-0.0036119811702519655,
-0.006409766618162394,
-0.003788186237215996,
0.0033678936306387186,
0.008344955742359161,
0.004778293427079916,
0.0018283206736668944,
-0.0039606220088899136,
-0.008156614378094673,
-0.001620698138140142,
-0.005367468576878309,
0.0021589200478047132,
0.008708933368325233,
0.003688204102218151,
-0.009646577760577202,
-0.0003910647355951369,
0.001042885472998023,
0.002376697026193142,
-0.0011818145867437124,
0.002542255213484168,
-0.009684792719781399,
0.007038412149995565,
-0.0007035004091449082,
0.005189988762140274,
0.010018648579716682,
-0.005280067212879658,
-0.00036880586412735283,
-0.001741465530358255,
0.0013998396461829543,
-0.0021551474928855896,
0.005029431544244289,
0.010162407532334328,
-0.0038173296488821507,
-0.004522285889834166,
0.0041625164449214935,
0.003566170111298561,
0.010955271311104298,
0.006936184596270323,
-0.002965690800920129,
0.0018738630460575223,
-0.00479175103828311,
-0.00045332222362048924,
0.005232820753008127,
-0.003413621336221695,
0.006640931591391563,
0.002897375961765647,
-0.013623280450701714,
-0.008559225127100945,
0.0018272334709763527,
-0.009277325123548508,
0.0025021785404533148,
0.01379295252263546,
0.012825729325413704,
-0.004300201777368784,
0.004012766759842634,
-0.009745707735419273,
0.0011841141385957599,
0.006935551762580872,
0.003515496151521802,
-0.012979269959032536,
-0.9589567184448242,
0.0063142599537968636,
0.003707349067553878,
-0.002051777206361294,
0.005713656544685364,
0.0028489914257079363,
0.0016202013939619064,
0.004378941375762224,
0.016760610044002533,
-0.008110239170491695,
-0.006249498575925827,
-0.00940585508942604,
-0.010281943716108799,
-0.0015384289436042309,
-0.007618050556629896,
-0.003654218977317214,
-0.0076335943304002285,
-0.0061486028134822845,
-0.005823608487844467,
-0.004785666707903147,
-0.0011817760532721877,
0.005884291138499975,
-0.0005917776725254953,
0.004730463493615389,
0.0020622785668820143,
0.0021670274436473846,
-0.005204519256949425,
-0.0011772543657571077,
-0.0035873274318873882,
-0.0018000336131080985,
-0.006520792376250029,
-0.014315498061478138,
-0.004423269536346197,
-0.0019613138865679502,
0.010837090201675892,
-0.0016650466714054346,
0.009151164442300797,
-0.003126617055386305,
0.004298963584005833,
-0.007798029109835625,
0.0060146041214466095,
-0.0015124640194699168,
0.003937617875635624,
-0.030560744926333427,
-0.0008795499452389777,
-0.000725813617464155,
-0.009577710181474686,
0.00985057931393385,
-0.002610583323985338,
-0.0003672961611300707,
-0.0029723055195063353,
-0.0042186095379292965,
0.008989118970930576,
-0.007833437994122505,
0.0022433805279433727,
-0.003928460646420717,
-0.005648660473525524,
-0.0019790097139775753,
-0.0083235502243042,
0.0004740022704936564,
0.004300190135836601,
-0.001702648471109569,
-0.0039075640961527824,
-0.0019716378301382065,
0.004052957519888878,
0.0015308096772059798,
0.0023259143345057964,
-0.017334172502160072,
-0.007118897512555122,
0.0007795840501785278,
-0.0007444011862389743,
-0.00373698677867651,
-0.0029325541108846664,
0.005551021546125412,
-0.010440582409501076,
0.005663486663252115,
0.0008258511661551893,
0.0000376714815502055,
-0.01128114853054285,
0.0012056230334565043,
-0.00851561687886715,
-0.009980805218219757,
0.0016418161103501916,
-0.005085849203169346,
-0.003843560814857483,
0.0011240530293434858,
0.0007703234441578388,
0.008208748884499073,
-0.0047528850845992565,
0.0038604724686592817,
0.012690667994320393,
-0.004017360508441925,
-0.0066007813438773155,
0.006479260046035051,
0.005664545577019453,
-0.00032953929621726274,
-0.000403255398850888,
0.001362449605949223,
0.007997081615030766,
0.006454149726778269,
0.0018647045362740755,
0.004764969926327467,
-0.0014097520615905523,
0.009610419161617756,
0.00012653331214096397,
-0.00048317911569029093,
-0.002077777637168765,
0.0006967467488721013,
-0.0023024440743029118,
0.00015160598559305072,
-0.004935365170240402,
-0.0029425285756587982,
-0.01249651052057743,
-0.007028926629573107,
-0.0040947068482637405,
-0.0007298841956071556,
0.003998668864369392,
-0.0047372509725391865,
-0.000648622983135283,
0.0006483822362497449,
0.007889671251177788,
0.00010644888243405148,
-0.0010675546946004033,
0.0010603199480101466,
0.0043664961121976376,
-0.00540679506957531,
0.01407148502767086,
-0.00962266605347395,
0.006001592613756657,
-0.0003341624396853149,
-0.01642443612217903,
0.009453855454921722,
0.009758559986948967,
-0.008030397817492485,
0.003036773530766368,
0.004979400429874659,
0.0034569960553199053,
-0.0009641674696467817,
-0.0056744725443422794,
-0.0027757135685533285,
-0.015379603020846844,
0.00005598422285402194,
0.02101808600127697,
0.00110727921128273,
0.011159971356391907,
0.012223506346344948,
-0.0033436839003115892,
0.0011878415243700147,
0.004641403444111347,
0.0019238452659919858,
0.011800740845501423,
-0.008234557695686817,
-0.0005392657476477325,
0.001344069722108543,
-0.006868572439998388,
0.001117184991016984,
0.005380657967180014,
0.005315113812685013,
-0.002376813907176256,
0.003841203171759844,
-0.0068537150509655476,
-0.005519401747733355,
-0.018755439668893814,
-0.0017079400131478906,
0.005299102980643511,
-0.003093037521466613,
0.0078650563955307,
-0.013505668379366398,
0.003379786852747202,
0.005546813365072012,
0.00301038078032434,
0.0005527227185666561,
0.0019524847157299519,
0.005383349489420652,
0.01023305207490921,
-0.006205311976373196,
0.002099718200042844,
0.00211319443769753,
-0.0004100857477169484,
0.0007311798399314284,
0.008564232848584652,
-0.007099074311554432,
-0.0061454144306480885,
0.004300261382013559,
0.0025751760695129633,
-0.00008161153527908027,
-0.002902526641264558,
-0.00855892151594162,
-0.0029423667583614588,
0.003777218284085393,
-0.004596630111336708,
0.004927328787744045,
0.0025415034033358097,
0.0035866894759237766,
-0.006381065584719181,
-0.0001728741335682571,
-0.004862276837229729,
-0.013174931518733501,
0.010433346033096313,
-0.0037192462477833033,
0.002801937982439995,
0.013603475876152515,
0.0029263817705214024,
-0.010965730994939804,
0.006375695113092661,
0.007934189401566982,
-0.004577793646603823,
0.004561380483210087,
0.00711770448833704,
-0.00630980683490634,
-0.022118674591183662,
-0.002230469835922122,
-0.012613419443368912,
0.007808324880897999,
-0.0015832409262657166,
0.003691497491672635,
-0.0070635126903653145,
0.006238259840756655,
0.005500087048858404,
-0.01437115017324686,
-0.002470453968271613,
-0.0098089799284935,
0.010091598145663738,
0.00008652310498291627,
-0.0007247986504808068,
-0.003798220306634903,
-0.0005911490879952908,
-0.0025963305961340666,
-0.004184742458164692,
0.0003118814784102142,
0.004567497875541449,
0.0013263282598927617,
-0.002391332760453224,
0.0017124273581430316,
-0.006937090773135424,
0.0016298368573188782,
0.000807919364888221,
-0.011059596203267574,
0.001828821375966072,
0.0031195124611258507,
-0.0011487253941595554,
-0.002041434869170189,
0.0011754835722967982,
-0.0018838307587429881,
-0.007208634167909622,
-0.011359017342329025,
-0.0034244998823851347,
-0.005576909985393286,
-0.002039762679487467,
-0.011953109875321388,
-0.00270523177459836,
-0.006803078576922417,
0.006040900480002165,
-0.006283994298428297,
0.0069076670333743095,
0.0061828456819057465,
-0.006885255686938763,
0.007199299521744251,
-0.00023081830295268446,
0.002797539811581373,
0.0028541432693600655,
0.005627909209579229,
0.0010170791065320373,
-0.0065203397534787655,
-0.012751364149153233,
0.011055859737098217,
-0.008198832161724567,
-0.0002139866555808112,
0.014506745152175426,
0.006853321101516485,
0.009069613181054592,
0.0004099179059267044,
-0.001325791934505105,
0.00175396166741848,
0.007862865924835205,
-0.0147604551166296,
0.0017828996060416102,
-0.0005840163212269545,
0.00024753043544478714,
0.004019869025796652,
-0.002922109328210354,
0.00373240583576262,
0.008814035914838314,
0.002020628657191992,
-0.006472218316048384,
-0.0019957099575549364,
0.0025877682492136955,
0.0052849710918962955,
-0.012933140620589256,
0.0020167683251202106,
-0.0034951153211295605,
-0.0037752457428723574,
-0.0008597892592661083,
-0.0026115342043340206,
0.0010641143890097737,
0.005629991181194782,
-0.00160363654140383,
0.00641676876693964,
0.004737784154713154,
-0.0036019128747284412,
0.016872700303792953,
-0.006619445979595184,
-0.005908348597586155,
0.0031087901443243027,
0.0026951346080750227,
-0.0003545040381141007,
-0.006996980402618647,
-0.0013596125645563006,
0.0026474110782146454,
0.007427677977830172,
-0.0013549316208809614,
-0.005633984226733446,
-0.00019998954667244107,
0.002956469776108861,
-0.009406096301972866,
0.00010377242142567411,
0.010492654517292976,
-0.0036626325454562902,
0.004968284163624048,
-0.0025040660984814167,
-0.006733015179634094,
-0.012330079451203346,
0.052551642060279846,
-0.0013248377945274115,
0.0046142153441905975,
0.004593284800648689,
-0.008630535565316677,
-0.0010888893157243729,
-0.002557889325544238,
0.0067703984677791595,
-0.006533193401992321,
-0.007826484739780426,
0.007782298605889082,
-0.0008243879419751465,
0.0057657696306705475,
0.0032685031183063984,
-0.0010532878804951906,
0.01661558821797371,
-0.0035544089041650295,
-0.014716293662786484,
-0.016874315217137337,
0.009168277494609356,
-0.005918128415942192,
-0.006926227360963821,
0.009727702476084232,
-0.0033175668213516474,
-0.005404630675911903,
0.001542774960398674,
0.00724307494238019,
-0.00024785217829048634,
0.000011512557648529764,
-0.0022675744257867336,
-0.002075403928756714,
-0.0006636195466853678,
0.002217792207375169,
0.0073628812097013,
0.006970081478357315,
-0.0037798818666487932,
0.0040947371162474155,
-0.0008103685104288161,
-0.0010825525969266891,
-0.0005277138552628458,
0.003074503503739834,
0.008465426973998547,
-0.0014618448913097382,
-0.0033316914923489094,
0.007251017726957798,
0.004449011757969856,
0.0005957534885965288,
0.011228030547499657,
0.001322112511843443,
-0.006745126564055681,
0.008100878447294235,
0.008666597306728363,
0.0014063057024031878,
0.006913371849805117,
-0.0010416136356070638,
0.004535628017038107,
0.001548620406538248,
-0.005263653118163347,
-0.018122820183634758,
-0.0031826081685721874,
0.005308616906404495,
0.008627441711723804,
-0.001829312415793538,
0.002987440675497055,
-0.0018134905258193612,
-0.0035197404213249683,
-0.006349693983793259,
-0.0051623801700770855,
-0.0016544366953894496,
-0.001049197744578123,
0.004241655580699444,
0.06816013902425766,
-0.008143160492181778,
-0.0014001834206283092,
-0.008447632193565369,
-0.0010323739843443036,
-0.0030513866804540157,
0.0001913730229716748,
-0.00014562314026989043,
-0.0014243570622056723,
0.002624836517497897,
0.00040412781527265906,
-0.008388216607272625,
-0.01114189624786377,
0.0002728893596213311,
0.0030061861034482718,
-0.0026642722077667713,
0.005990921054035425,
0.005478694569319487,
-0.010554952546954155,
-0.0003638358321040869,
-0.01063820905983448,
-0.003537447191774845,
-0.002135674934834242,
-0.010098316706717014,
-0.004872419871389866,
-0.002799053443595767,
0.004651715513318777,
0.0029133532661944628,
0.007664803881198168,
-0.0019152099266648293,
0.0057730465196073055,
-0.0021701182704418898,
0.0007535819313488901,
-0.007760407403111458,
-0.001233577961102128,
-0.0048160492442548275,
0.007133118808269501,
0.0034007872454822063,
-0.011008038185536861,
-0.005219387821853161,
-0.0017952527850866318,
0.00044250485370866954,
-0.0060291835106909275,
0.004461205564439297,
0.0006332594784907997,
0.005905741825699806,
-0.0034227920696139336,
-0.0003116607549600303,
-0.006372910458594561,
0.0008239910821430385,
-0.013080243952572346,
0.0036722926888614893,
-0.17304041981697083,
0.00924711674451828,
0.004216401372104883,
-0.003879699856042862,
-0.006199530325829983,
-0.014758148230612278,
-0.0035227786283940077,
0.005534846801310778,
0.009220930747687817,
0.002147318096831441,
-0.001634404412470758,
-0.002398231765255332,
0.005098497495055199,
0.0038153419736772776,
-0.0008852177998051047,
-0.004001070279628038,
0.001429190975613892,
-0.0026505468413233757,
-0.0009342728299088776,
0.004325777757912874,
0.003968551754951477,
0.010132708586752415,
-0.00021596373699139804,
0.002570945071056485,
-0.002576305065304041,
-0.005020312964916229,
0.006906624883413315,
-0.002098304219543934,
0.0031185857951641083,
-0.012215650640428066,
-0.003256560303270817,
-0.00260360911488533,
-0.0051558190025389194,
0.0016017720336094499,
0.006366144400089979,
0.00006896170089021325,
0.009377038106322289,
0.00449490686878562,
-0.0068665542639791965,
0.007307871710509062,
-0.008439053781330585,
0.026905568316578865,
0.005434609949588776,
0.0055009969510138035,
-0.0010016771266236901,
-0.004939836449921131,
-0.005685250740498304,
0.007680702488869429,
0.0011850919108837843,
0.009734216146171093,
-0.012839973904192448,
-0.00129650067538023,
0.003169693984091282,
0.01851201243698597,
-0.004568169824779034,
-0.009056813083589077,
-0.00716637447476387,
-0.002365550957620144,
0.0035871260333806276,
0.009270650334656239,
0.011945509351789951,
-0.003966945223510265,
0.010144020430743694,
-0.004481099545955658,
-0.02164549194276333,
0.002754794666543603,
-0.006087400484830141,
-0.007990648970007896,
0.0037209331057965755,
0.006189173553138971,
0.010152039118111134,
0.000406065140850842,
0.00017856954946182668,
-0.0015317845391109586,
0.005239611957222223,
0.00034847803181037307,
0.006986296270042658,
-0.0029579021502286196,
0.005190576426684856,
-0.009041910991072655,
0.007488320115953684,
-0.011300040408968925,
-0.0024369715247303247,
0.000912731047719717,
-0.004806965123862028,
0.012524159625172615,
0.005017573479562998,
-0.002429633168503642,
-0.0009678758797235787,
-0.010068402625620365,
-0.0038977251388132572,
0.0015378791140392423,
0.0031794572714716196,
-0.00933457538485527,
0.0023488246370106936,
0.0006025675684213638,
0.007110248785465956,
0.005530065856873989,
-0.009274087846279144,
0.007023175247013569,
0.006691824644804001,
-0.005228328052908182,
0.0009712669416330755,
-0.004862484522163868,
0.00001781546598067507,
0.003999943844974041,
-0.005642033647745848,
-0.006898173131048679,
0.004548052791506052,
-0.006282453890889883,
-0.0056692552752792835,
0.005840471480041742,
-0.008517156355082989,
-0.010005001910030842,
-0.0026439139619469643,
-0.012028769589960575,
0.0008665197528898716
] |
8a4aca2698c2e4be69222dd4573ceaef0614a5f5 | 2,113 | py | Python | ceilometer/data_processing/notifications.py | vmturbo/ceilometer | f856d3c915b738a64bce14967ba8114fe923c1af | [
"Apache-2.0"
] | null | null | null | ceilometer/data_processing/notifications.py | vmturbo/ceilometer | f856d3c915b738a64bce14967ba8114fe923c1af | [
"Apache-2.0"
] | null | null | null | ceilometer/data_processing/notifications.py | vmturbo/ceilometer | f856d3c915b738a64bce14967ba8114fe923c1af | [
"Apache-2.0"
] | 1 | 2019-09-16T02:11:41.000Z | 2019-09-16T02:11:41.000Z | # Copyright (c) 2014 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo.config import cfg
import oslo.messaging
from ceilometer import plugin
from ceilometer import sample
OPTS = [
cfg.StrOpt('sahara_control_exchange',
default='sahara',
help="Exchange name for Data Processing notifications."),
]
cfg.CONF.register_opts(OPTS)
SERVICE = 'sahara'
class DataProcessing(plugin.NotificationBase):
resource_name = '%s.cluster' % SERVICE
@property
def event_types(self):
return [
'%s.create' % self.resource_name,
'%s.update' % self.resource_name,
'%s.delete' % self.resource_name,
]
@staticmethod
def get_targets(conf):
"""Return a sequence of oslo.messaging.Target
It is defining the exchange and topics to be connected for this plugin.
"""
return [oslo.messaging.Target(topic=topic,
exchange=conf.sahara_control_exchange)
for topic in conf.notification_topics]
def process_notification(self, message):
name = message['event_type'].replace(self.resource_name, 'cluster')
project_id = message['payload']['project_id']
user_id = message['_context_user_id']
yield sample.Sample.from_notification(
name=name,
type=sample.TYPE_DELTA,
unit='cluster',
volume=1,
resource_id=message['payload']['cluster_id'],
user_id=user_id,
project_id=project_id,
message=message)
| 29.347222 | 79 | 0.6531 | 1 | 1.2696 | [
0.0017806509276852012,
0.022124284878373146,
0.00877358391880989,
0.0038246989715844393,
0.005293808877468109,
-0.001464450848288834,
-0.0075005232356488705,
0.0013537047198042274,
-0.006258266046643257,
0.0037966761738061905,
0.004151251632720232,
0.004310912918299437,
0.007279082201421261,
-0.01538130734115839,
-0.0014397659106180072,
0.014568331651389599,
-0.05187418684363365,
0.003952886443585157,
-0.004003647714853287,
0.003932917024940252,
-0.006800052244216204,
0.009795387275516987,
0.00872170552611351,
0.005316443741321564,
0.005663692485541105,
-0.002066486282274127,
0.007978614419698715,
0.0004161681281402707,
-0.006180720869451761,
-0.00869624875485897,
0.0006602430366910994,
-0.002847003284841776,
-0.00722658121958375,
-0.005788899026811123,
0.007681146264076233,
-0.006955109536647797,
-0.0010541473748162389,
-0.020475734025239944,
0.012730438262224197,
-0.0032285561319440603,
-0.0066460599191486835,
-0.016076279804110527,
-0.0009981112089008093,
0.0038913977332413197,
-0.007717843633145094,
0.000904889137018472,
-0.004005431663244963,
0.0030830164905637503,
-0.013787131756544113,
0.006679586134850979,
-0.00887107290327549,
0.005599107127636671,
0.01726328767836094,
0.00019690349290613085,
-0.004840914625674486,
-0.008964521810412407,
0.014172082766890526,
-0.000013416156434686854,
-0.010905533097684383,
-0.001073877909220755,
-0.0037179782520979643,
-0.0025268939789384604,
0.004891206976026297,
0.0025211379397660494,
-0.015708737075328827,
-0.00578998913988471,
-0.0038011108990758657,
0.0011312819551676512,
-0.0019609786104410887,
0.0063600968569517136,
0.002029743744060397,
-0.0021342479158192873,
0.008702516555786133,
0.0033910535275936127,
0.002441386692225933,
-0.00802092906087637,
0.0005606611375696957,
-0.0012259104987606406,
0.009051232598721981,
0.0018044222379103303,
0.0052589853294193745,
-0.00856317114084959,
0.004938498605042696,
0.006505479570478201,
0.014076856896281242,
0.010157685726881027,
0.021452227607369423,
-0.009822719730436802,
0.047156210988759995,
0.007989191450178623,
-0.006940356455743313,
0.0009110962273553014,
-0.00805688090622425,
-0.0017090936889871955,
-0.0058624278753995895,
-0.029992664232850075,
-0.002254515653476119,
-0.003154260106384754,
-0.0018122723558917642,
0.0036125988699495792,
-0.00002304469126102049,
0.008019650354981422,
-0.0017633106326684356,
-0.0010752476518973708,
-0.009056349284946918,
0.010099777951836586,
-0.00996243767440319,
-0.005408577620983124,
0.004860780201852322,
0.0009118309826590121,
-0.013321559876203537,
-0.0024411894846707582,
0.0028191127348691225,
-0.013203579001128674,
0.0015979408053681254,
0.0013629680033773184,
-0.0059389760717749596,
0.05391811579465866,
-0.0025396542623639107,
0.004629145842045546,
-0.004377603065222502,
0.00422366289421916,
0.0017381382640451193,
0.005249181762337685,
0.009421244263648987,
-0.0029536744114011526,
0.013233075849711895,
0.008879777044057846,
0.002818761393427849,
0.010172214359045029,
-0.0013717043912038207,
0.007329209242016077,
-0.0037636097986251116,
-0.004293802659958601,
0.0009845425374805927,
-0.007713481318205595,
0.009178975597023964,
-0.0026386722456663847,
-0.01146477460861206,
0.0030643220525234938,
0.0019232822814956307,
-0.008812556974589825,
0.003485949244350195,
-0.0029310809914022684,
0.006151104345917702,
-0.00859965942800045,
-0.0032867419067770243,
-0.0045527308247983456,
-0.004082928411662579,
0.0027163156773895025,
0.011763650923967361,
0.005256043281406164,
0.0032607405446469784,
-0.004976544063538313,
-0.009449432604014874,
0.0008042088593356311,
-0.0025898541789501905,
0.0006150268018245697,
0.009088568389415741,
0.005303308367729187,
-0.010556555353105068,
-0.0024219397455453873,
0.002954106545075774,
0.006978385150432587,
-0.0017488572048023343,
0.0018203305080533028,
-0.008554444648325443,
0.007966604083776474,
0.0001450486306566745,
0.002550153760239482,
0.010013080202043056,
-0.0035423096269369125,
0.00021766302234027535,
-0.000912051706109196,
0.0037655874621123075,
-0.0015732188476249576,
0.006578187458217144,
0.009754716418683529,
-0.0034266875591129065,
-0.002937319688498974,
0.002519522327929735,
0.006508319638669491,
0.009577814489603043,
0.007280879188328981,
-0.002200667979195714,
0.0028348220512270927,
-0.0032074584160000086,
-0.0030079891439527273,
0.006311990786343813,
-0.003865860402584076,
0.004568006843328476,
0.00467343907803297,
-0.014419760555028915,
-0.0064910161308944225,
0.0024414826184511185,
-0.008368530310690403,
0.002654311014339328,
0.015009318478405476,
0.0122454185038805,
-0.00417132256552577,
0.0034262998960912228,
-0.007683043368160725,
0.001797121367417276,
0.008127951994538307,
0.000888155831489712,
-0.014033696614205837,
-0.9594541192054749,
0.008606676943600178,
0.002821599831804633,
-0.0020909372251480818,
0.005547275301069021,
0.0013675291556864977,
0.006187779363244772,
0.0034879769664257765,
0.016401955857872963,
-0.005875463597476482,
-0.005942538846284151,
-0.008221706375479698,
-0.010230880230665207,
-0.001584049197845161,
-0.0068383971229195595,
-0.0011621179291978478,
-0.005947863683104515,
-0.0034659842494875193,
-0.003225377993658185,
-0.0021163118071854115,
-0.001148732379078865,
0.007763466332107782,
-0.0011998816626146436,
0.004755790811032057,
0.001815223484300077,
0.00471170898526907,
-0.00536237470805645,
-0.0008220231393352151,
-0.0018591266125440598,
-0.0010604939889162779,
-0.0053171138279139996,
-0.015170217491686344,
-0.004758517257869244,
-0.0022573263850063086,
0.009842478670179844,
0.0005444901180453598,
0.010044688358902931,
-0.004395069554448128,
0.0043644686229527,
-0.009000441059470177,
0.005539675243198872,
-0.00007043161167530343,
0.003319833194836974,
-0.0304857287555933,
-0.0015721417730674148,
-0.00012511428212746978,
-0.0077077895402908325,
0.008745686151087284,
-0.0023506670258939266,
0.000582826032768935,
-0.0029996633529663086,
-0.004148390144109726,
0.009697429835796356,
-0.0069616506807506084,
0.0023721305187791586,
-0.005456734448671341,
-0.008306615054607391,
-0.0025744836311787367,
-0.009149848483502865,
0.0013656625524163246,
0.005037032533437014,
-0.0020119398832321167,
-0.003369600512087345,
-0.001955840503796935,
0.001968886936083436,
0.0036056486424058676,
0.0003943162446375936,
-0.019860677421092987,
-0.006817885674536228,
-0.0008353597950190306,
0.002150831976905465,
-0.003900191280990839,
-0.002062049927189946,
0.0039412169717252254,
-0.009105153381824493,
0.004986419342458248,
0.0022824895568192005,
-0.0025754268281161785,
-0.010404237546026707,
0.00021818546520080417,
-0.008166651241481304,
-0.009079367853701115,
0.0022080764174461365,
-0.00585688604041934,
-0.004149667918682098,
-0.0021322905085980892,
-0.0022732855286449194,
0.008955257013440132,
-0.0035993068013340235,
0.004389008041471243,
0.01200813427567482,
-0.0017851607408374548,
-0.005833566654473543,
0.005454427562654018,
0.006636484060436487,
-0.0017263712361454964,
-0.0022408273071050644,
0.0016974583268165588,
0.008703628554940224,
0.004990020301192999,
0.003196406876668334,
0.004534026142209768,
0.0005922772106714547,
0.009858560748398304,
-0.0015903536695986986,
-0.0006245469558052719,
-0.005307583138346672,
-0.00033521291334182024,
-0.00616037892177701,
-0.0023825676180422306,
-0.003092654049396515,
-0.002208752790465951,
-0.012940087355673313,
-0.009608210064470768,
-0.0026331108529120684,
-0.003479127073660493,
0.004062103107571602,
-0.005165420938283205,
0.0003195673052687198,
0.0013429191894829273,
0.00634009251371026,
-0.000636350188869983,
-0.001587755512446165,
0.001366059179417789,
0.005210335832089186,
-0.00531380157917738,
0.012689312919974327,
-0.013459389097988605,
0.005639348644763231,
-0.001940646325238049,
-0.015820279717445374,
0.007905048318207264,
0.010503393597900867,
-0.007453328929841518,
0.0017785230884328485,
0.004479901399463415,
0.002921278588473797,
-0.001761066378094256,
-0.004544027615338564,
-0.0033194043207913637,
-0.015559288673102856,
-0.001203258871100843,
0.017784621566534042,
0.00005133033846504986,
0.008929544128477573,
0.009148267097771168,
-0.0020623395685106516,
0.0017093410715460777,
0.00606796657666564,
0.0010221294360235333,
0.013602487742900848,
-0.01090837549418211,
0.00007686626486247405,
0.002178383292630315,
-0.006949943490326405,
-0.00023868940479587764,
0.006300431676208973,
0.006750708911567926,
-0.000833330035675317,
0.0017879612278193235,
-0.007564815692603588,
-0.006838141940534115,
-0.01747014932334423,
-0.0014998845290392637,
0.009588700719177723,
-0.005604247562587261,
0.00737130967900157,
-0.011673610657453537,
0.003991929814219475,
0.005052684806287289,
0.005699517671018839,
0.0011151782236993313,
-0.00005917815724387765,
0.006920310668647289,
0.01105471607297659,
-0.007259043399244547,
0.003832136048004031,
0.001118204090744257,
-0.001472574076615274,
0.002412730362266302,
0.011192213743925095,
-0.008290417492389679,
-0.007807300426065922,
0.003974827937781811,
0.003862963989377022,
0.0010468059917911887,
-0.0032850175630301237,
-0.008585920557379723,
-0.00416704872623086,
0.0007495207246392965,
-0.006741989403963089,
0.005203926470130682,
0.0017443163087591529,
0.0038059770595282316,
-0.008200227282941341,
-0.00035511134774424136,
-0.004788172896951437,
-0.011930455453693867,
0.009733639657497406,
-0.0029610905330628157,
0.0024682972580194473,
0.013485913164913654,
0.0033748771529644728,
-0.012786907143890858,
0.0054073939099907875,
0.011180790141224861,
-0.002482410054653883,
0.0032755821011960506,
0.00691634276881814,
-0.00507832458242774,
-0.02293400838971138,
-0.004429538268595934,
-0.015873180702328682,
0.007125752978026867,
-0.002993006492033601,
0.0036710253916680813,
-0.007412570528686047,
0.007232649251818657,
0.0052958340384066105,
-0.013781916350126266,
-0.004485657904297113,
-0.0076604378409683704,
0.009548665955662727,
-0.0020153517834842205,
-0.00044854404404759407,
-0.0027686699759215117,
-0.0003647206467576325,
-0.002813891042023897,
-0.0028809462673962116,
-0.001976185478270054,
0.005093376152217388,
0.002072216710075736,
-0.002620871877297759,
0.003490966046229005,
-0.0069885943084955215,
0.0006582200876437128,
0.0013735167449340224,
-0.0121866250410676,
0.00029070154414512217,
0.004475361667573452,
-0.0012955998536199331,
-0.0031146646942943335,
0.000010285087228112388,
-0.0028662902768701315,
-0.006798680871725082,
-0.011961276642978191,
-0.0023689300287514925,
-0.0030462078284472227,
-0.0014087046729400754,
-0.012057661078870296,
-0.0018477460835129023,
-0.00919245183467865,
0.005553660448640585,
-0.006975176278501749,
0.007739485707134008,
0.003057485679164529,
-0.004315705504268408,
0.007372405845671892,
0.0005969891790300608,
0.0036673215217888355,
0.004338863305747509,
0.005899874959141016,
0.000026823199732461944,
-0.006653960328549147,
-0.012344670481979847,
0.012226319871842861,
-0.007054158020764589,
0.0023729573003947735,
0.012267679907381535,
0.005310315638780594,
0.006819473579525948,
-0.001283658784814179,
-0.0003947250952478498,
-0.0010279123671352863,
0.009883617050945759,
-0.014535230584442616,
0.004002329893410206,
-0.002760618459433317,
0.0022309748455882072,
0.002508635399863124,
-0.002316822065040469,
0.003484841203317046,
0.00913647934794426,
0.0009111954714171588,
-0.005335133522748947,
-0.00496580870822072,
0.000861228269059211,
0.004361631814390421,
-0.014448767527937889,
-0.0008477833471260965,
-0.0019930340349674225,
-0.0038160686381161213,
-0.004452339373528957,
-0.002130929846316576,
0.0004049765702802688,
0.005107556935399771,
-0.001078929053619504,
0.007362774573266506,
0.0009722887189127505,
-0.006416489835828543,
0.015880584716796875,
-0.005382474511861801,
-0.004195640794932842,
0.002761926967650652,
0.0018713517347350717,
-0.0003486253262963146,
-0.007466752547770739,
-0.002515775617212057,
0.002251142170280218,
0.00606835400685668,
-0.004458240699023008,
-0.005311438348144293,
-0.0011438479414209723,
0.0006224255193956196,
-0.010634450241923332,
0.0035117382649332285,
0.012067418545484543,
-0.0013217562809586525,
0.005427066702395678,
-0.003008507424965501,
-0.00959203764796257,
-0.014128251932561398,
0.05459614470601082,
-0.0011765932431444526,
0.004468218423426151,
0.005169157404452562,
-0.007515351288020611,
-0.000699751079082489,
-0.0036234131548553705,
0.008020504377782345,
-0.005467367358505726,
-0.0073640053160488605,
0.008574732579290867,
-0.003703358117491007,
0.004788380581885576,
0.004023045301437378,
-0.003347533056512475,
0.016488347202539444,
-0.0015188237885013223,
-0.015656467527151108,
-0.01878470554947853,
0.006251418963074684,
-0.004928435664623976,
-0.008716809563338757,
0.00881379283964634,
-0.003271621186286211,
-0.008679171092808247,
0.0009334504138678312,
0.004179351031780243,
0.003248455934226513,
-0.0005335547029972076,
-0.0012884668540209532,
-0.001490933122113347,
-0.0022133663296699524,
0.0024538682773709297,
0.005563611630350351,
0.009513293392956257,
-0.0034300184343010187,
0.0023983786813914776,
-0.0015081667806953192,
-0.002182074123993516,
-0.0022943783551454544,
0.004434274975210428,
0.00782198179513216,
0.0003912786487489939,
-0.001791779650375247,
0.004670892376452684,
0.0071360282599925995,
0.00005713482460123487,
0.010696472600102425,
0.00011468728189356625,
-0.00640508159995079,
0.007256422657519579,
0.007297528441995382,
0.0018358612433075905,
0.007639074232429266,
-0.0007506371475756168,
0.006071314215660095,
0.0025162422098219395,
-0.006021976470947266,
-0.01810527592897415,
-0.0017808768898248672,
0.006986658554524183,
0.009056063368916512,
-0.002711996901780367,
0.0018952620448544621,
-0.0038599336985498667,
-0.004731111694127321,
-0.008391916751861572,
-0.007726335432380438,
-0.002755755325779319,
0.0008117274846881628,
0.0026666303165256977,
0.0703413337469101,
-0.008377659134566784,
-0.0017169552156701684,
-0.008951670490205288,
-0.0004060606297571212,
-0.004685962572693825,
-0.000865480222273618,
0.002346592955291271,
-0.0019371454836800694,
0.0019538092892616987,
0.0023795105516910553,
-0.006556328851729631,
-0.01238888967782259,
-0.00000808821823738981,
0.0028541393112391233,
-0.0032118477392941713,
0.0030406585428863764,
0.0073218755424022675,
-0.010456855408847332,
-0.00015259088831953704,
-0.011347904801368713,
-0.0024890140630304813,
-0.003184371395036578,
-0.009307749569416046,
-0.004285486415028572,
-0.001397432992234826,
0.004710016306489706,
0.004136913921684027,
0.007330996450036764,
-0.003918370697647333,
0.007970438338816166,
-0.001123638590797782,
-0.001953782746568322,
-0.006464065983891487,
0.00024350505555048585,
-0.005972258746623993,
0.007636460941284895,
0.0007701033027842641,
-0.010610276833176613,
-0.005815428681671619,
-0.0006533163250423968,
0.00010161026148125529,
-0.005110743921250105,
0.0042344615794718266,
0.002126765437424183,
0.004306666553020477,
-0.004695707466453314,
-0.00014008597645442933,
-0.00663285655900836,
0.0013557403581216931,
-0.013072236441075802,
0.007910856045782566,
-0.1655077338218689,
0.008161191828548908,
0.006352336145937443,
-0.005353248678147793,
-0.0029288181103765965,
-0.015553454868495464,
-0.004399972036480904,
0.005578671116381884,
0.009727098979055882,
0.003415019018575549,
-0.001426213188096881,
-0.002856296021491289,
0.005146751180291176,
0.0020035186316818,
-0.0022577133495360613,
-0.005193048156797886,
0.0019998536445200443,
-0.006266809068620205,
-0.0005904713761992753,
0.005378772038966417,
0.0035927966237068176,
0.009295390918850899,
0.0017461003735661507,
0.0033263785298913717,
-0.0016231428598985076,
-0.00494861975312233,
0.0057670241221785545,
-0.0039580208249390125,
0.004147023893892765,
-0.012537611648440361,
-0.0025248052552342415,
-0.003198720049113035,
-0.0047959522344172,
0.0010406769579276443,
0.005654770415276289,
-0.00046538535389117897,
0.011052985675632954,
0.004274843726307154,
-0.008188731968402863,
0.00942461472004652,
-0.007704717572778463,
0.02578495442867279,
0.006872599013149738,
0.004196498543024063,
-0.001359643298201263,
-0.0063303085044026375,
-0.005445956252515316,
0.006851240061223507,
0.0010997276986017823,
0.009660422801971436,
-0.012198970653116703,
0.001705351984128356,
0.005087884608656168,
0.018589017912745476,
-0.0056105079129338264,
-0.009263560175895691,
-0.004526330623775721,
-0.000775292341131717,
0.0009656799375079572,
0.007725589908659458,
0.009996912442147732,
-0.00305724935606122,
0.00856260396540165,
-0.002316401805728674,
-0.021638015285134315,
0.0023348003160208464,
-0.003617364214733243,
-0.005764539819210768,
0.0032908243592828512,
0.0066018616780638695,
0.008696516044437885,
0.000524846080224961,
0.0027085680048912764,
-0.0013218316016718745,
0.0056702736765146255,
-0.0012301284587010741,
0.006726840976625681,
-0.0027565867640078068,
0.005298379343003035,
-0.009429157711565495,
0.007131021935492754,
-0.009846191853284836,
-0.001051008002832532,
0.0029102591797709465,
-0.0017225986812263727,
0.011572974734008312,
0.003424539230763912,
-0.0027810498140752316,
0.00012175613665021956,
-0.011722337454557419,
-0.0014382577501237392,
0.004658990539610386,
0.0015825765440240502,
-0.008123485371470451,
0.0018454756354913116,
0.0007874815491959453,
0.00632075872272253,
0.008400176651775837,
-0.009732543490827084,
0.008754917420446873,
0.0056334431283175945,
-0.005458310712128878,
-0.0012513537658378482,
-0.006674956995993853,
0.0016257228562608361,
0.005160721950232983,
-0.006450936198234558,
-0.005801999941468239,
0.00399608863517642,
-0.005191479343920946,
-0.004474235232919455,
0.005365636665374041,
-0.011816665530204773,
-0.00823605339974165,
-0.002113075228407979,
-0.0088631771504879,
-0.0016124113462865353
] |
8a4ad309763c3cfd1dc25a625d22290970950e53 | 946 | py | Python | tests/src/Diksha_Reports/usage_by_textbook/download_all_collection_records.py | JalajaTR/cQube | 6bf58ab25f0c36709630987ab730bbd5d9192c03 | [
"MIT"
] | null | null | null | tests/src/Diksha_Reports/usage_by_textbook/download_all_collection_records.py | JalajaTR/cQube | 6bf58ab25f0c36709630987ab730bbd5d9192c03 | [
"MIT"
] | 2 | 2022-02-01T00:55:12.000Z | 2022-03-29T22:29:09.000Z | tests/src/Diksha_Reports/usage_by_textbook/download_all_collection_records.py | JalajaTR/cQube | 6bf58ab25f0c36709630987ab730bbd5d9192c03 | [
"MIT"
] | null | null | null | import os
import time
from selenium.webdriver.support.select import Select
from Data.parameters import Data
from get_dir import pwd
from reuse_func import GetData
class All_records_download():
def __init__(self,driver):
self.driver = driver
self.filename =''
def test_download_csv(self):
self.data = GetData()
self.p = pwd()
self.driver.find_element_by_xpath(Data.hyper_link).click()
self.data.page_loading(self.driver)
colltype = Select(self.driver.find_element_by_name('collection_type'))
colltype.select_by_visible_text(' Overall ')
self.data.page_loading(self.driver)
self.driver.find_element_by_id(Data.Download).click()
time.sleep(4)
self.filename = self.p.get_download_dir() + '/collectionType_all_data.csv'
time.sleep(2)
file = os.path.isfile(self.filename)
os.remove(self.filename)
return file
| 28.666667 | 82 | 0.684989 | 1 | 0.9081 | [
0.0008492212509736419,
0.02474304847419262,
0.008567060343921185,
0.00025915741571225226,
0.00442745815962553,
-0.004532575607299805,
-0.0090714730322361,
0.00214057182893157,
-0.009833521209657192,
0.003467879258096218,
0.0032145974691957235,
0.004067515954375267,
0.009401821531355381,
-0.01606091670691967,
0.003000639844685793,
0.017195390537381172,
-0.054711706936359406,
0.0014007785357534885,
-0.004113038070499897,
0.0008911119657568634,
-0.010422177612781525,
0.009116039611399174,
0.007458401843905449,
0.007014365401118994,
0.0064073544926941395,
-0.0004838071472477168,
0.009089956991374493,
0.002172607695683837,
-0.009783653542399406,
-0.006516787223517895,
-0.002187530742958188,
-0.001973728882148862,
-0.007451412733644247,
-0.006656535901129246,
0.007698527071624994,
-0.0026871308218687773,
-0.00020136836974415928,
-0.019523484632372856,
0.012549941428005695,
-0.004057182464748621,
-0.0056009008549153805,
-0.014875871129333973,
0.002801985014230013,
0.0035045628901571035,
-0.009431730024516582,
0.0028292371425777674,
-0.0036745218094438314,
0.00209433794952929,
-0.012218606658279896,
0.003799927420914173,
-0.012014874257147312,
0.004939637146890163,
0.013812518678605556,
0.0032945938874036074,
-0.00600562384352088,
-0.006608208175748587,
0.010334093123674393,
0.00022428116062656045,
-0.01117125153541565,
0.00015091818931978196,
-0.005130498670041561,
-0.002014571102336049,
0.004990078508853912,
0.0026059483643621206,
-0.018443550914525986,
-0.006634721998125315,
-0.00710692536085844,
0.0032721746247261763,
-0.0007514122989960015,
0.004632190801203251,
0.00199693045578897,
-0.0006266356213018298,
0.0068153575994074345,
0.0040186382830142975,
0.004013192839920521,
-0.004919889383018017,
-0.002136056777089834,
0.0025561884976923466,
0.006272312253713608,
0.0028901861514896154,
0.0047241454012691975,
-0.00697949668392539,
0.004425510298460722,
0.010625525377690792,
0.012709581293165684,
0.007755263242870569,
0.0189837459474802,
-0.011027499102056026,
0.04525895044207573,
0.007890847511589527,
-0.01087607629597187,
0.002881642896682024,
-0.007512671872973442,
-0.0023624992463737726,
-0.004253552295267582,
-0.030109722167253494,
-0.0018797244410961866,
-0.005372700747102499,
-0.00016836907889228314,
0.0049705966375768185,
0.0012110619572922587,
0.006762361619621515,
0.0010337401181459427,
-0.00435588089749217,
-0.009519954212009907,
0.016352688893675804,
-0.009155647829174995,
-0.0040024700574576855,
0.006051636766642332,
0.0012945695780217648,
-0.01188816037029028,
0.0010976179037243128,
-0.00046356386155821383,
-0.01492447778582573,
0.0032879107166081667,
0.00009625344682717696,
-0.006123675499111414,
0.05586468428373337,
-0.0025747893378138542,
0.001843190286308527,
-0.004209333099424839,
-0.000734966597519815,
0.000715391244739294,
0.00668810959905386,
0.011070278473198414,
-0.003384708659723401,
0.01283204834908247,
0.006948860362172127,
0.005993836559355259,
0.009687033481895924,
-0.0015775684732943773,
0.009426009841263294,
-0.0038283977191895247,
-0.0012319962261244655,
0.0015660688513889909,
-0.007535202894359827,
0.008313464932143688,
-0.003476898418739438,
-0.006897344253957272,
0.0015565858921036124,
-0.00143067364115268,
-0.009300313889980316,
0.001180629595182836,
-0.0020257967989891768,
0.0006730305030941963,
-0.01205357350409031,
-0.0035839939955621958,
-0.0036778561770915985,
-0.002709760796278715,
0.0024985866621136665,
0.00862919446080923,
0.0031817066483199596,
0.0038600533735007048,
-0.006899636704474688,
-0.009172615595161915,
-0.0018553342670202255,
-0.004967085551470518,
0.0001125969210988842,
0.008569382131099701,
0.003350103972479701,
-0.008608909323811531,
-0.0007842840277589858,
0.005073018372058868,
0.0027012410573661327,
-0.0014145729364827275,
0.0022387956269085407,
-0.00788198597729206,
0.00901796855032444,
-0.0007554182084277272,
0.005271581932902336,
0.013741899281740189,
-0.004179875832051039,
-0.0014408042188733816,
0.00025203294353559613,
0.005423304159194231,
-0.001318523078225553,
0.005116183776408434,
0.010205972008407116,
-0.002427786123007536,
-0.004671803209930658,
0.007973503321409225,
0.004064273089170456,
0.008517073467373848,
0.007987516932189465,
-0.002227537566795945,
0.001294562709517777,
-0.0065714470110833645,
-0.001995355822145939,
0.005649617873132229,
-0.003694085171446204,
0.006857577711343765,
0.004876826424151659,
-0.01406881958246231,
-0.005360039882361889,
0.0008942494750954211,
-0.010745357722043991,
0.0006493122782558203,
0.01414836198091507,
0.012483716942369938,
-0.00007346139318542555,
0.0037018456496298313,
-0.011009715497493744,
-0.0014689010567963123,
0.005619217175990343,
0.003490310860797763,
-0.013963871635496616,
-0.9563272595405579,
0.006397897377610207,
0.004094164352864027,
0.000963590806350112,
0.007493189070373774,
0.002853141399100423,
0.0021702684462070465,
0.003832797519862652,
0.016954321414232254,
-0.009882478043437004,
-0.007063307333737612,
-0.011368428356945515,
-0.012971538119018078,
0.0004924398381263018,
-0.006443867459893227,
-0.0012038395507261157,
-0.007313336245715618,
-0.008008996956050396,
-0.0042976392433047295,
-0.0036470575723797083,
-0.002741651376709342,
0.010508017614483833,
-0.0024506384506821632,
0.006585049908608198,
0.001776313642039895,
0.0020303833298385143,
-0.008832760155200958,
-0.0028748929034918547,
-0.0021616420708596706,
-0.0021270872093737125,
-0.0073753115721046925,
-0.013490616343915462,
-0.0050054374150931835,
0.0019203441916033626,
0.009857235476374626,
0.00261530838906765,
0.009535008110105991,
-0.0013331202790141106,
0.0038328117225319147,
-0.010093028657138348,
0.006951359566301107,
0.0036353140603750944,
0.003619246184825897,
-0.028178555890917778,
-0.0014231425011530519,
-0.0015630966518074274,
-0.009164255112409592,
0.009092830121517181,
-0.0005826868582516909,
-0.0010534754255786538,
-0.0039013060741126537,
-0.004870058968663216,
0.009304462932050228,
-0.008766356855630875,
0.004780357237905264,
-0.004766345955431461,
-0.005345457699149847,
-0.00134452641941607,
-0.007907325401902199,
-0.0004438063479028642,
0.002463210141286254,
-0.0033164932392537594,
-0.00412287563085556,
-0.0020158530678600073,
0.004194647539407015,
0.0022820811718702316,
0.0007164351991377771,
-0.01866401545703411,
-0.00618630601093173,
0.0013553410535678267,
0.00038150098407641053,
-0.0015420139534398913,
-0.00277117732912302,
0.002400332363322377,
-0.008445880375802517,
0.0070384591817855835,
0.0029048172291368246,
0.0018772606272250414,
-0.012008636258542538,
-0.001978744752705097,
-0.010952658951282501,
-0.008542736060917377,
0.002257408108562231,
-0.004735815804451704,
-0.002081914572045207,
0.0006102278712205589,
0.0024797776713967323,
0.007536798715591431,
-0.005340282339602709,
0.004095727112144232,
0.01305436808615923,
-0.004492088221013546,
-0.008448648266494274,
0.007115060929208994,
0.007644807919859886,
0.003158800769597292,
-0.004914897494018078,
0.0013838837621733546,
0.008264473639428616,
0.008556637912988663,
0.0001562935212859884,
0.00583758344873786,
-0.0016580160008743405,
0.009604680351912975,
-0.0008392613963223994,
0.0006569534889422357,
-0.0038680145516991615,
-0.0009746804716996849,
-0.002115628682076931,
-0.0028689007740467787,
-0.003131467616185546,
-0.0034180476795881987,
-0.010735496878623962,
-0.011026378720998764,
-0.003152713645249605,
0.002846183953806758,
0.0016223579877987504,
-0.0038045858964323997,
-0.0014912198530510068,
0.001719701336696744,
0.008919940330088139,
0.000728523766156286,
-0.00442944560199976,
-0.0009187821415252984,
0.002017094986513257,
-0.008354158140718937,
0.01882844790816307,
-0.010313238948583603,
0.006998644210398197,
-0.001420794753357768,
-0.016995981335639954,
0.008157915435731411,
0.011884474195539951,
-0.006969572044909,
0.0017782088834792376,
0.0022585545666515827,
0.002536179032176733,
-0.001930955215357244,
-0.004687917418777943,
-0.001560586504638195,
-0.01957113854587078,
-0.0007032460416667163,
0.02099987119436264,
0.0002935330558102578,
0.01103702001273632,
0.010627467185258865,
-0.0049408660270273685,
0.0008811480947770178,
0.010482719168066978,
0.0031862673349678516,
0.01213825773447752,
-0.00926152616739273,
0.0006001064903102815,
0.003152655204758048,
-0.006936637684702873,
0.0020358306355774403,
0.004211742896586657,
0.0035339943133294582,
-0.0035190973430871964,
0.00230365339666605,
-0.009135816246271133,
-0.007050056476145983,
-0.019041990861296654,
-0.0032009335700422525,
0.004757036454975605,
-0.004008892457932234,
0.00483414763584733,
-0.011285228654742241,
0.0019740676507353783,
0.0057438132353127,
0.005449976772069931,
0.0003597505565267056,
0.0005202957545407116,
0.006233497057110071,
0.013071038760244846,
-0.0072724404744803905,
0.0008935252553783357,
0.005430332850664854,
-0.004270853009074926,
-0.00006170198321342468,
0.008542395196855068,
-0.006048189476132393,
-0.005476353690028191,
0.004490859340876341,
0.002644340740516782,
-0.00020400820358190686,
-0.00365884299390018,
-0.007224001921713352,
-0.0028070418629795313,
0.002491296036168933,
-0.0050486670807003975,
0.0008646537899039686,
-0.0013982271775603294,
0.0037438005674630404,
-0.009890679270029068,
-0.00016327304183505476,
-0.0011594987008720636,
-0.011322038248181343,
0.008950774557888508,
-0.0005640643066726625,
-0.0016859392635524273,
0.01313934475183487,
0.0020606298930943012,
-0.01372569054365158,
0.006219392642378807,
0.008686460554599762,
-0.004912924021482468,
0.004558464977890253,
0.00878041610121727,
-0.004279799293726683,
-0.019940176978707314,
-0.0011857390636578202,
-0.014731715433299541,
0.005281987600028515,
-0.003940211143344641,
0.003988112322986126,
-0.00871008075773716,
0.0064207105897367,
0.00759542640298605,
-0.012214151211082935,
-0.003262801095843315,
-0.008844893425703049,
0.010010948404669762,
-0.0005460816901177168,
-0.000026020319637609646,
-0.0035040085203945637,
-0.0005191786913201213,
-0.002541473601013422,
-0.002993397181853652,
-0.0008875539642758667,
0.003522667568176985,
0.0025372712407261133,
-0.0027769727166742086,
0.002632205141708255,
-0.0021471302025020123,
-0.0011741732014343143,
0.0018360065296292305,
-0.011241234838962555,
0.00220042304135859,
0.007022316101938486,
-0.0016817834693938494,
-0.004526420962065458,
0.001172192394733429,
-0.002256870036944747,
-0.00706473970785737,
-0.011422941461205482,
-0.0033334081526845694,
-0.005071807187050581,
-0.0020508081652224064,
-0.011442325077950954,
-0.0026198734994977713,
-0.01035293098539114,
0.009376592002809048,
-0.007931786589324474,
0.007054708898067474,
0.0076957084238529205,
-0.005331670865416527,
0.004501220770180225,
-0.0010083455126732588,
0.005502333864569664,
0.0013024300569668412,
0.004872060846537352,
0.0021015710663050413,
-0.005333720240741968,
-0.011762376874685287,
0.0104470020160079,
-0.009294711984694004,
0.0015099034644663334,
0.015231030993163586,
0.0073508950881659985,
0.010390261188149452,
-0.0011220858432352543,
0.0014742285711690784,
0.0034087728708982468,
0.00728520518168807,
-0.015211427584290504,
0.002957439748570323,
-0.004608986433595419,
-0.0019229112658649683,
0.005146555136889219,
-0.006749078631401062,
0.004609146621078253,
0.008337639272212982,
0.002258831402286887,
-0.005901268683373928,
-0.0014564176090061665,
0.0008382167434319854,
0.002893072087317705,
-0.013720919378101826,
0.0012898097047582269,
-0.0028484549839049578,
-0.005611826200038195,
-0.001270910375751555,
-0.0011333511210978031,
0.000661620229948312,
0.0031233245972543955,
-0.0009866562904790044,
0.007764286361634731,
0.0036350484006106853,
-0.003596946829929948,
0.015046430751681328,
-0.004409724846482277,
-0.006409300956875086,
0.0023787878453731537,
0.002559739863499999,
-0.0027129892259836197,
-0.005098108202219009,
-0.001963859423995018,
0.0017727661179378629,
0.007341363467276096,
-0.0039639705792069435,
-0.00773383304476738,
-0.0020133976358920336,
0.0012005794560536742,
-0.006270567886531353,
-0.0005548672052100301,
0.012958659790456295,
-0.0034873788245022297,
0.005802143830806017,
-0.0010185417486354709,
-0.007755693979561329,
-0.012699521146714687,
0.05543171614408493,
-0.0017540473490953445,
0.002888408722355962,
0.006469481159001589,
-0.004903330933302641,
-0.0015102982288226485,
-0.0008834978216327727,
0.0067965192720294,
-0.00653577595949173,
-0.009023016318678856,
0.00855438131839037,
-0.003519822610542178,
0.001565499696880579,
0.003467355854809284,
-0.00042930131894536316,
0.01979212276637554,
-0.005189945455640554,
-0.017214100807905197,
-0.016959626227617264,
0.004221959039568901,
-0.004814474377781153,
-0.0067788222804665565,
0.008953605778515339,
-0.005029145162552595,
-0.0026129588950425386,
0.0008111185161396861,
0.004101618193089962,
-0.00023105244326870888,
-0.0015336814103648067,
-0.0012485913466662169,
-0.0014008369762450457,
-0.0008708621026016772,
0.002389278495684266,
0.003441702574491501,
0.00959621462970972,
-0.0018337937071919441,
0.0037684449926018715,
0.0015464083990082145,
-0.0029778587631881237,
0.0002281634951941669,
0.00719783129170537,
0.006622982677072287,
-0.002006956608965993,
-0.0037052398547530174,
0.007933497428894043,
0.004135109484195709,
0.00046675046905875206,
0.012387879192829132,
0.0008381938678212464,
-0.0051701851189136505,
0.00632265442982316,
0.009164188988506794,
0.0001472892618039623,
0.006894888821989298,
-0.001643655588850379,
0.007198578678071499,
0.0030706131365150213,
-0.010684480890631676,
-0.013810397125780582,
-0.0026770683471113443,
0.008124103769659996,
0.010821770876646042,
0.0006047755596227944,
0.00029833524604327977,
-0.0004191446350887418,
-0.004321505315601826,
-0.008600142784416676,
-0.007357823196798563,
-0.0012025176547467709,
0.001308122999034822,
0.005355199333280325,
0.06868018209934235,
-0.006838969886302948,
-0.0003635917091742158,
-0.008866136893630028,
-0.0009496106067672372,
0.0005489093018695712,
-0.0002414281916571781,
-0.0006739214877597988,
-0.0005266983644105494,
0.002803462091833353,
0.004267546813935041,
-0.008208063431084156,
-0.010070933029055595,
-0.0004476112371776253,
0.0032571901101619005,
-0.002092815237119794,
0.0017134308582171798,
0.006651079282164574,
-0.00882822833955288,
0.0024369359016418457,
-0.011930938810110092,
-0.0009661433869041502,
-0.002058480167761445,
-0.009749460965394974,
-0.004491558764129877,
-0.00388898653909564,
0.005173958372324705,
0.004200169816613197,
0.00518439058214426,
-0.001962146954610944,
0.00477991346269846,
-0.0018827911699190736,
0.0004340082232374698,
-0.005589379463344812,
-0.00041249848436564207,
-0.004635840654373169,
0.007315502967685461,
0.002052311785519123,
-0.011612847447395325,
-0.006658761762082577,
0.0003529988753143698,
-0.0017713239649310708,
-0.006491886917501688,
0.006870517507195473,
-0.0001911355648189783,
0.0035488996654748917,
-0.0023615555837750435,
0.0025227218866348267,
-0.006353435106575489,
0.0029087134171277285,
-0.014512483030557632,
0.005602547433227301,
-0.17784585058689117,
0.009855696931481361,
0.005763797555118799,
-0.005635752808302641,
-0.003998564090579748,
-0.01314824540168047,
-0.006362521555274725,
0.003912106156349182,
0.011123872362077236,
0.00467465678229928,
-5.95877907016984e-7,
0.00007389989332295954,
0.0026892279274761677,
0.003450426971539855,
-0.0026768557727336884,
-0.003639193484559655,
0.00312679260969162,
-0.004316970240324736,
0.0029979317914694548,
0.005774462595582008,
0.004741727840155363,
0.00842039193958044,
0.0016859738389030099,
0.0029057818464934826,
0.0008731853449717164,
-0.005095059052109718,
0.004850305151194334,
-0.0018033090746030211,
0.005189892835915089,
-0.01374673843383789,
-0.005424155853688717,
-0.004888995084911585,
-0.0039636436849832535,
0.00007413186540361494,
0.004184856079518795,
-0.0003189800772815943,
0.008428486064076424,
-0.0005634996923618019,
-0.006791732273995876,
0.007694034371525049,
-0.005565633997321129,
0.029287628829479218,
0.004048345144838095,
0.007949086837470531,
0.0004374140698928386,
-0.005311368033289909,
-0.00511645944789052,
0.010863706469535828,
0.0015901989536359906,
0.013241130858659744,
-0.014247354120016098,
-0.0013264764565974474,
0.0040909163653850555,
0.018541306257247925,
-0.006289876066148281,
-0.010143271647393703,
-0.009875253774225712,
-0.0029858145862817764,
0.0022293273359537125,
0.008392056450247765,
0.011540652252733707,
-0.003913457505404949,
0.008177133277058601,
-0.0037098852917551994,
-0.02345009334385395,
0.0042427945882081985,
-0.002625095658004284,
-0.005548557732254267,
0.002580188447609544,
0.005686951335519552,
0.010483491234481335,
-0.004454637411981821,
0.004364498890936375,
-0.0021671911235898733,
0.002245117211714387,
-0.0017005113186314702,
0.006964175496250391,
-0.003957460634410381,
0.006764480844140053,
-0.011387255042791367,
0.011097629554569721,
-0.009072407148778439,
-0.002293973695486784,
0.003099221969023347,
-0.005356392357498407,
0.009444884955883026,
0.005447376985102892,
-0.005538839381188154,
-0.0015010022325441241,
-0.012140990234911442,
-0.0018146198708564043,
0.0010808720253407955,
0.003197598038241267,
-0.007756818551570177,
0.004390494432300329,
-0.0015809442847967148,
0.005614445544779301,
0.006765604950487614,
-0.011186552233994007,
0.0069778086617589,
0.004316375125199556,
-0.00680816313251853,
-0.0009683999815024436,
-0.006603331305086613,
0.0023099733516573906,
0.0052803209982812405,
-0.006084110587835312,
-0.008147942833602428,
0.004504735115915537,
-0.005623271688818932,
-0.003583700628951192,
0.00550293130800128,
-0.009373034350574017,
-0.008484543301165104,
-0.0044764247722923756,
-0.011880781501531601,
0.0001459325576433912
] |
8a4baa5bb9eb37f79466bfa86485901ebe84452b | 39,528 | py | Python | yt_dlp/cookies.py | Naysabots/yt-dlp | bef4697a6a4c225d010125d6ff6dfbfd4fb76e33 | [
"Unlicense"
] | null | null | null | yt_dlp/cookies.py | Naysabots/yt-dlp | bef4697a6a4c225d010125d6ff6dfbfd4fb76e33 | [
"Unlicense"
] | null | null | null | yt_dlp/cookies.py | Naysabots/yt-dlp | bef4697a6a4c225d010125d6ff6dfbfd4fb76e33 | [
"Unlicense"
] | null | null | null | import contextlib
import ctypes
import json
import os
import shutil
import struct
import subprocess
import sys
import tempfile
from datetime import datetime, timedelta, timezone
from enum import Enum, auto
from hashlib import pbkdf2_hmac
from .aes import (
aes_cbc_decrypt_bytes,
aes_gcm_decrypt_and_verify_bytes,
unpad_pkcs7,
)
from .compat import compat_b64decode, compat_cookiejar_Cookie
from .minicurses import MultilinePrinter, QuietMultilinePrinter
from .utils import Popen, YoutubeDLCookieJar, error_to_str, expand_path
try:
import sqlite3
SQLITE_AVAILABLE = True
except ImportError:
# although sqlite3 is part of the standard library, it is possible to compile python without
# sqlite support. See: https://github.com/yt-dlp/yt-dlp/issues/544
SQLITE_AVAILABLE = False
try:
import secretstorage
SECRETSTORAGE_AVAILABLE = True
except ImportError:
SECRETSTORAGE_AVAILABLE = False
SECRETSTORAGE_UNAVAILABLE_REASON = (
'as the `secretstorage` module is not installed. '
'Please install by running `python3 -m pip install secretstorage`.')
except Exception as _err:
SECRETSTORAGE_AVAILABLE = False
SECRETSTORAGE_UNAVAILABLE_REASON = f'as the `secretstorage` module could not be initialized. {_err}'
CHROMIUM_BASED_BROWSERS = {'brave', 'chrome', 'chromium', 'edge', 'opera', 'vivaldi'}
SUPPORTED_BROWSERS = CHROMIUM_BASED_BROWSERS | {'firefox', 'safari'}
class YDLLogger:
def __init__(self, ydl=None):
self._ydl = ydl
def debug(self, message):
if self._ydl:
self._ydl.write_debug(message)
def info(self, message):
if self._ydl:
self._ydl.to_screen(f'[Cookies] {message}')
def warning(self, message, only_once=False):
if self._ydl:
self._ydl.report_warning(message, only_once)
def error(self, message):
if self._ydl:
self._ydl.report_error(message)
def progress_bar(self):
"""Return a context manager with a print method. (Optional)"""
# Do not print to files/pipes, loggers, or when --no-progress is used
if not self._ydl or self._ydl.params.get('noprogress') or self._ydl.params.get('logger'):
return
file = self._ydl._out_files['error']
try:
if not file.isatty():
return
except BaseException:
return
printer = MultilinePrinter(file, preserve_output=False)
printer.print = lambda message: printer.print_at_line(f'[Cookies] {message}', 0)
return printer
def _create_progress_bar(logger):
if hasattr(logger, 'progress_bar'):
printer = logger.progress_bar()
if printer:
return printer
printer = QuietMultilinePrinter()
printer.print = lambda _: None
return printer
def load_cookies(cookie_file, browser_specification, ydl):
cookie_jars = []
if browser_specification is not None:
browser_name, profile, keyring = _parse_browser_specification(*browser_specification)
cookie_jars.append(extract_cookies_from_browser(browser_name, profile, YDLLogger(ydl), keyring=keyring))
if cookie_file is not None:
cookie_file = expand_path(cookie_file)
jar = YoutubeDLCookieJar(cookie_file)
if os.access(cookie_file, os.R_OK):
jar.load(ignore_discard=True, ignore_expires=True)
cookie_jars.append(jar)
return _merge_cookie_jars(cookie_jars)
def extract_cookies_from_browser(browser_name, profile=None, logger=YDLLogger(), *, keyring=None):
if browser_name == 'firefox':
return _extract_firefox_cookies(profile, logger)
elif browser_name == 'safari':
return _extract_safari_cookies(profile, logger)
elif browser_name in CHROMIUM_BASED_BROWSERS:
return _extract_chrome_cookies(browser_name, profile, keyring, logger)
else:
raise ValueError(f'unknown browser: {browser_name}')
def _extract_firefox_cookies(profile, logger):
logger.info('Extracting cookies from firefox')
if not SQLITE_AVAILABLE:
logger.warning('Cannot extract cookies from firefox without sqlite3 support. '
'Please use a python interpreter compiled with sqlite3 support')
return YoutubeDLCookieJar()
if profile is None:
search_root = _firefox_browser_dir()
elif _is_path(profile):
search_root = profile
else:
search_root = os.path.join(_firefox_browser_dir(), profile)
cookie_database_path = _find_most_recently_used_file(search_root, 'cookies.sqlite', logger)
if cookie_database_path is None:
raise FileNotFoundError(f'could not find firefox cookies database in {search_root}')
logger.debug(f'Extracting cookies from: "{cookie_database_path}"')
with tempfile.TemporaryDirectory(prefix='yt_dlp') as tmpdir:
cursor = None
try:
cursor = _open_database_copy(cookie_database_path, tmpdir)
cursor.execute('SELECT host, name, value, path, expiry, isSecure FROM moz_cookies')
jar = YoutubeDLCookieJar()
with _create_progress_bar(logger) as progress_bar:
table = cursor.fetchall()
total_cookie_count = len(table)
for i, (host, name, value, path, expiry, is_secure) in enumerate(table):
progress_bar.print(f'Loading cookie {i: 6d}/{total_cookie_count: 6d}')
cookie = compat_cookiejar_Cookie(
version=0, name=name, value=value, port=None, port_specified=False,
domain=host, domain_specified=bool(host), domain_initial_dot=host.startswith('.'),
path=path, path_specified=bool(path), secure=is_secure, expires=expiry, discard=False,
comment=None, comment_url=None, rest={})
jar.set_cookie(cookie)
logger.info(f'Extracted {len(jar)} cookies from firefox')
return jar
finally:
if cursor is not None:
cursor.connection.close()
def _firefox_browser_dir():
if sys.platform in ('linux', 'linux2'):
return os.path.expanduser('~/.mozilla/firefox')
elif sys.platform == 'win32':
return os.path.expandvars(R'%APPDATA%\Mozilla\Firefox\Profiles')
elif sys.platform == 'darwin':
return os.path.expanduser('~/Library/Application Support/Firefox')
else:
raise ValueError(f'unsupported platform: {sys.platform}')
def _get_chromium_based_browser_settings(browser_name):
# https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md
if sys.platform in ('linux', 'linux2'):
config = _config_home()
browser_dir = {
'brave': os.path.join(config, 'BraveSoftware/Brave-Browser'),
'chrome': os.path.join(config, 'google-chrome'),
'chromium': os.path.join(config, 'chromium'),
'edge': os.path.join(config, 'microsoft-edge'),
'opera': os.path.join(config, 'opera'),
'vivaldi': os.path.join(config, 'vivaldi'),
}[browser_name]
elif sys.platform == 'win32':
appdata_local = os.path.expandvars('%LOCALAPPDATA%')
appdata_roaming = os.path.expandvars('%APPDATA%')
browser_dir = {
'brave': os.path.join(appdata_local, R'BraveSoftware\Brave-Browser\User Data'),
'chrome': os.path.join(appdata_local, R'Google\Chrome\User Data'),
'chromium': os.path.join(appdata_local, R'Chromium\User Data'),
'edge': os.path.join(appdata_local, R'Microsoft\Edge\User Data'),
'opera': os.path.join(appdata_roaming, R'Opera Software\Opera Stable'),
'vivaldi': os.path.join(appdata_local, R'Vivaldi\User Data'),
}[browser_name]
elif sys.platform == 'darwin':
appdata = os.path.expanduser('~/Library/Application Support')
browser_dir = {
'brave': os.path.join(appdata, 'BraveSoftware/Brave-Browser'),
'chrome': os.path.join(appdata, 'Google/Chrome'),
'chromium': os.path.join(appdata, 'Chromium'),
'edge': os.path.join(appdata, 'Microsoft Edge'),
'opera': os.path.join(appdata, 'com.operasoftware.Opera'),
'vivaldi': os.path.join(appdata, 'Vivaldi'),
}[browser_name]
else:
raise ValueError(f'unsupported platform: {sys.platform}')
# Linux keyring names can be determined by snooping on dbus while opening the browser in KDE:
# dbus-monitor "interface='org.kde.KWallet'" "type=method_return"
keyring_name = {
'brave': 'Brave',
'chrome': 'Chrome',
'chromium': 'Chromium',
'edge': 'Microsoft Edge' if sys.platform == 'darwin' else 'Chromium',
'opera': 'Opera' if sys.platform == 'darwin' else 'Chromium',
'vivaldi': 'Vivaldi' if sys.platform == 'darwin' else 'Chrome',
}[browser_name]
browsers_without_profiles = {'opera'}
return {
'browser_dir': browser_dir,
'keyring_name': keyring_name,
'supports_profiles': browser_name not in browsers_without_profiles
}
def _extract_chrome_cookies(browser_name, profile, keyring, logger):
logger.info(f'Extracting cookies from {browser_name}')
if not SQLITE_AVAILABLE:
logger.warning(f'Cannot extract cookies from {browser_name} without sqlite3 support. '
'Please use a python interpreter compiled with sqlite3 support')
return YoutubeDLCookieJar()
config = _get_chromium_based_browser_settings(browser_name)
if profile is None:
search_root = config['browser_dir']
elif _is_path(profile):
search_root = profile
config['browser_dir'] = os.path.dirname(profile) if config['supports_profiles'] else profile
else:
if config['supports_profiles']:
search_root = os.path.join(config['browser_dir'], profile)
else:
logger.error(f'{browser_name} does not support profiles')
search_root = config['browser_dir']
cookie_database_path = _find_most_recently_used_file(search_root, 'Cookies', logger)
if cookie_database_path is None:
raise FileNotFoundError(f'could not find {browser_name} cookies database in "{search_root}"')
logger.debug(f'Extracting cookies from: "{cookie_database_path}"')
decryptor = get_cookie_decryptor(config['browser_dir'], config['keyring_name'], logger, keyring=keyring)
with tempfile.TemporaryDirectory(prefix='yt_dlp') as tmpdir:
cursor = None
try:
cursor = _open_database_copy(cookie_database_path, tmpdir)
cursor.connection.text_factory = bytes
column_names = _get_column_names(cursor, 'cookies')
secure_column = 'is_secure' if 'is_secure' in column_names else 'secure'
cursor.execute(f'SELECT host_key, name, value, encrypted_value, path, expires_utc, {secure_column} FROM cookies')
jar = YoutubeDLCookieJar()
failed_cookies = 0
unencrypted_cookies = 0
with _create_progress_bar(logger) as progress_bar:
table = cursor.fetchall()
total_cookie_count = len(table)
for i, line in enumerate(table):
progress_bar.print(f'Loading cookie {i: 6d}/{total_cookie_count: 6d}')
is_encrypted, cookie = _process_chrome_cookie(decryptor, *line)
if not cookie:
failed_cookies += 1
continue
elif not is_encrypted:
unencrypted_cookies += 1
jar.set_cookie(cookie)
if failed_cookies > 0:
failed_message = f' ({failed_cookies} could not be decrypted)'
else:
failed_message = ''
logger.info(f'Extracted {len(jar)} cookies from {browser_name}{failed_message}')
counts = decryptor.cookie_counts.copy()
counts['unencrypted'] = unencrypted_cookies
logger.debug(f'cookie version breakdown: {counts}')
return jar
finally:
if cursor is not None:
cursor.connection.close()
def _process_chrome_cookie(decryptor, host_key, name, value, encrypted_value, path, expires_utc, is_secure):
host_key = host_key.decode('utf-8')
name = name.decode('utf-8')
value = value.decode('utf-8')
path = path.decode('utf-8')
is_encrypted = not value and encrypted_value
if is_encrypted:
value = decryptor.decrypt(encrypted_value)
if value is None:
return is_encrypted, None
return is_encrypted, compat_cookiejar_Cookie(
version=0, name=name, value=value, port=None, port_specified=False,
domain=host_key, domain_specified=bool(host_key), domain_initial_dot=host_key.startswith('.'),
path=path, path_specified=bool(path), secure=is_secure, expires=expires_utc, discard=False,
comment=None, comment_url=None, rest={})
class ChromeCookieDecryptor:
"""
Overview:
Linux:
- cookies are either v10 or v11
- v10: AES-CBC encrypted with a fixed key
- v11: AES-CBC encrypted with an OS protected key (keyring)
- v11 keys can be stored in various places depending on the activate desktop environment [2]
Mac:
- cookies are either v10 or not v10
- v10: AES-CBC encrypted with an OS protected key (keyring) and more key derivation iterations than linux
- not v10: 'old data' stored as plaintext
Windows:
- cookies are either v10 or not v10
- v10: AES-GCM encrypted with a key which is encrypted with DPAPI
- not v10: encrypted with DPAPI
Sources:
- [1] https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/
- [2] https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/key_storage_linux.cc
- KeyStorageLinux::CreateService
"""
def decrypt(self, encrypted_value):
raise NotImplementedError('Must be implemented by sub classes')
@property
def cookie_counts(self):
raise NotImplementedError('Must be implemented by sub classes')
def get_cookie_decryptor(browser_root, browser_keyring_name, logger, *, keyring=None):
if sys.platform in ('linux', 'linux2'):
return LinuxChromeCookieDecryptor(browser_keyring_name, logger, keyring=keyring)
elif sys.platform == 'darwin':
return MacChromeCookieDecryptor(browser_keyring_name, logger)
elif sys.platform == 'win32':
return WindowsChromeCookieDecryptor(browser_root, logger)
else:
raise NotImplementedError(f'Chrome cookie decryption is not supported on this platform: {sys.platform}')
class LinuxChromeCookieDecryptor(ChromeCookieDecryptor):
def __init__(self, browser_keyring_name, logger, *, keyring=None):
self._logger = logger
self._v10_key = self.derive_key(b'peanuts')
password = _get_linux_keyring_password(browser_keyring_name, keyring, logger)
self._v11_key = None if password is None else self.derive_key(password)
self._cookie_counts = {'v10': 0, 'v11': 0, 'other': 0}
@staticmethod
def derive_key(password):
# values from
# https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/os_crypt_linux.cc
return pbkdf2_sha1(password, salt=b'saltysalt', iterations=1, key_length=16)
@property
def cookie_counts(self):
return self._cookie_counts
def decrypt(self, encrypted_value):
version = encrypted_value[:3]
ciphertext = encrypted_value[3:]
if version == b'v10':
self._cookie_counts['v10'] += 1
return _decrypt_aes_cbc(ciphertext, self._v10_key, self._logger)
elif version == b'v11':
self._cookie_counts['v11'] += 1
if self._v11_key is None:
self._logger.warning('cannot decrypt v11 cookies: no key found', only_once=True)
return None
return _decrypt_aes_cbc(ciphertext, self._v11_key, self._logger)
else:
self._cookie_counts['other'] += 1
return None
class MacChromeCookieDecryptor(ChromeCookieDecryptor):
def __init__(self, browser_keyring_name, logger):
self._logger = logger
password = _get_mac_keyring_password(browser_keyring_name, logger)
self._v10_key = None if password is None else self.derive_key(password)
self._cookie_counts = {'v10': 0, 'other': 0}
@staticmethod
def derive_key(password):
# values from
# https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/os_crypt_mac.mm
return pbkdf2_sha1(password, salt=b'saltysalt', iterations=1003, key_length=16)
@property
def cookie_counts(self):
return self._cookie_counts
def decrypt(self, encrypted_value):
version = encrypted_value[:3]
ciphertext = encrypted_value[3:]
if version == b'v10':
self._cookie_counts['v10'] += 1
if self._v10_key is None:
self._logger.warning('cannot decrypt v10 cookies: no key found', only_once=True)
return None
return _decrypt_aes_cbc(ciphertext, self._v10_key, self._logger)
else:
self._cookie_counts['other'] += 1
# other prefixes are considered 'old data' which were stored as plaintext
# https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/os_crypt_mac.mm
return encrypted_value
class WindowsChromeCookieDecryptor(ChromeCookieDecryptor):
def __init__(self, browser_root, logger):
self._logger = logger
self._v10_key = _get_windows_v10_key(browser_root, logger)
self._cookie_counts = {'v10': 0, 'other': 0}
@property
def cookie_counts(self):
return self._cookie_counts
def decrypt(self, encrypted_value):
version = encrypted_value[:3]
ciphertext = encrypted_value[3:]
if version == b'v10':
self._cookie_counts['v10'] += 1
if self._v10_key is None:
self._logger.warning('cannot decrypt v10 cookies: no key found', only_once=True)
return None
# https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/os_crypt_win.cc
# kNonceLength
nonce_length = 96 // 8
# boringssl
# EVP_AEAD_AES_GCM_TAG_LEN
authentication_tag_length = 16
raw_ciphertext = ciphertext
nonce = raw_ciphertext[:nonce_length]
ciphertext = raw_ciphertext[nonce_length:-authentication_tag_length]
authentication_tag = raw_ciphertext[-authentication_tag_length:]
return _decrypt_aes_gcm(ciphertext, self._v10_key, nonce, authentication_tag, self._logger)
else:
self._cookie_counts['other'] += 1
# any other prefix means the data is DPAPI encrypted
# https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/os_crypt_win.cc
return _decrypt_windows_dpapi(encrypted_value, self._logger).decode('utf-8')
def _extract_safari_cookies(profile, logger):
if profile is not None:
logger.error('safari does not support profiles')
if sys.platform != 'darwin':
raise ValueError(f'unsupported platform: {sys.platform}')
cookies_path = os.path.expanduser('~/Library/Cookies/Cookies.binarycookies')
if not os.path.isfile(cookies_path):
logger.debug('Trying secondary cookie location')
cookies_path = os.path.expanduser('~/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies')
if not os.path.isfile(cookies_path):
raise FileNotFoundError('could not find safari cookies database')
with open(cookies_path, 'rb') as f:
cookies_data = f.read()
jar = parse_safari_cookies(cookies_data, logger=logger)
logger.info(f'Extracted {len(jar)} cookies from safari')
return jar
class ParserError(Exception):
pass
class DataParser:
def __init__(self, data, logger):
self._data = data
self.cursor = 0
self._logger = logger
def read_bytes(self, num_bytes):
if num_bytes < 0:
raise ParserError(f'invalid read of {num_bytes} bytes')
end = self.cursor + num_bytes
if end > len(self._data):
raise ParserError('reached end of input')
data = self._data[self.cursor:end]
self.cursor = end
return data
def expect_bytes(self, expected_value, message):
value = self.read_bytes(len(expected_value))
if value != expected_value:
raise ParserError(f'unexpected value: {value} != {expected_value} ({message})')
def read_uint(self, big_endian=False):
data_format = '>I' if big_endian else '<I'
return struct.unpack(data_format, self.read_bytes(4))[0]
def read_double(self, big_endian=False):
data_format = '>d' if big_endian else '<d'
return struct.unpack(data_format, self.read_bytes(8))[0]
def read_cstring(self):
buffer = []
while True:
c = self.read_bytes(1)
if c == b'\x00':
return b''.join(buffer).decode('utf-8')
else:
buffer.append(c)
def skip(self, num_bytes, description='unknown'):
if num_bytes > 0:
self._logger.debug(f'skipping {num_bytes} bytes ({description}): {self.read_bytes(num_bytes)!r}')
elif num_bytes < 0:
raise ParserError(f'invalid skip of {num_bytes} bytes')
def skip_to(self, offset, description='unknown'):
self.skip(offset - self.cursor, description)
def skip_to_end(self, description='unknown'):
self.skip_to(len(self._data), description)
def _mac_absolute_time_to_posix(timestamp):
return int((datetime(2001, 1, 1, 0, 0, tzinfo=timezone.utc) + timedelta(seconds=timestamp)).timestamp())
def _parse_safari_cookies_header(data, logger):
p = DataParser(data, logger)
p.expect_bytes(b'cook', 'database signature')
number_of_pages = p.read_uint(big_endian=True)
page_sizes = [p.read_uint(big_endian=True) for _ in range(number_of_pages)]
return page_sizes, p.cursor
def _parse_safari_cookies_page(data, jar, logger):
p = DataParser(data, logger)
p.expect_bytes(b'\x00\x00\x01\x00', 'page signature')
number_of_cookies = p.read_uint()
record_offsets = [p.read_uint() for _ in range(number_of_cookies)]
if number_of_cookies == 0:
logger.debug(f'a cookies page of size {len(data)} has no cookies')
return
p.skip_to(record_offsets[0], 'unknown page header field')
with _create_progress_bar(logger) as progress_bar:
for i, record_offset in enumerate(record_offsets):
progress_bar.print(f'Loading cookie {i: 6d}/{number_of_cookies: 6d}')
p.skip_to(record_offset, 'space between records')
record_length = _parse_safari_cookies_record(data[record_offset:], jar, logger)
p.read_bytes(record_length)
p.skip_to_end('space in between pages')
def _parse_safari_cookies_record(data, jar, logger):
p = DataParser(data, logger)
record_size = p.read_uint()
p.skip(4, 'unknown record field 1')
flags = p.read_uint()
is_secure = bool(flags & 0x0001)
p.skip(4, 'unknown record field 2')
domain_offset = p.read_uint()
name_offset = p.read_uint()
path_offset = p.read_uint()
value_offset = p.read_uint()
p.skip(8, 'unknown record field 3')
expiration_date = _mac_absolute_time_to_posix(p.read_double())
_creation_date = _mac_absolute_time_to_posix(p.read_double()) # noqa: F841
try:
p.skip_to(domain_offset)
domain = p.read_cstring()
p.skip_to(name_offset)
name = p.read_cstring()
p.skip_to(path_offset)
path = p.read_cstring()
p.skip_to(value_offset)
value = p.read_cstring()
except UnicodeDecodeError:
logger.warning('failed to parse Safari cookie because UTF-8 decoding failed', only_once=True)
return record_size
p.skip_to(record_size, 'space at the end of the record')
cookie = compat_cookiejar_Cookie(
version=0, name=name, value=value, port=None, port_specified=False,
domain=domain, domain_specified=bool(domain), domain_initial_dot=domain.startswith('.'),
path=path, path_specified=bool(path), secure=is_secure, expires=expiration_date, discard=False,
comment=None, comment_url=None, rest={})
jar.set_cookie(cookie)
return record_size
def parse_safari_cookies(data, jar=None, logger=YDLLogger()):
"""
References:
- https://github.com/libyal/dtformats/blob/main/documentation/Safari%20Cookies.asciidoc
- this data appears to be out of date but the important parts of the database structure is the same
- there are a few bytes here and there which are skipped during parsing
"""
if jar is None:
jar = YoutubeDLCookieJar()
page_sizes, body_start = _parse_safari_cookies_header(data, logger)
p = DataParser(data[body_start:], logger)
for page_size in page_sizes:
_parse_safari_cookies_page(p.read_bytes(page_size), jar, logger)
p.skip_to_end('footer')
return jar
class _LinuxDesktopEnvironment(Enum):
"""
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/base/nix/xdg_util.h
DesktopEnvironment
"""
OTHER = auto()
CINNAMON = auto()
GNOME = auto()
KDE = auto()
PANTHEON = auto()
UNITY = auto()
XFCE = auto()
class _LinuxKeyring(Enum):
"""
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/key_storage_util_linux.h
SelectedLinuxBackend
"""
KWALLET = auto()
GNOMEKEYRING = auto()
BASICTEXT = auto()
SUPPORTED_KEYRINGS = _LinuxKeyring.__members__.keys()
def _get_linux_desktop_environment(env):
"""
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/base/nix/xdg_util.cc
GetDesktopEnvironment
"""
xdg_current_desktop = env.get('XDG_CURRENT_DESKTOP', None)
desktop_session = env.get('DESKTOP_SESSION', None)
if xdg_current_desktop is not None:
xdg_current_desktop = xdg_current_desktop.split(':')[0].strip()
if xdg_current_desktop == 'Unity':
if desktop_session is not None and 'gnome-fallback' in desktop_session:
return _LinuxDesktopEnvironment.GNOME
else:
return _LinuxDesktopEnvironment.UNITY
elif xdg_current_desktop == 'GNOME':
return _LinuxDesktopEnvironment.GNOME
elif xdg_current_desktop == 'X-Cinnamon':
return _LinuxDesktopEnvironment.CINNAMON
elif xdg_current_desktop == 'KDE':
return _LinuxDesktopEnvironment.KDE
elif xdg_current_desktop == 'Pantheon':
return _LinuxDesktopEnvironment.PANTHEON
elif xdg_current_desktop == 'XFCE':
return _LinuxDesktopEnvironment.XFCE
elif desktop_session is not None:
if desktop_session in ('mate', 'gnome'):
return _LinuxDesktopEnvironment.GNOME
elif 'kde' in desktop_session:
return _LinuxDesktopEnvironment.KDE
elif 'xfce' in desktop_session:
return _LinuxDesktopEnvironment.XFCE
else:
if 'GNOME_DESKTOP_SESSION_ID' in env:
return _LinuxDesktopEnvironment.GNOME
elif 'KDE_FULL_SESSION' in env:
return _LinuxDesktopEnvironment.KDE
return _LinuxDesktopEnvironment.OTHER
def _choose_linux_keyring(logger):
"""
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/key_storage_util_linux.cc
SelectBackend
"""
desktop_environment = _get_linux_desktop_environment(os.environ)
logger.debug(f'detected desktop environment: {desktop_environment.name}')
if desktop_environment == _LinuxDesktopEnvironment.KDE:
linux_keyring = _LinuxKeyring.KWALLET
elif desktop_environment == _LinuxDesktopEnvironment.OTHER:
linux_keyring = _LinuxKeyring.BASICTEXT
else:
linux_keyring = _LinuxKeyring.GNOMEKEYRING
return linux_keyring
def _get_kwallet_network_wallet(logger):
""" The name of the wallet used to store network passwords.
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/kwallet_dbus.cc
KWalletDBus::NetworkWallet
which does a dbus call to the following function:
https://api.kde.org/frameworks/kwallet/html/classKWallet_1_1Wallet.html
Wallet::NetworkWallet
"""
default_wallet = 'kdewallet'
try:
proc = Popen([
'dbus-send', '--session', '--print-reply=literal',
'--dest=org.kde.kwalletd5',
'/modules/kwalletd5',
'org.kde.KWallet.networkWallet'
], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
stdout, stderr = proc.communicate_or_kill()
if proc.returncode != 0:
logger.warning('failed to read NetworkWallet')
return default_wallet
else:
network_wallet = stdout.decode('utf-8').strip()
logger.debug(f'NetworkWallet = "{network_wallet}"')
return network_wallet
except Exception as e:
logger.warning(f'exception while obtaining NetworkWallet: {e}')
return default_wallet
def _get_kwallet_password(browser_keyring_name, logger):
logger.debug('using kwallet-query to obtain password from kwallet')
if shutil.which('kwallet-query') is None:
logger.error('kwallet-query command not found. KWallet and kwallet-query '
'must be installed to read from KWallet. kwallet-query should be'
'included in the kwallet package for your distribution')
return b''
network_wallet = _get_kwallet_network_wallet(logger)
try:
proc = Popen([
'kwallet-query',
'--read-password', f'{browser_keyring_name} Safe Storage',
'--folder', f'{browser_keyring_name} Keys',
network_wallet
], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
stdout, stderr = proc.communicate_or_kill()
if proc.returncode != 0:
logger.error(f'kwallet-query failed with return code {proc.returncode}. Please consult '
'the kwallet-query man page for details')
return b''
else:
if stdout.lower().startswith(b'failed to read'):
logger.debug('failed to read password from kwallet. Using empty string instead')
# this sometimes occurs in KDE because chrome does not check hasEntry and instead
# just tries to read the value (which kwallet returns "") whereas kwallet-query
# checks hasEntry. To verify this:
# dbus-monitor "interface='org.kde.KWallet'" "type=method_return"
# while starting chrome.
# this may be a bug as the intended behaviour is to generate a random password and store
# it, but that doesn't matter here.
return b''
else:
logger.debug('password found')
if stdout[-1:] == b'\n':
stdout = stdout[:-1]
return stdout
except Exception as e:
logger.warning(f'exception running kwallet-query: {error_to_str(e)}')
return b''
def _get_gnome_keyring_password(browser_keyring_name, logger):
if not SECRETSTORAGE_AVAILABLE:
logger.error(f'secretstorage not available {SECRETSTORAGE_UNAVAILABLE_REASON}')
return b''
# the Gnome keyring does not seem to organise keys in the same way as KWallet,
# using `dbus-monitor` during startup, it can be observed that chromium lists all keys
# and presumably searches for its key in the list. It appears that we must do the same.
# https://github.com/jaraco/keyring/issues/556
with contextlib.closing(secretstorage.dbus_init()) as con:
col = secretstorage.get_default_collection(con)
for item in col.get_all_items():
if item.get_label() == f'{browser_keyring_name} Safe Storage':
return item.get_secret()
else:
logger.error('failed to read from keyring')
return b''
def _get_linux_keyring_password(browser_keyring_name, keyring, logger):
# note: chrome/chromium can be run with the following flags to determine which keyring backend
# it has chosen to use
# chromium --enable-logging=stderr --v=1 2>&1 | grep key_storage_
# Chromium supports a flag: --password-store=<basic|gnome|kwallet> so the automatic detection
# will not be sufficient in all cases.
keyring = _LinuxKeyring[keyring] if keyring else _choose_linux_keyring(logger)
logger.debug(f'Chosen keyring: {keyring.name}')
if keyring == _LinuxKeyring.KWALLET:
return _get_kwallet_password(browser_keyring_name, logger)
elif keyring == _LinuxKeyring.GNOMEKEYRING:
return _get_gnome_keyring_password(browser_keyring_name, logger)
elif keyring == _LinuxKeyring.BASICTEXT:
# when basic text is chosen, all cookies are stored as v10 (so no keyring password is required)
return None
assert False, f'Unknown keyring {keyring}'
def _get_mac_keyring_password(browser_keyring_name, logger):
logger.debug('using find-generic-password to obtain password from OSX keychain')
try:
proc = Popen(
['security', 'find-generic-password',
'-w', # write password to stdout
'-a', browser_keyring_name, # match 'account'
'-s', f'{browser_keyring_name} Safe Storage'], # match 'service'
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
stdout, stderr = proc.communicate_or_kill()
if stdout[-1:] == b'\n':
stdout = stdout[:-1]
return stdout
except Exception as e:
logger.warning(f'exception running find-generic-password: {error_to_str(e)}')
return None
def _get_windows_v10_key(browser_root, logger):
path = _find_most_recently_used_file(browser_root, 'Local State', logger)
if path is None:
logger.error('could not find local state file')
return None
logger.debug(f'Found local state file at "{path}"')
with open(path, encoding='utf8') as f:
data = json.load(f)
try:
base64_key = data['os_crypt']['encrypted_key']
except KeyError:
logger.error('no encrypted key in Local State')
return None
encrypted_key = compat_b64decode(base64_key)
prefix = b'DPAPI'
if not encrypted_key.startswith(prefix):
logger.error('invalid key')
return None
return _decrypt_windows_dpapi(encrypted_key[len(prefix):], logger)
def pbkdf2_sha1(password, salt, iterations, key_length):
return pbkdf2_hmac('sha1', password, salt, iterations, key_length)
def _decrypt_aes_cbc(ciphertext, key, logger, initialization_vector=b' ' * 16):
plaintext = unpad_pkcs7(aes_cbc_decrypt_bytes(ciphertext, key, initialization_vector))
try:
return plaintext.decode('utf-8')
except UnicodeDecodeError:
logger.warning('failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?', only_once=True)
return None
def _decrypt_aes_gcm(ciphertext, key, nonce, authentication_tag, logger):
try:
plaintext = aes_gcm_decrypt_and_verify_bytes(ciphertext, key, authentication_tag, nonce)
except ValueError:
logger.warning('failed to decrypt cookie (AES-GCM) because the MAC check failed. Possibly the key is wrong?', only_once=True)
return None
try:
return plaintext.decode('utf-8')
except UnicodeDecodeError:
logger.warning('failed to decrypt cookie (AES-GCM) because UTF-8 decoding failed. Possibly the key is wrong?', only_once=True)
return None
def _decrypt_windows_dpapi(ciphertext, logger):
"""
References:
- https://docs.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptunprotectdata
"""
from ctypes.wintypes import DWORD
class DATA_BLOB(ctypes.Structure):
_fields_ = [('cbData', DWORD),
('pbData', ctypes.POINTER(ctypes.c_char))]
buffer = ctypes.create_string_buffer(ciphertext)
blob_in = DATA_BLOB(ctypes.sizeof(buffer), buffer)
blob_out = DATA_BLOB()
ret = ctypes.windll.crypt32.CryptUnprotectData(
ctypes.byref(blob_in), # pDataIn
None, # ppszDataDescr: human readable description of pDataIn
None, # pOptionalEntropy: salt?
None, # pvReserved: must be NULL
None, # pPromptStruct: information about prompts to display
0, # dwFlags
ctypes.byref(blob_out) # pDataOut
)
if not ret:
logger.warning('failed to decrypt with DPAPI', only_once=True)
return None
result = ctypes.string_at(blob_out.pbData, blob_out.cbData)
ctypes.windll.kernel32.LocalFree(blob_out.pbData)
return result
def _config_home():
return os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
def _open_database_copy(database_path, tmpdir):
# cannot open sqlite databases if they are already in use (e.g. by the browser)
database_copy_path = os.path.join(tmpdir, 'temporary.sqlite')
shutil.copy(database_path, database_copy_path)
conn = sqlite3.connect(database_copy_path)
return conn.cursor()
def _get_column_names(cursor, table_name):
table_info = cursor.execute(f'PRAGMA table_info({table_name})').fetchall()
return [row[1].decode('utf-8') for row in table_info]
def _find_most_recently_used_file(root, filename, logger):
# if there are multiple browser profiles, take the most recently used one
i, paths = 0, []
with _create_progress_bar(logger) as progress_bar:
for curr_root, dirs, files in os.walk(root):
for file in files:
i += 1
progress_bar.print(f'Searching for "{filename}": {i: 6d} files searched')
if file == filename:
paths.append(os.path.join(curr_root, file))
return None if not paths else max(paths, key=lambda path: os.lstat(path).st_mtime)
def _merge_cookie_jars(jars):
output_jar = YoutubeDLCookieJar()
for jar in jars:
for cookie in jar:
output_jar.set_cookie(cookie)
if jar.filename is not None:
output_jar.filename = jar.filename
return output_jar
def _is_path(value):
return os.path.sep in value
def _parse_browser_specification(browser_name, profile=None, keyring=None):
if browser_name not in SUPPORTED_BROWSERS:
raise ValueError(f'unsupported browser: "{browser_name}"')
if keyring not in (None, *SUPPORTED_KEYRINGS):
raise ValueError(f'unsupported keyring: "{keyring}"')
if profile is not None and _is_path(profile):
profile = os.path.expanduser(profile)
return browser_name, profile, keyring
| 39.646941 | 134 | 0.664921 | 1 | 2.0706 | [
0.003334618406370282,
0.025327205657958984,
0.016490694135427475,
0.011427578516304493,
-0.03283870220184326,
0.007564689498394728,
-0.03484921529889107,
-0.012394719757139683,
-0.01006300002336502,
0.03839680925011635,
-0.022675499320030212,
-0.019010860472917557,
-0.0007244172156788409,
-0.0352737158536911,
-0.010535725392401218,
0.019836550578475,
0.05892031639814377,
-0.027150122448801994,
-0.03751710429787636,
-0.010141352191567421,
-0.018331779167056084,
0.015846526250243187,
-0.013254783116281033,
0.009241446852684021,
0.014844897203147411,
0.0194142684340477,
0.027368921786546707,
0.0071187326684594154,
-0.010662670247256756,
0.002774783642962575,
-0.013756023719906807,
0.0004664967709686607,
0.026248054578900337,
0.0018830228364095092,
-0.004783303011208773,
0.010579776018857956,
-0.009096866473555565,
0.07800482958555222,
-0.007638461887836456,
0.022411372512578964,
0.006895764730870724,
-0.007071306928992271,
-0.03555962070822716,
-0.09088977426290512,
0.00663753179833293,
0.03283729404211044,
-0.018040837720036507,
0.006520823109894991,
-0.043034184724092484,
0.019673727452754974,
0.0060379644855856895,
0.03841318562626839,
-0.02259962446987629,
-0.013096234761178493,
0.010419891215860844,
0.01999013125896454,
-0.006178813520818949,
-0.03344664350152016,
0.008319681510329247,
-0.0127009442076087,
0.021201863884925842,
-0.019700653851032257,
0.0002622005995362997,
0.005612427368760109,
0.05195767432451248,
0.045654475688934326,
-0.01369505189359188,
-0.013098328374326229,
-0.09795781970024109,
-0.021307790651917458,
-0.004253723192960024,
0.011532960459589958,
0.05602754279971123,
0.061297982931137085,
0.03451482206583023,
-0.0015056851552799344,
0.0011844515101984143,
-0.006304731126874685,
0.009621812961995602,
-0.01832788623869419,
-0.03922627121210098,
0.024402201175689697,
-0.014941771514713764,
0.0036789781879633665,
-0.004437386058270931,
0.0060859424993395805,
0.048818137496709824,
-0.04525800049304962,
0.014043745584785938,
0.026523152366280556,
-0.03143956884741783,
-0.0033069797791540623,
0.012783106416463852,
-0.011939316056668758,
-0.02896292135119438,
-0.02724269963800907,
-0.021832434460520744,
-0.02105899341404438,
0.003372655250132084,
0.04384278133511543,
0.0015119127929210663,
-0.027006573975086212,
-0.017037084326148033,
-0.013402172364294529,
-0.021776780486106873,
-0.01580733433365822,
-0.03650564327836037,
0.013141190633177757,
-0.011341716162860394,
-0.013836567290127277,
-0.006157826632261276,
-0.018107516691088676,
0.01227998360991478,
0.037637680768966675,
0.02482329122722149,
-0.0032356204465031624,
0.023304183036088943,
0.0034456353168934584,
0.03668767958879471,
0.05330793559551239,
0.009746518917381763,
-0.0058263749815523624,
0.012629938311874866,
-0.041945286095142365,
-0.05706331878900528,
0.05039671063423157,
-0.0015265553956851363,
-0.034380268305540085,
0.011624757200479507,
-0.007707768119871616,
0.014771690592169762,
-0.016756976023316383,
-0.008932767435908318,
-0.022297710180282593,
0.000845235597807914,
-0.02000569738447666,
-0.036333564668893814,
0.02272171340882778,
-0.014289703220129013,
0.022771749645471573,
0.02332371100783348,
0.0003919650916941464,
0.015389890410006046,
0.0321042574942112,
0.024872560054063797,
-0.01836221292614937,
0.013866988010704517,
-0.012941906228661537,
0.013713793829083443,
-0.008603149093687534,
-0.005202824715524912,
-0.00542270764708519,
0.00040578542393632233,
0.022556565701961517,
-0.0009741157409735024,
0.01588597148656845,
-0.016671767458319664,
-0.0033378361258655787,
-0.032461609691381454,
0.03631804510951042,
-0.020802684128284454,
-0.023605121299624443,
-0.010594584047794342,
0.03018811158835888,
-0.03031890280544758,
0.03203897550702095,
-0.007711234036833048,
0.0012455007527023554,
-0.013977627269923687,
-0.017533954232931137,
0.02591542713344097,
0.006848497781902552,
0.004328455310314894,
-0.0007884161896072328,
-0.013922356069087982,
-0.0070147099904716015,
0.05024576559662819,
0.00489709572866559,
-0.014658574014902115,
-0.019972002133727074,
0.01342772413045168,
0.0075611243955791,
0.02781934291124344,
0.04445231705904007,
0.018397796899080276,
-0.017992163076996803,
-0.024830520153045654,
-0.021292204037308693,
0.0012700579827651381,
-0.02037607505917549,
-0.011285336688160896,
-0.007703257258981466,
0.009694225154817104,
-0.02598360739648342,
0.017448173835873604,
0.029406452551484108,
0.02670428715646267,
0.0008901144028641284,
-0.023470820859074593,
-0.012555819004774094,
-0.011612443253397942,
-0.020194068551063538,
-0.01933434046804905,
0.05109046772122383,
-0.0064367568120360374,
-0.02917535789310932,
-0.720764696598053,
0.0007582167163491249,
-0.02284436859190464,
-0.03564440831542015,
0.013897075317800045,
0.01964203268289566,
-0.059064459055662155,
0.012300562113523483,
-0.0588420033454895,
-0.014878992922604084,
-0.002278067171573639,
-0.00474441796541214,
-0.04795435816049576,
0.0006135337753221393,
0.03339255973696709,
-0.019521674141287804,
0.02863503061234951,
-0.02834145538508892,
-0.015605252236127853,
0.008473178371787071,
-0.026524782180786133,
-0.04330393671989441,
-0.023255761712789536,
0.030804678797721863,
0.04177570715546608,
0.000762778683565557,
0.012002361007034779,
-0.004384809173643589,
-0.01026082318276167,
0.023927515372633934,
-0.00816584937274456,
-0.02883268892765045,
-0.033548492938280106,
-0.025883914902806282,
0.009566335938870907,
-0.0019640284590423107,
0.02511821873486042,
-0.008580027148127556,
-0.004770689643919468,
-0.0024338087532669306,
-0.03961308300495148,
-0.024684211239218712,
0.016110364347696304,
-0.05323786661028862,
-0.033866461366415024,
0.0347292535007,
-0.028078237548470497,
-0.03550546616315842,
0.027884453535079956,
0.028302842751145363,
0.015878932550549507,
0.020878054201602936,
-0.0026912761386483908,
-0.0363244004547596,
0.005879578646272421,
0.018850916996598244,
0.010504777543246746,
-0.0371529720723629,
0.008214873261749744,
0.028291981667280197,
-0.0313885472714901,
-0.032208945602178574,
-0.031215528026223183,
-0.015157748013734818,
-0.018237672746181488,
-0.011510618031024933,
0.03599109128117561,
-0.002989343833178282,
-0.031391821801662445,
-0.004785898141562939,
0.027253687381744385,
0.018027694895863533,
-0.01737203449010849,
0.08699203282594681,
0.025118326768279076,
-0.009438700042665005,
-0.00922517478466034,
0.017307084053754807,
0.005011922214180231,
-0.07338722795248032,
0.023770594969391823,
-0.019305042922496796,
-0.0004391235124785453,
0.010697235353291035,
-0.04021700471639633,
-0.002838259795680642,
0.002735069254413247,
0.009536177851259708,
-0.007202394772320986,
0.04776010289788246,
0.03358447179198265,
0.05380188301205635,
0.007671944797039032,
-0.0030498921405524015,
0.004806458484381437,
0.0043167308904230595,
-0.05056045949459076,
0.024639178067445755,
-0.007107579614967108,
0.02326161414384842,
-0.0183456651866436,
0.020350724458694458,
0.013130431063473225,
0.025200866162776947,
-0.009982071816921234,
-0.0027210647240281105,
-0.04680623859167099,
-0.0009092978434637189,
0.0007167382282204926,
-0.033101845532655716,
0.027948860079050064,
-0.005534241907298565,
-0.06798674166202545,
-0.006721475161612034,
-0.03336556628346443,
-0.023039989173412323,
0.02262999676167965,
-0.015538755804300308,
0.0371539480984211,
0.0023462767712771893,
-0.008622915484011173,
0.017831802368164062,
-0.032540448009967804,
-0.017471181228756905,
-0.0010637136874720454,
0.019693482667207718,
-0.059978194534778595,
0.031313855201005936,
0.034721679985523224,
0.004121412523090839,
-0.017613615840673447,
0.0031894047278910875,
0.0029592160135507584,
0.006467582657933235,
0.013476042076945305,
-0.04590034484863281,
0.013839354738593102,
-0.004118942189961672,
0.021059738472104073,
0.014660462737083435,
0.014666570350527763,
-0.00269755139015615,
0.0006832642247900367,
-0.044862620532512665,
0.022878821939229965,
0.007200048305094242,
0.018459489569067955,
0.031310196965932846,
0.07729870826005936,
0.01531099621206522,
-0.007083476986736059,
0.046615537256002426,
-0.029794281348586082,
0.04203018546104431,
-0.017207032069563866,
0.015054675750434399,
0.019626567140221596,
0.00736969755962491,
-0.00112984050065279,
0.009715870954096317,
-0.005356757435947657,
0.007319941651076078,
-0.026334956288337708,
-0.009301627054810524,
0.03240341693162918,
-0.01561669260263443,
-0.0008636432467028499,
0.033064503222703934,
0.022553449496626854,
0.01220789086073637,
0.027200814336538315,
-0.04641968756914139,
0.004636621568351984,
-0.00806272029876709,
-0.012451227754354477,
-0.006196713540703058,
-0.006036696489900351,
-0.03482704609632492,
0.01103593222796917,
-0.010266625322401524,
0.021961448714137077,
-0.006166952196508646,
-0.01692839525640011,
-0.001390544231981039,
0.020144741982221603,
-0.004961194470524788,
-0.036465227603912354,
0.031223053112626076,
0.014799557626247406,
-0.02498660795390606,
0.012772176414728165,
-0.017719263210892677,
-0.01479583140462637,
0.0052248029969632626,
0.000284442154224962,
-0.020915765315294266,
-0.006397439632564783,
0.02651047334074974,
0.01542106457054615,
-0.014405593276023865,
0.010478511452674866,
0.052827391773462296,
0.008786631748080254,
0.0005571002839133143,
-0.013103951700031757,
0.0813249796628952,
-0.016467450186610222,
-0.008477524854242802,
0.03234264254570007,
-0.029441481456160545,
0.008715586736798286,
0.015606644563376904,
0.019769323989748955,
-0.0362677276134491,
-0.020957624539732933,
0.05912259593605995,
-0.048573486506938934,
-0.03883117064833641,
-0.04505763575434685,
-0.0453149676322937,
0.005228523164987564,
-0.004938255064189434,
0.029293028637766838,
0.025485310703516006,
-0.007443100214004517,
-0.019995136186480522,
-0.03649875521659851,
0.011304454877972603,
0.027620911598205566,
0.005047135520726442,
-0.009065346792340279,
0.030527357012033463,
-0.019992010667920113,
-0.018196692690253258,
-0.03938761726021767,
0.027912326157093048,
-0.02211747318506241,
-0.022398361936211586,
0.03431537747383118,
-0.02193514071404934,
0.027402985841035843,
-0.00996458437293768,
-0.0073836324736475945,
0.011491135694086552,
0.015565060079097748,
0.02405303530395031,
0.020315811038017273,
-0.009661044925451279,
-0.038477472960948944,
-0.008316564373672009,
0.010276423767209053,
-0.029062243178486824,
0.02072056755423546,
-0.011176911182701588,
-0.015916060656309128,
0.004713721573352814,
-0.007704386953264475,
0.025369420647621155,
0.030690424144268036,
-0.002167903119698167,
0.004906778689473867,
0.00032887625275179744,
-0.01995965465903282,
0.009117498062551022,
0.0050328513607382774,
-0.00945974513888359,
-0.007542835548520088,
-0.05510757490992546,
0.01902017928659916,
0.009539458900690079,
0.024523446336388588,
0.0015729089500382543,
-0.00752099696546793,
0.0010774204274639487,
0.03143300861120224,
-0.01974264532327652,
-0.013624933548271656,
-0.031148158013820648,
0.014427367597818375,
0.026213062927126884,
-0.0064267865382134914,
0.00813189148902893,
0.05252888426184654,
0.0027365931309759617,
-0.024998797103762627,
-0.008264638483524323,
-0.005356437060981989,
-0.015106488950550556,
-0.038120660930871964,
-0.011259197257459164,
0.00017353839939460158,
-0.00634044548496604,
-0.006804844830185175,
0.024787019938230515,
-0.007838134653866291,
0.054536186158657074,
0.014633760787546635,
-0.019877154380083084,
0.03783588111400604,
-0.012866773642599583,
-0.008833449333906174,
-0.032236579805612564,
-0.021340560168027878,
0.0035637826658785343,
-0.009179852902889252,
0.0009668870479799807,
0.015622607432305813,
-0.004944609943777323,
0.03859212249517441,
0.013802504166960716,
0.019426017999649048,
0.012032382190227509,
0.007921612821519375,
-0.03513875976204872,
-0.03487420827150345,
-0.015740448608994484,
0.0029449963476508856,
0.0008597875712439418,
0.009961224161088467,
-0.03244598209857941,
0.023571809753775597,
0.0021347436122596264,
0.0012165101943537593,
0.016314087435603142,
0.004023945424705744,
-0.019915996119379997,
-0.03903452679514885,
-0.0053159617818892,
0.009358016774058342,
0.019213946536183357,
-0.014113151468336582,
-0.013422796502709389,
0.003906674683094025,
-0.002180461771786213,
0.015904230996966362,
-0.01675872504711151,
0.0069217374548316,
0.0195256769657135,
0.050966713577508926,
0.00968740601092577,
0.07730889320373535,
0.06290356069803238,
-0.013525789603590965,
0.006743346806615591,
-0.0019595285411924124,
0.02504074200987816,
-0.05868418514728546,
-0.008447024039924145,
0.03200145065784454,
0.03763865306973457,
0.0074742380529642105,
-0.026330048218369484,
-0.05740337818861008,
0.004817421548068523,
0.006838729605078697,
-0.02291097491979599,
0.021914273500442505,
-0.005334546323865652,
-0.00013792687968816608,
-0.03982209786772728,
0.02398156002163887,
-0.010972262360155582,
-0.03926564380526543,
0.0002644756168592721,
0.004398680292069912,
-0.01726696826517582,
0.015884270891547203,
-0.017155243083834648,
-0.0005428471486084163,
-0.009979024529457092,
-0.0005120434216223657,
-0.019969932734966278,
0.002078630728647113,
-0.010239659808576107,
0.007418666500598192,
0.008963026106357574,
0.02862042747437954,
0.011567700654268265,
-0.030065953731536865,
-0.014491860754787922,
-0.019166886806488037,
-0.046568114310503006,
0.008705701678991318,
-0.04536781087517738,
0.05381851643323898,
-0.01631283387541771,
0.05357738584280014,
-0.006145340856164694,
-0.0215297881513834,
-0.013758317567408085,
-0.022355902940034866,
0.006151210051029921,
0.032982535660266876,
0.0017313578864559531,
0.005441117100417614,
-0.00588189996778965,
-0.008933338336646557,
-0.01926298998296261,
-0.003333232831209898,
-0.016953976824879646,
-0.017374366521835327,
0.0005581572186201811,
0.00100239971652627,
-0.02595287747681141,
0.012382508255541325,
-0.0058997077867388725,
0.028164688497781754,
-0.005734030622988939,
-0.009991568513214588,
0.02526899054646492,
0.04083600640296936,
0.004247737117111683,
-0.008244652301073074,
-0.028833676129579544,
0.03956868126988411,
-0.04271199181675911,
-0.0435250885784626,
-0.01345969457179308,
0.020437194034457207,
0.010364264249801636,
0.005875026807188988,
0.010875023901462555,
0.0018611899577081203,
0.024644862860441208,
0.004395711701363325,
-0.029746046289801598,
-0.0077201067470014095,
-0.014275193214416504,
-0.005935647524893284,
0.04291243106126785,
-0.01857749931514263,
-0.02667444758117199,
-0.03462877497076988,
0.032602593302726746,
-0.0090176435187459,
0.011682050302624702,
0.030937351286411285,
0.034379176795482635,
-0.029609473422169685,
-0.005022907163947821,
-0.002899706130847335,
0.032327570021152496,
-0.02096172235906124,
0.018222155049443245,
-0.019151436164975166,
-0.06532217562198639,
0.0224791020154953,
-0.015067517757415771,
0.01866135746240616,
-0.017307424917817116,
0.009241530671715736,
0.0045541515573859215,
0.0326659120619297,
0.006163481622934341,
-0.01765141822397709,
-0.013929885812103748,
0.047589436173439026,
0.0021063790190964937,
-0.013795247301459312,
0.02337794005870819,
-0.005610584281384945,
-0.019073989242315292,
-0.019686462357640266,
0.01964375376701355,
0.004255977459251881,
0.00567271001636982,
0.0022774836979806423,
-0.031311728060245514,
0.03744479641318321,
-0.044387124478816986,
0.02628364972770214,
-0.0032444819808006287,
0.004904888570308685,
0.02038414031267166,
0.012005792930722237,
0.004953254014253616,
0.007773132994771004,
0.01608848199248314,
0.030760612338781357,
0.021625591441988945,
-0.06110742688179016,
0.03196531906723976,
-0.011620849370956421,
-0.01075646374374628,
0.038433339446783066,
0.03721693530678749,
-0.002515133237466216,
-0.020878354087471962,
-0.0010407855734229088,
-0.003409308847039938,
-0.0252964049577713,
-0.024387266486883163,
-0.068628691136837,
0.0037007417995482683,
-0.0095259640365839,
-0.01529946830123663,
0.02008538320660591,
-0.010728958062827587,
0.05767744407057762,
0.046394988894462585,
-0.02997230552136898,
-0.007572303991764784,
0.023533685132861137,
-0.00976188201457262,
0.04555470868945122,
-0.002432845067232847,
0.08139441907405853,
-0.00639366777613759,
0.006376845762133598,
-0.007984581403434277,
-0.017816120758652687,
0.015791144222021103,
-0.011469964869320393,
-0.010988878086209297,
0.01563672348856926,
0.02612893283367157,
0.0010184058919548988,
-0.008699946105480194,
-0.007108268793672323,
-0.0222685057669878,
0.01271415688097477,
0.024071985855698586,
-0.016715269535779953,
0.018486907705664635,
0.020959334447979927,
-0.02538895793259144,
0.011261184699833393,
-0.013278624042868614,
-0.024676647037267685,
0.031674839556217194,
0.010816673748195171,
0.006984043400734663,
-0.018971407786011696,
0.029527761042118073,
0.022851433604955673,
-0.026606984436511993,
-0.010469114407896996,
0.019769538193941116,
0.006788617465645075,
0.009701668284833431,
-0.0016223330749198794,
-0.0016227522864937782,
0.005488261580467224,
-0.0042194947600364685,
-0.025282982736825943,
-0.007053343113511801,
0.038682110607624054,
0.008330821059644222,
0.0006735509959980845,
0.030399711802601814,
-0.027610916644334793,
0.014113989658653736,
-0.019202053546905518,
0.02380559965968132,
-0.02189745381474495,
-0.029249724000692368,
-0.010033180005848408,
0.019246306270360947,
-0.008098994381725788,
-0.026250381022691727,
-0.002870230469852686,
0.027947744354605675
] |
8a4c2b7fd420450ab300e48488a392b1a4cf50ef | 1,205 | py | Python | hgtools/tests/conftest.py | jaraco/hgtools | 1090d139e5dbdab864da8f1917a9e674331b6f9b | [
"MIT"
] | 1 | 2017-05-17T15:12:29.000Z | 2017-05-17T15:12:29.000Z | hgtools/tests/conftest.py | jaraco/hgtools | 1090d139e5dbdab864da8f1917a9e674331b6f9b | [
"MIT"
] | 12 | 2016-01-01T14:43:44.000Z | 2021-10-03T02:13:19.000Z | hgtools/tests/conftest.py | jaraco/hgtools | 1090d139e5dbdab864da8f1917a9e674331b6f9b | [
"MIT"
] | null | null | null | import os
import pytest
from hgtools import managers
def _ensure_present(mgr):
try:
mgr.version()
except Exception:
pytest.skip()
@pytest.fixture
def tmpdir_as_cwd(tmpdir):
with tmpdir.as_cwd():
yield tmpdir
@pytest.fixture
def hg_repo(tmpdir_as_cwd):
mgr = managers.MercurialManager()
_ensure_present(mgr)
mgr._invoke('init', '.')
os.makedirs('bar')
touch('bar/baz')
mgr._invoke('addremove')
mgr._invoke('ci', '-m', 'committed')
with open('bar/baz', 'w') as baz:
baz.write('content')
mgr._invoke('ci', '-m', 'added content')
return tmpdir_as_cwd
@pytest.fixture
def git_repo(tmpdir_as_cwd):
mgr = managers.GitManager()
_ensure_present(mgr)
mgr._invoke('init')
mgr._invoke('config', 'user.email', 'hgtools@example.com')
mgr._invoke('config', 'user.name', 'HGTools')
os.makedirs('bar')
touch('bar/baz')
mgr._invoke('add', '.')
mgr._invoke('commit', '-m', 'committed')
with open('bar/baz', 'w') as baz:
baz.write('content')
mgr._invoke('commit', '-am', 'added content')
return tmpdir_as_cwd
def touch(filename):
with open(filename, 'a'):
pass
| 21.517857 | 62 | 0.624066 | 1 | 1.1166 | [
0.0016717275138944387,
0.023070475086569786,
0.009414000436663628,
0.001453850301913917,
0.006271772552281618,
-0.001669152406975627,
-0.009288748726248741,
0.00020546026644296944,
-0.006411558482795954,
0.004651048686355352,
0.0023558754473924637,
0.005570153705775738,
0.006546123884618282,
-0.017739783972501755,
0.0008622355526313186,
0.017323344945907593,
-0.05240999162197113,
0.0006004058523103595,
-0.004149125888943672,
0.003250671550631523,
-0.007347805425524712,
0.008944591507315636,
0.00881595816463232,
0.006350240204483271,
0.005924662575125694,
-0.0006164357182569802,
0.009173671714961529,
0.002425622893497348,
-0.0066238269209861755,
-0.008711770176887512,
-0.00025913171702995896,
-0.004288940690457821,
-0.007358987350016832,
-0.008109495043754578,
0.006799235939979553,
-0.00240262015722692,
0.0006608370458707213,
-0.016483763232827187,
0.01212870143353939,
-0.00516270287334919,
-0.008792232722043991,
-0.016699012368917465,
-0.0022882726043462753,
0.004034016747027636,
-0.008980660699307919,
0.0011605533072724938,
-0.0033679658081382513,
0.0025362325832247734,
-0.01169105339795351,
0.007185058668255806,
-0.009716753847897053,
0.0055962237529456615,
0.015454291366040707,
0.0030175717547535896,
-0.005838153883814812,
-0.007154850289225578,
0.0136486841365695,
0.0007196285878308117,
-0.010366235859692097,
0.00022637260553892702,
-0.004245423711836338,
-0.003423205344006419,
0.005789436399936676,
0.0013780867448076606,
-0.015213795937597752,
-0.005914208944886923,
-0.004028914496302605,
0.004560193978250027,
-0.0014639337314292789,
0.007487262599170208,
-0.0007229040493257344,
0.00014682831533718854,
0.0074184974655508995,
0.003016731468960643,
0.0034439738374203444,
-0.004873739089816809,
-0.0027598587330430746,
-0.0002915344957727939,
0.008149653673171997,
0.002782951109111309,
0.003985096700489521,
-0.006877006497234106,
0.004173499532043934,
0.010652453638613224,
0.01610151305794716,
0.007704867981374264,
0.019937772303819656,
-0.009253761731088161,
0.047460075467824936,
0.00821705162525177,
-0.00856513250619173,
0.002443167148157954,
-0.007076401729136705,
-0.0026093870401382446,
-0.003278781194239855,
-0.028010716661810875,
-0.0006398661644198,
-0.0036581959575414658,
0.0014655195409432054,
0.004754080902785063,
-0.000641842489130795,
0.004765707068145275,
-0.00262628891505301,
-0.0017157432157546282,
-0.009231891483068466,
0.010901818983256817,
-0.00785346981137991,
-0.003261506324633956,
0.006210231687873602,
0.0021732558961957693,
-0.011331981047987938,
-0.002007432747632265,
0.00021366748842410743,
-0.011684696190059185,
0.0038548612501472235,
0.004170517902821302,
-0.0064386725425720215,
0.05460837483406067,
-0.0014278735034167767,
0.002036540536209941,
-0.003748301649466157,
0.0015877827536314726,
0.0020252298563718796,
0.005394434556365013,
0.009999766014516354,
-0.003654106752946973,
0.0127979451790452,
0.009722095914185047,
0.0034555753227323294,
0.008162811398506165,
-0.0008361262152902782,
0.00898456759750843,
-0.00421404791995883,
-0.0030494763050228357,
0.002503636060282588,
-0.00793386809527874,
0.007475088816136122,
-0.0016677933745086193,
-0.007861676625907421,
-0.0005359690403565764,
-0.0005716909654438496,
-0.008894619531929493,
0.0028829111251980066,
-0.004781300667673349,
0.0025470817927271128,
-0.011689446866512299,
-0.005495263263583183,
-0.004123760852962732,
-0.004875269718468189,
0.0023954983334988356,
0.007866078987717628,
0.004814077168703079,
0.004127556923776865,
-0.005630452185869217,
-0.008498238399624825,
-0.0012348517775535583,
-0.005153781268745661,
0.0015417130198329687,
0.008027615956962109,
0.004039027262479067,
-0.009236027486622334,
-0.0007706491742283106,
0.0040524061769247055,
0.0036924167070537806,
-0.000789216544944793,
0.0015837219543755054,
-0.010610999539494514,
0.008332214318215847,
0.0017724145436659455,
0.00460681039839983,
0.012096491642296314,
-0.005700451321899891,
-0.0014130749041214585,
0.00013791557285003364,
0.004647309426218271,
0.001019744318909943,
0.005630897358059883,
0.009577414952218533,
-0.003759154351428151,
-0.0039608837105333805,
0.0029710084199905396,
0.004871775396168232,
0.009305906482040882,
0.00827397033572197,
-0.003724726615473628,
0.0010491027496755123,
-0.0035277025308459997,
-0.0014785027597099543,
0.006590485107153654,
-0.0032157953828573227,
0.006356436293572187,
0.005262922961264849,
-0.015773018822073936,
-0.008869359269738197,
0.0008713115239515901,
-0.008615675382316113,
0.001936598215252161,
0.013102978467941284,
0.013171630911529064,
-0.0031897600274533033,
0.001706046867184341,
-0.0104060722514987,
0.0002703620120882988,
0.008029533550143242,
0.0023662419989705086,
-0.013888071291148663,
-0.9581874012947083,
0.004636967554688454,
0.003937392495572567,
-0.0005777916521765292,
0.006513799540698528,
0.005095330066978931,
0.001980275847017765,
0.0036801015958189964,
0.015220771543681622,
-0.009490249678492546,
-0.007648942060768604,
-0.008794533088803291,
-0.00768089247867465,
-0.00003153993020532653,
-0.007746198680251837,
-0.00523732416331768,
-0.007725934963673353,
-0.007102629169821739,
-0.005507275462150574,
-0.0017556791426613927,
-0.0017310221446678042,
0.007585028186440468,
-0.0010644372086971998,
0.004362895153462887,
0.002749006263911724,
0.0028956045862287283,
-0.007421472109854221,
-0.0017445010598748922,
-0.0016027643578127027,
-0.0026725726202130318,
-0.007394976448267698,
-0.01542847789824009,
-0.0031818102579563856,
-0.0011859716614708304,
0.01058722659945488,
0.00032849377021193504,
0.007702875882387161,
-0.0023030568845570087,
0.0004593165940605104,
-0.005986121017485857,
0.005431119818240404,
-0.0009746011346578598,
0.002420099452137947,
-0.02981286309659481,
-0.0022925017401576042,
-0.0016316225519403815,
-0.0078501021489501,
0.008095309138298035,
0.0013716117246076465,
-0.0011604835744947195,
-0.0013466211967170238,
-0.005484353750944138,
0.009643693454563618,
-0.00854756310582161,
0.003300850512459874,
-0.0027813580818474293,
-0.00675076711922884,
-0.0020381773356348276,
-0.009278060868382454,
0.0018260885262861848,
0.005027522332966328,
-0.0016686854651197791,
-0.005257106851786375,
-0.003618587739765644,
0.0009644546080380678,
0.0020649221260100603,
0.00031758667319081724,
-0.015539544634521008,
-0.0060964045114815235,
-0.0011284403735771775,
-0.0011776103638112545,
-0.0027695377357304096,
-0.002316857688128948,
0.005035459529608488,
-0.008694629184901714,
0.006833455990999937,
0.0034331653732806444,
-0.000318036851240322,
-0.010177292861044407,
0.0008453323971480131,
-0.006414609029889107,
-0.010367779061198235,
0.0014778783079236746,
-0.005570908077061176,
-0.0037448867224156857,
0.0006022826419211924,
0.00008813892782200128,
0.007146626245230436,
-0.005569435656070709,
0.005467091221362352,
0.013347945176064968,
-0.0038948683068156242,
-0.009310344234108925,
0.006738767493516207,
0.005760456435382366,
-0.000530101649928838,
-0.0018085018964484334,
0.002157454611733556,
0.008507267571985722,
0.006506175268441439,
0.0018854005029425025,
0.006104959174990654,
-0.0008680151076987386,
0.007787962909787893,
0.0006224313983693719,
0.0014706276124343276,
-0.003128312062472105,
-0.001616715220734477,
-0.002491747261956334,
-0.0015334690688177943,
-0.005055090878158808,
-0.0014969705371186137,
-0.012865369208157063,
-0.010811584070324898,
-0.0028120572678744793,
-0.0003365334705449641,
0.0029586919117718935,
-0.004143401049077511,
-0.0008114062366075814,
0.003122976515442133,
0.009280710481107235,
-0.0013631836045533419,
-0.0032541556283831596,
0.0017600352875888348,
0.001687174430117011,
-0.009154756553471088,
0.015377555973827839,
-0.010794500820338726,
0.005967879667878151,
-0.0006999462493695319,
-0.014940931461751461,
0.008594851940870285,
0.011564156971871853,
-0.00812138244509697,
0.0017009141156449914,
0.002978032222017646,
0.004009587690234184,
-0.00047836045268923044,
-0.005001600366085768,
-0.004824856296181679,
-0.016674630343914032,
0.0010702877771109343,
0.01983865350484848,
0.0013290662318468094,
0.010852918028831482,
0.012569262646138668,
-0.003015909343957901,
0.0021046949550509453,
0.004923046100884676,
-0.00018346942670177668,
0.01209806278347969,
-0.008713852614164352,
-0.0004035512392874807,
0.0014040006790310144,
-0.007230963557958603,
0.0007438653847202659,
0.005012021400034428,
0.005385871976613998,
-0.0037741020787507296,
0.0035945738200098276,
-0.006638499908149242,
-0.004898094106465578,
-0.0170433446764946,
-0.0016849334351718426,
0.007498013321310282,
-0.005768731702119112,
0.006002590525895357,
-0.013448444195091724,
0.0033981711603701115,
0.005744095426052809,
0.00356742343865335,
-0.0014528663596138358,
0.0009350151522085071,
0.004889471456408501,
0.011533495038747787,
-0.007131492719054222,
0.004498561844229698,
0.002756123896688223,
-0.0014079514658078551,
0.000026921474272967316,
0.007251429371535778,
-0.0076184580102562904,
-0.0060228705406188965,
0.004410617519170046,
0.004625730216503143,
0.00025811244267970324,
-0.0038585711736232042,
-0.009567766450345516,
-0.0023551476188004017,
0.005209740716964006,
-0.005691854748874903,
0.0051438454538583755,
0.0026491277385503054,
0.005269292276352644,
-0.0061015719547867775,
-0.0006043679895810783,
-0.004628132563084364,
-0.012121068313717842,
0.009803567081689835,
-0.002493583597242832,
0.0020377011969685555,
0.01374751701951027,
0.0021615796722471714,
-0.013215468265116215,
0.005238148849457502,
0.008768435567617416,
-0.003722904482856393,
0.00467044860124588,
0.005065308418124914,
-0.0056897299364209175,
-0.02429467998445034,
-0.0035491969902068377,
-0.015375719405710697,
0.006350455805659294,
-0.0024409920442849398,
0.002651604125276208,
-0.008423150517046452,
0.007567091844975948,
0.005212477874010801,
-0.014182992279529572,
-0.004347055219113827,
-0.007439075503498316,
0.008721375837922096,
-0.0009221247746609151,
-0.0012414860539138317,
-0.003506122622638941,
-0.0019121788209304214,
-0.0016235848888754845,
-0.0029003662057220936,
-0.00004773277396452613,
0.002944743260741234,
0.00025649165036156774,
-0.002987089566886425,
0.000900458893738687,
-0.0038465566467493773,
0.0004484731762204319,
0.0026320163160562515,
-0.011018319055438042,
0.0036390800960361958,
0.005627928301692009,
-0.003543888684362173,
-0.004079548642039299,
-0.0004557847569230944,
-0.0024972837418317795,
-0.006225928198546171,
-0.01111789233982563,
-0.0036542366724461317,
-0.004701910074800253,
-0.002439600881189108,
-0.011961149983108044,
-0.00258769653737545,
-0.006601259112358093,
0.006345324218273163,
-0.0061178975738584995,
0.005803912412375212,
0.004229369573295116,
-0.005436043255031109,
0.007530523929744959,
-0.003130296478047967,
0.0034259497188031673,
0.003382130293175578,
0.0037866318598389626,
0.0014497233787551522,
-0.006700512487441301,
-0.013507490046322346,
0.013338418677449226,
-0.00981665775179863,
0.0006146273808553815,
0.013284262269735336,
0.005711538717150688,
0.01047598011791706,
0.0006779446266591549,
-0.00023689046793151647,
0.0016070930287241936,
0.007840440608561039,
-0.014219025149941444,
0.002928697969764471,
-0.0030199720058590174,
-0.0004691746144089848,
0.004126993473619223,
-0.003988670185208321,
0.004032442811876535,
0.007456971798092127,
0.0015916569391265512,
-0.007382347714155912,
-0.0033804201520979404,
0.0026764629874378443,
0.004745859187096357,
-0.012704039923846722,
-0.00039480492705479264,
-0.00436042295768857,
-0.0042428551241755486,
-0.004143619444221258,
-0.0034133128356188536,
-0.00040271878242492676,
0.004472577013075352,
-0.0025101222563534975,
0.006981241051107645,
0.003765261499211192,
-0.004803116898983717,
0.014403380453586578,
-0.006293624173849821,
-0.0033716035541146994,
0.0018401005072519183,
0.00047270720824599266,
-0.003059845184907317,
-0.004998513497412205,
-0.004190277773886919,
0.0037002437748014927,
0.004599130712449551,
-0.0031977773178368807,
-0.005020858719944954,
-0.002026104833930731,
0.0015127590158954263,
-0.008182360790669918,
-0.0011910353787243366,
0.011355951428413391,
-0.0011521622072905302,
0.004043275490403175,
-0.000984333106316626,
-0.007989791221916676,
-0.014092531055212021,
0.05332350358366966,
-0.0006256353226490319,
0.005088339559733868,
0.005664704367518425,
-0.006096435245126486,
-0.0012034240644425154,
-0.0019828227814286947,
0.007537566125392914,
-0.0067249177955091,
-0.00827055424451828,
0.008514229208230972,
-0.002290966920554638,
0.005391504615545273,
-0.00014782763901166618,
-0.0023318305611610413,
0.01666264981031418,
-0.0038564137648791075,
-0.016608163714408875,
-0.01675480417907238,
0.007461389061063528,
-0.004469310864806175,
-0.008894963189959526,
0.007412457838654518,
-0.005820607766509056,
-0.002884831978008151,
0.0001419683831045404,
0.0049583944492042065,
0.002095144707709551,
0.00036157944123260677,
-0.002722332952544093,
-0.0005545378662645817,
-0.0011571119539439678,
0.003979494795203209,
0.006475590635091066,
0.0075556617230176926,
-0.005782837979495525,
0.0028104535304009914,
-0.0021091648377478123,
-0.0007373156258836389,
-0.0019561308436095715,
0.003292629960924387,
0.008762496523559093,
-0.001758276717737317,
-0.002866244874894619,
0.0062836939468979836,
0.0031522708013653755,
0.0011064904974773526,
0.010618544183671474,
0.000234643739531748,
-0.004893523640930653,
0.00919250212609768,
0.007278050296008587,
-0.00021690655557904392,
0.009038224816322327,
-0.001205030595883727,
0.004441006574779749,
0.001750442897900939,
-0.005734255537390709,
-0.015428467653691769,
-0.0032808510586619377,
0.00624819565564394,
0.008297226391732693,
-0.001872366527095437,
0.002973338356241584,
-0.0019867480732500553,
-0.002865737769752741,
-0.006427171174436808,
-0.008535213768482208,
-0.001901088049635291,
0.002159807365387678,
0.003795927856117487,
0.07003176212310791,
-0.005945338401943445,
-0.0016838067676872015,
-0.008686703629791737,
-0.001910676248371601,
-0.0024941491428762674,
0.00015540345339104533,
0.0015353496419265866,
-0.0036940036807209253,
0.0026989830657839775,
0.001460823928937316,
-0.007941928692162037,
-0.009601866826415062,
0.0007806409848853946,
0.003340930910781026,
-0.003060186980292201,
0.0035557937808334827,
0.006870982237160206,
-0.008233994245529175,
0.003288117004558444,
-0.011432989500463009,
-0.002860281616449356,
-0.003191554918885231,
-0.008373184129595757,
-0.0024422635324299335,
-0.003557217540219426,
0.00440179044380784,
0.0016466592205688357,
0.004571602679789066,
-0.0012217701878398657,
0.005395368207246065,
0.00017932021000888199,
-0.0007912438595667481,
-0.0053435275331139565,
-0.0013801606837660074,
-0.004892635624855757,
0.0065171923488378525,
0.003826705738902092,
-0.009071641601622105,
-0.005653250962495804,
-0.000853284727782011,
0.002454134402796626,
-0.005613763350993395,
0.005210995674133301,
-0.0010755641851574183,
0.006035621277987957,
-0.000554705155082047,
-0.0009335677605122328,
-0.006400044541805983,
0.0010810547973960638,
-0.012902429327368736,
0.0035734791308641434,
-0.17570486664772034,
0.009543068706989288,
0.004985199775546789,
-0.004939360078424215,
-0.004082465544342995,
-0.01641315221786499,
-0.0036539521533995867,
0.004847545642405748,
0.010550937615334988,
0.0006035364931449294,
-0.0013243634020909667,
-0.002388067776337266,
0.005430077668279409,
0.003396277781575918,
-0.0013441547052934766,
-0.005098199471831322,
0.0022922963835299015,
-0.003880028147250414,
0.00011798214836744592,
0.003632017644122243,
0.004269100725650787,
0.008908912539482117,
0.002364902989938855,
0.001441383850760758,
-0.0015193303115665913,
-0.004635253921151161,
0.0076227253302931786,
-0.003314623609185219,
0.004296439699828625,
-0.012177691794931889,
-0.000876824778970331,
-0.003615965833887458,
-0.005073165986686945,
0.0017690050881356,
0.006604970432817936,
-0.0019504878437146544,
0.007330616936087608,
0.0035979992244392633,
-0.007216357160359621,
0.007827183231711388,
-0.006699872203171253,
0.028642158955335617,
0.003386876778677106,
0.007131517399102449,
-0.00031852981192059815,
-0.0052934023551642895,
-0.004302216228097677,
0.009792177937924862,
0.0021902108564972878,
0.01086634024977684,
-0.010603727772831917,
-0.0027099072467535734,
0.00497388606891036,
0.018249664455652237,
-0.0037765922024846077,
-0.010025104507803917,
-0.005888970568776131,
-0.0022043725475668907,
0.003896087873727083,
0.008154848590493202,
0.011068377643823624,
-0.004992435220628977,
0.00866050086915493,
-0.004368165973573923,
-0.018949801102280617,
0.0021859235130250454,
-0.004900753498077393,
-0.007975874468684196,
0.0015459614805877209,
0.00628528231754899,
0.011135533452033997,
0.0006890379590913653,
0.004661784507334232,
-0.0012453836388885975,
0.0055922530591487885,
-0.0006427019252441823,
0.0069826398976147175,
-0.0013862871564924717,
0.005977052729576826,
-0.008591338992118835,
0.007937915623188019,
-0.010927031747996807,
-0.003992509562522173,
0.0024617642629891634,
-0.005438690539449453,
0.012137399055063725,
0.002902065636590123,
-0.001383340684697032,
-0.001156096113845706,
-0.011145605705678463,
-0.0021877691615372896,
0.0033007627353072166,
-0.001202526967972517,
-0.009280280210077763,
0.002808153862133622,
0.00023728622181806713,
0.006540319416671991,
0.006510982755571604,
-0.010231825523078442,
0.004733584821224213,
0.0059641883708536625,
-0.005399278365075588,
0.001470640767365694,
-0.00567035935819149,
-0.00003069694867008366,
0.0032717925496399403,
-0.003114508930593729,
-0.005927351303398609,
0.0037962652277201414,
-0.0066558136604726315,
-0.0036574313417077065,
0.006825594697147608,
-0.00816503819078207,
-0.00804016925394535,
-0.0015228412812575698,
-0.01009333599358797,
0.001768216141499579
] |
8a4c6c7b420769dc35e8f30f400909774d7d25e6 | 22,154 | py | Python | gfirefly/dbentrust/dbutils.py | handsome3163/H2Dgame-Firefly | 2d213928977dc490909f456327e5cae80998e60d | [
"MIT"
] | 675 | 2015-01-01T05:18:30.000Z | 2022-03-18T08:27:06.000Z | gfirefly/dbentrust/dbutils.py | liuis/Firefly | fd2795b8c26de6ab63bbec23d11f18c3dfb39a50 | [
"MIT"
] | 3 | 2015-01-29T02:36:14.000Z | 2022-01-21T09:19:21.000Z | gfirefly/dbentrust/dbutils.py | liuis/Firefly | fd2795b8c26de6ab63bbec23d11f18c3dfb39a50 | [
"MIT"
] | 248 | 2015-01-04T08:24:31.000Z | 2022-02-18T07:14:02.000Z | #coding:utf8
'''
Created on 2013-8-21
@author: lan (www.9miao.com)
'''
import itertools
import datetime
def safeunicode(obj, encoding='utf-8'):
r"""
Converts any given object to unicode string.
>>> safeunicode('hello')
u'hello'
>>> safeunicode(2)
u'2'
>>> safeunicode('\xe1\x88\xb4')
u'\u1234'
"""
t = type(obj)
if t is unicode:
return obj
elif t is str:
return obj.decode(encoding)
elif t in [int, float, bool]:
return unicode(obj)
elif hasattr(obj, '__unicode__') or isinstance(obj, unicode):
return unicode(obj)
else:
return str(obj).decode(encoding)
def safestr(obj, encoding='utf-8'):
r"""
Converts any given object to utf-8 encoded string.
>>> safestr('hello')
'hello'
>>> safestr(u'\u1234')
'\xe1\x88\xb4'
>>> safestr(2)
'2'
"""
if isinstance(obj, unicode):
return obj.encode(encoding)
elif isinstance(obj, str):
return obj
elif hasattr(obj, 'next'): # iterator
return itertools.imap(safestr, obj)
else:
return str(obj)
def sqlify(obj):
"""
converts `obj` to its proper SQL version
>>> sqlify(None)
'NULL'
>>> sqlify(True)
"'t'"
>>> sqlify(3)
'3'
"""
# because `1 == True and hash(1) == hash(True)`
# we have to do this the hard way...
if obj is None:
return 'NULL'
elif obj is True:
return "'t'"
elif obj is False:
return "'f'"
elif datetime and isinstance(obj, datetime.datetime):
return repr(obj.isoformat())
else:
if isinstance(obj, unicode): obj = obj.encode('utf8')
return repr(obj)
def sqllist(lst):
"""
Converts the arguments for use in something like a WHERE clause.
>>> sqllist(['a', 'b'])
'a, b'
>>> sqllist('a')
'a'
>>> sqllist(u'abc')
u'abc'
"""
if isinstance(lst, basestring):
return lst
else:
return ', '.join(lst)
def _sqllist(values):
"""
>>> _sqllist([1, 2, 3])
<sql: '(1, 2, 3)'>
"""
items = []
items.append('(')
for i, v in enumerate(values):
if i != 0:
items.append(', ')
items.append(sqlparam(v))
items.append(')')
return SQLQuery(items)
def sqlquote(a):
"""
Ensures `a` is quoted properly for use in a SQL query.
>>> 'WHERE x = ' + sqlquote(True) + ' AND y = ' + sqlquote(3)
<sql: "WHERE x = 't' AND y = 3">
>>> 'WHERE x = ' + sqlquote(True) + ' AND y IN ' + sqlquote([2, 3])
<sql: "WHERE x = 't' AND y IN (2, 3)">
"""
if isinstance(a, list):
return _sqllist(a)
else:
return sqlparam(a).sqlquery()
def _interpolate(sformat):
"""
Takes a format string and returns a list of 2-tuples of the form
(boolean, string) where boolean says whether string should be evaled
or not.
from <http://lfw.org/python/Itpl.py> (public domain, Ka-Ping Yee)
"""
from tokenize import tokenprog
tokenprog = tokenprog
def matchorfail(text, pos):
match = tokenprog.match(text, pos)
if match is None:
raise _ItplError(text, pos)
return match, match.end()
namechars = "abcdefghijklmnopqrstuvwxyz" \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
chunks = []
pos = 0
while 1:
dollar = sformat.find("$", pos)
if dollar < 0:
break
nextchar = sformat[dollar + 1]
if nextchar == "{":
chunks.append((0, sformat[pos:dollar]))
pos, level = dollar + 2, 1
while level:
match, pos = matchorfail(sformat, pos)
tstart, tend = match.regs[3]
token = sformat[tstart:tend]
if token == "{":
level = level + 1
elif token == "}":
level = level - 1
chunks.append((1, sformat[dollar + 2:pos - 1]))
elif nextchar in namechars:
chunks.append((0, sformat[pos:dollar]))
match, pos = matchorfail(sformat, dollar + 1)
while pos < len(sformat):
if sformat[pos] == "." and \
pos + 1 < len(sformat) and sformat[pos + 1] in namechars:
match, pos = matchorfail(sformat, pos + 1)
elif sformat[pos] in "([":
pos, level = pos + 1, 1
while level:
match, pos = matchorfail(sformat, pos)
tstart, tend = match.regs[3]
token = sformat[tstart:tend]
if token[0] in "([":
level = level + 1
elif token[0] in ")]":
level = level - 1
else:
break
chunks.append((1, sformat[dollar + 1:pos]))
else:
chunks.append((0, sformat[pos:dollar + 1]))
pos = dollar + 1 + (nextchar == "$")
if pos < len(sformat):
chunks.append((0, sformat[pos:]))
return chunks
def sqlwhere(dictionary, grouping=' AND '):
"""
Converts a `dictionary` to an SQL WHERE clause `SQLQuery`.
>>> sqlwhere({'cust_id': 2, 'order_id':3})
<sql: 'order_id = 3 AND cust_id = 2'>
>>> sqlwhere({'cust_id': 2, 'order_id':3}, grouping=', ')
<sql: 'order_id = 3, cust_id = 2'>
>>> sqlwhere({'a': 'a', 'b': 'b'}).query()
'a = %s AND b = %s'
"""
return SQLQuery.join([k + ' = ' + sqlparam(v) for k, v in dictionary.items()], grouping)
def reparam(string_, dictionary):
"""
Takes a string and a dictionary and interpolates the string
using values from the dictionary. Returns an `SQLQuery` for the result.
>>> reparam("s = $s", dict(s=True))
<sql: "s = 't'">
>>> reparam("s IN $s", dict(s=[1, 2]))
<sql: 's IN (1, 2)'>
"""
dictionary = dictionary.copy() # eval mucks with it
result = []
for live, chunk in _interpolate(string_):
if live:
v = eval(chunk, dictionary)
result.append(sqlquote(v))
else:
result.append(chunk)
return SQLQuery.join(result, '')
class UnknownParamstyle(Exception):
"""
raised for unsupported db paramstyles
(currently supported: qmark, numeric, format, pyformat)
"""
pass
class _ItplError(ValueError):
def __init__(self, text, pos):
ValueError.__init__(self)
self.text = text
self.pos = pos
def __str__(self):
return "unfinished expression in %s at char %d" % (
repr(self.text), self.pos)
class SQLParam(object):
"""
Parameter in SQLQuery.
>>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam("joe")])
>>> q
<sql: "SELECT * FROM test WHERE name='joe'">
>>> q.query()
'SELECT * FROM test WHERE name=%s'
>>> q.values()
['joe']
"""
__slots__ = ["value"]
def __init__(self, value):
self.value = value
def get_marker(self, paramstyle='pyformat'):
if paramstyle == 'qmark':
return '?'
elif paramstyle == 'numeric':
return ':1'
elif paramstyle is None or paramstyle in ['format', 'pyformat']:
return '%s'
raise UnknownParamstyle, paramstyle
def sqlquery(self):
return SQLQuery([self])
def __add__(self, other):
return self.sqlquery() + other
def __radd__(self, other):
return other + self.sqlquery()
def __str__(self):
return str(self.value)
def __repr__(self):
return '<param: %s>' % repr(self.value)
sqlparam = SQLParam
class SQLQuery(object):
"""
You can pass this sort of thing as a clause in any db function.
Otherwise, you can pass a dictionary to the keyword argument `vars`
and the function will call reparam for you.
Internally, consists of `items`, which is a list of strings and
SQLParams, which get concatenated to produce the actual query.
"""
__slots__ = ["items"]
# tested in sqlquote's docstring
def __init__(self, items=None):
r"""Creates a new SQLQuery.
>>> SQLQuery("x")
<sql: 'x'>
>>> q = SQLQuery(['SELECT * FROM ', 'test', ' WHERE x=', SQLParam(1)])
>>> q
<sql: 'SELECT * FROM test WHERE x=1'>
>>> q.query(), q.values()
('SELECT * FROM test WHERE x=%s', [1])
>>> SQLQuery(SQLParam(1))
<sql: '1'>
"""
if items is None:
self.items = []
elif isinstance(items, list):
self.items = items
elif isinstance(items, SQLParam):
self.items = [items]
elif isinstance(items, SQLQuery):
self.items = list(items.items)
else:
self.items = [items]
# Take care of SQLLiterals
for i, item in enumerate(self.items):
if isinstance(item, SQLParam) and isinstance(item.value, SQLLiteral):
self.items[i] = item.value.v
def append(self, value):
self.items.append(value)
def __add__(self, other):
if isinstance(other, basestring):
items = [other]
elif isinstance(other, SQLQuery):
items = other.items
else:
return NotImplemented
return SQLQuery(self.items + items)
def __radd__(self, other):
if isinstance(other, basestring):
items = [other]
else:
return NotImplemented
return SQLQuery(items + self.items)
def __iadd__(self, other):
if isinstance(other, (basestring, SQLParam)):
self.items.append(other)
elif isinstance(other, SQLQuery):
self.items.extend(other.items)
else:
return NotImplemented
return self
def __len__(self):
return len(self.query())
def query(self, paramstyle=None):
"""
Returns the query part of the sql query.
>>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
>>> q.query()
'SELECT * FROM test WHERE name=%s'
>>> q.query(paramstyle='qmark')
'SELECT * FROM test WHERE name=?'
"""
s = []
for x in self.items:
if isinstance(x, SQLParam):
x = x.get_marker(paramstyle)
s.append(safestr(x))
else:
x = safestr(x)
# automatically escape % characters in the query
# For backward compatability, ignore escaping when the query looks already escaped
if paramstyle in ['format', 'pyformat']:
if '%' in x and '%%' not in x:
x = x.replace('%', '%%')
s.append(x)
return "".join(s)
def values(self):
"""
Returns the values of the parameters used in the sql query.
>>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
>>> q.values()
['joe']
"""
return [i.value for i in self.items if isinstance(i, SQLParam)]
def join(items, sep=' ', prefix=None, suffix=None, target=None):
"""
Joins multiple queries.
>>> SQLQuery.join(['a', 'b'], ', ')
<sql: 'a, b'>
Optinally, prefix and suffix arguments can be provided.
>>> SQLQuery.join(['a', 'b'], ', ', prefix='(', suffix=')')
<sql: '(a, b)'>
If target argument is provided, the items are appended to target instead of creating a new SQLQuery.
"""
if target is None:
target = SQLQuery()
target_items = target.items
if prefix:
target_items.append(prefix)
for i, item in enumerate(items):
if i != 0:
target_items.append(sep)
if isinstance(item, SQLQuery):
target_items.extend(item.items)
else:
target_items.append(item)
if suffix:
target_items.append(suffix)
return target
join = staticmethod(join)
def _str(self):
try:
return self.query() % tuple([sqlify(x) for x in self.values()])
except (ValueError, TypeError):
return self.query()
def __str__(self):
return safestr(self._str())
def __unicode__(self):
return safeunicode(self._str())
def __repr__(self):
return '<sql: %s>' % repr(str(self))
class SQLLiteral:
"""
Protects a string from `sqlquote`.
>>> sqlquote('NOW()')
<sql: "'NOW()'">
>>> sqlquote(SQLLiteral('NOW()'))
<sql: 'NOW()'>
"""
def __init__(self, v):
self.v = v
def __repr__(self):
return self.v
class SQLProducer:
"""Database"""
def __init__(self):
"""Creates a database.
"""
pass
def query(self, sql_query,processed=False, svars=None):
"""
Execute SQL query `sql_query` using dictionary `vars` to interpolate it.
If `processed=True`, `vars` is a `reparam`-style list to use
instead of interpolating.
>>> db = DB(None, {})
>>> db.query("SELECT * FROM foo", _test=True)
<sql: 'SELECT * FROM foo'>
>>> db.query("SELECT * FROM foo WHERE x = $x", vars=dict(x='f'), _test=True)
<sql: "SELECT * FROM foo WHERE x = 'f'">
>>> db.query("SELECT * FROM foo WHERE x = " + sqlquote('f'), _test=True)
<sql: "SELECT * FROM foo WHERE x = 'f'">
"""
if svars is None:
svars = {}
if not processed and not isinstance(sql_query, SQLQuery):
sql_query = reparam(sql_query, svars)
return sql_query
def sql_clauses(self, what, tables, where, group, order, limit, offset):
return (
('SELECT', what),
('FROM', sqllist(tables)),
('WHERE', where),
('GROUP BY', group),
('ORDER BY', order),
('LIMIT', limit),
('OFFSET', offset))
def gen_clause(self, sql, val, svars):
if isinstance(val, (int, long)):
if sql == 'WHERE':
nout = 'id = ' + sqlquote(val)
else:
nout = SQLQuery(val)
elif isinstance(val, (list, tuple)) and len(val) == 2:
nout = SQLQuery(val[0], val[1]) # backwards-compatibility
elif isinstance(val, SQLQuery):
nout = val
else:
nout = reparam(val, svars)
def xjoin(a, b):
if a and b: return a + ' ' + b
else: return a or b
return xjoin(sql, nout)
def _where(self, where, svars):
if isinstance(where, (int, long)):
where = "id = " + sqlparam(where)
elif isinstance(where, (list, tuple)) and len(where) == 2:
where = SQLQuery(where[0], where[1])
elif isinstance(where, SQLQuery):
pass
else:
where = reparam(where, svars)
return where
def select(self, tables, svars=None, what='*', where=None, order=None, group=None,
limit=None, offset=None, _test=False):
"""
Selects `what` from `tables` with clauses `where`, `order`,
`group`, `limit`, and `offset`. Uses vars to interpolate.
Otherwise, each clause can be a SQLQuery.
>>> db = DB(None, {})
>>> db.select('foo', _test=True)
<sql: 'SELECT * FROM foo'>
>>> db.select(['foo', 'bar'], where="foo.bar_id = bar.id", limit=5, _test=True)
<sql: 'SELECT * FROM foo, bar WHERE foo.bar_id = bar.id LIMIT 5'>
"""
if svars is None: svars = {}
sql_clauses = self.sql_clauses(what, tables, where, group, order, limit, offset)
clauses = [self.gen_clause(sql, val, svars) for sql, val in sql_clauses if val is not None]
qout = SQLQuery.join(clauses)
if _test: return qout
return self.query(qout, processed=True)
def insert(self, tablename, seqname=None, _test=False, **values):
"""
Inserts `values` into `tablename`. Returns current sequence ID.
Set `seqname` to the ID if it's not the default, or to `False`
if there isn't one.
>>> db = DB(None, {})
>>> q = db.insert('foo', name='bob', age=2, created=SQLLiteral('NOW()'), _test=True)
>>> q
<sql: "INSERT INTO foo (age, name, created) VALUES (2, 'bob', NOW())">
>>> q.query()
'INSERT INTO foo (age, name, created) VALUES (%s, %s, NOW())'
>>> q.values()
[2, 'bob']
"""
def q(x): return "(" + x + ")"
if values:
_keys = SQLQuery.join(values.keys(), ', ')
_values = SQLQuery.join([sqlparam(v) for v in values.values()], ', ')
sql_query = "INSERT INTO %s " % tablename + q(_keys) + ' VALUES ' + q(_values)
else:
sql_query = SQLQuery(self._get_insert_default_values_query(tablename))
return sql_query
def _get_insert_default_values_query(self, table):
return "INSERT INTO %s DEFAULT VALUES" % table
def multiple_insert(self, tablename, values, seqname=None, _test=False):
"""
Inserts multiple rows into `tablename`. The `values` must be a list of dictioanries,
one for each row to be inserted, each with the same set of keys.
Returns the list of ids of the inserted rows.
Set `seqname` to the ID if it's not the default, or to `False`
if there isn't one.
>>> db = DB(None, {})
>>> db.supports_multiple_insert = True
>>> values = [{"name": "foo", "email": "foo@example.com"}, {"name": "bar", "email": "bar@example.com"}]
>>> db.multiple_insert('person', values=values, _test=True)
<sql: "INSERT INTO person (name, email) VALUES ('foo', 'foo@example.com'), ('bar', 'bar@example.com')">
"""
if not values:
return []
if not self.supports_multiple_insert:
out = [self.insert(tablename, seqname=seqname, _test=_test, **v) for v in values]
if seqname is False:
return None
else:
return out
keys = values[0].keys()
#@@ make sure all keys are valid
# make sure all rows have same keys.
for v in values:
if v.keys() != keys:
raise ValueError, 'Bad data'
sql_query = SQLQuery('INSERT INTO %s (%s) VALUES ' % (tablename, ', '.join(keys)))
for i, row in enumerate(values):
if i != 0:
sql_query.append(", ")
SQLQuery.join([SQLParam(row[k]) for k in keys], sep=", ", target=sql_query, prefix="(", suffix=")")
if _test: return sql_query
db_cursor = self._db_cursor()
if seqname is not False:
sql_query = self._process_insert_query(sql_query, tablename, seqname)
if isinstance(sql_query, tuple):
# for some databases, a separate query has to be made to find
# the id of the inserted row.
q1, q2 = sql_query
self._db_execute(db_cursor, q1)
self._db_execute(db_cursor, q2)
else:
self._db_execute(db_cursor, sql_query)
try:
out = db_cursor.fetchone()[0]
out = range(out-len(values)+1, out+1)
except Exception:
out = None
if not self.ctx.transactions:
self.ctx.commit()
return out
def update(self, tables, where, svars=None, _test=False, **values):
"""
Update `tables` with clause `where` (interpolated using `vars`)
and setting `values`.
>>> db = DB(None, {})
>>> name = 'Joseph'
>>> q = db.update('foo', where='name = $name', name='bob', age=2,
... created=SQLLiteral('NOW()'), vars=locals(), _test=True)
>>> q
<sql: "UPDATE foo SET age = 2, name = 'bob', created = NOW() WHERE name = 'Joseph'">
>>> q.query()
'UPDATE foo SET age = %s, name = %s, created = NOW() WHERE name = %s'
>>> q.values()
[2, 'bob', 'Joseph']
"""
if svars is None: svars = {}
where = self._where(where, svars)
query = (
"UPDATE " + sqllist(tables) +
" SET " + sqlwhere(values, ', ') +
" WHERE " + where)
if _test: return query
db_cursor = self._db_cursor()
self._db_execute(db_cursor, query)
if not self.ctx.transactions:
self.ctx.commit()
return db_cursor.rowcount
def delete(self, table, where, using=None, svars=None, _test=False):
"""
Deletes from `table` with clauses `where` and `using`.
>>> db = DB(None, {})
>>> name = 'Joe'
>>> db.delete('foo', where='name = $name', vars=locals(), _test=True)
<sql: "DELETE FROM foo WHERE name = 'Joe'">
"""
if svars is None:
svars = {}
where = self._where(where, svars)
q = 'DELETE FROM ' + table
if using:
q += ' USING ' + sqllist(using)
if where:
q += ' WHERE ' + where
return q
sqlproducer = SQLProducer()
| 31.693848 | 115 | 0.510743 | 1 | 2.2341 | [
0.03941420465707779,
0.04466051608324051,
-0.009903770871460438,
0.0032014630269259214,
-0.030808569863438606,
0.019914081320166588,
-0.029919365420937538,
-0.020373720675706863,
-0.031350940465927124,
0.008216562680900097,
0.017062347382307053,
-0.0023241406306624413,
0.03459693491458893,
0.045132432132959366,
-0.019255787134170532,
-0.06040012836456299,
-0.03373388200998306,
0.002844208851456642,
-0.029488464817404747,
-0.014977125450968742,
-0.004934986587613821,
0.010348673909902573,
-0.0011621750891208649,
0.021102003753185272,
0.024104908108711243,
0.06496448069810867,
-0.005709468852728605,
0.004771674983203411,
-0.03144855797290802,
0.018439805135130882,
0.025662587955594063,
0.06206231564283371,
-0.021296249702572823,
-0.013502204790711403,
-0.03590922802686691,
-0.0019415300339460373,
-0.04037635773420334,
-0.046216126531362534,
0.03557903692126274,
-0.021783484145998955,
-0.04633403196930885,
-0.001452755881473422,
-0.011580088175833225,
0.012025951407849789,
-0.016673970967531204,
-0.027540873736143112,
0.016162659972906113,
0.028439408168196678,
-0.03600907325744629,
-0.01635744981467724,
0.03677162528038025,
-0.01515912264585495,
-0.06071159616112709,
-0.026522360742092133,
0.009329456835985184,
-0.033693231642246246,
0.0071367910131812096,
-0.01786292903125286,
-0.04480768367648125,
0.012420053593814373,
0.040578555315732956,
-0.03121650032699108,
-0.016615984961390495,
-0.0266885906457901,
-0.004319978877902031,
0.01087854988873005,
0.002774956403300166,
-0.04241035878658295,
-0.009314967319369316,
-0.03779301047325134,
0.03502914309501648,
0.0011243111221119761,
-0.006106389220803976,
0.058135025203228,
-0.027529997751116753,
-0.020888714119791985,
-0.03849802538752556,
-0.004431789740920067,
-0.011560890823602676,
0.017780328169465065,
-0.03126982972025871,
0.08527503907680511,
-0.01804959960281849,
0.013071245513856411,
-0.006660244893282652,
0.0017667009960860014,
0.028974339365959167,
-0.07848875969648361,
0.03487452492117882,
0.019583923742175102,
-0.030566392466425896,
-0.0031161499209702015,
-0.02172783389687538,
-0.02060815691947937,
-0.006965788081288338,
-0.05811058729887009,
0.04507865011692047,
0.012216427363455296,
0.04493850842118263,
0.047775737941265106,
0.04213906452059746,
0.03333166614174843,
0.07152660936117172,
-0.012068825773894787,
-0.04115777462720871,
0.01183377020061016,
-0.0073045226745307446,
-0.01887112855911255,
-0.016928035765886307,
-0.035477206110954285,
0.05017499998211861,
0.035442084074020386,
0.010546853765845299,
-0.04275962710380554,
0.02383565716445446,
-0.004640610422939062,
0.017563190311193466,
0.0006503416807390749,
0.01725658029317856,
-0.027957355603575706,
-0.007781592197716236,
0.008051515556871891,
-0.00871216505765915,
0.044686365872621536,
0.003600144060328603,
0.016546471044421196,
0.0004383884952403605,
-0.014107710681855679,
0.02545974962413311,
-0.0016368129290640354,
-0.026757653802633286,
-0.027361813932657242,
-0.034667450934648514,
-0.036984410136938095,
0.04245300218462944,
0.017145689576864243,
-0.03696189820766449,
0.038453634828329086,
0.017315097153186798,
0.005112041253596544,
-0.03579194098711014,
-0.0360068753361702,
0.01954282820224762,
-0.005579112563282251,
0.04345211386680603,
-0.05636172741651535,
-0.0431123748421669,
-0.014581714756786823,
-0.023074321448802948,
0.0230526402592659,
0.007488347124308348,
0.04000018909573555,
-0.020824678242206573,
0.019917624071240425,
-0.05783369392156601,
-0.036902301013469696,
0.012320727109909058,
-0.0044977013021707535,
-0.01793486997485161,
-0.0021983557380735874,
-0.033864352852106094,
0.005768848117440939,
-0.031197158619761467,
0.005120811518281698,
0.004066221881657839,
0.02674177661538124,
0.019444933161139488,
0.025064023211598396,
-0.03911999985575676,
-0.03127523511648178,
0.022562652826309204,
0.005505457986146212,
0.0048734331503510475,
0.011453641578555107,
0.03996036946773529,
0.018551768735051155,
-0.0000026508512291911757,
-0.029514558613300323,
0.012069114483892918,
-0.024600595235824585,
-0.0018549924716353416,
-0.05349580943584442,
0.05364393815398216,
-0.034362126141786575,
-0.014486731961369514,
0.007051148917526007,
-0.01583900675177574,
0.004660143982619047,
0.020675456151366234,
0.00317324697971344,
-0.01550285518169403,
0.04416893050074577,
-0.0059076519683003426,
0.02301555871963501,
0.021015377715229988,
-0.014370808377861977,
-0.012266067788004875,
-0.04294271394610405,
0.03588869422674179,
0.022025303915143013,
0.06259335577487946,
-0.07783687859773636,
0.02252422831952572,
0.06616745889186859,
-0.047042958438396454,
0.012255885638296604,
-0.6308737993240356,
-0.010973338969051838,
0.02534129098057747,
-0.014535140246152878,
0.021154897287487984,
0.000047941546654328704,
-0.03622893989086151,
0.029171418398618698,
-0.02863234095275402,
0.008414911106228828,
-0.0026400904171168804,
-0.031644392758607864,
-0.060876309871673584,
-0.02389395795762539,
-0.01413745153695345,
-0.009746469557285309,
-0.020403141155838966,
-0.005747599992901087,
0.013514476828277111,
0.04473671317100525,
-0.011299708858132362,
0.04663505032658577,
0.020857632160186768,
0.0392613559961319,
0.011373032815754414,
-0.00851881317794323,
0.032241519540548325,
0.034656114876270294,
-0.012507583014667034,
-0.0011921654222533107,
-0.025058289989829063,
-0.0002760959614533931,
0.021589234471321106,
0.003420294029638171,
0.03399225324392319,
-0.010586514137685299,
-0.011890229769051075,
-0.010590934194624424,
-0.045970991253852844,
-0.007746797055006027,
-0.01713677868247032,
-0.00956961140036583,
-0.020371297374367714,
-0.027945805341005325,
-0.004269411321729422,
-0.0016489605186507106,
0.028090903535485268,
-0.026247041299939156,
0.03825625404715538,
0.04333220794796944,
-0.029879096895456314,
0.0605270117521286,
0.008897505700588226,
-0.032670632004737854,
0.0010551499435678124,
0.0039436393417418,
-0.061228763312101364,
0.0010922005167230964,
-0.03745328262448311,
0.006439486984163523,
0.0414358414709568,
-0.006864565424621105,
0.01445358619093895,
0.04700811579823494,
-0.025173578411340714,
-0.023788364604115486,
0.021172521635890007,
-0.044851530343294144,
-0.025042103603482246,
0.0166655033826828,
-0.01918332278728485,
0.007726263254880905,
-0.041337791830301285,
0.04022569581866264,
0.007418653462082148,
0.006572004407644272,
0.023899422958493233,
-0.0040503619238734245,
-0.007702356204390526,
0.04299439117312431,
0.03438825532793999,
0.00894968956708908,
-0.02761690691113472,
-0.014944770373404026,
-0.02253870666027069,
-0.002683099824935198,
0.04515959694981575,
-0.01118364930152893,
-0.005062669049948454,
0.03430839255452156,
-0.020978959277272224,
0.0070040966384112835,
-0.0378124937415123,
0.002085091546177864,
-0.010892186313867569,
-0.012448183260858059,
-0.008986084721982479,
0.04662696644663811,
0.024355947971343994,
0.023484596982598305,
-0.02970757521688938,
0.003798766527324915,
0.010165257379412651,
-0.0018130999524146318,
-0.06470648944377899,
0.008679166436195374,
-0.04883796349167824,
-0.007984841242432594,
0.04448403790593147,
-0.03533828258514404,
-0.02539072372019291,
0.03750893101096153,
-0.013989202678203583,
0.014413767494261265,
0.07768362760543823,
0.007230996619910002,
-0.006339454557746649,
0.004789064172655344,
-0.014738587662577629,
0.034535281360149384,
-0.015687640756368637,
0.053053513169288635,
-0.036513801664114,
0.04139013960957527,
0.0026028614956885576,
-0.024702979251742363,
0.0349443219602108,
0.009616128169000149,
-0.008777320384979248,
-0.014410466887056828,
-0.03453003615140915,
-0.043230462819337845,
-0.032519858330488205,
-0.022832605987787247,
0.009584416635334492,
-0.07061650604009628,
-0.013602960854768753,
-0.001214840216562152,
-0.02955382876098156,
-0.022876957431435585,
0.008317580446600914,
-0.008551154285669327,
-0.04976701736450195,
-0.06411860883235931,
0.013819849118590355,
0.018558144569396973,
-0.005912872031331062,
0.003536555217579007,
-0.016987361013889313,
-0.018923765048384666,
0.01933625526726246,
0.06377975642681122,
-0.007569441106170416,
0.001119617954827845,
-0.03717214986681938,
0.03726525232195854,
-0.04359766095876694,
-0.0009565814398229122,
0.01189453899860382,
0.05794550105929375,
0.003838516306132078,
-0.03779379278421402,
0.008816279470920563,
0.004686362575739622,
-0.02486310340464115,
0.006217051297426224,
-0.020319383591413498,
-0.0033587736543267965,
-0.048162445425987244,
0.058023057878017426,
0.04359223693609238,
0.018153559416532516,
-0.024768684059381485,
0.018116621300578117,
-0.024435164406895638,
0.008897021412849426,
-0.006283754017204046,
-0.01716870255768299,
-0.007548617664724588,
-0.012865609489381313,
-0.005648057907819748,
-0.005175299942493439,
-0.013757901266217232,
-0.019705697894096375,
-0.009616204537451267,
0.020117459818720818,
-0.023644933477044106,
0.003476175479590893,
0.02241135574877262,
-0.00025179923977702856,
0.018917931243777275,
0.022056546062231064,
-0.003972025588154793,
0.028953801840543747,
-0.03296809270977974,
0.00021777022629976273,
0.01945933885872364,
0.025545533746480942,
0.014843831770122051,
-0.01228373870253563,
0.010969579219818115,
-0.018689511343836784,
-0.0355069562792778,
0.03930043429136276,
0.008525409735739231,
0.06746386736631393,
-0.0021553863771259785,
-0.023622356355190277,
-0.04972316697239876,
-0.003851749701425433,
-0.051689013838768005,
-0.001103121554479003,
0.014492443762719631,
0.018738580867648125,
0.028777869418263435,
0.023583028465509415,
-0.041711024940013885,
0.024632178246974945,
-0.007131222169846296,
-0.02571280486881733,
-0.009915151633322239,
-0.00701230438426137,
0.01938449777662754,
-0.01757427304983139,
0.013833306729793549,
-0.02729257382452488,
-0.01353774219751358,
-0.0172987449914217,
-0.0357290580868721,
-0.017940912395715714,
0.014275351539254189,
0.011705279350280762,
0.010108563117682934,
-0.00723943579941988,
0.025993751361966133,
-0.00704544922336936,
-0.03618417680263519,
-0.007358157075941563,
-0.003513002535328269,
-0.005675964057445526,
0.0008484060526825488,
0.0023769668769091368,
-0.01959642581641674,
-0.007352200802415609,
-0.044599927961826324,
0.00007019571057753637,
0.015734722837805748,
-0.02795843780040741,
-0.017931781709194183,
-0.011934177950024605,
-0.015117376111447811,
-0.03481099009513855,
0.06341509521007538,
-0.03715338185429573,
0.01964736171066761,
0.04467986896634102,
-0.010530107654631138,
0.0444754920899868,
-0.010535496287047863,
0.007601920980960131,
0.006625477224588394,
-0.030540302395820618,
0.001857732655480504,
-0.0037039988674223423,
0.01273404248058796,
0.01989670842885971,
0.03328321874141693,
-0.005612056702375412,
-0.015553006902337074,
0.03556634485721588,
-0.014712430536746979,
-0.020741473883390427,
-0.012914382852613926,
-0.006643975153565407,
0.010871478356420994,
0.05369462072849274,
-0.02781251259148121,
-0.00277911894954741,
0.009029265493154526,
0.03769697621464729,
-0.009499981999397278,
-0.0007614275673404336,
-0.04706567898392677,
0.004805772099643946,
0.012949131429195404,
0.04050440713763237,
-0.01571866311132908,
-0.03165261074900627,
-0.04514848440885544,
-0.013075180351734161,
-0.0014808280393481255,
0.020074859261512756,
0.04017697647213936,
0.019672639667987823,
-0.01551126316189766,
-0.042560264468193054,
-0.011626663617789745,
-0.02301500365138054,
-0.010417808778584003,
-0.04959113523364067,
-0.013427100144326687,
-0.006912069395184517,
-0.013642339035868645,
-0.0007415877771563828,
-0.024262825027108192,
-0.0211497750133276,
0.0006225061952136457,
0.00007810635725036263,
0.015205913223326206,
0.016789674758911133,
0.019158096984028816,
0.015844251960515976,
-0.031185753643512726,
0.043166227638721466,
0.009904622100293636,
-0.025924663990736008,
0.018331829458475113,
0.013833248987793922,
0.021030355244874954,
0.02245316654443741,
0.005461431574076414,
0.06660157442092896,
0.009381301701068878,
-0.022564386948943138,
0.04665781185030937,
-0.041782524436712265,
-0.010312369093298912,
0.01390217524021864,
-0.013127703219652176,
0.04408416524529457,
0.00503052631393075,
0.02695264108479023,
0.011212560348212719,
0.002608600305393338,
-0.008822217583656311,
0.025790413841605186,
0.053549185395240784,
0.006904584355652332,
0.05391823500394821,
-0.018602726981043816,
0.033145103603601456,
0.014672970399260521,
-0.054793551564216614,
0.02558940462768078,
-0.009945018216967583,
-0.019850796088576317,
-0.022623028606176376,
0.020546091720461845,
0.025319702923297882,
0.0034157324116677046,
-0.015325173735618591,
-0.048769742250442505,
-0.03161159157752991,
0.059720080345869064,
-0.02677001617848873,
-0.045622944831848145,
-0.011829535476863384,
0.019515642896294594,
-0.000244103284785524,
0.00005717435487895273,
0.015665177255868912,
0.0025241952389478683,
-0.022326843813061714,
-0.001695079728960991,
-0.05378761142492294,
0.007594895549118519,
0.006679484620690346,
-0.021522104740142822,
-0.012730395421385765,
0.05688144639134407,
-0.04210234060883522,
-0.007872889749705791,
0.017284540459513664,
0.010307476855814457,
-0.003997787367552519,
0.034263357520103455,
0.027128001675009727,
0.02153049409389496,
-0.011252028867602348,
0.0011828842107206583,
-0.010536542162299156,
0.048320867121219635,
0.006361718755215406,
0.027089867740869522,
0.0010371378157287836,
-0.039307888597249985,
0.009122387506067753,
-0.015911497175693512,
-0.019575150683522224,
-0.05472856014966965,
-0.003956504166126251,
0.022376924753189087,
-0.015178008005023003,
0.012760838493704796,
0.0008900300017558038,
-0.022113554179668427,
-0.029552128165960312,
-0.019900724291801453,
-0.006479891482740641,
-0.02380393072962761,
-0.02257692813873291,
-0.01005786657333374,
0.046328239142894745,
-0.029551692306995392,
-0.011794449761509895,
0.002022120403125882,
0.015208814293146133,
-0.014597173780202866,
0.03208789601922035,
-0.010561928153038025,
-0.005460231564939022,
0.03671509772539139,
0.03598897531628609,
-0.05108755826950073,
0.0545039139688015,
0.017765305936336517,
-0.014695463702082634,
0.015652306377887726,
0.008685662411153316,
0.03615376353263855,
0.001612344873137772,
0.030130811035633087,
-0.0003862697631120682,
0.02215106599032879,
-0.03703789412975311,
0.012915261089801788,
0.028342757374048233,
0.020591698586940765,
-0.06636615097522736,
0.0003683537943288684,
-0.016640976071357727,
0.02052224613726139,
-0.039561010897159576,
0.0006888640346005559,
-0.005514407530426979,
-0.00848805345594883,
0.0170692577958107,
0.01589689962565899,
-0.008628178387880325,
0.056170038878917694,
0.0525800921022892,
-0.012381959706544876,
-0.008907717652618885,
0.07205770909786224,
-0.031257882714271545,
-0.07773580402135849,
0.0113533865660429,
-0.0201350599527359,
0.016269773244857788,
-0.03026314079761505,
-0.06288687139749527,
0.0041526551358401775,
0.003589809639379382,
-0.013420459814369678,
-0.014597147703170776,
0.04520581290125847,
-0.02590848132967949,
-0.021997343748807907,
0.050748877227306366,
-0.02066180855035782,
0.005396008025854826,
0.038295067846775055,
0.010637531988322735,
-0.016050826758146286,
-0.0021911170333623886,
0.02356943115592003,
-0.02447550930082798,
0.025324255228042603,
-0.014900271780788898,
-0.004874200094491243,
-0.005493375472724438,
0.02745283953845501,
-0.016695184633135796,
0.016561206430196762,
0.02862079255282879,
0.03921962156891823,
-0.03479384258389473,
-0.0014777472242712975,
0.060392387211322784,
0.021335501223802567,
0.0028752959333360195,
-0.04135551676154137,
0.030612921342253685,
-0.013007019646465778,
0.01557517983019352,
0.006689607165753841,
-0.022424159571528435,
-0.026799475774168968,
-0.028384672477841377,
0.00948102492839098,
-0.0058518811129033566,
-0.027083642780780792,
0.00039879552787169814,
0.03916380926966667,
0.03184700384736061,
-0.05133432149887085,
0.003161228261888027,
-0.030675435438752174,
0.0036904355511069298,
-0.03991391509771347,
-0.009954674169421196,
0.03579657897353172,
0.024756602942943573,
-0.0022360545117408037,
0.03580348193645477,
0.040176983922719955,
0.029479190707206726,
-0.0010746798943728209,
-0.04370976611971855,
0.019465109333395958,
0.0015765577554702759,
-0.005842973943799734,
-0.01279662735760212,
-0.05412707105278969,
-0.014355486258864403,
0.05747804418206215,
0.035300951451063156,
-0.038041844964027405,
0.05844336375594139,
0.007004395592957735,
0.0058760992251336575,
0.027061142027378082,
0.02046104520559311,
0.017031801864504814,
0.0402999110519886,
-0.019259311258792877,
-0.0264916829764843,
0.0005447618896141648,
0.012377305887639523,
-0.009032164700329304,
0.004590208176523447,
-0.01287126261740923,
-0.04531289264559746,
-0.024875976145267487,
0.019848329946398735,
-0.03275402635335922,
0.052265144884586334,
0.02099017985165119,
0.009131297469139099,
0.008982779458165169,
0.06528127938508987,
0.004794962704181671,
0.004527371376752853,
-0.0050161974504590034,
-0.006537874694913626,
0.02887030690908432,
-0.025424569845199585,
-0.00959706399589777,
0.020873095840215683,
0.032404348254203796,
0.006389196962118149,
0.03272387757897377,
0.0025568422861397266,
0.0014365192037075758,
-0.018245233222842216,
-0.020699765533208847,
-0.015546517446637154,
0.017885588109493256,
-0.02493668906390667,
-0.01083605270832777,
-0.01985991932451725,
0.009580908343195915
] |
8a4ccded7f4f9f9be895e48e8a31955a7046241e | 4,371 | py | Python | dddppp/settings.py | tysonclugg/dddppp | 22f52d671ca71c2df8d6ac566a1626e5f05b3159 | [
"MIT"
] | null | null | null | dddppp/settings.py | tysonclugg/dddppp | 22f52d671ca71c2df8d6ac566a1626e5f05b3159 | [
"MIT"
] | null | null | null | dddppp/settings.py | tysonclugg/dddppp | 22f52d671ca71c2df8d6ac566a1626e5f05b3159 | [
"MIT"
] | null | null | null | """
Django settings for dddppp project.
Generated by 'django-admin startproject' using Django 1.8.2.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import pkg_resources
import pwd
PROJECT_NAME = 'dddppp'
# Enforce a valid POSIX environment
# Get missing environment variables via call to pwd.getpwuid(...)
_PW_CACHE = None
_PW_MAP = {
'LOGNAME': 'pw_name',
'USER': 'pw_name',
'USERNAME': 'pw_name',
'UID': 'pw_uid',
'GID': 'pw_gid',
'HOME': 'pw_dir',
'SHELL': 'pw_shell',
}
for _missing_env in set(_PW_MAP).difference(os.environ):
if _PW_CACHE is None:
_PW_CACHE = pwd.getpwuid(os.getuid())
os.environ[_missing_env] = str(getattr(_PW_CACHE, _PW_MAP[_missing_env]))
del _PW_CACHE, _PW_MAP, pwd
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'nfd_lvt=&k#h#$a^_l09j#5%s=mg+0aw=@t84ry$&rps43c33+'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [
'localhost',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dddp',
'dddp.server',
'dddp.accounts',
'dddppp.slides',
]
for (requirement, pth) in [
('django-extensions', 'django_extensions'),
]:
try:
pkg_resources.get_distribution(requirement)
except (
pkg_resources.DistributionNotFound,
pkg_resources.VersionConflict,
):
continue
INSTALLED_APPS.append(pth)
MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
#'django.middleware.security.SecurityMiddleware',
]
ROOT_URLCONF = 'dddppp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'dddppp.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('PGDATABASE', PROJECT_NAME),
'USER': os.environ.get('PGUSER', os.environ['LOGNAME']),
'PASSWORD': os.environ.get('DJANGO_DATABASE_PASSWORD', ''),
'HOST': os.environ.get('PGHOST', ''),
'PORT': os.environ.get('PGPORT', ''),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-au'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
# django-secure
# see: https://github.com/carljm/django-secure/ for more options
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
#SECURE_SSL_REDIRECT = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_FRAME_DENY = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
DDDPPP_CONTENT_TYPES = []
PROJ_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
| 26.981481 | 77 | 0.695722 | 1 | 2.0976 | [
0.012596240267157555,
0.047156039625406265,
-0.004612838849425316,
0.005868595093488693,
-0.031222160905599594,
-0.00741373747587204,
0.02007110044360161,
0.00022972917940933257,
0.011362319812178612,
-0.023998480290174484,
0.02529819868505001,
0.020105021074414253,
-0.016755172982811928,
0.045233238488435745,
-0.00914098136126995,
-0.013350960798561573,
0.0016438851598650217,
0.07591167837381363,
-0.02857143245637417,
0.0016647095326334238,
0.03200773894786835,
0.011698512360453606,
0.014283707365393639,
0.002173692686483264,
-0.018851516768336296,
0.021749338135123253,
-0.04338023066520691,
0.014558563940227032,
-0.007415002211928368,
-0.020233530551195145,
-0.049568917602300644,
-0.045314643532037735,
-0.004504346288740635,
-0.0016819300362840295,
0.023510146886110306,
-0.01878700777888298,
0.003104822477325797,
-0.012561886571347713,
0.03825436905026436,
-0.004503729287534952,
-0.012856855988502502,
-0.018528515473008156,
-0.03406427428126335,
-0.022648081183433533,
0.000008590139259467833,
-0.03157547116279602,
-0.022614115849137306,
-0.03231355920433998,
-0.005391864571720362,
-0.021245962008833885,
0.006965796463191509,
0.03637247160077095,
0.01657099649310112,
0.0546114556491375,
0.02386375516653061,
-0.03568365052342415,
-0.00311783398501575,
0.019678957760334015,
-0.008478273637592793,
0.026263542473316193,
-0.0023927208967506886,
0.017645884305238724,
0.03413960710167885,
-0.016009705141186714,
0.02382688596844673,
0.0016092315781861544,
0.038351740688085556,
0.013887167908251286,
0.020131811499595642,
0.01764623075723648,
-0.025820132344961166,
-0.0504927933216095,
0.014778951182961464,
0.04744063317775726,
0.0710434541106224,
0.007748336996883154,
0.022459618747234344,
0.00572569714859128,
-0.006233242340385914,
0.009149288758635521,
0.005896120332181454,
0.026516225188970566,
-0.013255848549306393,
-0.016077499836683273,
0.05054724961519241,
0.020938733592629433,
0.005134129896759987,
-0.022756939753890038,
0.02199205383658409,
-0.02528354711830616,
0.01024012640118599,
0.044493723660707474,
-0.015667349100112915,
0.017863189801573753,
-0.031385816633701324,
-0.032687049359083176,
-0.0014132573269307613,
-0.026973336935043335,
0.03254735469818115,
-0.017009403556585312,
0.0027378248050808907,
0.03459835797548294,
0.03140641376376152,
0.02880161628127098,
0.017093190923333168,
-0.026606140658259392,
-0.03749175742268562,
0.04130041226744652,
0.014752949588000774,
-0.021899480372667313,
-0.06696853786706924,
-0.0066339001059532166,
-0.058901917189359665,
-0.01573260873556137,
-0.06682799011468887,
-0.02583988383412361,
-0.0029475113842636347,
0.0007447757525369525,
0.009227011352777481,
0.04518688842654228,
-0.00047123708645813167,
-0.039045173674821854,
-0.012435543350875378,
0.023936057463288307,
-0.019209198653697968,
0.046307891607284546,
0.03059212863445282,
0.03741324692964554,
0.010250616818666458,
0.01752711646258831,
0.021523628383874893,
-0.0011128174373880029,
0.002984910272061825,
-0.03956236317753792,
-0.030929410830140114,
-0.009367442689836025,
-0.003649658989161253,
-0.031598202884197235,
-0.02661558985710144,
0.019385553896427155,
0.03410365805029869,
-0.026765193790197372,
-0.013604093343019485,
0.03804352506995201,
-0.014440258033573627,
-0.028851741924881935,
-0.02059038355946541,
-0.00002803669121931307,
0.0034735146909952164,
0.02216390147805214,
0.023366471752524376,
-0.03609452396631241,
0.020099394023418427,
-0.03142356127500534,
-0.03354490548372269,
0.03656871244311333,
-0.0060773673467338085,
0.0159043837338686,
0.009252308867871761,
0.001341859344393015,
-0.03528907522559166,
0.00624426594004035,
-0.01985516957938671,
0.03136395290493965,
-0.01317821815609932,
-0.007596652954816818,
0.01685277558863163,
0.011949606239795685,
0.007997778244316578,
0.03905695676803589,
0.0006540807080455124,
0.01927352137863636,
0.01955299824476242,
0.027134712785482407,
-0.024663932621479034,
-0.023353978991508484,
0.016193365678191185,
-0.015157208777964115,
-0.0271557979285717,
-0.024389108642935753,
0.022772816941142082,
-0.007652466185390949,
-0.03741840645670891,
0.05478304997086525,
-0.009425767697393894,
0.0007237266981974244,
0.01268855668604374,
-0.03258909657597542,
0.014397135935723782,
-0.0027340708766132593,
0.013949860818684101,
0.021562280133366585,
0.029497871175408363,
0.03436792641878128,
-0.017125509679317474,
-0.02756783366203308,
0.03804854676127434,
-0.0022966989781707525,
-0.0018861088901758194,
0.003666909644380212,
0.009160995483398438,
-0.007757450919598341,
0.022611400112509727,
0.01196630485355854,
0.0003322031407151371,
-0.009060771204531193,
-0.7038108706474304,
0.022386910393834114,
0.012315941974520683,
0.014843519777059555,
-0.07731175422668457,
0.02574680745601654,
-0.04104166850447655,
0.009476075880229473,
0.00992021057754755,
0.005650869105011225,
-0.006926166359335184,
0.020006809383630753,
-0.024489380419254303,
0.020435495302081108,
-0.00703266728669405,
-0.02908046543598175,
0.019489502534270287,
0.031487856060266495,
-0.006879473105072975,
0.038036931306123734,
-0.023541714996099472,
-0.06083875894546509,
0.003343082033097744,
-0.005648071877658367,
-0.014191130176186562,
-0.01700476184487343,
-0.013743210583925247,
-0.028271380811929703,
-0.027467593550682068,
-0.04720475897192955,
-0.019232580438256264,
-0.015969570726156235,
0.032896559685468674,
-0.03695073351264,
-0.04584947228431702,
0.02488204650580883,
0.06661930680274963,
-0.03437149524688721,
-0.042159002274274826,
0.005939203780144453,
-0.015499396249651909,
-0.029906924813985825,
-0.04148923605680466,
-0.051549579948186874,
-0.022788891568779945,
0.010507202707231045,
0.07131131738424301,
-0.00008903773414203897,
0.03565900772809982,
-0.010190999135375023,
-0.02656940557062626,
0.01320351380854845,
0.03487978130578995,
-0.02098020724952221,
-0.0034459971357136965,
-0.00868096761405468,
-0.03406061604619026,
-0.014347583055496216,
0.03780866041779518,
0.0059959497302770615,
0.0016610019374638796,
-0.031493496149778366,
-0.000045626115024788305,
-0.007474924437701702,
-0.044538237154483795,
0.01127617433667183,
-0.006174412090331316,
-0.03190124034881592,
-0.022457754239439964,
0.007577443961054087,
-0.02089628577232361,
-0.030378706753253937,
-0.06281672418117523,
0.010703782550990582,
-0.008246439509093761,
-0.012181872501969337,
0.02735714800655842,
-0.03837037831544876,
-0.05554947629570961,
-0.01702936924993992,
0.014342951588332653,
-0.005117684602737427,
-0.015436793677508831,
-0.011524892412126064,
0.022879697382450104,
-0.002705673221498728,
-0.024196797981858253,
0.015856731683015823,
0.02914985455572605,
0.024230681359767914,
0.04288528487086296,
-0.004322484135627747,
0.031350329518318176,
0.03751605004072189,
0.01872394047677517,
0.06386344134807587,
-0.03337903320789337,
-0.030857453122735023,
-0.010910297743976116,
-0.0019016499863937497,
-0.0006252299644984305,
0.006489966996014118,
-0.01742064766585827,
-0.02416219376027584,
-0.09961578994989395,
0.010558830574154854,
-0.030747609212994576,
-0.04592021182179451,
-0.0155333885923028,
0.02058875374495983,
0.023611152544617653,
-0.016917169094085693,
0.030230186879634857,
-0.025038328021764755,
0.021921837702393532,
-0.004144411999732256,
0.006322311237454414,
-0.004635957535356283,
-0.007721632719039917,
0.0002126369217876345,
0.020476188510656357,
-0.03275514394044876,
0.024375783279538155,
0.013166830874979496,
-0.024077262729406357,
0.023714978247880936,
-0.013276931829750538,
-0.011420824564993382,
-0.006249594036489725,
0.023919757455587387,
-0.04265064373612404,
-0.01738823764026165,
-0.000034612545277923346,
-0.052598986774683,
-0.0018035328248515725,
0.017969312146306038,
-0.0005861332174390554,
-0.02292267233133316,
-0.024873925372958183,
-0.003076201770454645,
0.015044794417917728,
0.002105867024511099,
0.012502684257924557,
-0.0315224789083004,
0.02693108841776848,
0.03301436826586723,
-0.02329389937222004,
0.004682499449700117,
-0.004393617156893015,
-0.02072799950838089,
0.01942129246890545,
0.04816345497965813,
-0.004610585980117321,
0.02452806383371353,
-0.0038587048184126616,
0.00996503233909607,
0.00045518847764469683,
-0.013249964453279972,
-0.02863968349993229,
0.01504790410399437,
-0.04265684261918068,
0.012278190813958645,
0.019149351865053177,
-0.013497890904545784,
0.013043534010648727,
-0.016841424629092216,
0.006762122735381126,
-0.0398714654147625,
-0.01159718818962574,
0.016550352796912193,
0.035076770931482315,
-0.02161046676337719,
-0.019016243517398834,
0.03253746032714844,
-0.009968101046979427,
-0.025890568271279335,
-0.03349278122186661,
-0.04750698059797287,
0.008984759449958801,
0.001540207420475781,
0.03584562987089157,
-0.00014416780322790146,
0.006184642668813467,
0.008916442282497883,
-0.011266956105828285,
0.024155044928193092,
0.007250678725540638,
0.005117467138916254,
0.03486969694495201,
0.029194606468081474,
-0.012687528505921364,
0.052735719829797745,
-0.03277665749192238,
-0.012304228730499744,
-0.005417325999587774,
-0.011822416447103024,
-0.023436585441231728,
-0.00845414213836193,
-0.01129390113055706,
-0.04240730032324791,
0.005792757496237755,
0.0038670566864311695,
0.013176213018596172,
0.001048374455422163,
-0.016003312543034554,
0.012724122032523155,
-0.001778577221557498,
0.015779318287968636,
-0.010484263300895691,
-0.028501804918050766,
0.04102478176355362,
0.02664985880255699,
0.01918979175388813,
-0.019350560382008553,
0.017031455412507057,
0.008394611068069935,
-0.03988029435276985,
0.0359843485057354,
0.028223147615790367,
-0.009036309085786343,
0.006501501891762018,
0.01149758417159319,
0.016147999092936516,
0.01736629381775856,
0.013968183659017086,
0.03236581012606621,
0.01610955409705639,
0.019133031368255615,
-0.046155672520399094,
-0.02446228265762329,
-0.0538673959672451,
0.004796849098056555,
-0.014569918625056744,
-0.016636431217193604,
-0.040964510291814804,
-0.025262614712119102,
0.006899435538798571,
-0.004093818366527557,
-0.0051636178977787495,
-0.011097943410277367,
-0.002166041638702154,
0.0057616326957941055,
-0.028377888724207878,
-0.010226947255432606,
0.010678104124963284,
-0.008624300360679626,
-0.0017628363566473126,
-0.008582091890275478,
-0.0039017426315695047,
-0.0020665908232331276,
-0.017707210034132004,
-0.012851137667894363,
-0.0008550446946173906,
-0.020282205194234848,
-0.016636718064546585,
-0.005996160674840212,
0.025763021782040596,
0.007279503159224987,
-0.021442074328660965,
0.012966196984052658,
0.019349994137883186,
0.010551301762461662,
0.009540705941617489,
0.006880246568471193,
0.02568199671804905,
0.01827595941722393,
0.02054576389491558,
-0.03336840495467186,
-0.04655570909380913,
-0.008894797414541245,
-0.007640899624675512,
0.017836887389421463,
-0.023704035207629204,
0.009032477624714375,
-0.0024430835619568825,
0.03750108182430267,
-0.019568590447306633,
-0.007040336728096008,
0.021724041551351547,
-0.003084491705521941,
-0.05810480937361717,
0.008205123245716095,
-0.025301000103354454,
-0.0250187236815691,
-0.013356777839362621,
-0.0313245989382267,
-0.0214291550219059,
0.022122954949736595,
-0.004403280559927225,
-0.0283002108335495,
-0.03803841397166252,
0.008395489305257797,
0.011735650710761547,
0.037794675678014755,
-0.0003024730831384659,
-0.0062155039049685,
-0.0023230062797665596,
-0.015216867439448833,
-0.031215395778417587,
0.04852120950818062,
0.01910020038485527,
-0.040313057601451874,
-0.010197722353041172,
-0.00469185272231698,
-0.023691099137067795,
0.022550510242581367,
-0.023056404665112495,
-0.002869231393560767,
0.008035390637814999,
0.010247652418911457,
0.021256370469927788,
-0.005627800710499287,
-0.001616023015230894,
0.015942074358463287,
-0.0015906357439234853,
0.012860557064414024,
0.025295764207839966,
-0.0070029390044510365,
-0.020255006849765778,
-0.009664751589298248,
-0.0335555262863636,
0.024098161607980728,
-0.03888452425599098,
0.001821188721805811,
0.006031728815287352,
-0.004126210696995258,
-0.01937272772192955,
-0.0021045440807938576,
-0.015148531645536423,
0.013368855230510235,
-0.011218279600143433,
-0.011202242225408554,
0.01589220203459263,
0.020777221769094467,
0.04891145974397659,
0.012770808301866055,
-0.019348889589309692,
-0.0065137650817632675,
0.009708822704851627,
-0.02516791597008705,
-0.004707480780780315,
0.015286128968000412,
-0.035991769284009933,
-0.002682297257706523,
0.02052592858672142,
-0.011447875760495663,
-0.012274619191884995,
0.003387585747987032,
-0.007235911209136248,
0.000014751943126611877,
-0.024529028683900833,
0.008542502298951149,
-0.026296494528651237,
0.011440525762736797,
-0.017555823549628258,
-0.01824030838906765,
0.008705473504960537,
-0.0007673318614251912,
0.024710338562726974,
-0.0003856733092106879,
0.040006451308727264,
0.022295279428362846,
0.0013126947451382875,
0.010827815160155296,
0.006418286357074976,
-0.021477095782756805,
0.006406423170119524,
0.0019105509854853153,
-0.014850727282464504,
-0.029407301917672157,
0.0006612666766159236,
0.04695639759302139,
-0.013741075992584229,
0.00562948826700449,
0.01533177774399519,
-0.01580693945288658,
0.01696406863629818,
0.05126207321882248,
-0.004239942412823439,
0.015114483423531055,
-0.010765171609818935,
0.013506158255040646,
-0.03363823890686035,
0.004122153390198946,
0.0034741314593702555,
-0.008587813004851341,
-0.012465395033359528,
-0.011999552138149738,
0.004523195791989565,
0.005955805070698261,
0.02869420312345028,
-0.012020563706755638,
-0.046904899179935455,
0.007280948106199503,
-0.00035869944258593023,
0.030877530574798584,
-0.026182763278484344,
-0.008490407839417458,
0.004266013856977224,
0.0038430916611105204,
-0.026111865416169167,
0.041821978986263275,
-0.025250252336263657,
0.00582858407869935,
0.0017225707415491343,
-0.00873052328824997,
-0.017612149938941002,
0.013788294047117233,
-0.020458832383155823,
0.05850185081362724,
-0.002816411666572094,
-0.014898208901286125,
-0.035964351147413254,
-0.011066640727221966,
0.04239101707935333,
0.01392090879380703,
-0.04332413151860237,
0.0027331016026437283,
0.0015412094071507454,
-0.011806306429207325,
-0.0013061600038781762,
0.027436647564172745,
0.023464996367692947,
0.01710880734026432,
-0.010172264650464058,
0.02805596962571144,
-0.0074684470891952515,
0.005064039491117001,
0.06901761889457703,
0.01984497159719467,
-0.013724678196012974,
0.010711008682847023,
-0.02257574535906315,
-0.02743166871368885,
0.044775526970624924,
-0.050092704594135284,
0.010372125543653965,
-0.010853178799152374,
0.02813180349767208,
-0.003030127612873912,
-0.022636614739894867,
-0.0061900559812784195,
-0.019179245457053185,
0.033251941204071045,
0.023945771157741547,
-0.156636580824852,
0.02384484000504017,
0.01568710058927536,
0.013323195278644562,
-0.013483788818120956,
-0.09766179323196411,
0.004554737359285355,
0.007902116514742374,
-0.0142593365162611,
0.02620372548699379,
0.00021089806978125125,
-0.03143930435180664,
0.020938055589795113,
-0.018640724942088127,
0.0023397624026983976,
0.05157897621393204,
-0.03651461750268936,
0.0007478633779101074,
-0.0000451334890385624,
-0.007999717257916927,
-0.0013345020124688745,
0.013970225118100643,
-0.009871642105281353,
-0.0012816785601899028,
-0.014615093357861042,
0.006046927534043789,
0.021188391372561455,
0.06017705798149109,
-0.0034456613939255476,
-0.035751309245824814,
0.012979674153029919,
0.01281080674380064,
0.04011773318052292,
0.0044124554842710495,
-0.01746273599565029,
0.01786077953875065,
0.018115367740392685,
0.052674420177936554,
0.0044120061211287975,
0.0030962328892201185,
-0.015270043164491653,
-0.0023050843738019466,
0.05563634634017944,
0.01553410291671753,
-0.0031520079355686903,
0.016278905794024467,
-0.015645192936062813,
-0.022191137075424194,
-0.025830794125795364,
-0.005319696385413408,
0.009907227009534836,
-0.008184372447431087,
-0.03511732444167137,
0.008101553656160831,
-0.03203359246253967,
0.03616432473063469,
0.008082494139671326,
0.01095606293529272,
-0.029485048726201057,
0.03754240646958351,
0.03707486018538475,
0.04846492409706116,
0.03298960253596306,
-0.003849375993013382,
0.02415972761809826,
-0.03242715820670128,
-0.023128056898713112,
0.03363689035177231,
0.038608454167842865,
0.03979147598147392,
0.006966068409383297,
0.0071190171875059605,
0.055688582360744476,
-0.0036649482790380716,
0.020320305600762367,
0.019867300987243652,
0.008566483855247498,
0.04119323194026947,
0.008611651137471199,
0.006293737795203924,
0.03308485448360443,
0.001866515027359128,
-0.02567082829773426,
0.011789405718445778,
0.0058708046562969685,
0.00899752788245678,
0.005228744354099035,
-0.010665674693882465,
-0.027922792360186577,
0.02473246119916439,
0.023360133171081543,
0.016557078808546066,
-0.002856174483895302,
0.003759006503969431,
-0.053467847406864166,
0.04069992154836655,
0.016923170536756516,
-0.006504305638372898,
0.02627764269709587,
0.03253250569105148,
-0.012142563238739967,
0.05010935291647911,
-0.022836755961179733,
0.02713499404489994,
0.012499268166720867,
0.022436190396547318,
-0.0015255409525707364,
0.019017545506358147,
-0.00496686389669776,
-0.044721778482198715,
-0.030960360541939735,
0.043652236461639404,
0.0392833836376667,
-0.02945556864142418,
-0.030912991613149643,
-0.011144803836941719,
-0.0036301130894571543
] |
8a4fee7da31280c4ead726e734baac5bb3fc023e | 1,227 | py | Python | setup.py | dantas/wifi | e9cd6df7d3411f1532843999f6c33f45369c3fe4 | [
"BSD-2-Clause"
] | 1 | 2019-04-29T14:57:45.000Z | 2019-04-29T14:57:45.000Z | setup.py | dantas/wifi | e9cd6df7d3411f1532843999f6c33f45369c3fe4 | [
"BSD-2-Clause"
] | null | null | null | setup.py | dantas/wifi | e9cd6df7d3411f1532843999f6c33f45369c3fe4 | [
"BSD-2-Clause"
] | null | null | null | #!/usr/bin/env python
from setuptools import setup
import os
__doc__ = """
Command line tool and library wrappers around iwlist and
/etc/network/interfaces.
"""
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
install_requires = [
'setuptools',
'pbkdf2',
]
try:
import argparse
except:
install_requires.append('argparse')
version = '1.0.0'
setup(
name='wifi',
version=version,
author='Rocky Meza, Gavin Wahl',
author_email='rockymeza@gmail.com',
description=__doc__,
long_description=read('README.rst'),
packages=['wifi'],
scripts=['bin/wifi'],
test_suite='tests',
platforms=["Debian"],
license='BSD',
install_requires=install_requires,
classifiers=[
"License :: OSI Approved :: BSD License",
"Topic :: System :: Networking",
"Operating System :: POSIX :: Linux",
"Environment :: Console",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
],
data_files=[
('/etc/bash_completion.d/', ['extras/wifi-completion.bash']),
]
)
| 23.150943 | 70 | 0.625102 | 1 | 1.0476 | [
0.0006940467283129692,
0.023608282208442688,
0.008956341072916985,
0.0007909935666248202,
0.00515421899035573,
-0.003093504114076495,
-0.011263852939009666,
0.0032535966020077467,
-0.0090645682066679,
0.0013738226843997836,
0.0019993071909993887,
0.006141475401818752,
0.006734047085046768,
-0.017668265849351883,
0.0014742433559149504,
0.016423696652054787,
-0.05468524619936943,
0.0017696745926514268,
-0.0024568180087953806,
0.0023269066587090492,
-0.009863859042525291,
0.0094715291634202,
0.0069520967081189156,
0.008318452164530754,
0.006930922623723745,
0.0008719941251911223,
0.008003455586731434,
0.002428075997158885,
-0.008575450628995895,
-0.00660306541249156,
0.0002129926288034767,
-0.002878913888707757,
-0.0061228335835039616,
-0.009575019590556622,
0.007120027206838131,
-0.0033632724080234766,
-0.0003209939750377089,
-0.018289634957909584,
0.011421099305152893,
-0.0038940960075706244,
-0.007752031087875366,
-0.015450343489646912,
-0.0005972093786112964,
0.004192691296339035,
-0.008651656098663807,
0.0016897779423743486,
-0.003981622401624918,
0.002197010675445199,
-0.010530147701501846,
0.005804055370390415,
-0.008541523478925228,
0.007600155659019947,
0.013793425634503365,
0.004327581729739904,
-0.005528549663722515,
-0.006519853603094816,
0.01220690831542015,
0.00030002067796885967,
-0.010358192957937717,
0.000983312726020813,
-0.001354159670881927,
-0.0024995976127684116,
0.004265637136995792,
0.004951937589794397,
-0.017063433304429054,
-0.008521368727087975,
-0.002837067935615778,
0.0021169863175600767,
-0.0014244935009628534,
0.00675054918974638,
-0.0005378367495723069,
-0.0017566864844411612,
0.0074715381488204,
0.0026431989390403032,
0.006687156856060028,
-0.000781205075327307,
-0.0010640573455020785,
0.00019681219418998808,
0.009318636730313301,
0.005148035008460283,
0.0035910201258957386,
-0.006541033275425434,
0.007952891290187836,
0.00900332722812891,
0.015956150367856026,
0.009374218992888927,
0.01731925457715988,
-0.01042898464947939,
0.047269150614738464,
0.004684313200414181,
-0.010997891426086426,
0.0009283003746531904,
-0.00876957643777132,
-0.0031910131219774485,
-0.004495504777878523,
-0.02828514203429222,
0.0019017909653484821,
-0.002660138998180628,
-0.0022016384173184633,
0.004923366941511631,
-0.0012121403124183416,
0.004922821652144194,
-0.00349063822068274,
-0.0017474942142143846,
-0.011698761023581028,
0.014259975403547287,
-0.00963884498924017,
-0.0018492271192371845,
0.006015204358845949,
0.0022239258978515863,
-0.007255282253026962,
-0.0026042074896395206,
0.0010487653780728579,
-0.011985094286501408,
0.004682658240199089,
0.004313047043979168,
-0.004247820936143398,
0.053848013281822205,
-0.0015217652544379234,
0.004378529731184244,
-0.0029637282714247704,
0.0012859791750088334,
-0.00199490156956017,
0.005794973578304052,
0.007754886522889137,
-0.0028428626246750355,
0.011024431325495243,
0.005618863273411989,
0.001669401302933693,
0.009186750277876854,
-0.0024370786268264055,
0.007405867800116539,
-0.00511448597535491,
-0.0017108493484556675,
-0.0003900734009221196,
-0.007409375160932541,
0.006840024143457413,
-0.0013612047769129276,
-0.006306726019829512,
-0.0007868809625506401,
-0.00009261086961487308,
-0.009984874166548252,
0.004479091614484787,
-0.0005048469756729901,
0.0050557819195091724,
-0.011734364554286003,
-0.00496466550976038,
-0.002058221260085702,
-0.0045114620588719845,
0.0025840012822300196,
0.009886582382023335,
0.0038635015953332186,
0.004343409091234207,
-0.003996516577899456,
-0.008385739289224148,
-0.0016090432181954384,
-0.0034013083204627037,
0.0019390856614336371,
0.00543280178681016,
0.00607591075822711,
-0.010931217111647129,
-0.0005126323085278273,
0.002384508028626442,
0.0038169424515217543,
-0.00046934420242905617,
0.0036656041629612446,
-0.008224798366427422,
0.007302206475287676,
4.966682709550696e-8,
0.004708318505436182,
0.011125845834612846,
-0.0026628493797034025,
-0.0006341244443319738,
0.0007730003562755883,
0.0037036575376987457,
0.000414473470300436,
0.007823115214705467,
0.010161367245018482,
-0.0014588774647563696,
-0.0035727564245462418,
0.004141342360526323,
0.005051703657954931,
0.005454638972878456,
0.008645188063383102,
-0.0028924145735800266,
0.0012798942625522614,
-0.004355622921139002,
-0.0010433049174025655,
0.00417716521769762,
-0.0023341276682913303,
0.005582215264439583,
0.005481421947479248,
-0.013813162222504616,
-0.008631951175630093,
-0.0001247586333192885,
-0.00858988519757986,
0.0001698235428193584,
0.012760662473738194,
0.01388540118932724,
-0.005602954886853695,
0.0042336066253483295,
-0.010961744002997875,
0.0012469494249671698,
0.008656985126435757,
0.0003245101252105087,
-0.014346213079988956,
-0.9577951431274414,
0.0057226624339818954,
0.0018897535046562552,
-0.001734821475110948,
0.005082221236079931,
0.00047244373126886785,
0.002236247295513749,
0.005064976867288351,
0.01313657034188509,
-0.008303810842335224,
-0.007250701542943716,
-0.007641525007784367,
-0.01240111980587244,
-0.0014544143341481686,
-0.007175295613706112,
-0.002229084726423025,
-0.006850930862128735,
-0.0053044394589960575,
-0.0031193618196994066,
-0.004342051688581705,
-0.0022701413836330175,
0.008475309237837791,
0.00004050325878779404,
0.004568384028971195,
0.0026462101377546787,
0.003347159596160054,
-0.005700342822819948,
-0.002052632160484791,
-0.000010229540748696309,
-0.0037736212834715843,
-0.00589272053912282,
-0.016608092933893204,
-0.004089116118848324,
-0.0018139034509658813,
0.01012459583580494,
0.0026754382997751236,
0.009653713554143906,
-0.0007770917727611959,
0.00316253793425858,
-0.007883038371801376,
0.0054546138271689415,
0.0025116922333836555,
0.002964571351185441,
-0.0310331042855978,
-0.0001592781045474112,
-0.00019797282584477216,
-0.010594891384243965,
0.006049551069736481,
0.0019468637183308601,
-0.0028304813895374537,
-0.001887014601379633,
-0.005608276464045048,
0.009336110204458237,
-0.009056306444108486,
0.007894211448729038,
-0.00431687431409955,
-0.007331666070967913,
-0.004141195677220821,
-0.009890670888125896,
0.002428698819130659,
0.005181637592613697,
-0.004174938425421715,
-0.004513770341873169,
-0.0030684403609484434,
0.0005537910619750619,
0.003903689794242382,
0.0017252933466807008,
-0.01699335128068924,
-0.00509582320228219,
-0.002053104108199477,
0.004512897692620754,
-0.005450084805488586,
-0.004065715707838535,
0.00566834257915616,
-0.008065924979746342,
0.005917919799685478,
0.001981857931241393,
-0.0006480137235485017,
-0.01108565740287304,
0.0025613061152398586,
-0.008050059899687767,
-0.0070054358802735806,
0.0009174358565360308,
-0.0033721027430146933,
-0.005078088492155075,
0.0007802912150509655,
-0.0005004924605600536,
0.0062703778967261314,
-0.003921210300177336,
0.004233840852975845,
0.011206493712961674,
-0.005258822813630104,
-0.008669866248965263,
0.004907602909952402,
0.007620048709213734,
-0.0005592239322140813,
-0.001694727805443108,
0.0033705956302583218,
0.009311928413808346,
0.007108926773071289,
0.004092027898877859,
0.0045690820552408695,
-0.001361498492769897,
0.012279616668820381,
-0.0017969394102692604,
0.0011833261232823133,
-0.004724221769720316,
-0.001596486079506576,
-0.0034638948272913694,
0.0022437686566263437,
-0.0037542188074439764,
-0.0029632486402988434,
-0.012627885676920414,
-0.009632289409637451,
-0.0014144557062536478,
-0.0005105872405692935,
0.0031083007343113422,
-0.005259346216917038,
-0.0013911613496020436,
0.004142713267356157,
0.010207969695329666,
-0.0013451947597786784,
-0.003500542836263776,
0.00021844850562047213,
0.002348347334191203,
-0.00614433316513896,
0.013940086588263512,
-0.010691913776099682,
0.005480560008436441,
-0.0022051932755857706,
-0.01543661579489708,
0.007815367542207241,
0.007893054746091366,
-0.007246745750308037,
0.0038182162679731846,
0.002058965852484107,
0.004089463967829943,
-0.00029676445410586894,
-0.002460194518789649,
-0.004336295649409294,
-0.01586890034377575,
0.0010824876371771097,
0.020884323865175247,
0.0035710677038878202,
0.007943503558635712,
0.010305078700184822,
-0.0032015263568609953,
0.001815629773773253,
0.007435696665197611,
-0.0019603404216468334,
0.012315787374973297,
-0.007462524343281984,
-0.0036855624057352543,
0.0008974418160505593,
-0.007543785031884909,
0.0016593938926234841,
0.00551450252532959,
0.004732848610728979,
-0.0025168107822537422,
0.0015563018387183547,
-0.006547536235302687,
-0.004374900832772255,
-0.0171736441552639,
-0.003126411931589246,
0.008157946169376373,
-0.006103005260229111,
0.006521127186715603,
-0.012222379446029663,
0.0054756891913712025,
0.006553812883794308,
0.004538469482213259,
-0.000813811959233135,
0.0009418561239726841,
0.005842568352818489,
0.009889869950711727,
-0.00534593453630805,
0.0001269352505914867,
0.0018433413933962584,
-0.0003185248060617596,
0.0007664166041649878,
0.0048104943707585335,
-0.0076380218379199505,
-0.004251345060765743,
0.002549006137996912,
0.004797677509486675,
-0.0010252746287733316,
-0.003950942307710648,
-0.008512899279594421,
-0.003711503464728594,
0.002596884733065963,
-0.003516845405101776,
0.005247836001217365,
0.0011257893638685346,
0.004230013117194176,
-0.00922556221485138,
0.0009354718495160341,
-0.005199745297431946,
-0.01114018727093935,
0.010165892541408539,
-0.0036579847801476717,
0.0017441086238250136,
0.010915731079876423,
0.004669991787523031,
-0.014067086391150951,
0.005335284862667322,
0.00759270740672946,
-0.004987536463886499,
0.003214360447600484,
0.005574425216764212,
-0.005024577025324106,
-0.02251819334924221,
-0.0028998220805078745,
-0.014079558663070202,
0.006887002382427454,
-0.0039697689935564995,
0.0009032257366925478,
-0.007524768356233835,
0.00529532739892602,
0.006098544225096703,
-0.01223251223564148,
-0.0032370109111070633,
-0.008446639403700829,
0.008836480788886547,
-0.0014152458170428872,
-0.0014925869181752205,
-0.004055771976709366,
-0.0014554441440850496,
-0.0029481968376785517,
-0.0022032856941223145,
-0.0035981626715511084,
0.005556399933993816,
0.0037921727634966373,
-0.003058552974835038,
0.00302184303291142,
-0.004957091994583607,
0.0005432706675492227,
0.0015668753767386079,
-0.009913058020174503,
0.0020795012824237347,
0.00676806690171361,
-0.0005974665400572121,
-0.004855092149227858,
0.00015841634012758732,
-0.0018140320898965001,
-0.003883336205035448,
-0.010018846020102501,
-0.0017106315353885293,
-0.0033619452733546495,
-0.0000011567816500246408,
-0.009821456857025623,
-0.0009250178700312972,
-0.008408975787460804,
0.007052009459584951,
-0.0074468874372541904,
0.007530549541115761,
0.003944488242268562,
-0.00457393005490303,
0.007036618888378143,
-0.002924487227573991,
0.003895871341228485,
0.003411297220736742,
0.005849920213222504,
0.0003252931928727776,
-0.004170885309576988,
-0.012474210932850838,
0.012543091550469398,
-0.006924495566636324,
0.0009349389583803713,
0.013970992527902126,
0.004845567978918552,
0.010710418224334717,
0.000668472028337419,
-0.0011014181654900312,
0.005674087908118963,
0.007787501439452171,
-0.011302917264401913,
0.004366195760667324,
-0.003723062574863434,
0.00018438519327901304,
0.004470834508538246,
-0.003883630270138383,
0.00240354728884995,
0.010192825458943844,
0.001478671794757247,
-0.0074340179562568665,
-0.0013407819205895066,
0.0020316247828304768,
0.004488169681280851,
-0.013116494752466679,
0.00006913035758771002,
-0.0031280098482966423,
-0.003976824693381786,
-0.004503696225583553,
-0.002547075506299734,
-0.0010797249851748347,
0.00498595368117094,
-0.0004632464551832527,
0.006364578381180763,
0.0021912273950874805,
-0.003645086893811822,
0.014696460217237473,
-0.00832262635231018,
-0.003909891936928034,
0.003853945294395089,
0.002168067963793874,
-0.003514305455610156,
-0.006971961352974176,
-0.0038175468798726797,
0.003066669451072812,
0.005051128100603819,
-0.0024556333664804697,
-0.004970266483724117,
0.000038487662095576525,
0.0014979714760556817,
-0.010426957160234451,
-0.00012215322931297123,
0.014190426096320152,
-0.003252010326832533,
0.004900580272078514,
-0.0016278865514323115,
-0.006138283293694258,
-0.014287152327597141,
0.052464328706264496,
0.0007871525012888014,
0.005499084480106831,
0.005956513807177544,
-0.005797187797725201,
-0.0017674572300165892,
-0.000883482804056257,
0.007073346525430679,
-0.009959673509001732,
-0.010397523641586304,
0.010082978755235672,
-0.002582452492788434,
0.004075724631547928,
0.0013513301964849234,
-0.0022725306916981936,
0.014212114736437798,
-0.002743430668488145,
-0.015308089554309845,
-0.018172966316342354,
0.006949865724891424,
-0.006273470353335142,
-0.00799395889043808,
0.00648794649168849,
-0.0022829773370176554,
-0.0046760691329836845,
0.0014508562162518501,
0.004224441479891539,
0.00010642936831573024,
0.0010899407789111137,
-0.0038907115813344717,
-0.0020960248075425625,
0.00030437076929956675,
0.0007526155677624047,
0.008154124021530151,
0.00871337577700615,
-0.004017930012196302,
0.005051772575825453,
-0.0013440006878226995,
0.00025466628721915185,
-0.002538838889449835,
0.004067940637469292,
0.00827427301555872,
-0.00206473795697093,
-0.00334754167124629,
0.0036090107169002295,
0.0034037590958178043,
0.0020036352798342705,
0.009616449475288391,
-0.0010677549289539456,
-0.0051374780014157295,
0.008077549748122692,
0.006296560633927584,
0.0012753632618114352,
0.006003866903483868,
-0.0021044600289314985,
0.004609068389981985,
0.0044503407552838326,
-0.006710938643664122,
-0.018148496747016907,
-0.0063849627040326595,
0.004017430357635021,
0.00692214397713542,
-0.0015532601391896605,
0.0031630226876586676,
-0.004912995267659426,
-0.0016470662085339427,
-0.009191174060106277,
-0.004696444142609835,
-0.004352356307208538,
0.0013449068646878004,
0.0017319568432867527,
0.0725850909948349,
-0.004383206833153963,
-0.001828085514716804,
-0.006487320642918348,
0.0006327051669359207,
-0.0016732250805944204,
-0.0027628163807094097,
-0.00013725341705139726,
-0.0023484863340854645,
0.0008764162193983793,
0.000820778077468276,
-0.007400553673505783,
-0.010488416999578476,
0.0023083186242729425,
0.0005320156924426556,
-0.0028656201902776957,
0.006274143233895302,
0.005400493741035461,
-0.009839831851422787,
0.00218091974966228,
-0.010761191137135029,
-0.0007966028060764074,
-0.004636031109839678,
-0.00957852229475975,
-0.0032691180240362883,
-0.0023252523969858885,
0.005840439349412918,
0.0056885359808802605,
0.004758036695420742,
-0.0026522602420300245,
0.006064390763640404,
-0.0013688376639038324,
0.0014120785053819418,
-0.00557149201631546,
-0.0001183440035674721,
-0.007878288626670837,
0.006232523825019598,
0.003546023042872548,
-0.011417468078434467,
-0.004211784806102514,
-0.0021059978753328323,
0.0006848900229670107,
-0.0046713752672076225,
0.004558964166790247,
-0.0011056337971240282,
0.0036355722695589066,
-0.0019508082186803222,
-0.00006466396007454023,
-0.007370819803327322,
-0.00025787422782741487,
-0.013756485655903816,
0.004672825802117586,
-0.17744283378124237,
0.010696579702198505,
0.004080158658325672,
-0.005659505259245634,
-0.004247060511261225,
-0.014743375591933727,
-0.008037499152123928,
0.003475093748420477,
0.012417490594089031,
0.0007187720038928092,
-0.0023106622975319624,
-0.00006770476466044784,
0.006139983888715506,
0.004757753107696772,
0.0013205334544181824,
-0.005687854252755642,
0.0032463150564581156,
-0.005446008872240782,
0.001468500355258584,
0.002332444302737713,
0.0037237282376736403,
0.010303398594260216,
0.0024519292637705803,
0.0005471163312904537,
-0.0017315070144832134,
-0.003908031620085239,
0.005674396641552448,
-0.0005271050031296909,
0.004823070950806141,
-0.012022675015032291,
-0.0035257735289633274,
-0.004213128238916397,
-0.006160037592053413,
-0.0025172883179038763,
0.006542900111526251,
-0.00230344757437706,
0.008106488734483719,
0.002530769445002079,
-0.00847327709197998,
0.007059733849018812,
-0.009280215948820114,
0.023821987211704254,
0.0009559720056131482,
0.008442379534244537,
0.001865448197349906,
-0.006139822769910097,
-0.004377817735075951,
0.009496530517935753,
0.00039270546403713524,
0.013721220195293427,
-0.011785241775214672,
-0.0029927766881883144,
0.0033509114291518927,
0.018849331885576248,
-0.0038452292792499065,
-0.008129389956593513,
-0.007791493088006973,
-0.0041931308805942535,
0.0022267114836722612,
0.010452203452587128,
0.010164828971028328,
-0.0030673500150442123,
0.00962868519127369,
-0.004464506637305021,
-0.019768496975302696,
0.0025820862501859665,
-0.0030480525456368923,
-0.006490298081189394,
0.0022192911710590124,
0.0081553366035223,
0.010746308602392673,
0.0011110258055850863,
0.0047898790799081326,
-0.0009557113517075777,
0.004945823457092047,
0.0005907408194616437,
0.006282186601310968,
-0.0013317986158654094,
0.005337394308298826,
-0.008313735947012901,
0.008745415136218071,
-0.010761831887066364,
-0.0033182520419359207,
-0.0004187551967334002,
-0.004953577648848295,
0.010604090988636017,
0.004181151278316975,
-0.0014079650864005089,
-0.0011612609960138798,
-0.009843227453529835,
-0.00345103582367301,
0.0036731334403157234,
0.0017564191948622465,
-0.009726929478347301,
0.0038915560580790043,
-0.0018096916610375047,
0.004895390942692757,
0.0058630602434277534,
-0.008190557360649109,
0.006868526339530945,
0.0027284114621579647,
-0.0050056930631399155,
0.0009120287140831351,
-0.005177318584173918,
0.0039453934878110886,
0.0030528272036463022,
-0.005188837181776762,
-0.0061250715516507626,
0.003418376436457038,
-0.005390563979744911,
-0.0054974607191979885,
0.005902498494833708,
-0.009309457615017891,
-0.00816524401307106,
-0.002059070160612464,
-0.012551055289804935,
0.0013032241258770227
] |
8a5020fde45eeb5e84a7966a0bf40c59df2eeca7 | 2,653 | py | Python | auth-api/src/auth_api/resources/org_products.py | severinbeauvais/sbc-auth | c98f75ea8970a357c62093b6e9f7deab61ae87c5 | [
"Apache-2.0"
] | null | null | null | auth-api/src/auth_api/resources/org_products.py | severinbeauvais/sbc-auth | c98f75ea8970a357c62093b6e9f7deab61ae87c5 | [
"Apache-2.0"
] | null | null | null | auth-api/src/auth_api/resources/org_products.py | severinbeauvais/sbc-auth | c98f75ea8970a357c62093b6e9f7deab61ae87c5 | [
"Apache-2.0"
] | null | null | null | # Copyright © 2019 Province of British Columbia
#
# 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.
"""API endpoints for managing an Org resource."""
from flask import request
from flask_restplus import Namespace, Resource, cors
from auth_api import status as http_status
from auth_api.exceptions import BusinessException
from auth_api.jwt_wrapper import JWTWrapper
from auth_api.schemas import ProductSubscriptionSchema
from auth_api.schemas import utils as schema_utils
from auth_api.services import Product as ProductService
from auth_api.tracer import Tracer
from auth_api.utils.roles import Role
from auth_api.utils.util import cors_preflight
API = Namespace('products', description='Endpoints for products management')
TRACER = Tracer.get_instance()
_JWT = JWTWrapper.get_instance()
@cors_preflight('GET,POST,OPTIONS')
@API.route('', methods=['GET', 'POST', 'OPTIONS'])
class OrgProducts(Resource):
"""Resource for managing product subscriptions."""
@staticmethod
@TRACER.trace()
@cors.crossdomain(origin='*')
@_JWT.has_one_of_roles([Role.STAFF_CREATE_ACCOUNTS.value])
def post(org_id):
"""Post a new product subscription to the org using the request body."""
request_json = request.get_json()
valid_format, errors = schema_utils.validate(request_json, 'org_product_subscription')
if not valid_format:
return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST
try:
subscriptions = ProductService.create_product_subscription(org_id, request_json)
if subscriptions is None:
response, status = {'message': 'Not authorized to perform this action'}, \
http_status.HTTP_401_UNAUTHORIZED
else:
response, status = {'subscriptions': ProductSubscriptionSchema().dump(subscriptions, many=True)}, \
http_status.HTTP_201_CREATED
except BusinessException as exception:
response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
return response, status
| 42.790323 | 115 | 0.724463 | 1 | 1.4061 | [
0.001113331294618547,
0.0230258721858263,
0.007570899557322264,
0.004723194055259228,
0.003957543056458235,
-0.0017245658673346043,
-0.00795777328312397,
0.0027914391830563545,
-0.006295913364738226,
0.0016983073437586427,
0.0023285667411983013,
0.004855593200773001,
0.006662514992058277,
-0.016903547570109367,
0.00009995099389925599,
0.01681290753185749,
-0.051485590636730194,
0.00015149821410886943,
-0.0028601924423128366,
0.001682061585597694,
-0.0059140147641301155,
0.00918296817690134,
0.010183965787291527,
0.0052915108390152454,
0.006418062839657068,
-0.0014815591275691986,
0.009081599302589893,
0.0015583584317937493,
-0.006785759702324867,
-0.005328572820872068,
-0.0018883784068748355,
-0.0038443359080702066,
-0.0037802192382514477,
-0.007275714538991451,
0.006847304757684469,
-0.002828095108270645,
-0.0009877968113869429,
-0.019693369045853615,
0.013012894429266453,
-0.006836253684014082,
-0.00694583635777235,
-0.015419631265103817,
-0.0016661180416122079,
0.003895484609529376,
-0.00955911073833704,
0.0024810510221868753,
-0.003984714392572641,
0.003258580807596445,
-0.014192749746143818,
0.007810623850673437,
-0.008540271781384945,
0.007643659599125385,
0.013542835600674152,
0.002990244422107935,
-0.005534560419619083,
-0.0059201340191066265,
0.013382380828261375,
-0.0008934253710322082,
-0.01205536164343357,
-0.00042348046554252505,
-0.004236265085637569,
-0.00364891835488379,
0.005621758289635181,
0.003045802004635334,
-0.016406219452619553,
-0.006323464214801788,
-0.002939466619864106,
0.0017975186929106712,
-0.00037946304655633867,
0.005650584120303392,
-0.00018963469483423978,
0.000007578386430395767,
0.006792571395635605,
0.005905651021748781,
0.0060003409162163734,
-0.004474523011595011,
-0.0004645464650820941,
-0.0011525575537234545,
0.0077233039774000645,
0.004430748987942934,
0.004375198390334845,
-0.006158208940178156,
0.005209675058722496,
0.008290974423289299,
0.013255761936306953,
0.009106649085879326,
0.020695166662335396,
-0.01209359709173441,
0.048629842698574066,
0.009859820827841759,
-0.008873440325260162,
0.0023430297151207924,
-0.009780720807611942,
-0.0011964874574914575,
-0.005303054116666317,
-0.026770537719130516,
0.00039900196134112775,
-0.004246247000992298,
0.0009589382098056376,
0.001938449451699853,
-0.00004785677811014466,
0.006405547261238098,
-0.002184682758525014,
-0.0007216287776827812,
-0.008578091859817505,
0.010251718573272228,
-0.009438086301088333,
-0.0036787318531423807,
0.005670404992997646,
0.0029470401350408792,
-0.011254636570811272,
-0.000509992940351367,
0.0019630107562988997,
-0.012190084904432297,
0.0044068158604204655,
0.002162541961297393,
-0.006045617628842592,
0.05452437326312065,
0.0010396072175353765,
0.0070413826033473015,
-0.005841170437633991,
0.001105126109905541,
-0.0007638823008164763,
0.003950273152440786,
0.009486879222095013,
-0.002485703444108367,
0.011420570313930511,
0.007476470898836851,
0.0028259570244699717,
0.008784820325672626,
-0.0030246314126998186,
0.008407952263951302,
-0.0037402245216071606,
-0.003343480871990323,
0.001975669525563717,
-0.007298043463379145,
0.00630623335018754,
-0.0014914394123479724,
-0.008178099989891052,
0.0004068827838636935,
-0.000019219338355469517,
-0.009844940155744553,
0.0013998473295941949,
-0.0028606250416487455,
0.003349387552589178,
-0.012716146185994148,
-0.00410129688680172,
-0.004645921289920807,
-0.006513999775052071,
0.0023614962119609118,
0.00965867843478918,
0.004120991565287113,
0.0025101511273533106,
-0.004467410501092672,
-0.009468622505664825,
0.00195399415679276,
-0.003896489040926099,
0.002148962812498212,
0.005900240037590265,
0.0023632082156836987,
-0.009874879382550716,
0.00042367755668237805,
0.0033027513418346643,
0.001784042688086629,
-0.0011330981506034732,
0.003331198589876294,
-0.006988320499658585,
0.006005897186696529,
0.0018397688400000334,
0.004139413125813007,
0.010738533921539783,
-0.005555714014917612,
-0.00023918187071103603,
-0.0001742305903462693,
0.001667763921432197,
-0.0014534612419083714,
0.004465445410460234,
0.009429175406694412,
-0.0023699323646724224,
-0.004456368274986744,
0.0029562448617070913,
0.006129547022283077,
0.009305527433753014,
0.007758587133139372,
-0.004058485850691795,
0.0010851214174181223,
-0.00507212383672595,
-0.002395296236500144,
0.00707319937646389,
-0.005454922094941139,
0.004735132679343224,
0.0035121808759868145,
-0.012649240903556347,
-0.006875869818031788,
0.0031284033320844173,
-0.006256235763430595,
0.001416557701304555,
0.012918866239488125,
0.010710686445236206,
-0.004234901163727045,
0.0028285777661949396,
-0.007394852116703987,
-0.00016888084064703435,
0.0046259998343884945,
0.0024146398063749075,
-0.012494229711592197,
-0.9590392112731934,
0.007370572071522474,
0.002487432910129428,
-0.0015599934849888086,
0.0058042192831635475,
0.002121199853718281,
0.0039863064885139465,
0.005130769684910774,
0.01498729083687067,
-0.010256960988044739,
-0.005865742452442646,
-0.00985207874327898,
-0.010261476039886475,
-0.0015796732623130083,
-0.009182380512356758,
-0.002285126131027937,
-0.007273866329342127,
-0.0062293098308146,
0.00021877820836380124,
-0.0024750540032982826,
-0.0035273961257189512,
0.007374405860900879,
-0.0008262370829470456,
0.005782143212854862,
0.003280426375567913,
0.004114734008908272,
-0.006265707779675722,
0.000503250805195421,
-0.0018081610323861241,
0.0005169732612557709,
-0.00760109256953001,
-0.014617891982197762,
-0.003232555231079459,
-0.003240942256525159,
0.013735252432525158,
-0.0010133733740076423,
0.008128192275762558,
-0.0022243496496230364,
0.00240873615257442,
-0.007335904520004988,
0.005766512826085091,
-0.001351404469460249,
0.0039036034140735865,
-0.030733518302440643,
0.0019144773250445724,
-0.001660043140873313,
-0.009932340122759342,
0.008261548355221748,
-0.0007081518415361643,
-0.0008302929345518351,
-0.0014622168382629752,
-0.005551966838538647,
0.010029538534581661,
-0.007697272580116987,
0.00326539040543139,
-0.0046141124330461025,
-0.00888008251786232,
-0.0032788270618766546,
-0.008298950269818306,
0.0007060308707877994,
0.004662851803004742,
-0.003076955210417509,
-0.004883565939962864,
-0.003740188665688038,
0.0029561109840869904,
0.0023002740927040577,
0.00043128058314323425,
-0.01996198669075966,
-0.006414963398128748,
0.00010008605750044808,
-0.0007777017308399081,
-0.006443135440349579,
-0.001882728305645287,
0.005752662196755409,
-0.008570908568799496,
0.006833892315626144,
0.0019018164603039622,
0.001720330328680575,
-0.0122692184522748,
0.0004338580183684826,
-0.0069597321562469006,
-0.007365699857473373,
0.0011627384228631854,
-0.005877895746380091,
-0.004549235571175814,
-0.0015538653824478388,
0.000999466865323484,
0.007897726260125637,
-0.0026367653626948595,
0.0039016378577798605,
0.011682853102684021,
-0.002115869428962469,
-0.006718389689922333,
0.006460508797317743,
0.0066340621560812,
0.00003484969784040004,
-0.002023167908191681,
0.001863335375674069,
0.007740922272205353,
0.007398057263344526,
0.0044219656847417355,
0.006741646211594343,
-0.00007466268289135769,
0.01145154144614935,
-0.001481065759435296,
0.002916528144851327,
-0.0021491702646017075,
-0.0004763951583299786,
-0.002911707852035761,
-0.00010460652265464887,
-0.0047811781987547874,
-0.003582313656806946,
-0.013234112411737442,
-0.008683664724230766,
-0.003461321583017707,
-0.0016452305717393756,
0.0037630824372172356,
-0.003545372746884823,
-0.0009843588341027498,
0.003362537594512105,
0.007324254605919123,
0.001253254245966673,
-0.0010084019741043448,
0.00047060605720616877,
0.0027819438837468624,
-0.007141435984522104,
0.015659619122743607,
-0.012239708565175533,
0.005862419493496418,
-0.00028312255744822323,
-0.01731782592833042,
0.007971430197358131,
0.009981835260987282,
-0.008262861520051956,
0.001718210754916072,
0.005077855195850134,
0.003519236808642745,
-0.0011844331165775657,
-0.004982838407158852,
-0.0024068099446594715,
-0.014275685884058475,
-0.00008890697063179687,
0.0196385495364666,
-0.0004095229087397456,
0.009509461000561714,
0.012775741517543793,
-0.0015816801460459828,
0.0008255543070845306,
0.004551908001303673,
0.0012668428244069219,
0.011162370443344116,
-0.009997216053307056,
0.0006429842323996127,
0.002158386167138815,
-0.0071192639879882336,
-0.0002829160657711327,
0.007068198639899492,
0.0074819340370595455,
-0.0014284186763688922,
0.004672331269830465,
-0.007226426154375076,
-0.0049136667512357235,
-0.018635202199220657,
-0.00362214888446033,
0.007378338370472193,
-0.0045330417342484,
0.006520845927298069,
-0.012306868098676205,
0.005842593964189291,
0.00521832937374711,
0.003095855237916112,
-0.0010883811628445983,
0.00046703152474947274,
0.0044623371213674545,
0.011932358145713806,
-0.0042145391926169395,
0.0027095836121588945,
0.0019970659632235765,
0.0001153548073489219,
0.0002333823940716684,
0.007774330209940672,
-0.00764858303591609,
-0.006397343706339598,
0.0026850919239223003,
0.004836924374103546,
-0.0008056113729253411,
-0.004468930419534445,
-0.009110094979405403,
-0.002788808196783066,
0.004467944148927927,
-0.005618432071059942,
0.005349841900169849,
0.001924932119436562,
0.0041315327398478985,
-0.005043849814683199,
0.0003591800050344318,
-0.0035076166968792677,
-0.012765388004481792,
0.010109112598001957,
-0.00370004796423018,
0.0018756462959572673,
0.01503349095582962,
0.003681622678413987,
-0.0114791514351964,
0.004909368697553873,
0.008734594099223614,
-0.004473804030567408,
0.004886559676378965,
0.00578821636736393,
-0.006266476586461067,
-0.02278628759086132,
-0.003068153513595462,
-0.014116701669991016,
0.007417380344122648,
-0.0034856367856264114,
0.005784603767096996,
-0.008105545304715633,
0.007851076312363148,
0.007969441823661327,
-0.014977577142417431,
-0.004859288688749075,
-0.007022736594080925,
0.008996333926916122,
-0.0006164282094687223,
-0.00033252956927753985,
-0.0032719767186790705,
0.00013635228970088065,
-0.003923097625374794,
-0.003851877758279443,
-0.003014618530869484,
0.006932368036359549,
0.001289290259592235,
-0.002584960078820586,
0.001435843063518405,
-0.004239099100232124,
-0.0003431739751249552,
0.0005842026439495385,
-0.011694679968059063,
0.002870735479518771,
0.0023174560628831387,
-0.0024449347984045744,
-0.004321091342717409,
0.0014687443617731333,
-0.000761335133574903,
-0.008932759054005146,
-0.012158065102994442,
-0.0018623208161443472,
-0.0044863042421638966,
-0.003975491039454937,
-0.011826765723526478,
-0.001577516901306808,
-0.008574160747230053,
0.005764181260019541,
-0.008080543950200081,
0.007250395603477955,
0.005958575289696455,
-0.004721542354673147,
0.006522875279188156,
-0.0013396538561210036,
0.003938943147659302,
0.004588412586599588,
0.005304829683154821,
0.001360586378723383,
-0.0054629649966955185,
-0.011459874920547009,
0.009934499859809875,
-0.007508775684982538,
0.00040935142897069454,
0.011487545445561409,
0.004046846646815538,
0.008002492599189281,
0.00005163330934010446,
0.000348403729731217,
0.0012809393228963017,
0.0074534304440021515,
-0.014279564842581749,
0.002710254630073905,
-0.002179943723604083,
-0.0004889502306468785,
0.00476367212831974,
-0.0031567371916025877,
0.002964550396427512,
0.00858083926141262,
0.0016724324086681008,
-0.008282716386020184,
-0.0016817660070955753,
0.0024137021973729134,
0.0046082837507128716,
-0.012081477791070938,
0.0003633095184341073,
-0.004698183853179216,
-0.004099826794117689,
-0.003379342844709754,
-0.0052745952270925045,
0.00040103052742779255,
0.005542425438761711,
-0.002119050594046712,
0.0055429707281291485,
0.0011986566241830587,
-0.0033992282114923,
0.014494881965219975,
-0.005409973207861185,
-0.004399249795824289,
0.0014451220631599426,
0.0040177227929234505,
-0.002454637084156275,
-0.0076430547051131725,
-0.002728357445448637,
0.0026128077879548073,
0.00831628404557705,
-0.0023093982599675655,
-0.006167302839457989,
-0.0023761247284710407,
0.0023180809803307056,
-0.009860487654805183,
0.002513410523533821,
0.012232478708028793,
-0.0031561858486384153,
0.00508246710523963,
-0.003190771210938692,
-0.0073326765559613705,
-0.013532483018934727,
0.0528012253344059,
-0.001513042370788753,
0.004061907064169645,
0.0039035531226545572,
-0.0074790227226912975,
-0.0007707124459557235,
-0.0025339697021991014,
0.007602110039442778,
-0.005909591447561979,
-0.006588333752006292,
0.008271369151771069,
-0.0030975628178566694,
0.004737561568617821,
0.0030553205870091915,
0.0002969200140796602,
0.014359001070261002,
-0.005904237739741802,
-0.016130957752466202,
-0.018278274685144424,
0.008314395323395729,
-0.005469963885843754,
-0.0071924892254173756,
0.010230532847344875,
-0.0031137268524616957,
-0.0058405278250575066,
0.0025244757998734713,
0.007178898435086012,
0.001284741680137813,
-0.0002449765452183783,
-0.003671180922538042,
-0.00233612023293972,
-0.0009720117086544633,
0.0022310952190309763,
0.005569168832153082,
0.006340847350656986,
-0.0038864114321768284,
0.004711890127509832,
-0.0030872654169797897,
-0.0015941280871629715,
-0.0006870779325254261,
0.003480916377156973,
0.007533571682870388,
-0.0009060307638719678,
-0.0011109800543636084,
0.005277880467474461,
0.004776103422045708,
0.0007356294663622975,
0.009828975424170494,
0.0010217352537438273,
-0.006829822435975075,
0.007857431657612324,
0.006501005031168461,
0.000364531297236681,
0.0070366645231842995,
-0.0011023601982742548,
0.0064931148663163185,
0.0017548030009493232,
-0.007088044658303261,
-0.016910945996642113,
-0.003131047124043107,
0.0057913498021662235,
0.009778853505849838,
-0.0008846697746776044,
0.00019377282296773046,
-0.0019363381434231997,
-0.002528649754822254,
-0.005402012262493372,
-0.008033410646021366,
-0.0024322131648659706,
-0.0002490338229108602,
0.005515302065759897,
0.0676671490073204,
-0.008907632902264595,
-0.0021086011547595263,
-0.006953112315386534,
-0.0016704872250556946,
-0.0035576457157731056,
-0.0005007341969758272,
0.001738665858283639,
-0.003044361947104335,
0.000564404996111989,
0.0017270331736654043,
-0.008318583481013775,
-0.01134488359093666,
-0.0003173842269461602,
0.0000386810461350251,
-0.002648707013577223,
0.004669290967285633,
0.0067443279549479485,
-0.009875010699033737,
0.0011806318070739508,
-0.01168102864176035,
-0.0037328361067920923,
-0.0024088809732347727,
-0.011046777479350567,
-0.00338898622430861,
-0.001994787948206067,
0.006009885109961033,
0.0036684854421764612,
0.006814073771238327,
-0.003320473711937666,
0.005804723594337702,
-0.0013440947514027357,
0.000609474431257695,
-0.0047483909875154495,
-0.00004461931166588329,
-0.0039803339168429375,
0.008417616598308086,
0.002527023432776332,
-0.008302836678922176,
-0.005105033051222563,
-0.0020895772613584995,
-0.0009234636090695858,
-0.004072569310665131,
0.003043126780539751,
0.00047691859072074294,
0.005295082926750183,
-0.0022656116634607315,
-0.0017801831709221005,
-0.005423408932983875,
0.002566747134551406,
-0.012216583825647831,
0.006674407981336117,
-0.1719369739294052,
0.009273819625377655,
0.004334041848778725,
-0.005348959006369114,
-0.004564376547932625,
-0.01622670702636242,
-0.0034954766742885113,
0.004958844743669033,
0.010704693384468555,
0.002222078386694193,
-0.0007546909037046134,
-0.002568586962297559,
0.0038491827435791492,
0.004364387597888708,
-0.000990657601505518,
-0.005995667539536953,
0.0038624971639364958,
-0.004170754458755255,
-0.0001738760620355606,
0.00500198220834136,
0.003828957211226225,
0.010384125635027885,
0.0013908697292208672,
0.0015955186681821942,
-0.0021421522833406925,
-0.004058812744915485,
0.007807033136487007,
-0.0010768264764919877,
0.0036313000600785017,
-0.011170168407261372,
-0.002626734785735607,
-0.004934994503855705,
-0.006005233619362116,
0.002196247922256589,
0.006472008768469095,
-0.000206217824597843,
0.010260017588734627,
0.00351924542337656,
-0.008713762275874615,
0.0075311907567083836,
-0.009624521248042583,
0.027173016220331192,
0.00708014378324151,
0.005325081292539835,
-0.000525280658621341,
-0.006659057457000017,
-0.006058880593627691,
0.007162461522966623,
0.002191696083173156,
0.011654592119157314,
-0.012154529802501202,
-0.0020467224530875683,
0.0022565422113984823,
0.019193187355995178,
-0.005271867848932743,
-0.008052338846027851,
-0.006682435050606728,
-0.0021648702677339315,
0.0008413709583692253,
0.006369621027261019,
0.011598024517297745,
-0.002379701239988208,
0.007274949457496405,
-0.0027461613062769175,
-0.02222578413784504,
0.00517637375742197,
-0.00424169609323144,
-0.008076194673776627,
0.004664500709623098,
0.00472871121019125,
0.00920068845152855,
-0.0013063863152638078,
0.002422354416921735,
-0.0004817744193132967,
0.005121935158967972,
-0.0006001655128784478,
0.005630768835544586,
-0.001553564565256238,
0.0047247447073459625,
-0.009313980117440224,
0.007380729541182518,
-0.009832993149757385,
-0.002044781344011426,
0.0018109418451786041,
-0.003596923314034939,
0.01282113790512085,
0.004215031396597624,
-0.0010341554880142212,
0.0005667992518283427,
-0.009962367825210094,
-0.0035201602149754763,
0.0015254318714141846,
0.00046028647921048105,
-0.00958983413875103,
0.0038008037954568863,
0.0006650701398029923,
0.004588165786117315,
0.0055620018392801285,
-0.00960475206375122,
0.005925956182181835,
0.004492420703172684,
-0.004542306065559387,
-0.00021776619541924447,
-0.005303417798131704,
0.0016242758138105273,
0.0015390354674309492,
-0.005637910217046738,
-0.004194781184196472,
0.0027832272462546825,
-0.006150212604552507,
-0.0060972366482019424,
0.006154297385364771,
-0.008985349908471107,
-0.011079084128141403,
-0.0008440061355940998,
-0.011181899346411228,
0.0006884568138048053
] |
8a507bf3c4b912bd7ed181d618b52de6b0f464f2 | 3,749 | py | Python | TWLight/applications/management/commands/send_coordinator_reminders.py | nicole331/TWLight | fab9002e76868f8a2ef36f9279c777de34243b2c | [
"MIT"
] | 67 | 2017-12-14T22:27:48.000Z | 2022-03-13T18:21:31.000Z | TWLight/applications/management/commands/send_coordinator_reminders.py | nicole331/TWLight | fab9002e76868f8a2ef36f9279c777de34243b2c | [
"MIT"
] | 433 | 2017-03-24T22:51:23.000Z | 2022-03-31T19:36:22.000Z | TWLight/applications/management/commands/send_coordinator_reminders.py | Mahuton/TWLight | 90b299d07b0479f21dc90e17b8d05f5a221b0de1 | [
"MIT"
] | 105 | 2017-06-23T03:53:41.000Z | 2022-03-30T17:24:29.000Z | import logging
from collections import Counter
from django.core.management.base import BaseCommand
from django.db.models import Q
from TWLight.applications.models import Application
from TWLight.resources.models import Partner
from TWLight.applications.signals import Reminder
from TWLight.users.models import Editor
logger = logging.getLogger(__name__)
class Command(BaseCommand):
def handle(self, *args, **options):
# This is not DRY. Originally, this pulled the queryset from
# TWLight.applications.views.ListApplicationsView.get_queryset().
# But that now expects a request object. So, we did a copy/paste.
# We're actually getting apps with a status of PENDING or QUESTION
# or APPROVED, and their corresponding user preferences being True
# for partners with a status of AVAILABLE.
all_apps = (
Application.objects.filter(
Q(
partner__coordinator__editor__user__userprofile__pending_app_reminders=True
)
& Q(status=Application.PENDING)
| Q(
partner__coordinator__editor__user__userprofile__discussion_app_reminders=True
)
& Q(status=Application.QUESTION)
| Q(
partner__coordinator__editor__user__userprofile__approved_app_reminders=True
)
& Q(status=Application.APPROVED),
partner__status__in=[Partner.AVAILABLE],
editor__isnull=False,
)
.exclude(editor__user__groups__name="restricted")
.order_by("status", "partner", "date_created")
)
# A deduplicated dict of coordinators from the pending app queryset, along
# with a count of how many total pending apps they have
coordinators = Counter(
all_apps.values_list(
"partner__coordinator__editor",
"partner__coordinator__email",
"partner__coordinator__editor__user__userprofile__lang",
)
)
for coordinator, count in list(coordinators.items()):
try:
# We create a dictionary with the three status codes
# we'd want to send emails for, and their corresponding
# counts.
app_status_and_count = {
Application.PENDING: all_apps.filter(
status=Application.PENDING,
partner__coordinator__editor=coordinator[0],
).count(),
Application.QUESTION: all_apps.filter(
status=Application.QUESTION,
partner__coordinator__editor=coordinator[0],
).count(),
Application.APPROVED: all_apps.filter(
status=Application.APPROVED,
partner__coordinator__editor=coordinator[0],
).count(),
}
editor = Editor.objects.get(id=coordinator[0])
except Editor.DoesNotExist:
logger.info(
"Editor {} does not exist; skipping.".format(coordinator[0])
)
break
# Only bother with the signal if we have a coordinator email.
if coordinator[1]:
Reminder.coordinator_reminder.send(
sender=self.__class__,
app_status_and_count=app_status_and_count,
coordinator_wp_username=editor.wp_username,
coordinator_email=coordinator[1],
coordinator_lang=coordinator[2],
)
| 43.593023 | 98 | 0.584956 | 1 | 1.6461 | [
0.0021562641486525536,
0.022040847688913345,
0.009340410120785236,
0.0032322523184120655,
0.0037935872096568346,
-0.003042724449187517,
-0.007769546937197447,
0.0023307513911277056,
-0.007325411774218082,
0.0030941972509026527,
0.002369217574596405,
0.0058530340902507305,
0.006753253750503063,
-0.016623036935925484,
-0.00039576535345986485,
0.016701385378837585,
-0.05065969377756119,
0.0010552448220551014,
-0.0056400238536298275,
0.0023863217793405056,
-0.007139527704566717,
0.009199991822242737,
0.009219176135957241,
0.004542714916169643,
0.00475740060210228,
-0.0027390867471694946,
0.008578701876103878,
0.0001501943334005773,
-0.005999039392918348,
-0.006151167675852776,
0.0003710938908625394,
-0.002966495230793953,
-0.0057295565493404865,
-0.0064617665484547615,
0.005205271299928427,
-0.006322238594293594,
-0.0006852541700936854,
-0.019975697621703148,
0.012282315641641617,
-0.003997439984232187,
-0.00829590205103159,
-0.01676645129919052,
-0.0009083511540666223,
0.003801307873800397,
-0.007400857750326395,
0.0027200363110750914,
-0.004966234788298607,
0.0022999614011496305,
-0.011011469177901745,
0.006746472325176001,
-0.007929799146950245,
0.004833991639316082,
0.014491845853626728,
0.004219748545438051,
-0.005755032412707806,
-0.007839333266019821,
0.013916281051933765,
-0.0004901351640000939,
-0.010400884784758091,
0.0008416968630626798,
-0.004880118183791637,
-0.0032664702739566565,
0.0045936317183077335,
0.00030909694032743573,
-0.016564201563596725,
-0.007203365210443735,
-0.0022761118598282337,
0.003915228880941868,
0.00018893326341640204,
0.008047250099480152,
0.00037758631515316665,
-0.001726543647237122,
0.006758101284503937,
0.0047556497156620026,
0.004831149708479643,
-0.005132602993398905,
0.00043485002242960036,
-0.0010120704537257552,
0.009296126663684845,
0.003199903294444084,
0.004515862092375755,
-0.006346041336655617,
0.0071418252773582935,
0.008296952582895756,
0.012750174850225449,
0.0065184407867491245,
0.02027478627860546,
-0.010835720226168633,
0.047119494527578354,
0.008031509816646576,
-0.007198695093393326,
0.0025128712877631187,
-0.007844183593988419,
-0.0020937409717589617,
-0.007150564342737198,
-0.028087381273508072,
0.0008180916775017977,
-0.002580429194495082,
0.0002561020664870739,
0.004625548608601093,
0.0003577278694137931,
0.006773235276341438,
-0.0020082402043044567,
-0.0019803582690656185,
-0.009420176967978477,
0.012736812233924866,
-0.008807383477687836,
-0.002970216330140829,
0.004050803370773792,
0.0005910358740948141,
-0.011528946459293365,
-0.0014578565023839474,
0.0032552636694163084,
-0.013053267262876034,
0.002433260902762413,
0.0025925999507308006,
-0.006264816038310528,
0.05386433005332947,
-0.0003482602769508958,
0.0024116821587085724,
-0.005381666123867035,
0.0035487099085003138,
0.0025511770509183407,
0.007293129339814186,
0.008016902953386307,
-0.0024102560710161924,
0.012600713409483433,
0.007528902031481266,
0.00359815894626081,
0.007220760453492403,
-0.003651553299278021,
0.006898912135511637,
-0.004100537858903408,
-0.002819329034537077,
0.0015065597835928202,
-0.007262835279107094,
0.007422456983476877,
-0.0013069318374618888,
-0.009285444393754005,
0.0022265741135925055,
0.0014443427789956331,
-0.01132560521364212,
0.001196961267851293,
-0.0025622339453548193,
0.004990761633962393,
-0.010537016205489635,
-0.005734402220696211,
-0.0046262964606285095,
-0.005279600620269775,
0.0026686538476496935,
0.00941385980695486,
0.0028866776265203953,
0.003683511633425951,
-0.005274914670735598,
-0.007079898379743099,
0.0016639551613479853,
-0.0029777586460113525,
0.000674689479637891,
0.005013228859752417,
0.005060849245637655,
-0.00910228956490755,
0.001063006347976625,
0.004254686646163464,
0.003470495343208313,
-0.000938365061301738,
0.003999229054898024,
-0.009143708273768425,
0.00747661292552948,
0.00016140348452609032,
0.002807528944686055,
0.011290998198091984,
-0.004902016371488571,
-0.00015064651961438358,
-0.0019992042798548937,
0.004029301460832357,
-0.0004517177876550704,
0.00550843495875597,
0.01010941807180643,
-0.004242350813001394,
-0.00580134242773056,
0.0038170272018760443,
0.004834309685975313,
0.00874114315956831,
0.007373374421149492,
-0.0029560974799096584,
0.0026715591084212065,
-0.004654360935091972,
-0.0027848328463733196,
0.007242111023515463,
-0.005446253810077906,
0.004422713071107864,
0.0031598566565662622,
-0.012894873507320881,
-0.00865056924521923,
0.0035023547243326902,
-0.008360394276678562,
0.0017663351027294993,
0.015854153782129288,
0.010853827930986881,
-0.0043194969184696674,
0.00470657367259264,
-0.009323370642960072,
0.0036158240400254726,
0.008448188193142414,
0.002461150987073779,
-0.012401205487549305,
-0.9593784809112549,
0.007278041448444128,
0.001949421945028007,
-0.0017289327224716544,
0.005242578219622374,
0.002062014536932111,
0.0037218881770968437,
0.005908844992518425,
0.01482242252677679,
-0.008459244854748249,
-0.004723375663161278,
-0.011150545440614223,
-0.01009252667427063,
-0.0018840114353224635,
-0.009207119233906269,
-0.0018458411796018481,
-0.006665898486971855,
-0.004240140784531832,
-0.002196535002440214,
-0.0026254141703248024,
-0.002668835688382387,
0.0071041034534573555,
-0.0005177471321076155,
0.004342273809015751,
0.001650063437409699,
0.0037359579000622034,
-0.004692120011895895,
-0.0009288641740567982,
-0.0024769038427621126,
-0.0017990836640819907,
-0.008155450224876404,
-0.015591686591506004,
-0.004214219283312559,
-0.0009438625420443714,
0.009581300429999828,
-0.00015615207666996866,
0.009478196501731873,
-0.0028840270824730396,
0.0018064072355628014,
-0.010427046567201614,
0.005287791136652231,
-0.0013456151355057955,
0.0034642189275473356,
-0.028849974274635315,
0.0003620105271693319,
-0.000738120696041733,
-0.007554696407169104,
0.00770740769803524,
0.0007547666900791228,
0.0017363561782985926,
-0.004107262473553419,
-0.004269808065146208,
0.008320746012032032,
-0.006127572618424892,
0.004630412440747023,
-0.004262348171323538,
-0.00809580460190773,
-0.0023398660123348236,
-0.008480134420096874,
0.0010370509698987007,
0.006787184625864029,
-0.0038164197467267513,
-0.004036851692944765,
-0.0035736304707825184,
0.0004735269758384675,
0.0016712169162929058,
0.0023507578298449516,
-0.01816367730498314,
-0.00969191174954176,
-0.0008715944713912904,
0.0002916328376159072,
-0.004868508782237768,
-0.0038094015326350927,
0.004841355141252279,
-0.009597914293408394,
0.006878741085529327,
0.0016811747336760163,
-0.0010990073205903172,
-0.010423014871776104,
0.0008933480712585151,
-0.008530187420547009,
-0.008943966589868069,
0.0014383969828486443,
-0.007919213734567165,
-0.0059905811212956905,
-0.002424292964860797,
0.001022299868054688,
0.00855990219861269,
-0.0036883761640638113,
0.005262827035039663,
0.011271540075540543,
-0.0032281028106808662,
-0.00797413382679224,
0.006322252564132214,
0.006218149326741695,
-0.000050192589696962386,
-0.0020325323566794395,
0.003147583920508623,
0.008180176839232445,
0.005568048916757107,
0.0010627900483086705,
0.005725134629756212,
0.00098570273257792,
0.009326154366135597,
-0.0034951812122017145,
0.001351809361949563,
-0.005843191407620907,
-0.00004060220453538932,
-0.004286113195121288,
0.0004890713025815785,
-0.003987591713666916,
-0.0027291192673146725,
-0.013584188185632229,
-0.008265715092420578,
-0.002665133448317647,
-0.0017187660560011864,
0.004505307879298925,
-0.005075534805655479,
0.000650764093734324,
0.002923213876783848,
0.008273568004369736,
0.0017050206661224365,
-0.0015484149334952235,
0.00043541230843402445,
0.002245360054075718,
-0.0063691530376672745,
0.01601438783109188,
-0.010669762268662453,
0.0057169473730027676,
-0.0020550191402435303,
-0.01554617565125227,
0.007010349538177252,
0.009731762111186981,
-0.009100421331822872,
0.0017728533130139112,
0.003945815842598677,
0.003223587293177843,
-0.0023640012368559837,
-0.005338543560355902,
-0.004408522043377161,
-0.016535313799977303,
-0.0011673056287690997,
0.018635695800185204,
0.0009620906785130501,
0.010816729627549648,
0.011300230398774147,
-0.0019418691517785192,
0.0003790369664784521,
0.004764086566865444,
0.0007353863911703229,
0.012765997089445591,
-0.009452392347157001,
-0.001654868945479393,
0.0016409899108111858,
-0.00544119393453002,
0.0013721458381041884,
0.005791659466922283,
0.005344640463590622,
-0.0028956690803170204,
0.002320261672139168,
-0.007521139457821846,
-0.005177878774702549,
-0.01759129948914051,
-0.0036169167142361403,
0.011891947127878666,
-0.0057007139548659325,
0.006361374165862799,
-0.010532904416322708,
0.007157285697758198,
0.005399215500801802,
0.0037163926754146814,
-0.0003447882190812379,
0.0011354007292538881,
0.006848755292594433,
0.011696111410856247,
-0.004405052401125431,
0.003908820915967226,
0.0020164819434285164,
0.00016793228860478848,
0.0005414515035226941,
0.009012495167553425,
-0.007670267019420862,
-0.005379426293075085,
0.0037410922814160585,
0.0041707721538841724,
-0.0009492128738202155,
-0.004170969128608704,
-0.008300707675516605,
-0.0014999224804341793,
0.0014545456506311893,
-0.004317345563322306,
0.00376464007422328,
0.0021918732672929764,
0.004139818251132965,
-0.006120532285422087,
0.0008070414187386632,
-0.002158678136765957,
-0.012386894784867764,
0.01063599158078432,
-0.0019427851075306535,
0.0010914952727034688,
0.01137014664709568,
0.004190288484096527,
-0.013501611538231373,
0.006558443419635296,
0.009962939657270908,
-0.0038628880865871906,
0.0045555392280220985,
0.00617889454588294,
-0.0060592032968997955,
-0.021302418783307076,
-0.0030661756172776222,
-0.014922890812158585,
0.0056234137155115604,
-0.0032342830672860146,
0.004645130597054958,
-0.006546392105519772,
0.00539642246440053,
0.005329625215381384,
-0.015008860267698765,
-0.00626965519040823,
-0.007929309271275997,
0.010968837887048721,
-0.0011451903264969587,
-0.0003663951647467911,
-0.003873072564601898,
-0.00018803964485414326,
-0.0021091820672154427,
-0.0033129286020994186,
-0.0024481338914483786,
0.006297810468822718,
0.001212127972394228,
-0.0038801850751042366,
0.0018667628755792975,
-0.005460419692099094,
0.0019547471310943365,
0.00217814720235765,
-0.009516860358417034,
0.0024429617915302515,
0.002679644152522087,
-0.0025804273318499327,
-0.004450872074812651,
0.0018081675516441464,
0.000060568589105969295,
-0.007879262790083885,
-0.013173457235097885,
-0.004882263019680977,
-0.0030982005409896374,
-0.003996301908046007,
-0.011904900893568993,
-0.0014054689090698957,
-0.008500698022544384,
0.0028715827502310276,
-0.0074684214778244495,
0.0072115762159228325,
0.004835799336433411,
-0.0061714970506727695,
0.007898213341832161,
-0.0009228144772350788,
0.004537978675216436,
0.0042145149782299995,
0.006436638999730349,
0.0015859237173572183,
-0.003779913764446974,
-0.012994829565286636,
0.012260335497558117,
-0.00757560133934021,
0.0008407523855566978,
0.013469352386891842,
0.005057447589933872,
0.009598555974662304,
-0.0010776951676234603,
0.0007733596139587462,
0.0009075469570234418,
0.007008705288171768,
-0.015867924317717552,
0.0037175347097218037,
-0.002901766449213028,
0.0010046366369351745,
0.00324059184640646,
-0.0030274423770606518,
0.0020527425222098827,
0.009214307181537151,
0.0030247564427554607,
-0.008840011432766914,
-0.003619201248511672,
0.0022112273145467043,
0.0036851821932941675,
-0.01196657307446003,
0.0003938358277082443,
-0.004511423408985138,
-0.00463067227974534,
-0.003921225666999817,
-0.004482466261833906,
-0.0016377985011786222,
0.004794255364686251,
-0.002376360585913062,
0.0060042389668524265,
0.003514325013384223,
-0.006363641936331987,
0.01575293578207493,
-0.006389791611582041,
-0.004659400321543217,
0.003059340873733163,
0.003175256075337529,
-0.0032271482050418854,
-0.006253511644899845,
-0.0029486713465303183,
0.004626256879419088,
0.005282955709844828,
-0.0019565606489777565,
-0.005918989423662424,
0.0020426760893315077,
-0.0006287478609010577,
-0.010827389545738697,
0.001147424103692174,
0.009416659362614155,
-0.0014766809763386846,
0.005562749691307545,
-0.0024637992028146982,
-0.008868136443197727,
-0.014686011709272861,
0.053958408534526825,
-0.0002535508538130671,
0.004128042608499527,
0.0041692908853292465,
-0.005993816070258617,
-0.0016071522841230035,
-0.0022669993340969086,
0.006915222387760878,
-0.006609599571675062,
-0.007020394783467054,
0.007147152442485094,
-0.003006498795002699,
0.003260789206251502,
0.0028119729831814766,
-0.0013660024851560593,
0.016773050650954247,
-0.0027499389834702015,
-0.01625165157020092,
-0.017600128427147865,
0.008412960916757584,
-0.004603052511811256,
-0.009088648483157158,
0.010824790224432945,
-0.0013598836958408356,
-0.004669239744544029,
0.0027200053445994854,
0.006220084615051746,
0.0035042348317801952,
0.00030552808311767876,
-0.0029672712553292513,
-0.0009848728077486157,
-0.0006588493124581873,
0.0032586168963462114,
0.004120472818613052,
0.006915159057825804,
-0.0024531097151339054,
0.005896586459130049,
-0.002492718631401658,
-0.0025178014766424894,
-0.001292186789214611,
0.005185389891266823,
0.006894524209201336,
-0.0017820148495957255,
-0.001614073640666902,
0.0032200077548623085,
0.005791161209344864,
0.0010097253834828734,
0.009989170357584953,
-0.0003673087921924889,
-0.006566134747117758,
0.007231632713228464,
0.008327159099280834,
0.00038536658394150436,
0.00867229513823986,
0.0008120666607283056,
0.004952473100274801,
0.001964722527191043,
-0.0073615787550807,
-0.016906943172216415,
-0.003712377045303583,
0.007488218601793051,
0.007878206670284271,
-0.002146871527656913,
0.0012657643528655171,
-0.004328373819589615,
-0.00231269677169621,
-0.007774568162858486,
-0.006910677067935467,
-0.00299681699834764,
0.002490472048521042,
0.0034946149680763483,
0.07036340981721878,
-0.007118504494428635,
-0.002281747292727232,
-0.007803366519510746,
-0.0006591812707483768,
-0.002157136332243681,
0.0008164257742464542,
0.0025544126983731985,
-0.0027801436372101307,
0.001509284833446145,
0.0010250104824081063,
-0.004995736759155989,
-0.01165760774165392,
-0.0007381223258562386,
0.0016567438142374158,
-0.0029207293409854174,
0.0022858872544020414,
0.006985930260270834,
-0.010526127181947231,
0.00015078276919666678,
-0.011500593274831772,
-0.004125481937080622,
-0.002334398217499256,
-0.009266955778002739,
-0.0018725305562838912,
-0.0029459293000400066,
0.0043311286717653275,
0.0039464496076107025,
0.006877969019114971,
-0.003159887157380581,
0.0065842317417263985,
-0.001909936312586069,
-0.0007022586651146412,
-0.004465682432055473,
-0.00016245401639025658,
-0.00484430743381381,
0.006794350687414408,
0.0001616223598830402,
-0.008877082727849483,
-0.0052262479439377785,
-0.0010436564916744828,
0.0015172112034633756,
-0.0069687156938016415,
0.00274099363014102,
-0.0000020565057639032602,
0.004978484474122524,
-0.0037561345379799604,
-0.000619723869021982,
-0.007049120031297207,
0.0035206153988838196,
-0.013434574007987976,
0.006999590899795294,
-0.16924317181110382,
0.009797430597245693,
0.005052637308835983,
-0.00662835780531168,
-0.0028519127517938614,
-0.015721501782536507,
-0.004691296722739935,
0.0046717883087694645,
0.010948164388537407,
0.0014626617776229978,
-0.002448843326419592,
-0.0005068590980954468,
0.004065836779773235,
0.003653935855254531,
-0.0028499909676611423,
-0.00516774645075202,
0.0022684214636683464,
-0.004286209587007761,
-0.00009390492778038606,
0.004425933584570885,
0.004186825826764107,
0.009556816890835762,
0.0012764502316713333,
0.0010756265837699175,
-0.0010845675133168697,
-0.003931380808353424,
0.006440858356654644,
-0.0047054230235517025,
0.004495848901569843,
-0.01228100061416626,
-0.002077857730910182,
-0.0036241826601326466,
-0.0036863686982542276,
0.0017810999415814877,
0.004714084789156914,
-0.0006631211726926267,
0.009522991254925728,
0.001930423197336495,
-0.008617417886853218,
0.010420531965792179,
-0.008808465674519539,
0.027335500344634056,
0.007812393829226494,
0.006618163548409939,
0.00019318006525281817,
-0.006938539911061525,
-0.005469240248203278,
0.008598786778748035,
0.0019282501889392734,
0.012612607330083847,
-0.01303666178137064,
0.00004696861287811771,
0.005318973679095507,
0.01720592938363552,
-0.006616909522563219,
-0.010500811971724033,
-0.006025828421115875,
-0.0030834146309643984,
0.0014005841221660376,
0.00756486039608717,
0.008988032117486,
-0.00406359788030386,
0.009150948375463486,
-0.0030242041684687138,
-0.021014787256717682,
0.0023419850040227175,
-0.0034492930863052607,
-0.00721305888146162,
0.002329431939870119,
0.007654968183487654,
0.009976617991924286,
-0.00033833878114819527,
0.0033018402755260468,
-0.00016658869571983814,
0.006452704779803753,
0.0007677911780774593,
0.007918690331280231,
-0.001831340603530407,
0.0063488781452178955,
-0.009267283603549004,
0.00580639997497201,
-0.009594130329787731,
-0.002265054965391755,
0.002171556930989027,
-0.003252186579629779,
0.01143608521670103,
0.003742442699149251,
-0.0016607604920864105,
-0.000714017660357058,
-0.009328318759799004,
-0.000695250928401947,
0.0024944066535681486,
0.0015627273824065924,
-0.006748293060809374,
0.0027381640393286943,
-0.00004624988287105225,
0.0044725751504302025,
0.006518200039863586,
-0.010716961696743965,
0.0072740595787763596,
0.0055225919932127,
-0.0047669075429439545,
0.00008249873644672334,
-0.005687265191227198,
0.0032075117342174053,
0.003832724643871188,
-0.005637050606310368,
-0.0049887471832334995,
0.002750885207206011,
-0.005355669651180506,
-0.004162375815212727,
0.006064225919544697,
-0.008410838432610035,
-0.010874386876821518,
-0.0024631137493997812,
-0.01012843381613493,
0.00014830692089162767
] |
8a509772d4b71309e020c912aabb38728c706128 | 15,176 | py | Python | python/3D-rrt/pvtrace/LightSources.py | rapattack88/mcclanahoochie | 6df72553ba954b52e949a6847a213b22f9e90157 | [
"Apache-2.0"
] | 1 | 2020-12-27T21:37:35.000Z | 2020-12-27T21:37:35.000Z | python/3D-rrt/pvtrace/LightSources.py | rapattack88/mcclanahoochie | 6df72553ba954b52e949a6847a213b22f9e90157 | [
"Apache-2.0"
] | null | null | null | python/3D-rrt/pvtrace/LightSources.py | rapattack88/mcclanahoochie | 6df72553ba954b52e949a6847a213b22f9e90157 | [
"Apache-2.0"
] | null | null | null | # pvtrace 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.
#
# pvtrace 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 numpy as np
from external.transformations import translation_matrix, rotation_matrix
import external.transformations as tf
from Trace import Photon
from Geometry import Box, Cylinder, FinitePlane, transform_point, transform_direction, rotation_matrix_from_vector_alignment, norm
from Materials import Spectrum
def random_spherecial_vector():
# This method of calculating isotropic vectors is taken from GNU Scientific Library
LOOP = True
while LOOP:
x = -1. + 2. * np.random.uniform()
y = -1. + 2. * np.random.uniform()
s = x**2 + y**2
if s <= 1.0:
LOOP = False
z = -1. + 2. * s
a = 2 * np.sqrt(1 - s)
x = a * x
y = a * y
return np.array([x,y,z])
class SimpleSource(object):
"""A light source that will generate photons of a single colour, direction and position."""
def __init__(self, position=[0,0,0], direction=[0,0,1], wavelength=555, use_random_polarisation=False):
super(SimpleSource, self).__init__()
self.position = position
self.direction = direction
self.wavelength = wavelength
self.use_random_polarisation = use_random_polarisation
self.throw = 0
self.source_id = "SimpleSource_" + str(id(self))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.position = np.array(self.position)
photon.direction = np.array(self.direction)
photon.active = True
photon.wavelength = self.wavelength
# If use_polarisation is set generate a random polarisation vector of the photon
if self.use_random_polarisation:
# Randomise rotation angle around xy-plane, the transform from +z to the direction of the photon
vec = random_spherecial_vector()
vec[2] = 0.
vec = norm(vec)
R = rotation_matrix_from_vector_alignment(self.direction, [0,0,1])
photon.polarisation = transform_direction(vec, R)
else:
photon.polarisation = None
photon.id = self.throw
self.throw = self.throw + 1
return photon
class Laser(object):
"""A light source that will generate photons of a single colour, direction and position."""
def __init__(self, position=[0,0,0], direction=[0,0,1], wavelength=555, polarisation=None):
super(Laser, self).__init__()
self.position = np.array(position)
self.direction = np.array(direction)
self.wavelength = wavelength
assert polarisation != None, "Polarisation of the Laser is not set."
self.polarisation = np.array(polarisation)
self.throw = 0
self.source_id = "LaserSource_" + str(id(self))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.position = np.array(self.position)
photon.direction = np.array(self.direction)
photon.active = True
photon.wavelength = self.wavelength
photon.polarisation = self.polarisation
photon.id = self.throw
self.throw = self.throw + 1
return photon
class PlanarSource(object):
"""A box that emits photons from the top surface (normal), sampled from the spectrum."""
def __init__(self, spectrum=None, wavelength=555, direction=(0,0,1), length=0.05, width=0.05):
super(PlanarSource, self).__init__()
self.spectrum = spectrum
self.wavelength = wavelength
self.plane = FinitePlane(length=length, width=width)
self.length = length
self.width = width
# direction is the direction that photons are fired out of the plane in the GLOBAL FRAME.
# i.e. this is passed directly to the photon to set is's direction
self.direction = direction
self.throw = 0
self.source_id = "PlanarSource_" + str(id(self))
def translate(self, translation):
self.plane.append_transform(tf.translation_matrix(translation))
def rotate(self, angle, axis):
self.plane.append_transform(tf.rotation_matrix(angle, axis))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.id = self.throw
self.throw = self.throw + 1
# Create a point which is on the surface of the finite plane in it's local frame
x = np.random.uniform(0., self.length)
y = np.random.uniform(0., self.width)
local_point = (x, y, 0.)
# Transform the direciton
photon.position = transform_point(local_point, self.plane.transform)
photon.direction = self.direction
photon.active = True
if self.spectrum != None:
photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
else:
photon.wavelength = self.wavelength
return photon
class LensSource(object):
"""
A source where photons generated in a plane are focused on a line with space tolerance given by variable "focussize".
The focus line should be perpendicular to the plane normal and aligned with the z-axis.
"""
def __init__(self, spectrum = None, wavelength = 555, linepoint=(0,0,0), linedirection=(0,0,1), focussize = 0, planeorigin = (-1,-1,-1), planeextent = (-1,1,1)):
super(LensSource, self).__init__()
self.spectrum = spectrum
self.wavelength = wavelength
self.planeorigin = planeorigin
self.planeextent = planeextent
self.linepoint = np.array(linepoint)
self.linedirection = np.array(linedirection)
self.focussize = focussize
self.throw = 0
self.source_id = "LensSource_" + str(id(self))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.id = self.throw
self.throw = self.throw + 1
# Position
x = np.random.uniform(self.planeorigin[0],self.planeextent[0])
y = np.random.uniform(self.planeorigin[1],self.planeextent[1])
z = np.random.uniform(self.planeorigin[2],self.planeextent[2])
photon.position = np.array((x,y,z))
# Direction
focuspoint = np.array((0.,0.,0.))
focuspoint[0] = self.linepoint[0] + np.random.uniform(-self.focussize,self.focussize)
focuspoint[1] = self.linepoint[1] + np.random.uniform(-self.focussize,self.focussize)
focuspoint[2] = photon.position[2]
direction = focuspoint - photon.position
modulus = (direction[0]**2+direction[1]**2+direction[2]**2)**0.5
photon.direction = direction/modulus
# Wavelength
if self.spectrum != None:
photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
else:
photon.wavelength = self.wavelength
return photon
class LensSourceAngle(object):
"""
A source where photons generated in a plane are focused on a line with space tolerance given by variable "focussize".
The focus line should be perpendicular to the plane normal and aligned with the z-axis.
For this lense an additional z-boost is added (Angle of incidence in z-direction).
"""
def __init__(self, spectrum = None, wavelength = 555, linepoint=(0,0,0), linedirection=(0,0,1), angle = 0, focussize = 0, planeorigin = (-1,-1,-1), planeextent = (-1,1,1)):
super(LensSourceAngle, self).__init__()
self.spectrum = spectrum
self.wavelength = wavelength
self.planeorigin = planeorigin
self.planeextent = planeextent
self.linepoint = np.array(linepoint)
self.linedirection = np.array(linedirection)
self.focussize = focussize
self.angle = angle
self.throw = 0
self.source_id = "LensSourceAngle_" + str(id(self))
def photon(self):
photon = Photon()
photon.id = self.throw
self.throw = self.throw + 1
# Position
x = np.random.uniform(self.planeorigin[0],self.planeextent[0])
y = np.random.uniform(self.planeorigin[1],self.planeextent[1])
boost = y*np.tan(self.angle)
z = np.random.uniform(self.planeorigin[2],self.planeextent[2]) - boost
photon.position = np.array((x,y,z))
# Direction
focuspoint = np.array((0.,0.,0.))
focuspoint[0] = self.linepoint[0] + np.random.uniform(-self.focussize,self.focussize)
focuspoint[1] = self.linepoint[1] + np.random.uniform(-self.focussize,self.focussize)
focuspoint[2] = photon.position[2] + boost
direction = focuspoint - photon.position
modulus = (direction[0]**2+direction[1]**2+direction[2]**2)**0.5
photon.direction = direction/modulus
# Wavelength
if self.spectrum != None:
photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
else:
photon.wavelength = self.wavelength
return photon
class CylindricalSource(object):
"""
A source for photons emitted in a random direction and position inside a cylinder(radius, length)
"""
def __init__(self, spectrum = None, wavelength = 555, radius = 1, length = 10):
super(CylindricalSource, self).__init__()
self.spectrum = spectrum
self.wavelength = wavelength
self.shape = Cylinder(radius = radius, length = length)
self.radius = radius
self.length = length
self.throw = 0
self.source_id = "CylindricalSource_" + str(id(self))
def translate(self, translation):
self.shape.append_transform(tf.translation_matrix(translation))
def rotate(self, angle, axis):
self.shape.append_transform(tf.rotation_matrix(angle, axis))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.id = self.throw
self.throw = self.throw + 1
# Position of emission
phi = np.random.uniform(0., 2*np.pi)
r = np.random.uniform(0.,self.radius)
x = r*np.cos(phi)
y = r*np.sin(phi)
z = np.random.uniform(0.,self.length)
local_center = (x,y,z)
photon.position = transform_point(local_center, self.shape.transform)
# Direction of emission (no need to transform if meant to be isotropic)
phi = np.random.uniform(0.,2*np.pi)
theta = np.random.uniform(0.,np.pi)
x = np.cos(phi)*np.sin(theta)
y = np.sin(phi)*np.sin(theta)
z = np.cos(theta)
local_direction = (x,y,z)
photon.direction = local_direction
# Set wavelength of photon
if self.spectrum != None:
photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
else:
photon.wavelength = self.wavelength
# Further initialisation
photon.active = True
return photon
class PointSource(object):
"""
A point source that emits randomly in solid angle specified by phimin, ..., thetamax
"""
def __init__(self, spectrum = None, wavelength = 555, center = (0.,0.,0.), phimin = 0, phimax = 2*np.pi, thetamin = 0, thetamax = np.pi):
super(PointSource, self).__init__()
self.spectrum = spectrum
self.wavelength = wavelength
self.center = center
self.phimin = phimin
self.phimax = phimax
self.thetamin = thetamin
self.thetamax = thetamax
self.throw = 0
self.source_id = "PointSource_" + str(id(self))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.id = self.throw
self.throw = self.throw + 1
phi = np.random.uniform(self.phimin, self.phimax)
theta = np.random.uniform(self.thetamin, self.thetamax)
x = np.cos(phi)*np.sin(theta)
y = np.sin(phi)*np.sin(theta)
z = np.cos(theta)
direction = (x,y,z)
transform = tf.translation_matrix((0,0,0))
point = transform_point(self.center, transform)
photon.direction = direction
photon.position = point
if self.spectrum != None:
photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
else:
photon.wavelength = self.wavelength
photon.active = True
return photon
class RadialSource(object):
"""
A point source that emits at discrete angles theta(i) and phi(i)
"""
def __init__(self, spectrum = None, wavelength = 555, center = (0.,0.,0.), phimin = 0, phimax = 2*np.pi, thetamin = 0, thetamax = np.pi, spacing=20):
super(RadialSource, self).__init__()
self.spectrum = spectrum
self.wavelength = wavelength
self.center = center
self.phimin = phimin
self.phimax = phimax
self.thetamin = thetamin
self.thetamax = thetamax
self.spacing = spacing
self.throw = 0
self.source_id = "RadialSource_" + str(id(self))
def photon(self):
photon = Photon()
photon.source = self.source_id
photon.id = self.throw
self.throw = self.throw + 1
intphi = np.random.randint(1, self.spacing+1)
inttheta = np.random.randint(1, self.spacing+1)
phi = intphi*(self.phimax-self.phimin)/self.spacing
if self.thetamin == self.thetamax:
theta = self.thetamin
else:
theta = inttheta*(self.thetamax-self.thetamin)/self.spacing
x = np.cos(phi)*np.sin(theta)
y = np.sin(phi)*np.sin(theta)
z = np.cos(theta)
direction = (x,y,z)
transform = tf.translation_matrix((0,0,0))
point = transform_point(self.center, transform)
photon.direction = direction
photon.position = point
if self.spectrum != None:
photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
else:
photon.wavelength = self.wavelength
photon.active = True
return photon
| 38.035088 | 176 | 0.61136 | 1 | 2.0061 | [
-0.0371338352560997,
0.06081198900938034,
0.029416486620903015,
0.042657271027565,
-0.04472101107239723,
-0.0061302389949560165,
-0.0017170949140563607,
-0.029410220682621002,
-0.03514431416988373,
-0.015377513132989407,
0.017693419009447098,
0.009808170609176159,
0.04285237938165665,
-0.035055577754974365,
-0.021607091650366783,
0.017512638121843338,
0.06767438352108002,
0.027488071471452713,
-0.03835659846663475,
0.0029012940358370543,
0.001999101834371686,
0.011749745346605778,
-0.010304698720574379,
-0.0005857566138729453,
-0.025480162352323532,
-0.04120045155286789,
0.0159249696880579,
-0.0067541650496423244,
-0.0182819701731205,
-0.021990636363625526,
-0.01199446152895689,
-0.013448875397443771,
-0.021033987402915955,
0.029629413038492203,
-0.036010969430208206,
0.00721155246719718,
0.026004202663898468,
-0.05083388090133667,
-0.008080996572971344,
-0.010591955855488777,
0.0006599935586564243,
0.03815028816461563,
0.009839423932135105,
-0.00840839371085167,
0.023003600537776947,
0.031253647059202194,
-0.018952911719679832,
0.028464369475841522,
0.01354895904660225,
0.026231752708554268,
0.031054046005010605,
0.021403513848781586,
-0.028691496700048447,
0.020154578611254692,
0.01908513531088829,
-0.03198286518454552,
0.011207357980310917,
-0.0033015941735357046,
0.00824018009006977,
-0.003097368171438575,
-0.015360219404101372,
0.012416433542966843,
0.016199083998799324,
0.0344279445707798,
-0.0022261161357164383,
-0.003923818469047546,
0.02823485992848873,
-0.007958032190799713,
-0.012168836779892445,
-0.025421788915991783,
-0.028397632762789726,
-0.01941937394440174,
0.03262250870466232,
0.05157804489135742,
-0.023237839341163635,
0.0012990887043997645,
-0.05249462276697159,
0.027643758803606033,
-0.018978862091898918,
-0.00554412417113781,
0.0007897428004071116,
0.05252150073647499,
-0.01058319304138422,
0.025762148201465607,
-0.029563793912529945,
0.03594110906124115,
0.0434906966984272,
-0.04666437581181526,
0.0697484090924263,
0.020121829584240913,
-0.04643793776631355,
0.011147896759212017,
-0.023430418223142624,
-0.008538800291717052,
-0.022258272394537926,
-0.027406543493270874,
-0.009463080205023289,
-0.02505550906062126,
-0.01837640069425106,
-0.015037625096738338,
0.026949971914291382,
0.03647071495652199,
0.04063946753740311,
-0.03916550055146217,
-0.005552212707698345,
0.04925648868083954,
-0.04108255356550217,
0.02134619653224945,
0.01930866204202175,
-0.0321904793381691,
-0.047526389360427856,
-0.05820981413125992,
0.0145133500918746,
-0.01541692391037941,
-0.04583090916275978,
-0.03275047242641449,
-0.010613048449158669,
-0.00150672672316432,
-0.005158436484634876,
0.020861651748418808,
-0.032538384199142456,
0.0025100880302488804,
0.024193115532398224,
0.014878993853926659,
-0.040120575577020645,
0.06452380865812302,
0.013017152436077595,
0.01773855648934841,
-0.01352609135210514,
0.03026505932211876,
-0.03455377742648125,
-0.01672593504190445,
-0.018683020025491714,
-0.020512117072939873,
0.014311783015727997,
0.02852913923561573,
0.0011201576562598348,
0.014641876332461834,
-0.04891068488359451,
0.03349319472908974,
-0.008383079431951046,
-0.06504293531179428,
0.023086827248334885,
-0.0597747303545475,
0.013299200683832169,
-0.012109817005693913,
-0.016744811087846756,
-0.012714602053165436,
0.028648938983678818,
0.0005865379935130477,
0.0122015830129385,
-0.0012495816918089986,
-0.0020209362264722586,
0.040551260113716125,
-0.013277263380587101,
-0.023214958608150482,
0.017682965844869614,
-0.02852066047489643,
0.004928543698042631,
-0.01664905622601509,
-0.024679001420736313,
0.01623765006661415,
0.009557869285345078,
-0.016686247661709785,
-0.03963562101125717,
-0.002721915254369378,
-0.012865091674029827,
0.006200236268341541,
-0.012207340449094772,
-0.0005923215067014098,
-0.001510176225565374,
0.009054732508957386,
-0.0019170284504070878,
-0.018056904897093773,
-0.07179366797208786,
0.026069849729537964,
-0.005960692651569843,
-0.005646707955747843,
0.030389901250600815,
-0.011478469707071781,
0.0022507919929921627,
0.01079908199608326,
0.042208876460790634,
0.036183834075927734,
0.015859363600611687,
-0.007119548972696066,
-0.029191123321652412,
0.03266653046011925,
-0.010611804202198982,
0.00835100281983614,
-0.014489357359707355,
0.0563238263130188,
-0.023095905780792236,
0.007025009952485561,
-0.005171702243387699,
0.02467719465494156,
0.002166231395676732,
-0.008557259105145931,
-0.014687575399875641,
0.05593238025903702,
0.004040553700178862,
-0.007157529704272747,
-0.003099763533100486,
0.013716801069676876,
0.02107408456504345,
-0.0061111184768378735,
-0.7122862935066223,
-0.004463553428649902,
0.05217913165688515,
0.0054582213051617146,
0.02199169062077999,
0.02178380638360977,
-0.041207000613212585,
-0.02580854669213295,
-0.04153573885560036,
-0.03436805307865143,
-0.0084530645981431,
0.00970243476331234,
-0.07196135818958282,
-0.02732374519109726,
0.04313630610704422,
-0.033014364540576935,
-0.006472586188465357,
-0.015221224166452885,
0.01798824407160282,
-0.0007365513010881841,
-0.032260432839393616,
0.05328672006726265,
-0.009723558090627193,
-0.006029867101460695,
0.012051062658429146,
-0.004933489486575127,
-0.0029832436703145504,
0.0204597320407629,
0.03085230477154255,
-0.007601470220834017,
0.027125263586640358,
0.008652981370687485,
-0.016455888748168945,
0.007686536759138107,
-0.0015285116387531161,
0.017469050362706184,
0.034462280571460724,
-0.00861748680472374,
0.031034596264362335,
-0.015851128846406937,
-0.01039001066237688,
0.0050471448339521885,
-0.012608903460204601,
-0.05851215496659279,
-0.0029823884833604097,
-0.05915694311261177,
-0.060311682522296906,
0.017177730798721313,
-0.013160845264792442,
-0.0006581862107850611,
-0.03837793692946434,
0.03677817061543465,
0.0231166984885931,
-0.035200927406549454,
0.0007420245092362165,
-0.0008181626908481121,
0.0011350791901350021,
0.0023433382157236338,
0.01735796220600605,
-0.011137702502310276,
0.04701591283082962,
0.02984975278377533,
-0.000630741473287344,
0.000587634916882962,
0.003013611538335681,
0.02296699956059456,
-0.008721149526536465,
-0.07319731265306473,
-0.025058746337890625,
0.016630616039037704,
-0.014714926481246948,
0.012704460881650448,
-0.008090250194072723,
0.02595052495598793,
-0.020518768578767776,
0.02676723338663578,
-0.04670895263552666,
-0.013747486285865307,
-0.05071904882788658,
-0.013757779262959957,
0.03495949134230614,
-0.019933192059397697,
-0.014301293529570103,
-0.02886909991502762,
-0.0018555588321760297,
-0.009240686893463135,
0.0026230269577354193,
-0.016738861799240112,
-0.009258920326828957,
0.011116530746221542,
0.06481916457414627,
0.0061545586213469505,
0.02207260951399803,
-0.005790409166365862,
-0.0020190048962831497,
-0.012546386569738388,
0.020037006586790085,
0.0315965972840786,
0.035556260496377945,
0.036895159631967545,
-0.027008485049009323,
0.024513984099030495,
-0.01744680106639862,
0.022213343530893326,
0.03207973390817642,
0.002624722197651863,
-0.023464376106858253,
0.023472338914871216,
0.06444600224494934,
-0.012002227827906609,
-0.034559983760118484,
-0.015591627918183804,
-0.014671891927719116,
-0.006806442514061928,
-0.03085862286388874,
-0.018019452691078186,
-0.003191376570612192,
-0.014762163162231445,
0.010431564413011074,
0.0025926504749804735,
0.024433115497231483,
0.03025973215699196,
-0.003102715592831373,
-0.03173933923244476,
-0.01835671439766884,
-0.0022213158663362265,
-0.007958331145346165,
-0.005017327144742012,
-0.008965237997472286,
0.05247778072953224,
-0.023671535775065422,
-0.03131949156522751,
-0.045764900743961334,
0.015302354469895363,
0.008681094273924828,
0.000371172180166468,
-0.021795175969600677,
-0.03583017736673355,
-0.005608942359685898,
0.016580156981945038,
0.01242317445576191,
0.019757071509957314,
0.03937036544084549,
-0.05811546742916107,
0.014916935935616493,
0.01864817552268505,
0.028940469026565552,
-0.011190677992999554,
0.06620372086763382,
0.020406179130077362,
-0.017000705003738403,
0.018786968663334846,
-0.011728937737643719,
-0.01749514974653721,
-0.042310792952775955,
-0.0015186492819339037,
-0.015613463707268238,
0.010739481076598167,
-0.0036833644844591618,
0.030894046649336815,
-0.03352691978216171,
0.01361009944230318,
0.0448530837893486,
0.01482710987329483,
-0.007142999209463596,
-0.014216243289411068,
0.01740012690424919,
-0.004177634138613939,
0.009199007414281368,
-0.015080778859555721,
0.00407610647380352,
-0.006594137754291296,
0.037191376090049744,
-0.028187794610857964,
-0.048438988626003265,
-0.0022869021631777287,
-0.01734527014195919,
-0.007843077182769775,
-0.02114654704928398,
-0.01707792840898037,
-0.06829622387886047,
0.002971585374325514,
0.01145168673247099,
-0.03741734102368355,
-0.014735094271600246,
-0.0031687456648796797,
0.00036147955688647926,
-0.005271002650260925,
0.04678964614868164,
-0.01211380586028099,
0.0015289154835045338,
0.030002709478139877,
-0.018898971378803253,
0.0018184793880209327,
-0.03373030573129654,
-0.029140526428818703,
-0.01641586609184742,
0.002189930295571685,
0.009136942215263844,
-0.04152701422572136,
0.03758075088262558,
0.03956374153494835,
0.0022211929317563772,
-0.012437199242413044,
0.011563288047909737,
0.025887107476592064,
-0.02864737994968891,
-0.05710526183247566,
0.03633960708975792,
-0.025853894650936127,
0.011628327891230583,
-0.015806373208761215,
0.01979488506913185,
-0.013563590124249458,
-0.0028482067864388227,
0.016405045986175537,
-0.03637263551354408,
-0.011650145053863525,
-0.055866509675979614,
-0.05798967927694321,
0.015437962487339973,
0.01128935907036066,
0.04081830009818077,
0.008038097992539406,
0.013100603595376015,
0.00564961601048708,
-0.011338677257299423,
0.005917096044868231,
0.001054007443599403,
-0.0041511147283017635,
0.027617957442998886,
0.005299339070916176,
0.03198911249637604,
-0.015072980895638466,
-0.007844153791666031,
0.030472226440906525,
-0.01107723731547594,
-0.03470342978835106,
-0.01110819075256586,
-0.00469930050894618,
-0.017046606168150902,
0.002102472586557269,
-0.024586621671915054,
0.028293708339333534,
0.006783962249755859,
0.0173574760556221,
0.022865697741508484,
-0.01557349506765604,
0.0003009876818396151,
-0.02000192552804947,
-0.02966192364692688,
-0.006027829833328724,
0.0060665300115942955,
0.010068459436297417,
0.03872479498386383,
-0.012103508226573467,
-0.02419511415064335,
-0.004575421568006277,
0.02230900153517723,
0.00803685374557972,
-0.030745821073651314,
-0.006672772578895092,
-0.02042245678603649,
-0.018194502219557762,
-0.010302335023880005,
0.013157500885426998,
0.005985366180539131,
-0.02076742611825466,
-0.020090119913220406,
0.031161289662122726,
0.008501533418893814,
0.012610756792128086,
-0.03437579423189163,
-0.010297155939042568,
0.006249928381294012,
-0.024496691301465034,
0.011702686548233032,
-0.021293966099619865,
0.024094553664326668,
0.005344131495803595,
-0.040179383009672165,
-0.023390401154756546,
-0.047704923897981644,
-0.001177208498120308,
0.006744481157511473,
0.025296106934547424,
-0.06219280883669853,
-0.03575156256556511,
-0.03526448458433151,
0.00399791169911623,
0.013638940639793873,
-0.031339727342128754,
0.05325052887201309,
0.04053894802927971,
-0.005681800190359354,
-0.021411728113889694,
0.0038441631477326155,
-0.0017986481543630362,
0.04628336802124977,
0.022966062650084496,
-0.0029253014363348484,
0.0022063273936510086,
-0.024103013798594475,
0.014850495383143425,
0.010023942217230797,
0.024253208190202713,
0.007312985602766275,
0.015179208479821682,
0.007256040815263987,
0.0027007684111595154,
-0.00008772285946179181,
0.01596991904079914,
-0.027612078934907913,
0.0062747919000685215,
0.026402203366160393,
0.015801018103957176,
0.06510511040687561,
0.0023967053275555372,
0.008867000229656696,
0.025784125551581383,
-0.0005116917309351265,
0.009582753293216228,
-0.03613996133208275,
-0.009053198620676994,
0.036613091826438904,
0.010948055423796177,
-0.0201822929084301,
-0.01778511144220829,
-0.01256082858890295,
0.0068414886482059956,
-0.03518252074718475,
-0.013436749577522278,
-0.02358430251479149,
0.007062187418341637,
0.0444323904812336,
-0.04780607298016548,
0.029204512014985085,
0.017946358770132065,
-0.0009185209055431187,
0.029627526178956032,
0.029894568026065826,
0.03871028870344162,
0.02149859257042408,
-0.03267023339867592,
0.0006282225949689746,
0.009976519271731377,
0.006360652390867472,
0.030428795143961906,
-0.014439994469285011,
0.02083209902048111,
0.023360993713140488,
-0.007046419195830822,
-0.02633095532655716,
-0.013299821875989437,
0.005065925884991884,
-0.003935264423489571,
-0.004186021164059639,
0.00013101345393806696,
0.0180603489279747,
0.028875576332211494,
0.022122103720903397,
-0.04349145293235779,
0.017260193824768066,
0.0019039075123146176,
-0.0036382267717272043,
-0.030907148495316505,
0.02777097560465336,
0.009461688809096813,
0.007298529148101807,
0.041103966534137726,
-0.007295783143490553,
-0.012022623792290688,
-0.014320268295705318,
0.022384049370884895,
0.0042611476965248585,
0.04148637875914574,
0.007997064851224422,
0.04226146265864372,
0.0049897669814527035,
0.004335068166255951,
0.02759329043328762,
0.02379310503602028,
-0.024276426061987877,
0.02194145694375038,
0.027636177837848663,
-0.03074795939028263,
0.018744543194770813,
-0.005140253808349371,
-0.008449663408100605,
-0.02064441330730915,
0.01000798400491476,
-0.024600809440016747,
0.020932897925376892,
0.02647187002003193,
0.03976672887802124,
0.011511866934597492,
-0.015345186926424503,
0.0067075383849442005,
-0.007738991174846888,
-0.008227021433413029,
-0.014894033782184124,
-0.016926610842347145,
-0.0019137548515573144,
-0.0037174487952142954,
0.015490279532968998,
-0.009556978940963745,
-0.03106393665075302,
0.02377932146191597,
0.021251225844025612,
-0.008150466717779636,
0.018280820921063423,
0.012006957083940506,
-0.04029546305537224,
-0.010163206607103348,
-0.03420547768473625,
0.013256041333079338,
-0.03342733159661293,
0.01524493657052517,
-0.019649755209684372,
0.035068169236183167,
-0.0011863206746056676,
-0.008837971836328506,
-0.0018897660775110126,
-0.007825815118849277,
-0.030727552250027657,
-0.017949575558304787,
0.010951678268611431,
-0.017869314178824425,
-0.014868279919028282,
-0.00028769340133294463,
-0.022750837728381157,
-0.010095186531543732,
0.006068010814487934,
-0.016773762181401253,
0.026249440386891365,
-0.023467620834708214,
-0.02787252888083458,
-0.0045622424222528934,
-0.018659742549061775,
-0.021380189806222916,
-0.0010578962974250317,
0.024083085358142853,
-0.008467678911983967,
-0.000776568369474262,
0.018311340361833572,
0.011569778434932232,
0.006149115972220898,
-0.007131766062229872,
-0.0015082795871421695,
0.019495917484164238,
0.026369374245405197,
0.008003934286534786,
0.022855442017316818,
0.041724879294633865,
0.004712800495326519,
0.02041449584066868,
-0.0024734290782362223,
-0.02652081660926342,
0.00784676056355238,
-0.001889917184598744,
0.007233849726617336,
0.03741965815424919,
-0.011409871280193329,
0.029226170852780342,
0.04994099214673042,
0.021235212683677673,
-0.0029878108762204647,
-0.01375503372400999,
0.001351462327875197,
-0.008976402692496777,
-0.038298968225717545,
0.0176653191447258,
-0.02001326158642769,
0.02365208975970745,
-0.04303276538848877,
0.002127112355083227,
-0.016354041174054146,
-0.005196095909923315,
0.04840734228491783,
0.03546905145049095,
-0.05992383882403374,
0.01721992902457714,
-0.004016141407191753,
-0.010594366118311882,
0.004227762576192617,
0.012182428501546383,
-0.010516108945012093,
0.04056898504495621,
-0.01602402701973915,
0.014068341813981533,
-0.0019793426617980003,
-0.0013111484004184604,
0.006287098862230778,
0.028925664722919464,
0.020273249596357346,
-0.014586345292627811,
0.004831652157008648,
-0.003814093302935362,
0.0371001735329628,
-0.0047837053425610065,
0.014325005933642387,
-0.03471526503562927,
0.032418470829725266,
-0.0035466006956994534,
0.0007527022389695048,
0.00404603686183691,
0.0926043912768364,
0.03555724397301674,
0.012474213726818562,
-0.02256595529615879,
-0.03211679309606552,
0.0091901496052742,
-0.024046823382377625,
-0.0004556943313218653,
0.034834787249565125,
0.031796958297491074,
0.04792730137705803,
-0.03562202304601669,
-0.0014627972850576043,
-0.0007356763817369938,
-0.01124329399317503,
0.05184398591518402,
0.03301990032196045,
0.01940736547112465,
-0.01401509903371334,
-0.01181193720549345,
-0.04330937936902046,
0.006444502621889114,
0.02064887247979641,
0.012944621965289116,
-0.005998870357871056,
0.010184381157159805,
-0.010450633242726326,
-0.0011217801366001368,
0.03149891644716263,
-0.052584148943424225,
-0.010964255779981613,
-0.020313313230872154,
-0.004970671609044075,
-0.023971492424607277,
0.05879479646682739,
-0.017708774656057358,
-0.038463886827230453,
-0.02376434952020645,
-0.04103696346282959,
-0.03639120236039162,
-0.005137292202562094,
0.004395569209009409,
0.009624989703297615,
-0.008305083960294724,
0.009363674558699131,
-0.0114061264321208,
0.009558675810694695,
0.027470817789435387,
-0.04615942761301994,
-0.009352375753223896,
-0.04004674032330513,
-0.004529332276433706,
0.011370498687028885,
-0.030408596619963646,
-0.0011646962957456708,
0.006550256162881851
] |
8a50b1905c10bef14015d0bd1e4794d8d3018140 | 38,121 | py | Python | circuitry/circuitry.py | nthparty/circuitry | e8bc8bde93cf5056368a14a21086f18f1bcd934f | [
"MIT"
] | 3 | 2020-06-23T19:11:53.000Z | 2021-01-06T16:42:56.000Z | circuitry/circuitry.py | nthparty/circuitry | e8bc8bde93cf5056368a14a21086f18f1bcd934f | [
"MIT"
] | 4 | 2020-07-28T03:14:59.000Z | 2020-07-28T17:44:25.000Z | circuitry/circuitry.py | nthparty/circuitry | e8bc8bde93cf5056368a14a21086f18f1bcd934f | [
"MIT"
] | 1 | 2020-06-23T19:07:59.000Z | 2020-06-23T19:07:59.000Z | """Embedded DSL for assembling logic circuits.
Embedded domain-specific combinator library for
assembling abstract definitions of logic circuits
and synthesizing circuits from those definitions.
"""
from __future__ import annotations
from typing import Sequence
import doctest
from parts import parts
from circuit import op, gate, circuit, signature
class bit():
"""
Class for representing an abstract bit. Such a bit
can be interpreted concretely as a value, but it is
also used to keep track of relationships between
operators and to represent the wires within a
circuit built up out of those operators.
>>> bit.hook_operation(lambda o, v, *args: None)
>>> bit.circuit(circuit())
>>> b = output(input(1).and_(input(1)))
>>> b.value == bit.circuit().evaluate([1,1])[0]
True
>>> def make_hook(bit_):
... def hook(o, v, *args):
... return bit_.constructor(*args)(v, bit_.gate(o, [a.gate for a in args]))
... return hook
>>> bit.hook_operation(make_hook(bit))
>>> bit.circuit(circuit())
>>> b = output(input(0).and_(input(0)))
>>> b.value == bit.circuit().evaluate([0,0])[0]
True
"""
_circuit = None
_hook_operation = None
@staticmethod
def circuit(circuit_=None):
if circuit_ is not None:
bit._circuit = circuit_
return None
else:
bit._circuit.prune_and_topological_sort_stable()
return bit._circuit
@staticmethod
def hook_operation(hook=None):
bit._hook_operation = hook
@staticmethod
def operation(o, *args):
# Ensure second argument is a `bit`.
args = list(args)
if len(args) == 2:
args[1] = constant(args[1]) if isinstance(args[1], int) else args[1]
# Compute the value of the result of the operation on the arguments.
v = o(*[a.value for a in args])
# Return output from hook if it exists and if
# it returns an output.
if bit._hook_operation is not None:
r = bit._hook_operation(o, v, *args)
if r is not None:
return r
return bit.constructor(*args)(v, bit.gate(o, [a.gate for a in args]))
@staticmethod
def constructor(b1, b2=None):
# The inference code below is not currently in use.
"""
if isinstance(b1, input_one) and isinstance(b2, input_one):
return input_one
elif isinstance(b1, input_two) and isinstance(b2, input_two):
return input_two
elif isinstance(b1, (input_one, input_two)) and b2 is None:
return type(b1)
else:
return bit
"""
return bit
@staticmethod
def gate(operation, igs):
return bit._circuit.gate(operation, igs)
def __init__(self, value, gate_=None):
self.value = value
self.gate = bit._circuit.gate() if gate_ is None else gate_
def __int__(self):
return self.value
def not_(self):
"""
>>> results = []
>>> for x in [0, 1]:
... bit.circuit(circuit())
... b = output(input(x).not_())
... results.append(int(b) == bit.circuit().evaluate([x])[0])
>>> all(results)
True
"""
return bit.operation(op.not_, self)
def __invert__(self):
"""
>>> results = []
>>> for x in [0, 1]:
... bit.circuit(circuit())
... b = output(~input(x))
... results.append(int(b) == bit.circuit().evaluate([x])[0])
>>> all(results)
True
"""
return bit.operation(op.not_, self)
def __rsub__(self, other):
"""
>>> results = []
>>> for x in [0, 1]:
... bit.circuit(circuit())
... b = output(1 - input(x))
... results.append(int(b) == bit.circuit().evaluate([x])[0])
>>> all(results)
True
>>> bit.circuit(circuit())
>>> 2 - input(0)
Traceback (most recent call last):
...
ValueError: can only subtract a bit from the integer 1
"""
if other == 1:
return bit.operation(op.not_, self)
raise ValueError('can only subtract a bit from the integer 1')
def and_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).and_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.and_, self, other)
def __and__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) & input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.and_, self, other)
def __rand__(self, other):
"""
>>> bit.circuit(circuit())
>>> b = 0 & constant(1)
>>> b.value
0
"""
return self & (constant(other) if isinstance(other, int) else other)
def nimp(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nimp(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nimp_, self, other)
def nimp_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nimp_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nimp_, self, other)
def __gt__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) > input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return self.nimp(other)
def nif(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nif(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nif_, self, other)
def nif_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nif_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nif_, self, other)
def __lt__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) < input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return self.nif(other)
def xor(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).xor(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.xor_, self, other)
def xor_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).xor_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.xor_, self, other)
def __xor__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) ^ input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.xor_, self, other)
def __rxor__(self, other):
"""
>>> bit.circuit(circuit())
>>> b = 1 ^ constant(0)
>>> b.value
1
"""
return self ^ (constant(other) if isinstance(other, int) else other)
def or_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).or_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.or_, self, other)
def __or__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) | input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.or_, self, other)
def __ror__(self, other):
"""
>>> bit.circuit(circuit())
>>> b = 1 | constant(0)
>>> b.value
1
"""
return self | (constant(other) if isinstance(other, int) else other)
def nor(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nor(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nor_, self, other)
def nor_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nor_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nor_, self, other)
def __mod__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) % input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nor_, self, other)
def xnor(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).xnor(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.xnor_, self, other)
def xnor_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).xnor_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.xnor_, self, other)
def __eq__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) == input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.xnor_, self, other)
def if_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).if_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.if_, self, other)
def __ge__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) >= input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.if_, self, other)
def imp(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).imp(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.imp_, self, other)
def imp_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).imp_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.imp_, self, other)
def __le__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) <= input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.imp_, self, other)
def nand(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nand(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nand_, self, other)
def nand_(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x).nand_(input(y)))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nand_, self, other)
def __matmul__(self, other):
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... b = output(input(x) @ input(y))
... results.append(int(b) == bit.circuit().evaluate([x,y])[0])
>>> all(results)
True
"""
return bit.operation(op.nand_, self, other)
class constant(bit):
"""Bit that is designated as a constant input."""
class input(bit):
"""Bit that is designated as a variable input."""
def __init__(self: bit, value: int):
self.value = value
self.gate = bit._circuit.gate(op.id_, is_input=True)
class input_one(input):
"""Bit that is designated as a variable input from one source."""
class input_two(input):
"""Bit that is designated as a variable input from a second source."""
class output(bit):
"""
Bit that is designated an output.
>>> bit.circuit(circuit())
>>> b0 = output(input(1).not_())
>>> b1 = output(b0.not_())
>>> b2 = output(b0)
>>> [b0.value, b1.value, b2.value]
[0, 1, 0]
"""
def __init__(self: bit, b: bit):
# Check if bit is ready as final output or whether there are others dependent on it.
if len(b.gate.outputs) > 0:
b = ~(~b) # Preserve the bit by copying it to a new wire.
self.value = b.value
self.gate = bit._circuit.gate(op.id_, [b.gate], is_output=True)
class bits_type(int): # pylint: disable=R0903
"""
Class for representing an input or output type of a
function decorated for automated synthesis.
"""
class bits(list):
"""
Class for representing a vector of abstract bits.
"""
@staticmethod
def from_byte(byte_: int, constructor=bit) -> bits:
return bits([
constructor(bit_)
for bit_ in reversed([(byte_>>i)%2 for i in range(8)])
])
@staticmethod
def from_bytes(bytes_, constructor=bit) -> bits:
"""
>>> bit.circuit(circuit())
>>> [b.value for b in bits.from_bytes(bytes([255]))]
[1, 1, 1, 1, 1, 1, 1, 1]
>>> bit.circuit(circuit())
>>> [b.value for b in bits.from_bytes(bytes([11, 0]))]
[0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
"""
return bits([
bit_
for byte_ in bytes_
for bit_ in bits.from_byte(byte_, constructor)
])
@staticmethod
def zeros(n: int) -> bits:
"""
>>> bit.circuit(circuit())
>>> xs = bits.zeros(3)
>>> ys = outputs(xs.not_())
>>> [y.value for y in ys]
[1, 1, 1]
"""
return bits([constant(0)]*n)
def __new__(cls, argument = None) -> bits:
"""
Return bits object given the supplied argument.
"""
return bits_type(argument)\
if isinstance(argument, int) else\
list.__new__(cls, argument)
def __int__(self: bits) -> int:
"""
>>> bit.circuit(circuit())
>>> xs = constants([0, 0, 0])
>>> ys = outputs(xs.not_())
>>> int(ys)
7
"""
return sum(int(b)*(2**i) for (i, b) in zip(range(len(self)), reversed(self)))
def not_(self: bits) -> bits:
"""
>>> results = []
>>> for x in [0, 1]:
... bit.circuit(circuit())
... xs = inputs([x, x, x])
... ys = outputs(xs.not_())
... ns = [int(y) for y in ys]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x]))
>>> all(results)
True
"""
return bits([x.not_() for x in self])
def __invert__(self: bits) -> bits:
"""
>>> results = []
>>> for x in [0, 1]:
... bit.circuit(circuit())
... xs = inputs([x, x, x])
... ys = outputs(~xs)
... ns = [int(y) for y in ys]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x]))
>>> all(results)
True
"""
return bits([x.not_() for x in self])
def and_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.and_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.and_(y) for (x, y) in zip(self, other)])
def __and__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs & ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.and_(y) for (x, y) in zip(self, other)])
def nimp(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nimp(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nimp_(y) for (x, y) in zip(self, other)])
def nimp_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nimp_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nimp_(y) for (x, y) in zip(self, other)])
def __gt__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs > ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nimp_(y) for (x, y) in zip(self, other)])
def nif(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nif(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nif_(y) for (x, y) in zip(self, other)])
def nif_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nif_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nif_(y) for (x, y) in zip(self, other)])
def __lt__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs < ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nif_(y) for (x, y) in zip(self, other)])
def xor(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.xor(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.xor_(y) for (x, y) in zip(self, other)])
def xor_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.xor_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.xor_(y) for (x, y) in zip(self, other)])
def __xor__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs ^ ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.xor_(y) for (x, y) in zip(self, other)])
def or_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.or_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.or_(y) for (x, y) in zip(self, other)])
def __or__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs | ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.or_(y) for (x, y) in zip(self, other)])
def nor(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nor(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nor_(y) for (x, y) in zip(self, other)])
def nor_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nor_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nor_(y) for (x, y) in zip(self, other)])
def __mod__(self, other) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs % ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nor_(y) for (x, y) in zip(self, other)])
def xnor(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.xnor(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.xnor_(y) for (x, y) in zip(self, other)])
def xnor_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.xnor_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.xnor_(y) for (x, y) in zip(self, other)])
def __eq__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs == ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.xnor_(y) for (x, y) in zip(self, other)])
def if_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.if_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.if_(y) for (x, y) in zip(self, other)])
def __ge__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs >= ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.if_(y) for (x, y) in zip(self, other)])
def imp(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.imp(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.imp_(y) for (x, y) in zip(self, other)])
def imp_(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.imp_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.imp_(y) for (x, y) in zip(self, other)])
def __le__(self: bits, other: bits) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs <= ys)
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.imp_(y) for (x, y) in zip(self, other)])
def nand(self: bits, other) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nand(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nand_(y) for (x, y) in zip(self, other)])
def nand_(self: bits, other) -> bits:
"""
>>> results = []
>>> for (x, y) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
... bit.circuit(circuit())
... (xs, ys) = (inputs([x, x, x]), inputs([y, y, y]))
... zs = outputs(xs.nand_(ys))
... ns = [int(z) for z in zs]
... c = bit.circuit()
... results.append(ns == c.evaluate([x, x, x, y, y, y]))
>>> all(results)
True
"""
return bits([x.nand_(y) for (x, y) in zip(self, other)])
def __rshift__(self: bits, other) -> bits:
"""
Overloaded operator: rotation and shift operations.
>>> bit.circuit(circuit())
>>> bs = bits(map(bit, [1,1,1,1,0,0,0,0]))
>>> bs = bs >> 3
>>> [b.value for b in bs]
[0, 0, 0, 1, 1, 1, 1, 0]
>>> bit.circuit(circuit())
>>> bs = bits(map(bit, [0,0,0,0,1,1,1,1]))
>>> bs = bs >> {3}
>>> [b.value for b in bs]
[1, 1, 1, 0, 0, 0, 0, 1]
"""
if isinstance(other, set) and isinstance(list(other)[0], int): # Rotation.
quantity = list(other)[0]
return bits(self[len(self)-quantity:]) ** bits(self[0:len(self)-quantity])
else: # Shift
return bits([constant(0)]*other) ** bits(self[0:len(self)-other])
def __lshift__(self: bits, other) -> bits:
"""
>>> bit.circuit(circuit())
>>> bs = bits(map(bit, [1,1,1,1,0,0,0,0]))
>>> bs = bs << 3
>>> [b.value for b in bs]
[1, 0, 0, 0, 0, 0, 0, 0]
"""
return bits(self[other:]) ** bits([constant(0) for _ in range(other)])
def __truediv__(self: bits, other) -> Sequence[bits]:
"""
>>> bit.circuit(circuit())
>>> bs = bits(map(bit, [1,1,1,1,0,0,0,0]))
>>> bss = list(bs / 2)
>>> ([b.value for b in bss[0]], [b.value for b in bss[1]])
([1, 1, 1, 1], [0, 0, 0, 0])
>>> bit.circuit(circuit())
>>> bs = bits(map(bit, [1,1,1,1,0,0,0,0]))
>>> bss = list(bs / {2})
>>> [[b.value for b in bs] for bs in bss]
[[1, 1], [1, 1], [0, 0], [0, 0]]
>>> bit.circuit(circuit())
>>> bs = bits(map(bit, [1,1,1,1,0,0,0,0]))
>>> bss = list(bs / [1, 3, 4])
>>> [[b.value for b in bs] for bs in bss]
[[1], [1, 1, 1], [0, 0, 0, 0]]
"""
if isinstance(other, list) and len(other) > 0 and isinstance(other[0], int):
return map(bits, parts(self, length=other)) # Sequence of lengths.
elif isinstance(other, set) and len(other) == 1 and isinstance(list(other)[0], int):
return self / (len(self)//list(other)[0]) # Parts of length `other`.
else:
return map(bits, parts(self, other)) # Number of parts is `other`.
def __add__(self: bits, other) -> bits:
"""Concatenation of bit vectors."""
result = list(self)
result.extend(list(other))
return bits(result)
def __pow__(self: bits, other) -> bits:
"""Concatenation of bit vectors."""
return self + other
def constants(l):
return bits(map(constant, l))
def inputs(l):
return bits(map(input, l))
def outputs(l):
return bits(map(output, l))
def synthesize(f):
"""
Decorator for automatically synthesizing a circuit from a
function that takes only `bit` and/or `bits` objects as its
arguments and returns an output of type `bit` or `bits`.
>>> @synthesize
... def equal(x: bit, y: bit) -> bit:
... return (x & y) | ((1 - x) & (1 - y))
>>> xys = [bits([x, y]) for x in (0, 1) for y in (0, 1)]
>>> [equal.circuit.evaluate(xy) for xy in xys]
[[1], [0], [0], [1]]
>>> @synthesize
... def conjunction(xy: bits(2)) -> bits(2):
... return (xy[0], xy[0] & xy[1])
>>> xys = [bits([x, y]) for x in (0, 1) for y in (0, 1)]
>>> [conjunction.circuit.evaluate(xy) for xy in xys]
[[0, 0], [0, 0], [1, 0], [1, 1]]
>>> @synthesize
... def equal(x, y):
... return x & y
Traceback (most recent call last):
...
RuntimeError: automated circuit synthesis failed
"""
# Functions for determining types/signature from
# the type annotation of the decorated function.
type_in = lambda a: input(0) if a is bit else inputs([0] * a)
type_out = lambda a: output if a is bit else outputs
# For forward-compatibility with PEP 563.
eval_ = lambda a: eval(a) if isinstance(a, str) else a # pylint: disable=W0123
try:
# Construct the circuit and add it to the function as an attribute.
bit.circuit(circuit())
args_in = {
k: type_in(eval_(a))
for (k, a) in f.__annotations__.items() if k != 'return'
}
type_out(eval_(f.__annotations__['return']))(f(**args_in))
f.circuit = bit.circuit()
except:
raise RuntimeError('automated circuit synthesis failed') from None
# Return the original function.
return f
if __name__ == "__main__":
doctest.testmod() # pragma: no cover
| 33.557218 | 92 | 0.440728 | 1 | 2.1276 | [
-0.05078115686774254,
0.05582547187805176,
0.039147306233644485,
0.020544618368148804,
-0.014925393275916576,
-0.006380914710462093,
-0.0009819120168685913,
-0.002196595072746277,
-0.04467378929257393,
0.03709706291556358,
0.0331231988966465,
-0.01493798941373825,
0.029838036745786667,
-0.016148928552865982,
0.0003112615959253162,
-0.014642639085650444,
0.13865932822227478,
-0.016114259138703346,
-0.015049641951918602,
-0.015105479396879673,
0.013266201131045818,
-0.0014893525512889028,
0.01587260141968727,
0.02861492708325386,
-0.01910168118774891,
0.005249905865639448,
0.030405662953853607,
-0.022275937721133232,
0.009504545480012894,
-0.020607125014066696,
-0.015241432003676891,
0.0016446587396785617,
0.018836671486496925,
0.037401631474494934,
-0.007365833036601543,
0.01719396933913231,
0.0184074267745018,
-0.06392467767000198,
-0.014258704148232937,
0.009489224292337894,
-0.00003513466435833834,
0.033989451825618744,
0.021881060674786568,
-0.04570755735039711,
0.061007753014564514,
-0.032050635665655136,
-0.009694854728877544,
0.017009461298584938,
-0.056357402354478836,
0.016670899465680122,
-0.015367051586508751,
0.020799871534109116,
-0.005412223748862743,
-0.024939274415373802,
0.0020798943005502224,
-0.05478738248348236,
0.0037575778551399708,
0.0009123877389356494,
-0.0032706602942198515,
0.0012002557050436735,
0.0011692477855831385,
0.010464468039572239,
0.045917119830846786,
0.006700876634567976,
0.043630149215459824,
-0.016314657405018806,
0.021624360233545303,
0.010534626431763172,
-0.026479391381144524,
-0.05036464333534241,
0.001966907409951091,
-0.023448621854186058,
0.008032072335481644,
0.06651730090379715,
0.0009640901116654277,
-0.009831043891608715,
-0.028553998097777367,
-0.010327867232263088,
0.003286059945821762,
0.004096704535186291,
-0.008553359657526016,
0.07444330304861069,
0.012982330285012722,
-0.0007635941728949547,
-0.005629800260066986,
0.041145484894514084,
0.037149056792259216,
-0.0519808791577816,
0.051398538053035736,
0.008021369576454163,
-0.05046146363019943,
0.011748306453227997,
-0.05379056930541992,
-0.0007083400851115584,
-0.05830956995487213,
-0.06743153929710388,
0.04157273471355438,
0.013474690727889538,
-0.00719697680324316,
-0.00592002784833312,
0.004433772061020136,
-0.0014512815978378057,
0.027455119416117668,
-0.0013899514451622963,
-0.04042503237724304,
-0.003362929681316018,
-0.04266181215643883,
0.013001891784369946,
-0.010015216656029224,
-0.027237683534622192,
-0.04416302591562271,
-0.021042494103312492,
0.025454536080360413,
-0.06992245465517044,
-0.05103214085102081,
-0.01936180703341961,
-0.007288634777069092,
0.002418074756860733,
-0.04051961004734039,
-0.005919560790061951,
0.0005192294484004378,
0.0026157626416534185,
0.00012047544441884384,
-0.0000774018481024541,
-0.02961510792374611,
0.07674651592969894,
0.001379405497573316,
0.017971787601709366,
0.01703457534313202,
0.0056119393557310104,
-0.023428674787282944,
0.010387812741100788,
-0.005735131446272135,
0.00792755838483572,
-0.005649630445986986,
0.010277500376105309,
0.0315900519490242,
-0.012535233981907368,
-0.047411464154720306,
-0.004150024149566889,
0.008293054066598415,
-0.011771157383918762,
0.028075067326426506,
-0.017466669902205467,
0.01477749366313219,
-0.04311637207865715,
0.017775190994143486,
0.013611895963549614,
-0.04005589336156845,
-0.013814514502882957,
0.03347155824303627,
0.028694171458482742,
-0.027422413229942322,
0.028166959062218666,
0.00002389511610090267,
0.0020671638194471598,
-0.03627786412835121,
-0.05229005590081215,
-0.001356757478788495,
0.022573944181203842,
0.00797668844461441,
0.03680862858891487,
0.01965435780584812,
-0.00828839186578989,
-0.0012503948528319597,
0.06922652572393417,
-0.05912372097373009,
-0.00534722488373518,
0.010573843494057655,
-0.016185149550437927,
-0.0063854241743683815,
0.011234281584620476,
-0.022011570632457733,
0.013657215982675552,
-0.06076734513044357,
0.019935281947255135,
0.024470768868923187,
0.03741595521569252,
0.01921478845179081,
-0.014445197768509388,
0.019748399034142494,
-0.0013580179074779153,
0.011953323148190975,
0.02544667385518551,
0.043837860226631165,
0.0022694352082908154,
-0.028675910085439682,
-0.035656511783599854,
-0.010703232139348984,
-0.004408504348248243,
-0.0239640474319458,
0.0688854232430458,
-0.022380979731678963,
-0.03364510461688042,
0.026008816435933113,
-0.04106013476848602,
-0.017540154978632927,
0.04415377974510193,
-0.0108804227784276,
0.014863674528896809,
0.01342419907450676,
-0.019496198743581772,
0.01615035906434059,
-0.006087073124945164,
0.027050495147705078,
0.0023425593972206116,
-0.5946177840232849,
0.001792706549167633,
0.03440440073609352,
0.0031066639348864555,
-0.015325117856264114,
0.02549351565539837,
-0.025473304092884064,
0.02378401905298233,
-0.04646359756588936,
-0.008318781852722168,
0.0021397313103079796,
-0.03376174345612526,
-0.037394579499959946,
0.004714639391750097,
-0.015546039678156376,
-0.024150574579834938,
-0.0033152559772133827,
-0.016617802903056145,
0.03107735700905323,
0.028061944991350174,
0.003450051648542285,
-0.010999538004398346,
-0.037293314933776855,
0.0074661122635006905,
-0.03860561549663544,
-0.023584850132465363,
0.03796304017305374,
0.028422746807336807,
0.02460610866546631,
-0.014929866418242455,
-0.008590318262577057,
-0.019343722611665726,
0.02208872139453888,
0.014924204908311367,
-0.03048849292099476,
0.0061461240984499454,
-0.00909963808953762,
-0.017997439950704575,
0.07317757606506348,
0.003129490651190281,
-0.022642677649855614,
0.0031082555651664734,
-0.010494274087250233,
-0.05964653939008713,
-0.026438431814312935,
-0.035563986748456955,
-0.011971160769462585,
-0.03151080012321472,
0.0068862223997712135,
0.02697506919503212,
-0.03488976135849953,
0.04037991538643837,
0.026732301339507103,
-0.03775803744792938,
0.0198256466537714,
-0.01690739020705223,
-0.02219013124704361,
-0.0299918781965971,
0.014576997607946396,
-0.021400921046733856,
0.053912583738565445,
-0.01052652858197689,
-0.009767783805727959,
0.010275390930473804,
0.010430817492306232,
0.022329043596982956,
0.01208898238837719,
-0.05587661266326904,
-0.056663837283849716,
0.047377072274684906,
-0.06513060629367828,
0.0074547575786709785,
-0.047848910093307495,
0.056188177317380905,
-0.017643829807639122,
0.03161734342575073,
-0.007595354225486517,
-0.030477354303002357,
-0.05791497230529785,
0.012091023847460747,
0.023233948275446892,
-0.023713253438472748,
-0.010748368687927723,
0.007386190816760063,
-0.0044927881099283695,
-0.012365168891847134,
-0.02060987427830696,
-0.006190082989633083,
0.01620316691696644,
0.002242069924250245,
0.05642896890640259,
0.05586008355021477,
0.0207704808562994,
0.043654173612594604,
0.0259611364454031,
-0.010995755903422832,
-0.005135747138410807,
0.08272913098335266,
0.014964678324759007,
0.02280787192285061,
-0.03123694844543934,
0.027666427195072174,
0.00904177874326706,
0.01055885013192892,
-0.023105816915631294,
0.012471537105739117,
-0.046930596232414246,
0.004913075361400843,
0.029306694865226746,
0.01105801947414875,
-0.02184581197798252,
0.00289999321103096,
-0.00904222670942545,
0.010142815299332142,
-0.040422338992357254,
-0.010442422702908516,
-0.00006733451300533488,
-0.05584803968667984,
0.02401036210358143,
-0.011709482409060001,
-0.009693382307887077,
-0.017920812591910362,
-0.0013820737367495894,
0.01534417923539877,
-0.017598802223801613,
-0.016763702034950256,
-0.04179555922746658,
0.0075997100211679935,
0.0066882288083434105,
0.016224471852183342,
-0.05413352698087692,
0.02928103320300579,
-0.04552888870239258,
0.004668909125030041,
0.034767743200063705,
-0.017118779942393303,
-0.06609612703323364,
-0.047962989658117294,
0.012668321840465069,
0.034058939665555954,
-0.017601436004042625,
-0.004613698925822973,
0.010661271400749683,
-0.020989546552300453,
0.0008950483752414584,
0.051817215979099274,
0.019436294212937355,
-0.007925032638013363,
-0.006778517737984657,
-0.02003525383770466,
0.011220024898648262,
0.021770894527435303,
0.02342807501554489,
0.0004300287982914597,
-0.001373028731904924,
0.020091082900762558,
-0.05250335484743118,
-0.024127421900629997,
0.05648306384682655,
0.030941691249608994,
-0.01821480691432953,
0.03330857679247856,
-0.004807963501662016,
0.04335523396730423,
0.019564680755138397,
0.016877099871635437,
-0.0067135426215827465,
-0.006036655977368355,
0.04990464448928833,
0.033262599259614944,
0.03588755056262016,
0.017689784988760948,
0.032967519015073776,
-0.019029418006539345,
-0.0029774752911180258,
0.035197023302316666,
-0.01879381760954857,
-0.03284327685832977,
0.03231731429696083,
-0.024727003648877144,
-0.055145833641290665,
0.00013373362889979035,
-0.0028495981823652983,
-0.0022471651900559664,
0.013059776276350021,
-0.014433842152357101,
-0.013665181584656239,
-0.00639656838029623,
0.014450124464929104,
-0.021717727184295654,
0.04685207083821297,
0.01258925162255764,
-0.04022001475095749,
-0.0019493205472826958,
-0.04584497585892677,
-0.013130768202245235,
-0.040986720472574234,
0.0070508611388504505,
-0.002218538196757436,
-0.021503953263163567,
0.023455819115042686,
0.011483805254101753,
0.016703646630048752,
-0.004345804452896118,
0.030997827649116516,
0.10347677767276764,
-0.01057288609445095,
-0.006613067351281643,
0.024308642372488976,
-0.0050484188832342625,
0.02989751473069191,
-0.019784176722168922,
0.010850530117750168,
0.004703913815319538,
-0.026543492451310158,
0.0032697184942662716,
-0.048899877816438675,
-0.06906028091907501,
0.02134408988058567,
-0.0595783032476902,
-0.021474774926900864,
-0.04622546583414078,
0.04447650909423828,
0.005318066105246544,
0.013379924930632114,
-0.006048823706805706,
-0.03224135562777519,
0.025505296885967255,
-0.00763612100854516,
-0.023210624232888222,
0.03258506581187248,
0.01026143878698349,
-0.00872222613543272,
-0.03491911664605141,
-0.01244328822940588,
0.005658102687448263,
-0.029062718152999878,
-0.05570739507675171,
-0.024450376629829407,
-0.023799652233719826,
-0.006218969356268644,
-0.051830191165208817,
0.014996482990682125,
0.05336537957191467,
0.011550738476216793,
-0.024965764954686165,
-0.015265732072293758,
-0.010758599266409874,
0.0007786217029206455,
-0.007448737975209951,
0.0035269781947135925,
0.027164336293935776,
-0.0007205308065749705,
-0.019496435299515724,
0.015096650458872318,
-0.03319524601101875,
-0.015082867816090584,
-0.026263093575835228,
0.017161043360829353,
0.01840750314295292,
-0.01959705352783203,
0.01829070970416069,
-0.009304162114858627,
0.04011145606637001,
-0.0008522435091435909,
0.01296602375805378,
-0.0033980447333306074,
-0.0072144921869039536,
0.0023396131582558155,
0.06295960396528244,
0.006327709183096886,
-0.004505711607635021,
-0.028102822601795197,
-0.022091522812843323,
-0.018704187124967575,
-0.024124784395098686,
0.0030746853444725275,
-0.056582286953926086,
0.009031571447849274,
0.025010673329234123,
0.0068065691739320755,
-0.009939102455973625,
-0.0024133012630045414,
0.020220646634697914,
-0.016736749559640884,
0.01420238334685564,
-0.01645396463572979,
0.0014946813462302089,
-0.07740969955921173,
-0.010172204114496708,
0.004773234017193317,
-0.03492727875709534,
0.06621631979942322,
0.01781347766518593,
-0.02850313112139702,
-0.015227014198899269,
-0.0316443033516407,
0.008372641168534756,
0.03265145793557167,
-0.006079280748963356,
0.03019179403781891,
-0.007404583506286144,
-0.01627630740404129,
-0.03137395530939102,
-0.0008750868146307766,
-0.033010032027959824,
0.03456944227218628,
-0.008456971496343613,
0.02725105918943882,
0.024657992646098137,
-0.005134397652000189,
0.044855255633592606,
0.03099045529961586,
-0.005182463210076094,
0.016678456217050552,
0.027157554402947426,
0.018814794719219208,
0.023772234097123146,
0.02590370923280716,
-0.00998999085277319,
-0.014860733412206173,
0.030316410586237907,
-0.02333514578640461,
-0.01882423833012581,
-0.022230885922908783,
-0.010143093764781952,
-0.023186014965176582,
-0.003381176618859172,
-0.017173361033201218,
0.009018603712320328,
-0.01771201193332672,
-0.010976452380418777,
0.0012692476157099009,
0.0038802074268460274,
0.0008387768175452948,
-0.06046584993600845,
0.03899344801902771,
0.03267991170287132,
0.04204441234469414,
0.0026569277979433537,
-0.04660666733980179,
0.03455587103962898,
-0.03372039645910263,
0.028323588892817497,
0.02615351416170597,
-0.00995348859578371,
0.01903499849140644,
0.049481701105833054,
0.048368483781814575,
0.01248757354915142,
0.007845206186175346,
0.002244923496618867,
-0.011441758833825588,
-0.008553257212042809,
-0.0042025428265333176,
-0.031239241361618042,
-0.027974404394626617,
0.007214617449790239,
0.008108219131827354,
0.02538887970149517,
-0.03067208081483841,
0.029170705005526543,
-0.01957562193274498,
-0.015479016117751598,
-0.004053088836371899,
-0.051076970994472504,
0.04405960813164711,
0.040005799382925034,
-0.005144074559211731,
0.03695913404226303,
0.005529444664716721,
-0.016541091725230217,
0.04848449304699898,
0.015649734064936638,
-0.013434256426990032,
0.03527580574154854,
0.06335818767547607,
-0.010595086961984634,
0.009568437933921814,
-0.017628153786063194,
0.00006387057510437444,
-0.014073637314140797,
0.014690885320305824,
-0.01787322387099266,
0.020626628771424294,
-0.015593324787914753,
-0.003139093518257141,
0.033344343304634094,
-0.04966822266578674,
-0.07301723212003708,
-0.014224911108613014,
-0.023881185799837112,
0.02896520309150219,
0.049262452870607376,
0.010580768808722496,
-0.013131874613463879,
0.00190670695155859,
0.014282762072980404,
-0.0031247406732290983,
-0.011334982700645924,
-0.009626636281609535,
-0.01287432387471199,
0.03783693537116051,
-0.006029428448528051,
0.06132061034440994,
-0.024697132408618927,
-0.023266196250915527,
-0.008436040952801704,
0.0082754110917449,
0.00047227588947862387,
0.025274692103266716,
0.02542741410434246,
-0.026796991005539894,
-0.01079400535672903,
-0.04125954583287239,
0.01862826943397522,
-0.01317367609590292,
-0.006780610885471106,
-0.025123421102762222,
-0.0009715730557218194,
-0.02001405507326126,
0.018673310056328773,
0.01124695036560297,
0.02866355888545513,
-0.036601610481739044,
-0.007426575757563114,
-0.0005815392942167819,
0.029639126732945442,
-0.00007819954043952748,
0.03921327367424965,
0.026593346148729324,
0.03100941702723503,
-0.03184524178504944,
-0.027492905035614967,
0.027722744271159172,
-0.031290680170059204,
-0.01115536130964756,
-0.0020149867050349712,
-0.02634473890066147,
-0.005437730345875025,
-0.034986577928066254,
-0.0318620465695858,
0.03238188847899437,
-0.010631590150296688,
-0.008112844079732895,
0.08744166791439056,
0.01571612060070038,
0.005686059128493071,
0.002446131780743599,
0.04131462424993515,
0.002872851211577654,
-0.01317665260285139,
0.009961390867829323,
0.010624988004565239,
0.007885896600782871,
-0.00007794819248374552,
-0.01563306152820587,
0.049469925463199615,
0.020160982385277748,
0.04107598215341568,
-0.0014967835741117597,
0.0220995731651783,
-0.030768750235438347,
0.04527115076780319,
0.052600521594285965,
0.015587205067276955,
0.016603795811533928,
-0.012878645211458206,
-0.01217502448707819,
0.014483107253909111,
-0.061726972460746765,
-0.0024324373807758093,
-0.029128888621926308,
0.015256884507834911,
-0.032696373760700226,
-0.032663460820913315,
-0.015165007673203945,
-0.0029219004791229963,
0.026061005890369415,
0.002180873416364193,
-0.041697122156620026,
0.03997378051280975,
0.0036059217527508736,
-0.029615789651870728,
-0.010344714857637882,
0.02422465942800045,
-0.028835907578468323,
0.06624787300825119,
-0.010555529966950417,
0.05083231255412102,
-0.007051032967865467,
-0.012686643749475479,
0.01604873687028885,
0.06832269579172134,
0.014277513138949871,
-0.03570621460676193,
0.01998497173190117,
0.0313429981470108,
0.051711566746234894,
0.0029541300609707832,
-0.05145682394504547,
-0.011007064953446388,
0.0018212377326563,
0.001267727930098772,
0.02865346148610115,
0.03574725240468979,
0.09221427887678146,
0.05729161202907562,
-0.00637786416336894,
-0.020961012691259384,
-0.020961757749319077,
-0.033688824623823166,
-0.001553565845824778,
0.013376211747527122,
0.04730874300003052,
-0.027881687507033348,
0.026405546814203262,
-0.034602370113134384,
-0.00505104148760438,
-0.0024637177120894194,
-0.013134143315255642,
0.03866861015558243,
0.021146636456251144,
-0.007018338423222303,
-0.0593317411839962,
0.004453168250620365,
-0.0471537820994854,
-0.038903169333934784,
0.008609938435256481,
0.02298726886510849,
-0.014452867209911346,
-0.024402592331171036,
0.001965489238500595,
-0.012824425473809242,
0.006447690539062023,
-0.046904657036066055,
0.02439255081117153,
0.033621612936258316,
-0.03868885710835457,
-0.03396151587367058,
0.05030639097094536,
0.014474240131676197,
-0.025675324723124504,
-0.0548955537378788,
-0.01884138397872448,
-0.04513068497180939,
0.015378249809145927,
0.0017848724965006113,
0.011674048379063606,
0.026369940489530563,
-0.013138391077518463,
-0.011319809593260288,
-0.024143541231751442,
0.03303046151995659,
-0.0626155436038971,
0.03414624556899071,
-0.012434420175850391,
-0.012241191230714321,
-0.0018450658535584807,
-0.07337291538715363,
-0.018928736448287964,
-0.037065356969833374
] |
8a50da9ca339ad2c3e097b9d78b1dde9a457d80b | 1,037 | py | Python | plot_user_activity.py | KanayBhandari/discord_bot_project | 4baa62c963c532b08060689bed872e36e72460f9 | [
"MIT"
] | null | null | null | plot_user_activity.py | KanayBhandari/discord_bot_project | 4baa62c963c532b08060689bed872e36e72460f9 | [
"MIT"
] | null | null | null | plot_user_activity.py | KanayBhandari/discord_bot_project | 4baa62c963c532b08060689bed872e36e72460f9 | [
"MIT"
] | null | null | null | import discord
import random
from datetime import datetime
import pandas as pd
import matplotlib.pyplot as plt
import csv
async def plot_user_activity(client, ctx):
plt.style.use('fivethirtyeight')
df = pd.read_csv('innovators.csv', encoding= 'unicode_escape')
author = df['author'].to_list()
message_counter = {}
for i in author:
if i in message_counter:
message_counter[i] += 1
else:
message_counter[i] = 1
# for not mentioning the bot in the line graph.
message_counter.pop('ninza_bot_test')
authors_in_discord = list(message_counter.keys())
no_of_messages = list(message_counter.values())
plt.plot(authors_in_discord, no_of_messages, marker = 'o', markersize=10)
plt.title('msg sent by author in the server.')
plt.xlabel('Author')
plt.ylabel('Message_count')
plt.savefig('output2.png')
plt.tight_layout()
plt.close()
await ctx.send(file = discord.File('output2.png'))
| 26.589744 | 78 | 0.649952 | 1 | 0.9741 | [
0.0038550051394850016,
0.024563269689679146,
0.008514560759067535,
-0.002363705774769187,
0.0034258412197232246,
-0.0024694318417459726,
-0.005979456007480621,
0.0028496955055743456,
-0.009105220437049866,
0.002035334939137101,
0.0025042386259883642,
0.006675302982330322,
0.006269948091357946,
-0.018723685294389725,
-0.00028837661375291646,
0.015521038323640823,
-0.050684794783592224,
0.001791465561836958,
-0.0018294596811756492,
0.004376941826194525,
-0.009293519891798496,
0.011076027527451515,
0.008566946722567081,
0.006054183002561331,
0.005928218364715576,
-0.0011995140230283141,
0.009175038896501064,
-0.0022205342538654804,
-0.008783428929746151,
-0.008279905654489994,
0.00029907538555562496,
-0.0003452711389400065,
-0.007589101325720549,
-0.00620115315541625,
0.003357161534950137,
-0.004837269429117441,
-0.0011643193429335952,
-0.01965228095650673,
0.014591521583497524,
-0.004783564247190952,
-0.0038569485768675804,
-0.012794582173228264,
0.0012232523877173662,
0.00447112275287509,
-0.00979926623404026,
0.0018486145418137312,
-0.005626529920846224,
0.0027096921112388372,
-0.01042290311306715,
0.004984341096132994,
-0.008119097910821438,
0.0038930256851017475,
0.013689501211047173,
0.0022999064531177282,
-0.002159700496122241,
-0.007330944295972586,
0.013576151803135872,
-0.0008221245370805264,
-0.012316345237195492,
-0.0018930240767076612,
-0.004485388286411762,
-0.001582354656420648,
0.005757208447903395,
0.002368795918300748,
-0.01893392950296402,
-0.005810694303363562,
-0.0065816305577754974,
0.002044114749878645,
-0.001143202418461442,
0.006497795227915049,
-0.0002144794270861894,
0.0004404436331242323,
0.00428035156801343,
0.003357198555022478,
0.0026088671293109655,
-0.008173367939889431,
-0.001048361067660153,
0.0024007726460695267,
0.007992830127477646,
0.006102044600993395,
0.005121206399053335,
-0.0076674954034388065,
0.005503514315932989,
0.010855253785848618,
0.01215639989823103,
0.008919649757444859,
0.016931351274251938,
-0.009921999648213387,
0.045422185212373734,
0.00788069423288107,
-0.00800388865172863,
0.0006657512276433408,
-0.007632290944457054,
-0.003936123568564653,
-0.006070035044103861,
-0.02892819605767727,
-0.002546766074374318,
-0.004536578431725502,
-0.001819974509999156,
0.004282919690012932,
0.002455929759889841,
0.010823764838278294,
-0.00026244772016070783,
-0.0037539766635745764,
-0.006611628923565149,
0.014544759877026081,
-0.008736593648791313,
-0.005275737959891558,
0.007776412181556225,
0.001549099339172244,
-0.011482395231723785,
0.0005519033875316381,
0.00263853557407856,
-0.012067149393260479,
0.004639177583158016,
0.0004467333492357284,
-0.006235042121261358,
0.052795637398958206,
-0.00007987001299625263,
0.0001717449922580272,
-0.005196170881390572,
0.00038935852353461087,
0.001237862859852612,
0.005492031574249268,
0.007645280100405216,
-0.0026347830425947905,
0.015201101079583168,
0.010924853384494781,
0.004844319075345993,
0.009093450382351875,
-0.0018366491422057152,
0.005245241802185774,
-0.0020218833815306425,
-0.00042002342524938285,
0.0021017249673604965,
-0.008488018065690994,
0.006163383834064007,
-0.0007850286783650517,
-0.008444870822131634,
0.002449019579216838,
0.0005681685288436711,
-0.010852625593543053,
0.0021674646995961666,
-0.0060703991912305355,
0.0048746089451014996,
-0.009835843928158283,
-0.003327876329421997,
-0.005283350590616465,
-0.003442301880568266,
0.0014676690334454179,
0.010373943485319614,
0.002970482688397169,
0.003542905440554023,
-0.0046865567564964294,
-0.008084208704531193,
-0.0003689052537083626,
-0.0022438650485128164,
0.0006980533362366259,
0.005567924119532108,
0.003213495947420597,
-0.011355916038155556,
-0.002357397461310029,
0.0027775433845818043,
0.005432938225567341,
-0.003349861828610301,
0.0025908544193953276,
-0.008216229267418385,
0.008603635244071484,
-0.0004889831179752946,
0.004232228267937899,
0.012691454961895943,
-0.005055601242929697,
-0.00020425079856067896,
-0.00046941119944676757,
0.002313775010406971,
-0.0027242386713624,
0.006409142632037401,
0.012617440894246101,
-0.004970767069607973,
-0.007008847780525684,
0.0047874245792627335,
0.0035401401109993458,
0.00519097363576293,
0.00533221336081624,
-0.0010017578024417162,
0.0051518455147743225,
-0.00501554599031806,
-0.0027143401093780994,
0.006114701274782419,
-0.003294151509180665,
0.005112449638545513,
0.003762941574677825,
-0.01267810259014368,
-0.011229590512812138,
0.0017026180867105722,
-0.006785048637539148,
0.00434462446719408,
0.01253901980817318,
0.012138708494603634,
-0.0025566250551491976,
0.0030210819095373154,
-0.01095216628164053,
0.0007117923232726753,
0.010293207131326199,
0.0013121375814080238,
-0.010162103921175003,
-0.9596750736236572,
0.007303961552679539,
0.0024734579492360353,
-0.003068577265366912,
0.004540706519037485,
0.001169105526059866,
0.0021003554575145245,
0.0034897061996161938,
0.012991202995181084,
-0.007471691817045212,
-0.005774395074695349,
-0.01139362994581461,
-0.009595208801329136,
-0.0021109660156071186,
-0.008340701460838318,
-0.003016163595020771,
-0.006401360034942627,
-0.006395479664206505,
-0.0029414391610771418,
-0.0014763025101274252,
-0.004509102087467909,
0.0110944714397192,
-0.0015634977025911212,
0.004640396684408188,
0.006523698102682829,
0.0027912361547350883,
-0.003529849462211132,
-0.0025747253093868494,
-0.001757998252287507,
-0.0020152952056378126,
-0.0068145254626870155,
-0.012152176350355148,
-0.0070845503360033035,
-0.0023858400527387857,
0.009986928664147854,
0.0008991126669570804,
0.009735500440001488,
-0.0049389079213142395,
0.0005750269046984613,
-0.009275319054722786,
0.006348867900669575,
-0.0008945060544647276,
0.0025248941965401173,
-0.02843160554766655,
-0.00030083328601904213,
-0.0019167439313605428,
-0.009294688701629639,
0.009501777589321136,
-0.0009605687810108066,
0.0014910881873220205,
-0.0039753541350364685,
-0.0030400215182453394,
0.006942154373973608,
-0.006059166509658098,
0.0031299933325499296,
-0.002407135907560587,
-0.007433743681758642,
-0.001911137136630714,
-0.007323302794247866,
0.000824527523946017,
0.004420015960931778,
-0.0028484726790338755,
-0.001169687369838357,
-0.004570735152810812,
0.006225980818271637,
0.0014452440664172173,
0.00110552366822958,
-0.019268233329057693,
-0.008402244187891483,
0.0021668998524546623,
0.0005367238773033023,
-0.0026494415942579508,
-0.004058120306581259,
0.0036298343911767006,
-0.01081889122724533,
0.0051756384782493114,
0.0022166359703987837,
-0.0006662602536380291,
-0.011825760826468468,
-0.004222423769533634,
-0.01073994766920805,
-0.008838357403874397,
0.0045389290899038315,
-0.006878644693642855,
-0.0037284689024090767,
-0.0015267902053892612,
-0.001492541516199708,
0.006734656635671854,
-0.005990835838019848,
0.003779413178563118,
0.012057196348905563,
0.00048144973698072135,
-0.007044237107038498,
0.008272976614534855,
0.004069789312779903,
0.0019752064254134893,
-0.00369208469055593,
0.004752402659505606,
0.0070210956037044525,
0.008166708052158356,
0.0037444517947733402,
0.004488996230065823,
0.002113707596436143,
0.0077852546237409115,
-0.0036814354825764894,
-0.0020699682645499706,
-0.005175451282411814,
0.002176681999117136,
-0.003512889612466097,
0.00015214532322715968,
-0.003772435011342168,
-0.002225491451099515,
-0.012659447267651558,
-0.009008466266095638,
-0.0012023486196994781,
-0.0007207280723378062,
0.0013732899678871036,
-0.002308228751644492,
0.0006096700089983642,
0.001482924446463585,
0.008012856356799603,
0.0011599658755585551,
-0.005789255723357201,
-0.0021121944300830364,
-0.0003935010463465005,
-0.004520780872553587,
0.014085373841226101,
-0.010957393795251846,
0.005677050445228815,
-0.0030903436709195375,
-0.014750683680176735,
0.004578785039484501,
0.00930023193359375,
-0.009336438030004501,
0.0011818832717835903,
0.003507820190861821,
0.005214639939367771,
-0.0012488695792853832,
-0.003916055895388126,
-0.006000423338264227,
-0.016469145193696022,
-0.0008070703479461372,
0.016593899577856064,
0.004127198364585638,
0.01264798454940319,
0.012544948607683182,
-0.0048830946907401085,
0.002532160608097911,
0.0083460146561265,
0.004296719096601009,
0.015377826988697052,
-0.01007774192839861,
0.0008946023299358785,
0.0026134802028536797,
-0.005103521980345249,
0.0012470678193494678,
0.006152098998427391,
0.003178501268848777,
-0.0064224679954349995,
0.0013106920523568988,
-0.00874563492834568,
-0.004467541351914406,
-0.015354016795754433,
-0.003945800010114908,
0.005197037011384964,
-0.0077338628470897675,
0.005469901021569967,
-0.01311242114752531,
0.005680672358721495,
0.0035637023393064737,
0.005267111584544182,
-0.00013876093726139516,
0.0019902295898646116,
0.007078489288687706,
0.013734628446400166,
-0.005045123398303986,
0.005084628239274025,
0.0032095008064061403,
-0.00297205476090312,
0.003163259942084551,
0.00993143580853939,
-0.007217635400593281,
-0.006256709806621075,
0.003204591339454055,
0.0040297009982168674,
0.0020937889348715544,
-0.00588400661945343,
-0.006867156829684973,
-0.0025591859593987465,
-0.0006446130573749542,
-0.006312710698693991,
0.0030960505828261375,
-0.0016131509328261018,
0.0037671613972634077,
-0.005291441921144724,
-0.0013325127074494958,
0.0015896683325991035,
-0.011559702455997467,
0.009036696515977383,
-0.002235777210444212,
0.003457000944763422,
0.013851221650838852,
0.0020436756312847137,
-0.015116964466869831,
0.005180825013667345,
0.008736318908631802,
-0.004153471905738115,
0.0036932185757905245,
0.005652336869388819,
-0.0070156860165297985,
-0.01965213567018509,
-0.0021718472708016634,
-0.014744195155799389,
0.005689563695341349,
-0.0015708047430962324,
0.002317819045856595,
-0.007651892490684986,
0.009598753415048122,
0.004654133692383766,
-0.012063426896929741,
-0.006083628628402948,
-0.009609028697013855,
0.009099667891860008,
0.0019407434156164527,
-0.00007437923341058195,
-0.004038328770548105,
-0.0018491096561774611,
-0.002439510077238083,
-0.0040281666442751884,
-0.002100169425830245,
0.0029158531688153744,
0.002202368574216962,
-0.0012188319815322757,
0.0027011330239474773,
-0.001644766191020608,
0.00183569872751832,
-0.00019650931062642485,
-0.009387143887579441,
-0.0005298816249705851,
0.005110172089189291,
-0.003261796198785305,
-0.006073072552680969,
0.002935680327937007,
-0.0024877539835870266,
-0.008560377173125744,
-0.011396149173378944,
-0.003825664985924959,
-0.0043895049020648,
-0.0023708445951342583,
-0.011786215007305145,
-0.005701812915503979,
-0.011959741823375225,
0.0062091657891869545,
-0.00494872871786356,
0.009597881697118282,
0.0024121892638504505,
-0.005576265510171652,
0.00697531970217824,
-0.0010475144954398274,
0.00538331875577569,
0.003188835456967354,
0.004456748254597187,
0.0004897702601738274,
-0.00522390753030777,
-0.00891566276550293,
0.008178026415407658,
-0.007562209852039814,
0.0012792814522981644,
0.01394606288522482,
0.0040584891103208065,
0.00796474888920784,
-0.003081725211814046,
0.0006047635106369853,
0.00010595161438686773,
0.009209300391376019,
-0.013857772573828697,
0.004701004363596439,
-0.004328376613557339,
0.0016514550661668181,
0.003454505931586027,
-0.0053699142299592495,
0.003835730953142047,
0.01222678367048502,
0.001694259000942111,
-0.006170815322548151,
-0.004461850505322218,
0.00128148403018713,
0.005892517976462841,
-0.01075627189129591,
0.0015211416175588965,
-0.0016051055863499641,
-0.004753353539854288,
-0.0015656208852306008,
-0.0039651351980865,
-0.0021639722399413586,
0.00576035538688302,
-0.0033702647779136896,
0.006222140975296497,
0.0037361520808190107,
-0.0063431523740291595,
0.014061718247830868,
-0.0036022753920406103,
-0.005071934312582016,
0.00395195884630084,
0.0013075614115223289,
-0.002062427345663309,
-0.006150531116873026,
-0.005221307277679443,
0.0020759757608175278,
0.0054153213277459145,
-0.005238065961748362,
-0.0043486617505550385,
-0.0005777066107839346,
0.00002904390566982329,
-0.008739122189581394,
0.0010395748540759087,
0.009919075295329094,
-0.003802507882937789,
0.007200092077255249,
0.0003480293380562216,
-0.00682902242988348,
-0.01213099341839552,
0.051051683723926544,
-0.00101994420401752,
0.0042450702749192715,
0.006430510431528091,
-0.007216013036668301,
0.0005463614361360669,
-0.0022592381574213505,
0.00907096080482006,
-0.006050169467926025,
-0.005626364145427942,
0.008270199410617352,
-0.0029855400789529085,
0.004137183539569378,
0.0015667587285861373,
-0.003616908797994256,
0.016051575541496277,
-0.003438027575612068,
-0.014072032645344734,
-0.017345020547509193,
0.0054007843136787415,
-0.004521533381193876,
-0.009345795027911663,
0.007757884915918112,
-0.0016670158365741372,
-0.007305901497602463,
0.0020053405314683914,
0.0067793200723826885,
0.0031091435812413692,
-0.002880951389670372,
-0.0024674904998391867,
0.0003494364209473133,
-0.0016276732785627246,
0.00517241982743144,
0.005533389747142792,
0.010908345691859722,
-0.002171644475311041,
0.0036308597773313522,
-0.005351382307708263,
-0.0035534226335585117,
-0.002383979270234704,
0.00445537781342864,
0.006649250164628029,
0.0005768825067207217,
0.00016377901192754507,
0.005118160042911768,
0.004987822845578194,
0.0005094008520245552,
0.008774901740252972,
0.00005729585973313078,
-0.003396014217287302,
0.008537622168660164,
0.007839472033083439,
-0.0005629069055430591,
0.00692274933680892,
-0.002331177005544305,
0.0069767190143466,
0.0008521160343661904,
-0.006894383579492569,
-0.016839170828461647,
0.00009964632045011967,
0.009337800554931164,
0.00883952435106039,
-0.003092884784564376,
0.002645948203280568,
-0.0011221704771742225,
-0.0034999980125576258,
-0.009130587801337242,
-0.006736666429787874,
0.000010037502761406358,
0.004154234658926725,
0.003993294667452574,
0.07235600799322128,
-0.008091744966804981,
-0.0019826889038085938,
-0.009939946234226227,
-0.0018582495395094156,
-0.0027015109080821276,
-0.0023620505817234516,
-0.0011465814895927906,
-0.002886574948206544,
0.0015872670337557793,
0.0017156210960820317,
-0.008456621319055557,
-0.012376967817544937,
0.0008024589042179286,
0.0036533745005726814,
-0.0038002559449523687,
0.0018881828291341662,
0.005921900738030672,
-0.009463775902986526,
0.0033346079289913177,
-0.01295679435133934,
-0.0006231381557881832,
-0.0011886997381225228,
-0.008418658748269081,
-0.005842923186719418,
-0.0020821248181164265,
0.005421345587819815,
0.004383119288831949,
0.0015209338162094355,
-0.003780278144404292,
0.0044122678227722645,
-0.002917459700256586,
-0.0011496410006657243,
-0.003556639887392521,
-0.00014139006088953465,
-0.00439337408170104,
0.006379671394824982,
0.0006100741447880864,
-0.010086465626955032,
-0.005890084896236658,
0.0014718115562573075,
-0.002199305919930339,
-0.008226515725255013,
0.0038169999606907368,
0.00019431114196777344,
0.004671682137995958,
-0.0050707426853477955,
0.0008857072098180652,
-0.005881240125745535,
0.0016704612644389272,
-0.013954628258943558,
0.004371021408587694,
-0.1667167991399765,
0.008695476688444614,
0.002108985325321555,
-0.004320865031331778,
-0.0014615077525377274,
-0.013727294281125069,
-0.006505577825009823,
0.005694550462067127,
0.009655332192778587,
0.003296556184068322,
-0.0011809966526925564,
0.0002058409299934283,
0.0057467310689389706,
0.0022450482938438654,
-0.0037658826913684607,
-0.0027897998224943876,
0.0031566673424094915,
-0.001735783414915204,
0.001770851667970419,
0.004179863724857569,
0.0029629445634782314,
0.009128027595579624,
-0.001824880950152874,
0.002910584444180131,
-0.00109666062053293,
-0.004991214256733656,
0.004666697699576616,
-0.0026972200721502304,
0.007665249519050121,
-0.0123794199898839,
-0.003964639734476805,
-0.002228220459073782,
-0.0019198294030502439,
-0.000525728682987392,
0.005160185042768717,
-0.0011989999329671264,
0.010521783493459225,
0.0029466338455677032,
-0.006999995093792677,
0.007214338053017855,
-0.01028995681554079,
0.030848151072859764,
0.002087665256112814,
0.005842246580868959,
-0.00015079563308972865,
-0.006252696271985769,
-0.005375869572162628,
0.011560474522411823,
0.003013196401298046,
0.012861594557762146,
-0.013277781195938587,
0.001230855705216527,
0.0048146541230380535,
0.018546363338828087,
-0.00424624839797616,
-0.009733459912240505,
-0.00811713095754385,
-0.0003455326077528298,
0.0020913586486130953,
0.008684937842190266,
0.00933558028191328,
-0.003708974923938513,
0.009719754569232464,
-0.0031210340093821287,
-0.022132955491542816,
0.004643294494599104,
-0.004457202740013599,
-0.006431001238524914,
0.00024199408653657883,
0.00704342732205987,
0.011049330234527588,
-0.0022365665063261986,
0.005074347369372845,
0.0008710467955097556,
0.006713910028338432,
-0.001062316121533513,
0.0052182637155056,
-0.001513984869234264,
0.00708234217017889,
-0.008136308752000332,
0.010422388091683388,
-0.005430905614048243,
-0.0010163203114643693,
0.003970060031861067,
-0.005499577149748802,
0.009918797761201859,
0.004793712869286537,
-0.00411057285964489,
-0.0005906185833737254,
-0.01154960785061121,
-0.0008121051359921694,
0.0037648119032382965,
0.00040190122672356665,
-0.009067808277904987,
0.003493854310363531,
0.0028972518630325794,
0.005926690995693207,
0.009679037146270275,
-0.010292159393429756,
0.00711059058085084,
0.004200573544949293,
-0.0061616674065589905,
-0.0003079310990869999,
-0.005323509685695171,
0.0043846252374351025,
0.0055928900837898254,
-0.006480362266302109,
-0.005932713393121958,
0.004748296923935413,
-0.007723816204816103,
-0.0034355726093053818,
0.006023949943482876,
-0.009620548225939274,
-0.006305787246674299,
0.00019857939332723618,
-0.010376942344009876,
-0.0016821596072986722
] |
8a50f54c898793f1acb00252a2b2f5ed4e326667 | 790 | py | Python | setup.py | skojaku/fastnode2vec | bb65f68469f00f489fa6744d35b8756200b4e285 | [
"MIT"
] | 61 | 2020-04-21T18:58:47.000Z | 2022-03-26T22:41:45.000Z | setup.py | skojaku/fastnode2vec | bb65f68469f00f489fa6744d35b8756200b4e285 | [
"MIT"
] | 17 | 2020-04-21T22:37:17.000Z | 2022-03-31T22:36:03.000Z | setup.py | skojaku/fastnode2vec | bb65f68469f00f489fa6744d35b8756200b4e285 | [
"MIT"
] | 6 | 2020-07-30T01:41:59.000Z | 2022-01-19T10:13:01.000Z | #!/usr/bin/env python3
import os
from setuptools import setup
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name="fastnode2vec",
version="0.0.5",
author="Louis Abraham",
license="MIT",
author_email="louis.abraham@yahoo.fr",
description="Fast implementation of node2vec",
long_description=read("README.md"),
long_description_content_type="text/markdown",
url="https://github.com/louisabraham/fastnode2vec",
packages=["fastnode2vec"],
install_requires=["numpy", "numba", "gensim", "click", "tqdm"],
python_requires=">=3.6",
entry_points={"console_scripts": ["fastnode2vec = fastnode2vec.cli:node2vec"]},
classifiers=["Topic :: Scientific/Engineering :: Artificial Intelligence"],
)
| 29.259259 | 83 | 0.694937 | 1 | 0.9141 | [
0.0007497284677810967,
0.022816723212599754,
0.0089865205809474,
-0.0008681859471835196,
0.005151662509888411,
-0.0022862704936414957,
-0.010645519010722637,
0.004829039331525564,
-0.008305155672132969,
0.0013940403005108237,
0.0016509321285411716,
0.005823380313813686,
0.0070917136035859585,
-0.0180804505944252,
0.0013060359051451087,
0.01748625375330448,
-0.05569513887166977,
0.0022235908545553684,
-0.004272926598787308,
0.0025412142276763916,
-0.007385717239230871,
0.011193785816431046,
0.007799237035214901,
0.008369388058781624,
0.005705326329916716,
0.000018962291505886242,
0.00923967082053423,
0.0018859007395803928,
-0.008251745253801346,
-0.0071555450558662415,
-0.0017090756446123123,
-0.0030634249560534954,
-0.006287354975938797,
-0.008224692195653915,
0.007393281906843185,
-0.0027112308889627457,
0.0003222940140403807,
-0.019559230655431747,
0.010210217908024788,
-0.005613900721073151,
-0.006467055529356003,
-0.016017960384488106,
-0.0002507849712856114,
0.004202304407954216,
-0.009502886794507504,
0.004205033648759127,
-0.0036761905066668987,
0.0030765801202505827,
-0.009342636913061142,
0.00646810932084918,
-0.010740411467850208,
0.006830974016338587,
0.014921465888619423,
0.004612505901604891,
-0.006025129929184914,
-0.006607051007449627,
0.012149705551564693,
0.0012424183078110218,
-0.011389522813260555,
0.0008547349134460092,
-0.003590626874938607,
-0.0014181564329192042,
0.00428499560803175,
0.005310072563588619,
-0.019158663228154182,
-0.009619670920073986,
-0.003976060077548027,
0.0015772783663123846,
-0.002671685302630067,
0.005774152465164661,
0.0010027720127254725,
-0.001909063197672367,
0.0066062696278095245,
0.0020285877399146557,
0.004463630262762308,
-0.0025659624952822924,
-0.0018428958719596267,
0.0018518323777243495,
0.010014902800321579,
0.004674588330090046,
0.003362613031640649,
-0.007497577928006649,
0.006357877049595118,
0.010218740440905094,
0.013870634138584137,
0.009217352606356144,
0.019469236955046654,
-0.010374407283961773,
0.046646781265735626,
0.005954984109848738,
-0.010125096887350082,
-0.00015494239050894976,
-0.00769329397007823,
-0.0015094135887920856,
-0.005096440203487873,
-0.030295345932245255,
0.001294230343773961,
-0.0031171217560768127,
-0.0007463291985914111,
0.004435924347490072,
-0.0018386075971648097,
0.004971552640199661,
-0.00305056176148355,
-0.0034923574421554804,
-0.010634098201990128,
0.012548906728625298,
-0.009298663586378098,
-0.002055180026218295,
0.008163812570273876,
0.002471833024173975,
-0.011583943851292133,
-0.0004997422220185399,
0.0015426183817908168,
-0.013096335344016552,
0.004712884780019522,
0.003720992710441351,
-0.004566344432532787,
0.054978206753730774,
-0.001228257198818028,
0.0007583566475659609,
-0.0044252583757042885,
0.00021583441412076354,
-0.00034450343810021877,
0.0063810329884290695,
0.009031934663653374,
-0.0031699168030172586,
0.013563549146056175,
0.007790921255946159,
0.0034489904064685106,
0.008607177063822746,
-0.0018627466633915901,
0.004957878030836582,
-0.003912079147994518,
-0.0017553918296471238,
-0.0007677256362512708,
-0.007977191358804703,
0.008709205314517021,
-0.0009108210797421634,
-0.007210000418126583,
0.0006428017513826489,
-0.0016403220361098647,
-0.011772040277719498,
0.0024546668864786625,
-0.0036346279084682465,
0.00195523863658309,
-0.011017431505024433,
-0.0037320093251764774,
-0.0013079143827781081,
-0.0038051046431064606,
0.0029274653643369675,
0.008236667141318321,
0.003762132953852415,
0.0038509778678417206,
-0.005006224848330021,
-0.009526737034320831,
-0.0020023216493427753,
-0.0027117144782096148,
0.0024942958261817694,
0.006083482410758734,
0.004211725201457739,
-0.010803023353219032,
-0.0017557821702212095,
0.003182303626090288,
0.005753774661570787,
-0.0023197403643280268,
0.003976371139287949,
-0.008393675088882446,
0.008979412727057934,
0.000171983745531179,
0.0023479925002902746,
0.010476789437234402,
-0.004236866720020771,
-0.0004268148331902921,
0.0006483764736913145,
0.0035797967575490475,
0.00038900214713066816,
0.005788488779217005,
0.010962869971990585,
-0.0043459488078951836,
-0.004329093266278505,
0.003460898296907544,
0.005914612673223019,
0.008431992493569851,
0.008731112815439701,
-0.003614069428294897,
0.0015054994728416204,
-0.002669883891940117,
-0.0004170487227384001,
0.005749654956161976,
-0.005236971192061901,
0.005765038542449474,
0.004543590825051069,
-0.014530942775309086,
-0.006737196817994118,
-0.0002055694058071822,
-0.009196816943585873,
0.0023594817612320185,
0.014022954739630222,
0.011946971528232098,
-0.0018183656502515078,
0.0023469445295631886,
-0.012378289364278316,
0.0006948962109163404,
0.0076997773721814156,
-0.000305016350466758,
-0.01272024679929018,
-0.956750750541687,
0.006422283127903938,
0.0026495102792978287,
-0.0025850865058600903,
0.0040019541047513485,
0.0006697273347526789,
0.002302690641954541,
0.004137588664889336,
0.014025040902197361,
-0.005354855675250292,
-0.006630390416830778,
-0.008854219689965248,
-0.012125938199460506,
0.0008562421426177025,
-0.009143433533608913,
-0.003555638249963522,
-0.006520926021039486,
-0.00705878296867013,
-0.00130634312517941,
-0.005569051019847393,
-0.0027324333786964417,
0.009893848560750484,
-0.0020106784068048,
0.004971784073859453,
0.003162639681249857,
0.004559209104627371,
-0.004110218025743961,
-0.001093371887691319,
-0.0007421664777211845,
-0.0037546793464571238,
-0.005373321007937193,
-0.01657566800713539,
-0.005642296280711889,
-0.0019487590761855245,
0.010179226286709309,
0.0019169299630448222,
0.008952244184911251,
-0.0004741486336570233,
0.0020113945938646793,
-0.007109303958714008,
0.003879895433783531,
0.0022914239671081305,
0.002902749925851822,
-0.03054301254451275,
-0.00025182851823046803,
0.00039263206417672336,
-0.008406433276832104,
0.00714212516322732,
0.0022606051061302423,
-0.001037260633893311,
-0.0023850686848163605,
-0.006891871336847544,
0.009566173888742924,
-0.008649234659969807,
0.007794290781021118,
-0.004718460142612457,
-0.007950786501169205,
-0.002131134970113635,
-0.00892211589962244,
0.0025368318893015385,
0.0035174714867025614,
-0.0042613050900399685,
-0.0041284142062067986,
-0.003960469737648964,
0.001612016698345542,
0.003590755630284548,
0.001797048724256456,
-0.01916038617491722,
-0.006251480896025896,
-0.0023842693772166967,
0.005751767661422491,
-0.003935863729566336,
-0.0038993069902062416,
0.00520726665854454,
-0.00971335917711258,
0.0074359518475830555,
0.00257406965829432,
-0.000827621843200177,
-0.009461783803999424,
0.0013302989536896348,
-0.008823486045002937,
-0.007124315947294235,
0.0023725684732198715,
-0.004988798405975103,
-0.0036637301091104746,
-0.0003431372460909188,
0.0010335342958569527,
0.0063748848624527454,
-0.004483933560550213,
0.0042929938063025475,
0.011256881058216095,
-0.0036161281168460846,
-0.008527759462594986,
0.005909229163080454,
0.006314435973763466,
0.0018672097939997911,
-0.002872675424441695,
0.0008577161352150142,
0.008800067007541656,
0.006488268729299307,
0.0029641396831721067,
0.005136542022228241,
0.0006026407354511321,
0.010688398964703083,
-0.0008710836409591138,
0.002894680481404066,
-0.004173786845058203,
-0.0027435997035354376,
-0.004402897786349058,
0.0007229807670228183,
-0.003654500236734748,
-0.0028341079596430063,
-0.011171599850058556,
-0.009434148669242859,
-0.0031168232671916485,
0.0010047535179182887,
0.0019379848381504416,
-0.003976226784288883,
-0.0008025057031773031,
0.0030345143750309944,
0.010617157444357872,
-0.0013874692376703024,
-0.004391305614262819,
0.00008207875362131745,
0.002437656046822667,
-0.005898552481085062,
0.014172393828630447,
-0.012039529159665108,
0.005952492821961641,
-0.0025995951145887375,
-0.015559385530650616,
0.007646102458238602,
0.007997535169124603,
-0.00770105654373765,
-0.0004013818106614053,
0.002482426119968295,
0.0021519612055271864,
-0.000397741881897673,
-0.0035775164142251015,
-0.004446450155228376,
-0.01827327348291874,
-0.000056073600717354566,
0.019803613424301147,
0.002894726814702153,
0.009286412969231606,
0.011879883706569672,
-0.0032516212668269873,
0.0021581423934549093,
0.004696343559771776,
0.0003268914297223091,
0.014744182117283344,
-0.008458402939140797,
-0.0007097850902937353,
0.002206772333011031,
-0.006208738777786493,
0.0015774555504322052,
0.005772019736468792,
0.0033793444745242596,
-0.0018293351167812943,
0.001626281999051571,
-0.00715074734762311,
-0.0045973677188158035,
-0.01756276935338974,
-0.0023737354204058647,
0.008651847019791603,
-0.005625631660223007,
0.00501858489587903,
-0.010158584453165531,
0.004993199370801449,
0.005787408445030451,
0.003729005344212055,
0.0016640886897221208,
0.0008458726806566119,
0.006510385777801275,
0.011011081747710705,
-0.007167583331465721,
0.0031092192512005568,
0.0019029324175789952,
-0.0024311544839292765,
0.0005953370709903538,
0.007035553455352783,
-0.00809425301849842,
-0.004138121381402016,
0.0031042322516441345,
0.0033826089929789305,
0.0016463689971715212,
-0.003564076730981469,
-0.007656273432075977,
-0.0036602600011974573,
0.0016138640930876136,
-0.005753819365054369,
0.004821339622139931,
0.002297611441463232,
0.004231772385537624,
-0.0074312337674200535,
0.0011666880454868078,
-0.002418027725070715,
-0.011626710183918476,
0.011044230312108994,
-0.0025285393930971622,
0.0010190033353865147,
0.012432238087058067,
0.004323903936892748,
-0.0136513477191329,
0.004968586843460798,
0.008743801154196262,
-0.004314865451306105,
0.0046091461554169655,
0.00606292812153697,
-0.005937464535236359,
-0.023275945335626602,
-0.0014992182841524482,
-0.01365405973047018,
0.006570084951817989,
-0.00338301295414567,
0.0019187582656741142,
-0.007105433847755194,
0.007588506676256657,
0.006571009289473295,
-0.013599878177046776,
-0.0034298724494874477,
-0.010727310553193092,
0.00795047078281641,
-0.001670605386607349,
-0.0007510805153287947,
-0.0036125716287642717,
-0.0019469737308099866,
-0.001788488938473165,
-0.0018491285154595971,
-0.002596350386738777,
0.005035530775785446,
0.0019083591178059578,
-0.004458311945199966,
0.002393776550889015,
-0.003379473928362131,
-0.0004155930073466152,
-0.0006296417559497058,
-0.009683285839855671,
0.0011997639667242765,
0.006507968530058861,
-0.001974170096218586,
-0.003574417205527425,
0.0015180407790467143,
-0.0005558017292059958,
-0.004908793605864048,
-0.010688957758247852,
-0.0051535675302147865,
-0.0026143493596464396,
-0.002538821194320917,
-0.012065938673913479,
-0.002299383981153369,
-0.011307462118566036,
0.005496847443282604,
-0.006437234580516815,
0.009161232970654964,
0.0009489150252193213,
-0.0048505086451768875,
0.005436148960143328,
-0.0013288194313645363,
0.005023297853767872,
0.00422583008185029,
0.008258841931819916,
0.0012024070601910353,
-0.006702607497572899,
-0.011246788315474987,
0.012181638740003109,
-0.00810298789292574,
0.002378892619162798,
0.01414155587553978,
0.003183642402291298,
0.010800730437040329,
-0.00014668017684016377,
0.00041938130743801594,
0.005805431865155697,
0.0076531777158379555,
-0.013908381573855877,
0.00376293808221817,
-0.003653242252767086,
0.000024921786462073214,
0.005014284513890743,
-0.003973396960645914,
0.0031902664341032505,
0.00942144077271223,
0.0029038903303444386,
-0.00762410880997777,
-0.0024029805790632963,
0.0007591024623252451,
0.004451346583664417,
-0.01192115992307663,
0.00014320101763587445,
-0.002286761999130249,
-0.0042685652151703835,
-0.0040036337450146675,
-0.003201819723471999,
-0.0006224063690751791,
0.005724675487726927,
-0.0024663805961608887,
0.007235806901007891,
0.0015968041261658072,
-0.0045206621289253235,
0.013949421234428883,
-0.006703200284391642,
-0.005932177882641554,
0.0029175328090786934,
0.0007241757703013718,
-0.002428812440484762,
-0.006294499151408672,
-0.005122656933963299,
0.0019222694681957364,
0.004558849614113569,
-0.001495668780989945,
-0.0030746818520128727,
-0.001405068556778133,
0.0008356755133718252,
-0.010136854834854603,
0.001127906609326601,
0.013245714828372002,
-0.0027576801367104053,
0.005742807872593403,
-0.0009753541671670973,
-0.006068094167858362,
-0.012464108876883984,
0.05284921079874039,
-0.0001279412826988846,
0.005591065622866154,
0.006280404981225729,
-0.0077245826832950115,
-0.0018600515322759748,
-0.001249715336598456,
0.00658593000844121,
-0.00758279487490654,
-0.009171178564429283,
0.011057637631893158,
-0.0035793036222457886,
0.0040506161749362946,
0.0016376447165384889,
-0.002496265573427081,
0.016004309058189392,
-0.003649948164820671,
-0.01852436177432537,
-0.015692049637436867,
0.007219622377306223,
-0.004533186089247465,
-0.008108383975923061,
0.006614666897803545,
-0.0028917447198182344,
-0.003909366205334663,
0.0013969381107017398,
0.0057017928920686245,
0.000915460754185915,
0.0014734257711097598,
-0.002735467627644539,
-0.0010956114856526256,
0.0000521578112966381,
0.0028602126985788345,
0.007326211780309677,
0.008321251720190048,
-0.0017524012364447117,
0.004095005337148905,
-0.0017047302098944783,
0.001056856825016439,
-0.0021062202285975218,
0.005172364879399538,
0.005832340568304062,
-0.0015811247285455465,
-0.0011431360617280006,
0.004886627662926912,
0.0033211850095540285,
0.0008524987497366965,
0.010295274667441845,
-0.00008520692790625617,
-0.004568514879792929,
0.010076942853629589,
0.006526335142552853,
-0.000534856750164181,
0.005414112936705351,
-0.0014585054013878107,
0.005432918202131987,
0.001660783658735454,
-0.007428262382745743,
-0.016955506056547165,
-0.0025136249605566263,
0.006977146491408348,
0.008083932101726532,
-0.0005641177413053811,
0.002306522335857153,
-0.001819828525185585,
-0.0032744077034294605,
-0.008640442043542862,
-0.00590527756139636,
-0.004540286958217621,
0.001992440316826105,
0.0014514257200062275,
0.07180305570363998,
-0.005356468725949526,
-0.0011809574207291007,
-0.008563879877328873,
-0.0008184867328964174,
-0.002829359145835042,
-0.003076659282669425,
0.0005736674065701663,
-0.003062061034142971,
0.002774608787149191,
0.000748459598980844,
-0.006619701161980629,
-0.010919561609625816,
0.000764999131206423,
0.001289882929995656,
-0.002284435322508216,
0.004672629293054342,
0.0057829306460917,
-0.011410676874220371,
0.0026251869276165962,
-0.01216384768486023,
-0.0050643980503082275,
-0.002226926852017641,
-0.00891214981675148,
-0.0027189666870981455,
-0.003516941098496318,
0.004576323088258505,
0.003995999228209257,
0.004576527513563633,
-0.0033552898094058037,
0.006088052876293659,
-0.0008968892507255077,
0.0013661407865583897,
-0.0036415301728993654,
0.0004570339515339583,
-0.005403741262853146,
0.0072128684259951115,
0.0005578116979449987,
-0.012392698787152767,
-0.005969514138996601,
-0.0030125894118100405,
-0.00033139227889478207,
-0.004534493666142225,
0.005685999058187008,
-0.0005884941201657057,
0.005682235583662987,
-0.003268578089773655,
0.0006645005778409541,
-0.00617553573101759,
-0.00011723670468199998,
-0.012714015319943428,
0.0058472068049013615,
-0.17930223047733307,
0.010633114725351334,
0.0027222693897783756,
-0.004342090338468552,
-0.0036302427761256695,
-0.01435037050396204,
-0.008893908001482487,
0.002723386976867914,
0.011618180200457573,
0.0019241714617237449,
0.00020183970627840608,
-0.00023585719463881105,
0.004093612544238567,
0.004309036768972874,
-0.0011832903837785125,
-0.005852531176060438,
0.0020276252180337906,
-0.00479377806186676,
0.0008969279588200152,
0.0046571996062994,
0.004776096437126398,
0.008868883363902569,
0.002860104665160179,
0.003369918093085289,
-0.00038182816933840513,
-0.0041076065972447395,
0.005658529233187437,
-0.0024158316664397717,
0.00732786301523447,
-0.011987625621259212,
-0.003347044577822089,
-0.0032004197128117085,
-0.004684723913669586,
-0.001095873536542058,
0.004392227157950401,
-0.0029938456136733294,
0.008586473762989044,
0.0008567632758058608,
-0.008612885139882565,
0.008949940092861652,
-0.008403818123042583,
0.028547747060656548,
0.0017144858138635755,
0.007110428996384144,
-0.00027107622008770704,
-0.004241270944476128,
-0.004295306745916605,
0.009184769354760647,
0.002550212200731039,
0.013159740716218948,
-0.013199378736317158,
-0.003696662141010165,
0.004370694048702717,
0.018667852506041527,
-0.004936602432280779,
-0.008276719599962234,
-0.007073552347719669,
-0.0047227442264556885,
0.0025049869436770678,
0.009355281479656696,
0.008567065000534058,
-0.0041334484703838825,
0.010267145931720734,
-0.003871089778840542,
-0.021452518180012703,
0.003987761214375496,
-0.003693814855068922,
-0.007649604696780443,
0.002052868017926812,
0.007738689426332712,
0.010569179430603981,
-0.0004698567499872297,
0.00488183181732893,
-0.0013038904871791601,
0.005895460490137339,
-0.0008354425081051886,
0.00825622957199812,
-0.002176290610805154,
0.0049713472835719585,
-0.009275742806494236,
0.008532951585948467,
-0.008484826423227787,
-0.003351372666656971,
0.0016518236370757222,
-0.004358405712991953,
0.011718520894646645,
0.003886568360030651,
-0.0029739956371486187,
-0.0015104402555152774,
-0.010750860907137394,
-0.002055969787761569,
0.0018246214604005218,
0.0021852466743439436,
-0.007861464284360409,
0.003379539120942354,
-0.0011198630090802908,
0.00523783965036273,
0.008332788944244385,
-0.007527780253440142,
0.007579611148685217,
0.0014802193036302924,
-0.005182470194995403,
0.0005356009351089597,
-0.004316140431910753,
0.003823205828666687,
0.0032126198057085276,
-0.006973892915993929,
-0.005686592776328325,
0.005122476257383823,
-0.006965181324630976,
-0.00510903587564826,
0.00747835636138916,
-0.01059042476117611,
-0.007975311949849129,
0.000012304371921345592,
-0.012407377362251282,
-0.0002064069121843204
] |
8a521621650bf40359a7bc7b59a9b8905567d6ce | 738 | py | Python | app/main/config.py | nhattvm11/flask-restful-boilerplate | a450c03c1b1db2886b4e00b2c30284a59d9b91e6 | [
"MIT"
] | null | null | null | app/main/config.py | nhattvm11/flask-restful-boilerplate | a450c03c1b1db2886b4e00b2c30284a59d9b91e6 | [
"MIT"
] | null | null | null | app/main/config.py | nhattvm11/flask-restful-boilerplate | a450c03c1b1db2886b4e00b2c30284a59d9b91e6 | [
"MIT"
] | null | null | null | import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
SECRET_KEY = os.getenv('SECRET_KEY', '')
DEBUG = False
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'flask_main.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
class TestingConfig(Config):
DEBUG = True
TESTING = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'flask_main.db')
PRESERVE_CONTEXT_ON_EXCEPTION = False
SQLALCHEMY_TRACK_MODIFICATIONS = False
class ProductionConfig(Config):
DEBUG = False
config_by_name = dict(
dev=DevelopmentConfig,
test=TestingConfig,
prod=ProductionConfig
)
key = Config.SECRET_KEY
| 21.085714 | 83 | 0.718157 | 1 | 0.8871 | [
0.0010810407111421227,
0.022703683003783226,
0.008437560871243477,
0.0026159805711358786,
0.004574979189783335,
-0.0027060434222221375,
-0.012026852928102016,
0.003197247162461281,
-0.007315522525459528,
0.0031041610054671764,
0.002041189931333065,
0.004528373945504427,
0.006286140065640211,
-0.018224261701107025,
0.0008855786290951073,
0.015768440440297127,
-0.05209354683756828,
0.002922702580690384,
-0.005112932994961739,
0.002451064996421337,
-0.007888239808380604,
0.008070094510912895,
0.007974253967404366,
0.0072747268714010715,
0.004331598058342934,
0.0005697953747585416,
0.008593718521296978,
0.00416158139705658,
-0.007893936708569527,
-0.006013695616275072,
-0.000733676424715668,
-0.002524791983887553,
-0.005018095951527357,
-0.007619426120072603,
0.006798073649406433,
-0.002031259471550584,
0.0007496637408621609,
-0.021289795637130737,
0.012552471831440926,
-0.004528926219791174,
-0.007112741470336914,
-0.016416974365711212,
-0.0018288376741111279,
0.0026041895616799593,
-0.010458420030772686,
0.0026887801941484213,
-0.005159907508641481,
0.005076695699244738,
-0.01219276525080204,
0.005445348098874092,
-0.010526925325393677,
0.006347955204546452,
0.01344868540763855,
0.0030701139476150274,
-0.007052388973534107,
-0.006521128583699465,
0.012514025904238224,
0.0026011765003204346,
-0.012001946568489075,
0.002038080943748355,
-0.004508297424763441,
-0.002256940584629774,
0.006025649607181549,
0.004610002040863037,
-0.016577135771512985,
-0.005398736800998449,
-0.002792605198919773,
0.0026763989590108395,
-0.0005281713674776256,
0.005237850826233625,
0.0006187005201354623,
-0.0022429078817367554,
0.00466555031016469,
0.0027641989290714264,
0.0037061546463519335,
-0.003951390739530325,
-0.0019680687692016363,
0.0029988333117216825,
0.011088346131145954,
0.0016418852610513568,
0.005011300556361675,
-0.007874231785535812,
0.00786428153514862,
0.010330595076084137,
0.014850910753011703,
0.007107440382242203,
0.01962057128548622,
-0.010202576406300068,
0.04636789485812187,
0.0041225263848900795,
-0.010814215987920761,
0.0013414178974926472,
-0.009871214628219604,
-0.0010083424858748913,
-0.001259434036910534,
-0.029355395585298538,
0.00039944282616488636,
-0.0042053465731441975,
0.0006150912959128618,
0.0040593924932181835,
-0.0015065233455970883,
0.005766844376921654,
-0.0015553695848211646,
-0.0032985317520797253,
-0.008001201786100864,
0.01064341887831688,
-0.008619443513453007,
-0.0014023898402228951,
0.006899197120219469,
0.0011660963064059615,
-0.010648981668055058,
-0.0005427124560810626,
0.003770391922444105,
-0.012305527925491333,
0.004728447645902634,
0.002664053812623024,
-0.004548160824924707,
0.054453521966934204,
0.0011713466374203563,
0.0030715030152350664,
-0.004539563320577145,
0.00001388749478792306,
0.00048785729450173676,
0.005955992732197046,
0.0068577965721488,
-0.0033039606641978025,
0.011610617861151695,
0.006301789078861475,
0.004025961738079786,
0.007079510483890772,
0.00030944833997637033,
0.0071300966665148735,
-0.005108032841235399,
-0.002134052338078618,
0.0020323924254626036,
-0.007286956999450922,
0.006357134319841862,
-0.002180545823648572,
-0.006594836711883545,
0.0012542473850771785,
0.0009676608024165034,
-0.012167127802968025,
0.001067347009666264,
-0.0035665056202560663,
0.002749952021986246,
-0.012746846303343773,
-0.005991207901388407,
-0.0013115914771333337,
-0.004840665962547064,
0.003143328009173274,
0.006269786972552538,
0.004303582478314638,
0.0029949212912470102,
-0.005536227021366358,
-0.008595316670835018,
-0.001333925873041153,
-0.0041988687589764595,
0.0027262100484222174,
0.0075488006696105,
0.0034631157759577036,
-0.010635853745043278,
-0.002442908938974142,
0.0031673589255660772,
0.003659944050014019,
-0.0005067502497695386,
0.002356632612645626,
-0.008659846149384975,
0.007710401900112629,
0.001175531535409391,
0.0040187896229326725,
0.010796193033456802,
-0.003529295092448592,
-0.0007429145625792444,
-0.00038685178151354194,
0.002169681480154395,
0.000055581058404641226,
0.00447999220341444,
0.010912646539509296,
-0.0033496825490146875,
-0.006875092629343271,
0.0027018534019589424,
0.004698804579675198,
0.008195661008358002,
0.011360338889062405,
-0.002986965235322714,
0.002711912617087364,
-0.003464078763499856,
-0.0004309577925596386,
0.004721460863947868,
-0.0050424267537891865,
0.006134410388767719,
0.003105827607214451,
-0.013470576144754887,
-0.008631345815956593,
0.0005630223313346505,
-0.009273854084312916,
0.0005966428434476256,
0.014762203209102154,
0.009989493526518345,
-0.002572117606177926,
0.002850322285667062,
-0.009357458911836147,
0.0005198979051783681,
0.007940582931041718,
0.0029261792078614235,
-0.013047248125076294,
-0.9574143290519714,
0.004133358132094145,
0.0026810516137629747,
0.0002966766769532114,
0.003414548235014081,
0.005133007653057575,
0.003983075264841318,
0.004289285745471716,
0.013572667725384235,
-0.011426307260990143,
-0.006424959748983383,
-0.010278014466166496,
-0.008412927389144897,
-0.002786638680845499,
-0.007005507592111826,
-0.0023752714041620493,
-0.0051508028991520405,
-0.006654072552919388,
-0.0030196011066436768,
-0.004863557871431112,
-0.0021281822118908167,
0.00948303285986185,
0.0016253424109891057,
0.0051704393699765205,
0.003855159506201744,
0.0029008665587753057,
-0.0017928563756868243,
0.0011900248937308788,
-0.0004989039152860641,
-0.004151979926973581,
-0.0069873398169875145,
-0.015663154423236847,
-0.005485277622938156,
-0.0007340922602452338,
0.011082940734922886,
0.000759835762437433,
0.008928775787353516,
0.0003284311678726226,
0.002575143938884139,
-0.010505588725209236,
0.0043658060021698475,
-0.00008934171637520194,
0.002153549110516906,
-0.03030264377593994,
0.0027840302791446447,
-0.0025684775318950415,
-0.007732330355793238,
0.008951598778367043,
0.00025299578555859625,
-0.00010440334881423041,
-0.004527492448687553,
-0.0034924964420497417,
0.009816056117415428,
-0.009613914415240288,
0.004761621821671724,
-0.006502542644739151,
-0.007287363987416029,
-0.0033433411736041307,
-0.009326882660388947,
0.0004949733847752213,
0.003960825502872467,
-0.002888281596824527,
-0.004482413176447153,
-0.000976755516603589,
0.0007864968501962721,
0.00046843686141073704,
0.0019449724350124598,
-0.017687855288386345,
-0.0056970263831317425,
-0.003269319422543049,
0.0009240371291525662,
-0.005281162913888693,
-0.004145072307437658,
0.004993870388716459,
-0.010010615922510624,
0.006537263747304678,
0.0024688427802175283,
0.001055647386237979,
-0.010043957270681858,
0.0021388933528214693,
-0.007232367061078548,
-0.010671324096620083,
0.0013201714027673006,
-0.006273368373513222,
-0.0038563476409763098,
0.0007315632537938654,
0.003753221593797207,
0.008972721174359322,
-0.0033585254568606615,
0.0037548497784882784,
0.012605780735611916,
-0.004802300129085779,
-0.009201054461300373,
0.008650613948702812,
0.007712392136454582,
0.0006108643137849867,
-0.000994852976873517,
0.003620538394898176,
0.009684481658041477,
0.00867786817252636,
0.004013747908174992,
0.005101191345602274,
0.00041705305920913815,
0.009218689054250717,
0.00012472497473936528,
0.003225241554901004,
-0.001906746649183333,
-0.003972440958023071,
-0.002921709092333913,
-0.0018940117442980409,
-0.004018264357000589,
-0.0013456896413117647,
-0.013762635178864002,
-0.008560985326766968,
-0.003417740575969219,
0.00003601576099754311,
-0.00023235300614032894,
-0.0018006589962169528,
0.0013573536416515708,
0.0034090951085090637,
0.009835277684032917,
0.003065042430534959,
-0.0018073417013511062,
0.0018471943913027644,
0.0028101319912821054,
-0.0062450626865029335,
0.0126540781930089,
-0.013979954645037651,
0.006683701649308205,
0.0007541364757344127,
-0.01666337437927723,
0.007668822072446346,
0.0102243572473526,
-0.009991180151700974,
0.0012223433004692197,
0.004354384262114763,
0.004761489573866129,
-0.00028180741355754435,
-0.004559545777738094,
-0.002609360497444868,
-0.016447994858026505,
0.000002924385853475542,
0.019307538866996765,
0.00040479053859598935,
0.010388928465545177,
0.012196446768939495,
-0.002035818761214614,
0.003387040225788951,
0.0071082087233662605,
0.00008521881682099774,
0.013101520016789436,
-0.009421057999134064,
-0.0028426693752408028,
0.0007206416921690106,
-0.004875221289694309,
0.0011950861662626266,
0.0038649544585496187,
0.006328715942800045,
-0.0032672067172825336,
0.0021302883978933096,
-0.004758268594741821,
-0.0041793216951191425,
-0.019390732049942017,
-0.000994891976006329,
0.007501992397010326,
-0.0035376879386603832,
0.004798153415322304,
-0.011239386163651943,
0.00647136103361845,
0.005996540188789368,
0.0021052006632089615,
-0.0011344481026753783,
0.0004144144768361002,
0.008701048791408539,
0.011117038317024708,
-0.008693819865584373,
0.0046871742233633995,
0.001383771188557148,
0.00004544052353594452,
0.0017545324517413974,
0.009424090385437012,
-0.009663872420787811,
-0.00766361877322197,
0.0030201503541320562,
0.0024246536195278168,
0.001662760623730719,
-0.0029374081641435623,
-0.00749057624489069,
-0.003544496838003397,
0.0027298210188746452,
-0.004223915748298168,
0.00428074412047863,
0.005018644500523806,
0.0033661951310932636,
-0.007312170695513487,
-0.000781560258474201,
-0.0038942708633840084,
-0.012695319019258022,
0.012320898473262787,
-0.003962596878409386,
0.0038807447999715805,
0.011090025305747986,
0.006207372527569532,
-0.012820880860090256,
0.007162843365222216,
0.007948300801217556,
-0.0050930180586874485,
0.0033901729620993137,
0.007307972759008408,
-0.007348309736698866,
-0.02431452088057995,
-0.0010608771117404103,
-0.013309101574122906,
0.006766615901142359,
-0.0039235264994204044,
0.0032663862220942974,
-0.0069360858760774136,
0.008466489613056183,
0.0028506494127213955,
-0.0141823198646307,
-0.0051070405170321465,
-0.008047848008573055,
0.009578491561114788,
-0.00044241512659937143,
-0.0014663382899016142,
-0.0026612388901412487,
-0.0003225980035495013,
-0.0040251039899885654,
-0.001920049893669784,
-0.0017837263876572251,
0.004825927317142487,
0.0026963758282363415,
-0.003931194543838501,
0.0016266715247184038,
-0.005950153339654207,
0.0010756755946204066,
0.002584271365776658,
-0.010932902805507183,
0.0039820061065256596,
0.004164214711636305,
-0.004039081744849682,
-0.005694861989468336,
0.00012527710350695997,
-0.0008472217596136034,
-0.007238655351102352,
-0.00966873113065958,
-0.002414123388007283,
-0.003904568962752819,
-0.0033346284180879593,
-0.009497593156993389,
-0.0002575692778918892,
-0.00817557517439127,
0.005430289544165134,
-0.0062348018400371075,
0.0071443901397287846,
0.006462565623223782,
-0.005273270420730114,
0.007129416801035404,
-0.002388295251876116,
0.003598692361265421,
0.003507413202896714,
0.005833176895976067,
-0.0005560470162890851,
-0.006101638078689575,
-0.00980627816170454,
0.01094846986234188,
-0.008564085699617863,
-0.0010898951441049576,
0.013583464547991753,
0.005516161676496267,
0.00892554223537445,
0.0007382705807685852,
-0.0009577600285410881,
0.004701846279203892,
0.008485769852995872,
-0.014003898948431015,
0.00106236117426306,
0.00025676400400698185,
0.0003923522017430514,
0.005328789819031954,
-0.004487609025090933,
0.004569913260638714,
0.007829821668565273,
0.0029087455477565527,
-0.007237795274704695,
-0.002123685786500573,
0.0005654552369378507,
0.0042291064746677876,
-0.012544510886073112,
0.0006348042516037822,
-0.005659257527440786,
-0.004028782248497009,
-0.0035643407609313726,
-0.003334996523335576,
-0.001057417830452323,
0.006215980276465416,
-0.0020036480855196714,
0.005033449269831181,
0.0017816631589084864,
-0.0026036198250949383,
0.015256666578352451,
-0.005215710029006004,
-0.004875876009464264,
0.001920033129863441,
-0.0003864694444928318,
-0.0026919834781438112,
-0.008121355436742306,
-0.002185078337788582,
0.002054148353636265,
0.0035344099160283804,
-0.0014826414408162236,
-0.006723752710968256,
-0.002362617291510105,
0.004266953561455011,
-0.007395660039037466,
0.0016632340848445892,
0.008979704231023788,
-0.0010409732349216938,
0.0049974084831774235,
-0.000807874312158674,
-0.008349694311618805,
-0.013543752953410149,
0.053039949387311935,
-0.003142117988318205,
0.004887842573225498,
0.004299253225326538,
-0.0072624897584319115,
-0.003124652896076441,
-0.00323334033600986,
0.005815459880977869,
-0.006211583036929369,
-0.007383385673165321,
0.007933620363473892,
-0.003514097072184086,
0.004344656132161617,
0.0030542511958628893,
-0.0019347998313605785,
0.0162655059248209,
-0.0067559173330664635,
-0.017302121967077255,
-0.016180094331502914,
0.0071183666586875916,
-0.005182168446481228,
-0.008565833792090416,
0.008077271282672882,
-0.002901635132730007,
-0.0033533014357089996,
0.0003292867913842201,
0.0038117750082165003,
0.0006681970553472638,
-0.00125654018484056,
-0.004048240836709738,
-0.0006295737694017589,
-0.000808140670415014,
0.003992676734924316,
0.008432558737695217,
0.005870217457413673,
-0.0028995636384934187,
0.0030676694586873055,
-0.0035178244579583406,
0.0010463653597980738,
-0.00012035123654641211,
0.003282965859398246,
0.006903877016156912,
-0.0016936425818130374,
-0.0016088861739262938,
0.004596262238919735,
0.003927263896912336,
0.0004622286942321807,
0.009712672792375088,
0.0006717568030580878,
-0.00468629552051425,
0.006648858077824116,
0.008782656863331795,
-0.0013168270234018564,
0.005766912363469601,
-0.0041374326683580875,
0.0038129889871925116,
0.0012622888898476958,
-0.006128773558884859,
-0.01572718285024166,
-0.002585998270660639,
0.006554993335157633,
0.005977742373943329,
-0.0007843713974580169,
0.003430059412494302,
-0.002542031230404973,
-0.0028209660667926073,
-0.008393913507461548,
-0.006232263054698706,
-0.0028277270030230284,
-0.0004311199299991131,
0.0034013548865914345,
0.06962556391954422,
-0.005881438031792641,
-0.0017604221357032657,
-0.00948254019021988,
-0.0014109098119661212,
-0.001096152700483799,
-0.0008502046694047749,
0.0006675552576780319,
-0.001613853732123971,
0.000849741802085191,
0.00347271584905684,
-0.008385585620999336,
-0.011533960700035095,
0.0021742447279393673,
0.003088671714067459,
-0.002979044336825609,
0.002972047310322523,
0.006740703247487545,
-0.00902357418090105,
0.0029701567254960537,
-0.010161633603274822,
-0.002967065665870905,
-0.002909999340772629,
-0.00802831444889307,
-0.002396382624283433,
-0.0054277051240205765,
0.0019939374178647995,
0.002922066254541278,
0.008025377057492733,
-0.0018919388530775905,
0.005968139506876469,
-0.0019091467838734388,
-0.0010013434803113341,
-0.003968380391597748,
-0.0006780386902391911,
-0.004455077461898327,
0.007420205511152744,
0.00271669402718544,
-0.009382982738316059,
-0.004654851742088795,
-0.0015782047994434834,
-0.001200069673359394,
-0.006128373555839062,
0.0036438030656427145,
0.000011042556252505165,
0.006258441600948572,
-0.002965907333418727,
0.0009393859654664993,
-0.006243336480110884,
0.0022469565737992525,
-0.012090878561139107,
0.0034953488502651453,
-0.1792372763156891,
0.01154558639973402,
0.0032054386101663113,
-0.005271362140774727,
-0.007361237891018391,
-0.017119910567998886,
-0.008405591361224651,
0.0039989883080124855,
0.011888142675161362,
0.0030825368594378233,
-0.003545930841937661,
0.00023166366736404598,
0.005704812705516815,
0.002686805324628949,
-0.003002402139827609,
-0.005198859144002199,
0.0034520914778113365,
-0.005408376455307007,
-0.0005773220909759402,
0.00540269585326314,
0.00605010287836194,
0.008954275399446487,
0.000939596735406667,
0.0012860813876613975,
-0.0028653573244810104,
-0.00397886335849762,
0.006454215385019779,
-0.0027788877487182617,
0.004805103410035372,
-0.011318070814013481,
-0.003667163196951151,
-0.004807548131793737,
-0.001642028451897204,
0.004570746328681707,
0.0059156883507966995,
0.0003945378994103521,
0.007166622672230005,
0.003015196183696389,
-0.007360852789133787,
0.00840851105749607,
-0.00563221238553524,
0.027307452633976936,
0.009345750324428082,
0.009467342868447304,
0.003309255000203848,
-0.005995164625346661,
-0.00350677571259439,
0.00931867677718401,
0.0017568747280165553,
0.013103156350553036,
-0.01219945028424263,
-0.003609155071899295,
0.0011072719935327768,
0.01997656747698784,
-0.005822222679853439,
-0.008546439930796623,
-0.0074426596984267235,
-0.0036199181340634823,
0.005121960770338774,
0.010274693369865417,
0.009713574312627316,
-0.003628083737567067,
0.00907140038907528,
-0.00532967783510685,
-0.01841454580426216,
0.002977102529257536,
-0.004293329548090696,
-0.007048028986901045,
0.0004969891742803156,
0.005224238615483046,
0.011314024217426777,
0.00020630753715522587,
0.0007183774723671377,
-0.0011525320587679744,
0.0053687016479671,
-0.0001292827510042116,
0.007764585316181183,
-0.0022775758989155293,
0.005247577093541622,
-0.0077580418437719345,
0.009234015829861164,
-0.010758950375020504,
-0.0031398979481309652,
0.001282347016967833,
-0.002844468457624316,
0.010669827461242676,
0.004302144981920719,
-0.0036348302382975817,
-0.000046428995119640604,
-0.009801345877349377,
-0.002482393989339471,
0.0008196542039513588,
0.0015182661591097713,
-0.007299345452338457,
0.0022521300707012415,
0.0003920111630577594,
0.005964470095932484,
0.006866296753287315,
-0.0097823366522789,
0.005794655531644821,
0.004800110124051571,
-0.008081053383648396,
0.00071701843990013,
-0.0029442193917930126,
0.0008886956493370235,
0.0037564903032034636,
-0.006846655160188675,
-0.007390064653009176,
0.0032723648473620415,
-0.006929255090653896,
-0.005835012998431921,
0.00662375008687377,
-0.010473238304257393,
-0.009152035228908062,
-0.000002264332351842313,
-0.009997464716434479,
0.00015400188567582518
] |
8a522d6b63aaba15a267dd005faa4b6a9a20a8c0 | 946 | py | Python | Chapter07/library/check_user_py3.py | djouani/Learning-Ansible-2.X-Third-Edition | 34d6745c2bde8367ad2db7c9343bc8477b0643d7 | [
"MIT"
] | 22 | 2019-04-22T02:13:39.000Z | 2021-10-01T22:03:51.000Z | Chapter07/library/check_user_py3.py | djouani/Learning-Ansible-2.X-Third-Edition | 34d6745c2bde8367ad2db7c9343bc8477b0643d7 | [
"MIT"
] | 1 | 2019-12-12T20:22:43.000Z | 2020-08-30T17:13:00.000Z | Chapter07/library/check_user_py3.py | djouani/Learning-Ansible-2.X-Third-Edition | 34d6745c2bde8367ad2db7c9343bc8477b0643d7 | [
"MIT"
] | 25 | 2019-04-09T04:29:50.000Z | 2021-12-22T22:17:14.000Z | #!/usr/bin/env python
import pwd
from ansible.module_utils.basic import AnsibleModule
class User:
def __init__(self, user):
self.user = user
# Check if user exists
def check_if_user_exists(self):
try:
user = pwd.getpwnam(self.user)
success = True
ret_msg = 'User %s exists' % self.user
except KeyError:
success = False
ret_msg = 'User %s does not exists' % self.user
return success, ret_msg
def main():
# Parsing argument file
module = AnsibleModule(
argument_spec = dict(
user = dict(required=True)
)
)
user = module.params.get('user')
chkusr = User(user)
success, ret_msg = chkusr.check_if_user_exists()
# Error handling and JSON return
if success:
module.exit_json(msg=ret_msg)
else:
module.fail_json(msg=ret_msg)
if __name__ == "__main__":
main()
| 23.073171 | 59 | 0.599366 | 1 | 0.9546 | [
0.00204598275013268,
0.0262062419205904,
0.006556274369359016,
-0.0005226365174166858,
0.004423763602972031,
-0.0023663202300667763,
-0.011294121854007244,
0.003251331392675638,
-0.008056700229644775,
0.001395409693941474,
0.0023396306205540895,
0.007315716240555048,
0.007597974967211485,
-0.017655549570918083,
-0.001874796929769218,
0.015981266275048256,
-0.05259418487548828,
0.0016548014245927334,
-0.0023743256460875273,
0.002529166406020522,
-0.007679106201976538,
0.009334088303148746,
0.008159114979207516,
0.0072583360597491264,
0.006890763528645039,
0.001611668965779245,
0.011162622831761837,
0.0027756134513765574,
-0.005868652369827032,
-0.007681226823478937,
-0.00013184937415644526,
-0.0010983239626511931,
-0.004429030232131481,
-0.006078080274164677,
0.006392037495970726,
-0.003857130417600274,
-0.0003514169075060636,
-0.019068364053964615,
0.012805311940610409,
-0.008085132576525211,
-0.00718805193901062,
-0.017114127054810524,
-0.004949170630425215,
0.006343979854136705,
-0.008817766793072224,
0.0032474217005074024,
-0.006136247422546148,
0.0006891806842759252,
-0.010518915951251984,
0.006637214682996273,
-0.009459070861339569,
0.00502443965524435,
0.012423509731888771,
0.0017870781011879444,
-0.00692188274115324,
-0.009627850726246834,
0.011655980721116066,
-0.0009978818707168102,
-0.010464641265571117,
0.00043588763219304383,
-0.002587241120636463,
-0.001834304304793477,
0.006941835395991802,
0.0030443419236689806,
-0.015459894202649593,
-0.008004621602594852,
-0.004509049467742443,
0.0012838043039664626,
-0.0009460588917136192,
0.006113769486546516,
-0.0005008659791201353,
-0.0023869420401751995,
0.008905338123440742,
0.004872222896665335,
0.006559747736901045,
-0.0028043005149811506,
-0.002278597792610526,
0.0003133780264761299,
0.008822910487651825,
0.006669619120657444,
0.003494983771815896,
-0.00821054819971323,
0.00994230154901743,
0.007371821906417608,
0.014036995358765125,
0.00742348562926054,
0.02029387280344963,
-0.010103588923811913,
0.046890366822481155,
0.00872682873159647,
-0.009538532234728336,
0.0019360260339453816,
-0.009573839604854584,
-0.00217950576916337,
-0.006381522864103317,
-0.030776411294937134,
0.0017953545320779085,
-0.0032457306515425444,
-0.00339245842769742,
0.0051148454658687115,
0.001139546395279467,
0.0032191933132708073,
0.0001959022629307583,
-0.0032178147230297327,
-0.009694483131170273,
0.012771563604474068,
-0.01303774956613779,
-0.0032686761114746332,
0.004260139539837837,
0.002667931839823723,
-0.01113332249224186,
-0.0010225182631984353,
0.0011705722426995635,
-0.011635039933025837,
0.0032593137584626675,
0.0019612780306488276,
-0.004022267181426287,
0.05418988689780235,
0.00014528846077155322,
0.005392067134380341,
-0.004010526929050684,
0.0021403443533927202,
-0.002890242263674736,
0.0047810557298362255,
0.011258129961788654,
-0.0030144716147333384,
0.009021248668432236,
0.006368216127157211,
0.0010035804007202387,
0.009324419312179089,
-0.0036765604745596647,
0.007574348710477352,
-0.005907990038394928,
-0.00026872329181060195,
0.0017295752186328173,
-0.00999243650585413,
0.007221781648695469,
-0.0015104631893336773,
-0.005902118980884552,
0.0004143376718275249,
0.0014195111580193043,
-0.010790854692459106,
0.0027987745124846697,
-0.0025425567291677,
0.004039897117763758,
-0.010275977663695812,
-0.006825171876698732,
-0.003267797874286771,
-0.0030698233749717474,
0.0025519432965666056,
0.011123741045594215,
0.0044447509571909904,
0.002906483132392168,
-0.002799058798700571,
-0.007620969321578741,
-0.0011172862723469734,
-0.006615093443542719,
0.0019844837952405214,
0.005458296742290258,
0.005124066956341267,
-0.01087450422346592,
-0.001998163526877761,
0.0026099334936589003,
0.0046910978853702545,
0.0004687317705247551,
0.0003842675359919667,
-0.00780990906059742,
0.0072539737448096275,
0.0034538647159934044,
0.004925860092043877,
0.011110288091003895,
-0.005976537242531776,
-0.0022231265902519226,
0.0007900433265604079,
0.002084018662571907,
0.001457956968806684,
0.004590081982314587,
0.009350139647722244,
-0.006111771799623966,
-0.0038296363782137632,
0.004176577087491751,
0.005085424054414034,
0.010011809878051281,
0.007306910585612059,
-0.003884012345224619,
0.0016204792773351073,
-0.004764277022331953,
-0.0012469738721847534,
0.006307048257440329,
-0.005475889891386032,
0.005787812639027834,
0.005481132306158543,
-0.01512643788009882,
-0.009397030808031559,
0.0006559401517733932,
-0.009627853520214558,
-0.0001581907708896324,
0.01165673229843378,
0.010559266433119774,
-0.005241486709564924,
0.0014505709987133741,
-0.009136402048170567,
0.00016060769848991185,
0.008498317562043667,
0.0013433065032586455,
-0.01281777210533619,
-0.9571539759635925,
0.006739492062479258,
0.0034680645912885666,
-0.0027543948963284492,
0.0074540418572723866,
0.0009556636214256287,
0.003045676974579692,
0.004919789731502533,
0.014306479133665562,
-0.011713488027453423,
-0.005364434327930212,
-0.009516719728708267,
-0.010765631683170795,
-0.0023021104279905558,
-0.006177213508635759,
-0.002269204705953598,
-0.0062408288940787315,
-0.006972183007746935,
-0.004876095335930586,
-0.0013501506764441729,
-0.002720832359045744,
0.009033852256834507,
-0.0018437947146594524,
0.004431879613548517,
0.00038366991793736815,
0.001547306659631431,
-0.005708229728043079,
-0.0025684565771371126,
-0.0009725542040541768,
-0.001762342406436801,
-0.006316227838397026,
-0.01598605141043663,
-0.0011474062921479344,
-0.0007421225891448557,
0.01251167245209217,
0.001495405682362616,
0.00841707456856966,
-0.0033257720060646534,
0.00131630664691329,
-0.00884253904223442,
0.0033615718130022287,
0.0015234262682497501,
0.003241075435653329,
-0.029649382457137108,
-0.000015082595382409636,
-0.00021057407138869166,
-0.008129355497658253,
0.008218388073146343,
0.0009869150817394257,
-0.0023640880826860666,
-0.0004593547200784087,
-0.005240969359874725,
0.011490723118185997,
-0.00830724835395813,
0.005109385587275028,
-0.0030258866026997566,
-0.006911686155945063,
-0.0035334809217602015,
-0.009113829582929611,
0.0028568515554070473,
0.005333723034709692,
-0.0026586472522467375,
-0.0066610402427613735,
-0.003265255829319358,
0.002788589335978031,
0.0024875644594430923,
0.0033366724383085966,
-0.017277425155043602,
-0.005156693514436483,
-0.002705237129703164,
0.0008899043314158916,
-0.002420365344733,
-0.0041889105923473835,
0.0062614502385258675,
-0.0089119803160429,
0.005919318646192551,
0.0013730452628806233,
-0.0002981339057441801,
-0.014158470556139946,
0.002281775465235114,
-0.010480687953531742,
-0.00734780915081501,
0.0030953078530728817,
-0.0050762421451509,
-0.005413326434791088,
0.0008482628618367016,
0.001473748474381864,
0.0064530507661402225,
-0.0031410406809300184,
0.003459632396697998,
0.010757979936897755,
-0.0034501338377594948,
-0.008535481058061123,
0.00573880597949028,
0.008384100161492825,
-0.0001842466153902933,
0.00018108304357156157,
0.003346737241372466,
0.008941514417529106,
0.007353795692324638,
0.0019286066526547074,
0.004991937428712845,
0.000028645279599004425,
0.008603017777204514,
-0.000005938049525866518,
0.0023775033187121153,
-0.0012246082769706845,
-0.00013217332889325917,
-0.004049062728881836,
0.001565812504850328,
-0.005649529863148928,
-0.0035946236457675695,
-0.012136868201196194,
-0.008169690147042274,
-0.005414814222604036,
0.0014120069099590182,
0.00334299448877573,
-0.003327149199321866,
-0.001055984292179346,
0.001689700409770012,
0.008589048869907856,
0.0007935145404189825,
-0.0017156683607026935,
0.0018643856747075915,
0.0036518187262117863,
-0.006665263324975967,
0.014654891565442085,
-0.011640448123216629,
0.005421675741672516,
-0.0015992643311619759,
-0.01732354611158371,
0.00872731488198042,
0.009717036969959736,
-0.010935518890619278,
0.003862427081912756,
0.00408726604655385,
0.0034989737905561924,
-0.0010397835867479444,
-0.005232620052993298,
-0.003484315238893032,
-0.01560142356902361,
-0.0003764152352232486,
0.02146039716899395,
0.0003213343443349004,
0.010386736132204533,
0.010889727622270584,
-0.00401646550744772,
0.0035210782662034035,
0.004021305590867996,
-0.0003515474672894925,
0.011378580704331398,
-0.0063016233034431934,
-0.00029098871164023876,
0.0014375293394550681,
-0.005838731303811073,
0.000906251952983439,
0.00508706271648407,
0.005159992724657059,
-0.002818360226228833,
0.0025463467463850975,
-0.006481481716036797,
-0.0043769157491624355,
-0.017130790278315544,
-0.005071209277957678,
0.0062886676751077175,
-0.005569813773036003,
0.003931152634322643,
-0.011388948187232018,
0.005535291973501444,
0.009165149182081223,
0.004425509367138147,
-0.00013984263932798058,
0.0005314114969223738,
0.0038592752534896135,
0.01031939685344696,
-0.0055248793214559555,
0.004772919230163097,
0.0018938902067020535,
0.0017388699343428016,
-0.0005218115984462202,
0.005070904269814491,
-0.008377150632441044,
-0.0031932538840919733,
0.002474402077496052,
0.002895904937759042,
0.0011143817100673914,
-0.002361334627494216,
-0.008527486585080624,
-0.0049482849426567554,
0.0039199297316372395,
-0.005445090588182211,
0.0041364342905581,
0.0004905024543404579,
0.0036162741016596556,
-0.0086758341640234,
0.00037699550739489496,
-0.002462895354256034,
-0.010917747393250465,
0.008896314539015293,
-0.003572334535419941,
0.0019288857001811266,
0.011381496675312519,
0.0040458133444190025,
-0.011849135160446167,
0.006727335974574089,
0.007703112903982401,
-0.00493764178827405,
0.005742579232901335,
0.0042162067256867886,
-0.004301931243389845,
-0.01995568536221981,
-0.0030527987983077765,
-0.0134833212941885,
0.006248810328543186,
-0.0004851946432609111,
0.005702442955225706,
-0.009394240565598011,
0.007993046194314957,
0.0050896527245640755,
-0.014568481594324112,
-0.005102977156639099,
-0.009493635036051273,
0.008152575232088566,
0.00010340751759940758,
-0.00286887283436954,
-0.0043311393819749355,
-0.0035446740221232176,
-0.001121232402510941,
-0.001502860221080482,
-0.0024139336310327053,
0.004886234644800425,
0.0012738228542730212,
-0.0034048722591251135,
0.002105194376781583,
-0.0031512845307588577,
-0.00018577443552203476,
0.0009968216763809323,
-0.01128903217613697,
0.004025169648230076,
0.004953023977577686,
-0.0037607704289257526,
-0.0026671707164496183,
0.001056102104485035,
-0.0004179305105935782,
-0.0037241035606712103,
-0.01280264649540186,
-0.001068016281351447,
-0.003979451488703489,
-0.002413094975054264,
-0.01068753469735384,
-0.003350266721099615,
-0.007365058641880751,
0.006913099437952042,
-0.010373192839324474,
0.00642634741961956,
0.006970727350562811,
-0.006634092424064875,
0.008772364817559719,
-0.002820211462676525,
0.002804559888318181,
0.002420021453872323,
0.003746362403035164,
0.0035426330287009478,
-0.005662211682647467,
-0.00958693865686655,
0.012572811916470528,
-0.009933513589203358,
0.000022343565433402546,
0.01350326742976904,
0.003828336950391531,
0.009465987794101238,
0.0008021245594136417,
-0.0015338483499363065,
0.0031140546780079603,
0.009362821467220783,
-0.012639726512134075,
0.004976933356374502,
-0.0024056227412074804,
0.0006591450073756278,
0.007001299411058426,
-0.0018575179856270552,
0.0006943587795831263,
0.009021195583045483,
0.002022853121161461,
-0.0059960209764540195,
-0.0013125184923410416,
0.002230845857411623,
0.006597475148737431,
-0.014762547798454762,
0.0007584886625409126,
-0.0040824864991009235,
-0.004163926467299461,
-0.00479783583432436,
-0.0014421956147998571,
-0.00031488307286053896,
0.00527920899912715,
-0.002581496722996235,
0.005841831211000681,
0.0024013365618884563,
-0.0024873847141861916,
0.015605335123836994,
-0.003408410120755434,
-0.005223679821938276,
0.0032974816858768463,
0.0029855987522751093,
-0.0015637645265087485,
-0.0059142629615962505,
-0.0006158608011901379,
0.0022878742311149836,
0.005565873347222805,
-0.0035153492353856564,
-0.005684085190296173,
-0.0008801461663097143,
0.0010217363014817238,
-0.009426498785614967,
0.00017950010078493506,
0.014103035442531109,
-0.003135501639917493,
0.004789344035089016,
-0.0013581053353846073,
-0.006458192132413387,
-0.013473186641931534,
0.05223934352397919,
0.0020703021436929703,
0.005852964241057634,
0.0047894688323140144,
-0.005653887987136841,
-0.0012123332126066089,
-0.0019997102208435535,
0.006954018026590347,
-0.007960543036460876,
-0.010153952986001968,
0.009468276053667068,
-0.002756331581622362,
0.0040936958976089954,
0.0004381798207759857,
-0.0005601009470410645,
0.016049759462475777,
-0.003711647354066372,
-0.014566928148269653,
-0.016773076727986336,
0.010183513164520264,
-0.00621384009718895,
-0.008408457040786743,
0.007311454974114895,
-0.0029928917065262794,
-0.0038818083703517914,
0.0010148599976673722,
0.004480409435927868,
0.00016130119911395013,
0.0026648519560694695,
-0.0046755969524383545,
-0.0026775868609547615,
0.0017022985266521573,
0.0021621244959533215,
0.00432449160143733,
0.010570589452981949,
-0.0033857105299830437,
0.0038712515961378813,
-0.0007211570627987385,
-0.0018809959292411804,
-0.0005812348681502044,
0.003355775959789753,
0.008111417293548584,
-0.0007464907830581069,
-0.00411220034584403,
0.0043396903201937675,
0.0035919698420912027,
0.0022170853335410357,
0.012025820091366768,
0.0013075468596071005,
-0.004518359433859587,
0.007304563652724028,
0.007088496349751949,
0.00041376551962457597,
0.009618558920919895,
-0.0019481884082779288,
0.004521831404417753,
0.0023471107706427574,
-0.005658959504216909,
-0.015927515923976898,
-0.0026963739655911922,
0.004592237528413534,
0.008343088440597057,
-0.0019038185710087419,
0.0036225372459739447,
-0.0003122052294202149,
-0.001647499855607748,
-0.0071566239930689335,
-0.009943146258592606,
-0.0039983391761779785,
-0.0009591810521669686,
0.0034473317209631205,
0.07057493925094604,
-0.00611256854608655,
-0.0013348369393497705,
-0.007905324921011925,
-0.0003861623990815133,
-0.000346935325069353,
-0.00013928736734669656,
-0.00040215608896687627,
-0.003188305301591754,
0.0017464237753301859,
0.004022370558232069,
-0.008019814267754555,
-0.009166965261101723,
0.001547487685456872,
0.0014933992642909288,
-0.006030943710356951,
0.007646738551557064,
0.007689556106925011,
-0.007909135892987251,
0.002329598879441619,
-0.011793096549808979,
-0.003634513821452856,
-0.00478315819054842,
-0.01162612996995449,
-0.005368479993194342,
-0.0035180351696908474,
0.003926517441868782,
0.0033335096668452024,
0.004565896932035685,
-0.003080811118707061,
0.00541726453229785,
0.00016671547200530767,
0.0001820754405343905,
-0.005701575428247452,
0.0008859953377395868,
-0.007552625145763159,
0.00618233485147357,
0.005341800395399332,
-0.012089982628822327,
-0.0055556283332407475,
-0.001017795060761273,
0.000041539246012689546,
-0.006606039125472307,
0.002835808089002967,
-0.00007320983422687277,
0.004480212926864624,
-0.002732624765485525,
-0.0009228978306055069,
-0.007867727428674698,
0.0018731734016910195,
-0.011863050051033497,
0.006663855630904436,
-0.17825448513031006,
0.011626126244664192,
0.0010711540235206485,
-0.004835302475839853,
-0.0034780714195221663,
-0.016880357638001442,
-0.005799814127385616,
0.004285958595573902,
0.011495636776089668,
-0.0007073601009324193,
-0.0014210471417754889,
-0.0009173990110866725,
0.005360902287065983,
0.005641840863972902,
0.0014534476213157177,
-0.007340915501117706,
0.0033559927251189947,
-0.0046609435230493546,
0.001265263999812305,
0.004058597609400749,
0.003426518989726901,
0.0095114316791296,
0.0013675513910129666,
0.000041033756133401766,
-0.0009623613441362977,
-0.005079895723611116,
0.005037115886807442,
0.0007357067079283297,
0.0042112828232347965,
-0.011141093447804451,
-0.0021033845841884613,
-0.0047708735801279545,
-0.003204894484952092,
-0.00019696817616932094,
0.006831400096416473,
-0.00020826967374887317,
0.007624909281730652,
0.004958449397236109,
-0.007149780169129372,
0.00756824342533946,
-0.010610620491206646,
0.026946235448122025,
0.0026929446030408144,
0.005568650551140308,
0.0032283840700984,
-0.007643961813300848,
-0.004450673703104258,
0.008478483185172081,
0.0013110812287777662,
0.013696867972612381,
-0.010227648541331291,
-0.005498624872416258,
0.0026760417968034744,
0.02000352181494236,
-0.005220590624958277,
-0.009372950531542301,
-0.00793788954615593,
-0.0024507101625204086,
0.0022472748532891273,
0.00829293578863144,
0.009403550997376442,
-0.0024171257391572,
0.009359676390886307,
-0.004683367908000946,
-0.02251468226313591,
0.0017423920799046755,
-0.002640556311234832,
-0.006918264087289572,
0.003322180360555649,
0.007569537963718176,
0.013669987209141254,
-0.00034721667179837823,
0.0038071940653026104,
0.00007393856503767893,
0.005946587771177292,
0.0011355741880834103,
0.009282547049224377,
-0.00036270995042286813,
0.004857159685343504,
-0.009366213344037533,
0.007139947265386581,
-0.01187429390847683,
-0.0019820095039904118,
-0.00006474369729403406,
-0.005713552236557007,
0.012688172981142998,
0.005850476678460836,
-0.001007217913866043,
-0.0016774240648373961,
-0.009830067865550518,
-0.00622233422473073,
0.00047634608927182853,
0.0017156644025817513,
-0.010084476321935654,
0.0013159961672499776,
-0.0014517795061692595,
0.005701031535863876,
0.006205399055033922,
-0.007500477600842714,
0.0064028180204331875,
0.0030202765483409166,
-0.004678560420870781,
0.0015875331591814756,
-0.005743483547121286,
0.002730251057073474,
0.004218729212880135,
-0.007300353609025478,
-0.0065344274044036865,
0.0031139396596699953,
-0.00569934444501996,
-0.004585400223731995,
0.006247217766940594,
-0.009024287573993206,
-0.008065545000135899,
-0.002091420581564307,
-0.014261588454246521,
-0.0009291853057220578
] |
8a52440233bd3169102a1818d34f5c74f2141148 | 2,823 | py | Python | backend/server/converters/schema/ontology.py | GenomicsNX/cellxgene | f9c744327a3be48c93b47bba71a480e1eeb97835 | [
"MIT"
] | 8 | 2021-03-17T23:42:41.000Z | 2022-03-08T13:08:55.000Z | backend/server/converters/schema/ontology.py | GenomicsNX/cellxgene | f9c744327a3be48c93b47bba71a480e1eeb97835 | [
"MIT"
] | 194 | 2021-08-18T23:52:44.000Z | 2022-03-30T19:40:41.000Z | backend/server/converters/schema/ontology.py | GenomicsNX/cellxgene | f9c744327a3be48c93b47bba71a480e1eeb97835 | [
"MIT"
] | 8 | 2021-03-22T17:07:31.000Z | 2022-03-08T11:07:48.000Z | """Methods for working with ontologies and the OLS."""
from urllib.parse import quote_plus
import requests
OLS_API_ROOT = "http://www.ebi.ac.uk/ols/api"
# Curie means something like CL:0000001
def _ontology_name(curie):
"""Get the name of the ontology from the curie, CL or UBERON for example."""
return curie.split(":")[0]
def _ontology_value(curie):
"""Get the id component of the curie, 0000001 from CL:0000001 for example."""
return curie.split(":")[1]
def _double_encode(url):
"""Double url encode a url. This is required by the OLS API."""
return quote_plus(quote_plus(url))
def _iri(curie):
"""Get the iri from a curie. This is a bit hopeful that they all map to purl.obolibrary.org"""
if _ontology_name(curie) == "EFO":
return f"http://www.ebi.ac.uk/efo/EFO_{_ontology_value(curie)}"
return f"http://purl.obolibrary.org/obo/{_ontology_name(curie)}_{_ontology_value(curie)}"
class OntologyLookupError(Exception):
"""Exception for some problem with looking up ontology information."""
def _ontology_info_url(curie):
"""Get the to make a GET to to get information about an ontology term."""
# If the curie is empty, just return an empty string. This happens when there is no
# valid ontology value.
if not curie:
return ""
else:
return f"{OLS_API_ROOT}/ontologies/{_ontology_name(curie)}/terms/{_double_encode(_iri(curie))}"
def get_ontology_label(curie):
"""For a given curie like 'CL:1000413', get the label like 'endothelial cell of artery'"""
url = _ontology_info_url(curie)
if not url:
return ""
response = requests.get(url)
if not response.ok:
raise OntologyLookupError(
f"Curie {curie} lookup failed, got status code {response.status_code}: {response.text}"
)
return response.json()["label"]
def lookup_candidate_term(label, ontology="cl", method="select"):
"""Lookup candidate terms for a label. This is useful when there is an existing label in a
submitted dataset, and you want to find an appropriate ontology term.
Args:
label: the label to find ontology terms for
ontology: the ontology to search in, cl or uberon or efo for example
method: select or search. search provides much broader results
Returns:
list of (curie, label) tuples returned by OLS
"""
# using OLS REST API [https://www.ebi.ac.uk/ols/docs/api]
url = f"{OLS_API_ROOT}/{method}?q={quote_plus(label)}&ontology={ontology.lower()}"
response = requests.get(url)
if not response.ok:
raise OntologyLookupError(
f"Label {label} lookup failed, got status code {response.status_code}: {response.text}"
)
return [(r["obo_id"], r["label"]) for r in response.json()["response"]["docs"]]
| 32.448276 | 103 | 0.681899 | 1 | 1.6761 | [
0.002153850859031081,
0.023367442190647125,
0.008854318410158157,
0.0004040235362481326,
0.0032666712068021297,
-0.003906640689820051,
-0.008328010328114033,
0.003415518207475543,
-0.007853426039218903,
0.002713157795369625,
0.0024915803223848343,
0.005900831893086433,
0.008328404277563095,
-0.01634172536432743,
0.0002866772119887173,
0.016487348824739456,
-0.04889547824859619,
0.0005734282312914729,
-0.004227453842759132,
0.002506155986338854,
-0.005532931536436081,
0.008412688039243221,
0.009373701177537441,
0.005027018021792173,
0.006644824519753456,
-0.0010877855820581317,
0.009846610948443413,
0.0007785981870256364,
-0.008680042810738087,
-0.007320769131183624,
-0.001724338624626398,
-0.0018897549016401172,
-0.005140542984008789,
-0.007599047385156155,
0.005871827248483896,
-0.0023497771471738815,
-0.0021205362863838673,
-0.020708102732896805,
0.012176395393908024,
-0.0026512211188673973,
-0.0074544972740113735,
-0.015192457474768162,
0.00017003629181999713,
0.0033355599734932184,
-0.008990130387246609,
0.0021644842345267534,
-0.004055331461131573,
0.0036939140409231186,
-0.010810622945427895,
0.0077768233604729176,
-0.009274523705244064,
0.007214969955384731,
0.013606415130198002,
0.0026854760944843292,
-0.005654866341501474,
-0.00565190939232707,
0.01215354260057211,
-0.0004675211675930768,
-0.010258449241518974,
-0.0013789576478302479,
-0.004074495285749435,
-0.0012873499654233456,
0.005801207851618528,
0.0038162709679454565,
-0.015810193493962288,
-0.007602147292345762,
-0.0030647418461740017,
0.0026870123110711575,
-0.0002011715405387804,
0.00507367542013526,
-0.00025946408277377486,
-0.0008238684386014938,
0.008097155950963497,
0.005672974977642298,
0.005232734605669975,
-0.0029720517341047525,
-0.0008112892392091453,
-0.0013761173468083143,
0.008449774235486984,
0.004994316957890987,
0.003554678987711668,
-0.0066309901885688305,
0.005414849147200584,
0.007634344510734081,
0.014207323081791401,
0.008309904485940933,
0.021484747529029846,
-0.012276475317776203,
0.04948762431740761,
0.009215441532433033,
-0.008816157467663288,
0.002654655370861292,
-0.008311113342642784,
-0.0014848000137135386,
-0.0036487008910626173,
-0.027664152905344963,
0.00008801467629382387,
-0.0053805154748260975,
0.0001346668868791312,
0.0017198575660586357,
-0.0003789239563047886,
0.007012675516307354,
-0.0017192177474498749,
-0.0015124684432521462,
-0.007772918324917555,
0.010799472220242023,
-0.009100144729018211,
-0.003544310573488474,
0.005294459406286478,
0.002176956506446004,
-0.01028595119714737,
-0.0025320558343082666,
0.002225470030680299,
-0.011767982505261898,
0.003017002483829856,
0.003889863844960928,
-0.006371763534843922,
0.05405842512845993,
-0.0001937789929797873,
0.006480604875832796,
-0.006338797509670258,
0.0024288289714604616,
0.0006773521308787167,
0.004768042825162411,
0.0099227549508214,
-0.0020089366007596254,
0.0088231535628438,
0.007995150983333588,
0.003867809660732746,
0.009494657628238201,
-0.0024816361255943775,
0.007795830722898245,
-0.004159837029874325,
-0.002899064449593425,
0.0015733061591163278,
-0.007132075261324644,
0.007867762818932533,
-0.0015901178121566772,
-0.008395018987357616,
0.0004062791704200208,
-0.0003571531269699335,
-0.008225916884839535,
0.0015162002528086305,
-0.004340066108852625,
0.004095899406820536,
-0.011123796924948692,
-0.002734145615249872,
-0.003595089539885521,
-0.004060465842485428,
0.0035104050766676664,
0.012442120350897312,
0.0035467182751744986,
0.0034496893640607595,
-0.00520400470122695,
-0.010505135171115398,
0.00019420711032580584,
-0.00395938428118825,
0.0017301508923992515,
0.007358253002166748,
0.0032307107467204332,
-0.010897901840507984,
0.00015228755364660174,
0.0024599984753876925,
0.0018279955256730318,
0.00002405793384241406,
0.004099822137504816,
-0.008558923378586769,
0.005559486337006092,
-0.00013673589273821563,
0.005637729074805975,
0.011635524220764637,
-0.005242169834673405,
-0.0009046102059073746,
0.00039013297646306455,
0.002127666026353836,
-0.0002677090233191848,
0.005029535852372646,
0.010447443462908268,
-0.0029693730175495148,
-0.004415742587298155,
0.004387344233691692,
0.005297612398862839,
0.009272207506000996,
0.004879135638475418,
-0.004478355869650841,
0.0008823747048154473,
-0.006179062649607658,
-0.0025291636120527983,
0.005570549052208662,
-0.00523887574672699,
0.004478261340409517,
0.005127863958477974,
-0.012990910559892654,
-0.007726509589701891,
0.0014752158895134926,
-0.006851826328784227,
0.0010981196537613869,
0.012506055645644665,
0.011973204091191292,
-0.0036341981031000614,
0.00397065281867981,
-0.009672149084508419,
0.0007968114805407822,
0.006139060016721487,
0.002529183402657509,
-0.013281389139592648,
-0.9594501852989197,
0.007022208068519831,
0.0023800728376954794,
-0.002395093906670809,
0.005605390295386314,
0.0036004234571009874,
0.003778234589844942,
0.003928217571228743,
0.015187062323093414,
-0.009799887426197529,
-0.007273980416357517,
-0.010593673214316368,
-0.011665783822536469,
-0.002390087116509676,
-0.007591926027089357,
-0.003968030214309692,
-0.006751084700226784,
-0.008317570202052593,
-0.001834724796935916,
-0.0031987119000405073,
-0.002337946556508541,
0.008785475976765156,
-0.00015428899496328086,
0.005489513743668795,
0.0034053593408316374,
0.0028567491099238396,
-0.006109560839831829,
-0.002211491810157895,
-0.003781684208661318,
-0.0010233354987576604,
-0.006755358073860407,
-0.013904818333685398,
-0.003259013406932354,
-0.0007164827547967434,
0.010394996032118797,
0.00019527596305124462,
0.00900160614401102,
-0.0014573907246813178,
0.001435830257833004,
-0.006211294326931238,
0.005408196244388819,
0.00006572803249582648,
0.004437378142029047,
-0.030747640877962112,
0.00011669315426843241,
-0.00102422502823174,
-0.009271510876715183,
0.008447728119790554,
0.00047997210640460253,
-0.0011657060822471976,
-0.0032168349716812372,
-0.005914943292737007,
0.009404418058693409,
-0.006051754113286734,
0.00309973512776196,
-0.005688265897333622,
-0.008609999902546406,
-0.001609627390280366,
-0.008610493503510952,
-0.00012231626897118986,
0.003374823834747076,
-0.003434708807617426,
-0.004726852290332317,
-0.0038922750391066074,
0.002395929303020239,
0.0023847592528909445,
0.0024208335671573877,
-0.01945987157523632,
-0.007141716778278351,
0.0017746466910466552,
-0.00027601385954767466,
-0.00545049924403429,
-0.0023045579437166452,
0.0043418025597929955,
-0.00876450352370739,
0.008123134262859821,
0.001782950828783214,
-0.0004991989699192345,
-0.012189742177724838,
0.00028601076337508857,
-0.008137605153024197,
-0.006587051786482334,
0.0013835459249094129,
-0.004805233329534531,
-0.004226434975862503,
-0.0012133329873904586,
-0.0006744061247445643,
0.006532729137688875,
-0.003036332782357931,
0.0049744113348424435,
0.009297683835029602,
-0.0038202640134841204,
-0.007896545343101025,
0.005082393996417522,
0.006023217458277941,
0.000121693366963882,
-0.0037092447746545076,
0.00016121275257319212,
0.00855000875890255,
0.0067819394171237946,
0.0030940864235162735,
0.00535953976213932,
0.00011489355529192835,
0.009184423834085464,
-0.0016984004760161042,
0.0008953290525823832,
-0.0035117235966026783,
0.0005412264727056026,
-0.00288068107329309,
0.000952476286329329,
-0.003118733176961541,
-0.002902075881138444,
-0.011635909788310528,
-0.009352806955575943,
-0.004731548484414816,
-0.0006404551677405834,
0.003100956091657281,
-0.005139208398759365,
-0.001532101770862937,
0.003562129568308592,
0.008212610147893429,
-0.0006924771587364376,
-0.0022997725754976273,
0.0010438557947054505,
0.003262953832745552,
-0.006669557187706232,
0.014870206825435162,
-0.011779497377574444,
0.006502376403659582,
0.0002517898101359606,
-0.015641676262021065,
0.007939164526760578,
0.008331500925123692,
-0.008620455861091614,
0.0014428376452997327,
0.004642168991267681,
0.003126393537968397,
-0.0001365962962154299,
-0.004786500241607428,
-0.0034935816656798124,
-0.015761641785502434,
0.00041845915256999433,
0.02032589539885521,
0.0005119223496876657,
0.009252648800611496,
0.010599988512694836,
-0.00366064696572721,
0.002649059984833002,
0.007203163579106331,
0.00034270217292942107,
0.011316460557281971,
-0.008917187340557575,
0.0002661202452145517,
0.0027165550272911787,
-0.007232247851788998,
-0.0005618557333946228,
0.007214145734906197,
0.005514522083103657,
-0.0023607241455465555,
0.0029820005875080824,
-0.008770233020186424,
-0.005348771344870329,
-0.017481792718172073,
-0.004412429872900248,
0.006372536066919565,
-0.0033911147620528936,
0.007443920709192753,
-0.012225989252328873,
0.005335426423698664,
0.0076684495434165,
0.0028408861253410578,
-0.0011229236843064427,
0.0011676381109282374,
0.005715607665479183,
0.01165560819208622,
-0.004931574687361717,
0.001488142996095121,
0.003913381136953831,
-0.0003319956304039806,
-0.0005365688120946288,
0.007654381450265646,
-0.006323646754026413,
-0.006162660196423531,
0.003516256343573332,
0.004135756753385067,
-0.0008282625931315124,
-0.004377506673336029,
-0.008387514390051365,
-0.003808440640568733,
0.0021340136881917715,
-0.005430881399661303,
0.004598363768309355,
0.00009336150105809793,
0.004067488480359316,
-0.005410914774984121,
-0.001663354691118002,
-0.0013168980367481709,
-0.013135457411408424,
0.010947110131382942,
-0.003632443258538842,
0.0032341936603188515,
0.012814759276807308,
0.0037568763364106417,
-0.011700285598635674,
0.0046268487349152565,
0.007078532595187426,
-0.004497240763157606,
0.005469645839184523,
0.004345163702964783,
-0.007104998920112848,
-0.02170437201857567,
-0.0035284359473735094,
-0.013315104879438877,
0.007198575884103775,
-0.0013359823497012258,
0.003957086242735386,
-0.00766800669953227,
0.006009272299706936,
0.00936984270811081,
-0.013152159750461578,
-0.005112741608172655,
-0.008812119252979755,
0.008992746472358704,
0.000034492171835154295,
-0.0002002289256779477,
-0.0034857371356338263,
-0.00018717221973929554,
-0.000757400004658848,
-0.005024433135986328,
-0.002317361533641815,
0.006372405216097832,
0.0011799321509897709,
-0.0021120079327374697,
0.0022471053525805473,
-0.005474375560879707,
-0.00013858378224540502,
-0.0018144304631277919,
-0.010398747399449348,
0.003591441083699465,
0.002666042884811759,
-0.0031646534334868193,
-0.0033298807684332132,
0.00237468583509326,
-0.001089918427169323,
-0.008090351708233356,
-0.01147952489554882,
-0.005510810296982527,
-0.004445226863026619,
-0.0018225496169179678,
-0.01200263760983944,
-0.0029671452939510345,
-0.010148990899324417,
0.005722512025386095,
-0.007459545508027077,
0.008778942748904228,
0.005777455400675535,
-0.005133130121976137,
0.006814354564994574,
-0.001628059078939259,
0.0049117254093289375,
0.004200296476483345,
0.006544371601194143,
0.0005678918678313494,
-0.005180237349122763,
-0.01150036882609129,
0.009857012890279293,
-0.0063245645724236965,
0.001587382867000997,
0.013433965854346752,
0.0053282249718904495,
0.008714035153388977,
0.00027605987270362675,
0.000951966445427388,
0.003312739310786128,
0.006005228962749243,
-0.012506404891610146,
0.0041235461831092834,
-0.0031211641617119312,
0.00008797306509222835,
0.004128213506191969,
-0.0025453856214880943,
0.0011036715004593134,
0.008528762497007847,
0.0006178196053951979,
-0.008241834118962288,
-0.0015620971098542213,
0.0028479723259806633,
0.004921222571283579,
-0.013173236511647701,
-0.00006820190174039453,
-0.0038993600755929947,
-0.003987381234765053,
-0.002758495043963194,
-0.004500178620219231,
0.0006082247709855437,
0.004880303982645273,
-0.0011283677304163575,
0.006571666803210974,
0.0013105003163218498,
-0.005011820234358311,
0.013294585049152374,
-0.003255297429859638,
-0.004163993056863546,
0.0025587764102965593,
0.003641375107690692,
-0.0017058945959433913,
-0.005291053559631109,
-0.0005606032209470868,
0.0020897325593978167,
0.008502570912241936,
-0.001874298439361155,
-0.0034262591507285833,
-0.0016345514450222254,
0.0012695988407358527,
-0.010491633787751198,
0.00241022533737123,
0.01405212003737688,
-0.0038940554950386286,
0.006757617462426424,
-0.0025428859516978264,
-0.008548110723495483,
-0.013767438940703869,
0.052219491451978683,
-0.0010249478509649634,
0.0025121697690337896,
0.0041332063265144825,
-0.006597656290978193,
0.00023316312581300735,
-0.0021093550603836775,
0.007326980587095022,
-0.0068428851664066315,
-0.008173501119017601,
0.00796651840209961,
-0.00326793035492301,
0.004932409152388573,
0.005010646302253008,
-0.001031591440550983,
0.01481633260846138,
-0.0039107003249228,
-0.017591314390301704,
-0.016901439055800438,
0.008005861192941666,
-0.004586783237755299,
-0.0059707676991820335,
0.010043395683169365,
-0.003007542574778199,
-0.006347232963889837,
0.0009135627187788486,
0.006844036281108856,
0.0014205648330971599,
0.0000260363522102125,
-0.003356930799782276,
-0.0013027106178924441,
-0.00040554392035119236,
0.0015839627012610435,
0.0046984851360321045,
0.006891288328915834,
-0.002805964555591345,
0.003422142704948783,
-0.0005964803276583552,
-0.002029246650636196,
-0.0009397128014825284,
0.003867434337735176,
0.006980468053370714,
-0.0006904825568199158,
-0.0013241540873423219,
0.006248623598366976,
0.004392764065414667,
0.0027701908256858587,
0.01000524777919054,
0.000716380076482892,
-0.007441909983754158,
0.009091813117265701,
0.0040771630592644215,
0.001247126143425703,
0.006940315943211317,
-0.0006163906073197722,
0.007371590938419104,
0.0015866763424128294,
-0.007901577278971672,
-0.016711313277482986,
-0.003053617663681507,
0.006329087540507317,
0.009170802310109138,
-0.0007605091668665409,
-0.0010863039642572403,
-0.002384685445576906,
-0.0013333512470126152,
-0.005643936339765787,
-0.008083175867795944,
-0.0034317944664508104,
0.001737242448143661,
0.0033937024418264627,
0.06787565350532532,
-0.006493538152426481,
-0.0013538760831579566,
-0.008208932355046272,
-0.0019318618578836322,
-0.0038561245892196894,
-0.0010796082206070423,
-0.0002966941683553159,
-0.00272289477288723,
0.00278718420304358,
0.0006658001220785081,
-0.006007458548992872,
-0.012242529541254044,
0.0004916510661132634,
0.0017232033424079418,
-0.003570577362552285,
0.0069006457924842834,
0.0056933509185910225,
-0.010110418312251568,
0.0003635773900896311,
-0.010684874840080738,
-0.0019498261390253901,
-0.002454620087519288,
-0.011478416621685028,
-0.004539655987173319,
-0.0032640318386256695,
0.005581509321928024,
0.0027313672471791506,
0.007623953744769096,
-0.002653291681781411,
0.004863036796450615,
-0.0023798251058906317,
-0.0002859187370631844,
-0.00474918307736516,
-0.0021312921307981014,
-0.006396092474460602,
0.007677184883505106,
0.001910614431835711,
-0.010551692917943,
-0.0056583634577691555,
-0.000855451391544193,
-0.001714959624223411,
-0.0042543294839560986,
0.003718877909705043,
0.0003393158258404583,
0.00614926079288125,
-0.002845786279067397,
0.00013306865002959967,
-0.006402535364031792,
0.0021441769786179066,
-0.01273813471198082,
0.004373189993202686,
-0.17185302078723907,
0.009513390250504017,
0.004387969616800547,
-0.005737402942031622,
-0.003888067090883851,
-0.012596314772963524,
-0.0047057312913239,
0.003580405842512846,
0.00971596036106348,
0.0016957313055172563,
-0.0014499645913019776,
-0.0012060299050062895,
0.0033174115233123302,
0.004080005455762148,
-0.0002905955188907683,
-0.003944864962249994,
0.004016348626464605,
-0.0043577030301094055,
0.0016881467308849096,
0.0033411781769245863,
0.004441263619810343,
0.00936311949044466,
0.0012571251718327403,
0.0030446003656834364,
-0.0016466655069962144,
-0.005300775170326233,
0.007418998051434755,
-0.0015492215752601624,
0.005917940754443407,
-0.01202899869531393,
-0.002524490235373378,
-0.004423481412231922,
-0.005961413029581308,
0.00126999756321311,
0.004550079349428415,
-0.0017087962478399277,
0.009313574992120266,
0.0037756357342004776,
-0.0084361108019948,
0.009110335260629654,
-0.008060520514845848,
0.026799693703651428,
0.006363549269735813,
0.0065970453433692455,
-0.0007302967715077102,
-0.006869033444672823,
-0.0055940416641533375,
0.008573904633522034,
0.002600231906399131,
0.012016947381198406,
-0.013872195966541767,
-0.00043971335981041193,
0.0030454148072749376,
0.018595224246382713,
-0.004677383694797754,
-0.008779366500675678,
-0.006427756976336241,
-0.001876393216662109,
0.0013859206810593605,
0.007981495931744576,
0.011880946345627308,
-0.0033210550900548697,
0.008525327779352665,
-0.0025871340185403824,
-0.021770648658275604,
0.0032664602622389793,
-0.004341623745858669,
-0.006120921112596989,
0.005251813679933548,
0.005787264555692673,
0.008380015380680561,
-0.001283785211853683,
0.0012943658512085676,
-0.0024130952078849077,
0.005040120333433151,
0.00016388797666877508,
0.005240432918071747,
-0.0017733011627569795,
0.003655270906165242,
-0.010300285182893276,
0.004723884165287018,
-0.009298339486122131,
-0.003650392172858119,
0.002581040607765317,
-0.0037821766454726458,
0.011358142830431461,
0.004891613963991404,
-0.0011503431014716625,
-0.0010565010597929358,
-0.009401406161487103,
-0.0029799065086990595,
0.0006153829745016992,
0.0015240026405081153,
-0.007789840456098318,
0.0029281247407197952,
0.0015107484068721533,
0.0052652484737336636,
0.004773407708853483,
-0.008718350902199745,
0.005744079127907753,
0.004529554396867752,
-0.005002166610211134,
0.00014305503282230347,
-0.003985192626714706,
0.0027411438059061766,
0.004043004475533962,
-0.004395774099975824,
-0.0037034819833934307,
0.0023766520898789167,
-0.007731983438134193,
-0.006249155383557081,
0.008429819718003273,
-0.008333318866789341,
-0.010693132877349854,
-0.003249001456424594,
-0.012866178527474403,
0.0013149826554581523
] |
8a5244b8a475e9cca6ead4f4463ced1af6491956 | 17,945 | py | Python | survey/api/matrix.py | djaodjin/djaodjin-survey | a6eb8a577fecd219850478c245d9ebe990438a64 | [
"BSD-2-Clause"
] | 15 | 2015-03-12T18:14:50.000Z | 2022-03-26T10:16:55.000Z | survey/api/matrix.py | djaodjin/djaodjin-survey | a6eb8a577fecd219850478c245d9ebe990438a64 | [
"BSD-2-Clause"
] | 19 | 2015-03-31T20:48:08.000Z | 2022-03-30T17:31:49.000Z | survey/api/matrix.py | djaodjin/djaodjin-survey | a6eb8a577fecd219850478c245d9ebe990438a64 | [
"BSD-2-Clause"
] | 4 | 2015-12-16T20:53:34.000Z | 2017-12-20T19:50:42.000Z | # Copyright (c) 2020, DjaoDjin inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import logging, re
from collections import OrderedDict
from django.db.models import F
from django.http import Http404
from django.shortcuts import get_object_or_404
from extra_views.contrib.mixins import SearchableListMixin
from rest_framework import generics
from rest_framework.pagination import PageNumberPagination
from rest_framework import response as http
from ..compat import reverse
from ..mixins import MatrixMixin
from ..models import Answer, Matrix, EditableFilter
from ..utils import (get_account_model, get_account_serializer,
get_question_serializer)
from .serializers import EditableFilterSerializer, MatrixSerializer
LOGGER = logging.getLogger(__name__)
class MatrixCreateAPIView(generics.ListCreateAPIView):
"""
Filtered list of ``Question``.
**Examples**:
.. code-block:: http
GET /api/matrix/
Response:
{
"slug": "all",
"title": "All accounts against all questions",
"metric": {
"slug": "all-questions",
"title": "All questions",
"predicates": []
},
"cohorts": [{
"slug": "all-accounts",
"title": "All accounts",
"predicates": []
}]
}
.. code-block:: http
POST /api/matrix/
{
"slug": "all",
"title": "All accounts against all questions",
"metric": {
"slug": "all-questions",
"title": "All questions",
"predicates": []
},
"cohorts": [{
"slug": "all-accounts",
"title": "All accounts",
"predicates": []
}]
}
Response:
201 CREATED
{
"slug": "all",
"title": "All accounts against all questions",
"metric": {
"slug": "all-questions",
"title": "All questions",
"predicates": []
},
"cohorts": [{
"slug": "all-accounts",
"title": "All accounts",
"predicates": []
}]
}
"""
serializer_class = MatrixSerializer
def get_queryset(self):
return Matrix.objects.all()
class MatrixDetailAPIView(MatrixMixin, generics.RetrieveUpdateDestroyAPIView):
"""
A table of scores for cohorts aganist a metric.
**Examples**:
.. code-block:: http
GET /api/matrix/languages
Response:
[{
"slug": "languages",
"title": "All cohorts for all questions"
"scores":{
"portfolio-a": "0.1",
"portfolio-b": "0.5",
}
}]
"""
serializer_class = MatrixSerializer
lookup_field = 'slug'
lookup_url_kwarg = 'path'
question_model = get_question_serializer().Meta.model
def aggregate_scores(self, metric, cohorts, cut=None, accounts=None):
#pylint:disable=unused-argument,too-many-locals
if accounts is None:
accounts = get_account_model().objects.all()
scores = {}
if metric:
assert 'metric' in metric.tags, \
"filter '%s' is not tagged as a metric" % str(metric)
includes, excludes = metric.as_kwargs()
questions = self.question_model.objects.filter(
**includes).exclude(**excludes)
nb_questions = len(questions)
if nb_questions > 0:
for cohort in cohorts:
if isinstance(cohort, EditableFilter):
includes, excludes = cohort.as_kwargs()
qs_accounts = accounts.filter(
**includes).exclude(**excludes)
else:
# If `matrix.cohorts is None`, the `cohorts` argument
# will be a list of single account objects.
qs_accounts = [cohort]
nb_accounts = len(qs_accounts)
if nb_accounts > 0:
nb_correct_answers = Answer.objects.filter(
question__in=questions,
sample__account__in=qs_accounts).filter(
measured=F('question__correct_answer')).count()
score = nb_correct_answers * 100 / (
nb_questions * nb_accounts)
LOGGER.debug("score for '%s' = (%d * 100) "\
"/ (%d * %d) = %f", str(cohort), nb_correct_answers,
nb_questions, nb_accounts, score)
assert score <= 100
scores.update({str(cohort): score})
return {"scores": scores}
@property
def matrix(self):
if not hasattr(self, '_matrix'):
self._matrix = Matrix.objects.filter(
slug=self.kwargs.get(self.matrix_url_kwarg)).first()
return self._matrix
def get_accounts(self):
#pylint:disable=unused-argument,no-self-use
return get_account_model().objects.all()
def get_likely_metric(self, cohort_slug):
"""
Returns a URL to a ``Matrix`` derived from *cohort*.
Many times people will use the same name to either mean a cohort
or a metric and expect the system will magically switch between
both meaning. This is an attempt at magic.
"""
likely_metric = None
look = re.match(r"(\S+)(-\d+)", cohort_slug)
if look:
try:
likely_metric = self.request.build_absolute_uri(
reverse('matrix_chart', args=(
EditableFilter.objects.get(slug=look.group(1)).slug,)))
except EditableFilter.DoesNotExist:
pass
return likely_metric
def get(self, request, *args, **kwargs):
#pylint:disable=unused-argument,too-many-locals
matrix = self.matrix
if matrix:
metric = self.matrix.metric
else:
parts = self.kwargs.get(self.matrix_url_kwarg).split('/')
metric = get_object_or_404(EditableFilter, slug=parts[-1])
matrix = Matrix.objects.filter(slug=parts[0]).first()
if not matrix:
raise Http404()
cohort_serializer = EditableFilterSerializer
cohorts = matrix.cohorts.exclude(tags__contains='aggregate')
public_cohorts = matrix.cohorts.filter(tags__contains='aggregate')
cut = matrix.cut
if not cohorts:
# We don't have any cohorts, let's show individual accounts instead.
if cut:
includes, excludes = cut.as_kwargs()
accounts = self.get_accounts().filter(
**includes).exclude(**excludes)
else:
accounts = self.get_accounts()
cohort_serializer = get_account_serializer()
# Implementation Note: switch cohorts from an queryset
# of `EditableFilter` to a queryset of `Account` ...
cohorts = accounts
result = []
scores = {}
val = {
'slug': metric.slug,
'title': metric.title,
'metric': EditableFilterSerializer().to_representation(metric),
'cut': EditableFilterSerializer().to_representation(cut),
'cohorts': cohort_serializer(many=True).to_representation(cohorts)}
# In some case, a metric and cohort have a connection
# and could have the same name.
for cohort in val['cohorts']:
likely_metric = self.get_likely_metric(cohort['slug'])
if likely_metric:
cohort['likely_metric'] = likely_metric
scores.update(val)
scores.update({"values": self.aggregate_scores(
metric, cohorts, cut, accounts=self.get_accounts())})
result += [scores]
if public_cohorts:
public_scores = {}
public_scores.update(val)
public_scores.update(
{"cohorts": EditableFilterSerializer(
public_cohorts, many=True).data,
"values": self.aggregate_scores(metric, public_cohorts)})
result += [public_scores]
return http.Response(result)
class EditableFilterQuerysetMixin(object):
@staticmethod
def get_queryset():
return EditableFilter.objects.all()
class EditableFilterListAPIView(SearchableListMixin,
EditableFilterQuerysetMixin, generics.ListCreateAPIView):
"""
List fitlers
**Tags**: survey
**Examples**
.. code-block:: http
GET /api/xia/matrix/filters/ HTTP/1.1
responds
.. code-block:: json
{
"count": 2,
previous: null,
next: null,
results: [
{
"slug": "all",
"title": "All",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
},
{
"slug": "none",
"title": "None",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
}
]
}
"""
search_fields = ['tags']
serializer_class = EditableFilterSerializer
def post(self, request, *args, **kwargs):
"""
Create a fitler
**Tags**: survey
**Examples**
.. code-block:: http
POST /api/xia/matrix/filters/ HTTP/1.1
responds
.. code-block:: json
{
"count": 2,
previous: null,
next: null,
results: [
{
"slug": "all",
"title": "All",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
},
{
"slug": "none",
"title": "None",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
}
]
}
"""
#pylint:disable=useless-super-delegation
return super(EditableFilterListAPIView, self).post(
request, *args, **kwargs)
class EditableFilterDetailAPIView(generics.RetrieveUpdateDestroyAPIView):
"""
Retrieve a fitler
**Tags**: survey
**Examples**
.. code-block:: http
GET /api/xia/matrix/filters/all/ HTTP/1.1
responds
.. code-block:: json
{
"slug": "all",
"title": "All",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
}
"""
serializer_class = EditableFilterSerializer
lookup_field = 'slug'
lookup_url_kwarg = 'editable_filter'
def get_queryset(self):
return EditableFilter.objects.all()
def put(self, request, *args, **kwargs):
"""
Updates a fitler
**Tags**: survey
**Examples**
.. code-block:: http
PUT /api/xia/matrix/filters/all/ HTTP/1.1
.. code-block:: json
{
"slug": "all",
"title": "All",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
}
responds
.. code-block:: json
{
"slug": "all",
"title": "All",
"tags": "",
"predicates": [
"rank": 1,
"operator": "",
"operand": "",
"field": "",
"selector": ""
],
"likely_metric": ""
}
"""
#pylint:disable=useless-super-delegation
return super(EditableFilterDetailAPIView, self).put(
request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
"""
Deletes a fitler
**Tags**: survey
**Examples**
.. code-block:: http
DELETE /api/xia/matrix/filters/all/ HTTP/1.1
"""
#pylint:disable=useless-super-delegation
return super(EditableFilterDetailAPIView, self).delete(
request, *args, **kwargs)
class EditableFilterPagination(PageNumberPagination):
def paginate_queryset(self, queryset, request, view=None):
self.editable_filter = view.editable_filter
return super(EditableFilterPagination, self).paginate_queryset(
queryset, request, view=view)
def get_paginated_response(self, data):
return http.Response(OrderedDict([
('editable_filter', EditableFilterSerializer().to_representation(
self.editable_filter)),
('count', self.page.paginator.count),
('next', self.get_next_link()),
('previous', self.get_previous_link()),
('results', data)
]))
class EditableFilterObjectsAPIView(generics.ListAPIView):
"""
List filter objects
**Tags**: survey
**Examples**
.. code-block:: http
GET /api/xia/matrix/filters/ HTTP/1.1
responds
.. code-block:: json
{
"created_at": "2020-01-01T00:00:00Z",
"measured": 12
}
"""
pagination_class = EditableFilterPagination
serializer_class = None # override in subclasses
lookup_field = 'slug'
lookup_url_kwarg = 'editable_filter'
def get_queryset(self):
return self.get_serializer_class().Meta.model.objects.all()
def get(self, request, *args, **kwargs): #pylint: disable=unused-argument
self.editable_filter = generics.get_object_or_404(
EditableFilter.objects.all(),
slug=self.kwargs[self.lookup_url_kwarg])
return super(EditableFilterObjectsAPIView, self).get(
request, *args, **kwargs)
class AccountListAPIView(EditableFilterObjectsAPIView):
"""
Filtered list of ``EditableFilter``.
**Examples**:
.. code-block:: http
GET /api/questions/languages
Response:
{
"slug": "languages",
"title": "All questions related to languages"
"predicates":[{
"operator": "contains",
"operand": "language",
"field": "text",
"selector":"keepmatching"
}]
}
"""
serializer_class = get_account_serializer()
class QuestionListAPIView(EditableFilterObjectsAPIView):
"""
Filtered list of ``Question``.
**Examples**:
.. code-block:: http
GET /api/questions/languages
Response:
{
"slug": "languages",
"title": "All questions related to languages"
"predicates":[{
"operator": "contains",
"operand": "language",
"field": "text",
"selector":"keepmatching"
}]
}
"""
serializer_class = get_question_serializer()
| 29.958264 | 80 | 0.51017 | 1 | 1.8921 | [
-0.008558575995266438,
0.024743692949414253,
-0.01141850184649229,
0.012761343270540237,
0.023509610444307327,
-0.020996535196900368,
-0.006734995171427727,
-0.019181054085493088,
-0.00937417708337307,
0.019841620698571205,
0.008437620475888252,
0.0012472944799810648,
0.0194740891456604,
0.019725747406482697,
-0.05746138468384743,
-0.0017585571622475982,
0.09256203472614288,
-0.03891558572649956,
0.022688331082463264,
-0.001548989675939083,
0.005132046062499285,
0.004518613219261169,
-0.002664613537490368,
0.002139703370630741,
-0.014144071377813816,
0.0006861143046990037,
0.007133186794817448,
0.0044058701023459435,
0.008951623924076557,
-0.006042427383363247,
-0.01091876719146967,
-0.017119048163294792,
0.00929287914186716,
-0.0017289024544879794,
0.00003723604459082708,
0.009955024346709251,
-0.0011166009353473783,
-0.056341856718063354,
0.006630686577409506,
0.041378527879714966,
0.01237859670072794,
-0.022729268297553062,
-0.004299507476389408,
-0.011873232200741768,
0.023906361311674118,
0.003981012850999832,
-0.004599249921739101,
-0.007811725605279207,
-0.07477254420518875,
-0.012918230146169662,
-0.023248305544257164,
0.015061329118907452,
0.015497831627726555,
-0.04368586093187332,
-0.011509835720062256,
-0.01977039873600006,
-0.019801031798124313,
0.04035471752285957,
-0.023660479113459587,
0.02564523182809353,
-0.0009070695959962904,
0.03721655160188675,
0.01430531032383442,
-0.018165957182645798,
0.02090240828692913,
-0.006834841333329678,
0.010545463301241398,
0.005218192003667355,
-0.02542741596698761,
-0.027167947962880135,
-0.0169856958091259,
0.024075929075479507,
-0.021134573966264725,
0.04092799499630928,
0.02399248443543911,
-0.005877495743334293,
-0.029449716210365295,
-0.012448449619114399,
-0.023280054330825806,
0.014786474406719208,
0.0006316672079265118,
0.03626364842057228,
0.02925780601799488,
-0.02233290858566761,
0.0026532169431447983,
0.004251969512552023,
0.023508988320827484,
-0.04784921184182167,
0.03940732777118683,
0.014305884018540382,
0.0018393062055110931,
0.02579716220498085,
0.016311848536133766,
0.02049569971859455,
-0.07173532992601395,
-0.024152487516403198,
-0.007060911972075701,
0.021972106769680977,
0.02473853901028633,
0.030947856605052948,
0.032552096992731094,
-0.019311174750328064,
-0.01092458050698042,
0.019563397392630577,
-0.02259746752679348,
-0.03833034634590149,
-0.04183793440461159,
0.0007814173586666584,
-0.014754951931536198,
-0.018700189888477325,
-0.011874008923768997,
-0.03887318819761276,
-0.014349759556353092,
0.013091711327433586,
-0.005869139917194843,
-0.014031981118023396,
0.03356320783495903,
-0.003068339079618454,
0.02214946784079075,
0.034268662333488464,
-0.001076315063983202,
-0.021526064723730087,
0.005593600682914257,
-0.00033250462729483843,
-0.014177458360791206,
0.036455947905778885,
-0.012144497595727444,
-0.005275496747344732,
0.0211807768791914,
-0.0034540442284196615,
0.01310116145759821,
-0.00026704385527409613,
-0.015922419726848602,
-0.029099904000759125,
-0.0014089986216276884,
-0.018530594184994698,
0.01574559509754181,
-0.0005228411755524576,
0.0029965995345264673,
0.009332094341516495,
0.01310853473842144,
0.012433182448148727,
-0.02280154451727867,
0.008322455920279026,
0.011118873953819275,
-0.011212596669793129,
-0.013110385276377201,
-0.013680537231266499,
0.00036500266287475824,
0.005782612133771181,
-0.010969599708914757,
0.0026720711030066013,
0.014447362162172794,
-0.007890970446169376,
0.0015131662366911769,
-0.013812040910124779,
-0.011579116806387901,
-0.05131097882986069,
0.000864136207383126,
0.008508782833814621,
-0.02354273572564125,
0.021211573854088783,
-0.010221628472208977,
0.03036520443856716,
-0.036777008324861526,
0.02417743392288685,
-0.003844144754111767,
0.03321602940559387,
0.009463398717343807,
0.013173569925129414,
0.006332871504127979,
-0.0011747532989829779,
-0.009027925319969654,
-0.04083506390452385,
-0.02263018675148487,
0.017083225771784782,
0.02051842212677002,
-0.028948914259672165,
-0.02722599171102047,
-0.025142906233668327,
0.02264382690191269,
-0.014571890234947205,
-0.001611635903827846,
0.05491813272237778,
0.016417546197772026,
-0.029153166338801384,
-0.015145720914006233,
-0.022705549374222755,
-0.005476357880979776,
-0.014523095451295376,
-0.01942986063659191,
0.01081224624067545,
-0.027656691148877144,
-0.022309867665171623,
0.01931355521082878,
0.003295378526672721,
0.02235119417309761,
-0.007857081480324268,
0.002514656400308013,
0.006575329229235649,
0.005627707578241825,
0.0042468528263270855,
0.017679378390312195,
-0.00022934572189114988,
-0.0009309404995292425,
0.0005262586637400091,
-0.8010021448135376,
0.036292169243097305,
-0.005768551956862211,
-0.01273052766919136,
0.013504368253052235,
0.0001631658960832283,
-0.029849637299776077,
0.02947039157152176,
-0.0667167454957962,
0.04168242961168289,
0.006660470739006996,
0.01776687242090702,
-0.01938026398420334,
-0.01666276901960373,
0.009980841539800167,
-0.022559592500329018,
0.010970191098749638,
0.016674699261784554,
0.007719788700342178,
-0.013278219848871231,
0.015906617045402527,
-0.008321596309542656,
-0.010031797923147678,
-0.01427490171045065,
0.02555086277425289,
0.030364444479346275,
0.018777796998620033,
-0.008272996172308922,
0.04921615123748779,
0.009592821821570396,
0.0006510051316581666,
-0.02370324358344078,
-0.010844706557691097,
-0.013232695870101452,
0.014578323811292648,
0.003256451105698943,
0.012497973628342152,
0.015375166200101376,
-0.006571763660758734,
0.0010929827112704515,
0.0047955019399523735,
-0.0032499448861926794,
0.01020241528749466,
-0.04058010131120682,
-0.026796886697411537,
-0.010890236124396324,
-0.034835223108530045,
-0.01741129346191883,
0.005088023375719786,
0.0010644333669915795,
-0.011800947599112988,
0.04542941600084305,
0.031468141824007034,
-0.01834949292242527,
-0.005982589907944202,
0.021628335118293762,
-0.0012491366360336542,
-0.024213748052716255,
-0.006672713905572891,
-0.004087244160473347,
0.008273439481854439,
0.0064102099277079105,
-0.00406958581879735,
0.02131315879523754,
0.0036335166078060865,
-0.005682647693902254,
0.04053701087832451,
-0.009788556024432182,
-0.028818989172577858,
0.005862545222043991,
-0.017663678154349327,
-0.0029285128694027662,
-0.03729946166276932,
0.08943746984004974,
-0.02156154066324234,
-0.0027049307245761156,
0.0025148207787424326,
-0.003677549073472619,
-0.043272651731967926,
-0.014926422387361526,
0.025615766644477844,
0.012801744043827057,
0.0010222858982160687,
-0.004798803478479385,
-0.03042040392756462,
-0.0012248283019289374,
0.009926516562700272,
-0.030726894736289978,
0.02513991855084896,
0.028699854388833046,
0.012257817201316357,
0.022800112143158913,
0.01320869754999876,
-0.016562040895223618,
0.020753731951117516,
0.033683016896247864,
0.00873488001525402,
0.009391076862812042,
0.020879413932561874,
0.012498910538852215,
-0.0064255851320922375,
0.030664190649986267,
0.011589337140321732,
0.009702008217573166,
0.013666296377778053,
0.005793581251055002,
-0.004024877212941647,
0.018489213660359383,
0.0536193922162056,
-0.01424966100603342,
0.0056344554759562016,
-0.015961535274982452,
-0.009904534555971622,
0.014744501560926437,
0.004950020927935839,
-0.022463571280241013,
0.0039311861619353294,
-0.009117907844483852,
0.01046973280608654,
-0.014682195149362087,
-0.011764618568122387,
-0.005413340404629707,
0.04784851521253586,
-0.02709841914474964,
-0.01252037938684225,
0.001264232094399631,
-0.01493839267641306,
0.0015184212243184447,
-0.013434152118861675,
0.019533073529601097,
-0.0033625562209635973,
-0.013816856779158115,
-0.013187005184590816,
0.007602781057357788,
-0.0014544035075232387,
-0.00019483081996440887,
-0.03464552387595177,
-0.03870990499854088,
-0.013389571569859982,
0.0003619237686507404,
-0.007840409874916077,
0.010523609817028046,
-0.00653139827772975,
-0.06487046182155609,
0.0012217119801789522,
0.003080696566030383,
0.025569576770067215,
-0.005437742453068495,
0.035767942667007446,
-0.015569811686873436,
-0.009043105877935886,
-0.014330139383673668,
-0.0311163067817688,
-0.0016442774794995785,
0.007911383174359798,
0.03714780509471893,
-0.03614767640829086,
0.0072293574921786785,
0.020909041166305542,
-0.008872824721038342,
0.019416552037000656,
-0.00898275151848793,
-0.01982834003865719,
0.006694035138934851,
0.014538613148033619,
-0.007036250084638596,
-0.030919399112462997,
0.02762649767100811,
0.03593693673610687,
0.017849203199148178,
0.04621933028101921,
-0.028296753764152527,
0.013463910669088364,
-0.013122634962201118,
-0.023093029856681824,
-0.02041276916861534,
0.013174571096897125,
-0.037627317011356354,
0.016990235075354576,
-0.0029423427768051624,
-0.03157329186797142,
0.0013146500568836927,
-0.008881068788468838,
-0.012794414535164833,
0.007443764712661505,
-0.0023636354599148035,
-0.0249288659542799,
0.017201121896505356,
-0.011811991222202778,
-0.002542242407798767,
-0.0059944200329482555,
0.025850942358374596,
0.009538221172988415,
0.013485795818269253,
-0.0050743138417601585,
-0.012353548780083656,
0.010336396284401417,
-0.0003451086231507361,
-0.020822880789637566,
0.027960240840911865,
-0.011445857584476471,
-0.0016554089961573482,
0.028019452467560768,
0.000044457734475145116,
0.007274147588759661,
0.032195914536714554,
0.0024205008521676064,
0.004469830077141523,
0.0033826834987848997,
0.01138185802847147,
0.036961447447538376,
0.0018830084009096026,
0.006154071073979139,
-0.01926390640437603,
0.0055817412212491035,
-0.01168966107070446,
-0.04197213798761368,
0.005558461416512728,
0.0006809913320466876,
-0.018963754177093506,
-0.0038680846337229013,
-0.02293800376355648,
0.00980530958622694,
0.011643503792583942,
0.013726946897804737,
-0.02359311282634735,
-0.03420836105942726,
0.004300636705011129,
0.005951604340225458,
-0.008431530557572842,
-0.004245750140398741,
-0.0027306724805384874,
0.005241290666162968,
-0.013762237504124641,
0.002792725106701255,
0.005739488173276186,
-0.012633989565074444,
-0.0017218986758962274,
-0.032413650304079056,
-0.01583527959883213,
0.011755716986954212,
-0.039966657757759094,
0.01870417408645153,
0.03466382622718811,
-0.005264252424240112,
-0.009501641616225243,
-0.008077382110059261,
-0.03170853480696678,
-0.018944013863801956,
-0.007663948927074671,
-0.037633176892995834,
0.030853768810629845,
-0.04034501314163208,
-0.006230665370821953,
-0.006726052146404982,
0.015065498650074005,
-0.02597985602915287,
0.00047855579759925604,
0.02934514917433262,
0.013905627653002739,
0.004861956462264061,
-0.004048165399581194,
-0.007290938403457403,
0.0297068003565073,
0.019505558535456657,
0.009787274524569511,
-0.00515776639804244,
-0.00640455586835742,
-0.004540923051536083,
-0.022778265178203583,
0.007685978896915913,
0.001212654053233564,
-0.021853739395737648,
-0.007280220743268728,
0.01822921261191368,
-0.01334819383919239,
-0.0016034032450988889,
0.0007459598709829152,
-0.010667399503290653,
0.013604439795017242,
0.0032811358105391264,
-0.022328486666083336,
-0.0025699231773614883,
0.030784904956817627,
-0.012039008550345898,
-0.0305365938693285,
0.03203870728611946,
-0.020938638597726822,
-0.051927898079156876,
-0.02143666334450245,
-0.023359572514891624,
0.00450386805459857,
-0.02005373127758503,
0.01733175292611122,
-0.02286388911306858,
0.05031641945242882,
-0.0019497565226629376,
-0.01003058347851038,
0.012309461832046509,
0.001821768470108509,
0.033162642270326614,
-0.0037514176219701767,
-0.031590793281793594,
0.017798669636249542,
-0.004019775427877903,
-0.010961489751935005,
0.005560027901083231,
-0.03886748477816582,
0.03595402464270592,
0.019010266289114952,
0.004969876725226641,
-0.008758582174777985,
0.007037097122520208,
-0.01444968767464161,
-0.028040830045938492,
-0.020977981388568878,
0.021445009857416153,
0.061779871582984924,
0.00007159742381190881,
-0.01198193896561861,
-0.0019288865150883794,
0.0077510918490588665,
-0.004970600828528404,
-0.03126365318894386,
0.0006285638664849102,
-0.005976869724690914,
-0.02005835808813572,
0.000524949049577117,
0.005799868609756231,
0.027070624753832817,
-0.01466857548803091,
-0.01247609406709671,
0.005276666022837162,
0.023729357868433,
0.012365967966616154,
-0.013255731202661991,
0.007882358506321907,
0.023310862481594086,
0.026418758556246758,
0.008167541585862637,
0.004911464173346758,
-0.01180584542453289,
-0.05870761722326279,
0.0336717888712883,
0.007884097285568714,
0.026056278496980667,
0.03677980229258537,
0.041795823723077774,
0.009173148311674595,
0.05402518808841705,
0.02956613525748253,
-0.030351724475622177,
-0.02919664792716503,
-0.009731583297252655,
0.017820825800299644,
-0.001093283062800765,
-0.008510736748576164,
0.009920070879161358,
0.02044088952243328,
-0.02319413796067238,
-0.0021998051088303328,
0.0022082237992435694,
-0.02142529934644699,
-0.0029154557269066572,
0.010285407304763794,
-0.017464807257056236,
-0.011525576002895832,
-0.01578061282634735,
-0.027381442487239838,
0.014453563839197159,
-0.008503934368491173,
-0.026630200445652008,
-0.0143514946103096,
0.01136773731559515,
0.011020422913134098,
0.016115674749016762,
0.03643733263015747,
-0.002990753622725606,
-0.02295028045773506,
0.026113802567124367,
-0.0005437865038402379,
0.011295360513031483,
0.017956780269742012,
-0.018061693757772446,
0.04303498566150665,
-0.012921311892569065,
0.026146473363041878,
0.022825369611382484,
0.00963148009032011,
-0.0032338672317564487,
-0.019590266048908234,
0.0020260780584067106,
-0.007622303906828165,
-0.01088167168200016,
-0.010357392951846123,
-0.023800836876034737,
-0.029024986550211906,
-0.017176497727632523,
-0.0070771886967122555,
0.005425119772553444,
0.006109264213591814,
0.029011936858296394,
0.016724824905395508,
-0.024899758398532867,
0.006523561663925648,
-0.018102271482348442,
0.04244484379887581,
0.0008422252140007913,
-0.0031531290151178837,
0.001865581376478076,
0.01856619119644165,
0.026046354323625565,
-0.009027213789522648,
0.01778360828757286,
0.005345750134438276,
-0.038890544325113297,
-0.02474774420261383,
0.021206531673669815,
-0.0328965000808239,
0.009292274713516235,
-0.002993235131725669,
0.0038834193255752325,
0.015612561255693436,
0.026094000786542892,
0.007334779016673565,
-0.0074458341114223,
-0.0008596543921157718,
-0.009554842486977577,
0.0014708561357110739,
0.011956126429140568,
-0.027722381055355072,
0.06302521377801895,
-0.0028481334447860718,
-0.012548821046948433,
0.04174983128905296,
-0.040547627955675125,
0.0020115231163799763,
-0.020188724622130394,
0.02204637974500656,
0.004106472712010145,
0.0033591310493648052,
0.014666659757494926,
0.019360654056072235,
0.02381732501089573,
-0.011158466339111328,
-0.05227142944931984,
0.022010354325175285,
-0.001997605664655566,
-0.007220472674816847,
-0.016747448593378067,
-0.010646779090166092,
-0.036916252225637436,
0.028462471440434456,
-0.0015615577576681972,
-0.006200830917805433,
-0.004689676221460104,
0.04431314766407013,
0.03388660028576851,
-0.01813817396759987,
0.014194006100296974,
-0.01013909000903368,
0.0001908440754050389,
0.002640386577695608,
0.06087520346045494,
0.011153002269566059,
0.0073383888229727745,
-0.004117770120501518,
-0.02096925675868988,
-0.011716943234205246,
-0.029380809515714645,
0.028055578470230103,
0.017320172861218452,
-0.021828969940543175,
-0.0056493706069886684,
-0.01137510221451521,
-0.0027206414379179478,
0.0028846822679042816,
0.0379202701151371,
0.006806710734963417,
-0.0008048118324950337,
-0.031769804656505585,
0.012020627968013287,
-0.015651274472475052,
0.010754291899502277,
-0.0003356513916514814,
-0.01754196546971798,
-0.014681353233754635,
0.02119913510978222,
-0.012313688173890114,
-0.0006942658219486475,
-0.017033830285072327,
-0.0075471182353794575,
-0.0001717050326988101,
0.009725160896778107,
0.002367626642808318,
-0.0026884200051426888,
0.02471000701189041,
-0.02994725853204727,
0.03840729221701622,
-0.008199519477784634,
-0.054122257977724075,
-0.023535415530204773,
-0.021047277376055717,
-0.022619636729359627,
0.027316821739077568,
-0.002317244652658701,
0.09406237304210663,
0.0013756719417870045,
-0.030587447807192802,
-0.004036493133753538,
-0.028565604239702225,
0.024304891005158424,
-0.03862079977989197,
0.013000516220927238,
-0.004157730378210545,
-0.005394856911152601,
0.019619975239038467,
-0.023761557415127754,
-0.007859010249376297,
0.01774156652390957,
0.007676007691770792,
0.010471451096236706,
-0.006452890112996101,
-0.0004874682053923607,
-0.023763496428728104,
0.002082822611555457,
-0.02772624045610428,
-0.03237783536314964,
0.015454764477908611,
0.023454464972019196,
0.010151909664273262,
0.019153879955410957,
-0.026958351954817772,
0.01460958644747734,
0.013848615810275078,
-0.03551912680268288,
0.012845499441027641,
0.02314700558781624,
-0.00278275809250772,
0.0034775310195982456,
0.03723716735839844,
0.02329598180949688,
0.030087267979979515,
0.0020329251419752836,
0.002486519981175661,
-0.019515665248036385,
0.015564397908747196,
0.0034837061539292336,
0.011777803301811218,
-0.022735249251127243,
-0.018599078059196472,
-0.04278649389743805,
0.012030567042529583,
0.023172486573457718,
-0.005987009033560753,
-0.009377218782901764,
0.004383951425552368,
0.020480919629335403,
-0.010703722946345806,
-0.02824661135673523,
-0.010176076553761959,
0.02973478101193905
] |
8a5248567c33c615e0f8be2779b082966267e38c | 2,740 | py | Python | remove_labels.py | iFishy/DomainApp | 970ee96450859b1c40a86a9d654beb99c56aa00f | [
"MIT"
] | null | null | null | remove_labels.py | iFishy/DomainApp | 970ee96450859b1c40a86a9d654beb99c56aa00f | [
"MIT"
] | null | null | null | remove_labels.py | iFishy/DomainApp | 970ee96450859b1c40a86a9d654beb99c56aa00f | [
"MIT"
] | null | null | null | from __future__ import print_function
import httplib2
import os
import sys
import pickle
from apiclient import discovery
from apiclient import errors
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/gmail-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/gmail.labels'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Inbox Organize'
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'gmail-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
def GetLabels(service, user_id):
try:
response = service.users().labels().list(userId=user_id).execute()
labels = response['labels']
"""
for label in labels:
print ('Label id: %s - Label name: %s' % (label['id'], label['name']))
"""
return labels
except errors.HttpError as error:
print ('An error occurred: %s' % error)
def DeleteLabel(service, user_id, label_id):
try:
service.users().labels().delete(userId=user_id, id=label_id).execute()
print ('Label with id: %s deleted successfully.' % label_id)
except errors.HttpError as error:
print ('An error occurred: %s' % error)
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('gmail', 'v1', http=http)
userId = 'me'
labels = GetLabels(service, userId)
for label in labels:
if (label['type'] == 'user'):
print('Deleting label:', label['name'])
DeleteLabel(service, userId, label['id'])
if __name__ == '__main__':
main()
| 30.444444 | 79 | 0.69635 | 1 | 1.5516 | [
0.002551274374127388,
0.025151964277029037,
0.007575204595923424,
-0.00026258709840476513,
0.0031352746300399303,
-0.0025747702457010746,
-0.009451574645936489,
0.0011747857788577676,
-0.007197228260338306,
0.002455113921314478,
0.002845918294042349,
0.004317297134548426,
0.007117012515664101,
-0.015868203714489937,
0.00013695214875042439,
0.014643543399870396,
-0.049743205308914185,
0.00022708115284331143,
-0.003742081578820944,
0.0015126786893233657,
-0.008720741607248783,
0.008935141377151012,
0.009841465391218662,
0.006660790648311377,
0.007428841665387154,
0.0005641778698191047,
0.00998721830546856,
0.0027166898362338543,
-0.009157750755548477,
-0.0066099888645112514,
-0.00031464299536310136,
-0.0009083120967261493,
-0.006235439796000719,
-0.006930002477020025,
0.006249300669878721,
-0.0026569664478302,
-0.0012915139086544514,
-0.01861708052456379,
0.014438522979617119,
-0.004498984664678574,
-0.006944662891328335,
-0.014657450839877129,
0.0008147734915837646,
0.0036020749248564243,
-0.007594534195959568,
0.0005136557738296688,
-0.004352595657110214,
0.0029110813047736883,
-0.010677090846002102,
0.00653656292706728,
-0.009813095442950726,
0.006463360507041216,
0.012762489728629589,
0.003744976595044136,
-0.005267958156764507,
-0.0062697287648916245,
0.012043253518640995,
-0.0001293959649046883,
-0.011289186775684357,
-0.0032708090730011463,
-0.00449585635215044,
-0.0018357000080868602,
0.006554885767400265,
0.002344684209674597,
-0.013830461539328098,
-0.006598497275263071,
-0.004129367880523205,
0.0031239453237503767,
0.0012162375496700406,
0.005703482311218977,
0.0007136192871257663,
0.00025057143648155034,
0.005918753799051046,
0.003487712936475873,
0.004416270647197962,
-0.003494465723633766,
-0.001993051962926984,
0.0011537255486473441,
0.00678364560008049,
0.003593500703573227,
0.004600060172379017,
-0.005213548429310322,
0.004933491349220276,
0.009017438627779484,
0.013718785718083382,
0.007522164843976498,
0.017900638282299042,
-0.011961622163653374,
0.048324622213840485,
0.007613747846335173,
-0.009147760458290577,
0.002171090105548501,
-0.007982069626450539,
-0.0015115708811208606,
-0.004097616765648127,
-0.025508681312203407,
-0.00035603236756287515,
-0.0040873694233596325,
-0.001166603178717196,
0.0029286460485309362,
-0.0002752257278189063,
0.007969729602336884,
-0.0015822086716070771,
-0.002430165419355035,
-0.006120023783296347,
0.010877451859414577,
-0.008296537213027477,
-0.004179368261247873,
0.005523592233657837,
0.002083179308101535,
-0.010244756937026978,
-0.0022361243609339,
0.00319196586497128,
-0.012888569384813309,
0.002714385511353612,
0.001969246892258525,
-0.006507025100290775,
0.0524110347032547,
0.0005052175838500261,
0.003199345897883177,
-0.004219846334308386,
0.0026427176780998707,
0.001768699148669839,
0.005613432265818119,
0.009791452437639236,
-0.0033274886664003134,
0.010300219990313053,
0.009381009265780449,
0.003745745401829481,
0.009424171410501003,
-0.0038402467034757137,
0.008737084455788136,
-0.004412428941577673,
-0.00187019188888371,
0.0023517052177339792,
-0.007408267352730036,
0.008125942200422287,
-0.0026780443731695414,
-0.008496614173054695,
0.0013298579724505544,
-0.0003120139881502837,
-0.00910110305994749,
0.001838097581639886,
-0.005659399088472128,
0.003789662616327405,
-0.011977090500295162,
-0.00218044500797987,
-0.003898697905242443,
-0.004785954020917416,
0.0024175243452191353,
0.011638052761554718,
0.0043954430148005486,
0.002302994951605797,
-0.005639723502099514,
-0.010366292670369148,
-0.0010658468818292022,
-0.002246604533866048,
0.002499287249520421,
0.007389158476144075,
0.0016016822773963213,
-0.01088387705385685,
-0.0009890056680887938,
0.002388075226917863,
0.002052825875580311,
-0.00035868107806891203,
0.0009816689416766167,
-0.009349722415208817,
0.005545559339225292,
-0.00027366014546714723,
0.005120382644236088,
0.011923272162675858,
-0.004033522680401802,
-0.001740619889460504,
-0.0000153737510117935,
0.0033833312336355448,
-0.0010757395066320896,
0.0048421830870211124,
0.010613027960062027,
-0.002720538293942809,
-0.0036462978459894657,
0.002486966550350189,
0.005564299412071705,
0.007589085027575493,
0.004943793639540672,
-0.003226006869226694,
0.0015279583167284727,
-0.005480405408889055,
-0.0018139299936592579,
0.0059098294004797935,
-0.004251714330166578,
0.004992243368178606,
0.0043798936530947685,
-0.014800156466662884,
-0.009838899597525597,
0.00015795535000506788,
-0.007888862863183022,
0.0010609409073367715,
0.01303798146545887,
0.00960323866456747,
-0.003341415897011757,
0.003539098659530282,
-0.008436588570475578,
0.0016679363325238228,
0.0069523463025689125,
0.0007495518657378852,
-0.012744322419166565,
-0.9602440595626831,
0.005611293949186802,
0.0036718628834933043,
-0.0012749546440318227,
0.00582214817404747,
0.0024073771201074123,
0.002804271876811981,
0.003693165723234415,
0.01259730476886034,
-0.010768692009150982,
-0.0063659558072686195,
-0.010763636790215969,
-0.008701182901859283,
-0.0033412212505936623,
-0.007519606966525316,
-0.0029905640985816717,
-0.0051743509247899055,
-0.0060631511732935905,
-0.0016295576933771372,
-0.0033168389927595854,
-0.0031497692689299583,
0.009677198715507984,
-0.0014625269686803222,
0.005319225136190653,
0.002971955109387636,
0.0030069814529269934,
-0.005207337439060211,
-0.003484478686004877,
-0.0020456137135624886,
-0.0025044078938663006,
-0.005861662328243256,
-0.014545735903084278,
-0.002299584448337555,
-0.0018989740638062358,
0.01051553525030613,
0.0005245600477792323,
0.00932085420936346,
-0.002875463105738163,
0.0023939264938235283,
-0.006571211852133274,
0.004522069822996855,
-0.0004013483412563801,
0.0032636115793138742,
-0.02886999398469925,
0.00007644661673111841,
-0.0012191339628770947,
-0.010048742406070232,
0.008243832737207413,
-0.0020579458214342594,
-0.0011755552841350436,
-0.0037870025262236595,
-0.004506869241595268,
0.010206865146756172,
-0.007006611209362745,
0.0023933646734803915,
-0.003966804128140211,
-0.007504670415073633,
-0.00196881708689034,
-0.008739260956645012,
0.0012624141527339816,
0.002634228440001607,
-0.005541222635656595,
-0.005059997085481882,
-0.002157957758754492,
0.0027220104821026325,
0.0036930732894688845,
0.0010714082745835185,
-0.016257666051387787,
-0.004874643869698048,
-0.00031171151204034686,
0.0003661584050860256,
-0.005606909282505512,
-0.003729522228240967,
0.0048165819607675076,
-0.008651269599795341,
0.0047429404221475124,
0.0023365968372672796,
-0.0004486065008677542,
-0.012933764606714249,
-0.0001392386038787663,
-0.007903425954282284,
-0.006800045724958181,
0.0022267482709139585,
-0.005076938774436712,
-0.004697955679148436,
0.0008566577453166246,
0.0002316605969099328,
0.005450928118079901,
-0.005620213225483894,
0.004133203066885471,
0.011293548159301281,
-0.002318793907761574,
-0.008721604943275452,
0.0055253473110497,
0.005778388120234013,
-0.0009702406823635101,
-0.0033371581230312586,
0.0034396478440612555,
0.0090367766097188,
0.008116397075355053,
0.0035469208378344774,
0.005309913773089647,
-0.0002416850911686197,
0.007801317609846592,
-0.0005834031035192311,
-0.0003529377281665802,
-0.002751762978732586,
0.0004798925365321338,
-0.002429590094834566,
-0.0016497416654601693,
-0.0019651998300105333,
-0.0022289766930043697,
-0.012688233517110348,
-0.00935300625860691,
-0.003518355078995228,
-0.0004246851895004511,
0.0029010497964918613,
-0.0030477887485176325,
-0.0005978259723633528,
0.001997169805690646,
0.008603086695075035,
0.0017898111836984754,
-0.0028702220879495144,
0.0007627216400578618,
0.0025046318769454956,
-0.006117093842476606,
0.014180941507220268,
-0.012586245313286781,
0.00768724549561739,
-0.0006027661147527397,
-0.016233133152127266,
0.005160086322575808,
0.008578198961913586,
-0.009143449366092682,
0.0016824998892843723,
0.0035045386757701635,
0.0035012129228562117,
0.0003733833145815879,
-0.0038139435928314924,
-0.002738925162702799,
-0.015448922291398048,
0.0003153521101921797,
0.018741032108664513,
0.000993747846223414,
0.010344991460442543,
0.012120215222239494,
-0.0027598945889621973,
0.003025355050340295,
0.004587498027831316,
0.0007887292886152864,
0.012483198195695877,
-0.009533734992146492,
-0.000638194615021348,
0.0016759263817220926,
-0.004985718987882137,
-0.0018463332671672106,
0.00508012343198061,
0.008113391697406769,
-0.005215706769376993,
0.0011618058197200298,
-0.00801093503832817,
-0.005767005030065775,
-0.018534215167164803,
-0.003195172641426325,
0.005316447466611862,
-0.005003754049539566,
0.004980446305125952,
-0.012832997366786003,
0.006235773209482431,
0.0075175161473453045,
0.00305815483443439,
-0.001271171378903091,
0.00008294897270388901,
0.007056505884975195,
0.01299900934100151,
-0.005565050058066845,
0.0023951949551701546,
0.003365457756444812,
-0.0010174097260460258,
0.0014585318276658654,
0.008866769261658192,
-0.0050885677337646484,
-0.00589255103841424,
0.0036545603070408106,
0.0042599160224199295,
-0.00018018268747255206,
-0.005232894327491522,
-0.008782472461462021,
-0.0019208419835194945,
0.001707345829345286,
-0.0045902542769908905,
0.005101529415696859,
-0.00023382810468319803,
0.0039036658126860857,
-0.005841359496116638,
-0.0014853165484964848,
0.0013538141502067447,
-0.013835124671459198,
0.009579419158399105,
-0.0031948057003319263,
0.002570897340774536,
0.013041224330663681,
0.00393636291846633,
-0.012855798937380314,
0.005080671980977058,
0.010579843074083328,
-0.004202278796583414,
0.003572325222194195,
0.006600258406251669,
-0.006595502607524395,
-0.020391622558236122,
-0.0026919348165392876,
-0.01337806973606348,
0.006154987029731274,
-0.002657933160662651,
0.003598032984882593,
-0.009044555947184563,
0.00786516908556223,
0.00785163976252079,
-0.013378250412642956,
-0.004339068662375212,
-0.007078084163367748,
0.00811126921325922,
0.00022082868963479996,
0.00012249949213583022,
-0.0043210177682340145,
-0.0005364687531255186,
-0.00179213285446167,
-0.002567712916061282,
-0.0016848498489707708,
0.005348272621631622,
0.001023857039399445,
-0.0018746928544715047,
0.0020410160068422556,
-0.005028707440942526,
0.001855492708273232,
0.000051302602514624596,
-0.009702693670988083,
0.0037620316725224257,
0.003832773305475712,
-0.002184768905863166,
-0.0050309584476053715,
0.00199540751054883,
-0.0028763480950146914,
-0.006797645706683397,
-0.011804032139480114,
-0.002955144504085183,
-0.003988088574260473,
-0.0024006792809814215,
-0.011782301589846611,
-0.0029563182033598423,
-0.007537481840699911,
0.00604444881901145,
-0.007739989552646875,
0.008250454440712929,
0.005452436860650778,
-0.005578167736530304,
0.005162136163562536,
-0.0023958405945450068,
0.004378810990601778,
0.0031663812696933746,
0.004509849473834038,
0.0015160227194428444,
-0.005357666406780481,
-0.011502547189593315,
0.01019973959773779,
-0.007610932923853397,
0.0007972989697009325,
0.012836284935474396,
0.004708520602434874,
0.009916558861732483,
0.0010136478813365102,
-0.0000694037662469782,
0.0018215262098237872,
0.007404912728816271,
-0.01253858394920826,
0.0038054045289754868,
-0.0043125762604177,
0.001260916586034,
0.005054702516645193,
-0.003712808946147561,
0.004211592487990856,
0.00975758209824562,
0.0008667568326927722,
-0.005365512799471617,
-0.001718855113722384,
0.003155031008645892,
0.005179086234420538,
-0.011219579726457596,
0.00009727420547278598,
-0.004199353978037834,
-0.003935912158340216,
-0.0026994256768375635,
-0.001395808532834053,
-0.001385547686368227,
0.0035369342658668756,
-0.003201378509402275,
0.005166313145309687,
0.0026601089630275965,
-0.004718173760920763,
0.013468167744576931,
-0.004957079887390137,
-0.004436058923602104,
0.0020525737199932337,
0.0025957769248634577,
-0.0025097825564444065,
-0.006554321851581335,
-0.0008397407364100218,
0.0028389287181198597,
0.0070384228602051735,
-0.0037512609269469976,
-0.005305011756718159,
-0.00035681179724633694,
0.001787374378181994,
-0.009305885061621666,
0.0009939076844602823,
0.01335397269576788,
-0.00500257033854723,
0.006013723090291023,
-0.0033241347409784794,
-0.007790624629706144,
-0.012816608883440495,
0.05448480695486069,
0.00034999416675418615,
0.0042810081504285336,
0.005098435096442699,
-0.00636404799297452,
-0.0001273693924304098,
-0.002938170451670885,
0.007432142738252878,
-0.005784372333437204,
-0.008521837182343006,
0.008748973719775677,
-0.0026397525798529387,
0.004057199228554964,
0.004347939509898424,
-0.002209434052929282,
0.01568674109876156,
-0.0049584065563976765,
-0.017017744481563568,
-0.016635384410619736,
0.006115993484854698,
-0.003380349837243557,
-0.007173741236329079,
0.00986767839640379,
-0.003226229688152671,
-0.004109399393200874,
0.0012590883998200297,
0.004341745283454657,
0.0006240676157176495,
-0.0003439447027631104,
-0.004256598185747862,
-0.0018538113217800856,
-0.0028040867764502764,
0.0020588890183717012,
0.005775426048785448,
0.008647110313177109,
-0.004322811495512724,
0.0042774006724357605,
-0.0032692246604710817,
-0.0016901524504646659,
-0.0023515999782830477,
0.003989832941442728,
0.007809964474290609,
-0.0004949281574226916,
-0.00030912645161151886,
0.005718986503779888,
0.0044367494992911816,
0.0021878459956496954,
0.010270447470247746,
0.0006854343810118735,
-0.004321457352489233,
0.008074279874563217,
0.006968511734157801,
0.00038537534419447184,
0.0073992302641272545,
-0.0009648852865211666,
0.007226767484098673,
0.0004362307954579592,
-0.00808405876159668,
-0.014233945868909359,
-0.0024733999744057655,
0.007366091012954712,
0.009040354751050472,
-0.0009779668180271983,
0.0002908682799898088,
-0.0015355091309174895,
-0.0027389160823076963,
-0.004914605990052223,
-0.007275986019521952,
-0.0010774153051897883,
0.0007078826893121004,
0.0032254625111818314,
0.06902683526277542,
-0.007032422814518213,
0.0004789990489371121,
-0.00814126431941986,
-0.001440661959350109,
-0.0026893524918705225,
-0.0012019281275570393,
-0.0003072777471970767,
-0.0026284109335392714,
0.0008831048617139459,
0.0015457577537745237,
-0.007296515628695488,
-0.012183871120214462,
0.0016115782782435417,
0.00007745418406557292,
-0.002727904822677374,
0.004212321247905493,
0.0061623891815543175,
-0.007832013070583344,
0.0021432009525597095,
-0.010683881118893623,
0.0010173387126997113,
-0.0023345777299255133,
-0.012016483582556248,
-0.003992506768554449,
-0.003403841285035014,
0.0049978275783360004,
0.0031470253597944975,
0.006507435347884893,
-0.0021742498502135277,
0.006861473899334669,
-0.003218031721189618,
-0.0008705661748535931,
-0.0053958892822265625,
0.0006259573274292052,
-0.005423323716968298,
0.0061543104238808155,
0.0017131969798356295,
-0.010018679313361645,
-0.005298615898936987,
0.0005360750947147608,
-0.000005321561729942914,
-0.005782380234450102,
0.0026654547546058893,
-0.0014852189924567938,
0.003966392483562231,
-0.0018348809098824859,
0.00010521829972276464,
-0.006345588248223066,
0.0007045086240395904,
-0.01343175396323204,
0.0058832173235714436,
-0.16996271908283234,
0.010754327289760113,
0.004646854009479284,
-0.004276982508599758,
-0.004537555854767561,
-0.014389792457222939,
-0.004084391053766012,
0.004244237672537565,
0.010130043141543865,
0.0026716934517025948,
-0.002482646144926548,
-0.0011384023819118738,
0.004070119932293892,
0.0048185912892222404,
-0.0021173374261707067,
-0.003901030868291855,
0.00489477114751935,
-0.0019328998168930411,
0.0011730011319741607,
0.0037401632871478796,
0.0036764456890523434,
0.0092387730255723,
-0.00031562469666823745,
0.0006564767681993544,
-0.0019209787715226412,
-0.006460767239332199,
0.005176358390599489,
-0.0008992510265670717,
0.005720196291804314,
-0.012929415330290794,
-0.002519759116694331,
-0.004136877134442329,
-0.004520805086940527,
0.0019029394024983048,
0.004659205675125122,
-0.0009583992068655789,
0.00921516865491867,
0.002396209631115198,
-0.007216637954115868,
0.006825670134276152,
-0.006541426293551922,
0.02983221970498562,
0.005007931496948004,
0.0073264348320662975,
0.0010408046655356884,
-0.005595516879111528,
-0.006146876607090235,
0.009373186156153679,
0.00299705658107996,
0.013203001581132412,
-0.012911896221339703,
-0.000584729656111449,
0.003212659852579236,
0.018188873305916786,
-0.0037083171773701906,
-0.007947515696287155,
-0.006677604280412197,
-0.003146640257909894,
0.002142720390111208,
0.007128220517188311,
0.009986812248826027,
-0.002580305328592658,
0.006447001360356808,
-0.0013087136903777719,
-0.020815204828977585,
0.0033949788194149733,
-0.004451268818229437,
-0.005954142194241285,
0.0031658646184951067,
0.0071389987133443356,
0.00974979531019926,
0.0002466545265633613,
0.0005607950733974576,
-0.0011602496961131692,
0.005971352569758892,
0.001165926456451416,
0.004933778662234545,
-0.0020100087858736515,
0.0033841778058558702,
-0.009179357439279556,
0.007952172309160233,
-0.00935450941324234,
-0.002419092459604144,
0.00034327173489145935,
-0.004854925442487001,
0.012265336699783802,
0.004858709871768951,
-0.0028014713898301125,
-0.002210685983300209,
-0.00807077158242464,
-0.004229635000228882,
0.003906617406755686,
0.0005080312839709222,
-0.009540174156427383,
0.002571944147348404,
0.0017147705657407641,
0.004829047713428736,
0.005620623007416725,
-0.011323872022330761,
0.005687972530722618,
0.0053786844946444035,
-0.005805769935250282,
0.0011456767097115517,
-0.0035456418991088867,
0.0022672382183372974,
0.004356252029538155,
-0.005606682039797306,
-0.006232074461877346,
0.0008666887297295034,
-0.007407360710203648,
-0.004957740195095539,
0.006068187300115824,
-0.009787087328732014,
-0.008834751322865486,
-0.00178439705632627,
-0.01091422513127327,
0.00028808199567720294
] |
8a5251a1a46d1a18949b3dd2b2c26f7e8e32aa06 | 7,795 | py | Python | readgadget/modules/rs_structs.py | danielmarostica/pygadgetreader | 977949da7fcb6585f3e0270019d369c6967b317c | [
"BSD-3-Clause"
] | 6 | 2020-09-02T21:11:59.000Z | 2021-09-24T16:12:44.000Z | readgadget/modules/rs_structs.py | danielmarostica/pygadgetreader | 977949da7fcb6585f3e0270019d369c6967b317c | [
"BSD-3-Clause"
] | 1 | 2021-09-24T14:40:03.000Z | 2021-09-25T20:07:13.000Z | readgadget/modules/rs_structs.py | danielmarostica/pygadgetreader | 977949da7fcb6585f3e0270019d369c6967b317c | [
"BSD-3-Clause"
] | 1 | 2020-11-18T19:15:39.000Z | 2020-11-18T19:15:39.000Z | import numpy as np
import sys
## ROCKSTAR ##
halostruct1 = np.dtype([('id',np.int64),
('pos',np.float32,(6,)),
('corevel',np.float32,(3,)),
('bulkvel',np.float32,(3,)),
('m',np.float32),
('r',np.float32),
('child_r',np.float32),
('vmax_r',np.float32),
('mgrav',np.float32),
('vmax',np.float32),
('rvmax',np.float32),
('rs',np.float32),
('klypin_rs',np.float32),
('vrms',np.float32),
('J',np.float32,(3,)),
('energy',np.float32),
('spin',np.float32),
('alt_m',np.float32,(4,)),
('Xoff',np.float32),
('Voff',np.float32),
('b_to_a',np.float32),
('c_to_a',np.float32),
('A',np.float32,(3,)),
('b_to_a2',np.float32),
('c_to_a2',np.float32),
('A2',np.float32,(3,)),
('bullock_spin',np.float32),
('kin_to_pot',np.float32),
('m_pe_b',np.float32),
('m_pe_d',np.float32),
('dummy1',np.float32), ## ALIGNMENT
('num_p',np.int64),
('num_child_particles',np.int64),
('p_start',np.int64),
('desc',np.int64),
('flags',np.int64),
('n_core',np.int64),
('dummy2',np.float32), ## ALIGNMENT
('min_pos_err',np.float32),
('min_vel_err',np.float32),
('min_bulkvel_err',np.float32)
])
halostruct2 = np.dtype([('id',np.int64),
('pos',np.float32,(6,)),
('corevel',np.float32,(3,)),
('bulkvel',np.float32,(3,)),
('m',np.float32),
('r',np.float32),
('child_r',np.float32),
('vmax_r',np.float32),
('mgrav',np.float32),
('vmax',np.float32),
('rvmax',np.float32),
('rs',np.float32),
('klypin_rs',np.float32),
('vrms',np.float32),
('J',np.float32,(3,)),
('energy',np.float32),
('spin',np.float32),
('alt_m',np.float32,(4,)),
('Xoff',np.float32),
('Voff',np.float32),
('b_to_a',np.float32),
('c_to_a',np.float32),
('A',np.float32,(3,)),
('b_to_a2',np.float32),
('c_to_a2',np.float32),
('A2',np.float32,(3,)),
('bullock_spin',np.float32),
('kin_to_pot',np.float32),
('m_pe_b',np.float32),
('m_pe_d',np.float32),
('halfmass_radius',np.float32),
#('dummy1',np.float32), ## ALIGNMENT
('num_p',np.int64),
('num_child_particles',np.int64),
('p_start',np.int64),
('desc',np.int64),
('flags',np.int64),
('n_core',np.int64),
('dummy2',np.float32), ## ALIGNMENT
('min_pos_err',np.float32),
('min_vel_err',np.float32),
('min_bulkvel_err',np.float32)
])
## ROCKSTAR-GALAXIES ##
halogalaxystruct1 = np.dtype([('id',np.int64),
('pos',np.float32,(6,)),
('corevel',np.float32,(3,)),
('bulkvel',np.float32,(3,)),
('m',np.float32),
('r',np.float32),
('child_r',np.float32),
('vmax_r',np.float32),
('mgrav',np.float32),
('vmax',np.float32),
('rvmax',np.float32),
('rs',np.float32),
('klypin_rs',np.float32),
('vrms',np.float32),
('J',np.float32,(3,)),
('energy',np.float32),
('spin',np.float32),
('alt_m',np.float32,(4,)),
('Xoff',np.float32),
('Voff',np.float32),
('b_to_a',np.float32),
('c_to_a',np.float32),
('A',np.float32,(3,)),
('b_to_a2',np.float32),
('c_to_a2',np.float32),
('A2',np.float32,(3,)),
('bullock_spin',np.float32),
('kin_to_pot',np.float32),
('m_pe_b',np.float32),
('m_pe_d',np.float32),
('dummy1',np.float32), ## ALIGNMENT
('num_p',np.int64),
('num_child_particles',np.int64),
('p_start',np.int64),
('desc',np.int64),
('flags',np.int64),
('n_core',np.int64),
('dummy2',np.float32), ## ALIGNMENT
('min_pos_err',np.float32),
('min_vel_err',np.float32),
('min_bulkvel_err',np.float32),
('type',np.int32),
('sm',np.float32),
('gas',np.float32),
('bh',np.float32),
('peak_density',np.float32),
('av_density',np.float32),
])
def getRSformat(obj):
if obj.galaxies == 0:
if obj.format_revision == 0:
print('OUTDATED ROCKSTAR, PLEASE UPDATE!')
sys.exit()
elif obj.format_revision == 1:
if obj.debug: print('returning halostruct1')
return halostruct1
elif obj.format_revision == 2:
if obj.debug: print('returning halostruct2')
return halostruct2
else:
print('found HALO_FORMAT_REVISION=%d, if this is >2 email me!' %
obj.format_revision)
sys.exit()
elif obj.galaxies == 1:
if obj.format_revision == 0:
print('OUTDATED ROCKSTAR-GALAXIES, PLEASE UPDATE!')
sys.exit()
elif obj.format_revision == 1:
if obj.debug: print('returning halogalaxystruct1')
return halogalaxystruct1
else:
print('found HALO_FORMAT_REVISION=%d, if this is >1 email me!' %
obj.format_revision)
sys.exit()
| 44.289773 | 78 | 0.340988 | 1 | 1.8846 | [
-0.035986997187137604,
-0.011988445185124874,
-0.026614634320139885,
0.013033484108746052,
-0.03668242692947388,
0.010351482778787613,
-0.03978385776281357,
-0.019108397886157036,
-0.009261056780815125,
-0.0012063377071172,
0.02988399565219879,
0.010127151384949684,
0.060085199773311615,
-0.029642323032021523,
-0.0004336809797678143,
0.016396434977650642,
-0.04088600352406502,
-0.10297725349664688,
-0.05931095406413078,
-0.03692002221941948,
0.0073633878491818905,
0.021800734102725983,
-0.0377216599881649,
-0.022159799933433533,
0.009965488687157631,
0.002917076228186488,
0.025944901630282402,
-0.02994036115705967,
0.03054405376315117,
-0.023602357134222984,
0.027126558125019073,
0.03854237496852875,
-0.03486192598938942,
-0.06257717311382294,
0.010682987049221992,
0.028280004858970642,
0.024158459156751633,
0.03364294022321701,
0.05737496167421341,
0.003617044072598219,
-0.0016893085557967424,
-0.0009371552150696516,
-0.012985652312636375,
-0.044114939868450165,
0.029222190380096436,
0.029126036912202835,
-0.010318245738744736,
-0.018000848591327667,
-0.052803993225097656,
0.028368143364787102,
0.011531299911439419,
0.05038878321647644,
-0.03409039229154587,
-0.03281397372484207,
-0.0019161432282999158,
0.017974892631173134,
0.0667266994714737,
0.005472433287650347,
-0.04052336886525154,
-0.03881847858428955,
0.0012738208752125502,
0.06772982329130173,
-0.012593078427016735,
-0.015811463817954063,
0.069646917283535,
-0.015417966060340405,
0.025729862973093987,
-0.001631285296753049,
-0.08339472115039825,
0.02230558544397354,
0.03320034593343735,
0.04076089337468147,
0.033019401133060455,
0.08217504620552063,
0.0035129967145621777,
0.008735072799026966,
-0.004384152591228485,
-0.036931999027729034,
-0.010849947109818459,
-0.05983160808682442,
-0.03519282117486,
0.04387464374303818,
-0.009054606780409813,
0.03372206166386604,
-0.027563387528061867,
-0.020625358447432518,
0.02880222350358963,
-0.030420247465372086,
0.03872532397508621,
0.026790499687194824,
-0.004745053127408028,
-0.029780320823192596,
0.001690806937403977,
-0.004430265165865421,
-0.03556923195719719,
-0.014714185148477554,
0.012626620940864086,
-0.007629477418959141,
-0.01695685088634491,
0.014269129373133183,
0.02419370971620083,
0.014000967144966125,
0.024042513221502304,
-0.007912721484899521,
0.024497928097844124,
0.052410006523132324,
-0.04498216509819031,
-0.008671683259308338,
0.01380986999720335,
-0.023272639140486717,
0.05329955369234085,
0.06632211059331894,
0.030033599585294724,
0.014222265221178532,
-0.044294048100709915,
-0.025687066838145256,
0.010227571241557598,
0.004358099773526192,
0.006179661490023136,
-0.05703825131058693,
0.025353319942951202,
0.031186696141958237,
-0.03645756095647812,
-0.09736527502536774,
-0.032845232635736465,
0.03649201989173889,
-0.009786119684576988,
-0.024294205009937286,
0.01470324769616127,
-0.03043553978204727,
-0.04713675007224083,
0.022144373506307602,
-0.005172617733478546,
-0.026852861046791077,
-0.010882117785513401,
-0.012719696387648582,
-0.015058080665767193,
0.008163350634276867,
-0.06535886973142624,
0.035356223583221436,
0.025293394923210144,
0.028333241119980812,
0.010811430402100086,
0.002377205528318882,
0.030052222311496735,
-0.03611668199300766,
0.005366832483559847,
0.015577666461467743,
0.0019154949113726616,
-0.025294899940490723,
0.03925524279475212,
0.04619830474257469,
-0.037553250789642334,
0.015618004836142063,
-0.011198652908205986,
-0.03357668220996857,
0.040793273597955704,
-0.026584608480334282,
-0.03491737321019173,
-0.02180086262524128,
-0.06397844105958939,
0.05049223452806473,
0.03423839807510376,
-0.016694320365786552,
0.06007205322384834,
0.020002420991659164,
0.036332011222839355,
0.04236236587166786,
-0.0043344274163246155,
0.05462608486413956,
0.044184498488903046,
-0.009081987664103508,
0.017085237428545952,
-0.05593617260456085,
0.10098521411418915,
-0.02613803930580616,
0.02098042145371437,
-0.01585417240858078,
0.028518738225102425,
-0.047135211527347565,
-0.009282932616770267,
-0.027675993740558624,
-0.004617204889655113,
0.03388013318181038,
-0.016077358275651932,
0.04853997007012367,
-0.09166218340396881,
-0.025780485942959785,
0.04521360248327255,
-0.0129336416721344,
-0.04785628244280815,
-0.013495159335434437,
0.03719487413764,
0.010320676490664482,
-0.020988324657082558,
0.013175014406442642,
-0.020931685343384743,
-0.002698922296985984,
0.018833553418517113,
-0.03073597140610218,
0.002758018672466278,
-0.0351320318877697,
0.037074409425258636,
-0.02018975466489792,
-0.0003984873474109918,
0.016224831342697144,
-0.478034108877182,
0.007978315465152264,
-0.013499842956662178,
-0.023668915033340454,
0.008792909793555737,
-0.006847687531262636,
-0.04023568332195282,
0.014121165499091148,
0.0204161349684,
0.05523780733346939,
0.0033962607849389315,
-0.020600415766239166,
-0.06258682161569595,
-0.024374933913350105,
-0.029726875945925713,
-0.000024914977984735742,
-0.005728699266910553,
-0.03637247160077095,
0.01821412518620491,
0.003458794206380844,
0.02400461956858635,
-0.07151288539171219,
0.0010373754194006324,
-0.021684663370251656,
0.06569679826498032,
0.020782778039574623,
0.036680955439805984,
0.005055240821093321,
-0.06489679217338562,
0.033745698630809784,
0.03076872229576111,
0.021273648366332054,
0.02621753327548504,
-0.012900733388960361,
0.03294364735484123,
0.019190441817045212,
0.032789960503578186,
-0.00648407032713294,
-0.020703524351119995,
0.005261696875095367,
-0.032002296298742294,
-0.00534081319347024,
-0.036238402128219604,
-0.055294882506132126,
-0.017697326838970184,
0.008959725499153137,
0.011293050833046436,
-0.0028490202967077494,
0.03078642301261425,
0.03804092854261398,
-0.08113519102334976,
0.04579761251807213,
0.001995092025026679,
-0.009265817701816559,
-0.03800342604517937,
0.006007740739732981,
-0.022430164739489555,
-0.034072235226631165,
0.004648231901228428,
-0.005933631677180529,
0.045227423310279846,
0.058181870728731155,
-0.028305256739258766,
-0.02111460082232952,
-0.0021712135057896376,
0.01589062064886093,
0.013143268413841724,
0.012056087143719196,
-0.05964577570557594,
0.014082802459597588,
0.02381960116326809,
-0.0018281382508575916,
-0.06213071942329407,
-0.005215276498347521,
0.01608678326010704,
0.011875951662659645,
-0.006184266414493322,
-0.0341147854924202,
-0.0011469877790659666,
-0.03452759608626366,
0.027601899579167366,
0.03393609821796417,
0.009463498368859291,
-0.04644736647605896,
0.00040787970647215843,
-0.004504835233092308,
-0.06613317877054214,
0.026122037321329117,
-0.029630128294229507,
-0.003139387583360076,
-0.008953261189162731,
-0.005462272092700005,
-0.05515472590923309,
0.002488549333065748,
-0.015719730406999588,
0.059165842831134796,
-0.0747700184583664,
0.02344740368425846,
-0.020214492455124855,
-0.007495534606277943,
0.03634144365787506,
-0.0007483327062800527,
-0.036309659481048584,
0.05948226526379585,
-0.04937927424907684,
-0.028279054909944534,
-0.012731294147670269,
-0.022934749722480774,
-0.00738489581272006,
-0.03299934044480324,
0.026644162833690643,
4.6475201997964177e-7,
0.021706147119402885,
-0.0002480046823620796,
-0.040316615253686905,
-0.06119875982403755,
-0.02902800589799881,
-0.012492879293859005,
0.01736990176141262,
0.005214103497564793,
-0.016919029876589775,
0.005925239995121956,
0.005662020295858383,
0.00685273390263319,
-0.05479798465967178,
0.07883201539516449,
-0.03255174681544304,
0.009226382710039616,
-0.039559654891490936,
-0.015156148001551628,
0.05222871154546738,
-0.004375069867819548,
-0.031451448798179626,
0.022381657734513283,
-0.010784809477627277,
-0.03372529149055481,
-0.00017994936206378043,
-0.009696053341031075,
0.01169339194893837,
-0.013167569413781166,
0.04358771815896034,
-0.0060283285565674305,
0.021874461323022842,
-0.03518717736005783,
-0.007666211575269699,
0.025201324373483658,
0.0002650210808496922,
-0.002114576520398259,
0.0068078977055847645,
0.04176969826221466,
-0.028949694707989693,
-0.009535522200167179,
-0.012794116511940956,
0.04494563117623329,
-0.01935703307390213,
0.04829519987106323,
-0.051334917545318604,
-0.011785007081925869,
0.0040289307944476604,
0.01835072785615921,
0.007070776540786028,
-0.009025235660374165,
-0.026864340528845787,
0.003485063323751092,
0.026798322796821594,
-0.010143730789422989,
0.030462097376585007,
0.05761834233999252,
0.000036711608117911965,
-0.013375339098274708,
0.03565617650747299,
-0.014613484963774681,
-0.011415899731218815,
-0.02026076801121235,
0.002470326377078891,
-0.014276300556957722,
-0.03622213378548622,
-0.10754530131816864,
-0.02568207122385502,
0.012326769530773163,
-0.0460943840444088,
-0.01699301414191723,
-0.022004544734954834,
-0.027134304866194725,
-0.003748603630810976,
0.05500148981809616,
-0.02654178813099861,
-0.006773053668439388,
-0.006974850781261921,
-0.007366347126662731,
0.06375452131032944,
-0.03194144368171692,
-0.001737757702358067,
0.026072952896356583,
-0.06343143433332443,
-0.05113634094595909,
0.0156896710395813,
-0.012204157188534737,
0.045598339289426804,
-0.005899543408304453,
0.02184911258518696,
0.05658191069960594,
0.023867003619670868,
0.018214093521237373,
-0.05500120669603348,
0.02734452113509178,
-0.003757431171834469,
0.01910342648625374,
-0.0376473031938076,
-0.014484463259577751,
-0.0009705877164378762,
0.01863076724112034,
0.03567618131637573,
-0.02109365537762642,
-0.019079525023698807,
0.004466287791728973,
0.0061143203638494015,
-0.008607025258243084,
0.026772433891892433,
0.023991601541638374,
-0.03884735330939293,
0.015602107159793377,
0.006643201690167189,
0.004141726531088352,
-0.013154181651771069,
-0.016348131000995636,
0.0013272688956931233,
-0.038992125540971756,
-0.0466216504573822,
-0.00271224626339972,
0.014956408180296421,
0.012974489480257034,
-0.06054345518350601,
0.012843254022300243,
-0.003393801162019372,
0.06482794880867004,
-0.014137595891952515,
-0.025729414075613022,
-0.005663685966283083,
0.03090810589492321,
0.011476043611764908,
-0.0788712352514267,
-0.025425048545002937,
-0.010251996107399464,
-0.026753492653369904,
0.002267665695399046,
-0.0029485151171684265,
-0.057810161262750626,
-0.041150886565446854,
-0.010387090034782887,
0.003382254857569933,
0.027638405561447144,
0.006856526713818312,
0.0001257148978766054,
0.021315094083547592,
0.05067099630832672,
-0.023251352831721306,
0.014546421356499195,
-0.0033904993906617165,
0.03554780036211014,
0.009561010636389256,
-0.05336102843284607,
-0.007365782279521227,
-0.04677342250943184,
-0.009295045398175716,
-0.013890006579458714,
-0.03890198841691017,
-0.017337776720523834,
-0.03922934830188751,
0.04474528878927231,
0.007674948778003454,
-0.035006869584321976,
-0.03307505324482918,
-0.0132284602150321,
0.045743100345134735,
-0.005989992059767246,
0.012694275937974453,
-0.008194705471396446,
-0.023686151951551437,
0.026544978842139244,
0.012131166644394398,
0.025452224537730217,
0.002370381262153387,
0.010653659701347351,
-0.029437094926834106,
0.0045763710513710976,
0.08225534111261368,
-0.0007032218272797763,
-0.042904600501060486,
-0.014430560171604156,
-0.009582294151186943,
-0.08801217377185822,
0.01589135080575943,
0.030959276482462883,
0.01607619598507881,
0.022363020107150078,
-0.013682225719094276,
-0.020941810682415962,
0.0028113750740885735,
-0.06168753281235695,
-0.014249755069613457,
-0.030536333099007607,
0.0009892107918858528,
-0.021649057045578957,
0.008581310510635376,
-0.01187356561422348,
0.011625505983829498,
-0.006335461977869272,
0.0461338609457016,
0.02447597123682499,
0.03769439086318016,
-0.010629716329276562,
0.008746610954403877,
0.014720981009304523,
0.028636982664465904,
0.022685933858156204,
-0.018358204513788223,
0.012266107834875584,
0.05168057605624199,
-0.011741443537175655,
0.005037444643676281,
-0.014607331715524197,
0.020600594580173492,
-0.03311462700366974,
-0.004271811340004206,
-0.03788284957408905,
-0.028219666332006454,
-0.005183682776987553,
0.014187520369887352,
0.018161464482545853,
-0.017587650567293167,
0.012682624161243439,
0.03740504011511803,
0.050185080617666245,
-0.028047239407896996,
-0.0037718424573540688,
-0.023657722398638725,
0.025029810145497322,
0.019106922671198845,
0.0223019290715456,
0.02367999590933323,
0.030562153086066246,
-0.020567962899804115,
0.007486412301659584,
0.03135788440704346,
-0.006569569930434227,
0.03584027662873268,
0.07913114130496979,
0.01966482773423195,
0.02461308240890503,
-0.0407535657286644,
-0.020804062485694885,
0.008772960864007473,
-0.011971964500844479,
-0.011867915280163288,
-0.025228573009371758,
-0.029186200350522995,
0.013600679114460945,
-0.028297049924731255,
0.012454967945814133,
-0.03196770325303078,
-0.029238024726510048,
-0.007883061654865742,
-0.04858258366584778,
-0.020019719377160072,
-0.05498749762773514,
0.029215553775429726,
-0.028712434694170952,
0.018355194479227066,
0.005916744004935026,
-0.02235923521220684,
-0.043302271515131,
-0.0630936324596405,
0.04242158308625221,
0.006769543047994375,
0.018175197765231133,
0.05076553300023079,
0.013171548023819923,
0.005990908015519381,
-0.008824758231639862,
0.017554525285959244,
-0.06170470267534256,
0.019249143078923225,
-0.0004948264686390758,
0.041087109595537186,
-0.021207645535469055,
0.020062817260622978,
-0.003908638842403889,
-0.010425664484500885,
-0.04159252718091011,
0.0012661408400163054,
0.051075056195259094,
0.032121580094099045,
0.033151064068078995,
0.06597749143838882,
0.029291294515132904,
-0.051229383796453476,
0.008161235600709915,
-0.0030807468574494123,
-0.03535200655460358,
0.017401453107595444,
0.0008636634447611868,
-0.05881435424089432,
-0.003460584208369255,
0.003481712192296982,
-0.006553541403263807,
0.05389588698744774,
0.008175504393875599,
0.008330647833645344,
0.07372762262821198,
-0.02340204082429409,
0.030114149674773216,
0.004064582753926516,
-0.020596040412783623,
-0.01030287891626358,
0.04264478385448456,
0.00015544697816949338,
0.0048814271576702595,
-0.04998430609703064,
-0.003529865527525544,
-0.00502041494473815,
-0.00017397390911355615,
-0.02344508282840252,
-0.03014938160777092,
-0.07140132039785385,
0.020625459030270576,
-0.02864021621644497,
-0.03368571028113365,
0.013185931369662285,
0.0082970280200243,
-0.032887887209653854,
0.02193637192249298,
-0.0070220730267465115,
0.00006911440141266212,
0.01290248241275549,
0.05041879415512085,
-0.0455067902803421,
-0.0012277410132810473,
0.007397043984383345,
0.022574523463845253,
-0.00982132088392973,
-0.047536760568618774,
0.018660910427570343,
0.04733441025018692,
0.008256403729319572,
-0.018969248980283737,
0.033467814326286316,
0.040295280516147614,
-0.010774658992886543,
-0.039899133145809174,
0.0009987226221710443,
0.032646551728248596,
0.007981888949871063,
-0.012851469218730927,
-0.0006542995106428862,
0.002139122923836112,
0.12729455530643463,
0.036519914865493774,
0.05182305723428726,
0.019621657207608223,
0.0379377156496048,
0.014009994454681873,
-0.007220823783427477,
0.015841111540794373,
0.033035118132829666,
0.055973879992961884,
0.02743218094110489,
-0.004024013876914978,
-0.027538716793060303,
-0.0069120535627007484,
0.03527432307600975,
0.06817261129617691,
-0.04112616553902626,
0.007529763039201498,
0.04137823358178139,
0.007306256331503391,
-0.002332126721739769,
0.01177925243973732,
0.024564124643802643,
0.08544571697711945,
0.01138856541365385,
0.014554622583091259,
0.04791004955768585,
-0.006564038340002298,
0.0705556720495224,
-0.040354277938604355,
-0.022703614085912704,
0.00967684667557478,
-0.012179084122180939,
-0.006975650787353516,
-0.0743153989315033,
0.030075952410697937,
0.021658672019839287,
0.06485398858785629,
0.03889622166752815,
-0.04578344523906708,
0.027781540527939796,
-0.04683760181069374,
0.004210231825709343,
-0.04321502149105072,
-0.014337166212499142,
-0.008982867002487183,
-0.029867712408304214,
0.023452570661902428,
0.013774445280432701,
0.0150300906971097,
0.004305871203541756,
0.0069374945014715195,
-0.036694545298814774,
0.002425144426524639,
0.010047425515949726,
-0.014814338646829128,
-0.01020212285220623,
-0.05363369733095169,
0.0035555630456656218,
0.021840259432792664,
0.038109537214040756,
-0.032272111624479294,
-0.012739377096295357,
-0.07247091084718704,
0.035261768847703934,
-0.03078756295144558,
-0.01822500303387642,
-0.02107352763414383,
-0.006967082619667053,
0.014049675315618515,
-0.03064427711069584,
0.010627898387610912,
0.003505861619487405,
-0.0013770278310403228,
0.015202412381768227,
-0.02234099619090557,
0.023755524307489395,
0.0018799008103087544,
0.024360865354537964,
-0.009230467490851879,
0.026102514937520027,
0.006209626328200102,
-0.031302113085985184,
0.03543224185705185,
0.03851441666483879,
0.013890338130295277,
0.014168152585625648,
-0.00412236200645566,
-0.024486279115080833,
-0.0010082200169563293,
0.003299304284155369,
0.00818758737295866,
0.01598610356450081,
0.040305763483047485,
0.005700260866433382,
0.04360499978065491,
0.015001651830971241,
0.004655767232179642,
0.009714833460748196,
0.01659911498427391,
-0.007497153244912624,
-0.010530714876949787,
0.04212486371397972,
-0.05848744511604309,
-0.0014332039281725883,
0.013649911619722843
] |
8a525a8a02f61d5499bb1c8bffd7e68682942e12 | 9,990 | py | Python | ics2entropiawiki.py | entropia/ics2entropiawiki | d77fa8073c2b18eade1c2b85feaccab8b6598c6b | [
"Apache-2.0"
] | 2 | 2020-01-02T04:52:03.000Z | 2020-03-02T04:00:08.000Z | ics2entropiawiki.py | entropia/ics2entropiawiki | d77fa8073c2b18eade1c2b85feaccab8b6598c6b | [
"Apache-2.0"
] | 8 | 2018-11-06T10:05:43.000Z | 2021-10-09T20:26:16.000Z | ics2entropiawiki.py | entropia/ics2entropiawiki | d77fa8073c2b18eade1c2b85feaccab8b6598c6b | [
"Apache-2.0"
] | null | null | null | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""ics2entropiawiki
Read an ics file with the entropia events and insert them in to the
entropia homepage wiki.
Example:
$ ics2entropiawiki.py --config /etc/ics2entropiawiki/config.ini
Inserts events not in the past to the "Termine" Wiki page and appends past
events to the "Vergangene_Termine" Site
"""
import locale
import configparser
import re
import requests
from argparse import ArgumentParser
from datetime import timedelta, datetime
from ics import Calendar
from mwclient import Site
from dateutil.tz import tzlocal
BOTWARNING = """
<!--
This text is automatically generated by the ics2entropiawiki bot, everything you write and everything you edit
WILL BE OVERWRITTEN
Dieser Text ist vom ics2entropiawiki bot automatisch generiert. Alles was hier manuell editiert, hinzugefügt wird
WIRD ÜBERSCHRIEBEN
-->
"""
TABLE_HEADER = """
{| class="termine" border="1" cellspacing="0" cellpadding="5" width="100%" style="border-collapse:collapse;"
! style="width:250px;" | Datum !! style="width:50px;" | Zeit !! Ort !! Beschreibung\
"""
ARCHIVE_TABLE_HEADER = """
{| class="termine" border="1" cellspacing="0" cellpadding="5" style="border-collapse:collapse;" width="100%"
|width=15%|'''Datum'''
|width=6%|'''Zeit'''
|width=15%|'''Ort'''
|width=69%|'''Beschreibung'''
"""
TABLE_FOOTER = (
"|}",
"\n",
"Weitere Links: [[Vorlage:Termine|Termine]] ",
"([https://entropia.de/index.php?title=Vorlage:Termine&action=edit Bearbeiten]),",
" [[Vorlage:Vergangene_Termine|Vergangene Termine]], [[Anfahrt]]"
)
LINE_SEPARATOR = "|-\n"
try:
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
except locale.Error:
pass
class EntropiaEvent:
"""
Parses an ics Event and converts it to an entropia-wiki suitable form
"""
def __init__(self, event):
"""
:param event: The event to be evaluated
:type event: ics.event.Event
"""
self.event = event
self.begintime = event.begin.datetime.astimezone()
self.endtime = event._end_time.datetime.astimezone()
@property
def location(self):
"""
Retrieve the location of an event
:return: location
:rtype: str
"""
locations = {
"entropia": "[[Anfahrt|Entropia]]",
}
location = " "
if self.event.location:
location = self.event.location
if location.lower() in locations.keys():
location = locations[location.lower()]
return location
@property
def begin_date(self):
"""
:return: Entropia-Wiki formatted begin time
:rtype: str
"""
return self.begintime.strftime("%a., %d.%m.%Y")
@property
def end_date(self):
"""
:return: Entropia-Wiki formatted end time
:rtype: str
"""
end_date = ""
if self.endtime - self.begintime > timedelta(days=1):
end_date = " - " + self.endtime.strftime("%a., %d.%m.%Y")
return end_date
@property
def days_to_event(self):
"""
:return: Days to the start of the event
:rtype: datetime.timedelta
"""
return self.endtime - datetime.now(tz=tzlocal())
@property
def is_past_event(self):
"""
:return: Check if the event lies in the past
:rtype: bool
"""
return self.days_to_event < timedelta(days=0)
@property
def start_time(self):
"""
:return: The starting time of the event
:rtype: str
"""
start_time = " "
if not self.event.all_day:
start_time = self.begintime.strftime("%H:%M")
return start_time
@property
def description(self):
"""
:return: The event's description
:rtype: str
"""
links = None
wiki = None
event = self.event
if event.description:
links = re.findall("^[Ll]ink:(.*)$", event.description)
wiki = re.findall("^[Ww]iki:(.*)$", event.description)
if links and event.name:
description = "["+links[0]+" "+event.name+"]"
elif wiki:
description = wiki[0]
elif not event.name:
description = "N.A."
else:
description = event.name
return description
def __str__(self):
"""
:return: A wiki line describing the event
:rtype: str
"""
return ("| " +
self.begin_date +
self.end_date +
" || " +
self.start_time +
" || " +
self.location +
" || " +
self.description
)
def append_past_events(past_events, wiki_user, wiki_pw, wiki_archive):
"""
Append the "new" past events to the wiki archive page
:param past_events: the past events that were not added to the events page
:type past_events: list
:param wiki_user: bot user for the wiki
:type wiki_user: str
:param wiki_pw: password for the wiki user
:type wiki_pw: str
:param wiki_archive: archive page
:type wiki_archive: str
:return: None
:rtype: None
"""
site = Site('entropia.de', path='/')
site.login(wiki_user, wiki_pw)
page = site.pages[wiki_archive]
text = page.text().split('\n')
last_table_position = 0
for event in past_events:
year_header = "== {} ==".format(event.endtime.strftime('%Y'))
for index, txtline in enumerate(text):
if txtline == '|}':
last_table_position = index
if str(event) in text:
continue
if year_header in text:
append_list = (
'\n' +
LINE_SEPARATOR +
str(event)
)
text = text[:last_table_position]+[append_list, ]+text[last_table_position:]
else:
append_list = (
3 * '\n' +
year_header +
ARCHIVE_TABLE_HEADER +
'\n' +
LINE_SEPARATOR +
'\n' +
str(event) +
'\n|}'
)
text = text[:last_table_position+1]+[append_list, ]+text[last_table_position+1:]
page.save("\n".join(text))
def get_args():
"""
Retrieve arguments from the command line, the config file respectively
:return: Parsed arguments from command line, config file
:rtype: list
"""
parser = ArgumentParser()
parser.add_argument(
"-c", "--config",
default="/etc/ics2entropiawiki/config.ini",
dest="configfile",
help="Configuration file path",
metavar="CONFIG"
)
parser.add_argument(
"-u", "--url",
dest="ics_url",
help="The URL under which the ICS-file can be retrieved",
metavar="URL",
)
parser.add_argument(
"-f", "--file",
dest="local_file",
help="Local ics file",
metavar="FILE"
)
parser.add_argument(
"--wiki-user",
dest="wiki_user",
help="Wiki user",
metavar="WIKIUSER"
)
parser.add_argument(
"--wiki-password",
dest="wiki_pw",
help="Wiki user's password",
metavar="WIKIPW"
)
parser.add_argument(
"--wiki-page",
dest="wiki_page",
help='Wiki page',
metavar='WIKIPAGE'
)
parser.add_argument(
"--wiki-archive",
dest="wiki_archive",
help='Wiki archive',
metavar='WIKIARCHIVE'
)
parser.add_argument(
"-d", "--debug",
dest="debug",
action="store_true",
default=False
)
args = parser.parse_args()
configfile = args.configfile
ics_url = args.ics_url
file = args.local_file
wiki = {
'user': args.wiki_user,
'pass': args.wiki_pw,
'page': args.wiki_page,
'archive': args.wiki_archive,
}
debug = args.debug
if configfile:
config = configparser.ConfigParser()
config.read(configfile)
try:
ics_url = config["default"]["url"]
wiki = config["wiki"]
except KeyError as error:
print("Please have a look at the sample config provided with the package")
raise error
return ics_url, file, wiki, debug
def deradicalise_ical(ics):
"""
:param ics: input file
:type ics: str
:return: file with remove radicale_headers
"""
deradicalised = ""
for line in ics.splitlines():
if 'X-RADICALE-NAME:' not in line:
deradicalised += "\n"+line
return deradicalised
def main():
"""
:return: None
:rtype: None
"""
ics_url, file, wiki, debug = get_args()
event_strings = []
past_events = []
if file:
calendar = Calendar(deradicalise_ical(open(file).read()))
else:
ics_result = requests.get(ics_url)
ics_result.encoding = 'utf-8'
calendar = Calendar(deradicalise_ical(ics_result.text))
for event in sorted(calendar.events, key=lambda ev: ev.begin):
event = EntropiaEvent(event)
if not event.is_past_event:
event_strings.append(
"\n" +
LINE_SEPARATOR +
str(event)
)
else:
past_events.append(event)
append_past_events(past_events, wiki['user'], wiki['pass'], wiki['archive'])
termine = BOTWARNING + "\n" + TABLE_HEADER + "\n" + "".join(event_strings) + "\n" + "".join(TABLE_FOOTER)
if debug:
print(termine)
site = Site('entropia.de', path='/')
site.login(wiki['user'], wiki['pass'])
page = site.pages[wiki['page']]
if termine:
page.save(termine, "Terminbot was here")
page.purge()
if __name__ == '__main__':
main()
| 26.289474 | 116 | 0.563063 | 0 | 0 | [
-0.015761813148856163,
0.05492469295859337,
-0.012667507864534855,
0.006638692691922188,
-0.003942843992263079,
0.00432336563244462,
-0.0362921766936779,
-0.001706323237158358,
0.024306338280439377,
0.018993472680449486,
0.007237378042191267,
-0.0012892897939309478,
0.04883255437016487,
-0.04506761580705643,
0.015887193381786346,
0.003977098502218723,
0.13392116129398346,
-0.012031965889036655,
-0.00022884955978952348,
0.015897367149591446,
0.0035712344106286764,
0.004008797463029623,
-0.005939647555351257,
0.007740152068436146,
0.019852207973599434,
0.0165258776396513,
0.04250909388065338,
-0.011001288890838623,
0.02333991415798664,
-0.023330634459853172,
-0.05239149555563927,
0.01865299604833126,
0.02288362756371498,
0.007877076044678688,
-0.0024799518287181854,
0.008901833556592464,
-0.0229325070977211,
-0.041363608092069626,
0.053564172238111496,
0.03387821465730667,
0.003849174827337265,
-0.026214072480797768,
-0.008379616774618626,
-0.010752753354609013,
0.03758756443858147,
-0.0010227716993540525,
-0.012665865942835808,
-0.0036626358050853014,
-0.025663994252681732,
0.0024938255082815886,
-0.034626975655555725,
0.08294618874788284,
0.0025874595157802105,
0.012587527744472027,
0.029870448634028435,
-0.05719638988375664,
0.014104040339589119,
0.0033681662753224373,
-0.04886527359485626,
-0.046654459089040756,
-0.011664527468383312,
-0.012009036727249622,
0.000554375525098294,
0.016308894380927086,
0.007808154448866844,
0.021646026521921158,
-0.010176097974181175,
-0.001070258324034512,
-0.03513674437999725,
-0.036188755184412,
-0.06790349632501602,
-0.007720767054706812,
0.041260045021772385,
0.0939687117934227,
-0.00035326770739629865,
0.0010861678747460246,
-0.02321484684944153,
-0.03357252851128578,
-0.007946513593196869,
-0.009722729213535786,
-0.015029541216790676,
0.0581832081079483,
-0.005401088390499353,
0.038601554930210114,
0.017270348966121674,
0.0228517334908247,
0.043858401477336884,
-0.0462811179459095,
0.025678357109427452,
0.04153640940785408,
-0.01413832325488329,
-0.0047460575588047504,
0.0026571983471512794,
0.01302935928106308,
-0.028832074254751205,
-0.009549916721880436,
0.012220440432429314,
-0.013129308819770813,
0.022178854793310165,
0.053407154977321625,
0.009845503605902195,
-0.013308710418641567,
0.05021190643310547,
0.007400622591376305,
-0.010506435297429562,
0.00844859704375267,
-0.07116684317588806,
-0.007166395429521799,
-0.008103921078145504,
-0.006362304091453552,
-0.05309739708900452,
0.011475270614027977,
0.022233931347727776,
-0.030676059424877167,
-0.010931801050901413,
-0.03579304367303848,
-0.01168114971369505,
0.032609470188617706,
-0.001745859393849969,
0.13866671919822693,
-0.019422346726059914,
0.00018575919966679066,
-0.025384271517395973,
-0.046128444373607635,
-0.008948893286287785,
0.028987595811486244,
-0.011196636594831944,
0.03654130920767784,
0.001816627918742597,
0.024102408438920975,
0.010947251692414284,
-0.04703974351286888,
-0.03731906786561012,
-0.016387438401579857,
-0.0015324788400903344,
0.001984667731449008,
-0.022676877677440643,
0.06268679350614548,
-0.05030220001935959,
0.0016709334449842572,
0.007099166978150606,
-0.006064917892217636,
0.020742543041706085,
-0.0035430691204965115,
-0.0129581643268466,
-0.041762612760066986,
-0.017502378672361374,
0.004229691810905933,
-0.0001160727915703319,
-0.011700761504471302,
0.01951429806649685,
0.015881765633821487,
-0.005250756163150072,
0.014825536869466305,
-0.02713477984070778,
-0.0008922932320274413,
-0.023789169266819954,
-0.04712517932057381,
-0.027545273303985596,
0.01915890909731388,
-0.017875617370009422,
-0.000993133638985455,
-0.02707267366349697,
0.04898463562130928,
-0.006300505716353655,
0.04326848313212395,
-0.04127116873860359,
0.05802243575453758,
-0.012785417027771473,
-0.028824083507061005,
0.016188012436032295,
0.016994871199131012,
0.0019839175511151552,
0.018097754567861557,
-0.02020845375955105,
0.011175106279551983,
0.05011628195643425,
0.024906953796744347,
0.01793508231639862,
-0.03364508971571922,
0.03193061053752899,
-0.02252921275794506,
0.03295522555708885,
0.05160125344991684,
-0.0012353045167401433,
-0.023130161687731743,
-0.03289644047617912,
0.004307993687689304,
0.018849272280931473,
-0.060040801763534546,
0.0117273461073637,
0.03849310055375099,
-0.008889595046639442,
-0.016196487471461296,
0.02977249212563038,
-0.03883408010005951,
-0.03422478586435318,
0.012279808521270752,
0.024473849684000015,
-0.03636104613542557,
0.0021882904693484306,
0.01148025318980217,
0.043156273663043976,
-0.0036418859381228685,
-0.02576185204088688,
-0.017419252544641495,
-0.6542573571205139,
0.022360121831297874,
0.011268090456724167,
-0.00924583338201046,
-0.00033346295822411776,
0.030009940266609192,
-0.03909440338611603,
0.01779167167842388,
-0.005893674213439226,
-0.049376361072063446,
-0.018731029704213142,
0.013116768561303616,
-0.024905038997530937,
-0.0445563904941082,
0.009386394172906876,
-0.03282386437058449,
-0.011574886739253998,
-0.0044730352237820625,
-0.04251284897327423,
0.03858952596783638,
-0.0003354947839397937,
-0.01182990800589323,
0.01669171266257763,
0.01858554035425186,
0.0004048803821206093,
-0.054461028426885605,
-0.019669020548462868,
0.02474135160446167,
0.0054483492858707905,
-0.009621402248740196,
-0.025497984141111374,
-0.03145907074213028,
0.0036701911594718695,
0.0033025669399648905,
0.03714920952916145,
-0.04831843450665474,
0.009621252305805683,
0.019137075170874596,
-0.028521275147795677,
0.008290335536003113,
0.01896553486585617,
-0.007655489258468151,
0.008089580573141575,
-0.031247811391949654,
-0.056276388466358185,
-0.017086727544665337,
-0.03486853465437889,
-0.019031407311558723,
-0.019566712900996208,
0.02173803187906742,
-0.000640522048342973,
0.04909699782729149,
0.0042297630570828915,
0.024452688172459602,
-0.03265535831451416,
0.017948424443602562,
-0.023165393620729446,
-0.01019994169473648,
-0.028274670243263245,
0.0008265547221526504,
0.01545458659529686,
0.016467612236738205,
-0.017077088356018066,
-0.0043204110115766525,
-0.0020320569165050983,
0.01173071376979351,
0.04070407897233963,
-0.02577672339975834,
-0.03316984698176384,
0.029921500012278557,
-0.028375020250678062,
0.013538628816604614,
-0.046845003962516785,
0.02288820594549179,
0.0038880533538758755,
0.012163981795310974,
-0.024184787645936012,
0.03895260766148567,
0.04145793616771698,
-0.027911974117159843,
-0.012431291863322258,
-0.01575515978038311,
-0.011068478226661682,
-0.04859654977917671,
-0.031228050589561462,
0.05450526624917984,
-0.048016905784606934,
0.028889551758766174,
0.008009878918528557,
0.031709227710962296,
0.05285997316241264,
0.023900136351585388,
-0.04820992797613144,
-0.022518694400787354,
0.012275722809135914,
0.013385164551436901,
-0.02453421987593174,
0.041090261191129684,
0.023341555148363113,
0.0031059731263667345,
-0.02486591227352619,
0.004408563487231731,
0.01942160725593567,
0.007486292161047459,
-0.04424178972840309,
0.036685504019260406,
-0.01843295805156231,
-0.0019238131353631616,
0.0007658199174329638,
-0.035540871322155,
0.03661014512181282,
0.004625157918781042,
-0.005667622201144695,
0.023430757224559784,
0.018505262210965157,
0.0010935900500044227,
0.004079503007233143,
-0.03490243852138519,
0.04895380884408951,
-0.01614641770720482,
0.043878763914108276,
-0.007576322183012962,
0.025141172111034393,
-0.01714852638542652,
0.024630410596728325,
-0.0070816753432154655,
0.00593232735991478,
0.014108224771916866,
-0.018632514402270317,
0.05492020025849342,
-0.02546282298862934,
0.003699966473504901,
0.012980424799025059,
0.018626851961016655,
-0.023148948326706886,
-0.029687980189919472,
-0.023017358034849167,
-0.042763832956552505,
-0.013829769566655159,
-0.0173992607742548,
0.00885540246963501,
-0.018774457275867462,
0.0034021702595055103,
-0.043887000530958176,
0.0025688486639410257,
-0.045591991394758224,
0.005147410091012716,
-0.024330349639058113,
0.02127290517091751,
-0.03763478249311447,
0.0014191385125741363,
0.0453086718916893,
0.006548975128680468,
0.05215912684798241,
-0.022948410362005234,
0.009172692894935608,
0.003237517084926367,
0.0016524033853784204,
0.06548545509576797,
0.007084604352712631,
-0.03022593818604946,
-0.015703843906521797,
-0.014306102879345417,
-0.007808482274413109,
-0.046379659324884415,
-0.0008274856954813004,
0.028787212446331978,
0.012050001882016659,
0.0008773943991400301,
0.037096090614795685,
-0.032615259289741516,
-0.011760936118662357,
0.004219954367727041,
0.025603968650102615,
0.03615740314126015,
-0.02347651496529579,
0.022358331829309464,
-0.03527249023318291,
-0.031187305226922035,
0.052038200199604034,
0.013027148321270943,
-0.01932142861187458,
-0.041689563542604446,
0.020981410518288612,
-0.001872166176326573,
0.00948387011885643,
-0.013950956985354424,
-0.000029617720429087058,
-0.029419010505080223,
-0.008504782803356647,
0.01965385489165783,
0.024039510637521744,
-0.024670029059052467,
0.0013323698658496141,
-0.015433032065629959,
-0.0006991821574047208,
0.0222991444170475,
0.014246066100895405,
0.014492503367364407,
-0.018226854503154755,
-0.011894240975379944,
-0.016443772241473198,
-0.006555889267474413,
-0.008849198929965496,
-0.014882644638419151,
0.028117334470152855,
0.0034518628381192684,
-0.02072843909263611,
-0.006065988913178444,
0.02642567828297615,
-0.012118124403059483,
-0.023709982633590698,
0.012594637461006641,
0.006044158712029457,
-0.05379528924822807,
0.018715692684054375,
-0.01952609233558178,
0.0025845691561698914,
0.008250906132161617,
-0.003792084287852049,
-0.05822638422250748,
-0.007286215201020241,
0.052341707050800323,
-0.004745360929518938,
-0.03658099099993706,
-0.025774035602808,
-0.03180144727230072,
-0.007575740106403828,
-0.008129294030368328,
0.02551819011569023,
-0.03561420738697052,
-0.016425397247076035,
0.014952685683965683,
0.0021834394428879023,
-0.00945418979972601,
0.0023888032883405685,
0.016873428598046303,
-0.018475929275155067,
0.008195803500711918,
0.013112134300172329,
0.0002075093798339367,
-0.01913139410316944,
0.02184990793466568,
0.014218665659427643,
-0.007761161774396896,
-0.008443192578852177,
-0.01669875532388687,
-0.005612383130937815,
-0.067703016102314,
0.0059134466573596,
-0.003008495317772031,
0.08453315496444702,
0.004337209276854992,
0.00039972137892618775,
0.005784549750387669,
0.036663830280303955,
0.02309163101017475,
0.015029373578727245,
0.02216753363609314,
0.009473699145019054,
0.007356169633567333,
0.005173319019377232,
0.010333660989999771,
-0.007511652074754238,
0.004591559991240501,
0.012822144664824009,
-0.02410050854086876,
-0.017912592738866806,
0.0012184339575469494,
0.023374522104859352,
-0.02019426040351391,
-0.020856531336903572,
-0.02699286863207817,
-0.00045894132927060127,
0.011100071482360363,
0.006835905369371176,
0.0065386309288442135,
0.001558237592689693,
-0.024805670604109764,
0.05018222704529762,
-0.022144272923469543,
-0.04414128512144089,
0.023539943620562553,
0.016405925154685974,
-0.015492817386984825,
0.02828812226653099,
-0.01379951648414135,
-0.006367132533341646,
-0.032153498381376266,
-0.028528206050395966,
-0.014719150960445404,
-0.07597757130861282,
-0.021421289071440697,
0.022490128874778748,
-0.01357958372682333,
0.0007285831379704177,
-0.05645986273884773,
-0.026826055720448494,
-0.018630431964993477,
0.0025863931514322758,
0.016347011551260948,
0.030544042587280273,
-0.053021833300590515,
0.025336554273962975,
0.010011553764343262,
-0.00637024687603116,
0.032332103699445724,
0.0310534480959177,
0.027288710698485374,
0.020879734307527542,
0.009176693856716156,
0.005938548129051924,
0.006829231046140194,
-0.028110357001423836,
0.03279799222946167,
0.01169641688466072,
0.04246033728122711,
-0.00036886101588606834,
0.030293632298707962,
-0.013723636977374554,
-0.0016918539768084884,
0.017917171120643616,
-0.021237481385469437,
-0.0012809555046260357,
-0.029532095417380333,
-0.0249940138310194,
-0.03166608884930611,
0.017154205590486526,
0.011058940552175045,
-0.0021811805199831724,
-0.04530879855155945,
0.020814018324017525,
0.0005866161081939936,
-0.006764593999832869,
0.021967751905322075,
-0.011114471592009068,
0.022392984479665756,
0.057683613151311874,
0.04392379894852638,
0.019486958160996437,
-0.0018316229106858373,
0.03404907137155533,
0.005785677582025528,
-0.03137927129864693,
0.01180935651063919,
-0.024444682523608208,
-0.053884267807006836,
0.02728276140987873,
0.03174160420894623,
0.03318607434630394,
-0.02543429657816887,
-0.01740720495581627,
-0.021026965230703354,
0.03426764905452728,
0.0017380461795255542,
-0.0035241544246673584,
-0.021050099283456802,
0.006391327362507582,
0.007085597142577171,
-0.010078239254653454,
0.02394448220729828,
-0.018998226150870323,
-0.025333328172564507,
-0.011397138237953186,
0.024713754653930664,
-0.03456876426935196,
0.021788334473967552,
0.002851976314559579,
-0.001958277774974704,
-0.000264867878286168,
0.033694639801979065,
-0.007390399929136038,
-0.009840982966125011,
0.016433818265795708,
-0.030786961317062378,
0.05021902918815613,
0.04243764281272888,
-0.008899640291929245,
-0.05276200920343399,
-0.009544610045850277,
-0.025841200724244118,
-0.013463511131703854,
0.024691062048077583,
-0.012863666750490665,
0.019040284678339958,
-0.06335994601249695,
-0.009467063471674919,
0.042796581983566284,
-0.01183453667908907,
-0.021239295601844788,
0.018239878118038177,
-0.01007536705583334,
0.042161885648965836,
0.021848684176802635,
-0.008705147542059422,
-0.02047581411898136,
0.006123598664999008,
0.005683461669832468,
-0.007330349180847406,
0.0031734041403979063,
0.010668947361409664,
0.004688101354986429,
0.015682531520724297,
0.005171237979084253,
0.07069643586874008,
-0.008421779610216618,
0.06215183436870575,
-0.006604271940886974,
0.02089267037808895,
0.0362982340157032,
-0.005880666431039572,
-0.019682735204696655,
-0.005540984217077494,
-0.016820043325424194,
0.014508070424199104,
-0.008840788155794144,
0.008643991313874722,
0.005332590080797672,
0.014340066350996494,
-0.011565633118152618,
-0.02309119701385498,
0.00126356678083539,
0.006405119318515062,
-0.0215059332549572,
-0.006259611342102289,
-0.000555771985091269,
-0.0029693085234612226,
-0.017727689817547798,
-0.03136007487773895,
0.005819021724164486,
0.021751947700977325,
-0.05061505734920502,
-0.029236147180199623,
0.02456154301762581,
-0.022068219259381294,
0.01694883219897747,
0.02183508686721325,
0.0021378502715379,
-0.027402363717556,
0.001054283231496811,
0.031418949365615845,
0.010096876882016659,
-0.010714397765696049,
0.039006590843200684,
-0.0016386595088988543,
-0.08065446466207504,
0.032637983560562134,
-0.002937675453722477,
-0.012777689844369888,
-0.0328025221824646,
0.0028563090600073338,
0.03886318579316139,
0.0016860069008544087,
-0.004625343251973391,
0.00006981034675845876,
-0.010892379097640514,
0.011729626916348934,
0.0038876296021044254,
-0.0032912034075707197,
0.022705283015966415,
0.018119141459465027,
0.05153312534093857,
-0.009556311182677746,
0.00352312158793211,
0.027408942580223083,
0.07165417075157166,
-0.005745931062847376,
-0.017149874940514565,
0.026394635438919067,
0.014584844931960106,
0.01574205420911312,
0.008048555813729763,
0.0218815878033638,
-0.00891787838190794,
0.012229611165821552,
0.01819002628326416,
0.030396509915590286,
0.005638745613396168,
0.007036139257252216,
0.010808300226926804,
-0.09685198217630386,
0.031268104910850525,
0.024284690618515015,
0.04811616241931915,
-0.0013896923046559095,
0.010973753407597542,
-0.0021947352215647697,
-0.0044123041443526745,
-0.045111458748579025,
0.05846712365746498,
-0.006513687781989574,
-0.019159764051437378,
0.0044916728511452675,
0.002900324994698167,
0.02014271356165409,
0.014367741532623768,
-0.034370437264442444,
0.036124568432569504,
0.0008376219775527716,
-0.02117195352911949,
-0.008847038261592388,
-0.002038488630205393,
0.04596767574548721,
-0.007048729341477156,
-0.0015151634579524398,
0.017928825691342354,
0.06237740442156792,
-0.00012038571003358811,
-0.032204434275627136,
-0.021780697628855705,
-0.021897314116358757,
-0.009467660449445248,
-0.03796594589948654,
-0.04588186740875244,
0.008389722555875778,
0.033220324665308,
-0.0026920016389340162,
-0.03388712555170059,
0.004301366396248341,
-0.03825399652123451,
0.011821269989013672,
0.018835967406630516,
-0.040151435881853104,
-0.020781589671969414,
0.012800890952348709,
-0.007521459367126226,
-0.02210744470357895,
0.023854373022913933,
0.011001690290868282,
-0.008237876929342747,
0.008074439130723476,
0.008530724793672562,
0.02806778997182846,
-0.013898707926273346,
-0.03905665501952171,
-0.036459311842918396,
-0.01383162010461092,
0.024879232048988342,
-0.023867661133408546,
-0.03148099407553673,
-0.005617971066385508,
0.005762768909335136,
-0.015539458952844143,
0.015195295214653015,
-0.018589403480291367,
-0.012723712250590324,
-0.046228498220443726,
0.03451801836490631,
0.014485417865216732,
0.03237837925553322,
0.009407823905348778,
-0.014655053615570068,
-0.01690884307026863,
0.008385557681322098,
-0.035244740545749664,
-0.06499223411083221,
0.012491215951740742,
0.005916737951338291,
0.005013191141188145,
-0.03519338369369507,
-0.026568859815597534,
-0.02104981616139412
] |
8a525fbb996d5472af74df006412af4f27d25fa6 | 527 | py | Python | Arrays/LeftRotation.py | anand722000/algo_ds_101 | b3e25ce2b2e47e53024f8d349232b04de2837ce3 | [
"MIT"
] | 175 | 2019-12-08T19:48:20.000Z | 2022-03-24T07:38:08.000Z | Arrays/LeftRotation.py | anand722000/algo_ds_101 | b3e25ce2b2e47e53024f8d349232b04de2837ce3 | [
"MIT"
] | 40 | 2019-12-07T08:11:41.000Z | 2020-10-09T08:11:22.000Z | Arrays/LeftRotation.py | anand722000/algo_ds_101 | b3e25ce2b2e47e53024f8d349232b04de2837ce3 | [
"MIT"
] | 95 | 2019-12-07T06:25:31.000Z | 2022-03-03T20:12:45.000Z | #!/bin/python3
import math
import os
import random
import re
import sys
# Complete the rotLeft function below.
def rotLeft(a, d):
alist = list(a)
b = alist[d:]+alist[:d]
return b
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nd = input().split()
n = int(nd[0])
d = int(nd[1])
a = list(map(int, input().rstrip().split()))
result = rotLeft(a, d)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()
| 16.46875 | 49 | 0.548387 | 1 | 0.8421 | [
0.0034236772917211056,
0.022995347157120705,
0.008030070923268795,
0.0005700503243133426,
0.005259562749415636,
-0.0034913152921944857,
-0.009995628148317337,
0.0038517683278769255,
-0.00728241354227066,
-0.0002494386280886829,
0.0017841991502791643,
0.005569247994571924,
0.0068800682201981544,
-0.017657941207289696,
-0.0014841820811852813,
0.01722627319395542,
-0.05218646675348282,
0.001148741808719933,
-0.0011885636486113071,
0.004730704706162214,
-0.00838362518697977,
0.009627433493733406,
0.008563831448554993,
0.004681762307882309,
0.004824343603104353,
-0.0017988611944019794,
0.01006531622260809,
0.00027067583869211376,
-0.00449681980535388,
-0.006099400110542774,
-0.0005432455218397081,
-0.0002400200319243595,
-0.008058689534664154,
-0.007945091463625431,
0.004924949258565903,
-0.005109830293804407,
0.00013747850607614964,
-0.01912667416036129,
0.01274372823536396,
-0.004968550521880388,
-0.0058207125402987,
-0.015692442655563354,
0.00015675243048463017,
0.004746724385768175,
-0.009015528485178947,
0.0031125119421631098,
-0.007116788066923618,
0.0024855805095285177,
-0.011894424445927143,
0.005089516285806894,
-0.009965541772544384,
0.004846073687076569,
0.014619692228734493,
0.004543871618807316,
-0.004238683730363846,
-0.007528253830969334,
0.011602927930653095,
-0.002489988226443529,
-0.01172599196434021,
-0.0008879466913640499,
-0.0032407070975750685,
-0.0019105226965621114,
0.006239444948732853,
0.002132449531927705,
-0.017057174816727638,
-0.006885849870741367,
-0.005623193457722664,
0.0020238624420017004,
-0.0024000597186386585,
0.005338911432772875,
0.0005736221792176366,
0.0005986521719023585,
0.0066136582754552364,
0.003969063051044941,
0.0015528560616075993,
-0.0061676986515522,
-0.0034873608965426683,
-0.0008732435526326299,
0.007218856830149889,
0.003349109087139368,
0.00527177145704627,
-0.006614459212869406,
0.007136486005038023,
0.010434326715767384,
0.012777491472661495,
0.007668353617191315,
0.019584497436881065,
-0.008830742910504341,
0.04536840319633484,
0.008768987841904163,
-0.007356851827353239,
0.0025047268718481064,
-0.007940394803881645,
-0.0034878868609666824,
-0.005230965092778206,
-0.028976334258913994,
-0.0011471861507743597,
-0.0033235165756195784,
-0.0009609183180145919,
0.0054276552982628345,
0.00203384249471128,
0.008149675093591213,
0.00046997430035844445,
-0.004551519174128771,
-0.009234650060534477,
0.01344068069010973,
-0.00996506679803133,
-0.004776802845299244,
0.005472502205520868,
0.002933200215920806,
-0.01415256317704916,
0.0004487427941057831,
0.0009449146455153823,
-0.013880214653909206,
0.00745369540527463,
0.0017211948288604617,
-0.00512032862752676,
0.052376639097929,
-0.0008300747722387314,
0.003065728582441807,
-0.0050203837454319,
0.0009111846447922289,
0.0010702976724132895,
0.007200193591415882,
0.01023475918918848,
-0.0033523349557071924,
0.014031444676220417,
0.007226200774312019,
0.004098691511899233,
0.008283643051981926,
-0.0005636676796711981,
0.007314085029065609,
-0.0031460479367524385,
-0.0020733254496008158,
0.0004523295210674405,
-0.007438963279128075,
0.006149393040686846,
-0.0009778252569958568,
-0.005850955843925476,
0.0029295552521944046,
0.000851451710332185,
-0.010523064061999321,
0.0027593260165303946,
-0.0019097966141998768,
0.005588816944509745,
-0.010558544658124447,
-0.006575802806764841,
-0.0038353074342012405,
-0.005767264403402805,
0.0015425547026097775,
0.01050132978707552,
0.00475563807412982,
0.002244026632979512,
-0.005752952303737402,
-0.007159811910241842,
-0.000541639281436801,
-0.0030322023667395115,
0.0014701394829899073,
0.006739523261785507,
0.006244874559342861,
-0.011289742775261402,
-0.003341063391417265,
0.0020560945849865675,
0.002314262092113495,
-0.0009033771348185837,
0.004865141119807959,
-0.009902924299240112,
0.00852585956454277,
0.0011651403037831187,
0.0033594192937016487,
0.012688848190009594,
-0.003828809130936861,
-0.0003950991958845407,
0.0010255720699205995,
0.004393473267555237,
-0.00007142032700357959,
0.006344649475067854,
0.011680142022669315,
-0.0040118759498000145,
-0.007276029326021671,
0.005619785748422146,
0.004276524297893047,
0.007150930352509022,
0.006385484244674444,
-0.0034712955821305513,
0.002326017012819648,
-0.003770934185013175,
-0.0018317658687010407,
0.008039364591240883,
-0.006502092815935612,
0.005882987752556801,
0.004650087095797062,
-0.014939692802727222,
-0.011107783764600754,
0.00047377985902130604,
-0.007551367860287428,
0.0006394443917088211,
0.013845293782651424,
0.013103971257805824,
-0.003190591000020504,
0.003377167508006096,
-0.012621631845831871,
0.0021491495426744223,
0.010150859132409096,
0.0025696870870888233,
-0.011803139932453632,
-0.9587006568908691,
0.006772138178348541,
0.0031346753239631653,
-0.0020474661141633987,
0.004185701720416546,
0.001939259236678481,
0.0031707100570201874,
0.004481915384531021,
0.015274953097105026,
-0.007574298419058323,
-0.004908270668238401,
-0.00997504498809576,
-0.00949028879404068,
-0.0037228427827358246,
-0.004574102349579334,
-0.0047562918625772,
-0.009091218002140522,
-0.005829320754855871,
-0.0023187408223748207,
-0.001337382011115551,
-0.0025953513104468584,
0.009677939116954803,
0.0006649167044088244,
0.004223471041768789,
0.002976084593683481,
0.003990073688328266,
-0.005098432302474976,
-0.002844835165888071,
0.0002404536644462496,
-0.0024433794897049665,
-0.00570746511220932,
-0.013437941670417786,
-0.004224354401230812,
-0.00006290154124144465,
0.011353306472301483,
0.0007445571245625615,
0.009564276784658432,
-0.001385368057526648,
-0.0009382670978084207,
-0.008876189589500427,
0.005774432793259621,
0.001513223396614194,
0.0020127692259848118,
-0.03012824058532715,
-0.00045935576781630516,
-0.0014850680017843843,
-0.00911271944642067,
0.00727559020742774,
0.0006428880151361227,
-0.0007098866626620293,
-0.002795881126075983,
-0.004827297292649746,
0.006931664887815714,
-0.008845717646181583,
0.002231896622106433,
-0.0015833560610190034,
-0.008486911654472351,
-0.0021045140456408262,
-0.01046924851834774,
0.00156085891649127,
0.004226443357765675,
-0.004184954799711704,
-0.003142536384984851,
-0.005287801381200552,
0.002746282611042261,
0.002361454302445054,
0.002493381267413497,
-0.017452508211135864,
-0.006939185317605734,
0.00010072426812257618,
-0.00033067978802137077,
-0.0021667678374797106,
-0.00402270071208477,
0.0023319139145314693,
-0.009669803082942963,
0.005894420202821493,
0.0030167370568960905,
-0.001498874742537737,
-0.012347441166639328,
0.0009721090900711715,
-0.010447515174746513,
-0.008568831719458103,
0.00247908104211092,
-0.00615922873839736,
-0.005255477968603373,
-0.0019094684394076467,
0.002305992180481553,
0.008857120759785175,
-0.0023932831827551126,
0.001914738561026752,
0.01047129463404417,
-0.0006255201296880841,
-0.009060434065759182,
0.006891503464430571,
0.007555831223726273,
-0.0005924410652369261,
-0.0013179830275475979,
0.003507960820570588,
0.007810747716575861,
0.007515359669923782,
0.0009933614637702703,
0.005454020109027624,
0.0012842051219195127,
0.008956578560173512,
-0.002078823046758771,
0.0012740589445456862,
-0.003774007549509406,
0.0008885411079972982,
-0.0039180247113108635,
0.0006934097036719322,
-0.005791091360151768,
-0.001560588483698666,
-0.013293380849063396,
-0.008513190783560276,
-0.002304135588929057,
-0.0003362778516020626,
0.002125771017745137,
-0.002880303654819727,
0.0002494662767276168,
0.000857371895108372,
0.008577724918723106,
-0.0017612642841413617,
-0.004794673062860966,
-0.0002536018437240273,
0.0013973047025501728,
-0.004373061936348677,
0.014785265550017357,
-0.011744900606572628,
0.007096919231116772,
-0.002081657759845257,
-0.014006153680384159,
0.005195803940296173,
0.01177369337528944,
-0.009228278882801533,
0.003158524399623275,
0.0026434962637722492,
0.0029286695644259453,
-0.002048701047897339,
-0.004796807188540697,
-0.004507511854171753,
-0.0174354687333107,
0.001960668945685029,
0.019918717443943024,
0.0023136064410209656,
0.010497624054551125,
0.01188010536134243,
-0.005813872907310724,
0.0017416997579857707,
0.0066750445403158665,
0.0023327788803726435,
0.013108739629387856,
-0.006425360217690468,
-0.000559087551664561,
0.003457688959315419,
-0.0064957039430737495,
0.0028628893196582794,
0.005594954360276461,
0.0029511097818613052,
-0.0041569131426513195,
0.0016397546278312802,
-0.006613182369619608,
-0.003950712736696005,
-0.018000168725848198,
-0.005498351063579321,
0.007601464632898569,
-0.004187698010355234,
0.0052805314771831036,
-0.012749881483614445,
0.005640310700982809,
0.005598211195319891,
0.005867765285074711,
-0.0008250357932411134,
0.0016246772138401866,
0.00458681071177125,
0.012148040346801281,
-0.007362262345850468,
0.00514136953279376,
0.006229368969798088,
-0.0021764393895864487,
0.0021701958030462265,
0.007005671039223671,
-0.006700684316456318,
-0.00633759330958128,
0.0037621583323925734,
0.004125244449824095,
0.0005276779411360621,
-0.002875050762668252,
-0.0071520027704536915,
-0.003559206146746874,
0.0028697513043880463,
-0.008264821954071522,
0.003728570882230997,
0.000047774276026757434,
0.0034058429300785065,
-0.00569124473258853,
-0.000275046331807971,
-0.0029056326020509005,
-0.01186143048107624,
0.01096831914037466,
-0.0017559423577040434,
0.0027589902747422457,
0.011097419075667858,
0.0025093816220760345,
-0.011396177113056183,
0.006001936737447977,
0.008793273940682411,
-0.0044172885827720165,
0.0019487595418468118,
0.0072272783145308495,
-0.004112954251468182,
-0.022126492112874985,
-0.0023708727676421404,
-0.01407629158347845,
0.008179455064237118,
-0.0021010267082601786,
0.0004066394758410752,
-0.007913718931376934,
0.00851723738014698,
0.004126198124140501,
-0.012683146633207798,
-0.0056754667311906815,
-0.009057325311005116,
0.008969533257186413,
0.0005898593226447701,
-0.0029064626432955265,
-0.002376899588853121,
-0.0019188890000805259,
-0.0007920062635093927,
-0.0024795879144221544,
-0.003909156192094088,
0.0036731057334691286,
0.00284864311106503,
-0.002209585625678301,
0.0038197182584553957,
-0.0026410419959574938,
0.001312516164034605,
0.0006920063751749694,
-0.010299294255673885,
0.000885374320205301,
0.0038291283417493105,
-0.0018662468064576387,
-0.003231575945392251,
-0.000007282098522409797,
-0.0018755736527964473,
-0.0049546509981155396,
-0.011988949961960316,
-0.003520946716889739,
-0.002660027239471674,
-0.0035051077138632536,
-0.012087298557162285,
-0.002771984087303281,
-0.006132297217845917,
0.006779838353395462,
-0.006891895085573196,
0.008480767719447613,
0.006288571283221245,
-0.004636680241674185,
0.007849042303860188,
-0.0007615145295858383,
0.005621739663183689,
0.0009225581889040768,
0.004181132186204195,
0.0010870371479541063,
-0.0053737894631922245,
-0.011109665967524052,
0.010666473768651485,
-0.008901434950530529,
0.0021478880662471056,
0.014238460920751095,
0.0033369334414601326,
0.00934798363596201,
-0.0023940913379192352,
0.0002879480889532715,
0.00048626697389408946,
0.00797539483755827,
-0.012550133280456066,
0.0030088266357779503,
-0.004231847357004881,
-0.0010216818191111088,
0.004310591146349907,
-0.001911795581690967,
0.00014278794697020203,
0.009185142815113068,
0.002713543362915516,
-0.004856665153056383,
-0.00410101842135191,
0.0017643998144194484,
0.00231461925432086,
-0.012822241522371769,
-0.0015514392871409655,
-0.0018208575202152133,
-0.005644388496875763,
-0.00388363772071898,
-0.002731181448325515,
-0.0015374637441709638,
0.004598875995725393,
-0.0006423015147447586,
0.005476310383528471,
0.0056502907536923885,
-0.00803937017917633,
0.013895941898226738,
-0.0023836889304220676,
-0.0016133527969941497,
0.003559292759746313,
0.0030945546459406614,
-0.002169561106711626,
-0.006523042917251587,
-0.0033143770415335894,
0.0021806308068335056,
0.006138163153082132,
-0.0019501387141644955,
-0.003910342697054148,
-0.0012286767596378922,
0.0002719262265600264,
-0.011992163024842739,
0.0006113568670116365,
0.013507434166967869,
-0.005557577591389418,
0.0032032891176640987,
-0.0005685555515810847,
-0.008934232406318188,
-0.012584000825881958,
0.0547574907541275,
0.0013040994526818395,
0.0030562204774469137,
0.004914931952953339,
-0.007203080225735903,
-0.0008068029419519007,
-0.0026197161059826612,
0.008464165963232517,
-0.005084153730422258,
-0.007086797617375851,
0.009980395436286926,
-0.0035684066824615,
0.0027955106925219297,
0.0031986022368073463,
-0.0019985430408269167,
0.01563342846930027,
-0.003109441604465246,
-0.013930183835327625,
-0.01852569170296192,
0.006105209235101938,
-0.004056021571159363,
-0.008398208767175674,
0.008087069727480412,
-0.0014843111857771873,
-0.004390203393995762,
0.0013640017714351416,
0.004710334353148937,
0.0030739097855985165,
-0.0012876776745542884,
-0.0025384605396538973,
-0.0029723646584898233,
-0.0009738514199852943,
0.0040828692726790905,
0.004076055251061916,
0.008103698492050171,
-0.0029658537823706865,
0.004049719776958227,
-0.0013519213534891605,
-0.003083106130361557,
-0.0003506519424263388,
0.005061319563537836,
0.006221731659024954,
-0.0005072808708064258,
-0.001362872077152133,
0.00522850314155221,
0.005122465081512928,
0.0025298616383224726,
0.010843449272215366,
-0.001022355048917234,
-0.00828801840543747,
0.008329812437295914,
0.008601834066212177,
-0.001750726718455553,
0.009038131684064865,
-0.0020032324828207493,
0.006025879178196192,
0.0022797188721597195,
-0.009010953828692436,
-0.015074389986693859,
-0.0018687584670260549,
0.007725678849965334,
0.008439783938229084,
-0.002258335705846548,
0.0010383652988821268,
-0.0010579469380900264,
-0.002852106001228094,
-0.008294856175780296,
-0.005586427170783281,
-0.0039819711819291115,
0.002432028530165553,
0.0032835572492331266,
0.07115048170089722,
-0.00739651545882225,
-0.001932264189235866,
-0.008181343786418438,
0.00005251755646895617,
-0.0020412837620824575,
-0.0009000178542919457,
-0.00008299633191199973,
-0.0006502566975541413,
0.0004009866970591247,
-0.00047466091928072274,
-0.007970941253006458,
-0.009582947008311749,
0.000532407546415925,
0.0037124142982065678,
-0.003974666818976402,
0.003832006361335516,
0.0071725002489984035,
-0.00880715623497963,
0.0025491989217698574,
-0.012526733800768852,
-0.003590673441067338,
-0.0008490492473356426,
-0.008938138373196125,
-0.0049547902308404446,
-0.0015320529928430915,
0.0034700846299529076,
0.004719851538538933,
0.003049504244700074,
-0.0059826914221048355,
0.0052114552818238735,
-0.002648276975378394,
-0.0012871474027633667,
-0.0044497218914330006,
-0.0008415376069024205,
-0.0063810767605900764,
0.008221651427447796,
0.0010852179257199168,
-0.011186419986188412,
-0.0034989400301128626,
-0.00036236949381418526,
0.0008151292568072677,
-0.005310864187777042,
0.0030463566072285175,
-0.0010624375427141786,
0.003417863044887781,
-0.0025782817974686623,
0.0008853430044837296,
-0.00553573714569211,
0.0032041582744568586,
-0.01465807668864727,
0.006585178431123495,
-0.17227548360824585,
0.010689275339245796,
0.0019823946058750153,
-0.0042265839874744415,
-0.003191914176568389,
-0.016876263543963432,
-0.006930913310497999,
0.003574785776436329,
0.009713348001241684,
0.0020095740910619497,
-0.0011555837700143456,
-0.0002594303514342755,
0.005673112813383341,
0.0021660744678229094,
-0.00223411968909204,
-0.004890033043920994,
0.005299913231283426,
-0.004372213035821915,
0.00009262780076824129,
0.0030780539382249117,
0.004961258266121149,
0.008679920807480812,
0.001631544902920723,
0.002329509472474456,
-0.0011830131988972425,
-0.004032043740153313,
0.006034213583916426,
-0.0008710531983524561,
0.0030474229715764523,
-0.009931720793247223,
-0.00287216086871922,
-0.004934130702167749,
-0.002963067265227437,
0.00026900783996097744,
0.005879409611225128,
-0.001266893115825951,
0.008257240988314152,
0.0035393403377383947,
-0.007189465221017599,
0.007333218120038509,
-0.00848845299333334,
0.028414594009518623,
0.003213731572031975,
0.007196161430329084,
0.0016836373833939433,
-0.005400619935244322,
-0.004904530942440033,
0.010610666126012802,
0.0002135085960617289,
0.011050546541810036,
-0.01208930928260088,
-0.0015037225093692541,
0.0026593839284032583,
0.018534353002905846,
-0.005046478006988764,
-0.011207783594727516,
-0.007388975005596876,
-0.0026587063912302256,
0.001929296413436532,
0.00893316324800253,
0.00985691137611866,
-0.004034347832202911,
0.008796347305178642,
-0.0030739151407033205,
-0.019323475658893585,
0.003246154636144638,
-0.0049340128898620605,
-0.009113283827900887,
-0.0009770249016582966,
0.0076786912977695465,
0.011402200907468796,
-0.0018567988881841302,
0.003952997270971537,
-0.0007686966564506292,
0.007139823865145445,
-0.0010799253359436989,
0.00642567640170455,
-0.0016601014649495482,
0.006060746498405933,
-0.009801148436963558,
0.006749027408659458,
-0.009243190288543701,
-0.003249018220230937,
0.001052591484040022,
-0.0043198480270802975,
0.009738142602145672,
0.004392137750983238,
-0.0005036985967308283,
-0.0014004184631630778,
-0.010062123648822308,
-0.002357024932280183,
0.00177658349275589,
0.002958587370812893,
-0.008403932675719261,
0.002522991271689534,
-0.00011736427404684946,
0.005917034111917019,
0.008620536886155605,
-0.0099960807710886,
0.007082861382514238,
0.004501079674810171,
-0.005099114496260881,
-0.0012241152580827475,
-0.0041704922914505005,
0.002632161835208535,
0.003918441012501717,
-0.00510632386431098,
-0.006614586804062128,
0.00659778481349349,
-0.007135516963899136,
-0.0026552120689302683,
0.00581901241093874,
-0.010354111902415752,
-0.008889677003026009,
-0.0001925716787809506,
-0.009785759262740612,
-0.0006035795086063445
] |
8a541e67401b79ca7c42ad0362d81bb514bab960 | 947 | py | Python | tests/unittests/test_zoo.py | SaizhuoWang/carefree-learn | 3bf7b00286cdef556cc00fa2fcba5c390b5b9d20 | [
"MIT"
] | null | null | null | tests/unittests/test_zoo.py | SaizhuoWang/carefree-learn | 3bf7b00286cdef556cc00fa2fcba5c390b5b9d20 | [
"MIT"
] | null | null | null | tests/unittests/test_zoo.py | SaizhuoWang/carefree-learn | 3bf7b00286cdef556cc00fa2fcba5c390b5b9d20 | [
"MIT"
] | 1 | 2021-01-04T02:23:00.000Z | 2021-01-04T02:23:00.000Z | import os
import cflearn
import platform
import unittest
from cfdata.tabular import TabularDataset
num_jobs = 0 if platform.system() == "Linux" else 2
logging_folder = "__test_zoo__"
class TestZoo(unittest.TestCase):
@staticmethod
def _test_zoo_core(model: str) -> None:
x, y = TabularDataset.iris().xy
zoo_folder = os.path.join(logging_folder, f"__{model}__")
zoo = cflearn.Zoo(model)
for key, config in zoo.benchmarks.items():
local_logging_folder = os.path.join(zoo_folder, key)
config["logging_folder"] = local_logging_folder
m = cflearn.make(model, **config).fit(x, y)
cflearn.evaluate(x, y, pipelines=m)
cflearn._rmtree(logging_folder)
def test_fcnn_zoo(self) -> None:
self._test_zoo_core("fcnn")
def test_tree_dnn_zoo(self) -> None:
self._test_zoo_core("tree_dnn")
if __name__ == "__main__":
unittest.main()
| 27.852941 | 65 | 0.663147 | 1 | 0.9906 | [
0.0016773180104792118,
0.023094573989510536,
0.00797781441360712,
-0.00039858309901319444,
0.005630421917885542,
-0.0018969946540892124,
-0.00910553615540266,
0.002871905453503132,
-0.00763715710490942,
0.0020787338726222515,
0.0027450439520180225,
0.004450022242963314,
0.007638591341674328,
-0.017179852351546288,
0.00005801377119496465,
0.018000472337007523,
-0.05296028032898903,
-0.0000407808693125844,
-0.005338937044143677,
0.002229708945378661,
-0.00851879920810461,
0.007950087077915668,
0.008438993245363235,
0.008284847252070904,
0.005689157638698816,
-0.00021901869331486523,
0.011345025151968002,
0.0017470130696892738,
-0.007432383485138416,
-0.008531134575605392,
-0.0006744494894519448,
-0.0009987364755943418,
-0.008615645579993725,
-0.0062128519639372826,
0.006266480777412653,
-0.002696247538551688,
-0.00010383082553744316,
-0.01791512407362461,
0.011151842772960663,
-0.006534920074045658,
-0.00519744073972106,
-0.01681281067430973,
-0.001007855636999011,
0.0035184305161237717,
-0.008963562548160553,
0.0034532679710537195,
-0.004384939558804035,
0.0022861252073198557,
-0.010384984314441681,
0.006681113038212061,
-0.011592088267207146,
0.006063277833163738,
0.012781300581991673,
0.002021247986704111,
-0.006996492389589548,
-0.006767128128558397,
0.01161935180425644,
0.0021561365574598312,
-0.010645381174981594,
0.0009690456208772957,
-0.004580632783472538,
-0.002186273690313101,
0.005722020287066698,
0.003172449301928282,
-0.014339469373226166,
-0.00694795697927475,
-0.005478119943290949,
0.002946605673059821,
-0.0021556206047534943,
0.005398566368967295,
0.0020325775258243084,
-0.0016152061289176345,
0.006779766175895929,
0.004041667096316814,
0.005412706173956394,
-0.002514785621315241,
-0.003479686100035906,
0.00287535204552114,
0.010571847669780254,
0.0025245328433811665,
0.0022978628985583782,
-0.008532196283340454,
0.004013136960566044,
0.011391309089958668,
0.015322578139603138,
0.010643030516803265,
0.02094508707523346,
-0.010068601928651333,
0.04397740215063095,
0.005534177180379629,
-0.009186363779008389,
0.0029282858595252037,
-0.009956816211342812,
-0.0023942904081195593,
-0.0006158312899060547,
-0.029521413147449493,
0.00043241848470643163,
-0.0045549445785582066,
-0.001170101691968739,
0.004157307557761669,
-0.0015455704415217042,
0.005867051426321268,
-0.001770333619788289,
-0.0033707383554428816,
-0.010028263553977013,
0.009197353385388851,
-0.007984473370015621,
-0.003046860685572028,
0.007325639948248863,
0.001607430400326848,
-0.012207928113639355,
-0.0014569670893251896,
0.0008522259304299951,
-0.013489672914147377,
0.00384885142557323,
0.004499092232435942,
-0.00686248391866684,
0.05334699526429176,
-0.0007068488630466163,
0.00377639033831656,
-0.004947145935148001,
0.0010511783184483647,
-0.000977167161181569,
0.003970957826822996,
0.010510986670851707,
-0.003972044680267572,
0.010587954893708229,
0.006561798043549061,
0.004084678366780281,
0.0070309764705598354,
-0.0012595615116879344,
0.009380909614264965,
-0.0038051994051784277,
-0.0015622786013409495,
0.0013006770750507712,
-0.0064094215631484985,
0.007920297794044018,
-0.0020449606236070395,
-0.006648034323006868,
-0.0006366033339872956,
-0.0011905673891305923,
-0.010288920253515244,
0.0002780623035505414,
-0.005029371473938227,
0.0033732973970472813,
-0.012636090628802776,
-0.003520955564454198,
-0.002743885852396488,
-0.004096399061381817,
0.003360876115038991,
0.007603267673403025,
0.0035781541373580694,
0.004248401150107384,
-0.005662262439727783,
-0.009399033151566982,
-0.001443317043595016,
-0.004166964441537857,
0.002635484328493476,
0.007072365842759609,
0.0036849051248282194,
-0.0100996233522892,
-0.0018817782402038574,
0.0014469149755313993,
0.003403760027140379,
0.00003500600723782554,
0.0008315971354022622,
-0.008499556221067905,
0.0076754395850002766,
0.00129468715749681,
0.0054292334243655205,
0.010520386509597301,
-0.004222529474645853,
-0.00022379033907782286,
0.000804097973741591,
0.0004897027392871678,
0.0005640973686240613,
0.004171616397798061,
0.010873953811824322,
-0.002779821865260601,
-0.005302250850945711,
0.003849513130262494,
0.0043949466198682785,
0.00992595124989748,
0.009541051462292671,
-0.0037558325566351414,
0.001658674911595881,
-0.004117833916097879,
-0.0005047195591032505,
0.006427615415304899,
-0.004536306951195002,
0.006589421071112156,
0.004520171321928501,
-0.0138288838788867,
-0.007993885315954685,
-0.0013327521737664938,
-0.008943501859903336,
0.002807922661304474,
0.015247897244989872,
0.010564816184341908,
-0.00013596561620943248,
0.0022114403545856476,
-0.010255719535052776,
0.0006717562791891396,
0.008290632627904415,
0.003241294762119651,
-0.013934856280684471,
-0.9580543041229248,
0.006338618695735931,
0.003968046512454748,
-0.0017636562697589397,
0.0050480058416724205,
0.0031743512954562902,
0.0022880351170897484,
0.0046241311356425285,
0.01317807100713253,
-0.010226782411336899,
-0.006454901769757271,
-0.00882812961935997,
-0.009333379566669464,
0.0009038386633619666,
-0.005900007206946611,
-0.0032354684080928564,
-0.004776679910719395,
-0.006764510180801153,
-0.0026750375982373953,
-0.003732848446816206,
-0.0008519102120772004,
0.009451373480260372,
-0.0014267700025811791,
0.004938125144690275,
0.0034800805151462555,
0.0024370134342461824,
-0.005041954573243856,
-0.001635038061067462,
-0.00364734698086977,
-0.0023807340767234564,
-0.0067660873755812645,
-0.016687342897057533,
-0.004225215874612331,
-0.0035338832531124353,
0.011594388633966446,
0.0009218478226102889,
0.009067459031939507,
-0.0017034367192536592,
0.0031142286024987698,
-0.008471689186990261,
0.004263955168426037,
0.0012582718627527356,
0.00417691096663475,
-0.029375653713941574,
-0.0010238889371976256,
0.00061989133246243,
-0.007838119752705097,
0.006215098313987255,
0.0019127152627333999,
-0.00002165665864595212,
-0.0023118325043469667,
-0.006341491360217333,
0.010129297152161598,
-0.007901588454842567,
0.0042700027115643024,
-0.004845892544835806,
-0.00735809188336134,
-0.002478314097970724,
-0.007633158005774021,
0.0006533266277983785,
0.006406032480299473,
-0.0032868392299860716,
-0.00451687490567565,
-0.003760711755603552,
0.002637430327013135,
0.0013481654459610581,
0.0022342228330671787,
-0.01601755991578102,
-0.005786508787423372,
-0.003563860896974802,
0.001989145064726472,
-0.002482874784618616,
-0.003767856163904071,
0.004329649731516838,
-0.007710108067840338,
0.00589940557256341,
0.002711351728066802,
0.00047945728874765337,
-0.009330829605460167,
0.00038696639239788055,
-0.009867966175079346,
-0.006947709713131189,
0.003112692618742585,
-0.005012988578528166,
-0.004310879856348038,
-0.00006233591557247564,
0.0035920722875744104,
0.009096340276300907,
-0.006223737727850676,
0.004990789107978344,
0.011753642000257969,
-0.005268027540296316,
-0.009966450743377209,
0.005178605206310749,
0.007959677837789059,
0.0006987498491071165,
-0.00371326575987041,
0.001831056084483862,
0.007739769760519266,
0.00771196186542511,
0.0015960963210090995,
0.006142307072877884,
0.00025077068130485713,
0.008815871551632881,
0.0003664432151708752,
0.0020088928285986185,
-0.0003531952970661223,
-0.0020352520514279604,
-0.0031383300665766,
-0.002140503376722336,
-0.003271438181400299,
-0.003650609403848648,
-0.011648912914097309,
-0.009964941069483757,
-0.004751062486320734,
0.0007190962205640972,
0.0010953632881864905,
-0.0033014384098351,
-0.0005618581781163812,
0.0029309005476534367,
0.01059302780777216,
0.00010427634697407484,
-0.004634912125766277,
0.0015802884008735418,
0.0026075353380292654,
-0.005902462173253298,
0.014961094595491886,
-0.010836081579327583,
0.0071098692715168,
-0.0021382353734225035,
-0.015562677755951881,
0.005585577804595232,
0.008010901510715485,
-0.008225303143262863,
0.0003045859921257943,
0.0017362091457471251,
0.0014823514502495527,
-0.0015599310863763094,
-0.004195417743176222,
-0.0026197892148047686,
-0.01792525127530098,
0.00009023558959597722,
0.01968548446893692,
0.00078644382301718,
0.011731338687241077,
0.012493696063756943,
-0.0022906519006937742,
0.004112977534532547,
0.006825082004070282,
-0.000060601261793635786,
0.013572410680353642,
-0.009115512482821941,
-0.0010940332431346178,
0.0010439630132168531,
-0.005762796849012375,
0.0025438738521188498,
0.0055073900148272514,
0.004225745331496,
-0.0029956449288874865,
0.0026860851794481277,
-0.004246491007506847,
-0.003783854888752103,
-0.017846256494522095,
0.00006014292739564553,
0.008155313320457935,
-0.0019668040331453085,
0.004843889269977808,
-0.011308535933494568,
0.002621071645990014,
0.004450594075024128,
0.004856818821281195,
-0.0002205397904617712,
0.0011647705687209964,
0.006772736087441444,
0.011254996992647648,
-0.008044023998081684,
0.0034264230635017157,
0.0019746171310544014,
-0.001004554913379252,
0.00021704152459278703,
0.007090616971254349,
-0.0072693289257586,
-0.005033879075199366,
0.002669369801878929,
0.002809535013511777,
0.0003657527267932892,
-0.003174377139657736,
-0.007719851564615965,
-0.003040305571630597,
0.0035004515666514635,
-0.002496253466233611,
0.0036351969465613365,
0.0042027439922094345,
0.002185551216825843,
-0.008217718452215195,
-0.0006484042387455702,
-0.002961681457236409,
-0.010007495991885662,
0.010754967108368874,
-0.003379569621756673,
0.002983784768730402,
0.014117483049631119,
0.003941680770367384,
-0.012249819003045559,
0.00618063285946846,
0.009160670451819897,
-0.0031423214823007584,
0.005824378691613674,
0.004945361986756325,
-0.006435241550207138,
-0.023158768191933632,
-0.0023893951438367367,
-0.01212532352656126,
0.007306321524083614,
-0.0034596300683915615,
0.002598174847662449,
-0.007784342858940363,
0.008098000660538673,
0.005913203582167625,
-0.014711149968206882,
-0.0042027197778224945,
-0.008490925654768944,
0.007050469052046537,
-0.0012586109805852175,
-0.001317500718869269,
-0.005068608094006777,
-0.002848168835043907,
-0.00219632126390934,
-0.0022681693080812693,
-0.0012831094209104776,
0.005391763523221016,
0.002409478882327676,
-0.0039217909798026085,
0.0032469856087118387,
-0.004115795250982046,
-0.0011591926449909806,
-0.0002281300548929721,
-0.010362750850617886,
0.0017461589304730296,
0.004143883939832449,
-0.0031630978919565678,
-0.0037267140578478575,
0.0003012346860487014,
-0.002531652804464102,
-0.004999993368983269,
-0.010544240474700928,
-0.005094269756227732,
-0.003695545718073845,
-0.0024682790972292423,
-0.009917691349983215,
-0.002674099523574114,
-0.006600114516913891,
0.008363315835595131,
-0.0066870409063994884,
0.005806536879390478,
0.0046929544769227505,
-0.004360059276223183,
0.007342767436057329,
-0.0021237749606370926,
0.003995796199887991,
0.0027839113026857376,
0.0046701026149094105,
0.0020961700938642025,
-0.006574810948222876,
-0.008449923247098923,
0.012568975798785686,
-0.00980603788048029,
-0.00011204218753846362,
0.013362252153456211,
0.006518658250570297,
0.01101237628608942,
0.0009537322330288589,
0.0006838751141913235,
0.0050260829739272594,
0.006630160380154848,
-0.014598052017390728,
0.0042666103690862656,
-0.003698898246511817,
-0.0009781046537682414,
0.004712823778390884,
-0.003634125692769885,
0.002351331990212202,
0.005805040709674358,
0.0024703647941350937,
-0.007129243575036526,
-0.0008538151159882545,
-0.0004941402585245669,
0.0026957422960549593,
-0.011647570878267288,
0.0004289755888748914,
-0.004260675981640816,
-0.0038528824225068092,
-0.002948095789179206,
-0.0018819442484527826,
-0.001862258417531848,
0.006034941412508488,
-0.0021265053655952215,
0.005844755098223686,
0.0026666326448321342,
-0.004123449791222811,
0.01349791418761015,
-0.005437966901808977,
-0.004670009948313236,
0.0018170386319980025,
0.0015337244840338826,
-0.004509364254772663,
-0.006342409644275904,
-0.001468753325752914,
0.0021142151672393084,
0.004738860297948122,
-0.0020707761868834496,
-0.00304493959993124,
-0.0009161735069938004,
0.0006088244845159352,
-0.010116573423147202,
0.0014961492270231247,
0.010758011601865292,
-0.0019858800806105137,
0.0050561740063130856,
-0.00043547985842451453,
-0.006855081766843796,
-0.014381649903953075,
0.05375903844833374,
-0.002091960748657584,
0.003501448780298233,
0.004942075815051794,
-0.00555541692301631,
-0.002272756304591894,
-0.0010967651614919305,
0.008433165960013866,
-0.006485962308943272,
-0.00826621986925602,
0.009172464720904827,
-0.0024765548296272755,
0.0035539104137569666,
0.00223714136518538,
-0.001572083798237145,
0.01686762645840645,
-0.00437703775241971,
-0.019399315118789673,
-0.014879230409860611,
0.0061074127443134785,
-0.0046446421183645725,
-0.005411297082901001,
0.008432713337242603,
-0.003452734323218465,
-0.00146829045843333,
0.00021254096645861864,
0.005697714630514383,
-0.0008224405464716256,
-0.0004540138761512935,
-0.0025060016196221113,
-0.0020484700798988342,
-0.00010939997446257621,
0.003292372217401862,
0.008070462383329868,
0.008275655098259449,
-0.0030250241979956627,
0.004816626198589802,
-0.0002023395209107548,
0.0007643860881216824,
-0.0006160210468806326,
0.004697235766798258,
0.005644674878567457,
-0.0026267871726304293,
-0.0026405982207506895,
0.005812459159642458,
0.006278920918703079,
0.00034244294511154294,
0.010952739976346493,
0.00004058906779391691,
-0.005192207638174295,
0.0081078065559268,
0.007849191315472126,
-0.0017640137812122703,
0.008308381773531437,
-0.002279456704854965,
0.005417673382908106,
0.0001685135212028399,
-0.009405883029103279,
-0.015823030844330788,
-0.002965798368677497,
0.006684550084173679,
0.006113405339419842,
-0.0019821031019091606,
0.0022516355384141207,
0.0009659130009822547,
-0.0029598188120871782,
-0.008319712243974209,
-0.008157651871442795,
-0.004113529343158007,
0.0021487963385879993,
0.004458567593246698,
0.07071226090192795,
-0.007203858345746994,
-0.001873090397566557,
-0.007559814490377903,
-0.0012354593491181731,
-0.0009351195767521858,
0.0006637135520577431,
-0.0008109898772090673,
-0.002712134039029479,
0.002669119043275714,
0.0019426830112934113,
-0.008309128694236279,
-0.010836795903742313,
0.0017683804035186768,
0.0016340629663318396,
-0.0031750809866935015,
0.0035040199290961027,
0.00643136166036129,
-0.008931963704526424,
0.002077730605378747,
-0.011329693719744682,
-0.0025141851510852575,
-0.004081760533154011,
-0.009905830025672913,
-0.005109795834869146,
-0.0030786702409386635,
0.003096209140494466,
0.003010498359799385,
0.0038611767813563347,
-0.0027038666885346174,
0.006084327585995197,
-0.0012770512839779258,
0.0001854399888543412,
-0.002385021885856986,
-0.0012667394476011395,
-0.006898814812302589,
0.0067787752486765385,
0.0022722624707967043,
-0.012222507037222385,
-0.005896782968193293,
-0.0019401260651648045,
-0.0005374277243390679,
-0.005949426908046007,
0.00728977145627141,
-0.0006929814699105918,
0.007555115967988968,
-0.001105547184124589,
0.0022791665978729725,
-0.00560412835329771,
0.00015975412679836154,
-0.01116494182497263,
0.005002024583518505,
-0.17754577100276947,
0.011043863371014595,
0.002815317828208208,
-0.0026168853510171175,
-0.004642241634428501,
-0.013098440133035183,
-0.007996966131031513,
0.0038607893511652946,
0.010906945914030075,
0.003011135384440422,
0.000050149923481512815,
-0.0017607896588742733,
0.005566488020122051,
0.004973653703927994,
-0.0010045819217339158,
-0.006862185429781675,
0.002283673034980893,
-0.00594139751046896,
-0.0004957467317581177,
0.0048883589915931225,
0.004356278106570244,
0.009529595263302326,
0.002010924741625786,
0.002018588362261653,
-0.0006855458486825228,
-0.004547055810689926,
0.003460276871919632,
-0.0036582902539521456,
0.006716989446431398,
-0.010384628549218178,
-0.004066005349159241,
-0.0028680607210844755,
-0.00381750101223588,
0.00016978800704237074,
0.003031978150829673,
0.001477029756642878,
0.006956277880817652,
0.0011912418995052576,
-0.008771788328886032,
0.008386318571865559,
-0.005895575974136591,
0.029541226103901863,
0.003649955615401268,
0.007879648357629776,
-0.00006797120295232162,
-0.005106584168970585,
-0.003407234326004982,
0.00930764339864254,
0.00224094744771719,
0.011525225825607777,
-0.014321993105113506,
-0.004204652737826109,
0.002847876399755478,
0.018026942387223244,
-0.004790564067661762,
-0.00978788174688816,
-0.008082874119281769,
-0.0032316134311258793,
0.00351125979796052,
0.00832656305283308,
0.011252203956246376,
-0.0037330484483391047,
0.005141506902873516,
-0.0026076880749315023,
-0.022666294127702713,
0.0042593395337462425,
-0.00553225027397275,
-0.008211705833673477,
-0.0013014768483117223,
0.007408688310533762,
0.010735070332884789,
-0.001728542847558856,
0.002981239464133978,
-0.002061134669929743,
0.005757868755608797,
-0.002396261552348733,
0.007035152055323124,
-0.00039469668990932405,
0.004790509585291147,
-0.008611682802438736,
0.009270093403756618,
-0.009797496721148491,
-0.0014971172204241157,
0.002807461889460683,
-0.004567592404782772,
0.010861597955226898,
0.003997798077762127,
-0.0034677779767662287,
-0.0016336324624717236,
-0.007882415316998959,
-0.0008413178729824722,
0.002533746650442481,
0.00030026937020011246,
-0.00898152869194746,
0.0038742723409086466,
0.0007477792096324265,
0.006117968820035458,
0.007902568206191063,
-0.010110764764249325,
0.005931777413934469,
0.00487489951774478,
-0.0071386732161045074,
-0.00003401900903554633,
-0.004185137804597616,
0.0034099742770195007,
0.0033916577231138945,
-0.0051495712250471115,
-0.005489081144332886,
0.0031663107220083475,
-0.008038284257054329,
-0.005033418536186218,
0.0047870781272649765,
-0.009417472407221794,
-0.009895130060613155,
-0.0019000682514160872,
-0.011100724339485168,
0.0013025120133534074
] |
8a54334c8ec0d2c98a16bb220c95973a631adeb1 | 3,810 | py | Python | unit_13/26-Data_Structures/4_Merge_Sort_and_Linked_Lists/3_linked_list_merge_sort.py | duliodenis/python_master_degree | 3ab76838ce2fc1606f28e988a3273dd27122a621 | [
"MIT"
] | 19 | 2019-03-14T01:39:32.000Z | 2022-02-03T00:36:43.000Z | unit_13/26-Data_Structures/4_Merge_Sort_and_Linked_Lists/3_linked_list_merge_sort.py | duliodenis/python_master_degree | 3ab76838ce2fc1606f28e988a3273dd27122a621 | [
"MIT"
] | 1 | 2020-04-10T01:01:16.000Z | 2020-04-10T01:01:16.000Z | unit_13/26-Data_Structures/4_Merge_Sort_and_Linked_Lists/3_linked_list_merge_sort.py | duliodenis/python_master_degree | 3ab76838ce2fc1606f28e988a3273dd27122a621 | [
"MIT"
] | 5 | 2019-01-02T20:46:05.000Z | 2020-07-08T22:47:48.000Z | #
# Data Structures: Linked List Merge Sort: The Conquer Step
# Python Techdegree
#
# Created by Dulio Denis on 3/24/19.
# Copyright (c) 2019 ddApps. All rights reserved.
# ------------------------------------------------
from linked_list import Node, LinkedList
def merge_sort(linked_list):
'''
Sorts a linked list in ascending order.
- Recuresively divide the linked list into sublists containing a single node
- Repeatedly merge the sublists to produce sorted swublists until one remains
Returns a sorted linked list.
Runs in O(kn log n) time.
'''
if linked_list.size() == 1:
return linked_list
elif linked_list.is_empty():
return linked_list
left_half, right_half = split(linked_list)
left = merge_sort(left_half)
right = merge_sort(right_half)
return merge(left, right)
def split(linked_list):
'''
Divide the unsorted list at the midpoint into sublists.
Takes O(k log n) quasilinear time.
'''
if linked_list == None or linked_list.head == None:
left_half = linked_list
right_half = None
return left_half, right_half
else: # non-empty linked lists
size = linked_list.size()
midpoint = size // 2
mid_node = linked_list.node_at_index(midpoint-1)
left_half = linked_list
right_half = LinkedList()
right_half = mid_node.next_node
mid_node.next_node = None
return left_half, right_half
def merge(left, right):
'''
Merges two linked lists, sorting by data in nodes.
Returns a new, merged list.
Runs in O(n) linear time.
'''
# Create a new linked list that contains nodes from
# merging left and right
merged = LinkedList()
# Add a fake head that is discarded later to simplify code
merged.add(0)
# Set current to the head of the linked list
current = merged.head
# Obtain head nodes for left and right linked lists
left_head = left.head
right_head = right.head
# Iterate over left and right until we reach the tail node
# of either
while left_head or right_head:
# If the head node of the left is None, we're past the tail
# Add the node from right to merged linkned list
if left_head is None:
current.next_node = right_head
# Call next on right to set loop condition to False
right_head = right_head.next_node
# If the head node of right is None, we're past the tail
# Add the tail node from left to merged linked list
elif right_head is None:
current.next_node = left_head
# Call next on left to set loop condition to False
left_head = left_head.next_node
else:
# Not at either tail node
# Obtain node data to perform comparison operations
left_data = left_head.data
right_data = right_head.data
# If data on left is less than right, set current to left node
if left_data < right_data:
current.next_node = left_head
# Move left head to next node
left_head = left_head.next_node
# If data on left is greater than right, set current to right node
else:
current.next_node = right_head
# Move right head to next node
right_head = right_head.next_node
# Move current to next node
current = current.next_node
# Discard fake head and set first merged node as head
head = merged.head.next_node
merged.head = head
return merged
l = LinkedList()
l.add(10)
l.add(2)
l.add(44)
l.add(15)
l.add(200)
print(l)
sorted_linked_list = merge_sort(l)
print(sorted_linked_list)
| 32.288136 | 81 | 0.630971 | 1 | 1.9161 | [
0.0011698480229824781,
0.02450457587838173,
0.007097312249243259,
-0.0008401676896028221,
0.00364128639921546,
-0.0021016192622482777,
-0.010855584405362606,
0.0024092462845146656,
-0.004794215317815542,
0.003339692484587431,
0.0014898601220920682,
0.005940879695117474,
0.008139378391206264,
-0.015327367931604385,
-0.00006840394053142518,
0.016444247215986252,
-0.05199674144387245,
0.0015872679650783539,
-0.002216581255197525,
0.0005778362974524498,
-0.008931901305913925,
0.008605086244642735,
0.009303070604801178,
0.004199619870632887,
0.006647143978625536,
0.0003371362981852144,
0.008135566487908363,
0.001499239238910377,
-0.008482605218887329,
-0.005567373242229223,
-0.0006967568187974393,
-0.001894141430966556,
-0.0051753222942352295,
-0.008359523490071297,
0.005977808032184839,
-0.003747343085706234,
-0.0018880629213526845,
-0.018855588510632515,
0.01469662506133318,
-0.0034637972712516785,
-0.0047208224423229694,
-0.013267738744616508,
0.0013295157114043832,
0.002919931197538972,
-0.0075258249416947365,
0.00043731590267270803,
-0.006254495587199926,
0.0011514415964484215,
-0.010615736246109009,
0.005956754088401794,
-0.008185300044715405,
0.005571859423071146,
0.013393879868090153,
0.0033640102483332157,
-0.006463262718170881,
-0.005360742099583149,
0.012304863892495632,
-0.00020005356054753065,
-0.009486964903771877,
-0.0010433315765112638,
-0.0023878188803792,
-0.0014858065405860543,
0.004196126479655504,
0.0026133209466934204,
-0.013852978125214577,
-0.008315418846905231,
-0.004912542644888163,
0.0021174014545977116,
-0.0016642631962895393,
0.004953455645591021,
0.001542066689580679,
0.0005570053472183645,
0.006140152458101511,
0.004407881759107113,
0.004047892522066832,
-0.0026684848126024008,
-0.0036854420322924852,
-0.0003778607933782041,
0.008660516701638699,
0.0034273152705281973,
0.003940548747777939,
-0.00793332140892744,
0.006958204321563244,
0.01015331968665123,
0.013491847552359104,
0.00459281075745821,
0.018241455778479576,
-0.01182478480041027,
0.047236859798431396,
0.007590059656649828,
-0.007460552733391523,
0.0026533138006925583,
-0.007975544780492783,
-0.001463624881580472,
-0.0032328851521015167,
-0.0278328824788332,
0.0009813988581299782,
-0.005259613040834665,
0.0005995830288156867,
0.002835246967151761,
-0.0005089910118840635,
0.007819654420018196,
0.00012252744636498392,
-0.0037542812060564756,
-0.007192335091531277,
0.010354327969253063,
-0.007189139723777771,
-0.003874617163091898,
0.0054926457814872265,
0.0010382168693467975,
-0.01089340727776289,
-0.002169862389564514,
0.0034783771261572838,
-0.012125412002205849,
0.002354415599256754,
0.0017521569970995188,
-0.004531834740191698,
0.05261171609163284,
-0.00001741429696267005,
0.003913894761353731,
-0.004536152817308903,
0.0019589457660913467,
0.0022685681469738483,
0.006285569630563259,
0.010497522540390491,
-0.0037739831022918224,
0.012261844240128994,
0.007271124515682459,
0.003872197587043047,
0.008398232981562614,
-0.003037142800167203,
0.006838927511125803,
-0.005342773161828518,
-0.002062267856672406,
0.0008612617966718972,
-0.005971104372292757,
0.007462783716619015,
-0.0032980134710669518,
-0.007301758974790573,
0.0019934421870857477,
-0.0012248370330780745,
-0.009878707118332386,
0.0020576680544763803,
-0.003722000867128372,
0.004598093684762716,
-0.009563198313117027,
-0.0021805227734148502,
-0.002247414318844676,
-0.00549523439258337,
0.0010216200025752187,
0.011243232525885105,
0.0024548983201384544,
0.002575565129518509,
-0.004638447891920805,
-0.00869001541286707,
0.00025556754553690553,
-0.0017465637065470219,
0.0012431323993951082,
0.008846690878272057,
0.003950920421630144,
-0.011396553367376328,
-0.0016831062966957688,
0.0008264494827017188,
0.0008823501993902028,
-0.0008319295011460781,
0.004600924905389547,
-0.008337646722793579,
0.006949482019990683,
-0.0011517246020957828,
0.003909895196557045,
0.011321124620735645,
-0.0033534627873450518,
0.00019573453755583614,
0.0004046685353387147,
0.0016043786890804768,
-0.0006973905256018043,
0.0037180730141699314,
0.009199332445859909,
-0.0018815603107213974,
-0.0037852642126381397,
0.00425596022978425,
0.0034349539782851934,
0.00748848170042038,
0.002620463725179434,
-0.0025532194413244724,
0.0022358247078955173,
-0.005846927873790264,
-0.002793361898511648,
0.006506070028990507,
-0.003048738231882453,
0.00535727059468627,
0.005660641938447952,
-0.012735321186482906,
-0.009119285270571709,
-0.0013130157021805644,
-0.008063527755439281,
0.0007116537308320403,
0.014146583154797554,
0.011112912558019161,
-0.0018813437782227993,
0.00236517027951777,
-0.010322020389139652,
0.0004196453664917499,
0.009721538983285427,
0.002282207366079092,
-0.011654828675091267,
-0.9601352214813232,
0.007903008721768856,
0.004122838843613863,
-0.001625183504074812,
0.006368156522512436,
0.002969062188640237,
0.00471260491758585,
0.003924454562366009,
0.011800553649663925,
-0.008790832944214344,
-0.006594992242753506,
-0.01184292882680893,
-0.012985844165086746,
-0.0021743837278336287,
-0.005839603953063488,
-0.0033361301757395267,
-0.006667614448815584,
-0.007660267874598503,
-0.0026727921795099974,
-0.003338705748319626,
-0.000711566477548331,
0.007946472615003586,
-0.0006069724913686514,
0.0061994390562176704,
0.0025714770890772343,
0.0029266877099871635,
-0.006436260882765055,
-0.002660291036590934,
-0.002295828191563487,
-0.003359775757417083,
-0.006017250940203667,
-0.013954461552202702,
-0.003489857539534569,
-0.0010256192181259394,
0.00885893777012825,
0.0025011065881699324,
0.00881856121122837,
-0.0031567339319735765,
0.0010067418916150928,
-0.008213983848690987,
0.004293513018637896,
0.0002733139263000339,
0.0015067373169586062,
-0.02819669619202614,
0.0008886438445188105,
0.0010707093169912696,
-0.009789111092686653,
0.006192948203533888,
-0.000549156276974827,
0.00008115443051792681,
-0.004636065103113651,
-0.006103743799030781,
0.008477719500660896,
-0.00629200367256999,
0.00513867661356926,
-0.00430038059130311,
-0.010225653648376465,
-0.0003055076231248677,
-0.0074404943734407425,
-0.00001393586444464745,
0.0030219934415072203,
-0.003416879568248987,
-0.0038130120374262333,
-0.0032798657193779945,
0.0024779809173196554,
0.003070252947509289,
0.0031495383009314537,
-0.01940978318452835,
-0.0049614496529102325,
0.0014329906553030014,
0.0017831887817010283,
-0.0028542201034724712,
-0.004539042245596647,
0.0038167915772646666,
-0.008484020829200745,
0.005823074374347925,
0.0030880013946443796,
-0.0006103707128204405,
-0.012328931130468845,
-0.001519060810096562,
-0.007971596904098988,
-0.006705034989863634,
0.0010088541312143207,
-0.004399426747113466,
-0.004340574145317078,
0.0006758963572792709,
0.0016192847397178411,
0.005608820356428623,
-0.004941144492477179,
0.0030057516414672136,
0.01071203127503395,
-0.002691185101866722,
-0.009465801529586315,
0.005524368025362492,
0.00577154103666544,
0.000900566577911377,
-0.0033317531924694777,
0.0066506098955869675,
0.008139102719724178,
0.008123465813696384,
0.0027386974543333054,
0.0037420825101435184,
0.0016607454745098948,
0.00810522772371769,
-0.0008777460898272693,
-0.00005747840623371303,
-0.0036602055188268423,
0.00003824729719781317,
-0.004448124207556248,
-0.0001892829459393397,
-0.003358934773132205,
-0.0037695406936109066,
-0.010661539621651173,
-0.010057191364467144,
-0.004193717148154974,
0.00023604129091836512,
0.0025105883833020926,
-0.004478137474507093,
-0.0024720916990190744,
0.001070588012225926,
0.007907073944807053,
0.001601060968823731,
-0.005763353779911995,
-0.00017876709171105176,
0.00289172469638288,
-0.005263158585876226,
0.014100557193160057,
-0.012262402102351189,
0.0074255685321986675,
0.0002477732195984572,
-0.016237445175647736,
0.0074343434534966946,
0.00862027145922184,
-0.009141026064753532,
0.0014933523489162326,
0.002084763254970312,
0.0034201601520180702,
0.0012610384728759527,
-0.004840245936065912,
-0.004678884521126747,
-0.01827125810086727,
-0.000044716358388541266,
0.019066130742430687,
0.0015636737225577235,
0.009996148757636547,
0.012050556018948555,
-0.0038952704053372145,
0.002393467351794243,
0.006628777366131544,
0.0008647728827781975,
0.01366286538541317,
-0.008627175353467464,
-0.0006067200447432697,
0.0026218893472105265,
-0.0072725685313344,
0.000529539305716753,
0.0044868094846606255,
0.004750023130327463,
-0.004792100749909878,
0.00294923922047019,
-0.007052246015518904,
-0.0032849404960870743,
-0.015947159379720688,
-0.00446888105943799,
0.005062684416770935,
-0.0037738720420747995,
0.004482939373701811,
-0.011075392365455627,
0.0059033771976828575,
0.006839995738118887,
0.00544291315600276,
0.00004939787686453201,
0.0011522668646648526,
0.005591235589236021,
0.012113712728023529,
-0.005566839128732681,
0.0005394454346969724,
0.0040397047996521,
-0.002108317567035556,
0.00035946667776443064,
0.005506965331733227,
-0.006247634533792734,
-0.004849809221923351,
0.0025249544996768236,
0.005082977935671806,
-0.0021991454996168613,
-0.003517071483656764,
-0.007449363823980093,
-0.004110244102776051,
0.002270412864163518,
-0.007391910068690777,
0.0046127913519740105,
-0.001654469990171492,
0.003315193811431527,
-0.006631792057305574,
-0.003343850141391158,
-0.0015976346330717206,
-0.013139729388058186,
0.011838855221867561,
-0.003200500039383769,
0.003923455253243446,
0.012119083665311337,
0.0047896308824419975,
-0.01251205150038004,
0.004028593190014362,
0.010731836780905724,
-0.003781814593821764,
0.004678074736148119,
0.0057915388606488705,
-0.007029925938695669,
-0.020910462364554405,
-0.0024024941958487034,
-0.012235159054398537,
0.004169691354036331,
-0.0020559707190841436,
0.003981018904596567,
-0.008701600134372711,
0.006487702950835228,
0.00846379529684782,
-0.012891994789242744,
-0.008202636614441872,
-0.007918564602732658,
0.00745233241468668,
0.0009082151227630675,
-0.0019978045020252466,
-0.0029418219346553087,
-0.0005942449788562953,
0.0000748836318962276,
-0.0033691879361867905,
-0.0027178365271538496,
0.006313095800578594,
0.0034738320391625166,
-0.0021860473789274693,
0.001876052119769156,
-0.0025762137956917286,
0.0013225709553807974,
0.00008324663940584287,
-0.00914253480732441,
0.0039046527817845345,
0.0031415061093866825,
-0.004072032868862152,
-0.001302089192904532,
0.000926792505197227,
-0.004904897417873144,
-0.006331283133476973,
-0.012144047766923904,
-0.004553331062197685,
-0.00355346268042922,
-0.004166574217379093,
-0.012198949232697487,
-0.0018038572743535042,
-0.0076302532106637955,
0.007472079712897539,
-0.006625584792345762,
0.008588309399783611,
0.0061884610913693905,
-0.004561753012239933,
0.0056578353978693485,
-0.0016955123282968998,
0.005920665338635445,
0.0017559695988893509,
0.006786581594496965,
0.0017692400142550468,
-0.004873035009950399,
-0.010337854735553265,
0.012476089410483837,
-0.008227723650634289,
-0.000010527132872084621,
0.015418567694723606,
0.006306760478764772,
0.008891577832400799,
0.0013805655762553215,
0.0014812087174504995,
0.0011009356239810586,
0.0061110639944672585,
-0.013235538266599178,
0.005177393555641174,
-0.004978639539331198,
0.00007834508869564161,
0.004204033873975277,
-0.004058273509144783,
0.0006461239536292851,
0.008954514749348164,
0.000045159416913520545,
-0.008117717690765858,
-0.0005548651097342372,
0.0025105250533670187,
0.00220570364035666,
-0.012289122678339481,
0.0018047861522063613,
-0.002814867999404669,
-0.004717730917036533,
-0.0027866323944181204,
-0.0015852134674787521,
0.001566779101267457,
0.002183884149417281,
-0.0007251984789036214,
0.005194396246224642,
0.0025021685287356377,
-0.005429680459201336,
0.01378562767058611,
-0.004485273268073797,
-0.0021839768160134554,
0.005704801995307207,
0.0018637027824297547,
-0.0025126116815954447,
-0.00414011487737298,
0.0006337765953503549,
0.001989298965781927,
0.0071030547842383385,
-0.003085185308009386,
-0.0031590904109179974,
-0.0019183872500434518,
-0.0002657344448380172,
-0.00907814595848322,
0.0005620314623229206,
0.01338108628988266,
-0.006337364669889212,
0.006936042569577694,
-0.0026392084546387196,
-0.007064315490424633,
-0.014121750369668007,
0.05355503782629967,
0.0012722999090328813,
0.003849797183647752,
0.0032323501072824,
-0.007104983553290367,
0.0003037036512978375,
-0.001465435023419559,
0.007289043627679348,
-0.006270999554544687,
-0.007779830601066351,
0.009133424609899521,
-0.00382677698507905,
0.003579342272132635,
0.003742997068911791,
-0.0005136709660291672,
0.014817442744970322,
-0.001319224014878273,
-0.01607542484998703,
-0.015513403341174126,
0.007025097031146288,
-0.00290673621930182,
-0.006798504386097193,
0.009516273625195026,
-0.0036040102131664753,
-0.0016476005548611283,
0.0010286594042554498,
0.00492278765887022,
-0.0013516314793378115,
0.000038554902857868,
-0.002708826446905732,
-0.002051146002486348,
-0.0007821001927368343,
0.003367629135027528,
0.003861088305711746,
0.006399229168891907,
-0.0022335974499583244,
0.004752499982714653,
-0.00125797837972641,
-0.0011213853722438216,
-0.0030490329954773188,
0.004660382866859436,
0.008334694430232048,
-0.0016573048196732998,
-0.0007894976297393441,
0.005822805687785149,
0.004403415136039257,
0.0031938471365720034,
0.011723889037966728,
0.00007615069625899196,
-0.004887812305241823,
0.00914444774389267,
0.006676764227449894,
-0.00012322711700107902,
0.009574309922754765,
-0.00004761857780977152,
0.00644605653360486,
0.0020985675510019064,
-0.009717659093439579,
-0.01342374924570322,
-0.004464148543775082,
0.009898776188492775,
0.008862496353685856,
-0.0026499025989323854,
-0.0013876905431970954,
-0.0026020570658147335,
-0.0014792557340115309,
-0.005733627360314131,
-0.007578424643725157,
-0.002377196215093136,
0.0023452164605259895,
0.0053094965405762196,
0.07025875151157379,
-0.007032329216599464,
-0.0028858680743724108,
-0.008652503602206707,
-0.0008010083111003041,
-0.004756769631057978,
-0.0002761453506536782,
0.0000037329741644498426,
0.00002064865293505136,
0.0014426979469135404,
0.001361026894301176,
-0.008514035493135452,
-0.011011120863258839,
0.001742356107570231,
0.0008617600542493165,
-0.0021016565151512623,
0.003919320181012154,
0.005428175907582045,
-0.00842411257326603,
0.00006573701102752239,
-0.011508414521813393,
-0.0010261870920658112,
-0.001563310157507658,
-0.010565485805273056,
-0.004149033222347498,
-0.004882628098130226,
0.003968901000916958,
0.0027886482421308756,
0.004548605065792799,
-0.003390186931937933,
0.007308203727006912,
-0.003972550854086876,
-0.0011384538374841213,
-0.005681624170392752,
-0.00022090431593824178,
-0.006589420605450869,
0.009459498338401318,
0.0017329344991594553,
-0.010844013653695583,
-0.003519243560731411,
0.0016334604006260633,
-0.000499021029099822,
-0.004375406540930271,
0.004104070831090212,
-0.0027511247899383307,
0.003671378828585148,
-0.002924158936366439,
0.0011434232583269477,
-0.006742540281265974,
0.002261202549561858,
-0.013228780589997768,
0.004102200269699097,
-0.1698981076478958,
0.01047556009143591,
0.005199138540774584,
-0.0051285759545862675,
-0.004508511628955603,
-0.014096156693994999,
-0.004240145906805992,
0.0031378655694425106,
0.007516734767705202,
0.0029834865126758814,
-0.002309541217982769,
-0.0014066353905946016,
0.0047540063969790936,
0.0026276418939232826,
-0.0025237933732569218,
-0.00350971519947052,
0.005637063644826412,
-0.004511588253080845,
0.00134566193446517,
0.002560713794082403,
0.0061048055067658424,
0.011436648666858673,
0.0015008995542302728,
0.00349259446375072,
-0.0013080659555271268,
-0.004914149641990662,
0.005825539585202932,
-0.0027405349537730217,
0.006392807234078646,
-0.011353167705237865,
-0.002850433811545372,
-0.005567838437855244,
-0.00443308986723423,
0.00222327234223485,
0.006434580776840448,
-0.0018054468091577291,
0.008477950468659401,
0.00023619586136192083,
-0.007756845559924841,
0.009029948152601719,
-0.007671452593058348,
0.028797442093491554,
0.0020664234180003405,
0.008155766874551773,
0.0006341147236526012,
-0.006337959319353104,
-0.004100722726434469,
0.008681613951921463,
0.00027563743060454726,
0.011203374713659286,
-0.016808344051241875,
0.00012658732885029167,
0.0030779012013226748,
0.018354708328843117,
-0.005020512267947197,
-0.010013382881879807,
-0.0062087299302220345,
-0.003150366712361574,
0.00006303645932348445,
0.00956345722079277,
0.009907796047627926,
-0.0029352554120123386,
0.006186564918607473,
-0.0006426699692383409,
-0.021961525082588196,
0.002548427088186145,
-0.005661360919475555,
-0.005817798897624016,
-0.0011016798671334982,
0.00687932875007391,
0.008227897807955742,
-0.0027670268900692463,
0.0019592836033552885,
-0.000229796496569179,
0.00496415002271533,
-0.00029075847123749554,
0.004639928694814444,
-0.0008261156617663801,
0.004346499685198069,
-0.009772645309567451,
0.005982596427202225,
-0.00793261919170618,
-0.0010085414396598935,
0.0027504859026521444,
-0.0046723936684429646,
0.010577680543065071,
0.0051172771491110325,
-0.0035658145789057016,
-0.002279751468449831,
-0.008331507444381714,
-0.0025201591197401285,
0.0025635194033384323,
0.003654017113149166,
-0.008596476167440414,
0.003946325276046991,
0.0005556829855777323,
0.0027427449822425842,
0.005472747143357992,
-0.011564647778868675,
0.004422074183821678,
0.005648005288094282,
-0.004691037815064192,
0.0021395955700427294,
-0.0031344585586339235,
0.002321748062968254,
0.0042745755054056644,
-0.00540643185377121,
-0.008077811449766159,
0.0035552922636270523,
-0.006093637552112341,
-0.005312421824783087,
0.006102079525589943,
-0.007142612710595131,
-0.007680024951696396,
-0.00341795664280653,
-0.010408296249806881,
0.0016699963016435504
] |
8a5438fd129b5b6996b6b2555c75bb6bb382b7d5 | 5,639 | py | Python | nearpy/examples/example2.py | samyoo78/NearPy | 1b534b864d320d875508e95cd2b76b6d8c07a90b | [
"MIT"
] | 624 | 2015-01-02T21:45:28.000Z | 2022-03-02T11:04:27.000Z | nearpy/examples/example2.py | samyoo78/NearPy | 1b534b864d320d875508e95cd2b76b6d8c07a90b | [
"MIT"
] | 65 | 2015-02-06T09:47:46.000Z | 2021-09-26T01:45:26.000Z | nearpy/examples/example2.py | samyoo78/NearPy | 1b534b864d320d875508e95cd2b76b6d8c07a90b | [
"MIT"
] | 136 | 2015-01-07T04:45:41.000Z | 2021-11-25T17:46:07.000Z | # -*- coding: utf-8 -*-
# Copyright (c) 2013 Ole Krause-Sparmann
# 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 numpy
import scipy
import unittest
import time
from nearpy import Engine
from nearpy.distances import CosineDistance
from nearpy.hashes import RandomBinaryProjections, HashPermutations, HashPermutationMapper
def example2():
# Dimension of feature space
DIM = 100
# Number of data points (dont do too much because of exact search)
POINTS = 20000
##########################################################
print('Performing indexing with HashPermutations...')
t0 = time.time()
# Create permutations meta-hash
permutations = HashPermutations('permut')
# Create binary hash as child hash
rbp_perm = RandomBinaryProjections('rbp_perm', 14)
rbp_conf = {'num_permutation':50,'beam_size':10,'num_neighbour':100}
# Add rbp as child hash of permutations hash
permutations.add_child_hash(rbp_perm, rbp_conf)
# Create engine
engine_perm = Engine(DIM, lshashes=[permutations], distance=CosineDistance())
# First index some random vectors
matrix = numpy.zeros((POINTS,DIM))
for i in range(POINTS):
v = numpy.random.randn(DIM)
matrix[i] = v
engine_perm.store_vector(v)
# Then update permuted index
permutations.build_permuted_index()
t1 = time.time()
print('Indexing took %f seconds' % (t1-t0))
# Get random query vector
query = numpy.random.randn(DIM)
# Do random query on engine 3
print('\nNeighbour distances with HashPermutations:')
print(' -> Candidate count is %d' % engine_perm.candidate_count(query))
results = engine_perm.neighbours(query)
dists = [x[2] for x in results]
print(dists)
# Real neighbours
print('\nReal neighbour distances:')
query = query.reshape((DIM))
dists = CosineDistance().distance(matrix, query)
dists = dists.reshape((-1,))
dists = sorted(dists)
print(dists[:10])
##########################################################
print('\nPerforming indexing with HashPermutationMapper...')
t0 = time.time()
# Create permutations meta-hash
permutations2 = HashPermutationMapper('permut2')
# Create binary hash as child hash
rbp_perm2 = RandomBinaryProjections('rbp_perm2', 14)
# Add rbp as child hash of permutations hash
permutations2.add_child_hash(rbp_perm2)
# Create engine
engine_perm2 = Engine(DIM, lshashes=[permutations2], distance=CosineDistance())
# First index some random vectors
matrix = numpy.zeros((POINTS,DIM))
for i in range(POINTS):
v = numpy.random.randn(DIM)
matrix[i] = v
engine_perm2.store_vector(v)
t1 = time.time()
print('Indexing took %f seconds' % (t1-t0))
# Get random query vector
query = numpy.random.randn(DIM)
# Do random query on engine 4
print('\nNeighbour distances with HashPermutationMapper:')
print(' -> Candidate count is %d' % engine_perm2.candidate_count(query))
results = engine_perm2.neighbours(query)
dists = [x[2] for x in results]
print(dists)
# Real neighbours
print('\nReal neighbour distances:')
query = query.reshape((DIM))
dists = CosineDistance().distance(matrix,query)
dists = dists.reshape((-1,))
dists = sorted(dists)
print(dists[:10])
##########################################################
print('\nPerforming indexing with multiple binary hashes...')
t0 = time.time()
hashes = []
for k in range(20):
hashes.append(RandomBinaryProjections('rbp_%d' % k, 10))
# Create engine
engine_rbps = Engine(DIM, lshashes=hashes, distance=CosineDistance())
# First index some random vectors
matrix = numpy.zeros((POINTS,DIM))
for i in range(POINTS):
v = numpy.random.randn(DIM)
matrix[i] = v
engine_rbps.store_vector(v)
t1 = time.time()
print('Indexing took %f seconds' % (t1-t0))
# Get random query vector
query = numpy.random.randn(DIM)
# Do random query on engine 4
print('\nNeighbour distances with multiple binary hashes:')
print(' -> Candidate count is %d' % engine_rbps.candidate_count(query))
results = engine_rbps.neighbours(query)
dists = [x[2] for x in results]
print(dists)
# Real neighbours
print('\nReal neighbour distances:')
query = query.reshape((DIM))
dists = CosineDistance().distance(matrix,query)
dists = dists.reshape((-1,))
dists = sorted(dists)
print(dists[:10])
##########################################################
| 32.039773 | 90 | 0.662529 | 1 | 2.0691 | [
-0.040002547204494476,
0.026935553178191185,
-0.006685627158731222,
-0.009221378713846207,
0.0014860492665320635,
0.05686836689710617,
0.0007371506653726101,
-0.03519662469625473,
-0.05516264587640762,
0.034237392246723175,
0.013571991585195065,
-0.01179387979209423,
0.04590948671102524,
-0.00012241456715855747,
-0.02063760533928871,
-0.0008588426862843335,
0.17402388155460358,
-0.007267998065799475,
-0.005528351292014122,
-0.000316772551741451,
-0.01389981061220169,
-0.020673731341958046,
-0.007203108165413141,
0.009677899070084095,
0.030917411670088768,
-0.011229646392166615,
0.05032053962349892,
0.03516504168510437,
-0.017613502219319344,
-0.029782436788082123,
-0.008176824077963829,
0.007396065630018711,
0.005073315929621458,
0.01687202788889408,
-0.004011400975286961,
0.027189169079065323,
0.0015924221370369196,
-0.09945521503686905,
0.022924646735191345,
0.014090253040194511,
0.0056158252991735935,
-0.013083509169518948,
0.014923586510121822,
-0.028213627636432648,
0.05309641361236572,
-0.02140517719089985,
-0.029757197946310043,
0.017459966242313385,
-0.040393006056547165,
0.027057187631726265,
-0.0143037810921669,
0.041920267045497894,
-0.021758928894996643,
0.002765282988548279,
-0.018023382872343063,
-0.040052980184555054,
0.006921893917024136,
0.02698344551026821,
-0.033719252794981,
0.009340140968561172,
0.01854316145181656,
0.006017396226525307,
0.0038116599898785353,
-0.01605057530105114,
0.011466766707599163,
-0.0032853931188583374,
-0.0121957091614604,
-0.03312787786126137,
-0.061856482177972794,
-0.06340581178665161,
-0.01461087353527546,
0.007547213230282068,
-0.009251588955521584,
0.03890078142285347,
0.03276509419083595,
-0.003488535061478615,
-0.025951005518436432,
0.010099397972226143,
0.02016124688088894,
-0.014302614144980907,
-0.0029468180146068335,
0.06304317712783813,
-0.007798735052347183,
-0.002764788456261158,
0.0055933259427547455,
-0.045506756752729416,
0.030523164197802544,
-0.07627377659082413,
0.05785531550645828,
0.014941916801035404,
-0.03420494496822357,
0.005689681973308325,
-0.03931915760040283,
0.021987779065966606,
-0.0013394245179370046,
-0.02718743123114109,
0.036558132618665695,
-0.019897138699889183,
0.030291637405753136,
0.0029167707543820143,
-0.007870347239077091,
-0.027716822922229767,
0.05528600886464119,
0.0019608268048614264,
-0.03218179568648338,
0.02375480718910694,
-0.04235859587788582,
-0.01823481358587742,
-0.015955250710248947,
-0.016848526895046234,
0.02540034055709839,
0.008922484703361988,
0.025391917675733566,
-0.023965315893292427,
-0.01234828494489193,
-0.025348950177431107,
0.0024140807799994946,
0.018658941611647606,
0.020516881719231606,
-0.009514100849628448,
-0.013796904124319553,
0.020659416913986206,
-0.028100116178393364,
0.013891205191612244,
-0.014419329352676868,
0.06705748289823532,
-0.014225670136511326,
0.042793817818164825,
0.05624588951468468,
0.006175011862069368,
-0.007528752088546753,
-0.010855566710233688,
-0.027892762795090675,
-0.03551230579614639,
0.0471598356962204,
-0.02110678143799305,
0.0043642399832606316,
-0.0100179985165596,
-0.06617479771375656,
-0.004397709388285875,
-0.008831257931888103,
-0.020997319370508194,
0.01243627816438675,
-0.004340645391494036,
-0.005729608237743378,
-0.0210065096616745,
0.02299596183001995,
0.03572637587785721,
-0.0022216683719307184,
-0.006444021128118038,
0.04567848518490791,
0.0022438864689320326,
0.01254980731755495,
0.01666446030139923,
-0.025525523349642754,
-0.008916506543755531,
0.00024701908114366233,
-0.029550829902291298,
-0.0067742434330284595,
-0.02570650540292263,
-0.04939160868525505,
-0.013094990514218807,
0.031122419983148575,
0.007682659663259983,
-0.0015275900950655341,
0.02295803278684616,
-0.04814793914556503,
0.025522297248244286,
0.0015232078731060028,
0.030309239402413368,
0.01786884106695652,
0.0012563408818095922,
-0.03831592947244644,
0.013674432411789894,
-0.05317626893520355,
0.01489700935781002,
0.00680511211976409,
0.01846558041870594,
0.0037135370075702667,
-0.012318718247115612,
0.04053778201341629,
0.012009243480861187,
0.025631198659539223,
0.01764199137687683,
-0.00809304229915142,
0.02587304823100567,
-0.04862407222390175,
-0.01155255176126957,
0.006369031500071287,
0.024805257096886635,
-0.01260682474821806,
0.013049363158643246,
0.027412882074713707,
-0.020268017426133156,
0.015989765524864197,
0.025801043957471848,
-0.02821972966194153,
0.036627840250730515,
-0.013510765507817268,
-0.0286418367177248,
-0.008971360512077808,
0.013589726760983467,
0.012451263144612312,
-0.003916118294000626,
-0.025733884423971176,
-0.005185144953429699,
-0.6193509101867676,
0.006069422699511051,
0.02578401193022728,
0.01964871771633625,
0.006788263097405434,
0.01747957058250904,
-0.008608425036072731,
-0.010868235491216183,
-0.049220144748687744,
-0.007024415768682957,
0.0006996379233896732,
-0.00856997724622488,
-0.018326768651604652,
-0.016816210001707077,
0.015208883211016655,
-0.03199251368641853,
0.01752804033458233,
-0.013483346439898014,
-0.007560412865132093,
0.006516309920698404,
0.01849367283284664,
-0.05472058430314064,
-0.0319683663547039,
-0.0026690701488405466,
0.027146508917212486,
-0.014597048051655293,
0.00017789062985684723,
0.0018225766252726316,
0.033901479095220566,
-0.035002101212739944,
0.006319199688732624,
0.01424051821231842,
0.05272065848112106,
0.022271055728197098,
0.0005573717062361538,
0.03791934996843338,
0.029529660940170288,
0.0025474163703620434,
0.009412487037479877,
-0.0009216199396178126,
-0.005591565743088722,
-0.004583381116390228,
-0.040675681084394455,
-0.053556524217128754,
-0.018196331337094307,
-0.060408104211091995,
-0.011658321134746075,
-0.012507048435509205,
-0.012243642471730709,
-0.004082016181200743,
-0.02055676281452179,
0.026422282680869102,
0.00209982180967927,
-0.051162514835596085,
-0.04548971354961395,
-0.029675837606191635,
-0.011886644177138805,
-0.0017161043360829353,
0.018488695845007896,
-0.016703659668564796,
0.04143998399376869,
0.04256673902273178,
0.002598872408270836,
0.021539803594350815,
-0.0320889987051487,
-0.006532792001962662,
0.05926010385155678,
-0.07815968990325928,
-0.03187398985028267,
0.03591005131602287,
-0.03843538463115692,
-0.017983637750148773,
-0.0630638375878334,
0.04338300973176956,
-0.005937184207141399,
0.015583605505526066,
-0.025011736899614334,
-0.005637043155729771,
-0.042988646775484085,
-0.005120508372783661,
0.008372839540243149,
-0.04690099507570267,
-0.016720537096261978,
0.02079778164625168,
-0.018295491114258766,
-0.0163415540009737,
-0.009949728846549988,
-0.016497710719704628,
-0.011996439658105373,
0.03871263563632965,
0.029238902032375336,
0.012367840856313705,
-0.00004080633880221285,
0.0018710667500272393,
0.05274662375450134,
0.012344526126980782,
-0.0042817555367946625,
0.056962788105010986,
-0.018535057082772255,
0.03630102798342705,
-0.025830604135990143,
-0.013115458190441132,
-0.01455474179238081,
0.002796318382024765,
-0.026154566556215286,
0.020849784836173058,
-0.04211537539958954,
-0.024342402815818787,
0.06754463911056519,
-0.03354930505156517,
-0.029179001227021217,
0.0008842520765028894,
0.012057720683515072,
-0.04306671395897865,
0.01690024882555008,
0.008647685870528221,
-0.029723718762397766,
-0.025736765936017036,
0.01712164282798767,
0.02234666794538498,
-0.004883570596575737,
0.012867899611592293,
0.008514166809618473,
0.010075620375573635,
0.0010545575059950352,
0.03489125892519951,
0.025343487039208412,
-0.02335602417588234,
0.03015211969614029,
-0.0012824427103623748,
-0.028543833643198013,
-0.026007920503616333,
-0.03462783247232437,
0.012938539497554302,
0.019526667892932892,
0.006846743170171976,
-0.027324043214321136,
-0.025471670553088188,
-0.027129804715514183,
0.01189965009689331,
0.010359307751059532,
-0.06170320510864258,
0.03260126709938049,
-0.055424392223358154,
0.042919524013996124,
0.015200544148683548,
0.018587151542305946,
0.010322821326553822,
0.031525660306215286,
0.0056956554763019085,
-0.01659160479903221,
0.001517586992122233,
0.005771409720182419,
0.004702786449342966,
-0.04482237249612808,
-0.0031805471517145634,
-0.06687761843204498,
0.03837534785270691,
0.05490420386195183,
0.006924304645508528,
-0.03127855062484741,
0.02953646332025528,
-0.011471248231828213,
0.011042158119380474,
-0.006473035551607609,
-0.009830103255808353,
-0.009352872148156166,
-0.01831231638789177,
0.0540744848549366,
0.036852188408374786,
0.012111782096326351,
-0.00042023503920063376,
0.06572580337524414,
0.01573028601706028,
0.002154172398149967,
-0.020335698500275612,
0.015405606478452682,
-0.03685932233929634,
0.006316987331956625,
-0.028277596458792686,
0.04503612220287323,
0.003734040539711714,
0.013230361044406891,
-0.006497582886368036,
0.02216922864317894,
-0.006883502006530762,
0.014395046979188919,
0.01430387981235981,
-0.01620829850435257,
-0.016686448827385902,
-0.008298203349113464,
0.0017062764381989837,
-0.022647440433502197,
0.007264553103595972,
-0.016820482909679413,
-0.022517699748277664,
-0.022429481148719788,
0.0006161985802464187,
0.011414393782615662,
-0.05495350435376167,
-0.007861515507102013,
-0.019644616171717644,
0.02327221818268299,
-0.04038853570818901,
-0.001491436385549605,
0.027619220316410065,
0.018432656303048134,
0.0032817292958498,
0.006162120960652828,
-0.007025579456239939,
0.027366122230887413,
-0.006728461477905512,
-0.005750556476414204,
0.01573415845632553,
-0.025593576952815056,
0.03719261288642883,
-0.04635215923190117,
-0.01786048896610737,
0.04133186116814613,
-0.00964466854929924,
-0.03374083712697029,
-0.035259123891592026,
0.024581409990787506,
0.03356262296438217,
0.003332190914079547,
-0.038901153951883316,
-0.03557785227894783,
-0.009624050930142403,
0.014069861732423306,
-0.009648888371884823,
0.035705529153347015,
-0.0008113225921988487,
-0.012288609519600868,
-0.03457077220082283,
0.017352547496557236,
0.02629869244992733,
0.010037796571850777,
0.014033538289368153,
0.059630975127220154,
-0.02284560166299343,
0.03360399603843689,
-0.02999068796634674,
0.007033083587884903,
0.017246074974536896,
-0.02933303266763687,
0.01158186700195074,
0.007794629316776991,
-0.015934115275740623,
-0.017142055556178093,
-0.02052466943860054,
-0.016880717128515244,
0.06801548600196838,
0.036570653319358826,
-0.03336186707019806,
-0.01580100879073143,
0.053424715995788574,
0.0062807342037558556,
0.002662715967744589,
0.01295337826013565,
0.024472519755363464,
-0.023870963603258133,
-0.03996775671839714,
0.004745211452245712,
0.012976312078535557,
-0.040809743106365204,
0.013785655610263348,
-0.012786433100700378,
-0.002223498886451125,
-0.01161680556833744,
0.0756930410861969,
0.012189505621790886,
0.0030611564870923758,
-0.054796963930130005,
-0.01446102000772953,
-0.006192094646394253,
-0.012613103725016117,
-0.04800266772508621,
-0.007473500911146402,
-0.0018129252130165696,
0.010917103849351406,
-0.002436363836750388,
0.006424004212021828,
-0.013223506510257721,
0.013162698596715927,
-0.0070861633867025375,
0.028775641694664955,
0.045822665095329285,
0.006857779808342457,
-0.005359973292797804,
-0.007251645438373089,
-0.024769240990281105,
-0.05469948425889015,
0.05681859701871872,
0.05314450338482857,
-0.007211355958133936,
-0.009923413395881653,
0.0037288374733179808,
-0.01753254607319832,
0.014707704074680805,
0.025510869920253754,
0.036009397357702255,
0.006272673606872559,
-0.016667084768414497,
-0.024525584653019905,
0.006864229682832956,
-0.004765973426401615,
0.009509514085948467,
0.020725812762975693,
0.008816080167889595,
0.003604571335017681,
0.0013083950616419315,
0.023896843194961548,
0.0014115190133452415,
0.03170173242688179,
-0.020321741700172424,
-0.017175205051898956,
-0.003161510918289423,
0.01988702453672886,
0.015478899702429771,
0.014534976333379745,
-0.0140251899138093,
0.05607498809695244,
-0.006694826763123274,
-0.027919232845306396,
-0.012884306721389294,
-0.031574223190546036,
-0.004380935803055763,
0.02107609063386917,
-0.020028667524456978,
-0.03972687944769859,
-0.010097081772983074,
0.022559795528650284,
0.0354340486228466,
0.028011145070195198,
-0.007470510434359312,
-0.0003661320952232927,
0.02606046572327614,
0.030787743628025055,
-0.03671815246343613,
0.0298797395080328,
0.017189396545290947,
-0.03344593942165375,
-0.0414823442697525,
0.011943073011934757,
-0.014218905009329319,
0.03066328540444374,
0.009907997213304043,
-0.012530859559774399,
0.027359848842024803,
0.020157217979431152,
-0.019655849784612656,
0.0036775777116417885,
0.002467966405674815,
-0.0464213602244854,
-0.021029023453593254,
0.004199170973151922,
0.028733067214488983,
0.009957471862435341,
-0.012455442920327187,
-0.003429829142987728,
-0.010550876148045063,
0.003227817825973034,
-0.028585974127054214,
-0.013691093772649765,
-0.03748543560504913,
-0.007777075283229351,
0.027283353731036186,
0.005656406749039888,
0.03005230613052845,
0.01374585647135973,
0.006400005891919136,
-0.003162665758281946,
-0.009570680558681488,
0.04392082244157791,
0.0110166622325778,
0.035692259669303894,
0.03828296810388565,
0.0231469739228487,
-0.0027945986948907375,
-0.02155482955276966,
0.01340031623840332,
-0.09530855715274811,
0.026512691751122475,
-0.015384932048618793,
0.04515710473060608,
-0.06858036667108536,
-0.014631425961852074,
0.037866707891225815,
-0.03430338203907013,
-0.06228484958410263,
-0.007353713735938072,
-0.010247232392430305,
0.07132337242364883,
0.03581733629107475,
-0.008031453005969524,
-0.021506106480956078,
-0.03022092580795288,
-0.03226318582892418,
0.03371492400765419,
-0.004800720605999231,
0.038369208574295044,
0.006457513198256493,
0.003680011723190546,
-0.02251611091196537,
0.01437080092728138,
0.01011731754988432,
0.03268040344119072,
0.03967826068401337,
-0.02869039587676525,
0.006071730982512236,
-0.03857849910855293,
-0.02642637863755226,
0.019247636198997498,
-0.009522018022835255,
0.019447719678282738,
0.020191526040434837,
-0.007684025913476944,
-0.033646732568740845,
-0.025223419070243835,
0.022990016266703606,
-0.027621295303106308,
0.0012797496747225523,
-0.009033897891640663,
0.01628691516816616,
-0.04054700955748558,
0.0024392399936914444,
0.019147314131259918,
0.015722347423434258,
-0.030293043702840805,
0.03184974938631058,
-0.007141414098441601,
0.050789974629879,
-0.03694310411810875,
-0.005542199593037367,
0.013541718944907188,
-0.01335512101650238,
-0.023381588980555534,
-0.01778201386332512,
-0.00010344151087338105,
-0.005811207462102175,
-0.0005533882649615407,
0.0025219013914465904,
0.03439424932003021,
0.029245121404528618,
0.037111904472112656,
0.0021747671999037266,
0.04092559218406677,
-0.0202025156468153,
-0.052329327911138535,
-0.027358705177903175,
-0.08446992933750153,
0.015197137370705605,
-0.014018143527209759,
-0.007547589484602213,
-0.016355223953723907,
-0.005185919348150492,
-0.002037725644186139,
0.03922353312373161,
0.010783543810248375,
0.01877124421298504,
0.044544070959091187,
0.044637806713581085,
0.027695031836628914,
0.002071003895252943,
-0.006172643043100834,
0.03526594862341881,
0.026335539296269417,
-0.04016046226024628,
0.01580028608441353,
-0.009615104645490646,
0.01548152044415474,
0.009014553390443325,
-0.033654291182756424,
0.020225387066602707,
-0.02264603227376938,
-0.04565635323524475,
-0.014060866087675095,
0.005381397437304258,
-0.005230488255620003,
0.006377512589097023,
-0.054884154349565506,
0.030814148485660553,
0.0066338651813566685,
0.01331742387264967,
0.02114889957010746,
0.02032916620373726,
-0.003758466336876154,
-0.025972791016101837,
-0.009363062679767609,
0.013593349605798721,
-0.026145167648792267,
-0.025155266746878624,
-0.024751340970396996,
0.022223148494958878,
0.033602602779865265,
-0.013805508613586426,
0.02634405344724655,
0.04594608023762703,
0.055093586444854736,
0.013932950794696808,
-0.049816325306892395,
-0.018515711650252342,
0.02065713331103325,
-0.013639179058372974,
0.0634768009185791,
0.003000917611643672,
0.06430547684431076,
0.038499392569065094,
0.002729819854721427,
0.00018831947818398476,
-0.002213875064626336,
-0.012767613865435123,
0.02540135756134987,
-0.009672777727246284,
0.03163909167051315,
-0.009267466142773628,
0.026707375422120094,
-0.08147899806499481,
-0.023037521168589592,
-0.030798358842730522,
0.02379631996154785,
0.03181600943207741,
0.005514949094504118,
-0.0036506354808807373,
0.0032833402510732412,
-0.021843641996383667,
-0.07459041476249695,
0.005659020505845547,
0.031117841601371765,
0.00781711470335722,
-0.001967081567272544,
-0.0022577091585844755,
-0.0066507658921182156,
0.01962457224726677,
-0.007366994395852089,
-0.04125732555985451,
0.011365583166480064,
0.05249412730336189,
-0.03907468542456627,
-0.01596786454319954,
0.04648825526237488,
0.03428785502910614,
-0.005429171025753021,
-0.0032571195624768734,
-0.07339919358491898,
-0.03043084591627121,
-0.008163787424564362,
-0.0342211090028286,
0.032281361520290375,
0.034863997250795364,
-0.004257235676050186,
-0.01455172710120678,
-0.0042400360107421875,
-0.023568911477923393,
-0.012325754389166832,
-0.07537984848022461,
-0.006071505602449179,
0.02732527069747448,
-0.002886698115617037,
-0.0702708438038826,
-0.0028849223162978888,
0.03450237214565277
] |
8a54995b61e4b0596e764748ce12766155458309 | 2,551 | py | Python | discordbot.py | 8ka1alu/heroku-global-py | 7968ff6c215d6d86149221c246b4aaa5cd04df59 | [
"MIT"
] | null | null | null | discordbot.py | 8ka1alu/heroku-global-py | 7968ff6c215d6d86149221c246b4aaa5cd04df59 | [
"MIT"
] | null | null | null | discordbot.py | 8ka1alu/heroku-global-py | 7968ff6c215d6d86149221c246b4aaa5cd04df59 | [
"MIT"
] | null | null | null | from discord.ext import commands, tasks # Bot Commands Frameworkをインポート
import traceback # エラー表示のためにインポート
import os
import discord
import r
TOKEN = os.environ['DISCORD_BOT_TOKEN']
prefix = os.environ['DISCORD_BOT_PREFIX'] #プレフィックス
# 読み込むコグの名前を格納しておく。
INITIAL_EXTENSIONS = [
'cogs.eval',
'cogs.glchat',
'cogs.gladd',
'cogs.gldel'
]
# クラスの定義。ClientのサブクラスであるBotクラスを継承。
class MyBot(commands.Bot):
# MyBotのコンストラクタ。
def __init__(self, command_prefix, help_command):
# スーパークラスのコンストラクタに値を渡して実行。
super().__init__(command_prefix,help_command)
# INITIAL_COGSに格納されている名前から、コグを読み込む。
# エラーが発生した場合は、エラー内容を表示。
for cog in INITIAL_EXTENSIONS:
try:
self.load_extension(cog)
except Exception:
traceback.print_exc()
# Botの準備完了時に呼び出されるイベント
async def on_ready(self):
print(self.user.name) # ボットの名前
print(self.user.id) # ボットのID
print(discord.__version__) # discord.pyのバージョン
print('----------------')
print('Hello World !!')
await self.change_presence(status=discord.Status.idle,activity=discord.Game(name=f'Ping:{self.ws.latency * 1000:.0f}ms'))
conn=r.connect()
ky=conn.keys()
global_ch="gloch"
count=0
for i in ky:
i=str(i)
if i == global_ch:
count+=1
if count>0:
smsd=conn.smembers(global_ch)
count=0
for q in smsd:
q=str(q)
if q=="0":
count+=1
if count>0:
p=conn.srem(global_ch,"0")
if p==True:
print("正常起動")
else:
print("異常発生")
else:
print(ky)
else:
p=conn.sadd(global_ch,"0")
if p==True:
print("正常起動")
else:
print("異常発生")
class JapaneseHelpCommand(commands.DefaultHelpCommand):
def __init__(self):
super().__init__()
self.commands_heading = "コマンド:"
self.no_category = "その他"
self.command_attrs["help"] = "コマンド一覧と簡単な説明を表示"
def get_ending_note(self):
return (f"各コマンドの説明: {prefix}help <コマンド名>\n"
f"各カテゴリの説明: {prefix}help <カテゴリ名>\n")
#MyBotのインスタンス化及び起動処理。
if __name__ == '__main__':
bot = MyBot(command_prefix=prefix,help_command=JapaneseHelpCommand()) # command_prefixはコマンドの最初の文字として使うもの。 e.g. !ping
bot.run(TOKEN) # Botのトークン
| 29.321839 | 130 | 0.563701 | 1 | 1.8741 | [
0.0016865944489836693,
0.026595445349812508,
0.007640566676855087,
-0.002702359575778246,
0.0015238403575494885,
-0.0017903621774166822,
-0.00914925616234541,
0.004103219602257013,
-0.0077839139848947525,
0.00380698568187654,
0.0010698084952309728,
0.006760309915989637,
0.00634510675445199,
-0.01874176226556301,
0.0005806049448437989,
0.014803347177803516,
-0.0510181300342083,
-0.00031375905382446945,
-0.0032893416937440634,
0.0006593873258680105,
-0.009347259066998959,
0.009320957586169243,
0.007542588748037815,
0.005036937538534403,
0.00673990324139595,
0.002935414668172598,
0.011096222326159477,
0.0011129702907055616,
-0.009135954082012177,
-0.007461085449904203,
0.0005394991603679955,
-0.0005907013546675444,
-0.006890569813549519,
-0.006731887347996235,
0.004346182569861412,
-0.0036253947764635086,
-0.0023367826361209154,
-0.01932903565466404,
0.01439655665308237,
-0.005561001133173704,
-0.006370668765157461,
-0.015168181620538235,
-0.0013103359378874302,
0.006970937829464674,
-0.007319416850805283,
0.00027235003653913736,
-0.005122750997543335,
0.0008021201938390732,
-0.01110944151878357,
0.005607091821730137,
-0.0069785634987056255,
0.00708784069865942,
0.012489493004977703,
0.0037937487941235304,
-0.004799059126526117,
-0.007013707421720028,
0.014618261717259884,
0.0015204274095594883,
-0.011279494501650333,
-0.004290522076189518,
-0.004630570765584707,
-0.00092483771732077,
0.006818715482950211,
0.003224399173632264,
-0.01824217475950718,
-0.008594761602580547,
-0.00690460717305541,
0.0031068017706274986,
-0.00015844966401346028,
0.004719169344753027,
0.001453056582249701,
0.0012126942165195942,
0.007738868240267038,
0.0038596377708017826,
0.004333776421844959,
-0.006498470902442932,
-0.002076906617730856,
0.0008749609114602208,
0.006328535731881857,
0.004418669734150171,
0.002846808871254325,
-0.008056564256548882,
0.006312807556241751,
0.009164909832179546,
0.012571354396641254,
0.00899312924593687,
0.019185815006494522,
-0.01051612850278616,
0.04760284721851349,
0.00906947162002325,
-0.008355419151484966,
0.0005041937110945582,
-0.009455084800720215,
-0.0020635847467929125,
-0.006131244357675314,
-0.027195775881409645,
0.0006544984062202275,
-0.00381773361004889,
-0.0023948887828737497,
0.0026657450944185257,
0.0011768901022151113,
0.008608152158558369,
0.0001505090476712212,
-0.0025439984165132046,
-0.00714877899736166,
0.013619324192404747,
-0.008718308992683887,
-0.004861579276621342,
0.007408808916807175,
0.0020338736940175295,
-0.010747327469289303,
-0.000950500019825995,
0.002683931030333042,
-0.012414844706654549,
0.0035761541221290827,
0.0016737387049943209,
-0.0034381751902401447,
0.05516945570707321,
-0.001928591402247548,
0.004758807364851236,
-0.004572658333927393,
0.002238145563751459,
-0.0011422419920563698,
0.0037090396508574486,
0.009588674642145634,
-0.001486890367232263,
0.009841701947152615,
0.009880000725388527,
0.005762497894465923,
0.008173083886504173,
-0.0026042982935905457,
0.005457703955471516,
-0.0015333493938669562,
-0.0010884740622714162,
0.0023442197125405073,
-0.008350122720003128,
0.007032935973256826,
-0.0006448429776355624,
-0.008632561191916466,
0.00300160376355052,
0.002663024002686143,
-0.010512836277484894,
0.003555729053914547,
-0.004108985885977745,
0.0027345684356987476,
-0.01049965713173151,
-0.004036888014525175,
-0.004128354601562023,
-0.005449534393846989,
0.0006919491570442915,
0.011377516202628613,
0.0029902795795351267,
0.004377237055450678,
-0.0030978608410805464,
-0.008175858296453953,
-0.0004152490582782775,
-0.0018196430755779147,
0.000693596841301769,
0.006805987562984228,
0.003988902550190687,
-0.011214287020266056,
-0.0038705444894731045,
0.00363375386223197,
0.0024999703746289015,
-0.0012504251208156347,
0.002531993668526411,
-0.0067860158160328865,
0.0056025064550340176,
-0.0029246013145893812,
0.005891083274036646,
0.011157797649502754,
-0.00429962296038866,
-0.0016817622818052769,
-0.0007081372896209359,
0.000029968054150231183,
-0.0007833375711925328,
0.007185968104749918,
0.01099688932299614,
-0.004000485874712467,
-0.0021694281604140997,
0.0033824979327619076,
0.005535174626857042,
0.00572474580258131,
0.003984465729445219,
-0.0037663327530026436,
0.003066674340516329,
-0.005640740040689707,
-0.003580983728170395,
0.0063972994685173035,
-0.0013485033996403217,
0.003795246360823512,
0.005386289209127426,
-0.012671838514506817,
-0.01046251691877842,
0.00022397079737856984,
-0.005476199556142092,
0.0016055715968832374,
0.01256606075912714,
0.011550966650247574,
-0.004998643416911364,
0.001036304049193859,
-0.007867702282965183,
0.001305104000493884,
0.009133663959801197,
0.0009732507169246674,
-0.010151646099984646,
-0.9597870707511902,
0.006732969079166651,
0.0033466508612036705,
-0.0031855946872383356,
0.006971062161028385,
-0.0005693712155334651,
0.006104293279349804,
0.0016153730684891343,
0.01437446940690279,
-0.009969598613679409,
-0.006201048847287893,
-0.009083966724574566,
-0.011292711831629276,
-0.0024649137631058693,
-0.010477233678102493,
-0.001599555485881865,
-0.007689927238970995,
-0.008727842010557652,
-0.0018419590778648853,
0.0000591725402045995,
-0.002622701460495591,
0.011494672857224941,
-0.0015754394698888063,
0.005204595159739256,
0.0057004583068192005,
0.0022786834742873907,
-0.006049034651368856,
-0.0032383513171225786,
-0.0013146511046215892,
-0.0017466569552198052,
-0.0033494632225483656,
-0.013994132168591022,
-0.005895633716136217,
-0.001111142337322235,
0.011020847596228123,
0.00210892828181386,
0.007112478371709585,
-0.004680541809648275,
0.0024354110937565565,
-0.008565394207835197,
0.006923720706254244,
0.000516208412591368,
0.0007842265185900033,
-0.02982153929769993,
0.0015753644984215498,
-0.00013971800217404962,
-0.008171077817678452,
0.008413989096879959,
0.0001990830060094595,
-0.0017142677679657936,
-0.004390358459204435,
-0.006300009321421385,
0.007482411805540323,
-0.006936606019735336,
0.004174757283180952,
-0.005141949746757746,
-0.00959840975701809,
-0.0024403922725468874,
-0.010320119559764862,
0.0013340371660888195,
0.004056579899042845,
-0.004011136945337057,
-0.004215308930724859,
-0.006706396583467722,
0.0037910586688667536,
0.004053397104144096,
0.002589971525594592,
-0.018016144633293152,
-0.008168691769242287,
0.0019735286477953196,
-0.0005555434036068618,
-0.0070569789968431,
-0.0034849243238568306,
0.004865394439548254,
-0.008820264600217342,
0.006635468453168869,
0.001104474882595241,
0.00040296243969351053,
-0.013889182358980179,
-0.0016866738442331553,
-0.008954223245382309,
-0.007888233289122581,
0.0025677932426333427,
-0.003496190533041954,
-0.004484040196985006,
0.00017764198128134012,
-0.002114357426762581,
0.004711479879915714,
-0.003633965738117695,
0.0026356480084359646,
0.009261975064873695,
-0.0031186274718493223,
-0.008061687462031841,
0.006184481084346771,
0.006816380191594362,
0.0007606598665006459,
-0.0012922697933390737,
0.005289962515234947,
0.008199544623494148,
0.008976868353784084,
0.0026516560465097427,
0.005187841597944498,
0.001980361994355917,
0.010817775502800941,
-0.004921876825392246,
0.000041378454625373706,
-0.0022071837447583675,
0.000014588830708817113,
-0.0044138492085039616,
0.0019332924857735634,
-0.0035995529033243656,
-0.003775228513404727,
-0.01231462974101305,
-0.009317222982645035,
-0.0023832577280700207,
-0.001215841737575829,
0.003321495372802019,
-0.003996364306658506,
0.00067457853583619,
0.004406320862472057,
0.005207636393606663,
0.0009537321166135371,
-0.004938922356814146,
-0.0021143713966012,
0.0011040391400456429,
-0.004854368511587381,
0.014216244220733643,
-0.011473610065877438,
0.0068429880775511265,
-0.004804412834346294,
-0.01673453487455845,
0.004618122708052397,
0.008158732205629349,
-0.01050532702356577,
0.0019261999987065792,
0.004176545888185501,
0.004088420886546373,
-0.0006688579451292753,
-0.002022126456722617,
-0.0047147441655397415,
-0.01670585200190544,
-0.0007321339217014611,
0.01854422315955162,
0.0017806875985115767,
0.008759516291320324,
0.011769707314670086,
-0.003194862976670265,
0.0048212106339633465,
0.003836456686258316,
0.002714657224714756,
0.011983797885477543,
-0.007675729226320982,
-0.0013125173281878233,
0.002679660217836499,
-0.005760728847235441,
0.0003571006818674505,
0.005054221488535404,
0.005394825246185064,
-0.003680249210447073,
0.0011214386904612184,
-0.008222660981118679,
-0.004127322230488062,
-0.015310681425035,
-0.004276722203940153,
0.005476774647831917,
-0.006833277642726898,
0.004231521859765053,
-0.016073936596512794,
0.005111422389745712,
0.00669737346470356,
0.005248177330940962,
-0.0011407516431063414,
0.0011149130295962095,
0.006269782781600952,
0.013509965501725674,
-0.0036061485297977924,
0.001289551379159093,
0.001973476493731141,
0.00015973058179952204,
-0.0020044248085469007,
0.009780938737094402,
-0.007387630641460419,
-0.007053276989609003,
0.0026540569961071014,
0.006420844700187445,
0.0017801811918616295,
-0.004168934654444456,
-0.008156415075063705,
-0.0031568678095936775,
0.0027391703333705664,
-0.007163394242525101,
0.004106492269784212,
-0.004822991788387299,
0.0030494569800794125,
-0.006460876669734716,
-0.0015028563793748617,
0.0006438119453378022,
-0.013291374780237675,
0.007452270481735468,
-0.0012112254044041038,
0.003870500484481454,
0.014745754189789295,
0.003715320723131299,
-0.014165138825774193,
0.004225509706884623,
0.009467530995607376,
-0.00443846732378006,
0.004618578124791384,
0.0027109929360449314,
-0.006291059777140617,
-0.01806238293647766,
-0.003050501924008131,
-0.01282831933349371,
0.007004446815699339,
0.0005399202345870435,
0.0033835354261100292,
-0.007448561489582062,
0.007163287606090307,
0.007563304156064987,
-0.013541764579713345,
-0.00785776786506176,
-0.008362481370568275,
0.009774052537977695,
0.0020957374945282936,
0.00038606880116276443,
-0.003938851412385702,
-0.0015691714361310005,
-0.0020330811385065317,
-0.00482604606077075,
-0.0034309285692870617,
0.0056473128497600555,
0.0018203174695372581,
-0.0009178547188639641,
0.002976146759465337,
-0.0028907491359859705,
-0.00017251855751965195,
0.0013126841513440013,
-0.009384478442370892,
0.0017575051169842482,
0.005864378064870834,
-0.0009789984906092286,
-0.0055162967182695866,
0.004018639679998159,
0.0005275599542073905,
-0.008118689991533756,
-0.012291163206100464,
-0.0027870668563991785,
-0.0032169686164706945,
-0.0015435860259458423,
-0.012149922549724579,
-0.0033791558817029,
-0.012353554368019104,
0.0048342482186853886,
-0.005991085432469845,
0.010258357040584087,
0.006405833642929792,
-0.00551008153706789,
0.004827621392905712,
-0.0012159486068412662,
0.004978029057383537,
0.0027275877073407173,
0.0032667124178260565,
0.000586167792789638,
-0.004443701822310686,
-0.009466533549129963,
0.012608666904270649,
-0.009111681021749973,
0.0027362918481230736,
0.010283718816936016,
0.005065185949206352,
0.007489820476621389,
-0.0012791240587830544,
0.0016400673193857074,
0.00015331889153458178,
0.007644701283425093,
-0.013108063489198685,
0.004426263738423586,
-0.0052917953580617905,
0.0034747058525681496,
0.004924609325826168,
-0.003601134056225419,
0.002146785845980048,
0.008454687893390656,
0.000891073199454695,
-0.007016057148575783,
-0.0022002621553838253,
0.0014607987832278013,
0.005617243237793446,
-0.011058413423597813,
0.002078356919810176,
-0.0032653273083269596,
-0.004230847582221031,
-0.00408830214291811,
-0.004416510462760925,
-0.0008687856607139111,
0.005567357875406742,
-0.0014417205238714814,
0.0053161135874688625,
0.00020048697479069233,
-0.005096540320664644,
0.015007350593805313,
-0.004950457252562046,
-0.006257076747715473,
0.0019300419371575117,
0.0001251109642907977,
-0.002653577132150531,
-0.005859550554305315,
-0.0008278806344605982,
0.0030427940655499697,
0.007023402955383062,
-0.004672766663134098,
-0.004701471887528896,
0.000847367278765887,
0.002027596114203334,
-0.010212205350399017,
0.0012467432534322143,
0.011480633169412613,
-0.005984694696962833,
0.007292740046977997,
0.00018121233733836561,
-0.005098349880427122,
-0.013632461428642273,
0.051490943878889084,
-0.001079934649169445,
0.004632080905139446,
0.005320723634213209,
-0.007632740307599306,
0.0020705724600702524,
-0.0014997824328020215,
0.009021767415106297,
-0.005938091780990362,
-0.007114292122423649,
0.005230661481618881,
-0.0007935010944493115,
0.005693336017429829,
0.0022818793077021837,
-0.0005977478576824069,
0.015873663127422333,
-0.004206039477139711,
-0.01683260314166546,
-0.017757175490260124,
0.009178734384477139,
-0.004094568081200123,
-0.007236127275973558,
0.00834169052541256,
-0.0028851465322077274,
-0.0043597291223704815,
0.0021684912499040365,
0.00550640095025301,
0.0006899932632222772,
-0.00048239910393022,
-0.002309252507984638,
-0.0013039103941991925,
-0.001262818230316043,
0.0027441242709755898,
0.0038611183408647776,
0.01113833300769329,
-0.003856802126392722,
0.003919254522770643,
-0.0012152018025517464,
-0.003240738296881318,
-0.0021553465630859137,
0.0033318717032670975,
0.0059076957404613495,
-0.0011346522951498628,
0.00036174224806018174,
0.005877133924514055,
0.006330050993710756,
0.0031912983395159245,
0.008789285086095333,
-0.0026057211216539145,
-0.0059468853287398815,
0.00899475160986185,
0.007148851174861193,
0.0011546489549800754,
0.008569085039198399,
-0.001469152863137424,
0.007379184477031231,
0.001519973506219685,
-0.006714154034852982,
-0.016396204009652138,
-0.00042671989649534225,
0.006659581791609526,
0.00925549864768982,
-0.0026042209938168526,
0.0011473301565274596,
-0.0035820782650262117,
-0.00022668999736197293,
-0.008739643730223179,
-0.010694585740566254,
-0.0026509277522563934,
0.003809104673564434,
0.005445873364806175,
0.07111027836799622,
-0.006046677473932505,
0.00019710787455551326,
-0.007911276072263718,
-0.0017528246389701962,
-0.0017302201595157385,
-0.00022536830510944128,
-0.000893188058398664,
-0.003349538194015622,
0.0007677735993638635,
0.004757508169859648,
-0.007129319943487644,
-0.01187218725681305,
-0.0006290129967965186,
0.0018954563420265913,
-0.004647286608815193,
0.0019398564472794533,
0.007580725476145744,
-0.010304847732186317,
0.0010304473107680678,
-0.012224196456372738,
-0.00020911035244353116,
-0.0033970833756029606,
-0.011431516148149967,
-0.0039062274154275656,
-0.0029665264301002026,
0.007280511781573296,
0.006750392261892557,
0.005872389301657677,
-0.002555876038968563,
0.004200727678835392,
-0.0035904115065932274,
0.00008405204425798729,
-0.004599288105964661,
0.00005980374771752395,
-0.004692003596574068,
0.006031338591128588,
0.002603815635666251,
-0.012541132979094982,
-0.007264809682965279,
0.000593945209402591,
-0.0009242933592759073,
-0.007316928822547197,
0.002331741852685809,
0.0006166890962049365,
0.004361373372375965,
-0.0034786078613251448,
0.00006963509076740593,
-0.007937063463032246,
0.0019725188612937927,
-0.013824322260916233,
0.005529623944312334,
-0.16537871956825256,
0.009783684276044369,
0.003815440693870187,
-0.005649283993989229,
-0.0010276921093463898,
-0.012845752760767937,
-0.005035753827542067,
0.004104056861251593,
0.010928712785243988,
0.003982355818152428,
0.001159969950094819,
0.0005247229128144681,
0.005753376055508852,
0.002519237343221903,
-0.0005704130744561553,
-0.0051736729219555855,
0.0012594768777489662,
-0.002508302917703986,
0.0009681989904493093,
0.0036597936414182186,
0.00252474844455719,
0.009927636943757534,
-0.0009585085208527744,
0.0006285886047407985,
-0.0010210761101916432,
-0.005526445340365171,
0.00455858651548624,
-0.0019624808337539434,
0.0066323112696409225,
-0.012792091816663742,
-0.0038252901285886765,
-0.0023332631681114435,
-0.0030828421004116535,
0.0018050981452688575,
0.006822511553764343,
0.0004017555620521307,
0.008501667529344559,
0.0018056750996038318,
-0.005732723977416754,
0.008283653296530247,
-0.0075794304721057415,
0.028452476486563683,
0.003937775734812021,
0.00752369174733758,
0.0021796373184770346,
-0.008943775668740273,
-0.004393485374748707,
0.008507689461112022,
0.003181736683472991,
0.013334492221474648,
-0.012844018638134003,
0.00026842072838917375,
0.003339627990499139,
0.018760353326797485,
-0.0026211459189653397,
-0.009787489660084248,
-0.006577040068805218,
-0.0029218203853815794,
-0.00020588091865647584,
0.007243481930345297,
0.01057855598628521,
-0.003385838121175766,
0.007330926135182381,
-0.004583974834531546,
-0.021490085870027542,
0.005074062384665012,
-0.005279814824461937,
-0.0026956789661198854,
0.0030827720183879137,
0.007187059614807367,
0.011115657165646553,
-0.00023096721270121634,
0.006680456921458244,
0.002439291449263692,
0.004424588289111853,
0.0003046825877390802,
0.005709970369935036,
-0.0016990525182336569,
0.005021517165005207,
-0.008366909809410572,
0.007558462209999561,
-0.007315339520573616,
-0.0014191094087436795,
0.003452001139521599,
-0.0059281098656356335,
0.010666071437299252,
0.004298102576285601,
-0.004629926756024361,
-0.0012766075087711215,
-0.011766484007239342,
-0.0006111135589890182,
0.0025503274518996477,
0.0017886764835566282,
-0.010639810934662819,
0.005796782672405243,
0.0008538846159353852,
0.0038560261018574238,
0.007629806641489267,
-0.010575701482594013,
0.005026071798056364,
0.0035340427421033382,
-0.004977019969373941,
0.0008859694935381413,
-0.0037481565959751606,
0.005560319870710373,
0.004556527826935053,
-0.007443834561854601,
-0.004467045422643423,
0.0006754999631084502,
-0.008748829364776611,
-0.0021110400557518005,
0.0077845435589551926,
-0.011160289868712425,
-0.007586960215121508,
-0.003216508775949478,
-0.012142155319452286,
-0.002855585888028145
] |
8a54b71c70f57dfff2df2e65acf1f13a323c5a9e | 9,468 | py | Python | examples/plot_spectral_unmixing.py | ealopez/pycroscopy | 9f7c0543b67eaa0668296295fc5f492360c130a0 | [
"MIT"
] | null | null | null | examples/plot_spectral_unmixing.py | ealopez/pycroscopy | 9f7c0543b67eaa0668296295fc5f492360c130a0 | [
"MIT"
] | null | null | null | examples/plot_spectral_unmixing.py | ealopez/pycroscopy | 9f7c0543b67eaa0668296295fc5f492360c130a0 | [
"MIT"
] | null | null | null | """
=================================================================
Spectral Unmixing
=================================================================
Suhas Somnath, Rama K. Vasudevan, Stephen Jesse
* Institute for Functional Imaging of Materials
* Center for Nanophase Materials Sciences
Oak Ridge National Laboratory, Oak Ridge TN 37831, USA
In this notebook we load some spectral data, and perform basic data analysis, including:
========================================================================================
* KMeans Clustering
* Non-negative Matrix Factorization
* Principal Component Analysis
Software Prerequisites:
=======================
* Standard distribution of **Anaconda** (includes numpy, scipy, matplotlib and sci-kit learn)
* **pycroscopy** : Though pycroscopy is mainly used here for plotting purposes only, it's true capabilities
are realized through the ability to seamlessly perform these analyses on any imaging dataset (regardless
of origin, size, complexity) and storing the results back into the same dataset among other things
"""
# Import packages
# Ensure that this code works on both python 2 and python 3
from __future__ import division, print_function, absolute_import, unicode_literals
# basic numeric computation:
import numpy as np
# The package used for creating and manipulating HDF5 files:
import h5py
# Plotting and visualization:
import matplotlib.pyplot as plt
# for downloading files:
import wget
import os
# multivariate analysis:
from sklearn.cluster import KMeans
from sklearn.decomposition import NMF
import subprocess
import sys
def install(package):
subprocess.call([sys.executable, "-m", "pip", "install", package])
# Package for downloading online files:
# finally import pycroscopy:
try:
import pycroscopy as px
except ImportError:
print('pycroscopy not found. Will install with pip.')
import pip
install('pycroscopy')
import pycroscopy as px
from pycroscopy.viz import cluster_utils
#####################################################################################
# The Data
# ========
#
# In this example, we will work on a **Band Excitation Piezoresponse Force Microscopy (BE-PFM)** imaging dataset
# acquired from advanced atomic force microscopes. In this dataset, a spectra was collected for each position in a two
# dimensional grid of spatial locations. Thus, this is a three dimensional dataset that has been flattened to a two
# dimensional matrix in accordance with the pycroscopy data format.
#
# Fortunately, all statistical analysis, machine learning, spectral unmixing algorithms, etc. only accept data that is
# formatted in the same manner of [position x spectra] in a two dimensional matrix.
#
# We will be using an data file available on our GitHub project page by default. You are encouraged
# to download this document as a Jupyter Notebook (button at the bottom of the page) and use your own data instead.
# When using your own data, you can skip this cell and provide the path to your data using the variable - data_file_path
data_file_path = 'temp_um.h5'
# download the data file from Github:
url = 'https://raw.githubusercontent.com/pycroscopy/pycroscopy/master/data/BELine_0004.h5'
data_file_path = wget.download(url, data_file_path, bar=None)
h5_file = h5py.File(data_file_path, mode='r+')
print('Contents of data file:')
print('----------------------')
px.hdf_utils.print_tree(h5_file)
print('----------------------')
h5_meas_grp = h5_file['Measurement_000']
# Extracting some basic parameters:
num_rows = px.hdf_utils.get_attr(h5_meas_grp, 'grid_num_rows')
num_cols = px.hdf_utils.get_attr(h5_meas_grp, 'grid_num_cols')
# Getting a reference to the main dataset:
h5_main = px.PycroDataset(h5_meas_grp['Channel_000/Raw_Data'])
px.hdf_utils.write_simple_attrs(h5_main, {'quantity': 'Deflection', 'units': 'V'})
# Extracting the X axis - vector of frequencies
h5_spec_vals = px.hdf_utils.get_auxiliary_datasets(h5_main, 'Spectroscopic_Values')[-1]
freq_vec = np.squeeze(h5_spec_vals.value) * 1E-3
print('Data currently of shape:', h5_main.shape)
x_label = 'Frequency (kHz)'
y_label = 'Amplitude (a.u.)'
#####################################################################################
# 1. Singular Value Decomposition (SVD)
# =====================================
#
# SVD is an eigenvector decomposition that is defined statistically, and therefore typically produces
# non-physical eigenvectors. Consequently, the interpretation of eigenvectors and abundance maps from
# SVD requires care and caution in interpretation. Nonetheless, it is a good method for quickly
# visualizing the major trends in the dataset since the resultant eigenvectors are sorted in descending
# order of variance or importance. Furthermore, SVD is also very well suited for data cleaning through
# the reconstruction of the dataset using only the first N (most significant) components.
#
# SVD results in three matrices:
#
# * V - Eigenvectors sorted by variance in descending order
# * U - corresponding abundance maps
# * S - Variance or importance of each of these components
#
# Advantage of pycroscopy:
# ------------------------
# Notice that we are working with a complex valued dataset. Passing the complex values as is to SVD would result in
# complex valued eigenvectors / endmembers as well as abundance maps. Complex valued abundance maps are not physical.
# Thus, one would need to restructure the data such that it is real-valued only.
#
# One solution is to stack the real value followed by the magnitude of the imaginary component before passing to SVD.
# After SVD, the real-valued eigenvectors would need to be treated as the concatenation of the real and imaginary
# components. So, the eigenvectors would need to be restructured to get back the complex valued eigenvectors.
#
# **Pycroscopy handles all these data transformations (both for the source dataset and the eigenvectors)
# automatically.** In general, pycroscopy handles compound / complex valued datasets everywhere possible
#
# Furthermore, while it is not discussed in this example, pycroscopy also writes back the results from SVD back to
# the same source h5 file including all relevant links to the source dataset and other ancillary datasets
decomposer = px.processing.svd_utils.SVD(h5_main, num_components=100)
h5_svd_group = decomposer.compute()
h5_u = h5_svd_group['U']
h5_v = h5_svd_group['V']
h5_s = h5_svd_group['S']
# Since the two spatial dimensions (x, y) have been collapsed to one, we need to reshape the abundance maps:
abun_maps = np.reshape(h5_u[:, :25], (num_rows, num_cols, -1))
px.plot_utils.plot_map_stack(abun_maps, num_comps=9, title='SVD Abundance Maps', reverse_dims=True,
color_bar_mode='single', cmap='inferno', title_yoffset=0.95)
# Visualize the variance / statistical importance of each component:
px.plot_utils.plot_scree(h5_s, title='Note the exponential drop of variance with number of components')
# Visualize the eigenvectors:
_ = px.plot_utils.plot_complex_spectra(h5_v[:9, :], x_label=x_label, y_label=y_label,
title='SVD Eigenvectors', evenly_spaced=False)
#####################################################################################
# 2. KMeans Clustering
# ====================
#
# KMeans clustering is a quick and easy method to determine the types of spectral responses present in the
# data. It is not a decomposition method, but a basic clustering method. The user inputs the number of
# clusters (sets) to partition the data into. The algorithm proceeds to find the optimal labeling
# (ie., assignment of each spectra as belonging to the k<sup>th</sup> set) such that the within-cluster
# sum of squares is minimized.
#
# Set the number of clusters below
num_clusters = 4
estimator = px.processing.Cluster(h5_main, KMeans(n_clusters=num_clusters))
h5_kmeans_grp = estimator.compute(h5_main)
h5_kmeans_labels = h5_kmeans_grp['Labels']
h5_kmeans_mean_resp = h5_kmeans_grp['Mean_Response']
cluster_utils.plot_cluster_h5_group(h5_kmeans_grp)
#####################################################################################
# 3. Non-negative Matrix Factorization (NMF)
# ===========================================
#
# NMF, or non-negative matrix factorization, is a method that is useful towards unmixing of spectral
# data. It only works on data with positive real values. It operates by approximate determination of
# factors (matrices) W and H, given a matrix V, as shown below
#
# .. image:: https://upload.wikimedia.org/wikipedia/commons/f/f9/NMF.png
#
# Unlike SVD and k-Means that can be applied to complex-valued datasets, NMF only works on non-negative datasets.
# For illustrative purposes, we will only take the amplitude component of the spectral data
num_comps = 4
# get the non-negative portion of the dataset
data_mat = np.abs(h5_main)
model = NMF(n_components=num_comps, init='random', random_state=0)
model.fit(data_mat)
fig, axis = plt.subplots(figsize=(5.5, 5))
px.plot_utils.plot_line_family(axis, freq_vec, model.components_, label_prefix='NMF Component #')
axis.set_xlabel(x_label, fontsize=12)
axis.set_ylabel(y_label, fontsize=12)
axis.set_title('NMF Components', fontsize=14)
axis.legend(bbox_to_anchor=[1.0, 1.0], fontsize=12)
#####################################################################################
# Close and delete the h5_file
h5_file.close()
os.remove(data_file_path)
| 43.036364 | 120 | 0.705218 | 1 | 1.9716 | [
-0.020135274156928062,
0.031033646315336227,
-0.01031496375799179,
-0.01142222248017788,
-0.015432465821504593,
0.017476411536335945,
-0.008772860281169415,
-0.018610810860991478,
-0.03272492066025734,
0.026152679696679115,
-0.006689672823995352,
0.008044993504881859,
0.04362254589796066,
0.00826489832252264,
-0.03514287620782852,
-0.0018358242232352495,
0.02569945715367794,
-0.028922317549586296,
-0.0009054734837263823,
0.014897380955517292,
-0.016943607479333878,
0.01571294665336609,
-0.003590909531340003,
0.029177242890000343,
0.006728844251483679,
-0.020988497883081436,
0.022330861538648605,
0.018392054364085197,
0.013854731805622578,
-0.008563044480979443,
0.0038770714309066534,
-0.024879341945052147,
-0.012324333190917969,
-0.007981781847774982,
-0.0028071715496480465,
-0.01404829416424036,
0.006795724853873253,
-0.048593804240226746,
0.010749260894954205,
0.023908022791147232,
0.027617521584033966,
-0.0180804505944252,
-0.005460710264742374,
0.002584257395938039,
0.01296431478112936,
0.003662962932139635,
-0.02058110386133194,
0.032765742391347885,
-0.046286169439554214,
0.025340579450130463,
0.002719609998166561,
-0.0037709439639002085,
0.02538677677512169,
-0.028888525441288948,
0.01424534060060978,
-0.03301810100674629,
-0.007725174073129892,
0.02927629090845585,
-0.049821630120277405,
0.0229958426207304,
0.034149155020713806,
0.0016382380854338408,
0.00819270871579647,
-0.01660357601940632,
0.05429137125611305,
-0.004967382177710533,
0.009629881009459496,
-0.0036350793670862913,
-0.060118868947029114,
-0.0233756173402071,
0.02124316617846489,
0.03855786845088005,
0.007970432750880718,
0.051455773413181305,
0.008843795396387577,
0.02979079633951187,
-0.036538973450660706,
-0.018551038578152657,
-0.015677018091082573,
0.01690012402832508,
-0.004319553729146719,
0.06247258558869362,
0.011091782711446285,
0.005787684582173824,
0.013072818517684937,
0.023274851962924004,
0.034455277025699615,
-0.048988956958055496,
0.02701687254011631,
0.015959255397319794,
-0.020060958340764046,
0.053113460540771484,
-0.024834012612700462,
0.0056658778339624405,
-0.04677654430270195,
-0.07816547900438309,
0.009307143278419971,
0.00931070651859045,
-0.0063238893635571,
0.018124626949429512,
0.017634429037570953,
-0.02417905069887638,
0.01844055950641632,
0.005503554828464985,
-0.0008604517788626254,
-0.0006662856321781874,
-0.057522062212228775,
0.009353178553283215,
-0.0022756177932024,
-0.009698007255792618,
0.0037813177332282066,
-0.012576625682413578,
-0.0008905596914701164,
-0.011361847631633282,
-0.013810277916491032,
-0.011308583430945873,
-0.013058648444712162,
0.010565188713371754,
-0.019708242267370224,
0.024690892547369003,
-0.004094783682376146,
-0.028146421536803246,
0.010958652943372726,
-0.019847318530082703,
-0.02061023749411106,
0.07140681892633438,
-0.012114854529500008,
-0.006520319730043411,
0.034826360642910004,
-0.018504949286580086,
0.00015532324323430657,
-0.009223869070410728,
0.02250499464571476,
-0.023855110630393028,
-0.010583586059510708,
-0.011806333437561989,
0.0036672342102974653,
-0.012172488495707512,
-0.028531420975923538,
0.008881750516593456,
0.02233368344604969,
-0.03382009267807007,
-0.000846139038912952,
-0.029231159016489983,
-0.0027817250229418278,
-0.03447772189974785,
-0.029534941539168358,
-0.013495744206011295,
-0.014259055256843567,
-0.01857100985944271,
-0.006566277705132961,
-0.02973008155822754,
-0.002633429132401943,
0.018380921334028244,
0.00021469809871632606,
-0.023465923964977264,
0.0030023897998034954,
-0.06935577839612961,
0.025485944002866745,
-0.017780911177396774,
-0.021438127383589745,
0.0022053271532058716,
-0.009124841541051865,
0.006958502810448408,
-0.02454560063779354,
0.027228351682424545,
-0.026543231680989265,
0.018018478527665138,
-0.010117734782397747,
0.02802252024412155,
0.00041698446148075163,
-0.007357271853834391,
0.0012626060051843524,
-0.02120116539299488,
-0.03018336370587349,
0.012642791494727135,
0.0205446295440197,
0.011157608591020107,
0.0054187229834496975,
-0.0009817536920309067,
0.01784934289753437,
0.000825104012619704,
-0.008923664689064026,
0.021733863279223442,
0.01978171244263649,
0.011697296984493732,
-0.026550810784101486,
-0.015260562300682068,
-0.01078052632510662,
-0.032696906477212906,
-0.015337305143475533,
0.012233483605086803,
-0.040974751114845276,
-0.019934333860874176,
0.02711176685988903,
0.010295171290636063,
0.028427034616470337,
-0.009656027890741825,
-0.0008932583732530475,
0.017254840582609177,
0.005265675950795412,
-0.02428542450070381,
-0.0019629760645329952,
0.016634635627269745,
-0.01634441874921322,
-0.02017979510128498,
-0.7683323621749878,
0.02393692545592785,
0.013843980617821217,
-0.005746548529714346,
0.018524575978517532,
0.05408379063010216,
-0.041084643453359604,
0.034966230392456055,
-0.09699036180973053,
0.04055165499448776,
0.0215928815305233,
-0.0003792818752117455,
-0.023188794031739235,
0.014560671523213387,
0.03290766477584839,
-0.02459067478775978,
0.01715276576578617,
0.01805071346461773,
0.026446402072906494,
-0.002701579127460718,
0.021290551871061325,
-0.010803922079503536,
-0.014429504983127117,
0.015656806528568268,
0.02092020958662033,
-0.0062729776836931705,
0.0357261523604393,
0.008045275695621967,
0.025684574618935585,
-0.03572148457169533,
0.0027189021930098534,
-0.0053379409946501255,
0.011790111660957336,
-0.02943539433181286,
0.016282735392451286,
0.04644429683685303,
0.00468940194696188,
-0.0122311906889081,
0.003386708442121744,
-0.008954934775829315,
0.0073914313688874245,
-0.014783629216253757,
-0.04623284563422203,
-0.05433468520641327,
-0.04251541197299957,
-0.01756899617612362,
-0.039936911314725876,
-0.04471272975206375,
0.029436146840453148,
-0.006646487396210432,
-0.02367621287703514,
0.03047630935907364,
0.024875396862626076,
-0.017422689124941826,
-0.017962558194994926,
0.013002878054976463,
-0.02443668618798256,
-0.003163156798109412,
-0.002746660728007555,
-0.009077557362616062,
0.01531971525400877,
-0.012113938108086586,
-0.04079889878630638,
0.0043581402860581875,
0.001319090835750103,
0.010452153161168098,
0.0696544274687767,
-0.02716987393796444,
-0.014998682774603367,
0.010026431642472744,
-0.035562239587306976,
-0.017435383051633835,
-0.019551638513803482,
0.10963942855596542,
-0.0032396328169852495,
0.010168765671551228,
-0.007473430130630732,
0.015646232292056084,
-0.052964724600315094,
-0.0057374476455152035,
0.010642852634191513,
-0.017762497067451477,
-0.014159774407744408,
-0.011453050188720226,
-0.014140859246253967,
0.021837584674358368,
-0.007729190401732922,
-0.0037130750715732574,
-0.014575575478374958,
-0.020036915317177773,
0.006020871922373772,
0.0344713069498539,
0.013041702099144459,
-0.013165649957954884,
-0.010890930891036987,
0.0359545573592186,
0.02014259621500969,
0.003539560129866004,
0.009836692363023758,
0.014990556053817272,
-0.043621838092803955,
0.0012672607554122806,
-0.006805203389376402,
0.05868392810225487,
0.021111760288476944,
0.008977395482361317,
-0.027973486110568047,
0.0008844669791869819,
0.04960634559392929,
-0.017938990145921707,
-0.00024309435684699565,
-0.023383742198348045,
-0.0011127075413241982,
-0.007067795842885971,
-0.005043793935328722,
-0.04113362357020378,
0.010906356386840343,
-0.03675347566604614,
0.0036120049189776182,
-0.0008718446479178965,
-0.04298628866672516,
-0.007671758066862822,
0.025168202817440033,
-0.00030542336753569543,
-0.01286448072642088,
0.01711154729127884,
-0.003870964515954256,
0.012054180726408958,
-0.000461794639704749,
0.010654734447598457,
-0.039527587592601776,
-0.008607896976172924,
-0.019577043130993843,
-0.002450081752613187,
-0.0021715129259973764,
-0.006215579342097044,
-0.01619652286171913,
-0.018744271248579025,
-0.013155386783182621,
-0.006569189485162497,
-0.016331756487488747,
-0.022999145090579987,
-0.0148014472797513,
-0.032478656619787216,
0.013904188759624958,
-0.011400748044252396,
0.030935432761907578,
0.024884240701794624,
0.025040412321686745,
0.029172349721193314,
-0.0055023678578436375,
0.008835803717374802,
0.0038224596064537764,
-0.007603805512189865,
-0.004704077262431383,
0.03876345604658127,
-0.021833861246705055,
0.00794856995344162,
0.008972262032330036,
-0.006497540045529604,
-0.014644933864474297,
-0.005402416456490755,
-0.03282860666513443,
0.018996477127075195,
0.004160122945904732,
0.003190124174579978,
-0.016539666801691055,
0.03341588005423546,
-0.005535558797419071,
0.004157835617661476,
0.005586900748312473,
-0.008948507718741894,
0.042066775262355804,
-0.001535428804345429,
-0.00602338369935751,
0.014964018948376179,
-0.02318636141717434,
-0.04143236204981804,
-0.009809520095586777,
-0.014421512372791767,
-0.005850430577993393,
0.02301473543047905,
-0.012673968449234962,
0.020934943109750748,
0.004217786714434624,
0.02816069684922695,
-0.004127759952098131,
0.03294952213764191,
0.020267872139811516,
0.009361442178487778,
-0.0001180083563667722,
0.021503420546650887,
-0.019122065976262093,
0.025485455989837646,
-0.03527773916721344,
-0.013780603185296059,
-0.005165753420442343,
-0.03281547129154205,
-0.004158983938395977,
-0.023192323744297028,
0.0002755423483904451,
0.046424899250268936,
0.01526299212127924,
-0.02180476486682892,
0.003233953844755888,
0.0348360650241375,
0.016550101339817047,
-0.0029431937728077173,
-0.003986032214015722,
0.00005606073682429269,
0.012930760160088539,
-0.01254426408559084,
0.01967906579375267,
-0.007103715557605028,
0.015258366242051125,
0.023708278313279152,
-0.035005003213882446,
-0.01226159930229187,
0.025975612923502922,
-0.026549899950623512,
0.01168771367520094,
-0.0059768217615783215,
-0.0031750702764838934,
0.014467544853687286,
0.006412838585674763,
0.001663082162849605,
-0.037242088466882706,
0.017137907445430756,
0.0017893826588988304,
-0.009256917051970959,
-0.0037666535936295986,
0.009283015504479408,
0.014408251270651817,
-0.005724460352212191,
-0.0048785703256726265,
0.012221915647387505,
-0.022359328344464302,
-0.0003184289380442351,
-0.0069856238551437855,
-0.027259614318609238,
-0.016750462353229523,
-0.000009990171747631393,
-0.030750634148716927,
0.028410926461219788,
-0.020945927128195763,
0.006826638709753752,
0.01846991665661335,
-0.02043982222676277,
-0.05314015597105026,
-0.0068570091389119625,
-0.05290598049759865,
0.015887295827269554,
-0.008718772791326046,
0.010729346424341202,
0.015924829989671707,
0.022763483226299286,
-0.024714462459087372,
0.03386102616786957,
0.03644794598221779,
0.01645270362496376,
-0.009832074865698814,
-0.026070134714245796,
-0.00559017900377512,
0.011450959369540215,
-0.001969370059669018,
0.023824358358979225,
-0.009299509227275848,
0.01230752281844616,
0.005108807701617479,
0.01733415573835373,
0.007033018860965967,
0.016123725101351738,
-0.028192218393087387,
0.0036297279875725508,
-0.00953433196991682,
-0.0010273086372762918,
-0.005467840936034918,
-0.05572879686951637,
0.007525038905441761,
0.015802497044205666,
-0.04112599790096283,
0.015803959220647812,
0.01686190627515316,
0.018874121829867363,
0.000322780484566465,
-0.0019338479032739997,
0.031317949295043945,
-0.02110353112220764,
-0.04237240180373192,
0.006147875916212797,
-0.007529108319431543,
-0.02256160043179989,
-0.007562715094536543,
0.0017257567960768938,
-0.014014948159456253,
0.026225853711366653,
0.016134245321154594,
-0.005060724448412657,
0.018887117505073547,
0.03535795584321022,
0.05580030381679535,
-0.0024756407365202904,
0.004136305768042803,
-0.0007678666152060032,
0.01230462733656168,
-0.028925655409693718,
0.017589716240763664,
-0.036652613431215286,
0.0427681989967823,
0.014275624416768551,
-0.007380403112620115,
0.0211653932929039,
0.008731870912015438,
0.013611641712486744,
0.0004384047060739249,
-0.003553661983460188,
0.042516399174928665,
0.06627634167671204,
0.008555036969482899,
0.0032985529396682978,
-0.02122136577963829,
-0.010189227759838104,
-0.036012791097164154,
-0.036861542612314224,
0.017196502536535263,
-0.009336723014712334,
-0.02088167518377304,
0.012217571027576923,
-0.011046015657484531,
0.03786619007587433,
-0.02051633410155773,
0.002049189992249012,
0.03732197359204292,
-0.0010023096110671759,
0.012516324408352375,
-0.021272985264658928,
0.025057820603251457,
0.030083341524004936,
0.023362180218100548,
-0.00964922271668911,
-0.030876055359840393,
0.008331703022122383,
-0.012295990251004696,
0.013762877322733402,
-0.007629893254488707,
0.02260882593691349,
0.040539562702178955,
0.06272812932729721,
0.031562335789203644,
-0.005907247308641672,
0.05052131786942482,
-0.028320107609033585,
-0.04197651147842407,
0.003540737321600318,
0.012810593470931053,
0.012125572189688683,
-0.018860170617699623,
0.01727478578686714,
-0.000028759255656041205,
-0.006436786148697138,
0.022276507690548897,
-0.00204415712505579,
0.005881514400243759,
-0.024671873077750206,
0.006117316894233227,
0.0014888213481754065,
0.008796833455562592,
-0.031830910593271255,
-0.03702270984649658,
0.03005879744887352,
0.003955915570259094,
-0.029468415305018425,
-0.011621430516242981,
-0.0073998779989778996,
0.024908948689699173,
0.02390550822019577,
0.039372336119413376,
-0.010249100625514984,
-0.010177752003073692,
0.011935431510210037,
-0.01913764886558056,
-0.03010757826268673,
0.02884804829955101,
-0.011742161586880684,
0.015438760630786419,
-0.013093225657939911,
0.03639061003923416,
0.009195812046527863,
-0.003493581898510456,
-0.0012039036955684423,
-0.007165958639234304,
-0.020357344299554825,
0.0020957044325768948,
0.010751689784228802,
-0.033733732998371124,
-0.004277579486370087,
-0.024371536448597908,
-0.016609501093626022,
0.005490715149790049,
0.01236102543771267,
0.0013156139757484198,
0.006062747910618782,
0.0069718630984425545,
-0.022915111854672432,
-0.03725910186767578,
-0.0010325527982786298,
0.03740734979510307,
0.01567981205880642,
-0.012000001035630703,
0.03116546757519245,
0.026088004931807518,
0.021314585581421852,
-0.0031345628667622805,
0.0027558100409805775,
0.03220226243138313,
-0.014675618149340153,
-0.017501866444945335,
0.011292340233922005,
-0.02339296229183674,
-0.008214645087718964,
-0.023243067786097527,
-0.024315832182765007,
-0.011723509058356285,
-0.017547741532325745,
-0.0003583428915590048,
-0.001360385213047266,
0.03666730597615242,
-0.01491506490856409,
0.0070046023465693,
0.008974291384220123,
0.009530233219265938,
-0.03263865038752556,
-0.017444875091314316,
0.018723981454968452,
0.0003451740194577724,
-0.03338943421840668,
0.01549066323786974,
-0.03239936754107475,
-0.0154733806848526,
0.03164714574813843,
-0.00009080873132916167,
-0.0021657675970345736,
0.00852984469383955,
-0.00466071767732501,
-0.013175257481634617,
0.015938833355903625,
0.038784705102443695,
0.013946357183158398,
-0.012465886771678925,
-0.02013537846505642,
0.020224928855895996,
-0.0029895298648625612,
0.021476836875081062,
0.016121061518788338,
0.022955307736992836,
0.014090392738580704,
0.04298853874206543,
0.032092124223709106,
0.013252158649265766,
0.0060875811614096165,
-0.02788412943482399,
0.018627457320690155,
-0.01871795766055584,
0.03573399782180786,
0.0020639945287257433,
0.021473759785294533,
0.026217620819807053,
-0.01566615141928196,
-0.006014767102897167,
-0.039856474846601486,
0.014638671651482582,
0.03686043992638588,
-0.021250946447253227,
0.006312706973403692,
-0.0046686516143381596,
-0.017328595742583275,
-0.021213900297880173,
0.014036460779607296,
0.004801489878445864,
0.0009196115424856544,
0.0010230420157313347,
0.009038674645125866,
0.015532814897596836,
-0.0014877740759402514,
0.01620577648282051,
-0.03850644454360008,
-0.010377224534749985,
0.011585346423089504,
-0.008797011338174343,
0.016638150438666344,
-0.005065522622317076,
-0.0008664188790135086,
-0.015584738925099373,
0.01738601364195347,
-0.014871985651552677,
0.002506107557564974,
0.02693694271147251,
-0.009973361156880856,
0.03843240812420845,
-0.00014474682393483818,
-0.022051114588975906,
-0.05348514765501022,
-0.020819101482629776,
-0.035592272877693176,
0.035736773163080215,
0.00803038664162159,
0.10414726287126541,
0.029325561597943306,
-0.008644611574709415,
-0.014910236932337284,
-0.022649483755230904,
0.018198668956756592,
-0.03131077066063881,
-0.00035611013299785554,
-0.014978061430156231,
0.014198379591107368,
0.038671232759952545,
-0.040007684379816055,
0.0020541632547974586,
0.012675457634031773,
0.01969669573009014,
0.028048597276210785,
-0.0073045045137405396,
-0.029714899137616158,
0.004021583590656519,
-0.014960475265979767,
-0.02990025468170643,
-0.028658613562583923,
0.019943635910749435,
0.009547917172312737,
-0.011403525248169899,
0.0032322173938155174,
-0.024470079690217972,
0.011247116141021252,
-0.005664056167006493,
-0.04106847941875458,
0.017178475856781006,
-0.01389396470040083,
-0.021815044805407524,
0.0003616284520830959,
0.026843933388590813,
0.01746777817606926,
0.015329643152654171,
-0.011661949567496777,
-0.013644225895404816,
-0.017769519239664078,
-0.009166931733489037,
0.0003028674400411546,
0.014957994222640991,
-0.0014297800371423364,
-0.011285257525742054,
-0.024084866046905518,
0.013895918615162373,
0.003244965337216854,
-0.02526395209133625,
0.0022792296949774027,
-0.0056688738986849785,
0.02191954478621483,
-0.005163852125406265,
-0.033905357122421265,
0.011232907883822918,
0.025427134707570076
] |
8a54efc9a7ad3665cabc7b4468043314dcb3122b | 3,743 | py | Python | test/test_downloadfile.py | foliant-docs/foliantcontrib.downloadfile | 1af9481f9bc9142d8b1ac1eff93fa0c5577ccaec | [
"MIT"
] | null | null | null | test/test_downloadfile.py | foliant-docs/foliantcontrib.downloadfile | 1af9481f9bc9142d8b1ac1eff93fa0c5577ccaec | [
"MIT"
] | null | null | null | test/test_downloadfile.py | foliant-docs/foliantcontrib.downloadfile | 1af9481f9bc9142d8b1ac1eff93fa0c5577ccaec | [
"MIT"
] | null | null | null | import shutil
from pathlib import Path
from unittest import TestCase
from unittest.mock import Mock
from unittest.mock import patch
from foliant.config.downloadfile import download_file
from foliant.config.downloadfile import get_file_ext_from_url
from foliant.config.downloadfile import get_file_name_from_url
class TestDownloadFile(TestCase):
def setUp(self):
self.project_dir = (Path(__file__).parent / 'project_dir').resolve()
self.project_dir.mkdir(exist_ok=True)
def tearDown(self):
shutil.rmtree(self.project_dir, ignore_errors=True)
@patch('foliant.config.downloadfile.urlopen', autospec=True)
def test_only_url(self, urlopen):
mock_response = Mock()
mock_response.read.return_value = b'File content'
urlopen.return_value = mock_response
url = 'http://example.com/myfile.txt'
download_file(root_dir=self.project_dir, url=url)
request = urlopen.call_args.args[0]
context = urlopen.call_args.kwargs['context']
self.assertEqual(request.headers, {})
self.assertIsNone(context)
with open(self.project_dir / 'myfile.txt') as f:
self.assertEqual(f.read(), 'File content')
@patch('foliant.config.downloadfile.urlopen', autospec=True)
def test_save_to(self, urlopen):
mock_response = Mock()
mock_response.read.return_value = b'File content'
urlopen.return_value = mock_response
url = 'http://example.com/myfile.txt'
save_to = 'subdir1/subdir2/downloaded.txt'
download_file(root_dir=self.project_dir, url=url, save_to=save_to)
request = urlopen.call_args.args[0]
context = urlopen.call_args.kwargs['context']
self.assertEqual(request.headers, {})
self.assertIsNone(context)
with open(self.project_dir / save_to) as f:
self.assertEqual(f.read(), 'File content')
@patch('foliant.config.downloadfile.urlopen', autospec=True)
def test_with_auth(self, urlopen):
mock_response = Mock()
mock_response.read.return_value = b'File content'
urlopen.return_value = mock_response
url = 'http://example.com/myfile.txt'
download_file(
root_dir=self.project_dir,
url=url,
login='john',
password='qwerty1234'
)
request = urlopen.call_args.args[0]
context = urlopen.call_args.kwargs['context']
self.assertIn('Authorization', request.headers)
self.assertIsNone(context)
with open(self.project_dir / 'myfile.txt') as f:
self.assertEqual(f.read(), 'File content')
class TestGetFileNameFromURL(TestCase):
def test_with_ext(self):
url = 'http://example.com/sub/myfile.txt'
name = get_file_name_from_url(url)
self.assertEqual(name, 'myfile.txt')
def test_no_ext(self):
url = 'http://example.com/sub/myfile'
name = get_file_name_from_url(url)
self.assertEqual(name, 'myfile')
def test_with_clutter(self):
url = 'http://example.com/sub/myfile.txt?param=val&foo=bar'
name = get_file_name_from_url(url)
self.assertEqual(name, 'myfile.txt')
class TestGetFileExtFromURL(TestCase):
def test_with_ext(self):
url = 'http://example.com/sub/myfile.txt'
ext = get_file_ext_from_url(url)
self.assertEqual(ext, '.txt')
def test_no_ext(self):
url = 'http://example.com/sub/myfile'
ext = get_file_ext_from_url(url)
self.assertEqual(ext, '')
def test_with_clutter(self):
url = 'http://example.com/sub/myfile.txt?param=val&foo=bar'
ext = get_file_ext_from_url(url)
self.assertEqual(ext, '.txt')
| 32.833333 | 76 | 0.663906 | 1 | 1.8501 | [
-0.031337372958660126,
0.024502631276845932,
0.023715930059552193,
-0.019287189468741417,
0.0010309630306437612,
0.02921384386718273,
-0.05999370291829109,
-0.02734246291220188,
-0.03172416239976883,
0.03045373223721981,
-0.0017725183861330152,
-0.005643146112561226,
0.03050251118838787,
-0.05256880447268486,
-0.014351772144436836,
0.005590531509369612,
0.08366881310939789,
0.024840176105499268,
-0.009971105493605137,
-0.012956264428794384,
0.01161284651607275,
-0.002635893179103732,
-0.016016360372304916,
0.005140972789376974,
0.021854884922504425,
0.003649036632850766,
0.03971346840262413,
-0.000012432357834768482,
-0.012240974232554436,
-0.018724502995610237,
-0.012519481591880322,
0.026798585429787636,
0.01809164322912693,
0.024824626743793488,
-0.04488491639494896,
0.012075858190655708,
0.01486277487128973,
-0.0818767100572586,
-0.00641984585672617,
0.01123303547501564,
-0.02018466778099537,
-0.045945197343826294,
-0.0040979101322591305,
-0.001320578739978373,
0.04748651385307312,
0.0006836302927695215,
-0.018270276486873627,
0.03834039345383644,
-0.0316273532807827,
-0.005893567577004433,
-0.029037879779934883,
0.03582632914185524,
0.02687881886959076,
-0.018603650853037834,
0.017088018357753754,
-0.03420840948820114,
0.01671769469976425,
0.024217963218688965,
-0.03590600937604904,
0.019663037732243538,
-0.022549644112586975,
-0.0025694933719933033,
-0.004217752255499363,
-0.008207718841731548,
0.05476376414299011,
-0.008566428907215595,
-0.0036179928574711084,
-0.013875122182071209,
-0.04302957281470299,
-0.0007164038252085447,
-0.006525327451527119,
-0.04209378734230995,
0.02383575215935707,
0.06448203325271606,
0.01564704440534115,
0.03126535564661026,
-0.052823908627033234,
-0.011261110194027424,
0.015610217116773129,
0.006580049637705088,
-0.012746873311698437,
0.06537185609340668,
-0.008819966576993465,
0.006295565981417894,
-0.04148736223578453,
0.022473515942692757,
0.06533245742321014,
-0.0682913288474083,
0.05918522924184799,
0.053555503487586975,
-0.033382825553417206,
0.010019349865615368,
-0.05574098601937294,
0.00504755973815918,
-0.02094840444624424,
-0.06509614735841751,
0.00456609670072794,
-0.006645205896347761,
0.014247801154851913,
-0.009082796983420849,
0.0017244567861780524,
-0.038745757192373276,
0.007115515414625406,
-0.024883756414055824,
-0.03319675475358963,
0.01024880912154913,
-0.0410497672855854,
0.00023970901384018362,
-0.005836680065840483,
-0.02908351644873619,
-0.05136791989207268,
-0.0038758781738579273,
0.022643644362688065,
-0.03162195160984993,
0.029550718143582344,
-0.023588240146636963,
0.046232543885707855,
0.005457562860101461,
0.013245077803730965,
-0.0036437648814171553,
0.017742685973644257,
-0.00782470591366291,
0.056625332683324814,
-0.013034689240157604,
-0.03786924481391907,
0.06489232927560806,
-0.030945317819714546,
0.006291201338171959,
-0.0047476328909397125,
0.00861868541687727,
-0.016245467588305473,
-0.0030154141131788492,
-0.020335422828793526,
-0.002896385733038187,
0.03717973083257675,
0.0002594090474303812,
0.001412339974194765,
0.007492071483284235,
-0.03594762831926346,
0.011307398788630962,
0.01736806519329548,
-0.010953085497021675,
-0.009605061262845993,
-0.026395687833428383,
-0.001910725375637412,
-0.047876738011837006,
0.001032331958413124,
-0.0011878269724547863,
-0.01889723725616932,
-0.03288302943110466,
-0.018904002383351326,
0.02178644761443138,
0.0009288958972319961,
0.028812937438488007,
-0.018178226426243782,
-0.006849754136055708,
-0.0003951256803702563,
-0.04853992909193039,
0.026105359196662903,
-0.025079701095819473,
-0.0452808141708374,
0.046743299812078476,
-0.002690085908398032,
-0.007208752445876598,
0.03039921261370182,
0.030915074050426483,
-0.011490068398416042,
0.03447382524609566,
-0.027753708884119987,
0.02074345573782921,
-0.0035173783544451,
0.018268179148435593,
-0.0375349186360836,
-0.002483195625245571,
-0.0016799593577161431,
-0.00386738870292902,
0.017249800264835358,
0.01535010151565075,
0.02048606052994728,
0.008714129216969013,
-0.006318259052932262,
0.01933751255273819,
0.03049522079527378,
0.035148411989212036,
0.035524848848581314,
0.002931059105321765,
-0.06884673237800598,
-0.011653225868940353,
0.0036048335023224354,
-0.0008013910264708102,
-0.013806137256324291,
0.03225289285182953,
-0.016603058204054832,
-0.034656036645174026,
0.03239310905337334,
0.024617517367005348,
0.02728102169930935,
-0.025222528725862503,
-0.02119848132133484,
-0.011897144839167595,
-0.02557867206633091,
0.007750122807919979,
-0.021119635552167892,
0.04957454279065132,
0.002200039103627205,
0.01534151192754507,
-0.6911366581916809,
-0.009924940764904022,
-0.021678881719708443,
-0.00955364853143692,
0.044572941958904266,
-0.009703278541564941,
-0.0026650242507457733,
0.008696876466274261,
-0.028501175343990326,
-0.008085847832262516,
-0.00633989879861474,
-0.02045886218547821,
-0.03292779624462128,
-0.017575398087501526,
0.028806552290916443,
-0.028828585520386696,
0.020311670377850533,
-0.01696956343948841,
-0.01358596421778202,
0.020196925848722458,
0.02271408587694168,
-0.01989934593439102,
0.004208579659461975,
-0.0007387819932773709,
0.04362097382545471,
0.025642231106758118,
0.030766690149903297,
-0.01783827133476734,
0.015932612121105194,
-0.030877746641635895,
0.01449107937514782,
-0.011058726347982883,
0.011345123872160912,
-0.02244679071009159,
0.029315169900655746,
0.027449799701571465,
0.010029710829257965,
-0.018173696473240852,
-0.000208935554837808,
0.014995434321463108,
-0.04757321625947952,
0.0028038006275892258,
-0.006594272330403328,
-0.0755171924829483,
-0.02444048412144184,
0.003271963447332382,
-0.034518640488386154,
-0.02202463150024414,
0.007409903220832348,
0.030567964538931847,
-0.01719236560165882,
0.03346491605043411,
0.03317880257964134,
-0.01513239461928606,
0.010286875069141388,
0.03173751011490822,
-0.013989336788654327,
-0.031112583354115486,
-0.0018267506966367364,
0.0036996614653617144,
0.062324851751327515,
0.013370422646403313,
-0.013182374648749828,
0.014478936791419983,
0.024616951122879982,
0.03172837942838669,
0.059034958481788635,
-0.023632381111383438,
-0.02502204105257988,
0.030240368098020554,
-0.0497499480843544,
0.010332799516618252,
-0.046858374029397964,
0.15146805346012115,
-0.01383194886147976,
0.013345999643206596,
-0.01645795628428459,
0.0018161428160965443,
-0.06099402531981468,
0.0005939392140135169,
0.04305463284254074,
-0.018162470310926437,
-0.013125013560056686,
0.0051691485568881035,
-0.02582201547920704,
-0.00647283811122179,
-0.02310699224472046,
0.0036848702002316713,
-0.023481059819459915,
0.003599034622311592,
0.029496625065803528,
0.036559414118528366,
-0.011904885992407799,
-0.0071708266623318195,
-0.005886259954422712,
0.023496627807617188,
0.015684625133872032,
0.06651033461093903,
0.021230485290288925,
0.017120536416769028,
-0.04800904914736748,
-0.007564054802060127,
-0.004962708335369825,
0.03354024887084961,
-0.027613148093223572,
0.01715606264770031,
-0.033830322325229645,
-0.020161209627985954,
0.03127757087349892,
-0.011365759186446667,
-0.0017685728380456567,
-0.0017110586632043123,
-0.01932000368833542,
0.019885078072547913,
-0.005911492742598057,
-0.023578675463795662,
0.014301992021501064,
-0.03959758207201958,
0.042503148317337036,
0.0019289699848741293,
-0.028309840708971024,
-0.01494667399674654,
0.005535916890949011,
0.05339007079601288,
-0.00201794202439487,
-0.024475445970892906,
-0.025156307965517044,
-0.0019196686334908009,
-0.009407964535057545,
0.01652880571782589,
-0.006984278559684753,
-0.010895603336393833,
-0.021837186068296432,
0.0012281661620363593,
0.008974741213023663,
0.0028741867281496525,
-0.013937760144472122,
-0.03833955526351929,
-0.02898084558546543,
-0.012538515962660313,
-0.0038053274620324373,
-0.035285331308841705,
0.005579651799052954,
-0.05647909641265869,
0.03936973214149475,
0.010186524130403996,
0.016513599082827568,
0.0013955567264929414,
-0.015306578949093819,
-0.017542321234941483,
-0.020861586555838585,
0.02460911124944687,
-0.004113436210900545,
-0.002729227766394615,
-0.02440882846713066,
0.0070478408597409725,
-0.009391901083290577,
0.013189912773668766,
0.025537801906466484,
-0.003077324014157057,
0.010135567747056484,
0.013157213106751442,
-0.028314342722296715,
0.040546104311943054,
0.004435432143509388,
-0.034056127071380615,
0.013003760948777199,
-0.0036398828960955143,
0.0026786504313349724,
0.03049028106033802,
0.006446676328778267,
-0.033794108778238297,
0.020161978900432587,
-0.004734297748655081,
-0.011445735581219196,
0.001234244555234909,
-0.00870970543473959,
-0.04606997221708298,
0.012674433179199696,
-0.04899364709854126,
-0.01404030155390501,
-0.002903872635215521,
0.008201248943805695,
-0.006299082655459642,
-0.0029164536390453577,
0.0006469400250352919,
-0.013166087679564953,
-0.005820952355861664,
0.010212075896561146,
-0.018662987276911736,
0.002219193847849965,
0.020496005192399025,
-0.012880351394414902,
0.0220964215695858,
-0.03721289709210396,
-0.019917646422982216,
-0.010844280011951923,
0.009053290821611881,
-0.01163474004715681,
-0.005703804548829794,
0.024752739816904068,
0.0252763070166111,
0.04725997522473335,
-0.010832148604094982,
-0.012429489754140377,
0.05283496901392937,
-0.005525475833564997,
0.013111275620758533,
0.027349527925252914,
0.00027127060457132757,
0.038692355155944824,
-0.017719103023409843,
0.021263929083943367,
0.027520786970853806,
-0.03325766324996948,
0.05138814076781273,
-0.046567801386117935,
-0.003253459231927991,
-0.011447863653302193,
-0.03052263893187046,
-0.021365230903029442,
-0.0076095787808299065,
0.03302088379859924,
0.022384081035852432,
0.0008594935643486679,
-0.013239157386124134,
-0.02249997667968273,
0.022400574758648872,
-0.009012230671942234,
-0.036175236105918884,
0.017425013706088066,
-0.0008309780969284475,
-0.015089254826307297,
-0.027046672999858856,
-0.02274509146809578,
0.01551139634102583,
0.005844806786626577,
-0.044339947402477264,
-0.021138658747076988,
-0.010770079679787159,
-0.012155596166849136,
-0.0034567241091281176,
0.0198995191603899,
0.013685397803783417,
-0.024530939757823944,
0.023700617253780365,
0.021765321493148804,
-0.05160596966743469,
-0.010788765735924244,
-0.013440519571304321,
-0.0022253375500440598,
0.03570981323719025,
-0.02059727907180786,
0.006988303270190954,
0.02960529923439026,
0.003335832618176937,
-0.000912256829906255,
0.011643950827419758,
0.025801368057727814,
0.02925679460167885,
0.029952125623822212,
-0.02320827730000019,
0.03368286043405533,
0.041380010545253754,
-0.02361140213906765,
0.028304612264037132,
0.017373384907841682,
-0.030222885310649872,
-0.019122419878840446,
0.03741651400923729,
-0.006585633382201195,
-0.00938628800213337,
-0.03477570042014122,
-0.006592799909412861,
0.01496403943747282,
-0.01660054922103882,
-0.011618676595389843,
-0.015811145305633545,
0.025267671793699265,
-0.003204040927812457,
-0.03815842419862747,
-0.02773279882967472,
0.026181835681200027,
0.018249284476041794,
-0.032733555883169174,
0.01677272841334343,
0.006011904217302799,
-0.004959132522344589,
-0.05610094591975212,
0.003761669620871544,
-0.0005116821266710758,
-0.010913866572082043,
0.028704695403575897,
0.013180818408727646,
-0.025852616876363754,
0.00672100530937314,
0.00009665376273915172,
0.002828840631991625,
0.044347863644361496,
0.01453433372080326,
0.0684342160820961,
0.006871610414236784,
0.005107065197080374,
0.0180050116032362,
0.018040984869003296,
-0.028163406997919083,
0.011407436802983284,
0.0061564031057059765,
0.04793115332722664,
-0.0008897701627574861,
0.01671704091131687,
0.015767740085721016,
-0.00647575780749321,
0.003024224890395999,
0.004405317362397909,
-0.0027200765907764435,
0.05533721670508385,
-0.011662266217172146,
0.028934985399246216,
-0.0065947663970291615,
-0.031546421349048615,
0.029162444174289703,
-0.019874421879649162,
-0.01432120893150568,
0.0009124436764977872,
-0.010309278964996338,
-0.04530032351613045,
-0.025008659809827805,
-0.00676724361255765,
0.049890074878931046,
-0.014467529952526093,
-0.01170356385409832,
0.005016044247895479,
0.012627104297280312,
0.018923187628388405,
-0.003197170328348875,
0.028402844443917274,
0.035077787935733795,
0.0160357803106308,
0.007898210547864437,
-0.026202457025647163,
0.040315765887498856,
-0.00023354838776867837,
-0.02483198791742325,
0.03700334206223488,
0.02716650441288948,
0.04258815944194794,
0.02898133546113968,
0.042896904051303864,
0.02944752760231495,
0.011700325645506382,
-0.034713611006736755,
0.0062567018903791904,
0.008759493008255959,
0.012511967681348324,
-0.002872695680707693,
-0.02234908752143383,
0.025352220982313156,
0.03101656585931778,
-0.006449522916227579,
-0.009610564447939396,
-0.012522065080702305,
-0.014947867020964622,
-0.009687003679573536,
-0.019035257399082184,
-0.044268377125263214,
0.04359733313322067,
-0.0314556248486042,
0.0045308000408113,
0.028506122529506683,
-0.009980125352740288,
-0.01977524347603321,
-0.0037161754444241524,
0.01705273427069187,
0.004063611850142479,
0.013589424081146717,
0.015783660113811493,
0.03233290836215019,
-0.012526827864348888,
0.0033680435735732317,
-0.010468105785548687,
-0.03910552337765694,
-0.008762027136981487,
-0.06054304912686348,
0.03869522362947464,
-0.03207780420780182,
-0.013880113139748573,
0.006652290932834148,
-0.004025273956358433,
-0.02319822832942009,
-0.0060272300615906715,
0.036978621035814285,
0.02547847107052803,
0.03744543343782425,
-0.012619607150554657,
0.001091485726647079,
-0.0431617833673954,
-0.017325839027762413,
0.02091629058122635,
-0.008612650446593761,
0.009794897399842739,
0.0169255081564188,
-0.016334693878889084,
-0.05677793547511101,
0.026208622381091118,
-0.01098607201129198,
-0.0026919289957731962,
-0.006212170235812664,
-0.011387604288756847,
0.005648349411785603,
-0.009262312203645706,
0.0034275075886398554,
0.015983618795871735,
-0.011788911186158657,
0.008351655676960945,
-0.018879743292927742,
-0.024564767256379128,
-0.0077303131110966206,
-0.01376186590641737,
0.010838739573955536,
-0.0020184353925287724,
0.02044445462524891,
-0.0016080463537946343,
-0.0006810331251472235,
-0.04457436501979828,
-0.0024778596125543118,
0.023648114874958992,
0.000481947761727497,
0.007502581458538771,
0.038024988025426865,
0.006324377376586199,
0.03585430979728699,
-0.036116622388362885,
0.0050679417327046394,
0.02733481302857399,
-0.0028752507641911507,
-0.04672164469957352,
-0.00591241056099534,
-0.007966848090291023,
0.014528452418744564,
-0.04227480664849281,
-0.015639930963516235,
0.010622281581163406,
-0.003382592462003231,
-0.0062147146090865135,
0.021122518926858902,
0.02908366732299328,
-0.006518184207379818,
0.006628952454775572,
-0.01950116828083992,
0.012098042294383049,
0.00426802271977067,
0.009844888001680374,
-0.01278676651418209,
-0.005931729916483164,
0.026960793882608414,
-0.026061469689011574,
0.03131943941116333,
0.025456160306930542,
0.02304108627140522,
0.009368053637444973,
0.021638689562678337,
-0.025534842163324356,
0.016811711713671684,
0.039847232401371,
0.04113990440964699,
0.00014446346904151142,
-0.0077486648224294186,
-0.01796703413128853,
-0.03610153868794441,
-0.014206556603312492,
0.022526875138282776,
-0.021724559366703033,
0.0020788596011698246,
0.003144223941490054,
0.012381772510707378,
-0.014888129197061062,
-0.002889933530241251,
0.018954021856188774,
0.02693730965256691,
-0.04081578180193901,
0.005760548170655966,
0.0024049566127359867,
0.013364934362471104,
0.015024861320853233,
0.013851234689354897,
-0.012964884750545025,
-0.009954795241355896,
-0.014419157058000565,
-0.002083035185933113,
-0.027972321957349777,
-0.00760001502931118,
-0.016458624973893166,
0.02231466770172119,
0.0001382056507281959,
0.01115837786346674,
0.007970944046974182,
0.04059293493628502,
0.048511531203985214,
-0.00787003431469202,
-0.05067756772041321,
-0.0522736981511116,
0.02297896333038807,
-0.02983430027961731,
0.03281067684292793,
0.027854949235916138,
0.08059531450271606,
0.03082205541431904,
-0.018948977813124657,
0.007419340778142214,
-0.028951261192560196,
-0.026706380769610405,
-0.03137575462460518,
0.01968553476035595,
0.004229397047311068,
0.0018465324537828565,
0.02941233105957508,
-0.06880255788564682,
-0.006304414477199316,
-0.002684905892238021,
-0.003336456138640642,
0.04722562059760094,
0.009747008793056011,
0.0010981078958138824,
0.0018870315980166197,
-0.015068341046571732,
-0.051124632358551025,
-0.03303975984454155,
0.012389356270432472,
0.01937488093972206,
0.020525969564914703,
-0.03290056064724922,
-0.020698199048638344,
-0.008360353298485279,
0.018680041655898094,
-0.031024469062685966,
0.0022462059278041124,
0.04932429641485214,
-0.0015976683935150504,
-0.018856238573789597,
0.02685929462313652,
0.019514234736561775,
-0.04989912733435631,
-0.01679343916475773,
-0.0332542322576046,
-0.006825776305049658,
0.0008859024965204298,
0.019395768642425537,
0.001298365881666541,
0.01678497903048992,
0.005675458814948797,
-0.004742789082229137,
-0.01417581643909216,
-0.0020106725860387087,
-0.04177092760801315,
-0.04210808873176575,
-0.007803240325301886,
0.022123809903860092,
-0.022761961445212364,
-0.04872883856296539,
-0.04299837723374367,
0.002661920851096511
] |
8a550e70bdbd276329aa52d0c840e8979d0e9e43 | 2,113 | py | Python | question.py | Lilium765/momoko | c84b37cbe280055fedaac4ee9195d6410b234aba | [
"MIT"
] | null | null | null | question.py | Lilium765/momoko | c84b37cbe280055fedaac4ee9195d6410b234aba | [
"MIT"
] | null | null | null | question.py | Lilium765/momoko | c84b37cbe280055fedaac4ee9195d6410b234aba | [
"MIT"
] | null | null | null | import discord
client = discord.Client() # 接続に使用するオブジェクト
# 起動時
@client.event
async def on_ready():
print('ログイン成功')
# メッセージを監視
@client.event
async def on_message(message):
# 「/box」が頭についたメッセージならオウム返しする
if message.content.startswith('/box'):
# 文字から「/box」を抜く
question = message.content[len('/box'):].strip()
# 質問させたいチャンネルのid
target_channel_id = getTargetChannelId()
# id=0なら質問者にエラー報告DM
# idが0以外なら匿名質問する
if target_channel_id == 0:
dm = await message.author.create_dm() # 質問者へDM作成
await dm.send(
'Sorry, メッセージを送信できませんでした.'
'もう1度試してみてください.\n'
'【質問文】' + question)
else:
# 匿名質問させたいチャンネル
target_channel = client.get_channel(target_channel_id)
# チャンネルに質問メッセージ送信
await target_channel.send(question)
# 匿名質問させたいチャンネルのidを取得
# 指定したカテゴリにある最初のTextチャンネル=質問させたいチャンネルとみなす
# ただしカテゴリにチャンネルが無い時は0を返す
def getTargetChannelId() -> int:
# 質問させたいチャンネル(対象チャンネル)
target_channel = {'id': 0, 'position': 99999999}
# ***********************************************************
# 指定カテゴリ(対象チャンネルが含まれたカテゴリ)の名前
category_id = 711238137598181396 # カテゴリidを指定
target_category_name = client.get_channel(category_id).name
# ***********************************************************
# 指定したサーバにある全てのTextチャンネル一覧
all_channels = client.get_guild(602423784946925568).text_channels
# 全てのTextチャンネルから「指定カテゴリに属する最初のチャンネル」を探す
for channel in all_channels:
# 指定カテゴリに属する場合だけ対象チャンネル候補とみなす
if str(channel.category) == target_category_name:
# positionが小さいほうを「より対象チャンネルに近い」として交換
# 初期値はpositionが大きい(99999999)ので,必ず入れ替わる想定
# 繰り返せば,最後にはpositionが最も小さいチャンネルを代入できる
if target_channel['position'] > int(channel.position):
target_channel['id'] = int(channel.id)
target_channel['position'] = int(channel.position)
# 最終的に代入されたidを返す
return target_channel['id']
# botとしてDiscordに接続(botのトークンを指定)
client.run('605042341715378176')
| 30.623188 | 69 | 0.618552 | 1 | 1.9671 | [
0.0017622556770220399,
0.026404159143567085,
0.0068703582510352135,
-0.0025755767710506916,
0.002711213193833828,
-0.003171762451529503,
-0.011209907941520214,
0.004262780304998159,
-0.007348243147134781,
0.0026239340659230947,
0.001591815846040845,
0.00582249416038394,
0.006795196328312159,
-0.01925809681415558,
0.0011745189549401402,
0.015606820583343506,
-0.05312145873904228,
-0.0007705660536885262,
-0.0037523715291172266,
0.0010963536333292723,
-0.008070561103522778,
0.008776126429438591,
0.007800987455993891,
0.005122649483382702,
0.006823899690061808,
0.0026982231065630913,
0.01120761875063181,
0.003114584367722273,
-0.009500976651906967,
-0.00695499312132597,
0.0012411861680448055,
-0.00030178658198565245,
-0.006859711371362209,
-0.008771131746470928,
0.003952843602746725,
-0.0028126025572419167,
-0.002247919561341405,
-0.020017728209495544,
0.014093222096562386,
-0.004236625973135233,
-0.0074214325286448,
-0.015459815971553326,
0.0005672336556017399,
0.007317510899156332,
-0.009632987901568413,
-0.0003163847723044455,
-0.004467575810849667,
0.0011617264244705439,
-0.009131116792559624,
0.00539341801777482,
-0.007352145854383707,
0.006765334866940975,
0.010859517380595207,
0.0030528628267347813,
-0.004134143237024546,
-0.005881857592612505,
0.013308071531355381,
0.0003202759544365108,
-0.011138188652694225,
-0.0025864308699965477,
-0.0034152159933000803,
-0.0011149998754262924,
0.006495647132396698,
0.0026743330527096987,
-0.019157197326421738,
-0.007602647412568331,
-0.005281710997223854,
0.004893918987363577,
-0.0006593195139430463,
0.005207074340432882,
0.0019158453214913607,
-0.00005366600817069411,
0.006422220263630152,
0.004388532135635614,
0.004075151868164539,
-0.0058401161804795265,
-0.0017621384467929602,
0.0008096648380160332,
0.007148670498281717,
0.0035866769030690193,
0.003808818757534027,
-0.00739906495437026,
0.006656796205788851,
0.00975676067173481,
0.013865168206393719,
0.009985808283090591,
0.018949467688798904,
-0.0109999505802989,
0.046424929052591324,
0.00847257487475872,
-0.008858276531100273,
0.0011658179573714733,
-0.00954514741897583,
-0.0023903183173388243,
-0.002601076615974307,
-0.02682020328938961,
0.00004979089862899855,
-0.004208761733025312,
-0.0013333692913874984,
0.0027885318268090487,
0.00037507101660594344,
0.008828068152070045,
0.0002685414219740778,
-0.0014095514779910445,
-0.006788837257772684,
0.01309614721685648,
-0.008504018187522888,
-0.004293488338589668,
0.007284254767000675,
0.00337238353677094,
-0.010164497420191765,
0.000024735223632887937,
0.0029683285392820835,
-0.01023116149008274,
0.0042226556688547134,
0.003260507946833968,
-0.004596707411110401,
0.05581790581345558,
-0.001266484847292304,
0.00399389723315835,
-0.006887497846037149,
-0.0005720075569115579,
0.0019360787700861692,
0.005856696050614119,
0.008274951949715614,
-0.0025735090021044016,
0.009435505606234074,
0.00894179753959179,
0.003805997082963586,
0.008873729035258293,
-0.0024412230122834444,
0.00572641845792532,
-0.0035831781569868326,
-0.0004822846967726946,
0.0020394877064973116,
-0.008895805105566978,
0.0077754235826432705,
-0.0009785874281078577,
-0.00574344489723444,
0.0011082683922722936,
0.00201076315715909,
-0.010366667062044144,
0.005002409219741821,
-0.00468077277764678,
0.0021478489506989717,
-0.011109001003205776,
-0.00363611476495862,
-0.004783538170158863,
-0.003268528962507844,
0.00008887586591299623,
0.010050243698060513,
0.004326208028942347,
0.0019795759581029415,
-0.004608538001775742,
-0.008404516614973545,
-0.00029789682594127953,
-0.0033330463338643312,
0.001034395769238472,
0.007678614463657141,
0.002928968518972397,
-0.008709602989256382,
-0.0033919047564268112,
0.0033087567426264286,
-0.0003613696899265051,
-0.0010945730609819293,
0.001342176808975637,
-0.0070684608072042465,
0.007002540864050388,
-0.0024289172142744064,
0.005115363746881485,
0.010380994528532028,
-0.004460514057427645,
-0.0015392786590382457,
-0.0006186289247125387,
-0.0002828634169418365,
-0.0013632255140691996,
0.003368663601577282,
0.011420651338994503,
-0.004962967708706856,
-0.0028667673468589783,
0.0030540102161467075,
0.004644463770091534,
0.007997025735676289,
0.0034623348619788885,
-0.00276059377938509,
0.00239447969943285,
-0.00574572803452611,
-0.0006169272237457335,
0.006083237938582897,
-0.0009869169443845749,
0.005441548302769661,
0.004133066162467003,
-0.01206390280276537,
-0.009379051625728607,
0.00026827165856957436,
-0.007063201628625393,
0.0024187457747757435,
0.011473631486296654,
0.010791243985295296,
-0.005033509340137243,
0.0010002730414271355,
-0.00691149802878499,
0.0019778339192271233,
0.009121485985815525,
0.0014589971397072077,
-0.013071105815470219,
-0.9594625234603882,
0.006109323818236589,
0.001587512670084834,
-0.0025036241859197617,
0.006217463873326778,
0.0009959922172129154,
0.005914515815675259,
0.0025334798265248537,
0.012749397195875645,
-0.010603315196931362,
-0.007675680797547102,
-0.009678085334599018,
-0.01098831370472908,
-0.002417841227725148,
-0.009567885659635067,
-0.0031386124901473522,
-0.006791878491640091,
-0.00820999126881361,
-0.0010367376962676644,
-0.0022512399591505527,
-0.002147806342691183,
0.01029502134770155,
-0.0009808281902223825,
0.005139370448887348,
0.0077544525265693665,
0.0011630961671471596,
-0.005374483298510313,
-0.0030628859531134367,
-0.0028379003051668406,
-0.0008674188866280019,
-0.005112353712320328,
-0.01485029049217701,
-0.007075231522321701,
-0.000008938820428738836,
0.010904527269303799,
-0.00029738599550910294,
0.007388260215520859,
-0.004194491542875767,
0.002024350455030799,
-0.007781461346894503,
0.00585757102817297,
0.000312597316224128,
0.003843366401270032,
-0.026765575632452965,
0.002460738178342581,
-0.0002837575157172978,
-0.009147979319095612,
0.008856317028403282,
-0.0002548484189901501,
-0.0027099065482616425,
-0.004014302510768175,
-0.006630849093198776,
0.006745903752744198,
-0.005452761426568031,
0.0037059502210468054,
-0.005030646454542875,
-0.008815237320959568,
-0.0025411052629351616,
-0.010429391637444496,
0.002930243033915758,
0.003467437345534563,
-0.004490116145461798,
-0.002724312711507082,
-0.005853900220245123,
0.0033437663223594427,
0.0031244694255292416,
0.0020120316185057163,
-0.017391225323081017,
-0.006944380700588226,
0.00014314900909084827,
0.0025449986569583416,
-0.004847283009439707,
-0.004414098337292671,
0.006003673188388348,
-0.009008697234094143,
0.005777412559837103,
0.0022879845928400755,
0.0009796021040529013,
-0.013583182357251644,
-0.0016555074835196137,
-0.010031314566731453,
-0.0093605425208807,
0.0018188883550465107,
-0.0044344826601445675,
-0.0028701121918857098,
-0.0001119198786909692,
-0.0007896479801274836,
0.005898507311940193,
-0.005408431403338909,
0.0028947696555405855,
0.007883011363446712,
-0.004145657178014517,
-0.009592143818736076,
0.007373189087957144,
0.006363087799400091,
0.0014733370626345277,
-0.001365767908282578,
0.004849133547395468,
0.00843746680766344,
0.007990358397364616,
0.002402643673121929,
0.003964993171393871,
0.002629533875733614,
0.008473305031657219,
-0.0020163431763648987,
0.0014130151830613613,
-0.00109079759567976,
0.0004885683301836252,
-0.004974093288183212,
0.0021671676076948643,
-0.002633534837514162,
-0.0020628822967410088,
-0.012192409485578537,
-0.010926719754934311,
-0.004234923981130123,
0.00020070654863957316,
0.002498259302228689,
-0.00455876300111413,
0.00048396451165899634,
0.002633665921166539,
0.006122687365859747,
0.00031268963357433677,
-0.005006093997508287,
-0.0016124368412420154,
0.0016364986076951027,
-0.006280046422034502,
0.014397695660591125,
-0.010504135861992836,
0.006484016310423613,
-0.0037488380912691355,
-0.01560631487518549,
0.004882491193711758,
0.007848341949284077,
-0.010530094616115093,
0.00133582076523453,
0.003437145845964551,
0.005266639869660139,
0.0017772708088159561,
-0.0022457456216216087,
-0.0053858975879848,
-0.016561144962906837,
-0.00043576760799624026,
0.01829046569764614,
0.0030558034777641296,
0.010989599861204624,
0.012335468083620071,
-0.00451389467343688,
0.003940977156162262,
0.002272161887958646,
0.003022808115929365,
0.01178526971489191,
-0.009107339195907116,
-0.00023135913943406194,
0.0009791201446205378,
-0.0048841149546206,
0.0013314886018633842,
0.004544089548289776,
0.005608842708170414,
-0.00528319738805294,
0.0013002051273360848,
-0.00611313059926033,
-0.003197978250682354,
-0.015802673995494843,
-0.002553831785917282,
0.0062089953571558,
-0.00599298719316721,
0.006088150665163994,
-0.013818453066051006,
0.005711134523153305,
0.006965381093323231,
0.0023644890170544386,
-0.0010052970610558987,
0.00018580243340693414,
0.006210041232407093,
0.011435415595769882,
-0.004376695025712252,
0.002824142575263977,
0.0019458101596683264,
0.0001442049106117338,
-0.0008001024252735078,
0.008168649859726429,
-0.008173045702278614,
-0.006766430102288723,
0.0031028452794998884,
0.005678481422364712,
0.0021849623881280422,
-0.004421957768499851,
-0.009442591108381748,
-0.002975450363010168,
0.004394209943711758,
-0.006540034431964159,
0.004727593157440424,
-0.001958962297067046,
0.004587335046380758,
-0.006817972287535667,
-0.0006449578795582056,
0.0011864777188748121,
-0.01321603637188673,
0.007961596362292767,
-0.002229846315458417,
0.004684895742684603,
0.014484365470707417,
0.0038123885169625282,
-0.01419501006603241,
0.00548333115875721,
0.007596640847623348,
-0.005230702925473452,
0.004939427599310875,
0.003404987044632435,
-0.006355223711580038,
-0.020233742892742157,
-0.0011609588982537389,
-0.014462048187851906,
0.00706499395892024,
-0.0005771548603661358,
0.003433366771787405,
-0.0073912059888243675,
0.006916487589478493,
0.006567991804331541,
-0.012385262176394463,
-0.0059949662536382675,
-0.008536003530025482,
0.008114874362945557,
0.001882228534668684,
-0.000993314664810896,
-0.0034988238476216793,
-0.0005798369529657066,
-0.0027222188655287027,
-0.003558920929208398,
-0.0011532158823683858,
0.0056534442119300365,
0.001778342411853373,
-0.0027048035990446806,
0.0015845977468416095,
-0.002457043621689081,
0.0012448490597307682,
0.002151018939912319,
-0.010108002461493015,
0.003023562952876091,
0.005375380627810955,
-0.0029293722473084927,
-0.00337713910266757,
0.003039833391085267,
-0.002298956038430333,
-0.0067375944927334785,
-0.010076716542243958,
-0.002582024782896042,
-0.0042062001302838326,
-0.00240359571762383,
-0.012377921491861343,
-0.002367854118347168,
-0.011928305961191654,
0.005248808767646551,
-0.007135164923965931,
0.009995287284255028,
0.005015490110963583,
-0.007121905218809843,
0.006491254549473524,
-0.0022666482254862785,
0.003787924535572529,
0.0026797200553119183,
0.0043532345443964005,
-0.00006628993287449703,
-0.005067336373031139,
-0.009533713571727276,
0.01258526649326086,
-0.008773420006036758,
0.0008282473427243531,
0.011772943660616875,
0.004754329100251198,
0.007955827750265598,
0.0015204965602606535,
0.0003156090388074517,
0.0020898112561553717,
0.007998602464795113,
-0.012866711243987083,
0.0037579720374196768,
-0.0036443204153329134,
0.002543568378314376,
0.003715804312378168,
-0.0037046230863779783,
0.0032716430723667145,
0.00801199022680521,
0.0002754863235168159,
-0.006910459138453007,
-0.0011237671133130789,
0.0016042479546740651,
0.005240478552877903,
-0.010710148140788078,
0.001130531425587833,
-0.005775391589850187,
-0.003308877581730485,
-0.004303937777876854,
-0.00458246935158968,
-0.000749147729948163,
0.005388123448938131,
-0.003251478774473071,
0.005751512944698334,
0.0015080245211720467,
-0.004050955176353455,
0.014747574925422668,
-0.007396983448415995,
-0.004084590822458267,
0.003361265640705824,
0.0003231335140299052,
-0.0013048734981566668,
-0.006900784559547901,
-0.001127101480960846,
0.0013240502448752522,
0.005839263554662466,
-0.004568932112306356,
-0.005432354751974344,
-0.0023755456786602736,
0.0013305017491802573,
-0.010128128342330456,
0.0012767737498506904,
0.01148440781980753,
-0.005642639007419348,
0.005867331754416227,
-0.0007367797079496086,
-0.005497610662132502,
-0.013407062739133835,
0.054688192903995514,
-0.002360976068302989,
0.0032094730995595455,
0.005553994793444872,
-0.007778178434818983,
0.000802647031378001,
-0.0019239020766690373,
0.007520341780036688,
-0.0054923840798437595,
-0.008050964213907719,
0.007658170536160469,
-0.0023715421557426453,
0.006116439122706652,
0.002255075378343463,
-0.00039856191142462194,
0.014966242015361786,
-0.0049644033424556255,
-0.01620764657855034,
-0.015919240191578865,
0.006796773057430983,
-0.003477629506960511,
-0.007187838666141033,
0.008088531903922558,
-0.0014170878566801548,
-0.003213148331269622,
0.0005120319547131658,
0.007004519924521446,
-0.0005665054777637124,
0.0006511167157441378,
-0.0030729605350643396,
0.00024037924595177174,
-0.001188228139653802,
0.0035113657359033823,
0.006099523976445198,
0.008730107918381691,
-0.002360250800848007,
0.0033324372489005327,
-0.003136086743324995,
-0.002456067595630884,
-0.0015856105601415038,
0.003786676097661257,
0.007185801398009062,
-0.0004144685226492584,
0.0007252694922499359,
0.005233392119407654,
0.005760679021477699,
0.0031147815752774477,
0.009532658383250237,
-0.0012404167791828513,
-0.005635243374854326,
0.009331782348453999,
0.008501182310283184,
0.0006170478882268071,
0.008099422790110111,
-0.0018671004800125957,
0.005959568079560995,
0.0025388228241354227,
-0.006423074286431074,
-0.016419941559433937,
-0.0005201741005294025,
0.007626404520124197,
0.008099250495433807,
-0.0030578463338315487,
0.0015976452268660069,
-0.00406419625505805,
0.000104200400528498,
-0.0076885283924639225,
-0.00938321091234684,
-0.0006558840395882726,
0.003272648435086012,
0.005575749557465315,
0.07069343328475952,
-0.00667828693985939,
-0.00123923912178725,
-0.007842103950679302,
-0.0014195175608620048,
-0.0020137012470513582,
-0.0000609239395998884,
-0.002971233334392309,
-0.002068241825327277,
0.0006221183575689793,
0.004217594396322966,
-0.0075241560116410255,
-0.011378354392945766,
0.0009755701757967472,
0.0022232457995414734,
-0.005150039214640856,
0.003196130972355604,
0.006079625338315964,
-0.008007884956896305,
0.0021081308368593454,
-0.011210993863642216,
-0.0017129116458818316,
-0.0030954706016927958,
-0.00968845933675766,
-0.004726743325591087,
-0.00489405170083046,
0.005698427092283964,
0.004369849804788828,
0.007735592778772116,
-0.004236096516251564,
0.0043809921480715275,
-0.0032127320300787687,
0.002013149671256542,
-0.003196835285052657,
0.0018323996337130666,
-0.0063767386600375175,
0.006305895280092955,
0.0022622141987085342,
-0.011292967014014721,
-0.006204664241522551,
-0.00018843186262529343,
-0.0008069004397839308,
-0.006566197145730257,
0.0034221357200294733,
0.0007887815590947866,
0.005510665476322174,
-0.002880909712985158,
0.0005056931986473501,
-0.0062909359112381935,
0.0012566150398924947,
-0.013549699448049068,
0.0037260304670780897,
-0.16970959305763245,
0.00807262770831585,
0.005697064101696014,
-0.005753743927925825,
-0.002132596680894494,
-0.012399011291563511,
-0.005124444607645273,
0.0029831859283149242,
0.010368971154093742,
0.002939579775556922,
0.00021962870960123837,
-0.00046524315257556736,
0.005811311770230532,
0.0018728725844994187,
-0.00042897253297269344,
-0.003429396776482463,
0.0038181128911674023,
-0.002782054478302598,
0.00044399351463653147,
0.0034643448889255524,
0.0027992771938443184,
0.009262386709451675,
0.0008393608150072396,
0.0006851087091490626,
-0.0010362203465774655,
-0.005999790504574776,
0.00456574372947216,
-0.003709534415975213,
0.007286964450031519,
-0.013065318576991558,
-0.003911892417818308,
-0.0027335388585925102,
-0.0029500077944248915,
0.0013469720724970102,
0.005596045404672623,
-0.003062109462916851,
0.0073531921952962875,
0.0022746860049664974,
-0.006468601990491152,
0.007523357402533293,
-0.007427634205669165,
0.029355015605688095,
0.0038237369153648615,
0.008818281814455986,
0.0022036470472812653,
-0.006149937864392996,
-0.004418717697262764,
0.01012495718896389,
0.003968909848481417,
0.012473726645112038,
-0.011308028362691402,
-0.0004191920452285558,
0.003022067481651902,
0.018940282985568047,
-0.002558025997132063,
-0.009606719017028809,
-0.006785158533602953,
-0.004012882709503174,
0.0020518717356026173,
0.00863126665353775,
0.009727798402309418,
-0.0030994222033768892,
0.007033656816929579,
-0.0031179282814264297,
-0.021642843261361122,
0.0038985703140497208,
-0.004129368346184492,
-0.005038401111960411,
0.002410049084573984,
0.006986214313656092,
0.009029506705701351,
-0.001520133693702519,
0.0029776766896247864,
0.0014244650956243277,
0.0041933744214475155,
0.0010070186108350754,
0.005712019745260477,
-0.0024867872707545757,
0.004901347681879997,
-0.008083769120275974,
0.006943142972886562,
-0.008613264188170433,
-0.002640900667756796,
0.002565317787230015,
-0.005102021619677544,
0.010155284777283669,
0.00443619629368186,
-0.0028352977242320776,
-0.00018068525241687894,
-0.010771451517939568,
0.00011215500126127154,
0.0033811768516898155,
0.0011441325768828392,
-0.011080867610871792,
0.00412969384342432,
-0.0010731588117778301,
0.0031394432298839092,
0.0075386459939181805,
-0.009886248968541622,
0.0036632483825087547,
0.004161135759204626,
-0.006573597434908152,
0.00031663011759519577,
-0.0024256666656583548,
0.0028775723185390234,
0.004794152919203043,
-0.005809325259178877,
-0.005531178321689367,
0.0010109884897246957,
-0.007619945798069239,
-0.0041567240841686726,
0.007365019991993904,
-0.010018840432167053,
-0.008911964483559132,
-0.0024922383017838,
-0.01273523923009634,
0.0007273636292666197
] |
8a5581cd0e7ff399dcb5faaf23430dc8e5e4058e | 4,370 | py | Python | figure_code/rate_of_change_tc.py | DavisWeaver/fears | 857cb959a3a111a41df4cf62c4c6a19d3abd33c0 | [
"MIT"
] | null | null | null | figure_code/rate_of_change_tc.py | DavisWeaver/fears | 857cb959a3a111a41df4cf62c4c6a19d3abd33c0 | [
"MIT"
] | null | null | null | figure_code/rate_of_change_tc.py | DavisWeaver/fears | 857cb959a3a111a41df4cf62c4c6a19d3abd33c0 | [
"MIT"
] | 1 | 2021-11-09T14:42:01.000Z | 2021-11-09T14:42:01.000Z | import matplotlib.pyplot as plt
import numpy as np
from fears.utils import results_manager, plotter, dir_manager
import os
suffix = '07212021_0001'
data_folder = 'results_' + suffix
exp_info_file = 'experiment_info_' + suffix + '.p'
exp_folders,exp_info = results_manager.get_experiment_results(data_folder,
exp_info_file)
max_cells = exp_info.populations[0].max_cells
n_sims = exp_info.n_sims
k_abs = exp_info.slopes
exp_folders.reverse()
k_abs = np.flip(k_abs)
fig,ax = plt.subplots(nrows=2,ncols=2,figsize=(4,4))
pop = exp_info.populations[0]
ax = ax.reshape((len(k_abs),))
axnum = 0
tc_axes=[]
drug_axes=[]
for exp in exp_folders:
k_abs_t = exp[exp.find('=')+1:]
k_abs_t = float(k_abs_t)
num = np.argwhere(k_abs == k_abs_t)
num = num[0,0]
# generate timecourse axes
tcax = ax[axnum]
# da = tcax.twinx()
sim_files = os.listdir(path=exp)
sim_files = sorted(sim_files)
survive_count = 0
counts_total = None
k=0
while k < len(sim_files):
# for sim in sim_files:
sim = sim_files[k]
sim = exp + os.sep + sim
data = results_manager.get_data(sim)
dc = data[:,-1]
data = data[:,0:-1]
# data = data/np.max(data)
data_t = data[-1,:]
# check to see if any genotypes are at least 10% of the max cell count
if any(data_t >= 1):
survive_count += 1
if counts_total is None:
counts_total = data
else:
counts_total += data
# data = data/np.max(data)
# exp_info.populations[num].counts_log_scale = True
data = data/max_cells
if k==0:
drug_kwargs = {'alpha':0.7,
'color':'black',
'linewidth':2,
'label':'Drug Concentration ($\u03BC$M)'
}
tcax,drug_ax = plotter.plot_timecourse_to_axes(exp_info.populations[num],
data,
tcax,
drug_curve=dc,
drug_ax_sci_notation=True,
drug_kwargs=drug_kwargs,
legend_labels=False,
grayscale=True,
color='gray',
linewidth=1,
labelsize=12,
alpha=0.7
)
drug_ax.set_ylabel('')
drug_axes.append( drug_ax )
else:
tcax,da = plotter.plot_timecourse_to_axes(exp_info.populations[num],
data,
tcax,
grayscale=True,
color='gray',
legend_labels=False,
linewidth=2,
labelsize=12,
alpha=0.2
)
# drug_ax.set_ylim(0,10**4)
k+=1
if survive_count > 0:
counts_avg = counts_total/survive_count
# counts_avg = counts_avg/np.max(counts_avg)
# counts_avg = counts_total
counts_avg = counts_avg/np.max(counts_avg)
tcax,temp = plotter.plot_timecourse_to_axes(exp_info.populations[num],
counts_avg,
tcax,
labelsize=12)
# t = np.arange(len(dc))
# t = t*exp_info.populations[0].timestep_scale/24
# da.plot(t,dc)
tc_axes.append( tcax )
axnum+=1 | 37.350427 | 85 | 0.415103 | 1 | 1.7661 | [
0.0006683396641165018,
0.020111411809921265,
0.008400516584515572,
0.00396568002179265,
0.005120113957673311,
-0.0015026830369606614,
-0.005273659713566303,
-0.00040937389712780714,
-0.007576938718557358,
0.004703974816948175,
0.001798727666027844,
0.007240287493914366,
0.006225987337529659,
-0.014892565086483955,
-0.0005722223431803286,
0.015770038589835167,
-0.05012189596891403,
-0.002919265767559409,
-0.0012345545692369342,
0.0016443576896563172,
-0.0070142680779099464,
0.008622395806014538,
0.009883169084787369,
0.004040209110826254,
0.005419482942670584,
-0.004931135568767786,
0.007994800806045532,
0.00047477890620939434,
-0.010162224993109703,
-0.005029288120567799,
-0.002602932509034872,
-0.0012014671228826046,
-0.004000016953796148,
-0.005318660754710436,
0.002710141707211733,
-0.006433987058699131,
-0.0020444083493202925,
-0.01889886148273945,
0.00981423445045948,
-0.0034427540376782417,
-0.0026059309020638466,
-0.010755100287497044,
-0.00034718739334493876,
-0.001832446432672441,
-0.008758066222071648,
0.004955700132995844,
-0.0046630194410681725,
0.00047070212895050645,
-0.01244724728167057,
0.005331919062882662,
-0.005045756231993437,
0.005056886933743954,
0.015368214808404446,
0.0016916054300963879,
-0.006466594524681568,
-0.006501900032162666,
0.014672387391328812,
0.002327113412320614,
-0.00925060361623764,
0.00012428610352799296,
-0.0017646991182118654,
-0.0034145622048527002,
0.004876697435975075,
0.002285691909492016,
-0.011767148971557617,
-0.0057028657756745815,
-0.006308302283287048,
-0.0015894346870481968,
-0.0027787541039288044,
0.0043329717591404915,
0.0010394513374194503,
0.0010665424633771181,
0.005126466974616051,
0.007200102787464857,
0.00481892004609108,
-0.004368877504020929,
0.00029941785032860935,
0.0005089761107228696,
0.009811150841414928,
0.003281987737864256,
0.0029233829118311405,
-0.002694800030440092,
0.005078661721199751,
0.008926558308303356,
0.013407736085355282,
0.01075882837176323,
0.016396187245845795,
-0.012101068161427975,
0.048135701566934586,
0.008062529377639294,
-0.009300732053816319,
0.005375910084694624,
-0.013071652501821518,
-0.0036447769962251186,
-0.007946542464196682,
-0.02600514516234398,
0.0011027822038158774,
-0.004008950665593147,
0.0013415493303909898,
0.003824942046776414,
0.0008610911318100989,
0.008363250643014908,
0.0019078385084867477,
-0.00226958142593503,
-0.009590060450136662,
0.005207578651607037,
-0.011173835024237633,
-0.004457542207092047,
0.006636493839323521,
0.0027586231008172035,
-0.011593129485845566,
-0.00004569334487314336,
-0.00024009817570913583,
-0.014135338366031647,
0.0013979156501591206,
0.006461623124778271,
-0.005316769704222679,
0.04999207705259323,
0.00011329584958730265,
0.00770320650190115,
-0.004863505717366934,
0.0014544647419825196,
-0.0006937049911357462,
0.0026951951440423727,
0.010541251860558987,
-0.000041893676097970456,
0.010026875883340836,
0.002852358855307102,
0.003020079107955098,
0.010509485378861427,
-0.0045869434252381325,
0.0034663446713238955,
-0.0022935164161026478,
-0.001461887382902205,
-0.0027338634245097637,
-0.005993449129164219,
0.005112167447805405,
-0.0033921117428690195,
-0.0116495992988348,
0.003496312303468585,
-0.003420688444748521,
-0.0069535039365291595,
-0.0004063267260789871,
-0.0032765704672783613,
0.009601675905287266,
-0.012033574283123016,
-0.0026062973774969578,
-0.0028616872150450945,
-0.006534362677484751,
0.001796657801605761,
0.010365479625761509,
0.004648711532354355,
0.0022153733298182487,
-0.004970904439687729,
-0.009197906590998173,
0.003325794357806444,
-0.005250499118119478,
-0.002211015671491623,
0.005530661437660456,
0.0060995048843324184,
-0.013087179511785507,
0.002545885508880019,
0.0016085993265733123,
0.001053893007338047,
-0.002650744980201125,
0.005987620912492275,
-0.005809021182358265,
0.0071972450241446495,
-0.0008800513460300863,
0.0044194795191287994,
0.013797719962894917,
-0.0025769260246306658,
0.00026992277707904577,
-0.0000010221817774436204,
0.002024794463068247,
0.0013372079702094197,
0.008681272156536579,
0.01115232054144144,
-0.0018039746209979057,
-0.005346287041902542,
0.008119617588818073,
0.00513873714953661,
0.007220476865768433,
0.0024948581121861935,
-0.0027720769867300987,
-0.00003829464549198747,
-0.005205158609896898,
-0.004096117336302996,
0.0083705373108387,
-0.0073670558631420135,
0.005542803555727005,
0.0016877450980246067,
-0.013527262024581432,
-0.009228413924574852,
-0.002771375235170126,
-0.005833479110151529,
0.002045420929789543,
0.013737166300415993,
0.01529333833605051,
-0.004637954756617546,
0.0031498465687036514,
-0.013319876044988632,
0.0005124884773977101,
0.01127285324037075,
-0.00008412409079028293,
-0.00993733573704958,
-0.9610792994499207,
0.010476094670593739,
0.0049059740267694,
-0.003675957443192601,
0.005334558431059122,
0.0011486423900350928,
0.0010481656063348055,
0.0046692159958183765,
0.01320465188473463,
-0.00488667469471693,
-0.0030261881183832884,
-0.010168257169425488,
-0.012850165367126465,
-0.0013639325043186545,
-0.01088193990290165,
-0.0035102302208542824,
-0.0054403673857450485,
-0.005433843471109867,
-0.005189939867705107,
-0.001500195125117898,
-0.0035860829520970583,
0.005104235839098692,
-0.001929453224875033,
0.003135771956294775,
-0.00032975609065033495,
0.004258996341377497,
-0.0013071225257590413,
-0.0017221561865881085,
-0.0004083749372512102,
-0.0025715550873428583,
-0.007621135096997023,
-0.012362931855022907,
-0.0003119499306194484,
-0.0030625464860349894,
0.007853853516280651,
0.004258796107023954,
0.007960802875459194,
-0.0032814021687954664,
0.002796463668346405,
-0.010017425753176212,
0.005059231538325548,
0.0005169121432118118,
0.0014542941935360432,
-0.030735962092876434,
0.00017330076661892235,
0.0022868607193231583,
-0.008295002393424511,
0.008860153146088123,
0.0017620321596041322,
-0.00041194839286617935,
-0.005168778821825981,
-0.004548053257167339,
0.009847798384726048,
-0.004626779351383448,
0.0057151103392243385,
-0.0014329437399283051,
-0.01003055926412344,
-0.0033750038128346205,
-0.003059962997213006,
0.003598014824092388,
0.004959541372954845,
-0.0013183136470615864,
-0.0020062385592609644,
-0.007985861971974373,
0.0012826130259782076,
0.0004144844424445182,
0.002835767110809684,
-0.02156952954828739,
-0.012303084135055542,
0.002849786775186658,
0.0014385513495653868,
-0.00040940489270724356,
-0.00491314334794879,
0.004509951453655958,
-0.007620563730597496,
0.004902191925793886,
0.003025626065209508,
0.0020772533025592566,
-0.0101653216406703,
-0.0021253316663205624,
-0.011918977834284306,
-0.006964296568185091,
0.0012324334820732474,
-0.003216672223061323,
-0.006425025407224894,
-0.0004456105234567076,
0.0007411142578348517,
0.006556383334100246,
-0.0037765675224363804,
0.0043247961439192295,
0.008213798515498638,
-0.0002868890587706119,
-0.006992092356085777,
0.005703722592443228,
0.007012048736214638,
0.002963948529213667,
-0.0002704320359043777,
0.004573350306600332,
0.003881626296788454,
0.010490032844245434,
0.003174275392666459,
0.009012274444103241,
0.0032190626952797174,
0.014570205472409725,
-0.0025979892816394567,
-0.0036048400215804577,
-0.008276739157736301,
-0.00021477308473549783,
-0.004357591737061739,
0.0009619143675081432,
-0.007989627309143543,
-0.002322417451068759,
-0.012736638076603413,
-0.008692590519785881,
-0.0006531500839628279,
-0.002164185978472233,
0.005098389927297831,
-0.007903986610472202,
-0.004111954942345619,
0.0020024580880999565,
0.006210084073245525,
0.0002873198827728629,
-0.003520890837535262,
-0.0013612080365419388,
0.002600481966510415,
-0.005487809889018536,
0.015092183835804462,
-0.011739728040993214,
0.007729638833552599,
0.003049468854442239,
-0.015581339597702026,
0.002545909956097603,
0.01041480340063572,
-0.006983176805078983,
0.00028445915086194873,
0.0014455501222983003,
0.0013739489950239658,
-0.004256739281117916,
-0.0018178882310166955,
-0.0004915370373055339,
-0.01616751030087471,
0.000790894846431911,
0.018572470173239708,
-0.002127331215888262,
0.009656410664319992,
0.008207674138247967,
-0.0037546874955296516,
0.0004403628408908844,
0.006599025800824165,
-0.0007628665189258754,
0.011963299475610256,
-0.008717636577785015,
-0.0011986010940745473,
0.001347778714261949,
-0.00724098552018404,
0.002028962131589651,
0.00868956558406353,
0.004217108711600304,
-0.001319698872976005,
0.0058496491983532906,
-0.005165548995137215,
-0.005640621297061443,
-0.015047941356897354,
-0.00758355762809515,
0.007635688874870539,
-0.002479926683008671,
0.006295043509453535,
-0.012910404242575169,
0.0040679131634533405,
0.00118395802564919,
0.009933189488947392,
0.001158139668405056,
0.0009008130291476846,
0.005521722137928009,
0.01171390525996685,
-0.006142082158476114,
-0.0008003495167940855,
0.006221989169716835,
-0.0012530649546533823,
-0.00348391174338758,
0.007973924279212952,
-0.006173447240144014,
-0.004049035720527172,
0.000408261053962633,
0.005099462810903788,
-0.0003805826709140092,
-0.00039750346331857145,
-0.009419874288141727,
-0.004074206575751305,
0.004225695040076971,
-0.008123335428535938,
0.0013654049253091216,
0.0018766801804304123,
0.004094787873327732,
-0.006069718394428492,
-0.00263611669652164,
-0.005389655474573374,
-0.009557732380926609,
0.012093756347894669,
-0.004054313059896231,
0.003859615419059992,
0.018043171614408493,
0.007197183556854725,
-0.012905905023217201,
0.0060169086791574955,
0.008525116369128227,
-0.002928438363596797,
0.0035823818761855364,
0.005628223065286875,
-0.003899914911016822,
-0.02144305221736431,
-0.004759343806654215,
-0.008962376974523067,
0.0037062412593513727,
-0.0032462282106280327,
0.008027945645153522,
-0.005129254423081875,
0.0025095795281231403,
0.00589933805167675,
-0.014966783113777637,
-0.007642708253115416,
-0.008948936127126217,
0.009184201247990131,
0.002497520763427019,
0.0031485373619943857,
-0.002253635786473751,
-0.002130425302311778,
-0.0005875963834114373,
-0.0039719888009130955,
-0.004861305933445692,
0.005324982106685638,
0.000013212019439379219,
-0.0025182703975588083,
0.0011327584506943822,
-0.0020939474925398827,
0.00010044262307928875,
-0.00010189868044108152,
-0.006547829136252403,
0.004352264106273651,
-0.0003752470074687153,
-0.0007960420334711671,
-0.0027873804792761803,
0.004659302998334169,
-0.001889867358841002,
-0.01119592972099781,
-0.01042124256491661,
-0.003947223536670208,
-0.0025436091236770153,
-0.005163845606148243,
-0.009096874855458736,
-0.004129728768020868,
-0.006574744358658791,
0.006274181418120861,
-0.00749078718945384,
0.008733680471777916,
0.010610128752887249,
-0.005784953013062477,
0.005975825246423483,
-0.0006449190550483763,
0.006131155416369438,
0.0032648162450641394,
0.0037624991964548826,
0.002439401810988784,
-0.00720387976616621,
-0.007356408052146435,
0.01178766880184412,
-0.00736446026712656,
0.002160708885639906,
0.01617622934281826,
0.0051506320014595985,
0.009824294596910477,
-0.005897836294025183,
-0.001522365491837263,
-0.0020677305292338133,
0.0037202590610831976,
-0.012765577994287014,
0.005104781594127417,
-0.0052221184596419334,
0.0022194809280335903,
0.002398209646344185,
-0.004196041263639927,
0.0022813561372458935,
0.013420944102108479,
0.0008371690637432039,
-0.00652893865481019,
-0.00007325020123971626,
0.0015186491655185819,
0.0025856872089207172,
-0.010469972155988216,
0.0024937668349593878,
-0.0025192878674715757,
-0.005256609991192818,
-0.0009674561442807317,
-0.0019327172776684165,
0.0022350710351020098,
0.004911754745990038,
-0.0027997870929539204,
0.005245670676231384,
0.00037953414721414447,
-0.004837530665099621,
0.011980894953012466,
-0.0030397437512874603,
-0.0021713345777243376,
0.0013903840444982052,
0.0028159432113170624,
-0.0034029223024845123,
-0.003570852568373084,
-0.006979131605476141,
0.004424734972417355,
0.007666401565074921,
-0.0035008799750357866,
-0.0025688218884170055,
-0.0010721852304413915,
-0.0021994549315422773,
-0.011396268382668495,
-0.00006666672561550513,
0.013796268962323666,
-0.006578019820153713,
0.00704638147726655,
-0.000936242111492902,
-0.00847542379051447,
-0.014458741992712021,
0.047635000199079514,
-0.0005938785034231842,
0.004382900893688202,
0.00277914060279727,
-0.00604614382609725,
-0.002254577586427331,
0.0018116433639079332,
0.008630329743027687,
-0.006704219616949558,
-0.005189924035221338,
0.008209564723074436,
-0.004458823706954718,
0.000647257489617914,
0.002361568622291088,
0.0025462571065872908,
0.01881139911711216,
-0.0010262508876621723,
-0.015609183348715305,
-0.017780616879463196,
0.005941304378211498,
-0.0016757897101342678,
-0.0057883779518306255,
0.010259109549224377,
-0.005573590286076069,
-0.005740914028137922,
0.004278059117496014,
0.007786856964230537,
0.001640213537029922,
-0.0010833980049937963,
-0.003425530856475234,
-0.006200047209858894,
0.0032948069274425507,
0.001085764612071216,
0.004394154995679855,
0.009447336196899414,
-0.0021397641394287348,
0.006186387035995722,
-0.0026750697288662195,
-0.0031812554225325584,
-0.0068766833283007145,
0.002035402925685048,
0.00732417730614543,
-0.0016572275198996067,
-0.006594354286789894,
0.002733273198828101,
0.0034070650581270456,
0.0025283314753323793,
0.011374435387551785,
0.0005261477781459689,
-0.0076475590467453,
0.005198679864406586,
0.004334154073148966,
0.0012857612455263734,
0.009212442673742771,
0.0006289739394560456,
0.00653856573626399,
0.0038333439733833075,
-0.010275362059473991,
-0.018279751762747765,
-0.001542719197459519,
0.010498865507543087,
0.008231576532125473,
-0.0014267185470089316,
0.000607098510954529,
-0.00032229203497990966,
-0.0023395796306431293,
-0.0071878330782055855,
-0.011475715786218643,
-0.0028055396396666765,
0.0016835065325722098,
0.004282462410628796,
0.0685102790594101,
-0.006213244516402483,
-0.0013884840300306678,
-0.009239014238119125,
-0.000057835393818095326,
-0.0010844941716641188,
-0.0008490805048495531,
0.0021661582868546247,
-0.0010163927217945457,
0.004827079828828573,
-0.0007852904382161796,
-0.008732355199754238,
-0.013643144629895687,
0.0006105075008235872,
0.0015023959567770362,
-0.002742899814620614,
0.00017295728321187198,
0.006515353452414274,
-0.008060610853135586,
0.0014248962979763746,
-0.011179587803781033,
0.00033455988159403205,
0.0016791009111329913,
-0.011113611049950123,
-0.0037567182444036007,
-0.004441671073436737,
0.009048194624483585,
0.004690489266067743,
0.0031720937695354223,
-0.0016678126994520426,
0.0036251565907150507,
-0.003400697372853756,
0.0024785534478724003,
-0.004768841899931431,
-0.000535957224201411,
-0.005331589374691248,
0.009232217445969582,
0.0028701922856271267,
-0.012730740942060947,
-0.0032602634746581316,
0.0015228193951770663,
0.002642712090164423,
-0.005195583216845989,
0.0044102780520915985,
0.0004070759459864348,
0.0029222879093140364,
-0.004348712507635355,
-0.0005282240454107523,
-0.006565517745912075,
0.0069543542340397835,
-0.011434919200837612,
0.007252953946590424,
-0.16099092364311218,
0.009536435827612877,
0.0028527805116027594,
-0.0066026425920426846,
-0.0042277793399989605,
-0.016787150874733925,
-0.008298706263303757,
0.005126117262989283,
0.011478075757622719,
0.003939510323107243,
-0.0010738431010395288,
-0.00048111280193552375,
0.006780613679438829,
0.0007296896073967218,
-0.002024053828790784,
-0.008809695020318031,
0.0038446281105279922,
-0.006147561129182577,
-0.0005531327333301306,
0.0024810265749692917,
0.002443344332277775,
0.015978656709194183,
-0.0010473623406141996,
0.0029570136684924364,
-0.000511793652549386,
-0.0031508873216807842,
0.008472606539726257,
-0.0006230820436030626,
0.004470583982765675,
-0.009854867123067379,
-0.006246390286833048,
-0.007276787422597408,
-0.004764173179864883,
0.002802312606945634,
0.006020504981279373,
0.0015724357217550278,
0.01022801361978054,
0.002605949528515339,
-0.009279917925596237,
0.006193253677338362,
-0.006344080902636051,
0.02651906944811344,
0.00099844834767282,
0.0038011744618415833,
0.0014908310258761048,
-0.008712238632142544,
-0.007841669954359531,
0.0075535583309829235,
0.0022892081178724766,
0.013575918041169643,
-0.01728433184325695,
0.00033961483859457076,
0.003894220106303692,
0.019717853516340256,
-0.0033353709150105715,
-0.012821792624890804,
-0.005942835472524166,
-0.0013700068229809403,
-0.0014993060613051057,
0.0055504608899354935,
0.010698609054088593,
-0.0024021293502300978,
0.007049853447824717,
-0.0017440940719097853,
-0.020501751452684402,
0.0031168118584901094,
-0.0017175149405375123,
-0.004721402656286955,
-0.001289843930862844,
0.004317110404372215,
0.007619507145136595,
0.0025862539187073708,
0.0027491659857332706,
0.0005402149399742484,
0.003471454605460167,
-0.0009879417484626174,
0.004493973217904568,
0.0019096728647127748,
0.007629308849573135,
-0.010108689777553082,
0.007291142363101244,
-0.007860113866627216,
-0.0012325462885200977,
0.002862755674868822,
-0.0046975756995379925,
0.00970036257058382,
0.00556306354701519,
-0.005655493587255478,
-0.0046116942539811134,
-0.008330863900482655,
-0.0020084187854081392,
0.002111593261361122,
0.0007333795656450093,
-0.009913659654557705,
0.002149189356714487,
0.004479348659515381,
0.0052000307478010654,
0.005848489701747894,
-0.010009103454649448,
0.007206146605312824,
0.004715664312243462,
-0.009127255529165268,
0.0006464573089033365,
-0.006608915980905294,
0.0068309735506772995,
0.0055945697240531445,
-0.005956355016678572,
-0.006627639755606651,
0.0014037293149158359,
-0.0041467007249593735,
-0.00515329884365201,
0.004277613013982773,
-0.007548226974904537,
-0.012536495923995972,
-0.0026916135102510452,
-0.008548358455300331,
-0.0006010671495459974
] |
8a55afc76d238a2edb1a2adff77422f604912e7b | 25,760 | py | Python | rpython/annotator/annrpython.py | microvm/pypy-mu | 6b03fbe93052d0eb3a4c67152c987c16837b3484 | [
"Apache-2.0",
"OpenSSL"
] | null | null | null | rpython/annotator/annrpython.py | microvm/pypy-mu | 6b03fbe93052d0eb3a4c67152c987c16837b3484 | [
"Apache-2.0",
"OpenSSL"
] | null | null | null | rpython/annotator/annrpython.py | microvm/pypy-mu | 6b03fbe93052d0eb3a4c67152c987c16837b3484 | [
"Apache-2.0",
"OpenSSL"
] | null | null | null | from __future__ import absolute_import
import types
from collections import defaultdict
from rpython.tool.ansi_print import AnsiLogger
from rpython.tool.pairtype import pair
from rpython.tool.error import (format_blocked_annotation_error,
gather_error, source_lines)
from rpython.flowspace.model import Variable, Constant, checkgraph
from rpython.translator import simplify, transform
from rpython.annotator import model as annmodel, signature
from rpython.annotator.model import (
typeof, s_ImpossibleValue, SomeInstance, intersection, difference)
from rpython.annotator.bookkeeper import Bookkeeper
from rpython.rtyper.normalizecalls import perform_normalizations
log = AnsiLogger("annrpython")
class RPythonAnnotator(object):
"""Block annotator for RPython.
See description in doc/translation.txt."""
def __init__(self, translator=None, policy=None, bookkeeper=None):
import rpython.rtyper.extfuncregistry # has side effects
if translator is None:
# interface for tests
from rpython.translator.translator import TranslationContext
translator = TranslationContext()
translator.annotator = self
self.translator = translator
self.pendingblocks = {} # map {block: graph-containing-it}
self.annotated = {} # set of blocks already seen
self.added_blocks = None # see processblock() below
self.links_followed = {} # set of links that have ever been followed
self.notify = {} # {block: {positions-to-reflow-from-when-done}}
self.fixed_graphs = {} # set of graphs not to annotate again
self.blocked_blocks = {} # set of {blocked_block: (graph, index)}
# --- the following information is recorded for debugging ---
self.blocked_graphs = {} # set of graphs that have blocked blocks
# --- end of debugging information ---
self.frozen = False
if policy is None:
from rpython.annotator.policy import AnnotatorPolicy
self.policy = AnnotatorPolicy()
else:
self.policy = policy
if bookkeeper is None:
bookkeeper = Bookkeeper(self)
self.bookkeeper = bookkeeper
def __getstate__(self):
attrs = """translator pendingblocks annotated links_followed
notify bookkeeper frozen policy added_blocks""".split()
ret = self.__dict__.copy()
for key, value in ret.items():
if key not in attrs:
assert type(value) is dict, (
"%r is not dict. please update %s.__getstate__" %
(key, self.__class__.__name__))
ret[key] = {}
return ret
#___ convenience high-level interface __________________
def build_types(self, function, input_arg_types, complete_now=True,
main_entry_point=False):
"""Recursively build annotations about the specific entry point."""
assert isinstance(function, types.FunctionType), "fix that!"
from rpython.annotator.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
# make input arguments and set their type
args_s = [self.typeannotation(t) for t in input_arg_types]
# XXX hack
annmodel.TLS.check_str_without_nul = (
self.translator.config.translation.check_str_without_nul)
flowgraph, inputs_s = self.get_call_parameters(function, args_s, policy)
if main_entry_point:
self.translator.entry_point_graph = flowgraph
return self.build_graph_types(flowgraph, inputs_s, complete_now=complete_now)
def get_call_parameters(self, function, args_s, policy):
desc = self.bookkeeper.getdesc(function)
prevpolicy = self.policy
self.policy = policy
self.bookkeeper.enter(None)
try:
return desc.get_call_parameters(args_s)
finally:
self.bookkeeper.leave()
self.policy = prevpolicy
def annotate_helper(self, function, args_s, policy=None):
if policy is None:
from rpython.annotator.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
# XXX hack
annmodel.TLS.check_str_without_nul = (
self.translator.config.translation.check_str_without_nul)
graph, inputcells = self.get_call_parameters(function, args_s, policy)
self.build_graph_types(graph, inputcells, complete_now=False)
self.complete_helpers(policy)
return graph
def complete_helpers(self, policy):
saved = self.policy, self.added_blocks
self.policy = policy
try:
self.added_blocks = {}
self.complete()
# invoke annotation simplifications for the new blocks
self.simplify(block_subset=self.added_blocks)
finally:
self.policy, self.added_blocks = saved
def build_graph_types(self, flowgraph, inputcells, complete_now=True):
checkgraph(flowgraph)
nbarg = len(flowgraph.getargs())
assert len(inputcells) == nbarg # wrong number of args
# register the entry point
self.addpendinggraph(flowgraph, inputcells)
# recursively proceed until no more pending block is left
if complete_now:
self.complete()
return self.annotation(flowgraph.getreturnvar())
def gettype(self, variable):
"""Return the known type of a control flow graph variable,
defaulting to 'object'."""
if isinstance(variable, Constant):
return type(variable.value)
elif isinstance(variable, Variable):
s_variable = variable.annotation
if s_variable:
return s_variable.knowntype
else:
return object
else:
raise TypeError("Variable or Constant instance expected, "
"got %r" % (variable,))
def getuserclassdefinitions(self):
"""Return a list of ClassDefs."""
return self.bookkeeper.classdefs
#___ medium-level interface ____________________________
def addpendinggraph(self, flowgraph, inputcells):
self.addpendingblock(flowgraph, flowgraph.startblock, inputcells)
def addpendingblock(self, graph, block, cells):
"""Register an entry point into block with the given input cells."""
if graph in self.fixed_graphs:
# special case for annotating/rtyping in several phases: calling
# a graph that has already been rtyped. Safety-check the new
# annotations that are passed in, and don't annotate the old
# graph -- it's already low-level operations!
for a, s_newarg in zip(block.inputargs, cells):
s_oldarg = self.binding(a)
assert annmodel.unionof(s_oldarg, s_newarg) == s_oldarg
else:
assert not self.frozen
if block not in self.annotated:
self.bindinputargs(graph, block, cells)
else:
self.mergeinputargs(graph, block, cells)
if not self.annotated[block]:
self.pendingblocks[block] = graph
def complete_pending_blocks(self):
while self.pendingblocks:
block, graph = self.pendingblocks.popitem()
self.processblock(graph, block)
def complete(self):
"""Process pending blocks until none is left."""
while True:
self.complete_pending_blocks()
self.policy.no_more_blocks_to_annotate(self)
if not self.pendingblocks:
break # finished
# make sure that the return variables of all graphs is annotated
if self.added_blocks is not None:
newgraphs = [self.annotated[block] for block in self.added_blocks]
newgraphs = dict.fromkeys(newgraphs)
got_blocked_blocks = False in newgraphs
else:
newgraphs = self.translator.graphs #all of them
got_blocked_blocks = False in self.annotated.values()
if got_blocked_blocks:
for graph in self.blocked_graphs.values():
self.blocked_graphs[graph] = True
blocked_blocks = [block for block, done in self.annotated.items()
if done is False]
assert len(blocked_blocks) == len(self.blocked_blocks)
text = format_blocked_annotation_error(self, self.blocked_blocks)
#raise SystemExit()
raise annmodel.AnnotatorError(text)
for graph in newgraphs:
v = graph.getreturnvar()
if v.annotation is None:
self.setbinding(v, s_ImpossibleValue)
def validate(self):
"""Check that the annotation results are valid"""
self.bookkeeper.check_no_flags_on_instances()
def annotation(self, arg):
"Gives the SomeValue corresponding to the given Variable or Constant."
if isinstance(arg, Variable):
return arg.annotation
elif isinstance(arg, Constant):
return self.bookkeeper.immutablevalue(arg.value)
else:
raise TypeError('Variable or Constant expected, got %r' % (arg,))
def binding(self, arg):
"Gives the SomeValue corresponding to the given Variable or Constant."
s_arg = self.annotation(arg)
if s_arg is None:
raise KeyError
return s_arg
def typeannotation(self, t):
return signature.annotation(t, self.bookkeeper)
def setbinding(self, arg, s_value):
s_old = arg.annotation
if s_old is not None:
if not s_value.contains(s_old):
log.WARNING("%s does not contain %s" % (s_value, s_old))
log.WARNING("%s" % annmodel.unionof(s_value, s_old))
assert False
arg.annotation = s_value
def warning(self, msg, pos=None):
if pos is None:
try:
pos = self.bookkeeper.position_key
except AttributeError:
pos = '?'
if pos != '?':
pos = self.whereami(pos)
log.WARNING("%s/ %s" % (pos, msg))
#___ interface for annotator.bookkeeper _______
def recursivecall(self, graph, whence, inputcells):
if isinstance(whence, tuple):
parent_graph, parent_block, parent_index = whence
tag = parent_block, parent_index
self.translator.update_call_graph(parent_graph, graph, tag)
# self.notify[graph.returnblock] is a dictionary of call
# points to this func which triggers a reflow whenever the
# return block of this graph has been analysed.
callpositions = self.notify.setdefault(graph.returnblock, {})
if whence is not None:
if callable(whence):
def callback():
whence(self, graph)
else:
callback = whence
callpositions[callback] = True
# generalize the function's input arguments
self.addpendingblock(graph, graph.startblock, inputcells)
# get the (current) return value
v = graph.getreturnvar()
try:
return self.binding(v)
except KeyError:
# the function didn't reach any return statement so far.
# (some functions actually never do, they always raise exceptions)
return s_ImpossibleValue
def reflowfromposition(self, position_key):
graph, block, index = position_key
self.reflowpendingblock(graph, block)
def call_sites(self):
newblocks = self.added_blocks
if newblocks is None:
newblocks = self.annotated # all of them
for block in newblocks:
for op in block.operations:
if op.opname in ('simple_call', 'call_args'):
yield op
# some blocks are partially annotated
if op.result.annotation is None:
break # ignore the unannotated part
#___ simplification (should be moved elsewhere?) _______
def simplify(self, block_subset=None, extra_passes=None):
# Generic simplifications
transform.transform_graph(self, block_subset=block_subset,
extra_passes=extra_passes)
if block_subset is None:
graphs = self.translator.graphs
else:
graphs = {}
for block in block_subset:
graph = self.annotated.get(block)
if graph:
graphs[graph] = True
for graph in graphs:
simplify.eliminate_empty_blocks(graph)
self.bookkeeper.compute_at_fixpoint()
if block_subset is None:
perform_normalizations(self)
#___ flowing annotations in blocks _____________________
def processblock(self, graph, block):
# Important: this is not called recursively.
# self.flowin() can only issue calls to self.addpendingblock().
# The analysis of a block can be in three states:
# * block not in self.annotated:
# never seen the block.
# * self.annotated[block] == False:
# the input variables of the block have bindings but we
# still have to consider all the operations in the block.
# * self.annotated[block] == graph-containing-block:
# analysis done (at least until we find we must generalize the
# input variables).
#print '* processblock', block, cells
self.annotated[block] = graph
if block in self.blocked_blocks:
del self.blocked_blocks[block]
try:
self.flowin(graph, block)
except BlockedInference as e:
self.annotated[block] = False # failed, hopefully temporarily
self.blocked_blocks[block] = (graph, e.opindex)
except Exception as e:
# hack for debug tools only
if not hasattr(e, '__annotator_block'):
setattr(e, '__annotator_block', block)
raise
# The dict 'added_blocks' is used by rpython.annlowlevel to
# detect which are the new blocks that annotating an additional
# small helper creates.
if self.added_blocks is not None:
self.added_blocks[block] = True
def reflowpendingblock(self, graph, block):
assert not self.frozen
assert graph not in self.fixed_graphs
self.pendingblocks[block] = graph
assert block in self.annotated
self.annotated[block] = False # must re-flow
self.blocked_blocks[block] = (graph, None)
def bindinputargs(self, graph, block, inputcells):
# Create the initial bindings for the input args of a block.
assert len(block.inputargs) == len(inputcells)
for a, cell in zip(block.inputargs, inputcells):
self.setbinding(a, cell)
self.annotated[block] = False # must flowin.
self.blocked_blocks[block] = (graph, None)
def mergeinputargs(self, graph, block, inputcells):
# Merge the new 'cells' with each of the block's existing input
# variables.
oldcells = [self.binding(a) for a in block.inputargs]
try:
unions = [annmodel.unionof(c1,c2) for c1, c2 in zip(oldcells,inputcells)]
except annmodel.UnionError as e:
# Add source code to the UnionError
e.source = '\n'.join(source_lines(graph, block, None, long=True))
raise
# if the merged cells changed, we must redo the analysis
if unions != oldcells:
self.bindinputargs(graph, block, unions)
def apply_renaming(self, s_out, renaming):
if hasattr(s_out, 'is_type_of'):
renamed_is_type_of = []
for v in s_out.is_type_of:
renamed_is_type_of += renaming[v]
assert s_out.knowntype is type
newcell = typeof(renamed_is_type_of)
if s_out.is_constant():
newcell.const = s_out.const
s_out = newcell
if hasattr(s_out, 'knowntypedata'):
renamed_knowntypedata = {}
for value, constraints in s_out.knowntypedata.items():
renamed_knowntypedata[value] = {}
for v, s in constraints.items():
new_vs = renaming.get(v, [])
for new_v in new_vs:
renamed_knowntypedata[value][new_v] = s
assert isinstance(s_out, annmodel.SomeBool)
newcell = annmodel.SomeBool()
if s_out.is_constant():
newcell.const = s_out.const
s_out = newcell
s_out.set_knowntypedata(renamed_knowntypedata)
return s_out
def whereami(self, position_key):
graph, block, i = position_key
blk = ""
if block:
at = block.at()
if at:
blk = " block"+at
opid=""
if i is not None:
opid = " op=%d" % i
return repr(graph) + blk + opid
def flowin(self, graph, block):
try:
i = 0
while i < len(block.operations):
op = block.operations[i]
with self.bookkeeper.at_position((graph, block, i)):
new_ops = op.transform(self)
if new_ops is not None:
block.operations[i:i+1] = new_ops
if not new_ops:
continue
new_ops[-1].result = op.result
op = new_ops[0]
self.consider_op(op)
i += 1
except BlockedInference as e:
if e.op is block.raising_op:
# this is the case where the last operation of the block will
# always raise an exception which is immediately caught by
# an exception handler. We then only follow the exceptional
# branches.
exits = [link for link in block.exits
if link.exitcase is not None]
elif e.op.opname in ('simple_call', 'call_args', 'next'):
# XXX warning, keep the name of the call operations in sync
# with the flow object space. These are the operations for
# which it is fine to always raise an exception. We then
# swallow the BlockedInference and that's it.
# About 'next': see test_annotate_iter_empty_container().
return
else:
# other cases are problematic (but will hopefully be solved
# later by reflowing). Throw the BlockedInference up to
# processblock().
e.opindex = i
raise
except annmodel.HarmlesslyBlocked:
return
except annmodel.AnnotatorError as e: # note that UnionError is a subclass
e.source = gather_error(self, graph, block, i)
raise
else:
# dead code removal: don't follow all exits if the exitswitch
# is known
exits = block.exits
if isinstance(block.exitswitch, Variable):
s_exitswitch = self.binding(block.exitswitch)
if s_exitswitch.is_constant():
exits = [link for link in exits
if link.exitcase == s_exitswitch.const]
if block.canraise:
op = block.raising_op
s_exception = self.get_exception(op)
for link in exits:
case = link.exitcase
if case is None:
self.follow_link(graph, link, {})
continue
if s_exception == s_ImpossibleValue:
break
s_case = SomeInstance(self.bookkeeper.getuniqueclassdef(case))
s_matching_exc = intersection(s_exception, s_case)
if s_matching_exc != s_ImpossibleValue:
self.follow_raise_link(graph, link, s_matching_exc)
s_exception = difference(s_exception, s_case)
else:
if isinstance(block.exitswitch, Variable):
knowntypedata = getattr(
block.exitswitch.annotation, "knowntypedata", {})
else:
knowntypedata = {}
for link in exits:
constraints = knowntypedata.get(link.exitcase, {})
self.follow_link(graph, link, constraints)
if block in self.notify:
# reflow from certain positions when this block is done
for callback in self.notify[block]:
if isinstance(callback, tuple):
self.reflowfromposition(callback) # callback is a position
else:
callback()
def follow_link(self, graph, link, constraints):
assert not (isinstance(link.exitcase, (types.ClassType, type)) and
issubclass(link.exitcase, BaseException))
ignore_link = False
inputs_s = []
renaming = defaultdict(list)
for v_out, v_input in zip(link.args, link.target.inputargs):
renaming[v_out].append(v_input)
for v_out in link.args:
s_out = self.annotation(v_out)
if v_out in constraints:
s_constraint = constraints[v_out]
s_out = pair(s_out, s_constraint).improve()
# ignore links that try to pass impossible values
if s_out == s_ImpossibleValue:
ignore_link = True
s_out = self.apply_renaming(s_out, renaming)
inputs_s.append(s_out)
if ignore_link:
return
self.links_followed[link] = True
self.addpendingblock(graph, link.target, inputs_s)
def follow_raise_link(self, graph, link, s_last_exc_value):
v_last_exc_type = link.last_exception
v_last_exc_value = link.last_exc_value
assert (isinstance(link.exitcase, (types.ClassType, type)) and
issubclass(link.exitcase, BaseException))
assert v_last_exc_type and v_last_exc_value
if isinstance(v_last_exc_value, Variable):
self.setbinding(v_last_exc_value, s_last_exc_value)
if isinstance(v_last_exc_type, Variable):
self.setbinding(v_last_exc_type, typeof([v_last_exc_value]))
inputs_s = []
renaming = defaultdict(list)
for v_out, v_input in zip(link.args, link.target.inputargs):
renaming[v_out].append(v_input)
for v_out, v_input in zip(link.args, link.target.inputargs):
if v_out == v_last_exc_type:
s_out = typeof(renaming[v_last_exc_value])
if isinstance(v_last_exc_type, Constant):
s_out.const = v_last_exc_type.value
elif v_last_exc_type.annotation.is_constant():
s_out.const = v_last_exc_type.annotation.const
inputs_s.append(s_out)
else:
s_out = self.annotation(v_out)
s_out = self.apply_renaming(s_out, renaming)
inputs_s.append(s_out)
self.links_followed[link] = True
self.addpendingblock(graph, link.target, inputs_s)
#___ creating the annotations based on operations ______
def consider_op(self, op):
# let's be careful about avoiding propagated SomeImpossibleValues
# to enter an op; the latter can result in violations of the
# more general results invariant: e.g. if SomeImpossibleValue enters is_
# is_(SomeImpossibleValue, None) -> SomeBool
# is_(SomeInstance(not None), None) -> SomeBool(const=False) ...
# boom -- in the assert of setbinding()
for arg in op.args:
if isinstance(self.annotation(arg), annmodel.SomeImpossibleValue):
raise BlockedInference(self, op, -1)
resultcell = op.consider(self)
if resultcell is None:
resultcell = s_ImpossibleValue
elif resultcell == s_ImpossibleValue:
raise BlockedInference(self, op, -1) # the operation cannot succeed
assert isinstance(resultcell, annmodel.SomeObject)
assert isinstance(op.result, Variable)
self.setbinding(op.result, resultcell) # bind resultcell to op.result
def get_exception(self, operation):
"""
Return the annotation for all exceptions that `operation` may raise.
"""
can_only_throw = operation.get_can_only_throw(self)
if can_only_throw is None:
return SomeInstance(self.bookkeeper.getuniqueclassdef(Exception))
else:
return self.bookkeeper.new_exception(can_only_throw)
class BlockedInference(Exception):
"""This exception signals the type inference engine that the situation
is currently blocked, and that it should try to progress elsewhere."""
def __init__(self, annotator, op, opindex):
self.annotator = annotator
try:
self.break_at = annotator.bookkeeper.position_key
except AttributeError:
self.break_at = None
self.op = op
self.opindex = opindex
def __repr__(self):
if not self.break_at:
break_at = "?"
else:
break_at = self.annotator.whereami(self.break_at)
return "<BlockedInference break_at %s [%s]>" %(break_at, self.op)
__str__ = __repr__
| 40.312989 | 85 | 0.604891 | 0 | 0 | [
-0.02724207565188408,
0.038451239466667175,
-0.0034854670520871878,
0.007583759259432554,
-0.04780026525259018,
0.008883636444807053,
0.009781203232705593,
-0.004683295730501413,
-0.015044057741761208,
0.0020718425512313843,
-0.015376431867480278,
-0.001243984210304916,
0.025622626766562462,
-0.026616739109158516,
-0.012275896966457367,
0.008025696501135826,
0.04597501456737518,
0.014328296296298504,
-0.004175892565399408,
-0.00877822283655405,
-0.023281490430235863,
0.014103855937719345,
-0.0033938547130674124,
0.01740964688360691,
0.04967544972896576,
-0.01330922544002533,
0.02198503352701664,
0.02275051735341549,
0.008841930888593197,
-0.011624457314610481,
0.00178073241841048,
0.0032146009616553783,
-0.02800772152841091,
-0.043914638459682465,
-0.006089729722589254,
0.03075648657977581,
0.014474458992481232,
-0.08415315300226212,
0.03663952276110649,
0.004746341612190008,
-0.005808087065815926,
-0.013137347996234894,
0.0038776046130806208,
-0.048699136823415756,
0.03810873255133629,
0.023094085976481438,
0.005582023877650499,
0.022777926176786423,
-0.029441040009260178,
-0.012887858785688877,
0.0010272531071677804,
-0.013269429095089436,
0.006376716773957014,
-0.030741069465875626,
0.014556162990629673,
-0.04781816899776459,
0.014226380735635757,
0.025110766291618347,
-0.011576687917113304,
0.005521672777831554,
-0.054762911051511765,
0.011401229538023472,
-0.0018215898890048265,
0.02411278709769249,
0.03799143061041832,
-0.01960541307926178,
0.011814054101705551,
0.0053526731207966805,
-0.06450968235731125,
-0.01410068478435278,
0.00033675850136205554,
0.022904086858034134,
0.030891092494130135,
0.020147215574979782,
0.02894354611635208,
0.004383496008813381,
-0.019710605964064598,
-0.027905790135264397,
-0.0260731540620327,
0.036644041538238525,
-0.008621126413345337,
0.10739964246749878,
0.020245611667633057,
-0.008747365325689316,
0.007590604480355978,
0.03710068389773369,
0.046392932534217834,
-0.03886794298887253,
-0.018103014677762985,
0.02686716429889202,
-0.02946455217897892,
0.009996511042118073,
-0.03642383962869644,
-0.034429095685482025,
-0.010685202665627003,
-0.06393714994192123,
-0.004365069326013327,
-0.004207858350127935,
-0.01635965332388878,
-0.03428275138139725,
0.04286374896764755,
0.044094059616327286,
0.03344981372356415,
0.0030586745124310255,
0.03451268747448921,
-0.0011048419401049614,
-0.07007210701704025,
0.008514096960425377,
0.03709840774536133,
-0.014609763398766518,
-0.06044858321547508,
0.022451579570770264,
0.02664945088326931,
-0.047497138381004333,
-0.010048121213912964,
-0.007175778970122337,
-0.023304408416152,
0.017328189685940742,
0.023638293147087097,
0.07086688280105591,
0.007480431813746691,
-0.01309604849666357,
0.015453236177563667,
-0.04903125762939453,
-0.03865792602300644,
0.07403457909822464,
0.026934616267681122,
-0.006196905858814716,
0.0028834068216383457,
-0.01479141041636467,
-0.04606946185231209,
-0.007765965536236763,
-0.015192624181509018,
0.02991088479757309,
0.01522401999682188,
-0.009078496135771275,
0.019441446289420128,
0.025049299001693726,
-0.04955708980560303,
0.054940514266490936,
0.010300109162926674,
-0.009876217693090439,
0.010471047833561897,
-0.06781001389026642,
-0.0001632192579563707,
-0.0034157712943851948,
-0.014992542564868927,
0.017780223861336708,
-0.027237216010689735,
-0.005628867074847221,
0.0253671295940876,
0.00935489870607853,
0.016335679218173027,
0.012275131419301033,
0.009790044277906418,
-0.014607933349907398,
-0.033259302377700806,
-0.05385423079133034,
0.008826248347759247,
-0.03248815983533859,
0.011044478043913841,
0.04819222912192345,
0.004426461644470692,
-0.00568731315433979,
0.04477127268910408,
-0.044170867651700974,
-0.010315299034118652,
0.05983859300613403,
0.006399502977728844,
0.04218577221035957,
0.031735360622406006,
0.011523264460265636,
-0.01891794614493847,
-0.01226653903722763,
-0.04443245753645897,
0.016391713172197342,
0.02453007735311985,
0.002224621595814824,
-0.007534205447882414,
-0.007211980875581503,
-0.012063305824995041,
-0.054184507578611374,
0.0030196222942322493,
0.025715410709381104,
0.0005313209840096533,
-0.031402092427015305,
-0.08539929240942001,
-0.021359050646424294,
0.018481116741895676,
-0.005997809115797281,
-0.03736246004700661,
0.023704685270786285,
-0.03781454265117645,
-0.01412584912031889,
0.02656600996851921,
-0.00047203132999129593,
0.01538063120096922,
-0.04819739609956741,
0.0065825567580759525,
0.003680506022647023,
-0.010730350390076637,
-0.013315409421920776,
0.003946208395063877,
0.04193727672100067,
0.012232941575348377,
-0.01854926347732544,
-0.6070037484169006,
0.031446635723114014,
-0.018671853467822075,
-0.03153671696782112,
0.022313889116048813,
0.03541916236281395,
-0.016997816041111946,
-0.0464908629655838,
-0.04667166247963905,
0.04374260455369949,
-0.018048856407403946,
0.011178233660757542,
-0.005149263422936201,
0.017395228147506714,
-0.0014061498222872615,
-0.0069940523244440556,
-0.023694470524787903,
-0.031521882861852646,
0.00027573780971579254,
0.007498753722757101,
0.012285105884075165,
-0.02732408046722412,
-0.01463753916323185,
0.0010432362323626876,
0.022813860327005386,
-0.024463407695293427,
0.022927016019821167,
0.02666238509118557,
-0.05154308304190636,
-0.005443904083222151,
0.0212789885699749,
0.004403732251375914,
0.03333033621311188,
0.006334683857858181,
0.033651698380708694,
0.027440635487437248,
0.0426892451941967,
-0.056243691593408585,
0.032666005194187164,
-0.027515478432178497,
0.023537784814834595,
-0.03344200551509857,
-0.023977156728506088,
-0.04600180685520172,
-0.04754960909485817,
0.014595402404665947,
-0.03945130109786987,
-0.07405440509319305,
-0.0017235513078048825,
0.006393043324351311,
-0.02627594582736492,
-0.0013836829457432032,
0.0075713410042226315,
-0.00598386162891984,
-0.02697422355413437,
0.028634145855903625,
-0.04546896368265152,
-0.028446076437830925,
0.009637128561735153,
-0.0039517818950116634,
0.03048969991505146,
-0.0042142304591834545,
-0.0061588529497385025,
-0.016524791717529297,
-0.008909442462027073,
0.02505006454885006,
0.07523408532142639,
-0.030359137803316116,
-0.04441855475306511,
0.05756472051143646,
-0.04423877224326134,
0.04228869080543518,
-0.03417820855975151,
0.11862052232027054,
0.02200641855597496,
-0.0014213001122698188,
-0.007499984465539455,
0.0056716278195381165,
-0.09698297083377838,
-0.04574109613895416,
0.01887356862425804,
-0.006247593555599451,
-0.01043807715177536,
-0.0058079669252038,
-0.012422691099345684,
-0.016043931245803833,
0.01194960717111826,
-0.007927140220999718,
0.009166363626718521,
0.004483453463762999,
0.047476448118686676,
0.029424693435430527,
0.062071263790130615,
-0.004641265142709017,
-0.013524781912565231,
0.01419300027191639,
0.060042738914489746,
0.05427026003599167,
0.02043991908431053,
-0.005393679719418287,
-0.029880808666348457,
0.0030558849684894085,
-0.04079121723771095,
0.036340609192848206,
-0.00855856854468584,
-0.031623125076293945,
0.0031967200338840485,
-0.031545642763376236,
0.030826177448034286,
-0.03225189074873924,
0.016154667362570763,
-0.023817460983991623,
-0.057151637971401215,
0.02456541173160076,
0.012124648317694664,
-0.009447596035897732,
-0.0026411893777549267,
-0.060460999608039856,
0.014071434736251831,
-0.01874370127916336,
-0.024100447073578835,
-0.04177892953157425,
-0.034615132957696915,
0.030089333653450012,
-0.013258680701255798,
0.0443418063223362,
-0.019399426877498627,
0.012078024446964264,
0.019886601716279984,
0.00525348074734211,
-0.0539429746568203,
0.017173757776618004,
0.01991312764585018,
0.0022596316412091255,
-0.029213041067123413,
-0.004221329465508461,
-0.029134420678019524,
-0.009266914799809456,
0.0012756827054545283,
-0.00767796253785491,
0.022693723440170288,
-0.021700602024793625,
-0.012500741519033909,
-0.05210745707154274,
0.02598683349788189,
0.010308733209967613,
0.01812518760561943,
-0.02274884097278118,
-0.023285945877432823,
-0.03973798081278801,
0.0020910107996314764,
0.0267738439142704,
0.01726352982223034,
-0.006197011098265648,
-0.023902583867311478,
-0.016179442405700684,
-0.0012675744947046041,
0.006939303129911423,
0.015775611624121666,
0.006940341088920832,
-0.044416140764951706,
-0.017694219946861267,
-0.025492632761597633,
0.007982946000993252,
-0.006817243527621031,
-0.011014139279723167,
0.0034516211599111557,
0.03524300828576088,
0.04396113380789757,
0.001895623398013413,
0.06042354553937912,
-0.016946842893958092,
-0.0018672089790925384,
-0.008195469155907631,
-0.032942455261945724,
0.012473216280341148,
0.026573339477181435,
-0.06785271316766739,
0.017230290919542313,
0.038298554718494415,
-0.02731330133974552,
0.025043170899152756,
-0.00645377766340971,
-0.013742501847445965,
-0.025224726647138596,
0.02596537210047245,
-0.0009130124817602336,
0.02626582235097885,
0.05336981639266014,
-0.05052655562758446,
-0.02189842239022255,
0.022170290350914,
-0.016619915142655373,
0.02132044918835163,
-0.02173752710223198,
-0.03886916860938072,
0.03642520308494568,
0.005977034103125334,
-0.011778588406741619,
-0.02222594991326332,
-0.011971237137913704,
0.036717481911182404,
0.0031923698261380196,
0.036668810993433,
0.011799255385994911,
-0.022086281329393387,
-0.0017041050596162677,
-0.018878234550356865,
-0.000634149182587862,
-0.029536962509155273,
0.01948878914117813,
-0.037081871181726456,
0.0372944176197052,
0.01920115016400814,
0.008621525950729847,
0.01678556017577648,
-0.015959084033966064,
-0.0899525061249733,
0.03313656151294708,
-0.0066446177661418915,
-0.0025263968855142593,
-0.009280966594815254,
0.005633581895381212,
-0.004722130484879017,
-0.04281012341380119,
0.0037682722322642803,
-0.01586797647178173,
0.03435612842440605,
-0.00605987710878253,
-0.03228837251663208,
0.006993912160396576,
0.0020143173169344664,
-0.032208554446697235,
-0.000866741465870291,
-0.04194232076406479,
0.006136404350399971,
-0.03498988226056099,
-0.045576032251119614,
-0.0469931922852993,
-0.0016238945536315441,
0.009574459865689278,
-0.0068673803471028805,
-0.032956503331661224,
0.03462967649102211,
-0.011463047005236149,
-0.03214588761329651,
0.03530697897076607,
-0.04951342195272446,
-0.052444420754909515,
-0.006745104677975178,
-0.0320284366607666,
0.008586477488279343,
0.04492729902267456,
0.023440249264240265,
-0.005348714534193277,
0.005560260731726885,
-0.02342222072184086,
0.02392948605120182,
0.029163019731640816,
0.003894171677529812,
-0.01003235299140215,
-0.05041680112481117,
0.003244281280785799,
0.06626950949430466,
-0.051397666335105896,
-0.0018301052041351795,
-0.004509619902819395,
0.00036265660310164094,
-0.038346219807863235,
0.03658127784729004,
0.02556769549846649,
-0.000627682195045054,
0.0013594679767265916,
-0.005377776920795441,
-0.04861648380756378,
0.0126029122620821,
-0.019374633207917213,
-0.007315719500184059,
0.01945723593235016,
-0.0036995462141931057,
-0.009634294547140598,
0.001918325200676918,
0.05391785874962807,
0.03000320866703987,
-0.0007728454656898975,
0.016720766201615334,
0.027487287297844887,
0.011404960416257381,
-0.016152650117874146,
0.0010481365025043488,
0.011872677132487297,
-0.047691747546195984,
0.041247591376304626,
0.020187193527817726,
-0.0019985358230769634,
-0.029651254415512085,
-0.0023953013587743044,
0.041010547429323196,
0.0508616678416729,
-0.003823072649538517,
0.01123577170073986,
0.0098296282812953,
-0.019932499155402184,
-0.01653314381837845,
0.03866395726799965,
0.008742566220462322,
0.03031574748456478,
-0.004615829326212406,
0.04228559508919716,
0.020356904715299606,
0.03293919563293457,
0.047615453600883484,
-0.020319541916251183,
-0.004054971970617771,
0.01756804808974266,
0.01762760803103447,
0.031514476984739304,
-0.003908348735421896,
0.001329725026153028,
0.0093346256762743,
-0.016292281448841095,
0.011739809066057205,
-0.021503040567040443,
-0.04550715535879135,
-0.021068353205919266,
-0.05644352361559868,
-0.03593209758400917,
-0.03122629225254059,
-0.012839539907872677,
0.01888863742351532,
-0.004886743146926165,
-0.03812321648001671,
0.018709883093833923,
-0.003077357541769743,
-0.010747043415904045,
-0.01818220689892769,
0.018015345558524132,
0.06235084310173988,
0.015472467057406902,
-0.00741981016471982,
0.000365147105185315,
0.05864597484469414,
0.008752000518143177,
-0.02702506072819233,
0.05019160360097885,
-0.050778403878211975,
0.04573778808116913,
0.03064410760998726,
0.005645310040563345,
-0.006210540886968374,
0.01373925432562828,
-0.05422813445329666,
-0.002819166285917163,
-0.008537443354725838,
0.0037175274919718504,
-0.024327468127012253,
-0.010927511379122734,
0.04797013849020004,
0.03419804945588112,
0.018159283325076103,
-0.00879746489226818,
-0.00115778180770576,
-0.006230283062905073,
-0.0108198132365942,
-0.010843264870345592,
-0.017958590760827065,
0.04142748937010765,
-0.023428024724125862,
-0.005815509241074324,
0.016941653564572334,
0.04999315366148949,
-0.023401297628879547,
0.007370609790086746,
-0.015537765808403492,
0.025716198608279228,
0.022719811648130417,
0.005303704645484686,
-0.0004485394456423819,
0.029262050986289978,
0.01240387000143528,
-0.045081671327352524,
-0.018605777993798256,
0.018559055402874947,
0.0037060310132801533,
0.02374819479882717,
-0.026722092181444168,
0.020676761865615845,
0.03024282306432724,
-0.003397993976250291,
-0.029635168612003326,
0.010582592338323593,
0.026737693697214127,
0.046594198793172836,
0.021765021607279778,
-0.008238207548856735,
0.029024742543697357,
-0.01722976565361023,
-0.0170578733086586,
-0.004991851281374693,
0.004181263502687216,
-0.061552006751298904,
0.0014956039376556873,
-0.005009109154343605,
0.0041616493836045265,
0.06376270204782486,
-0.01524839922785759,
0.0021291961893439293,
0.009616080671548843,
0.022173089906573296,
-0.0030010221526026726,
0.009705000557005405,
0.04472064599394798,
-0.05498812720179558,
0.002794442465528846,
0.02497793175280094,
0.044187817722558975,
-0.0259843897074461,
-0.025032667443156242,
-0.0003342959680594504,
0.03069317154586315,
-0.07781940698623657,
-0.00882484670728445,
0.015526046976447105,
0.0013599991798400879,
-0.004956768359988928,
-0.024768169969320297,
0.019558342173695564,
-0.03121117688715458,
0.024857550859451294,
0.0018108350923284888,
-0.03032841347157955,
0.025957535952329636,
-0.022155243903398514,
0.01301445160061121,
0.031167015433311462,
-0.006229882128536701,
0.008110911585390568,
0.013302458450198174,
-0.02443966642022133,
-0.014392311684787273,
-0.027040032669901848,
-0.023641139268875122,
0.013078462332487106,
-0.007776228245347738,
0.0202927328646183,
0.003669323632493615,
0.01578604057431221,
0.012527952902019024,
-0.024344881996512413,
0.007856272161006927,
-0.009040266275405884,
0.021362530067563057,
0.04258398711681366,
0.021371977403759956,
-0.031136704608798027,
0.025212373584508896,
-0.0028009244706481695,
0.026852313429117203,
0.05927392095327377,
0.02115866169333458,
0.02847171574831009,
0.03276396170258522,
-0.03324562683701515,
0.011468019336462021,
0.04206710308790207,
0.013973510824143887,
-0.014189084991812706,
-0.00010905764065682888,
-0.020841632038354874,
-0.0018458882113918662,
-0.009853878989815712,
0.023567568510770798,
0.006603510119020939,
-0.013176248408854008,
0.002047168556600809,
0.018171614035964012,
0.015741536393761635,
0.027611710131168365,
0.03626695275306702,
0.024225357919931412,
-0.029573922976851463,
0.057706985622644424,
0.0003121947811450809,
0.06529753655195236,
-0.007802643813192844,
0.030089357867836952,
-0.0008086694870144129,
0.023785855621099472,
-0.029742566868662834,
-0.00966029055416584,
-0.027537567541003227,
-0.026991993188858032,
0.0035801799967885017,
0.06989137828350067,
0.015427153557538986,
-0.057788360863924026,
0.02510054036974907,
-0.0198820773512125,
0.005842466838657856,
0.020492536947131157,
0.006926310248672962,
-0.04663025215268135,
-0.0015618522884324193,
-0.029459532350301743,
0.03617801517248154,
0.01863124966621399,
0.05645188316702843,
0.01596313714981079,
-0.015908867120742798,
0.03386465087532997,
-0.03420824557542801,
-0.0006777055677957833,
-0.03275252878665924,
-0.000806580064818263,
0.03362618386745453,
0.01841539330780506,
-0.023351427167654037,
-0.08984250575304031,
0.02681904286146164,
0.004986190237104893,
0.029717279598116875,
0.0023018752690404654,
0.005873542279005051,
-0.04737762734293938,
0.02855592966079712,
-0.024796225130558014,
-0.006251224782317877,
-0.03533116728067398,
-0.023534463718533516,
0.03173059970140457,
-0.000738790025934577,
0.014068960212171078,
-0.032250985503196716,
0.0022025734651833773,
0.025124935433268547,
-0.04566110298037529,
0.006358788348734379,
0.046553850173950195,
-0.027871692553162575,
-0.004343765787780285,
-0.01721971295773983,
-0.0005339193157851696,
-0.01147543080151081,
-0.03470899164676666,
-0.01793820969760418,
0.004476074129343033,
-0.012675684876739979,
-0.01872052438557148,
0.02669726498425007,
-0.030241547152400017,
0.02520446851849556,
0.002324403263628483,
-0.02424238994717598,
0.011789298616349697,
-0.03714694827795029,
-0.023746779188513756,
0.0029591110069304705,
0.029119964689016342,
-0.006301102228462696,
-0.022261902689933777,
-0.028193285688757896,
0.01599542610347271
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.