content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
# Copyright 2021 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 os import pathlib from appimagebuilder.utils.finder import Finder from appimagebuilder.context import AppInfo, Context, BundleInfo from appimagebuilder.commands.apt_deploy import AptDeployCommand from appimagebuilder.commands.create_appimage import CreateAppImageCommand from appimagebuilder.commands.file_deploy import FileDeployCommand from appimagebuilder.commands.pacman_deploy import PacmanDeployCommand from appimagebuilder.commands.run_script import RunScriptCommand from appimagebuilder.commands.run_test import RunTestCommand from appimagebuilder.commands.setup_app_info import SetupAppInfoCommand from appimagebuilder.commands.setup_runtime import SetupRuntimeCommand from appimagebuilder.commands.setup_symlinks import SetupSymlinksCommand from appimagebuilder.commands.deploy_record import ( WriteDeployRecordCommand, ) from appimagebuilder.recipe.roamer import Roamer
[ 2, 220, 15069, 220, 33448, 31078, 22593, 47828, 1155, 64, 198, 2, 198, 2, 220, 2448, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597, 1048, 16727, 257, 198, 2, 220, 4866, 286, 428, 3788, 290, 3917, 10314, 3696, 357, 1169, ...
4.037135
377
# python3 --> Enter Python Shell # from geocode import getGeocodeLocation # getGeocodeLocation("Place you wanto to query") import httplib2 import json # san_francisco = getGeocodeLocation("San Francisco, CA") # response header: {'content-type': 'application/json; charset=UTF-8', 'date': 'Sat, 27 Jan 2018 06:25:35 GMT', 'expires': 'Sun, 28 Jan 2018 06:25:35 GMT', 'cache-control': 'public, max-age=86400', 'vary': 'Accept-Language', 'access-control-allow-origin': '*', 'server': 'mafe', 'content-length': '1749', 'x-xss-protection': '1; mode=block', 'x-frame-options': 'SAMEORIGIN', 'alt-svc': 'hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"', 'status': '200', '-content-encoding': 'gzip', 'content-location': 'https://maps.googleapis.com/maps/api/geocode/json?address=San+Francisco,+CA&key=AIzaSyDZHGnbFkjZcOEgYPpDqlO2YhBHKsNxhnE'} # san_francisco # {'results': [{'address_components': [{'long_name': 'San Francisco', 'short_name': 'SF', 'types': ['locality', 'political']}, {'long_name': 'San Francisco County', 'short_name': 'San Francisco County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'California', 'short_name': 'CA', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'formatted_address': 'San Francisco, CA, USA', 'geometry': {'bounds': {'northeast': {'lat': 37.9298239, 'lng': -122.28178}, 'southwest': {'lat': 37.6398299, 'lng': -123.173825}}, 'location': {'lat': 37.7749295, 'lng': -122.4194155}, 'location_type': 'APPROXIMATE', 'viewport': {'northeast': {'lat': 37.812,'lng': -122.3482}, 'southwest': {'lat': 37.70339999999999, 'lng': -122.527}}}, 'place_id': 'ChIJIQBpAG2ahYAR_6128GcTUEo', 'types': ['locality', 'political']}], 'status': 'OK'} # san_francisco.keys() # dict_keys(['results', 'status']) # san_francisco['results'][0]['geometry']['location']['lat'] # 37.7749295 # san_francisco['results'][0]['geometry']['location']['lng'] # -122.4194155
[ 2, 21015, 18, 14610, 6062, 11361, 17537, 198, 2, 422, 4903, 420, 1098, 1330, 651, 10082, 420, 1098, 14749, 198, 2, 651, 10082, 420, 1098, 14749, 7203, 27271, 345, 765, 78, 284, 12405, 4943, 628, 198, 11748, 1841, 489, 571, 17, 198, ...
2.530834
827
""" The roseguarden project Copyright (C) 2018-2020 Marcus Drobisch, 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/>. """ __authors__ = ["Marcus Drobisch"] __contact__ = "roseguarden@fabba.space" __credits__ = [] __license__ = "GPLv3"
[ 37811, 198, 464, 8278, 5162, 5872, 1628, 198, 198, 15269, 357, 34, 8, 2864, 12, 42334, 220, 17068, 21045, 65, 25308, 11, 198, 198, 1212, 1430, 318, 1479, 3788, 25, 345, 460, 17678, 4163, 340, 290, 14, 273, 13096, 340, 739, 198, 1169...
3.674312
218
""" MIT License Copyright (c) 2018 Aaron Michael Scott Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import datetime import csv import os def reader(file_path='', delimiter=','): """Returns a CSVReader object """ if os.path.isfile(file_path): if os.access(file_path, os.R_OK): return CSVReader(file_path, delimiter=delimiter) else: raise Exception('{fname} exists but is not readable.'.format(fname=file_path)) else: raise Exception('{fname} does not exist'.format(fname=file_path)) def writer(file_path='', headers=[]): """Returns a CSVWriter object """ if not os.path.isfile(file_path): if isinstance(headers, list): return CSVWriter(file_path=file_path, headers=headers) else: raise Exception('Headers need to be in a list object.') else: raise Exception('{fname} is already a file. Please write to a new location.'.format(fname=file_path)) def the_date(): return datetime.date.today().strftime('%m_%d_%Y')
[ 37811, 198, 36393, 13789, 198, 198, 15269, 357, 66, 8, 2864, 12139, 3899, 4746, 198, 198, 5990, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597, 1048, 16727, 257, 4866, 198, 1659, 428, 3788, 290, 3917, 10314, 3696, 357, 1169...
3.028065
677
from PyQt4.QtGui import QImage, QPainter from PyQt4.QtCore import QSize # configure the output image width = 800 height = 600 dpi = 92 img = QImage(QSize(width, height), QImage.Format_RGB32) img.setDotsPerMeterX(dpi / 25.4 * 1000) img.setDotsPerMeterY(dpi / 25.4 * 1000) # get the map layers and extent layers = [ layer.id() for layer in iface.legendInterface().layers() ] extent = iface.mapCanvas().extent() # configure map settings for export mapSettings = QgsMapSettings() mapSettings.setMapUnits(0) mapSettings.setExtent(extent) mapSettings.setOutputDpi(dpi) mapSettings.setOutputSize(QSize(width, height)) mapSettings.setLayers(layers) mapSettings.setFlags(QgsMapSettings.Antialiasing | QgsMapSettings.UseAdvancedEffects | QgsMapSettings.ForceVectorOutput | QgsMapSettings.DrawLabeling) # configure and run painter p = QPainter() p.begin(img) mapRenderer = QgsMapRendererCustomPainterJob(mapSettings, p) mapRenderer.start() mapRenderer.waitForFinished() p.end() # save the result img.save("C:/temp/custom_export.png","png")
[ 6738, 9485, 48, 83, 19, 13, 48, 83, 8205, 72, 1330, 1195, 5159, 11, 1195, 38490, 353, 201, 198, 6738, 9485, 48, 83, 19, 13, 48, 83, 14055, 1330, 1195, 10699, 201, 198, 2, 17425, 262, 5072, 2939, 201, 198, 10394, 796, 10460, 201, ...
2.700767
391
""" Load a dataset of historic documents by specifying the folder where its located. """ import argparse # Utils import itertools import logging import math from datetime import datetime from pathlib import Path from torchvision.datasets.folder import has_file_allowed_extension, pil_loader from torchvision.transforms import functional as F from tqdm import tqdm IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm', '.gif') JPG_EXTENSIONS = ('.jpg', '.jpeg') def get_img_paths_uncropped(directory): """ Parameters ---------- directory: string parent directory with images inside Returns ------- paths: list of paths """ paths = [] directory = Path(directory).expanduser() if not directory.is_dir(): logging.error(f'Directory not found ({directory})') for subdir in sorted(directory.iterdir()): if not subdir.is_dir(): continue for img_name in sorted(subdir.iterdir()): if has_file_allowed_extension(str(img_name), IMG_EXTENSIONS): paths.append((subdir / img_name, str(subdir.stem))) return paths if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-i', '--input_path', help='Path to the root folder of the dataset (contains train/val/test)', type=Path, required=True) parser.add_argument('-o', '--output_path', help='Path to the output folder', type=Path, required=True) parser.add_argument('-tr', '--crop_size_train', help='Size of the crops in the training set', type=int, required=True) parser.add_argument('-v', '--crop_size_val', help='Size of the crops in the validation set', type=int, required=True) parser.add_argument('-te', '--crop_size_test', help='Size of the crops in the test set', type=int, required=True) parser.add_argument('-ov', '--overlap', help='Overlap of the different crops (between 0-1)', type=float, default=0.5) parser.add_argument('-l', '--leading_zeros_length', help='amount of leading zeros to encode the coordinates', type=int, default=4) parser.add_argument('-oe', '--override_existing', help='If true overrides the images ', type=bool, default=False) args = parser.parse_args() dataset_generator = CroppedDatasetGenerator(**args.__dict__) dataset_generator.write_crops() # example call arguments # -i # /Users/voegtlil/Documents/04_Datasets/003-DataSet/CB55-10-segmentation # -o # /Users/voegtlil/Desktop/fun # -tr # 300 # -v # 300 # -te # 256 # example call arguments # -i # /dataset/DIVA-HisDB/segmentation/CB55 # -o # /net/research-hisdoc/datasets/semantic_segmentation/datasets_cropped/temp-CB55 # -tr # 300 # -v # 300 # -te # 256 # dataset_generator = CroppedDatasetGenerator( # input_path=Path('/dataset/DIVA-HisDB/segmentation/CB55'), # output_path=Path('/net/research-hisdoc/datasets/semantic_segmentation/datasets_cropped/CB55'), # crop_size_train=300, # crop_size_val=300, # crop_size_test=256, # overlap=0.5, # leading_zeros_length=4, # override_existing=False) # dataset_generator.write_crops()
[ 37811, 198, 8912, 257, 27039, 286, 9566, 4963, 416, 31577, 262, 9483, 810, 663, 5140, 13, 198, 37811, 198, 198, 11748, 1822, 29572, 198, 2, 7273, 4487, 198, 11748, 340, 861, 10141, 198, 11748, 18931, 198, 11748, 10688, 198, 6738, 4818, ...
2.076756
1,837
#!/usr/bin/env python # _*_ coding: utf-8 _*_ # @Time : 2021/12/27 14:04 # @Author : zhangjianming # @Email : YYDSPanda@163.com # @File : run_task.py # @Software: PyCharm import sys sys.path.extend(["."]) from torch_model_demo.task.run_task import train_fashion_demo if __name__ == '__main__': train_fashion_demo()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 4808, 9, 62, 19617, 25, 3384, 69, 12, 23, 4808, 9, 62, 198, 2, 2488, 7575, 220, 220, 220, 1058, 33448, 14, 1065, 14, 1983, 1478, 25, 3023, 198, 2, 2488, 13838, 220, 1058, 1976...
2.258503
147
import numpy as np import math import logging as log import sys from tqdm import tqdm from common.feature_distance import calc_features_similarity from common.common_objects import DetectedObject, validate_detected_object, Bbox from common.common_objects import get_bbox_center, get_dist, calc_bbox_area from common.find_best_assignment import solve_assignment_problem from common.annotation import AnnotationObject, AnnotationStorage def convert_tracks_to_annotation_storage(tracks): ann_objects_by_frame_index = {} for cur_track in tqdm(tracks, desc="Converting"): track_id = cur_track.get_id() first_frame_index = cur_track.objects[0].frame_index last_frame_index = cur_track.objects[-1].frame_index for frame_index in range(first_frame_index, last_frame_index+1): bbox = cur_track.get_bbox_for_frame(frame_index) tl_x = math.floor(bbox.tl_x) tl_y = math.floor(bbox.tl_y) br_x = math.ceil(bbox.br_x) br_y = math.ceil(bbox.br_y) detect_obj = DetectedObject(frame_index=frame_index, bbox=Bbox(tl_x, tl_y, br_x, br_y), appearance_feature=[]) ann_obj = AnnotationObject(detect_obj=detect_obj, track_id=track_id) if frame_index not in ann_objects_by_frame_index: ann_objects_by_frame_index[frame_index] = {} ann_objects_by_frame_index[frame_index][track_id] = ann_obj annotation_objects = [] for frame_index in sorted(ann_objects_by_frame_index.keys()): cur_ann_objects = ann_objects_by_frame_index[frame_index] for track_id in sorted(cur_ann_objects.keys()): annotation_objects.append(cur_ann_objects[track_id]) annotation_storage = AnnotationStorage.create_annotation_storage_from_list(annotation_objects) return annotation_storage
[ 11748, 299, 32152, 355, 45941, 198, 11748, 10688, 198, 11748, 18931, 355, 2604, 198, 11748, 25064, 198, 6738, 256, 80, 36020, 1330, 256, 80, 36020, 198, 6738, 2219, 13, 30053, 62, 30246, 1330, 42302, 62, 40890, 62, 38610, 414, 198, 6738...
2.266436
867
from django.db import router from django.db.models import Q, Manager from django.db import connections from .contenttypes import ct, get_content_type from .query import GM2MTgtQuerySet def create_gm2m_related_manager(superclass=None, **kwargs): """ Dynamically create a manager class that only concerns an instance (source or target) """ bases = [GM2MBaseManager] if superclass is None: # no superclass provided, the manager is a generic target model manager bases.insert(0, GM2MBaseTgtManager) else: # superclass provided, the manager is a source model manager and also # derives from superclass bases.insert(0, GM2MBaseSrcManager) bases.append(superclass) # Django's Manager constructor sets model to None, we store it under the # class's attribute '_model' and it is retrieved in __init__ kwargs['_model'] = kwargs.pop('model') return type(Manager)('GM2MManager', tuple(bases), kwargs)
[ 6738, 42625, 14208, 13, 9945, 1330, 20264, 201, 198, 6738, 42625, 14208, 13, 9945, 13, 27530, 1330, 1195, 11, 9142, 201, 198, 6738, 42625, 14208, 13, 9945, 1330, 8787, 201, 198, 201, 198, 6738, 764, 11299, 19199, 1330, 269, 83, 11, 65...
2.710875
377
from selenium.webdriver.chrome.options import Options from selenium import webdriver import logging import coloredlogs import os import pathlib import time import twitter as tt from utils import retry from fetch_likes import get_user_likes, login from conf.settings import USER_ID, USERNAME, PASSWORD CURR_PATH = pathlib.Path(__file__).parent.absolute() TWEETS_FOLDER = os.path.join(CURR_PATH, 'screenshots') LIKED_FOLDER = os.path.join(CURR_PATH, 'screenshots', 'liked')
[ 6738, 384, 11925, 1505, 13, 12384, 26230, 13, 46659, 13, 25811, 1330, 18634, 198, 6738, 384, 11925, 1505, 1330, 3992, 26230, 198, 198, 11748, 18931, 198, 11748, 16396, 6404, 82, 198, 11748, 28686, 198, 11748, 3108, 8019, 198, 11748, 640, ...
2.975
160
#!/usr/bin/python import sys import os from os.path import join, isdir import sentencepiece as spm #-------------------------- #--------------------------
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 198, 11748, 25064, 198, 11748, 28686, 198, 6738, 28686, 13, 6978, 1330, 4654, 11, 318, 15908, 198, 11748, 6827, 12239, 355, 599, 76, 198, 198, 2, 22369, 438, 198, 2, 22369, 438, 628 ]
3.853659
41
import typing from fiepipelib.gitlabserver.data.gitlab_server import GitLabServer from fiepipelib.gitlabserver.routines.manager import GitLabServerManagerInteractiveRoutines from fiepipedesktoplib.gitlabserver.shell.gitlab_hostname_input_ui import GitLabHostnameInputDefaultShellUI from fiepipedesktoplib.gitlabserver.shell.gitlab_username_input_ui import GitLabUsernameInputDefaultShellUI from fiepipedesktoplib.gitlabserver.shell.gitlab_private_token_input_ui import GitLabPrivateTokenInputDefaultShellUI from fiepipedesktoplib.gitlabserver.shell.gitlabserver import GitLabServerShell from fiepipedesktoplib.gitlabserver.shell.server_name_var_command import GitLabServerNameVar from fiepipedesktoplib.locallymanagedtypes.shells.AbstractLocalManagedTypeCommand import LocalManagedTypeCommand from fiepipedesktoplib.shells.AbstractShell import AbstractShell from fiepipedesktoplib.shells.variables.fqdn_var_command import FQDNVarCommand if __name__ == '__main__': main()
[ 11748, 19720, 198, 198, 6738, 277, 494, 79, 40634, 571, 13, 18300, 23912, 15388, 13, 7890, 13, 18300, 23912, 62, 15388, 1330, 15151, 17822, 10697, 198, 6738, 277, 494, 79, 40634, 571, 13, 18300, 23912, 15388, 13, 81, 448, 1127, 13, 37...
3.223684
304
import torch def repeat(N, fn): """repeat module N times :param int N: repeat time :param function fn: function to generate module :return: repeated modules :rtype: MultiSequential """ return MultiSequential(*[fn(n) for n in range(N)])
[ 11748, 28034, 628, 198, 198, 4299, 9585, 7, 45, 11, 24714, 2599, 198, 220, 220, 220, 37227, 44754, 8265, 399, 1661, 628, 220, 220, 220, 1058, 17143, 493, 399, 25, 9585, 640, 198, 220, 220, 220, 1058, 17143, 2163, 24714, 25, 2163, 28...
2.88172
93
import torch import torch.nn as nn import torch.nn.functional as F
[ 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 11748, 28034, 13, 20471, 13, 45124, 355, 376, 628 ]
3.4
20
from runner import runner if __name__ == '__main__': r = runner() p = 'public class main{public static void main (String[] args){' \ 'public String StudentAnswer(String myInput){' \ 'return "myOutput"; ' \ '}System.out.println("hello world!");}}' print (r.sendCode(p, ''))
[ 6738, 17490, 1330, 17490, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 374, 796, 17490, 3419, 198, 220, 220, 220, 279, 796, 705, 11377, 1398, 1388, 90, 11377, 9037, 7951, 1388, 357, 10100, 21...
2.596639
119
import traceback import telebot from telebot import apihelper from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton, MessageEntity, Message, CallbackQuery from beancount_bot import transaction from beancount_bot.config import get_config, load_config from beancount_bot.dispatcher import Dispatcher from beancount_bot.i18n import _ from beancount_bot.session import get_session, SESS_AUTH, get_session_for, set_session from beancount_bot.task import load_task, get_task from beancount_bot.transaction import get_manager from beancount_bot.util import logger apihelper.ENABLE_MIDDLEWARE = True bot = telebot.TeleBot(token=None, parse_mode=None) ####### # Authentication # ####### def check_auth() -> bool: """ Check if you log in :return: """ return SESS_AUTH in bot.session and bot.session[SESS_AUTH] def auth_token_handler(message: Message): """ Login token callback :param message: :return: """ if check_auth(): return # Unconfirmation is considered an authentication token auth_token = get_config('bot.auth_token') if auth_token == message.text: set_session(message.from_user.id, SESS_AUTH, True) bot.reply_to(message, _("Authentic success")) else: bot.reply_to(message, _("Authentication token error")) ####### # instruction # ####### def show_usage_for(message: Message, d: Dispatcher): """ Show the method of use of a specific processor :param message: :param d: :return: """ usage = _("help{name}\n\n{usage}").format(name=d.get_name(), usage=d.get_usage()) bot.reply_to(message, usage) ####### # trade # ####### def serving(): """ start up Bot :return: """ # set up Token token = get_config('bot.token') bot.token = token # Set a proxy proxy = get_config('bot.proxy') if proxy is not None: apihelper.proxy = {'https': proxy} # start up bot.infinity_polling()
[ 11748, 12854, 1891, 198, 11748, 5735, 13645, 198, 6738, 5735, 13645, 1330, 40391, 2978, 525, 198, 6738, 5735, 13645, 13, 19199, 1330, 554, 1370, 9218, 3526, 9704, 929, 11, 554, 1370, 9218, 3526, 21864, 11, 16000, 32398, 11, 16000, 11, 4...
2.689702
738
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import pytest import numpy as np import sklearn.metrics as skm import fairlearn.metrics as metrics # ====================================================== a = "a" b = "b" c = "c" Y_true = [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1] Y_pred = [1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1] Y_true_ternary = [a, b, c, c, c, b, b, b, c, c, a, a, a, a, a, b, c, c] Y_pred_ternary = [b, c, c, c, b, b, b, b, b, c, a, a, c, a, a, b, c, c] groups = [3, 4, 1, 0, 0, 0, 3, 2, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4] weight = [1, 2, 3, 1, 2, 3, 4, 2, 3, 3, 2, 1, 2, 3, 1, 2, 3, 4] group2 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1] # ======================================================= # Define as a dictionary so that the actual name can be seen # when pytest builds the tests supported_metrics_weighted = [(skm.accuracy_score, metrics.group_accuracy_score), (skm.confusion_matrix, metrics.group_confusion_matrix), (skm.zero_one_loss, metrics.group_zero_one_loss)] # The following only work with binary data when called with their default arguments supported_metrics_weighted_binary = [(skm.precision_score, metrics.group_precision_score), (skm.recall_score, metrics.group_recall_score), (skm.roc_auc_score, metrics.group_roc_auc_score), (skm.mean_squared_error, metrics.group_mean_squared_error), (skm.r2_score, metrics.group_r2_score)] supported_metrics_weighted_binary = supported_metrics_weighted_binary + supported_metrics_weighted metrics_no_sample_weights = [(skm.max_error, metrics.group_max_error), (skm.mean_absolute_error, metrics.group_mean_absolute_error), (skm.mean_squared_log_error, metrics.group_mean_squared_log_error), (skm.median_absolute_error, metrics.group_median_absolute_error)] supported_metrics_unweighted = metrics_no_sample_weights + supported_metrics_weighted_binary # ======================================================= # ====================================================================================== def test_group_accuracy_score_unnormalized(): result = metrics.group_accuracy_score(Y_true, Y_pred, groups, normalize=False) expected_overall = skm.accuracy_score(Y_true, Y_pred, False) assert result.overall == expected_overall # ====================================================================================== # ====================================================================================== # ====================================================================================== # ====================================================================================== # ====================================================================================== # ============================================================================================= # ============================================================================================= # =============================================================================================
[ 2, 15069, 357, 66, 8, 5413, 10501, 13, 1439, 2489, 10395, 13, 198, 2, 49962, 739, 262, 17168, 13789, 13, 198, 198, 11748, 12972, 9288, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 1341, 35720, 13, 4164, 10466, 355, 1341, 76, 198, ...
2.804167
1,200
""" Adapted from OpenAI Baselines. """ import numpy as np import tensorflow as tf # pylint: ignore-module import random import copy import os import functools import collections import multiprocessing def switch(condition, then_expression, else_expression): """Switches between two operations depending on a scalar value (int or bool). Note that both `then_expression` and `else_expression` should be symbolic tensors of the *same shape*. # Arguments condition: scalar tensor. then_expression: TensorFlow operation. else_expression: TensorFlow operation. """ x_shape = copy.copy(then_expression.get_shape()) x = tf.cond(tf.cast(condition, 'bool'), lambda: then_expression, lambda: else_expression) x.set_shape(x_shape) return x # ================================================================ # Extras # ================================================================ # ================================================================ # Mathematical utils # ================================================================ def huber_loss(x, delta=1.0): """Reference: https://en.wikipedia.org/wiki/Huber_loss""" return tf.where( tf.abs(x) < delta, tf.square(x) * 0.5, delta * (tf.abs(x) - 0.5 * delta) ) # ================================================================ # Global session # ================================================================ def make_session(num_cpu=None, make_default=False): """Returns a session that will use <num_cpu> CPU's only""" if num_cpu is None: num_cpu = int(os.getenv('RCALL_NUM_CPU', multiprocessing.cpu_count())) tf_config = tf.ConfigProto( inter_op_parallelism_threads=num_cpu, intra_op_parallelism_threads=num_cpu) tf_config.gpu_options.allocator_type = 'BFC' if make_default: return tf.InteractiveSession(config=tf_config) else: return tf.Session(config=tf_config) def single_threaded_session(): """Returns a session which will only use a single CPU""" return make_session(num_cpu=1) ALREADY_INITIALIZED = set() def initialize(): """Initialize all the uninitialized variables in the global scope.""" new_variables = set(tf.global_variables()) - ALREADY_INITIALIZED tf.get_default_session().run(tf.variables_initializer(new_variables)) ALREADY_INITIALIZED.update(new_variables) # ================================================================ # Saving variables and setting up experiment directories # ================================================================ # ================================================================ # Model components # ================================================================ def batch_to_seq(h, nbatch, nsteps, flat=False): """ Assumes Time major data!! x.shape = [nsteps, nbatch, *obs_shape] h = x.reshape([-1, *x.shape[2:]])) """ if flat: h = tf.reshape(h, [nsteps, nbatch]) else: h = tf.reshape(h, [nsteps, nbatch, -1]) return [tf.squeeze(v, [0]) for v in tf.split(axis=0, num_or_size_splits=nsteps, value=h)] def seq_to_batch(h, flat = False): """ Assumes Time major data!! x.shape = [nsteps, nbatch, *obs_shape] x = output.reshape(nsteps, nbatch, *obs_shape), where output is the output of this function. """ shape = h[0].get_shape().as_list() if not flat: assert(len(shape) > 1) nh = h[0].get_shape()[-1].value return tf.reshape(tf.concat(axis=0, values=h), [-1, nh]) else: return tf.reshape(tf.stack(values=h, axis=0), [-1]) def ortho_init(scale=1.0): return _ortho_init def normc_initializer(std=1.0): return _initializer def lstm(xs, ms, s, scope, nh, init_scale=1.0): nbatch, nin = [v.value for v in xs[0].get_shape()] nsteps = len(xs) with tf.variable_scope(scope): wx = tf.get_variable("wx", [nin, nh*4], initializer=ortho_init(init_scale)) wh = tf.get_variable("wh", [nh, nh*4], initializer=ortho_init(init_scale)) b = tf.get_variable("b", [nh*4], initializer=tf.constant_initializer(0.0)) c, h = tf.split(axis=1, num_or_size_splits=2, value=s) for idx, (x, m) in enumerate(zip(xs, ms)): c = c*(1-m) h = h*(1-m) z = tf.matmul(x, wx) + tf.matmul(h, wh) + b i, f, o, u = tf.split(axis=1, num_or_size_splits=4, value=z) i = tf.nn.sigmoid(i) f = tf.nn.sigmoid(f) o = tf.nn.sigmoid(o) u = tf.tanh(u) c = f*c + i*u h = o*tf.tanh(c) xs[idx] = h s = tf.concat(axis=1, values=[c, h]) return xs, s # ================================================================ # Theano-like Function # ================================================================ def function(inputs, outputs, updates=None, givens=None): """Just like Theano function. Take a bunch of tensorflow placeholders and expressions computed based on those placeholders and produces f(inputs) -> outputs. Function f takes values to be fed to the input's placeholders and produces the values of the expressions in outputs. Input values can be passed in the same order as inputs or can be provided as kwargs based on placeholder name (passed to constructor or accessible via placeholder.op.name). Example: x = tf.placeholder(tf.int32, (), name="x") y = tf.placeholder(tf.int32, (), name="y") z = 3 * x + 2 * y lin = function([x, y], z, givens={y: 0}) with single_threaded_session(): initialize() assert lin(2) == 6 assert lin(x=3) == 9 assert lin(2, 2) == 10 assert lin(x=2, y=3) == 12 Parameters ---------- inputs: [tf.placeholder, tf.constant, or object with make_feed_dict method] list of input arguments outputs: [tf.Variable] or tf.Variable list of outputs or a single output to be returned from function. Returned value will also have the same shape. """ if isinstance(outputs, list): return _Function(inputs, outputs, updates, givens=givens) elif isinstance(outputs, (dict, collections.OrderedDict)): f = _Function(inputs, outputs.values(), updates, givens=givens) return lambda *args, **kwargs: type(outputs)(zip(outputs.keys(), f(*args, **kwargs))) else: f = _Function(inputs, [outputs], updates, givens=givens) return lambda *args, **kwargs: f(*args, **kwargs)[0] # ================================================================ # Flat vectors # ================================================================ def var_shape(x): out = x.get_shape().as_list() assert all(isinstance(a, int) for a in out), \ "shape function assumes that shape is fully known" return out def numel(x): return intprod(var_shape(x)) def intprod(x): return int(np.prod(x)) def flatgrad(loss, var_list, clip_norm=None): grads = tf.gradients(loss, var_list) if clip_norm is not None: grads, _ = tf.clip_by_global_norm(grads, clip_norm=clip_norm) return tf.concat(axis=0, values=[ tf.reshape(grad if grad is not None else tf.zeros_like(v), [numel(v)]) for (v, grad) in zip(var_list, grads) ]) def flattenallbut0(x): return tf.reshape(x, [-1, intprod(x.get_shape().as_list()[1:])]) def reset(): global ALREADY_INITIALIZED ALREADY_INITIALIZED = set() tf.reset_default_graph() """ Random Seeds """ def set_global_seeds(i): try: import tensorflow as tf except ImportError: pass else: tf.set_random_seed(i) np.random.seed(i) random.seed(i)
[ 37811, 198, 48003, 276, 422, 4946, 20185, 6455, 20655, 13, 198, 37811, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 11192, 273, 11125, 355, 48700, 220, 1303, 279, 2645, 600, 25, 8856, 12, 21412, 198, 11748, 4738, 198, 11748, 486...
2.575274
3,009
# Under MIT License, see LICENSE.txt """ Module dfinissant des constantes de programmations python pour l'IA """ from enum import Enum ROBOT_RADIUS = 90 ROBOT_DIAMETER = ROBOT_RADIUS * 2 ROBOT_CENTER_TO_KICKER = 60 BALL_RADIUS = 21 MAX_PLAYER_ON_FIELD_PER_TEAM = 6 BALL_OUTSIDE_FIELD_BUFFER = 200 # Radius and angles for tactics DISTANCE_BEHIND = ROBOT_RADIUS + 30 # in millimeters ANGLE_TO_GRAB_BALL = 1 # in radians; must be large in case ball moves fast RADIUS_TO_GRAB_BALL = ROBOT_RADIUS + 30 ANGLE_TO_HALT = 0.05 # 3 degrees RADIUS_TO_HALT = ROBOT_RADIUS + BALL_RADIUS REASONABLE_OFFSET = 50 # To take into account the camera precision and other things # Rules KEEPOUT_DISTANCE_FROM_BALL = 500 + ROBOT_RADIUS + REASONABLE_OFFSET KEEPOUT_DISTANCE_FROM_GOAL = ROBOT_RADIUS + REASONABLE_OFFSET PADDING_DEFENSE_AREA = 100 # Rule 5.2: Minimum movement before a ball is "in play" IN_PLAY_MIN_DISTANCE = 50 # Rule 8.2.1: Distance from the opposing team defending zone INDIRECT_KICK_OFFSET = 200 # Deadzones POSITION_DEADZONE = ROBOT_RADIUS * 0.1 # Orientation abs_tol ORIENTATION_ABSOLUTE_TOLERANCE = 0.01 # 0.5 degree # TeamColor
[ 2, 4698, 17168, 13789, 11, 766, 38559, 24290, 13, 14116, 198, 37811, 19937, 288, 15643, 747, 415, 748, 6937, 274, 390, 1430, 76, 602, 21015, 12797, 300, 6, 3539, 37227, 198, 198, 6738, 33829, 1330, 2039, 388, 628, 198, 49, 9864, 2394,...
2.470968
465
import numpy as np x_pi = 3.14159265358979324 * 3000.0 / 180.0 pi = 3.1415926535897932384626 a = 6378245.0 ee = 0.00669342162296594323 def gcj02tobd09(lng, lat): """ Convert coordinates from GCJ02 to BD09 Parameters ------- lng : Series or number Longitude lat : Series or number Latitude return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ try: lng = lng.astype(float) lat = lat.astype(float) except: lng = float(lng) lat = float(lat) z = np.sqrt(lng * lng + lat * lat) + 0.00002 * np.sin(lat * x_pi) theta = np.arctan2(lat, lng) + 0.000003 * np.cos(lng * x_pi) bd_lng = z * np.cos(theta) + 0.0065 bd_lat = z * np.sin(theta) + 0.006 return bd_lng, bd_lat def bd09togcj02(bd_lon, bd_lat): """ Convert coordinates from BD09 to GCJ02 Parameters ------- lng : Series or number Longitude lat : Series or number Latitude return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ try: bd_lon = bd_lon.astype(float) bd_lat = bd_lat.astype(float) except: bd_lon = float(bd_lon) bd_lat = float(bd_lat) x = bd_lon - 0.0065 y = bd_lat - 0.006 z = np.sqrt(x * x + y * y) - 0.00002 * np.sin(y * x_pi) theta = np.arctan2(y, x) - 0.000003 * np.cos(x * x_pi) gg_lng = z * np.cos(theta) gg_lat = z * np.sin(theta) return gg_lng, gg_lat def wgs84togcj02(lng, lat): """ Convert coordinates from WGS84 to GCJ02 Parameters ------- lng : Series or number Longitude lat : Series or number Latitude return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ try: lng = lng.astype(float) lat = lat.astype(float) except: lng = float(lng) lat = float(lat) dlat = transformlat(lng - 105.0, lat - 35.0) dlng = transformlng(lng - 105.0, lat - 35.0) radlat = lat / 180.0 * pi magic = np.sin(radlat) magic = 1 - ee * magic * magic sqrtmagic = np.sqrt(magic) dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) dlng = (dlng * 180.0) / (a / sqrtmagic * np.cos(radlat) * pi) mglat = lat + dlat mglng = lng + dlng return mglng, mglat def gcj02towgs84(lng, lat): """ Convert coordinates from GCJ02 to WGS84 Parameters ------- lng : Series or number Longitude lat : Series or number Latitude return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ try: lng = lng.astype(float) lat = lat.astype(float) except: lng = float(lng) lat = float(lat) dlat = transformlat(lng - 105.0, lat - 35.0) dlng = transformlng(lng - 105.0, lat - 35.0) radlat = lat / 180.0 * pi magic = np.sin(radlat) magic = 1 - ee * magic * magic sqrtmagic = np.sqrt(magic) dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) dlng = (dlng * 180.0) / (a / sqrtmagic * np.cos(radlat) * pi) mglat = lat + dlat mglng = lng + dlng return lng * 2 - mglng, lat * 2 - mglat def wgs84tobd09(lon,lat): """ Convert coordinates from WGS84 to BD09 Parameters ------- lng : Series or number Longitude lat : Series or number Latitude return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ try: lon = lon.astype(float) lat = lat.astype(float) except: lon = float(lon) lat = float(lat) lon,lat = wgs84togcj02(lon,lat) lon,lat = gcj02tobd09(lon,lat) return lon,lat def bd09towgs84(lon,lat): """ Convert coordinates from BD09 to WGS84 Parameters ------- lng : Series or number Longitude lat : Series or number Latitude return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ try: lon = lon.astype(float) lat = lat.astype(float) except: lon = float(lon) lat = float(lat) lon,lat = bd09togcj02(lon,lat) lon,lat = gcj02towgs84(lon,lat) return lon,lat def bd09mctobd09(x,y): """ Convert coordinates from BD09MC to BD09 Parameters ------- x : Series or number x coordinates y : Series or number y coordinates return ------- lng : Series or number Longitude (Converted) lat : Series or number Latitude (Converted) """ MCBAND = [12890594.86, 8362377.87, 5591021, 3481989.83, 1678043.12, 0] MC2LL = [ [1.410526172116255e-8, 0.00000898305509648872, -1.9939833816331, 200.9824383106796, -187.2403703815547, 91.6087516669843, -23.38765649603339, 2.57121317296198, -0.03801003308653, 17337981.2], [-7.435856389565537e-9, 0.000008983055097726239, -0.78625201886289, 96.32687599759846, -1.85204757529826, -59.36935905485877, 47.40033549296737, -16.50741931063887, 2.28786674699375, 10260144.86], [-3.030883460898826e-8, 0.00000898305509983578, 0.30071316287616, 59.74293618442277, 7.357984074871, -25.38371002664745, 13.45380521110908, -3.29883767235584, 0.32710905363475, 6856817.37], [-1.981981304930552e-8, 0.000008983055099779535, 0.03278182852591, 40.31678527705744, 0.65659298677277, -4.44255534477492, 0.85341911805263, 0.12923347998204, -0.04625736007561, 4482777.06], [3.09191371068437e-9, 0.000008983055096812155, 0.00006995724062, 23.10934304144901, -0.00023663490511, -0.6321817810242, -0.00663494467273, 0.03430082397953, -0.00466043876332, 2555164.4], [2.890871144776878e-9, 0.000008983055095805407, -3.068298e-8, 7.47137025468032, -0.00000353937994, -0.02145144861037, -0.00001234426596, 0.00010322952773, -0.00000323890364, 826088.5] ] y1 = y.iloc[0] for cD in range(len(MCBAND)): if y1 >= MCBAND[cD]: cE = MC2LL[cD] break cD = cE T = cD[0] + cD[1] * np.abs(x); cB = np.abs(y) / cD[9] cE = cD[2] + cD[3] * cB + cD[4] * cB * cB +\ cD[5] * cB * cB * cB + cD[6] * cB * cB * cB * cB +\ cD[7] * cB * cB * cB * cB * cB +\ cD[8] * cB * cB * cB * cB * cB * cB return T,cE def getdistance(lon1, lat1, lon2, lat2): ''' Input the origin/destination location in the sequence of [lon1, lat1, lon2, lat2] (in decimal) from DataFrame. The output is the distance (m). Parameters ------- lon1 : Series or number Start longitude lat1 : Series or number Start latitude lon2 : Series or number End longitude lat2 : Series or number End latitude return ------- distance : Series or number The distance ''' try: lon1 = lon1.astype(float) lat1 = lat1.astype(float) lon2 = lon2.astype(float) lat2 = lat2.astype(float) except: lon1 = float(lon1) lat1 = float(lat1) lon2 = float(lon2) lat2 = float(lat2) lon1, lat1, lon2, lat2 = map(lambda r:r*pi/180, [lon1, lat1, lon2, lat2]) dlon = lon2 - lon1 dlat = lat2 - lat1 a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2 c = 2 * np.arcsin(a**0.5) r = 6371 # return c * r * 1000 def transform_shape(gdf,method): ''' Convert coordinates of all data. The input is the geographic elements DataFrame. Parameters ------- gdf : GeoDataFrame Geographic elements method : function The coordinate converting function return ------- gdf : GeoDataFrame The result of converting ''' from shapely.ops import transform gdf1 = gdf.copy() gdf1['geometry'] = gdf1['geometry'].apply(lambda r:transform(method, r)) return gdf1
[ 198, 11748, 299, 32152, 355, 45941, 198, 87, 62, 14415, 796, 513, 13, 1415, 19707, 22980, 2327, 4531, 3720, 33916, 1635, 20343, 13, 15, 1220, 11546, 13, 15, 198, 14415, 796, 513, 13, 1415, 19707, 22980, 2327, 4531, 44750, 23721, 3510, ...
2.018294
4,045
######## # Copyright (c) 2014 GigaSpaces Technologies Ltd. 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. ERROR_MAPPING = dict([ (error.ERROR_CODE, error) for error in [ DeploymentEnvironmentCreationInProgressError, DeploymentEnvironmentCreationPendingError, IllegalExecutionParametersError, NoSuchIncludeFieldError, MissingRequiredDeploymentInputError, UnknownDeploymentInputError, UnknownDeploymentSecretError, UnsupportedDeploymentGetSecretError, FunctionsEvaluationError, UnknownModificationStageError, ExistingStartedDeploymentModificationError, DeploymentModificationAlreadyEndedError, UserUnauthorizedError, ForbiddenError, MaintenanceModeActiveError, MaintenanceModeActivatingError, NotModifiedError, InvalidExecutionUpdateStatus, PluginInUseError, PluginInstallationError, PluginInstallationTimeout, NotClusterMaster, RemovedFromCluster, DeploymentPluginNotFound]])
[ 7804, 198, 2, 15069, 357, 66, 8, 1946, 402, 13827, 4561, 2114, 21852, 12052, 13, 1439, 2489, 10395, 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, 4...
2.906028
564
import boto3 import logging import os from random import randrange from urllib.request import urlopen # It is not recommended to enable DEBUG logs in production, # this is just to show an example of a recommendation # by Amazon CodeGuru Profiler. logging.getLogger('botocore').setLevel(logging.DEBUG) SITE = 'http://www.python.org/' CW_NAMESPACE = 'ProfilerPythonDemo' S3_BUCKET = os.environ['S3_BUCKET']
[ 11748, 275, 2069, 18, 198, 11748, 18931, 198, 11748, 28686, 198, 198, 6738, 4738, 1330, 43720, 9521, 198, 6738, 2956, 297, 571, 13, 25927, 1330, 19016, 9654, 198, 198, 2, 632, 318, 407, 7151, 284, 7139, 16959, 17259, 287, 3227, 11, 19...
3.044444
135
from functools import wraps from werkzeug.exceptions import HTTPException from api.exceptions import MessageNotFound
[ 6738, 1257, 310, 10141, 1330, 27521, 198, 6738, 266, 9587, 2736, 1018, 13, 1069, 11755, 1330, 14626, 16922, 198, 6738, 40391, 13, 1069, 11755, 1330, 16000, 3673, 21077, 628 ]
4.068966
29
"""Command to run Nile scripts.""" import logging from importlib.machinery import SourceFileLoader from nile.nre import NileRuntimeEnvironment def run(path, network): """Run nile scripts passing on the NRE object.""" logger = logging.getLogger() logger.disabled = True script = SourceFileLoader("script", path).load_module() nre = NileRuntimeEnvironment(network) script.run(nre)
[ 37811, 21575, 284, 1057, 38063, 14750, 526, 15931, 198, 11748, 18931, 198, 6738, 1330, 8019, 13, 76, 620, 15451, 1330, 8090, 8979, 17401, 198, 198, 6738, 299, 576, 13, 77, 260, 1330, 38063, 41006, 31441, 628, 198, 4299, 1057, 7, 6978, ...
3.248
125
array = [] for _ in range(int(input())): command = input().strip().split(" ") cmd_type = command[0] if (cmd_type == "print"): print(array) elif (cmd_type == "sort"): array.sort() elif (cmd_type == "reverse"): array.reverse() elif (cmd_type == "pop"): array.pop() elif (cmd_type == "remove"): array.remove(int(command[1])) elif (cmd_type == "append"): array.append(int(command[1])) elif (cmd_type == "insert"): array.insert(int(command[1]), int(command[2]))
[ 18747, 796, 17635, 198, 1640, 4808, 287, 2837, 7, 600, 7, 15414, 28955, 2599, 198, 220, 220, 220, 3141, 796, 5128, 22446, 36311, 22446, 35312, 7203, 366, 8, 198, 220, 220, 220, 23991, 62, 4906, 796, 3141, 58, 15, 60, 198, 220, 220, ...
2.14902
255
# Created by Qingzhi Ma at 2019-07-23 # All right reserved # Department of Computer Science # the University of Warwick # Q.Ma.2@warwick.ac.uk from sklearn.neighbors import KernelDensity
[ 2, 15622, 416, 28927, 89, 5303, 6669, 379, 13130, 12, 2998, 12, 1954, 198, 2, 1439, 826, 10395, 198, 2, 2732, 286, 13851, 5800, 198, 2, 262, 2059, 286, 49398, 198, 2, 1195, 13, 21467, 13, 17, 31, 5767, 16239, 13, 330, 13, 2724, ...
3.241379
58
#!/usr/bin/env python import setuptools from setuptools import setup from os import path # Read the package requirements with open("requirements.txt", "r") as f: requirements = [line.rstrip("\n") for line in f if line != "\n"] # Read the contents of the README file this_directory = path.abspath(path.dirname(__file__)) with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: long_description = f.read() setup(name='access-spotify', version="1.1", author="pancham_banerjee", author_email="panchajanya.banerjee@gmail.com", packages=setuptools.find_packages(), scripts=["./bin/access_script.py"], install_requires=requirements, license="MIT", description="A package to get all album and track info for an artist by querying the Spotify API", long_description=long_description, long_description_content_type='text/markdown' )
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 11748, 900, 37623, 10141, 198, 6738, 900, 37623, 10141, 1330, 9058, 198, 6738, 28686, 1330, 3108, 198, 198, 2, 4149, 262, 5301, 5359, 198, 4480, 1280, 7203, 8897, 18883, 13, 14116, ...
2.787879
330
# -*- coding: utf-8 -*- """ mundiapi This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). """
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 201, 198, 201, 198, 37811, 201, 198, 220, 220, 220, 27943, 72, 15042, 201, 198, 201, 198, 220, 220, 220, 770, 2393, 373, 6338, 7560, 416, 3486, 3955, 1404, 2149, 410, 17, ...
2.149254
67
from hearthstone.enums import GameTag, TAG_TYPES
[ 6738, 3285, 400, 6440, 13, 268, 5700, 1330, 3776, 24835, 11, 37801, 62, 9936, 47, 1546, 628, 198 ]
2.833333
18
# Archivo ejemplo 00 de creacion de clases en Python from math import gcd # greatest common denominator = Maximo Comun Divisor (MCD) if __name__ == "__main__": a = Fraccion(5,12) print(a) b = Fraccion(3,5) c = a*b c_real = c.a_numero_real() print("Multiplicar la fraccion {} por la fraccion {} da como resultado la fraccion {} que es equivalente a {}".format(a,b,c,c_real))# Escribe tu cdigo aqu :-) a = Fraccion(1,2) print(a) b = Fraccion(1,4) c = a+b c_real = c.a_numero_real() print("Sumar la fraccion {} con la fraccion {} da como resultado la fraccion {} que es equivalente a {}".format(a,b,c,c_real))# Escribe tu cdigo aqu :-)
[ 2, 5579, 23593, 304, 73, 18856, 78, 3571, 390, 1126, 49443, 390, 537, 1386, 551, 11361, 198, 198, 6738, 10688, 1330, 308, 10210, 1303, 6000, 2219, 31457, 1352, 796, 5436, 25147, 955, 403, 4777, 271, 273, 357, 44, 8610, 8, 628, 198, ...
2.333333
294
from . import models from . import components from . import http
[ 6738, 764, 1330, 4981, 198, 6738, 764, 1330, 6805, 198, 6738, 764, 1330, 2638, 198 ]
4.333333
15
import os import pandas as pd
[ 11748, 28686, 198, 11748, 19798, 292, 355, 279, 67, 628, 628 ]
3
11
from distutils.core import setup import snip_basic_verify setup( py_modules=['snip_basic_verify'], ext_modules=[snip_basic_verify.ffi.verifier.get_extension()])
[ 201, 198, 6738, 1233, 26791, 13, 7295, 1330, 9058, 201, 198, 11748, 3013, 541, 62, 35487, 62, 332, 1958, 201, 198, 201, 198, 40406, 7, 201, 198, 220, 220, 220, 12972, 62, 18170, 28, 17816, 16184, 541, 62, 35487, 62, 332, 1958, 6, ...
2.373333
75
#!../env/bin/python """A simple test script for the PCE portion of OnRamp. Usage: ./test_pce.py This script is only intended to be run in a fresh install of the repository. It has side-effects that could corrupt module and user data if run in a production setting. Prior to running this script, ensure that onramp/pce/bin/onramp_pce_install.py has been called and that the server is running. Also Ensure ./test_pce_config.cfg contains the proper settings. """ import nose import sys if __name__ == '__main__': print (__doc__) response = raw_input('(C)ontinue or (A)bort? ') if response != 'C': sys.exit(0) nose.main()
[ 2, 0, 40720, 24330, 14, 8800, 14, 29412, 198, 37811, 32, 2829, 1332, 4226, 329, 262, 4217, 36, 6903, 286, 1550, 49, 696, 13, 198, 198, 28350, 25, 24457, 9288, 62, 79, 344, 13, 9078, 198, 198, 1212, 4226, 318, 691, 5292, 284, 307, ...
2.954338
219
import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt import logging from .analysis import lifetime_histogram from .analysis import histogram_cellwise,histogram_featurewise import numpy as np def plot_mask_cell_track_follow(cell,track, cog, features, mask_total, field_contour, field_filled, width=10000, name= 'test', plotdir='./', file_format=['png'],figsize=(10/2.54, 10/2.54),dpi=300, **kwargs): '''Make plots for all cells centred around cell and with one background field as filling and one background field as contrours Input: Output: ''' from iris import Constraint from numpy import unique import os track_cell=track[track['cell']==cell] for i_row,row in track_cell.iterrows(): constraint_time = Constraint(time=row['time']) constraint_x = Constraint(projection_x_coordinate = lambda cell: row['projection_x_coordinate']-width < cell < row['projection_x_coordinate']+width) constraint_y = Constraint(projection_y_coordinate = lambda cell: row['projection_y_coordinate']-width < cell < row['projection_y_coordinate']+width) constraint = constraint_time & constraint_x & constraint_y mask_total_i=mask_total.extract(constraint) if field_contour is None: field_contour_i=None else: field_contour_i=field_contour.extract(constraint) if field_filled is None: field_filled_i=None else: field_filled_i=field_filled.extract(constraint) cells=list(unique(mask_total_i.core_data())) if cell not in cells: cells.append(cell) if 0 in cells: cells.remove(0) track_i=track[track['cell'].isin(cells)] track_i=track_i[track_i['time']==row['time']] if cog is None: cog_i=None else: cog_i=cog[cog['cell'].isin(cells)] cog_i=cog_i[cog_i['time']==row['time']] if features is None: features_i=None else: features_i=features[features['time']==row['time']] fig1, ax1 = plt.subplots(ncols=1, nrows=1, figsize=figsize) fig1.subplots_adjust(left=0.2, bottom=0.15, right=0.85, top=0.80) datestring_stamp = row['time'].strftime('%Y-%m-%d %H:%M:%S') celltime_stamp = "%02d:%02d:%02d" % (row['time_cell'].dt.total_seconds() // 3600,(row['time_cell'].dt.total_seconds() % 3600) // 60, row['time_cell'].dt.total_seconds() % 60 ) title=datestring_stamp + ' , ' + celltime_stamp datestring_file = row['time'].strftime('%Y-%m-%d_%H%M%S') ax1=plot_mask_cell_individual_follow(cell_i=cell,track=track_i, cog=cog_i,features=features_i, mask_total=mask_total_i, field_contour=field_contour_i, field_filled=field_filled_i, width=width, axes=ax1,title=title, **kwargs) out_dir = os.path.join(plotdir, name) os.makedirs(out_dir, exist_ok=True) if 'png' in file_format: savepath_png = os.path.join(out_dir, name + '_' + datestring_file + '.png') fig1.savefig(savepath_png, dpi=dpi) logging.debug('field_contour field_filled Mask plot saved to ' + savepath_png) if 'pdf' in file_format: savepath_pdf = os.path.join(out_dir, name + '_' + datestring_file + '.pdf') fig1.savefig(savepath_pdf, dpi=dpi) logging.debug('field_contour field_filled Mask plot saved to ' + savepath_pdf) plt.close() plt.clf() def plot_mask_cell_individual_follow(cell_i,track, cog,features, mask_total, field_contour, field_filled, axes=None,width=10000, label_field_contour=None, cmap_field_contour='Blues',norm_field_contour=None, linewidths_contour=0.8,contour_labels=False, vmin_field_contour=0,vmax_field_contour=50,levels_field_contour=None,nlevels_field_contour=10, label_field_filled=None,cmap_field_filled='summer',norm_field_filled=None, vmin_field_filled=0,vmax_field_filled=100,levels_field_filled=None,nlevels_field_filled=10, title=None ): '''Make individual plot for cell centred around cell and with one background field as filling and one background field as contrours Input: Output: ''' import numpy as np from .utils import mask_cell_surface from mpl_toolkits.axes_grid1 import make_axes_locatable from matplotlib.colors import Normalize divider = make_axes_locatable(axes) x_pos=track[track['cell']==cell_i]['projection_x_coordinate'].item() y_pos=track[track['cell']==cell_i]['projection_y_coordinate'].item() if field_filled is not None: if levels_field_filled is None: levels_field_filled=np.linspace(vmin_field_filled,vmax_field_filled, nlevels_field_filled) plot_field_filled = axes.contourf((field_filled.coord('projection_x_coordinate').points-x_pos)/1000, (field_filled.coord('projection_y_coordinate').points-y_pos)/1000, field_filled.data, cmap=cmap_field_filled,norm=norm_field_filled, levels=levels_field_filled,vmin=vmin_field_filled, vmax=vmax_field_filled) cax_filled = divider.append_axes("right", size="5%", pad=0.1) norm_filled= Normalize(vmin=vmin_field_filled, vmax=vmax_field_filled) sm_filled= plt.cm.ScalarMappable(norm=norm_filled, cmap = plot_field_filled.cmap) sm_filled.set_array([]) cbar_field_filled = plt.colorbar(sm_filled, orientation='vertical',cax=cax_filled) cbar_field_filled.ax.set_ylabel(label_field_filled) cbar_field_filled.set_clim(vmin_field_filled, vmax_field_filled) if field_contour is not None: if levels_field_contour is None: levels_field_contour=np.linspace(vmin_field_contour, vmax_field_contour, nlevels_field_contour) if norm_field_contour: vmin_field_contour=None, vmax_field_contour=None, plot_field_contour = axes.contour((field_contour.coord('projection_x_coordinate').points-x_pos)/1000, (field_contour.coord('projection_y_coordinate').points-y_pos)/1000, field_contour.data, cmap=cmap_field_contour,norm=norm_field_contour, levels=levels_field_contour,vmin=vmin_field_contour, vmax=vmax_field_contour, linewidths=linewidths_contour) if contour_labels: axes.clabel(plot_field_contour, fontsize=10) cax_contour = divider.append_axes("bottom", size="5%", pad=0.1) if norm_field_contour: vmin_field_contour=None vmax_field_contour=None norm_contour=norm_field_contour else: norm_contour= Normalize(vmin=vmin_field_contour, vmax=vmax_field_contour) sm_contour= plt.cm.ScalarMappable(norm=norm_contour, cmap = plot_field_contour.cmap) sm_contour.set_array([]) cbar_field_contour = plt.colorbar(sm_contour, orientation='horizontal',ticks=levels_field_contour,cax=cax_contour) cbar_field_contour.ax.set_xlabel(label_field_contour) cbar_field_contour.set_clim(vmin_field_contour, vmax_field_contour) for i_row, row in track.iterrows(): cell = int(row['cell']) if cell==cell_i: color='darkred' else: color='darkorange' cell_string=' '+str(int(row['cell'])) axes.text((row['projection_x_coordinate']-x_pos)/1000, (row['projection_y_coordinate']-y_pos)/1000, cell_string,color=color,fontsize=6, clip_on=True) # Plot marker for tracked cell centre as a cross axes.plot((row['projection_x_coordinate']-x_pos)/1000, (row['projection_y_coordinate']-y_pos)/1000, 'x', color=color,markersize=4) #Create surface projection of mask for the respective cell and plot it in the right color z_coord = 'model_level_number' if len(mask_total.shape)==3: mask_total_i_surface = mask_cell_surface(mask_total, cell, track, masked=False, z_coord=z_coord) elif len(mask_total.shape)==2: mask_total_i_surface=mask_total axes.contour((mask_total_i_surface.coord('projection_x_coordinate').points-x_pos)/1000, (mask_total_i_surface.coord('projection_y_coordinate').points-y_pos)/1000, mask_total_i_surface.data, levels=[0, cell], colors=color, linestyles=':',linewidth=1) if cog is not None: for i_row, row in cog.iterrows(): cell = row['cell'] if cell==cell_i: color='darkred' else: color='darkorange' # plot marker for centre of gravity as a circle axes.plot((row['x_M']-x_pos)/1000, (row['y_M']-y_pos)/1000, 'o', markeredgecolor=color, markerfacecolor='None',markersize=4) if features is not None: for i_row, row in features.iterrows(): color='purple' axes.plot((row['projection_x_coordinate']-x_pos)/1000, (row['projection_y_coordinate']-y_pos)/1000, '+', color=color,markersize=3) axes.set_xlabel('x (km)') axes.set_ylabel('y (km)') axes.set_xlim([-1*width/1000, width/1000]) axes.set_ylim([-1*width/1000, width/1000]) axes.xaxis.set_label_position('top') axes.xaxis.set_ticks_position('top') axes.set_title(title,pad=35,fontsize=10,horizontalalignment='left',loc='left') return axes def plot_mask_cell_track_static(cell,track, cog, features, mask_total, field_contour, field_filled, width=10000,n_extend=1, name= 'test', plotdir='./', file_format=['png'],figsize=(10/2.54, 10/2.54),dpi=300, **kwargs): '''Make plots for all cells with fixed frame including entire development of the cell and with one background field as filling and one background field as contrours Input: Output: ''' from iris import Constraint from numpy import unique import os track_cell=track[track['cell']==cell] x_min=track_cell['projection_x_coordinate'].min()-width x_max=track_cell['projection_x_coordinate'].max()+width y_min=track_cell['projection_y_coordinate'].min()-width y_max=track_cell['projection_y_coordinate'].max()+width #set up looping over time based on mask's time coordinate to allow for one timestep before and after the track time_coord=mask_total.coord('time') time=time_coord.units.num2date(time_coord.points) i_start=max(0,np.where(time==track_cell['time'].values[0])[0][0]-n_extend) i_end=min(len(time)-1,np.where(time==track_cell['time'].values[-1])[0][0]+n_extend+1) time_cell=time[slice(i_start,i_end)] for time_i in time_cell: # for i_row,row in track_cell.iterrows(): # time_i=row['time'] # constraint_time = Constraint(time=row['time']) constraint_time = Constraint(time=time_i) constraint_x = Constraint(projection_x_coordinate = lambda cell: x_min < cell < x_max) constraint_y = Constraint(projection_y_coordinate = lambda cell: y_min < cell < y_max) constraint = constraint_time & constraint_x & constraint_y mask_total_i=mask_total.extract(constraint) if field_contour is None: field_contour_i=None else: field_contour_i=field_contour.extract(constraint) if field_filled is None: field_filled_i=None else: field_filled_i=field_filled.extract(constraint) track_i=track[track['time']==time_i] cells_mask=list(unique(mask_total_i.core_data())) track_cells=track_i.loc[(track_i['projection_x_coordinate'] > x_min) & (track_i['projection_x_coordinate'] < x_max) & (track_i['projection_y_coordinate'] > y_min) & (track_i['projection_y_coordinate'] < y_max)] cells_track=list(track_cells['cell'].values) cells=list(set( cells_mask + cells_track )) if cell not in cells: cells.append(cell) if 0 in cells: cells.remove(0) track_i=track_i[track_i['cell'].isin(cells)] if cog is None: cog_i=None else: cog_i=cog[cog['cell'].isin(cells)] cog_i=cog_i[cog_i['time']==time_i] if features is None: features_i=None else: features_i=features[features['time']==time_i] fig1, ax1 = plt.subplots(ncols=1, nrows=1, figsize=figsize) fig1.subplots_adjust(left=0.2, bottom=0.15, right=0.80, top=0.85) datestring_stamp = time_i.strftime('%Y-%m-%d %H:%M:%S') if time_i in track_cell['time'].values: time_cell_i=track_cell[track_cell['time'].values==time_i]['time_cell'] celltime_stamp = "%02d:%02d:%02d" % (time_cell_i.dt.total_seconds() // 3600, (time_cell_i.dt.total_seconds() % 3600) // 60, time_cell_i.dt.total_seconds() % 60 ) else: celltime_stamp=' - ' title=datestring_stamp + ' , ' + celltime_stamp datestring_file = time_i.strftime('%Y-%m-%d_%H%M%S') ax1=plot_mask_cell_individual_static(cell_i=cell, track=track_i, cog=cog_i,features=features_i, mask_total=mask_total_i, field_contour=field_contour_i, field_filled=field_filled_i, xlim=[x_min/1000,x_max/1000],ylim=[y_min/1000,y_max/1000], axes=ax1,title=title,**kwargs) out_dir = os.path.join(plotdir, name) os.makedirs(out_dir, exist_ok=True) if 'png' in file_format: savepath_png = os.path.join(out_dir, name + '_' + datestring_file + '.png') fig1.savefig(savepath_png, dpi=dpi) logging.debug('Mask static plot saved to ' + savepath_png) if 'pdf' in file_format: savepath_pdf = os.path.join(out_dir, name + '_' + datestring_file + '.pdf') fig1.savefig(savepath_pdf, dpi=dpi) logging.debug('Mask static plot saved to ' + savepath_pdf) plt.close() plt.clf() def plot_mask_cell_individual_static(cell_i,track, cog, features, mask_total, field_contour, field_filled, axes=None,xlim=None,ylim=None, label_field_contour=None, cmap_field_contour='Blues',norm_field_contour=None, linewidths_contour=0.8,contour_labels=False, vmin_field_contour=0,vmax_field_contour=50,levels_field_contour=None,nlevels_field_contour=10, label_field_filled=None,cmap_field_filled='summer',norm_field_filled=None, vmin_field_filled=0,vmax_field_filled=100,levels_field_filled=None,nlevels_field_filled=10, title=None,feature_number=False ): '''Make plots for cell in fixed frame and with one background field as filling and one background field as contrours Input: Output: ''' import numpy as np from .utils import mask_features,mask_features_surface from mpl_toolkits.axes_grid1 import make_axes_locatable from matplotlib.colors import Normalize divider = make_axes_locatable(axes) if field_filled is not None: if levels_field_filled is None: levels_field_filled=np.linspace(vmin_field_filled,vmax_field_filled, 10) plot_field_filled = axes.contourf(field_filled.coord('projection_x_coordinate').points/1000, field_filled.coord('projection_y_coordinate').points/1000, field_filled.data, levels=levels_field_filled, norm=norm_field_filled, cmap=cmap_field_filled, vmin=vmin_field_filled, vmax=vmax_field_filled) cax_filled = divider.append_axes("right", size="5%", pad=0.1) norm_filled= Normalize(vmin=vmin_field_filled, vmax=vmax_field_filled) sm1= plt.cm.ScalarMappable(norm=norm_filled, cmap = plot_field_filled.cmap) sm1.set_array([]) cbar_field_filled = plt.colorbar(sm1, orientation='vertical',cax=cax_filled) cbar_field_filled.ax.set_ylabel(label_field_filled) cbar_field_filled.set_clim(vmin_field_filled, vmax_field_filled) if field_contour is not None: if levels_field_contour is None: levels_field_contour=np.linspace(vmin_field_contour, vmax_field_contour, 5) plot_field_contour = axes.contour(field_contour.coord('projection_x_coordinate').points/1000, field_contour.coord('projection_y_coordinate').points/1000, field_contour.data, cmap=cmap_field_contour,norm=norm_field_contour, levels=levels_field_contour,vmin=vmin_field_contour, vmax=vmax_field_contour, linewidths=linewidths_contour) if contour_labels: axes.clabel(plot_field_contour, fontsize=10) cax_contour = divider.append_axes("bottom", size="5%", pad=0.1) if norm_field_contour: vmin_field_contour=None vmax_field_contour=None norm_contour=norm_field_contour else: norm_contour= Normalize(vmin=vmin_field_contour, vmax=vmax_field_contour) sm_contour= plt.cm.ScalarMappable(norm=norm_contour, cmap = plot_field_contour.cmap) sm_contour.set_array([]) cbar_field_contour = plt.colorbar(sm_contour, orientation='horizontal',ticks=levels_field_contour,cax=cax_contour) cbar_field_contour.ax.set_xlabel(label_field_contour) cbar_field_contour.set_clim(vmin_field_contour, vmax_field_contour) for i_row, row in track.iterrows(): cell = row['cell'] feature = row['feature'] # logging.debug("cell: "+ str(row['cell'])) # logging.debug("feature: "+ str(row['feature'])) if cell==cell_i: color='darkred' if feature_number: cell_string=' '+str(int(cell))+' ('+str(int(feature))+')' else: cell_string=' '+str(int(cell)) elif np.isnan(cell): color='gray' if feature_number: cell_string=' '+'('+str(int(feature))+')' else: cell_string=' ' else: color='darkorange' if feature_number: cell_string=' '+str(int(cell))+' ('+str(int(feature))+')' else: cell_string=' '+str(int(cell)) axes.text(row['projection_x_coordinate']/1000, row['projection_y_coordinate']/1000, cell_string,color=color,fontsize=6, clip_on=True) # Plot marker for tracked cell centre as a cross axes.plot(row['projection_x_coordinate']/1000, row['projection_y_coordinate']/1000, 'x', color=color,markersize=4) #Create surface projection of mask for the respective cell and plot it in the right color z_coord = 'model_level_number' if len(mask_total.shape)==3: mask_total_i_surface = mask_features_surface(mask_total, feature, masked=False, z_coord=z_coord) elif len(mask_total.shape)==2: mask_total_i_surface=mask_features(mask_total, feature, masked=False, z_coord=z_coord) axes.contour(mask_total_i_surface.coord('projection_x_coordinate').points/1000, mask_total_i_surface.coord('projection_y_coordinate').points/1000, mask_total_i_surface.data, levels=[0, feature], colors=color, linestyles=':',linewidth=1) if cog is not None: for i_row, row in cog.iterrows(): cell = row['cell'] if cell==cell_i: color='darkred' else: color='darkorange' # plot marker for centre of gravity as a circle axes.plot(row['x_M']/1000, row['y_M']/1000, 'o', markeredgecolor=color, markerfacecolor='None',markersize=4) if features is not None: for i_row, row in features.iterrows(): color='purple' axes.plot(row['projection_x_coordinate']/1000, row['projection_y_coordinate']/1000, '+', color=color,markersize=3) axes.set_xlabel('x (km)') axes.set_ylabel('y (km)') axes.set_xlim(xlim) axes.set_ylim(ylim) axes.xaxis.set_label_position('top') axes.xaxis.set_ticks_position('top') axes.set_title(title,pad=35,fontsize=10,horizontalalignment='left',loc='left') return axes def plot_mask_cell_track_2D3Dstatic(cell,track, cog, features, mask_total, field_contour, field_filled, width=10000,n_extend=1, name= 'test', plotdir='./', file_format=['png'],figsize=(10/2.54, 10/2.54),dpi=300, ele=10,azim=30, **kwargs): '''Make plots for all cells with fixed frame including entire development of the cell and with one background field as filling and one background field as contrours Input: Output: ''' from iris import Constraint from numpy import unique import os from mpl_toolkits.mplot3d import Axes3D import matplotlib.gridspec as gridspec track_cell=track[track['cell']==cell] x_min=track_cell['projection_x_coordinate'].min()-width x_max=track_cell['projection_x_coordinate'].max()+width y_min=track_cell['projection_y_coordinate'].min()-width y_max=track_cell['projection_y_coordinate'].max()+width #set up looping over time based on mask's time coordinate to allow for one timestep before and after the track time_coord=mask_total.coord('time') time=time_coord.units.num2date(time_coord.points) i_start=max(0,np.where(time==track_cell['time'].values[0])[0][0]-n_extend) i_end=min(len(time)-1,np.where(time==track_cell['time'].values[-1])[0][0]+n_extend+1) time_cell=time[slice(i_start,i_end)] for time_i in time_cell: # for i_row,row in track_cell.iterrows(): # time_i=row['time'] # constraint_time = Constraint(time=row['time']) constraint_time = Constraint(time=time_i) constraint_x = Constraint(projection_x_coordinate = lambda cell: x_min < cell < x_max) constraint_y = Constraint(projection_y_coordinate = lambda cell: y_min < cell < y_max) constraint = constraint_time & constraint_x & constraint_y mask_total_i=mask_total.extract(constraint) if field_contour is None: field_contour_i=None else: field_contour_i=field_contour.extract(constraint) if field_filled is None: field_filled_i=None else: field_filled_i=field_filled.extract(constraint) track_i=track[track['time']==time_i] cells_mask=list(unique(mask_total_i.core_data())) track_cells=track_i.loc[(track_i['projection_x_coordinate'] > x_min) & (track_i['projection_x_coordinate'] < x_max) & (track_i['projection_y_coordinate'] > y_min) & (track_i['projection_y_coordinate'] < y_max)] cells_track=list(track_cells['cell'].values) cells=list(set( cells_mask + cells_track )) if cell not in cells: cells.append(cell) if 0 in cells: cells.remove(0) track_i=track_i[track_i['cell'].isin(cells)] if cog is None: cog_i=None else: cog_i=cog[cog['cell'].isin(cells)] cog_i=cog_i[cog_i['time']==time_i] if features is None: features_i=None else: features_i=features[features['time']==time_i] fig1=plt.figure(figsize=(20 / 2.54, 10 / 2.54)) fig1.subplots_adjust(left=0.1, bottom=0.15, right=0.9, top=0.9,wspace=0.3, hspace=0.25) # make two subplots for figure: gs1 = gridspec.GridSpec(1, 2,width_ratios=[1,1.2]) fig1.add_subplot(gs1[0]) fig1.add_subplot(gs1[1], projection='3d') ax1 = fig1.get_axes() datestring_stamp = time_i.strftime('%Y-%m-%d %H:%M:%S') if time_i in track_cell['time'].values: time_cell_i=track_cell[track_cell['time'].values==time_i]['time_cell'] celltime_stamp = "%02d:%02d:%02d" % (time_cell_i.dt.total_seconds() // 3600, (time_cell_i.dt.total_seconds() % 3600) // 60, time_cell_i.dt.total_seconds() % 60 ) else: celltime_stamp=' - ' title=datestring_stamp + ' , ' + celltime_stamp datestring_file = time_i.strftime('%Y-%m-%d_%H%M%S') ax1[0]=plot_mask_cell_individual_static(cell_i=cell, track=track_i, cog=cog_i,features=features_i, mask_total=mask_total_i, field_contour=field_contour_i, field_filled=field_filled_i, xlim=[x_min/1000,x_max/1000],ylim=[y_min/1000,y_max/1000], axes=ax1[0],title=title,**kwargs) ax1[1]=plot_mask_cell_individual_3Dstatic(cell_i=cell, track=track_i, cog=cog_i,features=features_i, mask_total=mask_total_i, field_contour=field_contour_i, field_filled=field_filled_i, xlim=[x_min/1000,x_max/1000],ylim=[y_min/1000,y_max/1000], axes=ax1[1],title=title, ele=ele,azim=azim, **kwargs) out_dir = os.path.join(plotdir, name) os.makedirs(out_dir, exist_ok=True) if 'png' in file_format: savepath_png = os.path.join(out_dir, name + '_' + datestring_file + '.png') fig1.savefig(savepath_png, dpi=dpi) logging.debug('Mask static 2d/3D plot saved to ' + savepath_png) if 'pdf' in file_format: savepath_pdf = os.path.join(out_dir, name + '_' + datestring_file + '.pdf') fig1.savefig(savepath_pdf, dpi=dpi) logging.debug('Mask static 2d/3D plot saved to ' + savepath_pdf) plt.close() plt.clf() def plot_mask_cell_track_3Dstatic(cell,track, cog, features, mask_total, field_contour, field_filled, width=10000,n_extend=1, name= 'test', plotdir='./', file_format=['png'],figsize=(10/2.54, 10/2.54),dpi=300, **kwargs): '''Make plots for all cells with fixed frame including entire development of the cell and with one background field as filling and one background field as contrours Input: Output: ''' from iris import Constraint from numpy import unique import os from mpl_toolkits.mplot3d import Axes3D track_cell=track[track['cell']==cell] x_min=track_cell['projection_x_coordinate'].min()-width x_max=track_cell['projection_x_coordinate'].max()+width y_min=track_cell['projection_y_coordinate'].min()-width y_max=track_cell['projection_y_coordinate'].max()+width #set up looping over time based on mask's time coordinate to allow for one timestep before and after the track time_coord=mask_total.coord('time') time=time_coord.units.num2date(time_coord.points) i_start=max(0,np.where(time==track_cell['time'].values[0])[0][0]-n_extend) i_end=min(len(time)-1,np.where(time==track_cell['time'].values[-1])[0][0]+n_extend+1) time_cell=time[slice(i_start,i_end)] for time_i in time_cell: # for i_row,row in track_cell.iterrows(): # time_i=row['time'] # constraint_time = Constraint(time=row['time']) constraint_time = Constraint(time=time_i) constraint_x = Constraint(projection_x_coordinate = lambda cell: x_min < cell < x_max) constraint_y = Constraint(projection_y_coordinate = lambda cell: y_min < cell < y_max) constraint = constraint_time & constraint_x & constraint_y mask_total_i=mask_total.extract(constraint) if field_contour is None: field_contour_i=None else: field_contour_i=field_contour.extract(constraint) if field_filled is None: field_filled_i=None else: field_filled_i=field_filled.extract(constraint) track_i=track[track['time']==time_i] cells_mask=list(unique(mask_total_i.core_data())) track_cells=track_i.loc[(track_i['projection_x_coordinate'] > x_min) & (track_i['projection_x_coordinate'] < x_max) & (track_i['projection_y_coordinate'] > y_min) & (track_i['projection_y_coordinate'] < y_max)] cells_track=list(track_cells['cell'].values) cells=list(set( cells_mask + cells_track )) if cell not in cells: cells.append(cell) if 0 in cells: cells.remove(0) track_i=track_i[track_i['cell'].isin(cells)] if cog is None: cog_i=None else: cog_i=cog[cog['cell'].isin(cells)] cog_i=cog_i[cog_i['time']==time_i] if features is None: features_i=None else: features_i=features[features['time']==time_i] # fig1, ax1 = plt.subplots(ncols=1, nrows=1, figsize=figsize) # fig1.subplots_adjust(left=0.2, bottom=0.15, right=0.80, top=0.85) fig1, ax1 = plt.subplots(ncols=1, nrows=1, figsize=(10/2.54, 10/2.54), subplot_kw={'projection': '3d'}) datestring_stamp = time_i.strftime('%Y-%m-%d %H:%M:%S') if time_i in track_cell['time'].values: time_cell_i=track_cell[track_cell['time'].values==time_i]['time_cell'] celltime_stamp = "%02d:%02d:%02d" % (time_cell_i.dt.total_seconds() // 3600, (time_cell_i.dt.total_seconds() % 3600) // 60, time_cell_i.dt.total_seconds() % 60 ) else: celltime_stamp=' - ' title=datestring_stamp + ' , ' + celltime_stamp datestring_file = time_i.strftime('%Y-%m-%d_%H%M%S') ax1=plot_mask_cell_individual_3Dstatic(cell_i=cell, track=track_i, cog=cog_i,features=features_i, mask_total=mask_total_i, field_contour=field_contour_i, field_filled=field_filled_i, xlim=[x_min/1000,x_max/1000],ylim=[y_min/1000,y_max/1000], axes=ax1,title=title,**kwargs) out_dir = os.path.join(plotdir, name) os.makedirs(out_dir, exist_ok=True) if 'png' in file_format: savepath_png = os.path.join(out_dir, name + '_' + datestring_file + '.png') fig1.savefig(savepath_png, dpi=dpi) logging.debug('Mask static plot saved to ' + savepath_png) if 'pdf' in file_format: savepath_pdf = os.path.join(out_dir, name + '_' + datestring_file + '.pdf') fig1.savefig(savepath_pdf, dpi=dpi) logging.debug('Mask static plot saved to ' + savepath_pdf) plt.close() plt.clf() def plot_mask_cell_individual_3Dstatic(cell_i,track, cog, features, mask_total, field_contour, field_filled, axes=None,xlim=None,ylim=None, label_field_contour=None, cmap_field_contour='Blues',norm_field_contour=None, linewidths_contour=0.8,contour_labels=False, vmin_field_contour=0,vmax_field_contour=50,levels_field_contour=None,nlevels_field_contour=10, label_field_filled=None,cmap_field_filled='summer',norm_field_filled=None, vmin_field_filled=0,vmax_field_filled=100,levels_field_filled=None,nlevels_field_filled=10, title=None,feature_number=False, ele=10.,azim=210. ): '''Make plots for cell in fixed frame and with one background field as filling and one background field as contrours Input: Output: ''' import numpy as np from .utils import mask_features,mask_features_surface # from mpl_toolkits.axes_grid1 import make_axes_locatable # from matplotlib.colors import Normalize from mpl_toolkits.mplot3d import Axes3D axes.view_init(elev=ele, azim=azim) axes.grid(b=False) axes.set_frame_on(False) # make the panes transparent axes.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) axes.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) axes.zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) # make the grid lines transparent axes.xaxis._axinfo["grid"]['color'] = (1,1,1,0) axes.yaxis._axinfo["grid"]['color'] = (1,1,1,0) axes.zaxis._axinfo["grid"]['color'] = (1,1,1,0) if title is not None: axes.set_title(title,horizontalalignment='left',loc='left') # colors_mask = ['pink','darkred', 'orange', 'darkred', 'red', 'darkorange'] x = mask_total.coord('projection_x_coordinate').points y = mask_total.coord('projection_y_coordinate').points z = mask_total.coord('model_level_number').points # z = mask_total.coord('geopotential_height').points zz, yy, xx = np.meshgrid(z, y, x, indexing='ij') # z_alt = mask_total.coord('geopotential_height').points # divider = make_axes_locatable(axes) # if field_filled is not None: # if levels_field_filled is None: # levels_field_filled=np.linspace(vmin_field_filled,vmax_field_filled, 10) # plot_field_filled = axes.contourf(field_filled.coord('projection_x_coordinate').points/1000, # field_filled.coord('projection_y_coordinate').points/1000, # field_filled.data, # levels=levels_field_filled, norm=norm_field_filled, # cmap=cmap_field_filled, vmin=vmin_field_filled, vmax=vmax_field_filled) # cax_filled = divider.append_axes("right", size="5%", pad=0.1) # norm_filled= Normalize(vmin=vmin_field_filled, vmax=vmax_field_filled) # sm1= plt.cm.ScalarMappable(norm=norm_filled, cmap = plot_field_filled.cmap) # sm1.set_array([]) # cbar_field_filled = plt.colorbar(sm1, orientation='vertical',cax=cax_filled) # cbar_field_filled.ax.set_ylabel(label_field_filled) # cbar_field_filled.set_clim(vmin_field_filled, vmax_field_filled) # if field_contour is not None: # if levels_field_contour is None: # levels_field_contour=np.linspace(vmin_field_contour, vmax_field_contour, 5) # plot_field_contour = axes.contour(field_contour.coord('projection_x_coordinate').points/1000, # field_contour.coord('projection_y_coordinate').points/1000, # field_contour.data, # cmap=cmap_field_contour,norm=norm_field_contour, # levels=levels_field_contour,vmin=vmin_field_contour, vmax=vmax_field_contour, # linewidths=linewidths_contour) # if contour_labels: # axes.clabel(plot_field_contour, fontsize=10) # cax_contour = divider.append_axes("bottom", size="5%", pad=0.1) # if norm_field_contour: # vmin_field_contour=None # vmax_field_contour=None # norm_contour=norm_field_contour # else: # norm_contour= Normalize(vmin=vmin_field_contour, vmax=vmax_field_contour) # # sm_contour= plt.cm.ScalarMappable(norm=norm_contour, cmap = plot_field_contour.cmap) # sm_contour.set_array([]) # # cbar_field_contour = plt.colorbar(sm_contour, orientation='horizontal',ticks=levels_field_contour,cax=cax_contour) # cbar_field_contour.ax.set_xlabel(label_field_contour) # cbar_field_contour.set_clim(vmin_field_contour, vmax_field_contour) # for i_row, row in track.iterrows(): cell = row['cell'] feature = row['feature'] # logging.debug("cell: "+ str(row['cell'])) # logging.debug("feature: "+ str(row['feature'])) if cell==cell_i: color='darkred' if feature_number: cell_string=' '+str(int(cell))+' ('+str(int(feature))+')' else: cell_string=' '+str(int(cell)) elif np.isnan(cell): color='gray' if feature_number: cell_string=' '+'('+str(int(feature))+')' else: cell_string=' ' else: color='darkorange' if feature_number: cell_string=' '+str(int(cell))+' ('+str(int(feature))+')' else: cell_string=' '+str(int(cell)) # axes.text(row['projection_x_coordinate']/1000, # row['projection_y_coordinate']/1000, # 0, # cell_string,color=color,fontsize=6, clip_on=True) # # Plot marker for tracked cell centre as a cross # axes.plot(row['projection_x_coordinate']/1000, # row['projection_y_coordinate']/1000, # 0, # 'x', color=color,markersize=4) #Create surface projection of mask for the respective cell and plot it in the right color # z_coord = 'model_level_number' # if len(mask_total.shape)==3: # mask_total_i_surface = mask_features_surface(mask_total, feature, masked=False, z_coord=z_coord) # elif len(mask_total.shape)==2: # mask_total_i_surface=mask_features(mask_total, feature, masked=False, z_coord=z_coord) # axes.contour(mask_total_i_surface.coord('projection_x_coordinate').points/1000, # mask_total_i_surface.coord('projection_y_coordinate').points/1000, # 0, # mask_total_i_surface.data, # levels=[0, feature], colors=color, linestyles=':',linewidth=1) mask_feature = mask_total.data == feature axes.scatter( # xx[mask_feature]/1000, yy[mask_feature]/1000, zz[mask_feature]/1000, xx[mask_feature]/1000, yy[mask_feature]/1000, zz[mask_feature], c=color, marker=',', s=5,#60000.0 * TWC_i[Mask_particle], alpha=0.3, cmap='inferno', label=cell_string,rasterized=True) axes.set_xlim(xlim) axes.set_ylim(ylim) axes.set_zlim([0, 100]) # axes.set_zlim([0, 20]) # axes.set_zticks([0, 5,10,15, 20]) axes.set_xlabel('x (km)') axes.set_ylabel('y (km)') axes.zaxis.set_rotate_label(False) # disable automatic rotation # axes.set_zlabel('z (km)', rotation=90) axes.set_zlabel('model level', rotation=90) return axes def plot_mask_cell_track_static_timeseries(cell,track, cog, features, mask_total, field_contour, field_filled, track_variable=None,variable=None,variable_ylabel=None,variable_label=[None],variable_legend=False,variable_color=None, width=10000,n_extend=1, name= 'test', plotdir='./', file_format=['png'],figsize=(20/2.54, 10/2.54),dpi=300, **kwargs): '''Make plots for all cells with fixed frame including entire development of the cell and with one background field as filling and one background field as contrours Input: Output: ''' '''Make plots for all cells with fixed frame including entire development of the cell and with one background field as filling and one background field as contrours Input: Output: ''' from iris import Constraint from numpy import unique import os import pandas as pd track_cell=track[track['cell']==cell] x_min=track_cell['projection_x_coordinate'].min()-width x_max=track_cell['projection_x_coordinate'].max()+width y_min=track_cell['projection_y_coordinate'].min()-width y_max=track_cell['projection_y_coordinate'].max()+width time_min=track_cell['time'].min() # time_max=track_cell['time'].max() track_variable_cell=track_variable[track_variable['cell']==cell] track_variable_cell['time_cell']=pd.to_timedelta(track_variable_cell['time_cell']) # track_variable_cell=track_variable_cell[(track_variable_cell['time']>=time_min) & (track_variable_cell['time']<=time_max)] #set up looping over time based on mask's time coordinate to allow for one timestep before and after the track time_coord=mask_total.coord('time') time=time_coord.units.num2date(time_coord.points) i_start=max(0,np.where(time==track_cell['time'].values[0])[0][0]-n_extend) i_end=min(len(time)-1,np.where(time==track_cell['time'].values[-1])[0][0]+n_extend+1) time_cell=time[slice(i_start,i_end)] for time_i in time_cell: constraint_time = Constraint(time=time_i) constraint_x = Constraint(projection_x_coordinate = lambda cell: x_min < cell < x_max) constraint_y = Constraint(projection_y_coordinate = lambda cell: y_min < cell < y_max) constraint = constraint_time & constraint_x & constraint_y mask_total_i=mask_total.extract(constraint) if field_contour is None: field_contour_i=None else: field_contour_i=field_contour.extract(constraint) if field_filled is None: field_filled_i=None else: field_filled_i=field_filled.extract(constraint) track_i=track[track['time']==time_i] cells_mask=list(unique(mask_total_i.core_data())) track_cells=track_i.loc[(track_i['projection_x_coordinate'] > x_min) & (track_i['projection_x_coordinate'] < x_max) & (track_i['projection_y_coordinate'] > y_min) & (track_i['projection_y_coordinate'] < y_max)] cells_track=list(track_cells['cell'].values) cells=list(set( cells_mask + cells_track )) if cell not in cells: cells.append(cell) if 0 in cells: cells.remove(0) track_i=track_i[track_i['cell'].isin(cells)] if cog is None: cog_i=None else: cog_i=cog[cog['cell'].isin(cells)] cog_i=cog_i[cog_i['time']==time_i] if features is None: features_i=None else: features_i=features[features['time']==time_i] fig1, ax1 = plt.subplots(ncols=2, nrows=1, figsize=figsize) fig1.subplots_adjust(left=0.1, bottom=0.15, right=0.90, top=0.85,wspace=0.3) datestring_stamp = time_i.strftime('%Y-%m-%d %H:%M:%S') if time_i in track_cell['time'].values: time_cell_i=track_cell[track_cell['time'].values==time_i]['time_cell'] celltime_stamp = "%02d:%02d:%02d" % (time_cell_i.dt.total_seconds() // 3600, (time_cell_i.dt.total_seconds() % 3600) // 60, time_cell_i.dt.total_seconds() % 60 ) else: celltime_stamp=' - ' title=celltime_stamp + ' , ' + datestring_stamp datestring_file = time_i.strftime('%Y-%m-%d_%H%M%S') # plot evolving timeseries of variable to second axis: ax1[0]=plot_mask_cell_individual_static(cell_i=cell, track=track_i, cog=cog_i,features=features_i, mask_total=mask_total_i, field_contour=field_contour_i, field_filled=field_filled_i, xlim=[x_min/1000,x_max/1000],ylim=[y_min/1000,y_max/1000], axes=ax1[0],title=title,**kwargs) track_variable_past=track_variable_cell[(track_variable_cell['time']>=time_min) & (track_variable_cell['time']<=time_i)] track_variable_current=track_variable_cell[track_variable_cell['time']==time_i] if variable_color is None: variable_color='navy' if type(variable) is str: # logging.debug('variable: '+str(variable)) if type(variable_color) is str: variable_color={variable:variable_color} variable=[variable] for i_variable,variable_i in enumerate(variable): color=variable_color[variable_i] ax1[1].plot(track_variable_past['time_cell'].dt.total_seconds()/ 60.,track_variable_past[variable_i].values,color=color,linestyle='-',label=variable_label[i_variable]) ax1[1].plot(track_variable_current['time_cell'].dt.total_seconds()/ 60.,track_variable_current[variable_i].values,color=color,marker='o',markersize=4,fillstyle='full') ax1[1].yaxis.tick_right() ax1[1].yaxis.set_label_position("right") ax1[1].set_xlim([0,2*60]) ax1[1].set_xticks(np.arange(0,120,15)) ax1[1].set_ylim([0,max(10,1.25*track_variable_cell[variable].max().max())]) ax1[1].set_xlabel('cell lifetime (min)') if variable_ylabel==None: variable_ylabel=variable ax1[1].set_ylabel(variable_ylabel) ax1[1].set_title(title) # insert legend, if flag is True if variable_legend: if (len(variable_label)<5): ncol=1 else: ncol=2 ax1[1].legend(loc='upper right', bbox_to_anchor=(1, 1),ncol=ncol,fontsize=8) out_dir = os.path.join(plotdir, name) os.makedirs(out_dir, exist_ok=True) if 'png' in file_format: savepath_png = os.path.join(out_dir, name + '_' + datestring_file + '.png') fig1.savefig(savepath_png, dpi=dpi) logging.debug('Mask static plot saved to ' + savepath_png) if 'pdf' in file_format: savepath_pdf = os.path.join(out_dir, name + '_' + datestring_file + '.pdf') fig1.savefig(savepath_pdf, dpi=dpi) logging.debug('Mask static plot saved to ' + savepath_pdf) plt.close() plt.clf()
[ 11748, 2603, 29487, 8019, 355, 285, 489, 198, 76, 489, 13, 1904, 10786, 46384, 11537, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 11748, 18931, 198, 6738, 764, 20930, 1330, 10869, 62, 10034, 21857, 198, 6738, 764,...
1.955499
24,651
from sanic import Blueprint from sanic_transmute import add_route from .views import ( get_all, get_status_by_country_id, get_status_by_country_name, get_deaths, get_active_cases, get_recovered_cases, get_confirmed_cases, list_countries, ) cases = Blueprint("cases", url_prefix="/cases") add_route(cases, get_all) add_route(cases, get_status_by_country_id) add_route(cases, get_status_by_country_name) add_route(cases, get_deaths) add_route(cases, get_active_cases) add_route(cases, get_recovered_cases) add_route(cases, get_confirmed_cases) add_route(cases, list_countries)
[ 6738, 5336, 291, 1330, 39932, 198, 6738, 5336, 291, 62, 7645, 76, 1133, 1330, 751, 62, 38629, 198, 6738, 764, 33571, 1330, 357, 198, 220, 220, 220, 651, 62, 439, 11, 198, 220, 220, 220, 651, 62, 13376, 62, 1525, 62, 19315, 62, 312...
2.598291
234
from ..downloader import Downloader import os import pytest
[ 6738, 11485, 15002, 263, 1330, 10472, 263, 198, 11748, 28686, 198, 198, 11748, 12972, 9288, 628, 628, 628, 198 ]
3.526316
19
# Generated by Django 3.2.4 on 2021-06-19 16:10 from django.db import migrations, models import django.utils.timezone
[ 2, 2980, 515, 416, 37770, 513, 13, 17, 13, 19, 319, 33448, 12, 3312, 12, 1129, 1467, 25, 940, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 198, 11748, 42625, 14208, 13, 26791, 13, 2435, 11340, 628 ]
2.926829
41
import copy import json from .dataset_info import DatasetInfoFactory
[ 11748, 4866, 198, 11748, 33918, 198, 6738, 764, 19608, 292, 316, 62, 10951, 1330, 16092, 292, 316, 12360, 22810, 628 ]
3.5
20
# -*- coding:utf-8 -*- # edit by fuzongfei import base64 import datetime # Create your views here. import json from django.http import Http404, HttpResponse from django.utils import timezone from django_filters.rest_framework import DjangoFilterBackend from rest_framework import filters from rest_framework.exceptions import PermissionDenied from rest_framework.generics import ListAPIView, GenericAPIView, CreateAPIView, UpdateAPIView, DestroyAPIView from rest_framework.views import APIView from rest_framework.viewsets import ViewSet from libs import permissions from libs.Pagination import Pagination from libs.RenderColumns import render_dynamic_columns from libs.response import JsonResponseV1 from sqlorders import models, serializers from sqlorders.filters import SqlOrderListFilter, GetTasksListFilter
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 2, 4370, 416, 277, 10277, 506, 5036, 72, 198, 11748, 2779, 2414, 198, 11748, 4818, 8079, 198, 2, 13610, 534, 5009, 994, 13, 198, 11748, 33918, 198, 198, 6738, 42625, 14208,...
3.4875
240
import glove_util as gut import numpy as np from sklearn.decomposition import TruncatedSVD import json with open('freq_count_pred.json') as f: freq_count_pred = json.load(f) with open('relationships.json') as f: relationships = json.load(f) predicate_embedding = {} sentences = [] i = 0 for image in relationships: i+=1 if i%1000 == 0: print (i) for relation in image['relationships']: w_avg = weighted_avg(relation['predicate'],0.001,300) sentences.append(w_avg) predicate_embedding[relation['relationship_id']] = w_avg pc = get_pc(np.array(sentences))[0] projection_space = np.outer(pc,pc) i = 0 for image in relationships: i+=1 if i%1000 == 0: print (i) for relation in image['relationships']: predicate_embedding[relation['relationship_id']] = predicate_embedding[relation['relationship_id']] - np.matmul(projection_space,predicate_embedding[relation['relationship_id']]) with open('predicate_embedding_300.json','w') as f: json.dump(predicate_embedding,f)
[ 11748, 29144, 62, 22602, 355, 12500, 220, 198, 11748, 299, 32152, 355, 45941, 220, 198, 6738, 1341, 35720, 13, 12501, 296, 9150, 1330, 833, 19524, 515, 50, 8898, 198, 11748, 33918, 198, 198, 4480, 1280, 10786, 19503, 80, 62, 9127, 62, ...
2.643799
379
# Importing Fernet class from cryptography.fernet import Fernet # Importing dump and load function from pickle import dump,load # To generate a strong pw # To get master pw from the file # To get key from the file # To store master pw in the file # Checking if user is running program for first time # Function to copy pw to clipboard # Encrypting the text # Decrypting the text
[ 2, 17267, 278, 38982, 316, 1398, 201, 198, 6738, 45898, 13, 69, 1142, 316, 1330, 38982, 316, 201, 198, 2, 17267, 278, 10285, 290, 3440, 2163, 201, 198, 6738, 2298, 293, 1330, 10285, 11, 2220, 201, 198, 201, 198, 2, 1675, 7716, 257, ...
3.123077
130
# -*- encoding=utf-8 -*- """ # ********************************************************************************** # Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. # [oecp] is licensed under the Mulan PSL v1. # You can use this software according to the terms and conditions of the Mulan PSL v1. # You may obtain a copy of Mulan PSL v1 at: # http://license.coscl.org.cn/MulanPSL # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR # PURPOSE. # See the Mulan PSL v1 for more details. # ********************************************************************************** """ from oecp.executor.base import CompareExecutor
[ 2, 532, 9, 12, 21004, 28, 40477, 12, 23, 532, 9, 12, 198, 37811, 198, 2, 41906, 17174, 8412, 1174, 198, 2, 15069, 357, 66, 8, 43208, 21852, 1766, 1539, 12052, 13, 12131, 12, 42334, 13, 1439, 2489, 10395, 13, 198, 2, 685, 78, 721...
3.578475
223
from django.db import models from django.utils import timezone # Course Category # Course Subcategory # Course # Course resources
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 6738, 42625, 14208, 13, 26791, 1330, 640, 11340, 198, 198, 2, 20537, 21743, 198, 220, 198, 2, 20537, 3834, 22872, 198, 198, 2, 20537, 198, 198, 2, 20537, 4133, 198 ]
3.552632
38
# 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 logging import traceback from yapsy.IPlugin import IPlugin from activitystreams.models.activity import Activity from dino import utils from dino.config import ErrorCodes from dino.config import ConfigKeys from dino.environ import GNEnvironment logger = logging.getLogger(__name__) __author__ = 'Oscar Eriksson <oscar.eriks@gmail.com>'
[ 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198, 2, 921, 743, 7330, 257, 4866, 286, 262, 13789, 379, 198, 2,...
3.665289
242
#!/usr/bin/env python # Script for parsing prometheus metrics format and send it into zabbix server # MIT License # https://github.com/Friz-zy/telegraf-monitoring-agent-setup import re import os import sys import time import json import socket import optparse try: from urllib.request import urlopen except: from urllib import urlopen METRICS = { 'default': { 'sort_labels': ['name', 'id', 'host', 'path', 'device', 'source', 'cpu'], }, 'docker_container_': { 'sort_labels': ['host', 'source', 'device', 'cpu'], }, } if __name__ == "__main__": main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 2, 12327, 329, 32096, 1552, 36916, 20731, 5794, 290, 3758, 340, 656, 1976, 6485, 844, 4382, 198, 2, 17168, 13789, 198, 2, 3740, 1378, 12567, 13, 785, 14, 30214, 89, 12, 7357, 14...
2.77619
210
# CompOFA Compound Once-For-All Networks for Faster Multi-Platform Deployment # Under blind review at ICLR 2021: https://openreview.net/forum?id=IgIk8RRT-Z # # Implementation based on: # Once for All: Train One Network and Specialize it for Efficient Deployment # Han Cai, Chuang Gan, Tianzhe Wang, Zhekai Zhang, Song Han # International Conference on Learning Representations (ICLR), 2020. import os import sys import torch import time import math import copy import random import argparse import torch.nn as nn import numpy as np import pandas as pd from torchvision import transforms, datasets from matplotlib import pyplot as plt sys.path.append("..") from ofa.model_zoo import ofa_net from ofa.utils import download_url from accuracy_predictor import AccuracyPredictor from flops_table import FLOPsTable from latency_table import LatencyTable from evolution_finder import EvolutionFinder from imagenet_eval_helper import evaluate_ofa_subnet, evaluate_ofa_specialized parser = argparse.ArgumentParser() parser.add_argument( '-n', '--net', metavar='OFANET', help='OFA network', required=True) parser.add_argument( '-t', '--target-hardware', metavar='TARGET_HARDWARE', help='Target Hardware', required=True) parser.add_argument( '--imagenet-path', metavar='IMAGENET_PATH', help='The path of ImageNet', type=str, required=True) args = parser.parse_args() arch = {'compofa' : ('compofa', 'model_best_compofa_simple.pth.tar'), 'compofa-elastic' : ('compofa-elastic', 'model_best_compofa_simple_elastic.pth.tar'), 'ofa_mbv3_d234_e346_k357_w1.0' : ('ofa', 'ofa_mbv3_d234_e346_k357_w1.0'), } hardware_latency = {'note10' : [15, 20, 25, 30], 'gpu' : [15, 25, 35, 45], 'cpu' : [12, 15, 18, 21]} MODEL_DIR = '../ofa/checkpoints/%s' % (arch[args.net][1]) imagenet_data_path = args.imagenet_path # imagenet_data_path = '/srv/data/datasets/ImageNet/' # set random seed random_seed = 3 random.seed(random_seed) np.random.seed(random_seed) torch.manual_seed(random_seed) print('Successfully imported all packages and configured random seed to %d!'%random_seed) os.environ['CUDA_VISIBLE_DEVICES'] = '0' cuda_available = torch.cuda.is_available() if cuda_available: torch.backends.cudnn.enabled = True torch.backends.cudnn.benchmark = True torch.cuda.manual_seed(random_seed) print('Using GPU.') else: print('Using CPU.') # Initialize the OFA Network ofa_network = ofa_net(args.net, model_dir=MODEL_DIR, pretrained=True) if args.target_hardware == 'cpu': ofa_network = ofa_network.cpu() else: ofa_network = ofa_network.cuda() print('The OFA Network is ready.') # Carry out data transforms if cuda_available: data_loader = torch.utils.data.DataLoader( datasets.ImageFolder( root=os.path.join(imagenet_data_path, 'val'), transform=build_val_transform(224) ), batch_size=250, # test batch size shuffle=True, num_workers=16, # number of workers for the data loader pin_memory=True, drop_last=False, ) print('The ImageNet dataloader is ready.') else: data_loader = None print('Since GPU is not found in the environment, we skip all scripts related to ImageNet evaluation.') # set up the accuracy predictor accuracy_predictor = AccuracyPredictor( pretrained=True, device='cuda:0' if cuda_available else 'cpu' ) print('The accuracy predictor is ready!') print(accuracy_predictor.model) # set up the latency table target_hardware = args.target_hardware use_latency_table = True if target_hardware == 'note10' else False latency_table = LatencyTable(device=target_hardware, use_latency_table=use_latency_table, network=args.net) """ Hyper-parameters for the evolutionary search process You can modify these hyper-parameters to see how they influence the final ImageNet accuracy of the search sub-net. """ latency_constraint = hardware_latency[args.target_hardware][0] # ms P = 100 # The size of population in each generation N = 500 # How many generations of population to be searched r = 0.25 # The ratio of networks that are used as parents for next generation params = { 'constraint_type': target_hardware, # Let's do FLOPs-constrained search 'efficiency_constraint': latency_constraint, 'mutate_prob': 0.1, # The probability of mutation in evolutionary search 'mutation_ratio': 0.5, # The ratio of networks that are generated through mutation in generation n >= 2. 'efficiency_predictor': latency_table, # To use a predefined efficiency predictor. 'accuracy_predictor': accuracy_predictor, # To use a predefined accuracy_predictor predictor. 'population_size': P, 'max_time_budget': N, 'parent_ratio': r, 'arch' : arch[args.net][0], } # initialize the evolution finder and run NAS finder = EvolutionFinder(**params) result_lis = [] for latency in hardware_latency[args.target_hardware]: finder.set_efficiency_constraint(latency) best_valids, best_info = finder.run_evolution_search() result_lis.append(best_info) print("NAS Completed!") # evaluate the searched model on ImageNet models = [] if cuda_available: for result in result_lis: _, net_config, latency = result print('Evaluating the sub-network with latency = %.1f ms on %s' % (latency, target_hardware)) top1 = evaluate_ofa_subnet( ofa_network, imagenet_data_path, net_config, data_loader, batch_size=250, device='cuda:0' if cuda_available else 'cpu') models.append([net_config, top1, latency]) df = pd.DataFrame(models, columns=['Model', 'Accuracy', 'Latency']) df.to_csv('NAS_results.csv') print('NAS results saved to NAS_results.csv')
[ 2, 3082, 46, 7708, 220, 3082, 633, 4874, 12, 1890, 12, 3237, 27862, 329, 38996, 15237, 12, 37148, 34706, 434, 198, 2, 4698, 7770, 2423, 379, 314, 5097, 49, 33448, 25, 3740, 1378, 9654, 19023, 13, 3262, 14, 27302, 30, 312, 28, 40, ...
2.630308
2,237
# coding: utf-8 import pickle # import json # import types path = 'application/model/radar_score_20180117/' if __name__ == '__main__': # README print "This is a program calculating house's 5 scores:" \ "Anti Drop Score," \ "House Appreciation," \ "Possess Cost," \ "Long-term Income" \ "Short-term Income"
[ 2, 19617, 25, 3384, 69, 12, 23, 198, 198, 11748, 2298, 293, 198, 2, 1330, 33918, 198, 2, 1330, 3858, 198, 198, 6978, 796, 705, 31438, 14, 19849, 14, 6335, 283, 62, 26675, 62, 7908, 486, 1558, 14, 6, 628, 220, 220, 198, 198, 361,...
2.428571
147
#!/bin/python3 import math import os import random import re import sys from typing import Counter # # Complete the 'numCells' function below. # # The function is expected to return an INTEGER. # The function accepts 2D_INTEGER_ARRAY grid as parameter. # grid = [[1, 2, 7], [4, 5, 6], [8, 8, 9]] print(numCells(grid)) # if __name__ == '__main__': # fptr = open(os.environ['OUTPUT_PATH'], 'w') # grid_rows = int(input().strip()) # grid_columns = int(input().strip()) # grid = [] # for _ in range(grid_rows): # grid.append(list(map(int, input().rstrip().split()))) # result = numCells(grid) # fptr.write(str(result) + '\n') # fptr.close()
[ 2, 48443, 8800, 14, 29412, 18, 198, 198, 11748, 10688, 198, 11748, 28686, 198, 11748, 4738, 198, 11748, 302, 198, 11748, 25064, 198, 6738, 19720, 1330, 15034, 628, 198, 198, 2, 198, 2, 13248, 262, 705, 22510, 34, 19187, 6, 2163, 2174,...
2.402098
286
from django.conf import settings from django.conf.urls import include, url from django.conf.urls.static import static urlpatterns = [ # Examples: # url(r'^$', 'evetool.views.home', name='home'), url(r'^', include('users.urls')), url(r'^', include('apis.urls')), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
[ 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 10414, 13, 6371, 82, 1330, 2291, 11, 19016, 198, 6738, 42625, 14208, 13, 10414, 13, 6371, 82, 13, 12708, 1330, 9037, 198, 198, 6371, 33279, 82, 796, 685, 198, 220...
2.589552
134
import os # virtualenv SCRIPTDIR = os.path.realpath(os.path.dirname(__file__)) venv_name = '_ck' osdir = 'Scripts' if os.name is 'nt' else 'bin' venv = os.path.join(venv_name, osdir, 'activate_this.py') activate_this = (os.path.join(SCRIPTDIR, venv)) # Python 3: exec(open(...).read()), Python 2: execfile(...) exec(open(activate_this).read(), dict(__file__=activate_this))
[ 11748, 28686, 198, 198, 2, 7166, 24330, 198, 6173, 32618, 21016, 4663, 796, 28686, 13, 6978, 13, 5305, 6978, 7, 418, 13, 6978, 13, 15908, 3672, 7, 834, 7753, 834, 4008, 198, 198, 574, 85, 62, 3672, 796, 705, 62, 694, 6, 198, 418, ...
2.516779
149
#!/usr/bin/env python # Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import json import os import sys import common if __name__ == '__main__': funcs = { 'run': main_run, 'compile_targets': main_compile_targets, } sys.exit(common.run_script(sys.argv[1:], funcs))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 15069, 1853, 383, 18255, 1505, 46665, 13, 1439, 2489, 10395, 13, 198, 2, 5765, 286, 428, 2723, 2438, 318, 21825, 416, 257, 347, 10305, 12, 7635, 5964, 326, 460, 307, 198, 2, 1043,...
2.822695
141
from autoPyTorch.utils.config.config_option import ConfigOption from autoPyTorch.pipeline.base.sub_pipeline_node import SubPipelineNode import traceback
[ 198, 6738, 8295, 20519, 15884, 354, 13, 26791, 13, 11250, 13, 11250, 62, 18076, 1330, 17056, 19722, 198, 6738, 8295, 20519, 15884, 354, 13, 79, 541, 4470, 13, 8692, 13, 7266, 62, 79, 541, 4470, 62, 17440, 1330, 3834, 47, 541, 4470, ...
3.255319
47
import csv import requests import sys """ A simple program to print the result of a Prometheus query as CSV. """ if len(sys.argv) != 3: print('Usage: {0} http://prometheus:9090 a_query'.format(sys.argv[0])) sys.exit(1) response = requests.get('{0}/api/v1/query'.format(sys.argv[1]), params={'query': sys.argv[2]}) results = response.json()['data']['result'] # Build a list of all labelnames used. labelnames = set() for result in results: labelnames.update(result['metric'].keys()) # Canonicalize labelnames.discard('__name__') labelnames = sorted(labelnames) writer = csv.writer(sys.stdout) # Write the header, writer.writerow(['name', 'timestamp', 'value'] + labelnames) # Write the samples. for result in results: l = [result['metric'].get('__name__', '')] + result['value'] for label in labelnames: l.append(result['metric'].get(label, '')) writer.writerow(l)
[ 11748, 269, 21370, 198, 11748, 7007, 198, 11748, 25064, 198, 198, 37811, 198, 32, 2829, 1430, 284, 3601, 262, 1255, 286, 257, 42696, 12405, 355, 44189, 13, 198, 37811, 198, 198, 361, 18896, 7, 17597, 13, 853, 85, 8, 14512, 513, 25, ...
2.677419
341
from rest_framework.test import APITestCase from rest_framework.test import APIRequestFactory import requests import pytest import json from django.core.management import call_command from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed from rest_framework.test import APIClient # Create your tests here. # @pytest.fixture(autouse=True) # def django_db_setup(django_db_setup, django_db_blocker): # signals = [pre_save, post_save, pre_delete, post_delete, m2m_changed] # restore = {} # with django_db_blocker.unblock(): # call_command("loaddata", "test_stuff.json")
[ 6738, 1334, 62, 30604, 13, 9288, 1330, 3486, 2043, 395, 20448, 198, 6738, 1334, 62, 30604, 13, 9288, 1330, 7824, 18453, 22810, 198, 11748, 7007, 198, 11748, 12972, 9288, 198, 11748, 33918, 198, 6738, 42625, 14208, 13, 7295, 13, 27604, 1...
2.831858
226
# 3. Define a function to check whether a number is even print(even(4)) print(even(-5))
[ 198, 2, 513, 13, 2896, 500, 257, 2163, 284, 2198, 1771, 257, 1271, 318, 772, 198, 198, 4798, 7, 10197, 7, 19, 4008, 198, 4798, 7, 10197, 32590, 20, 4008, 198 ]
2.903226
31
""" Posterior for Cauchy Distribution --------------------------------- Figure 5.11 The solid lines show the posterior pdf :math:`p(\mu|{x_i},I)` (top-left panel) and the posterior pdf :math:`p(\gamma|{x_i},I)` (top-right panel) for the two-dimensional pdf from figure 5.10. The dashed lines show the distribution of approximate estimates of :math:`\mu` and :math:`\gamma` based on the median and interquartile range. The bottom panels show the corresponding cumulative distributions. """ # Author: Jake VanderPlas # License: BSD # The figure produced by this code is published in the textbook # "Statistics, Data Mining, and Machine Learning in Astronomy" (2013) # For more information, see http://astroML.github.com # To report a bug or issue, use the following forum: # https://groups.google.com/forum/#!forum/astroml-general import numpy as np from matplotlib import pyplot as plt from scipy.stats import cauchy from astroML.stats import median_sigmaG from astroML.resample import bootstrap #---------------------------------------------------------------------- # This function adjusts matplotlib settings for a uniform feel in the textbook. # Note that with usetex=True, fonts are rendered with LaTeX. This may # result in an error if LaTeX is not installed on your system. In that case, # you can set usetex to False. from astroML.plotting import setup_text_plots setup_text_plots(fontsize=8, usetex=True) def cauchy_logL(x, gamma, mu): """Equation 5.74: cauchy likelihood""" x = np.asarray(x) n = x.size # expand x for broadcasting shape = np.broadcast(gamma, mu).shape x = x.reshape(x.shape + tuple([1 for s in shape])) return ((n - 1) * np.log(gamma) - np.sum(np.log(gamma ** 2 + (x - mu) ** 2), 0)) def estimate_mu_gamma(xi, axis=None): """Equation 3.54: Cauchy point estimates""" q25, q50, q75 = np.percentile(xi, [25, 50, 75], axis=axis) return q50, 0.5 * (q75 - q25) #------------------------------------------------------------ # Draw a random sample from the cauchy distribution, and compute # marginalized posteriors of mu and gamma np.random.seed(44) n = 10 mu_0 = 0 gamma_0 = 2 xi = cauchy(mu_0, gamma_0).rvs(n) gamma = np.linspace(0.01, 5, 70) dgamma = gamma[1] - gamma[0] mu = np.linspace(-3, 3, 70) dmu = mu[1] - mu[0] likelihood = np.exp(cauchy_logL(xi, gamma[:, np.newaxis], mu)) pmu = likelihood.sum(0) pmu /= pmu.sum() * dmu pgamma = likelihood.sum(1) pgamma /= pgamma.sum() * dgamma #------------------------------------------------------------ # bootstrap estimate mu_bins = np.linspace(-3, 3, 21) gamma_bins = np.linspace(0, 5, 17) mu_bootstrap, gamma_bootstrap = bootstrap(xi, 20000, estimate_mu_gamma, kwargs=dict(axis=1), random_state=0) #------------------------------------------------------------ # Plot results fig = plt.figure(figsize=(5, 5)) fig.subplots_adjust(wspace=0.35, right=0.95, hspace=0.2, top=0.95) # first axes: mu posterior ax1 = fig.add_subplot(221) ax1.plot(mu, pmu, '-k') ax1.hist(mu_bootstrap, mu_bins, normed=True, histtype='step', color='b', linestyle='dashed') ax1.set_xlabel(r'$\mu$') ax1.set_ylabel(r'$p(\mu|x,I)$') # second axes: mu cumulative posterior ax2 = fig.add_subplot(223, sharex=ax1) ax2.plot(mu, pmu.cumsum() * dmu, '-k') ax2.hist(mu_bootstrap, mu_bins, normed=True, cumulative=True, histtype='step', color='b', linestyle='dashed') ax2.set_xlabel(r'$\mu$') ax2.set_ylabel(r'$P(<\mu|x,I)$') ax2.set_xlim(-3, 3) # third axes: gamma posterior ax3 = fig.add_subplot(222, sharey=ax1) ax3.plot(gamma, pgamma, '-k') ax3.hist(gamma_bootstrap, gamma_bins, normed=True, histtype='step', color='b', linestyle='dashed') ax3.set_xlabel(r'$\gamma$') ax3.set_ylabel(r'$p(\gamma|x,I)$') ax3.set_ylim(-0.05, 1.1) # fourth axes: gamma cumulative posterior ax4 = fig.add_subplot(224, sharex=ax3, sharey=ax2) ax4.plot(gamma, pgamma.cumsum() * dgamma, '-k') ax4.hist(gamma_bootstrap, gamma_bins, normed=True, cumulative=True, histtype='step', color='b', linestyle='dashed') ax4.set_xlabel(r'$\gamma$') ax4.set_ylabel(r'$P(<\gamma|x,I)$') ax4.set_ylim(-0.05, 1.1) ax4.set_xlim(0, 4) plt.show()
[ 37811, 198, 47, 6197, 1504, 329, 327, 559, 29658, 27484, 198, 3880, 12, 198, 11337, 642, 13, 1157, 198, 198, 464, 4735, 3951, 905, 262, 34319, 37124, 1058, 11018, 25, 63, 79, 38016, 30300, 91, 90, 87, 62, 72, 5512, 40, 8, 63, 357,...
2.511283
1,684
# -*- coding: utf-8 -*- """The file system stat event formatter.""" from __future__ import unicode_literals from dfvfs.lib import definitions as dfvfs_definitions from plaso.formatters import interface from plaso.formatters import manager from plaso.lib import errors manager.FormattersManager.RegisterFormatters([ FileStatEventFormatter, NTFSFileStatEventFormatter, NTFSUSNChangeEventFormatter])
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 464, 2393, 1080, 1185, 1785, 1296, 1436, 526, 15931, 198, 198, 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, 198, 6738, 47764, 85, 9501, 13, 80...
3.152672
131
from rest_framework import serializers from applications.models import Application
[ 6738, 1334, 62, 30604, 1330, 11389, 11341, 198, 198, 6738, 5479, 13, 27530, 1330, 15678 ]
5.533333
15
from pathlib import Path import requests from requests_toolbelt.multipart.encoder import MultipartEncoder # api_token = "iNKzBVNVAoTMhwnT2amhZRAP4dTBjkEVw9AbpRWg" # brand_center = "mdanderson.co1" # data_center = "iad1" # headers = {"x-api-token": api_token} def upload_images_web(self, image_files, library_id, creating_full_url, qualtrics_folder, image_type): """Upload images from the web app to the Qualtrics server :param image_files: Bytes, the uploaded bytes data from the web app :param library_id: str, Qualtrics library ID number :param creating_full_url: bool, whether returns the IDs only or the full URLs :param qualtrics_folder: str, the Qualtrics Graphics folder for the uploaded images :param image_type: str, the image file type :return list[str], the list of image IDs or URLs """ image_urls = list() upload_url = f"{self.api_base_url}/libraries/{library_id}/graphics" file_count_digit = len(str(len(image_files))) for file_i, file in enumerate(image_files, start=1): encoded_fields = {'file': (f"image{file_i:0>{file_count_digit}}.{image_type}", file, f'image/{image_type}')} image_url_id = self._upload_image(encoded_fields, qualtrics_folder, upload_url, file, creating_full_url) image_urls.append(image_url_id) return image_urls def delete_images(self, library_id, image_url_ids): """Delete images from the specified library :param library_id: str, the library ID number :param image_url_ids: list[str], the image IDs or full URLs :return dict, the deletion report""" report = dict() for image_url_id in image_url_ids: if image_url_id.find("=") > 0: image_url_id = image_url_id[image_url_id.index("=") + 1:] url = f'{self.api_base_url}/libraries/{library_id}/graphics/{image_url_id}' delete_response = requests.delete(url, headers=self.api_headers) try: http_status = delete_response.json()['meta']['httpStatus'] except KeyError: raise Exception(f"Failed to delete image: {image_url_id}") else: report[image_url_id] = "Deleted" if http_status.startswith('200') else "Error" return report def create_survey(self, template_json): """Create the survey using the JSON template :param template_json: str in the JSON format, the JSON file for the qsf file :return str, the created Survey ID number """ upload_url = f"{self.api_base_url}/survey-definitions" creation_response = requests.post( upload_url, json=template_json, headers={**self.api_headers, "content-type": "application/json"} ) try: survey_id = creation_response.json()['result']['SurveyID'] except KeyError: raise Exception("Couldn't create the survey. Please check the params.") return survey_id def delete_survey(self, survey_id): """Delete the survey :param survey_id: str, the survey ID number :return dict, the deletion report """ report = dict() delete_url = f"{self.api_base_url}/survey-definitions/{survey_id}" delete_response = requests.delete(delete_url, headers=self.api_headers) try: http_status = delete_response.json()['meta']['httpStatus'] except KeyError: raise Exception(f"Failed to delete survey: {survey_id}") else: report[survey_id] = "Deleted" if http_status.startswith('200') else "Error" return report def export_responses(self, survey_id, file_format="csv", data_folder=None): """Export responses from the Qualtrics survey""" download_url = f"{self.api_base_url}/surveys/{survey_id}/export-responses/" download_payload = f'{{"format": "{file_format}"}}' download_response = requests.post( download_url, data=download_payload, headers={**self.api_headers, "content-type": "application/json"} ) try: progress_id = download_response.json()["result"]["progressId"] file_id = self._monitor_progress(download_url, progress_id) file_content = self._download_file(download_url, file_id) except KeyError: raise Exception("Can't download the responses. Please check the params.") return file_content
[ 6738, 3108, 8019, 1330, 10644, 198, 11748, 7007, 198, 6738, 7007, 62, 25981, 37976, 13, 16680, 541, 433, 13, 12685, 12342, 1330, 7854, 541, 433, 27195, 12342, 198, 198, 2, 40391, 62, 30001, 796, 366, 72, 46888, 89, 33, 53, 45, 11731, ...
2.24264
2,106
from SublimeLinter.lint import Linter, STREAM_STDOUT
[ 6738, 3834, 27299, 43, 3849, 13, 75, 600, 1330, 406, 3849, 11, 3563, 32235, 62, 36886, 628 ]
3.176471
17
from metal.gdb.metal_break import Breakpoint, MetalBreakpoint from metal.gdb.exitcode import ExitBreakpoint from metal.gdb.timeout import Timeout from metal.gdb.newlib import NewlibBreakpoints from metal.gdb.argv import ArgvBreakpoint
[ 6738, 6147, 13, 70, 9945, 13, 28469, 62, 9032, 1330, 12243, 4122, 11, 12136, 31737, 4122, 198, 198, 6738, 6147, 13, 70, 9945, 13, 37023, 8189, 1330, 29739, 31737, 4122, 198, 6738, 6147, 13, 70, 9945, 13, 48678, 1330, 3862, 448, 198, ...
3.352113
71
#!/usr/bin/python3 from datetime import datetime from PyQt5.QtWidgets import QTableWidgetItem, QTableWidget, QAbstractItemView, QMenu, QMessageBox from PyQt5.QtGui import QCursor from PyQt5.QtCore import Qt, pyqtSignal, QObject from portfolio.db.fdbhandler import results, strategies, balances def updatingdata(func): """ Decorator to flag self.updatingdata_flag whenever a function that edits data without user intervention is being run """ return wrapper
[ 2, 48443, 14629, 14, 8800, 14, 29412, 18, 198, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 54, 312, 11407, 1330, 1195, 10962, 38300, 7449, 11, 1195, 10962, 38300, 11, 1195, 23839, 7449, 768...
3.063291
158
#!/usr/bin/env python from distutils.core import setup VERSION = "0.0.1" setup( author='Nikolai Tschacher', name = "proxychecker", version = VERSION, description = "A Python proxychecker module that makes use of socks", url = "http://incolumitas.com", license = "BSD", author_email = "admin@incolumitas.com", keywords = ["socks", "proxy", "proxychecker"], py_modules = ['proxychecker', 'sockshandler', 'socks'] )
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 6738, 1233, 26791, 13, 7295, 1330, 9058, 198, 198, 43717, 796, 366, 15, 13, 15, 13, 16, 1, 198, 198, 40406, 7, 198, 220, 220, 220, 1772, 11639, 40979, 349, 1872, 13146, 354, 3493, ...
2.668639
169
#!/usr/bin/env python3 from app.lib.utils.request import request from app.lib.utils.encode import base64encode from app.lib.utils.common import get_capta, get_useragent if __name__ == "__main__": S2_052 = S2_052_BaseVerify('http://127.0.0.1:8088/struts2_rest_showcase_war_exploded/orders/3')
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 6738, 598, 13, 8019, 13, 26791, 13, 25927, 1330, 2581, 198, 6738, 598, 13, 8019, 13, 26791, 13, 268, 8189, 1330, 2779, 2414, 268, 8189, 198, 6738, 598, 13, 8019, 13, 26791, ...
2.547009
117
import sys # def get_tools(): # manager = PluginManager() # manager.setPluginPlaces(["plugins/file_cabinet"]) # manager.collectPlugins() # return [plugin.plugin_object for plugin in manager.getAllPlugins()]
[ 11748, 25064, 198, 2, 825, 651, 62, 31391, 33529, 198, 2, 220, 220, 220, 220, 4706, 796, 42636, 13511, 3419, 198, 2, 220, 220, 220, 220, 4706, 13, 2617, 37233, 3646, 2114, 7, 14692, 37390, 14, 7753, 62, 66, 6014, 316, 8973, 8, 198...
2.765432
81
from __future__ import absolute_import, print_function, unicode_literals # "preload" for FindIt #2: iterate over same journal list, but actually # load a PubMedArticle object on each PMID. (no list output created) from metapub import FindIt, PubMedFetcher from metapub.findit.dances import the_doi_2step from config import JOURNAL_ISOABBR_LIST_FILENAME fetch = PubMedFetcher() if __name__ == '__main__': main()
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 11, 3601, 62, 8818, 11, 28000, 1098, 62, 17201, 874, 198, 198, 2, 366, 3866, 2220, 1, 329, 9938, 1026, 1303, 17, 25, 11629, 378, 625, 976, 3989, 1351, 11, 475, 1682, 198, 2, 3440, 25...
3.021429
140
from __future__ import absolute_import from select import select import errno import functools import itertools import json import logging import os import socket import threading import time import traceback log = logging.getLogger(__name__) from .utils import makedirs, unlink base_handlers = { 'ping': lambda control, msg: {'type': 'pong', 'pid': os.getpid()} }
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 198, 6738, 2922, 1330, 2922, 198, 11748, 11454, 3919, 198, 11748, 1257, 310, 10141, 198, 11748, 340, 861, 10141, 198, 11748, 33918, 198, 11748, 18931, 198, 11748, 28686, 198, 11748, 178...
3.184874
119
# -*- coding: utf-8 -*- """ lantz.drivers.tektronix.tds1012 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Implements the drivers to control an oscilloscope. :copyright: 2015 by Lantz Authors, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ from lantz.core import Feat, MessageBasedDriver
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 220, 220, 220, 300, 46269, 13, 36702, 13, 660, 21841, 1313, 844, 13, 8671, 82, 8784, 17, 198, 220, 220, 220, 220, 27156, 15116, 8728, 4907, 93, 628, 220, ...
2.911504
113
########################################################################## # # Copyright 2014 VMware, Inc # Copyright 2011 Jose Fonseca # All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ##########################################################################/ from .winapi import * DXGI_FORMAT = Enum("DXGI_FORMAT", [ "DXGI_FORMAT_UNKNOWN", "DXGI_FORMAT_R32G32B32A32_TYPELESS", "DXGI_FORMAT_R32G32B32A32_FLOAT", "DXGI_FORMAT_R32G32B32A32_UINT", "DXGI_FORMAT_R32G32B32A32_SINT", "DXGI_FORMAT_R32G32B32_TYPELESS", "DXGI_FORMAT_R32G32B32_FLOAT", "DXGI_FORMAT_R32G32B32_UINT", "DXGI_FORMAT_R32G32B32_SINT", "DXGI_FORMAT_R16G16B16A16_TYPELESS", "DXGI_FORMAT_R16G16B16A16_FLOAT", "DXGI_FORMAT_R16G16B16A16_UNORM", "DXGI_FORMAT_R16G16B16A16_UINT", "DXGI_FORMAT_R16G16B16A16_SNORM", "DXGI_FORMAT_R16G16B16A16_SINT", "DXGI_FORMAT_R32G32_TYPELESS", "DXGI_FORMAT_R32G32_FLOAT", "DXGI_FORMAT_R32G32_UINT", "DXGI_FORMAT_R32G32_SINT", "DXGI_FORMAT_R32G8X24_TYPELESS", "DXGI_FORMAT_D32_FLOAT_S8X24_UINT", "DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS", "DXGI_FORMAT_X32_TYPELESS_G8X24_UINT", "DXGI_FORMAT_R10G10B10A2_TYPELESS", "DXGI_FORMAT_R10G10B10A2_UNORM", "DXGI_FORMAT_R10G10B10A2_UINT", "DXGI_FORMAT_R11G11B10_FLOAT", "DXGI_FORMAT_R8G8B8A8_TYPELESS", "DXGI_FORMAT_R8G8B8A8_UNORM", "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB", "DXGI_FORMAT_R8G8B8A8_UINT", "DXGI_FORMAT_R8G8B8A8_SNORM", "DXGI_FORMAT_R8G8B8A8_SINT", "DXGI_FORMAT_R16G16_TYPELESS", "DXGI_FORMAT_R16G16_FLOAT", "DXGI_FORMAT_R16G16_UNORM", "DXGI_FORMAT_R16G16_UINT", "DXGI_FORMAT_R16G16_SNORM", "DXGI_FORMAT_R16G16_SINT", "DXGI_FORMAT_R32_TYPELESS", "DXGI_FORMAT_D32_FLOAT", "DXGI_FORMAT_R32_FLOAT", "DXGI_FORMAT_R32_UINT", "DXGI_FORMAT_R32_SINT", "DXGI_FORMAT_R24G8_TYPELESS", "DXGI_FORMAT_D24_UNORM_S8_UINT", "DXGI_FORMAT_R24_UNORM_X8_TYPELESS", "DXGI_FORMAT_X24_TYPELESS_G8_UINT", "DXGI_FORMAT_R8G8_TYPELESS", "DXGI_FORMAT_R8G8_UNORM", "DXGI_FORMAT_R8G8_UINT", "DXGI_FORMAT_R8G8_SNORM", "DXGI_FORMAT_R8G8_SINT", "DXGI_FORMAT_R16_TYPELESS", "DXGI_FORMAT_R16_FLOAT", "DXGI_FORMAT_D16_UNORM", "DXGI_FORMAT_R16_UNORM", "DXGI_FORMAT_R16_UINT", "DXGI_FORMAT_R16_SNORM", "DXGI_FORMAT_R16_SINT", "DXGI_FORMAT_R8_TYPELESS", "DXGI_FORMAT_R8_UNORM", "DXGI_FORMAT_R8_UINT", "DXGI_FORMAT_R8_SNORM", "DXGI_FORMAT_R8_SINT", "DXGI_FORMAT_A8_UNORM", "DXGI_FORMAT_R1_UNORM", "DXGI_FORMAT_R9G9B9E5_SHAREDEXP", "DXGI_FORMAT_R8G8_B8G8_UNORM", "DXGI_FORMAT_G8R8_G8B8_UNORM", "DXGI_FORMAT_BC1_TYPELESS", "DXGI_FORMAT_BC1_UNORM", "DXGI_FORMAT_BC1_UNORM_SRGB", "DXGI_FORMAT_BC2_TYPELESS", "DXGI_FORMAT_BC2_UNORM", "DXGI_FORMAT_BC2_UNORM_SRGB", "DXGI_FORMAT_BC3_TYPELESS", "DXGI_FORMAT_BC3_UNORM", "DXGI_FORMAT_BC3_UNORM_SRGB", "DXGI_FORMAT_BC4_TYPELESS", "DXGI_FORMAT_BC4_UNORM", "DXGI_FORMAT_BC4_SNORM", "DXGI_FORMAT_BC5_TYPELESS", "DXGI_FORMAT_BC5_UNORM", "DXGI_FORMAT_BC5_SNORM", "DXGI_FORMAT_B5G6R5_UNORM", "DXGI_FORMAT_B5G5R5A1_UNORM", "DXGI_FORMAT_B8G8R8A8_UNORM", "DXGI_FORMAT_B8G8R8X8_UNORM", "DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM", "DXGI_FORMAT_B8G8R8A8_TYPELESS", "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB", "DXGI_FORMAT_B8G8R8X8_TYPELESS", "DXGI_FORMAT_B8G8R8X8_UNORM_SRGB", "DXGI_FORMAT_BC6H_TYPELESS", "DXGI_FORMAT_BC6H_UF16", "DXGI_FORMAT_BC6H_SF16", "DXGI_FORMAT_BC7_TYPELESS", "DXGI_FORMAT_BC7_UNORM", "DXGI_FORMAT_BC7_UNORM_SRGB", "DXGI_FORMAT_AYUV", "DXGI_FORMAT_Y410", "DXGI_FORMAT_Y416", "DXGI_FORMAT_NV12", "DXGI_FORMAT_P010", "DXGI_FORMAT_P016", "DXGI_FORMAT_420_OPAQUE", "DXGI_FORMAT_YUY2", "DXGI_FORMAT_Y210", "DXGI_FORMAT_Y216", "DXGI_FORMAT_NV11", "DXGI_FORMAT_AI44", "DXGI_FORMAT_IA44", "DXGI_FORMAT_P8", "DXGI_FORMAT_A8P8", "DXGI_FORMAT_B4G4R4A4_UNORM", ]) HRESULT = MAKE_HRESULT([ "DXGI_STATUS_OCCLUDED", "DXGI_STATUS_CLIPPED", "DXGI_STATUS_NO_REDIRECTION", "DXGI_STATUS_NO_DESKTOP_ACCESS", "DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE", "DXGI_STATUS_MODE_CHANGED", "DXGI_STATUS_MODE_CHANGE_IN_PROGRESS", "DXGI_ERROR_INVALID_CALL", "DXGI_ERROR_NOT_FOUND", "DXGI_ERROR_MORE_DATA", "DXGI_ERROR_UNSUPPORTED", "DXGI_ERROR_DEVICE_REMOVED", "DXGI_ERROR_DEVICE_HUNG", "DXGI_ERROR_DEVICE_RESET", "DXGI_ERROR_WAS_STILL_DRAWING", "DXGI_ERROR_FRAME_STATISTICS_DISJOINT", "DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE", "DXGI_ERROR_DRIVER_INTERNAL_ERROR", "DXGI_ERROR_NONEXCLUSIVE", "DXGI_ERROR_NOT_CURRENTLY_AVAILABLE", "DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED", "DXGI_ERROR_REMOTE_OUTOFMEMORY", # IDXGIKeyedMutex::AcquireSync "WAIT_ABANDONED", "WAIT_TIMEOUT", ]) DXGI_RGB = Struct("DXGI_RGB", [ (Float, "Red"), (Float, "Green"), (Float, "Blue"), ]) DXGI_GAMMA_CONTROL = Struct("DXGI_GAMMA_CONTROL", [ (DXGI_RGB, "Scale"), (DXGI_RGB, "Offset"), (Array(DXGI_RGB, 1025), "GammaCurve"), ]) DXGI_GAMMA_CONTROL_CAPABILITIES = Struct("DXGI_GAMMA_CONTROL_CAPABILITIES", [ (BOOL, "ScaleAndOffsetSupported"), (Float, "MaxConvertedValue"), (Float, "MinConvertedValue"), (UINT, "NumGammaControlPoints"), (Array(Float, "{self}.NumGammaControlPoints"), "ControlPointPositions"), ]) DXGI_RATIONAL = Struct("DXGI_RATIONAL", [ (UINT, "Numerator"), (UINT, "Denominator"), ]) DXGI_MODE_SCANLINE_ORDER = Enum("DXGI_MODE_SCANLINE_ORDER", [ "DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED", "DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE", "DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST", "DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST", ]) DXGI_MODE_SCALING = Enum("DXGI_MODE_SCALING", [ "DXGI_MODE_SCALING_UNSPECIFIED", "DXGI_MODE_SCALING_CENTERED", "DXGI_MODE_SCALING_STRETCHED", ]) DXGI_MODE_ROTATION = Enum("DXGI_MODE_ROTATION", [ "DXGI_MODE_ROTATION_UNSPECIFIED", "DXGI_MODE_ROTATION_IDENTITY", "DXGI_MODE_ROTATION_ROTATE90", "DXGI_MODE_ROTATION_ROTATE180", "DXGI_MODE_ROTATION_ROTATE270", ]) DXGI_MODE_DESC = Struct("DXGI_MODE_DESC", [ (UINT, "Width"), (UINT, "Height"), (DXGI_RATIONAL, "RefreshRate"), (DXGI_FORMAT, "Format"), (DXGI_MODE_SCANLINE_ORDER, "ScanlineOrdering"), (DXGI_MODE_SCALING, "Scaling"), ]) DXGI_QUALITY_LEVEL = FakeEnum(UINT, [ "DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN", "DXGI_CENTER_MULTISAMPLE_QUALITY_PATTERN", ]) DXGI_SAMPLE_DESC = Struct("DXGI_SAMPLE_DESC", [ (UINT, "Count"), (DXGI_QUALITY_LEVEL, "Quality"), ]) DXGI_RGBA = Struct("DXGI_RGBA", [ (Float, "r"), (Float, "g"), (Float, "b"), (Float, "a"), ]) IDXGIObject = Interface("IDXGIObject", IUnknown) IDXGIDeviceSubObject = Interface("IDXGIDeviceSubObject", IDXGIObject) IDXGIResource = Interface("IDXGIResource", IDXGIDeviceSubObject) IDXGIKeyedMutex = Interface("IDXGIKeyedMutex", IDXGIDeviceSubObject) IDXGISurface = Interface("IDXGISurface", IDXGIDeviceSubObject) IDXGISurface1 = Interface("IDXGISurface1", IDXGISurface) IDXGIAdapter = Interface("IDXGIAdapter", IDXGIObject) IDXGIOutput = Interface("IDXGIOutput", IDXGIObject) IDXGISwapChain = Interface("IDXGISwapChain", IDXGIDeviceSubObject) IDXGIFactory = Interface("IDXGIFactory", IDXGIObject) IDXGIDevice = Interface("IDXGIDevice", IDXGIObject) IDXGIFactory1 = Interface("IDXGIFactory1", IDXGIFactory) IDXGIAdapter1 = Interface("IDXGIAdapter1", IDXGIAdapter) IDXGIDevice1 = Interface("IDXGIDevice1", IDXGIDevice) DXGI_USAGE = Flags(UINT, [ "DXGI_CPU_ACCESS_NONE", # 0 "DXGI_CPU_ACCESS_SCRATCH", # 3 "DXGI_CPU_ACCESS_DYNAMIC", # 1 "DXGI_CPU_ACCESS_READ_WRITE", # 2 "DXGI_USAGE_SHADER_INPUT", "DXGI_USAGE_RENDER_TARGET_OUTPUT", "DXGI_USAGE_BACK_BUFFER", "DXGI_USAGE_SHARED", "DXGI_USAGE_READ_ONLY", "DXGI_USAGE_DISCARD_ON_PRESENT", "DXGI_USAGE_UNORDERED_ACCESS", ]) DXGI_FRAME_STATISTICS = Struct("DXGI_FRAME_STATISTICS", [ (UINT, "PresentCount"), (UINT, "PresentRefreshCount"), (UINT, "SyncRefreshCount"), (LARGE_INTEGER, "SyncQPCTime"), (LARGE_INTEGER, "SyncGPUTime"), ]) DXGI_MAPPED_RECT = Struct("DXGI_MAPPED_RECT", [ (INT, "Pitch"), (LinearPointer(BYTE, "_MappedSize"), "pBits"), ]) DXGI_ADAPTER_DESC = Struct("DXGI_ADAPTER_DESC", [ (WString, "Description"), (UINT, "VendorId"), (UINT, "DeviceId"), (UINT, "SubSysId"), (UINT, "Revision"), (SIZE_T, "DedicatedVideoMemory"), (SIZE_T, "DedicatedSystemMemory"), (SIZE_T, "SharedSystemMemory"), (LUID, "AdapterLuid"), ]) DXGI_OUTPUT_DESC = Struct("DXGI_OUTPUT_DESC", [ (WString, "DeviceName"), (RECT, "DesktopCoordinates"), (BOOL, "AttachedToDesktop"), (DXGI_MODE_ROTATION, "Rotation"), (HMONITOR, "Monitor"), ]) DXGI_SHARED_RESOURCE = Struct("DXGI_SHARED_RESOURCE", [ (HANDLE, "Handle"), ]) DXGI_RESOURCE_PRIORITY = FakeEnum(UINT, [ "DXGI_RESOURCE_PRIORITY_MINIMUM", "DXGI_RESOURCE_PRIORITY_LOW", "DXGI_RESOURCE_PRIORITY_NORMAL", "DXGI_RESOURCE_PRIORITY_HIGH", "DXGI_RESOURCE_PRIORITY_MAXIMUM", ]) DXGI_RESIDENCY = Enum("DXGI_RESIDENCY", [ "DXGI_RESIDENCY_FULLY_RESIDENT", "DXGI_RESIDENCY_RESIDENT_IN_SHARED_MEMORY", "DXGI_RESIDENCY_EVICTED_TO_DISK", ]) DXGI_SURFACE_DESC = Struct("DXGI_SURFACE_DESC", [ (UINT, "Width"), (UINT, "Height"), (DXGI_FORMAT, "Format"), (DXGI_SAMPLE_DESC, "SampleDesc"), ]) DXGI_SWAP_EFFECT = Enum("DXGI_SWAP_EFFECT", [ "DXGI_SWAP_EFFECT_DISCARD", "DXGI_SWAP_EFFECT_SEQUENTIAL", "DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL", "DXGI_SWAP_EFFECT_FLIP_DISCARD", ]) DXGI_SWAP_CHAIN_FLAG = Flags(UINT, [ "DXGI_SWAP_CHAIN_FLAG_NONPREROTATED", "DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH", "DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE", "DXGI_SWAP_CHAIN_FLAG_RESTRICTED_CONTENT", "DXGI_SWAP_CHAIN_FLAG_RESTRICT_SHARED_RESOURCE_DRIVER", "DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY", "DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT", "DXGI_SWAP_CHAIN_FLAG_FOREGROUND_LAYER", "DXGI_SWAP_CHAIN_FLAG_FULLSCREEN_VIDEO", "DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO", "DXGI_SWAP_CHAIN_FLAG_HW_PROTECTED", "DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING", #"DXGI_SWAP_CHAIN_FLAG_RESTRICTED_TO_ALL_HOLOGRAPHIC_DISPLAYS", # DXGI 1.6 ]) DXGI_SWAP_CHAIN_DESC = Struct("DXGI_SWAP_CHAIN_DESC", [ (DXGI_MODE_DESC, "BufferDesc"), (DXGI_SAMPLE_DESC, "SampleDesc"), (DXGI_USAGE, "BufferUsage"), (UINT, "BufferCount"), (HWND, "OutputWindow"), (BOOL, "Windowed"), (DXGI_SWAP_EFFECT, "SwapEffect"), (DXGI_SWAP_CHAIN_FLAG, "Flags"), ]) IDXGIObject.methods += [ StdMethod(HRESULT, "SetPrivateData", [(REFGUID, "Name"), (UINT, "DataSize"), (OpaqueBlob(Const(Void), "DataSize"), "pData")], sideeffects=False), StdMethod(HRESULT, "SetPrivateDataInterface", [(REFGUID, "Name"), (OpaquePointer(Const(IUnknown)), "pUnknown")], sideeffects=False), StdMethod(HRESULT, "GetPrivateData", [(REFGUID, "Name"), InOut(Pointer(UINT), "pDataSize"), Out(OpaquePointer(Void), "pData")], sideeffects=False), StdMethod(HRESULT, "GetParent", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppParent")]), ] IDXGIDeviceSubObject.methods += [ StdMethod(HRESULT, "GetDevice", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppDevice")]), ] SHARED_HANDLE = Handle("shared_handle", RAW_HANDLE) IDXGIResource.methods += [ StdMethod(HRESULT, "GetSharedHandle", [Out(Pointer(SHARED_HANDLE), "pSharedHandle")]), StdMethod(HRESULT, "GetUsage", [Out(Pointer(DXGI_USAGE), "pUsage")], sideeffects=False), StdMethod(HRESULT, "SetEvictionPriority", [(DXGI_RESOURCE_PRIORITY, "EvictionPriority")]), StdMethod(HRESULT, "GetEvictionPriority", [Out(Pointer(DXGI_RESOURCE_PRIORITY), "pEvictionPriority")], sideeffects=False), ] DWORD_TIMEOUT = FakeEnum(DWORD, [ "INFINITE", ]) IDXGIKeyedMutex.methods += [ StdMethod(HRESULT, "AcquireSync", [(UINT64, "Key"), (DWORD_TIMEOUT, "dwMilliseconds")], sideeffects=False), StdMethod(HRESULT, "ReleaseSync", [(UINT64, "Key")]), ] DXGI_MAP = Flags(UINT, [ "DXGI_MAP_READ", "DXGI_MAP_WRITE", "DXGI_MAP_DISCARD", ]) IDXGISurface.methods += [ StdMethod(HRESULT, "GetDesc", [Out(Pointer(DXGI_SURFACE_DESC), "pDesc")], sideeffects=False), StdMethod(HRESULT, "Map", [Out(Pointer(DXGI_MAPPED_RECT), "pLockedRect"), (DXGI_MAP, "MapFlags")]), StdMethod(HRESULT, "Unmap", []), ] IDXGISurface1.methods += [ StdMethod(HRESULT, "GetDC", [(BOOL, "Discard"), Out(Pointer(HDC), "phdc")]), StdMethod(HRESULT, "ReleaseDC", [(Pointer(RECT), "pDirtyRect")]), ] IDXGIAdapter.methods += [ StdMethod(HRESULT, "EnumOutputs", [(UINT, "Output"), Out(Pointer(ObjPointer(IDXGIOutput)), "ppOutput")]), StdMethod(HRESULT, "GetDesc", [Out(Pointer(DXGI_ADAPTER_DESC), "pDesc")], sideeffects=False), StdMethod(HRESULT, "CheckInterfaceSupport", [(REFGUID, "InterfaceName"), Out(Pointer(LARGE_INTEGER), "pUMDVersion")], sideeffects=False), ] DXGI_ENUM_MODES = Flags(UINT, [ "DXGI_ENUM_MODES_INTERLACED", "DXGI_ENUM_MODES_SCALING", "DXGI_ENUM_MODES_STEREO", "DXGI_ENUM_MODES_DISABLED_STEREO", ]) IDXGIOutput.methods += [ StdMethod(HRESULT, "GetDesc", [Out(Pointer(DXGI_OUTPUT_DESC), "pDesc")], sideeffects=False), StdMethod(HRESULT, "GetDisplayModeList", [(DXGI_FORMAT, "EnumFormat"), (DXGI_ENUM_MODES, "Flags"), InOut(Pointer(UINT), "pNumModes"), Out(Array(DXGI_MODE_DESC, "*pNumModes"), "pDesc")], sideeffects=False), StdMethod(HRESULT, "FindClosestMatchingMode", [(Pointer(Const(DXGI_MODE_DESC)), "pModeToMatch"), Out(Pointer(DXGI_MODE_DESC), "pClosestMatch"), (ObjPointer(IUnknown), "pConcernedDevice")], sideeffects=False), StdMethod(HRESULT, "WaitForVBlank", []), StdMethod(HRESULT, "TakeOwnership", [(ObjPointer(IUnknown), "pDevice"), (BOOL, "Exclusive")]), StdMethod(Void, "ReleaseOwnership", []), StdMethod(HRESULT, "GetGammaControlCapabilities", [Out(Pointer(DXGI_GAMMA_CONTROL_CAPABILITIES), "pGammaCaps")], sideeffects=False), StdMethod(HRESULT, "SetGammaControl", [(Pointer(Const(DXGI_GAMMA_CONTROL)), "pArray")], sideeffects=False), # Avoid NumGammaControlPoints mismatch StdMethod(HRESULT, "GetGammaControl", [Out(Pointer(DXGI_GAMMA_CONTROL), "pArray")], sideeffects=False), StdMethod(HRESULT, "SetDisplaySurface", [(ObjPointer(IDXGISurface), "pScanoutSurface")]), StdMethod(HRESULT, "GetDisplaySurfaceData", [(ObjPointer(IDXGISurface), "pDestination")]), StdMethod(HRESULT, "GetFrameStatistics", [Out(Pointer(DXGI_FRAME_STATISTICS), "pStats")], sideeffects=False), ] DXGI_PRESENT = Flags(UINT, [ "DXGI_PRESENT_TEST", "DXGI_PRESENT_DO_NOT_SEQUENCE", "DXGI_PRESENT_RESTART", "DXGI_PRESENT_DO_NOT_WAIT", "DXGI_PRESENT_STEREO_PREFER_RIGHT", "DXGI_PRESENT_STEREO_TEMPORARY_MONO", "DXGI_PRESENT_RESTRICT_TO_OUTPUT", "DXGI_PRESENT_USE_DURATION", ]) IDXGISwapChain.methods += [ StdMethod(HRESULT, "Present", [(UINT, "SyncInterval"), (DXGI_PRESENT, "Flags")]), StdMethod(HRESULT, "GetBuffer", [(UINT, "Buffer"), (REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppSurface")]), StdMethod(HRESULT, "SetFullscreenState", [(BOOL, "Fullscreen"), (ObjPointer(IDXGIOutput), "pTarget")]), StdMethod(HRESULT, "GetFullscreenState", [Out(Pointer(BOOL), "pFullscreen"), Out(Pointer(ObjPointer(IDXGIOutput)), "ppTarget")]), StdMethod(HRESULT, "GetDesc", [Out(Pointer(DXGI_SWAP_CHAIN_DESC), "pDesc")], sideeffects=False), StdMethod(HRESULT, "ResizeBuffers", [(UINT, "BufferCount"), (UINT, "Width"), (UINT, "Height"), (DXGI_FORMAT, "NewFormat"), (DXGI_SWAP_CHAIN_FLAG, "SwapChainFlags")]), StdMethod(HRESULT, "ResizeTarget", [(Pointer(Const(DXGI_MODE_DESC)), "pNewTargetParameters")]), StdMethod(HRESULT, "GetContainingOutput", [Out(Pointer(ObjPointer(IDXGIOutput)), "ppOutput")]), StdMethod(HRESULT, "GetFrameStatistics", [Out(Pointer(DXGI_FRAME_STATISTICS), "pStats")], sideeffects=False), StdMethod(HRESULT, "GetLastPresentCount", [Out(Pointer(UINT), "pLastPresentCount")], sideeffects=False), ] DXGI_MWA = Flags(UINT, [ "DXGI_MWA_NO_WINDOW_CHANGES", "DXGI_MWA_NO_ALT_ENTER", "DXGI_MWA_NO_PRINT_SCREEN", "DXGI_MWA_VALID", ]) IDXGIFactory.methods += [ StdMethod(HRESULT, "EnumAdapters", [(UINT, "Adapter"), Out(Pointer(ObjPointer(IDXGIAdapter)), "ppAdapter")]), StdMethod(HRESULT, "MakeWindowAssociation", [(HWND, "WindowHandle"), (DXGI_MWA, "Flags")], sideeffects=False), StdMethod(HRESULT, "GetWindowAssociation", [Out(Pointer(HWND), "pWindowHandle")], sideeffects=False), StdMethod(HRESULT, "CreateSwapChain", [(ObjPointer(IUnknown), "pDevice"), (Pointer(DXGI_SWAP_CHAIN_DESC), "pDesc"), Out(Pointer(ObjPointer(IDXGISwapChain)), "ppSwapChain")]), StdMethod(HRESULT, "CreateSoftwareAdapter", [(HMODULE, "Module"), Out(Pointer(ObjPointer(IDXGIAdapter)), "ppAdapter")]), ] IDXGIDevice.methods += [ StdMethod(HRESULT, "GetAdapter", [Out(Pointer(ObjPointer(IDXGIAdapter)), "pAdapter")]), StdMethod(HRESULT, "CreateSurface", [(Pointer(Const(DXGI_SURFACE_DESC)), "pDesc"), (UINT, "NumSurfaces"), (DXGI_USAGE, "Usage"), (Pointer(Const(DXGI_SHARED_RESOURCE)), "pSharedResource"), Out(Pointer(ObjPointer(IDXGISurface)), "ppSurface")]), StdMethod(HRESULT, "QueryResourceResidency", [(Array(Const(ObjPointer(IUnknown)), "NumResources"), "ppResources"), Out(Array(DXGI_RESIDENCY, "NumResources"), "pResidencyStatus"), (UINT, "NumResources")], sideeffects=False), StdMethod(HRESULT, "SetGPUThreadPriority", [(INT, "Priority")]), StdMethod(HRESULT, "GetGPUThreadPriority", [Out(Pointer(INT), "pPriority")], sideeffects=False), ] DXGI_ADAPTER_FLAG = FakeEnum(UINT, [ "DXGI_ADAPTER_FLAG_NONE", "DXGI_ADAPTER_FLAG_REMOTE", "DXGI_ADAPTER_FLAG_SOFTWARE", ]) DXGI_ADAPTER_DESC1 = Struct("DXGI_ADAPTER_DESC1", [ (WString, "Description"), (UINT, "VendorId"), (UINT, "DeviceId"), (UINT, "SubSysId"), (UINT, "Revision"), (SIZE_T, "DedicatedVideoMemory"), (SIZE_T, "DedicatedSystemMemory"), (SIZE_T, "SharedSystemMemory"), (LUID, "AdapterLuid"), (DXGI_SWAP_CHAIN_FLAG, "Flags"), ]) DXGI_DISPLAY_COLOR_SPACE = Struct("DXGI_DISPLAY_COLOR_SPACE", [ (Array(Array(FLOAT, 8), 2), "PrimaryCoordinates"), (Array(Array(FLOAT, 16), 2), "WhitePoints"), ]) IDXGIFactory1.methods += [ StdMethod(HRESULT, "EnumAdapters1", [(UINT, "Adapter"), Out(Pointer(ObjPointer(IDXGIAdapter1)), "ppAdapter")]), StdMethod(BOOL, "IsCurrent", [], sideeffects=False), ] IDXGIAdapter1.methods += [ StdMethod(HRESULT, "GetDesc1", [Out(Pointer(DXGI_ADAPTER_DESC1), "pDesc")], sideeffects=False), ] IDXGIDevice1.methods += [ StdMethod(HRESULT, "SetMaximumFrameLatency", [(UINT, "MaxLatency")]), StdMethod(HRESULT, "GetMaximumFrameLatency", [Out(Pointer(UINT), "pMaxLatency")], sideeffects=False), ] dxgi = Module('dxgi') dxgi.addInterfaces([ IDXGIKeyedMutex, IDXGIFactory1, IDXGIDevice1, IDXGIAdapter1, IDXGIResource, ]) dxgi.addFunctions([ StdFunction(HRESULT, "CreateDXGIFactory", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppFactory")]), StdFunction(HRESULT, "CreateDXGIFactory1", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppFactory")]), StdFunction(HRESULT, "DXGID3D10CreateDevice", [(HMODULE, "hModule"), (ObjPointer(IDXGIFactory), "pFactory"), (ObjPointer(IDXGIAdapter), "pAdapter"), (UINT, "Flags"), (OpaquePointer(Const(IUnknown)), "pUnknown"), Out(Pointer(ObjPointer(Void)), "ppDevice")], internal=True), StdFunction(HRESULT, "DXGID3D10CreateLayeredDevice", [(UINT), (UINT), (UINT), (UINT), (UINT)], internal=True), StdFunction(SIZE_T, "DXGID3D10GetLayeredDeviceSize", [(OpaqueArray(Const(Void), "NumLayers"), "pLayers"), (UINT, "NumLayers")], internal=True), StdFunction(HRESULT, "DXGID3D10RegisterLayers", [(OpaqueArray(Const(Void), "NumLayers"), "pLayers"), (UINT, "NumLayers")], internal=True), ]) # # DXGI 1.2 # IDXGIDisplayControl = Interface("IDXGIDisplayControl", IUnknown) IDXGIDisplayControl.methods += [ StdMethod(BOOL, "IsStereoEnabled", [], sideeffects=False), StdMethod(Void, "SetStereoEnabled", [(BOOL, "enabled")]), ] DXGI_OUTDUPL_MOVE_RECT = Struct("DXGI_OUTDUPL_MOVE_RECT", [ (POINT, "SourcePoint"), (RECT, "DestinationRect"), ]) DXGI_OUTDUPL_DESC = Struct("DXGI_OUTDUPL_DESC", [ (DXGI_MODE_DESC, "ModeDesc"), (DXGI_MODE_ROTATION, "Rotation"), (BOOL, "DesktopImageInSystemMemory"), ]) DXGI_OUTDUPL_POINTER_POSITION = Struct("DXGI_OUTDUPL_POINTER_POSITION", [ (POINT, "Position"), (BOOL, "Visible"), ]) DXGI_OUTDUPL_POINTER_SHAPE_TYPE = Enum("DXGI_OUTDUPL_POINTER_SHAPE_TYPE", [ "DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME", "DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR", "DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR", ]) DXGI_OUTDUPL_POINTER_SHAPE_INFO = Struct("DXGI_OUTDUPL_POINTER_SHAPE_INFO", [ (UINT, "Type"), (UINT, "Width"), (UINT, "Height"), (UINT, "Pitch"), (POINT, "HotSpot"), ]) DXGI_OUTDUPL_FRAME_INFO = Struct("DXGI_OUTDUPL_FRAME_INFO", [ (LARGE_INTEGER, "LastPresentTime"), (LARGE_INTEGER, "LastMouseUpdateTime"), (UINT, "AccumulatedFrames"), (BOOL, "RectsCoalesced"), (BOOL, "ProtectedContentMaskedOut"), (DXGI_OUTDUPL_POINTER_POSITION, "PointerPosition"), (UINT, "TotalMetadataBufferSize"), (UINT, "PointerShapeBufferSize"), ]) IDXGIOutputDuplication = Interface("IDXGIOutputDuplication", IDXGIObject) IDXGIOutputDuplication.methods += [ StdMethod(Void, "GetDesc", [Out(Pointer(DXGI_OUTDUPL_DESC), "pDesc")], sideeffects=False), StdMethod(HRESULT, "AcquireNextFrame", [(UINT, "TimeoutInMilliseconds"), Out(Pointer(DXGI_OUTDUPL_FRAME_INFO), "pFrameInfo"), Out(Pointer(ObjPointer(IDXGIResource)), "ppDesktopResource")]), StdMethod(HRESULT, "GetFrameDirtyRects", [(UINT, "DirtyRectsBufferSize"), Out(Array(RECT, "DirtyRectsBufferSize"), "pDirtyRectsBuffer"), Out(Pointer(UINT), "pDirtyRectsBufferSizeRequired")], sideeffects=False), StdMethod(HRESULT, "GetFrameMoveRects", [(UINT, "MoveRectsBufferSize"), Out(Array(DXGI_OUTDUPL_MOVE_RECT, "MoveRectsBufferSize"), "pMoveRectBuffer"), Out(Pointer(UINT), "pMoveRectsBufferSizeRequired")], sideeffects=False), StdMethod(HRESULT, "GetFramePointerShape", [(UINT, "PointerShapeBufferSize"), Out(OpaqueBlob(Void, "PointerShapeBufferSize"), "pPointerShapeBuffer"), Out(Pointer(UINT), "pPointerShapeBufferSizeRequired"), Out(Pointer(DXGI_OUTDUPL_POINTER_SHAPE_INFO), "pPointerShapeInfo")], sideeffects=False), StdMethod(HRESULT, "MapDesktopSurface", [Out(Pointer(DXGI_MAPPED_RECT), "pLockedRect")], sideeffects=False), StdMethod(HRESULT, "UnMapDesktopSurface", [], sideeffects=False), StdMethod(HRESULT, "ReleaseFrame", []), ] DXGI_ALPHA_MODE = Enum("DXGI_ALPHA_MODE", [ "DXGI_ALPHA_MODE_UNSPECIFIED", "DXGI_ALPHA_MODE_PREMULTIPLIED", "DXGI_ALPHA_MODE_STRAIGHT", "DXGI_ALPHA_MODE_IGNORE", ]) IDXGISurface2 = Interface("IDXGISurface2", IDXGISurface1) IDXGISurface2.methods += [ StdMethod(HRESULT, "GetResource", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppParentResource"), Out(Pointer(UINT), "pSubresourceIndex")]), ] DXGI_SHARED_RESOURCE_FLAG = Flags(DWORD, [ "DXGI_SHARED_RESOURCE_READ", "DXGI_SHARED_RESOURCE_WRITE", ]) IDXGIResource1 = Interface("IDXGIResource1", IDXGIResource) IDXGIResource1.methods += [ StdMethod(HRESULT, "CreateSubresourceSurface", [(UINT, "index"), Out(Pointer(ObjPointer(IDXGISurface2)), "ppSurface")]), StdMethod(HRESULT, "CreateSharedHandle", [(Pointer(Const(SECURITY_ATTRIBUTES)), "pAttributes"), (DXGI_SHARED_RESOURCE_FLAG, "dwAccess"), (LPCWSTR, "lpName"), Out(Pointer(HANDLE), "pHandle")]), ] DXGI_OFFER_RESOURCE_PRIORITY = Enum("DXGI_OFFER_RESOURCE_PRIORITY", [ "DXGI_OFFER_RESOURCE_PRIORITY_LOW", "DXGI_OFFER_RESOURCE_PRIORITY_NORMAL", "DXGI_OFFER_RESOURCE_PRIORITY_HIGH", ]) IDXGIDevice2 = Interface("IDXGIDevice2", IDXGIDevice1) IDXGIDevice2.methods += [ StdMethod(HRESULT, "OfferResources", [(UINT, "NumResources"), (Array(Const(ObjPointer(IDXGIResource)), "NumResources"), "ppResources"), (DXGI_OFFER_RESOURCE_PRIORITY, "Priority")]), StdMethod(HRESULT, "ReclaimResources", [(UINT, "NumResources"), (Array(Const(ObjPointer(IDXGIResource)), "NumResources"), "ppResources"), Out(Pointer(BOOL), "pDiscarded")]), StdMethod(HRESULT, "EnqueueSetEvent", [(HANDLE, "hEvent")], sideeffects=False), ] DXGI_MODE_DESC1 = Struct("DXGI_MODE_DESC1", [ (UINT, "Width"), (UINT, "Height"), (DXGI_RATIONAL, "RefreshRate"), (DXGI_FORMAT, "Format"), (DXGI_MODE_SCANLINE_ORDER, "ScanlineOrdering"), (DXGI_MODE_SCALING, "Scaling"), (BOOL, "Stereo"), ]) DXGI_SCALING = Enum("DXGI_SCALING", [ "DXGI_SCALING_STRETCH", "DXGI_SCALING_NONE", "DXGI_SCALING_ASPECT_RATIO_STRETCH", ]) DXGI_SWAP_CHAIN_DESC1 = Struct("DXGI_SWAP_CHAIN_DESC1", [ (UINT, "Width"), (UINT, "Height"), (DXGI_FORMAT, "Format"), (BOOL, "Stereo"), (DXGI_SAMPLE_DESC, "SampleDesc"), (DXGI_USAGE, "BufferUsage"), (UINT, "BufferCount"), (DXGI_SCALING, "Scaling"), (DXGI_SWAP_EFFECT, "SwapEffect"), (DXGI_ALPHA_MODE, "AlphaMode"), (DXGI_SWAP_CHAIN_FLAG, "Flags"), ]) DXGI_SWAP_CHAIN_FULLSCREEN_DESC = Struct("DXGI_SWAP_CHAIN_FULLSCREEN_DESC", [ (DXGI_RATIONAL, "RefreshRate"), (DXGI_MODE_SCANLINE_ORDER, "ScanlineOrdering"), (DXGI_MODE_SCALING, "Scaling"), (BOOL, "Windowed"), ]) DXGI_PRESENT_PARAMETERS = Struct("DXGI_PRESENT_PARAMETERS", [ (UINT, "DirtyRectsCount"), (Array(RECT, "{self}.DirtyRectsCount"), "pDirtyRects"), (Pointer(RECT), "pScrollRect"), (Pointer(POINT), "pScrollOffset"), ]) IDXGISwapChain1 = Interface("IDXGISwapChain1", IDXGISwapChain) IDXGISwapChain1.methods += [ StdMethod(HRESULT, "GetDesc1", [(Out(Pointer(DXGI_SWAP_CHAIN_DESC1), "pDesc"))], sideeffects=False), StdMethod(HRESULT, "GetFullscreenDesc", [(Out(Pointer(DXGI_SWAP_CHAIN_FULLSCREEN_DESC), "pDesc"))], sideeffects=False), StdMethod(HRESULT, "GetHwnd", [(Out(Pointer(HWND), "pHwnd"))], sideeffects=False), StdMethod(HRESULT, "GetCoreWindow", [(REFIID, "riid"), (Out(Pointer(ObjPointer(Void)), "ppUnk"))]), StdMethod(HRESULT, "Present1", [(UINT, "SyncInterval"), (DXGI_PRESENT, "Flags"), (Pointer(Const(DXGI_PRESENT_PARAMETERS)), "pPresentParameters")]), StdMethod(BOOL, "IsTemporaryMonoSupported", [], sideeffects=False), StdMethod(HRESULT, "GetRestrictToOutput", [(Out(Pointer(ObjPointer(IDXGIOutput)), "ppRestrictToOutput"))]), StdMethod(HRESULT, "SetBackgroundColor", [(Pointer(Const(DXGI_RGBA)), "pColor")]), StdMethod(HRESULT, "GetBackgroundColor", [(Out(Pointer(DXGI_RGBA), "pColor"))], sideeffects=False), StdMethod(HRESULT, "SetRotation", [(DXGI_MODE_ROTATION, "Rotation")]), StdMethod(HRESULT, "GetRotation", [(Out(Pointer(DXGI_MODE_ROTATION), "pRotation"))], sideeffects=False), ] IDXGIFactory2 = Interface("IDXGIFactory2", IDXGIFactory1) IDXGIFactory2.methods += [ StdMethod(BOOL, "IsWindowedStereoEnabled", [], sideeffects=False), StdMethod(HRESULT, "CreateSwapChainForHwnd", [(ObjPointer(IUnknown), "pDevice"), (HWND, "hWnd"), (Pointer(Const(DXGI_SWAP_CHAIN_DESC1)), "pDesc"), (Pointer(Const(DXGI_SWAP_CHAIN_FULLSCREEN_DESC)), "pFullscreenDesc"), (ObjPointer(IDXGIOutput), "pRestrictToOutput"), Out(Pointer(ObjPointer(IDXGISwapChain1)), "ppSwapChain")]), StdMethod(HRESULT, "CreateSwapChainForCoreWindow", [(ObjPointer(IUnknown), "pDevice"), (ObjPointer(IUnknown), "pWindow"), (Pointer(Const(DXGI_SWAP_CHAIN_DESC1)), "pDesc"), (ObjPointer(IDXGIOutput), "pRestrictToOutput"), Out(Pointer(ObjPointer(IDXGISwapChain1)), "ppSwapChain")]), StdMethod(HRESULT, "GetSharedResourceAdapterLuid", [(HANDLE, "hResource"), Out(Pointer(LUID), "pLuid")], sideeffects=False), StdMethod(HRESULT, "RegisterStereoStatusWindow", [(HWND, "WindowHandle"), (UINT, "wMsg"), Out(Pointer(DWORD), "pdwCookie")], sideeffects=False), StdMethod(HRESULT, "RegisterStereoStatusEvent", [(HANDLE, "hEvent"), Out(Pointer(DWORD), "pdwCookie")], sideeffects=False), StdMethod(Void, "UnregisterStereoStatus", [(DWORD, "dwCookie")], sideeffects=False), StdMethod(HRESULT, "RegisterOcclusionStatusWindow", [(HWND, "WindowHandle"), (UINT, "wMsg"), Out(Pointer(DWORD), "pdwCookie")], sideeffects=False), StdMethod(HRESULT, "RegisterOcclusionStatusEvent", [(HANDLE, "hEvent"), Out(Pointer(DWORD), "pdwCookie")], sideeffects=False), StdMethod(Void, "UnregisterOcclusionStatus", [(DWORD, "dwCookie")], sideeffects=False), StdMethod(HRESULT, "CreateSwapChainForComposition", [(ObjPointer(IUnknown), "pDevice"), (Pointer(Const(DXGI_SWAP_CHAIN_DESC1)), "pDesc"), (ObjPointer(IDXGIOutput), "pRestrictToOutput"), Out(Pointer(ObjPointer(IDXGISwapChain1)), "ppSwapChain")]), ] DXGI_GRAPHICS_PREEMPTION_GRANULARITY = Enum("DXGI_GRAPHICS_PREEMPTION_GRANULARITY", [ "DXGI_GRAPHICS_PREEMPTION_DMA_BUFFER_BOUNDARY", "DXGI_GRAPHICS_PREEMPTION_PRIMITIVE_BOUNDARY", "DXGI_GRAPHICS_PREEMPTION_TRIANGLE_BOUNDARY", "DXGI_GRAPHICS_PREEMPTION_PIXEL_BOUNDARY", "DXGI_GRAPHICS_PREEMPTION_INSTRUCTION_BOUNDARY", ]) DXGI_COMPUTE_PREEMPTION_GRANULARITY = Enum("DXGI_COMPUTE_PREEMPTION_GRANULARITY", [ "DXGI_COMPUTE_PREEMPTION_DMA_BUFFER_BOUNDARY", "DXGI_COMPUTE_PREEMPTION_DISPATCH_BOUNDARY", "DXGI_COMPUTE_PREEMPTION_THREAD_GROUP_BOUNDARY", "DXGI_COMPUTE_PREEMPTION_THREAD_BOUNDARY", "DXGI_COMPUTE_PREEMPTION_INSTRUCTION_BOUNDARY", ]) DXGI_ADAPTER_DESC2 = Struct("DXGI_ADAPTER_DESC2", [ (WString, "Description"), (UINT, "VendorId"), (UINT, "DeviceId"), (UINT, "SubSysId"), (UINT, "Revision"), (SIZE_T, "DedicatedVideoMemory"), (SIZE_T, "DedicatedSystemMemory"), (SIZE_T, "SharedSystemMemory"), (LUID, "AdapterLuid"), (DXGI_ADAPTER_FLAG, "Flags"), (DXGI_GRAPHICS_PREEMPTION_GRANULARITY, "GraphicsPreemptionGranularity"), (DXGI_COMPUTE_PREEMPTION_GRANULARITY, "ComputePreemptionGranularity"), ]) IDXGIAdapter2 = Interface("IDXGIAdapter2", IDXGIAdapter1) IDXGIAdapter2.methods += [ StdMethod(HRESULT, "GetDesc2", [Out(Pointer(DXGI_ADAPTER_DESC2), "pDesc")], sideeffects=False), ] IDXGIOutput1 = Interface("IDXGIOutput1", IDXGIOutput) IDXGIOutput1.methods += [ StdMethod(HRESULT, "GetDisplayModeList1", [(DXGI_FORMAT, "EnumFormat"), (DXGI_ENUM_MODES, "Flags"), InOut(Pointer(UINT), "pNumModes"), Out(Array(DXGI_MODE_DESC1, "*pNumModes"), "pDesc")], sideeffects=False), StdMethod(HRESULT, "FindClosestMatchingMode1", [(Pointer(Const(DXGI_MODE_DESC1)), "pModeToMatch"), Out(Pointer(DXGI_MODE_DESC1), "pClosestMatch"), (ObjPointer(IUnknown), "pConcernedDevice")], sideeffects=False), StdMethod(HRESULT, "GetDisplaySurfaceData1", [(ObjPointer(IDXGIResource), "pDestination")]), StdMethod(HRESULT, "DuplicateOutput", [(ObjPointer(IUnknown), "pDevice"), Out(Pointer(ObjPointer(IDXGIOutputDuplication)), "ppOutputDuplication")]), ] dxgi.addInterfaces([ IDXGIDisplayControl, IDXGIDevice2, IDXGISwapChain1, IDXGIFactory2, IDXGIResource1, IDXGIAdapter2, IDXGIOutput1, ]) # # DXGI 1.3 # DXGI_CREATE_FACTORY_FLAGS = Flags(UINT, [ "DXGI_CREATE_FACTORY_DEBUG", ]) dxgi.addFunctions([ StdFunction(HRESULT, "CreateDXGIFactory2", [(DXGI_CREATE_FACTORY_FLAGS, "Flags"), (REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppFactory")]), ]) IDXGIDevice3 = Interface("IDXGIDevice3", IDXGIDevice2) IDXGIDevice3.methods += [ StdMethod(Void, "Trim", []), ] DXGI_MATRIX_3X2_F = Struct("DXGI_MATRIX_3X2_F", [ (FLOAT, "_11"), (FLOAT, "_12"), (FLOAT, "_21"), (FLOAT, "_22"), (FLOAT, "_31"), (FLOAT, "_32"), ]) IDXGISwapChain2 = Interface("IDXGISwapChain2", IDXGISwapChain1) IDXGISwapChain2.methods += [ StdMethod(HRESULT, "SetSourceSize", [(UINT, "Width"), (UINT, "Height")]), StdMethod(HRESULT, "GetSourceSize", [Out(Pointer(UINT), "pWidth"), Out(Pointer(UINT), "pHeight")], sideeffects=False), StdMethod(HRESULT, "SetMaximumFrameLatency", [(UINT, "MaxLatency")]), StdMethod(HRESULT, "GetMaximumFrameLatency", [Out(Pointer(UINT), "pMaxLatency")], sideeffects=False), StdMethod(HANDLE, "GetFrameLatencyWaitableObject", [], sideeffects=False), StdMethod(HRESULT, "SetMatrixTransform", [(Pointer(Const(DXGI_MATRIX_3X2_F)), "pMatrix")]), StdMethod(HRESULT, "GetMatrixTransform", [Out(Pointer(DXGI_MATRIX_3X2_F), "pMatrix")], sideeffects=False), ] IDXGIOutput2 = Interface("IDXGIOutput2", IDXGIOutput1) IDXGIOutput2.methods += [ StdMethod(BOOL, "SupportsOverlays", [], sideeffects=False), ] IDXGIFactory3 = Interface("IDXGIFactory3", IDXGIFactory2) IDXGIFactory3.methods += [ StdMethod(DXGI_CREATE_FACTORY_FLAGS, "GetCreationFlags", [], sideeffects=False), ] DXGI_DECODE_SWAP_CHAIN_DESC = Struct("DXGI_DECODE_SWAP_CHAIN_DESC", [ (UINT, "Flags"), ]) # XXX: Flags DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS = Enum("DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS", [ "DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAG_NOMINAL_RANGE", "DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAG_BT709", "DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAG_xvYCC", ]) IDXGIDecodeSwapChain = Interface("IDXGIDecodeSwapChain", IUnknown) IDXGIDecodeSwapChain.methods += [ StdMethod(HRESULT, "PresentBuffer", [(UINT, "BufferToPresent"), (UINT, "SyncInterval"), (DXGI_PRESENT, "Flags")]), StdMethod(HRESULT, "SetSourceRect", [(Pointer(Const(RECT)), "pRect")]), StdMethod(HRESULT, "SetTargetRect", [(Pointer(Const(RECT)), "pRect")]), StdMethod(HRESULT, "SetDestSize", [(UINT, "Width"), (UINT, "Height")]), StdMethod(HRESULT, "GetSourceRect", [Out(Pointer(RECT), "pRect")], sideeffects=False), StdMethod(HRESULT, "GetTargetRect", [Out(Pointer(RECT), "pRect")], sideeffects=False), StdMethod(HRESULT, "GetDestSize", [Out(Pointer(UINT), "pWidth"), Out(Pointer(UINT), "pHeight")], sideeffects=False), StdMethod(HRESULT, "SetColorSpace", [(DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS, "ColorSpace")]), StdMethod(DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS, "GetColorSpace", [], sideeffects=False), ] IDXGIFactoryMedia = Interface("IDXGIFactoryMedia", IUnknown) IDXGIFactoryMedia.methods += [ StdMethod(HRESULT, "CreateSwapChainForCompositionSurfaceHandle", [(ObjPointer(IUnknown), "pDevice"), (HANDLE, "hSurface"), (Pointer(Const(DXGI_SWAP_CHAIN_DESC1)), "pDesc"), (ObjPointer(IDXGIOutput), "pRestrictToOutput"), Out(Pointer(ObjPointer(IDXGISwapChain1)), "ppSwapChain")]), StdMethod(HRESULT, "CreateDecodeSwapChainForCompositionSurfaceHandle", [(ObjPointer(IUnknown), "pDevice"), (HANDLE, "hSurface"), (Pointer(DXGI_DECODE_SWAP_CHAIN_DESC), "pDesc"), (ObjPointer(IDXGIResource), "pYuvDecodeBuffers"), (ObjPointer(IDXGIOutput), "pRestrictToOutput"), Out(Pointer(ObjPointer(IDXGIDecodeSwapChain)), "ppSwapChain")]), ] DXGI_FRAME_PRESENTATION_MODE = Enum("DXGI_FRAME_PRESENTATION_MODE", [ "DXGI_FRAME_PRESENTATION_MODE_COMPOSED", "DXGI_FRAME_PRESENTATION_MODE_OVERLAY", "DXGI_FRAME_PRESENTATION_MODE_NONE", ]) DXGI_FRAME_STATISTICS_MEDIA = Struct("DXGI_FRAME_STATISTICS_MEDIA", [ (UINT, "PresentCount"), (UINT, "PresentRefreshCount"), (UINT, "SyncRefreshCount"), (LARGE_INTEGER, "SyncQPCTime"), (LARGE_INTEGER, "SyncGPUTime"), (DXGI_FRAME_PRESENTATION_MODE, "CompositionMode"), (UINT, "ApprovedPresentDuration"), ]) IDXGISwapChainMedia = Interface("IDXGISwapChainMedia", IUnknown) IDXGISwapChainMedia.methods += [ StdMethod(HRESULT, "GetFrameStatisticsMedia", [Out(Pointer(DXGI_FRAME_STATISTICS_MEDIA), "pStats")], sideeffects=False), StdMethod(HRESULT, "SetPresentDuration", [(UINT, "Duration")]), StdMethod(HRESULT, "CheckPresentDurationSupport", [(UINT, "DesiredPresentDuration"), Out(Pointer(UINT), "pClosestSmallerPresentDuration"), Out(Pointer(UINT), "pClosestLargerPresentDuration")], sideeffects=False), ] DXGI_OVERLAY_SUPPORT_FLAG = FakeEnum(UINT, [ "DXGI_OVERLAY_SUPPORT_FLAG_DIRECT", "DXGI_OVERLAY_SUPPORT_FLAG_SCALING", ]) IDXGIOutput3 = Interface("IDXGIOutput3", IDXGIOutput2) IDXGIOutput3.methods += [ StdMethod(HRESULT, "CheckOverlaySupport", [(DXGI_FORMAT, "EnumFormat"), (ObjPointer(IUnknown), "pConcernedDevice"), Out(Pointer(DXGI_OVERLAY_SUPPORT_FLAG), "pFlags")], sideeffects=False), ] dxgi.addInterfaces([ IDXGIDevice3, IDXGISwapChain2, IDXGISwapChainMedia, IDXGIOutput3, IDXGIFactory3, IDXGIFactoryMedia, ]) # # Undocumented interfaces # IDXGIFactoryDWM = Interface("IDXGIFactoryDWM", IUnknown) IDXGISwapChainDWM = Interface("IDXGISwapChainDWM", IDXGIDeviceSubObject) IDXGIFactoryDWM.methods += [ StdMethod(HRESULT, "CreateSwapChain", [(ObjPointer(IUnknown), "pDevice"), (Pointer(DXGI_SWAP_CHAIN_DESC), "pDesc"), (ObjPointer(IDXGIOutput), "pOutput"), Out(Pointer(ObjPointer(IDXGISwapChainDWM)), "ppSwapChain")]), ] # http://shchetinin.blogspot.co.uk/2012/04/dwm-graphics-directx-win8win7.html IDXGISwapChainDWM.methods += [ StdMethod(HRESULT, "Present", [(UINT, "SyncInterval"), (DXGI_PRESENT, "Flags")]), StdMethod(HRESULT, "GetBuffer", [(UINT, "Buffer"), (REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppSurface")]), StdMethod(HRESULT, "GetDesc", [Out(Pointer(DXGI_SWAP_CHAIN_DESC), "pDesc")], sideeffects=False), StdMethod(HRESULT, "ResizeBuffers", [(UINT, "BufferCount"), (UINT, "Width"), (UINT, "Height"), (DXGI_FORMAT, "NewFormat"), (DXGI_SWAP_CHAIN_FLAG, "SwapChainFlags")]), StdMethod(HRESULT, "ResizeTarget", [(Pointer(Const(DXGI_MODE_DESC)), "pNewTargetParameters")]), StdMethod(HRESULT, "GetContainingOutput", [Out(Pointer(ObjPointer(IDXGIOutput)), "ppOutput")]), StdMethod(HRESULT, "GetFrameStatistics", [Out(Pointer(DXGI_FRAME_STATISTICS), "pStats")], sideeffects=False), StdMethod(HRESULT, "GetLastPresentCount", [Out(Pointer(UINT), "pLastPresentCount")], sideeffects=False), ] dxgi.addInterfaces([ IDXGIFactoryDWM, ]) # # DXGI 1.4 # DXGI_COLOR_SPACE_TYPE = Enum('DXGI_COLOR_SPACE_TYPE', [ 'DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709', 'DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709', 'DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709', 'DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020', 'DXGI_COLOR_SPACE_RESERVED', 'DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601', 'DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601', 'DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601', 'DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709', 'DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709', 'DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020', 'DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020', 'DXGI_COLOR_SPACE_CUSTOM', ]) DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG = Enum('DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG', [ 'DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT', 'DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_OVERLAY_PRESENT', ]) DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG = Enum('DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG', [ 'DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG_PRESENT', ]) DXGI_MEMORY_SEGMENT_GROUP = Enum('DXGI_MEMORY_SEGMENT_GROUP', [ 'DXGI_MEMORY_SEGMENT_GROUP_LOCAL', 'DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL', ]) DXGI_QUERY_VIDEO_MEMORY_INFO = Struct('DXGI_QUERY_VIDEO_MEMORY_INFO', [ (UINT64, 'Budget'), (UINT64, 'CurrentUsage'), (UINT64, 'AvailableForReservation'), (UINT64, 'CurrentReservation'), ]) IDXGISwapChain3 = Interface('IDXGISwapChain3', IDXGISwapChain2) IDXGIOutput4 = Interface('IDXGIOutput4', IDXGIOutput3) IDXGIFactory4 = Interface('IDXGIFactory4', IDXGIFactory3) IDXGIAdapter3 = Interface('IDXGIAdapter3', IDXGIAdapter2) IDXGISwapChain3.methods += [ StdMethod(UINT, 'GetCurrentBackBufferIndex', []), StdMethod(HRESULT, 'CheckColorSpaceSupport', [(DXGI_COLOR_SPACE_TYPE, 'ColorSpace'), Out(Pointer(UINT), 'pColorSpaceSupport')], sideeffects=False), StdMethod(HRESULT, 'SetColorSpace1', [(DXGI_COLOR_SPACE_TYPE, 'ColorSpace')]), StdMethod(HRESULT, 'ResizeBuffers1', [(UINT, 'BufferCount'), (UINT, 'Width'), (UINT, 'Height'), (DXGI_FORMAT, 'Format'), (DXGI_SWAP_CHAIN_FLAG, 'SwapChainFlags'), (Pointer(Const(UINT)), 'pCreationNodeMask'), (Array(Const(ObjPointer(IUnknown)), 'BufferCount'), 'ppPresentQueue')]), ] IDXGIOutput4.methods += [ StdMethod(HRESULT, 'CheckOverlayColorSpaceSupport', [(DXGI_FORMAT, 'Format'), (DXGI_COLOR_SPACE_TYPE, 'ColorSpace'), (ObjPointer(IUnknown), 'pConcernedDevice'), Out(Pointer(UINT), 'pFlags')], sideeffects=False), ] IDXGIFactory4.methods += [ StdMethod(HRESULT, 'EnumAdapterByLuid', [(LUID, 'AdapterLuid'), (REFIID, 'riid'), Out(Pointer(ObjPointer(Void)), 'ppvAdapter')]), StdMethod(HRESULT, 'EnumWarpAdapter', [(REFIID, 'riid'), Out(Pointer(ObjPointer(Void)), 'ppvAdapter')]), ] IDXGIAdapter3.methods += [ StdMethod(HRESULT, 'RegisterHardwareContentProtectionTeardownStatusEvent', [(HANDLE, 'hEvent'), Out(Pointer(DWORD), 'pdwCookie')], sideeffects=False), StdMethod(Void, 'UnregisterHardwareContentProtectionTeardownStatus', [(DWORD, 'dwCookie')], sideeffects=False), StdMethod(HRESULT, 'QueryVideoMemoryInfo', [(UINT, 'NodeIndex'), (DXGI_MEMORY_SEGMENT_GROUP, 'MemorySegmentGroup'), Out(Pointer(DXGI_QUERY_VIDEO_MEMORY_INFO), 'pVideoMemoryInfo')], sideeffects=False), StdMethod(HRESULT, 'SetVideoMemoryReservation', [(UINT, 'NodeIndex'), (DXGI_MEMORY_SEGMENT_GROUP, 'MemorySegmentGroup'), (UINT64, 'Reservation')]), StdMethod(HRESULT, 'RegisterVideoMemoryBudgetChangeNotificationEvent', [(HANDLE, 'hEvent'), Out(Pointer(DWORD), 'pdwCookie')], sideeffects=False), StdMethod(Void, 'UnregisterVideoMemoryBudgetChangeNotification', [(DWORD, 'dwCookie')], sideeffects=False), ] dxgi.addInterfaces([ IDXGISwapChain3, IDXGIOutput4, IDXGIFactory4, IDXGIAdapter3, ]) # # DXGI 1.5 # DXGI_HDR_METADATA_TYPE = Enum('DXGI_HDR_METADATA_TYPE', [ 'DXGI_HDR_METADATA_TYPE_NONE', 'DXGI_HDR_METADATA_TYPE_HDR10', ]) DXGI_HDR_METADATA_HDR10 = Struct('DXGI_HDR_METADATA_HDR10', [ (Array(UINT16, 2), 'RedPrimary'), (Array(UINT16, 2), 'GreenPrimary'), (Array(UINT16, 2), 'BluePrimary'), (Array(UINT16, 2), 'WhitePoint'), (UINT, 'MaxMasteringLuminance'), (UINT, 'MinMasteringLuminance'), (UINT16, 'MaxContentLightLevel'), (UINT16, 'MaxFrameAverageLightLevel'), ]) DXGI_OFFER_RESOURCE_FLAGS = FakeEnum(UINT, [ 'DXGI_OFFER_RESOURCE_FLAG_ALLOW_DECOMMIT', ]) DXGI_RECLAIM_RESOURCE_RESULTS = Enum('DXGI_RECLAIM_RESOURCE_RESULTS', [ 'DXGI_RECLAIM_RESOURCE_RESULT_OK', 'DXGI_RECLAIM_RESOURCE_RESULT_DISCARDED', 'DXGI_RECLAIM_RESOURCE_RESULT_NOT_COMMITTED', ]) DXGI_FEATURE, DXGI_FEATURE_DATA = EnumPolymorphic('DXGI_FEATURE', 'Feature', [ ('DXGI_FEATURE_PRESENT_ALLOW_TEARING', Pointer(BOOL)), ], Blob(Void, "FeatureSupportDataSize"), False) IDXGIOutput5 = Interface('IDXGIOutput5', IDXGIOutput4) IDXGISwapChain4 = Interface('IDXGISwapChain4', IDXGISwapChain3) IDXGIDevice4 = Interface('IDXGIDevice4', IDXGIDevice3) IDXGIFactory5 = Interface('IDXGIFactory5', IDXGIFactory4) IDXGIOutput5.methods += [ StdMethod(HRESULT, 'DuplicateOutput1', [(ObjPointer(IUnknown), 'pDevice'), (UINT, 'Flags'), (UINT, 'SupportedFormatsCount'), (Array(Const(DXGI_FORMAT), 'SupportedFormatsCount'), 'pSupportedFormats'), Out(Pointer(ObjPointer(IDXGIOutputDuplication)), 'ppOutputDuplication')]), ] IDXGISwapChain4.methods += [ StdMethod(HRESULT, 'SetHDRMetaData', [(DXGI_HDR_METADATA_TYPE, 'Type'), (UINT, 'Size'), (Blob(Void, 'Size'), 'pMetaData')]), ] IDXGIDevice4.methods += [ StdMethod(HRESULT, 'OfferResources1', [(UINT, 'NumResources'), (Array(Const(ObjPointer(IDXGIResource)), 'NumResources'), 'ppResources'), (DXGI_OFFER_RESOURCE_PRIORITY, 'Priority'), (DXGI_OFFER_RESOURCE_FLAGS, 'Flags')]), StdMethod(HRESULT, 'ReclaimResources1', [(UINT, 'NumResources'), (Array(Const(ObjPointer(IDXGIResource)), 'NumResources'), 'ppResources'), Out(Array(DXGI_RECLAIM_RESOURCE_RESULTS, 'NumResources'), 'pResults')]), ] IDXGIFactory5.methods += [ StdMethod(HRESULT, 'CheckFeatureSupport', [(DXGI_FEATURE, 'Feature'), Out(DXGI_FEATURE_DATA, 'pFeatureSupportData'), (UINT, 'FeatureSupportDataSize')], sideeffects=False), ] dxgi.addInterfaces([ IDXGIOutput5, IDXGISwapChain4, IDXGIDevice4, IDXGIFactory5, ]) # # DXGI 1.6 # DXGI_ADAPTER_FLAG3 = Enum('DXGI_ADAPTER_FLAG3', [ 'DXGI_ADAPTER_FLAG3_NONE', 'DXGI_ADAPTER_FLAG3_REMOTE', 'DXGI_ADAPTER_FLAG3_SOFTWARE', 'DXGI_ADAPTER_FLAG3_ACG_COMPATIBLE', 'DXGI_ADAPTER_FLAG3_FORCE_DWORD', 'DXGI_ADAPTER_FLAG3_SUPPORT_MONITORED_FENCES', 'DXGI_ADAPTER_FLAG3_SUPPORT_NON_MONITORED_FENCES', 'DXGI_ADAPTER_FLAG3_KEYED_MUTEX_CONFORMANCE', ]) DXGI_ADAPTER_DESC3 = Struct('DXGI_ADAPTER_DESC3', [ (WString, 'Description'), (UINT, 'VendorId'), (UINT, 'DeviceId'), (UINT, 'SubSysId'), (UINT, 'Revision'), (SIZE_T, 'DedicatedVideoMemory'), (SIZE_T, 'DedicatedSystemMemory'), (SIZE_T, 'SharedSystemMemory'), (LUID, 'AdapterLuid'), (DXGI_ADAPTER_FLAG3, 'Flags'), (DXGI_GRAPHICS_PREEMPTION_GRANULARITY, 'GraphicsPreemptionGranularity'), (DXGI_COMPUTE_PREEMPTION_GRANULARITY, 'ComputePreemptionGranularity'), ]) DXGI_OUTPUT_DESC1 = Struct('DXGI_OUTPUT_DESC1', [ (WString, 'DeviceName'), (RECT, 'DesktopCoordinates'), (BOOL, 'AttachedToDesktop'), (DXGI_MODE_ROTATION, 'Rotation'), (HMONITOR, 'Monitor'), (UINT, 'BitsPerColor'), (DXGI_COLOR_SPACE_TYPE, 'ColorSpace'), (Array(FLOAT, 2), 'RedPrimary'), (Array(FLOAT, 2), 'GreenPrimary'), (Array(FLOAT, 2), 'BluePrimary'), (Array(FLOAT, 2), 'WhitePoint'), (FLOAT, 'MinLuminance'), (FLOAT, 'MaxLuminance'), (FLOAT, 'MaxFullFrameLuminance'), ]) DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS = Flags(UINT, [ 'DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN', 'DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_WINDOWED', 'DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED', ]) DXGI_GPU_PREFERENCE = Enum('DXGI_GPU_PREFERENCE', [ 'DXGI_GPU_PREFERENCE_UNSPECIFIED', 'DXGI_GPU_PREFERENCE_MINIMUM_POWER', 'DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE', ]) IDXGIFactory6 = Interface('IDXGIFactory6', IDXGIFactory5) IDXGIAdapter4 = Interface('IDXGIAdapter4', IDXGIAdapter3) IDXGIOutput6 = Interface('IDXGIOutput6', IDXGIOutput5) IDXGIAdapter4.methods += [ StdMethod(HRESULT, 'GetDesc3', [Out(Pointer(DXGI_ADAPTER_DESC3), 'pDesc')], sideeffects=False), ] IDXGIOutput6.methods += [ StdMethod(HRESULT, 'GetDesc1', [Out(Pointer(DXGI_OUTPUT_DESC1), 'pDesc')], sideeffects=False), StdMethod(HRESULT, 'CheckHardwareCompositionSupport', [Out(Pointer(DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS), 'pFlags')], sideeffects=False), ] IDXGIFactory6.methods += [ StdMethod(HRESULT, 'EnumAdapterByGpuPreference', [(UINT, 'Adapter'), (DXGI_GPU_PREFERENCE, 'GpuPreference'), (REFIID, 'riid'), Out(Pointer(ObjPointer(Void)), 'ppvAdapter')]), ] dxgi.addInterfaces([ IDXGIFactory6, IDXGIAdapter4, IDXGIOutput6, ]) dxgi.addFunctions([ StdFunction(HRESULT, "DXGIDeclareAdapterRemovalSupport", [], sideeffects=False), ])
[ 29113, 29113, 7804, 2235, 198, 2, 198, 2, 15069, 1946, 37754, 11, 3457, 198, 2, 15069, 2813, 5264, 376, 261, 2363, 64, 198, 2, 1439, 6923, 33876, 13, 198, 2, 198, 2, 2448, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597,...
2.2377
21,544
import numpy as np import cv2 import glob import matplotlib.pyplot as plt
[ 11748, 299, 32152, 355, 45941, 198, 11748, 269, 85, 17, 198, 11748, 15095, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83 ]
3.041667
24
""" module logging""" # logging
[ 37811, 8265, 18931, 37811, 628, 198, 2, 18931, 198 ]
3.777778
9
# Copyright 2021 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Pool actions. """ # isort: STDLIB import os from collections import defaultdict # isort: THIRDPARTY from justbytes import Range from .._constants import PoolMaintenanceErrorCode from .._errors import ( StratisCliAggregateError, StratisCliEngineError, StratisCliIncoherenceError, StratisCliInUseOtherTierError, StratisCliInUseSameTierError, StratisCliNameConflictError, StratisCliNoChangeError, StratisCliPartialChangeError, StratisCliPartialFailureError, ) from .._stratisd_constants import BlockDevTiers, PoolActionAvailability, StratisdErrors from ._connection import get_object from ._constants import TOP_OBJECT from ._formatting import get_property, print_table, size_triple, to_hyphenated from ._utils import get_clevis_info def _generate_pools_to_blockdevs(managed_objects, to_be_added, tier): """ Generate a map of pools to which block devices they own :param managed_objects: the result of a GetManagedObjects call :type managed_objects: dict of str * dict :param to_be_added: the blockdevs to be added :type to_be_added: frozenset of str :param tier: tier to search for blockdevs to be added :type tier: _stratisd_constants.BlockDevTiers :returns: a map of pool names to sets of strings containing blockdevs they own :rtype: dict of str * frozenset of str """ # pylint: disable=import-outside-toplevel from ._data import MODev, MOPool, devs, pools pool_map = dict( (path, str(MOPool(info).Name())) for (path, info) in pools().search(managed_objects) ) pools_to_blockdevs = defaultdict(list) for modev in ( modev for modev in ( MODev(info) for (_, info) in devs(props={"Tier": tier}).search(managed_objects) ) if str(modev.Devnode()) in to_be_added ): pools_to_blockdevs[pool_map[modev.Pool()]].append(str(modev.Devnode())) return dict( (pool, frozenset(blockdevs)) for pool, blockdevs in pools_to_blockdevs.items() ) def _check_opposite_tier(managed_objects, to_be_added, other_tier): """ Check whether specified blockdevs are already in the other tier. :param managed_objects: the result of a GetManagedObjects call :type managed_objects: dict of str * dict :param to_be_added: the blockdevs to be added :type to_be_added: frozenset of str :param other_tier: the other tier, not the one requested :type other_tier: _stratisd_constants.BlockDevTiers :raises StratisCliInUseOtherTierError: if blockdevs are used by other tier """ pools_to_blockdevs = _generate_pools_to_blockdevs( managed_objects, to_be_added, other_tier ) if pools_to_blockdevs != {}: raise StratisCliInUseOtherTierError( pools_to_blockdevs, BlockDevTiers.DATA if other_tier == BlockDevTiers.CACHE else BlockDevTiers.CACHE, ) def _check_same_tier(pool_name, managed_objects, to_be_added, this_tier): """ Check whether specified blockdevs are already in the tier to which they are to be added. :param managed_objects: the result of a GetManagedObjects call :type managed_objects: dict of str * dict :param to_be_added: the blockdevs to be added :type to_be_added: frozenset of str :param this_tier: the tier requested :type this_tier: _stratisd_constants.BlockDevTiers :raises StratisCliPartialChangeError: if blockdevs are used by this tier :raises StratisCliInUseSameTierError: if blockdevs are used by this tier in another pool """ pools_to_blockdevs = _generate_pools_to_blockdevs( managed_objects, to_be_added, this_tier ) owned_by_current_pool = frozenset(pools_to_blockdevs.get(pool_name, [])) owned_by_other_pools = dict( (pool, devnodes) for pool, devnodes in pools_to_blockdevs.items() if pool_name != pool ) if owned_by_current_pool != frozenset(): raise StratisCliPartialChangeError( "add to cache" if this_tier == BlockDevTiers.CACHE else "add to data", to_be_added.difference(owned_by_current_pool), to_be_added.intersection(owned_by_current_pool), ) if owned_by_other_pools != {}: raise StratisCliInUseSameTierError(owned_by_other_pools, this_tier) def _fetch_locked_pools_property(proxy): """ Fetch the LockedPools property from stratisd. :param proxy: proxy to the top object in stratisd :return: a representation of unlocked devices :rtype: dict :raises StratisCliEngineError: """ # pylint: disable=import-outside-toplevel from ._data import Manager return Manager.Properties.LockedPools.Get(proxy)
[ 2, 15069, 33448, 2297, 10983, 11, 3457, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198, 2,...
2.658026
2,006
# -*- coding: utf-8 -*- # Author: Ivan Senin import calendar import time import datetime as dt import json
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 6434, 25, 21798, 2311, 259, 198, 198, 11748, 11845, 198, 11748, 640, 198, 11748, 4818, 8079, 355, 288, 83, 198, 11748, 33918, 628 ]
2.868421
38
from datetime import datetime, timezone from enum import Enum from typing import Dict, List, Optional import pydantic from fastapi import HTTPException, Path, status from pydantic import BaseModel, EmailStr, Field from contaxy.schema.exceptions import ClientValueError from contaxy.schema.shared import MAX_DESCRIPTION_LENGTH from contaxy.utils.fastapi_utils import as_form USERS_KIND = "users" ADMIN_ROLE = "roles/admin" USER_ROLE = "roles/user" contaxy_token_purposes = {purpose for purpose in TokenPurpose} # Oauth Specific Code # TODO: Replaced with pydantic class # class OAuth2TokenRequestForm: # """OAuth2 Token Endpoint Request Form.""" # def __init__( # self, # grant_type: OAuth2TokenGrantTypes = Form( # ..., # description="Grant type. Determines the mechanism used to authorize the creation of the tokens.", # ), # username: Optional[str] = Form( # None, description="Required for `password` grant type. The users username." # ), # password: Optional[str] = Form( # None, description="Required for `password` grant type. The users password." # ), # scope: Optional[str] = Form( # None, # description="Scopes that the client wants to be included in the access token. List of space-delimited, case-sensitive strings", # ), # client_id: Optional[str] = Form( # None, # description="The client identifier issued to the client during the registration process", # ), # client_secret: Optional[str] = Form( # None, # description=" The client secret. The client MAY omit the parameter if the client secret is an empty string.", # ), # code: Optional[str] = Form( # None, # description="Required for `authorization_code` grant type. The value is what was returned from the authorization endpoint.", # ), # redirect_uri: Optional[str] = Form( # None, # description="Required for `authorization_code` grant type. Specifies the callback location where the authorization was sent. This value must match the `redirect_uri` used to generate the original authorization_code.", # ), # refresh_token: Optional[str] = Form( # None, # description="Required for `refresh_token` grant type. The refresh token previously issued to the client.", # ), # state: Optional[str] = Form( # None, # description="An opaque value used by the client to maintain state between the request and callback. The parameter SHOULD be used for preventing cross-site request forgery.", # ), # set_as_cookie: Optional[bool] = Form( # False, # description="If `true`, the access (and refresh) token will be set as cookie instead of the response body.", # ), # ): # self.grant_type = grant_type # self.username = username # self.password = password # self.scopes = [] # if scope: # self.scopes = str(scope).split() # self.client_id = client_id # self.client_secret = client_secret # self.code = code # self.redirect_uri = redirect_uri # self.refresh_token = refresh_token # self.state = state # self.set_as_cookie = set_as_cookie # TODO: Not used right now # class OAuth2AuthorizeRequestForm: # """OAuth2 Authorize Endpoint Request Form.""" # def __init__( # self, # response_type: AuthorizeResponseType = Form( # ..., # description="Either code for requesting an authorization code or token for requesting an access token (implicit grant).", # ), # client_id: Optional[str] = Form( # None, description="The public identifier of the client." # ), # redirect_uri: Optional[str] = Form(None, description="Redirection URL."), # scope: Optional[str] = Form( # None, description="The scope of the access request." # ), # state: Optional[str] = Form( # None, # description="An opaque value used by the client to maintain state between the request and callback. The parameter SHOULD be used for preventing cross-site request forgery", # ), # nonce: Optional[str] = Form(None), # ): # self.response_type = response_type # self.client_id = client_id # self.redirect_uri = redirect_uri # self.scope = scope # self.state = state # self.nonce = nonce USER_ID_PARAM = Path( ..., title="User ID", description="A valid user ID.", # TODO: add length restriction ) # User Models
[ 6738, 4818, 8079, 1330, 4818, 8079, 11, 640, 11340, 198, 6738, 33829, 1330, 2039, 388, 198, 6738, 19720, 1330, 360, 713, 11, 7343, 11, 32233, 198, 198, 11748, 279, 5173, 5109, 198, 6738, 3049, 15042, 1330, 14626, 16922, 11, 10644, 11, ...
2.477727
1,953
import setuptools from hugdatafast.__init__ import __version__ with open("README.md", "r") as fh: long_description = fh.read() REQUIRED_PKGS = [ 'fastai>=2.0.8', 'fastscore>=1.0.1', # change of store_attr api 'datasets', ] setuptools.setup( name="hugdatafast", version=__version__, author="Richard Wang", author_email="richardyy1188@gmail.com", description="The elegant bridge between hugginface data and fastai", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/richarddwang/hugdatafast", license='Apache 2.0', packages=setuptools.find_packages(), classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Topic :: Scientific/Engineering :: Artificial Intelligence", ], python_requires='>=3.6', install_requires=REQUIRED_PKGS, keywords='datasets machine learning datasets metrics fastai huggingface', )
[ 11748, 900, 37623, 10141, 198, 6738, 16225, 7890, 7217, 13, 834, 15003, 834, 1330, 11593, 9641, 834, 198, 198, 4480, 1280, 7203, 15675, 11682, 13, 9132, 1600, 366, 81, 4943, 355, 277, 71, 25, 198, 220, 220, 220, 890, 62, 11213, 796, ...
2.71754
439
import pytest from leapp.repository.actor_definition import ActorDefinition, ActorInspectionFailedError, MultipleActorsError from leapp.exceptions import UnsupportedDefinitionKindError from leapp.repository import DefinitionKind from helpers import repository_dir import logging import mock _FAKE_META_DATA = { 'description': 'Fake Description', 'class_name': 'FakeActor', 'name': 'fake-actor', 'path': 'actors/test', 'tags': (), 'consumes': (), 'produces': (), 'dialogs': (), }
[ 11748, 12972, 9288, 198, 198, 6738, 443, 1324, 13, 260, 1930, 37765, 13, 11218, 62, 46758, 1330, 27274, 36621, 11, 27274, 818, 31308, 37, 6255, 12331, 11, 20401, 32, 5217, 12331, 198, 6738, 443, 1324, 13, 1069, 11755, 1330, 791, 15999, ...
3.077844
167
from django.db import models # Create your models here. from utils.models import BaseModel
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 201, 198, 201, 198, 2, 13610, 534, 4981, 994, 13, 201, 198, 6738, 3384, 4487, 13, 27530, 1330, 7308, 17633, 201, 198, 201, 198, 201, 198, 201, 198 ]
2.914286
35
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Cltwit is a command line twitter utility Author : Jrme Launay Date : 2013 """ import os import sys import re import getopt import gettext import sqlite3 import webbrowser import ConfigParser from sqlite2csv import sqlite2csv from cltwitdb import cltwitdb from utils import LocalTimezone from cltwitreport import TweetsReport APP_NAME = 'cltwit' LOC_PATH = os.path.dirname(__file__) + '/locale' gettext.find(APP_NAME, LOC_PATH) gettext.install(APP_NAME, LOC_PATH, True) try: import tweepy except ImportError: print(_("Veuillez installer tweetpy https://github.com/tweepy/tweepy")) sys.exit() # Rpertoire pour conf et bdd __cltwitdir__ = os.path.expanduser("~/.config/cltwit") # Fichier de configuration __configfile__ = __cltwitdir__ + "/cltwit.conf" # base de donnes et table sqlite __dblocation__ = __cltwitdir__ + '/data.db' __tablename__ = 'twitter' __Local__ = LocalTimezone() # gestion des couleurs sur le terminal BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) def has_colours(stream): """Vrifier la prise en charge des couleurs par le terminal""" if not hasattr(stream, "isatty"): return False if not stream.isatty(): return False # couleurs auto sur un TTY try: import curses curses.setupterm() return curses.tigetnum("colors") > 2 except: # Si erreur on suppose false return False __has_colours__ = has_colours(sys.stdout) def printout(text, colour=WHITE): """Print en couleur""" if __has_colours__: seq = "\x1b[1;%dm" % (30 + colour) + text + "\x1b[0m" sys.stdout.write(seq) else: sys.stdout.write(text.encode("Utf-8")) def checkdb(): """ Vrifier la prsence de la bdd sqlite et la crer si absente """ if (not os.path.exists(__dblocation__)): printout(_(u"Vous devez d'abord lancer la commande --database create \ pour crer une base de donnes de vos tweets."), RED) sys.exit() def checkconfig(): """Rcuprer la configuration ou la crer""" # On ouvre le fichier de conf config = ConfigParser.RawConfigParser() try: config.read(__configfile__) if config.has_option('twitterapi', 'access_token'): access_token = config.get('twitterapi', 'access_token') if config.has_option('twitterapi', 'access_password'): access_password = config.get('twitterapi', 'access_password') except: pass auth = tweepy.OAuthHandler("Jus1rnqM6S0WojJfOH1kQ", "AHQ5sTC8YYArHilXmqnsstOivY6ygQ2N27L1zBwk") # Si aucune conf , autorisation de connexion twitter via OAuth if not(config.has_option('twitterapi', 'access_token') and config.has_option('twitterapi', 'access_password')): # On ouvre le navigateur web pour rcuprer le numro d'autorisation while True: try: webbrowser.open(auth.get_authorization_url()) var = raw_input(_("Entrez le token !\n")) auth.get_access_token(var) except Exception, e: print(str(e)) continue break var = auth.access_token # On rcupre le token et le password access_password = str(var).split("&")[0].split("=")[1] access_token = str(var).split("&")[1].split("=")[1] # crire le fichier de conf avec les informations rcupres try: cfgfile = open(__configfile__, 'w') if not(config.has_section('twitterapi')): config.add_section('twitterapi') config.set('twitterapi', 'access_token', access_token) config.set('twitterapi', 'access_password', access_password) config.write(cfgfile) except IOError: pass finally: cfgfile.close() else: # Si un fichier de conf existait dj auth.set_access_token(access_token, access_password) return auth def login(): """ Se connecter l'api twitter via tweepy """ auth = checkconfig() api = tweepy.API(auth) # On vrifie la connexion l'api en rcuprant le user name try: twittername = api.me().screen_name except Exception, e: if 'Unable to get username' in (str(e)): printout(_(u"Impossible de s'authentifier avec l'api Twitter.\ Fonctionne en mode dconnect"), RED) print("\n") twittername = "offline_mode" printout(_(u"Authentifi avec le user twitter {0}").format(twittername.decode('utf-8')), GREEN) print("\n") return api, auth, twittername def get_friends_followers(api): """Renvoie la liste des id des friends et followers""" friend_id = [] follower_id = [] printout(_(u"Rcupration des Followers..."), YELLOW) print("\n") for follower in tweepy.Cursor(api.followers).items(): follower_id.append(follower.id) printout((u"Rcupration des Friends..."), YELLOW) print("\n") for friend in tweepy.Cursor(api.friends).items(): friend_id.append(friend.id) return friend_id, follower_id def get_diff(liste1, liste2): """Renvoie les objets de liste1 qui ne sont pas dans liste2""" return list(set(liste1).difference(set(liste2))) def follow_users(api, user): """Suivre une personne""" try: api.create_friendship(user) printout(_(u"Vous suivez maintenant {0}").format(api.get_user(user).screen_name.decode('utf-8')), GREEN) except Exception, e: print(e) def unfollow_user(api, user): """Cesser de suivre une personne""" try: api.destroy_friendship(user) printout(_(u"Vous ne suivez plus {0}").format(api.get_user(user).screen_name.decode('utf-8')), GREEN) except Exception, e: print(e) def main(argv=None): """ Point d'entre """ # Si le rpertoire pour la conf et la base de donnes n'existe pas le crer if not os.path.exists(__cltwitdir__): os.makedirs(__cltwitdir__) #~ twittername = "offline_mode" # Traitement des arguments if argv is None: argv = sys.argv if len(argv) == 1: help() try: opts, args = getopt.getopt(sys.argv[1:], "r:ahfut:o:s:d:", ["report", "api", "help", "follow", "unfollow", "tweet=", "output=", "search=", "database="]) except getopt.GetoptError, err: print(err) help() sys.exit() # traitement des options for option, value in opts: if option in ('-a', '--api'): api, auth, twittername = login() res = api.rate_limit_status() rtime = res['reset_time'] rhits = res['remaining_hits'] hlimit = res['hourly_limit'] from dateutil.parser import parse drtime = parse(rtime) printout(_("Informations sur l'utilisation de l'api Twitter"), YELLOW) print("\n") # Dfinir l'heure locale qui correspond l'heure renvoye # par l'api Twitter rlocaltime = drtime.astimezone(__Local__) printout(_("Maximum d'appels par heure: "), BLUE) print hlimit printout(_("Nombre d'appels restants: "), BLUE) print rhits printout(_("Heure du prochain reset: "), BLUE) print rlocaltime.strftime("%H:%M %Y-%m-%d") if option in ('-r', '--report'): api, auth, twittername = login() checkdb() conn = sqlite3.connect(__dblocation__) c = conn.cursor() c.execute("select substr(date, 1,4) from twitter order by date asc limit 1") dmois = c.fetchone()[0] c.execute("select substr(date, 1,4) from twitter order by date desc limit 1") fmois = c.fetchone()[0] # Requte des donnes exporter dd = dict() for a in range(int(dmois), int(fmois) + 1): result = [] for m in range(1, 13): mois = ('{num:02d}'.format(num=m)) c.execute("select count(*) from twitter where substr(date, 1,4) = '{0}' and substr(date, 6,2) = '{1}'".format(a, mois)) result.append(c.fetchone()[0]) dd[a] = result c.close() conn.close() treport = TweetsReport(value) # twittername = "offline" treport.ecrireTitre(twittername) nb = 0 for annee, donnees in dd.items(): nb += 1 if nb == 4: treport.NextPage() nb = 1 saut = 0 if nb == 1: saut = 0 if nb == 2: saut = 200 if nb == 3: saut = 400 treport.ecrireLegende(saut, annee, donnees) treport.addPie(saut, donnees) treport.save() printout(_(u"Report {0} cr !").format(value), GREEN) print("\n") sys.exit(0) if option in ('-d', '--database'): if value in ('u', 'update'): # Se connecter l'api twitter api, auth, twittername = login() # Mettre jour la base de donnes db = cltwitdb(__dblocation__, __tablename__) printout(_(u"Mise jour de la base de donnes de {0}").format(twittername.decode('utf-8')), YELLOW) print("\n") nb = db.update(api, twittername) printout(_(u"Ajout de {0} tweet(s) dans la base de donnes.").format(nb), GREEN) if value in ('c', 'create'): # Se connecter l'api twitter api, auth, twittername = login() # Crer la base de donnes db = cltwitdb(__dblocation__, __tablename__) printout(_(u"Cration de la liste des tweets de ") + twittername.decode('utf-8'), YELLOW) db.create(api, twittername) printout(_(u"Base de donnes cre"), GREEN) sys.exit() #~ database_create(api,twittername) if option in ("-o", "--output"): # Exporter en csv checkdb() conn = sqlite3.connect(__dblocation__) c = conn.cursor() # Requte des donnes exporter c.execute('select date, tweet, url from {0} order by date desc'.format(__tablename__)) # On appelle la classe sqlite2csv qui se charge de l'export export = sqlite2csv(open(value, "wb")) # Entte du fichier csv export.writerow(["Date", "Tweet", "URL"]) # Lignes du fichier csv export.writerows(c) # On ferme la connexion sqlite et le curseur c.close() conn.close() printout(_(u"Fichier csv {0} cr.").format(value.decode('utf-8')), GREEN) sys.exit() if option in ("-s", "--search"): # Rechercher un motif dans la base des tweets checkdb() printout(_(u"Recherche de {0} dans vos anciens tweets...") .format(value.decode('utf-8')), YELLOW) print("\n") # la mthode search retourne un tuple avec les champs # qui contiennent le motif db = cltwitdb(__dblocation__, __tablename__) results = db.search(value, "tweet") for result in results: print((u"{0} -> {1}\n{2}\n\n").format(result[1].decode('utf-8'), result[4].decode('utf-8'), result[2].decode('utf-8'))) if option in ("-u", "--unfollow"): # Se connecter l'api twitter api, auth, twittername = login() # Crer les liste friend et followers (par id) friend_id, follower_id = get_friends_followers(api) # Cration des listes follow et unfollow follow_liste = get_diff(follower_id, friend_id) unfollow_liste = get_diff(friend_id, follower_id) # Un-follow printout(_("Vous suivez {0} personnes qui ne vous suivent pas.") .format(len(unfollow_liste)), YELLOW) print("\n") printout(_("Voulez changer cela ? (o/N)"), BLUE) print("\n") reponse = raw_input("> ") if (reponse.lower() == 'o' or reponse.lower() == 'y'): for user in unfollow_liste: printout(_("Voulez-vous cesser de suivre {0} ? (o/N)") .format(api.get_user(user).screen_name), BLUE) print("\n") reponse = raw_input("> ") if (reponse.lower() == 'o' or reponse.lower() == 'y'): unfollow_user(api, user) if option in ("-f", "--follow"): # Se connecter l'api twitter api, auth, twittername = login() # Crer les liste friend et followers (par id) friend_id, follower_id = get_friends_followers(api) # Cration des listes follow et unfollow follow_liste = get_diff(follower_id, friend_id) unfollow_liste = get_diff(friend_id, follower_id) # follow printout(_("{0} personnes vous suivent alors que vous ne les suivez pas.") .format(len(follow_liste)), YELLOW) print("\n") printout(_("Voulez changer cela ? (o/N)"), BLUE) print("\n") reponse = raw_input("> ") if (reponse.lower() == 'o' or reponse.lower() == 'y'): for user in follow_liste: printout(_("Voulez-vous suivre {0} ? (o/N)" .format(api.get_user(user).screen_name)), BLUE) print("\n") reponse = raw_input("> ") if (reponse.lower() == 'o' or reponse.lower() == 'y'): follow_users(api, user) if option in ("-t", "--tweet"): # Se connecter l'api twitter api, auth, twittername = login() # Envoyer un tweet tweet_size = len(re.sub("https://\S*", "X"*23, re.sub("http://\S*", "X"*22, value))) if tweet_size < 141: api.update_status(value) print("\n") printout(_(u"Tweet envoy !"), GREEN) else: printout(_(u"La limite pour un tweet est de 140 caractres, votre message \ fait {0} caractres de trop").format(str(tweet_size - 140).decode('utf-8')), RED) sys.exit() if option in ("-h", "--help"): help() if __name__ == "__main__": try: sys.exit(main()) except KeyboardInterrupt: print("\n") print(_(u"Merci d'avoir utilis clitwit !"))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 17, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 34, 2528, 39289, 318, 257, 3141, 1627, 17044, 10361, 198, 13838, 1058, 7504, 1326, 19826, 323, 198, 104...
1.998256
7,456
# @AUTHOR : lonsty # @DATE : 2020/3/28 18:01
[ 2, 2488, 32, 24318, 1581, 1058, 300, 261, 34365, 198, 2, 2488, 35, 6158, 1058, 12131, 14, 18, 14, 2078, 1248, 25, 486, 628, 628, 198 ]
1.884615
26
import requests from bs4 import BeautifulSoup import re # # User-Agent headers = { "User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'} # # if __name__ == '__main__': get_weather() get_bar()
[ 11748, 7007, 198, 6738, 275, 82, 19, 1330, 23762, 50, 10486, 198, 11748, 302, 198, 198, 2, 220, 198, 2, 11787, 12, 36772, 198, 50145, 796, 1391, 198, 220, 220, 220, 366, 12982, 12, 36772, 1298, 705, 44, 8590, 5049, 14, 20, 13, 15,...
2.354331
127
import numpy as np import math import matplotlib.pyplot as plt U = 5 # equival a l'E R = 2 # equival a R1 R2 = 3 P = 1.2 Vt = 0.026 Is = 0.000005 n = 200 # profunditat Vd = np.zeros(n) # sries Vl = np.zeros(n) I1 = np.zeros(n) I1[0] = U / R # inicialitzaci de les sries Vd[0] = Vt * math.log(1 + I1[0] / Is) Vl[0] = P / I1[0] for i in range(1, n): # clcul dels coeficients I1[i] = (1 / R + 1 / R2) * (-Vd[i - 1] - Vl[i - 1]) Vd[i] = (i * Vt * I1[i] - convVd(Vd, I1, i)) / (i * (Is + I1[0])) Vl[i] = -convVlI(Vl, I1, i) / I1[0] If = sum(I1) Vdf = sum(Vd) Vlf = sum(Vl) print('I1: ' + str(If)) print('Vd: ' + str(Vdf)) print('Vl: ' + str(Vlf)) print('P: ' + str(Vlf * If)) Vdfinal = np.zeros(n) # per tal de veure com evoluciona la tensi del dode for j in range(n): Vdfinal[j] = np.sum([Vd[:(j+1)]]) print(Vdfinal)
[ 11748, 299, 32152, 355, 45941, 198, 11748, 10688, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 198, 52, 796, 642, 220, 1303, 6854, 257, 300, 6, 36, 198, 49, 796, 362, 220, 1303, 6854, 257, 371, 16, 198, 49, 1...
1.836207
464
"""Errors."""
[ 37811, 9139, 5965, 526, 15931, 628, 628, 628, 628, 628, 628, 198 ]
2.166667
12
import torch from torch import nn as nn from torch import autograd
[ 11748, 28034, 198, 6738, 28034, 1330, 299, 77, 355, 299, 77, 198, 6738, 28034, 1330, 1960, 519, 6335, 628 ]
3.578947
19
import pytest from whylogs.app.session import get_or_create_session, get_session, get_logger, reset_default_session, session_from_config from whylogs.app.config import SessionConfig from whylogs.app.session import Session from pandas import util
[ 198, 198, 11748, 12972, 9288, 198, 6738, 1521, 6404, 82, 13, 1324, 13, 29891, 1330, 651, 62, 273, 62, 17953, 62, 29891, 11, 651, 62, 29891, 11, 651, 62, 6404, 1362, 11, 13259, 62, 12286, 62, 29891, 11, 6246, 62, 6738, 62, 11250, 1...
3.324675
77
import enum BASELINE = "baseline" ENERGY = "energy" MAX_PRICE = "max_price" START_PRICE = "starting_price" INCREMENT = "increment" MIN_PRICE = "min_price" MAX_LOT_SIZE = "max_lot_size_wh" NAMESERVER_AGENT_AMOUNT = 3 ATTRIBUTE_LIST_LENGTH = 50 NEXT_ENERGY_CONSUMPTION = "next_energy_consumption" NEXT_ENERGY_GENERATION = "next_energy_generation" ENERGY_DIFFERENCE = "energy_difference" ENERGY_MARKET_PRICE = "energy_market_price" WANTED_ENERGY = "wanted_energy" ENERGY_BUY_MAX_PRICE = "energy_buy_max_price" ENERGY_BUY_STARTING_PRICE = "energy_buy_starting_price" ENERGY_BUY_PRICE_INCREMENT = "energy_buy_price_increment" ENERGY_SELL_MIN_PRICE = "energy_sell_min_price"
[ 11748, 33829, 198, 198, 33, 1921, 3698, 8881, 796, 366, 12093, 4470, 1, 198, 1677, 1137, 31212, 796, 366, 22554, 1, 198, 22921, 62, 4805, 8476, 796, 366, 9806, 62, 20888, 1, 198, 2257, 7227, 62, 4805, 8476, 796, 366, 38690, 62, 2088...
2.296928
293
from django.contrib.auth.models import User from django.test import TestCase from django.test import Client from django.urls import reverse from target import models from django.utils import timezone # Create your tests here.
[ 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 11787, 198, 6738, 42625, 14208, 13, 9288, 1330, 6208, 20448, 198, 6738, 42625, 14208, 13, 9288, 1330, 20985, 198, 6738, 42625, 14208, 13, 6371, 82, 1330, 9575, 198, 6738, 24...
3.721311
61
""" Module for jenkinsapi views """ import six import logging from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.job import Job from jenkinsapi.custom_exceptions import NotFound log = logging.getLogger(__name__)
[ 37811, 198, 26796, 329, 474, 268, 5331, 15042, 5009, 198, 37811, 198, 11748, 2237, 198, 11748, 18931, 198, 198, 6738, 474, 268, 5331, 15042, 13, 48796, 5331, 8692, 1330, 21835, 14881, 198, 6738, 474, 268, 5331, 15042, 13, 21858, 1330, 1...
3.257143
70
""" Autonomous dataset collection of data for jetson nano John Marangola - marangol@bc.edu """ import datasets import json from datasets import Board, ChessPiece, PieceColor, PieceType #from realsense_utils import RealSenseCamera import preprocessing as pr import cv2 import pandas as pd import os from os.path import isfile, join import uuid import numpy as np import uuid from PIL import Image from PIL.ExifTags import TAGS RUN_CALIBRATION = False # Run calibration sequence or use preexisting board four corners data from config/setup.txt BOARD_SAVE_DEST= r"board_metadata.jpeg" # Where the debug metadata board visualization image is saved (to ensure we properly setup the metadata) TMP_DEST = "/home/spark/cv-chess/core/vision/tmp/" # Where images are temporarily saved before being uploaded to drive in a batch LOCAL_MD_FILENAME = "local_meta.json" LOCAL_METADATA_JSON_PATH = TMP_DEST + LOCAL_MD_FILENAME TL = [250, 115] BL = [250, 687] TR = [825, 115] BR = [825, 687] def get_sorted_time_saved(images): """ Given a list of image filenames, return a dictionary of image filename : time written to disk pairs. Purpose: for debugging dataset Args: images (list): List of image filenames Returns: dict: dict of image filenames """ image_dat = [] for image in images: imtmp = Image.open(image) tmp = imtmp.getexif() image_dat.append(tmp) dt = {} for exifdata in image_dat: idx = image_dat.index(exifdata) # iterating over all EXIF data fields for tag_id in exifdata: tag = TAGS.get(tag_id, tag_id) data = exifdata.get(tag_id) # decode bytes if isinstance(data, bytes): data = data.decode() # Add datetime field if tag == "DateTime": dt[images[idx]] = data print(f"{tag:25}: {data}") output = sorted(dt.items(), key=lambda eta: eta[1], reverse=False) print(output) dt = {} for item in output: dt[item[0]] = item[1] with open(TMP_DEST + "datetimes.json", "w") as wr: # dump to json json.dump(output, wr) return output if __name__ == "__main__": # Initialize camera realsense = RealSenseCamera() """ # Check if calibration sequence must be run if RUN_CALIBRATION: realsense.calibrate_board_pos() if realsense.get_board_corners() is None: print("Failed to run calibration. Exiting...") exit() """ """ board_meta = Board() # Add pieces to metadata csv board_meta.add_pieces({ "A1":ChessPiece(PieceType.KNIGHT, PieceColor.BLUE), "A2":ChessPiece(PieceType.PAWN, PieceColor.BLUE), "A3":ChessPiece(PieceType.PAWN, PieceColor.ORANGE) }) board_meta.display_board(dest=BOARD_SAVE_DEST) print(f"Verify board is correct output dest={BOARD_SAVE_DEST}.\nContine [Y] or Exit [E]?") validate = input() if validate.upper() == "E" or validate.upper() == "N": print("Exiting...") realsense.stop_pipeline() exit() files = [] files = [f for f in os.listdir(TMP_DEST) if isfile(os.path.join(TMP_DEST, f))] # Check to see if there is pre-existing .csv metadata to add to if LOCAL_MD_FILENAME in files: try: total_metadata = pd.read_csv(LOCAL_METADATA_JSON_PATH) except: total_metadata = pd.DataFrame() else: total_metadata = pd.DataFrame() # Loop through input while input() != "exit": img = realsense.capture_rgb_image() # Capture the image img = img[105:690, 348:940, :] img = rotate_image(img, 1.5) files = pr.board_to_64_files(img, base_directory=TMP_DEST) # Break image up into 64 files piece_types, piece_colors = [], [] batch_id = uuid.uuid1() for tile in sorted(files.keys()): temp = board_meta.get_chess_piece(tile) if temp is None: piece_types.append(None) piece_colors.append(None) else: piece_types.append(temp.piece_type.name) piece_colors.append(temp.piece_color.name) tmp_meta = pd.DataFrame({ "File" : [files[file] for file in files.keys()], "Position" : [file for file in files.keys()], "Piece Type" : piece_types, "Piece Color" : piece_colors, "Batch ID" : [batch_id for i in range(len(files.keys()))] }) frames = [total_metadata, tmp_meta] total_metadata = pd.concat(frames) # Concatenate dataframes print(total_metadata) total_metadata.to_csv(path_or_buf=LOCAL_METADATA_JSON_PATH) """ #pr.delete_board2_64_output(base_directory=TMP_DEST) FEN = "5P1R/1Q1RP1P1/3R1P2/QQPPK1R1/1B1K1N2/B1R2N1B/1N2B3R/2B1BN2".upper() last_input = None df = pd.DataFrame() while input() != "end": resp = input("[n] for new fen, [anything key to take an image] >") if resp == "new": fen = input("Enter a FEN:").upper() img = realsense.capture_rgb_image() # Capture the image print("Captured image") img = img[105:690, 348:940, :] img = rotate_image(img, 1.5) cv2.imwrite("original.jpg", img) # Get dict of positions temp_dict = fen_to_dict(FEN) tiles = pr.board_to_64_files(img, temp_dict, base_directory=TMP_DEST) # Break image up into 64 files data_frame = pd.DataFrame(tiles) data_frame = data_frame.transpose() frames = [df, data_frame] df = pd.concat(frames) # Concatenate dataframe csv_file = df.to_csv(TMP_DEST + 'my_csv.csv', header=False, index=False) # Close streams and end pipeline realsense.stop_pipeline()
[ 37811, 198, 16541, 38175, 27039, 4947, 286, 1366, 329, 20792, 261, 38706, 198, 198, 7554, 1526, 648, 5708, 532, 1667, 648, 349, 31, 15630, 13, 15532, 198, 37811, 198, 198, 11748, 40522, 198, 11748, 33918, 198, 6738, 40522, 1330, 5926, 1...
2.15818
2,769
import os import numpy as np import pandas as pd from nilearn import datasets from sbfc.parser import seed_base_connectivity seed = os.path.dirname(__file__) + "/data/difumo64_pcc.nii.gz"
[ 11748, 28686, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 6738, 299, 576, 1501, 1330, 40522, 198, 198, 6738, 264, 65, 16072, 13, 48610, 1330, 9403, 62, 8692, 62, 8443, 3458, 198, 198, 28826, 796...
2.671233
73
import unittest from translator import english_to_french, french_to_english if __name__ == "__main__": unittest.main()
[ 11748, 555, 715, 395, 198, 6738, 33417, 1330, 46932, 62, 1462, 62, 69, 3532, 11, 48718, 62, 1462, 62, 39126, 198, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, 198, 220, 220, 220, 555, 715, 395, 13, 12417, 3419 ]
2.928571
42
# Copyright 2019 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import numpy as np import mindspore.nn as nn from mindspore import Tensor, Parameter from mindspore import context from mindspore.common.api import _executor from mindspore.ops import composite as C from mindspore.ops import operations as P from tests.ut.python.ops.test_math_ops import VirtualLoss grad_all = C.GradOperation(get_all=True) def test_dmnet_train_step(): size = 8 context.set_auto_parallel_context(device_num=size, global_rank=0) input_ = Tensor(np.ones([4096, 4096]).astype(np.float32) * 0.01) net = GradWrap(NetWithLoss(MultiTransformer())) context.set_auto_parallel_context(parallel_mode="auto_parallel") net.set_auto_parallel() _executor.compile(net, input_)
[ 2, 15069, 13130, 43208, 21852, 1766, 1539, 12052, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198...
3.190709
409
""" Copyright 2015 Rackspace 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 cloudcafe.compute.events.models.base import ( EventBaseModel, EventBaseListModel)
[ 37811, 198, 15269, 1853, 37927, 13200, 198, 198, 26656, 15385, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 5832, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198, 1639, 743, 7...
3.748571
175
from __future__ import absolute_import # Copyright (c) 2010-2017 openpyxl import pytest from openpyxl.xml.functions import fromstring, tostring from openpyxl.tests.helper import compare_xml
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 2, 15069, 357, 66, 8, 3050, 12, 5539, 1280, 9078, 87, 75, 198, 198, 11748, 12972, 9288, 198, 198, 6738, 1280, 9078, 87, 75, 13, 19875, 13, 12543, 2733, 1330, 422, 8841, 11, 284, ...
3.16129
62
# Copyright (c) 2014-2021, Dr Alex Meakins, Raysect Project # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of the Raysect Project 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. import numpy as np from raysect.core.math.function.float.function3d.interpolate.interpolator3darray import Interpolator3DArray from matplotlib.colors import SymLogNorm, Normalize import scipy import sys from raysect.core.math.function.float.function3d.interpolate.tests.data.interpolator3d_test_data import \ TestInterpolatorLoadBigValues, TestInterpolatorLoadNormalValues, TestInterpolatorLoadSmallValues,\ TestInterpolatorLoadBigValuesUneven, TestInterpolatorLoadNormalValuesUneven, TestInterpolatorLoadSmallValuesUneven from raysect.core.math.function.float.function3d.interpolate.tests.test_interpolator_3d import X_LOWER, X_UPPER,\ NB_XSAMPLES, NB_X, X_EXTRAP_DELTA_MAX, PRECISION, Y_LOWER, Y_UPPER, NB_YSAMPLES, NB_Y, \ Y_EXTRAP_DELTA_MAX, EXTRAPOLATION_RANGE, large_extrapolation_range, Z_LOWER, Z_UPPER, \ NB_ZSAMPLES, NB_Z, Z_EXTRAP_DELTA_MAX, N_EXTRAPOLATION, uneven_linspace # Force scientific format to get the right number of significant figures np.set_printoptions(30000, linewidth=100, formatter={'float': lambda x_str: format(x_str, '.'+str(PRECISION)+'E')}, threshold=sys.maxsize) # Overwrite imported values here. VISUAL_NOT_TESTS = False if VISUAL_NOT_TESTS: NB_X = 51 NB_Y = 51 NB_Z = 51 NB_XSAMPLES = 101 NB_YSAMPLES = 101 NB_ZSAMPLES = 101 X_EXTRAP_DELTA_MIN = 0.04 Y_EXTRAP_DELTA_MIN = 0.04 Z_EXTRAP_DELTA_MIN = 0.04 BIG_VALUE_FACTOR = 20. SMALL_VALUE_FACTOR = -20. def docstring_test(): """ .. code-block:: python >>> from raysect.core.math.function.float.function3d.interpolate.interpolator3darray import Interpolator3DArray >>> >>> x = np.linspace(-1., 1., 20) >>> y = np.linspace(-1., 1., 20) >>> z = np.linspace(-1., 1., 20) >>> x_array, y_array, z_array = np.meshgrid(x, y, z, indexing='ij') >>> f = np.exp(-(x_array**2 + y_array**2 + z_array**2)) >>> interpolator3D = Interpolator3DArray(x, y, z, f, 'cubic', 'nearest', 1.0, 1.0, 1.0) >>> # Interpolation >>> interpolator3D(1.0, 1.0, 0.2) 0.1300281183136766 >>> # Extrapolation >>> interpolator3D(1.0, 1.0, 1.1) 0.0497870683678659 >>> # Extrapolation out of bounds >>> interpolator3D(1.0, 1.0, 2.1) ValueError: The specified value (z=2.1) is outside of extrapolation range. """ pass if __name__ == '__main__': # Calculate for big values, small values, or normal values big_values = False small_values = True log_scale = False uneven_spacing = False use_saved_datastore_spline_knots = True verbose_options = [False, True, False, False] if VISUAL_NOT_TESTS: index_x_in = 40 else: index_x_in = 4 index_y_in = 0 index_z_in = 0 index_y_plot = 0 index_z_plot = 0 print('Using scipy version', scipy.__version__) # Find the function values to be used if big_values: factor = np.power(10., BIG_VALUE_FACTOR) elif small_values: factor = np.power(10., SMALL_VALUE_FACTOR) else: factor = 1. if uneven_spacing: x_in = uneven_linspace(X_LOWER, X_UPPER, NB_X, offset_fraction=1./3.) y_in = uneven_linspace(Y_LOWER, Y_UPPER, NB_Y, offset_fraction=1./3.) z_in = uneven_linspace(Z_LOWER, Z_UPPER, NB_Z, offset_fraction=1./3.) else: x_in = np.linspace(X_LOWER, X_UPPER, NB_X) y_in = np.linspace(Y_LOWER, Y_UPPER, NB_Y) z_in = np.linspace(Z_LOWER, Z_UPPER, NB_Z) x_in_full, y_in_full, z_in_full = np.meshgrid(x_in, y_in, z_in, indexing='ij') f_in = function_to_spline(x_in_full, y_in_full, z_in_full, factor) if use_saved_datastore_spline_knots: if uneven_spacing: if big_values: reference_loaded_values = TestInterpolatorLoadBigValuesUneven() elif small_values: reference_loaded_values = TestInterpolatorLoadSmallValuesUneven() else: reference_loaded_values = TestInterpolatorLoadNormalValuesUneven() else: if big_values: reference_loaded_values = TestInterpolatorLoadBigValues() elif small_values: reference_loaded_values = TestInterpolatorLoadSmallValues() else: reference_loaded_values = TestInterpolatorLoadNormalValues() f_in = reference_loaded_values.data if verbose_options[0]: print('Save this to self.data in test_interpolator:\n', repr(f_in)) xsamples = np.linspace(X_LOWER, X_UPPER, NB_XSAMPLES) ysamples = np.linspace(Y_LOWER, Y_UPPER, NB_YSAMPLES) zsamples = np.linspace(Z_LOWER, Z_UPPER, NB_ZSAMPLES) xsamples_extrapolation, ysamples_extrapolation, zsamples_extrapolation = large_extrapolation_range( xsamples, ysamples, zsamples, EXTRAPOLATION_RANGE, N_EXTRAPOLATION ) # # Extrapolation x and y values xsamples_out_of_bounds, ysamples_out_of_bounds, zsamples_out_of_bounds, xsamples_in_bounds, ysamples_in_bounds, \ zsamples_in_bounds = get_extrapolation_input_values( X_LOWER, X_UPPER, Y_LOWER, Y_UPPER, Z_LOWER, Z_UPPER, X_EXTRAP_DELTA_MAX, Y_EXTRAP_DELTA_MAX, Z_EXTRAP_DELTA_MAX, X_EXTRAP_DELTA_MIN, Y_EXTRAP_DELTA_MIN, Z_EXTRAP_DELTA_MIN ) interpolator3D = Interpolator3DArray(x_in, y_in, z_in, f_in, 'linear', 'linear', extrapolation_range_x=2.0, extrapolation_range_y=2.0, extrapolation_range_z=2.0) if VISUAL_NOT_TESTS: n_lower_upper_interp = 51 else: n_lower_upper_interp = 19 n_lower = 50 lower_p = 0.9 xsamples_lower_and_upper = np.linspace(X_LOWER, X_UPPER, n_lower_upper_interp) ysamples_lower_and_upper = np.linspace(Y_LOWER, Y_UPPER, n_lower_upper_interp) zsamples_lower_and_upper = np.linspace(Z_LOWER, Z_UPPER, n_lower_upper_interp) xsamples_lower_and_upper = np.concatenate((np.linspace(X_LOWER - (X_UPPER - X_LOWER) * lower_p, X_LOWER, n_lower)[ :-1], xsamples_lower_and_upper, np.linspace(X_UPPER, X_UPPER + (X_UPPER - X_LOWER) * lower_p, n_lower)[ 1:])) ysamples_lower_and_upper = np.concatenate((np.linspace(Y_LOWER - (Y_UPPER - Y_LOWER) * lower_p, Y_LOWER, n_lower)[ :-1], ysamples_lower_and_upper, np.linspace(Y_UPPER, Y_UPPER + (Y_UPPER - Y_LOWER) * lower_p, n_lower)[ 1:])) zsamples_lower_and_upper = np.concatenate((np.linspace(Z_LOWER - (Z_UPPER - Z_LOWER) * lower_p, Z_LOWER, n_lower)[ :-1], zsamples_lower_and_upper, np.linspace(Z_UPPER, Z_UPPER + (Z_UPPER - Z_LOWER) * lower_p, n_lower)[ 1:])) index_ysamples_lower_upper = np.where(x_in[index_y_in] == ysamples_lower_and_upper)[0].item() # extrapolation to save f_extrapolation_output = np.zeros((len(xsamples_extrapolation), )) for i in range(len(xsamples_extrapolation)): f_extrapolation_output[i] = interpolator3D( xsamples_extrapolation[i], ysamples_extrapolation[i], zsamples_extrapolation[i] ) if verbose_options[1]: print('Output of extrapolation to be saved:\n', repr(f_extrapolation_output)) check_plot = True if check_plot: import matplotlib.pyplot as plt from matplotlib import cm # Install mayavi and pyQt5 main_plots_on = True if main_plots_on: fig, ax = plt.subplots(1, 4) fig1, ax1 = plt.subplots(1, 2) if not (x_in[index_x_in] == xsamples).any(): raise ValueError( f'To compare a slice, NB_XSAMPLES={NB_XSAMPLES}-1, NB_YSAMPLES={NB_YSAMPLES}-1, NB_ZSAMPLES=' f'{NB_ZSAMPLES}-1 must be divisible by NB_X={NB_X}-1, NB_Y={NB_Y}-1, NB_Z={NB_Z}-1' ) if not (y_in[index_y_in] == ysamples_lower_and_upper).any(): raise ValueError( f'To compare a slice, NB_XSAMPLES={NB_XSAMPLES}-1, NB_YSAMPLES={NB_YSAMPLES}-1, NB_ZSAMPLES=' f'{NB_ZSAMPLES}-1 must be divisible by NB_X={NB_X}-1, NB_Y={NB_Y}-1, NB_Z={NB_Z}-1' ) index_xsamples = np.where(x_in[index_x_in] == xsamples)[0].item() index_ysamples_lower_upper = np.where(y_in[index_y_in] == ysamples_lower_and_upper)[0].item() # index_ysamples_lower_upper = 0 # index_zsamples_lower_upper = 0 index_zsamples_lower_upper = np.where(z_in[index_z_in] == zsamples_lower_and_upper)[0].item() f_plot_x = f_in[index_x_in, :, :] y_corners_x = pcolourmesh_corners(y_in) z_corners_x = pcolourmesh_corners(z_in) min_colourmap = np.min(f_in) max_colourmap = np.max(f_in) if log_scale: c_norm = SymLogNorm(vmin=min_colourmap, vmax=max_colourmap, linthresh=0.03) else: c_norm = Normalize(vmin=min_colourmap, vmax=max_colourmap) colourmap = cm.get_cmap('viridis', 512) ax[0].pcolormesh(y_corners_x, z_corners_x, f_plot_x, norm=c_norm, cmap='viridis') # ax[0].pcolormesh(y_in, z_in, f_plot_x) ax[0].set_aspect('equal') f_out = np.zeros((len(xsamples), len(ysamples), len(zsamples))) for i in range(len(xsamples)): for j in range(len(ysamples)): for k in range(len(zsamples)): f_out[i, j, k] = interpolator3D(xsamples[i], ysamples[j], zsamples[k]) if verbose_options[2]: print('Test interpolation:\n', repr(f_out)) f_out_lower_and_upper = np.zeros((len(xsamples_lower_and_upper), len(ysamples_lower_and_upper), len(zsamples_lower_and_upper))) for i in range(len(xsamples_lower_and_upper)): for j in range(len(ysamples_lower_and_upper)): for k in range(len(zsamples_lower_and_upper)): f_out_lower_and_upper[i, j, k] = interpolator3D( xsamples_lower_and_upper[i], ysamples_lower_and_upper[j], zsamples_lower_and_upper[k] ) f_out_extrapolation = np.zeros((len(xsamples_extrapolation), )) for i in range(len(xsamples_extrapolation)): f_out_extrapolation[i] = interpolator3D( xsamples_extrapolation[i], ysamples_extrapolation[i], zsamples_extrapolation[i] ) if verbose_options[3]: print('New output of extrapolation to be saved:\n', repr(f_out_extrapolation)) index_xsamples_extrap = np.where(x_in[index_x_in] == xsamples_extrapolation) f_out_x_extrapolation = f_out_extrapolation[index_xsamples_extrap] im = ax[3].scatter( ysamples_extrapolation[index_xsamples_extrap], zsamples_extrapolation[index_xsamples_extrap], c=f_out_x_extrapolation, norm=c_norm, cmap='viridis', s=10 ) ax[3].set_aspect('equal') f_out_x = f_out[index_xsamples, :, :] ysamples_mesh, zsamples_mesh = np.meshgrid(ysamples, zsamples) ax[0].scatter( ysamples_mesh.ravel(), zsamples_mesh.ravel(), c=f_out_x.ravel(), norm=c_norm, cmap='viridis', s=10 ) index_y_print = -1 index_z_print = 0 index_ysamples_print = np.where(y_in[index_y_print] == ysamples)[0].item() index_zsamples_print = np.where(z_in[index_z_print] == zsamples)[0].item() ax[0].set_title('Slice of x', size=20) ax[1].set_title(f'Interpolated points \nin slice of x={x_in[index_x_in]}', size=20) y_corners_xsamples = pcolourmesh_corners(ysamples) z_corners_xsamples = pcolourmesh_corners(zsamples) im2 = ax[1].pcolormesh(y_corners_xsamples, z_corners_xsamples, f_out_x, norm=c_norm, cmap='viridis') ax[1].set_aspect('equal') if not (x_in[index_x_in] == xsamples_lower_and_upper).any(): raise ValueError( f'To compare a slice, n_lower_upper={n_lower}-1, must be divisible by NB_X={NB_X}-1, NB_Y={NB_Y}-1,' f' NB_Z={NB_Z}-1' ) index_xsamples_lower_and_upper = np.where(x_in[index_x_in] == xsamples_lower_and_upper)[0].item() y_corners_xsamples_lower_and_upper = pcolourmesh_corners(ysamples_lower_and_upper) z_corners_xsamples_lower_and_upper = pcolourmesh_corners(zsamples_lower_and_upper) f_out_lower_and_upper_x = f_out_lower_and_upper[index_xsamples_lower_and_upper, :, :] im3 = ax[2].pcolormesh( y_corners_xsamples_lower_and_upper, z_corners_xsamples_lower_and_upper, f_out_lower_and_upper_x, norm=c_norm, cmap='viridis' ) check_array_z = np.zeros(len(zsamples_lower_and_upper)) check_array_y = np.zeros(len(ysamples_lower_and_upper)) for i in range(len(zsamples_lower_and_upper)): check_array_z[i] = interpolator3D( x_in[index_x_in], ysamples_lower_and_upper[index_ysamples_lower_upper], zsamples_lower_and_upper[i] ) check_array_y[i] = interpolator3D( x_in[index_x_in], ysamples_lower_and_upper[i], zsamples_lower_and_upper[index_zsamples_lower_upper] ) ax1[0].plot(zsamples_lower_and_upper, f_out_lower_and_upper_x[index_ysamples_lower_upper, :]) ax1[0].plot(z_in, f_in[index_x_in, index_y_in, :], 'bo') ax1[0].plot(zsamples_lower_and_upper, check_array_z, 'gx') ax1[1].plot(ysamples_lower_and_upper, check_array_y) # ax1[1].plot(ysamples_lower_and_upper, f_out_lower_and_upper_x[:, index_z_plot]) ax1[0].axvline(z_in[0], color='r', linestyle='--') ax1[0].axvline(z_in[-1], color='r', linestyle='--') ax1[1].axvline(y_in[0], color='r', linestyle='--') ax1[1].axvline(y_in[-1], color='r', linestyle='--') fig.colorbar(im, ax=ax[0]) fig.colorbar(im2, ax=ax[1]) fig.colorbar(im3, ax=ax[2]) ax[2].set_aspect('equal') plt.show()
[ 198, 2, 15069, 357, 66, 8, 1946, 12, 1238, 2481, 11, 1583, 4422, 2185, 461, 1040, 11, 7760, 8831, 4935, 198, 2, 1439, 2489, 10395, 13, 198, 2, 198, 2, 2297, 396, 3890, 290, 779, 287, 2723, 290, 13934, 5107, 11, 351, 393, 1231, 1...
1.992657
8,171
# Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. # # This software is licensed under the Apache License, Version 2.0 (the # "License") as published by the Apache Software Foundation. # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from __future__ import annotations import abc from typing import Union, List, TYPE_CHECKING try: from typing import Literal except ImportError: from typing_extensions import Literal from .framework.response import BaseResponse if TYPE_CHECKING: from supertokens_python.framework.request import BaseRequest from .supertokens import AppInfo from .normalised_url_path import NormalisedURLPath from .exceptions import SuperTokensError
[ 2, 15069, 357, 66, 8, 33448, 11, 569, 3861, 40, 23500, 290, 14, 273, 663, 29116, 13, 1439, 2489, 10395, 13, 198, 2, 198, 2, 770, 3788, 318, 11971, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 198, 2, 366, 34156, 49...
3.774834
302
# -*- coding: utf-8 -*- """Tests go in this directory."""
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 51, 3558, 467, 287, 428, 8619, 526, 15931, 198 ]
2.416667
24
__version__ = "{{cookiecutter._pkg_version}}"
[ 834, 9641, 834, 796, 366, 27007, 44453, 8968, 353, 13557, 35339, 62, 9641, 11709, 1, 198 ]
2.875
16
# -*- coding: utf-8 -*- """ @author:XuMing(xuming624@qq.com) @description: """ import datetime import os import pathlib import random import sys from loguru import logger sys.path.append('../..') from similarities import BM25Similarity from similarities.utils import http_get from similarities.data_loader import SearchDataLoader from similarities.evaluation import evaluate random.seed(42) pwd_path = os.path.dirname(os.path.realpath(__file__)) data_path = get_scifact() #### Loading test queries and corpus in DBPedia corpus, queries, qrels = SearchDataLoader(data_path).load(split="test") corpus_ids, query_ids = list(corpus), list(queries) logger.info(f"corpus: {len(corpus)}, queries: {len(queries)}") #### Randomly sample 1M pairs from Original Corpus (4.63M pairs) #### First include all relevant documents (i.e. present in qrels) corpus_set = set() for query_id in qrels: corpus_set.update(list(qrels[query_id].keys())) corpus_new = {corpus_id: corpus[corpus_id] for corpus_id in corpus_set} #### Remove already seen k relevant documents and sample (1M - k) docs randomly remaining_corpus = list(set(corpus_ids) - corpus_set) sample = min(1000000 - len(corpus_set), len(remaining_corpus)) # sample = 10 for corpus_id in random.sample(remaining_corpus, sample): corpus_new[corpus_id] = corpus[corpus_id] corpus_docs = {corpus_id: corpus_new[corpus_id]['title'] + corpus_new[corpus_id]['text'] for corpus_id, corpus in corpus_new.items()} #### Index 1M passages into the index (seperately) model = BM25Similarity(corpus_docs) #### Saving benchmark times time_taken_all = {} for query_id in query_ids: query = {query_id: queries[query_id]} #### Measure time to retrieve top-10 BM25 documents using single query latency start = datetime.datetime.now() q_res = model.most_similar(query, topn=10) end = datetime.datetime.now() # print(q_res) #### Measuring time taken in ms (milliseconds) time_taken = (end - start) time_taken = time_taken.total_seconds() * 1000 time_taken_all[query_id] = time_taken # logger.info("query: {}: {} {:.2f}ms".format(query_id, query, time_taken)) # logger.info("\tsearch result: {}".format(results[:2])) time_taken = list(time_taken_all.values()) logger.info("Average time taken: {:.2f}ms".format(sum(time_taken) / len(time_taken_all))) #### Saving benchmark times with batch # queries = [queries[query_id] for query_id in query_ids] start = datetime.datetime.now() results = model.most_similar(queries, topn=10) end = datetime.datetime.now() #### Measuring time taken in ms (milliseconds) time_taken = (end - start) time_taken = time_taken.total_seconds() * 1000 logger.info("All, Spend {:.2f}ms".format(time_taken)) logger.info("Average time taken: {:.2f}ms".format(time_taken / len(queries))) logger.info(f"Results size: {len(results)}") #### Evaluate your retrieval using NDCG@k, MAP@K ... ndcg, _map, recall, precision = evaluate(qrels, results) logger.info(f"MAP: {_map}")
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 31, 9800, 25, 55, 84, 44, 278, 7, 87, 12595, 21, 1731, 31, 38227, 13, 785, 8, 198, 31, 11213, 25, 198, 37811, 198, 11748, 4818, 8079, 198, 11748, 28686, ...
2.719855
1,103
#!/usr/bin/env python """ Copyright (c) 2014-2018 Alex Forencich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from myhdl import * import os import axis_ep import eth_ep import arp_ep module = 'arp_64' testbench = 'test_%s' % module srcs = [] srcs.append("../rtl/%s.v" % module) srcs.append("../rtl/lfsr.v") srcs.append("../rtl/arp_cache.v") srcs.append("../rtl/arp_eth_rx_64.v") srcs.append("../rtl/arp_eth_tx_64.v") srcs.append("%s.v" % testbench) src = ' '.join(srcs) build_cmd = "iverilog -o %s.vvp %s" % (testbench, src) if __name__ == '__main__': print("Running test...") test_bench()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 37811, 198, 198, 15269, 357, 66, 8, 1946, 12, 7908, 4422, 4558, 10782, 488, 198, 198, 5990, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597, 1048, 16727, 257, 4866, 198, 16...
3.101365
513