content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. import numpy import pytest import vector.backends.numpy_ import vector.backends.object_
[ 2, 15069, 357, 66, 8, 13130, 12, 1238, 2481, 11, 40458, 8678, 354, 293, 11, 5395, 350, 452, 945, 4106, 11, 40766, 13109, 16114, 947, 11, 290, 8616, 3059, 260, 7274, 13, 198, 2, 198, 2, 4307, 6169, 739, 262, 513, 12, 565, 682, 34...
3.106796
103
#!/usr/bin/env python3 import os # imports for array-handling import numpy as np import tensorflow as tf # keras imports for the dataset and building our neural network from tensorflow.keras.datasets import mnist from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Dropout # let's keep our keras backend tensorflow quiet os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # load mnist dataset (X_train, y_train), (X_test, y_test) = mnist.load_data() # building the input vector from the 28x28 pixels X_train = X_train.reshape(60000, 784) X_test = X_test.reshape(10000, 784) X_train = X_train.astype('float32') X_test = X_test.astype('float32') # Split the train set in a train + validation set X_valid = X_train[50000:] y_valid = y_train[50000:] X_train = X_train[:50000] y_train = y_train[:50000] # Normalize the data X_train = X_train / 255.0 X_test = X_test / 255.0 X_valid = X_valid / 255.0 # building a very simple linear stack of layers using a sequential model model = Sequential([ Dense(64, activation='relu', input_shape=(784,)), Dropout(0.2), Dense(10, activation='softmax') ]) # compiling the sequential model model.compile(loss='sparse_categorical_crossentropy', metrics=['accuracy'], optimizer='adam') batch_size = 32 epochs = 30 # training the model and saving metrics in history history = model.fit(X_train, y_train, batch_size=batch_size, epochs=epochs, verbose=2, validation_data=(X_valid, y_valid)) # saving the model # Convert the model to the TensorFlow Lite format without quantization converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert() # Save the basic model to disk open("model_basic.tflite", "wb").write(tflite_model) # Convert the model to the TensorFlow Lite format with quantization converter = tf.lite.TFLiteConverter.from_keras_model(model) (mnist_train, _), (_, _) = mnist.load_data() mnist_train = mnist_train.reshape(60000, 784) mnist_train = mnist_train.astype('float32') mnist_train = mnist_train / 255.0 mnist_ds = tf.data.Dataset.from_tensor_slices((mnist_train)).batch(1) converter.representative_dataset = representative_data_gen converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] tflite_model = converter.convert() # # Save the quantized model to disk open("model.tflite", "wb").write(tflite_model) basic_model_size = os.path.getsize("model_basic.tflite") print("Basic model is %d bytes" % basic_model_size) quantized_model_size = os.path.getsize("model.tflite") print("Quantized model is %d bytes" % quantized_model_size) difference = basic_model_size - quantized_model_size print("Difference is %d bytes" % difference) # Now let's verify the model on a few input digits # Instantiate an interpreter for the model model_quantized_reloaded = tf.lite.Interpreter('model.tflite') # Allocate memory for each model model_quantized_reloaded.allocate_tensors() # Get the input and output tensors so we can feed in values and get the results model_quantized_input = model_quantized_reloaded.get_input_details()[0]["index"] model_quantized_output = model_quantized_reloaded.get_output_details()[0]["index"] # Create arrays to store the results model_quantized_predictions = np.empty(X_test.size) for i in range(10): # Invoke the interpreter model_quantized_reloaded.set_tensor(model_quantized_input, X_test[i:i+1, :]) model_quantized_reloaded.invoke() model_quantized_prediction = model_quantized_reloaded.get_tensor(model_quantized_output) print("Digit: {} - Prediction:\n{}".format(y_test[i], model_quantized_prediction)) print("")
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 11748, 28686, 198, 198, 2, 17944, 329, 7177, 12, 4993, 1359, 198, 11748, 299, 32152, 355, 45941, 198, 198, 11748, 11192, 273, 11125, 355, 48700, 198, 198, 2, 41927, 292, 17944...
2.719764
1,356
import random values = [random.gauss(1, .5) for i in range(1000)]
[ 11748, 4738, 198, 27160, 796, 685, 25120, 13, 4908, 1046, 7, 16, 11, 764, 20, 8, 329, 1312, 287, 2837, 7, 12825, 15437, 628 ]
2.791667
24
# This python script handles stock api request from yfinance # Last Updated: 4/7/2020 # Credits:nto #Import yfinance api lib import yfinance as yf #Import pandas lib import pandas as pd #Import json to manipulate api data import json #Import math import math
[ 2, 770, 21015, 4226, 17105, 4283, 40391, 2581, 422, 331, 69, 14149, 198, 2, 4586, 19433, 25, 604, 14, 22, 14, 42334, 198, 2, 29501, 25, 429, 78, 198, 198, 2, 20939, 331, 69, 14149, 40391, 9195, 198, 11748, 331, 69, 14149, 355, 331...
3.376623
77
from datetime import date from random import randrange import factory import factory.fuzzy from hth.core.tests.utils import from_today
[ 6738, 4818, 8079, 1330, 3128, 198, 198, 6738, 4738, 1330, 43720, 9521, 198, 198, 11748, 8860, 198, 11748, 8860, 13, 69, 4715, 88, 198, 198, 6738, 289, 400, 13, 7295, 13, 41989, 13, 26791, 1330, 422, 62, 40838, 628, 628, 628 ]
3.487805
41
"""Support for Eight Sleep binary sensors.""" from __future__ import annotations import logging from pyeight.eight import EightSleep from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from . import ( CONF_BINARY_SENSORS, DATA_API, DATA_EIGHT, DATA_HEAT, EightSleepBaseEntity, EightSleepHeatDataCoordinator, ) _LOGGER = logging.getLogger(__name__)
[ 37811, 15514, 329, 18087, 17376, 13934, 15736, 526, 15931, 198, 6738, 11593, 37443, 834, 1330, 37647, 198, 198, 11748, 18931, 198, 198, 6738, 279, 5948, 432, 13, 26022, 1330, 18087, 40555, 198, 198, 6738, 1363, 562, 10167, 13, 5589, 3906,...
3.120603
199
#!/usr/bin/env python3 # # Copyright 2021 Graviti. Licensed under MIT License. # # pylint: disable=invalid-name # pylint: disable=missing-module-docstring import os from typing import Any, Dict, Iterator, Tuple from tensorbay.dataset import Data, Dataset from tensorbay.exception import ModuleImportError from tensorbay.label import Classification, LabeledBox2D, LabeledKeypoints2D DATASET_NAME = "FLIC" _VALID_KEYPOINT_INDICES = [0, 1, 2, 3, 4, 5, 6, 9, 12, 13, 16] def FLIC(path: str) -> Dataset: """`FLIC <https://bensapp.github.io/flic-dataset.html>`_ dataset. The folder structure should be like:: <path> exampls.mat images/ 2-fast-2-furious-00003571.jpg ... Arguments: path: The root directory of the dataset. Raises: ModuleImportError: When the module "scipy" can not be found. Returns: Loaded :class:`~tensorbay.dataset.dataset.Dataset` instance. """ try: from scipy.io import loadmat # pylint: disable=import-outside-toplevel except ModuleNotFoundError as error: raise ModuleImportError(module_name=error.name) from error root_path = os.path.abspath(os.path.expanduser(path)) dataset = Dataset(DATASET_NAME) annotations = loadmat(os.path.join(root_path, "examples.mat"))["examples"][0] dataset.create_segment("train") dataset.create_segment("test") dataset.load_catalog(os.path.join(os.path.dirname(__file__), "catalog.json")) # try whether the dataset has bad segment try: _ = annotations["isbad"] flag = True dataset.create_segment("bad") dataset.catalog.classification.add_attribute(name="isunchecked", type_="boolean") except ValueError: flag = False for data, segment_name in _get_data(root_path, annotations, flag): dataset[segment_name].append(data) return dataset
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 198, 2, 15069, 33448, 32599, 8846, 13, 49962, 739, 17168, 13789, 13, 198, 2, 198, 2, 279, 2645, 600, 25, 15560, 28, 259, 12102, 12, 3672, 198, 2, 279, 2645, 600, 25, 15560, ...
2.462324
783
def get_durations(distances, athletes): for distance in distances: for athlete in athletes: print(f'{athlete.run(distance)} ran {distance} meters in {get_time(athlete.get_duration(distance))}') if __name__ == "__main__": runr = Runner("run", 90, 15, 30) sprt1 = Sprinter("sprnt1", 90, 15, 30) sprt2 = Sprinter("sprnt2", 80, 10, 25) mrtn = MarathonRunner("mrtn", 50, 6, 7) # print('getting running time..') # print(f'{runr.run(100)} ran for {runr.get_duration(100)}') distances = (100, 200, 800, 1600, 5000, 20000) athletes = (runr, sprt1, sprt2, mrtn) get_durations(distances, athletes)
[ 198, 4299, 651, 62, 67, 20074, 7, 17080, 1817, 11, 10856, 2599, 198, 220, 220, 220, 329, 5253, 287, 18868, 25, 198, 220, 220, 220, 220, 220, 220, 220, 329, 16076, 287, 10856, 25, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, ...
2.397059
272
# coding: utf-8 """ Copyright 2018 OSIsoft, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at <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 pprint import pformat from six import iteritems
[ 2, 19617, 25, 3384, 69, 12, 23, 198, 198, 37811, 198, 197, 15269, 2864, 7294, 40, 4215, 11, 11419, 198, 197, 26656, 15385, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 197, 5832, 743, 407, 779, ...
3.577778
180
#! /root/anaconda3/bin/python import os from apscheduler.schedulers.asyncio import AsyncIOScheduler from pyrogram import Client, filters from read_config import read_config import json import requests import schedule import time config_data = read_config('./config/config_bot.json') app = Client(config_data['bot_user_name'], config_data['api_id'], config_data['api_hash']) # @app.on_message(filters.command('help')) app.run()
[ 2, 0, 1220, 15763, 14, 272, 330, 13533, 18, 14, 8800, 14, 29412, 198, 11748, 28686, 198, 6738, 257, 862, 1740, 18173, 13, 1416, 704, 377, 364, 13, 292, 13361, 952, 1330, 1081, 13361, 40, 2640, 1740, 18173, 198, 6738, 12972, 39529, 1...
2.965517
145
# Copyright (c) AIRBUS and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Dict, Tuple from skdecide.discrete_optimization.rcpsp_multiskill.rcpsp_multiskill import ( Employee, MS_RCPSPModel, SkillDetail, )
[ 2, 15069, 357, 66, 8, 31600, 45346, 290, 663, 29116, 13, 198, 2, 770, 2723, 2438, 318, 11971, 739, 262, 17168, 5964, 1043, 287, 262, 198, 2, 38559, 24290, 2393, 287, 262, 6808, 8619, 286, 428, 2723, 5509, 13, 198, 198, 6738, 11593, ...
3.181034
116
import logging # monkey patch to suppress the annoying warning you get when you import apache_beam # # No handlers could be found for logger "oauth2client.contrib.multistore_file" # # This warning is harmless, but annooying when you are using beam from a command line app # see: https://issues.apache.org/jira/browse/BEAM-1183 # This just creates a null handler for that logger so there is no output logger = logging.getLogger('oauth2client.contrib.multistore_file') handler = logging.NullHandler() logger.addHandler(handler)
[ 11748, 18931, 198, 198, 2, 21657, 8529, 284, 18175, 262, 15774, 6509, 345, 651, 618, 345, 1330, 2471, 4891, 62, 40045, 198, 2, 198, 2, 1400, 32847, 714, 307, 1043, 329, 49706, 366, 12162, 1071, 17, 16366, 13, 3642, 822, 13, 16680, 3...
3.464052
153
from django.db import models
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 628 ]
3.75
8
""" All scales have a means by which the values that are mapped onto the scale are interpreted. Numeric digital scales put out numbers for direct interpretation, but most scales cannot do this. What they offer is named markers/ticks that aid in assessing the values e.g. the common odometer will have ticks and values to help gauge the speed of the vehicle. The named markers are what we call breaks. Properly calculated breaks make interpretation straight forward. These functions provide ways to calculate good(hopefully) breaks. """ from __future__ import division import numpy as np import pandas as pd from matplotlib.dates import MinuteLocator, HourLocator, DayLocator from matplotlib.dates import WeekdayLocator, MonthLocator, YearLocator from matplotlib.dates import AutoDateLocator from matplotlib.dates import num2date, YEARLY from matplotlib.ticker import MaxNLocator from .utils import min_max, SECONDS, NANOSECONDS from .utils import same_log10_order_of_magnitude __all__ = ['mpl_breaks', 'log_breaks', 'minor_breaks', 'trans_minor_breaks', 'date_breaks', 'timedelta_breaks', 'extended_breaks'] # The break calculations rely on MPL locators to do # the heavylifting. It may be more convinient to lift # the calculations out of MPL. # Matplotlib's YearLocator uses different named # arguments than the others LOCATORS = { 'minute': MinuteLocator, 'hour': HourLocator, 'day': DayLocator, 'week': WeekdayLocator, 'month': MonthLocator, 'year': lambda interval: YearLocator(base=interval) } # This could be cleaned up, state overload? def value(self, td): """ Return the numeric value representation on a timedelta """ if self.package == 'pandas': return td.value else: return td.total_seconds() def scaled_limits(self): """ Minimum and Maximum to use for computing breaks """ _min = self.limits[0]/self.factor _max = self.limits[1]/self.factor return _min, _max def timedelta_to_numeric(self, timedeltas): """ Convert sequence of timedelta to numerics """ return [self.to_numeric(td) for td in timedeltas] def numeric_to_timedelta(self, numerics): """ Convert sequence of numerics to timedelta """ if self.package == 'pandas': return [self.type(int(x*self.factor), units='ns') for x in numerics] else: return [self.type(seconds=x*self.factor) for x in numerics] def get_scaling_factor(self, units): if self.package == 'pandas': return NANOSECONDS[units] else: return SECONDS[units] def to_numeric(self, td): """ Convert timedelta to a number corresponding to the appropriate units. The appropriate units are those determined with the object is initialised. """ if self.package == 'pandas': return td.value/NANOSECONDS[self.units] else: return td.total_seconds()/SECONDS[self.units] class extended_breaks(object): """ An extension of Wilkinson's tick position algorithm Parameters ---------- n : int Desired number of ticks Q : list List of nice numbers only_inside : bool If ``True``, then all the ticks will be within the given range. w : list Weights applied to the four optimization components (simplicity, coverage, density, and legibility). They should add up to 1. Examples -------- >>> limits = (0, 9) >>> extended_breaks()(limits) array([ 0. , 2.5, 5. , 7.5, 10. ]) >>> extended_breaks(n=6)(limits) array([ 0., 2., 4., 6., 8., 10.]) References ---------- - Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010. Additional Credit to Justin Talbot on whose code this implementation is almost entirely based. """ def __call__(self, limits): """ Calculate the breaks Parameters ---------- limits : array Minimum and maximum values. Returns ------- out : array_like Sequence of break points. """ Q = self.Q w = self.w only_inside = self.only_inside simplicity_max = self.simplicity_max density_max = self.density_max coverage_max = self.coverage_max simplicity = self.simplicity coverage = self.coverage density = self.density legibility = self.legibility log10 = np.log10 ceil = np.ceil floor = np.floor dmin, dmax = limits if dmin > dmax: dmin, dmax = dmax, dmin elif dmin == dmax: return np.array([dmin]) best_score = -2 j = 1 while j < float('inf'): for q in Q: sm = simplicity_max(q, j) if w[0]*sm + w[1] + w[2] + w[3] < best_score: j = float('inf') break k = 2 while k < float('inf'): dm = density_max(k) if w[0]*sm + w[1] + w[2]*dm + w[3] < best_score: break delta = (dmax-dmin)/(k+1)/j/q z = ceil(log10(delta)) while z < float('inf'): step = j*q*(10**z) cm = coverage_max(dmin, dmax, step*(k-1)) if w[0]*sm + w[1]*cm + w[2]*dm + w[3] < best_score: break min_start = int(floor(dmax/step)*j - (k-1)*j) max_start = int(ceil(dmin/step)*j) if min_start > max_start: z = z+1 break for start in range(min_start, max_start+1): lmin = start * (step/j) lmax = lmin + step*(k-1) lstep = step s = simplicity(q, j, lmin, lmax, lstep) c = coverage(dmin, dmax, lmin, lmax) d = density(k, dmin, dmax, lmin, lmax) l = legibility(lmin, lmax, lstep) score = w[0]*s + w[1]*c + w[2]*d + w[3]*l if (score > best_score and (not only_inside or (lmin >= dmin and lmax <= dmax))): best_score = score best = (lmin, lmax, lstep, q, k) z = z+1 k = k+1 j = j+1 try: locs = best[0] + np.arange(best[4])*best[2] except UnboundLocalError: locs = [] return locs
[ 37811, 198, 3237, 16252, 423, 257, 1724, 416, 543, 262, 3815, 326, 389, 27661, 198, 5957, 262, 5046, 389, 16173, 13, 399, 39223, 4875, 16252, 1234, 198, 448, 3146, 329, 1277, 10794, 11, 475, 749, 16252, 198, 66, 34574, 466, 428, 13, ...
2.02495
3,527
# Copyright 2022 NREL # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. # See https://floris.readthedocs.io for documentation import matplotlib.pyplot as plt import numpy as np from floris.tools import FlorisInterface from floris.tools.visualization import visualize_cut_plane """ 04_sweep_wind_directions This example demonstrates vectorization of wind direction. A vector of wind directions is passed to the intialize function and the powers of the two simulated turbines is computed for all wind directions in one call The power of both turbines for each wind direction is then plotted """ # Instantiate FLORIS using either the GCH or CC model fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2 # fi = FlorisInterface("inputs/cc.yaml") # New CumulativeCurl model # Define a two turbine farm D = 126. layout_x = np.array([0, D*6]) layout_y = [0, 0] fi.reinitialize(layout = [layout_x, layout_y]) # Sweep wind speeds but keep wind direction fixed wd_array = np.arange(250,291,1.) fi.reinitialize(wind_directions=wd_array) # Define a matrix of yaw angles to be all 0 # Note that yaw angles is now specified as a matrix whose dimesions are # wd/ws/turbine num_wd = len(wd_array) # Number of wind directions num_ws = 1 # Number of wind speeds num_turbine = len(layout_x) # Number of turbines yaw_angles = np.zeros((num_wd, num_ws, num_turbine)) # Calculate fi.calculate_wake(yaw_angles=yaw_angles) # Collect the turbine powers turbine_powers = fi.get_turbine_powers() / 1E3 # In kW # Pull out the power values per turbine pow_t0 = turbine_powers[:,:,0].flatten() pow_t1 = turbine_powers[:,:,1].flatten() # Plot fig, ax = plt.subplots() ax.plot(wd_array,pow_t0,color='k',label='Upstream Turbine') ax.plot(wd_array,pow_t1,color='r',label='Downstream Turbine') ax.grid(True) ax.legend() ax.set_xlabel('Wind Direction (deg)') ax.set_ylabel('Power (kW)') plt.show()
[ 2, 15069, 33160, 399, 16448, 198, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 345, 743, 407, 198, 2, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 921, 743, 7330, 257, 4866, ...
3.084399
782
import numpy import numpy as np # converting to a layer with 4 input and 3 neuron inputs = [[1.2, 2.1, 3.4, 1.2], [1.2, 2.1, 3.4, 1.2], [1.2, 2.1, 3.4, 1.2]] print(numpy.shape(inputs)) weights = [[4.1, -4.5, 3.1, 2.3], [-4.1, 4.5, 2.1, 2.3], [4.1, 4.5, 3.1, -2.3]] print(numpy.shape(weights)) biases = [1, 2, 3] weights2 = [[4.1, -4.5, 3.1], [-4.1, 4.5, 2.1], [4.1, 4.5, 3.1]] biases2 = [1, 2, 3] layer1_outputs = np.dot(inputs, np.array(weights).T) + biases layer2_outputs = np.dot(layer1_outputs, np.array(weights2).T) + biases2 print(layer2_outputs)
[ 11748, 299, 32152, 198, 11748, 299, 32152, 355, 45941, 198, 198, 2, 23202, 284, 257, 7679, 351, 604, 5128, 290, 513, 43164, 198, 15414, 82, 796, 16410, 16, 13, 17, 11, 362, 13, 16, 11, 513, 13, 19, 11, 352, 13, 17, 4357, 198, 22...
1.769886
352
from . import models from . import views from . import commands from . import jobs
[ 6738, 764, 1330, 4981, 198, 6738, 764, 1330, 5009, 198, 198, 6738, 764, 1330, 9729, 198, 6738, 764, 1330, 3946 ]
4.15
20
""" This is a Django_ integration of Select2_. The application includes Select2 driven Django Widgets and Form Fields. .. _Django: https://www.djangoproject.com/ .. _Select2: https://select2.org/ """ from django import get_version if get_version() < '3.2': default_app_config = "django_select2.apps.Select2AppConfig"
[ 37811, 198, 1212, 318, 257, 37770, 62, 11812, 286, 9683, 17, 44807, 198, 198, 464, 3586, 3407, 9683, 17, 7986, 37770, 24801, 11407, 290, 5178, 23948, 13, 198, 198, 492, 4808, 35, 73, 14208, 25, 3740, 1378, 2503, 13, 28241, 648, 404, ...
2.981651
109
# O(n ** 2) print(bubble_sort([8, 1, 13, 34, 5, 2, 21, 3, 1], False)) print(bubble_sort([1, 2, 3, 4, 5, 6]))
[ 2, 440, 7, 77, 12429, 362, 8, 628, 198, 4798, 7, 46176, 903, 62, 30619, 26933, 23, 11, 352, 11, 1511, 11, 4974, 11, 642, 11, 362, 11, 2310, 11, 513, 11, 352, 4357, 10352, 4008, 198, 4798, 7, 46176, 903, 62, 30619, 26933, 16, 1...
1.913793
58
"A Console-Based Email Client" #!/usr/local/bin/python """ ########################################################################## pymail - a simple console email interface client in Python; uses Python poplib module to view POP email messages, smtplib to send new mails, and the email package to extract mail headers and payload and compose mails; ########################################################################## """ import poplib, smtplib, email.utils, mailconfig from email.parser import Parser from email.message import Message fetchEncoding = mailconfig.fetchEncoding def decodeToUnicode(messageBytes, fetchEncoding=fetchEncoding): """ 4E, Py3.1: decode fetched bytes to str Unicode string for display or parsing; use global setting (or by platform default, hdrs inspection, intelligent guess); in Python 3.2/3.3, this step may not be required: if so, return message intact; """ return [line.decode(fetchEncoding) for line in messageBytes] def splitaddrs(field): """ 4E: split address list on commas, allowing for commas in name parts """ pairs = email.utils.getaddresses([field]) # [(name,addr)] return [email.utils.formataddr(pair) for pair in pairs] # [name <addr>] helptext = """ Available commands: i - index display l n? - list all messages (or just message n) d n? - mark all messages for deletion (or just message n) s n? - save all messages to a file (or just message n) m - compose and send a new mail message q - quit pymail ? - display this help text """ if __name__ == '__main__': import getpass, mailconfig mailserver = mailconfig.popservername # ex: 'pop.rmi.net' mailuser = mailconfig.popusername # ex: 'lutz' mailfile = mailconfig.savemailfile # ex: r'c:\stuff\savemail' mailpswd = getpass.getpass('Password for %s?' % mailserver) print('[Pymail email client]') msgList = loadmessages(mailserver, mailuser, mailpswd) # load all toDelete = interact(msgList, mailfile) if toDelete: deletemessages(mailserver, mailuser, mailpswd, toDelete) print('Bye.')
[ 1, 32, 24371, 12, 15001, 9570, 20985, 1, 198, 198, 2, 48443, 14629, 14, 12001, 14, 8800, 14, 29412, 198, 37811, 198, 29113, 29113, 7804, 2235, 198, 9078, 4529, 532, 257, 2829, 8624, 3053, 7071, 5456, 287, 11361, 26, 3544, 11361, 198, ...
3.006974
717
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (c) 2017~2999 - cologler <skyoflw@gmail.com> # ---------- # # ---------- import typing import inspect from .errors import ParameterTypeResolveError
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 198, 2, 15069, 357, 66, 8, 2177, 93, 1959, 2079, 532, 269, 928, 1754, 1279, 15688, 1659, 75, 86, 31, 14816, 13, ...
2.714286
77
import io import os from flask import Flask, request, jsonify from PIL import Image from resnet_model import MyResnetModel app = Flask(__name__) # max filesize 2mb app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 * 1024 # setup resnet model model = MyResnetModel(os.path.dirname(os.path.abspath(__file__)))
[ 11748, 33245, 198, 11748, 28686, 198, 6738, 42903, 1330, 46947, 11, 2581, 11, 33918, 1958, 198, 6738, 350, 4146, 1330, 7412, 198, 6738, 581, 3262, 62, 19849, 1330, 2011, 4965, 3262, 17633, 198, 198, 1324, 796, 46947, 7, 834, 3672, 834, ...
2.951923
104
from django.urls import reverse from rest_framework import status from .base import BaseTestCase
[ 6738, 42625, 14208, 13, 6371, 82, 1330, 9575, 198, 6738, 1334, 62, 30604, 1330, 3722, 198, 6738, 764, 8692, 1330, 7308, 14402, 20448, 628 ]
4.083333
24
# -*- coding: utf-8 -*- """ =============================================================================== module __GenericPhase__: Base class for building Phase objects =============================================================================== """ from OpenPNM.Network import GenericNetwork import OpenPNM.Phases.models from OpenPNM.Base import Core, Tools, logging import scipy as sp logger = logging.getLogger(__name__)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 23926, 25609, 18604, 198, 21412, 11593, 46189, 35645, 834, 25, 7308, 1398, 329, 2615, 18983, 5563, 198, 23926, 25609, 18604, 198, 198, 37811, 198, 6738, 4946, ...
4.585106
94
#!/usr/bin/env python3 import sys import copy from moveit_commander import move_group import rospy import moveit_commander import moveit_msgs.msg import geometry_msgs.msg from math import pi, sqrt, pow from std_msgs.msg import String import io import shutil import json #used to convert the points from the gui in a valid message for ros from geometry_msgs.msg import Pose, PoseStamped #used to read out the start points import os from nav_msgs.msg import Path #used for publishing the planned path from start to goal from visualization_msgs.msg import Marker, MarkerArray #used to make a service request from moveit_msgs.srv import GetPositionIKRequest, GetPositionIK from rqt_mypkg import path_planning_interface from trajectory_msgs.msg import JointTrajectoryPoint ## StatsitcisDefinedPath is used to get the path length of given points/positions generated by the Motion Plan
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 11748, 25064, 198, 11748, 4866, 198, 6738, 1445, 270, 62, 9503, 4066, 1330, 1445, 62, 8094, 198, 11748, 686, 2777, 88, 198, 11748, 1445, 270, 62, 9503, 4066, 198, 11748, 1445,...
3.513944
251
# -*- coding: utf-8 -*- from django.contrib import admin from .models import Mail admin.site.register(Mail, MailAdmin)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 198, 6738, 764, 27530, 1330, 11099, 628, 198, 198, 28482, 13, 15654, 13, 30238, 7, 25804, 11, 11099, 46787, 8, ...
2.755556
45
from uuid import uuid4 from fastapi.testclient import TestClient from ..main import app client = TestClient(app)
[ 6738, 334, 27112, 1330, 334, 27112, 19, 198, 198, 6738, 3049, 15042, 13, 9288, 16366, 1330, 6208, 11792, 198, 198, 6738, 11485, 12417, 1330, 598, 198, 198, 16366, 796, 6208, 11792, 7, 1324, 8, 628, 198 ]
3.277778
36
#!/usr/bin/python """ (C) Copyright 2019 Intel Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings. """ from __future__ import print_function import os import time from apricot import TestWithServers from ior_utils import IorCommand import slurm_utils from test_utils_pool import TestPool from test_utils_container import TestContainer from ClusterShell.NodeSet import NodeSet from general_utils import pcmd import socket
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 37811, 198, 7, 34, 8, 15069, 13130, 8180, 10501, 13, 198, 198, 26656, 15385, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 5832, 743, 407, 779, 428, 239...
4.003096
323
"""This is the Solution for Year 2020 Day 06""" import re from aoc.abstracts.solver import Answers, StrLines
[ 37811, 1212, 318, 262, 28186, 329, 6280, 12131, 3596, 9130, 37811, 198, 198, 11748, 302, 198, 198, 6738, 257, 420, 13, 397, 8709, 82, 13, 82, 14375, 1330, 42612, 11, 4285, 43, 1127, 628 ]
3.294118
34
from setuptools import find_packages, setup setup( name="typer", packages=find_packages(), )
[ 6738, 900, 37623, 10141, 1330, 1064, 62, 43789, 11, 9058, 198, 198, 40406, 7, 198, 220, 220, 220, 1438, 2625, 774, 525, 1600, 10392, 28, 19796, 62, 43789, 22784, 198, 8, 198 ]
3.0625
32
import numpy as np from numba import jit, prange from scipy.stats import mode from sklearn.metrics import accuracy_score __all__ = ['dtw_distance', 'KnnDTW'] # Modified from https://github.com/markdregan/K-Nearest-Neighbors-with-Dynamic-Time-Warping class KnnDTW(object): """K-nearest neighbor classifier using dynamic time warping as the distance measure between pairs of time series arrays Arguments --------- n_neighbors : int, optional (default = 1) Number of neighbors to use by default for KNN """ def fit(self, x, y): """Fit the model using x as training data and y as class labels Arguments --------- x : array of shape [n_samples, n_timepoints] Training data set for input into KNN classifer y : array of shape [n_samples] Training labels for input into KNN classifier """ self.x = np.copy(x) self.y = np.copy(y) def _dist_matrix(self, x, y): """Computes the M x N distance matrix between the training dataset and testing dataset (y) using the DTW distance measure Arguments --------- x : array of shape [n_samples, n_timepoints] y : array of shape [n_samples, n_timepoints] Returns ------- Distance matrix between each item of x and y with shape [training_n_samples, testing_n_samples] """ dm = dtw_distance(x, y) return dm def predict(self, x): """Predict the class labels or probability estimates for the provided data Arguments --------- x : array of shape [n_samples, n_timepoints] Array containing the testing data set to be classified Returns ------- 2 arrays representing: (1) the predicted class labels (2) the knn label count probability """ np.random.seed(0) dm = self._dist_matrix(x, self.x) # Identify the k nearest neighbors knn_idx = dm.argsort()[:, :self.n_neighbors] # Identify k nearest labels knn_labels = self.y[knn_idx] # Model Label mode_data = mode(knn_labels, axis=1) mode_label = mode_data[0] mode_proba = mode_data[1] / self.n_neighbors return mode_label.ravel(), mode_proba.ravel() def evaluate(self, x, y): """ Predict the class labels or probability estimates for the provided data and then evaluates the accuracy score. Arguments --------- x : array of shape [n_samples, n_timepoints] Array containing the testing data set to be classified y : array of shape [n_samples] Array containing the labels of the testing dataset to be classified Returns ------- 1 floating point value representing the accuracy of the classifier """ # Predict the labels and the probabilities pred_labels, pred_probas = self.predict(x) # Ensure labels are integers y = y.astype('int32') pred_labels = pred_labels.astype('int32') # Compute accuracy measure accuracy = accuracy_score(y, pred_labels) return accuracy def predict_proba(self, x): """Predict the class labels probability estimates for the provided data Arguments --------- x : array of shape [n_samples, n_timepoints] Array containing the testing data set to be classified Returns ------- 2 arrays representing: (1) the predicted class probabilities (2) the knn labels """ np.random.seed(0) dm = self._dist_matrix(x, self.x) # Invert the distance matrix dm = -dm classes = np.unique(self.y) class_dm = [] # Partition distance matrix by class for i, cls in enumerate(classes): idx = np.argwhere(self.y == cls)[:, 0] cls_dm = dm[:, idx] # [N_test, N_train_c] # Take maximum distance vector due to softmax probabilities cls_dm = np.max(cls_dm, axis=-1) # [N_test,] class_dm.append([cls_dm]) # Concatenate the classwise distance matrices and transpose class_dm = np.concatenate(class_dm, axis=0) # [C, N_test] class_dm = class_dm.transpose() # [N_test, C] # Compute softmax probabilities class_dm_exp = np.exp(class_dm - class_dm.max()) class_dm = class_dm_exp / np.sum(class_dm_exp, axis=-1, keepdims=True) probabilities = class_dm knn_labels = np.argmax(class_dm, axis=-1) return probabilities, knn_labels
[ 11748, 299, 32152, 355, 45941, 198, 6738, 997, 7012, 1330, 474, 270, 11, 778, 858, 198, 6738, 629, 541, 88, 13, 34242, 1330, 4235, 198, 6738, 1341, 35720, 13, 4164, 10466, 1330, 9922, 62, 26675, 198, 198, 834, 439, 834, 796, 37250, ...
2.305248
2,077
from setuptools import setup setup( name='uam_simulator', version='1.0', description='A tool to simulate different architectures for UAM traffic management', author='Coline Ramee', author_email='coline.ramee@gatech.edu', packages=['uam_simulator'], install_requires=['numpy', 'scikit-learn', 'gurobipy'] ) # If installing from source the package name is gurobipy, if installing with conda it's gurobi, but when importing it's still gurobipy
[ 6738, 900, 37623, 10141, 1330, 9058, 198, 198, 40406, 7, 198, 220, 220, 220, 1438, 11639, 84, 321, 62, 14323, 8927, 3256, 198, 220, 220, 220, 2196, 11639, 16, 13, 15, 3256, 198, 220, 220, 220, 6764, 11639, 32, 2891, 284, 29308, 1180...
2.955975
159
if __name__ == '__main__': sol=Solution() arr = ["un", "iq", "ue"] # arr = ["cha", "r", "act", "ers"] # arr = ["abcdefghijklmnopqrstuvwxyz"] # arr=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"] print(sol.maxLength(arr))
[ 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 1540, 28, 46344, 3419, 198, 220, 220, 220, 5240, 796, 14631, 403, 1600, 366, 25011, 1600, 366, 518, 8973, 198, 220, 220, 220, 1303, 5240, 796, 14631, ...
1.931507
146
# Generated by Django 3.0.6 on 2020-05-25 22:13 from django.db import migrations, models
[ 2, 2980, 515, 416, 37770, 513, 13, 15, 13, 21, 319, 12131, 12, 2713, 12, 1495, 2534, 25, 1485, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 628 ]
2.84375
32
from collections import namedtuple from datetime import timedelta import itertools from operator import attrgetter from pando.utils import utcnow from psycopg2.extras import execute_batch from ..constants import SEPA from ..exceptions import ( AccountSuspended, MissingPaymentAccount, RecipientAccountSuspended, NoSelfTipping, UserDoesntAcceptTips, ) from ..i18n.currencies import Money, MoneyBasket from ..utils import group_by ProtoTransfer = namedtuple( 'ProtoTransfer', 'amount recipient destination context unit_amount period team visibility', ) def prepare_payin(db, payer, amount, route, proto_transfers, off_session=False): """Prepare to charge a user. Args: payer (Participant): the user who will be charged amount (Money): the presentment amount of the charge route (ExchangeRoute): the payment instrument to charge proto_transfers ([ProtoTransfer]): the transfers to prepare off_session (bool): `True` means that the payment is being initiated because it was scheduled, `False` means that the payer has initiated the operation just now Returns: Record: the row created in the `payins` table Raises: AccountSuspended: if the payer's account is suspended """ assert isinstance(amount, Money), type(amount) assert route.participant == payer, (route.participant, payer) assert route.status in ('pending', 'chargeable') if payer.is_suspended or not payer.get_email_address(): raise AccountSuspended() with db.get_cursor() as cursor: payin = cursor.one(""" INSERT INTO payins (payer, amount, route, status, off_session) VALUES (%s, %s, %s, 'pre', %s) RETURNING * """, (payer.id, amount, route.id, off_session)) cursor.run(""" INSERT INTO payin_events (payin, status, error, timestamp) VALUES (%s, %s, NULL, current_timestamp) """, (payin.id, payin.status)) payin_transfers = [] for t in proto_transfers: payin_transfers.append(prepare_payin_transfer( cursor, payin, t.recipient, t.destination, t.context, t.amount, t.visibility, t.unit_amount, t.period, t.team, )) return payin, payin_transfers def update_payin( db, payin_id, remote_id, status, error, amount_settled=None, fee=None, intent_id=None, refunded_amount=None, ): """Update the status and other attributes of a charge. Args: payin_id (int): the ID of the charge in our database remote_id (str): the ID of the charge in the payment processor's database status (str): the new status of the charge error (str): if the charge failed, an error message to show to the payer Returns: Record: the row updated in the `payins` table """ with db.get_cursor() as cursor: payin = cursor.one(""" UPDATE payins SET status = %(status)s , error = %(error)s , remote_id = coalesce(remote_id, %(remote_id)s) , amount_settled = coalesce(amount_settled, %(amount_settled)s) , fee = coalesce(fee, %(fee)s) , intent_id = coalesce(intent_id, %(intent_id)s) , refunded_amount = coalesce(%(refunded_amount)s, refunded_amount) WHERE id = %(payin_id)s RETURNING * , (SELECT status FROM payins WHERE id = %(payin_id)s) AS old_status """, locals()) if not payin: return if remote_id and payin.remote_id != remote_id: raise AssertionError(f"the remote IDs don't match: {payin.remote_id!r} != {remote_id!r}") if status != payin.old_status: cursor.run(""" INSERT INTO payin_events (payin, status, error, timestamp) VALUES (%s, %s, %s, current_timestamp) """, (payin_id, status, error)) if status in ('pending', 'succeeded'): cursor.run(""" UPDATE exchange_routes SET status = 'consumed' WHERE id = %s AND one_off IS TRUE """, (payin.route,)) # Lock to avoid concurrent updates cursor.run("SELECT * FROM participants WHERE id = %s FOR UPDATE", (payin.payer,)) # Update scheduled payins, if appropriate if status in ('pending', 'succeeded'): sp = cursor.one(""" SELECT * FROM scheduled_payins WHERE payer = %s AND payin = %s """, (payin.payer, payin.id)) if not sp: # Try to find a scheduled renewal that matches this payin. # It doesn't have to be an exact match. schedule = cursor.all(""" SELECT * FROM scheduled_payins WHERE payer = %s AND payin IS NULL AND mtime < %s """, (payin.payer, payin.ctime)) today = utcnow().date() schedule.sort(key=lambda sp: abs((sp.execution_date - today).days)) payin_tippees = set(cursor.all(""" SELECT coalesce(team, recipient) AS tippee FROM payin_transfers WHERE payer = %s AND payin = %s """, (payin.payer, payin.id))) for sp in schedule: if any((tr['tippee_id'] in payin_tippees) for tr in sp.transfers): cursor.run(""" UPDATE scheduled_payins SET payin = %s , mtime = current_timestamp WHERE id = %s """, (payin.id, sp.id)) break return payin def adjust_payin_transfers(db, payin, net_amount): """Correct a payin's transfers once the net amount is known. Args: payin (Record): a row from the `payins` table net_amount (Money): the amount of money available to transfer """ payer = db.Participant.from_id(payin.payer) route = db.ExchangeRoute.from_id(payer, payin.route) provider = route.network.split('-', 1)[0] payer_country = route.country # We have to update the transfer amounts in a single transaction to # avoid ending up in an inconsistent state. with db.get_cursor() as cursor: payin_transfers = cursor.all(""" SELECT pt.id, pt.amount, pt.status, pt.remote_id, pt.team, pt.recipient, team_p FROM payin_transfers pt LEFT JOIN participants team_p ON team_p.id = pt.team WHERE pt.payin = %s ORDER BY pt.id FOR UPDATE OF pt """, (payin.id,)) assert payin_transfers if any(pt.status == 'succeeded' for pt in payin_transfers): # At least one of the transfers has already been executed, so it's # too complicated to adjust the amounts now. return transfers_by_tippee = group_by( payin_transfers, lambda pt: (pt.team or pt.recipient) ) prorated_amounts = resolve_amounts(net_amount, { tippee: MoneyBasket(pt.amount for pt in grouped).fuzzy_sum(net_amount.currency) for tippee, grouped in transfers_by_tippee.items() }) teams = set(pt.team for pt in payin_transfers if pt.team is not None) updates = [] for tippee, prorated_amount in prorated_amounts.items(): transfers = transfers_by_tippee[tippee] if tippee in teams: team = transfers[0].team_p tip = payer.get_tip_to(team) try: team_donations = resolve_team_donation( db, team, provider, payer, payer_country, prorated_amount, tip, sepa_only=True, ) except (MissingPaymentAccount, NoSelfTipping): team_amounts = resolve_amounts(prorated_amount, { pt.id: pt.amount.convert(prorated_amount.currency) for pt in transfers }) for pt in transfers: if pt.amount != team_amounts.get(pt.id): assert pt.remote_id is None and pt.status in ('pre', 'pending') updates.append((team_amounts[pt.id], pt.id)) else: team_donations = {d.recipient.id: d for d in team_donations} for pt in transfers: if pt.status == 'failed': continue d = team_donations.pop(pt.recipient, None) if d is None: assert pt.remote_id is None and pt.status in ('pre', 'pending') cursor.run(""" DELETE FROM payin_transfer_events WHERE payin_transfer = %(pt_id)s AND status = 'pending'; DELETE FROM payin_transfers WHERE id = %(pt_id)s; """, dict(pt_id=pt.id)) elif pt.amount != d.amount: assert pt.remote_id is None and pt.status in ('pre', 'pending') updates.append((d.amount, pt.id)) n_periods = prorated_amount / tip.periodic_amount.convert(prorated_amount.currency) for d in team_donations.values(): unit_amount = (d.amount / n_periods).round(allow_zero=False) prepare_payin_transfer( db, payin, d.recipient, d.destination, 'team-donation', d.amount, tip.visibility, unit_amount, tip.period, team=team.id, ) else: pt = transfers[0] if pt.amount != prorated_amount: assert pt.remote_id is None and pt.status in ('pre', 'pending') updates.append((prorated_amount, pt.id)) if updates: execute_batch(cursor, """ UPDATE payin_transfers SET amount = %s WHERE id = %s AND status <> 'succeeded'; """, updates) def resolve_tip( db, tip, tippee, provider, payer, payer_country, payment_amount, sepa_only=False, excluded_destinations=set(), ): """Prepare to fund a tip. Args: tip (Row): a row from the `tips` table tippee (Participant): the intended beneficiary of the donation provider (str): the payment processor ('paypal' or 'stripe') payer (Participant): the donor payer_country (str): the country the money is supposedly coming from payment_amount (Money): the amount of money being sent sepa_only (bool): only consider destination accounts within SEPA excluded_destinations (set): any `payment_accounts.pk` values to exclude Returns: a list of `ProtoTransfer` objects Raises: MissingPaymentAccount: if no suitable destination has been found NoSelfTipping: if the donor would end up sending money to themself RecipientAccountSuspended: if the tippee's account is suspended UserDoesntAcceptTips: if the tippee doesn't accept donations """ assert tip.tipper == payer.id assert tip.tippee == tippee.id if not tippee.accepts_tips: raise UserDoesntAcceptTips(tippee.username) if tippee.is_suspended: raise RecipientAccountSuspended(tippee) if tippee.kind == 'group': return resolve_team_donation( db, tippee, provider, payer, payer_country, payment_amount, tip, sepa_only=sepa_only, excluded_destinations=excluded_destinations, ) else: destination = resolve_destination( db, tippee, provider, payer, payer_country, payment_amount, sepa_only=sepa_only, excluded_destinations=excluded_destinations, ) return [ProtoTransfer( payment_amount, tippee, destination, 'personal-donation', tip.periodic_amount, tip.period, None, tip.visibility, )] def resolve_destination( db, tippee, provider, payer, payer_country, payin_amount, sepa_only=False, excluded_destinations=(), ): """Figure out where to send a payment. Args: tippee (Participant): the intended beneficiary of the payment provider (str): the payment processor ('paypal' or 'stripe') payer (Participant): the user who wants to pay payer_country (str): the country the money is supposedly coming from payin_amount (Money): the payment amount sepa_only (bool): only consider destination accounts within SEPA excluded_destinations (set): any `payment_accounts.pk` values to exclude Returns: Record: a row from the `payment_accounts` table Raises: MissingPaymentAccount: if no suitable destination has been found NoSelfTipping: if the payer would end up sending money to themself """ tippee_id = tippee.id if tippee_id == payer.id: raise NoSelfTipping() currency = payin_amount.currency excluded_destinations = list(excluded_destinations) destination = db.one(""" SELECT * FROM payment_accounts WHERE participant = %(tippee_id)s AND provider = %(provider)s AND is_current AND verified AND coalesce(charges_enabled, true) AND array_position(%(excluded_destinations)s::bigint[], pk) IS NULL AND ( country IN %(SEPA)s OR NOT %(sepa_only)s ) ORDER BY default_currency = %(currency)s DESC , country = %(payer_country)s DESC , connection_ts LIMIT 1 """, dict(locals(), SEPA=SEPA)) if destination: return destination else: raise MissingPaymentAccount(tippee) def resolve_team_donation( db, team, provider, payer, payer_country, payment_amount, tip, sepa_only=False, excluded_destinations=(), ): """Figure out how to distribute a donation to a team's members. Args: team (Participant): the team the donation is for provider (str): the payment processor ('paypal' or 'stripe') payer (Participant): the donor payer_country (str): the country code the money is supposedly coming from payment_amount (Money): the amount of money being sent tip (Row): the row from the `tips` table sepa_only (bool): only consider destination accounts within SEPA excluded_destinations (set): any `payment_accounts.pk` values to exclude Returns: a list of `ProtoTransfer` objects Raises: MissingPaymentAccount: if no suitable destination has been found NoSelfTipping: if the payer would end up sending money to themself RecipientAccountSuspended: if the team or all of its members are suspended """ if team.is_suspended: raise RecipientAccountSuspended(team) currency = payment_amount.currency takes = team.get_current_takes_for_payment(currency, tip.amount) if all(t.is_suspended for t in takes): raise RecipientAccountSuspended(takes) takes = [t for t in takes if not t.is_suspended] if len(takes) == 1 and takes[0].member == payer.id: raise NoSelfTipping() member_ids = tuple([t.member for t in takes]) excluded_destinations = list(excluded_destinations) payment_accounts = {row.participant: row for row in db.all(""" SELECT DISTINCT ON (participant) * FROM payment_accounts WHERE participant IN %(member_ids)s AND provider = %(provider)s AND is_current AND verified AND coalesce(charges_enabled, true) AND array_position(%(excluded_destinations)s::bigint[], pk) IS NULL ORDER BY participant , default_currency = %(currency)s DESC , country = %(payer_country)s DESC , connection_ts """, locals())} del member_ids if not payment_accounts: raise MissingPaymentAccount(team) takes = [t for t in takes if t.member in payment_accounts and t.member != payer.id] if not takes: raise NoSelfTipping() takes.sort(key=lambda t: ( -(t.amount / (t.paid_in_advance + payment_amount)), t.paid_in_advance, t.ctime )) # Try to distribute the donation to multiple members. if sepa_only or provider == 'stripe': sepa_accounts = {a.participant: a for a in db.all(""" SELECT DISTINCT ON (a.participant) a.* FROM payment_accounts a WHERE a.participant IN %(member_ids)s AND a.provider = %(provider)s AND a.is_current AND a.verified AND coalesce(a.charges_enabled, true) AND array_position(%(excluded_destinations)s::bigint[], a.pk) IS NULL AND a.country IN %(SEPA)s ORDER BY a.participant , a.default_currency = %(currency)s DESC , a.connection_ts """, dict(locals(), SEPA=SEPA, member_ids={t.member for t in takes}))} if sepa_only or len(sepa_accounts) > 1 and takes[0].member in sepa_accounts: selected_takes = [ t for t in takes if t.member in sepa_accounts and t.amount != 0 ] if selected_takes: resolve_take_amounts(payment_amount, selected_takes) selected_takes.sort(key=attrgetter('member')) n_periods = payment_amount / tip.periodic_amount.convert(currency) return [ ProtoTransfer( t.resolved_amount, db.Participant.from_id(t.member), sepa_accounts[t.member], 'team-donation', (t.resolved_amount / n_periods).round(allow_zero=False), tip.period, team.id, tip.visibility, ) for t in selected_takes if t.resolved_amount != 0 ] elif sepa_only: raise MissingPaymentAccount(team) # Fall back to sending the entire donation to the member who "needs" it most. member = db.Participant.from_id(takes[0].member) account = payment_accounts[member.id] return [ProtoTransfer( payment_amount, member, account, 'team-donation', tip.periodic_amount, tip.period, team.id, tip.visibility, )] def resolve_take_amounts(payment_amount, takes): """Compute team transfer amounts. Args: payment_amount (Money): the total amount of money to transfer takes (list): rows returned by `team.get_current_takes_for_payment(...)` This function doesn't return anything, instead it mutates the given takes, adding a `resolved_amount` attribute to each one. """ max_weeks_of_advance = 0 for t in takes: if t.amount == 0: t.weeks_of_advance = 0 continue t.weeks_of_advance = t.paid_in_advance / t.amount if t.weeks_of_advance > max_weeks_of_advance: max_weeks_of_advance = t.weeks_of_advance base_amounts = {t.member: t.amount for t in takes} convergence_amounts = { t.member: ( t.amount * (max_weeks_of_advance - t.weeks_of_advance) ).round_up() for t in takes } tr_amounts = resolve_amounts(payment_amount, base_amounts, convergence_amounts) for t in takes: t.resolved_amount = tr_amounts.get(t.member, payment_amount.zero()) def resolve_amounts(available_amount, base_amounts, convergence_amounts=None, payday_id=1): """Compute transfer amounts. Args: available_amount (Money): the payin amount to split into transfer amounts base_amounts (Dict[Any, Money]): a map of IDs to raw transfer amounts convergence_amounts (Dict[Any, Money]): an optional map of IDs to ideal additional amounts payday_id (int): the ID of the current or next payday, used to rotate who receives the remainder when there is a tie Returns a copy of `base_amounts` with updated values. """ min_transfer_amount = Money.MINIMUMS[available_amount.currency] r = {} amount_left = available_amount # Attempt to converge if convergence_amounts: convergence_sum = Money.sum(convergence_amounts.values(), amount_left.currency) if convergence_sum != 0: convergence_amounts = {k: v for k, v in convergence_amounts.items() if v != 0} if amount_left == convergence_sum: # We have just enough money for convergence. return convergence_amounts elif amount_left > convergence_sum: # We have more than enough money for full convergence, the extra # funds will be allocated in proportion to `base_amounts`. r.update(convergence_amounts) amount_left -= convergence_sum else: # We only have enough for partial convergence, the funds will be # allocated in proportion to `convergence_amounts`. base_amounts = convergence_amounts # Compute the prorated amounts base_sum = Money.sum(base_amounts.values(), amount_left.currency) base_ratio = 0 if base_sum == 0 else amount_left / base_sum for key, base_amount in sorted(base_amounts.items()): if base_amount == 0: continue assert amount_left >= min_transfer_amount amount = min((base_amount * base_ratio).round_down(), amount_left) r[key] = amount + r.get(key, 0) amount_left -= amount # Deal with rounding errors if amount_left > 0: # Try to distribute in a way that doesn't skew the percentages much. # If there's a tie, use the payday ID to rotate the winner every week. i = itertools.count(1) n = len(r) for key, amount in sorted(r.items(), key=compute_priority): r[key] += min_transfer_amount amount_left -= min_transfer_amount if amount_left == 0: break # Final check and return assert amount_left == 0, '%r != 0' % amount_left return r def prepare_payin_transfer( db, payin, recipient, destination, context, amount, visibility, unit_amount=None, period=None, team=None, ): """Prepare the allocation of funds from a payin. Args: payin (Record): a row from the `payins` table recipient (Participant): the user who will receive the money destination (Record): a row from the `payment_accounts` table amount (Money): the amount of money that will be received visibility (int): a copy of `tip.visibility` unit_amount (Money): the `periodic_amount` of a recurrent donation period (str): the period of a recurrent payment team (int): the ID of the project this payment is tied to Returns: Record: the row created in the `payin_transfers` table """ assert recipient.id == destination.participant, (recipient, destination) if recipient.is_suspended: raise RecipientAccountSuspended() if unit_amount: n_units = int(amount / unit_amount.convert(amount.currency)) else: n_units = None return db.one(""" INSERT INTO payin_transfers (payin, payer, recipient, destination, context, amount, unit_amount, n_units, period, team, visibility, status, ctime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 'pre', clock_timestamp()) RETURNING * """, (payin.id, payin.payer, recipient.id, destination.pk, context, amount, unit_amount, n_units, period, team, visibility)) def update_payin_transfer( db, pt_id, remote_id, status, error, amount=None, fee=None, update_donor=True, reversed_amount=None, ): """Update the status and other attributes of a payment. Args: pt_id (int): the ID of the payment in our database remote_id (str): the ID of the transfer in the payment processor's database status (str): the new status of the payment error (str): if the payment failed, an error message to show to the payer Returns: Record: the row updated in the `payin_transfers` table """ with db.get_cursor() as cursor: pt = cursor.one(""" UPDATE payin_transfers SET status = %(status)s , error = %(error)s , remote_id = coalesce(remote_id, %(remote_id)s) , amount = COALESCE(%(amount)s, amount) , fee = COALESCE(%(fee)s, fee) , reversed_amount = coalesce(%(reversed_amount)s, reversed_amount) WHERE id = %(pt_id)s RETURNING * , (SELECT amount FROM payin_transfers WHERE id = %(pt_id)s) AS old_amount , (SELECT reversed_amount FROM payin_transfers WHERE id = %(pt_id)s) AS old_reversed_amount , (SELECT status FROM payin_transfers WHERE id = %(pt_id)s) AS old_status """, locals()) if not pt: return if remote_id and pt.remote_id != remote_id: raise AssertionError(f"the remote IDs don't match: {pt.remote_id!r} != {remote_id!r}") if status != pt.old_status: cursor.run(""" INSERT INTO payin_transfer_events (payin_transfer, status, error, timestamp) VALUES (%s, %s, %s, current_timestamp) """, (pt_id, status, error)) # If the payment has failed or hasn't been settled yet, then stop here. if status != 'succeeded': return pt # Update the `paid_in_advance` value of the donation. params = pt._asdict() params['delta'] = pt.amount if pt.old_status == 'succeeded': params['delta'] -= pt.old_amount if pt.reversed_amount: params['delta'] += -(pt.reversed_amount - (pt.old_reversed_amount or 0)) elif pt.old_reversed_amount: params['delta'] += pt.old_reversed_amount if params['delta'] == 0: return pt updated_tips = cursor.all(""" WITH latest_tip AS ( SELECT * FROM tips WHERE tipper = %(payer)s AND tippee = COALESCE(%(team)s, %(recipient)s) ORDER BY mtime DESC LIMIT 1 ) UPDATE tips t SET paid_in_advance = ( coalesce_currency_amount(t.paid_in_advance, t.amount::currency) + convert(%(delta)s, t.amount::currency) ) , is_funded = true FROM latest_tip lt WHERE t.tipper = lt.tipper AND t.tippee = lt.tippee AND t.mtime >= lt.mtime RETURNING t.* """, params) if not updated_tips: # This transfer isn't linked to a tip. return pt assert len(updated_tips) < 10, updated_tips if any(t.paid_in_advance <= 0 for t in updated_tips): cursor.run(""" UPDATE tips SET is_funded = false WHERE tipper = %(payer)s AND paid_in_advance <= 0 """, params) # If it's a team donation, update the `paid_in_advance` value of the take. if pt.context == 'team-donation': updated_takes = cursor.all(""" WITH latest_take AS ( SELECT * FROM takes WHERE team = %(team)s AND member = %(recipient)s AND amount IS NOT NULL ORDER BY mtime DESC LIMIT 1 ) UPDATE takes t SET paid_in_advance = ( coalesce_currency_amount(lt.paid_in_advance, lt.amount::currency) + convert(%(delta)s, lt.amount::currency) ) FROM latest_take lt WHERE t.team = lt.team AND t.member = lt.member AND t.mtime >= lt.mtime RETURNING t.id """, params) assert 0 < len(updated_takes) < 10, params # Recompute the cached `receiving` amount of the donee. cursor.run(""" WITH our_tips AS ( SELECT t.amount FROM current_tips t WHERE t.tippee = %(p_id)s AND t.is_funded ) UPDATE participants AS p SET receiving = taking + coalesce_currency_amount( (SELECT sum(t.amount, p.main_currency) FROM our_tips t), p.main_currency ) , npatrons = (SELECT count(*) FROM our_tips) WHERE p.id = %(p_id)s """, dict(p_id=(pt.team or pt.recipient))) # Recompute the donor's cached `giving` amount and payment schedule. if update_donor: donor = db.Participant.from_id(pt.payer) donor.update_giving() donor.schedule_renewals() return pt def abort_payin(db, payin, error='aborted by payer'): """Mark a payin as cancelled. Args: payin (Record): a row from the `payins` table error (str): the error message to attach to the payin Returns: Record: the row updated in the `payins` table """ payin = update_payin(db, payin.id, payin.remote_id, 'failed', error) db.run(""" WITH updated_transfers as ( UPDATE payin_transfers SET status = 'failed' , error = %(error)s WHERE payin = %(payin_id)s AND status <> 'failed' RETURNING * ) INSERT INTO payin_transfer_events (payin_transfer, status, error, timestamp) SELECT pt.id, 'failed', pt.error, current_timestamp FROM updated_transfers pt """, dict(error=error, payin_id=payin.id)) return payin def record_payin_refund( db, payin_id, remote_id, amount, reason, description, status, error=None, ctime=None, ): """Record a charge refund. Args: payin_id (int): the ID of the refunded payin in our database remote_id (int): the ID of the refund in the payment processor's database amount (Money): the refund amount, must be less or equal to the payin amount reason (str): why this refund was initiated (`refund_reason` SQL type) description (str): details of the circumstances of this refund status (str): the current status of the refund (`refund_status` SQL type) error (str): error message, if the refund has failed ctime (datetime): when the refund was initiated Returns: Record: the row inserted in the `payin_refunds` table """ refund = db.one(""" INSERT INTO payin_refunds (payin, remote_id, amount, reason, description, status, error, ctime) VALUES (%(payin_id)s, %(remote_id)s, %(amount)s, %(reason)s, %(description)s, %(status)s, %(error)s, coalesce(%(ctime)s, current_timestamp)) ON CONFLICT (payin, remote_id) DO UPDATE SET amount = excluded.amount , reason = excluded.reason , description = excluded.description , status = excluded.status , error = excluded.error RETURNING * , ( SELECT old.status FROM payin_refunds old WHERE old.payin = %(payin_id)s AND old.remote_id = %(remote_id)s ) AS old_status """, locals()) notify = ( refund.status in ('pending', 'succeeded') and refund.status != refund.old_status and refund.ctime > (utcnow() - timedelta(hours=24)) ) if notify: payin = db.one("SELECT * FROM payins WHERE id = %s", (refund.payin,)) payer = db.Participant.from_id(payin.payer) payer.notify( 'payin_refund_initiated', payin_amount=payin.amount, payin_ctime=payin.ctime, refund_amount=refund.amount, refund_reason=refund.reason, email_unverified_address=True, ) return refund def record_payin_transfer_reversal( db, pt_id, remote_id, amount, payin_refund_id=None, ctime=None ): """Record a transfer reversal. Args: pt_id (int): the ID of the reversed transfer in our database remote_id (int): the ID of the reversal in the payment processor's database amount (Money): the reversal amount, must be less or equal to the transfer amount payin_refund_id (int): the ID of the associated payin refund in our database ctime (datetime): when the refund was initiated Returns: Record: the row inserted in the `payin_transfer_reversals` table """ return db.one(""" INSERT INTO payin_transfer_reversals (payin_transfer, remote_id, amount, payin_refund, ctime) VALUES (%(pt_id)s, %(remote_id)s, %(amount)s, %(payin_refund_id)s, coalesce(%(ctime)s, current_timestamp)) ON CONFLICT (payin_transfer, remote_id) DO UPDATE SET amount = excluded.amount , payin_refund = excluded.payin_refund RETURNING * """, locals())
[ 6738, 17268, 1330, 3706, 83, 29291, 198, 6738, 4818, 8079, 1330, 28805, 12514, 198, 11748, 340, 861, 10141, 198, 6738, 10088, 1330, 708, 81, 1136, 353, 198, 198, 6738, 19798, 78, 13, 26791, 1330, 3384, 66, 2197, 198, 6738, 17331, 22163,...
2.117355
16,301
# -*- coding:utf-8 -*- from vendor.errors.feature import FeatureProcessError """ : **, ** """ def f_assert_not_null(seq): """""" if seq in (None, '', [], {}, ()): raise FeatureProcessError("value: %s f_assert_not_null Error" % seq) if isinstance(seq, list): for value in seq: if value in (None, '', {}, [], ()): raise FeatureProcessError("value: %s f_assert_not_null Error" % seq) return seq def f_assert_jsonpath_true(seq): """jsonpathtrue seq[]""" if seq in ([],): raise FeatureProcessError("jsonpath not find field") return seq def f_assert_must_int(value_list): """int""" for value in value_list: if not isinstance(value, int): raise FeatureProcessError('%s f_assert_must_int Error' % value_list) return value_list def f_assert_must_list(value_list): """list""" for value in value_list: if not isinstance(value, list): raise FeatureProcessError('%s f_assert_must_list Error' % value_list) return value_list def f_assert_must_dict(value_list): """dict""" for value in value_list: if not isinstance(value, dict): raise FeatureProcessError('%s f_assert_must_dict Error' % value_list) return value_list def f_assert_must_digit(value_list, args=False): """ :param value_list: :param args: false True :return: example :value_list [-2,'-2', 3] :args false return :value_list [-2,'-2', 3] :args True return [-2,'-2', 3] """ for value in value_list: if args: if not str(value).lstrip('-').isdigit(): raise FeatureProcessError('%s negative number=%s f_assert_must_digit Error' % (value_list, args)) else: if not str(value).isdigit(): raise FeatureProcessError('%s negative number=%s f_assert_must_digit Error' % (value_list, args)) return value_list def f_assert_must_basestring(value_list): """""" for value in value_list: if not isinstance(value, basestring): raise FeatureProcessError('%s f_assert_must_basestring Error' % value_list) return value_list def f_assert_must_digit_or_float(value_list, args=False): """ float, args=false True :param value_list: :param args: false True :return: example :value_list [-2.0,'-2', 3] :args false return :value_list [-2.0,'-2', 3] :args True return [-2.0,'-2', 3] """ for value in value_list: if args: if not (str(value).count('.') <= 1 and str(value).replace('.', '').lstrip('-').isdigit()): raise FeatureProcessError( '%s negative number=%s f_assert_must_digit_or_float Error' % (value_list, args)) else: if not (str(value).count('.') <= 1 and str(value).replace('.', '').isdigit()): raise FeatureProcessError( '%s negative number=%s f_assert_must_digit_or_float Error' % (value_list, args)) return value_list def f_assert_must_percent(value_list): """ """ for value in value_list: if not (str(value)[-1] == '%' and (str(value[:-1]).count('.') <= 1 and str(value[:-1]).replace('.', '').isdigit())): raise FeatureProcessError( '%s f_assert_must_percent Error' % value_list) return value_list def f_assert_must_between(value_list, args): """ args :param value_list: :param args: :return: example :value_list [2, 2, 3] :args [1,3] :value_list ['-2', '-3', 3] :args ['-5',3] """ assert len(args) == 2 for value in value_list: if not (str(value).count('.') <= 1 and str(value).replace('.', '').lstrip('-').isdigit() and float(args[0]) <= float(value) <= float(args[1])): raise FeatureProcessError('%s f_assert_must_between %s Error' % (value_list, args)) return value_list def f_assert_seq0_gte_seq1(value_list): """""" if not value_list[0] >= value_list[1]: raise FeatureProcessError('%s f_assert_seq0_gte_seq1 Error' % value_list) return value_list if __name__ == '__main__': print f_assert_must_percent(['7.0%'])
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 198, 6738, 18371, 13, 48277, 13, 30053, 1330, 27018, 18709, 12331, 198, 198, 37811, 198, 220, 220, 220, 1058, 628, 220, 220, 220, 220, 220, 220, 220, 220, 198, 220, 220, ...
2.049101
2,281
import time from os import system, walk from config import CONFIG from encry import ENCRY from decry import DECRY # # if __name__ == '__main__': CONF = object text = '' cryptMode = '' print_menu(cryptMode, CONF, text)
[ 11748, 640, 198, 6738, 28686, 1330, 1080, 11, 2513, 198, 6738, 4566, 1330, 25626, 198, 6738, 2207, 563, 1330, 412, 7792, 18276, 198, 6738, 875, 563, 1330, 27196, 18276, 628, 198, 2, 220, 220, 220, 628, 628, 198, 198, 2, 220, 220, 62...
2.638298
94
# -*- coding: utf-8 -*- # Copyright (c) 2015, Frappe Technologies and contributors # License: MIT. See LICENSE import frappe from frappe.model.document import Document
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 15069, 357, 66, 8, 1853, 11, 39313, 27768, 21852, 290, 20420, 198, 2, 13789, 25, 17168, 13, 4091, 38559, 24290, 198, 198, 11748, 5306, 27768, 198, 6738, 5306, 27768, ...
3.333333
51
# -*- coding: utf-8 -*- # pylint: disable=unused-argument,pointless-statement """Tests for the `PseudoDojoFamily` class.""" import pytest from aiida_pseudo.data.pseudo import UpfData, Psp8Data, PsmlData, JthXmlData from aiida_pseudo.groups.family import PseudoDojoConfiguration, PseudoDojoFamily def test_type_string(clear_db): """Verify the `_type_string` class attribute is correctly set to the corresponding entry point name.""" assert PseudoDojoFamily._type_string == 'pseudo.family.pseudo_dojo' # pylint: disable=protected-access def test_pseudo_types(): """Test the `PseudoDojoFamily.pseudo_types` method.""" assert PseudoDojoFamily.pseudo_types == (UpfData, PsmlData, Psp8Data, JthXmlData) def test_default_configuration(): """Test the `PseudoDojoFamily.default_configuration` class attribute.""" assert isinstance(PseudoDojoFamily.default_configuration, PseudoDojoConfiguration) def test_valid_configurations(): """Test the `PseudoDojoFamily.valid_configurations` class attribute.""" valid_configurations = PseudoDojoFamily.valid_configurations assert isinstance(valid_configurations, tuple) for entry in valid_configurations: assert isinstance(entry, PseudoDojoConfiguration) def test_get_valid_labels(): """Test the `PseudoDojoFamily.get_valid_labels` class method.""" valid_labels = PseudoDojoFamily.get_valid_labels() assert isinstance(valid_labels, tuple) for entry in valid_labels: assert isinstance(entry, str) def test_format_configuration_label(): """Test the `PseudoDojoFamily.format_configuration_label` class method.""" configuration = PseudoDojoConfiguration('0.4', 'PBE', 'SR', 'standard', 'psp8') assert PseudoDojoFamily.format_configuration_label(configuration) == 'PseudoDojo/0.4/PBE/SR/standard/psp8' def test_constructor(): """Test that the `PseudoDojoFamily` constructor validates the label.""" with pytest.raises(ValueError, match=r'the label `.*` is not a valid PseudoDojo configuration label'): PseudoDojoFamily() with pytest.raises(ValueError, match=r'the label `.*` is not a valid PseudoDojo configuration label'): PseudoDojoFamily(label='nc-sr-04_pbe_standard_psp8') label = PseudoDojoFamily.format_configuration_label(PseudoDojoFamily.default_configuration) family = PseudoDojoFamily(label=label) assert isinstance(family, PseudoDojoFamily)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 279, 2645, 600, 25, 15560, 28, 403, 1484, 12, 49140, 11, 4122, 1203, 12, 26090, 198, 37811, 51, 3558, 329, 262, 4600, 47, 325, 12003, 5211, 7639, 24094, 63, 1398, ...
2.876485
842
import sys import os if sys.version_info[0] != 3 : print("Running in python "+sys.version_info[0]+", should be python 3.") print("Please install python 3.7 from the official site python.org") print("Exiting now.") exit() import shutil import argparse import fbx2tree import builder_fromfbx import time # config is useful to keep info for the different modules import config parser = argparse.ArgumentParser() parser.add_argument("file", help="file") parser.add_argument("-v", "--verbose", help="Print more stuff", action="store_true") parser.add_argument("-d", "--debug", help="Create intermediate xml files for debug", action="store_true") parser.add_argument("--closest", help="Try to stick as close to the original materials in 3dsmax, even if it is at the expense of realism", action="store_true") parser.add_argument("--realist", help="Try to make materials as realist as possible, even if it is at the expense of fidelity to the original scene", action="store_true") args = parser.parse_args() if args.closest and args.realist : print("Incompatible options : --closest and --realist. Choose one, or neither for a balanced result") exit(0) fullname = args.file if fullname.split(".")[-1].lower() != "fbx" : print("The file is not an fbx file") exit(0) config.curr_place = os.path.dirname(os.path.abspath(__file__)) config.filename = ".".join(fullname.split(".")[:-1]).split("\\")[-1]#Remove extension, remove path. config.filepath = "\\".join(fullname.split("\\")[:-1])+"\\"#Keep only path config.verbose = args.verbose config.debug = args.debug config.closest = args.closest config.realist = args.realist fbxtree = fbx2tree.transform() builder_fromfbx.build(fbxtree) print("Conversion finished !")
[ 11748, 25064, 198, 11748, 28686, 628, 198, 361, 25064, 13, 9641, 62, 10951, 58, 15, 60, 14512, 513, 1058, 198, 197, 4798, 7203, 28768, 287, 21015, 43825, 17597, 13, 9641, 62, 10951, 58, 15, 48688, 1600, 815, 307, 21015, 513, 19570, 19...
3.020797
577
import sys import json import plotly from flask import Flask from flask import render_template, request from plotly.graph_objects import Heatmap, Bar from sklearn.externals import joblib from sqlalchemy import create_engine sys.path.append("common") from common.nlp_common_utils import * if len(sys.argv) == 1: sys.argv.append('./data/DisasterResponse.db') sys.argv.append('./models/classifier.pkl') # this requires for joblib and pickle def tokenize(text): """ Used a common utility functions for tokenize text in to cleaned token list. INPUT: text - raw message OUTPUT: clean_tokens -- cleaned tokenized list """ return tokenize_text(text) # create a flask app app = Flask(__name__, template_folder='app/templates') # database_file_location, model_location = sys.argv[1:] # load data engine = create_engine('sqlite:///{}'.format(database_file_location)) df = pd.read_sql_table('DisasterResponse', engine) # category df df_categories = df.iloc[:, 4:] # load model model = joblib.load(model_location) def generate_graph_with_template(data, title, yaxis_title, xaxi_title): """ This common layout can be used to create Plotly graph layout. INPUT: data - a graph required JSON data i.e list title - a tile of the chart yaxis_title - Y title xaxix_title - X title OUTPUT: layout for particular graph. """ return { 'data': [data], 'layout': { 'title': title, 'yaxis': { 'title': yaxis_title }, 'xaxis': { 'title': xaxi_title } } } def generate_message_genres_bar_chart(): """ create a graph using extracted data for `genre` """ # extract data needed for visuals genre_counts = df.groupby('genre').count()['message'] genre_names = list(genre_counts.index) data = Bar(x=genre_names, y=genre_counts) title = 'Distribution of Message Genres' y_title = 'Count' x_title = 'Genre' return generate_graph_with_template(data, title, y_title, x_title) def generate_message_categories_distribution_bar_chart(): """ create a graph for distribution of the messages. """ data = Bar(x=df_categories.columns, y=list(df_categories.sum().sort_values(ascending=False))) title = 'Distribution of Message Categories' y_title = 'Count' x_title = 'Category' return generate_graph_with_template(data, title, y_title, x_title) def generate_two_cat_relation_heat_map(): """ A correlation matrix for categories """ data = Heatmap( z=df_categories.corr(), y=df_categories.columns, x=df_categories.columns) title = 'Correlation Distribution of Categories' y_title = 'Category' x_title = 'Category' return generate_graph_with_template(data, title, y_title, x_title) # index webpage displays cool visuals and receives user input text for model # web page that handles user query and displays model results def main(): app.run(host='0.0.0.0', port=3001, debug=True) if __name__ == '__main__': main()
[ 11748, 25064, 198, 11748, 33918, 198, 198, 11748, 7110, 306, 198, 6738, 42903, 1330, 46947, 198, 6738, 42903, 1330, 8543, 62, 28243, 11, 2581, 198, 6738, 7110, 306, 13, 34960, 62, 48205, 1330, 12308, 8899, 11, 2409, 198, 6738, 1341, 357...
2.571082
1,238
import re import sys from nltk.tokenize import word_tokenize from unidecode import unidecode from nltk.tokenize import sent_tokenize import argparse parser = argparse.ArgumentParser() parser.add_argument('fin') parser.add_argument('fout') args = parser.parse_args() textproc = TextProc() tokenizer = Tokenizer() sentences=set() with open(args.fin, 'r') as f: count = 0 for line in f: count+=1 sentences.add(line.strip()) if count % 100000==0: print(count) with open(args.fout, 'w') as f: count = 0 group = '' for s in sentences: count+=1 if s !='': group+=s+'\n' if count % 20==0: try: p = sent_tokenize(unidecode(group)) f.write('\n'.join(p)) group = '' except: print("nltk error") if count % 10000==0: print(count)
[ 11748, 302, 198, 11748, 25064, 198, 6738, 299, 2528, 74, 13, 30001, 1096, 1330, 1573, 62, 30001, 1096, 198, 6738, 555, 485, 8189, 1330, 555, 485, 8189, 198, 6738, 299, 2528, 74, 13, 30001, 1096, 1330, 1908, 62, 30001, 1096, 198, 11748...
2.276423
369
""" Melhore o jogo do DESAFIO 028 onde o computador vai "pensar" em um numero entre 0 e 10. S que agora o jogador vai tentar adivinhar at acertar, mostrando no final quantos palpites foram necessrios para vencer """ """ from random import randint tentativas = 1 computador = randint(0, 10) jogador = int(input('Informe um numero para jogarmos ')) while jogador != computador: jogador = int(input('Errou. Tente novamente. ')) tentativas += 1 print(f'Acertou. Pensei no {computador} tambm.') print(f'Total de tentativas {tentativas}.') """ # Corrigido do Professor from random import randint computador = randint(0, 10) print('Pensei em um nmero entre 0 e 10') acertou = False palpites = 0 while not acertou: jogador = int(input('Qual o seu palpite? ')) palpites += 1 if jogador == computador: acertou = True else: if jogador < computador: print('Mais..Tente mais uma vez.') elif jogador > computador: print('Menos. Tente mais uma vez.') print(f'Acertou com {palpites} tentativas. Parabns!')
[ 37811, 198, 21102, 71, 382, 267, 474, 24076, 466, 22196, 8579, 9399, 657, 2078, 319, 2934, 267, 2653, 7079, 410, 1872, 366, 79, 641, 283, 1, 795, 23781, 997, 3529, 920, 260, 657, 304, 838, 13, 198, 50, 8358, 556, 5799, 267, 48342, ...
2.425968
439
# coding: utf-8 import re import utility from commands import Command
[ 2, 19617, 25, 3384, 69, 12, 23, 198, 198, 11748, 302, 198, 11748, 10361, 198, 6738, 9729, 1330, 9455, 628, 198 ]
3.47619
21
import os min=512 max=512
[ 11748, 28686, 198, 198, 1084, 28, 25836, 198, 9806, 28, 25836, 628, 198 ]
2.230769
13
"""This module contains objects for saleorders endpoints""" from flask import Flask, jsonify, request, abort, make_response from flask_restful import Resource from flask_jwt_extended import get_jwt_identity, jwt_required from . import common_functions from ..models import products, saleorders from ..utils import verify from .. import database
[ 37811, 1212, 8265, 4909, 5563, 329, 5466, 6361, 886, 13033, 37811, 198, 198, 6738, 42903, 1330, 46947, 11, 33918, 1958, 11, 2581, 11, 15614, 11, 787, 62, 26209, 198, 6738, 42903, 62, 2118, 913, 1330, 20857, 198, 6738, 42903, 62, 73, 4...
3.943182
88
default_app_config = "nautobot.circuits.apps.CircuitsConfig"
[ 12286, 62, 1324, 62, 11250, 796, 366, 77, 2306, 672, 313, 13, 21170, 15379, 13, 18211, 13, 31560, 15379, 16934, 1, 198 ]
2.772727
22
import copy import numpy as np from scipy.special import wofz from scipy.integrate import quad from typing import List, Tuple import autoarray as aa from autogalaxy.profiles.mass_profiles import MassProfile from autogalaxy.profiles.mass_profiles.mass_profiles import ( MassProfileMGE, MassProfileCSE, ) from autogalaxy.profiles.mass_profiles.mass_profiles import psi_from def image_2d_via_radii_from(self, grid_radii: np.ndarray): """Calculate the intensity of the Gaussian light profile on a grid of radial coordinates. Parameters ---------- grid_radii The radial distance from the centre of the profile. for each coordinate on the grid. Note: sigma is divided by sqrt(q) here. """ return np.multiply( self.intensity, np.exp( -0.5 * np.square( np.divide(grid_radii, self.sigma / np.sqrt(self.axis_ratio)) ) ), ) # noinspection PyAbstractClass def image_2d_via_radii_from(self, radius: np.ndarray): """ Returns the intensity of the profile at a given radius. Parameters ---------- radius The distance from the centre of the profile. """ return self.intensity * np.exp( -self.sersic_constant * (((radius / self.effective_radius) ** (1.0 / self.sersic_index)) - 1) ) def decompose_convergence_via_mge(self) -> Tuple[List, List]: radii_min = self.effective_radius / 100.0 radii_max = self.effective_radius * 20.0 return self._decompose_convergence_via_mge( func=sersic_2d, radii_min=radii_min, radii_max=radii_max ) def decompose_convergence_via_cse(self,) -> Tuple[List, List]: """ Decompose the convergence of the Sersic profile into cored steep elliptical (cse) profiles. This decomposition uses the standard 2d profile of a Sersic mass profile. Parameters ---------- func The function representing the profile that is decomposed into CSEs. radii_min: The minimum radius to fit radii_max: The maximum radius to fit total_cses The number of CSEs used to approximate the input func. sample_points: int (should be larger than 'total_cses') The number of data points to fit Returns ------- Tuple[List, List] A list of amplitudes and core radii of every cored steep elliptical (cse) the mass profile is decomposed into. """ upper_dex, lower_dex, total_cses, sample_points = cse_settings_from( effective_radius=self.effective_radius, sersic_index=self.sersic_index, sersic_constant=self.sersic_constant, mass_to_light_gradient=0.0, ) scaled_effective_radius = self.effective_radius / np.sqrt(self.axis_ratio) radii_min = scaled_effective_radius / 10.0 ** lower_dex radii_max = scaled_effective_radius * 10.0 ** upper_dex return self._decompose_convergence_via_cse_from( func=sersic_2d, radii_min=radii_min, radii_max=radii_max, total_cses=total_cses, sample_points=sample_points, ) def with_new_normalization(self, normalization): mass_profile = copy.copy(self) mass_profile.mass_to_light_ratio = normalization return mass_profile class EllSersic(AbstractEllSersic, MassProfileMGE, MassProfileCSE): def decompose_convergence_via_mge(self): radii_min = self.effective_radius / 100.0 radii_max = self.effective_radius * 20.0 return self._decompose_convergence_via_mge( func=sersic_radial_gradient_2D, radii_min=radii_min, radii_max=radii_max ) def decompose_convergence_via_cse(self) -> Tuple[List, List]: """ Decompose the convergence of the Sersic profile into singular isothermal elliptical (sie) profiles. This decomposition uses the standard 2d profile of a Sersic mass profile. Parameters ---------- func The function representing the profile that is decomposed into CSEs. radii_min: The minimum radius to fit radii_max: The maximum radius to fit total_sies The number of SIEs used to approximate the input func. sample_points: int (should be larger than 'total_sies') The number of data points to fit Returns ------- Tuple[List, List] A list of amplitudes and core radii of every singular isothernal ellipsoids (sie) the mass profile is decomposed into. """ upper_dex, lower_dex, total_cses, sample_points = cse_settings_from( effective_radius=self.effective_radius, sersic_index=self.sersic_index, sersic_constant=self.sersic_constant, mass_to_light_gradient=self.mass_to_light_gradient, ) scaled_effective_radius = self.effective_radius / np.sqrt(self.axis_ratio) radii_min = scaled_effective_radius / 10.0 ** lower_dex radii_max = scaled_effective_radius * 10.0 ** upper_dex return self._decompose_convergence_via_cse_from( func=sersic_radial_gradient_2D, radii_min=radii_min, radii_max=radii_max, total_cses=total_cses, sample_points=sample_points, ) class SphSersicRadialGradient(EllSersicRadialGradient): def __init__( self, centre: Tuple[float, float] = (0.0, 0.0), intensity: float = 0.1, effective_radius: float = 0.6, sersic_index: float = 0.6, mass_to_light_ratio: float = 1.0, mass_to_light_gradient: float = 0.0, ): """ Setup a Sersic mass and light profiles. Parameters ---------- centre The (y,x) arc-second coordinates of the profile centre. intensity Overall flux intensity normalisation in the light profiles (electrons per second). effective_radius The circular radius containing half the light of this profile. sersic_index Controls the concentration of the profile (lower -> less concentrated, higher -> more concentrated). mass_to_light_ratio The mass-to-light ratio of the light profile. mass_to_light_gradient The mass-to-light radial gradient. """ super().__init__( centre=centre, elliptical_comps=(0.0, 0.0), intensity=intensity, effective_radius=effective_radius, sersic_index=sersic_index, mass_to_light_ratio=mass_to_light_ratio, mass_to_light_gradient=mass_to_light_gradient, ) class EllSersicCore(EllSersic): def __init__( self, centre: Tuple[float, float] = (0.0, 0.0), elliptical_comps: Tuple[float, float] = (0.0, 0.0), effective_radius: float = 0.6, sersic_index: float = 4.0, radius_break: float = 0.01, intensity_break: float = 0.05, gamma: float = 0.25, alpha: float = 3.0, mass_to_light_ratio: float = 1.0, ): """ The elliptical cored-Sersic light profile. Parameters ---------- centre The (y,x) arc-second coordinates of the profile centre. elliptical_comps The first and second ellipticity components of the elliptical coordinate system, (see the module `autogalaxy -> convert.py` for the convention). intensity Overall intensity normalisation of the light profile (units are dimensionless and derived from the data the light profile's image is compared too, which is expected to be electrons per second). effective_radius The circular radius containing half the light of this profile. sersic_index Controls the concentration of the profile (lower -> less concentrated, higher -> more concentrated). radius_break The break radius separating the inner power-law (with logarithmic slope gamma) and outer Sersic function. intensity_break The intensity at the break radius. gamma The logarithmic power-law slope of the inner core profiles alpha : Controls the sharpness of the transition between the inner core / outer Sersic profiles. """ super().__init__( centre=centre, elliptical_comps=elliptical_comps, intensity=intensity_break, effective_radius=effective_radius, sersic_index=sersic_index, mass_to_light_ratio=mass_to_light_ratio, ) self.radius_break = radius_break self.intensity_break = intensity_break self.alpha = alpha self.gamma = gamma def image_2d_via_radii_from(self, grid_radii: np.ndarray): """ Calculate the intensity of the cored-Sersic light profile on a grid of radial coordinates. Parameters ---------- grid_radii The radial distance from the centre of the profile. for each coordinate on the grid. """ return np.multiply( np.multiply( self.intensity_prime, np.power( np.add( 1, np.power(np.divide(self.radius_break, grid_radii), self.alpha), ), (self.gamma / self.alpha), ), ), np.exp( np.multiply( -self.sersic_constant, ( np.power( np.divide( np.add( np.power(grid_radii, self.alpha), (self.radius_break ** self.alpha), ), (self.effective_radius ** self.alpha), ), (1.0 / (self.alpha * self.sersic_index)), ) ), ) ), ) def image_2d_via_radii_from(self, grid_radii: np.ndarray): """Calculate the intensity of the Chamelon light profile on a grid of radial coordinates. Parameters ---------- grid_radii The radial distance from the centre of the profile. for each coordinate on the grid. """ axis_ratio_factor = (1.0 + self.axis_ratio) ** 2.0 return np.multiply( self.intensity / (1 + self.axis_ratio), np.add( np.divide( 1.0, np.sqrt( np.add( np.square(grid_radii), (4.0 * self.core_radius_0 ** 2.0) / axis_ratio_factor, ) ), ), -np.divide( 1.0, np.sqrt( np.add( np.square(grid_radii), (4.0 * self.core_radius_1 ** 2.0) / axis_ratio_factor, ) ), ), ), ) class SphChameleon(EllChameleon): def __init__( self, centre: Tuple[float, float] = (0.0, 0.0), intensity: float = 0.1, core_radius_0: float = 0.01, core_radius_1: float = 0.02, mass_to_light_ratio: float = 1.0, ): """ The spherica; Chameleon mass profile. Profile form: mass_to_light_ratio * intensity *\ (1.0 / Sqrt(x^2 + (y/q)^2 + core_radius_0^2) - 1.0 / Sqrt(x^2 + (y/q)^2 + (core_radius_0 + core_radius_1)**2.0)) Parameters ---------- centre The (y,x) arc-second coordinates of the profile centre. elliptical_comps The first and second ellipticity components of the elliptical coordinate system, (see the module `autogalaxy -> convert.py` for the convention). intensity Overall intensity normalisation of the light profile (units are dimensionless and derived from the data the light profile's image is compared too, which is expected to be electrons per second). core_radius_0 : the core size of the first elliptical cored Isothermal profile. core_radius_1 : core_radius_0 + core_radius_1 is the core size of the second elliptical cored Isothermal profile. We use core_radius_1 here is to avoid negative values. """ super().__init__( centre=centre, elliptical_comps=(0.0, 0.0), intensity=intensity, core_radius_0=core_radius_0, core_radius_1=core_radius_1, mass_to_light_ratio=mass_to_light_ratio, ) def cse_settings_from( effective_radius, sersic_index, sersic_constant, mass_to_light_gradient ): if mass_to_light_gradient > 0.5: if effective_radius > 0.2: lower_dex = 6.0 upper_dex = np.min( [np.log10((18.0 / sersic_constant) ** sersic_index), 1.1] ) if sersic_index <= 1.2: total_cses = 50 sample_points = 80 elif sersic_index > 3.8: total_cses = 40 sample_points = 50 lower_dex = 6.5 else: total_cses = 30 sample_points = 50 else: if sersic_index <= 1.2: upper_dex = 1.0 total_cses = 50 sample_points = 80 lower_dex = 4.5 elif sersic_index > 3.8: total_cses = 40 sample_points = 50 lower_dex = 6.0 upper_dex = 1.5 else: upper_dex = 1.1 lower_dex = 6.0 total_cses = 30 sample_points = 50 else: upper_dex = np.min( [ np.log10((23.0 / sersic_constant) ** sersic_index), 0.85 - np.log10(effective_radius), ] ) if (sersic_index <= 0.9) and (sersic_index > 0.8): total_cses = 50 sample_points = 80 upper_dex = np.log10((18.0 / sersic_constant) ** sersic_index) lower_dex = 4.3 + np.log10(effective_radius) elif sersic_index <= 0.8: total_cses = 50 sample_points = 80 upper_dex = np.log10((16.0 / sersic_constant) ** sersic_index) lower_dex = 4.0 + np.log10(effective_radius) elif sersic_index > 3.8: total_cses = 40 sample_points = 50 lower_dex = 4.5 + np.log10(effective_radius) else: lower_dex = 3.5 + np.log10(effective_radius) total_cses = 30 sample_points = 50 return upper_dex, lower_dex, total_cses, sample_points
[ 11748, 4866, 201, 198, 11748, 299, 32152, 355, 45941, 201, 198, 6738, 629, 541, 88, 13, 20887, 1330, 266, 1659, 89, 201, 198, 6738, 629, 541, 88, 13, 18908, 4873, 1330, 15094, 201, 198, 6738, 19720, 1330, 7343, 11, 309, 29291, 201, ...
1.922076
8,303
from core.terraform.resources import BaseTerraformVariable
[ 6738, 4755, 13, 353, 430, 687, 13, 37540, 1330, 7308, 15156, 430, 687, 43015, 628 ]
4
15
node1 = Node("A"); node2 = Node("B"); node3 = Node("C"); node4 = Node("D"); node5 = Node("E"); node1.adjacencyList.append(node2); node1.adjacencyList.append(node3); node2.adjacencyList.append(node4); node4.adjacencyList.append(node5); bfs = BreadthFirstSearch(); bfs.bfs(node1);
[ 197, 197, 197, 197, 197, 201, 198, 17440, 16, 796, 19081, 7203, 32, 15341, 201, 198, 17440, 17, 796, 19081, 7203, 33, 15341, 201, 198, 17440, 18, 796, 19081, 7203, 34, 15341, 201, 198, 17440, 19, 796, 19081, 7203, 35, 15341, 201, 19...
2.214815
135
"""Connection object for Network Manager.""" from ipaddress import ip_address, ip_interface from typing import Optional from ...const import ATTR_ADDRESS, ATTR_PREFIX from ...utils.gdbus import DBus from ..const import ( DBUS_ATTR_ADDRESS_DATA, DBUS_ATTR_CONNECTION, DBUS_ATTR_GATEWAY, DBUS_ATTR_ID, DBUS_ATTR_IP4CONFIG, DBUS_ATTR_IP6CONFIG, DBUS_ATTR_NAMESERVER_DATA, DBUS_ATTR_NAMESERVERS, DBUS_ATTR_STATE, DBUS_ATTR_TYPE, DBUS_ATTR_UUID, DBUS_NAME_CONNECTION_ACTIVE, DBUS_NAME_IP4CONFIG, DBUS_NAME_IP6CONFIG, DBUS_NAME_NM, DBUS_OBJECT_BASE, ) from ..interface import DBusInterfaceProxy from .configuration import IpConfiguration
[ 37811, 32048, 2134, 329, 7311, 9142, 526, 15931, 198, 6738, 20966, 21975, 1330, 20966, 62, 21975, 11, 20966, 62, 39994, 198, 6738, 19720, 1330, 32233, 198, 198, 6738, 2644, 9979, 1330, 5161, 5446, 62, 2885, 7707, 7597, 11, 5161, 5446, 6...
2.288525
305
from __future__ import print_function, absolute_import from .beats import Beat from StringIO import StringIO import sys import os import json import urllib import webbrowser try: import pycurl except: print("Need pycurl dependency to use qubole as the deployment platform. Run pip install pycurl in your virtualenv and try this again.") sys.exit(1)
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 11, 4112, 62, 11748, 198, 6738, 764, 1350, 1381, 1330, 12568, 198, 6738, 10903, 9399, 1330, 10903, 9399, 198, 11748, 25064, 198, 11748, 28686, 198, 11748, 33918, 198, 11748, 2956, 297, 571, ...
3.471154
104
# Copyright 2020 Alexis Lopez Zubieta # # 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. import fnmatch import hashlib import logging import os import subprocess from pathlib import Path from urllib import request from appimagebuilder.common import shell from .package import Package DEPENDS_ON = ["dpkg-deb", "apt-get", "apt-key", "fakeroot", "apt-cache"]
[ 2, 220, 220, 15069, 220, 12131, 31078, 22593, 47828, 1155, 64, 198, 2, 198, 2, 220, 220, 2448, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597, 1048, 16727, 257, 198, 2, 220, 220, 4866, 286, 428, 3788, 290, 3917, 10314, ...
3.839662
237
# -*- coding: utf-8 *-* import logging from unittest import TestCase from nicepy import assert_equal_struct, multi_assert_equal_struct, pretty_repr, permuteflat log = logging.getLogger(__name__)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 1635, 12, 9, 198, 11748, 18931, 198, 6738, 555, 715, 395, 1330, 6208, 20448, 198, 198, 6738, 3621, 9078, 1330, 6818, 62, 40496, 62, 7249, 11, 5021, 62, 30493, 62, 40496, 62, 7249, 11, ...
2.884058
69
# -*- coding: utf-8 -*- # Generated by Django 1.10.1 on 2017-03-20 16:07 from __future__ import unicode_literals from django.db import migrations, models
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 37770, 352, 13, 940, 13, 16, 319, 2177, 12, 3070, 12, 1238, 1467, 25, 2998, 198, 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, ...
2.736842
57
from django.apps import AppConfig
[ 6738, 42625, 14208, 13, 18211, 1330, 2034, 16934, 201, 198, 201, 198 ]
3.083333
12
from base_interval import BaseInterval
[ 6738, 2779, 62, 3849, 2100, 1330, 7308, 9492, 2100, 628 ]
4
10
# # Copyright (c) Microsoft and contributors. 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. # # Warning: This code was generated by a tool. # # Changes to this file may cause incorrect behavior and will be lost if the # code is regenerated. from datetime import datetime import json from requests import Session, Request import time import uuid try: from urllib import quote, unquote except: from urllib.parse import quote, unquote from azure.common import AzureHttpError from azure.mgmt.common import AzureOperationResponse, OperationStatusResponse, OperationStatus, Service from azure.mgmt.common.arm import ResourceBase, ResourceBaseExtended def parse_account_type(self, value): """ Parse enum values for type AccountType. Args: value (string): The value to parse. Returns: AccountType: The enum value. """ if 'Standard_LRS'.lower() == value.lower(): return AccountType.StandardLRS if 'Standard_ZRS'.lower() == value.lower(): return AccountType.StandardZRS if 'Standard_GRS'.lower() == value.lower(): return AccountType.StandardGRS if 'Standard_RAGRS'.lower() == value.lower(): return AccountType.StandardRAGRS if 'Premium_LRS'.lower() == value.lower(): return AccountType.PremiumLRS raise IndexError('value is outside the valid range.') def account_type_to_string(self, value): """ Convert an enum of type AccountType to a string. Args: value (AccountType): The value to convert to a string. Returns: string: The enum value as a string. """ if value == AccountType.StandardLRS: return 'Standard_LRS' if value == AccountType.StandardZRS: return 'Standard_ZRS' if value == AccountType.StandardGRS: return 'Standard_GRS' if value == AccountType.StandardRAGRS: return 'Standard_RAGRS' if value == AccountType.PremiumLRS: return 'Premium_LRS' raise IndexError('value is outside the valid range.') def parse_key_name(self, value): """ Parse enum values for type KeyName. Args: value (string): The value to parse. Returns: KeyName: The enum value. """ if 'key1'.lower() == value.lower(): return KeyName.Key1 if 'key2'.lower() == value.lower(): return KeyName.Key2 raise IndexError('value is outside the valid range.') def key_name_to_string(self, value): """ Convert an enum of type KeyName to a string. Args: value (KeyName): The value to convert to a string. Returns: string: The enum value as a string. """ if value == KeyName.Key1: return 'key1' if value == KeyName.Key2: return 'key2' raise IndexError('value is outside the valid range.') def get_create_operation_status(self, operation_status_link): """ The Get Create Operation Status operation returns the status of the specified create operation. After calling the asynchronous Begin Create operation, you can call Get Create Operation Status to determine whether the operation has succeeded, failed, or is still in progress. Args: operation_status_link (string): The URL where the status of the long-running create operation can be checked. Returns: StorageAccountCreateResponse: The Create storage account operation response. """ # Validate if operation_status_link is None: raise ValueError('operation_status_link cannot be None.') # Tracing # Construct URL url = '' url = url + operation_status_link url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'GET' # Set Headers http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Send Request response = self.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200 and status_code != 202 and status_code != 500: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200 or status_code == 202 or status_code == 500: response_content = body result = StorageAccountCreateResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: storage_account_instance = StorageAccount(tags={}) result.storage_account = storage_account_instance id_value = response_doc.get('id', None) if id_value is not None: id_instance = id_value storage_account_instance.id = id_instance name_value = response_doc.get('name', None) if name_value is not None: name_instance = name_value storage_account_instance.name = name_instance type_value = response_doc.get('type', None) if type_value is not None: type_instance = type_value storage_account_instance.type = type_instance location_value = response_doc.get('location', None) if location_value is not None: location_instance = location_value storage_account_instance.location = location_instance tags_sequence_element = response_doc.get('tags', None) if tags_sequence_element is not None: for property in tags_sequence_element: tags_key = property tags_value = tags_sequence_element[property] storage_account_instance.tags[tags_key] = tags_value properties_value = response_doc.get('properties', None) if properties_value is not None: provisioning_state_value = properties_value.get('provisioningState', None) if provisioning_state_value is not None: provisioning_state_instance = provisioning_state_value storage_account_instance.provisioning_state = provisioning_state_instance account_type_value = properties_value.get('accountType', None) if account_type_value is not None: account_type_instance = account_type_value storage_account_instance.account_type = account_type_instance primary_endpoints_value = properties_value.get('primaryEndpoints', None) if primary_endpoints_value is not None: primary_endpoints_instance = Endpoints() storage_account_instance.primary_endpoints = primary_endpoints_instance blob_value = primary_endpoints_value.get('blob', None) if blob_value is not None: blob_instance = blob_value primary_endpoints_instance.blob = blob_instance queue_value = primary_endpoints_value.get('queue', None) if queue_value is not None: queue_instance = queue_value primary_endpoints_instance.queue = queue_instance table_value = primary_endpoints_value.get('table', None) if table_value is not None: table_instance = table_value primary_endpoints_instance.table = table_instance primary_location_value = properties_value.get('primaryLocation', None) if primary_location_value is not None: primary_location_instance = primary_location_value storage_account_instance.primary_location = primary_location_instance status_of_primary_value = properties_value.get('statusOfPrimary', None) if status_of_primary_value is not None: status_of_primary_instance = status_of_primary_value storage_account_instance.status_of_primary = status_of_primary_instance last_geo_failover_time_value = properties_value.get('lastGeoFailoverTime', None) if last_geo_failover_time_value is not None: last_geo_failover_time_instance = last_geo_failover_time_value storage_account_instance.last_geo_failover_time = last_geo_failover_time_instance secondary_location_value = properties_value.get('secondaryLocation', None) if secondary_location_value is not None: secondary_location_instance = secondary_location_value storage_account_instance.secondary_location = secondary_location_instance status_of_secondary_value = properties_value.get('statusOfSecondary', None) if status_of_secondary_value is not None: status_of_secondary_instance = status_of_secondary_value storage_account_instance.status_of_secondary = status_of_secondary_instance creation_time_value = properties_value.get('creationTime', None) if creation_time_value is not None: creation_time_instance = creation_time_value storage_account_instance.creation_time = creation_time_instance custom_domain_value = properties_value.get('customDomain', None) if custom_domain_value is not None: custom_domain_instance = CustomDomain() storage_account_instance.custom_domain = custom_domain_instance name_value2 = custom_domain_value.get('name', None) if name_value2 is not None: name_instance2 = name_value2 custom_domain_instance.name = name_instance2 use_sub_domain_value = custom_domain_value.get('useSubDomain', None) if use_sub_domain_value is not None: use_sub_domain_instance = use_sub_domain_value custom_domain_instance.use_sub_domain = use_sub_domain_instance secondary_endpoints_value = properties_value.get('secondaryEndpoints', None) if secondary_endpoints_value is not None: secondary_endpoints_instance = Endpoints() storage_account_instance.secondary_endpoints = secondary_endpoints_instance blob_value2 = secondary_endpoints_value.get('blob', None) if blob_value2 is not None: blob_instance2 = blob_value2 secondary_endpoints_instance.blob = blob_instance2 queue_value2 = secondary_endpoints_value.get('queue', None) if queue_value2 is not None: queue_instance2 = queue_value2 secondary_endpoints_instance.queue = queue_instance2 table_value2 = secondary_endpoints_value.get('table', None) if table_value2 is not None: table_instance2 = table_value2 secondary_endpoints_instance.table = table_instance2 result.status_code = status_code result.retry_after = int(response.headers.get('retryafter', '0')) result.request_id = response.headers.get('x-ms-request-id') if status_code == 409: result.status = OperationStatus.Failed if status_code == 500: result.status = OperationStatus.InProgress if status_code == 202: result.status = OperationStatus.InProgress if status_code == 200: result.status = OperationStatus.Succeeded return result class StorageAccountOperations(object): """ Operations for managing storage accounts. __NOTE__: An instance of this class is automatically created for an instance of the [StorageManagementClient] """ def begin_create(self, resource_group_name, account_name, parameters): """ Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. Args: resource_group_name (string): The name of the resource group within the users subscription. account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. parameters (StorageAccountCreateParameters): The parameters to provide for the created account. Returns: StorageAccountCreateResponse: The Create storage account operation response. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') if account_name is None: raise ValueError('account_name cannot be None.') if len(account_name) < 3: raise IndexError('account_name is outside the valid range.') if len(account_name) > 24: raise IndexError('account_name is outside the valid range.') for account_name_char in account_name: if account_name_char.islower() == False and account_name_char.isdigit() == False: raise IndexError('account_name is outside the valid range.') if parameters is None: raise ValueError('parameters cannot be None.') if parameters.account_type is None: raise ValueError('parameters.account_type cannot be None.') if parameters.location is None: raise ValueError('parameters.location cannot be None.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts/' url = url + quote(account_name) query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'PUT' # Set Headers http_request.headers['Content-Type'] = 'application/json' http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Serialize Request request_content = None request_doc = None storage_account_create_parameters_json_value = {} request_doc = storage_account_create_parameters_json_value storage_account_create_parameters_json_value['location'] = parameters.location if parameters.tags is not None: tags_dictionary = {} for tags_key in parameters.tags: tags_value = parameters.tags[tags_key] tags_dictionary[tags_key] = tags_value storage_account_create_parameters_json_value['tags'] = tags_dictionary properties_value = {} storage_account_create_parameters_json_value['properties'] = properties_value properties_value['accountType'] = str(parameters.account_type) if parameters.account_type is not None else 'StandardLRS' request_content = json.dumps(request_doc) http_request.data = request_content http_request.headers['Content-Length'] = len(request_content) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200 and status_code != 202: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200 or status_code == 202: response_content = body result = StorageAccountCreateResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: storage_account_instance = StorageAccount(tags={}) result.storage_account = storage_account_instance id_value = response_doc.get('id', None) if id_value is not None: id_instance = id_value storage_account_instance.id = id_instance name_value = response_doc.get('name', None) if name_value is not None: name_instance = name_value storage_account_instance.name = name_instance type_value = response_doc.get('type', None) if type_value is not None: type_instance = type_value storage_account_instance.type = type_instance location_value = response_doc.get('location', None) if location_value is not None: location_instance = location_value storage_account_instance.location = location_instance tags_sequence_element = response_doc.get('tags', None) if tags_sequence_element is not None: for property in tags_sequence_element: tags_key2 = property tags_value2 = tags_sequence_element[property] storage_account_instance.tags[tags_key2] = tags_value2 properties_value2 = response_doc.get('properties', None) if properties_value2 is not None: provisioning_state_value = properties_value2.get('provisioningState', None) if provisioning_state_value is not None: provisioning_state_instance = provisioning_state_value storage_account_instance.provisioning_state = provisioning_state_instance account_type_value = properties_value2.get('accountType', None) if account_type_value is not None: account_type_instance = account_type_value storage_account_instance.account_type = account_type_instance primary_endpoints_value = properties_value2.get('primaryEndpoints', None) if primary_endpoints_value is not None: primary_endpoints_instance = Endpoints() storage_account_instance.primary_endpoints = primary_endpoints_instance blob_value = primary_endpoints_value.get('blob', None) if blob_value is not None: blob_instance = blob_value primary_endpoints_instance.blob = blob_instance queue_value = primary_endpoints_value.get('queue', None) if queue_value is not None: queue_instance = queue_value primary_endpoints_instance.queue = queue_instance table_value = primary_endpoints_value.get('table', None) if table_value is not None: table_instance = table_value primary_endpoints_instance.table = table_instance primary_location_value = properties_value2.get('primaryLocation', None) if primary_location_value is not None: primary_location_instance = primary_location_value storage_account_instance.primary_location = primary_location_instance status_of_primary_value = properties_value2.get('statusOfPrimary', None) if status_of_primary_value is not None: status_of_primary_instance = status_of_primary_value storage_account_instance.status_of_primary = status_of_primary_instance last_geo_failover_time_value = properties_value2.get('lastGeoFailoverTime', None) if last_geo_failover_time_value is not None: last_geo_failover_time_instance = last_geo_failover_time_value storage_account_instance.last_geo_failover_time = last_geo_failover_time_instance secondary_location_value = properties_value2.get('secondaryLocation', None) if secondary_location_value is not None: secondary_location_instance = secondary_location_value storage_account_instance.secondary_location = secondary_location_instance status_of_secondary_value = properties_value2.get('statusOfSecondary', None) if status_of_secondary_value is not None: status_of_secondary_instance = status_of_secondary_value storage_account_instance.status_of_secondary = status_of_secondary_instance creation_time_value = properties_value2.get('creationTime', None) if creation_time_value is not None: creation_time_instance = creation_time_value storage_account_instance.creation_time = creation_time_instance custom_domain_value = properties_value2.get('customDomain', None) if custom_domain_value is not None: custom_domain_instance = CustomDomain() storage_account_instance.custom_domain = custom_domain_instance name_value2 = custom_domain_value.get('name', None) if name_value2 is not None: name_instance2 = name_value2 custom_domain_instance.name = name_instance2 use_sub_domain_value = custom_domain_value.get('useSubDomain', None) if use_sub_domain_value is not None: use_sub_domain_instance = use_sub_domain_value custom_domain_instance.use_sub_domain = use_sub_domain_instance secondary_endpoints_value = properties_value2.get('secondaryEndpoints', None) if secondary_endpoints_value is not None: secondary_endpoints_instance = Endpoints() storage_account_instance.secondary_endpoints = secondary_endpoints_instance blob_value2 = secondary_endpoints_value.get('blob', None) if blob_value2 is not None: blob_instance2 = blob_value2 secondary_endpoints_instance.blob = blob_instance2 queue_value2 = secondary_endpoints_value.get('queue', None) if queue_value2 is not None: queue_instance2 = queue_value2 secondary_endpoints_instance.queue = queue_instance2 table_value2 = secondary_endpoints_value.get('table', None) if table_value2 is not None: table_instance2 = table_value2 secondary_endpoints_instance.table = table_instance2 result.status_code = status_code result.operation_status_link = response.headers.get('location') result.retry_after = int(response.headers.get('retryafter', '0')) result.request_id = response.headers.get('x-ms-request-id') if status_code == 409 or status_code == 400: result.status = OperationStatus.Failed if status_code == 200: result.status = OperationStatus.Succeeded return result def check_name_availability(self, account_name): """ Checks that account name is valid and is not in use. Args: account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. Returns: CheckNameAvailabilityResponse: The CheckNameAvailability operation response. """ # Validate if account_name is None: raise ValueError('account_name cannot be None.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/providers/Microsoft.Storage/checkNameAvailability' query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'POST' # Set Headers http_request.headers['Content-Type'] = 'application/json' http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Serialize Request request_content = None request_doc = None storage_account_check_name_availability_parameters_value = {} request_doc = storage_account_check_name_availability_parameters_value storage_account_check_name_availability_parameters_value['name'] = account_name storage_account_check_name_availability_parameters_value['type'] = 'Microsoft.Storage/storageAccounts' request_content = json.dumps(request_doc) http_request.data = request_content http_request.headers['Content-Length'] = len(request_content) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = CheckNameAvailabilityResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: name_available_value = response_doc.get('nameAvailable', None) if name_available_value is not None: name_available_instance = name_available_value result.name_available = name_available_instance reason_value = response_doc.get('reason', None) if reason_value is not None: reason_instance = reason_value result.reason = reason_instance message_value = response_doc.get('message', None) if message_value is not None: message_instance = message_value result.message = message_instance result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def create(self, resource_group_name, account_name, parameters): """ Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent create request is issued with exact same set of properties, the request succeeds.The max number of storage accounts that can be created per subscription is limited to 20. Args: resource_group_name (string): The name of the resource group within the users subscription. account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. parameters (StorageAccountCreateParameters): The parameters to provide for the created account. Returns: StorageAccountCreateResponse: The Create storage account operation response. """ client2 = self.client response = client2.storage_accounts.begin_create(resource_group_name, account_name, parameters) if response.status == OperationStatus.succeeded: return response result = client2.get_create_operation_status(response.operation_status_link) delay_in_seconds = response.retry_after if delay_in_seconds == 0: delay_in_seconds = 25 if client2.long_running_operation_initial_timeout >= 0: delay_in_seconds = client2.long_running_operation_initial_timeout while (result.status != OperationStatus.in_progress) == False: time.sleep(delay_in_seconds) result = client2.get_create_operation_status(response.operation_status_link) delay_in_seconds = result.retry_after if delay_in_seconds == 0: delay_in_seconds = 25 if client2.long_running_operation_retry_timeout >= 0: delay_in_seconds = client2.long_running_operation_retry_timeout return result def delete(self, resource_group_name, account_name): """ Deletes a storage account in Microsoft Azure. Args: resource_group_name (string): The name of the resource group within the users subscription. account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. Returns: AzureOperationResponse: A standard service response including an HTTP status code and request ID. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') if account_name is None: raise ValueError('account_name cannot be None.') if len(account_name) < 3: raise IndexError('account_name is outside the valid range.') if len(account_name) > 24: raise IndexError('account_name is outside the valid range.') for account_name_char in account_name: if account_name_char.islower() == False and account_name_char.isdigit() == False: raise IndexError('account_name is outside the valid range.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts/' url = url + quote(account_name) query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'DELETE' # Set Headers http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200 and status_code != 204: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response result = AzureOperationResponse() result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def get_properties(self, resource_group_name, account_name): """ Returns the properties for the specified storage account including but not limited to name, account type, location, and account status. The ListKeys operation should be used to retrieve storage keys. Args: resource_group_name (string): The name of the resource group within the users subscription. account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. Returns: StorageAccountGetPropertiesResponse: The Get storage account operation response. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') if account_name is None: raise ValueError('account_name cannot be None.') if len(account_name) < 3: raise IndexError('account_name is outside the valid range.') if len(account_name) > 24: raise IndexError('account_name is outside the valid range.') for account_name_char in account_name: if account_name_char.islower() == False and account_name_char.isdigit() == False: raise IndexError('account_name is outside the valid range.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts/' url = url + quote(account_name) query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'GET' # Set Headers http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = StorageAccountGetPropertiesResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: storage_account_instance = StorageAccount(tags={}) result.storage_account = storage_account_instance id_value = response_doc.get('id', None) if id_value is not None: id_instance = id_value storage_account_instance.id = id_instance name_value = response_doc.get('name', None) if name_value is not None: name_instance = name_value storage_account_instance.name = name_instance type_value = response_doc.get('type', None) if type_value is not None: type_instance = type_value storage_account_instance.type = type_instance location_value = response_doc.get('location', None) if location_value is not None: location_instance = location_value storage_account_instance.location = location_instance tags_sequence_element = response_doc.get('tags', None) if tags_sequence_element is not None: for property in tags_sequence_element: tags_key = property tags_value = tags_sequence_element[property] storage_account_instance.tags[tags_key] = tags_value properties_value = response_doc.get('properties', None) if properties_value is not None: provisioning_state_value = properties_value.get('provisioningState', None) if provisioning_state_value is not None: provisioning_state_instance = provisioning_state_value storage_account_instance.provisioning_state = provisioning_state_instance account_type_value = properties_value.get('accountType', None) if account_type_value is not None: account_type_instance = account_type_value storage_account_instance.account_type = account_type_instance primary_endpoints_value = properties_value.get('primaryEndpoints', None) if primary_endpoints_value is not None: primary_endpoints_instance = Endpoints() storage_account_instance.primary_endpoints = primary_endpoints_instance blob_value = primary_endpoints_value.get('blob', None) if blob_value is not None: blob_instance = blob_value primary_endpoints_instance.blob = blob_instance queue_value = primary_endpoints_value.get('queue', None) if queue_value is not None: queue_instance = queue_value primary_endpoints_instance.queue = queue_instance table_value = primary_endpoints_value.get('table', None) if table_value is not None: table_instance = table_value primary_endpoints_instance.table = table_instance primary_location_value = properties_value.get('primaryLocation', None) if primary_location_value is not None: primary_location_instance = primary_location_value storage_account_instance.primary_location = primary_location_instance status_of_primary_value = properties_value.get('statusOfPrimary', None) if status_of_primary_value is not None: status_of_primary_instance = status_of_primary_value storage_account_instance.status_of_primary = status_of_primary_instance last_geo_failover_time_value = properties_value.get('lastGeoFailoverTime', None) if last_geo_failover_time_value is not None: last_geo_failover_time_instance = last_geo_failover_time_value storage_account_instance.last_geo_failover_time = last_geo_failover_time_instance secondary_location_value = properties_value.get('secondaryLocation', None) if secondary_location_value is not None: secondary_location_instance = secondary_location_value storage_account_instance.secondary_location = secondary_location_instance status_of_secondary_value = properties_value.get('statusOfSecondary', None) if status_of_secondary_value is not None: status_of_secondary_instance = status_of_secondary_value storage_account_instance.status_of_secondary = status_of_secondary_instance creation_time_value = properties_value.get('creationTime', None) if creation_time_value is not None: creation_time_instance = creation_time_value storage_account_instance.creation_time = creation_time_instance custom_domain_value = properties_value.get('customDomain', None) if custom_domain_value is not None: custom_domain_instance = CustomDomain() storage_account_instance.custom_domain = custom_domain_instance name_value2 = custom_domain_value.get('name', None) if name_value2 is not None: name_instance2 = name_value2 custom_domain_instance.name = name_instance2 use_sub_domain_value = custom_domain_value.get('useSubDomain', None) if use_sub_domain_value is not None: use_sub_domain_instance = use_sub_domain_value custom_domain_instance.use_sub_domain = use_sub_domain_instance secondary_endpoints_value = properties_value.get('secondaryEndpoints', None) if secondary_endpoints_value is not None: secondary_endpoints_instance = Endpoints() storage_account_instance.secondary_endpoints = secondary_endpoints_instance blob_value2 = secondary_endpoints_value.get('blob', None) if blob_value2 is not None: blob_instance2 = blob_value2 secondary_endpoints_instance.blob = blob_instance2 queue_value2 = secondary_endpoints_value.get('queue', None) if queue_value2 is not None: queue_instance2 = queue_value2 secondary_endpoints_instance.queue = queue_instance2 table_value2 = secondary_endpoints_value.get('table', None) if table_value2 is not None: table_instance2 = table_value2 secondary_endpoints_instance.table = table_instance2 result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def list(self): """ Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. Returns: StorageAccountListResponse: The list storage accounts operation response. """ # Validate # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/providers/Microsoft.Storage/storageAccounts' query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'GET' # Set Headers http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = StorageAccountListResponse(storage_accounts=[]) response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: value_array = response_doc.get('value', None) if value_array is not None: for value_value in value_array: storage_account_json_instance = StorageAccount(tags={}) result.storage_accounts.append(storage_account_json_instance) id_value = value_value.get('id', None) if id_value is not None: id_instance = id_value storage_account_json_instance.id = id_instance name_value = value_value.get('name', None) if name_value is not None: name_instance = name_value storage_account_json_instance.name = name_instance type_value = value_value.get('type', None) if type_value is not None: type_instance = type_value storage_account_json_instance.type = type_instance location_value = value_value.get('location', None) if location_value is not None: location_instance = location_value storage_account_json_instance.location = location_instance tags_sequence_element = value_value.get('tags', None) if tags_sequence_element is not None: for property in tags_sequence_element: tags_key = property tags_value = tags_sequence_element[property] storage_account_json_instance.tags[tags_key] = tags_value properties_value = value_value.get('properties', None) if properties_value is not None: provisioning_state_value = properties_value.get('provisioningState', None) if provisioning_state_value is not None: provisioning_state_instance = provisioning_state_value storage_account_json_instance.provisioning_state = provisioning_state_instance account_type_value = properties_value.get('accountType', None) if account_type_value is not None: account_type_instance = account_type_value storage_account_json_instance.account_type = account_type_instance primary_endpoints_value = properties_value.get('primaryEndpoints', None) if primary_endpoints_value is not None: primary_endpoints_instance = Endpoints() storage_account_json_instance.primary_endpoints = primary_endpoints_instance blob_value = primary_endpoints_value.get('blob', None) if blob_value is not None: blob_instance = blob_value primary_endpoints_instance.blob = blob_instance queue_value = primary_endpoints_value.get('queue', None) if queue_value is not None: queue_instance = queue_value primary_endpoints_instance.queue = queue_instance table_value = primary_endpoints_value.get('table', None) if table_value is not None: table_instance = table_value primary_endpoints_instance.table = table_instance primary_location_value = properties_value.get('primaryLocation', None) if primary_location_value is not None: primary_location_instance = primary_location_value storage_account_json_instance.primary_location = primary_location_instance status_of_primary_value = properties_value.get('statusOfPrimary', None) if status_of_primary_value is not None: status_of_primary_instance = status_of_primary_value storage_account_json_instance.status_of_primary = status_of_primary_instance last_geo_failover_time_value = properties_value.get('lastGeoFailoverTime', None) if last_geo_failover_time_value is not None: last_geo_failover_time_instance = last_geo_failover_time_value storage_account_json_instance.last_geo_failover_time = last_geo_failover_time_instance secondary_location_value = properties_value.get('secondaryLocation', None) if secondary_location_value is not None: secondary_location_instance = secondary_location_value storage_account_json_instance.secondary_location = secondary_location_instance status_of_secondary_value = properties_value.get('statusOfSecondary', None) if status_of_secondary_value is not None: status_of_secondary_instance = status_of_secondary_value storage_account_json_instance.status_of_secondary = status_of_secondary_instance creation_time_value = properties_value.get('creationTime', None) if creation_time_value is not None: creation_time_instance = creation_time_value storage_account_json_instance.creation_time = creation_time_instance custom_domain_value = properties_value.get('customDomain', None) if custom_domain_value is not None: custom_domain_instance = CustomDomain() storage_account_json_instance.custom_domain = custom_domain_instance name_value2 = custom_domain_value.get('name', None) if name_value2 is not None: name_instance2 = name_value2 custom_domain_instance.name = name_instance2 use_sub_domain_value = custom_domain_value.get('useSubDomain', None) if use_sub_domain_value is not None: use_sub_domain_instance = use_sub_domain_value custom_domain_instance.use_sub_domain = use_sub_domain_instance secondary_endpoints_value = properties_value.get('secondaryEndpoints', None) if secondary_endpoints_value is not None: secondary_endpoints_instance = Endpoints() storage_account_json_instance.secondary_endpoints = secondary_endpoints_instance blob_value2 = secondary_endpoints_value.get('blob', None) if blob_value2 is not None: blob_instance2 = blob_value2 secondary_endpoints_instance.blob = blob_instance2 queue_value2 = secondary_endpoints_value.get('queue', None) if queue_value2 is not None: queue_instance2 = queue_value2 secondary_endpoints_instance.queue = queue_instance2 table_value2 = secondary_endpoints_value.get('table', None) if table_value2 is not None: table_instance2 = table_value2 secondary_endpoints_instance.table = table_instance2 next_link_value = response_doc.get('nextLink', None) if next_link_value is not None: next_link_instance = next_link_value result.next_link = next_link_instance result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def list_by_resource_group(self, resource_group_name): """ Lists all the storage accounts available under the given resource group. Note that storage keys are not returned; use the ListKeys operation for this. Args: resource_group_name (string): The name of the resource group within the users subscription. Returns: StorageAccountListResponse: The list storage accounts operation response. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts' query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'GET' # Set Headers http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = StorageAccountListResponse(storage_accounts=[]) response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: value_array = response_doc.get('value', None) if value_array is not None: for value_value in value_array: storage_account_json_instance = StorageAccount(tags={}) result.storage_accounts.append(storage_account_json_instance) id_value = value_value.get('id', None) if id_value is not None: id_instance = id_value storage_account_json_instance.id = id_instance name_value = value_value.get('name', None) if name_value is not None: name_instance = name_value storage_account_json_instance.name = name_instance type_value = value_value.get('type', None) if type_value is not None: type_instance = type_value storage_account_json_instance.type = type_instance location_value = value_value.get('location', None) if location_value is not None: location_instance = location_value storage_account_json_instance.location = location_instance tags_sequence_element = value_value.get('tags', None) if tags_sequence_element is not None: for property in tags_sequence_element: tags_key = property tags_value = tags_sequence_element[property] storage_account_json_instance.tags[tags_key] = tags_value properties_value = value_value.get('properties', None) if properties_value is not None: provisioning_state_value = properties_value.get('provisioningState', None) if provisioning_state_value is not None: provisioning_state_instance = provisioning_state_value storage_account_json_instance.provisioning_state = provisioning_state_instance account_type_value = properties_value.get('accountType', None) if account_type_value is not None: account_type_instance = account_type_value storage_account_json_instance.account_type = account_type_instance primary_endpoints_value = properties_value.get('primaryEndpoints', None) if primary_endpoints_value is not None: primary_endpoints_instance = Endpoints() storage_account_json_instance.primary_endpoints = primary_endpoints_instance blob_value = primary_endpoints_value.get('blob', None) if blob_value is not None: blob_instance = blob_value primary_endpoints_instance.blob = blob_instance queue_value = primary_endpoints_value.get('queue', None) if queue_value is not None: queue_instance = queue_value primary_endpoints_instance.queue = queue_instance table_value = primary_endpoints_value.get('table', None) if table_value is not None: table_instance = table_value primary_endpoints_instance.table = table_instance primary_location_value = properties_value.get('primaryLocation', None) if primary_location_value is not None: primary_location_instance = primary_location_value storage_account_json_instance.primary_location = primary_location_instance status_of_primary_value = properties_value.get('statusOfPrimary', None) if status_of_primary_value is not None: status_of_primary_instance = status_of_primary_value storage_account_json_instance.status_of_primary = status_of_primary_instance last_geo_failover_time_value = properties_value.get('lastGeoFailoverTime', None) if last_geo_failover_time_value is not None: last_geo_failover_time_instance = last_geo_failover_time_value storage_account_json_instance.last_geo_failover_time = last_geo_failover_time_instance secondary_location_value = properties_value.get('secondaryLocation', None) if secondary_location_value is not None: secondary_location_instance = secondary_location_value storage_account_json_instance.secondary_location = secondary_location_instance status_of_secondary_value = properties_value.get('statusOfSecondary', None) if status_of_secondary_value is not None: status_of_secondary_instance = status_of_secondary_value storage_account_json_instance.status_of_secondary = status_of_secondary_instance creation_time_value = properties_value.get('creationTime', None) if creation_time_value is not None: creation_time_instance = creation_time_value storage_account_json_instance.creation_time = creation_time_instance custom_domain_value = properties_value.get('customDomain', None) if custom_domain_value is not None: custom_domain_instance = CustomDomain() storage_account_json_instance.custom_domain = custom_domain_instance name_value2 = custom_domain_value.get('name', None) if name_value2 is not None: name_instance2 = name_value2 custom_domain_instance.name = name_instance2 use_sub_domain_value = custom_domain_value.get('useSubDomain', None) if use_sub_domain_value is not None: use_sub_domain_instance = use_sub_domain_value custom_domain_instance.use_sub_domain = use_sub_domain_instance secondary_endpoints_value = properties_value.get('secondaryEndpoints', None) if secondary_endpoints_value is not None: secondary_endpoints_instance = Endpoints() storage_account_json_instance.secondary_endpoints = secondary_endpoints_instance blob_value2 = secondary_endpoints_value.get('blob', None) if blob_value2 is not None: blob_instance2 = blob_value2 secondary_endpoints_instance.blob = blob_instance2 queue_value2 = secondary_endpoints_value.get('queue', None) if queue_value2 is not None: queue_instance2 = queue_value2 secondary_endpoints_instance.queue = queue_instance2 table_value2 = secondary_endpoints_value.get('table', None) if table_value2 is not None: table_instance2 = table_value2 secondary_endpoints_instance.table = table_instance2 next_link_value = response_doc.get('nextLink', None) if next_link_value is not None: next_link_instance = next_link_value result.next_link = next_link_instance result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def list_keys(self, resource_group_name, account_name): """ Lists the access keys for the specified storage account. Args: resource_group_name (string): The name of the resource group. account_name (string): The name of the storage account. Returns: StorageAccountListKeysResponse: The ListKeys operation response. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') if account_name is None: raise ValueError('account_name cannot be None.') if len(account_name) < 3: raise IndexError('account_name is outside the valid range.') if len(account_name) > 24: raise IndexError('account_name is outside the valid range.') for account_name_char in account_name: if account_name_char.islower() == False and account_name_char.isdigit() == False: raise IndexError('account_name is outside the valid range.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts/' url = url + quote(account_name) url = url + '/listKeys' query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'POST' # Set Headers http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = StorageAccountListKeysResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: storage_account_keys_instance = StorageAccountKeys() result.storage_account_keys = storage_account_keys_instance key1_value = response_doc.get('key1', None) if key1_value is not None: key1_instance = key1_value storage_account_keys_instance.key1 = key1_instance key2_value = response_doc.get('key2', None) if key2_value is not None: key2_instance = key2_value storage_account_keys_instance.key2 = key2_instance result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def regenerate_key(self, resource_group_name, account_name, regenerate_key): """ Regenerates the access keys for the specified storage account. Args: resource_group_name (string): The name of the resource group within the users subscription. account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. regenerate_key (KeyName): Specifies name of the key which should be regenerated. Returns: StorageAccountRegenerateKeyResponse: The RegenerateKey operation response. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') if account_name is None: raise ValueError('account_name cannot be None.') if len(account_name) < 3: raise IndexError('account_name is outside the valid range.') if len(account_name) > 24: raise IndexError('account_name is outside the valid range.') for account_name_char in account_name: if account_name_char.islower() == False and account_name_char.isdigit() == False: raise IndexError('account_name is outside the valid range.') if regenerate_key is None: raise ValueError('regenerate_key cannot be None.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts/' url = url + quote(account_name) url = url + '/regenerateKey' query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'POST' # Set Headers http_request.headers['Content-Type'] = 'application/json' http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Serialize Request request_content = None request_doc = None storage_account_regenerate_key_parameters_value = {} request_doc = storage_account_regenerate_key_parameters_value storage_account_regenerate_key_parameters_value['keyName'] = str(regenerate_key) if regenerate_key is not None else 'Key1' request_content = json.dumps(request_doc) http_request.data = request_content http_request.headers['Content-Length'] = len(request_content) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = StorageAccountRegenerateKeyResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: storage_account_keys_instance = StorageAccountKeys() result.storage_account_keys = storage_account_keys_instance key1_value = response_doc.get('key1', None) if key1_value is not None: key1_instance = key1_value storage_account_keys_instance.key1 = key1_instance key2_value = response_doc.get('key2', None) if key2_value is not None: key2_instance = key2_value storage_account_keys_instance.key2 = key2_instance result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result def update(self, resource_group_name, account_name, parameters): """ Updates the account type or tags for a storage account. It can also be used to add a custom domain (note that custom domains cannot be added via the Create operation). Only one custom domain is supported per storage account. This API can only be used to update one of tags, accountType, or customDomain per call. To update multiple of these properties, call the API multiple times with one change per call. This call does not change the storage keys for the account. If you want to change storage account keys, use the RegenerateKey operation. The location and name of the storage account cannot be changed after creation. Args: resource_group_name (string): The name of the resource group within the users subscription. account_name (string): The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. parameters (StorageAccountUpdateParameters): The parameters to update on the account. Note that only one property can be changed at a time using this API. Returns: StorageAccountUpdateResponse: The Update storage account operation response. """ # Validate if resource_group_name is None: raise ValueError('resource_group_name cannot be None.') if account_name is None: raise ValueError('account_name cannot be None.') if len(account_name) < 3: raise IndexError('account_name is outside the valid range.') if len(account_name) > 24: raise IndexError('account_name is outside the valid range.') for account_name_char in account_name: if account_name_char.islower() == False and account_name_char.isdigit() == False: raise IndexError('account_name is outside the valid range.') if parameters is None: raise ValueError('parameters cannot be None.') if parameters.custom_domain is not None: if parameters.custom_domain.name is None: raise ValueError('parameters.custom_domain.name cannot be None.') # Tracing # Construct URL url = '' url = url + '/subscriptions/' if self.client.credentials.subscription_id is not None: url = url + quote(self.client.credentials.subscription_id) url = url + '/resourceGroups/' url = url + quote(resource_group_name) url = url + '/providers/Microsoft.Storage/storageAccounts/' url = url + quote(account_name) query_parameters = [] query_parameters.append('api-version=2015-05-01-preview') if len(query_parameters) > 0: url = url + '?' + '&'.join(query_parameters) base_url = self.client.base_uri # Trim '/' character from the end of baseUrl and beginning of url. if base_url[len(base_url) - 1] == '/': base_url = base_url[0 : len(base_url) - 1] if url[0] == '/': url = url[1 : ] url = base_url + '/' + url url = url.replace(' ', '%20') # Create HTTP transport objects http_request = Request() http_request.url = url http_request.method = 'PATCH' # Set Headers http_request.headers['Content-Type'] = 'application/json' http_request.headers['x-ms-client-request-id'] = str(uuid.uuid4()) # Serialize Request request_content = None request_doc = None storage_account_update_parameters_json_value = {} request_doc = storage_account_update_parameters_json_value if parameters.tags is not None: tags_dictionary = {} for tags_key in parameters.tags: tags_value = parameters.tags[tags_key] tags_dictionary[tags_key] = tags_value storage_account_update_parameters_json_value['tags'] = tags_dictionary properties_value = {} storage_account_update_parameters_json_value['properties'] = properties_value if parameters.account_type is not None: properties_value['accountType'] = str(parameters.account_type) if parameters.account_type is not None else 'StandardLRS' if parameters.custom_domain is not None: custom_domain_value = {} properties_value['customDomain'] = custom_domain_value custom_domain_value['name'] = parameters.custom_domain.name if parameters.custom_domain.use_sub_domain is not None: custom_domain_value['useSubDomain'] = parameters.custom_domain.use_sub_domain request_content = json.dumps(request_doc) http_request.data = request_content http_request.headers['Content-Length'] = len(request_content) # Send Request response = self.client.send_request(http_request) body = response.content status_code = response.status_code if status_code != 200: error = AzureHttpError(body, response.status_code) raise error # Create Result result = None # Deserialize Response if status_code == 200: response_content = body result = StorageAccountUpdateResponse() response_doc = None if response_content: response_doc = json.loads(response_content.decode()) if response_doc is not None: storage_account_instance = StorageAccount(tags={}) result.storage_account = storage_account_instance id_value = response_doc.get('id', None) if id_value is not None: id_instance = id_value storage_account_instance.id = id_instance name_value = response_doc.get('name', None) if name_value is not None: name_instance = name_value storage_account_instance.name = name_instance type_value = response_doc.get('type', None) if type_value is not None: type_instance = type_value storage_account_instance.type = type_instance location_value = response_doc.get('location', None) if location_value is not None: location_instance = location_value storage_account_instance.location = location_instance tags_sequence_element = response_doc.get('tags', None) if tags_sequence_element is not None: for property in tags_sequence_element: tags_key2 = property tags_value2 = tags_sequence_element[property] storage_account_instance.tags[tags_key2] = tags_value2 properties_value2 = response_doc.get('properties', None) if properties_value2 is not None: provisioning_state_value = properties_value2.get('provisioningState', None) if provisioning_state_value is not None: provisioning_state_instance = provisioning_state_value storage_account_instance.provisioning_state = provisioning_state_instance account_type_value = properties_value2.get('accountType', None) if account_type_value is not None: account_type_instance = account_type_value storage_account_instance.account_type = account_type_instance primary_endpoints_value = properties_value2.get('primaryEndpoints', None) if primary_endpoints_value is not None: primary_endpoints_instance = Endpoints() storage_account_instance.primary_endpoints = primary_endpoints_instance blob_value = primary_endpoints_value.get('blob', None) if blob_value is not None: blob_instance = blob_value primary_endpoints_instance.blob = blob_instance queue_value = primary_endpoints_value.get('queue', None) if queue_value is not None: queue_instance = queue_value primary_endpoints_instance.queue = queue_instance table_value = primary_endpoints_value.get('table', None) if table_value is not None: table_instance = table_value primary_endpoints_instance.table = table_instance primary_location_value = properties_value2.get('primaryLocation', None) if primary_location_value is not None: primary_location_instance = primary_location_value storage_account_instance.primary_location = primary_location_instance status_of_primary_value = properties_value2.get('statusOfPrimary', None) if status_of_primary_value is not None: status_of_primary_instance = status_of_primary_value storage_account_instance.status_of_primary = status_of_primary_instance last_geo_failover_time_value = properties_value2.get('lastGeoFailoverTime', None) if last_geo_failover_time_value is not None: last_geo_failover_time_instance = last_geo_failover_time_value storage_account_instance.last_geo_failover_time = last_geo_failover_time_instance secondary_location_value = properties_value2.get('secondaryLocation', None) if secondary_location_value is not None: secondary_location_instance = secondary_location_value storage_account_instance.secondary_location = secondary_location_instance status_of_secondary_value = properties_value2.get('statusOfSecondary', None) if status_of_secondary_value is not None: status_of_secondary_instance = status_of_secondary_value storage_account_instance.status_of_secondary = status_of_secondary_instance creation_time_value = properties_value2.get('creationTime', None) if creation_time_value is not None: creation_time_instance = creation_time_value storage_account_instance.creation_time = creation_time_instance custom_domain_value2 = properties_value2.get('customDomain', None) if custom_domain_value2 is not None: custom_domain_instance = CustomDomain() storage_account_instance.custom_domain = custom_domain_instance name_value2 = custom_domain_value2.get('name', None) if name_value2 is not None: name_instance2 = name_value2 custom_domain_instance.name = name_instance2 use_sub_domain_value = custom_domain_value2.get('useSubDomain', None) if use_sub_domain_value is not None: use_sub_domain_instance = use_sub_domain_value custom_domain_instance.use_sub_domain = use_sub_domain_instance secondary_endpoints_value = properties_value2.get('secondaryEndpoints', None) if secondary_endpoints_value is not None: secondary_endpoints_instance = Endpoints() storage_account_instance.secondary_endpoints = secondary_endpoints_instance blob_value2 = secondary_endpoints_value.get('blob', None) if blob_value2 is not None: blob_instance2 = blob_value2 secondary_endpoints_instance.blob = blob_instance2 queue_value2 = secondary_endpoints_value.get('queue', None) if queue_value2 is not None: queue_instance2 = queue_value2 secondary_endpoints_instance.queue = queue_instance2 table_value2 = secondary_endpoints_value.get('table', None) if table_value2 is not None: table_instance2 = table_value2 secondary_endpoints_instance.table = table_instance2 result.status_code = status_code result.request_id = response.headers.get('x-ms-request-id') return result
[ 2, 220, 201, 198, 2, 15069, 357, 66, 8, 5413, 290, 20420, 13, 220, 1439, 2489, 10395, 13, 201, 198, 2, 220, 201, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 201, 198, 2, 345, 743,...
1.945131
50,174
#!/usr/bin/env python2 # Copyright 2015 Dejan D. M. Milosavljevic # # 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 platform import nucleotide import nucleotide.component import nucleotide.component.function atom_linux_RTL = { 'platform' : { 'host' : 'Linux', 'guest' : 'Linux' }, 'cc' : { 'vendor': 'FSF', 'name' : 'gcc', 'version': 'X' }, 'config' : { 'LINKFLAGS' : _linux_RTL_LINKFLAGS }, 'name' :'RTL', 'class': [ 'RTL', 'linux:RTL' ] }
[ 198, 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 17, 198, 198, 2, 220, 220, 15069, 1853, 1024, 13881, 360, 13, 337, 13, 4460, 418, 615, 75, 73, 1990, 291, 198, 2, 198, 2, 220, 220, 49962, 739, 262, 24843, 13789, 11, 10628, 362, ...
2.603912
409
import os policy_model_dir = os.environ.get("POLICY_MODEL_DIR", "models/dialogue/") rasa_nlu_config = os.environ.get("RASA_NLU_CONFIG", "nlu_config.yml") account_sid = os.environ.get("ACCOUNT_SID", "") auth_token = os.environ.get("AUTH_TOKEN", "") twilio_number = os.environ.get("TWILIO_NUMBER", "") platform_api = os.environ.get("RASA_API_ENDPOINT_URL", "") self_port = int(os.environ.get("SELF_PORT", "5001")) core_model_dir = os.environ.get("CORE_MODEL_DIR", "models/dialogue/") remote_core_endpoint = os.environ.get("RASA_REMOTE_CORE_ENDPOINT_URL", "") rasa_core_token = os.environ.get("RASA_CORE_TOKEN", "") mailchimp_api_key = os.environ.get("MAILCHIMP_API_KEY", "") mailchimp_list = os.environ.get("MAILCHIMP_LIST", "") gdrive_credentials = os.environ.get("GDRIVE_CREDENTIALS", "") access_token = os.environ.get("TELEGRAM_TOKEN", "") verify = os.environ.get("TELEGRAM_VERIFY", "rasas_bot") webhook_url = os.environ.get("WEBHOOK_URL", "https://website-demo.rasa.com/webhook") rasa_platform_token = os.environ.get("RASA_PLATFORM_TOKEN", "") rasa_nlg_endpoint = os.environ.get("RASA_NLG_ENDPOINT_URL", "")
[ 11748, 28686, 198, 198, 30586, 62, 19849, 62, 15908, 796, 28686, 13, 268, 2268, 13, 1136, 7203, 45472, 2149, 56, 62, 33365, 3698, 62, 34720, 1600, 366, 27530, 14, 38969, 5119, 14, 4943, 198, 198, 8847, 64, 62, 77, 2290, 62, 11250, 7...
2.196881
513
# -*- coding:utf-8 -*- from moderation_sdk.gettoken import get_token from moderation_sdk.moderation_text import moderation_text from moderation_sdk.utils import init_global_env if __name__ == '__main__': # Services currently support North China-Beijing(cn-north-4),China East-Shanghai1(cn-east-3), CN-Hong Kong(ap-southeast-1),AP-Singapore(ap-southeast-3) init_global_env('cn-north-4') # # access moderation text enhance,posy data by token # user_name = '******' password = '******' account_name = '******' # the same as user_name in commonly use token = get_token(user_name, password, account_name) # call interface use the text result = moderation_text(token, '666666luo+110qqfuck666666666666666', 'content', ['ad', 'politics', 'porn', 'abuse', 'contraband', 'flood']) print(result)
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 6738, 34401, 62, 21282, 74, 13, 1136, 30001, 1330, 651, 62, 30001, 198, 6738, 34401, 62, 21282, 74, 13, 4666, 263, 341, 62, 5239, 1330, 34401, 62, 5239, 198, 6738, 34401, ...
2.627273
330
from .base import BaseActionTestCase
[ 6738, 764, 8692, 1330, 7308, 12502, 14402, 20448, 628 ]
4.222222
9
from .common import * HEADER = r'''\usepackage{tikz} \definecolor{purple}{cmyk}{0.55,1,0,0.15} \definecolor{darkblue}{cmyk}{1,0.58,0,0.21} \usepackage[colorlinks, linkcolor=black, urlcolor=darkblue, citecolor=purple]{hyperref} \urlstyle{same} \newtheorem{theorem}{Theorem}[section] \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{conjecture}[theorem]{Conjecture} \newtheorem{claim}[theorem]{Claim} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \newtheorem{example}[theorem]{Example} \newtheorem{remark}[theorem]{Remark} '''
[ 6738, 764, 11321, 1330, 1635, 628, 198, 37682, 1137, 796, 374, 7061, 6, 59, 1904, 26495, 90, 83, 1134, 89, 92, 198, 59, 13086, 8043, 90, 14225, 1154, 18477, 66, 1820, 74, 18477, 15, 13, 2816, 11, 16, 11, 15, 11, 15, 13, 1314, 92...
2.357401
277
# -*- coding: utf-8 -*- """ Created on Thu Apr 15 11:31:06 2021 @author: a77510jm """
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 26223, 2758, 1315, 1367, 25, 3132, 25, 3312, 33448, 198, 198, 31, 9800, 25, 257, 34483, 940, 73, 76, 198, 37811, 628 ]
2.2
40
#!/usr/bin/env python # coding: utf-8 # <a id='top'></a> # # # # $\texttt{GiRaFFEfood}$: Initial data for $\texttt{GiRaFFE}$ # # ## Aligned Rotator # # $$\label{top}$$ # # This module provides another initial data option for $\texttt{GiRaFFE}$. This is a flat-spacetime test with initial data $$A_{\phi} = \frac{\mu \varpi}{r^3},$$ where $\mu = B_p R_{\rm NS} / 2$, $R_{\rm NS}$ is the neutron star radius, and $\varpi = \sqrt{x^2+y^2}$ is the cylindrical radius. We let $A_r = A_\theta = 0$. # # Additionally, the drift velocity $v^i = \Omega \textbf{e}_z \times \textbf{r} = [ijk] \Omega \textbf{e}^j_z x^k$, where $[ijk]$ is the Levi-Civita permutation symbol and $\textbf{e}^i_z = (0,0,1)$. # <a id='preliminaries'></a> # # ### Steps 0-1: Preliminaries # $$\label{preliminaries}$$ # # \[Back to [top](#top)\] # # Here, we will import the NRPy+ core modules and set the reference metric to Cartesian, set commonly used NRPy+ parameters, and set C parameters that will be set from outside the code eventually generated from these expressions. We will also set up a parameter to determine what initial data is set up, although it won't do much yet. # Step 0: Import the NRPy+ core modules and set the reference metric to Cartesian import NRPy_param_funcs as par import indexedexp as ixp import sympy as sp # SymPy: The Python computer algebra package upon which NRPy+ depends import reference_metric as rfm par.set_parval_from_str("reference_metric::CoordSystem","Cartesian") rfm.reference_metric() # Step 1a: Set commonly used parameters. thismodule = __name__ B_p_aligned_rotator,R_NS_aligned_rotator = par.Cparameters("REAL",thismodule, # B_p_aligned_rotator = the intensity of the magnetic field and # R_NS_aligned_rotator= "Neutron star" radius ["B_p_aligned_rotator","R_NS_aligned_rotator"], [1e-5, 1.0]) # The angular velocity of the "neutron star" Omega_aligned_rotator = par.Cparameters("REAL",thismodule,"Omega_aligned_rotator",1e3) # <a id='step2'></a> # # ### Step 2: Set the vectors A in Spherical coordinates # $$\label{step2}$$ # # \[Back to [top](#top)\] # # We will first build the fundamental vector $A_i$ in spherical coordinates (see [Table 3](https://arxiv.org/pdf/1704.00599.pdf)). Note that we use reference_metric.py to set $r$ and $\theta$ in terms of Cartesian coordinates; this will save us a step later when we convert to Cartesian coordinates. So, we set # \begin{align} # A_{\phi} &= \frac{\mu \varpi}{r^3}, \\ # \end{align} # with $\mu = B_p R_{\rm NS} / 2$, $R_{\rm NS}$ is the neutron star radius, and $\varpi = \sqrt{x^2+y^2}$
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 19617, 25, 3384, 69, 12, 23, 198, 198, 2, 1279, 64, 4686, 11639, 4852, 6, 12240, 64, 29, 198, 2, 198, 2, 198, 2, 1303, 39280, 5239, 926, 90, 33704, 21762, 5777, 36, 19425, 92,...
2.377946
1,188
""" requestspython https://mp.weixin.qq.com/s/jqGx-4t4ytDDnXxDkzbPqw HTTPX https://zhuanlan.zhihu.com/p/103824900 """ if __name__ == '__main__': post_url = "http://127.0.0.1:8888" post_data = {"image": 112, "name": 1} response = interface(post_url, post_data) print('status_code: ', response.status_code) # # print('url: ', response.url) # url # print('headers: ', response.headers) # # print('cookies: ', response.cookies) # cookie print('text: ', response.text) # # print('content: ', response.content) #
[ 37811, 198, 25927, 2777, 7535, 198, 5450, 1378, 3149, 13, 732, 844, 259, 13, 38227, 13, 785, 14, 82, 14, 73, 80, 38, 87, 12, 19, 83, 19, 20760, 16458, 77, 55, 87, 35, 74, 14969, 47, 80, 86, 198, 198, 40717, 55, 220, 198, 5450,...
2.259843
254
#!/usr/bin/env python # -*- coding: utf-8 -*- """ THOR detects differential peaks in multiple ChIP-seq profiles associated with two distinct biological conditions. Copyright (C) 2014-2016 Manuel Allhoff (allhoff@aices.rwth-aachen.de) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. @author: Manuel Allhoff """ # Python from __future__ import print_function import sys # Internal from .dpc_help import get_peaks, _fit_mean_var_distr, initialize, merge_output, handle_input from .tracker import Tracker from .postprocessing import _output_BED, _output_narrowPeak from ..THOR.neg_bin_rep_hmm import NegBinRepHMM, get_init_parameters, _get_pvalue_distr from ..THOR.RegionGiver import RegionGiver from ..THOR.postprocessing import filter_by_pvalue_strand_lag from .. import __version__ # External TEST = False #enable to test THOR locally def _write_info(tracker, report, **data): """Write information to tracker""" tracker.write(text=data['func_para'][0], header="Parameters for both estimated quadr. function y=max(|a|*x^2 + x + |c|, 0) (a)") tracker.write(text=data['func_para'][1], header="Parameters for both estimated quadr. function y=max(|a|*x^2 + x + |c|, 0) (c)") #tracker.write(text=data['init_mu'], header="Inital parameter estimate for HMM's Neg. Bin. Emission distribution (mu)") #tracker.write(text=data['init_alpha'], header="Inital parameter estimate for HMM's Neg. Bin. Emission distribution (alpha)") #tracker.write(text=data['m'].mu, header="Final HMM's Neg. Bin. Emission distribution (mu)") #tracker.write(text=data['m'].alpha, header="Final HMM's Neg. Bin. Emission distribution (alpha)") #tracker.write(text=data['m']._get_transmat(), header="Transmission matrix") if report: tracker.make_html() def train_HMM(region_giver, options, bamfiles, genome, chrom_sizes, dims, inputs, tracker): """Train HMM""" while True: train_regions = region_giver.get_training_regionset() exp_data = initialize(name=options.name, dims=dims, genome_path=genome, regions=train_regions, stepsize=options.stepsize, binsize=options.binsize, bamfiles=bamfiles, exts=options.exts, inputs=inputs, exts_inputs=options.exts_inputs, debug=options.debug, verbose=options.verbose, no_gc_content=options.no_gc_content, factors_inputs=options.factors_inputs, chrom_sizes=chrom_sizes, tracker=tracker, norm_regions=options.norm_regions, scaling_factors_ip=options.scaling_factors_ip, save_wig=options.save_wig, housekeeping_genes=options.housekeeping_genes, test=TEST, report=options.report, chrom_sizes_dict=region_giver.get_chrom_dict(), end=True, counter=0, output_bw=False, save_input=options.save_input, m_threshold=options.m_threshold, a_threshold=options.a_threshold, rmdup=options.rmdup) if exp_data.count_positive_signal() > len(train_regions.sequences[0]) * 0.00001: tracker.write(text=" ".join(map(lambda x: str(x), exp_data.exts)), header="Extension size (rep1, rep2, input1, input2)") tracker.write(text=map(lambda x: str(x), exp_data.scaling_factors_ip), header="Scaling factors") break func, func_para = _fit_mean_var_distr(exp_data.overall_coverage, options.name, options.debug, verbose=options.verbose, outputdir=options.outputdir, report=options.report, poisson=options.poisson) exp_data.compute_putative_region_index() print('Compute HMM\'s training set', file=sys.stderr) training_set, s0, s1, s2 = exp_data.get_training_set(TEST, exp_data, options.name, options.foldchange, options.threshold, options.size_ts, 3) init_alpha, init_mu = get_init_parameters(s0, s1, s2) m = NegBinRepHMM(alpha=init_alpha, mu=init_mu, dim_cond_1=dims[0], dim_cond_2=dims[1], func=func) training_set_obs = exp_data.get_observation(training_set) print('Train HMM', file=sys.stderr) m.fit([training_set_obs], options.hmm_free_para) distr = _get_pvalue_distr(m.mu, m.alpha, tracker) return m, exp_data, func_para, init_mu, init_alpha, distr def run_HMM(region_giver, options, bamfiles, genome, chrom_sizes, dims, inputs, tracker, exp_data, m, distr): """Run trained HMM chromosome-wise on genomic signal and call differential peaks""" output, pvalues, ratios, no_bw_files = [], [], [], [] print("Compute HMM's posterior probabilities and Viterbi path to call differential peaks", file=sys.stderr) for i, r in enumerate(region_giver): end = True if i == len(region_giver) - 1 else False print("- taking into account %s" % r.sequences[0].chrom, file=sys.stderr) exp_data = initialize(name=options.name, dims=dims, genome_path=genome, regions=r, stepsize=options.stepsize, binsize=options.binsize, bamfiles=bamfiles, exts=exp_data.exts, inputs=inputs, exts_inputs=exp_data.exts_inputs, debug=options.debug, verbose=False, no_gc_content=options.no_gc_content, factors_inputs=exp_data.factors_inputs, chrom_sizes=chrom_sizes, tracker=tracker, norm_regions=options.norm_regions, scaling_factors_ip=exp_data.scaling_factors_ip, save_wig=options.save_wig, housekeeping_genes=options.housekeeping_genes, test=TEST, report=False, chrom_sizes_dict=region_giver.get_chrom_dict(), gc_content_cov=exp_data.gc_content_cov, avg_gc_content=exp_data.avg_gc_content, gc_hist=exp_data.gc_hist, end=end, counter=i, m_threshold=options.m_threshold, a_threshold=options.a_threshold, rmdup=options.rmdup) if exp_data.no_data: continue no_bw_files.append(i) exp_data.compute_putative_region_index() if exp_data.indices_of_interest is None: continue states = m.predict(exp_data.get_observation(exp_data.indices_of_interest)) inst_ratios, inst_pvalues, inst_output = get_peaks(name=options.name, states=states, DCS=exp_data, distr=distr, merge=options.merge, exts=exp_data.exts, pcutoff=options.pcutoff, debug=options.debug, p=options.par, no_correction=options.no_correction, merge_bin=options.merge_bin, deadzones=options.deadzones) # if not inst_output: output += inst_output pvalues += inst_pvalues ratios += inst_ratios res_output, res_pvalues, res_filter_pass = filter_by_pvalue_strand_lag(ratios, options.pcutoff, pvalues, output, options.no_correction, options.name, options.singlestrand) _output_BED(options.name, res_output, res_pvalues, res_filter_pass) _output_narrowPeak(options.name, res_output, res_pvalues, res_filter_pass) merge_output(bamfiles, dims, options, no_bw_files, chrom_sizes)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 4221, 1581, 39382, 22577, 25740, 287, 3294, 609, 4061, 12, 41068, 16545, 3917, 198, 4480, 734, 7310, 10685, ...
2.143335
3,886
from http import HTTPStatus from typing import Tuple from uuid import UUID from fastapi import status, APIRouter, Response, Depends, HTTPException from command.command_handler import Status from domain.classroom.classroom_creation_command_handler import ClassroomCreated from domain.classroom.classroom_type import ClassroomSubject from domain.commands import ClassroomCreationCommand, ClassroomPatchCommand from domain.exceptions import DomainException, AggregateNotFoundException from infrastructure.command_bus_provider import CommandBusProvider from web.presentation.domain.detailed_classroom import DetailedClassroom from web.presentation.service.classroom_service import get_detailed_classroom from web.schema.classroom_response import ClassroomReadResponse, ClassroomCreatedResponse from web.schema.classroom_schemas import ClassroomCreation, ClassroomPatch router = APIRouter()
[ 6738, 2638, 1330, 14626, 19580, 198, 6738, 19720, 1330, 309, 29291, 198, 6738, 334, 27112, 1330, 471, 27586, 198, 198, 6738, 3049, 15042, 1330, 3722, 11, 3486, 4663, 39605, 11, 18261, 11, 2129, 2412, 11, 14626, 16922, 198, 198, 6738, 31...
4.036199
221
############################################################### # # This function is... INSUFFICIENT. It was developed as an # illustration of EDA lessons in the 2021 class. It's quick and # works well. # # Want a higher grade version of me? Then try pandas-profiling: # https://github.com/pandas-profiling/pandas-profiling # ############################################################### def insufficient_but_starting_eda(df,cat_vars_list=None): ''' Parameters ---------- df : DATAFRAME cat_vars_list : LIST, optional A list of strings containing variable names in the dataframe for variables where you want to see the number of unique values and the 10 most common values. Likely used for categorical values. Returns ------- None. It simply prints. Description ------- This function will print a MINIMUM amount of info about a new dataframe. You should ****look**** at all this output below and consider the data exploration and cleaning questions from https://ledatascifi.github.io/ledatascifi-2021/content/03/02e_eda_golden.html#member Also LOOK at more of the data manually. Then write up anything notable you observe. TIP: put this function in your codebook to reuse easily. PROTIP: Improve this function (better outputs, better formatting). FEATURE REQUEST: optionally print the nunique and top 10 values under the describe matrix FEATURE REQUEST: optionally print more stats (percentiles) ''' print(df.head(), '\n---') print(df.tail(), '\n---') print(df.columns, '\n---') print("The shape is: ",df.shape, '\n---') print("Info:",df.info(), '\n---') # memory usage, name, dtype, and # of non-null obs (--> # of missing obs) per variable print(df.describe(), '\n---') # summary stats, and you can customize the list! if cat_vars_list != None: for var in cat_vars_list: print(var,"has",df[var].nunique(),"values and its top 10 most common are:") print(df[var].value_counts().head(10), '\n---')
[ 29113, 14468, 7804, 4242, 21017, 198, 2, 198, 2, 770, 2163, 318, 986, 3268, 12564, 5777, 2149, 28495, 13, 632, 373, 4166, 355, 281, 220, 198, 2, 20936, 286, 412, 5631, 11658, 287, 262, 33448, 1398, 13, 632, 338, 2068, 290, 220, 198,...
2.852394
752
import logging l = logging.getLogger("angr.codenode") from .block import Block
[ 11748, 18931, 198, 75, 796, 18931, 13, 1136, 11187, 1362, 7203, 648, 81, 13, 19815, 268, 1098, 4943, 628, 628, 198, 6738, 764, 9967, 1330, 9726, 198 ]
3.074074
27
import os scrapy_project_path = '/Users/kingname/book/chapter_12/DeploySpider' os.chdir(scrapy_project_path) # os.system('scrapyd-deploy') import json import time import requests start_url = 'http://45.76.110.210:6800/schedule.json' start_data = {'project': 'DeploySpider', 'spider': 'Example'} end_url = 'http://45.76.110.210:6800/cancel.json' end_data = {'project': 'DeploySpider'} result = requests.post(start_url, data=start_data, auth=('kingname', 'genius')).text result = requests.post(end_url, data=end_data, auth=('kingname', 'genius')).text # result_dict = json.loads(result) # job_id = result_dict['jobid'] # print(f'jobid{job_id}') # # time.sleep(5) # end_data['job'] = job_id # result = requests.post(end_url, data=end_data).text # print(result)
[ 11748, 28686, 628, 198, 1416, 2416, 88, 62, 16302, 62, 6978, 796, 31051, 14490, 14, 3364, 3672, 14, 2070, 14, 43582, 62, 1065, 14, 49322, 41294, 6, 198, 418, 13, 354, 15908, 7, 1416, 2416, 88, 62, 16302, 62, 6978, 8, 1303, 198, 41...
2.521036
309
""" Simple math operating functions for unit test """ def add(a, b): """ Adding to parameters and return result :param a: :param b: :return: """ return a + b def minus(a, b): """ subtraction :param a: :param b: :return: """ return a - b def multi(a, b): """ multiple :param a: :param b: :return: """ return a * b def divide(a, b): """ division :param a: :param b: :return: """ return a // b
[ 37811, 198, 26437, 10688, 5361, 5499, 329, 4326, 1332, 198, 37811, 628, 198, 4299, 751, 7, 64, 11, 275, 2599, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 18247, 284, 10007, 290, 1441, 1255, 198, 220, 220, 220, 1058, 17143, 257, 2...
2.147059
238
from __future__ import print_function, division, absolute_import import itertools import sys # unittest only added in 3.4 self.subTest() if sys.version_info[0] < 3 or sys.version_info[1] < 4: import unittest2 as unittest else: import unittest # unittest.mock is not available in 2.7 (though unittest2 might contain it?) try: import unittest.mock as mock except ImportError: import mock import matplotlib matplotlib.use('Agg') # fix execution of tests involving matplotlib on travis import numpy as np import six.moves as sm import skimage import skimage.data import skimage.morphology import scipy import scipy.special import imgaug as ia import imgaug.random as iarandom from imgaug import parameters as iap from imgaug.testutils import reseed def test___init__(self): param = iap.Beta(0.5, 0.5) assert ( param.__str__() == param.__repr__() == "Beta(" "Deterministic(float 0.50000000), " "Deterministic(float 0.50000000)" ")" ) def test_draw_sample(self): param = iap.Beta(0.5, 0.5) sample = param.draw_sample() assert sample.shape == tuple() assert 0 - _eps(sample) < sample < 1.0 + _eps(sample) def test_draw_samples(self): param = iap.Beta(0.5, 0.5) samples = param.draw_samples((100, 1000)) assert samples.shape == (100, 1000) assert np.all( np.logical_and( 0 - _eps(samples) <= samples, samples <= 1.0 + _eps(samples) ) ) def test_via_comparison_to_np_beta(self): param = iap.Beta(0.5, 0.5) samples = param.draw_samples((100, 1000)) samples_direct = iarandom.RNG(1234).beta( a=0.5, b=0.5, size=(100, 1000)) nb_bins = 10 hist, _ = np.histogram(samples, bins=nb_bins, range=(0, 1.0), density=False) hist_direct, _ = np.histogram(samples_direct, bins=nb_bins, range=(0, 1.0), density=False) tolerance = 0.05 for nb_samples, nb_samples_direct in zip(hist, hist_direct): density = nb_samples / samples.size density_direct = nb_samples_direct / samples_direct.size assert ( density_direct - tolerance < density < density_direct + tolerance ) class TestDeterministic(unittest.TestCase): class TestFromLowerResolution(unittest.TestCase): class TestClip(unittest.TestCase): class TestDiscretize(unittest.TestCase): # TODO why are these tests applied to DiscreteUniform instead of Uniform? class TestMultiply(unittest.TestCase): class TestDivide(unittest.TestCase): class TestAdd(unittest.TestCase): class TestSubtract(unittest.TestCase): class TestPower(unittest.TestCase): class TestAbsolute(unittest.TestCase): class TestRandomSign(unittest.TestCase): class TestForceSign(unittest.TestCase): class TestPositive(unittest.TestCase): class TestNegative(unittest.TestCase): class TestIterativeNoiseAggregator(unittest.TestCase): class TestSigmoid(unittest.TestCase):
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 11, 7297, 11, 4112, 62, 11748, 198, 198, 11748, 340, 861, 10141, 198, 11748, 25064, 198, 2, 555, 715, 395, 691, 2087, 287, 513, 13, 19, 2116, 13, 7266, 14402, 3419, 198, 361, 25064, 13,...
2.248439
1,441
""" jsnek_saved_games_dataset that returns flat (vectorized) data """ from .jsnek_base_dataset import JSnekBaseDataset from .. import utils
[ 37811, 198, 8457, 710, 74, 62, 82, 9586, 62, 19966, 62, 19608, 292, 316, 326, 5860, 6228, 357, 31364, 1143, 8, 1366, 198, 37811, 198, 198, 6738, 764, 8457, 710, 74, 62, 8692, 62, 19608, 292, 316, 1330, 26755, 710, 74, 14881, 27354, ...
2.730769
52
# Generated by Django 3.2.7 on 2021-09-15 15:40 from django.db import migrations, models
[ 2, 2980, 515, 416, 37770, 513, 13, 17, 13, 22, 319, 33448, 12, 2931, 12, 1314, 1315, 25, 1821, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 628 ]
2.84375
32
import os import databases import sqlalchemy DB_CONNECTOR = os.getenv('APP_DB_CONNECTOR') DB_USERNAME = os.getenv('APP_DB_USERNAME') DB_PASSWORD = os.getenv('APP_DB_PASSWORD') DB_HOST = os.getenv('APP_DB_HOST') DB_PORT = os.getenv('APP_DB_PORT') DB_DATABASE = os.getenv('APP_DB_DATABASE') DB_URL = f'{DB_CONNECTOR}://{DB_USERNAME}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_DATABASE}' db: databases.Database = databases.Database(DB_URL) metadata: sqlalchemy.MetaData = sqlalchemy.MetaData()
[ 11748, 28686, 198, 198, 11748, 20083, 198, 11748, 44161, 282, 26599, 198, 198, 11012, 62, 10943, 48842, 1581, 796, 28686, 13, 1136, 24330, 10786, 24805, 62, 11012, 62, 10943, 48842, 1581, 11537, 198, 11012, 62, 29904, 20608, 796, 28686, 1...
2.322275
211
import os import time import argparse import torchvision import torch import torch.nn as nn from util import AverageMeter, TwoAugUnsupervisedDataset from encoder import SmallAlexNet from align_uniform import align_loss, uniform_loss import json if __name__ == '__main__': main()
[ 11748, 28686, 198, 11748, 640, 198, 11748, 1822, 29572, 198, 198, 11748, 28034, 10178, 198, 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 198, 6738, 7736, 1330, 13475, 44, 2357, 11, 4930, 12512, 3118, 16668, 16149, 27354,...
3.295455
88
from flask import Flask """ 1. Creating a flask application instance, the name argument is passed to flask application constructor. It's used to determine the root path""" app = Flask(__name__) app.config.from_object('config') from app import views, models
[ 6738, 42903, 1330, 46947, 198, 198, 37811, 352, 13, 30481, 257, 42903, 3586, 4554, 11, 262, 1438, 4578, 318, 3804, 284, 42903, 198, 31438, 23772, 13, 632, 338, 973, 284, 5004, 262, 6808, 3108, 37811, 198, 1324, 796, 46947, 7, 834, 367...
4.046875
64
# SPDX-License-Identifier: Apache-2.0 # Copyright(c) 2021 Open Networking Foundation import time from ipaddress import IPv4Address from pprint import pprint from trex_test import TrexTest from grpc_test import * from trex_stl_lib.api import ( STLVM, STLPktBuilder, STLStream, STLTXCont, ) import ptf.testutils as testutils UPF_DEST_MAC = "0c:c4:7a:19:6d:ca" # Port setup TREX_SENDER_PORT = 0 TREX_RECEIVER_PORT = 1 BESS_SENDER_PORT = 2 BESS_RECEIVER_PORT = 3 # Test specs DURATION = 10 RATE = 100_000 # 100 Kpps UE_COUNT = 10_000 # 10k UEs GTPU_PORT = 2152 PKT_SIZE = 64
[ 2, 30628, 55, 12, 34156, 12, 33234, 7483, 25, 24843, 12, 17, 13, 15, 198, 2, 15069, 7, 66, 8, 33448, 4946, 7311, 278, 5693, 198, 198, 11748, 640, 198, 6738, 20966, 21975, 1330, 25961, 19, 20231, 198, 6738, 279, 4798, 1330, 279, 47...
2.357143
252
from rest_framework import serializers from archives_app.documents_models import (FrequencyRelation, BoxArchiving, AdministrativeProcess, OriginBox, FrequencySheet, DocumentTypes)
[ 6738, 1334, 62, 30604, 1330, 11389, 11341, 198, 6738, 22415, 62, 1324, 13, 15390, 2886, 62, 27530, 1330, 357, 37, 28707, 6892, 341, 11, 8315, 19895, 1412, 11, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220...
2.083969
131
# -*- coding: utf-8 -*- ############################################################################## # Copyright (c) 2017 Science and Technology Facilities Council # # All rights reserved. # # Modifications made as part of the fparser project are distributed # under the following license: # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################################################## # Modified M.Hambley, UK Met Office ############################################################################## ''' Test battery associated with fparser.common.base_classes package. ''' import re import pytest import fparser.common.base_classes import fparser.common.readfortran import fparser.common.sourceinfo import fparser.common.utils from fparser import api def test_statement_logging(log, monkeypatch): ''' Tests the Statement class' logging methods. ''' reader = fparser.common.readfortran.FortranStringReader("dummy = 1") parser = DummyParser(reader) monkeypatch.setattr(fparser.common.base_classes.Statement, 'process_item', lambda x: None, raising=False) unit_under_test = fparser.common.base_classes.Statement(parser, None) unit_under_test.error('Scary biscuits') assert(log.messages == {'critical': [], 'debug': [], 'error': ['Scary biscuits'], 'info': [], 'warning': []}) log.reset() unit_under_test.warning('Trepidacious Cetations') assert(log.messages == {'critical': [], 'debug': [], 'error': [], 'info': [], 'warning': ['Trepidacious Cetations']}) log.reset() unit_under_test.info('Hilarious Ontologies') assert(log.messages == {'critical': [], 'debug': [], 'error': [], 'info': ['Hilarious Ontologies'], 'warning': []}) def test_log_comment_mix(log): ''' Tests that unexpected Fortran 90 comment in fixed format source is logged. ''' code = ' x=1 ! Cheese' parent = fparser.common.readfortran.FortranStringReader( code, ignore_comments=False) parent.set_format(fparser.common.sourceinfo.FortranFormat(False, True)) item = fparser.common.readfortran.Line(code, (1, 1), None, None, parent) with pytest.raises(fparser.common.utils.AnalyzeError): __ = BeginHarness(parent, item) expected = ' 1: x=1 ! Cheese <== ' \ + 'no parse pattern found for "x=1 ! cheese" ' \ + "in 'BeginHarness' block, " \ + 'trying to remove inline comment (not in Fortran 77).' result = log.messages['warning'][0].split('\n')[1] assert result == expected def test_log_unexpected(log): ''' Tests that an unexpected thing between begin and end statements logs an event. ''' code = [' jumper', ' end thing'] parent = fparser.common.readfortran.FortranStringReader('\n'.join(code)) parent.set_format(fparser.common.sourceinfo.FortranFormat(False, True)) item = fparser.common.readfortran.Line(code[0], (1, 1), None, None, parent) with pytest.raises(fparser.common.utils.AnalyzeError): __ = BeginThing(parent, item) expected = ' 1: jumper <== no parse pattern found for "jumper" ' \ "in 'BeginThing' block." result = log.messages['warning'][0].split('\n')[1] assert result == expected def test_space_after_enddo(): '''Make sure that there is no space after an 'END DO' without name, but there is a space if there is a name after 'END DO'. ''' # Unnamed loop: source_str = '''\ subroutine foo integer i, r do i = 1,100 r = r + 1 end do end subroutine foo ''' tree = api.parse(source_str, isfree=True, isstrict=False) assert "END DO " not in tree.tofortran() # Named loop: source_str = '''\ subroutine foo integer i, r loop1: do i = 1,100 r = r + 1 end do loop1 end subroutine foo ''' tree = api.parse(source_str, isfree=True, isstrict=False) assert "END DO loop1" in tree.tofortran()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 29113, 29113, 7804, 4242, 2235, 198, 2, 15069, 357, 66, 8, 2177, 5800, 290, 8987, 48939, 4281, 198, 2, 198, 2, 1439, 2489, 10395, 13, 198, 2, 198, 2, 3401, 6637, 925...
2.619865
2,215
from elsa import cli from pyvecorg import app cli(app, base_url='http://pyvec.org')
[ 6738, 1288, 11400, 1330, 537, 72, 198, 198, 6738, 12972, 35138, 2398, 1330, 598, 628, 198, 44506, 7, 1324, 11, 2779, 62, 6371, 11639, 4023, 1378, 9078, 35138, 13, 2398, 11537, 198 ]
2.71875
32
import curtsies.events as ev import sys DELIMITERS = ' .' WHITESPACE = ' ' def print_console(txt, npadding=0, newline=False, flush=True): """ Prints txt without newline, cursor positioned at the end. :param txt: The text to print :param length: The txt will be padded with spaces to fit this length :param newline: If True, a newline character will be appended :return: """ sys.stdout.write('\r{0}{1}'.format(txt, WHITESPACE * npadding)) if newline: sys.stdout.write('\n') if flush: sys.stdout.flush() def find_next_in_list(lst, what, start=0, reverse=False): """ Finds the next occurrence of what in lst starting at start. :param lst: The list to search :param what: The item to find, should be an iterable :param start: The starting position in the list :param reverse: Set this to True in order to traverse the list towards 0 :return: False if no occurrence found, index otherwise """ if start < 0 or start >= len(lst): return False end = -1 if reverse else len(lst) step = -1 if reverse else 1 for i in range(start, end, step): if lst[i] in what: return i return False
[ 11748, 1090, 912, 444, 13, 31534, 355, 819, 198, 11748, 25064, 198, 198, 35, 3698, 3955, 2043, 4877, 796, 705, 764, 6, 198, 12418, 2043, 1546, 47, 11598, 796, 705, 705, 628, 198, 4299, 3601, 62, 41947, 7, 14116, 11, 299, 39231, 28, ...
2.632829
463
from django.core.exceptions import ValidationError from django.utils import timezone from django.test import TestCase from events.models import Event, Invitee from users.tests.factories import UserFactory from users.models import get_sentinel_user
[ 6738, 42625, 14208, 13, 7295, 13, 1069, 11755, 1330, 3254, 24765, 12331, 198, 6738, 42625, 14208, 13, 26791, 1330, 640, 11340, 198, 6738, 42625, 14208, 13, 9288, 1330, 6208, 20448, 198, 6738, 2995, 13, 27530, 1330, 8558, 11, 10001, 578, ...
3.830769
65
cryptolist = ['ETH','BTC','XRP','EOS','ADA','NEO','STEEM', 'BTS','ZEC','XMR','XVG','XEM','OMG','MIOTA','XTZ','SC', 'CVC','BAT','XLM','ZRX','VEN']
[ 29609, 349, 396, 796, 37250, 20702, 41707, 35964, 41707, 55, 20031, 41707, 36, 2640, 41707, 26853, 41707, 45, 4720, 41707, 30516, 3620, 3256, 198, 6, 33, 4694, 41707, 57, 2943, 41707, 55, 13599, 41707, 55, 43490, 41707, 55, 3620, 41707, ...
2.164179
67
# Copyright (c) 2017 Sony 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. import os import pytest import numpy as np from nnabla.utils.data_source_loader import load_image from nnabla.utils.data_iterator import data_iterator_simple from .test_data_iterator import check_data_iterator_result
[ 2, 15069, 357, 66, 8, 2177, 10184, 10501, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351...
3.696429
224
# n # # b < c(c, d)(a, b) # # # # : # # : [[1,2], [2,3], [3,4]] # : 2 # : [1,2] -> [3,4] # # # [1, 1000] # # LeetCode # https://leetcode-cn.com/problems/maximum-length-of-pair-chain # from typing import List if __name__ == '__main__': s = Solution() assert s.findLongestChain([[1, 2], [2, 3], [3, 4]]) == 2
[ 2, 299, 198, 2, 198, 2, 275, 1279, 269, 7, 66, 11, 288, 5769, 64, 11, 275, 8, 198, 2, 198, 2, 220, 198, 2, 198, 2, 220, 1058, 198, 2, 198, 2, 1058, 16410, 16, 11, 17, 4357, 685, 17, 11, 18, 4357, 685, 18, 11, 19, 11907, ...
1.888889
171
from FactorTest.FactorTestPara import * from FactorTest.FactorTestBox import *
[ 6738, 27929, 14402, 13, 41384, 14402, 47, 3301, 1330, 1635, 201, 198, 6738, 27929, 14402, 13, 41384, 14402, 14253, 1330, 1635, 201, 198, 201, 198, 220, 220, 220, 220, 201, 198, 201, 198, 201, 198 ]
2.657143
35
from __future__ import division from qm.qm_calculator import QM_calculator from misc import call_name import os
[ 6738, 11593, 37443, 834, 1330, 7297, 198, 6738, 10662, 76, 13, 80, 76, 62, 9948, 3129, 1352, 1330, 1195, 44, 62, 9948, 3129, 1352, 198, 6738, 12747, 1330, 869, 62, 3672, 198, 11748, 28686, 628, 198 ]
3.166667
36
# -*- coding: utf-8 -*- ''' :synopsis: Unit Tests for Windows Registry Module 'module.reg' :platform: Windows :maturity: develop :codeauthor: Damon Atkins <https://github.com/damon-atkins> versionadded:: 2016.11.0 ''' # Import Python future libs from __future__ import absolute_import from __future__ import unicode_literals # Import Python Libs import sys import time # Import Salt Testing Libs from tests.support.unit import TestCase, skipIf from tests.support.helpers import destructiveTest # Import Salt Libs import salt.modules.reg as win_mod_reg from salt.ext import six try: from salt.ext.six.moves import winreg as _winreg # pylint: disable=import-error,no-name-in-module NO_WINDOWS_MODULES = False except ImportError: NO_WINDOWS_MODULES = True PY2 = sys.version_info[0] == 2 # The following used to make sure we are not # testing already existing data # Note strftime retunrns a str, so we need to make it unicode TIMEINT = int(time.time()) if PY2: TIME_INT_UNICODE = six.text_type(TIMEINT) TIMESTR = time.strftime('%X %x %Z').decode('utf-8') else: TIMESTR = time.strftime('%X %x %Z') TIME_INT_UNICODE = str(TIMEINT) # pylint: disable=R0204 # we do not need to prefix this with u, as we are # using from __future__ import unicode_literals UNICODETEST_WITH_SIGNS = 'Testing Unicode \N{COPYRIGHT SIGN},\N{TRADE MARK SIGN},\N{REGISTERED SIGN} '+TIMESTR UNICODETEST_WITHOUT_SIGNS = 'Testing Unicode'+TIMESTR UNICODE_TEST_KEY = 'UnicodeKey \N{TRADE MARK SIGN} '+TIME_INT_UNICODE UNICODE_TEST_KEY_DEL = 'Delete Me \N{TRADE MARK SIGN} '+TIME_INT_UNICODE
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 7061, 6, 198, 220, 220, 220, 1058, 28869, 24608, 25, 11801, 30307, 329, 3964, 33432, 19937, 705, 21412, 13, 2301, 6, 198, 220, 220, 220, 1058, 24254, 25, 3964, 198, 22...
2.707563
595
import traceback import re import sys import logging """ ********** Note by wvmarle: This file contains the complete code from chained_exception.py plus the error handling code from GlacierWrapper.py, allowing it to be used in other modules like glaciercorecalls as well. ********** """ if __name__ == '__main__': try: try: raise ChildrenException("parent") except ChildrenException, e: raise ParentException("children", cause=e) except ParentException, e: e.write(indentation='|| ')
[ 11748, 12854, 1891, 198, 11748, 302, 198, 11748, 25064, 198, 11748, 18931, 198, 198, 37811, 198, 198, 4557, 1174, 198, 6425, 416, 266, 85, 3876, 293, 25, 198, 198, 1212, 2393, 4909, 262, 1844, 2438, 422, 40682, 62, 1069, 4516, 13, 907...
2.863874
191
# Copyright 2022 @ReneFreingruber # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This mode can be started by passing the "--import_corpus_mode" flag to the fuzzer # or by starting the fuzzer the first time (when no OUTPUT directory exists yet). # # The script imports new testcases into the current corpus. # Please note that the progress of the script is not linear (especially when creating an initial corpus). # The script will start slow (because it will find a lot of testcases with new behavior and this requires # standardization, minimization & state creation. # These operations are slow because they require to restart the JS engine multiple times, # and therefore it will take a longer time. After some time, the import-mode will be faster because it finds less files # with new coverage. At the end, the mode will again be slow (or maybe very slow) because it's processing the # bigger testcases (testcases are sorted based on file size and handled from small files to big files). # State creation for big input files is extremely slow. # It's maybe better to skip these big testcases and continue because later testcases can maybe further be # minimized (which would then be again fast). => I created my initial corpus with a different script, # skipping the big testcases is therefore not implemented here yet (and must manually be done). # TODO: In my original code I also removed v8 native functions because they quickly lead to crashes # But I couldn't find the code anymore. I guess this should be implemented in this file somewhere at the end? # This affect at least the functions: # %ProfileCreateSnapshotDataBlob # %LiveEditPatchScript # %IsWasmCode # %IsAsmWasmCode # %ConstructConsString # %HaveSameMap # %IsJSReceiver # %HasSmiElements # %HasObjectElements # %HasDoubleElements # %HasDictionaryElements # %HasHoleyElements # %HasSloppyArgumentsElements # %HaveSameMap # %HasFastProperties # %HasPackedElements # # More information can be found in my master thesis page 115. import utils import os import config as cfg import native_code.speed_optimized_functions as speed_optimized_functions from native_code.executor import Execution_Status import sys import random import string import re code_prefix = "function my_opt_func() {\n" code_suffix1 = """ } %OptimizeFunctionOnNextCall(my_opt_func); my_opt_func(); """ code_suffix2 = """ } %PrepareFunctionForOptimization(my_opt_func); %OptimizeFunctionOnNextCall(my_opt_func); my_opt_func(); """ code_suffix3 = """ } my_opt_func(); %PrepareFunctionForOptimization(my_opt_func); %OptimizeFunctionOnNextCall(my_opt_func); my_opt_func(); """ # These are just used for debugging debugging_number_exceptions = 0 debugging_number_success = 0 debugging_number_new_coverage = 0 # This is a debug version of the above one. # The above one does all the required calculations (standardization, minimization, state creation) # which is very slow. But If I just want to quickly check how many files I can import, # then I'm using this debugging versions (which skips all these steps) # This version does also not restart the exec engine. # To use it, just replace the call with this function # TODO: This is pretty old code and needs a lot of refactoring/improvement ... # TODO: Also better implement these whole "\t" and " " and "\" checking... # One testcase file can contain multiple testcases # That's why this function returns a list of samples
[ 2, 15069, 33160, 2488, 49, 1734, 20366, 278, 622, 527, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, ...
3.71807
1,057
#!/usr/bin/env python """ Simple occupancy-grid-based mapping without localization. Subscribed topics: /scan Published topics: /map /map_metadata Author: Nathan Sprague Version: 2/13/14 """ import rospy from nav_msgs.msg import OccupancyGrid, MapMetaData from geometry_msgs.msg import Pose, Point, Quaternion from sensor_msgs.msg import LaserScan import numpy as np if __name__ == '__main__': try: m = Mapper() except rospy.ROSInterruptException: pass
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 37811, 17427, 42498, 12, 25928, 12, 3106, 16855, 1231, 42842, 13, 220, 198, 198, 7004, 47495, 10233, 25, 198, 14, 35836, 198, 198, 24492, 10233, 25, 198, 14, 8899, 220, 198, 14, ...
2.803468
173
""" flags.py . should be renamed helpers... . This file is scheduled for deletion """ """ valid accessory tags: "any_tag": {"code": "code_insert_as_string"} # execute arbitrary code to construct this key. "dialect": csv.excel_tab # dialect of the file, default = csv, set this to use tsv. or sniffer "skip_lines": number # number of lines to skip at the head of the file. "skiptill": skip until I see the first instance of <str> """ # lists of format-specifiers.
[ 37811, 198, 33152, 13, 9078, 198, 198, 13, 815, 307, 25121, 49385, 986, 198, 13, 770, 2393, 318, 7530, 329, 39948, 198, 37811, 198, 198, 37811, 198, 12102, 28207, 15940, 25, 198, 198, 1, 1092, 62, 12985, 1298, 19779, 8189, 1298, 366, ...
3.27972
143
import os import tornado.ioloop import tornado.web from jet_bridge.handlers.temporary_redirect import TemporaryRedirectHandler from jet_bridge_base import settings as base_settings from jet_bridge_base.views.api import ApiView from jet_bridge_base.views.image_resize import ImageResizeView from jet_bridge_base.views.file_upload import FileUploadView from jet_bridge_base.views.message import MessageView from jet_bridge_base.views.model import ModelViewSet from jet_bridge_base.views.model_description import ModelDescriptionView from jet_bridge_base.views.register import RegisterView from jet_bridge_base.views.reload import ReloadView from jet_bridge_base.views.sql import SqlView from jet_bridge import settings, media from jet_bridge.handlers.view import view_handler from jet_bridge.handlers.not_found import NotFoundHandler from jet_bridge.router import Router
[ 11748, 28686, 198, 198, 11748, 33718, 13, 1669, 11224, 198, 11748, 33718, 13, 12384, 198, 198, 6738, 12644, 62, 9458, 13, 4993, 8116, 13, 11498, 5551, 62, 445, 1060, 1330, 46042, 7738, 1060, 25060, 198, 6738, 12644, 62, 9458, 62, 8692, ...
3.65272
239
import requests from ...shared.exceptions import MediaServiceException from ...shared.interfaces.logging import LoggingModule from .interface import MediaService
[ 11748, 7007, 198, 198, 6738, 2644, 28710, 13, 1069, 11755, 1330, 6343, 16177, 16922, 198, 6738, 2644, 28710, 13, 3849, 32186, 13, 6404, 2667, 1330, 5972, 2667, 26796, 198, 6738, 764, 39994, 1330, 6343, 16177, 628 ]
4.555556
36
import async from async.services import EchoUpperData server = async.server('10.211.55.3', 20007) async.register(transport=server, protocol=EchoUpperData) async.run()
[ 11748, 30351, 198, 6738, 30351, 13, 30416, 1330, 21455, 52, 2848, 6601, 198, 198, 15388, 796, 30351, 13, 15388, 10786, 940, 13, 21895, 13, 2816, 13, 18, 3256, 4751, 22, 8, 198, 292, 13361, 13, 30238, 7, 7645, 634, 28, 15388, 11, 843...
2.964912
57
from ..alert_code import AlertCode
[ 6738, 11485, 44598, 62, 8189, 1330, 23276, 10669, 628 ]
4
9
from blaze import compute, resource, symbol, discover from blaze.utils import example flag = [False]
[ 6738, 31259, 1330, 24061, 11, 8271, 11, 6194, 11, 7073, 198, 6738, 31259, 13, 26791, 1330, 1672, 628, 198, 32109, 796, 685, 25101, 60, 628 ]
4.16
25
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ mwtab.mwschema ~~~~~~~~~~~~~~ This module provides schema definitions for different sections of the ``mwTab`` Metabolomics Workbench format. """ import sys from schema import Schema, Optional, Or if sys.version_info.major == 2: str = unicode metabolomics_workbench_schema = Schema( { "VERSION": str, "CREATED_ON": str, Optional("STUDY_ID"): str, Optional("ANALYSIS_ID"): str, Optional("PROJECT_ID"): str, Optional("HEADER"): str, Optional("DATATRACK_ID"): str } ) project_schema = Schema( { "PROJECT_TITLE": str, Optional("PROJECT_TYPE"): str, "PROJECT_SUMMARY": str, "INSTITUTE": str, Optional("DEPARTMENT"): str, Optional("LABORATORY"): str, "LAST_NAME": str, "FIRST_NAME": str, "ADDRESS": str, "EMAIL": str, "PHONE": str, Optional("FUNDING_SOURCE"): str, Optional("PROJECT_COMMENTS"): str, Optional("PUBLICATIONS"): str, Optional("CONTRIBUTORS"): str, Optional("DOI"): str } ) study_schema = Schema( { "STUDY_TITLE": str, Optional("STUDY_TYPE"): str, "STUDY_SUMMARY": str, "INSTITUTE": str, Optional("DEPARTMENT"): str, Optional("LABORATORY"): str, "LAST_NAME": str, "FIRST_NAME": str, "ADDRESS": str, "EMAIL": str, "PHONE": str, Optional("NUM_GROUPS"): str, Optional("TOTAL_SUBJECTS"): str, Optional("NUM_MALES"): str, Optional("NUM_FEMALES"): str, Optional("STUDY_COMMENTS"): str, Optional("PUBLICATIONS"): str, # assumed Optional("SUBMIT_DATE"): str # assumed } ) subject_schema = Schema( { "SUBJECT_TYPE": str, "SUBJECT_SPECIES": str, Optional("TAXONOMY_ID"): str, Optional("GENOTYPE_STRAIN"): str, Optional("AGE_OR_AGE_RANGE"): str, Optional("WEIGHT_OR_WEIGHT_RANGE"): str, Optional("HEIGHT_OR_HEIGHT_RANGE"): str, Optional("GENDER"): str, Optional("HUMAN_RACE"): str, Optional("HUMAN_ETHNICITY"): str, Optional("HUMAN_TRIAL_TYPE"): str, Optional("HUMAN_LIFESTYLE_FACTORS"): str, Optional("HUMAN_MEDICATIONS"): str, Optional("HUMAN_PRESCRIPTION_OTC"): str, Optional("HUMAN_SMOKING_STATUS"): str, Optional("HUMAN_ALCOHOL_DRUG_USE"): str, Optional("HUMAN_NUTRITION"): str, Optional("HUMAN_INCLUSION_CRITERIA"): str, Optional("HUMAN_EXCLUSION_CRITERIA"): str, Optional("ANIMAL_ANIMAL_SUPPLIER"): str, Optional("ANIMAL_HOUSING"): str, Optional("ANIMAL_LIGHT_CYCLE"): str, Optional("ANIMAL_FEED"): str, Optional("ANIMAL_WATER"): str, Optional("ANIMAL_INCLUSION_CRITERIA"): str, Optional("CELL_BIOSOURCE_OR_SUPPLIER"): str, Optional("CELL_STRAIN_DETAILS"): str, Optional("SUBJECT_COMMENTS"): str, Optional("CELL_PRIMARY_IMMORTALIZED"): str, Optional("CELL_PASSAGE_NUMBER"): str, Optional("CELL_COUNTS"): str, Optional("SPECIES_GROUP"): str } ) subject_sample_factors_schema = Schema( [ { "Subject ID": str, "Sample ID": str, "Factors": dict, Optional("Additional sample data"): { Optional("RAW_FILE_NAME"): str, Optional(str): str } } ] ) collection_schema = Schema( { "COLLECTION_SUMMARY": str, Optional("COLLECTION_PROTOCOL_ID"): str, Optional("COLLECTION_PROTOCOL_FILENAME"): str, Optional("COLLECTION_PROTOCOL_COMMENTS"): str, Optional("SAMPLE_TYPE"): str, # assumed optional due to large number of files without Optional("COLLECTION_METHOD"): str, Optional("COLLECTION_LOCATION"): str, Optional("COLLECTION_FREQUENCY"): str, Optional("COLLECTION_DURATION"): str, Optional("COLLECTION_TIME"): str, Optional("VOLUMEORAMOUNT_COLLECTED"): str, Optional("STORAGE_CONDITIONS"): str, Optional("COLLECTION_VIALS"): str, Optional("STORAGE_VIALS"): str, Optional("COLLECTION_TUBE_TEMP"): str, Optional("ADDITIVES"): str, Optional("BLOOD_SERUM_OR_PLASMA"): str, Optional("TISSUE_CELL_IDENTIFICATION"): str, Optional("TISSUE_CELL_QUANTITY_TAKEN"): str } ) treatment_schema = Schema( { "TREATMENT_SUMMARY": str, Optional("TREATMENT_PROTOCOL_ID"): str, Optional("TREATMENT_PROTOCOL_FILENAME"): str, Optional("TREATMENT_PROTOCOL_COMMENTS"): str, Optional("TREATMENT"): str, Optional("TREATMENT_COMPOUND"): str, Optional("TREATMENT_ROUTE"): str, Optional("TREATMENT_DOSE"): str, Optional("TREATMENT_DOSEVOLUME"): str, Optional("TREATMENT_DOSEDURATION"): str, Optional("TREATMENT_VEHICLE"): str, Optional("ANIMAL_VET_TREATMENTS"): str, Optional("ANIMAL_ANESTHESIA"): str, Optional("ANIMAL_ACCLIMATION_DURATION"): str, Optional("ANIMAL_FASTING"): str, Optional("ANIMAL_ENDP_EUTHANASIA"): str, Optional("ANIMAL_ENDP_TISSUE_COLL_LIST"): str, Optional("ANIMAL_ENDP_TISSUE_PROC_METHOD"): str, Optional("ANIMAL_ENDP_CLINICAL_SIGNS"): str, Optional("HUMAN_FASTING"): str, Optional("HUMAN_ENDP_CLINICAL_SIGNS"): str, Optional("CELL_STORAGE"): str, Optional("CELL_GROWTH_CONTAINER"): str, Optional("CELL_GROWTH_CONFIG"): str, Optional("CELL_GROWTH_RATE"): str, Optional("CELL_INOC_PROC"): str, Optional("CELL_MEDIA"): str, Optional("CELL_ENVIR_COND"): str, Optional("CELL_HARVESTING"): str, Optional("PLANT_GROWTH_SUPPORT"): str, Optional("PLANT_GROWTH_LOCATION"): str, Optional("PLANT_PLOT_DESIGN"): str, Optional("PLANT_LIGHT_PERIOD"): str, Optional("PLANT_HUMIDITY"): str, Optional("PLANT_TEMP"): str, Optional("PLANT_WATERING_REGIME"): str, Optional("PLANT_NUTRITIONAL_REGIME"): str, Optional("PLANT_ESTAB_DATE"): str, Optional("PLANT_HARVEST_DATE"): str, Optional("PLANT_GROWTH_STAGE"): str, Optional("PLANT_METAB_QUENCH_METHOD"): str, Optional("PLANT_HARVEST_METHOD"): str, Optional("PLANT_STORAGE"): str, Optional("CELL_PCT_CONFLUENCE"): str, Optional("CELL_MEDIA_LASTCHANGED"): str } ) sampleprep_schema = Schema( { "SAMPLEPREP_SUMMARY": str, Optional("SAMPLEPREP_PROTOCOL_ID"): str, Optional("SAMPLEPREP_PROTOCOL_FILENAME"): str, Optional("SAMPLEPREP_PROTOCOL_COMMENTS"): str, Optional("PROCESSING_METHOD"): str, Optional("PROCESSING_STORAGE_CONDITIONS"): str, Optional("EXTRACTION_METHOD"): str, Optional("EXTRACT_CONCENTRATION_DILUTION"): str, Optional("EXTRACT_ENRICHMENT"): str, Optional("EXTRACT_CLEANUP"): str, Optional("EXTRACT_STORAGE"): str, Optional("SAMPLE_RESUSPENSION"): str, Optional("SAMPLE_DERIVATIZATION"): str, Optional("SAMPLE_SPIKING"): str, Optional("ORGAN"): str, Optional("ORGAN_SPECIFICATION"): str, Optional("CELL_TYPE"): str, Optional("SUBCELLULAR_LOCATION"): str } ) chromatography_schema = Schema( { Optional("CHROMATOGRAPHY_SUMMARY"): str, "CHROMATOGRAPHY_TYPE": str, "INSTRUMENT_NAME": str, "COLUMN_NAME": str, Optional("FLOW_GRADIENT"): str, Optional("FLOW_RATE"): str, Optional("COLUMN_TEMPERATURE"): str, Optional("METHODS_FILENAME"): str, Optional("SOLVENT_A"): str, Optional("SOLVENT_B"): str, Optional("METHODS_ID"): str, Optional("COLUMN_PRESSURE"): str, Optional("INJECTION_TEMPERATURE"): str, Optional("INTERNAL_STANDARD"): str, Optional("INTERNAL_STANDARD_MT"): str, Optional("RETENTION_INDEX"): str, Optional("RETENTION_TIME"): str, Optional("SAMPLE_INJECTION"): str, Optional("SAMPLING_CONE"): str, Optional("ANALYTICAL_TIME"): str, Optional("CAPILLARY_VOLTAGE"): str, Optional("MIGRATION_TIME"): str, Optional("OVEN_TEMPERATURE"): str, Optional("PRECONDITIONING"): str, Optional("RUNNING_BUFFER"): str, Optional("RUNNING_VOLTAGE"): str, Optional("SHEATH_LIQUID"): str, Optional("TIME_PROGRAM"): str, Optional("TRANSFERLINE_TEMPERATURE"): str, Optional("WASHING_BUFFER"): str, Optional("WEAK_WASH_SOLVENT_NAME"): str, Optional("WEAK_WASH_VOLUME"): str, Optional("STRONG_WASH_SOLVENT_NAME"): str, Optional("STRONG_WASH_VOLUME"): str, Optional("TARGET_SAMPLE_TEMPERATURE"): str, Optional("SAMPLE_LOOP_SIZE"): str, Optional("SAMPLE_SYRINGE_SIZE"): str, Optional("RANDOMIZATION_ORDER"): str, Optional("CHROMATOGRAPHY_COMMENTS"): str } ) analysis_schema = Schema( { "ANALYSIS_TYPE": str, Optional("LABORATORY_NAME"): str, Optional("OPERATOR_NAME"): str, Optional("DETECTOR_TYPE"): str, Optional("SOFTWARE_VERSION"): str, Optional("ACQUISITION_DATE"): str, Optional("ANALYSIS_PROTOCOL_FILE"): str, Optional("ACQUISITION_PARAMETERS_FILE"): str, Optional("PROCESSING_PARAMETERS_FILE"): str, Optional("DATA_FORMAT"): str, # not specified in mwTab specification (assumed) Optional("ACQUISITION_ID"): str, Optional("ACQUISITION_TIME"): str, Optional("ANALYSIS_COMMENTS"): str, Optional("ANALYSIS_DISPLAY"): str, Optional("INSTRUMENT_NAME"): str, Optional("INSTRUMENT_PARAMETERS_FILE"): str, Optional("NUM_FACTORS"): str, Optional("NUM_METABOLITES"): str, Optional("PROCESSED_FILE"): str, Optional("RANDOMIZATION_ORDER"): str, Optional("RAW_FILE"): str, } ) ms_schema = Schema( { "INSTRUMENT_NAME": str, "INSTRUMENT_TYPE": str, "MS_TYPE": str, "ION_MODE": str, "MS_COMMENTS": str, # changed to required Optional("CAPILLARY_TEMPERATURE"): str, Optional("CAPILLARY_VOLTAGE"): str, Optional("COLLISION_ENERGY"): str, Optional("COLLISION_GAS"): str, Optional("DRY_GAS_FLOW"): str, Optional("DRY_GAS_TEMP"): str, Optional("FRAGMENT_VOLTAGE"): str, Optional("FRAGMENTATION_METHOD"): str, Optional("GAS_PRESSURE"): str, Optional("HELIUM_FLOW"): str, Optional("ION_SOURCE_TEMPERATURE"): str, Optional("ION_SPRAY_VOLTAGE"): str, Optional("IONIZATION"): str, Optional("IONIZATION_ENERGY"): str, Optional("IONIZATION_POTENTIAL"): str, Optional("MASS_ACCURACY"): str, Optional("PRECURSOR_TYPE"): str, Optional("REAGENT_GAS"): str, Optional("SOURCE_TEMPERATURE"): str, Optional("SPRAY_VOLTAGE"): str, Optional("ACTIVATION_PARAMETER"): str, Optional("ACTIVATION_TIME"): str, Optional("ATOM_GUN_CURRENT"): str, Optional("AUTOMATIC_GAIN_CONTROL"): str, Optional("BOMBARDMENT"): str, Optional("CDL_SIDE_OCTOPOLES_BIAS_VOLTAGE"): str, Optional("CDL_TEMPERATURE"): str, Optional("DATAFORMAT"): str, Optional("DESOLVATION_GAS_FLOW"): str, Optional("DESOLVATION_TEMPERATURE"): str, Optional("INTERFACE_VOLTAGE"): str, Optional("IT_SIDE_OCTOPOLES_BIAS_VOLTAGE"): str, Optional("LASER"): str, Optional("MATRIX"): str, Optional("NEBULIZER"): str, Optional("OCTPOLE_VOLTAGE"): str, Optional("PROBE_TIP"): str, Optional("RESOLUTION_SETTING"): str, Optional("SAMPLE_DRIPPING"): str, Optional("SCAN_RANGE_MOVERZ"): str, Optional("SCANNING"): str, Optional("SCANNING_CYCLE"): str, Optional("SCANNING_RANGE"): str, Optional("SKIMMER_VOLTAGE"): str, Optional("TUBE_LENS_VOLTAGE"): str, Optional("MS_RESULTS_FILE"): Or(str, dict) } ) nmr_schema = Schema( { "INSTRUMENT_NAME": str, "INSTRUMENT_TYPE": str, "NMR_EXPERIMENT_TYPE": str, Optional("NMR_COMMENTS"): str, Optional("FIELD_FREQUENCY_LOCK"): str, Optional("STANDARD_CONCENTRATION"): str, "SPECTROMETER_FREQUENCY": str, Optional("NMR_PROBE"): str, Optional("NMR_SOLVENT"): str, Optional("NMR_TUBE_SIZE"): str, Optional("SHIMMING_METHOD"): str, Optional("PULSE_SEQUENCE"): str, Optional("WATER_SUPPRESSION"): str, Optional("PULSE_WIDTH"): str, Optional("POWER_LEVEL"): str, Optional("RECEIVER_GAIN"): str, Optional("OFFSET_FREQUENCY"): str, Optional("PRESATURATION_POWER_LEVEL"): str, Optional("CHEMICAL_SHIFT_REF_CPD"): str, Optional("TEMPERATURE"): str, Optional("NUMBER_OF_SCANS"): str, Optional("DUMMY_SCANS"): str, Optional("ACQUISITION_TIME"): str, Optional("RELAXATION_DELAY"): str, Optional("SPECTRAL_WIDTH"): str, Optional("NUM_DATA_POINTS_ACQUIRED"): str, Optional("REAL_DATA_POINTS"): str, Optional("LINE_BROADENING"): str, Optional("ZERO_FILLING"): str, Optional("APODIZATION"): str, Optional("BASELINE_CORRECTION_METHOD"): str, Optional("CHEMICAL_SHIFT_REF_STD"): str, Optional("BINNED_INCREMENT"): str, Optional("BINNED_DATA_NORMALIZATION_METHOD"): str, Optional("BINNED_DATA_PROTOCOL_FILE"): str, Optional("BINNED_DATA_CHEMICAL_SHIFT_RANGE"): str, Optional("BINNED_DATA_EXCLUDED_RANGE"): str } ) data_schema = Schema( [ { Or("Metabolite", "Bin range(ppm)", only_one=True): str, Optional(str): str, }, ] ) extended_schema = Schema( [ { "Metabolite": str, Optional(str): str, "sample_id": str }, ] ) ms_metabolite_data_schema = Schema( { "Units": str, "Data": data_schema, "Metabolites": data_schema, Optional("Extended"): extended_schema } ) nmr_binned_data_schema = Schema( { "Units": str, "Data": data_schema } ) section_schema_mapping = { "METABOLOMICS WORKBENCH": metabolomics_workbench_schema, "PROJECT": project_schema, "STUDY": study_schema, "ANALYSIS": analysis_schema, "SUBJECT": subject_schema, "SUBJECT_SAMPLE_FACTORS": subject_sample_factors_schema, "COLLECTION": collection_schema, "TREATMENT": treatment_schema, "SAMPLEPREP": sampleprep_schema, "CHROMATOGRAPHY": chromatography_schema, "MS": ms_schema, "NM": nmr_schema, "MS_METABOLITE_DATA": ms_metabolite_data_schema, "NMR_METABOLITE_DATA": ms_metabolite_data_schema, "NMR_BINNED_DATA": nmr_binned_data_schema, }
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 37811, 198, 76, 86, 8658, 13, 76, 86, 15952, 2611, 198, 15116, 8728, 4907, 198, 198, 1212, 8265, 3769, 32815...
2.001318
7,588